Compare commits
132 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
74caf848c2 | ||
|
|
cf96b8ed83 | ||
|
|
3213bc9f84 | ||
| 3b6115159c | |||
|
|
1859f22109 | ||
|
|
f45a344db8 | ||
|
|
14f3ab52bb | ||
|
|
3bc797f23e | ||
|
|
d451763043 | ||
| dcd848984a | |||
| 487aeec04a | |||
| f589e2278a | |||
|
|
d43c38cd7c | ||
|
|
82afff2a6e | ||
|
|
7f5c132573 | ||
|
|
39f890dd4c | ||
|
|
1d8ceb15df | ||
|
|
68381da345 | ||
| 2277e015ae | |||
| 2b9cce41aa | |||
| 338e426017 | |||
|
|
6c9487a1e6 | ||
|
|
63831fc2d1 | ||
|
|
413bc98526 | ||
|
|
8c85e6c70b | ||
|
|
514f31a50a | ||
| 270b89ef2a | |||
|
|
705372f918 | ||
|
|
c4443c5669 | ||
| 9706c91c3f | |||
| 3a582d18d6 | |||
| 8dda33af0b | |||
|
|
5f694c88bf | ||
| 8f0b923744 | |||
| bc33f78d0c | |||
|
|
603d5cdd5f | ||
|
|
a81439b1d2 | ||
|
|
5dafcad3fa | ||
|
|
b0f54b0cde | ||
| d37d44123f | |||
|
|
8835249c1b | ||
|
|
5cc542e624 | ||
| e6d157e35f | |||
| 0e682e8d33 | |||
| 8760821aec | |||
|
|
7d88776633 | ||
|
|
1e7647dadc | ||
| b8a7f98cec | |||
| 97e009c84c | |||
|
|
786586e40c | ||
|
|
656fe2fbc3 | ||
| 2d5bb9694f | |||
|
|
e36652f930 | ||
| e9a294acdb | |||
| 3e90016ad5 | |||
| 5529093453 | |||
| 0232eee131 | |||
|
|
4c439e299c | ||
|
|
34e0f9f424 | ||
| 31a46b8df6 | |||
| 441d2fb39b | |||
| 1cdd1cbbe1 | |||
|
|
af9026b899 | ||
|
|
dbc07b2cf3 | ||
|
|
861f947499 | ||
| 8bc21dc861 | |||
|
|
532ad9fcb5 | ||
|
|
5fde9586fc | ||
|
|
878a2e68af | ||
|
|
e059e3c2af | ||
| 4f7bad232a | |||
|
|
bc0e93b522 | ||
| e432501e99 | |||
|
|
e48efef8d6 | ||
|
|
b801497a33 | ||
|
|
769e967815 | ||
|
|
379e4a33ff | ||
|
|
208ba4984b | ||
|
|
35ee76888d | ||
|
|
048021bb57 | ||
|
|
843d97e367 | ||
|
|
176a43d865 | ||
|
|
f287498659 | ||
|
|
3e34faed90 | ||
|
|
37aba2181b | ||
|
|
7335ffe445 | ||
|
|
43c1d56db3 | ||
|
|
2cffee4287 | ||
|
|
c125f20de4 | ||
|
|
f7ea59ce1b | ||
|
|
614849de64 | ||
|
|
d94c03cba1 | ||
|
|
44311fc6ec | ||
|
|
e4fa161e5a | ||
|
|
332c8909ff | ||
|
|
4c2c4d4ede | ||
|
|
c104834ea1 | ||
|
|
aa11314a07 | ||
|
|
8206a51c6c | ||
|
|
f4109275d7 | ||
|
|
f41595b727 | ||
|
|
f284b7a325 | ||
|
|
424b319c38 | ||
|
|
355ba48418 | ||
| 61b6b61a46 | |||
|
|
ea21d631c9 | ||
| 8f4483bbef | |||
|
|
2701816ebe | ||
| 8e75433282 | |||
| 53a4816272 | |||
|
|
b0db65a5cb | ||
|
|
4e3452a63c | ||
|
|
b546128183 | ||
|
|
2075d90760 | ||
|
|
63ac668df9 | ||
|
|
03e74ecb52 | ||
|
|
efebbc5305 | ||
|
|
442b80e7d9 | ||
|
|
712ebfaf24 | ||
|
|
42472dd496 | ||
|
|
b605605c13 | ||
|
|
81357906ca | ||
|
|
74b3e6a993 | ||
|
|
f3b561f8e9 | ||
|
|
b1e881798b | ||
| f0e82c458c | |||
|
|
05cdb20594 | ||
|
|
e640bd4516 | ||
|
|
bb5e5dfec5 | ||
| da38577e70 | |||
|
|
8896360473 | ||
| d0d21e84b8 |
59
detection/pom.xml
Normal file
59
detection/pom.xml
Normal file
@@ -0,0 +1,59 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.njcn.gather</groupId>
|
||||
<artifactId>CN_Gather</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>detection</artifactId>
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>njcn-common</artifactId>
|
||||
<version>0.0.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>mybatis-plus</artifactId>
|
||||
<version>0.0.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>spingboot2.3.12</artifactId>
|
||||
<version>2.3.12</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-all</artifactId>
|
||||
<version>4.1.68.Final</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.njcn.gather</groupId>
|
||||
<artifactId>device</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>1.2.83</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.njcn.gather</groupId>
|
||||
<artifactId>storage</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,128 @@
|
||||
package com.njcn.gather.detection.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
|
||||
import com.njcn.gather.detection.pojo.po.DevData;
|
||||
import com.njcn.gather.detection.service.PreDetectionService;
|
||||
import com.njcn.gather.detection.service.impl.DetectionServiceImpl;
|
||||
import com.njcn.gather.detection.util.socket.MsgUtil;
|
||||
import com.njcn.gather.device.device.pojo.vo.PreDetection;
|
||||
import com.njcn.gather.device.device.service.IPqDevService;
|
||||
import com.njcn.gather.device.script.pojo.param.PqScriptIssueParam;
|
||||
import com.njcn.gather.device.script.pojo.po.SourceIssue;
|
||||
import com.njcn.gather.device.script.service.IPqScriptDtlsService;
|
||||
import com.njcn.gather.system.dictionary.pojo.enums.DictDataEnum;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import com.njcn.web.utils.HttpResultUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@Api(tags = "预检测")
|
||||
@RestController
|
||||
@RequestMapping("/prepare")
|
||||
@RequiredArgsConstructor
|
||||
public class PreDetectionController extends BaseController {
|
||||
|
||||
private final PreDetectionService preDetectionService;
|
||||
|
||||
private final DetectionServiceImpl detectionServiceImpl;
|
||||
|
||||
private final IPqScriptDtlsService pqScriptDtlsService;
|
||||
|
||||
private final IPqDevService iPqDevService;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 终止预检测
|
||||
*/
|
||||
@PostMapping("/closePreTest")
|
||||
@OperateInfo
|
||||
@ApiOperation("终止预检测")
|
||||
@ApiImplicitParam(name = "param", value = "查询参数", required = true)
|
||||
public HttpResult<String> closePreTest(@RequestBody PreDetectionParam param){
|
||||
String methodDescribe = getMethodDescribe("closePreTest");
|
||||
preDetectionService.closePreTest(param);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
|
||||
/**
|
||||
* 开始预检测
|
||||
*/
|
||||
@PostMapping("/startPreTest")
|
||||
@OperateInfo
|
||||
@ApiOperation("开始预检测")
|
||||
@ApiImplicitParam(name = "param", value = "查询参数", required = true)
|
||||
public HttpResult<String> startPreTest(@RequestBody PreDetectionParam param){
|
||||
String methodDescribe = getMethodDescribe("startPreTest");
|
||||
preDetectionService.sourceCommunicationCheck(param);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 测试
|
||||
*/
|
||||
@PostMapping("/startTest")
|
||||
@OperateInfo
|
||||
@ApiOperation("测试")
|
||||
@ApiImplicitParam(name = "param", value = "查询参数", required = true)
|
||||
public HttpResult<String> startTest(@RequestBody PreDetectionParam param){
|
||||
String methodDescribe = getMethodDescribe("startTest");
|
||||
//preDetectionService.startTest(param);
|
||||
|
||||
String a = "{\"Time\":\"2025-01-02T14:14:44.958\",\"ID\":\"192.168.1.186_1\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.035600\"}}],\"SqlDataHarm\":[]}";
|
||||
String b = "{\"Time\":\"2025-01-02T14:14:39.004\",\"ID\":\"192.168.1.203_1\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.000000\"}}],\"SqlDataHarm\":[]}";
|
||||
String c = "{\"Time\":\"2025-01-02T14:14:39.004\",\"ID\":\"192.168.1.203_2\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.000000\"}}],\"SqlDataHarm\":[]}";
|
||||
String d = "{\"Time\":\"2025-01-02T14:14:47.956\",\"ID\":\"192.168.1.186_1\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.032300\"}}],\"SqlDataHarm\":[]}";
|
||||
String e = "{\"Time\":\"2025-01-02T14:14:42.004\",\"ID\":\"192.168.1.203_1\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.000000\"}}],\"SqlDataHarm\":[]}";
|
||||
String f = "{\"Time\":\"2025-01-02T14:14:42.004\",\"ID\":\"192.168.1.203_2\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.000000\"}}],\"SqlDataHarm\":[]}";
|
||||
|
||||
List<DevData> devDataList = new ArrayList<>();
|
||||
DevData aa = JSON.parseObject(a, DevData.class);
|
||||
DevData bb = JSON.parseObject(a, DevData.class);
|
||||
DevData cc = JSON.parseObject(a, DevData.class);
|
||||
DevData dd = JSON.parseObject(a, DevData.class);
|
||||
DevData ee = JSON.parseObject(a, DevData.class);
|
||||
DevData ff = JSON.parseObject(a, DevData.class);
|
||||
devDataList.add(aa);
|
||||
devDataList.add(bb);
|
||||
devDataList.add(cc);
|
||||
devDataList.add(dd);
|
||||
devDataList.add(ee);
|
||||
devDataList.add(ff);
|
||||
|
||||
PqScriptIssueParam issueParam = new PqScriptIssueParam();
|
||||
issueParam.setPlanId(param.getPlanId());
|
||||
issueParam.setSourceId(param.getSourceId());
|
||||
issueParam.setDevIds(param.getDevIds());
|
||||
issueParam.setScriptId("a303b2224845fcc6f60198b8ca23dca9");
|
||||
issueParam.setIsPhaseSequence(false);
|
||||
SourceIssue sourceIssues = pqScriptDtlsService.listSourceIssue(issueParam).get(0);
|
||||
|
||||
List<PreDetection> pqDevList = iPqDevService.getDevInfo(param.getDevIds());
|
||||
Map<String, String> devIdMapComm = pqDevList.stream().collect(Collectors.toMap(PreDetection::getDevIP, PreDetection::getDevId));
|
||||
|
||||
detectionServiceImpl.text(devDataList,param.getErrorSysId(),devIdMapComm,sourceIssues, DictDataEnum.AT_WILL_VALUE);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.njcn.gather.detection.controller;
|
||||
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import com.njcn.web.utils.HttpResultUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* @author wr
|
||||
* @description
|
||||
* @date 2024/12/10 14:25
|
||||
*/
|
||||
@Slf4j
|
||||
@Api(tags = "守时检测")
|
||||
@RestController
|
||||
@RequestMapping("/punctuality")
|
||||
@RequiredArgsConstructor
|
||||
public class PunctualityController extends BaseController {
|
||||
|
||||
// private final PunctualityService punctualityService;
|
||||
|
||||
@OperateInfo
|
||||
@PostMapping("/deliveryTime")
|
||||
@ApiOperation("下发守时检测")
|
||||
@ApiImplicitParam(name = "queryParam", value = "查询参数", required = true)
|
||||
public HttpResult<?> list(@RequestBody Object param) {
|
||||
String methodDescribe = getMethodDescribe("list");
|
||||
// punctualityService.triggerTimeMark();
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,795 @@
|
||||
package com.njcn.gather.detection.handler;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum;
|
||||
import com.njcn.gather.detection.pojo.enums.SourceResponseCodeEnum;
|
||||
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
|
||||
import com.njcn.gather.detection.pojo.po.DevData;
|
||||
import com.njcn.gather.detection.pojo.po.SourceCompareDev;
|
||||
import com.njcn.gather.detection.pojo.vo.DevLineTestResult;
|
||||
import com.njcn.gather.detection.pojo.vo.SocketDataMsg;
|
||||
import com.njcn.gather.detection.pojo.vo.SocketMsg;
|
||||
import com.njcn.gather.detection.pojo.vo.WebSocketVO;
|
||||
import com.njcn.gather.detection.service.impl.DetectionServiceImpl;
|
||||
import com.njcn.gather.detection.util.socket.MsgUtil;
|
||||
import com.njcn.gather.detection.util.socket.SocketManager;
|
||||
import com.njcn.gather.detection.util.socket.web.WebSocketHandler;
|
||||
import com.njcn.gather.device.device.pojo.vo.PreDetection;
|
||||
import com.njcn.gather.device.device.service.IPqDevService;
|
||||
import com.njcn.gather.device.script.pojo.param.PqScriptIssueParam;
|
||||
import com.njcn.gather.device.script.pojo.po.SourceIssue;
|
||||
import com.njcn.gather.device.script.service.IPqScriptDtlsService;
|
||||
import com.njcn.gather.storage.pojo.po.AdHarmonicResult;
|
||||
import com.njcn.gather.storage.pojo.po.AdNonHarmonicResult;
|
||||
import com.njcn.gather.storage.service.DetectionDataDealService;
|
||||
import com.njcn.gather.system.dictionary.pojo.enums.DictDataEnum;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.DateTimeParseException;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SocketDevResponseService {
|
||||
|
||||
|
||||
private final String handlerStr = "_Dev";
|
||||
private final String handlerSourceStr = "_Source";
|
||||
|
||||
private final WebSocketHandler webSocketHandler;
|
||||
private final IPqDevService iPqDevService;
|
||||
private final IPqScriptDtlsService scriptDtlsService;
|
||||
private final IPqScriptDtlsService pqScriptDtlsService;
|
||||
private final DetectionServiceImpl detectionServiceImpl;
|
||||
|
||||
private final DetectionDataDealService detectionDataDealService;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 存储的装置相序数据
|
||||
*/
|
||||
List<DevData> devInfo = new ArrayList<>();
|
||||
|
||||
Map<String, DevData> devDataMap = new HashMap<>();
|
||||
/**
|
||||
* 成功结束的装置
|
||||
*/
|
||||
List<String> success = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* 所有装置通道信息
|
||||
*/
|
||||
List<String> monitorIdListComm = new ArrayList<>();
|
||||
|
||||
|
||||
private List<PreDetection> devList = new ArrayList<>();
|
||||
/**
|
||||
* 装置名称
|
||||
*/
|
||||
Map<String, String> devNameMapComm = new HashMap<>();
|
||||
/**
|
||||
* 装置id
|
||||
*/
|
||||
Map<String, String> devIdMapComm = new HashMap<>();
|
||||
/**
|
||||
* 成功结束的装置
|
||||
*/
|
||||
List<String> successComm = new ArrayList<>();
|
||||
|
||||
|
||||
/**
|
||||
* 保存成功的协议
|
||||
*/
|
||||
List<String> successXieyi = new ArrayList<>();
|
||||
List<String> successXieyi3 = new ArrayList<>();
|
||||
|
||||
|
||||
List<AdNonHarmonicResult> adNonHarmonicResultList = new ArrayList<>();
|
||||
|
||||
|
||||
public void deal(PreDetectionParam param, String msg) throws Exception{
|
||||
SocketDataMsg socketDataMsg = MsgUtil.socketDataMsg(msg);
|
||||
String[] tem = socketDataMsg.getRequestId().split("&&");
|
||||
|
||||
SourceOperateCodeEnum sourceOperateCodeEnum = SourceOperateCodeEnum.getDictDataEnumByCode(tem[0]);
|
||||
switch (sourceOperateCodeEnum) {
|
||||
//设备通讯校验
|
||||
case YJC_SBTXJY:
|
||||
devComm(socketDataMsg, param, msg);
|
||||
break;
|
||||
//协议校验
|
||||
case YJC_XYJY:
|
||||
devXieyi(socketDataMsg, param, msg);
|
||||
break;
|
||||
//相序校验
|
||||
case YJC_XUJY:
|
||||
devXu(param, socketDataMsg);
|
||||
break;
|
||||
//获取实时数据
|
||||
case FORMAL_REAL:
|
||||
realDeal(param, socketDataMsg);
|
||||
break;
|
||||
//退出关闭
|
||||
case QUITE:
|
||||
quitDeal(socketDataMsg, param, msg);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 装置通讯检测
|
||||
*/
|
||||
private void devComm(SocketDataMsg socketDataMsg, PreDetectionParam param, String msg) {
|
||||
SourceResponseCodeEnum dictDataEnumByCode = SourceResponseCodeEnum.getDictDataEnumByCode(socketDataMsg.getCode());
|
||||
String s = param.getUserPageId() + handlerStr;
|
||||
SocketMsg<String> socketMsg = new SocketMsg<>();
|
||||
switch (Objects.requireNonNull(dictDataEnumByCode)) {
|
||||
case SUCCESS:
|
||||
//通讯校验成功
|
||||
webSocketHandler.sendMsgToUser(param.getUserPageId(), MsgUtil.msgToWebData(socketDataMsg, devNameMapComm, 1));
|
||||
String mId = JSON.parseObject(msg).get("data").toString();
|
||||
successComm.add(mId);
|
||||
|
||||
System.out.println(successComm.size() + "=====" + monitorIdListComm.size());
|
||||
if (successComm.size() == monitorIdListComm.size()) {
|
||||
|
||||
SocketDataMsg temMsg = new SocketDataMsg();
|
||||
temMsg.setCode(SourceResponseCodeEnum.DEV_COMM_ALL_SUCCESS.getCode());
|
||||
temMsg.setOperateCode(SourceOperateCodeEnum.DEV_INIT_GATHER_01.getValue());
|
||||
temMsg.setRequestId(SourceOperateCodeEnum.YJC_SBTXJY.getValue());
|
||||
webSocketHandler.sendMsgToUser(param.getUserPageId(), JSON.toJSONString(temMsg));
|
||||
|
||||
|
||||
//开始进行协议校验
|
||||
List<PreDetection> devList = iPqDevService.getDevInfo(param.getDevIds());
|
||||
Map<String, List<PreDetection>> map = new HashMap<>(1);
|
||||
map.put("deviceList", devList);
|
||||
String jsonString = JSON.toJSONString(map);
|
||||
socketMsg.setRequestId(SourceOperateCodeEnum.YJC_XYJY.getValue());
|
||||
socketMsg.setOperateCode(SourceOperateCodeEnum.DEV_INIT_GATHER_02.getValue());
|
||||
socketMsg.setData(jsonString);
|
||||
String json = JSON.toJSONString(socketMsg);
|
||||
|
||||
System.out.println("开始协议校验++++++++++");
|
||||
SocketManager.sendMsg(s, json);
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
case UNPROCESSED_BUSINESS:
|
||||
webSocketHandler.sendMsgToUser(param.getUserPageId(), JSON.toJSONString(socketDataMsg));
|
||||
break;
|
||||
|
||||
case DEV_ERROR:
|
||||
webSocketHandler.sendMsgToUser(param.getUserPageId(), MsgUtil.msgToWebData(socketDataMsg, devNameMapComm, 2));
|
||||
quitSend(param);
|
||||
quitSendSource(param);
|
||||
break;
|
||||
case DEV_TARGET:
|
||||
webSocketHandler.sendMsgToUser(param.getUserPageId(), MsgUtil.msgToWebData(socketDataMsg, devNameMapComm, 2));
|
||||
quitSend(param);
|
||||
quitSendSource(param);
|
||||
break;
|
||||
case RE_OPERATE:
|
||||
//出现已经初始化情况,发送用户用户确认是否继续检测
|
||||
webSocketHandler.sendMsgToUser(param.getUserPageId(), JSON.toJSONString(socketDataMsg));
|
||||
quitSend(param);
|
||||
break;
|
||||
case NO_INIT_DEV:
|
||||
//发起关闭操作
|
||||
quitSend(param);
|
||||
break;
|
||||
default:
|
||||
WebSocketVO webSocketVO = new WebSocketVO();
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 装置协议检测
|
||||
*/
|
||||
private void devXieyi(SocketDataMsg socketDataMsg, PreDetectionParam param, String msg) {
|
||||
SourceResponseCodeEnum dictDataEnumByCode = SourceResponseCodeEnum.getDictDataEnumByCode(socketDataMsg.getCode());
|
||||
SocketMsg socketMsg = new SocketMsg();
|
||||
String s = param.getUserPageId() + handlerStr;
|
||||
|
||||
switch (Objects.requireNonNull(dictDataEnumByCode)) {
|
||||
case SUCCESS:
|
||||
webSocketHandler.sendMsgToUser(param.getUserPageId(), MsgUtil.msgToWebData(socketDataMsg, devNameMapComm, 2));
|
||||
if (socketDataMsg.getOperateCode().equals(SourceOperateCodeEnum.DEV_INIT_GATHER_02.getValue())) {
|
||||
successXieyi.add(socketDataMsg.getData());
|
||||
if (successXieyi.size() == monitorIdListComm.size()) {
|
||||
|
||||
for (String string : successXieyi) {
|
||||
//模拟统计协议校验,通讯校验已经校验过,模拟直接推送
|
||||
|
||||
SocketDataMsg webSend = new SocketDataMsg();
|
||||
webSend.setOperateCode(SourceOperateCodeEnum.DEV_INIT_GATHER_01.getValue());
|
||||
webSend.setCode(SourceResponseCodeEnum.SUCCESS.getCode());
|
||||
webSend.setRequestId(SourceOperateCodeEnum.YJC_XYJY.getValue());
|
||||
webSend.setData(string);
|
||||
webSocketHandler.sendMsgToUser(param.getUserPageId(), MsgUtil.msgToWebData(webSend, devNameMapComm, 1));
|
||||
}
|
||||
|
||||
//协议3校验
|
||||
//successXieyi = new ArrayList<>();
|
||||
|
||||
List<PreDetection> devList = iPqDevService.getDevInfo(param.getDevIds());
|
||||
Map<String, List<PreDetection>> map = new HashMap(1);
|
||||
map.put("deviceList", devList);
|
||||
String jsonString = JSON.toJSONString(map);
|
||||
socketMsg.setRequestId(SourceOperateCodeEnum.YJC_XYJY.getValue());
|
||||
socketMsg.setOperateCode(SourceOperateCodeEnum.DEV_INIT_GATHER_03.getValue());
|
||||
socketMsg.setData(jsonString);
|
||||
String json = JSON.toJSONString(socketMsg);
|
||||
|
||||
System.out.println("开始3协议校验++++++++++");
|
||||
SocketManager.sendMsg(s, json);
|
||||
|
||||
}
|
||||
} else if (socketDataMsg.getOperateCode().equals(SourceOperateCodeEnum.DEV_INIT_GATHER_03.getValue())) {
|
||||
successXieyi3.add(socketDataMsg.getData());
|
||||
System.out.println(successXieyi3.size() + "=====" + monitorIdListComm.size());
|
||||
if (successXieyi3.size() == monitorIdListComm.size()) {
|
||||
|
||||
SocketDataMsg temMsg = new SocketDataMsg();
|
||||
temMsg.setCode(SourceResponseCodeEnum.DEV_COMM_ALL_SUCCESS.getCode());
|
||||
temMsg.setOperateCode(SourceOperateCodeEnum.DEV_INIT_GATHER_03.getValue());
|
||||
temMsg.setRequestId(SourceOperateCodeEnum.YJC_XYJY.getValue());
|
||||
webSocketHandler.sendMsgToUser(param.getUserPageId(), JSON.toJSONString(temMsg));
|
||||
|
||||
|
||||
PqScriptIssueParam issueParam = new PqScriptIssueParam();
|
||||
issueParam.setPlanId(param.getPlanId());
|
||||
issueParam.setSourceId(param.getSourceId());
|
||||
issueParam.setDevIds(param.getDevIds());
|
||||
issueParam.setScriptId("a303b2224845fcc6f60198b8ca23dca9");
|
||||
|
||||
SocketMsg<String> xuMsg = new SocketMsg<>();
|
||||
xuMsg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue());
|
||||
List<SourceIssue> sourceIssues;
|
||||
if (SourceOperateCodeEnum.FORMAL_TEST.getValue().equals(param.getOperateType())) {
|
||||
//正式检测
|
||||
issueParam.setIsPhaseSequence(false);
|
||||
sourceIssues = pqScriptDtlsService.listSourceIssue(issueParam);
|
||||
sourceIssues = sourceIssues.stream().sorted(Comparator.comparing(SourceIssue::getIndex)).collect(Collectors.toList());
|
||||
SocketManager.addSourceList(sourceIssues);
|
||||
Map<String, Long> sourceIssueMap = sourceIssues.stream().collect(Collectors.groupingBy(SourceIssue::getType, Collectors.counting()));
|
||||
SocketManager.initMap(sourceIssueMap);
|
||||
xuMsg.setData(JSON.toJSONString(sourceIssues.get(0)));
|
||||
xuMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue() + "&&" + sourceIssues.get(0).getType());
|
||||
SocketManager.sendMsg(param.getUserPageId() + handlerSourceStr, MsgUtil.toJsonWithNewLinePlain(xuMsg));
|
||||
|
||||
} else if (SourceOperateCodeEnum.PRE_TEST.getValue().equals(param.getOperateType())) {
|
||||
//预检测的相序检测
|
||||
issueParam.setIsPhaseSequence(true);
|
||||
xuMsg.setRequestId(SourceOperateCodeEnum.YJC_XUJY.getValue());
|
||||
sourceIssues = pqScriptDtlsService.listSourceIssue(issueParam);
|
||||
xuMsg.setData(JSON.toJSONString(sourceIssues.get(0)));
|
||||
SocketManager.sendMsg(param.getUserPageId() + handlerSourceStr, MsgUtil.toJsonWithNewLinePlain(xuMsg));
|
||||
}
|
||||
successComm.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
case UNPROCESSED_BUSINESS:
|
||||
webSocketHandler.sendMsgToUser(param.getUserPageId(), JSON.toJSONString(socketDataMsg));
|
||||
break;
|
||||
case DEV_ERROR:
|
||||
webSocketHandler.sendMsgToUser(param.getUserPageId(), MsgUtil.msgToWebData(socketDataMsg, devNameMapComm, 2));
|
||||
quitSend(param);
|
||||
quitSendSource(param);
|
||||
break;
|
||||
case DEV_TARGET:
|
||||
webSocketHandler.sendMsgToUser(param.getUserPageId(), MsgUtil.msgToWebData(socketDataMsg, devNameMapComm, 2));
|
||||
quitSend(param);
|
||||
quitSendSource(param);
|
||||
break;
|
||||
|
||||
case RE_OPERATE:
|
||||
//出现已经初始化情况,发送用户用户确认是否继续检测
|
||||
webSocketHandler.sendMsgToUser(param.getUserPageId(), JSON.toJSONString(socketDataMsg));
|
||||
quitSend(param);
|
||||
break;
|
||||
default:
|
||||
WebSocketVO webSocketVO = new WebSocketVO();
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 相序校验
|
||||
*/
|
||||
public void devXu(PreDetectionParam param, SocketDataMsg socketDataMsg) {
|
||||
String data = socketDataMsg.getData();
|
||||
DevData devData = JSON.parseObject(data, DevData.class);
|
||||
SourceResponseCodeEnum dictDataEnumByCode = SourceResponseCodeEnum.getDictDataEnumByCode(socketDataMsg.getCode());
|
||||
if (ObjectUtil.isNotNull(dictDataEnumByCode)) {
|
||||
SocketMsg socketMsg = new SocketMsg();
|
||||
switch (dictDataEnumByCode) {
|
||||
case SUCCESS:
|
||||
//webSocketHandler.sendMsgToUser(param.getUserPageId(), JSON.toJSONString(MsgUtil.msgToWebData(socketDataMsg,devNameMapComm,1)));
|
||||
devInfo.add(devData);
|
||||
success.add(devData.getId());
|
||||
if (success.size() == monitorIdListComm.size()) {
|
||||
PqScriptIssueParam sourceParam = new PqScriptIssueParam();
|
||||
sourceParam.setPlanId(param.getPlanId());
|
||||
sourceParam.setDevIds(param.getDevIds());
|
||||
sourceParam.setIsPhaseSequence(true);
|
||||
sourceParam.setSourceId(param.getSourceId());
|
||||
List<SourceIssue> sourceIssues = scriptDtlsService.listSourceIssue(sourceParam);
|
||||
List<SourceCompareDev> info = new ArrayList<>();
|
||||
if (CollUtil.isNotEmpty(sourceIssues)) {
|
||||
for (DevData dev : devInfo) {
|
||||
info.addAll(devIsSource(dev, sourceIssues.get(0)));
|
||||
}
|
||||
}
|
||||
if (CollUtil.isNotEmpty(info)) {
|
||||
SocketDataMsg dataMsg = new SocketDataMsg();
|
||||
dataMsg.setOperateCode(SourceOperateCodeEnum.DEV_DATA_REQUEST_02.getValue());
|
||||
dataMsg.setRequestId(SourceOperateCodeEnum.YJC_XUJY.getValue());
|
||||
dataMsg.setCode(SourceResponseCodeEnum.SUCCESS.getCode());
|
||||
|
||||
for (SourceCompareDev sourceCompareDev : info) {
|
||||
dataMsg.setData(sourceCompareDev.getDevName() + "_" + sourceCompareDev.getLineNum() + sourceCompareDev.getDesc() + "校验结果:" + (sourceCompareDev.getIsQualified() ? "合格" : "不合格"));
|
||||
webSocketHandler.sendMsgToUser(param.getUserPageId(), JSON.toJSONString(dataMsg));
|
||||
}
|
||||
}
|
||||
|
||||
String userSource = param.getUserPageId() + handlerSourceStr;
|
||||
SocketMsg msg = new SocketMsg();
|
||||
|
||||
|
||||
msg.setRequestId(SourceOperateCodeEnum.QUITE_SOURCE.getValue());
|
||||
msg.setOperateCode(SourceOperateCodeEnum.CLOSE_GATHER.getValue());
|
||||
Map<String, String> map = new HashMap<>(1);
|
||||
map.put("sourceId", sourceIssues.get(0).getSourceId());
|
||||
msg.setData(JSON.toJSONString(map));
|
||||
SocketManager.sendMsg(userSource, MsgUtil.toJsonWithNewLinePlain(msg));
|
||||
|
||||
//同时关闭设备三个步骤
|
||||
SocketMsg quitDevMsg = new SocketMsg();
|
||||
quitSend(param);
|
||||
|
||||
//向前端推送消息
|
||||
SocketDataMsg temMsg = new SocketDataMsg();
|
||||
temMsg.setCode(SourceResponseCodeEnum.DEV_COMM_ALL_SUCCESS.getCode());
|
||||
temMsg.setOperateCode(SourceOperateCodeEnum.DEV_DATA_REQUEST_02.getValue());
|
||||
temMsg.setRequestId(SourceOperateCodeEnum.YJC_XUJY.getValue());
|
||||
webSocketHandler.sendMsgToUser(param.getUserPageId(), JSON.toJSONString(temMsg));
|
||||
|
||||
|
||||
//如果是正式校验需要继续校验
|
||||
if (SourceOperateCodeEnum.FORMAL_TEST.getValue().equals(param.getOperateType())) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
case UNPROCESSED_BUSINESS:
|
||||
|
||||
break;
|
||||
|
||||
case NORMAL_RESPONSE:
|
||||
devInfo.add(devData);
|
||||
break;
|
||||
case DEV_ERROR:
|
||||
webSocketHandler.sendMsgToUser(param.getUserPageId(), MsgUtil.msgToWebData(socketDataMsg, devNameMapComm, 2));
|
||||
quitSend(param);
|
||||
quitSendSource(param);
|
||||
break;
|
||||
case DEV_TARGET:
|
||||
webSocketHandler.sendMsgToUser(param.getUserPageId(), MsgUtil.msgToWebData(socketDataMsg, devNameMapComm, 2));
|
||||
quitSend(param);
|
||||
quitSendSource(param);
|
||||
break;
|
||||
case RE_OPERATE:
|
||||
break;
|
||||
default:
|
||||
socketMsg.setRequestId(socketDataMsg.getRequestId());
|
||||
socketMsg.setOperateCode(socketDataMsg.getOperateCode());
|
||||
socketMsg.setData(dictDataEnumByCode.getMessage());
|
||||
webSocketHandler.sendMsgToUser(param.getUserPageId(), JSON.toJSONString(socketMsg));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 实时数据
|
||||
*/
|
||||
private final List<DevData> devDataList = new ArrayList();
|
||||
|
||||
public void realDeal(PreDetectionParam param, SocketDataMsg socketDataMsg) {
|
||||
String data = socketDataMsg.getData();
|
||||
DevData devData = JSON.parseObject(data, DevData.class);
|
||||
SourceResponseCodeEnum dictDataEnumByCode = SourceResponseCodeEnum.getDictDataEnumByCode(socketDataMsg.getCode());
|
||||
|
||||
SourceIssue sourceIssue = SocketManager.getSourceList().get(0);
|
||||
test(devData, dictDataEnumByCode, sourceIssue, socketDataMsg, param);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void test(DevData devData, SourceResponseCodeEnum dictDataEnumByCode, SourceIssue sourceIssue, SocketDataMsg socketDataMsg, PreDetectionParam param) {
|
||||
if (ObjectUtil.isNotNull(dictDataEnumByCode)) {
|
||||
SocketMsg<String> socketMsg = new SocketMsg<>();
|
||||
switch (dictDataEnumByCode) {
|
||||
case SUCCESS:
|
||||
//List<DevData.SqlDataDTO> sqlDataDTOList = devData.getSqlData();
|
||||
devDataList.add(devData);
|
||||
successComm.add(socketDataMsg.getRequestId());
|
||||
System.out.println("获取devData数量............." + devDataList.size());
|
||||
|
||||
if (successComm.size() == monitorIdListComm.size()) {
|
||||
System.out.println(sourceIssue.getType() +"_"+ sourceIssue.getIndex() + "当前测试小项读取数据已经全部结束。。。。。。。。。");
|
||||
System.out.println(JSON.toJSONString(sourceIssue));
|
||||
|
||||
//开启线程进行入库原始数据操作
|
||||
Map<String, Integer> flag = detectionServiceImpl.text(devDataList, param.getErrorSysId(), devIdMapComm, sourceIssue, DictDataEnum.AT_WILL_VALUE);
|
||||
System.out.println(flag);
|
||||
|
||||
long tem = SocketManager.getSourceTarget(sourceIssue.getType()) - 1;
|
||||
SocketManager.addTargetMap(sourceIssue.getType(), tem);
|
||||
|
||||
System.out.println("该大项还有"+tem+"个小项没有进行检测!!!!!!!!");
|
||||
|
||||
if (tem == 0) {
|
||||
System.out.println(sourceIssue.getType() + sourceIssue.getIndex() + "当前测试大项已经全部结束》》》》》》》》");
|
||||
|
||||
|
||||
baseDataInsert(devDataList,sourceIssue,param);
|
||||
|
||||
//当val为0则认为大项中的小项已经全部跑完,开始组装信息推送给前端
|
||||
WebSocketVO<List<DevLineTestResult>> webSocketVO = new WebSocketVO<>();
|
||||
webSocketVO.setRequestId(socketDataMsg.getRequestId().split("&&")[1] + "_End");
|
||||
//组装实体推送给前台
|
||||
List<DevLineTestResult> devListRes = new ArrayList<>();
|
||||
devList.forEach(dev -> {
|
||||
DevLineTestResult devLineTestResult = new DevLineTestResult();
|
||||
devLineTestResult.setDeviceId(dev.getDevId());
|
||||
devLineTestResult.setDeviceName(dev.getDevName());
|
||||
|
||||
List<Integer> tt = new ArrayList<>();
|
||||
List<PreDetection.MonitorListDTO> monitorListDTOList = dev.getMonitorList();
|
||||
for (PreDetection.MonitorListDTO point : monitorListDTOList) {
|
||||
Integer resultFlag = flag.get(dev.getDevIP() + "_" + point.getLine());
|
||||
tt.add(resultFlag);
|
||||
}
|
||||
devLineTestResult.setChnResult(tt.toArray(new Integer[monitorListDTOList.size()]));
|
||||
devListRes.add(devLineTestResult);
|
||||
});
|
||||
webSocketVO.setData(devListRes);
|
||||
webSocketHandler.sendMsgToUser(param.getUserPageId(), JSON.toJSONString(webSocketVO));
|
||||
|
||||
}
|
||||
|
||||
|
||||
//开始进行下一个大项检测
|
||||
List<SourceIssue> sourceIssueList = SocketManager.getSourceList();
|
||||
if (CollUtil.isNotEmpty(sourceIssueList)) {
|
||||
SocketMsg<String> xuMsg = new SocketMsg<>();
|
||||
xuMsg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue());
|
||||
|
||||
|
||||
//正式检测
|
||||
SourceIssue sourceIssues = SocketManager.getSourceList().get(0);
|
||||
xuMsg.setData(JSON.toJSONString(sourceIssues));
|
||||
xuMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue() + "&&" + sourceIssues.getType());
|
||||
SocketManager.sendMsg(param.getUserPageId() + handlerSourceStr, MsgUtil.toJsonWithNewLinePlain(xuMsg));
|
||||
}
|
||||
|
||||
//当小项结束后需要删除集合中的小项
|
||||
SocketManager.delSource(sourceIssue.getIndex());
|
||||
System.out.println("当前小项结束进行删除============"+sourceIssue.getType()+"_"+sourceIssue.getIndex());
|
||||
successComm.clear();
|
||||
devDataList.clear();
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case UNPROCESSED_BUSINESS:
|
||||
break;
|
||||
|
||||
case NORMAL_RESPONSE:
|
||||
devDataList.add(devData);
|
||||
|
||||
break;
|
||||
case DEV_ERROR:
|
||||
|
||||
break;
|
||||
case DEV_TARGET:
|
||||
|
||||
break;
|
||||
case RE_OPERATE:
|
||||
break;
|
||||
default:
|
||||
socketMsg.setRequestId(socketDataMsg.getRequestId());
|
||||
socketMsg.setOperateCode(socketDataMsg.getOperateCode());
|
||||
socketMsg.setData(dictDataEnumByCode.getMessage());
|
||||
webSocketHandler.sendMsgToUser(param.getUserPageId(), JSON.toJSONString(socketMsg));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 退出检测返回
|
||||
*/
|
||||
private void quitDeal(SocketDataMsg socketDataMsg, PreDetectionParam param, String msg) {
|
||||
SourceResponseCodeEnum dictDataEnumByCode = SourceResponseCodeEnum.getDictDataEnumByCode(socketDataMsg.getCode());
|
||||
SourceOperateCodeEnum operateCodeEnum = SourceOperateCodeEnum.getDictDataEnumByCode(socketDataMsg.getOperateCode());
|
||||
SocketMsg socketMsg = new SocketMsg();
|
||||
String s = param.getUserPageId() + handlerStr;
|
||||
|
||||
switch (dictDataEnumByCode) {
|
||||
case SUCCESS:
|
||||
//通讯校验成功
|
||||
switch (operateCodeEnum) {
|
||||
case QUIT_INIT_01:
|
||||
//关闭所有
|
||||
SocketManager.removeUser(s);
|
||||
quitSendSource(param);
|
||||
break;
|
||||
case QUIT_INIT_02:
|
||||
socketMsg.setRequestId("quit");
|
||||
socketMsg.setOperateCode("QUIT_FUNEND$01");
|
||||
SocketManager.sendMsg(s, JSON.toJSONString(socketMsg));
|
||||
break;
|
||||
case QUIT_INIT_03:
|
||||
socketMsg.setRequestId("quit");
|
||||
socketMsg.setOperateCode("QUIT_FUNEND$02");
|
||||
SocketManager.sendMsg(s, JSON.toJSONString(socketMsg));
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case UNPROCESSED_BUSINESS:
|
||||
break;
|
||||
case NO_INIT_DEV:
|
||||
switch (operateCodeEnum) {
|
||||
case QUIT_INIT_01:
|
||||
SocketManager.removeUser(s);
|
||||
quitSendSource(param);
|
||||
break;
|
||||
case QUIT_INIT_02:
|
||||
socketMsg.setRequestId("quit");
|
||||
socketMsg.setOperateCode("QUIT_FUNEND$01");
|
||||
SocketManager.sendMsg(s, JSON.toJSONString(socketMsg));
|
||||
break;
|
||||
case QUIT_INIT_03:
|
||||
socketMsg.setRequestId("quit");
|
||||
socketMsg.setOperateCode("QUIT_FUNEND$02");
|
||||
SocketManager.sendMsg(s, JSON.toJSONString(socketMsg));
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
WebSocketVO webSocketVO = new WebSocketVO();
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 退出检测
|
||||
*/
|
||||
private void quitSend(PreDetectionParam param) {
|
||||
SocketMsg socketMsg = new SocketMsg();
|
||||
socketMsg.setRequestId(SourceOperateCodeEnum.QUITE.getValue());
|
||||
socketMsg.setOperateCode(SourceOperateCodeEnum.QUIT_INIT_03.getValue());
|
||||
SocketManager.sendMsg(param.getUserPageId() + handlerStr, JSON.toJSONString(socketMsg));
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭源连接
|
||||
*/
|
||||
private void quitSendSource(PreDetectionParam param) {
|
||||
SocketMsg socketMsg = new SocketMsg();
|
||||
socketMsg.setRequestId(SourceOperateCodeEnum.QUITE_SOURCE.getValue());
|
||||
socketMsg.setOperateCode(SourceOperateCodeEnum.CLOSE_GATHER.getValue());
|
||||
SocketManager.sendMsg(param.getUserPageId() + handlerSourceStr, JSON.toJSONString(socketMsg));
|
||||
}
|
||||
|
||||
|
||||
private List<SourceCompareDev> devIsSource(DevData dev, SourceIssue issue) {
|
||||
|
||||
List<SourceCompareDev> info = new ArrayList<>();
|
||||
String[] split = dev.getId().split("_");
|
||||
String devName = null;
|
||||
if (devNameMapComm.containsKey(split[0])) {
|
||||
devName = devNameMapComm.get(split[0]);
|
||||
}
|
||||
List<SourceIssue.ChannelListDTO> channelList = issue.getChannelList();
|
||||
|
||||
List<DevData.SqlDataDTO> sqlData = dev.getSqlData();
|
||||
List<DevData.SqlDataDTO> dataV = sqlData.stream().filter(x -> "电压有效值".equals(x.getDesc())).collect(Collectors.toList());
|
||||
List<DevData.SqlDataDTO> dataI = sqlData.stream().filter(x -> "电流有效值".equals(x.getDesc())).collect(Collectors.toList());
|
||||
if (CollUtil.isNotEmpty(dataV)) {
|
||||
SourceCompareDev compareDev = getSourceCompareDev(split, dataV, "电压有效值", "U", channelList);
|
||||
compareDev.setDevName(devName);
|
||||
info.add(compareDev);
|
||||
}
|
||||
if (CollUtil.isNotEmpty(dataI)) {
|
||||
SourceCompareDev compareDev = getSourceCompareDev(split, dataI, "电流有效值", "I", channelList);
|
||||
compareDev.setDevName(devName);
|
||||
info.add(compareDev);
|
||||
}
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算是否合格
|
||||
*
|
||||
* @param split
|
||||
* @param data
|
||||
* @param name 指标名称
|
||||
* @param type U,I
|
||||
* @param channelList
|
||||
* @return
|
||||
*/
|
||||
private static SourceCompareDev getSourceCompareDev(String[] split,
|
||||
List<DevData.SqlDataDTO> data,
|
||||
String name,
|
||||
String type,
|
||||
List<SourceIssue.ChannelListDTO> channelList
|
||||
) {
|
||||
SourceCompareDev compareDev = new SourceCompareDev();
|
||||
|
||||
compareDev.setIp(split[0]);
|
||||
compareDev.setLineNum(split[1]);
|
||||
compareDev.setDesc(name);
|
||||
//装置数据
|
||||
DevData.SqlDataDTO.ListDTO devData = data.get(0).getList();
|
||||
List<SourceIssue.ChannelListDTO> sourceList = channelList.stream().filter(x -> (type + "a").equals(x.getChannelType()) ||
|
||||
(type + "b").equals(x.getChannelType()) ||
|
||||
(type + "c").equals(x.getChannelType())
|
||||
).collect(Collectors.toList());
|
||||
Map<String, Double> sourceMap = sourceList.stream()
|
||||
.collect(Collectors.toMap(x -> x.getChannelType().toUpperCase().replace(type, "")
|
||||
, SourceIssue.ChannelListDTO::getFAmp));
|
||||
Map<String, Double> devMap = new HashMap<>(3);
|
||||
devMap.put("A", devData.getA());
|
||||
devMap.put("B", devData.getB());
|
||||
devMap.put("C", devData.getC());
|
||||
Boolean is = true;
|
||||
for (SourceIssue.ChannelListDTO channelListDTO : sourceList) {
|
||||
if (!is) {
|
||||
break;
|
||||
}
|
||||
if (channelListDTO.getChannelType().equals((type + "a"))) {
|
||||
is = NumberUtil.isIn(BigDecimal.valueOf(devData.getA()),
|
||||
BigDecimal.valueOf(channelListDTO.getFAmp() * 0.95),
|
||||
BigDecimal.valueOf(channelListDTO.getFAmp() * 1.05));
|
||||
}
|
||||
if (channelListDTO.getChannelType().equals((type + "b"))) {
|
||||
is = NumberUtil.isIn(BigDecimal.valueOf(devData.getB()),
|
||||
BigDecimal.valueOf(channelListDTO.getFAmp() * 0.95),
|
||||
BigDecimal.valueOf(channelListDTO.getFAmp() * 1.05));
|
||||
}
|
||||
if (channelListDTO.getChannelType().equals((type + "c"))) {
|
||||
is = NumberUtil.isIn(BigDecimal.valueOf(devData.getC()),
|
||||
BigDecimal.valueOf(channelListDTO.getFAmp() * 0.95),
|
||||
BigDecimal.valueOf(channelListDTO.getFAmp() * 1.05));
|
||||
}
|
||||
|
||||
}
|
||||
compareDev.setIsQualified(is);
|
||||
compareDev.setSourceData(sourceMap);
|
||||
compareDev.setDevData(devMap);
|
||||
return compareDev;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 初始化集合
|
||||
*/
|
||||
public void initList(PreDetectionParam param) {
|
||||
this.monitorIdListComm = new ArrayList<>();
|
||||
this.successComm = new ArrayList<>();
|
||||
this.successXieyi = new ArrayList<>();
|
||||
this.successXieyi3 = new ArrayList<>();
|
||||
//初始化相序集合
|
||||
this.devInfo = new ArrayList<>();
|
||||
this.success = new ArrayList<>();
|
||||
this.devDataMap = new HashMap<>();
|
||||
|
||||
this.adNonHarmonicResultList.clear();
|
||||
this.devDataList.clear();
|
||||
this.devList.clear();
|
||||
|
||||
List<PreDetection> pqDevList = iPqDevService.getDevInfo(param.getDevIds());
|
||||
this.devList = pqDevList;
|
||||
this.monitorIdListComm = pqDevList.stream().flatMap(x -> x.getMonitorList().stream())
|
||||
.map(PreDetection.MonitorListDTO::getLineId)
|
||||
.collect(Collectors.toList());
|
||||
this.devNameMapComm = pqDevList.stream().collect(Collectors.toMap(PreDetection::getDevIP, PreDetection::getDevName));
|
||||
this.devIdMapComm = pqDevList.stream().collect(Collectors.toMap(PreDetection::getDevIP, PreDetection::getDevId));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 原始数据入库
|
||||
* @author cdf
|
||||
* @date 2024/12/29
|
||||
*/
|
||||
private void baseDataInsert(List<DevData> devDataList,SourceIssue sourceIssue,PreDetectionParam param){
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ISO_DATE_TIME; // ISO 8601格式
|
||||
|
||||
List<AdNonHarmonicResult> adHarmonicResultList = new ArrayList<>();
|
||||
for(DevData data : devDataList){
|
||||
AdNonHarmonicResult adNonHarmonicResult = new AdNonHarmonicResult();
|
||||
|
||||
LocalDateTime localDateTime = timeFormat(data.getTime(),formatter);
|
||||
if(Objects.nonNull(localDateTime)){
|
||||
adNonHarmonicResult.setTimeId(localDateTime);
|
||||
adNonHarmonicResult.setMonitorId(data.getId());
|
||||
adNonHarmonicResult.setScriptId(param.getScriptId());
|
||||
adNonHarmonicResult.setSort(sourceIssue.getIndex());
|
||||
adNonHarmonicResult.setAdType(sourceIssue.getSourceId());
|
||||
adNonHarmonicResult.setAValue(data.getSqlData().get(0).getList().getA().toString());
|
||||
adNonHarmonicResult.setBValue(data.getSqlData().get(0).getList().getB().toString());
|
||||
adNonHarmonicResult.setCValue(data.getSqlData().get(0).getList().getC().toString());
|
||||
adHarmonicResultList.add(adNonHarmonicResult);
|
||||
}
|
||||
}
|
||||
detectionDataDealService.acceptAdNon(adHarmonicResultList,"1");
|
||||
}
|
||||
};
|
||||
runnable.run();
|
||||
}
|
||||
|
||||
|
||||
private LocalDateTime timeFormat(String dateTimeStr, DateTimeFormatter formatter){
|
||||
//DateTimeFormatter formatter = DateTimeFormatter.ISO_DATE_TIME; // ISO 8601格式
|
||||
try {
|
||||
// 假设输入是UTC时间,将其解析为ZonedDateTime
|
||||
ZonedDateTime zonedDateTime = ZonedDateTime.parse(dateTimeStr, formatter.withZone(ZoneId.of("UTC")));
|
||||
// 将ZonedDateTime转换为LocalDateTime(去除时区信息)
|
||||
LocalDateTime localDateTime = zonedDateTime.toLocalDateTime();
|
||||
System.out.println("LocalDateTime: " + localDateTime);
|
||||
|
||||
return localDateTime;
|
||||
} catch (DateTimeParseException e) {
|
||||
System.err.println("日期时间字符串格式错误: " + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,263 @@
|
||||
package com.njcn.gather.detection.handler;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum;
|
||||
import com.njcn.gather.detection.pojo.enums.SourceResponseCodeEnum;
|
||||
import com.njcn.gather.detection.pojo.param.DevPhaseSequenceParam;
|
||||
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
|
||||
import com.njcn.gather.detection.pojo.vo.DevLineTestResult;
|
||||
import com.njcn.gather.detection.pojo.vo.SocketDataMsg;
|
||||
import com.njcn.gather.detection.pojo.vo.SocketMsg;
|
||||
import com.njcn.gather.detection.pojo.vo.WebSocketVO;
|
||||
import com.njcn.gather.detection.util.socket.MsgUtil;
|
||||
import com.njcn.gather.detection.util.socket.SocketManager;
|
||||
import com.njcn.gather.detection.util.socket.cilent.NettyClient;
|
||||
import com.njcn.gather.detection.util.socket.cilent.NettyDevClientHandler;
|
||||
import com.njcn.gather.detection.util.socket.web.WebSocketHandler;
|
||||
import com.njcn.gather.device.device.pojo.vo.PreDetection;
|
||||
import com.njcn.gather.device.device.service.IPqDevService;
|
||||
import com.njcn.gather.device.script.pojo.po.SourceIssue;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SocketSourceResponseService {
|
||||
|
||||
/**
|
||||
* 向webSocket客户端发送消息
|
||||
*/
|
||||
private final WebSocketHandler webSocketHandler;
|
||||
private final SocketDevResponseService socketDevResponseService;
|
||||
private final IPqDevService iPqDevService;
|
||||
|
||||
private final String DEV = "_Dev";
|
||||
private final String source = "_Source";
|
||||
|
||||
|
||||
@Value("${socket.device.ip}")
|
||||
private String ip;
|
||||
|
||||
@Value("${socket.device.port}")
|
||||
private Integer port;
|
||||
|
||||
private List<PreDetection> devList = new ArrayList<>();
|
||||
|
||||
|
||||
|
||||
public void deal(PreDetectionParam param, String msg) throws Exception {
|
||||
SocketDataMsg socketDataMsg = MsgUtil.socketDataMsg(msg);
|
||||
String[] tem = socketDataMsg.getRequestId().split("&&");
|
||||
SourceOperateCodeEnum enumByCode = SourceOperateCodeEnum.getDictDataEnumByCode(tem[0]);
|
||||
if (ObjectUtil.isNotNull(enumByCode)) {
|
||||
switch (enumByCode) {
|
||||
//源初始化
|
||||
case YJC_YTXJY:
|
||||
detectionDev(param, socketDataMsg);
|
||||
break;
|
||||
//相序检测
|
||||
case YJC_XUJY:
|
||||
phaseSequenceDev(param, socketDataMsg);
|
||||
break;
|
||||
//正式检测
|
||||
case FORMAL_REAL:
|
||||
senParamToDev(param, socketDataMsg);
|
||||
break;
|
||||
case QUITE_SOURCE:
|
||||
quitDeal(socketDataMsg,param);
|
||||
// System.out.println("关闭源回调:"+msg);
|
||||
break;
|
||||
|
||||
}
|
||||
} else {
|
||||
System.out.println("1");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 装置检测(当源初始化成功后,直接向装置通道向装置服务器发送,装置检测)
|
||||
*
|
||||
* @param param
|
||||
* @param socketDataMsg
|
||||
*/
|
||||
private void detectionDev(PreDetectionParam param, SocketDataMsg socketDataMsg) {
|
||||
SourceResponseCodeEnum dictDataEnumByCode = SourceResponseCodeEnum.getDictDataEnumByCode(socketDataMsg.getCode());
|
||||
if (ObjectUtil.isNotNull(dictDataEnumByCode)) {
|
||||
SocketMsg<String> socketMsg = new SocketMsg<>();
|
||||
|
||||
switch (dictDataEnumByCode) {
|
||||
case SUCCESS:
|
||||
|
||||
//todo 前端推送收到的消息暂未处理好
|
||||
webSocketHandler.sendMsgToUser(param.getUserPageId(), JSON.toJSONString(socketDataMsg));
|
||||
String s = param.getUserPageId() + DEV;
|
||||
//开始设备通讯检测(发送设备初始化)
|
||||
List<PreDetection> devList = iPqDevService.getDevInfo(param.getDevIds());
|
||||
Map<String, List<PreDetection>> map = new HashMap(1);
|
||||
map.put("deviceList", devList);
|
||||
String jsonString = JSON.toJSONString(map);
|
||||
socketMsg.setRequestId(SourceOperateCodeEnum.YJC_SBTXJY.getValue());
|
||||
socketMsg.setOperateCode(SourceOperateCodeEnum.DEV_INIT_GATHER_01.getValue());
|
||||
socketMsg.setData(jsonString);
|
||||
String json = JSON.toJSONString(socketMsg);
|
||||
// SocketManager.sendMsg(s,json);
|
||||
NettyClient.socketClient(ip, port, param.getUserPageId(), json, new NettyDevClientHandler(param, socketDevResponseService));
|
||||
break;
|
||||
case UNPROCESSED_BUSINESS:
|
||||
webSocketHandler.sendMsgToUser(param.getUserPageId(), JSON.toJSONString(socketDataMsg));
|
||||
break;
|
||||
default:
|
||||
socketMsg = new SocketMsg<>();
|
||||
socketMsg.setRequestId(socketDataMsg.getRequestId());
|
||||
socketMsg.setOperateCode(socketDataMsg.getOperateCode());
|
||||
socketMsg.setData(dictDataEnumByCode.getMessage());
|
||||
webSocketHandler.sendMsgToUser(param.getUserPageId(), JSON.toJSONString(socketMsg));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 相序检测向装置发送(当装置初始成功后,会向源发送加量请求。收到加量请求成功后会向装置发送参数下发。)
|
||||
*
|
||||
* @param param
|
||||
* @param socketDataMsg
|
||||
*/
|
||||
private void phaseSequenceDev(PreDetectionParam param, SocketDataMsg socketDataMsg) {
|
||||
SourceResponseCodeEnum dictDataEnumByCode = SourceResponseCodeEnum.getDictDataEnumByCode(socketDataMsg.getCode());
|
||||
if (ObjectUtil.isNotNull(dictDataEnumByCode)) {
|
||||
SocketMsg<String> socketMsg = new SocketMsg();
|
||||
switch (dictDataEnumByCode) {
|
||||
case SUCCESS:
|
||||
//向前端推送信息
|
||||
webSocketHandler.sendMsgToUser(param.getUserPageId(), JSON.toJSONString(socketDataMsg));
|
||||
|
||||
String s = param.getUserPageId() + DEV;
|
||||
socketMsg.setRequestId(SourceOperateCodeEnum.YJC_XUJY.getValue());
|
||||
socketMsg.setOperateCode(SourceOperateCodeEnum.DEV_DATA_REQUEST_02.getValue());
|
||||
List<PreDetection> pqDevList = iPqDevService.getDevInfo(param.getDevIds());
|
||||
List<String> moniterIdList = pqDevList.stream().flatMap(x -> x.getMonitorList().stream())
|
||||
.map(PreDetection.MonitorListDTO::getLineId)
|
||||
.collect(Collectors.toList());
|
||||
DevPhaseSequenceParam phaseSequenceParam = new DevPhaseSequenceParam();
|
||||
phaseSequenceParam.setMoniterIdList(moniterIdList);
|
||||
phaseSequenceParam.setDataType(Arrays.asList("实时数据/电压有效值", "实时数据/电流有效值"));
|
||||
phaseSequenceParam.setReadCount(1);
|
||||
phaseSequenceParam.setIgnoreCount(10);
|
||||
socketMsg.setData(JSON.toJSONString(phaseSequenceParam));
|
||||
SocketManager.sendMsg(s, JSON.toJSONString(socketMsg));
|
||||
break;
|
||||
case UNPROCESSED_BUSINESS:
|
||||
webSocketHandler.sendMsgToUser(param.getUserPageId(), JSON.toJSONString(socketDataMsg));
|
||||
break;
|
||||
default:
|
||||
socketMsg.setRequestId(socketDataMsg.getRequestId());
|
||||
socketMsg.setOperateCode(socketDataMsg.getOperateCode());
|
||||
socketMsg.setData(dictDataEnumByCode.getMessage());
|
||||
webSocketHandler.sendMsgToUser(param.getUserPageId(), JSON.toJSONString(socketMsg));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 组装和装置要数据
|
||||
*
|
||||
* @param param
|
||||
* @param socketDataMsg
|
||||
*/
|
||||
private void senParamToDev(PreDetectionParam param, SocketDataMsg socketDataMsg) {
|
||||
SourceResponseCodeEnum dictDataEnumByCode = SourceResponseCodeEnum.getDictDataEnumByCode(socketDataMsg.getCode());
|
||||
if (ObjectUtil.isNotNull(dictDataEnumByCode)) {
|
||||
SocketMsg<String> socketMsg = new SocketMsg<>();
|
||||
switch (dictDataEnumByCode) {
|
||||
case SUCCESS:
|
||||
//向前端推送信息
|
||||
// webSocketHandler.sendMsgToUser(param.getUserPageId(), JSON.toJSONString(socketDataMsg));
|
||||
|
||||
String s = param.getUserPageId() + DEV;
|
||||
SourceIssue sourceIssue = SocketManager.getSourceList().get(0);
|
||||
String comm = sourceIssue.getDevValueTypeList().get(0);
|
||||
|
||||
socketMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue()+"&&"+sourceIssue.getType());
|
||||
socketMsg.setOperateCode(SourceOperateCodeEnum.DEV_DATA_REQUEST_02.getValue());
|
||||
List<String> moniterIdList = devList.stream().flatMap(x -> x.getMonitorList().stream()).map(PreDetection.MonitorListDTO::getLineId).collect(Collectors.toList());
|
||||
DevPhaseSequenceParam phaseSequenceParam = new DevPhaseSequenceParam();
|
||||
|
||||
System.out.println("向装置下发的参数"+comm);
|
||||
phaseSequenceParam.setMoniterIdList(moniterIdList);
|
||||
phaseSequenceParam.setDataType(Arrays.asList(comm));
|
||||
phaseSequenceParam.setReadCount(2);
|
||||
phaseSequenceParam.setIgnoreCount(10);
|
||||
socketMsg.setData(JSON.toJSONString(phaseSequenceParam));
|
||||
SocketManager.sendMsg(s, JSON.toJSONString(socketMsg));
|
||||
|
||||
|
||||
//告诉前端当前项开始了
|
||||
WebSocketVO<List<DevLineTestResult>> webSocketVO = new WebSocketVO<>();
|
||||
webSocketVO.setRequestId(socketDataMsg.getRequestId().split("&&")[1]+"_Start");
|
||||
List<DevLineTestResult> devListRes = new ArrayList<>();
|
||||
devList.forEach(item->{
|
||||
DevLineTestResult devLineTestResult = new DevLineTestResult();
|
||||
devLineTestResult.setDeviceId(item.getDevId());
|
||||
devLineTestResult.setDeviceName(item.getDevName());
|
||||
devListRes.add(devLineTestResult);
|
||||
});
|
||||
webSocketVO.setData(devListRes);
|
||||
webSocketHandler.sendMsgToUser(param.getUserPageId(), JSON.toJSONString(webSocketVO));
|
||||
|
||||
break;
|
||||
case UNPROCESSED_BUSINESS:
|
||||
webSocketHandler.sendMsgToUser(param.getUserPageId(), JSON.toJSONString(socketDataMsg));
|
||||
break;
|
||||
default:
|
||||
socketMsg.setRequestId(socketDataMsg.getRequestId());
|
||||
socketMsg.setOperateCode(socketDataMsg.getOperateCode());
|
||||
socketMsg.setData(dictDataEnumByCode.getMessage());
|
||||
webSocketHandler.sendMsgToUser(param.getUserPageId(), JSON.toJSONString(socketMsg));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 退出检测返回
|
||||
*/
|
||||
private void quitDeal(SocketDataMsg socketDataMsg, PreDetectionParam param) {
|
||||
SourceResponseCodeEnum dictDataEnumByCode = SourceResponseCodeEnum.getDictDataEnumByCode(socketDataMsg.getCode());
|
||||
SourceOperateCodeEnum operateCodeEnum = SourceOperateCodeEnum.getDictDataEnumByCode(socketDataMsg.getOperateCode());
|
||||
SocketMsg socketMsg = new SocketMsg();
|
||||
switch (dictDataEnumByCode) {
|
||||
case SUCCESS:
|
||||
//通讯校验成功
|
||||
SocketManager.removeUser(param.getUserPageId() + source);
|
||||
break;
|
||||
case UNPROCESSED_BUSINESS:
|
||||
break;
|
||||
case MESSAGE_PARSING_ERROR:
|
||||
break;
|
||||
|
||||
default:
|
||||
WebSocketVO webSocketVO = new WebSocketVO();
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void initList(PreDetectionParam param){
|
||||
devList.clear();
|
||||
this.devList = iPqDevService.getDevInfo(param.getDevIds());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.njcn.gather.detection.pojo.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2024/11/9
|
||||
*/
|
||||
@Getter
|
||||
public enum DetectionResponseEnum {
|
||||
PLAN_PATTERN_NOT("A020001", "计划模式查询为空"),
|
||||
SOURCE_INFO_NOT("A020002", "源表信息不存在"),
|
||||
PLAN_AND_SOURCE_NOT("A020003", "计划和源关系不存在")
|
||||
|
||||
;
|
||||
|
||||
private String code;
|
||||
private String message;
|
||||
|
||||
DetectionResponseEnum(String code, String message) {
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package com.njcn.gather.detection.pojo.enums;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @Description:
|
||||
* @Author: wr
|
||||
* @Date: 2024/12/17 15:37
|
||||
*/
|
||||
@Getter
|
||||
public enum SourceOperateCodeEnum {
|
||||
|
||||
/**
|
||||
* 源状态
|
||||
*/
|
||||
INIT_GATHER("INIT_GATHER", "源初始化"),
|
||||
OPER_GATHER("OPER_GATHER", "源输出"),
|
||||
CLOSE_GATHER("CLOSE_GATHER", "源停止"),
|
||||
HEARTBEAT("HeartBeat", "心跳报文"),
|
||||
|
||||
/**
|
||||
* 终端 INIT_GATHER$01 INIT_GATHER采集初始化,01 统计采集、02 暂态采集、03 实时采集
|
||||
*/
|
||||
DEV_INIT_GATHER_01("INIT_GATHER$01", "统计采集"),
|
||||
DEV_INIT_GATHER_02("INIT_GATHER$02", "实时采集"),
|
||||
DEV_INIT_GATHER_03("INIT_GATHER$03", "暂态采集"),
|
||||
|
||||
DEV_DATA_REQUEST_01("DATA_REQUEST$01", "统计采集申请"),
|
||||
DEV_DATA_REQUEST_02("DATA_REQUEST$02", "实时采集申请"),
|
||||
DEV_DATA_REQUEST_03("DATA_REQUEST$03", "暂态采集申请"),
|
||||
|
||||
QUIT_INIT_01("QUIT_FUNEND$01", "关闭统计申请"),
|
||||
QUIT_INIT_02("QUIT_FUNEND$02", "关闭实时申请"),
|
||||
QUIT_INIT_03("QUIT_FUNEND$03", "关闭暂态申请"),
|
||||
|
||||
|
||||
/**
|
||||
* 请求操作类型对应实体中 requestId
|
||||
*/
|
||||
YJC_YTXJY("yjc_ytxjy", "预检测_源通讯检测"),
|
||||
YJC_SBTXJY("yjc_sbtxjy", "预检测_设备通讯检测"),
|
||||
YJC_XYJY("yjc_xyjy", "预检测_协议校验"),
|
||||
YJC_XUJY("YJC_xujy", "预检测_相序校验"),
|
||||
|
||||
FORMAL_REAL("formal_real","正式检测_获取实时数据"),
|
||||
FORMAL_STATISTIC("formal_statistic","正式检测_获取统计数据"),
|
||||
FORMAL_EVENT("formal_event","正式检测_获取暂态数据"),
|
||||
|
||||
QUITE("quit","预监测_关闭设备通讯初始化"),
|
||||
QUITE_SOURCE("close_source","预监测_关闭源通讯"),
|
||||
|
||||
|
||||
|
||||
PRE_TEST("0","预检测"),
|
||||
FORMAL_TEST("1","正式检测"),
|
||||
TIME_TEST("2","守时检测"),
|
||||
|
||||
|
||||
/**
|
||||
* 检测类型
|
||||
*/
|
||||
Test_Freq("formal_real&&Test_Freq","频率检测"),
|
||||
Test_VOL("formal_real&&Test_VOL","电压检测"),
|
||||
|
||||
|
||||
|
||||
|
||||
;
|
||||
|
||||
private final String value;
|
||||
private final String msg;
|
||||
|
||||
SourceOperateCodeEnum(String value, String msg) {
|
||||
this.value = value;
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public static SourceOperateCodeEnum getDictDataEnumByCode(String value) {
|
||||
for (SourceOperateCodeEnum sourceOperateCodeEnum : SourceOperateCodeEnum.values()) {
|
||||
if (ObjectUtil.equals(value, sourceOperateCodeEnum.getValue())) {
|
||||
return sourceOperateCodeEnum;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package com.njcn.gather.detection.pojo.enums;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @Author: wr
|
||||
* @Date: 2024/12/17 15:37
|
||||
*/
|
||||
@Getter
|
||||
public enum SourceResponseCodeEnum {
|
||||
|
||||
SUCCESS(10200, "请求成功"),
|
||||
UNPROCESSED_BUSINESS(10201, "立即响应,业务还未处理,类似肯定应答"),
|
||||
NORMAL_RESPONSE(10202, "正常响应中间状态码"),
|
||||
MESSAGE_PARSING_ERROR(10520, "报文解析有误"),
|
||||
CONTROLLED_SOURCE_ERROR(10521, "程控源参数有误"),
|
||||
TEST_ITEM_PARSING_ERROR(10522, "测试项解析有误"),
|
||||
SOURCE_CONNECTION_ERROR(10523, "源连接失败"),
|
||||
SOURCE_CONTROL_ERROR(10524, "获取源控制权失败"),
|
||||
RESET_ERROR(10525, "重置源失败"),
|
||||
STOP_ERROR(10526, "停止源失败"),
|
||||
NOT_INITIALIZED(10527, "源未进行初始化"),
|
||||
TARGET_SOURCE_ERROR(10528, "目标源有误(该用户已控制其他源,在关闭前无法操作新的源)"),
|
||||
UNABLE_TO_RESPOND(10529, "源状态有误,无法响应报文(例如源处于输出状态,无法响应初始化报文)"),
|
||||
|
||||
|
||||
//通讯模块
|
||||
DEV_ERROR(10550,"设备连接异常"),
|
||||
DEV_TARGET(10551,"设备触发报告异常"),
|
||||
RE_OPERATE(10552,"重复的初始化操作"),
|
||||
COMMUNICATION_ERR(10553,"通讯模块通讯异常"),
|
||||
DATA_RESOLVE(10554,"报文解析异常"),
|
||||
NO_INIT_DEV(10556,"不存在上线的设备"),
|
||||
|
||||
//自定义前端展示消息
|
||||
SOCKET_ERROR(25000,"服务端连接失败"),
|
||||
DEV_COMM_ALL_SUCCESS(25001,"校验成功")
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
;
|
||||
|
||||
private final Integer code;
|
||||
private final String message;
|
||||
|
||||
SourceResponseCodeEnum(Integer code, String message) {
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public static String getMsgByValue(Integer code) {
|
||||
for (SourceResponseCodeEnum state : SourceResponseCodeEnum.values()) {
|
||||
if (state.getCode().equals(code)) {
|
||||
return state.getMessage();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static SourceResponseCodeEnum getDictDataEnumByCode(Integer code) {
|
||||
for (SourceResponseCodeEnum sourceResponseCodeEnum : SourceResponseCodeEnum.values()) {
|
||||
if (ObjectUtil.equals(code, sourceResponseCodeEnum.getCode())) {
|
||||
return sourceResponseCodeEnum;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.njcn.gather.detection.pojo.param;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author wr
|
||||
* @description
|
||||
* @date 2024/12/18 9:17
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
public class DevPhaseSequenceParam {
|
||||
|
||||
/**
|
||||
* 装置下测点集合
|
||||
*/
|
||||
@JSONField(name = "moniterIdList", ordinal = 1)
|
||||
private List<String> moniterIdList;
|
||||
|
||||
/**
|
||||
* 设置需要的取值(平均值/电压有效值)
|
||||
*/
|
||||
@JSONField(name = "dataType", ordinal = 2)
|
||||
private List<String> dataType;
|
||||
|
||||
/**
|
||||
* 获取多少组数据
|
||||
*/
|
||||
@JSONField(name = "readCount", ordinal = 3)
|
||||
private Integer readCount;
|
||||
|
||||
/**
|
||||
* 忽略多少组数据
|
||||
*/
|
||||
@JSONField(name = "ignoreCount", ordinal = 4)
|
||||
private Integer ignoreCount;
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.njcn.gather.detection.pojo.param;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author wr
|
||||
* @description
|
||||
* @date 2024/12/11 13:45
|
||||
*/
|
||||
@Data
|
||||
public class PreDetectionParam {
|
||||
|
||||
/**
|
||||
* 操作类型 0.预检测 1.正式检测
|
||||
*/
|
||||
private String operateType = "0";
|
||||
|
||||
/**
|
||||
* 检测计划id
|
||||
*/
|
||||
private String planId;
|
||||
|
||||
/**
|
||||
* 用户功能组成唯一标识 zhangsan_test
|
||||
*/
|
||||
private String userPageId;
|
||||
|
||||
/**
|
||||
* 检测终端id集合
|
||||
*/
|
||||
private List<String> devIds;
|
||||
|
||||
/**
|
||||
* 检测脚本Id
|
||||
*/
|
||||
private String scriptId;
|
||||
|
||||
/**
|
||||
* 源id
|
||||
*/
|
||||
private String sourceId;
|
||||
|
||||
/**
|
||||
* 所属误差体系
|
||||
*/
|
||||
private String errorSysId;
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package com.njcn.gather.detection.pojo.po;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author wr
|
||||
* @description
|
||||
* @date 2024/12/18 9:09
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
public class DevData {
|
||||
|
||||
@JSONField(name = "Time", ordinal = 1)
|
||||
private String time;
|
||||
|
||||
@JSONField(name = "ID", ordinal = 2)
|
||||
private String id;
|
||||
|
||||
@JSONField(name = "result", ordinal = 3)
|
||||
private Boolean result;
|
||||
|
||||
@JSONField(name = "SqlData", ordinal = 4)
|
||||
private List<SqlDataDTO> sqlData;
|
||||
|
||||
@JSONField(name = "SqlDataHarm", ordinal = 5)
|
||||
private List<SqlDataHarmDTO> sqlDataHarm;
|
||||
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
public static class SqlDataDTO {
|
||||
//类型 平均值 最大值 最小值 CP95值 实时值
|
||||
@JSONField(name = "type", ordinal = 1)
|
||||
private String type;
|
||||
//指标 电流有效值
|
||||
@JSONField(name = "desc", ordinal = 2)
|
||||
private String desc;
|
||||
@JSONField(name = "list", ordinal = 3)
|
||||
private ListDTO list;
|
||||
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
public static class ListDTO {
|
||||
@JSONField(name = "A", ordinal = 1)
|
||||
private Double a;
|
||||
@JSONField(name = "B", ordinal = 2)
|
||||
private Double b;
|
||||
@JSONField(name = "C", ordinal = 3)
|
||||
private Double c;
|
||||
@JSONField(name = "T", ordinal = 4)
|
||||
private Double t;
|
||||
}
|
||||
}
|
||||
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
public static class SqlDataHarmDTO {
|
||||
@JSONField(name = "type", ordinal = 1)
|
||||
private String type;
|
||||
@JSONField(name = "desc", ordinal = 2)
|
||||
private String desc;
|
||||
@JSONField(name = "num", ordinal = 3)
|
||||
private Integer num;
|
||||
@JSONField(name = "list", ordinal = 4)
|
||||
private ListDTO list;
|
||||
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
public static class ListDTO {
|
||||
@JSONField(name = "A", ordinal = 1)
|
||||
private List<String> a;
|
||||
@JSONField(name = "B", ordinal = 2)
|
||||
private List<String> b;
|
||||
@JSONField(name = "C", ordinal = 3)
|
||||
private List<String> c;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
package com.njcn.gather.detection.pojo.po;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* @author wr
|
||||
* @description
|
||||
* @date 2024/12/18 9:09
|
||||
*/
|
||||
@Data
|
||||
public class SourceCompareDev {
|
||||
|
||||
/**
|
||||
* 装置名称
|
||||
*/
|
||||
@JSONField(ordinal = 1)
|
||||
private String devName;
|
||||
|
||||
/**
|
||||
* 装置ip
|
||||
*/
|
||||
@JSONField(ordinal = 2)
|
||||
private String ip;
|
||||
/**
|
||||
* 装置通道
|
||||
*/
|
||||
@JSONField(ordinal = 3)
|
||||
private String lineNum;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
@JSONField(ordinal = 3)
|
||||
private String desc;
|
||||
|
||||
/**
|
||||
* 是否合格
|
||||
*/
|
||||
@JSONField(ordinal = 4)
|
||||
private Boolean isQualified;
|
||||
|
||||
/**
|
||||
* 源数据
|
||||
*/
|
||||
@JSONField(ordinal = 5)
|
||||
private Map<String, Double> sourceData;
|
||||
|
||||
/**
|
||||
* 装置数据
|
||||
*/
|
||||
@JSONField(ordinal = 6)
|
||||
private Map<String, Double> DevData;
|
||||
|
||||
@Data
|
||||
public static class Info {
|
||||
/**
|
||||
* 装置名称
|
||||
*/
|
||||
@JSONField(ordinal = 1)
|
||||
private String devName;
|
||||
|
||||
/**
|
||||
* 装置ip
|
||||
*/
|
||||
@JSONField(ordinal = 2)
|
||||
private String ip;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
@JSONField(ordinal = 3)
|
||||
private String desc;
|
||||
|
||||
/**
|
||||
* 装置下所有通道信息
|
||||
*/
|
||||
@JSONField(ordinal = 4)
|
||||
List<SourceCompareDev> devNumlist;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.njcn.gather.detection.pojo.vo;
|
||||
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author wr
|
||||
* @description
|
||||
* @date 2024/12/20 13:52
|
||||
*/
|
||||
@Data
|
||||
public class DetectionData {
|
||||
|
||||
|
||||
/**
|
||||
* 第几次谐波
|
||||
*/
|
||||
private Double num;
|
||||
|
||||
/**
|
||||
* 是否是符合数据
|
||||
*/
|
||||
private Integer isData;
|
||||
|
||||
/**
|
||||
* 装置原始数据
|
||||
*/
|
||||
private Double data;
|
||||
|
||||
/**
|
||||
* 检测源定值
|
||||
*/
|
||||
private Double resultData;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package com.njcn.gather.detection.pojo.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* CN_Gather
|
||||
*
|
||||
* @author cdf
|
||||
* @date 2024/12/29
|
||||
*/
|
||||
@Data
|
||||
public class DetectionResultInfoVO {
|
||||
|
||||
private String freq;
|
||||
|
||||
private String Ua;
|
||||
|
||||
private String Ub;
|
||||
|
||||
private String Uc;
|
||||
|
||||
private String Ia;
|
||||
|
||||
private String Ib;
|
||||
|
||||
private String Ic;
|
||||
|
||||
private List<Result> resultList;
|
||||
|
||||
private List<OriginalInfo> resultInfoList;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 检测结果
|
||||
*/
|
||||
@Data
|
||||
public static class Result{
|
||||
|
||||
private Integer channelNum;
|
||||
|
||||
private Double standardVal;
|
||||
|
||||
private Double aVal;
|
||||
|
||||
private Double aLimit;
|
||||
|
||||
private Double bVal;
|
||||
|
||||
private Double bLimit;
|
||||
|
||||
private Double cVal;
|
||||
|
||||
private Double cLimit;
|
||||
|
||||
private Double maxError;
|
||||
|
||||
private Integer result;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 原始数据
|
||||
*/
|
||||
@Data
|
||||
public static class OriginalInfo{
|
||||
|
||||
private LocalDateTime time;
|
||||
|
||||
private Double aVal;
|
||||
|
||||
private Double bVal;
|
||||
|
||||
private Double cVal;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.njcn.gather.detection.pojo.vo;
|
||||
|
||||
import io.swagger.models.auth.In;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: cdf
|
||||
* @CreateTime: 2024-12-26
|
||||
* @Description: 装置测点检测结果
|
||||
*/
|
||||
@Data
|
||||
public class DevLineTestResult {
|
||||
|
||||
private String deviceId;
|
||||
|
||||
private String deviceName;
|
||||
|
||||
private Integer[] chnResult;
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.njcn.gather.detection.pojo.vo;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author wr
|
||||
* @description
|
||||
* @date 2024/12/13 9:09
|
||||
*/
|
||||
@Data
|
||||
public class SocketDataMsg {
|
||||
|
||||
/**
|
||||
* 标识不同业务
|
||||
*/
|
||||
private String type = "aaa";
|
||||
|
||||
/**
|
||||
* 请求id,确保接收到响应时,知晓是针对的哪次请求的应答
|
||||
*/
|
||||
@JSONField(ordinal = 1)
|
||||
private String requestId;
|
||||
|
||||
/**
|
||||
* 源初始化 INIT_GATHER$01 INIT_GATHER采集初始化,01 统计采集、02 暂态采集、03 实时采集
|
||||
*/
|
||||
@JSONField(ordinal = 2)
|
||||
private String operateCode;
|
||||
|
||||
/**
|
||||
* 数据体,传输前需要将对象、Array等转为String
|
||||
*/
|
||||
@JSONField(ordinal = 4)
|
||||
private String data;
|
||||
|
||||
/**
|
||||
* code码
|
||||
*/
|
||||
@JSONField(ordinal = 3)
|
||||
private Integer code;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.njcn.gather.detection.pojo.vo;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author wr
|
||||
* @description socket 通用发送报文请求
|
||||
* @date 2024/12/11 15:57
|
||||
*/
|
||||
@Data
|
||||
public class SocketMsg<T> {
|
||||
|
||||
/**
|
||||
* 请求id,确保接收到响应时,知晓是针对的哪次请求的应答
|
||||
*/
|
||||
@JSONField(ordinal = 1)
|
||||
private String requestId;
|
||||
|
||||
/**
|
||||
* 源初始化 INIT_GATHER$01 INIT_GATHER采集初始化,01 统计采集、02 暂态采集、03 实时采集
|
||||
*/
|
||||
@JSONField(ordinal = 2)
|
||||
private String operateCode;
|
||||
|
||||
/**
|
||||
* 数据体,传输前需要将对象、Array等转为String
|
||||
*/
|
||||
@JSONField(ordinal = 3)
|
||||
private T data;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.njcn.gather.detection.pojo.vo;
|
||||
|
||||
import com.njcn.gather.detection.pojo.enums.SourceResponseCodeEnum;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class WebSocketVO<T> {
|
||||
|
||||
private String type = "aaa";
|
||||
|
||||
private String requestId;
|
||||
|
||||
private String operateCode;
|
||||
|
||||
private String code;
|
||||
|
||||
private T data;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.njcn.gather.detection.service;
|
||||
|
||||
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author wr
|
||||
* @description 预检测流程
|
||||
* @date 2024/12/10 13:44
|
||||
*/
|
||||
public interface PreDetectionService {
|
||||
|
||||
/**
|
||||
* 源通讯校验socket入参拼接
|
||||
* @param param
|
||||
* @Author: wr
|
||||
* @Date: 2024/12/11 13:26
|
||||
*/
|
||||
void sourceCommunicationCheck(PreDetectionParam param);
|
||||
|
||||
|
||||
boolean startTest(PreDetectionParam param);
|
||||
|
||||
|
||||
boolean closePreTest(PreDetectionParam param);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.njcn.gather.detection.service;
|
||||
|
||||
/**
|
||||
* @Description: 守时检测流程
|
||||
* @Author: wr
|
||||
* @Date: 2024/12/10 14:23
|
||||
*/
|
||||
public interface PunctualityService {
|
||||
|
||||
/**
|
||||
* 触发时间标识
|
||||
*/
|
||||
void triggerTimeMark();
|
||||
}
|
||||
@@ -0,0 +1,957 @@
|
||||
package com.njcn.gather.detection.service.impl;
|
||||
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||
import com.njcn.gather.detection.pojo.po.DevData;
|
||||
import com.njcn.gather.detection.pojo.vo.DetectionData;
|
||||
import com.njcn.gather.device.err.pojo.param.PqErrSysParam;
|
||||
import com.njcn.gather.device.err.pojo.po.PqErrSysDtls;
|
||||
import com.njcn.gather.device.err.service.IPqErrSysDtlsService;
|
||||
import com.njcn.gather.device.script.pojo.po.PqScriptCheckData;
|
||||
import com.njcn.gather.device.script.pojo.po.SourceIssue;
|
||||
import com.njcn.gather.device.script.service.IPqScriptCheckDataService;
|
||||
import com.njcn.gather.storage.pojo.po.AdHarmonicResult;
|
||||
import com.njcn.gather.storage.pojo.po.AdNonHarmonicResult;
|
||||
import com.njcn.gather.storage.service.DetectionDataDealService;
|
||||
import com.njcn.gather.system.dictionary.pojo.enums.DictDataEnum;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author wr
|
||||
* @description
|
||||
* @date 2024/12/20 13:52
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class DetectionServiceImpl {
|
||||
|
||||
public final IPqErrSysDtlsService pqErrSysDtlsService;
|
||||
public final IPqScriptCheckDataService pqScriptCheckDataService;
|
||||
public final DetectionDataDealService detectionDataDealService;
|
||||
|
||||
public final String TYPE_A = "A";
|
||||
public final String TYPE_B = "B";
|
||||
public final String TYPE_C = "C";
|
||||
public final String TYPE_T = "T";
|
||||
public final String U = "U";
|
||||
public final String I = "I";
|
||||
public final String F = "F";
|
||||
public final String P = "P";
|
||||
public final String MAG = "MAG";
|
||||
public final String DUR = "DUR";
|
||||
|
||||
|
||||
/**
|
||||
* 开始处理指标类型
|
||||
* 一共20组数据,开始处理格式
|
||||
*/
|
||||
public Map<String, Integer> text(List<DevData> dev, String errorSysId, Map<String, String> devIdMapComm, SourceIssue issue, DictDataEnum dataRule) {
|
||||
Map<String, List<DevData>> devDataMap = dev.stream().collect(Collectors.groupingBy(DevData::getId));
|
||||
Map<String, Integer> stringBooleanMap = new LinkedHashMap<>();
|
||||
String code="1";
|
||||
devDataMap.forEach(((key, value) -> {
|
||||
stringBooleanMap.put(key, DetectionIndexProcessing(value,code, errorSysId, devIdMapComm, dataRule, issue));
|
||||
}));
|
||||
return stringBooleanMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 取值的方法
|
||||
* 1.根据源参数下发,获得所检测项目的误差体系
|
||||
* 2.根据数据处理原则,先将原始20组数据进行处理,是任意,还是部分
|
||||
* 3.根据误差体系筛选出,在范围内的数据,然后根据最大误差值是不是在合理范围内
|
||||
*
|
||||
* @param dev 原始数据
|
||||
* @param sourceIssue 源下发的参数
|
||||
* @return
|
||||
*/
|
||||
public Integer DetectionIndexProcessing(List<DevData> dev,String code, String errorSysId, Map<String, String> devIdMapComm, DictDataEnum dataRule, SourceIssue sourceIssue) {
|
||||
PqErrSysParam.DetectionParam param = new PqErrSysParam.DetectionParam();
|
||||
param.setIndex(sourceIssue.getIndex());
|
||||
param.setScriptId(sourceIssue.getScriptId());
|
||||
param.setErrorSysId(errorSysId);
|
||||
List<PqErrSysDtls> pqErrSysDtls = pqErrSysDtlsService.listPqErrSysDtlsByPqErrSysIdAndTypes(param);
|
||||
switch (sourceIssue.getType()) {
|
||||
/**
|
||||
* 频率
|
||||
*/
|
||||
case "FREQ":
|
||||
AdNonHarmonicResult freq = isQualified(dev, devIdMapComm, pqErrSysDtls, F, sourceIssue, dataRule, "FREQ");
|
||||
detectionDataDealService.acceptAdNonResult(Arrays.asList(freq),code);
|
||||
return freq.getResultFlag();
|
||||
/**
|
||||
* 电压
|
||||
*/
|
||||
case "V":
|
||||
AdNonHarmonicResult vrms = isQualified(dev, devIdMapComm, pqErrSysDtls, U, sourceIssue, dataRule, "VRMS");
|
||||
detectionDataDealService.acceptAdNonResult(Arrays.asList(vrms),code);
|
||||
return vrms.getResultFlag();
|
||||
/**
|
||||
* 电流
|
||||
*/
|
||||
case "I":
|
||||
AdNonHarmonicResult irms = isQualified(dev, devIdMapComm, pqErrSysDtls, I, sourceIssue, dataRule, "IRMS");
|
||||
detectionDataDealService.acceptAdNonResult(Arrays.asList(irms),code);
|
||||
return irms.getResultFlag();
|
||||
/**
|
||||
* 谐波电压
|
||||
*/
|
||||
case "HV":
|
||||
AdHarmonicResult harmV = isHarmQualified(dev, devIdMapComm, pqErrSysDtls, U, sourceIssue, dataRule, 2);
|
||||
detectionDataDealService.acceptAdResult(Arrays.asList(harmV),code);
|
||||
return harmV.getResultFlag();
|
||||
/**
|
||||
* 谐波电流
|
||||
*/
|
||||
case "HI":
|
||||
AdHarmonicResult harmI = isHarmQualified(dev, devIdMapComm, pqErrSysDtls, I, sourceIssue, dataRule, 2);
|
||||
detectionDataDealService.acceptAdResult(Arrays.asList(harmI),code);
|
||||
return harmI.getResultFlag();
|
||||
/**
|
||||
* 间谐波电压
|
||||
*/
|
||||
case "HSV":
|
||||
AdHarmonicResult harmInV = isHarmQualified(dev, devIdMapComm, pqErrSysDtls, U, sourceIssue, dataRule, 1);
|
||||
detectionDataDealService.acceptAdResult(Arrays.asList(harmInV),code);
|
||||
return harmInV.getResultFlag();
|
||||
/**
|
||||
* 间谐波电流
|
||||
*/
|
||||
case "HSI":
|
||||
AdHarmonicResult harmInI = isHarmQualified(dev, devIdMapComm, pqErrSysDtls, I, sourceIssue, dataRule, 1);
|
||||
detectionDataDealService.acceptAdResult(Arrays.asList(harmInI),code);
|
||||
return harmInI.getResultFlag();
|
||||
/**
|
||||
* 三相电压不平衡度
|
||||
*/
|
||||
case "IMBV":
|
||||
AdNonHarmonicResult vUnban = isUnBalanceOrFlickerQualified(dev, devIdMapComm, pqErrSysDtls, U, sourceIssue, dataRule, "V_UNBAN");
|
||||
detectionDataDealService.acceptAdNonResult(Arrays.asList(vUnban),code);
|
||||
return vUnban.getResultFlag();
|
||||
/**
|
||||
* 三相电流不平衡度
|
||||
*/
|
||||
case "IMBA":
|
||||
AdNonHarmonicResult iUnban = isUnBalanceOrFlickerQualified(dev, devIdMapComm, pqErrSysDtls, U, sourceIssue, dataRule, "I_UNBAN");
|
||||
detectionDataDealService.acceptAdNonResult(Arrays.asList(iUnban),code);
|
||||
return iUnban.getResultFlag();
|
||||
/**
|
||||
* 谐波有功功率
|
||||
*/
|
||||
case "HP":
|
||||
AdHarmonicResult harmP = isHarmQualified(dev, devIdMapComm, pqErrSysDtls, P, sourceIssue, dataRule, 2);
|
||||
detectionDataDealService.acceptAdResult(Arrays.asList(harmP),code);
|
||||
return harmP.getResultFlag();
|
||||
/**
|
||||
* 功率
|
||||
*/
|
||||
case "P":
|
||||
return 4;
|
||||
/**
|
||||
* 闪变
|
||||
*/
|
||||
case "F":
|
||||
AdNonHarmonicResult pst = isUnBalanceOrFlickerQualified(dev, devIdMapComm, pqErrSysDtls, null, sourceIssue, dataRule, "PST");
|
||||
detectionDataDealService.acceptAdNonResult(Arrays.asList(pst),code);
|
||||
return pst.getResultFlag();
|
||||
/**
|
||||
* 暂态
|
||||
*/
|
||||
case "VOLTAGE":
|
||||
return isVoltageQualified(dev, devIdMapComm, pqErrSysDtls, sourceIssue, dataRule,code);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断值是否在误差范围内,有则进行判断否则则不进行计算(非谐波类型)
|
||||
*
|
||||
* @param dev 处理过后的数据
|
||||
* @param pqErrSysDtls 误差体系
|
||||
* @param type (电压还是电流)
|
||||
* @param sourceIssue 源下发所对应的参数
|
||||
* @param dataRule 数据处理原则
|
||||
* @param code 源下发的装置通道code(->desc)
|
||||
* @return
|
||||
*/
|
||||
public AdNonHarmonicResult isQualified(List<DevData> dev,
|
||||
Map<String, String> devIdMapComm,
|
||||
List<PqErrSysDtls> pqErrSysDtls,
|
||||
String type,
|
||||
SourceIssue sourceIssue,
|
||||
DictDataEnum dataRule,
|
||||
String code) {
|
||||
Map<String, List<Double>> map = devListMap(dev, dataRule, code);
|
||||
Double fData = 1.0;
|
||||
if (U.equals(type)) {
|
||||
fData = sourceIssue.getFUn();
|
||||
}
|
||||
if (I.equals(type)) {
|
||||
fData = sourceIssue.getFIn();
|
||||
}
|
||||
if (F.equals(type)) {
|
||||
fData = sourceIssue.getFFreq();
|
||||
}
|
||||
AdNonHarmonicResult result = new AdNonHarmonicResult();
|
||||
String[] split = dev.get(0).getId().split("_");
|
||||
String devID = devIdMapComm.get(split[0]);
|
||||
result.setMonitorId(devID + "_" + split[1]);
|
||||
result.setScriptId(sourceIssue.getScriptId());
|
||||
result.setSort(sourceIssue.getIndex());
|
||||
result.setAdType(pqErrSysDtls.get(0).getScriptType());
|
||||
result.setDataType("avg");
|
||||
if (map.containsKey(TYPE_T)) {
|
||||
DetectionData t = rangeComparisonList(map.get(TYPE_T), pqErrSysDtls, fData, 1.0, dataRule);
|
||||
result.setTValue(t.getData() + "_" + t.getIsData()+"_"+t.getResultData());
|
||||
result.setResultFlag(t.getIsData());
|
||||
} else {
|
||||
//取出源所对应的相别信息
|
||||
List<SourceIssue.ChannelListDTO> channelTypeAList = sourceIssue.getChannelList().stream()
|
||||
.filter(x -> (type + "a").equals(x.getChannelType()))
|
||||
.collect(Collectors.toList());
|
||||
DetectionData a = rangeComparisonList(map.get(TYPE_A), pqErrSysDtls, fData, channelTypeAList.get(0).getFAmp(), dataRule);
|
||||
result.setAValue(a.getData() + "_" + a.getIsData()+"_"+a.getResultData());
|
||||
|
||||
List<SourceIssue.ChannelListDTO> channelTypeBList = sourceIssue.getChannelList().stream()
|
||||
.filter(x -> (type + "b").equals(x.getChannelType()))
|
||||
.collect(Collectors.toList());
|
||||
DetectionData b = rangeComparisonList(map.get(TYPE_B), pqErrSysDtls, fData, channelTypeBList.get(0).getFAmp(), dataRule);
|
||||
result.setBValue(b.getData() + "_" + b.getIsData()+"_"+b.getResultData());
|
||||
|
||||
List<SourceIssue.ChannelListDTO> channelTypeCList = sourceIssue.getChannelList().stream()
|
||||
.filter(x -> (type + "c").equals(x.getChannelType()))
|
||||
.collect(Collectors.toList());
|
||||
DetectionData c = rangeComparisonList(map.get(TYPE_C), pqErrSysDtls, fData, channelTypeCList.get(0).getFAmp(), dataRule);
|
||||
result.setCValue(c.getData() + "_" + c.getIsData()+"_"+c.getResultData());
|
||||
|
||||
List<Integer> numbers = Arrays.asList(a.getIsData(), b.getIsData(), a.getIsData()).stream().distinct().collect(Collectors.toList());
|
||||
return getAdNonHarmonicResult(result, numbers);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断值是否在误差范围内,有则进行判断否则则不进行计算(谐波类型)
|
||||
*
|
||||
* @param dev 处理过后的数据
|
||||
* @param pqErrSysDtls 误差体系
|
||||
* @param type (电压还是电流)
|
||||
* @param sourceIssue 源下发所对应的参数
|
||||
* @param dataRule 数据处理原则
|
||||
* @param num 处理数组下标位数
|
||||
* @return
|
||||
*/
|
||||
public AdHarmonicResult isHarmQualified(List<DevData> dev,
|
||||
Map<String, String> devIdMapComm,
|
||||
List<PqErrSysDtls> pqErrSysDtls,
|
||||
String type,
|
||||
SourceIssue sourceIssue,
|
||||
DictDataEnum dataRule,
|
||||
Integer num) {
|
||||
Map<String, Map<Double, List<Double>>> devMap = devHarmListMap(dev, sourceIssue, dataRule, num);
|
||||
Double fData = 1.0;
|
||||
if (U.equals(type)) {
|
||||
fData = sourceIssue.getFUn();
|
||||
}
|
||||
if (I.equals(type)) {
|
||||
fData = sourceIssue.getFIn();
|
||||
}
|
||||
List<DetectionData> integerBooleanA = harmRangeComparison(pqErrSysDtls, type, TYPE_A, sourceIssue, dataRule, devMap.get(TYPE_A), fData, num);
|
||||
List<DetectionData> integerBooleanB = harmRangeComparison(pqErrSysDtls, type, TYPE_B, sourceIssue, dataRule, devMap.get(TYPE_B), fData, num);
|
||||
List<DetectionData> integerBooleanC = harmRangeComparison(pqErrSysDtls, type, TYPE_C, sourceIssue, dataRule, devMap.get(TYPE_C), fData, num);
|
||||
AdHarmonicResult harmonicResult = new AdHarmonicResult();
|
||||
String[] split = dev.get(0).getId().split("_");
|
||||
String devID = devIdMapComm.get(split[0]);
|
||||
harmonicResult.setMonitorId(devID + "_" + split[1]);
|
||||
harmonicResult.setScriptId(sourceIssue.getScriptId());
|
||||
harmonicResult.setSort(sourceIssue.getIndex());
|
||||
harmonicResult.setAdType(pqErrSysDtls.get(0).getScriptType());
|
||||
harmonicResult.setDataType("avg");
|
||||
reflectHarmonic("a", integerBooleanA, harmonicResult);
|
||||
reflectHarmonic("b", integerBooleanA, harmonicResult);
|
||||
reflectHarmonic("c", integerBooleanA, harmonicResult);
|
||||
List<Integer> list = new ArrayList<>();
|
||||
list.addAll(integerBooleanA.stream().map(DetectionData::getIsData).distinct().collect(Collectors.toList()));
|
||||
list.addAll(integerBooleanB.stream().map(DetectionData::getIsData).distinct().collect(Collectors.toList()));
|
||||
list.addAll(integerBooleanC.stream().map(DetectionData::getIsData).distinct().collect(Collectors.toList()));
|
||||
List<Integer> numbers = list.stream().distinct().collect(Collectors.toList());
|
||||
return getAdHarmonicResult(harmonicResult, numbers);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 判断值是否在误差范围内,有则进行判断否则则不进行计算(三相不平衡和闪变)
|
||||
*
|
||||
* @param dev 处理过后的数据
|
||||
* @param pqErrSysDtls 误差体系
|
||||
* @param type (电压还是电流)
|
||||
* @param sourceIssue 源下发所对应的参数
|
||||
* @param dataRule 数据处理原则
|
||||
* @return
|
||||
*/
|
||||
public AdNonHarmonicResult isUnBalanceOrFlickerQualified(List<DevData> dev,
|
||||
Map<String, String> devIdMapComm,
|
||||
List<PqErrSysDtls> pqErrSysDtls,
|
||||
String type,
|
||||
SourceIssue sourceIssue,
|
||||
DictDataEnum dataRule,
|
||||
String code) {
|
||||
List<PqScriptCheckData> checkData = pqScriptCheckDataService.list(new MPJLambdaWrapper<PqScriptCheckData>()
|
||||
.eq(PqScriptCheckData::getIndex, sourceIssue.getIndex())
|
||||
.eq(PqScriptCheckData::getScriptId, sourceIssue.getScriptId())
|
||||
);
|
||||
Map<String, List<Double>> map = devListMap(dev, dataRule, code);
|
||||
Double fData = 1.0;
|
||||
if (U.equals(type)) {
|
||||
fData = sourceIssue.getFUn();
|
||||
}
|
||||
if (I.equals(type)) {
|
||||
fData = sourceIssue.getFIn();
|
||||
}
|
||||
AdNonHarmonicResult result = new AdNonHarmonicResult();
|
||||
String[] split = dev.get(0).getId().split("_");
|
||||
String devID = devIdMapComm.get(split[0]);
|
||||
result.setMonitorId(devID + "_" + split[1]);
|
||||
result.setScriptId(sourceIssue.getScriptId());
|
||||
result.setSort(sourceIssue.getIndex());
|
||||
result.setAdType(pqErrSysDtls.get(0).getScriptType());
|
||||
result.setDataType("avg");
|
||||
//取出源所对应的相别信息
|
||||
List<PqScriptCheckData> channelTypeAList = checkData.stream()
|
||||
.filter(x -> TYPE_A.equals(x.getPhase()))
|
||||
.collect(Collectors.toList());
|
||||
DetectionData a = rangeComparisonList(map.get(TYPE_A), pqErrSysDtls, fData, channelTypeAList.get(0).getValue(), dataRule);
|
||||
result.setAValue(a.getData() + "_" + a.getIsData()+"_"+a.getResultData());
|
||||
|
||||
List<PqScriptCheckData> channelTypeBList = checkData.stream()
|
||||
.filter(x -> TYPE_B.equals(x.getPhase()))
|
||||
.collect(Collectors.toList());
|
||||
DetectionData b = rangeComparisonList(map.get(TYPE_B), pqErrSysDtls, fData, channelTypeBList.get(0).getValue(), dataRule);
|
||||
result.setBValue(b.getData() + "_" + b.getIsData()+"_"+b.getResultData());
|
||||
|
||||
List<PqScriptCheckData> channelTypeCList = checkData.stream()
|
||||
.filter(x -> TYPE_C.equals(x.getPhase()))
|
||||
.collect(Collectors.toList());
|
||||
DetectionData c = rangeComparisonList(map.get(TYPE_C), pqErrSysDtls, fData, channelTypeCList.get(0).getValue(), dataRule);
|
||||
result.setCValue(c.getData() + "_" + c.getIsData()+"_"+b.getResultData());
|
||||
|
||||
List<Integer> numbers = Arrays.asList(a.getIsData(), b.getIsData(), a.getIsData());
|
||||
return getAdNonHarmonicResult(result, numbers);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 判断值是否在误差范围内,有则进行判断否则则不进行计算(暂态)
|
||||
*
|
||||
* @param dev 处理过后的数据
|
||||
* @param pqErrSysDtls 误差体系
|
||||
* @param sourceIssue 源下发所对应的参数
|
||||
* @param dataRule 数据处理原则
|
||||
* @param code 计划code
|
||||
* @return
|
||||
*/
|
||||
public Integer isVoltageQualified(List<DevData> dev,
|
||||
Map<String, String> devIdMapComm,
|
||||
List<PqErrSysDtls> pqErrSysDtls,
|
||||
SourceIssue sourceIssue,
|
||||
DictDataEnum dataRule,
|
||||
String code
|
||||
) {
|
||||
//电压幅值处理数据
|
||||
Map<String, List<Double>> mag = devListMap(dev, dataRule, MAG);
|
||||
//暂降时间处理数据
|
||||
Map<String, List<Double>> dur = devListMap(dev, dataRule, DUR);
|
||||
//理论上根据检测脚本,能知道误差体系,可以知道多个误差体系
|
||||
List<PqErrSysDtls> magErrList = pqErrSysDtls.stream().filter(x -> MAG.equals(x.getScriptCode())).collect(Collectors.toList());
|
||||
List<PqErrSysDtls> durErrList = pqErrSysDtls.stream().filter(x -> DUR.equals(x.getScriptCode())).collect(Collectors.toList());
|
||||
|
||||
AdNonHarmonicResult magResult = voltageResult(dev.get(0).getId(), devIdMapComm, sourceIssue, dataRule, mag, magErrList, sourceIssue.getFUn(), MAG);
|
||||
magResult.setAdType(magErrList.get(0).getScriptType());
|
||||
AdNonHarmonicResult durResult = voltageResult(dev.get(0).getId(), devIdMapComm, sourceIssue, dataRule, dur, durErrList, sourceIssue.getFFreq(), DUR);
|
||||
durResult.setAdType(durErrList.get(0).getScriptType());
|
||||
detectionDataDealService.acceptAdNonResult(Arrays.asList(magResult,durResult),code);
|
||||
List<Integer> numbers = Arrays.asList(magResult.getResultFlag(), durResult.getResultFlag()).stream().distinct().collect(Collectors.toList());
|
||||
if (numbers.contains(4)) {
|
||||
return 4;
|
||||
} else if (numbers.contains(2)) {
|
||||
return 2;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param devId 装置监测点id(ip_通道)
|
||||
* @param devIdMapComm ip_通道,装置名称
|
||||
* @param sourceIssue 源下发信息
|
||||
* @param dataRule 数据处理原则
|
||||
* @param mag
|
||||
* @param magErrList
|
||||
* @param fData
|
||||
* @Description:
|
||||
* @return: com.njcn.gather.storage.pojo.po.AdNonHarmonicResult
|
||||
* @Author: wr
|
||||
* @Date: 2024/12/30 14:54
|
||||
*/
|
||||
private AdNonHarmonicResult voltageResult(String devId,
|
||||
Map<String, String> devIdMapComm,
|
||||
SourceIssue sourceIssue,
|
||||
DictDataEnum dataRule,
|
||||
Map<String, List<Double>> mag,
|
||||
List<PqErrSysDtls> magErrList,
|
||||
Double fData,
|
||||
String dur
|
||||
) {
|
||||
AdNonHarmonicResult result = new AdNonHarmonicResult();
|
||||
String[] split = devId.split("_");
|
||||
String devID = devIdMapComm.get(split[0]);
|
||||
result.setMonitorId(devID + "_" + split[1]);
|
||||
result.setScriptId(sourceIssue.getScriptId());
|
||||
result.setSort(sourceIssue.getIndex());
|
||||
result.setDataType("avg");
|
||||
//取出源所对应的相别信息
|
||||
List<SourceIssue.ChannelListDTO> channelTypeAList = sourceIssue.getChannelList().stream()
|
||||
.filter(x -> ("Ua").equals(x.getChannelType()))
|
||||
.collect(Collectors.toList());
|
||||
Double retainATime;
|
||||
if (DUR.equals(dur)) {
|
||||
retainATime = channelTypeAList.get(0).getDipData().getRetainTime();
|
||||
} else {
|
||||
retainATime = channelTypeAList.get(0).getFAmp();
|
||||
}
|
||||
DetectionData a = rangeComparisonList(mag.get(TYPE_A), magErrList, fData, retainATime, dataRule);
|
||||
result.setAValue(a.getData() + "_" + a.getIsData()+"_"+a.getResultData());
|
||||
|
||||
List<SourceIssue.ChannelListDTO> channelTypeBList = sourceIssue.getChannelList().stream()
|
||||
.filter(x -> ("Ub").equals(x.getChannelType()))
|
||||
.collect(Collectors.toList());
|
||||
Double retainBTime;
|
||||
if (DUR.equals(dur)) {
|
||||
retainBTime = channelTypeBList.get(0).getDipData().getRetainTime();
|
||||
} else {
|
||||
retainBTime = channelTypeBList.get(0).getFAmp();
|
||||
}
|
||||
DetectionData b = rangeComparisonList(mag.get(TYPE_B), magErrList, fData, retainBTime, dataRule);
|
||||
result.setBValue(b.getData() + "_" + b.getIsData()+"_"+b.getResultData());
|
||||
|
||||
List<SourceIssue.ChannelListDTO> channelTypeCList = sourceIssue.getChannelList().stream()
|
||||
.filter(x -> ("Uc").equals(x.getChannelType()))
|
||||
.collect(Collectors.toList());
|
||||
Double retainCTime;
|
||||
if (DUR.equals(dur)) {
|
||||
retainCTime = channelTypeCList.get(0).getDipData().getRetainTime();
|
||||
} else {
|
||||
retainCTime = channelTypeCList.get(0).getFAmp();
|
||||
}
|
||||
DetectionData c = rangeComparisonList(mag.get(TYPE_C), magErrList, fData, retainCTime, dataRule);
|
||||
result.setCValue(c.getData() + "_" + c.getIsData()+"_"+c.getResultData());
|
||||
|
||||
List<Integer> numbers = Arrays.asList(a.getIsData(), b.getIsData(), a.getIsData()).stream().distinct().collect(Collectors.toList());
|
||||
|
||||
return getAdNonHarmonicResult(result, numbers);
|
||||
}
|
||||
|
||||
private AdNonHarmonicResult getAdNonHarmonicResult(AdNonHarmonicResult result, List<Integer> numbers) {
|
||||
if (numbers.size() > 2) {
|
||||
result.setResultFlag(4);
|
||||
} else if (numbers.size() > 1) {
|
||||
if (numbers.contains(4)) {
|
||||
result.setResultFlag(4);
|
||||
} else if (numbers.contains(2)) {
|
||||
result.setResultFlag(2);
|
||||
}
|
||||
} else {
|
||||
result.setResultFlag(numbers.get(0));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private AdHarmonicResult getAdHarmonicResult(AdHarmonicResult result, List<Integer> numbers) {
|
||||
if (numbers.size() > 2) {
|
||||
result.setResultFlag(4);
|
||||
} else if (numbers.size() > 1) {
|
||||
if (numbers.contains(4)) {
|
||||
result.setResultFlag(4);
|
||||
} else if (numbers.contains(2)) {
|
||||
result.setResultFlag(2);
|
||||
}
|
||||
} else {
|
||||
result.setResultFlag(numbers.get(0));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理非谐波类型取值
|
||||
*
|
||||
* @param dev
|
||||
* @param dataRule
|
||||
*/
|
||||
public Map<String, List<Double>> devListMap(List<DevData> dev, DictDataEnum dataRule, String code) {
|
||||
//设置
|
||||
Map<String, List<Double>> map = new HashMap<>(3);
|
||||
List<Double> a = new ArrayList<>();
|
||||
List<Double> b = new ArrayList<>();
|
||||
List<Double> c = new ArrayList<>();
|
||||
List<Double> t = new ArrayList<>();
|
||||
List<DevData.SqlDataDTO> sqlDataDTOS = dev.stream().flatMap(x -> x.getSqlData().stream().filter(j -> code.equals(j.getDesc())))
|
||||
.collect(Collectors.toList());
|
||||
if (CollUtil.isNotEmpty(sqlDataDTOS)) {
|
||||
List<DevData.SqlDataDTO.ListDTO> list = sqlDataDTOS.stream().map(DevData.SqlDataDTO::getList).collect(Collectors.toList());
|
||||
a = list.stream()
|
||||
.filter(x -> ObjectUtil.isNotNull(x.getA()))
|
||||
.map(DevData.SqlDataDTO.ListDTO::getA)
|
||||
.sorted(Comparator.comparing(Double::doubleValue).reversed())
|
||||
.collect(Collectors.toList());
|
||||
b = list.stream()
|
||||
.filter(x -> ObjectUtil.isNotNull(x.getA()))
|
||||
.map(DevData.SqlDataDTO.ListDTO::getB)
|
||||
.sorted(Comparator.comparing(Double::doubleValue).reversed())
|
||||
.collect(Collectors.toList());
|
||||
c = list.stream()
|
||||
.filter(x -> ObjectUtil.isNotNull(x.getC()))
|
||||
.map(DevData.SqlDataDTO.ListDTO::getC)
|
||||
.sorted(Comparator.comparing(Double::doubleValue).reversed())
|
||||
.collect(Collectors.toList());
|
||||
t = list.stream().filter(x -> ObjectUtil.isNotNull(x.getT()))
|
||||
.map(DevData.SqlDataDTO.ListDTO::getT)
|
||||
.sorted(Comparator.comparing(Double::doubleValue).reversed())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
switch (dataRule) {
|
||||
case SECTION_VALUE:
|
||||
a = getDoubles(a, 1, 19);
|
||||
b = getDoubles(b, 1, 19);
|
||||
c = getDoubles(c, 1, 19);
|
||||
t = getDoubles(t, 1, 19);
|
||||
break;
|
||||
case CP95_VALUE:
|
||||
a = getDoubles(a, 1, 2);
|
||||
b = getDoubles(b, 1, 2);
|
||||
c = getDoubles(c, 1, 2);
|
||||
t = getDoubles(t, 1, 2);
|
||||
break;
|
||||
case AVG_VALUE:
|
||||
a = getAvgDoubles(a);
|
||||
b = getAvgDoubles(b);
|
||||
c = getAvgDoubles(c);
|
||||
t = getAvgDoubles(t);
|
||||
break;
|
||||
}
|
||||
map.put(TYPE_A, a);
|
||||
map.put(TYPE_B, b);
|
||||
map.put(TYPE_C, c);
|
||||
if (CollUtil.isNotEmpty(t)) {
|
||||
map.put(TYPE_T, t);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
private void reflectHarmonic(String phase, List<DetectionData> integerBooleanA, AdHarmonicResult harmonicResult) {
|
||||
Map<Double, DetectionData> dataMap = integerBooleanA.stream().collect(Collectors.toMap(DetectionData::getNum, Function.identity()));
|
||||
dataMap.forEach((key, value) -> {
|
||||
try {
|
||||
// 设置 id 字段
|
||||
Field idField = AdHarmonicResult.class.getDeclaredField(phase + "Value" + key.intValue());
|
||||
idField.setAccessible(true);
|
||||
if (ObjectUtil.isNull(value.getIsData())) {
|
||||
idField.set(harmonicResult, value.getData());
|
||||
} else {
|
||||
idField.set(harmonicResult, value.getData() + "_" + value.getIsData()+"_"+value.getResultData());
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (NoSuchFieldException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param pqErrSysDtls 误差体系
|
||||
* @param type U,I
|
||||
* @param phase A,B,C
|
||||
* @param sourceIssue 源下发的值(谐波)
|
||||
* @param dataRule 数据处理原则
|
||||
* @param devMap
|
||||
* @param fData
|
||||
* @return
|
||||
*/
|
||||
public List<DetectionData> harmRangeComparison(List<PqErrSysDtls> pqErrSysDtls,
|
||||
String type,
|
||||
String phase,
|
||||
SourceIssue sourceIssue,
|
||||
DictDataEnum dataRule,
|
||||
Map<Double, List<Double>> devMap,
|
||||
Double fData, Integer num) {
|
||||
List<DetectionData> info = new ArrayList<>();
|
||||
//根据谐波几次相值/额定值
|
||||
Map<Double, Double> issueHarmMap;
|
||||
if (P.equals(type)) {
|
||||
List<PqScriptCheckData> checkData = pqScriptCheckDataService.list(new MPJLambdaWrapper<PqScriptCheckData>()
|
||||
.eq(PqScriptCheckData::getIndex, sourceIssue.getIndex())
|
||||
.eq(PqScriptCheckData::getPhase, phase)
|
||||
.eq(PqScriptCheckData::getScriptId, sourceIssue.getScriptId())
|
||||
);
|
||||
issueHarmMap = checkData.stream().collect(Collectors.toMap(PqScriptCheckData::getHarmNum, PqScriptCheckData::getValue));
|
||||
} else {
|
||||
if (1 == num) {
|
||||
issueHarmMap = sourceIssue.getChannelList().stream()
|
||||
.filter(x -> (type + phase.toLowerCase()).equals(x.getChannelType()))
|
||||
.flatMap(x -> x.getInharmList().stream())
|
||||
.collect(Collectors.toMap(SourceIssue.ChannelListDTO.InharmModel::getInharm, x -> x.getFApm()));
|
||||
} else {
|
||||
issueHarmMap = sourceIssue.getChannelList().stream()
|
||||
.filter(x -> (type + phase.toLowerCase()).equals(x.getChannelType()))
|
||||
.flatMap(x -> x.getHarmList().stream())
|
||||
.collect(Collectors.toMap(SourceIssue.ChannelListDTO.HarmModel::getHarm, x -> x.getFApm()));
|
||||
}
|
||||
|
||||
}
|
||||
Map<Double, PqErrSysDtls> errSysDtlMap = new LinkedHashMap<>();
|
||||
issueHarmMap.forEach((key, value) -> {
|
||||
//获得误差体系
|
||||
List<PqErrSysDtls> errSysDtls = pqErrSysDtls.stream().filter(x -> rangeComparison(x.getStartValue(),
|
||||
x.getStartFlag(),
|
||||
x.getEndValue(),
|
||||
x.getEndFlag(),
|
||||
divide(value - fData, fData).doubleValue())).collect(Collectors.toList());
|
||||
if (CollUtil.isNotEmpty(errSysDtls)) {
|
||||
errSysDtlMap.put(key, errSysDtls.get(0));
|
||||
} else {
|
||||
errSysDtlMap.put(key, null);
|
||||
}
|
||||
});
|
||||
devMap.forEach((harm, harmDataList) -> {
|
||||
PqErrSysDtls errSysDtl = errSysDtlMap.get(harm);
|
||||
DetectionData data = new DetectionData();
|
||||
data.setIsData(4);
|
||||
data.setNum(harm);
|
||||
data.setData(harmDataList.get(0));
|
||||
if (ObjectUtil.isNotNull(errSysDtl)) {
|
||||
if (0 == errSysDtl.getErrorValueType()) {
|
||||
errSysDtl.setMaxErrorValue(multiply(errSysDtl.getMaxErrorValue(), fData, 0));
|
||||
}
|
||||
Double v = issueHarmMap.get(harm);
|
||||
data.setResultData(v);
|
||||
setDetection(dataRule, harmDataList, errSysDtl, data, v);
|
||||
}
|
||||
info.add(data);
|
||||
});
|
||||
return info;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dataRule 数据处理原则
|
||||
* @param harmDataList 原始数据集合
|
||||
* @param errSysDtl 误差体系
|
||||
* @param data 初始化原始数据
|
||||
* @param v 源下发的数据
|
||||
* @Description:
|
||||
* @Author: wr
|
||||
* @Date: 2024/12/29 18:10
|
||||
*/
|
||||
private void setDetection(DictDataEnum dataRule, List<Double> harmDataList, PqErrSysDtls errSysDtl, DetectionData data, Double v) {
|
||||
List<Double> qualifiedList = harmDataList.stream()
|
||||
.filter(x -> NumberUtil.isIn(devSubtractChannelData(x, v, errSysDtl.getErrorValueType()),
|
||||
BigDecimal.valueOf(-errSysDtl.getMaxErrorValue()),
|
||||
BigDecimal.valueOf(errSysDtl.getMaxErrorValue()))).collect(Collectors.toList());
|
||||
if (CollUtil.isNotEmpty(qualifiedList)) {
|
||||
data.setData(qualifiedList.get(0));
|
||||
switch (dataRule) {
|
||||
case AT_WILL_VALUE:
|
||||
case CP95_VALUE:
|
||||
case AVG_VALUE:
|
||||
if (qualifiedList.size() > 0) {
|
||||
data.setIsData(1);
|
||||
} else {
|
||||
data.setIsData(2);
|
||||
}
|
||||
break;
|
||||
case SECTION_VALUE:
|
||||
case Own_value:
|
||||
if (qualifiedList.size() == harmDataList.size()) {
|
||||
data.setIsData(1);
|
||||
} else {
|
||||
data.setIsData(2);
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
data.setIsData(2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Map<String, Map<Double, List<Double>>> devHarmListMap(List<DevData> dev, SourceIssue sourceIssue, DictDataEnum dataRule, Integer num) {
|
||||
Map<String, Map<Double, List<Double>>> map = new HashMap<>(3);
|
||||
List<Double> harmNum;
|
||||
if (1 == num) {
|
||||
harmNum = sourceIssue.getChannelList().stream()
|
||||
.flatMap(x -> x.getInharmList().stream().map(f -> f.getInharm()))
|
||||
.sorted().distinct().collect(Collectors.toList());
|
||||
} else {
|
||||
harmNum = sourceIssue.getChannelList().stream()
|
||||
.flatMap(x -> x.getHarmList().stream().map(f -> f.getHarm()))
|
||||
.sorted().distinct().collect(Collectors.toList());
|
||||
}
|
||||
for (DevData devData : dev) {
|
||||
DevData.SqlDataDTO fund = devData.getSqlData().stream().collect(Collectors.toList()).stream().findFirst().get();
|
||||
DevData.SqlDataHarmDTO harm = devData.getSqlDataHarm().stream().filter(x -> 49 == x.getNum()).collect(Collectors.toList()).stream().findFirst().get();
|
||||
if (ObjectUtil.isNotNull(fund)) {
|
||||
harmPut(TYPE_A, map, harmNum, harm, String.valueOf(fund.getList().getA()), num);
|
||||
harmPut(TYPE_B, map, harmNum, harm, String.valueOf(fund.getList().getA()), num);
|
||||
harmPut(TYPE_C, map, harmNum, harm, String.valueOf(fund.getList().getA()), num);
|
||||
} else {
|
||||
harmPut(TYPE_A, map, harmNum, harm, "1.0", num);
|
||||
harmPut(TYPE_B, map, harmNum, harm, "1.0", num);
|
||||
harmPut(TYPE_C, map, harmNum, harm, "1.0", num);
|
||||
}
|
||||
}
|
||||
map.forEach((typeKey, typeValue) -> {
|
||||
typeValue.forEach((key, value) -> {
|
||||
value.sort(Comparator.comparing(Double::doubleValue).reversed());
|
||||
switch (dataRule) {
|
||||
case SECTION_VALUE:
|
||||
value.subList(19, value.size()).clear(); // 保留前19个元素
|
||||
value.remove(0); // 移除第一个元素
|
||||
break;
|
||||
case CP95_VALUE:
|
||||
value.subList(1, value.size()).clear(); // 保留第一个元素
|
||||
break;
|
||||
case AVG_VALUE:
|
||||
double average = value.stream().mapToDouble(Double::doubleValue).average().orElse(0.0);
|
||||
value.clear(); // 清空列表
|
||||
value.add(average); // 添加平均值
|
||||
break;
|
||||
}
|
||||
});
|
||||
});
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理数据是否合格
|
||||
*
|
||||
* @param list 原始的数据
|
||||
* @param pqErrSysDtls 误差体系
|
||||
* @param data 源下发的额定信息(额定电压,额定电流)
|
||||
* @param channelData 源下发的通道信息的值包括 {Ua, Ub, Uc, Ux, Ia, Ib, Ic, Ix ,NULL}
|
||||
* @param dataRule 数据处理原则
|
||||
* @returnd
|
||||
*/
|
||||
public DetectionData rangeComparisonList(List<Double> list, List<PqErrSysDtls> pqErrSysDtls, Double data, Double channelData, DictDataEnum dataRule) {
|
||||
DetectionData detectionData = new DetectionData();
|
||||
detectionData.setIsData(4);
|
||||
detectionData.setData(list.get(0));
|
||||
//先根据源所下发的数据,是否在误差体系范围内在则可以进行误差体系判断
|
||||
//获得误差体系
|
||||
List<PqErrSysDtls> errSysDtls = pqErrSysDtls.stream().filter(x -> rangeComparison(multiply(x.getStartValue(), data, x.getConditionType()),
|
||||
x.getStartFlag(),
|
||||
multiply(x.getEndValue(), data, x.getConditionType()),
|
||||
x.getEndFlag(),
|
||||
channelData)).collect(Collectors.toList());
|
||||
if (CollUtil.isNotEmpty(errSysDtls)) {
|
||||
PqErrSysDtls errSysDtl = errSysDtls.get(0);
|
||||
if (DUR.equals(errSysDtl.getScriptType())) {
|
||||
List<Double> qualifiedList = list.stream()
|
||||
.filter(x -> NumberUtil.isIn(BigDecimal.valueOf(x.doubleValue()),
|
||||
BigDecimal.valueOf(1.0 / data * (channelData - errSysDtl.getMaxErrorValue())),
|
||||
BigDecimal.valueOf(1.0 / data * (channelData + errSysDtl.getMaxErrorValue())))
|
||||
).collect(Collectors.toList());
|
||||
detectionData.setResultData(BigDecimal.valueOf(1.0 / data).doubleValue());
|
||||
if (CollUtil.isNotEmpty(qualifiedList)) {
|
||||
detectionData.setData(qualifiedList.get(0));
|
||||
switch (dataRule) {
|
||||
case AT_WILL_VALUE:
|
||||
case CP95_VALUE:
|
||||
case AVG_VALUE:
|
||||
if (qualifiedList.size() > 0) {
|
||||
detectionData.setIsData(1);
|
||||
} else {
|
||||
detectionData.setIsData(2);
|
||||
}
|
||||
break;
|
||||
case SECTION_VALUE:
|
||||
case Own_value:
|
||||
if (qualifiedList.size() == qualifiedList.size()) {
|
||||
detectionData.setIsData(1);
|
||||
} else {
|
||||
detectionData.setIsData(2);
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
detectionData.setIsData(2);
|
||||
}
|
||||
} else {
|
||||
if (0 == errSysDtl.getErrorValueType()) {
|
||||
errSysDtl.setMaxErrorValue(multiply(errSysDtl.getMaxErrorValue(), data, 0));
|
||||
}
|
||||
detectionData.setResultData(errSysDtl.getMaxErrorValue());
|
||||
setDetection(dataRule, list, errSysDtl, detectionData, channelData);
|
||||
}
|
||||
}
|
||||
return detectionData;
|
||||
}
|
||||
|
||||
/**
|
||||
* 先判断在范围的数据,在进行误差体系的判断
|
||||
*
|
||||
* @param startValue 开始值
|
||||
* @param startFlag 是否包含
|
||||
* @param endValue 结束值
|
||||
* @param endFlag 是否包含
|
||||
* @param devData 装置上送值
|
||||
* @return
|
||||
*/
|
||||
public Boolean rangeComparison(Double startValue, Integer startFlag, Double endValue, Integer endFlag, Double devData) {
|
||||
Boolean minBool = null;
|
||||
Boolean maxBool = null;
|
||||
if (ObjectUtil.isNotNull(startValue)) {
|
||||
if (1 == startFlag) {
|
||||
minBool = NumberUtil.isGreaterOrEqual(BigDecimal.valueOf(devData), BigDecimal.valueOf(startValue));
|
||||
} else {
|
||||
minBool = NumberUtil.isGreater(BigDecimal.valueOf(devData), BigDecimal.valueOf(startValue));
|
||||
}
|
||||
|
||||
}
|
||||
if (ObjectUtil.isNotNull(endValue)) {
|
||||
if (1 == endFlag) {
|
||||
maxBool = NumberUtil.isLessOrEqual(BigDecimal.valueOf(devData), BigDecimal.valueOf(endValue));
|
||||
} else {
|
||||
maxBool = NumberUtil.isLess(BigDecimal.valueOf(devData), BigDecimal.valueOf(endValue));
|
||||
}
|
||||
}
|
||||
if (ObjectUtil.isNotNull(minBool) && ObjectUtil.isNotNull(maxBool)) {
|
||||
return minBool && maxBool;
|
||||
} else {
|
||||
if (ObjectUtil.isNotNull(minBool)) {
|
||||
return minBool;
|
||||
}
|
||||
if (ObjectUtil.isNotNull(maxBool)) {
|
||||
return maxBool;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 技术数据误差值(装置返回的值 - 源通道下发的值)
|
||||
*
|
||||
* @param devData
|
||||
* @param channelData
|
||||
* @param errorValueType
|
||||
* @return
|
||||
*/
|
||||
public BigDecimal devSubtractChannelData(Double devData, Double channelData, Integer errorValueType) {
|
||||
switch (errorValueType) {
|
||||
case 2:
|
||||
return BigDecimal.valueOf(devData - channelData)
|
||||
.divide(BigDecimal.valueOf(devData), 7, RoundingMode.HALF_UP);
|
||||
case 3:
|
||||
return BigDecimal.valueOf(devData - channelData)
|
||||
.divide(BigDecimal.valueOf(channelData), 7, RoundingMode.HALF_UP);
|
||||
}
|
||||
return BigDecimal.valueOf(devData - channelData);
|
||||
}
|
||||
|
||||
public BigDecimal divide(Double devData, Double channelData) {
|
||||
return BigDecimal.valueOf(devData)
|
||||
.divide(BigDecimal.valueOf(channelData), 7, RoundingMode.HALF_UP);
|
||||
|
||||
}
|
||||
|
||||
public Double multiply(Double devData, Double channelData, Integer type) {
|
||||
if (ObjectUtil.isNotNull(type)) {
|
||||
if (0 == type) {
|
||||
return BigDecimal.valueOf(devData).multiply(BigDecimal.valueOf(channelData))
|
||||
.setScale(7, RoundingMode.HALF_UP).doubleValue();
|
||||
} else {
|
||||
if (ObjectUtil.isNotNull(devData)) {
|
||||
return BigDecimal.valueOf(devData).doubleValue();
|
||||
} else {
|
||||
return devData;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return devData;
|
||||
|
||||
}
|
||||
|
||||
public Double multiply(String devData, String channelData) {
|
||||
return BigDecimal.valueOf(Double.valueOf(devData)).multiply(BigDecimal.valueOf(Double.valueOf(channelData)))
|
||||
.setScale(7, RoundingMode.HALF_UP).doubleValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理谐波原始数据
|
||||
*
|
||||
* @param type A,b,c
|
||||
* @param map 初始化集合
|
||||
* @param harmNum 多少次谐波集合
|
||||
* @param harm 基波信息
|
||||
* @param fund 2-50次谐波信息
|
||||
*/
|
||||
public void harmPut(String type, Map<String, Map<Double, List<Double>>> map, List<Double> harmNum, DevData.SqlDataHarmDTO harm, String fund, Integer num) {
|
||||
if (map.containsKey(type)) {
|
||||
Map<Double, List<Double>> integerListMap = map.get(type);
|
||||
for (Double i : harmNum) {
|
||||
if (integerListMap.containsKey(i)) {
|
||||
if (type.equals("A")) {
|
||||
integerListMap.get(num != 1 ? i : i + 0.5).add(multiply(harm.getList().getA().get((int) (i - num)), fund));
|
||||
}
|
||||
if (type.equals("B")) {
|
||||
integerListMap.get(num != 1 ? i : i + 0.5).add(multiply(harm.getList().getB().get((int) (i - num)), fund));
|
||||
}
|
||||
if (type.equals("C")) {
|
||||
integerListMap.get(num != 1 ? i : i + 0.5).add(multiply(harm.getList().getC().get((int) (i - num)), fund));
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Map<Double, List<Double>> integerListMap = new LinkedHashMap<>(5);
|
||||
for (Double i : harmNum) {
|
||||
List<Double> integerList = new ArrayList<>();
|
||||
if (type.equals("A")) {
|
||||
integerList.add(multiply(harm.getList().getA().get((int) (i - num)), fund));
|
||||
}
|
||||
if (type.equals("B")) {
|
||||
integerList.add(multiply(harm.getList().getB().get((int) (i - num)), fund));
|
||||
}
|
||||
if (type.equals("C")) {
|
||||
integerList.add(multiply(harm.getList().getC().get((int) (i - num)), fund));
|
||||
}
|
||||
integerListMap.put(num != 1 ? i : i + 0.5, integerList);
|
||||
}
|
||||
map.put(type, integerListMap);
|
||||
}
|
||||
}
|
||||
|
||||
public static List<Double> getAvgDoubles(List<Double> t) {
|
||||
if (CollUtil.isNotEmpty(t)) {
|
||||
t = Arrays.asList(t.stream().mapToDouble(Double::doubleValue).average().orElse(0.0));
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
public static List<Double> getDoubles(List<Double> t, Integer start, Integer end) {
|
||||
if (CollUtil.isNotEmpty(t)) {
|
||||
t = t.subList(start, end);
|
||||
}
|
||||
return t;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,176 @@
|
||||
package com.njcn.gather.detection.service.impl;
|
||||
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.gather.detection.handler.SocketDevResponseService;
|
||||
import com.njcn.gather.detection.handler.SocketSourceResponseService;
|
||||
import com.njcn.gather.detection.pojo.enums.DetectionResponseEnum;
|
||||
import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum;
|
||||
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
|
||||
import com.njcn.gather.detection.pojo.vo.SocketDataMsg;
|
||||
import com.njcn.gather.detection.pojo.vo.SocketMsg;
|
||||
import com.njcn.gather.detection.service.PreDetectionService;
|
||||
|
||||
import com.njcn.gather.detection.util.socket.MsgUtil;
|
||||
import com.njcn.gather.detection.util.socket.SocketManager;
|
||||
import com.njcn.gather.detection.util.socket.cilent.NettyClient;
|
||||
import com.njcn.gather.detection.util.socket.cilent.NettySourceClientHandler;
|
||||
import com.njcn.gather.device.device.service.IPqDevService;
|
||||
import com.njcn.gather.device.script.service.IPqScriptDtlsService;
|
||||
import com.njcn.gather.device.source.pojo.po.PqSource;
|
||||
import com.njcn.gather.device.source.pojo.po.SourceInitialize;
|
||||
import com.njcn.gather.device.source.service.IPqSourceService;
|
||||
import com.njcn.gather.plan.pojo.po.AdPlan;
|
||||
import com.njcn.gather.plan.pojo.po.AdPlanSource;
|
||||
import com.njcn.gather.plan.service.IAdPlanService;
|
||||
import com.njcn.gather.plan.service.IAdPlanSourceService;
|
||||
import com.njcn.gather.system.dictionary.pojo.enums.DictDataEnum;
|
||||
import com.njcn.gather.system.dictionary.service.IDictDataService;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelFutureListener;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class PreDetectionServiceImpl implements PreDetectionService {
|
||||
|
||||
private final String source = "_Source";
|
||||
private final String dev = "_Dev";
|
||||
|
||||
private final IPqDevService iPqDevService;
|
||||
private final IDictDataService dictDataService;
|
||||
private final IAdPlanService iAdPlanService;
|
||||
private final IAdPlanSourceService adPlanSourceService;
|
||||
private final IPqSourceService pqSourceService;
|
||||
private final IPqScriptDtlsService pqScriptDtlsService;
|
||||
|
||||
private final SocketDevResponseService socketDevResponseService;
|
||||
private final SocketSourceResponseService socketSourceResponseService;
|
||||
|
||||
|
||||
@Value("${socket.source.ip:192.168.1.136}")
|
||||
private String ip;
|
||||
|
||||
@Value("${socket.source.port:10086}")
|
||||
private Integer port;
|
||||
|
||||
private final SocketSourceResponseService sourceResponseService;
|
||||
|
||||
|
||||
@Override
|
||||
public void sourceCommunicationCheck(PreDetectionParam param) {
|
||||
|
||||
|
||||
System.out.println("进来了啊啊啊啊啊啊啊啊啊啊啊啊啊----------------------------------------------------------------");
|
||||
Channel channel = SocketManager.getChannelByUserId(param.getUserPageId() + source);
|
||||
System.out.println("存活的源=========================="+channel);
|
||||
|
||||
if (Objects.nonNull(channel) && channel.isActive()) {
|
||||
System.out.println("进入关闭源。。//////");
|
||||
SocketDataMsg socketDataMsg = new SocketDataMsg();
|
||||
socketDataMsg.setOperateCode(SourceOperateCodeEnum.CLOSE_GATHER.getValue());
|
||||
socketDataMsg.setRequestId(SourceOperateCodeEnum.QUITE_SOURCE.getValue());
|
||||
SocketManager.sendMsg(param.getUserPageId()+source,JSON.toJSONString(socketDataMsg));
|
||||
|
||||
try {
|
||||
Thread.sleep(2000);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
SocketManager.removeUser(param.getUserPageId() + source);
|
||||
SocketManager.removeUser(param.getUserPageId() + dev);
|
||||
|
||||
try {
|
||||
Thread.sleep(2000);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
先组装源通讯协议
|
||||
查询计划什么模式的(除了对比式,其他都是一个计划对应一个源)
|
||||
*/
|
||||
AdPlan plan = iAdPlanService.getById(param.getPlanId());
|
||||
PqSource pqSource = pqSourceService.getById(plan.getDatasourceId());
|
||||
if (ObjectUtil.isNotNull(plan)) {
|
||||
plan.setErrorSysId(plan.getId());
|
||||
String code = dictDataService.getDictDataById(plan.getPattern()).getCode();
|
||||
DictDataEnum dictDataEnumByCode = DictDataEnum.getDictDataEnumByCode(code);
|
||||
switch (dictDataEnumByCode) {
|
||||
case DIGITAL:
|
||||
case SIMULATE:
|
||||
sendYtxSocket(param);
|
||||
break;
|
||||
case CONTRAST:
|
||||
break;
|
||||
default:
|
||||
throw new BusinessException(DetectionResponseEnum.PLAN_PATTERN_NOT);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void sendYtxSocket(PreDetectionParam param) {
|
||||
AdPlanSource planSource = adPlanSourceService.getOne(new LambdaQueryWrapper<AdPlanSource>()
|
||||
.eq(AdPlanSource::getPlanId, param.getPlanId())
|
||||
);
|
||||
if (ObjectUtil.isNotNull(planSource)) {
|
||||
SourceInitialize sourceParam = pqSourceService.getSourceInitializeParam(planSource.getSourceId());
|
||||
if (ObjectUtil.isNotNull(sourceParam)) {
|
||||
//开始组装socket报文请求头
|
||||
socketDevResponseService.initList(param);
|
||||
socketSourceResponseService.initList(param);
|
||||
SocketMsg msg = new SocketMsg();
|
||||
msg.setRequestId(SourceOperateCodeEnum.YJC_YTXJY.getValue());
|
||||
msg.setOperateCode(SourceOperateCodeEnum.INIT_GATHER.getValue());
|
||||
msg.setData(JSON.toJSONString(sourceParam));
|
||||
param.setSourceId(sourceParam.getSourceId());
|
||||
NettyClient.socketClient(ip, port, param.getUserPageId(), MsgUtil.toJsonWithNewLinePlain(msg), new NettySourceClientHandler(param, sourceResponseService));
|
||||
} else {
|
||||
throw new BusinessException(DetectionResponseEnum.SOURCE_INFO_NOT);
|
||||
}
|
||||
} else {
|
||||
throw new BusinessException(DetectionResponseEnum.PLAN_AND_SOURCE_NOT);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean startTest(PreDetectionParam param) {
|
||||
|
||||
socketDevResponseService.initList(param);
|
||||
NettyClient.socketClient(ip, port, param.getUserPageId(), "start\n", new NettySourceClientHandler(param, sourceResponseService));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean closePreTest(PreDetectionParam param) {
|
||||
|
||||
SocketMsg socketMsg = new SocketMsg();
|
||||
socketMsg.setRequestId(SourceOperateCodeEnum.QUITE.getValue());
|
||||
socketMsg.setOperateCode(SourceOperateCodeEnum.QUIT_INIT_03.getValue());
|
||||
SocketManager.sendMsg(param.getUserPageId() + dev, JSON.toJSONString(socketMsg));
|
||||
|
||||
|
||||
socketMsg.setRequestId(SourceOperateCodeEnum.QUITE_SOURCE.getValue());
|
||||
socketMsg.setOperateCode(SourceOperateCodeEnum.CLOSE_GATHER.getValue());
|
||||
SocketManager.sendMsg(param.getUserPageId() + source, JSON.toJSONString(socketMsg));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.njcn.gather.detection.util.socket;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum;
|
||||
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
|
||||
import com.njcn.gather.detection.pojo.vo.SocketMsg;
|
||||
|
||||
/**
|
||||
* @Author: cdf
|
||||
* @CreateTime: 2025-01-02
|
||||
* @Description: 工具类
|
||||
*/
|
||||
public class CnSocketUtil {
|
||||
|
||||
private final static String handlerStr = "_Dev";
|
||||
private final static String handlerSourceStr = "_Source";
|
||||
|
||||
/**
|
||||
* 退出检测
|
||||
*/
|
||||
public static void quitSend(PreDetectionParam param) {
|
||||
SocketMsg<String> socketMsg = new SocketMsg<>();
|
||||
socketMsg.setRequestId(SourceOperateCodeEnum.QUITE.getValue());
|
||||
socketMsg.setOperateCode(SourceOperateCodeEnum.QUIT_INIT_03.getValue());
|
||||
SocketManager.sendMsg(param.getUserPageId() + handlerStr, JSON.toJSONString(socketMsg));
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭源连接
|
||||
*/
|
||||
public static void quitSendSource(PreDetectionParam param) {
|
||||
SocketMsg<String> socketMsg = new SocketMsg<>();
|
||||
socketMsg.setRequestId(SourceOperateCodeEnum.QUITE_SOURCE.getValue());
|
||||
socketMsg.setOperateCode(SourceOperateCodeEnum.CLOSE_GATHER.getValue());
|
||||
SocketManager.sendMsg(param.getUserPageId() + handlerSourceStr, JSON.toJSONString(socketMsg));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.njcn.gather.detection.util.socket;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||
import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum;
|
||||
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
|
||||
import com.njcn.gather.detection.pojo.vo.SocketDataMsg;
|
||||
import com.njcn.gather.detection.pojo.vo.SocketMsg;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author wr
|
||||
* @description
|
||||
* @date 2024/12/11 19:27
|
||||
*/
|
||||
|
||||
public class MsgUtil {
|
||||
|
||||
|
||||
|
||||
public static SocketDataMsg socketDataMsg(String textMsg){
|
||||
return JSON.parseObject(textMsg,SocketDataMsg.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将对象转换为 JSON 字符串,并在末尾添加换行符
|
||||
*
|
||||
* @param obj 需要转换的对象
|
||||
* @return 包含换行符的 JSON 字符串
|
||||
*/
|
||||
public static String toJsonWithNewLine(Object obj) {
|
||||
return JSON.toJSONString(obj, SerializerFeature.PrettyFormat) + "\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* 将对象转换为 JSON 字符串,并在末尾添加换行符(不带格式化)
|
||||
*
|
||||
* @param obj 需要转换的对象
|
||||
* @return 包含换行符的 JSON 字符串
|
||||
*/
|
||||
public static String toJsonWithNewLinePlain(Object obj) {
|
||||
return JSON.toJSONString(obj) + "\n";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param socketDataMsg
|
||||
* @param devMap
|
||||
* @param type 0.装置 1.监测点
|
||||
* @return
|
||||
*/
|
||||
public static String msgToWebData(SocketDataMsg socketDataMsg, Map<String,String> devMap,Integer type){
|
||||
String data = socketDataMsg.getData();
|
||||
if (StrUtil.isNotBlank(data)) {
|
||||
String[] parts = data.split("_");
|
||||
if (parts.length > 0) {
|
||||
String key = parts[0];
|
||||
String newValue = devMap.get(key);
|
||||
if (newValue != null) {
|
||||
if(type == 0) {
|
||||
socketDataMsg.setData(newValue);
|
||||
}else {
|
||||
socketDataMsg.setData(newValue+"_"+parts[1]+"路");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return JSON.toJSONString(socketDataMsg);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
package com.njcn.gather.detection.util.socket;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.njcn.gather.device.script.pojo.po.SourceIssue;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.nio.NioEventLoopGroup;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
/**
|
||||
* @Description: webSocket存储的通道
|
||||
* @Author: wr
|
||||
* @Date: 2024/12/11 13:04
|
||||
*/
|
||||
public class SocketManager {
|
||||
|
||||
private static final Map<String, Channel> socketSessions = new ConcurrentHashMap<>();
|
||||
private static final Map<String, NioEventLoopGroup> socketGroup = new ConcurrentHashMap<>();
|
||||
|
||||
public static void addUser(String userId, Channel channel) {
|
||||
socketSessions.put(userId, channel);
|
||||
}
|
||||
|
||||
public static void addGroup(String userId, NioEventLoopGroup group) {
|
||||
socketGroup.put(userId, group);
|
||||
}
|
||||
|
||||
public static void removeUser(String userId) {
|
||||
Channel channel = socketSessions.get(userId);
|
||||
if(ObjectUtil.isNotNull(channel)){
|
||||
try {
|
||||
channel.close().sync();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
NioEventLoopGroup eventExecutors = socketGroup.get(userId);
|
||||
if(ObjectUtil.isNotNull(channel)){
|
||||
eventExecutors.shutdownGracefully();
|
||||
System.out.println(userId+"__"+channel.id()+"关闭了客户端");
|
||||
}
|
||||
}
|
||||
socketSessions.remove(userId);
|
||||
}
|
||||
|
||||
public static Channel getChannelByUserId(String userId) {
|
||||
return socketSessions.get(userId);
|
||||
}
|
||||
|
||||
public static NioEventLoopGroup getGroupByUserId(String userId) {
|
||||
return socketGroup.get(userId);
|
||||
}
|
||||
|
||||
public static void sendMsg(String userId,String msg) {
|
||||
Channel channel = socketSessions.get(userId);
|
||||
if(ObjectUtil.isNotNull(channel)){
|
||||
channel.writeAndFlush(msg+'\n');
|
||||
System.out.println(userId+"__"+channel.id()+"往"+channel.remoteAddress()+"发送数据:"+msg);
|
||||
}else{
|
||||
System.out.println(userId+"__发送数据:失败通道不存在"+msg);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* key:大类型code value:对应小项数量(成功一个后减一)
|
||||
*/
|
||||
private static Map<String, Long> targetMap = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* 存储所有检测小项
|
||||
*/
|
||||
private static List<SourceIssue> sourceIssueList = new CopyOnWriteArrayList<>();
|
||||
|
||||
|
||||
|
||||
public static void addSourceList(List<SourceIssue> sList) {
|
||||
sourceIssueList = sList;
|
||||
System.out.println(sList);
|
||||
}
|
||||
|
||||
public static List<SourceIssue> getSourceList() {
|
||||
return sourceIssueList;
|
||||
}
|
||||
|
||||
|
||||
public static void delSource(Integer index) {
|
||||
sourceIssueList.removeIf(s -> index.equals(s.getIndex()));
|
||||
}
|
||||
|
||||
public static void delSourceTarget(String sourceTag) {
|
||||
targetMap.remove(sourceTag);
|
||||
}
|
||||
|
||||
|
||||
public static void initMap(Map<String, Long> map) {
|
||||
targetMap = map;
|
||||
}
|
||||
|
||||
public static void addTargetMap(String scriptType,Long count) {
|
||||
targetMap.put(scriptType,count);
|
||||
}
|
||||
|
||||
public static Long getSourceTarget(String scriptType) {
|
||||
return targetMap.get(scriptType);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.njcn.gather.detection.util.socket;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.njcn.gather.detection.pojo.vo.WebSocketVO;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* @Description: webSocket存储的通道
|
||||
* @Author: wr
|
||||
* @Date: 2024/12/11 13:04
|
||||
*/
|
||||
@Slf4j
|
||||
public class WebServiceManager {
|
||||
|
||||
//key:页面 value:channel
|
||||
private static final Map<String, Channel> userSessions = new ConcurrentHashMap<>();
|
||||
|
||||
|
||||
|
||||
public static void addUser(String userId, Channel channel) {
|
||||
userSessions.put(userId, channel);
|
||||
}
|
||||
|
||||
public static void removeUser(String userId) {
|
||||
String id = userSessions.get(userId).id().toString();
|
||||
userSessions.remove(userId);
|
||||
}
|
||||
|
||||
public static void removeChannel(String channelId) {
|
||||
// 遍历并删除
|
||||
Iterator<Map.Entry<String, Channel>> iterator = userSessions.entrySet().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Map.Entry<String, Channel> entry = iterator.next();
|
||||
if (entry.getValue().id().equals(channelId)) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Channel getChannelByUserId(String userId) {
|
||||
return userSessions.get(userId);
|
||||
}
|
||||
|
||||
public static void sendMsg(String userId,String msg) {
|
||||
Channel channel = userSessions.get(userId);
|
||||
if(Objects.nonNull(channel) && channel.isActive()){
|
||||
TextWebSocketFrame wd = new TextWebSocketFrame(msg);
|
||||
channel.writeAndFlush(wd);
|
||||
}else {
|
||||
log.error("{}-websocket推送消息失败;当前用户-{}-客户端已经断开连接", LocalDateTime.now(),userId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void sendMessage(String userId, WebSocketVO webSocketVO) {
|
||||
Channel channel = userSessions.get(userId);
|
||||
if(Objects.nonNull(channel) && channel.isActive()){
|
||||
TextWebSocketFrame wd = new TextWebSocketFrame(JSON.toJSONString(webSocketVO));
|
||||
channel.writeAndFlush(wd);
|
||||
}else {
|
||||
log.error("{}-websocket推送消息失败;当前用户-{}-客户端已经断开连接", LocalDateTime.now(),userId);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,140 @@
|
||||
package com.njcn.gather.detection.util.socket.cilent;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.njcn.gather.detection.pojo.enums.SourceResponseCodeEnum;
|
||||
import com.njcn.gather.detection.pojo.vo.SocketDataMsg;
|
||||
import com.njcn.gather.detection.pojo.vo.WebSocketVO;
|
||||
import com.njcn.gather.detection.util.socket.SocketManager;
|
||||
import com.njcn.gather.detection.util.socket.WebServiceManager;
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
import io.netty.channel.*;
|
||||
import io.netty.channel.nio.NioEventLoopGroup;
|
||||
import io.netty.channel.socket.nio.NioSocketChannel;
|
||||
import io.netty.handler.codec.LineBasedFrameDecoder;
|
||||
import io.netty.handler.codec.string.StringDecoder;
|
||||
import io.netty.handler.codec.string.StringEncoder;
|
||||
import io.netty.handler.timeout.IdleStateHandler;
|
||||
import io.netty.util.CharsetUtil;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @Description: 心跳检测服务端 对应的服务端在netty-server 包下的NettyClient
|
||||
* @Author: wr
|
||||
* @Date: 2024/12/10 14:16
|
||||
*/
|
||||
|
||||
@Getter
|
||||
public class NettyClient {
|
||||
|
||||
public static void socketClient(String ip, Integer port, String userPageId,String msg, SimpleChannelInboundHandler<String> handler) {
|
||||
NioEventLoopGroup group = new NioEventLoopGroup();
|
||||
Bootstrap bootstrap = new Bootstrap();
|
||||
try {
|
||||
bootstrap.group(group)
|
||||
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 5000)
|
||||
.channel(NioSocketChannel.class)
|
||||
.handler(new ChannelInitializer<NioSocketChannel>() {
|
||||
@Override
|
||||
protected void initChannel(NioSocketChannel ch) {
|
||||
if (handler instanceof NettySourceClientHandler) {
|
||||
ch.pipeline()
|
||||
//空闲状态的handler
|
||||
// 添加LineBasedFrameDecoder来按行分割数据
|
||||
// .addLast(new LineBasedFrameDecoder(10240))
|
||||
.addLast(new IdleStateHandler(20, 0, 0, TimeUnit.SECONDS))
|
||||
.addLast(new StringDecoder(CharsetUtil.UTF_8))
|
||||
.addLast(new StringEncoder(CharsetUtil.UTF_8))
|
||||
.addLast(handler);
|
||||
} else {
|
||||
ch.pipeline()
|
||||
//空闲状态的handler
|
||||
// 添加LineBasedFrameDecoder来按行分割数据
|
||||
.addLast(new LineBasedFrameDecoder(10240))
|
||||
.addLast(new IdleStateHandler(10, 0, 0, TimeUnit.SECONDS))
|
||||
.addLast(new StringDecoder(CharsetUtil.UTF_8))
|
||||
.addLast(new StringEncoder(CharsetUtil.UTF_8))
|
||||
.addLast(handler);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
ChannelFuture channelFuture = bootstrap.connect(ip, port).sync();
|
||||
channelFuture.addListener((ChannelFutureListener) ch -> {
|
||||
if (!ch.isSuccess()) {
|
||||
System.out.println("链接服务端失败...");
|
||||
} else {
|
||||
System.out.println("链接服务端成功...");
|
||||
System.out.println("客户端向服务端发送消息:"+msg);
|
||||
channelFuture.channel().writeAndFlush(msg);
|
||||
}
|
||||
});
|
||||
NioEventLoopGroup groupByUserId = SocketManager.getGroupByUserId(userPageId + "_Dev");
|
||||
if(ObjectUtil.isNotNull(groupByUserId)){
|
||||
groupByUserId.shutdownGracefully();
|
||||
}else{
|
||||
if (handler instanceof NettySourceClientHandler) {
|
||||
SocketManager.addGroup(userPageId+"_Source",group);
|
||||
}else{
|
||||
SocketManager.addGroup(userPageId+"_Dev",group);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println("连接socket服务端发送异常............" + e.getMessage());
|
||||
group.shutdownGracefully();
|
||||
//TODO 通知页面
|
||||
SocketDataMsg socketDataMsg = new SocketDataMsg();
|
||||
socketDataMsg.setType("aaa");
|
||||
socketDataMsg.setCode(SourceResponseCodeEnum.SOCKET_ERROR.getCode());
|
||||
socketDataMsg.setData(SourceResponseCodeEnum.SOCKET_ERROR.getMessage());
|
||||
socketDataMsg.setRequestId("connect");
|
||||
if (handler instanceof NettySourceClientHandler) {
|
||||
socketDataMsg.setOperateCode("Source");
|
||||
}else{
|
||||
socketDataMsg.setOperateCode("Dev");
|
||||
}
|
||||
WebServiceManager.sendMsg(userPageId, JSON.toJSONString(socketDataMsg));
|
||||
} finally {
|
||||
// System.out.println("进入clientSocket最后步骤---------------------");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 重连方法
|
||||
*/
|
||||
public static void connect(Bootstrap bootstrap, String msg) {
|
||||
try {
|
||||
bootstrap.connect("127.0.0.1", 8787).sync()
|
||||
.addListener((ChannelFutureListener) ch -> {
|
||||
if (!ch.isSuccess()) {
|
||||
ch.channel().close();
|
||||
final EventLoop loop = ch.channel().eventLoop();
|
||||
loop.schedule(() -> {
|
||||
System.err.println("服务端链接不上,开始重连操作...");
|
||||
//重连
|
||||
connect(bootstrap, msg);
|
||||
}, 3L, TimeUnit.SECONDS);
|
||||
} else {
|
||||
if (StrUtil.isNotBlank(msg)) {
|
||||
ch.channel().writeAndFlush(msg);
|
||||
}
|
||||
System.out.println("服务端链接成功...");
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
System.out.println(e.getMessage());
|
||||
try {
|
||||
Thread.sleep(3000L);
|
||||
} catch (InterruptedException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
//再重连
|
||||
connect(bootstrap, msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
package com.njcn.gather.detection.util.socket.cilent;
|
||||
|
||||
import com.njcn.gather.detection.handler.SocketDevResponseService;
|
||||
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
|
||||
import com.njcn.gather.detection.util.socket.CnSocketUtil;
|
||||
import com.njcn.gather.detection.util.socket.SocketManager;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
import io.netty.handler.timeout.TimeoutException;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.ConnectException;
|
||||
import java.net.ProtocolException;
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
/**
|
||||
* @Description: 源客户端业务处理(示例)
|
||||
* @Author: wr
|
||||
* @Date: 2024/12/10 14:16
|
||||
*/
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class NettyDevClientHandler extends SimpleChannelInboundHandler<String> {
|
||||
|
||||
private final String dev = "_Dev";
|
||||
|
||||
private final PreDetectionParam param;
|
||||
|
||||
private final SocketDevResponseService socketResponseService;
|
||||
|
||||
|
||||
/**
|
||||
* 当通道进行连接时推送消息
|
||||
* @param ctx
|
||||
*/
|
||||
@Override
|
||||
public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
||||
System.out.println("客户端通道已建立" + ctx.channel().id());
|
||||
Channel channel = SocketManager.getChannelByUserId(param.getUserPageId()+dev);
|
||||
if(Objects.nonNull(channel)){
|
||||
channel.close().sync();
|
||||
}
|
||||
SocketManager.addUser(param.getUserPageId()+dev,ctx.channel());
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理服务端消息消息信息
|
||||
*/
|
||||
@Override
|
||||
protected void channelRead0(ChannelHandlerContext ctx, String msg) throws InterruptedException {
|
||||
System.out.println("devhandler接收server端数据>>>>>>"+msg);
|
||||
try {
|
||||
socketResponseService.deal(param,msg);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
CnSocketUtil.quitSend(param);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 当通道断线时,支持重连
|
||||
* @param ctx
|
||||
*/
|
||||
@Override
|
||||
public void channelInactive(ChannelHandlerContext ctx) {
|
||||
System.out.println("客户端断线");
|
||||
//SocketManager.addUser(webUser,ctx.channel());
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户事件的回调方法(自定义事件用于心跳机制)
|
||||
*
|
||||
* @param ctx
|
||||
* @param evt
|
||||
*/
|
||||
@Override
|
||||
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
|
||||
System.out.println("进入超时。。。。。。");
|
||||
//当连接超过10S和发送消息后10S无响应时候,关闭channel
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlerAdded(ChannelHandlerContext ctx) {
|
||||
System.out.println("有通道准备接入" + ctx.channel());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
|
||||
// 处理异常,例如记录日志、关闭连接等
|
||||
cause.printStackTrace();
|
||||
// 根据异常类型进行不同的处理
|
||||
if (cause instanceof ConnectException) {
|
||||
// 处理连接异常,例如重试连接或记录特定的连接错误信息
|
||||
System.out.println("连接socket服务端异常");
|
||||
|
||||
} else if (cause instanceof IOException) {
|
||||
// 处理I/O异常,例如读写错误
|
||||
System.out.println("IOException caught: There was an I/O error.");
|
||||
// 例如,可以记录更详细的I/O错误信息
|
||||
} else if (cause instanceof TimeoutException) {
|
||||
// 处理超时异常
|
||||
System.out.println("TimeoutException caught: Operation timed out.");
|
||||
// 可以根据业务逻辑决定是否重试或记录超时信息
|
||||
} else if (cause instanceof ProtocolException) {
|
||||
// 处理协议异常,例如消息格式不正确
|
||||
System.out.println("ProtocolException caught: Invalid protocol message.");
|
||||
// 可以记录协议错误信息或向客户端发送错误响应
|
||||
} else {
|
||||
// 处理其他类型的异常
|
||||
System.out.println("Unknown exception caught: " + cause.getMessage());
|
||||
// 可以记录未知异常信息
|
||||
}
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
package com.njcn.gather.detection.util.socket.cilent;
|
||||
|
||||
import com.njcn.gather.detection.handler.SocketSourceResponseService;
|
||||
import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum;
|
||||
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
|
||||
import com.njcn.gather.detection.pojo.vo.SocketDataMsg;
|
||||
import com.njcn.gather.detection.pojo.vo.SocketMsg;
|
||||
import com.njcn.gather.detection.util.socket.CnSocketUtil;
|
||||
import com.njcn.gather.detection.util.socket.MsgUtil;
|
||||
import com.njcn.gather.detection.util.socket.SocketManager;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
import io.netty.handler.timeout.IdleState;
|
||||
import io.netty.handler.timeout.IdleStateEvent;
|
||||
import io.netty.handler.timeout.TimeoutException;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.ConnectException;
|
||||
import java.net.ProtocolException;
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
/**
|
||||
* @Description: 源客户端业务处理(示例)
|
||||
* @Author: wr
|
||||
* @Date: 2024/12/10 14:16
|
||||
*/
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class NettySourceClientHandler extends SimpleChannelInboundHandler<String> {
|
||||
|
||||
private final PreDetectionParam webUser;
|
||||
private final SocketSourceResponseService sourceResponseService;
|
||||
|
||||
/**
|
||||
* 当通道进行连接时推送消息
|
||||
*
|
||||
* @param ctx
|
||||
*/
|
||||
@Override
|
||||
public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
||||
System.out.println("客户端通道已建立" + ctx.channel().id());
|
||||
|
||||
SocketManager.addUser(webUser.getUserPageId() + "_Source", ctx.channel());
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理服务端消息信息
|
||||
*/
|
||||
@Override
|
||||
protected void channelRead0(ChannelHandlerContext ctx, String msg) throws InterruptedException {
|
||||
System.out.println("接收server端数据>>>>>>" + msg);
|
||||
try {
|
||||
sourceResponseService.deal(webUser, msg);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
CnSocketUtil.quitSend(webUser);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 当通道断线时,支持重连
|
||||
*
|
||||
* @param ctx
|
||||
*/
|
||||
@Override
|
||||
public void channelInactive(ChannelHandlerContext ctx) {
|
||||
// System.out.println("断线了......" + ctx.channel());
|
||||
// ctx.channel().eventLoop().schedule(() -> {
|
||||
// System.out.println("断线重连......");
|
||||
// //重连
|
||||
// NettyClient.connect();
|
||||
// }, 3L, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户事件的回调方法(自定义事件用于心跳机制)
|
||||
*
|
||||
* @param ctx
|
||||
* @param evt
|
||||
*/
|
||||
@Override
|
||||
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
|
||||
//如果是空闲状态事件
|
||||
if (evt instanceof IdleStateEvent) {
|
||||
if (((IdleStateEvent) evt).state() == IdleState.READER_IDLE) {
|
||||
//发送ping 保持心跳链接
|
||||
SocketMsg msg = new SocketMsg();
|
||||
msg.setRequestId("yxt");
|
||||
msg.setOperateCode(SourceOperateCodeEnum.HEARTBEAT.getValue());
|
||||
msg.setData("");
|
||||
ctx.writeAndFlush(MsgUtil.toJsonWithNewLinePlain(msg));
|
||||
}
|
||||
} else {
|
||||
//防止堆栈溢出
|
||||
//userEventTriggered(ctx, evt);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlerAdded(ChannelHandlerContext ctx) {
|
||||
System.out.println("有通道准备接入" + ctx.channel().id());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
|
||||
// 处理异常,例如记录日志、关闭连接等
|
||||
cause.printStackTrace();
|
||||
// 根据异常类型进行不同的处理
|
||||
if (cause instanceof ConnectException) {
|
||||
// 处理连接异常,例如重试连接或记录特定的连接错误信息
|
||||
System.out.println("连接socket服务端异常");
|
||||
|
||||
} else if (cause instanceof IOException) {
|
||||
// 处理I/O异常,例如读写错误
|
||||
System.out.println("IOException caught: There was an I/O error.");
|
||||
// 例如,可以记录更详细的I/O错误信息
|
||||
} else if (cause instanceof TimeoutException) {
|
||||
// 处理超时异常
|
||||
System.out.println("TimeoutException caught: Operation timed out.");
|
||||
// 可以根据业务逻辑决定是否重试或记录超时信息
|
||||
} else if (cause instanceof ProtocolException) {
|
||||
// 处理协议异常,例如消息格式不正确
|
||||
System.out.println("ProtocolException caught: Invalid protocol message.");
|
||||
// 可以记录协议错误信息或向客户端发送错误响应
|
||||
} else {
|
||||
// 处理其他类型的异常
|
||||
System.out.println("Unknown exception caught: " + cause.getMessage());
|
||||
// 可以记录未知异常信息
|
||||
}
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.njcn.gather.detection.util.socket.service;
|
||||
|
||||
import io.netty.bootstrap.ServerBootstrap;
|
||||
import io.netty.channel.ChannelFuture;
|
||||
import io.netty.channel.ChannelInitializer;
|
||||
import io.netty.channel.nio.NioEventLoopGroup;
|
||||
import io.netty.channel.socket.ServerSocketChannel;
|
||||
import io.netty.channel.socket.nio.NioServerSocketChannel;
|
||||
|
||||
|
||||
/**
|
||||
* @Description: NettyServer 心跳检测服务端
|
||||
*
|
||||
* Netty心跳检测与断线重连
|
||||
* 需求:
|
||||
* 1、客户端利用空闲状态给服务端发送心跳ping命令,保持长连接不被关闭;
|
||||
* 2、服务端如果超过指定的时间没有收到客户端心跳,则关闭连接;
|
||||
* 3、服务端关闭连接触发客户端的channelInactive方法,在此方法中进行重连;
|
||||
* @Author: wr
|
||||
* @Date: 2024/12/10 14:18
|
||||
*/
|
||||
public class NettyServer {
|
||||
|
||||
public static final int port = 8574;
|
||||
|
||||
public static void main(String[] args) {
|
||||
NettyServer nettyServer = new NettyServer();
|
||||
nettyServer.run();
|
||||
}
|
||||
|
||||
|
||||
private void run() {
|
||||
NioEventLoopGroup boss = new NioEventLoopGroup(1);
|
||||
NioEventLoopGroup work = new NioEventLoopGroup();
|
||||
try {
|
||||
ServerBootstrap bootstrap = new ServerBootstrap().group(boss, work);
|
||||
bootstrap.channel(NioServerSocketChannel.class)
|
||||
//这个处理器可以不写
|
||||
.handler(new ChannelInitializer<ServerSocketChannel>() {
|
||||
@Override
|
||||
protected void initChannel(ServerSocketChannel ch) {
|
||||
System.out.println("服务正在启动中......");
|
||||
}
|
||||
})
|
||||
//业务处理
|
||||
.childHandler(NettyServerChannelInitializer.INSTANCE);
|
||||
|
||||
ChannelFuture future = bootstrap.bind(port).sync();
|
||||
|
||||
future.addListener(f -> {
|
||||
if (future.isSuccess()) {
|
||||
System.out.println("服务启动成功");
|
||||
} else {
|
||||
System.out.println("服务启动失败");
|
||||
}
|
||||
});
|
||||
future.channel().closeFuture().sync();
|
||||
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
boss.shutdownGracefully();
|
||||
work.shutdownGracefully();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.njcn.gather.detection.util.socket.service;
|
||||
|
||||
import io.netty.channel.ChannelHandler;
|
||||
import io.netty.channel.ChannelInitializer;
|
||||
import io.netty.channel.socket.nio.NioSocketChannel;
|
||||
import io.netty.handler.codec.string.StringDecoder;
|
||||
import io.netty.handler.codec.string.StringEncoder;
|
||||
import io.netty.util.CharsetUtil;
|
||||
|
||||
/**
|
||||
* @Description: 服务端初始化配置
|
||||
* @Author: wr
|
||||
* @Date: 2024/12/10 14:18
|
||||
*/
|
||||
public class NettyServerChannelInitializer extends ChannelInitializer<NioSocketChannel> {
|
||||
|
||||
public static final NettyServerChannelInitializer INSTANCE = new NettyServerChannelInitializer();
|
||||
|
||||
@Override
|
||||
protected void initChannel(NioSocketChannel ch) {
|
||||
System.out.println("初始化一次888888888888888888888888");
|
||||
ch.pipeline()
|
||||
//空闲状态的处理器
|
||||
// .addLast(new IdleStateHandler(10, 0, 0, TimeUnit.SECONDS))
|
||||
.addLast(new StringDecoder(CharsetUtil.UTF_8))
|
||||
.addLast(new StringEncoder(CharsetUtil.UTF_8))
|
||||
.addLast(new NettyServerHandler());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
package com.njcn.gather.detection.util.socket.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandler;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
|
||||
/**
|
||||
* @Description: 客户端业务处理
|
||||
* @Author: wr
|
||||
* @Date: 2024/12/10 14:18
|
||||
*/
|
||||
|
||||
public class NettyServerHandler extends SimpleChannelInboundHandler<String> {
|
||||
|
||||
public static final NettyServerHandler INSTANCE = new NettyServerHandler();
|
||||
|
||||
/**
|
||||
* @Description: 当通道进行连接时推送消息
|
||||
* @Author: wr
|
||||
* @Date: 2024/12/10 14:19
|
||||
*/
|
||||
@Override
|
||||
public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
||||
System.out.println("服务端监听到"+ctx.channel().id()+"连接");
|
||||
super.channelActive(ctx);
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理消息信息
|
||||
*/
|
||||
@Override
|
||||
public void channelRead0(ChannelHandlerContext ctx, String msg) {
|
||||
System.out.println(ctx.channel().id()+"NettyServer服务端接收到客户端消息:"+msg);
|
||||
Channel channel = ctx.channel();
|
||||
/*
|
||||
if(msg.endsWith("结束")) {
|
||||
channel.writeAndFlush("socket指令结果:"+msg);
|
||||
for (int i = 0; i < 5; i++) {
|
||||
channel.writeAndFlush("socket指令结果:"+msg);
|
||||
}
|
||||
}else{
|
||||
channel.writeAndFlush("socket指令结果:成功指令");
|
||||
}*/
|
||||
if(!msg.contains("HeartBeat")){
|
||||
if(msg.contains("start")){
|
||||
JSONObject jsonObject1 = new JSONObject();
|
||||
jsonObject1.put("requestId","yjc_ytxjy");
|
||||
jsonObject1.put("operateCode","INIT_GATHER");
|
||||
jsonObject1.put("code","10201");
|
||||
channel.writeAndFlush(jsonObject1.toJSONString()+'\n');
|
||||
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("requestId","yjc_ytxjy");
|
||||
jsonObject.put("operateCode","INIT_GATHER");
|
||||
jsonObject.put("code","10200");
|
||||
channel.writeAndFlush(jsonObject.toJSONString()+'\n');
|
||||
}else if(msg.contains("YJC_xujy")){
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("requestId","YJC_xujy");
|
||||
jsonObject.put("operateCode","OPER_GATHER");
|
||||
jsonObject.put("code","10201");
|
||||
channel.writeAndFlush(jsonObject.toJSONString()+'\n');
|
||||
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
JSONObject jsonObject1 = new JSONObject();
|
||||
jsonObject1.put("requestId","YJC_xujy");
|
||||
jsonObject1.put("operateCode","OPER_GATHER");
|
||||
jsonObject1.put("code","10200");
|
||||
channel.writeAndFlush(jsonObject1.toJSONString()+'\n');
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlerAdded(ChannelHandlerContext ctx) {
|
||||
System.out.println("有新连接加入了++++......" + ctx.channel());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
|
||||
cause.printStackTrace();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
||||
// Client disconnected, close the server-side channel too
|
||||
System.out.println("NettyServer服务端监听到"+ctx.channel().id()+"关闭连接");
|
||||
ctx.close(); // This will trigger the close event on the server side
|
||||
super.channelInactive(ctx);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户事件的回调方法(自定义事件用于心跳机制)
|
||||
*/
|
||||
@Override
|
||||
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
|
||||
//空闲状态的事件
|
||||
// if (evt instanceof IdleStateEvent) {
|
||||
// IdleStateEvent event = (IdleStateEvent) evt;
|
||||
// System.out.println(event.state() + ">>>" + ctx.channel().id());
|
||||
// //已经10秒钟没有读时间了
|
||||
// if (event.state().equals(IdleState.READER_IDLE)){
|
||||
// // 心跳包丢失,10秒没有收到客户端心跳 (断开连接)
|
||||
// ctx.channel().close().sync();
|
||||
// System.out.println("已与 "+ctx.channel().remoteAddress()+" 断开连接");
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
package com.njcn.gather.detection.util.socket.web;
|
||||
|
||||
import com.njcn.gather.detection.util.socket.WebServiceManager;
|
||||
import io.netty.channel.ChannelHandler;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
import io.netty.handler.codec.http.FullHttpRequest;
|
||||
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
||||
/**
|
||||
* @Description: 泛型 代表的是处理数据的单位
|
||||
* TextWebSocketFrame : 文本信息帧
|
||||
* @Author: wr
|
||||
* @Date: 2024/12/10 13:56
|
||||
*/
|
||||
|
||||
@Component
|
||||
@ChannelHandler.Sharable
|
||||
@Slf4j
|
||||
public class WebSocketHandler extends SimpleChannelInboundHandler<TextWebSocketFrame> {
|
||||
|
||||
private final static String QUESTION_MARK = "?";
|
||||
private final static String EQUAL_TO = "=";
|
||||
|
||||
@Override
|
||||
public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
||||
System.out.println("服务端通道已建立" + ctx.channel().remoteAddress());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
|
||||
//首次连接是FullHttpRequest,把用户id和对应的channel对象存储起来
|
||||
if (null != msg && msg instanceof FullHttpRequest) {
|
||||
FullHttpRequest request = (FullHttpRequest) msg;
|
||||
String uri = request.uri();
|
||||
String userId = getUrlParams(uri);
|
||||
WebServiceManager.addUser(userId, ctx.channel());
|
||||
log.info("登录的用户id是:{}", userId);
|
||||
//如果url包含参数,需要处理
|
||||
if (uri.contains(QUESTION_MARK)) {
|
||||
String newUri = uri.substring(0, uri.indexOf(QUESTION_MARK));
|
||||
request.setUri(newUri);
|
||||
}
|
||||
|
||||
} else if (msg instanceof TextWebSocketFrame) {
|
||||
//正常的TEXT消息类型
|
||||
TextWebSocketFrame frame = (TextWebSocketFrame) msg;
|
||||
log.info("客户端收到服务器数据:{}", frame.text());
|
||||
}
|
||||
super.channelRead(ctx, msg);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户地址获取用户名 ws://127.0.0.1:7777/hello?name=aa
|
||||
* @param url
|
||||
* @return
|
||||
*/
|
||||
private static String getUrlParams(String url) {
|
||||
if (!url.contains(EQUAL_TO)) {
|
||||
return null;
|
||||
}
|
||||
String userId = url.substring(url.indexOf(EQUAL_TO) + 1);
|
||||
return userId;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void channelRead0(ChannelHandlerContext ctx, TextWebSocketFrame msg) {
|
||||
/* System.out.println("服务端消息 == " + msg.text());
|
||||
if(msg.text().equals("下发指令")){
|
||||
*//**
|
||||
* 处理对应消息
|
||||
* 1.先下发所要操作的流程信息
|
||||
* 2.组装对应的入参信息
|
||||
* 3.再用socket信息返回结束
|
||||
*//*
|
||||
//NettyClient.socketClient(msg.text(),new NettySourceClientHandler());
|
||||
|
||||
}*/
|
||||
|
||||
//可以直接调用text 拿到文本信息帧中的信息
|
||||
/* Channel channel = ctx.channel();
|
||||
TextWebSocketFrame resp = new TextWebSocketFrame(msg.text());
|
||||
channel.writeAndFlush(resp);*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlerAdded(ChannelHandlerContext ctx) {
|
||||
//WebServiceManager.addUser(userId, ctx.channel());
|
||||
System.out.println("有新的连接接入:" + ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
|
||||
// 假设用户 ID 是从某个地方获取的,这里简单示例为 "userId"
|
||||
System.out.println("weoSocket退出: " + ctx);
|
||||
WebServiceManager.removeChannel(ctx.channel().id().toString());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
|
||||
//空闲状态的事件
|
||||
// if (evt instanceof IdleStateEvent) {
|
||||
// IdleStateEvent event = (IdleStateEvent) evt;
|
||||
// System.out.println(event.state() + ">>>" + ctx.channel().id());
|
||||
// //已经10秒钟没有读时间了
|
||||
// if (event.state().equals(IdleState.READER_IDLE)){
|
||||
// // 心跳包丢失,10秒没有收到客户端心跳 (断开连接)
|
||||
// ctx.channel().close().sync();
|
||||
// System.out.println("已与 "+ctx.channel().remoteAddress()+" 断开连接");
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
* 推送数据至前台
|
||||
*/
|
||||
public void sendMsgToUser(String userId, String msg) {
|
||||
WebServiceManager.sendMsg(userId, msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
|
||||
cause.printStackTrace();
|
||||
ctx.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.njcn.gather.detection.util.socket.web;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||
import io.netty.channel.ChannelInitializer;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
import io.netty.channel.socket.SocketChannel;
|
||||
import io.netty.handler.codec.http.HttpObjectAggregator;
|
||||
import io.netty.handler.codec.http.HttpResponseDecoder;
|
||||
import io.netty.handler.codec.http.HttpServerCodec;
|
||||
import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler;
|
||||
import io.netty.handler.stream.ChunkedWriteHandler;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @Description: webSocket服务端自定义配置
|
||||
* @Author: wr
|
||||
* @Date: 2024/12/10 14:20
|
||||
*/
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class WebSocketInitializer extends ChannelInitializer<SocketChannel> {
|
||||
|
||||
private final WebSocketHandler webSocketHandler;
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected void initChannel(SocketChannel ch) throws Exception {
|
||||
ChannelPipeline pipeline = ch.pipeline();
|
||||
//设置心跳机制
|
||||
// ch.pipeline().addLast(new IdleStateHandler(5, 0, 0));
|
||||
//增加编解码器 的另一种方式
|
||||
pipeline.addLast(new HttpServerCodec());
|
||||
pipeline.addLast(new HttpResponseDecoder());
|
||||
//块方式写的处理器 适合处理大数据
|
||||
pipeline.addLast(new ChunkedWriteHandler());
|
||||
//聚合
|
||||
pipeline.addLast(new HttpObjectAggregator(512 * 1024));
|
||||
/*
|
||||
* 这个时候 我们需要声明我们使用的是 websocket 协议
|
||||
* netty为websocket也准备了对应处理器 设置的是访问路径
|
||||
* 这个时候我们只需要访问 ws://127.0.0.1:7777/hello 就可以了
|
||||
* 这个handler是将http协议升级为websocket 并且使用 101 作为响应码
|
||||
* */
|
||||
pipeline.addLast(webSocketHandler);
|
||||
pipeline.addLast(new WebSocketServerProtocolHandler("/hello"));
|
||||
|
||||
pipeline.addLast(new ChannelInboundHandlerAdapter() {
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
|
||||
// 处理异常,例如记录日志、关闭连接等
|
||||
System.out.println("进入异常++++++++++++++++++");
|
||||
cause.printStackTrace();
|
||||
ctx.close();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
package com.njcn.gather.detection.util.socket.web;
|
||||
|
||||
|
||||
import io.netty.bootstrap.ServerBootstrap;
|
||||
import io.netty.channel.ChannelFuture;
|
||||
import io.netty.channel.ChannelOption;
|
||||
import io.netty.channel.EventLoopGroup;
|
||||
import io.netty.channel.nio.NioEventLoopGroup;
|
||||
import io.netty.channel.socket.nio.NioServerSocketChannel;
|
||||
import io.netty.handler.logging.LoggingHandler;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
|
||||
|
||||
/**
|
||||
* @Description: websocket服务端
|
||||
* @Author: wr
|
||||
* @Date: 2024/12/10 13:59
|
||||
*/
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class WebSocketService {
|
||||
|
||||
private final WebSocketInitializer webSocketInitializer;
|
||||
|
||||
/**
|
||||
* 端口号
|
||||
*/
|
||||
@Value("${webSocket.port:7777}")
|
||||
int port;
|
||||
|
||||
|
||||
EventLoopGroup bossGroup;
|
||||
EventLoopGroup workerGroup;
|
||||
|
||||
|
||||
|
||||
@PostConstruct
|
||||
public void start() {
|
||||
new Thread(() -> {
|
||||
//可以自定义线程的数量
|
||||
bossGroup = new NioEventLoopGroup();
|
||||
// 默认创建的线程数量 = CPU 处理器数量 *2
|
||||
workerGroup = new NioEventLoopGroup();
|
||||
try {
|
||||
ServerBootstrap serverBootstrap = new ServerBootstrap();
|
||||
serverBootstrap.group(bossGroup, workerGroup)
|
||||
.channel(NioServerSocketChannel.class)
|
||||
.handler(new LoggingHandler())
|
||||
//当前连接被阻塞的时候,BACKLOG代表的事 阻塞队列的长度
|
||||
.option(ChannelOption.SO_BACKLOG, 128)
|
||||
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 5000)
|
||||
|
||||
//设置连接保持为活动状态
|
||||
.childOption(ChannelOption.SO_KEEPALIVE, true)
|
||||
.childHandler(webSocketInitializer);
|
||||
ChannelFuture future = serverBootstrap.bind(port).sync();
|
||||
future.addListener(f -> {
|
||||
if (future.isSuccess()) {
|
||||
System.out.println("webSocket服务启动成功");
|
||||
} else {
|
||||
System.out.println("webSocket服务启动失败");
|
||||
}
|
||||
});
|
||||
future.channel().closeFuture().sync();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
bossGroup.shutdownGracefully();
|
||||
workerGroup.shutdownGracefully();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 释放资源
|
||||
*/
|
||||
@PreDestroy
|
||||
public void destroy() throws InterruptedException {
|
||||
if (bossGroup != null) {
|
||||
bossGroup.shutdownGracefully().sync();
|
||||
}
|
||||
if (workerGroup != null) {
|
||||
workerGroup.shutdownGracefully().sync();
|
||||
}
|
||||
|
||||
System.out.println("webSocket销毁---------------");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,199 @@
|
||||
package com.njcn.gather.plan.controller;
|
||||
|
||||
import cn.afterturn.easypoi.excel.ExcelImportUtil;
|
||||
import cn.afterturn.easypoi.excel.entity.ImportParams;
|
||||
import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
import com.njcn.common.pojo.constant.OperateType;
|
||||
import com.njcn.common.pojo.enums.common.LogEnum;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.LogUtil;
|
||||
import com.njcn.gather.device.device.service.IPqDevService;
|
||||
import com.njcn.gather.device.pojo.enums.DevResponseEnum;
|
||||
import com.njcn.gather.device.pojo.enums.PatternEnum;
|
||||
import com.njcn.gather.plan.pojo.param.AdPlanParam;
|
||||
import com.njcn.gather.plan.pojo.vo.AdPlanExcel;
|
||||
import com.njcn.gather.plan.pojo.vo.AdPlanVO;
|
||||
import com.njcn.gather.plan.service.IAdPlanService;
|
||||
import com.njcn.gather.system.dictionary.service.IDictDataService;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import com.njcn.web.utils.ExcelUtil;
|
||||
import com.njcn.web.utils.HttpResultUtil;
|
||||
import com.njcn.web.utils.PoiUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024-12-09
|
||||
*/
|
||||
@Slf4j
|
||||
@Api(tags = "检测计划管理")
|
||||
@RestController
|
||||
@RequestMapping("/adPlan")
|
||||
@RequiredArgsConstructor
|
||||
public class AdPlanController extends BaseController {
|
||||
|
||||
private final IAdPlanService adPlanService;
|
||||
|
||||
@OperateInfo
|
||||
@PostMapping("/list")
|
||||
@ApiOperation("分页查询检测计划")
|
||||
@ApiImplicitParam(name = "queryParam", value = "查询参数", required = true)
|
||||
public HttpResult<Page<AdPlanVO>> list(@RequestBody @Validated AdPlanParam.QueryParam queryParam) {
|
||||
String methodDescribe = getMethodDescribe("list");
|
||||
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, queryParam);
|
||||
Page<AdPlanVO> result = adPlanService.listAdPlan(queryParam);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(operateType = OperateType.ADD)
|
||||
@PostMapping("/add")
|
||||
@ApiOperation("新增检测计划")
|
||||
@ApiImplicitParam(name = "pqDevParam", value = "检测计划", required = true)
|
||||
public HttpResult<Object> add(@RequestBody @Validated AdPlanParam param) {
|
||||
String methodDescribe = getMethodDescribe("add");
|
||||
LogUtil.njcnDebug(log, "{},新增数据为:{}", methodDescribe, param);
|
||||
boolean result = adPlanService.addAdPlan(param);
|
||||
if (result) {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
} else {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
|
||||
}
|
||||
}
|
||||
|
||||
@OperateInfo(operateType = OperateType.UPDATE)
|
||||
@PostMapping("/update")
|
||||
@ApiOperation("修改检测计划")
|
||||
@ApiImplicitParam(name = "updateParam", value = "检测计划", required = true)
|
||||
public HttpResult<Object> update(@RequestBody @Validated AdPlanParam.UpdateParam updateParam) {
|
||||
String methodDescribe = getMethodDescribe("update");
|
||||
LogUtil.njcnDebug(log, "{},修改数据为:{}", methodDescribe, updateParam);
|
||||
boolean result = adPlanService.updateAdPlan(updateParam);
|
||||
if (result) {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
} else {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
|
||||
}
|
||||
}
|
||||
|
||||
@OperateInfo(operateType = OperateType.DELETE)
|
||||
@PostMapping("/delete")
|
||||
@ApiOperation("删除检测计划")
|
||||
@ApiImplicitParam(name = "ids", value = "检测计划id", required = true)
|
||||
public HttpResult<Object> delete(@RequestBody List<String> ids) {
|
||||
String methodDescribe = getMethodDescribe("delete");
|
||||
LogUtil.njcnDebug(log, "{},删除ID数据为:{}", methodDescribe, String.join(StrUtil.COMMA, ids));
|
||||
boolean result = adPlanService.deleteAdPlan(ids);
|
||||
if (result) {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
} else {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@OperateInfo
|
||||
@GetMapping("/listByPattern")
|
||||
@ApiOperation("按照模式查询检测计划")
|
||||
@ApiImplicitParam(name = "pattern", value = "模式Id", required = true)
|
||||
public HttpResult<List<Map<String, Object>>> listByPattern(@RequestParam("pattern") String pattern) {
|
||||
String methodDescribe = getMethodDescribe("listByPattern");
|
||||
LogUtil.njcnDebug(log, "{},模式Id为:{}", methodDescribe, pattern);
|
||||
List<Map<String, Object>> result = adPlanService.listByPattern(pattern);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.DOWNLOAD)
|
||||
@PostMapping("/downloadTemplate")
|
||||
@ApiOperation("下载监测计划导入文件模板")
|
||||
public void downloadTemplate() {
|
||||
adPlanService.downloadTemplate();
|
||||
}
|
||||
|
||||
@OperateInfo(operateType = OperateType.DOWNLOAD)
|
||||
@PostMapping("/export")
|
||||
@ApiOperation("导出检测计划")
|
||||
@ApiImplicitParam(name = "queryParam", value = "查询参数", required = true)
|
||||
public void export(@RequestBody @Validated AdPlanParam.QueryParam queryParam) {
|
||||
String methodDescribe = getMethodDescribe("export");
|
||||
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, queryParam);
|
||||
List<AdPlanExcel.ExportData> data = adPlanService.getExportData(queryParam);
|
||||
ExcelUtil.exportExcel("检测计划导出数据.xlsx", AdPlanExcel.ExportData.class, data);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.UPLOAD)
|
||||
@PostMapping(value = "/import")
|
||||
@ApiOperation("批量导入检测计划数据")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "file", value = "检测计划数据文件", required = true),
|
||||
@ApiImplicitParam(name = "pattern", value = "模式Id", required = true)
|
||||
})
|
||||
public HttpResult<Object> importData(@RequestParam("file") MultipartFile file, @RequestParam("patternId") String patternId, HttpServletResponse response) {
|
||||
String methodDescribe = getMethodDescribe("importData");
|
||||
LogUtil.njcnDebug(log, "{},上传文件为:{}, 模式Id为:{}", methodDescribe, file.getOriginalFilename(), patternId);
|
||||
|
||||
ImportParams params = new ImportParams();
|
||||
params.setHeadRows(2);
|
||||
params.setNeedVerify(true);
|
||||
params.setStartSheetIndex(0);
|
||||
params.setSheetNum(1);
|
||||
|
||||
try {
|
||||
ExcelImportResult<AdPlanExcel.ImportData> adPlanExcelResult = ExcelImportUtil.importExcelMore(file.getInputStream(), AdPlanExcel.ImportData.class, params);
|
||||
if (adPlanExcelResult.isVerifyFail()) {
|
||||
// 此处前端要做特殊处理,具体可以参考技术监督的数据导入
|
||||
PoiUtil.exportFileByWorkbook(adPlanExcelResult.getFailWorkbook(), "非法检测计划数据.xlsx", response);
|
||||
} else {
|
||||
List<AdPlanExcel.ImportData> adPlanExcelList = adPlanExcelResult.getList();
|
||||
if (ObjectUtil.isNotEmpty(adPlanExcelList)) {
|
||||
adPlanService.importData(patternId, adPlanExcelList);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new BusinessException(DevResponseEnum.IMPORT_DATA_FAIL, e.getMessage());
|
||||
}
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
|
||||
// @OperateInfo
|
||||
// @GetMapping("/getPieData")
|
||||
// @ApiOperation("获取饼状图数据")
|
||||
// @ApiImplicitParam(name = "id", value = "检测计划id", required = true)
|
||||
// public HttpResult<List<List<Map<String, Object>>>> getPieData(@RequestParam("planId") String planId) {
|
||||
// String methodDescribe = getMethodDescribe("getPieData");
|
||||
// LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, planId);
|
||||
// List<List<Map<String, Object>>> result = pqDevService.getPieData(planId);
|
||||
// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
// }
|
||||
|
||||
@OperateInfo
|
||||
@GetMapping("/getBigTestItem")
|
||||
@ApiOperation("获取检测大项数据")
|
||||
@ApiImplicitParam(name = "id", value = "检测计划id", required = true)
|
||||
public HttpResult<List<Map<String, String>>> getBigTestItem(@RequestParam("planId") String planId) {
|
||||
String methodDescribe = getMethodDescribe("getBigTestItem");
|
||||
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, planId);
|
||||
List<Map<String, String>> result = adPlanService.getBigTestItem(planId);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.njcn.gather.plan.mapper;
|
||||
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
import com.njcn.gather.plan.pojo.po.AdPlan;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024-12-09
|
||||
*/
|
||||
public interface AdPlanMapper extends MPJBaseMapper<AdPlan> {
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.njcn.gather.plan.mapper;
|
||||
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
import com.njcn.gather.plan.pojo.po.AdPlanSource;
|
||||
import com.njcn.gather.device.source.pojo.po.PqSource;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024-12-09
|
||||
*/
|
||||
public interface AdPlanSourceMapper extends MPJBaseMapper<AdPlanSource> {
|
||||
|
||||
/**
|
||||
* 根据检测计划id获取检测源
|
||||
*
|
||||
* @param planId 检测计划id
|
||||
* @return 检测源列表
|
||||
*/
|
||||
List<PqSource> selectPqSourceByPlanId(String planId);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.njcn.gather.plan.mapper.AdPlanMapper">
|
||||
|
||||
|
||||
</mapper>
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.njcn.gather.plan.mapper.AdPlanSourceMapper">
|
||||
|
||||
|
||||
<select id="selectPqSourceByPlanId" resultType="com.njcn.gather.device.source.pojo.po.PqSource">
|
||||
SELECT pq_source.*
|
||||
FROM pq_source,
|
||||
ad_plan_source
|
||||
WHERE pq_source.id = ad_plan_source.Source_Id
|
||||
AND ad_plan_source.Plan_Id = #{planId}
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.njcn.gather.plan.pojo.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2024-12-12
|
||||
*/
|
||||
@Getter
|
||||
public enum DataSourceEnum {
|
||||
THREE_SENSE_ACTUAL_TIME_DATA("0", "3秒实时数据"),
|
||||
|
||||
MINUTE_STATISTICS_MAX("1", "分钟统计数据-最大"),
|
||||
MINUTE_STATISTICS_MIN("2", "分钟统计数据-最小"),
|
||||
MINUTE_STATISTICS_AVG("3", "分钟统计数据-平均"),
|
||||
MINUTE_STATISTICS_CP95("4", "分钟统计数据-CP95"),
|
||||
RECORDED_DATA("5", "录播数据");
|
||||
|
||||
private String value;
|
||||
private String msg;
|
||||
|
||||
DataSourceEnum(String value, String msg) {
|
||||
this.value = value;
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public static String getMsgByValue(String value) {
|
||||
for (DataSourceEnum dataSourceEnum : DataSourceEnum.values()) {
|
||||
if (dataSourceEnum.getValue().equals(value)) {
|
||||
return dataSourceEnum.getMsg();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getValueByMsg(String msg) {
|
||||
for (DataSourceEnum dataSourceEnum : DataSourceEnum.values()) {
|
||||
if (dataSourceEnum.getMsg().equals(msg)) {
|
||||
return dataSourceEnum.getValue();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
package com.njcn.gather.plan.pojo.param;
|
||||
|
||||
import com.njcn.common.pojo.constant.PatternRegex;
|
||||
import com.njcn.gather.device.pojo.constant.DevValidMessage;
|
||||
import com.njcn.web.pojo.param.BaseParam;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import javax.validation.constraints.*;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2024-12-09
|
||||
*/
|
||||
@Data
|
||||
public class AdPlanParam {
|
||||
|
||||
@ApiModelProperty(value = "名称", required = true)
|
||||
@NotBlank(message = DevValidMessage.NAME_NOT_BLANK)
|
||||
@Pattern(regexp = PatternRegex.PLAN_NAME_REGEX, message = DevValidMessage.NAME_FORMAT_ERROR)
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(value = "模式", required = true)
|
||||
@NotBlank(message = DevValidMessage.PATTERN_NOT_BLANK)
|
||||
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.PATTERN_FORMAT_ERROR)
|
||||
private String pattern;
|
||||
|
||||
// @ApiModelProperty(value = "父计划ID")
|
||||
// @Pattern(regexp = PatternRegex.SYSTEM_ID, message = DeviceValidMessage.PATTERN_FORMAT_ERROR)
|
||||
// private String fatherPlanId;
|
||||
|
||||
@ApiModelProperty(value = "检测源ID列表",required = true)
|
||||
@NotEmpty(message = DevValidMessage.SOURCE_IDS_NOT_EMPTY)
|
||||
private List<@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.SOURCE_ID_FORMAT_ERROR)String> sourceIds;
|
||||
|
||||
@ApiModelProperty(value = "数据源ID列表", required = true)
|
||||
@NotEmpty(message = DevValidMessage.DATASOURCE_ID_NOT_EMPTY)
|
||||
private List<String> datasourceIds;
|
||||
|
||||
@ApiModelProperty(value = "检测脚本ID", required = true)
|
||||
@NotBlank(message = DevValidMessage.SCRIPT_ID_NOT_BLANK)
|
||||
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.SCRIPT_ID_FORMAT_ERROR)
|
||||
private String scriptId;
|
||||
|
||||
@ApiModelProperty(value = "误差体系ID", required = true)
|
||||
@NotBlank(message = DevValidMessage.ERROR_SYS_ID_NOT_BLANK)
|
||||
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.ERROR_SYS_ID_FORMAT_ERROR)
|
||||
private String errorSysId;
|
||||
|
||||
@ApiModelProperty(value = "守时检测")
|
||||
@NotNull(message = DevValidMessage.TIME_CHECK_NOT_NULL)
|
||||
@Min(value = 0, message = DevValidMessage.TIME_CHECK_FORMAT_ERROR)
|
||||
@Max(value = 1, message = DevValidMessage.TIME_CHECK_FORMAT_ERROR)
|
||||
private Integer timeCheck;
|
||||
|
||||
@ApiModelProperty("被检设备ID列表")
|
||||
@NotNull(message = DevValidMessage.PQ_DEV_IDS_NOT_NULL)
|
||||
private List<String> devIds;
|
||||
|
||||
/**
|
||||
* 分页查询实体
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public static class QueryParam extends BaseParam {
|
||||
@ApiModelProperty("名称")
|
||||
@Pattern(regexp = PatternRegex.DEV_NAME_REGEX, message = DevValidMessage.NAME_FORMAT_ERROR)
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(value = "模式,字典表(数字、模拟、比对)")
|
||||
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.PATTERN_FORMAT_ERROR)
|
||||
@NotBlank(message = DevValidMessage.PATTERN_NOT_BLANK)
|
||||
private String pattern;
|
||||
|
||||
@ApiModelProperty(value = "检测状态")
|
||||
@Min(value = 0, message = DevValidMessage.TEST_STATE_FORMAT_ERROR)
|
||||
@Max(value = 2, message = DevValidMessage.TEST_STATE_FORMAT_ERROR)
|
||||
private Integer testState;
|
||||
|
||||
@ApiModelProperty(value = "报告生成状态")
|
||||
@Min(value = 0, message = DevValidMessage.REPORT_STATE_FORMAT_ERROR)
|
||||
@Max(value = 2, message = DevValidMessage.REPORT_STATE_FORMAT_ERROR)
|
||||
private Integer reportState;
|
||||
|
||||
@ApiModelProperty(value = "检测结果")
|
||||
@Min(value = 0, message = DevValidMessage.CHECK_RESULT_STATE_FORMAT_ERROR)
|
||||
@Max(value = 2, message = DevValidMessage.CHECK_RESULT_STATE_FORMAT_ERROR)
|
||||
private Integer result;
|
||||
}
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public static class UpdateParam extends AdPlanParam {
|
||||
@ApiModelProperty(value = "id", required = true)
|
||||
@NotBlank(message = DevValidMessage.ID_NOT_BLANK)
|
||||
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.ID_FORMAT_ERROR)
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 检测状态,字典表(未检、检测中、检测完成)
|
||||
*/
|
||||
// @ApiModelProperty(value = "检测状态")
|
||||
// @NotNull(message = DeviceValidMessage.TEST_STATE_NOT_NULL)
|
||||
// @Min(value = 0, message = DeviceValidMessage.TEST_STATE_FORMAT_ERROR)
|
||||
// @Max(value = 2, message = DeviceValidMessage.TEST_STATE_FORMAT_ERROR)
|
||||
// private Integer testState;
|
||||
|
||||
/**
|
||||
* 报告生成状态,字典表(未生成、部分生成、全部生成)
|
||||
*/
|
||||
// @ApiModelProperty(value = "报告生成状态")
|
||||
// @NotNull(message = DeviceValidMessage.REPORT_STATE_NOT_NULL)
|
||||
// @Min(value = 0, message = DeviceValidMessage.REPORT_STATE_FORMAT_ERROR)
|
||||
// @Max(value = 2, message = DeviceValidMessage.REPORT_STATE_FORMAT_ERROR)
|
||||
// private Integer reportState;
|
||||
|
||||
/**
|
||||
* 检测结果,字典表(符合、不符合、/)
|
||||
*/
|
||||
// @ApiModelProperty(value = "检测结果")
|
||||
// @NotNull(message = DeviceValidMessage.CHECK_RESULT_STATE_NOT_NULL)
|
||||
// @Min(value = 0, message = DeviceValidMessage.CHECK_RESULT_STATE_FORMAT_ERROR)
|
||||
// @Max(value = 2, message = DeviceValidMessage.CHECK_RESULT_STATE_FORMAT_ERROR)
|
||||
// private Integer result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
package com.njcn.gather.plan.pojo.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.njcn.db.mybatisplus.bo.BaseEntity;
|
||||
import io.swagger.models.auth.In;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024-12-09
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("ad_plan")
|
||||
public class AdPlan extends BaseEntity implements Serializable {
|
||||
private static final long serialVersionUID = 923200973006628094L;
|
||||
|
||||
/**
|
||||
* 检测计划ID
|
||||
*/
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 检测计划名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 模式,字典表(数字、模拟、比对)
|
||||
*/
|
||||
private String pattern;
|
||||
|
||||
/**
|
||||
* 父计划ID
|
||||
*/
|
||||
private String fatherPlanId;
|
||||
|
||||
/**
|
||||
* 数据源ID,字典表
|
||||
*/
|
||||
private String datasourceId;
|
||||
|
||||
/**
|
||||
* 检测脚本ID,关联PQ_Script表
|
||||
*/
|
||||
private String scriptId;
|
||||
|
||||
/**
|
||||
* 误差体系ID,关联PQ_Error_Sys表
|
||||
*/
|
||||
private String errorSysId;
|
||||
|
||||
/**
|
||||
* 守时检测
|
||||
*/
|
||||
private Integer timeCheck;
|
||||
|
||||
/**
|
||||
* 检测状态,字典表(未检、检测中、检测完成)
|
||||
*/
|
||||
private Integer testState;
|
||||
|
||||
/**
|
||||
* 报告生成状态,字典表(未生成、部分生成、全部生成)
|
||||
*/
|
||||
private Integer reportState;
|
||||
|
||||
/**
|
||||
* 检测结果,字典表(符合、不符合)
|
||||
*/
|
||||
private Integer result;
|
||||
|
||||
/**
|
||||
* 自动生成,用于生成数据表后缀
|
||||
*/
|
||||
private Integer code;
|
||||
|
||||
/**
|
||||
* 状态:0-删除 1-正常
|
||||
*/
|
||||
private Integer state;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.njcn.gather.plan.pojo.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024-12-09
|
||||
*/
|
||||
@Data
|
||||
@TableName("ad_plan_source")
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class AdPlanSource implements Serializable {
|
||||
private static final long serialVersionUID = -76292730578149530L;
|
||||
/**
|
||||
* 检测计划表Id
|
||||
*/
|
||||
@TableField("Plan_Id")
|
||||
private String planId;
|
||||
|
||||
/**
|
||||
* 检测源表Id
|
||||
*/
|
||||
@TableField("Source_Id")
|
||||
private String sourceId;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,184 @@
|
||||
package com.njcn.gather.plan.pojo.vo;
|
||||
|
||||
import cn.afterturn.easypoi.excel.annotation.Excel;
|
||||
import cn.afterturn.easypoi.excel.annotation.ExcelCollection;
|
||||
import com.njcn.common.pojo.constant.PatternRegex;
|
||||
import com.njcn.gather.device.pojo.constant.DevValidMessage;
|
||||
import com.njcn.web.pojo.annotation.DateTimeStrValid;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.hibernate.validator.constraints.Range;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Pattern;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2024-12-11
|
||||
*/
|
||||
@Data
|
||||
public class AdPlanExcel {
|
||||
@Excel(name = "名称", width = 40, needMerge = true, orderNum = "0")
|
||||
@NotBlank(message = DevValidMessage.NAME_NOT_BLANK)
|
||||
private String name;
|
||||
|
||||
@Excel(name = "检测源", width = 40, needMerge = true, orderNum = "1")
|
||||
@NotBlank(message = DevValidMessage.SOURC_NOT_BLANK)
|
||||
private String source;
|
||||
|
||||
@Excel(name = "数据源", width = 20, needMerge = true, orderNum = "2")
|
||||
@NotBlank(message = DevValidMessage.DATASOURCE_NOT_BLANK)
|
||||
private String datasourceId;
|
||||
|
||||
@Excel(name = "脚本", width = 50, needMerge = true, orderNum = "3")
|
||||
@NotBlank(message = DevValidMessage.SCRIPT_NOT_BLANK)
|
||||
private String scriptId;
|
||||
|
||||
@Excel(name = "误差体系", width = 30, needMerge = true, orderNum = "4")
|
||||
@NotBlank(message = DevValidMessage.ERRORSYS_NOT_BLANK)
|
||||
private String errorSysId;
|
||||
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public static class ExportData extends AdPlanExcel {
|
||||
// @Excel(name = "模式", width = 20, needMerge = true, orderNum = "1")
|
||||
// @NotBlank(message = DevValidMessage.PATTERN_NOT_BLANK)
|
||||
// private String pattern;
|
||||
|
||||
// @Excel(name = "父计划id", width = 25, needMerge = true, orderNum = "3")
|
||||
// private String fatherPlanId;
|
||||
|
||||
@Excel(name = "是否做守时检测(否\\是)", width = 15, replace = {"否_0", "是_1"}, needMerge = true, orderNum = "5")
|
||||
private Integer timeCheck;
|
||||
|
||||
@Excel(name = "检测状态(未检\\检测中\\检测完成)", width = 10, replace = {"未检_0", "检测中_1", "检测完成_2"}, needMerge = true, orderNum = "6")
|
||||
private Integer testState;
|
||||
|
||||
@Excel(name = "报告生成状态(未生成\\部分生成\\全部生成)", width = 15, replace = {"未生成_0", "部分生成_1", "全部生成_2"}, needMerge = true, orderNum = "7")
|
||||
private Integer reportState;
|
||||
|
||||
@Excel(name = "检测结果(不符合\\符合\\未检)", width = 10, replace = {"不符合_0", "符合_1", "未检_2"}, needMerge = true, orderNum = "8")
|
||||
private Integer result;
|
||||
|
||||
// @Excel(name = "数据表后缀", width = 20, needMerge = true, orderNum = "11")
|
||||
// private Integer code;
|
||||
|
||||
@ExcelCollection(name = "绑定的设备", orderNum = "9")
|
||||
private List<AdPlanExcel.BoundExportData> devices;
|
||||
}
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public static class ImportData extends AdPlanExcel {
|
||||
@Excel(name = "是否做守时检测(否\\是)", width = 15, replace = {"否_0", "是_1"}, needMerge = true, orderNum = "5")
|
||||
@NotBlank(message = DevValidMessage.TIMECHECK_NOT_BLANK)
|
||||
private String timeCheck;
|
||||
|
||||
@Excel(name = "检测状态(未检\\检测中\\检测完成)", width = 10, replace = {"未检_0", "检测中_1", "检测完成_2"}, needMerge = true, orderNum = "6")
|
||||
@NotBlank(message = DevValidMessage.TEST_STATE_NOT_NULL)
|
||||
private String testState;
|
||||
|
||||
@Excel(name = "报告生成状态(未生成\\部分生成\\全部生成)", width = 15, replace = {"未生成_0", "部分生成_1", "全部生成_2"}, needMerge = true, orderNum = "7")
|
||||
@NotBlank(message = DevValidMessage.REPORT_STATE_NOT_NULL)
|
||||
private String reportState;
|
||||
|
||||
@Excel(name = "检测结果(不符合\\符合\\未检)", width = 10, replace = {"不符合_0", "符合_1", "未检_2"}, needMerge = true, orderNum = "8")
|
||||
@NotBlank(message = DevValidMessage.CHECK_RESULT_STATE_NOT_NULL)
|
||||
private String result;
|
||||
|
||||
@ExcelCollection(name = "绑定的设备", orderNum = "9")
|
||||
private List<AdPlanExcel.BoundImportData> devices;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class BoundData {
|
||||
@Excel(name = "名称", width = 20)
|
||||
@NotBlank(message = DevValidMessage.NAME_NOT_BLANK)
|
||||
@Pattern(regexp = PatternRegex.DEV_NAME_REGEX, message = DevValidMessage.NAME_FORMAT_ERROR)
|
||||
private String name;
|
||||
|
||||
@Excel(name = "设备类型", width = 20, orderNum = "2")
|
||||
@NotBlank(message = DevValidMessage.DEV_TYPE_NOT_BLANK)
|
||||
private String devType;
|
||||
|
||||
@Excel(name = "设备通道数", width = 20, orderNum = "3")
|
||||
@NotNull(message = DevValidMessage.DEV_CHNS_NOT_NULL)
|
||||
private Integer devChns;
|
||||
|
||||
@Excel(name = "额定电压(V)", width = 15, orderNum = "4")
|
||||
@NotNull(message = DevValidMessage.DEV_VOLT_NOT_NULL)
|
||||
private Float devVolt;
|
||||
|
||||
@Excel(name = "额定电流(A)", width = 15, orderNum = "5")
|
||||
@NotNull(message = DevValidMessage.DEV_CURR_NOT_NULL)
|
||||
private Float devCurr;
|
||||
|
||||
@Excel(name = "设备厂家", width = 20, orderNum = "6")
|
||||
@NotBlank(message = DevValidMessage.MANUFACTURER_NOT_BLANK)
|
||||
private String manufacturer;
|
||||
|
||||
@Excel(name = "设备序列号", width = 40, orderNum = "8")
|
||||
@NotBlank(message = DevValidMessage.FACTORYNO_NOT_BLANK)
|
||||
private String createId;
|
||||
|
||||
@Excel(name = "固件版本", width = 15, orderNum = "9")
|
||||
@NotBlank(message = DevValidMessage.FIRMWARE_NOT_BLANK)
|
||||
private String hardwareVersion;
|
||||
|
||||
@Excel(name = "软件版本", width = 15, orderNum = "10")
|
||||
@NotBlank(message = DevValidMessage.SOFTWARE_NOT_BLANK)
|
||||
private String softwareVersion;
|
||||
|
||||
@Excel(name = "通讯协议", width = 15, orderNum = "11")
|
||||
@NotBlank(message = DevValidMessage.PROTOCOL_NOT_BLANK)
|
||||
private String protocol;
|
||||
|
||||
@Excel(name = "IP地址", width = 20, orderNum = "12")
|
||||
@NotBlank(message = DevValidMessage.IP_NOT_BLANK)
|
||||
@Pattern(regexp = PatternRegex.IP_REGEX, message = DevValidMessage.IP_FORMAT_ERROR)
|
||||
private String ip;
|
||||
|
||||
@Excel(name = "端口号", orderNum = "13")
|
||||
@NotNull(message = DevValidMessage.PORT_NOT_NULL)
|
||||
@Range(min = 1, max = 65535, message = DevValidMessage.PORT_RANGE_ERROR)
|
||||
private Integer port;
|
||||
|
||||
@Excel(name = "是否为加密版本(否\\是)", width = 20, replace = {"否_0", "是_1"}, orderNum = "14")
|
||||
@NotNull(message = DevValidMessage.ENCRYPTION_NOT_NULL)
|
||||
private Integer encryptionFlag;
|
||||
|
||||
@Excel(name = "识别码(当为加密版本时必填)", width = 30, orderNum = "15")
|
||||
private String series;
|
||||
|
||||
@Excel(name = "秘钥(当为加密版本时必填)", width = 30, orderNum = "16")
|
||||
private String devKey;
|
||||
}
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public static class BoundExportData extends BoundData {
|
||||
@Excel(name = "出厂日期(yyyy-MM-dd)", width = 25, format = "yyyy-MM-dd", orderNum = "7")
|
||||
@NotNull(message = DevValidMessage.CREATEDATETIME_NOT_NULL)
|
||||
private LocalDate createDate;
|
||||
|
||||
@Excel(name = "是否支持系数校准(否\\是)", width = 20, replace = {"否_0", "是_1"}, orderNum = "17", needMerge = true)
|
||||
private Integer factorFlag;
|
||||
}
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public static class BoundImportData extends BoundData {
|
||||
@Excel(name = "出厂日期(yyyy-MM-dd)", width = 25, format = "yyyy-MM-dd", orderNum = "7", needMerge = true)
|
||||
@NotNull(message = DevValidMessage.CREATEDATETIME_NOT_NULL)
|
||||
@DateTimeStrValid(message = DevValidMessage.CREATEDATETIME_FORMAT_ERROR)
|
||||
private String createDate;
|
||||
|
||||
@Excel(name = "是否支持系数校准(否\\是)", width = 20, replace = {"否_0", "是_1"}, orderNum = "17", needMerge = true)
|
||||
@NotBlank(message = DevValidMessage.FACTOR_FLAG_NOT_BLANK)
|
||||
private String factorFlag;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package com.njcn.gather.plan.pojo.vo;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2024-12-09
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class AdPlanVO {
|
||||
|
||||
/**
|
||||
* 检测计划ID
|
||||
*/
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 检测计划名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 模式,字典表(数字、模拟、比对)
|
||||
*/
|
||||
private String pattern;
|
||||
|
||||
/**
|
||||
* 父计划ID
|
||||
*/
|
||||
private String fatherPlanId;
|
||||
|
||||
/**
|
||||
* 数据源ID列表
|
||||
*/
|
||||
private List<String> datasourceIds;
|
||||
|
||||
/**
|
||||
* 检测源id
|
||||
*/
|
||||
private List<String> sourceIds;
|
||||
|
||||
/**
|
||||
* 检测源名称
|
||||
*/
|
||||
private List<String> sourceName;
|
||||
|
||||
/**
|
||||
* 检测脚本ID,关联PQ_Script表
|
||||
*/
|
||||
private String scriptId;
|
||||
|
||||
/**
|
||||
* 检测脚本名称
|
||||
*/
|
||||
private String scriptName;
|
||||
|
||||
/**
|
||||
* 误差体系ID,关联PQ_Error_Sys表
|
||||
*/
|
||||
private String errorSysId;
|
||||
|
||||
/**
|
||||
* 误差体系名称
|
||||
*/
|
||||
private String errorSysName;
|
||||
|
||||
/**
|
||||
* 守时检测
|
||||
*/
|
||||
private Integer timeCheck;
|
||||
|
||||
/**
|
||||
* 检测状态,字典表(未检、检测中、检测完成)
|
||||
*/
|
||||
private Integer testState;
|
||||
|
||||
/**
|
||||
* 报告生成状态,字典表(未生成、部分生成、全部生成)
|
||||
*/
|
||||
private Integer reportState;
|
||||
|
||||
/**
|
||||
* 检测结果,字典表(符合、不符合)
|
||||
*/
|
||||
private Integer result;
|
||||
|
||||
/**
|
||||
* 自动生成,用于生成数据表后缀
|
||||
*/
|
||||
private Integer code;
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package com.njcn.gather.plan.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.gather.plan.pojo.param.AdPlanParam;
|
||||
import com.njcn.gather.plan.pojo.vo.AdPlanVO;
|
||||
import com.njcn.gather.plan.pojo.po.AdPlan;
|
||||
import com.njcn.gather.plan.pojo.vo.AdPlanExcel;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024-12-09
|
||||
*/
|
||||
public interface IAdPlanService extends IService<AdPlan> {
|
||||
|
||||
/**
|
||||
* 分页查询检测计划
|
||||
*
|
||||
* @param queryParam 分页查询参数
|
||||
* @return 分页查询结果
|
||||
*/
|
||||
Page<AdPlanVO> listAdPlan(AdPlanParam.QueryParam queryParam);
|
||||
|
||||
/**
|
||||
* 新增检测计划
|
||||
*
|
||||
* @param param 检测计划参数
|
||||
* @return 新增成功则返回true,否则返回false
|
||||
*/
|
||||
boolean addAdPlan(AdPlanParam param);
|
||||
|
||||
/**
|
||||
* 更新检测计划
|
||||
*
|
||||
* @param param 更新参数
|
||||
* @return 更新成功则返回true,否则返回false
|
||||
*/
|
||||
boolean updateAdPlan(AdPlanParam.UpdateParam param);
|
||||
|
||||
/**
|
||||
* 删除检测计划
|
||||
*
|
||||
* @param ids 检测计划id列表
|
||||
* @return 删除成功则返回true,否则返回false
|
||||
*/
|
||||
boolean deleteAdPlan(List<String> ids);
|
||||
|
||||
/**
|
||||
* 根据模式查询检测计划
|
||||
*
|
||||
* @param pattern 模式Id
|
||||
* @return 检测计划列表
|
||||
*/
|
||||
List<Map<String, Object>> listByPattern(String pattern);
|
||||
|
||||
/**
|
||||
* 下载检测计划模板
|
||||
*/
|
||||
void downloadTemplate();
|
||||
|
||||
/**
|
||||
* 获取检测计划导出数据
|
||||
*
|
||||
* @param queryParam 查询参数
|
||||
* @return 检测计划导出数据
|
||||
*/
|
||||
List<AdPlanExcel.ExportData> getExportData(AdPlanParam.QueryParam queryParam);
|
||||
|
||||
/**
|
||||
* 导入检测计划
|
||||
* @param patternId 模式Id
|
||||
* @param adPlanExcelList 检测计划Excel列表
|
||||
* @return 导入成功则返回true,否则返回false
|
||||
*/
|
||||
void importData(String patternId, List<AdPlanExcel.ImportData> adPlanExcelList);
|
||||
|
||||
|
||||
/**
|
||||
* 可视化
|
||||
*
|
||||
* @param planList 检测计划列表
|
||||
*/
|
||||
void visualize(List<AdPlan> planList);
|
||||
|
||||
/**
|
||||
* 获取检测大项
|
||||
*
|
||||
* @param planId 检测计划Id
|
||||
* @return
|
||||
*/
|
||||
List<Map<String, String>> getBigTestItem(String planId);
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.njcn.gather.plan.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.gather.plan.pojo.po.AdPlanSource;
|
||||
import com.njcn.gather.device.source.pojo.po.PqSource;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024-12-09
|
||||
*/
|
||||
public interface IAdPlanSourceService extends IService<AdPlanSource> {
|
||||
/**
|
||||
* 根据检测计划id获取检测源
|
||||
*
|
||||
* @param planId 检测计划id
|
||||
* @return 检测源列表
|
||||
*/
|
||||
List<PqSource> listPqSourceByPlanId(String planId);
|
||||
|
||||
/**
|
||||
* 新增检测计划关联检测源数据
|
||||
*
|
||||
* @param planId 检测计划id
|
||||
* @param sourceIds 检测源id列表
|
||||
* @return 新增成功返回true,否则返回false
|
||||
*/
|
||||
boolean addAdPlanSource(String planId, List<String> sourceIds);
|
||||
|
||||
/**
|
||||
* 根据检测计划id删除关联的检测源数据
|
||||
*
|
||||
* @param planIds 检测计划id列表
|
||||
* @return 删除成功返回true,否则返回false
|
||||
*/
|
||||
boolean deleteAdPlanSourceByPlanIds(List<String> planIds);
|
||||
|
||||
/**
|
||||
* 更新检测计划关联的检测源数据
|
||||
*
|
||||
* @param planId 检测计划id
|
||||
* @param sourceIds 检测源id列表
|
||||
* @return 更新成功返回true,否则返回false
|
||||
*/
|
||||
boolean updateAdPlanSource(String planId, List<String> sourceIds);
|
||||
}
|
||||
@@ -0,0 +1,359 @@
|
||||
package com.njcn.gather.plan.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.common.pojo.enums.common.DataStateEnum;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.gather.device.device.pojo.enums.TimeCheckResultEnum;
|
||||
import com.njcn.gather.device.device.pojo.param.PqDevParam;
|
||||
import com.njcn.gather.device.device.pojo.po.PqDev;
|
||||
import com.njcn.gather.device.device.service.IPqDevService;
|
||||
import com.njcn.gather.device.err.service.IPqErrSysService;
|
||||
import com.njcn.gather.device.pojo.enums.*;
|
||||
import com.njcn.gather.device.script.pojo.po.PqScriptDtls;
|
||||
import com.njcn.gather.device.script.service.IPqScriptDtlsService;
|
||||
import com.njcn.gather.device.script.service.IPqScriptService;
|
||||
import com.njcn.gather.device.source.pojo.po.PqSource;
|
||||
import com.njcn.gather.device.source.service.IPqSourceService;
|
||||
import com.njcn.gather.plan.mapper.AdPlanMapper;
|
||||
import com.njcn.gather.plan.pojo.enums.DataSourceEnum;
|
||||
import com.njcn.gather.plan.pojo.param.AdPlanParam;
|
||||
import com.njcn.gather.plan.pojo.po.AdPlan;
|
||||
import com.njcn.gather.plan.pojo.vo.AdPlanExcel;
|
||||
import com.njcn.gather.plan.pojo.vo.AdPlanVO;
|
||||
import com.njcn.gather.plan.service.IAdPlanService;
|
||||
import com.njcn.gather.plan.service.IAdPlanSourceService;
|
||||
import com.njcn.gather.system.dictionary.pojo.po.DictTree;
|
||||
import com.njcn.gather.system.dictionary.service.IDictDataService;
|
||||
import com.njcn.gather.system.dictionary.service.IDictTreeService;
|
||||
import com.njcn.web.factory.PageFactory;
|
||||
import com.njcn.web.utils.ExcelUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024-12-09
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> implements IAdPlanService {
|
||||
|
||||
private final IPqScriptService pqScriptService;
|
||||
private final IPqErrSysService pqErrSysService;
|
||||
private final IAdPlanSourceService adPlanSourceService;
|
||||
private final IPqDevService pqDevService;
|
||||
private final IDictDataService dictDataService;
|
||||
private final IPqSourceService pqSourceService;
|
||||
private final IPqScriptDtlsService pqScriptDtlsService;
|
||||
private final IDictTreeService dictTreeService;
|
||||
|
||||
@Override
|
||||
public Page<AdPlanVO> listAdPlan(AdPlanParam.QueryParam queryParam) {
|
||||
Page<AdPlan> page1 = this.page(new Page<>(PageFactory.getPageNum(queryParam), PageFactory.getPageSize(queryParam)), this.getQueryWrapper(queryParam));
|
||||
List<AdPlan> adPlans = page1.getRecords();
|
||||
List<AdPlanVO> adPlanVOList = adPlans.stream().map(adPlan -> {
|
||||
AdPlanVO adPlanVO = new AdPlanVO();
|
||||
BeanUtil.copyProperties(adPlan, adPlanVO);
|
||||
adPlanVO.setDatasourceIds(Arrays.asList(adPlan.getDatasourceId().split(StrUtil.COMMA)));
|
||||
return adPlanVO;
|
||||
}).collect(Collectors.toList());
|
||||
adPlanVOList.forEach(adPlanVO -> {
|
||||
adPlanVO.setScriptName(pqScriptService.getPqScriptById(adPlanVO.getScriptId()).getName());
|
||||
adPlanVO.setErrorSysName(pqErrSysService.getPqErrSysById(adPlanVO.getErrorSysId()).getName());
|
||||
|
||||
List<PqSource> pqSourceList = adPlanSourceService.listPqSourceByPlanId(adPlanVO.getId());
|
||||
adPlanVO.setSourceIds(pqSourceList.stream().map(PqSource::getId).collect(Collectors.toList()));
|
||||
adPlanVO.setSourceName(pqSourceList.stream().map(PqSource::getName).collect(Collectors.toList()));
|
||||
});
|
||||
|
||||
Page<AdPlanVO> page2 = new Page<>(PageFactory.getPageNum(queryParam), PageFactory.getPageSize(queryParam));
|
||||
page2.setTotal(page1.getTotal());
|
||||
page2.setOrders(page1.orders());
|
||||
page2.setPages(page1.getPages());
|
||||
page2.setRecords(adPlanVOList);
|
||||
return page2;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public boolean addAdPlan(AdPlanParam param) {
|
||||
AdPlan adPlan = new AdPlan();
|
||||
BeanUtil.copyProperties(param, adPlan);
|
||||
|
||||
String planId = UUID.randomUUID().toString().replaceAll("-", "");
|
||||
adPlan.setId(planId);
|
||||
adPlan.setDatasourceId(String.join(StrUtil.COMMA, param.getDatasourceIds()));
|
||||
|
||||
adPlan.setState(DataStateEnum.ENABLE.getCode());
|
||||
// 默认为顶级检测计划
|
||||
adPlan.setFatherPlanId(CommonEnum.FATHER_ID.getValue());
|
||||
adPlan.setTestState(CheckStateEnum.UNCHECKED.getValue());
|
||||
adPlan.setReportState(PlanReportStateEnum.REPORT_STATE_NOT_GENERATED.getValue());
|
||||
adPlan.setResult(CheckResultEnum.UNCHECKED.getValue());
|
||||
// todo code 生成
|
||||
// 日期生成 MMdd
|
||||
//String dateStr = DateFormatUtils.format(new Date(), "MMdd");
|
||||
adPlan.setCode(this.generateCode());
|
||||
|
||||
// 新增检测计划、检测源关联
|
||||
adPlanSourceService.addAdPlanSource(planId, param.getSourceIds());
|
||||
if (ObjectUtil.isNotEmpty(param.getDevIds())) {
|
||||
// 新增时,绑定设备
|
||||
pqDevService.bind(planId, param.getDevIds());
|
||||
|
||||
// 守时检测
|
||||
pqDevService.updatePqDevTimeCheckResult(param.getDevIds(), TimeCheckResultEnum.UNKNOWN);
|
||||
}
|
||||
|
||||
return this.save(adPlan);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public boolean updateAdPlan(AdPlanParam.UpdateParam param) {
|
||||
AdPlan adPlan = new AdPlan();
|
||||
BeanUtil.copyProperties(param, adPlan);
|
||||
|
||||
adPlan.setDatasourceId(String.join(StrUtil.COMMA, param.getDatasourceIds()));
|
||||
|
||||
// 修改检测计划、检测源关联
|
||||
adPlanSourceService.updateAdPlanSource(param.getId(), param.getSourceIds());
|
||||
|
||||
pqDevService.bind(param.getId(), param.getDevIds());
|
||||
|
||||
return this.updateById(adPlan);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public boolean deleteAdPlan(List<String> ids) {
|
||||
for (String id : ids) {
|
||||
PqDevParam.QueryParam queryParam = new PqDevParam.QueryParam();
|
||||
queryParam.setPlanId(id);
|
||||
if (ObjectUtils.isNotEmpty(pqDevService.listByPlanId(queryParam))) {
|
||||
throw new BusinessException(DevResponseEnum.PLAN_HAS_DEVICE_BIND);
|
||||
}
|
||||
}
|
||||
// 删除检测计划、检测源关联
|
||||
adPlanSourceService.deleteAdPlanSourceByPlanIds(ids);
|
||||
|
||||
return this.lambdaUpdate().in(AdPlan::getId, ids).set(AdPlan::getState, DataStateEnum.DELETED.getCode()).update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> listByPattern(String pattern) {
|
||||
List<AdPlan> adPlanList = this.lambdaQuery().eq(AdPlan::getPattern, pattern).eq(AdPlan::getState, DataStateEnum.ENABLE.getCode()).list();
|
||||
Map<Integer, List<AdPlan>> map1 = adPlanList.stream().collect(Collectors.groupingBy(AdPlan::getTestState));
|
||||
|
||||
List<Map<String, Object>> result = new ArrayList<>();
|
||||
|
||||
for (CheckStateEnum checkStateEnum : CheckStateEnum.values()) {
|
||||
// 检测计划的检测状态中没有 归档 状态
|
||||
if (checkStateEnum.getValue() == CheckStateEnum.DOCUMENTED.getValue()) {
|
||||
continue;
|
||||
}
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("name", checkStateEnum.getMsg());
|
||||
List<Map<String, Object>> children = new ArrayList<>();
|
||||
if (map1.containsKey(checkStateEnum.getValue())) {
|
||||
map1.get(checkStateEnum.getValue()).forEach(adPlan -> {
|
||||
Map<String, Object> child = new HashMap<>();
|
||||
child.put("id", adPlan.getId());
|
||||
child.put("scriptId", adPlan.getScriptId());
|
||||
child.put("errorSysId", adPlan.getErrorSysId());
|
||||
child.put("code", adPlan.getCode());
|
||||
child.put("pid", adPlan.getFatherPlanId());
|
||||
child.put("name", adPlan.getName());
|
||||
child.put("timeCheck", adPlan.getTimeCheck());
|
||||
children.add(child);
|
||||
});
|
||||
}
|
||||
map.put("children", children);
|
||||
result.add(map);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downloadTemplate() {
|
||||
ExcelUtil.exportExcel("检测计划模板.xlsx", AdPlanExcel.ImportData.class, Collections.emptyList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AdPlanExcel.ExportData> getExportData(AdPlanParam.QueryParam queryParam) {
|
||||
List<AdPlan> planList = this.list(this.getQueryWrapper(queryParam));
|
||||
this.visualize(planList);
|
||||
List<AdPlanExcel.ExportData> planExcelList = BeanUtil.copyToList(planList, AdPlanExcel.ExportData.class);
|
||||
for (int i = 0; i < planList.size(); i++) {
|
||||
List<PqSource> pqSources = adPlanSourceService.listPqSourceByPlanId(planList.get(i).getId());
|
||||
planExcelList.get(i).setSource(pqSources.stream().map(PqSource::getName).collect(Collectors.joining(StrUtil.COMMA)));
|
||||
|
||||
PqDevParam.QueryParam queryParam1 = new PqDevParam.QueryParam();
|
||||
queryParam1.setPlanId(planList.get(i).getId());
|
||||
List<PqDev> pqDevs = pqDevService.listByPlanId(queryParam1);
|
||||
pqDevService.visualize(pqDevs);
|
||||
planExcelList.get(i).setDevices(BeanUtil.copyToList(pqDevs, AdPlanExcel.BoundExportData.class));
|
||||
}
|
||||
return planExcelList;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void importData(String patternId, List<AdPlanExcel.ImportData> adPlanExcelList) {
|
||||
List<AdPlan> adPlans = BeanUtil.copyToList(adPlanExcelList, AdPlan.class);
|
||||
List<PqDev> devList = new ArrayList<>();
|
||||
|
||||
String patternCode = dictDataService.getDictDataById(patternId).getCode();
|
||||
for (int i = 0; i < adPlans.size(); i++) {
|
||||
|
||||
AdPlanExcel.ImportData adPlanExcel = adPlanExcelList.get(i);
|
||||
String planId = UUID.randomUUID().toString().replaceAll("-", "");
|
||||
adPlans.get(i).setId(planId);
|
||||
adPlans.get(i).setPattern(patternId);
|
||||
|
||||
String source = adPlanExcel.getSource();
|
||||
String[] sourceNames = source.split(StrUtil.COMMA);
|
||||
// 若非比对模式,检测源、数据源有2个以上时,不导入
|
||||
if (!PatternEnum.CONTRAST.getValue().equals(patternCode) && sourceNames.length > 1) {
|
||||
throw new BusinessException(DevResponseEnum.IMPORT_SOURCE_ERROR);
|
||||
}
|
||||
|
||||
String datasource = adPlanExcel.getDatasourceId();
|
||||
String[] datasourceIds = datasource.split(StrUtil.COMMA);
|
||||
// 若非比对模式,数据源有2个以上时,不导入
|
||||
if (!PatternEnum.CONTRAST.getValue().equals(patternCode) && datasourceIds.length > 1) {
|
||||
throw new BusinessException(DevResponseEnum.IMPORT_DATASOURCE_ERROR);
|
||||
}
|
||||
|
||||
List<String> sourceIds = pqSourceService.listPqSourceIdByName(sourceNames);
|
||||
adPlanSourceService.addAdPlanSource(planId, sourceIds);
|
||||
|
||||
List<PqDev> pqDevs = adPlanExcel.getDevices().stream()
|
||||
.map(planExcel -> {
|
||||
PqDev dev = new PqDev();
|
||||
BeanUtil.copyProperties(planExcel, dev);
|
||||
dev.setPlanId(planId);
|
||||
dev.setPattern(patternId);
|
||||
return dev;
|
||||
}).collect(Collectors.toList());
|
||||
devList.addAll(pqDevs);
|
||||
}
|
||||
// 逆向可视化
|
||||
this.reverseVisualize(adPlans);
|
||||
this.saveBatch(adPlans);
|
||||
|
||||
pqDevService.reverseVisualize(devList);
|
||||
pqDevService.saveBatch(devList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取查询条件wrapper
|
||||
*
|
||||
* @param queryParam 查询条件
|
||||
* @return
|
||||
*/
|
||||
private Wrapper getQueryWrapper(AdPlanParam.QueryParam queryParam) {
|
||||
QueryWrapper<AdPlan> queryWrapper = new QueryWrapper<>();
|
||||
if (ObjectUtil.isNotNull(queryParam)) {
|
||||
queryWrapper.eq(StrUtil.isNotBlank(queryParam.getPattern()), "ad_plan.pattern", queryParam.getPattern()).eq(StrUtil.isNotBlank(queryParam.getName()), "ad_plan.name", queryParam.getName()).eq(ObjectUtil.isNotNull(queryParam.getTestState()), "ad_plan.Test_State", queryParam.getTestState()).eq(ObjectUtil.isNotNull(queryParam.getReportState()), "ad_plan.Report_State", queryParam.getReportState()).eq(ObjectUtil.isNotNull(queryParam.getResult()), "ad_plan.result", queryParam.getResult());
|
||||
}
|
||||
queryWrapper.eq("ad_plan.state", DataStateEnum.ENABLE.getCode()).orderBy(true, true, "Create_Time");
|
||||
return queryWrapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visualize(List<AdPlan> planList) {
|
||||
planList.forEach(adPlan -> {
|
||||
// if (StrUtil.isNotBlank(adPlan.getPattern())) {
|
||||
// adPlan.setPattern(dictDataService.getDictDataById(adPlan.getPattern()).getName());
|
||||
// }
|
||||
// if (CommonEnum.FATHER_ID.getValue().equals(adPlan.getFatherPlanId())) {
|
||||
// adPlan.setFatherPlanId(CommonEnum.FATHER_ID.getMsg());
|
||||
// } else {
|
||||
// adPlan.setFatherPlanId(this.getById(adPlan.getFatherPlanId()).getName());
|
||||
// }
|
||||
if (StrUtil.isNotBlank(adPlan.getDatasourceId())) {
|
||||
String[] datasourceIds = adPlan.getDatasourceId().split(StrUtil.COMMA);
|
||||
adPlan.setDatasourceId(Arrays.stream(datasourceIds).map(id -> DataSourceEnum.getMsgByValue(id)).collect(Collectors.joining(StrUtil.COMMA)));
|
||||
}
|
||||
if (StrUtil.isNotBlank(adPlan.getScriptId())) {
|
||||
String[] scriptIds = adPlan.getScriptId().split(StrUtil.COMMA);
|
||||
adPlan.setScriptId(Arrays.stream(scriptIds).map(id -> pqScriptService.getPqScriptById(id).getName()).collect(Collectors.joining(StrUtil.COMMA)));
|
||||
}
|
||||
if (StrUtil.isNotBlank(adPlan.getErrorSysId())) {
|
||||
adPlan.setErrorSysId(pqErrSysService.getPqErrSysById(adPlan.getErrorSysId()).getName());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map<String, String>> getBigTestItem(String planId) {
|
||||
List<Map<String, String>> result = new ArrayList<>();
|
||||
AdPlan adPlan = this.getById(planId);
|
||||
String scriptId = adPlan.getScriptId();
|
||||
|
||||
List<PqScriptDtls> scriptDtlsList = pqScriptDtlsService.listPqScriptDtlByScriptId(scriptId);
|
||||
|
||||
Map<String, List<PqScriptDtls>> collect = scriptDtlsList.stream()
|
||||
.sorted(Comparator.comparing(PqScriptDtls::getIndex))
|
||||
.collect(Collectors.groupingBy(PqScriptDtls::getScriptType, LinkedHashMap::new, Collectors.toList()));
|
||||
|
||||
collect.forEach((key, value) -> {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("id", key);
|
||||
DictTree dictTree = dictTreeService.getById(key);
|
||||
map.put("code", dictTree.getCode());
|
||||
map.put("scriptName", dictTree.getName());
|
||||
result.add(map);
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 逆向可视化
|
||||
*
|
||||
* @param planList 检测计划列表
|
||||
*/
|
||||
private void reverseVisualize(List<AdPlan> planList) {
|
||||
planList.forEach(adPlan -> {
|
||||
String[] datasourceIds = adPlan.getDatasourceId().split(StrUtil.COMMA);
|
||||
adPlan.setDatasourceId(Arrays.stream(datasourceIds).map(id -> DataSourceEnum.getValueByMsg(id)).collect(Collectors.joining(StrUtil.COMMA)));
|
||||
|
||||
adPlan.setScriptId(pqScriptService.getPqScriptByName(adPlan.getScriptId()).getId());
|
||||
|
||||
adPlan.setErrorSysId(pqErrSysService.getPqErrSysByName(adPlan.getErrorSysId()).getId());
|
||||
adPlan.setCode(this.generateCode());
|
||||
|
||||
adPlan.setState(DataStateEnum.ENABLE.getCode());
|
||||
// 默认为顶级检测计划
|
||||
adPlan.setFatherPlanId(CommonEnum.FATHER_ID.getValue());
|
||||
adPlan.setTestState(CheckStateEnum.UNCHECKED.getValue());
|
||||
adPlan.setReportState(PlanReportStateEnum.REPORT_STATE_NOT_GENERATED.getValue());
|
||||
adPlan.setResult(CheckResultEnum.UNCHECKED.getValue());
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成code
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private Integer generateCode() {
|
||||
return this.count() + 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.njcn.gather.plan.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.gather.plan.mapper.AdPlanSourceMapper;
|
||||
import com.njcn.gather.plan.pojo.po.AdPlanSource;
|
||||
import com.njcn.gather.plan.service.IAdPlanSourceService;
|
||||
import com.njcn.gather.device.source.pojo.po.PqSource;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024-12-09
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class AdPlanSourceServiceImpl extends ServiceImpl<AdPlanSourceMapper, AdPlanSource> implements IAdPlanSourceService {
|
||||
|
||||
private final AdPlanSourceMapper adPlanSourceMapper;
|
||||
|
||||
@Override
|
||||
public List<PqSource> listPqSourceByPlanId(String planId) {
|
||||
return adPlanSourceMapper.selectPqSourceByPlanId(planId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public boolean addAdPlanSource(String planId, List<String> sourceIds) {
|
||||
List<AdPlanSource> adPlanSourceList = new ArrayList<>();
|
||||
for (String sourceId : sourceIds) {
|
||||
adPlanSourceList.add(new AdPlanSource(planId, sourceId));
|
||||
}
|
||||
return this.saveBatch(adPlanSourceList);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public boolean deleteAdPlanSourceByPlanIds(List<String> planIds) {
|
||||
QueryWrapper<AdPlanSource> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.in("ad_plan_source.Plan_Id", planIds);
|
||||
return this.remove(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public boolean updateAdPlanSource(String planId, List<String> sourceIds) {
|
||||
this.deleteAdPlanSourceByPlanIds(Collections.singletonList(planId));
|
||||
this.addAdPlanSource(planId, sourceIds);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.njcn.gather.result.controller;
|
||||
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.LogUtil;
|
||||
import com.njcn.gather.result.pojo.param.ResultParam;
|
||||
import com.njcn.gather.result.pojo.vo.FormContentVO;
|
||||
import com.njcn.gather.result.pojo.vo.TreeDataVO;
|
||||
import com.njcn.gather.result.service.IResultService;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import com.njcn.web.utils.HttpResultUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2024-12-30
|
||||
*/
|
||||
@Slf4j
|
||||
@Api(tags = "检测结果")
|
||||
@RestController
|
||||
@RequestMapping("/result")
|
||||
@RequiredArgsConstructor
|
||||
public class ResultController extends BaseController {
|
||||
private final IResultService resultService;
|
||||
|
||||
@OperateInfo
|
||||
@PostMapping("/formContent")
|
||||
@ApiOperation("查询检测结果-表单内容")
|
||||
@ApiImplicitParam(name = "queryParam", value = "查询参数", required = true)
|
||||
public HttpResult<FormContentVO> formContent(@RequestBody @Validated ResultParam.QueryParam queryParam) {
|
||||
String methodDescribe = getMethodDescribe("formContent");
|
||||
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, queryParam);
|
||||
FormContentVO result = resultService.getFormContent(queryParam);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo
|
||||
@PostMapping("/treeData")
|
||||
@ApiOperation("查询检测结果-树形结构的具体检测项")
|
||||
@ApiImplicitParam(name = "queryParam", value = "查询参数", required = true)
|
||||
public HttpResult<List<TreeDataVO>> treeData(@RequestBody @Validated ResultParam queryParam) {
|
||||
String methodDescribe = getMethodDescribe("treeData");
|
||||
List<TreeDataVO> infoVOS = resultService.treeData(queryParam);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, infoVOS, methodDescribe);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.njcn.gather.result.pojo.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2024/11/9
|
||||
*/
|
||||
@Getter
|
||||
public enum ResultUnitEnum {
|
||||
|
||||
FREQ_UNIT("Hz", "频率"),
|
||||
V_RELATIVE_UNIT("%Un", "电压"),
|
||||
V_ABSOLUTELY_UNIT("V", "电压"),
|
||||
I_RELATIVE_UNIT("%In", "电流"),
|
||||
I_ABSOLUTELY_UNIT("A", "电流"),
|
||||
HV_UNIT("%", "谐波电压"),
|
||||
HI_UNIT("%", "谐波电流"),
|
||||
HP_UNIT("W", "谐波有功功率"),
|
||||
HSV_UNIT("%", "间谐波电压"),
|
||||
HSI_UNIT("%", "间谐波电流"),
|
||||
VOLTAGE_MAG_UNIT("周波", "暂态持续时间"),
|
||||
VOLTAGE_DUR_UNIT("%", "暂态深度"),
|
||||
IMBV_UNIT("%", "电压不平衡度"),
|
||||
IMBA_UNIT("%", "电流不平衡度"),
|
||||
|
||||
;
|
||||
|
||||
private String unit;
|
||||
private String name;
|
||||
|
||||
ResultUnitEnum(String unit, String name) {
|
||||
this.unit = unit;
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.njcn.gather.result.pojo.param;
|
||||
|
||||
import com.njcn.common.pojo.constant.PatternRegex;
|
||||
import com.njcn.gather.device.pojo.constant.DevValidMessage;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Pattern;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2024-12-30
|
||||
*/
|
||||
@Data
|
||||
public class ResultParam {
|
||||
|
||||
/**
|
||||
* 检测大相信息
|
||||
*/
|
||||
private String scriptType;
|
||||
|
||||
/**
|
||||
* 检测脚本id
|
||||
*/
|
||||
private String scriptId;
|
||||
|
||||
/**
|
||||
* 装置id
|
||||
*/
|
||||
private String devId;
|
||||
|
||||
/**
|
||||
* 装置通道
|
||||
*/
|
||||
private String devNum;
|
||||
|
||||
/**
|
||||
* 自动生成,用于生成数据表后缀
|
||||
*/
|
||||
private Integer code;
|
||||
|
||||
@Data
|
||||
public static class QueryParam {
|
||||
|
||||
@ApiModelProperty(value = "检测计划Id", required = true)
|
||||
@NotBlank(message = DevValidMessage.PLAN_ID_NOT_NULL)
|
||||
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.PLAN_ID_FORMAT_ERROR)
|
||||
private String planId;
|
||||
|
||||
// 脚本类型,当为null时,表示查询所有脚本类型,否则只查询指定脚本类型
|
||||
private String scriptType;
|
||||
|
||||
@ApiModelProperty(value = "设备Id", required = true)
|
||||
@NotBlank(message = DevValidMessage.DEV_ID_NOT_BLANK)
|
||||
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.DEV_ID_FORMAT_ERROR)
|
||||
private String deviceId;
|
||||
|
||||
// 通道号,当为-1时,表示查询所有通道号,否则只查询指定通道号
|
||||
private String chnNum;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.njcn.gather.result.pojo.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2024-12-30
|
||||
*/
|
||||
@Data
|
||||
public class FormContentVO {
|
||||
|
||||
private String scriptName;
|
||||
|
||||
private String errorSysName;
|
||||
|
||||
private String dataRule;
|
||||
|
||||
private String deviceName;
|
||||
|
||||
private List<Map<String, String>> chnList;
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
package com.njcn.gather.result.pojo.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2024-12-31
|
||||
*/
|
||||
@Data
|
||||
public class ResultVO {
|
||||
|
||||
/**
|
||||
* 结果数据
|
||||
*/
|
||||
private List<ResultData> resultData;
|
||||
|
||||
|
||||
/**
|
||||
* 原始数据
|
||||
*/
|
||||
private List<RawData> rawData;
|
||||
|
||||
@Data
|
||||
public static class RawData {
|
||||
|
||||
/**
|
||||
* 时间
|
||||
*/
|
||||
private String time;
|
||||
|
||||
|
||||
/**
|
||||
* (间)谐波次数
|
||||
*/
|
||||
private Double harmNum;
|
||||
|
||||
/**
|
||||
* A相数据
|
||||
*/
|
||||
private BigDecimal dataA;
|
||||
|
||||
/**
|
||||
* B相数据
|
||||
*/
|
||||
private BigDecimal dataB;
|
||||
|
||||
/**
|
||||
* C相数据
|
||||
*/
|
||||
private BigDecimal dataC;
|
||||
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class ResultData {
|
||||
|
||||
|
||||
/**
|
||||
* 类别
|
||||
*/
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* (间)谐波次数
|
||||
*/
|
||||
private Double harmNum;
|
||||
|
||||
/**
|
||||
* A相数据
|
||||
*/
|
||||
private BigDecimal DevDataA;
|
||||
private BigDecimal SourceDataA;
|
||||
|
||||
/**
|
||||
* B相数据
|
||||
*/
|
||||
private BigDecimal DevDataB;
|
||||
private BigDecimal SourceDataB;
|
||||
|
||||
/**
|
||||
* C相数据
|
||||
*/
|
||||
private BigDecimal DevDataC;
|
||||
private BigDecimal SourceDataC;
|
||||
|
||||
/**
|
||||
* T相数据
|
||||
*/
|
||||
private BigDecimal DevDataT;
|
||||
private BigDecimal SourceDataT;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.njcn.gather.result.pojo.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author wr
|
||||
* @description
|
||||
* @date 2024/12/31 15:00
|
||||
*/
|
||||
@Data
|
||||
public class TreeDataVO {
|
||||
|
||||
/**
|
||||
* 检测项目名称
|
||||
*/
|
||||
private String scriptTypeName;
|
||||
/**
|
||||
* 测试相
|
||||
*/
|
||||
private Integer index;
|
||||
/**
|
||||
* 是否检测合格
|
||||
*/
|
||||
private Integer fly;
|
||||
|
||||
/**
|
||||
* 检测信息集合
|
||||
*/
|
||||
private List<TreeDataVO> children;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.njcn.gather.result.service;
|
||||
|
||||
import com.njcn.gather.result.pojo.param.ResultParam;
|
||||
import com.njcn.gather.result.pojo.vo.FormContentVO;
|
||||
import com.njcn.gather.result.pojo.vo.ResultVO;
|
||||
import com.njcn.gather.result.pojo.vo.TreeDataVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2024-12-30
|
||||
*/
|
||||
public interface IResultService {
|
||||
/**
|
||||
* 检测详情表单头
|
||||
* @param queryParam
|
||||
* @return
|
||||
*/
|
||||
FormContentVO getFormContent(ResultParam.QueryParam queryParam);
|
||||
|
||||
|
||||
/**
|
||||
* 获取检测详情信息
|
||||
* @param param
|
||||
* @return: java.util.List<com.njcn.gather.result.pojo.vo.DetectionInfoVO>
|
||||
* @Author: wr
|
||||
* @Date: 2024/12/31 15:14
|
||||
*/
|
||||
List<TreeDataVO> treeData(ResultParam param);
|
||||
|
||||
/**
|
||||
* 展示结果数据
|
||||
* @param param
|
||||
* @return
|
||||
*/
|
||||
ResultVO resultData(ResultParam param);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,307 @@
|
||||
package com.njcn.gather.result.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||
import com.njcn.common.pojo.enums.common.DataStateEnum;
|
||||
import com.njcn.gather.device.device.pojo.vo.PqDevVO;
|
||||
import com.njcn.gather.device.device.service.IPqDevService;
|
||||
import com.njcn.gather.device.script.mapper.PqScriptMapper;
|
||||
import com.njcn.gather.device.script.pojo.po.PqScriptDtls;
|
||||
import com.njcn.gather.device.script.service.IPqScriptDtlsService;
|
||||
import com.njcn.gather.plan.pojo.po.AdPlan;
|
||||
import com.njcn.gather.plan.service.IAdPlanService;
|
||||
import com.njcn.gather.result.pojo.enums.ResultUnitEnum;
|
||||
import com.njcn.gather.result.pojo.param.ResultParam;
|
||||
import com.njcn.gather.result.pojo.vo.FormContentVO;
|
||||
import com.njcn.gather.result.pojo.vo.ResultVO;
|
||||
import com.njcn.gather.result.pojo.vo.TreeDataVO;
|
||||
import com.njcn.gather.result.service.IResultService;
|
||||
import com.njcn.gather.storage.pojo.po.AdBaseResult;
|
||||
import com.njcn.gather.storage.service.AdHarmonicService;
|
||||
import com.njcn.gather.storage.service.AdNonHarmonicService;
|
||||
import com.njcn.gather.system.config.service.ISysTestConfigService;
|
||||
import com.njcn.gather.system.dictionary.pojo.po.DictTree;
|
||||
import com.njcn.gather.system.dictionary.service.IDictTreeService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2024-12-30
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ResultServiceImpl implements IResultService {
|
||||
|
||||
private final IAdPlanService adPlanService;
|
||||
private final ISysTestConfigService sysTestConfigService;
|
||||
private final IPqDevService pqDevService;
|
||||
private final AdNonHarmonicService adNonHarmonicService;
|
||||
private final AdHarmonicService adHarmonicService;
|
||||
private final IPqScriptDtlsService pqScriptDtlsService;
|
||||
private final PqScriptMapper scriptMapper;
|
||||
private final IDictTreeService dictTreeService;
|
||||
|
||||
/**
|
||||
* 谐波类code,取树形字典表中的code
|
||||
*/
|
||||
private final List<String> HARMONIC_TYPE_CODE = Arrays.asList("HV", "HI", "HP", "HSV", "HSI");
|
||||
|
||||
|
||||
@Override
|
||||
public FormContentVO getFormContent(ResultParam.QueryParam queryParam) {
|
||||
FormContentVO formContentVO = new FormContentVO();
|
||||
AdPlan plan = adPlanService.getById(queryParam.getPlanId());
|
||||
String scriptId = null;
|
||||
if (ObjectUtil.isNotNull(plan)) {
|
||||
scriptId = plan.getScriptId();
|
||||
adPlanService.visualize(Collections.singletonList(plan));
|
||||
}
|
||||
formContentVO.setScriptName(plan.getScriptId());
|
||||
formContentVO.setErrorSysName(plan.getErrorSysId());
|
||||
formContentVO.setDataRule(sysTestConfigService.getConfig().getDataRule());
|
||||
formContentVO.setDeviceName(pqDevService.getById(queryParam.getDeviceId()).getName());
|
||||
|
||||
List<Map<String, String>> chnList = new ArrayList<>();
|
||||
|
||||
List<AdBaseResult> allResultList = new ArrayList<>();
|
||||
//只查询指定的脚本类型
|
||||
if (ObjectUtil.isNotNull(queryParam.getScriptType())) {
|
||||
List<Integer> indexList = pqScriptDtlsService.getIndexList(queryParam.getScriptType(), scriptId);
|
||||
DictTree dictTree = dictTreeService.getById(queryParam.getScriptType());
|
||||
|
||||
if (HARMONIC_TYPE_CODE.contains(dictTree.getCode())) {
|
||||
allResultList.addAll(adHarmonicService.get(scriptId, indexList, queryParam.getDeviceId(), queryParam.getChnNum(), plan.getCode()));
|
||||
} else {
|
||||
allResultList.addAll(adNonHarmonicService.get(scriptId, indexList, queryParam.getDeviceId(), queryParam.getChnNum(), plan.getCode()));
|
||||
}
|
||||
} else { //查询所有的脚本类型
|
||||
allResultList.addAll(adHarmonicService.get(scriptId, null, queryParam.getDeviceId(), queryParam.getChnNum(), plan.getCode()));
|
||||
allResultList.addAll(adNonHarmonicService.get(scriptId, null, queryParam.getDeviceId(), queryParam.getChnNum(), plan.getCode()));
|
||||
}
|
||||
|
||||
if (ObjectUtil.isNotEmpty(allResultList)) {
|
||||
Map<String, List<AdBaseResult>> chnMap = allResultList.stream().collect(
|
||||
Collectors.groupingBy(obj -> obj.getMonitorId().substring(obj.getMonitorId().lastIndexOf("_") + 1))
|
||||
);
|
||||
chnMap.forEach((chn, list) -> {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("value", chn);
|
||||
long count = list.stream().filter(obj -> obj.getResultFlag() == 0).count();
|
||||
map.put("label", count > 0 ? "0" : "1");
|
||||
chnList.add(map);
|
||||
});
|
||||
}
|
||||
|
||||
chnList.sort(Comparator.comparingInt(o -> Integer.parseInt(o.get("value"))));
|
||||
formContentVO.setChnList(chnList);
|
||||
return formContentVO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TreeDataVO> treeData(ResultParam param) {
|
||||
//根据所有的检测脚本查询出检测信息
|
||||
List<PqScriptDtls> dtlsList = pqScriptDtlsService.list(new MPJLambdaWrapper<PqScriptDtls>()
|
||||
.selectAll(PqScriptDtls.class)
|
||||
.eq(StrUtil.isNotBlank(param.getScriptId()), PqScriptDtls::getScriptId, param.getScriptId())
|
||||
.eq(StrUtil.isNotBlank(param.getScriptType()), PqScriptDtls::getScriptType, param.getScriptType())
|
||||
.ne(PqScriptDtls::getIndex, -1)
|
||||
.eq(PqScriptDtls::getEnable, DataStateEnum.ENABLE.getCode()));
|
||||
List<AdBaseResult> allResultList = new ArrayList<>();
|
||||
List<Integer> indexList = new ArrayList<>();
|
||||
if (StrUtil.isNotBlank(param.getScriptType())) {
|
||||
indexList = pqScriptDtlsService.getIndexList(param.getScriptType(), param.getScriptId());
|
||||
}
|
||||
allResultList.addAll(adNonHarmonicService.get(param.getScriptId(), indexList, param.getDevId(), param.getDevNum(), param.getCode()));
|
||||
allResultList.addAll(adHarmonicService.get(param.getScriptId(), indexList, param.getDevId(), param.getDevNum(), param.getCode()));
|
||||
Map<Integer, Set<Integer>> resultMap = new HashMap<>(5);
|
||||
if (CollUtil.isNotEmpty(allResultList)) {
|
||||
resultMap = allResultList.stream().collect(Collectors.groupingBy(AdBaseResult::getSort, Collectors.mapping(AdBaseResult::getResultFlag, Collectors.toSet())));
|
||||
}
|
||||
|
||||
Map<String, List<PqScriptDtls>> dtlsSortMap = dtlsList.stream()
|
||||
.sorted(Comparator.comparing(PqScriptDtls::getIndex))
|
||||
.collect(Collectors.groupingBy(PqScriptDtls::getScriptType, LinkedHashMap::new, Collectors.toList()));
|
||||
List<DictTree> dictTreeById = dictTreeService.getDictTreeById(new ArrayList<>(dtlsSortMap.keySet()));
|
||||
|
||||
Map<String, DictTree> dictTreeMap = dictTreeById.stream().collect(Collectors.toMap(DictTree::getId, Function.identity()));
|
||||
Map<String, String> subName = new LinkedHashMap<>();
|
||||
subName.put("Base", "额定工作条件下的测量");
|
||||
subName.put("VOL", "电压对XX测量的影响");
|
||||
subName.put("Freq", "频率对XX测量的影响");
|
||||
subName.put("Harm", "谐波对XX测量的影响");
|
||||
Boolean isValueType = scriptMapper.selectScriptIsValueType(param.getScriptId());
|
||||
PqDevVO dev = pqDevService.getPqDevById(param.getDevId());
|
||||
|
||||
List<TreeDataVO> infoVOS = new ArrayList<>();
|
||||
Map<Integer, Set<Integer>> finalResultMap = resultMap;
|
||||
dtlsSortMap.forEach((key, value) -> {
|
||||
DictTree dictTree = dictTreeMap.get(key);
|
||||
if (ObjectUtil.isNotNull(dictTree)) {
|
||||
List<TreeDataVO> scriptSubList = new ArrayList<>();
|
||||
|
||||
LinkedHashMap<String, List<PqScriptDtls>> subTypeMap = value.stream()
|
||||
.sorted(Comparator.comparing(PqScriptDtls::getIndex))
|
||||
.collect(Collectors.groupingBy(PqScriptDtls::getScriptSubType, LinkedHashMap::new, Collectors.toList()));
|
||||
subTypeMap.forEach((subKey, subValue) -> {
|
||||
List<TreeDataVO> scriptDlsList = new ArrayList<>();
|
||||
//根据index进行分组统计小相检测信息
|
||||
LinkedHashMap<Integer, List<PqScriptDtls>> indexMap = subValue.stream()
|
||||
.sorted(Comparator.comparing(PqScriptDtls::getIndex))
|
||||
.collect(Collectors.groupingBy(PqScriptDtls::getIndex, LinkedHashMap::new, Collectors.toList()));
|
||||
indexMap.forEach((index, scriptDtlIndex) -> {
|
||||
|
||||
if (finalResultMap.containsKey(index)) {
|
||||
Set<Integer> nums = finalResultMap.get(index);
|
||||
TreeDataVO childInfo = new TreeDataVO();
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("输入:");
|
||||
List<PqScriptDtls> freq = scriptDtlIndex.stream().filter(x -> "Freq".equals(x.getValueType())).collect(Collectors.toList());
|
||||
if (CollUtil.isNotEmpty(freq)) {
|
||||
buffer.append("频率=" + freq.get(0).getValue() + ResultUnitEnum.FREQ_UNIT.getUnit() + " ");
|
||||
}
|
||||
List<PqScriptDtls> vol = scriptDtlIndex.stream().filter(x -> "VOL".equals(x.getValueType()))
|
||||
.sorted(Comparator.comparing(PqScriptDtls::getPhase)).collect(Collectors.toList());
|
||||
if (CollUtil.isNotEmpty(vol)) {
|
||||
Float unit = 1f;
|
||||
if (isValueType) {
|
||||
unit = dev.getDevVolt();
|
||||
}
|
||||
for (PqScriptDtls dtls : vol) {
|
||||
BigDecimal volValue = new BigDecimal(dtls.getValue());
|
||||
BigDecimal result = volValue.divide(new BigDecimal(100), 2, BigDecimal.ROUND_HALF_UP)
|
||||
.multiply(new BigDecimal(unit.toString()));
|
||||
buffer.append("U" + dtls.getPhase().toLowerCase() + "=" + result.doubleValue() + ResultUnitEnum.V_ABSOLUTELY_UNIT.getUnit()
|
||||
+ ",相角=" + dtls.getAngle() + "° ");
|
||||
}
|
||||
|
||||
}
|
||||
List<PqScriptDtls> cur = scriptDtlIndex.stream().filter(x -> "CUR".equals(x.getValueType()))
|
||||
.sorted(Comparator.comparing(PqScriptDtls::getPhase))
|
||||
.collect(Collectors.toList());
|
||||
if (CollUtil.isNotEmpty(cur)) {
|
||||
Float unit = 1f;
|
||||
if (isValueType) {
|
||||
unit = dev.getDevCurr();
|
||||
}
|
||||
for (PqScriptDtls dtls : cur) {
|
||||
BigDecimal volValue = new BigDecimal(dtls.getValue());
|
||||
BigDecimal result = volValue.divide(new BigDecimal(100), 2, BigDecimal.ROUND_HALF_UP)
|
||||
.multiply(new BigDecimal(unit.toString()));
|
||||
buffer.append("I" + dtls.getPhase().toLowerCase() + "=" + result.doubleValue() + ResultUnitEnum.I_ABSOLUTELY_UNIT.getUnit()
|
||||
+ ",相角=" + dtls.getAngle() + "° ");
|
||||
}
|
||||
}
|
||||
dtlsSetBuffer(scriptDtlIndex, buffer, "Harm_V", "h", ResultUnitEnum.HV_UNIT.getUnit(), true);
|
||||
dtlsSetBuffer(scriptDtlIndex, buffer, "Harm_I", "h", ResultUnitEnum.HI_UNIT.getUnit(), true);
|
||||
dtlsSetBuffer(scriptDtlIndex, buffer, "InHarm_V", "i", ResultUnitEnum.HSV_UNIT.getUnit(), false);
|
||||
dtlsSetBuffer(scriptDtlIndex, buffer, "InHarm_I", "i", ResultUnitEnum.HSI_UNIT.getUnit(), false);
|
||||
dtlsSetBufferDip(scriptDtlIndex, buffer, "Dip", "暂态", ResultUnitEnum.HSI_UNIT.getUnit());
|
||||
dtlsSetBufferFlicker(scriptDtlIndex, buffer, "Flicker", "闪变");
|
||||
childInfo.setIndex(index);
|
||||
childInfo.setFly(conform(nums));
|
||||
childInfo.setScriptTypeName(buffer.toString());
|
||||
scriptDlsList.add(childInfo);
|
||||
}
|
||||
});
|
||||
if (CollUtil.isNotEmpty(scriptDlsList)) {
|
||||
TreeDataVO sub = new TreeDataVO();
|
||||
sub.setScriptTypeName(subName.get(subKey).replace("XX", dictTree.getName()));
|
||||
sub.setChildren(scriptDlsList);
|
||||
scriptSubList.add(sub);
|
||||
}
|
||||
});
|
||||
if (CollUtil.isNotEmpty(scriptSubList)) {
|
||||
//大相检测信息
|
||||
TreeDataVO infoVO = new TreeDataVO();
|
||||
infoVO.setScriptTypeName(dictTree.getName());
|
||||
infoVO.setChildren(scriptSubList);
|
||||
infoVOS.add(infoVO);
|
||||
}
|
||||
}
|
||||
});
|
||||
return infoVOS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultVO resultData(ResultParam param) {
|
||||
|
||||
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void dtlsSetBuffer(List<PqScriptDtls> scriptDtlIndex, StringBuffer buffer, String valueType, String name, String unit, Boolean fly) {
|
||||
LinkedHashMap<Double, List<PqScriptDtls>> harmNumMap = scriptDtlIndex.stream()
|
||||
.filter(x -> valueType.equals(x.getValueType()))
|
||||
.sorted(Comparator.comparing(PqScriptDtls::getHarmNum))
|
||||
.collect(Collectors.groupingBy(PqScriptDtls::getHarmNum, LinkedHashMap::new, Collectors.toList()));
|
||||
harmNumMap.forEach((harmNum, value) -> {
|
||||
if (fly) {
|
||||
buffer.append(name + String.format("%.0f", harmNum) + "(");
|
||||
} else {
|
||||
buffer.append(name + harmNum + "(");
|
||||
}
|
||||
if (CollUtil.isNotEmpty(value)) {
|
||||
for (PqScriptDtls dtls : value) {
|
||||
buffer.append(dtls.getPhase() + "相=" + dtls.getValue() + unit + " ");
|
||||
}
|
||||
buffer.append(") ");
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
private static void dtlsSetBufferDip(List<PqScriptDtls> scriptDtlIndex, StringBuffer buffer, String valueType, String name, String unit) {
|
||||
List<PqScriptDtls> list = scriptDtlIndex.stream().filter(x -> valueType.equals(x.getValueType()))
|
||||
.sorted(Comparator.comparing(PqScriptDtls::getPhase))
|
||||
.collect(Collectors.toList());
|
||||
if (CollUtil.isNotEmpty(list)) {
|
||||
buffer.append(name + " ");
|
||||
for (PqScriptDtls dtls : list) {
|
||||
buffer.append(dtls.getPhase() + "相(暂态深度=" + dtls.getTransValue() + ResultUnitEnum.VOLTAGE_DUR_UNIT.getUnit()
|
||||
+ " 暂态持续时间=" + dtls.getRetainTime().intValue() + ResultUnitEnum.VOLTAGE_MAG_UNIT.getUnit() + ") ");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void dtlsSetBufferFlicker(List<PqScriptDtls> scriptDtlIndex, StringBuffer buffer, String valueType, String name) {
|
||||
List<PqScriptDtls> list = scriptDtlIndex.stream().filter(x -> valueType.equals(x.getValueType()))
|
||||
.sorted(Comparator.comparing(PqScriptDtls::getPhase))
|
||||
.collect(Collectors.toList());
|
||||
if (CollUtil.isNotEmpty(list)) {
|
||||
buffer.append(name + " ");
|
||||
for (PqScriptDtls dtls : list) {
|
||||
buffer.append(dtls.getPhase() + "相(变动频度=" + dtls.getChagFre()
|
||||
+ "次/min 变动量=" + dtls.getChagValue() + ResultUnitEnum.VOLTAGE_DUR_UNIT.getUnit() + ") ");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Integer conform(Set<Integer> numbers) {
|
||||
if (numbers.size() > 2) {
|
||||
return 4;
|
||||
} else if (numbers.size() > 1) {
|
||||
if (numbers.contains(4)) {
|
||||
return 4;
|
||||
} else if (numbers.contains(2)) {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
return new ArrayList<>(numbers).get(0);
|
||||
}
|
||||
}
|
||||
8
device/Readme.md
Normal file
8
device/Readme.md
Normal file
@@ -0,0 +1,8 @@
|
||||
#### 简介
|
||||
设备模块主要包含以下功能:
|
||||
* 被检设备管理
|
||||
* 检测脚本管理
|
||||
* 误差体系管理
|
||||
* 检测源管理
|
||||
|
||||
|
||||
45
device/pom.xml
Normal file
45
device/pom.xml
Normal file
@@ -0,0 +1,45 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.njcn.gather</groupId>
|
||||
<artifactId>CN_Gather</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
<artifactId>device</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>njcn-common</artifactId>
|
||||
<version>0.0.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>mybatis-plus</artifactId>
|
||||
<version>0.0.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>spingboot2.3.12</artifactId>
|
||||
<version>2.3.12</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.njcn.gather</groupId>
|
||||
<artifactId>system</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>1.2.83</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,252 @@
|
||||
package com.njcn.gather.device.device.controller;
|
||||
|
||||
import cn.afterturn.easypoi.excel.ExcelImportUtil;
|
||||
import cn.afterturn.easypoi.excel.entity.ImportParams;
|
||||
import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
import com.njcn.common.pojo.constant.OperateType;
|
||||
import com.njcn.common.pojo.enums.common.LogEnum;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.LogUtil;
|
||||
import com.njcn.gather.device.device.pojo.param.PqDevParam;
|
||||
import com.njcn.gather.device.device.pojo.po.PqDev;
|
||||
import com.njcn.gather.device.device.pojo.vo.PqDevExcel;
|
||||
import com.njcn.gather.device.device.pojo.vo.PqDevVO;
|
||||
import com.njcn.gather.device.device.pojo.vo.PreDetection;
|
||||
import com.njcn.gather.device.device.service.IPqDevService;
|
||||
import com.njcn.gather.device.pojo.enums.DevResponseEnum;
|
||||
import com.njcn.gather.device.pojo.enums.PatternEnum;
|
||||
import com.njcn.gather.system.dictionary.pojo.po.DictData;
|
||||
import com.njcn.gather.system.dictionary.service.IDictDataService;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import com.njcn.web.utils.ExcelUtil;
|
||||
import com.njcn.web.utils.HttpResultUtil;
|
||||
import com.njcn.web.utils.PoiUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024/11/06
|
||||
*/
|
||||
@Slf4j
|
||||
@Api(tags = "被检设备")
|
||||
@RestController
|
||||
@RequestMapping("/pqDev")
|
||||
@RequiredArgsConstructor
|
||||
public class PqDevController extends BaseController {
|
||||
|
||||
private final IPqDevService pqDevService;
|
||||
private final IDictDataService dictDataService;
|
||||
|
||||
|
||||
@OperateInfo
|
||||
@GetMapping("/aaa")
|
||||
@ApiOperation("分页查询被检设备")
|
||||
@ApiImplicitParam(name = "queryParam", value = "查询参数", required = true)
|
||||
public HttpResult<List<PreDetection>> aaa() {
|
||||
String methodDescribe = getMethodDescribe("list");
|
||||
List<PreDetection> devInfo = pqDevService.getDevInfo(Arrays.asList("578c142b7e4e4978a35bd6225aa62a23", "393504f55f1f79bce255bfc195cfdb56"));
|
||||
Map<String,List<PreDetection> > map=new HashMap();
|
||||
map.put("deviceList",devInfo);
|
||||
String jsonString = JSON.toJSONString(map);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, devInfo, methodDescribe);
|
||||
}
|
||||
|
||||
|
||||
@OperateInfo
|
||||
@PostMapping("/list")
|
||||
@ApiOperation("分页查询被检设备")
|
||||
@ApiImplicitParam(name = "queryParam", value = "查询参数", required = true)
|
||||
public HttpResult<Page<PqDev>> list(@RequestBody @Validated PqDevParam.QueryParam queryParam) {
|
||||
String methodDescribe = getMethodDescribe("list");
|
||||
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, queryParam);
|
||||
Page<PqDev> result = pqDevService.listPqDevs(queryParam);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo
|
||||
@GetMapping("/getById")
|
||||
@ApiOperation("根据id查询被检设备")
|
||||
@ApiImplicitParam(name = "id", value = "被检设备id", required = true)
|
||||
public HttpResult<PqDevVO> getById(@RequestParam("id") String id) {
|
||||
String methodDescribe = getMethodDescribe("getById");
|
||||
LogUtil.njcnDebug(log, "{},查询ID为:{}", methodDescribe, id);
|
||||
PqDevVO result = pqDevService.getPqDevById(id);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(operateType = OperateType.ADD)
|
||||
@PostMapping("/add")
|
||||
@ApiOperation("新增被检设备")
|
||||
@ApiImplicitParam(name = "pqDevParam", value = "被检设备", required = true)
|
||||
public HttpResult<Object> add(@RequestBody @Validated PqDevParam pqDevParam) {
|
||||
String methodDescribe = getMethodDescribe("add");
|
||||
LogUtil.njcnDebug(log, "{},新增数据为:{}", methodDescribe, pqDevParam);
|
||||
boolean result = pqDevService.addPqDev(pqDevParam);
|
||||
if (result) {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
} else {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
|
||||
}
|
||||
}
|
||||
|
||||
@OperateInfo(operateType = OperateType.UPDATE)
|
||||
@PostMapping("/update")
|
||||
@ApiOperation("修改被检设备")
|
||||
@ApiImplicitParam(name = "updateParam", value = "被检设备", required = true)
|
||||
public HttpResult<Object> update(@RequestBody @Validated PqDevParam.UpdateParam updateParam) {
|
||||
String methodDescribe = getMethodDescribe("update");
|
||||
LogUtil.njcnDebug(log, "{},修改数据为:{}", methodDescribe, updateParam);
|
||||
boolean result = pqDevService.updatePqDev(updateParam);
|
||||
if (result) {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
} else {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
|
||||
}
|
||||
}
|
||||
|
||||
@OperateInfo(operateType = OperateType.DELETE)
|
||||
@PostMapping("/delete")
|
||||
@ApiOperation("删除被检设备")
|
||||
@ApiImplicitParam(name = "ids", value = "被检设备id", required = true)
|
||||
public HttpResult<Object> delete(@RequestBody @Validated PqDevParam.DeleteParam param) {
|
||||
String methodDescribe = getMethodDescribe("delete");
|
||||
LogUtil.njcnDebug(log, "{},删除ID数据为:{}", methodDescribe, String.join(StrUtil.COMMA, param.getIds()));
|
||||
boolean result = pqDevService.deletePqDev(param);
|
||||
if (result) {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
} else {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
|
||||
}
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.DOWNLOAD)
|
||||
@PostMapping("/downloadTemplate")
|
||||
@ApiOperation("下载被检设备导入文件模板")
|
||||
public void downloadTemplate() {
|
||||
pqDevService.downloadTemplate();
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.DOWNLOAD)
|
||||
@PostMapping("/export")
|
||||
@ApiOperation("导出被检设备数据")
|
||||
@ApiImplicitParam(name = "queryParam", value = "查询参数", required = true)
|
||||
public void export(@RequestBody @Validated PqDevParam.QueryParam queryParam) {
|
||||
String methodDescribe = getMethodDescribe("export");
|
||||
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, queryParam);
|
||||
DictData dictData = dictDataService.getDictDataById(queryParam.getPattern());
|
||||
if (ObjectUtil.isNotNull(dictData)) {
|
||||
if (PatternEnum.CONTRAST.getValue().equals(dictData.getCode())) {
|
||||
List<PqDevExcel.ContrastExportData> data = pqDevService.getContrastExportData(queryParam);
|
||||
ExcelUtil.exportExcel("被检设备导出数据.xlsx", PqDevExcel.ContrastExportData.class, data);
|
||||
} else {
|
||||
List<PqDevExcel.SimulateOrDigitalExportData> data = pqDevService.getSimulateOrDigitExportData(queryParam);
|
||||
ExcelUtil.exportExcel("被检设备导出数据.xlsx", PqDevExcel.SimulateOrDigitalExportData.class, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.UPLOAD)
|
||||
@PostMapping(value = "/import")
|
||||
@ApiOperation("批量导入被检设备数据")
|
||||
@ApiImplicitParam(name = "file", value = "被检设备数据文件", required = true)
|
||||
public HttpResult<Object> importData(@RequestParam("file") MultipartFile file, HttpServletResponse response) {
|
||||
String methodDescribe = getMethodDescribe("importData");
|
||||
LogUtil.njcnDebug(log, "{},上传文件为:{}", methodDescribe, file.getOriginalFilename());
|
||||
ImportParams params = new ImportParams();
|
||||
params.setHeadRows(2);
|
||||
params.setNeedVerify(true);
|
||||
params.setStartSheetIndex(0);
|
||||
params.setSheetNum(1);
|
||||
try {
|
||||
ExcelImportResult<PqDevExcel.ContrastImportData> excelImportResult = ExcelImportUtil.importExcelMore(file.getInputStream(), PqDevExcel.ContrastImportData.class, params);
|
||||
//如果存在非法数据,将不合格的数据导出
|
||||
if (excelImportResult.isVerifyFail()) {
|
||||
// 此处前端要做特殊处理,具体可以参考技术监督的数据导入
|
||||
Workbook failWorkbook = excelImportResult.getFailWorkbook();
|
||||
PoiUtil.exportFileByWorkbook(failWorkbook, "非法被检设备数据.xlsx", response);
|
||||
} else {
|
||||
//批量录入数据
|
||||
List<PqDevExcel.ContrastImportData> list = excelImportResult.getList();
|
||||
pqDevService.importContrastData(list);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new BusinessException(DevResponseEnum.IMPORT_DATA_FAIL);
|
||||
}
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@GetMapping("/listUnbound")
|
||||
@ApiOperation("获取指定模式下所有未绑定的设备")
|
||||
@ApiImplicitParam(name = "pattern", value = "模式id", required = true)
|
||||
public HttpResult<List<Map<String, Object>>> listUnbound(@RequestParam("pattern") String pattern) {
|
||||
String methodDescribe = getMethodDescribe("listUnbound");
|
||||
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, pattern);
|
||||
List<Map<String, Object>> result = pqDevService.listUnbound(pattern);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/listByPlanId")
|
||||
@ApiOperation("根据查询参数查询出所有已绑定的设备")
|
||||
@ApiImplicitParam(name = "planId", value = "计划id", required = true)
|
||||
public HttpResult<List<PqDev>> listByPlanId(@RequestBody @Validated PqDevParam.QueryParam param) {
|
||||
String methodDescribe = getMethodDescribe("listByPlanId");
|
||||
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, param);
|
||||
List<PqDev> result = pqDevService.listByPlanId(param);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.UPDATE)
|
||||
@GetMapping("/documented")
|
||||
@ApiOperation("设备归档")
|
||||
@ApiImplicitParam(name = "id", value = "设备id", required = true)
|
||||
public HttpResult<List<PqDev>> documented(@RequestParam String id) {
|
||||
String methodDescribe = getMethodDescribe("documented");
|
||||
LogUtil.njcnDebug(log, "{},设备id为:{}", methodDescribe, id);
|
||||
boolean result = pqDevService.documented(id);
|
||||
if (result) {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
} else {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
|
||||
}
|
||||
}
|
||||
|
||||
// @OperateInfo(operateType = OperateType.UPDATE)
|
||||
// @PostMapping("/bindDev")
|
||||
// @ApiOperation("检测计划绑定设备")
|
||||
// @ApiImplicitParam(name = "bindPlanParam", value = "绑定参数", required = true)
|
||||
// public HttpResult<Object> bindDev(@RequestBody @Validated PqDevParam.BindPlanParam bindPlanParam) {
|
||||
// String methodDescribe = getMethodDescribe("bindDev");
|
||||
// LogUtil.njcnDebug(log, "{},绑定计划数据为:planId={}, pqDevIds={}", methodDescribe, bindPlanParam.getPlanId(), String.join(StrUtil.COMMA, bindPlanParam.getPqDevIds()));
|
||||
// boolean result = pqDevService.bind(bindPlanParam.getPlanId(), bindPlanParam.getPqDevIds());
|
||||
// if (result) {
|
||||
// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
// } else {
|
||||
// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.njcn.gather.device.device.mapper;
|
||||
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
import com.njcn.gather.device.device.pojo.po.PqDev;
|
||||
import com.njcn.gather.device.device.pojo.vo.PreDetection;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024-11-06
|
||||
*/
|
||||
public interface PqDevMapper extends MPJBaseMapper<PqDev> {
|
||||
|
||||
/**
|
||||
* 根据装置id集合获取装置信息
|
||||
* @param devIds 装置id
|
||||
* @return: java.util.List<com.njcn.gather.device.device.pojo.vo.PreDetection>
|
||||
* @Author: wr
|
||||
* @Date: 2024/12/12 11:46
|
||||
*/
|
||||
List<PreDetection> selectDevInfo(@Param("devIds") List<String> devIds);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.njcn.gather.device.device.mapper.PqDevMapper">
|
||||
|
||||
<!-- 通用查询映射结果 -->
|
||||
<resultMap id="DevResultMap" type="com.njcn.gather.device.device.pojo.vo.PreDetection">
|
||||
<id column="Id" property="devId" />
|
||||
<id column="Name" property="devName" />
|
||||
<id column="IP" property="devIP" />
|
||||
<result column="Port" property="port" />
|
||||
<result column="Dev_Type" property="devType" />
|
||||
<result column="" property="icdType" />
|
||||
<result column="Series" property="devCode" />
|
||||
<result column="Dev_Key" property="devKey" />
|
||||
<result column="icdType" property="icdType" />
|
||||
|
||||
<collection
|
||||
property="monitorList"
|
||||
column="{ devId = Id}"
|
||||
select="com.njcn.gather.device.monitor.mapper.PqMonitorMapper.selectMonitorInfo"
|
||||
>
|
||||
</collection>
|
||||
</resultMap>
|
||||
<select id="selectDevInfo" resultMap="DevResultMap">
|
||||
SELECT
|
||||
d.Id,
|
||||
d.Name,
|
||||
d.IP,
|
||||
( select name from sys_dict_data sd where d.Dev_Type= sd.id) as Dev_Type,
|
||||
d.Port,
|
||||
d.Dev_Chns as devChns,
|
||||
d.Series,
|
||||
d.Dev_Key,
|
||||
p.name icdType
|
||||
FROM
|
||||
pq_dev d
|
||||
inner join pq_icd_path p on d.Icd_Id = p.id
|
||||
<where>
|
||||
<if test="devIds !=null and devIds.size()!=0">
|
||||
AND d.Id in
|
||||
<foreach collection="devIds" open="(" close=")" item="item" separator=",">
|
||||
#{item}
|
||||
</foreach>
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.njcn.gather.device.device.pojo.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2024-12-11
|
||||
*/
|
||||
@Getter
|
||||
public enum TimeCheckResultEnum {
|
||||
UNQUALIFY(0, "不合格"),
|
||||
QUALIFY(1, "合格"),
|
||||
UNKNOWN(2, "/");
|
||||
|
||||
private Integer value;
|
||||
private String msg;
|
||||
|
||||
TimeCheckResultEnum(Integer value, String msg) {
|
||||
this.value = value;
|
||||
this.msg = msg;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,229 @@
|
||||
package com.njcn.gather.device.device.pojo.param;
|
||||
|
||||
import com.njcn.common.pojo.constant.PatternRegex;
|
||||
import com.njcn.gather.device.monitor.pojo.param.PqMonitorParam;
|
||||
import com.njcn.gather.device.pojo.constant.DevValidMessage;
|
||||
import com.njcn.web.pojo.annotation.DateTimeStrValid;
|
||||
import com.njcn.web.pojo.param.BaseParam;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.hibernate.validator.constraints.Range;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.*;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024/11/06
|
||||
*/
|
||||
@Data
|
||||
public class PqDevParam {
|
||||
|
||||
@ApiModelProperty(value = "名称", required = true)
|
||||
@NotBlank(message = DevValidMessage.NAME_NOT_BLANK)
|
||||
@Pattern(regexp = PatternRegex.DEV_NAME_REGEX, message = DevValidMessage.NAME_FORMAT_ERROR)
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(value = "设备模式,字典表(数字、模拟、比对)", required = true)
|
||||
@NotBlank(message = DevValidMessage.PATTERN_NOT_BLANK)
|
||||
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.PATTERN_FORMAT_ERROR)
|
||||
private String pattern;
|
||||
|
||||
@ApiModelProperty(value = "设备类型,字典表", required = true)
|
||||
@NotBlank(message = DevValidMessage.DEV_TYPE_NOT_BLANK)
|
||||
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.DEV_TYPE_FORMAT_ERROR)
|
||||
private String devType;
|
||||
|
||||
@ApiModelProperty(value = "设备通道数", required = true)
|
||||
@NotNull(message = DevValidMessage.DEV_CHNS_NOT_NULL)
|
||||
@Min(value = 1, message = DevValidMessage.DEV_CHNS_RANGE_ERROR)
|
||||
private Integer devChns;
|
||||
|
||||
@ApiModelProperty(value = "额定电压(V)", required = true)
|
||||
@NotNull(message = DevValidMessage.DEV_VOLT_NOT_NULL)
|
||||
private Float devVolt;
|
||||
|
||||
@ApiModelProperty(value = "额定电流(A)", required = true)
|
||||
@NotNull(message = DevValidMessage.DEV_CURR_NOT_NULL)
|
||||
private Float devCurr;
|
||||
|
||||
@ApiModelProperty(value = "设备厂家,字典表", required = true)
|
||||
@NotBlank(message = DevValidMessage.MANUFACTURER_NOT_BLANK)
|
||||
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.MANUFACTURER_FORMAT_ERROR)
|
||||
private String manufacturer;
|
||||
|
||||
@ApiModelProperty(value = "出厂日期", required = true)
|
||||
@NotBlank(message = DevValidMessage.CREATEDATETIME_NOT_NULL)
|
||||
@DateTimeStrValid(format = "yyyy-MM-dd", message = DevValidMessage.CREATEDATETIME_FORMAT_ERROR)
|
||||
private String createDate;
|
||||
|
||||
@ApiModelProperty(value = "设备序列号", required = true)
|
||||
@NotBlank(message = DevValidMessage.FACTORYNO_NOT_BLANK)
|
||||
private String createId;
|
||||
|
||||
@ApiModelProperty(value = "固件版本", required = true)
|
||||
@NotBlank(message = DevValidMessage.FIRMWARE_NOT_BLANK)
|
||||
private String hardwareVersion;
|
||||
|
||||
@ApiModelProperty(value = "软件版本", required = true)
|
||||
@NotBlank(message = DevValidMessage.SOFTWARE_NOT_BLANK)
|
||||
private String softwareVersion;
|
||||
|
||||
@ApiModelProperty(value = "通讯协议", required = true)
|
||||
@NotBlank(message = DevValidMessage.PROTOCOL_NOT_BLANK)
|
||||
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.PROTOCOL_FORMAT_ERROR)
|
||||
private String protocol;
|
||||
|
||||
@ApiModelProperty(value = "IP地址", required = true)
|
||||
@NotBlank(message = DevValidMessage.IP_NOT_BLANK)
|
||||
@Pattern(regexp = PatternRegex.IP_REGEX, message = DevValidMessage.IP_FORMAT_ERROR)
|
||||
private String ip;
|
||||
|
||||
@ApiModelProperty(value = "端口号", required = true)
|
||||
@NotNull(message = DevValidMessage.PORT_NOT_NULL)
|
||||
@Range(min = 1, max = 65535, message = DevValidMessage.PORT_RANGE_ERROR)
|
||||
private Integer port;
|
||||
|
||||
@ApiModelProperty(value = "装置是否为加密版本", required = true)
|
||||
@NotNull(message = DevValidMessage.ENCRYPTION_NOT_NULL)
|
||||
@Min(value = 0, message = DevValidMessage.ENCRYPTION_FLAG_FORMAT_ERROR)
|
||||
@Max(value = 1, message = DevValidMessage.ENCRYPTION_FLAG_FORMAT_ERROR)
|
||||
private Integer encryptionFlag;
|
||||
|
||||
@ApiModelProperty("装置识别码(3ds加密)")
|
||||
private String series;
|
||||
|
||||
@ApiModelProperty("装置秘钥(3ds加密)")
|
||||
private String devKey;
|
||||
|
||||
@ApiModelProperty("样品编号")
|
||||
private String sampleId;
|
||||
|
||||
@ApiModelProperty(value = "送样日期")
|
||||
@DateTimeStrValid(message = DevValidMessage.ARRIVE_DATE_FORMAT_ERROR)
|
||||
private String arrivedDate;
|
||||
|
||||
@ApiModelProperty("所属地市名称")
|
||||
private String cityName;
|
||||
|
||||
@ApiModelProperty("所属供电公司名称")
|
||||
private String gdName;
|
||||
|
||||
@ApiModelProperty("所属电站名称")
|
||||
private String subName;
|
||||
|
||||
@ApiModelProperty("报告路径")
|
||||
private String reportPath;
|
||||
|
||||
@ApiModelProperty("设备关键信息二维码")
|
||||
private String qrCode;
|
||||
|
||||
@ApiModelProperty(value = "检测次数,默认为0", required = true)
|
||||
@NotNull(message = DevValidMessage.RECHECK_NUM_NOT_NULL)
|
||||
@Min(value = 0, message = DevValidMessage.RECHECK_NUM_FORMAT_ERROR)
|
||||
private Integer reCheckNum;
|
||||
|
||||
@ApiModelProperty("是否支持系数校准")
|
||||
@Min(value = 0, message = DevValidMessage.FACTOR_FLAG_FORMAT_ERROR)
|
||||
@Max(value = 1, message = DevValidMessage.FACTOR_FLAG_FORMAT_ERROR)
|
||||
private String factorFlag;
|
||||
|
||||
@ApiModelProperty("监测点台账列表")
|
||||
@Valid
|
||||
private List<PqMonitorParam> monitorList;
|
||||
|
||||
/**
|
||||
* 更新操作实体
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public static class UpdateParam extends PqDevParam {
|
||||
|
||||
@ApiModelProperty(value = "id", required = true)
|
||||
@NotBlank(message = DevValidMessage.ID_NOT_BLANK)
|
||||
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.ID_FORMAT_ERROR)
|
||||
private String id;
|
||||
|
||||
// @ApiModelProperty("检测状态")
|
||||
// @Min(value = 0, message = DevValidMessage.CHECK_STATE_FORMAT_ERROR)
|
||||
// @Max(value = 3, message = DevValidMessage.CHECK_STATE_FORMAT_ERROR)
|
||||
// private Integer checkState;
|
||||
//
|
||||
// @ApiModelProperty("检测结果")
|
||||
// @Min(value = 0, message = DevValidMessage.CHECK_RESULT_FORMAT_ERROR)
|
||||
// @Max(value = 2, message = DevValidMessage.CHECK_RESULT_FORMAT_ERROR)
|
||||
// private Integer checkResult;
|
||||
//
|
||||
// @ApiModelProperty("报告状态")
|
||||
// @Min(value = 0, message = DevValidMessage.REPORT_STATE_FORMAT_ERROR)
|
||||
// @Max(value = 2, message = DevValidMessage.REPORT_STATE_FORMAT_ERROR)
|
||||
// private Integer reportState;
|
||||
//
|
||||
// @ApiModelProperty("归档状态")
|
||||
// @Min(value = 0, message = DevValidMessage.DOCUMENT_STATE_FORMAT_ERROR)
|
||||
// @Max(value = 1, message = DevValidMessage.DOCUMENT_STATE_FORMAT_ERROR)
|
||||
// private Integer documentState;
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询实体
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public static class QueryParam extends BaseParam {
|
||||
@ApiModelProperty("名称")
|
||||
@Pattern(regexp = PatternRegex.DEV_NAME_REGEX, message = DevValidMessage.NAME_FORMAT_ERROR)
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(value = "设备模式,字典表(数字、模拟、比对)")
|
||||
private String pattern;
|
||||
|
||||
@ApiModelProperty("设备厂家")
|
||||
private String manufacturer;
|
||||
|
||||
@ApiModelProperty("检测计划ID")
|
||||
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.PLAN_ID_FORMAT_ERROR)
|
||||
private String planId;
|
||||
|
||||
@ApiModelProperty("检测状态列表")
|
||||
private List<
|
||||
@Min(value = 0, message = DevValidMessage.CHECK_STATE_FORMAT_ERROR)
|
||||
@Max(value = 3, message = DevValidMessage.CHECK_STATE_FORMAT_ERROR) Integer> checkStateList;
|
||||
|
||||
@ApiModelProperty("检测结果")
|
||||
@Min(value = 0, message = DevValidMessage.CHECK_RESULT_FORMAT_ERROR)
|
||||
@Max(value = 2, message = DevValidMessage.CHECK_RESULT_FORMAT_ERROR)
|
||||
private Integer checkResult;
|
||||
|
||||
@ApiModelProperty("报告状态")
|
||||
@Min(value = 0, message = DevValidMessage.REPORT_STATE_FORMAT_ERROR)
|
||||
@Max(value = 2, message = DevValidMessage.REPORT_STATE_FORMAT_ERROR)
|
||||
private Integer reportState;
|
||||
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class DeleteParam {
|
||||
@ApiModelProperty(value = "ids")
|
||||
private List<@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.ID_FORMAT_ERROR) String> ids;
|
||||
|
||||
@ApiModelProperty(value = "设备模式,字典表(数字、模拟、比对)", required = true)
|
||||
@NotBlank(message = DevValidMessage.PATTERN_NOT_BLANK)
|
||||
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.PATTERN_FORMAT_ERROR)
|
||||
private String pattern;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class BindPlanParam {
|
||||
@ApiModelProperty("检测计划ID")
|
||||
@NotNull(message = DevValidMessage.PLAN_ID_NOT_NULL)
|
||||
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.PLAN_ID_FORMAT_ERROR)
|
||||
private String planId;
|
||||
|
||||
@ApiModelProperty("被检设备ID列表")
|
||||
@NotNull(message = DevValidMessage.PQ_DEV_IDS_NOT_NULL)
|
||||
private List<String> pqDevIds;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,211 @@
|
||||
package com.njcn.gather.device.device.pojo.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldStrategy;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
|
||||
import com.njcn.db.mybatisplus.bo.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDate;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024/11/06
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("pq_dev")
|
||||
public class PqDev extends BaseEntity implements Serializable {
|
||||
private static final long serialVersionUID = -45763424394344208L;
|
||||
|
||||
/**
|
||||
* 主键装置序号ID
|
||||
*/
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 设备名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 设备模式,字典表(数字、模拟、比对)
|
||||
*/
|
||||
private String pattern;
|
||||
|
||||
/**
|
||||
* 设备类型,字典表
|
||||
*/
|
||||
private String devType;
|
||||
|
||||
/**
|
||||
* 设备通道数
|
||||
*/
|
||||
private Integer devChns;
|
||||
|
||||
/**
|
||||
* 额定电压(V)
|
||||
*/
|
||||
private Double devVolt;
|
||||
|
||||
/**
|
||||
* 额定电流(A)
|
||||
*/
|
||||
private Double devCurr;
|
||||
|
||||
/**
|
||||
* 设备厂家,字典表
|
||||
*/
|
||||
private String manufacturer;
|
||||
|
||||
/**
|
||||
* 出厂日期
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
@JsonDeserialize(using = LocalDateDeserializer.class)
|
||||
@JsonSerialize(using = LocalDateSerializer.class)
|
||||
private LocalDate createDate;
|
||||
|
||||
/**
|
||||
* 设备序列号
|
||||
*/
|
||||
private String createId;
|
||||
|
||||
/**
|
||||
* 固件版本
|
||||
*/
|
||||
private String hardwareVersion;
|
||||
|
||||
/**
|
||||
* 软件版本
|
||||
*/
|
||||
private String softwareVersion;
|
||||
|
||||
/**
|
||||
* 通讯协议,字典表(MMS、PODIF)
|
||||
*/
|
||||
private String protocol;
|
||||
|
||||
/**
|
||||
* IP地址
|
||||
*/
|
||||
private String ip;
|
||||
|
||||
/**
|
||||
* 端口号
|
||||
*/
|
||||
private Integer port;
|
||||
|
||||
/**
|
||||
* 装置是否为加密版本
|
||||
*/
|
||||
private Integer encryptionFlag;
|
||||
|
||||
/**
|
||||
* 装置识别码(3ds加密)
|
||||
*/
|
||||
private String series;
|
||||
|
||||
/**
|
||||
* 装置秘钥(3ds加密)
|
||||
*/
|
||||
private String devKey;
|
||||
|
||||
/**
|
||||
* 样品编号
|
||||
*/
|
||||
private String sampleId;
|
||||
|
||||
/**
|
||||
* 送样日期
|
||||
*/
|
||||
@TableField(updateStrategy = FieldStrategy.IGNORED)
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
@JsonDeserialize(using = LocalDateDeserializer.class)
|
||||
@JsonSerialize(using = LocalDateSerializer.class)
|
||||
private LocalDate arrivedDate;
|
||||
|
||||
/**
|
||||
* 所属地市名称
|
||||
*/
|
||||
private String cityName;
|
||||
|
||||
/**
|
||||
* 所属供电公司名称
|
||||
*/
|
||||
private String gdName;
|
||||
|
||||
/**
|
||||
* 所属电站名称
|
||||
*/
|
||||
private String subName;
|
||||
|
||||
/**
|
||||
* 检测状态
|
||||
*/
|
||||
private Integer checkState;
|
||||
|
||||
/**
|
||||
* 检测结果
|
||||
*/
|
||||
private Integer checkResult;
|
||||
|
||||
/**
|
||||
* 报告状态
|
||||
*/
|
||||
private Integer reportState;
|
||||
|
||||
/**
|
||||
* 归档状态
|
||||
*/
|
||||
private Integer documentState;
|
||||
|
||||
/**
|
||||
* 报告路径
|
||||
*/
|
||||
private String reportPath;
|
||||
|
||||
/**
|
||||
* 设备关键信息二维码
|
||||
*/
|
||||
private String qrCode;
|
||||
|
||||
/**
|
||||
* 检测次数,默认为0
|
||||
*/
|
||||
@TableField(value = "ReCheck_Num")
|
||||
private Integer reCheckNum;
|
||||
|
||||
/**
|
||||
* 状态:0-删除 1-正常
|
||||
*/
|
||||
private Integer state;
|
||||
|
||||
/**
|
||||
* 检测计划id
|
||||
*/
|
||||
private String planId;
|
||||
|
||||
/**
|
||||
* 守时检测结果(0:不合格, 1:合格)
|
||||
*/
|
||||
private Integer timeCheckResult;
|
||||
|
||||
/**
|
||||
* 是否支持系数校准(0:不支持,1:支持)
|
||||
*/
|
||||
private Integer factorFlag;
|
||||
|
||||
/**
|
||||
* 系数校准结果(0:不合格,1:合格)
|
||||
*/
|
||||
private Integer factorCheckResult;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,211 @@
|
||||
package com.njcn.gather.device.device.pojo.vo;
|
||||
|
||||
import cn.afterturn.easypoi.excel.annotation.Excel;
|
||||
import cn.afterturn.easypoi.excel.annotation.ExcelCollection;
|
||||
import com.njcn.common.pojo.constant.PatternRegex;
|
||||
import com.njcn.gather.device.monitor.pojo.vo.PqMonitorExcel;
|
||||
import com.njcn.gather.device.pojo.constant.DevValidMessage;
|
||||
import com.njcn.web.pojo.annotation.DateTimeStrValid;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.hibernate.validator.constraints.Range;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Pattern;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2024/11/7
|
||||
*/
|
||||
@Data
|
||||
public class PqDevExcel implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Excel(name = "名称", width = 20, needMerge = true)
|
||||
@NotBlank(message = DevValidMessage.NAME_NOT_BLANK)
|
||||
@Pattern(regexp = PatternRegex.DEV_NAME_REGEX, message = DevValidMessage.NAME_FORMAT_ERROR)
|
||||
private String name;
|
||||
|
||||
@Excel(name = "设备类型", width = 20, orderNum = "2", needMerge = true)
|
||||
@NotBlank(message = DevValidMessage.DEV_TYPE_NOT_BLANK)
|
||||
private String devType;
|
||||
|
||||
@Excel(name = "设备通道数", width = 20, orderNum = "3", needMerge = true)
|
||||
@NotNull(message = DevValidMessage.DEV_CHNS_NOT_NULL)
|
||||
private Integer devChns;
|
||||
|
||||
@Excel(name = "额定电压(V)", width = 15, orderNum = "4", needMerge = true)
|
||||
@NotNull(message = DevValidMessage.DEV_VOLT_NOT_NULL)
|
||||
private Float devVolt;
|
||||
|
||||
@Excel(name = "额定电流(A)", width = 15, orderNum = "5", needMerge = true)
|
||||
@NotNull(message = DevValidMessage.DEV_CURR_NOT_NULL)
|
||||
private Float devCurr;
|
||||
|
||||
@Excel(name = "设备厂家", width = 20, orderNum = "6", needMerge = true)
|
||||
@NotBlank(message = DevValidMessage.MANUFACTURER_NOT_BLANK)
|
||||
private String manufacturer;
|
||||
|
||||
@Excel(name = "设备序列号", width = 40, orderNum = "8", needMerge = true)
|
||||
@NotBlank(message = DevValidMessage.FACTORYNO_NOT_BLANK)
|
||||
private String createId;
|
||||
|
||||
@Excel(name = "固件版本", width = 15, orderNum = "9", needMerge = true)
|
||||
@NotBlank(message = DevValidMessage.FIRMWARE_NOT_BLANK)
|
||||
private String hardwareVersion;
|
||||
|
||||
@Excel(name = "软件版本", width = 15, orderNum = "10", needMerge = true)
|
||||
@NotBlank(message = DevValidMessage.SOFTWARE_NOT_BLANK)
|
||||
private String softwareVersion;
|
||||
|
||||
@Excel(name = "通讯协议", width = 15, orderNum = "11", needMerge = true)
|
||||
@NotBlank(message = DevValidMessage.PROTOCOL_NOT_BLANK)
|
||||
private String protocol;
|
||||
|
||||
@Excel(name = "IP地址", width = 20, orderNum = "12", needMerge = true)
|
||||
@NotBlank(message = DevValidMessage.IP_NOT_BLANK)
|
||||
@Pattern(regexp = PatternRegex.IP_REGEX, message = DevValidMessage.IP_FORMAT_ERROR)
|
||||
private String ip;
|
||||
|
||||
@Excel(name = "端口号", orderNum = "13", needMerge = true)
|
||||
@NotNull(message = DevValidMessage.PORT_NOT_NULL)
|
||||
@Range(min = 1, max = 65535, message = DevValidMessage.PORT_RANGE_ERROR)
|
||||
private Integer port;
|
||||
|
||||
@Excel(name = "是否为加密版本(否\\是)", width = 20, replace = {"否_0", "是_1"}, orderNum = "14", needMerge = true)
|
||||
@NotNull(message = DevValidMessage.ENCRYPTION_NOT_NULL)
|
||||
private Integer encryptionFlag;
|
||||
|
||||
@Excel(name = "识别码(当为加密版本时必填)", width = 30, orderNum = "15", needMerge = true)
|
||||
private String series;
|
||||
|
||||
@Excel(name = "秘钥(当为加密版本时必填)", width = 30, orderNum = "16", needMerge = true)
|
||||
private String devKey;
|
||||
|
||||
@Excel(name = "所属地市名称", width = 20, orderNum = "19", needMerge = true)
|
||||
private String cityName;
|
||||
|
||||
@Excel(name = "所属供电公司名称", width = 20, orderNum = "20", needMerge = true)
|
||||
private String gdName;
|
||||
|
||||
@Excel(name = "所属电站名称", width = 20, orderNum = "21", needMerge = true)
|
||||
private String subName;
|
||||
|
||||
@Excel(name = "关键信息二维码", width = 20, orderNum = "30", needMerge = true)
|
||||
private String qrCode;
|
||||
|
||||
@Excel(name = "检测次数", width = 15, orderNum = "31", needMerge = true)
|
||||
@NotNull(message = DevValidMessage.RECHECK_NUM_NOT_NULL)
|
||||
private Integer reCheckNum;
|
||||
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public static class ExportData extends PqDevExcel {
|
||||
|
||||
@Excel(name = "设备模式", width = 20, orderNum = "1", needMerge = true)
|
||||
@NotBlank(message = DevValidMessage.PATTERN_NOT_BLANK)
|
||||
private String pattern;
|
||||
|
||||
@Excel(name = "出厂日期(yyyy-MM-dd)", width = 25, format = "yyyy-MM-dd", orderNum = "7", needMerge = true)
|
||||
@NotNull(message = DevValidMessage.CREATEDATETIME_NOT_NULL)
|
||||
private LocalDate createDate;
|
||||
|
||||
@Excel(name = "是否支持系数校准(否\\是)", width = 15, replace = {"否_0", "是_1"}, orderNum = "22", needMerge = true)
|
||||
private Integer factorFlag;
|
||||
|
||||
@Excel(name = "守时检测结果(不合格\\合格\\/)", replace = {"不合格_0", "合格_1", "/_2"}, width = 15, orderNum = "23", needMerge = true)
|
||||
private Integer timeCheckResult;
|
||||
|
||||
@Excel(name = "系数校准结果(不合格\\合格\\/)", width = 15, replace = {"不合格_0", "合格_1", "/_2"}, orderNum = "24", needMerge = true)
|
||||
private Integer factorCheckResult;
|
||||
|
||||
@Excel(name = "检测状态(未检\\检测中\\检测完成\\归档)", width = 15, replace = {"未检_0", "检测中_1", "检测完成_2", "归档_3"}, orderNum = "25", needMerge = true)
|
||||
private Integer checkState;
|
||||
|
||||
@Excel(name = "检测结果(不符合\\符合\\未检)", width = 15, replace = {"不符合_0", "符合_1", "未检_2"}, orderNum = "26", needMerge = true)
|
||||
private Integer checkResult;
|
||||
|
||||
@Excel(name = "报告状态(未生成\\已生成\\未检)", width = 15, replace = {"未生成_0", "已生成_1", "未检_2"}, orderNum = "27", needMerge = true)
|
||||
private Integer reportState;
|
||||
|
||||
@Excel(name = "归档状态(未归档\\归档)", width = 15, replace = {"未归档_0", "归档_1"}, orderNum = "28", needMerge = true)
|
||||
private Integer documentState;
|
||||
|
||||
@Excel(name = "报告路径", width = 20, orderNum = "29", needMerge = true)
|
||||
private String reportPath;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 模拟式和比对式设备导出数据
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public static class SimulateOrDigitalExportData extends ExportData {
|
||||
@Excel(name = "样品编号", width = 40, orderNum = "17", needMerge = true)
|
||||
private String sampleId;
|
||||
|
||||
@Excel(name = "送样日期(yyyy-MM-dd)", width = 25, format = "yyyy-MM-dd", orderNum = "18", needMerge = true)
|
||||
private LocalDate arrivedDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* 比对式设备导出数据
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public static class ContrastExportData extends ExportData {
|
||||
@ExcelCollection(name = "检测点台账", orderNum = "32")
|
||||
List<PqMonitorExcel.ExportData> monitorList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 被检设备导入数据
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public static class ImportData extends PqDevExcel {
|
||||
|
||||
@Excel(name = "出厂日期(yyyy-MM-dd)", width = 25, format = "yyyy-MM-dd", orderNum = "7", needMerge = true)
|
||||
@NotNull(message = DevValidMessage.CREATEDATETIME_NOT_NULL)
|
||||
@DateTimeStrValid(message = DevValidMessage.CREATEDATETIME_FORMAT_ERROR)
|
||||
private String createDate;
|
||||
|
||||
|
||||
@Excel(name = "是否支持系数校准(否\\是)", width = 15, replace = {"否_0", "是_1"}, orderNum = "22", needMerge = true)
|
||||
@NotBlank(message = DevValidMessage.FACTOR_FLAG_NOT_BLANK)
|
||||
private String factorFlag;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 模拟式和比对式设备导入数据
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public static class SimulateOrDigitalImportData extends ImportData {
|
||||
@Excel(name = "样品编号", width = 40, orderNum = "17", needMerge = true)
|
||||
private String sampleId;
|
||||
|
||||
@Excel(name = "送样日期(yyyy-MM-dd)", width = 25, format = "yyyy-MM-dd", orderNum = "18", needMerge = true)
|
||||
@DateTimeStrValid(message = DevValidMessage.ARRIVE_DATE_FORMAT_ERROR)
|
||||
private String arrivedDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* 对比式设备导入数据
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public static class ContrastImportData extends ImportData {
|
||||
@ExcelCollection(name = "检测点台账", orderNum = "32")
|
||||
List<PqMonitorExcel.ImportData> monitorList;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
package com.njcn.gather.device.device.pojo.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
|
||||
import com.njcn.gather.device.monitor.pojo.po.PqMonitor;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2024-12-13
|
||||
*/
|
||||
@Data
|
||||
public class PqDevVO {
|
||||
|
||||
private String id;
|
||||
|
||||
private String name;
|
||||
|
||||
private String pattern;
|
||||
|
||||
private String devType;
|
||||
|
||||
private Integer devChns;
|
||||
|
||||
private Float devVolt;
|
||||
|
||||
private Float devCurr;
|
||||
|
||||
private String manufacturer;
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
@JsonDeserialize(using = LocalDateDeserializer.class)
|
||||
@JsonSerialize(using = LocalDateSerializer.class)
|
||||
private LocalDate createDate;
|
||||
|
||||
private String createId;
|
||||
|
||||
private String hardwareVersion;
|
||||
|
||||
private String softwareVersion;
|
||||
|
||||
private String protocol;
|
||||
|
||||
private String ip;
|
||||
|
||||
private Integer port;
|
||||
|
||||
private Integer encryptionFlag;
|
||||
|
||||
private String series;
|
||||
|
||||
private String devKey;
|
||||
|
||||
private String sampleId;
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
@JsonDeserialize(using = LocalDateDeserializer.class)
|
||||
@JsonSerialize(using = LocalDateSerializer.class)
|
||||
private LocalDate arrivedDate;
|
||||
|
||||
private String cityName;
|
||||
|
||||
private String gdName;
|
||||
|
||||
private String subName;
|
||||
|
||||
private Integer checkState;
|
||||
|
||||
private Integer checkResult;
|
||||
|
||||
private Integer reportState;
|
||||
|
||||
private Integer documentState;
|
||||
|
||||
private String reportPath;
|
||||
|
||||
private String qrCode;
|
||||
|
||||
private Integer reCheckNum;
|
||||
|
||||
private List<PqMonitor> monitorList;
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
package com.njcn.gather.device.device.pojo.vo;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.njcn.gather.device.device.util.DeviceUtil;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author wr
|
||||
* @description 预检测装置报文初始化
|
||||
* @date 2024/12/12 11:21
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class PreDetection {
|
||||
|
||||
/**
|
||||
* 装置ip
|
||||
*/
|
||||
@JSONField(serialize = false)
|
||||
private String devId;
|
||||
|
||||
/**
|
||||
* 装置ip
|
||||
*/
|
||||
@JSONField(serialize = false)
|
||||
private String devName;
|
||||
|
||||
|
||||
/**
|
||||
* 装置ip
|
||||
*/
|
||||
@JSONField(name = "devIP")
|
||||
private String devIP;
|
||||
|
||||
/**
|
||||
* 装置端口
|
||||
*/
|
||||
@JSONField(name = "port")
|
||||
private Integer port;
|
||||
|
||||
/**
|
||||
* 设备类型,字典表
|
||||
*/
|
||||
@JSONField(name = "devType")
|
||||
private String devType;
|
||||
|
||||
/**
|
||||
* icd设备类型
|
||||
*/
|
||||
@JSONField(name = "icdType")
|
||||
private String icdType;
|
||||
|
||||
/**
|
||||
* 装置识别码(3ds加密)
|
||||
*/
|
||||
@JSONField(name = "devCode")
|
||||
private String devCode;
|
||||
|
||||
/**
|
||||
* 装置秘钥(3ds加密)
|
||||
*/
|
||||
@JSONField(name = "devKey")
|
||||
private String devKey;
|
||||
|
||||
@JSONField(serialize = false)
|
||||
private Integer devChns;
|
||||
/**
|
||||
* 监测点信息
|
||||
*/
|
||||
@JSONField(name = "monitorList")
|
||||
private List<MonitorListDTO> monitorList;
|
||||
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public static class MonitorListDTO {
|
||||
/**
|
||||
* 监测点id
|
||||
*/
|
||||
@JSONField(name = "lineId")
|
||||
private String lineId;
|
||||
|
||||
/**
|
||||
* 监测点线路号
|
||||
*/
|
||||
@JSONField(name = "line")
|
||||
private Integer line;
|
||||
|
||||
/**
|
||||
* 监测点线路号
|
||||
*/
|
||||
@JSONField(name = "pt")
|
||||
private Integer pt;
|
||||
|
||||
/**
|
||||
* 监测点线路号
|
||||
*/
|
||||
@JSONField(name = "pt")
|
||||
private Integer ct;
|
||||
}
|
||||
|
||||
public String getDevKey() {
|
||||
if (StrUtil.isNotBlank(devKey)) {
|
||||
String key = DeviceUtil.decoderString(1, devKey);
|
||||
if (StrUtil.isNotBlank(key)) {
|
||||
return key;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getDevCode() {
|
||||
if (StrUtil.isNotBlank(devCode)) {
|
||||
String code = DeviceUtil.decoderString(1, devCode);
|
||||
if (StrUtil.isNotBlank(code)) {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
package com.njcn.gather.device.device.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.gather.device.device.pojo.enums.TimeCheckResultEnum;
|
||||
import com.njcn.gather.device.device.pojo.param.PqDevParam;
|
||||
import com.njcn.gather.device.device.pojo.po.PqDev;
|
||||
import com.njcn.gather.device.device.pojo.vo.PqDevExcel;
|
||||
import com.njcn.gather.device.device.pojo.vo.PqDevVO;
|
||||
import com.njcn.gather.device.device.pojo.vo.PreDetection;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024/11/06
|
||||
*/
|
||||
public interface IPqDevService extends IService<PqDev> {
|
||||
|
||||
/**
|
||||
* 分页查询被检设备列表
|
||||
*
|
||||
* @param queryParam 查询参数
|
||||
* @return 分页数据,包含被检设备列表
|
||||
*/
|
||||
Page<PqDev> listPqDevs(PqDevParam.QueryParam queryParam);
|
||||
|
||||
/**
|
||||
* 新增被检设备信息
|
||||
*
|
||||
* @param pqDevParam 被检设备信息
|
||||
* @return 新增成功返回true,否则返回false
|
||||
*/
|
||||
boolean addPqDev(PqDevParam pqDevParam);
|
||||
|
||||
/**
|
||||
* 修改被检设备信息
|
||||
*
|
||||
* @param updateParam 被检设备信息
|
||||
* @return 修改成功返回true,否则返回false
|
||||
*/
|
||||
boolean updatePqDev(PqDevParam.UpdateParam updateParam);
|
||||
|
||||
/**
|
||||
* 删除被检设备信息
|
||||
*
|
||||
* @param param 被检设备信息
|
||||
* @return 删除成功返回true,否则返回false
|
||||
*/
|
||||
boolean deletePqDev(PqDevParam.DeleteParam param);
|
||||
|
||||
/**
|
||||
* 批量更新被检设备守时检测结果
|
||||
*
|
||||
* @param ids 被检设备id列表
|
||||
* @param result 守时检测结果
|
||||
* @return 更新成功返回true,否则返回false
|
||||
*/
|
||||
boolean updatePqDevTimeCheckResult(List<String> ids, TimeCheckResultEnum result);
|
||||
|
||||
/**
|
||||
* 获取模拟式||数字式设备导出时所需的数据
|
||||
*
|
||||
* @param queryParam 查询参数
|
||||
* @return
|
||||
*/
|
||||
List<PqDevExcel.SimulateOrDigitalExportData> getSimulateOrDigitExportData(PqDevParam.QueryParam queryParam);
|
||||
|
||||
/**
|
||||
* 获取比对式设备导出时所需的数据
|
||||
*
|
||||
* @param queryParam 查询参数
|
||||
* @return 比对式设备导出时所需的数据
|
||||
*/
|
||||
List<PqDevExcel.ContrastExportData> getContrastExportData(PqDevParam.QueryParam queryParam);
|
||||
|
||||
/**
|
||||
* 下载模板文件
|
||||
*/
|
||||
void downloadTemplate();
|
||||
|
||||
/**
|
||||
* 批量导入被检设备信息
|
||||
*
|
||||
* @param sgEventExcels 批量导入的数据
|
||||
*/
|
||||
void importContrastData(List<PqDevExcel.ContrastImportData> sgEventExcels);
|
||||
|
||||
/**
|
||||
* 批量导入被检设备信息
|
||||
*
|
||||
* @param sgEventExcels 批量导入的数据
|
||||
*/
|
||||
void importSimulateAndDigitalData(List<PqDevExcel.SimulateOrDigitalImportData> sgEventExcels);
|
||||
|
||||
/**
|
||||
* 获取所有未绑定的设备
|
||||
*
|
||||
* @param pattern 模式Id
|
||||
* @return 未绑定的设备列表
|
||||
*/
|
||||
List<Map<String, Object>> listUnbound(String pattern);
|
||||
|
||||
/**
|
||||
* 根据计划id获取绑定的设备
|
||||
*
|
||||
* @param param 计划id
|
||||
* @return 绑定的设备列表
|
||||
*/
|
||||
List<PqDev> listByPlanId(PqDevParam.QueryParam param);
|
||||
|
||||
/**
|
||||
* 绑定计划
|
||||
*
|
||||
* @param planId 计划id
|
||||
* @param devIds 设备id列表
|
||||
* @return 绑定成功返回true,否则返回false
|
||||
*/
|
||||
boolean bind(String planId, List<String> devIds);
|
||||
|
||||
/**
|
||||
* 获取饼图数据
|
||||
*
|
||||
* @param planId 检测计划id
|
||||
* @return 饼图数据
|
||||
*/
|
||||
//List<List<Map<String, Object>>> getPieData(String planId);
|
||||
|
||||
/**
|
||||
* 根据id获取被检设备信息
|
||||
*
|
||||
* @param id 被检设备id
|
||||
* @return
|
||||
*/
|
||||
PqDevVO getPqDevById(String id);
|
||||
|
||||
/**
|
||||
* 获取所有非未检测状态的设备
|
||||
*
|
||||
* @return 所有非未检测状态的设备列表
|
||||
*/
|
||||
List<PqDev> listUnchecked();
|
||||
|
||||
/**
|
||||
* 可视化,各种id回显字典值,解码等操作
|
||||
*
|
||||
* @param sourceList
|
||||
*/
|
||||
void visualize(List<PqDev> sourceList);
|
||||
|
||||
/**
|
||||
* 逆向可视化
|
||||
*/
|
||||
void reverseVisualize(List<PqDev> sourceList);
|
||||
|
||||
/**
|
||||
* 获取装置信息和装置下监测点信息
|
||||
*
|
||||
* @param devIds
|
||||
* @return: java.util.List<com.njcn.gather.device.device.pojo.vo.PreDetection>
|
||||
* @Author: wr
|
||||
* @Date: 2024/12/12 15:50
|
||||
*/
|
||||
List<PreDetection> getDevInfo(@Param("devIds") List<String> devIds);
|
||||
|
||||
/**
|
||||
* 设备归档操作
|
||||
* @param id 设备id
|
||||
* @return 归档成功返回true,否则返回false
|
||||
*/
|
||||
boolean documented(String id);
|
||||
}
|
||||
@@ -0,0 +1,517 @@
|
||||
package com.njcn.gather.device.device.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.common.pojo.enums.common.DataStateEnum;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.db.mybatisplus.constant.DbConstant;
|
||||
import com.njcn.gather.device.device.mapper.PqDevMapper;
|
||||
import com.njcn.gather.device.device.pojo.enums.TimeCheckResultEnum;
|
||||
import com.njcn.gather.device.device.pojo.param.PqDevParam;
|
||||
import com.njcn.gather.device.device.pojo.po.PqDev;
|
||||
import com.njcn.gather.device.device.pojo.vo.PqDevExcel;
|
||||
import com.njcn.gather.device.device.pojo.vo.PqDevVO;
|
||||
import com.njcn.gather.device.device.pojo.vo.PreDetection;
|
||||
import com.njcn.gather.device.device.service.IPqDevService;
|
||||
import com.njcn.gather.device.device.util.DeviceUtil;
|
||||
import com.njcn.gather.device.monitor.pojo.po.PqMonitor;
|
||||
import com.njcn.gather.device.monitor.pojo.vo.PqMonitorExcel;
|
||||
import com.njcn.gather.device.monitor.service.IPqMonitorService;
|
||||
import com.njcn.gather.device.pojo.enums.*;
|
||||
import com.njcn.gather.system.dictionary.pojo.po.DictData;
|
||||
import com.njcn.gather.system.dictionary.service.IDictDataService;
|
||||
import com.njcn.web.factory.PageFactory;
|
||||
import com.njcn.web.utils.ExcelUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024/11/06
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements IPqDevService {
|
||||
|
||||
private final IDictDataService dictDataService;
|
||||
private final IPqMonitorService pqMonitorService;
|
||||
|
||||
@Override
|
||||
public Page<PqDev> listPqDevs(PqDevParam.QueryParam queryParam) {
|
||||
Page<PqDev> page = this.page(new Page<>(PageFactory.getPageNum(queryParam), PageFactory.getPageSize(queryParam)), this.getQueryWrapper(queryParam));
|
||||
page.getRecords().forEach(p -> {
|
||||
if (ObjectUtil.isNotNull(p.getSeries())) {
|
||||
p.setSeries(DeviceUtil.decoderString(1, p.getSeries()));
|
||||
}
|
||||
if (ObjectUtil.isNotNull(p.getDevKey())) {
|
||||
p.setDevKey(DeviceUtil.decoderString(1, p.getDevKey()));
|
||||
}
|
||||
});
|
||||
return page;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public boolean addPqDev(PqDevParam pqDevParam) {
|
||||
this.checkRepeat(pqDevParam, false);
|
||||
|
||||
PqDev pqDev = new PqDev();
|
||||
BeanUtil.copyProperties(pqDevParam, pqDev);
|
||||
if (pqDevParam.getEncryptionFlag() == 1) {
|
||||
if (StrUtil.isNotBlank(pqDevParam.getSeries()) && StrUtil.isNotBlank(pqDevParam.getDevKey())) {
|
||||
pqDev.setSeries(DeviceUtil.encodeString(1, pqDev.getSeries()));
|
||||
pqDev.setDevKey(DeviceUtil.encodeString(1, pqDev.getDevKey()));
|
||||
} else {
|
||||
throw new BusinessException(DevResponseEnum.SERIES_AND_DEVKEY_NOT_BLANK);
|
||||
}
|
||||
}
|
||||
// 新增时默认设置
|
||||
pqDev.setTimeCheckResult(TimeCheckResultEnum.UNKNOWN.getValue());
|
||||
pqDev.setFactorCheckResult(FactorCheckResultEnum.UNKNOWN.getValue());
|
||||
pqDev.setCheckState(CheckStateEnum.UNCHECKED.getValue());
|
||||
pqDev.setReportState(DevReportStateEnum.UNCHECKED.getValue());
|
||||
pqDev.setDocumentState(DevDocumentStateEnum.UNDOCUMENTED.getValue());
|
||||
pqDev.setCheckResult(CheckResultEnum.UNCHECKED.getValue());
|
||||
String id = UUID.randomUUID().toString().replaceAll("-", "");
|
||||
pqDev.setId(id);
|
||||
// 比对式设备添加监测点
|
||||
if (PatternEnum.CONTRAST.getValue().equals(dictDataService.getDictDataById(pqDevParam.getPattern()).getCode())) {
|
||||
if (ObjectUtil.isNotEmpty(pqDevParam.getMonitorList())) {
|
||||
pqMonitorService.addPqMonitorByDevId(id, pqDevParam.getMonitorList());
|
||||
}
|
||||
}
|
||||
pqDev.setState(DataStateEnum.ENABLE.getCode());
|
||||
return this.save(pqDev);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public boolean updatePqDev(PqDevParam.UpdateParam updateParam) {
|
||||
this.checkRepeat(updateParam, true);
|
||||
|
||||
PqDev pqDev = new PqDev();
|
||||
BeanUtil.copyProperties(updateParam, pqDev);
|
||||
if (Objects.nonNull(pqDev.getSeries())) {
|
||||
pqDev.setSeries(DeviceUtil.encodeString(1, pqDev.getSeries()));
|
||||
}
|
||||
if (Objects.nonNull(pqDev.getDevKey())) {
|
||||
pqDev.setDevKey(DeviceUtil.encodeString(1, pqDev.getDevKey()));
|
||||
}
|
||||
// 比对式设备修改监测点
|
||||
if (PatternEnum.CONTRAST.getValue().equals(dictDataService.getDictDataById(updateParam.getPattern()).getCode())) {
|
||||
if (ObjectUtil.isNotEmpty(updateParam.getMonitorList())) {
|
||||
pqMonitorService.updatePqMonitorByDevId(updateParam.getId(), updateParam.getMonitorList());
|
||||
}
|
||||
}
|
||||
return this.updateById(pqDev);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public boolean deletePqDev(PqDevParam.DeleteParam param) {
|
||||
if (PatternEnum.CONTRAST.getValue().equals(dictDataService.getDictDataById(param.getPattern()).getCode())) {
|
||||
for (String id : param.getIds()) {
|
||||
if (ObjectUtils.isEmpty(pqMonitorService.listPqMonitorByDevId(id))) {
|
||||
throw new BusinessException(DevResponseEnum.PQ_DEV_HAS_MONITOR);
|
||||
}
|
||||
}
|
||||
}
|
||||
return this.lambdaUpdate().set(PqDev::getState, DataStateEnum.DELETED.getCode()).in(PqDev::getId, param.getIds()).update();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public boolean updatePqDevTimeCheckResult(List<String> ids, TimeCheckResultEnum result) {
|
||||
return this.lambdaUpdate().set(PqDev::getTimeCheckResult, result.getValue()).in(PqDev::getId, ids).update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PqDevExcel.SimulateOrDigitalExportData> getSimulateOrDigitExportData(PqDevParam.QueryParam queryParam) {
|
||||
List<PqDev> pqDevs = this.list(this.getQueryWrapper(queryParam));
|
||||
if (ObjectUtil.isNotNull(pqDevs)) {
|
||||
this.visualize(pqDevs);
|
||||
List<PqDevExcel.SimulateOrDigitalExportData> pqDevExcels = BeanUtil.copyToList(pqDevs, PqDevExcel.SimulateOrDigitalExportData.class);
|
||||
return pqDevExcels;
|
||||
} else {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PqDevExcel.ContrastExportData> getContrastExportData(PqDevParam.QueryParam queryParam) {
|
||||
List<PqDev> pqDevs = this.list(this.getQueryWrapper(queryParam));
|
||||
if (ObjectUtil.isNotNull(pqDevs)) {
|
||||
this.visualize(pqDevs);
|
||||
List<PqDevExcel.ContrastExportData> pqDevExcels = BeanUtil.copyToList(pqDevs, PqDevExcel.ContrastExportData.class);
|
||||
for (int i = 0; i < pqDevs.size(); i++) {
|
||||
List<PqMonitorExcel.ExportData> monitorExportList = BeanUtil.copyToList(pqMonitorService.listPqMonitorByDevId(pqDevs.get(i).getId()), PqMonitorExcel.ExportData.class);
|
||||
monitorExportList.forEach(monitor -> {
|
||||
monitor.setPtType(dictDataService.getDictDataById(monitor.getPtType()).getName());
|
||||
});
|
||||
pqDevExcels.get(i).setMonitorList(monitorExportList);
|
||||
}
|
||||
return pqDevExcels;
|
||||
} else {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downloadTemplate() {
|
||||
ExcelUtil.exportExcel("被检设备模板.xlsx", PqDevExcel.ContrastImportData.class, Collections.emptyList());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public void importContrastData(List<PqDevExcel.ContrastImportData> pqDevExcelList) {
|
||||
List<PqDev> devList = new ArrayList<>();
|
||||
List<PqMonitor> monitorList = new ArrayList<>();
|
||||
String patternId = dictDataService.getDictDataByName(PatternEnum.CONTRAST.getMsg()).getId();
|
||||
pqDevExcelList.forEach(pqDevExcel -> {
|
||||
PqDev pqDev = new PqDev();
|
||||
BeanUtil.copyProperties(pqDevExcel, pqDev);
|
||||
pqDev.setId(UUID.randomUUID().toString().replaceAll("-", ""));
|
||||
pqDev.setPattern(patternId);
|
||||
// pqDev.setTimeCheckResult(TimeCheckResultEnum.UNKNOWN.getValue());
|
||||
// pqDev.setFactorCheckResult(FactorCheckResultEnum.UNKNOWN.getValue());
|
||||
// pqDev.setCheckState(CheckStateEnum.UNCHECKED.getValue());
|
||||
// pqDev.setReportState(DevReportStateEnum.UNCHECKED.getValue());
|
||||
// pqDev.setDocumentState(DevDocumentStateEnum.UNDOCUMENTED.getValue());
|
||||
// pqDev.setCheckResult(CheckResultEnum.UNCHECKED.getValue());
|
||||
devList.add(pqDev);
|
||||
|
||||
// 新增与被检设备绑定的监测点
|
||||
List<PqMonitor> monitors = pqDevExcel.getMonitorList().stream()
|
||||
.map(monitor -> {
|
||||
PqMonitor monitorPo = new PqMonitor();
|
||||
BeanUtil.copyProperties(monitor, monitorPo);
|
||||
monitorPo.setId(UUID.randomUUID().toString().replaceAll("-", ""));
|
||||
monitorPo.setDevId(pqDev.getId());
|
||||
monitorPo.setPtType(dictDataService.getDictDataByName(monitor.getPtType()).getId());
|
||||
return monitorPo;
|
||||
}).collect(Collectors.toList());
|
||||
monitorList.addAll(monitors);
|
||||
});
|
||||
|
||||
//逆向可视化
|
||||
this.reverseVisualize(devList);
|
||||
this.saveBatch(devList);
|
||||
|
||||
pqMonitorService.saveBatch(monitorList);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public void importSimulateAndDigitalData(List<PqDevExcel.SimulateOrDigitalImportData> pqDevExcelList) {
|
||||
List<PqDev> pqDevList = BeanUtil.copyToList(pqDevExcelList, PqDev.class);
|
||||
//逆向可视化
|
||||
this.reverseVisualize(pqDevList);
|
||||
this.saveBatch(pqDevList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> listUnbound(String pattern) {
|
||||
List<PqDev> pqDevList = this.lambdaQuery().eq(PqDev::getPattern, pattern).eq(PqDev::getState, DataStateEnum.ENABLE.getCode()).isNull(PqDev::getPlanId).list();
|
||||
List<Map<String, Object>> result = pqDevList.stream().map(pqDev -> {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("id", pqDev.getId());
|
||||
map.put("name", pqDev.getName());
|
||||
return map;
|
||||
}).collect(Collectors.toList());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PqDev> listByPlanId(PqDevParam.QueryParam param) {
|
||||
List<PqDev> pqDevList = this.lambdaQuery()
|
||||
.eq(StrUtil.isNotBlank(param.getPlanId()), PqDev::getPlanId, param.getPlanId())
|
||||
.like(StrUtil.isNotBlank(param.getName()), PqDev::getName, param.getName())
|
||||
.in(ObjectUtil.isNotEmpty(param.getCheckStateList()), PqDev::getCheckState, param.getCheckStateList())
|
||||
.eq(ObjectUtil.isNotNull(param.getCheckResult()), PqDev::getCheckResult, param.getCheckResult())
|
||||
.eq(ObjectUtil.isNotNull(param.getCheckResult()), PqDev::getCheckResult, param.getCheckResult())
|
||||
.eq(ObjectUtil.isNotNull(param.getReportState()), PqDev::getReportState, param.getReportState())
|
||||
.eq(PqDev::getState, DataStateEnum.ENABLE.getCode()).list();
|
||||
// List<Map<String, Object>> result = pqDevList.stream().map(pqDev -> {
|
||||
// Map<String, Object> map = new HashMap<>();
|
||||
// map.put("id", pqDev.getId());
|
||||
// map.put("name", pqDev.getName());
|
||||
// return map;
|
||||
// }).collect(Collectors.toList());
|
||||
return pqDevList;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public boolean bind(String planId, List<String> devIds) {
|
||||
this.lambdaUpdate().set(PqDev::getPlanId, null).eq(PqDev::getPlanId, planId).update();
|
||||
|
||||
if (ObjectUtil.isNotEmpty(devIds)) {
|
||||
this.lambdaUpdate().set(PqDev::getPlanId, planId).in(PqDev::getId, devIds).update();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public List getPieData(String planId) {
|
||||
// List<PqDev> pqDevList = this.lambdaQuery().eq(PqDev::getPlanId, planId).eq(PqDev::getState, DataStateEnum.ENABLE.getCode()).list();
|
||||
// Map<Integer, Long> checkStateMap = pqDevList.stream().collect(Collectors.groupingBy(PqDev::getCheckState, Collectors.counting()));
|
||||
// Map<Integer, Long> checkResultMap = pqDevList.stream().collect(Collectors.groupingBy(PqDev::getCheckResult, Collectors.counting()));
|
||||
// Map<Integer, Long> reportStateMap = pqDevList.stream().collect(Collectors.groupingBy(PqDev::getReportState, Collectors.counting()));
|
||||
//
|
||||
// List<Map<String, Object>> checkStateData = getCheckStatePieData(checkStateMap);
|
||||
// List<Map<String, Object>> checkResultData = getCheckResultPieData(checkResultMap);
|
||||
// List<Map<String, Object>> reportStateData = getReportStatePieData(reportStateMap);
|
||||
//
|
||||
// List<List<Map<String, Object>>> result = new ArrayList<>();
|
||||
// result.add(checkStateData);
|
||||
// result.add(checkResultData);
|
||||
// result.add(reportStateData);
|
||||
// return result;
|
||||
// }
|
||||
|
||||
@Override
|
||||
public PqDevVO getPqDevById(String id) {
|
||||
PqDev pqDev = this.getById(id);
|
||||
PqDevVO pqDevVO = new PqDevVO();
|
||||
BeanUtil.copyProperties(pqDev, pqDevVO);
|
||||
List<PqMonitor> monitorList = pqMonitorService.listPqMonitorByDevId(id);
|
||||
if (ObjectUtil.isNotEmpty(monitorList)) {
|
||||
pqDevVO.setMonitorList(monitorList);
|
||||
}
|
||||
return pqDevVO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PqDev> listUnchecked() {
|
||||
return this.lambdaQuery().eq(PqDev::getCheckState, CheckStateEnum.UNCHECKED.getValue()).eq(PqDev::getState, DataStateEnum.ENABLE.getCode()).list();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visualize(List<PqDev> sourceList) {
|
||||
sourceList.forEach(pqDev -> {
|
||||
if (StrUtil.isNotBlank(pqDev.getPattern())) {
|
||||
DictData dictData = dictDataService.getDictDataById(pqDev.getPattern());
|
||||
if (ObjectUtil.isNotNull(dictData)) {
|
||||
pqDev.setPattern(dictData.getName());
|
||||
}
|
||||
}
|
||||
if (StrUtil.isNotBlank(pqDev.getDevType())) {
|
||||
DictData dictData = dictDataService.getDictDataById(pqDev.getDevType());
|
||||
if (ObjectUtil.isNotNull(dictData)) {
|
||||
pqDev.setDevType(dictData.getName());
|
||||
}
|
||||
}
|
||||
if (StrUtil.isNotBlank(pqDev.getManufacturer())) {
|
||||
DictData dictData = dictDataService.getDictDataById(pqDev.getManufacturer());
|
||||
if (ObjectUtil.isNotNull(dictData)) {
|
||||
pqDev.setManufacturer(dictData.getName());
|
||||
}
|
||||
}
|
||||
if (StrUtil.isNotBlank(pqDev.getProtocol())) {
|
||||
DictData dictData = dictDataService.getDictDataById(pqDev.getProtocol());
|
||||
if (ObjectUtil.isNotNull(dictData)) {
|
||||
pqDev.setProtocol(dictData.getName());
|
||||
}
|
||||
}
|
||||
if (StrUtil.isNotBlank(pqDev.getSeries())) {
|
||||
pqDev.setSeries(DeviceUtil.decoderString(1, pqDev.getSeries()));
|
||||
}
|
||||
if (StrUtil.isNotBlank(pqDev.getDevKey())) {
|
||||
pqDev.setDevKey(DeviceUtil.decoderString(1, pqDev.getDevKey()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reverseVisualize(List<PqDev> sourceList) {
|
||||
sourceList.forEach(pqDev -> {
|
||||
// if (StrUtil.isNotBlank(pqDev.getPattern())) {
|
||||
// DictData dictData = dictDataService.getDictDataByName(pqDev.getPattern());
|
||||
// if (ObjectUtil.isNotNull(dictData)) {
|
||||
// pqDev.setPattern(dictData.getId());
|
||||
// }
|
||||
// }
|
||||
if (StrUtil.isNotBlank(pqDev.getDevType())) {
|
||||
DictData dictData = dictDataService.getDictDataByName(pqDev.getDevType());
|
||||
if (ObjectUtil.isNotNull(dictData)) {
|
||||
pqDev.setDevType(dictData.getId());
|
||||
}
|
||||
}
|
||||
if (StrUtil.isNotBlank(pqDev.getManufacturer())) {
|
||||
DictData dictData = dictDataService.getDictDataByName(pqDev.getManufacturer());
|
||||
if (ObjectUtil.isNotNull(dictData)) {
|
||||
pqDev.setManufacturer(dictData.getId());
|
||||
}
|
||||
}
|
||||
if (StrUtil.isNotBlank(pqDev.getProtocol())) {
|
||||
DictData dictData = dictDataService.getDictDataByName(pqDev.getProtocol());
|
||||
if (ObjectUtil.isNotNull(dictData)) {
|
||||
pqDev.setProtocol(dictData.getId());
|
||||
}
|
||||
}
|
||||
if (StrUtil.isNotBlank(pqDev.getSeries())) {
|
||||
pqDev.setSeries(DeviceUtil.encodeString(1, pqDev.getSeries()));
|
||||
}
|
||||
if (StrUtil.isNotBlank(pqDev.getDevKey())) {
|
||||
pqDev.setDevKey(DeviceUtil.encodeString(1, pqDev.getDevKey()));
|
||||
}
|
||||
pqDev.setState(DataStateEnum.ENABLE.getCode());
|
||||
pqDev.setTimeCheckResult(TimeCheckResultEnum.UNKNOWN.getValue());
|
||||
pqDev.setFactorCheckResult(FactorCheckResultEnum.UNKNOWN.getValue());
|
||||
pqDev.setCheckState(CheckStateEnum.UNCHECKED.getValue());
|
||||
pqDev.setReportState(DevReportStateEnum.UNCHECKED.getValue());
|
||||
pqDev.setDocumentState(DevDocumentStateEnum.UNDOCUMENTED.getValue());
|
||||
pqDev.setCheckResult(CheckResultEnum.UNCHECKED.getValue());
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取查询条件wrapper
|
||||
*
|
||||
* @param queryParam 查询条件
|
||||
* @return
|
||||
*/
|
||||
private Wrapper getQueryWrapper(PqDevParam.QueryParam queryParam) {
|
||||
QueryWrapper<PqDev> queryWrapper = new QueryWrapper<>();
|
||||
if (ObjectUtil.isNotNull(queryParam)) {
|
||||
queryWrapper
|
||||
.like(StrUtil.isNotBlank(queryParam.getName()), "pq_dev.name", queryParam.getName())
|
||||
.eq(StrUtil.isNotBlank(queryParam.getPattern()), "pq_dev.pattern", queryParam.getPattern())
|
||||
.eq(StrUtil.isNotBlank(queryParam.getManufacturer()), "pq_dev.manufacturer", queryParam.getManufacturer())
|
||||
.between(ObjectUtil.isAllNotEmpty(queryParam.getSearchBeginTime(), queryParam.getSearchEndTime()), "pq_dev.Create_Date", queryParam.getSearchBeginTime(), queryParam.getSearchEndTime());
|
||||
//排序
|
||||
if (ObjectUtil.isAllNotEmpty(queryParam.getSortBy(), queryParam.getOrderBy())) {
|
||||
queryWrapper.orderBy(true, queryParam.getOrderBy().equals(DbConstant.ASC), StrUtil.toUnderlineCase(queryParam.getSortBy()));
|
||||
}
|
||||
}
|
||||
queryWrapper.eq("pq_dev.state", DataStateEnum.ENABLE.getCode()).orderBy(true, true, "pq_dev.Create_Time");
|
||||
return queryWrapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PreDetection> getDevInfo(List<String> devIds) {
|
||||
List<PreDetection> preDetections = this.baseMapper.selectDevInfo(devIds);
|
||||
for (PreDetection preDetection : preDetections) {
|
||||
List<PreDetection.MonitorListDTO> monitorList = preDetection.getMonitorList();
|
||||
if(CollUtil.isEmpty(monitorList)){
|
||||
PreDetection.MonitorListDTO monitorListDTO;
|
||||
for (int i = 1; i <= preDetection.getDevChns(); i++) {
|
||||
monitorListDTO=new PreDetection.MonitorListDTO();
|
||||
monitorListDTO.setLineId(preDetection.getDevIP()+"_"+i);
|
||||
monitorListDTO.setLine(i);
|
||||
monitorListDTO.setPt(1);
|
||||
monitorListDTO.setPt(1);
|
||||
monitorList.add(monitorListDTO);
|
||||
}
|
||||
preDetection.setMonitorList(monitorList);
|
||||
}
|
||||
}
|
||||
return preDetections;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public boolean documented(String id) {
|
||||
// 只有检测完成的设备才可以进行归档
|
||||
PqDev pqDev = this.getById(id);
|
||||
if (ObjectUtil.isNotNull(pqDev) && !pqDev.getCheckState().equals(CheckStateEnum.CHECKED.getValue())) {
|
||||
return this.lambdaUpdate()
|
||||
.set(PqDev::getDocumentState, DevDocumentStateEnum.DOCUMENTED.getValue())
|
||||
.set(PqDev::getCheckState, CheckStateEnum.DOCUMENTED.getValue())
|
||||
.eq(PqDev::getId, id)
|
||||
.update();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取检测状态饼状图数据
|
||||
*
|
||||
* @param map 检测状态分组map
|
||||
* @return 检测状态饼状图数据
|
||||
*/
|
||||
// private List<Map<String, Object>> getCheckStatePieData(Map<Integer, Long> map) {
|
||||
// List<Map<String, Object>> result = new ArrayList<>();
|
||||
// for (CheckStateEnum e : CheckStateEnum.values()) {
|
||||
// Map<String, Object> temp = new HashMap<>();
|
||||
// temp.put("name", e.getMsg());
|
||||
// temp.put("value", map.getOrDefault(e.getValue(), 0L));
|
||||
// result.add(temp);
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
|
||||
/**
|
||||
* 获取检测结果饼状图数据
|
||||
*
|
||||
* @param map 检测结果分组map
|
||||
* @return 检测结果饼状图数据
|
||||
*/
|
||||
// private List<Map<String, Object>> getCheckResultPieData(Map<Integer, Long> map) {
|
||||
// List<Map<String, Object>> result = new ArrayList<>();
|
||||
// for (CheckResultEnum e : CheckResultEnum.values()) {
|
||||
// Map<String, Object> temp = new HashMap<>();
|
||||
// temp.put("name", e.getMsg());
|
||||
// temp.put("value", map.getOrDefault(e.getValue(), 0L));
|
||||
// result.add(temp);
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
|
||||
/**
|
||||
* 获取报告状态饼状图数据
|
||||
*
|
||||
* @param map 报告状态分组map
|
||||
* @return 报告状态饼状图数据
|
||||
*/
|
||||
// private List<Map<String, Object>> getReportStatePieData(Map<Integer, Long> map) {
|
||||
// List<Map<String, Object>> result = new ArrayList<>();
|
||||
// for (DevReportStateEnum e : DevReportStateEnum.values()) {
|
||||
// Map<String, Object> temp = new HashMap<>();
|
||||
// temp.put("name", e.getMsg());
|
||||
// temp.put("value", map.getOrDefault(e.getValue(), 0L));
|
||||
// result.add(temp);
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
|
||||
/**
|
||||
* 检查设备是否重复
|
||||
*
|
||||
* @param param 设备参数
|
||||
* @param isExcludeSelf 是否排除自己
|
||||
*/
|
||||
private void checkRepeat(PqDevParam param, boolean isExcludeSelf) {
|
||||
QueryWrapper<PqDev> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper
|
||||
.eq("state", DataStateEnum.ENABLE.getCode())
|
||||
.and(q -> q.eq("name", param.getName())
|
||||
.eq("pattern", param.getPattern())
|
||||
.eq("manufacturer", param.getManufacturer())
|
||||
.eq("Dev_Type", param.getDevType()).or()
|
||||
.eq("Create_Id", param.getCreateId())); //设备序列号重复
|
||||
if (isExcludeSelf) {
|
||||
if (param instanceof PqDevParam.UpdateParam) {
|
||||
queryWrapper.ne("id", ((PqDevParam.UpdateParam) param).getId());
|
||||
}
|
||||
}
|
||||
int count = this.count(queryWrapper);
|
||||
if (count > 0) {
|
||||
throw new BusinessException(DevResponseEnum.PQ_DEV_REPEAT);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.njcn.gather.device.device.util;
|
||||
|
||||
import com.njcn.common.utils.sm.Sm4Utils;
|
||||
import com.njcn.common.utils.sm.ThreeDesUtil;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
|
||||
/**
|
||||
* pqs
|
||||
*
|
||||
* @author cdf
|
||||
* @date 2022/1/6
|
||||
*/
|
||||
public class DeviceUtil {
|
||||
|
||||
|
||||
/**
|
||||
* cd 系统配置的解密方式
|
||||
* content 需要解密的内容
|
||||
* 解密对应内容
|
||||
*
|
||||
* @author cdf
|
||||
* @date 2021/10/12
|
||||
*/
|
||||
public static String decoderString(Integer cd, String content) {
|
||||
String seriesTmp = null;
|
||||
if (cd == 0) {
|
||||
seriesTmp = Base64.decodeBase64(content).toString();
|
||||
} else if (cd == 1) {
|
||||
seriesTmp = ThreeDesUtil.decryptThreeDes(content);
|
||||
} else if (cd == 2) {
|
||||
//SM4加密密码
|
||||
String secretkey = Sm4Utils.globalSecretKey;
|
||||
Sm4Utils sm4 = new Sm4Utils(secretkey);
|
||||
seriesTmp = sm4.decryptData_ECB(content);
|
||||
}
|
||||
return seriesTmp;
|
||||
}
|
||||
|
||||
/**
|
||||
* cd 系统配置的加密方式
|
||||
* content 需要加密的内容
|
||||
* 加密对应内容
|
||||
*
|
||||
* @author cdf
|
||||
* @date 2021/10/12
|
||||
*/
|
||||
public static String encodeString(Integer cd, String content) {
|
||||
String key = null;
|
||||
if (cd == 0) {
|
||||
key = Base64.encodeBase64String(content.getBytes());
|
||||
} else if (cd == 1) {
|
||||
key = ThreeDesUtil.encryptThreeDes(content);
|
||||
} else if (cd == 2) {
|
||||
//SM4加密密码
|
||||
// String secretkey = Sm4Utils.globalSecretKey;
|
||||
// Sm4Utils sm4 = new Sm4Utils(secretkey);
|
||||
// key = sm4.encryptData_ECB(content);
|
||||
}
|
||||
return key;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,143 @@
|
||||
package com.njcn.gather.device.err.controller;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
import com.njcn.common.pojo.constant.OperateType;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.LogUtil;
|
||||
import com.njcn.gather.device.err.pojo.param.PqErrSysParam;
|
||||
import com.njcn.gather.device.err.pojo.po.PqErrSys;
|
||||
import com.njcn.gather.device.err.pojo.vo.PqErrSysDtlsVO;
|
||||
import com.njcn.gather.device.err.service.IPqErrSysService;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import com.njcn.web.utils.HttpResultUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024-11-27
|
||||
*/
|
||||
@Slf4j
|
||||
@Api(tags = "误差体系管理")
|
||||
@RestController
|
||||
@RequestMapping("/pqErrSys")
|
||||
@RequiredArgsConstructor
|
||||
public class PqErrSysController extends BaseController {
|
||||
private final IPqErrSysService pqErrSysService;
|
||||
|
||||
@OperateInfo
|
||||
@PostMapping("/list")
|
||||
@ApiOperation("分页查询误差体系")
|
||||
@ApiImplicitParam(name = "param", value = "查询参数", required = true)
|
||||
public HttpResult<Page<PqErrSys>> list(@RequestBody @Validated PqErrSysParam.QueryParam param) {
|
||||
String methodDescribe = getMethodDescribe("list");
|
||||
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, param);
|
||||
Page<PqErrSys> result = pqErrSysService.listPqErrSys(param);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo
|
||||
@GetMapping("/getById")
|
||||
@ApiOperation("根据id查询误差体系")
|
||||
@ApiImplicitParam(name = "id", value = "查询参数", required = true)
|
||||
public HttpResult<PqErrSys> getPqErrSysById(@RequestParam("id") String id) {
|
||||
String methodDescribe = getMethodDescribe("getById");
|
||||
LogUtil.njcnDebug(log, "{},查询ID为:{}", methodDescribe, id);
|
||||
PqErrSys result = pqErrSysService.getPqErrSysById(id);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(operateType = OperateType.ADD)
|
||||
@PostMapping("/add")
|
||||
@ApiOperation("新增误差体系")
|
||||
@ApiImplicitParam(name = "param", value = "误差体系", required = true)
|
||||
public HttpResult<Object> add(@RequestBody @Validated PqErrSysParam param) {
|
||||
String methodDescribe = getMethodDescribe("add");
|
||||
LogUtil.njcnDebug(log, "{},新增数据为:{}", methodDescribe, param);
|
||||
boolean result = pqErrSysService.addPqErrSys(param);
|
||||
if (result) {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
} else {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
|
||||
}
|
||||
}
|
||||
|
||||
@OperateInfo(operateType = OperateType.UPDATE)
|
||||
@PostMapping("/update")
|
||||
@ApiOperation("修改误差体系")
|
||||
@ApiImplicitParam(name = "param", value = "误差体系", required = true)
|
||||
public HttpResult<Object> update(@RequestBody @Validated PqErrSysParam.UpdateParam param) {
|
||||
String methodDescribe = getMethodDescribe("update");
|
||||
LogUtil.njcnDebug(log, "{},修改数据为:{}", methodDescribe, param);
|
||||
boolean result = pqErrSysService.updatePqErrSys(param);
|
||||
if (result) {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
} else {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
|
||||
}
|
||||
}
|
||||
|
||||
@OperateInfo(operateType = OperateType.DELETE)
|
||||
@PostMapping("/delete")
|
||||
@ApiOperation("删除误差体系")
|
||||
@ApiImplicitParam(name = "ids", value = "误差体系id", required = true)
|
||||
public HttpResult<Object> delete(@RequestBody List<String> ids) {
|
||||
String methodDescribe = getMethodDescribe("delete");
|
||||
LogUtil.njcnDebug(log, "{},删除ID数据为:{}", methodDescribe, String.join(StrUtil.COMMA, ids));
|
||||
boolean result = pqErrSysService.deletePqErrSys(ids);
|
||||
if (result) {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
} else {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
|
||||
}
|
||||
}
|
||||
|
||||
@OperateInfo()
|
||||
@GetMapping("/getDetail")
|
||||
@ApiOperation("查看误差体系项详情")
|
||||
@ApiImplicitParam(name = "id", value = "误差体系id", required = true)
|
||||
public HttpResult<List<PqErrSysDtlsVO>> getDetail(@RequestParam("id") String id) {
|
||||
String methodDescribe = getMethodDescribe("getDetail");
|
||||
LogUtil.njcnDebug(log, "{},查看ID为:{}", methodDescribe, id);
|
||||
List<PqErrSysDtlsVO> result = pqErrSysService.getDetail(id);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo
|
||||
@GetMapping("/getAll")
|
||||
@ApiOperation("获取所有误差体系")
|
||||
public HttpResult<List<Map<String, Object>>> getAllPqErrSys() {
|
||||
String methodDescribe = getMethodDescribe("getAllPqErrSys");
|
||||
LogUtil.njcnDebug(log, "{}", methodDescribe);
|
||||
List<Map<String, Object>> result = pqErrSysService.listAllPqErrSys();
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
|
||||
// @OperateInfo(operateType = OperateType.ADD)
|
||||
// @GetMapping("/copy")
|
||||
// @ApiOperation("复制误差体系")
|
||||
// @ApiImplicitParam(name = "id", value = "误差体系id", required = true)
|
||||
// public HttpResult<Object> copy(@RequestParam("id") String id) {
|
||||
// String methodDescribe = getMethodDescribe("copy");
|
||||
// LogUtil.njcnDebug(log, "{},复制ID为:{}", methodDescribe, id);
|
||||
// boolean result = pqErrSysService.copyPqErrSys(id);
|
||||
// if (result) {
|
||||
// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
// } else {
|
||||
// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.njcn.gather.device.err.mapper;
|
||||
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
import com.njcn.gather.device.err.pojo.po.PqErrSysDtls;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024-11-27
|
||||
*/
|
||||
public interface PqErrSysDtlsMapper extends MPJBaseMapper<PqErrSysDtls> {
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.njcn.gather.device.err.mapper;
|
||||
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
import com.njcn.gather.device.err.pojo.po.PqErrSys;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024-11-27
|
||||
*/
|
||||
public interface PqErrSysMapper extends MPJBaseMapper<PqErrSys> {
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.njcn.gather.device.err.mapper.PqErrSysDtlsMapper">
|
||||
|
||||
|
||||
</mapper>
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.njcn.gather.device.err.mapper.PqErrSysMapper">
|
||||
|
||||
|
||||
</mapper>
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.njcn.gather.device.err.pojo.param;
|
||||
|
||||
import com.njcn.common.pojo.constant.PatternRegex;
|
||||
import com.njcn.gather.device.pojo.constant.DevValidMessage;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Pattern;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2024-11-21
|
||||
*/
|
||||
@Data
|
||||
public class PqErrSysDtlsParam {
|
||||
|
||||
@ApiModelProperty(value = "误差项类型", required = true)
|
||||
@NotBlank(message = DevValidMessage.ERR_SYS_DTLS_ERROR_TYPE_NOT_BLANK)
|
||||
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.ERR_SYS_DTLS_ERROR_TYPE_FORMAT_ERROR)
|
||||
private String errorType;
|
||||
|
||||
@ApiModelProperty(value = "脚本项类型", required = true)
|
||||
@NotBlank(message = DevValidMessage.ERR_SYS_DTLS_SCRIPT_TYPE_NOT_BLANK)
|
||||
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.ERR_SYS_DTLS_SCRIPT_TYPE_FORMAT_ERROR)
|
||||
private String scriptType;
|
||||
|
||||
@ApiModelProperty(value = "误差判断起始值", required = true)
|
||||
private Double startValue;
|
||||
|
||||
@ApiModelProperty(value = "是否包含起始值", required = true)
|
||||
private Integer startFlag;
|
||||
|
||||
@ApiModelProperty(value = "误差判断结束值", required = true)
|
||||
private Double endValue;
|
||||
|
||||
@ApiModelProperty(value = "是否包含结束值", required = true)
|
||||
private Integer endFlag;
|
||||
|
||||
// @ApiModelProperty(value = "单位", required = true)
|
||||
// @NotBlank(message = DeviceValidMessage.UNIT_NOT_BLANK)
|
||||
// @Pattern(regexp = PatternRegex.SYSTEM_ID, message = DeviceValidMessage.UNIT_FORMAT_ERROR)
|
||||
// private String unit;
|
||||
|
||||
@ApiModelProperty(value = "判断条件值类型", required = true)
|
||||
private Integer conditionType;
|
||||
|
||||
@ApiModelProperty(value = "最大值误差", required = true)
|
||||
@NotNull(message = DevValidMessage.MAX_ERROR_VALUE_NOT_NULL)
|
||||
private Double maxErrorValue;
|
||||
|
||||
@ApiModelProperty(value = "误差值类型", required = true)
|
||||
@NotNull(message = DevValidMessage.ERROR_VALUE_TYPE_NOT_BLANK)
|
||||
private Integer errorValueType;
|
||||
|
||||
@ApiModelProperty("排序")
|
||||
@NotNull(message = DevValidMessage.SORT_NOT_NULL)
|
||||
private Integer sort;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package com.njcn.gather.device.err.pojo.param;
|
||||
|
||||
import com.njcn.common.pojo.constant.PatternRegex;
|
||||
import com.njcn.gather.device.pojo.constant.DevValidMessage;
|
||||
import com.njcn.web.pojo.annotation.DateTimeStrValid;
|
||||
import com.njcn.web.pojo.param.BaseParam;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.*;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2024-11-27
|
||||
*/
|
||||
@Data
|
||||
public class PqErrSysParam {
|
||||
|
||||
@ApiModelProperty(value = "参照标准名称", required = true)
|
||||
@NotBlank(message = DevValidMessage.STANDARD_NAME_NOT_BLANK)
|
||||
@Pattern(regexp = PatternRegex.ERR_SYS_NAME, message = DevValidMessage.STANDARD_NAME_FORMAT_ERROR)
|
||||
private String standardName;
|
||||
|
||||
@ApiModelProperty(value = "标准实施年份", required = true)
|
||||
@NotBlank(message = DevValidMessage.STANDARD_TIME_NOT_BLANK)
|
||||
@DateTimeStrValid(format = "yyyy", message = DevValidMessage.STANDARD_TIME_FORMAT_ERROR)
|
||||
private String standardTime;
|
||||
|
||||
@ApiModelProperty(value = "设备等级", required = true)
|
||||
@NotBlank(message = DevValidMessage.DEV_LEVEL_NOT_BLANK)
|
||||
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.DEV_LEVEL_FORMAT_ERROR)
|
||||
private String devLevel;
|
||||
|
||||
@ApiModelProperty("状态")
|
||||
@NotNull(message = DevValidMessage.ENABLE_NOT_NULL)
|
||||
@Min(value = 0, message = DevValidMessage.ENABLE_FORMAT_ERROR)
|
||||
@Max(value = 1, message = DevValidMessage.ENABLE_FORMAT_ERROR)
|
||||
private Integer enable;
|
||||
|
||||
@ApiModelProperty(value = "误差详情列表", required = true)
|
||||
@Valid
|
||||
private List<PqErrSysDtlsParam> pqErrSysDtlsList;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public static class QueryParam extends BaseParam {
|
||||
@ApiModelProperty("标准实施年份")
|
||||
@DateTimeStrValid(format = "yyyy", message = DevValidMessage.STANDARD_TIME_FORMAT_ERROR)
|
||||
private String standardTime;
|
||||
|
||||
@ApiModelProperty("设备等级")
|
||||
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.DEV_LEVEL_FORMAT_ERROR)
|
||||
private String devLevel;
|
||||
}
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public static class UpdateParam extends PqErrSysParam {
|
||||
@ApiModelProperty("id")
|
||||
@NotBlank(message = DevValidMessage.ID_NOT_BLANK)
|
||||
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.ID_FORMAT_ERROR)
|
||||
private String id;
|
||||
}
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public static class DetectionParam{
|
||||
@ApiModelProperty("所属误差体系ID")
|
||||
private String errorSysId;
|
||||
|
||||
@ApiModelProperty("总检测脚本中的测试项序号")
|
||||
private Integer index;
|
||||
|
||||
@ApiModelProperty("所属检测脚本")
|
||||
private String scriptId;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.njcn.gather.device.err.pojo.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
|
||||
import com.njcn.db.mybatisplus.bo.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024-11-27
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("pq_err_sys")
|
||||
public class PqErrSys extends BaseEntity implements Serializable {
|
||||
private static final long serialVersionUID = -90836093088362651L;
|
||||
/**
|
||||
* 误差体系ID
|
||||
*/
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 误差体系名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 参照标准名称
|
||||
*/
|
||||
private String standardName;
|
||||
|
||||
/**
|
||||
* 标准推行时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy")
|
||||
@JsonDeserialize(using = LocalDateDeserializer.class)
|
||||
@JsonSerialize(using = LocalDateSerializer.class)
|
||||
private LocalDate standardTime;
|
||||
|
||||
/**
|
||||
* 设备等级,字典表
|
||||
*/
|
||||
private String devLevel;
|
||||
|
||||
/**
|
||||
* 状态:0-不启用 1-启用
|
||||
*/
|
||||
private Integer enable;
|
||||
|
||||
/**
|
||||
* 状态:0-删除 1-正常
|
||||
*/
|
||||
private Integer state;
|
||||
|
||||
@TableField(exist = false)
|
||||
private List<PqErrSysDtls> pqErrSysDtlsList;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
package com.njcn.gather.device.err.pojo.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024-11-27
|
||||
*/
|
||||
@Data
|
||||
@TableName("pq_err_sys_dtls")
|
||||
public class PqErrSysDtls implements Serializable {
|
||||
private static final long serialVersionUID = -52777336589097027L;
|
||||
/**
|
||||
* 误差体系子表ID
|
||||
*/
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 所属误差体系ID
|
||||
*/
|
||||
private String errorSysId;
|
||||
|
||||
/**
|
||||
* 误差项类型
|
||||
*/
|
||||
private String errorType;
|
||||
|
||||
/**
|
||||
* 脚本项类型
|
||||
*/
|
||||
private String scriptType;
|
||||
|
||||
/**
|
||||
* 脚本项类型Code
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private String scriptCode;
|
||||
|
||||
/**
|
||||
* 误差判断起始值
|
||||
*/
|
||||
private Double startValue;
|
||||
|
||||
/**
|
||||
* 是否包含起始值
|
||||
*/
|
||||
private Integer startFlag;
|
||||
|
||||
/**
|
||||
* 误差判断结束值
|
||||
*/
|
||||
private Double endValue;
|
||||
|
||||
/**
|
||||
* 是否包含结束值
|
||||
*/
|
||||
private Integer endFlag;
|
||||
|
||||
/**
|
||||
* 单位
|
||||
*/
|
||||
// private String unit;
|
||||
|
||||
/**
|
||||
* 判断条件值类型(包括值类型,绝对值、相对值)
|
||||
*/
|
||||
private Integer conditionType;
|
||||
|
||||
/**
|
||||
* 误差最大值
|
||||
*/
|
||||
@TableField("Max_Error_Value")
|
||||
private Double maxErrorValue;
|
||||
|
||||
/**
|
||||
* 误差值类型
|
||||
*/
|
||||
private Integer errorValueType;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
private Integer sort;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.njcn.gather.device.err.pojo.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2024-12-02
|
||||
*/
|
||||
@Data
|
||||
public class PqErrSysDtlsVO {
|
||||
/**
|
||||
* 列1
|
||||
*/
|
||||
private String col1;
|
||||
|
||||
/**
|
||||
* 列2
|
||||
*/
|
||||
private String col2;
|
||||
|
||||
/**
|
||||
* 装置等级
|
||||
*/
|
||||
private String devLevel;
|
||||
|
||||
/**
|
||||
* 测量类型
|
||||
*/
|
||||
private String testType;
|
||||
|
||||
/**
|
||||
* 测量条件 & 最大误差
|
||||
*/
|
||||
private List<Map<String, Object>> info;
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.njcn.gather.device.err.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.gather.device.err.pojo.param.PqErrSysDtlsParam;
|
||||
import com.njcn.gather.device.err.pojo.param.PqErrSysParam;
|
||||
import com.njcn.gather.device.err.pojo.po.PqErrSysDtls;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024-11-27
|
||||
*/
|
||||
public interface IPqErrSysDtlsService extends IService<PqErrSysDtls> {
|
||||
|
||||
/**
|
||||
* 根据误差体系id查询误差详情
|
||||
* @param pqErrSysId 误差体系id
|
||||
* @return
|
||||
*/
|
||||
List<PqErrSysDtls> listPqErrSysDtlsByPqErrSysId(String pqErrSysId);
|
||||
|
||||
/**
|
||||
* 新增误差详情
|
||||
* @param pqErrSysId 误差体系id
|
||||
* @param list 新增参数
|
||||
* @return 成功返回true,失败返回false
|
||||
*/
|
||||
boolean addPqErrSysDtls(String pqErrSysId, List<PqErrSysDtlsParam> list);
|
||||
|
||||
/**
|
||||
* 更新误差详情
|
||||
* @param pqErrSysId 误差体系id
|
||||
* @param list 更新参数
|
||||
* @return 成功返回true,失败返回false
|
||||
*/
|
||||
boolean updatePqErrSysDtls(String pqErrSysId, List<PqErrSysDtlsParam> list);
|
||||
|
||||
/**
|
||||
* 根据误差体系id删除误差详情
|
||||
* @param pqErrSysIds
|
||||
* @return 成功返回true,失败返回false
|
||||
*/
|
||||
boolean deletePqErrSysDtlsByPqErrSysId(List<String> pqErrSysIds);
|
||||
|
||||
/**
|
||||
* 根据误差体系id查询误差详情
|
||||
* @param param 误差体系id
|
||||
* @return
|
||||
*/
|
||||
List<PqErrSysDtls> listPqErrSysDtlsByPqErrSysIdAndTypes(PqErrSysParam.DetectionParam param);
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package com.njcn.gather.device.err.service;
|
||||
|
||||
import cn.hutool.core.date.StopWatch;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.gather.device.err.pojo.param.PqErrSysParam;
|
||||
import com.njcn.gather.device.err.pojo.po.PqErrSys;
|
||||
import com.njcn.gather.device.err.pojo.vo.PqErrSysDtlsVO;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024-11-27
|
||||
*/
|
||||
public interface IPqErrSysService extends IService<PqErrSys> {
|
||||
|
||||
/**
|
||||
* 分页查询误差体系列表
|
||||
*
|
||||
* @param param 分页查询参数
|
||||
* @return 分页查询结果
|
||||
*/
|
||||
Page<PqErrSys> listPqErrSys(PqErrSysParam.QueryParam param);
|
||||
|
||||
/**
|
||||
* 根据id查询误差体系
|
||||
*
|
||||
* @param id id
|
||||
* @return 误差体系
|
||||
*/
|
||||
PqErrSys getPqErrSysById(String id);
|
||||
|
||||
/**
|
||||
* 新增误差体系
|
||||
*
|
||||
* @param param 新增参数
|
||||
* @return 成功返回true,失败返回false
|
||||
*/
|
||||
boolean addPqErrSys(PqErrSysParam param);
|
||||
|
||||
/**
|
||||
* 更新误差体系
|
||||
*
|
||||
* @param param 更新参数
|
||||
* @return 成功返回true,失败返回false
|
||||
*/
|
||||
boolean updatePqErrSys(PqErrSysParam.UpdateParam param);
|
||||
|
||||
/**
|
||||
* 删除误差体系
|
||||
*
|
||||
* @param ids id列表
|
||||
* @return 成功返回true,失败返回false
|
||||
*/
|
||||
boolean deletePqErrSys(List<String> ids);
|
||||
|
||||
List<PqErrSysDtlsVO> getDetail(String id);
|
||||
|
||||
/**
|
||||
* 获取所有误差体系
|
||||
*
|
||||
* @return 误差体系列表
|
||||
*/
|
||||
List<Map<String, Object>> listAllPqErrSys();
|
||||
|
||||
/**
|
||||
* 根据误差体系名称查询误差体系
|
||||
*
|
||||
* @param name 误差体系名称
|
||||
* @return 误差体系
|
||||
*/
|
||||
PqErrSys getPqErrSysByName(String name);
|
||||
|
||||
/**
|
||||
* 复制误差体系
|
||||
*
|
||||
* @param id 误差体系id
|
||||
* @return 成功返回true,失败返回false
|
||||
*/
|
||||
//boolean copyPqErrSys(String id);
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package com.njcn.gather.device.err.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||
import com.njcn.gather.device.err.mapper.PqErrSysDtlsMapper;
|
||||
import com.njcn.gather.device.err.pojo.param.PqErrSysDtlsParam;
|
||||
import com.njcn.gather.device.err.pojo.param.PqErrSysParam;
|
||||
import com.njcn.gather.device.err.pojo.po.PqErrSysDtls;
|
||||
import com.njcn.gather.device.err.service.IPqErrSysDtlsService;
|
||||
import com.njcn.gather.device.script.pojo.param.PqScriptCheckDataParam;
|
||||
import com.njcn.gather.device.script.service.IPqScriptCheckDataService;
|
||||
import com.njcn.gather.system.dictionary.pojo.po.DictTree;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024-11-27
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class PqErrSysDtlsServiceImpl extends ServiceImpl<PqErrSysDtlsMapper, PqErrSysDtls> implements IPqErrSysDtlsService {
|
||||
|
||||
private final IPqScriptCheckDataService pqScriptCheckDataService;
|
||||
|
||||
|
||||
@Override
|
||||
public List<PqErrSysDtls> listPqErrSysDtlsByPqErrSysId(String pqErrSysId) {
|
||||
return this.lambdaQuery().eq(PqErrSysDtls::getErrorSysId, pqErrSysId).orderBy(true, true, PqErrSysDtls::getSort).list();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public boolean addPqErrSysDtls(String pqErrSysId, List<PqErrSysDtlsParam> list) {
|
||||
List<PqErrSysDtls> data = new ArrayList<>();
|
||||
for (PqErrSysDtlsParam param : list) {
|
||||
PqErrSysDtls pqErrSysDtls = new PqErrSysDtls();
|
||||
BeanUtils.copyProperties(param, pqErrSysDtls);
|
||||
pqErrSysDtls.setErrorSysId(pqErrSysId);
|
||||
data.add(pqErrSysDtls);
|
||||
}
|
||||
return this.saveBatch(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public boolean updatePqErrSysDtls(String pqErrSysId, List<PqErrSysDtlsParam> list) {
|
||||
//先按照pqErrSysId全部删除
|
||||
this.deletePqErrSysDtlsByPqErrSysId(Collections.singletonList(pqErrSysId));
|
||||
//再重新插入
|
||||
this.addPqErrSysDtls(pqErrSysId, list);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public boolean deletePqErrSysDtlsByPqErrSysId(List<String> pqErrSysIds) {
|
||||
QueryWrapper<PqErrSysDtls> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.in("pq_err_sys_dtls.Error_Sys_Id", pqErrSysIds);
|
||||
return this.remove(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PqErrSysDtls> listPqErrSysDtlsByPqErrSysIdAndTypes(PqErrSysParam.DetectionParam param) {
|
||||
PqScriptCheckDataParam script = new PqScriptCheckDataParam();
|
||||
script.setScriptId(param.getScriptId());
|
||||
script.setIndex(param.getIndex());
|
||||
script.setIsValueTypeName(false);
|
||||
List<String> valueType = pqScriptCheckDataService.getValueType(script);
|
||||
//根据检测脚本id和检测序号,查询出检测子项目
|
||||
return this.list(new MPJLambdaWrapper<PqErrSysDtls>().selectAll(PqErrSysDtls.class)
|
||||
.selectAll(PqErrSysDtls.class)
|
||||
.selectAs(DictTree::getCode, PqErrSysDtls::getScriptCode)
|
||||
.leftJoin(DictTree.class, DictTree::getId, PqErrSysDtls::getScriptType)
|
||||
.eq(PqErrSysDtls::getErrorSysId, param.getErrorSysId())
|
||||
.in(PqErrSysDtls::getScriptType, valueType)
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,210 @@
|
||||
package com.njcn.gather.device.err.service.impl;
|
||||
|
||||
import cn.hutool.core.text.StrPool;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.common.pojo.enums.common.DataStateEnum;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.gather.device.err.mapper.PqErrSysMapper;
|
||||
import com.njcn.gather.device.err.pojo.param.PqErrSysParam;
|
||||
import com.njcn.gather.device.err.pojo.po.PqErrSys;
|
||||
import com.njcn.gather.device.err.pojo.po.PqErrSysDtls;
|
||||
import com.njcn.gather.device.err.pojo.vo.PqErrSysDtlsVO;
|
||||
import com.njcn.gather.device.err.service.IPqErrSysDtlsService;
|
||||
import com.njcn.gather.device.err.service.IPqErrSysService;
|
||||
import com.njcn.gather.device.pojo.enums.DevResponseEnum;
|
||||
import com.njcn.gather.system.dictionary.pojo.po.DictData;
|
||||
import com.njcn.gather.system.dictionary.pojo.po.DictTree;
|
||||
import com.njcn.gather.system.dictionary.service.IDictDataService;
|
||||
import com.njcn.gather.system.dictionary.service.IDictTreeService;
|
||||
import com.njcn.web.factory.PageFactory;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024-11-27
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class PqErrSysServiceImpl extends ServiceImpl<PqErrSysMapper, PqErrSys> implements IPqErrSysService {
|
||||
|
||||
private final IPqErrSysDtlsService pqErrSysDtlsService;
|
||||
private final IDictTreeService dictTreeService;
|
||||
private final IDictDataService dictDataService;
|
||||
|
||||
@Override
|
||||
public Page<PqErrSys> listPqErrSys(PqErrSysParam.QueryParam param) {
|
||||
QueryWrapper<PqErrSys> queryWrapper = new QueryWrapper<>();
|
||||
if (ObjectUtil.isNotNull(param)) {
|
||||
queryWrapper.between(ObjectUtil.isNotEmpty(param.getStandardTime()), "pq_err_sys.Standard_Time", param.getStandardTime() + "-01-01", param.getStandardTime() + "-12-31").eq(ObjectUtil.isNotEmpty(param.getDevLevel()), "pq_err_sys.Dev_Level", param.getDevLevel());
|
||||
}
|
||||
queryWrapper.eq("pq_err_sys.state", DataStateEnum.ENABLE.getCode());
|
||||
return this.page(new Page<>(PageFactory.getPageNum(param), PageFactory.getPageSize(param)), queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PqErrSys getPqErrSysById(String id) {
|
||||
PqErrSys pqErrSys = this.lambdaQuery().eq(PqErrSys::getId, id).eq(PqErrSys::getState, DataStateEnum.ENABLE.getCode()).one();
|
||||
if (ObjectUtil.isNotNull(pqErrSys)) {
|
||||
pqErrSys.setPqErrSysDtlsList(pqErrSysDtlsService.listPqErrSysDtlsByPqErrSysId(id));
|
||||
}
|
||||
return pqErrSys;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public boolean addPqErrSys(PqErrSysParam param) {
|
||||
PqErrSys pqErrSys = new PqErrSys();
|
||||
BeanUtils.copyProperties(param, pqErrSys);
|
||||
String id = UUID.randomUUID().toString().replaceAll("-", "");
|
||||
pqErrSys.setId(id);
|
||||
pqErrSys.setName(generateErrSysName(param));
|
||||
pqErrSys.setStandardTime(LocalDate.of(Integer.parseInt(param.getStandardTime()), 1, 1));
|
||||
pqErrSys.setState(DataStateEnum.ENABLE.getCode());
|
||||
boolean result1 = this.save(pqErrSys);
|
||||
boolean result2 = pqErrSysDtlsService.updatePqErrSysDtls(id, param.getPqErrSysDtlsList());
|
||||
return result1 && result2;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public boolean updatePqErrSys(PqErrSysParam.UpdateParam param) {
|
||||
PqErrSys pqErrSys = new PqErrSys();
|
||||
BeanUtils.copyProperties(param, pqErrSys);
|
||||
pqErrSys.setName(generateErrSysName(param));
|
||||
pqErrSys.setStandardTime(LocalDate.of(Integer.parseInt(param.getStandardTime()), 1, 1));
|
||||
boolean result1 = this.updateById(pqErrSys);
|
||||
boolean result2 = pqErrSysDtlsService.updatePqErrSysDtls(param.getId(), param.getPqErrSysDtlsList());
|
||||
return result1 && result2;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public boolean deletePqErrSys(List<String> ids) {
|
||||
pqErrSysDtlsService.deletePqErrSysDtlsByPqErrSysId(ids);
|
||||
this.lambdaUpdate().in(PqErrSys::getId, ids).set(PqErrSys::getState, DataStateEnum.DELETED.getCode()).update();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PqErrSysDtlsVO> getDetail(String id) {
|
||||
List<PqErrSysDtlsVO> result = new ArrayList<>();
|
||||
List<PqErrSysDtls> pqErrSysDtls = pqErrSysDtlsService.listPqErrSysDtlsByPqErrSysId(id);
|
||||
if (ObjectUtil.isNotEmpty(pqErrSysDtls)) {
|
||||
PqErrSysDtlsVO temp = new PqErrSysDtlsVO();
|
||||
temp.setDevLevel(this.getById(id).getDevLevel());
|
||||
//按照测量项分组
|
||||
Map<String, List<PqErrSysDtls>> map = pqErrSysDtls.stream().collect(Collectors.groupingBy(PqErrSysDtls::getErrorType));
|
||||
map.forEach((key, value) -> {
|
||||
this.visualize(value, temp);
|
||||
result.add(temp);
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public List<Map<String, Object>> listAllPqErrSys() {
|
||||
List<PqErrSys> pqErrSysList = this.lambdaQuery().eq(PqErrSys::getState, DataStateEnum.ENABLE.getCode()).list();
|
||||
List<Map<String, Object>> result = pqErrSysList.stream().map(pqErrSys -> {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("id", pqErrSys.getId());
|
||||
map.put("name", pqErrSys.getName());
|
||||
return map;
|
||||
}).collect(Collectors.toList());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PqErrSys getPqErrSysByName(String name) {
|
||||
return this.lambdaQuery().eq(PqErrSys::getName, name).eq(PqErrSys::getState, DataStateEnum.ENABLE.getCode()).one();
|
||||
}
|
||||
|
||||
/**
|
||||
* 将检测项可视化
|
||||
*
|
||||
* @param list
|
||||
* @param temp
|
||||
*/
|
||||
private void visualize(List<PqErrSysDtls> list, PqErrSysDtlsVO temp) {
|
||||
if (ObjectUtil.isNotEmpty(list)) {
|
||||
String type = list.get(0).getErrorType();
|
||||
DictTree dictTree = dictTreeService.queryById(type);
|
||||
if (ObjectUtil.isNotNull(dictTree)) {
|
||||
String[] pids = dictTree.getPids().split(StrPool.COMMA);
|
||||
temp.setTestType(dictTree.getName());
|
||||
temp.setCol1(dictTreeService.queryById(pids[1]).getName());
|
||||
if (pids.length == 3) {
|
||||
temp.setCol2(dictTreeService.queryById(pids[2]).getName());
|
||||
}
|
||||
// if (pids.length == 2) {
|
||||
// temp.setCol2(dictTreeService.queryById(pids[1]).getName());
|
||||
// }
|
||||
}
|
||||
|
||||
list.forEach(pqErrSysDtls -> {
|
||||
if (ObjectUtil.isNull(temp.getInfo())) {
|
||||
temp.setInfo(new ArrayList<>());
|
||||
}
|
||||
Map<String, Object> map1 = new HashMap();
|
||||
map1.put("startValue", pqErrSysDtls.getStartValue());
|
||||
map1.put("startFlag", pqErrSysDtls.getStartFlag());
|
||||
map1.put("endValue", pqErrSysDtls.getEndValue());
|
||||
map1.put("endFlag", pqErrSysDtls.getEndFlag());
|
||||
map1.put("conditionType", pqErrSysDtls.getConditionType());
|
||||
map1.put("maxErrorValue", pqErrSysDtls.getMaxErrorValue());
|
||||
map1.put("errorValueType", pqErrSysDtls.getErrorValueType());
|
||||
temp.getInfo().add(map1);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成误差体系名称(标准号+年份+设备等级)
|
||||
*
|
||||
* @return 误差体系名称
|
||||
*/
|
||||
private String generateErrSysName(PqErrSysParam param) {
|
||||
DictData devLevelDictData = dictDataService.getDictDataById(param.getDevLevel());
|
||||
if (ObjectUtil.isNotNull(devLevelDictData)) {
|
||||
return param.getStandardName() + "-" + param.getStandardTime() + "-" + devLevelDictData.getName();
|
||||
}
|
||||
throw new BusinessException(DevResponseEnum.PQ_ERRSYS_GEN_NAME_ERROR);
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public boolean copyPqErrSys(String id) {
|
||||
// PqErrSys pqErrSys = this.getPqErrSysById(id);
|
||||
// pqErrSys.setId(UUID.randomUUID().toString().replaceAll("-", ""));
|
||||
// pqErrSys.setName(pqErrSys.getName() + "_副本");
|
||||
// pqErrSys.setStandardTime(LocalDate.of(pqErrSys.getStandardTime().getYear(), 1, 1));
|
||||
// pqErrSys.getPqErrSysDtlsList().forEach(pqErrSysDtls -> pqErrSysDtls.setId(UUID.randomUUID().toString().replaceAll("-", "")));
|
||||
// return this.save(pqErrSys);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 生成误差体系名称(标准号+年份+设备等级)
|
||||
*
|
||||
* @return 检测源名称
|
||||
*/
|
||||
private String generatePqSourceName(PqErrSysParam param) {
|
||||
DictData devLevel = dictDataService.getDictDataById(param.getDevLevel());
|
||||
if (ObjectUtils.allNotNull(param.getStandardName(), param.getStandardTime(), devLevel)) {
|
||||
return param.getStandardName() + "-" + param.getStandardTime() + "-" + devLevel.getName();
|
||||
}
|
||||
throw new BusinessException(DevResponseEnum.ERR_SOURCE_GEN_NAME_ERROR);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.njcn.gather.device.monitor.controller;
|
||||
|
||||
import com.njcn.gather.device.monitor.service.IPqMonitorService;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import io.swagger.annotations.Api;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024-12-12
|
||||
*/
|
||||
@Slf4j
|
||||
@Api(tags = "监测点管理")
|
||||
@RestController
|
||||
@RequestMapping("/pqMonitor")
|
||||
@RequiredArgsConstructor
|
||||
public class PqMonitorController extends BaseController {
|
||||
private final IPqMonitorService pqMonitorService;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.njcn.gather.device.monitor.mapper;
|
||||
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
import com.njcn.gather.device.device.pojo.vo.PreDetection;
|
||||
import com.njcn.gather.device.monitor.pojo.po.PqMonitor;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024-12-12
|
||||
*/
|
||||
public interface PqMonitorMapper extends MPJBaseMapper<PqMonitor> {
|
||||
|
||||
/**
|
||||
* 根据终端id获取监测点集合
|
||||
* @param devId
|
||||
* @return: java.util.List<com.njcn.gather.device.device.pojo.vo.PreDetection.MonitorListDTO>
|
||||
* @Author: wr
|
||||
* @Date: 2024/12/12 13:15
|
||||
*/
|
||||
List<PreDetection.MonitorListDTO> selectMonitorInfo(@Param("devId") String devId);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.njcn.gather.device.monitor.mapper.PqMonitorMapper">
|
||||
|
||||
<select id="selectMonitorInfo"
|
||||
resultType="com.njcn.gather.device.device.pojo.vo.PreDetection$MonitorListDTO">
|
||||
SELECT
|
||||
Id as lineId,
|
||||
Num as line,
|
||||
pt as pt,
|
||||
ct as ct
|
||||
FROM
|
||||
pq_monitor
|
||||
WHERE
|
||||
dev_id = #{devId}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.njcn.gather.device.monitor.pojo.param;
|
||||
|
||||
import com.njcn.common.pojo.constant.PatternRegex;
|
||||
import com.njcn.gather.device.pojo.constant.DevValidMessage;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Pattern;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2024-12-12
|
||||
*/
|
||||
@Data
|
||||
public class PqMonitorParam {
|
||||
|
||||
@ApiModelProperty(value = "谐波系统监测点ID")
|
||||
private String code;
|
||||
|
||||
@ApiModelProperty(value = "所属母线")
|
||||
@NotBlank(message = DevValidMessage.BELONG_LINE_NOT_BLANK)
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(value = "监测点序号")
|
||||
@NotNull(message = DevValidMessage.MONITOR_NUM_NOT_NULL)
|
||||
private Integer num;
|
||||
|
||||
@ApiModelProperty(value = "PT变比")
|
||||
@NotNull(message = DevValidMessage.PT_NOT_NULL)
|
||||
private Float pt;
|
||||
|
||||
@ApiModelProperty(value = "CT变比")
|
||||
@NotNull(message = DevValidMessage.CT_NOT_NULL)
|
||||
private Float ct;
|
||||
|
||||
@ApiModelProperty(value = "接线方式")
|
||||
@NotBlank(message = DevValidMessage.WIRING_TYPE_NOT_BLANK)
|
||||
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.WIRING_TYPE_FORMAT_ERROR)
|
||||
private String ptType;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.njcn.gather.device.monitor.pojo.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.njcn.db.mybatisplus.bo.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024-12-12
|
||||
*/
|
||||
@Data
|
||||
@TableName("pq_monitor")
|
||||
public class PqMonitor implements Serializable {
|
||||
private static final long serialVersionUID = -97606920356561872L;
|
||||
/**
|
||||
* 监测点ID
|
||||
*/
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 默认与谐波系统监测点ID相同
|
||||
*/
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 所属设备ID
|
||||
*/
|
||||
private String devId;
|
||||
|
||||
/**
|
||||
* 所属母线
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 监测点序号
|
||||
*/
|
||||
private Integer num;
|
||||
|
||||
/**
|
||||
* PT变比
|
||||
*/
|
||||
private Float pt;
|
||||
|
||||
/**
|
||||
* CT变比
|
||||
*/
|
||||
private Float ct;
|
||||
|
||||
/**
|
||||
* 接线方式,字典表
|
||||
*/
|
||||
private String ptType;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.njcn.gather.device.monitor.pojo.vo;
|
||||
|
||||
import cn.afterturn.easypoi.excel.annotation.Excel;
|
||||
import com.njcn.common.pojo.constant.PatternRegex;
|
||||
import com.njcn.gather.device.pojo.constant.DevValidMessage;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Pattern;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2024-12-09
|
||||
*/
|
||||
@Data
|
||||
public class PqMonitorExcel {
|
||||
|
||||
@Excel(name = "监测点序号", width = 20, orderNum = "1")
|
||||
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.MONITOR_NUM_FORMAT_ERROR)
|
||||
private Integer num;
|
||||
|
||||
@Excel(name = "所属母线", width = 20, orderNum = "2")
|
||||
@NotBlank(message = DevValidMessage.BELONG_LINE_NOT_BLANK)
|
||||
private String name;
|
||||
|
||||
@Excel(name = "PT变比", width = 20, orderNum = "3")
|
||||
@NotNull(message = DevValidMessage.PT_NOT_NULL)
|
||||
private Float pt;
|
||||
|
||||
@Excel(name = "CT变比", width = 20, orderNum = "4")
|
||||
@NotNull(message = DevValidMessage.CT_NOT_NULL)
|
||||
private Float ct;
|
||||
|
||||
@Excel(name = "接线方式", width = 20, orderNum = "5")
|
||||
@NotBlank(message = DevValidMessage.WIRING_TYPE_NOT_BLANK)
|
||||
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.WIRING_TYPE_FORMAT_ERROR)
|
||||
private String ptType;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public static class ImportData extends PqMonitorExcel {
|
||||
|
||||
}
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public static class ExportData extends PqMonitorExcel {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.njcn.gather.device.monitor.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.gather.device.device.pojo.po.PqDev;
|
||||
import com.njcn.gather.device.monitor.pojo.param.PqMonitorParam;
|
||||
import com.njcn.gather.device.monitor.pojo.po.PqMonitor;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024-12-12
|
||||
*/
|
||||
public interface IPqMonitorService extends IService<PqMonitor> {
|
||||
|
||||
/**
|
||||
* 根据设备id获取所有监测点信息
|
||||
*
|
||||
* @param devId 被检设备id
|
||||
* @return 监测点信息列表
|
||||
*/
|
||||
List<PqMonitor> listPqMonitorByDevId(String devId);
|
||||
|
||||
/**
|
||||
* 批量新增监测点信息
|
||||
*
|
||||
* @param devId 被检设备id
|
||||
* @param pqMonitorParamList 监测点信息列表
|
||||
* @return 新增成功返回true,否则返回false
|
||||
*/
|
||||
boolean addPqMonitorByDevId(String devId, List<PqMonitorParam> pqMonitorParamList);
|
||||
|
||||
/**
|
||||
* 批量删除监测点信息
|
||||
*
|
||||
* @param devId 被检设备id
|
||||
* @return 删除成功返回true,否则返回false
|
||||
*/
|
||||
boolean deletePqMonitorByDevId(String devId);
|
||||
|
||||
/**
|
||||
* 修改监测点信息
|
||||
*
|
||||
* @param devId 被检设备id
|
||||
* @param paramList 监测点信息
|
||||
* @return 修改成功返回true,否则返回false
|
||||
*/
|
||||
boolean updatePqMonitorByDevId(String devId, List<PqMonitorParam> paramList);
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.njcn.gather.device.monitor.service.impl;
|
||||
|
||||
import cn.afterturn.easypoi.excel.entity.ExportParams;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.gather.device.device.pojo.po.PqDev;
|
||||
import com.njcn.gather.device.monitor.mapper.PqMonitorMapper;
|
||||
import com.njcn.gather.device.monitor.pojo.param.PqMonitorParam;
|
||||
import com.njcn.gather.device.monitor.pojo.po.PqMonitor;
|
||||
import com.njcn.gather.device.monitor.pojo.vo.PqMonitorExcel;
|
||||
import com.njcn.gather.device.monitor.service.IPqMonitorService;
|
||||
import com.njcn.gather.system.dictionary.service.IDictDataService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024-12-12
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class PqMonitorServiceImpl extends ServiceImpl<PqMonitorMapper, PqMonitor> implements IPqMonitorService {
|
||||
|
||||
private final IDictDataService dictDataService;
|
||||
|
||||
@Override
|
||||
public List<PqMonitor> listPqMonitorByDevId(String devId) {
|
||||
return this.lambdaQuery().eq(PqMonitor::getDevId, devId).list();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public boolean addPqMonitorByDevId(String devId, List<PqMonitorParam> pqMonitorParamList) {
|
||||
List<PqMonitor> pqMonitorList = BeanUtil.copyToList(pqMonitorParamList, PqMonitor.class);
|
||||
pqMonitorList.forEach(pqMonitor -> pqMonitor.setDevId(devId));
|
||||
return this.saveBatch(pqMonitorList);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public boolean deletePqMonitorByDevId(String devId) {
|
||||
QueryWrapper<PqMonitor> wrapper = new QueryWrapper<>();
|
||||
wrapper.eq("pq_monitor.Dev_Id", devId);
|
||||
return this.remove(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public boolean updatePqMonitorByDevId(String devId, List<PqMonitorParam> paramList) {
|
||||
// 先删除原有数据
|
||||
this.deletePqMonitorByDevId(devId);
|
||||
// 再添加新数据
|
||||
List<PqMonitor> pqMonitorList = BeanUtil.copyToList(paramList, PqMonitor.class);
|
||||
pqMonitorList.forEach(pqMonitor -> pqMonitor.setDevId(devId));
|
||||
return this.saveBatch(pqMonitorList);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,210 @@
|
||||
package com.njcn.gather.device.pojo.constant;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024/11/06
|
||||
*/
|
||||
public interface DevValidMessage {
|
||||
|
||||
String ID_NOT_BLANK = "id不能为空,请检查id参数";
|
||||
|
||||
String ID_FORMAT_ERROR = "id格式错误,请检查id参数";
|
||||
|
||||
String PORT_RANGE_ERROR = "端口号范围错误,请检查port参数";
|
||||
|
||||
String NAME_NOT_BLANK = "名称不能为空,请检查name参数";
|
||||
|
||||
String NAME_FORMAT_ERROR = "名称格式错误,请检查name参数";
|
||||
|
||||
String PATTERN_NOT_BLANK = "模式不能为空,请检查pattern参数";
|
||||
|
||||
String DEV_TYPE_NOT_BLANK = "设备类型不能为空,请检查devType参数";
|
||||
|
||||
String DEV_CHNS_NOT_NULL = "设备通道系数不能为空,请检查devChns参数";
|
||||
|
||||
String DEV_VOLT_NOT_NULL = "额定电压不能为空,请检查devVolt参数";
|
||||
|
||||
String DEV_CURR_NOT_NULL = "额定电流不能为空,请检查devCurr参数";
|
||||
|
||||
String MANUFACTURER_NOT_BLANK = "设备厂家不能为空,请检查manufacturer参数";
|
||||
|
||||
String CREATEDATETIME_NOT_NULL = "出厂日期不能为空,请检查producedDate参数";
|
||||
|
||||
String CREATEDATETIME_FORMAT_ERROR = "出厂日期格式错误,请检查createDateTime参数";
|
||||
|
||||
String FACTORYNO_NOT_BLANK = "出厂编号不能为空,请检查factoryNo参数";
|
||||
|
||||
String FIRMWARE_NOT_BLANK = "固件版本不能为空,请检查firmware参数";
|
||||
|
||||
String SOFTWARE_NOT_BLANK = "软件版本不能为空,请检查software参数";
|
||||
|
||||
String PROTOCOL_NOT_BLANK = "通讯协议不能为空,请检查protocol参数";
|
||||
|
||||
String IP_NOT_BLANK = "IP地址不能为空,请检查ip参数";
|
||||
|
||||
String IP_FORMAT_ERROR = "IP地址格式错误,请检查ip参数";
|
||||
|
||||
String PORT_NOT_NULL = "端口号不能为空,请检查port参数";
|
||||
|
||||
String ENCRYPTION_NOT_NULL = "是否为加密版本不能为空,请检查encryption参数";
|
||||
|
||||
String RECHECK_NUM_NOT_NULL = "检测次数不能为空,请检查reCheckNum参数";
|
||||
|
||||
String PLAN_ID_NOT_NULL = "检测计划ID不能为空,请检查planId参数";
|
||||
|
||||
String PQ_DEV_IDS_NOT_NULL = "设备ID集合不能为null,请检查pqDevIds参数";
|
||||
|
||||
String ARRIVE_DATE_FORMAT_ERROR = "送样日期格式错误,请检查arrivedDateTime参数";
|
||||
|
||||
String ENCRYPTION_FLAG_FORMAT_ERROR = "是否为加密版本格式错误,请检查encryptionFlag参数";
|
||||
|
||||
String RECHECK_NUM_FORMAT_ERROR = "检测次数格式错误,请检查recheckNum参数";
|
||||
|
||||
String PATTERN_FORMAT_ERROR = "模式格式错误,请检查pattern参数";
|
||||
|
||||
String SOURCE_IDS_NOT_EMPTY = "检测源ID不能为空,请检查sourceIds参数";
|
||||
|
||||
String SOURCE_ID_FORMAT_ERROR = "检测源ID格式错误,请检查sourceIds参数";
|
||||
|
||||
String DEV_TYPE_FORMAT_ERROR = "设备类型格式错误,请检查devType参数";
|
||||
|
||||
String DEV_CHNS_RANGE_ERROR = "设备通道系数错误,请检查devChns参数";
|
||||
|
||||
String MANUFACTURER_FORMAT_ERROR = "设备厂家格式错误,请检查manufacturer参数";
|
||||
|
||||
String PROTOCOL_FORMAT_ERROR = "通讯协议格式错误,请检查protocol参数";
|
||||
|
||||
String PLAN_ID_FORMAT_ERROR = "检测计划ID格式错误,请检查planId参数";
|
||||
|
||||
String STANDARD_TIME_FORMAT_ERROR = "标准推行时间格式错误,请检查standardTime参数";
|
||||
|
||||
String SCRIPT_TYPE_NOT_BLANK = "检测脚本类型不能为空,请检查scriptType参数";
|
||||
|
||||
String STANDARD_NAME_NOT_BLANK = "参照标准名称不能为空,请检查standardName参数";
|
||||
|
||||
String STANDARD_NAME_FORMAT_ERROR = "参照标准名称格式错误,请检查standardName参数";
|
||||
|
||||
String STANDARD_TIME_NOT_BLANK = "标准推行时间不能为空,请检查standardTime参数";
|
||||
|
||||
String SCRIPT_TYPE_FORMAT_ERROR = "检测脚本类型格式错误,请检查scriptType参数";
|
||||
|
||||
String DEV_LEVEL_NOT_BLANK = "设备等级不能为空,请检查devLevel参数";
|
||||
|
||||
String DEV_LEVEL_FORMAT_ERROR = "设备等级格式错误,请检查devLevel参数";
|
||||
|
||||
String ENABLE_FORMAT_ERROR = "是否启用格式错误,请检查enable参数";
|
||||
|
||||
String ERR_SYS_ID_NOT_BLANK = "误差体系ID不能为空,请检查errSysId参数";
|
||||
|
||||
String ERR_SYS_DTLS_ERROR_TYPE_NOT_BLANK = "误差项类型不能为空,请检查errorType参数";
|
||||
|
||||
String ERR_SYS_DTLS_ERROR_TYPE_FORMAT_ERROR = "误差项类型格式错误,请检查errorType参数";
|
||||
|
||||
String ERR_SYS_DTLS_SCRIPT_TYPE_NOT_BLANK = "脚本项类型不能为空,请检查scriptType参数";
|
||||
|
||||
String ERR_SYS_DTLS_SCRIPT_TYPE_FORMAT_ERROR = "脚本项类型格式错误,请检查scriptType参数";
|
||||
|
||||
String START_VALUE_NOT_NULL = "起始值不能为空,请检查startValue参数";
|
||||
|
||||
String START_FLAG_NOT_NULL = "是否包含起始值不能为空,请检查startFlag参数";
|
||||
|
||||
String END_VALUE_NOT_NULL = "结束值不能为空,请检查endValue参数";
|
||||
|
||||
String END_FLAG_NOT_NULL = "是否包含结束值不能为空,请检查endFlag参数";
|
||||
|
||||
String CONDITION_TYPE_NOT_BLANK = "判断条件类型不能为空,请检查conditionType参数";
|
||||
|
||||
String ERROR_VALUE_FORMAT_ERROR = "误差值格式错误,请检查errorValue参数";
|
||||
|
||||
String MAX_ERROR_VALUE_NOT_NULL = "最大误差值不能为空,请检查maxErrorValue参数";
|
||||
|
||||
String ERROR_VALUE_TYPE_NOT_BLANK = "误差值类型不能为空,请检查errorValueType参数";
|
||||
|
||||
String PQ_SOURCE_TYPE_NOT_BLANK = "检测源类型不能为空,请检查pqSourceType参数";
|
||||
|
||||
String PQ_SOURCE_TYPE_FORMAT_ERROR = "检测源类型格式错误,请检查pqSourceType参数";
|
||||
|
||||
String ENABLE_NOT_NULL = "状态不能为空,请检查enable参数";
|
||||
|
||||
String PQ_SOURCE_NAME_FORMAT_ERROR = "检测源名称格式错误,请检查pqSourceName参数";
|
||||
|
||||
String PQ_SOURCE_PARAMETER_ID_NOT_BLANK = "检测源参数ID不能为空,请检查pqSourceParameterId参数";
|
||||
|
||||
String PQ_SOURCE_PARAMETER_PID_NOT_BLANK = "检测源参数PID不能为空,请检查pqSourceParameterId参数";
|
||||
|
||||
String PQ_SOURCE_PARAMETER_TYPE_NOT_BLANK = "检测源参数类型不能为空,请检查pqSourceParameterType参数";
|
||||
|
||||
String PQ_SOURCE_PARAMETER_REMARK_NOT_BLANK = "检测源参数描述不能为空,请检查pqSourceParameterRemark参数";
|
||||
|
||||
String PQ_SOURCE_PARAMETER_VALUE_NOT_BLANK = "参数值不能为空,请检查pqSourceParameterValue参数";
|
||||
|
||||
String DEV_ID_NOT_BLANK = "设备ID不能为空";
|
||||
|
||||
String DEV_ID_FORMAT_ERROR = "设备ID格式错误";
|
||||
|
||||
String BELONG_LINE_NOT_BLANK = "所属母线不能为空";
|
||||
|
||||
String PT_NOT_NULL = "PT变比不能为空";
|
||||
|
||||
String CT_NOT_NULL = "CT变比不能为空";
|
||||
|
||||
String WIRING_TYPE_NOT_BLANK = "接线方式不能为空";
|
||||
|
||||
String WIRING_TYPE_FORMAT_ERROR = "接线方式格式错误";
|
||||
|
||||
String DATASOURCE_ID_NOT_EMPTY = "数据源ID不能为空";
|
||||
|
||||
String SCRIPT_ID_NOT_BLANK = "检测脚本ID不能为空";
|
||||
|
||||
String SCRIPT_ID_FORMAT_ERROR = "检测脚本ID格式错误";
|
||||
|
||||
String ERROR_SYS_ID_NOT_BLANK = "误差体系ID不能为空";
|
||||
|
||||
String ERROR_SYS_ID_FORMAT_ERROR = "误差体系ID格式错误";
|
||||
|
||||
String TIME_CHECK_NOT_NULL = "守时检测不能为空";
|
||||
|
||||
String TIME_CHECK_FORMAT_ERROR = "守时检测格式错误";
|
||||
|
||||
String TEST_STATE_NOT_NULL = "检测状态不能为空";
|
||||
|
||||
String TEST_STATE_FORMAT_ERROR = "检测状态格式错误";
|
||||
|
||||
String REPORT_STATE_NOT_NULL = "报告生成状态不能为空";
|
||||
|
||||
String REPORT_STATE_FORMAT_ERROR = "报告生成状态格式错误";
|
||||
|
||||
String CHECK_RESULT_STATE_NOT_NULL = "检测结果不能为空";
|
||||
|
||||
String CHECK_RESULT_STATE_FORMAT_ERROR = "检测结果格式错误";
|
||||
|
||||
String CHECK_STATE_FORMAT_ERROR = "检测状态格式错误";
|
||||
|
||||
String CHECK_RESULT_FORMAT_ERROR = "检测结果格式错误";
|
||||
|
||||
String DOCUMENT_STATE_FORMAT_ERROR = "归档状态格式错误";
|
||||
|
||||
String MONITOR_CODE_FORMAT_ERROR = "监测点编码格式错误";
|
||||
|
||||
String MONITOR_NUM_NOT_NULL = "监测点序号不能为空";
|
||||
|
||||
String FACTOR_FLAG_FORMAT_ERROR = "是否支持系数校准格式错误";
|
||||
|
||||
String MONITOR_NUM_FORMAT_ERROR = "监测点序号格式错误";
|
||||
|
||||
String SOURC_NOT_BLANK = "检测源不能为空";
|
||||
|
||||
String DATASOURCE_NOT_BLANK = "数据源不能为空";
|
||||
|
||||
String SCRIPT_NOT_BLANK = "检测脚本不能为空";
|
||||
|
||||
String ERRORSYS_NOT_BLANK = "误差体系不能为空";
|
||||
|
||||
String TIMECHECK_NOT_BLANK = "是否做守时检测不能为空";
|
||||
|
||||
String FACTOR_FLAG_NOT_BLANK = "是否支持系数校准不能为空";
|
||||
|
||||
String CONDITION_TYPE_FORMAT_ERROR = "判断条件类型格式错误,请检查conditionType参数";
|
||||
|
||||
String SORT_NOT_NULL = "排序不能为空";
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.njcn.gather.device.pojo.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2024-12-12
|
||||
*/
|
||||
@Getter
|
||||
public enum CheckResultEnum {
|
||||
NOT_ACCORD("不符合", 0),
|
||||
ACCORD("符合", 1),
|
||||
UNCHECKED("未检", 2);
|
||||
|
||||
private final Integer value;
|
||||
private final String msg;
|
||||
|
||||
CheckResultEnum(String msg, Integer value) {
|
||||
this.msg = msg;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static String getMsgByValue(Integer value) {
|
||||
for (CheckStateEnum state : CheckStateEnum.values()) {
|
||||
if (state.getValue().equals(value)) {
|
||||
return state.getMsg();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.njcn.gather.device.pojo.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2024-12-12
|
||||
*/
|
||||
@Getter
|
||||
public enum CheckStateEnum {
|
||||
UNCHECKED("未检", 0),
|
||||
CHECKING("检测中", 1),
|
||||
CHECKED("检测完成", 2),
|
||||
/**
|
||||
* 检测计划没有该状态,只有未检、检测中、检测完成三种状态。被检设备有这种状态
|
||||
*/
|
||||
DOCUMENTED("归档", 3);
|
||||
|
||||
private final Integer value;
|
||||
private final String msg;
|
||||
|
||||
CheckStateEnum(String msg, Integer value) {
|
||||
this.msg = msg;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static String getMsgByValue(Integer value) {
|
||||
for (CheckStateEnum state : CheckStateEnum.values()) {
|
||||
if (state.getValue().equals(value)) {
|
||||
return state.getMsg();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.njcn.gather.device.pojo.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2024-12-13
|
||||
*/
|
||||
@Getter
|
||||
public enum CommonEnum {
|
||||
FATHER_ID("0", "无"),
|
||||
|
||||
NO("0", "否"),
|
||||
YES("1", "是"),
|
||||
;
|
||||
|
||||
private String value;
|
||||
private String msg;
|
||||
|
||||
CommonEnum(String value, String msg) {
|
||||
this.value = value;
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.njcn.gather.device.pojo.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2024-12-12
|
||||
*/
|
||||
@Getter
|
||||
public enum DevDocumentStateEnum {
|
||||
UNDOCUMENTED("未归档", 0),
|
||||
DOCUMENTED("归档", 1);
|
||||
|
||||
private final Integer value;
|
||||
private final String msg;
|
||||
|
||||
DevDocumentStateEnum(String msg, Integer value) {
|
||||
this.msg = msg;
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.njcn.gather.device.pojo.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2024-12-12
|
||||
*/
|
||||
@Getter
|
||||
public enum DevReportStateEnum {
|
||||
NOT_GENERATED("未生成", 0),
|
||||
GENERATED("已生成", 1),
|
||||
UNCHECKED("未检", 2);
|
||||
|
||||
private final Integer value;
|
||||
private final String msg;
|
||||
|
||||
DevReportStateEnum(String msg, Integer value) {
|
||||
this.msg = msg;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static String getMsgByValue(Integer value) {
|
||||
for (CheckStateEnum state : CheckStateEnum.values()) {
|
||||
if (state.getValue().equals(value)) {
|
||||
return state.getMsg();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user