三方额度查询

This commit is contained in:
赵辉
2026-06-16 16:23:34 +08:00
parent ff5bc742aa
commit c6e4e76d82
6 changed files with 129 additions and 0 deletions
@@ -3,7 +3,9 @@ package com.mhd.user.application.service;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.google.common.base.Strings;
import com.mhd.common.core.constant.NoticeConstants;
import com.mhd.common.core.domain.dto.AccountCashWalletDto;
@@ -1511,4 +1513,104 @@ public class UserShipperApplicationService {
String account = "MDM_" + code;
return account.length() > 20 ? account.substring(0, 20) : account;
}
/**
* 批量查询赊销额度
* 第一步:调用UAP登录接口获取token(只调一次)
* 第二步:遍历customerNcCodeList,逐个查询赊销额度
* 第三步:查询成功后更新货主的额度同步时间(limitTime)并保存
*
* @param userShipperDTO 包含 customerNcCodeList(客户编码列表)和 organizationId(组织ID
* @return 每个客户编码的查询结果
*/
public AjaxResult querySaleCreditLimit(UserShipperDTO userShipperDTO) {
List<String> customerNcCodeList = userShipperDTO.getCustomerNcCodeList();
if (CollUtil.isEmpty(customerNcCodeList)) {
return AjaxResult.error("客户编码列表不能为空");
}
try {
// 第一步:调用UAP登录接口获取token(批量共用一个token)
String loginUrl = "http://10.0.0.212/uapws/rest/user/login";
com.alibaba.fastjson.JSONObject loginParam = new com.alibaba.fastjson.JSONObject();
loginParam.put("usercode", "MDM");
loginParam.put("pwd", "MDM1234!@#$");
log.info("调用UAP登录接口,请求参数:{}", loginParam.toJSONString());
String loginResult = HttpRequest.post(loginUrl)
.header("Content-Type", "application/json")
.body(loginParam.toJSONString())
.execute()
.body();
log.info("UAP登录接口返回:{}", loginResult);
if (StringUtils.isEmpty(loginResult)) {
return AjaxResult.error("UAP登录接口返回为空");
}
com.alibaba.fastjson.JSONObject loginJson = com.alibaba.fastjson.JSONObject.parseObject(loginResult);
String uapToken = loginJson.getString("uap_token");
String uapUsercode = loginJson.getString("uap_usercode");
String uapDataSource = loginJson.getString("uap_dataSource");
if (StringUtils.isEmpty(uapToken)) {
return AjaxResult.error("UAP登录失败,未获取到token");
}
// 第二步:遍历每个customerNcCode,逐个查询赊销额度
String queryUrl = "http://10.0.0.212/uapws/rest/api/salecredit/querysalecreditlimit";
com.alibaba.fastjson.JSONObject allResults = new com.alibaba.fastjson.JSONObject();
for (String custcode : customerNcCodeList) {
if (StringUtils.isEmpty(custcode)) {
continue;
}
UserShipperEntity userShipperEntity = userShipperMapper.selectOne(new LambdaQueryWrapper<UserShipperEntity>()
.eq(UserShipperEntity::getCustomerNcCode, custcode));
String orgcode = userShipperMapper.getOrgNcCode(userShipperEntity.getOrganizationId());
if (StringUtils.isEmpty(orgcode)) {
return AjaxResult.error("组织NC编码不能为空");
}
try {
com.alibaba.fastjson.JSONObject queryParam = new com.alibaba.fastjson.JSONObject();
queryParam.put("custcode", custcode);
queryParam.put("orgcode", orgcode);
log.info("调用赊销额度查询接口,custcode={}orgcode={}", custcode, orgcode);
String queryResult = HttpRequest.post(queryUrl)
.header("Content-Type", "application/json")
.header("uap_token", uapToken)
.header("uap_usercode", uapUsercode)
.header("uap_dataSource", uapDataSource)
.header("token", "94B3992EAD9747D3598CC6F7775F6239B5DC3B526DF7DE0091CB8B2D")
.body(queryParam.toJSONString())
.execute()
.body();
log.info("赊销额度查询接口返回,custcode={}result={}", custcode, queryResult);
if (StringUtils.isNotEmpty(queryResult)) {
com.alibaba.fastjson.JSONObject resultJson = com.alibaba.fastjson.JSONObject.parseObject(queryResult);
allResults.put(custcode, resultJson);
// 第三步:查询成功,更新货主的额度同步时间(limitTime)
if (userShipperEntity != null) {
userShipperEntity.setLimitTime(new Date());
userShipperMapper.updateById(userShipperEntity);
log.info("更新货主额度同步时间成功,custcode={}shipperId={}", custcode, userShipperEntity.getShipperId());
} else {
log.warn("未找到对应货主,custcode={}organizationId={}", custcode, userShipperDTO.getOrganizationId());
}
} else {
log.warn("赊销额度查询返回为空,custcode={}", custcode);
}
} catch (Exception e) {
log.error("查询赊销额度异常,custcode={}", custcode, e);
}
}
return AjaxResult.success(allResults);
} catch (Exception e) {
log.error("批量查询赊销额度异常", e);
return AjaxResult.error("批量查询赊销额度失败:" + e.getMessage());
}
}
}