<?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="digital.laboratory.platform.entrustment.mapper.EntrustAlterApplyMapper">

    <resultMap id="BaseResultMap" type="digital.laboratory.platform.entrustment.entity.EntrustAlterApply">
            <id property="id" column="id" jdbcType="VARCHAR"/>
            <result property="entrustId" column="entrust_id" jdbcType="VARCHAR"/>
            <result property="applicant" column="applicant" jdbcType="VARCHAR"/>
            <result property="applyDate" column="apply_date" jdbcType="TIMESTAMP"/>
            <result property="applyOrgId" column="apply_org_id" jdbcType="VARCHAR"/>
            <result property="reviewer" column="reviewer" jdbcType="VARCHAR"/>
            <result property="status" column="status" jdbcType="TINYINT"/>
            <result property="reason" column="reason" jdbcType="VARCHAR"/>
            <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
            <result property="createBy" column="create_by" jdbcType="VARCHAR"/>
            <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
            <result property="updateBy" column="update_by" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="Base_Column_List">
        id,entrust_id,applicant,
        apply_date,apply_org_id,reviewer,
        status,reason,create_time,
        create_by,update_time,update_by
    </sql>

<!--    连接委托表查询委托案件名称-->
    <sql id="getVOSQL">
        SELECT eaa.*, ce.case_name FROM
            b_entrust_alter_apply eaa
                LEFT JOIN b_entrustment e ON eaa.entrust_id = e.id
                LEFT JOIN b_case_event ce ON ce.id = e.case_id
    </sql>

    <select id="getEntrustAlterApplyVOPage"
            resultType="digital.laboratory.platform.entrustment.vo.EntrustAlterApplyVO">
        <include refid="getVOSQL"/>
        <where>
            <if test="query.keywords != null and query.keywords != ''">
                AND case_name LIKE CONCAT('%', #{keywords}, '%')
            </if>
            <if test="query.applicant != null and query.applicant != ''">
                AND applicant_id = #{applicant}
            </if>
            <if test="query.startDate != null">
                AND apply_date &gt;= #{startDate}
            </if>
            <if test="query.endDate != null">
                AND apply_date &lt;= #{endDate}
            </if>
            <if test="query.status != null">
                AND status &lt;= #{status}
            </if>
            <if test="query.isStaff != null and !query.isStaff and query.clientOrgId != null and query.clientOrgId != ''">
                AND apply_org_id = #{query.clientOrgId}
            </if>
        </where>
        ORDER BY apply_date DESC
    </select>

    <select id="getEntrustAlterApplyVOOne"
            resultType="digital.laboratory.platform.entrustment.vo.EntrustAlterApplyVO">
        <include refid="getVOSQL"/>
        ${ew.customSqlSegment}
    </select>

    <select id="getEntrustAlterApplyVOList"
            resultType="digital.laboratory.platform.entrustment.vo.EntrustAlterApplyVO">
        <include refid="getVOSQL"/>
        ${ew.customSqlSegment}
    </select>
</mapper>
