From 0fdba9757b67f2122f8c563a6a96249cd56fcbc4 Mon Sep 17 00:00:00 2001 From: hurui <177768073@qq.com> Date: Tue, 30 May 2023 11:21:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/OpenApiApplication.java | 2 +- .../api/controller/v1/LedgerController.java | 71 +++++++++++++++-- ...OpenApiTradeOrderProfitSharingService.java | 21 +++++ ...ApiTradeOrderProfitSharingServiceImpl.java | 78 +++++++++++++++++++ .../BsTradeOrderProfitSharingService.java | 8 ++ .../service/impl/BsMerKeyServiceImpl.java | 3 + 6 files changed, 177 insertions(+), 6 deletions(-) create mode 100644 service/src/main/java/com/hfkj/openapi/v1/service/OpenApiTradeOrderProfitSharingService.java create mode 100644 service/src/main/java/com/hfkj/openapi/v1/service/impl/OpenApiTradeOrderProfitSharingServiceImpl.java diff --git a/open-api/src/main/java/com/OpenApiApplication.java b/open-api/src/main/java/com/OpenApiApplication.java index 5e2b6a4..1f43253 100644 --- a/open-api/src/main/java/com/OpenApiApplication.java +++ b/open-api/src/main/java/com/OpenApiApplication.java @@ -16,7 +16,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement; // @ComponentScan @EnableTransactionManagement @EnableScheduling -@EnableMethodCache(basePackages = "com.hai") +@EnableMethodCache(basePackages = "com.hfkj") @EnableCreateCacheAnnotation @ServletComponentScan @EnableAspectJAutoProxy(proxyTargetClass = true) diff --git a/open-api/src/main/java/com/api/controller/v1/LedgerController.java b/open-api/src/main/java/com/api/controller/v1/LedgerController.java index 2c251c7..fcdbe4c 100644 --- a/open-api/src/main/java/com/api/controller/v1/LedgerController.java +++ b/open-api/src/main/java/com/api/controller/v1/LedgerController.java @@ -4,27 +4,34 @@ import com.alibaba.fastjson.JSONObject; 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.IDGenerator; import com.hfkj.common.utils.ResponseMsgUtil; +import com.hfkj.entity.BsMer; +import com.hfkj.entity.BsMerLedger; import com.hfkj.entity.BsTradeOrder; +import com.hfkj.entity.BsTradeOrderProfitSharing; import com.hfkj.model.ResponseData; import com.hfkj.openapi.v1.model.request.RequestSeparateModel; +import com.hfkj.openapi.v1.model.request.RequestSeparateRecvDataModel; import com.hfkj.openapi.v1.model.request.RequestTradePreorderModel; import com.hfkj.openapi.v1.service.OpenApiTradeOrderService; import com.hfkj.openapi.v1.utils.SignatureUtil; import com.hfkj.service.BsMerKeyService; -import com.hfkj.sysenum.TradeOrderStatusEnum; +import com.hfkj.service.BsMerLedgerService; +import com.hfkj.service.BsMerService; +import com.hfkj.service.BsTradeOrderProfitSharingService; +import com.hfkj.sysenum.*; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Controller; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; +import java.util.Date; /** * @className: LedgerController @@ -44,6 +51,30 @@ public class LedgerController { @Resource private OpenApiTradeOrderService openApiTradeOrderService; + @Resource + private BsTradeOrderProfitSharingService tradeOrderProfitSharingService; + @Resource + private BsMerLedgerService merLedgerService; + @Resource + private BsMerService merService; + + @RequestMapping(value="/getMerKey",method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "分账关系申请") + public ResponseData getMerKey(@RequestParam String merNo) { + log.info("========= Start 聚合主扫接口 Start ==========="); + try { + + return ResponseMsgUtil.success(merKeyService.getKeyByMerNo(merNo)); + + } catch (Exception e) { + log.info("出现异常:", e); + return ResponseMsgUtil.exception(e); + } finally { + log.info("========= END 聚合主扫接口 END ==========="); + } + } + @RequestMapping(value="/applyBind",method = RequestMethod.POST) @ResponseBody @ApiOperation(value = "分账关系申请") @@ -101,6 +132,25 @@ public class LedgerController { if (!SignatureUtil.checkSign(body.getSign(), body, merKeyService.getKeyByMerNo(body.getMerchantNo()))) { throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_SIGN_ERR, ""); } + if (body.getRecvDatas() == null || body.getRecvDatas().size() == 0) { + throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "未填写分账接收方"); + } + for (RequestSeparateRecvDataModel recvData : body.getRecvDatas()) { + // 查询接收方信息 + BsMer mer = merService.getMer(recvData.getRecvMerchantNo()); + if (mer == null) { + throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "未知的接收方"); + } + if (!mer.getMerStatus().equals(MerStatusEnum.status1.getNumber())) { + throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "接收方状态错误"); + } + + } + // 分账流水号重复校验 + if (tradeOrderProfitSharingService.getDetailByProfitSharingOrderNo(body.getOutSeparateNo()) != null) { + throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "分账流水号重复"); + } + // 查询交易订单 BsTradeOrder tradeOrder = openApiTradeOrderService.getOrderByOutTradeNo(body.getOutTradeNo()); if (tradeOrder == null) { @@ -109,6 +159,17 @@ public class LedgerController { if (!tradeOrder.getStatus().equals(TradeOrderStatusEnum.status3.getNumber())) { throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "交易订单不处于已支付"); } + if (tradeOrder.getProfitSharingStatus().equals(false)) { + throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "交易订单不支持分账"); + } + // 查询商户分账权限 + BsMerLedger merLedger = merLedgerService.getMerLedger(tradeOrder.getMerId(), PlatformTypeEnum.getDataByNumber(tradeOrder.getPlatformType())); + if (merLedger == null) { + throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "商户分账权限未开通"); + } + if (!merLedger.getStatus().equals(MerLedgerStatusEnum.status1.getNumber())) { + throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "商户分账权限未开通"); + } diff --git a/service/src/main/java/com/hfkj/openapi/v1/service/OpenApiTradeOrderProfitSharingService.java b/service/src/main/java/com/hfkj/openapi/v1/service/OpenApiTradeOrderProfitSharingService.java new file mode 100644 index 0000000..330ed15 --- /dev/null +++ b/service/src/main/java/com/hfkj/openapi/v1/service/OpenApiTradeOrderProfitSharingService.java @@ -0,0 +1,21 @@ +package com.hfkj.openapi.v1.service; + +import com.hfkj.openapi.v1.model.request.RequestSeparateModel; + +import java.util.Map; + +/** + * 开放api 交易利润分享 + * @className: OpenApiTradeOrderProfitSharingService + * @author: HuRui + * @date: 2023/5/23 + **/ +public interface OpenApiTradeOrderProfitSharingService { + + /** + * 分账 + * @param separateModel + */ + Map separate(RequestSeparateModel separateModel); + +} 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 new file mode 100644 index 0000000..bff3749 --- /dev/null +++ b/service/src/main/java/com/hfkj/openapi/v1/service/impl/OpenApiTradeOrderProfitSharingServiceImpl.java @@ -0,0 +1,78 @@ +package com.hfkj.openapi.v1.service.impl; + +import com.alibaba.fastjson.JSONObject; +import com.hfkj.channel.lakala.LaKaLaTradeService; +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.dao.OpenApiTradeOrderMapper; +import com.hfkj.entity.BsTradeOrder; +import com.hfkj.entity.BsTradeOrderProfitSharing; +import com.hfkj.entity.BsTradeOrderRefund; +import com.hfkj.openapi.v1.model.TradeBillsModel; +import com.hfkj.openapi.v1.model.request.RequestRefundTradeModel; +import com.hfkj.openapi.v1.model.request.RequestSeparateModel; +import com.hfkj.openapi.v1.model.response.ResponseRefundTradeModel; +import com.hfkj.openapi.v1.service.OpenApiTradeOrderProfitSharingService; +import com.hfkj.openapi.v1.service.OpenApiTradeOrderService; +import com.hfkj.openapi.v1.utils.SignatureUtil; +import com.hfkj.service.BsMerKeyService; +import com.hfkj.service.BsTradeOrderProfitSharingService; +import com.hfkj.service.BsTradeOrderRefundService; +import com.hfkj.service.BsTradeOrderService; +import com.hfkj.sysenum.*; +import org.apache.commons.collections4.MapUtils; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.math.BigDecimal; +import java.util.Date; +import java.util.List; +import java.util.Map; + +/** + * @className: TradeOrderServiceImpl + * @author: HuRui + * @date: 2023/5/24 + **/ +@Service("openApiTradeOrderProfitSharingService") +public class OpenApiTradeOrderProfitSharingServiceImpl implements OpenApiTradeOrderProfitSharingService { + + @Resource + private BsTradeOrderProfitSharingService tradeOrderProfitSharingService; + + @Resource + private OpenApiTradeOrderService openApiTradeOrderService; + + @Override + @Transactional(propagation= Propagation.REQUIRES_NEW, timeout = 20) + public Map separate(RequestSeparateModel separateModel) { + // 查询交易订单 + BsTradeOrder tradeOrder = openApiTradeOrderService.getOrderByOutTradeNo(separateModel.getOutTradeNo()); + if (tradeOrder == null) { + throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "未知的交易单号"); + } + if (!tradeOrder.getStatus().equals(TradeOrderStatusEnum.status3.getNumber())) { + throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "交易订单不处于已支付"); + } + if (tradeOrder.getProfitSharingStatus().equals(false)) { + throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "交易订单不支持分账"); + } + BsTradeOrderProfitSharing tradeOrderProfitSharing = new BsTradeOrderProfitSharing(); + tradeOrderProfitSharing.setCmdType(ProfitSharingCmdTypeEnum.CMD_TYPE_1.getNumber()); + tradeOrderProfitSharing.setTradeOrderId(tradeOrder.getId()); + tradeOrderProfitSharing.setTradeOrderNo(tradeOrder.getOutTradeNo()); + tradeOrderProfitSharing.setProfitSharingOrderNo(separateModel.getOutSeparateNo()); + tradeOrderProfitSharing.setPlatformType(tradeOrder.getPlatformType()); + tradeOrderProfitSharing.setPlatformMerNo(tradeOrder.getPlatformMerNo()); + tradeOrderProfitSharing.setPlatformTradeNo(tradeOrder.getPlatformTradeNo()); + tradeOrderProfitSharing.setPlatformAppid(tradeOrder.getPlatformAppid()); + tradeOrderProfitSharing.setProfitSharingAmoun(separateModel.getTotalAmount()); + tradeOrderProfitSharing.setStatus(ProfitSharingStatusEnum.status0.getNumber()); + tradeOrderProfitSharingService.editData(tradeOrderProfitSharing); + return null; + } +} diff --git a/service/src/main/java/com/hfkj/service/BsTradeOrderProfitSharingService.java b/service/src/main/java/com/hfkj/service/BsTradeOrderProfitSharingService.java index f7f77e3..60fba18 100644 --- a/service/src/main/java/com/hfkj/service/BsTradeOrderProfitSharingService.java +++ b/service/src/main/java/com/hfkj/service/BsTradeOrderProfitSharingService.java @@ -26,6 +26,12 @@ public interface BsTradeOrderProfitSharingService { */ void createProfitSharing(BsTradeOrder tradeOrder); + /** + * 查询分账记录 + * @param profitSharingCmdType + * @param tradeOrderId + * @return + */ BsTradeOrderProfitSharing getProfitSharingByTradeOrderId(ProfitSharingCmdTypeEnum profitSharingCmdType,Long tradeOrderId); /** @@ -46,4 +52,6 @@ public interface BsTradeOrderProfitSharingService { * @return */ List getNeedFinishProfitSharingOrder(); + + } diff --git a/service/src/main/java/com/hfkj/service/impl/BsMerKeyServiceImpl.java b/service/src/main/java/com/hfkj/service/impl/BsMerKeyServiceImpl.java index 33ebce1..e68b235 100644 --- a/service/src/main/java/com/hfkj/service/impl/BsMerKeyServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/impl/BsMerKeyServiceImpl.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; @@ -32,6 +34,7 @@ public class BsMerKeyServiceImpl implements BsMerKeyService { } @Override + @Cached(cacheType = CacheType.REMOTE, name="MER_KEY:", key = "#merNo") // 缓存一个月 public String getKeyByMerNo(String merNo) { return MapUtils.getString(getDetailByMerNo(merNo), "merKey"); }