正式检测-左侧检测项、检测详情弹窗-表单内容

This commit is contained in:
caozehui
2024-12-31 14:42:19 +08:00
parent 3bc797f23e
commit 14f3ab52bb
22 changed files with 652 additions and 23 deletions

View File

@@ -0,0 +1,61 @@
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 queryParam) {
String methodDescribe = getMethodDescribe("treeData");
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
}

View File

@@ -0,0 +1,37 @@
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 {
@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;
}
}

View File

@@ -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;
}

View File

@@ -0,0 +1,16 @@
package com.njcn.gather.result.pojo.vo;
import lombok.Data;
/**
* @author caozehui
* @data 2024-12-31
*/
@Data
public class TreeDataVO {
private String id;
private String scriptName;
private TreeDataVO[] children;
}

View File

@@ -0,0 +1,12 @@
package com.njcn.gather.result.service;
import com.njcn.gather.result.pojo.param.ResultParam;
import com.njcn.gather.result.pojo.vo.FormContentVO;
/**
* @author caozehui
* @data 2024-12-30
*/
public interface IResultService {
FormContentVO getFormContent(ResultParam.QueryParam queryParam);
}

View File

@@ -0,0 +1,109 @@
package com.njcn.gather.result.service.impl;
import cn.hutool.core.util.ObjectUtil;
import com.njcn.db.mybatisplus.handler.DynamicTableNameHandler;
import com.njcn.gather.device.device.service.IPqDevService;
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.param.ResultParam;
import com.njcn.gather.result.pojo.vo.FormContentVO;
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.util.*;
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 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())) {
String prefix = "ad_harmonic_result_";
DynamicTableNameHandler.setTableName(prefix + plan.getCode());
allResultList.addAll(adHarmonicService.get(scriptId, indexList, queryParam.getDeviceId(), queryParam.getChnNum()));
DynamicTableNameHandler.remove();
} else {
String prefix = "ad_non_harmonic_result_";
DynamicTableNameHandler.setTableName(prefix + plan.getCode());
allResultList.addAll(adNonHarmonicService.get(scriptId, indexList, queryParam.getDeviceId(), queryParam.getChnNum()));
DynamicTableNameHandler.remove();
}
} else { //查询所有的脚本类型
String prefix = "ad_harmonic_result_";
DynamicTableNameHandler.setTableName(prefix + plan.getCode());
allResultList.addAll(adHarmonicService.get(scriptId, null, queryParam.getDeviceId(), queryParam.getChnNum()));
DynamicTableNameHandler.remove();
prefix = "ad_non_harmonic_result_";
DynamicTableNameHandler.setTableName(prefix + plan.getCode());
allResultList.addAll(adNonHarmonicService.get(scriptId, null, queryParam.getDeviceId(), queryParam.getChnNum()));
DynamicTableNameHandler.remove();
}
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;
}
}