package com.mldong.modules.wf.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.Dict;
import cn.hutool.core.util.ReflectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.expression.ExpressionUtil;
import cn.hutool.extra.spring.SpringUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import com.mldong.base.CommonPage;
import com.mldong.base.LabelValueVO;
import com.mldong.base.YesNoEnum;
import com.mldong.modules.wf.api.WfUserApi;
import com.mldong.modules.wf.dto.ProcessInstancePageParam;
import com.mldong.modules.wf.dto.ProcessInstanceParam;
import com.mldong.modules.wf.engine.DecisionHandler;
import com.mldong.modules.wf.engine.FlowEngine;
import com.mldong.modules.wf.engine.core.Execution;
import com.mldong.modules.wf.engine.core.ServiceContext;
import com.mldong.modules.wf.engine.handlers.impl.MergeBranchHandler;
import com.mldong.modules.wf.engine.model.*;
import com.mldong.modules.wf.engine.util.FlowUtil;
import com.mldong.modules.wf.entity.ProcessCcInstance;
import com.mldong.modules.wf.entity.ProcessDefine;
import com.mldong.modules.wf.entity.ProcessInstance;
import com.mldong.modules.wf.entity.ProcessTask;
import com.mldong.modules.wf.enums.FlowConst;
import com.mldong.modules.wf.enums.ProcessInstanceStateEnum;
import com.mldong.modules.wf.enums.ProcessSubmitTypeEnum;
import com.mldong.modules.wf.enums.ProcessTaskStateEnum;
import com.mldong.modules.wf.mapper.ProcessCcInstanceMapper;
import com.mldong.modules.wf.mapper.ProcessInstanceMapper;
import com.mldong.modules.wf.mapper.ProcessTaskMapper;
import com.mldong.modules.wf.service.ProcessDefineService;
import com.mldong.modules.wf.service.ProcessInstanceService;
import com.mldong.modules.wf.service.ProcessTaskService;
import com.mldong.modules.wf.vo.HighLightVO;
import com.mldong.modules.wf.vo.ProcessInstanceVO;
import com.mldong.modules.wf.vo.ProcessTaskVO;
import com.mldong.web.LoginUserHolder;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import java.util.stream.Collectors;
/**
* <p>
* 流程实例 服务实现类
* </p>
*
* @author mldong
* @since 2023-09-26
*/
@Service
@RequiredArgsConstructor
public class ProcessInstanceServiceImpl extends ServiceImpl<ProcessInstanceMapper, ProcessInstance> implements ProcessInstanceService {
private final ProcessTaskMapper processTaskMapper;
private final ProcessCcInstanceMapper processCcInstanceMapper;
@Override
@Transactional(rollbackFor = Exception.class)
public boolean save(ProcessInstanceParam param) {
param.setId(null);
ProcessInstance processInstance = new ProcessInstance();
BeanUtil.copyProperties(param, processInstance);
return super.save(processInstance);
}
@Override
public boolean update(ProcessInstanceParam param) {
ProcessInstance processInstance = new ProcessInstance();
BeanUtil.copyProperties(param, processInstance);
return super.updateById(processInstance);
}
@Override
public CommonPage<ProcessInstanceVO> page(ProcessInstancePageParam param) {
if(StrUtil.isEmpty(param.getOrderBy())) {
// 按id即时间倒序
param.setOrderBy("t.id desc");
}
IPage<ProcessInstanceVO> page = param.buildMpPage();
QueryWrapper queryWrapper = param.buildQueryWrapper();
Long userId = LoginUserHolder.getUserId();
if(YesNoEnum.YES.equals(param.getIsCC())) {
// 我的抄送实例
queryWrapper.exists("select * from wf_process_cc_instance cc where cc.process_instance_id=t.id and cc.actor_id="+userId);
} else {
// 当前用户发起的流程
queryWrapper.eq("t.operator", userId);
}
List<ProcessInstanceVO> list = baseMapper.selectCustom(page, queryWrapper);
page.setRecords(list);
return CommonPage.toPage(page);
}
@Override
public ProcessInstanceVO findById(Long id) {
ProcessInstanceVO vo = baseMapper.findById(id);
if(vo!=null) {
vo.setJsonObject(SpringUtil.getBean(ProcessDefineService.class).getDefineJsonObject(vo.getProcessDefineId()));
}
return vo;
}
@Transactional(rollbackFor = Exception.class)
@Override
public void finishProcessInstance(Long processInstanceId) {
ProcessInstance processInstance = new ProcessInstance();
processInstance.setId(processInstanceId);
processInstance.setState(ProcessInstanceStateEnum.FINISHED.getCode());
baseMapper.updateById(processInstance);
}
@Override
public void rejectProcessInstance(Long processInstanceId) {
ProcessInstance processInstance = new ProcessInstance();
processInstance.setId(processInstanceId);
processInstance.setState(ProcessInstanceStateEnum.REJECT.getCode());
baseMapper.updateById(processInstance);
}
@Override
public ProcessInstance createProcessInstance(ProcessDefine processDefine, String operator, Dict args) {
return createProcessInstance(processDefine, operator, args, null, null);
}
@Override
public ProcessInstance createProcessInstance(ProcessDefine processDefine, String operator, Dict args, Long parentId, String parentNodeName) {
ProcessInstance processInstance = new ProcessInstance();
processInstance.setParentId(parentId);
processInstance.setParentNodeName(parentNodeName);
processInstance.setProcessDefineId(processDefine.getId());
processInstance.setOperator(operator);
processInstance.setState(ProcessInstanceStateEnum.DOING.getCode());
// 业务流水号从流程变量中获取
processInstance.setBusinessNo(args.getStr(FlowConst.BUSINESS_NO));
// 追加用户信息到参数
FlowUtil.addUserInfoToArgs(operator,args);
// 追加自动构造标题
FlowUtil.addAutoGenTitle(processDefine.getDisplayName(),args);
processInstance.setVariable(JSONUtil.toJsonStr(args));
ProcessModel processModel = SpringUtil.getBean(ProcessDefineService.class).processDefineToModel(processDefine);
String expireTime = processModel.getExpireTime();
if(StrUtil.isNotEmpty(expireTime)) {
processInstance.setExpireTime(FlowUtil.processTime(expireTime,args));
}
saveProcessInstance(processInstance);
return processInstance;
}
@Override
public void addVariable(Long processDefineId, Dict args) {
ProcessInstance processInstance = baseMapper.selectById(processDefineId);
Dict newDict = Dict.create();
newDict.putAll(JSONUtil.toBean(processInstance.getVariable(),Dict.class));
newDict.putAll(args);
ProcessInstance up = new ProcessInstance();
up.setId(processDefineId);
up.setVariable(JSONUtil.toJsonStr(newDict));
baseMapper.updateById(up);
}
@Override
public void removeVariable(Long processDefineId, String... keys) {
ProcessInstance processInstance = baseMapper.selectById(processDefineId);
Dict oldDict = JSONUtil.toBean(processInstance.getVariable(),Dict.class);
for (int i = 0; i < keys.length; i++) {
oldDict.remove(keys[i]);
}
ProcessInstance up = new ProcessInstance();
up.setId(processDefineId);
up.setVariable(JSONUtil.toJsonStr(oldDict));
baseMapper.updateById(up);
}
@Override
public void saveProcessInstance(ProcessInstance processInst
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
SpringBoot+Vue3快速开发平台、自研工作流引擎 (520个子文件)
cn.hutool.extra.expression.ExpressionEngine 49B
spring.factories 181B
param.java.ftl 5KB
entity.java.ftl 5KB
controller.java.ftl 4KB
serviceImpl.java.ftl 3KB
mapper.xml.ftl 2KB
service.java.ftl 1KB
mapper.java.ftl 940B
vo.java.ftl 363B
pageParam.java.ftl 250B
.gitattributes 115B
.gitignore 494B
.gitkeep 0B
.gitkeep 0B
.gitkeep 0B
.gitkeep 0B
.gitkeep 0B
.gitkeep 0B
.gitkeep 0B
.gitkeep 0B
.gitkeep 0B
.gitkeep 0B
.gitkeep 0B
.gitkeep 0B
.gitkeep 0B
.gitkeep 0B
.gitkeep 0B
.gitkeep 0B
.gitkeep 0B
.gitkeep 0B
.gitkeep 0B
.gitkeep 0B
.gitkeep 0B
.gitkeep 0B
.gitkeep 0B
.gitkeep 0B
.gitkeep 0B
ProcessInstanceServiceImpl.java 29KB
ProcessTaskServiceImpl.java 25KB
LowCodeServiceUtil.java 22KB
UserServiceImpl.java 19KB
AuthServiceImpl.java 14KB
SchemaServiceImpl.java 13KB
MenuServiceImpl.java 12KB
RbacServiceImpl.java 11KB
ProcessDesignServiceImpl.java 10KB
ConstantContextHolder.java 10KB
FlowEngineImpl.java 10KB
ProcessDefineServiceImpl.java 10KB
PageParam.java 9KB
CodeGenerator.java 9KB
UserController.java 9KB
ProcessTaskController.java 7KB
SchemaController.java 7KB
UserProvider.java 7KB
SwaggerConfig.java 6KB
ProcessInstanceController.java 6KB
DictServiceImpl.java 6KB
ProcessInstanceService.java 6KB
FileInfoController.java 5KB
CountersignHandler.java 5KB
MenuController.java 5KB
ProcessTaskService.java 5KB
ProcessModel.java 5KB
UrlWrapUtil.java 5KB
NodeModel.java 5KB
FileInfoServiceImpl.java 5KB
SchemaFieldServiceImpl.java 5KB
ProcessDesignController.java 5KB
DictItemServiceImpl.java 4KB
PoiUtil.java 4KB
ProcessSurrogateServiceImpl.java 4KB
CustomMetaObjectHandler.java 4KB
AssignmentHandlerScanner.java 4KB
CaptchaManager.java 4KB
DictController.java 4KB
FlowUtil.java 4KB
RedisUtil.java 4KB
AbstractNodeParser.java 4KB
RbacController.java 4KB
DictScanner.java 4KB
CommonPage.java 4KB
ProcessDefineService.java 4KB
AuthController.java 4KB
VisLogServiceImpl.java 4KB
EnhanceFreemarkerTemplateEngine.java 4KB
SchemaFieldController.java 4KB
RelIdExcelColumnHandler.java 4KB
DeptController.java 4KB
ProcessTaskActorController.java 3KB
XssHttpServletRequestWrapper.java 3KB
ConstantsInitListener.java 3KB
ProcessDefineController.java 3KB
UserService.java 3KB
RelThirdAccountController.java 3KB
ProcessDesignHisController.java 3KB
ProcessSurrogateController.java 3KB
WxMaGranter.java 3KB
TaskParser.java 3KB
共 520 条
- 1
- 2
- 3
- 4
- 5
- 6
资源评论
Java程序员-张凯
- 粉丝: 1w+
- 资源: 7453
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于java的人人乐超市采购管理系统源代码(完整前后端+mysql+说明文档+LW).zip
- 社团管理系统核心代码讲解文档.docx
- 基于java的体育用品商城源代码(完整前后端+mysql+说明文档+LW).zip
- 无线通讯标准,适合无线通讯编程使用
- 永磁同步电机(pmsm)匝间短路故障simulink仿真 提供文档参考说明
- 基于java的实验室预约管理系统源代码(完整前后端+mysql+说明文档+LW).zip
- 1734527732620.jpg
- IMG_20241218_211357.jpg
- 基于java的水产品销售网源代码(完整前后端+mysql+说明文档+LW).zip
- 基于java的网上零食购物网站系统源代码(完整前后端+mysql+说明文档+LW).zip
- Comsol含色散材料光子晶体能带求解 包含一维光子晶体和二维光子晶体 共十余个mph文件,包含多个技巧
- 基于java的网上书店系统源代码(完整前后端+mysql+说明文档+LW).zip
- 基于java的小海星幼儿园管理系统源代码(完整前后端+mysql+说明文档+LW).zip
- 基于java的在线音乐网源代码(完整前后端+mysql+说明文档+LW).zip
- 激关相关的模型,视频 增材制造.mph 激光焊接.mph run- 激光熔覆-可行.mph 激光烧蚀.mph 激光熔铸.mph 激光打孔·飞溅-较好-原始.mph 激光打孔.mph 激光打
- 基于java的新疆特产销售网源代码(完整前后端+mysql+说明文档+LW).zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功