where (is_publish = 1 or enforcement_department_id IN ( SELECT dept_id FROM sys_dept WHERE dept_id = #{bo.deptId} or find_in_set( #{bo.deptId} , ancestors ) != 0 ))
<iftest="bo.searchText != null and bo.searchText != ''">
and (plan_name like concat('%', #{bo.searchText}, '%')
or enforcement_department like concat('%', #{bo.searchText}, '%')
or bureau_dept_name like concat('%', #{bo.searchText}, '%'))
</if>
order by create_time desc
<where>
<!-- 使用 UNION 替代 OR,提升查询性能 -->
id IN (
<!-- 已发布的计划 -->
SELECT id FROM enforcement_inspection_program WHERE is_publish = 1
UNION
<!-- 本部门及下级部门的计划 -->
SELECT id FROM enforcement_inspection_program
WHERE enforcement_department_id IN (
SELECT dept_id FROM sys_dept
WHERE dept_id = #{bo.deptId}
OR FIND_IN_SET(#{bo.deptId}, ancestors) != 0
)
)
<!-- 搜索条件 -->
<iftest="bo.searchText != null and bo.searchText != ''">
AND (plan_name LIKE CONCAT('%', #{bo.searchText}, '%')
OR enforcement_department LIKE CONCAT('%', #{bo.searchText}, '%')
OR bureau_dept_name LIKE CONCAT('%', #{bo.searchText}, '%'))