|
@@ -7,13 +7,18 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.huimv.env.admin.common.utils.Result;
|
|
|
import com.huimv.env.admin.common.utils.ResultCode;
|
|
|
import com.huimv.env.admin.entity.Terminal;
|
|
|
+import com.huimv.env.admin.entity.TerminalPort;
|
|
|
import com.huimv.env.admin.entity.vo.*;
|
|
|
import com.huimv.env.admin.entity.Gateway;
|
|
|
import com.huimv.env.admin.service.IGatewayService;
|
|
|
+import com.huimv.env.admin.service.ITerminalPortService;
|
|
|
import com.huimv.env.admin.service.ITerminalService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import javax.validation.constraints.NotBlank;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
@@ -32,21 +37,44 @@ public class GatewayController {
|
|
|
private IGatewayService gatewayService;
|
|
|
@Autowired
|
|
|
private ITerminalService terminalService;
|
|
|
+ @Autowired
|
|
|
+ private ITerminalPortService portService;
|
|
|
|
|
|
@PostMapping("/add")
|
|
|
+ @Transactional
|
|
|
public Result add(@RequestBody GateWayAddParam gateWayAddParam){
|
|
|
- List<Gateway> gatewayList = gatewayService.list(new QueryWrapper<Gateway>().lambda().eq(Gateway::getDeviceCode, gateWayAddParam.getDeviceCode()));
|
|
|
+ String deviceCode = gateWayAddParam.getDeviceCode();
|
|
|
+ List<Gateway> gatewayList = gatewayService.list(new QueryWrapper<Gateway>().lambda().eq(Gateway::getDeviceCode, deviceCode));
|
|
|
if (ObjectUtil.isNotEmpty(gatewayList)){
|
|
|
return new Result(10001,"网关编号已存在",false);
|
|
|
}
|
|
|
Gateway gateway = new Gateway();
|
|
|
- gateway.setDeviceCode(gateWayAddParam.getDeviceCode());
|
|
|
+ gateway.setDeviceCode(deviceCode);
|
|
|
gateway.setDeviceName(gateWayAddParam.getDeviceName());
|
|
|
gateway.setLocationId(gateWayAddParam.getLocationId());
|
|
|
gateway.setType(gateWayAddParam.getType());
|
|
|
gateway.setFarmId(gateWayAddParam.getFarmId());
|
|
|
gatewayService.save(gateway);
|
|
|
|
|
|
+ List terminalList = new ArrayList();
|
|
|
+ for (int i = 1; i <= gateWayAddParam.getTerminalNum(); i++){
|
|
|
+ Terminal terminal = new Terminal();
|
|
|
+ terminal.setDeviceCode(deviceCode + i);
|
|
|
+ terminal.setGatewayId(gateway.getId());
|
|
|
+ terminal.setFarmId(gateWayAddParam.getFarmId());
|
|
|
+ terminalList.add(terminal);
|
|
|
+ List portList = new ArrayList();
|
|
|
+ for (int j = 1; j < 9; j++){
|
|
|
+ TerminalPort terminalPort = new TerminalPort();
|
|
|
+ terminalPort.setDeviceCode(terminal.getDeviceCode()+j);
|
|
|
+ terminalPort.setTerminalId(terminal.getId());
|
|
|
+ terminalPort.setFarmId(terminal.getFarmId());
|
|
|
+ portList.add(terminalPort);
|
|
|
+ }
|
|
|
+ portService.saveBatch(portList);
|
|
|
+ }
|
|
|
+ terminalService.saveBatch(terminalList);
|
|
|
+
|
|
|
return Result.SUCCESS();
|
|
|
}
|
|
|
|