Commit ef75b2f3 by HlQ

[add] 使用 RestClient 替换 Hutool 的 http 请求工具类

[fix] 修复项目合并时,集团 id 错误的问题
1 parent f18e25ef
package vion.config;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestClient;
/**
* @author HlQ
* @date 2024/7/19
*/
@Configuration
@Slf4j
public class RestClientConfig {
@Bean(name = "bongRestClient")
public RestClient getBongRestClient() {
return RestClient.builder()
.baseUrl("https://proapi.xbongbong.com")
.build();
}
@Bean(name = "oDingRestClient")
public RestClient getODingRestClient() {
return RestClient.builder()
.baseUrl("https://oapi.dingtalk.com")
.build();
}
@Bean(name = "dingRestClient")
public RestClient getdingRestClient() {
return RestClient.builder()
.baseUrl("https://api.dingtalk.com")
.build();
}
}
......@@ -10,15 +10,15 @@ import org.dromara.hutool.core.math.NumberUtil;
import org.dromara.hutool.core.text.StrUtil;
import org.dromara.hutool.core.util.ObjUtil;
import org.dromara.hutool.crypto.SecureUtil;
import org.dromara.hutool.http.client.Request;
import org.dromara.hutool.http.meta.Method;
import org.dromara.hutool.json.JSONObject;
import org.dromara.hutool.json.JSONUtil;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.RestClient;
import vion.constant.RedisKeyEnum;
import vion.model.Dictionary;
import vion.model.*;
......@@ -46,6 +46,7 @@ public class ContractRunner {
private final IPaymentService paymentService;
private final IRContractProductService contractProductService;
private final RedissonClient redissonClient;
private final RestClient bongRestClient;
@Value("${xbongbong.token}")
private String token;
......@@ -75,12 +76,13 @@ public class ContractRunner {
.set("corpid", corpId)
.set("formId", 8429903)
.set("pageSize", 100);
var res = Request.of("https://proapi.xbongbong.com/pro/v2/api/contract/list")
var jobO = bongRestClient.post()
.uri("/pro/v2/api/contract/list")
.contentType(MediaType.APPLICATION_JSON)
.header("sign", SecureUtil.sha256(json.toString() + token))
.body(json.toString())
.method(Method.POST)
.send();
var jobO = JSONUtil.parseObj(res.bodyStr());
.retrieve()
.body(JSONObject.class);
if (jobO.getInt("code") != 1) {
log.error("获取合同列表失败,错误原因:{}", jobO);
return;
......@@ -115,12 +117,13 @@ public class ContractRunner {
.set("formId", 8429903)
.set("page", i)
.set("pageSize", 100);
var resR = Request.of("https://proapi.xbongbong.com/pro/v2/api/contract/list")
var jobR = bongRestClient.post()
.uri("/pro/v2/api/contract/list")
.contentType(MediaType.APPLICATION_JSON)
.header("sign", SecureUtil.sha256(jsonR.toString() + token))
.body(jsonR.toString())
.method(Method.POST)
.send();
var jobR = JSONUtil.parseObj(resR.bodyStr());
.body(json.toString())
.retrieve()
.body(JSONObject.class);
var jsonArrR = jobR.getJSONObject("result").getJSONArray("list");
var dataIdSetR = jsonArrR.stream().map(v -> JSONUtil.parseObj(v).getInt("dataId")).collect(Collectors.toSet());
dataIdSet.addAll(dataIdSetR);
......@@ -139,12 +142,13 @@ public class ContractRunner {
var json1 = JSONUtil.ofObj()
.set("corpid", corpId)
.set("dataId", dataId);
var res1 = Request.of("https://proapi.xbongbong.com/pro/v2/api/contract/detail")
var jobj1 = bongRestClient.post()
.uri("/pro/v2/api/contract/detail")
.contentType(MediaType.APPLICATION_JSON)
.header("sign", SecureUtil.sha256(json1.toString() + token))
.body(json1.toString())
.method(Method.POST)
.send();
var jobj1 = JSONUtil.parseObj(res1.bodyStr());
.retrieve()
.body(JSONObject.class);
if (jobj1.getInt("code") != 1) {
log.error("获取合同详情失败,错误原因:{}", jobj1);
return;
......@@ -159,6 +163,7 @@ public class ContractRunner {
contract.setMaintainSdate(Opt.ofNullable(jsonObj1.getLong("date_4")).map(sec -> DateUtil.date(sec * 1000)).orElse(null));
contract.setMaintainEdate(Opt.ofNullable(jsonObj1.getLong("date_5")).map(sec -> DateUtil.date(sec * 1000)).orElse(null));
String warrantyPeriod = Opt.ofNullable(jsonObj1.getJSONObject("text_23")).map(wp -> wp.getStr("text")).orElse("");
// 23 质保 没有维保开始时间和结束时间 25 维保
if (StrUtil.isNotBlank(warrantyPeriod) && warrantyPeriod.contains("个月")) {
String substring = warrantyPeriod.substring(0, (warrantyPeriod.length() - 2));
contract.setWarrantyPeriod(Integer.parseInt(substring));
......@@ -400,13 +405,13 @@ public class ContractRunner {
.set("page", 1)
.set("pageSize", 100);
var res = Request.of("https://proapi.xbongbong.com/pro/v2/api/product/list")
var jobj = bongRestClient.post()
.uri("/pro/v2/api/product/list")
.contentType(MediaType.APPLICATION_JSON)
.header("sign", SecureUtil.sha256(json.toString() + token))
.body(json.toString())
.method(Method.POST)
.send();
var body = res.bodyStr();
var jobj = JSONUtil.parseObj(body);
.retrieve()
.body(JSONObject.class);
if (jobj.getInt("code") != 1) {
log.error("获取CRM产品列表失败:{}", jobj);
return List.of();
......@@ -420,13 +425,13 @@ public class ContractRunner {
.set("corpid", corpId)
.set("page", i)
.set("pageSize", 100);
var res1 = Request.of("https://proapi.xbongbong.com/pro/v2/api/product/list")
.header("sign", SecureUtil.sha256(json1 + token))
.body(json1.toString())
.method(Method.POST)
.send();
var body1 = res1.bodyStr();
var jobj1 = JSONUtil.parseObj(body1);
var jobj1 = bongRestClient.post()
.uri("/pro/v2/api/product/list")
.contentType(MediaType.APPLICATION_JSON)
.header("sign", SecureUtil.sha256(json1.toString() + token))
.body(json.toString())
.retrieve()
.body(JSONObject.class);
if (jobj1.getInt("code") != 1) {
log.error("获取CRM产品列表失败:{}", jobj1);
return List.of();
......
......@@ -29,14 +29,14 @@ import org.dromara.hutool.core.text.StrUtil;
import org.dromara.hutool.core.util.ObjUtil;
import org.dromara.hutool.crypto.SecureUtil;
import org.dromara.hutool.http.client.HttpDownloader;
import org.dromara.hutool.http.client.Request;
import org.dromara.hutool.http.meta.Method;
import org.dromara.hutool.json.JSONObject;
import org.dromara.hutool.json.JSONUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.RestClient;
import vion.dto.ContractDTO;
import vion.dto.RContractTeamDTO;
import vion.mapper.ContractMapper;
......@@ -75,6 +75,7 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
private final SettlementDiffMapper settlementDiffMapper;
private final DingMod dingMod;
private final Converter converter;
private final RestClient bongRestClient;
@Value("${fileUrl:}")
private String fileUrl;
......@@ -527,15 +528,15 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
@Override
public String createContract(String contractJson) {
var sha256 = SecureUtil.sha256(contractJson + token);
var res = Request.of("https://proapi.xbongbong.com/pro/v2/api/contract/list")
var jobj = bongRestClient.post()
.uri("/pro/v2/api/contract/list")
.contentType(MediaType.APPLICATION_JSON)
.header("sign", sha256)
.body(contractJson)
.method(Method.POST)
.send();
var body = res.bodyStr();
var jobj = JSONUtil.parseObj(body);
.retrieve()
.body(JSONObject.class);
if (jobj.getInt("code") != 1) {
log.error("调用CRM接口创建合同失败,错误原因:{}", body);
log.error("调用CRM接口创建合同失败,错误原因:{}", jobj);
return "创建合同失败";
}
return "合同创建成功";
......@@ -559,15 +560,15 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
.set("pageSize", pageSize)
.set("conditions", conditions);
var res = Request.of("https://proapi.xbongbong.com/pro/v2/api/product/list")
var jobj = bongRestClient.post()
.uri("/pro/v2/api/product/list")
.contentType(MediaType.APPLICATION_JSON)
.header("sign", SecureUtil.sha256(json.toString() + token))
.body(json.toString())
.method(Method.POST)
.send();
var body = res.bodyStr();
var jobj = JSONUtil.parseObj(body);
.retrieve()
.body(JSONObject.class);
if (jobj.getInt("code") != 1) {
log.error("调用CRM接口获取产品列表失败,错误原因:{}", body);
log.error("调用CRM接口获取产品列表失败,错误原因:{}", jobj);
return JSONUtil.ofObj();
}
return JSONUtil.ofObj().set("records", jobj.getJSONObject("result").getJSONArray("list"))
......@@ -597,12 +598,13 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
.set("corpid", corpId)
.set("formId", 8429903)
.set("pageSize", 100);
var res = Request.of("https://proapi.xbongbong.com/pro/v2/api/contract/list")
var jobO = bongRestClient.post()
.uri("/pro/v2/api/contract/list")
.contentType(MediaType.APPLICATION_JSON)
.header("sign", SecureUtil.sha256(json.toString() + token))
.body(json.toString())
.method(Method.POST)
.send();
var jobO = JSONUtil.parseObj(res.bodyStr());
.retrieve()
.body(JSONObject.class);
if (jobO.getInt("code") != 1) {
var errorInfo = StrUtil.format("获取合同列表失败,错误原因:{}", jobO);
log.error(errorInfo);
......@@ -627,12 +629,14 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
.set("formId", 8429903)
.set("page", i)
.set("pageSize", 100);
var resR = Request.of("https://proapi.xbongbong.com/pro/v2/api/contract/list")
var jobR = bongRestClient.post()
.uri("/pro/v2/api/contract/list")
.contentType(MediaType.APPLICATION_JSON)
.header("sign", SecureUtil.sha256(jsonR.toString() + token))
.body(jsonR.toString())
.method(Method.POST)
.send();
var jobR = JSONUtil.parseObj(resR.bodyStr());
.retrieve()
.body(JSONObject.class);
var jsonArrR = jobR.getJSONObject("result").getJSONArray("list");
var fileListR = jsonArrR.stream().map(v -> {
var fileArr = JSONUtil.parseObj(v).getJSONObject("data").getJSONArray("file_1");
......@@ -649,7 +653,6 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
var contractId2Sha256Map = fileInfoList.stream().collect(Collectors.groupingBy(FileInfo::getContractId,
Collectors.mapping(FileInfo::getSha256, Collectors.toList())));
List<FileInfo> saveFileInfoList = new ArrayList<>();
for (JSONObject entries : fileList) {
var contractNo = entries.getStr("contractNo");
var fileArr = entries.getJSONArray("fileArr");
......@@ -663,6 +666,7 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
continue;
}
List<FileInfo> saveFileInfoList = new ArrayList<>();
for (Object o : fileArr) {
var fileObj = JSONUtil.parseObj(o);
var filename = fileObj.getStr("filename");
......@@ -688,8 +692,8 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
fileInfo.setUploader("销帮帮同步");
saveFileInfoList.add(fileInfo);
}
fileService.saveBatch(saveFileInfoList);
}
fileService.saveBatch(saveFileInfoList);
log.info("同步销帮帮合同文件[完成]");
return "销帮帮合同文件同步完成,请核对已同步文件!";
}
......@@ -869,12 +873,13 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
.set("corpid", corpId)
.set("formId", 8429903)
.set("pageSize", 100);
var res = Request.of("https://proapi.xbongbong.com/pro/v2/api/contract/list")
var jobO = bongRestClient.post()
.uri("/pro/v2/api/contract/list")
.contentType(MediaType.APPLICATION_JSON)
.header("sign", SecureUtil.sha256(json.toString() + token))
.body(json.toString())
.method(Method.POST)
.send();
var jobO = JSONUtil.parseObj(res.bodyStr());
.retrieve()
.body(JSONObject.class);
if (jobO.getInt("code") != 1) {
log.error("获取合同列表失败,错误原因:{}", jobO);
}
......@@ -897,12 +902,13 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
.set("formId", 8429903)
.set("page", i)
.set("pageSize", 100);
var resR = Request.of("https://proapi.xbongbong.com/pro/v2/api/contract/list")
var jobR = bongRestClient.post()
.uri("/pro/v2/api/contract/list")
.contentType(MediaType.APPLICATION_JSON)
.header("sign", SecureUtil.sha256(jsonR.toString() + token))
.body(jsonR.toString())
.method(Method.POST)
.send();
var jobR = JSONUtil.parseObj(resR.bodyStr());
.retrieve()
.body(JSONObject.class);
var jsonArrR = jobR.getJSONObject("result").getJSONArray("list");
var dataIdSetR = jsonArrR.stream().map(v -> JSONUtil.parseObj(v).getJSONObject("data").getStr("serialNo")).collect(Collectors.toSet());
dataIdSet.addAll(dataIdSetR);
......@@ -988,12 +994,13 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
.set("corpid", corpId)
.set("formId", 8429903)
.set("pageSize", 100);
var res = Request.of("https://proapi.xbongbong.com/pro/v2/api/contract/list")
var jobO = bongRestClient.post()
.uri("/pro/v2/api/contract/list")
.contentType(MediaType.APPLICATION_JSON)
.header("sign", SecureUtil.sha256(json.toString() + token))
.body(json.toString())
.method(Method.POST)
.send();
var jobO = JSONUtil.parseObj(res.bodyStr());
.retrieve()
.body(JSONObject.class);
if (jobO.getInt("code") != 1) {
log.error("获取合同列表失败,错误原因:{}", jobO);
}
......@@ -1004,12 +1011,13 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
var json1 = JSONUtil.ofObj()
.set("corpid", corpId)
.set("dataId", CollUtil.getFirst(dataIdSet));
var res1 = Request.of("https://proapi.xbongbong.com/pro/v2/api/contract/detail")
var jobj1 = bongRestClient.post()
.uri("/pro/v2/api/contract/detail")
.contentType(MediaType.APPLICATION_JSON)
.header("sign", SecureUtil.sha256(json1.toString() + token))
.body(json1.toString())
.method(Method.POST)
.send();
var jobj1 = JSONUtil.parseObj(res1.bodyStr());
.retrieve()
.body(JSONObject.class);
if (jobj1.getInt("code") != 1) {
log.error("获取合同详情失败,错误原因:{}", jobj1);
}
......@@ -1089,7 +1097,6 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
var bongMap = BeanUtil.beanToMap(xbongContract, new HashMap<>(), copyOptions);
if (!mapEqual(platMap, bongMap)) {
log.info("不一致的合同:{}", contractNo);
// SC 合同全部对比, CS 合同只对比金额
}
}
}
......
......@@ -367,8 +367,8 @@ public class StoreServiceImpl extends MPJBaseServiceImpl<StoreMapper, Store> imp
public String mergeStore(StoreDTO dto) {
// targetId 合并到 sourceId
Long sourceId = dto.getSourceId();
Store store = this.getById(sourceId);
Long targetId = dto.getTargetId();
var targetStore = this.getById(targetId);
// 项目关联合同合并
Opt.ofEmptyAble(contractStoreService.lambdaQuery().select(RContractStore::getContractId).eq(RContractStore::getStoreId, targetId).list())
.ifPresent(l -> {
......@@ -385,13 +385,13 @@ public class StoreServiceImpl extends MPJBaseServiceImpl<StoreMapper, Store> imp
});
// 工单相关合并
taskMapper.update(new Task(), Wrappers.lambdaUpdate(Task.class).set(Task::getStoreId, sourceId).set(Task::getAccountId, store.getAccountId()).eq(Task::getStoreId, targetId));
taskMapper.update(new Task(), Wrappers.lambdaUpdate(Task.class).set(Task::getStoreId, sourceId).set(Task::getAccountId, targetStore.getAccountId()).eq(Task::getStoreId, targetId));
taskTempService.lambdaUpdate().set(TaskTemp::getStoreId, sourceId).eq(TaskTemp::getStoreId, targetId).update();
// 所有 targetId 的文件 转移到 sourceId
fileService.lambdaUpdate().set(FileInfo::getStoreId, sourceId).eq(FileInfo::getStoreId, targetId).update();
faultLogService.lambdaUpdate().set(FaultLog::getStoreId, sourceId).eq(FaultLog::getStoreId, targetId).update();
formService.lambdaUpdate().set(Form::getStoreId, sourceId).set(Form::getAccountId, store.getAccountId()).eq(Form::getStoreId, targetId).update(new Form());
inspectService.lambdaUpdate().set(Inspect::getStoreId, sourceId).set(Inspect::getAccountId, store.getAccountId()).eq(Inspect::getStoreId, targetId).update(new Inspect());
formService.lambdaUpdate().set(Form::getStoreId, sourceId).set(Form::getAccountId, targetStore.getAccountId()).eq(Form::getStoreId, targetId).update(new Form());
inspectService.lambdaUpdate().set(Inspect::getStoreId, sourceId).set(Inspect::getAccountId, targetStore.getAccountId()).eq(Inspect::getStoreId, targetId).update(new Inspect());
// 删除 targetId 对应的项目
this.removeById(targetId);
return "合并成功";
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!