From 73619c25c18260386791e3e7079277c1b10b9a2f Mon Sep 17 00:00:00 2001
From: quyixiao <2621048238@qq.com>
Date: Mon, 13 Jun 2022 12:17:17 +0800
Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BF=AE=E6=94=B9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../service/impl/FlowStartServiceImpl.java | 1600 ++++++++---------
.../app/impl/ResultRecordServiceImpl.java | 5 +
2 files changed, 801 insertions(+), 804 deletions(-)
diff --git a/src/main/java/com/lz/modules/flow/service/impl/FlowStartServiceImpl.java b/src/main/java/com/lz/modules/flow/service/impl/FlowStartServiceImpl.java
index 2d395eec..8e30c851 100644
--- a/src/main/java/com/lz/modules/flow/service/impl/FlowStartServiceImpl.java
+++ b/src/main/java/com/lz/modules/flow/service/impl/FlowStartServiceImpl.java
@@ -19,7 +19,6 @@ 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.mchange.lang.IntegerUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.BeanUtils;
@@ -33,13 +32,13 @@ import java.util.function.Function;
import java.util.stream.Collectors;
/**
-*
-* 发起考核表 服务类
-*
-*
-* @author quyixiao
-* @since 2020-10-13
-*/
+ *
+ * 发起考核表 服务类
+ *
+ *
+ * @author quyixiao
+ * @since 2020-10-13
+ */
@Service
@Slf4j
@@ -47,756 +46,743 @@ public class FlowStartServiceImpl extends ServiceImpl> staffManages = new HashedMap();//部门(id+几级)和部门几级管理对应关系,减少数据库查找
+ Map> mustRole = new HashMap<>();
+ Map> selfMustRole = new HashMap<>();
+ List noticeStaff = new ArrayList<>();
+ List resultRecords = new ArrayList<>();
+ for (GroupStaffs groupStaffs : startGroupStaffIds.getGroups()
+ ) {
+ List staffSimpleInfos = staffService.selectStaffSimpleInfos(groupStaffs.getStaffIds());
+ if (staffSimpleInfos.size() == 0) {
+ log.info("无有效考核人员");
+ R.error(groupStaffs.getEvaluationGroup().getName() + "——无有效考核人员");
+ }
+ //流程流转中中途加人走的流程
+ EvaluationGroup evaluationGroup =
+ evaluationGroupService.selectEvaluationGroupById(groupStaffs.getEvaluationGroup().getId());
+ //evaluationGroupService.selectEvaluationGroupByCopyId(groupStaffs.getEvaluationGroup().getId(),flowStart.getId());//20201218注释,不适用历史数据,使用最新模板数据
+ StartStartDto startDto = start(evaluationGroup, flowStart, staffManages, staffSimpleInfos, mustRole, selfMustRole, false);
+ switch (startDto.getStatus()) {
+
+ case 1:
+ return R.error(groupStaffs.getEvaluationGroup().getName() + "——没有设置考核模板");
+ case 2:
+ return R.error(groupStaffs.getEvaluationGroup().getName() + "——没有绩效流程节点");
+ case 3:
+ return R.error(groupStaffs.getEvaluationGroup().getName() + "——没有设置考核流程");
+ case 4:
+ return R.error(groupStaffs.getEvaluationGroup().getName() + "——没有设置绩效管理人员");
+ case 5:
+ return R.error(groupStaffs.getEvaluationGroup().getName() + "——初始化考核流程失败");
+ case 0:
+ noticeStaff.addAll(staffSimpleInfos);
+ resultRecords.add(startDto);
+ break;
+ }
-
- @Override
- public int updateFlowStartById(FlowStart flowStart){
- return flowStartMapper.updateFlowStartById(flowStart);
- }
+ }
+ initFlowRecordAnsy(resultRecords, noticeStaff);
+ return R.ok("发起成功").put("data", flowStart);
+ }
- @Override
- public int updateCoverFlowStartById(FlowStart flowStart){
- return flowStartMapper.updateCoverFlowStartById(flowStart);
- }
+ public static void main(String[] args) {
+ List ids = new ArrayList<>();
+ ids.add("64");
+ ids.add("65");
+ ids.add("98");
+ ids.add("111");
+ //ids.add("134");
+ ids.add("140");
+ ids.add("141");
+ ids.add("134");
+ Map maps = ids.stream().collect(Collectors.toMap(e -> e, e -> e));
+
+ System.out.println(maps);
+ }
+
+ @Override
+ public R saveStart(FlowStart flowStart) {
+ log.info("发起考核{}", flowStart);
+ //下面生成或者合并发起绩效
+ if (flowStart.getStartTime() == null) {
+ log.info("未设置有效考核月份");
+ return R.error("未设置有效考核月份");
+ }
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月");
+ String startDate = sdf.format(flowStart.getStartTime());
+
+ if (flowStart.getCycleType().intValue() != 0) {
+ //月份
+ if (flowStart.getEndTime() == null) {
+ log.info("未设置有效考核结束月份");
+ return R.error("未设置有效考核结束月份");
+ }
+ String endDate = sdf.format(flowStart.getEndTime());
+ flowStart.setName(startDate + "至" + endDate + "绩效考核");
+ } else {
+ flowStart.setName(startDate + "绩效考核");
+ }
+ List newIds = new ArrayList<>();
+ FlowStart flowStart1 = selectFlowStartByName(flowStart.getName());
+ if (flowStart1 == null) {
+ insertFlowStart(flowStart);
+ flowStart1 = flowStart;
+ } else {
+
+ //因为保存的时拷贝后的组,所以这里查询原来的组
+ List lIds = Arrays.stream(flowStart1.getGroupIds().split(",")).map(new Function() {
+ @Override
+ public Long apply(String s) {
+ newIds.add(s);
+ return Long.valueOf(s);
+ }
+ }).collect(Collectors.toList());
+ List evaluationGroups = evaluationGroupService.selectEvaluationGroupByCopyIds(lIds);
+
+ List ids1 = evaluationGroups.stream().map(new Function() {
+ @Override
+ public String apply(EvaluationGroup evaluationGroup) {
+ return evaluationGroup.getId().toString();
+ }
+ }).collect(Collectors.toList());
+ //查询拷贝后的
+ Map maps = ids1.stream().collect(Collectors.toMap(e -> e, e -> e));
- @Override
- public int deleteFlowStartById(Long id){
- return flowStartMapper.deleteFlowStartById(id);
- }
+ //求差集发起,但是历史记录怎么搞
+ List ids = Arrays.stream(flowStart.getGroupIds().split(",")).map(new Function() {
+ @Override
+ public String apply(String s) {
+ return s;
+ }
+ }).collect(Collectors.toList());
+ for (int i = 0; i < ids.size(); ) {//过滤掉已经发起的
+ String str = ids.get(i);
+ if (maps.containsKey(str)) {
+ ids.remove(str);
+ continue;
+ }
+ i++;
+ }
- @Override
- public FlowStart selectFlowStartByName(String name){
- return flowStartMapper.selectFlowStartByName(name);
- }
-
- //发起指定用户的绩效,中途添加的时候
- public R startStaffs(StartGroups startGroupStaffIds){
- log.info("发起指定用户的绩效,中途添加的时候{}", startGroupStaffIds);
- FlowStart flowStart = flowStartMapper.selectFlowStartById(startGroupStaffIds.getStartId());
- if(flowStart == null){
- log.info("发起任务不存在");
- return R.error("发起任务不存在");
- }
-
- Map> staffManages = new HashedMap();//部门(id+几级)和部门几级管理对应关系,减少数据库查找
- Map> mustRole = new HashMap<>();
- Map> selfMustRole = new HashMap<>();
- List noticeStaff = new ArrayList<>();
- List resultRecords = new ArrayList<>();
- for (GroupStaffs groupStaffs:startGroupStaffIds.getGroups()
- ) {
- List staffSimpleInfos = staffService.selectStaffSimpleInfos(groupStaffs.getStaffIds());
- if(staffSimpleInfos.size() == 0){
- log.info("无有效考核人员");
- R.error(groupStaffs.getEvaluationGroup().getName() + "——无有效考核人员");
- }
- //流程流转中中途加人走的流程
- EvaluationGroup evaluationGroup =
- evaluationGroupService.selectEvaluationGroupById(groupStaffs.getEvaluationGroup().getId());
- //evaluationGroupService.selectEvaluationGroupByCopyId(groupStaffs.getEvaluationGroup().getId(),flowStart.getId());//20201218注释,不适用历史数据,使用最新模板数据
- StartStartDto startDto = start(evaluationGroup, flowStart, staffManages, staffSimpleInfos, mustRole, selfMustRole, false);
- switch (startDto.getStatus()){
-
- case 1:
- return R.error(groupStaffs.getEvaluationGroup().getName() + "——没有设置考核模板");
- case 2:
- return R.error(groupStaffs.getEvaluationGroup().getName() + "——没有绩效流程节点");
- case 3:
- return R.error(groupStaffs.getEvaluationGroup().getName() + "——没有设置考核流程");
- case 4:
- return R.error(groupStaffs.getEvaluationGroup().getName() + "——没有设置绩效管理人员");
- case 5:
- return R.error(groupStaffs.getEvaluationGroup().getName() + "——初始化考核流程失败");
- case 0:
- noticeStaff.addAll(staffSimpleInfos);
- resultRecords.add(startDto);
- break;
- }
-
-
- }
- initFlowRecordAnsy(resultRecords, noticeStaff);
-
-
- return R.ok("发起成功").put("data", flowStart);
- }
-
- public static void main(String[] args) {
- List ids = new ArrayList<>();
- ids.add("64");
- ids.add("65");
- ids.add("98");
- ids.add("111");
- //ids.add("134");
- ids.add("140");
- ids.add("141");
- ids.add("134");
- Map maps = ids.stream().collect(Collectors.toMap(e->e, e->e));
-
- System.out.println(maps);
- }
-
- @Override
- public R saveStart(FlowStart flowStart){
- log.info("发起考核{}", flowStart);
- //下面生成或者合并发起绩效
- if(flowStart.getStartTime() == null){
- log.info("未设置有效考核月份");
- return R.error("未设置有效考核月份");
- }
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月");
- String startDate = sdf.format(flowStart.getStartTime());
-
- if(flowStart.getCycleType().intValue() != 0){
- //月份
- if(flowStart.getEndTime() == null){
- log.info("未设置有效考核结束月份");
- return R.error("未设置有效考核结束月份");
- }
- String endDate = sdf.format(flowStart.getEndTime());
- flowStart.setName(startDate + "至" + endDate + "绩效考核");
- }else{
- flowStart.setName(startDate + "绩效考核");
- }
- List newIds = new ArrayList<>();
- FlowStart flowStart1 = selectFlowStartByName(flowStart.getName());
- if(flowStart1 == null){
- insertFlowStart(flowStart);
- flowStart1 = flowStart;
- }else{
-
- //因为保存的时拷贝后的组,所以这里查询原来的组
- List lIds= Arrays.stream(flowStart1.getGroupIds().split(",")).map(new Function() {
- @Override
- public Long apply(String s) {
- newIds.add(s);
- return Long.valueOf(s);
- }
- }).collect(Collectors.toList());
- List evaluationGroups = evaluationGroupService.selectEvaluationGroupByCopyIds(lIds);
-
- List ids1= evaluationGroups.stream().map(new Function() {
- @Override
- public String apply(EvaluationGroup evaluationGroup) {
- return evaluationGroup.getId().toString();
- }
- }).collect(Collectors.toList());
- //查询拷贝后的
-
-
-
- Map maps = ids1.stream().collect(Collectors.toMap(e->e, e->e));
-
- //求差集发起,但是历史记录怎么搞
- List ids= Arrays.stream(flowStart.getGroupIds().split(",")).map(new Function() {
- @Override
- public String apply(String s) {
- return s;
- }
- }).collect(Collectors.toList());
- for(int i = 0; i < ids.size();){//过滤掉已经发起的
- String str = ids.get(i);
- if(maps.containsKey(str)){
- ids.remove(str);
- continue;
- }
- i++;
- }
-
- if(ids.size() == 0){
+ if (ids.size() == 0) {
/*return R.ok("发起成功,该任务已经发起过")
.put("data", flowStart1);*/
- log.info("可能会使用历史数模板数据");
- flowStart.setId(flowStart1.getId());
- flowStart.setIsDelete(flowStart1.getIsDelete());
- }else{
- log.info("有新增组");
- ids1.addAll(ids);
- flowStart1.setGroupIds(ids1.stream().collect(Collectors.joining(",")));//把新的组信息加入,把拷贝前的组信息保存下来
-
-
- flowStart.setGroupIds(ids.stream().collect(Collectors.joining(",")));//过滤后的考核组
- flowStart.setId(flowStart1.getId());
- flowStart.setIsDelete(flowStart1.getIsDelete());
- }
- }
-
-
- Map> staffManages = new HashedMap();//部门(id+几级)和部门几级管理对应关系,减少数据库查找
- //下面开始初始化流程
- List ids = Arrays.stream(flowStart.getGroupIds().split(",")).map(new Function() {
- @Override
- public Long apply(String s) {
- return Long.parseLong(s);
- }
- }).collect(Collectors.toList());
- List evaluationGroups = evaluationGroupService.selectEvaluationGroupByIds(ids);
-
- Map> mustRole = new HashMap<>();
- Map> selfMustRole = new HashMap<>();
- List noticeStaff = new ArrayList<>();
- List startStartDtos = new ArrayList<>();
- for (int n = 0; n < evaluationGroups.size(); n++
- ) {
- EvaluationGroup evaluationGroup = evaluationGroups.get(n);
- //下面初始化员工考核流程
- List staffIds = evaluationGroupService.selectAllStaffSimpleInfoByGroupId(evaluationGroup);
- if(staffIds.size() == 0){
- TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();//事务回滚
- log.info("无有效考核人员");
- return R.error(evaluationGroup.getName() + "——无有效考核人员");
- }
- if(flowStart.getIsDelete() != null){//已经发起过的
- //下面去掉已经发起的用户
- List longs = evaluationStartStaffService.selectStaffIdsByStartAndStaffId(flowStart.getId(), staffIds);
- if(longs.size() > 0){
- Map map
- = staffIds.stream().collect(Collectors.toMap(StaffSimpleInfo::getId, e->e));
- for (Long key:longs
- ) {
- map.remove(key);
- }
- staffIds = map.values().stream().collect(Collectors.toList());
-
- if(staffIds.size() == 0){
- log.info("本次发起参与人员为0");
- return R.error(evaluationGroup.getName() + "——本次发起参与人员为0");
- }
- }
-
- }
-
-
- StartStartDto startDto = start(evaluationGroup, flowStart, staffManages, staffIds, mustRole, selfMustRole, false);
- switch (startDto.getStatus()){
-
- case 1:
- return R.error(evaluationGroup.getName() + "——没有设置考核模板");
- case 2:
- return R.error(evaluationGroup.getName() + "——没有绩效流程节点");
- case 3:
- return R.error(evaluationGroup.getName() + "——没有设置考核流程");
- case 4:
- return R.error(evaluationGroup.getName() + "——没有设置绩效管理人员");
- case 5:
- return R.error(evaluationGroup.getName() + "——初始化考核流程失败");
- case 0:
- newIds.add(evaluationGroup.getId().toString());
- noticeStaff.addAll(staffIds);
- startStartDtos.add(startDto);
- break;
- }
- }
- flowStart1.setGroupIds(newIds.stream().collect(Collectors.joining(",")));
- updateFlowStartById(flowStart1);//更新组信息到记录里面
- initFlowRecordAnsy(startStartDtos, noticeStaff);
-
- //dingtalkBusiness.sendWorkMSGWithAsyn(noticeStaff, WorkMsgTypeEnum.START_WORK.getType());
- return R.ok("发起成功").put("data", flowStart);
- }
- //isInsert表示是否中途加人
- private StartStartDto start(EvaluationGroup evaluationGroup, FlowStart flowStart,
- Map> staffManages, List staffIds,
- Map> mustRole, Map> selfMustRole, boolean isInsert){
- log.info("开始发起考评组考核{}", evaluationGroup);
- StartStartDto startStartDto = new StartStartDto();
- List resultModelDtos = resultModelService.selectResultDtoByGroupId(evaluationGroup.getId());
- if(resultModelDtos.size() == 0){
- TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();//事务回滚
- log.info("没有设置考核模板");
- startStartDto.setStatus(1);
- return startStartDto;
- }
-
- List flowCharts = flowChartService.selectFlowChartsByGroupId(evaluationGroup.getId());
- if(flowCharts.size() == 0){
- TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();//事务回滚
- log.info("无有效绩效流程节点");
- startStartDto.setStatus(2);
- return startStartDto;
- }
- List flowChartDetailRecords = new ArrayList<>();
- for (FlowChart chart:flowCharts
- ) {//按照节点顺序获取正确的流程
- List flowChartDetailRecords1
- = flowChartDetailRecordService.selectOpenFlowChartDetailRecordByGroupIdAndChartId(evaluationGroup.getId(), chart.getId());
- flowChartDetailRecords.addAll(flowChartDetailRecords1);
- }
-
- if(flowChartDetailRecords.size() == 0){
- TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();//事务回滚
- log.info("没有设置考核流程");
- startStartDto.setStatus(3);
- return startStartDto;
- }
- Map chartNameMaps =
- flowCharts.stream().collect(Collectors.toMap(FlowChart::getId, FlowChart::getName));//流程节点与流程名称对应map,下面多次循环,减少数据库查找
-
- //获取绩效考核管理员
- List staffManagers = staffService.selectStaffsByGroupId(evaluationGroup.getCopyId());
-
- if(staffManagers == null || staffManagers.size() == 0){
- TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();//事务回滚
- log.info("没有设置绩效管理人员");
- startStartDto.setStatus(4);
- return startStartDto;
- }
-
- List resultRecords = new ArrayList<>();
- List flows;
- List flowApprovalRoles;
- //下面拷贝一份考评组信息发起后所使用的考评组id为复制后的id
- if(!isInsert){
- evaluationGroup.setCopyId(evaluationGroup.getId());
- evaluationGroup.setId(null);
- evaluationGroup.setGmtCreate(null);
- evaluationGroup.setGmtModified(null);
- evaluationGroup.setStartId(flowStart.getId());
- evaluationGroupService.insertEvaluationGroup(evaluationGroup);
-
- //拷贝考评组的指标信息
- List resultTagetLibs = new ArrayList<>();
-
- for (ResultModelDto dto:resultModelDtos
- ) {
- dto.setEvaluationGroupId(evaluationGroup.getId());//设置拷贝组的id
- //下面拷贝一份考评组信息的维度信息
- ResultModel resultModel = new ResultModel();
- BeanUtils.copyProperties(dto, resultModel);
- resultModel.setId(null);
- resultModelService.insertResultModel(resultModel);
-
- List libDtos = resultTagetLibService.selectResultTagetLibDtoByModelId(dto.getId());
- dto.setTagetLibs(libDtos);
- for (ResultTagetLibDto libDto: libDtos
- ) {
- //下面拷贝考评组里面的指标信息
- ResultTagetLib resultTagetLib = new ResultTagetLib();
- BeanUtils.copyProperties(libDto, resultTagetLib);
- resultTagetLib.setModelId(resultModel.getId());//设置新的维度id
- resultTagetLib.setId(null);
- resultTagetLibs.add(resultTagetLib);
- }
- dto.setId(resultModel.getId());
- }
- if(resultTagetLibs.size() > 0){
- //插入备份的考评组指标信息
- resultTagetLibService.saveBatch(resultTagetLibs);
- }
- //拷贝一份流程
- for(FlowChartDetailRecord flowChartDetailRecord: flowChartDetailRecords){
- flowChartDetailRecord.setId(null);
- flowChartDetailRecord.setGmtCreate(null);
- flowChartDetailRecord.setGmtModified(null);
- flowChartDetailRecord.setEvaluationGroupId(evaluationGroup.getId());
- }
- flowChartDetailRecordService.saveBatch(flowChartDetailRecords);
- }else{
-
- if(evaluationGroup == null){
- log.info("无法找到拷贝组信息");
- startStartDto.setStatus(5);
- return startStartDto;
- }
- resultModelDtos = resultModelService.selectResultDtoByGroupId(evaluationGroup.getId());
- if(resultModelDtos.size() == 0){
- TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();//事务回滚
- log.info("拷贝组的维度信息错误");
- startStartDto.setStatus(1);
- return startStartDto;
- }
- for (ResultModelDto modelDto:resultModelDtos
- ) {
- List resultTagetLibDtos = resultTagetLibService.selectResultTagetLibDtoByModelId(modelDto.getId());
- modelDto.setTagetLibs(resultTagetLibDtos);
- }
-
- //以下代码没必要更新,因为这个拷贝分用不到。正确的对应关系清查看lz_evaluation_start_staff
- //evaluationGroup.setStaffIds(evaluationGroup.getStaffIds() + ",");
-
- List evaluationStartStaffs = new ArrayList<>();
- List resultDetails = new ArrayList();
- //下面初始化参与人员
- for (StaffSimpleInfo staffInfo:staffIds
- ) {
-
- EvaluationStartStaff evaluationStartStaff = new EvaluationStartStaff();
- evaluationStartStaff.setEvaluationId(evaluationGroup.getId());
- evaluationStartStaff.setEvaluationName(evaluationGroup.getName());
- evaluationStartStaff.setStaffId(staffInfo.getId());
- evaluationStartStaff.setStartId(flowStart.getId());
- evaluationStartStaff.setDepartmentId(staffInfo.getDepartmentId());
- evaluationStartStaff.setType(CheckStaffType.STAFF.getCode());
- evaluationStartStaffs.add(evaluationStartStaff);
-
-
- //初始化lz_result_records数据
- ResultRecord resultRecord = new ResultRecord();
- resultRecord.setDepartmentId(staffInfo.getDepartmentId());
- resultRecord.setDepartmentName(staffInfo.getDepartmentName());
- resultRecord.setStaffId(staffInfo.getId());
- resultRecord.setStaffName(staffInfo.getName());
- resultRecord.setType(1);//设置为提交目标
- resultRecord.setStatus(0);//设置为新建
- resultRecord.setStartId(flowStart.getId());
- resultRecord.setEvaluationId(evaluationGroup.getId());
- resultRecord.setFlowProcess(0);//设置为目标制定
-
- //设置当前审批员工id current_approval_staff_id
- resultRecord.setCurrentApprovalStaffId(staffInfo.getId());
- //设置当前审批员工姓名 current_approval_staff_name
- resultRecord.setCurrentApprovalStaffName(staffInfo.getName());
- resultRecords.add(resultRecord);
- resultRecordService.insertResultRecord(resultRecord);
-
-
-
- //resultRecordService.initFlowRecord(resultRecord.getId());
-
- //下面生成实际的考核流程
- staffInfo.setResultRecord(resultRecord);
- staffInfo.setFlowStart(flowStart);
- for (ResultModelDto modelDto:resultModelDtos
- ) {
-
- log.info("发起考核,modelDto:{}, tagetLibsSize:{}", modelDto, modelDto.getTagetLibs().size());
- if(modelDto.getTagetLibs() != null && modelDto.getTagetLibs().size() > 0){//模板里面有添加指标
- for (ResultTagetLibDto libDto:
- modelDto.getTagetLibs()) {
-
- ResultDetail resultDetail = new ResultDetail();
- resultDetail.setRecordId(resultRecord.getId());
- resultDetail.setTarget(libDto.getName());
- resultDetail.setType(modelDto.getType());
- resultDetail.setKeyResult(libDto.getKeyResult());
- resultDetail.setCheckWeight(libDto.getWeight());
- resultDetail.setStaffId(resultRecord.getStaffId());
- resultDetail.setPriority(libDto.getOrderBy());
- resultDetail.setModelId(modelDto.getId());
- resultDetails.add(resultDetail);
- }
- }else{
- log.info("无考评组信息");
- }
- }
-
- //如果有数据插入lz_result_detail表
- log.info("发起考核,新增绩效详情个数{}", resultDetails.size());
- if(resultDetails.size() > 0){
- //
- resultDetailService.saveBatch(resultDetails);
- }
- }
- evaluationStartStaffService.saveBatch(evaluationStartStaffs);
- startStartDto.setResultRecordList(resultRecords);
- flows = flowService.selectByFlowId(evaluationGroup.getId(),flowStart.getId());
- List flowIds = flows.stream().map(new Function() {
- @Override
- public Long apply(Flow flow) {
- return flow.getId();
- }
- }).collect(Collectors.toList());
-
- flowApprovalRoles =flowApprovalRoleService.selectFlowApprovalRoleList(flowIds);
- startStartDto.setFlows(flows);
- startStartDto.setFlowApprovalRoles(flowApprovalRoles);
- startStartDto.setStatus(0);
- return startStartDto;
- }
-
- //下面初始化lz_flow流程表 lz_flow_approval_role流程审批表
- flows = new ArrayList<>();
- flowApprovalRoles = new ArrayList<>();
- int stepIndex = 0;
- for (FlowChartDetailRecord flowChartDetailRecord:flowChartDetailRecords
- ) {//初始化考评组对应的的flow
- Flow flow = new Flow();
- flow.setFlowId(evaluationGroup.getId());
- flow.setOpt("+");
- flow.setStartId(flowStart.getId());
- flow.setChartId(flowChartDetailRecord.getChartId());
- flow.setOptDesc(chartNameMaps.get(flowChartDetailRecord.getChartId()));
- flows.add(flow);
- flowService.insertFlow(flow);
- FlowApprovalRole flowApprovalRole = null;
- List flowChartRoles = null;
- //获取必备权限
- if(mustRole.containsKey(flow.getChartId())){
- flowChartRoles = mustRole.get(flow.getChartId());
- }else{
- flowChartRoles =
- flowChartRoleService.selectFlowChartRolesByChartIdAndType(flow.getChartId(), 1);
- mustRole.put(flow.getChartId(), flowChartRoles);
- }
-
- if(flowChartDetailRecord.getOptType().intValue() == ChartOptType.APPOINT.getCode()){//指定人员的
-
- String roles = null;
- if(flowChartRoles != null && flowChartRoles.size() > 0){//
- roles = flowChartRoles.stream().map(new Function() {
- @Override
- public String apply(FlowChartRole flowChartRole) {
- return flowChartRole.getRoleId().toString();
- }
- }).collect(Collectors.joining(","));
-
- }
-
- String[] optIds = flowChartDetailRecord.getOptIds().split(",");
- for (String id:optIds
- ) {//初始化考评组对应的的FlowApprovalRole
-
- flowApprovalRole = new FlowApprovalRole();
- flowApprovalRole.setFlowId(flow.getId());
- flowApprovalRole.setApprovalId(Long.parseLong(id));
- flowApprovalRole.setStepType(flowChartDetailRecord.getStepType());
- flowApprovalRole.setRoleId(flowChartDetailRecord.getRoleIds());
- flowApprovalRole.setType(flowChartDetailRecord.getOptType());
- flowApprovalRoles.add(flowApprovalRole);
- flowApprovalRole.setStepIndex(stepIndex);
- if(roles != null){
- if(flowApprovalRole.getRoleId() == null || flowApprovalRole.getRoleId().length() == 0){
- flowApprovalRole.setRoleId(roles);
- }else{
- flowApprovalRole.setRoleId(flowApprovalRole.getRoleId() + "," + roles);
- }
- }
-
-
- if(flowChartDetailRecord.getStepType().intValue() == 0){
- //依次
- stepIndex++;
- }
- }
- if(flowApprovalRole != null){
- stepIndex = flowApprovalRole.getStepIndex() + 1;
- }
-
- }else{
- if(flowChartDetailRecord.getOptType().intValue() == ChartOptType.SELF.getCode()) {//参与人员为自己的
- //获取被考核人的必备权限
- if (selfMustRole.containsKey(flow.getChartId())) {
- flowChartRoles.addAll(selfMustRole.get(flow.getChartId()));
- } else {
- List flowChartRoles1 =
- flowChartRoleService.selectFlowChartRolesByChartIdAndType(flow.getChartId(), 2);
- selfMustRole.put(flow.getChartId(), flowChartRoles1);
- flowChartRoles.addAll(flowChartRoles1);
- }
- }
- flowApprovalRole = new FlowApprovalRole();
- flowApprovalRole.setFlowId(flow.getId());
- flowApprovalRole.setStepType(flowChartDetailRecord.getStepType());
- flowApprovalRole.setRoleId(flowChartDetailRecord.getRoleIds());
- flowApprovalRole.setType(flowChartDetailRecord.getOptType());
- flowApprovalRoles.add(flowApprovalRole);
- flowApprovalRole.setStepIndex(stepIndex);
-
- if(flowChartRoles != null && flowChartRoles.size() > 0){//
- String roles = flowChartRoles.stream().map(new Function() {
- @Override
- public String apply(FlowChartRole flowChartRole) {
- return flowChartRole.getRoleId().toString();
- }
- }).collect(Collectors.joining(","));
- if(flowApprovalRole.getRoleId() == null || flowApprovalRole.getRoleId().length() == 0){
- flowApprovalRole.setRoleId(roles);
- }else{
- flowApprovalRole.setRoleId(flowApprovalRole.getRoleId() + "," + roles);
- }
- }
-
- stepIndex++;
- }
- }
- //插入记录/flowChart/saveDetailProcs
- if(flowApprovalRoles.size() > 0){
- flowApprovalRoleService.saveBatch(flowApprovalRoles);
-
- //初始化lz_result_details数据
- List resultDetails = new ArrayList<>();
-
- List evaluationStartStaffs = new ArrayList<>();
-
- //下面初始化参与人员
- for (StaffSimpleInfo staffInfo:staffIds
- ) {
-
- EvaluationStartStaff evaluationStartStaff = new EvaluationStartStaff();
- evaluationStartStaff.setEvaluationId(evaluationGroup.getId());
- evaluationStartStaff.setEvaluationName(evaluationGroup.getName());
- evaluationStartStaff.setStaffId(staffInfo.getId());
- evaluationStartStaff.setStartId(flowStart.getId());
- evaluationStartStaff.setDepartmentId(staffInfo.getDepartmentId());
- evaluationStartStaff.setType(CheckStaffType.STAFF.getCode());
- evaluationStartStaffs.add(evaluationStartStaff);
-
- //初始化lz_result_records数据
- ResultRecord resultRecord = new ResultRecord();
- resultRecord.setDepartmentId(staffInfo.getDepartmentId());
- resultRecord.setDepartmentName(staffInfo.getDepartmentName());
- resultRecord.setStaffId(staffInfo.getId());
- resultRecord.setStaffName(staffInfo.getName());
- resultRecord.setType(1);//设置为提交目标
- resultRecord.setStatus(0);//设置为新建
- resultRecord.setStartId(flowStart.getId());
- resultRecord.setEvaluationId(evaluationGroup.getId());
- resultRecord.setFlowProcess(0);//设置为目标制定
-
-
-
-
- //下面初始化flow_staff_id_role字段,步骤为0的
- String roleJSON = "[";
- for (int i = 0; i < flowApprovalRoles.size() ;i++){
- FlowApprovalRole approvalRole = flowApprovalRoles.get(i);
- if(approvalRole.getStepIndex().intValue() == 0){//找到所有步骤为0的人员
- Long staffId = approvalRole.getApprovalId();//默认为指定人员。
- if(approvalRole.getType().intValue() == ChartOptType.SELF.getCode()){
- //制定人员为自己的
- staffId = staffInfo.getId();
- if(i == 0){//目前只设置一个,多个不明确是否支持,roleJSON是支持多个的
- //设置当前审批员工id current_approval_staff_id
- resultRecord.setCurrentApprovalStaffId(staffInfo.getId());
- //设置当前审批员工姓名 current_approval_staff_name
- resultRecord.setCurrentApprovalStaffName(staffInfo.getName());
-
- }
- } else if(approvalRole.getType().intValue() > 0){//当设置为几级领导时
- ///查找领导,如果不存在那么设置管理人员
- List staffLeader;
- String key = staffInfo.getDepartmentId() + "_" + approvalRole.getType();
- if(staffManages.containsKey(key)){
- staffLeader = staffManages.get(staffInfo.getDepartmentId());
- }else{
- DepartManagers departManagers =
- staffService.findLeader(staffInfo.getId(), approvalRole.getType());
- staffLeader = departManagers.getManagers();
- staffManages.put(key, departManagers.getManagers());
- }
-
- if(staffLeader == null || staffLeader.size() == 0){
- //没有领导,通知到组设置的绩效管理人员
- for (StaffEntity entity:staffManagers
- ) {
- roleJSON += ("{\"roleId\":0,\"staffId\":" + entity.getId() + "},");//这里写死了权限为0的即为找不到领导
-
- }
- if(i == 0){//目前只设置一个,多个不明确是否支持,roleJSON是支持多个的
- //设置当前审批员工id current_approval_staff_id
- resultRecord.setCurrentApprovalStaffId(staffManagers.get(0).getId());
- //设置当前审批员工姓名 current_approval_staff_name
- resultRecord.setCurrentApprovalStaffName(staffManagers.get(0).getName());
-
- }
- }else{
- for(int j = 0; j > staffManages = new HashedMap();//部门(id+几级)和部门几级管理对应关系,减少数据库查找
+ //下面开始初始化流程
+ List ids = Arrays.stream(flowStart.getGroupIds().split(",")).map(new Function() {
+ @Override
+ public Long apply(String s) {
+ return Long.parseLong(s);
+ }
+ }).collect(Collectors.toList());
+ List evaluationGroups = evaluationGroupService.selectEvaluationGroupByIds(ids);
+
+ Map> mustRole = new HashMap<>();
+ Map> selfMustRole = new HashMap<>();
+ List noticeStaff = new ArrayList<>();
+ List startStartDtos = new ArrayList<>();
+ for (int n = 0; n < evaluationGroups.size(); n++
+ ) {
+ EvaluationGroup evaluationGroup = evaluationGroups.get(n);
+ //下面初始化员工考核流程
+ List staffIds = evaluationGroupService.selectAllStaffSimpleInfoByGroupId(evaluationGroup);
+ if (staffIds.size() == 0) {
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();//事务回滚
+ log.info("无有效考核人员");
+ return R.error(evaluationGroup.getName() + "——无有效考核人员");
+ }
+ if (flowStart.getIsDelete() != null) {//已经发起过的
+ //下面去掉已经发起的用户
+ List longs = evaluationStartStaffService.selectStaffIdsByStartAndStaffId(flowStart.getId(), staffIds);
+ if (longs.size() > 0) {
+ Map map
+ = staffIds.stream().collect(Collectors.toMap(StaffSimpleInfo::getId, e -> e));
+ for (Long key : longs
+ ) {
+ map.remove(key);
+ }
+ staffIds = map.values().stream().collect(Collectors.toList());
+
+ if (staffIds.size() == 0) {
+ log.info("本次发起参与人员为0");
+ return R.error(evaluationGroup.getName() + "——本次发起参与人员为0");
+ }
+ }
+
+ }
+
+
+ StartStartDto startDto = start(evaluationGroup, flowStart, staffManages, staffIds, mustRole, selfMustRole, false);
+ switch (startDto.getStatus()) {
+
+ case 1:
+ return R.error(evaluationGroup.getName() + "——没有设置考核模板");
+ case 2:
+ return R.error(evaluationGroup.getName() + "——没有绩效流程节点");
+ case 3:
+ return R.error(evaluationGroup.getName() + "——没有设置考核流程");
+ case 4:
+ return R.error(evaluationGroup.getName() + "——没有设置绩效管理人员");
+ case 5:
+ return R.error(evaluationGroup.getName() + "——初始化考核流程失败");
+ case 0:
+ newIds.add(evaluationGroup.getId().toString());
+ noticeStaff.addAll(staffIds);
+ startStartDtos.add(startDto);
+ break;
+ }
+ }
+ flowStart1.setGroupIds(newIds.stream().collect(Collectors.joining(",")));
+ updateFlowStartById(flowStart1);//更新组信息到记录里面
+ initFlowRecordAnsy(startStartDtos, noticeStaff);
+
+ //dingtalkBusiness.sendWorkMSGWithAsyn(noticeStaff, WorkMsgTypeEnum.START_WORK.getType());
+ return R.ok("发起成功").put("data", flowStart);
+ }
+
+ //isInsert表示是否中途加人
+ private StartStartDto start(EvaluationGroup evaluationGroup, FlowStart flowStart,
+ Map> staffManages, List staffIds,
+ Map> mustRole, Map> selfMustRole, boolean isInsert) {
+ log.info("开始发起考评组考核{}", evaluationGroup);
+ StartStartDto startStartDto = new StartStartDto();
+ List resultModelDtos = resultModelService.selectResultDtoByGroupId(evaluationGroup.getId());
+ if (resultModelDtos.size() == 0) {
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();//事务回滚
+ log.info("没有设置考核模板");
+ startStartDto.setStatus(1);
+ return startStartDto;
+ }
+
+ List flowCharts = flowChartService.selectFlowChartsByGroupId(evaluationGroup.getId());
+ if (flowCharts.size() == 0) {
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();//事务回滚
+ log.info("无有效绩效流程节点");
+ startStartDto.setStatus(2);
+ return startStartDto;
+ }
+ List flowChartDetailRecords = new ArrayList<>();
+ for (FlowChart chart : flowCharts
+ ) {//按照节点顺序获取正确的流程
+ List flowChartDetailRecords1
+ = flowChartDetailRecordService.selectOpenFlowChartDetailRecordByGroupIdAndChartId(evaluationGroup.getId(), chart.getId());
+ flowChartDetailRecords.addAll(flowChartDetailRecords1);
+ }
+
+ if (flowChartDetailRecords.size() == 0) {
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();//事务回滚
+ log.info("没有设置考核流程");
+ startStartDto.setStatus(3);
+ return startStartDto;
+ }
+ Map chartNameMaps =
+ flowCharts.stream().collect(Collectors.toMap(FlowChart::getId, FlowChart::getName));//流程节点与流程名称对应map,下面多次循环,减少数据库查找
+
+ //获取绩效考核管理员
+ List staffManagers = staffService.selectStaffsByGroupId(evaluationGroup.getCopyId());
+
+ if (staffManagers == null || staffManagers.size() == 0) {
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();//事务回滚
+ log.info("没有设置绩效管理人员");
+ startStartDto.setStatus(4);
+ return startStartDto;
+ }
+
+ List resultRecords = new ArrayList<>();
+ List flows;
+ List flowApprovalRoles;
+ //下面拷贝一份考评组信息发起后所使用的考评组id为复制后的id
+ if (!isInsert) {
+ evaluationGroup.setCopyId(evaluationGroup.getId());
+ evaluationGroup.setId(null);
+ evaluationGroup.setGmtCreate(null);
+ evaluationGroup.setGmtModified(null);
+ evaluationGroup.setStartId(flowStart.getId());
+ evaluationGroupService.insertEvaluationGroup(evaluationGroup);
+
+ //拷贝考评组的指标信息
+ List resultTagetLibs = new ArrayList<>();
+
+ for (ResultModelDto dto : resultModelDtos
+ ) {
+ dto.setEvaluationGroupId(evaluationGroup.getId());//设置拷贝组的id
+ //下面拷贝一份考评组信息的维度信息
+ ResultModel resultModel = new ResultModel();
+ BeanUtils.copyProperties(dto, resultModel);
+ resultModel.setId(null);
+ resultModelService.insertResultModel(resultModel);
+
+ List libDtos = resultTagetLibService.selectResultTagetLibDtoByModelId(dto.getId());
+ dto.setTagetLibs(libDtos);
+ for (ResultTagetLibDto libDto : libDtos
+ ) {
+ //下面拷贝考评组里面的指标信息
+ ResultTagetLib resultTagetLib = new ResultTagetLib();
+ BeanUtils.copyProperties(libDto, resultTagetLib);
+ resultTagetLib.setModelId(resultModel.getId());//设置新的维度id
+ resultTagetLib.setId(null);
+ resultTagetLibs.add(resultTagetLib);
+ }
+ dto.setId(resultModel.getId());
+ }
+ if (resultTagetLibs.size() > 0) {
+ //插入备份的考评组指标信息
+ resultTagetLibService.saveBatch(resultTagetLibs);
+ }
+ //拷贝一份流程
+ for (FlowChartDetailRecord flowChartDetailRecord : flowChartDetailRecords) {
+ flowChartDetailRecord.setId(null);
+ flowChartDetailRecord.setGmtCreate(null);
+ flowChartDetailRecord.setGmtModified(null);
+ flowChartDetailRecord.setEvaluationGroupId(evaluationGroup.getId());
+ }
+ flowChartDetailRecordService.saveBatch(flowChartDetailRecords);
+ } else {
+
+ if (evaluationGroup == null) {
+ log.info("无法找到拷贝组信息");
+ startStartDto.setStatus(5);
+ return startStartDto;
+ }
+ resultModelDtos = resultModelService.selectResultDtoByGroupId(evaluationGroup.getId());
+ if (resultModelDtos.size() == 0) {
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();//事务回滚
+ log.info("拷贝组的维度信息错误");
+ startStartDto.setStatus(1);
+ return startStartDto;
+ }
+ for (ResultModelDto modelDto : resultModelDtos
+ ) {
+ List resultTagetLibDtos = resultTagetLibService.selectResultTagetLibDtoByModelId(modelDto.getId());
+ modelDto.setTagetLibs(resultTagetLibDtos);
+ }
+
+ //以下代码没必要更新,因为这个拷贝分用不到。正确的对应关系清查看lz_evaluation_start_staff
+ //evaluationGroup.setStaffIds(evaluationGroup.getStaffIds() + ",");
+
+ List evaluationStartStaffs = new ArrayList<>();
+ List resultDetails = new ArrayList();
+ //下面初始化参与人员
+ for (StaffSimpleInfo staffInfo : staffIds
+ ) {
+
+ EvaluationStartStaff evaluationStartStaff = new EvaluationStartStaff();
+ evaluationStartStaff.setEvaluationId(evaluationGroup.getId());
+ evaluationStartStaff.setEvaluationName(evaluationGroup.getName());
+ evaluationStartStaff.setStaffId(staffInfo.getId());
+ evaluationStartStaff.setStartId(flowStart.getId());
+ evaluationStartStaff.setDepartmentId(staffInfo.getDepartmentId());
+ evaluationStartStaff.setType(CheckStaffType.STAFF.getCode());
+ evaluationStartStaffs.add(evaluationStartStaff);
+
+
+ //初始化lz_result_records数据
+ ResultRecord resultRecord = new ResultRecord();
+ resultRecord.setDepartmentId(staffInfo.getDepartmentId());
+ resultRecord.setDepartmentName(staffInfo.getDepartmentName());
+ resultRecord.setStaffId(staffInfo.getId());
+ resultRecord.setStaffName(staffInfo.getName());
+ resultRecord.setType(1);//设置为提交目标
+ resultRecord.setStatus(0);//设置为新建
+ resultRecord.setStartId(flowStart.getId());
+ resultRecord.setEvaluationId(evaluationGroup.getId());
+ resultRecord.setFlowProcess(0);//设置为目标制定
+
+ //设置当前审批员工id current_approval_staff_id
+ resultRecord.setCurrentApprovalStaffId(staffInfo.getId());
+ //设置当前审批员工姓名 current_approval_staff_name
+ resultRecord.setCurrentApprovalStaffName(staffInfo.getName());
+ resultRecords.add(resultRecord);
+ resultRecordService.insertResultRecord(resultRecord);
+
+
+ //resultRecordService.initFlowRecord(resultRecord.getId());
+
+ //下面生成实际的考核流程
+ staffInfo.setResultRecord(resultRecord);
+ staffInfo.setFlowStart(flowStart);
+ for (ResultModelDto modelDto : resultModelDtos
+ ) {
+
+ log.info("发起考核,modelDto:{}, tagetLibsSize:{}", modelDto, modelDto.getTagetLibs().size());
+ if (modelDto.getTagetLibs() != null && modelDto.getTagetLibs().size() > 0) {//模板里面有添加指标
+ for (ResultTagetLibDto libDto :
+ modelDto.getTagetLibs()) {
+
+ ResultDetail resultDetail = new ResultDetail();
+ resultDetail.setRecordId(resultRecord.getId());
+ resultDetail.setTarget(libDto.getName());
+ resultDetail.setType(modelDto.getType());
+ resultDetail.setKeyResult(libDto.getKeyResult());
+ resultDetail.setCheckWeight(libDto.getWeight());
+ resultDetail.setStaffId(resultRecord.getStaffId());
+ resultDetail.setPriority(libDto.getOrderBy());
+ resultDetail.setModelId(modelDto.getId());
+ resultDetails.add(resultDetail);
+ }
+ } else {
+ log.info("无考评组信息");
+ }
+ }
+
+ //如果有数据插入lz_result_detail表
+ log.info("发起考核,新增绩效详情个数{}", resultDetails.size());
+ if (resultDetails.size() > 0) {
+ //
+ resultDetailService.saveBatch(resultDetails);
+ }
+ }
+ evaluationStartStaffService.saveBatch(evaluationStartStaffs);
+ startStartDto.setResultRecordList(resultRecords);
+ flows = flowService.selectByFlowId(evaluationGroup.getId(), flowStart.getId());
+ List flowIds = flows.stream().map(new Function() {
+ @Override
+ public Long apply(Flow flow) {
+ return flow.getId();
+ }
+ }).collect(Collectors.toList());
+
+ flowApprovalRoles = flowApprovalRoleService.selectFlowApprovalRoleList(flowIds);
+ startStartDto.setFlows(flows);
+ startStartDto.setFlowApprovalRoles(flowApprovalRoles);
+ startStartDto.setStatus(0);
+ return startStartDto;
+ }
+
+ //下面初始化lz_flow流程表 lz_flow_approval_role流程审批表
+ flows = new ArrayList<>();
+ flowApprovalRoles = new ArrayList<>();
+ int stepIndex = 0;
+ for (FlowChartDetailRecord flowChartDetailRecord : flowChartDetailRecords
+ ) {//初始化考评组对应的的flow
+ Flow flow = new Flow();
+ flow.setFlowId(evaluationGroup.getId());
+ flow.setOpt("+");
+ flow.setStartId(flowStart.getId());
+ flow.setChartId(flowChartDetailRecord.getChartId());
+ flow.setOptDesc(chartNameMaps.get(flowChartDetailRecord.getChartId()));
+ flows.add(flow);
+ flowService.insertFlow(flow);
+ FlowApprovalRole flowApprovalRole = null;
+ List flowChartRoles = null;
+ //获取必备权限
+ if (mustRole.containsKey(flow.getChartId())) {
+ flowChartRoles = mustRole.get(flow.getChartId());
+ } else {
+ flowChartRoles =
+ flowChartRoleService.selectFlowChartRolesByChartIdAndType(flow.getChartId(), 1);
+ mustRole.put(flow.getChartId(), flowChartRoles);
+ }
+
+ if (flowChartDetailRecord.getOptType().intValue() == ChartOptType.APPOINT.getCode()) {//指定人员的
+
+ String roles = null;
+ if (flowChartRoles != null && flowChartRoles.size() > 0) {//
+ roles = flowChartRoles.stream().map(new Function() {
+ @Override
+ public String apply(FlowChartRole flowChartRole) {
+ return flowChartRole.getRoleId().toString();
+ }
+ }).collect(Collectors.joining(","));
+
+ }
+
+ String[] optIds = flowChartDetailRecord.getOptIds().split(",");
+ for (String id : optIds
+ ) {//初始化考评组对应的的FlowApprovalRole
+
+ flowApprovalRole = new FlowApprovalRole();
+ flowApprovalRole.setFlowId(flow.getId());
+ flowApprovalRole.setApprovalId(Long.parseLong(id));
+ flowApprovalRole.setStepType(flowChartDetailRecord.getStepType());
+ flowApprovalRole.setRoleId(flowChartDetailRecord.getRoleIds());
+ flowApprovalRole.setType(flowChartDetailRecord.getOptType());
+ flowApprovalRoles.add(flowApprovalRole);
+ flowApprovalRole.setStepIndex(stepIndex);
+ if (roles != null) {
+ if (flowApprovalRole.getRoleId() == null || flowApprovalRole.getRoleId().length() == 0) {
+ flowApprovalRole.setRoleId(roles);
+ } else {
+ flowApprovalRole.setRoleId(flowApprovalRole.getRoleId() + "," + roles);
+ }
+ }
+
+
+ if (flowChartDetailRecord.getStepType().intValue() == 0) {
+ //依次
+ stepIndex++;
+ }
+ }
+ if (flowApprovalRole != null) {
+ stepIndex = flowApprovalRole.getStepIndex() + 1;
+ }
+
+ } else {
+ if (flowChartDetailRecord.getOptType().intValue() == ChartOptType.SELF.getCode()) {//参与人员为自己的
+ //获取被考核人的必备权限
+ if (selfMustRole.containsKey(flow.getChartId())) {
+ flowChartRoles.addAll(selfMustRole.get(flow.getChartId()));
+ } else {
+ List flowChartRoles1 =
+ flowChartRoleService.selectFlowChartRolesByChartIdAndType(flow.getChartId(), 2);
+ selfMustRole.put(flow.getChartId(), flowChartRoles1);
+ flowChartRoles.addAll(flowChartRoles1);
+ }
+ }
+ flowApprovalRole = new FlowApprovalRole();
+ flowApprovalRole.setFlowId(flow.getId());
+ flowApprovalRole.setStepType(flowChartDetailRecord.getStepType());
+ flowApprovalRole.setRoleId(flowChartDetailRecord.getRoleIds());
+ flowApprovalRole.setType(flowChartDetailRecord.getOptType());
+ flowApprovalRoles.add(flowApprovalRole);
+ flowApprovalRole.setStepIndex(stepIndex);
+
+ if (flowChartRoles != null && flowChartRoles.size() > 0) {//
+ String roles = flowChartRoles.stream().map(new Function() {
+ @Override
+ public String apply(FlowChartRole flowChartRole) {
+ return flowChartRole.getRoleId().toString();
+ }
+ }).collect(Collectors.joining(","));
+ if (flowApprovalRole.getRoleId() == null || flowApprovalRole.getRoleId().length() == 0) {
+ flowApprovalRole.setRoleId(roles);
+ } else {
+ flowApprovalRole.setRoleId(flowApprovalRole.getRoleId() + "," + roles);
+ }
+ }
+
+ stepIndex++;
+ }
+ }
+ //插入记录/flowChart/saveDetailProcs
+ if (flowApprovalRoles.size() > 0) {
+ flowApprovalRoleService.saveBatch(flowApprovalRoles);
+
+ //初始化lz_result_details数据
+ List resultDetails = new ArrayList<>();
+
+ List evaluationStartStaffs = new ArrayList<>();
+
+ //下面初始化参与人员
+ for (StaffSimpleInfo staffInfo : staffIds
+ ) {
+
+ EvaluationStartStaff evaluationStartStaff = new EvaluationStartStaff();
+ evaluationStartStaff.setEvaluationId(evaluationGroup.getId());
+ evaluationStartStaff.setEvaluationName(evaluationGroup.getName());
+ evaluationStartStaff.setStaffId(staffInfo.getId());
+ evaluationStartStaff.setStartId(flowStart.getId());
+ evaluationStartStaff.setDepartmentId(staffInfo.getDepartmentId());
+ evaluationStartStaff.setType(CheckStaffType.STAFF.getCode());
+ evaluationStartStaffs.add(evaluationStartStaff);
+
+ //初始化lz_result_records数据
+ ResultRecord resultRecord = new ResultRecord();
+ resultRecord.setDepartmentId(staffInfo.getDepartmentId());
+ resultRecord.setDepartmentName(staffInfo.getDepartmentName());
+ resultRecord.setStaffId(staffInfo.getId());
+ resultRecord.setStaffName(staffInfo.getName());
+ resultRecord.setType(1);//设置为提交目标
+ resultRecord.setStatus(0);//设置为新建
+ resultRecord.setStartId(flowStart.getId());
+ resultRecord.setEvaluationId(evaluationGroup.getId());
+ resultRecord.setFlowProcess(0);//设置为目标制定
+
+
+ //下面初始化flow_staff_id_role字段,步骤为0的
+ String roleJSON = "[";
+ for (int i = 0; i < flowApprovalRoles.size(); i++) {
+ FlowApprovalRole approvalRole = flowApprovalRoles.get(i);
+ if (approvalRole.getStepIndex().intValue() == 0) {//找到所有步骤为0的人员
+ Long staffId = approvalRole.getApprovalId();//默认为指定人员。
+ if (approvalRole.getType().intValue() == ChartOptType.SELF.getCode()) {
+ //制定人员为自己的
+ staffId = staffInfo.getId();
+ if (i == 0) {//目前只设置一个,多个不明确是否支持,roleJSON是支持多个的
+ //设置当前审批员工id current_approval_staff_id
+ resultRecord.setCurrentApprovalStaffId(staffInfo.getId());
+ //设置当前审批员工姓名 current_approval_staff_name
+ resultRecord.setCurrentApprovalStaffName(staffInfo.getName());
+
+ }
+ } else if (approvalRole.getType().intValue() > 0) {//当设置为几级领导时
+ ///查找领导,如果不存在那么设置管理人员
+ List staffLeader;
+ String key = staffInfo.getDepartmentId() + "_" + approvalRole.getType();
+ if (staffManages.containsKey(key)) {
+ staffLeader = staffManages.get(staffInfo.getDepartmentId());
+ } else {
+ DepartManagers departManagers =
+ staffService.findLeader(staffInfo.getId(), approvalRole.getType());
+ staffLeader = departManagers.getManagers();
+ staffManages.put(key, departManagers.getManagers());
+ }
+
+ if (staffLeader == null || staffLeader.size() == 0) {
+ //没有领导,通知到组设置的绩效管理人员
+ for (StaffEntity entity : staffManagers
+ ) {
+ roleJSON += ("{\"roleId\":0,\"staffId\":" + entity.getId() + "},");//这里写死了权限为0的即为找不到领导
+
+ }
+ if (i == 0) {//目前只设置一个,多个不明确是否支持,roleJSON是支持多个的
+ //设置当前审批员工id current_approval_staff_id
+ resultRecord.setCurrentApprovalStaffId(staffManagers.get(0).getId());
+ //设置当前审批员工姓名 current_approval_staff_name
+ resultRecord.setCurrentApprovalStaffName(staffManagers.get(0).getName());
+
+ }
+ } else {
+ for (int j = 0; j < staffLeader.size(); j++) {
+ StaffEntity staff = staffLeader.get(j);
+
+ roleJSON += ("{\"roleId\":" + approvalRole.getRoleId() +
+ ",\"staffId\":" + staff.getId() + "},");
+ }
+ if (i == 0) {//目前只设置一个,多个不明确是否支持,roleJSON是支持多个的
+ //设置当前审批员工id current_approval_staff_id
+ resultRecord.setCurrentApprovalStaffId(staffLeader.get(0).getId());
+ //设置当前审批员工姓名 current_approval_staff_name
+ resultRecord.setCurrentApprovalStaffName(staffLeader.get(0).getName());
+
+ }
+ }
+
+ continue;
+ } else {
+ if (i == 0) {//目前只设置一个,多个不明确是否支持,roleJSON是支持多个的
+ //设置当前审批员工id current_approval_staff_id
+ resultRecord.setCurrentApprovalStaffId(approvalRole.getApprovalId());
+ //设置当前审批员工姓名 current_approval_staff_name
+ resultRecord.setCurrentApprovalStaffName("");
+
+ }
+ }
+
+ roleJSON += ("{\"roleId\":" + approvalRole.getRoleId() +
+ ",\"staffId\":" + staffId + "},");
+ continue;
+ }
+ break;
+ }
+ roleJSON += "]";
+ roleJSON = roleJSON.replace(",]", "]");
+ resultRecord.setFlowStaffIdRole(roleJSON);
+ resultRecords.add(resultRecord);
+ resultRecordService.insertResultRecord(resultRecord);
+
+
+ //startStartDto.getResultRecordList().add(resultRecord);
+ staffInfo.setResultRecord(resultRecord);
+ staffInfo.setFlowStart(flowStart);
+ //下面生成实际的考核流程
/*ExecutorService executor = Executors.newFixedThreadPool(10);
List resultRecords = Lists.newArrayList();
@@ -807,98 +793,104 @@ public class FlowStartServiceImpl extends ServiceImpl 0){//模板里面有添加指标
- for (ResultTagetLibDto libDto:
- modelDto.getTagetLibs()) {
- ResultDetail resultDetail = new ResultDetail();
- resultDetail.setRecordId(resultRecord.getId());
- resultDetail.setTarget(libDto.getName());
- resultDetail.setType(modelDto.getType());
- resultDetail.setKeyResult(libDto.getKeyResult());
- resultDetail.setCheckWeight(libDto.getWeight());
- resultDetail.setStaffId(resultRecord.getStaffId());
- resultDetail.setPriority(libDto.getOrderBy());
- resultDetail.setModelId(modelDto.getId());
- resultDetails.add(resultDetail);
- }
- }
- }
- }
- startStartDto.setResultRecordList(resultRecords);
- startStartDto.setFlowApprovalRoles(flowApprovalRoles);
- startStartDto.setFlows(flows);
- //如果有数据插入lz_result_detail表
- if(resultDetails.size() > 0){
- //
- resultDetailService.saveBatch(resultDetails);
- }
- evaluationStartStaffService.saveBatch(evaluationStartStaffs);
- }else{
- TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();//事务回滚
- log.info("初始化考核流程失败");
- startStartDto.setStatus(5);
- return startStartDto;
- }
+ //resultRecordService.initFlowRecord(resultRecord.getId());
+ //下面生成ResultDetail对象
+ for (ResultModelDto modelDto : resultModelDtos
+ ) {
+ if (modelDto.getTagetLibs() != null && modelDto.getTagetLibs().size() > 0) {//模板里面有添加指标
+ for (ResultTagetLibDto libDto :
+ modelDto.getTagetLibs()) {
+ ResultDetail resultDetail = new ResultDetail();
+ resultDetail.setRecordId(resultRecord.getId());
+ resultDetail.setTarget(libDto.getName());
+ resultDetail.setType(modelDto.getType());
+ resultDetail.setKeyResult(libDto.getKeyResult());
+ resultDetail.setCheckWeight(libDto.getWeight());
+ resultDetail.setStaffId(resultRecord.getStaffId());
+ resultDetail.setPriority(libDto.getOrderBy());
+ resultDetail.setModelId(modelDto.getId());
+ resultDetails.add(resultDetail);
+ }
+ }
+ }
+ }
+ startStartDto.setResultRecordList(resultRecords);
+ startStartDto.setFlowApprovalRoles(flowApprovalRoles);
+ startStartDto.setFlows(flows);
+ //如果有数据插入lz_result_detail表
+ if (resultDetails.size() > 0) {
+ //
+ resultDetailService.saveBatch(resultDetails);
+ }
+ evaluationStartStaffService.saveBatch(evaluationStartStaffs);
+ } else {
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();//事务回滚
+ log.info("初始化考核流程失败");
+ startStartDto.setStatus(5);
+ return startStartDto;
+ }
- startStartDto.setStatus(0);
- return startStartDto;
- }
+ startStartDto.setStatus(0);
+ return startStartDto;
+ }
- @Override
- public R getModelById(Long id, int type){
+ @Override
+ public R getModelById(Long id, int type) {
/*EvaluationGroup evaluationGroup = evaluationGroupService.selectEvaluationGroupById(id);
List staffIds = evaluationGroupService.selectAllStaffSimpleInfoByGroupId(evaluationGroup);*/
- //flowStart = flowStartService.selectFlowStartById(flowStart.getId());
- DepartManagers staffEntity = staffService.findLeader(id, type);
- return R.ok().put("data",staffEntity);
- }
+ //flowStart = flowStartService.selectFlowStartById(flowStart.getId());
+ DepartManagers staffEntity = staffService.findLeader(id, type);
+ return R.ok().put("data", staffEntity);
+ }
- private void initFlowRecordAnsy(List resultRecords, List noticeStaff){
- if(resultRecords.size() > 0){
- ThreadInitFlowRecord threadInitFlowRecord = new ThreadInitFlowRecord(resultRecords, noticeStaff);
+ private void initFlowRecordAnsy(List resultRecords, List noticeStaff) {
+ if (resultRecords.size() > 0) {
+ ThreadInitFlowRecord threadInitFlowRecord = new ThreadInitFlowRecord(resultRecords, noticeStaff);
- Thread thread = new Thread(threadInitFlowRecord);
- thread.start();
+ Thread thread = new Thread(threadInitFlowRecord);
+ thread.start();
- }
+ }
- }
+ }
- public class ThreadInitFlowRecord implements Runnable{
- List resultStarts;
- List noticeStaff;
+ public class ThreadInitFlowRecord implements Runnable {
+ List resultStarts;
+ List noticeStaff;
- public ThreadInitFlowRecord(List resultRecords, List noticeStaff){
+ public ThreadInitFlowRecord(List resultRecords, List noticeStaff) {
- this.resultStarts = resultRecords;
- this.noticeStaff = noticeStaff;
- }
+ this.resultStarts = resultRecords;
+ this.noticeStaff = noticeStaff;
+ }
- @Override
- public void run() {
- String oldNo = Logger.inheritableThreadLocalNo.get();//.threadLocalNo.get();
- String newNo = oldNo + "_initFlowRecord" ;//+ resultRecord.getStaffId() + "_" + resultRecord.getId();
- ch.qos.logback.classic.Logger.threadLocalNo.set(newNo);
- log.info("开始批量初始化流程,任务数量{}", resultStarts.size());
+ @Override
+ public void run() {
+ try {
+ log.info("开始批量初始化流程,任务数量{}", resultStarts.size());
+ String oldNo = Logger.inheritableThreadLocalNo.get();
+ for (StartStartDto startStartDto : resultStarts) {
+ try {
+ oldNo = Logger.inheritableThreadLocalNo.get();
+ String newNo = oldNo + "_initFlowRecord_" + startStartDto.getResultRecordList().get(0).getStartId();
+ Logger.threadLocalNo.set(newNo);
+ log.info("初始化任务中绩效数量{}", startStartDto.getResultRecordList().size());
+ for (ResultRecord resultRecord : startStartDto.getResultRecordList()) {
+ log.info("初始化绩效{}", resultRecord);
+ resultRecordService.initFlowRecord(resultRecord, startStartDto.getFlows(), startStartDto.getFlowApprovalRoles());
+ }
+ } catch (Exception e) {
+ log.error("发出异常", e);
+ } finally {
+ Logger.threadLocalNo.set(oldNo);
+ }
+ }
+ Logger.threadLocalNo.set(oldNo);
+ dingtalkBusiness.sendWorkMSGWithAsyn(noticeStaff, WorkMsgTypeEnum.START_WORK.getType());
+ } catch (Exception e) {
+ log.error("异常", e);
+ }
- for (StartStartDto startStartDto: resultStarts
- ) {
- log.info("初始化任务中绩效数量{}", startStartDto.getResultRecordList().size());
- for (ResultRecord resultRecord:startStartDto.getResultRecordList()
- ) {
- log.info("初始化绩效{}", resultRecord);
- resultRecordService.initFlowRecord(resultRecord, startStartDto.getFlows(), startStartDto.getFlowApprovalRoles());
- }
-
- }
-
-
- ch.qos.logback.classic.Logger.threadLocalNo.set(oldNo);
- dingtalkBusiness.sendWorkMSGWithAsyn(noticeStaff, WorkMsgTypeEnum.START_WORK.getType());
- }
- }
+ }
+ }
}
diff --git a/src/main/java/com/lz/modules/sys/service/app/impl/ResultRecordServiceImpl.java b/src/main/java/com/lz/modules/sys/service/app/impl/ResultRecordServiceImpl.java
index ab0ac8c8..4b7373b0 100644
--- a/src/main/java/com/lz/modules/sys/service/app/impl/ResultRecordServiceImpl.java
+++ b/src/main/java/com/lz/modules/sys/service/app/impl/ResultRecordServiceImpl.java
@@ -796,6 +796,7 @@ public class ResultRecordServiceImpl extends ServiceImpl flows, List flowApprovalRoles) {
+ log.info("员工id :" + resultRecord.getStaffId() + " ,员工名称 " + resultRecord.getStaffName());
int i = 0;
for (FlowApprovalRole flowApprovalRole : flowApprovalRoles) {
FlowRecord flowRecord = new FlowRecord();
@@ -817,14 +818,17 @@ public class ResultRecordServiceImpl extends ServiceImpl 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) { //如果是管理所有部门
+ log.info("如果是管理所有部门------");
insertFlowRecord(flowRecord, approvalStaff, flows, flowApprovalRole, resultRecord, i, 1);
} else {
+ log.info("222222222------");
DepartmentsStaffRelateEntity relateEntity = departmentsStaffRelateService.selectLastDepartmentByStaffId(resultRecord.getStaffId());
Map map = departmentsService.selectUserAllDepartmentIds(relateEntity.getDepartmentId());
List staffRoleDepartments = staffRoleDepartmentService.selectStaffRoleDepartmentByStaffRoleId(staffRole.getId());
@@ -837,6 +841,7 @@ public class ResultRecordServiceImpl extends ServiceImpl