mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-30 03:01:53 +08:00
工作流的 code review
This commit is contained in:
parent
baab642d28
commit
1bc4bdac0c
@ -28,6 +28,7 @@ public class LeaveApplyEndProcessor implements ExecutionListener {
|
||||
final Object approved = delegateExecution.getVariable("approved");
|
||||
OALeaveDO updateDo = new OALeaveDO();
|
||||
updateDo.setId(Long.valueOf(businessKey));
|
||||
// TODO @jason:代码的格式哈。} else { 。另外,这里可以简化成,二元表达式
|
||||
if (Objects.equals(approved, true)) {
|
||||
updateDo.setStatus(FlowStatusEnum.PASS.getStatus());
|
||||
}else{
|
||||
|
@ -26,11 +26,9 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.*;
|
||||
|
||||
import static cn.iocoder.yudao.adminserver.modules.bpm.enums.oa.OAErrorCodeConstants.*;
|
||||
import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants.POST_CODE_DUPLICATE;
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
|
||||
/**
|
||||
@ -116,6 +114,7 @@ public class OALeaveServiceImpl implements OALeaveService {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO @jason:要不,请假不支持删除,只支持取消?
|
||||
@Override
|
||||
public void deleteLeave(Long id) {
|
||||
// 校验存在
|
||||
|
@ -6,7 +6,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
// TODO @jason:前缀
|
||||
/**
|
||||
* 用户任务服务接口
|
||||
*/
|
||||
@ -25,14 +25,13 @@ public interface TaskService {
|
||||
*/
|
||||
void claimTask(String taskId);
|
||||
|
||||
|
||||
// TODO @jason:可以把实现方法的注释,统一写到接口里
|
||||
/**
|
||||
* 办理完成用户任务
|
||||
* @param taskReq 任务参数, 包含任务的参数,和 评论
|
||||
*/
|
||||
void completeTask(TaskReqVO taskReq);
|
||||
|
||||
|
||||
/**
|
||||
* 根据任务id, 查询已经完成的用户任务,未完成的用户任务
|
||||
* @param taskQuery 查询参数 一般 taskId
|
||||
@ -45,7 +44,6 @@ public interface TaskService {
|
||||
*/
|
||||
List<TaskStepVO> getHistorySteps(String processInstanceId);
|
||||
|
||||
|
||||
/**
|
||||
* 获取用户任务的 formKey, 对应外置表单, 需要根据formKey 对应业务表单
|
||||
* @param taskQuery 查询参数 ,一般taskId
|
||||
|
@ -174,21 +174,24 @@ public class TaskServiceImpl implements TaskService {
|
||||
public void getHighlightImg(String processInstanceId, HttpServletResponse response) {
|
||||
// 查询历史
|
||||
//TODO 云扬四海 貌似流程结束后,点击审批进度会报错
|
||||
HistoricProcessInstance hpi = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
|
||||
// 如果有结束时间
|
||||
// TODO @Li:一些 historyService 的查询,貌似比较通用,是不是抽一些小方法出来
|
||||
HistoricProcessInstance hpi = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
|
||||
// 如果有结束时间 TODO @Li:如果查询不到,是不是抛出一个业务异常比较好哈?
|
||||
if (hpi == null) {
|
||||
return;
|
||||
}
|
||||
// 没有结束时间。说明流程在执行过程中
|
||||
// TODO @Li:一些 runtimeService 的查询,貌似比较通用,是不是抽一些小方法出来
|
||||
ProcessInstance pi = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
|
||||
BpmnModel bpmnModel = repositoryService.getBpmnModel(pi.getProcessDefinitionId());
|
||||
BpmnModel bpmnModel = repositoryService.getBpmnModel(pi.getProcessDefinitionId()); // TODO @Li:这块和下面的逻辑比较相关,可以在后面一点查询。
|
||||
List<String> highLightedActivities = new ArrayList<>();
|
||||
|
||||
List<HistoricActivityInstance> historicActivityInstances = historyService.createHistoricActivityInstanceQuery().processInstanceId(processInstanceId)
|
||||
.orderByHistoricActivityInstanceId().asc().list();
|
||||
.orderByHistoricActivityInstanceId().asc().list(); // TODO @Li:这块和下面的逻辑比较相关,可以在后面一点查询。
|
||||
// 获取所有活动节点
|
||||
List<HistoricActivityInstance> finishedInstances = historyService.createHistoricActivityInstanceQuery()
|
||||
.processInstanceId(processInstanceId).finished().list();
|
||||
// TODO @Li:highLightedActivities 结果,可以使用 CollUtils.buildList() 方法。即使不用,也应该用 stream。简洁很重要。
|
||||
for (HistoricActivityInstance hai : finishedInstances) {
|
||||
highLightedActivities.add(hai.getActivityId());
|
||||
}
|
||||
@ -199,6 +202,7 @@ public class TaskServiceImpl implements TaskService {
|
||||
List<String> highLightedFlowIds = getHighLightedFlows(bpmnModel, historicActivityInstances);
|
||||
|
||||
//设置"宋体"
|
||||
// TODO @Li:Service 返回 bytes,最终 Controller 去写
|
||||
try (InputStream inputStream = processDiagramGenerator.generateDiagram(bpmnModel, highLightedActivities, highLightedFlowIds,
|
||||
"宋体", "宋体", "宋体")){
|
||||
String picName = hpi.getProcessDefinitionName()+".svg";
|
||||
@ -207,9 +211,9 @@ public class TaskServiceImpl implements TaskService {
|
||||
} catch (IOException e) {
|
||||
log.error(ExceptionUtils.getStackTrace(e));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// TODO @Li:参考 ServletUtils 方法。如果没有满足的,可以在写一个。
|
||||
private void responseImage(HttpServletResponse response, InputStream inputStream, String picName) throws IOException {
|
||||
response.setContentType("application/octet-stream;charset=UTF-8");
|
||||
response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(picName, "UTF-8"));
|
||||
@ -220,6 +224,8 @@ public class TaskServiceImpl implements TaskService {
|
||||
}
|
||||
response.flushBuffer();
|
||||
}
|
||||
|
||||
// TODO @Li:这个方法的可读性还有一定的优化空间,可以思考下哈。
|
||||
/**
|
||||
* 获取已经流转的线 https://blog.csdn.net/qiuxinfa123/article/details/119579863
|
||||
* @see
|
||||
@ -244,6 +250,7 @@ public class TaskServiceImpl implements TaskService {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO @Li:这两个变量,直接放到循环里。这种优化一般不需要做的,对性能影响超级小。
|
||||
FlowNode currentFlowNode;
|
||||
FlowNode targetFlowNode;
|
||||
// 遍历已完成的活动实例,从每个实例的outgoingFlows中找到已执行的
|
||||
@ -252,11 +259,10 @@ public class TaskServiceImpl implements TaskService {
|
||||
currentFlowNode = (FlowNode) bpmnModel.getMainProcess().getFlowElement(currentActivityInstance.getActivityId(), true);
|
||||
List<SequenceFlow> sequenceFlows = currentFlowNode.getOutgoingFlows();
|
||||
|
||||
/**
|
||||
* 遍历outgoingFlows并找到已流转的 满足如下条件认为已已流转:
|
||||
* 1.当前节点是并行网关或兼容网关,则通过outgoingFlows能够在历史活动中找到的全部节点均为已流转
|
||||
* 2.当前节点是以上两种类型之外的,通过outgoingFlows查找到的时间最早的流转节点视为有效流转
|
||||
*/
|
||||
// 遍历outgoingFlows并找到已流转的 满足如下条件认为已已流转:
|
||||
// 1.当前节点是并行网关或兼容网关,则通过outgoingFlows能够在历史活动中找到的全部节点均为已流转
|
||||
// 2.当前节点是以上两种类型之外的,通过outgoingFlows查找到的时间最早的流转节点视为有效流转
|
||||
// TODO @Li:“parallelGateway” 和 "inclusiveGateway",有对应的枚举么?如果木有,可以自己枚举哈
|
||||
if ("parallelGateway".equals(currentActivityInstance.getActivityType()) || "inclusiveGateway".equals(currentActivityInstance.getActivityType())) {
|
||||
// 遍历历史活动节点,找到匹配流程目标节点的
|
||||
for (SequenceFlow sequenceFlow : sequenceFlows) {
|
||||
@ -266,6 +272,7 @@ public class TaskServiceImpl implements TaskService {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// TODO @Li:如果是为了获取到时间更早的一个,是不是遍历的过程中,就可以解决
|
||||
List<Map<String, Object>> tempMapList = new ArrayList<>();
|
||||
for (SequenceFlow sequenceFlow : sequenceFlows) {
|
||||
for (HistoricActivityInstance historicActivityInstance : historicActivityInstances) {
|
||||
@ -283,6 +290,7 @@ public class TaskServiceImpl implements TaskService {
|
||||
long earliestStamp = 0L;
|
||||
String highLightedFlowId = null;
|
||||
for (Map<String, Object> map : tempMapList) {
|
||||
// TODO @Li:可以使用 MapUtil 去 get 值
|
||||
long highLightedFlowStartTime = Long.valueOf(map.get("highLightedFlowStartTime").toString());
|
||||
if (earliestStamp == 0 || earliestStamp >= highLightedFlowStartTime) {
|
||||
highLightedFlowId = map.get("highLightedFlowId").toString();
|
||||
|
@ -56,6 +56,7 @@ public interface SysUserMapper extends BaseMapperX<SysUserDO> {
|
||||
return selectList(new QueryWrapperX<SysUserDO>().like("username", username));
|
||||
}
|
||||
|
||||
// TODO jason:变量平铺比较好
|
||||
default List<SysUserDO> selectListByBaseVO(SysUserBaseVO reqVO) {
|
||||
return selectList(new QueryWrapperX<SysUserDO>().likeIfPresent("username", reqVO.getUsername())
|
||||
.likeIfPresent("nickname", reqVO.getNickname())
|
||||
|
@ -19,6 +19,7 @@
|
||||
<properties>
|
||||
<activiti.version>7.1.0.M6</activiti.version>
|
||||
</properties>
|
||||
<!-- TODO @jason:后续弄到 yudao-dependencies 里 -->
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
@ -1,5 +1,6 @@
|
||||
package cn.iocoder.yudao.framework.activiti.config;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.activiti.api.runtime.shared.identity.UserGroupManager;
|
||||
import org.activiti.image.ProcessDiagramGenerator;
|
||||
import org.activiti.image.impl.DefaultProcessDiagramGenerator;
|
||||
@ -14,24 +15,27 @@ import org.springframework.stereotype.Component;
|
||||
public class YudaoActivitiConfiguration {
|
||||
|
||||
|
||||
|
||||
// TODO @Li:可以说明下 ProcessDiagramGenerator 作用
|
||||
@Bean
|
||||
public ProcessDiagramGenerator processDiagramGenerator (){
|
||||
return new DefaultProcessDiagramGenerator();
|
||||
}
|
||||
|
||||
/**
|
||||
* ProcessEngineConfigurationConfigurer 实现类,设置使用 MyBatis SqlSessionFactory
|
||||
*/
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public static class SqlSessionFactoryProcessEngineConfigurationConfigurer
|
||||
implements ProcessEngineConfigurationConfigurer {
|
||||
|
||||
private final SqlSessionFactory sqlSessionFactory;
|
||||
public SqlSessionFactoryProcessEngineConfigurationConfigurer(SqlSessionFactory sessionFactory) {
|
||||
this.sqlSessionFactory = sessionFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configure(SpringProcessEngineConfiguration springProcessEngineConfiguration) {
|
||||
springProcessEngineConfiguration.setSqlSessionFactory(sqlSessionFactory);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user