初始化流程放到线程中去处理
This commit is contained in:
parent
9749cad480
commit
8fb450adb1
12
src/main/java/com/lz/modules/flow/model/StartStartDto.java
Normal file
12
src/main/java/com/lz/modules/flow/model/StartStartDto.java
Normal file
@ -0,0 +1,12 @@
|
||||
package com.lz.modules.flow.model;
|
||||
|
||||
import com.lz.modules.sys.entity.app.ResultRecord;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@Data
|
||||
public class StartStartDto {
|
||||
private int status;
|
||||
private List<ResultRecord> resultRecordList = new ArrayList<>();
|
||||
}
|
||||
@ -27,14 +27,17 @@ import com.lz.modules.sys.entity.app.ResultDetail;
|
||||
import com.lz.modules.sys.entity.app.ResultRecord;
|
||||
import com.lz.modules.sys.service.app.ResultDetailService;
|
||||
import com.lz.modules.sys.service.app.ResultRecordService;
|
||||
import com.lz.modules.third.entity.ThirdAppConfig;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections.map.HashedMap;
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
||||
|
||||
import java.net.URLEncoder;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
@ -167,6 +170,8 @@ public class FlowStartServiceImpl extends ServiceImpl<FlowStartMapper, FlowStart
|
||||
Map<String, List<StaffEntity>> staffManages = new HashedMap();//部门(id+几级)和部门几级管理对应关系,减少数据库查找
|
||||
Map<Long, List<FlowChartRole>> mustRole = new HashMap<>();
|
||||
Map<Long, List<FlowChartRole>> selfMustRole = new HashMap<>();
|
||||
List<StaffSimpleInfo> noticeStaff = new ArrayList<>();
|
||||
List<ResultRecord> resultRecords = new ArrayList<>();
|
||||
for (GroupStaffs groupStaffs:startGroupStaffIds.getGroups()
|
||||
) {
|
||||
List<StaffSimpleInfo> staffSimpleInfos = staffService.selectStaffSimpleInfos(groupStaffs.getStaffIds());
|
||||
@ -177,7 +182,8 @@ public class FlowStartServiceImpl extends ServiceImpl<FlowStartMapper, FlowStart
|
||||
//流程流转中中途加人走的流程
|
||||
EvaluationGroup evaluationGroup =
|
||||
evaluationGroupService.selectEvaluationGroupByCopyId(groupStaffs.getEvaluationGroup().getId(),flowStart.getId());
|
||||
switch (start(evaluationGroup, flowStart, staffManages, staffSimpleInfos, mustRole, selfMustRole, true)){
|
||||
StartStartDto startDto = start(evaluationGroup, flowStart, staffManages, staffSimpleInfos, mustRole, selfMustRole, true);
|
||||
switch (startDto.getStatus()){
|
||||
|
||||
case 1:
|
||||
return R.error(groupStaffs.getEvaluationGroup().getName() + "——没有设置考核模板");
|
||||
@ -189,10 +195,16 @@ public class FlowStartServiceImpl extends ServiceImpl<FlowStartMapper, FlowStart
|
||||
return R.error(groupStaffs.getEvaluationGroup().getName() + "——没有设置绩效管理人员");
|
||||
case 5:
|
||||
return R.error(groupStaffs.getEvaluationGroup().getName() + "——初始化考核流程失败");
|
||||
case 0:
|
||||
noticeStaff.addAll(staffSimpleInfos);
|
||||
resultRecords.addAll(startDto.getResultRecordList());
|
||||
break;
|
||||
}
|
||||
dingtalkBusiness.sendWorkMSGWithAsyn(staffSimpleInfos, WorkMsgTypeEnum.START_WORK.getType());
|
||||
|
||||
|
||||
}
|
||||
initFlowRecordAnsy(resultRecords);
|
||||
dingtalkBusiness.sendWorkMSGWithAsyn(noticeStaff, WorkMsgTypeEnum.START_WORK.getType());
|
||||
|
||||
return R.ok("发起成功").put("data", flowStart);
|
||||
}
|
||||
@ -274,6 +286,7 @@ public class FlowStartServiceImpl extends ServiceImpl<FlowStartMapper, FlowStart
|
||||
Map<Long, List<FlowChartRole>> mustRole = new HashMap<>();
|
||||
Map<Long, List<FlowChartRole>> selfMustRole = new HashMap<>();
|
||||
List<StaffSimpleInfo> noticeStaff = new ArrayList<>();
|
||||
List<ResultRecord> resultRecords = new ArrayList<>();
|
||||
for (int n = 0; n < evaluationGroups.size(); n++
|
||||
) {
|
||||
EvaluationGroup evaluationGroup = evaluationGroups.get(n);
|
||||
@ -305,8 +318,8 @@ public class FlowStartServiceImpl extends ServiceImpl<FlowStartMapper, FlowStart
|
||||
}
|
||||
|
||||
|
||||
|
||||
switch (start(evaluationGroup, flowStart, staffManages, staffIds, mustRole, selfMustRole, false)){
|
||||
StartStartDto startDto = start(evaluationGroup, flowStart, staffManages, staffIds, mustRole, selfMustRole, false)
|
||||
switch (startDto.getStatus()){
|
||||
|
||||
case 1:
|
||||
return R.error(evaluationGroup.getName() + "——没有设置考核模板");
|
||||
@ -320,30 +333,34 @@ public class FlowStartServiceImpl extends ServiceImpl<FlowStartMapper, FlowStart
|
||||
return R.error(evaluationGroup.getName() + "——初始化考核流程失败");
|
||||
case 0:
|
||||
noticeStaff.addAll(staffIds);
|
||||
resultRecords.addAll(startDto.getResultRecordList());
|
||||
break;
|
||||
}
|
||||
}
|
||||
initFlowRecordAnsy(resultRecords);
|
||||
dingtalkBusiness.sendWorkMSGWithAsyn(noticeStaff, WorkMsgTypeEnum.START_WORK.getType());
|
||||
return R.ok("发起成功").put("data", flowStart);
|
||||
}
|
||||
//isInsert表示是否中途加人
|
||||
private int start(EvaluationGroup evaluationGroup, FlowStart flowStart,
|
||||
private StartStartDto start(EvaluationGroup evaluationGroup, FlowStart flowStart,
|
||||
Map<String, List<StaffEntity>> staffManages, List<StaffSimpleInfo> staffIds,
|
||||
Map<Long, List<FlowChartRole>> mustRole, Map<Long, List<FlowChartRole>> selfMustRole, boolean isInsert){
|
||||
|
||||
|
||||
StartStartDto startStartDto = new StartStartDto();
|
||||
List<ResultModelDto> resultModelDtos = resultModelService.selectResultDtoByGroupId(evaluationGroup.getId());
|
||||
if(resultModelDtos.size() == 0){
|
||||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();//事务回滚
|
||||
log.info("没有设置考核模板");
|
||||
return 1;
|
||||
startStartDto.setStatus(1);
|
||||
return startStartDto;
|
||||
}
|
||||
|
||||
List<FlowChart> flowCharts = flowChartService.selectFlowChartsByGroupId(evaluationGroup.getId());
|
||||
if(flowCharts.size() == 0){
|
||||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();//事务回滚
|
||||
log.info("无有效绩效流程节点");
|
||||
return 2;
|
||||
startStartDto.setStatus(2);
|
||||
return startStartDto;
|
||||
}
|
||||
List<FlowChartDetailRecord> flowChartDetailRecords = new ArrayList<>();
|
||||
for (FlowChart chart:flowCharts
|
||||
@ -356,7 +373,8 @@ public class FlowStartServiceImpl extends ServiceImpl<FlowStartMapper, FlowStart
|
||||
if(flowChartDetailRecords.size() == 0){
|
||||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();//事务回滚
|
||||
log.info("没有设置考核流程");
|
||||
return 3;
|
||||
startStartDto.setStatus(3);
|
||||
return startStartDto;
|
||||
}
|
||||
Map<Long, String> chartNameMaps =
|
||||
flowCharts.stream().collect(Collectors.toMap(FlowChart::getId, FlowChart::getName));//流程节点与流程名称对应map,下面多次循环,减少数据库查找
|
||||
@ -367,7 +385,8 @@ public class FlowStartServiceImpl extends ServiceImpl<FlowStartMapper, FlowStart
|
||||
if(staffManagers == null || staffManagers.size() == 0){
|
||||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();//事务回滚
|
||||
log.info("没有设置绩效管理人员");
|
||||
return 4;
|
||||
startStartDto.setStatus(4);
|
||||
return startStartDto;
|
||||
}
|
||||
|
||||
//下面拷贝一份考评组信息发起后所使用的考评组id为复制后的id
|
||||
@ -406,7 +425,7 @@ public class FlowStartServiceImpl extends ServiceImpl<FlowStartMapper, FlowStart
|
||||
}
|
||||
if(resultTagetLibs.size() > 0){
|
||||
//插入备份的考评组指标信息
|
||||
resultTagetLibService.insertResultTagetLibs(resultTagetLibs);
|
||||
resultTagetLibService.saveBatch(resultTagetLibs);
|
||||
}
|
||||
//拷贝一份流程
|
||||
for(FlowChartDetailRecord flowChartDetailRecord: flowChartDetailRecords){
|
||||
@ -420,13 +439,15 @@ public class FlowStartServiceImpl extends ServiceImpl<FlowStartMapper, FlowStart
|
||||
|
||||
if(evaluationGroup == null){
|
||||
log.info("无法找到拷贝组信息");
|
||||
return 5;
|
||||
startStartDto.setStatus(5);
|
||||
return startStartDto;
|
||||
}
|
||||
resultModelDtos = resultModelService.selectResultDtoByGroupId(evaluationGroup.getId());
|
||||
if(resultModelDtos.size() == 0){
|
||||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();//事务回滚
|
||||
log.info("拷贝组的维度信息错误");
|
||||
return 1;
|
||||
startStartDto.setStatus(1);
|
||||
return startStartDto;
|
||||
}
|
||||
for (ResultModelDto modelDto:resultModelDtos
|
||||
) {
|
||||
@ -471,9 +492,10 @@ public class FlowStartServiceImpl extends ServiceImpl<FlowStartMapper, FlowStart
|
||||
resultRecord.setCurrentApprovalStaffId(staffInfo.getId());
|
||||
//设置当前审批员工姓名 current_approval_staff_name
|
||||
resultRecord.setCurrentApprovalStaffName(staffInfo.getName());
|
||||
|
||||
resultRecordService.insertResultRecord(resultRecord);
|
||||
|
||||
startStartDto.getResultRecordList().add(resultRecord);
|
||||
|
||||
|
||||
resultRecordService.initFlowRecord(resultRecord.getId());
|
||||
|
||||
@ -505,11 +527,12 @@ public class FlowStartServiceImpl extends ServiceImpl<FlowStartMapper, FlowStart
|
||||
//如果有数据插入lz_result_detail表
|
||||
if(resultDetails.size() > 0){
|
||||
//
|
||||
resultDetailService.insertResultDetails(resultDetails);
|
||||
resultDetailService.saveBatch(resultDetails);
|
||||
}
|
||||
}
|
||||
evaluationStartStaffService.insertEvaluationStartStaffs(evaluationStartStaffs);
|
||||
return 0;
|
||||
evaluationStartStaffService.saveBatch(evaluationStartStaffs);
|
||||
startStartDto.setStatus(0);
|
||||
return startStartDto;
|
||||
}
|
||||
|
||||
//下面初始化lz_flow流程表 lz_flow_approval_role流程审批表
|
||||
@ -618,7 +641,7 @@ public class FlowStartServiceImpl extends ServiceImpl<FlowStartMapper, FlowStart
|
||||
}
|
||||
//插入记录/flowChart/saveDetailProcs
|
||||
if(flowApprovalRoles.size() > 0){
|
||||
flowApprovalRoleService.insertFlowApprovalRoles(flowApprovalRoles);
|
||||
flowApprovalRoleService.saveBatch(flowApprovalRoles);
|
||||
|
||||
//初始化lz_result_details数据
|
||||
List<ResultDetail> resultDetails = new ArrayList<>();
|
||||
@ -735,63 +758,9 @@ public class FlowStartServiceImpl extends ServiceImpl<FlowStartMapper, FlowStart
|
||||
resultRecord.setFlowStaffIdRole(roleJSON);
|
||||
|
||||
resultRecordService.insertResultRecord(resultRecord);
|
||||
startStartDto.getResultRecordList().add(resultRecord);
|
||||
staffInfo.setRecordId(resultRecord.getId());
|
||||
//下面生成实际的考核流程
|
||||
/*List<Flow> flows = flowService.selectByFlowId(resultRecord.getEvaluationId(),resultRecord.getStartId());
|
||||
List<Long> flowIds = new ArrayList<>();
|
||||
for(Flow flow:flows){
|
||||
flowIds.add(flow.getId());
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
for (FlowApprovalRole flowApprovalRole : flowApprovalRoles) {
|
||||
FlowRecord flowRecord = new FlowRecord();
|
||||
flowRecord.setRecordId(resultRecord.getId());
|
||||
StaffEntity approvalStaff = new StaffEntity();
|
||||
if (FlowApprovalRoleTypeEnums.ME.getType().equals(flowApprovalRole.getType())) {
|
||||
approvalStaff = staffService.selectStaffById(resultRecord.getStaffId());
|
||||
} else if (FlowApprovalRoleTypeEnums.STAFF.getType().equals(flowApprovalRole.getType())) {
|
||||
approvalStaff = staffService.selectStaffById(flowApprovalRole.getApprovalId());
|
||||
} else if (FlowApprovalRoleTypeEnums.ONE_SUPPER.getType().equals(flowApprovalRole.getType())) {
|
||||
approvalStaff = getDepartmentStaff(resultRecord.getStaffId(), 1);
|
||||
} else if (FlowApprovalRoleTypeEnums.TWO_SUPPER.getType().equals(flowApprovalRole.getType())) {
|
||||
approvalStaff = getDepartmentStaff(resultRecord.getStaffId(), 2);
|
||||
} else if (FlowApprovalRoleTypeEnums.THREE_SUPPER.getType().equals(flowApprovalRole.getType())) {
|
||||
approvalStaff = getDepartmentStaff(resultRecord.getStaffId(), 3);
|
||||
} else if (FlowApprovalRoleTypeEnums.FOUR_SUPPER.getType().equals(flowApprovalRole.getType())) {
|
||||
approvalStaff = getDepartmentStaff(resultRecord.getStaffId(), 4);
|
||||
} else if (FlowApprovalRoleTypeEnums.FOUR_SUPPER.getType().equals(flowApprovalRole.getType())) {
|
||||
approvalStaff = getDepartmentStaff(resultRecord.getStaffId(), 5);
|
||||
}
|
||||
if(approvalStaff !=null && StringUtil.isNotBlank(approvalStaff.getName())){
|
||||
insertFlowRecord(flowRecord,approvalStaff,flows,flowApprovalRole,resultRecord,i,null);
|
||||
}else{
|
||||
List<StaffRole> staffRoles= staffRoleService.selectAllStaffRoleByDepartmentLevel(Arrays.asList(new String[]{RoleEnums.MASTER_PM.getName(),RoleEnums.CHILD_PM.getName()}));
|
||||
for(StaffRole staffRole:staffRoles){
|
||||
approvalStaff = staffService.selectStaffById(staffRole.getStaffId());
|
||||
if(staffRole.getDepartmentId() ==0){ //如果是管理所有部门
|
||||
insertFlowRecord(flowRecord,approvalStaff,flows,flowApprovalRole,resultRecord,i,1);
|
||||
}else{
|
||||
DepartmentsStaffRelateEntity relateEntity = departmentsStaffRelateService.selectLastDepartmentByStaffId(resultRecord.getStaffId());
|
||||
Map<String, String> map = departmentsService.selectUserAllDepartmentIds(relateEntity.getDepartmentId());
|
||||
List<StaffRoleDepartment> staffRoleDepartments = staffRoleDepartmentService.selectStaffRoleDepartmentByStaffRoleId(staffRole.getId());
|
||||
boolean flag = false;
|
||||
for(StaffRoleDepartment staffRoleDepartment: staffRoleDepartments){
|
||||
String departmentName = map.get(staffRoleDepartment.getDepartmentId());
|
||||
if(StringUtil.isNotBlank(departmentName)){
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(flag){ //如果管理员是管理特定部门
|
||||
insertFlowRecord(flowRecord,approvalStaff,flows,flowApprovalRole,resultRecord,i,1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
resultRecordService.updateResultRecordById(resultRecord);*/
|
||||
|
||||
/*ExecutorService executor = Executors.newFixedThreadPool(10);
|
||||
List<ResultRecord> resultRecords = Lists.newArrayList();
|
||||
@ -802,9 +771,7 @@ public class FlowStartServiceImpl extends ServiceImpl<FlowStartMapper, FlowStart
|
||||
e.printStackTrace();
|
||||
}*/
|
||||
|
||||
log.info("开始时间{}", System.currentTimeMillis());
|
||||
resultRecordService.initFlowRecord(resultRecord.getId());
|
||||
log.info("结束时间{}", System.currentTimeMillis());
|
||||
//下面生成ResultDetail对象
|
||||
for (ResultModelDto modelDto:resultModelDtos
|
||||
) {
|
||||
@ -828,66 +795,17 @@ public class FlowStartServiceImpl extends ServiceImpl<FlowStartMapper, FlowStart
|
||||
//如果有数据插入lz_result_detail表
|
||||
if(resultDetails.size() > 0){
|
||||
//
|
||||
resultDetailService.insertResultDetails(resultDetails);
|
||||
resultDetailService.saveBatch(resultDetails);
|
||||
}
|
||||
evaluationStartStaffService.insertEvaluationStartStaffs(evaluationStartStaffs);
|
||||
evaluationStartStaffService.saveBatch(evaluationStartStaffs);
|
||||
}else{
|
||||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();//事务回滚
|
||||
log.info("初始化考核流程失败");
|
||||
return 5;
|
||||
startStartDto.setStatus(5);
|
||||
return startStartDto;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void insertFlowRecord(FlowRecord flowRecord,StaffEntity approvalStaff,List<Flow> flows,FlowApprovalRole flowApprovalRole ,ResultRecord resultRecord,int i,Integer stepType ){
|
||||
flowRecord.setApprovalStaffName(approvalStaff.getName());
|
||||
flowRecord.setApprovalStaffId(approvalStaff.getId());
|
||||
flowRecord.setFlowName(getFlow(flows, flowApprovalRole.getFlowId()).getOptDesc());
|
||||
flowRecord.setRecordStaffId(resultRecord.getStaffId());
|
||||
flowRecord.setFlowId(flowApprovalRole.getFlowId());
|
||||
FlowChart flowChart = flowService.selectFlowChartByChartId(flowApprovalRole.getFlowId());
|
||||
flowRecord.setProcessId(flowChart.getProcessId());
|
||||
flowRecord.setFlowProcess(flowChart.getFlowProcess());
|
||||
String staffRole = StaffRoles.getStaffRole(approvalStaff.getId(), StringUtil.strToLongs(flowApprovalRole.getRoleId()));
|
||||
if (i == 0) {
|
||||
flowRecord.setStatus(FlowRecordStatusEnums.CURRENT_FLOW_STATUS.getStatus());
|
||||
resultRecord.setFlowStaffIdRole(staffRole);
|
||||
resultRecord.setFlowProcess(flowChart.getFlowProcess());
|
||||
} else {
|
||||
flowRecord.setStatus(FlowRecordStatusEnums.UN_TO_STATUS.getStatus());
|
||||
if(new Integer(4).equals(flowChart.getFlowProcess())){
|
||||
EvaluationStartStaff evaluationStartStaff = evaluationStartStaffService.selectEvaluationStartById(resultRecord.getEvaluationId(),resultRecord.getStartId());
|
||||
if(evaluationStartStaff !=null && new Integer(1).equals(evaluationStartStaff.getScore())){
|
||||
flowRecord.setStatus(FlowRecordStatusEnums.SKIP_STATUS.getStatus());
|
||||
}else{
|
||||
log.info("evaluationStartStaff is null evaluationId :" + resultRecord.getEvaluationId() + ", startId : " + resultRecord.getStartId());
|
||||
}
|
||||
}
|
||||
}
|
||||
flowRecord.setFlowStaffIdRole(staffRole);
|
||||
flowRecord.setFlowIndex(flowApprovalRole.getStepIndex());
|
||||
flowRecord.setType(stepType !=null ? stepType :flowApprovalRole.getStepType()); //步骤类型0:依次,1:或签(同时通知,一人通过或拒绝即可),2会签(同时通知,所有人同意才可)
|
||||
flowRecordService.insertFlowRecord(flowRecord);
|
||||
|
||||
}
|
||||
|
||||
public Flow getFlow(List<Flow> flows,Long flowId){
|
||||
for(Flow flow : flows){
|
||||
if(flow.getId().equals(flowId)){
|
||||
return flow;
|
||||
}
|
||||
}
|
||||
return new Flow();
|
||||
}
|
||||
|
||||
public StaffEntity getDepartmentStaff(Long staffId, int level) {
|
||||
DepartManagers departManagers = staffService.findLeader( staffId, level);
|
||||
List<StaffEntity> staffEntities = departManagers.getManagers();
|
||||
if(CollectionUtils.isNotEmpty(staffEntities)){
|
||||
return staffEntities.get(0);
|
||||
}
|
||||
return new StaffEntity();
|
||||
|
||||
startStartDto.setStatus(0);
|
||||
return startStartDto;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -899,5 +817,33 @@ public class FlowStartServiceImpl extends ServiceImpl<FlowStartMapper, FlowStart
|
||||
return R.ok().put("data",staffEntity);
|
||||
}
|
||||
|
||||
private void initFlowRecordAnsy(List<ResultRecord> resultRecords){
|
||||
ThreadInitFlowRecord threadInitFlowRecord = new ThreadInitFlowRecord(resultRecords);
|
||||
Thread thread = new Thread(threadInitFlowRecord);
|
||||
thread.start();
|
||||
}
|
||||
|
||||
public class ThreadInitFlowRecord implements Runnable{
|
||||
List<ResultRecord> resultRecords;
|
||||
|
||||
public ThreadInitFlowRecord(List<ResultRecord> resultRecords){
|
||||
this.resultRecords = resultRecords;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
log.info("开始批量推送消息,数量{}", resultRecords.size());
|
||||
for (ResultRecord resultRecord:resultRecords
|
||||
) {
|
||||
String oldNo = ch.qos.logback.classic.Logger.threadLocalNo.get();
|
||||
String newNo = oldNo + "_" + resultRecord.getId() + "_" + resultRecord.getStaffId();
|
||||
ch.qos.logback.classic.Logger.threadLocalNo.set(newNo);
|
||||
resultRecordService.initFlowRecord(resultRecord.getId());
|
||||
ch.qos.logback.classic.Logger.threadLocalNo.set(oldNo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user