Merge pull request 'develop' (#196) from develop into master
Reviewed-on: http://git.xdadan.loc/tanex/emis-service/pulls/196
This commit is contained in:
commit
983b7069b5
@ -613,8 +613,71 @@ public class EmisSettlePayRecordServiceImpl extends EmisBaseService implements I
|
||||
// 删除收款记录
|
||||
emisSettlePayRecordMapper.deleteEmisSettlePayRecordById(id);
|
||||
|
||||
// 重新计算账单收款
|
||||
emisSettleBillService.reCalcSettleBillPayStatus(payRecordOld.getSettleBillNo());
|
||||
// 重新计算账单收款(账单号可能为逗号分隔的多个)
|
||||
if (StringUtils.isNotBlank(payRecordOld.getSettleBillNo())) {
|
||||
List<String> settleBillNos = Arrays.stream(payRecordOld.getSettleBillNo().split(","))
|
||||
.map(String::trim)
|
||||
.filter(org.apache.commons.lang3.StringUtils::isNotBlank)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
for (String settleBillNo : settleBillNos) {
|
||||
emisSettleBillService.reCalcSettleBillPayStatus(settleBillNo);
|
||||
}
|
||||
}
|
||||
|
||||
// 重新计算对应发票的已收金额与付款状态
|
||||
// 规则:发票新的已收金额 = 发票历史已收金额 - 本次(payId)对应的金额汇总
|
||||
// 1) 查询本次收款的运单收款明细(包含applySeqNo)
|
||||
EmisSettlePayRel query = new EmisSettlePayRel();
|
||||
query.setPayId(payRecordOld.getPayId());
|
||||
List<EmisSettlePayRel> thisPayRelList = emisSettlePayRelMapper.selectEmisSettlePayRelList(query);
|
||||
if (!CollectionUtils.isEmpty(thisPayRelList)) {
|
||||
// 2) 按applySeqNo分组汇总本次金额
|
||||
Map<String, BigDecimal> revokeAmountByApplySeqNo = thisPayRelList.stream()
|
||||
.filter(rel -> StringUtils.isNotBlank(rel.getApplySeqNo()))
|
||||
.collect(Collectors.groupingBy(EmisSettlePayRel::getApplySeqNo,
|
||||
Collectors.mapping(EmisSettlePayRel::getPayMoney,
|
||||
Collectors.reducing(BigDecimal.ZERO, v -> v == null ? BigDecimal.ZERO : v,
|
||||
BigDecimal::add))));
|
||||
|
||||
// 3) 对每个发票applySeqNo执行:历史已收金额 - 本次金额,重算状态
|
||||
for (Map.Entry<String, BigDecimal> entry : revokeAmountByApplySeqNo.entrySet()) {
|
||||
String applySeqNo = entry.getKey();
|
||||
BigDecimal revokeAmount = entry.getValue() == null ? BigDecimal.ZERO : entry.getValue();
|
||||
|
||||
EmisSettleInvoiceRecord invoiceRecord = emisSettleInvoiceRecordMapper
|
||||
.selectInvoiceRecordByApplySeqNo(applySeqNo);
|
||||
if (invoiceRecord == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
BigDecimal historyReced = invoiceRecord.getRecedMoney() == null ? BigDecimal.ZERO
|
||||
: invoiceRecord.getRecedMoney();
|
||||
BigDecimal applyMoney = invoiceRecord.getApplyMoney() == null ? BigDecimal.ZERO
|
||||
: invoiceRecord.getApplyMoney();
|
||||
|
||||
// 新的已收金额 = 历史已收金额 - 本次撤销金额,且不小于0
|
||||
BigDecimal newReced = historyReced.subtract(revokeAmount);
|
||||
if (newReced.compareTo(BigDecimal.ZERO) < 0) {
|
||||
newReced = BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
String paymentStatus;
|
||||
if (newReced.compareTo(BigDecimal.ZERO) == 0) {
|
||||
paymentStatus = "0"; // 未付款
|
||||
} else if (newReced.compareTo(applyMoney) >= 0) {
|
||||
paymentStatus = "1"; // 已付款
|
||||
} else {
|
||||
paymentStatus = "2"; // 部分付款
|
||||
}
|
||||
|
||||
EmisSettleInvoiceRecord upd = new EmisSettleInvoiceRecord();
|
||||
upd.setId(invoiceRecord.getId());
|
||||
upd.setRecedMoney(newReced);
|
||||
upd.setPaymentStatus(paymentStatus);
|
||||
emisSettleInvoiceRecordMapper.updateEmisSettleInvoiceRecord(upd);
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -655,7 +655,23 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<select id="getInvoiceAmountsByPayIds" parameterType="java.util.List" resultType="map">
|
||||
select
|
||||
espbr.pay_id,
|
||||
SUM(esir.money) as total_amount
|
||||
(
|
||||
SUM(esir.money)
|
||||
+ COALESCE(
|
||||
(
|
||||
select SUM(COALESCE(r.add_open_money, 0))
|
||||
from emis_settle_invoice_record r
|
||||
where r.del_flag = '0' and r.invoice_status = '2'
|
||||
and r.apply_seq_no in (
|
||||
select distinct esir2.apply_seq_no
|
||||
from emis_settle_pay_bill_rel espbr2
|
||||
left join emis_settle_sub_bill essb2 on espbr2.settle_bill_no = essb2.settle_bill_no
|
||||
left join emis_settle_invoice_rel esir2 on essb2.bill_code = esir2.bill_no
|
||||
where espbr2.del_flag = '0' and essb2.del_flag = '0' and esir2.del_flag = '0'
|
||||
and espbr2.pay_id = espbr.pay_id
|
||||
)
|
||||
), 0)
|
||||
) as total_amount
|
||||
from emis_settle_pay_bill_rel espbr
|
||||
left join emis_settle_sub_bill essb on espbr.settle_bill_no = essb.settle_bill_no
|
||||
left join emis_settle_invoice_rel esir on essb.bill_code = esir.bill_no
|
||||
@ -708,7 +724,25 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
select
|
||||
espbr.pay_id,
|
||||
DATE(esir_record.op_date) as invoice_date,
|
||||
SUM(esir.money) as invoice_amount,
|
||||
(
|
||||
SUM(esir.money)
|
||||
+ COALESCE(
|
||||
(
|
||||
select SUM(COALESCE(r.add_open_money, 0))
|
||||
from emis_settle_invoice_record r
|
||||
where r.del_flag = '0' and r.invoice_status = '2'
|
||||
and DATE(r.op_date) = DATE(esir_record.op_date)
|
||||
and r.company_name = esir_record.company_name
|
||||
and r.apply_seq_no in (
|
||||
select distinct esir2.apply_seq_no
|
||||
from emis_settle_pay_bill_rel espbr2
|
||||
left join emis_settle_sub_bill essb2 on espbr2.settle_bill_no = essb2.settle_bill_no
|
||||
left join emis_settle_invoice_rel esir2 on essb2.bill_code = esir2.bill_no
|
||||
where espbr2.del_flag = '0' and essb2.del_flag = '0' and esir2.del_flag = '0'
|
||||
and espbr2.pay_id = espbr.pay_id
|
||||
)
|
||||
), 0)
|
||||
) as invoice_amount,
|
||||
GROUP_CONCAT(DISTINCT esir_record.company_name SEPARATOR ' ') as company_name,
|
||||
0 as total_invoice_amount,
|
||||
0 as bill_amount
|
||||
@ -732,7 +766,23 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
NULL as invoice_date,
|
||||
0 as invoice_amount,
|
||||
'' as company_name,
|
||||
SUM(CASE WHEN esir_record.invoice_status = '2' THEN esir.money ELSE 0 END) as total_invoice_amount,
|
||||
(
|
||||
SUM(CASE WHEN esir_record.invoice_status = '2' THEN esir.money ELSE 0 END)
|
||||
+ COALESCE(
|
||||
(
|
||||
select SUM(COALESCE(r.add_open_money, 0))
|
||||
from emis_settle_invoice_record r
|
||||
where r.del_flag = '0' and r.invoice_status = '2'
|
||||
and r.apply_seq_no in (
|
||||
select distinct esir2.apply_seq_no
|
||||
from emis_settle_pay_bill_rel espbr2
|
||||
left join emis_settle_sub_bill essb2 on espbr2.settle_bill_no = essb2.settle_bill_no
|
||||
left join emis_settle_invoice_rel esir2 on essb2.bill_code = esir2.bill_no
|
||||
where espbr2.del_flag = '0' and essb2.del_flag = '0' and esir2.del_flag = '0'
|
||||
and espbr2.pay_id = espbr.pay_id
|
||||
)
|
||||
), 0)
|
||||
) as total_invoice_amount,
|
||||
MAX(esb.rec_money) as bill_amount
|
||||
from emis_settle_pay_bill_rel espbr
|
||||
left join emis_settle_sub_bill essb on espbr.settle_bill_no = essb.settle_bill_no
|
||||
|
||||
@ -3,12 +3,13 @@
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.xdadan.erp.emis.mapper.EmisSettlePayRelMapper">
|
||||
|
||||
|
||||
<resultMap type="EmisSettlePayRel" id="EmisSettlePayRelResult" extends="com.xdadan.erp.emis.mapper.EmisBaseMapper.EmisBaseResult">
|
||||
<result property="id" column="id" />
|
||||
<result property="payId" column="pay_id" />
|
||||
<result property="billNo" column="bill_no" />
|
||||
<result property="payMoney" column="pay_money" />
|
||||
<result property="applySeqNo" column="apply_seq_no" />
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="EmisSettlePayRelWithSubBillResult" type="EmisSettlePayRel" extends="EmisSettlePayRelResult" >
|
||||
@ -20,26 +21,50 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectEmisSettlePayRelVo">
|
||||
select id, pay_id, bill_no, pay_money, del_flag, create_by, create_time, update_by, update_time, create_site, update_site from emis_settle_pay_rel
|
||||
select a.id,
|
||||
a.pay_id,
|
||||
a.bill_no,
|
||||
a.pay_money,
|
||||
a.del_flag,
|
||||
a.create_by,
|
||||
a.create_time,
|
||||
a.update_by,
|
||||
a.update_time,
|
||||
a.create_site,
|
||||
a.update_site,
|
||||
(
|
||||
select r.apply_seq_no
|
||||
from emis_settle_invoice_rel r
|
||||
where r.bill_no = a.bill_no
|
||||
and r.del_flag = '0'
|
||||
and exists (
|
||||
select 1 from emis_settle_pay_invoice_rel p
|
||||
where p.apply_seq_no = r.apply_seq_no
|
||||
and p.pay_id = a.pay_id
|
||||
and p.del_flag = '0'
|
||||
)
|
||||
limit 1
|
||||
) as apply_seq_no
|
||||
from emis_settle_pay_rel a
|
||||
</sql>
|
||||
|
||||
<select id="selectEmisSettlePayRelList" parameterType="EmisSettlePayRel" resultMap="EmisSettlePayRelWithSubBillResult">
|
||||
<include refid="selectEmisSettlePayRelVo"/>
|
||||
<where>
|
||||
del_flag='0'
|
||||
<if test="id != null "> and id = #{id}</if>
|
||||
<if test="payId != null and payId != ''"> and pay_id = #{payId}</if>
|
||||
<if test="billNo != null and billNo != ''"> and bill_no = #{billNo}</if>
|
||||
<if test="payMoney != null "> and pay_money = #{payMoney}</if>
|
||||
<if test="delFlag != null and delFlag != ''"> and del_flag like concat('%', #{delFlag}, '%')</if>
|
||||
<if test="createBy != null and createBy != ''"> and create_by like concat('%', #{createBy}, '%')</if>
|
||||
<if test="createTime != null "> and create_time = #{createTime}</if>
|
||||
<if test="updateBy != null and updateBy != ''"> and update_by like concat('%', #{updateBy}, '%')</if>
|
||||
<if test="updateTime != null "> and update_time = #{updateTime}</if>
|
||||
<if test="createSite != null and createSite != ''"> and create_site like concat('%', #{createSite}, '%')</if>
|
||||
<if test="updateSite != null and updateSite != ''"> and update_site like concat('%', #{updateSite}, '%')</if>
|
||||
<where>
|
||||
a.del_flag='0'
|
||||
<if test="id != null "> and a.id = #{id}</if>
|
||||
<if test="payId != null and payId != ''"> and a.pay_id = #{payId}</if>
|
||||
<if test="billNo != null and billNo != ''"> and a.bill_no = #{billNo}</if>
|
||||
<if test="payMoney != null "> and a.pay_money = #{payMoney}</if>
|
||||
<if test="delFlag != null and delFlag != ''"> and a.del_flag like concat('%', #{delFlag}, '%')</if>
|
||||
<if test="createBy != null and createBy != ''"> and a.create_by like concat('%', #{createBy}, '%')</if>
|
||||
<if test="createTime != null "> and a.create_time = #{createTime}</if>
|
||||
<if test="updateBy != null and updateBy != ''"> and a.update_by like concat('%', #{updateBy}, '%')</if>
|
||||
<if test="updateTime != null "> and a.update_time = #{updateTime}</if>
|
||||
<if test="createSite != null and createSite != ''"> and a.create_site like concat('%', #{createSite}, '%')</if>
|
||||
<if test="updateSite != null and updateSite != ''"> and a.update_site like concat('%', #{updateSite}, '%')</if>
|
||||
</where>
|
||||
order by create_time desc
|
||||
order by a.create_time desc
|
||||
</select>
|
||||
|
||||
<select id="selectHasPayListBySettleBillNo" parameterType="String" resultMap="EmisSettlePayRelWithSubBillResult">
|
||||
@ -84,13 +109,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
and update_site = #{updateSite}
|
||||
limit 1
|
||||
</select>
|
||||
|
||||
|
||||
<select id="selectEmisSettlePayRelById" parameterType="Long" resultMap="EmisSettlePayRelResult">
|
||||
select id, pay_id, bill_no, pay_money, del_flag, create_by, create_time, update_by, update_time, create_site, update_site
|
||||
select id, pay_id, bill_no, pay_money, del_flag, create_by, create_time, update_by, update_time, create_site, update_site
|
||||
from emis_settle_pay_rel a
|
||||
where a.id = #{id}
|
||||
</select>
|
||||
|
||||
|
||||
<insert id="insertEmisSettlePayRel" parameterType="EmisSettlePayRel" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into emis_settle_pay_rel
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
@ -148,4 +173,4 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
</mapper>
|
||||
</mapper>
|
||||
|
||||
@ -18,9 +18,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
STR_TO_DATE(CONCAT(DATE_FORMAT(w.send_date, '%Y-%m'), '-01'), '%Y-%m-%d') as bill_month,
|
||||
COUNT(*) as ticket_count
|
||||
FROM emis_tms_site_batch_miss bm
|
||||
LEFT JOIN emis_waybill w ON bm.bill_code = w.bill_code
|
||||
LEFT JOIN emis_site s ON bm.start_site_code = s.site_code
|
||||
WHERE 1=1
|
||||
LEFT JOIN emis_waybill w ON bm.bill_code = w.bill_code AND w.del_flag = '0'
|
||||
LEFT JOIN emis_site s ON bm.start_site_code = s.site_code AND s.del_flag = '0'
|
||||
WHERE bm.del_flag = '0'
|
||||
<if test="startSiteCode != null and startSiteCode != ''">
|
||||
AND bm.start_site_code = #{startSiteCode}
|
||||
</if>
|
||||
@ -62,12 +62,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
LIMIT 1) as product_type_name
|
||||
from emis_tms_site_batch_miss m
|
||||
left join emis_waybill w on m.bill_code = w.bill_code and w.del_flag='0'
|
||||
left join emis_site s1 on w.send_site_code=s1.site_code and s1.del_flag=0
|
||||
left join emis_site s2 on m.start_site_code=s2.site_code and s2.del_flag=0
|
||||
left join emis_site s3 on m.next_site_code=s3.site_code and s3.del_flag=0
|
||||
left join emis_site s1 on w.send_site_code=s1.site_code and s1.del_flag='0'
|
||||
left join emis_site s2 on m.start_site_code=s2.site_code and s2.del_flag='0'
|
||||
left join emis_site s3 on m.next_site_code=s3.site_code and s3.del_flag='0'
|
||||
left join emis_country c1 on w.send_country=c1.code and c1.del_flag='0'
|
||||
left join emis_country c2 on w.receive_country=c2.code and c2.del_flag='0'
|
||||
left join emis_site s4 on w.dispatch_underling_site_code=s4.site_code and s4.del_flag=0
|
||||
left join emis_site s4 on w.dispatch_underling_site_code=s4.site_code and s4.del_flag='0'
|
||||
left join emis_trans_line k on w.trans_line_type=k.line_code and k.del_flag='0'
|
||||
left join emis_trans_plan_rule r on m.trans_plan_rule_id=r.id and r.del_flag='0'
|
||||
left join emis_trans_line l on m.line_code=l.line_code and l.del_flag='0'
|
||||
@ -114,12 +114,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
LIMIT 1) as product_type_name
|
||||
from emis_tms_site_batch_miss m
|
||||
left join emis_waybill w on m.bill_code = w.bill_code and w.del_flag='0'
|
||||
left join emis_site s1 on w.send_site_code=s1.site_code and s1.del_flag=0
|
||||
left join emis_site s2 on m.start_site_code=s2.site_code and s2.del_flag=0
|
||||
left join emis_site s3 on m.next_site_code=s3.site_code and s3.del_flag=0
|
||||
left join emis_site s1 on w.send_site_code=s1.site_code and s1.del_flag='0'
|
||||
left join emis_site s2 on m.start_site_code=s2.site_code and s2.del_flag='0'
|
||||
left join emis_site s3 on m.next_site_code=s3.site_code and s3.del_flag='0'
|
||||
left join emis_country c1 on w.send_country=c1.code and c1.del_flag='0'
|
||||
left join emis_country c2 on w.receive_country=c2.code and c2.del_flag='0'
|
||||
left join emis_site s4 on w.dispatch_underling_site_code=s4.site_code and s4.del_flag=0
|
||||
left join emis_site s4 on w.dispatch_underling_site_code=s4.site_code and s4.del_flag='0'
|
||||
left join emis_trans_line k on w.trans_line_type=k.line_code and k.del_flag='0'
|
||||
left join emis_trans_plan_rule r on m.trans_plan_rule_id=r.id and r.del_flag='0'
|
||||
left join emis_trans_line l on m.line_code=l.line_code and l.del_flag='0'
|
||||
|
||||
Loading…
Reference in New Issue
Block a user