工作流完善

This commit is contained in:
wangwei
2017-09-06 10:30:46 +08:00
parent 8827509632
commit 1732bfaa8a
17 changed files with 354 additions and 62 deletions

View File

@@ -0,0 +1,11 @@
package org.hswebframework.web.dao.workflow;
import org.hswebframework.web.dao.CrudDao;
import org.hswebframework.web.entity.workflow.ActDefEntity;
/**
* @Author wangwei
* @Date 2017/9/5.
*/
public interface ProcDefFormDao extends CrudDao<ActDefEntity,String> {
}

View File

@@ -4,9 +4,10 @@
"http://www.mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.hswebframework.web.dao.workflow.ActDefDao">
<resultMap id="ActDefResultMap" type="org.hswebframework.web.entity.workflow.SimpleActDefEntity">
<id property="id" column="u_id" javaType="string" jdbcType="VARCHAR"/>
<result property="actId" column="act_id" javaType="String" jdbcType="VARCHAR"/>
<result property="defId" column="def_id" javaType="String" jdbcType="VARCHAR"/>
<id property="id" column="u_id" javaType="string" jdbcType="VARCHAR"/>
<result property="actId" column="act_id" javaType="String" jdbcType="VARCHAR"/>
<result property="formId" column="form_id" javaType="String" jdbcType="VARCHAR"/>
<result property="defId" column="def_id" javaType="String" jdbcType="VARCHAR"/>
</resultMap>
<!--用于动态生成sql所需的配置-->
@@ -14,8 +15,8 @@
<bind name="resultMapId" value="'ActDefResultMap'"/>
<bind name="tableName" value="'s_act_def'"/>
</sql>
<insert id="insert" parameterType="org.hswebframework.web.entity.workflow.SimpleActDefEntity" >
<insert id="insert" parameterType="org.hswebframework.web.entity.workflow.SimpleActDefEntity">
<include refid="config"/>
<include refid="BasicMapper.buildInsertSql"/>
</insert>

View File

@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://www.mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.hswebframework.web.dao.workflow.ProcDefFormDao">
<resultMap id="ProcDefFormResultMap" type="org.hswebframework.web.entity.workflow.SimpleProcDefFormEntity">
<id property="id" column="u_id" javaType="string" jdbcType="VARCHAR"/>
<result property="defKey" column="def_key" javaType="String" jdbcType="VARCHAR"/>
<result property="formId" column="form_id" javaType="String" jdbcType="VARCHAR"/>
</resultMap>
<!--用于动态生成sql所需的配置-->
<sql id="config">
<bind name="resultMapId" value="'ProcDefFormResultMap'"/>
<bind name="tableName" value="'s_def_form'"/>
</sql>
<insert id="insert" parameterType="org.hswebframework.web.entity.workflow.SimpleProcDefFormEntity" >
<include refid="config"/>
<include refid="BasicMapper.buildInsertSql"/>
</insert>
<delete id="deleteByPk" parameterType="String">
delete from s_def_form where u_id =#{id}
</delete>
<delete id="delete" parameterType="org.hswebframework.web.commons.entity.Entity">
<include refid="config"/>
<include refid="BasicMapper.buildDeleteSql"/>
</delete>
<update id="update" parameterType="org.hswebframework.web.commons.entity.Entity">
<include refid="config"/>
<include refid="BasicMapper.buildUpdateSql"/>
</update>
<select id="query" parameterType="org.hswebframework.web.commons.entity.Entity" resultMap="ProcDefFormResultMap">
<include refid="config"/>
<include refid="BasicMapper.buildSelectSql"/>
</select>
<select id="count" parameterType="org.hswebframework.web.commons.entity.Entity" resultType="int">
<include refid="config"/>
<include refid="BasicMapper.buildTotalSql"/>
</select>
</mapper>

View File

@@ -14,6 +14,10 @@ public interface ActDefEntity extends GenericEntity<String> {
* 节点ID
*/
String actId = "actId";
/**
* 表单ID
*/
String formId = "formId";
/**
* 矩阵ID
*/
@@ -23,6 +27,10 @@ public interface ActDefEntity extends GenericEntity<String> {
void setActId(String actId);
String getFormId();
void setFormId(String formId);
String getDefId();
void setDefId(String defId);

View File

@@ -0,0 +1,29 @@
package org.hswebframework.web.entity.workflow;
import org.hswebframework.web.commons.entity.GenericEntity;
/**
* @Author wangwei
* @Date 2017/9/5.
*/
public interface ProcDefFormEntity extends GenericEntity<String>{
/*-------------------------------------------
| 属性名常量 |
===========================================*/
/**
* 流程定义Key
*/
String defKey = "defKey";
/**
* 动态表单ID
*/
String formId = "formId";
String getDefKey();
void setDefKey(String defKey);
String getFormId();
void setFormId(String formId);
}

View File

@@ -9,6 +9,7 @@ import org.hswebframework.web.commons.entity.SimpleGenericEntity;
public class SimpleActDefEntity extends SimpleGenericEntity<String> implements ActDefEntity {
private String actId;
private String formId;
private String defId;
@Override
@@ -21,6 +22,16 @@ public class SimpleActDefEntity extends SimpleGenericEntity<String> implements A
this.actId = actId;
}
@Override
public String getFormId() {
return formId;
}
@Override
public void setFormId(String formId) {
this.formId = formId;
}
@Override
public String getDefId() {
return defId;

View File

@@ -0,0 +1,33 @@
package org.hswebframework.web.entity.workflow;
import org.hswebframework.web.commons.entity.SimpleGenericEntity;
/**
* @Author wangwei
* @Date 2017/9/5.
*/
public class SimpleProcDefFormEntity extends SimpleGenericEntity<String> implements ProcDefFormEntity {
String defKey;
String formId;
@Override
public String getDefKey() {
return defKey;
}
@Override
public void setDefKey(String defKey) {
this.defKey = defKey;
}
@Override
public String getFormId() {
return formId;
}
@Override
public void setFormId(String formId) {
this.formId = formId;
}
}

View File

@@ -100,11 +100,6 @@
<artifactId>hsweb-datasource-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.hswebframework.web</groupId>
<artifactId>hsweb-system-dynamic-form-service-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.hswebframework.web</groupId>
@@ -210,6 +205,11 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hswebframework.web</groupId>
<artifactId>hsweb-system-dynamic-form-service-simple</artifactId>
<version>${project.version}</version>
</dependency>
<!-- test -->

View File

@@ -0,0 +1,82 @@
package org.hswebframework.web.workflow.flowable.controller;
import org.activiti.engine.impl.pvm.process.ActivityImpl;
import org.activiti.engine.repository.ProcessDefinition;
import org.hswebframework.web.commons.entity.PagerResult;
import org.hswebframework.web.controller.message.ResponseMessage;
import org.hswebframework.web.entity.workflow.ActDefEntity;
import org.hswebframework.web.service.form.DynamicFormOperationService;
import org.hswebframework.web.service.workflow.ActDefService;
import org.hswebframework.web.workflow.flowable.service.BpmActivityService;
import org.hswebframework.web.workflow.flowable.service.BpmProcessService;
import org.hswebframework.web.workflow.flowable.service.BpmTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.hswebframework.web.commons.entity.param.QueryParamEntity.single;
/**
* @Author wangwei
* @Date 2017/9/5.
*/
@RestController
@RequestMapping("/workflow/proc-def/")
public class FlowableCoreController {
@Autowired
BpmTaskService bpmTaskService;
@Autowired
BpmProcessService bpmProcessService;
@Autowired
BpmActivityService bpmActivityService;
@Autowired
ActDefService actDefService;
@Autowired
DynamicFormOperationService dynamicFormOperationService;
/**
* 获取所有可用流程(流程配置与流程启动都可用该方法获取)
* @return
*/
@GetMapping("index")
public ResponseMessage<Map<String, Object>> index(){
List<ProcessDefinition> list = bpmProcessService.getAllProcessDefinition();
Map<String, Object> map = new HashMap<>();
for(ProcessDefinition processDefinition : list){
map.put(processDefinition.getName(),processDefinition.getId());
}
return ResponseMessage.ok(map);
}
/**
* 进入流程表单
* @param procDefId
* @return
*/
@GetMapping("open-form/{id}")
public ResponseMessage<Map<String,PagerResult<Object>>> openForm(@PathVariable("id") String procDefId){
Map<String,PagerResult<Object>> map = new HashMap<>();
ActivityImpl activity = bpmActivityService.getStartEvent(procDefId);
ActDefEntity actDefEntity = actDefService.selectSingle(single(ActDefEntity.actId,activity.getId()));
map.put(activity.getProcessDefinition().getKey(),
dynamicFormOperationService.selectPager(actDefEntity.getFormId(), null));
return ResponseMessage.ok(map);
}
/**
* 保存表单,启动流程
* @param formId
* @param defKey
* @param data
* @return
*/
@PostMapping("start/{formId}-{defKey}")
public ResponseMessage<Map<String, Object>> startProc(@PathVariable String formId,@PathVariable String defKey, @RequestBody Map<String, Object> data) {
dynamicFormOperationService.insert(formId, data);
bpmProcessService.startProcessInstance("admin",defKey,null,null,formId,null);
return ResponseMessage.ok(data);
}
}

View File

@@ -1,6 +1,9 @@
package org.hswebframework.web.workflow.flowable.controller;
import com.alibaba.fastjson.JSON;
import org.activiti.engine.impl.pvm.process.ActivityImpl;
import org.hswebframework.utils.ClassUtils;
import org.hswebframework.utils.StringUtils;
import org.hswebframework.web.controller.message.ResponseMessage;
import org.hswebframework.web.entity.workflow.ActDefEntity;
import org.hswebframework.web.service.workflow.ActDefService;
@@ -8,10 +11,13 @@ import org.hswebframework.web.workflow.flowable.service.BpmActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.hswebframework.web.commons.entity.param.QueryParamEntity.single;
/**
* @Author wangwei
* @Date 2017/9/4.
@@ -26,23 +32,52 @@ public class FlowableUtilsController {
@Autowired
ActDefService actDefService;
/**
* 获取流程所有配置节点
* @param procDefId
* @return
*/
@GetMapping("{procDefId}/acts")
public ResponseMessage<Map<String, Object>> acts(@PathVariable String procDefId) {
Map<String, Object> map = new HashMap<>();
public ResponseMessage<List<Map<String, Object>>> acts(@PathVariable String procDefId) {
List<Map<String, Object>> list = new ArrayList<>();
List<ActivityImpl> activities = bpmActivityService.getActivitiesById(procDefId, null);
for (ActivityImpl activity : activities) {
if (activity.getProperty("type").equals("userTask")) map.put(activity.getId(), activity.getProperty("name"));
Map<String,Object> map = new HashMap<>();
if(activity.getProperty("type").equals("startEvent")){
map.put("id", activity.getId());
map.put("name", "流程发起者");
map.put("info", actDefService.selectSingle(single(ActDefEntity.actId, activity.getId())));
}else if (activity.getProperty("type").equals("userTask")){
map.put("id", activity.getId());
map.put("name", activity.getProperty("name").toString());
map.put("info", actDefService.selectSingle(single(ActDefEntity.actId, activity.getId())));
}
if(map.size()>0) list.add(map);
}
return ResponseMessage.ok(map);
return ResponseMessage.ok(list);
}
@PostMapping("act/{actId}-{defId}")
public ResponseMessage<Map<String, Object>> setActClaimDef(@PathVariable String actId, @PathVariable String defId){
Map<String, Object> map = new HashMap<>();
ActDefEntity actDefEntity = actDefService.createEntity();
actDefEntity.setActId(actId);
actDefEntity.setDefId(defId);
actDefService.insert(actDefEntity);
return ResponseMessage.ok(map);
/**
* 给流程节点配置表单与人员矩阵
* @param entity
* @return
*/
@PostMapping("act/{entity}")
public ResponseMessage<String> setActClaimDef(@PathVariable String entity){
try{
List<Map> list = JSON.parseArray(entity,Map.class);
for(Map map : list){
ActDefEntity actDefEntity = actDefService.selectSingle(single(ActDefEntity.actId,map.get("act_id").toString()));
if(actDefEntity==null) actDefEntity = actDefService.createEntity();
actDefEntity.setActId(map.get("act_id").toString());
actDefEntity.setFormId(map.get("form_id").toString());
actDefEntity.setDefId(map.get("def_id").toString());
actDefService.saveOrUpdate(actDefEntity);
}
return ResponseMessage.ok("保存成功");
}catch (Exception e){
return ResponseMessage.ok("保存失败");
}
}
}

View File

@@ -85,10 +85,10 @@ public interface BpmActivityService {
/**
* 获取开始节点
*
* @param procDefKey 流程定义Key
* @param procDefId 流程定义ID
* @return ActivityImpl 当前流程的结束资源
*/
ActivityImpl getStartEvent(String procDefKey);
ActivityImpl getStartEvent(String procDefId);
/**
* 获取结束节点

View File

@@ -15,6 +15,12 @@ import java.util.Map;
*/
public interface BpmProcessService{
/**
* 获取所有可以启动的流程
* @return
*/
List<ProcessDefinition> getAllProcessDefinition();
/**
* 启动一个流程,并初始化自定义主表单数据
*

View File

@@ -108,9 +108,10 @@ public interface BpmTaskService{
* 设置办理人
*
* @param taskId 当前环节ID
* @param actId 当前环节图元ID
* @param userId 用户ID
*/
void setAssignee(String taskId, String userId);
void setAssignee(String taskId, String actId, String userId);
/**
* 结束流程

View File

@@ -225,12 +225,6 @@ public class BpmActivityServiceImp extends FlowableAbstract implements BpmActivi
@Override
public ActivityImpl getEndEvent(String procDefId) {
return findActivity(procDefId, activity -> "endEvent".equals(activity.getProperty("type")));
// for (ActivityImpl activity : pde.getActivities()) {
// if (activity.getProperty("type").equals("endEvent"))
// return activity;
// }
// return null;
}
/**

View File

@@ -30,6 +30,11 @@ public class BpmProcessServiceImp extends FlowableAbstract implements BpmProcess
@Resource
private BpmTaskService bpmTaskService;
@Override
public List<ProcessDefinition> getAllProcessDefinition() {
return repositoryService.createProcessDefinitionQuery().latestVersion().active().list();
}
@Override
public ProcessInstance startProcessInstance(String creatorId,
String procDefKey,

View File

@@ -15,6 +15,12 @@ import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.hswebframework.utils.StringUtils;
import org.hswebframework.web.NotFoundException;
import org.hswebframework.web.entity.organizational.RelationDefineEntity;
import org.hswebframework.web.entity.workflow.ActDefEntity;
import org.hswebframework.web.organizational.authorization.relation.Relations;
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.entity.TaskInfo;
import org.hswebframework.web.workflow.flowable.service.BpmActivityService;
import org.hswebframework.web.workflow.flowable.service.BpmTaskService;
@@ -22,12 +28,15 @@ import org.hswebframework.web.workflow.flowable.utils.FlowableAbstract;
import org.hswebframework.web.workflow.flowable.utils.JumpTaskCmd;
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 javax.annotation.Resource;
import java.util.*;
import static org.hswebframework.web.commons.entity.param.QueryParamEntity.single;
/**
* @Author wangwei
* @Date 2017/8/7.
@@ -40,6 +49,12 @@ public class BpmTaskServiceImp extends FlowableAbstract implements BpmTaskServic
@Resource
private BpmActivityService bpmActivityService;
@Autowired
ActDefService actDefService;
@Autowired
RelationDefineService relationDefineService;
@Autowired
RelationInfoService relationInfoService;
@Override
public List<Task> selectNowTask(String procInstId) {
@@ -244,8 +259,19 @@ public class BpmTaskServiceImp extends FlowableAbstract implements BpmTaskServic
}
@Override
public void setAssignee(String taskId, String userId) {
taskService.setAssignee(taskId, userId);
public void setAssignee(String taskId, String actId, String userId) {
if(!StringUtils.isNullOrEmpty(actId)){
// 获取节点配置信息
ActDefEntity actDefEntity = actDefService.selectSingle(single(ActDefEntity.actId,actId));
// 获取矩阵信息
RelationDefineEntity relationDefineEntity = relationDefineService.selectByPk(actDefEntity.getDefId());
// 获取人员信息
Relations relations = relationInfoService.getRelations(relationDefineEntity.getName(),userId);
// 设置待办人
taskService.setAssignee(taskId, userId);
}else {
taskService.setAssignee(taskId, userId);
}
}
@Override

View File

@@ -1,41 +1,45 @@
package org.hswebframework.web.workflow.flowable.test;
import org.activiti.engine.history.HistoricTaskInstance;
import org.activiti.engine.impl.pvm.process.ActivityImpl;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.task.Task;
import org.hswebframework.web.workflow.flowable.service.BpmActivityService;
import org.hswebframework.web.workflow.flowable.utils.FlowableAbstract;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import com.alibaba.fastjson.JSON;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Created by zhouhao on 2017/7/20.
*/
@RunWith(SpringRunner.class)
@SpringBootTest
public class ServiceTest extends FlowableAbstract {
@Autowired
BpmActivityService bpmActivityService;
@Test
public void getProcessDefinition(){
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionKey("test").singleResult();
System.out.println(processDefinition);
public class ServiceTest {
public static void main(String[] args) {
p();
}
@Test
public void getHiTask(){
//查出历史信息
HistoricTaskInstance historicTaskInstance = historyService.createHistoricTaskInstanceQuery().processInstanceId("5").taskAssignee("admin").singleResult();
Task task = taskService.createTaskQuery().taskId("123456").singleResult();
public static void p(){
String s = "[{\"name\":\"a\",\"key\":\"1\"},{\"name\":\"b\",\"key\":\"2\"},{\"name\":\"c\",\"key\":\"3\"}]";
List<Map> list = JSON.parseArray(s,Map.class);
System.out.println(list);
}
public static void s(){
Map<String, String> map1 = new HashMap<>();
Map<String, String> map2 = new HashMap<>();
Map<String, String> map3 = new HashMap<>();
map1.put("key","1");
map1.put("name","a");
map2.put("key","2");
map2.put("name","b");
map3.put("key","3");
map3.put("name","c");
List<Map<String,String>> list = new ArrayList<>();
list.add(map1);
list.add(map2);
list.add(map3);
System.out.println(JSON.toJSONString(list));
}
}