Browse Source

Merge branch 'ls2_operation+early_warning+safety_risk+portrait_0731' of http://git.ningdatech.com/liushuai/project-management into dev

tags/24080901
PoffyZhang 1 year ago
parent
commit
fb642499c7
6 changed files with 410 additions and 0 deletions
  1. +142
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/scheduler/listener/EarlyWarningListener.java
  2. +17
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/EarlyWarningRecordsMapper.java
  3. +108
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/sys/model/entity/WflowEarlyWarningRecords.java
  4. +106
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/sys/model/vo/WflowEarlyWarningRecordsVO.java
  5. +11
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/sys/service/IEarlyWarningRecordsService.java
  6. +26
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/EarlyWarningRecordsServiceImpl.java

+ 142
- 0
pmapi/src/main/java/com/ningdatech/pmapi/scheduler/listener/EarlyWarningListener.java View File

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

+ 17
- 0
pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/EarlyWarningRecordsMapper.java View File

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

/**
* <p>
* Mapper 接口
* </p>
*
* @author PoffyZhang
*/
@Repository
public interface EarlyWarningRecordsMapper extends BaseMapper<WflowEarlyWarningRecords> {

}

+ 108
- 0
pmapi/src/main/java/com/ningdatech/pmapi/sys/model/entity/WflowEarlyWarningRecords.java View File

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

}

+ 106
- 0
pmapi/src/main/java/com/ningdatech/pmapi/sys/model/vo/WflowEarlyWarningRecordsVO.java View File

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

}

+ 11
- 0
pmapi/src/main/java/com/ningdatech/pmapi/sys/service/IEarlyWarningRecordsService.java View File

@@ -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<WflowEarlyWarningRecords> {

}

+ 26
- 0
pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/EarlyWarningRecordsServiceImpl.java View File

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


/**
* <p>
* 业务实现类
* 菜单
* </p>
*
* @author ZPF
*/
@Slf4j
@Service
@RequiredArgsConstructor
public class EarlyWarningRecordsServiceImpl extends ServiceImpl<EarlyWarningRecordsMapper, WflowEarlyWarningRecords>
implements IEarlyWarningRecordsService {

}

Loading…
Cancel
Save