<?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="MdeJobInvitationRelMapper">
	<resultMap type="com.wechat.model.dbEntity.MdeJobInvitationRel" id="MdeJobInvitationRelMap">
		<id column="JOB_ID" property="jobId" />
		<result column="USER_CODE" property="userCode" />
		<result column="PUBLISHER" property="publisher" />
		<result column="JOB_NAME" property="jobName" />
		<result column="INVITATION" property="invitation" />
		<result column="STATUS" property="status" />
		<result column="remarks" property="remarks" />
		<result column="del_flag" property="delFlag" />
		<result column="create_by" property="createBy" />
		<result column="create_date" property="createDate" />
		<result column="update_by" property="updateBy" />
		<result column="update_date" property="updateDate" />
	</resultMap>
	<sql id="mdeJobInvitationRelColumns"> 
		a.JOB_ID ,
		a.USER_CODE,
		a.PUBLISHER,
		a.JOB_NAME ,
		a.INVITATION,
		a.STATUS,
		a.version_no,
		a.remarks ,
		a.del_flag,
		a.update_by,
		a.update_date,
		a.create_by,
		a.create_date
	</sql>


	<select id="findList" resultMap="MdeJobInvitationRelMap">
		SELECT
		<include refid="mdeJobInvitationRelColumns" />
		FROM MDE_JOB_INVITATION_REL a
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
		</where>
		<choose>
			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY #{page.orderBy}
			</when>
			<otherwise>
				ORDER BY a.update_date DESC
			</otherwise>
		</choose>
	</select>
	<!-- 获取企业发布职位信息 -->
	<select id="getByPublisher" resultMap="MdeJobInvitationRelMap">
		select
		<include refid="mdeJobInvitationRelColumns"></include>
		from MDE_JOB_INVITATION_REL a
		where
		a.del_flag=0
		AND a.PUBLISHER= #{publisher}
	</select>
	<!-- 获取用户收到的企业邀请信息 -->
	<select id="getRecievedHotelInvationInfo"
		resultType="com.wechat.model.responseDto.HotelInvitationInfoResp">
		SELECT
			r.publisher AS publisher,
			r.USER_CODE AS userCode,
			r. STATUS,
			r.create_date AS invitedDate,
			r.job_id AS jobId,
			r.job_name AS jobName,
			r.INVITATION AS invitation,
			u.HEAD_PORTRAIT AS headPortrait,
			u. NAME AS hotelName,
			u.foreign_name as foreignName
		FROM
		mde_job_invitation_rel r
		left join mde_user u on u.USER_CODE = r.PUBLISHER and u.DEL_FLAG = 0
		WHERE
			r.USER_CODE =#{userCode}
			AND r.DEL_FLAG = 0
		ORDER BY r.create_date DESC
	</select>

	<!-- 获取用户收到的企业邀请数量 -->
	<select id="getRecievedHotelInvationInfoCount" resultType="java.lang.Integer">
		SELECT
			count(1)
		FROM
		mde_job_invitation_rel r
		left join mde_user u on u.USER_CODE = r.PUBLISHER and u.DEL_FLAG = 0
		WHERE
			r.USER_CODE =#{userCode}
			AND r.DEL_FLAG = 0
	</select>
	<!-- 更新职位状态 -->
	<update id="updateStatus">
		UPDATE mde_job_invitation_rel
		SET STATUS =#{status},
			VERSION_NO = VERSION_NO+1
		WHERE
		job_id =#{jobId}
		AND user_code =#{userCode}
	</update>
	<insert id="insert">
		INSERT INTO MDE_JOB_INVITATION_REL(
		JOB_ID,
		USER_CODE,
		PUBLISHER,
		JOB_NAME,
		INVITATION,
		STATUS,
		create_date,
		update_date
		) VALUES (
		#{jobId},
		#{userCode},
		#{publisher},
		#{jobName},
		#{invitation},
		#{status},
		#{createDate},
		#{updateDate}
		)
	</insert>
	
	<!-- 查看该用户有职位是否被邀请 -->
	<select id="passiveInvitation" resultMap="MdeJobInvitationRelMap">
		SELECT
			<include refid="mdeJobInvitationRelColumns"></include>
		FROM
			mde_job_invitation_rel a
		WHERE
			a.job_id = #{jobId}
		AND a.user_code = #{userCode}
		limit 1
	</select>
	
</mapper>