<?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="MdePositionAnotherNameMapper">
	<resultMap type="com.wechat.model.dbEntity.MdePositionAnotherName" id="MdePositionAnotherName">
		<id column="position_id" property="positionId"/>
		<result column="position_name" property="positionName"/>
		<result column="position_grade" property="positionGrade"/>
		<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"/>
	</resultMap>
	<sql id="mdePositionAnotherNameColumns">
		a.position_id AS "positionId",
		a.position_name AS "positionName",
		a.position_grade AS "positionGrade",
		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="mdePositionAnotherNameJoins">
	</sql>
    
	<select id="get" resultMap="MdePositionAnotherName">
		SELECT 
			<include refid="mdePositionAnotherNameColumns"/>
		FROM mde_position_another_name a
		<include refid="mdePositionAnotherNameJoins"/>
		WHERE a = #{id}
	</select>
	
	<select id="getAllPositionAnotherName" resultMap="MdePositionAnotherName">
		SELECT 
		a.position_id as "positionId",a.position_name as "positionName"
		FROM mde_position_another_name a
		where a.DEL_FLAG ="0"
	</select>
	
	<select id="getPositionRecord" resultMap="MdePositionAnotherName">
		SELECT 
		a.position_id AS "positionId",
		a.position_name AS "positionName",
		a.update_date AS "updateDate",
		a.del_flag AS "delFlag"
		FROM mde_position_another_name a
		where a.DEL_FLAG ="0" and a.POSITION_ID = #{jobCode} and a.POSITION_NAME=#{jobName}
	</select>
	
	<select id="findList" resultMap="MdePositionAnotherName">
		SELECT 
			<include refid="mdePositionAnotherNameColumns"/>
		FROM mde_position_another_name a
		<include refid="mdePositionAnotherNameJoins"/>
		<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.position_grade, a.update_date DESC
			</otherwise>
		</choose>
	</select>
	
	<select id="findAllList" resultMap="MdePositionAnotherName">
		SELECT 
			<include refid="mdePositionAnotherNameColumns"/>
		FROM mde_position_another_name a
		<include refid="mdePositionAnotherNameJoins"/>
		<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.position_grade,a.update_date DESC
			</otherwise>
		</choose>
	</select>
	
	<insert id="insert">
		INSERT INTO mde_position_another_name(
			position_id,
			position_name,
			position_grade,
			<!-- version_no, -->
			create_by,
			create_date,
			update_by,
			update_date,
			remarks
		<!-- 	del_flag -->
		) VALUES (
			#{positionId},
			#{positionName},
		(SELECT position_grade FROM mde_position WHERE POSITION_ID = #{positionId}),
			#{createBy},
			#{createDate},
			#{updateBy},
			#{updateDate},
			#{remarks}
		<!-- 	#{delFlag} -->
		)
	</insert>
	
	<update id="update">
		UPDATE mde_position_another_name SET 	
			position_id = #{positionId},
			position_name = #{positionName},
			version_no = #{versionNo},
			update_by = #{updateBy},
			update_date = #{updateDate},
			remarks = #{remarks}
		WHERE id = #{id}
	</update>
	
	<update id="delete">
		UPDATE mde_position_another_name SET 
			del_flag = #{delFlag}
		WHERE position_id = #{positionId}
	</update>
	<select id="getAllAliasNameOfPosition" resultMap="MdePositionAnotherName">
			SELECT position_id as positionId ,position_name as positionName FROM `mde_position_another_name` where del_flag=0 order by position_grade
	</select>
</mapper>