From bbb399e9813794c5aa23c75a166140073a7635b3 Mon Sep 17 00:00:00 2001 From: PoffyZhang <99775271@qq.com> Date: Thu, 3 Aug 2023 15:12:27 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A2=84=E8=AD=A6=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scheduler/listener/EarlyWarningListener.java | 142 +++++++++++++++++++++ .../sys/mapper/EarlyWarningRecordsMapper.java | 17 +++ .../sys/model/entity/WflowEarlyWarningRecords.java | 108 ++++++++++++++++ .../sys/model/vo/WflowEarlyWarningRecordsVO.java | 106 +++++++++++++++ .../sys/service/IEarlyWarningRecordsService.java | 11 ++ .../impl/EarlyWarningRecordsServiceImpl.java | 26 ++++ 6 files changed, 410 insertions(+) create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/scheduler/listener/EarlyWarningListener.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/EarlyWarningRecordsMapper.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/sys/model/entity/WflowEarlyWarningRecords.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/sys/model/vo/WflowEarlyWarningRecordsVO.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/sys/service/IEarlyWarningRecordsService.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/EarlyWarningRecordsServiceImpl.java diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/scheduler/listener/EarlyWarningListener.java b/pmapi/src/main/java/com/ningdatech/pmapi/scheduler/listener/EarlyWarningListener.java new file mode 100644 index 0000000..9217caa --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/scheduler/listener/EarlyWarningListener.java @@ -0,0 +1,142 @@ +package com.ningdatech.pmapi.scheduler.listener; + +import cn.hutool.core.collection.CollUtil; +import com.alibaba.fastjson.JSON; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.ningdatech.pmapi.common.constant.BizConst; +import com.ningdatech.pmapi.common.helper.UserInfoHelper; +import com.ningdatech.pmapi.projectlib.enumeration.InstTypeEnum; +import com.ningdatech.pmapi.projectlib.model.entity.Project; +import com.ningdatech.pmapi.projectlib.model.entity.ProjectInst; +import com.ningdatech.pmapi.projectlib.service.IProjectInstService; +import com.ningdatech.pmapi.projectlib.service.IProjectService; +import com.ningdatech.pmapi.sys.model.entity.WflowEarlyWarningRecords; +import com.ningdatech.pmapi.sys.service.IEarlyWarningRecordsService; +import com.ningdatech.pmapi.user.security.auth.model.UserFullInfoDTO; +import com.wflow.enums.WarningRuleTypeEnum; +import com.wflow.workflow.notify.event.EarlyWarningEvent; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.flowable.engine.HistoryService; +import org.flowable.engine.history.HistoricActivityInstance; +import org.flowable.engine.history.HistoricProcessInstance; +import org.springframework.context.event.EventListener; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Component; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.util.List; +import java.util.Objects; + +/** + * 预警规则触发 + * + * @author ZPF + * @return + * @since 2023/08/03 14:19 + */ +@Slf4j +@Component +@RequiredArgsConstructor +public class EarlyWarningListener { + private final HistoryService historyService; + private final IProjectInstService projectInstService; + + private final IProjectService projectService; + + private final IEarlyWarningRecordsService earlyWarningRecordsService; + + private final UserInfoHelper userInfoHelper; + + @Async + @EventListener + public void onApplicationEvent(EarlyWarningEvent event) { + log.info("进入预警规则触发的 事件监听!"); + log.info("event:{}", JSON.toJSONString(event)); + String nodeId = event.getNodeId(); + Integer timeout = event.getTimeout(); + String noticeMethod = event.getNoticeMethod(); + String noticeContent = event.getNoticeContent(); + + //1.根据nodeId 查询到 node 去查找 未完成 项目实例关系表 找到实例 + List hais = historyService.createHistoricActivityInstanceQuery() + .activityId(nodeId) + .unfinished() + .orderByHistoricActivityInstanceStartTime() + .asc() + .list(); + + if (CollUtil.isEmpty(hais)) { + log.info("没有查到 历史实例"); + return; + } + + String instanceId = hais.get(0).getProcessInstanceId(); + + //查询当前未完成的此实例 + HistoricProcessInstance instance = historyService.createHistoricProcessInstanceQuery() + .processInstanceId(instanceId) + .unfinished() + .singleResult(); + + if (Objects.isNull(instance)) { + log.info("没有查到实例 或者 实例已经结束"); + return; + } + + //2.查到 此流程实例的 项目 + ProjectInst pi = projectInstService.getOne(Wrappers.lambdaQuery(ProjectInst.class) + .eq(ProjectInst::getInstCode, instanceId) + .last(BizConst.LIMIT_1)); + + if (Objects.isNull(pi)) { + log.info("没有查到实例项目关联信息"); + return; + } + + Long projectId = pi.getProjectId(); + Project project = projectService.getById(projectId); + + if (Objects.isNull(project)) { + log.info("没有查到该项目信息"); + return; + } + + for(HistoricActivityInstance hai : hais){ + String assignee = hai.getAssignee(); + UserFullInfoDTO user = userInfoHelper.getUserFullInfoByEmployeeCode(assignee); + WflowEarlyWarningRecords records = new WflowEarlyWarningRecords(); + records.setAreaCode(project.getAreaCode()); + records.setBuildOrgCode(project.getBuildOrgCode()); + records.setBuildOrgName(project.getBuildOrgName()); + records.setCreateOn(LocalDateTime.now()); + records.setWarningTime(LocalDateTime.now()); + records.setInstStart(hai.getStartTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime()); + records.setInstType(pi.getInstType()); + records.setNoticeMethod(noticeMethod); + records.setNoticeContent(convertContent(noticeContent,project.getProjectName(),InstTypeEnum.getByCode(pi.getInstType()),timeout)); + records.setProjectName(project.getProjectName()); + records.setRuleType(WarningRuleTypeEnum.PROCESS_WARNING.getCode()); + records.setWarningUsername(Objects.nonNull(user) ? user.getUsername() : StringUtils.EMPTY); + records.setWarningEmployeecode(assignee); + earlyWarningRecordsService.save(records); + } + } + + /** + * 转换出 通知的内容 + * @param noticeContent + * @param projectName + * @param byCode + * @param timeout + * @return + */ + private String convertContent(String noticeContent, String projectName, InstTypeEnum instTypeEnum, Integer timeout) { + noticeContent = noticeContent.replace("{projectName}",projectName) + .replace("{flowType}",Objects.nonNull(instTypeEnum) ? instTypeEnum.getDesc() : "{flowType}") + .replace("{time}",String.valueOf(timeout)); + log.info("通知内容 :{}",noticeContent); + return noticeContent; + } +} \ No newline at end of file diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/EarlyWarningRecordsMapper.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/EarlyWarningRecordsMapper.java new file mode 100644 index 0000000..5c3174f --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/EarlyWarningRecordsMapper.java @@ -0,0 +1,17 @@ +package com.ningdatech.pmapi.sys.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.ningdatech.pmapi.sys.model.entity.WflowEarlyWarningRecords; +import org.springframework.stereotype.Repository; + +/** + *

+ * Mapper 接口 + *

+ * + * @author PoffyZhang + */ +@Repository +public interface EarlyWarningRecordsMapper extends BaseMapper { + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/model/entity/WflowEarlyWarningRecords.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/model/entity/WflowEarlyWarningRecords.java new file mode 100644 index 0000000..c130f7f --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/model/entity/WflowEarlyWarningRecords.java @@ -0,0 +1,108 @@ +package com.ningdatech.pmapi.sys.model.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.ToString; +import lombok.experimental.Accessors; + +import java.io.Serializable; +import java.time.LocalDateTime; + +/** + * 实体类 + * 角色分配 + * 预警触发通知记录 + * @author PoffyZhang + */ +@Data +@NoArgsConstructor +@ToString(callSuper = true) +@Accessors(chain = true) +@TableName("wflow_early_warning_records") +@ApiModel(value = "WflowEarlyWarningRecords", description = "预警触发通知记录") +public class WflowEarlyWarningRecords implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "id") + @TableId(value = "id", type = IdType.AUTO) + private Long id; + + /** + * 区域CODE + */ + @ApiModelProperty(value = "区域CODE") + private String areaCode; + + /** + * 项目名称 + */ + @ApiModelProperty(value = "项目名称") + private String projectName; + + + /** + * 流程类型 + */ + @ApiModelProperty(value = "流程类型") + private Integer instType; + + /** + * 任务开始时间 + */ + @ApiModelProperty(value = "任务开始时间") + private LocalDateTime instStart; + + /** + * 预警时间 + */ + @ApiModelProperty(value = "预警时间") + private LocalDateTime warningTime; + + /** + * 通知人名 + */ + @ApiModelProperty(value = "通知人名") + private String warningUsername; + + /** + * 预警员工号 + */ + @ApiModelProperty(value = "预警员工号") + private String warningEmployeecode; + + /** + * 通知方式 + */ + @ApiModelProperty(value = "通知方式 0浙政钉 1短信 逗号分隔") + private String noticeMethod; + + /** + * 通知内容 + */ + @ApiModelProperty(value = "通知内容") + private String noticeContent; + + /** + * 申报单位 + */ + @ApiModelProperty(value = "申报单位CODE") + private String buildOrgCode; + @ApiModelProperty(value = "申报单位") + private String buildOrgName; + + /** + * 规则 + */ + @ApiModelProperty(value = "规则类型 1.流程预警规则 2.填报预警规则 3.实施监督") + private Integer ruleType; + + + private LocalDateTime createOn; + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/model/vo/WflowEarlyWarningRecordsVO.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/model/vo/WflowEarlyWarningRecordsVO.java new file mode 100644 index 0000000..6b8675b --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/model/vo/WflowEarlyWarningRecordsVO.java @@ -0,0 +1,106 @@ +package com.ningdatech.pmapi.sys.model.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.ToString; +import lombok.experimental.Accessors; + +import java.io.Serializable; +import java.time.LocalDateTime; + +/** + * 实体类 + * 角色分配 + * 预警触发通知记录 + * @author PoffyZhang + */ +@Data +@NoArgsConstructor +@ToString(callSuper = true) +@Accessors(chain = true) +@ApiModel(value = "WflowEarlyWarningRecords", description = "预警触发通知记录") +public class WflowEarlyWarningRecordsVO implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "id") + private Long id; + + /** + * 区域CODE + */ + @ApiModelProperty(value = "区域CODE") + private String areaCode; + + /** + * 项目名称 + */ + @ApiModelProperty(value = "项目名称") + private String projectName; + + + /** + * 流程类型 + */ + @ApiModelProperty(value = "流程类型") + private Integer instType; + + /** + * 任务开始时间 + */ + @ApiModelProperty(value = "任务开始时间") + private LocalDateTime instStart; + + /** + * 预警时间 + */ + @ApiModelProperty(value = "预警时间") + private LocalDateTime warningTime; + + /** + * 通知人名 + */ + @ApiModelProperty(value = "通知人名") + private String warningUsername; + + /** + * 预警员工号 + */ + @ApiModelProperty(value = "预警员工号") + private String warningEmployeecode; + + /** + * 通知方式 + */ + @ApiModelProperty(value = "通知方式 0浙政钉 1短信 逗号分隔") + private String noticeMethod; + + /** + * 通知内容 + */ + @ApiModelProperty(value = "通知内容") + private String noticeContent; + + /** + * 申报单位 + */ + @ApiModelProperty(value = "申报单位CODE") + private String buildOrgCode; + @ApiModelProperty(value = "申报单位") + private String buildOrgName; + + /** + * 规则 + */ + @ApiModelProperty(value = "规则类型 1.流程预警规则 2.填报预警规则 3.实施监督") + private Integer ruleType; + + + private LocalDateTime createOn; + private String createBy; + private LocalDateTime updateOn; + private String updateBy; + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/IEarlyWarningRecordsService.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/IEarlyWarningRecordsService.java new file mode 100644 index 0000000..34339ed --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/IEarlyWarningRecordsService.java @@ -0,0 +1,11 @@ +package com.ningdatech.pmapi.sys.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.ningdatech.pmapi.sys.model.entity.WflowEarlyWarningRecords; + +/** + * @author PoffyZhang + */ +public interface IEarlyWarningRecordsService extends IService { + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/EarlyWarningRecordsServiceImpl.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/EarlyWarningRecordsServiceImpl.java new file mode 100644 index 0000000..d952a55 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/EarlyWarningRecordsServiceImpl.java @@ -0,0 +1,26 @@ +package com.ningdatech.pmapi.sys.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.ningdatech.pmapi.sys.mapper.EarlyWarningRecordsMapper; +import com.ningdatech.pmapi.sys.model.entity.WflowEarlyWarningRecords; +import com.ningdatech.pmapi.sys.service.IEarlyWarningRecordsService; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + + +/** + *

+ * 业务实现类 + * 菜单 + *

+ * + * @author ZPF + */ +@Slf4j +@Service +@RequiredArgsConstructor +public class EarlyWarningRecordsServiceImpl extends ServiceImpl + implements IEarlyWarningRecordsService { + +}