|
@@ -534,10 +534,23 @@ public class ZhongcheServiceImpl implements ZhongcheService {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ Map fileLibrary = searchProjectFileLibrary(projectId, operatorId);
|
|
|
|
|
+ if (Objects.isNull(fileLibrary)) {
|
|
|
|
|
+ log.info("项目未启用文件库,跳过附件同步, projectId:{}", projectId);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
Map body = new HashMap();
|
|
Map body = new HashMap();
|
|
|
body.put("projectId", projectId);
|
|
body.put("projectId", projectId);
|
|
|
body.put("fileTokens", fileTokens);
|
|
body.put("fileTokens", fileTokens);
|
|
|
|
|
|
|
|
|
|
+ String productionFolderId = findProductionFolderId(fileLibrary);
|
|
|
|
|
+ if (Strings.isNotBlank(productionFolderId)) {
|
|
|
|
|
+ body.put("parentId", productionFolderId);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ log.info("未找到根目录文件夹04-生产制造,附件将同步到文件库根目录, projectId:{}", projectId);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
TBR response = (TBR) UtilHttp.doPost(
|
|
TBR response = (TBR) UtilHttp.doPost(
|
|
|
"https://open.teambition.com/api/v3/work/create",
|
|
"https://open.teambition.com/api/v3/work/create",
|
|
|
initHeaderToken(operatorId),
|
|
initHeaderToken(operatorId),
|
|
@@ -551,6 +564,51 @@ public class ZhongcheServiceImpl implements ZhongcheService {
|
|
|
log.info("已同步 {} 个附件到项目文件库, projectId:{}", fileTokens.size(), projectId);
|
|
log.info("已同步 {} 个附件到项目文件库, projectId:{}", fileTokens.size(), projectId);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private Map searchProjectFileLibrary(String projectId, String operatorId) {
|
|
|
|
|
+ Map query = new HashMap();
|
|
|
|
|
+ query.put("projectId", projectId);
|
|
|
|
|
+ query.put("q", "04-生产制造");
|
|
|
|
|
+ query.put("onlyWorks", false);
|
|
|
|
|
+ query.put("pageSize", 50);
|
|
|
|
|
+
|
|
|
|
|
+ TBR response = (TBR) UtilHttp.doGet(
|
|
|
|
|
+ "https://open.teambition.com/api/v3/work/search",
|
|
|
|
|
+ initHeaderToken(operatorId),
|
|
|
|
|
+ query,
|
|
|
|
|
+ TBR.class);
|
|
|
|
|
+ if (Objects.isNull(response)) {
|
|
|
|
|
+ throw new IllegalStateException("查询项目文件库失败:未收到 Teambition 响应");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!"200".equals(response.getCode())) {
|
|
|
|
|
+ if (isFileLibraryDisabled(response.getErrorMessage())) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ response.assertSuccess();
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!(response.getResult() instanceof Map)) {
|
|
|
|
|
+ throw new IllegalStateException("查询项目文件库失败:响应结果格式错误");
|
|
|
|
|
+ }
|
|
|
|
|
+ return (Map) response.getResult();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String findProductionFolderId(Map fileLibrary) {
|
|
|
|
|
+ List<Map> collections = UtilMap.getList(fileLibrary, "collections");
|
|
|
|
|
+ for (Map collection : collections) {
|
|
|
|
|
+ String title = UtilMap.getString(collection, "title");
|
|
|
|
|
+ if ("04-生产制造".equals(title)) {
|
|
|
|
|
+ return UtilMap.getString(collection, "id");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private boolean isFileLibraryDisabled(String errorMessage) {
|
|
|
|
|
+ return StringUtils.contains(errorMessage, "文件库")
|
|
|
|
|
+ && (StringUtils.contains(errorMessage, "未开启")
|
|
|
|
|
+ || StringUtils.contains(errorMessage, "未启用")
|
|
|
|
|
+ || StringUtils.contains(errorMessage, "未开通"));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 上传文件(核心方法)
|
|
* 上传文件(核心方法)
|
|
|
* @param filePath 本地文件路径(如"2.png")
|
|
* @param filePath 本地文件路径(如"2.png")
|