<?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="MdeEducationExperienceMapper">
    <resultMap id="MdeEducationExperience" type="com.wechat.model.dbEntity.MdeEducationExperience">
    	<id column="edu_id" property="eduId"/>
		<result column="user_code" property="userCode"/>
		<result column="education" property="education"/>
		<result column="sch_name" property="schName"/>
		<result column="sch_country" property="schCountry"/>
		<result column="sch_province" property="schProvince"/>
		<result column="sch_city" property="schCity"/>
		<result column="speciality" property="speciality"/>
		<result column="enter_date" property="enterDate"/>
		<result column="quit_date" property="quitDate"/>
		<result column="sch_describe" property="schDescribe"/>
		<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"/>
    </resultMap>
	<sql id="mdeEducationExperienceColumns">
		a.edu_id AS "eduId",
		a.user_code AS "userCode",
		a.education AS "education",
		a.sch_name AS "schName",
		a.sch_country AS "schCountry",
		a.sch_province AS "schProvince",
		a.sch_city AS "schCity",
		a.speciality AS "speciality",
		a.enter_date AS "enterDate",
		a.quit_date AS "quitDate",
		a.sch_describe AS "schDescribe",
		a.version_no AS "versionNo",
		a.remarks AS "remarks",
		a.del_flag AS "delFlag",
		a.create_by AS "createBy",
		a.create_date AS "createDate",
		a.update_by AS "updateBy",
		a.update_date AS "updateDate"
	</sql>
	
	<sql id="mdeEducationExperienceJoins">
	,s.label as educationName
	</sql>
    
	<select id="get" resultMap="MdeEducationExperience">
		SELECT 
			<include refid="mdeEducationExperienceColumns"/>
		FROM mde_education_experience a
		<include refid="mdeEducationExperienceJoins"/>
		WHERE a.edu_id = #{eduId}
	</select>
    <!-- 获取教育经历列表 -->
	<select id="getEducationExperienceByUserCode" resultMap="MdeEducationExperience">
		SELECT
			<include refid="mdeEducationExperienceColumns"/>
			<choose>
				<when test="lang == 'en'.toString()">
					,s.en as educationName
				</when>
				<otherwise>
					,s.label as educationName
				</otherwise>
			</choose>
		FROM
			mde_education_experience a,
			sys_dict s
		WHERE
			a.EDUCATION = s.`value`
		AND s.type = 'education'
		AND a.user_code = #{userCode}
		AND a.del_flag = 0
		ORDER BY
			a.education , 
			a.enter_date DESC
	</select>
	
	<select id="findList" resultMap="MdeEducationExperience">
		SELECT 
			<include refid="mdeEducationExperienceColumns"/>
		FROM mde_education_experience a
		<include refid="mdeEducationExperienceJoins"/>
		<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="MdeEducationExperience">
		SELECT 
			<include refid="mdeEducationExperienceColumns"/>
		FROM mde_education_experience a
		<include refid="mdeEducationExperienceJoins"/>
		<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_education_experience(
			user_code,
			education,
			sch_name,
			sch_country,
			sch_province,
			sch_city,
			speciality,
			enter_date,
			quit_date,
			sch_describe,
			version_no,
			remarks,
			del_flag,
			create_by,
			create_date,
			update_by,
			update_date
		) VALUES (
			#{userCode},
			#{education},
			#{schName},
			#{schCountry},
			#{schProvince},
			#{schCity},
			#{speciality},
			#{enterDate},
			#{quitDate},
			#{schDescribe},
			#{versionNo},
			#{remarks},
			#{delFlag},
			#{createBy},
			#{createDate},
			#{updateBy},
			#{updateDate}
		)
	</insert>
	
	<update id="update">
		UPDATE mde_education_experience SET 	
			<if test="userCode !=null"> user_code = #{userCode},          </if>
			<if test="education !=null"> education = #{education},         </if>
			<if test="schName !=null"> sch_name = #{schName},            </if>
			<if test="schCountry !=null"> sch_country = #{schCountry},      </if>
			<if test="schProvince !=null"> sch_province = #{schProvince},    </if>
			<if test="schCity !=null"> sch_city = #{schCity},            </if>
			<if test="speciality !=null"> speciality = #{speciality},       </if>
			<if test="enterDate !=null"> enter_date = #{enterDate},        </if>
			 quit_date = #{quitDate},
			<if test="schDescribe !=null"> sch_describe = #{schDescribe},    </if>
			<if test="remarks !=null"> remarks = #{remarks},             </if>
			<if test="updateBy !=null"> update_by = #{updateBy},          </if>
			<if test="updateDate !=null"> update_date = #{updateDate},      </if>
			version_no = version_no +1
		WHERE edu_id = #{eduId} 
		<if test="versionNo !=null">
			and version_no = #{versionNo}
		</if>
	</update>
	
	<update id="delete">
		UPDATE mde_education_experience SET 
			version_no = version_no +1,
			<if test="updateBy !=null"> update_by = #{updateBy},          </if>
			del_flag = #{delFlag}
		WHERE edu_id = #{eduId} <if test="versionNo !=null"> and version_no = #{versionNo} </if>
	</update>
	<!-- 批量查询教育经历 -->
	<select id="getEducationExperienceByUserCodeList"  resultMap="MdeEducationExperience">
		select 
		<include refid="mdeEducationExperienceColumns"/>
		<choose>
			<when test="lang == 'en'.toString()">
				,s.en as educationName
			</when>
			<otherwise>
				,s.label as educationName
			</otherwise>
		</choose>
		from mde_education_experience a,
		sys_dict s
		where 
			a.del_flag=0
			AND s.type = 'education'
			AND a.EDUCATION = s.`value`
			and a.user_code in 
			<foreach collection="userCodeList" item="userCode" separator="," open="(" close=")">
			#{userCode}
			</foreach>
			order by a.education ,a.enter_date desc
			limit 1
	</select>
	
</mapper>