|
|
@@ -2,37 +2,54 @@ 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.core.web.context.LoginUserHolder;
|
|
|
import com.sckw.payment.dao.KwpSettlementOfflineMapper;
|
|
|
import com.sckw.payment.model.KwpSettlementOffline;
|
|
|
-import com.sckw.payment.model.constant.SettlementWalletPayTypeEnum;
|
|
|
+import com.sckw.payment.model.KwpSettlementTrade;
|
|
|
+import com.sckw.payment.model.constant.TradingEnum;
|
|
|
import com.sckw.payment.model.dto.SettlementOfflineDto;
|
|
|
+import com.sckw.payment.model.dto.SettlementTradeDto;
|
|
|
+import com.sckw.payment.model.vo.req.SettlementOfflinePayReq;
|
|
|
import com.sckw.payment.model.vo.req.SettlementOfflineReq;
|
|
|
-import com.sckw.payment.model.vo.req.SettlementReq;
|
|
|
import com.sckw.payment.model.vo.res.SettlementOfflineVo;
|
|
|
-import lombok.AllArgsConstructor;
|
|
|
+import com.sckw.system.api.RemoteSystemService;
|
|
|
+import com.sckw.system.api.model.dto.res.UserCacheResDto;
|
|
|
+import jakarta.annotation.Resource;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
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.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @author xucaiqin
|
|
|
* @date 2023-07-10 16:38:36
|
|
|
*/
|
|
|
-@AllArgsConstructor
|
|
|
@Service
|
|
|
@Slf4j
|
|
|
public class KwpSettlementOfflineService {
|
|
|
-
|
|
|
- private final KwpSettlementOfflineMapper settlementOfflineMapper;
|
|
|
+ @Resource
|
|
|
+ private KwpSettlementOfflineMapper settlementOfflineMapper;
|
|
|
+ @Resource
|
|
|
+ private KwpSettlementTradeService settlementTradeService;
|
|
|
+ @DubboReference(version = "2.0.0", group = "design", check = false)
|
|
|
+ private RemoteSystemService remoteSystemService;
|
|
|
|
|
|
/**
|
|
|
* 物流-线下付款(运费收款)记录-列表
|
|
|
+ *
|
|
|
* @author Aick Spt
|
|
|
* @date 2023-07-26 17:15
|
|
|
*/
|
|
|
@@ -107,50 +124,92 @@ public class KwpSettlementOfflineService {
|
|
|
}
|
|
|
|
|
|
public PageRes<SettlementOfflineVo> pageListTradeCollection(SettlementOfflineReq settlementOfflineReq) {
|
|
|
- // //todo 查询缓存,获取客户企业id
|
|
|
-// String keywords = settlementReq.getKeywords();
|
|
|
-// if (StringUtils.isNotBlank(keywords)) {
|
|
|
-// System.out.println("关键之:" + keywords);
|
|
|
-// }
|
|
|
PageHelper.startPage(settlementOfflineReq.getPage(), settlementOfflineReq.getPageSize());
|
|
|
-
|
|
|
- List<SettlementOfflineDto> settlementOfflineLogisticsList = settlementOfflineMapper.pageListLogisticsCollection(settlementOfflineReq);
|
|
|
- for (SettlementOfflineDto entity : settlementOfflineLogisticsList) {
|
|
|
- entity.setCreateByText("创建人名称");
|
|
|
- entity.setUpdateByText("更新人名称");
|
|
|
+ List<SettlementOfflineDto> settlementOfflineDto = settlementOfflineMapper.pageList(settlementOfflineReq);
|
|
|
+ if (CollectionUtils.isEmpty(settlementOfflineDto)) {
|
|
|
+ return new PageRes<>();
|
|
|
}
|
|
|
-
|
|
|
- if (CollectionUtils.isEmpty(settlementOfflineLogisticsList)) {
|
|
|
- return new PageRes<>(new PageInfo<>());
|
|
|
- }
|
|
|
-
|
|
|
+ Map<Long, UserCacheResDto> map = new HashMap<>();
|
|
|
//指定返回值
|
|
|
- List<SettlementOfflineVo> collect = settlementOfflineLogisticsList.stream().map(a -> {
|
|
|
+ List<SettlementOfflineVo> collect = settlementOfflineDto.stream().map(a -> {
|
|
|
SettlementOfflineVo settlementOfflineVo = new SettlementOfflineVo();
|
|
|
BeanUtils.copyProperties(a, settlementOfflineVo);
|
|
|
+
|
|
|
+ Long createBy = a.getCreateBy();
|
|
|
+ Long updateBy = a.getUpdateBy();
|
|
|
+ UserCacheResDto userCacheResDto = map.get(createBy);
|
|
|
+ if (Objects.isNull(userCacheResDto)) {
|
|
|
+ userCacheResDto = remoteSystemService.queryUserCacheById(createBy);
|
|
|
+ map.put(createBy, userCacheResDto);
|
|
|
+ }
|
|
|
+ if (Objects.nonNull(userCacheResDto)) {
|
|
|
+ settlementOfflineVo.setCreateByText(userCacheResDto.getName());
|
|
|
+ }
|
|
|
+ userCacheResDto = map.get(updateBy);
|
|
|
+ if (Objects.isNull(userCacheResDto)) {
|
|
|
+ userCacheResDto = remoteSystemService.queryUserCacheById(updateBy);
|
|
|
+ map.put(updateBy, userCacheResDto);
|
|
|
+ }
|
|
|
+ if (Objects.nonNull(userCacheResDto)) {
|
|
|
+ settlementOfflineVo.setUpdateByText(userCacheResDto.getName());
|
|
|
+ }
|
|
|
return settlementOfflineVo;
|
|
|
}).collect(Collectors.toList());
|
|
|
-
|
|
|
return new PageRes<>(new PageInfo<>(collect));
|
|
|
}
|
|
|
|
|
|
- public Integer confirmTradeCollection(Long id, Float price) {
|
|
|
- log.info("接收到数据,开始物流-物流-线下付款(销售收款)记录-新增,待完善");
|
|
|
- //todo 待完善
|
|
|
- //先查询出结算单情况
|
|
|
-
|
|
|
- //检查结算单状态和所差金额
|
|
|
-
|
|
|
- //对比金额
|
|
|
-
|
|
|
- //累加入库结算单
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public String confirmTradeCollection(SettlementOfflinePayReq payReq) {
|
|
|
+ SettlementTradeDto byId = settlementTradeService.getById(payReq.getSettlementIdLong());
|
|
|
+ if (Objects.isNull(byId)) {
|
|
|
+ throw new BusinessException("结算单不存在");
|
|
|
+ }
|
|
|
+ if (TradingEnum.OFFLINE_PAY.getStatus() != byId.getTrading()) {
|
|
|
+ throw new BusinessException("只支持线下付款交易方法进行线下结算");
|
|
|
+ }
|
|
|
+ BigDecimal totalPrice = byId.getTotalPrice();
|
|
|
+ BigDecimal actualPrice = byId.getActualPrice();
|
|
|
+ if (Objects.isNull(totalPrice)) {
|
|
|
+ throw new BusinessException("总应收异常");
|
|
|
+ }
|
|
|
+ if (Objects.isNull(actualPrice)) {
|
|
|
+ throw new BusinessException("已收款金额异常");
|
|
|
+ }
|
|
|
+ //总应收-已收款=剩余待付款
|
|
|
+ BigDecimal subtract = totalPrice.subtract(actualPrice);
|
|
|
+ //本次付款金额
|
|
|
+ BigDecimal payPrice = payReq.getPayPrice();
|
|
|
+ //剩余待付款-本次付款=下次剩余待付款
|
|
|
+ BigDecimal subtract1 = subtract.subtract(payPrice);
|
|
|
+ if (subtract1.compareTo(new BigDecimal("0.0")) < 0) {
|
|
|
+ throw new BusinessException("实际付款金额大于剩余待付款金额");
|
|
|
+ }
|
|
|
+ KwpSettlementTrade kwpSettlementTrade = new KwpSettlementTrade();
|
|
|
+ kwpSettlementTrade.setId(byId.getId());
|
|
|
+ kwpSettlementTrade.setActualPrice(actualPrice.add(payPrice));//已收款加本次收款
|
|
|
+ kwpSettlementTrade.setStatus(1);
|
|
|
+ kwpSettlementTrade.setUpdateBy(LoginUserHolder.getUserId());
|
|
|
+ kwpSettlementTrade.setUpdateTime(LocalDateTime.now());
|
|
|
+ settlementTradeService.updateById(kwpSettlementTrade);
|
|
|
|
|
|
- //新增电子钱包结算记录
|
|
|
KwpSettlementOffline kwpSettlementOffline = new KwpSettlementOffline();
|
|
|
kwpSettlementOffline.setId(new IdWorker(1).nextId());
|
|
|
+ kwpSettlementOffline.setEntId(LoginUserHolder.getEntId());
|
|
|
+ kwpSettlementOffline.setSettlementId(byId.getId());
|
|
|
+ kwpSettlementOffline.setOrderType(payReq.getOrderType());
|
|
|
+ kwpSettlementOffline.setPayTime(LocalDateTime.now());
|
|
|
+ kwpSettlementOffline.setPayPrice(payReq.getPayPrice());
|
|
|
+ kwpSettlementOffline.setTopayPrice(subtract1);
|
|
|
+ kwpSettlementOffline.setUrl(payReq.getUrl());
|
|
|
+ kwpSettlementOffline.setRemark("");
|
|
|
+ kwpSettlementOffline.setStatus(0);
|
|
|
+ kwpSettlementOffline.setCreateBy(LoginUserHolder.getUserId());
|
|
|
+ kwpSettlementOffline.setCreateTime(LocalDateTime.now());
|
|
|
+ kwpSettlementOffline.setUpdateBy(LoginUserHolder.getUserId());
|
|
|
+ kwpSettlementOffline.setUpdateTime(LocalDateTime.now());
|
|
|
+ kwpSettlementOffline.setDelFlag(0);
|
|
|
|
|
|
- //todo 待完善
|
|
|
settlementOfflineMapper.insert(kwpSettlementOffline);
|
|
|
- return settlementOfflineMapper.confirmLogisticsCollection(id, price);
|
|
|
+ return "";
|
|
|
}
|
|
|
}
|