|
@@ -1,6 +1,8 @@
|
|
|
package com.malk.zhongche.service.impl;
|
|
package com.malk.zhongche.service.impl;
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
+import com.auth0.jwt.JWT;
|
|
|
|
|
+import com.auth0.jwt.algorithms.Algorithm;
|
|
|
import com.malk.server.aliwork.YDConf;
|
|
import com.malk.server.aliwork.YDConf;
|
|
|
import com.malk.server.aliwork.YDParam;
|
|
import com.malk.server.aliwork.YDParam;
|
|
|
import com.malk.server.common.McR;
|
|
import com.malk.server.common.McR;
|
|
@@ -9,9 +11,12 @@ import com.malk.service.aliwork.YDClient;
|
|
|
import com.malk.service.dingtalk.DDClient;
|
|
import com.malk.service.dingtalk.DDClient;
|
|
|
import com.malk.service.dingtalk.DDClient_Contacts;
|
|
import com.malk.service.dingtalk.DDClient_Contacts;
|
|
|
import com.malk.service.teambition.TBClient;
|
|
import com.malk.service.teambition.TBClient;
|
|
|
|
|
+import com.malk.utils.UtilHttp;
|
|
|
import com.malk.utils.UtilMap;
|
|
import com.malk.utils.UtilMap;
|
|
|
|
|
+import com.malk.utils.UtilToken;
|
|
|
import com.malk.zhongche.service.ZhongcheService;
|
|
import com.malk.zhongche.service.ZhongcheService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.logging.log4j.util.Strings;
|
|
import org.apache.logging.log4j.util.Strings;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
@@ -199,6 +204,83 @@ public class ZhongcheServiceImpl implements ZhongcheService {
|
|
|
return McR.success();
|
|
return McR.success();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public McR updateParentTaskType(Map map) {
|
|
|
|
|
+ log.info("更新父任务任务类型:{}",JSONObject.toJSONString(map));
|
|
|
|
|
+ String taskId = UtilMap.getString(map, "taskId");
|
|
|
|
|
+
|
|
|
|
|
+ Map taskInfo = tbClient.queryTaskDetail(taskId, null, null).get(0);
|
|
|
|
|
+
|
|
|
|
|
+ String parentTaskId = UtilMap.getString(taskInfo, "parentTaskId");
|
|
|
|
|
+
|
|
|
|
|
+ Map parentTaskInfo = tbClient.queryTaskDetail(parentTaskId, null, null).get(0);
|
|
|
|
|
+
|
|
|
|
|
+ String projectId = UtilMap.getString(parentTaskInfo, "projectId");
|
|
|
|
|
+ String sfcId = UtilMap.getString(parentTaskInfo, "sfcId");
|
|
|
|
|
+
|
|
|
|
|
+ //获取项目任务类型
|
|
|
|
|
+ List<Map> result = searchProjectSfc(projectId);
|
|
|
|
|
+
|
|
|
|
|
+ String sfcId2 = "";//任务(企业)
|
|
|
|
|
+ String sfcId3 = "";//末级任务(企业)
|
|
|
|
|
+
|
|
|
|
|
+ for (Map resultMap : result) {
|
|
|
|
|
+ String name = UtilMap.getString(resultMap, "name");
|
|
|
|
|
+ String id = UtilMap.getString(resultMap, "id");
|
|
|
|
|
+
|
|
|
|
|
+ switch (name){
|
|
|
|
|
+ case "任务(企业)":sfcId2 = id;break;
|
|
|
|
|
+ case "末级任务(企业)":sfcId3 = id;break;
|
|
|
|
|
+ default:break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //若父任务任务类型为末级任务(企业),更新为任务(企业)
|
|
|
|
|
+ if (sfcId.equals(sfcId3)){
|
|
|
|
|
+ updateTaskSfc(parentTaskId, sfcId2);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return McR.success();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void updateLastTaskSfc() {
|
|
|
|
|
+ List<String> projectIds = searchProject();
|
|
|
|
|
+
|
|
|
|
|
+ for (String projectId : projectIds) {
|
|
|
|
|
+ if (!"6969d8a34991ad9a71ce4ec5".equals(projectId)) continue;//宜搭测试项目
|
|
|
|
|
+
|
|
|
|
|
+ //查询项目下所有非顶级任务
|
|
|
|
|
+ List<Map> taskList = tbClient.queryProjectTaskList(projectId, UtilMap.map("q, pageSize", "taskLayer = exceptTopLevel", 1000), null);
|
|
|
|
|
+
|
|
|
|
|
+ String sfcId = "";//末级任务(企业)
|
|
|
|
|
+ //获取项目任务类型
|
|
|
|
|
+ List<Map> result = searchProjectSfc(projectId);
|
|
|
|
|
+ for (Map resultMap : result) {
|
|
|
|
|
+ String name = UtilMap.getString(resultMap, "name");
|
|
|
|
|
+ String id = UtilMap.getString(resultMap, "id");
|
|
|
|
|
+
|
|
|
|
|
+ switch (name){
|
|
|
|
|
+ case "末级任务(企业)":sfcId = id;break;
|
|
|
|
|
+ default:break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //遍历所有任务,查询末级任务
|
|
|
|
|
+ for (Map task : taskList) {
|
|
|
|
|
+ String taskId = UtilMap.getString(task, "id");
|
|
|
|
|
+
|
|
|
|
|
+ //查询该任务是否有子任务
|
|
|
|
|
+ List<Map> sonTaskList = tbClient.queryTaskDetail(null, null, taskId);
|
|
|
|
|
+
|
|
|
|
|
+ if (sonTaskList.isEmpty()){
|
|
|
|
|
+ //更新任务类型为末级任务(企业)
|
|
|
|
|
+ updateTaskSfc(taskId, sfcId);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private Map getRootTask(String taskId) {
|
|
private Map getRootTask(String taskId) {
|
|
|
Map taskInfo = tbClient.queryTaskDetail(taskId, null, null).get(0);
|
|
Map taskInfo = tbClient.queryTaskDetail(taskId, null, null).get(0);
|
|
|
|
|
|
|
@@ -235,4 +317,74 @@ public class ZhongcheServiceImpl implements ZhongcheService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ private static final Long EXPIRES_IN = 7200000L;
|
|
|
|
|
+
|
|
|
|
|
+ private String getAccessToken() {
|
|
|
|
|
+ String accessToken = UtilToken.get("invalid-token-teambition");
|
|
|
|
|
+ if (StringUtils.isNotBlank(accessToken)) {
|
|
|
|
|
+ return accessToken;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ Algorithm algorithm = Algorithm.HMAC256(tbConf.getAppSecret());
|
|
|
|
|
+ long timestamp = System.currentTimeMillis();
|
|
|
|
|
+ Date issuedAt = new Date(timestamp);
|
|
|
|
|
+ Date expiresAt = new Date(timestamp + EXPIRES_IN);
|
|
|
|
|
+ accessToken = JWT.create().withClaim("_appId", tbConf.getAppID()).withIssuedAt(issuedAt).withExpiresAt(expiresAt).sign(algorithm);
|
|
|
|
|
+ log.info("响应token, {}", accessToken);
|
|
|
|
|
+ UtilToken.put("invalid-token-teambition", accessToken, EXPIRES_IN);
|
|
|
|
|
+ return accessToken;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private Map<String, String> initHeaderToken() {
|
|
|
|
|
+ Map header = new HashMap();
|
|
|
|
|
+ header.put("Authorization", getAccessToken());
|
|
|
|
|
+ header.put("X-Tenant-Id", tbConf.getTenantId());
|
|
|
|
|
+ header.put("X-Tenant-Type", "organization");
|
|
|
|
|
+ return header;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 操作者ID: 若是查询, 以操作人视角作为权限
|
|
|
|
|
+ private Map<String, String> initHeaderToken(String operatorId) {
|
|
|
|
|
+ Map header = initHeaderToken();
|
|
|
|
|
+ header.put("x-operator-id", operatorId);
|
|
|
|
|
+ return header;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //搜索项目任务类型
|
|
|
|
|
+ private List<Map> searchProjectSfc(String projectId) {
|
|
|
|
|
+ String s = UtilHttp.doGet("https://open.teambition.com/api/v3/project/" + projectId + "/scenariofieldconfig/search", initHeaderToken(), UtilMap.map("objectTypes", "task"));
|
|
|
|
|
+ Map result = (Map) JSONObject.parse(s);
|
|
|
|
|
+
|
|
|
|
|
+ log.info("result:{}",result);
|
|
|
|
|
+
|
|
|
|
|
+ List<Map> list = UtilMap.getList(result, "result");
|
|
|
|
|
+
|
|
|
|
|
+ return list;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //更新任务的任务类型
|
|
|
|
|
+ private Map updateTaskSfc(String taskId, String sfcId) {
|
|
|
|
|
+ String s = UtilHttp.doPut("https://open.teambition.com/api/v3/task/" + taskId + "/sfc/update", initHeaderToken(tbConf.getOperatorId()), null, UtilMap.map("sfcId", sfcId));
|
|
|
|
|
+
|
|
|
|
|
+ Map result = (Map) JSONObject.parse(s);
|
|
|
|
|
+
|
|
|
|
|
+ log.info("result:{}",result);
|
|
|
|
|
+
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //通过TQL搜索项目
|
|
|
|
|
+ private List<String> searchProject() {
|
|
|
|
|
+ String s = UtilHttp.doGet("https://open.teambition.com/api/project/search", initHeaderToken(tbConf.getOperatorId()), UtilMap.map("pageSize", 100));
|
|
|
|
|
+
|
|
|
|
|
+ Map result = (Map) JSONObject.parse(s);
|
|
|
|
|
+
|
|
|
|
|
+ log.info("result:{}",result);
|
|
|
|
|
+
|
|
|
|
|
+ List<String> list = UtilMap.getList(result, "result");
|
|
|
|
|
+
|
|
|
|
|
+ return list;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|