<?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="applyReason" column="apply_reason" 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="updateRecord" column="update_record" 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,apply_reason,
        reviewer,status,reason,
        update_record,create_time,create_by,
        update_time,update_by
    </sql>

<!--    连接委托表查询委托案件名称-->
    <sql id="getVOSQL">
        SELECT eaa.*, ce.case_name, ce.id as case_id 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 ce.case_name LIKE CONCAT('%', #{query.keywords}, '%')
            </if>
            <if test="query.applicant != null and query.applicant != ''">
                AND eaa.applicant_id = #{query.applicant}
            </if>
            <if test="query.startDate != null">
                AND eaa.apply_date &gt;= #{query.startDate}
            </if>
            <if test="query.endDate != null">
                AND eaa.apply_date &lt;= #{query.endDate}
            </if>
            <if test="query.status != null">
                AND eaa.status = #{query.status}
            </if>
            <if test="query.isStaff != null and !query.isStaff and query.clientOrgId != null and query.clientOrgId != ''">
                AND eaa.apply_org_id = #{query.clientOrgId}
            </if>
        </where>
        ORDER BY eaa.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>
