wzy 1 mês atrás
pai
commit
f1146a52c7

+ 24 - 0
mjava-zhongche/pom.xml

@@ -46,4 +46,28 @@
             <scope>provided</scope>
         </dependency>
     </dependencies>
+
+    <build>
+        <finalName>zhongche</finalName>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>3.1</version>
+                <configuration>
+                    <source>1.8</source>
+                    <target>1.8</target>
+                    <encoding>UTF-8</encoding>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+                <configuration>
+                    <executable>true</executable>
+                    <includeSystemScope>true</includeSystemScope>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
 </project>

+ 29 - 0
mjava-zhongche/src/main/java/com/malk/zhongche/controller/ZhongcheController.java

@@ -0,0 +1,29 @@
+package com.malk.zhongche.controller;
+
+import com.malk.server.common.McR;
+import com.malk.zhongche.service.ZhongcheService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.Map;
+
+@RestController
+public class ZhongcheController {
+    @Autowired
+    private ZhongcheService zhongcheService;
+
+    //获取任务信息
+    @GetMapping("/getTaskInfo")
+    public McR getTaskInfo(String taskId,String projectId){
+        return zhongcheService.getTaskInfo(taskId,projectId);
+    }
+
+    //更新任务延期信息
+    @PostMapping("/updateTaskDelayInfo")
+    public McR updateTaskDelayInfo(@RequestBody Map map){
+        return zhongcheService.updateTaskDelayInfo(map);
+    }
+}

+ 12 - 0
mjava-zhongche/src/main/java/com/malk/zhongche/service/ZhongcheService.java

@@ -0,0 +1,12 @@
+package com.malk.zhongche.service;
+
+import com.malk.server.common.McR;
+
+import java.util.Map;
+
+public interface ZhongcheService {
+    McR getTaskInfo(String taskId,String projectId);
+
+    McR updateTaskDelayInfo(Map map);
+
+}

+ 214 - 0
mjava-zhongche/src/main/java/com/malk/zhongche/service/impl/ZhongcheServiceImpl.java

@@ -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;
+    }
+}

+ 9 - 5
mjava-zhongche/src/main/resources/application-dev.yml

@@ -13,10 +13,10 @@ logging:
 
 # dingtalk
 dingtalk:
-  agentId:
-  appKey:
-  appSecret:
-  corpId:
+  agentId: 4396020096
+  appKey: ding26hdqsk96t6t6np0
+  appSecret: pBjGhyUDyinn192nDK7DQcaEsaGDDwfTLOsER-X3ZoWhGU9DURZGykRkw3aLgAtE
+  corpId: ding187f52da89b1e5c8a1320dcb25e91351
   aesKey:
   token:
   operator:
@@ -25,4 +25,8 @@ aliwork:
   appType: APP_SL9V2KUH6GBEISLNXXTJ
   systemToken: HOE66T71Z9H2PLVHM6EU85Q7H2AJ2YV2GRKKMWL1
 
-
+teambition:
+  AppID: 69c4f0f024a34a74e1c06d61
+  AppSecret: X77qcnv2AICiv70R41YZxGVFXRrFGCta
+  OperatorId: 67ce737aaec2f7379c7bbf6f
+  TenantId: 658a6467d87ead477d2d3f9d

+ 12 - 8
mjava-zhongche/src/main/resources/application-prod.yml

@@ -9,20 +9,24 @@ logging:
   config: classpath:logback-spring.xml
   path: /home/server/zhongche/log/
   level:
-    com.malk.*: info
+    com.malk.*: debug
 
 # dingtalk
 dingtalk:
-  agentId:
-  appKey:
-  appSecret:
-  corpId:
+  agentId: 4396020096
+  appKey: ding26hdqsk96t6t6np0
+  appSecret: pBjGhyUDyinn192nDK7DQcaEsaGDDwfTLOsER-X3ZoWhGU9DURZGykRkw3aLgAtE
+  corpId: ding187f52da89b1e5c8a1320dcb25e91351
   aesKey:
   token:
   operator:
 
 aliwork:
-  appType:
-  systemToken:
-
+  appType: APP_SL9V2KUH6GBEISLNXXTJ
+  systemToken: HOE66T71Z9H2PLVHM6EU85Q7H2AJ2YV2GRKKMWL1
 
+teambition:
+  AppID: 69c4f0f024a34a74e1c06d61
+  AppSecret: X77qcnv2AICiv70R41YZxGVFXRrFGCta
+  OperatorId: 67ce737aaec2f7379c7bbf6f
+  TenantId: 658a6467d87ead477d2d3f9d

+ 4 - 0
mjava-zhongche/src/test/java/com/malk/zhongche/ZcTest.java

@@ -0,0 +1,4 @@
+package com.malk.zhongche;
+
+public class ZcTest {
+}