refactor(purchase): 优化采购订单查询的动态SQL逻辑
- 将原有的静态字段映射改为根据表名动态选择字段 - 使用choose/when替代if条件判断,提高SQL的可读性 - 重构了bu_todo和bu_todo_completed表的查询逻辑 - 移除了重复的approve_user条件过滤 - 优化了已完成任务表的聚合查询,使用max函数获取最新审批时间master
parent
a48315e409
commit
0b0add0b48
|
|
@ -116,18 +116,49 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
, t1.status, t1.approve_status, t1.approve_time, t1.approve_node, t1.confirm_status, t1.create_time, t1.update_time, t1.del_flag,t1.version
|
||||
, t1.file_id
|
||||
,t2.vendor_name,t2.vendor_user,t2.vendor_phone
|
||||
|
||||
<choose>
|
||||
<when test="'bu_todo'.equals(tableName)">
|
||||
,t3.apply_time,t3.process_key,t3.todo_id,t3.task_id
|
||||
<if test="'bu_todo_completed'.equals(tableName)">
|
||||
,t3.approve_time as todo_approve_time
|
||||
</if>
|
||||
</when>
|
||||
<when test="'bu_todo_completed'.equals(tableName)">
|
||||
,t3.apply_time,t3.approve_time as todo_approve_time,t3.process_key
|
||||
</when>
|
||||
</choose>
|
||||
from oms_purchase_order t1
|
||||
left join oms_vendor_info t2 on t1.vendor_id = t2.vendor_id
|
||||
inner join ${tableName} t3 on (t3.process_key in ('purchase_order_online') and t3.approve_user=#{entity.approveUser} and t3.task_name!='商务' and t3.business_key=t1.purchase_no)
|
||||
inner join
|
||||
<choose>
|
||||
<when test="'bu_todo'.equals(tableName)">
|
||||
(select bt.business_key,bt.apply_time,bt.process_key,bt.todo_id,bt.task_id from bu_todo bt
|
||||
WHERE
|
||||
bt.process_key IN ('purchase_order_online')
|
||||
AND bt.approve_user = #{entity.approveUser}
|
||||
AND bt.task_name!='商务'
|
||||
)
|
||||
</when>
|
||||
<when test="'bu_todo_completed'.equals(tableName)">
|
||||
(SELECT
|
||||
business_key,
|
||||
max(btc.approve_time) approve_time,
|
||||
max(btc.apply_time) apply_time,
|
||||
max(btc.process_key) process_key
|
||||
|
||||
FROM
|
||||
bu_todo_completed btc
|
||||
WHERE
|
||||
btc.process_key IN ('purchase_order_online')
|
||||
AND btc.approve_user = #{entity.approveUser}
|
||||
AND btc.task_name!='商务'
|
||||
GROUP BY business_key)
|
||||
</when>
|
||||
</choose>
|
||||
t3 on t3.business_key=t1.purchase_no
|
||||
<where>
|
||||
<if test="entity.purchaseNo != null and entity.purchaseNo != ''"> and t1.purchase_no = #{entity.purchaseNo}</if>
|
||||
<if test="entity.vendorName != null "> and t2.vendor_name = #{entity.vendorName}</if>
|
||||
<if test="entity.ownerName != null "> and t1.owner_name = #{entity.ownerName}</if>
|
||||
<if test="entity.approveUser != null "> and t3.approve_user = #{entity.approveUser}</if>
|
||||
<!-- <if test="entity.approveUser != null "> and t3.approve_user = #{entity.approveUser}</if>-->
|
||||
<if test="entity.params.applyTimeStart != null and entity.params.applyTimeEnd != ''">
|
||||
<choose>
|
||||
<when test="entity.params.applyTimeStart != null and entity.params.applyTimeEnd != null">
|
||||
|
|
|
|||
Loading…
Reference in New Issue