终端相关代码修改

This commit is contained in:
2022-07-01 15:13:47 +08:00
parent 19966fd1c7
commit 4eac5c3028
4 changed files with 79 additions and 75 deletions

View File

@@ -42,9 +42,9 @@ public class DeviceParam {
/** /**
* 通讯类型MMS、CLD字典表 * 通讯类型MMS、CLD字典表
*/ */
@ApiModelProperty(name = "comType",value = "通讯类型",required = true) @ApiModelProperty(name = "frontType",value = "通讯类型",required = true)
@NotBlank(message = "通讯类型不能为空") @NotBlank(message = "通讯类型不能为空")
private String comType; private String frontType;
@ApiModelProperty(name = "ip",value = "装置ip",required = true) @ApiModelProperty(name = "ip",value = "装置ip",required = true)
@NotBlank(message = "设备ip不能为空") @NotBlank(message = "设备ip不能为空")

View File

@@ -64,7 +64,7 @@ public class TerminalBaseController extends BaseController {
@ApiOperation("终端新增操作") @ApiOperation("终端新增操作")
@OperateInfo(operateType = OperateType.ADD, info = LogEnum.BUSINESS_MEDIUM) @OperateInfo(operateType = OperateType.ADD, info = LogEnum.BUSINESS_MEDIUM)
@PostMapping("addTerminal") @PostMapping("addTerminal")
public HttpResult addTerminal(@Valid @RequestBody AddTerminalParam addTerminalParam) { public HttpResult<Object> addTerminal(@Valid @RequestBody AddTerminalParam addTerminalParam) {
String methodDescribe = getMethodDescribe("addTerminal"); String methodDescribe = getMethodDescribe("addTerminal");
//装置母线监测点相关检验 //装置母线监测点相关检验
if (CollectionUtil.isNotEmpty(addTerminalParam.getDeviceParam())) { if (CollectionUtil.isNotEmpty(addTerminalParam.getDeviceParam())) {

View File

@@ -138,15 +138,12 @@ public class TerminalBaseServiceImpl extends ServiceImpl<LineMapper, Line> imple
Line line = assembleLine(addTerminalParam.getProjectParam().getName(), LineBaseEnum.PROJECT_LEVEL.getCode(), "0", "0", addTerminalParam.getProjectParam().getSort()); Line line = assembleLine(addTerminalParam.getProjectParam().getName(), LineBaseEnum.PROJECT_LEVEL.getCode(), "0", "0", addTerminalParam.getProjectParam().getSort());
this.baseMapper.insert(line); this.baseMapper.insert(line);
projectIndex = line.getId(); projectIndex = line.getId();
} else {
//throw new BusinessException(DeviceResponseEnum.REQUEST_DATA_ERROR);
} }
} }
//省份 //省份
if (Objects.nonNull(addTerminalParam.getProvinceParam())) { if (Objects.nonNull(addTerminalParam.getProvinceParam())) {
if (StrUtil.isBlank(provinceIndex) && StrUtil.isNotBlank(projectIndex)) { if (StrUtil.isBlank(provinceIndex) && StrUtil.isNotBlank(projectIndex)) {
HttpResult<Area> provinceDic = areaFeignClient.selectIdArea(addTerminalParam.getProvinceParam().getName()); Area result = areaFeignClient.selectIdArea(addTerminalParam.getProvinceParam().getName()).getData();
Area result = provinceDic.getData();
if (Objects.isNull(result)) { if (Objects.isNull(result)) {
throw new BusinessException(DeviceResponseEnum.PROVINCE_GET_ERROR); throw new BusinessException(DeviceResponseEnum.PROVINCE_GET_ERROR);
} }
@@ -155,8 +152,6 @@ public class TerminalBaseServiceImpl extends ServiceImpl<LineMapper, Line> imple
Line province = assembleLine(result.getId(), LineBaseEnum.PROVINCE_LEVEL.getCode(), projectIndex, projectIndex, addTerminalParam.getProvinceParam().getSort()); Line province = assembleLine(result.getId(), LineBaseEnum.PROVINCE_LEVEL.getCode(), projectIndex, projectIndex, addTerminalParam.getProvinceParam().getSort());
this.baseMapper.insert(province); this.baseMapper.insert(province);
provinceIndex = province.getId(); provinceIndex = province.getId();
} else {
//throw new BusinessException(DeviceResponseEnum.REQUEST_DATA_ERROR);
} }
} }
@@ -190,39 +185,21 @@ public class TerminalBaseServiceImpl extends ServiceImpl<LineMapper, Line> imple
//装置 //装置
if (Objects.nonNull(addTerminalParam.getDeviceParam())) { if (Objects.nonNull(addTerminalParam.getDeviceParam())) {
if (CollectionUtil.isNotEmpty(addTerminalParam.getDeviceParam()) && StrUtil.isNotBlank(subIndex)) {
List<String> devNameList = addTerminalParam.getDeviceParam().stream()
.filter((dev -> dev.getDevIndex() == null))
.map(DeviceParam::getName)
.collect(Collectors.toList());
LambdaQueryWrapper<Line> lineLambdaQueryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<Line> lineLambdaQueryWrapper = new LambdaQueryWrapper<>();
if (CollectionUtil.isNotEmpty(devNameList)) { if (CollectionUtil.isNotEmpty(addTerminalParam.getDeviceParam()) && StrUtil.isNotBlank(subIndex)) {
lineLambdaQueryWrapper.eq(Line::getPid, subIndex).in(Line::getName, devNameList); //校验变电站下的装置名称ip是否重复
List<Line> deviceListRes = this.list(lineLambdaQueryWrapper); checkDev(addTerminalParam, subIndex,lineLambdaQueryWrapper);
//校验当前变电站下是否有同名设备
if (CollectionUtil.isNotEmpty(deviceListRes)) {
List<String> stringList = deviceListRes.stream().map(Line::getName).collect(Collectors.toList());
throw new BusinessException(DeviceResponseEnum.DEVICE_SAME_NAME, String.join(";", stringList));
}
}
List<String> devIpList = addTerminalParam.getDeviceParam().stream().filter((dev -> dev.getDevIndex() == null)).map(DeviceParam::getIp).collect(Collectors.toList());
if (CollectionUtil.isNotEmpty(devIpList)) {
List<Device> deviceListIpRes = lineMapper.getDeviceBySubId(subIndex, devIpList);
//校验当前变电站下是否有相同ip
if (CollectionUtil.isNotEmpty(deviceListIpRes)) {
List<String> stringList = deviceListIpRes.stream().map(Device::getIp).collect(Collectors.toList());
throw new BusinessException(DeviceResponseEnum.DEVICE_SAME_IP, String.join(";", stringList));
}
}
for (DeviceParam deviceParam : addTerminalParam.getDeviceParam()) { for (DeviceParam deviceParam : addTerminalParam.getDeviceParam()) {
//用于记录装置id //用于记录装置id
String devIdIndex; String devIdIndex;
//监测点索引最后一位数 //监测点序号
List<Integer> listId = Stream.of(1, 2, 3, 4, 5, 6).collect(Collectors.toList()); List<Integer> listLineNum = Stream.of(1, 2, 3, 4, 5, 6).collect(Collectors.toList());
//母线序号
List<Integer> listVoltageNum = Stream.of(1, 2, 3, 4, 5, 6).collect(Collectors.toList());
//标识当前装置下的监测点数量 //标识当前装置下的监测点数量
int lineNum = 0; int lineNum = 0, voltageNum = 0;
//校验监测点总数不超过6 //校验监测点总数不超过6
if (CollectionUtil.isNotEmpty(deviceParam.getSubVoltageParam())) { if (CollectionUtil.isNotEmpty(deviceParam.getSubVoltageParam())) {
for (SubVoltageParam subVoltage : deviceParam.getSubVoltageParam()) { for (SubVoltageParam subVoltage : deviceParam.getSubVoltageParam()) {
@@ -256,8 +233,7 @@ public class TerminalBaseServiceImpl extends ServiceImpl<LineMapper, Line> imple
deviceDetail.setUpdateTime(LocalDateTime.now()); deviceDetail.setUpdateTime(LocalDateTime.now());
deviceMapper.insert(deviceDetail); deviceMapper.insert(deviceDetail);
//装置功能 //装置功能
HttpResult<List<DictData>> httpResult = dicDataFeignClient.getDicDataByTypeName(DicDataTypeEnum.DEV_FUN.getName()); List<DictData> funList = dicDataFeignClient.getDicDataByTypeName(DicDataTypeEnum.DEV_FUN.getName()).getData();
List<DictData> funList = httpResult.getData();
if (CollectionUtil.isEmpty(funList)) { if (CollectionUtil.isEmpty(funList)) {
throw new BusinessException(DeviceResponseEnum.DIC_GET_EMPTY); throw new BusinessException(DeviceResponseEnum.DIC_GET_EMPTY);
} }
@@ -281,7 +257,7 @@ public class TerminalBaseServiceImpl extends ServiceImpl<LineMapper, Line> imple
if (CollectionUtil.isNotEmpty(lineDetails)) { if (CollectionUtil.isNotEmpty(lineDetails)) {
lineNum = lineNum + lineDetails.size(); lineNum = lineNum + lineDetails.size();
for (LineDetail sline : lineDetails) { for (LineDetail sline : lineDetails) {
listId.removeIf(integer -> sline.getNum().equals(integer)); listLineNum.removeIf(integer -> sline.getNum().equals(integer));
} }
} }
} }
@@ -317,8 +293,8 @@ public class TerminalBaseServiceImpl extends ServiceImpl<LineMapper, Line> imple
String subvIndex; String subvIndex;
if (StrUtil.isBlank(subVoltageParam.getSubvIndex()) && StrUtil.isNotBlank(devIdIndex)) { if (StrUtil.isBlank(subVoltageParam.getSubvIndex()) && StrUtil.isNotBlank(devIdIndex)) {
HttpResult<DictData> scaleRes = dicDataFeignClient.getDicDataById(subVoltageParam.getScale()); DictData scaleRes = dicDataFeignClient.getDicDataById(subVoltageParam.getScale()).getData();
if (Objects.isNull(scaleRes.getData())) { if (Objects.isNull(scaleRes)) {
throw new BusinessException(DeviceResponseEnum.DIC_GET_EMPTY); throw new BusinessException(DeviceResponseEnum.DIC_GET_EMPTY);
} }
Line subVoltage = assembleLine(subVoltageParam.getName(), LineBaseEnum.SUB_V_LEVEL.getCode(), devIdIndex, projectIndex + StrUtil.COMMA + provinceIndex + StrUtil.COMMA + gdIndex + StrUtil.COMMA + subIndex + StrUtil.COMMA + devIdIndex, subVoltageParam.getSort()); Line subVoltage = assembleLine(subVoltageParam.getName(), LineBaseEnum.SUB_V_LEVEL.getCode(), devIdIndex, projectIndex + StrUtil.COMMA + provinceIndex + StrUtil.COMMA + gdIndex + StrUtil.COMMA + subIndex + StrUtil.COMMA + devIdIndex, subVoltageParam.getSort());
@@ -327,7 +303,7 @@ public class TerminalBaseServiceImpl extends ServiceImpl<LineMapper, Line> imple
Voltage voltage = new Voltage(); Voltage voltage = new Voltage();
voltage.setId(subVoltage.getId()); voltage.setId(subVoltage.getId());
voltage.setNum(subVoltageParam.getNum()); voltage.setNum(subVoltageParam.getNum());
voltage.setScale(scaleRes.getData().getId()); voltage.setScale(scaleRes.getId());
voltage.setModel(subVoltageParam.getModel()); voltage.setModel(subVoltageParam.getModel());
voltageMapper.insert(voltage); voltageMapper.insert(voltage);
} else { } else {
@@ -353,15 +329,15 @@ public class TerminalBaseServiceImpl extends ServiceImpl<LineMapper, Line> imple
for (LineParam lineParam : subVoltageParam.getLineParam()) { for (LineParam lineParam : subVoltageParam.getLineParam()) {
if (StrUtil.isBlank(lineParam.getLineIndex()) && StrUtil.isNotBlank(subvIndex)) { if (StrUtil.isBlank(lineParam.getLineIndex()) && StrUtil.isNotBlank(subvIndex)) {
//判断监测点序号是否重复 //判断监测点序号是否重复
if (CollectionUtil.isNotEmpty(listId)) { if (CollectionUtil.isNotEmpty(listLineNum)) {
if (!listId.contains(lineParam.getNum())) { if (!listLineNum.contains(lineParam.getNum())) {
throw new BusinessException(DeviceResponseEnum.LINE_NUM_USE, "监测点序号:" + lineParam.getNum()); throw new BusinessException(DeviceResponseEnum.LINE_NUM_USE, "监测点序号:" + lineParam.getNum());
} }
} else { } else {
throw new BusinessException(DeviceResponseEnum.DEVICE_LINE_BIG); throw new BusinessException(DeviceResponseEnum.DEVICE_LINE_BIG);
} }
//删除与当前线路号重复的项 //删除与当前线路号重复的项
listId.removeIf(lineNo -> lineNo.equals(lineParam.getNum())); listLineNum.removeIf(lineNo -> lineNo.equals(lineParam.getNum()));
HttpResult<DictData> httpScale = dicDataFeignClient.getDicDataById(subVoltageParam.getScale()); HttpResult<DictData> httpScale = dicDataFeignClient.getDicDataById(subVoltageParam.getScale());
Float jcap = DeviceUtil.getJCAPByScale(httpScale.getData().getName()); Float jcap = DeviceUtil.getJCAPByScale(httpScale.getData().getName());
Line line = assembleLine(lineParam.getName(), LineBaseEnum.LINE_LEVEL.getCode(), subvIndex, projectIndex + StrUtil.COMMA + provinceIndex + StrUtil.COMMA + gdIndex + StrUtil.COMMA + subIndex + StrUtil.COMMA + devIdIndex + StrUtil.COMMA + subvIndex, lineParam.getSort()); Line line = assembleLine(lineParam.getName(), LineBaseEnum.LINE_LEVEL.getCode(), subvIndex, projectIndex + StrUtil.COMMA + provinceIndex + StrUtil.COMMA + gdIndex + StrUtil.COMMA + subIndex + StrUtil.COMMA + devIdIndex + StrUtil.COMMA + subvIndex, lineParam.getSort());
@@ -399,6 +375,34 @@ public class TerminalBaseServiceImpl extends ServiceImpl<LineMapper, Line> imple
return true; return true;
} }
/**
* 校验装置
*/
private void checkDev(AddTerminalParam addTerminalParam, String subIndex,LambdaQueryWrapper<Line> lineLambdaQueryWrapper) {
List<String> devNameList = addTerminalParam.getDeviceParam().stream().filter((dev -> dev.getDevIndex() == null)).map(DeviceParam::getName).collect(Collectors.toList());
if (CollectionUtil.isNotEmpty(devNameList)) {
lineLambdaQueryWrapper.eq(Line::getPid, subIndex).in(Line::getName, devNameList);
List<Line> deviceListRes = this.list(lineLambdaQueryWrapper);
//校验当前变电站下是否有同名设备
if (CollectionUtil.isNotEmpty(deviceListRes)) {
List<String> stringList = deviceListRes.stream().map(Line::getName).collect(Collectors.toList());
throw new BusinessException(DeviceResponseEnum.DEVICE_SAME_NAME, String.join(";", stringList));
}
}
List<String> devIpList = addTerminalParam.getDeviceParam().stream().filter((dev -> dev.getDevIndex() == null)).map(DeviceParam::getIp).collect(Collectors.toList());
if (CollectionUtil.isNotEmpty(devIpList)) {
List<Device> deviceListIpRes = lineMapper.getDeviceBySubId(subIndex, devIpList);
//校验当前变电站下的装置是否有相同ip
if (CollectionUtil.isNotEmpty(deviceListIpRes)) {
List<String> stringList = deviceListIpRes.stream().map(Device::getIp).collect(Collectors.toList());
throw new BusinessException(DeviceResponseEnum.DEVICE_SAME_IP, String.join(";", stringList));
}
}
}
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Boolean updateTerminal(UpdateTerminalParam updateTerminalParam) { public Boolean updateTerminal(UpdateTerminalParam updateTerminalParam) {