<?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="MdeJobFairMapper" >
  <resultMap id="BaseResultMap" type="com.wechat.model.dbEntity.MdeJobFair" >
    <id column="FAIR_ID" property="fairId" jdbcType="INTEGER" />
    <result column="FAIR_TITLE" property="fairTitle" jdbcType="VARCHAR" />
    <result column="FAIR_SLOGAN" property="fairSlogan" jdbcType="VARCHAR" />
    <result column="FAIR_TYPE" property="fairType" jdbcType="CHAR" />
    <result column="START_DATE" property="startDate" jdbcType="DATE" />
    <result column="STOP_DATE" property="stopDate" jdbcType="DATE" />
    <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" >
    FAIR_ID, FAIR_TITLE, FAIR_SLOGAN, FAIR_TYPE, START_DATE, STOP_DATE, VERSION_NO, CREATE_BY, 
    CREATE_DATE, UPDATE_BY, UPDATE_DATE, REMARKS, DEL_FLAG
  </sql>

	<resultMap type="com.wechat.model.responseDto.JobFairByHotelResp" id="JobFairByHotelResp">
		<result column="fairId" property="fairId"/>		
		<result column="fairSlogan" property="fairSlogan"/>	
		<result column="fairType" property="fairType"/>
		<result column="headImg" property="headImg"/>
		<result column="backgroundImg" property="backgroundImg"/>
		<result column="bottomImg" property="bottomImg"/>
		<result column="pcHeadImg" property="pcHeadImg"/>
		<result column="pcBackgroundImg" property="pcBackgroundImg"/>
		<result column="shareImg" property="shareImg"/>
		<result column="pcBottomImg" property="pcBottomImg"/>
		<result column="insideColour" property="insideColour"/>
		<result column="jobColour" property="jobColour"/>
		<result column="backgroundColour" property="backgroundColour"/>
		<result column="remarks" property="remarks"/>
		<collection  property="hotelList" ofType="com.wechat.model.dto.JobFairHotelsDto">
			<id column="userCode" property="userCode"/>
			<result column="nameCn" property="nameCn"/>	
			<result column="nameEn" property="nameEn"/>
			<result column="cityName" property="cityName"/> 
			<result column="headPortrait" property="headPortrait"/>	
			<result column="provinceName" property="provinceName"/>
			<result column="createDate" property="createDate"/> 
			<result column="cityCode" property="cityCode"/>
			<result column="prepareFlag" property="prepareFlag"/> 
			<collection  property="jobList" ofType="com.wechat.model.dto.JobFairJobsDto">
				<id column="jobId" property="jobId"/>
				<result column="jobName" property="jobName"/>
				<result column="positionId" property="positionId"/>		
				<result column="jobCreateDate" property="createDate"/>
			</collection>
			<collection  property="positionIds" ofType="java.lang.Integer">
				<id column="positionId" property="positionId"/>
			</collection>
		</collection>
	</resultMap>
	
	<resultMap type="com.wechat.model.responseDto.DPResp" id="JobFairDepartmentsResp">
		<result column="depdName" property="label"/>		
		<result column="depdId" property="value"/>	
		<collection  column="depdId" property="children" ofType="com.wechat.model.responseDto.DPResp">
			<result column="positionName" property="label"/>		
			<result column="positionId" property="value"/>	
		</collection>
	</resultMap>
		
	<resultMap type="com.wechat.model.dto.City" id="JobFairCitysResp">
		<result column="provinceName" property="name"/>		
		<result column="provinceValue" property="value"/>	
		<collection column="provinceValue" property="children" ofType="com.wechat.model.dto.AreaDto">
			<result column="cityName" property="name"/>		
			<result column="cityValue" property="value"/>	
		</collection>
	</resultMap>
  
	<select id="getFairByHotel" resultMap="JobFairByHotelResp">
		SELECT
			a.FAIR_ID as fairId,
			a.FAIR_SLOGAN as fairSlogan,
			a.FAIR_TYPE as fairType,
			a.REMARKS as remarks,
			a.head_img AS headImg,
			a.background_img AS backgroundImg,
			a.SHARE_IMG AS shareImg,
			a.BOTTOM_IMG as bottomImg,
			a.pc_head_img AS pcHeadImg,
			a.pc_background_img AS pcBackgroundImg,
			a.pc_BOTTOM_IMG as pcBottomImg,
			a.INSIDE_COLOUR AS insideColour,
			a.JOB_COLOUR AS jobColour,
			a.background_colour AS backgroundColour,
			c.USER_CODE as userCode,
			c.`NAME` as nameCn,
			c.FOREIGN_NAME as nameEn,
			c.HEAD_PORTRAIT as headPortrait,
			c.CREATE_DATE as createDate,
			d.NAME AS provinceName,
			e.NAME AS cityName,
			job.JOB_ID as jobId,
			job.POSITION_ID as positionId,
			job.CREATE_DATE as jobCreateDate,
			job.JOB_NAME as jobName,
			c.addr_city as cityCode,
			c.PREPARE_FLAG as prepareFlag
		FROM
			MDE_JOB_FAIR a
			INNER JOIN MDE_FAIR_DTL b ON a.FAIR_ID = b.FAIR_ID
			LEFT JOIN mde_user c ON b.DTL_ID = c.USER_CODE
			LEFT JOIN sys_area d ON d.CODE = c.addr_province
			LEFT JOIN sys_area e ON e.CODE = c.addr_city
			INNER JOIN mde_job_advertised job ON job.PUBLISHER = b.DTL_ID 
		WHERE
			a.FAIR_ID = #{fairId}
			AND job.JOB_STATUS = '0' 
			AND a.DEL_FLAG = '0' 
			AND b.DEL_FLAG = '0' 
			AND c.DEL_FLAG = '0' 
			AND job.DEL_FLAG = '0' 
			<![CDATA[ AND a.START_DATE <= date_format( NOW(), '%Y-%m-%d' ) AND a.STOP_DATE >= date_format( NOW(), '%Y-%m-%d' ) ]]>
		ORDER BY 
			job.UPDATE_DATE desc, c.VIP_FLAG desc, b.SORT asc, job.RECOMMEND_FLAG desc
	</select>
  
  	<select id="getJobFairCitys" resultMap="JobFairCitysResp">
		SELECT
			IFNULL(d.NAME,'其他')  AS provinceName,
			c.ADDR_PROVINCE as provinceValue,
			e.NAME  AS cityName,
			c.addr_city as cityValue
		FROM
			MDE_JOB_FAIR a
			INNER JOIN MDE_FAIR_DTL b ON a.FAIR_ID = b.FAIR_ID
			LEFT JOIN mde_user c ON b.DTL_ID = c.USER_CODE
			LEFT JOIN sys_area d ON d.CODE = c.ADDR_PROVINCE
			LEFT JOIN sys_area e ON e.CODE = c.addr_city
		WHERE
			a.FAIR_ID = #{fairId}
			AND a.DEL_FLAG = '0' 
			AND b.DEL_FLAG = '0' 
			AND c.DEL_FLAG = '0'  
			<![CDATA[ AND a.START_DATE <= date_format( NOW(), '%Y-%m-%d' ) AND a.STOP_DATE >= date_format( NOW(), '%Y-%m-%d' ) ]]>
		GROUP BY
			c.addr_city
		ORDER BY 
			IFNULL(c.addr_city,'999999') 
	</select>
	
	<select id="getJobFairDepartments" resultMap="JobFairDepartmentsResp">
		SELECT
			dep.DEPD_NAME_CN as depdName,
			psn.DEPD_ID as depdId,
			psn.POSITION_NAME_CN as positionName,
			job.POSITION_ID as positionId
		FROM
			MDE_FAIR_DTL b 
			INNER JOIN mde_job_advertised job ON job.PUBLISHER = b.DTL_ID 
			INNER JOIN mde_position psn on job.POSITION_ID = psn.POSITION_ID
			INNER JOIN mde_department dep on dep.DEPD_ID = psn.DEPD_ID
		WHERE
			b.FAIR_ID = #{fairId}
			AND job.JOB_STATUS = '0'  
			AND b.DEL_FLAG = '0'  
			AND job.DEL_FLAG = '0' 
		GROUP BY
			psn.DEPD_ID,job.POSITION_ID
		ORDER BY 
			psn.DEPD_ID,job.POSITION_ID
	</select>
	
</mapper>