mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-19 18:45:03 +08:00
update sim卡批量续费方法
This commit is contained in:
@@ -213,17 +213,64 @@ public class SimCardService {
|
||||
List<String> xunZhongCards = map.get("xunzhong");
|
||||
// 智宇物联平台 Sim卡卡号
|
||||
List<String> wuLianCards = map.get("wulian");
|
||||
// 异步批量执行续费方法
|
||||
XunZhongSimRenewal(xunZhongCards, dto.getCycleNumber());
|
||||
|
||||
WuLianSimRenew(wuLianCards, dto.getCycleNumber());
|
||||
// 保存所有续费结果
|
||||
List<SimRenewResultVO> allResults = new ArrayList<>();
|
||||
|
||||
// 讯众续费
|
||||
if (CollectionUtils.isNotEmpty(xunZhongCards)) {
|
||||
try {
|
||||
List<SimRenewResultVO> xunZhongResults = XunZhongSimRenewal(xunZhongCards, dto.getCycleNumber());
|
||||
allResults.addAll(xunZhongResults);
|
||||
} catch (BusinessException e) {
|
||||
logger.error("【====讯众物联====】批量续费失败: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// 物联平台续费
|
||||
if (CollectionUtils.isNotEmpty(wuLianCards)) {
|
||||
List<SimRenewResultVO> wuLianResults = WuLianSimRenew(wuLianCards, dto.getCycleNumber());
|
||||
allResults.addAll(wuLianResults);
|
||||
}
|
||||
|
||||
// 将续费完成后的数据插入数据库
|
||||
// SimRechargeRecord record = SimRechargeRecord.builder()
|
||||
// .iccId(iccId)
|
||||
// .status("1")
|
||||
// .build();
|
||||
// simRechargeRecordService.insertSimRechargeRecord()
|
||||
saveSimRechargeRecords(allResults);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存SIM卡续费记录到数据库
|
||||
*
|
||||
* @param results 续费结果列表
|
||||
*/
|
||||
private void saveSimRechargeRecords(List<SimRenewResultVO> results) {
|
||||
if (CollectionUtils.isEmpty(results)) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (SimRenewResultVO result : results) {
|
||||
try {
|
||||
SimRechargeRecord record = SimRechargeRecord.builder()
|
||||
.iccId(result.getIccId())
|
||||
// 优先使用外部订单号,如果没有则使用卡商返回的订单号
|
||||
.rechargeOrderCode(StringUtils.isNotEmpty(result.getOutOrderNo())
|
||||
? result.getOutOrderNo()
|
||||
: result.getRechargeOrderCode())
|
||||
// 金额字段暂时设为null,后续可通过配置表或其他方式获取
|
||||
.payAmount(null)
|
||||
.orderAmount(null)
|
||||
// 状态:0-成功,1-失败
|
||||
.status(result.isResult() ? "0" : "1")
|
||||
.build();
|
||||
|
||||
simRechargeRecordService.insertSimRechargeRecord(record);
|
||||
logger.info("【====SIM卡续费记录保存====】iccid: {}, 订单号: {}, 状态: {}",
|
||||
result.getIccId(), record.getRechargeOrderCode(),
|
||||
result.isResult() ? "成功" : "失败");
|
||||
} catch (Exception e) {
|
||||
logger.error("【====SIM卡续费记录保存失败====】iccid: {}, 错误: {}",
|
||||
result.getIccId(), e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -281,8 +328,16 @@ public class SimCardService {
|
||||
// 讯众
|
||||
try {
|
||||
vo.setSimSuppler(SimSupplierEnum.XUN_ZHONG.getName());
|
||||
XunZhongSimRenewal(Lists.newArrayList(iccId), cycleNumber);
|
||||
vo.setResult(true);
|
||||
List<SimRenewResultVO> results = XunZhongSimRenewal(Lists.newArrayList(iccId), cycleNumber);
|
||||
if (CollectionUtils.isNotEmpty(results)) {
|
||||
SimRenewResultVO result = results.get(0);
|
||||
vo.setResult(result.isResult());
|
||||
vo.setRechargeOrderCode(result.getRechargeOrderCode());
|
||||
vo.setOutOrderNo(result.getOutOrderNo());
|
||||
if (!result.isResult()) {
|
||||
vo.setReason(result.getReason());
|
||||
}
|
||||
}
|
||||
} catch (BusinessException e) {
|
||||
vo.setResult(false);
|
||||
vo.setReason(e.getMessage());
|
||||
@@ -292,8 +347,16 @@ public class SimCardService {
|
||||
if (StringUtils.equals(code, SimSupplierEnum.WU_LIAN_INTERNET.getCode())) {
|
||||
try {
|
||||
vo.setSimSuppler(SimSupplierEnum.WU_LIAN_INTERNET.getName());
|
||||
WuLianSimRenew(Lists.newArrayList(iccId), cycleNumber);
|
||||
vo.setResult(true);
|
||||
List<SimRenewResultVO> results = WuLianSimRenew(Lists.newArrayList(iccId), cycleNumber);
|
||||
if (CollectionUtils.isNotEmpty(results)) {
|
||||
SimRenewResultVO result = results.get(0);
|
||||
vo.setResult(result.isResult());
|
||||
vo.setRechargeOrderCode(result.getRechargeOrderCode());
|
||||
vo.setOutOrderNo(result.getOutOrderNo());
|
||||
if (!result.isResult()) {
|
||||
vo.setReason(result.getReason());
|
||||
}
|
||||
}
|
||||
} catch (BusinessException e) {
|
||||
vo.setResult(false);
|
||||
vo.setReason(e.getMessage());
|
||||
@@ -438,14 +501,15 @@ public class SimCardService {
|
||||
*
|
||||
* @param iccIds 需要续期的sim卡
|
||||
* @param cycleNumber 续费周期(0-999),0表示无限周期
|
||||
* @return
|
||||
* @return 续费结果列表
|
||||
*/
|
||||
public void XunZhongSimRenewal(List<String> iccIds, int cycleNumber) {
|
||||
public List<SimRenewResultVO> XunZhongSimRenewal(List<String> iccIds, int cycleNumber) {
|
||||
List<SimRenewResultVO> resultList = new ArrayList<>();
|
||||
if (CollectionUtils.isEmpty(iccIds)) {
|
||||
throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
|
||||
return resultList;
|
||||
}
|
||||
String iccId = list2Str(iccIds);
|
||||
|
||||
String iccId = list2Str(iccIds);
|
||||
String timestamp = String.valueOf(System.currentTimeMillis() / 1000);
|
||||
|
||||
Hashtable<String, Object> params = new Hashtable<>();
|
||||
@@ -455,21 +519,44 @@ public class SimCardService {
|
||||
params.put("cycle_number", cycleNumber);
|
||||
|
||||
String signStr = XunZhongSimUtils.getSignStr(params);
|
||||
|
||||
params.put("sign", signStr);
|
||||
|
||||
String postResult = XunZhongSimUtils.sendPost(renewURL, params);
|
||||
logger.info("【====讯众物联====】sim卡续费业务, result:{}", postResult);
|
||||
JSONObject jsonResult = JSONObject.parseObject(postResult);
|
||||
String code = jsonResult.getString("code");
|
||||
|
||||
if (!StringUtils.equals("0", code)) {
|
||||
String message = jsonResult.getString("message");
|
||||
// 续费失败,为每个iccid创建失败记录
|
||||
for (String id : iccIds) {
|
||||
SimRenewResultVO vo = new SimRenewResultVO();
|
||||
vo.setIccId(id);
|
||||
vo.setSimSuppler(SimSupplierEnum.XUN_ZHONG.getName());
|
||||
vo.setCycleNumber(cycleNumber);
|
||||
vo.setResult(false);
|
||||
vo.setReason(message);
|
||||
resultList.add(vo);
|
||||
}
|
||||
throw new BusinessException(code, message);
|
||||
}
|
||||
// 续费成功, 将信息存库
|
||||
SimRechargeRecord record = SimRechargeRecord.builder()
|
||||
.iccId()
|
||||
.build();
|
||||
|
||||
// 续费成功,解析返回结果
|
||||
JSONArray resultArray = jsonResult.getJSONArray("result");
|
||||
if (resultArray != null && !resultArray.isEmpty()) {
|
||||
for (int i = 0; i < resultArray.size(); i++) {
|
||||
JSONObject item = resultArray.getJSONObject(i);
|
||||
SimRenewResultVO vo = new SimRenewResultVO();
|
||||
vo.setIccId(item.getString("iccid"));
|
||||
vo.setSimSuppler(SimSupplierEnum.XUN_ZHONG.getName());
|
||||
vo.setCycleNumber(cycleNumber);
|
||||
vo.setResult(true);
|
||||
vo.setRechargeOrderCode(item.getString("order_no"));
|
||||
resultList.add(vo);
|
||||
}
|
||||
}
|
||||
|
||||
return resultList;
|
||||
}
|
||||
|
||||
|
||||
@@ -569,36 +656,54 @@ public class SimCardService {
|
||||
/**
|
||||
* 物联平台续费接口
|
||||
*
|
||||
* @param iccIds
|
||||
* @param cycleNumber
|
||||
* @return
|
||||
* @param iccIds 卡号列表
|
||||
* @param cycleNumber 续费周期
|
||||
* @return 续费结果列表
|
||||
*/
|
||||
public void WuLianSimRenew(List<String> iccIds, int cycleNumber) {
|
||||
List<WuLianSimRenewVO> resultList = new ArrayList<>();
|
||||
public List<SimRenewResultVO> WuLianSimRenew(List<String> iccIds, int cycleNumber) {
|
||||
List<SimRenewResultVO> resultList = new ArrayList<>();
|
||||
if (CollectionUtils.isEmpty(iccIds)) {
|
||||
return;
|
||||
return resultList;
|
||||
}
|
||||
// 先查出卡的信息
|
||||
List<WuLianSimData> wuLianSimData = WuLianGetSimInfo(iccIds);
|
||||
for (WuLianSimData data : wuLianSimData) {
|
||||
SimRenewResultVO renewResult = new SimRenewResultVO();
|
||||
renewResult.setIccId(data.getIccId());
|
||||
renewResult.setSimSuppler(SimSupplierEnum.WU_LIAN_INTERNET.getName());
|
||||
renewResult.setCycleNumber(cycleNumber);
|
||||
|
||||
String outOrderNo = IdUtils.generateTransactionCode(data.getMsisdn());
|
||||
renewResult.setOutOrderNo(outOrderNo);
|
||||
|
||||
JSONObject param = new JSONObject();
|
||||
param.put("appid", appId);
|
||||
param.put("appsecret", appSecret);
|
||||
param.put("name", WuLianSimRenew);
|
||||
param.put("msisdn", data.getMsisdn());
|
||||
param.put("packageId", data.getPackageId()); // 套餐id
|
||||
param.put("outOrderNo", IdUtils.generateTransactionCode(data.getMsisdn())); // 外部业务订单号
|
||||
param.put("outOrderNo", outOrderNo); // 外部业务订单号
|
||||
param.put("period", cycleNumber); // 续费周期
|
||||
|
||||
String result = HttpUtils.sendPostContentType(wuLianGetWay, param.toJSONString(), "application/json");
|
||||
logger.info("【====物联网智能云平台====】Sim卡续费, result: {}", result);
|
||||
JSONObject resultJson = JSONObject.parseObject(result);
|
||||
String resultCode = resultJson.getString("code");
|
||||
WuLianSimRenewVO vo = null;
|
||||
|
||||
if (!StringUtils.equals("0", resultCode)) {
|
||||
throw new BusinessException(resultCode, resultJson.getString("msg"));
|
||||
renewResult.setResult(false);
|
||||
renewResult.setReason(resultJson.getString("msg"));
|
||||
} else {
|
||||
renewResult.setResult(true);
|
||||
// 解析返回的订单信息
|
||||
JSONObject dataObj = resultJson.getJSONObject("data");
|
||||
if (dataObj != null) {
|
||||
renewResult.setRechargeOrderCode(dataObj.getString("orderNo"));
|
||||
}
|
||||
}
|
||||
resultList.add(renewResult);
|
||||
}
|
||||
return resultList;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -34,4 +34,14 @@ public class SimRenewResultVO {
|
||||
* 失败原因
|
||||
*/
|
||||
private String reason;
|
||||
|
||||
/**
|
||||
* 充值订单号(卡商平台返回的订单号)
|
||||
*/
|
||||
private String rechargeOrderCode;
|
||||
|
||||
/**
|
||||
* 外部订单号(我方生成的订单号)
|
||||
*/
|
||||
private String outOrderNo;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user