计划名称去重、计划倒序排列

This commit is contained in:
caozehui
2025-01-16 15:59:09 +08:00
parent dd9662091a
commit 659f1e1ed5
7 changed files with 199 additions and 2 deletions

View File

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

View File

@@ -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.device.source.service.IPqSourceService;
import com.njcn.gather.plan.mapper.AdPlanMapper; import com.njcn.gather.plan.mapper.AdPlanMapper;
import com.njcn.gather.plan.pojo.enums.DataSourceEnum; 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.param.AdPlanParam;
import com.njcn.gather.plan.pojo.po.AdPlan; import com.njcn.gather.plan.pojo.po.AdPlan;
import com.njcn.gather.plan.pojo.vo.AdPlanExcel; import com.njcn.gather.plan.pojo.vo.AdPlanExcel;
@@ -95,6 +96,7 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
@Override @Override
@Transactional(rollbackFor = {Exception.class}) @Transactional(rollbackFor = {Exception.class})
public boolean addAdPlan(AdPlanParam param) { public boolean addAdPlan(AdPlanParam param) {
this.checkRepeat(param,false);
AdPlan adPlan = new AdPlan(); AdPlan adPlan = new AdPlan();
BeanUtil.copyProperties(param, adPlan); BeanUtil.copyProperties(param, adPlan);
@@ -132,6 +134,7 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
@Override @Override
@Transactional(rollbackFor = {Exception.class}) @Transactional(rollbackFor = {Exception.class})
public boolean updateAdPlan(AdPlanParam.UpdateParam param) { public boolean updateAdPlan(AdPlanParam.UpdateParam param) {
this.checkRepeat(param,true);
AdPlan adPlan = new AdPlan(); AdPlan adPlan = new AdPlan();
BeanUtil.copyProperties(param, adPlan); BeanUtil.copyProperties(param, adPlan);
@@ -277,7 +280,12 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
private Wrapper getQueryWrapper(AdPlanParam.QueryParam queryParam) { private Wrapper getQueryWrapper(AdPlanParam.QueryParam queryParam) {
QueryWrapper<AdPlan> queryWrapper = new QueryWrapper<>(); QueryWrapper<AdPlan> queryWrapper = new QueryWrapper<>();
if (ObjectUtil.isNotNull(queryParam)) { 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"); queryWrapper.eq("ad_plan.state", DataStateEnum.ENABLE.getCode()).orderBy(true, true, "Create_Time");
return queryWrapper; return queryWrapper;
@@ -400,4 +408,26 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
private Integer generateCode() { private Integer generateCode() {
return this.lambdaQuery().select(AdPlan::getCode).orderByDesc(AdPlan::getCode).last("LIMIT 1").one().getCode() + 1; 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<AdPlan> 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);
}
}
} }

View File

@@ -1,9 +1,12 @@
package com.njcn.gather.result.controller; package com.njcn.gather.result.controller;
import com.njcn.common.pojo.annotation.OperateInfo; 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.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult; import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.LogUtil; 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.param.ResultParam;
import com.njcn.gather.result.pojo.vo.FormContentVO; import com.njcn.gather.result.pojo.vo.FormContentVO;
import com.njcn.gather.result.pojo.vo.ResultVO; import com.njcn.gather.result.pojo.vo.ResultVO;
@@ -67,4 +70,20 @@ public class ResultController extends BaseController {
ResultVO resultVO = resultService.resultData(queryParam); ResultVO resultVO = resultService.resultData(queryParam);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, resultVO, methodDescribe); 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);
}
} }

View File

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

View File

@@ -45,6 +45,11 @@ public class ResultParam {
*/ */
private Integer index; private Integer index;
/**
* 当前选中的检测项
*/
private String currentCheckItem;
@Data @Data
public static class QueryParam { public static class QueryParam {

View File

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

View File

@@ -1,10 +1,14 @@
package com.njcn.gather.result.service.impl; 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.CollUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.github.yulichang.wrapper.MPJLambdaWrapper; import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.njcn.common.pojo.enums.common.DataStateEnum; 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.device.service.IPqDevService;
import com.njcn.gather.device.script.mapper.PqScriptMapper; import com.njcn.gather.device.script.mapper.PqScriptMapper;
import com.njcn.gather.device.script.pojo.po.PqScriptCheckData; 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.device.script.util.ScriptDtlsDesc;
import com.njcn.gather.plan.pojo.po.AdPlan; import com.njcn.gather.plan.pojo.po.AdPlan;
import com.njcn.gather.plan.service.IAdPlanService; 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.enums.ResultUnitEnum;
import com.njcn.gather.result.pojo.param.ResultParam; import com.njcn.gather.result.pojo.param.ResultParam;
import com.njcn.gather.result.pojo.vo.FormContentVO; 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.ResultVO;
import com.njcn.gather.result.pojo.vo.TreeDataVO; import com.njcn.gather.result.pojo.vo.TreeDataVO;
import com.njcn.gather.result.service.IResultService; import com.njcn.gather.result.service.IResultService;
import com.njcn.gather.storage.pojo.param.StorageParam; import com.njcn.gather.storage.pojo.param.StorageParam;
import com.njcn.gather.storage.pojo.po.AdBaseResult; 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.AdHarmonicService;
import com.njcn.gather.storage.service.AdNonHarmonicService; import com.njcn.gather.storage.service.AdNonHarmonicService;
import com.njcn.gather.system.config.service.ISysTestConfigService; import com.njcn.gather.system.config.service.ISysTestConfigService;
import com.njcn.gather.system.dictionary.pojo.po.DictTree; import com.njcn.gather.system.dictionary.pojo.po.DictTree;
import com.njcn.gather.system.dictionary.service.IDictTreeService; import com.njcn.gather.system.dictionary.service.IDictTreeService;
import com.njcn.web.utils.ExcelUtil;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@@ -746,7 +754,6 @@ public class ResultServiceImpl implements IResultService {
} }
@Override @Override
public ResultVO resultData(ResultParam param) { public ResultVO resultData(ResultParam param) {
StorageParam storage = new StorageParam(); StorageParam storage = new StorageParam();
@@ -780,6 +787,52 @@ public class ResultServiceImpl implements IResultService {
return resultVO; 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<Double> harmNum = new ArrayList<>();
if (HARMONIC_TYPE_CODE.contains(dictTree.getCode())) {
List<PqScriptCheckData> list = pqScriptCheckDataService.list(new MPJLambdaWrapper<PqScriptCheckData>()
.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<String, List<RawDataVO>> rawDataMap = null;
if (CollUtil.isEmpty(harmNum)) {
rawDataMap = adNonHarmonicService.listNonHarmData(storage);
} else {
storage.setHarmNum(harmNum);
rawDataMap = adHarmonicService.listHarmData(storage);
}
if (ObjectUtil.isNotNull(rawDataMap)) {
List<RawDataVO> rawDataVOList = rawDataMap.get(param.getCurrentCheckItem());
if (CollUtil.isNotEmpty(rawDataVOList)) {
if (isTPhase(rawDataVOList)) {
List<RawDataExcel.TRawDataExcel> rawDataExcelList = BeanUtil.copyToList(rawDataVOList, RawDataExcel.TRawDataExcel.class);
ExcelUtil.exportExcel("原始数据.xlsx", RawDataExcel.TRawDataExcel.class, ObjectUtil.isEmpty(rawDataExcelList) ? new ArrayList<>() : rawDataExcelList);
} else {
List<RawDataExcel.NotTRawDataExcel> 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<Integer> numbers) { private Integer conform(Set<Integer> numbers) {
if (CollUtil.isNotEmpty(numbers)) { if (CollUtil.isNotEmpty(numbers)) {
if (numbers.size() > 1) { if (numbers.size() > 1) {
@@ -792,4 +845,12 @@ public class ResultServiceImpl implements IResultService {
return 4; return 4;
} }
} }
private boolean isTPhase(List<RawDataVO> rawDataVOList) {
String dataT = rawDataVOList.get(0).getDataT();
if (ObjectUtil.isNotNull(dataT)) {
return true;
}
return false;
}
} }