|
@@ -42,11 +42,11 @@ public class GatewayController {
|
|
|
|
|
|
@PostMapping("/add")
|
|
@PostMapping("/add")
|
|
@Transactional
|
|
@Transactional
|
|
- public Result add(@RequestBody GateWayAddParam gateWayAddParam){
|
|
|
|
|
|
+ public Result add(@RequestBody GateWayAddParam gateWayAddParam) {
|
|
String deviceCode = gateWayAddParam.getDeviceCode();
|
|
String deviceCode = gateWayAddParam.getDeviceCode();
|
|
List<Gateway> gatewayList = gatewayService.list(new QueryWrapper<Gateway>().lambda().eq(Gateway::getDeviceCode, deviceCode));
|
|
List<Gateway> gatewayList = gatewayService.list(new QueryWrapper<Gateway>().lambda().eq(Gateway::getDeviceCode, deviceCode));
|
|
- if (ObjectUtil.isNotEmpty(gatewayList)){
|
|
|
|
- return new Result(10001,"网关编号已存在",false);
|
|
|
|
|
|
+ if (ObjectUtil.isNotEmpty(gatewayList)) {
|
|
|
|
+ return new Result(10001, "网关编号已存在", false);
|
|
}
|
|
}
|
|
Gateway gateway = new Gateway();
|
|
Gateway gateway = new Gateway();
|
|
gateway.setDeviceCode(deviceCode);
|
|
gateway.setDeviceCode(deviceCode);
|
|
@@ -54,11 +54,12 @@ public class GatewayController {
|
|
gateway.setLocationId(gateWayAddParam.getLocationId());
|
|
gateway.setLocationId(gateWayAddParam.getLocationId());
|
|
gateway.setType(gateWayAddParam.getType());
|
|
gateway.setType(gateWayAddParam.getType());
|
|
gateway.setFarmId(gateWayAddParam.getFarmId());
|
|
gateway.setFarmId(gateWayAddParam.getFarmId());
|
|
|
|
+ gateway.setVersion(String.valueOf(gateWayAddParam.getVersion()));
|
|
gateway.setTerminalNum(gateWayAddParam.getTerminalNum());
|
|
gateway.setTerminalNum(gateWayAddParam.getTerminalNum());
|
|
gatewayService.save(gateway);
|
|
gatewayService.save(gateway);
|
|
|
|
|
|
|
|
|
|
- for (int i = 1; i <= gateWayAddParam.getTerminalNum(); i++){
|
|
|
|
|
|
+ for (int i = 1; i <= gateWayAddParam.getTerminalNum(); i++) {
|
|
Terminal terminal = new Terminal();
|
|
Terminal terminal = new Terminal();
|
|
terminal.setDeviceCode(deviceCode + i);
|
|
terminal.setDeviceCode(deviceCode + i);
|
|
terminal.setGatewayId(gateway.getId());
|
|
terminal.setGatewayId(gateway.getId());
|
|
@@ -67,40 +68,47 @@ public class GatewayController {
|
|
terminal.setOrders(i);
|
|
terminal.setOrders(i);
|
|
terminalService.save(terminal);
|
|
terminalService.save(terminal);
|
|
List portList = new ArrayList();
|
|
List portList = new ArrayList();
|
|
- for (int j = 1; j < 9; j++){
|
|
|
|
|
|
+ if (gateWayAddParam.getVersion() == 2) {
|
|
TerminalPort terminalPort = new TerminalPort();
|
|
TerminalPort terminalPort = new TerminalPort();
|
|
- terminalPort.setDeviceCode(terminal.getDeviceCode()+j);
|
|
|
|
|
|
+ terminalPort.setDeviceCode(terminal.getDeviceCode() + 1);
|
|
terminalPort.setTerminalId(terminal.getId());
|
|
terminalPort.setTerminalId(terminal.getId());
|
|
terminalPort.setFarmId(terminal.getFarmId());
|
|
terminalPort.setFarmId(terminal.getFarmId());
|
|
portList.add(terminalPort);
|
|
portList.add(terminalPort);
|
|
|
|
+ } else {
|
|
|
|
+ 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);
|
|
portService.saveBatch(portList);
|
|
}
|
|
}
|
|
-
|
|
|
|
return Result.SUCCESS();
|
|
return Result.SUCCESS();
|
|
}
|
|
}
|
|
|
|
|
|
@PostMapping("/page")
|
|
@PostMapping("/page")
|
|
- public Result page(@RequestBody GateWayPageParam gateWayPageParam){
|
|
|
|
- Page<Gateway> page = new Page<>(gateWayPageParam.getPageNum(),gateWayPageParam.getPageSize());
|
|
|
|
- Page<Gateway> gatewayPage = gatewayService.page(page,new QueryWrapper<Gateway>().lambda()
|
|
|
|
- .eq(Gateway::getFarmId,gateWayPageParam.getFarmId())
|
|
|
|
- .like(ObjectUtil.isNotEmpty(gateWayPageParam.getDeviceCode()),Gateway::getDeviceCode,gateWayPageParam.getDeviceCode()));
|
|
|
|
- return new Result(ResultCode.SUCCESS,gatewayPage);
|
|
|
|
|
|
+ public Result page(@RequestBody GateWayPageParam gateWayPageParam) {
|
|
|
|
+ Page<Gateway> page = new Page<>(gateWayPageParam.getPageNum(), gateWayPageParam.getPageSize());
|
|
|
|
+ Page<Gateway> gatewayPage = gatewayService.page(page, new QueryWrapper<Gateway>().lambda()
|
|
|
|
+ .eq(Gateway::getFarmId, gateWayPageParam.getFarmId())
|
|
|
|
+ .like(ObjectUtil.isNotEmpty(gateWayPageParam.getDeviceCode()), Gateway::getDeviceCode, gateWayPageParam.getDeviceCode()));
|
|
|
|
+ return new Result(ResultCode.SUCCESS, gatewayPage);
|
|
}
|
|
}
|
|
|
|
|
|
@PostMapping("/list")
|
|
@PostMapping("/list")
|
|
- public Result list(@RequestBody GateWayListParam gateWayListParam){
|
|
|
|
|
|
+ public Result list(@RequestBody GateWayListParam gateWayListParam) {
|
|
List<Gateway> gatewayList = gatewayService.list(new QueryWrapper<Gateway>().lambda().eq(ObjectUtil.isNotEmpty(gateWayListParam.getFarmId()), Gateway::getFarmId, gateWayListParam.getFarmId()));
|
|
List<Gateway> gatewayList = gatewayService.list(new QueryWrapper<Gateway>().lambda().eq(ObjectUtil.isNotEmpty(gateWayListParam.getFarmId()), Gateway::getFarmId, gateWayListParam.getFarmId()));
|
|
- return new Result(ResultCode.SUCCESS,gatewayList);
|
|
|
|
|
|
+ return new Result(ResultCode.SUCCESS, gatewayList);
|
|
}
|
|
}
|
|
|
|
|
|
@PostMapping("/update")
|
|
@PostMapping("/update")
|
|
- public Result update(@RequestBody GateWayUpdateParam gateWayUpdateParam){
|
|
|
|
|
|
+ public Result update(@RequestBody GateWayUpdateParam gateWayUpdateParam) {
|
|
Gateway gateway = gatewayService.getById(gateWayUpdateParam.getId());
|
|
Gateway gateway = gatewayService.getById(gateWayUpdateParam.getId());
|
|
- List<Gateway> gatewayList = gatewayService.list(new QueryWrapper<Gateway>().lambda().eq(Gateway::getDeviceCode, gateWayUpdateParam.getDeviceCode()).ne(Gateway::getId,gateWayUpdateParam.getId()));
|
|
|
|
- if (ObjectUtil.isNotEmpty(gatewayList)){
|
|
|
|
- return new Result(10001,"网关编号已存在",false);
|
|
|
|
|
|
+ List<Gateway> gatewayList = gatewayService.list(new QueryWrapper<Gateway>().lambda().eq(Gateway::getDeviceCode, gateWayUpdateParam.getDeviceCode()).ne(Gateway::getId, gateWayUpdateParam.getId()));
|
|
|
|
+ if (ObjectUtil.isNotEmpty(gatewayList)) {
|
|
|
|
+ return new Result(10001, "网关编号已存在", false);
|
|
}
|
|
}
|
|
gateway.setDeviceCode(gateWayUpdateParam.getDeviceCode());
|
|
gateway.setDeviceCode(gateWayUpdateParam.getDeviceCode());
|
|
gateway.setDeviceName(gateWayUpdateParam.getDeviceName());
|
|
gateway.setDeviceName(gateWayUpdateParam.getDeviceName());
|
|
@@ -112,10 +120,10 @@ public class GatewayController {
|
|
}
|
|
}
|
|
|
|
|
|
@PostMapping("/delete")
|
|
@PostMapping("/delete")
|
|
- public Result delete(@RequestBody GateWayDeleteParam gateWayDeleteParam){
|
|
|
|
|
|
+ public Result delete(@RequestBody GateWayDeleteParam gateWayDeleteParam) {
|
|
List<Terminal> terminalList = terminalService.list(new QueryWrapper<Terminal>().lambda().eq(Terminal::getGatewayId, gateWayDeleteParam.getId()));
|
|
List<Terminal> terminalList = terminalService.list(new QueryWrapper<Terminal>().lambda().eq(Terminal::getGatewayId, gateWayDeleteParam.getId()));
|
|
- if (ObjectUtil.isNotEmpty(terminalList)){
|
|
|
|
- return new Result(10001,"网关存在下属终端",false);
|
|
|
|
|
|
+ if (ObjectUtil.isNotEmpty(terminalList)) {
|
|
|
|
+ return new Result(10001, "网关存在下属终端", false);
|
|
}
|
|
}
|
|
gatewayService.removeById(gateWayDeleteParam.getId());
|
|
gatewayService.removeById(gateWayDeleteParam.getId());
|
|
return Result.SUCCESS();
|
|
return Result.SUCCESS();
|