parent
29a75d02fd
commit
b2b92972ff
@ -0,0 +1,64 @@ |
||||
package com.hfkj.schedule; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.hfkj.channel.tianque.service.TianQueLedgerService; |
||||
import com.hfkj.entity.*; |
||||
import com.hfkj.service.BsMerLedgerService; |
||||
import com.hfkj.sysenum.*; |
||||
import lombok.SneakyThrows; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.scheduling.annotation.Scheduled; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @className: MerLedgerSchedule |
||||
* @author: HuRui |
||||
* @date: 2023/9/25 |
||||
**/ |
||||
public class MerLedgerSchedule { |
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(MerLedgerSchedule.class); |
||||
|
||||
@Resource |
||||
private BsMerLedgerService merLedgerService; |
||||
@Resource |
||||
private TianQueLedgerService tianQueLedgerService; |
||||
|
||||
/** |
||||
* 审批状态查询 |
||||
*/ |
||||
@SneakyThrows |
||||
@Scheduled(cron="0 0/1 * * * ?") //每1分钟执行一次
|
||||
public void merLedgerApplyment() { |
||||
Map<String, Object> param = new HashMap<>(); |
||||
param.put("status", MerLedgerStatusEnum.status2.getNumber()); |
||||
// 查询审核中的数据
|
||||
List<BsMerLedger> merLedgerList = merLedgerService.getMerLedgerList(param); |
||||
for (BsMerLedger merLedger : merLedgerList) { |
||||
try { |
||||
if (merLedger.getPlatformType().equals(PlatformTypeEnum.type5.getNumber())) { |
||||
// 查询签约结果
|
||||
JSONObject signContract = tianQueLedgerService.querySignContract(merLedger.getCupNo()); |
||||
// 签约状态,枚举值 00:已发送链接,未签约 01:签约失败 02:签约成功 03:未签约 04:审批中
|
||||
if (signContract.getString("signResult").equals("01")) { |
||||
merLedger.setStatus(MerLedgerStatusEnum.status3.getNumber()); |
||||
merLedger.setRejectReason("签约失败"); |
||||
merLedgerService.editMerLedger(merLedger); |
||||
|
||||
} else if (signContract.getString("signResult").equals("02")) { |
||||
merLedger.setStatus(MerLedgerStatusEnum.status1.getNumber()); |
||||
merLedgerService.editMerLedger(merLedger); |
||||
} |
||||
} |
||||
} catch (Exception e) { |
||||
|
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,124 @@ |
||||
package com.hfkj.channel.tianque.service; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.hfkj.channel.tianque.config.TianQueConfig; |
||||
import com.hfkj.channel.tianque.utils.RequestUtil; |
||||
import com.hfkj.common.exception.ErrorCode; |
||||
import com.hfkj.common.exception.ErrorHelp; |
||||
import com.hfkj.common.exception.SysCode; |
||||
import com.hfkj.common.utils.DateUtil; |
||||
import com.hfkj.config.CommonSysConst; |
||||
import com.hfkj.entity.*; |
||||
import com.hfkj.service.*; |
||||
import com.hfkj.sysenum.*; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.io.File; |
||||
import java.math.BigDecimal; |
||||
import java.util.*; |
||||
import java.util.stream.Collectors; |
||||
|
||||
/** |
||||
* 分账业务 |
||||
* @className: TianQueSeparateService |
||||
* @author: HuRui |
||||
* @date: 2023/9/22 |
||||
**/ |
||||
@Component |
||||
public class TianQueLedgerService { |
||||
|
||||
private static Logger log = LoggerFactory.getLogger(TianQueLedgerService.class); |
||||
@Resource |
||||
private BsMerLedgerService merLedgerService; |
||||
@Resource |
||||
private BsMerLedgerApplyService merLedgerApplyService; |
||||
|
||||
/** |
||||
* 分账协议签署 |
||||
* @param merLedgerId |
||||
* @return |
||||
*/ |
||||
public JSONObject applyLedger(Long merLedgerId) { |
||||
log.info("========= Start 分账协议签署 Start ==========="); |
||||
BsMerLedger merLedger = merLedgerService.getMerLedgerById(merLedgerId); |
||||
if (merLedger == null || !merLedger.getPlatformType().equals(PlatformTypeEnum.type5.getNumber())) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
Map<String, Object> param = new HashMap<>(); |
||||
param.put("mno", merLedger.getCupNo()); |
||||
param.put("signType", "02"); // 线下签约
|
||||
param.put("ledgerLetter", RequestUtil.requestUpload("77", new File(CommonSysConst.getSysConfig().getFile_url() + "/" + merLedger.getSplitEntrustFilePath())).getString("PhotoUrl")); |
||||
|
||||
JSONObject responseBody = RequestUtil.request(TianQueConfig.requestUrl + "/merchant/sign/getUrl", param); |
||||
log.info("请求参数:",JSONObject.toJSONString(param)); |
||||
log.info("响应参数:", responseBody.toJSONString()); |
||||
System.out.println("body:" + JSONObject.toJSONString(param)); |
||||
System.out.println("response:" + responseBody.toJSONString()); |
||||
if (!"0000".equals(responseBody.getString("bizCode"))) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, responseBody.getString("bizMsg")); |
||||
} |
||||
|
||||
merLedger.setStatus(MerLedgerStatusEnum.status2.getNumber()); |
||||
merLedgerService.editMerLedger(merLedger); |
||||
|
||||
BsMerLedgerApply merLedgerApply = new BsMerLedgerApply(); |
||||
merLedgerApply.setMerLedgerId(merLedger.getId()); |
||||
merLedgerApply.setMerId(merLedger.getMerId()); |
||||
merLedgerApply.setOrderNo(System.currentTimeMillis()+""); |
||||
merLedgerApply.setRequestBody(JSONObject.toJSONString(param)); |
||||
merLedgerApply.setResponseBody(responseBody.toJSONString()); |
||||
merLedgerApplyService.editMerLedgerApply(merLedgerApply); |
||||
|
||||
log.info("========= END 分账协议签署 END ==========="); |
||||
return responseBody; |
||||
} |
||||
|
||||
/** |
||||
* 分账协议签署结果查询 |
||||
* @param mno |
||||
* @return |
||||
*/ |
||||
public JSONObject querySignContract(String mno) { |
||||
log.info("========= Start 分账协议签署结果查询 Start ==========="); |
||||
Map<String, Object> param = new HashMap<>(); |
||||
param.put("mno", mno); |
||||
|
||||
JSONObject responseBody = RequestUtil.request(TianQueConfig.requestUrl + "/merchant/sign/querySignContract", param); |
||||
log.info("请求参数:",JSONObject.toJSONString(param)); |
||||
log.info("响应参数:", responseBody.toJSONString()); |
||||
System.out.println("body:" + JSONObject.toJSONString(param)); |
||||
System.out.println("response:" + responseBody.toJSONString()); |
||||
if (!"0000".equals(responseBody.getString("bizCode"))) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, responseBody.getString("bizMsg")); |
||||
} |
||||
|
||||
log.info("========= END 分账协议签署结果查询 END ==========="); |
||||
return responseBody; |
||||
} |
||||
|
||||
/** |
||||
* 分账接收方设置 |
||||
* @param mno |
||||
* @return |
||||
*/ |
||||
public JSONObject querySignContract(String mno,List<String> mnoArray) { |
||||
log.info("========= Start 分账设置 Start ==========="); |
||||
Map<String, Object> param = new HashMap<>(); |
||||
param.put("mno", mno); |
||||
param.put("mnoArray", mnoArray.stream().distinct().collect(Collectors.joining(",")));// 分账收款商户编号(逗号分隔)
|
||||
|
||||
JSONObject responseBody = RequestUtil.request(TianQueConfig.requestUrl + "/query/ledger/setMnoArray", param); |
||||
log.info("请求参数:",JSONObject.toJSONString(param)); |
||||
log.info("响应参数:", responseBody.toJSONString()); |
||||
System.out.println("body:" + JSONObject.toJSONString(param)); |
||||
System.out.println("response:" + responseBody.toJSONString()); |
||||
if (!"0000".equals(responseBody.getString("bizCode"))) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, responseBody.getString("bizMsg")); |
||||
} |
||||
log.info("========= END 分账接收方设置 END ==========="); |
||||
return responseBody; |
||||
} |
||||
} |
@ -0,0 +1,221 @@ |
||||
package com.hfkj.channel.tianque.service; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.hfkj.channel.lakala.config.LaKaLaConfig; |
||||
import com.hfkj.channel.tianque.config.TianQueConfig; |
||||
import com.hfkj.channel.tianque.utils.RequestUtil; |
||||
import com.hfkj.common.exception.ErrorCode; |
||||
import com.hfkj.common.exception.ErrorHelp; |
||||
import com.hfkj.common.exception.SysCode; |
||||
import com.hfkj.common.utils.DateUtil; |
||||
import com.hfkj.common.utils.HttpsUtils; |
||||
import com.hfkj.config.CommonSysConst; |
||||
import com.hfkj.entity.*; |
||||
import com.hfkj.service.*; |
||||
import com.hfkj.sysenum.ProfitSharingCmdTypeEnum; |
||||
import com.hfkj.sysenum.ProfitSharingReceiverStatusEnum; |
||||
import com.hfkj.sysenum.ProfitSharingStatusEnum; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.math.BigDecimal; |
||||
import java.util.*; |
||||
|
||||
/** |
||||
* 分账业务 |
||||
* @className: TianQueSeparateService |
||||
* @author: HuRui |
||||
* @date: 2023/9/22 |
||||
**/ |
||||
@Component |
||||
public class TianQueSeparateService { |
||||
|
||||
private static Logger log = LoggerFactory.getLogger(TianQueSeparateService.class); |
||||
|
||||
@Resource |
||||
private BsTradeOrderService tradeOrderService; |
||||
@Resource |
||||
private BsTradeOrderProfitSharingService tradeOrderProfitSharingService; |
||||
@Resource |
||||
private BsTradeOrderProfitSharingReceiverService tradeOrderProfitSharingReceiverService; |
||||
@Resource |
||||
private BsMerService merService; |
||||
@Resource |
||||
private CommonService commonService; |
||||
|
||||
/** |
||||
* 发起分账 |
||||
* @param profitSharingOrderNo |
||||
* @return |
||||
*/ |
||||
public BsTradeOrderProfitSharing separate(String profitSharingOrderNo) { |
||||
log.info("========= Start 分账 Start ==========="); |
||||
// 交易分账
|
||||
BsTradeOrderProfitSharing tradeOrderProfitSharing = tradeOrderProfitSharingService.getDetailByProfitSharingOrderNo(profitSharingOrderNo); |
||||
if (null == tradeOrderProfitSharing) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到交易分账记录"); |
||||
} |
||||
if (!tradeOrderProfitSharing.getStatus().equals(ProfitSharingStatusEnum.status0.getNumber())) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "业务不处于待处理状态"); |
||||
} |
||||
// 查询交易详情
|
||||
BsTradeOrder tradeOrder = tradeOrderService.getOrderByOutTradeNo(tradeOrderProfitSharing.getTradeOrderNo()); |
||||
// 分账接收方
|
||||
List<BsTradeOrderProfitSharingReceiver> profitSharingReceiverList = tradeOrderProfitSharingReceiverService.getReceiverListByProfitSharingId(tradeOrderProfitSharing.getId()); |
||||
|
||||
Map<String, Object> param = new HashMap<>(); |
||||
param.put("mno", tradeOrder.getPlatformMerNo()); |
||||
param.put("ordNo", tradeOrder.getOutTradeNo()); |
||||
param.put("uuid", tradeOrderProfitSharing.getProfitSharingOrderNo()); |
||||
// 异步分账枚举:00 取消分账 01 分账
|
||||
param.put("ledgerAccountFlag", tradeOrderProfitSharing.getCmdType().equals(ProfitSharingCmdTypeEnum.CMD_TYPE_1.getNumber())?"01":"00"); |
||||
|
||||
List<Map<String,Object>> recvDatasMapList = new ArrayList<>(); |
||||
Map<String,Object> recvDatasMap; |
||||
|
||||
for (BsTradeOrderProfitSharingReceiver receiver : profitSharingReceiverList) { |
||||
if (receiver.getReceiverAmount().compareTo(new BigDecimal("0")) != 0) { |
||||
recvDatasMap = new HashMap<>(); |
||||
recvDatasMap.put("mno", receiver.getReceiverAccount()); |
||||
recvDatasMap.put("allotValue", receiver.getReceiverAmount()); |
||||
recvDatasMapList.add(recvDatasMap); |
||||
} |
||||
} |
||||
param.put("ledgerRule", recvDatasMapList); |
||||
|
||||
JSONObject responseBody = RequestUtil.request(TianQueConfig.requestUrl + "/query/ledger/launchLedger", param); |
||||
log.info("请求参数:",JSONObject.toJSONString(param)); |
||||
log.info("响应参数:", responseBody.toJSONString()); |
||||
System.out.println("body:" + JSONObject.toJSONString(param)); |
||||
System.out.println("response:" + responseBody.toJSONString()); |
||||
if (!"0000".equals(responseBody.getString("bizCode"))) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, responseBody.getString("bizMsg")); |
||||
} |
||||
// 分账状态 00 分账成功 01 分账失败 05 分账中
|
||||
String statusCode = responseBody.getString("ledgerStatus"); |
||||
if (statusCode.equals("05")) { |
||||
tradeOrderProfitSharing.setStatus(ProfitSharingStatusEnum.status2.getNumber()); |
||||
} else if (statusCode.equals("00")) { |
||||
tradeOrderProfitSharing.setStatus(ProfitSharingStatusEnum.status1.getNumber()); |
||||
tradeOrderProfitSharing.setProfitSharingTime(new Date()); |
||||
tradeOrderProfitSharing.setFinishTime(new Date()); |
||||
} else if (statusCode.equals("01")) { |
||||
tradeOrderProfitSharing.setStatus(ProfitSharingStatusEnum.status4.getNumber()); |
||||
} |
||||
tradeOrderProfitSharing.setPlatformProfitSharingOrderNo(responseBody.getString("uuid")); |
||||
tradeOrderProfitSharingService.editData(tradeOrderProfitSharing); |
||||
|
||||
// 处理接收方数据
|
||||
if (tradeOrderProfitSharing.equals(ProfitSharingStatusEnum.status1.getName())) { |
||||
for (BsTradeOrderProfitSharingReceiver receiver : profitSharingReceiverList) { |
||||
receiver.setStatus(ProfitSharingReceiverStatusEnum.status1.getNumber()); |
||||
receiver.setProfitSharingTime(new Date()); |
||||
receiver.setFinishTime(new Date()); |
||||
tradeOrderProfitSharingReceiverService.editData(receiver); |
||||
} |
||||
} |
||||
log.info("========= END 分账 END ==========="); |
||||
return tradeOrderProfitSharing; |
||||
} |
||||
|
||||
/** |
||||
* 分账撤销 |
||||
* @param profitSharingOrderNo 交易订单号 |
||||
* @return |
||||
*/ |
||||
public JSONObject cancel(String profitSharingOrderNo) { |
||||
log.info("========= Start 分账撤销 Start ==========="); |
||||
// 交易订单分账
|
||||
BsTradeOrderProfitSharing tradeOrderProfitSharing = tradeOrderProfitSharingService.getDetailByProfitSharingOrderNo(profitSharingOrderNo); |
||||
if (null == tradeOrderProfitSharing) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "未找到交易分账记录"); |
||||
} |
||||
|
||||
Map<String, Object> param = new HashMap<>(); |
||||
param.put("mno", tradeOrderProfitSharing.getPlatformMerNo()); |
||||
param.put("origUuid", tradeOrderProfitSharing.getOriginProfitSharingOrderNo()); |
||||
param.put("uuid", tradeOrderProfitSharing.getProfitSharingOrderNo()); |
||||
|
||||
List<Map<String,Object>> recvDatasMapList = new ArrayList<>(); |
||||
Map<String,Object> recvDatasMap; |
||||
List<BsTradeOrderProfitSharingReceiver> receiverList = tradeOrderProfitSharingReceiverService.getReceiverListByProfitSharingId(tradeOrderProfitSharing.getId()); |
||||
for (BsTradeOrderProfitSharingReceiver receiver : receiverList) { |
||||
recvDatasMap = new HashMap<>(); |
||||
recvDatasMap.put("mno", receiver.getReceiverNo()); |
||||
recvDatasMap.put("allotValue", receiver.getReceiverAmount()); |
||||
recvDatasMapList.add(recvDatasMap); |
||||
} |
||||
param.put("ledgerRule", recvDatasMapList); |
||||
|
||||
JSONObject responseBody = RequestUtil.request(TianQueConfig.requestUrl + "/query/ledger/ledgerBack", param); |
||||
log.info("请求参数:",JSONObject.toJSONString(param)); |
||||
log.info("响应参数:", responseBody.toJSONString()); |
||||
System.out.println("body:" + JSONObject.toJSONString(param)); |
||||
System.out.println("response:" + responseBody.toJSONString()); |
||||
if (!"0000".equals(responseBody.getString("bizCode"))) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, responseBody.getString("bizMsg")); |
||||
} |
||||
tradeOrderProfitSharing.setStatus(ProfitSharingStatusEnum.status2.getNumber()); |
||||
tradeOrderProfitSharing.setPlatformProfitSharingOrderNo(responseBody.getJSONObject("resp_data").getString("separate_no")); |
||||
tradeOrderProfitSharingService.editData(tradeOrderProfitSharing); |
||||
log.info("========= end 分账撤销 end ==========="); |
||||
return responseBody; |
||||
} |
||||
|
||||
/** |
||||
* 分账交易金额查询 |
||||
* @param profitSharingOrderNo |
||||
* @return |
||||
*/ |
||||
public JSONObject queryAmt(String tradeNo) { |
||||
// 交易订单分账
|
||||
BsTradeOrder outTradeNo = tradeOrderService.getOrderByOutTradeNo(tradeNo); |
||||
if (null == outTradeNo) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "未找到交易记录"); |
||||
} |
||||
Map<String, Object> param = new HashMap<>(); |
||||
param.put("mno", outTradeNo.getPlatformMerNo()); |
||||
param.put("ordNo", outTradeNo.getOutTradeNo()); |
||||
|
||||
JSONObject responseBody = RequestUtil.request(TianQueConfig.requestUrl + "/query/ledger/queryLedgerAmt", param); |
||||
log.info("请求参数:",JSONObject.toJSONString(param)); |
||||
log.info("响应参数:", responseBody.toJSONString()); |
||||
System.out.println("body:" + JSONObject.toJSONString(param)); |
||||
System.out.println("response:" + responseBody.toJSONString()); |
||||
if (!"0000".equals(responseBody.getString("bizCode"))) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, responseBody.getString("bizMsg")); |
||||
} |
||||
return responseBody; |
||||
} |
||||
|
||||
/** |
||||
* 分账结果查询 |
||||
* @param profitSharingOrderNo 交易订单号 |
||||
* @return |
||||
*/ |
||||
public JSONObject query(String profitSharingOrderNo) { |
||||
log.info("========= Start 分账结果查询 Start ==========="); |
||||
// 交易订单分账
|
||||
BsTradeOrderProfitSharing tradeOrderProfitSharing = tradeOrderProfitSharingService.getDetailByProfitSharingOrderNo(profitSharingOrderNo); |
||||
if (null == tradeOrderProfitSharing) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "未找到交易分账记录"); |
||||
} |
||||
Map<String, Object> param = new HashMap<>(); |
||||
param.put("mno", tradeOrderProfitSharing.getPlatformMerNo()); |
||||
param.put("uuid", tradeOrderProfitSharing.getProfitSharingOrderNo()); |
||||
|
||||
JSONObject responseBody = RequestUtil.request(TianQueConfig.requestUrl + "/query/ledger/queryLedgerAccount", param); |
||||
log.info("请求参数:",JSONObject.toJSONString(param)); |
||||
log.info("响应参数:", responseBody.toJSONString()); |
||||
System.out.println("body:" + JSONObject.toJSONString(param)); |
||||
System.out.println("response:" + responseBody.toJSONString()); |
||||
if (!"0000".equals(responseBody.getString("bizCode"))) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, responseBody.getString("bizMsg")); |
||||
} |
||||
log.info("========= end 分账结果查询 end ==========="); |
||||
return responseBody; |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue