终端相关代码修改

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字典表
*/
@ApiModelProperty(name = "comType",value = "通讯类型",required = true)
@ApiModelProperty(name = "frontType",value = "通讯类型",required = true)
@NotBlank(message = "通讯类型不能为空")
private String comType;
private String frontType;
@ApiModelProperty(name = "ip",value = "装置ip",required = true)
@NotBlank(message = "设备ip不能为空")

View File

@@ -64,7 +64,7 @@ public class TerminalBaseController extends BaseController {
@ApiOperation("终端新增操作")
@OperateInfo(operateType = OperateType.ADD, info = LogEnum.BUSINESS_MEDIUM)
@PostMapping("addTerminal")
public HttpResult addTerminal(@Valid @RequestBody AddTerminalParam addTerminalParam) {
public HttpResult<Object> addTerminal(@Valid @RequestBody AddTerminalParam addTerminalParam) {
String methodDescribe = getMethodDescribe("addTerminal");
//装置母线监测点相关检验
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());
this.baseMapper.insert(line);
projectIndex = line.getId();
} else {
//throw new BusinessException(DeviceResponseEnum.REQUEST_DATA_ERROR);
}
}
//省份
if (Objects.nonNull(addTerminalParam.getProvinceParam())) {
if (StrUtil.isBlank(provinceIndex) && StrUtil.isNotBlank(projectIndex)) {
HttpResult<Area> provinceDic = areaFeignClient.selectIdArea(addTerminalParam.getProvinceParam().getName());
Area result = provinceDic.getData();
Area result = areaFeignClient.selectIdArea(addTerminalParam.getProvinceParam().getName()).getData();
if (Objects.isNull(result)) {
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());
this.baseMapper.insert(province);
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 (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<>();
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));
}
}
if (CollectionUtil.isNotEmpty(addTerminalParam.getDeviceParam()) && StrUtil.isNotBlank(subIndex)) {
//校验变电站下的装置名称ip是否重复
checkDev(addTerminalParam, subIndex,lineLambdaQueryWrapper);
for (DeviceParam deviceParam : addTerminalParam.getDeviceParam()) {
//用于记录装置id
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
if (CollectionUtil.isNotEmpty(deviceParam.getSubVoltageParam())) {
for (SubVoltageParam subVoltage : deviceParam.getSubVoltageParam()) {
@@ -256,8 +233,7 @@ public class TerminalBaseServiceImpl extends ServiceImpl<LineMapper, Line> imple
deviceDetail.setUpdateTime(LocalDateTime.now());
deviceMapper.insert(deviceDetail);
//装置功能
HttpResult<List<DictData>> httpResult = dicDataFeignClient.getDicDataByTypeName(DicDataTypeEnum.DEV_FUN.getName());
List<DictData> funList = httpResult.getData();
List<DictData> funList = dicDataFeignClient.getDicDataByTypeName(DicDataTypeEnum.DEV_FUN.getName()).getData();
if (CollectionUtil.isEmpty(funList)) {
throw new BusinessException(DeviceResponseEnum.DIC_GET_EMPTY);
}
@@ -281,7 +257,7 @@ public class TerminalBaseServiceImpl extends ServiceImpl<LineMapper, Line> imple
if (CollectionUtil.isNotEmpty(lineDetails)) {
lineNum = lineNum + lineDetails.size();
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;
if (StrUtil.isBlank(subVoltageParam.getSubvIndex()) && StrUtil.isNotBlank(devIdIndex)) {
HttpResult<DictData> scaleRes = dicDataFeignClient.getDicDataById(subVoltageParam.getScale());
if (Objects.isNull(scaleRes.getData())) {
DictData scaleRes = dicDataFeignClient.getDicDataById(subVoltageParam.getScale()).getData();
if (Objects.isNull(scaleRes)) {
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());
@@ -327,7 +303,7 @@ public class TerminalBaseServiceImpl extends ServiceImpl<LineMapper, Line> imple
Voltage voltage = new Voltage();
voltage.setId(subVoltage.getId());
voltage.setNum(subVoltageParam.getNum());
voltage.setScale(scaleRes.getData().getId());
voltage.setScale(scaleRes.getId());
voltage.setModel(subVoltageParam.getModel());
voltageMapper.insert(voltage);
} else {
@@ -353,15 +329,15 @@ public class TerminalBaseServiceImpl extends ServiceImpl<LineMapper, Line> imple
for (LineParam lineParam : subVoltageParam.getLineParam()) {
if (StrUtil.isBlank(lineParam.getLineIndex()) && StrUtil.isNotBlank(subvIndex)) {
//判断监测点序号是否重复
if (CollectionUtil.isNotEmpty(listId)) {
if (!listId.contains(lineParam.getNum())) {
if (CollectionUtil.isNotEmpty(listLineNum)) {
if (!listLineNum.contains(lineParam.getNum())) {
throw new BusinessException(DeviceResponseEnum.LINE_NUM_USE, "监测点序号:" + lineParam.getNum());
}
} else {
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());
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());
@@ -399,6 +375,34 @@ public class TerminalBaseServiceImpl extends ServiceImpl<LineMapper, Line> imple
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
@Transactional(rollbackFor = Exception.class)
public Boolean updateTerminal(UpdateTerminalParam updateTerminalParam) {