parent
df6a9d61eb
commit
665360576a
25 changed files with 762 additions and 179 deletions
@ -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<Map<String,Object>> getProcessInstanceVariable() { |
||||
return CacheUtil.get(FLOW_CACHE, "processinstancevariable:cache", "all", () -> { |
||||
R<List<Map<String,Object>>> result = getFlowClient().bladeManMadeVariabList(); |
||||
return result.getData(); |
||||
}); |
||||
} |
||||
|
||||
public static void clearBladeManMadeCache() { |
||||
CacheUtil.clear(FLOW_CACHE); |
||||
} |
||||
|
||||
} |
||||
@ -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; |
||||
} |
||||
@ -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<String,String> getAllToMap() { |
||||
Map<String,String> re = new HashMap<>(); |
||||
RepeatTypeEnum[] values = values(); |
||||
for(RepeatTypeEnum r:values){ |
||||
re.put(r.getCode(), r.getName()); |
||||
} |
||||
return re; |
||||
} |
||||
} |
||||
@ -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<List<Map<String, Object>>> bladeManMadeVariabList(); |
||||
} |
||||
@ -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<BladeManMade> { |
||||
} |
||||
@ -0,0 +1,5 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
||||
<mapper namespace="org.springblade.plugin.workbench.mapper.BladeManMadeMapper"> |
||||
|
||||
</mapper> |
||||
@ -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<BladeManMade> { |
||||
List<Map<String,Object>> bladeManMadeVariabList(); |
||||
} |
||||
@ -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<BladeManMadeMapper, BladeManMade> implements IBladeManMadeService { |
||||
|
||||
private final HistoryService historyService; |
||||
|
||||
@Override |
||||
public List<Map<String, Object>> bladeManMadeVariabList() { |
||||
List<BladeManMade> bladeManMades = baseMapper.selectList(Wrappers.lambdaQuery()); |
||||
List<Map<String,Object>> maps = new ArrayList<>(); |
||||
if(bladeManMades.size() > 0){ |
||||
bladeManMades.forEach(bl ->{ |
||||
List<HistoricVariableInstance> variableList = historyService.createHistoricVariableInstanceQuery().processInstanceId(bl.getProcInstId()).list(); |
||||
Map<String,Object> variable = new HashMap<>(); |
||||
variableList.forEach(va ->{ |
||||
variable.put(va.getVariableName(),va.getValue()); |
||||
}); |
||||
maps.add(variable); |
||||
}); |
||||
|
||||
} |
||||
|
||||
return maps; |
||||
} |
||||
} |
||||
@ -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<Task> list) { |
||||
|
||||
} |
||||
} |
||||
@ -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<Task> list) { |
||||
System.out.println("不执行提醒"); |
||||
} |
||||
} |
||||
@ -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<Task> list); |
||||
} |
||||
@ -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<Task> 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(), ""); |
||||
}); |
||||
} |
||||
|
||||
} |
||||
} |
||||
@ -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<Map<String, Object>> 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); |
||||
|
||||
}); |
||||
} |
||||
} |
||||
} |
||||
@ -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<Map<String,Object>> list) { |
||||
|
||||
} |
||||
} |
||||
@ -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<Map<String,Object>> list); |
||||
} |
||||
@ -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<Map<String, Object>> 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); |
||||
|
||||
}); |
||||
} |
||||
} |
||||
} |
||||
@ -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<Map<String,Object>> 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); |
||||
|
||||
}); |
||||
} |
||||
|
||||
} |
||||
} |
||||
Loading…
Reference in new issue