Merge remote-tracking branch 'origin/main' into main

# Conflicts:
#	lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/service/impl/AutoStartModelServiceImpl.java
main
litao 3 years ago
commit d7af3dd2ff
  1. 1
      lab-ops/lab-log/src/main/java/org/springblade/core/log/feign/LogClient.java
  2. 30
      lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/config/TskPoolConfig.java
  3. 33
      lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/listener/ProcessEndListener.java
  4. 3
      lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/controller/WorkBenchController.java
  5. 2
      lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/feign/IFlowClient.java
  6. 22
      lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/feign/ProcessErrorLogClient.java
  7. 5
      lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/service/IAutoStartModelService.java
  8. 31
      lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workbench/service/impl/AutoStartModelServiceImpl.java
  9. 9
      lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workflow/design/controller/WfDeploymentController.java
  10. 6
      lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workflow/design/service/IWfDesignService.java
  11. 50
      lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workflow/design/service/impl/WfDesignServiceImpl.java
  12. 16
      lab-plugin/lab-workflow/src/main/java/org/springblade/plugin/workflow/process/service/impl/WfProcessService.java

@ -50,4 +50,5 @@ public class LogClient implements ILogClient {
log.setParams(log.getParams().replace("&", "&")); log.setParams(log.getParams().replace("&", "&"));
return R.data(errorLogService.save(log)); return R.data(errorLogService.save(log));
} }
} }

@ -0,0 +1,30 @@
package org.springblade.plugin.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;
/**
* @Description 自定义线程池
* @Author ytl
* @Date 2023/3/17 0017 9:21
*/
@Configuration
@EnableAsync
public class TskPoolConfig {
@Bean("taskExecutor")
public Executor taskExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(10);
executor.setMaxPoolSize(20);
executor.setQueueCapacity(200);
executor.setKeepAliveSeconds(60);
executor.setThreadNamePrefix("taskExecutor-");
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
return executor;
}
}

@ -1,15 +1,19 @@
package org.springblade.plugin.listener; package org.springblade.plugin.listener;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.flowable.engine.delegate.DelegateExecution; import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.ExecutionListener; import org.flowable.engine.delegate.ExecutionListener;
import org.springblade.core.log.model.LogError; import org.springblade.core.log.model.LogError;
import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.tool.utils.Func; import org.springblade.core.tool.utils.Func;
import org.springblade.plugin.config.SpringContextHolder; import org.springblade.plugin.config.SpringContextHolder;
import org.springblade.plugin.workbench.enumutil.RepeatEnum; import org.springblade.plugin.workbench.enumutil.RepeatEnum;
import org.springblade.plugin.workbench.feign.ProcessErrorLogClient;
import org.springblade.plugin.workbench.service.IAutoStartModelService; import org.springblade.plugin.workbench.service.IAutoStartModelService;
import org.springblade.plugin.workbench.service.impl.AutoStartModelServiceImpl; import org.springblade.plugin.workbench.service.impl.AutoStartModelServiceImpl;
import org.springblade.plugin.workflow.core.utils.WfTaskUtil;
import org.springblade.resource.enums.SysTypeEnum; import org.springblade.resource.enums.SysTypeEnum;
import org.springblade.resource.feign.IMessageClient; import org.springblade.resource.feign.IMessageClient;
@ -19,6 +23,7 @@ import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes; import org.springframework.web.context.request.ServletRequestAttributes;
import javax.annotation.PostConstruct;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -31,8 +36,6 @@ import java.util.Map;
*/ */
@Component @Component
public class ProcessEndListener implements ExecutionListener { public class ProcessEndListener implements ExecutionListener {
@Autowired
private IMessageClient messageClient;
@Override @Override
public void notify(DelegateExecution delegateExecution) { public void notify(DelegateExecution delegateExecution) {
@ -41,14 +44,17 @@ public class ProcessEndListener implements ExecutionListener {
Map<String, Object> variables = delegateExecution.getVariables(); Map<String, Object> variables = delegateExecution.getVariables();
Map<String, Object> variablesMap = new HashMap<>(); Map<String, Object> variablesMap = new HashMap<>();
variablesMap.putAll(variables); variablesMap.putAll(variables);
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); String paramsMap = variablesMap.toString();
// HttpServletResponse response = servletRequestAttributes.getResponse(); String paramsStr = paramsMap.substring(1, paramsMap.length() - 1).replace(",","&");
switch (event) { switch (event) {
case "start": case "start":
System.out.println("ProcessEndListener-start event-------------------"); System.out.println("ProcessEndListener-start event-------------------");
//中止或撤销的工作流不做任何处理了 //中止或撤销的工作流不做任何处理了
if(variablesMap.containsKey("wf_process_terminate")) return; if(variablesMap.containsKey("wf_process_terminate")) return;
IAutoStartModelService autoStartModelService = (IAutoStartModelService) SpringContextHolder.getBean(AutoStartModelServiceImpl.class); IAutoStartModelService autoStartModelService = (IAutoStartModelService) SpringContextHolder.getBean(AutoStartModelServiceImpl.class);
//判断工作流的的重复模式,重复的任务生成工单、保存任务信息,计算下次任务开始时间 //判断工作流的的重复模式,重复的任务生成工单、保存任务信息,计算下次任务开始时间
if (Func.isNotEmpty(variablesMap.get("chongfumoshi")) && !StringUtils.equals(RepeatEnum.不重复.getCode(), variablesMap.get("chongfumoshi").toString())) { if (Func.isNotEmpty(variablesMap.get("chongfumoshi")) && !StringUtils.equals(RepeatEnum.不重复.getCode(), variablesMap.get("chongfumoshi").toString())) {
String s = autoStartModelService.saveStartProcess(processInstanceId, variablesMap); String s = autoStartModelService.saveStartProcess(processInstanceId, variablesMap);
@ -56,10 +62,27 @@ public class ProcessEndListener implements ExecutionListener {
//发送消息 //发送消息
// messageClient.event(SysTypeEnum.INFORM.getValue(), "生成工单", // messageClient.event(SysTypeEnum.INFORM.getValue(), "生成工单",
// "你发起的工作流生成工单失败", 1, 5, variablesMap.get("applyUser").toString(), "/plugin/workflow/process/workorder"); // "你发起的工作流生成工单失败", 1, 5, variablesMap.get("applyUser").toString(), "/plugin/workflow/process/workorder");
//保存错误日志
LogError logError = new LogError();
logError.setMessage(s);
logError.setCreateTime(DateUtil.now());
logError.setTenantId(WfTaskUtil.getTenantId());
logError.setParams(paramsStr);
autoStartModelService.saveProcessErrorLog(logError);
} }
} else {//不重复任务,生成工单 } else {//不重复任务,生成工单
autoStartModelService.newWorkOrder(processInstanceId, variablesMap); boolean b = autoStartModelService.newWorkOrder(processInstanceId, variablesMap);
if(!b){
//保存错误日志
LogError logError = new LogError();
logError.setMessage("生成工单失败");
logError.setCreateTime(DateUtil.now());
logError.setTenantId(WfTaskUtil.getTenantId());
logError.setParams(paramsStr);
autoStartModelService.saveProcessErrorLog(logError);
}
} }
break; break;
case "end": case "end":

@ -47,10 +47,11 @@ public class WorkBenchController extends BladeController {
@ApiOperationSupport(order = 1) @ApiOperationSupport(order = 1)
@ApiOperation(value = "重复开启工作流", notes = "重复开启工作流") @ApiOperation(value = "重复开启工作流", notes = "重复开启工作流")
public void repeat(){ public void repeat(){
System.out.println("执行工作台调度任务重复开启工作流。。。。。。");
autoStartModelService.autoCreateWorkOrderByQuartz(); autoStartModelService.autoCreateWorkOrderByQuartz();
} }
//一下2个方法待删除
@GetMapping("/bladeManMadeVariabList") @GetMapping("/bladeManMadeVariabList")
@ApiOperationSupport(order = 2) @ApiOperationSupport(order = 2)
@ApiOperation(value = "bladeManMadeVariabList", notes = "bladeManMadeVariabList") @ApiOperation(value = "bladeManMadeVariabList", notes = "bladeManMadeVariabList")

@ -10,7 +10,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
* @Description * @Description 废弃
* @Author ytl * @Author ytl
* @Date 2023/2/21 0021 15:09 * @Date 2023/2/21 0021 15:09
*/ */

@ -0,0 +1,22 @@
package org.springblade.plugin.workbench.feign;
import org.springblade.core.log.model.LogError;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
/**
* @Description
* @Author ytl
* @Date 2023/3/16 0016 13:41
*/
@FeignClient(
value = "blade-log"
)
public interface ProcessErrorLogClient {
String API_PREFIX = "/log/saveErrorLog";
@PostMapping(API_PREFIX)
void saveErrorLog(@RequestBody LogError logError);
}

@ -1,10 +1,12 @@
package org.springblade.plugin.workbench.service; package org.springblade.plugin.workbench.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import org.springblade.core.log.model.LogError;
import org.springblade.core.mp.base.BaseService; import org.springblade.core.mp.base.BaseService;
import org.springblade.core.tool.api.R; import org.springblade.core.tool.api.R;
import org.springblade.plugin.workbench.entity.AutoStartModel; import org.springblade.plugin.workbench.entity.AutoStartModel;
import org.springblade.plugin.workbench.vo.AutoStartModelVO; import org.springblade.plugin.workbench.vo.AutoStartModelVO;
import org.springframework.web.bind.annotation.RequestBody;
import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotEmpty;
import java.util.List; import java.util.List;
@ -33,4 +35,7 @@ public interface IAutoStartModelService extends BaseService<AutoStartModel> {
String newWorkOrderAndSaveModel(String processinstanceId,Map<String,Object> variables); String newWorkOrderAndSaveModel(String processinstanceId,Map<String,Object> variables);
void autoCreateWorkOrderByQuartz(); void autoCreateWorkOrderByQuartz();
void saveProcessErrorLog(@RequestBody LogError logError);
} }

@ -9,6 +9,7 @@ import org.apache.commons.lang3.StringUtils;
import org.flowable.engine.HistoryService; import org.flowable.engine.HistoryService;
import org.flowable.task.api.history.HistoricTaskInstance; import org.flowable.task.api.history.HistoricTaskInstance;
import org.flowable.variable.api.history.HistoricVariableInstance; import org.flowable.variable.api.history.HistoricVariableInstance;
import org.springblade.core.log.model.LogError;
import org.springblade.core.mp.base.BaseServiceImpl; import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.tool.api.R; import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.DateUtil; import org.springblade.core.tool.utils.DateUtil;
@ -27,6 +28,7 @@ import org.springblade.plugin.operation.workorder.service.IWorkOrderService;
import org.springblade.plugin.workbench.cache.FlowCache; import org.springblade.plugin.workbench.cache.FlowCache;
import org.springblade.plugin.workbench.entity.AutoStartModel; import org.springblade.plugin.workbench.entity.AutoStartModel;
import org.springblade.plugin.workbench.enumutil.RepeatEnum; import org.springblade.plugin.workbench.enumutil.RepeatEnum;
import org.springblade.plugin.workbench.feign.ProcessErrorLogClient;
import org.springblade.plugin.workbench.mapper.BladeManMadeMapper; import org.springblade.plugin.workbench.mapper.BladeManMadeMapper;
import org.springblade.plugin.workbench.service.IAutoStartModelService; import org.springblade.plugin.workbench.service.IAutoStartModelService;
import org.springblade.plugin.workbench.util.MyDateUtil; import org.springblade.plugin.workbench.util.MyDateUtil;
@ -40,6 +42,8 @@ import org.springblade.system.user.cache.UserCache;
import org.springblade.system.user.entity.User; import org.springblade.system.user.entity.User;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.temporal.TemporalAdjusters; import java.time.temporal.TemporalAdjusters;
@ -70,13 +74,23 @@ public class AutoStartModelServiceImpl extends BaseServiceImpl<BladeManMadeMappe
private final IWorkOrderService workOrderService; private final IWorkOrderService workOrderService;
private final ProcessErrorLogClient processErrorLogClient;
@Override
public void saveProcessErrorLog(@RequestBody LogError logError){
processErrorLogClient.saveErrorLog(logError);
}
@Override @Override
public List<Map<String, Object>> bladeManMadeVariabList() { public List<Map<String, Object>> bladeManMadeVariabList() {
LambdaQueryWrapper<AutoStartModel> queryWrapper = Wrappers.lambdaQuery(); LambdaQueryWrapper<AutoStartModel> queryWrapper = Wrappers.lambdaQuery();
// status = 10 isBreak = 0才是可以自动任务,status = 1,isBreak = 0刚建立,status=1 ,isBreak = 1删除,不自动执行了 // status = 10 isBreak = 0才是可以自动任务,status = 1,isBreak = 0刚建立,status=1 ,isBreak = 1删除,不自动执行了
queryWrapper.ne(AutoStartModel::getIsBreak, 1); queryWrapper.ne(AutoStartModel::getIsBreak, 1);
List<AutoStartModel> autoStartModels = baseMapper.selectList(queryWrapper); List<AutoStartModel> autoStartModels = baseMapper.selectList(queryWrapper);
List<Map<String,Object>> maps = new ArrayList<>(); List<Map<String,Object>> maps = new ArrayList<>();
if(autoStartModels.size() > 0){ if(autoStartModels.size() > 0){
autoStartModels.forEach(bl ->{ autoStartModels.forEach(bl ->{
@ -116,10 +130,10 @@ public class AutoStartModelServiceImpl extends BaseServiceImpl<BladeManMadeMappe
copy.setRepeatMode(DictBizCache.getById(l.getRepeatMode()).getDictValue()); copy.setRepeatMode(DictBizCache.getById(l.getRepeatMode()).getDictValue());
copy.setMaintenanceCompany(UserCache.getUser(l.getMaintenanceCompany()).getName()); copy.setMaintenanceCompany(UserCache.getUser(l.getMaintenanceCompany()).getName());
HistoricTaskInstance historicTaskInstance = historyService.createHistoricTaskInstanceQuery().processInstanceId(l.getProcessInstanceId()) List<HistoricTaskInstance> listHisInstance = historyService.createHistoricTaskInstanceQuery().processInstanceId(l.getProcessInstanceId())
.orderByHistoricTaskInstanceStartTime().desc().list().get(0); .orderByHistoricTaskInstanceStartTime().desc().list();
copy.setTaskId(historicTaskInstance.getId()); copy.setTaskId(Func.isEmpty(listHisInstance) ? "" : listHisInstance.get(0).getId());
//模块和数据表 //模块和数据表
Integer type = l.getType(); Integer type = l.getType();
if(type == 1){//系统 if(type == 1){//系统
@ -153,7 +167,7 @@ public class AutoStartModelServiceImpl extends BaseServiceImpl<BladeManMadeMappe
baseMapper.updateById(autoStartModel); baseMapper.updateById(autoStartModel);
} }
} }
FlowCache.clearBladeManMadeCache(); // FlowCache.clearBladeManMadeCache();
return true; return true;
} }
@ -196,8 +210,9 @@ public class AutoStartModelServiceImpl extends BaseServiceImpl<BladeManMadeMappe
*/ */
@Override @Override
public boolean newWorkOrder(String processInstanceId,Map<String,Object> variables){ public boolean newWorkOrder(String processInstanceId,Map<String,Object> variables){
boolean save = false;
WorkOrder workOrder = new WorkOrder(); WorkOrder workOrder = new WorkOrder();
try{
workOrder.setUploadRecord(JSON.toJSONString(variables.get("uploadrecord"))); workOrder.setUploadRecord(JSON.toJSONString(variables.get("uploadrecord")));
workOrder.setOperateSys(variables.get("xitongmingchengshujuku").toString()); workOrder.setOperateSys(variables.get("xitongmingchengshujuku").toString());
workOrder.setOperateModule(variables.get("xitongmokuaishujubiao").toString()); workOrder.setOperateModule(variables.get("xitongmokuaishujubiao").toString());
@ -223,7 +238,7 @@ public class AutoStartModelServiceImpl extends BaseServiceImpl<BladeManMadeMappe
workOrder.setIsFinish(1); workOrder.setIsFinish(1);
workOrder.setFinishTime(new Date()); workOrder.setFinishTime(new Date());
} }
boolean save = false;
save = workOrderService.save(workOrder); save = workOrderService.save(workOrder);
int retryNum = 0; int retryNum = 0;
@ -236,8 +251,12 @@ public class AutoStartModelServiceImpl extends BaseServiceImpl<BladeManMadeMappe
retryNum ++; retryNum ++;
} }
} }
}catch (Exception e){
e.printStackTrace();
}finally {
return save; return save;
} }
}
/** /**
* 保存工作流程要做的事情 * 保存工作流程要做的事情

@ -11,6 +11,8 @@ import org.springblade.plugin.workflow.design.entity.WfProcessDef;
import org.springblade.plugin.workflow.design.service.IWfDesignService; import org.springblade.plugin.workflow.design.service.IWfDesignService;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController @RestController
@AllArgsConstructor @AllArgsConstructor
@RequestMapping("/design/deployment") @RequestMapping("/design/deployment")
@ -30,8 +32,13 @@ public class WfDeploymentController {
public R remove(@RequestBody String body) { public R remove(@RequestBody String body) {
JSONObject data = JSON.parseObject(body); JSONObject data = JSON.parseObject(body);
String id = data.getString("deploymentId"); String id = data.getString("deploymentId");
//查询出本次部署相关的processinstanceids
List<String> processinstanceIds = flowDesignService.getProcessinstanceIdList(id);
//删除部署信息
flowDesignService.deleteDeployment(id); flowDesignService.deleteDeployment(id);
//异步删除autostartmodel
if(processinstanceIds.size() > 0) flowDesignService.stopAutoStartModel(processinstanceIds);
return R.success("操作成功"); return R.success("操作成功");
} }

@ -6,6 +6,8 @@ import org.springblade.core.mp.support.Query;
import org.springblade.plugin.workflow.design.entity.WfModel; import org.springblade.plugin.workflow.design.entity.WfModel;
import org.springblade.plugin.workflow.design.entity.WfProcessDef; import org.springblade.plugin.workflow.design.entity.WfProcessDef;
import java.util.List;
/** /**
* 服务类 * 服务类
*/ */
@ -18,4 +20,8 @@ public interface IWfDesignService extends IService<WfModel> {
void changeDeploymentCategory(String deploymentId, String category); void changeDeploymentCategory(String deploymentId, String category);
void deleteDeployment(String deploymentId); void deleteDeployment(String deploymentId);
List<String> getProcessinstanceIdList(String deploymentId);
void stopAutoStartModel(List<String> processinstanceIds);
} }

@ -3,6 +3,7 @@ package org.springblade.plugin.workflow.design.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
@ -10,8 +11,10 @@ import org.apache.commons.lang3.StringUtils;
import org.flowable.bpmn.model.BpmnModel; import org.flowable.bpmn.model.BpmnModel;
import org.flowable.bpmn.model.ExtensionAttribute; import org.flowable.bpmn.model.ExtensionAttribute;
import org.flowable.common.engine.impl.db.SuspensionState; import org.flowable.common.engine.impl.db.SuspensionState;
import org.flowable.engine.HistoryService;
import org.flowable.engine.ProcessEngineConfiguration; import org.flowable.engine.ProcessEngineConfiguration;
import org.flowable.engine.RepositoryService; import org.flowable.engine.RepositoryService;
import org.flowable.engine.history.HistoricProcessInstance;
import org.flowable.engine.impl.persistence.entity.ProcessDefinitionEntityImpl; import org.flowable.engine.impl.persistence.entity.ProcessDefinitionEntityImpl;
import org.flowable.engine.repository.Deployment; import org.flowable.engine.repository.Deployment;
import org.flowable.engine.repository.ProcessDefinition; import org.flowable.engine.repository.ProcessDefinition;
@ -19,6 +22,8 @@ import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.utils.Func; import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.ObjectUtil; import org.springblade.core.tool.utils.ObjectUtil;
import org.springblade.core.tool.utils.StringUtil; import org.springblade.core.tool.utils.StringUtil;
import org.springblade.plugin.workbench.entity.AutoStartModel;
import org.springblade.plugin.workbench.service.IAutoStartModelService;
import org.springblade.plugin.workflow.core.constant.WfExtendConstant; import org.springblade.plugin.workflow.core.constant.WfExtendConstant;
import org.springblade.plugin.workflow.core.constant.WfProcessConstant; import org.springblade.plugin.workflow.core.constant.WfProcessConstant;
import org.springblade.plugin.workflow.core.query.WfProcessDefinitionQuery; import org.springblade.plugin.workflow.core.query.WfProcessDefinitionQuery;
@ -30,6 +35,7 @@ import org.springblade.plugin.workflow.design.entity.*;
import org.springblade.plugin.workflow.design.entity.WfProcessDef; import org.springblade.plugin.workflow.design.entity.WfProcessDef;
import org.springblade.plugin.workflow.design.mapper.WfSerialMapper; import org.springblade.plugin.workflow.design.mapper.WfSerialMapper;
import org.springblade.plugin.workflow.design.service.IWfDesignService; import org.springblade.plugin.workflow.design.service.IWfDesignService;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -46,6 +52,8 @@ public class WfDesignServiceImpl extends ServiceImpl<WfModelMapper, WfModel> imp
private final WfSerialMapper wfSerialMapper; private final WfSerialMapper wfSerialMapper;
private final RepositoryService repositoryService; private final RepositoryService repositoryService;
private final ProcessEngineConfiguration processEngineConfiguration; private final ProcessEngineConfiguration processEngineConfiguration;
private final HistoryService historyService;
private final IAutoStartModelService autoStartModelService;
@Override @Override
public IPage<WfProcessDef> deploymentPage(WfProcessDef process, Query query) { public IPage<WfProcessDef> deploymentPage(WfProcessDef process, Query query) {
@ -165,6 +173,7 @@ public class WfDesignServiceImpl extends ServiceImpl<WfModelMapper, WfModel> imp
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void deleteDeployment(String deploymentId) { public void deleteDeployment(String deploymentId) {
repositoryService.deleteDeployment(deploymentId, true); repositoryService.deleteDeployment(deploymentId, true);
WfDeploymentForm form = new WfDeploymentForm(); WfDeploymentForm form = new WfDeploymentForm();
@ -176,4 +185,45 @@ public class WfDesignServiceImpl extends ServiceImpl<WfModelMapper, WfModel> imp
wfSerialMapper.delete(new QueryWrapper<>(serial)); wfSerialMapper.delete(new QueryWrapper<>(serial));
} }
/**
* 根据部署id查询出相关的工作流id
* @param deploymentId
* @return
*/
@Override
public List<String> getProcessinstanceIdList(String deploymentId){
List<String> result = new ArrayList<>();
//deploymentId查询出ProcessDefinition,根据ProcessDefinition查询Processinstanceid,根据Processinstanceid到 autoStartModel表将is_deleted = 1
List<ProcessDefinition> list = repositoryService.createProcessDefinitionQuery().deploymentId(deploymentId).list();
if(list.size() > 0){
list.forEach(processDefinition ->{
List<HistoricProcessInstance> instances = historyService.createHistoricProcessInstanceQuery().processDefinitionId(processDefinition.getId()).list();
instances.forEach(instance ->{
result.add(instance.getId());
});
});
}
return result;
}
/**
* 逻辑删除autostartModel
* @param processinstanceIds
*/
@Override
@Async
public void stopAutoStartModel(List<String> processinstanceIds){
processinstanceIds.forEach(processinstanceId ->{
LambdaQueryWrapper<AutoStartModel> wrapper = Wrappers.lambdaQuery();
wrapper.eq(AutoStartModel::getProcessInstanceId,processinstanceId);
List<AutoStartModel> list = autoStartModelService.list(wrapper);
if(list.size() > 0){
list.forEach(autoStartModel -> {
autoStartModelService.removeById(autoStartModel.getId());
});
}
});
}
} }

@ -1021,11 +1021,11 @@ public class WfProcessService implements IWfProcessService {
.setType(WfNotice.Type.TERMINATE)); .setType(WfNotice.Type.TERMINATE));
//清空FLOW_CACHE缓存,并删除blade_flow_autostart_model中processinstanceid = 的记录 //清空FLOW_CACHE缓存,并删除blade_flow_autostart_model中processinstanceid = 的记录
CacheUtil.clear(FLOW_CACHE, Boolean.FALSE); //CacheUtil.clear(FLOW_CACHE, Boolean.FALSE);
//task.getProcessInstanceId() //task.getProcessInstanceId()
LambdaQueryWrapper<AutoStartModel> autoStartModelWrapper = Wrappers.lambdaQuery(); // LambdaQueryWrapper<AutoStartModel> autoStartModelWrapper = Wrappers.lambdaQuery();
autoStartModelWrapper.eq(AutoStartModel::getProcessInstanceId, task.getProcessInstanceId()); // autoStartModelWrapper.eq(AutoStartModel::getProcessInstanceId, task.getProcessInstanceId());
autoStartModelService.remove(autoStartModelWrapper); // autoStartModelService.remove(autoStartModelWrapper);
return R.success("终止成功"); return R.success("终止成功");
} }
@ -1122,11 +1122,11 @@ public class WfProcessService implements IWfProcessService {
this.dispatchTaskTo(task.getProcessInstanceId(), endEvent.getId()); this.dispatchTaskTo(task.getProcessInstanceId(), endEvent.getId());
//清空FLOW_CACHE缓存,并删除blade_flow_autostart_model中processinstanceid 的记录 //清空FLOW_CACHE缓存,并删除blade_flow_autostart_model中processinstanceid 的记录
CacheUtil.clear(FLOW_CACHE, Boolean.FALSE); //CacheUtil.clear(FLOW_CACHE, Boolean.FALSE);
//task.getProcessInstanceId() //task.getProcessInstanceId()
LambdaQueryWrapper<AutoStartModel> autoStartModelWrapper = Wrappers.lambdaQuery(); // LambdaQueryWrapper<AutoStartModel> autoStartModelWrapper = Wrappers.lambdaQuery();
autoStartModelWrapper.eq(AutoStartModel::getProcessInstanceId, task.getProcessInstanceId()); // autoStartModelWrapper.eq(AutoStartModel::getProcessInstanceId, task.getProcessInstanceId());
autoStartModelService.remove(autoStartModelWrapper); // autoStartModelService.remove(autoStartModelWrapper);
return R.success("撤销成功"); return R.success("撤销成功");
} }

Loading…
Cancel
Save