<?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="MdeInformationMapper">
    <resultMap type="com.wechat.model.dbEntity.MdeInformation" id="MdeInformation">
    	<id column="info_id" property="infoId"/>
		<result column="info_title" property="infoTitle"/>
		<result column="info_picurl" property="infoPicurl"/>
		<result column="keyword" property="keyword"/>
		<result column="info_desc" property="infoDesc"/>
		<result column="info_url" property="infoUrl"/>
		<result column="info_content" property="infoContent"/>
		<result column="status" property="status"/>
		<result column="info_price" property="infoPrice"/>
		<result column="vip_show" property="vipShow"/>
		<result column="who_like" property="whoLike"/>
		<result column="like_count" property="likeCount"/>
		<result column="who_comment" property="whoComment"/>
		<result column="comment_count" property="commentCount"/>
		<result column="info_type" property="infoType"/>
		<result column="version_no" property="versionNo"/>
		<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"/>
		<result column="VIP_SHOW_TITLE" property="vipShowTitle"/>
		
		<result column="START_TIME" property="startTime"/>
		<result column="END_TIME" property="endTime"/>
		<result column="REC_PROVINCE" property="recProvince"/>
		<result column="REC_CITY" property="recCity"/>
		<result column="REC_EXPERIENCE_F" property="recExperienceF"/>
		<result column="REC_EXPERIENCE_T" property="recExperienceT"/>
		<result column="REC_EDUCATION" property="recEducation"/>
		<result column="REC_DEPD_ID" property="recDepdId"/>
		<result column="REC_VIP_FLAG" property="recVipFlag"/>
		<result column="REC_WORK_STATUS" property="recWorkStatus"/>

		<result column="user_code" property="userCode"/>
		<result column="is_href" property="isHref"/>
		<result column="in_flag" property="inFlag"/>
		<result column="head_portrait" property="userHeadPortrait"/>
		<result column="name" property="name"/>
		<result column="foreign_name" property="foreign_name"/>
    </resultMap>
	<sql id="mdeInformationColumns">
		a.info_id AS "infoId",
		a.info_title AS "infoTitle",
		a.info_picurl AS "infoPicurl",
		a.keyword AS "keyword",
		a.info_desc AS "infoDesc",
		a.info_url AS "infoUrl",
		a.info_content AS "infoContent",
		a.status AS "status",
		a.info_price AS "infoPrice",
		a.vip_show AS "vipShow",
		a.who_like AS "whoLike",
		a.like_count AS "likeCount",
		a.who_comment AS "whoComment",
		a.comment_count AS "commentCount",
		a.info_type AS "infoType",
		a.version_no AS "versionNo",
		a.remarks AS "remarks",
		a.del_flag AS "delFlag",
		a.update_by AS "updateBy",
		a.update_date AS "updateDate",
		a.VIP_SHOW_TITLE AS "vipShowTitle",
		
		a.START_TIME AS "startTime",
		a.END_TIME AS "endTime",
		a.REC_PROVINCE AS "recProvince",
		a.REC_CITY AS "recCity",
		a.REC_EXPERIENCE_F AS "recExperienceF",
		a.REC_EXPERIENCE_T AS "recExperienceT",
		a.REC_EDUCATION AS "recEducation",
		a.REC_DEPD_ID AS "recDepdId",
		a.REC_VIP_FLAG AS "recVipFlag",
		a.REC_WORK_STATUS AS "recWorkStatus",
		
		a.user_code AS "userCode",
		a.is_href AS "isHref",
		a.in_flag AS "inFlag",
		a.head_portrait AS "userHeadPortrait",
		a.name AS "name",
		a.foreign_name AS "foreignName"
	</sql>
	
	<sql id="mdeInformationJoins">
	
	</sql>
    
	<select id="get" resultMap="MdeInformation">
		SELECT 
			<include refid="mdeInformationColumns"/>
		FROM mde_information a
		<include refid="mdeInformationJoins"/>
		WHERE a.info_id = #{id}
	</select>
	
	<select id="findList" resultMap="MdeInformation">
		SELECT 
			<include refid="mdeInformationColumns"/>
		FROM mde_information a
		<include refid="mdeInformationJoins"/>
		<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="findAllList" resultMap="MdeInformation">
		SELECT 
			<include refid="mdeInformationColumns"/>
		FROM mde_information a
		<include refid="mdeInformationJoins"/>
		<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>
	
	<insert id="insert">
		INSERT INTO mde_information(
			info_title,
			info_picurl,
			keyword,
			info_desc,
			info_url,
			info_content,
			status,
			info_price,
			vip_show,
			who_like,
			like_count,
			who_comment,
			comment_count,
			info_type,
			START_TIME,
			END_TIME,
			REC_PROVINCE,
			REC_CITY,
			REC_EXPERIENCE_F,
			REC_EXPERIENCE_T,
			REC_EDUCATION,
			REC_DEPD_ID,
			REC_VIP_FLAG,
			REC_WORK_STATUS,
			version_no,
			remarks,
			del_flag,
			create_by,
			create_date,
			update_by,
			update_date,
			VIP_SHOW_TITLE
		) VALUES (
			#{infoTitle},
			#{infoPicurl},
			#{keyword},
			#{infoDesc},
			#{infoUrl},
			#{infoContent},
			#{status},
			#{infoPrice},
			#{vipShow},
			#{whoLike},
			#{likeCount},
			#{whoComment},
			#{commentCount},
			#{infoType},
			#{startTime},
			#{endTime},
			#{recProvince},
			#{recCity},
			#{recExperienceF},
			#{recExperienceT},
			#{recEducation},
			#{recDepdId},
			#{recVipFlag},
			#{recWorkStatus},
			#{versionNo},
			#{remarks},
			#{delFlag},
			#{createBy},
			#{createDate},
			#{updateBy},
			#{updateDate},
			#{vipShowTitle}
		)
	</insert>
	
	<update id="update">
		UPDATE mde_information SET 	
			info_title = #{infoTitle},
			info_picurl = #{infoPicurl},
			keyword = #{keyword},
			info_desc = #{infoDesc},
			info_url = #{infoUrl},
			info_content = #{infoContent},
			status = #{status},
			info_price = #{infoPrice},
			vip_show = #{vipShow},
			who_like = #{whoLike},
			like_count = #{likeCount},
			who_comment = #{whoComment},
			comment_count = #{commentCount},
			
			<if test="infoType != null">info_type = #{infoType},</if>
			<if test="startTime != null">START_TIME = #{startTime},</if>
			<if test="endTime != null">END_TIME = #{endTime},</if>
			REC_PROVINCE = #{recProvince},
			REC_CITY = #{recCity},
			REC_EXPERIENCE_F = #{recExperienceF},
			REC_EXPERIENCE_T = #{recExperienceT},
			REC_EDUCATION = #{recEducation},
			REC_DEPD_ID = #{recDepdId},
			REC_VIP_FLAG = #{recVipFlag},
			REC_WORK_STATUS = #{recWorkStatus},
		
			version_no = version_no +1,
			remarks = #{remarks},
			update_by = #{updateBy},
			update_date = #{updateDate},
			vip_show_title = #{vipShowTitle}
		WHERE info_id = #{id} and version_no = #{versionNo}
	</update>
	
	<update id="delete">
		UPDATE mde_information SET 
			version_no = version_no +1,
			del_flag = #{DEL_FLAG_DELETE}
		WHERE info_id = #{id} and version_no = #{versionNo}
	</update>
	
	<!-- 根据type获取资讯 -->
	<select id="hotInformations" resultMap="MdeInformation">
		SELECT 
			<include refid="mdeInformationColumns"/>
		FROM mde_information a
		<include refid="mdeInformationJoins"/>
		<where>
			a.del_flag = 0 and a.info_type=#{type} and a.status=2
		</where>
		order by a.create_date desc
		limit #{index}, 1
	</select>
	
	<!-- 根据type获取所有资讯 -->
	<select id="allHotInformations" resultMap="MdeInformation">
		SELECT 
			<include refid="mdeInformationColumns"/>
		FROM mde_information a
		<where>
			a.del_flag = 0 and a.info_type=#{type} and a.status=2
		</where>
		order by a.update_date desc
		limit 15
	</select>
	
	
	<!-- 根据type获取资讯 -->
	<select id="getInformationsById" resultMap="MdeInformation">
		SELECT 
			<include refid="mdeInformationColumns"/>
		FROM mde_information a
		<include refid="mdeInformationJoins"/>
		<where>
			a.del_flag = 0 and a.info_id = #{infoId} and a.status=2
		</where>
	</select>
	<!-- 获取资讯 -->
	<select id="hotInformationsByTypeAndUserCode" resultMap="MdeInformation">
		SELECT 
			<include refid="mdeInformationColumns"/>
		FROM mde_information a
		<include refid="mdeInformationJoins"/>
		left join mde_user c on c.user_code=#{userCode}
		<where>
			a.del_flag = 0 and a.info_type=#{type} and a.status=2
		</where>
		order by a.create_date desc
		limit #{index}, 1
	</select>
	
</mapper>