From 665360576a3dc9d67cad4d7663d7c1f05f7987d0 Mon Sep 17 00:00:00 2001 From: yitonglei Date: Tue, 21 Feb 2023 17:45:06 +0800 Subject: [PATCH] =?UTF-8?q?1.=E5=A2=9E=E5=8A=A0=E8=87=AA=E5=8A=A8=E5=BC=80?= =?UTF-8?q?=E5=90=AF=E5=B7=A5=E4=BD=9C=E6=B5=81=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...{IRemindClient.java => IRepeatClient.java} | 8 +- .../{RemindXxlJob.java => RepeatXxlJob.java} | 15 +- .../plugin/workbench/cache/FlowCache.java | 45 +++++ .../controller/WorkBenchController.java | 32 +++- .../plugin/workbench/entity/BladeManMade.java | 25 +++ .../workbench/enumutil/RemindTypeEnum.java | 2 +- .../workbench/enumutil/RepeatTypeEnum.java | 43 +++++ .../plugin/workbench/feign/IFlowClient.java | 26 +++ .../workbench/mapper/BladeManMadeMapper.java | 12 ++ .../workbench/mapper/BladeManMadeMapper.xml | 5 + .../service/IBladeManMadeService.java | 16 ++ .../workbench/service/IWorkBenchService.java | 2 +- .../service/impl/BladeManMadeServiceImpl.java | 47 +++++ .../service/impl/WorkBenchServiceImpl.java | 181 ++++++++++++------ .../util/RemindIntervalDayClass.java | 22 --- .../plugin/workbench/util/RemindNoClass.java | 19 -- .../workbench/util/RemindOperation.java | 14 -- .../plugin/workbench/util/RemindTueClass.java | 40 ---- .../workbench/util/RepeatMonthClass.java | 68 +++++++ .../plugin/workbench/util/RepeatNoClass.java | 16 ++ .../workbench/util/RepeatOperation.java | 13 ++ .../workbench/util/RepeatQuarterClass.java | 76 ++++++++ .../workbench/util/RepeatWeekClass.java | 69 +++++++ .../process/service/IWfProcessService.java | 3 + .../service/impl/WfProcessService.java | 142 +++++++++++++- 25 files changed, 762 insertions(+), 179 deletions(-) rename lab-ops/lab-xxljob/src/main/java/org/springblade/job/executor/client/{IRemindClient.java => IRepeatClient.java} (67%) rename lab-ops/lab-xxljob/src/main/java/org/springblade/job/executor/jobhandler/{RemindXxlJob.java => RepeatXxlJob.java} (57%) create mode 100644 lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/cache/FlowCache.java create mode 100644 lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/entity/BladeManMade.java create mode 100644 lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/enumutil/RepeatTypeEnum.java create mode 100644 lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/feign/IFlowClient.java create mode 100644 lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/mapper/BladeManMadeMapper.java create mode 100644 lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/mapper/BladeManMadeMapper.xml create mode 100644 lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/service/IBladeManMadeService.java create mode 100644 lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/service/impl/BladeManMadeServiceImpl.java delete mode 100644 lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/util/RemindIntervalDayClass.java delete mode 100644 lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/util/RemindNoClass.java delete mode 100644 lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/util/RemindOperation.java delete mode 100644 lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/util/RemindTueClass.java create mode 100644 lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/util/RepeatMonthClass.java create mode 100644 lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/util/RepeatNoClass.java create mode 100644 lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/util/RepeatOperation.java create mode 100644 lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/util/RepeatQuarterClass.java create mode 100644 lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/util/RepeatWeekClass.java diff --git a/lab-ops/lab-xxljob/src/main/java/org/springblade/job/executor/client/IRemindClient.java b/lab-ops/lab-xxljob/src/main/java/org/springblade/job/executor/client/IRepeatClient.java similarity index 67% rename from lab-ops/lab-xxljob/src/main/java/org/springblade/job/executor/client/IRemindClient.java rename to lab-ops/lab-xxljob/src/main/java/org/springblade/job/executor/client/IRepeatClient.java index 5b3d193..12d2274 100644 --- a/lab-ops/lab-xxljob/src/main/java/org/springblade/job/executor/client/IRemindClient.java +++ b/lab-ops/lab-xxljob/src/main/java/org/springblade/job/executor/client/IRepeatClient.java @@ -4,16 +4,16 @@ import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.GetMapping; /** - * @Description 调用提醒模式接口类 + * @Description 调用自动创建流程 * @Author ytl * @Date 2023/2/18 0018 18:04 */ @FeignClient( value = "blade-workflow" ) -public interface IRemindClient { - String API_PREFIX = "/workBench/remind"; +public interface IRepeatClient { + String API_PREFIX = "/workBench/repeat"; @GetMapping(API_PREFIX) - void remind(); + void repeat(); } diff --git a/lab-ops/lab-xxljob/src/main/java/org/springblade/job/executor/jobhandler/RemindXxlJob.java b/lab-ops/lab-xxljob/src/main/java/org/springblade/job/executor/jobhandler/RepeatXxlJob.java similarity index 57% rename from lab-ops/lab-xxljob/src/main/java/org/springblade/job/executor/jobhandler/RemindXxlJob.java rename to lab-ops/lab-xxljob/src/main/java/org/springblade/job/executor/jobhandler/RepeatXxlJob.java index a87b57d..3765841 100644 --- a/lab-ops/lab-xxljob/src/main/java/org/springblade/job/executor/jobhandler/RemindXxlJob.java +++ b/lab-ops/lab-xxljob/src/main/java/org/springblade/job/executor/jobhandler/RepeatXxlJob.java @@ -2,10 +2,9 @@ package org.springblade.job.executor.jobhandler; import com.xxl.job.core.biz.model.ReturnT; import com.xxl.job.core.handler.annotation.XxlJob; -import com.xxl.job.core.log.XxlJobLogger; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springblade.job.executor.client.IRemindClient; +import org.springblade.job.executor.client.IRepeatClient; import org.springframework.stereotype.Component; /** @@ -14,16 +13,16 @@ import org.springframework.stereotype.Component; * @Date 2023/2/18 0018 18:10 */ -@Component("remindXxlJob") +@Component("repeatXxlJob") @AllArgsConstructor @Slf4j -public class RemindXxlJob { - private final IRemindClient remindClient; +public class RepeatXxlJob { + private final IRepeatClient remindClient; - @XxlJob("remindToComplateJob") - public ReturnT remindToComplateJob(String param) throws Exception { + @XxlJob("repeatToStartProcessJob") + public ReturnT repeatToStartProcessJob(String param) throws Exception { log.info("执行工作流提醒任务。。。。"); - remindClient.remind(); + remindClient.repeat(); return ReturnT.SUCCESS; } diff --git a/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/cache/FlowCache.java b/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/cache/FlowCache.java new file mode 100644 index 0000000..128e703 --- /dev/null +++ b/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/cache/FlowCache.java @@ -0,0 +1,45 @@ +package org.springblade.plugin.workbench.cache; + +import org.springblade.common.constant.CommonConstant; +import org.springblade.core.cache.utils.CacheUtil; +import org.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.SpringUtil; +import org.springblade.plugin.workbench.entity.BladeManMade; +import org.springblade.plugin.workbench.feign.IFlowClient; +import org.springblade.system.entity.Menu; +import org.springblade.system.feign.ISysClient; + +import java.util.List; +import java.util.Map; + +import static org.springblade.core.cache.constant.CacheConstant.FLOW_CACHE; +import static org.springblade.core.cache.constant.CacheConstant.SYS_CACHE; + +/** + * @Description + * @Author ytl + * @Date 2023/2/21 0021 14:30 + */ +public class FlowCache { + private static IFlowClient flowClient; + + private static IFlowClient getFlowClient() { + if (flowClient == null) { + flowClient = SpringUtil.getBean(IFlowClient.class); + } + return flowClient; + } + + + public static List> getProcessInstanceVariable() { + return CacheUtil.get(FLOW_CACHE, "processinstancevariable:cache", "all", () -> { + R>> result = getFlowClient().bladeManMadeVariabList(); + return result.getData(); + }); + } + + public static void clearBladeManMadeCache() { + CacheUtil.clear(FLOW_CACHE); + } + +} diff --git a/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/controller/WorkBenchController.java b/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/controller/WorkBenchController.java index a315d08..c3689be 100644 --- a/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/controller/WorkBenchController.java +++ b/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/controller/WorkBenchController.java @@ -6,11 +6,17 @@ import io.swagger.annotations.ApiOperation; import lombok.AllArgsConstructor; import org.springblade.core.boot.ctrl.BladeController; import org.springblade.core.tenant.annotation.NonDS; +import org.springblade.core.tool.api.R; +import org.springblade.plugin.workbench.entity.BladeManMade; +import org.springblade.plugin.workbench.service.IBladeManMadeService; import org.springblade.plugin.workbench.service.IWorkBenchService; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import java.util.List; +import java.util.Map; + /** * @Description 工作台 * @Author ytl @@ -24,13 +30,29 @@ import org.springframework.web.bind.annotation.RestController; @Api(value = "工作台", tags = "工作台") public class WorkBenchController extends BladeController { private final IWorkBenchService workBenchService; + private final IBladeManMadeService bladeManMadeService; - @GetMapping("/remind") + @GetMapping("/repeat") @ApiOperationSupport(order = 1) - @ApiOperation(value = "调用提醒任务", notes = "调用提醒任务") - public void remind(){ - System.out.println("执行工作台调度任务。。。。。。"); - workBenchService.getTaskToRemind(); + @ApiOperation(value = "重复开启工作流", notes = "重复开启工作流") + public void repeat(){ + System.out.println("执行工作台调度任务重复开启工作流。。。。。。"); + workBenchService.getTaskToRepeat(); + } + + @GetMapping("/bladeManMadeVariabList") + @ApiOperationSupport(order = 2) + @ApiOperation(value = "bladeManMadeVariabList", notes = "bladeManMadeVariabList") + public R>> bladeManMadeVariabList(){ + List> maps = bladeManMadeService.bladeManMadeVariabList(); + return R.data(maps); } + @GetMapping("/bladeManMadebList") + @ApiOperationSupport(order = 3) + @ApiOperation(value = "bladeManMadebList", notes = "bladeManMadebList") + public R>> bladeManMadebList(){ + List> maps = bladeManMadeService.bladeManMadeVariabList(); + return R.data(maps); + } } diff --git a/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/entity/BladeManMade.java b/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/entity/BladeManMade.java new file mode 100644 index 0000000..103b818 --- /dev/null +++ b/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/entity/BladeManMade.java @@ -0,0 +1,25 @@ +package org.springblade.plugin.workbench.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.springblade.core.tenant.mp.TenantEntity; +import org.springblade.core.tool.utils.DateUtil; + +/** + * @Description + * @Author ytl + * @Date 2023/2/20 0020 15:25 + */ + +@Data +@TableName("blade_flow_man_made") +@EqualsAndHashCode(callSuper = true) +public class BladeManMade extends TenantEntity { + private static final long serialVersionUID = 1L; + + private String procInstId; + + + private Long processSeconds; +} diff --git a/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/enumutil/RemindTypeEnum.java b/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/enumutil/RemindTypeEnum.java index f8cfc20..c94fc81 100644 --- a/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/enumutil/RemindTypeEnum.java +++ b/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/enumutil/RemindTypeEnum.java @@ -18,7 +18,7 @@ public enum RemindTypeEnum { //表dict_biz中code = reminde_mode 的id private String code; - //表dict_biz中code = reminde_mode 的dict_value + //表dict_biz中code = reminde_mode 的 private String name; RemindTypeEnum(String code, String name){ diff --git a/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/enumutil/RepeatTypeEnum.java b/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/enumutil/RepeatTypeEnum.java new file mode 100644 index 0000000..fa5364f --- /dev/null +++ b/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/enumutil/RepeatTypeEnum.java @@ -0,0 +1,43 @@ +package org.springblade.plugin.workbench.enumutil; + +import java.util.HashMap; +import java.util.Map; + +/** + * @Description + * @Author ytl + * @Date 2023/2/20 0020 17:38 + */ +public enum RepeatTypeEnum { + 不重复("1627589799957266433","repeatNoClass"), + 每周("1627589960532000769","repeatWeekClass"), + 每月("1627590001325801474", "repeatMonthClass"), + 每季度("1627590044137062402", "repeatQuarterClass"); + + //表dict_biz中code = repeat_mode 的id + private String code; + //表dict_biz中code = repeat_mode 的id + private String name; + + RepeatTypeEnum(String code, String name){ + this.name = name; + this.code = code; + } + + public String getCode(){ + return code; + } + + public String getName(){ + return name; + } + + public static Map getAllToMap() { + Map re = new HashMap<>(); + RepeatTypeEnum[] values = values(); + for(RepeatTypeEnum r:values){ + re.put(r.getCode(), r.getName()); + } + return re; + } +} diff --git a/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/feign/IFlowClient.java b/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/feign/IFlowClient.java new file mode 100644 index 0000000..cca741c --- /dev/null +++ b/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/feign/IFlowClient.java @@ -0,0 +1,26 @@ +package org.springblade.plugin.workbench.feign; + +import org.springblade.core.launch.constant.AppConstant; +import org.springblade.core.tool.api.R; +import org.springblade.system.feign.ISysClientFallback; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.GetMapping; + +import java.util.List; +import java.util.Map; + +/** + * @Description + * @Author ytl + * @Date 2023/2/21 0021 15:09 + */ +@FeignClient( + value = "blade-workflow" +) +public interface IFlowClient { + String API_PREFIX = "/workBench"; + String API_PREFIX_INSTANCE_VARIABLE = API_PREFIX + "/bladeManMadeVariabList"; + + @GetMapping(API_PREFIX_INSTANCE_VARIABLE) + R>> bladeManMadeVariabList(); +} diff --git a/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/mapper/BladeManMadeMapper.java b/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/mapper/BladeManMadeMapper.java new file mode 100644 index 0000000..ed6cc60 --- /dev/null +++ b/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/mapper/BladeManMadeMapper.java @@ -0,0 +1,12 @@ +package org.springblade.plugin.workbench.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.springblade.plugin.workbench.entity.BladeManMade; + +/** + * @Description + * @Author ytl + * @Date 2023/2/20 0020 15:23 + */ +public interface BladeManMadeMapper extends BaseMapper { +} diff --git a/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/mapper/BladeManMadeMapper.xml b/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/mapper/BladeManMadeMapper.xml new file mode 100644 index 0000000..4796948 --- /dev/null +++ b/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/mapper/BladeManMadeMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/service/IBladeManMadeService.java b/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/service/IBladeManMadeService.java new file mode 100644 index 0000000..e9ba281 --- /dev/null +++ b/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/service/IBladeManMadeService.java @@ -0,0 +1,16 @@ +package org.springblade.plugin.workbench.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import org.springblade.plugin.workbench.entity.BladeManMade; + +import java.util.List; +import java.util.Map; + +/** + * @Description + * @Author ytl + * @Date 2023/2/20 0020 15:36 + */ +public interface IBladeManMadeService extends IService { + List> bladeManMadeVariabList(); +} diff --git a/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/service/IWorkBenchService.java b/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/service/IWorkBenchService.java index 4a9c186..bb3b047 100644 --- a/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/service/IWorkBenchService.java +++ b/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/service/IWorkBenchService.java @@ -7,5 +7,5 @@ package org.springblade.plugin.workbench.service; */ public interface IWorkBenchService { - void getTaskToRemind(); + void getTaskToRepeat(); } diff --git a/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/service/impl/BladeManMadeServiceImpl.java b/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/service/impl/BladeManMadeServiceImpl.java new file mode 100644 index 0000000..6ff7661 --- /dev/null +++ b/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/service/impl/BladeManMadeServiceImpl.java @@ -0,0 +1,47 @@ +package org.springblade.plugin.workbench.service.impl; + +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import lombok.AllArgsConstructor; +import org.flowable.engine.HistoryService; +import org.flowable.variable.api.history.HistoricVariableInstance; +import org.springblade.core.mp.base.BaseServiceImpl; +import org.springblade.plugin.workbench.entity.BladeManMade; +import org.springblade.plugin.workbench.mapper.BladeManMadeMapper; +import org.springblade.plugin.workbench.service.IBladeManMadeService; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @Description + * @Author ytl + * @Date 2023/2/20 0020 15:38 + */ +@Service +@AllArgsConstructor +public class BladeManMadeServiceImpl extends BaseServiceImpl implements IBladeManMadeService { + + private final HistoryService historyService; + + @Override + public List> bladeManMadeVariabList() { + List bladeManMades = baseMapper.selectList(Wrappers.lambdaQuery()); + List> maps = new ArrayList<>(); + if(bladeManMades.size() > 0){ + bladeManMades.forEach(bl ->{ + List variableList = historyService.createHistoricVariableInstanceQuery().processInstanceId(bl.getProcInstId()).list(); + Map variable = new HashMap<>(); + variableList.forEach(va ->{ + variable.put(va.getVariableName(),va.getValue()); + }); + maps.add(variable); + }); + + } + + return maps; + } +} diff --git a/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/service/impl/WorkBenchServiceImpl.java b/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/service/impl/WorkBenchServiceImpl.java index de878da..c405e51 100644 --- a/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/service/impl/WorkBenchServiceImpl.java +++ b/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/service/impl/WorkBenchServiceImpl.java @@ -1,25 +1,26 @@ package org.springblade.plugin.workbench.service.impl; import lombok.AllArgsConstructor; +import org.flowable.engine.HistoryService; import org.flowable.engine.RuntimeService; import org.flowable.engine.TaskService; -import org.flowable.engine.runtime.ProcessInstance; -import org.flowable.task.api.Task; -import org.springblade.common.constant.CommonConstant; -import org.springblade.common.constant.TenantConstant; +import org.flowable.engine.history.HistoricProcessInstance; +import org.flowable.variable.api.history.HistoricVariableInstance; import org.springblade.core.tool.utils.DateUtil; import org.springblade.core.tool.utils.Func; import org.springblade.core.tool.utils.SpringUtil; -import org.springblade.plugin.workbench.enumutil.RemindTypeEnum; +import org.springblade.plugin.workbench.entity.BladeManMade; +import org.springblade.plugin.workbench.enumutil.RepeatTypeEnum; +import org.springblade.plugin.workbench.service.IBladeManMadeService; import org.springblade.plugin.workbench.service.IWorkBenchService; -import org.springblade.plugin.workbench.util.RemindOperation; -import org.springblade.plugin.workflow.core.utils.WfTaskUtil; +import org.springblade.plugin.workbench.util.RepeatOperation; import org.springblade.system.cache.DictBizCache; import org.springblade.system.entity.DictBiz; +import org.springblade.system.user.cache.UserCache; +import org.springblade.system.user.entity.User; import org.springframework.stereotype.Service; import java.util.*; -import java.util.stream.Collectors; /** * @Description @@ -34,65 +35,129 @@ public class WorkBenchServiceImpl implements IWorkBenchService { private final RuntimeService runtimeService; + private final IBladeManMadeService bladeManMadeService; + + private final HistoryService historyService; + + +// @Override +// public void getTaskToRemind(){ +// List list = new ArrayList<>(); +// //获取正在运行的任务 WfTaskUtil.getTenantId() +// String tenantId = WfTaskUtil.getTenantId(); +// if(Func.isEmpty(tenantId) || Func.isBlank(tenantId)){ +// list = taskService.createTaskQuery().taskTenantId(TenantConstant.DEFAULT_TENANT_ID).list(); +// } +// +// Map> taskRemindMap = new HashMap<>(); +// +// //筛选出到期的任务 +// List collect = list.stream().filter(ts -> { +// +// Map variableMap = runtimeService.getVariables(ts.getProcessInstanceId()); +// if(Func.isNotEmpty(variableMap)){ +// if(Func.isNotEmpty(variableMap.get("qiwangwanchengshijian")) && Func.isNotBlank(variableMap.get("qiwangwanchengshijian").toString())){ +// Date qiwangwanchengshijian = DateUtil.parse(variableMap.get("qiwangwanchengshijian").toString(), "yyyy-MM-dd HH:mm:ss"); +// if(DateUtil.between(DateUtil.now(), qiwangwanchengshijian).isNegative()){ +// return true; +// }else{ +// return false; +// } +// }else{ +// return false; +// } +// }else{ +// return false; +// } +// }).collect(Collectors.toList()); +// +// List reminde_mode = DictBizCache.getList("reminde_mode"); +// Map> map = new HashMap<>(); +// //将到期任务按照提醒类型分类 +// collect.forEach(cl ->{ +// Map variableMap = runtimeService.getVariables(cl.getProcessInstanceId()); +// if(Func.isNotEmpty(variableMap.get("tixingmoshi")) && Func.isNotBlank(variableMap.get("tixingmoshi").toString())){ +// DictBiz tixingmoshi = DictBizCache.getById(Long.parseLong(variableMap.get("tixingmoshi").toString())); +// List tasks; +// if(map.get(tixingmoshi.getDictValue()) == null){ +// tasks = new ArrayList(); +// }else{ +// tasks = map.get(tixingmoshi.getDictValue()); +// } +// tasks.add(cl); +// map.put(tixingmoshi.getDictValue(), tasks); +// } +// }); +// +// //遍历map并根据具体的操作类去执行提醒 +// Iterator>> iterator = map.entrySet().iterator(); +// while(iterator.hasNext()){ +// Map.Entry> next = iterator.next(); +// List tasks = next.getValue(); +// String key = next.getKey(); +// +// RemindOperation bean = SpringUtil.getContext().getBean(RemindTypeEnum.valueOf(key).getName(), RemindOperation.class); +// bean.remind(tasks); +// } +// } @Override - public void getTaskToRemind(){ - List list = new ArrayList<>(); - //获取正在运行的任务 WfTaskUtil.getTenantId() - String tenantId = WfTaskUtil.getTenantId(); - if(Func.isEmpty(tenantId) || Func.isBlank(tenantId)){ - list = taskService.createTaskQuery().taskTenantId(TenantConstant.DEFAULT_TENANT_ID).list(); - } + public void getTaskToRepeat(){ + List list = bladeManMadeService.list(); + Map>> maps = new HashMap<>(); + + if(list.size() > 0){ + for(BladeManMade bl : list){ + //历史流程变量 + Map processVariables = new HashMap<>(); + List list1 = historyService.createHistoricVariableInstanceQuery().processInstanceId(bl.getProcInstId()).list(); + HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(bl.getProcInstId()).singleResult(); + + list1.forEach(l ->{ + processVariables.put(l.getVariableName(),l.getValue()); + }); + if(Func.isNotEmpty(processVariables)){ + + //获取流程定义id key + processVariables.put("defid",historicProcessInstance.getProcessDefinitionId()); + processVariables.put("defkey",historicProcessInstance.getProcessDefinitionKey()); + //将当前BladeManMade表的processinstanceid和repeatnum传入 + processVariables.put("processinstanceid",historicProcessInstance.getId()); + User applyUser = UserCache.getUser(Long.parseLong(processVariables.get("applyUser").toString())); - Map> taskRemindMap = new HashMap<>(); + processVariables.put("createRoleName",applyUser.getRealName()); - //筛选出到期的任务 - List collect = list.stream().filter(ts -> { + //设置期望完成时间 + processVariables.put("qiwangwanchengshijian", DateUtil.plusSeconds(DateUtil.now(),bl.getProcessSeconds())); - Map variableMap = runtimeService.getVariables(ts.getProcessInstanceId()); - if(Func.isNotEmpty(variableMap)){ - if(Func.isNotEmpty(variableMap.get("qiwangwanchengshijian")) && Func.isNotBlank(variableMap.get("qiwangwanchengshijian").toString())){ - Date qiwangwanchengshijian = DateUtil.parse(variableMap.get("qiwangwanchengshijian").toString(), "yyyy-MM-dd HH:mm:ss"); - if(DateUtil.between(DateUtil.now(), qiwangwanchengshijian).isNegative()){ - return true; - }else{ - return false; + Object chongfumoshi = processVariables.get("chongfumoshi"); + if(Func.isNotEmpty(chongfumoshi)){ + DictBiz chongfuDic = DictBizCache.getById(Long.valueOf(chongfumoshi.toString())); + if(Func.isNotEmpty(chongfuDic)){ + if(Func.isNotEmpty(maps.get(chongfuDic.getDictValue()))){ + List> variableList = maps.get(chongfuDic.getDictValue()); + variableList.add(processVariables); + maps.put(chongfuDic.getDictValue(),variableList); + }else{ + List> variableList01 = new ArrayList<>(); + variableList01.add(processVariables); + maps.put(chongfuDic.getDictValue(),variableList01); + } + + } } - }else{ - return false; - } - }else{ - return false; - } - }).collect(Collectors.toList()); - - List reminde_mode = DictBizCache.getList("reminde_mode"); - Map> map = new HashMap<>(); - //将到期任务按照提醒类型分类 - collect.forEach(cl ->{ - Map variableMap = runtimeService.getVariables(cl.getProcessInstanceId()); - if(Func.isNotEmpty(variableMap.get("tixingmoshi")) && Func.isNotBlank(variableMap.get("tixingmoshi").toString())){ - DictBiz tixingmoshi = DictBizCache.getById(Long.parseLong(variableMap.get("tixingmoshi").toString())); - List tasks; - if(map.get(tixingmoshi.getDictValue()) == null){ - tasks = new ArrayList(); - }else{ - tasks = map.get(tixingmoshi.getDictValue()); } - tasks.add(cl); - map.put(tixingmoshi.getDictValue(), tasks); } - }); - - //遍历map并根据具体的操作类去执行提醒 - Iterator>> iterator = map.entrySet().iterator(); - while(iterator.hasNext()){ - Map.Entry> next = iterator.next(); - List tasks = next.getValue(); - String key = next.getKey(); + } - RemindOperation bean = SpringUtil.getContext().getBean(RemindTypeEnum.valueOf(key).getName(), RemindOperation.class); - bean.remind(tasks); + //遍历maps,调用具体的重复模式去执行重复新建工作流 + if(Func.isNotEmpty(maps)){ + Iterator>>> iterator = maps.entrySet().iterator(); + while(iterator.hasNext()){ + Map.Entry>> next = iterator.next(); + RepeatOperation repeatType = SpringUtil.getContext().getBean(RepeatTypeEnum.valueOf(next.getKey()).getName(), RepeatOperation.class); + repeatType.repeat(next.getValue()); + } } } } diff --git a/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/util/RemindIntervalDayClass.java b/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/util/RemindIntervalDayClass.java deleted file mode 100644 index 329bcdd..0000000 --- a/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/util/RemindIntervalDayClass.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.springblade.plugin.workbench.util; - -import lombok.AllArgsConstructor; -import org.flowable.task.api.Task; -import org.springframework.stereotype.Component; - -import java.util.List; - -/** - * @Description - * @Author ytl - * @Date 2023/2/20 0020 13:10 - */ -@Component(value = "remindTueClass") -@AllArgsConstructor -public class RemindIntervalDayClass implements RemindOperation{ - - @Override - public void remind(List list) { - - } -} diff --git a/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/util/RemindNoClass.java b/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/util/RemindNoClass.java deleted file mode 100644 index e953808..0000000 --- a/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/util/RemindNoClass.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.springblade.plugin.workbench.util; - -import org.flowable.task.api.Task; -import org.springframework.stereotype.Component; - -import java.util.List; - -/** - * @Description - * @Author ytl - * @Date 2023/2/18 0018 17:54 - */ -@Component(value = "remindNoClass") -public class RemindNoClass implements RemindOperation{ - @Override - public void remind(List list) { - System.out.println("不执行提醒"); - } -} diff --git a/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/util/RemindOperation.java b/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/util/RemindOperation.java deleted file mode 100644 index 9630075..0000000 --- a/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/util/RemindOperation.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.springblade.plugin.workbench.util; - -import org.flowable.task.api.Task; - -import java.util.List; - -/** - * @Description 提醒操作 - * @Author ytl - * @Date 2023/2/18 0018 17:51 - */ -public interface RemindOperation { - public void remind(List list); -} diff --git a/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/util/RemindTueClass.java b/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/util/RemindTueClass.java deleted file mode 100644 index 7aa044f..0000000 --- a/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/util/RemindTueClass.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.springblade.plugin.workbench.util; - -import lombok.AllArgsConstructor; -import org.apache.commons.lang.StringUtils; -import org.flowable.task.api.Task; -import org.springblade.core.tool.utils.DateUtil; -import org.springblade.core.tool.utils.Func; -import org.springblade.resource.enums.SysTypeEnum; -import org.springblade.resource.feign.IMessageClient; -import org.springframework.stereotype.Component; - -import java.time.DayOfWeek; -import java.time.LocalDateTime; -import java.util.List; - -/** - * @Description - * @Author ytl - * @Date 2023/2/18 0018 17:55 - */ -@Component(value = "remindTueClass") -@AllArgsConstructor -public class RemindTueClass implements RemindOperation { - - private final IMessageClient messageClient; - - @Override - public void remind(List list) { - System.out.println("每周一提醒"); - String s = DateUtil.fromDate(DateUtil.now()).getDayOfWeek().toString(); - if(StringUtils.isNotBlank(s) && StringUtils.equals("MONDAY",s)){ - list.forEach(task ->{ - // 发送提示消息 - messageClient.event(SysTypeEnum.INFORM.getValue(), "任务", - "你有新的任务(审批),请及时处理", 1, 5, task.getAssignee() == null ? "" : task.getAssignee(), ""); - }); - } - - } -} diff --git a/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/util/RepeatMonthClass.java b/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/util/RepeatMonthClass.java new file mode 100644 index 0000000..a922219 --- /dev/null +++ b/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/util/RepeatMonthClass.java @@ -0,0 +1,68 @@ +package org.springblade.plugin.workbench.util; + +import lombok.AllArgsConstructor; +import org.apache.commons.lang.StringUtils; +import org.flowable.engine.IdentityService; +import org.springblade.core.tool.utils.Func; +import org.springblade.plugin.workflow.core.constant.WfProcessConstant; +import org.springblade.plugin.workflow.process.service.IWfProcessService; +import org.springframework.stereotype.Component; + +import java.time.DayOfWeek; +import java.time.LocalDateTime; +import java.util.List; +import java.util.Map; + +/** + * @Description 每月执行,每月的第一天执行 + * @Author ytl + * @Date 2023/2/21 0021 14:14 + */ + +@Component(value = "repeatMonthClass") +@AllArgsConstructor +public class RepeatMonthClass implements RepeatOperation{ + private final IdentityService identityService; + + + private final IWfProcessService wfProcessService; + + @Override + public void repeat(List> list) { + LocalDateTime localDateTime = LocalDateTime.now(); + int dayOfMonth = localDateTime.getDayOfMonth(); + + if(dayOfMonth == 1){ //如果是每月第一天才执行 + list.forEach(map ->{ + // + identityService.setAuthenticatedUserId(map.get("applyUser").toString()); + + //开始时间 + String start = map.get("start").toString(); + //definitationid + String processDefId = map.get("defid").toString(); + //defnationkey + String defKey = map.get("defkey").toString(); + //重复次数 + Integer repeatNum = Integer.parseInt(map.get("repeatnum").toString()); + //实例id + String processinstanceId = map.get("processinstanceid").toString(); + //角色名称 + String createRoleName = map.get("createRoleName").toString(); + + map.remove("defid"); + map.remove("defkey"); + map.remove("repeatnum"); + map.remove("processinstanceid"); + + //如果是技术员发起的一般任务,直接指定assignee = 公司 + if(Func.equals(createRoleName, WfProcessConstant.COMMENT_ROLE_NAME) && Func.equals(map.get("$renwudengji"), WfProcessConstant.COMMENT_TASK_LEVEL)){ + map.put("assignee",map.get("yunweigongsi")); + } + + wfProcessService.autoStartProcessInstanceById(processDefId,defKey,map); + + }); + } + } +} diff --git a/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/util/RepeatNoClass.java b/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/util/RepeatNoClass.java new file mode 100644 index 0000000..a36d573 --- /dev/null +++ b/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/util/RepeatNoClass.java @@ -0,0 +1,16 @@ +package org.springblade.plugin.workbench.util; + +import java.util.List; +import java.util.Map; + +/** + * @Description + * @Author ytl + * @Date 2023/2/20 0020 17:06 + */ +public class RepeatNoClass implements RepeatOperation{ + @Override + public void repeat(List> list) { + + } +} diff --git a/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/util/RepeatOperation.java b/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/util/RepeatOperation.java new file mode 100644 index 0000000..abdbd90 --- /dev/null +++ b/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/util/RepeatOperation.java @@ -0,0 +1,13 @@ +package org.springblade.plugin.workbench.util; + +import java.util.List; +import java.util.Map; + +/** + * @Description 重复开启工作流 + * @Author ytl + * @Date 2023/2/20 0020 17:00 + */ +public interface RepeatOperation { + public void repeat(List> list); +} diff --git a/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/util/RepeatQuarterClass.java b/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/util/RepeatQuarterClass.java new file mode 100644 index 0000000..013ea95 --- /dev/null +++ b/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/util/RepeatQuarterClass.java @@ -0,0 +1,76 @@ +package org.springblade.plugin.workbench.util; + +import lombok.AllArgsConstructor; +import org.flowable.engine.IdentityService; +import org.springblade.core.tool.utils.Func; +import org.springblade.plugin.workflow.core.constant.WfProcessConstant; +import org.springblade.plugin.workflow.process.service.IWfProcessService; +import org.springframework.stereotype.Component; + +import java.time.LocalDate; +import java.util.List; +import java.util.Map; + +/** + * @Description 每季度第一天执行 + * @Author ytl + * @Date 2023/2/21 0021 17:18 + */ +@Component(value = "repeatQuarterClass") +@AllArgsConstructor +public class RepeatQuarterClass implements RepeatOperation{ + + private final IdentityService identityService; + + + private final IWfProcessService wfProcessService; + + @Override + public void repeat(List> list) { + LocalDate now = LocalDate.now(); + LocalDate localDate = now.withDayOfMonth(1); + int month = now.getMonth().getValue(); + if (1 <= month && month <= 3) { + localDate = localDate.withMonth(1); + } else if (4 <= month && month <= 6) { + localDate = localDate.withMonth(4); + } else if (7 <= month && month <= 9) { + localDate = localDate.withMonth(7); + } else { + localDate = localDate.withMonth(10); + } + + if(now.equals(localDate)){ + list.forEach(map ->{ + // + identityService.setAuthenticatedUserId(map.get("applyUser").toString()); + + //开始时间 + String start = map.get("start").toString(); + //definitationid + String processDefId = map.get("defid").toString(); + //defnationkey + String defKey = map.get("defkey").toString(); + //重复次数 + Integer repeatNum = Integer.parseInt(map.get("repeatnum").toString()); + //实例id + String processinstanceId = map.get("processinstanceid").toString(); + //角色名称 + String createRoleName = map.get("createRoleName").toString(); + + map.remove("defid"); + map.remove("defkey"); + map.remove("repeatnum"); + map.remove("processinstanceid"); + + //如果是技术员发起的一般任务,直接指定assignee = 公司 + if(Func.equals(createRoleName, WfProcessConstant.COMMENT_ROLE_NAME) && Func.equals(map.get("$renwudengji"), WfProcessConstant.COMMENT_TASK_LEVEL)){ + map.put("assignee",map.get("yunweigongsi")); + } + + wfProcessService.autoStartProcessInstanceById(processDefId,defKey,map); + + }); + } + } +} diff --git a/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/util/RepeatWeekClass.java b/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/util/RepeatWeekClass.java new file mode 100644 index 0000000..3ca3861 --- /dev/null +++ b/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/util/RepeatWeekClass.java @@ -0,0 +1,69 @@ +package org.springblade.plugin.workbench.util; + +import lombok.AllArgsConstructor; +import org.apache.commons.lang.StringUtils; +import org.flowable.engine.IdentityService; +import org.flowable.engine.RuntimeService; +import org.flowable.engine.runtime.ProcessInstance; +import org.springblade.core.tool.utils.DateUtil; +import org.springblade.core.tool.utils.Func; +import org.springblade.plugin.workflow.core.constant.WfProcessConstant; +import org.springblade.plugin.workflow.process.service.IWfProcessService; +import org.springframework.stereotype.Component; + +import java.time.DayOfWeek; +import java.time.LocalDateTime; +import java.util.List; +import java.util.Map; + +/** + * @Description 每周执行,每周的第一天执行 + * @Author ytl + * @Date 2023/2/20 0020 17:07 + */ +@Component(value = "repeatWeekClass") +@AllArgsConstructor +public class RepeatWeekClass implements RepeatOperation{ + + private final IdentityService identityService; + + + private final IWfProcessService wfProcessService; + + + @Override + public void repeat(List> list) { + LocalDateTime localDateTime = LocalDateTime.now(); + DayOfWeek dayOfWeek = localDateTime.getDayOfWeek(); +//MONDAY + if(StringUtils.equals(dayOfWeek.name(),"MONDAY")){ //如果是周一才执行 + list.forEach(map ->{ + identityService.setAuthenticatedUserId(map.get("applyUser").toString()); + + //definitationid + String processDefId = map.get("defid").toString(); + //defnationkey + String defKey = map.get("defkey").toString(); + + //实例id + String processinstanceId = map.get("processinstanceid").toString(); + //角色名称 + String createRoleName = map.get("createRoleName").toString(); + + map.remove("defid"); + map.remove("defkey"); + map.remove("repeatnum"); + map.remove("processinstanceid"); + + //如果是技术员发起的一般任务,直接指定assignee = 公司 + if(Func.equals(createRoleName, WfProcessConstant.COMMENT_ROLE_NAME) && Func.equals(map.get("$renwudengji"), WfProcessConstant.COMMENT_TASK_LEVEL)){ + map.put("assignee",map.get("yunweigongsi")); + } + + wfProcessService.autoStartProcessInstanceById(processDefId,defKey,map); + + }); + } + + } +} diff --git a/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workflow/process/service/IWfProcessService.java b/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workflow/process/service/IWfProcessService.java index c86b1d1..4bfa233 100644 --- a/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workflow/process/service/IWfProcessService.java +++ b/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workflow/process/service/IWfProcessService.java @@ -143,4 +143,7 @@ public interface IWfProcessService { * @return */ Task selectProcessInstanceId(String processInstanceId, String userCode); + + + String autoStartProcessInstanceById(String processDefId, String defKey,Map variables); } diff --git a/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workflow/process/service/impl/WfProcessService.java b/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workflow/process/service/impl/WfProcessService.java index e43a878..ed0669e 100644 --- a/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workflow/process/service/impl/WfProcessService.java +++ b/lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workflow/process/service/impl/WfProcessService.java @@ -3,6 +3,7 @@ package org.springblade.plugin.workflow.process.service.impl; import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.google.common.collect.Sets; import lombok.AllArgsConstructor; @@ -39,6 +40,9 @@ import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.DateUtil; import org.springblade.core.tool.utils.Func; import org.springblade.core.tool.utils.StringUtil; +import org.springblade.plugin.workbench.cache.FlowCache; +import org.springblade.plugin.workbench.entity.BladeManMade; +import org.springblade.plugin.workbench.service.IBladeManMadeService; import org.springblade.plugin.workflow.core.constant.WfExtendConstant; import org.springblade.plugin.workflow.core.utils.ObjectUtil; import org.springblade.plugin.workflow.core.utils.WfModelUtil; @@ -57,11 +61,14 @@ import org.springblade.plugin.workflow.process.service.*; import org.springblade.system.user.cache.UserCache; import org.springblade.system.user.entity.User; import org.springblade.system.user.feign.IUserSearchClient; +import org.springframework.data.redis.core.RedisTemplate; import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.AsyncResult; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import javax.annotation.Nullable; +import java.time.Duration; import java.util.*; import java.util.concurrent.Future; import java.util.stream.Collectors; @@ -86,9 +93,80 @@ public class WfProcessService implements IWfProcessService { private final IUserSearchClient userSearchService; + private final IBladeManMadeService bladeManMadeService; + + private final RedisTemplate redisTemplate; + // private final LimsInvoked limsInvoked; @Override + public String autoStartProcessInstanceById(String processDefId,String defKey, Map map){ + + ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefId, defKey, map); + return handleAutoProcessInstance(processInstance, map); + } + + private String handleAutoProcessInstance(ProcessInstance processInstance, @Nullable Map variables) { + String userId = WfTaskUtil.getTaskUser(); + String processDefId = processInstance.getProcessDefinitionId(); + if (variables == null) { + variables = new HashMap<>(); + } + // 业务变量 + Map customVariables = new HashMap<>(); + + //User user = UserCache.getUser(Long.parseLong(userId)); + customVariables.put(WfProcessConstant.TASK_VARIABLE_APPLY_USER_NAME, variables.get("applyUser").toString()); + // 流水号 + String sn = wfSerialService.getNextSN(processInstance.getDeploymentId()); + if (StringUtil.isNotBlank(sn)) { + customVariables.put(WfProcessConstant.TASK_VARIABLE_SN, sn); + } + runtimeService.setVariables(processInstance.getId(), customVariables); + + // 修改流程实例名称,方便查询 + try { + runtimeService.setProcessInstanceName(processInstance.getId(), processInstance.getProcessDefinitionName()); + } catch (Exception ignore) { + return processInstance.getId(); + } + // 自动跳过第一节点 + BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefId); + String skip = WfModelUtil.getProcessExtensionAttribute(bpmnModel, WfExtendConstant.SKIP_FIRST_NODE); + if (StringUtil.isNotBlank(skip) && "true".equals(skip)) { + List taskList = taskService.createTaskQuery().processInstanceId(processInstance.getId()).list(); + taskList.forEach(task -> taskService.complete(task.getId())); + } + // 指定下一步审核人 + this.handleNextNodeAssignee(processInstance.getId(), variables.get(WfProcessConstant.TASK_VARIABLE_ASSIGNEE), null); + // 消息 + wfNoticeService.resolveNoticeInfo(new WfNotice() + .setFromUserId(userId) + .setProcessId(processInstance.getId()) + .setType(WfNotice.Type.START)); + // 处理抄送 + Object copyUser = variables.get(WfProcessConstant.TASK_VARIABLE_COPY_USER); + if (ObjectUtil.isNotEmpty(copyUser)) { + List taskList = taskService.createTaskQuery().processInstanceId(processInstance.getId()).list(); + if (taskList.size() > 0) { + Task task = taskList.get(0); + WfProcess process = new WfProcess(); + process.setAssignee(WfTaskUtil.getTaskUser()); + process.setAssigneeName(WfTaskUtil.getNickName()); + process.setTaskId(task.getId()); + process.setTaskName(processInstance.getProcessDefinitionName() + "-" + task.getName()); + process.setProcessInstanceId(processInstance.getId()); + process.setCopyUser(copyUser.toString()); + wfCopyService.resolveCopyUser(process); + } + } + // 删除草稿箱 + wfDraftService.deleteByProcessDefId(processDefId, WfTaskUtil.getTaskUser(), variables.get(WfProcessConstant.TASK_VARIABLE_PLATFORM)); + return processInstance.getId(); + } + + @Override + @Transactional(rollbackFor = Exception.class) public String startProcessInstanceById(String processDefId, Map variables) { ProcessDefinition definition = WfProcessCache.getProcessDefinition(processDefId); if (definition == null) { @@ -100,17 +178,67 @@ public class WfProcessService implements IWfProcessService { variables.put(WfProcessConstant.TASK_VARIABLE_APPLY_USER, userId); variables.put(WfProcessConstant.TASK_CREATE_ROLE, createRoleName); - //如果是技术员发起的一般任务,直接指定assignee = 公司 - if(Func.equals(createRoleName, WfProcessConstant.COMMENT_ROLE_NAME) && Func.equals(variables.get("$renwudengji"), WfProcessConstant.COMMENT_TASK_LEVEL)){ - variables.put("assignee",variables.get("yunweigongsi")); + //判断该手动发起任务是否已经发起过,或者时不重复任务 + if(StringUtils.equals(variables.get("$chongfumoshi").toString(),"不重复")){ + // 启动流程 + identityService.setAuthenticatedUserId(userId); + + ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefId, definition.getKey(), variables); + return handleProcessInstance(processInstance, variables); + }else if(this.isNewProcess(variables) && Func.isEmpty(variables.get("forcestart"))){ + return "类似任务已经发起过,是否要强制发起"; + }else{ + //如果是技术员发起的一般任务,直接指定assignee = 公司 + if(Func.equals(createRoleName, WfProcessConstant.COMMENT_ROLE_NAME) && Func.equals(variables.get("$renwudengji"), WfProcessConstant.COMMENT_TASK_LEVEL)){ + variables.put("assignee",variables.get("yunweigongsi")); + } + // 启动流程 + identityService.setAuthenticatedUserId(userId); + + ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefId, definition.getKey(), variables); + + //将新增的流程实例id保存到blade_flow_man_made + BladeManMade bladeManMade = new BladeManMade(); + bladeManMade.setProcInstId(processInstance.getId()); + Date startTime = processInstance.getStartTime(); + Date qiwangwanchengshijian = DateUtil.parse(variables.get("qiwangwanchengshijian").toString(), "yyyy-MM-dd HH:mm:ss"); + Duration between = DateUtil.between(startTime, qiwangwanchengshijian); + bladeManMade.setProcessSeconds(between.getSeconds()); + bladeManMadeService.save(bladeManMade); + FlowCache.clearBladeManMadeCache(); + return handleProcessInstance(processInstance, variables); } - // 启动流程 - identityService.setAuthenticatedUserId(userId); - ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefId, definition.getKey(), variables); + } + //判断该类型的流程是否已经发起过,false:有重复的,true:没重复 + private boolean isNewProcess(Map variables){ + variables.remove("qiwangwanchengshijian"); + boolean b = false; + List> processInstanceVariable = FlowCache.getProcessInstanceVariable(); + for(Map hi : processInstanceVariable){ + boolean noEqual = this.isNoEqual(variables, hi); + if(noEqual){//有不相等的,直接下一次循环判断 + continue; + }else{//没有不相等的,说明有重复的,结束循环,返回b=true + b = true; + break; + } + } - return handleProcessInstance(processInstance, variables); + return b; + } +//判断是否有不相等的,true 有 false没有 + private boolean isNoEqual(Map map1, Map map2){ + Set> entries = map1.entrySet(); + Iterator> iterator = entries.iterator(); + while(iterator.hasNext()){ + Map.Entry next = iterator.next(); + if(!Func.equals(next.getValue(),map2.get(next.getKey()))){ + return true; + } + } + return false; } @Override