|
|
@@ -1,22 +1,23 @@
|
|
|
package com.sckw.payment.service;
|
|
|
|
|
|
+import com.alibaba.nacos.shaded.com.google.common.collect.Lists;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
-import com.sckw.core.model.page.PageHelperUtil;
|
|
|
-import com.sckw.core.model.page.PageResult;
|
|
|
+import com.sckw.core.exception.BusinessException;
|
|
|
+import com.sckw.core.model.page.PageRes;
|
|
|
import com.sckw.core.utils.IdWorker;
|
|
|
import com.sckw.payment.dao.KwpLedgerLogisticsMapper;
|
|
|
import com.sckw.payment.dao.KwpLedgerLogisticsOrderMapper;
|
|
|
import com.sckw.payment.dao.KwpLedgerLogisticsTrackMapper;
|
|
|
+import com.sckw.payment.dao.KwpSettlementLogisticsMapper;
|
|
|
import com.sckw.payment.model.KwpLedgerLogistics;
|
|
|
import com.sckw.payment.model.KwpLedgerLogisticsOrder;
|
|
|
import com.sckw.payment.model.KwpLedgerLogisticsTrack;
|
|
|
+import com.sckw.payment.model.KwpSettlementLogistics;
|
|
|
import com.sckw.payment.model.constant.LedgerLicEnum;
|
|
|
import com.sckw.payment.model.dto.LedgerLogisticsDto;
|
|
|
-import com.sckw.payment.model.vo.req.LedgerReq;
|
|
|
-import com.sckw.payment.model.vo.req.LogisticsReq;
|
|
|
-import com.sckw.payment.model.vo.req.LogisticsSendReq;
|
|
|
+import com.sckw.payment.model.vo.req.*;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
@@ -24,7 +25,9 @@ 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.Objects;
|
|
|
|
|
|
/**
|
|
|
* @author xucaiqin
|
|
|
@@ -37,8 +40,15 @@ public class KwpLedgerLogisticsService {
|
|
|
private final KwpLedgerLogisticsMapper logisticsMapper;
|
|
|
private final KwpLedgerLogisticsTrackMapper logisticsTrackMapper;
|
|
|
private final KwpLedgerLogisticsOrderMapper logisticsOrderMapper;
|
|
|
+ private final KwpSettlementLogisticsMapper settlementLogisticsMapper;
|
|
|
|
|
|
- public PageResult pageList(LogisticsReq logisticsReq) {
|
|
|
+ /**
|
|
|
+ * 分页查询物流对账单列表
|
|
|
+ *
|
|
|
+ * @param logisticsReq 查询参数
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public PageRes<LedgerLogisticsDto> pageList(LogisticsReq logisticsReq) {
|
|
|
//todo 查询缓存,获取客户企业id
|
|
|
String keywords = logisticsReq.getKeywords();
|
|
|
if (StringUtils.isNotBlank(keywords)) {
|
|
|
@@ -46,17 +56,36 @@ public class KwpLedgerLogisticsService {
|
|
|
}
|
|
|
PageHelper.startPage(logisticsReq.getPage(), logisticsReq.getPageSize());
|
|
|
|
|
|
- List<LedgerLogisticsDto> kwpLedgerLogisticsList = logisticsMapper.pageSelect(logisticsReq);
|
|
|
+ List<LedgerLogisticsDto> kwpLedgerLogisticsList = logisticsMapper.pageSelect(logisticsReq, new ArrayList<>());
|
|
|
|
|
|
- return PageHelperUtil.getPageResult(new PageInfo<>(kwpLedgerLogisticsList));
|
|
|
+ return new PageRes<>(new PageInfo<>(kwpLedgerLogisticsList));
|
|
|
}
|
|
|
|
|
|
- public Object sendLedger(LogisticsSendReq logisticsReq) {
|
|
|
- return null;
|
|
|
+ /**
|
|
|
+ * 保存物流对账单
|
|
|
+ *
|
|
|
+ * @param logisticsReq
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public String sendLedger(LogisticsSendReq logisticsReq) {
|
|
|
+ Long id = logisticsReq.getId();
|
|
|
+ if (Objects.isNull(id)) {
|
|
|
+ //新增
|
|
|
+ } else {
|
|
|
+ //修改
|
|
|
+ }
|
|
|
+ return "新增对账单成功";
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 保存物流对账单草稿
|
|
|
+ *
|
|
|
+ * @param logisticsReq
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public Object sendLedgerDraft(LogisticsSendReq logisticsReq) {
|
|
|
+ public String sendLedgerDraft(LogisticsSendReq logisticsReq) {
|
|
|
/*插入物流对账单*/
|
|
|
KwpLedgerLogistics kwpLedgerLogistics = new KwpLedgerLogistics();
|
|
|
kwpLedgerLogistics.setId(new IdWorker(1).nextId());
|
|
|
@@ -67,49 +96,88 @@ public class KwpLedgerLogisticsService {
|
|
|
kwpLedgerLogistics.setName(logisticsReq.getName());
|
|
|
kwpLedgerLogistics.setStartTime(logisticsReq.getStartTime());
|
|
|
kwpLedgerLogistics.setEndTime(logisticsReq.getEndTime());
|
|
|
- kwpLedgerLogistics.setTaxRate(new BigDecimal("0"));//todo
|
|
|
- kwpLedgerLogistics.setTrading(logisticsReq.getTrading());//todo
|
|
|
+ kwpLedgerLogistics.setTaxRate(logisticsReq.getTaxRate());//todo 发票税率数据库字段类型
|
|
|
+ kwpLedgerLogistics.setTrading(logisticsReq.getTrading());
|
|
|
+ kwpLedgerLogistics.setTotalPrice(logisticsReq.getTotalPrice());
|
|
|
+ kwpLedgerLogistics.setSettlePrice(logisticsReq.getSettlePrice());
|
|
|
//todo 查询运单
|
|
|
|
|
|
kwpLedgerLogistics.setUnloadAmount(new BigDecimal("0"));
|
|
|
kwpLedgerLogistics.setLoadAmount(new BigDecimal("0"));
|
|
|
kwpLedgerLogistics.setDeficitAmount(new BigDecimal("0"));
|
|
|
kwpLedgerLogistics.setLoseAmount(new BigDecimal("0"));
|
|
|
- kwpLedgerLogistics.setTotalPrice(logisticsReq.getTotalPrice());
|
|
|
- kwpLedgerLogistics.setSettlePrice(logisticsReq.getSettlePrice());
|
|
|
kwpLedgerLogistics.setActualPrice(new BigDecimal("0"));
|
|
|
- kwpLedgerLogistics.setCheckPhone("");//取承运订单的第一条数据
|
|
|
+ kwpLedgerLogistics.setCheckPhone("");//todo 取配置的数据
|
|
|
kwpLedgerLogistics.setCheckUser("");
|
|
|
kwpLedgerLogistics.setCarrierPhone("");
|
|
|
kwpLedgerLogistics.setCarrierUser("");
|
|
|
kwpLedgerLogistics.setGenerateTime(null);
|
|
|
kwpLedgerLogistics.setUrl("");
|
|
|
kwpLedgerLogistics.setRemark(logisticsReq.getRemark());
|
|
|
- kwpLedgerLogistics.setStatus(0);
|
|
|
- kwpLedgerLogistics.setCreateBy(0L);
|
|
|
+ kwpLedgerLogistics.setStatus(LedgerLicEnum.SAVE.getStatus());
|
|
|
+ kwpLedgerLogistics.setCreateBy(0L);//todo
|
|
|
kwpLedgerLogistics.setCreateTime(LocalDateTime.now());
|
|
|
kwpLedgerLogistics.setUpdateBy(0L);
|
|
|
kwpLedgerLogistics.setUpdateTime(LocalDateTime.now());
|
|
|
kwpLedgerLogistics.setDelFlag(0);
|
|
|
logisticsMapper.insert(kwpLedgerLogistics);
|
|
|
/*插入对账关联物流运单*/
|
|
|
- logisticsOrderMapper.insert(new KwpLedgerLogisticsOrder());
|
|
|
- return null;
|
|
|
+ List<Long> ids = logisticsReq.getIds();
|
|
|
+ for (Long id : ids) {
|
|
|
+ KwpLedgerLogisticsOrder kwpLedgerLogisticsOrder = new KwpLedgerLogisticsOrder();
|
|
|
+ kwpLedgerLogisticsOrder.setId(new IdWorker(1).nextId());
|
|
|
+ kwpLedgerLogisticsOrder.setLLedgerId(kwpLedgerLogistics.getId());
|
|
|
+ kwpLedgerLogisticsOrder.setLOrderId(id);
|
|
|
+ kwpLedgerLogisticsOrder.setRemark("");
|
|
|
+ kwpLedgerLogisticsOrder.setStatus(0);
|
|
|
+ logisticsOrderMapper.insert(kwpLedgerLogisticsOrder);
|
|
|
+ }
|
|
|
+ return "保存成功";
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ /**
|
|
|
+ * 删除物流对账单
|
|
|
+ *
|
|
|
+ * @param id 物流对账单id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
public Integer remove(Long id) {
|
|
|
- return logisticsMapper.deleteById(id);
|
|
|
+ KwpLedgerLogistics kwpLedgerLogistics = logisticsMapper.selectById(id);
|
|
|
+ if (Objects.isNull(kwpLedgerLogistics)) {
|
|
|
+ throw new BusinessException("对账单不存在!");
|
|
|
+ }
|
|
|
+ List<Integer> objects = Lists.newArrayList(LedgerLicEnum.BACK.getStatus(), LedgerLicEnum.SAVE.getStatus());
|
|
|
+ if (!objects.contains(kwpLedgerLogistics.getStatus())) {
|
|
|
+ throw new BusinessException("只有【已保存】和【已退回】的单据才支持删除!");
|
|
|
+ }
|
|
|
+ kwpLedgerLogistics.setDelFlag(1);
|
|
|
+ return logisticsMapper.updateById(kwpLedgerLogistics);
|
|
|
}
|
|
|
|
|
|
- public String backOrder(Long id) {
|
|
|
- KwpLedgerLogistics kwpLedgerLogistics = new KwpLedgerLogistics();
|
|
|
- kwpLedgerLogistics.setId(id);
|
|
|
- kwpLedgerLogistics.setStatus(LedgerLicEnum.CANCEL.getStatus());
|
|
|
- logisticsMapper.updateById(kwpLedgerLogistics);
|
|
|
- return null;
|
|
|
+ /**
|
|
|
+ * 撤回物流对账单
|
|
|
+ *
|
|
|
+ * @param id 物流对账单id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Integer backOrder(Long id) {
|
|
|
+ KwpLedgerLogistics kwpLedgerLogistics = logisticsMapper.selectById(id);
|
|
|
+ if (Objects.isNull(kwpLedgerLogistics)) {
|
|
|
+ throw new BusinessException("对账单不存在!");
|
|
|
+ }
|
|
|
+ if (LedgerLicEnum.TO_LEDGER.getStatus() != kwpLedgerLogistics.getStatus()) {
|
|
|
+ throw new BusinessException("只有【待对账】的单据才支持撤销!");
|
|
|
+ }
|
|
|
+ kwpLedgerLogistics.setStatus(LedgerLicEnum.BACK.getStatus());
|
|
|
+ return logisticsMapper.updateById(kwpLedgerLogistics);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 查询物流对账单驳回记录
|
|
|
+ *
|
|
|
+ * @param id 物流对账单id
|
|
|
+ * @return 物流对账单驳回记录
|
|
|
+ */
|
|
|
public List<KwpLedgerLogisticsTrack> queryBack(Long id) {
|
|
|
LambdaQueryWrapper<KwpLedgerLogisticsTrack> wrapper = new LambdaQueryWrapper<>();
|
|
|
wrapper.eq(KwpLedgerLogisticsTrack::getLLedgerId, id);
|
|
|
@@ -117,13 +185,88 @@ public class KwpLedgerLogisticsService {
|
|
|
return logisticsTrackMapper.selectList(wrapper);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 驳回物流对账单
|
|
|
+ *
|
|
|
+ * @param ledgerReq 驳回参数
|
|
|
+ * @return
|
|
|
+ */
|
|
|
public Integer doBack(LedgerReq ledgerReq) {
|
|
|
+ KwpLedgerLogistics kwpLedgerLogistics = logisticsMapper.selectById(ledgerReq.getId());
|
|
|
+ if (Objects.isNull(kwpLedgerLogistics)) {
|
|
|
+ throw new BusinessException("对账单不存在!");
|
|
|
+ }
|
|
|
KwpLedgerLogisticsTrack kwpLedgerLogisticsTrack = new KwpLedgerLogisticsTrack();
|
|
|
kwpLedgerLogisticsTrack.setId(new IdWorker(1).nextId());
|
|
|
kwpLedgerLogisticsTrack.setLLedgerId(ledgerReq.getId());
|
|
|
kwpLedgerLogisticsTrack.setRemark(ledgerReq.getRemark());
|
|
|
kwpLedgerLogisticsTrack.setStatus(0);
|
|
|
-
|
|
|
return logisticsTrackMapper.insert(kwpLedgerLogisticsTrack);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 对账确认
|
|
|
+ * 订单变更为已对账
|
|
|
+ *
|
|
|
+ * @param confirmReq
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Integer confirmOrder(LogisticsConfirmReq confirmReq) {
|
|
|
+ KwpLedgerLogistics kwpLedgerLogistics = logisticsMapper.selectById(confirmReq.getId());
|
|
|
+ if (Objects.isNull(kwpLedgerLogistics)) {
|
|
|
+ throw new BusinessException("对账单不存在!");
|
|
|
+ }
|
|
|
+ kwpLedgerLogistics.setStatus(LedgerLicEnum.LEDGERED.getStatus());
|
|
|
+ kwpLedgerLogistics.setAuditPhone(confirmReq.getAuditPhone());
|
|
|
+ kwpLedgerLogistics.setAuditUser(confirmReq.getAuditUser());
|
|
|
+ kwpLedgerLogistics.setUrl(confirmReq.getUrl());
|
|
|
+ kwpLedgerLogistics.setUpdateTime(LocalDateTime.now());
|
|
|
+ return logisticsMapper.updateById(kwpLedgerLogistics);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 对账完成
|
|
|
+ *
|
|
|
+ * @param ledgerReq
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public String orderSuccess(LedgerSuccessReq ledgerReq) {
|
|
|
+ KwpLedgerLogistics kwpLedgerLogistics = logisticsMapper.selectById(ledgerReq.getId());
|
|
|
+ if (Objects.isNull(kwpLedgerLogistics)) {
|
|
|
+ throw new BusinessException("对账单不存在!");
|
|
|
+ }
|
|
|
+ if (LedgerLicEnum.LEDGERED.getStatus() != kwpLedgerLogistics.getStatus()) {
|
|
|
+ throw new BusinessException("只有【已对账】的订单支持完成对账!");
|
|
|
+ }
|
|
|
+ kwpLedgerLogistics.setStatus(LedgerLicEnum.SUCCESS.getStatus());
|
|
|
+ kwpLedgerLogistics.setAuditPhone(ledgerReq.getSuccessPhone());
|
|
|
+ kwpLedgerLogistics.setAuditUser(ledgerReq.getSuccessUser());
|
|
|
+ kwpLedgerLogistics.setUpdateTime(LocalDateTime.now());
|
|
|
+ logisticsMapper.updateById(kwpLedgerLogistics);
|
|
|
+ //生成结算单
|
|
|
+ KwpSettlementLogistics kwpSettlementLogistics = new KwpSettlementLogistics();
|
|
|
+ kwpSettlementLogistics.setId(new IdWorker(1).nextId());
|
|
|
+ kwpSettlementLogistics.setEntId(0L);//todo
|
|
|
+ kwpSettlementLogistics.setLLedgerId(kwpLedgerLogistics.getId());
|
|
|
+ kwpSettlementLogistics.setSlOrderNo(String.valueOf(new IdWorker(1).nextId()));//todo
|
|
|
+ kwpSettlementLogistics.setName(kwpLedgerLogistics.getName());//取物流对账单名称
|
|
|
+ kwpSettlementLogistics.setTotalPrice(kwpLedgerLogistics.getTotalPrice());
|
|
|
+ kwpSettlementLogistics.setActualPrice(kwpLedgerLogistics.getActualPrice());
|
|
|
+ kwpSettlementLogistics.setReceiptTime(LocalDateTime.now());
|
|
|
+ kwpSettlementLogistics.setRemark("");
|
|
|
+ kwpSettlementLogistics.setAuditUser(kwpLedgerLogistics.getAuditUser());
|
|
|
+ kwpSettlementLogistics.setAuditPhone(kwpLedgerLogistics.getAuditPhone());
|
|
|
+ kwpSettlementLogistics.setSuccessUser(ledgerReq.getSuccessUser());
|
|
|
+ kwpSettlementLogistics.setSuccessPhone(ledgerReq.getSuccessPhone());
|
|
|
+ kwpSettlementLogistics.setStatus(0);
|
|
|
+ kwpSettlementLogistics.setCreateBy(0L);
|
|
|
+ kwpSettlementLogistics.setCreateTime(LocalDateTime.now());
|
|
|
+ kwpSettlementLogistics.setUpdateBy(0L);
|
|
|
+ kwpSettlementLogistics.setUpdateTime(LocalDateTime.now());
|
|
|
+ kwpSettlementLogistics.setDelFlag(0);
|
|
|
+
|
|
|
+ settlementLogisticsMapper.insert(kwpSettlementLogistics);
|
|
|
+ return "对账完成";
|
|
|
+ }
|
|
|
}
|