Refactor billing options retrieval to include data permissions and add effective date handling for product imports

This commit is contained in:
wuweihua
2026-10-09 09:27:28 +08:00
parent fea34d1d10
commit c95a9861cc
42 changed files with 984 additions and 219 deletions
@@ -191,8 +191,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<update id="refreshStatusByDates">
update product_country
set status = case
when expire_date is not null and expire_date &lt;= curdate() then '2'
when effective_date is null or effective_date &gt; curdate() then '0'
when expire_date is not null and expire_date &lt;= now() then '2'
when effective_date is null or effective_date &gt; now() then '0'
else '1'
end
</update>
@@ -206,8 +206,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<update id="refreshStatusByDates">
update product
set status = case
when expire_date is not null and expire_date &lt;= curdate() then '2'
when effective_date is null or effective_date &gt; curdate() then '0'
when expire_date is not null and expire_date &lt;= now() then '2'
when effective_date is null or effective_date &gt; now() then '0'
else '1'
end
</update>
@@ -12,6 +12,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="feeName" column="fee_name" />
<result property="scId" column="sc_id" />
<result property="amount" column="amount" />
<result property="productAmount" column="product_amount" />
<result property="redlineAmount" column="redline_amount" />
<result property="currency" column="currency" />
<result property="roundMode" column="round_mode" />
<result property="remark" column="remark" />
@@ -21,7 +23,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<select id="selectByBillId" parameterType="String" resultMap="PrcIncomeBillFeeResult">
select fee_id, bill_id, income_bill_id, fee_type, fee_name, sc_id, amount, currency, round_mode, remark,
select fee_id, bill_id, income_bill_id, fee_type, fee_name, sc_id, amount, product_amount, redline_amount, currency, round_mode, remark,
ar_bill_status, manual_flag, create_time
from prc_income_bill_fee
where bill_id = #{billId}
@@ -29,7 +31,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select>
<select id="selectByBillIds" resultMap="PrcIncomeBillFeeResult">
select fee_id, bill_id, income_bill_id, fee_type, fee_name, sc_id, amount, currency, round_mode, remark,
select fee_id, bill_id, income_bill_id, fee_type, fee_name, sc_id, amount, product_amount, redline_amount, currency, round_mode, remark,
ar_bill_status, manual_flag, create_time
from prc_income_bill_fee
where bill_id in
@@ -40,7 +42,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select>
<select id="selectUnbilledByBillIds" resultMap="PrcIncomeBillFeeResult">
select fee_id, bill_id, income_bill_id, fee_type, fee_name, sc_id, amount, currency, round_mode, remark,
select fee_id, bill_id, income_bill_id, fee_type, fee_name, sc_id, amount, product_amount, redline_amount, currency, round_mode, remark,
ar_bill_status, manual_flag, create_time
from prc_income_bill_fee
where ar_bill_status = #{arBillStatus}
@@ -52,7 +54,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select>
<select id="selectByFeeId" parameterType="String" resultMap="PrcIncomeBillFeeResult">
select fee_id, bill_id, income_bill_id, fee_type, fee_name, sc_id, amount, currency, round_mode, remark,
select fee_id, bill_id, income_bill_id, fee_type, fee_name, sc_id, amount, product_amount, redline_amount, currency, round_mode, remark,
ar_bill_status, manual_flag, create_time
from prc_income_bill_fee
where fee_id = #{feeId}
@@ -68,21 +70,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<insert id="insertPrcIncomeBillFee" parameterType="PrcIncomeBillFee">
insert into prc_income_bill_fee (
fee_id, bill_id, income_bill_id, fee_type, fee_name, sc_id, amount, currency, round_mode, remark,
fee_id, bill_id, income_bill_id, fee_type, fee_name, sc_id, amount, product_amount, redline_amount, currency, round_mode, remark,
ar_bill_status, manual_flag, create_time
) values (
#{feeId}, #{billId}, #{incomeBillId}, #{feeType}, #{feeName}, #{scId}, #{amount}, #{currency}, #{roundMode}, #{remark},
#{feeId}, #{billId}, #{incomeBillId}, #{feeType}, #{feeName}, #{scId}, #{amount}, #{productAmount}, #{redlineAmount}, #{currency}, #{roundMode}, #{remark},
#{arBillStatus}, #{manualFlag}, sysdate()
)
</insert>
<insert id="insertBatch" parameterType="java.util.List">
insert into prc_income_bill_fee (
fee_id, bill_id, income_bill_id, fee_type, fee_name, sc_id, amount, currency, round_mode, remark,
fee_id, bill_id, income_bill_id, fee_type, fee_name, sc_id, amount, product_amount, redline_amount, currency, round_mode, remark,
ar_bill_status, manual_flag, create_time
) values
<foreach collection="list" item="item" separator=",">
(#{item.feeId}, #{item.billId}, #{item.incomeBillId}, #{item.feeType}, #{item.feeName}, #{item.scId}, #{item.amount},
#{item.productAmount}, #{item.redlineAmount},
#{item.currency}, #{item.roundMode}, #{item.remark},
#{item.arBillStatus}, #{item.manualFlag}, sysdate())
</foreach>
@@ -94,6 +97,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
fee_name = #{feeName},
sc_id = #{scId},
amount = #{amount},
product_amount = #{productAmount},
redline_amount = #{redlineAmount},
currency = #{currency},
round_mode = #{roundMode},
remark = #{remark}
@@ -17,6 +17,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="settlementMan" column="settlement_man" />
<result property="settlementManCode" column="settlement_man_code" />
<result property="serviceMan" column="service_man" />
<result property="serviceManCode" column="service_man_code" />
<result property="customerId" column="customer_id" />
<result property="customerCode" column="customer_code" />
<result property="customerName" column="customer_name" />
@@ -77,7 +78,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<sql id="selectPrcOrderBillVo">
select bill_id, bill_key, order_no, tracking_no, transfer_no,
belong_saler, belong_saler_code, settlement_man, settlement_man_code, service_man,
belong_saler, belong_saler_code, settlement_man, settlement_man_code, service_man, service_man_code,
customer_id, customer_code, customer_name,
pieces, actual_weight, volume, volume_weight, pkg_length, pkg_width, pkg_height,
shipper_name, consignee_name, dest_postcode, warehouse_code, order_time, order_remark,
@@ -89,13 +90,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
freight_amount, surcharge_amount, income_total, pay_total, currency, ar_bill_status,
customer_active_status, credit_arrears_status, round_mode,
created_by, create_time, updated_by, update_time
from prc_order_bill
from prc_order_bill p
</sql>
<!-- 应收生成专用来源快照:income_total 只汇总当前仍未出账的费用。 -->
<sql id="selectArBillSourceVo">
select p.bill_id, p.bill_key, p.order_no, p.tracking_no, p.transfer_no,
p.belong_saler, p.belong_saler_code, p.settlement_man, p.settlement_man_code, p.service_man,
p.belong_saler, p.belong_saler_code, p.settlement_man, p.settlement_man_code, p.service_man, p.service_man_code,
p.customer_id, p.customer_code, p.customer_name,
p.pieces, p.actual_weight, p.volume, p.volume_weight, p.pkg_length, p.pkg_width, p.pkg_height,
p.shipper_name, p.consignee_name, p.dest_postcode, p.warehouse_code, p.order_time, p.order_remark,
@@ -150,119 +151,167 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where bill_id = #{billId}
</select>
<!-- 计费列表数据权限:当前用户为销售员或结算员(工号=user_name 或 user_id)可见;
@DataScope 注入 su.user_id / su.dept_id 条件;空则不过滤(管理员/全部数据权限) -->
<sql id="orderBillDataScopeFilter">
<if test="params != null and params.dataScope != null and params.dataScope != ''">
AND EXISTS (
SELECT 1 FROM sys_user su
WHERE su.del_flag = '0'
AND (
(p.belong_saler_code IS NOT NULL AND p.belong_saler_code != ''
AND (su.user_name = p.belong_saler_code COLLATE utf8mb4_general_ci
OR su.user_id = p.belong_saler_code + 0))
OR
(p.settlement_man_code IS NOT NULL AND p.settlement_man_code != ''
AND (su.user_name = p.settlement_man_code COLLATE utf8mb4_general_ci
OR su.user_id = p.settlement_man_code + 0))
)
${params.dataScope}
)
</if>
</sql>
<!-- options query: query + limit, dataScope in query.params -->
<sql id="orderBillDataScopeFilterByQuery">
<if test="query != null and query.params != null and query.params.dataScope != null and query.params.dataScope != ''">
AND EXISTS (
SELECT 1 FROM sys_user su
WHERE su.del_flag = '0'
AND (
(p.belong_saler_code IS NOT NULL AND p.belong_saler_code != ''
AND (su.user_name = p.belong_saler_code COLLATE utf8mb4_general_ci
OR su.user_id = p.belong_saler_code + 0))
OR
(p.settlement_man_code IS NOT NULL AND p.settlement_man_code != ''
AND (su.user_name = p.settlement_man_code COLLATE utf8mb4_general_ci
OR su.user_id = p.settlement_man_code + 0))
)
${query.params.dataScope}
)
</if>
</sql>
<select id="selectOrderNoOptions" resultType="String">
select order_no
from prc_order_bill
select p.order_no
from prc_order_bill p
<where>
<if test="keyword != null and keyword != ''">
order_no like concat('%', #{keyword}, '%')
<if test="query.params != null and query.params.optionKeyword != null and query.params.optionKeyword != ''">
AND p.order_no like concat('%', #{query.params.optionKeyword}, '%')
</if>
<include refid="orderBillDataScopeFilterByQuery"/>
</where>
group by order_no
order by max(create_time) desc
group by p.order_no
order by max(p.create_time) desc
limit #{limit}
</select>
<select id="selectTrackingNoOptions" resultType="String">
select tracking_no
from prc_order_bill
select p.tracking_no
from prc_order_bill p
<where>
<if test="keyword != null and keyword != ''">
tracking_no like concat('%', #{keyword}, '%')
<if test="query.params != null and query.params.optionKeyword != null and query.params.optionKeyword != ''">
AND p.tracking_no like concat('%', #{query.params.optionKeyword}, '%')
</if>
<include refid="orderBillDataScopeFilterByQuery"/>
</where>
group by tracking_no
order by max(create_time) desc
group by p.tracking_no
order by max(p.create_time) desc
limit #{limit}
</select>
<select id="selectTransferNoOptions" resultType="String">
select transfer_no
from prc_order_bill
select p.transfer_no
from prc_order_bill p
<where>
<if test="keyword != null and keyword != ''">
transfer_no like concat('%', #{keyword}, '%')
<if test="query.params != null and query.params.optionKeyword != null and query.params.optionKeyword != ''">
AND p.transfer_no like concat('%', #{query.params.optionKeyword}, '%')
</if>
<include refid="orderBillDataScopeFilterByQuery"/>
</where>
group by transfer_no
order by max(create_time) desc
group by p.transfer_no
order by max(p.create_time) desc
limit #{limit}
</select>
<select id="selectPrcOrderBillList" parameterType="PrcOrderBill" resultMap="PrcOrderBillResult">
<include refid="selectPrcOrderBillVo"/>
<where>
<if test="billId != null and billId != ''">
AND p.bill_id = #{billId}
</if>
<if test="orderNo != null and orderNo != ''">
AND order_no like concat('%', #{orderNo}, '%')
AND p.order_no like concat('%', #{orderNo}, '%')
</if>
<if test="orderNos != null and orderNos.size() > 0">
AND order_no IN
AND p.order_no IN
<foreach collection="orderNos" item="ono" open="(" separator="," close=")">
#{ono}
</foreach>
</if>
<if test="trackingNo != null and trackingNo != ''">
AND tracking_no like concat('%', #{trackingNo}, '%')
AND p.tracking_no like concat('%', #{trackingNo}, '%')
</if>
<if test="trackingNos != null and trackingNos.size() > 0">
AND tracking_no IN
AND p.tracking_no IN
<foreach collection="trackingNos" item="tno" open="(" separator="," close=")">
#{tno}
</foreach>
</if>
<if test="transferNo != null and transferNo != ''">
AND transfer_no like concat('%', #{transferNo}, '%')
AND p.transfer_no like concat('%', #{transferNo}, '%')
</if>
<if test="transferNos != null and transferNos.size() > 0">
AND transfer_no IN
AND p.transfer_no IN
<foreach collection="transferNos" item="rno" open="(" separator="," close=")">
#{rno}
</foreach>
</if>
<if test="customerActiveStatus != null and customerActiveStatus != ''">
AND customer_active_status = #{customerActiveStatus}
AND p.customer_active_status = #{customerActiveStatus}
</if>
<if test="creditArrearsStatus != null and creditArrearsStatus != ''">
AND credit_arrears_status = #{creditArrearsStatus}
AND p.credit_arrears_status = #{creditArrearsStatus}
</if>
<if test="customerCode != null and customerCode != ''">
AND customer_code like concat('%', #{customerCode}, '%')
AND p.customer_code like concat('%', #{customerCode}, '%')
</if>
<if test="customerCodes != null and customerCodes.size() > 0">
AND customer_code IN
AND p.customer_code IN
<foreach collection="customerCodes" item="ccode" open="(" separator="," close=")">
#{ccode}
</foreach>
</if>
<if test="customerName != null and customerName != ''">
AND customer_name like concat('%', #{customerName}, '%')
AND p.customer_name like concat('%', #{customerName}, '%')
</if>
<if test="productCode != null and productCode != ''">
AND product_code like concat('%', #{productCode}, '%')
AND p.product_code like concat('%', #{productCode}, '%')
</if>
<if test="productCodes != null and productCodes.size() > 0">
AND product_code IN
AND p.product_code IN
<foreach collection="productCodes" item="pcode" open="(" separator="," close=")">
#{pcode}
</foreach>
</if>
<if test="countryCode != null and countryCode != ''">
AND country_code = #{countryCode}
AND p.country_code = #{countryCode}
</if>
<if test="matchSource != null and matchSource != ''">
AND match_source = #{matchSource}
AND p.match_source = #{matchSource}
</if>
<if test="bizDate != null">
AND biz_date = #{bizDate}
AND p.biz_date = #{bizDate}
</if>
<if test="params.beginTime != null and params.beginTime != ''">
AND date_format(create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
AND date_format(p.create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
</if>
<if test="params.endTime != null and params.endTime != ''">
AND date_format(create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
AND date_format(p.create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
</if>
<include refid="orderBillDataScopeFilter"/>
</where>
order by create_time desc, bill_id desc
order by p.create_time desc, p.bill_id desc
</select>
<!-- rename_bill_tables.sql 已将需求文档中的 prc_bill 映射为本项目的 prc_order_bill。 -->
@@ -449,7 +498,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<insert id="insertPrcOrderBill" parameterType="PrcOrderBill">
insert into prc_order_bill (
bill_id, bill_key, order_no, tracking_no, transfer_no,
belong_saler, belong_saler_code, settlement_man, settlement_man_code, service_man,
belong_saler, belong_saler_code, settlement_man, settlement_man_code, service_man, service_man_code,
customer_id, customer_code, customer_name,
pieces, actual_weight, volume, volume_weight, pkg_length, pkg_width, pkg_height,
shipper_name, consignee_name, dest_postcode, warehouse_code, order_time, order_remark,
@@ -463,7 +512,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
create_time
) values (
#{billId}, #{billKey}, #{orderNo}, #{trackingNo}, #{transferNo},
#{belongSaler}, #{belongSalerCode}, #{settlementMan}, #{settlementManCode}, #{serviceMan},
#{belongSaler}, #{belongSalerCode}, #{settlementMan}, #{settlementManCode}, #{serviceMan}, #{serviceManCode},
#{customerId}, #{customerCode}, #{customerName},
#{pieces}, #{actualWeight}, #{volume}, #{volumeWeight}, #{pkgLength}, #{pkgWidth}, #{pkgHeight},
#{shipperName}, #{consigneeName}, #{destPostcode}, #{warehouseCode}, #{orderTime}, #{orderRemark},
@@ -488,6 +537,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
settlement_man = #{settlementMan},
settlement_man_code = #{settlementManCode},
service_man = #{serviceMan},
service_man_code = #{serviceManCode},
customer_id = #{customerId},
customer_code = #{customerCode},
customer_name = #{customerName},
@@ -137,6 +137,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectUserVo"/>
where u.user_name = #{userName} and u.del_flag = '0'
</select>
<select id="selectUserByNickName" parameterType="String" resultMap="SysUserResult">
<include refid="selectUserVo"/>
where u.nick_name = #{nickName} and u.del_flag = '0'
order by case when u.status = '0' then 0 else 1 end, u.user_id
limit 1
</select>
<select id="selectUserById" parameterType="Long" resultMap="SysUserResult">
<include refid="selectUserVo"/>