From 46f2f13f04597032b894de7d698c9dd3fdf52e43 Mon Sep 17 00:00:00 2001 From: hurui <177768073@qq.com> Date: Tue, 30 May 2023 14:16:36 +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 --- .../api/controller/v1/LedgerController.java | 183 --------------- .../v1/TradeProfitSharingController.java | 214 ++++++++++++++++++ .../model/request/RequestSeparateModel.java | 6 +- ...ApiTradeOrderProfitSharingServiceImpl.java | 2 +- .../service/impl/BsMerKeyServiceImpl.java | 2 +- .../hfkj/service/impl/BsMerServiceImpl.java | 2 + 6 files changed, 222 insertions(+), 187 deletions(-) create mode 100644 open-api/src/main/java/com/api/controller/v1/TradeProfitSharingController.java 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 fcdbe4c..e2f0b3c 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 @@ -48,33 +48,6 @@ public class LedgerController { @Resource private BsMerKeyService merKeyService; - @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 = "分账关系申请") @@ -121,160 +94,4 @@ public class LedgerController { } } - @RequestMapping(value="/separate",method = RequestMethod.POST) - @ResponseBody - @ApiOperation(value = "分账发起") - public ResponseData separate(@Validated @RequestBody RequestSeparateModel body) { - log.info("========= Start 分账发起接口 Start ==========="); - log.info("请求参数:" + JSONObject.toJSONString(body)); - try { - // 验证签名 - 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) { - 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, "交易订单不支持分账"); - } - // 查询商户分账权限 - 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, "商户分账权限未开通"); - } - - - - log.info("返回参数:" + JSONObject.toJSONString(null)); - return ResponseMsgUtil.success(null); - - } catch (Exception e) { - log.info("出现异常:", e); - return ResponseMsgUtil.exception(e); - } finally { - log.info("========= END 分账发起接口 END ==========="); - } - } - - @RequestMapping(value="/cancel",method = RequestMethod.POST) - @ResponseBody - @ApiOperation(value = "分账撤销") - public ResponseData cancel(@Validated @RequestBody RequestTradePreorderModel body) { - log.info("========= Start 分账撤销接口 Start ==========="); - log.info("请求参数:" + JSONObject.toJSONString(body)); - try { - // 验证签名 - if (!SignatureUtil.checkSign(body.getSign(), body, merKeyService.getKeyByMerNo(body.getMerchantNo()))) { - throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_SIGN_ERR, ""); - } - - log.info("返回参数:" + JSONObject.toJSONString(null)); - return ResponseMsgUtil.success(null); - - } catch (Exception e) { - log.info("出现异常:", e); - return ResponseMsgUtil.exception(e); - } finally { - log.info("========= END 分账撤销接口 END ==========="); - } - } - - @RequestMapping(value="/fallback",method = RequestMethod.POST) - @ResponseBody - @ApiOperation(value = "分账退回") - public ResponseData fallback(@Validated @RequestBody RequestTradePreorderModel body) { - log.info("========= Start 分账退回接口 Start ==========="); - log.info("请求参数:" + JSONObject.toJSONString(body)); - try { - // 验证签名 - if (!SignatureUtil.checkSign(body.getSign(), body, merKeyService.getKeyByMerNo(body.getMerchantNo()))) { - throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_SIGN_ERR, ""); - } - - log.info("返回参数:" + JSONObject.toJSONString(null)); - return ResponseMsgUtil.success(null); - - } catch (Exception e) { - log.info("出现异常:", e); - return ResponseMsgUtil.exception(e); - } finally { - log.info("========= END 分账退回接口 END ==========="); - } - } - - @RequestMapping(value="/query",method = RequestMethod.POST) - @ResponseBody - @ApiOperation(value = "分账结果查询") - public ResponseData query(@Validated @RequestBody RequestTradePreorderModel body) { - log.info("========= Start 分账结果查询接口 Start ==========="); - log.info("请求参数:" + JSONObject.toJSONString(body)); - try { - // 验证签名 - if (!SignatureUtil.checkSign(body.getSign(), body, merKeyService.getKeyByMerNo(body.getMerchantNo()))) { - throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_SIGN_ERR, ""); - } - - log.info("返回参数:" + JSONObject.toJSONString(null)); - return ResponseMsgUtil.success(null); - - } catch (Exception e) { - log.info("出现异常:", e); - return ResponseMsgUtil.exception(e); - } finally { - log.info("========= END 分账结果查询接口 END ==========="); - } - } - - @RequestMapping(value="/queryAmt",method = RequestMethod.POST) - @ResponseBody - @ApiOperation(value = "可分账金额查询") - public ResponseData queryAmt(@Validated @RequestBody RequestTradePreorderModel body) { - log.info("========= Start 可分账金额查询接口 Start ==========="); - log.info("请求参数:" + JSONObject.toJSONString(body)); - try { - // 验证签名 - if (!SignatureUtil.checkSign(body.getSign(), body, merKeyService.getKeyByMerNo(body.getMerchantNo()))) { - throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_SIGN_ERR, ""); - } - - log.info("返回参数:" + JSONObject.toJSONString(null)); - return ResponseMsgUtil.success(null); - - } catch (Exception e) { - log.info("出现异常:", e); - return ResponseMsgUtil.exception(e); - } finally { - log.info("========= END 可分账金额查询接口 END ==========="); - } - } - - } 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 new file mode 100644 index 0000000..9244915 --- /dev/null +++ b/open-api/src/main/java/com/api/controller/v1/TradeProfitSharingController.java @@ -0,0 +1,214 @@ +package com.api.controller.v1; + +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.ResponseMsgUtil; +import com.hfkj.config.CommonSysConst; +import com.hfkj.entity.BsMer; +import com.hfkj.entity.BsMerLedger; +import com.hfkj.entity.BsTradeOrder; +import com.hfkj.entity.BsTradeOrderRefund; +import com.hfkj.model.ResponseData; +import com.hfkj.openapi.v1.model.TradeBillsModel; +import com.hfkj.openapi.v1.model.request.*; +import com.hfkj.openapi.v1.model.response.ResponseQueryTradeModel; +import com.hfkj.openapi.v1.model.response.ResponseRefundTradeModel; +import com.hfkj.openapi.v1.service.OpenApiTradeOrderService; +import com.hfkj.openapi.v1.utils.SignatureUtil; +import com.hfkj.service.BsMerKeyService; +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 javax.annotation.Resource; +import java.math.BigDecimal; +import java.util.Date; +import java.util.List; +import java.util.Map; + +@Controller +@Api(value = "交易订单") +@RequestMapping(value = "/v1/tradeProfitSharing") +public class TradeProfitSharingController { + private static Logger log = LoggerFactory.getLogger(TradeProfitSharingController.class); + + @Resource + private BsMerKeyService merKeyService; + @Resource + private OpenApiTradeOrderService openApiTradeOrderService; + @Resource + private BsTradeOrderProfitSharingService tradeOrderProfitSharingService; + @Resource + private BsMerLedgerService merLedgerService; + @Resource + private BsMerService merService; + + @RequestMapping(value="/separate",method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "分账发起") + public ResponseData separate(@Validated @RequestBody RequestSeparateModel body) { + log.info("========= Start 分账发起接口 Start ==========="); + log.info("请求参数:" + JSONObject.toJSONString(body)); + try { + // 验证签名 +/* 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, "未填写分账接收方"); + }*/ + // 分账流水号重复校验 + if (tradeOrderProfitSharingService.getDetailByProfitSharingOrderNo(body.getOutSeparateNo()) != null) { + throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "分账流水号重复"); + } + // 查询交易订单 + BsTradeOrder tradeOrder = openApiTradeOrderService.getOrderByOutTradeNo(body.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, "交易订单不支持分账"); + } + // 查询商户分账权限 + 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, "商户分账权限未开通"); + } +/* for (RequestSeparateRecvDataModel recvData : body.getRecvDatas()) { + // 查询接收方信息 + BsMer recvMer = merService.getMer(recvData.getRecvMerchantNo()); + if (recvMer == null) { + throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "未知的接收方"); + } + if (!recvMer.getMerStatus().equals(MerStatusEnum.status1.getNumber())) { + throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "接收方状态异常"); + } + }*/ + + + + log.info("返回参数:" + JSONObject.toJSONString(null)); + return ResponseMsgUtil.success(null); + + } catch (Exception e) { + log.info("出现异常:", e); + return ResponseMsgUtil.exception(e); + } finally { + log.info("========= END 分账发起接口 END ==========="); + } + } + + @RequestMapping(value="/cancel",method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "分账撤销") + public ResponseData cancel(@Validated @RequestBody RequestTradePreorderModel body) { + log.info("========= Start 分账撤销接口 Start ==========="); + log.info("请求参数:" + JSONObject.toJSONString(body)); + try { + // 验证签名 + if (!SignatureUtil.checkSign(body.getSign(), body, merKeyService.getKeyByMerNo(body.getMerchantNo()))) { + throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_SIGN_ERR, ""); + } + + log.info("返回参数:" + JSONObject.toJSONString(null)); + return ResponseMsgUtil.success(null); + + } catch (Exception e) { + log.info("出现异常:", e); + return ResponseMsgUtil.exception(e); + } finally { + log.info("========= END 分账撤销接口 END ==========="); + } + } + + @RequestMapping(value="/fallback",method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "分账退回") + public ResponseData fallback(@Validated @RequestBody RequestTradePreorderModel body) { + log.info("========= Start 分账退回接口 Start ==========="); + log.info("请求参数:" + JSONObject.toJSONString(body)); + try { + // 验证签名 + if (!SignatureUtil.checkSign(body.getSign(), body, merKeyService.getKeyByMerNo(body.getMerchantNo()))) { + throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_SIGN_ERR, ""); + } + + log.info("返回参数:" + JSONObject.toJSONString(null)); + return ResponseMsgUtil.success(null); + + } catch (Exception e) { + log.info("出现异常:", e); + return ResponseMsgUtil.exception(e); + } finally { + log.info("========= END 分账退回接口 END ==========="); + } + } + + @RequestMapping(value="/query",method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "分账结果查询") + public ResponseData query(@Validated @RequestBody RequestTradePreorderModel body) { + log.info("========= Start 分账结果查询接口 Start ==========="); + log.info("请求参数:" + JSONObject.toJSONString(body)); + try { + // 验证签名 + if (!SignatureUtil.checkSign(body.getSign(), body, merKeyService.getKeyByMerNo(body.getMerchantNo()))) { + throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_SIGN_ERR, ""); + } + + log.info("返回参数:" + JSONObject.toJSONString(null)); + return ResponseMsgUtil.success(null); + + } catch (Exception e) { + log.info("出现异常:", e); + return ResponseMsgUtil.exception(e); + } finally { + log.info("========= END 分账结果查询接口 END ==========="); + } + } + + @RequestMapping(value="/queryAmt",method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "可分账金额查询") + public ResponseData queryAmt(@Validated @RequestBody RequestTradePreorderModel body) { + log.info("========= Start 可分账金额查询接口 Start ==========="); + log.info("请求参数:" + JSONObject.toJSONString(body)); + try { + // 验证签名 + if (!SignatureUtil.checkSign(body.getSign(), body, merKeyService.getKeyByMerNo(body.getMerchantNo()))) { + throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_SIGN_ERR, ""); + } + + log.info("返回参数:" + JSONObject.toJSONString(null)); + return ResponseMsgUtil.success(null); + + } catch (Exception e) { + log.info("出现异常:", e); + return ResponseMsgUtil.exception(e); + } finally { + log.info("========= END 可分账金额查询接口 END ==========="); + } + } + + + +} diff --git a/service/src/main/java/com/hfkj/openapi/v1/model/request/RequestSeparateModel.java b/service/src/main/java/com/hfkj/openapi/v1/model/request/RequestSeparateModel.java index f5af498..7ce1d63 100644 --- a/service/src/main/java/com/hfkj/openapi/v1/model/request/RequestSeparateModel.java +++ b/service/src/main/java/com/hfkj/openapi/v1/model/request/RequestSeparateModel.java @@ -3,6 +3,7 @@ package com.hfkj.openapi.v1.model.request; import lombok.Data; import org.hibernate.validator.constraints.Length; +import javax.validation.Valid; import javax.validation.constraints.DecimalMax; import javax.validation.constraints.DecimalMin; import javax.validation.constraints.NotBlank; @@ -44,13 +45,14 @@ public class RequestSeparateModel { @NotBlank(message = "分账总金额必填项") @DecimalMin(value = "0.01", message = "分账总金额最小0.01") @DecimalMax(value = "9999999", message = "分账总金额最大9999999") - private BigDecimal totalAmount; + private String totalAmount; /** * 分账接收方 */ @NotBlank(message = "分账接收方必填项") - private List recvDatas; + @Valid + private RequestSeparateRecvDataModel recvDatas; /** * 签名参数 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 bff3749..748c25c 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 @@ -70,7 +70,7 @@ public class OpenApiTradeOrderProfitSharingServiceImpl implements OpenApiTradeOr tradeOrderProfitSharing.setPlatformMerNo(tradeOrder.getPlatformMerNo()); tradeOrderProfitSharing.setPlatformTradeNo(tradeOrder.getPlatformTradeNo()); tradeOrderProfitSharing.setPlatformAppid(tradeOrder.getPlatformAppid()); - tradeOrderProfitSharing.setProfitSharingAmoun(separateModel.getTotalAmount()); + tradeOrderProfitSharing.setProfitSharingAmoun(new BigDecimal(separateModel.getTotalAmount())); tradeOrderProfitSharing.setStatus(ProfitSharingStatusEnum.status0.getNumber()); tradeOrderProfitSharingService.editData(tradeOrderProfitSharing); return null; 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 e68b235..169590b 100644 --- a/service/src/main/java/com/hfkj/service/impl/BsMerKeyServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/impl/BsMerKeyServiceImpl.java @@ -34,7 +34,7 @@ public class BsMerKeyServiceImpl implements BsMerKeyService { } @Override - @Cached(cacheType = CacheType.REMOTE, name="MER_KEY:", key = "#merNo") // 缓存一个月 + @Cached(cacheType = CacheType.REMOTE, name="MER_KEY:", key = "#merNo") public String getKeyByMerNo(String merNo) { return MapUtils.getString(getDetailByMerNo(merNo), "merKey"); } 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 5253c5a..f164eba 100644 --- a/service/src/main/java/com/hfkj/service/impl/BsMerServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/impl/BsMerServiceImpl.java @@ -2,6 +2,8 @@ package com.hfkj.service.impl; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +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;