zn-cloud/yudao-module-bpm/yudao-module-bpm-biz/src/main/resources/mapper/oa/BpmOAWorkOrderMapper.xml
aikai f02142ed03 refactor(bpm): 优化工作订单相关 SQL 查询中的时间范围搜索逻辑
- 将单一的 BETWEEN 条件拆分为两个独立的条件
- 允许单独搜索开始时间和结束时间
- 提高了查询的灵活性和准确性
2025-07-01 09:35:42 +08:00

208 lines
8.2 KiB
XML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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="cn.iocoder.yudao.module.bpm.dal.mysql.oa.BpmOAWorkOrderMapper">
<!-- 工单分页查询结果映射 -->
<resultMap id="WorkOrderPageResultMap" type="cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.workorder.BpmOAWorkOrderRespVO">
<id column="id" property="id"/>
<result column="title" property="title"/>
<result column="type" property="type"/>
<result column="level" property="level"/>
<result column="content" property="content"/>
<result column="from_user_id" property="fromUserId"/>
<result column="from_dept_id" property="fromDeptId"/>
<result column="assignee_user_id" property="assigneeUserId"/>
<result column="assignee_dept_id" property="assigneeDeptId"/>
<result column="status" property="status"/>
<result column="expected_time" property="expectedTime"/>
<result column="completed_time" property="completedTime"/>
<result column="result_description" property="resultDescription"/>
<result column="result" property="result"/>
<result column="process_instance_id" property="processInstanceId"/>
<result column="create_time" property="createTime"/>
<result column="update_time" property="updateTime"/>
<!-- 关联用户和部门名称 -->
<result column="from_user_name" property="fromUserName"/>
<result column="from_dept_name" property="fromDeptName"/>
<result column="assignee_user_name" property="assigneeUserName"/>
<result column="assignee_dept_name" property="assigneeDeptName"/>
<!-- 字典名称 -->
<result column="type_name" property="typeName"/>
<result column="level_name" property="levelName"/>
<result column="status_name" property="statusName"/>
</resultMap>
<!-- 工单分页查询SQL所有工单 -->
<select id="selectWorkOrderPage" resultMap="WorkOrderPageResultMap">
SELECT
w.id,
w.title,
w.type,
w.level,
w.content,
w.from_user_id,
w.from_dept_id,
w.assignee_user_id,
w.assignee_dept_id,
w.status,
w.expected_time,
w.completed_time,
w.result_description,
w.result,
w.process_instance_id,
w.create_time,
w.update_time,
fu.nickname AS from_user_name,
fd.name AS from_dept_name,
au.nickname AS assignee_user_name,
ad.name AS assignee_dept_name
FROM bpm_oa_work_order w
LEFT JOIN system_users fu ON w.from_user_id = fu.id
LEFT JOIN system_dept fd ON w.from_dept_id = fd.id
LEFT JOIN system_users au ON w.assignee_user_id = au.id
LEFT JOIN system_dept ad ON w.assignee_dept_id = ad.id
<where>
w.deleted = 0
<if test="req.title != null and req.title != ''">
AND w.title LIKE CONCAT('%', #{req.title}, '%')
</if>
<if test="req.type != null and req.type != ''">
AND w.type = #{req.type}
</if>
<if test="req.status != null">
AND w.status = #{req.status}
</if>
<if test="req.assigneeUserId != null">
AND w.assignee_user_id = #{req.assigneeUserId}
</if>
<if test="req.fromUserId != null">
AND w.from_user_id = #{req.fromUserId}
</if>
<if test="req.level != null">
AND w.level = #{req.level}
</if>
<if test="req.createTime != null and req.createTime.length > 0">
<if test="req.createTime[0] != null">
AND w.create_time &gt;= #{req.createTime[0]}
</if>
<if test="req.createTime[1] != null">
AND w.create_time &lt;= #{req.createTime[1]}
</if>
</if>
</where>
ORDER BY w.id DESC
</select>
<!-- 我发起的工单分页查询SQL -->
<select id="selectMyWorkOrderPage" resultMap="WorkOrderPageResultMap">
SELECT
w.id,
w.title,
w.type,
w.level,
w.content,
w.from_user_id,
w.from_dept_id,
w.assignee_user_id,
w.assignee_dept_id,
w.status,
w.expected_time,
w.completed_time,
w.result_description,
w.result,
w.process_instance_id,
w.create_time,
w.update_time,
fu.nickname AS from_user_name,
fd.name AS from_dept_name,
au.nickname AS assignee_user_name,
ad.name AS assignee_dept_name
FROM bpm_oa_work_order w
LEFT JOIN system_users fu ON w.from_user_id = fu.id
LEFT JOIN system_dept fd ON w.from_dept_id = fd.id
LEFT JOIN system_users au ON w.assignee_user_id = au.id
LEFT JOIN system_dept ad ON w.assignee_dept_id = ad.id
<where>
w.deleted = 0 AND w.from_user_id = #{req.loginUserId}
<if test="req.title != null and req.title != ''">
AND w.title LIKE CONCAT('%', #{req.title}, '%')
</if>
<if test="req.type != null and req.type != ''">
AND w.type = #{req.type}
</if>
<if test="req.status != null">
AND w.status = #{req.status}
</if>
<if test="req.createTime != null and req.createTime.length > 0">
<if test="req.createTime[0] != null">
AND w.create_time &gt;= #{req.createTime[0]}
</if>
<if test="req.createTime[1] != null">
AND w.create_time &lt;= #{req.createTime[1]}
</if>
</if>
</where>
ORDER BY w.id DESC
</select>
<!-- 分配给我的工单分页查询SQL -->
<select id="selectAssignedWorkOrderPage" resultMap="WorkOrderPageResultMap">
SELECT
w.id,
w.title,
w.type,
w.level,
w.content,
w.from_user_id,
w.from_dept_id,
w.assignee_user_id,
w.assignee_dept_id,
w.status,
w.expected_time,
w.completed_time,
w.result_description,
w.result,
w.process_instance_id,
w.create_time,
w.update_time,
fu.nickname AS from_user_name,
fd.name AS from_dept_name,
au.nickname AS assignee_user_name,
ad.name AS assignee_dept_name
FROM bpm_oa_work_order w
LEFT JOIN system_users fu ON w.from_user_id = fu.id
LEFT JOIN system_dept fd ON w.from_dept_id = fd.id
LEFT JOIN system_users au ON w.assignee_user_id = au.id
LEFT JOIN system_dept ad ON w.assignee_dept_id = ad.id
<where>
w.deleted = 0 AND w.assignee_user_id = #{req.loginUserId}
<if test="req.title != null and req.title != ''">
AND w.title LIKE CONCAT('%', #{req.title}, '%')
</if>
<if test="req.type != null and req.type != ''">
AND w.type = #{req.type}
</if>
<if test="req.status != null">
AND w.status = #{req.status}
</if>
<if test="req.createTime != null and req.createTime.length > 0">
<if test="req.createTime[0] != null">
AND w.create_time &gt;= #{req.createTime[0]}
</if>
<if test="req.createTime[1] != null">
AND w.create_time &lt;= #{req.createTime[1]}
</if>
</if>
</where>
ORDER BY w.id DESC
</select>
<select id="selectByProcessInstanceId"
resultType="cn.iocoder.yudao.module.bpm.dal.dataobject.oa.BpmOAWorkOrderDO">
select a.*
from bpm_oa_work_order a
where a.deleted = 0
and a.process_instance_id = #{processInstanceId}
</select>
</mapper>