|
|
@@ -1,10 +1,30 @@
|
|
|
package com.sckw.freight.service.freight.impl;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.sckw.freight.entity.freight.KwpLedgerLogistics;
|
|
|
import com.sckw.freight.entity.freight.KwpSettlementLogistics;
|
|
|
import com.sckw.freight.mapper.freight.KwpSettlementLogisticsMapper;
|
|
|
+import com.sckw.freight.model.enums.DelFlagEnum;
|
|
|
+import com.sckw.freight.model.enums.SettlementLogisticsStatusEnum;
|
|
|
+import com.sckw.freight.model.vo.request.RequestSettlementLogisticsPageInfo;
|
|
|
+import com.sckw.freight.model.vo.response.ResponsePageData;
|
|
|
+import com.sckw.freight.model.vo.response.ResponseSettlementLogistics;
|
|
|
+import com.sckw.freight.service.freight.IKwpLedgerLogisticsService;
|
|
|
import com.sckw.freight.service.freight.IKwpSettlementLogisticsService;
|
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.sckw.freight.util.DateTimeUtil;
|
|
|
+import com.sckw.freight.util.R;
|
|
|
+import com.sckw.freight.util.SnowflakeIdUtil;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
|
@@ -17,4 +37,136 @@ import org.springframework.stereotype.Service;
|
|
|
@Service
|
|
|
public class KwpSettlementLogisticsServiceImpl extends ServiceImpl<KwpSettlementLogisticsMapper, KwpSettlementLogistics> implements IKwpSettlementLogisticsService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ IKwpLedgerLogisticsService iKwpLedgerLogisticsService;
|
|
|
+ @Autowired
|
|
|
+ KwpSettlementLogisticsMapper kwpSettlementLogisticsMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description: 添加物流结算单 由支付后的回调添加支付记录
|
|
|
+ * 注意: 这儿的结算单如同 只是一条收款明细。
|
|
|
+ * <p>
|
|
|
+ * 步骤
|
|
|
+ * 先进性数据验证
|
|
|
+ * 1:根据 lLedgerId 查询物流单对账单信息
|
|
|
+ * 2:插入结算单信息(插入支付记录)
|
|
|
+ * 3:修改物流单对账单状态(如果支付总额已超过对账单)
|
|
|
+ * @author: xj
|
|
|
+ * @date: 2025/1/12 星期日 10:44
|
|
|
+ * @param: lLedgerId 物流单对账单id
|
|
|
+ * @param: price 支付金额
|
|
|
+ * @param: payTime 支付时间
|
|
|
+ * @param: slOrderNo 付款单单号
|
|
|
+ * @param: userid 操作用户id
|
|
|
+ * @return: void
|
|
|
+ **/
|
|
|
+ @Transactional
|
|
|
+ public void addSettlementLogistics(Long lLedgerId, BigDecimal price, String slOrderNo, LocalDateTime payTime, Long userid) {
|
|
|
+ //先进性数据验证
|
|
|
+ KwpLedgerLogistics logistics = verifySettlementLogistics(lLedgerId, price, payTime, userid);
|
|
|
+ //插入结算单信息(插入支付记录)
|
|
|
+ saveSettlementLogistics(logistics, price, slOrderNo, payTime, userid);
|
|
|
+ //修改物流单对账单状态(如果支付总额已超过对账单)
|
|
|
+ iKwpLedgerLogisticsService.updateLedgerLogisticsStatus(logistics, userid);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description:分页查询收款记录
|
|
|
+ * @author: xj
|
|
|
+ * @date: 2025/1/12 星期日 13:48
|
|
|
+ * @param:
|
|
|
+ * @return: null
|
|
|
+ **/
|
|
|
+ @Override
|
|
|
+ public R<ResponsePageData<ResponseSettlementLogistics>> list(RequestSettlementLogisticsPageInfo requestPageInfo) {
|
|
|
+ //分页查询
|
|
|
+ LambdaQueryWrapper<KwpSettlementLogistics> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ if (requestPageInfo.getLLedgerId() != null) {
|
|
|
+ wrapper.eq(KwpSettlementLogistics::getLLedgerId, requestPageInfo.getLLedgerId());
|
|
|
+ }
|
|
|
+ if (requestPageInfo.getSlOrderNo() != null) {
|
|
|
+ wrapper.like(KwpSettlementLogistics::getSlOrderNo, requestPageInfo.getSlOrderNo());
|
|
|
+ }
|
|
|
+ if (requestPageInfo.getPayTime() != null && requestPageInfo.getPayTime().size() == 2) {
|
|
|
+ wrapper.ge(KwpSettlementLogistics::getReceiptTime, requestPageInfo.getPayTime().get(0));
|
|
|
+ wrapper.le(KwpSettlementLogistics::getReceiptTime, requestPageInfo.getPayTime().get(1));
|
|
|
+ }
|
|
|
+ wrapper.orderByDesc(KwpSettlementLogistics::getCreateTime);
|
|
|
+ Page<KwpSettlementLogistics> page = new Page<>(requestPageInfo.getPage(), requestPageInfo.getPageSize());
|
|
|
+ Page<KwpSettlementLogistics> selectPage = kwpSettlementLogisticsMapper.selectPage(page, wrapper);
|
|
|
+
|
|
|
+ if (selectPage.getRecords() == null) selectPage.setRecords(new ArrayList<>());
|
|
|
+ List<ResponseSettlementLogistics> responseSettlementLogisticsStream = selectPage.getRecords().stream().map(item -> {
|
|
|
+
|
|
|
+ ResponseSettlementLogistics responseSettlementLogistics = new ResponseSettlementLogistics();
|
|
|
+ responseSettlementLogistics.setId(item.getId());
|
|
|
+ responseSettlementLogistics.setEntId(item.getEntId());
|
|
|
+ responseSettlementLogistics.setLLedgerId(item.getLLedgerId());
|
|
|
+ responseSettlementLogistics.setSlOrderNo(item.getSlOrderNo());
|
|
|
+ responseSettlementLogistics.setTotalPrice(item.getTotalPrice());
|
|
|
+ responseSettlementLogistics.setReceiptTime(DateTimeUtil.format(item.getReceiptTime(), "YYYY-MM-dd HH:mm:ss"));
|
|
|
+ responseSettlementLogistics.setCreatedTime(DateTimeUtil.format(item.getCreateTime(), "YYYY-MM-dd HH:mm:ss"));
|
|
|
+ responseSettlementLogistics.setRemark(item.getRemark());
|
|
|
+ responseSettlementLogistics.setStatus(item.getStatus());
|
|
|
+ responseSettlementLogistics.setStatusName(SettlementLogisticsStatusEnum.getMsg(item.getStatus()));
|
|
|
+ return responseSettlementLogistics;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ //返回分页数据
|
|
|
+ ResponsePageData<ResponseSettlementLogistics> responsePageData = new ResponsePageData<>();
|
|
|
+ responsePageData.setList(responseSettlementLogisticsStream);
|
|
|
+ responsePageData.setTotal(selectPage.getTotal());
|
|
|
+ responsePageData.setPages(selectPage.getPages());
|
|
|
+ responsePageData.setPage(selectPage.getCurrent());
|
|
|
+ responsePageData.setPageSize(selectPage.getSize());
|
|
|
+ return R.ok(responsePageData);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description:验证参数并返回 物流单对账单信息
|
|
|
+ * @author: xj
|
|
|
+ * @date: 2025/1/12 星期日 11:03
|
|
|
+ * @return: KwpLedgerLogistics
|
|
|
+ **/
|
|
|
+ private KwpLedgerLogistics verifySettlementLogistics(Long lLedgerId, BigDecimal price, LocalDateTime payTime, Long userid) {
|
|
|
+ if (lLedgerId == null) throw new RuntimeException("lLedgerId不能为空");
|
|
|
+ if (price == null) throw new RuntimeException("price不能为空");
|
|
|
+ if (payTime == null) throw new RuntimeException("payTime不能为空");
|
|
|
+ if (userid == null) throw new RuntimeException("userid不能为空");
|
|
|
+ if (price.compareTo(BigDecimal.ZERO) <= 0) throw new RuntimeException("price不能小于等于0");
|
|
|
+ KwpLedgerLogistics logistics = iKwpLedgerLogisticsService.getById(lLedgerId);
|
|
|
+ if (logistics == null) throw new RuntimeException("物流对账单" + lLedgerId + "不存在");
|
|
|
+ return logistics;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description: 保存结算单信息(收款记录)
|
|
|
+ * @author: xj
|
|
|
+ * @date: 2025/1/12 星期日 11:14
|
|
|
+ * @param:
|
|
|
+ * @return: null
|
|
|
+ **/
|
|
|
+ private void saveSettlementLogistics(KwpLedgerLogistics logistics, BigDecimal price, String slOrderNo, LocalDateTime payTime, Long userid) {
|
|
|
+ KwpSettlementLogistics settlementLogistics = new KwpSettlementLogistics();
|
|
|
+ settlementLogistics.setId(SnowflakeIdUtil.getInstance().nextId());
|
|
|
+ settlementLogistics.setEntId(logistics.getEntId());
|
|
|
+ settlementLogistics.setLLedgerId(logistics.getId());
|
|
|
+ settlementLogistics.setSlOrderNo(slOrderNo);
|
|
|
+ settlementLogistics.setName(logistics.getName());
|
|
|
+ settlementLogistics.setTotalPrice(price);
|
|
|
+ settlementLogistics.setActualPrice(price);
|
|
|
+ settlementLogistics.setReceiptTime(payTime);
|
|
|
+ settlementLogistics.setStatus(SettlementLogisticsStatusEnum.FullSettlement.getCode());
|
|
|
+ settlementLogistics.setCreateBy(userid);
|
|
|
+ settlementLogistics.setUpdateBy(userid);
|
|
|
+ settlementLogistics.setCreateTime(LocalDateTime.now());
|
|
|
+ settlementLogistics.setUpdateTime(LocalDateTime.now());
|
|
|
+ settlementLogistics.setDelFlag(DelFlagEnum.NotDelete.getCode());
|
|
|
+
|
|
|
+ boolean save = save(settlementLogistics);
|
|
|
+ if (!save) throw new RuntimeException("保存结算单失败");
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|