<?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="com.nantian.cloud.jljc.mapper.TTrainingPersonMapper">

	<!-- 可根据自己的需求，是否要使用 -->
    <resultMap type="com.nantian.cloud.jljc.entity.TTrainingPerson" id="tTrainingPersonMap">
        <result property="id" column="id"/>
        <result property="trainingId" column="training_id"/>
        <result property="name" column="name"/>
        <result property="idType" column="id_type"/>
        <result property="idNumber" column="id_number"/>
        <result property="sex" column="sex"/>
        <result property="enterpriseId" column="enterprise_id"/>
        <result property="epc" column="epc"/>
        <result property="state" column="state"/>
        <result property="delFlag" column="del_flag"/>
        <result property="remarks" column="remarks"/>
        <result property="userid" column="userid"/>
        <result property="updateTime" column="update_time"/>
        <result property="telephone" column="telephone"/>
        <result column="dept_id" property="deptId"/>
        <result column="ethnic" property="ethnic"/>
        <result column="dinner" property="dinner"/>
        <result column="accommodation" property="accommodation"/>
        <result column="territorial" property="territorial"/>
        <result column="enterpriseName" property="enterpriseName"/>
        <result column="jobTitle" property="jobTitle"/>
        <result column="location" property="location"/>
        <result column="type" property="type"/>
        <result column="trainingSession" property="training_session"/>
    </resultMap>



<!--    根据条件查询数据信息
    -->
    <select id="getInfo" parameterType="java.lang.String" resultType="java.lang.Object">
        SELECT * FROM t_training_person
    WHERE 1 = 1
    <if test="enterpriseName != null || enterpriseName !=''">
      and  enterpriseName like '%'||#{enterpriseName}||'%'
    </if>
     <if test="name != null || name !=''">
         and  name like '%'||#{name}||'%'
     </if>
     <if test="updateTime != null || updateTime !=''">
         and  convert(update_time,DATETIME) like #{updateTime}||'%'
     </if>
    </select>



    <!--统计报名人数-->
    <select id="getCount" parameterType="java.lang.Integer" resultType="java.lang.Object">
        select count(*) from t_training_person where training_id = #{trainingId}
        and del_flag=1
    </select>

<!--查询人员信息-->
    <select id="getPersonInfo" parameterType="java.lang.String" resultType="java.lang.Object">
        SELECT enterprise_name,name,sex,ethnic,telephone,dinner,accommodation,territorial
        FROM t_training_person t
        WHERE t.training_id = #{trainingId}
        <if test="t.territorial != null || t.territorial !=''">
            and  t.territorial  like concat('%',#{territorial},'%')
        </if>
        <if test="t.enterpriseName != null || t.enterpriseName !=''">
            and  t.enterprise_name like concat('%',#{enterpriseName},'%')
        </if>
        <if test="name != null || name !=''">
            and  t.name like concat('%',#{name},'%')
        </if>
        and t.del_flag=1
    </select>


    <select id="getInfoT" parameterType="java.lang.Object" resultType="list">
        SELECT p.enterprise_name,p.name,p.sex,p.ethnic,p.telephone,p.dinner,p.accommodation,p.territorial,t.name,t.content,t.topic,t.start_time,t.end_time
        FROM t_training_person p,t_training t
        WHERE p.training_id = t.id
        and p.training_id = #{trainingId}
        <if test="p.enterpriseName != null || p.enterpriseName !=''">
            and  p.enterpriseName like '%'||#{enterpriseName}||'%'
        </if>
        <if test="p.updateTime != null || p.updateTime !=''">
            and  convert(p.update_time,DATETIME) like #{updateTime}||'%'
        </if>
    </select>


    <select id="getInfoBy" parameterType="java.lang.Object" resultMap="tTrainingPersonMap">
        SELECT enterprise_name,name,sex,ethnic,telephone,dinner,accommodation,territorial
        FROM t_training_person
        WHERE 1 = 1
        <if test="enterpriseName != null || enterpriseName !=''">
            and  enterpriseName like '%'||#{enterpriseName}||'%'
        </if>
        <if test="updateTime != null || updateTime !=''">
            and  convert(update_time,DATETIME) like #{updateTime}||'%'
        </if>
    </select>

    <select id="getInfoByBrainingId" parameterType="java.lang.String" resultMap="tTrainingPersonMap">
        select training_id from t_training_person where enterprise_name like '%'||#{enterpriseName}||'%'
    </select>


    <select id="getInfoById" parameterType="java.lang.Object" resultType="list">
        SELECT p.enterprise_name,p.name,p.sex,p.ethnic,p.telephone,p.dinner,p.accommodation,p.territorial,t.name,t.content,t.topic,t.start_time,t.end_time
        FROM t_training_person p,t_training t
        WHERE  t.id = p.training_id
        and t.id = #{id}
        <if test="p.enterpriseName != null || p.enterpriseName !=''">
            and  p.enterpriseName like '%'||#{enterpriseName}||'%'
        </if>
        <if test="p.updateTime != null || p.updateTime !=''">
            and  convert(p.update_time,DATETIME) like #{updateTime}||'%'
        </if>
    </select>

    <select id="getPerson" parameterType="java.lang.String" resultMap="tTrainingPersonMap">
        SELECT enterprise_name,name,sex,ethnic,telephone,dinner,accommodation,territorial
        FROM t_training_person
        where  training_id = #{id}
    </select>


    <select id="getCountById" parameterType="java.lang.Integer" resultType="java.lang.Integer">
        select count(*) from t_training_person where training_id = #{id} and del_flag=1
    </select>

    <select id="pageByScope" resultType="com.nantian.cloud.jljc.vo.TTrainingPersonVo">
        select p.*,t.name trainingName,t.start_time startTime,t.end_time endTime
        from t_training_person p
        left join t_training t on t.id = p.training_id
        where p.del_flag = 1
        <if test="p.trainingName != null and p.trainingName !=''">
            and  t.name like concat('%',#{p.trainingName},'%')
        </if>
        <if test="p.year != null and p.year !=''">
            and  t.start_sign_up_time like concat('%',#{p.year},'%')
        </if>
        <if test="p.trainingSession != null and p.trainingSession !=''">
            and  p.training_session like concat('%',#{p.trainingSession},'%')
        </if>
        <if test="p.enterpriseName != null and p.enterpriseName !=''">
            and  p.enterprise_name like concat('%',#{p.enterpriseName},'%')
        </if>
        <if test="p.name != null and p.name !=''">
            and  p.name like concat('%',#{p.name},'%')
        </if>
        <if test="p.dinner != null and p.dinner !=''">
            and  p.dinner like concat('%',#{p.dinner},'%')
        </if>
        <if test="p.accommodation != null and p.accommodation !=''">
            and  p.accommodation like concat('%',#{p.accommodation},'%')
        </if>
        <if test="p.territorial != null and p.territorial !=''">
            and  p.territorial like concat('%',#{p.territorial},'%')
        </if>
        <if test="p.jobTitle != null and p.jobTitle !=''">
            and  p.job_title like concat('%',#{p.jobTitle},'%')
        </if>
        <if test="p.location != null and p.location !=''">
            and  p.location like concat('%',#{p.location},'%')
        </if>
        <if test="p.type!=null and p.type!='' and p.type != '0'">
            and  p.type = #{p.type}
        </if>
        order by p.update_time desc
    </select>
    <select id="getTrainingPersonInfo" resultType="com.nantian.cloud.jljc.vo.TTrainingPersonVo">
        SELECT tp.*,t.name as training_name,t.topic,t.start_time,t.end_time
        FROM t_training_person tp,t_training t
        WHERE tp.userid= #{userid}
          <if test="year!=null and year!=''">
              and year(t.start_time) like concat('%',#{year},'%')
          </if>
          <if test="trainingName!=null and trainingName!=''">
              and t.name like concat('%',#{trainingName},'%')
          </if>
        and tp.training_id =t.id
        and tp.del_flag = 1
        order by tp.update_time desc
    </select>


</mapper>