|
|
@@ -935,24 +935,24 @@
|
|
|
sys_dept sd on sd.id = suji.dept_id and sd.is_delete = 0
|
|
|
left join
|
|
|
ptl_agreement pa on pa.id = io.agreement_id and pa.is_delete = 0
|
|
|
- left join
|
|
|
- (
|
|
|
- SELECT *
|
|
|
- FROM (
|
|
|
- SELECT t.*,
|
|
|
- ROW_NUMBER() OVER(PARTITION BY t.order_no ORDER BY t.create_time DESC) AS rn
|
|
|
- FROM ins_order_adjust t where t.is_delete = 0
|
|
|
- ) x WHERE x.rn = 1
|
|
|
- ) ioa ON io.id = ioa.order_no
|
|
|
- left join
|
|
|
- (
|
|
|
- SELECT *
|
|
|
- FROM (
|
|
|
- SELECT t.*,
|
|
|
- ROW_NUMBER() OVER(PARTITION BY t.order_no ORDER BY t.create_time DESC) AS rn
|
|
|
- FROM ins_order_adjust t where t.status = 2 and t.is_delete = 0
|
|
|
- ) x WHERE x.rn = 1
|
|
|
- ) ioa1 ON io.id = ioa1.order_no
|
|
|
+ <!-- 优化1: 替代原 ROW_NUMBER() 获取最新一条 adjust 记录(避免每次查询对 ins_order_adjust 全表窗口扫描) -->
|
|
|
+ LEFT JOIN ins_order_adjust ioa
|
|
|
+ ON ioa.id = (
|
|
|
+ SELECT t.id
|
|
|
+ FROM ins_order_adjust t
|
|
|
+ WHERE t.order_no = io.id AND t.is_delete = 0
|
|
|
+ ORDER BY t.create_time DESC, t.id DESC
|
|
|
+ LIMIT 1
|
|
|
+ )
|
|
|
+ <!-- 优化2: 替代原 ROW_NUMBER() 获取 status=2 的最新一条 adjust 记录 -->
|
|
|
+ LEFT JOIN ins_order_adjust ioa1
|
|
|
+ ON ioa1.id = (
|
|
|
+ SELECT t.id
|
|
|
+ FROM ins_order_adjust t
|
|
|
+ WHERE t.order_no = io.id AND t.status = 2 AND t.is_delete = 0
|
|
|
+ ORDER BY t.create_time DESC, t.id DESC
|
|
|
+ LIMIT 1
|
|
|
+ )
|
|
|
<where>
|
|
|
and io.is_delete = 0 and io.parent_id != '0' and sujis.type_attr NOT IN (1,2,3,4)
|
|
|
<if test="insOrdersParam.jzgInfoId != null and insOrdersParam.jzgInfoId != ''">
|
|
|
@@ -1075,6 +1075,336 @@
|
|
|
order by io.create_time desc
|
|
|
</select>
|
|
|
|
|
|
+ <!-- ====================================================================================================
|
|
|
+ 手动分页性能优化(queryOrderListPage / countOrderListPage,非 APP 使用):
|
|
|
+ 原 queryOrderList 走 MP 自动分页时,count 和数据查询都要把 ~13 张展示表 JOIN + 批改子查询在整个
|
|
|
+ ins_orders 集合上执行一遍(10万~100万行、无筛选翻页时尤其明显)。这里改为两阶段延迟关联:
|
|
|
+ 1) 内层/统计:只扫主表 ins_orders(过滤条件全部改写为不依赖展示表别名的 EXISTS/IN 半连接,
|
|
|
+ 成员链路 su-suji-sujis-sd 收敛为一个 IN 子查询),先按 create_time 索引拿到本页 id;
|
|
|
+ 2) 外层:仅对本页 <=size 行联展示表补全展示字段,并在外层重复应用过滤条件保持与旧 SQL 相同的行语义。
|
|
|
+ 语义说明:展示表若存在一单多行(异常数据)时新旧结果的分页边界可能略有差异,正常 1:1 数据完全一致。
|
|
|
+ ==================================================================================================== -->
|
|
|
+
|
|
|
+ <!-- 成员链路半连接:等价于原 LEFT JOIN sys_user/sys_user_jzg_info/sys_user_jzg_info_salesman/sys_dept
|
|
|
+ 且 sujis.type_attr NOT IN (1,2,3,4) 的行保留语义(业务员姓名/类型、部门筛选也并入同一链路) -->
|
|
|
+ <sql id="orderMemberChainCond">
|
|
|
+ io.real_quote_user_id in (
|
|
|
+ select su.mobile
|
|
|
+ from sys_user su
|
|
|
+ inner join sys_user_jzg_info suji on suji.user_id = su.id and suji.system_code = #{insOrdersParam.systemCode}
|
|
|
+ and suji.is_delete = 0
|
|
|
+ inner join sys_user_jzg_info_salesman sujis on sujis.sys_user_jzg_info_id = suji.id and sujis.is_delete = 0
|
|
|
+ left join sys_dept sd on sd.id = suji.dept_id and sd.is_delete = 0
|
|
|
+ where su.is_delete = 0
|
|
|
+ and sujis.type_attr NOT IN (1,2,3,4)
|
|
|
+ <if test="insOrdersParam.salesmanInfo != null and insOrdersParam.salesmanInfo != ''">
|
|
|
+ and su.username = #{insOrdersParam.salesmanInfo}
|
|
|
+ </if>
|
|
|
+ <if test="insOrdersParam.salesmanType != null and insOrdersParam.salesmanType != ''">
|
|
|
+ and sujis.type_attr = #{insOrdersParam.salesmanType}
|
|
|
+ </if>
|
|
|
+ <if test="insOrdersParam.deptId != null and insOrdersParam.deptId != ''">
|
|
|
+ and sd.id = #{insOrdersParam.deptId}
|
|
|
+ </if>
|
|
|
+ <if test="insOrdersParam.deptName != null and insOrdersParam.deptName != ''">
|
|
|
+ and sd.name = #{insOrdersParam.deptName}
|
|
|
+ </if>
|
|
|
+ )
|
|
|
+ </sql>
|
|
|
+
|
|
|
+ <!-- 通用过滤条件(半连接/标量子查询形式,只依赖主表 io,不依赖任何展示表别名;
|
|
|
+ 展示表过滤语义与原 LEFT JOIN + WHERE 相同,批改类过滤保持“取最新一条 adjust”口径) -->
|
|
|
+ <sql id="orderDetailFilterCond">
|
|
|
+ <if test="insOrdersParam.licenseNo != null and insOrdersParam.licenseNo != ''">
|
|
|
+ AND io.id IN (SELECT order_no FROM ins_orders_car_info WHERE license_no = #{insOrdersParam.licenseNo} AND
|
|
|
+ is_delete = 0)
|
|
|
+ </if>
|
|
|
+ <if test="insOrdersParam.orderStatus!= null and insOrdersParam.orderStatus!= ''">
|
|
|
+ AND io.order_status = #{insOrdersParam.orderStatus}
|
|
|
+ </if>
|
|
|
+ <if test="insOrdersParam.adjustStatus!= null and insOrdersParam.adjustStatus!= ''">
|
|
|
+ AND #{insOrdersParam.adjustStatus} = (SELECT t.status FROM ins_order_adjust t WHERE t.order_no = io.id AND
|
|
|
+ t.is_delete = 0 ORDER BY t.create_time DESC, t.id DESC LIMIT 1)
|
|
|
+ </if>
|
|
|
+ <if test="insOrdersParam.salesman!= null">
|
|
|
+ AND io.real_quote_user_id = #{insOrdersParam.salesman}
|
|
|
+ </if>
|
|
|
+ <if test="insOrdersParam.startDate != null and insOrdersParam.startDate != ''and insOrdersParam.endDate != null and insOrdersParam.endDate != ''">
|
|
|
+ AND io.create_time BETWEEN #{insOrdersParam.startDate} and #{insOrdersParam.endDate}
|
|
|
+ </if>
|
|
|
+ <if test="insOrdersParam.companyName != null and insOrdersParam.companyName != ''">
|
|
|
+ AND io.company_name = #{insOrdersParam.companyName}
|
|
|
+ </if>
|
|
|
+ <if test="insOrdersParam.companyId != null and insOrdersParam.companyId != ''">
|
|
|
+ AND io.company_id = #{insOrdersParam.companyId}
|
|
|
+ </if>
|
|
|
+ <if test="insOrdersParam.productCode != null and insOrdersParam.productCode != ''">
|
|
|
+ AND io.product_id = #{insOrdersParam.productCode}
|
|
|
+ </if>
|
|
|
+ <if test="insOrdersParam.productName != null and insOrdersParam.productName != ''">
|
|
|
+ AND io.product_name = #{insOrdersParam.productName}
|
|
|
+ </if>
|
|
|
+ <if test="insOrdersParam.vinNo != null and insOrdersParam.vinNo != ''">
|
|
|
+ AND io.id IN (SELECT order_no FROM ins_orders_car_info WHERE vin_no = #{insOrdersParam.vinNo} AND is_delete
|
|
|
+ = 0)
|
|
|
+ </if>
|
|
|
+ <if test="insOrdersParam.ownerName != null and insOrdersParam.ownerName != ''">
|
|
|
+ AND io.id IN (SELECT order_no FROM ins_orders_car_user_info WHERE policy_person_type = 1 AND name =
|
|
|
+ #{insOrdersParam.ownerName} AND is_delete = 0)
|
|
|
+ </if>
|
|
|
+ <if test="insOrdersParam.ownerMobile != null and insOrdersParam.ownerMobile != ''">
|
|
|
+ AND io.id IN (SELECT order_no FROM ins_orders_car_user_info WHERE policy_person_type = 1 AND mobile =
|
|
|
+ #{insOrdersParam.ownerMobile} AND is_delete = 0)
|
|
|
+ </if>
|
|
|
+ <if test="insOrdersParam.policyName != null and insOrdersParam.policyName != ''">
|
|
|
+ AND io.id IN (SELECT order_no FROM ins_orders_car_user_info WHERE policy_person_type = 2 AND name =
|
|
|
+ #{insOrdersParam.policyName} AND is_delete = 0)
|
|
|
+ </if>
|
|
|
+ <if test="insOrdersParam.policyMobile != null and insOrdersParam.policyMobile != ''">
|
|
|
+ AND io.id IN (SELECT order_no FROM ins_orders_car_user_info WHERE policy_person_type = 2 AND mobile =
|
|
|
+ #{insOrdersParam.policyMobile} AND is_delete = 0)
|
|
|
+ </if>
|
|
|
+ <if test="insOrdersParam.insurName != null and insOrdersParam.insurName != ''">
|
|
|
+ AND io.id IN (SELECT order_no FROM ins_orders_car_user_info WHERE policy_person_type = 3 AND name =
|
|
|
+ #{insOrdersParam.insurName} AND is_delete = 0)
|
|
|
+ </if>
|
|
|
+ <if test="insOrdersParam.insurMobile != null and insOrdersParam.insurMobile != ''">
|
|
|
+ AND io.id IN (SELECT order_no FROM ins_orders_car_user_info WHERE policy_person_type = 3 AND mobile =
|
|
|
+ #{insOrdersParam.insurMobile} AND is_delete = 0)
|
|
|
+ </if>
|
|
|
+ <if test="insOrdersParam.ciStartDate != null">
|
|
|
+ AND io.id IN (SELECT order_no FROM ins_orders_risk WHERE risk_code = '0507' AND start_date =
|
|
|
+ #{insOrdersParam.ciStartDate} AND is_delete = 0)
|
|
|
+ </if>
|
|
|
+ <if test="insOrdersParam.biStartDate != null">
|
|
|
+ AND io.id IN (SELECT order_no FROM ins_orders_risk WHERE risk_code = '0510' AND start_date =
|
|
|
+ #{insOrdersParam.biStartDate} AND is_delete = 0)
|
|
|
+ </if>
|
|
|
+ <if test="insOrdersParam.sumPremium != null">
|
|
|
+ AND io.id IN (SELECT order_no FROM ins_orders_costs WHERE sum_premium = #{insOrdersParam.sumPremium} AND
|
|
|
+ is_delete = 0)
|
|
|
+ </if>
|
|
|
+ <if test="insOrdersParam.ciPremium != null">
|
|
|
+ AND io.id IN (SELECT order_no FROM ins_orders_costs WHERE jq_premium = #{insOrdersParam.ciPremium} AND
|
|
|
+ is_delete = 0)
|
|
|
+ </if>
|
|
|
+ <if test="insOrdersParam.biPremium != null">
|
|
|
+ AND io.id IN (SELECT order_no FROM ins_orders_costs WHERE sy_premium = #{insOrdersParam.biPremium} AND
|
|
|
+ is_delete = 0)
|
|
|
+ </if>
|
|
|
+ <if test="insOrdersParam.niPremium != null">
|
|
|
+ AND io.id IN (SELECT order_no FROM ins_orders_costs WHERE jy_premium = #{insOrdersParam.niPremium} AND
|
|
|
+ is_delete = 0)
|
|
|
+ </if>
|
|
|
+ <if test="insOrdersParam.vvTax != null">
|
|
|
+ AND io.id IN (SELECT order_no FROM ins_orders_costs WHERE tax_premium = #{insOrdersParam.vvTax} AND
|
|
|
+ is_delete = 0)
|
|
|
+ </if>
|
|
|
+ <if test="insOrdersParam.agreementName != null and insOrdersParam.agreementName != ''">
|
|
|
+ AND io.agreement_id IN (SELECT id FROM ptl_agreement WHERE agreement_name = #{insOrdersParam.agreementName}
|
|
|
+ AND is_delete = 0)
|
|
|
+ </if>
|
|
|
+ <if test="insOrdersParam.paymentLink != null and insOrdersParam.paymentLink != ''">
|
|
|
+ AND io.pay_link = #{insOrdersParam.paymentLink}
|
|
|
+ </if>
|
|
|
+ <if test="insOrdersParam.adjustId != null">
|
|
|
+ AND #{insOrdersParam.adjustId} = (SELECT t.id FROM ins_order_adjust t WHERE t.order_no = io.id AND
|
|
|
+ t.is_delete = 0 ORDER BY t.create_time DESC, t.id DESC LIMIT 1)
|
|
|
+ </if>
|
|
|
+ <if test="insOrdersParam.adjustPremium != null">
|
|
|
+ AND #{insOrdersParam.adjustPremium} = (SELECT t.after_premium FROM ins_order_adjust t WHERE t.order_no =
|
|
|
+ io.id AND t.status = 2 AND t.is_delete = 0 ORDER BY t.create_time DESC, t.id DESC LIMIT 1)
|
|
|
+ </if>
|
|
|
+ <if test="insOrdersParam.startSigningTime != null and insOrdersParam.startSigningTime != ''and insOrdersParam.endSigningTime != null and insOrdersParam.endSigningTime != ''">
|
|
|
+ AND io.signing_time BETWEEN #{insOrdersParam.startSigningTime} and #{insOrdersParam.endSigningTime}
|
|
|
+ </if>
|
|
|
+ <if test="insOrdersParam.startPayTime != null and insOrdersParam.startPayTime != ''and insOrdersParam.endPayTime != null and insOrdersParam.endPayTime != ''">
|
|
|
+ AND io.pay_time BETWEEN #{insOrdersParam.startPayTime} and #{insOrdersParam.endPayTime}
|
|
|
+ </if>
|
|
|
+ </sql>
|
|
|
+
|
|
|
+ <!-- 非 APP 手工分页特有用:订单号 / 父单号(保持原 queryOrderList 过滤口径) -->
|
|
|
+ <sql id="orderNoParentFilterCond">
|
|
|
+ <if test="insOrdersParam.orderNo != null and insOrdersParam.orderNo != ''">
|
|
|
+ AND io.id = #{insOrdersParam.orderNo}
|
|
|
+ </if>
|
|
|
+ <if test="insOrdersParam.parentId != null and insOrdersParam.parentId != ''">
|
|
|
+ AND io.parent_id = #{insOrdersParam.parentId}
|
|
|
+ </if>
|
|
|
+ <if test="insOrdersParam.parentIds != null and insOrdersParam.parentIds.size() > 0">
|
|
|
+ AND io.parent_id IN
|
|
|
+ <foreach collection="insOrdersParam.parentIds" item="pid" open="(" separator="," close=")">
|
|
|
+ #{pid}
|
|
|
+ </foreach>
|
|
|
+ </if>
|
|
|
+ </sql>
|
|
|
+
|
|
|
+ <!-- 手动分页版(非 APP):两阶段延迟关联取当前页数据(先主表取 id,再联展示表) -->
|
|
|
+ <select id="queryOrderListPage" resultType="com.jzg.commons.entity.orders.vo.OrderListVo">
|
|
|
+ WITH RECURSIVE leader_tree AS (
|
|
|
+ SELECT ss.id, su.mobile, 1 AS depth
|
|
|
+ FROM sys_user_jzg_info ss
|
|
|
+ LEFT JOIN sys_user su ON su.id = ss.user_id AND su.is_delete = 0
|
|
|
+ WHERE ss.id = #{insOrdersParam.jzgInfoId}
|
|
|
+ AND ss.is_delete = 0
|
|
|
+ UNION ALL
|
|
|
+ SELECT t.id, su.mobile, lt.depth + 1
|
|
|
+ FROM sys_user_jzg_info t
|
|
|
+ INNER JOIN leader_tree lt ON t.leader_id = lt.id
|
|
|
+ LEFT JOIN sys_user su ON su.id = t.user_id AND su.is_delete = 0
|
|
|
+ WHERE t.is_delete = 0
|
|
|
+ AND lt.depth <![CDATA[ < ]]> 10
|
|
|
+ )
|
|
|
+ SELECT
|
|
|
+ io.id as order_no,
|
|
|
+ io.quote_no as no,
|
|
|
+ io.company_id,
|
|
|
+ io.company_name,
|
|
|
+ io.product_id as productCode,
|
|
|
+ io.product_name as productName,
|
|
|
+ io.order_status,
|
|
|
+ io.create_time,
|
|
|
+ io.create_by,
|
|
|
+ io.error_message,
|
|
|
+ io.parent_id,
|
|
|
+ ioci.license_no,
|
|
|
+ ioci.vin_no,
|
|
|
+ owner_u.name as owner_name,
|
|
|
+ owner_u.mobile as owner_mobile,
|
|
|
+ policy_u.name as policy_name,
|
|
|
+ policy_u.mobile as policy_mobile,
|
|
|
+ insur_u.name as insur_name,
|
|
|
+ insur_u.mobile as insur_mobile,
|
|
|
+ iorci.start_date as ci_start_date,
|
|
|
+ iorbi.start_date as bi_start_date,
|
|
|
+ iorco.sum_premium as sumPremium,
|
|
|
+ iorco.jq_premium as ciPremium,
|
|
|
+ iorco.sy_premium as biPremium,
|
|
|
+ iorco.jy_premium as niPremium,
|
|
|
+ iorco.tax_premium as vvTax,
|
|
|
+ su.username as recorder,
|
|
|
+ suji.name as salesmanInfo,
|
|
|
+ suji.id as jzgInfoId,
|
|
|
+ sujis.type_attr as salesmanType,
|
|
|
+ pa.agreement_name as agreementName,
|
|
|
+ sd.name as deptName,
|
|
|
+ io.pay_link as paymentLink,
|
|
|
+ ioa.status as adjustStatus,
|
|
|
+ ioa.id as adjustId,
|
|
|
+ ioa1.after_premium as adjustPremium
|
|
|
+ FROM
|
|
|
+ ins_orders io
|
|
|
+ INNER JOIN (
|
|
|
+ SELECT io.id AS order_id
|
|
|
+ FROM ins_orders io
|
|
|
+ <where>
|
|
|
+ io.is_delete = 0
|
|
|
+ AND io.parent_id != '0'
|
|
|
+ AND
|
|
|
+ <include refid="orderMemberChainCond"/>
|
|
|
+ <if test="insOrdersParam.jzgInfoId != null and insOrdersParam.jzgInfoId != ''">
|
|
|
+ and io.real_quote_user_id in (
|
|
|
+ select lt.mobile from leader_tree lt where lt.mobile is not null
|
|
|
+ )
|
|
|
+ </if>
|
|
|
+ <include refid="orderNoParentFilterCond"/>
|
|
|
+ <include refid="orderDetailFilterCond"/>
|
|
|
+ </where>
|
|
|
+ ORDER BY io.create_time DESC, io.id DESC
|
|
|
+ LIMIT #{offset}, #{size}
|
|
|
+ ) page ON page.order_id = io.id
|
|
|
+ LEFT JOIN ins_orders_car_info ioci ON ioci.order_no = io.id and ioci.is_delete = 0
|
|
|
+ LEFT JOIN
|
|
|
+ ins_orders_car_user_info owner_u on owner_u.order_no = io.id and owner_u.policy_person_type = 1 and
|
|
|
+ owner_u.is_delete = 0
|
|
|
+ left JOIN
|
|
|
+ ins_orders_car_user_info policy_u on policy_u.order_no = io.id and policy_u.policy_person_type = 2 and
|
|
|
+ policy_u.is_delete = 0
|
|
|
+ left JOIN
|
|
|
+ ins_orders_car_user_info insur_u on insur_u.order_no = io.id and insur_u.policy_person_type = 3 and
|
|
|
+ insur_u.is_delete = 0
|
|
|
+ left join
|
|
|
+ ins_orders_risk iorci on iorci.order_no = io.id and iorci.risk_code = '0507' and iorci.is_delete = 0
|
|
|
+ left join
|
|
|
+ ins_orders_risk iorbi on iorbi.order_no = io.id and iorbi.risk_code = '0510' and iorbi.is_delete = 0
|
|
|
+ LEFT JOIN
|
|
|
+ ins_orders_costs iorco on iorco.order_no = io.id and iorco.is_delete = 0
|
|
|
+ left join
|
|
|
+ sys_user su on su.mobile = io.real_quote_user_id and su.is_delete = 0
|
|
|
+ left join
|
|
|
+ sys_user_jzg_info suji on suji.user_id = su.id and suji.system_code = #{insOrdersParam.systemCode} and
|
|
|
+ suji.is_delete = 0
|
|
|
+ left join
|
|
|
+ sys_user_jzg_info_salesman sujis ON suji.id = sujis.sys_user_jzg_info_id AND sujis.is_delete = 0
|
|
|
+ left join
|
|
|
+ sys_dept sd on sd.id = suji.dept_id and sd.is_delete = 0
|
|
|
+ left join
|
|
|
+ ptl_agreement pa on pa.id = io.agreement_id and pa.is_delete = 0
|
|
|
+ LEFT JOIN ins_order_adjust ioa
|
|
|
+ ON ioa.id = (
|
|
|
+ SELECT t.id
|
|
|
+ FROM ins_order_adjust t
|
|
|
+ WHERE t.order_no = io.id AND t.is_delete = 0
|
|
|
+ ORDER BY t.create_time DESC, t.id DESC
|
|
|
+ LIMIT 1
|
|
|
+ )
|
|
|
+ LEFT JOIN ins_order_adjust ioa1
|
|
|
+ ON ioa1.id = (
|
|
|
+ SELECT t.id
|
|
|
+ FROM ins_order_adjust t
|
|
|
+ WHERE t.order_no = io.id AND t.status = 2 AND t.is_delete = 0
|
|
|
+ ORDER BY t.create_time DESC, t.id DESC
|
|
|
+ LIMIT 1
|
|
|
+ )
|
|
|
+ <where>
|
|
|
+ io.is_delete = 0
|
|
|
+ AND io.parent_id != '0'
|
|
|
+ AND
|
|
|
+ <include refid="orderMemberChainCond"/>
|
|
|
+ <if test="insOrdersParam.jzgInfoId != null and insOrdersParam.jzgInfoId != ''">
|
|
|
+ and io.real_quote_user_id in (
|
|
|
+ select lt.mobile from leader_tree lt where lt.mobile is not null
|
|
|
+ )
|
|
|
+ </if>
|
|
|
+ <include refid="orderNoParentFilterCond"/>
|
|
|
+ <include refid="orderDetailFilterCond"/>
|
|
|
+ </where>
|
|
|
+ ORDER BY io.create_time DESC, io.id DESC
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <!-- 手动分页版(非 APP):轻量统计总条数(只扫主表,不联展示表、无批改窗口) -->
|
|
|
+ <select id="countOrderListPage" resultType="long">
|
|
|
+ WITH RECURSIVE leader_tree AS (
|
|
|
+ SELECT ss.id, su.mobile, 1 AS depth
|
|
|
+ FROM sys_user_jzg_info ss
|
|
|
+ LEFT JOIN sys_user su ON su.id = ss.user_id AND su.is_delete = 0
|
|
|
+ WHERE ss.id = #{insOrdersParam.jzgInfoId}
|
|
|
+ AND ss.is_delete = 0
|
|
|
+ UNION ALL
|
|
|
+ SELECT t.id, su.mobile, lt.depth + 1
|
|
|
+ FROM sys_user_jzg_info t
|
|
|
+ INNER JOIN leader_tree lt ON t.leader_id = lt.id
|
|
|
+ LEFT JOIN sys_user su ON su.id = t.user_id AND su.is_delete = 0
|
|
|
+ WHERE t.is_delete = 0
|
|
|
+ AND lt.depth <![CDATA[ < ]]> 10
|
|
|
+ )
|
|
|
+ SELECT COUNT(*)
|
|
|
+ FROM ins_orders io
|
|
|
+ <where>
|
|
|
+ io.is_delete = 0
|
|
|
+ AND io.parent_id != '0'
|
|
|
+ AND
|
|
|
+ <include refid="orderMemberChainCond"/>
|
|
|
+ <if test="insOrdersParam.jzgInfoId != null and insOrdersParam.jzgInfoId != ''">
|
|
|
+ and io.real_quote_user_id in (
|
|
|
+ select lt.mobile from leader_tree lt where lt.mobile is not null
|
|
|
+ )
|
|
|
+ </if>
|
|
|
+ <include refid="orderNoParentFilterCond"/>
|
|
|
+ <include refid="orderDetailFilterCond"/>
|
|
|
+ </where>
|
|
|
+ </select>
|
|
|
+
|
|
|
<select id="queryOrderListAll" resultType="com.jzg.commons.entity.orders.vo.OrderListVo">
|
|
|
SELECT
|
|
|
io.id as order_no,
|
|
|
@@ -1419,51 +1749,9 @@
|
|
|
io.create_time
|
|
|
FROM
|
|
|
ins_orders io
|
|
|
- LEFT JOIN ins_orders_car_info ioci ON ioci.order_no = io.id and ioci.is_delete = 0
|
|
|
- LEFT JOIN
|
|
|
- ins_orders_car_user_info owner_u on owner_u.order_no = io.id and owner_u.policy_person_type = 1 and
|
|
|
- owner_u.is_delete = 0
|
|
|
- left JOIN
|
|
|
- ins_orders_car_user_info policy_u on policy_u.order_no = io.id and policy_u.policy_person_type = 2 and
|
|
|
- policy_u.is_delete = 0
|
|
|
- left JOIN
|
|
|
- ins_orders_car_user_info insur_u on insur_u.order_no = io.id and insur_u.policy_person_type = 3 and
|
|
|
- insur_u.is_delete = 0
|
|
|
- left join
|
|
|
- ins_orders_risk iorci on iorci.order_no = io.id and iorci.risk_code = '0507' and iorci.is_delete = 0
|
|
|
- left join
|
|
|
- ins_orders_risk iorbi on iorbi.order_no = io.id and iorbi.risk_code = '0510' and iorbi.is_delete = 0
|
|
|
- LEFT JOIN
|
|
|
- ins_orders_costs iorco on iorco.order_no = io.id and iorco.is_delete = 0
|
|
|
- left join
|
|
|
- sys_user su on su.mobile = io.real_quote_user_id and su.is_delete = 0
|
|
|
- left join
|
|
|
- sys_user_jzg_info suji on suji.user_id = su.id and suji.system_code = #{insOrdersParam.systemCode} and
|
|
|
- suji.is_delete = 0
|
|
|
- left join
|
|
|
- sys_user_jzg_info_salesman sujis ON suji.id = sujis.sys_user_jzg_info_id AND sujis.is_delete = 0
|
|
|
- left join
|
|
|
- sys_dept sd on sd.id = suji.dept_id and sd.is_delete = 0
|
|
|
- left join
|
|
|
- ptl_agreement pa on pa.id = io.agreement_id and pa.is_delete = 0
|
|
|
- left join
|
|
|
- (
|
|
|
- SELECT *
|
|
|
- FROM (
|
|
|
- SELECT t.*,
|
|
|
- ROW_NUMBER() OVER(PARTITION BY t.order_no ORDER BY t.create_time DESC) AS rn
|
|
|
- FROM ins_order_adjust t where t.is_delete = 0
|
|
|
- ) x WHERE x.rn = 1
|
|
|
- ) ioa ON io.id = ioa.order_no
|
|
|
- left join
|
|
|
- (
|
|
|
- SELECT *
|
|
|
- FROM (
|
|
|
- SELECT t.*,
|
|
|
- ROW_NUMBER() OVER(PARTITION BY t.order_no ORDER BY t.create_time DESC) AS rn
|
|
|
- FROM ins_order_adjust t where t.status = 2 and t.is_delete = 0
|
|
|
- ) x WHERE x.rn = 1
|
|
|
- ) ioa1 ON io.id = ioa1.order_no
|
|
|
+ <!-- 性能优化:dedup 内层不再联任何展示表(此前 ~13 张 LEFT JOIN + 批改相关子查询在全量集合上执行后才排序 LIMIT),
|
|
|
+ 过滤条件改写为只依赖主表 io 的半连接/标量子查询(见 orderDetailFilterCond),
|
|
|
+ 使“无筛选翻页”场景退化为 ins_orders 单表 create_time 索引有序扫描 -->
|
|
|
<where>
|
|
|
and io.is_delete = 0
|
|
|
<choose>
|
|
|
@@ -1474,7 +1762,8 @@
|
|
|
and io.parent_id != '0'
|
|
|
</otherwise>
|
|
|
</choose>
|
|
|
- and sujis.type_attr NOT IN (1,2,3,4)
|
|
|
+ AND
|
|
|
+ <include refid="orderMemberChainCond"/>
|
|
|
<if test="insOrdersParam.jzgInfoId != null and insOrdersParam.jzgInfoId != ''">
|
|
|
and io.real_quote_user_id in (select bbb.mobile from sys_user bbb where bbb.id in ( select ss.user_id
|
|
|
from sys_user_jzg_info ss where 1 =1 and (ss.leader_id = #{insOrdersParam.jzgInfoId} or ss.id
|
|
|
@@ -1483,105 +1772,7 @@
|
|
|
<if test="insOrdersParam.orderNo != null and insOrdersParam.orderNo != ''">
|
|
|
AND io.id = #{insOrdersParam.orderNo}
|
|
|
</if>
|
|
|
- <if test="insOrdersParam.licenseNo != null and insOrdersParam.licenseNo != ''">
|
|
|
- AND ioci.license_no = #{insOrdersParam.licenseNo}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.orderStatus!= null and insOrdersParam.orderStatus!= ''">
|
|
|
- AND io.order_status = #{insOrdersParam.orderStatus}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.adjustStatus!= null and insOrdersParam.adjustStatus!= ''">
|
|
|
- AND ioa.status = #{insOrdersParam.adjustStatus}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.salesman!= null">
|
|
|
- AND io.real_quote_user_id = #{insOrdersParam.salesman}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.companyId != null and insOrdersParam.companyId != ''">
|
|
|
- AND io.company_id = #{insOrdersParam.companyId}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.startDate != null and insOrdersParam.startDate != ''and insOrdersParam.endDate != null and insOrdersParam.endDate != ''">
|
|
|
- AND io.create_time BETWEEN #{insOrdersParam.startDate} and #{insOrdersParam.endDate}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.companyName != null and insOrdersParam.companyName != ''">
|
|
|
- AND io.company_name = #{insOrdersParam.companyName}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.productCode != null and insOrdersParam.productCode != ''">
|
|
|
- AND io.product_id = #{insOrdersParam.productCode}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.productName != null and insOrdersParam.productName != ''">
|
|
|
- AND io.product_name = #{insOrdersParam.productName}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.vinNo != null and insOrdersParam.vinNo != ''">
|
|
|
- AND ioci.vin_no = #{insOrdersParam.vinNo}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.ownerName != null and insOrdersParam.ownerName != ''">
|
|
|
- AND owner_u.name = #{insOrdersParam.ownerName}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.ownerMobile != null and insOrdersParam.ownerMobile != ''">
|
|
|
- AND owner_u.mobile = #{insOrdersParam.ownerMobile}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.policyName != null and insOrdersParam.policyName != ''">
|
|
|
- AND policy_u.name = #{insOrdersParam.policyName}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.policyMobile != null and insOrdersParam.policyMobile != ''">
|
|
|
- AND policy_u.mobile = #{insOrdersParam.policyMobile}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.insurName != null and insOrdersParam.insurName != ''">
|
|
|
- AND insur_u.name = #{insOrdersParam.insurName}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.insurMobile != null and insOrdersParam.insurMobile != ''">
|
|
|
- AND insur_u.mobile = #{insOrdersParam.insurMobile}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.ciStartDate != null">
|
|
|
- AND iorci.start_date = #{insOrdersParam.ciStartDate}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.biStartDate != null">
|
|
|
- AND iorbi.start_date = #{insOrdersParam.biStartDate}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.sumPremium != null">
|
|
|
- AND iorco.sum_premium = #{insOrdersParam.sumPremium}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.ciPremium != null">
|
|
|
- AND iorco.jq_premium = #{insOrdersParam.ciPremium}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.biPremium != null">
|
|
|
- AND iorco.sy_premium = #{insOrdersParam.biPremium}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.niPremium != null">
|
|
|
- AND iorco.jy_premium = #{insOrdersParam.niPremium}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.vvTax != null">
|
|
|
- AND iorco.tax_premium = #{insOrdersParam.vvTax}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.salesmanInfo != null and insOrdersParam.salesmanInfo != ''">
|
|
|
- AND su.username = #{insOrdersParam.salesmanInfo}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.salesmanType != null and insOrdersParam.salesmanType != ''">
|
|
|
- AND sujis.type_attr = #{insOrdersParam.salesmanType}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.agreementName != null and insOrdersParam.agreementName != ''">
|
|
|
- AND pa.agreement_name = #{insOrdersParam.agreementName}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.deptId != null and insOrdersParam.deptId != ''">
|
|
|
- AND sd.id = #{insOrdersParam.deptId}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.deptName != null and insOrdersParam.deptName != ''">
|
|
|
- AND sd.name = #{insOrdersParam.deptName}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.paymentLink != null and insOrdersParam.paymentLink != ''">
|
|
|
- AND io.pay_link = #{insOrdersParam.paymentLink}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.adjustId != null">
|
|
|
- AND ioa.id = #{insOrdersParam.adjustId}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.adjustPremium != null">
|
|
|
- AND ioa1.after_premium = #{insOrdersParam.adjustPremium}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.startSigningTime != null and insOrdersParam.startSigningTime != ''and insOrdersParam.endSigningTime != null and insOrdersParam.endSigningTime != ''">
|
|
|
- AND io.signing_time BETWEEN #{insOrdersParam.startSigningTime} and #{insOrdersParam.endSigningTime}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.startPayTime != null and insOrdersParam.startPayTime != ''and insOrdersParam.endPayTime != null and insOrdersParam.endPayTime != ''">
|
|
|
- AND io.pay_time BETWEEN #{insOrdersParam.startPayTime} and #{insOrdersParam.endPayTime}
|
|
|
- </if>
|
|
|
+ <include refid="orderDetailFilterCond"/>
|
|
|
</where>
|
|
|
) dedup
|
|
|
ORDER BY dedup.create_time DESC
|
|
|
@@ -1617,77 +1808,40 @@
|
|
|
sys_dept sd on sd.id = suji.dept_id and sd.is_delete = 0
|
|
|
left join
|
|
|
ptl_agreement pa on pa.id = io.agreement_id and pa.is_delete = 0
|
|
|
- left join
|
|
|
- (
|
|
|
- SELECT *
|
|
|
- FROM (
|
|
|
- SELECT t.*,
|
|
|
- ROW_NUMBER() OVER(PARTITION BY t.order_no ORDER BY t.create_time DESC) AS rn
|
|
|
- FROM ins_order_adjust t where t.is_delete = 0
|
|
|
- ) x WHERE x.rn = 1
|
|
|
- ) ioa ON io.id = ioa.order_no
|
|
|
- left join
|
|
|
- (
|
|
|
- SELECT *
|
|
|
- FROM (
|
|
|
- SELECT t.*,
|
|
|
- ROW_NUMBER() OVER(PARTITION BY t.order_no ORDER BY t.create_time DESC) AS rn
|
|
|
- FROM ins_order_adjust t where t.status = 2 and t.is_delete = 0
|
|
|
- ) x WHERE x.rn = 1
|
|
|
- ) ioa1 ON io.id = ioa1.order_no
|
|
|
+ <!-- 优化1: 替代原 ROW_NUMBER() 获取最新一条 adjust 记录(避免每次查询对 ins_order_adjust 全表窗口扫描) -->
|
|
|
+ LEFT JOIN ins_order_adjust ioa
|
|
|
+ ON ioa.id = (
|
|
|
+ SELECT t.id
|
|
|
+ FROM ins_order_adjust t
|
|
|
+ WHERE t.order_no = io.id AND t.is_delete = 0
|
|
|
+ ORDER BY t.create_time DESC, t.id DESC
|
|
|
+ LIMIT 1
|
|
|
+ )
|
|
|
+ <!-- 优化2: 替代原 ROW_NUMBER() 获取 status=2 的最新一条 adjust 记录 -->
|
|
|
+ LEFT JOIN ins_order_adjust ioa1
|
|
|
+ ON ioa1.id = (
|
|
|
+ SELECT t.id
|
|
|
+ FROM ins_order_adjust t
|
|
|
+ WHERE t.order_no = io.id AND t.status = 2 AND t.is_delete = 0
|
|
|
+ ORDER BY t.create_time DESC, t.id DESC
|
|
|
+ LIMIT 1
|
|
|
+ )
|
|
|
order by io.create_time desc) tt
|
|
|
where tt.rn = 1
|
|
|
</select>
|
|
|
|
|
|
- <!-- 手动分页版:统计按车牌+状态分组去重后的总条数 -->
|
|
|
+ <!-- 手动分页版:统计按车牌+状态分组去重后的总条数(性能优化版)
|
|
|
+ 等价性:原实现 ROW_NUMBER() OVER(PARTITION BY COALESCE(license_no,id),order_status) + rn=1 的计数
|
|
|
+ == 按相同分组键去重后的分组数;展示表(人员/险种/费用/批改等)JOIN 引入的行重复不会改变分组数,
|
|
|
+ 因此这里只保留车牌联表 ioci,其余展示表联接全部去掉,过滤条件收敛为只依赖主表的半连接 -->
|
|
|
<select id="countOrderListDistinct" resultType="java.lang.Long">
|
|
|
SELECT COUNT(*) FROM (
|
|
|
SELECT
|
|
|
- io.id AS order_id,
|
|
|
- ROW_NUMBER() OVER(PARTITION BY COALESCE(ioci.license_no, io.id), io.order_status ORDER BY io.create_time DESC) AS rn
|
|
|
+ COALESCE(ioci.license_no, io.id) AS license_key,
|
|
|
+ io.order_status
|
|
|
FROM
|
|
|
ins_orders io
|
|
|
LEFT JOIN ins_orders_car_info ioci ON ioci.order_no = io.id and ioci.is_delete = 0
|
|
|
- LEFT JOIN
|
|
|
- ins_orders_car_user_info owner_u on owner_u.order_no = io.id and owner_u.policy_person_type = 1 and owner_u.is_delete = 0
|
|
|
- left JOIN
|
|
|
- ins_orders_car_user_info policy_u on policy_u.order_no = io.id and policy_u.policy_person_type = 2 and policy_u.is_delete = 0
|
|
|
- left JOIN
|
|
|
- ins_orders_car_user_info insur_u on insur_u.order_no = io.id and insur_u.policy_person_type = 3 and insur_u.is_delete = 0
|
|
|
- left join
|
|
|
- ins_orders_risk iorci on iorci.order_no = io.id and iorci.risk_code = '0507' and iorci.is_delete = 0
|
|
|
- left join
|
|
|
- ins_orders_risk iorbi on iorbi.order_no = io.id and iorbi.risk_code = '0510' and iorbi.is_delete = 0
|
|
|
- LEFT JOIN
|
|
|
- ins_orders_costs iorco on iorco.order_no = io.id and iorco.is_delete = 0
|
|
|
- left join
|
|
|
- sys_user su on su.mobile = io.real_quote_user_id and su.is_delete = 0
|
|
|
- left join
|
|
|
- sys_user_jzg_info suji on suji.user_id = su.id and suji.system_code = #{insOrdersParam.systemCode} and suji.is_delete = 0
|
|
|
- left join
|
|
|
- sys_user_jzg_info_salesman sujis ON suji.id = sujis.sys_user_jzg_info_id AND sujis.is_delete = 0
|
|
|
- left join
|
|
|
- sys_dept sd on sd.id = suji.dept_id and sd.is_delete = 0
|
|
|
- left join
|
|
|
- ptl_agreement pa on pa.id = io.agreement_id and pa.is_delete = 0
|
|
|
- left join
|
|
|
- (
|
|
|
- SELECT *
|
|
|
- FROM (
|
|
|
- SELECT t.*,
|
|
|
- ROW_NUMBER() OVER(PARTITION BY t.order_no ORDER BY t.create_time DESC) AS rn
|
|
|
- FROM ins_order_adjust t where t.is_delete = 0
|
|
|
- ) x WHERE x.rn = 1
|
|
|
- ) ioa ON io.id = ioa.order_no
|
|
|
- left join
|
|
|
- (
|
|
|
- SELECT *
|
|
|
- FROM (
|
|
|
- SELECT t.*,
|
|
|
- ROW_NUMBER() OVER(PARTITION BY t.order_no ORDER BY t.create_time DESC) AS rn
|
|
|
- FROM ins_order_adjust t where t.status = 2 and t.is_delete = 0
|
|
|
- ) x WHERE x.rn = 1
|
|
|
- ) ioa1 ON io.id = ioa1.order_no
|
|
|
<where>
|
|
|
and io.is_delete = 0
|
|
|
<choose>
|
|
|
@@ -1698,7 +1852,8 @@
|
|
|
and io.parent_id != '0'
|
|
|
</otherwise>
|
|
|
</choose>
|
|
|
- and sujis.type_attr NOT IN (1,2,3,4)
|
|
|
+ AND
|
|
|
+ <include refid="orderMemberChainCond"/>
|
|
|
<if test="insOrdersParam.jzgInfoId != null and insOrdersParam.jzgInfoId != ''">
|
|
|
and io.real_quote_user_id in (select bbb.mobile from sys_user bbb where bbb.id in ( select ss.user_id
|
|
|
from sys_user_jzg_info ss where 1 =1 and (ss.leader_id = #{insOrdersParam.jzgInfoId} or ss.id
|
|
|
@@ -1707,108 +1862,10 @@
|
|
|
<if test="insOrdersParam.orderNo != null and insOrdersParam.orderNo != ''">
|
|
|
AND io.id = #{insOrdersParam.orderNo}
|
|
|
</if>
|
|
|
- <if test="insOrdersParam.licenseNo != null and insOrdersParam.licenseNo != ''">
|
|
|
- AND ioci.license_no = #{insOrdersParam.licenseNo}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.orderStatus!= null and insOrdersParam.orderStatus!= ''">
|
|
|
- AND io.order_status = #{insOrdersParam.orderStatus}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.adjustStatus!= null and insOrdersParam.adjustStatus!= ''">
|
|
|
- AND ioa.status = #{insOrdersParam.adjustStatus}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.salesman!= null">
|
|
|
- AND io.real_quote_user_id = #{insOrdersParam.salesman}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.companyId != null and insOrdersParam.companyId != ''">
|
|
|
- AND io.company_id = #{insOrdersParam.companyId}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.startDate != null and insOrdersParam.startDate != ''and insOrdersParam.endDate != null and insOrdersParam.endDate != ''">
|
|
|
- AND io.create_time BETWEEN #{insOrdersParam.startDate} and #{insOrdersParam.endDate}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.companyName != null and insOrdersParam.companyName != ''">
|
|
|
- AND io.company_name = #{insOrdersParam.companyName}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.productCode != null and insOrdersParam.productCode != ''">
|
|
|
- AND io.product_id = #{insOrdersParam.productCode}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.productName != null and insOrdersParam.productName != ''">
|
|
|
- AND io.product_name = #{insOrdersParam.productName}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.vinNo != null and insOrdersParam.vinNo != ''">
|
|
|
- AND ioci.vin_no = #{insOrdersParam.vinNo}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.ownerName != null and insOrdersParam.ownerName != ''">
|
|
|
- AND owner_u.name = #{insOrdersParam.ownerName}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.ownerMobile != null and insOrdersParam.ownerMobile != ''">
|
|
|
- AND owner_u.mobile = #{insOrdersParam.ownerMobile}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.policyName != null and insOrdersParam.policyName != ''">
|
|
|
- AND policy_u.name = #{insOrdersParam.policyName}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.policyMobile != null and insOrdersParam.policyMobile != ''">
|
|
|
- AND policy_u.mobile = #{insOrdersParam.policyMobile}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.insurName != null and insOrdersParam.insurName != ''">
|
|
|
- AND insur_u.name = #{insOrdersParam.insurName}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.insurMobile != null and insOrdersParam.insurMobile != ''">
|
|
|
- AND insur_u.mobile = #{insOrdersParam.insurMobile}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.ciStartDate != null">
|
|
|
- AND iorci.start_date = #{insOrdersParam.ciStartDate}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.biStartDate != null">
|
|
|
- AND iorbi.start_date = #{insOrdersParam.biStartDate}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.sumPremium != null">
|
|
|
- AND iorco.sum_premium = #{insOrdersParam.sumPremium}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.ciPremium != null">
|
|
|
- AND iorco.jq_premium = #{insOrdersParam.ciPremium}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.biPremium != null">
|
|
|
- AND iorco.sy_premium = #{insOrdersParam.biPremium}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.niPremium != null">
|
|
|
- AND iorco.jy_premium = #{insOrdersParam.niPremium}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.vvTax != null">
|
|
|
- AND iorco.tax_premium = #{insOrdersParam.vvTax}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.salesmanInfo != null and insOrdersParam.salesmanInfo != ''">
|
|
|
- AND su.username = #{insOrdersParam.salesmanInfo}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.salesmanType != null and insOrdersParam.salesmanType != ''">
|
|
|
- AND sujis.type_attr = #{insOrdersParam.salesmanType}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.agreementName != null and insOrdersParam.agreementName != ''">
|
|
|
- AND pa.agreement_name = #{insOrdersParam.agreementName}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.deptId != null and insOrdersParam.deptId != ''">
|
|
|
- AND sd.id = #{insOrdersParam.deptId}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.deptName != null and insOrdersParam.deptName != ''">
|
|
|
- AND sd.name = #{insOrdersParam.deptName}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.paymentLink != null and insOrdersParam.paymentLink != ''">
|
|
|
- AND io.pay_link = #{insOrdersParam.paymentLink}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.adjustId != null">
|
|
|
- AND ioa.id = #{insOrdersParam.adjustId}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.adjustPremium != null">
|
|
|
- AND ioa1.after_premium = #{insOrdersParam.adjustPremium}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.startSigningTime != null and insOrdersParam.startSigningTime != ''and insOrdersParam.endSigningTime != null and insOrdersParam.endSigningTime != ''">
|
|
|
- AND io.signing_time BETWEEN #{insOrdersParam.startSigningTime} and #{insOrdersParam.endSigningTime}
|
|
|
- </if>
|
|
|
- <if test="insOrdersParam.startPayTime != null and insOrdersParam.startPayTime != ''and insOrdersParam.endPayTime != null and insOrdersParam.endPayTime != ''">
|
|
|
- AND io.pay_time BETWEEN #{insOrdersParam.startPayTime} and #{insOrdersParam.endPayTime}
|
|
|
- </if>
|
|
|
+ <include refid="orderDetailFilterCond"/>
|
|
|
</where>
|
|
|
+ GROUP BY COALESCE(ioci.license_no, io.id), io.order_status
|
|
|
) dedup
|
|
|
- WHERE dedup.rn = 1
|
|
|
</select>
|
|
|
|
|
|
<!-- 根据主订单id集合查询其下的从订单(联表,不分页) -->
|
|
|
@@ -1879,24 +1936,24 @@
|
|
|
sys_dept sd on sd.id = suji.dept_id and sd.is_delete = 0
|
|
|
left join
|
|
|
ptl_agreement pa on pa.id = io.agreement_id and pa.is_delete = 0
|
|
|
- left join
|
|
|
- (
|
|
|
- SELECT *
|
|
|
- FROM (
|
|
|
- SELECT t.*,
|
|
|
- ROW_NUMBER() OVER(PARTITION BY t.order_no ORDER BY t.create_time DESC) AS rn
|
|
|
- FROM ins_order_adjust t where t.is_delete = 0
|
|
|
- ) x WHERE x.rn = 1
|
|
|
- ) ioa ON io.id = ioa.order_no
|
|
|
- left join
|
|
|
- (
|
|
|
- SELECT *
|
|
|
- FROM (
|
|
|
- SELECT t.*,
|
|
|
- ROW_NUMBER() OVER(PARTITION BY t.order_no ORDER BY t.create_time DESC) AS rn
|
|
|
- FROM ins_order_adjust t where t.status = 2 and t.is_delete = 0
|
|
|
- ) x WHERE x.rn = 1
|
|
|
- ) ioa1 ON io.id = ioa1.order_no
|
|
|
+ <!-- 优化1: 替代原 ROW_NUMBER() 获取最新一条 adjust 记录(避免每次查询对 ins_order_adjust 全表窗口扫描) -->
|
|
|
+ LEFT JOIN ins_order_adjust ioa
|
|
|
+ ON ioa.id = (
|
|
|
+ SELECT t.id
|
|
|
+ FROM ins_order_adjust t
|
|
|
+ WHERE t.order_no = io.id AND t.is_delete = 0
|
|
|
+ ORDER BY t.create_time DESC, t.id DESC
|
|
|
+ LIMIT 1
|
|
|
+ )
|
|
|
+ <!-- 优化2: 替代原 ROW_NUMBER() 获取 status=2 的最新一条 adjust 记录 -->
|
|
|
+ LEFT JOIN ins_order_adjust ioa1
|
|
|
+ ON ioa1.id = (
|
|
|
+ SELECT t.id
|
|
|
+ FROM ins_order_adjust t
|
|
|
+ WHERE t.order_no = io.id AND t.status = 2 AND t.is_delete = 0
|
|
|
+ ORDER BY t.create_time DESC, t.id DESC
|
|
|
+ LIMIT 1
|
|
|
+ )
|
|
|
<where>
|
|
|
and io.is_delete = 0 and io.parent_id in
|
|
|
<foreach collection="parentIds" item="pid" open="(" separator="," close=")">
|