| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- package com.malk.tuosi.event;
- import com.alibaba.fastjson.JSONObject;
- import com.malk.delegate.TBEvent;
- import com.malk.server.common.McException;
- import com.malk.service.teambition.TBClient;
- import com.malk.utils.UtilMap;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.context.annotation.Primary;
- import org.springframework.scheduling.annotation.Async;
- import org.springframework.stereotype.Service;
- import java.util.*;
- @Primary
- @Service
- @Slf4j
- public class McTbEventImpl implements TBEvent {
- @Autowired
- private TBClient tbClient;
- // @Async
- @Override
- public void callBackTask(JSONObject eventJson) {
- String event = eventJson.getString("event");
- if(event.equals("v3.task.node.status.update")){
- JSONObject data = eventJson.getJSONObject("data");
- String taskId = data.getString("taskId");
- String status = data.getString("status");
- String nodeId = data.getString("nodeId");
- String creatorId = data.getString("creatorId");
- // Map task = tbClient.queryTaskDetail(taskId,null,null).get(0);
- // if(!"6970a3ff4f887b90bfdbe7e3".equals(String.valueOf(task.get("projectId")))){
- // return;
- // }
- // if(!Arrays.asList("622ee3450cf3bb5e1a486f1f","61a9e8a36355609fb6383d40").contains(creatorId)){
- // return;
- // }
- if(status.equals("finish")){
- List<Map> list=tbClient.queryNodeList(taskId);
- Map node = _getNodeDetail(list,nodeId);
- if(String.valueOf(node.get("name")).contains("接单")){
- List<String> assigneeIds = UtilMap.getList(node,"assigneeIds");
- String startDate = UtilMap.getString(node,"startDate");
- String dueDate = UtilMap.getString(node,"dueDate");
- Map nextMap=_getNextNode(list,nodeId);
- if(nextMap!=null){
- String nextId = UtilMap.getString(nextMap,"id");
- tbClient.updateNodeById(taskId,nextId,assigneeIds,startDate,dueDate,creatorId);
- }
- }
- }else if(status.equals("begin")){
- List<Map> list=tbClient.queryNodeList(taskId);
- // Map node = _getNodeDetail(list,nodeId);
- // if(String.valueOf(node.get("name")).contains("接单")){
- nextNode(taskId,list,nodeId,creatorId);
- // }
- }
- }
- }
- private void nextNode(String taskId,List<Map> list,String nodeId,String creatorId){
- Map nextMap=_getNextNode(list,nodeId);
- if(nextMap!=null){
- String nextId = UtilMap.getString(nextMap,"id");
- tbClient.updateNodeById(taskId,nextId,new ArrayList<>(),null,null,creatorId);
- nextNode(taskId,list,nextId,creatorId);
- }
- }
- @Override
- public void callBackProject(JSONObject eventJson) {
- }
- @Async
- @Override
- public void callBackWorktime(JSONObject eventJson) {
- }
- private Map _getNodeDetail(List<Map> list, String nodeId) {
- Optional optional = list.stream().filter(item -> nodeId.equals(item.get("id"))).findAny();
- McException.assertAccessException(!optional.isPresent(), nodeId + ": 节点不存在");
- return (Map) optional.get();
- }
- private Map _getNextNode(List<Map> list, String nodeId) {
- for(Map map : list) {
- List<String> prevIds = UtilMap.getList(map,"prevIds");
- if(prevIds.contains(nodeId)){
- return map;
- }
- }
- return null;
- }
- }
|