|
|
@@ -0,0 +1,508 @@
|
|
|
+package com.muzhi.duohui.service.impl;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.aliyun.dingtalkyida_1_0.models.SearchFormDatasResponse;
|
|
|
+import com.aliyun.tea.TeaException;
|
|
|
+import com.aliyun.teautil.models.RuntimeOptions;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
+import com.muzhi.duohui.common.R;
|
|
|
+import com.muzhi.duohui.service.AccessTokenService;
|
|
|
+import com.muzhi.duohui.service.TbService;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import okhttp3.*;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+
|
|
|
+@Service
|
|
|
+@Slf4j
|
|
|
+public class TbServiceImpl implements TbService {
|
|
|
+
|
|
|
+ //宜搭接口调用
|
|
|
+ public static com.aliyun.dingtalkyida_1_0.Client createClient() throws Exception {
|
|
|
+ com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
|
|
|
+ config.protocol = "https";
|
|
|
+ config.regionId = "central";
|
|
|
+ return new com.aliyun.dingtalkyida_1_0.Client(config);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private AccessTokenService accessTokenService;
|
|
|
+
|
|
|
+ //夺汇TB企业ID(tbOrganizationId)
|
|
|
+ public static String tbOrganizationId = "5e8e8a6ef849edccba9be9e3";
|
|
|
+
|
|
|
+ //通过任务id查询任务详情
|
|
|
+ public JSONArray getRenwuxiangqing(String rwid){
|
|
|
+
|
|
|
+ //获取属于该区域名称的项目集id
|
|
|
+ OkHttpClient client1 = new OkHttpClient().newBuilder()
|
|
|
+ .build();
|
|
|
+ Request request1 = new Request.Builder()
|
|
|
+ .url("https://open.teambition.com/api/v3/task/query?taskId="+ rwid)
|
|
|
+ .method("GET", null)
|
|
|
+ .addHeader("Authorization", "Bearer " + accessTokenService.getAppToken())
|
|
|
+ .addHeader("X-Tenant-Id", tbOrganizationId)
|
|
|
+ .addHeader("X-Tenant-Type", "organization")
|
|
|
+ .build();
|
|
|
+
|
|
|
+ int code1 = 0;
|
|
|
+ JSONArray result1 = null;
|
|
|
+ try {
|
|
|
+ Response response1 = client1.newCall(request1).execute();
|
|
|
+ String bodyStr1 = response1.body().string();
|
|
|
+ JSONObject jsonObject1 = JSON.parseObject(bodyStr1);
|
|
|
+ System.out.println("返回体body:" + jsonObject1);
|
|
|
+ code1 = jsonObject1.getInteger("code");
|
|
|
+
|
|
|
+ result1 = jsonObject1.getJSONArray("result");
|
|
|
+ System.out.println("result===>" + result1);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ System.out.println("查询【通过任务id查询所属项目id】接口返回的状态码(200成功,400异常):" + code1);
|
|
|
+
|
|
|
+ //任务类型id
|
|
|
+// String sfcId = null;
|
|
|
+// if (!result1.isEmpty() || result1 != null) {
|
|
|
+// JSONObject jsonObject1 = result1.getJSONObject(0);
|
|
|
+//
|
|
|
+// //任务类型id
|
|
|
+// sfcId = jsonObject1.getString("sfcId");
|
|
|
+// System.out.println("任务类型id:" + sfcId);
|
|
|
+// }
|
|
|
+
|
|
|
+ return result1;
|
|
|
+ }
|
|
|
+
|
|
|
+ //通过任务类型id搜索项目任务类型
|
|
|
+ public JSONArray getQiyeTaskType(String projectId, String rwlxid){
|
|
|
+
|
|
|
+ //获取属于该区域名称的项目集id
|
|
|
+ OkHttpClient client1 = new OkHttpClient().newBuilder()
|
|
|
+ .build();
|
|
|
+ Request request1 = new Request.Builder()
|
|
|
+ .url("https://open.teambition.com/api/v3/project/"+ projectId +"/scenariofieldconfig/search?sfcIds="+ rwlxid)
|
|
|
+ .method("GET", null)
|
|
|
+ .addHeader("Authorization", "Bearer " + accessTokenService.getAppToken())
|
|
|
+ .addHeader("X-Tenant-Id", tbOrganizationId)
|
|
|
+ .addHeader("X-Tenant-Type", "organization")
|
|
|
+ .build();
|
|
|
+
|
|
|
+ int code1 = 0;
|
|
|
+ JSONArray result1 = null;
|
|
|
+ try {
|
|
|
+ Response response1 = client1.newCall(request1).execute();
|
|
|
+ String bodyStr1 = response1.body().string();
|
|
|
+ JSONObject jsonObject1 = JSON.parseObject(bodyStr1);
|
|
|
+ System.out.println("返回体body:" + jsonObject1);
|
|
|
+ code1 = jsonObject1.getInteger("code");
|
|
|
+
|
|
|
+ result1 = jsonObject1.getJSONArray("result");
|
|
|
+ System.out.println("result===>" + result1);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ System.out.println("查询【通过任务类型id搜索项目任务类型】接口返回的状态码(200成功,400异常):" + code1);
|
|
|
+
|
|
|
+ return result1;
|
|
|
+ }
|
|
|
+
|
|
|
+ //根据任务自定义字段id,查询企业「自定义字段」名称
|
|
|
+ public String getTaskCustomfieldName(String taskCustomfieldId){
|
|
|
+
|
|
|
+ OkHttpClient client1 = new OkHttpClient().newBuilder()
|
|
|
+ .build();
|
|
|
+ Request request1 = new Request.Builder()
|
|
|
+ .url("https://open.teambition.com/api/v3/customfield/search?cfIds=" + taskCustomfieldId)
|
|
|
+ .method("GET", null)
|
|
|
+ .addHeader("Authorization", "Bearer " + accessTokenService.getAppToken())
|
|
|
+ .addHeader("X-Tenant-Id", tbOrganizationId)
|
|
|
+ .addHeader("X-Tenant-Type", "organization")
|
|
|
+ .build();
|
|
|
+
|
|
|
+ int code1 = 0;
|
|
|
+ JSONArray result1 = null;
|
|
|
+ try {
|
|
|
+ Response response1 = client1.newCall(request1).execute();
|
|
|
+ String bodyStr1 = response1.body().string();
|
|
|
+ JSONObject jsonObject1 = JSON.parseObject(bodyStr1);
|
|
|
+ System.out.println("返回体body:" + jsonObject1);
|
|
|
+ code1 = jsonObject1.getInteger("code");
|
|
|
+
|
|
|
+ result1 = jsonObject1.getJSONArray("result");
|
|
|
+ System.out.println("result===>" + result1);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ System.out.println("查询【根据任务自定义字段id,查询企业「自定义字段」名称】接口返回的状态码(200成功,400异常):" + code1);
|
|
|
+
|
|
|
+ //自定义字段名称
|
|
|
+ String xmztName = null;
|
|
|
+ if (!result1.isEmpty() || result1 != null) {
|
|
|
+ for (int i = 0; i < result1.size(); i++) {
|
|
|
+ JSONObject jsonObject1 = result1.getJSONObject(i);
|
|
|
+ //自定义字段名称
|
|
|
+ xmztName = jsonObject1.getString("name");
|
|
|
+ System.out.println("自定义字段名称:" + xmztName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return xmztName;
|
|
|
+ }
|
|
|
+
|
|
|
+ //更新项目自定义字段值
|
|
|
+ public JSONObject updateXmCustomField(String operatorId, String xmid, String customfieldId, List listTitle){
|
|
|
+
|
|
|
+ Map mapAll = new HashMap();
|
|
|
+ mapAll.put("customfieldId", customfieldId);
|
|
|
+ mapAll.put("value", listTitle);
|
|
|
+
|
|
|
+ String mapStr = JSON.toJSONString(mapAll);
|
|
|
+ System.out.println("封装更新的字段参数:" + mapStr);
|
|
|
+
|
|
|
+
|
|
|
+ OkHttpClient client = new OkHttpClient().newBuilder()
|
|
|
+ .build();
|
|
|
+ MediaType mediaType = MediaType.parse("application/json");
|
|
|
+ RequestBody body = RequestBody.create(mediaType, mapStr);
|
|
|
+ Request request = new Request.Builder()
|
|
|
+ .url("https://open.teambition.com/api/v3/project/"+ xmid +"/status/customfield/create")
|
|
|
+ .method("POST", body)
|
|
|
+ .addHeader("x-operator-id", operatorId)
|
|
|
+ .addHeader("Authorization", "Bearer " + accessTokenService.getAppToken())
|
|
|
+ .addHeader("X-Tenant-Id", tbOrganizationId)
|
|
|
+ .addHeader("X-Tenant-Type", "organization")
|
|
|
+ .addHeader("Content-Type", "application/json")
|
|
|
+ .build();
|
|
|
+
|
|
|
+ JSONObject jsonObject1 = new JSONObject();
|
|
|
+ try {
|
|
|
+ Response response1 = client.newCall(request).execute();
|
|
|
+ String bodyStr1 = response1.body().string();
|
|
|
+ jsonObject1 = JSON.parseObject(bodyStr1);
|
|
|
+ System.out.println("返回体body:" + jsonObject1);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ return jsonObject1;
|
|
|
+ }
|
|
|
+
|
|
|
+ //根据项目id,查询项目概览自定义字段列表中「自定义字段」id
|
|
|
+ public String getXiangmuZidingyiziduanid(String xmid, String zidingyiziduanName){
|
|
|
+
|
|
|
+ OkHttpClient client1 = new OkHttpClient().newBuilder()
|
|
|
+ .build();
|
|
|
+ Request request1 = new Request.Builder()
|
|
|
+ .url("https://open.teambition.com/api/v3/project/"+ xmid +"/status/customfield/list")
|
|
|
+ .method("GET", null)
|
|
|
+ .addHeader("Authorization", "Bearer " + accessTokenService.getAppToken())
|
|
|
+ .addHeader("X-Tenant-Id", tbOrganizationId)
|
|
|
+ .addHeader("X-Tenant-Type", "organization")
|
|
|
+ .build();
|
|
|
+
|
|
|
+ int code1 = 0;
|
|
|
+ JSONArray result1 = null;
|
|
|
+ try {
|
|
|
+ Response response1 = client1.newCall(request1).execute();
|
|
|
+ String bodyStr1 = response1.body().string();
|
|
|
+ JSONObject jsonObject1 = JSON.parseObject(bodyStr1);
|
|
|
+ System.out.println("返回体body:" + jsonObject1);
|
|
|
+ code1 = jsonObject1.getInteger("code");
|
|
|
+
|
|
|
+ result1 = jsonObject1.getJSONArray("result");
|
|
|
+ System.out.println("result===>" + result1);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ System.out.println("查询【根据项目id,查询项目概览自定义字段列表中「自定义字段」id】接口返回的状态码(200成功,400异常):" + code1);
|
|
|
+
|
|
|
+ //自定义字段id
|
|
|
+ String xmzdyzdId = null;
|
|
|
+ if (!result1.isEmpty() || result1 != null) {
|
|
|
+ for (int i = 0; i < result1.size(); i++) {
|
|
|
+ JSONObject jsonObject1 = result1.getJSONObject(i);
|
|
|
+ //自定义字段名称
|
|
|
+ String xmztName = jsonObject1.getString("name");
|
|
|
+ System.out.println("自定义字段名称:" + xmztName);
|
|
|
+
|
|
|
+ if (xmztName.equals(zidingyiziduanName)){
|
|
|
+ //自定义字段id
|
|
|
+ xmzdyzdId = jsonObject1.getString("cfId");
|
|
|
+ System.out.println("自定义字段id:" + xmzdyzdId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return xmzdyzdId;
|
|
|
+ }
|
|
|
+
|
|
|
+ private final ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据Excel文档梳理的字段名称与字段类型映射字典
|
|
|
+ */
|
|
|
+ private static final Map<String, String> FIELD_NAME_TYPE_MAPPING = new HashMap<>();
|
|
|
+ static {
|
|
|
+ FIELD_NAME_TYPE_MAPPING.put("覆盖国家", "多选");
|
|
|
+ FIELD_NAME_TYPE_MAPPING.put("是否白标", "单选");
|
|
|
+ FIELD_NAME_TYPE_MAPPING.put("渠道能力", "多选");
|
|
|
+ FIELD_NAME_TYPE_MAPPING.put("应用站点", "多选");
|
|
|
+ FIELD_NAME_TYPE_MAPPING.put("FBD", "成员");
|
|
|
+ FIELD_NAME_TYPE_MAPPING.put("FBD渠道协作人", "成员");
|
|
|
+ FIELD_NAME_TYPE_MAPPING.put("产品经理", "成员");
|
|
|
+ FIELD_NAME_TYPE_MAPPING.put("研发", "成员");
|
|
|
+ FIELD_NAME_TYPE_MAPPING.put("合规", "成员");
|
|
|
+ FIELD_NAME_TYPE_MAPPING.put("客资", "成员");
|
|
|
+ FIELD_NAME_TYPE_MAPPING.put("风控", "成员");
|
|
|
+ FIELD_NAME_TYPE_MAPPING.put("运营", "成员");
|
|
|
+ FIELD_NAME_TYPE_MAPPING.put("技术支持", "成员");
|
|
|
+ FIELD_NAME_TYPE_MAPPING.put("财务", "成员");
|
|
|
+ FIELD_NAME_TYPE_MAPPING.put("法务", "成员");
|
|
|
+ FIELD_NAME_TYPE_MAPPING.put("税务", "成员");
|
|
|
+ FIELD_NAME_TYPE_MAPPING.put("组别", "单选");
|
|
|
+ FIELD_NAME_TYPE_MAPPING.put("渠道类型", "单选");
|
|
|
+ FIELD_NAME_TYPE_MAPPING.put("国家和能力", "层级选择");
|
|
|
+ FIELD_NAME_TYPE_MAPPING.put("商务首次沟通日期", "日期");
|
|
|
+ FIELD_NAME_TYPE_MAPPING.put("NDA完成日期", "日期");
|
|
|
+ FIELD_NAME_TYPE_MAPPING.put("FBD预审完成日期", "日期");
|
|
|
+ FIELD_NAME_TYPE_MAPPING.put("商务合同签署完成日期", "日期");
|
|
|
+ FIELD_NAME_TYPE_MAPPING.put("立项上会日期", "日期");
|
|
|
+ FIELD_NAME_TYPE_MAPPING.put("PRD评审完成日期", "日期");
|
|
|
+ FIELD_NAME_TYPE_MAPPING.put("技术方案评审完成日期", "日期");
|
|
|
+ FIELD_NAME_TYPE_MAPPING.put("预计提测日期", "日期");
|
|
|
+ FIELD_NAME_TYPE_MAPPING.put("预计发布日期", "日期");
|
|
|
+ FIELD_NAME_TYPE_MAPPING.put("实际提测日期", "日期");
|
|
|
+ FIELD_NAME_TYPE_MAPPING.put("实际发布日期", "日期");
|
|
|
+ FIELD_NAME_TYPE_MAPPING.put("白名单对客日期", "日期");
|
|
|
+ FIELD_NAME_TYPE_MAPPING.put("全量对客日期", "日期");
|
|
|
+ FIELD_NAME_TYPE_MAPPING.put("立项文件夹", "钉钉文档");
|
|
|
+ FIELD_NAME_TYPE_MAPPING.put("优先级", "单选");
|
|
|
+ FIELD_NAME_TYPE_MAPPING.put("PRD", "钉钉文档");
|
|
|
+ FIELD_NAME_TYPE_MAPPING.put("技术方案", "钉钉文档");
|
|
|
+ FIELD_NAME_TYPE_MAPPING.put("业务价值", "数字");
|
|
|
+ FIELD_NAME_TYPE_MAPPING.put("产研复杂度", "数字");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 任务类型与项目概览字段类型映射字典
|
|
|
+ */
|
|
|
+ private static final Map<String, String> FIELD_USER_TYPE_MAPPING = new HashMap<>();
|
|
|
+ static {
|
|
|
+ FIELD_USER_TYPE_MAPPING.put("渠道商务里程碑", "FBD");
|
|
|
+ FIELD_USER_TYPE_MAPPING.put("立项评估-产品评估", "产品经理");
|
|
|
+ FIELD_USER_TYPE_MAPPING.put("技术开发发布里程碑", "研发");
|
|
|
+ FIELD_USER_TYPE_MAPPING.put("立项评估-合规评估", "合规");
|
|
|
+ FIELD_USER_TYPE_MAPPING.put("立项评估-客资评估", "客资");
|
|
|
+ FIELD_USER_TYPE_MAPPING.put("渠道管理-风控验证", "风控");
|
|
|
+ FIELD_USER_TYPE_MAPPING.put("立项评估-运营评估", "运营");
|
|
|
+ FIELD_USER_TYPE_MAPPING.put("渠道管理-连通性测试", "技术支持");
|
|
|
+ FIELD_USER_TYPE_MAPPING.put("立项评估-财务评估", "财务");
|
|
|
+ FIELD_USER_TYPE_MAPPING.put("立项评估-法务评估", "法务");
|
|
|
+ FIELD_USER_TYPE_MAPPING.put("立项评估-税务评估(白标必须)", "税务");
|
|
|
+ }
|
|
|
+ //获取对应类型的方法
|
|
|
+ public static String getTypeByFieldName(String fieldName) {
|
|
|
+ // 使用 .get() 方法获取值
|
|
|
+ return FIELD_USER_TYPE_MAPPING.get(fieldName);
|
|
|
+ }
|
|
|
+
|
|
|
+ //接收TB的WebHook推送过来的数据
|
|
|
+ @Async
|
|
|
+ @Override
|
|
|
+ public R callBack(Map body) throws Exception{
|
|
|
+
|
|
|
+ String s = JSON.toJSONString(body);
|
|
|
+ System.out.println("TB推送过来的数据:" + s);
|
|
|
+
|
|
|
+ //解析TB推送过来的数据
|
|
|
+ JSONObject jsonObject = JSON.parseObject(s);
|
|
|
+ String event = jsonObject.getString("event");
|
|
|
+ System.out.println("事件名称「推送类型」:" + event);
|
|
|
+ String timestamp = jsonObject.getString("timestamp");
|
|
|
+ System.out.println("事件触发时间「毫秒级时间戳」:" + timestamp);
|
|
|
+
|
|
|
+// 休眠10秒
|
|
|
+// try {
|
|
|
+// Thread.sleep(10000);
|
|
|
+// }catch (InterruptedException e){
|
|
|
+// e.printStackTrace();
|
|
|
+// }
|
|
|
+
|
|
|
+ if (event.equals("v3.task.customfield.update")) {//======任务自定义字段更新======
|
|
|
+ log.info("【任务自定义字段更新】,开始执行===》");
|
|
|
+ JSONObject data = jsonObject.getJSONObject("data");
|
|
|
+ System.out.println("任务信息data:" + data);
|
|
|
+
|
|
|
+ //项目id
|
|
|
+// String xmid = data.getString("projectId");
|
|
|
+// System.out.println("项目id:" + xmid);
|
|
|
+ //任务id
|
|
|
+ String taskId = data.getString("taskId");
|
|
|
+ System.out.println("任务id:" + taskId);
|
|
|
+ //操作者id
|
|
|
+ String operatorId = data.getString("creatorId");
|
|
|
+ System.out.println("操作者id:" + operatorId);
|
|
|
+ //任务自定义字段id
|
|
|
+ String customfieldId = data.getString("customfieldId");
|
|
|
+ System.out.println("任务自定义字段id:" + customfieldId);
|
|
|
+ //当前字段旧内容
|
|
|
+ JSONArray customfieldOldValue = data.getJSONArray("customfieldOldValue");
|
|
|
+ System.out.println("当前字段旧内容[]:" + customfieldOldValue);
|
|
|
+ //当前字段新内容
|
|
|
+ JSONArray customfieldValue = data.getJSONArray("customfieldValue");
|
|
|
+ System.out.println("当前字段新内容[]:" + customfieldValue);
|
|
|
+
|
|
|
+ /*根据任务id查询任务所属的项目id*/
|
|
|
+ JSONArray renwuxiangqing = getRenwuxiangqing(taskId);
|
|
|
+ //项目id
|
|
|
+ String projectId = null;
|
|
|
+ if (!renwuxiangqing.isEmpty() || renwuxiangqing != null) {
|
|
|
+ JSONObject jsonObject1 = renwuxiangqing.getJSONObject(0);
|
|
|
+ //项目id
|
|
|
+ projectId = jsonObject1.getString("projectId");
|
|
|
+ System.out.println("项目id:" + projectId);
|
|
|
+ }
|
|
|
+ if (projectId == null){
|
|
|
+ log.error("根据任务id查询所属项目id为空");
|
|
|
+ return R.error().message("根据任务id查询所属项目id为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ /*根据任务自定义字段id,查询企业「自定义字段」名称*/
|
|
|
+ String taskName = getTaskCustomfieldName(customfieldId);
|
|
|
+ System.out.println("任务中当前更新的字段名称:" + taskName);
|
|
|
+ if (!FIELD_NAME_TYPE_MAPPING.containsKey(taskName)) {
|
|
|
+ log.error("非文档映射内的字段,忽略");
|
|
|
+ return R.error().message("非文档映射内的字段,忽略"); // 非文档映射内的字段,忽略
|
|
|
+ }
|
|
|
+
|
|
|
+ /*根据项目id,查询项目概览自定义字段列表中「自定义字段」id*/
|
|
|
+ String xmzdyzdid = getXiangmuZidingyiziduanid(projectId, taskName);
|
|
|
+ if (xmzdyzdid != null){
|
|
|
+ log.info("【根据项目id,查询项目概览自定义字段列表中「自定义字段」id】不为空,开始执行后续业务===》");
|
|
|
+ /*更新项目概览自定义字段*/
|
|
|
+ JSONObject jsonObject2 = updateXmCustomField(operatorId, projectId, xmzdyzdid, customfieldValue);
|
|
|
+ int code = jsonObject2.getInteger("code");
|
|
|
+ System.out.println("【更新项目自定义字段值】接口返回的状态码(200成功,400异常):" + code);
|
|
|
+ if (code == 200){
|
|
|
+ log.info("【更新项目自定义字段值】成功!");
|
|
|
+ return R.ok().message("更新项目自定义字段值成功");
|
|
|
+ }else {
|
|
|
+ String errorMessage = jsonObject2.getString("errorMessage");
|
|
|
+ System.out.println("【更新项目自定义字段值】接口返回的异常错误信息:" + errorMessage);
|
|
|
+
|
|
|
+ log.error("【更新项目自定义字段值】失败!");
|
|
|
+ return R.error().message("更新项目自定义字段值失败,异常错误信息【" + errorMessage + "】");
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ log.error("【根据项目id,查询项目概览自定义字段列表中「自定义字段」id】为空,结束执行后续业务!");
|
|
|
+ return R.error().message("根据项目id,查询项目概览自定义字段列表中「自定义字段」id为空,结束执行后续业务!");
|
|
|
+ }
|
|
|
+ }else if (event.equals("v3.task.executor.update")){//======任务执行者更新======
|
|
|
+ log.info("【任务执行者更新】,开始执行===》");
|
|
|
+ JSONObject data = jsonObject.getJSONObject("data");
|
|
|
+ System.out.println("任务信息data:" + data);
|
|
|
+
|
|
|
+ //任务id
|
|
|
+ String taskId = data.getString("taskId");
|
|
|
+ System.out.println("任务id:" + taskId);
|
|
|
+ //操作者id
|
|
|
+ String operatorId = data.getString("creatorId");
|
|
|
+ System.out.println("操作者id:" + operatorId);
|
|
|
+ //更新后的执行者id
|
|
|
+ String executorId = data.getString("executorId") != null ? data.getString("executorId") : "";
|
|
|
+ System.out.println("更新后的执行者id:" + executorId);
|
|
|
+ /*根据任务id查询任务所属的项目id*/
|
|
|
+ JSONArray renwuxiangqing = getRenwuxiangqing(taskId);
|
|
|
+ //项目id
|
|
|
+ String projectId = null;
|
|
|
+ if (!renwuxiangqing.isEmpty() || renwuxiangqing != null) {
|
|
|
+ JSONObject jsonObject1 = renwuxiangqing.getJSONObject(0);
|
|
|
+ //项目id
|
|
|
+ projectId = jsonObject1.getString("projectId");
|
|
|
+ System.out.println("项目id:" + projectId);
|
|
|
+ }
|
|
|
+ if (projectId == null){
|
|
|
+ log.error("根据任务id查询所属项目id为空");
|
|
|
+ return R.error().message("根据任务id查询所属项目id为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ /*根据任务id查询任务类型*/
|
|
|
+ JSONArray renwuxiangqingArray = getRenwuxiangqing(taskId);
|
|
|
+ //任务类型id
|
|
|
+ String renwuleixingid = null;
|
|
|
+ if (!renwuxiangqingArray.isEmpty() || renwuxiangqingArray != null) {
|
|
|
+ JSONObject jsonObject1 = renwuxiangqingArray.getJSONObject(0);
|
|
|
+ //当前任务类型id
|
|
|
+ renwuleixingid = jsonObject1.getString("sfcId");
|
|
|
+ System.out.println("当前任务类型id:" + renwuleixingid);
|
|
|
+ /*通过任务类型id搜索项目任务类型*/
|
|
|
+ JSONArray qiyeTaskType = getQiyeTaskType(projectId, renwuleixingid);
|
|
|
+ //任务类型名称
|
|
|
+ String sfcName = null;
|
|
|
+ if (!qiyeTaskType.isEmpty() || qiyeTaskType != null) {
|
|
|
+ JSONObject jsonObject3 = qiyeTaskType.getJSONObject(0);
|
|
|
+ //任务类型名称
|
|
|
+ sfcName = jsonObject3.getString("name");
|
|
|
+ System.out.println("任务类型名称:" + sfcName);
|
|
|
+ if (!FIELD_USER_TYPE_MAPPING.containsKey(sfcName)) {
|
|
|
+ log.error("非文档映射内的任务类型,忽略");
|
|
|
+ return R.error().message("非文档映射内的任务类型,忽略"); // 非文档映射内的字段,忽略
|
|
|
+ }else {
|
|
|
+ String typeByFieldName = getTypeByFieldName(sfcName);
|
|
|
+ log.info("当前任务类型匹配的项目概览成员字段名称:" + typeByFieldName);
|
|
|
+
|
|
|
+ /*根据项目id,查询项目概览自定义字段列表中「自定义字段」id*/
|
|
|
+ String xmzdyzdid = getXiangmuZidingyiziduanid(projectId, typeByFieldName);
|
|
|
+ if (xmzdyzdid != null){
|
|
|
+ log.info("【根据项目id,查询项目概览自定义字段列表中「自定义字段」id】不为空,开始执行后续业务===》");
|
|
|
+ /*更新项目概览自定义字段*/
|
|
|
+ Map mapTitle = new HashMap();
|
|
|
+ mapTitle.put("id", executorId);
|
|
|
+ String title = null;
|
|
|
+ if (!executorId.equals("")){
|
|
|
+ title = "系统同步";
|
|
|
+ }
|
|
|
+ mapTitle.put("title", title);//TB成员字段传TBuserId,title默认空即可,也可匹配到TB中的人员进行写入成员字段
|
|
|
+ List listTitle = new ArrayList();
|
|
|
+ listTitle.add(mapTitle);
|
|
|
+ JSONObject jsonObject2 = updateXmCustomField(operatorId, projectId, xmzdyzdid, listTitle);
|
|
|
+ int code = jsonObject2.getInteger("code");
|
|
|
+ System.out.println("【更新项目自定义字段值】接口返回的状态码(200成功,400异常):" + code);
|
|
|
+ if (code == 200){
|
|
|
+ log.info("【更新项目自定义字段值】成功!");
|
|
|
+ return R.ok().message("更新项目自定义字段值成功");
|
|
|
+ }else {
|
|
|
+ String errorMessage = jsonObject2.getString("errorMessage");
|
|
|
+ System.out.println("【更新项目自定义字段值】接口返回的异常错误信息:" + errorMessage);
|
|
|
+
|
|
|
+ log.error("【更新项目自定义字段值】失败!");
|
|
|
+ return R.error().message("更新项目自定义字段值失败,异常错误信息【" + errorMessage + "】");
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ log.error("【根据项目id,查询项目概览自定义字段列表中「自定义字段」id】为空,结束执行后续业务!");
|
|
|
+ return R.error().message("根据项目id,查询项目概览自定义字段列表中「自定义字段」id为空,结束执行后续业务!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ log.error("通过任务类型id搜索企业任务类型名称为空!");
|
|
|
+ return R.error().message("通过任务类型id搜索企业任务类型名称为空!");
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ log.error("根据任务id查询任务类型为空!");
|
|
|
+ return R.error().message("根据任务id查询任务类型为空!");
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ log.error("当前事件不属于任务自定义字段/任务执行者更新,结束执行后续业务!");
|
|
|
+ return R.error().message("当前事件不属于任务自定义字段/任务执行者更新,结束执行后续业务!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|