<?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="MdeBoleInfoMapper">
    <resultMap type="com.wechat.model.dbEntity.MdeBoleInfo" id="MdeBoleInfo">
		<id column="bole_id" property="boleId"/>
		<result column="bole_type" property="boleType"/>
		<result column="name" property="name"/>
		<result column="image_url" property="imageUrl"/>
		<result column="company_name" property="companyName"/>
		<result column="position" property="position"/>
		<result column="comment" property="comment"/>
		
		<result column="sex" property="sex"/>
		<result column="sort" property="sort"/>
		<result column="personal_profile" property="personalProfile"/>
		
		<result column="version_no" property="versionNo"/>
		<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="remarks" property="remarks"/>
		<result column="del_flag" property="delFlag"/>
		<result column="position_name" property="positionName"/>
	</resultMap>
	<sql id="mdeBoleInfoColumns">
		a.bole_id AS "boleId",
		a.bole_type AS "boleType",
		a.name AS "name",
		a.image_url AS "imageUrl",
		a.company_name AS "companyName",
		a.position AS "position",
		a.comment AS "comment",
		<!-- a.sex AS "sex", -->
		a.sort AS "sort",
		a.personal_profile AS "personalProfile",
		a.version_no AS "versionNo",
		a.create_by AS "createBy",
		a.create_date AS "createDate",
		a.update_by AS "updateBy",
		a.update_date AS "updateDate",
		a.remarks AS "remarks",
		a.del_flag AS "delFlag"
		
		
	</sql>
	
	<sql id="MdeBoleInfoJoins">
	 left join mde_position b on a.position = b.POSITION_ID and b.DEL_FLAG = 0
	</sql>
    
	<select id="get" resultMap="MdeBoleInfo">
		SELECT 
			<include refid="mdeBoleInfoColumns"/>
		FROM mde_bole_info a
		<include refid="MdeBoleInfoJoins"/>
		WHERE a.bole_id = #{boleId} and a.del_flag = 0
	</select>
	
	<!-- 获取荣誉顾问 -->
	<select id="getHonoraryAdvisor" resultMap="MdeBoleInfo">
		SELECT 
			<include refid="mdeBoleInfoColumns"/>
		FROM mde_bole_info a
		<include refid="MdeBoleInfoJoins"/>
		WHERE a.del_flag =0 and bole_type=1
	</select>
	
	<!-- 获取职业发展导师团 -->
	<select id="getCareerDevelopmentMentor" resultMap="MdeBoleInfo">
		SELECT 
			<include refid="mdeBoleInfoColumns"/>
		FROM mde_bole_info a
		<include refid="MdeBoleInfoJoins"/>
		WHERE a.del_flag = 0 and bole_type=2
	</select>
	
	<!-- 获取所有伯乐 -->
	<select id="getAllBole" resultMap="MdeBoleInfo">
		SELECT 
			<include refid="mdeBoleInfoColumns"/>
			,CASE #{lang} 
				when 'zh' then b.POSITION_NAME_CN
				when 'en' then b.POSITION_NAME_EN
				ELSE b.POSITION_NAME_CN
			END AS positionName
			
		FROM mde_bole_info a
		<include refid="MdeBoleInfoJoins"/>
		WHERE a.del_flag = 0
		order by bole_type asc,SORT asc
	</select>
	
	<insert id="insert">
		INSERT INTO mde_bole_info(
			bole_type,name,image_url,company_name,position,comment,version_no,create_by,create_date,update_by,update_date,remarks,del_flag,
			sex,sort ,personal_profile
		) VALUES (
			#{boleType},#{name},#{imageUrl}},#{companyName},#{position},#{comment},#{versionNo},
			#{createBy},#{createDate},#{updateBy},#{updateDate},#{remarks},#{delFlag},
			#{sex},#{sort},#{personalProfile}
		)
	</insert>
	
	<update id="update">
		UPDATE mde_bole_info SET 	
			<if test="boleType!=null"> bole_type = #{boleType},          </if>
			<if test="name!=null"> name = #{name},                   </if>
			<if test="imageUrl"> image_url = #{imageUrl},                   </if>
			<if test="companyName!=null"> company_name = #{companyName},    </if>
			<if test="position!=null"> position = #{position},           </if>
			<if test="comment!=null"> comment = #{comment},             </if>
			<if test="updateBy!=null"> update_by = #{updateBy},          </if>
			<if test="updateDate!=null"> update_date = #{updateDate},      </if>
			<if test="remarks!=null"> remarks = #{remarks},              </if>
			<if test="sex!=null"> sex = #{sex},              </if>
			<if test="sort!=null"> sort = #{sort},              </if>
			<if test="personalProfile!=null"> personal_profile = #{personalProfile},              </if>
			version_no = version_no +1
		WHERE a.bole_id = #{boleId} <if test="versionNo!=null"> and version_no = #{versionNo} </if>
	</update>
	
	<update id="delete">
		UPDATE mde_bole_info SET 
			version_no = version_no +1,
			del_flag = #{delFlag}
		WHERE a.bole_id = #{boleId} <if test="versionNo!=null"> and version_no = #{versionNo} </if>
	</update>
	
</mapper>