diff --git a/cweb/src/main/java/com/cweb/controller/BsMerLedgerController.java b/cweb/src/main/java/com/cweb/controller/BsMerLedgerController.java index 5901190..13093e1 100644 --- a/cweb/src/main/java/com/cweb/controller/BsMerLedgerController.java +++ b/cweb/src/main/java/com/cweb/controller/BsMerLedgerController.java @@ -62,16 +62,23 @@ public class BsMerLedgerController { log.error("BsDeviceOrderPayController -> payOrder error!","参数校验失败"); throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); } + } else if (body.getPlatformType().equals(PlatformTypeEnum.type5.getNumber())) { + if (StringUtils.isBlank(body.getSplitEntrustFilePath())) { + log.error("BsDeviceOrderPayController -> payOrder error!","参数校验失败"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); + } } // 商户平台 BsMerPlatformNo merPlatform = merPlatformNoService.getPlatformNo(body.getMerId(), PlatformTypeEnum.getDataByNumber(body.getPlatformType())); if (merPlatform == null) { - log.error("BsDeviceOrderPayController -> payOrder error!","参数校验失败"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "当前平台未进件"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "当前渠道未进件"); + } + if (!merPlatform.getStatus().equals(MerPlatformNoStatusEnum.status1.getNumber())) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "当前渠道状态不处于正常状态"); } BsMer mer = merService.getMer(body.getMerId()); - // 设备订单 + // 分账信息 BsMerLedger merLedger = merLedgerService.getMerLedger(body.getMerId(), PlatformTypeEnum.getDataByNumber(body.getPlatformType())); if (merLedger == null) { merLedger = new BsMerLedger(); @@ -138,7 +145,6 @@ public class BsMerLedgerController { || body.getMerLedgerId() == null || StringUtils.isBlank(body.getReceiverNo()) || StringUtils.isBlank(body.getReceiverName()) - || StringUtils.isBlank(body.getEntrustFilePath()) ) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的优惠类型"); } @@ -160,13 +166,17 @@ public class BsMerLedgerController { receiver.setCupNo(merLedger.getCupNo()); receiver.setReceiverNo(body.getReceiverNo()); receiver.setReceiverName(body.getReceiverName()); - receiver.setEntrustFileName(body.getEntrustFilePath().substring(body.getEntrustFilePath().lastIndexOf("/")+1)); - receiver.setEntrustFilePath(body.getEntrustFilePath()); + if (StringUtils.isNotBlank(body.getEntrustFilePath())) { + receiver.setEntrustFileName(body.getEntrustFilePath().substring(body.getEntrustFilePath().lastIndexOf("/")+1)); + receiver.setEntrustFilePath(body.getEntrustFilePath()); + } } else { receiver.setReceiverNo(body.getReceiverNo()); receiver.setReceiverName(body.getReceiverName()); - receiver.setEntrustFileName(body.getEntrustFilePath().substring(body.getEntrustFilePath().lastIndexOf("/")+1)); - receiver.setEntrustFilePath(body.getEntrustFilePath()); + if (StringUtils.isNotBlank(body.getEntrustFilePath())) { + receiver.setEntrustFileName(body.getEntrustFilePath().substring(body.getEntrustFilePath().lastIndexOf("/")+1)); + receiver.setEntrustFilePath(body.getEntrustFilePath()); + } } merLedgerReceiverService.merLedgerReceiverApply(receiver); diff --git a/cweb/src/main/java/com/cweb/controller/TestController.java b/cweb/src/main/java/com/cweb/controller/TestController.java index 6df09c8..50446a2 100644 --- a/cweb/src/main/java/com/cweb/controller/TestController.java +++ b/cweb/src/main/java/com/cweb/controller/TestController.java @@ -13,6 +13,7 @@ import com.hfkj.channel.saas.utils.SaasCommon; import com.hfkj.channel.saas.utils.SaasMerRequest; import com.hfkj.channel.tianque.service.TianQueMerElecSignService; import com.hfkj.channel.tianque.service.TianQueMerService; +import com.hfkj.channel.tianque.service.TianQueSeparateService; import com.hfkj.channel.tianque.service.TianQueTradeService; import com.hfkj.channel.weixin.WeiXinMerService; import com.hfkj.channel.weixin.utils.WxUtils; @@ -255,6 +256,8 @@ public class TestController { @Resource private TianQueTradeService tianQueTradeService; @Resource + private TianQueSeparateService tianQueSeparateService; + @Resource private TianQueMerElecSignService tianQueMerElecSignService; @RequestMapping(value="/tianQueTest",method = RequestMethod.GET) @ResponseBody @@ -271,7 +274,8 @@ public class TestController { //tianQueMerService.weChatPayConf("399230921077727", "597456493", "03", "", "", "https://pay.dctpay.com/scanPay/"); //return ResponseMsgUtil.success(tianQueMerService.weChatPayConf("399230921077727", "597456493", "01", "wxa075e8509802f826", "00", "")); - return ResponseMsgUtil.success(tianQueMerService.queryConf("399230921077727", "597456493")); + // return ResponseMsgUtil.success(tianQueMerService.queryConf("399230921077727", "597456493")); + return ResponseMsgUtil.success(tianQueSeparateService.queryAmt(code)); // 1200 // return ResponseMsgUtil.success(saasCommon.fileUpload(new HashMap<>())); /* AlipaySystemOauthTokenRequest request = new AlipaySystemOauthTokenRequest(); diff --git a/open-api/src/main/java/com/api/controller/v1/TradeController.java b/open-api/src/main/java/com/api/controller/v1/TradeController.java index 236ce37..5efbe3c 100644 --- a/open-api/src/main/java/com/api/controller/v1/TradeController.java +++ b/open-api/src/main/java/com/api/controller/v1/TradeController.java @@ -53,8 +53,6 @@ public class TradeController { private OpenApiTradeOrderService openApiTradeOrderService; @Resource private BsMerService merService; - @Resource - private RedisTemplate redisTemplate; @RequestMapping(value="/preorder",method = RequestMethod.POST) @ResponseBody diff --git a/open-api/src/main/java/com/api/controller/v1/TradeProfitSharingController.java b/open-api/src/main/java/com/api/controller/v1/TradeProfitSharingController.java index cc30949..190a15c 100644 --- a/open-api/src/main/java/com/api/controller/v1/TradeProfitSharingController.java +++ b/open-api/src/main/java/com/api/controller/v1/TradeProfitSharingController.java @@ -111,7 +111,7 @@ public class TradeProfitSharingController { throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "接收方状态异常"); } // 接收方分账信息 - BsMerLedger ledger = merLedgerService.getMerLedger(recvMer.getId(), PlatformTypeEnum.type1); + BsMerLedger ledger = merLedgerService.getMerLedger(recvMer.getId(), PlatformTypeEnum.getDataByNumber(tradeOrder.getPlatformType())); if (ledger == null) { throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "接收方状态异常"); } diff --git a/schedule/src/main/java/com/hfkj/schedule/MerLedgerSchedule.java b/schedule/src/main/java/com/hfkj/schedule/MerLedgerSchedule.java new file mode 100644 index 0000000..291c218 --- /dev/null +++ b/schedule/src/main/java/com/hfkj/schedule/MerLedgerSchedule.java @@ -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 param = new HashMap<>(); + param.put("status", MerLedgerStatusEnum.status2.getNumber()); + // 查询审核中的数据 + List 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) { + + } + } + } + +} diff --git a/schedule/src/main/java/com/hfkj/schedule/TradeOrderSchedule.java b/schedule/src/main/java/com/hfkj/schedule/TradeOrderSchedule.java index 695575a..0767668 100644 --- a/schedule/src/main/java/com/hfkj/schedule/TradeOrderSchedule.java +++ b/schedule/src/main/java/com/hfkj/schedule/TradeOrderSchedule.java @@ -3,6 +3,8 @@ package com.hfkj.schedule; import com.alibaba.fastjson.JSONObject; import com.hfkj.channel.lakala.LaKaLaTradeSeparateService; import com.hfkj.channel.lakala.LaKaLaTradeService; +import com.hfkj.channel.tianque.service.TianQueLedgerService; +import com.hfkj.channel.tianque.service.TianQueSeparateService; import com.hfkj.channel.tianque.service.TianQueTradeService; import com.hfkj.channel.weixin.utils.WxOrderConfig; import com.hfkj.common.utils.DateUtil; @@ -42,6 +44,8 @@ public class TradeOrderSchedule { @Resource private LaKaLaTradeService laKaLaTradeService; @Resource + private TianQueSeparateService tianQueSeparateService; + @Resource private TianQueTradeService tianQueTradeService; @Resource private BsTradeSettleService tradeSettleService; @@ -155,7 +159,8 @@ public class TradeOrderSchedule { } } - } else if (tradeOrderProfitSharing.getPlatformType().equals(PlatformTypeEnum.type4.getNumber())) { + } + else if (tradeOrderProfitSharing.getPlatformType().equals(PlatformTypeEnum.type4.getNumber())) { List> receiversList = new ArrayList<>(); Map receiversMap; @@ -201,7 +206,53 @@ public class TradeOrderSchedule { } } } - + else if (tradeOrderProfitSharing.getPlatformType().equals(PlatformTypeEnum.type5.getNumber())) { + if (tradeOrderProfitSharing.getCmdType().equals(ProfitSharingCmdTypeEnum.CMD_TYPE_1.getNumber())) { + if (tradeOrderProfitSharing.getStatus().equals(0)) { + tianQueSeparateService.separate(tradeOrderProfitSharing.getProfitSharingOrderNo()); + + } else if (tradeOrderProfitSharing.getStatus().equals(2)) { + JSONObject query = tianQueSeparateService.query(tradeOrderProfitSharing.getProfitSharingOrderNo()); + // 分账结果,枚举值 取值范围:00 分账成功 01 分账失败 05 分账中 + if (query.getString("ledgerStatus").equals("00")) { + tradeOrderProfitSharing.setStatus(ProfitSharingStatusEnum.status1.getNumber()); + tradeOrderProfitSharing.setFinishTime(new Date()); + tradeOrderProfitSharingService.editData(tradeOrderProfitSharing); + // 修改接收方状态 + List receiverList = tradeOrderProfitSharingReceiverService.getReceiverListByProfitSharingId(tradeOrderProfitSharing.getId()); + for (BsTradeOrderProfitSharingReceiver receiver : receiverList) { + receiver.setStatus(ProfitSharingReceiverStatusEnum.status1.getNumber()); + tradeOrderProfitSharingReceiverService.editData(receiver); + } + } else if (query.getString("ledgerStatus").equals("01")) { + tradeOrderProfitSharing.setStatus(ProfitSharingStatusEnum.status4.getNumber()); + tradeOrderProfitSharingService.editData(tradeOrderProfitSharing); + } + } + } else if (tradeOrderProfitSharing.getCmdType().equals(ProfitSharingCmdTypeEnum.CMD_TYPE_2.getNumber())) { + if (tradeOrderProfitSharing.getStatus().equals(0)) { + tianQueSeparateService.cancel(tradeOrderProfitSharing.getProfitSharingOrderNo()); + + } else if (tradeOrderProfitSharing.getStatus().equals(2)) { + JSONObject query = tianQueSeparateService.query(tradeOrderProfitSharing.getProfitSharingOrderNo()); + // 分账结果,枚举值 取值范围:00 分账成功 01 分账失败 05 分账中 + if (query.getString("ledgerStatus").equals("00")) { + tradeOrderProfitSharing.setStatus(ProfitSharingStatusEnum.status1.getNumber()); + tradeOrderProfitSharing.setFinishTime(new Date()); + tradeOrderProfitSharingService.editData(tradeOrderProfitSharing); + // 修改接收方状态 + List receiverList = tradeOrderProfitSharingReceiverService.getReceiverListByProfitSharingId(tradeOrderProfitSharing.getId()); + for (BsTradeOrderProfitSharingReceiver receiver : receiverList) { + receiver.setStatus(ProfitSharingReceiverStatusEnum.status1.getNumber()); + tradeOrderProfitSharingReceiverService.editData(receiver); + } + } else if (query.getString("ledgerStatus").equals("01")) { + tradeOrderProfitSharing.setStatus(ProfitSharingStatusEnum.status4.getNumber()); + tradeOrderProfitSharingService.editData(tradeOrderProfitSharing); + } + } + } + } } catch (Exception e) { tradeOrderProfitSharing.setExt1("分账失败"); tradeOrderProfitSharingService.editData(tradeOrderProfitSharing); diff --git a/service/src/main/java/com/hfkj/channel/lakala/LaKaLaLedgerService.java b/service/src/main/java/com/hfkj/channel/lakala/LaKaLaLedgerService.java index ca9baad..9f5efaa 100644 --- a/service/src/main/java/com/hfkj/channel/lakala/LaKaLaLedgerService.java +++ b/service/src/main/java/com/hfkj/channel/lakala/LaKaLaLedgerService.java @@ -472,6 +472,9 @@ public class LaKaLaLedgerService { if (merLedgerReceiver == null) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到分账关系"); } + if (StringUtils.isBlank(merLedgerReceiver.getEntrustFilePath())) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未上传协议"); + } // 商户 BsMer mer = merService.getMer(merLedgerReceiver.getMerId()); if (mer == null) { diff --git a/service/src/main/java/com/hfkj/channel/lakala/LaKaLaTradeSeparateService.java b/service/src/main/java/com/hfkj/channel/lakala/LaKaLaTradeSeparateService.java index 06aaf0d..9fb6a74 100644 --- a/service/src/main/java/com/hfkj/channel/lakala/LaKaLaTradeSeparateService.java +++ b/service/src/main/java/com/hfkj/channel/lakala/LaKaLaTradeSeparateService.java @@ -59,7 +59,7 @@ public class LaKaLaTradeSeparateService { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "业务不处于待处理状态"); } // 查询交易详情 - BsTradeOrder tradeOrder = tradeOrderService.getOrderByTradeNoId(tradeOrderProfitSharing.getTradeOrderId()); + BsTradeOrder tradeOrder = tradeOrderService.getOrderByOutTradeNo(tradeOrderProfitSharing.getTradeOrderNo()); // 商户 BsMer mer = merService.getMer(tradeOrder.getMerId()); // 分账接收方 @@ -149,7 +149,7 @@ public class LaKaLaTradeSeparateService { throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "未找到交易分账记录"); } // 查询交易详情 - BsTradeOrder tradeOrder = tradeOrderService.getOrderByTradeNoId(tradeOrderProfitSharing.getTradeOrderId()); + BsTradeOrder tradeOrder = tradeOrderService.getOrderByOutTradeNo(tradeOrderProfitSharing.getTradeOrderNo()); Map commonParam = new HashMap<>(); commonParam.put("req_time", DateUtil.format(new Date(), "yyyyMMddHHmmss")); diff --git a/service/src/main/java/com/hfkj/channel/tianque/service/TianQueLedgerService.java b/service/src/main/java/com/hfkj/channel/tianque/service/TianQueLedgerService.java new file mode 100644 index 0000000..28ecaa4 --- /dev/null +++ b/service/src/main/java/com/hfkj/channel/tianque/service/TianQueLedgerService.java @@ -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 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 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 mnoArray) { + log.info("========= Start 分账设置 Start ==========="); + Map 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; + } +} diff --git a/service/src/main/java/com/hfkj/channel/tianque/service/TianQueSeparateService.java b/service/src/main/java/com/hfkj/channel/tianque/service/TianQueSeparateService.java new file mode 100644 index 0000000..e23cb39 --- /dev/null +++ b/service/src/main/java/com/hfkj/channel/tianque/service/TianQueSeparateService.java @@ -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 profitSharingReceiverList = tradeOrderProfitSharingReceiverService.getReceiverListByProfitSharingId(tradeOrderProfitSharing.getId()); + + Map 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> recvDatasMapList = new ArrayList<>(); + Map 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 param = new HashMap<>(); + param.put("mno", tradeOrderProfitSharing.getPlatformMerNo()); + param.put("origUuid", tradeOrderProfitSharing.getOriginProfitSharingOrderNo()); + param.put("uuid", tradeOrderProfitSharing.getProfitSharingOrderNo()); + + List> recvDatasMapList = new ArrayList<>(); + Map recvDatasMap; + List 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 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 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; + } + +} diff --git a/service/src/main/java/com/hfkj/channel/tianque/service/TianQueTradeService.java b/service/src/main/java/com/hfkj/channel/tianque/service/TianQueTradeService.java index 78dc2f1..b03c301 100644 --- a/service/src/main/java/com/hfkj/channel/tianque/service/TianQueTradeService.java +++ b/service/src/main/java/com/hfkj/channel/tianque/service/TianQueTradeService.java @@ -95,7 +95,10 @@ public class TianQueTradeService { } } param.put("userId", order.getPayUserId()); - param.put("ledgerAccountFlag", "01"); // 异步分账类型 00 异步分账,01 不分账,04 多次分账 + param.put("ledgerAccountFlag", order.getProfitSharingStatus().equals(true)?"00":"01"); // 异步分账类型 00 异步分账,01 不分账,04 多次分账 + if (order.getProfitSharingStatus().equals(true)) { + param.put("ledgerAccountEffectTime", "7"); // 分账有效时间(单位天 + } if (order.getCreateType() != null && order.getCreateType().equals(TradeOrderCreateTypeEnum.type3.getCode())) { param.put("notifyUrl", CommonSysConst.getSysConfig().getTianque_open_api_pay_notify_url()); } else { diff --git a/service/src/main/java/com/hfkj/openapi/v1/service/impl/OpenApiTradeOrderProfitSharingServiceImpl.java b/service/src/main/java/com/hfkj/openapi/v1/service/impl/OpenApiTradeOrderProfitSharingServiceImpl.java index 2212f14..c235261 100644 --- a/service/src/main/java/com/hfkj/openapi/v1/service/impl/OpenApiTradeOrderProfitSharingServiceImpl.java +++ b/service/src/main/java/com/hfkj/openapi/v1/service/impl/OpenApiTradeOrderProfitSharingServiceImpl.java @@ -3,6 +3,7 @@ package com.hfkj.openapi.v1.service.impl; import com.alibaba.fastjson.JSONObject; import com.hfkj.channel.lakala.LaKaLaTradeSeparateService; import com.hfkj.channel.lakala.LaKaLaTradeService; +import com.hfkj.channel.tianque.service.TianQueSeparateService; import com.hfkj.common.exception.ErrorCode; import com.hfkj.common.exception.ErrorHelp; import com.hfkj.common.exception.SysCode; @@ -51,6 +52,8 @@ public class OpenApiTradeOrderProfitSharingServiceImpl implements OpenApiTradeOr private OpenApiTradeOrderService openApiTradeOrderService; @Resource private LaKaLaTradeSeparateService laKaLaTradeSeparateService; + @Resource + private TianQueSeparateService tianQueSeparateService; @Override @Transactional(propagation= Propagation.REQUIRES_NEW, timeout = 20) @@ -86,7 +89,9 @@ public class OpenApiTradeOrderProfitSharingServiceImpl implements OpenApiTradeOr for (RequestSeparateModel.RequestSeparateRecvDataModel recvData : separateModel.getRecvDatas()) { BsMer recvMer = merService.getMer(recvData.getRecvMerchantNo()); - BsMerLedger merLedger = merLedgerService.getMerLedger(recvMer.getId(), PlatformTypeEnum.type1); + // 分账权限 + BsMerLedger merLedger = merLedgerService.getMerLedger(recvMer.getId(), PlatformTypeEnum.getDataByNumber(tradeOrder.getPlatformType())); + BsTradeOrderProfitSharingReceiver profitSharingReceiver = new BsTradeOrderProfitSharingReceiver(); profitSharingReceiver.setTradeOrderProfitSharingId(tradeOrderProfitSharing.getId()); profitSharingReceiver.setTradeOrderId(tradeOrder.getId()); @@ -101,8 +106,14 @@ public class OpenApiTradeOrderProfitSharingServiceImpl implements OpenApiTradeOr tradeOrderProfitSharingReceiverService.editData(profitSharingReceiver); } + BsTradeOrderProfitSharing profitSharing = null; // 调用第三方分账 - BsTradeOrderProfitSharing profitSharing = laKaLaTradeSeparateService.separate(tradeOrderProfitSharing.getProfitSharingOrderNo()); + if (tradeOrder.getPlatformType().equals(PlatformTypeEnum.type1.getNumber())) { + profitSharing = laKaLaTradeSeparateService.separate(tradeOrderProfitSharing.getProfitSharingOrderNo()); + + } else if (tradeOrder.getPlatformType().equals(PlatformTypeEnum.type5.getNumber())) { + profitSharing = tianQueSeparateService.separate(tradeOrderProfitSharing.getProfitSharingOrderNo()); + } ResponseSeparateModel responseSeparate = new ResponseSeparateModel(); responseSeparate.setMerchantNo(separateModel.getMerchantNo()); diff --git a/service/src/main/java/com/hfkj/openapi/v1/utils/SignatureUtil.java b/service/src/main/java/com/hfkj/openapi/v1/utils/SignatureUtil.java index 51f93a0..9e5a11f 100644 --- a/service/src/main/java/com/hfkj/openapi/v1/utils/SignatureUtil.java +++ b/service/src/main/java/com/hfkj/openapi/v1/utils/SignatureUtil.java @@ -84,17 +84,14 @@ public class SignatureUtil { public static void main(String[] args) throws Exception { String paramStr = "{\n" + - " \"merchantNo\": \"2023041916292112804\",\n" + - " \"outTradeNo\": \"ZF1130202305051459532538970034\",\n" + - " \"payMode\": \"WECHAT\",\n" + - " \"totalAmount\": 0.01,\n" + - " \"transType\": \"JSAPI\",\n" + - " \"subAppid\": \"wx52bbabe89258602a\",\n" + - " \"userId\": \"oz6S35CrEuPfBbpta6DuLninz2tA\",\n" + - " \"profitSharing\": 0,\n" + - " \"specialField\": \"测试\"" + + " \"merchantNo\": \"2023090616352962600\",\n" + + " \"outTradeNo\": \"ZF113020230505145953253897005\",\n" + + " \"refundAmount\": \"0.01\",\n" + + " \"refundReason\": \"测试退款\",\n" + + " \"refundTradeNo\": \"1170004\"" + "}"; - String sign = createSign(JSONObject.parseObject(paramStr), "cj0XLsFuryluIXiopa25IwvsurWzBeUW"); + + String sign = createSign(JSONObject.parseObject(paramStr), "tglpZHbMLS8URfGeNqn82MGMcVRU9GtO"); System.out.println(sign); } diff --git a/service/src/main/java/com/hfkj/service/impl/BsMerLedgerReceiverServiceImpl.java b/service/src/main/java/com/hfkj/service/impl/BsMerLedgerReceiverServiceImpl.java index b9bd335..2f14c62 100644 --- a/service/src/main/java/com/hfkj/service/impl/BsMerLedgerReceiverServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/impl/BsMerLedgerReceiverServiceImpl.java @@ -1,7 +1,9 @@ package com.hfkj.service.impl; +import com.alibaba.fastjson.JSONObject; import com.hfkj.channel.lakala.LaKaLaLedgerService; import com.hfkj.channel.lakala.LaKaLaMerService; +import com.hfkj.channel.tianque.service.TianQueLedgerService; import com.hfkj.dao.BsMerLedgerReceiverMapper; import com.hfkj.entity.BsMerLedgerReceiver; import com.hfkj.entity.BsMerLedgerReceiverExample; @@ -15,9 +17,12 @@ import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; +import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.Stream; /** * @className: BsMerLedgerReceiverServiceImpl @@ -32,6 +37,8 @@ public class BsMerLedgerReceiverServiceImpl implements BsMerLedgerReceiverServic @Resource private LaKaLaLedgerService laKaLaLedgerService; + @Resource + private TianQueLedgerService tianQueLedgerService; @Override public void editMerLedgerReceiver(BsMerLedgerReceiver merLedgerReceiver) { @@ -52,6 +59,11 @@ public class BsMerLedgerReceiverServiceImpl implements BsMerLedgerReceiverServic if (merLedgerReceiver.getPlatformType().equals(PlatformTypeEnum.type1.getNumber())) { laKaLaLedgerService.applyBind(merLedgerReceiver); + + } else if (merLedgerReceiver.getPlatformType().equals(PlatformTypeEnum.type5.getNumber())) { + tianQueLedgerService.querySignContract(merLedgerReceiver.getPlatformNo(), Stream.of(merLedgerReceiver.getReceiverNo()).collect(Collectors.toList())); + merLedgerReceiver.setStatus(MerLedgerReceiverStatusEnum.status1.getNumber()); + editMerLedgerReceiver(merLedgerReceiver); } } diff --git a/service/src/main/java/com/hfkj/service/impl/BsMerLedgerServiceImpl.java b/service/src/main/java/com/hfkj/service/impl/BsMerLedgerServiceImpl.java index 139f38f..dcf77a3 100644 --- a/service/src/main/java/com/hfkj/service/impl/BsMerLedgerServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/impl/BsMerLedgerServiceImpl.java @@ -2,6 +2,10 @@ package com.hfkj.service.impl; import com.ccb.wlpt.util.StringUtil; import com.hfkj.channel.lakala.LaKaLaLedgerService; +import com.hfkj.channel.tianque.service.TianQueLedgerService; +import com.hfkj.channel.tianque.service.TianQueMerService; +import com.hfkj.channel.tianque.utils.RequestUtil; +import com.hfkj.config.CommonSysConst; import com.hfkj.dao.BsMerLedgerMapper; import com.hfkj.entity.BsMerLedger; import com.hfkj.entity.BsMerLedgerExample; @@ -14,6 +18,7 @@ import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; +import java.io.File; import java.util.Date; import java.util.List; import java.util.Map; @@ -28,10 +33,10 @@ public class BsMerLedgerServiceImpl implements BsMerLedgerService { @Resource private BsMerLedgerMapper merLedgerMapper; - @Resource private LaKaLaLedgerService laKaLaLedgerService; - + @Resource + private TianQueLedgerService tianQueLedgerService; @Override public void editMerLedger(BsMerLedger merLedger) { if (merLedger.getId() == null) { @@ -51,6 +56,9 @@ public class BsMerLedgerServiceImpl implements BsMerLedgerService { if (merLedger.getPlatformType().equals(PlatformTypeEnum.type1.getNumber())) { laKaLaLedgerService.applyLedger(merLedger.getId()); + + } else if (merLedger.getPlatformType().equals(PlatformTypeEnum.type5.getNumber())) { + tianQueLedgerService.applyLedger(merLedger.getId()); } } diff --git a/service/src/main/java/com/hfkj/service/impl/BsMerPlatformNoServiceImpl.java b/service/src/main/java/com/hfkj/service/impl/BsMerPlatformNoServiceImpl.java index d226a3e..96c0717 100644 --- a/service/src/main/java/com/hfkj/service/impl/BsMerPlatformNoServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/impl/BsMerPlatformNoServiceImpl.java @@ -1,5 +1,6 @@ package com.hfkj.service.impl; +import com.hfkj.common.utils.RedisUtil; import com.hfkj.dao.BsMerPlatformNoMapper; import com.hfkj.entity.BsMerPlatformNo; import com.hfkj.entity.BsMerPlatformNoExample; @@ -20,6 +21,8 @@ public class BsMerPlatformNoServiceImpl implements BsMerPlatformNoService { @Resource private BsMerPlatformNoMapper merPlatformNoMapper; + @Resource + private RedisUtil redisUtil; @Override public void editMerPlatformNo(BsMerPlatformNo merPlatformNo) { @@ -35,10 +38,15 @@ public class BsMerPlatformNoServiceImpl implements BsMerPlatformNoService { @Override public BsMerPlatformNo getPlatformNo(Long merId, PlatformTypeEnum type) { + Object platform = redisUtil.hget("PLATFORM", merId + "_" + type.getNumber()); + if (platform != null) { + return (BsMerPlatformNo) platform; + } BsMerPlatformNoExample example = new BsMerPlatformNoExample(); example.createCriteria().andMerIdEqualTo(merId).andPlatformTypeEqualTo(type.getNumber()).andStatusEqualTo(1); List list = merPlatformNoMapper.selectByExample(example); if (list.size() > 0) { + redisUtil.hset("PLATFORM", merId + "_" + type.getNumber(), list.get(0)); return list.get(0); } return null; @@ -46,6 +54,10 @@ public class BsMerPlatformNoServiceImpl implements BsMerPlatformNoService { @Override public BsMerPlatformNo getCurrentPlatform(Long merId) { + Object platform = redisUtil.hget("PLATFORM", merId+""); + if (platform != null) { + return (BsMerPlatformNo) platform; + } BsMerPlatformNoExample example = new BsMerPlatformNoExample(); example.createCriteria() .andMerIdEqualTo(merId) @@ -53,6 +65,7 @@ public class BsMerPlatformNoServiceImpl implements BsMerPlatformNoService { .andCurrentPlatformEqualTo(true); List list = merPlatformNoMapper.selectByExample(example); if (list.size() > 0) { + redisUtil.hset("PLATFORM", merId+"", list.get(0)); return list.get(0); } return null; @@ -119,9 +132,11 @@ public class BsMerPlatformNoServiceImpl implements BsMerPlatformNoService { for (BsMerPlatformNo platform : platformNoList) { if (platform.getPlatformType().equals(type.getNumber())) { platform.setCurrentPlatform(true); + redisUtil.hset("PLATFORM", merId+"", platform); } else { platform.setCurrentPlatform(false); } + redisUtil.hset("PLATFORM", merId + "_" + platform.getPlatformType(), platform); editMerPlatformNo(platform); } } diff --git a/service/src/main/java/com/hfkj/service/impl/BsMerPlatformTermServiceImpl.java b/service/src/main/java/com/hfkj/service/impl/BsMerPlatformTermServiceImpl.java index 07b8b4c..79bff48 100644 --- a/service/src/main/java/com/hfkj/service/impl/BsMerPlatformTermServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/impl/BsMerPlatformTermServiceImpl.java @@ -1,5 +1,7 @@ package com.hfkj.service.impl; +import com.alicp.jetcache.anno.CacheType; +import com.alicp.jetcache.anno.Cached; import com.hfkj.dao.BsMerPlatformTermMapper; import com.hfkj.entity.BsMerPlatformTerm; import com.hfkj.entity.BsMerPlatformTermExample; @@ -30,6 +32,7 @@ public class BsMerPlatformTermServiceImpl implements BsMerPlatformTermService { } @Override + @Cached(cacheType = CacheType.REMOTE, name="MER_PLATFORM_TERM:", key = "#platformTermNoId + '_' + #busiTypeCode") public BsMerPlatformTerm getMerPlatformTerm(Long platformTermNoId, String busiTypeCode) { BsMerPlatformTermExample example = new BsMerPlatformTermExample(); example.createCriteria() diff --git a/service/src/main/java/com/hfkj/service/impl/BsMerServiceImpl.java b/service/src/main/java/com/hfkj/service/impl/BsMerServiceImpl.java index 59cd79b..c311f69 100644 --- a/service/src/main/java/com/hfkj/service/impl/BsMerServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/impl/BsMerServiceImpl.java @@ -436,6 +436,7 @@ public class BsMerServiceImpl implements BsMerService { } @Override + // @Cached(cacheType = CacheType.REMOTE, name="MER_NO:", key = "#merNo") public BsMer getMer(String merNo) { BsMerExample example = new BsMerExample(); example.createCriteria().andMerNoEqualTo(merNo).andMerStatusEqualTo(MerStatusEnum.status1.getNumber()); diff --git a/service/src/main/java/com/hfkj/service/impl/BsStoreServiceImpl.java b/service/src/main/java/com/hfkj/service/impl/BsStoreServiceImpl.java index b03ce5a..e65ed3d 100644 --- a/service/src/main/java/com/hfkj/service/impl/BsStoreServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/impl/BsStoreServiceImpl.java @@ -1,5 +1,7 @@ package com.hfkj.service.impl; +import com.alicp.jetcache.anno.CacheType; +import com.alicp.jetcache.anno.Cached; import com.hfkj.common.exception.ErrorCode; import com.hfkj.common.exception.ErrorHelp; import com.hfkj.common.exception.SysCode; @@ -134,6 +136,7 @@ public class BsStoreServiceImpl implements BsStoreService { } @Override + @Cached(cacheType = CacheType.REMOTE, name="STORE:", key = "#storeId") public BsStore getStoreById(Long storeId) { return storeMapper.selectByPrimaryKey(storeId); } diff --git a/service/src/main/java/com/hfkj/service/impl/BsTradeOrderProfitSharingServiceImpl.java b/service/src/main/java/com/hfkj/service/impl/BsTradeOrderProfitSharingServiceImpl.java index 76a8a2b..df64313 100644 --- a/service/src/main/java/com/hfkj/service/impl/BsTradeOrderProfitSharingServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/impl/BsTradeOrderProfitSharingServiceImpl.java @@ -79,6 +79,8 @@ public class BsTradeOrderProfitSharingServiceImpl implements BsTradeOrderProfitS platformServiceCharge = new BigDecimal("0.000"); } else if (tradeOrder.getPlatformType().equals(PlatformTypeEnum.type4.getNumber())) { platformServiceCharge = new BigDecimal("0.002"); + } else if (tradeOrder.getPlatformType().equals(PlatformTypeEnum.type5.getNumber())) { + platformServiceCharge = new BigDecimal("0.000"); } // 交易金额 * 渠道平台收取手续费率 = 渠道平台手续费 (四舍五入向上取取整) diff --git a/service/src/main/java/com/hfkj/service/impl/BsTradeOrderRefundServiceImpl.java b/service/src/main/java/com/hfkj/service/impl/BsTradeOrderRefundServiceImpl.java index 9f1bba8..83afef0 100644 --- a/service/src/main/java/com/hfkj/service/impl/BsTradeOrderRefundServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/impl/BsTradeOrderRefundServiceImpl.java @@ -12,10 +12,7 @@ import com.hfkj.dao.BsTradeOrderRefundMapper; import com.hfkj.entity.*; import com.hfkj.channel.lakala.LaKaLaTradeService; import com.hfkj.service.*; -import com.hfkj.sysenum.PlatformTypeEnum; -import com.hfkj.sysenum.StoreDiscountActivityPartakeWayEnum; -import com.hfkj.sysenum.TradeOrderRefundStatusEnum; -import com.hfkj.sysenum.TradeOrderStatusEnum; +import com.hfkj.sysenum.*; import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; @@ -136,7 +133,9 @@ public class BsTradeOrderRefundServiceImpl implements BsTradeOrderRefundService editOrderRefund(tradeOrderRefund); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, e.getMessage()); } finally { - HsgIntegralService.refundReturn(tradeOrder.getId().toString(),tradeOrder.getOutTradeNo(), refundStatus); + if (!tradeOrder.getCreateType().equals(TradeOrderCreateTypeEnum.type3.getCode())) { + HsgIntegralService.refundReturn(tradeOrder.getId().toString(),tradeOrder.getOutTradeNo(), refundStatus); + } } } diff --git a/service/src/main/java/com/hfkj/service/impl/BsTradeOrderServiceImpl.java b/service/src/main/java/com/hfkj/service/impl/BsTradeOrderServiceImpl.java index 6f07434..271f346 100644 --- a/service/src/main/java/com/hfkj/service/impl/BsTradeOrderServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/impl/BsTradeOrderServiceImpl.java @@ -10,6 +10,7 @@ import com.hfkj.common.exception.ErrorHelp; import com.hfkj.common.exception.SysCode; import com.hfkj.common.utils.DateUtil; import com.hfkj.common.utils.IDGenerator; +import com.hfkj.common.utils.RedisUtil; import com.hfkj.common.utils.RequestUtils; import com.hfkj.config.device.SoundService; import com.hfkj.dao.BsTradeOrderMapper; @@ -61,6 +62,10 @@ public class BsTradeOrderServiceImpl implements BsTradeOrderService { @Resource private LaKaLaTradeService laKaLaTradeService; + @Resource + private RedisUtil redisUtil; + private final static String TRADE_ORDER = "TRADE_ORDER:"; + @Override public void editOrder(BsTradeOrder tradeOrder) { if (tradeOrder.getId() == null) { @@ -71,6 +76,8 @@ public class BsTradeOrderServiceImpl implements BsTradeOrderService { tradeOrder.setUpdateTime(new Date()); tradeOrderMapper.updateByPrimaryKey(tradeOrder); } + // 缓存十分钟 + redisUtil.set(TRADE_ORDER + tradeOrder.getOutTradeNo(), tradeOrder,60*10); } @Override @@ -321,11 +328,18 @@ public class BsTradeOrderServiceImpl implements BsTradeOrderService { @Override public BsTradeOrder getOrderByOutTradeNo(String outTradeNo) { + Object obj = redisUtil.get(TRADE_ORDER + outTradeNo); + if (obj != null) { + return (BsTradeOrder) obj; + } BsTradeOrderExample example = new BsTradeOrderExample(); example.createCriteria().andOutTradeNoEqualTo(outTradeNo); List list = tradeOrderMapper.selectByExample(example); if (list.size() > 0) { - return list.get(0); + BsTradeOrder tradeOrder = list.get(0); + // 缓存十分钟 + redisUtil.set(TRADE_ORDER + tradeOrder.getOutTradeNo(), tradeOrder,60*10); + return tradeOrder; } return null; }