✨ 新增应收账单按角色和客户归属的行级数据权限

This commit is contained in:
caojia
2026-10-29 16:42:28 +08:00
parent b091d47f64
commit 02c49e3efe
30 changed files with 587 additions and 72 deletions
@@ -77,22 +77,23 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where writeoff_id = #{writeoffId} and status = #{effectiveStatus}
</update>
<select id="selectWriteoffList" parameterType="ArBalanceWriteoff" resultMap="ArBalanceWriteoffResult">
<select id="selectWriteoffList" resultMap="ArBalanceWriteoffResult">
<include refid="selectColumns"/>
<where>
<if test="customerId != null">and w.customer_id = #{customerId}</if>
<if test="arBillId != null">and w.ar_bill_id = #{arBillId}</if>
<if test="status != null and status != ''">and w.status = #{status}</if>
<if test="currency != null and currency != ''">and w.currency = #{currency}</if>
<if test="writeoffNo != null and writeoffNo != ''">and w.writeoff_no like concat('%', #{writeoffNo}, '%')</if>
<if test="billNo != null and billNo != ''">and w.bill_no like concat('%', #{billNo}, '%')</if>
<if test="receiptId != null">and w.receipt_id = #{receiptId}</if>
<if test="params != null and params.beginTime != null and params.beginTime != ''">
and date_format(w.writeoff_date,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
<if test="query.customerId != null">and w.customer_id = #{query.customerId}</if>
<if test="query.arBillId != null">and w.ar_bill_id = #{query.arBillId}</if>
<if test="query.status != null and query.status != ''">and w.status = #{query.status}</if>
<if test="query.currency != null and query.currency != ''">and w.currency = #{query.currency}</if>
<if test="query.writeoffNo != null and query.writeoffNo != ''">and w.writeoff_no like concat('%', #{query.writeoffNo}, '%')</if>
<if test="query.billNo != null and query.billNo != ''">and w.bill_no like concat('%', #{query.billNo}, '%')</if>
<if test="query.receiptId != null">and w.receipt_id = #{query.receiptId}</if>
<if test="query.params != null and query.params.beginTime != null and query.params.beginTime != ''">
and date_format(w.writeoff_date,'%y%m%d') &gt;= date_format(#{query.params.beginTime},'%y%m%d')
</if>
<if test="params != null and params.endTime != null and params.endTime != ''">
and date_format(w.writeoff_date,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
<if test="query.params != null and query.params.endTime != null and query.params.endTime != ''">
and date_format(w.writeoff_date,'%y%m%d') &lt;= date_format(#{query.params.endTime},'%y%m%d')
</if>
<include refid="com.bms.ar.mapper.ArBillScopeMapper.billScope"/>
</where>
order by w.create_time desc, w.writeoff_id desc
</select>
@@ -78,6 +78,34 @@
order by f.fee_no, f.detail_fee_id
</select>
<select id="selectByBillIdAndDetailIdScoped" resultMap="ArBillDetailFeeResult">
select f.detail_fee_id,
f.detail_id,
f.prc_income_bill_fee_id,
f.fee_no,
f.fee_type,
f.fee_name,
f.sc_id,
f.quantity,
f.unit,
f.unit_price,
f.amount,
f.product_amount,
f.redline_amount,
f.currency,
f.calculation_formula,
f.round_mode,
f.remark,
f.create_by,
f.create_time
from ar_bill_detail_fee f
inner join ar_bill_detail d on d.detail_id = f.detail_id
where d.ar_bill_id = #{arBillId}
and f.detail_id = #{detailId}
AND EXISTS (SELECT 1 FROM ar_bill b WHERE b.ar_bill_id = d.ar_bill_id <include refid="com.bms.ar.mapper.ArBillScopeMapper.billScope"/>)
order by f.fee_no, f.detail_fee_id
</select>
<select id="selectByBillId" parameterType="long" resultMap="ArBillDetailFeeResult">
select detail_fee_id,
detail_id,
@@ -46,6 +46,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
from ar_bill_detail where ar_bill_id = #{arBillId} order by detail_no
</select>
<select id="selectByBillIdScoped" resultMap="ArBillDetailResult">
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, billing_fail_status, remark, create_by, create_time
from ar_bill_detail where ar_bill_id = #{arBillId} AND EXISTS (SELECT 1 FROM ar_bill b WHERE b.ar_bill_id = ar_bill_detail.ar_bill_id <include refid="com.bms.ar.mapper.ArBillScopeMapper.billScope"/>)
order by detail_no
</select>
<select id="selectByBillIdAndSourceIds" resultMap="ArBillDetailResult">
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,
@@ -69,6 +69,15 @@
order by create_time desc, task_id desc
</select>
<select id="selectActiveByCreateByScoped" resultMap="ArBillGenerateTaskResult">
<include refid="columns"/>
where create_by = #{createBy}
and status in ('WAITING', 'RUNNING', 'CANCEL_REQUESTED')
AND EXISTS (SELECT 1 FROM ar_bill b WHERE b.ar_bill_id = ar_bill_generate_task.ar_bill_id
<include refid="com.bms.ar.mapper.ArBillScopeMapper.billScope"/>)
order by create_time desc, task_id desc
</select>
<!-- 定时调度器按创建时间顺序取待处理任务。 -->
<select id="selectWaiting" resultMap="ArBillGenerateTaskResult">
<include refid="columns"/>
@@ -26,7 +26,7 @@
<result property="createTime" column="create_time"/>
</resultMap>
<select id="selectList" parameterType="ArBillLog" resultMap="ArBillLogResult">
<select id="selectList" resultMap="ArBillLogResult">
select l.log_id, l.ar_bill_id, l.object_type, l.object_id, l.operation_type, l.operation_desc,
case l.object_type
when 'BILL' then b.bill_no
@@ -43,14 +43,15 @@
left join ar_balance_writeoff bw on bw.writeoff_id = case when l.object_type = 'BALANCE_WRITEOFF' then
cast(l.object_id as unsigned) end
<where>
<if test="arBillId != null">and l.ar_bill_id = #{arBillId}</if>
<if test="objectType != null and objectType != ''">and l.object_type = #{objectType}</if>
<if test="objectId != null and objectId != ''">and l.object_id = #{objectId}</if>
<if test="operationType != null and operationType != ''">and l.operation_type = #{operationType}</if>
<if test="operationSource != null and operationSource != ''">and l.operation_source = #{operationSource}
<if test="query.arBillId != null">and l.ar_bill_id = #{query.arBillId}</if>
<if test="query.objectType != null and query.objectType != ''">and l.object_type = #{query.objectType}</if>
<if test="query.objectId != null and query.objectId != ''">and l.object_id = #{query.objectId}</if>
<if test="query.operationType != null and query.operationType != ''">and l.operation_type = #{query.operationType}</if>
<if test="query.operationSource != null and query.operationSource != ''">and l.operation_source = #{query.operationSource}
</if>
<if test="requestId != null and requestId != ''">and l.request_id = #{requestId}</if>
<if test="result != null and result != ''">and l.result = #{result}</if>
<if test="query.requestId != null and query.requestId != ''">and l.request_id = #{query.requestId}</if>
<if test="query.result != null and query.result != ''">and l.result = #{query.result}</if>
<include refid="com.bms.ar.mapper.ArBillScopeMapper.billScope"/>
</where>
order by l.create_time desc, l.log_id desc
</select>
@@ -76,34 +76,35 @@
<sql id="arBillListFilter">
<where>
and (generation_status is null or generation_status = 'READY')
<if test="billNo != null and billNo != ''">and bill_no like concat('%', #{billNo}, '%')</if>
<if test="billName != null and billName != ''">and bill_name like concat('%', #{billName}, '%')</if>
<if test="customerCode != null and customerCode != ''">and customer_code like concat('%', #{customerCode},
<if test="query.billNo != null and query.billNo != ''">and bill_no like concat('%', #{query.billNo}, '%')</if>
<if test="query.billName != null and query.billName != ''">and bill_name like concat('%', #{query.billName}, '%')</if>
<if test="query.customerCode != null and query.customerCode != ''">and customer_code like concat('%', #{query.customerCode},
'%')
</if>
<if test="customerName != null and customerName != ''">and customer_name like concat('%', #{customerName},
<if test="query.customerName != null and query.customerName != ''">and customer_name like concat('%', #{query.customerName},
'%')
</if>
<if test="customerId != null">and customer_id = #{customerId}</if>
<if test="status != null and status != ''">and status = #{status}</if>
<if test="currency != null and currency != ''">and currency = #{currency}</if>
<if test="billDateStart != null">and bill_date &gt;= #{billDateStart}</if>
<if test="billDateEnd != null">and bill_date &lt;= #{billDateEnd}</if>
<if test="billPeriodEnd != null">and bill_period_end = #{billPeriodEnd}</if>
<if test="query.customerId != null">and customer_id = #{query.customerId}</if>
<if test="query.status != null and query.status != ''">and status = #{query.status}</if>
<if test="query.currency != null and query.currency != ''">and currency = #{query.currency}</if>
<if test="query.billDateStart != null">and bill_date &gt;= #{query.billDateStart}</if>
<if test="query.billDateEnd != null">and bill_date &lt;= #{query.billDateEnd}</if>
<if test="query.billPeriodEnd != null">and bill_period_end = #{query.billPeriodEnd}</if>
<include refid="com.bms.ar.mapper.ArBillScopeMapper.billScope"/>
</where>
</sql>
<select id="selectArBillList" parameterType="com.bms.ar.domain.vo.ArBillQuery" resultMap="ArBillResult">
<include refid="selectArBillColumns"/>
<select id="selectArBillList" resultMap="ArBillResult">
select b.* from ar_bill b
<include refid="arBillListFilter"/>
order by create_time desc, ar_bill_id desc
</select>
<select id="selectArBillSummary" parameterType="com.bms.ar.domain.vo.ArBillQuery" resultMap="ArBillSummaryResult">
<select id="selectArBillSummary" resultMap="ArBillSummaryResult">
select coalesce(sum(total_amount), 0) as total_amount,
coalesce(sum(written_off_amount), 0) as written_off_amount,
coalesce(sum(unwritten_amount), 0) as unwritten_amount
from ar_bill
from ar_bill b
<include refid="arBillListFilter"/>
</select>
@@ -112,6 +113,11 @@
where ar_bill_id = #{arBillId}
</select>
<select id="selectArBillByIdScoped" resultMap="ArBillResult">
select b.* from ar_bill b where b.ar_bill_id = #{arBillId}
<include refid="com.bms.ar.mapper.ArBillScopeMapper.billScope"/>
</select>
<select id="selectArBillByBillNo" parameterType="string" resultMap="ArBillResult">
<include refid="selectArBillColumns"/>
where bill_no = #{billNo}
@@ -144,11 +150,12 @@
</select>
<select id="selectUnsettledByCustomer" resultMap="ArBillResult">
<include refid="selectArBillColumns"/>
select b.* from ar_bill b
where customer_id = #{customerId}
and status in ('CONFIRMED', 'PARTIAL_WRITTEN_OFF')
and (generation_status is null or generation_status = 'READY')
and unwritten_amount &gt; 0
<include refid="com.bms.ar.mapper.ArBillScopeMapper.billScope"/>
order by bill_date asc, ar_bill_id asc
</select>
@@ -0,0 +1,63 @@
<?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.ArBillScopeMapper">
<resultMap id="CustomerOption" type="com.bms.customer.customerinfo.domain.BmsCustomerOption">
<id property="customerId" column="customer_id"/>
<result property="customerCode" column="customer_code"/>
<result property="customerName" column="customer_name"/>
</resultMap>
<select id="countCustomerSourceBills" resultType="int">
SELECT COUNT(*) FROM prc_order_bill WHERE customer_id = #{customerId}
AND bill_id IN
<foreach collection="sourceIds" item="sourceId" open="(" separator="," close=")">#{sourceId}</foreach>
</select>
<!-- c 固定为客户表别名;无部门层级扩展,不按角色管理 data_scope 过滤。 -->
<sql id="customerScope">
<choose>
<when test="scope != null and scope.all"/>
<when test="scope != null and (scope.self or scope.department)">
AND c.del_flag = '0'
AND EXISTS (
SELECT 1 FROM sys_user su
WHERE CAST(su.user_id AS CHAR) = c.sales_user_id AND su.del_flag = '0'
AND (1 = 0
<if test="scope.self">OR su.user_id = #{scope.userId}</if>
<if test="scope.department">OR su.dept_id = #{scope.deptId}</if>
)
)
</when>
<otherwise>AND 1 = 0</otherwise>
</choose>
</sql>
<!-- b 固定为账单表别名;ALL 无需关联客户,保留归属异常的历史账单。 -->
<sql id="billScope">
<choose>
<when test="scope != null and scope.all"/>
<otherwise>
AND EXISTS (SELECT 1 FROM ctr_customer c WHERE c.customer_id = b.customer_id
<include refid="com.bms.ar.mapper.ArBillScopeMapper.customerScope"/>
)
</otherwise>
</choose>
</sql>
<select id="countAccessibleBill" resultType="int">
SELECT COUNT(*) FROM ar_bill b WHERE b.ar_bill_id = #{arBillId}
<include refid="billScope"/>
</select>
<select id="selectAccessibleCustomer" resultMap="CustomerOption">
SELECT c.customer_id, c.customer_code, c.customer_name FROM ctr_customer c
WHERE c.customer_id = #{customerId} AND c.del_flag = '0'
<include refid="customerScope"/>
</select>
<select id="selectCustomerOptions" resultMap="CustomerOption">
SELECT c.customer_id, c.customer_code, c.customer_name FROM ctr_customer c WHERE c.del_flag = '0'
<include refid="customerScope"/>
<if test="keywords != null and !keywords.isEmpty()">
AND (<foreach collection="keywords" item="keyword" separator=" OR ">
(c.customer_name LIKE CONCAT('%', #{keyword}, '%') OR c.customer_code LIKE CONCAT('%', #{keyword}, '%')
OR c.customer_code_dw LIKE CONCAT('%', #{keyword}, '%'))
</foreach>)
</if>
ORDER BY c.customer_id DESC
</select>
</mapper>