Merge remote-tracking branch 'origin/master'
# Conflicts: # detection/src/main/java/com/njcn/gather/device/service/impl/PqDevServiceImpl.java
This commit is contained in:
@@ -355,12 +355,13 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
||||
pqDevVO.setDevKey(EncryptionUtil.decoderString(1, pqDevVO.getDevKey()));
|
||||
}
|
||||
if (StrUtil.isNotBlank(pqDevVO.getCheckBy())) {
|
||||
SysUser user = userService.getById(pqDevVO.getCheckBy());
|
||||
if (ObjectUtil.isNotNull(user)) {
|
||||
pqDevVO.setCheckBy(user.getName());
|
||||
SysUser sysUser = userService.getById(pqDevVO.getCheckBy());
|
||||
if (ObjectUtil.isNotNull(sysUser)) {
|
||||
pqDevVO.setCheckBy(sysUser.getName());
|
||||
} else {
|
||||
pqDevVO.setCheckBy(pqDevVO.getCheckBy());
|
||||
}
|
||||
}
|
||||
|
||||
DevType devType = devTypeService.getById(pqDevVO.getDevType());
|
||||
if (ObjectUtil.isNotNull(devType)) {
|
||||
pqDevVO.setDevChns(devType.getDevChns());
|
||||
@@ -794,7 +795,7 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
||||
}
|
||||
int count = this.count(queryWrapper);
|
||||
if (count > 0) {
|
||||
throw new BusinessException(DetectionResponseEnum.PQ_DEV_REPEAT);
|
||||
throw new BusinessException(DetectionResponseEnum.PQ_DEV_REPEAT, "【" + param.getName() + "】被检设备已存在");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1195,10 +1196,23 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
||||
@Transactional
|
||||
public boolean importContrastDev(List<ContrastDevExcel> contrastDevExcelList, String patternId, String planId) {
|
||||
if (CollUtil.isNotEmpty(contrastDevExcelList)) {
|
||||
List<PqMonitor> monitorList = new ArrayList<>();
|
||||
List<PqDev> oldDevList = contrastDevExcelList.stream().map(devExcel -> {
|
||||
// 根据设备名称分组
|
||||
Map<String, List<ContrastDevExcel>> listMap = contrastDevExcelList.stream()
|
||||
.collect(Collectors.groupingBy(ContrastDevExcel::getName, LinkedHashMap::new, Collectors.toList()));
|
||||
List<PqDev> oldDevList = new ArrayList<>(listMap.size());
|
||||
List<PqMonitor> finalMonitorList = new ArrayList<>();
|
||||
for (Map.Entry<String, List<ContrastDevExcel>> entry : listMap.entrySet()) {
|
||||
String name = entry.getKey();
|
||||
List<ContrastDevExcel> devExcelList = entry.getValue();
|
||||
// 监测点数据
|
||||
List<PqMonitorExcel> pqMonitorExcelList = devExcelList.stream()
|
||||
.map(ContrastDevExcel::getPqMonitorExcelList)
|
||||
.filter(Objects::nonNull)
|
||||
.flatMap(List::stream)
|
||||
.collect(Collectors.toList());
|
||||
// 取第一条为设备基本信息
|
||||
ContrastDevExcel devExcel = devExcelList.get(0);
|
||||
PqDev pqDev = BeanUtil.copyProperties(devExcel, PqDev.class);
|
||||
|
||||
if (pqDev.getEncryptionFlag() == 1) {
|
||||
if (StrUtil.isNotBlank(pqDev.getSeries()) && StrUtil.isNotBlank(pqDev.getDevKey())) {
|
||||
pqDev.setSeries(EncryptionUtil.encodeString(1, pqDev.getSeries()));
|
||||
@@ -1210,43 +1224,47 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
||||
DevType devType = devTypeService.getByName(pqDev.getDevType());
|
||||
if (ObjectUtil.isNull(devType)) {
|
||||
throw new BusinessException(DetectionResponseEnum.DEV_TYPE_NOT_EXIST);
|
||||
} else {
|
||||
pqDev.setDevType(devType.getId());
|
||||
|
||||
Integer devChns = devType.getDevChns();
|
||||
List<Integer> numList = devExcel.getPqMonitorExcelList().stream().map(monitorExcel -> monitorExcel.getNum()).collect(Collectors.toList());
|
||||
if (CollUtil.isNotEmpty(numList)) {
|
||||
Integer max = CollectionUtil.max(numList);
|
||||
Integer min = CollectionUtil.min(numList);
|
||||
if (min < 1 || max > devChns) {
|
||||
throw new BusinessException(DetectionResponseEnum.MONITOR_NUM_OUT_OF_RANGE);
|
||||
}
|
||||
if (min == max && numList.size() > 1) {
|
||||
throw new BusinessException(DetectionResponseEnum.MONITOR_NUM_REPEAT);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 校验监测点数量
|
||||
int devChns = devType.getDevChns();
|
||||
if (pqMonitorExcelList.size() != devChns) {
|
||||
throw new BusinessException(DetectionResponseEnum.IMPORT_DATA_FAIL, "【" + name + "】的设备类型必须具备" + devChns + "个监测点信息!");
|
||||
}
|
||||
List<Integer> numList = pqMonitorExcelList.stream().map(PqMonitorExcel::getNum).collect(Collectors.toList());
|
||||
// 判断是否有重复的num
|
||||
Set<Integer> uniqueNumSet = new HashSet<>(numList);
|
||||
if (uniqueNumSet.size() != numList.size()) {
|
||||
throw new BusinessException(DetectionResponseEnum.MONITOR_NUM_REPEAT);
|
||||
}
|
||||
Integer max = CollectionUtil.max(numList);
|
||||
Integer min = CollectionUtil.min(numList);
|
||||
if (min < 1 || max > devChns) {
|
||||
throw new BusinessException(DetectionResponseEnum.MONITOR_NUM_OUT_OF_RANGE);
|
||||
}
|
||||
|
||||
pqDev.setDevType(devType.getId());
|
||||
pqDev.setImportFlag(1);
|
||||
pqDev.setId(UUID.randomUUID().toString().replaceAll("-", ""));
|
||||
pqDev.setCreateId(pqDev.getName()); //导入时设备序列号默认与设备名称相同
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < devExcel.getPqMonitorExcelList().size(); i++) {
|
||||
PqMonitor monitor = BeanUtil.copyProperties(devExcel.getPqMonitorExcelList().get(i), PqMonitor.class);
|
||||
if (StrUtil.isBlank(monitor.getName())) {
|
||||
continue;
|
||||
}
|
||||
sb.append(monitor.getNum() + StrUtil.COMMA);
|
||||
List<PqMonitor> monitorList = new ArrayList<>();
|
||||
// 根据num排序
|
||||
pqMonitorExcelList.sort(Comparator.comparingInt(PqMonitorExcel::getNum));
|
||||
for (PqMonitorExcel pqMonitorExcel : pqMonitorExcelList) {
|
||||
PqMonitor monitor = BeanUtil.copyProperties(pqMonitorExcel, PqMonitor.class);
|
||||
monitor.setDevId(pqDev.getId());
|
||||
monitorList.add(monitor);
|
||||
}
|
||||
if (sb.length() > 0) {
|
||||
pqDev.setInspectChannel(sb.replace(sb.length() - 1, sb.length(), "").toString());
|
||||
StringBuilder inspectChannelBuilder = new StringBuilder();
|
||||
for (int i = 1; i <= devChns; i++) {
|
||||
inspectChannelBuilder.append(i);
|
||||
if (i < devChns) {
|
||||
inspectChannelBuilder.append(",");
|
||||
}
|
||||
}
|
||||
return pqDev;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
pqDev.setInspectChannel(inspectChannelBuilder.toString());
|
||||
oldDevList.add(pqDev);
|
||||
finalMonitorList.addAll(monitorList);
|
||||
}
|
||||
//逆向可视化
|
||||
this.reverseVisualizeProvinceDev(oldDevList, patternId);
|
||||
|
||||
@@ -1275,7 +1293,7 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
||||
PqDev newDev = newDevList.stream().filter(dev -> dev.getHarmSysId().equals(oldDev.getHarmSysId())).findFirst().orElse(null);
|
||||
if (ObjectUtil.isNotNull(newDev)) {
|
||||
newDevList.remove(newDev);
|
||||
monitorList.stream()
|
||||
finalMonitorList.stream()
|
||||
.filter(monitor -> monitor.getDevId().equals(newDev.getId()))
|
||||
.forEach(monitor -> monitor.setDevId(oldDev.getId()));
|
||||
BeanUtil.copyProperties(newDev, oldDev, "id");
|
||||
@@ -1303,8 +1321,8 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
||||
.in("pq_monitor.Dev_Id", devIdList);
|
||||
pqMonitorService.remove(wrapper);
|
||||
}
|
||||
pqMonitorService.reverseVisualizeMonitor(monitorList);
|
||||
pqMonitorService.saveBatch(monitorList);
|
||||
pqMonitorService.reverseVisualizeMonitor(finalMonitorList);
|
||||
pqMonitorService.saveBatch(finalMonitorList);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -1420,11 +1438,6 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
||||
pqDev.setDelegate(delegateDictData.getId());
|
||||
}
|
||||
}
|
||||
// pqDev.setTimeCheckResult(TimeCheckResultEnum.UNKNOWN.getValue());
|
||||
// pqDev.setFactorCheckResult(FactorCheckResultEnum.UNKNOWN.getValue());
|
||||
// pqDev.setCheckState(CheckStateEnum.UNCHECKED.getValue());
|
||||
// pqDev.setReportState(DevReportStateEnum.UNCHECKED.getValue());
|
||||
// pqDev.setCheckResult(CheckResultEnum.UNCHECKED.getValue());
|
||||
pqDev.setState(DataStateEnum.ENABLE.getCode());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -111,4 +111,5 @@ public interface IPqMonitorService extends IService<PqMonitor> {
|
||||
* @return
|
||||
*/
|
||||
Integer getDevCheckResult(String devId);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.njcn.gather.plan.controller;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
import com.njcn.common.pojo.constant.OperateType;
|
||||
@@ -13,6 +15,7 @@ import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.LogUtil;
|
||||
import com.njcn.gather.device.pojo.enums.CommonEnum;
|
||||
import com.njcn.gather.device.pojo.param.PqDevParam;
|
||||
import com.njcn.gather.device.pojo.po.PqDev;
|
||||
import com.njcn.gather.device.pojo.po.PqStandardDev;
|
||||
import com.njcn.gather.device.pojo.vo.PqDevVO;
|
||||
import com.njcn.gather.device.service.IPqDevService;
|
||||
@@ -397,10 +400,17 @@ public class AdPlanController extends BaseController {
|
||||
@ApiImplicitParam(name = "devIds", value = "被检设备ids", required = true),
|
||||
@ApiImplicitParam(name = "report", value = "是否导出报告, 0 否,1 是", required = true)
|
||||
})
|
||||
public void exportPlanCheckData(@RequestParam("planId") String planId, @RequestParam("devIds") String devIds, @RequestParam("report") Integer report, HttpServletResponse response) {
|
||||
public HttpResult<Boolean> exportPlanCheckData(@RequestParam("planId") String planId, @RequestParam("devIds") String devIds, @RequestParam("report") Integer report) {
|
||||
String methodDescribe = getMethodDescribe("exportPlanCheckData");
|
||||
LogUtil.njcnDebug(log, "{},导出ID数据为:{} {} {}", methodDescribe, planId, devIds, report);
|
||||
adPlanService.exportPlanCheckDataZip(planId, StrUtil.split(devIds, StrUtil.COMMA), report, response);
|
||||
LogUtil.njcnDebug(log, "{},导出计划ID数据为:{} {} {}", methodDescribe, planId, devIds, report);
|
||||
// 获取检测计划绑定的被检设备数据
|
||||
List<PqDev> devList = pqDevService.list(new LambdaQueryWrapper<PqDev>().eq(PqDev::getPlanId, planId).in(PqDev::getId, StrUtil.split(devIds, StrUtil.COMMA)));
|
||||
if (CollUtil.isEmpty(devList)) {
|
||||
throw new BusinessException(CommonResponseEnum.FAIL, "选择的被检设备不存在");
|
||||
}
|
||||
asyncPlanHandler.exportPlanCheckDataZip(getUserId(), planId, devList, report);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -10,13 +10,13 @@ import java.util.Objects;
|
||||
*/
|
||||
@Getter
|
||||
public enum DataSourceEnum {
|
||||
REAL_DATA("real", "3s实时数据"),
|
||||
REAL_DATA("real", "3s数据(150周波数据)"),
|
||||
|
||||
MINUTE_STATISTICS_MAX("max", "分钟统计数据-最大"),
|
||||
MINUTE_STATISTICS_MIN("min", "分钟统计数据-最小"),
|
||||
MINUTE_STATISTICS_AVG("avg", "分钟统计数据-平均"),
|
||||
MINUTE_STATISTICS_CP95("cp95", "分钟统计数据-CP95"),
|
||||
WAVE_DATA("wave_data", "录波");
|
||||
MINUTE_STATISTICS_MAX("max", "分钟统计数据-最大值"),
|
||||
MINUTE_STATISTICS_MIN("min", "分钟统计数据-最小值"),
|
||||
MINUTE_STATISTICS_AVG("avg", "分钟统计数据-平均值"),
|
||||
MINUTE_STATISTICS_CP95("cp95", "分钟统计数据-CP95值"),
|
||||
WAVE_DATA("wave_data", "录波数据");
|
||||
|
||||
private String value;
|
||||
private String msg;
|
||||
|
||||
@@ -2,17 +2,23 @@ package com.njcn.gather.plan.service;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.util.ZipUtil;
|
||||
import cn.hutool.json.JSONConfig;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.gather.detection.pojo.po.AdPair;
|
||||
import com.njcn.gather.detection.service.IAdPariService;
|
||||
import com.njcn.gather.device.pojo.enums.CheckStateEnum;
|
||||
import com.njcn.gather.device.pojo.po.PqDev;
|
||||
import com.njcn.gather.device.pojo.po.PqDevSub;
|
||||
import com.njcn.gather.device.service.IPqDevService;
|
||||
import com.njcn.gather.device.service.IPqDevSubService;
|
||||
import com.njcn.gather.monitor.pojo.po.PqMonitor;
|
||||
import com.njcn.gather.monitor.service.IPqMonitorService;
|
||||
import com.njcn.gather.plan.pojo.po.AdPlan;
|
||||
import com.njcn.gather.plan.pojo.vo.AdPlanCheckDataVO;
|
||||
import com.njcn.gather.plan.service.util.BatchFileReader;
|
||||
@@ -33,9 +39,13 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@EnableAsync
|
||||
@@ -48,20 +58,185 @@ public class AsyncPlanHandler {
|
||||
private final IPqDevService pqDevService;
|
||||
private final IDevTypeService devTypeService;
|
||||
private final IPqDevSubService pqDevSubService;
|
||||
private final IPqMonitorService pqMonitorService;
|
||||
|
||||
private final IAdPariService adPairService;
|
||||
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
@Value("${report.reportDir}")
|
||||
private String reportPath;
|
||||
@Value("${data.homeDir}")
|
||||
private String dataPath;
|
||||
|
||||
private static final int BATCH_SIZE = 10000;
|
||||
private static final int FINAL_STEP = 85;
|
||||
private static final String TEST_DATA_DIR = "plan_test_data";
|
||||
|
||||
|
||||
@Async
|
||||
public void exportPlanCheckDataZip(String uid, String planId, List<PqDev> devList, Integer report) {
|
||||
NonWebAutoFillValueHandler.setCurrentUserId(uid);
|
||||
LocalDateTime startTime = LocalDateTime.now();
|
||||
AdPlanCheckDataVO planCheckDataVO = new AdPlanCheckDataVO();
|
||||
AtomicInteger progress = new AtomicInteger(0);
|
||||
AtomicInteger currentProgress = new AtomicInteger(0);
|
||||
sseClient.sendMessage(uid, planId, HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), progress, "开始导出文件"));
|
||||
|
||||
// 获取检测计划基本数据
|
||||
AdPlan plan = adPlanService.getById(planId);
|
||||
planCheckDataVO.setPlan(plan);
|
||||
planCheckDataVO.setDevList(devList);
|
||||
List<String> devIdList = devList.stream().map(PqDev::getId).collect(Collectors.toList());
|
||||
// 被检设备状态统计
|
||||
List<PqDevSub> devSubList = pqDevSubService.list(new LambdaQueryWrapper<PqDevSub>().in(PqDevSub::getDevId, devIdList));
|
||||
planCheckDataVO.setDevSubList(devSubList);
|
||||
// 被检设备监测点信息
|
||||
List<PqMonitor> monitorList = pqMonitorService.list(new LambdaQueryWrapper<PqMonitor>().in(PqMonitor::getDevId, devIdList));
|
||||
planCheckDataVO.setMonitorList(monitorList);
|
||||
// devMonitorId = 被检设备ID+通道号
|
||||
List<String> devMonitorIds = new ArrayList<>();
|
||||
for (PqDev dev : devList) {
|
||||
List<String> channelNoList = StrUtil.split(dev.getInspectChannel(), StrUtil.COMMA);
|
||||
for (String channelNo : channelNoList) {
|
||||
devMonitorIds.add(dev.getId() + StrUtil.UNDERLINE + channelNo);
|
||||
}
|
||||
}
|
||||
planCheckDataVO.setDevMonitorIds(devMonitorIds);
|
||||
|
||||
// 设备通道匹对关系
|
||||
List<AdPair> pairList = adPairService.list(new LambdaQueryWrapper<AdPair>().eq(AdPair::getPlanId, planId).in(AdPair::getDevMonitorId, devMonitorIds));
|
||||
planCheckDataVO.setPairList(pairList);
|
||||
progress.addAndGet(1);
|
||||
sseClient.sendMessage(uid, planId, HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), progress, "生成检测计划基本信息数据文件中,请耐心等待..."));
|
||||
|
||||
// 获取计划检测结果数据表以及数据
|
||||
Integer code = plan.getCode();
|
||||
List<String> dataTableNames = CollUtil.newArrayList("ad_harmonic_" + code, "ad_non_harmonic_" + code, "ad_harmonic_result_" + code, "ad_non_harmonic_result_" + code);
|
||||
|
||||
// 创建临时目录用于存储文件
|
||||
File tempDataDir = FileUtil.mkdir(FileUtil.getTmpDirPath() + "plan_test_data_" + System.currentTimeMillis() + "/");
|
||||
int dataBatch = 0;
|
||||
int current = 0;
|
||||
if (CollUtil.isNotEmpty(pairList)) {
|
||||
for (String dataTableName : dataTableNames) {
|
||||
// 创建数据文件
|
||||
String fileName = dataTableName.replace("_" + code, "") + ".txt";
|
||||
File dataFile = FileUtil.file(tempDataDir, fileName);
|
||||
// 确保文件存在
|
||||
FileUtil.touch(dataFile);
|
||||
|
||||
// 初始化写入标志,用于判断是否已写入字段名
|
||||
boolean isFirstWrite = true;
|
||||
|
||||
// 分页查询,避免一次性加载大量数据
|
||||
int pageSize = BATCH_SIZE; // 每页查询10000条记录
|
||||
int offset = 0;
|
||||
List<Map<String, Object>> pageData;
|
||||
do {
|
||||
dataBatch += 1;
|
||||
if (current < FINAL_STEP + 5) {
|
||||
current = Math.min(current + 1, FINAL_STEP + 5);
|
||||
}
|
||||
currentProgress.set(current);
|
||||
sseClient.sendMessage(uid, planId, HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), progress.get() + currentProgress.get(), "生成检测结果数据文件中,请耐心等待..."));
|
||||
|
||||
String paginatedSql = buildPaginatedQuery(dataTableName, devMonitorIds, pageSize, offset);
|
||||
pageData = jdbcTemplate.queryForList(paginatedSql);
|
||||
|
||||
// 将当前页数据追加到文件中
|
||||
if (CollUtil.isNotEmpty(pageData)) {
|
||||
StringBuilder content = new StringBuilder();
|
||||
|
||||
// 如果是第一次写入,先写入字段名
|
||||
if (isFirstWrite) {
|
||||
// 获取字段名
|
||||
Map<String, Object> firstRow = pageData.get(0);
|
||||
List<String> fieldNames = new ArrayList<>(firstRow.keySet());
|
||||
|
||||
// 写入字段名作为第一行
|
||||
content.append(StrUtil.join("\t", fieldNames)).append(System.lineSeparator());
|
||||
isFirstWrite = false;
|
||||
}
|
||||
|
||||
// 写入数据行
|
||||
for (Map<String, Object> data : pageData) {
|
||||
List<Object> values = new ArrayList<>(data.values());
|
||||
content.append(StrUtil.join("\t", values)).append(System.lineSeparator());
|
||||
}
|
||||
|
||||
// 追加内容到文件
|
||||
FileUtil.appendUtf8String(content.toString(), dataFile);
|
||||
}
|
||||
offset += pageSize;
|
||||
|
||||
} while (pageData.size() == pageSize); // 如果查询结果少于pageSize,说明已经查询完所有数据
|
||||
}
|
||||
}
|
||||
planCheckDataVO.setDataBatch(dataBatch);
|
||||
int currentVal = progress.get() + currentProgress.get();
|
||||
if (currentVal < FINAL_STEP + 5) {
|
||||
progress.addAndGet(FINAL_STEP + 5);
|
||||
} else {
|
||||
progress.set(currentVal);
|
||||
}
|
||||
sseClient.sendMessage(uid, planId, HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), progress, "压缩检测结果数据文件中,请耐心等待..."));
|
||||
|
||||
// 导出数据.zip文件
|
||||
String jsonStr = JSONUtil.toJsonStr(planCheckDataVO, new JSONConfig().setIgnoreNullValue(false));
|
||||
try {
|
||||
// 创建 JSON 文件
|
||||
String jsonFileName = plan.getName() + ".json";
|
||||
File jsonFile = FileUtil.file(tempDataDir, jsonFileName);
|
||||
FileUtil.writeUtf8String(jsonStr, jsonFile);
|
||||
|
||||
// 创建 ZIP 文件
|
||||
String zipFileName = plan.getName() + "_检测数据包.zip";
|
||||
File zipFile = FileUtil.file(dataPath + File.separator + TEST_DATA_DIR + File.separator, zipFileName);
|
||||
|
||||
// 添加检测报告文件
|
||||
if (ObjectUtil.isNotNull(report) && report.equals(1)) {
|
||||
for (PqDev dev : devList) {
|
||||
DevType devType = devTypeService.getById(dev.getDevType());
|
||||
String dirPath = reportPath.concat(File.separator).concat(devType.getName());
|
||||
File reportFile = new File(dirPath.concat(File.separator).concat(dev.getCreateId()).concat(ReportConstant.DOCX));
|
||||
// 如果reportFile存在,则将reportFile中的文件添加到已有的zip文件中
|
||||
if (FileUtil.exist(reportFile)) {
|
||||
// 复制reportFile到临时目录
|
||||
FileUtil.copy(reportFile, tempDataDir, true);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// 创建zip文件,包含所有文件
|
||||
ZipUtil.zip(tempDataDir.getAbsolutePath(), zipFile.getAbsolutePath());
|
||||
// 删除临时目录
|
||||
FileUtil.del(tempDataDir);
|
||||
LocalDateTime endTime = LocalDateTime.now();
|
||||
log.info("生成数据包完成,耗时: {}s", Duration.between(startTime, endTime).getSeconds());
|
||||
progress.set(100);
|
||||
sseClient.sendMessage(uid, planId, HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), progress, zipFile.getAbsolutePath()));
|
||||
} catch (Exception e) {
|
||||
log.error("生成数据包失败", e);
|
||||
sseClient.sendMessage(uid, planId, HttpResultUtil.assembleResult(CommonResponseEnum.FAIL.getCode(), progress.get() + currentProgress.get(), "生成数据包失败"));
|
||||
} finally {
|
||||
NonWebAutoFillValueHandler.clearCurrentUserId();
|
||||
}
|
||||
|
||||
sseClient.closeSse(uid);
|
||||
}
|
||||
|
||||
|
||||
@Transactional
|
||||
@Async
|
||||
public void importAndMergePlanCheckData(MultipartFile file, String uid, String planId) {
|
||||
NonWebAutoFillValueHandler.setCurrentUserId(uid);
|
||||
AtomicInteger progress = new AtomicInteger();
|
||||
LocalDateTime startTime = LocalDateTime.now();
|
||||
AtomicInteger progress = new AtomicInteger(0);
|
||||
AtomicInteger currentProgress = new AtomicInteger(0);
|
||||
AtomicInteger dataCount = new AtomicInteger(0);
|
||||
try {
|
||||
sseClient.sendMessage(uid, planId, HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), progress, "开始保存文件"));
|
||||
sseClient.sendMessage(uid, planId, HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), progress, "开始保存文件,请耐心等待..."));
|
||||
// 创建临时目录用于解压文件
|
||||
File tempDir = FileUtil.mkdir(FileUtil.getTmpDirPath() + "import_plan_check_data_" + System.currentTimeMillis() + "/");
|
||||
|
||||
@@ -69,7 +244,7 @@ public class AsyncPlanHandler {
|
||||
File zipFile = FileUtil.file(tempDir, file.getOriginalFilename());
|
||||
file.transferTo(zipFile);
|
||||
progress.addAndGet(1);
|
||||
sseClient.sendMessage(uid, planId, HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), progress, "开始解压文件"));
|
||||
sseClient.sendMessage(uid, planId, HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), progress, "开始解压文件,请耐心等待..."));
|
||||
|
||||
// 解压zip文件
|
||||
File unzipDir = FileUtil.mkdir(FileUtil.file(tempDir, "unzip"));
|
||||
@@ -123,17 +298,18 @@ public class AsyncPlanHandler {
|
||||
}
|
||||
if (!StrUtil.equals(planId, subPlan.getFatherPlanId())) {
|
||||
FileUtil.del(tempDir);
|
||||
sseClient.sendMessage(uid, planId, HttpResultUtil.assembleResult(CommonResponseEnum.FAIL.getCode(), progress, "该当前检修计划的子计划"));
|
||||
sseClient.sendMessage(uid, planId, HttpResultUtil.assembleResult(CommonResponseEnum.FAIL.getCode(), progress, "非当前检修计划的子计划"));
|
||||
return;
|
||||
}
|
||||
progress.addAndGet(1);
|
||||
sseClient.sendMessage(uid, planId, HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), progress, "开始同步计划基本信息"));
|
||||
// 更新检测计划信息
|
||||
checkPlan.setFatherPlanId(subPlan.getFatherPlanId());
|
||||
checkPlan.setImportFlag(0);
|
||||
adPlanService.updateById(checkPlan);
|
||||
sseClient.sendMessage(uid, planId, HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), progress, "开始同步计划基本信息,请耐心等待..."));
|
||||
// 更新检测计划几个状态字段
|
||||
subPlan.setTestState(checkPlan.getTestState());
|
||||
subPlan.setReportState(checkPlan.getReportState());
|
||||
subPlan.setResult(checkPlan.getResult());
|
||||
adPlanService.updateById(subPlan);
|
||||
progress.addAndGet(1);
|
||||
sseClient.sendMessage(uid, planId, HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), progress, "开始同步计划设备信息"));
|
||||
sseClient.sendMessage(uid, planId, HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), progress, "开始同步计划设备信息,请耐心等待..."));
|
||||
|
||||
// 批量更新被检设备信息
|
||||
// 不更新导入标志
|
||||
@@ -145,13 +321,13 @@ public class AsyncPlanHandler {
|
||||
pqDevSubService.update(devSub, new LambdaUpdateWrapper<PqDevSub>().eq(PqDevSub::getDevId, devSub.getDevId()));
|
||||
}
|
||||
progress.addAndGet(1);
|
||||
sseClient.sendMessage(uid, planId, HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), progress, "开始同步通道配对信息"));
|
||||
sseClient.sendMessage(uid, planId, HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), progress, "开始同步通道配对信息,请耐心等待..."));
|
||||
|
||||
// 同步检测数据
|
||||
List<AdPair> pairList = planCheckDataVO.getPairList();
|
||||
adPairService.updateBatchById(pairList);
|
||||
|
||||
|
||||
// 主计划
|
||||
AdPlan plan = adPlanService.getById(planId);
|
||||
if (CollUtil.isNotEmpty(docxFiles)) {
|
||||
progress.addAndGet(1);
|
||||
sseClient.sendMessage(uid, planId, HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), progress, "开始同步检测报告文件"));
|
||||
@@ -170,10 +346,9 @@ public class AsyncPlanHandler {
|
||||
}
|
||||
}
|
||||
if (CollUtil.isNotEmpty(dataFiles)) {
|
||||
AdPlan plan = adPlanService.getById(planId);
|
||||
Integer planCode = plan.getCode();
|
||||
progress.addAndGet(1);
|
||||
sseClient.sendMessage(uid, planId, HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), progress, "开始同步检测数据信息"));
|
||||
sseClient.sendMessage(uid, planId, HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), progress, "开始同步检测数据信息,请耐心等待..."));
|
||||
// 合并前清除相关表数据
|
||||
String mainHarmonicTableName = "ad_harmonic_" + planCode;
|
||||
String mainNonHarmonicTableName = "ad_non_harmonic_" + planCode;
|
||||
@@ -195,7 +370,8 @@ public class AsyncPlanHandler {
|
||||
jdbcTemplate.update("DELETE FROM " + mainNonHarmonicResultTableName + " WHERE dev_monitor_id IN (" + devMonitorIdsStr + ")");
|
||||
}
|
||||
int dataBatch = planCheckDataVO.getDataBatch();
|
||||
int step = 80 / (dataBatch + 1);
|
||||
int stepCount = dataBatch * BATCH_SIZE / FINAL_STEP;
|
||||
|
||||
for (File dataFile : dataFiles) {
|
||||
// 直接插入主计划表中
|
||||
String fileName = FileUtil.mainName(dataFile);
|
||||
@@ -206,9 +382,18 @@ public class AsyncPlanHandler {
|
||||
final boolean[] isFirstBatch = {true};
|
||||
final String[] headers = {null};
|
||||
|
||||
BatchFileReader.readLinesInBatches(dataFile, 10000, lines -> {
|
||||
progress.addAndGet(step);
|
||||
sseClient.sendMessage(uid, planId, HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), progress, "同步检测数据信息中"));
|
||||
BatchFileReader.readLinesInBatches(dataFile, BATCH_SIZE, lines -> {
|
||||
dataCount.addAndGet(lines.size());
|
||||
// 计算当前进度
|
||||
int current = dataCount.get() / stepCount;
|
||||
|
||||
// 确保进度不超过finalStep
|
||||
if (current > FINAL_STEP) {
|
||||
current = FINAL_STEP;
|
||||
}
|
||||
currentProgress.set(current);
|
||||
sseClient.sendMessage(uid, planId, HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), progress.get() + currentProgress.get(), "同步检测数据信息中,请耐心等待..."));
|
||||
|
||||
|
||||
if (CollUtil.isNotEmpty(lines)) {
|
||||
if (isFirstBatch[0]) {
|
||||
@@ -229,30 +414,68 @@ public class AsyncPlanHandler {
|
||||
|
||||
|
||||
progress.addAndGet(1);
|
||||
sseClient.sendMessage(uid, planId, HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), progress, "表 " + tableName + " 数据同步完成"));
|
||||
sseClient.sendMessage(uid, planId, HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), progress.get() + currentProgress.get(), "表 " + tableName + " 数据同步完成"));
|
||||
}
|
||||
}
|
||||
|
||||
progress.addAndGet(1);
|
||||
sseClient.sendMessage(uid, planId, HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), progress, "开始合并检测数据信息"));
|
||||
|
||||
// 删除临时目录
|
||||
FileUtil.del(tempDir);
|
||||
// 更新主计划状态
|
||||
List<String> planIds = adPlanService.lambdaQuery().eq(AdPlan::getFatherPlanId, planId).list().stream().map(AdPlan::getId).collect(Collectors.toList());
|
||||
planIds.add(planId);
|
||||
List<String> devIds = pqDevService.lambdaQuery().in(PqDev::getPlanId, planIds).list().stream().map(PqDev::getId).collect(Collectors.toList());
|
||||
List<PqDevSub> devSubs = pqDevSubService.lambdaQuery().in(PqDevSub::getDevId, devIds).list();
|
||||
long checkedCount = devSubs.stream().filter(sub -> sub.getCheckState().equals(CheckStateEnum.CHECKED.getValue())).count();
|
||||
if (checkedCount > 0) {
|
||||
plan.setTestState(CheckStateEnum.CHECKING.getValue());
|
||||
// 都已检测完成
|
||||
if (checkedCount == devSubs.size()) {
|
||||
plan.setTestState(CheckStateEnum.CHECKED.getValue());
|
||||
}
|
||||
} else {
|
||||
plan.setTestState(CheckStateEnum.UNCHECKED.getValue());
|
||||
// 是否有检测中
|
||||
long checkingCount = devSubs.stream().filter(sub -> sub.getCheckState().equals(CheckStateEnum.CHECKING.getValue())).count();
|
||||
if (checkingCount > 0) {
|
||||
plan.setTestState(CheckStateEnum.CHECKING.getValue());
|
||||
}
|
||||
}
|
||||
adPlanService.updateById(plan);
|
||||
LocalDateTime endTime = LocalDateTime.now();
|
||||
log.info("数据合并完成,耗时:{}s", Duration.between(startTime, endTime).getSeconds());
|
||||
progress.set(100);
|
||||
sseClient.sendMessage(uid, planId, HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), progress, "数据合并完成"));
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("导入数据失败", e);
|
||||
sseClient.sendMessage(uid, planId, HttpResultUtil.assembleResult(CommonResponseEnum.FAIL.getCode(), progress, "导入失败"));
|
||||
sseClient.sendMessage(uid, planId, HttpResultUtil.assembleResult(CommonResponseEnum.FAIL.getCode(), progress.get() + currentProgress.get(), "导入失败"));
|
||||
} finally {
|
||||
NonWebAutoFillValueHandler.clearCurrentUserId();
|
||||
}
|
||||
|
||||
|
||||
sseClient.closeSse(uid);
|
||||
|
||||
}
|
||||
|
||||
// 构建分页查询SQL
|
||||
private String buildPaginatedQuery(String tableName, List<String> devMonitorIds, int limit, int offset) {
|
||||
StringBuilder sql = new StringBuilder("SELECT * FROM " + tableName);
|
||||
|
||||
sql.append(" WHERE Dev_Monitor_Id IN (");
|
||||
for (int i = 0; i < devMonitorIds.size(); i++) {
|
||||
sql.append("'").append(devMonitorIds.get(i)).append("'");
|
||||
if (i < devMonitorIds.size() - 1) {
|
||||
sql.append(",");
|
||||
}
|
||||
}
|
||||
sql.append(")");
|
||||
sql.append(" ORDER BY Id");
|
||||
|
||||
// 添加分页限制
|
||||
sql.append(" LIMIT ").append(limit).append(" OFFSET ").append(offset);
|
||||
|
||||
return sql.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理数据行
|
||||
|
||||
@@ -199,4 +199,10 @@ public interface IAdPlanService extends IService<AdPlan> {
|
||||
*/
|
||||
void exportPlanCheckDataZip(String planId, List<String> devIds, Integer report, HttpServletResponse response);
|
||||
|
||||
/**
|
||||
* 比对模式下计划的检测大项获取
|
||||
* @param planId 计划ID
|
||||
* @return 检测项集合
|
||||
*/
|
||||
List<String> getScriptListContrast(String planId);
|
||||
}
|
||||
|
||||
@@ -85,10 +85,16 @@ public class SseClient {
|
||||
}
|
||||
try {
|
||||
sseEmitter.send(SseEmitter.event().id(messageId).reconnectTime(1 * 60 * 1000L).data(message));
|
||||
log.info("用户{},消息id:{},推送成功:{}", uid, messageId, message);
|
||||
// log.info("用户{},消息id:{},推送成功:{}", uid, messageId, message);
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
log.error("用户{},消息id:{},推送IO异常:{}", uid, messageId, e.getMessage());
|
||||
// 客户端断开连接属于正常情况,不需要重连,直接移除连接
|
||||
sseEmitterMap.remove(uid);
|
||||
sseEmitter.complete();
|
||||
return false;
|
||||
} catch (Exception e) {
|
||||
log.error("用户{},消息id:{},推送异常:{}", uid, messageId, e.getMessage(), e);
|
||||
log.error("用户{},消息id:{},推送其他异常:{}", uid, messageId, e.getMessage(), e);
|
||||
sseEmitter.complete();
|
||||
scheduleReconnect(uid);
|
||||
return false;
|
||||
|
||||
@@ -1835,15 +1835,13 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
|
||||
// 更新检测配置
|
||||
AdPlanTestConfig testConfig = subPlanMetaDataVO.getTestConfig();
|
||||
testConfig.setPlanId(plan.getId());
|
||||
if (testConfig != null) {
|
||||
Integer count = adPlanTestConfigService.lambdaQuery().eq(AdPlanTestConfig::getPlanId, plan.getId()).count();
|
||||
if (count.intValue() == 0) {
|
||||
adPlanTestConfigService.save(testConfig);
|
||||
} else {
|
||||
adPlanTestConfigService.update(testConfig, new LambdaUpdateWrapper<AdPlanTestConfig>().eq(AdPlanTestConfig::getPlanId, plan.getId()));
|
||||
}
|
||||
|
||||
Integer count = adPlanTestConfigService.lambdaQuery().eq(AdPlanTestConfig::getPlanId, plan.getId()).count();
|
||||
if (count.intValue() == 0) {
|
||||
adPlanTestConfigService.save(testConfig);
|
||||
} else {
|
||||
adPlanTestConfigService.update(testConfig, new LambdaUpdateWrapper<AdPlanTestConfig>().eq(AdPlanTestConfig::getPlanId, plan.getId()));
|
||||
}
|
||||
testConfig.setPlanId(plan.getId());
|
||||
|
||||
// 批量更新误差体系
|
||||
List<PqErrSys> errSysList = subPlanMetaDataVO.getErrSysList();
|
||||
@@ -2053,6 +2051,26 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 比对模式下计划的检测项获取
|
||||
* @param planId 计划ID
|
||||
* @return 检测项
|
||||
*/
|
||||
@Override
|
||||
public List<String> getScriptListContrast(String planId) {
|
||||
List<String> scriptList = new ArrayList<>();
|
||||
AdPlan adPlan = this.baseMapper.selectById(planId);
|
||||
String pattern = adPlan.getPattern();
|
||||
DictData dictData = dictDataService.getDictDataById(pattern);
|
||||
if (ObjectUtil.isNotNull(dictData)) {
|
||||
if(dictData.getCode().equalsIgnoreCase("Contrast")){
|
||||
String[] items = adPlan.getTestItem().split(",");
|
||||
scriptList = new ArrayList<>(Arrays.asList(items));
|
||||
}
|
||||
}
|
||||
return scriptList;
|
||||
}
|
||||
|
||||
// 构建分页查询SQL
|
||||
private String buildPaginatedQuery(String tableName, List<String> devMonitorIds, int limit, int offset) {
|
||||
StringBuilder sql = new StringBuilder("SELECT * FROM " + tableName);
|
||||
|
||||
@@ -35,5 +35,8 @@ public class DevReportParam implements Serializable {
|
||||
*/
|
||||
private String devId;
|
||||
|
||||
/**
|
||||
* 批量下载时传递的被检设备id列表
|
||||
*/
|
||||
private List<String> devIdList;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,11 @@ public interface PowerConstant {
|
||||
*/
|
||||
List<String> T_PHASE = Arrays.asList("VOLTAGE", "IMBV", "IMBA", "FREQ");
|
||||
|
||||
/**
|
||||
* T相指标存B相字段
|
||||
*/
|
||||
List<String> TB_PHASE = Arrays.asList("IMBV", "IMBA");
|
||||
|
||||
|
||||
/**
|
||||
* 有次数的指标
|
||||
@@ -39,6 +44,12 @@ public interface PowerConstant {
|
||||
*/
|
||||
List<Integer> DATA_RANGE = Arrays.asList(1, 2);
|
||||
|
||||
/**
|
||||
* abc相别
|
||||
*/
|
||||
List<String> PHASE_ABC = Arrays.asList("a", "b", "c");
|
||||
|
||||
|
||||
/**
|
||||
* 暂态符号
|
||||
*/
|
||||
|
||||
@@ -30,6 +30,12 @@ public enum BaseReportKeyEnum {
|
||||
MONTH("month","月份"),
|
||||
DAY("day","日"),
|
||||
YEAR_MONTH_DAY("year-month-day","年-月-日"),
|
||||
REPORT_DATE("reportDate","年-月-日"),
|
||||
SUB_NAME("subName","变电站"),
|
||||
CHECK_BY("checkBy","检测人"),
|
||||
AUDIT_BY("auditBy","负责人、审核人"),
|
||||
ERROR_SYS_NAME("errorSysName","误差体系"),
|
||||
CREATE_DATE("createDate","生产日期"),
|
||||
TEMPERATURE("temp","温度"),
|
||||
HUMIDITY("hum","相对湿度"),
|
||||
DELEGATE("delegate","委托方");
|
||||
|
||||
@@ -15,6 +15,9 @@ public enum ItemReportKeyEnum {
|
||||
NAME_DETAIL("nameDetail", "检测项详细,比如:频率测量准确度"),
|
||||
INFLUENCE("influence", "影响量的描述,比如额定工作条件、谐波对电压的影响等等"),
|
||||
ERROR_SCOPE("errorScope", "误差范围,注:在段落中时需加上(),表格中无需添加"),
|
||||
A_ERROR_SCOPE("a_errorScope", "A级误差,比如:±0.1%Un\n(±0.05774),需要换行,电压需要转为幅值"),
|
||||
NUM_OF_DATA("numOfData", "有效数据组数"),
|
||||
PHASE("phase", "相别"),
|
||||
ERROR_SCOPE_MAG("errorScopeMag", "特征幅值:误差范围"),
|
||||
ERROR_SCOPE_DUR("errorScopeDur", "持续时间:误差范围"),
|
||||
SCRIPT_DETAIL("scriptDetail", "脚本输出明细。比如:基波电压UN=57.74V,f=50Hz,谐波含有率Uh=10%UN=5.774V"),
|
||||
|
||||
@@ -14,6 +14,7 @@ public enum PowerIndexEnum {
|
||||
|
||||
UNKNOWN("UNKNOWN", "未知指标"),
|
||||
FREQ("FREQ", "频率"),
|
||||
LINE_TITLE("LINE_TITLE", "测量回路"),
|
||||
V("V", "电压"),
|
||||
I("I", "电流"),
|
||||
P("P", "功率"),
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.njcn.gather.report.pojo.result;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
* @version 1.0
|
||||
* @data 2025/9/18 13:22
|
||||
*/
|
||||
@Data
|
||||
public class ContrastTestResult implements Serializable {
|
||||
|
||||
/**
|
||||
* 指标CODE
|
||||
*/
|
||||
private String scriptCode;
|
||||
|
||||
/**
|
||||
* 指标名称
|
||||
*/
|
||||
private String scriptName;
|
||||
|
||||
/**
|
||||
* 是否谐波类
|
||||
*/
|
||||
private boolean isHarmonic;
|
||||
|
||||
/**
|
||||
* 是否合格
|
||||
*/
|
||||
private String result;
|
||||
|
||||
/**
|
||||
* 特殊情况的一些描述
|
||||
* 比如:存在无法比较时,比如谐波类存在标准和被检均为0的情况
|
||||
*/
|
||||
private String specialCase;
|
||||
|
||||
/**
|
||||
* 非谐波类检测结果
|
||||
* 相别 -- 占位符名称 -- 占位符值
|
||||
*/
|
||||
Map<String,Map<String,String>> checkResultNonHarmonic;
|
||||
|
||||
/**
|
||||
* 谐波类检测结果
|
||||
* 次数 -- 相别 -- 占位符名称 -- 占位符值
|
||||
*/
|
||||
List<Map<String,Map<String,Map<String,String>>>> checkResultHarmonic;
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -12,7 +12,7 @@ import javax.validation.constraints.NotNull;
|
||||
* @data 2025-09-10
|
||||
*/
|
||||
@Data
|
||||
public class MonitorResultVO {
|
||||
public class MonitorResultVO implements Comparable<MonitorResultVO> {
|
||||
|
||||
/**
|
||||
* 监测点id
|
||||
@@ -69,4 +69,21 @@ public class MonitorResultVO {
|
||||
@ApiModelProperty(value = "数据源类型", required = true)
|
||||
@NotBlank(message = DetectionValidMessage.DEV_MONITOR_RESULT_TYPE_NOT_BLANK)
|
||||
private String resultType;
|
||||
|
||||
/**
|
||||
* 根据线路号排序
|
||||
*/
|
||||
@Override
|
||||
public int compareTo(MonitorResultVO other) {
|
||||
if (this.monitorNum == null && other.monitorNum == null) {
|
||||
return 0;
|
||||
}
|
||||
if (this.monitorNum == null) {
|
||||
return 1;
|
||||
}
|
||||
if (other.monitorNum == null) {
|
||||
return -1;
|
||||
}
|
||||
return this.monitorNum.compareTo(other.monitorNum);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
package com.njcn.gather.result.service;
|
||||
|
||||
import com.njcn.gather.device.pojo.vo.PqDevVO;
|
||||
import com.njcn.gather.report.pojo.DevReportParam;
|
||||
import com.njcn.gather.report.pojo.result.ContrastTestResult;
|
||||
import com.njcn.gather.report.pojo.result.SingleTestResult;
|
||||
import com.njcn.gather.result.pojo.param.ResultParam;
|
||||
import com.njcn.gather.result.pojo.vo.*;
|
||||
import com.njcn.gather.script.pojo.vo.PqScriptDtlDataVO;
|
||||
import com.njcn.gather.system.dictionary.pojo.po.DictTree;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -88,13 +92,6 @@ public interface IResultService {
|
||||
*/
|
||||
SingleTestResult getFinalContent(List<PqScriptDtlDataVO> checkDataVOList, String planCode, String devId, Integer lineNo, List<String> tableKeys);
|
||||
|
||||
/**
|
||||
* 获取段落中指定的key对应的值
|
||||
*
|
||||
* @param itemCode 测试大项code
|
||||
* @param pKeys 待填充的值
|
||||
*/
|
||||
Map<String, String> getParagraphKeysValue(String itemCode, List<String> pKeys);
|
||||
|
||||
/**
|
||||
* 获取比对式表单头
|
||||
@@ -128,4 +125,14 @@ public interface IResultService {
|
||||
* @return
|
||||
*/
|
||||
List<ContrastTestItemVO> getCheckItem(String devId, String chnNum, Integer num);
|
||||
|
||||
/**
|
||||
* 获取设备比对式结果,用于出比对检测的报告
|
||||
* @param devReportParam 设备报告参数
|
||||
* @param pqDevVO 设备信息 省去一次sql查询
|
||||
* @return 该设备的比对式结果
|
||||
*/
|
||||
Map<Integer, List<ContrastTestResult>> getContrastResultForReport(DevReportParam devReportParam, PqDevVO pqDevVO);
|
||||
|
||||
ContrastTestResult getContrastResultHarm(MonitorResultVO monitorResultVO, List<String> scriptId, Integer planCode, DictTree dictTree);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.njcn.gather.result.service.impl;
|
||||
import cn.afterturn.easypoi.excel.entity.ExportParams;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import cn.hutool.core.text.StrPool;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
@@ -33,6 +34,7 @@ import com.njcn.gather.device.pojo.enums.CommonEnum;
|
||||
import com.njcn.gather.device.pojo.enums.PatternEnum;
|
||||
import com.njcn.gather.device.pojo.po.PqDev;
|
||||
import com.njcn.gather.device.pojo.po.PqStandardDev;
|
||||
import com.njcn.gather.device.pojo.vo.PqDevVO;
|
||||
import com.njcn.gather.device.service.IPqDevService;
|
||||
import com.njcn.gather.device.service.IPqStandardDevService;
|
||||
import com.njcn.gather.err.service.IPqErrSysService;
|
||||
@@ -44,10 +46,12 @@ import com.njcn.gather.plan.pojo.po.AdPlanTestConfig;
|
||||
import com.njcn.gather.plan.service.IAdPlanService;
|
||||
import com.njcn.gather.plan.service.IAdPlanTestConfigService;
|
||||
import com.njcn.gather.pojo.enums.DetectionResponseEnum;
|
||||
import com.njcn.gather.report.pojo.DevReportParam;
|
||||
import com.njcn.gather.report.pojo.constant.PowerConstant;
|
||||
import com.njcn.gather.report.pojo.enums.AffectEnum;
|
||||
import com.njcn.gather.report.pojo.enums.ItemReportKeyEnum;
|
||||
import com.njcn.gather.report.pojo.enums.PowerIndexEnum;
|
||||
import com.njcn.gather.report.pojo.result.ContrastTestResult;
|
||||
import com.njcn.gather.report.pojo.result.SingleTestResult;
|
||||
import com.njcn.gather.result.pojo.enums.ResultUnitEnum;
|
||||
import com.njcn.gather.result.pojo.param.ResultParam;
|
||||
@@ -1521,43 +1525,6 @@ public class ResultServiceImpl implements IResultService {
|
||||
return JSONUtil.toBean(filedValue, DetectionData.class);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取段落中指定的key对应的值,目前主要为测试大项名称服务,通过code匹配
|
||||
*
|
||||
* @param itemCode 测试大项code
|
||||
* @param pKeys 待填充的值
|
||||
*/
|
||||
@Override
|
||||
public Map<String, String> getParagraphKeysValue(String itemCode, List<String> pKeys) {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
if (CollUtil.isNotEmpty(pKeys)) {
|
||||
for (String pKey : pKeys) {
|
||||
ItemReportKeyEnum reportKeyEnum = ItemReportKeyEnum.getByKey(pKey);
|
||||
if (Objects.nonNull(reportKeyEnum)) {
|
||||
if (reportKeyEnum.getKey().equals(ItemReportKeyEnum.NAME.getKey())) {
|
||||
PowerIndexEnum indexEnum = PowerIndexEnum.getByKey(itemCode);
|
||||
if (Objects.nonNull(indexEnum)) {
|
||||
map.put(reportKeyEnum.getKey(), indexEnum.getDesc());
|
||||
} else {
|
||||
log.error("电能指标枚举未找到测试项");
|
||||
}
|
||||
} else if (reportKeyEnum.getKey().equals(ItemReportKeyEnum.NAME_DETAIL.getKey())) {
|
||||
PowerIndexEnum indexEnum = PowerIndexEnum.getByKey(itemCode);
|
||||
if (Objects.nonNull(indexEnum)) {
|
||||
map.put(reportKeyEnum.getKey(), indexEnum.getDesc().concat("测量准确度"));
|
||||
} else {
|
||||
log.error("电能指标枚举未找到测试项");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log.error("段落枚举未找到占用符");
|
||||
}
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FormContentVO getContrastFormContent(ResultParam.QueryParam queryParam) {
|
||||
FormContentVO formContentVO = new FormContentVO();
|
||||
@@ -1890,6 +1857,797 @@ public class ResultServiceImpl implements IResultService {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取对比结果
|
||||
*
|
||||
* @param devReportParam 设备报告参数
|
||||
* @param pqDevVO 设备信息 省去一次sql查询
|
||||
*/
|
||||
@Override
|
||||
public Map<Integer, List<ContrastTestResult>> getContrastResultForReport(DevReportParam devReportParam, PqDevVO pqDevVO) {
|
||||
Map<Integer/*回路号*/, List<ContrastTestResult>> finalContent = new LinkedHashMap<>();
|
||||
// 获取该设备下参与测试的回路(已有检测结论的)
|
||||
List<MonitorResultVO> monitorResultVOS = this.getMonitorResult(devReportParam.getDevId());
|
||||
if (CollectionUtil.isNotEmpty(monitorResultVOS)) {
|
||||
Collections.sort(monitorResultVOS);
|
||||
// 获取该计划下所有的检测指标,注:如果用户应用的是录波数据,频率这个指标不用出结果,因为当前的算法无法得出合理的结果
|
||||
List<String> scriptList = adPlanService.getScriptListContrast(devReportParam.getPlanId());
|
||||
// 对测试项按字典表排个序
|
||||
scriptList = dictTreeService.sort(scriptList);
|
||||
AdPlan adPlan = adPlanService.getById(devReportParam.getPlanId());
|
||||
if (CollectionUtil.isNotEmpty(scriptList)) {
|
||||
for (MonitorResultVO monitorResultVO : monitorResultVOS) {
|
||||
List<ContrastTestResult> contrastTestResults = new ArrayList<>();
|
||||
int monitorNum = monitorResultVO.getMonitorNum();
|
||||
// 看看当前这个回路结论的来源,可能是某次的实时数据、某次的测试下的某次录波数据、某次统计数据
|
||||
for (String scriptId : scriptList) {
|
||||
// 获取该指标的code,需要判断是否为谐波还是非谐波的指标
|
||||
DictTree dictTree = dictTreeService.getById(scriptId);
|
||||
// 本处的scriptId为父级,我需要获取自己
|
||||
List<String> subScriptIds = dictTreeService.getChildIds(scriptId);
|
||||
String scriptCode = dictTree.getCode();
|
||||
if (PowerConstant.TIME.contains(scriptCode)) {
|
||||
// 谐波类,谐波类稍微特殊一点,存在2~50次的数据,所以需要特殊处理
|
||||
ContrastTestResult contrastTestResult = getContrastResultHarm(monitorResultVO, subScriptIds, adPlan.getCode(), dictTree);
|
||||
if (Objects.nonNull(contrastTestResult)) {
|
||||
contrastTestResults.add(contrastTestResult);
|
||||
}
|
||||
} else {
|
||||
// 非谐波类,非谐波需要注意T相和三相
|
||||
ContrastTestResult contrastTestResult = getContrastResultNonHarm(monitorResultVO, subScriptIds, adPlan.getCode(), dictTree);
|
||||
if (Objects.nonNull(contrastTestResult)) {
|
||||
contrastTestResults.add(contrastTestResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
finalContent.put(monitorNum, contrastTestResults);
|
||||
}
|
||||
}
|
||||
return finalContent;
|
||||
}
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取谐波类数据的结果数据
|
||||
*
|
||||
* @param monitorResultVO 数据来源信息
|
||||
* @param subScriptIds 实际检测指标id
|
||||
* @param planCode 计划code,表名需要
|
||||
* @param dictTree 测试指标信息
|
||||
* @return 结果数据
|
||||
*/
|
||||
@Override
|
||||
public ContrastTestResult getContrastResultHarm(MonitorResultVO monitorResultVO, List<String> subScriptIds, Integer planCode, DictTree dictTree) {
|
||||
ContrastHarmonicResult result = contrastHarmonicService.getContrastResultHarm(planCode, monitorResultVO.getMonitorId(), subScriptIds, monitorResultVO.getResultType(), Integer.parseInt(monitorResultVO.getWhichTime()));
|
||||
// 收集组数数据
|
||||
int numOfData = contrastHarmonicService.getNumOfData(planCode, monitorResultVO.getMonitorId(), subScriptIds, monitorResultVO.getResultType(), Integer.parseInt(monitorResultVO.getWhichTime()));
|
||||
if (Objects.nonNull(result)) {
|
||||
// 谐波类的获取2~50次的数据
|
||||
ContrastTestResult contrastTestResult = new ContrastTestResult();
|
||||
contrastTestResult.setScriptCode(dictTree.getCode());
|
||||
contrastTestResult.setScriptName(dictTree.getName());
|
||||
contrastTestResult.setHarmonic(true);
|
||||
|
||||
// 判断是否为间谐波
|
||||
boolean isInterHarmonic = "HSV".equals(dictTree.getCode()) || "HSI".equals(dictTree.getCode());
|
||||
|
||||
// 根据指标代码确定小数位数
|
||||
Integer decimalPlaces = getDecimalPlacesByScriptCode(dictTree.getCode());
|
||||
|
||||
// 默认结果是符合的,后续解析过程中存在不符合的,则改为不符合
|
||||
// 构建谐波数据结果Map: 次数 -> 相别 -> List<Map<占位符名称, 占位符值>>
|
||||
List<Map<String, Map<String, Map<String, String>>>> harmonicResult = new ArrayList<>();
|
||||
List<String> allResult = new ArrayList<>();
|
||||
|
||||
// 收集特殊情况信息
|
||||
Map<Integer, List<String>> zeroFilteredMap = new LinkedHashMap<>(); // 双零过滤的次数和相别
|
||||
Map<Integer, Map<String, List<String>>> unComparableMap = new LinkedHashMap<>(); // 无法比较的次数和相别(按组数分组)
|
||||
Map<Integer, Map<String, List<String>>> unqualifiedMap = new LinkedHashMap<>(); // 不符合的次数和相别(按组数分组)
|
||||
int totalDataPoints = 0; // 统计总的数据点数
|
||||
int zeroFilteredPoints = 0; // 统计双零过滤的数据点数
|
||||
|
||||
// 遍历 2~50 次谐波
|
||||
for (int harmNum = 2; harmNum <= 50; harmNum++) {
|
||||
String harmKey = String.valueOf(harmNum);
|
||||
Map<String, Map<String, Map<String, String>>> checkResultHarmonic = new LinkedHashMap<>();
|
||||
List<String> zeroFilteredPhases = new ArrayList<>(); // 当前次数被过滤的相别
|
||||
|
||||
try {
|
||||
Map<String, Map<String, String>> phaseData = new LinkedHashMap<>();
|
||||
boolean hasNonZeroData = false; // 标记是否有非双零数据
|
||||
|
||||
for (String phase : PowerConstant.PHASE_ABC) {
|
||||
Field field = result.getClass().getDeclaredField(phase + "Value" + harmKey);
|
||||
field.setAccessible(true);
|
||||
String valueJson = (String) field.get(result);
|
||||
Map<String, String> singlePhaseData = parseHarmonicPhaseData(valueJson, phase.toUpperCase() + "相", harmNum, numOfData, dictTree.getCode(), decimalPlaces);
|
||||
|
||||
if (CollUtil.isNotEmpty(singlePhaseData)) {
|
||||
totalDataPoints++; // 统计总数据点
|
||||
|
||||
// 检查是否为双零情况
|
||||
String standardVal = singlePhaseData.get(ItemReportKeyEnum.STANDARD.getKey());
|
||||
String testVal = singlePhaseData.get(ItemReportKeyEnum.TEST.getKey());
|
||||
|
||||
// 判断是否为双零(标准值和被检值都为0或"0.0"或"0")
|
||||
boolean isZeroFiltered = isZeroValue(standardVal) && isZeroValue(testVal);
|
||||
|
||||
if (isZeroFiltered) {
|
||||
zeroFilteredPoints++; // 统计双零点
|
||||
// 双零情况,记录但不加入结果判定
|
||||
zeroFilteredPhases.add(phase.toUpperCase() + "相");
|
||||
// 将结果改为特殊标记,不参与整体结论判定
|
||||
singlePhaseData.put(ItemReportKeyEnum.RESULT.getKey(), "双零过滤");
|
||||
} else {
|
||||
// 有非双零数据
|
||||
hasNonZeroData = true;
|
||||
// 非双零情况,正常处理结果
|
||||
String resultTemp = singlePhaseData.get(ItemReportKeyEnum.RESULT.getKey());
|
||||
if (StrUtil.isNotBlank(resultTemp)) {
|
||||
allResult.add(resultTemp);
|
||||
|
||||
// 收集特殊情况
|
||||
if ("无法比较".equals(resultTemp)) {
|
||||
String numOfDataStr = singlePhaseData.get(ItemReportKeyEnum.NUM_OF_DATA.getKey());
|
||||
unComparableMap.computeIfAbsent(harmNum, k -> new LinkedHashMap<>())
|
||||
.computeIfAbsent(numOfDataStr, k -> new ArrayList<>())
|
||||
.add(phase.toUpperCase() + "相");
|
||||
} else if ("不符合".equals(resultTemp)) {
|
||||
String numOfDataStr = singlePhaseData.get(ItemReportKeyEnum.NUM_OF_DATA.getKey());
|
||||
unqualifiedMap.computeIfAbsent(harmNum, k -> new LinkedHashMap<>())
|
||||
.computeIfAbsent(numOfDataStr, k -> new ArrayList<>())
|
||||
.add(phase.toUpperCase() + "相");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
phaseData.put(phase.toUpperCase() + "相", singlePhaseData);
|
||||
}
|
||||
}
|
||||
|
||||
// 记录当前次数的双零过滤情况
|
||||
if (!zeroFilteredPhases.isEmpty()) {
|
||||
zeroFilteredMap.put(harmNum, zeroFilteredPhases);
|
||||
}
|
||||
|
||||
// 只有当该次谐波有非双零数据时,才添加到结果集中
|
||||
if (hasNonZeroData) {
|
||||
checkResultHarmonic.put(harmKey, phaseData);
|
||||
// 如果该次谐波有数据,添加到结果Map中
|
||||
if (CollUtil.isNotEmpty(checkResultHarmonic)) {
|
||||
harmonicResult.add(checkResultHarmonic);
|
||||
}
|
||||
}
|
||||
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||
log.warn("获取第{}次谐波数据失败: {}", harmNum, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// 判断是否所有数据都是双零
|
||||
boolean allDataIsZero = (totalDataPoints > 0 && totalDataPoints == zeroFilteredPoints);
|
||||
|
||||
// 生成specialCase描述
|
||||
String specialCase = generateHarmonicSpecialCase(zeroFilteredMap, unComparableMap, unqualifiedMap,
|
||||
totalDataPoints, zeroFilteredPoints, isInterHarmonic);
|
||||
|
||||
// 设置检测结果
|
||||
String overallResult;
|
||||
if (allDataIsZero) {
|
||||
// 如果所有数据都是双零,结果为符合
|
||||
overallResult = "符合";
|
||||
} else {
|
||||
// 根据所有相数据的结果判断总体结论
|
||||
overallResult = determineOverallResult(allResult);
|
||||
}
|
||||
|
||||
contrastTestResult.setResult(overallResult);
|
||||
contrastTestResult.setSpecialCase(specialCase);
|
||||
contrastTestResult.setCheckResultHarmonic(harmonicResult);
|
||||
|
||||
return contrastTestResult;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断值是否为零
|
||||
* @param value 字符串值
|
||||
* @return 是否为零
|
||||
*/
|
||||
private boolean isZeroValue(String value) {
|
||||
if (StrUtil.isBlank(value) || "/".equals(value) || "null".equals(value)) {
|
||||
return false; // 空值或无效值不算零
|
||||
}
|
||||
try {
|
||||
double d = Double.parseDouble(value);
|
||||
return d == 0.0;
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成谐波类特殊情况描述
|
||||
* @param zeroFilteredMap 双零过滤的次数和相别
|
||||
* @param unComparableMap 无法比较的次数和相别
|
||||
* @param unqualifiedMap 不符合的次数和相别
|
||||
* @param totalDataPoints 总数据点数
|
||||
* @param zeroFilteredPoints 双零过滤的数据点数
|
||||
* @param isInterHarmonic 是否为间谐波
|
||||
* @return 特殊情况描述
|
||||
*/
|
||||
private String generateHarmonicSpecialCase(Map<Integer, List<String>> zeroFilteredMap,
|
||||
Map<Integer, Map<String, List<String>>> unComparableMap,
|
||||
Map<Integer, Map<String, List<String>>> unqualifiedMap,
|
||||
int totalDataPoints, int zeroFilteredPoints,
|
||||
boolean isInterHarmonic) {
|
||||
StringBuilder specialCaseDesc = new StringBuilder();
|
||||
boolean hasZeroFiltered = false;
|
||||
boolean allZero = false;
|
||||
|
||||
// 1. 检查双零过滤情况
|
||||
if (!zeroFilteredMap.isEmpty()) {
|
||||
hasZeroFiltered = true;
|
||||
// 判断是否所有数据都是双零
|
||||
allZero = (totalDataPoints > 0 && totalDataPoints == zeroFilteredPoints);
|
||||
|
||||
if (allZero) {
|
||||
// 所有次数的所有相别都是双零,直接返回
|
||||
specialCaseDesc.append("注:因所有谐波次数的标准值与被检值均为0,检测结论为符合。");
|
||||
return specialCaseDesc.toString();
|
||||
}
|
||||
}
|
||||
|
||||
// 2. 处理无法比较情况
|
||||
if (!unComparableMap.isEmpty()) {
|
||||
if (specialCaseDesc.length() > 0) {
|
||||
specialCaseDesc.append(" ");
|
||||
} else {
|
||||
specialCaseDesc.append("注:");
|
||||
}
|
||||
|
||||
// 合并相同情况的次数和相别
|
||||
Map<String, Map<String, List<Integer>>> groupedUnComparable = new LinkedHashMap<>();
|
||||
for (Map.Entry<Integer, Map<String, List<String>>> harmEntry : unComparableMap.entrySet()) {
|
||||
Integer harmNum = harmEntry.getKey();
|
||||
for (Map.Entry<String, List<String>> dataEntry : harmEntry.getValue().entrySet()) {
|
||||
String numOfData = dataEntry.getKey();
|
||||
List<String> phases = dataEntry.getValue();
|
||||
String phaseKey = String.join("、", phases);
|
||||
groupedUnComparable.computeIfAbsent(numOfData, k -> new LinkedHashMap<>())
|
||||
.computeIfAbsent(phaseKey, k -> new ArrayList<>())
|
||||
.add(harmNum);
|
||||
}
|
||||
}
|
||||
|
||||
// 生成描述
|
||||
for (Map.Entry<String, Map<String, List<Integer>>> dataEntry : groupedUnComparable.entrySet()) {
|
||||
for (Map.Entry<String, List<Integer>> phaseEntry : dataEntry.getValue().entrySet()) {
|
||||
String phases = phaseEntry.getKey();
|
||||
List<Integer> harmNums = phaseEntry.getValue();
|
||||
specialCaseDesc.append("第").append(formatHarmNumbers(harmNums, isInterHarmonic)).append("次谐波");
|
||||
specialCaseDesc.append(phases).append("无样本数据满足误差比较的前置条件,无法执行有效性判定。");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 处理不符合情况
|
||||
if (!unqualifiedMap.isEmpty()) {
|
||||
if (specialCaseDesc.length() > 0) {
|
||||
specialCaseDesc.append(" ");
|
||||
} else {
|
||||
specialCaseDesc.append("注:");
|
||||
}
|
||||
|
||||
// 重新组织数据结构:收集所有相同组数的次数-相别组合
|
||||
Map<String, List<String>> groupedByNumOfData = new LinkedHashMap<>();
|
||||
|
||||
for (Map.Entry<Integer, Map<String, List<String>>> harmEntry : unqualifiedMap.entrySet()) {
|
||||
Integer harmNum = harmEntry.getKey();
|
||||
for (Map.Entry<String, List<String>> dataEntry : harmEntry.getValue().entrySet()) {
|
||||
String numOfData = dataEntry.getKey();
|
||||
List<String> phases = dataEntry.getValue();
|
||||
|
||||
// 如果一个次数下有多个相别,合并成一个描述
|
||||
String harmPhaseDesc;
|
||||
String displayHarmNum = getDisplayHarmNumber(harmNum, isInterHarmonic);
|
||||
if (phases.size() == 1) {
|
||||
harmPhaseDesc = "第" + displayHarmNum + "次谐波" + phases.get(0);
|
||||
} else {
|
||||
harmPhaseDesc = "第" + displayHarmNum + "次谐波" + String.join("、", phases);
|
||||
}
|
||||
groupedByNumOfData.computeIfAbsent(numOfData, k -> new ArrayList<>())
|
||||
.add(harmPhaseDesc);
|
||||
}
|
||||
}
|
||||
|
||||
// 生成描述
|
||||
for (Map.Entry<String, List<String>> entry : groupedByNumOfData.entrySet()) {
|
||||
String numOfData = entry.getKey();
|
||||
List<String> harmPhaseList = entry.getValue();
|
||||
|
||||
// 合并描述:第4次谐波A相、B相、C相、第32次谐波A相、第44次谐波C相
|
||||
specialCaseDesc.append(String.join("、", harmPhaseList));
|
||||
specialCaseDesc.append("收集有效组数为").append(numOfData)
|
||||
.append("组,误差计算结果不符合误差标准要求。");
|
||||
}
|
||||
}
|
||||
|
||||
// 4. 最后添加双零过滤的笼统描述(如果有部分双零)
|
||||
if (hasZeroFiltered && !allZero) {
|
||||
if (specialCaseDesc.length() > 0) {
|
||||
specialCaseDesc.append(" ");
|
||||
} else {
|
||||
specialCaseDesc.append("注:");
|
||||
}
|
||||
specialCaseDesc.append("表格不展示标准值与被检值均为0的数据。");
|
||||
}
|
||||
|
||||
return specialCaseDesc.length() > 0 ? specialCaseDesc.toString() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取显示用的谐波次数
|
||||
* @param harmNum 原始次数(2-50)
|
||||
* @param isInterHarmonic 是否为间谐波
|
||||
* @return 显示用的次数字符串
|
||||
*/
|
||||
private String getDisplayHarmNumber(int harmNum, boolean isInterHarmonic) {
|
||||
if (isInterHarmonic) {
|
||||
// 间谐波:2->1.5, 3->2.5, 4->3.5 ... 50->49.5
|
||||
double displayNum = harmNum - 0.5;
|
||||
// 如果是整数则显示整数,否则显示小数
|
||||
if (displayNum == (int) displayNum) {
|
||||
return String.valueOf((int) displayNum);
|
||||
}
|
||||
return String.valueOf(displayNum);
|
||||
}
|
||||
return String.valueOf(harmNum);
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化谐波次数列表
|
||||
* @param harmNumbers 谐波次数列表
|
||||
* @param isInterHarmonic 是否为间谐波
|
||||
* @return 格式化的字符串,如"2、3、5"或"2-5、7、9-11"(间谐波为"1.5、2.5、3.5")
|
||||
*/
|
||||
private String formatHarmNumbers(List<Integer> harmNumbers, boolean isInterHarmonic) {
|
||||
if (harmNumbers.isEmpty()) {
|
||||
return "";
|
||||
}
|
||||
if (harmNumbers.size() == 1) {
|
||||
return getDisplayHarmNumber(harmNumbers.get(0), isInterHarmonic);
|
||||
}
|
||||
|
||||
Collections.sort(harmNumbers);
|
||||
|
||||
if (isInterHarmonic) {
|
||||
// 间谐波不使用范围表示,直接用顿号分隔
|
||||
List<String> displayNumbers = new ArrayList<>();
|
||||
for (Integer harmNum : harmNumbers) {
|
||||
displayNumbers.add(getDisplayHarmNumber(harmNum, true));
|
||||
}
|
||||
return String.join("、", displayNumbers);
|
||||
} else {
|
||||
// 普通谐波使用范围表示
|
||||
List<String> parts = new ArrayList<>();
|
||||
int start = harmNumbers.get(0);
|
||||
int end = start;
|
||||
|
||||
for (int i = 1; i < harmNumbers.size(); i++) {
|
||||
int current = harmNumbers.get(i);
|
||||
if (current == end + 1) {
|
||||
end = current;
|
||||
} else {
|
||||
if (start == end) {
|
||||
parts.add(String.valueOf(start));
|
||||
} else if (end - start == 1) {
|
||||
parts.add(start + "、" + end);
|
||||
} else {
|
||||
parts.add(start + "-" + end);
|
||||
}
|
||||
start = current;
|
||||
end = current;
|
||||
}
|
||||
}
|
||||
|
||||
// 处理最后一组
|
||||
if (start == end) {
|
||||
parts.add(String.valueOf(start));
|
||||
} else if (end - start == 1) {
|
||||
parts.add(start + "、" + end);
|
||||
} else {
|
||||
parts.add(start + "-" + end);
|
||||
}
|
||||
|
||||
return String.join("、", parts);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取非谐波类数据的结果数据
|
||||
*
|
||||
* @param monitorResultVO 数据来源信息
|
||||
* @param subScriptId 实际检测指标id
|
||||
* @param planCode 计划code,表名需要
|
||||
* @param dictTree 测试指标信息
|
||||
* @return 结果数据
|
||||
*/
|
||||
private ContrastTestResult getContrastResultNonHarm(MonitorResultVO monitorResultVO, List<String> subScriptId, Integer planCode, DictTree dictTree) {
|
||||
ContrastNonHarmonicResult result = contrastNonHarmonicService.getContrastResultHarm(planCode, monitorResultVO.getMonitorId(), subScriptId, monitorResultVO.getResultType(), Integer.parseInt(monitorResultVO.getWhichTime()));
|
||||
// 收集组数数据
|
||||
int numOfData = contrastNonHarmonicService.getNumOfData(planCode, monitorResultVO.getMonitorId(), subScriptId, monitorResultVO.getResultType(), Integer.parseInt(monitorResultVO.getWhichTime()));
|
||||
if (Objects.nonNull(result)) {
|
||||
// 非谐波类
|
||||
ContrastTestResult contrastTestResult = new ContrastTestResult();
|
||||
contrastTestResult.setScriptCode(dictTree.getCode());
|
||||
contrastTestResult.setScriptName(dictTree.getName());
|
||||
contrastTestResult.setHarmonic(false);
|
||||
List<String> allResult = new ArrayList<>();
|
||||
Map<String, Map<String, String>> checkResultNonHarmonic = new LinkedHashMap<>();
|
||||
|
||||
// 根据指标代码确定小数位数
|
||||
Integer decimalPlaces = getDecimalPlacesByScriptCode(dictTree.getCode());
|
||||
|
||||
try {
|
||||
// 非谐波的需要注意是否为T相还是ABC三相的
|
||||
if (PowerConstant.T_PHASE.contains(dictTree.getCode())) {
|
||||
Field field;
|
||||
if (PowerConstant.TB_PHASE.contains(dictTree.getCode())) {
|
||||
field = result.getClass().getDeclaredField("bValue");
|
||||
} else {
|
||||
field = result.getClass().getDeclaredField("tValue");
|
||||
}
|
||||
field.setAccessible(true);
|
||||
String valueJson = (String) field.get(result);
|
||||
Map<String, String> singlePhaseData = parseNonHarmonicPhaseData(valueJson, "T相", numOfData, dictTree.getCode(), decimalPlaces);
|
||||
checkResultNonHarmonic.put("T相", singlePhaseData);
|
||||
if (CollUtil.isNotEmpty(singlePhaseData)) {
|
||||
String resultTemp = singlePhaseData.get(ItemReportKeyEnum.RESULT.getKey());
|
||||
if (StrUtil.isNotBlank(resultTemp)) {
|
||||
allResult.add(resultTemp);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// ABC三相
|
||||
for (String phase : PowerConstant.PHASE_ABC) {
|
||||
Field field = result.getClass().getDeclaredField(phase + "Value");
|
||||
field.setAccessible(true);
|
||||
String valueJson = (String) field.get(result);
|
||||
Map<String, String> singlePhaseData = parseNonHarmonicPhaseData(valueJson, phase.toUpperCase() + "相", numOfData, dictTree.getCode(), decimalPlaces);
|
||||
checkResultNonHarmonic.put(phase.toUpperCase() + "相", singlePhaseData);
|
||||
if (CollUtil.isNotEmpty(singlePhaseData)) {
|
||||
String resultTemp = singlePhaseData.get(ItemReportKeyEnum.RESULT.getKey());
|
||||
if (StrUtil.isNotBlank(resultTemp)) {
|
||||
allResult.add(resultTemp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 生成 specialCase 描述
|
||||
StringBuilder specialCaseDesc = new StringBuilder();
|
||||
List<String> unComparablePhases = new ArrayList<>();
|
||||
Map<String, List<String>> unqualifiedPhasesMap = new LinkedHashMap<>(); // 按组数分组
|
||||
|
||||
// 遍历每个相别的结果,收集特殊情况信息
|
||||
for (Map.Entry<String, Map<String, String>> entry : checkResultNonHarmonic.entrySet()) {
|
||||
String phase = entry.getKey();
|
||||
Map<String, String> phaseData = entry.getValue();
|
||||
String phaseResult = phaseData.get(ItemReportKeyEnum.RESULT.getKey());
|
||||
|
||||
if ("无法比较".equals(phaseResult)) {
|
||||
unComparablePhases.add(phase);
|
||||
} else if ("不符合".equals(phaseResult)) {
|
||||
String numOfDataStr = phaseData.get(ItemReportKeyEnum.NUM_OF_DATA.getKey());
|
||||
// 按组数分组存储相别
|
||||
unqualifiedPhasesMap.computeIfAbsent(numOfDataStr, k -> new ArrayList<>()).add(phase);
|
||||
}
|
||||
}
|
||||
|
||||
// 生成无法比较的描述
|
||||
if (!unComparablePhases.isEmpty()) {
|
||||
specialCaseDesc.append("注:");
|
||||
if (unComparablePhases.size() == 1) {
|
||||
specialCaseDesc.append(unComparablePhases.get(0));
|
||||
} else {
|
||||
specialCaseDesc.append(String.join("、", unComparablePhases));
|
||||
}
|
||||
specialCaseDesc.append("无样本数据满足误差比较的前置条件,无法执行有效性判定。");
|
||||
}
|
||||
|
||||
// 生成不符合的描述(合并相同组数的相别)
|
||||
if (!unqualifiedPhasesMap.isEmpty()) {
|
||||
if (specialCaseDesc.length() > 0) {
|
||||
specialCaseDesc.append(" ");
|
||||
} else {
|
||||
specialCaseDesc.append("注:");
|
||||
}
|
||||
for (Map.Entry<String, List<String>> entry : unqualifiedPhasesMap.entrySet()) {
|
||||
String numOfDataStr = entry.getKey();
|
||||
List<String> phases = entry.getValue();
|
||||
if (phases.size() == 1) {
|
||||
specialCaseDesc.append(phases.get(0));
|
||||
} else {
|
||||
specialCaseDesc.append(String.join("、", phases));
|
||||
}
|
||||
specialCaseDesc.append("收集有效组数为").append(numOfDataStr).append("组,误差计算结果不符合误差标准要求。");
|
||||
if (unqualifiedPhasesMap.size() > 1) {
|
||||
specialCaseDesc.append(" ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 设置检测结果 - 根据所有相数据的结果判断总体结论
|
||||
String overallResult = determineOverallResult(allResult);
|
||||
contrastTestResult.setResult(overallResult);
|
||||
contrastTestResult.setSpecialCase(specialCaseDesc.length() > 0 ? specialCaseDesc.toString() : null);
|
||||
contrastTestResult.setCheckResultNonHarmonic(checkResultNonHarmonic);
|
||||
return contrastTestResult;
|
||||
} catch (Exception e) {
|
||||
log.warn("获取{}数据失败", dictTree.getName());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析非谐波数据
|
||||
*
|
||||
* @param valueJson JSON格式的数据
|
||||
* @param phase 相别标识
|
||||
* @param numOfData 收集组数
|
||||
* @param scriptCode 脚本代码,用于判断是否需要特殊格式化
|
||||
* @param decimalPlaces 小数位数,null则不格式化
|
||||
* @return 解析后的数据列表
|
||||
*/
|
||||
private Map<String, String> parseNonHarmonicPhaseData(String valueJson, String phase, int numOfData, String scriptCode, Integer decimalPlaces) {
|
||||
try {
|
||||
// 解析JSON数据,假设是 DetectionData 对象列表
|
||||
List<DetectionData> dataList = JSON.parseArray(valueJson, DetectionData.class);
|
||||
Map<String, String> dataMap = new LinkedHashMap<>();
|
||||
if (CollUtil.isNotEmpty(dataList)) {
|
||||
DetectionData detectionData = dataList.get(0);
|
||||
|
||||
// 相别
|
||||
dataMap.put(ItemReportKeyEnum.PHASE.getKey(), phase);
|
||||
// 有效组数 todo... 目前是对齐组数
|
||||
dataMap.put(ItemReportKeyEnum.NUM_OF_DATA.getKey(), String.valueOf(numOfData));
|
||||
|
||||
// 标准值 - 根据参数决定是否格式化
|
||||
String standardValue = String.valueOf(detectionData.getResultData());
|
||||
if (decimalPlaces != null && detectionData.getResultData() != null) {
|
||||
standardValue = formatSignificantDigits(detectionData.getResultData(), decimalPlaces);
|
||||
}
|
||||
dataMap.put(ItemReportKeyEnum.STANDARD.getKey(), standardValue);
|
||||
|
||||
// 被检值 - 根据参数决定是否格式化
|
||||
String testValue = String.valueOf(detectionData.getData());
|
||||
if (decimalPlaces != null && detectionData.getData() != null) {
|
||||
testValue = formatSignificantDigits(detectionData.getData(), decimalPlaces);
|
||||
}
|
||||
dataMap.put(ItemReportKeyEnum.TEST.getKey(), testValue);
|
||||
|
||||
// 误差 - 根据参数决定是否格式化
|
||||
String errorValue = String.valueOf(detectionData.getErrorData());
|
||||
if (decimalPlaces != null && detectionData.getErrorData() != null) {
|
||||
errorValue = formatSignificantDigits(detectionData.getErrorData().doubleValue(), decimalPlaces);
|
||||
}
|
||||
dataMap.put(ItemReportKeyEnum.ERROR.getKey(), errorValue);
|
||||
|
||||
// 误差范围 - 根据参数决定是否格式化
|
||||
String errorScope = String.valueOf(detectionData.getRadius());
|
||||
if (decimalPlaces != null && detectionData.getRadius() != null) {
|
||||
errorScope = formatErrorRange(detectionData.getRadius(), decimalPlaces);
|
||||
}
|
||||
dataMap.put(ItemReportKeyEnum.A_ERROR_SCOPE.getKey(), errorScope);
|
||||
|
||||
// 结论
|
||||
dataMap.put(ItemReportKeyEnum.RESULT.getKey(), getTestResult(detectionData.getIsData()));
|
||||
} else {
|
||||
// 相别
|
||||
dataMap.put(ItemReportKeyEnum.PHASE.getKey(), phase);
|
||||
// 有效组数
|
||||
dataMap.put(ItemReportKeyEnum.NUM_OF_DATA.getKey(), String.valueOf(0));
|
||||
// 标准值
|
||||
dataMap.put(ItemReportKeyEnum.STANDARD.getKey(), "/");
|
||||
// 被检值
|
||||
dataMap.put(ItemReportKeyEnum.TEST.getKey(), "/");
|
||||
// 误差
|
||||
dataMap.put(ItemReportKeyEnum.ERROR.getKey(), "/");
|
||||
// 误差范围
|
||||
dataMap.put(ItemReportKeyEnum.A_ERROR_SCOPE.getKey(), "/");
|
||||
// 结论
|
||||
dataMap.put(ItemReportKeyEnum.RESULT.getKey(), "无法比较");
|
||||
}
|
||||
return dataMap;
|
||||
} catch (Exception e) {
|
||||
log.warn("获取数据失败");
|
||||
|
||||
}
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据所有相数据的检测结果判断总体指标结论
|
||||
* 判断原则:所有都符合就符合,有一个不符合就不符合,如果所有都是无法比较就无法比较
|
||||
*
|
||||
* @param allResult 所有相数据的检测结果集合
|
||||
* @return 总体指标结论
|
||||
*/
|
||||
private String determineOverallResult(List<String> allResult) {
|
||||
if (CollUtil.isEmpty(allResult)) {
|
||||
return "无法比较";
|
||||
}
|
||||
|
||||
// 统计各种结果的数量
|
||||
// 是否有不符合
|
||||
boolean hasUnqualified = false;
|
||||
// 是否有符合
|
||||
boolean hasQualified = false;
|
||||
// 是否有无法比较
|
||||
boolean hasUncomparable = false;
|
||||
|
||||
for (String result : allResult) {
|
||||
if ("不符合".equals(result)) {
|
||||
hasUnqualified = true;
|
||||
} else if ("符合".equals(result)) {
|
||||
hasQualified = true;
|
||||
} else if ("无法比较".equals(result)) {
|
||||
hasUncomparable = true;
|
||||
}
|
||||
}
|
||||
|
||||
// 按照优先级判断:有一个不符合就不符合
|
||||
if (hasUnqualified) {
|
||||
return "不符合";
|
||||
}
|
||||
|
||||
// 如果没有不符合,且有符合的,就是符合
|
||||
if (hasQualified) {
|
||||
return "符合";
|
||||
}
|
||||
|
||||
// 如果全部都是无法比较
|
||||
if (hasUncomparable) {
|
||||
return "无法比较";
|
||||
}
|
||||
|
||||
// 默认返回无法比较(理论上不会到这里)
|
||||
return "无法比较";
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析谐波相数据
|
||||
*
|
||||
* @param jsonData JSON格式的数据
|
||||
* @param phase 相别标识
|
||||
* @param harmNum 谐波次数
|
||||
* @param numOfData 收集组数
|
||||
* @param scriptCode 脚本代码,用于判断是否需要特殊格式化
|
||||
* @param decimalPlaces 小数位数,null则不格式化
|
||||
* @return 解析后的数据列表
|
||||
*/
|
||||
private Map<String, String> parseHarmonicPhaseData(String jsonData, String phase, int harmNum, int numOfData, String scriptCode, Integer decimalPlaces) {
|
||||
try {
|
||||
// 解析JSON数据,假设是 DetectionData 对象列表
|
||||
List<DetectionData> dataList = JSON.parseArray(jsonData, DetectionData.class);
|
||||
Map<String, String> dataMap = new LinkedHashMap<>();
|
||||
if (CollUtil.isNotEmpty(dataList)) {
|
||||
DetectionData detectionData = dataList.get(0);
|
||||
// 次数
|
||||
dataMap.put(ItemReportKeyEnum.TIME.getKey(), String.valueOf(harmNum));
|
||||
// 相别
|
||||
dataMap.put(ItemReportKeyEnum.PHASE.getKey(), phase);
|
||||
// 有效组数 todo... 目前是对齐组数
|
||||
dataMap.put(ItemReportKeyEnum.NUM_OF_DATA.getKey(), String.valueOf(numOfData));
|
||||
|
||||
// 标准值 - 根据参数决定是否格式化
|
||||
String standardValue = String.valueOf(detectionData.getResultData());
|
||||
if (decimalPlaces != null && detectionData.getResultData() != null) {
|
||||
standardValue = formatSignificantDigits(detectionData.getResultData(), decimalPlaces);
|
||||
}
|
||||
dataMap.put(ItemReportKeyEnum.STANDARD.getKey(), standardValue);
|
||||
|
||||
// 被检值 - 根据参数决定是否格式化
|
||||
String testValue = String.valueOf(detectionData.getData());
|
||||
if (decimalPlaces != null && detectionData.getData() != null) {
|
||||
testValue = formatSignificantDigits(detectionData.getData(), decimalPlaces);
|
||||
}
|
||||
dataMap.put(ItemReportKeyEnum.TEST.getKey(), testValue);
|
||||
|
||||
// 误差 - 根据参数决定是否格式化
|
||||
String errorValue = String.valueOf(detectionData.getErrorData());
|
||||
if (decimalPlaces != null && detectionData.getErrorData() != null) {
|
||||
errorValue = formatSignificantDigits(detectionData.getErrorData().doubleValue(), decimalPlaces);
|
||||
}
|
||||
dataMap.put(ItemReportKeyEnum.ERROR.getKey(), errorValue);
|
||||
|
||||
// 误差范围 - 根据参数决定是否格式化
|
||||
String errorScope = String.valueOf(detectionData.getRadius());
|
||||
if (decimalPlaces != null && detectionData.getRadius() != null) {
|
||||
errorScope = formatErrorRange(detectionData.getRadius(), decimalPlaces);
|
||||
}
|
||||
dataMap.put(ItemReportKeyEnum.A_ERROR_SCOPE.getKey(), errorScope);
|
||||
|
||||
// 结论
|
||||
dataMap.put(ItemReportKeyEnum.RESULT.getKey(), getTestResult(detectionData.getIsData()));
|
||||
} else {
|
||||
// 次数
|
||||
dataMap.put(ItemReportKeyEnum.TIME.getKey(), String.valueOf(harmNum));
|
||||
// 相别
|
||||
dataMap.put(ItemReportKeyEnum.PHASE.getKey(), phase);
|
||||
// 有效组数
|
||||
dataMap.put(ItemReportKeyEnum.NUM_OF_DATA.getKey(), "0");
|
||||
// 标准值
|
||||
dataMap.put(ItemReportKeyEnum.STANDARD.getKey(), "/");
|
||||
// 被检值
|
||||
dataMap.put(ItemReportKeyEnum.TEST.getKey(), "/");
|
||||
// 误差
|
||||
dataMap.put(ItemReportKeyEnum.ERROR.getKey(), "/");
|
||||
// 误差范围
|
||||
dataMap.put(ItemReportKeyEnum.A_ERROR_SCOPE.getKey(), "/");
|
||||
// 结论
|
||||
dataMap.put(ItemReportKeyEnum.RESULT.getKey(), "无法比较");
|
||||
}
|
||||
return dataMap;
|
||||
} catch (Exception e) {
|
||||
log.error("解析{}第{}次谐波数据失败: {}", phase, harmNum, e.getMessage());
|
||||
}
|
||||
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否有不合格的数据
|
||||
*
|
||||
* @param dataList 数据列表
|
||||
* @return true表示有不合格数据
|
||||
*/
|
||||
private boolean hasUnqualifiedData(List<Map<String, String>> dataList) {
|
||||
if (CollUtil.isEmpty(dataList)) {
|
||||
return false;
|
||||
}
|
||||
for (Map<String, String> data : dataList) {
|
||||
String resultFlag = data.get("resultFlag");
|
||||
// resultFlag: 1-合格,2-不合格,4-无法比较
|
||||
if ("2".equals(resultFlag)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取检测结果
|
||||
*
|
||||
* @param monitorResultVO 回路检测结论信息
|
||||
*/
|
||||
private String getTestResult(MonitorResultVO monitorResultVO) {
|
||||
Integer checkResult = monitorResultVO.getCheckResult();
|
||||
return getTestResult(checkResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取检测结果
|
||||
*
|
||||
* @param checkResult 回路检测结论信息
|
||||
*/
|
||||
private String getTestResult(Integer checkResult) {
|
||||
switch (checkResult) {
|
||||
case 2:
|
||||
return "不符合";
|
||||
case 4:
|
||||
return "无法比较";
|
||||
default:
|
||||
// 因为只有 1、2、4,所以这里直接返回符合
|
||||
return "符合";
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, List<RawResultDataVO>> getResultMap(DictTree dictTree, List<String> adTypeList, String monitorId, String unit, Integer num, Integer waveNum, Boolean isWave, String code) {
|
||||
Map<String, List<RawResultDataVO>> resultMap = new LinkedHashMap<>();
|
||||
|
||||
@@ -2558,4 +3316,129 @@ public class ResultServiceImpl implements IResultService {
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化数值,保留指定的小数位数
|
||||
*
|
||||
* @param value 原始数值
|
||||
* @param decimalPlaces 小数位数
|
||||
* @return 格式化后的字符串
|
||||
*/
|
||||
private String formatSignificantDigits(double value, int decimalPlaces) {
|
||||
if (value == 0.0) {
|
||||
return "0";
|
||||
}
|
||||
|
||||
// 使用BigDecimal进行精确计算
|
||||
BigDecimal bd = new BigDecimal(String.valueOf(value));
|
||||
|
||||
// 保留指定的小数位数,四舍五入
|
||||
bd = bd.setScale(decimalPlaces, BigDecimal.ROUND_HALF_UP);
|
||||
|
||||
// 移除末尾的零(可选,根据需要决定是否保留)
|
||||
String result = bd.stripTrailingZeros().toPlainString();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化误差范围,将 "-0.057735~0.057735" 格式化为 "±0.05774"
|
||||
*
|
||||
* @param radiusValue 误差范围值(通常是正数,表示±范围)
|
||||
* @return 格式化后的误差范围字符串
|
||||
*/
|
||||
private String formatErrorRange(double radiusValue) {
|
||||
return formatErrorRangeWithDecimalPlaces(radiusValue, 5);
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化误差范围,支持自定义小数位数
|
||||
*
|
||||
* @param radiusValue 误差范围值(通常是正数,表示±范围)
|
||||
* @param decimalPlaces 小数位数
|
||||
* @return 格式化后的误差范围字符串
|
||||
*/
|
||||
/**
|
||||
* 格式化误差范围字符串,支持处理"-0.05~0.05"格式并转换为"±0.05"格式
|
||||
*
|
||||
* @param errorRange 误差范围字符串
|
||||
* @param decimalPlaces 小数位数
|
||||
* @return 格式化后的误差范围
|
||||
*/
|
||||
private String formatErrorRange(String errorRange, Integer decimalPlaces) {
|
||||
if (errorRange == null || decimalPlaces == null) {
|
||||
return errorRange;
|
||||
}
|
||||
|
||||
try {
|
||||
// 尝试直接解析为数字
|
||||
double radiusValue = Double.parseDouble(errorRange);
|
||||
return formatErrorRangeWithDecimalPlaces(radiusValue, decimalPlaces);
|
||||
} catch (NumberFormatException e) {
|
||||
// 处理"-0.05~0.05"这种格式
|
||||
if (errorRange.contains("~")) {
|
||||
String[] parts = errorRange.split("~");
|
||||
if (parts.length == 2) {
|
||||
try {
|
||||
double minValue = Double.parseDouble(parts[0].trim());
|
||||
double maxValue = Double.parseDouble(parts[1].trim());
|
||||
// 取绝对值的最大值作为范围
|
||||
double absMax = Math.max(Math.abs(minValue), Math.abs(maxValue));
|
||||
return formatErrorRangeWithDecimalPlaces(absMax, decimalPlaces);
|
||||
} catch (NumberFormatException ex) {
|
||||
log.warn("无法解析误差范围格式: {}", errorRange);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 如果无法解析,返回原值
|
||||
return errorRange;
|
||||
}
|
||||
}
|
||||
|
||||
private String formatErrorRangeWithDecimalPlaces(double radiusValue, int decimalPlaces) {
|
||||
if (radiusValue == 0.0) {
|
||||
return "±0";
|
||||
}
|
||||
|
||||
// 取绝对值并保留指定小数位数
|
||||
double absValue = Math.abs(radiusValue);
|
||||
String formattedValue = formatSignificantDigits(absValue, decimalPlaces);
|
||||
|
||||
return "±" + formattedValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据指标代码获取对应的小数位数
|
||||
*
|
||||
* @param scriptCode 指标代码
|
||||
* @return 小数位数,null表示不格式化
|
||||
*/
|
||||
private Integer getDecimalPlacesByScriptCode(String scriptCode) {
|
||||
if (scriptCode == null) {
|
||||
return null;
|
||||
}
|
||||
switch (scriptCode) {
|
||||
// 保留2位小数
|
||||
case "FREQ": // 频率
|
||||
return 2;
|
||||
// 保留3位小数
|
||||
case "I": // 电流
|
||||
return 3;
|
||||
// 保留4位小数
|
||||
case "IMBV": // 电压不平衡度
|
||||
case "IMBA": // 电流不平衡度
|
||||
return 4;
|
||||
// 保留5位小数
|
||||
case "V": // 电压
|
||||
case "HV": // 电压谐波
|
||||
case "HI": // 电流谐波
|
||||
case "HP": // 功率谐波
|
||||
case "HSV": // 电压间谐波
|
||||
case "HSI": // 电流间谐波
|
||||
return 5;
|
||||
// 其他指标不格式化
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user