lfx hace 9 meses
padre
commit
8eda8f4aae

+ 6 - 0
pom.xml

@@ -307,6 +307,12 @@
                 </exclusion>
             </exclusions>
         </dependency>
+
+        <dependency>
+            <groupId>com.malk</groupId>
+            <artifactId>base</artifactId>
+            <version>1.1-SNAPSHOT</version>
+        </dependency>
     </dependencies>
 
     <build>

+ 2 - 1
src/main/java/com/muzhi/tianhe/TianHeApplication.java

@@ -4,6 +4,7 @@ package com.muzhi.tianhe;
 import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.annotation.ComponentScan;
 import org.springframework.scheduling.annotation.EnableAsync;
 import org.springframework.scheduling.annotation.EnableScheduling;
 
@@ -12,7 +13,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
 @EnableAsync
 @SpringBootApplication//(exclude= DataSourceAutoConfiguration.class)
 @EnableScheduling//开启定时任务
-//@ComponentScan(basePackages = {"com.muzhi"})
+@ComponentScan(basePackages = {"com.muzhi","com.malk"})
 public class TianHeApplication {
 
     public static void main(String[] args){

+ 27 - 27
src/main/java/com/muzhi/tianhe/config/AsyncConfig.java

@@ -1,27 +1,27 @@
-package com.muzhi.tianhe.config;
-
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.core.task.TaskExecutor;
-import org.springframework.scheduling.annotation.EnableAsync;
-import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
-
-@Configuration
-@EnableAsync // 开启异步任务支持
-public class AsyncConfig {
-    @Bean
-    public TaskExecutor taskExecutor() {
-        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
-        // 设置核心线程数
-        executor.setCorePoolSize(5);
-        // 最大线程数
-        executor.setMaxPoolSize(10);
-        // 队列容量
-        executor.setQueueCapacity(20);
-        // 线程池名前缀
-        executor.setThreadNamePrefix("Async-");
-        // 初始化
-        executor.initialize();
-        return executor;
-    }
-}
+//package com.muzhi.tianhe.config;
+//
+//import org.springframework.context.annotation.Bean;
+//import org.springframework.context.annotation.Configuration;
+//import org.springframework.core.task.TaskExecutor;
+//import org.springframework.scheduling.annotation.EnableAsync;
+//import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
+//
+//@Configuration
+//@EnableAsync // 开启异步任务支持
+//public class AsyncConfig {
+//    @Bean
+//    public TaskExecutor taskExecutor() {
+//        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
+//        // 设置核心线程数
+//        executor.setCorePoolSize(5);
+//        // 最大线程数
+//        executor.setMaxPoolSize(10);
+//        // 队列容量
+//        executor.setQueueCapacity(20);
+//        // 线程池名前缀
+//        executor.setThreadNamePrefix("Async-");
+//        // 初始化
+//        executor.initialize();
+//        return executor;
+//    }
+//}

+ 23 - 0
src/main/java/com/muzhi/tianhe/controller/TbController.java

@@ -1,10 +1,13 @@
 package com.muzhi.tianhe.controller;
 
+import com.malk.server.common.McR;
 import com.muzhi.tianhe.entity.Tianhe;
 import com.muzhi.tianhe.entity.vo.TianheDataVo;
 import com.muzhi.tianhe.entity.vo.TianheQuery;
 import com.muzhi.tianhe.exceptionhander.R;
 import com.muzhi.tianhe.service.TbService;
+import com.muzhi.tianhe.service.ThTbService;
+import com.muzhi.tianhe.service.impl.TbApiService;
 import com.muzhi.tianhe.util.UtilExcel;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
@@ -33,6 +36,12 @@ public class TbController {
     @Autowired
     private TbService tbService;
 
+    @Autowired
+    private ThTbService thTbService;
+
+    @Autowired
+    private TbApiService tbApiService;
+
     //获取项目信息
     @Scheduled(cron = "0 0 0,12 * * ? ")
     @ApiOperation(value = "获取项目信息")
@@ -42,6 +51,20 @@ public class TbController {
         return "success";
     }
 
+    //获取项目状态
+    @Scheduled(cron = "0 0 1 * * ? ")
+    @ApiOperation(value = "获取项目状态")
+    @PostMapping("syncState")
+    public McR syncState(){
+        thTbService.syncState();
+        return McR.success();
+    }
+
+    @GetMapping("getCust")
+    public McR getCust(@RequestParam String projectId,@RequestParam String sfcId){
+        return McR.success(tbApiService.getProjectCustomfield(projectId,sfcId));
+    }
+
     @GetMapping("syncProject")
     public String syncProject(String id){
         tbService.asyncXm(id);

+ 2 - 2
src/main/java/com/muzhi/tianhe/controller/TBCallBackController.java

@@ -21,7 +21,7 @@ import java.util.List;
 @Slf4j
 @RestController
 @RequestMapping("/mc/tb")
-public class TBCallBackController {
+public class ThTBCallBackController {
 
     @Autowired
     private ThTbService thTbService;
@@ -37,7 +37,7 @@ public class TBCallBackController {
      * * 3. 任务创建, 会先回调创建事件, 接着立即回调任务更新事件 [若是通过模板创建, 任务只会回调创建, 不会回调更新]
      * * 4. 项目移入回收站,不会触发回调,删除后会触发项目与任务的 remove 事件; 若是将任务移入回收站, 会触发任务更新回调
      */
-    @PostMapping("/callback")
+    @PostMapping("/callback2")
     public String callback(@RequestBody JSONObject eventJson) {
         String success = "success";
         String eventName = eventJson.getString("event");

+ 4 - 0
src/main/java/com/muzhi/tianhe/entity/Tianhe.java

@@ -62,6 +62,10 @@ public class Tianhe {
     @ApiModelProperty(value = "项目状态")
     private String xiangmuzhuangtai;
 
+    @ExcelProperty("项目状态颜色")
+    @ApiModelProperty(value = "项目状态颜色")
+    private String xiangmuzhuangtaicolor;
+
     @ExcelProperty("项目负责人")
     @ApiModelProperty(value = "项目负责人")
     private String xiangmufuzeren;

+ 4 - 0
src/main/java/com/muzhi/tianhe/service/ThTbService.java

@@ -8,4 +8,8 @@ public interface ThTbService {
 
     void taskLink(String taskId,String linkedId);
 
+    void syncState();
+
+    void syncStateProject(String projectId);
+
 }

+ 7 - 2
src/main/java/com/muzhi/tianhe/service/impl/TbApiService.java

@@ -97,6 +97,11 @@ public class TbApiService {
         return result.getJSONArray("result");
     }
 
+    public JSONArray getProjectCustomfield(String projectId,String sfcId){
+        JSONObject result=header(HttpRequest.get(PRIVATE_API_URL + "/v3/project/"+ projectId +"/customfield/search?pageSize=1000&sfcId="+sfcId));
+        return result.getJSONArray("result");
+    }
+
     public JSONArray getProjectRoleMember(String projectId,String id){
         JSONObject result=header(HttpUtil.createGet(PRIVATE_API_URL + "/v3/project/"+ projectId +"/member").form("projectRoleId",id));
         return result.getJSONArray("result");
@@ -107,8 +112,8 @@ public class TbApiService {
         return result.getJSONArray("result");
     }
 
-    public JSONArray getProjecGrouptTag(String id){
-        JSONObject result=header(HttpUtil.createGet(PRIVATE_API_URL + "/v3/project-tag/query").form(new JSONObject().fluentPut("ids",id)));
+    public JSONArray getProjecGrouptTag(Map map){
+        JSONObject result=header(HttpUtil.createGet(PRIVATE_API_URL + "/v3/project-tag/query").form(map));
         return result.getJSONArray("result");
     }
 

+ 38 - 5
src/main/java/com/muzhi/tianhe/service/impl/TbServiceImpl.java

@@ -138,6 +138,18 @@ public class TbServiceImpl extends ServiceImpl<TianheMapper, Tianhe> implements
         return result;
     }
 
+    private String getColor(String degree){
+        if(degree.equals("normal")){
+            return "绿灯";
+        }else if(degree.equals("normal")){
+            return "黄灯";
+        }else if(degree.equals("normal")){
+            return "红灯";
+        }else{
+            return "";
+        }
+    }
+
     // 同步项目下所有周报任务
     private void getZhoubao(String rwlxid,String projectId,boolean isNeedDel){
         Tianhe tianhe = new Tianhe();
@@ -151,12 +163,15 @@ public class TbServiceImpl extends ServiceImpl<TianheMapper, Tianhe> implements
             }
             //里程碑
             tianhe.setLichengbei(TB_LICHENGBEI_MAP.get(projectId));
-            Map<String,JSONArray> projectCustValueMap=getProjectCustVule(projectId);
+            Map<String,JSONArray> projectCustValueMap=getProjectCustVule(projectId); // 概览自定义字段
             // 项目概览自定义字段
             tianhe.setGl(projectCustValueMap);
 
             tianhe.setXiangmubianhao(projectId);
-            tianhe.setXiangmuzhuangtai(getProjectState(projectId));
+
+            JSONObject state=getProjectState(projectId);
+            tianhe.setXiangmuzhuangtai(state.getString("name"));
+            tianhe.setXiangmuzhuangtaicolor(getColor(state.getString("degree")));
             JSONArray projects=tbApiService.getProjectInfo(projectId);
             JSONObject project = projects.getJSONObject(0);
 //            JSONArray customfields = project.getJSONArray("customfields");
@@ -175,6 +190,8 @@ public class TbServiceImpl extends ServiceImpl<TianheMapper, Tianhe> implements
                 //是否归档
                 tianhe.setShifouguidang(project.getString("isSuspended").equals("false")?0:1);
             }
+
+
             // 循环处理每个任务
             for (int i = 0; i < tasks.size(); i++) {
                 JSONObject task = tasks.getJSONObject(i);
@@ -562,11 +579,11 @@ public class TbServiceImpl extends ServiceImpl<TianheMapper, Tianhe> implements
      * @param projectId
      * @return
      */
-    public String getProjectState(String projectId) {
+    public JSONObject getProjectState(String projectId) {
         try {
             JSONArray array=tbApiService.getProjectState(projectId);
             if(array!=null&&array.size()>0){
-                return array.getJSONObject(0).getString("name");
+                return array.getJSONObject(0);
             }
         }catch (Exception e){
             e.printStackTrace();
@@ -635,7 +652,7 @@ public class TbServiceImpl extends ServiceImpl<TianheMapper, Tianhe> implements
         if(isProjectId){
             array=tbApiService.getProjectTag(id);
         }else{
-            array=tbApiService.getProjecGrouptTag(id);
+            array=tbApiService.getProjecGrouptTag(new JSONObject().fluentPut("ids",id));
         }
         if(array!=null&&array.size()>0){
             if(isProjectId){
@@ -696,4 +713,20 @@ public class TbServiceImpl extends ServiceImpl<TianheMapper, Tianhe> implements
         }
         return result;
     }
+
+    /***
+     * 查询项目概览自定义字段数据
+     */
+    private Map<String,String> getProjectStateVule(String projectId){
+        Map<String,String> result=new HashMap<>();
+        try {
+            JSONArray array = tbApiService.getProjectStateId(projectId,"","","");
+            List<JSONObject> list=array.toJavaList(JSONObject.class);
+            list.forEach(item -> result.put(item.getString("id"),item.getString("name")));
+            return result;
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+        return result;
+    }
 }

+ 88 - 0
src/main/java/com/muzhi/tianhe/service/impl/ThTbServiceImpl.java

@@ -2,6 +2,11 @@ package com.muzhi.tianhe.service.impl;
 
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.malk.server.aliwork.YDConf;
+import com.malk.server.aliwork.YDParam;
+import com.malk.server.aliwork.YDSearch;
+import com.malk.service.aliwork.YDClient;
+import com.malk.utils.UtilMap;
 import com.muzhi.tianhe.service.ThTbService;
 import com.muzhi.tianhe.util.PublicUtil;
 import lombok.extern.slf4j.Slf4j;
@@ -17,7 +22,10 @@ public class ThTbServiceImpl implements ThTbService {
 
     @Autowired
     private TbApiService tbApiService;
+    @Autowired
+    private YDClient ydClient;
 
+    private static String PROJECT_TAG_ID = "65b77b8f7bbdd92f48e6920d"; // 战略部分组
 
     @Override
     public void task(String taskId,String type,JSONObject data) {
@@ -421,4 +429,84 @@ public class ThTbServiceImpl implements ThTbService {
         JSONArray value=((JSONObject) optional.get()).getJSONArray("value");
         tbApiService.updateTaskCustomfield(task.getString("id"),projectCusts.get(custName),value);
     }
+
+    @Override
+    public void syncState() {
+        syncStateByTag(PROJECT_TAG_ID);
+    }
+
+    private void syncStateByTag(String tagId){
+        JSONArray projectIds=tbApiService.getProjecTagUser(tagId);
+        for (int j = 0; j < projectIds.size(); j++) {
+            syncStateProject(projectIds.getString(j));
+        }
+        JSONArray array=tbApiService.getProjecGrouptTag(new JSONObject().fluentPut("parentProjectTagId",tagId));
+        for (int i = 0; i < array.size(); i++) {
+            syncStateByTag(array.getJSONObject(i).getString("id"));
+        }
+    }
+
+    @Override
+    public void syncStateProject(String projectId) {
+        // 同步项目下任务状态
+        JSONObject project = tbApiService.getProjectInfo(projectId).getJSONObject(0);;
+        Map<String,String> map=getProjectStateVule(projectId);
+        JSONArray array = getXiangmuRenwuLeixing(projectId);
+        for (int j = 0; j < array.size(); j++) {
+            if(array.getJSONObject(j).getString("name").contains("变更")){
+                continue;
+            }
+            JSONArray tasks=tbApiService.getTasksByType(projectId,array.getJSONObject(j).getString("id"));
+            for (int i = 0; i < tasks.size(); i++) {
+                JSONObject task = tasks.getJSONObject(i);
+                log.info("同步任务,任务编号:[{}]进度:[{}/{}]",task.getString("id"),i+1,tasks.size());
+                ydClient.operateData(YDParam.builder().formUuid("FORM-59A439BCB8194F10B8C862C579F285F5KWG6")
+                        .formDataJson(JSONObject.toJSONString(UtilMap.map("textField_m0rkuewb, textField_m0rkuewd, textField_m0rkuewc, textField_m0rkuewe, selectField_m0rkuewk, textField_m0vtq84z, textField_m0vtq850"
+                                ,task.getString("id"),task.getString("content")
+                                ,projectId,project.getString("name"),map.get(task.getString("tfsId"))
+                                ,array.getJSONObject(j).getString("id"),array.getJSONObject(j).getString("name"))))
+                        .searchCondition(JSONObject.toJSONString(Arrays.asList(new YDSearch("textField_m0rkuewb",task.getString("id"),"taskid", YDSearch.Type.TEXT_FIELD,YDSearch.Operator.EQ))))
+                        .build(), YDConf.FORM_OPERATION.upsert);
+            }
+        }
+//        // 同步项目下自定义字段
+//        List<JSONObject> projectCoutList=tbApiService.getProjectCustomfield(projectId).toJavaList(JSONObject.class);
+//        projectCoutList.forEach(item -> {
+//            ydClient.operateData(YDParam.builder().formUuid("FORM-C5B14D2EE4464AED835BA259388E829D9937")
+//                    .formDataJson(JSONObject.toJSONString(UtilMap.map("textField_m0vvz8ni, textField_m0vvz8nj, textField_m0vvz8nk, textField_m0vvz8nl"
+//                            ,projectId,item.getString("id"),item.getString("name"),item.getString("id"))))
+//                    .searchCondition(JSONObject.toJSONString(Arrays.asList(new YDSearch("textField_m0vvz8nl",item.getString("id"),"自定义字段编号", YDSearch.Type.TEXT_FIELD,YDSearch.Operator.EQ))))
+//                    .build(), YDConf.FORM_OPERATION.upsert);
+//        });
+    }
+
+    //获取项目任务类型
+    public JSONArray getXiangmuRenwuLeixing(String xmid){
+        JSONArray array=tbApiService.getTasksType(xmid);
+        JSONArray result = new JSONArray();
+        if (array != null){
+            for (int i = 0; i < array.size(); i++) {
+                Map map = new HashMap();
+                String name = array.getJSONObject(i).getString("name");
+                String id = array.getJSONObject(i).getString("id");
+                map.put("name",name);
+                map.put("id",id);
+                result.add(map);
+            }
+        }
+        return result;
+    }
+
+    private Map<String,String> getProjectStateVule(String projectId){
+        Map<String,String> result=new HashMap<>();
+        try {
+            JSONArray array = tbApiService.getProjectStateId(projectId,"","","");
+            List<JSONObject> list=array.toJavaList(JSONObject.class);
+            list.forEach(item -> result.put(item.getString("id"),item.getString("name")));
+            return result;
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+        return result;
+    }
 }

+ 7 - 0
src/main/resources/application.properties

@@ -55,3 +55,10 @@ spring.thymeleaf.cache=false
 #spring.mvc.date-format=yyyy-MM-dd
 
 spring.resources.static-locations=classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/,classpath:/templates/
+
+aliwork.appType=APP_JMBVQ7C8A9X2PFBPU111
+aliwork.systemToken=RC966V717UBO2D0TERFZ37T0JMRM2MBVQKR0M8OG
+dingtalk.agentId=2691784047
+dingtalk.appKey=dinghbynhnd2dbgypmsa
+dingtalk.appSecret=Kl5Xw8x0TlEIlvcJuUkYZD18UTTShJmfdKrAIpY8oX-Q_tazyUKA28nQh7dG5-mq
+

+ 16 - 5
src/test/java/com/muzhi/tianhe/TbTest.java

@@ -5,6 +5,11 @@ import cn.hutool.http.HttpUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.malk.server.aliwork.YDConf;
+import com.malk.server.aliwork.YDParam;
+import com.malk.server.aliwork.YDSearch;
+import com.malk.service.aliwork.YDClient;
+import com.malk.utils.UtilMap;
 import com.muzhi.tianhe.service.AccessTokenService;
 import com.muzhi.tianhe.service.TbService;
 import com.muzhi.tianhe.service.ThTbService;
@@ -19,10 +24,7 @@ import org.junit.jupiter.api.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
 
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
+import java.util.*;
 
 @Slf4j
 @SpringBootTest(classes = TianHeApplication.class)
@@ -44,7 +46,7 @@ public class TbTest {
 //            log.info("u:{}",users);
 //            tbService.test();
 //            tbService.getDingUserId("");
-            tbService.asyncXm();
+            tbService.asyncXm("661be43bfc0ff5ef94bdd073");
 //            JSONArray array=tbApiService.getProjectState("65efed344f2eb1fe4e88c81f");
 //            System.out.println(array);
         } catch (Exception e) {
@@ -54,6 +56,8 @@ public class TbTest {
 
     private String data="{\"created\":\"2024-06-25T03:05:18.778Z\",\"creatorId\":\"65b1dc8355d0f38026a1c3db\",\"customfieldId\":\"65b9e3af475c2137f56d572d\",\"customfieldOldValue\":[],\"customfieldType\":\"lookup\",\"customfieldValue\":[{\"id\":\"65b1dc8355d0f38026a1c3db\",\"title\":\"顾虎臣\"}],\"taskId\":\"667127e4a830bd315b3baf44\",\"updated\":\"2024-06-25T03:05:18.778Z\"}";
 
+    @Autowired
+    private YDClient ydClient;
 
     @Test
     public void tbTest(){
@@ -79,4 +83,11 @@ public class TbTest {
     //ADD COLUMN `glxiangmushishicelue`  text NULL AFTER `taskid`,
     //ADD COLUMN `glxiangmujili`  text NULL AFTER `taskid`,
     //ADD COLUMN `glxiangmuzhuyaofengxian`  text NULL AFTER `taskid`;
+
+    @Test
+    public void syncStatus(){
+        thTbService.syncState();
+
+    }
+
 }