mirror of
https://github.com/hs-web/hsweb-framework.git
synced 2026-06-01 10:21:26 +08:00
工作流完善
This commit is contained in:
@@ -28,4 +28,6 @@ import java.util.List;
|
||||
*/
|
||||
public interface PersonDao extends CrudDao<PersonEntity, String> {
|
||||
List<PersonEntity> selectByPositionId(String positionId);
|
||||
|
||||
List<PersonEntity> selectByRoleId(String positionId);
|
||||
}
|
||||
|
||||
@@ -60,6 +60,10 @@
|
||||
select * from s_person where u_id in (select person_id from s_person_position where position_id=#{positionId})
|
||||
</select>
|
||||
|
||||
<select id="selectByRoleId" parameterType="String" resultMap="PersonResultMap">
|
||||
select * from s_person where u_id in (select user_id from s_user_role where role_id=#{roleId})
|
||||
</select>
|
||||
|
||||
<select id="query" parameterType="org.hswebframework.web.commons.entity.Entity" resultMap="PersonResultMap">
|
||||
<include refid="config"/>
|
||||
<include refid="BasicMapper.buildSelectSql"/>
|
||||
|
||||
@@ -37,4 +37,5 @@ public interface PersonService extends CrudService<PersonEntity, String> {
|
||||
|
||||
List<PersonEntity> selectByPositionId(String positionId);
|
||||
|
||||
List<PersonEntity> selectByRoleId(String roleId);
|
||||
}
|
||||
|
||||
@@ -173,6 +173,12 @@ public class SimplePersonService extends GenericEntityService<PersonEntity, Stri
|
||||
return personDao.selectByPositionId(positionId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PersonEntity> selectByRoleId(String roleId) {
|
||||
Objects.requireNonNull(roleId);
|
||||
return personDao.selectByRoleId(roleId);
|
||||
}
|
||||
|
||||
protected void syncPositionInfo(String personId, Set<String> positionIds) {
|
||||
for (String positionId : positionIds) {
|
||||
PersonPositionEntity positionEntity = entityFactory.newInstance(PersonPositionEntity.class);
|
||||
|
||||
@@ -19,7 +19,7 @@ public interface ActDefEntity extends GenericEntity<String> {
|
||||
*/
|
||||
String formId = "formId";
|
||||
/**
|
||||
* 矩阵ID
|
||||
* 关系ID
|
||||
*/
|
||||
String defId = "defId";
|
||||
|
||||
|
||||
@@ -3,10 +3,12 @@ package org.hswebframework.web.workflow.flowable.controller;
|
||||
import org.activiti.engine.impl.pvm.process.ActivityImpl;
|
||||
import org.activiti.engine.repository.ProcessDefinition;
|
||||
import org.activiti.engine.task.Task;
|
||||
import org.hswebframework.web.NotFoundException;
|
||||
import org.hswebframework.web.commons.entity.PagerResult;
|
||||
import org.hswebframework.web.commons.entity.param.UpdateParamEntity;
|
||||
import org.hswebframework.web.controller.message.ResponseMessage;
|
||||
import org.hswebframework.web.entity.workflow.ActDefEntity;
|
||||
import org.hswebframework.web.organizational.authorization.PersonnelAuthorization;
|
||||
import org.hswebframework.web.service.form.DynamicFormOperationService;
|
||||
import org.hswebframework.web.service.workflow.ActDefService;
|
||||
import org.hswebframework.web.workflow.flowable.service.BpmActivityService;
|
||||
@@ -77,9 +79,12 @@ public class FlowableCoreController {
|
||||
*/
|
||||
@PostMapping("start/{formId}-{defId}")
|
||||
public ResponseMessage<Map<String, Object>> startProc(@PathVariable String formId,@PathVariable String defId, @RequestBody Map<String, Object> data) {
|
||||
PersonnelAuthorization authorization = PersonnelAuthorization
|
||||
.current()
|
||||
.orElseThrow(NotFoundException::new);
|
||||
dynamicFormOperationService.insert(formId, data);
|
||||
ProcessDefinition processDefinition = bpmProcessService.getProcessDefinitionById(defId);
|
||||
bpmProcessService.startProcessInstance("4291d7da9005377ec9aec4a71ea837f",processDefinition.getKey(),null,null,formId,null);
|
||||
bpmProcessService.startProcessInstance(authorization.getPersonnel().getId(),processDefinition.getKey(),null,null,formId,null);
|
||||
return ResponseMessage.ok(data);
|
||||
}
|
||||
|
||||
@@ -89,18 +94,31 @@ public class FlowableCoreController {
|
||||
*/
|
||||
@GetMapping("tasks")
|
||||
public ResponseMessage<List<Task>> getMyTasks() {
|
||||
String userId = "e5141bc62f1837c41a4ac40c0e253595";
|
||||
PersonnelAuthorization authorization = PersonnelAuthorization
|
||||
.current()
|
||||
.orElseThrow(NotFoundException::new);
|
||||
String userId = authorization.getPersonnel().getId();
|
||||
List<Task> tasks = bpmTaskService.claimList(userId);
|
||||
return ResponseMessage.ok(tasks).include(Task.class, "id", "name", "createTime", "executionId"
|
||||
, "parentTaskId", "processInstanceId", "processDefinitionId", "taskDefinitionKey")
|
||||
.exclude(Task.class, "definition", "mainFormData");
|
||||
}
|
||||
|
||||
/**
|
||||
* 办理
|
||||
* @param formId
|
||||
* @param taskId
|
||||
* @param paramEntity
|
||||
* @return
|
||||
*/
|
||||
@PutMapping("complete/{formId}-{taskId}")
|
||||
public ResponseMessage<Map<String,Object>> complete(@PathVariable String formId,@PathVariable String taskId, @RequestBody UpdateParamEntity<Map<String, Object>> paramEntity){
|
||||
PersonnelAuthorization authorization = PersonnelAuthorization
|
||||
.current()
|
||||
.orElseThrow(NotFoundException::new);
|
||||
String userId = authorization.getPersonnel().getId();
|
||||
dynamicFormOperationService.update(formId,paramEntity);
|
||||
// 认领
|
||||
String userId = "e5141bc62f1837c41a4ac40c0e253595";
|
||||
bpmTaskService.claim(taskId,userId);
|
||||
// 办理
|
||||
bpmTaskService.complete(taskId, userId, null, null);
|
||||
|
||||
@@ -170,6 +170,12 @@ public interface BpmTaskService{
|
||||
* 获取流程变量
|
||||
* @param procInstId 流程实例ID
|
||||
*/
|
||||
Map<String,Object> getVariables(String procInstId);
|
||||
Map<String,Object> getVariablesByProcInstId(String procInstId);
|
||||
|
||||
/**
|
||||
* 获取流程变量
|
||||
* @param taskId
|
||||
* @return
|
||||
*/
|
||||
Map<String,Object> getVariablesByTaskId(String taskId);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.hswebframework.web.workflow.flowable.service;
|
||||
|
||||
import org.hswebframework.web.entity.workflow.ActDefEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author wangwei
|
||||
* @Date 2017/9/13.
|
||||
*/
|
||||
public interface BpmUtilsService {
|
||||
|
||||
/**
|
||||
* 根据配置获取用户
|
||||
* @param userId
|
||||
* @param actDefEntity
|
||||
* @return
|
||||
*/
|
||||
List<String> selectUserIdsBy(String userId, ActDefEntity actDefEntity);
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import org.activiti.engine.history.HistoricProcessInstance;
|
||||
import org.activiti.engine.history.HistoricTaskInstance;
|
||||
import org.activiti.engine.impl.RepositoryServiceImpl;
|
||||
import org.activiti.engine.impl.TaskServiceImpl;
|
||||
import org.activiti.engine.impl.persistence.entity.IdentityLinkEntity;
|
||||
import org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity;
|
||||
import org.activiti.engine.impl.pvm.PvmActivity;
|
||||
import org.activiti.engine.impl.pvm.PvmTransition;
|
||||
@@ -13,15 +14,20 @@ import org.activiti.engine.impl.pvm.process.TransitionImpl;
|
||||
import org.activiti.engine.runtime.Execution;
|
||||
import org.activiti.engine.runtime.ProcessInstance;
|
||||
import org.activiti.engine.task.Task;
|
||||
import org.hswebframework.utils.ClassUtils;
|
||||
import org.hswebframework.utils.StringUtils;
|
||||
import org.hswebframework.web.NotFoundException;
|
||||
import org.hswebframework.web.entity.organizational.PersonEntity;
|
||||
import org.hswebframework.web.entity.workflow.ActDefEntity;
|
||||
import org.hswebframework.web.organizational.authorization.Personnel;
|
||||
import org.hswebframework.web.organizational.authorization.relation.Relation;
|
||||
import org.hswebframework.web.service.organizational.PersonService;
|
||||
import org.hswebframework.web.service.organizational.RelationDefineService;
|
||||
import org.hswebframework.web.service.organizational.RelationInfoService;
|
||||
import org.hswebframework.web.service.workflow.ActDefService;
|
||||
import org.hswebframework.web.workflow.flowable.service.BpmActivityService;
|
||||
import org.hswebframework.web.workflow.flowable.service.BpmTaskService;
|
||||
import org.hswebframework.web.workflow.flowable.service.BpmUtilsService;
|
||||
import org.hswebframework.web.workflow.flowable.utils.FlowableAbstract;
|
||||
import org.hswebframework.web.workflow.flowable.utils.JumpTaskCmd;
|
||||
import org.slf4j.Logger;
|
||||
@@ -32,6 +38,8 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collector;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.hswebframework.web.commons.entity.param.QueryParamEntity.single;
|
||||
|
||||
@@ -50,9 +58,7 @@ public class BpmTaskServiceImp extends FlowableAbstract implements BpmTaskServic
|
||||
@Autowired
|
||||
ActDefService actDefService;
|
||||
@Autowired
|
||||
RelationDefineService relationDefineService;
|
||||
@Autowired
|
||||
RelationInfoService relationInfoService;
|
||||
BpmUtilsService bpmUtilsService;
|
||||
|
||||
@Override
|
||||
public List<Task> selectNowTask(String procInstId) {
|
||||
@@ -167,9 +173,9 @@ public class BpmTaskServiceImp extends FlowableAbstract implements BpmTaskServic
|
||||
if (execution.size() > 0) {
|
||||
List<Task> tasks = selectNowTask(task.getProcessInstanceId());
|
||||
// 自定义下一执行人
|
||||
if (tasks.size()==0 && !StringUtils.isNullOrEmpty(nextClaim)) claim(tasks.get(0).getId(), nextClaim);
|
||||
if (tasks.size() == 0 && !StringUtils.isNullOrEmpty(nextClaim)) claim(tasks.get(0).getId(), nextClaim);
|
||||
else {
|
||||
for(Task t:tasks){
|
||||
for (Task t : tasks) {
|
||||
addCandidateUser(t.getId(), t.getTaskDefinitionKey(), userId);
|
||||
}
|
||||
}
|
||||
@@ -259,20 +265,24 @@ public class BpmTaskServiceImp extends FlowableAbstract implements BpmTaskServic
|
||||
|
||||
@Override
|
||||
public void addCandidateUser(String taskId, String actId, String userId) {
|
||||
if(!StringUtils.isNullOrEmpty(actId)){
|
||||
if (!StringUtils.isNullOrEmpty(actId)) {
|
||||
// 获取节点配置信息
|
||||
ActDefEntity actDefEntity = actDefService.selectSingle(single(ActDefEntity.actId,actId));
|
||||
// 获取矩阵信息
|
||||
// RelationDefineEntity relationDefineEntity = relationDefineService.selectByPk(actDefEntity.getDefId());
|
||||
// 获取人员信息
|
||||
List<Relation> relations = relationInfoService
|
||||
.getRelations(actDefEntity.getType(),userId)
|
||||
.findPos(actDefEntity.getDefId());
|
||||
// 设置待办人
|
||||
for(Relation relation : relations){
|
||||
taskService.addCandidateUser(taskId,relation.getTarget());
|
||||
ActDefEntity actDefEntity = actDefService.selectSingle(single(ActDefEntity.actId, actId));
|
||||
// 根据配置类型 获取人员信息 设置待办人
|
||||
if (actDefEntity!=null) {
|
||||
List<String> list = bpmUtilsService.selectUserIdsBy(userId,actDefEntity);
|
||||
for (String uId: list) {
|
||||
taskService.addCandidateUser(taskId, uId);
|
||||
}
|
||||
} else {
|
||||
taskService.addCandidateUser(taskId,
|
||||
runtimeService.getIdentityLinksForProcessInstance(selectTaskByTaskId(taskId).getProcessInstanceId())
|
||||
.stream()
|
||||
.filter(linkEntity -> linkEntity.getType().equals("starter"))
|
||||
.findFirst().orElseThrow(()-> new NotFoundException("发起人获取失败")).getUserId()
|
||||
);
|
||||
}
|
||||
}else {
|
||||
} else {
|
||||
taskService.addCandidateUser(taskId, userId);
|
||||
}
|
||||
}
|
||||
@@ -365,7 +375,7 @@ public class BpmTaskServiceImp extends FlowableAbstract implements BpmTaskServic
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getVariables(String procInstId) {
|
||||
public Map<String, Object> getVariablesByProcInstId(String procInstId) {
|
||||
List<Execution> executions = runtimeService.createExecutionQuery().processInstanceId(procInstId).list();
|
||||
String executionId = "";
|
||||
for (Execution execution : executions) {
|
||||
@@ -375,4 +385,9 @@ public class BpmTaskServiceImp extends FlowableAbstract implements BpmTaskServic
|
||||
}
|
||||
return runtimeService.getVariables(executionId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getVariablesByTaskId(String taskId) {
|
||||
return taskService.getVariables(taskId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
package org.hswebframework.web.workflow.flowable.service.imp;
|
||||
|
||||
import org.hswebframework.web.entity.organizational.PersonEntity;
|
||||
import org.hswebframework.web.entity.workflow.ActDefEntity;
|
||||
import org.hswebframework.web.organizational.authorization.relation.Relation;
|
||||
import org.hswebframework.web.service.organizational.PersonService;
|
||||
import org.hswebframework.web.service.organizational.RelationDefineService;
|
||||
import org.hswebframework.web.service.organizational.RelationInfoService;
|
||||
import org.hswebframework.web.service.workflow.ActDefService;
|
||||
import org.hswebframework.web.workflow.flowable.service.BpmActivityService;
|
||||
import org.hswebframework.web.workflow.flowable.service.BpmUtilsService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author wangwei
|
||||
* @Date 2017/9/13.
|
||||
*/
|
||||
@Service
|
||||
@Transactional(rollbackFor = Throwable.class)
|
||||
public class BpmUtilsServiceImp implements BpmUtilsService {
|
||||
|
||||
protected Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
@Autowired
|
||||
PersonService personService;
|
||||
@Autowired
|
||||
RelationInfoService relationInfoService;
|
||||
|
||||
@Override
|
||||
public List<String> selectUserIdsBy(String userId, ActDefEntity actDefEntity) {
|
||||
List<String> list = new ArrayList<>();
|
||||
// 根据配置类型 获取人员信息 设置待办人
|
||||
if (actDefEntity.getType().equals("person")) { // 矩阵
|
||||
List<Relation> relations = relationInfoService.getRelations(actDefEntity.getType(), userId).findPos(actDefEntity.getDefId());
|
||||
for (Relation relation : relations) {
|
||||
list.add(relation.getTarget());
|
||||
}
|
||||
} else if (actDefEntity.getType().equals("position")) { // 岗位
|
||||
List<PersonEntity> personEntities = personService.selectByPositionId(actDefEntity.getDefId());
|
||||
for(PersonEntity personEntity:personEntities){
|
||||
list.add(personEntity.getUserId());
|
||||
}
|
||||
} else if (actDefEntity.getType().equals("role")) { // 角色
|
||||
List<PersonEntity> personEntities = personService.selectByRoleId(actDefEntity.getDefId());
|
||||
for(PersonEntity personEntity:personEntities){
|
||||
list.add(personEntity.getUserId());
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user