|
@@ -8,14 +8,20 @@ import com.qmth.sop.business.bean.result.FlowFormWidgetResult;
|
|
|
import com.qmth.sop.business.bean.result.FlowResult;
|
|
|
import com.qmth.sop.business.bean.result.FlowTaskResult;
|
|
|
import com.qmth.sop.business.entity.TFCustomFlow;
|
|
|
-import com.qmth.sop.business.service.ActivitiConsumerService;
|
|
|
-import com.qmth.sop.business.service.TFCustomFlowService;
|
|
|
+import com.qmth.sop.business.entity.TFCustomFlowEntity;
|
|
|
+import com.qmth.sop.business.entity.TFFlowApprove;
|
|
|
+import com.qmth.sop.business.entity.TFFlowLog;
|
|
|
+import com.qmth.sop.business.service.*;
|
|
|
import com.qmth.sop.common.enums.ExceptionResultEnum;
|
|
|
+import com.qmth.sop.common.enums.FlowApproveOperationEnum;
|
|
|
+import com.qmth.sop.common.enums.FlowApproveSetupEnum;
|
|
|
+import com.qmth.sop.common.enums.FlowStatusEnum;
|
|
|
import com.qmth.sop.common.util.GsonUtil;
|
|
|
import com.qmth.sop.common.util.JacksonUtil;
|
|
|
import io.swagger.annotations.*;
|
|
|
import org.activiti.engine.FormService;
|
|
|
import org.activiti.engine.RepositoryService;
|
|
|
+import org.activiti.engine.RuntimeService;
|
|
|
import org.activiti.engine.TaskService;
|
|
|
import org.activiti.engine.repository.DeploymentBuilder;
|
|
|
import org.activiti.engine.runtime.ProcessInstance;
|
|
@@ -23,6 +29,7 @@ import org.activiti.engine.task.Task;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.core.io.ClassPathResource;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
@@ -43,10 +50,10 @@ public class ActivitiFromHtmlController {
|
|
|
private final static Logger log = LoggerFactory.getLogger(ActivitiFromHtmlController.class);
|
|
|
|
|
|
@Resource
|
|
|
- private ActivitiConsumerService activitiConsumerService;
|
|
|
+ ActivitiConsumerService activitiConsumerService;
|
|
|
|
|
|
@Resource
|
|
|
- private RepositoryService repositoryService;
|
|
|
+ RepositoryService repositoryService;
|
|
|
|
|
|
@Resource
|
|
|
FormService formService;
|
|
@@ -57,6 +64,18 @@ public class ActivitiFromHtmlController {
|
|
|
@Resource
|
|
|
TFCustomFlowService tfCustomFlowService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ RuntimeService runtimeService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ TFCustomFlowEntityService tfCustomFlowEntityService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ TFFlowApproveService tfFlowApproveService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ TFFlowLogService tfFlowLogService;
|
|
|
+
|
|
|
/**
|
|
|
* 注册流程
|
|
|
*
|
|
@@ -64,6 +83,7 @@ public class ActivitiFromHtmlController {
|
|
|
*/
|
|
|
@ApiOperation(value = "创建流程接口")
|
|
|
@RequestMapping(value = "/createDeployment", method = RequestMethod.POST)
|
|
|
+ @Transactional
|
|
|
@ApiResponses({@ApiResponse(code = 200, message = "返回信息", response = Object.class)})
|
|
|
public Map<String, Object> createDeployment() throws IOException {
|
|
|
DeploymentBuilder builder = repositoryService.createDeployment();
|
|
@@ -82,41 +102,13 @@ public class ActivitiFromHtmlController {
|
|
|
|
|
|
@ApiOperation(value = "获取流程提交表单属性接口")
|
|
|
@RequestMapping(value = "/flow/start", method = RequestMethod.POST)
|
|
|
+ @Transactional
|
|
|
@ApiResponses({@ApiResponse(code = 200, message = "返回信息", response = Object.class)})
|
|
|
public Map<String, Object> flowStart(@ApiParam(value = "部署流程id", required = true) @RequestParam String deploymentId) {
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
String processDefinitionId = null;
|
|
|
-// ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(processDefinitionId).singleResult();
|
|
|
-// boolean hasStartFormKey = processDefinition.hasStartFormKey();
|
|
|
-// //获得流程模型
|
|
|
-// BpmnModel model = repositoryService.getBpmnModel(processDefinitionId);
|
|
|
-// //获得流程模型的所有节点
|
|
|
-// Collection<FlowElement> flowElements = model.getMainProcess().getFlowElements();
|
|
|
-// List<FormPropertyBean> formPropertyBeanList = new LinkedList<>();
|
|
|
-// for (FlowElement e : flowElements) {
|
|
|
-// // 判断节点类型
|
|
|
-// if (e instanceof UserTask) {
|
|
|
-// UserTask userTask = (UserTask) e;
|
|
|
-// if (Objects.nonNull(userTask.getFormKey())) {
|
|
|
-//// Object o = formService.getRenderedTaskForm(processDefinitionId, userTask.getId());
|
|
|
-//// log.info("task formProperties:{}", JacksonUtil.parseJson(o));
|
|
|
-// }
|
|
|
-// } else if (e instanceof StartEvent) {
|
|
|
-// StartEvent startEvent = (StartEvent) e;
|
|
|
-// if (Objects.nonNull(startEvent.getFormKey())) {
|
|
|
-// Object o = formService.getRenderedStartForm(processDefinitionId);
|
|
|
-// log.info("start formProperties:{}", JacksonUtil.parseJson(o));
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
TFCustomFlow tfCustomFlow = tfCustomFlowService.getOne(new QueryWrapper<TFCustomFlow>().lambda().eq(TFCustomFlow::getActFlowId, deploymentId));
|
|
|
Optional.ofNullable(tfCustomFlow.getFlowProcessVar()).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("流程没有部署数据!"));
|
|
|
-// Object o = formService.getRenderedStartForm(processDefinitionId);
|
|
|
-// if (Objects.nonNull(o)) {
|
|
|
-// log.info("start formProperties:{}", JacksonUtil.parseJson(o));
|
|
|
-// List<FlowFormWidgetResult> list = JSONArray.parseArray(o.toString(), FlowFormWidgetResult.class);
|
|
|
-// map.put("FormProperty", new FormPropertyBean(null, null, list));
|
|
|
-// }
|
|
|
if (Objects.isNull(tfCustomFlow.getFlowKey())) {
|
|
|
processDefinitionId = activitiConsumerService.findProcessDefinitionIdByDeploymentId(deploymentId);
|
|
|
tfCustomFlow.setFlowKey(processDefinitionId);
|
|
@@ -136,6 +128,7 @@ public class ActivitiFromHtmlController {
|
|
|
}
|
|
|
map.put("processDefinitionId", processDefinitionId);
|
|
|
map.put("deploymentId", deploymentId);
|
|
|
+ map.put("id", tfCustomFlow.getId());
|
|
|
return map;
|
|
|
}
|
|
|
|
|
@@ -172,8 +165,9 @@ public class ActivitiFromHtmlController {
|
|
|
|
|
|
@ApiOperation(value = "启动流程接口")
|
|
|
@RequestMapping(value = "/startActivityDemo", method = RequestMethod.POST)
|
|
|
+ @Transactional
|
|
|
@ApiResponses({@ApiResponse(code = 200, message = "返回信息", response = Object.class)})
|
|
|
- public Map<String, Object> startActivityDemo(@ApiParam(value = "流程定义id", required = true) @RequestParam String processDefinitionId,
|
|
|
+ public Map<String, Object> startActivityDemo(@ApiParam(value = "流程定义id", required = true) @RequestParam Long id,
|
|
|
@ApiParam(value = "审批人id", required = true) @RequestParam String approveId,
|
|
|
@ApiParam(value = "上传文件") @RequestParam(required = false) MultipartFile file,
|
|
|
HttpServletRequest request) {
|
|
@@ -188,24 +182,45 @@ public class ActivitiFromHtmlController {
|
|
|
}
|
|
|
varMap.putAll(formDataMap);
|
|
|
|
|
|
- ProcessInstance processInstance = formService.submitStartFormData(processDefinitionId, formDataMap);
|
|
|
+ TFCustomFlow tfCustomFlow = tfCustomFlowService.getById(id);
|
|
|
+ Optional.ofNullable(tfCustomFlow.getFlowProcessVar()).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("流程没有部署数据!"));
|
|
|
+ ProcessInstance processInstance = runtimeService.startProcessInstanceById(tfCustomFlow.getFlowKey(), varMap);
|
|
|
+// ProcessInstance processInstance = formService.submitStartFormData(tfCustomFlow.getFlowKey(), varMap);
|
|
|
if (Objects.nonNull(processInstance)) {
|
|
|
+ TFCustomFlowEntity tfCustomFlowEntity = new TFCustomFlowEntity(tfCustomFlow.getId(), null);
|
|
|
+ TFFlowApprove tfFlowApprove = new TFFlowApprove(null, Long.parseLong(approveId), FlowStatusEnum.START, null);
|
|
|
+ TFFlowLog tfFlowLog = new TFFlowLog(null, tfFlowApprove.getApproveId(), null, FlowApproveOperationEnum.START, FlowApproveSetupEnum.START.getSetup(), FlowApproveSetupEnum.START.getTitle());
|
|
|
List<Task> taskList = taskService.createTaskQuery().processInstanceId(processInstance.getId()).list();
|
|
|
if (!CollectionUtils.isEmpty(taskList)) {
|
|
|
+ FlowResult flowResult = JSONObject.parseObject(tfCustomFlow.getFlowProcessVar(), FlowResult.class);
|
|
|
+ Map<String, FlowTaskResult> setupMap = flowResult.getSetupMap();
|
|
|
+ tfCustomFlowEntity.setFlowProcessVar(tfCustomFlow.getFlowProcessVar());
|
|
|
List<FormPropertyBean> formPropertyList = new LinkedList<>();
|
|
|
for (Task t : taskList) {
|
|
|
String flowTaskId = t.getId();
|
|
|
- String processInstanceId = t.getProcessInstanceId();
|
|
|
- Object o = formService.getRenderedTaskForm(flowTaskId);
|
|
|
- log.info("flowTaskId:{},flowId:{}", flowTaskId, processInstanceId);
|
|
|
- if (Objects.nonNull(o)) {
|
|
|
- log.info("task formProperties:{}", JacksonUtil.parseJson(o));
|
|
|
- List<FlowFormWidgetResult> list = JSONArray.parseArray(o.toString(), FlowFormWidgetResult.class);
|
|
|
- formPropertyList.add(new FormPropertyBean(processInstanceId, flowTaskId, list));
|
|
|
+ Long flowId = Long.parseLong(t.getProcessInstanceId());
|
|
|
+ varMap.put("flowId", t.getProcessInstanceId());
|
|
|
+ varMap.put("taskId", flowTaskId);
|
|
|
+ tfCustomFlowEntity.setFlowId(flowId);
|
|
|
+ tfFlowApprove.setFlowId(flowId);
|
|
|
+ tfFlowApprove.setApproveMaxSetup(setupMap.size());
|
|
|
+ tfFlowLog.setFlowId(flowId);
|
|
|
+ tfFlowLog.setTaskId(Long.parseLong(flowTaskId));
|
|
|
+ tfFlowLog.setPendApproveId(Arrays.asList(approveId).toString().replaceAll("\\[", "").replaceAll("\\]", ""));
|
|
|
+ log.info("flowTaskId:{},flowId:{}", flowTaskId, flowId);
|
|
|
+// Object o = formService.getRenderedTaskForm(flowTaskId);
|
|
|
+ FlowTaskResult currFlowTaskResult = GsonUtil.fromJson(GsonUtil.toJson(setupMap.get(t.getTaskDefinitionKey())), FlowTaskResult.class);
|
|
|
+ if (Objects.nonNull(currFlowTaskResult)) {
|
|
|
+ log.info("task formProperties:{}", JacksonUtil.parseJson(currFlowTaskResult));
|
|
|
+ formPropertyList.add(new FormPropertyBean(t.getProcessInstanceId(), flowTaskId, currFlowTaskResult));
|
|
|
}
|
|
|
}
|
|
|
varMap.put("formProperties", formPropertyList);
|
|
|
}
|
|
|
+ tfCustomFlowEntityService.save(tfCustomFlowEntity);
|
|
|
+ tfFlowLog.setObjectId(tfCustomFlowEntity.getId());
|
|
|
+ tfFlowApproveService.save(tfFlowApprove);
|
|
|
+ tfFlowLogService.save(tfFlowLog);
|
|
|
}
|
|
|
return varMap;
|
|
|
}
|
|
@@ -228,7 +243,7 @@ public class ActivitiFromHtmlController {
|
|
|
if (Objects.nonNull(o)) {
|
|
|
log.info("task formProperties:{}", JacksonUtil.parseJson(o));
|
|
|
List<FlowFormWidgetResult> list = JSONArray.parseArray(o.toString(), FlowFormWidgetResult.class);
|
|
|
- formPropertyList.add(new FormPropertyBean(processInstanceId, flowTaskId, userId, list));
|
|
|
+ formPropertyList.add(new FormPropertyBean(processInstanceId, flowTaskId, userId, null));
|
|
|
}
|
|
|
}
|
|
|
varMap.put("formProperties", formPropertyList);
|
|
@@ -267,7 +282,7 @@ public class ActivitiFromHtmlController {
|
|
|
if (Objects.nonNull(o)) {
|
|
|
log.info("task formProperties:{}", JacksonUtil.parseJson(o));
|
|
|
List<FlowFormWidgetResult> list = JSONArray.parseArray(o.toString(), FlowFormWidgetResult.class);
|
|
|
- formPropertyList.add(new FormPropertyBean(processInstanceId, flowTaskId, t.getAssignee(), list));
|
|
|
+ formPropertyList.add(new FormPropertyBean(processInstanceId, flowTaskId, t.getAssignee(), null));
|
|
|
}
|
|
|
varMap.put("formProperties", formPropertyList);
|
|
|
}
|