初始代码

This commit is contained in:
wangmingwei
2026-04-21 16:49:46 +08:00
parent aae9dc4036
commit f0453ff3a3
2396 changed files with 256575 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>yunzhupaas-workflow-engine</artifactId>
<groupId>com.yunzhupaas</groupId>
<version>5.2.0-RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>yunzhupaas-workflow-engine-biz</artifactId>
<dependencies>
<dependency>
<groupId>com.yunzhupaas</groupId>
<artifactId>yunzhupaas-workflow-engine-entity</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.yunzhupaas</groupId>
<artifactId>yunzhupaas-provider</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.yunzhupaas</groupId>
<artifactId>yunzhupaas-system-biz</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.yunzhupaas</groupId>
<artifactId>yunzhupaas-permission-biz</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,16 @@
package com.yunzhupaas.engine.mapper;
import com.yunzhupaas.base.mapper.SuperMapper;
import com.yunzhupaas.engine.entity.FlowAuthorizeEntity;
/**
* 流程权限表
*
* @author 云筑产品开发平台组
* @version V3.1.0
* @copyright 深圳市乐程软件有限公司
*/
public interface FlowAuthorizeMapper extends SuperMapper<FlowAuthorizeEntity> {
}

View File

@@ -0,0 +1,16 @@
package com.yunzhupaas.engine.mapper;
import com.yunzhupaas.base.mapper.SuperMapper;
import com.yunzhupaas.engine.entity.FlowCandidatesEntity;
/**
* 流程候选人
*
* @author 云筑产品开发平台组
* @version V3.1.0
* @copyright 深圳市乐程软件有限公司
*/
public interface FlowCandidatesMapper extends SuperMapper<FlowCandidatesEntity> {
}

View File

@@ -0,0 +1,16 @@
package com.yunzhupaas.engine.mapper;
import com.yunzhupaas.base.mapper.SuperMapper;
import com.yunzhupaas.engine.entity.FlowCommentEntity;
/**
* 流程评论
*
* @author 云筑产品开发平台组
* @version V3.1.0
* @copyright 深圳市乐程软件有限公司
*/
public interface FlowCommentMapper extends SuperMapper<FlowCommentEntity> {
}

View File

@@ -0,0 +1,17 @@
package com.yunzhupaas.engine.mapper;
import com.yunzhupaas.base.mapper.SuperMapper;
import com.yunzhupaas.engine.entity.FlowDelegateEntity;
/**
* 流程委托
*
* @author 云筑产品开发平台组
* @version V3.1.0
* @copyright 深圳市乐程软件有限公司
* @date 2023/09/27
*/
public interface FlowDelegateMapper extends SuperMapper<FlowDelegateEntity> {
}

View File

@@ -0,0 +1,17 @@
package com.yunzhupaas.engine.mapper;
import com.yunzhupaas.base.mapper.SuperMapper;
import com.yunzhupaas.engine.entity.FlowEngineVisibleEntity;
/**
* 流程可见
*
* @author 云筑产品开发平台组
* @version V3.1.0
* @copyright 深圳市乐程软件有限公司
* @date 2023/09/27
*/
public interface FlowEngineVisibleMapper extends SuperMapper<FlowEngineVisibleEntity> {
}

View File

@@ -0,0 +1,16 @@
package com.yunzhupaas.engine.mapper;
import com.yunzhupaas.base.mapper.SuperMapper;
import com.yunzhupaas.engine.entity.FlowEventLogEntity;
/**
* 流程事件日志
*
* @author 云筑产品开发平台组
* @version V3.1.0
* @copyright 深圳市乐程软件有限公司
*/
public interface FlowEventLogMapper extends SuperMapper<FlowEventLogEntity> {
}

View File

@@ -0,0 +1,16 @@
package com.yunzhupaas.engine.mapper;
import com.yunzhupaas.base.mapper.SuperMapper;
import com.yunzhupaas.engine.entity.FlowOperatorUserEntity;
/**
* 流程依次审批
*
* @author 云筑产品开发平台组
* @version V3.1.0
* @copyright 深圳市乐程软件有限公司
*/
public interface FlowOperatorUserMapper extends SuperMapper<FlowOperatorUserEntity> {
}

View File

@@ -0,0 +1,17 @@
package com.yunzhupaas.engine.mapper;
import com.yunzhupaas.base.mapper.SuperMapper;
import com.yunzhupaas.engine.entity.FlowRejectDataEntity;
/**
* 冻结审批
*
* @author 云筑产品开发平台组
* @version V3.1.0
* @copyright 深圳市乐程软件有限公司
* @date 2023/09/27
*/
public interface FlowRejectDataMapper extends SuperMapper<FlowRejectDataEntity> {
}

View File

@@ -0,0 +1,17 @@
package com.yunzhupaas.engine.mapper;
import com.yunzhupaas.base.mapper.SuperMapper;
import com.yunzhupaas.engine.entity.FlowTaskCirculateEntity;
/**
* 流程传阅
*
* @author 云筑产品开发平台组
* @version V3.1.0
* @copyright 深圳市乐程软件有限公司
* @date 2023/09/27
*/
public interface FlowTaskCirculateMapper extends SuperMapper<FlowTaskCirculateEntity> {
}

View File

@@ -0,0 +1,42 @@
package com.yunzhupaas.engine.mapper;
import com.yunzhupaas.base.mapper.SuperMapper;
import com.yunzhupaas.engine.entity.FlowTaskEntity;
import com.yunzhupaas.engine.model.flowtask.FlowTaskListModel;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
/**
* 流程任务
*
* @author 云筑产品开发平台组
* @version V3.1.0
* @copyright 深圳市乐程软件有限公司
* @date 2023/09/27
*/
public interface FlowTaskMapper extends SuperMapper<FlowTaskEntity> {
/**
* 已办事宜
*
* @return
*/
List<FlowTaskListModel> getTrialList(@Param("map") Map<String, Object> map);
/**
* 抄送事宜
*
* @return
*/
List<FlowTaskListModel> getCirculateList(@Param("map") Map<String, Object> map);
/**
* 待办事宜
*
* @return
*/
List<FlowTaskListModel> getWaitList(@Param("map") Map<String, Object> map);
}

View File

@@ -0,0 +1,17 @@
package com.yunzhupaas.engine.mapper;
import com.yunzhupaas.base.mapper.SuperMapper;
import com.yunzhupaas.engine.entity.FlowTaskNodeEntity;
/**
* 流程节点
*
* @author 云筑产品开发平台组
* @version V3.1.0
* @copyright 深圳市乐程软件有限公司
* @date 2023/09/27
*/
public interface FlowTaskNodeMapper extends SuperMapper<FlowTaskNodeEntity> {
}

View File

@@ -0,0 +1,16 @@
package com.yunzhupaas.engine.mapper;
import com.yunzhupaas.base.mapper.SuperMapper;
import com.yunzhupaas.engine.entity.FlowTaskOperatorEntity;
/**
* 流程经办
*
* @author 云筑产品开发平台组
* @version V3.1.0
* @copyright 深圳市乐程软件有限公司
* @date 2023/09/27
*/
public interface FlowTaskOperatorMapper extends SuperMapper<FlowTaskOperatorEntity> {
}

View File

@@ -0,0 +1,17 @@
package com.yunzhupaas.engine.mapper;
import com.yunzhupaas.base.mapper.SuperMapper;
import com.yunzhupaas.engine.entity.FlowTaskOperatorRecordEntity;
/**
* 流程经办记录
*
* @author 云筑产品开发平台组
* @version V3.1.0
* @copyright 深圳市乐程软件有限公司
* @date 2023/09/27
*/
public interface FlowTaskOperatorRecordMapper extends SuperMapper<FlowTaskOperatorRecordEntity> {
}

View File

@@ -0,0 +1,17 @@
package com.yunzhupaas.engine.mapper;
import com.yunzhupaas.base.mapper.SuperMapper;
import com.yunzhupaas.engine.entity.FlowTemplateJsonEntity;
/**
* 流程引擎
*
* @author 云筑产品开发平台组
* @version V3.4.2
* @copyright 深圳市乐程软件有限公司
* @date 2024年7月11日 上午9:18
*/
public interface FlowTemplateJsonMapper extends SuperMapper<FlowTemplateJsonEntity> {
}

View File

@@ -0,0 +1,17 @@
package com.yunzhupaas.engine.mapper;
import com.yunzhupaas.base.mapper.SuperMapper;
import com.yunzhupaas.engine.entity.FlowTemplateEntity;
/**
* 流程引擎
*
* @author 云筑产品开发平台组
* @version V3.4.2
* @copyright 深圳市乐程软件有限公司
* @date 2024年7月11日 上午9:18
*/
public interface FlowTemplateMapper extends SuperMapper<FlowTemplateEntity> {
}

View File

@@ -0,0 +1,16 @@
package com.yunzhupaas.engine.mapper;
import com.yunzhupaas.base.mapper.SuperMapper;
import com.yunzhupaas.engine.entity.FlowUserEntity;
/**
* 流程发起用户信息
*
* @author 云筑产品开发平台组
* @version V3.1.0
* @copyright 深圳市乐程软件有限公司
*/
public interface FlowUserMapper extends SuperMapper<FlowUserEntity> {
}

View File

@@ -0,0 +1,34 @@
package com.yunzhupaas.engine.service;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.yunzhupaas.base.service.SuperService;
import com.yunzhupaas.engine.entity.FlowAuthorizeEntity;
import java.util.List;
/**
* 流程权限表
*
* @author 云筑产品开发平台组
* @version V3.1.0
* @copyright 深圳市乐程软件有限公司
*/
public interface FlowAuthorizeService extends SuperService<FlowAuthorizeEntity> {
/**
* 列表
*
* @return
*/
List<FlowAuthorizeEntity> getList(String taskId, String nodeCode, SFunction<FlowAuthorizeEntity, ?>... columns);
/**
* 创建
*
* @param list 实体对象
*/
void create(List<FlowAuthorizeEntity> list);
}

View File

@@ -0,0 +1,96 @@
package com.yunzhupaas.engine.service;
import com.yunzhupaas.base.service.SuperService;
import com.yunzhupaas.engine.entity.FlowCandidatesEntity;
import java.util.List;
/**
* 流程候选人
*
* @author 云筑产品开发平台组
* @version V3.1.0
* @copyright 深圳市乐程软件有限公司
*/
public interface FlowCandidatesService extends SuperService<FlowCandidatesEntity> {
/**
* 列表
*
* @param taskNodeId 节点主键
* @return
*/
List<FlowCandidatesEntity> getList(String taskNodeId);
/**
* 列表
*
* @param taskNodeId 节点主键
* @return
*/
List<FlowCandidatesEntity> getList(String taskId, String taskNodeId);
/**
* 信息
*
* @param id 主键值
* @return
*/
FlowCandidatesEntity getInfo(String id);
/**
* 创建
*
* @param entity 实体对象
*/
void create(FlowCandidatesEntity entity);
/**
* 创建
*
* @param list 实体对象
*/
void create(List<FlowCandidatesEntity> list);
/**
* 更新
*
* @param id 主键值
* @param entity 实体对象
* @return
*/
void update(String id, FlowCandidatesEntity entity);
/**
* 删除
*
* @param entity 实体对象
* @return
*/
void delete(FlowCandidatesEntity entity);
/**
* 删除
*
* @param taskId
*/
void deleteByTaskId(String taskId);
/**
* 拒绝删除候选人节点
*/
void deleteTaskNodeId(List<String> taskNodeId);
/**
* 撤回删除候选人
*
* @param taskOperatorId 经办主键
*/
void delete(List<String> taskOperatorId);
/**
* 撤回删除候选人节点
*/
void deleteTaskNodeId(List<String> taskNodeId, Integer type);
}

View File

@@ -0,0 +1,58 @@
package com.yunzhupaas.engine.service;
import com.yunzhupaas.base.service.SuperService;
import com.yunzhupaas.engine.entity.FlowCommentEntity;
import com.yunzhupaas.engine.model.flowcomment.FlowCommentPagination;
import java.util.List;
/**
* 流程评论
*
* @author 云筑产品开发平台组
* @version V3.1.0
* @copyright 深圳市乐程软件有限公司
*/
public interface FlowCommentService extends SuperService<FlowCommentEntity> {
/**
* 列表
*
* @param pagination 请求参数
* @return
*/
List<FlowCommentEntity> getlist(FlowCommentPagination pagination);
/**
* 信息
*
* @param id 主键值
* @return
*/
FlowCommentEntity getInfo(String id);
/**
* 创建
*
* @param entity 实体对象
*/
void create(FlowCommentEntity entity);
/**
* 更新
*
* @param id 主键值
* @param entity 实体对象
* @return
*/
void update(String id, FlowCommentEntity entity);
/**
* 删除
*
* @param entity 实体对象
* @return
*/
void delete(FlowCommentEntity entity);
}

View File

@@ -0,0 +1,125 @@
package com.yunzhupaas.engine.service;
import com.yunzhupaas.base.service.SuperService;
import com.yunzhupaas.base.vo.ListVO;
import com.yunzhupaas.engine.entity.FlowDelegateEntity;
import com.yunzhupaas.engine.model.flowcandidate.FlowCandidateUserModel;
import com.yunzhupaas.engine.model.flowdelegate.FlowDelegateCrForm;
import com.yunzhupaas.engine.model.flowdelegate.FlowDelegatePagination;
import com.yunzhupaas.engine.model.flowengine.FlowPagination;
import com.yunzhupaas.engine.model.flowtemplate.FlowPageListVO;
import com.yunzhupaas.exception.WorkFlowException;
import java.util.List;
/**
* 流程委托
*
* @author 云筑产品开发平台组
* @version V3.1.0
* @copyright 深圳市乐程软件有限公司
* @date 2023/09/27
*/
public interface FlowDelegateService extends SuperService<FlowDelegateEntity> {
/**
* 列表
*
* @param pagination 请求参数
* @return
*/
List<FlowDelegateEntity> getList(FlowDelegatePagination pagination);
/**
* 列表
*
* @return
*/
List<FlowDelegateEntity> getList();
/**
* 信息
*
* @param id 主键值
* @return
*/
FlowDelegateEntity getInfo(String id);
/**
* 删除
*
* @param entity 实体对象
*/
void delete(FlowDelegateEntity entity);
/**
* 创建
*
* @param entity 实体对象
*/
void create(FlowDelegateEntity entity);
/**
* 获取被委托人的表单
*
* @param touserId 被委托人
* @return
*/
List<FlowDelegateEntity> getUser(String touserId);
/**
* 获取委托的表单
*
* @param userId 委托人
* @param flowId 流程引擎
* @param touserId 被委托人
* @return
*/
List<FlowDelegateEntity> getUser(String userId, String flowId, String touserId);
/**
* 更新
*
* @param id 主键值
* @param entity 实体对象
* @return
*/
boolean update(String id, FlowDelegateEntity entity);
/**
* 委托结束
*
* @param id 主键值
* @param entity 实体对象
* @return
*/
boolean updateStop(String id, FlowDelegateEntity entity);
/**
* 获取我的委托发起
*
* @return
*/
List<FlowPageListVO> getflow(FlowPagination pagination);
/**
* 根据流程获取委托人列表。
*
* @param flowId 流程版本id
* @return
*/
ListVO<FlowCandidateUserModel> getUserListByFlowId(String flowId) throws WorkFlowException;
/**
* 根据条件查询相关委托信息
*
* @param
* @return
* @copyright 深圳市乐程软件有限公司
* @date 2024/10/28
*/
List<FlowDelegateEntity> selectSameParamAboutDelaget(FlowDelegateCrForm model);
}

View File

@@ -0,0 +1,41 @@
package com.yunzhupaas.engine.service;
import com.yunzhupaas.engine.enums.FlowStatusEnum;
import com.yunzhupaas.engine.model.flowengine.FlowModel;
import com.yunzhupaas.engine.model.flowengine.shuntjson.childnode.ChildNode;
import com.yunzhupaas.exception.WorkFlowException;
/**
* 在线开发工作流
*
* @author 云筑产品开发平台组
* @version V3.1.0
* @copyright 深圳市乐程软件有限公司
* @date 2024/3/15 9:19
*/
public interface FlowDynamicService {
/**
* 流程数据
*
* @param flowModel
*/
void flowTask(FlowModel flowModel, FlowStatusEnum flowStatus, ChildNode childNode) throws WorkFlowException;
/**
* 保存流程
*
* @param flowModel
* @throws WorkFlowException
*/
void createOrUpdate(FlowModel flowModel) throws WorkFlowException;
/**
* 批量保存流程
*
* @param flowModel
* @throws WorkFlowException
*/
void batchCreateOrUpdate(FlowModel flowModel) throws WorkFlowException;
}

View File

@@ -0,0 +1,60 @@
package com.yunzhupaas.engine.service;
import com.yunzhupaas.base.service.SuperService;
import com.yunzhupaas.engine.entity.FlowEngineVisibleEntity;
import com.yunzhupaas.engine.model.flowtask.FlowAssistModel;
import java.util.List;
/**
* 流程可见
*
* @author 云筑产品开发平台组
* @version V3.1.0
* @copyright 深圳市乐程软件有限公司
* @date 2023/09/27
*/
public interface FlowEngineVisibleService extends SuperService<FlowEngineVisibleEntity> {
/**
* 列表
*
* @param flowIdList 流程主键
* @return
*/
List<FlowEngineVisibleEntity> getList(List<String> flowIdList);
/**
* 列表
*
* @return
*/
List<FlowEngineVisibleEntity> getList();
/**
* 可见流程列表
*
* @param userId 用户主键
* @return
*/
List<FlowEngineVisibleEntity> getVisibleFlowList(String userId);
/**
* 可见流程列表
*
* @param userId 用户主键
* @return
*/
List<FlowEngineVisibleEntity> getVisibleFlowList(String userId, Integer type);
/**
* 删除流程可见
*/
void deleteVisible(String flowId);
/**
* 保存协管数据
*/
void assistList(FlowAssistModel assistModel);
}

View File

@@ -0,0 +1,33 @@
package com.yunzhupaas.engine.service;
import com.yunzhupaas.base.service.SuperService;
import com.yunzhupaas.engine.entity.FlowEventLogEntity;
import java.util.List;
/**
* 流程事件日志
*
* @author 云筑产品开发平台组
* @version V3.1.0
* @copyright 深圳市乐程软件有限公司
*/
public interface FlowEventLogService extends SuperService<FlowEventLogEntity> {
/**
* 创建
*
* @param entity 实体对象
*/
void create(FlowEventLogEntity entity);
/**
* 获取日志列表
*
* @param taskNodeId
* @return
*/
List<FlowEventLogEntity> getList(List<String> taskNodeId);
}

View File

@@ -0,0 +1,80 @@
package com.yunzhupaas.engine.service;
import com.yunzhupaas.base.service.SuperService;
import com.yunzhupaas.engine.entity.FlowOperatorUserEntity;
import java.util.List;
import java.util.Set;
/**
* 流程依次审批
*
* @author 云筑产品开发平台组
* @version V3.1.0
* @copyright 深圳市乐程软件有限公司
*/
public interface FlowOperatorUserService extends SuperService<FlowOperatorUserEntity> {
/**
* 列表
*
* @param taskId 流程实例Id
* @return
*/
List<FlowOperatorUserEntity> getList(String taskId);
/**
* 信息
*
* @param id 主键值
* @return
*/
FlowOperatorUserEntity getInfo(String id);
/**
* 获取
*
* @return
*/
List<FlowOperatorUserEntity> getTaskList(String taskId, String taskNodeId);
/**
* 创建
*
* @param list 实体对象
*/
void create(List<FlowOperatorUserEntity> list);
/**
* 更新
*
* @param id 主键值
* @param entity 实体对象
* @return
*/
void update(String id, FlowOperatorUserEntity entity);
/**
* 删除
*
* @param entity 实体对象
* @return
*/
void delete(FlowOperatorUserEntity entity);
/**
* 删除
*
* @param taskId
*/
void deleteByTaskId(String taskId);
/**
* 驳回的节点之后审批人删除
*
* @param taskId
* @param taskNodeId
*/
void updateReject(String taskId, Set<String> taskNodeId);
}

View File

@@ -0,0 +1,46 @@
package com.yunzhupaas.engine.service;
import com.yunzhupaas.base.service.SuperService;
import com.yunzhupaas.engine.entity.FlowRejectDataEntity;
/**
* 冻结审批
*
* @author 云筑产品开发平台组
* @version V3.1.0
* @copyright 深圳市乐程软件有限公司
* @date 2024-09-29 上午9:18
*/
public interface FlowRejectDataService extends SuperService<FlowRejectDataEntity> {
/**
* 新增
*
* @param rejectEntity
*/
void createOrUpdate(FlowRejectDataEntity rejectEntity);
/**
* 新增
*
* @param rejectEntity
*/
void create(FlowRejectDataEntity rejectEntity);
/**
* 更新
*
* @param rejectEntity
*/
void update(String id, FlowRejectDataEntity rejectEntity);
/**
* 获取信息
*
* @param id
* @return
*/
FlowRejectDataEntity getInfo(String id);
}

View File

@@ -0,0 +1,42 @@
package com.yunzhupaas.engine.service;
import com.yunzhupaas.base.service.SuperService;
import com.yunzhupaas.engine.entity.FlowTaskCirculateEntity;
import java.util.List;
/**
* 流程传阅
*
* @author 云筑产品开发平台组
* @version V3.1.0
* @copyright 深圳市乐程软件有限公司
* @date 2023/09/27
*/
public interface FlowTaskCirculateService extends SuperService<FlowTaskCirculateEntity> {
/**
* 删除根据实例Id
*
* @param taskId 任务主键
* @return
*/
void deleteByTaskId(String taskId);
/**
* 创建
*
* @param entitys 实体对象
* @return
*/
void create(List<FlowTaskCirculateEntity> entitys);
/**
* 获取列表
*
* @param taskId
* @return
*/
List<FlowTaskCirculateEntity> getList(String taskId);
}

View File

@@ -0,0 +1,276 @@
package com.yunzhupaas.engine.service;
import com.yunzhupaas.engine.entity.FlowTaskEntity;
import com.yunzhupaas.engine.entity.FlowTaskOperatorEntity;
import com.yunzhupaas.engine.entity.FlowTaskOperatorRecordEntity;
import com.yunzhupaas.engine.model.flowbefore.FlowBeforeInfoVO;
import com.yunzhupaas.engine.model.flowbefore.FlowSummary;
import com.yunzhupaas.engine.model.flowcandidate.FlowCandidateUserModel;
import com.yunzhupaas.engine.model.flowcandidate.FlowCandidateVO;
import com.yunzhupaas.engine.model.flowcandidate.FlowRejectVO;
import com.yunzhupaas.engine.model.flowengine.FlowModel;
import com.yunzhupaas.exception.WorkFlowException;
import java.util.List;
/**
* 流程引擎
*
* @author 云筑产品开发平台组
* @version V3.2.0
* @copyright 深圳市乐程软件有限公司
* @date 2024年4月27日 上午9:18
*/
public interface FlowTaskNewService {
/**
* 保存
*
* @param flowModel 保存数据
* @return
* @throws WorkFlowException 异常
*/
FlowTaskEntity saveIsAdmin(FlowModel flowModel) throws WorkFlowException;
/**
* 保存
*
* @param flowModel 保存数据
* @return
* @throws WorkFlowException 异常
*/
FlowTaskEntity save(FlowModel flowModel) throws WorkFlowException;
/**
* 提交
*
* @param flowModel 提交数据
* @throws WorkFlowException 异常
*/
void submit(FlowModel flowModel) throws WorkFlowException;
/**
* 提交包含事件和数据
*
* @param flowModel 提交数据
* @throws WorkFlowException
*/
void submitAll(FlowModel flowModel) throws WorkFlowException;
/**
* 审批
*
* @param flowTask 流程实例
* @param operator 流程经办
* @param flowModel 提交数据
* @throws WorkFlowException
*/
void audit(FlowTaskEntity flowTask, FlowTaskOperatorEntity operator, FlowModel flowModel) throws WorkFlowException;
/**
* 审批包含事件和数据
*
* @param flowTask 流程实例
* @param operator 流程经办
* @param flowModel 提交数据
* @throws WorkFlowException
*/
void auditAll(FlowTaskEntity flowTask, FlowTaskOperatorEntity operator, FlowModel flowModel) throws WorkFlowException;
/**
* 验证流程审批
*
* @param flowModel 提交数据
* @throws WorkFlowException
*/
void audit(FlowModel flowModel) throws WorkFlowException;
/**
* 驳回
*
* @param flowTask 流程实例
* @param operator 流程经办
* @param flowModel 提交数据
* @throws WorkFlowException
*/
void reject(FlowTaskEntity flowTask, FlowTaskOperatorEntity operator, FlowModel flowModel) throws WorkFlowException;
/**
* 驳回包含事件和数据
*
* @param flowTask 流程实例
* @param operator 流程经办
* @param flowModel 提交数据
* @throws WorkFlowException
*/
void rejectAll(FlowTaskEntity flowTask, FlowTaskOperatorEntity operator, FlowModel flowModel) throws WorkFlowException;
/**
* 验证流程审批
*
* @param flowModel 提交数据
* @throws WorkFlowException
*/
void reject(FlowModel flowModel) throws WorkFlowException;
/**
* 已办撤回
*
* @param id 已办id
* @param operatorRecord 经办记录
* @param flowModel 提交数据
* @throws WorkFlowException 异常
*/
void recall(String id, FlowTaskOperatorRecordEntity operatorRecord, FlowModel flowModel) throws WorkFlowException;
/**
* 发起撤回
*
* @param flowTask 流程实例
* @param flowModel 提交数据
*/
void revoke(FlowTaskEntity flowTask, FlowModel flowModel, boolean isParentId) throws WorkFlowException;
/**
* 发起撤回
*
* @param id 流程主键
* @param flowModel 提交数据
*/
void revoke(List<String> id, FlowModel flowModel, boolean isParentId) throws WorkFlowException;
/**
* 终止
*
* @param flowTask 流程实例
* @param flowModel 提交数据
*/
void cancel(FlowTaskEntity flowTask, FlowModel flowModel) throws WorkFlowException;
/**
* 终止
*
* @param flowModel 提交数据
*/
void cancel(List<String> id, FlowModel flowModel) throws WorkFlowException;
/**
* 指派
*
* @param id
* @param flowModel 提交数据
* @return
*/
void assign(String id, FlowModel flowModel) throws WorkFlowException;
/**
* 转办
*
* @param taskOperator 经办数据
*/
void transfer(FlowTaskOperatorEntity taskOperator, FlowModel flowModel) throws WorkFlowException;
/**
* 验证流程审批
*
* @param flowModel 提交数据
* @throws WorkFlowException
*/
void transfer(FlowModel flowModel) throws WorkFlowException;
/**
* 获取任务详情
*
* @return
* @throws WorkFlowException 异常
*/
FlowBeforeInfoVO getBeforeInfo(FlowModel flowModel) throws WorkFlowException;
/**
* 查询审批汇总
*
* @param id 主键
* @param category 类型(1.部门 2.角色 3.岗位)
* @param type 0.查询全部 1.查询通过和拒绝
* @return
*/
List<FlowSummary> recordList(String id, String category, String type);
/**
* 催办
*
* @param id 主键
* @return
* @throws WorkFlowException
*/
boolean press(String id, FlowModel flowModel) throws WorkFlowException;
/**
* 获取候选人节点
*
* @param id 主键
* @return
* @throws WorkFlowException
*/
FlowCandidateVO candidates(String id, FlowModel flowModel, boolean batch) throws WorkFlowException;
/**
* 获取候选人list
*
* @param id 主键
* @return
* @throws WorkFlowException
*/
List<FlowCandidateUserModel> candidateUser(String id, FlowModel flowModel) throws WorkFlowException;
/**
* 批量审批
*
* @throws WorkFlowException
*/
void batch(FlowModel flowModel) throws WorkFlowException;
/**
* 批量获取候选人节点
*
* @return
*/
FlowCandidateVO batchCandidates(String flowId, String taskOperatorId, FlowModel flowModel) throws WorkFlowException;
/**
* 判断操作权限
*
* @param userId
* @param flowTask
* @param operator
* @param msg
* @throws WorkFlowException
*/
void permissions(String userId, FlowTaskEntity flowTask, FlowTaskOperatorEntity operator, String msg, FlowModel flowModel) throws WorkFlowException;
/**
* 变更、复活节点
*
* @param flowModel
*/
void change(FlowModel flowModel) throws WorkFlowException;
/**
* 拒绝下拉框
*
* @param id
* @param batch
* @return
*/
FlowRejectVO rejectList(String id, boolean batch) throws WorkFlowException;
/**
* 流程挂起和恢复
*
* @param id
* @param flowModel
* @param isSuspend true 挂起 false 恢复
*/
void suspend(String id, FlowModel flowModel, boolean isSuspend);
}

View File

@@ -0,0 +1,111 @@
package com.yunzhupaas.engine.service;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.yunzhupaas.base.service.SuperService;
import com.yunzhupaas.engine.entity.FlowTaskNodeEntity;
import com.yunzhupaas.engine.model.flowtasknode.TaskNodeListModel;
import java.util.List;
/**
* 流程节点
*
* @author 云筑产品开发平台组
* @version V3.1.0
* @copyright 深圳市乐程软件有限公司
* @date 2023/09/27
*/
public interface FlowTaskNodeService extends SuperService<FlowTaskNodeEntity> {
/**
* 列表
*
* @param taskId 任务主键
* @return
*/
List<FlowTaskNodeEntity> getList(String taskId, SFunction<FlowTaskNodeEntity, ?>... columns);
/**
* 列表
*
* @param id 节点主键
* @return
*/
List<FlowTaskNodeEntity> getList(List<String> id, SFunction<FlowTaskNodeEntity, ?>... columns);
/**
* 列表
*
* @param nodeListModel
* @return
*/
List<FlowTaskNodeEntity> getList(TaskNodeListModel nodeListModel, SFunction<FlowTaskNodeEntity, ?>... columns);
/**
* 信息
*
* @param id 主键值
* @return
*/
FlowTaskNodeEntity getInfo(String id, SFunction<FlowTaskNodeEntity, ?>... columns);
/**
* 删除根据实例Id
*
* @param taskId 任务主键
*/
void deleteByTaskId(String taskId);
/**
* 创建
*
* @param entity 实体对象
*/
void create(FlowTaskNodeEntity entity);
/**
* 更新
*
* @param entity 实体对象
*/
void update(FlowTaskNodeEntity entity);
/**
* 更新驳回开始流程节点
*
* @param taskId 流程id
*/
void update(String taskId);
/**
* 修改节点的审批状态
*
* @param id 主键值
* @param start 状态
*/
void updateCompletion(List<String> id, int start);
/**
* 修改节点数据
*
* @param taskNodeLis
*/
void updateTaskNode(List<FlowTaskNodeEntity> taskNodeLis);
/**
* 修改节点的选择分支数据
*
* @param id
*/
void updateTaskNodeCandidates(List<String> id, String candidates);
/**
* 保存子流程任务id
*
* @param entity
*/
void updateTaskIdList(FlowTaskNodeEntity entity);
}

View File

@@ -0,0 +1,102 @@
package com.yunzhupaas.engine.service;
import com.yunzhupaas.base.service.SuperService;
import com.yunzhupaas.engine.entity.FlowTaskOperatorRecordEntity;
import java.util.List;
import java.util.Set;
/**
* 流程经办记录
*
* @author 云筑产品开发平台组
* @version V3.1.0
* @copyright 深圳市乐程软件有限公司
* @date 2023/09/27
*/
public interface FlowTaskOperatorRecordService extends SuperService<FlowTaskOperatorRecordEntity> {
/**
* 列表
*
* @param taskId 流程实例Id
* @return
*/
List<FlowTaskOperatorRecordEntity> getList(String taskId);
/**
* 消息汇总列表
*
* @param taskId 流程实例Id
* @param handleStatus 状态
* @return
*/
List<FlowTaskOperatorRecordEntity> getRecordList(String taskId, List<Integer> handleStatus);
/**
* 信息
*
* @param id 主键值
* @return
*/
FlowTaskOperatorRecordEntity getInfo(String id);
/**
* 删除
*
* @param entity 实体对象
* @return
*/
void delete(FlowTaskOperatorRecordEntity entity);
/**
* 创建
*
* @param entity 实体对象
* @return
*/
void create(FlowTaskOperatorRecordEntity entity);
/**
* 更新
*
* @param id 主键值
* @param entity 实体对象
*/
void update(String id, FlowTaskOperatorRecordEntity entity);
/**
* 驳回流转记录状态
*
* @param taskNodeId 流程id
* @param taskId 流程实例Id
*/
void updateStatus(Set<String> taskNodeId, String taskId);
/**
* 通过3个id查询记录
*
* @param taskId
* @param taskNodeId
* @param taskOperatorId
* @return
*/
FlowTaskOperatorRecordEntity getInfo(String taskId, String taskNodeId, String taskOperatorId);
/**
* 更新撤回经办记录
*
* @param idAll 经办id
*/
void updateStatus(List<String> idAll);
/**
* 更新驳回流程节点
*
* @param taskId 流程id
*/
void update(String taskId);
FlowTaskOperatorRecordEntity getIsCheck(String taskOperatorId, Integer status);
}

View File

@@ -0,0 +1,127 @@
package com.yunzhupaas.engine.service;
import com.yunzhupaas.base.service.SuperService;
import com.yunzhupaas.engine.entity.FlowTaskOperatorEntity;
import com.yunzhupaas.exception.WorkFlowException;
import java.util.List;
import java.util.Set;
/**
* 流程经办
*
* @author 云筑产品开发平台组
* @version V3.1.0
* @copyright 深圳市乐程软件有限公司
* @date 2023/09/27
*/
public interface FlowTaskOperatorService extends SuperService<FlowTaskOperatorEntity> {
/**
* 列表
*
* @param taskId 流程实例Id
* @return
*/
List<FlowTaskOperatorEntity> getList(String taskId);
/**
* 信息
*
* @param id 主键值
* @return
*/
FlowTaskOperatorEntity getInfo(String id) throws WorkFlowException;
/**
* 信息
*
* @param id 主键值
* @return
*/
FlowTaskOperatorEntity getOperatorInfo(String id);
/**
* 创建
*
* @param entitys 实体对象
*/
void create(List<FlowTaskOperatorEntity> entitys);
/**
* 更新
*
* @param entity 实体对象
*/
void update(FlowTaskOperatorEntity entity);
/**
* 更新会签委托人的审核状态
*
* @param taskNodeId 流程节点id
* @param userId 委托人id
* @param completion 审批状态
*/
void update(String taskNodeId, List<String> userId, String completion);
/**
* 更新流程经办审核状态
*
* @param taskNodeId 流程节点id
* @param type 流程类型
*/
void update(String taskNodeId, Integer type);
/**
* 更新驳回流程节点
*
* @param taskId 流程id
*/
void update(String taskId);
/**
* 经办未审核人员
*
* @param taskId 任务id
* @return
*/
List<FlowTaskOperatorEntity> press(String taskId);
/**
* 驳回的节点之后的节点作废
*
* @param taskId
* @param taskNodeId
*/
void updateReject(String taskId, Set<String> taskNodeId);
/**
* 删除经办id
*
* @param idAll 经办id
*/
void deleteList(List<String> idAll);
/**
* 查询加签人信息
*
* @param parentId 父节点Id
* @return
*/
List<FlowTaskOperatorEntity> getParentId(String parentId);
/**
* 更新经办记录作废
*
* @param idAll
*/
void updateTaskOperatorState(List<String> idAll);
/**
* 获取自己代办的流程任务
*
* @return
*/
List<FlowTaskOperatorEntity> getBatchList();
}

View File

@@ -0,0 +1,222 @@
package com.yunzhupaas.engine.service;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.yunzhupaas.base.service.SuperService;
import com.yunzhupaas.engine.entity.FlowTaskEntity;
import com.yunzhupaas.engine.model.flowbefore.FlowBatchModel;
import com.yunzhupaas.engine.model.flowtask.FlowTaskListModel;
import com.yunzhupaas.engine.model.flowtask.PaginationFlowTask;
import com.yunzhupaas.exception.WorkFlowException;
import com.yunzhupaas.model.FlowWorkListVO;
import com.yunzhupaas.permission.model.user.WorkHandoverModel;
import java.util.List;
/**
* 流程任务
*
* @author 云筑产品开发平台组
* @version V3.1.0
* @copyright 深圳市乐程软件有限公司
* @date 2023/09/27
*/
public interface FlowTaskService extends SuperService<FlowTaskEntity> {
/**
* 列表(流程监控)
*
* @param paginationFlowTask
* @return
*/
List<FlowTaskEntity> getMonitorList(PaginationFlowTask paginationFlowTask);
/**
* 列表(我发起的)
*
* @param paginationFlowTask
* @return
*/
List<FlowTaskEntity> getLaunchList(PaginationFlowTask paginationFlowTask);
/**
* 列表(待我审批)
* @param pagination
* @return
*/
List<FlowTaskListModel> getWaitList(PaginationFlowTask pagination);
/**
* 列表(抄送我的)
*
* @param pagination
* @return
*/
List<FlowTaskListModel> getCirculateList(PaginationFlowTask pagination);
/**
* 列表(我已审批)
*
* @param pagination
* @return
*/
List<FlowTaskListModel> getTrialList(PaginationFlowTask pagination);
/**
* 信息
*
* @param id 主键值
* @return
* @throws WorkFlowException 异常
*/
FlowTaskEntity getInfo(String id, SFunction<FlowTaskEntity, ?>... columns) throws WorkFlowException;
/**
* 更新
*
* @param entity 主键值
* @return
*/
void update(FlowTaskEntity entity);
/**
* 创建
*
* @param entity 主键值
* @return
*/
void create(FlowTaskEntity entity);
/**
* 创建或者修改
*
* @param entity 主键值
* @return
*/
void createOrUpdate(FlowTaskEntity entity);
/**
* 信息
*
* @param id 主键值
* @param columns 指定获取的列数据 , 任务中存了三个JSON数据 排除后可以提高查询速度
* @return
*/
FlowTaskEntity getInfoSubmit(String id, SFunction<FlowTaskEntity, ?>... columns);
/**
* 信息
*
* @param ids 主键值
* @param columns 指定获取的列数据 , 任务中存了三个JSON数据 排除后可以提高查询速度
* @return
*/
List<FlowTaskEntity> getInfosSubmit(String[] ids, SFunction<FlowTaskEntity, ?>... columns);
/**
* 删除
*
* @param entity 实体对象
* @throws WorkFlowException 异常
*/
void delete(FlowTaskEntity entity) throws WorkFlowException;
/**
* 递归删除所有字节点
*
* @param id
*/
void deleteChildAll(List<String> id);
/**
* 批量删除流程
*
* @param ids
*/
void delete(String[] ids) throws WorkFlowException;
/**
* 查询订单状态
*
* @param id
* @return
*/
List<FlowTaskEntity> getOrderStaList(List<String> id, SFunction<FlowTaskEntity, ?>... columns);
/**
* 查询子流程
*
* @param id
* @return
*/
List<FlowTaskEntity> getChildList(String id, SFunction<FlowTaskEntity, ?>... columns);
/**
* 查询子流程
*
* @param id
* @return
*/
List<FlowTaskEntity> getChildList(List<String> id, SFunction<FlowTaskEntity, ?>... columns);
/**
* 查询流程列表
*
* @param tempId
* @return
*/
List<FlowTaskEntity> getTemplateIdList(String tempId);
/**
* 查询流程列表
*
* @param flowId
* @return
*/
List<FlowTaskEntity> getFlowList(String flowId);
/**
* 批量审批引擎
*
* @return
*/
List<FlowBatchModel> batchFlowSelector();
/**
* 获取子节点下所有数据
*
* @param idList
* @param idAll
*/
void deleTaskAll(List<String> idList, List<String> idAll);
/**
* 获取所有子流程
*
* @param id
* @return
*/
List<String> getChildAllList(String id);
/**
* 获取子流程
*
* @param id
* @return
*/
void getChildList(String id, boolean suspend, List<String> list);
/**
* 流程交接
* @return
*/
FlowWorkListVO flowWork(String fromId);
/**
* 流程交接
* @return
*/
boolean flowWork(WorkHandoverModel workHandoverModel);
}

View File

@@ -0,0 +1,129 @@
package com.yunzhupaas.engine.service;
import com.yunzhupaas.base.service.SuperService;
import com.yunzhupaas.engine.entity.FlowTemplateJsonEntity;
import com.yunzhupaas.engine.model.flowengine.FlowPagination;
import com.yunzhupaas.engine.model.flowtemplate.FlowSelectVO;
import com.yunzhupaas.engine.model.flowtemplatejson.FlowTemplateJsonPage;
import com.yunzhupaas.exception.WorkFlowException;
import java.util.List;
/**
* 流程引擎
*
* @author 云筑产品开发平台组
* @version V3.4.2
* @copyright 深圳市乐程软件有限公司
* @date 2024年7月11日 上午9:18
*/
public interface FlowTemplateJsonService extends SuperService<FlowTemplateJsonEntity> {
/**
* 列表
*
* @return
*/
List<FlowTemplateJsonEntity> getTemplateList(List<String> id);
/**
* 列表
*
* @return
*/
List<FlowTemplateJsonEntity> getTemplateJsonList(List<String> id);
/**
* 分页列表
*
* @param page
* @return
*/
List<FlowTemplateJsonEntity> getListPage(FlowTemplateJsonPage page, boolean isPage);
/**
* 查询子流程
*
* @return
*/
List<FlowSelectVO> getChildListPage(FlowPagination page);
/**
* 获取主版本
*
* @param id
* @return
*/
List<FlowTemplateJsonEntity> getMainList(List<String> id);
/**
* 获取主版本
*
* @param id
* @return
*/
FlowTemplateJsonEntity getInfo(String id) throws WorkFlowException;
/**
* 获取主版本
*
* @param id
* @return
*/
FlowTemplateJsonEntity getJsonInfo(String id);
/**
* 创建
*
* @param entity 实体对象
*/
void create(FlowTemplateJsonEntity entity);
/**
* 更新
*
* @param id 主键值
* @param entity 实体对象
* @return
*/
void update(String id, FlowTemplateJsonEntity entity);
/**
* 删除
*
* @param entity
*/
void delete(FlowTemplateJsonEntity entity);
/**
* 查询主版本流程
*
* @return
*/
List<FlowTemplateJsonEntity> getListAll(List<String> id);
/**
* 设置主版本
*
* @param ids
*/
void templateJsonMajor(String ids) throws WorkFlowException;
/**
* 获取消息发送配置id
*
* @param engine
* @return
*/
List<String> sendMsgConfigList(FlowTemplateJsonEntity engine);
/**
* 修改流程引擎名称
*
* @param groupId
* @param fullName
*/
void updateFullName(String groupId, String fullName);
}

View File

@@ -0,0 +1,179 @@
package com.yunzhupaas.engine.service;
import com.yunzhupaas.base.service.SuperService;
import com.yunzhupaas.engine.entity.FlowTemplateEntity;
import com.yunzhupaas.engine.entity.FlowTemplateJsonEntity;
import com.yunzhupaas.engine.model.flowengine.FlowPagination;
import com.yunzhupaas.engine.model.flowtemplate.FlowExportModel;
import com.yunzhupaas.engine.model.flowtemplate.FlowTemplateInfoVO;
import com.yunzhupaas.engine.model.flowtemplate.FlowTemplateListVO;
import com.yunzhupaas.engine.model.flowtemplate.FlowTemplateVO;
import com.yunzhupaas.exception.WorkFlowException;
import java.util.List;
/**
* 流程引擎
*
* @author 云筑产品开发平台组
* @version V3.4.2
* @copyright 深圳市乐程软件有限公司
* @date 2024年7月11日 上午9:18
*/
public interface FlowTemplateService extends SuperService<FlowTemplateEntity> {
/**
* 分页列表
*
* @param pagination 分页
* @return
*/
List<FlowTemplateEntity> getPageList(FlowPagination pagination);
/**
* 信息
*
* @param id 主键值
* @return
* @throws WorkFlowException 异常
*/
FlowTemplateEntity getInfo(String id) throws WorkFlowException;
/**
* 验证名称
*
* @param fullName 名称
* @param id 主键值
* @return
*/
boolean isExistByFullName(String fullName, String id);
/**
* 验证编码
*
* @param enCode 编码
* @param id 主键值
* @return
*/
boolean isExistByEnCode(String enCode, String id);
/**
* 创建
*
* @param entity 实体对象
*/
void create(FlowTemplateEntity entity, List<FlowTemplateJsonEntity> templateJsonList) throws WorkFlowException;
/**
* 创建
*
* @param entity 实体对象
*/
void create(FlowTemplateEntity entity);
/**
* 获取流程信息
*
* @param id 主键值
* @return
*/
FlowTemplateInfoVO info(String id) throws WorkFlowException;
/**
* 更新
*
* @param id 主键值
* @param entity 实体对象
* @return
*/
FlowTemplateVO updateVisible(String id, FlowTemplateEntity entity, List<FlowTemplateJsonEntity> templateJsonList) throws WorkFlowException;
/**
* 更新
*
* @param id 主键值
* @param entity 实体对象
* @return
*/
boolean update(String id, FlowTemplateEntity entity) throws WorkFlowException;
/**
* 复制
*
* @param entity 实体对象
*/
void copy(FlowTemplateEntity entity, List<FlowTemplateJsonEntity> templateJsonEntity) throws WorkFlowException;
/**
* 删除
*/
void delete(FlowTemplateEntity entity) throws WorkFlowException;
/**
* 导入创建
*
* @param id 导出主键
*/
FlowExportModel exportData(String id) throws WorkFlowException;
/**
* 工作流导入
*
* @return
* @throws WorkFlowException
*/
void ImportData(FlowExportModel flowExportModel, String type) throws WorkFlowException;
/**
* 流程设计列表
*
* @return
*/
List<FlowTemplateListVO> getSelectList();
/**
* 所属流程树形
*
* @return
*/
List<FlowTemplateListVO> getTreeList();
/**
* 查询引擎
*
* @param id 主键值
* @return
*/
List<FlowTemplateEntity> getTemplateList(List<String> id);
/**
* 信息
*
* @param code 主键值
* @return
* @throws WorkFlowException 异常
*/
FlowTemplateEntity getFlowIdByCode(String code) throws WorkFlowException;
/**
* 列表
*
* @param pagination 分页对象
* @param isPage 是否分页
* @return
*/
List<FlowTemplateEntity> getListAll(FlowPagination pagination, boolean isPage);
/**
* 列表
* 当isAll为true时可查询全部。为false不可查询全部。
*
* @param pagination 分页对象
* @param listAll 是否查询列表
* @return
*/
List<FlowTemplateEntity> getListByFlowIds(FlowPagination pagination, List<String> listAll, Boolean isAll, Boolean isPage, String userId);
void saveLogicFlowAndForm(String id);
}

View File

@@ -0,0 +1,62 @@
package com.yunzhupaas.engine.service;
import com.yunzhupaas.base.service.SuperService;
import com.yunzhupaas.engine.entity.FlowUserEntity;
/**
* 流程发起用户信息
*
* @author 云筑产品开发平台组
* @version V3.1.0
* @copyright 深圳市乐程软件有限公司
*/
public interface FlowUserService extends SuperService<FlowUserEntity> {
/**
* 信息
*
* @param id 主键值
* @return
*/
FlowUserEntity getInfo(String id);
/**
* 信息
*
* @param id 主键值
* @return
*/
FlowUserEntity getTaskInfo(String id);
/**
* 创建
*
* @param entity 实体对象
*/
void create(FlowUserEntity entity);
/**
* 更新
*
* @param id 主键值
* @param entity 实体对象
* @return
*/
void update(String id, FlowUserEntity entity);
/**
* 删除
*
* @param entity 实体对象
* @return
*/
void delete(FlowUserEntity entity);
/**
* 删除
*
* @param taskId
*/
void deleteByTaskId(String taskId);
}

View File

@@ -0,0 +1,44 @@
package com.yunzhupaas.engine.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.yunzhupaas.base.service.SuperServiceImpl;
import com.yunzhupaas.engine.entity.FlowAuthorizeEntity;
import com.yunzhupaas.engine.mapper.FlowAuthorizeMapper;
import com.yunzhupaas.engine.service.FlowAuthorizeService;
import com.yunzhupaas.util.RandomUtil;
import com.yunzhupaas.util.StringUtil;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 流程权限表
*
* @author 云筑产品开发平台组
* @version V3.1.0
* @copyright 深圳市乐程软件有限公司
*/
@Service
public class FlowAuthorizeServiceImpl extends SuperServiceImpl<FlowAuthorizeMapper, FlowAuthorizeEntity> implements FlowAuthorizeService {
@Override
public List<FlowAuthorizeEntity> getList(String taskId, String nodeCode, SFunction<FlowAuthorizeEntity, ?>... columns) {
QueryWrapper<FlowAuthorizeEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(FlowAuthorizeEntity::getTaskId, taskId);
if (StringUtil.isNotEmpty(nodeCode)) {
queryWrapper.lambda().eq(FlowAuthorizeEntity::getNodeCode, nodeCode);
}
queryWrapper.lambda().select(columns);
return this.list(queryWrapper);
}
@Override
public void create(List<FlowAuthorizeEntity> list) {
for (FlowAuthorizeEntity entity : list) {
entity.setId(RandomUtil.uuId());
this.save(entity);
}
}
}

View File

@@ -0,0 +1,110 @@
package com.yunzhupaas.engine.service.impl;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yunzhupaas.base.service.SuperServiceImpl;
import com.yunzhupaas.engine.entity.FlowCandidatesEntity;
import com.yunzhupaas.engine.mapper.FlowCandidatesMapper;
import com.yunzhupaas.engine.service.FlowCandidatesService;
import com.yunzhupaas.util.RandomUtil;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 流程候选人
*
* @author 云筑产品开发平台组
* @version V3.1.0
* @copyright 深圳市乐程软件有限公司
*/
@Service
public class FlowCandidatesServiceImpl extends SuperServiceImpl<FlowCandidatesMapper, FlowCandidatesEntity> implements FlowCandidatesService {
@Override
public List<FlowCandidatesEntity> getList(String taskNodeId) {
return getList(null, taskNodeId);
}
@Override
public List<FlowCandidatesEntity> getList(String taskId, String taskNodeId) {
QueryWrapper<FlowCandidatesEntity> queryWrapper = new QueryWrapper<>();
if (ObjectUtil.isNotEmpty(taskId)) {
queryWrapper.lambda().eq(FlowCandidatesEntity::getTaskId, taskId);
}
if (ObjectUtil.isNotEmpty(taskNodeId)) {
queryWrapper.lambda().eq(FlowCandidatesEntity::getTaskNodeId, taskNodeId);
}
return this.list(queryWrapper);
}
@Override
public FlowCandidatesEntity getInfo(String id) {
QueryWrapper<FlowCandidatesEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(FlowCandidatesEntity::getId, id);
return this.getOne(queryWrapper);
}
@Override
public void create(FlowCandidatesEntity entity) {
entity.setId(RandomUtil.uuId());
this.save(entity);
}
@Override
public void create(List<FlowCandidatesEntity> list) {
for (FlowCandidatesEntity entity : list) {
entity.setId(RandomUtil.uuId());
this.save(entity);
}
}
@Override
public void update(String id, FlowCandidatesEntity entity) {
entity.setId(id);
this.updateById(entity);
}
@Override
public void delete(FlowCandidatesEntity entity) {
if (entity != null) {
this.removeById(entity.getId());
}
}
@Override
public void deleteByTaskId(String taskId) {
QueryWrapper<FlowCandidatesEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(FlowCandidatesEntity::getTaskId, taskId);
this.remove(queryWrapper);
}
@Override
public void deleteTaskNodeId(List<String> taskNodeId) {
if (taskNodeId.size() > 0) {
QueryWrapper<FlowCandidatesEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().in(FlowCandidatesEntity::getTaskNodeId, taskNodeId);
this.remove(queryWrapper);
}
}
@Override
public void delete(List<String> taskOperatorId) {
if (taskOperatorId.size() > 0) {
QueryWrapper<FlowCandidatesEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().in(FlowCandidatesEntity::getOperatorId, taskOperatorId);
this.remove(queryWrapper);
}
}
@Override
public void deleteTaskNodeId(List<String> taskNodeId, Integer type) {
if (taskNodeId.size() > 0) {
QueryWrapper<FlowCandidatesEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().in(FlowCandidatesEntity::getTaskNodeId, taskNodeId);
queryWrapper.lambda().eq(FlowCandidatesEntity::getType, type);
this.remove(queryWrapper);
}
}
}

View File

@@ -0,0 +1,70 @@
package com.yunzhupaas.engine.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yunzhupaas.base.service.SuperServiceImpl;
import com.yunzhupaas.engine.entity.FlowCommentEntity;
import com.yunzhupaas.engine.mapper.FlowCommentMapper;
import com.yunzhupaas.engine.model.flowcomment.FlowCommentPagination;
import com.yunzhupaas.engine.service.FlowCommentService;
import com.yunzhupaas.util.RandomUtil;
import com.yunzhupaas.util.UserProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
/**
* 流程评论
*
* @author 云筑产品开发平台组
* @version V3.1.0
* @copyright 深圳市乐程软件有限公司
*/
@Service
public class FlowCommentServiceImpl extends SuperServiceImpl<FlowCommentMapper, FlowCommentEntity> implements FlowCommentService {
@Override
public List<FlowCommentEntity> getlist(FlowCommentPagination pagination) {
QueryWrapper<FlowCommentEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(FlowCommentEntity::getTaskId, pagination.getTaskId());
queryWrapper.lambda().isNull(FlowCommentEntity::getDeleteMark);
queryWrapper.lambda().orderByDesc(FlowCommentEntity::getCreatorTime);
Page<FlowCommentEntity> page = new Page<>(pagination.getCurrentPage(), pagination.getPageSize());
IPage<FlowCommentEntity> userIPage = this.page(page, queryWrapper);
return pagination.setData(userIPage.getRecords(), page.getTotal());
}
@Override
public FlowCommentEntity getInfo(String id) {
QueryWrapper<FlowCommentEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(FlowCommentEntity::getId, id);
return this.getOne(queryWrapper);
}
@Override
public void create(FlowCommentEntity entity) {
entity.setCreatorTime(new Date());
entity.setCreatorUserId(UserProvider.getUser().getUserId());
entity.setId(RandomUtil.uuId());
this.save(entity);
}
@Override
public void update(String id, FlowCommentEntity entity) {
entity.setId(id);
this.updateById(entity);
}
@Override
public void delete(FlowCommentEntity entity) {
if (entity != null) {
this.removeById(entity.getId());
}
}
}

View File

@@ -0,0 +1,335 @@
package com.yunzhupaas.engine.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.ImmutableList;
import com.yunzhupaas.base.UserInfo;
import com.yunzhupaas.base.service.SuperServiceImpl;
import com.yunzhupaas.base.vo.ListVO;
import com.yunzhupaas.constant.MsgCode;
import com.yunzhupaas.constant.PermissionConst;
import com.yunzhupaas.engine.entity.FlowDelegateEntity;
import com.yunzhupaas.engine.entity.FlowEngineVisibleEntity;
import com.yunzhupaas.engine.entity.FlowTemplateEntity;
import com.yunzhupaas.engine.entity.FlowTemplateJsonEntity;
import com.yunzhupaas.engine.mapper.FlowDelegateMapper;
import com.yunzhupaas.engine.model.flowcandidate.FlowCandidateUserModel;
import com.yunzhupaas.engine.model.flowdelegate.FlowDelegateCrForm;
import com.yunzhupaas.engine.model.flowdelegate.FlowDelegateModel;
import com.yunzhupaas.engine.model.flowdelegate.FlowDelegatePagination;
import com.yunzhupaas.engine.model.flowengine.FlowPagination;
import com.yunzhupaas.engine.model.flowtemplate.FlowPageListVO;
import com.yunzhupaas.engine.service.FlowDelegateService;
import com.yunzhupaas.engine.service.FlowEngineVisibleService;
import com.yunzhupaas.engine.service.FlowTemplateJsonService;
import com.yunzhupaas.engine.service.FlowTemplateService;
import com.yunzhupaas.engine.util.FlowMsgUtil;
import com.yunzhupaas.engine.util.FlowNature;
import com.yunzhupaas.exception.WorkFlowException;
import com.yunzhupaas.permission.entity.OrganizeEntity;
import com.yunzhupaas.permission.entity.UserEntity;
import com.yunzhupaas.permission.entity.UserRelationEntity;
import com.yunzhupaas.util.*;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.stream.Collectors;
/**
* 流程委托
*
* @author 云筑产品开发平台组
* @version V3.1.0
* @copyright 深圳市乐程软件有限公司
* @date 2023/09/27
*/
@Service
public class FlowDelegateServiceImpl extends SuperServiceImpl<FlowDelegateMapper, FlowDelegateEntity> implements FlowDelegateService {
@Autowired
private ServiceAllUtil serviceUtil;
@Autowired
private FlowMsgUtil flowMsgUtil;
@Autowired
private FlowTemplateService flowTemplateService;
@Autowired
private FlowTemplateJsonService flowTemplateJsonService;
@Autowired
private FlowEngineVisibleService flowEngineVisibleService;
@Override
public List<FlowDelegateEntity> getList(FlowDelegatePagination pagination) {
// 定义变量判断是否需要使用修改时间倒序
boolean flag = false;
String userId = UserProvider.getUser().getUserId();
QueryWrapper<FlowDelegateEntity> queryWrapper = new QueryWrapper<>();
if ("2".equals(pagination.getMyOrDelagateToMe())) {//MyOrDelagateToMe=2查询委托给我的列表
queryWrapper.lambda().eq(FlowDelegateEntity::getToUserId, userId);
} else {
// if (!UserProvider.getUser().getIsAdministrator()) {//非超管
// List<UserByRoleVO> list = serviceUtil.getListByAuthorize("0");
// if (CollectionUtils.isNotEmpty(list)) {//是分管
// List<String> userIds = new ArrayList<>();
// for (UserByRoleVO item : list) {
// List<UserByRoleVO> listByAuthorize = serviceUtil.getListByAuthorize(item.getId());
// userIds.addAll(listByAuthorize.stream().map(UserByRoleVO::getId).collect(Collectors.toList()));
// }
// queryWrapper.lambda().and(
// t -> t.eq(FlowDelegateEntity::getUserId, userId))
// .or().in(FlowDelegateEntity::getUserId, userIds);
// } else {
// queryWrapper.lambda().eq(FlowDelegateEntity::getUserId, userId);
// }
// }
queryWrapper.lambda().eq(FlowDelegateEntity::getUserId, userId);
}
if (!StringUtils.isEmpty(pagination.getKeyword())) {
flag = true;
if ("1".equals(pagination.getMyOrDelagateToMe())) {
queryWrapper.lambda().and(
t -> t.like(FlowDelegateEntity::getFlowName, pagination.getKeyword())
.or().like(FlowDelegateEntity::getToUserName, pagination.getKeyword())
);
} else {
queryWrapper.lambda().and(
t -> t.like(FlowDelegateEntity::getFlowName, pagination.getKeyword())
.or().like(FlowDelegateEntity::getUserName, pagination.getKeyword())
);
}
}
//排序
queryWrapper.lambda().orderByAsc(FlowDelegateEntity::getSortCode).orderByDesc(FlowDelegateEntity::getCreatorTime);
if (flag) {
queryWrapper.lambda().orderByDesc(FlowDelegateEntity::getLastModifyTime);
}
Page page = new Page(pagination.getCurrentPage(), pagination.getPageSize());
IPage<FlowDelegateEntity> flowDelegateEntityPage = this.page(page, queryWrapper);
return pagination.setData(flowDelegateEntityPage.getRecords(), page.getTotal());
}
@Override
public List<FlowDelegateEntity> getList() {
String userId = UserProvider.getUser().getUserId();
QueryWrapper<FlowDelegateEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().and(
t -> t.eq(FlowDelegateEntity::getCreatorUserId, userId)
.or().eq(FlowDelegateEntity::getUserId, userId));
return this.baseMapper.selectList(queryWrapper);
}
@Override
public FlowDelegateEntity getInfo(String id) {
QueryWrapper<FlowDelegateEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(FlowDelegateEntity::getId, id);
return this.getOne(queryWrapper);
}
@Override
public void delete(FlowDelegateEntity entity) {
this.removeById(entity.getId());
}
@Override
public void create(FlowDelegateEntity entity) {
UserInfo userInfo = UserProvider.getUser();
entity.setId(RandomUtil.uuId());
entity.setSortCode(RandomUtil.parses());
entity.setCreatorUserId(userInfo.getUserId());
FlowDelegateModel delegate = new FlowDelegateModel();
delegate.setToUserIds(ImmutableList.of(entity.getToUserId()));
delegate.setType(entity.getType());
delegate.setUserInfo(userInfo);
flowMsgUtil.delegateMsg(delegate);
this.save(entity);
}
@Override
public List<FlowDelegateEntity> getUser(String touserId) {
return getUser(null, null, touserId);
}
@Override
public List<FlowDelegateEntity> getUser(String userId, String flowId, String touserId) {
Date thisTime = DateUtil.getNowDate();
QueryWrapper<FlowDelegateEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(FlowDelegateEntity::getType, 1);
queryWrapper.lambda().le(FlowDelegateEntity::getStartTime, thisTime).ge(FlowDelegateEntity::getEndTime, thisTime);
if (StringUtil.isNotEmpty(userId)) {
queryWrapper.lambda().eq(FlowDelegateEntity::getUserId, userId);
}
if (StringUtil.isNotEmpty(touserId)) {
queryWrapper.lambda().eq(FlowDelegateEntity::getToUserId, touserId);
}
List<FlowDelegateEntity> list = this.list(queryWrapper);
List<FlowDelegateEntity> listRes = new ArrayList<>();
if (StringUtil.isNotEmpty(flowId)) {
for (FlowDelegateEntity item : list) {
if (StringUtil.isNotEmpty(item.getFlowId())) {
String[] split = item.getFlowId().split(",");
if (Arrays.asList(split).contains(flowId)) {
listRes.add(item);
}
} else {//为空是全部流程
listRes.add(item);
}
}
} else {
listRes = list;
}
return listRes;
}
@Override
public boolean update(String id, FlowDelegateEntity entity) {
UserInfo userInfo = UserProvider.getUser();
entity.setId(id);
entity.setLastModifyTime(new Date());
entity.setLastModifyUserId(userInfo.getUserId());
FlowDelegateModel delegate = new FlowDelegateModel();
delegate.setToUserIds(ImmutableList.of(entity.getToUserId()));
delegate.setType(entity.getType());
delegate.setUserInfo(userInfo);
flowMsgUtil.delegateMsg(delegate);
return this.updateById(entity);
}
@Override
public boolean updateStop(String id, FlowDelegateEntity entity) {
UserInfo userInfo = UserProvider.getUser();
entity.setId(id);
entity.setLastModifyTime(new Date());
entity.setLastModifyUserId(userInfo.getUserId());
FlowDelegateModel delegate = new FlowDelegateModel();
delegate.setToUserIds(ImmutableList.of(entity.getToUserId()));
delegate.setType(FlowNature.EndMsg);
delegate.setUserInfo(userInfo);
flowMsgUtil.delegateMsg(delegate);
return this.updateById(entity);
}
@Override
public List<FlowPageListVO> getflow(FlowPagination pagination) {
List<FlowDelegateEntity> list = getLaunchDelagateList();
if (CollectionUtils.isEmpty(list)) {
return new ArrayList<>();
}
// List<String> listFlow = new ArrayList<>();
// for (FlowDelegateEntity item : list) {
// if (StringUtil.isNotEmpty(item.getFlowId())) {
// listFlow.addAll(
// flowTemplateService.getListByFlowIds(pagination, Arrays.asList(item.getFlowId().split(",")), false, false, item.getUserId())
// .stream().map(FlowTemplateEntity::getId).collect(Collectors.toList()));
// } else {
// listFlow.addAll(flowTemplateService.getListByFlowIds(pagination, null, true, false, item.getUserId())
// .stream().map(FlowTemplateEntity::getId).collect(Collectors.toList()));
// }
// }
// List<FlowTemplateEntity> listReslut = flowTemplateService.getListByFlowIds(pagination, listFlow, false, false, null);
List<String> templateIdList = new ArrayList<>();
int num = 0;
for (FlowDelegateEntity item : list) {
if (StringUtil.isNotEmpty(item.getFlowId())) {
templateIdList.addAll(Arrays.asList(item.getFlowId().split(",")));
}
num += StringUtil.isEmpty(item.getFlowId()) ? 1 : 0;
}
if (num == 0) {
pagination.setTemplateIdList(templateIdList);
}
List<FlowTemplateEntity> dataList = flowTemplateService.getListAll(pagination, true);
List<FlowPageListVO> listVO = JsonUtil.getJsonToList(dataList, FlowPageListVO.class);
return listVO;
}
@Override
public ListVO<FlowCandidateUserModel> getUserListByFlowId(String flowId) throws WorkFlowException {
FlowTemplateJsonEntity info = flowTemplateJsonService.getInfo(flowId);
String templateId = info.getTemplateId();
List<FlowDelegateEntity> list = getLaunchDelagateList();
Set<UserEntity> userName = new HashSet<>();
for (FlowDelegateEntity item : list) {
//用户可见列表
UserEntity userInfo = serviceUtil.getUserInfo(item.getUserId());
boolean visibleType = "1".equals(userInfo.getIsAdministrator());
List<String> listVisible = null;
if (!visibleType) {
List<String> id = flowEngineVisibleService.getVisibleFlowList(userInfo.getId()).stream().map(FlowEngineVisibleEntity::getFlowId).collect(Collectors.toList());
//可见列表
listVisible = flowTemplateJsonService.getListAll(id).stream().map(FlowTemplateJsonEntity::getTemplateId).collect(Collectors.toList());
}
//判断委托人是否有发起权限
if (StringUtil.isNotEmpty(item.getFlowId())) {
List<String> strings = Arrays.asList(item.getFlowId().split(","));
if (strings.contains(templateId) && listVisible.contains(templateId)) {
userName.add(userInfo);
}
} else {
if (listVisible.contains(templateId)) {
userName.add(userInfo);
}
}
}
List<String> userIdAll = userName.stream().map(UserEntity::getId).collect(Collectors.toList());
Map<String, List<UserRelationEntity>> userMap = serviceUtil.getListByUserIdAll(userIdAll).stream().filter(t -> PermissionConst.ORGANIZE.equals(t.getObjectType())).collect(Collectors.groupingBy(UserRelationEntity::getUserId));
List<FlowCandidateUserModel> jsonToList = new ArrayList<>();
for (UserEntity entity : userName) {
List<UserRelationEntity> listByUserId = userMap.get(entity.getId()) != null ? userMap.get(entity.getId()) : new ArrayList<>();
StringJoiner joiner = new StringJoiner(",");
for (UserRelationEntity relation : listByUserId) {
List<OrganizeEntity> organizeId = serviceUtil.getOrganizeId(relation.getObjectId());
if (organizeId.size() > 0) {
String organizeName = organizeId.stream().map(OrganizeEntity::getFullName).collect(Collectors.joining("/"));
joiner.add(organizeName);
}
}
FlowCandidateUserModel vo = JsonUtil.getJsonToBean(entity, FlowCandidateUserModel.class);
vo.setFullName(entity.getRealName() + "/" + entity.getAccount());
vo.setHeadIcon(UploaderUtil.uploaderImg(entity.getHeadIcon()));
vo.setOrganize(joiner.toString());
jsonToList.add(vo);
}
if (jsonToList.size() == 0) {
throw new WorkFlowException(MsgCode.WF029.get());
}
ListVO<FlowCandidateUserModel> vo = new ListVO<>();
vo.setList(jsonToList);
return vo;
}
/**
* 获取当前用户所有发起委托列表
*
* @param
* @return
* @copyright 深圳市乐程软件有限公司
* @date 2024/10/17
*/
private List<FlowDelegateEntity> getLaunchDelagateList() {
String userId = UserProvider.getUser().getUserId();
Date thisTime = DateUtil.getNowDate();
QueryWrapper<FlowDelegateEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(FlowDelegateEntity::getToUserId, userId);
queryWrapper.lambda().le(FlowDelegateEntity::getStartTime, thisTime).ge(FlowDelegateEntity::getEndTime, thisTime);
queryWrapper.lambda().like(FlowDelegateEntity::getType, 0);
List<FlowDelegateEntity> list = this.baseMapper.selectList(queryWrapper);//全部发起委托
return list;
}
@Override
public List<FlowDelegateEntity> selectSameParamAboutDelaget(FlowDelegateCrForm model) {
QueryWrapper<FlowDelegateEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(FlowDelegateEntity::getUserId, model.getUserId());
queryWrapper.lambda().eq(FlowDelegateEntity::getToUserId, model.getToUserId());
queryWrapper.lambda().eq(FlowDelegateEntity::getType, model.getType());
queryWrapper.lambda().gt(FlowDelegateEntity::getEndTime, new Date());
List<FlowDelegateEntity> list = this.list(queryWrapper);
return list;
}
}

View File

@@ -0,0 +1,116 @@
package com.yunzhupaas.engine.service.impl;
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
import com.yunzhupaas.base.UserInfo;
import com.yunzhupaas.engine.entity.FlowTemplateEntity;
import com.yunzhupaas.engine.entity.FlowTemplateJsonEntity;
import com.yunzhupaas.engine.enums.FlowStatusEnum;
import com.yunzhupaas.engine.model.flowbefore.FlowTemplateAllModel;
import com.yunzhupaas.engine.model.flowengine.FlowModel;
import com.yunzhupaas.engine.model.flowengine.shuntjson.childnode.ChildNode;
import com.yunzhupaas.engine.service.FlowDynamicService;
import com.yunzhupaas.engine.service.FlowTaskNewService;
import com.yunzhupaas.engine.util.FlowContextHolder;
import com.yunzhupaas.engine.util.FlowTaskUtil;
import com.yunzhupaas.exception.WorkFlowException;
import com.yunzhupaas.base.model.flow.FlowFormDataModel;
import com.yunzhupaas.permission.entity.UserEntity;
import com.yunzhupaas.util.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
/**
* 在线开发工作流
*
* @author 云筑产品开发平台组
* @version V3.1.0
* @copyright 深圳市乐程软件有限公司
* @date 2024/3/15 9:19
*/
@Slf4j
@Service
public class FlowDynamicServiceImpl implements FlowDynamicService {
@Autowired
public ServiceAllUtil serviceUtil;
@Autowired
private FlowTaskUtil flowTaskUtil;
@Autowired
private FlowTaskNewService flowTaskNewService;
@Override
public void flowTask(FlowModel flowModel, FlowStatusEnum flowStatus, ChildNode childNode) throws WorkFlowException {
Map<String, Object> formData = flowModel.getFormData();
String id = flowModel.getProcessId();
Map<String, Object> map = flowModel.getFormData();
formData.put(FlowFormConstant.FLOWID, flowModel.getFlowId());
String formId = childNode.getProperties().getFormId();
List<Map<String, Object>> formOperates = childNode.getProperties().getFormOperates();
FlowFormDataModel formDataModel = FlowFormDataModel.builder().
formId(formId).id(id).delegateUser(serviceUtil.getUserInfo(flowModel.getUserId())).
map(map).formOperates(formOperates).build();
switch (flowStatus) {
case save:
flowTaskNewService.save(flowModel);
serviceUtil.createOrUpdate(formDataModel);
break;
case submit:
FlowContextHolder.addData(formId, formData);
FlowContextHolder.addChildData(id, formId, formData);
FlowContextHolder.addFormOperates(id, formId, formOperates);
flowTaskNewService.submitAll(flowModel);
break;
case none:
serviceUtil.createOrUpdate(formDataModel);
break;
default:
break;
}
}
@Override
public void createOrUpdate(FlowModel flowModel) throws WorkFlowException {
FlowTemplateAllModel model = flowTaskUtil.templateJson(flowModel.getFlowId());
FlowTemplateJsonEntity templateJson = model.getTemplateJson();
FlowTemplateEntity template = model.getTemplate();
ChildNode childNode = JsonUtil.getJsonToBean(templateJson.getFlowTemplateJson(), ChildNode.class);
FlowStatusEnum statusEnum = FlowStatusEnum.submit.getMessage().equals(flowModel.getStatus()) ? FlowStatusEnum.submit :
template.getType() == 0 ? FlowStatusEnum.save : FlowStatusEnum.none;
flowTask(flowModel, statusEnum, childNode);
}
@Override
@DSTransactional
public void batchCreateOrUpdate(FlowModel flowModel) throws WorkFlowException {
UserInfo userInfo = flowModel.getUserInfo();
List<String> batchUserId = flowModel.getDelegateUserList();
boolean isBatchUser = batchUserId.size() == 0;
if (isBatchUser) {
batchUserId.add(userInfo.getUserId());
}
for (String id : batchUserId) {
FlowModel model = JsonUtil.getJsonToBean(flowModel, FlowModel.class);
model.setDelegateUser(isBatchUser ? model.getDelegateUser() : userInfo.getUserId());
model.setProcessId(StringUtil.isNotEmpty(model.getId()) ? model.getId() : RandomUtil.uuId());
if (!isBatchUser) {
UserEntity userEntity = serviceUtil.getUserInfo(id);
if (userEntity != null) {
UserInfo info = new UserInfo();
info.setUserName(userEntity.getRealName());
info.setUserId(userEntity.getId());
model.setUserInfo(info);
}
}
model.setUserId(id);
createOrUpdate(model);
}
}
}

View File

@@ -0,0 +1,102 @@
package com.yunzhupaas.engine.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.common.collect.ImmutableList;
import com.yunzhupaas.base.service.SuperServiceImpl;
import com.yunzhupaas.engine.entity.FlowEngineVisibleEntity;
import com.yunzhupaas.engine.mapper.FlowEngineVisibleMapper;
import com.yunzhupaas.engine.model.flowtask.FlowAssistModel;
import com.yunzhupaas.engine.service.FlowEngineVisibleService;
import com.yunzhupaas.permission.entity.UserRelationEntity;
import com.yunzhupaas.util.RandomUtil;
import com.yunzhupaas.util.ServiceAllUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* 流程可见
*
* @author 云筑产品开发平台组
* @version V3.1.0
* @copyright 深圳市乐程软件有限公司
* @date 2023/09/27
*/
@Service
public class FlowEngineVisibleServiceImpl extends SuperServiceImpl<FlowEngineVisibleMapper, FlowEngineVisibleEntity> implements FlowEngineVisibleService {
@Autowired
private ServiceAllUtil serviceUtil;
@Override
public List<FlowEngineVisibleEntity> getList(List<String> flowIdList) {
List<FlowEngineVisibleEntity> list = new ArrayList<>();
if (flowIdList.size() > 0) {
QueryWrapper<FlowEngineVisibleEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().in(FlowEngineVisibleEntity::getFlowId, flowIdList);
queryWrapper.lambda().orderByAsc(FlowEngineVisibleEntity::getSortCode).orderByDesc(FlowEngineVisibleEntity::getCreatorTime);
list.addAll(this.list(queryWrapper));
}
return list;
}
@Override
public List<FlowEngineVisibleEntity> getList() {
QueryWrapper<FlowEngineVisibleEntity> queryWrapper = new QueryWrapper<>();
return this.list(queryWrapper);
}
@Override
public List<FlowEngineVisibleEntity> getVisibleFlowList(String userId) {
return getVisibleFlowList(userId, 1);
}
@Override
public List<FlowEngineVisibleEntity> getVisibleFlowList(String userId, Integer type) {
List<String> userRelationList = serviceUtil.getListByUserIdAll(ImmutableList.of(userId)).stream().map(UserRelationEntity::getObjectId).collect(Collectors.toList());
userRelationList.add(userId);
QueryWrapper<FlowEngineVisibleEntity> wrapper = new QueryWrapper<>();
wrapper.lambda().in(FlowEngineVisibleEntity::getOperatorId, userRelationList);
wrapper.lambda().eq(FlowEngineVisibleEntity::getType, type);
List<FlowEngineVisibleEntity> flowList = this.list(wrapper);
return flowList;
}
@Override
public void deleteVisible(String flowId) {
QueryWrapper<FlowEngineVisibleEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(FlowEngineVisibleEntity::getFlowId, flowId);
this.remove(queryWrapper);
}
@Override
public void assistList(FlowAssistModel assistModel) {
List<FlowEngineVisibleEntity> assistListAll = this.getList(ImmutableList.of(assistModel.getTemplateId()));
for (FlowEngineVisibleEntity entity : assistListAll) {
this.removeById(entity.getId());
}
List<String> list = assistModel.getList();
List<FlowEngineVisibleEntity> visibleList = new ArrayList<>();
for (String idAll : list) {
String[] id = idAll.split("--");
String operatorId = id[0];
String type = id.length > 1 ? id[1] : "user";
FlowEngineVisibleEntity visible = new FlowEngineVisibleEntity();
visible.setOperatorId(operatorId);
visible.setOperatorType(type);
visible.setType(2);
visibleList.add(visible);
}
for (int i = 0; i < visibleList.size(); i++) {
FlowEngineVisibleEntity visibleEntity = visibleList.get(i);
visibleEntity.setId(RandomUtil.uuId());
visibleEntity.setFlowId(assistModel.getTemplateId());
visibleEntity.setSortCode(Long.parseLong(i + ""));
this.save(visibleEntity);
}
}
}

View File

@@ -0,0 +1,39 @@
package com.yunzhupaas.engine.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yunzhupaas.base.service.SuperServiceImpl;
import com.yunzhupaas.engine.entity.FlowEventLogEntity;
import com.yunzhupaas.engine.mapper.FlowEventLogMapper;
import com.yunzhupaas.engine.service.FlowEventLogService;
import com.yunzhupaas.util.RandomUtil;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 流程事件日志
*
* @author 云筑产品开发平台组
* @version V3.1.0
* @copyright 深圳市乐程软件有限公司
*/
@Service
public class FlowEventLogServiceImpl extends SuperServiceImpl<FlowEventLogMapper, FlowEventLogEntity> implements FlowEventLogService {
@Override
public void create(FlowEventLogEntity entity) {
entity.setId(RandomUtil.uuId());
this.save(entity);
}
@Override
public List<FlowEventLogEntity> getList(List<String> nodeIdList) {
QueryWrapper<FlowEventLogEntity> queryWrapper = new QueryWrapper<>();
if (nodeIdList.size() > 0) {
queryWrapper.lambda().in(FlowEventLogEntity::getTaskNodeId, nodeIdList);
}
return this.list(queryWrapper);
}
}

View File

@@ -0,0 +1,88 @@
package com.yunzhupaas.engine.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yunzhupaas.base.service.SuperServiceImpl;
import com.yunzhupaas.engine.entity.FlowOperatorUserEntity;
import com.yunzhupaas.engine.mapper.FlowOperatorUserMapper;
import com.yunzhupaas.engine.service.FlowOperatorUserService;
import com.yunzhupaas.util.RandomUtil;
import com.yunzhupaas.util.StringUtil;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Set;
/**
* 流程依次审批
*
* @author 云筑产品开发平台组
* @version V3.1.0
* @copyright 深圳市乐程软件有限公司
*/
@Service
public class FlowOperatorUserServiceImpl extends SuperServiceImpl<FlowOperatorUserMapper, FlowOperatorUserEntity> implements FlowOperatorUserService {
@Override
public List<FlowOperatorUserEntity> getList(String taskId) {
return getTaskList(taskId, null);
}
@Override
public FlowOperatorUserEntity getInfo(String id) {
QueryWrapper<FlowOperatorUserEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(FlowOperatorUserEntity::getId, id);
return this.getOne(queryWrapper);
}
@Override
public List<FlowOperatorUserEntity> getTaskList(String taskId, String taskNodeId) {
QueryWrapper<FlowOperatorUserEntity> queryWrapper = new QueryWrapper<>();
if (StringUtil.isNotEmpty(taskId)) {
queryWrapper.lambda().eq(FlowOperatorUserEntity::getTaskId, taskId);
}
if (StringUtil.isNotEmpty(taskNodeId)) {
queryWrapper.lambda().eq(FlowOperatorUserEntity::getTaskNodeId, taskNodeId);
}
queryWrapper.lambda().orderByAsc(FlowOperatorUserEntity::getSortCode);
return this.list(queryWrapper);
}
@Override
public void create(List<FlowOperatorUserEntity> list) {
for (FlowOperatorUserEntity entity : list) {
entity.setId(RandomUtil.uuId());
this.save(entity);
}
}
@Override
public void update(String id, FlowOperatorUserEntity entity) {
entity.setId(id);
this.updateById(entity);
}
@Override
public void delete(FlowOperatorUserEntity entity) {
if (entity != null) {
this.removeById(entity.getId());
}
}
@Override
public void deleteByTaskId(String taskId) {
QueryWrapper<FlowOperatorUserEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(FlowOperatorUserEntity::getTaskId, taskId);
this.remove(queryWrapper);
}
@Override
public void updateReject(String taskId, Set<String> taskNodeId) {
if (taskNodeId.size() > 0) {
QueryWrapper<FlowOperatorUserEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(FlowOperatorUserEntity::getTaskId, taskId);
queryWrapper.lambda().in(FlowOperatorUserEntity::getTaskNodeId, taskNodeId);
this.remove(queryWrapper);
}
}
}

View File

@@ -0,0 +1,49 @@
package com.yunzhupaas.engine.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yunzhupaas.base.service.SuperServiceImpl;
import com.yunzhupaas.engine.entity.FlowRejectDataEntity;
import com.yunzhupaas.engine.mapper.FlowRejectDataMapper;
import com.yunzhupaas.engine.service.FlowRejectDataService;
import com.yunzhupaas.util.RandomUtil;
import org.springframework.stereotype.Service;
/**
* 冻结审批
*
* @author 云筑产品开发平台组
* @version V3.1.0
* @copyright 深圳市乐程软件有限公司
* @date 2024-09-29 上午9:18
*/
@Service
public class FlowRejectDataDataServiceImpl extends SuperServiceImpl<FlowRejectDataMapper, FlowRejectDataEntity> implements FlowRejectDataService {
@Override
public void createOrUpdate(FlowRejectDataEntity rejectEntity) {
this.saveOrUpdate(rejectEntity);
}
@Override
public void create(FlowRejectDataEntity rejectEntity) {
if (rejectEntity.getId() == null) {
rejectEntity.setId(RandomUtil.uuId());
}
this.save(rejectEntity);
}
@Override
public void update(String id, FlowRejectDataEntity rejectEntity) {
rejectEntity.setId(id);
this.updateById(rejectEntity);
}
@Override
public FlowRejectDataEntity getInfo(String id) {
QueryWrapper<FlowRejectDataEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(FlowRejectDataEntity::getId, id);
return this.getOne(queryWrapper);
}
}

View File

@@ -0,0 +1,44 @@
package com.yunzhupaas.engine.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yunzhupaas.base.service.SuperServiceImpl;
import com.yunzhupaas.engine.entity.FlowTaskCirculateEntity;
import com.yunzhupaas.engine.mapper.FlowTaskCirculateMapper;
import com.yunzhupaas.engine.service.FlowTaskCirculateService;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 流程传阅
*
* @author 云筑产品开发平台组
* @version V3.1.0
* @copyright 深圳市乐程软件有限公司
* @date 2023/09/27
*/
@Service
public class FlowTaskCirculateServiceImpl extends SuperServiceImpl<FlowTaskCirculateMapper, FlowTaskCirculateEntity> implements FlowTaskCirculateService {
@Override
public void deleteByTaskId(String taskId) {
QueryWrapper<FlowTaskCirculateEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(FlowTaskCirculateEntity::getTaskId, taskId);
this.remove(queryWrapper);
}
@Override
public void create(List<FlowTaskCirculateEntity> entitys) {
for (FlowTaskCirculateEntity entity : entitys) {
this.save(entity);
}
}
@Override
public List<FlowTaskCirculateEntity> getList(String taskId) {
QueryWrapper<FlowTaskCirculateEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(FlowTaskCirculateEntity::getTaskId, taskId);
return this.list(queryWrapper);
}
}

View File

@@ -0,0 +1,149 @@
package com.yunzhupaas.engine.service.impl;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.yunzhupaas.base.service.SuperServiceImpl;
import com.yunzhupaas.engine.entity.FlowTaskNodeEntity;
import com.yunzhupaas.engine.enums.FlowNodeEnum;
import com.yunzhupaas.engine.mapper.FlowTaskNodeMapper;
import com.yunzhupaas.engine.model.flowtasknode.TaskNodeListModel;
import com.yunzhupaas.engine.service.FlowTaskNodeService;
import com.yunzhupaas.engine.util.FlowNature;
import com.yunzhupaas.util.StringUtil;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
/**
* 流程节点
*
* @author 云筑产品开发平台组
* @version V3.1.0
* @copyright 深圳市乐程软件有限公司
* @date 2023/09/27
*/
@Service
public class FlowTaskNodeServiceImpl extends SuperServiceImpl<FlowTaskNodeMapper, FlowTaskNodeEntity> implements FlowTaskNodeService {
@Override
public List<FlowTaskNodeEntity> getList(String taskId, SFunction<FlowTaskNodeEntity, ?>... columns) {
TaskNodeListModel nodeListModel = new TaskNodeListModel();
nodeListModel.setId(taskId);
return getList(nodeListModel, columns);
}
@Override
public List<FlowTaskNodeEntity> getList(List<String> id, SFunction<FlowTaskNodeEntity, ?>... columns) {
List<FlowTaskNodeEntity> list = new ArrayList<>();
if (id.size() > 0) {
QueryWrapper<FlowTaskNodeEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().in(FlowTaskNodeEntity::getId, id);
queryWrapper.lambda().select(columns);
list.addAll(this.list(queryWrapper));
}
return list;
}
@Override
public List<FlowTaskNodeEntity> getList(TaskNodeListModel nodeListModel, SFunction<FlowTaskNodeEntity, ?>... columns) {
QueryWrapper<FlowTaskNodeEntity> queryWrapper = new QueryWrapper<>();
String taskId = nodeListModel.getId();
queryWrapper.lambda().eq(FlowTaskNodeEntity::getTaskId, taskId);
Integer state = nodeListModel.getState();
if (ObjectUtil.isNotEmpty(state)) {
queryWrapper.lambda().eq(FlowTaskNodeEntity::getState, state);
}
Integer completion = nodeListModel.getCompletion();
if (ObjectUtil.isNotEmpty(completion)) {
queryWrapper.lambda().eq(FlowTaskNodeEntity::getCompletion, completion);
}
String nodeCode = nodeListModel.getNotNodeCode();
if (ObjectUtil.isNotEmpty(nodeCode)) {
queryWrapper.lambda().ne(FlowTaskNodeEntity::getNodeCode, nodeCode);
}
queryWrapper.lambda().select(columns);
return this.list(queryWrapper);
}
@Override
public FlowTaskNodeEntity getInfo(String id, SFunction<FlowTaskNodeEntity, ?>... columns) {
QueryWrapper<FlowTaskNodeEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(FlowTaskNodeEntity::getId, id);
queryWrapper.lambda().select(columns);
return this.getOne(queryWrapper);
}
@Override
public void deleteByTaskId(String taskId) {
QueryWrapper<FlowTaskNodeEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(FlowTaskNodeEntity::getTaskId, taskId);
this.remove(queryWrapper);
}
@Override
public void create(FlowTaskNodeEntity entity) {
this.save(entity);
}
@Override
public void update(FlowTaskNodeEntity entity) {
this.updateById(entity);
}
@Override
public void update(String taskId) {
UpdateWrapper<FlowTaskNodeEntity> wrapper = new UpdateWrapper<>();
wrapper.lambda().eq(FlowTaskNodeEntity::getTaskId, taskId);
wrapper.lambda().set(FlowTaskNodeEntity::getCompletion, FlowNodeEnum.Futility.getCode());
wrapper.lambda().set(FlowTaskNodeEntity::getState, FlowNodeEnum.Futility.getCode());
this.update(wrapper);
}
@Override
public void updateCompletion(List<String> id, int start) {
if (id.size() > 0) {
UpdateWrapper<FlowTaskNodeEntity> wrapper = new UpdateWrapper<>();
wrapper.lambda().in(FlowTaskNodeEntity::getId, id);
wrapper.lambda().set(FlowTaskNodeEntity::getCompletion, start);
this.update(wrapper);
}
}
@Override
public void updateTaskNode(List<FlowTaskNodeEntity> taskNodeLis) {
for (FlowTaskNodeEntity taskNodeLi : taskNodeLis) {
String nodeNext = StringUtil.isNotEmpty(taskNodeLi.getNodeNext()) ? taskNodeLi.getNodeNext() : FlowNature.NodeEnd;
UpdateWrapper<FlowTaskNodeEntity> updateWrapper = new UpdateWrapper<>();
updateWrapper.lambda().eq(FlowTaskNodeEntity::getId, taskNodeLi.getId());
updateWrapper.lambda().set(FlowTaskNodeEntity::getNodeNext, nodeNext);
updateWrapper.lambda().set(FlowTaskNodeEntity::getSortCode, taskNodeLi.getSortCode());
updateWrapper.lambda().set(FlowTaskNodeEntity::getState, taskNodeLi.getState());
updateWrapper.lambda().set(FlowTaskNodeEntity::getCompletion, taskNodeLi.getCompletion());
updateWrapper.lambda().set(FlowTaskNodeEntity::getNodePropertyJson, taskNodeLi.getNodePropertyJson());
this.update(updateWrapper);
}
}
@Override
public void updateTaskNodeCandidates(List<String> id, String candidates) {
if (id.size() > 0) {
UpdateWrapper<FlowTaskNodeEntity> wrapper = new UpdateWrapper<>();
wrapper.lambda().in(FlowTaskNodeEntity::getId, id);
wrapper.lambda().set(FlowTaskNodeEntity::getCandidates, candidates);
this.update(wrapper);
}
}
@Override
public void updateTaskIdList(FlowTaskNodeEntity entity) {
UpdateWrapper<FlowTaskNodeEntity> wrapper = new UpdateWrapper<>();
wrapper.lambda().eq(FlowTaskNodeEntity::getId, entity.getId());
wrapper.lambda().set(FlowTaskNodeEntity::getNodePropertyJson, entity.getNodePropertyJson());
this.update(wrapper);
}
}

View File

@@ -0,0 +1,121 @@
package com.yunzhupaas.engine.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.yunzhupaas.base.service.SuperServiceImpl;
import com.yunzhupaas.engine.entity.FlowTaskOperatorRecordEntity;
import com.yunzhupaas.engine.enums.FlowNodeEnum;
import com.yunzhupaas.engine.enums.FlowRecordEnum;
import com.yunzhupaas.engine.mapper.FlowTaskOperatorRecordMapper;
import com.yunzhupaas.engine.service.FlowTaskOperatorRecordService;
import com.yunzhupaas.util.RandomUtil;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Set;
/**
* 流程经办
*
* @author 云筑产品开发平台组
* @version V3.1.0
* @copyright 深圳市乐程软件有限公司
* @date 2023/09/27
*/
@Service
public class FlowTaskOperatorRecordServiceImpl extends SuperServiceImpl<FlowTaskOperatorRecordMapper, FlowTaskOperatorRecordEntity> implements FlowTaskOperatorRecordService {
@Override
public List<FlowTaskOperatorRecordEntity> getList(String taskId) {
QueryWrapper<FlowTaskOperatorRecordEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(FlowTaskOperatorRecordEntity::getTaskId, taskId).orderByAsc(FlowTaskOperatorRecordEntity::getHandleTime);
return this.list(queryWrapper);
}
@Override
public List<FlowTaskOperatorRecordEntity> getRecordList(String taskId, List<Integer> handleStatus) {
QueryWrapper<FlowTaskOperatorRecordEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(FlowTaskOperatorRecordEntity::getTaskId, taskId);
if (handleStatus.size() > 0) {
queryWrapper.lambda().in(FlowTaskOperatorRecordEntity::getHandleStatus, handleStatus);
}
queryWrapper.lambda().orderByDesc(FlowTaskOperatorRecordEntity::getHandleTime);
return this.list(queryWrapper);
}
@Override
public FlowTaskOperatorRecordEntity getInfo(String id) {
QueryWrapper<FlowTaskOperatorRecordEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(FlowTaskOperatorRecordEntity::getId, id);
return this.getOne(queryWrapper);
}
@Override
public void delete(FlowTaskOperatorRecordEntity entity) {
QueryWrapper<FlowTaskOperatorRecordEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(FlowTaskOperatorRecordEntity::getId, entity.getId());
this.remove(queryWrapper);
}
@Override
public void create(FlowTaskOperatorRecordEntity entity) {
entity.setId(RandomUtil.uuId());
this.save(entity);
}
@Override
public void update(String id, FlowTaskOperatorRecordEntity entity) {
entity.setId(id);
this.updateById(entity);
}
@Override
public void updateStatus(Set<String> taskNodeId, String taskId) {
if (taskNodeId.size() > 0) {
UpdateWrapper<FlowTaskOperatorRecordEntity> updateWrapper = new UpdateWrapper<>();
updateWrapper.lambda().in(FlowTaskOperatorRecordEntity::getTaskNodeId, taskNodeId);
updateWrapper.lambda().eq(FlowTaskOperatorRecordEntity::getTaskId, taskId);
updateWrapper.lambda().set(FlowTaskOperatorRecordEntity::getStatus, FlowRecordEnum.revoke.getCode());
this.update(updateWrapper);
}
}
@Override
public FlowTaskOperatorRecordEntity getInfo(String taskId, String taskNodeId, String taskOperatorId) {
QueryWrapper<FlowTaskOperatorRecordEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(FlowTaskOperatorRecordEntity::getTaskId, taskId);
queryWrapper.lambda().eq(FlowTaskOperatorRecordEntity::getTaskNodeId, taskNodeId);
queryWrapper.lambda().eq(FlowTaskOperatorRecordEntity::getTaskOperatorId, taskOperatorId);
queryWrapper.lambda().eq(FlowTaskOperatorRecordEntity::getStatus, FlowNodeEnum.FreeApprover.getCode());
queryWrapper.lambda().eq(FlowTaskOperatorRecordEntity::getHandleStatus, FlowRecordEnum.audit.getCode());
return this.getOne(queryWrapper);
}
@Override
public void updateStatus(List<String> idAll) {
if (idAll.size() > 0) {
UpdateWrapper<FlowTaskOperatorRecordEntity> updateWrapper = new UpdateWrapper<>();
updateWrapper.lambda().in(FlowTaskOperatorRecordEntity::getId, idAll);
updateWrapper.lambda().set(FlowTaskOperatorRecordEntity::getStatus, FlowRecordEnum.revoke.getCode());
this.update(updateWrapper);
}
}
@Override
public void update(String taskId) {
UpdateWrapper<FlowTaskOperatorRecordEntity> updateWrapper = new UpdateWrapper<>();
updateWrapper.lambda().eq(FlowTaskOperatorRecordEntity::getTaskId, taskId);
updateWrapper.lambda().set(FlowTaskOperatorRecordEntity::getStatus, FlowRecordEnum.revoke.getCode());
this.update(updateWrapper);
}
@Override
public FlowTaskOperatorRecordEntity getIsCheck(String taskOperatorId, Integer status) {
QueryWrapper<FlowTaskOperatorRecordEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(FlowTaskOperatorRecordEntity::getTaskOperatorId, taskOperatorId);
queryWrapper.lambda().eq(FlowTaskOperatorRecordEntity::getStatus, status);
return this.getOne(queryWrapper);
}
}

View File

@@ -0,0 +1,168 @@
package com.yunzhupaas.engine.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.yunzhupaas.base.UserInfo;
import com.yunzhupaas.base.service.SuperServiceImpl;
import com.yunzhupaas.constant.MsgCode;
import com.yunzhupaas.engine.entity.FlowDelegateEntity;
import com.yunzhupaas.engine.entity.FlowTaskOperatorEntity;
import com.yunzhupaas.engine.enums.FlowNodeEnum;
import com.yunzhupaas.engine.mapper.FlowTaskOperatorMapper;
import com.yunzhupaas.engine.service.FlowDelegateService;
import com.yunzhupaas.engine.service.FlowTaskOperatorService;
import com.yunzhupaas.engine.util.FlowNature;
import com.yunzhupaas.exception.WorkFlowException;
import com.yunzhupaas.util.UserProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
/**
* 流程经办记录
*
* @author 云筑产品开发平台组
* @version V3.1.0
* @copyright 深圳市乐程软件有限公司
* @date 2023/09/27
*/
@Service
public class FlowTaskOperatorServiceImpl extends SuperServiceImpl<FlowTaskOperatorMapper, FlowTaskOperatorEntity> implements FlowTaskOperatorService {
@Autowired
private FlowDelegateService flowDelegateService;
@Override
public List<FlowTaskOperatorEntity> getList(String taskId) {
QueryWrapper<FlowTaskOperatorEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(FlowTaskOperatorEntity::getTaskId, taskId).orderByDesc(FlowTaskOperatorEntity::getCreatorTime);
return this.list(queryWrapper);
}
@Override
public FlowTaskOperatorEntity getInfo(String id) throws WorkFlowException {
QueryWrapper<FlowTaskOperatorEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(FlowTaskOperatorEntity::getId, id);
FlowTaskOperatorEntity entity = this.getOne(queryWrapper);
if (entity == null) {
throw new WorkFlowException(MsgCode.FA001.get());
}
return entity;
}
@Override
public FlowTaskOperatorEntity getOperatorInfo(String id) {
QueryWrapper<FlowTaskOperatorEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(FlowTaskOperatorEntity::getId, id);
FlowTaskOperatorEntity entity = this.getOne(queryWrapper);
return entity;
}
@Override
public void create(List<FlowTaskOperatorEntity> entitys) {
for (FlowTaskOperatorEntity entity : entitys) {
this.save(entity);
}
}
@Override
public void update(FlowTaskOperatorEntity entity) {
this.updateById(entity);
}
@Override
public void update(String taskNodeId, List<String> userId, String completion) {
if (userId.size() > 0) {
UpdateWrapper<FlowTaskOperatorEntity> updateWrapper = new UpdateWrapper<>();
updateWrapper.lambda().eq(FlowTaskOperatorEntity::getTaskNodeId, taskNodeId);
updateWrapper.lambda().in(FlowTaskOperatorEntity::getHandleId, userId);
updateWrapper.lambda().set(FlowTaskOperatorEntity::getCompletion, FlowNature.AuditCompletion);
this.update(updateWrapper);
}
}
@Override
public void update(String taskNodeId, Integer type) {
UpdateWrapper<FlowTaskOperatorEntity> updateWrapper = new UpdateWrapper<>();
updateWrapper.lambda().eq(FlowTaskOperatorEntity::getTaskNodeId, taskNodeId);
updateWrapper.lambda().eq(FlowTaskOperatorEntity::getType, type);
updateWrapper.lambda().set(FlowTaskOperatorEntity::getCompletion, FlowNature.AuditCompletion);
this.update(updateWrapper);
}
@Override
public void update(String taskId) {
UpdateWrapper<FlowTaskOperatorEntity> updateWrapper = new UpdateWrapper<>();
updateWrapper.lambda().eq(FlowTaskOperatorEntity::getTaskId, taskId);
updateWrapper.lambda().set(FlowTaskOperatorEntity::getState, FlowNodeEnum.Futility.getCode());
this.update(updateWrapper);
}
@Override
public List<FlowTaskOperatorEntity> press(String taskId) {
QueryWrapper<FlowTaskOperatorEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(FlowTaskOperatorEntity::getCompletion, FlowNature.ProcessCompletion)
.eq(FlowTaskOperatorEntity::getTaskId, taskId)
.eq(FlowTaskOperatorEntity::getState, FlowNodeEnum.Process.getCode() + "");
return this.list(queryWrapper);
}
@Override
public void updateReject(String taskId, Set<String> taskNodeId) {
if (taskNodeId.size() > 0) {
UpdateWrapper<FlowTaskOperatorEntity> updateWrapper = new UpdateWrapper<>();
updateWrapper.lambda().eq(FlowTaskOperatorEntity::getTaskId, taskId);
updateWrapper.lambda().in(FlowTaskOperatorEntity::getTaskNodeId, taskNodeId);
updateWrapper.lambda().set(FlowTaskOperatorEntity::getState, FlowNodeEnum.Futility.getCode());
this.update(updateWrapper);
}
}
@Override
public void deleteList(List<String> idAll) {
if (idAll.size() > 0) {
QueryWrapper<FlowTaskOperatorEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().in(FlowTaskOperatorEntity::getId, idAll);
this.remove(queryWrapper);
}
}
@Override
public List<FlowTaskOperatorEntity> getParentId(String parentId) {
QueryWrapper<FlowTaskOperatorEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(FlowTaskOperatorEntity::getAppendHandleId, parentId);
queryWrapper.lambda().orderByDesc(FlowTaskOperatorEntity::getCreatorTime);
return this.list(queryWrapper);
}
@Override
public void updateTaskOperatorState(List<String> idAll) {
if (idAll.size() > 0) {
UpdateWrapper<FlowTaskOperatorEntity> queryWrapper = new UpdateWrapper<>();
queryWrapper.lambda().in(FlowTaskOperatorEntity::getId, idAll);
queryWrapper.lambda().set(FlowTaskOperatorEntity::getState, FlowNodeEnum.Futility.getCode());
queryWrapper.lambda().set(FlowTaskOperatorEntity::getCompletion, FlowNature.RejectCompletion);
this.update(queryWrapper);
}
}
@Override
public List<FlowTaskOperatorEntity> getBatchList() {
UserInfo userInfo = UserProvider.getUser();
List<String> userList = flowDelegateService.getUser(userInfo.getUserId()).stream().map(FlowDelegateEntity::getCreatorUserId).collect(Collectors.toList());
userList.add(userInfo.getUserId());
QueryWrapper<FlowTaskOperatorEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().in(FlowTaskOperatorEntity::getHandleId, userList);
queryWrapper.lambda().eq(FlowTaskOperatorEntity::getCompletion, FlowNature.ProcessCompletion);
queryWrapper.lambda().eq(FlowTaskOperatorEntity::getState, FlowNature.ProcessCompletion);
queryWrapper.lambda().select(FlowTaskOperatorEntity::getTaskId);
return list(queryWrapper);
}
}

View File

@@ -0,0 +1,911 @@
package com.yunzhupaas.engine.service.impl;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.toolkit.JoinWrappers;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.google.common.collect.ImmutableList;
import com.yunzhupaas.base.UserInfo;
import com.yunzhupaas.base.service.SuperServiceImpl;
import com.yunzhupaas.constant.MsgCode;
import com.yunzhupaas.engine.entity.*;
import com.yunzhupaas.engine.enums.FlowNodeEnum;
import com.yunzhupaas.engine.enums.FlowTaskStatusEnum;
import com.yunzhupaas.engine.mapper.FlowTaskMapper;
import com.yunzhupaas.engine.model.flowbefore.FlowBatchModel;
import com.yunzhupaas.engine.model.flowtask.FlowTaskListModel;
import com.yunzhupaas.engine.model.flowtask.PaginationFlowTask;
import com.yunzhupaas.engine.model.flowtemplatejson.FlowTemplateJsonPage;
import com.yunzhupaas.engine.service.*;
import com.yunzhupaas.engine.util.FlowNature;
import com.yunzhupaas.exception.WorkFlowException;
import com.yunzhupaas.model.FlowWorkListVO;
import com.yunzhupaas.model.FlowWorkModel;
import com.yunzhupaas.permission.entity.UserEntity;
import com.yunzhupaas.permission.model.user.WorkHandoverModel;
import com.yunzhupaas.util.JsonUtil;
import com.yunzhupaas.util.ServiceAllUtil;
import com.yunzhupaas.util.StringUtil;
import com.yunzhupaas.util.UserProvider;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import java.util.stream.Collectors;
/**
* 流程任务
*
* @author 云筑产品开发平台组
* @version V3.1.0
* @copyright 深圳市乐程软件有限公司
* @date 2023/09/27
*/
@Slf4j
@Service
public class FlowTaskServiceImpl extends SuperServiceImpl<FlowTaskMapper, FlowTaskEntity> implements FlowTaskService {
@Autowired
private ServiceAllUtil serviceUtil;
@Autowired
private FlowTemplateService flowTemplateService;
@Autowired
private FlowTemplateJsonService flowTemplateJsonService;
@Autowired
private FlowDelegateService flowDelegateService;
@Autowired
private FlowTaskNodeService flowTaskNodeService;
@Autowired
private FlowTaskOperatorService flowTaskOperatorService;
@Autowired
private FlowOperatorUserService flowOperatorUserService;
@Autowired
private FlowRejectDataService flowRejectDataService;
@Autowired
private FlowTaskOperatorRecordService flowTaskOperatorRecordService;
@Autowired
private FlowTaskCirculateService flowTaskCirculateService;
@Autowired
private FlowCandidatesService flowCandidatesService;
@Autowired
private FlowCommentService flowCommentService;
@Autowired
private FlowAuthorizeService flowAuthorizeService;
@Autowired
private FlowUserService flowUserService;
@Autowired
private FlowEngineVisibleService flowEngineVisibleService;
@Override
public List<FlowTaskEntity> getMonitorList(PaginationFlowTask pagination) {
// 定义变量判断是否需要使用修改时间倒序
boolean flag = false;
UserInfo userInfo = UserProvider.getUser();
QueryWrapper<FlowTaskEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().select(FlowTaskEntity::getId);
queryWrapper.lambda().gt(FlowTaskEntity::getStatus, FlowTaskStatusEnum.Draft.getCode());
queryWrapper.lambda().and(t -> t.isNull(FlowTaskEntity::getSuspend).or().ne(FlowTaskEntity::getSuspend, FlowTaskStatusEnum.Draft.getCode()));
if (!userInfo.getIsAdministrator()) {
List<String> userList = serviceUtil.getOrganizeUserList("select");
if (userList.size() == 0) {
return new ArrayList<>();
}
queryWrapper.lambda().in(FlowTaskEntity::getCreatorUserId, userList);
}
//关键字(流程名称、流程编码)
String keyWord = pagination.getKeyword();
if (ObjectUtil.isNotEmpty(keyWord)) {
flag = true;
queryWrapper.lambda().and(t -> t.like(FlowTaskEntity::getEnCode, keyWord).or().like(FlowTaskEntity::getFullName, keyWord));
}
//日期范围近7天、近1月、近3月、自定义
if (ObjectUtil.isNotEmpty(pagination.getStartTime()) && ObjectUtil.isNotEmpty(pagination.getEndTime())) {
queryWrapper.lambda().between(FlowTaskEntity::getStartTime, new Date(pagination.getStartTime()), new Date(pagination.getEndTime()));
}
//流程状态
Integer status = pagination.getStatus();
if (ObjectUtil.isNotEmpty(status)) {
flag = true;
List<Integer> statusList = new ArrayList() {{
add(status);
}};
if (Objects.equals(status, FlowTaskStatusEnum.Revoke.getCode())) {
statusList.add(FlowTaskStatusEnum.Resubmit.getCode());
}
queryWrapper.lambda().in(FlowTaskEntity::getStatus, statusList);
}
//所属流程
String templateId = pagination.getTemplateId();
if (ObjectUtil.isNotEmpty(templateId)) {
flag = true;
queryWrapper.lambda().eq(FlowTaskEntity::getTemplateId, templateId);
}
//所属名称
String flowId = pagination.getFlowId();
if (ObjectUtil.isNotEmpty(flowId)) {
flag = true;
FlowTemplateJsonPage page = new FlowTemplateJsonPage();
page.setTemplateId(templateId);
page.setFlowId(flowId);
List<String> flowList = flowTemplateJsonService.getListPage(page, false).stream().map(FlowTemplateJsonEntity::getId).collect(Collectors.toList());
if (flowList.size() == 0) {
return new ArrayList<>();
}
queryWrapper.lambda().in(FlowTaskEntity::getFlowId, flowList);
}
//所属分类
String flowCategory = pagination.getFlowCategory();
if (ObjectUtil.isNotEmpty(flowCategory)) {
flag = true;
queryWrapper.lambda().eq(FlowTaskEntity::getFlowCategory, flowCategory);
}
//发起人员
String creatorUserId = pagination.getCreatorUserId();
if (ObjectUtil.isNotEmpty(creatorUserId)) {
flag = true;
queryWrapper.lambda().eq(FlowTaskEntity::getCreatorUserId, creatorUserId);
}
//紧急程度
Integer flowUrgent = pagination.getFlowUrgent();
if (ObjectUtil.isNotEmpty(flowUrgent)) {
flag = true;
queryWrapper.lambda().eq(FlowTaskEntity::getFlowUrgent, flowUrgent);
}
//排序
// if ("desc".equals(pagination.getSort().toLowerCase())) {
// queryWrapper.lambda().orderByDesc(FlowTaskEntity::getCreatorTime);
// } else {
queryWrapper.lambda().orderByAsc(FlowTaskEntity::getSortCode).orderByDesc(FlowTaskEntity::getCreatorTime);
// }
if (flag) {
queryWrapper.lambda().orderByDesc(FlowTaskEntity::getLastModifyTime);
}
Page<FlowTaskEntity> page = new Page<>(pagination.getCurrentPage(), pagination.getPageSize());
IPage<FlowTaskEntity> flowTaskEntityPage = this.page(page, queryWrapper);
if (!flowTaskEntityPage.getRecords().isEmpty()) {
List<String> ids = flowTaskEntityPage.getRecords().stream().map(FlowTaskEntity::getId).collect(Collectors.toList());
queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().in(FlowTaskEntity::getId, ids);
//排序
queryWrapper.lambda().orderByAsc(FlowTaskEntity::getSortCode).orderByDesc(FlowTaskEntity::getCreatorTime);
if (flag) {
queryWrapper.lambda().orderByDesc(FlowTaskEntity::getLastModifyTime);
}
flowTaskEntityPage.setRecords(this.list(queryWrapper));
}
return pagination.setData(flowTaskEntityPage.getRecords(), page.getTotal());
}
@Override
public List<FlowTaskEntity> getLaunchList(PaginationFlowTask pagination) {
QueryWrapper<FlowTaskEntity> queryWrapper = new QueryWrapper<>();
String userId = UserProvider.getUser().getUserId();
if (pagination.getDelegateType()) {
queryWrapper.lambda().select(FlowTaskEntity::getId).eq(FlowTaskEntity::getDelegateUser, userId);
} else {
queryWrapper.lambda().select(FlowTaskEntity::getId).eq(FlowTaskEntity::getCreatorUserId, userId);
}
//关键字(流程名称、流程编码)
String keyWord = pagination.getKeyword();
if (ObjectUtil.isNotEmpty(keyWord)) {
queryWrapper.lambda().and(t -> t.like(FlowTaskEntity::getEnCode, keyWord).or().like(FlowTaskEntity::getFullName, keyWord));
}
//日期范围近7天、近1月、近3月、自定义
if (ObjectUtil.isNotEmpty(pagination.getStartTime()) && ObjectUtil.isNotEmpty(pagination.getEndTime())) {
queryWrapper.lambda().between(FlowTaskEntity::getStartTime, new Date(pagination.getStartTime()), new Date(pagination.getEndTime()));
}
//所属流程
String templateId = pagination.getTemplateId();
if (ObjectUtil.isNotEmpty(templateId)) {
queryWrapper.lambda().eq(FlowTaskEntity::getTemplateId, templateId);
}
//所属名称
String flowId = pagination.getFlowId();
if (ObjectUtil.isNotEmpty(flowId)) {
FlowTemplateJsonPage page = new FlowTemplateJsonPage();
page.setTemplateId(templateId);
page.setFlowId(flowId);
List<String> flowList = flowTemplateJsonService.getListPage(page, false).stream().map(FlowTemplateJsonEntity::getId).collect(Collectors.toList());
if (flowList.size() == 0) {
return new ArrayList<>();
}
queryWrapper.lambda().in(FlowTaskEntity::getFlowId, flowList);
}
//流程状态
Integer status = pagination.getStatus();
if (ObjectUtil.isNotEmpty(status)) {
List<Integer> statusList = new ArrayList() {{
add(status);
}};
if (Objects.equals(status, FlowTaskStatusEnum.Revoke.getCode())) {
statusList.add(FlowTaskStatusEnum.Resubmit.getCode());
}
queryWrapper.lambda().in(FlowTaskEntity::getStatus, statusList);
}
//紧急程度
Integer flowUrgent = pagination.getFlowUrgent();
if (ObjectUtil.isNotEmpty(flowUrgent)) {
queryWrapper.lambda().eq(FlowTaskEntity::getFlowUrgent, flowUrgent);
}
//所属分类
String flowCategory = pagination.getFlowCategory();
if (ObjectUtil.isNotEmpty(flowCategory)) {
queryWrapper.lambda().eq(FlowTaskEntity::getFlowCategory, flowCategory);
}
//排序
queryWrapper.lambda().orderByAsc(FlowTaskEntity::getStatus).orderByDesc(FlowTaskEntity::getStartTime);
Page<FlowTaskEntity> page = new Page<>(pagination.getCurrentPage(), pagination.getPageSize());
IPage<FlowTaskEntity> flowTaskEntityPage = this.page(page, queryWrapper);
if (!flowTaskEntityPage.getRecords().isEmpty()) {
List<String> ids = flowTaskEntityPage.getRecords().stream().map(FlowTaskEntity::getId).collect(Collectors.toList());
queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().in(FlowTaskEntity::getId, ids);
//排序
queryWrapper.lambda().orderByAsc(FlowTaskEntity::getStatus).orderByDesc(FlowTaskEntity::getStartTime);
flowTaskEntityPage.setRecords(this.list(queryWrapper));
}
return pagination.setData(flowTaskEntityPage.getRecords(), page.getTotal());
}
@Override
public List<FlowTaskListModel> getWaitList(PaginationFlowTask pagination) {
String userId = StringUtil.isNotEmpty(pagination.getUserId()) ? pagination.getUserId() : UserProvider.getUser().getUserId();
MPJLambdaWrapper<FlowTaskEntity> wrapper = JoinWrappers.lambda(FlowTaskEntity.class)
.selectAll(FlowTaskEntity.class)
.leftJoin(FlowTaskOperatorEntity.class, FlowTaskOperatorEntity::getTaskId, FlowTaskEntity::getId)
.selectAs(FlowTaskOperatorEntity::getId, FlowTaskListModel::getId)
.selectAs(FlowTaskOperatorEntity::getNodeName, FlowTaskListModel::getThisStep)
.selectAs(FlowTaskOperatorEntity::getNodeName, FlowTaskListModel::getNodeName)
.selectAs(FlowTaskOperatorEntity::getTaskNodeId, FlowTaskListModel::getThisStepId)
.selectAs(FlowTaskOperatorEntity::getHandleId, FlowTaskListModel::getHandleId)
.selectAs(FlowTaskOperatorEntity::getCreatorTime, FlowTaskListModel::getCreatorTime)
.eq(FlowTaskOperatorEntity::getCompletion, FlowNature.ProcessCompletion)
.le(FlowTaskOperatorEntity::getCreatorTime, new Date())
.eq(FlowTaskOperatorEntity::getState, FlowNodeEnum.Process.getCode())
.eq(FlowTaskEntity::getStatus, FlowTaskStatusEnum.Handle.getCode());
boolean isDelegateType = pagination.getDelegateType();
List<String> handleId = new ArrayList<>();
handleId.add(userId);
Map<String, String[]> delegateListAll = new HashMap<>();
//是否委托
if (isDelegateType) {
List<FlowDelegateEntity> delegateList = flowDelegateService.getUser(userId);
for (FlowDelegateEntity entity : delegateList) {
if (StringUtil.isNotEmpty(entity.getFlowId())) {
String[] flowIdAll = entity.getFlowId().split(",");
delegateListAll.put(entity.getUserId(), flowIdAll);
} else {
handleId.add(entity.getUserId());
}
}
}
//代办人
wrapper.and(t -> {
t.in(FlowTaskOperatorEntity::getHandleId, handleId);
if (isDelegateType) {
for (String key : delegateListAll.keySet()) {
t.or(tw -> tw.in(FlowTaskEntity::getTemplateId, delegateListAll.get(key)).eq(FlowTaskOperatorEntity::getHandleId, key));
}
}
});
//关键字(流程名称、流程编码)
String keyWord = pagination.getKeyword();
if (ObjectUtil.isNotEmpty(keyWord)) {
wrapper.and(t -> t.like(FlowTaskEntity::getEnCode, keyWord).or().like(FlowTaskEntity::getFullName, keyWord));
}
//日期范围近7天、近1月、近3月、自定义
if (ObjectUtil.isNotEmpty(pagination.getStartTime()) && ObjectUtil.isNotEmpty(pagination.getEndTime())) {
wrapper.between(FlowTaskEntity::getStartTime, new Date(pagination.getStartTime()), new Date(pagination.getEndTime()));
}
//所属流程
String templateId = pagination.getTemplateId();
if (ObjectUtil.isNotEmpty(templateId)) {
wrapper.eq(FlowTaskEntity::getTemplateId, templateId);
}
//是否批量
Integer isBatch = pagination.getIsBatch();
if (ObjectUtil.isNotEmpty(isBatch)) {
wrapper.eq(FlowTaskEntity::getIsBatch, isBatch);
}
//所属名称
String flowId = pagination.getFlowId();
if (ObjectUtil.isNotEmpty(flowId)) {
List<String> flowList = new ArrayList<>();
if (ObjectUtil.isEmpty(isBatch)) {
FlowTemplateJsonPage page = new FlowTemplateJsonPage();
page.setTemplateId(templateId);
page.setFlowId(flowId);
flowList.addAll(flowTemplateJsonService.getListPage(page, false).stream().map(FlowTemplateJsonEntity::getId).collect(Collectors.toList()));
if (flowList.size() == 0) {
return new ArrayList<>();
}
} else {
flowList.add(flowId);
}
wrapper.in(FlowTaskEntity::getFlowId, flowList);
}
//所属分类
String category = pagination.getFlowCategory();
if (ObjectUtil.isNotEmpty(category)) {
wrapper.in(FlowTaskEntity::getFlowCategory, category.split(","));
}
//发起人员
String creatorUserId = pagination.getCreatorUserId();
if (ObjectUtil.isNotEmpty(creatorUserId)) {
wrapper.eq(FlowTaskEntity::getCreatorUserId, creatorUserId);
}
//节点编码
String nodeCode = pagination.getNodeCode();
if (ObjectUtil.isNotEmpty(nodeCode)) {
wrapper.eq(FlowTaskOperatorEntity::getNodeCode, nodeCode);
}
//紧急程度
Integer flowUrgent = pagination.getFlowUrgent();
if (ObjectUtil.isNotEmpty(flowUrgent)) {
wrapper.eq(FlowTaskEntity::getFlowUrgent, flowUrgent);
}
wrapper.orderByDesc(FlowTaskOperatorEntity::getCreatorTime);
Page<FlowTaskListModel> page = new Page<>(pagination.getCurrentPage(), pagination.getPageSize());
Page<FlowTaskListModel> data = this.selectJoinListPage(page, FlowTaskListModel.class, wrapper);
for (FlowTaskListModel entity : data.getRecords()) {
boolean isuser = entity.getHandleId().equals(userId);
entity.setDelegateUser(!isuser ? entity.getCreatorUserId() : null);
}
return pagination.setData(data.getRecords(), page.getTotal());
}
@Override
public List<FlowTaskListModel> getCirculateList(PaginationFlowTask pagination) {
String userId = StringUtil.isNotEmpty(pagination.getUserId()) ? pagination.getUserId() : UserProvider.getUser().getUserId();
MPJLambdaWrapper<FlowTaskEntity> wrapper = JoinWrappers.lambda(FlowTaskEntity.class)
.selectAll(FlowTaskEntity.class)
.leftJoin(FlowTaskCirculateEntity.class, FlowTaskCirculateEntity::getTaskId, FlowTaskEntity::getId)
.selectAs(FlowTaskCirculateEntity::getNodeName, FlowTaskListModel::getThisStep)
.selectAs(FlowTaskCirculateEntity::getTaskNodeId, FlowTaskListModel::getThisStepId)
.selectAs(FlowTaskCirculateEntity::getId, FlowTaskListModel::getCirculateId)
.selectAs(FlowTaskCirculateEntity::getCreatorTime, FlowTaskListModel::getCreatorTime)
.eq(FlowTaskCirculateEntity::getObjectId, userId);
//关键字(流程名称、流程编码)
String keyWord = pagination.getKeyword();
if (ObjectUtil.isNotEmpty(keyWord)) {
wrapper.and(t -> t.like(FlowTaskEntity::getEnCode, keyWord).or().like(FlowTaskEntity::getFullName, keyWord));
}
//日期范围近7天、近1月、近3月、自定义
if (ObjectUtil.isNotEmpty(pagination.getStartTime()) && ObjectUtil.isNotEmpty(pagination.getEndTime())) {
wrapper.between(FlowTaskEntity::getStartTime, new Date(pagination.getStartTime()), new Date(pagination.getEndTime()));
}
//所属流程
String templateId = pagination.getTemplateId();
if (ObjectUtil.isNotEmpty(templateId)) {
wrapper.eq(FlowTaskEntity::getTemplateId, templateId);
}
//所属名称
String flowId = pagination.getFlowId();
if (ObjectUtil.isNotEmpty(flowId)) {
FlowTemplateJsonPage page = new FlowTemplateJsonPage();
page.setTemplateId(templateId);
page.setFlowId(flowId);
List<String> flowList = flowTemplateJsonService.getListPage(page, false).stream().map(FlowTemplateJsonEntity::getId).collect(Collectors.toList());
if (flowList.size() == 0) {
return new ArrayList<>();
}
wrapper.in(FlowTaskEntity::getFlowId, flowList);
}
//所属分类
String category = pagination.getFlowCategory();
if (ObjectUtil.isNotEmpty(category)) {
wrapper.in(FlowTaskEntity::getFlowCategory, category.split(","));
}
//发起人员
String creatorUserId = pagination.getCreatorUserId();
if (ObjectUtil.isNotEmpty(creatorUserId)) {
wrapper.in(FlowTaskEntity::getCreatorUserId, creatorUserId);
}
//紧急程度
Integer flowUrgent = pagination.getFlowUrgent();
if (ObjectUtil.isNotEmpty(flowUrgent)) {
wrapper.in(FlowTaskEntity::getFlowUrgent, flowUrgent);
}
wrapper.orderByDesc(FlowTaskCirculateEntity::getCreatorTime);
Page<FlowTaskListModel> page = new Page(pagination.getCurrentPage(), pagination.getPageSize());
Page<FlowTaskListModel> data = this.selectJoinListPage(page, FlowTaskListModel.class, wrapper);
return pagination.setData(data.getRecords(), page.getTotal());
}
@Override
public List<FlowTaskListModel> getTrialList(PaginationFlowTask pagination) {
String userId = StringUtil.isNotEmpty(pagination.getUserId()) ? pagination.getUserId() : UserProvider.getUser().getUserId();
Integer handleStatus[] = new Integer[]{0, 1, 10, 13};
MPJLambdaWrapper<FlowTaskOperatorRecordEntity> recordWrapper = JoinWrappers.lambda(FlowTaskOperatorRecordEntity.class)
.select(FlowTaskOperatorRecordEntity::getHandleId)
.select(FlowTaskOperatorRecordEntity::getTaskNodeId)
.select(FlowTaskOperatorRecordEntity::getTaskId)
.selectMax(FlowTaskOperatorRecordEntity::getHandleTime)
.in(FlowTaskOperatorRecordEntity::getHandleStatus, handleStatus)
.eq(FlowTaskOperatorRecordEntity::getHandleId, userId)
.isNotNull(FlowTaskOperatorRecordEntity::getTaskOperatorId)
.groupBy(FlowTaskOperatorRecordEntity::getTaskId, FlowTaskOperatorRecordEntity::getTaskNodeId, FlowTaskOperatorRecordEntity::getHandleId);
List<FlowTaskOperatorRecordEntity> recordList = flowTaskOperatorRecordService.selectJoinList(FlowTaskOperatorRecordEntity.class, recordWrapper);
if (recordList.size() > 0) {
List<String> taskId = recordList.stream().map(FlowTaskOperatorRecordEntity::getTaskId).collect(Collectors.toList());
List<String> taskNodeId = recordList.stream().map(FlowTaskOperatorRecordEntity::getTaskNodeId).collect(Collectors.toList());
List<Date> handleTime = recordList.stream().map(FlowTaskOperatorRecordEntity::getHandleTime).collect(Collectors.toList());
MPJLambdaWrapper<FlowTaskEntity> wrapper = JoinWrappers.lambda(FlowTaskEntity.class)
.leftJoin(FlowTaskOperatorRecordEntity.class, FlowTaskOperatorRecordEntity::getTaskId, FlowTaskEntity::getId)
.leftJoin(FlowTaskOperatorEntity.class, FlowTaskOperatorEntity::getId, FlowTaskOperatorRecordEntity::getTaskOperatorId)
.selectAll(FlowTaskEntity.class)
.selectAs(FlowTaskOperatorRecordEntity::getId, FlowTaskListModel::getId)
.selectAs(FlowTaskOperatorRecordEntity::getNodeName, FlowTaskListModel::getThisStep)
.selectAs(FlowTaskOperatorRecordEntity::getTaskNodeId, FlowTaskListModel::getThisStepId)
.selectAs(FlowTaskOperatorRecordEntity::getHandleStatus, FlowTaskListModel::getStatus)
.selectAs(FlowTaskOperatorRecordEntity::getHandleId, FlowTaskListModel::getHandleId)
.selectAs(FlowTaskOperatorRecordEntity::getHandleTime, FlowTaskListModel::getCreatorTime)
.selectAs(FlowTaskOperatorEntity::getHandleId, FlowTaskListModel::getDelegateUser)
.in(FlowTaskOperatorRecordEntity::getTaskId, taskId)
.in(FlowTaskOperatorRecordEntity::getTaskNodeId, taskNodeId)
.in(FlowTaskOperatorRecordEntity::getHandleStatus, handleStatus)
.and(t -> {
for (Date date : handleTime) {
t.or().eq(FlowTaskOperatorRecordEntity::getHandleTime, date);
}
});
//关键字(流程名称、流程编码)
String keyWord = pagination.getKeyword();
if (ObjectUtil.isNotEmpty(keyWord)) {
wrapper.and(t -> t.like(FlowTaskEntity::getEnCode, keyWord).or().like(FlowTaskEntity::getFullName, keyWord));
}
//日期范围近7天、近1月、近3月、自定义
if (ObjectUtil.isNotEmpty(pagination.getStartTime()) && ObjectUtil.isNotEmpty(pagination.getEndTime())) {
wrapper.between(FlowTaskEntity::getStartTime, new Date(pagination.getStartTime()), new Date(pagination.getEndTime()));
}
//所属流程
String templateId = pagination.getTemplateId();
if (ObjectUtil.isNotEmpty(templateId)) {
wrapper.eq(FlowTaskEntity::getTemplateId, templateId);
}
//所属名称
String flowId = pagination.getFlowId();
if (ObjectUtil.isNotEmpty(flowId)) {
FlowTemplateJsonPage page = new FlowTemplateJsonPage();
page.setTemplateId(templateId);
page.setFlowId(flowId);
List<String> flowList = flowTemplateJsonService.getListPage(page, false).stream().map(FlowTemplateJsonEntity::getId).collect(Collectors.toList());
if (flowList.size() == 0) {
return new ArrayList<>();
}
wrapper.in(FlowTaskEntity::getFlowId, flowList);
}
//所属分类
String category = pagination.getFlowCategory();
if (ObjectUtil.isNotEmpty(category)) {
wrapper.in(FlowTaskEntity::getFlowCategory, category.split(","));
}
//发起人员
String creatorUserId = pagination.getCreatorUserId();
if (ObjectUtil.isNotEmpty(creatorUserId)) {
wrapper.in(FlowTaskEntity::getCreatorUserId, creatorUserId);
}
//紧急程度
Integer flowUrgent = pagination.getFlowUrgent();
if (ObjectUtil.isNotEmpty(flowUrgent)) {
wrapper.in(FlowTaskEntity::getFlowUrgent, flowUrgent);
}
wrapper.orderByDesc(FlowTaskOperatorRecordEntity::getHandleTime);
Page<FlowTaskListModel> page = new Page<>(pagination.getCurrentPage(), pagination.getPageSize());
Page<FlowTaskListModel> data = this.selectJoinListPage(page, FlowTaskListModel.class, wrapper);
for (FlowTaskListModel entity : data.getRecords()) {
boolean isuser = entity.getHandleId().equals(entity.getDelegateUser());
entity.setDelegateUser(!isuser ? entity.getCreatorUserId() : null);
}
return pagination.setData(data.getRecords(), page.getTotal());
}
return new ArrayList<>();
}
@Override
public FlowTaskEntity getInfo(String id, SFunction<FlowTaskEntity, ?>... columns) throws WorkFlowException {
QueryWrapper<FlowTaskEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(FlowTaskEntity::getId, id);
queryWrapper.lambda().select(columns);
FlowTaskEntity entity = this.getOne(queryWrapper);
if (entity == null) {
throw new WorkFlowException(MsgCode.FA001.get());
}
return entity;
}
@Override
public void update(FlowTaskEntity entity) {
this.updateById(entity);
}
@Override
public void create(FlowTaskEntity entity) {
this.save(entity);
}
@Override
public void createOrUpdate(FlowTaskEntity entity) {
this.saveOrUpdate(entity);
}
@Override
public FlowTaskEntity getInfoSubmit(String id, SFunction<FlowTaskEntity, ?>... columns) {
List<FlowTaskEntity> list = getInfosSubmit(new String[]{id}, columns);
if (list.isEmpty()) {
return null;
}
return list.get(0);
}
@Override
public List<FlowTaskEntity> getInfosSubmit(String[] ids, SFunction<FlowTaskEntity, ?>... columns) {
List<FlowTaskEntity> resultList = Collections.emptyList();
if (ids == null || ids.length == 0) {
return resultList;
}
LambdaQueryWrapper<FlowTaskEntity> queryWrapper = new LambdaQueryWrapper<>();
if (ids.length == 1) {
queryWrapper.select(columns).and(
t -> t.eq(FlowTaskEntity::getId, ids[0])
);
resultList = this.list(queryWrapper);
if (resultList.isEmpty()) {
queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.select(columns).and(
t -> t.eq(FlowTaskEntity::getProcessId, ids[0])
);
resultList = this.list(queryWrapper);
}
} else {
queryWrapper.select(FlowTaskEntity::getId).and(t -> {
t.in(FlowTaskEntity::getId, ids).or().in(FlowTaskEntity::getProcessId, ids);
});
List<String> resultIds = this.listObjs(queryWrapper, t -> t.toString());
if (!resultIds.isEmpty()) {
queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.select(columns).in(FlowTaskEntity::getId, resultIds);
resultList = this.list(queryWrapper);
}
}
return resultList;
}
@Override
public void delete(FlowTaskEntity entity) throws WorkFlowException {
if (FlowTaskStatusEnum.Suspend.getCode().equals(entity.getStatus())) {
throw new WorkFlowException(MsgCode.WF048.get());
}
List<Integer> status = ImmutableList.of(FlowTaskStatusEnum.Draft.getCode(),FlowTaskStatusEnum.Revoke.getCode(),
FlowTaskStatusEnum.Cancel.getCode(),FlowTaskStatusEnum.Resubmit.getCode());
if(!status.contains(entity.getStatus())){
throw new WorkFlowException(MsgCode.WF063.get());
}
if (!FlowNature.ParentId.equals(entity.getParentId()) && StringUtil.isNotEmpty(entity.getParentId())) {
throw new WorkFlowException(entity.getFullName() + MsgCode.WF021.get());
}
if (!checkStatus(entity.getStatus())) {
throw new WorkFlowException(MsgCode.WF049.get());
} else {
List<String> idList = ImmutableList.of(entity.getId());
this.deleteAll(idList, true, true);
}
}
@Override
public void deleteChildAll(List<String> idAll) {
this.deleteAll(idAll, true, true);
}
@Override
public void delete(String[] ids) throws WorkFlowException {
if (ids.length > 0) {
List<String> idList = Arrays.asList(ids);
List<FlowTaskEntity> flowTaskList = getOrderStaList(idList);
List<FlowTaskEntity> del = flowTaskList.stream().filter(t -> t.getFlowType() == 1).collect(Collectors.toList());
if (del.size() > 0) {
throw new WorkFlowException(del.get(0).getFullName() + MsgCode.WF020.get());
}
List<FlowTaskEntity> child = flowTaskList.stream().filter(t -> !FlowNature.ParentId.equals(t.getParentId()) && StringUtil.isNotEmpty(t.getParentId())).collect(Collectors.toList());
if (child.size() > 0) {
throw new WorkFlowException(child.get(0).getFullName() + MsgCode.WF021.get());
}
List<FlowTaskEntity> taskStatusList = new ArrayList<>();
for (String id : ids) {
List<String> childAllList = getChildAllList(id);
taskStatusList.addAll(getOrderStaList(childAllList));
}
List<FlowTaskEntity> taskStatus = taskStatusList.stream().filter(t -> FlowTaskStatusEnum.Suspend.getCode().equals(t.getStatus())).collect(Collectors.toList());
if (taskStatus.size() > 0) {
throw new WorkFlowException(taskStatus.get(0).getFullName() + MsgCode.WF050.get());
}
UserInfo userInfo = UserProvider.getUser();
if (!userInfo.getIsAdministrator()) {
List<String> organizeUserList = serviceUtil.getOrganizeUserList("delete");
List<FlowTaskEntity> taskOrganize = taskStatusList.stream().filter(t -> !organizeUserList.contains(t.getCreatorUserId())).collect(Collectors.toList());
if (taskOrganize.size() > 0) {
throw new WorkFlowException(taskOrganize.get(0).getFullName() + MsgCode.WF051.get());
}
}
this.deleteAll(idList, true, true);
}
}
@Override
public List<FlowTaskEntity> getOrderStaList(List<String> id, SFunction<FlowTaskEntity, ?>... columns) {
List<FlowTaskEntity> list = new ArrayList<>();
if (id.size() > 0) {
QueryWrapper<FlowTaskEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().in(FlowTaskEntity::getId, id);
list = this.list(queryWrapper);
}
return list;
}
@Override
public List<FlowTaskEntity> getChildList(String id, SFunction<FlowTaskEntity, ?>... columns) {
return getChildList(ImmutableList.of(id), columns);
}
@Override
public List<FlowTaskEntity> getChildList(List<String> id, SFunction<FlowTaskEntity, ?>... columns) {
QueryWrapper<FlowTaskEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().select(columns).in(FlowTaskEntity::getParentId, id);
return this.list(queryWrapper);
}
@Override
public List<FlowTaskEntity> getTemplateIdList(String tempId) {
QueryWrapper<FlowTaskEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(FlowTaskEntity::getTemplateId, tempId);
queryWrapper.lambda().select(FlowTaskEntity::getId, FlowTaskEntity::getFlowId);
return this.list(queryWrapper);
}
@Override
public List<FlowTaskEntity> getFlowList(String flowId) {
QueryWrapper<FlowTaskEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(FlowTaskEntity::getFlowId, flowId);
queryWrapper.lambda().select(FlowTaskEntity::getId);
return list(queryWrapper);
}
@Override
public List<FlowBatchModel> batchFlowSelector() {
List<FlowTaskOperatorEntity> operatorList = flowTaskOperatorService.getBatchList();
List<String> taskIdList = operatorList.stream().map(FlowTaskOperatorEntity::getTaskId).collect(Collectors.toList());
List<FlowTaskEntity> taskList = getOrderStaList(taskIdList);
Map<String, List<FlowTaskEntity>> flowList = taskList.stream().filter(t -> ObjectUtil.isNotEmpty(t.getIsBatch()) && t.getIsBatch() == 1).collect(Collectors.groupingBy(FlowTaskEntity::getTemplateId));
List<FlowBatchModel> batchFlowList = new ArrayList<>();
for (String key : flowList.keySet()) {
List<FlowTaskEntity> flowTaskList = flowList.get(key);
List<String> flowTask = flowTaskList.stream().map(FlowTaskEntity::getId).collect(Collectors.toList());
List<FlowTemplateJsonEntity> templateJsonList = flowTemplateJsonService.getTemplateJsonList(flowTaskList.stream().map(FlowTaskEntity::getFlowId).collect(Collectors.toList()));
if (flowTaskList.size() > 0) {
String flowName = flowTaskList.stream().map(FlowTaskEntity::getFlowName).distinct().collect(Collectors.joining(","));
String flowId = templateJsonList.stream().map(FlowTemplateJsonEntity::getTemplateId).distinct().collect(Collectors.joining(","));
Long count = operatorList.stream().filter(t -> flowTask.contains(t.getTaskId())).count();
FlowBatchModel batchModel = new FlowBatchModel();
batchModel.setNum(count);
batchModel.setId(flowId);
batchModel.setFullName(flowName + "(" + count + ")");
batchFlowList.add(batchModel);
}
}
batchFlowList = batchFlowList.stream().sorted(Comparator.comparing(FlowBatchModel::getNum).reversed()).collect(Collectors.toList());
return batchFlowList;
}
@Override
public List<String> getChildAllList(String id) {
List<String> idAll = new ArrayList<>();
List<String> idList = ImmutableList.of(id);
this.deleTaskAll(idList, idAll);
return idAll;
}
@Override
public void deleTaskAll(List<String> idList, List<String> idAll) {
idAll.addAll(idList);
for (String id : idList) {
List<FlowTaskEntity> taskAll = this.getChildList(id, FlowTaskEntity::getId);
List<String> list = taskAll.stream().map(FlowTaskEntity::getId).collect(Collectors.toList());
this.deleTaskAll(list, idAll);
}
}
@Override
public void getChildList(String id, boolean suspend, List<String> list) {
List<FlowTaskEntity> taskAll = this.getChildList(id, FlowTaskEntity::getId, FlowTaskEntity::getIsAsync);
if (suspend) {
taskAll = taskAll.stream().filter(t -> FlowNature.ChildSync.equals(t.getIsAsync())).collect(Collectors.toList());
}
for (FlowTaskEntity entity : taskAll) {
list.add(entity.getId());
this.getChildList(entity.getId(), suspend, list);
}
}
@Override
public FlowWorkListVO flowWork(String fromId) {
FlowWorkListVO vo = new FlowWorkListVO();
//代办
QueryWrapper<FlowTaskOperatorEntity> operatorWrapper = new QueryWrapper<>();
operatorWrapper.lambda().eq(FlowTaskOperatorEntity::getHandleId, fromId);
List<FlowTaskOperatorEntity> list = flowTaskOperatorService.list(operatorWrapper);
List<String> taskIdList = list.stream().map(FlowTaskOperatorEntity::getTaskId).collect(Collectors.toList());
List<FlowTaskEntity> taskList = getOrderStaList(taskIdList);
List<FlowTemplateEntity> waitTemplateList = flowTemplateService.getTemplateList(taskList.stream().map(FlowTaskEntity::getTemplateId).collect(Collectors.toList()));
List<FlowWorkModel> waitList = new ArrayList<>();
for (FlowTaskOperatorEntity entity : list) {
FlowWorkModel workModel = JsonUtil.getJsonToBean(entity, FlowWorkModel.class);
FlowTaskEntity taskEntity = taskList.stream().filter(t -> t.getId().equals(entity.getTaskId())).findFirst().orElse(null);
if (taskEntity != null) {
workModel.setFullName(taskEntity.getFullName());
FlowTemplateEntity templateEntity = waitTemplateList.stream().filter(t -> t.getId().equals(taskEntity.getTemplateId())).findFirst().orElse(null);
if (templateEntity != null) {
workModel.setIcon(templateEntity.getIcon());
}
}
waitList.add(workModel);
}
vo.setWait(waitList);
//流程
QueryWrapper<FlowTemplateJsonEntity> queryWrapper = new QueryWrapper<>();
List<FlowTemplateJsonEntity> templateJsonList = flowTemplateJsonService.list(queryWrapper).stream().filter(t -> t.getFlowTemplateJson().contains(fromId)).collect(Collectors.toList());
List<String> templateIdList = templateJsonList.stream().map(FlowTemplateJsonEntity::getTemplateId).collect(Collectors.toList());
List<FlowTemplateEntity> templateList = flowTemplateService.getTemplateList(templateIdList);
List<FlowWorkModel> flowList = new ArrayList<>();
for (FlowTemplateJsonEntity entity : templateJsonList) {
FlowWorkModel workModel = JsonUtil.getJsonToBean(entity, FlowWorkModel.class);
FlowTemplateEntity templateEntity = templateList.stream().filter(t -> t.getId().equals(entity.getTemplateId())).findFirst().orElse(null);
if (templateEntity != null) {
workModel.setFullName(templateEntity.getFullName() + "_" + entity.getFullName() + "(V" + entity.getVersion() + ")");
workModel.setIcon(templateEntity.getIcon());
}
flowList.add(workModel);
}
vo.setFlow(flowList);
return vo;
}
@Override
@Transactional
public boolean flowWork(WorkHandoverModel workHandoverModel) {
String fromId = workHandoverModel.getFromId();
String toId = workHandoverModel.getToId();
List<String> waitList = workHandoverModel.getWaitList();
//待办事宜
if (waitList.size() > 0) {
UpdateWrapper<FlowTaskOperatorEntity> operator = new UpdateWrapper<>();
operator.lambda().in(FlowTaskOperatorEntity::getId, waitList);
operator.lambda().eq(FlowTaskOperatorEntity::getHandleId, fromId);
operator.lambda().set(FlowTaskOperatorEntity::getHandleId, toId);
flowTaskOperatorService.update(operator);
UpdateWrapper<FlowOperatorUserEntity> userOperator = new UpdateWrapper<>();
userOperator.lambda().in(FlowOperatorUserEntity::getId, waitList);
userOperator.lambda().eq(FlowOperatorUserEntity::getHandleId, fromId);
userOperator.lambda().set(FlowOperatorUserEntity::getHandleId, toId);
flowOperatorUserService.update(userOperator);
UpdateWrapper<FlowCandidatesEntity> candidates = new UpdateWrapper<>();
candidates.lambda().in(FlowCandidatesEntity::getId, waitList);
candidates.lambda().eq(FlowCandidatesEntity::getHandleId, fromId);
candidates.lambda().set(FlowCandidatesEntity::getHandleId, toId);
flowCandidatesService.update(candidates);
}
//负责流程
List<String> flowList = workHandoverModel.getFlowList();
if (flowList.size() > 0) {
UserEntity toUser = serviceUtil.getUserInfo(toId);
String toUserName = toUser != null ? toUser.getRealName() + "/" + toUser.getAccount() : "";
UserEntity fromUser = serviceUtil.getUserInfo(fromId);
String fromUserName = fromUser != null ? fromUser.getRealName() + "/" + fromUser.getAccount() : "";
//json
List<FlowTemplateJsonEntity> templateJsonList = flowTemplateJsonService.getTemplateJsonList(flowList);
for (FlowTemplateJsonEntity entity : templateJsonList) {
String json = entity.getFlowTemplateJson().replaceAll(fromId, toId).replaceAll(fromUserName, toUserName);
entity.setFlowTemplateJson(json);
flowTemplateJsonService.update(entity.getId(), entity);
}
//任务
QueryWrapper<FlowTaskEntity> taskQueryWrapper = new QueryWrapper<>();
taskQueryWrapper.lambda().in(FlowTaskEntity::getFlowId, flowList);
List<FlowTaskEntity> list = this.list(taskQueryWrapper);
for (FlowTaskEntity entity : list) {
update(entity);
QueryWrapper<FlowTaskNodeEntity> nodeQueryWrapper = new QueryWrapper<>();
nodeQueryWrapper.lambda().eq(FlowTaskNodeEntity::getTaskId, entity.getId());
List<FlowTaskNodeEntity> nodeList = flowTaskNodeService.list(nodeQueryWrapper);
for (FlowTaskNodeEntity taskNodeEntity : nodeList) {
taskNodeEntity.setNodePropertyJson(taskNodeEntity.getNodePropertyJson().replaceAll(fromId, toId).replaceAll(fromUserName, toUserName));
flowTaskNodeService.update(taskNodeEntity);
}
}
//流程可见
List<String> templateIdList = templateJsonList.stream().map(FlowTemplateJsonEntity::getTemplateId).collect(Collectors.toList());
if (templateIdList.size() > 0) {
UpdateWrapper<FlowEngineVisibleEntity> visibleWrapper = new UpdateWrapper<>();
visibleWrapper.lambda().eq(FlowEngineVisibleEntity::getOperatorId, fromId);
visibleWrapper.lambda().in(FlowEngineVisibleEntity::getFlowId, templateIdList);
visibleWrapper.lambda().set(FlowEngineVisibleEntity::getOperatorId, toId);
flowEngineVisibleService.update(visibleWrapper);
}
}
return true;
}
/**
* 验证有效状态
*
* @param status 状态编码
* @return
*/
private boolean checkStatus(int status) {
List<Integer> statusList = ImmutableList.of(FlowTaskStatusEnum.Draft.getCode(), FlowTaskStatusEnum.Reject.getCode(),
FlowTaskStatusEnum.Revoke.getCode(), FlowTaskStatusEnum.Resubmit.getCode());
if (statusList.contains(status)) {
return true;
} else {
return false;
}
}
/**
* 递归删除所有子节点
*
* @param idList
* @param isRecord
* @param isCirculate
*/
private void deleteAll(List<String> idList, boolean isRecord, boolean isCirculate) {
List<String> idAll = new ArrayList<>();
this.deleTaskAll(idList, idAll);
if (idAll.size() > 0) {
QueryWrapper<FlowTaskEntity> task = new QueryWrapper<>();
task.lambda().in(FlowTaskEntity::getId, idAll);
this.remove(task);
QueryWrapper<FlowCandidatesEntity> candidates = new QueryWrapper<>();
candidates.lambda().in(FlowCandidatesEntity::getTaskId, idAll);
flowCandidatesService.remove(candidates);
QueryWrapper<FlowCommentEntity> comment = new QueryWrapper<>();
comment.lambda().in(FlowCommentEntity::getTaskId, idAll);
flowCommentService.remove(comment);
QueryWrapper<FlowAuthorizeEntity> authorize = new QueryWrapper<>();
authorize.lambda().in(FlowAuthorizeEntity::getTaskId, idAll);
flowAuthorizeService.remove(authorize);
QueryWrapper<FlowUserEntity> user = new QueryWrapper<>();
user.lambda().in(FlowUserEntity::getTaskId, idAll);
flowUserService.remove(user);
QueryWrapper<FlowTaskNodeEntity> node = new QueryWrapper<>();
node.lambda().in(FlowTaskNodeEntity::getTaskId, idAll);
flowTaskNodeService.remove(node);
QueryWrapper<FlowTaskOperatorEntity> operator = new QueryWrapper<>();
operator.lambda().in(FlowTaskOperatorEntity::getTaskId, idAll);
flowTaskOperatorService.remove(operator);
QueryWrapper<FlowOperatorUserEntity> operatorUser = new QueryWrapper<>();
operatorUser.lambda().in(FlowOperatorUserEntity::getTaskId, idAll);
flowOperatorUserService.remove(operatorUser);
QueryWrapper<FlowRejectDataEntity> rejectData = new QueryWrapper<>();
rejectData.lambda().in(FlowRejectDataEntity::getId, idAll);
flowRejectDataService.remove(rejectData);
QueryWrapper<FlowTaskOperatorRecordEntity> record = new QueryWrapper<>();
record.lambda().in(FlowTaskOperatorRecordEntity::getTaskId, idAll);
flowTaskOperatorRecordService.remove(record);
QueryWrapper<FlowTaskCirculateEntity> circulate = new QueryWrapper<>();
circulate.lambda().in(FlowTaskCirculateEntity::getTaskId, idAll);
flowTaskCirculateService.remove(circulate);
}
}
}

View File

@@ -0,0 +1,309 @@
package com.yunzhupaas.engine.service.impl;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.toolkit.JoinWrappers;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.google.common.collect.ImmutableList;
import com.yunzhupaas.base.service.SuperServiceImpl;
import com.yunzhupaas.constant.MsgCode;
import com.yunzhupaas.engine.entity.FlowTemplateEntity;
import com.yunzhupaas.engine.entity.FlowTemplateJsonEntity;
import com.yunzhupaas.engine.mapper.FlowTemplateJsonMapper;
import com.yunzhupaas.engine.model.flowengine.FlowPagination;
import com.yunzhupaas.engine.model.flowengine.shuntjson.childnode.ChildNode;
import com.yunzhupaas.engine.model.flowengine.shuntjson.childnode.MsgConfig;
import com.yunzhupaas.engine.model.flowengine.shuntjson.childnode.Properties;
import com.yunzhupaas.engine.model.flowengine.shuntjson.nodejson.ChildNodeList;
import com.yunzhupaas.engine.model.flowengine.shuntjson.nodejson.ConditionList;
import com.yunzhupaas.engine.model.flowtemplate.FlowSelectVO;
import com.yunzhupaas.engine.model.flowtemplatejson.FlowTemplateJsonPage;
import com.yunzhupaas.engine.service.FlowTemplateJsonService;
import com.yunzhupaas.engine.util.FlowJsonUtil;
import com.yunzhupaas.exception.WorkFlowException;
import com.yunzhupaas.util.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
/**
* 流程引擎
*
* @author 云筑产品开发平台组
* @version V3.4.2
* @copyright 深圳市乐程软件有限公司
* @date 2024年7月11日 上午9:18
*/
@Service
public class FlowTemplateJsonServiceImpl extends SuperServiceImpl<FlowTemplateJsonMapper, FlowTemplateJsonEntity> implements FlowTemplateJsonService {
@Autowired
private ServiceAllUtil serviceUtil;
@Override
public List<FlowTemplateJsonEntity> getTemplateList(List<String> id) {
List<FlowTemplateJsonEntity> list = new ArrayList<>();
if (id.size() > 0) {
QueryWrapper<FlowTemplateJsonEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().in(FlowTemplateJsonEntity::getTemplateId, id);
queryWrapper.lambda().orderByDesc(FlowTemplateJsonEntity::getDeleteMark);
list = this.list(queryWrapper);
}
return list;
}
@Override
public List<FlowTemplateJsonEntity> getTemplateJsonList(List<String> id) {
List<FlowTemplateJsonEntity> list = new ArrayList<>();
if (id.size() > 0) {
QueryWrapper<FlowTemplateJsonEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().in(FlowTemplateJsonEntity::getId, id);
queryWrapper.lambda().orderByDesc(FlowTemplateJsonEntity::getDeleteMark);
list = this.list(queryWrapper);
}
return list;
}
@Override
public List<FlowTemplateJsonEntity> getListPage(FlowTemplateJsonPage pagination, boolean isPage) {
if (StringUtil.isNotEmpty(pagination.getFlowId())) {
FlowTemplateJsonEntity info = getJsonInfo(pagination.getFlowId());
if (info != null) {
pagination.setGroupId(info.getGroupId());
}
}
QueryWrapper<FlowTemplateJsonEntity> queryWrapper = new QueryWrapper<>();
//关键字(流程名称、流程编码)
String keyWord = pagination.getKeyword();
if (ObjectUtil.isNotEmpty(keyWord)) {
queryWrapper.lambda().like(FlowTemplateJsonEntity::getVersion, keyWord);
}
//流程id
String templateId = pagination.getTemplateId();
if (ObjectUtil.isNotEmpty(templateId)) {
queryWrapper.lambda().eq(FlowTemplateJsonEntity::getTemplateId, templateId);
}
//流程状态
Integer enableMark = pagination.getEnabledMark();
if (ObjectUtil.isNotEmpty(enableMark)) {
queryWrapper.lambda().eq(FlowTemplateJsonEntity::getEnabledMark, enableMark);
}
//流程分组
String groupId = pagination.getGroupId();
if (ObjectUtil.isNotEmpty(groupId)) {
queryWrapper.lambda().eq(FlowTemplateJsonEntity::getGroupId, groupId);
}
//日期范围近7天、近1月、近3月、自定义
if (ObjectUtil.isNotEmpty(pagination.getStartTime()) && ObjectUtil.isNotEmpty(pagination.getEndTime())) {
queryWrapper.lambda().between(FlowTemplateJsonEntity::getCreatorTime, new Date(pagination.getStartTime()), new Date(pagination.getEndTime()));
}
queryWrapper.lambda().orderByDesc(FlowTemplateJsonEntity::getEnabledMark).orderByDesc(FlowTemplateJsonEntity::getCreatorTime);
if (isPage) {
Page<FlowTemplateJsonEntity> page = new Page<>(pagination.getCurrentPage(), pagination.getPageSize());
IPage<FlowTemplateJsonEntity> userPage = this.page(page, queryWrapper);
return pagination.setData(userPage.getRecords(), page.getTotal());
} else {
queryWrapper.lambda().select(FlowTemplateJsonEntity::getId, FlowTemplateJsonEntity::getGroupId);
return list(queryWrapper);
}
}
@Override
public List<FlowSelectVO> getChildListPage(FlowPagination pagination) {
MPJLambdaWrapper<FlowTemplateJsonEntity> wrapper = JoinWrappers.lambda(FlowTemplateJsonEntity.class)
.select(FlowTemplateJsonEntity::getFullName, FlowTemplateJsonEntity::getId)
.leftJoin(FlowTemplateEntity.class, FlowTemplateEntity::getId, FlowTemplateJsonEntity::getTemplateId)
.selectAs(FlowTemplateEntity::getFullName, FlowSelectVO::getFlowName)
.selectAs(FlowTemplateEntity::getType, FlowSelectVO::getFlowType)
.eq(FlowTemplateEntity::getEnabledMark, 1)
.eq(FlowTemplateJsonEntity::getEnabledMark, 1)
.eq(FlowTemplateJsonEntity::getVisibleType, 0);
if (ObjectUtil.isNotEmpty(pagination.getKeyword())) {
wrapper.like(FlowTemplateJsonEntity::getFullName, pagination.getKeyword());
}
if (ObjectUtil.isNotEmpty(pagination.getFlowType())) {
wrapper.eq(FlowTemplateEntity::getType, pagination.getFlowType());
}
wrapper.orderByAsc(FlowTemplateEntity::getSortCode).orderByDesc(FlowTemplateEntity::getCreatorTime);
Page<FlowSelectVO> page = new Page<>(pagination.getCurrentPage(), pagination.getPageSize());
Page<FlowSelectVO> data = this.selectJoinListPage(page, FlowSelectVO.class, wrapper);
return pagination.setData(data.getRecords(), page.getTotal());
}
@Override
public List<FlowTemplateJsonEntity> getMainList(List<String> templaIdList) {
List<FlowTemplateJsonEntity> list = new ArrayList<>();
if (templaIdList.size() > 0) {
QueryWrapper<FlowTemplateJsonEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().in(FlowTemplateJsonEntity::getTemplateId, templaIdList);
queryWrapper.lambda().eq(FlowTemplateJsonEntity::getEnabledMark, 1);
queryWrapper.lambda().orderByAsc(FlowTemplateJsonEntity::getSortCode);
list.addAll(this.list(queryWrapper));
}
return list;
}
@Override
public FlowTemplateJsonEntity getInfo(String id) throws WorkFlowException {
QueryWrapper<FlowTemplateJsonEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(FlowTemplateJsonEntity::getId, id);
FlowTemplateJsonEntity templateJsonEntity = this.getOne(queryWrapper);
if (templateJsonEntity == null) {
throw new WorkFlowException(MsgCode.FA001.get());
}
return templateJsonEntity;
}
@Override
public FlowTemplateJsonEntity getJsonInfo(String id) {
QueryWrapper<FlowTemplateJsonEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(FlowTemplateJsonEntity::getId, id);
FlowTemplateJsonEntity templateJsonEntity = this.getOne(queryWrapper);
return templateJsonEntity;
}
@Override
public void create(FlowTemplateJsonEntity entity) {
if (entity.getId() == null) {
entity.setId(RandomUtil.uuId());
}
entity.setCreatorTime(new Date());
entity.setCreatorUserId(UserProvider.getUser().getUserId());
this.save(entity);
}
@Override
public void update(String id, FlowTemplateJsonEntity entity) {
entity.setId(id);
entity.setLastModifyTime(new Date());
entity.setLastModifyUserId(UserProvider.getUser().getUserId());
this.updateById(entity);
}
@Override
public void delete(FlowTemplateJsonEntity entity) {
if (entity != null) {
this.removeById(entity.getId());
}
}
@Override
public List<FlowTemplateJsonEntity> getListAll(List<String> id) {
QueryWrapper<FlowTemplateJsonEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(FlowTemplateJsonEntity::getEnabledMark, 1);
queryWrapper.lambda().and(w -> w.eq(FlowTemplateJsonEntity::getVisibleType, 0).or(!id.isEmpty()).in(!id.isEmpty(), FlowTemplateJsonEntity::getId, id));
queryWrapper.lambda().select(FlowTemplateJsonEntity::getId, FlowTemplateJsonEntity::getTemplateId);
List<FlowTemplateJsonEntity> list = this.list(queryWrapper);
return list;
}
@Override
@DSTransactional
public void templateJsonMajor(String ids) throws WorkFlowException {
String[] idAll = ids.split(",");
for (String id : idAll) {
FlowTemplateJsonEntity templateJson = getInfo(id);
if (StringUtil.isEmpty(templateJson.getFlowTemplateJson())) {
throw new WorkFlowException(MsgCode.WF052.get());
}
List<String> idList = ImmutableList.of(templateJson.getTemplateId());
List<FlowTemplateJsonEntity> list = getTemplateList(idList).stream().filter(t -> t.getGroupId().equals(templateJson.getGroupId())).collect(Collectors.toList());
for (FlowTemplateJsonEntity entity : list) {
if (entity.getEnabledMark() == 1 || entity.getId().equals(templateJson.getId())) {
entity.setEnabledMark(entity.getId().equals(templateJson.getId()) ? 1 : 0);
this.update(entity.getId(), entity);
}
}
}
}
@Override
public List<String> sendMsgConfigList(FlowTemplateJsonEntity engine) {
List<String> sendConfigList = new ArrayList<>();
ChildNode childNodeAll = JsonUtil.getJsonToBean(engine.getFlowTemplateJson(), ChildNode.class);
//获取流程节点
List<ChildNodeList> nodeListAll = new ArrayList<>();
List<ConditionList> conditionListAll = new ArrayList<>();
//递归获取条件数据和节点数据
FlowJsonUtil.getTemplateAll(childNodeAll, nodeListAll, conditionListAll);
for (ChildNodeList childNode : nodeListAll) {
Properties properties = childNode.getProperties();
MsgConfig waitMsgConfig = properties.getWaitMsgConfig();
MsgConfig endMsgConfig = properties.getEndMsgConfig();
MsgConfig approveMsgConfig = properties.getApproveMsgConfig();
MsgConfig rejectMsgConfig = properties.getRejectMsgConfig();
MsgConfig copyMsgConfig = properties.getCopyMsgConfig();
MsgConfig launchMsgConfig = properties.getLaunchMsgConfig();
MsgConfig overtimeMsgConfig = properties.getOvertimeMsgConfig();
MsgConfig noticeMsgConfig = properties.getNoticeMsgConfig();
//流程代办
if (1 == waitMsgConfig.getOn()) {
if (StringUtil.isNotBlank(waitMsgConfig.getMsgId())) {
sendConfigList.add(waitMsgConfig.getMsgId());
}
}
//流程结束
if (1 == endMsgConfig.getOn()) {
if (StringUtil.isNotBlank(endMsgConfig.getMsgId())) {
sendConfigList.add(endMsgConfig.getMsgId());
}
}
//节点同意
if (1 == approveMsgConfig.getOn()) {
if (StringUtil.isNotBlank(approveMsgConfig.getMsgId())) {
sendConfigList.add(approveMsgConfig.getMsgId());
}
}
//节点拒绝
if (1 == rejectMsgConfig.getOn()) {
if (StringUtil.isNotBlank(rejectMsgConfig.getMsgId())) {
sendConfigList.add(rejectMsgConfig.getMsgId());
}
}
//节点抄送
if (1 == copyMsgConfig.getOn()) {
if (StringUtil.isNotBlank(copyMsgConfig.getMsgId())) {
sendConfigList.add(copyMsgConfig.getMsgId());
}
}
//子流程
if (1 == launchMsgConfig.getOn()) {
if (StringUtil.isNotBlank(launchMsgConfig.getMsgId())) {
sendConfigList.add(launchMsgConfig.getMsgId());
}
}
//超时
if (1 == overtimeMsgConfig.getOn()) {
if (StringUtil.isNotBlank(overtimeMsgConfig.getMsgId())) {
sendConfigList.add(overtimeMsgConfig.getMsgId());
}
}
//提醒
if (1 == noticeMsgConfig.getOn()) {
if (StringUtil.isNotBlank(waitMsgConfig.getMsgId())) {
sendConfigList.add(noticeMsgConfig.getMsgId());
}
}
}
sendConfigList = sendConfigList.stream().distinct().collect(Collectors.toList());
return sendConfigList;
}
@Override
public void updateFullName(String groupId, String fullName) {
UpdateWrapper<FlowTemplateJsonEntity> updateWrapper = new UpdateWrapper<>();
updateWrapper.lambda().set(FlowTemplateJsonEntity::getFullName, fullName);
updateWrapper.lambda().eq(FlowTemplateJsonEntity::getGroupId, groupId);
this.update(updateWrapper);
}
}

View File

@@ -0,0 +1,738 @@
package com.yunzhupaas.engine.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.ImmutableList;
import com.yunzhupaas.base.UserInfo;
import com.yunzhupaas.base.entity.DictionaryDataEntity;
import com.yunzhupaas.base.service.SuperServiceImpl;
import com.yunzhupaas.constant.MsgCode;
import com.yunzhupaas.constant.PermissionConst;
import com.yunzhupaas.engine.entity.FlowEngineVisibleEntity;
import com.yunzhupaas.engine.entity.FlowTaskEntity;
import com.yunzhupaas.engine.entity.FlowTemplateEntity;
import com.yunzhupaas.engine.entity.FlowTemplateJsonEntity;
import com.yunzhupaas.engine.mapper.FlowTemplateMapper;
import com.yunzhupaas.engine.model.flowengine.FlowPagination;
import com.yunzhupaas.engine.model.flowengine.shuntjson.childnode.ChildNode;
import com.yunzhupaas.engine.model.flowengine.shuntjson.childnode.MsgConfig;
import com.yunzhupaas.engine.model.flowengine.shuntjson.childnode.Properties;
import com.yunzhupaas.engine.model.flowengine.shuntjson.nodejson.ChildNodeList;
import com.yunzhupaas.engine.model.flowengine.shuntjson.nodejson.ConditionList;
import com.yunzhupaas.engine.model.flowtemplate.FlowExportModel;
import com.yunzhupaas.engine.model.flowtemplate.FlowTemplateInfoVO;
import com.yunzhupaas.engine.model.flowtemplate.FlowTemplateListVO;
import com.yunzhupaas.engine.model.flowtemplate.FlowTemplateVO;
import com.yunzhupaas.engine.model.flowtemplatejson.FlowJsonModel;
import com.yunzhupaas.engine.model.flowtemplatejson.FlowTemplateJsonPage;
import com.yunzhupaas.engine.service.FlowEngineVisibleService;
import com.yunzhupaas.engine.service.FlowTaskService;
import com.yunzhupaas.engine.service.FlowTemplateJsonService;
import com.yunzhupaas.engine.service.FlowTemplateService;
import com.yunzhupaas.engine.util.FlowJsonUtil;
import com.yunzhupaas.exception.WorkFlowException;
import com.yunzhupaas.permission.entity.UserEntity;
import com.yunzhupaas.util.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.stream.Collectors;
/**
* 流程引擎
*
* @author 云筑产品开发平台组
* @version V3.4.2
* @copyright 深圳市乐程软件有限公司
* @date 2024年7月11日 上午9:18
*/
@Service
public class FlowTemplateServiceImpl extends SuperServiceImpl<FlowTemplateMapper, FlowTemplateEntity> implements FlowTemplateService {
@Autowired
private FlowTaskService flowTaskService;
@Autowired
private ServiceAllUtil serviceUtil;
@Autowired
private FlowEngineVisibleService flowEngineVisibleService;
@Autowired
private FlowTemplateJsonService flowTemplateJsonService;
@Override
public List<FlowTemplateEntity> getPageList(FlowPagination pagination) {
// 定义变量判断是否需要使用修改时间倒序
boolean flag = false;
QueryWrapper<FlowTemplateEntity> queryWrapper = new QueryWrapper<>();
if (ObjectUtil.isNotEmpty(pagination.getKeyword())) {
flag = true;
queryWrapper.lambda().and(
t -> t.like(FlowTemplateEntity::getFullName, pagination.getKeyword())
.or().like(FlowTemplateEntity::getEnCode, pagination.getKeyword())
);
}
if (ObjectUtil.isNotEmpty(pagination.getCategory())) {
flag = true;
queryWrapper.lambda().eq(FlowTemplateEntity::getCategory, pagination.getCategory());
}
if (ObjectUtil.isNotEmpty(pagination.getType())) {
flag = true;
queryWrapper.lambda().eq(FlowTemplateEntity::getType, pagination.getType());
}
if (ObjectUtil.isNotEmpty(pagination.getEnabledMark())) {
flag = true;
queryWrapper.lambda().eq(FlowTemplateEntity::getEnabledMark, pagination.getEnabledMark());
}
//排序
queryWrapper.lambda().orderByAsc(FlowTemplateEntity::getSortCode).orderByDesc(FlowTemplateEntity::getCreatorTime);
if (flag) {
queryWrapper.lambda().orderByDesc(FlowTemplateEntity::getLastModifyTime);
}
Page<FlowTemplateEntity> page = new Page<>(pagination.getCurrentPage(), pagination.getPageSize());
IPage<FlowTemplateEntity> userPage = this.page(page, queryWrapper);
return pagination.setData(userPage.getRecords(), page.getTotal());
}
@Override
public FlowTemplateEntity getInfo(String id) throws WorkFlowException {
QueryWrapper<FlowTemplateEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(FlowTemplateEntity::getId, id);
FlowTemplateEntity FlowTemplateEntity = this.getOne(queryWrapper);
if (FlowTemplateEntity == null) {
throw new WorkFlowException(MsgCode.FA001.get());
}
return FlowTemplateEntity;
}
@Override
public boolean isExistByFullName(String fullName, String id) {
QueryWrapper<FlowTemplateEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(FlowTemplateEntity::getFullName, fullName);
queryWrapper.lambda().eq(FlowTemplateEntity::getType, 0);
if (!ObjectUtil.isEmpty(id)) {
queryWrapper.lambda().ne(FlowTemplateEntity::getId, id);
}
return this.count(queryWrapper) > 0 ? true : false;
}
@Override
public boolean isExistByEnCode(String enCode, String id) {
QueryWrapper<FlowTemplateEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(FlowTemplateEntity::getEnCode, enCode);
if (!ObjectUtil.isEmpty(id)) {
queryWrapper.lambda().ne(FlowTemplateEntity::getId, id);
}
return this.count(queryWrapper) > 0 ? true : false;
}
@Override
@DSTransactional
public void create(FlowTemplateEntity entity, List<FlowTemplateJsonEntity> templateJsonList) throws WorkFlowException {
if (isExistByFullName(entity.getFullName(), entity.getId())) {
throw new WorkFlowException(MsgCode.EXIST001.get());
}
if (isExistByEnCode(entity.getEnCode(), entity.getId())) {
throw new WorkFlowException(MsgCode.EXIST002.get());
}
boolean formType = entity.getType() == 1;
UserInfo userInfo = UserProvider.getUser();
entity.setId(StringUtil.isNotEmpty(entity.getId()) ? entity.getId() : RandomUtil.uuId());
entity.setCreatorUserId(userInfo.getUserId());
entity.setCreatorTime(new Date());
entity.setEnabledMark(0);
entity.setLastModifyUserId(null);
entity.setLastModifyTime(null);
this.setIgnoreLogicDelete().removeById(entity.getId());
this.setIgnoreLogicDelete().saveOrUpdate(entity);
this.clearIgnoreLogicDelete();
List<String> tempIdList = ImmutableList.of(entity.getId());
List<FlowTemplateJsonEntity> templateList = flowTemplateJsonService.getTemplateList(tempIdList);
Set<String> formIdList = new HashSet<>();
//保存引擎数据
for (int k = 0; k < templateJsonList.size(); k++) {
FlowTemplateJsonEntity templateJson = templateJsonList.get(k);
templateJson.setId(StringUtil.isNotEmpty(templateJson.getId()) ? templateJson.getId() : RandomUtil.uuId());
templateJson.setTemplateId(entity.getId());
templateJson.setGroupId(StringUtil.isNotEmpty(templateJson.getGroupId()) ? templateJson.getGroupId() : RandomUtil.uuId());
List<FlowEngineVisibleEntity> visibleList = visibleList(templateJson, formType, formIdList);
flowEngineVisibleService.deleteVisible(templateJson.getId());
int version = templateList.stream().filter(t -> t.getGroupId().equals(templateJson.getGroupId())).map(FlowTemplateJsonEntity::getVersion).mapToInt(Integer::parseInt).max().orElse(0) + 1;
templateJson.setVersion(version + "");
templateJson.setSortCode(Long.parseLong(k + ""));
templateJson.setVisibleType(visibleList.size() == 0 ? 0 : 1);
templateJson.setEnabledMark(1);
flowTemplateJsonService.setIgnoreLogicDelete().removeById(templateJson.getId());
flowTemplateJsonService.setIgnoreLogicDelete().saveOrUpdate(templateJson);
flowTemplateJsonService.clearIgnoreLogicDelete();
for (int i = 0; i < visibleList.size(); i++) {
FlowEngineVisibleEntity visibleEntity = visibleList.get(i);
visibleEntity.setId(RandomUtil.uuId());
visibleEntity.setFlowId(templateJson.getId());
visibleEntity.setSortCode(Long.parseLong(i + ""));
flowEngineVisibleService.save(visibleEntity);
}
}
if (formType && formIdList.size() > 1) {
throw new WorkFlowException(MsgCode.WF055.get());
}
serviceUtil.formIdList(new ArrayList<>(formIdList), entity.getId());
}
@Override
public void create(FlowTemplateEntity entity) {
UserInfo userInfo = UserProvider.getUser();
entity.setId(StringUtil.isNotEmpty(entity.getId()) ? entity.getId() : RandomUtil.uuId());
entity.setCreatorUserId(userInfo.getUserId());
entity.setCreatorTime(new Date());
entity.setEnabledMark(0);
this.saveOrUpdate(entity);
}
@Override
public FlowTemplateInfoVO info(String id) throws WorkFlowException {
FlowTemplateEntity flowEntity = getInfo(id);
FlowTemplateInfoVO vo = JsonUtil.getJsonToBean(flowEntity, FlowTemplateInfoVO.class);
FlowTemplateJsonPage page = new FlowTemplateJsonPage();
page.setTemplateId(id);
List<FlowTemplateJsonEntity> listAll = flowTemplateJsonService.getListPage(page, false);
List<FlowTemplateJsonEntity> list = flowTemplateJsonService.getMainList(ImmutableList.of(id));
List<FlowTaskEntity> flowTaskList = flowTaskService.getTemplateIdList(id);
List<FlowJsonModel> templateList = new ArrayList<>();
for (FlowTemplateJsonEntity templateJson : list) {
FlowJsonModel model = new FlowJsonModel();
model.setFlowId(templateJson.getId());
model.setId(templateJson.getId());
model.setFullName(templateJson.getFullName());
model.setFlowTemplateJson(JsonUtil.stringToMap(templateJson.getFlowTemplateJson()));
List<String> flowIdList = listAll.stream().filter(t -> templateJson.getGroupId().equals(t.getGroupId())).map(FlowTemplateJsonEntity::getId).collect(Collectors.toList());
boolean isDelete = flowTaskList.stream().filter(t -> flowIdList.contains(t.getFlowId())).count() > 0;
model.setIsDelete(isDelete);
templateList.add(model);
}
vo.setFlowTemplateJson(JsonUtil.getObjectToString(templateList));
return vo;
}
@Override
@DSTransactional
public FlowTemplateVO updateVisible(String id, FlowTemplateEntity entity, List<FlowTemplateJsonEntity> templateJsonList) throws WorkFlowException {
if (isExistByFullName(entity.getFullName(), id)) {
throw new WorkFlowException(MsgCode.EXIST001.get());
}
if (isExistByEnCode(entity.getEnCode(), id)) {
throw new WorkFlowException(MsgCode.EXIST002.get());
}
boolean formType = entity.getType() == 1;
UserInfo userInfo = UserProvider.getUser();
FlowTemplateVO vo = new FlowTemplateVO();
List<String> listVO = new ArrayList<>();
entity.setId(id);
entity.setLastModifyTime(new Date());
entity.setLastModifyUserId(userInfo.getUserId());
this.saveOrUpdate(entity);
//删除没有用到的流程
List<FlowTemplateJsonEntity> templateList = flowTemplateJsonService.getMainList(ImmutableList.of(entity.getId()));
for (int i = 0; i < templateList.size(); i++) {
FlowTemplateJsonEntity templateJson = templateList.get(i);
List<FlowTaskEntity> flowList = flowTaskService.getFlowList(templateJson.getId());
if (flowList.size() > 0) {
templateList.remove(i);
}
}
List<String> tempJsonIdList = templateList.stream().map(FlowTemplateJsonEntity::getId).collect(Collectors.toList());
List<String> templateJsonId = templateJsonList.stream().filter(t -> StringUtil.isNotEmpty(t.getId())).map(FlowTemplateJsonEntity::getId).collect(Collectors.toList());
tempJsonIdList.removeAll(templateJsonId);
for (String tempJsonId : tempJsonIdList) {
FlowTemplateJsonEntity delTemplateJson = flowTemplateJsonService.getInfo(tempJsonId);
flowEngineVisibleService.deleteVisible(delTemplateJson.getId());
flowTemplateJsonService.delete(delTemplateJson);
}
Set<String> formIdList = new HashSet<>();
//保存引擎数据
for (int k = 0; k < templateJsonList.size(); k++) {
FlowTemplateJsonEntity templateJson = templateJsonList.get(k);
boolean isTempId = StringUtil.isNotEmpty(templateJson.getId());
String jsonId = isTempId ? templateJson.getId() : RandomUtil.uuId();
//json变化才新增版本true=变化
FlowTemplateJsonEntity info = isTempId ? flowTemplateJsonService.getInfo(jsonId) : null;
boolean ischange = info != null && StringUtil.isNotEmpty(info.getFlowTemplateJson()) && !info.getFlowTemplateJson().equals(templateJson.getFlowTemplateJson());
//判断流程任务是否被使用
List<FlowTaskEntity> flowList = flowTaskService.getFlowList(jsonId);
boolean isRand = flowList.size() > 0 && ischange;
templateJson.setId(isRand ? RandomUtil.uuId() : jsonId);
templateJson.setTemplateId(id);
templateJson.setGroupId(isTempId ? info.getGroupId() : RandomUtil.uuId());
int version = 1;
//判断是否在使用,新增版本
if (isRand) {
version = flowTemplateJsonService.getTemplateList(ImmutableList.of(id)).stream().filter(t -> t.getGroupId().equals(templateJson.getGroupId())).map(FlowTemplateJsonEntity::getVersion).mapToInt(Integer::parseInt).max().orElse(0) + 1;
listVO.add(templateJson.getId());
}
List<FlowEngineVisibleEntity> visibleList = visibleList(templateJson, formType, formIdList);
flowEngineVisibleService.deleteVisible(templateJson.getId());
templateJson.setVisibleType(visibleList.size() == 0 ? 0 : 1);
templateJson.setSortCode(Long.parseLong(k + ""));
templateJson.setEnabledMark(isRand ? 0 : isTempId ? info.getEnabledMark() : 1);
templateJson.setVersion(isRand ? version + "" : isTempId ? info.getVersion() : version + "");
flowTemplateJsonService.saveOrUpdate(templateJson);
for (int i = 0; i < visibleList.size(); i++) {
FlowEngineVisibleEntity visibleEntity = visibleList.get(i);
visibleEntity.setId(RandomUtil.uuId());
visibleEntity.setFlowId(templateJson.getId());
visibleEntity.setSortCode(Long.parseLong(i + ""));
flowEngineVisibleService.save(visibleEntity);
}
flowTemplateJsonService.updateFullName(templateJson.getGroupId(), templateJson.getFullName());
}
vo.setIsMainVersion(listVO.size() > 0);
vo.setId(String.join(",", listVO));
if (formType && formIdList.size() > 1) {
throw new WorkFlowException(MsgCode.WF055.get());
}
serviceUtil.formIdList(new ArrayList<>(formIdList), entity.getId());
return vo;
}
@Override
public boolean update(String id, FlowTemplateEntity entity) {
entity.setId(id);
boolean flag = this.updateById(entity);
return flag;
}
@Override
@DSTransactional
public void copy(FlowTemplateEntity entity, List<FlowTemplateJsonEntity> templateJsonEntity) throws WorkFlowException {
try {
String copyNum = UUID.randomUUID().toString().substring(0, 5);
entity.setFullName(entity.getFullName() + ".副本" + copyNum);
entity.setEnCode(entity.getEnCode() + copyNum);
entity.setId(null);
entity.setLastModifyTime(null);
entity.setLastModifyUserId(null);
for (FlowTemplateJsonEntity jsonEntity : templateJsonEntity) {
jsonEntity.setCreatorUserId(UserProvider.getUser().getUserId());
jsonEntity.setCreatorTime(new Date());
jsonEntity.setLastModifyUserId(null);
jsonEntity.setLastModifyTime(null);
jsonEntity.setGroupId(null);
jsonEntity.setId(null);
}
this.create(entity, templateJsonEntity);
} catch (Exception e) {
log.error(e.getMessage());
throw new WorkFlowException(MsgCode.PRI006.get());
}
}
@Override
@DSTransactional
public void delete(FlowTemplateEntity entity) throws WorkFlowException {
List<FlowTaskEntity> flowTaskList = flowTaskService.getTemplateIdList(entity.getId());
if (flowTaskList.size() > 0) {
throw new WorkFlowException(MsgCode.WF057.get());
}
List<FlowTemplateJsonEntity> list = flowTemplateJsonService.getTemplateList(ImmutableList.of(entity.getId()));
this.removeById(entity.getId());
serviceUtil.formIdList(new ArrayList<>(), entity.getId());
for (FlowTemplateJsonEntity templateJson : list) {
List<String> sendConfigIdList = flowTemplateJsonService.sendMsgConfigList(templateJson);
if (sendConfigIdList != null && sendConfigIdList.size() > 0) {
serviceUtil.updateSendConfigUsed(entity.getId(), sendConfigIdList);
}
serviceUtil.deleteFormId(templateJson.getId());
flowEngineVisibleService.deleteVisible(templateJson.getId());
}
}
@Override
public FlowExportModel exportData(String id) throws WorkFlowException {
FlowTemplateEntity entity = getInfo(id);
List<FlowTemplateJsonEntity> templateJsonList = flowTemplateJsonService.getMainList(ImmutableList.of(id));
FlowExportModel model = new FlowExportModel();
model.setFlowTemplate(entity);
model.setFlowTemplateJson(templateJsonList);
return model;
}
@Override
@DSTransactional
public void ImportData(FlowExportModel flowExportModel, String type) throws WorkFlowException {
FlowTemplateEntity entity = flowExportModel.getFlowTemplate();
List<FlowTemplateJsonEntity> flowTemplateJson = flowExportModel.getFlowTemplateJson();
if (entity != null) {
StringJoiner joiner = new StringJoiner("");
entity.setCreatorUserId(UserProvider.getLoginUserId());
entity.setCreatorTime(new Date());
entity.setLastModifyTime(null);
entity.setLastModifyUserId(null);
entity.setEnabledMark(0);
List<String> templateList = new ArrayList<>();
FlowTemplateEntity templateEntity = Import(entity, type, templateList);
if (templateList.size() > 0) {
joiner.add(String.join("", templateList) + "重复");
}
List<FlowTemplateJsonEntity> jsonList = new ArrayList<>();
if (ObjectUtil.isNotEmpty(flowTemplateJson)) {
List<String> idList = new ArrayList<>();
List<String> nameList = new ArrayList<>();
StringJoiner childJoiner = new StringJoiner("");
for (FlowTemplateJsonEntity templateJsonEntity : flowTemplateJson) {
templateJsonEntity.setCreatorUserId(UserProvider.getLoginUserId());
templateJsonEntity.setCreatorTime(new Date());
templateJsonEntity.setLastModifyTime(null);
templateJsonEntity.setLastModifyUserId(null);
templateJsonEntity.setGroupId(null);
FlowTemplateJsonEntity jsonEntity = Import(templateJsonEntity, type, idList, nameList);
jsonList.add(jsonEntity);
}
if (idList.size() > 0) {
childJoiner.add("ID(" + String.join("", idList) + ")");
}
if (nameList.size() > 0) {
childJoiner.add("名称(" + String.join("", nameList) + ")");
}
if (childJoiner.length() > 0) {
joiner.add("flowTemplateJson" + childJoiner + "重复");
}
}
if (StringUtil.isNotEmpty(joiner.toString())) {
throw new WorkFlowException(joiner.toString());
}
create(templateEntity, jsonList);
}
}
@Override
public List<FlowTemplateListVO> getSelectList() {
FlowPagination pagination = new FlowPagination();
pagination.setFlowType(0);
List<FlowTemplateEntity> data = getListAll(pagination, false);
List<DictionaryDataEntity> dictionList = serviceUtil.getDiList();
Map<String, List<FlowTemplateEntity>> dataList = data.stream().collect(Collectors.groupingBy(FlowTemplateEntity::getCategory));
List<FlowTemplateListVO> listVOS = new LinkedList<>();
for (DictionaryDataEntity entity : dictionList) {
FlowTemplateListVO model = new FlowTemplateListVO();
model.setFullName(entity.getFullName());
model.setId(entity.getId());
List<FlowTemplateEntity> childList = dataList.get(entity.getId()) != null ? dataList.get(entity.getId()) : new ArrayList<>();
model.setNum(childList.size());
if (childList.size() > 0) {
model.setChildren(JsonUtil.getJsonToList(childList, FlowTemplateListVO.class));
}
listVOS.add(model);
}
return listVOS;
}
@Override
public List<FlowTemplateListVO> getTreeList() {
FlowPagination pagination = new FlowPagination();
List<FlowTemplateEntity> data = getListAll(pagination, false);
List<DictionaryDataEntity> dictionList = serviceUtil.getDiList();
Map<Integer, List<FlowTemplateEntity>> typeList = data.stream().collect(Collectors.groupingBy(FlowTemplateEntity::getType));
List<FlowTemplateListVO> listVOS = new LinkedList<>();
for (Integer key : typeList.keySet()) {
boolean type = Objects.equals(0, key);
//发起类型
FlowTemplateListVO model = new FlowTemplateListVO();
model.setId(key + "");
model.setFullName(type ? "发起流程" : "功能流程");
model.setDisabled(true);
Map<String, List<FlowTemplateEntity>> dataList = typeList.get(key).stream().collect(Collectors.groupingBy(FlowTemplateEntity::getCategory));
List<FlowTemplateListVO> dictionListVOS = new LinkedList<>();
for (DictionaryDataEntity entity : dictionList) {
FlowTemplateListVO dictionModel = new FlowTemplateListVO();
dictionModel.setFullName(entity.getFullName());
dictionModel.setId(RandomUtil.uuId());
List<FlowTemplateEntity> childList = dataList.get(entity.getId()) != null ? dataList.get(entity.getId()) : new ArrayList<>();
dictionModel.setDisabled(true);
if (childList.size() > 0) {
dictionModel.setChildren(JsonUtil.getJsonToList(childList, FlowTemplateListVO.class));
dictionModel.setNum(childList.size());
dictionListVOS.add(dictionModel);
}
}
if (dictionListVOS.size() > 0) {
model.setChildren(dictionListVOS);
listVOS.add(model);
}
}
return listVOS;
}
@Override
public List<FlowTemplateEntity> getTemplateList(List<String> id) {
List<FlowTemplateEntity> list = new ArrayList<>();
if (id.size() > 0) {
QueryWrapper<FlowTemplateEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().in(FlowTemplateEntity::getId, id);
list = this.list(queryWrapper);
}
return list;
}
@Override
public FlowTemplateEntity getFlowIdByCode(String code) throws WorkFlowException {
QueryWrapper<FlowTemplateEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(FlowTemplateEntity::getEnCode, code);
FlowTemplateEntity FlowTemplateEntity = this.getOne(queryWrapper);
if (FlowTemplateEntity == null) {
throw new WorkFlowException(MsgCode.FA001.get());
}
return FlowTemplateEntity;
}
@Override
public List<FlowTemplateEntity> getListAll(FlowPagination pagination, boolean isPage) {
// 定义变量判断是否需要使用修改时间倒序
boolean flag = false;
QueryWrapper<FlowTemplateEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(FlowTemplateEntity::getEnabledMark, 1);
if (ObjectUtil.isNotEmpty(pagination.getFlowType())) {
flag = true;
queryWrapper.lambda().eq(FlowTemplateEntity::getType, pagination.getFlowType());
}
if (ObjectUtil.isNotEmpty(pagination.getKeyword())) {
flag = true;
queryWrapper.lambda().like(FlowTemplateEntity::getFullName, pagination.getKeyword());
}
if (ObjectUtil.isNotEmpty(pagination.getCategory())) {
flag = true;
queryWrapper.lambda().eq(FlowTemplateEntity::getCategory, pagination.getCategory());
}
if (ObjectUtil.isNotEmpty(pagination.getTemplateIdList())) {
queryWrapper.lambda().in(FlowTemplateEntity::getId, pagination.getTemplateIdList());
}
queryWrapper.lambda().orderByAsc(FlowTemplateEntity::getSortCode).orderByDesc(FlowTemplateEntity::getCreatorTime);
if (flag) {
queryWrapper.lambda().orderByDesc(FlowTemplateEntity::getLastModifyTime);
}
queryWrapper.lambda().select(
FlowTemplateEntity::getId, FlowTemplateEntity::getEnCode,
FlowTemplateEntity::getFullName,
FlowTemplateEntity::getType, FlowTemplateEntity::getIcon,
FlowTemplateEntity::getCategory, FlowTemplateEntity::getIconBackground,
FlowTemplateEntity::getCreatorUserId, FlowTemplateEntity::getSortCode,
FlowTemplateEntity::getEnabledMark, FlowTemplateEntity::getCreatorTime
);
if (isPage) {
Page<FlowTemplateEntity> page = new Page<>(pagination.getCurrentPage(), pagination.getPageSize());
IPage<FlowTemplateEntity> userPage = this.page(page, queryWrapper);
return pagination.setData(userPage.getRecords(), page.getTotal());
} else {
return this.list(queryWrapper);
}
}
@Override
public List<FlowTemplateEntity> getListByFlowIds(FlowPagination pagination, List<String> listAll, Boolean isAll, Boolean isPage, String userId) {
// 定义变量判断是否需要使用修改时间倒序
boolean flag = false;
QueryWrapper<FlowTemplateEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(FlowTemplateEntity::getEnabledMark, 1);
List<String> listIn = new ArrayList<>();
List<String> listVisible = null;
if (StringUtil.isNotEmpty(userId)) {//当用户不为空的时候【判断该用户的权限
UserEntity userInfo = serviceUtil.getUserInfo(userId);
boolean visibleType = "1".equals(userInfo.getIsAdministrator());
if (!visibleType) {
List<String> id = flowEngineVisibleService.getVisibleFlowList(userInfo.getId()).stream().map(FlowEngineVisibleEntity::getFlowId).collect(Collectors.toList());
//可见列表
listVisible = flowTemplateJsonService.getListAll(id).stream().map(FlowTemplateJsonEntity::getTemplateId).collect(Collectors.toList());
}
if (CollectionUtil.isNotEmpty(listVisible) && CollectionUtil.isNotEmpty(listAll)) {
for (String str : listAll) {
if (listVisible.contains(str)) {
listIn.add(str);
}
}
} else if (isAll) {
listIn = listVisible;
}
} else {//不判断用户权限
listIn = listAll;
}
if (CollectionUtil.isEmpty(listIn) && !isAll) {
return new ArrayList<>();
}
if (CollectionUtil.isNotEmpty(listIn)) {
queryWrapper.lambda().in(FlowTemplateEntity::getId, listIn);
}
if (ObjectUtil.isNotEmpty(pagination.getKeyword())) {
flag = true;
queryWrapper.lambda().like(FlowTemplateEntity::getFullName, pagination.getKeyword());
}
if (ObjectUtil.isNotEmpty(pagination.getCategory())) {
flag = true;
queryWrapper.lambda().eq(FlowTemplateEntity::getCategory, pagination.getCategory());
}
if (ObjectUtil.isNotEmpty(pagination.getFlowType())) {
flag = true;
queryWrapper.lambda().eq(FlowTemplateEntity::getType, pagination.getFlowType());
}
queryWrapper.lambda().orderByAsc(FlowTemplateEntity::getSortCode).orderByDesc(FlowTemplateEntity::getCreatorTime);
if (flag) {
queryWrapper.lambda().orderByDesc(FlowTemplateEntity::getLastModifyTime);
}
queryWrapper.lambda().select(
FlowTemplateEntity::getId, FlowTemplateEntity::getEnCode,
FlowTemplateEntity::getFullName,
FlowTemplateEntity::getType, FlowTemplateEntity::getIcon,
FlowTemplateEntity::getCategory, FlowTemplateEntity::getIconBackground,
FlowTemplateEntity::getCreatorUserId, FlowTemplateEntity::getSortCode,
FlowTemplateEntity::getEnabledMark, FlowTemplateEntity::getCreatorTime
);
if (isPage) {
Page<FlowTemplateEntity> page = new Page<>(pagination.getCurrentPage(), pagination.getPageSize());
IPage<FlowTemplateEntity> userPage = this.page(page, queryWrapper);
return pagination.setData(userPage.getRecords(), page.getTotal());
} else {
return list(queryWrapper);
}
}
@Override
public void saveLogicFlowAndForm(String id) {
FlowTemplateEntity flowEnt = this.setIgnoreLogicDelete().getById(id);
if (flowEnt != null) {
flowEnt.setDeleteMark(null);
this.setIgnoreLogicDelete().updateById(flowEnt);
QueryWrapper<FlowTemplateJsonEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(FlowTemplateJsonEntity::getTemplateId, id);
List<FlowTemplateJsonEntity> list = flowTemplateJsonService.setIgnoreLogicDelete().list(queryWrapper);
list.forEach(t -> t.setDeleteMark(null));
flowTemplateJsonService.setIgnoreLogicDelete().updateBatchById(list);
}
this.clearIgnoreLogicDelete();
}
private List<FlowEngineVisibleEntity> visibleList(FlowTemplateJsonEntity entity, boolean formType, Set<String> formIdList) throws WorkFlowException {
List<FlowEngineVisibleEntity> visibleList = new ArrayList<>();
String templeId = entity.getTemplateId();
String formData = StringUtil.isNotEmpty(entity.getFlowTemplateJson()) ? entity.getFlowTemplateJson() : "{}";
ChildNode childNode = JsonUtil.getJsonToBean(formData, ChildNode.class);
Properties properties = childNode.getProperties();
if (StringUtil.isNotEmpty(properties.getFormId())) {
formIdList.add(properties.getFormId());
}
//流程可见
for (String initiator : properties.getInitiator()) {
String type = initiator.split("--").length > 1 ? initiator.split("--")[1] : PermissionConst.USER;
String operatorId = initiator.split("--")[0];
FlowEngineVisibleEntity visible = new FlowEngineVisibleEntity();
visible.setOperatorId(operatorId);
visible.setOperatorType(type);
visible.setType(1);
visibleList.add(visible);
}
List<ChildNodeList> nodeListAll = new ArrayList<>();
List<ConditionList> conditionListAll = new ArrayList<>();
FlowJsonUtil.getTemplateAll(childNode, nodeListAll, conditionListAll);
List<String> sendIdList = new ArrayList<>();
for (ChildNodeList childNodeList : nodeListAll) {
Properties childProperties = childNodeList.getProperties();
MsgConfig waitMsgConfig = childProperties.getWaitMsgConfig();
if (StringUtil.isNotEmpty(waitMsgConfig.getMsgId())) {
sendIdList.add(waitMsgConfig.getMsgId());
}
MsgConfig endMsgConfig = childProperties.getEndMsgConfig();
if (StringUtil.isNotEmpty(endMsgConfig.getMsgId())) {
sendIdList.add(endMsgConfig.getMsgId());
}
MsgConfig approveMsgConfig = childProperties.getApproveMsgConfig();
if (StringUtil.isNotEmpty(approveMsgConfig.getMsgId())) {
sendIdList.add(approveMsgConfig.getMsgId());
}
MsgConfig rejectMsgConfig = childProperties.getRejectMsgConfig();
if (StringUtil.isNotEmpty(rejectMsgConfig.getMsgId())) {
sendIdList.add(rejectMsgConfig.getMsgId());
}
MsgConfig copyMsgConfig = childProperties.getCopyMsgConfig();
if (StringUtil.isNotEmpty(copyMsgConfig.getMsgId())) {
sendIdList.add(copyMsgConfig.getMsgId());
}
MsgConfig launchMsgConfig = childProperties.getLaunchMsgConfig();
if (StringUtil.isNotEmpty(launchMsgConfig.getMsgId())) {
sendIdList.add(launchMsgConfig.getMsgId());
}
MsgConfig overtimeMsgConfig = childProperties.getOvertimeMsgConfig();
if (StringUtil.isNotEmpty(overtimeMsgConfig.getMsgId())) {
sendIdList.add(overtimeMsgConfig.getMsgId());
}
MsgConfig noticeMsgConfig = childProperties.getNoticeMsgConfig();
if (StringUtil.isNotEmpty(noticeMsgConfig.getMsgId())) {
sendIdList.add(noticeMsgConfig.getMsgId());
}
}
entity.setSendConfigIds(JsonUtil.getObjectToString(sendIdList));
return visibleList;
}
private FlowTemplateEntity Import(FlowTemplateEntity templateEntity, String type, List<String> errList) {
FlowTemplateEntity entity = JsonUtil.getJsonToBean(templateEntity, FlowTemplateEntity.class);
boolean skip = Objects.equals("0", type);
int num = 0;
QueryWrapper<FlowTemplateEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(FlowTemplateEntity::getId, entity.getId());
if (this.count(queryWrapper) > 0) {
num++;
if (skip) {
errList.add("ID");
}
}
queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(FlowTemplateEntity::getEnCode, entity.getEnCode());
if (this.count(queryWrapper) > 0) {
num++;
if (skip) {
errList.add("编码");
}
}
queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(FlowTemplateEntity::getFullName, entity.getFullName());
if (this.count(queryWrapper) > 0) {
num++;
if (skip) {
errList.add("名称");
}
}
if (num > 0 && !skip) {
String copyNum = UUID.randomUUID().toString().substring(0, 5);
entity.setFullName(entity.getFullName() + ".副本" + copyNum);
entity.setEnCode(entity.getEnCode() + copyNum);
}
entity.setId(RandomUtil.uuId());
return entity;
}
private FlowTemplateJsonEntity Import(FlowTemplateJsonEntity templateEntity, String type, List<String> idList, List<String> nameList) {
FlowTemplateJsonEntity entity = JsonUtil.getJsonToBean(templateEntity, FlowTemplateJsonEntity.class);
boolean skip = Objects.equals("0", type);
QueryWrapper<FlowTemplateJsonEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(FlowTemplateJsonEntity::getId, entity.getId());
if (flowTemplateJsonService.count(queryWrapper) > 0) {
if (skip) {
idList.add(entity.getId());
}
}
queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(FlowTemplateJsonEntity::getFullName, entity.getFullName());
queryWrapper.lambda().eq(FlowTemplateJsonEntity::getTemplateId, entity.getId());
if (flowTemplateJsonService.count(queryWrapper) > 0) {
if (skip) {
nameList.add(entity.getFullName());
}
}
entity.setId(RandomUtil.uuId());
return entity;
}
}

View File

@@ -0,0 +1,61 @@
package com.yunzhupaas.engine.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yunzhupaas.base.service.SuperServiceImpl;
import com.yunzhupaas.engine.entity.FlowUserEntity;
import com.yunzhupaas.engine.mapper.FlowUserMapper;
import com.yunzhupaas.engine.service.FlowUserService;
import com.yunzhupaas.util.RandomUtil;
import org.springframework.stereotype.Service;
/**
* 流程发起用户信息
*
* @author 云筑产品开发平台组
* @version V3.1.0
* @copyright 深圳市乐程软件有限公司
*/
@Service
public class FlowUserServiceImpl extends SuperServiceImpl<FlowUserMapper, FlowUserEntity> implements FlowUserService {
@Override
public FlowUserEntity getInfo(String id) {
QueryWrapper<FlowUserEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(FlowUserEntity::getId, id);
return this.getOne(queryWrapper);
}
@Override
public FlowUserEntity getTaskInfo(String id) {
QueryWrapper<FlowUserEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(FlowUserEntity::getTaskId, id);
return this.getOne(queryWrapper);
}
@Override
public void create(FlowUserEntity entity) {
entity.setId(RandomUtil.uuId());
this.save(entity);
}
@Override
public void update(String id, FlowUserEntity entity) {
entity.setId(id);
this.updateById(entity);
}
@Override
public void delete(FlowUserEntity entity) {
if (entity != null) {
this.removeById(entity.getId());
}
}
@Override
public void deleteByTaskId(String taskId) {
QueryWrapper<FlowUserEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(FlowUserEntity::getTaskId, taskId);
this.remove(queryWrapper);
}
}

View File

@@ -0,0 +1,927 @@
package com.yunzhupaas.engine.util;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.yunzhupaas.base.ActionResult;
import com.yunzhupaas.base.UserInfo;
import com.yunzhupaas.emnus.TemplateEnum;
import com.yunzhupaas.engine.entity.*;
import com.yunzhupaas.engine.enums.FlowMessageEnum;
import com.yunzhupaas.engine.enums.FlowTaskStatusEnum;
import com.yunzhupaas.engine.model.flowbefore.FlowTemplateAllModel;
import com.yunzhupaas.engine.model.flowdelegate.FlowDelegateModel;
import com.yunzhupaas.engine.model.flowengine.FlowModel;
import com.yunzhupaas.engine.model.flowengine.shuntjson.childnode.Properties;
import com.yunzhupaas.engine.model.flowengine.shuntjson.childnode.*;
import com.yunzhupaas.engine.model.flowengine.shuntjson.nodejson.ChildNodeList;
import com.yunzhupaas.engine.model.flowmessage.FlowEventModel;
import com.yunzhupaas.engine.model.flowmessage.FlowMessageModel;
import com.yunzhupaas.engine.model.flowmessage.FlowMsgModel;
import com.yunzhupaas.engine.model.flowmessage.FlowParameterModel;
import com.yunzhupaas.engine.model.flowtask.FlowContModel;
import com.yunzhupaas.engine.service.FlowDelegateService;
import com.yunzhupaas.engine.service.FlowEventLogService;
import com.yunzhupaas.engine.service.FlowTaskService;
import com.yunzhupaas.exception.WorkFlowException;
import com.yunzhupaas.message.model.SentMessageForm;
import com.yunzhupaas.permission.entity.UserEntity;
import com.yunzhupaas.util.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author :云筑产品开发平台组
* @version: V3.1.0
* @copyright 深圳市乐程软件有限公司
* @date 2022/3/30 11:45
*/
@Component
public class FlowMsgUtil {
@Autowired
private FlowTaskService flowTaskService;
@Autowired
private ServiceAllUtil serviceUtil;
@Autowired
private FlowTaskUtil flowTaskUtil;
@Autowired
private FlowDelegateService flowDelegateService;
@Autowired
private FlowEventLogService flowEventLogService;
/**
* 发送消息
*
* @param flowMsgModel
*/
public void message(FlowMsgModel flowMsgModel) throws WorkFlowException {
List<SentMessageForm> messageListAll = new ArrayList<>();
FlowTaskEntity taskEntity = flowMsgModel.getTaskEntity();
List<String> creatorUserId = new ArrayList<>();
UserEntity user = taskEntity != null ? serviceUtil.getUserInfo(taskEntity.getCreatorUserId()) : null;
if (taskEntity != null) {
creatorUserId.add(taskEntity.getCreatorUserId());
}
FlowTaskNodeEntity flowTaskNode = flowMsgModel.getTaskNodeEntity();
FlowTemplateAllModel flowTemplateAllModel = flowMsgModel.getFlowTemplateAllModel();
List<FlowTaskNodeEntity> nodeList = flowMsgModel.getNodeList();
List<FlowTaskOperatorEntity> operatorList = flowMsgModel.getOperatorList();
List<FlowTaskCirculateEntity> circulateList = flowMsgModel.getCirculateList();
FlowTaskNodeEntity startNode = nodeList.stream().filter(t -> FlowNature.NodeStart.equals(t.getNodeType())).findFirst().orElse(null);
String nodeJson = startNode != null ? startNode.getNodePropertyJson() : "{}";
FlowModel flowModel = flowMsgModel.getFlowModel();
UserInfo userInfo = flowModel.getUserInfo();
FlowTaskOperatorRecordEntity recordEntity = new FlowTaskOperatorRecordEntity();
recordEntity.setTaskId(startNode != null ? startNode.getTaskId() : "");
recordEntity.setHandleId(userInfo != null ? userInfo.getUserId() : "");
//等待
if (flowMsgModel.getWait()) {
ChildNodeList childNode = JsonUtil.getJsonToBean(nodeJson, ChildNodeList.class);
Properties properties = childNode.getProperties();
MsgConfig taskMsgConfig = properties.getWaitMsgConfig();
if (taskMsgConfig.getOn() == 3) {
taskMsgConfig.setMsgId("PZXTLC001");
}
Map<String, List<FlowTaskOperatorEntity>> operatorMap = operatorList.stream().collect(Collectors.groupingBy(FlowTaskOperatorEntity::getTaskNodeId));
for (String key : operatorMap.keySet()) {
recordEntity.setTaskNodeId(key);
List<SentMessageForm> messageList = new ArrayList<>();
List<FlowTaskOperatorEntity> taskOperatorList = operatorMap.get(key);
FlowMessageModel messageModel = new FlowMessageModel();
FlowTaskNodeEntity taskNode = nodeList.stream().filter(t -> t.getId().equals(recordEntity.getTaskNodeId())).findFirst().orElse(null);
Map<String, Object> data = flowTaskUtil.infoData(taskNode.getFormId(), taskNode.getTaskId());
messageModel.setData(data);
messageModel.setMsgConfig(taskMsgConfig);
messageModel.setRecordEntity(recordEntity);
messageModel.setStatus(taskEntity.getStatus());
messageModel.setFullName(taskEntity.getFullName());
// if (StringUtil.isNotEmpty(flowMsgModel.getTitle())) {
// messageModel.setFullName(taskEntity.getFullName() + flowMsgModel.getTitle());
// }
messageModel.setUserInfo(userInfo);
messageModel(taskOperatorList, flowTemplateAllModel, messageModel);
setMessageList(messageList, messageModel);
messageListAll.addAll(messageList);
for (FlowTaskOperatorEntity operator : taskOperatorList) {
List<SentMessageForm> delegationMsg = delegationMsg(operator, messageModel, flowTemplateAllModel);
messageListAll.addAll(delegationMsg);
}
}
}
//结束
if (flowMsgModel.getEnd()) {
//发起人
ChildNodeList childNode = JsonUtil.getJsonToBean(nodeJson, ChildNodeList.class);
Properties properties = childNode.getProperties();
MsgConfig msgConfig = properties.getEndMsgConfig();
if (msgConfig.getOn() == 3) {
msgConfig.setMsgId("PZXTLC010");
}
List<SentMessageForm> messageList = new ArrayList<>();
FlowMessageModel messageModel = new FlowMessageModel();
String formId = properties.getFormId();
Map<String, Object> data = flowTaskUtil.infoData(formId, childNode.getTaskId());
messageModel.setData(data);
messageModel.setTitle("已【结束】");
messageModel.setMsgConfig(msgConfig);
messageModel.setType(FlowMessageEnum.me.getCode());
messageModel.setRecordEntity(recordEntity);
messageModel.setStatus(taskEntity.getStatus());
messageModel.setFullName(taskEntity.getFullName());
messageModel.setUserInfo(userInfo);
List<FlowTaskOperatorEntity> taskOperatorList = new ArrayList() {{
FlowTaskOperatorEntity operatorEntity = new FlowTaskOperatorEntity();
operatorEntity.setTaskId(childNode.getTaskId());
operatorEntity.setTaskNodeId(childNode.getTaskNodeId());
operatorEntity.setHandleId(taskEntity.getCreatorUserId());
add(operatorEntity);
}};
messageModel(taskOperatorList, flowTemplateAllModel, messageModel);
setMessageList(messageList, messageModel);
messageListAll.addAll(messageList);
}
//同意
if (flowMsgModel.getApprove()) {
ChildNodeList childNode = JsonUtil.getJsonToBean(nodeJson, ChildNodeList.class);
Properties properties = childNode.getProperties();
MsgConfig msgConfig = properties.getApproveMsgConfig();
if (msgConfig.getOn() == 3) {
msgConfig.setMsgId("PZXTLC002");
}
Map<String, List<FlowTaskOperatorEntity>> operatorMap = operatorList.stream().collect(Collectors.groupingBy(FlowTaskOperatorEntity::getTaskNodeId));
for (String key : operatorMap.keySet()) {
recordEntity.setTaskNodeId(flowTaskNode.getId());
//默认获取当前节点
FlowTaskNodeEntity taskNode = nodeList.stream().filter(t -> t.getId().equals(recordEntity.getTaskNodeId())).findFirst().orElse(null);
ChildNodeList taskChildNode = JsonUtil.getJsonToBean(taskNode.getNodePropertyJson(), ChildNodeList.class);
Properties taskProperties = taskChildNode.getProperties();
MsgConfig taskMsgConfig = taskProperties.getApproveMsgConfig();
if (taskMsgConfig.getOn() == 2) {
taskMsgConfig = msgConfig;
}
if (taskMsgConfig.getOn() == 3) {
taskMsgConfig.setMsgId("PZXTLC002");
}
List<SentMessageForm> messageList = new ArrayList<>();
List<FlowTaskOperatorEntity> taskOperatorList = operatorMap.get(key);
FlowMessageModel messageModel = new FlowMessageModel();
Map<String, Object> data = flowTaskUtil.infoData(taskNode.getFormId(), taskNode.getTaskId());
messageModel.setData(data);
messageModel.setTitle("已被【同意】");
messageModel.setMsgConfig(taskMsgConfig);
messageModel.setRecordEntity(recordEntity);
messageModel.setStatus(taskEntity.getStatus());
messageModel.setFullName(taskEntity.getFullName());
messageModel.setUserInfo(userInfo);
messageModel(taskOperatorList, flowTemplateAllModel, messageModel);
setMessageList(messageList, messageModel);
messageListAll.addAll(messageList);
for (FlowTaskOperatorEntity operator : taskOperatorList) {
List<SentMessageForm> delegationMsg = delegationMsg(operator, messageModel, flowTemplateAllModel);
messageListAll.addAll(delegationMsg);
}
}
}
//拒绝
if (flowMsgModel.getReject()) {
ChildNodeList childNode = JsonUtil.getJsonToBean(nodeJson, ChildNodeList.class);
Properties properties = childNode.getProperties();
MsgConfig msgConfig = properties.getRejectMsgConfig();
if (msgConfig.getOn() == 3) {
msgConfig.setMsgId("PZXTLC003");
}
Map<String, List<FlowTaskOperatorEntity>> operatorMap = operatorList.stream().collect(Collectors.groupingBy(FlowTaskOperatorEntity::getTaskNodeId));
for (String key : operatorMap.keySet()) {
recordEntity.setTaskNodeId(flowTaskNode.getId());
//默认获取当前节点
FlowTaskNodeEntity taskNode = nodeList.stream().filter(t -> t.getId().equals(recordEntity.getTaskNodeId())).findFirst().orElse(null);
ChildNodeList taskChildNode = JsonUtil.getJsonToBean(taskNode.getNodePropertyJson(), ChildNodeList.class);
Properties taskProperties = taskChildNode.getProperties();
MsgConfig taskMsgConfig = taskProperties.getRejectMsgConfig();
if (taskMsgConfig.getOn() == 2) {
taskMsgConfig = msgConfig;
}
if (taskMsgConfig.getOn() == 3) {
taskMsgConfig.setMsgId("PZXTLC003");
}
List<SentMessageForm> messageList = new ArrayList<>();
List<FlowTaskOperatorEntity> taskOperatorList = operatorMap.get(key);
FlowMessageModel messageModel = new FlowMessageModel();
Map<String, Object> data = flowTaskUtil.infoData(taskNode.getFormId(), taskNode.getTaskId());
messageModel.setData(data);
messageModel.setTitle("已被【退回】");
messageModel.setMsgConfig(taskMsgConfig);
messageModel.setRecordEntity(recordEntity);
messageModel.setStatus(taskEntity.getStatus());
messageModel.setType(FlowMessageEnum.wait.getCode());
messageModel.setFullName(taskEntity.getFullName());
messageModel.setUserInfo(userInfo);
messageModel(taskOperatorList, flowTemplateAllModel, messageModel);
setMessageList(messageList, messageModel);
messageListAll.addAll(messageList);
for (FlowTaskOperatorEntity operator : taskOperatorList) {
List<SentMessageForm> delegationMsg = delegationMsg(operator, messageModel, flowTemplateAllModel);
messageListAll.addAll(delegationMsg);
}
}
}
//抄送
if (flowMsgModel.getCopy()) {
ChildNodeList childNode = JsonUtil.getJsonToBean(nodeJson, ChildNodeList.class);
Properties properties = childNode.getProperties();
MsgConfig msgConfig = properties.getCopyMsgConfig();
if (msgConfig.getOn() == 3) {
msgConfig.setMsgId("PZXTLC007");
}
Map<String, List<FlowTaskCirculateEntity>> circulateMap = circulateList.stream().collect(Collectors.groupingBy(FlowTaskCirculateEntity::getTaskNodeId));
for (String key : circulateMap.keySet()) {
recordEntity.setTaskNodeId(key);
//默认获取当前节点
FlowTaskNodeEntity taskNode = nodeList.stream().filter(t -> t.getId().equals(key)).findFirst().orElse(null);
ChildNodeList taskChildNode = JsonUtil.getJsonToBean(taskNode.getNodePropertyJson(), ChildNodeList.class);
Properties taskProperties = taskChildNode.getProperties();
MsgConfig taskMsgConfig = taskProperties.getCopyMsgConfig();
if (taskMsgConfig.getOn() == 2) {
taskMsgConfig = msgConfig;
}
if (taskMsgConfig.getOn() == 3) {
taskMsgConfig.setMsgId("PZXTLC007");
}
List<SentMessageForm> messageList = new ArrayList<>();
List<FlowTaskOperatorEntity> taskOperatorList = new ArrayList<>();
for (FlowTaskCirculateEntity circulateEntity : circulateMap.get(key)) {
FlowTaskOperatorEntity operatorEntity = JsonUtil.getJsonToBean(circulateEntity, FlowTaskOperatorEntity.class);
operatorEntity.setHandleId(circulateEntity.getObjectId());
taskOperatorList.add(operatorEntity);
}
FlowMessageModel messageModel = new FlowMessageModel();
Map<String, Object> data = flowTaskUtil.infoData(taskNode.getFormId(), taskNode.getTaskId());
messageModel.setData(data);
messageModel.setTitle("已被【抄送】");
messageModel.setMsgConfig(taskMsgConfig);
messageModel.setRecordEntity(recordEntity);
messageModel.setStatus(taskEntity.getStatus());
messageModel.setType(FlowMessageEnum.circulate.getCode());
messageModel.setFullName(taskEntity.getFullName());
messageModel.setUserInfo(userInfo);
messageModel(taskOperatorList, flowTemplateAllModel, messageModel);
setMessageList(messageList, messageModel);
messageListAll.addAll(messageList);
}
}
//子流程
if (flowMsgModel.getLaunch()) {
ChildNodeList childNode = JsonUtil.getJsonToBean(nodeJson, ChildNodeList.class);
Properties properties = childNode.getProperties();
MsgConfig msgConfig = properties.getLaunchMsgConfig();
if (msgConfig.getOn() == 3) {
msgConfig.setMsgId("PZXTLC011");
}
Map<String, List<FlowTaskOperatorEntity>> operatorMap = operatorList.stream().collect(Collectors.groupingBy(FlowTaskOperatorEntity::getTaskNodeId));
for (String key : operatorMap.keySet()) {
recordEntity.setTaskNodeId(key);
//默认获取当前节点
FlowTaskNodeEntity taskNode = nodeList.stream().filter(t -> t.getId().equals(key)).findFirst().orElse(null);
ChildNodeList taskChildNode = JsonUtil.getJsonToBean(taskNode.getNodePropertyJson(), ChildNodeList.class);
Properties taskProperties = taskChildNode.getProperties();
MsgConfig taskMsgConfig = taskProperties.getLaunchMsgConfig();
if (taskMsgConfig.getOn() == 2) {
taskMsgConfig = msgConfig;
}
if (taskMsgConfig.getOn() == 3) {
taskMsgConfig.setMsgId("PZXTLC011");
}
List<SentMessageForm> messageList = new ArrayList<>();
List<FlowTaskOperatorEntity> taskOperatorList = operatorMap.get(key);
FlowMessageModel messageModel = new FlowMessageModel();
Map<String, Object> data = flowTaskUtil.infoData(properties.getFormId(), childNode.getTaskId());
messageModel.setData(data);
messageModel.setTitle("请发起【子流程】");
messageModel.setMsgConfig(taskMsgConfig);
messageModel.setRecordEntity(recordEntity);
messageModel.setType(FlowMessageEnum.me.getCode());
messageModel.setStatus(FlowTaskStatusEnum.Draft.getCode());
messageModel.setFullName(taskEntity.getFullName());
messageModel.setUserInfo(userInfo);
messageModel(taskOperatorList, flowTemplateAllModel, messageModel);
setMessageList(messageList, messageModel);
messageListAll.addAll(messageList);
}
}
//发起人
if (flowMsgModel.getStart()) {
ChildNodeList childNode = JsonUtil.getJsonToBean(nodeJson, ChildNodeList.class);
Properties properties = childNode.getProperties();
MsgConfig msgConfig = properties.getRejectMsgConfig();
if (msgConfig.getOn() == 3) {
msgConfig.setMsgId("PZXTLC003");
}
List<SentMessageForm> messageList = new ArrayList<>();
FlowMessageModel meModel = new FlowMessageModel();
Map<String, Object> data = flowTaskUtil.infoData(properties.getFormId(), childNode.getTaskId());
meModel.setData(data);
meModel.setTitle("已被【退回】");
meModel.setRecordEntity(recordEntity);
meModel.setStatus(taskEntity.getStatus());
meModel.setMsgConfig(msgConfig);
meModel.setType(FlowMessageEnum.me.getCode());
meModel.setFullName(taskEntity.getFullName());
meModel.setUserInfo(userInfo);
List<FlowTaskOperatorEntity> meOperatorList = new ArrayList() {{
FlowTaskOperatorEntity operatorEntity = new FlowTaskOperatorEntity();
operatorEntity.setTaskId(flowTaskNode.getTaskId());
operatorEntity.setHandleId(taskEntity.getCreatorUserId());
add(operatorEntity);
}};
messageModel(meOperatorList, flowTemplateAllModel, meModel);
setMessageList(messageList, meModel);
messageListAll.addAll(messageList);
}
//超时
if (flowMsgModel.getOvertime()) {
ChildNodeList childNode = JsonUtil.getJsonToBean(nodeJson, ChildNodeList.class);
Properties properties = childNode.getProperties();
MsgConfig msgConfig = properties.getOvertimeMsgConfig();
if (msgConfig.getOn() == 3) {
msgConfig.setMsgId("PZXTLC009");
}
Map<String, List<FlowTaskOperatorEntity>> operatorMap = operatorList.stream().collect(Collectors.groupingBy(FlowTaskOperatorEntity::getTaskNodeId));
for (String key : operatorMap.keySet()) {
recordEntity.setTaskNodeId(key);
FlowTaskNodeEntity taskNode = nodeList.stream().filter(t -> t.getId().equals(key)).findFirst().orElse(null);
ChildNodeList taskChildNode = JsonUtil.getJsonToBean(taskNode.getNodePropertyJson(), ChildNodeList.class);
Properties taskProperties = taskChildNode.getProperties();
MsgConfig taskMsgConfig = taskProperties.getOvertimeMsgConfig();
if (taskMsgConfig.getOn() == 2) {
taskMsgConfig = msgConfig;
}
if (taskMsgConfig.getOn() == 3) {
taskMsgConfig.setMsgId("PZXTLC009");
}
List<SentMessageForm> messageList = new ArrayList<>();
List<FlowTaskOperatorEntity> taskOperatorList = operatorMap.get(key);
FlowMessageModel messageModel = new FlowMessageModel();
Map<String, Object> data = flowTaskUtil.infoData(taskNode.getFormId(), taskNode.getTaskId());
messageModel.setData(data);
messageModel.setTitle("已【超时】");
messageModel.setMsgConfig(taskMsgConfig);
messageModel.setRecordEntity(recordEntity);
messageModel.setStatus(taskEntity.getStatus());
messageModel.setFullName(taskEntity.getFullName());
messageModel.setUserInfo(userInfo);
messageModel(taskOperatorList, flowTemplateAllModel, messageModel);
setMessageList(messageList, messageModel);
messageListAll.addAll(messageList);
for (FlowTaskOperatorEntity operator : taskOperatorList) {
List<SentMessageForm> delegationMsg = delegationMsg(operator, messageModel, flowTemplateAllModel);
messageListAll.addAll(delegationMsg);
}
}
}
//提醒
if (flowMsgModel.getNotice()) {
ChildNodeList childNode = JsonUtil.getJsonToBean(nodeJson, ChildNodeList.class);
Properties properties = childNode.getProperties();
MsgConfig msgConfig = properties.getNoticeMsgConfig();
if (msgConfig.getOn() == 3) {
msgConfig.setMsgId("PZXTLC008");
}
Map<String, List<FlowTaskOperatorEntity>> operatorMap = operatorList.stream().collect(Collectors.groupingBy(FlowTaskOperatorEntity::getTaskNodeId));
for (String key : operatorMap.keySet()) {
recordEntity.setTaskNodeId(key);
FlowTaskNodeEntity taskNode = nodeList.stream().filter(t -> t.getId().equals(key)).findFirst().orElse(null);
ChildNodeList taskChildNode = JsonUtil.getJsonToBean(taskNode.getNodePropertyJson(), ChildNodeList.class);
Properties taskProperties = taskChildNode.getProperties();
MsgConfig taskMsgConfig = taskProperties.getNoticeMsgConfig();
if (taskMsgConfig.getOn() == 2) {
taskMsgConfig = msgConfig;
}
if (taskMsgConfig.getOn() == 3) {
taskMsgConfig.setMsgId("PZXTLC008");
}
List<SentMessageForm> messageList = new ArrayList<>();
List<FlowTaskOperatorEntity> taskOperatorList = operatorMap.get(key);
FlowMessageModel messageModel = new FlowMessageModel();
Map<String, Object> data = flowTaskUtil.infoData(taskNode.getFormId(), taskNode.getTaskId());
messageModel.setData(data);
messageModel.setTitle("请尽快【审批】");
messageModel.setMsgConfig(taskMsgConfig);
messageModel.setRecordEntity(recordEntity);
messageModel.setStatus(taskEntity.getStatus());
messageModel.setFullName(taskEntity.getFullName());
messageModel.setUserInfo(userInfo);
messageModel(taskOperatorList, flowTemplateAllModel, messageModel);
setMessageList(messageList, messageModel);
messageListAll.addAll(messageList);
for (FlowTaskOperatorEntity operator : taskOperatorList) {
List<SentMessageForm> delegationMsg = delegationMsg(operator, messageModel, flowTemplateAllModel);
messageListAll.addAll(delegationMsg);
}
}
}
//评论提醒
if (flowMsgModel.getComment()) {
ChildNodeList childNode = JsonUtil.getJsonToBean(nodeJson, ChildNodeList.class);
Properties properties = childNode.getProperties();
MsgConfig commentMsgConfig = properties.getCommentMsgConfig();
if (commentMsgConfig.getOn() == 3) {
commentMsgConfig.setMsgId("MBXTLC017");
}
//审批人
if (operatorList != null && !operatorList.isEmpty()) {
Map<String, List<FlowTaskOperatorEntity>> operatorMap = operatorList.stream().collect(Collectors.groupingBy(FlowTaskOperatorEntity::getTaskNodeId));
for (String key : operatorMap.keySet()) {
recordEntity.setTaskNodeId(key);
List<SentMessageForm> messageList = new ArrayList<>();
List<FlowTaskOperatorEntity> taskOperatorList = operatorMap.get(key);
FlowMessageModel messageModel = new FlowMessageModel();
FlowTaskNodeEntity taskNode = nodeList.stream().filter(t -> t.getId().equals(recordEntity.getTaskNodeId())).findFirst().orElse(null);
Map<String, Object> data = flowTaskUtil.infoData(taskNode.getFormId(), taskNode.getTaskId());
messageModel.setData(data);
messageModel.setTitle("有关于您的评论,请及时查看");
messageModel.setMsgConfig(commentMsgConfig);
messageModel.setRecordEntity(recordEntity);
messageModel.setStatus(taskEntity.getStatus());
messageModel.setFullName(messageModel.getTitle());
messageModel.setUserInfo(userInfo);
messageModel.setType(3);
messageModel(taskOperatorList, flowTemplateAllModel, messageModel);
setMessageList(messageList, messageModel);
messageListAll.addAll(messageList);
for (FlowTaskOperatorEntity operator : taskOperatorList) {
List<SentMessageForm> delegationMsg = delegationMsg(operator, messageModel, flowTemplateAllModel);
messageListAll.addAll(delegationMsg);
}
}
}
//抄送人
if (circulateList != null && !circulateList.isEmpty()) {
Map<String, List<FlowTaskCirculateEntity>> circulateMap = circulateList.stream().collect(Collectors.groupingBy(FlowTaskCirculateEntity::getTaskNodeId));
for (String key : circulateMap.keySet()) {
recordEntity.setTaskNodeId(key);
//默认获取当前节点
FlowTaskNodeEntity taskNode = nodeList.stream().filter(t -> t.getId().equals(key)).findFirst().orElse(null);
List<SentMessageForm> messageList = new ArrayList<>();
List<FlowTaskOperatorEntity> taskOperatorList = new ArrayList<>();
for (FlowTaskCirculateEntity circulateEntity : circulateMap.get(key)) {
FlowTaskOperatorEntity operatorEntity = JsonUtil.getJsonToBean(circulateEntity, FlowTaskOperatorEntity.class);
operatorEntity.setHandleId(circulateEntity.getObjectId());
taskOperatorList.add(operatorEntity);
}
FlowMessageModel messageModel = new FlowMessageModel();
Map<String, Object> data = flowTaskUtil.infoData(taskNode.getFormId(), taskNode.getTaskId());
messageModel.setData(data);
messageModel.setTitle("有关于您的评论,请及时查看");
messageModel.setMsgConfig(commentMsgConfig);
messageModel.setRecordEntity(recordEntity);
messageModel.setStatus(taskEntity.getStatus());
messageModel.setType(FlowMessageEnum.circulate.getCode());
messageModel.setFullName(messageModel.getTitle());
messageModel.setUserInfo(userInfo);
messageModel(taskOperatorList, flowTemplateAllModel, messageModel);
setMessageList(messageList, messageModel);
messageListAll.addAll(messageList);
}
}
//发起人
if (StringUtil.isNotEmpty(flowMsgModel.getStartHandId())) {
List<SentMessageForm> messageList = new ArrayList<>();
FlowMessageModel messageModel = new FlowMessageModel();
Map<String, Object> data = flowTaskUtil.infoData(properties.getFormId(), childNode.getTaskId());
messageModel.setData(data);
messageModel.setTitle("有关于您的评论,请及时查看");
messageModel.setRecordEntity(recordEntity);
messageModel.setStatus(taskEntity.getStatus());
messageModel.setMsgConfig(commentMsgConfig);
messageModel.setType(FlowMessageEnum.me.getCode());
messageModel.setFullName(messageModel.getTitle());
messageModel.setUserInfo(userInfo);
List<FlowTaskOperatorEntity> meOperatorList = new ArrayList() {{
FlowTaskOperatorEntity operatorEntity = new FlowTaskOperatorEntity();
operatorEntity.setTaskId(taskEntity.getId());
operatorEntity.setHandleId(flowMsgModel.getStartHandId());
add(operatorEntity);
}};
messageModel(meOperatorList, flowTemplateAllModel, messageModel);
setMessageList(messageList, messageModel);
messageListAll.addAll(messageList);
}
//审批已办记录
List<FlowTaskOperatorRecordEntity> operatorRecordList = flowMsgModel.getOperatorRecordList();
if (operatorRecordList != null && !operatorRecordList.isEmpty()) {
Map<String, List<FlowTaskOperatorRecordEntity>> operatorRecordMap = operatorRecordList.stream().collect(Collectors.groupingBy(FlowTaskOperatorRecordEntity::getTaskNodeId));
for (String key : operatorRecordMap.keySet()) {
recordEntity.setTaskNodeId(key);
List<SentMessageForm> messageList = new ArrayList<>();
List<FlowTaskOperatorRecordEntity> taskOperatorList = operatorRecordMap.get(key);
FlowMessageModel messageModel = new FlowMessageModel();
FlowTaskNodeEntity taskNode = nodeList.stream().filter(t -> t.getId().equals(recordEntity.getTaskNodeId())).findFirst().orElse(null);
Map<String, Object> data = flowTaskUtil.infoData(taskNode.getFormId(), taskNode.getTaskId());
messageModel.setData(data);
messageModel.setTitle("有关于您的评论,请及时查看");
messageModel.setMsgConfig(commentMsgConfig);
messageModel.setRecordEntity(recordEntity);
messageModel.setStatus(taskEntity.getStatus());
messageModel.setFullName(messageModel.getTitle());
messageModel.setUserInfo(userInfo);
messageModel.setType(3);
messageModelRecord(taskOperatorList, flowTemplateAllModel, messageModel);
setMessageList(messageList, messageModel);
messageListAll.addAll(messageList);
}
}
}
for (SentMessageForm sentMessageForm : messageListAll) {
FlowTemplateJsonEntity templateJson = flowTemplateAllModel.getTemplateJson();
sentMessageForm.setFlowName(templateJson.getFullName());
sentMessageForm.setUserName(user != null ? user.getRealName() : "");
}
serviceUtil.sendMessage(messageListAll);
}
/**
* 封装站内信消息
*/
private void messageModel(List<FlowTaskOperatorEntity> taskOperatorList, FlowTemplateAllModel flowTemplateAllModel, FlowMessageModel messageModel) {
List<String> userList = new ArrayList<>();
Map<String, String> contMsg = new HashMap<>();
for (FlowTaskOperatorEntity taskOperator : taskOperatorList) {
FlowContModel contModel = flowMessage(flowTemplateAllModel, taskOperator, messageModel);
contMsg.put(taskOperator.getHandleId(), JsonUtil.getObjectToString(contModel));
userList.add(taskOperator.getHandleId());
}
messageModel.setUserList(userList);
messageModel.setContMsg(contMsg);
}
/**
* 封装站内信消息
*/
private void messageModelRecord(List<FlowTaskOperatorRecordEntity> taskOperatorRecordList, FlowTemplateAllModel flowTemplateAllModel, FlowMessageModel messageModel) {
List<String> userList = new ArrayList<>();
Map<String, String> contMsg = new HashMap<>();
for (FlowTaskOperatorRecordEntity taskOperator : taskOperatorRecordList) {
FlowContModel contModel = flowMessageRecord(flowTemplateAllModel, taskOperator, messageModel);
contMsg.put(taskOperator.getHandleId(), JsonUtil.getObjectToString(contModel));
userList.add(taskOperator.getHandleId());
}
messageModel.setUserList(userList);
messageModel.setContMsg(contMsg);
}
/**
* 封装站内信对象
*
* @param taskOperator
* @return
*/
private FlowContModel flowMessageRecord(FlowTemplateAllModel flowTemplateAllModel, FlowTaskOperatorRecordEntity taskOperator, FlowMessageModel messageModel) {
FlowTemplateJsonEntity templateJson = flowTemplateAllModel.getTemplateJson();
FlowTemplateEntity template = flowTemplateAllModel.getTemplate();
FlowContModel contModel = new FlowContModel();
contModel.setEnCode(template.getEnCode());
contModel.setFlowId(templateJson.getId());
contModel.setTaskNodeId(taskOperator.getTaskNodeId());
contModel.setTaskOperatorId(taskOperator.getTaskOperatorId());
contModel.setProcessId(taskOperator.getTaskId());
contModel.setType(messageModel.getType());
contModel.setStatus(messageModel.getStatus());
return contModel;
}
/**
* 封装站内信对象
*
* @param taskOperator
* @return
*/
private FlowContModel flowMessage(FlowTemplateAllModel flowTemplateAllModel, FlowTaskOperatorEntity taskOperator, FlowMessageModel messageModel) {
FlowTemplateJsonEntity templateJson = flowTemplateAllModel.getTemplateJson();
FlowTemplateEntity template = flowTemplateAllModel.getTemplate();
FlowContModel contModel = new FlowContModel();
contModel.setEnCode(template.getEnCode());
contModel.setFlowId(templateJson.getId());
contModel.setTaskNodeId(taskOperator.getTaskNodeId());
contModel.setTaskOperatorId(taskOperator.getId());
contModel.setProcessId(taskOperator.getTaskId());
contModel.setType(messageModel.getType());
contModel.setStatus(messageModel.getStatus());
return contModel;
}
/**
* 整合发送消息
*
* @param messageList
* @param flowMessageModel
*/
private void setMessageList(List<SentMessageForm> messageList, FlowMessageModel flowMessageModel) {
Map<String, Object> data = new HashMap<>(flowMessageModel.getData());
MsgConfig msgConfig = flowMessageModel.getMsgConfig() != null ? flowMessageModel.getMsgConfig() : new MsgConfig();
List<String> userList = flowMessageModel.getUserList();
FlowTaskOperatorRecordEntity record = flowMessageModel.getRecordEntity();
String templateId = msgConfig.getOn() == 0 ? "0" : msgConfig.getMsgId();
Boolean sysMessage = msgConfig.getOn() != 0;
//解析发送配置json获取消息模板参数
List<TemplateJsonModel> templateJson = new ArrayList<>();
for (SendConfigJson sendConfigJson : msgConfig.getTemplateJson()) {
List<TemplateJsonModel> templateJson1 = sendConfigJson.getParamJson();
templateJson.addAll(templateJson1);
List<String> paramJson = ImmutableList.of(FlowConstant.MANDATOR, FlowConstant.MANDATARY, FlowConstant.CREATORUSERNAME, FlowConstant.SENDTIME);
for (String field : paramJson) {
TemplateJsonModel templateJsonModel = new TemplateJsonModel();
templateJsonModel.setMsgTemplateId(sendConfigJson.getId());
templateJsonModel.setRelationField(field);
templateJsonModel.setField(field);
templateJsonModel.setSourceType(TemplateEnum.System.getCode());
templateJson.add(templateJsonModel);
}
}
SentMessageForm messageModel = new SentMessageForm();
messageModel.setSysMessage(sysMessage);
messageModel.setTemplateId(templateId);
messageModel.setToUserIds(userList);
Map<String, Object> parameterMap = new HashMap<>();
for (TemplateJsonModel templateJsonModel : templateJson) {
String fieldId = templateJsonModel.getField();
String msgTemplateId = templateJsonModel.getMsgTemplateId();
String relationField = templateJsonModel.getRelationField();
String dataValue = data.get(relationField) != null ? String.valueOf(data.get(relationField)) : "";
String dataFieldValue = relationField;
String dataJson = Objects.equals(TemplateEnum.Field.getCode(), templateJsonModel.getSourceType()) ? dataValue : dataFieldValue;
FlowEventModel eventModel = FlowEventModel.builder().data(data).dataJson(dataJson).record(record).templateJson(templateJsonModel).build();
dataJson = data(eventModel);
parameterMap.put(msgTemplateId + fieldId, dataJson);
}
data.putAll(parameterMap);
messageModel.setUserInfo(flowMessageModel.getUserInfo());
messageModel.setParameterMap(data);
messageModel.setContentMsg(flowMessageModel.getContMsg());
messageModel.setTitle(flowMessageModel.getFullName());
if (userList.size() > 0) {
messageList.add(messageModel);
}
}
/**
* 组装接口数据
*
* @return
*/
public Map<String, String> parameterMap(Map<String, Object> data, List<TemplateJsonModel> templateJsonModelList, FlowTaskOperatorRecordEntity record) {
Map<String, String> parameterMap = new HashMap<>();
for (TemplateJsonModel templateJsonModel : templateJsonModelList) {
String fieldId = templateJsonModel.getField();
String msgTemplateId = templateJsonModel.getMsgTemplateId();
String relationField = templateJsonModel.getRelationField();
String dataValue = data.get(relationField) != null ? String.valueOf(data.get(relationField)) : null;
String dataFieldValue = relationField;
String dataJson = Objects.equals(TemplateEnum.Field.getCode(), templateJsonModel.getSourceType()) ? dataValue : dataFieldValue;
FlowEventModel eventModel = FlowEventModel.builder().data(data).dataJson(dataJson).record(record).templateJson(templateJsonModel).build();
dataJson = data(eventModel);
parameterMap.put(StringUtil.isNotEmpty(msgTemplateId) ? msgTemplateId : "" + fieldId, dataJson);
}
return parameterMap;
}
/**
* @return
*/
private String data(FlowEventModel eventModel) {
FlowTaskOperatorRecordEntity record = eventModel.getRecord();
TemplateJsonModel templateJson = eventModel.getTemplateJson();
String relationField = StringUtil.isNotEmpty(templateJson.getRelationField()) ? templateJson.getRelationField() : "";
List<Integer> typeList = ImmutableList.of(TemplateEnum.Field.getCode(), TemplateEnum.System.getCode());
boolean isType = typeList.contains(templateJson.getSourceType());
String dataJson = eventModel.getDataJson();
Map<String, Object> data = eventModel.getData();
UserInfo userInfo = UserProvider.getUser();
String userId = StringUtil.isNotEmpty(userInfo.getUserId()) ? userInfo.getUserId() : StringUtil.isNotEmpty(record.getHandleId()) ? record.getHandleId() : "";
UserEntity userEntity = serviceUtil.getUserInfo(userId);
String userName = userEntity != null ? userEntity.getRealName() : "";
String value = dataJson;
FlowTaskEntity taskEntity = flowTaskService.getInfoSubmit(record.getTaskId(), FlowTaskEntity::getFlowId, FlowTaskEntity::getFlowName
, FlowTaskEntity::getFullName, FlowTaskEntity::getCreatorUserId, FlowTaskEntity::getDelegateUser);
if (isType) {
switch (relationField) {
case FlowConstant.FLOW_ID:
value = taskEntity.getFlowId();
break;
case FlowConstant.TASK_ID:
value = record.getTaskId();
break;
case FlowConstant.TASK_NODE_ID:
value = record.getTaskNodeId();
break;
case FlowConstant.FLOW_FULL_NAME:
value = taskEntity.getFlowName();
break;
case FlowConstant.TASK_FULL_NAME:
value = taskEntity.getFullName();
break;
case FlowConstant.LAUNCH_USER_ID:
value = taskEntity.getCreatorUserId();
break;
case FlowConstant.LAUNCH_USER_NAME:
case FlowConstant.CREATORUSERNAME:
case FlowConstant.MANDATOR:
UserEntity createUser = taskEntity != null ? serviceUtil.getUserInfo(taskEntity.getCreatorUserId()) : null;
value = createUser != null ? createUser.getRealName() : "";
break;
case FlowConstant.FLOW_OPERATOR_USER_ID:
value = userId;
break;
case FlowConstant.FLOW_OPERATOR_USER_NAME:
value = userName;
break;
case FlowConstant.SENDTIME:
value = DateUtil.getNow();
break;
case FlowConstant.MANDATARY:
UserEntity delegate = StringUtil.isNotEmpty(taskEntity.getDelegateUser()) ? serviceUtil.getUserInfo(taskEntity.getDelegateUser()) : null;
value = delegate != null ? delegate.getRealName() : "";
break;
default:
String[] model = StringUtil.isNotEmpty(relationField) ? relationField.split("-") : new String[]{};
if (model.length > 1) {
Object dataList = data.get(model[0]);
if (dataList instanceof List) {
List<Map<String, Object>> listAll = (List<Map<String, Object>>) dataList;
List<Object> list = new ArrayList<>();
for (Map<String, Object> objectMap : listAll) {
list.add(objectMap.get(model[1]));
}
value = String.valueOf(list);
}
}
break;
}
}
return value;
}
//--------------------------------------------事件处理---------------------------------------------------------
/**
* 流程事件
*
* @param status 事件状态 1.发起 2.结束 3.发起撤回 4同意 5拒绝 6节点撤回 7 超时 8提醒
* @param childNode 节点数据
* @param record 审批数据
*/
public void event(Integer status, ChildNodeList childNode, FlowTaskOperatorRecordEntity record, FlowModel flowModel) {
if (childNode != null) {
boolean on = false;
String interId = "";
List<TemplateJsonModel> templateJsonModelList = new ArrayList<>();
FuncConfig config = null;
List<Integer> eventList = ImmutableList.of(2, 7, 8);
Map<Integer, String> map = ImmutableMap.of(1, "发起事件", 2, "结束事件",
3, "撤回事件", 4, "同意事件", 5, "退回事件", 6, "撤回事件",
7, "超时事件", 8, "提醒事件");
//属性
Properties properties = childNode.getProperties();
Integer funcConfigRule = properties.getFuncConfigRule();
switch (status) {
case 1:
config = properties.getInitFuncConfig();
break;
case 2:
config = properties.getEndFuncConfig();
break;
case 3:
config = properties.getFlowRecallFuncConfig();
break;
case 4:
config = properties.getApproveFuncConfig();
break;
case 5:
config = properties.getRejectFuncConfig();
break;
case 6:
config = properties.getRecallFuncConfig();
break;
case 7:
config = properties.getOvertimeFuncConfig();
break;
case 8:
config = properties.getNoticeFuncConfig();
break;
default:
break;
}
if (config != null) {
on = config.getOn();
interId = config.getInterfaceId();
templateJsonModelList = config.getTemplateJson();
}
if (on && StringUtil.isNotEmpty(interId)) {
Map<String, Object> data = flowModel.getFormData();
Map<String, String> parameterMap = parameterMap(data, templateJsonModelList, record);
List<FlowParameterModel> allEvent = FlowContextHolder.getAllEvent();
if (allEvent.size() == 0) {
ActionResult result = serviceUtil.infoToId(interId, parameterMap);
boolean error = Objects.equals(400, result.getCode());
FlowEventLogEntity logEntity = new FlowEventLogEntity();
logEntity.setTaskNodeId(childNode.getTaskNodeId());
logEntity.setFullName(map.get(status));
logEntity.setInterfaceId(interId);
logEntity.setResult(error ? result.getMsg() : "");
flowEventLogService.create(logEntity);
if (error && !eventList.contains(status) && Objects.equals(FlowNature.FuncTerminate, funcConfigRule)) {
FlowContextHolder.addEvent(interId, parameterMap);
}
}
}
}
}
/**
* 封装委托消息
*
* @param operator
* @param messageModel
* @return
*/
private List<SentMessageForm> delegationMsg(FlowTaskOperatorEntity operator, FlowMessageModel messageModel, FlowTemplateAllModel flowTemplateAllModel) {
List<SentMessageForm> messageList = new ArrayList<>();
FlowTaskEntity taskEntity = flowTaskService.getInfoSubmit(operator.getTaskId(), FlowTaskEntity::getFlowId);
if (taskEntity != null) {
//todo 获取委托人
List<String> userList = flowDelegateService.getUser(null, taskEntity.getTemplateId(), operator.getHandleId()).stream().map(FlowDelegateEntity::getToUserId).collect(Collectors.toList());
List<FlowTaskOperatorEntity> taskOperatorList = new ArrayList<>();
for (String user : userList) {
FlowTaskOperatorEntity delegaOperator = JsonUtil.getJsonToBean(operator, FlowTaskOperatorEntity.class);
delegaOperator.setHandleId(user);
taskOperatorList.add(delegaOperator);
}
messageModel(taskOperatorList, flowTemplateAllModel, messageModel);
setMessageList(messageList, messageModel);
}
return messageList;
}
//--------------------------------------委托消息------------------------------------------------------
public void delegateMsg(FlowDelegateModel flowDelegate) {
List<String> toUserIds = flowDelegate.getToUserIds();
UserInfo userInfo = flowDelegate.getUserInfo();
FlowTaskEntity flowTask = flowDelegate.getFlowTask();
FlowTemplateAllModel templateAllModel = flowDelegate.getTemplateAllModel();
Map<String, String> contentMsg = new HashMap<>();
Boolean delegate = flowDelegate.getDelegate();
boolean approve = flowDelegate.getApprove();
if (approve) {
SentMessageForm flowMsgModel = new SentMessageForm();
flowMsgModel.setToUserIds(toUserIds);
flowMsgModel.setUserInfo(flowDelegate.getUserInfo());
// String flowName = flowTask.getFlowName();
String flowName = templateAllModel.getTemplateJson().getFullName();
Map<String, Object> parameterMap = new HashMap<>();
parameterMap.put(FlowConstant.MANDATOR, userInfo.getUserName());
UserEntity mandatary = StringUtil.isNotEmpty(flowTask.getDelegateUser()) ? serviceUtil.getUserInfo(flowTask.getDelegateUser()) : null;
parameterMap.put(FlowConstant.MANDATARY, mandatary != null ? mandatary.getRealName() : "");
parameterMap.put(FlowConstant.TITLE, flowTask != null ? flowTask.getFullName() : "");
flowMsgModel.setParameterMap(parameterMap);
//1.委托设置 2.委托给我
Integer type = flowDelegate.getType();
if (delegate) {
String title = FlowNature.StartMsg.equals(type) ? "了发起委托" : FlowNature.ApproveMsg.equals(type) ? "了审批委托" : "的委托已结束";
String templateId = FlowNature.StartMsg.equals(type) ? "PZXTLG012" : FlowNature.ApproveMsg.equals(type) ? "PZXTLG013" : "PZXTLG014";
String content = userInfo.getUserName() + "向您发起" + title;
flowMsgModel.setTitle(content);
flowMsgModel.setTemplateId(templateId);
} else {
String title = FlowNature.StartMsg.equals(type) ? "已发起了您的" : "已审批了您的";
String templateId = FlowNature.StartMsg.equals(type) ? "PZXTLG015" : "PZXTLG016";
String content = userInfo.getUserName() + title + flowName;
flowMsgModel.setTitle(content);
flowMsgModel.setTemplateId(templateId);
}
Integer delegateType = delegate ? FlowNature.EndMsg : FlowNature.ApproveMsg;
contentMsg.put("type", delegateType + "");
flowMsgModel.setContentMsg(contentMsg);
flowMsgModel.setFlowType(2);
flowMsgModel.setType(2);
List<SentMessageForm> messageListAll = new ArrayList<>();
if (toUserIds.size() > 0) {
messageListAll.add(flowMsgModel);
}
serviceUtil.sendDelegateMsg(messageListAll);
}
}
}

View File

@@ -0,0 +1,93 @@
package com.yunzhupaas.engine.util;
import com.yunzhupaas.engine.entity.FlowTaskEntity;
import com.yunzhupaas.engine.entity.FlowTaskNodeEntity;
import com.yunzhupaas.engine.entity.FlowTaskOperatorEntity;
import com.yunzhupaas.engine.model.flowengine.shuntjson.childnode.LimitModel;
import com.yunzhupaas.engine.model.flowengine.shuntjson.childnode.Properties;
import com.yunzhupaas.engine.model.flowengine.shuntjson.nodejson.ChildNodeList;
import com.yunzhupaas.engine.model.flowtime.FlowTimeModel;
import com.yunzhupaas.engine.service.FlowTaskNodeService;
import com.yunzhupaas.engine.service.FlowTaskOperatorService;
import com.yunzhupaas.engine.service.FlowTaskService;
import com.yunzhupaas.exception.WorkFlowException;
import com.yunzhupaas.util.DateUtil;
import com.yunzhupaas.util.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* @author :云筑产品开发平台组
* @version: V3.1.0
* @copyright 深圳市乐程软件有限公司
* @date 2022/6/17 17:41
*/
@Component
public class FlowTimerUtil {
@Autowired
private FlowTaskNodeService flowTaskNodeService;
@Autowired
private FlowTaskService flowTaskService;
@Autowired
private FlowTaskOperatorService flowTaskOperatorService;
/**
* 限时开始时间
*/
public FlowTimeModel time(FlowTaskNodeEntity taskNodeEntity, List<FlowTaskNodeEntity> nodeList
, FlowTaskEntity flowTaskEntity, FlowTaskOperatorEntity operatorInfo) throws WorkFlowException {
FlowTaskNodeEntity startNode = nodeList.stream().filter(t -> FlowNature.NodeStart.equals(t.getNodeType())).findFirst().orElse(null);
String nodeJson = startNode != null ? startNode.getNodePropertyJson() : "{}";
ChildNodeList childNode = JsonUtil.getJsonToBean(taskNodeEntity.getNodePropertyJson(), ChildNodeList.class);
FlowTimeModel date = new FlowTimeModel();
date.setChildNode(JsonUtil.getJsonToBean(nodeJson, ChildNodeList.class));//开始节点
date.setChildNodeEvnet(childNode);//当前节点
Date(operatorInfo, flowTaskEntity, date);
return date;
}
private void Date(FlowTaskOperatorEntity operatorInfo, FlowTaskEntity flowTaskEntity, FlowTimeModel flowTimeModel) throws WorkFlowException {
Properties taskProperties = flowTimeModel.getChildNodeEvnet().getProperties();
LimitModel limitModel = taskProperties.getTimeLimitConfig();
boolean isOn = limitModel.getOn() != 0;
if (limitModel.getOn() == 2) {
taskProperties = flowTimeModel.getChildNode().getProperties();
limitModel = taskProperties.getTimeLimitConfig();
}
Map<String, Object> data = JsonUtil.stringToMap(flowTaskEntity.getFlowFormContentJson());
flowTimeModel.setOn(isOn);
if (isOn) {
Date date = null;
if (limitModel.getNodeLimit() == 0) {
date = operatorInfo.getCreatorTime();
} else if (limitModel.getNodeLimit() == 1) {
date = flowTaskEntity.getCreatorTime();
} else {
Object formData = data.get(limitModel.getFormField());
try {
date = new Date((Long) formData);
} catch (Exception e) {
}
if (date == null) {
try {
date = DateUtil.stringToDate(String.valueOf(formData));
} catch (Exception e) {
}
}
}
if (date == null) {
date = flowTaskEntity.getCreatorTime();
}
flowTimeModel.setDate(date);
}
}
}

View File

@@ -0,0 +1,32 @@
package com.yunzhupaas.job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.quartz.QuartzJobBean;
/**
* 超时设置定时器
*
* @author 云筑产品开发平台组
* @version V3.4.2
* @copyright 深圳市乐程软件有限公司
* @date 2024/6/15 16:23
*/
public class AutoApproveJob extends QuartzJobBean {
public static final String autoApprove = "idgenerator_AutoApprove";
@Autowired
private WorkTimeoutJobUtil workTimeoutJobUtil;
@Autowired
private RedisTemplate redisTemplate;
@Override
protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
workTimeoutJobUtil.approveModel(redisTemplate);
}
}

View File

@@ -0,0 +1,76 @@
package com.yunzhupaas.job;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* 流程设计
*
* @author 云筑产品开发平台组
* @version V3.3.0 flowable
* @copyright 深圳市乐程软件有限公司
* @date 2024/6/1 17:27
*/
@Configuration
public class JobConfig {
@Bean
public JobDetail testJobDetail() {
JobDetail JobDetail = JobBuilder.newJob(WorkJobNew.class)
.storeDurably() //必须调用该方法,添加任务
.build();
return JobDetail;
}
@Bean
public Trigger testTrigger() {
CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule("0/10 * * * * ?"); //配置任务频率测试环境10s正式环境修改成30s
Trigger trigger = TriggerBuilder.newTrigger()
.forJob(testJobDetail())
.withSchedule(cronScheduleBuilder) //对触发器配置任务
.build();
return trigger;
}
@Bean
public JobDetail timeoutSettingJobDetail() {
JobDetail JobDetail = JobBuilder.newJob(TimeoutSettingJob.class)
.storeDurably() //必须调用该方法,添加任务
.build();
return JobDetail;
}
@Bean
public Trigger timeoutTrigger() {
CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule("0 0 * * * ?"); //配置任务频率测试环境每分钟正式环境修改成每小时0 0 * * * ?
Trigger trigger = TriggerBuilder.newTrigger()
.forJob(timeoutSettingJobDetail())
.withSchedule(cronScheduleBuilder) //对触发器配置任务
.build();
return trigger;
}
@Bean
public JobDetail autoApproveDetail() {
JobDetail JobDetail = JobBuilder.newJob(AutoApproveJob.class)
.storeDurably() //必须调用该方法,添加任务
.build();
return JobDetail;
}
@Bean
public Trigger autoApproveTrigger() {
CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule("0/5 * * * * ?"); //配置任务频率测试环境每分钟正式环境修改成每小时5 0 * * * ?
Trigger trigger = TriggerBuilder.newTrigger()
.forJob(autoApproveDetail())
.withSchedule(cronScheduleBuilder) //对触发器配置任务
.build();
return trigger;
}
}

View File

@@ -0,0 +1,46 @@
package com.yunzhupaas.job;
import com.yunzhupaas.engine.model.flowtask.WorkTimeoutJobModel;
import com.yunzhupaas.util.RedisUtil;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.quartz.QuartzJobBean;
import java.util.List;
import java.util.concurrent.TimeUnit;
/**
* 超时设置定时器
*
* @author 云筑产品开发平台组
* @version V3.4.2
* @copyright 深圳市乐程软件有限公司
* @date 2024/6/15 16:23
*/
@DisallowConcurrentExecution
public class TimeoutSettingJob extends QuartzJobBean {
@Autowired
private RedisUtil redisUtil;
@Autowired
private WorkTimeoutJobUtil workTimeoutJobUtil;
@Autowired
private
RedisTemplate redisTemplate;
@Override
protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
List<WorkTimeoutJobModel> listRedis = workTimeoutJobUtil.getListRedis(redisUtil);
for (WorkTimeoutJobModel entity : listRedis) {
boolean useSuccess = redisTemplate.opsForValue().setIfAbsent(WorkTimeoutJobUtil.WORKTIMEOUT_REDIS_KEY + "_key:" + entity.getTaskNodeOperatorId(), System.currentTimeMillis(), 300, TimeUnit.SECONDS);
if (!useSuccess || entity.isSuspend()) continue;
workTimeoutJobUtil.runTimeOutMethod(entity, true);
redisUtil.remove(WorkTimeoutJobUtil.WORKTIMEOUT_REDIS_KEY + "_key:" + entity.getTaskNodeOperatorId());
}
}
}

View File

@@ -0,0 +1,101 @@
package com.yunzhupaas.job;
import com.yunzhupaas.base.UserInfo;
import com.yunzhupaas.config.ConfigValueUtil;
import com.yunzhupaas.database.util.TenantDataSourceUtil;
import com.yunzhupaas.engine.entity.FlowTaskOperatorEntity;
import com.yunzhupaas.engine.model.flowmessage.FlowMsgModel;
import com.yunzhupaas.engine.model.flowtask.WorkJobModel;
import com.yunzhupaas.engine.util.FlowMsgUtil;
import com.yunzhupaas.util.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.quartz.QuartzJobBean;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
/**
* 流程设计
*
* @author 云筑产品开发平台组
* @version V3.3.0 flowable
* @copyright 深圳市乐程软件有限公司
* @date 2024/6/1 17:32
*/
@Slf4j
@DisallowConcurrentExecution
public class WorkJobNew extends QuartzJobBean {
@Autowired
private RedisUtil redisUtil;
@Autowired
private ConfigValueUtil configValueUtil;
@Autowired
private FlowMsgUtil flowMsgUtil;
@Autowired
private RedisTemplate redisTemplate;
@Override
protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
// System.out.println("定时器");
// List<WorkJobModel> listRedis = WorkJobUtil.getListRedis(redisUtil);
Map<String, Object> listRedisTime = WorkJobUtil.getListRedisTime(redisUtil);
if (listRedisTime != null) {
try {
long time = System.currentTimeMillis();
// runCode(listRedis, time);
//新逻辑取key 时间缓存如有延迟则取延迟workJobModel对象缓存。
for (String key : listRedisTime.keySet()) {
boolean useSuccess = redisTemplate.opsForValue().setIfAbsent(WorkJobUtil.REDIS_KEY + "_key:" + key, System.currentTimeMillis(), 300, TimeUnit.SECONDS);
if (!useSuccess) continue;
try {
boolean isNext = Long.valueOf(listRedisTime.get(key).toString()).longValue() < time;
if (isNext) {
WorkJobModel workJobModel = WorkJobUtil.getListRedisJson(redisUtil, key);
UserInfo userInfo = workJobModel.getUserInfo();
FlowMsgModel flowMsgModel = workJobModel.getFlowMsgModel();
if (configValueUtil.isMultiTenancy()) {
TenantDataSourceUtil.switchTenant(userInfo.getTenantId());
}
flowMsgUtil.message(flowMsgModel);
redisUtil.removeHash(WorkJobUtil.REDIS_KEY, key);
redisUtil.removeHash(WorkJobUtil.REDIS_KEY + "_json", key);
}
} finally {
redisTemplate.delete(WorkJobUtil.REDIS_KEY + "_key:" + key);
}
}
} catch (Exception e) {
log.error("工作流调度报错:" + e.getMessage());
}
}
}
//旧逻辑
private void runCode(List<WorkJobModel> listRedis, long time) {
for (WorkJobModel workJobModel : listRedis) {
boolean useSuccess = redisTemplate.opsForValue().setIfAbsent(WorkJobUtil.REDIS_KEY + "_key:" + workJobModel.getTaskId(), System.currentTimeMillis(), 300, TimeUnit.SECONDS);
if (!useSuccess) continue;
List<FlowTaskOperatorEntity> operatorList = workJobModel.getFlowMsgModel().getOperatorList();
// System.out.println("每个对象:" + workJobModel);
boolean isNext = operatorList.stream().filter(t -> t.getCreatorTime().getTime() > time).count() == 0;
UserInfo userInfo = workJobModel.getUserInfo();
FlowMsgModel flowMsgModel = workJobModel.getFlowMsgModel();
if (configValueUtil.isMultiTenancy()) {
TenantDataSourceUtil.switchTenant(userInfo.getTenantId());
}
if (isNext) {
redisUtil.removeHash(WorkJobUtil.REDIS_KEY, workJobModel.getTaskId());
redisUtil.remove(WorkJobUtil.REDIS_KEY + "_key:" + workJobModel.getTaskId());
}
}
}
}

View File

@@ -0,0 +1,135 @@
package com.yunzhupaas.job;
import com.alibaba.fastjson.JSONObject;
import com.yunzhupaas.base.UserInfo;
import com.yunzhupaas.engine.entity.FlowTaskOperatorEntity;
import com.yunzhupaas.engine.model.flowmessage.FlowMsgModel;
import com.yunzhupaas.engine.model.flowtask.WorkJobModel;
import com.yunzhupaas.engine.util.FlowMsgUtil;
import com.yunzhupaas.util.JsonUtil;
import com.yunzhupaas.util.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 流程定时器工具类
*
* @author 云筑产品开发平台组
* @version V3.3.0 flowable
* @copyright 深圳市乐程软件有限公司
* @date 2024/6/2 9:04
*/
@Component
public class WorkJobUtil {
/**
* 缓存key
*/
public static final String REDIS_KEY = "idgenerator_WorkJobNew";
private static FlowMsgUtil flowMsgUtil;
/**
* 将数据放入缓存
*
* @param
* @return
* @copyright 深圳市乐程软件有限公司
* @date 2024/6/2
*/
public static void insertRedis(WorkJobModel workJobModel, RedisUtil redisUtil) {
JSONObject json = new JSONObject();
json.put("taskId", workJobModel.getTaskId());
json.put("flowMsgModel", JsonUtil.getObjectToString(workJobModel.getFlowMsgModel()));
json.put("userInfo", JsonUtil.getObjectToString(workJobModel.getUserInfo()));
List<FlowTaskOperatorEntity> operatorList = workJobModel.getFlowMsgModel().getOperatorList();
if (operatorList.isEmpty()) {
return;
}
long time = System.currentTimeMillis();
boolean isNext = operatorList.stream().filter(t -> t.getCreatorTime().getTime() > time).count() > 0;
if (isNext) {
Map<String, List<FlowTaskOperatorEntity>> operatorMap = operatorList.stream().collect(Collectors.groupingBy(FlowTaskOperatorEntity::getTaskNodeId));
for (String key : operatorMap.keySet()) {
redisUtil.insertHash(REDIS_KEY, workJobModel.getTaskId() + key, String.valueOf(operatorMap.get(key).get(0).getCreatorTime().getTime()));
redisUtil.insertHash(REDIS_KEY + "_json", workJobModel.getTaskId() + key, json.toJSONString());
}
} else {
try {
flowMsgUtil.message(workJobModel.getFlowMsgModel());
} catch (Exception e) {
}
}
}
/**
* 定时器取用数据调用创建方法
*
* @param
* @return
* @copyright 深圳市乐程软件有限公司
* @date 2024/6/2
*/
public static List<WorkJobModel> getListRedis(RedisUtil redisUtil) {
List<WorkJobModel> list = new ArrayList<>();
if (redisUtil.exists(REDIS_KEY)) {
Map<String, Object> map = redisUtil.getMap(REDIS_KEY);
for (Object object : map.keySet()) {
if (map.get(object) instanceof String) {
Map<String, Object> jsonMap = JsonUtil.stringToMap(String.valueOf(map.get(object)));
String taskId = jsonMap.get("taskId").toString();
FlowMsgModel flowMsgModel = JsonUtil.getJsonToBean(jsonMap.get("flowMsgModel").toString(), FlowMsgModel.class);
UserInfo userInfo = JsonUtil.getJsonToBean(jsonMap.get("userInfo").toString(), UserInfo.class);
list.add(new WorkJobModel(taskId, flowMsgModel, userInfo));
}
}
}
return list;
}
/**
* 定时器取用数据调用创建方法
*
* @param
* @return
* @copyright 深圳市乐程软件有限公司
* @date 2024/6/2
*/
public static Map<String, Object> getListRedisTime(RedisUtil redisUtil) {
Map<String, Object> map = null;
if (redisUtil.exists(REDIS_KEY)) {
map = redisUtil.getMap(REDIS_KEY);
}
return map;
}
/**
* 获取缓存信息
*
* @param
* @return
* @copyright 深圳市乐程软件有限公司
* @date 2024/6/2
*/
public static WorkJobModel getListRedisJson(RedisUtil redisUtil, String key) {
String hashValues = redisUtil.getHashValues(REDIS_KEY + "_json", key);
Map<String, Object> jsonMap = JsonUtil.stringToMap(String.valueOf(hashValues));
String taskId = jsonMap.get("taskId").toString();
FlowMsgModel flowMsgModel = JsonUtil.getJsonToBean(jsonMap.get("flowMsgModel").toString(), FlowMsgModel.class);
UserInfo userInfo = JsonUtil.getJsonToBean(jsonMap.get("userInfo").toString(), UserInfo.class);
return new WorkJobModel(taskId, flowMsgModel, userInfo);
}
@Autowired
public void setFlowMsgUtil(FlowMsgUtil flowMsgUtil) {
WorkJobUtil.flowMsgUtil = flowMsgUtil;
}
}

View File

@@ -0,0 +1,679 @@
package com.yunzhupaas.job;
import com.yunzhupaas.base.UserInfo;
import com.yunzhupaas.config.ConfigValueUtil;
import com.yunzhupaas.constant.MsgCode;
import com.yunzhupaas.database.util.TenantDataSourceUtil;
import com.yunzhupaas.engine.entity.FlowTaskEntity;
import com.yunzhupaas.engine.entity.FlowTaskNodeEntity;
import com.yunzhupaas.engine.entity.FlowTaskOperatorEntity;
import com.yunzhupaas.engine.entity.FlowTaskOperatorRecordEntity;
import com.yunzhupaas.engine.enums.FlowNodeEnum;
import com.yunzhupaas.engine.enums.FlowTaskStatusEnum;
import com.yunzhupaas.engine.model.flowbefore.FlowTemplateAllModel;
import com.yunzhupaas.engine.model.flowengine.FlowModel;
import com.yunzhupaas.engine.model.flowengine.shuntjson.childnode.LimitModel;
import com.yunzhupaas.engine.model.flowengine.shuntjson.childnode.Properties;
import com.yunzhupaas.engine.model.flowengine.shuntjson.childnode.TimeModel;
import com.yunzhupaas.engine.model.flowmessage.FlowMsgModel;
import com.yunzhupaas.engine.model.flowtask.FlowApproveModel;
import com.yunzhupaas.engine.model.flowtask.WorkTimeoutJobModel;
import com.yunzhupaas.engine.model.flowtime.FlowTimeModel;
import com.yunzhupaas.engine.service.FlowTaskNewService;
import com.yunzhupaas.engine.service.FlowTaskNodeService;
import com.yunzhupaas.engine.service.FlowTaskOperatorService;
import com.yunzhupaas.engine.service.FlowTaskService;
import com.yunzhupaas.engine.util.FlowMsgUtil;
import com.yunzhupaas.engine.util.FlowNature;
import com.yunzhupaas.engine.util.FlowTaskUtil;
import com.yunzhupaas.engine.util.FlowTimerUtil;
import com.yunzhupaas.exception.WorkFlowException;
import com.yunzhupaas.util.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.DependsOn;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
/**
* 流程设计
*
* @author 云筑产品开发平台组
* @version V3.3.0 flowable
* @copyright 深圳市乐程软件有限公司
* @date 2024/6/15 17:37
*/
@Component
@Slf4j
@DependsOn("threadPoolTaskExecutor")
public class WorkTimeoutJobUtil {
/**
* 缓存key
*/
public static final String WORKTIMEOUT_REDIS_KEY = "idgenerator_WorkTimeout";
public static Map<String, List<ScheduledFuture>> futureList = new HashMap<>();
public static Map<String, FlowApproveModel> userInfoMap = new HashMap<>();
@Autowired
public FlowMsgUtil flowMsgUtil;
@Autowired
public FlowTaskNodeService flowTaskNodeService;
@Lazy
@Autowired
public FlowTaskNewService flowTaskNewService;
//测试
boolean testFlag = false;
@Autowired
private RedisUtil redisUtil;
@Autowired
private ConfigValueUtil configValueUtil;
@Autowired
private FlowTaskService flowTaskService;
@Autowired
private FlowTaskOperatorService flowTaskOperatorService;
@Autowired
private FlowTimerUtil flowTimerUtil;
@Autowired
private FlowTaskUtil flowTaskUtil;
private static ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = null;
WorkTimeoutJobUtil(ThreadPoolTaskExecutor threadPoolTaskExecutor) {
if(scheduledThreadPoolExecutor == null) {
scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(2, threadPoolTaskExecutor.getThreadPoolExecutor().getThreadFactory());
}
}
/**
* 将数据放入缓存
*
* @param
* @return
* @copyright 深圳市乐程软件有限公司
* @date 2024/6/2
*/
public void insertRedis(WorkTimeoutJobModel workTimeoutJobModel, RedisUtil redisUtil) {
insertRedis(workTimeoutJobModel, redisUtil, true);
}
/**
* 将数据放入缓存
*
* @param
* @return
* @copyright 深圳市乐程软件有限公司
* @date 2024/6/2
*/
public void insertRedis(WorkTimeoutJobModel workTimeoutJobModel, RedisUtil redisUtil, boolean isRunTimeOut) {
workTimeoutJobModel.setCounter(0);
workTimeoutJobModel.setOvertimeNum(0);
String objectToString = JsonUtil.getObjectToString(workTimeoutJobModel);
redisUtil.insertHash(WORKTIMEOUT_REDIS_KEY, workTimeoutJobModel.getTaskNodeOperatorId(), objectToString);
if (isRunTimeOut) {
this.runTimeOutMethod(workTimeoutJobModel, false);
}
}
/**
* 定时器取用数据调用创建方法
*
* @param
* @return
* @copyright 深圳市乐程软件有限公司
* @date 2024/6/2
*/
public List<WorkTimeoutJobModel> getListRedis(RedisUtil redisUtil) {
List<WorkTimeoutJobModel> list = new ArrayList<>();
if (redisUtil.exists(WORKTIMEOUT_REDIS_KEY)) {
Map<String, Object> map = redisUtil.getMap(WORKTIMEOUT_REDIS_KEY);
for (Object object : map.keySet()) {
if (map.get(object) instanceof String) {
WorkTimeoutJobModel workTimeoutJobModel = JsonUtil.getJsonToBean(String.valueOf(map.get(object)), WorkTimeoutJobModel.class);
list.add(workTimeoutJobModel);
}
}
}
return list;
}
/**
* 运行限时设置的内容。
*
* @param
* @return
* @copyright 深圳市乐程软件有限公司
* @date 2024/7/25
*/
public void runTimeOutMethod(WorkTimeoutJobModel entity, boolean isTimeTask) {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH");
if (testFlag) {
formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");
}
//切换数据库
if (configValueUtil.isMultiTenancy()) {
TenantDataSourceUtil.switchTenant(entity.getTenantId());
}
try {
FlowTaskOperatorEntity operatorInfo = flowTaskOperatorService.getOperatorInfo(entity.getTaskNodeOperatorId());
if (operatorInfo == null || operatorInfo.getCompletion() != 0 || operatorInfo.getState() != 0) {
throw new WorkFlowException(MsgCode.WF064.get());
}
Date realThisTime = DateUtil.stringToDate(DateUtil.getNow());
Date thisTime = formatter.parse(DateUtil.getmmNow());
FlowTaskEntity flowTask = flowTaskService.getInfo(entity.getTaskId());
FlowTemplateAllModel templateAllModel = flowTaskUtil.templateJson(flowTask.getFlowId());
List<FlowTaskNodeEntity> taskNodeList = flowTaskNodeService.getList(flowTask.getId());
FlowTaskNodeEntity flowTaskNodeEntity = flowTaskNodeService.getInfo(entity.getTaskNodeId());
//节点属性
FlowTimeModel flowTimeModel = flowTimerUtil.time(flowTaskNodeEntity, taskNodeList, flowTask, operatorInfo);
Properties approversThis = flowTimeModel.getChildNodeEvnet().getProperties();
Properties approversStart = flowTimeModel.getChildNode().getProperties();
LimitModel timeLimitConfig = approversThis.getTimeLimitConfig();
if (timeLimitConfig.getOn() == 2) {
timeLimitConfig = approversStart.getTimeLimitConfig();
}
TimeModel overTimeConfig = approversThis.getOverTimeConfig();
if (overTimeConfig.getOn() == 2) {
overTimeConfig = approversStart.getOverTimeConfig();
}
TimeModel noticeConfig = approversThis.getNoticeConfig();
if (noticeConfig.getOn() == 2) {
noticeConfig = approversStart.getNoticeConfig();
}
FlowModel flowModel = entity.getFlowModel();
//限时设置
if (timeLimitConfig.getOn() == 1) {
Date limitStartTime = formatter.parse(formatter.format(flowTimeModel.getDate()));
Date realStartTime = flowTimeModel.getDate();
Long timeout = realStartTime.getTime() - limitStartTime.getTime();
Integer limitedDuration = timeLimitConfig.getDuringDeal();
Date limitEndTime = DateUtil.dateAddHours(limitStartTime, limitedDuration);//加限时时间
if (testFlag) {
//以1分钟为准
limitEndTime = DateUtil.dateAddMinutes(limitStartTime, limitedDuration);//加限时时间
}
if (isTimeTask) {//砍掉尾数的定时器触发当前时间加上被砍掉的时间尾数,为本应该是触发定时器的时间
realThisTime = DateUtil.dateAddSeconds(thisTime, timeout.intValue() / 1000);
}
//1.提醒设置 在限定时间范围内有效
if (noticeConfig.getOn() == 1 && realThisTime.getTime() >= limitStartTime.getTime() + timeout && realThisTime.getTime() <= limitEndTime.getTime() + timeout) {
noticeMethod(entity, testFlag, thisTime, flowTask, templateAllModel, taskNodeList, flowTaskNodeEntity, flowTimeModel, noticeConfig, flowModel, limitStartTime, timeout, limitEndTime, isTimeTask, realThisTime);
}
//2.超时,在限时时长之后生效
if (overTimeConfig.getOn() == 1 && realThisTime.getTime() >= limitEndTime.getTime() + timeout) {
timeoutMethod(entity, formatter, testFlag, thisTime, flowTask, templateAllModel, taskNodeList, flowTaskNodeEntity, operatorInfo, flowTimeModel, overTimeConfig, flowModel, timeout, limitEndTime, isTimeTask, realThisTime);
}
//判断是提交过来的是否在1个小时范围内
if (!isTimeTask) {
if (overTimeConfig.getOn() == 1 && realThisTime.getTime() >= limitStartTime.getTime() + timeout && realThisTime.getTime() <= limitEndTime.getTime() + timeout) {
timeout = limitEndTime.getTime() + timeout - System.currentTimeMillis();
if (timeout < 3600000) {
isTimeTask = true;
timeoutMethod(entity, formatter, testFlag, thisTime, flowTask, templateAllModel, taskNodeList, flowTaskNodeEntity, operatorInfo, flowTimeModel, overTimeConfig, flowModel, timeout, limitEndTime, isTimeTask, realThisTime);
}
}
}
}
} catch (WorkFlowException we) {
we.printStackTrace();
redisUtil.removeHash(this.WORKTIMEOUT_REDIS_KEY, entity.getTaskNodeOperatorId());
redisUtil.removeHash(this.WORKTIMEOUT_REDIS_KEY, entity.getTaskNodeId());
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 超时相关逻辑
*
* @param
* @return
* @copyright 深圳市乐程软件有限公司
* @date 2024/8/10
*/
private void timeoutMethod(WorkTimeoutJobModel entity, SimpleDateFormat formatter, boolean testFlag, Date thisTime, FlowTaskEntity flowTask, FlowTemplateAllModel templateAllModel,
List<FlowTaskNodeEntity> taskNodeList, FlowTaskNodeEntity flowTaskNodeEntity, FlowTaskOperatorEntity operatorInfo,
FlowTimeModel flowTimeModel, TimeModel overTimeConfig, FlowModel flowModel, long timeout, Date limitEndTime, boolean isTimeTask, Date realThisTime) throws ParseException {
Integer firstTimeout = overTimeConfig.getFirstOver();
Integer timeoutInterval = overTimeConfig.getOverTimeDuring();
Date timeoutStartTime = DateUtil.dateAddHours(limitEndTime, firstTimeout);
Long delayTime = 500l;
if (isTimeTask) {
delayTime = timeout;
}
if (testFlag) {
//以1分钟为单位进行测试超时测试假设起始时间starTime=xxxx以startTimeTest替换给定
timeoutStartTime = DateUtil.dateAddMinutes(limitEndTime, firstTimeout);
}
//当节点创建时间大于超时开始时间时,以节点创建时间为起始
// if (operatorInfo.getCreatorTime().getTime() >= timeoutStartTime.getTime()) {
// String format = formatter.format(operatorInfo.getCreatorTime());
// timeoutStartTime = formatter.parse(format);
// }
if (overTimeConfig.getOverTimeDuring() == 0) {//超时间隔=0只提醒一次
if (thisTime.compareTo(timeoutStartTime) == 0) {
TimeModel finalOverTimeConfig = overTimeConfig;
Runnable resetExpire = () -> {
FlowTaskOperatorEntity operatorNow = null;
if (isTimeTask) {
operatorNow = onTimeCheckOperatorHave(entity, 1);
} else {
operatorNow = entity.getOperatorEntity();
}
if (operatorNow == null) return;
//超时消息
if (finalOverTimeConfig.getOverNotice()) {
List<FlowTaskOperatorEntity> list = new ArrayList();
list.add(operatorNow);
sendMessge(false, flowTask, templateAllModel, taskNodeList, flowTaskNodeEntity, list, flowModel);
}
//超时事件
if (finalOverTimeConfig.getOverEvent() && finalOverTimeConfig.getOverEventTime() >= 1) {
sendEvent(entity, 7, flowTimeModel);
}
//超时自动审批
if (finalOverTimeConfig.getOverAutoApprove() && finalOverTimeConfig.getOverAutoApproveTime() >= 1) {
// _log("超时任务: {}-自动审批", entity.getTaskNodeOperatorId());
//自动审批
autoApprove(operatorNow, taskNodeList, flowTask, flowModel);
}
redisUtil.removeHash(this.WORKTIMEOUT_REDIS_KEY, entity.getTaskNodeOperatorId());//超时提醒只有一次的时候完成就移除
};
this.runScheduleTask(resetExpire, delayTime, entity.getTaskNodeOperatorId());
}
} else if (overTimeConfig.getOverTimeDuring() > 0) {//超时间隔>0
//创建即触发超时
if (!isTimeTask && entity.getOvertimeNum() == 0 && realThisTime.getTime() > timeoutStartTime.getTime() + timeout) {
Long bett = realThisTime.getTime() - timeoutStartTime.getTime() - timeout;
int finaConut = 0;
if (testFlag) {
finaConut = bett.intValue() / (60000 * timeoutInterval);
} else {
finaConut = bett.intValue() / (3600000 * timeoutInterval);
}
// _log("创建即超时次数:{}", finaConut);
if (overTimeConfig.getOverNotice()) {
// _log("超时任务: {}-创建即触发超时通知", entity.getTaskNodeOperatorId());
List<FlowTaskOperatorEntity> list = new ArrayList<>();
list.add(entity.getOperatorEntity());
sendMessge(false, flowTask, templateAllModel, taskNodeList, flowTaskNodeEntity, list, flowModel);
}
if (overTimeConfig.getOverEvent() && overTimeConfig.getOverEventTime() <= (finaConut + 1) && entity.getOvertimeNum() == 0) {
//接收到就已经超时多次,直接触发一次事件
// _log("超时任务: {}-创建即触发进入超时事件", entity.getTaskNodeOperatorId());
sendEvent(entity, 7, flowTimeModel);
}
if (overTimeConfig.getOverAutoApprove() && overTimeConfig.getOverAutoApproveTime() <= (finaConut + 1) && entity.getOvertimeNum() == 0) {
// _log("超时任务: {}-创建即触发超时自动审批", entity.getTaskNodeOperatorId());
//自动审批
autoApprove(entity.getOperatorEntity(), taskNodeList, flowTask, flowModel);
}
addNum(entity.getTaskNodeOperatorId(), 1);//有执行则次数加1
}
int n = 0;
while (isTimeTask) {
Date whileTime = DateUtil.dateAddHours(timeoutStartTime, timeoutInterval * n);
if (testFlag) {
//以1分钟为单位进行测试超时测试假设起始时间starTime=xxxx以startTimeTest替换给定
whileTime = DateUtil.dateAddMinutes(timeoutStartTime, timeoutInterval * n);
}
// _log("超时任务: {}-第:{}次超时时间循环:{}", entity.getTaskNodeOperatorId(), (n + 1), DateUtil.dateFormat(whileTime));
if (thisTime.compareTo(whileTime) == 0) {
int finalN = n;
TimeModel finalOverTimeConfig1 = overTimeConfig;
Runnable resetExpire = () -> {
FlowTaskOperatorEntity operatorNow = null;
if (isTimeTask) {
operatorNow = onTimeCheckOperatorHave(entity, 1);
} else {
operatorNow = entity.getOperatorEntity();
}
if (operatorNow == null) return;
//todo 超时通知
if (finalOverTimeConfig1.getOverNotice()) {
// _log("超时任务: {}-第{}次的超时通知", entity.getTaskNodeOperatorId(), (finalN + 1));
List<FlowTaskOperatorEntity> list = new ArrayList<>();
list.add(operatorNow);
sendMessge(false, flowTask, templateAllModel, taskNodeList, flowTaskNodeEntity, list, flowModel);
}
//todo 超时事件
if (finalOverTimeConfig1.getOverEvent() && finalOverTimeConfig1.getOverEventTime() == (finalN + 1)) {
// _log("超时任务: {}-第{}次进入超时事件", entity.getTaskNodeOperatorId(), (finalN + 1));
//节点事件
sendEvent(entity, 7, flowTimeModel);
}
//todo 超时自动审批
if (finalOverTimeConfig1.getOverAutoApprove() && finalOverTimeConfig1.getOverAutoApproveTime() == (finalN + 1)) {
// _log("超时任务: {}-第{}次进入超时自动审批", entity.getTaskNodeOperatorId(), (finalN + 1));
//自动审批
autoApprove(operatorNow, taskNodeList, flowTask, flowModel);
}
addNum(entity.getTaskNodeOperatorId(), 1);
};
this.runScheduleTask(resetExpire, delayTime, entity.getTaskNodeOperatorId());
}
if (whileTime.after(thisTime)) {
break;
}
n++;
}
}
}
/**
* 提醒方法执行内容
*
* @param
* @return
* @copyright 深圳市乐程软件有限公司
* @date 2024/8/8
*/
public void noticeMethod(WorkTimeoutJobModel entity, boolean testFlag, Date thisTime, FlowTaskEntity flowTask, FlowTemplateAllModel templateAllModel,
List<FlowTaskNodeEntity> taskNodeList, FlowTaskNodeEntity flowTaskNodeEntity, FlowTimeModel flowTimeModel, TimeModel noticeConfig,
FlowModel flowModel, Date limitStartTime, long timeout, Date limitEndTime, boolean isTimeTask, Date realThisTime) {
Integer firstWarnTime = noticeConfig.getFirstOver();
Integer warnInterval = noticeConfig.getOverTimeDuring();
Date warnStartTime = DateUtil.dateAddHours(limitStartTime, firstWarnTime);
Long delayTime = 0l;
if (isTimeTask) {
delayTime = timeout;
}
if (testFlag) {
warnStartTime = DateUtil.dateAddMinutes(limitStartTime, firstWarnTime);
}
if (noticeConfig.getOverTimeDuring() == 0) {//提醒间隔为0-只提醒一次
if (thisTime.compareTo(warnStartTime) == 0) {
TimeModel finalNoticeConfig = noticeConfig;
Runnable resetExpire = () -> {
//待处理任务列表
FlowTaskOperatorEntity operatorNow = null;
if (isTimeTask) {
operatorNow = onTimeCheckOperatorHave(entity, 0);
} else {
operatorNow = entity.getOperatorEntity();
}
if (operatorNow == null) return;
if (finalNoticeConfig.getOverNotice()) {
List<FlowTaskOperatorEntity> list = new ArrayList();
list.add(operatorNow);
sendMessge(true, flowTask, templateAllModel, taskNodeList, flowTaskNodeEntity, list, flowModel);
}
if (finalNoticeConfig.getOverEvent() && finalNoticeConfig.getOverEventTime() >= 1) {
sendEvent(entity, 8, flowTimeModel);
}
addNum(entity.getTaskNodeOperatorId(), 0);
};
this.runScheduleTask(resetExpire, delayTime, entity.getTaskNodeOperatorId());
}
} else if (noticeConfig.getOverTimeDuring() > 0) {//提醒间隔大于0
long noticeTimes = (limitEndTime.getTime() - warnStartTime.getTime()) / (warnInterval * 60 * 60 * 1000);
if (testFlag) {
noticeTimes = (limitEndTime.getTime() - warnStartTime.getTime()) / (warnInterval * 60 * 1000);
}
//限定时间在创建时间之前,有过几次时的提醒的情况(前面不管多少次只提醒一次)
if (!isTimeTask && entity.getCounter() == 0 && noticeConfig.getOverEventTime() > 0 && realThisTime.getTime() > warnStartTime.getTime() + timeout) {
if (noticeConfig.getOverNotice()) {
// _log("创建即出发提醒信息");
List<FlowTaskOperatorEntity> list = new ArrayList();
list.add(entity.getOperatorEntity());
sendMessge(true, flowTask, templateAllModel, taskNodeList, flowTaskNodeEntity, list, flowModel);
}
if (noticeConfig.getOverEvent()) {
// _log("创建即出发提醒事件");
sendEvent(entity, 8, flowTimeModel);
}
addNum(entity.getTaskNodeOperatorId(), 0);//有执行则次数加1
}
for (int n = 0; n <= noticeTimes; n++) {
Date whileTime = DateUtil.dateAddHours(warnStartTime, warnInterval * n);
if (testFlag) {
//假设以1分钟代替一个小时
whileTime = DateUtil.dateAddMinutes(warnStartTime, warnInterval * n);
}
// _log("提醒任务: {}-第{}次提醒时间循环: {}", entity.getTaskNodeOperatorId(), (n + 1), DateUtil.dateFormat(whileTime));
if (isTimeTask && thisTime.compareTo(whileTime) == 0) {//定时器提醒时间
int finalN = n;
TimeModel finalNoticeConfig1 = noticeConfig;
Runnable resetExpire = () -> {
FlowTaskOperatorEntity operatorNow = null;
if (isTimeTask) {
operatorNow = onTimeCheckOperatorHave(entity, 0);
} else {
operatorNow = entity.getOperatorEntity();
}
if (operatorNow == null) return;
//todo 提醒事件
if (finalNoticeConfig1.getOverEvent() && finalNoticeConfig1.getOverEventTime() == (finalN + 1)) {
// _log("提醒任务: {}-第{}次进入提醒事件", entity.getTaskNodeOperatorId(), (finalN + 1));
sendEvent(entity, 8, flowTimeModel);
}
//todo 提醒通知
if (finalNoticeConfig1.getOverNotice()) {
// _log("提醒任务: {}-第{}次的提醒通知", entity.getTaskNodeOperatorId(), (finalN + 1));
List<FlowTaskOperatorEntity> list = new ArrayList();
list.add(operatorNow);
sendMessge(true, flowTask, templateAllModel, taskNodeList, flowTaskNodeEntity, list, flowModel);
}
addNum(entity.getTaskNodeOperatorId(), 0);
};
this.runScheduleTask(resetExpire, delayTime, entity.getTaskNodeOperatorId());
}
}
}
}
/**
* 自动审批
*
* @param
* @return
* @copyright 深圳市乐程软件有限公司
* @date 2024/8/10
*/
private void autoApprove(FlowTaskOperatorEntity operatorNow, List<FlowTaskNodeEntity> taskNodeList, FlowTaskEntity flowTask, FlowModel flowModel) {
operatorNow.setAutomation("1");
FlowTaskEntity infoSubmit = flowTaskService.getInfoSubmit(flowTask.getId(), FlowTaskEntity::getStatus);
if (infoSubmit != null && !FlowTaskStatusEnum.Suspend.getCode().equals(infoSubmit.getStatus())) {
List<FlowTaskOperatorEntity> list = new ArrayList<>();
list.add(operatorNow);
FlowApproveModel approveModel = FlowApproveModel.builder().operatorList(list).taskNodeList(taskNodeList).flowTask(flowTask).flowModel(flowModel).build();
flowTaskOperatorService.update(operatorNow);
userInfoMap.put(operatorNow.getTaskId(), approveModel);
}
}
private FlowTaskOperatorEntity onTimeCheckOperatorHave(WorkTimeoutJobModel entity, Integer type) {
FlowTaskOperatorEntity operatorNow = flowTaskOperatorService.getOperatorInfo(entity.getTaskNodeOperatorId());
if (operatorNow == null || operatorNow.getCompletion() != 0 || operatorNow.getState() != 0) {
removeTaskOperatorEntities(entity);
return null;
}
String hashValues = redisUtil.getHashValues(this.WORKTIMEOUT_REDIS_KEY, entity.getTaskNodeOperatorId());
WorkTimeoutJobModel workTimeoutJobModel = JsonUtil.getJsonToBean(hashValues, WorkTimeoutJobModel.class);
if (workTimeoutJobModel == null) {
return null;
}
if (type == 1 && !entity.getOvertimeNum().equals(workTimeoutJobModel.getOvertimeNum())) {//判断redis被取用之后是否被改变,被改变这次不执行
return null;
}
if (type == 0 && !entity.getCounter().equals(workTimeoutJobModel.getCounter())) {//判断redis被取用之后是否被改变,被改变这次不执行
return null;
}
return operatorNow;
}
private void removeTaskOperatorEntities(WorkTimeoutJobModel entity) {
//已处理任务移除缓存
redisUtil.removeHash(this.WORKTIMEOUT_REDIS_KEY, entity.getTaskNodeOperatorId());
}
/**
* 执行缓存次数加一
*
* @param
* @return
* @copyright 深圳市乐程软件有限公司
* @date 2024/8/8
*/
private void addNum(String operatorId, Integer type) {
//执行没有问题,缓存替换次数加一 type:0-提醒1-超时
String hashValues = redisUtil.getHashValues(WORKTIMEOUT_REDIS_KEY, operatorId);
WorkTimeoutJobModel entity = JsonUtil.getJsonToBean(hashValues, WorkTimeoutJobModel.class);
if (type == 0) {
Integer counter = entity.getCounter() == null ? 1 : entity.getCounter() + 1;
entity.setCounter(counter);
} else {
Integer overtimenum = entity.getOvertimeNum() == null ? 1 : entity.getOvertimeNum() + 1;
entity.setOvertimeNum(overtimenum);
}
String objectToString = JsonUtil.getObjectToString(entity);
redisUtil.insertHash(WORKTIMEOUT_REDIS_KEY, entity.getTaskNodeOperatorId(), objectToString);
}
/**
* 发送事件
*
* @param
* @return
* @copyright 深圳市乐程软件有限公司
* @date 2024/6/21
*/
private void sendEvent(WorkTimeoutJobModel entity, int status, FlowTimeModel flowTimeModel) {
// _log("进入事件调用");
//节点事件
FlowTaskOperatorRecordEntity operatorRecord = new FlowTaskOperatorRecordEntity();
operatorRecord.setTaskNodeId(entity.getTaskNodeId());
operatorRecord.setTaskId(entity.getTaskId());
FlowTaskEntity infoSubmit = flowTaskService.getInfoSubmit(entity.getTaskId(), FlowTaskEntity::getStatus);
if (infoSubmit != null && !FlowTaskStatusEnum.Suspend.getCode().equals(infoSubmit.getStatus())) {
UserInfo userInfo = entity.getFlowModel().getUserInfo();
String token = AuthUtil.loginTempUser(userInfo.getUserId(), userInfo.getTenantId(), true);
userInfo = UserProvider.getUser(token);
UserProvider.setLocalLoginUser(userInfo);
flowMsgUtil.event(status, flowTimeModel.getChildNodeEvnet(), operatorRecord, entity.getFlowModel());
}
}
/**
* 发送消息
*
* @param
* @return
* @copyright 深圳市乐程软件有限公司
* @date 2024/6/21
*/
@Async
public void sendMessge(boolean isNotice, FlowTaskEntity flowTask, FlowTemplateAllModel templateAllModel, List<FlowTaskNodeEntity> taskNodeList, FlowTaskNodeEntity flowTaskNodeEntity, List<FlowTaskOperatorEntity> list, FlowModel flowModel) {
//发送流程消息
FlowMsgModel flowMsgModel = new FlowMsgModel();
flowMsgModel.setWait(false);
if (isNotice) {
flowMsgModel.setNotice(true);
} else {
flowMsgModel.setOvertime(true);
}
flowMsgModel.setCirculateList(new ArrayList<>());
flowMsgModel.setNodeList(taskNodeList);
flowMsgModel.setOperatorList(list);
flowMsgModel.setTaskEntity(flowTask);
flowMsgModel.setTaskNodeEntity(flowTaskNodeEntity);
flowMsgModel.setFlowTemplateAllModel(templateAllModel);
flowMsgModel.setData(JsonUtil.stringToMap(flowTask.getFlowFormContentJson()));
flowMsgModel.setFlowModel(flowModel);
FlowTaskEntity infoSubmit = flowTaskService.getInfoSubmit(flowTask.getId(), FlowTaskEntity::getStatus);
if (infoSubmit != null && !FlowTaskStatusEnum.Suspend.getCode().equals(infoSubmit.getStatus())) {
try {
flowMsgUtil.message(flowMsgModel);
} catch (Exception e) {
}
}
}
private void runScheduleTask(Runnable runnable, long delayTime, String operatorId) {
ScheduledFuture schedule = scheduledThreadPoolExecutor.schedule(runnable, delayTime / 1000, TimeUnit.SECONDS);
addFuture(operatorId, schedule);
}
private void _log(String msg, Object... args) {
if (log.isDebugEnabled()) {
log.debug(msg, args);
}
}
private void addFuture(String operatorId, ScheduledFuture future) {
List<ScheduledFuture> scheduledFutures = futureList.get(operatorId) != null ? futureList.get(operatorId) : new ArrayList<>();
scheduledFutures.add(future);
futureList.put(operatorId, scheduledFutures);
}
/**
* @param operatorList
* @param isSuspend true 挂起 false 恢复
*/
public void suspendFuture(List<FlowTaskOperatorEntity> operatorList, boolean isSuspend) {
for (FlowTaskOperatorEntity entity : operatorList) {
// List<ScheduledFuture> scheduledFutures = futureList.get(entity.getId()) != null ? futureList.get(entity.getId()) : new ArrayList<>();
// for (ScheduledFuture scheduledFuture : scheduledFutures) {
// scheduledFuture.cancel(true);
// }
// futureList.remove(entity.getId());
String hashValues = redisUtil.getHashValues(WORKTIMEOUT_REDIS_KEY, entity.getId());
if (StringUtil.isNotEmpty(hashValues)) {
WorkTimeoutJobModel workTimeoutJobModel = JsonUtil.getJsonToBean(hashValues, WorkTimeoutJobModel.class);
workTimeoutJobModel.setSuspend(isSuspend);
String objectToString = JsonUtil.getObjectToString(workTimeoutJobModel);
redisUtil.insertHash(WORKTIMEOUT_REDIS_KEY, workTimeoutJobModel.getTaskNodeOperatorId(), objectToString);
}
}
}
public void approveModel(RedisTemplate redisTemplate) {
List<String> idList = new ArrayList<>();
for (String key : userInfoMap.keySet()) {
try {
boolean useSuccess = redisTemplate.opsForValue().setIfAbsent(AutoApproveJob.autoApprove + "_key:" + key, System.currentTimeMillis(), 300, TimeUnit.SECONDS);
if (!useSuccess) continue;
FlowApproveModel approveModel = userInfoMap.get(key);
UserInfo userInfo = approveModel.getFlowModel().getUserInfo();
//切换数据库
if (configValueUtil.isMultiTenancy()) {
TenantDataSourceUtil.switchTenant(userInfo.getTenantId());
}
FlowTaskEntity taskEntity = flowTaskService.getInfo(key);
List<FlowTaskOperatorEntity> list = flowTaskOperatorService.getList(key).stream().filter(t -> FlowNature.ProcessCompletion.equals(t.getCompletion()) && FlowNodeEnum.Process.getCode().equals(t.getState()) && "1".equals(t.getAutomation())).collect(Collectors.toList());
approveModel.setOperatorList(list);
approveModel.setFlowTask(taskEntity);
flowTaskUtil.approve(approveModel);
FlowTaskEntity info = flowTaskService.getInfoSubmit(key, FlowTaskEntity::getStatus);
boolean isAdd = !FlowTaskStatusEnum.Handle.getCode().equals(info.getStatus());
if (isAdd) {
idList.add(key);
}
} catch (Exception e) {
e.getMessage();
} finally {
idList.add(key);
redisTemplate.delete(AutoApproveJob.autoApprove + "_key:" + key);
}
}
for (String key : idList) {
userInfoMap.remove(key);
}
}
}

View File

@@ -0,0 +1,268 @@
package com.yunzhupaas.util;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.yunzhupaas.base.ActionResult;
import com.yunzhupaas.base.Pagination;
import com.yunzhupaas.base.entity.DataInterfaceEntity;
import com.yunzhupaas.base.entity.DictionaryDataEntity;
import com.yunzhupaas.base.entity.VisualdevEntity;
import com.yunzhupaas.base.model.flow.FlowFormDataModel;
import com.yunzhupaas.base.service.BillRuleService;
import com.yunzhupaas.base.service.DataInterfaceService;
import com.yunzhupaas.base.service.DictionaryDataService;
import com.yunzhupaas.base.util.SentMessageUtil;
import com.yunzhupaas.base.vo.DownloadVO;
import com.yunzhupaas.config.ConfigValueUtil;
import com.yunzhupaas.emnus.ModuleTypeEnum;
import com.yunzhupaas.engine.model.flowtemplate.FlowExportModel;
import com.yunzhupaas.exception.WorkFlowException;
import com.yunzhupaas.message.model.SentMessageForm;
import com.yunzhupaas.message.service.SendMessageConfigService;
import com.yunzhupaas.permission.entity.*;
import com.yunzhupaas.permission.model.organizeadministrator.OrganizeAdministratorModel;
import com.yunzhupaas.permission.service.*;
import com.yunzhupaas.util.enums.DictionaryDataEnum;
import com.yunzhupaas.visual.service.VisualdevApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.*;
import java.util.stream.Collectors;
import static com.yunzhupaas.util.Constants.ADMIN_KEY;
/**
* @author :云筑产品开发平台组
* @version: V3.1.0
* @copyright 深圳市乐程软件有限公司
* @date 2022/4/9 13:28
*/
@Component
@DS("")
public class ServiceAllUtil {
@Autowired
private DictionaryDataService dictionaryDataService;
@Autowired
private UserRelationService userRelationService;
@Autowired
private UserService userService;
@Autowired
private RoleService roleService;
@Autowired
private OrganizeService organizeService;
@Autowired
private OrganizeAdministratorService organizeAdministratorService;
@Autowired
private PositionService positionService;
@Autowired
private BillRuleService billRuleService;
@Autowired
private DataInterfaceService dataInterfaceService;
@Autowired
private SentMessageUtil sentMessageUtil;
@Autowired
private SendMessageConfigService sendMessageConfigService;
@Autowired
private DataFileExport fileExport;
@Autowired
private ConfigValueUtil configValueUtil;
//--------------------------------数据字典------------------------------
public List<DictionaryDataEntity> getDiList() {
List<DictionaryDataEntity> dictionList = dictionaryDataService.getListByTypeDataCode(DictionaryDataEnum.FLOWWOEK_ENGINE.getDictionaryTypeId());
return dictionList;
}
public List<DictionaryDataEntity> getDictionName(List<String> id) {
List<DictionaryDataEntity> dictionList = dictionaryDataService.getDictionName(id);
return dictionList;
}
//--------------------------------用户关系表------------------------------
public List<UserRelationEntity> getListByUserIdAll(List<String> id) {
List<UserRelationEntity> list = userRelationService.getListByUserIdAll(id).stream().filter(t -> StringUtil.isNotEmpty(t.getObjectId())).collect(Collectors.toList());
return list;
}
public List<UserRelationEntity> getListByObjectIdAll(List<String> id) {
List<UserRelationEntity> list = userRelationService.getListByObjectIdAll(id);
return list;
}
public String getAdmin() {
UserEntity admin = userService.getUserByAccount(ADMIN_KEY);
return admin.getId();
}
//--------------------------------用户------------------------------
public List<UserEntity> getUserName(List<String> id) {
List<UserEntity> list = getUserName(id, false);
return list;
}
public List<UserEntity> getListByManagerId(String managerId) {
List<UserEntity> list = StringUtil.isNotEmpty(managerId) ? userService.getListByManagerId(managerId, null) : new ArrayList<>();
return list;
}
public List<UserEntity> getUserName(List<String> id, boolean enableMark) {
List<UserEntity> list = userService.getUserName(id);
if (enableMark) list = list.stream().filter(t -> t.getEnabledMark() != 0).collect(Collectors.toList());
return list;
}
public List<UserEntity> getUserName(List<String> id, Pagination pagination) {
List<UserEntity> list = userService.getUserName(id, pagination);
return list;
}
public UserEntity getUserInfo(String id) {
UserEntity entity = null;
if (StringUtil.isNotEmpty(id)) {
entity = id.equalsIgnoreCase(ADMIN_KEY) ? userService.getUserByAccount(id) : userService.getInfo(id);
}
return entity;
}
public List<String> getUserListAll(List<String> idList) {
List<String> userIdList = userService.getUserIdList(idList, null);
return userIdList;
}
public List<String> getOrganizeUserList(String type) {
OrganizeAdministratorModel model = organizeAdministratorService.getOrganizeAdministratorList();
Map<String, List<String>> map = new HashMap<>();
map.put("select", model.getSelectList());
map.put("add", model.getAddList());
map.put("delete", model.getDeleteList());
map.put("edit", model.getEditList());
List<String> list = map.get(type) != null ? map.get(type) : new ArrayList<>();
List<String> userList = userRelationService.getListByObjectIdAll(list).stream().map(UserRelationEntity::getUserId).collect(Collectors.toList());
return userList;
}
//--------------------------------单据规则------------------------------
public void useBillNumber(String enCode) {
billRuleService.useBillNumber(enCode);
}
//--------------------------------角色------------------------------
public List<RoleEntity> getListByIds(List<String> id) {
List<RoleEntity> list = roleService.getListByIds(id, null, false);
return list;
}
//--------------------------------组织------------------------------
public List<OrganizeEntity> getOrganizeName(List<String> id) {
List<OrganizeEntity> list = organizeService.getOrganizeName(id);
return list;
}
public OrganizeEntity getOrganizeInfo(String id) {
OrganizeEntity entity = StringUtil.isNotEmpty(id) ? organizeService.getInfo(id) : null;
return entity;
}
public List<OrganizeEntity> getOrganizeId(String organizeId) {
List<OrganizeEntity> organizeList = new ArrayList<>();
organizeService.getOrganizeId(organizeId, organizeList);
Collections.reverse(organizeList);
return organizeList;
}
public List<OrganizeEntity> getDepartmentAll(String organizeId) {
List<OrganizeEntity> departmentAll = organizeService.getDepartmentAll(organizeId);
return departmentAll;
}
//--------------------------------岗位------------------------------
public List<PositionEntity> getPositionName(List<String> id) {
List<PositionEntity> list = positionService.getPositionName(id, false);
return list;
}
//--------------------------------远端------------------------------
public ActionResult infoToId(String interId, Map<String, String> parameterMap) {
return dataInterfaceService.infoToId(interId, null, parameterMap);
}
public List<DataInterfaceEntity> getInterfaceList(List<String> id) {
return dataInterfaceService.getList(id);
}
//--------------------------------发送消息------------------------------
public void sendMessage(List<SentMessageForm> messageListAll) {
for (SentMessageForm messageForm : messageListAll)
if (messageForm.isSysMessage()) sentMessageUtil.sendMessage(messageForm);
}
public void updateSendConfigUsed(String id, List<String> idList) {
sendMessageConfigService.updateUsed(id, idList);
}
public void sendDelegateMsg(List<SentMessageForm> messageListAll) {
for (SentMessageForm messageForm : messageListAll) {
sentMessageUtil.sendDelegateMsg(messageForm);
}
}
//------------------------------导出-------------------------------
public DownloadVO exportData(FlowExportModel model) {
DownloadVO downloadVO = fileExport.exportFile(model, configValueUtil.getTemporaryFilePath(), model.getFlowTemplate().getFullName(), ModuleTypeEnum.FLOW_FLOWENGINE.getTableName());
return downloadVO;
}
//------------------------------表单数据-------------------------------
public void createOrUpdate(FlowFormDataModel flowFormDataModel) throws WorkFlowException {
//todo 流程调用表单接口
// formDataService.saveOrUpdate(flowFormDataModel);
}
public Map<String, Object> infoData(String formId, String id) throws WorkFlowException {
//todo 流程调用表单接口
Map<String, Object> dataAll = new HashMap<>();
// if (StringUtil.isNotEmpty(formId) && StringUtil.isNotEmpty(id)) {
// Map<String, Object> info = new HashMap<>();
// ActionResult result = formDataService.info(formId, id);
// if (result.getCode() != 200) {
// throw new WorkFlowException(result.getMsg());
// }
// if (result.getData() instanceof Map) {
// info.putAll((Map) result.getData());
// }
// dataAll.putAll(info);
// }
return dataAll;
}
//------------------------------表单对象-------------------------------
public VisualdevEntity getForm(String id) {
//todo 流程调用表单接口
// FlowFormEntity form = StringUtil.isNotEmpty(id) ? flowFormService.getById(id) : null;
// return form;
return null;
}
public List<VisualdevEntity> getFlowIdList(String id) {
// List<FlowFormEntity> list = StringUtil.isNotEmpty(id) ? flowFormService.getFlowIdList(id) : new ArrayList<>();
// return list;
return null;
}
public void updateForm(VisualdevEntity entity) {
// flowFormService.updateForm(entity);
}
public void formIdList(List<String> formId, String tempJsonId) {
// flowFormRelationService.saveFlowIdByFormIds(tempJsonId, formId);
}
public void deleteFormId(String tempJsonId) {
// flowFormRelationService.saveFlowIdByFormIds(tempJsonId, new ArrayList<>());
}
}