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

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
@@ -16,6 +16,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="productCode" column="product_code"/>
<result property="productName" column="product_name"/>
<result property="goodsDescription" column="goods_description"/>
<result property="billingFailStatus" column="billing_fail_status"/>
<result property="countryCode" column="country_code"/>
<result property="countryName" column="country_name"/>
<result property="destPostcode" column="dest_postcode"/>
@@ -41,7 +42,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
select detail_id, ar_bill_id, prc_order_bill_id, detail_no, order_no, tracking_no, transfer_no, receive_time,
product_code, product_name, goods_description, country_code, country_name, dest_postcode,
actual_weight, receive_weight, volume_weight, charge_weight, freight_rate, registration_fee, pkg_length, pkg_width, pkg_height,
currency, total_amount, product_amount, redline_amount, remark, create_by, create_time
currency, total_amount, product_amount, redline_amount, billing_fail_status, remark, create_by, create_time
from ar_bill_detail where ar_bill_id = #{arBillId} order by detail_no
</select>
@@ -49,7 +50,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
select detail_id, ar_bill_id, prc_order_bill_id, detail_no, order_no, tracking_no, transfer_no, receive_time,
product_code, product_name, goods_description, country_code, country_name, dest_postcode,
actual_weight, receive_weight, volume_weight, charge_weight, freight_rate, registration_fee, pkg_length, pkg_width, pkg_height,
currency, total_amount, product_amount, redline_amount, remark, create_by, create_time
currency, total_amount, product_amount, redline_amount, billing_fail_status, remark, create_by, create_time
from ar_bill_detail
where ar_bill_id = #{arBillId}
and prc_order_bill_id in
@@ -87,7 +88,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
select d.detail_id, d.ar_bill_id, d.prc_order_bill_id, d.detail_no, d.order_no, d.tracking_no, d.transfer_no, d.receive_time,
d.product_code, d.product_name, d.goods_description, d.country_code, d.country_name, d.dest_postcode,
d.actual_weight, d.receive_weight, d.volume_weight, d.charge_weight, d.freight_rate, d.registration_fee, d.pkg_length, d.pkg_width, d.pkg_height,
d.currency, d.total_amount, d.product_amount, d.redline_amount, d.remark, d.create_by, d.create_time,
d.currency, d.total_amount, d.product_amount, d.redline_amount, d.billing_fail_status, d.remark, d.create_by, d.create_time,
f.detail_fee_id as fee_detail_id, f.detail_id as fee_parent_detail_id,
f.prc_income_bill_fee_id as fee_prc_income_bill_fee_id,
f.fee_no, f.fee_type, f.fee_name, f.sc_id as fee_sc_id, f.quantity as fee_quantity,
@@ -106,7 +107,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
select detail_id, ar_bill_id, prc_order_bill_id, detail_no, order_no, tracking_no, transfer_no, receive_time,
product_code, product_name, goods_description, country_code, country_name, dest_postcode,
actual_weight, receive_weight, volume_weight, charge_weight, freight_rate, registration_fee, pkg_length, pkg_width, pkg_height,
currency, total_amount, product_amount, redline_amount, remark, create_by, create_time
currency, total_amount, product_amount, redline_amount, billing_fail_status, remark, create_by, create_time
from ar_bill_detail
where ar_bill_id = #{arBillId} and detail_no &gt; #{lastDetailNo}
order by detail_no
@@ -125,12 +126,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
product_name, goods_description, country_code, country_name, dest_postcode,
actual_weight, receive_weight,
volume_weight, charge_weight, freight_rate, registration_fee, pkg_length, pkg_width, pkg_height, currency,
total_amount, product_amount, redline_amount,
total_amount, product_amount, redline_amount, billing_fail_status,
remark, create_by, create_time)
values (#{arBillId}, #{prcOrderBillId}, #{detailNo}, #{orderNo}, #{trackingNo}, #{transferNo}, #{receiveTime},
#{productCode}, #{productName}, #{goodsDescription}, #{countryCode}, #{countryName},
#{destPostcode}, #{actualWeight}, #{receiveWeight}, #{volumeWeight}, #{chargeWeight}, #{freightRate}, #{registrationFee}, #{pkgLength}, #{pkgWidth},
#{pkgHeight}, #{currency}, #{totalAmount}, #{productAmount}, #{redlineAmount}, #{remark}, #{createBy}, sysdate())
#{pkgHeight}, #{currency}, #{totalAmount}, #{productAmount}, #{redlineAmount}, #{billingFailStatus}, #{remark}, #{createBy}, sysdate())
</insert>
<insert id="insertBatch" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="detailId">
@@ -138,7 +139,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
ar_bill_id, prc_order_bill_id, detail_no, order_no, tracking_no, transfer_no, receive_time, product_code,
product_name, goods_description, country_code, country_name, dest_postcode, actual_weight, receive_weight,
volume_weight, charge_weight, freight_rate, registration_fee, pkg_length, pkg_width, pkg_height, currency, total_amount,
product_amount, redline_amount,
product_amount, redline_amount, billing_fail_status,
remark, create_by, create_time
) values
<foreach collection="list" item="item" separator=",">
@@ -146,7 +147,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{item.transferNo}, #{item.receiveTime}, #{item.productCode}, #{item.productName}, #{item.goodsDescription},
#{item.countryCode}, #{item.countryName}, #{item.destPostcode}, #{item.actualWeight}, #{item.receiveWeight},
#{item.volumeWeight}, #{item.chargeWeight}, #{item.freightRate}, #{item.registrationFee}, #{item.pkgLength}, #{item.pkgWidth}, #{item.pkgHeight},
#{item.currency}, #{item.totalAmount}, #{item.productAmount}, #{item.redlineAmount},
#{item.currency}, #{item.totalAmount}, #{item.productAmount}, #{item.redlineAmount}, #{item.billingFailStatus},
#{item.remark}, #{item.createBy}, sysdate())
</foreach>
</insert>
@@ -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'