71 lines
3.6 KiB
XML
71 lines
3.6 KiB
XML
<?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.receivable.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 EXISTS (
|
|
SELECT 1 FROM sys_dept dept
|
|
WHERE dept.dept_id = su.dept_id
|
|
AND (dept.dept_id = #{scope.deptId}
|
|
OR find_in_set(#{scope.deptId}, dept.ancestors))
|
|
)
|
|
</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.receivable.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>
|