|
|
@@ -1,13 +1,329 @@
|
|
|
package com.sckw.payment.service;
|
|
|
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
|
+import com.github.pagehelper.PageInfo;
|
|
|
+import com.sckw.core.exception.BusinessException;
|
|
|
+import com.sckw.core.model.page.PageRes;
|
|
|
+import com.sckw.core.utils.IdWorker;
|
|
|
+import com.sckw.payment.dao.KwpSettlementLogisticsMapper;
|
|
|
+import com.sckw.payment.dao.KwpSettlementTradeMapper;
|
|
|
+import com.sckw.payment.dao.KwpSettlementWalletMapper;
|
|
|
+import com.sckw.payment.model.KwpSettlementLogistics;
|
|
|
+import com.sckw.payment.model.KwpSettlementTrade;
|
|
|
+import com.sckw.payment.model.KwpSettlementWallet;
|
|
|
+import com.sckw.payment.model.constant.SettlementEnum;
|
|
|
+import com.sckw.payment.model.constant.SettlementOrderTypeEnum;
|
|
|
+import com.sckw.payment.model.constant.SettlementWalletPayTypeEnum;
|
|
|
+import com.sckw.payment.model.constant.WalletChannelEnum;
|
|
|
+import com.sckw.payment.model.dto.SettlementLogisticsDto;
|
|
|
+import com.sckw.payment.model.dto.SettlementTradeDto;
|
|
|
+import com.sckw.payment.model.dto.SettlementWalletDto;
|
|
|
+import com.sckw.payment.model.vo.req.SettlementWalletReq;
|
|
|
+import com.sckw.payment.model.vo.res.SettlementWalletVo;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
- * @author xucaiqin
|
|
|
- * @date 2023-07-10 16:38:36
|
|
|
+ * @author Aick Spt
|
|
|
+ * @date 2023-07-20 14:55
|
|
|
*/
|
|
|
-
|
|
|
+@AllArgsConstructor
|
|
|
@Service
|
|
|
+@Slf4j
|
|
|
public class KwpSettlementWalletService {
|
|
|
|
|
|
+ private final KwpSettlementWalletMapper settlementWalletMapper;
|
|
|
+
|
|
|
+ private final KwpSettlementLogisticsMapper kwpSettlementLogisticsMapper;
|
|
|
+
|
|
|
+ private final KwpSettlementLogisticsService kwpSettlementLogisticsService;
|
|
|
+
|
|
|
+ private final KwpSettlementTradeService kwpSettlementTradeService;
|
|
|
+
|
|
|
+ private final KwpSettlementTradeMapper kwpSettlementTradeMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 物流-电子钱包付款(货到付款)结算记录-列表
|
|
|
+ *
|
|
|
+ * @author Aick Spt
|
|
|
+ * @date 2023-07-26 16:43
|
|
|
+ */
|
|
|
+ public PageRes<SettlementWalletVo> pageListLogisticsPayment(SettlementWalletReq settlementWalletReq) {
|
|
|
+// //todo 查询缓存,获取客户企业id
|
|
|
+// String keywords = settlementReq.getKeywords();
|
|
|
+// if (StringUtils.isNotBlank(keywords)) {
|
|
|
+// System.out.println("关键之:" + keywords);
|
|
|
+// }
|
|
|
+ PageHelper.startPage(settlementWalletReq.getPage(), settlementWalletReq.getPageSize());
|
|
|
+ settlementWalletReq.setPayType(SettlementWalletPayTypeEnum.CASH_ON_DELIVERY.getStatus());//只筛选 货到付款
|
|
|
+ List<SettlementWalletDto> settlementWalletLogisticsList = settlementWalletMapper.pageListLogisticsPayment(settlementWalletReq);
|
|
|
+
|
|
|
+ if (CollectionUtils.isEmpty(settlementWalletLogisticsList)) {
|
|
|
+ return new PageRes<>(new PageInfo<>());
|
|
|
+ }
|
|
|
+
|
|
|
+ for (SettlementWalletDto entity : settlementWalletLogisticsList) {
|
|
|
+ entity.setCreateByText("创建人名称");
|
|
|
+ entity.setUpdateByText("更新人名称");
|
|
|
+ }
|
|
|
+
|
|
|
+ //指定返回值
|
|
|
+ List<SettlementWalletVo> collect = settlementWalletLogisticsList.stream().map(a -> {
|
|
|
+ SettlementWalletVo settlementWalletVo = new SettlementWalletVo();
|
|
|
+ BeanUtils.copyProperties(a, settlementWalletVo);
|
|
|
+ return settlementWalletVo;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ return new PageRes<>(new PageInfo<>(collect));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 结算-物流订单详情
|
|
|
+ *
|
|
|
+ * @param id 结算物流订单id
|
|
|
+ * @author Aick Spt
|
|
|
+ * @date 2023-07-19 09:11
|
|
|
+ */
|
|
|
+ public SettlementWalletDto detailLogisticsPayment(Long id) {
|
|
|
+ return settlementWalletMapper.detailLogisticsPayment(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 物流-电子钱包付款(货到付款)结算记录-新增
|
|
|
+ *
|
|
|
+ * @param id 结算单id
|
|
|
+ * @param price 付款金额
|
|
|
+ * @return InsertId
|
|
|
+ * @author Aick Spt
|
|
|
+ * @date 2023-07-20 14:23
|
|
|
+ * <p>
|
|
|
+ * Transactional// isolation:事务的隔离级别,此处使用后端数据库的默认隔离级别, propagation: 如果当前没有事务,就新建一个事务,如果已经存在一个事务中,加入到这个事务中(常见)。(rollbackFor = Exception.class, isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
|
|
|
+ */
|
|
|
+ @Transactional
|
|
|
+ public Integer confirmLogisticsPayment(Long id, BigDecimal price) {
|
|
|
+ //先查询出结算单情况
|
|
|
+ SettlementLogisticsDto settlementLogisticsDto = kwpSettlementLogisticsService.detailPayment(id);
|
|
|
+ log.info(String.valueOf(settlementLogisticsDto));
|
|
|
+ //检查结算单状态和所差金额
|
|
|
+ if (settlementLogisticsDto == null) {
|
|
|
+ log.error("非法请求,查无数据:" + id);
|
|
|
+ throw new BusinessException("非法请求运费结算参数ID");
|
|
|
+ }
|
|
|
+ if (settlementLogisticsDto.getStatus() == SettlementEnum.ALL_PAYMENT.getStatus()) {
|
|
|
+ log.error("非法请求,该订单已结算完成:" + id);
|
|
|
+ throw new BusinessException("该订单已结算完成,无法操作");
|
|
|
+ }
|
|
|
+ BigDecimal remainingReceivables = settlementLogisticsDto.getTotalPrice();
|
|
|
+ if (settlementLogisticsDto.getActualPrice() != null) {//剩余金额
|
|
|
+ remainingReceivables = settlementLogisticsDto.getTotalPrice().subtract(settlementLogisticsDto.getActualPrice());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (remainingReceivables.compareTo(price) < 0) {//-1表示小于,0是等于,1是大于
|
|
|
+ log.error("本次结算输入金额比剩余付款金额大:ID:" + id + " 剩余金额:" + remainingReceivables + " 本次输入金额:" + price);
|
|
|
+ throw new BusinessException("参数错误:输入金额过大 " + price + " 剩余金额最大值:" + remainingReceivables);
|
|
|
+ }
|
|
|
+ //累加入库结算单
|
|
|
+ KwpSettlementLogistics settlementLogistics1 = new KwpSettlementLogistics();
|
|
|
+ settlementLogistics1.setId(settlementLogisticsDto.getId());
|
|
|
+ settlementLogistics1.setUpdateTime(LocalDateTime.now());
|
|
|
+ if (remainingReceivables.compareTo(price) == 0) {//全部结算
|
|
|
+ settlementLogistics1.setStatus(SettlementEnum.ALL_PAYMENT.getStatus());
|
|
|
+ }
|
|
|
+ if (remainingReceivables.compareTo(price) > 0) {//部分结算
|
|
|
+ settlementLogistics1.setStatus(SettlementEnum.PARTIAL_PAYMENT.getStatus());
|
|
|
+ }
|
|
|
+ BigDecimal actualPrice = settlementLogisticsDto.getActualPrice();
|
|
|
+ settlementLogistics1.setActualPrice((actualPrice == null) ? price : actualPrice.add(price));
|
|
|
+ int upInt = kwpSettlementLogisticsMapper.updateById(settlementLogistics1);
|
|
|
+ if (upInt > 0) {
|
|
|
+ //新增一条电子钱包结算记录
|
|
|
+ remainingReceivables = remainingReceivables.subtract(price);
|
|
|
+ KwpSettlementWallet kwpSettlementWallet = new KwpSettlementWallet();
|
|
|
+ kwpSettlementWallet.setId(new IdWorker(1).nextId());
|
|
|
+ kwpSettlementWallet.setEntId(settlementLogisticsDto.getEntId());
|
|
|
+ kwpSettlementWallet.setSettlementId(settlementLogisticsDto.getId());
|
|
|
+ kwpSettlementWallet.setOrderType(SettlementOrderTypeEnum.LOGISTICS.getStatus());
|
|
|
+ kwpSettlementWallet.setChannel(WalletChannelEnum.HF.getStatus());//先用数字默认定义为1
|
|
|
+ kwpSettlementWallet.setPayTime(LocalDateTime.now());
|
|
|
+ kwpSettlementWallet.setPayPrice(price);
|
|
|
+ kwpSettlementWallet.setTopayPrice(remainingReceivables);
|
|
|
+ kwpSettlementWallet.setType(SettlementWalletPayTypeEnum.CASH_ON_DELIVERY.getStatus());
|
|
|
+ kwpSettlementWallet.setRemark("");
|
|
|
+ kwpSettlementWallet.setStatus(1);
|
|
|
+ kwpSettlementWallet.setCreateBy(1L);//todo 待处理明确创建人
|
|
|
+ kwpSettlementWallet.setCreateTime(LocalDateTime.now());
|
|
|
+ kwpSettlementWallet.setUpdateBy(1L);//todo 待处理明确更新人
|
|
|
+ kwpSettlementWallet.setUpdateTime(LocalDateTime.now());
|
|
|
+ kwpSettlementWallet.setDelFlag(0);
|
|
|
+ Integer insertKwpSettlementWallet = settlementWalletMapper.insert(kwpSettlementWallet);
|
|
|
+
|
|
|
+ //物流货到付款电子钱包逻辑
|
|
|
+ //todo 待处理费电子钱包逻辑
|
|
|
+
|
|
|
+ return insertKwpSettlementWallet;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public PageRes<SettlementWalletVo> pageListTradePayment(SettlementWalletReq settlementWalletReq) {
|
|
|
+// //todo 查询缓存,获取客户企业id
|
|
|
+// String keywords = settlementReq.getKeywords();
|
|
|
+// if (StringUtils.isNotBlank(keywords)) {
|
|
|
+// System.out.println("关键之:" + keywords);
|
|
|
+// }
|
|
|
+ PageHelper.startPage(settlementWalletReq.getPage(), settlementWalletReq.getPageSize());
|
|
|
+
|
|
|
+ List<SettlementWalletDto> settlementWalletLogisticsList = settlementWalletMapper.pageListLogisticsPayment(settlementWalletReq);
|
|
|
+ for (SettlementWalletDto entity : settlementWalletLogisticsList) {
|
|
|
+ entity.setCreateByText("创建人名称");
|
|
|
+ entity.setUpdateByText("更新人名称");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (CollectionUtils.isEmpty(settlementWalletLogisticsList)) {
|
|
|
+ return new PageRes<>(new PageInfo<>());
|
|
|
+ }
|
|
|
+
|
|
|
+ //指定返回值
|
|
|
+ List<SettlementWalletVo> collect = settlementWalletLogisticsList.stream().map(a -> {
|
|
|
+ SettlementWalletVo settlementWalletVo = new SettlementWalletVo();
|
|
|
+ BeanUtils.copyProperties(a, settlementWalletVo);
|
|
|
+ return settlementWalletVo;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ return new PageRes<>(new PageInfo<>(collect));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 销售-付款确认-(新增电子钱包记录-采购货到付款)
|
|
|
+ *
|
|
|
+ * @author Aick Spt
|
|
|
+ * @date 2023-07-27 16:13
|
|
|
+ */
|
|
|
+ public Integer confirmTradePayment(Long id, BigDecimal price) {
|
|
|
+ //先查询出结算单情况
|
|
|
+ SettlementTradeDto settlementTradeDto = kwpSettlementTradeService.detailPayment(id);
|
|
|
+ log.info(String.valueOf(settlementTradeDto));
|
|
|
+ //检查结算单状态和所差金额
|
|
|
+ if (settlementTradeDto == null) {
|
|
|
+ log.error("非法请求,查无数据:" + id);
|
|
|
+ throw new BusinessException("非法请求运费结算参数ID");
|
|
|
+ }
|
|
|
+ if (settlementTradeDto.getStatus() == SettlementEnum.ALL_PAYMENT.getStatus()) {
|
|
|
+ log.error("非法请求,该订单已结算完成:" + id);
|
|
|
+ throw new BusinessException("该订单已结算完成,无法操作");
|
|
|
+ }
|
|
|
+ BigDecimal remainingReceivables = settlementTradeDto.getTotalPrice();
|
|
|
+ if (settlementTradeDto.getActualPrice() != null) {//剩余金额
|
|
|
+ remainingReceivables = settlementTradeDto.getTotalPrice().subtract(settlementTradeDto.getActualPrice());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (remainingReceivables.compareTo(price) < 0) {//-1表示小于,0是等于,1是大于
|
|
|
+ log.error("本次结算输入金额比剩余付款金额大:ID:" + id + " 剩余金额:" + remainingReceivables + " 本次输入金额:" + price);
|
|
|
+ throw new BusinessException("参数错误:输入金额过大 " + price + " 剩余金额最大值:" + remainingReceivables);
|
|
|
+ }
|
|
|
+ //累加入库结算单
|
|
|
+ KwpSettlementTrade kwpSettlementTrade = new KwpSettlementTrade();
|
|
|
+ kwpSettlementTrade.setId(settlementTradeDto.getId());
|
|
|
+ kwpSettlementTrade.setUpdateTime(LocalDateTime.now());
|
|
|
+ if (remainingReceivables.compareTo(price) == 0) {//全部结算
|
|
|
+ kwpSettlementTrade.setStatus(SettlementEnum.ALL_PAYMENT.getStatus());
|
|
|
+ }
|
|
|
+ if (remainingReceivables.compareTo(price) > 0) {//部分结算
|
|
|
+ kwpSettlementTrade.setStatus(SettlementEnum.PARTIAL_PAYMENT.getStatus());
|
|
|
+ }
|
|
|
+ BigDecimal actualPrice = settlementTradeDto.getActualPrice();
|
|
|
+ kwpSettlementTrade.setActualPrice((actualPrice == null) ? price : actualPrice.add(price));
|
|
|
+ int upInt = kwpSettlementTradeMapper.updateById(kwpSettlementTrade);
|
|
|
+ if (upInt > 0) {
|
|
|
+ //新增一条电子钱包结算记录
|
|
|
+ remainingReceivables = remainingReceivables.subtract(price);
|
|
|
+ KwpSettlementWallet kwpSettlementWallet = new KwpSettlementWallet();
|
|
|
+ kwpSettlementWallet.setId(new IdWorker(1).nextId());
|
|
|
+ kwpSettlementWallet.setEntId(settlementTradeDto.getEntId());
|
|
|
+ kwpSettlementWallet.setSettlementId(settlementTradeDto.getId());
|
|
|
+ kwpSettlementWallet.setOrderType(SettlementOrderTypeEnum.LOGISTICS.getStatus());
|
|
|
+ kwpSettlementWallet.setChannel(WalletChannelEnum.HF.getStatus());//先用数字默认定义为1
|
|
|
+ kwpSettlementWallet.setPayTime(LocalDateTime.now());
|
|
|
+ kwpSettlementWallet.setPayPrice(price);
|
|
|
+ kwpSettlementWallet.setTopayPrice(remainingReceivables);
|
|
|
+ kwpSettlementWallet.setType(SettlementWalletPayTypeEnum.CASH_ON_DELIVERY.getStatus());
|
|
|
+ kwpSettlementWallet.setRemark("");
|
|
|
+ kwpSettlementWallet.setStatus(1);
|
|
|
+ kwpSettlementWallet.setCreateBy(1L);//todo 待处理明确创建人
|
|
|
+ kwpSettlementWallet.setCreateTime(LocalDateTime.now());
|
|
|
+ kwpSettlementWallet.setUpdateBy(1L);//todo 待处理明确更新人
|
|
|
+ kwpSettlementWallet.setUpdateTime(LocalDateTime.now());
|
|
|
+ kwpSettlementWallet.setDelFlag(0);
|
|
|
+ Integer insertKwpSettlementWallet = settlementWalletMapper.insert(kwpSettlementWallet);
|
|
|
+
|
|
|
+ //物流货到付款电子钱包逻辑
|
|
|
+ //todo 待处理费电子钱包逻辑
|
|
|
+
|
|
|
+ return insertKwpSettlementWallet;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public PageRes<SettlementWalletVo> pageListTradeCollection(SettlementWalletReq settlementWalletReq) {
|
|
|
+// //todo 查询缓存,获取客户企业id
|
|
|
+// String keywords = settlementReq.getKeywords();
|
|
|
+// if (StringUtils.isNotBlank(keywords)) {
|
|
|
+// System.out.println("关键之:" + keywords);
|
|
|
+// }
|
|
|
+ PageHelper.startPage(settlementWalletReq.getPage(), settlementWalletReq.getPageSize());
|
|
|
+
|
|
|
+ List<SettlementWalletDto> settlementWalletLogisticsList = settlementWalletMapper.pageListLogisticsPayment(settlementWalletReq);
|
|
|
+ for (SettlementWalletDto entity : settlementWalletLogisticsList) {
|
|
|
+ entity.setCreateByText("创建人名称");
|
|
|
+ entity.setUpdateByText("更新人名称");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (CollectionUtils.isEmpty(settlementWalletLogisticsList)) {
|
|
|
+ return new PageRes<>(new PageInfo<>());
|
|
|
+ }
|
|
|
+
|
|
|
+ //指定返回值
|
|
|
+ List<SettlementWalletVo> collect = settlementWalletLogisticsList.stream().map(a -> {
|
|
|
+ SettlementWalletVo settlementWalletVo = new SettlementWalletVo();
|
|
|
+ BeanUtils.copyProperties(a, settlementWalletVo);
|
|
|
+ return settlementWalletVo;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ return new PageRes<>(new PageInfo<>(collect));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public Integer confirmTradeCollection(Long id, Float price) {
|
|
|
+ log.info("接收到数据,开始物流-销售-收款确认-预付款(电子钱包)-新增,待完善");
|
|
|
+ //todo 待完善
|
|
|
+ //先查询出结算单情况
|
|
|
+
|
|
|
+ //检查结算单状态和所差金额
|
|
|
+
|
|
|
+ //对比金额
|
|
|
+
|
|
|
+ //累加入库结算单
|
|
|
+
|
|
|
+ //扣费电子钱包
|
|
|
+
|
|
|
+ //新增电子钱包结算记录
|
|
|
+ KwpSettlementWallet kwpSettlementWallet = new KwpSettlementWallet();
|
|
|
+ kwpSettlementWallet.setId(new IdWorker(1).nextId());
|
|
|
+ //todo 待完善
|
|
|
+ settlementWalletMapper.insert(kwpSettlementWallet);
|
|
|
+ return settlementWalletMapper.confirmLogisticsPayment(id, price);
|
|
|
+ }
|
|
|
}
|
|
|
+
|