diff --git a/detection/src/main/java/com/njcn/gather/plan/pojo/enums/PlanResponseEnum.java b/detection/src/main/java/com/njcn/gather/plan/pojo/enums/PlanResponseEnum.java new file mode 100644 index 00000000..4190741e --- /dev/null +++ b/detection/src/main/java/com/njcn/gather/plan/pojo/enums/PlanResponseEnum.java @@ -0,0 +1,21 @@ +package com.njcn.gather.plan.pojo.enums; + +import lombok.Getter; + +/** + * @author caozehui + * @data 2025-01-16 + */ +@Getter +public enum PlanResponseEnum { + PLAN_REPEATED("A003014", "当前模式下,该计划已存在"); + + private final String message; + private final String code; + + + PlanResponseEnum(String code, String message) { + this.code = code; + this.message = message; + } +} diff --git a/detection/src/main/java/com/njcn/gather/plan/service/impl/AdPlanServiceImpl.java b/detection/src/main/java/com/njcn/gather/plan/service/impl/AdPlanServiceImpl.java index 9d20d947..6911a954 100644 --- a/detection/src/main/java/com/njcn/gather/plan/service/impl/AdPlanServiceImpl.java +++ b/detection/src/main/java/com/njcn/gather/plan/service/impl/AdPlanServiceImpl.java @@ -25,6 +25,7 @@ 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.enums.PlanResponseEnum; import com.njcn.gather.plan.pojo.param.AdPlanParam; import com.njcn.gather.plan.pojo.po.AdPlan; import com.njcn.gather.plan.pojo.vo.AdPlanExcel; @@ -95,6 +96,7 @@ public class AdPlanServiceImpl extends ServiceImpl impleme @Override @Transactional(rollbackFor = {Exception.class}) public boolean addAdPlan(AdPlanParam param) { + this.checkRepeat(param,false); AdPlan adPlan = new AdPlan(); BeanUtil.copyProperties(param, adPlan); @@ -132,6 +134,7 @@ public class AdPlanServiceImpl extends ServiceImpl impleme @Override @Transactional(rollbackFor = {Exception.class}) public boolean updateAdPlan(AdPlanParam.UpdateParam param) { + this.checkRepeat(param,true); AdPlan adPlan = new AdPlan(); BeanUtil.copyProperties(param, adPlan); @@ -277,7 +280,12 @@ public class AdPlanServiceImpl extends ServiceImpl impleme private Wrapper getQueryWrapper(AdPlanParam.QueryParam queryParam) { QueryWrapper 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(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()) + .orderByDesc("Create_Time"); } queryWrapper.eq("ad_plan.state", DataStateEnum.ENABLE.getCode()).orderBy(true, true, "Create_Time"); return queryWrapper; @@ -400,4 +408,26 @@ public class AdPlanServiceImpl extends ServiceImpl impleme private Integer generateCode() { return this.lambdaQuery().select(AdPlan::getCode).orderByDesc(AdPlan::getCode).last("LIMIT 1").one().getCode() + 1; } + + /** + * 检查计划是否重复 + * + * @param param 计划参数 + * @param isExcludeSelf 是否排除自己 + */ + private void checkRepeat(AdPlanParam param, boolean isExcludeSelf) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("state", DataStateEnum.ENABLE.getCode()) + .eq("Name", param.getName()) + .eq("Pattern", param.getPattern()); + if (isExcludeSelf) { + if (param instanceof AdPlanParam.UpdateParam) { + queryWrapper.ne("id", ((AdPlanParam.UpdateParam) param).getId()); + } + } + int count = this.count(queryWrapper); + if (count > 0) { + throw new BusinessException(PlanResponseEnum.PLAN_REPEATED); + } + } } diff --git a/detection/src/main/java/com/njcn/gather/result/controller/ResultController.java b/detection/src/main/java/com/njcn/gather/result/controller/ResultController.java index bd034f23..604e3938 100644 --- a/detection/src/main/java/com/njcn/gather/result/controller/ResultController.java +++ b/detection/src/main/java/com/njcn/gather/result/controller/ResultController.java @@ -1,9 +1,12 @@ package com.njcn.gather.result.controller; 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.response.HttpResult; import com.njcn.common.utils.LogUtil; +import com.njcn.gather.device.device.pojo.param.PqDevParam; import com.njcn.gather.result.pojo.param.ResultParam; import com.njcn.gather.result.pojo.vo.FormContentVO; import com.njcn.gather.result.pojo.vo.ResultVO; @@ -67,4 +70,20 @@ public class ResultController extends BaseController { ResultVO resultVO = resultService.resultData(queryParam); return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, resultVO, methodDescribe); } + + /** + * 导出灿能二楼设备 + * + * @param queryParam + */ + @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.DOWNLOAD) + @PostMapping("/exportRawData") + @ApiOperation("导出原始数据") + @ApiImplicitParam(name = "queryParam", value = "查询参数", required = true) + public void exportCNDev(@RequestBody @Validated ResultParam queryParam) { + String methodDescribe = getMethodDescribe("exportRawData"); + LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, queryParam); + + resultService.exportRawData(queryParam); + } } diff --git a/detection/src/main/java/com/njcn/gather/result/pojo/enums/ResultResponseEnum.java b/detection/src/main/java/com/njcn/gather/result/pojo/enums/ResultResponseEnum.java new file mode 100644 index 00000000..67552ee5 --- /dev/null +++ b/detection/src/main/java/com/njcn/gather/result/pojo/enums/ResultResponseEnum.java @@ -0,0 +1,21 @@ +package com.njcn.gather.result.pojo.enums; + +import lombok.Getter; + +/** + * @author caozehui + * @data 2025-01-16 + */ +@Getter +public enum ResultResponseEnum { + + RAW_DATA_NOT_EXIST("原始数据不存在!", "A001014"); + + private final String message; + private final String code; + + ResultResponseEnum(String code,String message) { + this.code = code; + this.message = message; + } +} diff --git a/detection/src/main/java/com/njcn/gather/result/pojo/param/ResultParam.java b/detection/src/main/java/com/njcn/gather/result/pojo/param/ResultParam.java index 83a3897c..60e9cb85 100644 --- a/detection/src/main/java/com/njcn/gather/result/pojo/param/ResultParam.java +++ b/detection/src/main/java/com/njcn/gather/result/pojo/param/ResultParam.java @@ -45,6 +45,11 @@ public class ResultParam { */ private Integer index; + /** + * 当前选中的检测项 + */ + private String currentCheckItem; + @Data public static class QueryParam { diff --git a/detection/src/main/java/com/njcn/gather/result/pojo/vo/RawDataExcel.java b/detection/src/main/java/com/njcn/gather/result/pojo/vo/RawDataExcel.java new file mode 100644 index 00000000..d3d37340 --- /dev/null +++ b/detection/src/main/java/com/njcn/gather/result/pojo/vo/RawDataExcel.java @@ -0,0 +1,40 @@ +package com.njcn.gather.result.pojo.vo; + +import cn.afterturn.easypoi.excel.annotation.Excel; +import com.njcn.gather.device.device.pojo.vo.PqDevExcel; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * @author caozehui + * @data 2025-01-16 + */ +@Data +public class RawDataExcel { + + @Excel(name = "时间", width = 25, orderNum = "1") + private String time; + + @Data + @EqualsAndHashCode(callSuper = true) + public static class NotTRawDataExcel extends RawDataExcel { + + @Excel(name = "A相", width = 15, orderNum = "2") + private String dataA; + + @Excel(name = "B相", width = 15, orderNum = "3") + private String dataB; + + @Excel(name = "C相", width = 15, orderNum = "4") + private String dataC; + } + + @Data + @EqualsAndHashCode(callSuper = true) + public static class TRawDataExcel extends RawDataExcel { + + @Excel(name = "T相", width = 15, orderNum = "2") + private String dataT; + + } +} diff --git a/detection/src/main/java/com/njcn/gather/result/service/impl/ResultServiceImpl.java b/detection/src/main/java/com/njcn/gather/result/service/impl/ResultServiceImpl.java index bb023818..d1536bde 100644 --- a/detection/src/main/java/com/njcn/gather/result/service/impl/ResultServiceImpl.java +++ b/detection/src/main/java/com/njcn/gather/result/service/impl/ResultServiceImpl.java @@ -1,10 +1,14 @@ 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.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.common.pojo.exception.BusinessException; +import com.njcn.gather.device.device.pojo.vo.CNDevExcel; import com.njcn.gather.device.device.service.IPqDevService; import com.njcn.gather.device.script.mapper.PqScriptMapper; import com.njcn.gather.device.script.pojo.po.PqScriptCheckData; @@ -14,19 +18,23 @@ import com.njcn.gather.device.script.service.IPqScriptDtlsService; import com.njcn.gather.device.script.util.ScriptDtlsDesc; import com.njcn.gather.plan.pojo.po.AdPlan; import com.njcn.gather.plan.service.IAdPlanService; +import com.njcn.gather.result.pojo.enums.ResultResponseEnum; 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.RawDataExcel; 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.param.StorageParam; import com.njcn.gather.storage.pojo.po.AdBaseResult; +import com.njcn.gather.storage.pojo.vo.RawDataVO; 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 com.njcn.web.utils.ExcelUtil; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -746,7 +754,6 @@ public class ResultServiceImpl implements IResultService { } - @Override public ResultVO resultData(ResultParam param) { StorageParam storage = new StorageParam(); @@ -780,6 +787,52 @@ public class ResultServiceImpl implements IResultService { return resultVO; } + @Override + public void exportRawData(ResultParam param) { + StorageParam storage = new StorageParam(); + storage.setIndex(param.getIndex()); + storage.setScriptId(param.getScriptId()); + storage.setDevId(param.getDevId()); + storage.setDevNum(param.getDevNum()); + storage.setCode(param.getCode()); + DictTree dictTree = dictTreeService.getById(param.getScriptType()); + List harmNum = new ArrayList<>(); + if (HARMONIC_TYPE_CODE.contains(dictTree.getCode())) { + List list = pqScriptCheckDataService.list(new MPJLambdaWrapper() + .distinct() + .select(PqScriptCheckData::getHarmNum) + .eq(PqScriptCheckData::getScriptId, param.getScriptId()) + .isNotNull(PqScriptCheckData::getHarmNum) + .eq(PqScriptCheckData::getIndex, param.getIndex()) + ); + harmNum = list.stream().sorted(Comparator.comparing(PqScriptCheckData::getHarmNum)) + .map(PqScriptCheckData::getHarmNum).distinct().collect(Collectors.toList()); + } + + Map> rawDataMap = null; + if (CollUtil.isEmpty(harmNum)) { + rawDataMap = adNonHarmonicService.listNonHarmData(storage); + } else { + storage.setHarmNum(harmNum); + rawDataMap = adHarmonicService.listHarmData(storage); + } + if (ObjectUtil.isNotNull(rawDataMap)) { + List rawDataVOList = rawDataMap.get(param.getCurrentCheckItem()); + + if (CollUtil.isNotEmpty(rawDataVOList)) { + if (isTPhase(rawDataVOList)) { + List rawDataExcelList = BeanUtil.copyToList(rawDataVOList, RawDataExcel.TRawDataExcel.class); + ExcelUtil.exportExcel("原始数据.xlsx", RawDataExcel.TRawDataExcel.class, ObjectUtil.isEmpty(rawDataExcelList) ? new ArrayList<>() : rawDataExcelList); + } else { + List rawDataExcelList = BeanUtil.copyToList(rawDataVOList, RawDataExcel.NotTRawDataExcel.class); + ExcelUtil.exportExcel("原始数据.xlsx", RawDataExcel.NotTRawDataExcel.class, ObjectUtil.isEmpty(rawDataExcelList) ? new ArrayList<>() : rawDataExcelList); + } + } else { + throw new BusinessException(ResultResponseEnum.RAW_DATA_NOT_EXIST); + } + } + } + private Integer conform(Set numbers) { if (CollUtil.isNotEmpty(numbers)) { if (numbers.size() > 1) { @@ -792,4 +845,12 @@ public class ResultServiceImpl implements IResultService { return 4; } } + + private boolean isTPhase(List rawDataVOList) { + String dataT = rawDataVOList.get(0).getDataT(); + if (ObjectUtil.isNotNull(dataT)) { + return true; + } + return false; + } }