<?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.task.BpmTaskExtMapper">

    <select id="selectTodoTaskPage" resultType="cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task.BpmTaskTodoPageRespVO">
        SELECT
            t.id,
            t.name,
            t.create_time AS createTime,
            p.process_instance_id AS processInstanceId,
            p.NAME AS processInstanceName,
            p.start_user_id AS startUserId,
            u.nickname AS startUserNickname,
            p.process_definition_id AS processDefinitionId,
            p.ccids AS ccUserIds
        FROM
            bpm_task_ext t,
            bpm_process_instance_ext p
                LEFT JOIN system_users u ON u.id = p.start_user_id
                AND u.deleted = 0
        WHERE
            t.deleted = 0
            AND p.deleted = 0
            AND t.process_instance_id = p.process_instance_id
            AND t.result = 1
            AND t.assignee_user_id = #{userId}
            AND EXISTS (
                SELECT
                    1
                FROM
                    system_dept a
                WHERE
                    a.flag LIKE CONCAT('%', #{reqVO.deptId}, '%')
                AND a.id = u.dept_id)
            <if test="reqVO.name != null and reqVO.name != '' ">
                AND p.name LIKE CONCAT('%', #{reqVO.name}, '%')
            </if>
            <if test="reqVO.createTime != null and reqVO.createTime.length > 0">
                <if test="reqVO.createTime[0] != null">
                    and t.create_time &gt;= #{reqVO.createTime[0]}
                </if>
                <if test="reqVO.createTime[1] != null">
                    and t.create_time &lt;= #{reqVO.createTime[1]}
                </if>
            </if>
    </select>

    <select id="selectTodoTaskDept" resultType="java.lang.Long">
        SELECT
            u.dept_id
        FROM
            bpm_task_ext t,
            bpm_process_instance_ext p
                LEFT JOIN system_users u ON u.id = p.start_user_id
                AND u.deleted = 0
        WHERE
            t.deleted = 0
            AND p.deleted = 0
            AND t.process_instance_id = p.process_instance_id
            AND t.result = 1
            AND t.assignee_user_id = #{userId}
            <if test="reqVO.name != null">
                AND p.name LIKE CONCAT('%', #{reqVO.name}, '%')
            </if>
            <if test="reqVO.createTime != null and reqVO.createTime.length > 0">
                <if test="reqVO.createTime[0] != null">
                    and t.create_time &gt;= #{reqVO.createTime[0]}
                </if>
                <if test="reqVO.createTime[1] != null">
                    and t.create_time &lt;= #{reqVO.createTime[1]}
                </if>
            </if>
    </select>


</mapper>
