<?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="MdePositionMapper">
	<resultMap type="com.wechat.model.dbEntity.MdePosition"
		id="MdePosition">
		<id column="position_id" property="positionId" />
		<result column="depd_id" property="depdId" />
		<result column="position_name_cn" property="positionNameCn" />
		<result column="position_name_en" property="positionNameEn" />
		<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="mdePositionColumns">
		a.position_id AS "positionId",
		a.depd_id AS "depdId",
		a.position_name_cn AS "positionNameCn",
		a.position_name_en AS "positionNameEn",
		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="mdePositionJoins">
	</sql>

	<select id="get" resultMap="MdePosition">
		SELECT
		<include refid="mdePositionColumns" />
		FROM mde_position a
		<include refid="mdePositionJoins" />
		WHERE a.id = #{id}
	</select>

	<select id="getAllPositions" resultMap="MdePosition">
		SELECT
		<include refid="mdePositionColumns" />
		FROM mde_position a
		<where>
			a.del_flag = 0
		</where>
		order by if(a.depd_id='0','990',a.depd_id) asc , a.POSITION_GRADE desc, a.position_id asc
	</select>
	<select id="findList" resultMap="MdePosition">
		SELECT
		<include refid="mdePositionColumns" />
		FROM mde_position a
		<include refid="mdePositionJoins" />
		<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="MdePosition">
		SELECT
		<include refid="mdePositionColumns" />
		FROM mde_position a
		<include refid="mdePositionJoins" />
		<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_position(
		depd_id,
		position_name_cn,
		position_name_en,
		position_grade,
		version_no,
		create_by,
		create_date,
		update_by,
		update_date,
		remarks,
		del_flag
		) VALUES (
		#{depdId},
		#{positionNameCn},
		#{positionNameEn},
		#{positionGrade},
		#{versionNo},
		#{createBy},
		#{createDate},
		#{updateBy},
		#{updateDate},
		#{remarks},
		#{delFlag}
		)
	</insert>

	<update id="update">
		UPDATE mde_position SET
		depd_id = #{depdId},
		position_name_cn = #{positionNameCn},
		position_name_en = #{positionNameEn},
		position_grade = #{positionGrade},
		update_by = #{updateBy},
		update_date = #{updateDate},
		remarks = #{remarks},
		version_no = version_no +1,
		WHERE position_id = #{positionId} and version_no =
		#{versionNo}
	</update>

	<update id="delete">
		UPDATE mde_position SET
		version_no = version_no +1,
		del_flag = #{delFlag}
		WHERE position_id = #{positionId} and version_no =
		#{versionNo}
	</update>

	<select id="getPvByJobId" resultType="java.lang.Integer">
		SELECT
			PAGE_VIEW as pageView
		FROM MDE_VIEW_JOB_PUV_ALL
		<where>
			JOB_ID = #{jobId}
		</where>
	</select>
	
	
	
</mapper>