浏览代码

项目状态更新

pruple_boy 10 月之前
父节点
当前提交
e1f233191d

+ 85 - 44
mjava-aiwei/src/main/java/com/malk/aiwei/service/impl/AWImplClient.java

@@ -2,7 +2,6 @@ package com.malk.aiwei.service.impl;
 
 import cn.hutool.core.util.ObjectUtil;
 import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONObject;
 import com.google.common.collect.Lists;
 import com.malk.aiwei.server.AWServer;
 import com.malk.aiwei.service.AWClint;
@@ -50,6 +49,7 @@ public class AWImplClient implements AWClint {
         Map<String, String> formUuid = UtilMap.empty();
         if (UtilEnv.getActiveProfile().equals(UtilEnv.ENV_PROD)) {
             formUuid.put("DENTRY", "FORM-BD73A57B62EA4153B896C9BB3EA14D28GWSQ");                // 文件夹/文件版本记录
+            formUuid.put("PERMISSION", "FORM-3380221DFDF84FBD8BCF503198294257TFWB");            // 文件夹权限
             formUuid.put("REVIEW", "FORM-812FD46AF391449A8F206EDB3221B38840UQ");                // 交付物审批记录
             formUuid.put("REVIEW_PROCESS", "TPROC--RJC66SC1NEFHXJ0H770K0CF4WN1K21HQ706RL5");    // 交付物审批记录
             formUuid.put("PROJECT", "FORM-141E21DF183846028E21727CE43CD1C75CLZ");               // 项目主数据
@@ -64,6 +64,7 @@ public class AWImplClient implements AWClint {
         } else {
             // [ fixme: 测试环境添加主数据, 匹配不同架构下企业成员 ]
             formUuid.put("DENTRY", "FORM-AA1237FC3B5A4DEBA7C823EDB48CCDEBZ1SV");
+            formUuid.put("PERMISSION", "FORM-E06FB2317C3A4C119B96EE2B034AD3A8O3YF");
             formUuid.put("REVIEW", "FORM-FBC1A390B4C348089020C763938A6F54RUNY");
             formUuid.put("REVIEW_PROCESS", "TPROC--YU966T91PIDH4XDR82OJC8GVOP7Z19PODTXQL6");
             formUuid.put("PROJECT", "FORM-84EF78C7DBA047E58A8C8511106F91D5WNVI");
@@ -71,6 +72,7 @@ public class AWImplClient implements AWClint {
             formUuid.put("CHECK", "FORM-E6CB042D7929448888AE5E2B27631E57IVPM");
             formUuid.put("RECORD", "FORM-7B63BB056145452F8BC0A2C52492DE00QVBH");
             formUuid.put("ROLE", "FORM-5BE21392886E46DF955D1EBC100ADA429NON");
+            formUuid.put("ROLE_PDT", "FORM-EE138B018F5F4B569279B299D43AA77E2QL1");
             formUuid.put("CRM_LOG", "FORM-7F40E85D4FA8487C8E00C9156B76A953CBMG");
             formUuid.put("TEMPLATE", "FORM-C864290977A64FC4A061434DF21D5871JA04");
             formUuid.put("DOMAIN", "https://kabom7.aliwork.com/");
@@ -258,7 +260,7 @@ public class AWImplClient implements AWClint {
      * 交付物审批变更发起
      */
     @Override
-    public void changeApprove(String taskId, String instanceId,String title) {
+    public void changeApprove(String taskId, String instanceId, String title) {
         String result = _matchFormUuid("DOMAIN") + ydConf.getAppType() + "/processDetail?procInsId=" + instanceId;
         Map body = TBConf.assembleCustomFieldName(AWServer.TASK_APPROVE_LINK, result);
         tbClient.updateTaskCustomField(taskId, tbConf.getOperatorId(), body);
@@ -429,7 +431,7 @@ public class AWImplClient implements AWClint {
     @Override
     public Map doCheck(String taskId, boolean isTask) {
 
-        log.info("检查项check, {},isTask:{}", taskId,isTask);
+        log.info("检查项check {}, isTask {}", taskId, isTask);
         Map taskData = _getTaskFieldMap(taskId, AWServer.TASK_CODE, AWServer.TASK_CHECK_LINK, AWServer.TASK_ROLE, AWServer.TASK_STAGE, AWServer.TASK_CHECK_STATUS, AWServer.TASK_PRODUCT, AWServer.TASK_PRODUCT_VERSION);
         Map rTask = UtilMap.getMap(taskData, "task");
         String pCode = UtilMap.getString(rTask, "projectId");
@@ -454,7 +456,7 @@ public class AWImplClient implements AWClint {
         String executorId = UtilMap.getString(rTask, "executorId");
         String tCode = UtilMap.getString(taskData, AWServer.TASK_CODE);
 
-        String resultTitle = "",resultUrl = "";
+        String resultTitle = "", resultUrl = "";
         List<Map> tList = null;
         Map rProject = null;
         if (StringUtils.isBlank(tCode)) {
@@ -481,14 +483,14 @@ public class AWImplClient implements AWClint {
                 }
             }
         }
-        log.info("检查项结果, {},{}", resultTitle,resultUrl);
-        String result=resultTitle.equals(AWServer.TASK_CHECK_LINK_OK)?resultUrl:resultTitle;
+        log.info("检查项结果, {},{}", resultTitle, resultUrl);
+        String result = resultTitle.equals(AWServer.TASK_CHECK_LINK_OK) ? resultUrl : resultTitle;
         if (isTask) {
             if (!result.equals(checkLink)) {
                 Map body = TBConf.assembleCustomFieldName(AWServer.TASK_CHECK_LINK, result);
                 tbClient.updateTaskCustomField(taskId, tbConf.getOperatorId(), body);
                 // prd 7.17 技术检查项从未匹配到更新,刷新检查状态为空
-                if (resultTitle.equals(AWServer.TASK_CHECK_LINK_OK) && (checkLink.equals("未配置预检项")||checkLink.equals(""))) {
+                if (resultTitle.equals(AWServer.TASK_CHECK_LINK_OK) && (checkLink.equals("未配置预检项") || checkLink.equals(""))) {
                     Map body2 = TBConf.assembleCustomFieldName(AWServer.TASK_CHECK_STATUS);
                     tbClient.updateTaskCustomField(taskId, tbConf.getOperatorId(), body2);
                 }
@@ -499,7 +501,7 @@ public class AWImplClient implements AWClint {
                 Map body = TBConf.assembleCustomFieldName(AWServer.TASK_CHECK_STATUS, "已检查");
                 tbClient.updateTaskCustomField(taskId, tbConf.getOperatorId(), body);
             }
-            return UtilMap.map("result", resultTitle.equals(AWServer.TASK_CHECK_LINK_OK)?resultUrl:resultTitle);
+            return UtilMap.map("result", result);
         }
         // prd 7.17 添加执行人为空校验
         McException.assertAccessException(StringUtils.isBlank(executorId), "执行人不能为空!");
@@ -517,7 +519,8 @@ public class AWImplClient implements AWClint {
             item.put("associationFormField_lrrnem5r", YDConf.associationForm(ydConf.getAppType(), _matchFormUuid("CHECK"), UtilMap.getString(item, "instanceId"), UtilMap.getString(item, "textField_lrnd3h0r"), "", false));
             return item;
         }).collect(Collectors.toList()));
-        formData.put("userId",extra.get("userId"));// prd 7.17 技术检查项需要匹配userId
+        // prd 7.17 技术检查项需要匹配userId
+        formData.put("userId", extra.get("userId"));
         return formData;
     }
 
@@ -634,6 +637,10 @@ public class AWImplClient implements AWClint {
                     .useLatestVersion(true)
                     .build();
             if (projectMaps.size() > 0) {
+                /// 7.18 项目状态不一致执行概览字段更新, 避免tb重复更新造成操作记录
+                if (!formData.get("textField_ltsdsti7").equals(projectMaps.get(0).get("textField_ltsdsti7"))) {
+                    formData.put("src_state", formData.get("textField_ltsdsti7"));
+                }
                 ydParam2.setFormInstanceId(String.valueOf(projectMaps.get(0).get("instanceId")));
                 ydClient.operateData(ydParam2, YDConf.FORM_OPERATION.update); // 主表为增量更新
                 // 保留tb项目号, 避免冲重复通过模板参加项目 [供新增用]
@@ -781,7 +788,9 @@ public class AWImplClient implements AWClint {
         if (isCreate) {
             tbClient.updateProjectStatusField(projectId, tbConf.getOperatorId(), TBConf.assembleCustomFieldName("项目描述", UtilMap.getString(formData, "textareaField_lrj7vnxl")));
             tbClient.updateProjectStatusField(projectId, tbConf.getOperatorId(), TBConf.assembleCustomFieldName("项目重要等级", UtilMap.getString(formData, "textField_lwj1r7n6")));
-            // prd 7.18 更新项目状态需求
+        }
+        /// 7.18 项目状态不一致执行概览字段更新, 避免tb重复更新造成操作记录
+        if (UtilMap.isNotBlankString(formData, "src_state")) {
             tbClient.updateProjectStatusField(projectId, tbConf.getOperatorId(), TBConf.assembleCustomFieldName("状态", UtilMap.getString(formData, "textField_ltsdsti7")));
         }
         log.info("TB项目信息, {}, {}", projectId, roleIds.size());
@@ -1371,6 +1380,7 @@ public class AWImplClient implements AWClint {
         String formInstanceId = "";
         List<String> staffIds = new ArrayList<>();
         List<Map> subList = null;
+        String proType = "";
 
         // 通用账户unionId
         String unionId = String.valueOf(ddClient_contacts.getUserInfoById(ddClient.getAccessToken(), ddConf.getOperator()).get("unionid"));
@@ -1391,6 +1401,7 @@ public class AWImplClient implements AWClint {
                 }
             }
             subList = details; // 子表数据
+            proType = UtilMap.getString(pList.get(0), "textField_ltwcq7s6"); // prd 多模板适配: [任务号 + 项目类型]
             if (StringUtils.isBlank(workspaceId)) {
                 // 获取知识库空间Id [ ppExt: 知识库列表接口, 查询受到 operatorId 权限控制, 仅会返回操作者有权限知识库 ] todo tb提供接口返回知识库相关信息
                 List<Map> workspaces = ddClient_storage.searchWorkspaces(ddClient.getAccessToken(), unionId, pCode, null);
@@ -1422,7 +1433,7 @@ public class AWImplClient implements AWClint {
                 log.error(e.getMessage(), e);
             }
             // 知识库文件夹 & 拷贝处理 [prd 文件目录结构 TR评审节点/资源名称]
-            Map taskData = _getTaskFieldMap(taskId, AWServer.TASK_APPROVE_ATTACHMENT, AWServer.TASK_APPROVE_VERSION, AWServer.TASK_STAGE, AWServer.TASK_ROLE);
+            Map taskData = _getTaskFieldMap(taskId, AWServer.TASK_APPROVE_ATTACHMENT, AWServer.TASK_APPROVE_VERSION, AWServer.TASK_STAGE, AWServer.TASK_ROLE, AWServer.TASK_CODE);
             Map rTask = UtilMap.getMap(taskData, "task");
             // fixme: 知识库所有操作和权限都与依赖于权限, 通过 spaceId + dentryId 查询创建人需要传递操作者, 操作者需要有查看以上权限. todo 目前临时读取执行人, tb文档相关信息需要返回创建人信息
             Map<String, String> extra = (Map) tbClient.idMapQuery(UtilMap.getString(rTask, "executorId"), "dingTalk-user", ddConf.getCorpId()).get(0).get("extra");
@@ -1478,7 +1489,8 @@ public class AWImplClient implements AWClint {
                 DDR_New ddr_new;
                 try {
                     ddr_new = ddClient_storage.copyDentries(ddClient.getAccessToken(), unionId, workspaceId, UtilMap.getString(doc, "instanceId"), workspaceId, rootNodeId, docName);
-                    //_updatePermission(ddr_new.getDentryUuid(), unionId, tName, subList); // 设置文件权限矩阵
+                    String taskCode = UtilMap.getString(taskData, AWServer.TASK_CODE);
+                    //_updatePermission(taskCode, proType, ddr_new.getDentryUuid(), unionId, tName, subList); // 设置文件权限矩阵
                 } catch (McException e) {
                     // ppExt: 权限异常可能原因是重复授权, 依然执行复制操作, 再跳过
                     log.error(e.getMessage(), e);
@@ -1524,8 +1536,42 @@ public class AWImplClient implements AWClint {
     }
 
     /// 交付件权限设置,包括TBManager账号设置为只读,针对文件. 移除非权限矩阵的项目成员
-    private void _updatePermission(String dentryUuid, String creatorUnionId, String roleName, List<Map> details) {
-
+    private void _updatePermission(String taskCode, String proType, String dentryUuid, String creatorUnionId, String roleName, List<Map> details) {
+
+        boolean isAll = false;
+
+        // 取值权限矩阵: 获取角色在项目主数据对应成员
+        List<Map> tList = ydService.queryDataList_FormData(_matchFormUuid("PERMISSION"), UtilMap.map("selectField_lrncf4hk, radioField_lyvawhud", taskCode, "启用"));
+        tList = tList.stream().filter(item -> taskCode.equals(item.get("selectField_lrncf4hk")) && UtilMap.getList(item, "multiSelectField_ltwjre9s").contains(proType)).collect(Collectors.toList());
+        List<String> userIds = new ArrayList<>();
+        if (tList.size() > 0) {
+            List<String> roles = UtilMap.getList(tList.get(0), "multiSelectField_lyv8g8sy");
+            if (roles.contains("项目组成员")) {
+                isAll = true;
+            } else {
+                // 兼容: 添加当前任务资源名称角色
+                if (!roles.contains(roleName)) {
+                    roles.add(roleName);
+                }
+                for (String roleN : roles) {
+                    Optional optional = details.stream().filter(item -> roleN.equals(item.get("selectField_lqxu6bgf"))).findAny();
+                    if (optional.isPresent()) {
+                        userIds.addAll((List<String>) UtilMap.getList((Map) optional.get(), "employeeField_lqxtykch_id"));
+                    }
+                }
+            }
+        } else {
+            isAll = true;
+        }
+        /// 若权限体系包含了 [项目组成员] 或 未匹配到任务权限, 则开放为项目全员可见
+        if (isAll) {
+            for (Map detail : details) {
+                if (ObjectUtil.isNotNull(detail.get("employeeField_lqxtykch_id"))) {
+                    userIds.addAll((List) detail.get("employeeField_lqxtykch_id"));
+                }
+            }
+        }
+        // 设置权限节点
         ddClient_storage.updateDentryPermissionsInheritances(ddClient.getAccessToken(), dentryUuid, creatorUnionId, "BREAK");
         List<String> staffIds = new ArrayList<>();
         try {  // todo 目前权限绑定群聊会异常, BUG
@@ -1535,7 +1581,8 @@ public class AWImplClient implements AWClint {
                 if ("USER".equals(UtilMap.getString(team, "type"))) {
                     String roleId = UtilMap.getString(UtilMap.getMap(member, "role"), "id");
                     String userId = UtilMap.getString(team, "id");
-                    if (!Arrays.asList("OWNER", "MANAGER").contains(roleId)) {
+                    // ppExt: 非权限体系内的成员, 以及文件所有者\管理者外, 执行删除
+                    if (!Arrays.asList("OWNER", "MANAGER").contains(roleId) && !userIds.contains(userId)) {
                         staffIds.add(userId);
                     }
                 }
@@ -1544,27 +1591,26 @@ public class AWImplClient implements AWClint {
             if (staffIds.contains(ddConf.getOperator())) {
                 staffIds.remove(ddConf.getOperator());
             }
-            log.info("删除文件权限 {}, {}, {}", dentryUuid, staffIds);
-
-            // 权限成员列表,最大size30, 通过 partition 快速切割[ 只读权限]
-            List<List<String>> parts = Lists.partition(staffIds, DDConf.WORKSPACE_PERMISSION_SIZE);
-            for (List<String> ids : parts) {
-                List<Map> members = ids.stream().map(userId -> UtilMap.map("type, id", "USER", userId)).collect(Collectors.toList());
-                // ppExt 会自动移除更低的权限
-                ddClient_storage.deleteDentryPermissions(ddClient.getAccessToken(), dentryUuid, creatorUnionId, "EDITOR", members, null);
-            }
+            log.info("文件权限 {}, 删除 = {}, 只读 = {}", dentryUuid, staffIds, userIds);
+            _batchUpdatePermission(staffIds, dentryUuid, creatorUnionId, "EDITOR", true);
+            _batchUpdatePermission(userIds, dentryUuid, creatorUnionId, "READER", false);
         } catch (McException e) {
             log.error(e.getMessage(), e);
         }
+    }
+
 
-        // 获取角色在项目主数据对应成员 [ todo 取值权限矩阵 ]
-        Optional optional = details.stream().filter(item -> roleName.equals(item.get("selectField_lqxu6bgf"))).findAny();
-        if (!optional.isPresent()) {
-            return;
+    /// fixme 权限成员列表,最大size30, 通过 partition 快速切割
+    private void _batchUpdatePermission(List<String> userIds, String dentryUuid, String creatorUnionId, String roleId, boolean isDelete) {
+        List<List<String>> parts = Lists.partition(userIds, DDConf.WORKSPACE_PERMISSION_SIZE);
+        for (List<String> ids : parts) {
+            List<Map> members = ids.stream().map(userId -> UtilMap.map("type, id", "USER", userId)).collect(Collectors.toList());
+            if (isDelete) {
+                ddClient_storage.deleteDentryPermissions(ddClient.getAccessToken(), dentryUuid, creatorUnionId, roleId, members, null);
+            } else {
+                ddClient_storage.updateDentryPermissions(ddClient.getAccessToken(), dentryUuid, creatorUnionId, roleId, members, null);
+            }
         }
-        List<String> roleIds = (List<String>) UtilMap.getList((Map) optional.get(), "employeeField_lqxtykch_id");
-        List<Map> members = roleIds.stream().map(userId -> UtilMap.map("type, id", "USER", userId)).collect(Collectors.toList());
-        ddClient_storage.updateDentryPermissions(ddClient.getAccessToken(), dentryUuid, creatorUnionId, "READER", members, null);
     }
 
     /// 更新一级归档目录 dentryUuid 权限打断, 并更新项目成员只读权限, 且更新记录实例ID [ 用于后续项目全量同步时, 刷新权限 ]
@@ -1598,12 +1644,7 @@ public class AWImplClient implements AWClint {
             staffIds.remove(ddConf.getOperator());
         }
         log.info("更新一级归档目录 {}, {}, {}", dentryUuid, staffIds, formInstanceId);
-        // 权限成员列表,最大size30, 通过 partition 快速切割[ 只读权限]
-        List<List<String>> parts = Lists.partition(staffIds, DDConf.WORKSPACE_PERMISSION_SIZE);
-        for (List<String> ids : parts) {
-            List<Map> members = ids.stream().map(userId -> UtilMap.map("type, id", "USER", userId)).collect(Collectors.toList());
-            ddClient_storage.updateDentryPermissions(ddClient.getAccessToken(), dentryUuid, creatorUnionId, "READER", members, null);
-        }
+        _batchUpdatePermission(staffIds, dentryUuid, creatorUnionId, "READER", false);
         if (StringUtils.isNotBlank(formInstanceId)) {
             ydClient.operateData(YDParam.builder()
                     .formInstanceId(formInstanceId)
@@ -1633,7 +1674,7 @@ public class AWImplClient implements AWClint {
 
     @Override
     public void test() {
-//        approveVersion("659a681d44ade3345fdc0d39", "99999");
+        approveVersion("659a681d44ade3345fdc0d39", "99999");
 //
 //        String pCode = "99999";
 //        String pCode = "A240407DryRun";
@@ -1645,15 +1686,15 @@ public class AWImplClient implements AWClint {
 //        String creatorUnionId = String.valueOf(ddClient_contacts.getUserInfoById(ddClient.getAccessToken(), "095358016629044412").get("unionid"));
 //        List<Map> allMembers = ddClient_storage.queryDentryPermissions(ddClient.getAccessToken(), "14lgGw3P8vMDNPvMC7aw11LzJ5daZ90D", creatorUnionId, null);
 //        log.info("xxxx, {}", allMembers);
-
-        String taskId = "65addc57055591ee7d17d807";
-        Map taskData = _getTaskFieldMap(taskId, AWServer.TASK_APPROVE_LINK, AWServer.TASK_APPROVE_VERSION, AWServer.TASK_STAGE, AWServer.TASK_ROLE);
-        List<Map> checkList = _getCustomFieldList(taskData, AWServer.TASK_APPROVE_LINK);
+//
+//        String taskId = "65addc57055591ee7d17d807";
+//        Map taskData = _getTaskFieldMap(taskId, AWServer.TASK_APPROVE_LINK, AWServer.TASK_APPROVE_VERSION, AWServer.TASK_STAGE, AWServer.TASK_ROLE);
+//        List<Map> checkList = _getCustomFieldList(taskData, AWServer.TASK_APPROVE_LINK);
 
 //        checkList = new ArrayList<>();
 //        String url = "https://kabom7.aliwork.com/APP_H7WUJTKB448F9IBDC6C4/processDetail?formUuid=FORM-FBC1A390B4C348089020C763938A6F54RUNY&procInsId=5bd917c4-b23c-4f2f-ba4b-cef533118cdf&isAdmin=true&navConfig.layout=1180";
-        String url = "https://kabom7.aliwork.com/APP_H7WUJTKB448F9IBDC6C4/submission/FORM-7B63BB056145452F8BC0A2C52492DE00QVBH?taskId=65addc57055591ee7d17d807";
-        _updateApproveField(taskId, checkList, url, "技术检查项确认", "待提交", AWServer.TASK_APPROVE_LINK);
+//        String url = "https://kabom7.aliwork.com/APP_H7WUJTKB448F9IBDC6C4/submission/FORM-7B63BB056145452F8BC0A2C52492DE00QVBH?taskId=65addc57055591ee7d17d807";
+//        _updateApproveField(taskId, checkList, url, "技术检查项确认", "待提交", AWServer.TASK_APPROVE_LINK);
 
     }
 

+ 18 - 0
mjava-cloudpure/src/main/java/com/malk/cloudpure/controller/TLYController.java

@@ -12,6 +12,7 @@ import com.malk.utils.UtilMap;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.map.HashedMap;
 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.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
@@ -145,6 +146,8 @@ public class TLYController {
         formData.put("textField_lygvvyd9", tasks.get(0).get("taskId"));
         formData.put("textField_lygvvyda", tasks.get(0).get("userId"));
         formData.put("textField_lyh4y3th", processInstanceId);
+        formData.put("selectField_lyo1uao4", "否"); // 出差是否报销, 否
+        formData.put("selectField_lyo1zprd", "是"); // 同步存量数据, 否
 
         log.info("审批数据, {}", JSON.toJSONString(formData));
         ydClient.operateData(YDParam.builder()
@@ -178,6 +181,21 @@ public class TLYController {
         ddClient_workflow.terminateRunningApprove(accessToken, processInstanceId, true, "发起人撤销", userId);
         return McR.success();
     }
+
+    @GetMapping("test")
+    McR test() {
+
+
+        long beginTime = UtilDateTime.parseDateTime("2024-06-01 00:00:00").getTime();
+        long finishTime = UtilDateTime.parseDateTime("2024-07-17 00:00:00").getTime();
+
+        Map extInfo = UtilMap.map("statuses", Arrays.asList("COMPLETED"));
+        List<String> dataList = ddClient_workflow.getInstanceIds_all(ddClient.getAccessToken(), "PROC-6E40CB5E-F2AE-4CE6-9864-F5C3848D0C7E", beginTime, finishTime, extInfo);
+
+
+        log.info("xxxx, {}", dataList.size());
+        return McR.success();
+    }
 }