|
@@ -191,9 +191,10 @@ public class ZhongcheServiceImpl implements ZhongcheService {
|
|
|
List<Map> result = UtilMap.getList(jsonMap, "result");
|
|
List<Map> result = UtilMap.getList(jsonMap, "result");
|
|
|
for (Map map1 : result) {
|
|
for (Map map1 : result) {
|
|
|
String activityId = UtilMap.getString(map1, "activityId");
|
|
String activityId = UtilMap.getString(map1, "activityId");
|
|
|
|
|
+ String actionExit = UtilMap.getString(map1,"actionExit");
|
|
|
|
|
|
|
|
//管理员审批节点
|
|
//管理员审批节点
|
|
|
- if ("node_ocmouwh06v1".equals(activityId)){
|
|
|
|
|
|
|
+ if ("node_ocmouwh06v1".equals(activityId) && "agree".equals(actionExit)){
|
|
|
String operatorUserId = UtilMap.getString(map1, "operatorUserId");
|
|
String operatorUserId = UtilMap.getString(map1, "operatorUserId");
|
|
|
|
|
|
|
|
Map jsonMap2 = (Map) JSONObject.parse(UtilHttp.doGet("https://open.teambition.com/api/idmap/dingtalk/getTbUserId", initHeaderToken(), UtilMap.map("dingUserIds", operatorUserId)));
|
|
Map jsonMap2 = (Map) JSONObject.parse(UtilHttp.doGet("https://open.teambition.com/api/idmap/dingtalk/getTbUserId", initHeaderToken(), UtilMap.map("dingUserIds", operatorUserId)));
|
|
@@ -380,75 +381,88 @@ public class ZhongcheServiceImpl implements ZhongcheService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (Objects.nonNull(formData.get("attachmentField_mpzbe3w8"))){
|
|
|
|
|
|
|
+ //优先收集"问题表"各行的【存在问题附件】,合并结果为空则回退取默认附件字段
|
|
|
|
|
+ List<Map> fileList = new ArrayList<>();
|
|
|
|
|
+ List<Map> problemRows = parseListField(formData.get("tableField_m9w8qyii"));//问题表
|
|
|
|
|
+ for (Map problemRow : problemRows) {
|
|
|
|
|
+ fileList.addAll(parseListField(problemRow.get("attachmentField_madl2j0j")));//存在问题附件
|
|
|
|
|
+ }
|
|
|
|
|
+ if (fileList.isEmpty()){
|
|
|
|
|
+ fileList = parseListField(formData.get("attachmentField_mpzbe3w8"));//默认附件字段
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (!fileList.isEmpty()){
|
|
|
List<Map> addValues = new ArrayList<>();
|
|
List<Map> addValues = new ArrayList<>();
|
|
|
|
|
+ List<String> fileTokens = new ArrayList<>();
|
|
|
|
|
|
|
|
- List<Map> fileList = (List<Map>) JSONArray.parse(String.valueOf(formData.get("attachmentField_mpzbe3w8")));
|
|
|
|
|
for (Map fileMap : fileList) {
|
|
for (Map fileMap : fileList) {
|
|
|
- String ydDownloadUrl = fileMap.get("downloadUrl").toString();
|
|
|
|
|
- String fileName = fileMap.get("name").toString();
|
|
|
|
|
-
|
|
|
|
|
- try {
|
|
|
|
|
- //下载宜搭附件
|
|
|
|
|
- downloadYdFile(ydDownloadUrl, filePath + fileName);
|
|
|
|
|
- System.out.println("文件下载成功!");
|
|
|
|
|
-
|
|
|
|
|
- //TB文件创建文件上传凭证
|
|
|
|
|
- Path path = Paths.get(filePath + fileName);
|
|
|
|
|
- String mimeType = Files.probeContentType(path);
|
|
|
|
|
- System.out.println(mimeType); // application/pdf
|
|
|
|
|
-
|
|
|
|
|
- File file = new File(fileName);
|
|
|
|
|
- long fileSize = file.length();
|
|
|
|
|
-
|
|
|
|
|
- Map body = new HashMap();
|
|
|
|
|
- body.put("scope", "task:"+taskId+"/attachment");
|
|
|
|
|
- body.put("fileSize", fileSize);
|
|
|
|
|
- body.put("fileType", mimeType);
|
|
|
|
|
- body.put("fileName", fileName);
|
|
|
|
|
- body.put("category", "attachment");
|
|
|
|
|
-
|
|
|
|
|
- TBR tbr = (TBR) UtilHttp.doPost("https://open.teambition.com/api/v3/awos/upload-token", initHeaderToken(), null, body, TBR.class);
|
|
|
|
|
- Map result = (Map) tbr.getResult();
|
|
|
|
|
- String uploadUrl = UtilMap.getString(result, "uploadUrl");
|
|
|
|
|
- String token = UtilMap.getString(result, "token");
|
|
|
|
|
-
|
|
|
|
|
- //上传文件
|
|
|
|
|
- uploadFile(filePath + fileName, uploadUrl, mimeType);
|
|
|
|
|
-
|
|
|
|
|
- Map value = new HashMap();
|
|
|
|
|
- value.put("title",fileName);
|
|
|
|
|
- value.put("metaString",JSONObject.toJSONString(UtilMap.map("fileToken",token)));
|
|
|
|
|
-
|
|
|
|
|
- addValues.add(value);
|
|
|
|
|
- } catch (IOException e) {
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
|
|
+ String ydDownloadUrl = fileMap.get("downloadUrl").toString();
|
|
|
|
|
+ String fileName = fileMap.get("name").toString();
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ //下载宜搭附件
|
|
|
|
|
+ downloadYdFile(ydDownloadUrl, filePath + fileName);
|
|
|
|
|
+ System.out.println("文件下载成功!");
|
|
|
|
|
+
|
|
|
|
|
+ //TB文件创建文件上传凭证
|
|
|
|
|
+ Path path = Paths.get(filePath + fileName);
|
|
|
|
|
+ String mimeType = Files.probeContentType(path);
|
|
|
|
|
+ System.out.println(mimeType); // application/pdf
|
|
|
|
|
+
|
|
|
|
|
+ File file = new File(filePath + fileName);
|
|
|
|
|
+ long fileSize = file.length();
|
|
|
|
|
+
|
|
|
|
|
+ Map body = new HashMap();
|
|
|
|
|
+ body.put("scope", "task:"+taskId+"/attachment");
|
|
|
|
|
+ body.put("fileSize", fileSize);
|
|
|
|
|
+ body.put("fileType", mimeType);
|
|
|
|
|
+ body.put("fileName", fileName);
|
|
|
|
|
+ body.put("category", "attachment");
|
|
|
|
|
+
|
|
|
|
|
+ TBR tbr = (TBR) UtilHttp.doPost("https://open.teambition.com/api/v3/awos/upload-token", initHeaderToken(), null, body, TBR.class);
|
|
|
|
|
+ Map result = (Map) tbr.getResult();
|
|
|
|
|
+ String uploadUrl = UtilMap.getString(result, "uploadUrl");
|
|
|
|
|
+ String token = UtilMap.getString(result, "token");
|
|
|
|
|
+
|
|
|
|
|
+ //上传文件
|
|
|
|
|
+ uploadFile(filePath + fileName, uploadUrl, mimeType);
|
|
|
|
|
+
|
|
|
|
|
+ Map value = new HashMap();
|
|
|
|
|
+ value.put("title",fileName);
|
|
|
|
|
+ value.put("metaString",JSONObject.toJSONString(UtilMap.map("fileToken",token)));
|
|
|
|
|
+
|
|
|
|
|
+ addValues.add(value);
|
|
|
|
|
+ fileTokens.add(token);
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
|
+ throw new IllegalStateException("同步宜搭附件到 Teambition 失败: " + fileName, e);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- //更新tb任务附件
|
|
|
|
|
- Map body = new HashMap();
|
|
|
|
|
- body.put("customfieldId", "67e372b0142aea12588c2d22");
|
|
|
|
|
- body.put("addValues",addValues);
|
|
|
|
|
|
|
+ //更新tb任务附件
|
|
|
|
|
+ Map body = new HashMap();
|
|
|
|
|
+ body.put("customfieldId", "67e372b0142aea12588c2d22");
|
|
|
|
|
+ body.put("addValues",addValues);
|
|
|
|
|
+
|
|
|
|
|
+ Map map2 = tbClient.updateTaskCustomField(taskId, tbOperatorId, body);
|
|
|
|
|
+ log.info("map2:{}",JSONObject.toJSONString(map2));
|
|
|
|
|
|
|
|
- Map map2 = tbClient.updateTaskCustomField(taskId, tbOperatorId, body);
|
|
|
|
|
- log.info("map2:{}",JSONObject.toJSONString(map2));
|
|
|
|
|
|
|
+ createProjectLibraryFiles(projectId, fileTokens, tbOperatorId);
|
|
|
|
|
|
|
|
- //查询任务所在工作流的任务状态列表
|
|
|
|
|
- TBR tbr = (TBR) UtilHttp.doGet("https://open.teambition.com/api/v3/task/" + taskId + "/tfs", initHeaderToken(), null, TBR.class);
|
|
|
|
|
|
|
+ //查询任务所在工作流的任务状态列表
|
|
|
|
|
+ TBR tbr = (TBR) UtilHttp.doGet("https://open.teambition.com/api/v3/task/" + taskId + "/tfs", initHeaderToken(), null, TBR.class);
|
|
|
|
|
|
|
|
- List<Map> tfsList = (List<Map>) tbr.getResult();
|
|
|
|
|
|
|
+ List<Map> tfsList = (List<Map>) tbr.getResult();
|
|
|
|
|
|
|
|
- for (Map tfsMap : tfsList) {
|
|
|
|
|
- String tfsName = UtilMap.getString(tfsMap, "name");
|
|
|
|
|
|
|
+ for (Map tfsMap : tfsList) {
|
|
|
|
|
+ String tfsName = UtilMap.getString(tfsMap, "name");
|
|
|
|
|
|
|
|
- if ("已完成".equals(tfsName)){
|
|
|
|
|
- String tfsId = UtilMap.getString(tfsMap, "id");
|
|
|
|
|
- //完成tb任务
|
|
|
|
|
- tbClient.updateTaskFlowStatus(taskId, tbOperatorId, tfsId,null);
|
|
|
|
|
|
|
+ if ("已完成".equals(tfsName)){
|
|
|
|
|
+ String tfsId = UtilMap.getString(tfsMap, "id");
|
|
|
|
|
+ //完成tb任务
|
|
|
|
|
+ tbClient.updateTaskFlowStatus(taskId, tbOperatorId, tfsId,null);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
return McR.success();
|
|
return McR.success();
|
|
|
}
|
|
}
|
|
@@ -481,6 +495,62 @@ public class ZhongcheServiceImpl implements ZhongcheService {
|
|
|
return McR.success(map);
|
|
return McR.success(map);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 解析宜搭"附件/子表单"类字段值,兼容 String(JSON) 与 List 两种返回形态。
|
|
|
|
|
+ * @param raw 宜搭表单字段原始值(可能为 null、JSON 字符串或 List)
|
|
|
|
|
+ * @return 由 Map 组成的列表;无值或解析失败时返回空列表,不抛异常
|
|
|
|
|
+ */
|
|
|
|
|
+ private List<Map> parseListField(Object raw) {
|
|
|
|
|
+ List<Map> list = new ArrayList<>();
|
|
|
|
|
+ if (Objects.isNull(raw)){
|
|
|
|
|
+ return list;
|
|
|
|
|
+ }
|
|
|
|
|
+ List<?> source;
|
|
|
|
|
+ if (raw instanceof List){
|
|
|
|
|
+ source = (List<?>) raw;
|
|
|
|
|
+ }else if (raw instanceof String && StringUtils.isNotBlank((String) raw)){
|
|
|
|
|
+ try {
|
|
|
|
|
+ source = JSONArray.parseArray((String) raw);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.warn("解析宜搭字段JSON失败, raw:{}", raw, e);
|
|
|
|
|
+ return list;
|
|
|
|
|
+ }
|
|
|
|
|
+ }else {
|
|
|
|
|
+ return list;
|
|
|
|
|
+ }
|
|
|
|
|
+ for (Object item : source) {
|
|
|
|
|
+ if (item instanceof Map){
|
|
|
|
|
+ list.add((Map) item);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return list;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void createProjectLibraryFiles(String projectId, List<String> fileTokens, String operatorId) {
|
|
|
|
|
+ if (!Strings.isNotBlank(projectId)) {
|
|
|
|
|
+ throw new IllegalArgumentException("项目ID不能为空,无法同步项目文件库");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (fileTokens.isEmpty()) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Map body = new HashMap();
|
|
|
|
|
+ body.put("projectId", projectId);
|
|
|
|
|
+ body.put("fileTokens", fileTokens);
|
|
|
|
|
+
|
|
|
|
|
+ TBR response = (TBR) UtilHttp.doPost(
|
|
|
|
|
+ "https://open.teambition.com/api/v3/work/create",
|
|
|
|
|
+ initHeaderToken(operatorId),
|
|
|
|
|
+ null,
|
|
|
|
|
+ body,
|
|
|
|
|
+ TBR.class);
|
|
|
|
|
+ if (Objects.isNull(response)) {
|
|
|
|
|
+ throw new IllegalStateException("创建项目文件库文件失败:未收到 Teambition 响应");
|
|
|
|
|
+ }
|
|
|
|
|
+ response.assertSuccess();
|
|
|
|
|
+ log.info("已同步 {} 个附件到项目文件库, projectId:{}", fileTokens.size(), projectId);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 上传文件(核心方法)
|
|
* 上传文件(核心方法)
|
|
|
* @param filePath 本地文件路径(如"2.png")
|
|
* @param filePath 本地文件路径(如"2.png")
|
|
@@ -650,7 +720,7 @@ public class ZhongcheServiceImpl implements ZhongcheService {
|
|
|
// 操作者ID: 若是查询, 以操作人视角作为权限
|
|
// 操作者ID: 若是查询, 以操作人视角作为权限
|
|
|
private Map<String, String> initHeaderToken(String operatorId) {
|
|
private Map<String, String> initHeaderToken(String operatorId) {
|
|
|
Map header = initHeaderToken();
|
|
Map header = initHeaderToken();
|
|
|
- header.put("x-operator-id", operatorId);
|
|
|
|
|
|
|
+ header.put("X-Operator-Id", operatorId);
|
|
|
return header;
|
|
return header;
|
|
|
}
|
|
}
|
|
|
|
|
|