Merge pull request 'develop' (#291) from develop into master

Reviewed-on: http://git.xdadan.loc/tanex/emis-service/pulls/291
This commit is contained in:
heyu 2026-01-12 17:20:02 +08:00
commit f1e5eac0c0
7 changed files with 145 additions and 20 deletions

View File

@ -57,6 +57,8 @@ public class EmisWriteoffApplyController extends EmisBaseController {
emisWriteoffApply = new EmisWriteoffApply(); emisWriteoffApply = new EmisWriteoffApply();
} }
setPrivParams(emisWriteoffApply);
// 处理params参数,支持运单号、账单号多选查询 // 处理params参数,支持运单号、账单号多选查询
if (emisWriteoffApply.getParams() != null && emisWriteoffApply.getParams().containsKey("queryParams")) { if (emisWriteoffApply.getParams() != null && emisWriteoffApply.getParams().containsKey("queryParams")) {
String queryParams = (String) emisWriteoffApply.getParams().get("queryParams"); String queryParams = (String) emisWriteoffApply.getParams().get("queryParams");

View File

@ -1175,27 +1175,32 @@ public class EmisSettleBillServiceImpl extends EmisBaseService implements IEmisS
// 遍历每个发票记录,更新其收款状态 // 遍历每个发票记录,更新其收款状态
for (EmisSettleInvoiceRecord invoiceRecord : invoiceRecordList) { for (EmisSettleInvoiceRecord invoiceRecord : invoiceRecordList) {
String invoiceSettleBillNo = invoiceRecord.getSettleBillNo(); String applySeqNo = invoiceRecord.getApplySeqNo();
if (StringUtils.isEmpty(invoiceSettleBillNo)) { if (StringUtils.isEmpty(applySeqNo)) {
continue;
}
// 通过申请序号获取发票关联的子账单列表
List<EmisSettleInvoiceRel> invoiceRelList = emisSettleInvoiceRelMapper.selectListByApplySeqNo(applySeqNo);
if (CollectionUtils.isEmpty(invoiceRelList)) {
log.debug("updateInvoicePaymentStatus===>发票申请序号{}没有关联的子账单", applySeqNo);
continue; continue;
} }
// 解析发票对应的所有账单号(可能用逗号分隔)
String[] billNoArray = invoiceSettleBillNo.split(",");
BigDecimal totalRecedMoney = BigDecimal.ZERO; BigDecimal totalRecedMoney = BigDecimal.ZERO;
// 遍历发票对应的每个账单号,计算每个账单的实际收款金额并累加 // 遍历发票关联的每个子账单,获取运单已收金额并累加
for (String billNo : billNoArray) { for (EmisSettleInvoiceRel invoiceRel : invoiceRelList) {
billNo = billNo.trim(); String subBillNo = invoiceRel.getBillNo();
if (StringUtils.isEmpty(billNo)) { if (StringUtils.isEmpty(subBillNo)) {
continue; continue;
} }
// 通过账单号查询emis_settle_bill获取reced_money作为已收金额
EmisSettleBill bill = selectEmisSettleBillBySettleBillNo(billNo); // 通过子账单号查询子账单,获取运单已收金额
BigDecimal billTotalHasPayMoney = (bill != null && bill.getRecedMoney() != null) EmisSettleSubBill subBill = emisSettleSubBillMapper.selectSettleSubBillBySubBillNo(subBillNo);
? bill.getRecedMoney() if (subBill != null && subBill.getRecedMoney() != null) {
: BigDecimal.ZERO; totalRecedMoney = totalRecedMoney.add(subBill.getRecedMoney());
totalRecedMoney = totalRecedMoney.add(billTotalHasPayMoney); }
} }
// 获取发票申请金额 // 获取发票申请金额
@ -1219,8 +1224,8 @@ public class EmisSettleBillServiceImpl extends EmisBaseService implements IEmisS
updateInvoiceRecord.setRecedMoney(totalRecedMoney); updateInvoiceRecord.setRecedMoney(totalRecedMoney);
emisSettleInvoiceRecordMapper.updateEmisSettleInvoiceRecord(updateInvoiceRecord); emisSettleInvoiceRecordMapper.updateEmisSettleInvoiceRecord(updateInvoiceRecord);
log.debug("updateInvoicePaymentStatus===>发票申请序号:{}, 收款状态:{}, 已收金额:{}, 申请金额:{}, 对应账单号:{}", log.debug("updateInvoicePaymentStatus===>发票申请序号:{}, 收款状态:{}, 已收金额:{}, 申请金额:{}",
invoiceRecord.getApplySeqNo(), paymentStatus, totalRecedMoney, applyMoney, invoiceSettleBillNo); invoiceRecord.getApplySeqNo(), paymentStatus, totalRecedMoney, applyMoney);
} }
} catch (Exception e) { } catch (Exception e) {

View File

@ -12,6 +12,7 @@ package com.xdadan.erp.emis.service.impl;
import com.xdadan.erp.emis.domain.*; import com.xdadan.erp.emis.domain.*;
import com.xdadan.erp.emis.domain.enumtype.EmisBizErrorType; import com.xdadan.erp.emis.domain.enumtype.EmisBizErrorType;
import com.xdadan.erp.emis.domain.enumtype.WriteoffApplyStatus;
import com.xdadan.erp.emis.domain.exception.EmisBizError; import com.xdadan.erp.emis.domain.exception.EmisBizError;
import com.xdadan.erp.emis.domain.stat.PayBackRecordDtl; import com.xdadan.erp.emis.domain.stat.PayBackRecordDtl;
import com.xdadan.erp.emis.mapper.*; import com.xdadan.erp.emis.mapper.*;
@ -80,6 +81,12 @@ public class EmisSettlePayRecordServiceImpl extends EmisBaseService implements I
@Autowired @Autowired
private EmisWaybillMapper emisWaybillMapper; private EmisWaybillMapper emisWaybillMapper;
@Autowired
private EmisWriteoffApplyMapper emisWriteoffApplyMapper;
@Autowired
private EmisWriteoffApplyDetailMapper emisWriteoffApplyDetailMapper;
/** /**
* 查询账单收退款记录 * 查询账单收退款记录
* *
@ -473,6 +480,9 @@ public class EmisSettlePayRecordServiceImpl extends EmisBaseService implements I
&& !"7".equals(emisSettlePayRecord.getPayType())) { && !"7".equals(emisSettlePayRecord.getPayType())) {
throw new EmisBizError(EmisBizErrorType.FAIL, "业务账单未确认,不允许收款!"); throw new EmisBizError(EmisBizErrorType.FAIL, "业务账单未确认,不允许收款!");
} }
// 校验账单对应的运单是否在销账申请表中,且中心审核状态为未审核
checkWriteoffApplyStatus(settleBillNo);
} }
} }
@ -604,6 +614,63 @@ public class EmisSettlePayRecordServiceImpl extends EmisBaseService implements I
} }
} }
/**
* 校验账单对应的运单是否在销账申请表中,且中心审核状态为未审核
*
* @param settleBillNo 账单号
* @throws EmisBizError 如果存在未审核的销账申请,则抛出异常
*/
private void checkWriteoffApplyStatus(String settleBillNo) throws EmisBizError {
// 根据账单号查询子账单列表,获取运单号列表
List<EmisSettleSubBill> subBillList = emisSettleSubBillMapper.selectSubBillListBySettleBillNo(settleBillNo);
if (CollectionUtils.isEmpty(subBillList)) {
return;
}
// 提取运单号列表
List<String> billCodeList = subBillList.stream()
.map(EmisSettleSubBill::getBillCode)
.filter(StringUtils::isNotBlank)
.distinct()
.collect(Collectors.toList());
if (CollectionUtils.isEmpty(billCodeList)) {
return;
}
// 根据运单号查询销账申请明细
for (String billCode : billCodeList) {
EmisWriteoffApplyDetail queryDetail = new EmisWriteoffApplyDetail();
queryDetail.setBillCode(billCode);
List<EmisWriteoffApplyDetail> detailList = emisWriteoffApplyDetailMapper.selectEmisWriteoffApplyDetailList(queryDetail);
if (CollectionUtils.isEmpty(detailList)) {
continue;
}
// 获取所有申请ID,去重
List<Long> applyIds = detailList.stream()
.map(EmisWriteoffApplyDetail::getApplyId)
.filter(id -> id != null)
.distinct()
.collect(Collectors.toList());
if (CollectionUtils.isEmpty(applyIds)) {
continue;
}
// 查询销账申请,检查中心审核状态
for (Long applyId : applyIds) {
EmisWriteoffApply writeoffApply = emisWriteoffApplyMapper.selectEmisWriteoffApplyById(applyId);
if (writeoffApply != null
&& WriteoffApplyStatus.CENTER_PENDING.statusCode.equals(writeoffApply.getBlCenterConfirmed())) {
throw new EmisBizError(EmisBizErrorType.FAIL,
billCode + "已经登记业务销账申请,请先处理再销账");
}
}
}
}
/** /**
* 收款退款 * 收款退款
* *

View File

@ -153,6 +153,22 @@ public class EmisWriteoffApplyServiceImpl extends EmisBaseService implements IEm
throw new EmisBizError("运单号 " + detail.getBillCode() + " 的账单应收金额为空"); throw new EmisBizError("运单号 " + detail.getBillCode() + " 的账单应收金额为空");
} }
// 检查结算账单的理赔金额、折让金额、抵扣金额、其他金额
if (detail.getEmisSettleBill() == null) {
throw new EmisBizError("运单号 " + detail.getBillCode() + " 的账单信息为空");
}
BigDecimal satisfyMoney = detail.getEmisSettleBill().getSatisfyMoney();
BigDecimal allowanceMoney = detail.getEmisSettleBill().getAllowanceMoney();
BigDecimal deductionMoney = detail.getEmisSettleBill().getDeductionMoney();
BigDecimal otherMoney = detail.getEmisSettleBill().getOtherMoney();
if ((satisfyMoney != null && satisfyMoney.compareTo(BigDecimal.ZERO) != 0) ||
(allowanceMoney != null && allowanceMoney.compareTo(BigDecimal.ZERO) != 0) ||
(deductionMoney != null && deductionMoney.compareTo(BigDecimal.ZERO) != 0) ||
(otherMoney != null && otherMoney.compareTo(BigDecimal.ZERO) != 0)) {
throw new EmisBizError(detail.getBillCode() + " 存在理赔金额/折让金额/抵扣金额/其他金额,请联系财务处理");
}
// 验证:申请金额 + 已收金额 <= 账单应收金额 // 验证:申请金额 + 已收金额 <= 账单应收金额
BigDecimal totalAmount = detail.getApplyMoney().add(receivedAmount); BigDecimal totalAmount = detail.getApplyMoney().add(receivedAmount);
if (totalAmount.compareTo(recMoney) > 0) { if (totalAmount.compareTo(recMoney) > 0) {

View File

@ -353,8 +353,6 @@
when a.settle_type = '2' when a.settle_type = '2'
and a.credit_period = 30 and a.credit_period = 30
and a.settle_day = '1' and a.settle_day = '1'
and b.trade_date <![CDATA[ >= ]]> DATE_ADD(STR_TO_DATE(CONCAT(REPLACE(a.bill_month,'-',''),'01'),'%Y%m%d'), INTERVAL 2 MONTH)
and b.trade_date <![CDATA[ < ]]> DATE_ADD(STR_TO_DATE(CONCAT(REPLACE(a.bill_month,'-',''),'01'),'%Y%m%d'), INTERVAL 3 MONTH)
and NOT EXISTS ( and NOT EXISTS (
SELECT 1 SELECT 1
FROM emis_settle_invoice_record f FROM emis_settle_invoice_record f
@ -371,7 +369,12 @@
end end
) )
) )
then case
when b.trade_date <![CDATA[ >= ]]> DATE_ADD(STR_TO_DATE(CONCAT(REPLACE(a.bill_month,'-',''),'01'),'%Y%m%d'), INTERVAL 2 MONTH)
and b.trade_date <![CDATA[ < ]]> DATE_ADD(STR_TO_DATE(CONCAT(REPLACE(a.bill_month,'-',''),'01'),'%Y%m%d'), INTERVAL 3 MONTH)
then ifnull(d.pay_money,0) then ifnull(d.pay_money,0)
else 0
end
when a.settle_type='2' when a.settle_type='2'
and a.credit_period <![CDATA[ >= ]]> 30 and a.credit_period <![CDATA[ >= ]]> 30
and b.trade_date <![CDATA[ > ]]> a.payment_due_date and b.trade_date <![CDATA[ > ]]> a.payment_due_date
@ -1053,8 +1056,6 @@
when a.settle_type = '2' when a.settle_type = '2'
and a.credit_period = 30 and a.credit_period = 30
and a.settle_day = '1' and a.settle_day = '1'
and b.trade_date <![CDATA[ >= ]]> DATE_ADD(STR_TO_DATE(CONCAT(REPLACE(a.bill_month,'-',''),'01'),'%Y%m%d'), INTERVAL 2 MONTH)
and b.trade_date <![CDATA[ < ]]> DATE_ADD(STR_TO_DATE(CONCAT(REPLACE(a.bill_month,'-',''),'01'),'%Y%m%d'), INTERVAL 3 MONTH)
and NOT EXISTS ( and NOT EXISTS (
SELECT 1 SELECT 1
FROM emis_settle_invoice_record f FROM emis_settle_invoice_record f
@ -1071,7 +1072,12 @@
end end
) )
) )
then case
when b.trade_date <![CDATA[ >= ]]> DATE_ADD(STR_TO_DATE(CONCAT(REPLACE(a.bill_month,'-',''),'01'),'%Y%m%d'), INTERVAL 2 MONTH)
and b.trade_date <![CDATA[ < ]]> DATE_ADD(STR_TO_DATE(CONCAT(REPLACE(a.bill_month,'-',''),'01'),'%Y%m%d'), INTERVAL 3 MONTH)
then ifnull(d.pay_money,0) then ifnull(d.pay_money,0)
else 0
end
when a.settle_type='2' when a.settle_type='2'
and a.credit_period <![CDATA[ >= ]]> 30 and a.credit_period <![CDATA[ >= ]]> 30
and b.trade_date <![CDATA[ > ]]> a.payment_due_date and b.trade_date <![CDATA[ > ]]> a.payment_due_date

View File

@ -575,6 +575,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
and b.trade_date <![CDATA[ > ]]> esb.payment_due_date and b.trade_date <![CDATA[ > ]]> esb.payment_due_date
and b.trade_date <![CDATA[ >= ]]> DATE_SUB( esb.payment_due_date, INTERVAL (esb.credit_period-60) DAY ) and b.trade_date <![CDATA[ >= ]]> DATE_SUB( esb.payment_due_date, INTERVAL (esb.credit_period-60) DAY )
) )
OR
(
( (esb.settle_type='2' and esb.credit_period <![CDATA[ < ]]> 30) or esb.settle_type='1' )
and b.trade_date <![CDATA[ > ]]> esb.payment_due_date
)
) )
</if> </if>

View File

@ -104,6 +104,30 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</foreach> </foreach>
) )
</if> </if>
<if test="params.privSiteCode != null and params.privSiteCode != '88888'">
and (
wa.apply_site_code=#{params.privSiteCode}
or EXISTS (
select 1 from emis_writeoff_apply_detail wad_check
inner join emis_waybill w_check on wad_check.bill_code = w_check.bill_code and w_check.del_flag = '0'
where wad_check.apply_id = wa.id
and wad_check.del_flag = '0'
and (
w_check.salesmen = #{params.privEmpName}
or w_check.payee = #{params.privEmpName}
or EXISTS (
select 1 from emis_salesmen_rel esr
where esr.del_flag = '0'
and esr.bl_open = '1'
and now() <![CDATA[ >= ]]> esr.start_date
and now() <![CDATA[ <= ]]> esr.end_date
and esr.salesmen = w_check.salesmen
and esr.sales_ass = #{params.privEmpName}
)
)
)
)
</if>
</where> </where>
order by wa.create_time desc order by wa.create_time desc
</select> </select>