|
|
@@ -0,0 +1,84 @@
|
|
|
+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")||status.equals("begin")){
|
|
|
+ boolean isBegin = status.equals("begin");
|
|
|
+ List<Map> list=tbClient.queryNodeList(taskId);
|
|
|
+ Map node = _getNodeDetail(list,nodeId);
|
|
|
+ if(String.valueOf(node.get("name")).contains("接单")){
|
|
|
+ List<String> assigneeIds = isBegin? new ArrayList<>() :UtilMap.getList(node,"assigneeIds");
|
|
|
+ String startDate = isBegin? null: UtilMap.getString(node,"startDate");
|
|
|
+ String dueDate = isBegin? null: 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @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;
|
|
|
+ }
|
|
|
+}
|