✨ 应收账单保存计费失败状态并导出说明及黄色标注

This commit is contained in:
caojia
2026-10-14 17:50:03 +08:00
parent 996d854492
commit e4438d6f01
8 changed files with 157 additions and 51 deletions
@@ -118,7 +118,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where f.bill_id = p.bill_id
and f.ar_bill_status = #{feeArBillStatus}) as income_total,
p.pay_total, p.currency, p.ar_bill_status,
p.customer_active_status, p.credit_arrears_status, p.refund_status, p.round_mode,
p.customer_active_status, p.credit_arrears_status, p.refund_status, p.billing_fail_status, p.round_mode,
p.created_by, p.create_time, p.updated_by, p.update_time
from prc_order_bill p
left join prc_order_bill_ext e on e.bill_id = p.bill_id
@@ -358,6 +358,29 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</if>
</sql>
<!-- 有未出账费用的订单,或尚未纳入有效账单的无费用计费失败订单。 -->
<sql id="arBillEligibleSourceCondition">
and (
exists (
select 1 from prc_income_bill_fee f
where f.bill_id = p.bill_id and f.ar_bill_status = #{feeArBillStatus}
)
or (
p.billing_fail_status in (1, 2, 3)
and not exists (
select 1 from prc_income_bill_fee f where f.bill_id = p.bill_id
)
and not exists (
select 1 from ar_bill_detail d
inner join ar_bill b on b.ar_bill_id = d.ar_bill_id
where d.prc_order_bill_id = p.bill_id
and d.billing_fail_status in (1, 2, 3)
and b.status &lt;&gt; 'VOID' and b.generation_status &lt;&gt; 'FAILED'
)
)
)
</sql>
<select id="selectPrcOrderBillByCustomerPeriod" resultMap="PrcOrderBillArSourceResult">
<include refid="selectArBillSourceVo"/>
where p.customer_id = #{customerId}
@@ -385,11 +408,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<foreach collection="arBillStatuses" item="status" open="(" separator="," close=")">
#{status}
</foreach>
and exists (
select 1 from prc_income_bill_fee f
where f.bill_id = p.bill_id
and f.ar_bill_status = #{feeArBillStatus}
)
<include refid="arBillEligibleSourceCondition"/>
<if test="currency != null and currency != ''">
and p.currency = #{currency}
</if>
@@ -448,11 +467,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<foreach collection="arBillStatuses" item="status" open="(" separator="," close=")">
#{status}
</foreach>
and exists (
select 1 from prc_income_bill_fee f
where f.bill_id = p.bill_id
and f.ar_bill_status = #{feeArBillStatus}
)
<include refid="arBillEligibleSourceCondition"/>
<if test="currency != null and currency != ''">
and p.currency = #{currency}
</if>
@@ -499,11 +514,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<foreach collection="arBillStatuses" item="status" open="(" separator="," close=")">
#{status}
</foreach>
and exists (
select 1 from prc_income_bill_fee f
where f.bill_id = p.bill_id
and f.ar_bill_status = #{feeArBillStatus}
)
<include refid="arBillEligibleSourceCondition"/>
and p.bill_id in
<foreach collection="billIds" item="billId" open="(" separator="," close=")">
#{billId}
@@ -662,7 +673,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
and p.ar_bill_status = #{fromStatus}
</update>
<!-- 订单状态由来源费用状态汇总,避免补录或删除费用后状态失真。 -->
<!-- 订单状态按费用汇总;无费用的失败订单以有效账单中的失败快照判断占用。 -->
<update id="refreshArBillStatusByBillIds">
update prc_order_bill o
left join (
@@ -678,7 +689,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
group by bill_id
) f on f.bill_id = o.bill_id
set o.ar_bill_status = case
when f.bill_id is null then 'UNBILLED'
when f.bill_id is null then case when exists (
select 1 from ar_bill_detail d
inner join ar_bill b on b.ar_bill_id = d.ar_bill_id
where d.prc_order_bill_id = o.bill_id
and d.billing_fail_status in (1, 2, 3)
and b.status &lt;&gt; 'VOID' and b.generation_status &lt;&gt; 'FAILED'
) then 'BILLED' else 'UNBILLED' end
when f.unbilled_count > 0 and f.billed_count > 0 then 'PARTIAL'
when f.unbilled_count > 0 then 'UNBILLED'
when f.billed_count = f.fee_count then 'BILLED'
@@ -712,7 +729,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
group by f.bill_id
) fee_summary on fee_summary.bill_id = o.bill_id
set o.ar_bill_status = case
when fee_summary.bill_id is null then 'UNBILLED'
when fee_summary.bill_id is null then case when exists (
select 1 from ar_bill_detail d
inner join ar_bill b on b.ar_bill_id = d.ar_bill_id
where d.prc_order_bill_id = o.bill_id
and d.billing_fail_status in (1, 2, 3)
and b.status &lt;&gt; 'VOID' and b.generation_status &lt;&gt; 'FAILED'
and b.ar_bill_id &lt;&gt; #{arBillId}
) then 'BILLED' else 'UNBILLED' end
when fee_summary.unbilled_count > 0 and fee_summary.billed_count > 0 then 'PARTIAL'
when fee_summary.unbilled_count > 0 then 'UNBILLED'
when fee_summary.billed_count = fee_summary.fee_count then 'BILLED'