|
@@ -18,6 +18,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import javax.validation.constraints.NotNull;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
@@ -43,35 +44,42 @@ public class TerminalController {
|
|
|
@Autowired
|
|
|
private TerminalMapper terminalMapper;
|
|
|
|
|
|
-// @PostMapping("/add")
|
|
|
-// @Transactional
|
|
|
-// public Result add(@RequestBody TerminalAddParam terminalAddParam){
|
|
|
-// List<Terminal> terminalList = terminalService.list(new QueryWrapper<Terminal>().lambda()
|
|
|
-// .eq(Terminal::getDeviceCode, terminalAddParam.getDeviceCode()));
|
|
|
-// if (ObjectUtil.isNotEmpty(terminalList)){
|
|
|
-// return new Result(10001,"终端编号已存在",false);
|
|
|
-// }
|
|
|
-// Gateway gateway = gatewayService.getById(terminalAddParam.getGatewayId());
|
|
|
-//
|
|
|
-// Terminal terminal = new Terminal();
|
|
|
-// terminal.setDeviceCode(terminalAddParam.getDeviceCode());
|
|
|
-// terminal.setDeviceName(terminalAddParam.getDeviceName());
|
|
|
-// terminal.setGatewayId(terminalAddParam.getGatewayId());
|
|
|
-// terminal.setType(terminalAddParam.getType());
|
|
|
-// terminal.setFarmId(terminalAddParam.getFarmId());
|
|
|
-// terminalService.save(terminal);
|
|
|
-//
|
|
|
-// List portList = new ArrayList();
|
|
|
-// for (int i = 1; i < 9; i++){
|
|
|
-// TerminalPort terminalPort = new TerminalPort();
|
|
|
-// terminalPort.setDeviceCode(gateway.getDeviceCode()+terminal.getDeviceCode()+i);
|
|
|
-// terminalPort.setTerminalId(terminal.getId());
|
|
|
-// terminalPort.setFarmId(terminal.getFarmId());
|
|
|
-// portList.add(terminalPort);
|
|
|
-// }
|
|
|
-// portService.saveBatch(portList);
|
|
|
-// return Result.SUCCESS();
|
|
|
-// }
|
|
|
+ @PostMapping("/add")
|
|
|
+ @Transactional
|
|
|
+ public Result add(@RequestBody TerminalAddParam terminalAddParam){
|
|
|
+ List<Terminal> terminalList = terminalService.list(new QueryWrapper<Terminal>().lambda()
|
|
|
+ .eq(Terminal::getDeviceCode, terminalAddParam.getDeviceCode()));
|
|
|
+ if (ObjectUtil.isNotEmpty(terminalList)){
|
|
|
+ return new Result(10001,"终端编号已存在",false);
|
|
|
+ }
|
|
|
+ Integer gatewayId = terminalAddParam.getGatewayId();
|
|
|
+ Gateway gateway = gatewayService.getById(gatewayId);
|
|
|
+
|
|
|
+ Integer maxOrder = terminalMapper.getMaxOrder(gatewayId);
|
|
|
+
|
|
|
+ Terminal terminal = new Terminal();
|
|
|
+ terminal.setDeviceCode(terminalAddParam.getDeviceCode());
|
|
|
+ terminal.setDeviceName(terminalAddParam.getDeviceName());
|
|
|
+ terminal.setGatewayId(gatewayId);
|
|
|
+ terminal.setOrders(maxOrder + 1);
|
|
|
+ terminal.setType(terminalAddParam.getType());
|
|
|
+ terminal.setFarmId(terminalAddParam.getFarmId());
|
|
|
+ terminalService.save(terminal);
|
|
|
+
|
|
|
+ gateway.setTerminalNum(gateway.getTerminalNum()+1);
|
|
|
+ gatewayService.updateById(gateway);
|
|
|
+
|
|
|
+ List portList = new ArrayList();
|
|
|
+ for (int i = 1; i < 9; i++){
|
|
|
+ TerminalPort terminalPort = new TerminalPort();
|
|
|
+ terminalPort.setDeviceCode(gateway.getDeviceCode()+terminal.getDeviceCode()+i);
|
|
|
+ terminalPort.setTerminalId(terminal.getId());
|
|
|
+ terminalPort.setFarmId(terminal.getFarmId());
|
|
|
+ portList.add(terminalPort);
|
|
|
+ }
|
|
|
+ portService.saveBatch(portList);
|
|
|
+ return Result.SUCCESS();
|
|
|
+ }
|
|
|
|
|
|
@PostMapping("/list")
|
|
|
public Result list(@RequestBody TerminalListParam terminalListParam){
|