Merge branch 'test' into feauture-20261104

# Conflicts:
#	bms-back/bms-system/src/main/java/com/bms/price/mapper/PrcOrderBillMapper.java
This commit is contained in:
liuminghui
2026-11-09 15:37:55 +08:00
46 changed files with 2238 additions and 83 deletions
@@ -11,6 +11,11 @@
<result property="customerId" column="customer_id"/>
<result property="customerCode" column="customer_code"/>
<result property="customerName" column="customer_name"/>
<result property="profitCustomerArea" column="profit_customer_area"/>
<result property="profitSalesUserId" column="profit_sales_user_id"/>
<result property="profitSalesUserCode" column="profit_sales_user_code"/>
<result property="profitSalesUserName" column="profit_sales_user_name"/>
<result property="profitSnapshotSource" column="profit_snapshot_source"/>
<result property="billPeriodStart" column="bill_period_start"/>
<result property="billPeriodEnd" column="bill_period_end"/>
<result property="billDate" column="bill_date"/>
@@ -48,6 +53,11 @@
customer_id,
customer_code,
customer_name,
profit_customer_area,
profit_sales_user_id,
profit_sales_user_code,
profit_sales_user_name,
profit_snapshot_source,
bill_period_start,
bill_period_end,
bill_date,
@@ -169,13 +179,15 @@
</select>
<insert id="insertArBill" parameterType="ArBill" useGeneratedKeys="true" keyProperty="arBillId">
insert into ar_bill (bill_no, bill_name, customer_id, customer_code, customer_name, bill_period_start,
insert into ar_bill (bill_no, bill_name, customer_id, customer_code, customer_name,
profit_customer_area, profit_sales_user_id, profit_sales_user_code, profit_sales_user_name, profit_snapshot_source, bill_period_start,
bill_period_end,
bill_date, currency, order_count, total_amount, written_off_amount, unwritten_amount,
status, generation_status, bill_version, bank_account_name, bank_account_no, bank_name,
remark,
confirmed_by, confirmed_time, create_by, create_user_id, create_time, update_by, update_time)
values (#{billNo}, #{billName}, #{customerId}, #{customerCode}, #{customerName}, #{billPeriodStart},
values (#{billNo}, #{billName}, #{customerId}, #{customerCode}, #{customerName},
#{profitCustomerArea}, #{profitSalesUserId}, #{profitSalesUserCode}, #{profitSalesUserName}, #{profitSnapshotSource}, #{billPeriodStart},
#{billPeriodEnd},
#{billDate}, #{currency}, #{orderCount}, #{totalAmount}, #{writtenOffAmount}, #{unwrittenAmount},
#{status}, #{generationStatus}, #{billVersion}, #{bankAccountName}, #{bankAccountNo}, #{bankName},
@@ -0,0 +1,187 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bms.ar.mapper.ArCommissionMapper">
<resultMap id="rate" type="com.bms.ar.profit.ArCommissionRate">
<id property="rateId" column="rate_id"/><result property="salesUserId" column="sales_user_id"/>
<result property="salesUserCode" column="sales_user_code"/><result property="salesUserName" column="sales_user_name"/>
<result property="rate" column="rate"/><result property="effectiveAt" column="effective_at"/>
<result property="createBy" column="create_by"/><result property="remark" column="remark"/>
</resultMap>
<resultMap id="missingRate" type="com.bms.ar.profit.ArWriteoffRate">
<id property="writeoffId" column="writeoff_id"/><result property="arBillId" column="ar_bill_id"/>
<result property="billNo" column="bill_no"/><result property="customerName" column="customer_name"/>
<result property="salesUserId" column="sales_user_id"/><result property="salesUserName" column="sales_user_name"/>
<result property="writeoffAmount" column="writeoff_amount"/><result property="writeoffDate" column="writeoff_date"/>
<result property="rate" column="rate"/>
<result property="status" column="status"/><result property="confirmedBy" column="confirmed_by"/>
<result property="confirmedTime" column="confirmed_time"/><result property="remark" column="confirm_remark"/>
</resultMap>
<resultMap id="commissionResult" type="com.bms.ar.profit.ArCommissionResult">
<id property="resultId" column="result_id"/><result property="arBillId" column="ar_bill_id"/>
<result property="detailId" column="detail_id"/><result property="billNo" column="bill_no"/>
<result property="orderNo" column="order_no"/><result property="salesUserName" column="sales_user_name"/>
<result property="currency" column="currency"/><result property="grossProfit" column="gross_profit"/>
<result property="commissionAmount" column="commission_amount"/><result property="resultStatus" column="result_status"/>
<result property="createTime" column="create_time"/>
<result property="reversedBy" column="reversed_by"/><result property="reversedTime" column="reversed_time"/>
<result property="salesUserId" column="sales_user_id"/><result property="weightedRate" column="weighted_rate"/>
<result property="billAmount" column="bill_amount"/>
</resultMap>
<resultMap id="commissionSummary" type="com.bms.ar.profit.ArCommissionSummary">
<result property="salesUserId" column="sales_user_id"/><result property="salesUserName" column="sales_user_name"/>
<result property="currency" column="currency"/><result property="orderCount" column="order_count"/>
<result property="pendingCount" column="pending_count"/><result property="commissionAmount" column="commission_amount"/>
</resultMap>
<select id="selectRates" resultMap="rate">
select r.rate_id, r.sales_user_id, u.user_name as sales_user_code, u.nick_name as sales_user_name,
r.rate, r.effective_at, r.create_by, r.remark
from ar_profit_commission_rate r left join sys_user u on u.user_id = r.sales_user_id
order by r.sales_user_id, r.effective_at desc, r.rate_id desc
</select>
<select id="selectEffective" resultMap="rate">
select rate_id, sales_user_id, rate, effective_at
from ar_profit_commission_rate
where sales_user_id = #{salesUserId} and effective_at &lt;= #{at}
order by effective_at desc, rate_id desc limit 1 for update
</select>
<insert id="insertRate" parameterType="com.bms.ar.profit.ArCommissionRate" useGeneratedKeys="true" keyProperty="rateId">
insert into ar_profit_commission_rate(sales_user_id, rate, effective_at, create_by, create_time, remark)
values(#{salesUserId}, #{rate}, #{effectiveAt}, #{createBy}, sysdate(), #{remark})
</insert>
<select id="lockSalesUser" resultType="long">
select user_id from sys_user where user_id = #{salesUserId} for update
</select>
<insert id="insertWriteoffRate">
insert into ar_profit_writeoff_rate(writeoff_id, sales_user_id, rate_id, rate, create_time)
values(#{writeoffId}, #{salesUserId}, #{rateId}, #{rate}, sysdate())
</insert>
<select id="selectMissingRates" resultMap="missingRate">
select w.writeoff_id, b.ar_bill_id, b.bill_no, b.customer_name,
b.profit_sales_user_id as sales_user_id, b.profit_sales_user_name as sales_user_name,
w.writeoff_amount, w.writeoff_date, r.rate
from ar_balance_writeoff w join ar_bill b on b.ar_bill_id = w.ar_bill_id
left join ar_profit_writeoff_rate r on r.writeoff_id = w.writeoff_id
where w.status = 'EFFECTIVE' and (r.rate is null or r.rate &lt; 0 or r.rate > 100)
and b.status in ('CONFIRMED', 'PARTIAL_WRITTEN_OFF', 'WRITTEN_OFF')
and b.generation_status = 'READY'
order by w.writeoff_date desc, w.writeoff_id desc
</select>
<select id="selectWriteoffRates" resultMap="missingRate">
select w.writeoff_id, b.ar_bill_id, b.bill_no, b.customer_name,
b.profit_sales_user_id as sales_user_id, b.profit_sales_user_name as sales_user_name,
w.writeoff_amount, w.writeoff_date, w.status, r.rate, r.confirmed_by, r.confirmed_time, r.confirm_remark
from ar_balance_writeoff w join ar_bill b on b.ar_bill_id = w.ar_bill_id
left join ar_profit_writeoff_rate r on r.writeoff_id = w.writeoff_id
where b.ar_bill_id = #{billId} and b.generation_status = 'READY'
and b.status in ('CONFIRMED', 'PARTIAL_WRITTEN_OFF', 'WRITTEN_OFF')
order by w.create_time, w.writeoff_id
</select>
<select id="selectBillIdByWriteoffId" resultType="long">
select ar_bill_id from ar_balance_writeoff where writeoff_id = #{writeoffId} and status = 'EFFECTIVE'
</select>
<select id="countMissingRates" resultType="int">
select count(*) from ar_balance_writeoff w
left join ar_profit_writeoff_rate r on r.writeoff_id = w.writeoff_id
where w.ar_bill_id = #{billId} and w.status = 'EFFECTIVE' and (r.rate is null or r.rate &lt; 0 or r.rate > 100)
</select>
<update id="confirmMissingRate">
update ar_profit_writeoff_rate r
join ar_balance_writeoff w on w.writeoff_id = r.writeoff_id and w.status = 'EFFECTIVE'
join ar_bill b on b.ar_bill_id = w.ar_bill_id
set r.sales_user_id = b.profit_sales_user_id, r.rate = #{rate}, r.confirmed_by = #{operator},
r.confirmed_time = sysdate(), r.confirm_remark = #{remark}
where r.writeoff_id = #{writeoffId} and r.rate is null and b.profit_sales_user_id is not null
</update>
<select id="selectResults" resultMap="commissionResult">
select r.result_id, r.ar_bill_id, r.detail_id, b.bill_no, d.order_no,
b.profit_sales_user_name as sales_user_name, r.currency, r.gross_profit,
r.commission_amount, r.result_status, r.create_time, r.reversed_by, r.reversed_time
from ar_profit_commission_result r join ar_bill b on b.ar_bill_id = r.ar_bill_id
join ar_bill_detail d on d.detail_id = r.detail_id
where 1 = 1
<choose>
<when test="includeReversed">and (r.result_status = 'REVERSED' or (b.status = 'WRITTEN_OFF' and b.generation_status = 'READY'))</when>
<otherwise>and r.result_status != 'REVERSED' and b.status = 'WRITTEN_OFF' and b.generation_status = 'READY'</otherwise>
</choose>
<if test="billId != null">and r.ar_bill_id = #{billId}</if>
order by r.result_id desc
</select>
<select id="selectCommissionSummary" resultMap="commissionSummary">
select r.sales_user_id, max(b.profit_sales_user_name) as sales_user_name, r.currency,
count(*) as order_count,
sum(case when r.result_status != 'READY' then 1 else 0 end) as pending_count,
<choose>
<when test="billId != null">
case when sum(case when r.result_status != 'READY' then 1 else 0 end) > 0 then null
else sum(case when r.result_status = 'READY' then r.commission_amount else null end) end
</when>
<otherwise>sum(case when r.result_status = 'READY' then r.commission_amount else null end)</otherwise>
</choose> as commission_amount
from ar_profit_commission_result r join ar_bill b on b.ar_bill_id = r.ar_bill_id
where r.result_status != 'REVERSED' and b.status = 'WRITTEN_OFF' and b.generation_status = 'READY'
<if test="billId != null">and r.ar_bill_id = #{billId}</if>
group by r.sales_user_id, r.currency
order by sales_user_name, r.currency
</select>
<update id="reverseResults">
update ar_profit_commission_result
set result_status = 'REVERSED', reversed_by = #{operator}, reversed_time = sysdate()
where ar_bill_id = #{billId} and result_status != 'REVERSED'
</update>
<!-- 当且仅当账单全部核销时,以当次费用快照及每笔有效核销的比例生成正式记录。 -->
<select id="selectSettlementInputs" resultMap="commissionResult">
<bind name="shenzhenArea" value="@com.bms.price.enums.ProfitAreaRule@SHENZHEN.getCustomerArea()"/>
<bind name="guangzhouArea" value="@com.bms.price.enums.ProfitAreaRule@GUANGZHOU.getCustomerArea()"/>
select x.ar_bill_id, x.detail_id, x.profit_sales_user_id as sales_user_id, x.currency, x.gross_profit,
x.weighted_rate, x.total_amount as bill_amount, coalesce(x.issue, 'READY') as result_status
from (
select b.ar_bill_id, d.detail_id, b.profit_sales_user_id, d.currency, b.total_amount, w.weighted_rate,
case when f.currency_count = 1 and f.fee_currency = d.currency and d.currency = b.currency and f.sales_amount = d.total_amount and b.profit_customer_area = #{shenzhenArea} and f.product_complete = 1
then f.sales_amount - f.product_amount
when f.currency_count = 1 and f.fee_currency = d.currency and d.currency = b.currency and f.sales_amount = d.total_amount and b.profit_customer_area = #{guangzhouArea} and f.redline_complete = 1
then f.sales_amount - f.redline_amount else null end as gross_profit,
case when b.profit_sales_user_id is null or b.profit_customer_area is null
or b.profit_customer_area not in (#{shenzhenArea},#{guangzhouArea}) then 'MISSING_SNAPSHOT'
when w.bill_id is null or w.written_amount != b.total_amount then 'WRITEOFF_MISMATCH'
when w.missing_rates > 0 then 'MISSING_RATE'
when b.total_amount is null or b.total_amount &lt;= 0 or d.total_amount is null
or d.currency is null or b.currency is null or f.sales_amount is null
or f.currency_count != 1 or f.fee_currency != d.currency or d.currency != b.currency
or f.sales_amount != d.total_amount
or (b.profit_customer_area = #{shenzhenArea} and coalesce(f.product_complete, 0) = 0)
or (b.profit_customer_area = #{guangzhouArea} and coalesce(f.redline_complete, 0) = 0)
then 'MISSING_PRICE'
else null end as issue
from ar_bill b inner join ar_bill_detail d on d.ar_bill_id = b.ar_bill_id
left join (
select fee.detail_id, case when count(fee.amount) = count(*) then sum(fee.amount) else null end as sales_amount,
case when count(fee.currency) = count(*) then count(distinct fee.currency) else 0 end as currency_count, min(fee.currency) as fee_currency,
case when count(fee.product_amount) = count(*) then sum(fee.product_amount) else null end as product_amount,
case when count(fee.redline_amount) = count(*) then sum(fee.redline_amount) else null end as redline_amount,
case when count(fee.product_amount) = count(*) then 1 else 0 end as product_complete,
case when count(fee.redline_amount) = count(*) then 1 else 0 end as redline_complete
from ar_bill_detail_fee fee join ar_bill_detail detail on detail.detail_id = fee.detail_id
where detail.ar_bill_id = #{billId} group by fee.detail_id
) f on f.detail_id = d.detail_id
left join (
select w.ar_bill_id as bill_id, sum(w.writeoff_amount) as written_amount,
sum(case when r.rate is null or r.rate &lt; 0 or r.rate > 100 then 1 else 0 end) as missing_rates,
sum(w.writeoff_amount * r.rate) as weighted_rate
from ar_balance_writeoff w left join ar_profit_writeoff_rate r on r.writeoff_id = w.writeoff_id
where w.status = 'EFFECTIVE' and w.ar_bill_id = #{billId}
group by w.ar_bill_id
) w on w.bill_id = b.ar_bill_id
where b.ar_bill_id = #{billId} and b.status = 'WRITTEN_OFF' and b.generation_status = 'READY'
) x order by x.detail_id
</select>
<insert id="insertResults">
insert into ar_profit_commission_result
(ar_bill_id, detail_id, sales_user_id, currency, gross_profit, commission_amount, result_status, create_by, create_time)
values
<foreach collection="items" item="item" separator=",">
(#{item.arBillId}, #{item.detailId}, #{item.salesUserId}, #{item.currency}, #{item.grossProfit},
#{item.commissionAmount}, #{item.resultStatus}, #{operator}, sysdate())
</foreach>
</insert>
</mapper>
@@ -0,0 +1,158 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bms.ar.mapper.ArProfitMapper">
<resultMap id="row" type="com.bms.ar.profit.ArProfitRow">
<id property="arBillId" column="ar_bill_id"/>
<result property="billNo" column="bill_no"/><result property="billDate" column="bill_date"/>
<result property="customerCode" column="customer_code"/><result property="customerName" column="customer_name"/>
<result property="customerArea" column="customer_area"/><result property="snapshotSource" column="snapshot_source"/>
<result property="salesUserName" column="sales_user_name"/><result property="currency" column="currency"/>
<result property="status" column="status"/><result property="salesAmount" column="sales_amount"/>
<result property="productAmount" column="product_amount"/><result property="salesGrossProfit" column="sales_gross_profit"/>
<result property="salesGrossMarginRate" column="sales_gross_margin_rate"/>
<result property="writtenOffAmount" column="written_off_amount"/><result property="unwrittenAmount" column="unwritten_amount"/>
</resultMap>
<resultMap id="summary" type="com.bms.ar.profit.ArProfitSummary">
<result property="currency" column="currency"/><result property="billCount" column="bill_count"/>
<result property="invalidBillCount" column="invalid_bill_count"/>
<result property="salesAmount" column="sales_amount"/><result property="productAmount" column="product_amount"/>
<result property="salesGrossProfit" column="sales_gross_profit"/><result property="salesGrossMarginRate" column="sales_gross_margin_rate"/>
<result property="writtenOffAmount" column="written_off_amount"/><result property="unwrittenAmount" column="unwritten_amount"/>
</resultMap>
<resultMap id="detail" type="com.bms.ar.domain.ArBillDetail">
<id property="detailId" column="detail_id"/><result property="orderNo" column="order_no"/>
<result property="productName" column="product_name"/><result property="currency" column="currency"/>
<result property="totalAmount" column="total_amount"/>
</resultMap>
<resultMap id="fee" type="com.bms.ar.domain.ArBillDetailFee">
<id property="detailFeeId" column="detail_fee_id"/><result property="detailId" column="detail_id"/>
<result property="feeName" column="fee_name"/><result property="feeType" column="fee_type"/>
<result property="amount" column="amount"/><result property="productAmount" column="product_amount"/>
<result property="redlineAmount" column="redline_amount"/><result property="currency" column="currency"/>
</resultMap>
<sql id="scopeCondition">
<choose>
<when test="scope.all"/>
<when test="scope.self or scope.department">
and (1 = 0
<if test="scope.self">or b.profit_sales_user_id = #{scope.userId}</if>
<if test="scope.department">
or exists (select 1 from sys_user u inner join sys_dept dept on dept.dept_id = u.dept_id
where u.user_id = b.profit_sales_user_id and u.del_flag = '0'
and (dept.dept_id = #{scope.deptId} or find_in_set(#{scope.deptId}, dept.ancestors)))
</if>
)
</when>
<otherwise>and 1 = 0</otherwise>
</choose>
</sql>
<!-- 订单号仅用于筛选账单,不限制该账单内参与计算的明细。 -->
<sql id="billConditions">
where b.status in ('CONFIRMED', 'PARTIAL_WRITTEN_OFF', 'WRITTEN_OFF') and b.generation_status = 'READY'
<include refid="scopeCondition"/>
<if test="query.customerId != null">and b.customer_id = #{query.customerId}</if>
<if test="query.billNo != null and query.billNo != ''">and b.bill_no like concat('%', #{query.billNo}, '%')</if>
<if test="query.arBillId != null">and b.ar_bill_id = #{query.arBillId}</if>
<if test="query.orderNo != null and query.orderNo != ''">
and exists (select 1 from ar_bill_detail matched where matched.ar_bill_id = b.ar_bill_id
and matched.order_no like concat('%', #{query.orderNo}, '%'))
</if>
<if test="query.status != null and query.status != ''">and b.status = #{query.status}</if>
<if test="query.salesUserId != null">and b.profit_sales_user_id = #{query.salesUserId}</if>
<if test="query.beginBillDate != null">and b.bill_date &gt;= #{query.beginBillDate}</if>
<if test="query.endBillDate != null">and b.bill_date &lt;= #{query.endBillDate}</if>
</sql>
<!-- 按费用快照先聚合到订单,再聚合到完整账单,避免账单金额及费用重复。 -->
<sql id="billRows">
<bind name="shenzhenArea" value="@com.bms.price.enums.ProfitAreaRule@SHENZHEN.getCustomerArea()"/>
<bind name="guangzhouArea" value="@com.bms.price.enums.ProfitAreaRule@GUANGZHOU.getCustomerArea()"/>
select b.ar_bill_id, b.bill_no, b.bill_date, b.customer_code, b.customer_name,
b.profit_customer_area as customer_area, b.profit_snapshot_source as snapshot_source,
b.profit_sales_user_name as sales_user_name, b.currency, b.status,
b.total_amount as sales_amount, b.written_off_amount, b.unwritten_amount,
case when a.detail_count > 0 and a.invalid_count = 0 and b.total_amount is not null
and a.detail_total = b.total_amount then a.product_total else null end as product_amount,
case when a.detail_count > 0 and a.invalid_count = 0 and b.total_amount is not null
and a.detail_total = b.total_amount then b.total_amount - a.product_total else null end as sales_gross_profit,
case when a.detail_count > 0 and a.invalid_count = 0 and b.total_amount is not null
and a.detail_total = b.total_amount and b.total_amount != 0
then round((b.total_amount - a.product_total) * 100 / b.total_amount, 4) else null end as sales_gross_margin_rate,
case when a.detail_count > 0 and a.invalid_count = 0 and b.total_amount is not null
and a.detail_total = b.total_amount then 0 else 1 end as profit_incomplete
from ar_bill b
left join (
select d.ar_bill_id, count(*) as detail_count, sum(d.total_amount) as detail_total,
sum(case when d.total_amount is not null and d.currency is not null and b.currency is not null
and d.currency = b.currency and f.currency_count = 1 and f.fee_currency = d.currency
and f.sales_amount is not null and f.sales_amount = d.total_amount
and ((b.profit_customer_area = #{shenzhenArea} and f.product_complete = 1)
or (b.profit_customer_area = #{guangzhouArea} and f.redline_complete = 1))
then 0 else 1 end) as invalid_count,
sum(case when b.profit_customer_area = #{shenzhenArea} then f.product_amount
when b.profit_customer_area = #{guangzhouArea} then f.redline_amount else null end) as product_total
from ar_bill_detail d join ar_bill b on b.ar_bill_id = d.ar_bill_id
left join (
select fee.detail_id,
case when count(fee.amount) = count(*) then sum(fee.amount) else null end as sales_amount,
case when count(fee.currency) = count(*) then count(distinct fee.currency) else 0 end as currency_count,
min(fee.currency) as fee_currency,
case when count(fee.product_amount) = count(*) then sum(fee.product_amount) else null end as product_amount,
case when count(fee.redline_amount) = count(*) then sum(fee.redline_amount) else null end as redline_amount,
case when count(fee.product_amount) = count(*) then 1 else 0 end as product_complete,
case when count(fee.redline_amount) = count(*) then 1 else 0 end as redline_complete
from ar_bill_detail_fee fee
join ar_bill_detail d on d.detail_id = fee.detail_id
join ar_bill b on b.ar_bill_id = d.ar_bill_id
<include refid="billConditions"/>
group by fee.detail_id
) f on f.detail_id = d.detail_id
<include refid="billConditions"/>
group by d.ar_bill_id
) a on a.ar_bill_id = b.ar_bill_id
<include refid="billConditions"/>
</sql>
<select id="selectBills" resultMap="row">
<include refid="billRows"/>
order by b.bill_date desc, b.ar_bill_id desc
</select>
<select id="selectSummary" resultMap="summary">
select t.currency, count(*) as bill_count, sum(t.profit_incomplete) as invalid_bill_count,
sum(t.sales_amount) as sales_amount, sum(t.product_amount) as product_amount,
sum(t.sales_gross_profit) as sales_gross_profit,
case when sum(case when t.profit_incomplete = 0 then t.sales_amount else null end) = 0 then null
else round(sum(t.sales_gross_profit) * 100 /
sum(case when t.profit_incomplete = 0 then t.sales_amount else null end), 4) end as sales_gross_margin_rate,
sum(t.written_off_amount) as written_off_amount, sum(t.unwritten_amount) as unwritten_amount
from (<include refid="billRows"/>) t group by t.currency order by t.currency
</select>
<select id="selectSalesOptions" resultType="com.bms.ar.profit.ArProfitSalesOption">
select u.user_id as userId, u.nick_name as name, u.user_name as code
from sys_user u
where u.del_flag = '0' and u.status = '0'
<if test="keyword != null and keyword != ''">
and (u.nick_name like concat('%', #{keyword}, '%')
or u.user_name like concat('%', #{keyword}, '%'))
</if>
order by u.nick_name, u.user_id
limit 50
</select>
<select id="selectBillDetails" resultMap="detail">
select d.detail_id, d.order_no, d.product_name, d.currency, d.total_amount
from ar_bill_detail d join ar_bill b on b.ar_bill_id = d.ar_bill_id
where b.ar_bill_id = #{query.arBillId}
and b.status in ('CONFIRMED', 'PARTIAL_WRITTEN_OFF', 'WRITTEN_OFF') and b.generation_status = 'READY'
<include refid="scopeCondition"/>
order by d.detail_no, d.detail_id
</select>
<select id="selectFees" resultMap="fee">
select f.* from ar_bill_detail_fee f
join ar_bill_detail d on d.detail_id = f.detail_id
join ar_bill b on b.ar_bill_id = d.ar_bill_id
where d.detail_id = #{query.detailId}
and b.status in ('CONFIRMED', 'PARTIAL_WRITTEN_OFF', 'WRITTEN_OFF') and b.generation_status = 'READY'
<include refid="scopeCondition"/>
order by f.fee_no, f.detail_fee_id
</select>
</mapper>
@@ -1077,4 +1077,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
update_time = sysdate()
where bill_id = #{billId}
</update>
<select id="countByPsvId" resultType="int">
select count(1) from prc_order_bill where psv_id = #{psvId}
</select>
</mapper>