<?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.wechat.dao.MdeInterviewDao" >
  <resultMap id="BaseResultMap" type="com.wechat.model.dbEntity.MdeInterview" >
    <id column="INTV_ID" property="intvId" jdbcType="INTEGER" />
    <result column="JOB_ID" property="jobId" jdbcType="INTEGER" />
    <result column="PUBLISHER" property="publisher" jdbcType="VARCHAR" />
    <result column="INTERVIEWEE" property="interviewee" jdbcType="VARCHAR" />
    <result column="ENT_CONTACTS" property="entContacts" jdbcType="VARCHAR" />
    <result column="ENT_CONTACT_INFO" property="entContactInfo" jdbcType="VARCHAR" />
    <result column="TYPE" property="type" jdbcType="CHAR" />
    <result column="ADDR_PROVINCE" property="addrProvince" jdbcType="VARCHAR" />
    <result column="ADDR_CITY" property="addrCity" jdbcType="VARCHAR" />
    <result column="ADDR_AREA" property="addrArea" jdbcType="VARCHAR" />
    <result column="ADD_DETAIL" property="addDetail" jdbcType="VARCHAR" />
    <result column="INTV_TIME" property="intvTime" jdbcType="TIMESTAMP" />
    <result column="STATUS" property="status" jdbcType="CHAR" />
    <result column="VERSION_NO" property="versionNo" jdbcType="INTEGER" />
    <result column="CREATE_BY" property="createBy" jdbcType="VARCHAR" />
    <result column="CREATE_DATE" property="createDate" jdbcType="TIMESTAMP" />
    <result column="UPDATE_BY" property="updateBy" jdbcType="VARCHAR" />
    <result column="UPDATE_DATE" property="updateDate" jdbcType="TIMESTAMP" />
    <result column="REMARKS" property="remarks" jdbcType="VARCHAR" />
    <result column="DEL_FLAG" property="delFlag" jdbcType="CHAR" />
  </resultMap>
  <sql id="Base_Column_List" >
    INTV_ID, JOB_ID, PUBLISHER, INTERVIEWEE, ENT_CONTACTS, ENT_CONTACT_INFO, TYPE, ADDR_PROVINCE, 
    ADDR_CITY, ADDR_AREA, ADD_DETAIL, INTV_TIME, STATUS, VERSION_NO, CREATE_BY, CREATE_DATE, 
    UPDATE_BY, UPDATE_DATE, REMARKS, DEL_FLAG
  </sql>
  
  <resultMap type="com.wechat.model.dto.InterviewListDto" id="interviewListDtoMap">
	 <id column="intvId" property="intvId"/>
	 <result column="jobId" property="jobId"/>
	 <result column="publisher" property="publisher"/>
	 <result column="interviewee" property="interviewee"/>
	 <result column="entContacts" property="entContacts"/>
	 <result column="entContactInfo" property="entContactInfo"/>
	 <result column="type" property="type"/>
	 <result column="addrProvince" property="addrProvince"/>
	 <result column="addrCity" property="addrCity"/>
	 <result column="addrArea" property="addrArea"/>
	 <result column="addDetail" property="addDetail"/>
	 <result column="intvTime" property="intvTime"/>
	 <result column="status" property="status"/>
	 <result column="inviteDate" property="inviteDate"/>
	 <result column="updateDate" property="updateDate"/>
	<collection column="intvId" property="interviewTime" ofType="com.wechat.model.dto.InterviewTimeListDto" >
		<result column="intvTimeId" property="intvTimeId"/>
		<result column="intvTimeFrom" property="intvTimeFrom"/>    
        <result column="intvTimeTo" property="intvTimeTo"/>
        <result column="confirmedBy" property="confirmedBy"/>
	</collection>
  </resultMap>
  
  <resultMap type="com.wechat.model.dto.InterviewDetailDto" id="intvDetailMap">
	 <id column="intvId" property="intvId"/>
	 <result column="jobId" property="jobId"/>
	 <result column="publisher" property="publisher"/>
	 <result column="interviewee" property="interviewee"/>
	 <result column="entContacts" property="entContacts"/>
	 <result column="entContactInfo" property="entContactInfo"/>
	 <result column="type" property="type"/>
	 <result column="addrProvince" property="addrProvince"/>
	 <result column="addrCity" property="addrCity"/>
	 <result column="addrArea" property="addrArea"/>
	 <result column="addrProvinceName" property="addrProvinceName"/>
	 <result column="addrCityName" property="addrCityName"/>
	 <result column="addrAreaName" property="addrAreaName"/>
	 <result column="addDetail" property="addDetail"/>
	 <result column="intvTime" property="intvTime"/>
	 <result column="roomId" property="roomId"/>
	 <result column="status" property="status"/>
	 <result column="inviteDate" property="inviteDate"/>
	 <result column="updateDate" property="updateDate"/>
	<collection column="intvTimeId" property="intvTimeList" ofType="com.wechat.model.dto.IntvTimeDto" >
		<result column="intvTimeId" property="intvTimeId"/>
		<result column="intvTimeFrom" property="intvTimeFrom"/>    
        <result column="intvTimeTo" property="intvTimeTo"/>
        <result column="confirmedBy" property="confirmedBy"/>
        <result column="status" property="status"/>
        <result column="content" property="content"/>
        <result column="sort" property="sort"/>
	</collection>
  </resultMap>
  
  <select id="getIntvListP" resultMap="interviewListDtoMap" >
	SELECT
		 intv.INTV_ID           as intvId
		,intv.JOB_ID            as jobId
		,intv.PUBLISHER         as publisher
		,intv.INTERVIEWEE       as interviewee
		,intv.ENT_CONTACTS      as entContacts
		,intv.ENT_CONTACT_INFO  as entContactInfo
		,intv.TYPE              as type
		,intv.ADDR_PROVINCE     as addrProvince
		,intv.ADDR_CITY         as addrCity
		,intv.ADDR_AREA         as addrArea
		,intv.ADD_DETAIL        as addDetail
		,intv.INTV_TIME         as intvTime
		,intv.STATUS            as status
		,intv.CREATE_DATE       as inviteDate
		,intv.UPDATE_DATE       as updateDate
		,time.INTV_TIME_ID   as intvTimeId
		,time.INTV_TIME_FROM as intvTimeFrom
		,time.INTV_TIME_TO   as intvTimeTo
		,time.CONFIRMED_BY   as confirmedBy
	FROM
		mde_interview intv
		INNER JOIN mde_user usr ON intv.PUBLISHER = usr.USER_CODE
		INNER JOIN mde_job_advertised job ON intv.JOB_ID = job.JOB_ID
		LEFT JOIN mde_intv_time time ON intv.INTV_ID = time.INTV_ID 
		AND time.STATUS = '0' 
		AND time.DEL_FLAG = '0' 
	WHERE
		intv.INTERVIEWEE = #{interviewee}
		AND intv.DEL_FLAG = '0'
  </select>
  
  <select id="getIntvDetail" resultMap="intvDetailMap" >
	SELECT
		 intv.INTV_ID           as intvId
		,intv.JOB_ID            as jobId
		,intv.PUBLISHER         as publisher
		,intv.INTERVIEWEE       as interviewee
		,intv.ENT_CONTACTS      as entContacts
		,intv.ENT_CONTACT_INFO  as entContactInfo
		,intv.TYPE              as type
		,intv.ADDR_PROVINCE     as addrProvince
		,intv.ADDR_CITY         as addrCity
		,intv.ADDR_AREA         as addrArea
		,intv.ADD_DETAIL        as addDetail
		,intv.INTV_TIME         as intvTime
		,intv.ROOM_ID           as roomId
		,intv.STATUS            as status
		,time.INTV_TIME_ID      as intvTimeId
		,time.INTV_TIME_FROM    as intvTimeFrom
		,time.INTV_TIME_TO      as intvTimeTo
		,time.CONFIRMED_BY      as confirmedBy
		,time.CONTENT           as content
		,time.sort              as sort
		,c.name                 as addrProvinceName
		,d.name                 as addrCityName
		,e.name                 as addrAreaName
	FROM
		mde_interview intv
		INNER JOIN mde_user usr ON intv.PUBLISHER = usr.USER_CODE
		INNER JOIN mde_job_advertised job ON intv.JOB_ID = job.JOB_ID
		LEFT JOIN mde_intv_time time 
			ON intv.INTV_ID = time.INTV_ID  
			 AND time.STATUS = '0' 
		     AND time.DEL_FLAG = '0'
		left join sys_area c on c.code=intv.addr_province 
		left join sys_area d on d.code=intv.addr_city 
		left join sys_area e on e.code=intv.addr_area 
	WHERE
		intv.INTV_ID = #{intvId}
		<if test="interviewee != null and interviewee !=''" >
			and intv.INTERVIEWEE = #{interviewee}
		 </if>
		<if test="publisher != null and publisher !=''" >
			and intv.PUBLISHER = #{publisher}
		 </if>
		AND intv.DEL_FLAG = '0'
  </select>
  
  <update id="confirmIntvTime" parameterType="com.wechat.model.dbEntity.MdeInterview" >
    update mde_interview
    set 
      INTV_TIME = #{intvTime,jdbcType=TIMESTAMP},
      ROOM_ID = #{roomId},
      STATUS = #{status,jdbcType=CHAR},
      UPDATE_BY = #{updateBy,jdbcType=VARCHAR},
      UPDATE_DATE = #{updateDate,jdbcType=TIMESTAMP},
      version_no = version_no +1
    where INTV_ID = #{intvId}
     <if test="publisher != null and publisher !=''" >
        and PUBLISHER = #{publisher}
      </if>
      <if test="interviewee != null and interviewee !=''" >
        and INTERVIEWEE = #{interviewee}
      </if>
  </update>
  
  <update id="updateIntvStatus" parameterType="com.wechat.model.dbEntity.MdeInterview" >
    update mde_interview
    set 
      STATUS = #{status,jdbcType=CHAR},
      UPDATE_BY = #{updateBy,jdbcType=VARCHAR},
      UPDATE_DATE = #{updateDate,jdbcType=TIMESTAMP},
     <if test="remarks != null" >
      REMARKS = #{remarks,jdbcType=VARCHAR},
      </if>
      version_no = version_no +1
    where INTV_ID = #{intvId}
       <if test="publisher != null and publisher !=''" >
        and PUBLISHER = #{publisher}
      </if>
      <if test="interviewee != null and interviewee !=''" >
        and INTERVIEWEE = #{interviewee}
      </if>
  </update>
  
  
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
    delete from mde_interview
    where INTV_ID = #{intvId,jdbcType=INTEGER}
  </delete>
  
  
  <select id="getIntvByRoomId" resultType="com.wechat.model.dbEntity.MdeInterview" >
	SELECT
		 intv.INTV_ID           as intvId
		,intv.JOB_ID            as jobId
		,intv.PUBLISHER         as publisher
		,intv.INTERVIEWEE       as interviewee
		,intv.TYPE              as type
		,intv.INTV_TIME         as intvTime
		,intv.ROOM_ID           as roomId
		,intv.STATUS            as status
	FROM
		mde_interview intv
	WHERE
		intv.ROOM_ID = #{roomId}
	  <if test="publisher != null and publisher !=''" >
        and PUBLISHER = #{publisher}
      </if>
      <if test="interviewee != null and interviewee !=''" >
        and INTERVIEWEE = #{interviewee}
      </if>
		AND intv.STATUS = '3' 
		AND intv.DEL_FLAG = '0'
	ORDER BY
		intv.INTV_TIME DESC 
	LIMIT 1
  </select>
  

  <insert id="insert" useGeneratedKeys="true" keyProperty="intvId" parameterType="com.wechat.model.dbEntity.MdeInterview" >
    insert into mde_interview (INTV_ID, JOB_ID, PUBLISHER, 
      INTERVIEWEE, ENT_CONTACTS, ENT_CONTACT_INFO, 
      TYPE, 
      <if test="addrProvince != null" >
        ADDR_PROVINCE,
      </if>
      <if test="addrCity != null" >
        ADDR_CITY,
      </if>
      <if test="addrArea != null" >
        ADDR_AREA,
      </if>
      <if test="addDetail != null" >
        ADD_DETAIL,
      </if>
      <if test="intvTime != null" >
        INTV_TIME,
      </if> 
      STATUS, CREATE_BY, 
      CREATE_DATE, UPDATE_BY, UPDATE_DATE, 
      REMARKS)
    values (#{intvId,jdbcType=INTEGER}, #{jobId,jdbcType=INTEGER}, #{publisher,jdbcType=VARCHAR}, 
      #{interviewee,jdbcType=VARCHAR}, #{entContacts,jdbcType=VARCHAR}, #{entContactInfo,jdbcType=VARCHAR}, 
      #{type,jdbcType=CHAR}, 
     <if test="addrProvince != null" >
        #{addrProvince,jdbcType=VARCHAR},
      </if>
      <if test="addrCity != null" >
        #{addrCity,jdbcType=VARCHAR},
      </if>
      <if test="addrArea != null" >
        #{addrArea,jdbcType=VARCHAR},
      </if>
      <if test="addDetail != null" >
        #{addDetail,jdbcType=VARCHAR},
      </if>
      <if test="intvTime != null" >
        #{intvTime,jdbcType=TIMESTAMP},
      </if>
      #{status,jdbcType=CHAR}, #{createBy,jdbcType=VARCHAR}, 
      #{createDate,jdbcType=TIMESTAMP}, #{updateBy,jdbcType=VARCHAR}, #{updateDate,jdbcType=TIMESTAMP}, 
      #{remarks,jdbcType=VARCHAR})
  </insert>
  
  <insert id="insertSelective" parameterType="com.wechat.model.dbEntity.MdeInterview" >
    insert into mde_interview
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="intvId != null" >
        INTV_ID,
      </if>
      <if test="jobId != null" >
        JOB_ID,
      </if>
      <if test="publisher != null" >
        PUBLISHER,
      </if>
      <if test="interviewee != null" >
        INTERVIEWEE,
      </if>
      <if test="entContacts != null" >
        ENT_CONTACTS,
      </if>
      <if test="entContactInfo != null" >
        ENT_CONTACT_INFO,
      </if>
      <if test="type != null" >
        TYPE,
      </if>
      <if test="addrProvince != null" >
        ADDR_PROVINCE,
      </if>
      <if test="addrCity != null" >
        ADDR_CITY,
      </if>
      <if test="addrArea != null" >
        ADDR_AREA,
      </if>
      <if test="addDetail != null" >
        ADD_DETAIL,
      </if>
      <if test="intvTime != null" >
        INTV_TIME,
      </if>
      <if test="status != null" >
        STATUS,
      </if>
      <if test="versionNo != null" >
        VERSION_NO,
      </if>
      <if test="createBy != null" >
        CREATE_BY,
      </if>
      <if test="createDate != null" >
        CREATE_DATE,
      </if>
      <if test="updateBy != null" >
        UPDATE_BY,
      </if>
      <if test="updateDate != null" >
        UPDATE_DATE,
      </if>
      <if test="remarks != null" >
        REMARKS,
      </if>
      <if test="delFlag != null" >
        DEL_FLAG,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="intvId != null" >
        #{intvId,jdbcType=INTEGER},
      </if>
      <if test="jobId != null" >
        #{jobId,jdbcType=INTEGER},
      </if>
      <if test="publisher != null" >
        #{publisher,jdbcType=VARCHAR},
      </if>
      <if test="interviewee != null" >
        #{interviewee,jdbcType=VARCHAR},
      </if>
      <if test="entContacts != null" >
        #{entContacts,jdbcType=VARCHAR},
      </if>
      <if test="entContactInfo != null" >
        #{entContactInfo,jdbcType=VARCHAR},
      </if>
      <if test="type != null" >
        #{type,jdbcType=CHAR},
      </if>
      <if test="addrProvince != null" >
        #{addrProvince,jdbcType=VARCHAR},
      </if>
      <if test="addrCity != null" >
        #{addrCity,jdbcType=VARCHAR},
      </if>
      <if test="addrArea != null" >
        #{addrArea,jdbcType=VARCHAR},
      </if>
      <if test="addDetail != null" >
        #{addDetail,jdbcType=VARCHAR},
      </if>
      <if test="intvTime != null" >
        #{intvTime,jdbcType=TIMESTAMP},
      </if>
      <if test="status != null" >
        #{status,jdbcType=CHAR},
      </if>
      <if test="versionNo != null" >
        #{versionNo,jdbcType=INTEGER},
      </if>
      <if test="createBy != null" >
        #{createBy,jdbcType=VARCHAR},
      </if>
      <if test="createDate != null" >
        #{createDate,jdbcType=TIMESTAMP},
      </if>
      <if test="updateBy != null" >
        #{updateBy,jdbcType=VARCHAR},
      </if>
      <if test="updateDate != null" >
        #{updateDate,jdbcType=TIMESTAMP},
      </if>
      <if test="remarks != null" >
        #{remarks,jdbcType=VARCHAR},
      </if>
      <if test="delFlag != null" >
        #{delFlag,jdbcType=CHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.wechat.model.dbEntity.MdeInterview" >
    update mde_interview
    <set >
      <if test="jobId != null" >
        JOB_ID = #{jobId,jdbcType=INTEGER},
      </if>
      <if test="publisher != null" >
        PUBLISHER = #{publisher,jdbcType=VARCHAR},
      </if>
      <if test="interviewee != null" >
        INTERVIEWEE = #{interviewee,jdbcType=VARCHAR},
      </if>
      <if test="entContacts != null" >
        ENT_CONTACTS = #{entContacts,jdbcType=VARCHAR},
      </if>
      <if test="entContactInfo != null" >
        ENT_CONTACT_INFO = #{entContactInfo,jdbcType=VARCHAR},
      </if>
      <if test="type != null" >
        TYPE = #{type,jdbcType=CHAR},
      </if>
      <if test="addrProvince != null" >
        ADDR_PROVINCE = #{addrProvince,jdbcType=VARCHAR},
      </if>
      <if test="addrCity != null" >
        ADDR_CITY = #{addrCity,jdbcType=VARCHAR},
      </if>
      <if test="addrArea != null" >
        ADDR_AREA = #{addrArea,jdbcType=VARCHAR},
      </if>
      <if test="addDetail != null" >
        ADD_DETAIL = #{addDetail,jdbcType=VARCHAR},
      </if>
      <if test="intvTime != null" >
        INTV_TIME = #{intvTime,jdbcType=TIMESTAMP},
      </if>
      <if test="status != null" >
        STATUS = #{status,jdbcType=CHAR},
      </if>
      <if test="versionNo != null" >
        VERSION_NO = #{versionNo,jdbcType=INTEGER},
      </if>
      <if test="createBy != null" >
        CREATE_BY = #{createBy,jdbcType=VARCHAR},
      </if>
      <if test="createDate != null" >
        CREATE_DATE = #{createDate,jdbcType=TIMESTAMP},
      </if>
      <if test="updateBy != null" >
        UPDATE_BY = #{updateBy,jdbcType=VARCHAR},
      </if>
      <if test="updateDate != null" >
        UPDATE_DATE = #{updateDate,jdbcType=TIMESTAMP},
      </if>
      <if test="remarks != null" >
        REMARKS = #{remarks,jdbcType=VARCHAR},
      </if>
      <if test="delFlag != null" >
        DEL_FLAG = #{delFlag,jdbcType=CHAR},
      </if>
    </set>
    where INTV_ID = #{intvId,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.wechat.model.dbEntity.MdeInterview" >
    update mde_interview
    set JOB_ID = #{jobId,jdbcType=INTEGER},
      PUBLISHER = #{publisher,jdbcType=VARCHAR},
      INTERVIEWEE = #{interviewee,jdbcType=VARCHAR},
      ENT_CONTACTS = #{entContacts,jdbcType=VARCHAR},
      ENT_CONTACT_INFO = #{entContactInfo,jdbcType=VARCHAR},
      TYPE = #{type,jdbcType=CHAR},
      ADDR_PROVINCE = #{addrProvince,jdbcType=VARCHAR},
      ADDR_CITY = #{addrCity,jdbcType=VARCHAR},
      ADDR_AREA = #{addrArea,jdbcType=VARCHAR},
      ADD_DETAIL = #{addDetail,jdbcType=VARCHAR},
      INTV_TIME = #{intvTime,jdbcType=TIMESTAMP},
      STATUS = #{status,jdbcType=CHAR},
      VERSION_NO = #{versionNo,jdbcType=INTEGER},
      CREATE_BY = #{createBy,jdbcType=VARCHAR},
      CREATE_DATE = #{createDate,jdbcType=TIMESTAMP},
      UPDATE_BY = #{updateBy,jdbcType=VARCHAR},
      UPDATE_DATE = #{updateDate,jdbcType=TIMESTAMP},
      REMARKS = #{remarks,jdbcType=VARCHAR},
      DEL_FLAG = #{delFlag,jdbcType=CHAR}
    where INTV_ID = #{intvId,jdbcType=INTEGER}
  </update>
</mapper>