<?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.knowledge.mapper.TTrainMapper">

    <resultMap type="cn.iocoder.yudao.module.knowledge.entity.TTrain" id="tTrainMap">
            <result property="id" column="id"/>
            <result property="code" column="code"/>
            <result property="name" column="name"/>
            <result property="holdUnit" column="hold_unit"/>
            <result property="holdForm" column="hold_form"/>
            <result property="plan" column="plan"/>
            <result property="teacherName" column="teacher_name"/>
            <result property="teacherEducation" column="teacher_education"/>
            <result property="jobTitle" column="job_title"/>
            <result property="teachTime" column="teach_time"/>
            <result property="handAddress" column="hand_address"/>
            <result property="startTime" column="start_time"/>
            <result property="stopTime" column="stop_time"/>
            <result property="holdApprovalOpinion" column="hold_approval_opinion"/>
            <result property="coApprovalOpinion" column="co_approval_opinion"/>
            <result property="desrc" column="desrc"/>
            <result property="examTime" column="start_date"/>
        <result property="duration" column="duration"/>
    </resultMap>

    <!-- 用于select查询公用抽取的列 -->
    <sql id="columns">
        id,code,name,hold_unit,hold_form,plan,teacher_name,teacher_education,job_title,teach_time,hand_address,start_time,stop_time,hold_approval_opinion,co_approval_opinion,desrc
    </sql>
    <select id="findList" resultMap="tTrainMap">
        select
        <include refid="columns"/>
        from t_train tt
        <where>
            deleted = 0
                    <if test="params.id != null">
                        and id = #{params.id}
                    </if>
                    <if test="params.code != null and params.code != ''">
                        and code = #{params.code}
                    </if>
                    <if test="params.name != null and params.name != ''">
                        and name like concat('%', #{params.name},'%')
                    </if>
                    <if test="params.holdUnit != null and params.holdUnit != ''">
                        and hold_unit = #{params.holdUnit}
                    </if>
                    <if test="params.holdForm != null">
                        and hold_form = #{params.holdForm}
                    </if>
                    <if test="params.plan != null and params.plan != ''">
                        and plan = #{params.plan}
                    </if>
                    <if test="params.teacherName != null and params.teacherName != ''">
                        and teacher_name like concat('%', #{params.teacherName}, '%')
                    </if>
                    <if test="params.teacherEducation != null and params.teacherEducation != ''">
                        and  teacher_education = #{params.teacherEducation}
                    </if>
                    <if test="params.jobTitle != null and params.jobTitle != ''">
                        and  job_title = #{params.jobTitle}
                    </if>
                    <if test="params.handAddress != null and params.handAddress != ''">
                        and  hand_address like concat('%', #{params.handAddress},'%')
                    </if>
                    <if test="params.startTime != null">
                        and  start_time <![CDATA[<=]]> #{params.startTime}
                        and stop_time  <![CDATA[>=]]> #{params.startTime}
                    </if>

                    <if test="params.holdApprovalOpinion != null and params.holdApprovalOpinion != ''">
                        and  hold_approval_opinion = #{params.holdApprovalOpinion}
                    </if>
                    <if test="params.coApprovalOpinion != null and params.coApprovalOpinion != ''">
                        and co_approval_opinion = #{params.coApprovalOpinion}
                    </if>
                    <if test="params.desrc != null and params.desrc != ''">
                        and   desrc = #{params.desrc}
                    </if>
        </where>
         order by create_time desc
    </select>

    <select id="findListByUser" resultMap="tTrainMap">
        select
        distinct tt.id,tt.code,tt.name,tt.hold_unit,tt.hold_form,tt.plan,
        tt.teacher_name,tt.teacher_education,tt.job_title,tt.teach_time,tt.hand_address,
        tt.start_time,tt.stop_time,tt.hold_approval_opinion,tt.co_approval_opinion,tt.desrc,
        ttp.duration,ttp.start_date,tt.create_time
        from t_train tt
        left join t_test_paper_info ttp on ttp.train_id = tt.id and ttp.deleted = 0
        inner join t_train_user ttu on tt.id = ttu.train_id and ttu.deleted = 0
        <where>
            tt.deleted = 0 and ttu.usercode = #{params.usercode}
            <if test="params.id != null">
                and tt.id = #{params.id}
            </if>
            <if test="params.code != null and params.code != ''">
                and tt.code = #{params.code}
            </if>
            <if test="params.name != null and params.name != ''">
                and tt.name like concat('%', #{params.name},'%')
            </if>
            <if test="params.holdUnit != null and params.holdUnit != ''">
                and tt.hold_unit = #{params.holdUnit}
            </if>
            <if test="params.holdForm != null">
                and tt.hold_form = #{params.holdForm}
            </if>
            <if test="params.plan != null and params.plan != ''">
                and tt.plan = #{params.plan}
            </if>
            <if test="params.teacherName != null and params.teacherName != ''">
                and tt.teacher_name like concat('%', #{params.teacherName}, '%')
            </if>
            <if test="params.teacherEducation != null and params.teacherEducation != ''">
                and  tt.teacher_education = #{params.teacherEducation}
            </if>
            <if test="params.jobTitle != null and params.jobTitle != ''">
                and  tt.job_title = #{params.jobTitle}
            </if>
            <if test="params.handAddress != null and params.handAddress != ''">
                and  tt.hand_address like concat('%', #{params.handAddress},'%')
            </if>
            <if test="params.startTime != null">
                and  tt.start_time <![CDATA[<=]]> #{params.startTime}
                and tt.stop_time  <![CDATA[>=]]> #{params.startTime}
            </if>

            <if test="params.holdApprovalOpinion != null and params.holdApprovalOpinion != ''">
                and  tt.hold_approval_opinion = #{params.holdApprovalOpinion}
            </if>
            <if test="params.coApprovalOpinion != null and params.coApprovalOpinion != ''">
                and tt.co_approval_opinion = #{params.coApprovalOpinion}
            </if>
            <if test="params.desrc != null and params.desrc != ''">
                and   tt.desrc = #{params.desrc}
            </if>
        </where>
        order by tt.create_time desc
    </select>

</mapper>
