|
@@ -0,0 +1,108 @@
|
|
|
+package com.huyi.flowable.message;
|
|
|
+
|
|
|
+import com.huyi.flowable.mapper.MeHistoryMapper;
|
|
|
+import com.huyi.flowable.server.mapper.MessageMapper;
|
|
|
+import net.sf.json.JSONObject;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.flowable.engine.IdentityService;
|
|
|
+import org.flowable.engine.TaskService;
|
|
|
+import org.flowable.engine.runtime.ProcessInstance;
|
|
|
+import org.flowable.identitylink.api.IdentityLink;
|
|
|
+import org.flowable.identitylink.api.IdentityLinkInfo;
|
|
|
+import org.flowable.idm.api.User;
|
|
|
+import org.flowable.task.api.Task;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+@Component
|
|
|
+public class MessageService {
|
|
|
+ @Autowired
|
|
|
+ protected TaskService taskService;
|
|
|
+ @Autowired
|
|
|
+ protected MessageMapper messageMapper;
|
|
|
+ @Autowired
|
|
|
+ protected IdentityService identityService;
|
|
|
+ @Autowired
|
|
|
+ protected MeHistoryMapper meHistoryMapper;
|
|
|
+
|
|
|
+ //TODO 不同项目不适用
|
|
|
+ public void addStartFlowMessage(ProcessInstance instance){
|
|
|
+ if (instance == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Map<String, Object> paras = instance.getProcessVariables();
|
|
|
+ // 获取公司ID
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("procdefId", instance.getProcessDefinitionId());
|
|
|
+ List<Map<String, Object>> historyList = meHistoryMapper.queryMeHistory(map);
|
|
|
+ String companyId = historyList.get(0).get("companyId").toString();
|
|
|
+ // 1000000006 为融资审批,其他为融信审批
|
|
|
+ String menuId = historyList.get(0).get("menuId").toString();
|
|
|
+ String businessKey = instance.getBusinessKey();
|
|
|
+
|
|
|
+ Map<String, Object> param = new HashMap<>();
|
|
|
+ param.put("id", UUID.randomUUID().toString().replaceAll("-", ""));
|
|
|
+ param.put("companyId", companyId);
|
|
|
+ param.put("tableId", businessKey);
|
|
|
+
|
|
|
+ // 融资审批
|
|
|
+ if ("1000000006".equals(menuId)) {
|
|
|
+ param.put("workType", "03");
|
|
|
+ // 融信审批
|
|
|
+ } else {
|
|
|
+// Map<String, Object> financeInf = messageMapper.queryFinanceInf(businessKey);
|
|
|
+ Map<String, String> userInf = messageMapper.queryUser(String.valueOf(paras.get("createBy")));
|
|
|
+ param.put("workType", "00");
|
|
|
+ param.put("title", "【内部审批】融信【"+paras.get("zfiNumber")+"】资料待审批,审批发起人【"+userInf.get("nickName")+"】");
|
|
|
+ }
|
|
|
+ messageMapper.insertMessage(param);
|
|
|
+
|
|
|
+ try {
|
|
|
+ List<Task> taskList = this.taskService.createTaskQuery().processInstanceId(instance.getId()).list();
|
|
|
+ for (Task task : taskList) {
|
|
|
+ Map<String, String> messageData = new HashMap<>();
|
|
|
+ messageData.put("id", UUID.randomUUID().toString().replaceAll("-", ""));
|
|
|
+
|
|
|
+ List<Long> userIdList = new ArrayList<>();
|
|
|
+ // 审批人
|
|
|
+ String assignee = task.getAssignee();
|
|
|
+ // 无审批人代表为多人审批
|
|
|
+ if (StringUtils.isEmpty(assignee)) {
|
|
|
+ List<IdentityLink> identityLinkList = taskService.getIdentityLinksForTask(task.getId());
|
|
|
+ for (Object o : identityLinkList) {
|
|
|
+ IdentityLinkInfo identityLinkInfo = (IdentityLinkInfo)o;
|
|
|
+ String type = identityLinkInfo.getType();
|
|
|
+ if ("candidate".equals(type)) {
|
|
|
+ String userId = identityLinkInfo.getUserId();
|
|
|
+ String groupId = identityLinkInfo.getGroupId();
|
|
|
+ // 指定用户审批
|
|
|
+ if (userId != null) {
|
|
|
+ userIdList.add(Long.parseLong(userId));
|
|
|
+ // 用户分组审批
|
|
|
+ } else {
|
|
|
+ List<User> userList = identityService.createUserQuery().memberOfGroup(groupId).list();
|
|
|
+ for (User user : userList) {
|
|
|
+ userIdList.add(Long.parseLong(user.getId()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 指定人员审批
|
|
|
+ } else {
|
|
|
+ userIdList.add(Long.parseLong(assignee));
|
|
|
+ }
|
|
|
+ if (userIdList.size() > 0) {
|
|
|
+ Map userMap = new HashMap();
|
|
|
+ userMap.put("noticeId", param.get("id"));
|
|
|
+ userMap.put("userList", userIdList);
|
|
|
+ messageMapper.insertNoticeUserRel(userMap);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ System.out.println("消息增加失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|