提交代码

yy_dev
胡锐 2 years ago
parent 9f1a566193
commit 0fdba9757b
  1. 2
      open-api/src/main/java/com/OpenApiApplication.java
  2. 71
      open-api/src/main/java/com/api/controller/v1/LedgerController.java
  3. 21
      service/src/main/java/com/hfkj/openapi/v1/service/OpenApiTradeOrderProfitSharingService.java
  4. 78
      service/src/main/java/com/hfkj/openapi/v1/service/impl/OpenApiTradeOrderProfitSharingServiceImpl.java
  5. 8
      service/src/main/java/com/hfkj/service/BsTradeOrderProfitSharingService.java
  6. 3
      service/src/main/java/com/hfkj/service/impl/BsMerKeyServiceImpl.java

@ -16,7 +16,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
// @ComponentScan // @ComponentScan
@EnableTransactionManagement @EnableTransactionManagement
@EnableScheduling @EnableScheduling
@EnableMethodCache(basePackages = "com.hai") @EnableMethodCache(basePackages = "com.hfkj")
@EnableCreateCacheAnnotation @EnableCreateCacheAnnotation
@ServletComponentScan @ServletComponentScan
@EnableAspectJAutoProxy(proxyTargetClass = true) @EnableAspectJAutoProxy(proxyTargetClass = true)

@ -4,27 +4,34 @@ import com.alibaba.fastjson.JSONObject;
import com.hfkj.common.exception.ErrorCode; import com.hfkj.common.exception.ErrorCode;
import com.hfkj.common.exception.ErrorHelp; import com.hfkj.common.exception.ErrorHelp;
import com.hfkj.common.exception.SysCode; 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.common.utils.ResponseMsgUtil;
import com.hfkj.entity.BsMer;
import com.hfkj.entity.BsMerLedger;
import com.hfkj.entity.BsTradeOrder; import com.hfkj.entity.BsTradeOrder;
import com.hfkj.entity.BsTradeOrderProfitSharing;
import com.hfkj.model.ResponseData; import com.hfkj.model.ResponseData;
import com.hfkj.openapi.v1.model.request.RequestSeparateModel; 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.model.request.RequestTradePreorderModel;
import com.hfkj.openapi.v1.service.OpenApiTradeOrderService; import com.hfkj.openapi.v1.service.OpenApiTradeOrderService;
import com.hfkj.openapi.v1.utils.SignatureUtil; import com.hfkj.openapi.v1.utils.SignatureUtil;
import com.hfkj.service.BsMerKeyService; 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.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.*;
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 javax.annotation.Resource;
import java.util.Date;
/** /**
* @className: LedgerController * @className: LedgerController
@ -44,6 +51,30 @@ public class LedgerController {
@Resource @Resource
private OpenApiTradeOrderService openApiTradeOrderService; 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) @RequestMapping(value="/applyBind",method = RequestMethod.POST)
@ResponseBody @ResponseBody
@ApiOperation(value = "分账关系申请") @ApiOperation(value = "分账关系申请")
@ -101,6 +132,25 @@ public class LedgerController {
if (!SignatureUtil.checkSign(body.getSign(), body, merKeyService.getKeyByMerNo(body.getMerchantNo()))) { if (!SignatureUtil.checkSign(body.getSign(), body, merKeyService.getKeyByMerNo(body.getMerchantNo()))) {
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_SIGN_ERR, ""); 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()); BsTradeOrder tradeOrder = openApiTradeOrderService.getOrderByOutTradeNo(body.getOutTradeNo());
if (tradeOrder == null) { if (tradeOrder == null) {
@ -109,6 +159,17 @@ public class LedgerController {
if (!tradeOrder.getStatus().equals(TradeOrderStatusEnum.status3.getNumber())) { if (!tradeOrder.getStatus().equals(TradeOrderStatusEnum.status3.getNumber())) {
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "交易订单不处于已支付"); 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, "商户分账权限未开通");
}

@ -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<String, Object> separate(RequestSeparateModel separateModel);
}

@ -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<String, Object> 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;
}
}

@ -26,6 +26,12 @@ public interface BsTradeOrderProfitSharingService {
*/ */
void createProfitSharing(BsTradeOrder tradeOrder); void createProfitSharing(BsTradeOrder tradeOrder);
/**
* 查询分账记录
* @param profitSharingCmdType
* @param tradeOrderId
* @return
*/
BsTradeOrderProfitSharing getProfitSharingByTradeOrderId(ProfitSharingCmdTypeEnum profitSharingCmdType,Long tradeOrderId); BsTradeOrderProfitSharing getProfitSharingByTradeOrderId(ProfitSharingCmdTypeEnum profitSharingCmdType,Long tradeOrderId);
/** /**
@ -46,4 +52,6 @@ public interface BsTradeOrderProfitSharingService {
* @return * @return
*/ */
List<BsTradeOrderProfitSharing> getNeedFinishProfitSharingOrder(); List<BsTradeOrderProfitSharing> getNeedFinishProfitSharingOrder();
} }

@ -1,5 +1,7 @@
package com.hfkj.service.impl; 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.ErrorCode;
import com.hfkj.common.exception.ErrorHelp; import com.hfkj.common.exception.ErrorHelp;
import com.hfkj.common.exception.SysCode; import com.hfkj.common.exception.SysCode;
@ -32,6 +34,7 @@ public class BsMerKeyServiceImpl implements BsMerKeyService {
} }
@Override @Override
@Cached(cacheType = CacheType.REMOTE, name="MER_KEY:", key = "#merNo") // 缓存一个月
public String getKeyByMerNo(String merNo) { public String getKeyByMerNo(String merNo) {
return MapUtils.getString(getDetailByMerNo(merNo), "merKey"); return MapUtils.getString(getDetailByMerNo(merNo), "merKey");
} }

Loading…
Cancel
Save