前置机功能开发

This commit is contained in:
hzj
2025-05-06 14:09:21 +08:00
parent a2fcb97a8d
commit fc75a7084d
12 changed files with 254 additions and 58 deletions

View File

@@ -7,8 +7,10 @@ import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.device.pq.pojo.dto.DeviceInfo;
import com.njcn.device.pq.pojo.dto.NodeProcessDeviceTree;
import com.njcn.device.pq.pojo.param.NodeDeviceParam;
import com.njcn.device.pq.pojo.po.DeviceProcess;
import com.njcn.device.pq.service.NodeDeviceService;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
@@ -49,6 +51,15 @@ public class NodeDeviceController extends BaseController {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
}
@ApiOperation("查询前置-进程-设备-设备树")
@OperateInfo(info = LogEnum.BUSINESS_MEDIUM)
@PostMapping("nodeDeviceTree")
public HttpResult<NodeProcessDeviceTree> nodeDeviceTree(@RequestParam("nodeId") String nodeId){
String methodDescribe = getMethodDescribe("nodeDeviceTree");
NodeProcessDeviceTree list = nodeDeviceService.nodeDeviceTree(nodeId);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
}
@ApiOperation("一键分配装置所属进程号")
@OperateInfo(info = LogEnum.BUSINESS_MEDIUM)
@PostMapping("oneKeyDistribution")
@@ -58,7 +69,14 @@ public class NodeDeviceController extends BaseController {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
}
@ApiOperation("更新设备进程号")
@OperateInfo(info = LogEnum.BUSINESS_MEDIUM)
@PostMapping("updateDeviceProcess")
public HttpResult<Boolean> updateDeviceProcess(@RequestBody DeviceProcess deviceProcess){
String methodDescribe = getMethodDescribe("nodeDeviceTree");
Boolean flag = nodeDeviceService.updateDeviceProcess(deviceProcess);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, flag, methodDescribe);
}
}

View File

@@ -444,23 +444,22 @@ public class TerminalBaseController extends BaseController {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
}
@ApiOperation("请求前置设备设备")
@ApiOperation("请求前置设备重启")
@PostMapping(value = "askRestartDevice")
@OperateInfo(info = LogEnum.BUSINESS_COMMON,operateType = OperateType.DELETE)
@ApiImplicitParams({
@ApiImplicitParam(name = "devId", value = "设备id", required = true),
@ApiImplicitParam(name = "deviceRebootType", value = "重启类型", required = true)
})
public HttpResult<Object> askRestartDevice(@RequestParam("devId")String devId,@RequestParam("deviceRebootType")String deviceRebootType) {
public HttpResult<Object> askRestartDevice(@RequestParam("devId")List<String> devIds,@RequestParam("deviceRebootType")String deviceRebootType,@RequestParam("processNo")Integer processNo) {
String methodDescribe = getMethodDescribe("askRestartDevice");
terminalBaseService.askRestartDevice(devId,deviceRebootType);
terminalBaseService.askRestartDevice(devIds,deviceRebootType,processNo);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
}
@ApiOperation("台账变更推送")
@PostMapping(value = "ledgerChangePush")
@OperateInfo(info = LogEnum.BUSINESS_COMMON,operateType = OperateType.QUERY)
public HttpResult<Object> ledgerChangePush() {
String methodDescribe = getMethodDescribe("ledgerChangePush");
terminalBaseService.ledgerChangePush();

View File

@@ -10,16 +10,19 @@
s1.Name devType,
pq_device.Port port,
pq_line.Name name,
sub.Name subName,
pq_device.Update_Time updateTime,
s2.Name manufacturer,
pq_device.Com_Flag status,
pq_device.Series series,
pq_device_process.process_no processNo,
pq_device.Dev_Key devKey
pq_device.Dev_Key devKey,
pq_node.max_Process_Num maxProcessNum
FROM
pq_device
LEFT JOIN pq_node ON pq_node.Id = pq_device.Node_Id
LEFT JOIN pq_line on pq_device.id = pq_line.id
LEFT JOIN pq_line sub on pq_line.pid = sub.id
LEFT JOIN pq_device_process on pq_device_process.id = pq_device.id
LEFT JOIN sys_dict_data s1 ON pq_device.Dev_Type = s1.id
LEFT JOIN sys_dict_data s2 ON pq_device.Manufacturer = s2.id

View File

@@ -1,7 +1,9 @@
package com.njcn.device.pq.service;
import com.njcn.device.pq.pojo.dto.DeviceInfo;
import com.njcn.device.pq.pojo.dto.NodeProcessDeviceTree;
import com.njcn.device.pq.pojo.param.NodeDeviceParam;
import com.njcn.device.pq.pojo.po.DeviceProcess;
import org.springframework.stereotype.Service;
import java.util.List;
@@ -18,4 +20,8 @@ public interface NodeDeviceService {
List<DeviceInfo> nodeDeviceList(NodeDeviceParam nodeDeviceParam);
void oneKeyDistribution(String nodeId);
NodeProcessDeviceTree nodeDeviceTree(String nodeId);
Boolean updateDeviceProcess(DeviceProcess deviceProcess);
}

View File

@@ -287,7 +287,7 @@ public interface TerminalBaseService {
//通知前置重启设备
void askRestartProcess(Integer processNo,String processType,String deviceRebootType);
void askRestartDevice(String devId, String deviceRebootType);
void askRestartDevice(List<String> devId, String deviceRebootType,Integer processNo);
void ledgerChangePush();
}

View File

@@ -7,6 +7,7 @@ import com.njcn.device.pq.mapper.LineMapper;
import com.njcn.device.pq.mapper.NodeMapper;
import com.njcn.device.pq.pojo.dto.DeviceInfo;
import com.njcn.device.pq.pojo.dto.MonitorInfo;
import com.njcn.device.pq.pojo.dto.NodeProcessDeviceTree;
import com.njcn.device.pq.pojo.param.NodeDeviceParam;
import com.njcn.device.pq.pojo.po.Device;
import com.njcn.device.pq.pojo.po.DeviceProcess;
@@ -14,13 +15,16 @@ import com.njcn.device.pq.pojo.po.Node;
import com.njcn.device.pq.service.DeviceProcessService;
import com.njcn.device.pq.service.IDeviceService;
import com.njcn.device.pq.service.NodeDeviceService;
import com.njcn.redis.utils.RedisUtil;
import lombok.RequiredArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.ListUtils;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -38,6 +42,8 @@ public class NodeDeviceServiceImpl implements NodeDeviceService {
private final LineMapper lineMapper;
private final IDeviceService iDeviceService;
private final DeviceProcessService deviceProcessService;
private final RedisUtil redisUtil;
@Override
public List<DeviceInfo> nodeDeviceList(NodeDeviceParam nodeDeviceParam) {
@@ -82,4 +88,35 @@ public class NodeDeviceServiceImpl implements NodeDeviceService {
deviceProcessService.updateBatchById(collect);
}
@Override
public NodeProcessDeviceTree nodeDeviceTree(String nodeId) {
Node node = nodeMapper.selectById(nodeId);
NodeProcessDeviceTree nodeProcessDeviceTree = new NodeProcessDeviceTree();
nodeProcessDeviceTree.setNode(node);
NodeDeviceParam nodeDeviceParam = new NodeDeviceParam();
nodeDeviceParam.setIp(node.getIp());
List<DeviceInfo> list = nodeMapper.nodeDeviceList(nodeDeviceParam);
List<NodeProcessDeviceTree.ProcessDevice> processDeviceLis = new ArrayList<>();
for (int i = 1; i <= node.getMaxProcessNum(); i++) {
NodeProcessDeviceTree.ProcessDevice processDevice= new NodeProcessDeviceTree.ProcessDevice();
processDevice.setProcessNo(i);
int finalI = i;
List<DeviceInfo> collect = list.stream().filter(deviceInfo -> Objects.equals(deviceInfo.getProcessNo(), finalI)).collect(Collectors.toList());
processDevice.setDeviceInfoList(collect);
processDeviceLis.add(processDevice);
// redisUtil.getObjectByKey()
}
nodeProcessDeviceTree.setProcessDeviceList(processDeviceLis);
return nodeProcessDeviceTree;
}
@Override
public Boolean updateDeviceProcess(DeviceProcess deviceProcess) {
return deviceProcessService.updateById(deviceProcess);
}
}

View File

@@ -40,6 +40,7 @@ import com.njcn.device.pq.pojo.bo.excel.OverLimitExcel;
import com.njcn.device.pq.pojo.bo.excel.TerminalBaseExcel;
import com.njcn.device.pq.pojo.dto.DeviceInfo;
import com.njcn.device.pq.pojo.dto.PollutionSubstationDTO;
import com.njcn.device.pq.pojo.dto.PqsTerminalPushLogDTO;
import com.njcn.device.pq.pojo.param.*;
import com.njcn.device.pq.pojo.param.oracle.*;
import com.njcn.device.pq.pojo.po.*;
@@ -318,10 +319,10 @@ public class TerminalBaseServiceImpl extends ServiceImpl<LineMapper, Line> imple
// .stream()
// .min(Comparator.comparingInt(e -> e.getValue()))
// .map(Map.Entry::getKey);
DeviceProcess deviceProcess = new DeviceProcess();
deviceProcess.setId(device.getId());
deviceProcess.setProcessNo(deviceParam.getProcessNum());
deviceProcessService.saveOrUpdate(deviceProcess);
// DeviceProcess deviceProcess = new DeviceProcess();
// deviceProcess.setId(device.getId());
// deviceProcess.setProcessNo(deviceParam.getProcessNum());
// deviceProcessService.saveOrUpdate(deviceProcess);
//装置功能
List<DictData> funList = dicDataFeignClient.getDicDataByTypeName(DicDataTypeEnum.DEV_FUN.getName()).getData();
if (CollectionUtil.isEmpty(funList)) {
@@ -706,9 +707,15 @@ public class TerminalBaseServiceImpl extends ServiceImpl<LineMapper, Line> imple
BeanUtils.copyProperties(updateDeviceParam, deviceDetail);
deviceDetail.setId(updateDeviceParam.getDevIndex());
coderM3d(deviceDetail,true);
this.updateById(device);
deviceMapper.updateById(deviceDetail);
// DeviceProcess deviceProcess = new DeviceProcess();
// deviceProcess.setId(updateDeviceParam.getDevIndex());
// deviceProcess.setProcessNo(updateDeviceParam.getProcessNum());
// deviceProcessService.saveOrUpdate(deviceProcess);
}
//母线
@@ -1416,7 +1423,9 @@ public class TerminalBaseServiceImpl extends ServiceImpl<LineMapper, Line> imple
// 2. 查询并删除所有省份
List<Line> provinces = findChildren(project.getId());
if (CollectionUtil.isEmpty(provinces)) return;
if (CollectionUtil.isEmpty(provinces)) {
return;
}
List<String> provinceIds = provinces.stream()
.map(Line::getId)
@@ -1433,7 +1442,9 @@ public class TerminalBaseServiceImpl extends ServiceImpl<LineMapper, Line> imple
// 1. 查询并删除所有供电公司
List<Line> powerCompanies = findChildren(provinceId);
if (CollectionUtil.isEmpty(powerCompanies)) return;
if (CollectionUtil.isEmpty(powerCompanies)) {
return;
}
List<String> companyIds = powerCompanies.stream()
.map(Line::getId)
@@ -1449,7 +1460,9 @@ public class TerminalBaseServiceImpl extends ServiceImpl<LineMapper, Line> imple
this.removeById(companyId);
// 1. 查询并删除所有变电站
List<Line> substations = findChildren(companyId);
if (CollectionUtil.isEmpty(substations)) return;
if (CollectionUtil.isEmpty(substations)) {
return;
}
List<String> substationIds = substations.stream()
.map(Line::getId)
@@ -1467,7 +1480,9 @@ public class TerminalBaseServiceImpl extends ServiceImpl<LineMapper, Line> imple
substationMapper.deleteById(substationId);
// 1. 查询并删除所有装置
List<Line> devices = findChildren(substationId);
if (CollectionUtil.isEmpty(devices)) return;
if (CollectionUtil.isEmpty(devices)) {
return;
}
logsList.addAll(devices);
@@ -1486,10 +1501,12 @@ public class TerminalBaseServiceImpl extends ServiceImpl<LineMapper, Line> imple
private void deleteDeviceAndChildren(String deviceId,List<Line> logsList) {
this.removeById(deviceId);
deviceMapper.deleteById(deviceId);
deviceProcessService.removeById(deviceId);
// 1. 查询并删除所有母线
List<Line> busbars = findChildren(deviceId);
if (CollectionUtil.isEmpty(busbars)) return;
if (CollectionUtil.isEmpty(busbars)) {
return;
}
List<String> busbarIds = busbars.stream()
.map(Line::getId)
@@ -1510,7 +1527,9 @@ public class TerminalBaseServiceImpl extends ServiceImpl<LineMapper, Line> imple
voltageMapper.deleteById(busbarId);
// 1. 查询并删除所有监测点
List<Line> monitoringPoints = findChildren(busbarId);
if (CollectionUtil.isEmpty(monitoringPoints)) return;
if (CollectionUtil.isEmpty(monitoringPoints)) {
return;
}
logsList.addAll(monitoringPoints);
@@ -3641,65 +3660,99 @@ public class TerminalBaseServiceImpl extends ServiceImpl<LineMapper, Line> imple
@Override
@Async
public void askRestartDevice(String devId, String deviceRebootType) {
DeviceProcess one = deviceProcessService.lambdaQuery().eq(DeviceProcess::getId, devId).one();
// @Async
public void askRestartDevice(List<String> devId, String deviceRebootType,Integer processNum) {
DeviceRebootMessage deviceRebootMessage = new DeviceRebootMessage();
deviceRebootMessage.setCode(deviceRebootType);
if(Objects.equals(deviceRebootType, DeviceRebootType.DELETE_TERMINAL)){
DeviceRebootMessage.DeviceInfo deviceInfo = new DeviceRebootMessage.DeviceInfo();
deviceInfo.setId(devId);
List<DeviceRebootMessage.DeviceInfo> list = new ArrayList<>();
list.add(deviceInfo);
devId.forEach(temp->{
DeviceRebootMessage.DeviceInfo deviceInfo = new DeviceRebootMessage.DeviceInfo();
deviceInfo.setId(temp);
list.add(deviceInfo);
});
deviceRebootMessage.setData(list);
deviceRebootMessage.setIndex(one.getProcessNo());
deviceRebootMessage.setIndex(processNum);
produceFeignClient.askRestartDevice(deviceRebootMessage);
//删除设备进程关系
deviceProcessService.removeById(devId);
deviceProcessService.removeByIds(devId);
}else {
NodeDeviceParam nodeDeviceParam = new NodeDeviceParam();
nodeDeviceParam.setDevId(devId);
List<DeviceInfo> deviceInfos = nodeDeviceService.nodeDeviceList(nodeDeviceParam);
if (CollectionUtil.isNotEmpty(deviceInfos)){
deviceRebootMessage.setIndex(one.getProcessNo());
DeviceInfo deviceInfo = deviceInfos.get(0);
DeviceRebootMessage.DeviceInfo deviceInfo1 = new DeviceRebootMessage.DeviceInfo();
BeanUtils.copyProperties(deviceInfo,deviceInfo1);
List<DeviceRebootMessage.DeviceInfo.MonitorInfo> monitorInfoList=deviceInfo.getMonitorData().stream().map(tempMonitorInfo->{
DeviceRebootMessage.DeviceInfo.MonitorInfo m = new DeviceRebootMessage.DeviceInfo.MonitorInfo();
BeanUtils.copyProperties(tempMonitorInfo,m);
return m;
}).collect(Collectors.toList());
deviceInfo1.setMonitorData(monitorInfoList);
List<DeviceRebootMessage.DeviceInfo> list = new ArrayList<>();
list.add(deviceInfo1);
List<DeviceRebootMessage.DeviceInfo> list = new ArrayList<>();
devId.forEach(temp->{
NodeDeviceParam nodeDeviceParam = new NodeDeviceParam();
nodeDeviceParam.setDevId(temp);
List<DeviceInfo> deviceInfos = nodeDeviceService.nodeDeviceList(nodeDeviceParam);
if (CollectionUtil.isNotEmpty(deviceInfos)) {
deviceRebootMessage.setIndex(processNum);
DeviceInfo deviceInfo = deviceInfos.get(0);
DeviceRebootMessage.DeviceInfo deviceInfo1 = new DeviceRebootMessage.DeviceInfo();
BeanUtils.copyProperties(deviceInfo, deviceInfo1);
List<DeviceRebootMessage.DeviceInfo.MonitorInfo> monitorInfoList = deviceInfo.getMonitorData().stream().map(tempMonitorInfo -> {
DeviceRebootMessage.DeviceInfo.MonitorInfo m = new DeviceRebootMessage.DeviceInfo.MonitorInfo();
BeanUtils.copyProperties(tempMonitorInfo, m);
return m;
}).collect(Collectors.toList());
deviceInfo1.setMonitorData(monitorInfoList);
list.add(deviceInfo1);
}
});
deviceRebootMessage.setData(list);
produceFeignClient.askRestartDevice(deviceRebootMessage);
}
}
}
@Override
@Transactional
public void ledgerChangePush() {
QueryWrapper<PqsTerminalLogs> queryWrapper= new QueryWrapper<PqsTerminalLogs>();
QueryWrapper<PqsTerminalLogs> queryWrapper= new QueryWrapper<>();
queryWrapper.lambda().eq(PqsTerminalLogs::getState, 1).eq(PqsTerminalLogs::getIsPush, 0).in(PqsTerminalLogs::getTerminalType,Stream.of(4,6).collect(Collectors.toList()));
List<PqsTerminalLogs> list = pqsTerminalLogsMapper.selectList(queryWrapper);
// list.forEach(temp->{
// PqsTerminalPushLogDTO pqsTerminalPushLogDTO = new PqsTerminalPushLogDTO();
// if(Objects.equals(temp.getTerminalType(),6)){
// pqsTerminalPushLogDTO.setId(temp.getId());
// pqsTerminalPushLogDTO.setNodeId();
// pqsTerminalPushLogDTO.setProcessNum();
// pqsTerminalPushLogDTO.setDevId();
// pqsTerminalPushLogDTO.setOperateType(DeviceRebootType.LEDGER_MODIFY);
//
//
// }
//
// });
if(!CollectionUtils.isEmpty(list)){
//一个是删除操作,其余都算终端设备更新操作
List<PqsTerminalLogs> delDevice = list.stream().filter(temp -> Objects.equals(temp.getOperateType(), Param.DEL) && Objects.equals(temp.getTerminalType(), 4)).distinct().collect(Collectors.toList());
List<String> delDevIds = new ArrayList<>();
if(!CollectionUtils.isEmpty(delDevice)){
delDevice.forEach(temp->{
this.askRestartDevice(temp.getObjIndex(), DeviceRebootType.DELETE_TERMINAL);
delDevIds.add(temp.getObjIndex());
}
);
List<String> collect = delDevice.stream().map(PqsTerminalLogs::getObjIndex).collect(Collectors.toList());
delDevIds.addAll(collect);
List<DeviceProcess> deviceProcessList = deviceProcessService.lambdaQuery().in(DeviceProcess::getId, collect).list();
//根据进程号分组每个进程发送一条信息给前置如果该进程修改的设备数超过10台则直接重启该进程
Map<Integer, List<DeviceProcess>> collect1 = deviceProcessList.stream().collect(Collectors.groupingBy(DeviceProcess::getProcessNo));
//根据进程号
collect1.forEach((k,v)->{
// this.askRestartDevice(temp.getObjIndex(), DeviceRebootType.DELETE_TERMINAL);
if(v.size()>=10){
// this.askRestartProcess(k,);
}else {
// this.askRestartDevice();
}
});
}
List<String> updateDevIds = new ArrayList<>();
List<String> lineIds = list.stream().filter(temp -> Objects.equals(temp.getTerminalType(), 6)).map(PqsTerminalLogs::getObjIndex).distinct().collect(Collectors.toList());
@@ -3719,7 +3772,7 @@ public class TerminalBaseServiceImpl extends ServiceImpl<LineMapper, Line> imple
updateDevIds.removeAll(delDevIds);
}
updateDevIds.stream().distinct().forEach(temp->{
this.askRestartDevice(temp, DeviceRebootType.LEDGER_MODIFY);
// this.askRestartDevice(temp, DeviceRebootType.LEDGER_MODIFY);
}
);
list.forEach(temp->{