|
@@ -0,0 +1,214 @@
|
|
|
|
|
+package com.malk.zhongche.service.impl;
|
|
|
|
|
+
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
+import com.malk.server.aliwork.YDConf;
|
|
|
|
|
+import com.malk.server.aliwork.YDParam;
|
|
|
|
|
+import com.malk.server.common.McR;
|
|
|
|
|
+import com.malk.server.teambition.TBConf;
|
|
|
|
|
+import com.malk.service.aliwork.YDClient;
|
|
|
|
|
+import com.malk.service.dingtalk.DDClient;
|
|
|
|
|
+import com.malk.service.dingtalk.DDClient_Contacts;
|
|
|
|
|
+import com.malk.service.teambition.TBClient;
|
|
|
|
|
+import com.malk.utils.UtilMap;
|
|
|
|
|
+import com.malk.zhongche.service.ZhongcheService;
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.apache.logging.log4j.util.Strings;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
|
+
|
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
|
|
+import java.time.Instant;
|
|
|
|
|
+import java.time.ZoneId;
|
|
|
|
|
+import java.time.ZonedDateTime;
|
|
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
+
|
|
|
|
|
+@Slf4j
|
|
|
|
|
+@Service
|
|
|
|
|
+public class ZhongcheServiceImpl implements ZhongcheService {
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private TBClient tbClient;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private YDClient ydClient;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private DDClient_Contacts ddClient_contacts;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private DDClient ddClient;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private TBConf tbConf;
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public McR getTaskInfo(String taskId,String projectId) {
|
|
|
|
|
+ Map taskInfo = tbClient.queryTaskDetail(taskId,null,null).get(0);
|
|
|
|
|
+
|
|
|
|
|
+ log.info("taskInfo:{}", JSONObject.toJSONString(taskInfo));
|
|
|
|
|
+
|
|
|
|
|
+ List<Map> customfields = UtilMap.getList(taskInfo, "customfields");
|
|
|
|
|
+
|
|
|
|
|
+ List<String> wtls = new ArrayList<>();//问题类型
|
|
|
|
|
+
|
|
|
|
|
+ for (Map customfield : customfields) {
|
|
|
|
|
+ String cfId = UtilMap.getString(customfield, "cfId");
|
|
|
|
|
+
|
|
|
|
|
+ switch (cfId){
|
|
|
|
|
+ case "6941202e92136abe2d9de68f"://问题类型
|
|
|
|
|
+ List<Map> value = UtilMap.getList(customfield, "value");
|
|
|
|
|
+
|
|
|
|
|
+ for (Map map : value) {
|
|
|
|
|
+ wtls.add(UtilMap.getString(map, "title"));
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ case "6969da08b9d8a458d706212d"://完成状态
|
|
|
|
|
+ break;
|
|
|
|
|
+ case "6969dc054cd1174e86aa213a"://延期次数
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ String executorId = UtilMap.getString(taskInfo, "executorId");//执行者id
|
|
|
|
|
+
|
|
|
|
|
+ Map ddUserInfo = tbClient.idMapQuery(executorId, true).get(0);
|
|
|
|
|
+
|
|
|
|
|
+ Map extra = UtilMap.getMap(ddUserInfo, "extra");
|
|
|
|
|
+
|
|
|
|
|
+ String ddUserId = UtilMap.getString(extra, "userId");//执行人钉钉userid
|
|
|
|
|
+ Map userInfoById = ddClient_contacts.getUserInfoById(ddClient.getAccessToken(),ddUserId);
|
|
|
|
|
+ String ddUserName = UtilMap.getString(userInfoById, "name");//执行人钉钉姓名
|
|
|
|
|
+ Map ddUser = new HashMap();
|
|
|
|
|
+ ddUser.put("label",ddUserName);
|
|
|
|
|
+ ddUser.put("value",ddUserId);
|
|
|
|
|
+ ddUser.put("emplId",ddUserId);
|
|
|
|
|
+
|
|
|
|
|
+ long startDate = extracted(UtilMap.getString(taskInfo, "startDate"));//任务开始时间
|
|
|
|
|
+ long dueDate = extracted(UtilMap.getString(taskInfo, "dueDate"));//任务截止时间
|
|
|
|
|
+
|
|
|
|
|
+ String tfsId = UtilMap.getString(taskInfo, "tfsId");//任务状态id
|
|
|
|
|
+
|
|
|
|
|
+ Map body = new HashMap();
|
|
|
|
|
+ body.put("tfsIds", tfsId);
|
|
|
|
|
+ Map tfsInfo = tbClient.queryProjectCustomFlowStatus(projectId, body).get(0);
|
|
|
|
|
+ String tfsName = UtilMap.getString(tfsInfo, "name");//任务状态
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ //获取tb任务上级任务
|
|
|
|
|
+ String parentTaskId = UtilMap.getString(taskInfo, "parentTaskId");
|
|
|
|
|
+ Map parentTaskInfo = tbClient.queryTaskDetail(parentTaskId, null, null).get(0);
|
|
|
|
|
+ String parentTaskName = UtilMap.getString(parentTaskInfo, "content");
|
|
|
|
|
+
|
|
|
|
|
+ //获取tb顶级任务
|
|
|
|
|
+ Map rootTaskInfo = getRootTask(parentTaskId);
|
|
|
|
|
+ String rootTaskName = UtilMap.getString(rootTaskInfo, "content");
|
|
|
|
|
+
|
|
|
|
|
+ Map result = new HashMap();
|
|
|
|
|
+ result.put("wtls", wtls);
|
|
|
|
|
+ result.put("ddUser", ddUser);
|
|
|
|
|
+ result.put("startDate", startDate);
|
|
|
|
|
+ result.put("dueDate", dueDate);
|
|
|
|
|
+ result.put("tfsName", tfsName);
|
|
|
|
|
+ result.put("parentTaskName", parentTaskName);
|
|
|
|
|
+ result.put("rootTaskName", rootTaskName);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ return McR.success(result);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public McR updateTaskDelayInfo(Map map) {
|
|
|
|
|
+ String formInstId = UtilMap.getString(map, "formInstId");
|
|
|
|
|
+
|
|
|
|
|
+ Map formData = ydClient.queryData(YDParam.builder()
|
|
|
|
|
+ .formInstanceId(formInstId)
|
|
|
|
|
+ .build(), YDConf.FORM_QUERY.retrieve_id).getFormData();
|
|
|
|
|
+
|
|
|
|
|
+ String projectId = UtilMap.getString(formData, "textField_mkkrgg8u");//项目id
|
|
|
|
|
+ String taskId = UtilMap.getString(formData, "textField_mkkrgg8y");//任务id
|
|
|
|
|
+ long dueDate = UtilMap.getLong(formData, "dateField_mn757w7y");//预计完成时间
|
|
|
|
|
+
|
|
|
|
|
+ Map taskInfo = tbClient.queryTaskDetail(taskId, null, null).get(0);
|
|
|
|
|
+
|
|
|
|
|
+ List<Map> customfields = UtilMap.getList(taskInfo, "customfields");
|
|
|
|
|
+
|
|
|
|
|
+ int delayNum = 0;//延期次数
|
|
|
|
|
+
|
|
|
|
|
+ for (Map customfield : customfields) {
|
|
|
|
|
+ String cfId = UtilMap.getString(customfield, "cfId");
|
|
|
|
|
+
|
|
|
|
|
+ switch (cfId){
|
|
|
|
|
+ case "6941202e92136abe2d9de68f"://问题类型
|
|
|
|
|
+ break;
|
|
|
|
|
+ case "6969da08b9d8a458d706212d"://完成状态
|
|
|
|
|
+ break;
|
|
|
|
|
+ case "6969dc054cd1174e86aa213a"://延期次数
|
|
|
|
|
+ List<Map> values = UtilMap.getList(customfield, "value");
|
|
|
|
|
+ if (Objects.nonNull(values) && !values.isEmpty()){
|
|
|
|
|
+ Map value = values.get(0);
|
|
|
|
|
+ delayNum = Integer.parseInt(UtilMap.getString(value, "title"));
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //更新任务截止时间
|
|
|
|
|
+
|
|
|
|
|
+ // 1. 转换为 Instant(UTC 时间点)
|
|
|
|
|
+ Instant instant = Instant.ofEpochMilli(dueDate);
|
|
|
|
|
+
|
|
|
|
|
+ // 2.1 转换为 UTC 时间(比上海时间早 8 小时)
|
|
|
|
|
+ ZonedDateTime utcTime = instant.atZone(ZoneId.of("UTC"));
|
|
|
|
|
+ DateTimeFormatter utcFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'");
|
|
|
|
|
+ String utcDateTime = utcTime.format(utcFormatter);
|
|
|
|
|
+ System.out.println("UTC date-time (比上海早8小时): " + utcDateTime); // 输出: 2026-03-20T01:30:00Z
|
|
|
|
|
+
|
|
|
|
|
+ tbClient.updateTaskDueDate(taskId, utcDateTime, tbConf.getOperatorId());
|
|
|
|
|
+
|
|
|
|
|
+ //更新任务延期次数
|
|
|
|
|
+ Map body = new HashMap();
|
|
|
|
|
+ body.put("customfieldId", "6969dc054cd1174e86aa213a");
|
|
|
|
|
+
|
|
|
|
|
+ Map value = new HashMap();
|
|
|
|
|
+ value.put("title",delayNum + 1 + "");
|
|
|
|
|
+ body.put("value",Arrays.asList(value));
|
|
|
|
|
+
|
|
|
|
|
+ Map map1 = tbClient.updateTaskCustomField(taskId, tbConf.getOperatorId(), body);
|
|
|
|
|
+
|
|
|
|
|
+ log.info("map1:{}",JSONObject.toJSONString(map1));
|
|
|
|
|
+
|
|
|
|
|
+ return McR.success();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private Map getRootTask(String taskId) {
|
|
|
|
|
+ Map taskInfo = tbClient.queryTaskDetail(taskId, null, null).get(0);
|
|
|
|
|
+
|
|
|
|
|
+ String parentTaskId = UtilMap.getString(taskInfo, "parentTaskId");
|
|
|
|
|
+
|
|
|
|
|
+ if (Strings.isNotBlank(parentTaskId)){
|
|
|
|
|
+ return getRootTask(parentTaskId);
|
|
|
|
|
+ }else {
|
|
|
|
|
+ return taskInfo;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //转换时区并返回时间戳
|
|
|
|
|
+ private static long extracted(String dueDate) {
|
|
|
|
|
+ // 1. 解析为 Instant(UTC 时间)
|
|
|
|
|
+ Instant instant = Instant.parse(dueDate);
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 转换为目标时区(Asia/Shanghai, UTC+8)
|
|
|
|
|
+ ZoneId shanghaiZone = ZoneId.of("Asia/Shanghai");
|
|
|
|
|
+ ZonedDateTime shanghaiTime = instant.atZone(shanghaiZone);
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 转换为时间戳(毫秒)
|
|
|
|
|
+ long timestamp = shanghaiTime.toInstant().toEpochMilli();
|
|
|
|
|
+
|
|
|
|
|
+ // 输出结果
|
|
|
|
|
+ System.out.println("UTC 时间: " + instant);
|
|
|
|
|
+ System.out.println("上海时间: " + shanghaiTime);
|
|
|
|
|
+ System.out.println("时间戳(毫秒): " + timestamp);
|
|
|
|
|
+
|
|
|
|
|
+ return timestamp;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|