技术监督计划导入

This commit is contained in:
wr
2025-03-28 16:13:24 +08:00
parent a6c536cf45
commit 0200607c0c
10 changed files with 71 additions and 316 deletions

View File

@@ -4,8 +4,8 @@ import cn.afterturn.easypoi.excel.annotation.Excel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.NotBlank;
import java.io.Serializable;
import java.util.Date;
/**
* @Description:
@@ -19,56 +19,48 @@ public class SupervisionPlanExcel {
* 负责单位ID
*/
@Excel(name = "*计划负责单位", width = 30)
@NotBlank(message = "计划负责单位不能为空")
private String deptId;
/**
* 普测计划名称
* 计划名称
*/
@Excel(name = "*普测计划名称", width = 30)
@NotBlank(message = "不能为空")
@Excel(name = "*计划名称", width = 30)
private String planName;
/**
* 监督类型
*/
@Excel(name = "*监督类型", width = 30)
@NotBlank(message = "监督类型不能为空")
private String supvType;
/**
* 监督对象名称
*/
@Excel(name = "*监督对象名称", width = 30)
@NotBlank(message = "监督对象名称不能为空")
private String supvObjectName;
/**
* 计划开始时间
*/
@Excel(name = "*计划开始时间(yyyy-MM-dd)", width = 30)
@NotBlank(message = "计划开始时间不能为空")
private String planStartTime;
@Excel(name = "*计划开始时间(yyyy/MM/dd)", width = 30,exportFormat = "yyyy/MM/dd")
private Date planStartTime;
/**
* 计划结束时间
*/
@Excel(name = "*计划结束时间(yyyy-MM-dd)", width = 30)
@NotBlank(message = "计划结束时间不能为空")
private String planEndTime;
@Excel(name = "*计划结束时间(yyyy/MM/dd)", width = 30,exportFormat = "yyyy/MM/dd")
private Date planEndTime;
/**
* 0 关联系统内变电站1 用户手动输入变电站
*/
@Excel(name = "*是否系统电站", width = 30, replace = {"是_1", "否_0",})
@NotBlank(message = "是否系统电站不能为空")
@Excel(name = "*是否系统电站", width = 30, replace = {"是_0", "否_1",})
private String customSubstationFlag ;
/**
* 变电站台账ID或者用户手动输入的变电站名称
*/
@Excel(name = "*关联电站一", width = 30)
@NotBlank(message = "关联电站一不能为空")
private String substation;
/**

View File

@@ -121,11 +121,11 @@ public class SurveyPlanController extends BaseController {
}
@PostMapping(value = "/importPlanData", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
@PostMapping(value = "/importPlanData")
@ApiOperation("批量导入技术监督计划")
@OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.ADD)
public HttpResult<String> importPlanData(@ApiParam(value = "文件", required = true) @RequestPart("file") MultipartFile file, HttpServletResponse response) {
String methodDescribe = getMethodDescribe("importDevData");
String methodDescribe = getMethodDescribe("importPlanData");
surveyPlanService.importPlanData(file, response);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}

View File

@@ -357,33 +357,6 @@ public class SupervisionDevMainReportPOServiceImpl extends ServiceImpl<Supervisi
List<PullDown> pullDowns = new ArrayList<>();
PullDown pullDown;
pullDown = new PullDown();
pullDown.setFirstCol(0);
pullDown.setLastCol(0);
pullDown.setIsText(true);
pullDowns.add(pullDown);
pullDown = new PullDown();
pullDown.setFirstCol(10);
pullDown.setLastCol(10);
pullDown.setIsText(true);
pullDowns.add(pullDown);
pullDown = new PullDown();
pullDown.setFirstCol(11);
pullDown.setLastCol(11);
pullDown.setIsText(true);
pullDowns.add(pullDown);
pullDown = new PullDown();
pullDown.setFirstCol(20);
pullDown.setLastCol(20);
pullDown.setIsText(true);
pullDowns.add(pullDown);
pullDown = new PullDown();
pullDown.setFirstCol(1);
pullDown.setLastCol(1);

View File

@@ -66,6 +66,7 @@ import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.time.ZoneId;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -144,12 +145,16 @@ public class SurveyPlanServiceImpl extends ServiceImpl<SurveyPlanMapper, SurveyP
String[] subIds = substation.split(StrPool.COMMA);
for (String subId : subIds) {
String name = lineFeignClient.getSubstationInfo(subId).getData().getName();
subName = subName.concat(StrPool.COMMA).concat(name);
PollutionSubstationDTO data = lineFeignClient.getSubstationInfo(subId).getData();
if (ObjectUtil.isNotNull(data)) {
String name = data.getName();
subName = subName.concat(StrPool.COMMA).concat(name);
}
}
if(StrUtil.isNotBlank(subName)){
subName = subName.substring(1);
}
subName = subName.substring(1);
}
record.setSubstation(subName);
} else {
record.setSubstationName(record.getSubstation());
@@ -387,36 +392,12 @@ public class SurveyPlanServiceImpl extends ServiceImpl<SurveyPlanMapper, SurveyP
pullDown.setStrings(depts.stream().map(DeptDTO::getName).distinct().collect(Collectors.toList()));
pullDowns.add(pullDown);
pullDown = new PullDown();
pullDown.setFirstCol(1);
pullDown.setLastCol(1);
pullDown.setIsText(true);
pullDowns.add(pullDown);
pullDown = new PullDown();
pullDown.setFirstCol(2);
pullDown.setLastCol(2);
pullDown.setStrings(supType.stream().map(DictData::getName).distinct().collect(Collectors.toList()));
pullDowns.add(pullDown);
pullDown = new PullDown();
pullDown.setFirstCol(3);
pullDown.setLastCol(3);
pullDown.setIsText(true);
pullDowns.add(pullDown);
pullDown = new PullDown();
pullDown.setFirstCol(4);
pullDown.setLastCol(4);
pullDown.setIsText(true);
pullDowns.add(pullDown);
pullDown = new PullDown();
pullDown.setFirstCol(5);
pullDown.setLastCol(5);
pullDown.setIsText(true);
pullDowns.add(pullDown);
pullDown = new PullDown();
pullDown.setFirstCol(6);
pullDown.setLastCol(6);
@@ -445,6 +426,7 @@ public class SurveyPlanServiceImpl extends ServiceImpl<SurveyPlanMapper, SurveyP
@Override
public void importPlanData(MultipartFile file, HttpServletResponse response) {
List<SupervisionPlanExcel.ExcelMsg> planMsgList = new ArrayList<>();
ImportParams params = new ImportParams();
//表头
params.setHeadRows(1);
@@ -455,19 +437,13 @@ public class SurveyPlanServiceImpl extends ServiceImpl<SurveyPlanMapper, SurveyP
params.setSheetNum(1);
List<SupervisionPlanExcel> planExcels;
try {
planExcels = ExcelImportUtil.importExcel(file.getInputStream(), SupervisionPlanExcel.class, params);
planExcels = ExcelImportUtil.importExcel(file.getInputStream(), SupervisionPlanExcel.class, params);
//如果存在非法数据,将不合格的数据导出
// if (CollectionUtil.isEmpty(objectExcelImportResult.getList())) {
// throw new BusinessException(SupervisionResponseEnum.IMPORT_PLAN_DATA_ERROR);
// }
if (planExcels.size() > 1) {
if (CollUtil.isEmpty(planExcels)) {
throw new BusinessException(SupervisionResponseEnum.IMPORT_PLAN_DATA_ERROR);
}
List<SupervisionPlanExcel.ExcelMsg> planMsgList = new ArrayList<>();
//各地市
List<DeptDTO> deptS = deptFeignClient.getDepSonDetailByDeptId(RequestUtil.getDeptIndex()).getData();
List<DeptDTO> deptS = deptFeignClient.getDepSonDetailByDeptId("0d52f9f6e43ec0ee83013cd32da93f66").getData();
List<DictData> supType = dicDataFeignClient.getDicDataByTypeCode(DicDataTypeEnum.SUPV_TYPE.getCode()).getData();
SubstationParam substationParam = new SubstationParam();
@@ -489,18 +465,12 @@ public class SurveyPlanServiceImpl extends ServiceImpl<SurveyPlanMapper, SurveyP
po.setDeptId(DeptIds.get(0));
}
}
List<SubGetBase> subList = new ArrayList<>();
List<String> list = Arrays.asList(planExcel.getSubstation(), planExcel.getSubstation2(), planExcel.getSubstation3());
if (CollUtil.isEmpty(list)) {
msg.append("关联电站不能为空!");
if (StrUtil.isEmpty(planExcel.getPlanName())) {
msg.append("计划名称不能为空!");
} else {
if ("1".equals(planExcel.getCustomSubstationFlag())) {
subList.addAll(data.stream().filter(x -> list.contains(x.getName())).collect(Collectors.toList()));
if (CollUtil.isEmpty(subList)) {
msg.append("关联电站不存在!");
}
}
po.setPlanName(planExcel.getPlanName());
}
if (StrUtil.isEmpty(planExcel.getSupvType())) {
msg.append("监督类型不能为空!");
} else {
@@ -513,24 +483,38 @@ public class SurveyPlanServiceImpl extends ServiceImpl<SurveyPlanMapper, SurveyP
}
if (StrUtil.isEmpty(planExcel.getSupvObjectName())) {
msg.append("监督对象名称不能为空!");
} else {
po.setSupvObjectName(planExcel.getSupvObjectName());
}
try {
Date startTime = planExcel.getPlanStartTime();
Date endTime = planExcel.getPlanEndTime();
po.setPlanStartTime(startTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDate());
po.setPlanEndTime(endTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDate());
} catch (Exception e) {
msg.append("计划时间格式有误!");
}
try {
DateTime startTime = DateUtil.parseDate(planExcel.getPlanStartTime());
DateTime endTime = DateUtil.parseDate(planExcel.getPlanEndTime());
po.setSupvObjectName(planExcel.getSupvObjectName());
po.setPlanStartTime(startTime.toLocalDateTime().toLocalDate());
po.setPlanEndTime(endTime.toLocalDateTime().toLocalDate());
if ("1".equals(planExcel.getCustomSubstationFlag())) {
List<String> subIds = subList.stream().map(SubGetBase::getId).collect(Collectors.toList());
po.setSubstation(String.join(",", subIds));
if (StrUtil.isEmpty(planExcel.getCustomSubstationFlag())) {
msg.append("是否系统电站不能为空!");
} else {
po.setCustomSubstationFlag(Integer.valueOf(planExcel.getCustomSubstationFlag()));
}
List<String> list = Arrays.asList(planExcel.getSubstation(), planExcel.getSubstation2(), planExcel.getSubstation3())
.stream().filter(Objects::nonNull).distinct().collect(Collectors.toList());
if (CollUtil.isEmpty(list)) {
msg.append("关联电站不能为空!");
} else {
if ("0".equals(planExcel.getCustomSubstationFlag())) {
List<String> subIds = data.stream().filter(x -> list.contains(x.getName())).map(SubGetBase::getId).collect(Collectors.toList());
if (CollUtil.isEmpty(subIds)) {
msg.append("关联电站不存在!");
} else {
po.setSubstation(String.join(",", subIds));
}
} else {
po.setSubstation(planExcel.getSubstation());
}
po.setCustomSubstationFlag(Integer.valueOf(planExcel.getCustomSubstationFlag()));
po.setSubstation(subList.get(0).getId());
} catch (Exception e) {
msg.append("计划时间格式有误!");
}
String string = msg.toString();
if (StrUtil.isNotBlank(string)) {
@@ -543,23 +527,27 @@ public class SurveyPlanServiceImpl extends ServiceImpl<SurveyPlanMapper, SurveyP
po.setStatus(BpmTaskStatusEnum.RUNNING.getStatus());
po.setState(DataStateEnum.ENABLE.getCode());
info.add(po);
// this.saveOrUpdate(po);
// SurveyPlan surveyPlan = this.baseMapper.selectById(po.getId());
// Map<String, Object> processInstanceVariables = new HashMap<>(16);
// BpmProcessInstanceCreateReqDTO bpmProcessInstanceCreateReqDTO = new BpmProcessInstanceCreateReqDTO();
// bpmProcessInstanceCreateReqDTO.setProcessDefinitionKey(SupervisionKeyEnum.SURVEY_PLAN.getKey());
// bpmProcessInstanceCreateReqDTO.setBusinessKey(surveyPlan.getId());
// bpmProcessInstanceCreateReqDTO.setStartUserSelectAssignees(new HashMap<>(16));
// bpmProcessInstanceCreateReqDTO.setVariables(processInstanceVariables);
// String processInstanceId = bpmProcessFeignClient.createProcessInstance(surveyPlan.getCreateBy(), bpmProcessInstanceCreateReqDTO).getData();
// // 将工作流的编号,更新到流程单中
// surveyPlan.setProcessInstanceId(processInstanceId);
// this.baseMapper.updateById(surveyPlan);
}
}
if (CollUtil.isNotEmpty(info)) {
for (SurveyPlan surveyPlan : info) {
this.saveOrUpdate(surveyPlan);
SurveyPlan plan = this.baseMapper.selectById(surveyPlan.getId());
Map<String, Object> processInstanceVariables = new HashMap<>(16);
BpmProcessInstanceCreateReqDTO bpmProcessInstanceCreateReqDTO = new BpmProcessInstanceCreateReqDTO();
bpmProcessInstanceCreateReqDTO.setProcessDefinitionKey(SupervisionKeyEnum.SURVEY_PLAN.getKey());
bpmProcessInstanceCreateReqDTO.setBusinessKey(plan.getId());
bpmProcessInstanceCreateReqDTO.setStartUserSelectAssignees(new HashMap<>(16));
bpmProcessInstanceCreateReqDTO.setVariables(processInstanceVariables);
String processInstanceId = bpmProcessFeignClient.createProcessInstance(plan.getCreateBy(), bpmProcessInstanceCreateReqDTO).getData();
// 将工作流的编号,更新到流程单中
plan.setProcessInstanceId(processInstanceId);
this.baseMapper.updateById(plan);
}
}
//判断有没有错误信息
if (CollectionUtil.isNotEmpty(planMsgList)) {
ExcelUtil.exportExcel("失败列表.xlsx", SupervisionDevMainReportExcel.ExcelMsg.class, planMsgList);
ExcelUtil.exportExcel("失败列表.xlsx", SupervisionPlanExcel.ExcelMsg.class, planMsgList);
}
} catch (Exception e) {
throw new BusinessException(SupervisionResponseEnum.IMPORT_PLAN_ERROR);

View File

@@ -91,11 +91,6 @@
<artifactId>cs-device-api</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>com.njcn.platform</groupId>
<artifactId>algorithm-api</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>

View File

@@ -1,39 +0,0 @@
package com.njcn.system.timer.tasks.algorithm;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.njcn.algorithm.pojo.bo.BaseParam;
import com.njcn.algorithm.pojo.liteflow.LiteFlowAlgorithmFeignClient;
import com.njcn.system.timer.TimerTaskRunner;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
/**
* 类的介绍:装置算法执行链定时任务
*
* @author xuyang
* @version 1.0.0
* @createTime 2023/12/6 9:35
*/
@Component
@RequiredArgsConstructor
public class DeviceAlgorithmTaskRunner implements TimerTaskRunner {
private final LiteFlowAlgorithmFeignClient liteFlowFeignClient;
@Override
public void action(String date) {
BaseParam baseParam = new BaseParam();
baseParam.setFullChain(true);
baseParam.setRepair(false);
if(StrUtil.isBlank(date)){
baseParam.setDataDate(DateUtil.yesterday().toString(DatePattern.NORM_DATE_PATTERN));
}else {
baseParam.setDataDate(date);
}
liteFlowFeignClient.deviceExecutor(baseParam);
}
}

View File

@@ -1,39 +0,0 @@
package com.njcn.system.timer.tasks.algorithm;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.njcn.algorithm.pojo.bo.BaseParam;
import com.njcn.algorithm.pojo.liteflow.LiteFlowAlgorithmFeignClient;
import com.njcn.system.timer.TimerTaskRunner;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
/**
* 类的介绍:监测点算法执行链定时任务
*
* @author xuyang
* @version 1.0.0
* @createTime 2023/12/6 9:35
*/
@Component
@RequiredArgsConstructor
public class MeasurementAlgorithmTaskRunner implements TimerTaskRunner {
private final LiteFlowAlgorithmFeignClient liteFlowFeignClient;
@Override
public void action(String date) {
BaseParam baseParam = new BaseParam();
baseParam.setFullChain(true);
baseParam.setRepair(false);
if(StrUtil.isBlank(date)){
baseParam.setDataDate(DateUtil.yesterday().toString(DatePattern.NORM_DATE_PATTERN));
}else {
baseParam.setDataDate(date);
}
liteFlowFeignClient.measurementPointExecutor(baseParam);
}
}

View File

@@ -1,41 +0,0 @@
package com.njcn.system.timer.tasks.algorithm;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.njcn.algorithm.pojo.bo.BaseParam;
import com.njcn.algorithm.pojo.liteflow.LiteFlowAlgorithmFeignClient;
import com.njcn.system.timer.TimerTaskRunner;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
/**
* 类的介绍:监测点算法执行链定时任务
*
* @author xuyang
* @version 1.0.0
* @createTime 2023/12/6 9:35
*/
@Component
@RequiredArgsConstructor
public class MeasurementHourAlgorithmTaskRunner implements TimerTaskRunner {
private final LiteFlowAlgorithmFeignClient liteFlowFeignClient;
@Override
public void action(String date) {
BaseParam baseParam = new BaseParam();
baseParam.setFullChain(true);
//由于是按小时跑的,前端其他算法都是按天跑的,因此修改参数
if(StrUtil.isBlank(date)){
baseParam.setRepair(false);
baseParam.setDataDate(DateUtil.now());
}else {
baseParam.setRepair(true);
baseParam.setBeginTime(date+ " 00:00:00");
baseParam.setEndTime(date+ " 24:00:00");
}
liteFlowFeignClient.measurementPointExecutorByHour(baseParam);
}
}

View File

@@ -1,37 +0,0 @@
package com.njcn.system.timer.tasks.algorithm;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.njcn.algorithm.pojo.bo.BaseParam;
import com.njcn.algorithm.pojo.liteflow.LiteFlowAlgorithmFeignClient;
import com.njcn.system.timer.TimerTaskRunner;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
/**
* 类的介绍:单位监测点算法执行链定时任务
*
* @author xuyang
* @version 1.0.0
* @createTime 2023/12/6 9:35
*/
@Component
@RequiredArgsConstructor
public class OrgAlgorithmTaskRunner implements TimerTaskRunner {
private final LiteFlowAlgorithmFeignClient liteFlowFeignClient;
@Override
public void action(String date) {
BaseParam baseParam = new BaseParam();
baseParam.setFullChain(true);
baseParam.setRepair(false);
if(StrUtil.isBlank(date)){
baseParam.setDataDate(DateUtil.yesterday().toString(DatePattern.NORM_DATE_PATTERN));
}else {
baseParam.setDataDate(date);
}
liteFlowFeignClient.orgPointExecutor(baseParam);
}
}

View File

@@ -1,37 +0,0 @@
package com.njcn.system.timer.tasks.algorithm;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.njcn.algorithm.pojo.bo.BaseParam;
import com.njcn.algorithm.pojo.liteflow.LiteFlowAlgorithmFeignClient;
import com.njcn.system.timer.TimerTaskRunner;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
/**
* 类的介绍:变电站算法执行链定时任务
*
* @author xuyang
* @version 1.0.0
* @createTime 2023/12/6 9:35
*/
@Component
@RequiredArgsConstructor
public class SubstationAlgorithmTaskRunner implements TimerTaskRunner {
private final LiteFlowAlgorithmFeignClient liteFlowFeignClient;
@Override
public void action(String date) {
BaseParam baseParam = new BaseParam();
baseParam.setFullChain(true);
baseParam.setRepair(false);
if(StrUtil.isBlank(date)){
baseParam.setDataDate(DateUtil.yesterday().toString(DatePattern.NORM_DATE_PATTERN));
}else {
baseParam.setDataDate(date);
}
liteFlowFeignClient.substationExecutor(baseParam);
}
}