<?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="com.wechat.dao.MdeSubscribedPositionsMapper" >
  <resultMap id="BaseResultMap" type="com.wechat.model.dbEntity.MdeSubscribedPositions" >
    <id column="USER_CODE" property="userCode" jdbcType="BIGINT" />
    <id column="POSITION_ID" property="positionId" jdbcType="INTEGER" />
    <result column="DEPD_ID" property="depdId" jdbcType="INTEGER" />
    <result column="POSITION_GRADE" property="positionGrade" jdbcType="INTEGER" />
    <result column="VERSION_NO" property="versionNo" jdbcType="INTEGER" />
    <result column="REMARKS" property="remarks" jdbcType="VARCHAR" />
    <result column="DEL_FLAG" property="delFlag" jdbcType="INTEGER" />
    <result column="CREATE_BY" property="createBy" jdbcType="VARCHAR" />
    <result column="CREATE_DATE" property="createDate" jdbcType="TIMESTAMP" />
    <result column="UPDATE_BY" property="updateBy" jdbcType="VARCHAR" />
    <result column="UPDATE_DATE" property="updateDate" jdbcType="TIMESTAMP" />
  </resultMap>
  <sql id="Base_Column_List" >
    USER_CODE, POSITION_ID, DEPD_ID, POSITION_GRADE, VERSION_NO, REMARKS, DEL_FLAG, CREATE_BY, 
    CREATE_DATE, UPDATE_BY, UPDATE_DATE
  </sql>

  <delete id="deleteByUserCode" parameterType="String" >
    delete from mde_subscribed_positions
    where USER_CODE = #{userCode}
  </delete>
  
  <insert id="insert" parameterType="com.wechat.model.dbEntity.MdeSubscribedPositions" >
    insert into mde_subscribed_positions (USER_CODE, POSITION_ID, DEPD_ID, 
      POSITION_GRADE, 
      CREATE_BY, CREATE_DATE, 
      UPDATE_BY, UPDATE_DATE)
    values (#{userCode,jdbcType=BIGINT}, #{positionId,jdbcType=INTEGER}, #{depdId,jdbcType=INTEGER}, 
      #{positionGrade,jdbcType=INTEGER}, 
      #{createBy,jdbcType=VARCHAR}, #{createDate,jdbcType=TIMESTAMP}, 
      #{updateBy,jdbcType=VARCHAR}, #{updateDate,jdbcType=TIMESTAMP})
  </insert>
 
  <select id="getSubscribedPositions" resultType="com.wechat.model.dto.SubscribedPositionsDto" >
    SELECT
		a.POSITION_ID AS positionId,
		a.DEPD_ID AS depdId,
		<choose>
			<when test="lang != null and lang == 'en'.toString()">
				b.POSITION_NAME_EN as positionName
			</when>
			<otherwise>
				b.POSITION_NAME_CN as positionName
			</otherwise>
		</choose>
	FROM
		mde_subscribed_positions a 
	  inner join MDE_POSITION b 
	     on	a.POSITION_ID = b.POSITION_ID
	WHERE
		a.USER_CODE = #{userCode}
		AND a.DEL_FLAG = '0'
		AND b.DEL_FLAG = '0'
  </select>
  
  
  
  
  <insert id="insertSelective" parameterType="com.wechat.model.dbEntity.MdeSubscribedPositions" >
    insert into mde_subscribed_positions
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="userCode != null" >
        USER_CODE,
      </if>
      <if test="positionId != null" >
        POSITION_ID,
      </if>
      <if test="depdId != null" >
        DEPD_ID,
      </if>
      <if test="positionGrade != null" >
        POSITION_GRADE,
      </if>
      <if test="versionNo != null" >
        VERSION_NO,
      </if>
      <if test="remarks != null" >
        REMARKS,
      </if>
      <if test="delFlag != null" >
        DEL_FLAG,
      </if>
      <if test="createBy != null" >
        CREATE_BY,
      </if>
      <if test="createDate != null" >
        CREATE_DATE,
      </if>
      <if test="updateBy != null" >
        UPDATE_BY,
      </if>
      <if test="updateDate != null" >
        UPDATE_DATE,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="userCode != null" >
        #{userCode,jdbcType=BIGINT},
      </if>
      <if test="positionId != null" >
        #{positionId,jdbcType=INTEGER},
      </if>
      <if test="depdId != null" >
        #{depdId,jdbcType=INTEGER},
      </if>
      <if test="positionGrade != null" >
        #{positionGrade,jdbcType=INTEGER},
      </if>
      <if test="versionNo != null" >
        #{versionNo,jdbcType=INTEGER},
      </if>
      <if test="remarks != null" >
        #{remarks,jdbcType=VARCHAR},
      </if>
      <if test="delFlag != null" >
        #{delFlag,jdbcType=INTEGER},
      </if>
      <if test="createBy != null" >
        #{createBy,jdbcType=VARCHAR},
      </if>
      <if test="createDate != null" >
        #{createDate,jdbcType=TIMESTAMP},
      </if>
      <if test="updateBy != null" >
        #{updateBy,jdbcType=VARCHAR},
      </if>
      <if test="updateDate != null" >
        #{updateDate,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.wechat.model.dbEntity.MdeSubscribedPositions" >
    update mde_subscribed_positions
    <set >
      <if test="depdId != null" >
        DEPD_ID = #{depdId,jdbcType=INTEGER},
      </if>
      <if test="positionGrade != null" >
        POSITION_GRADE = #{positionGrade,jdbcType=INTEGER},
      </if>
      <if test="versionNo != null" >
        VERSION_NO = #{versionNo,jdbcType=INTEGER},
      </if>
      <if test="remarks != null" >
        REMARKS = #{remarks,jdbcType=VARCHAR},
      </if>
      <if test="delFlag != null" >
        DEL_FLAG = #{delFlag,jdbcType=INTEGER},
      </if>
      <if test="createBy != null" >
        CREATE_BY = #{createBy,jdbcType=VARCHAR},
      </if>
      <if test="createDate != null" >
        CREATE_DATE = #{createDate,jdbcType=TIMESTAMP},
      </if>
      <if test="updateBy != null" >
        UPDATE_BY = #{updateBy,jdbcType=VARCHAR},
      </if>
      <if test="updateDate != null" >
        UPDATE_DATE = #{updateDate,jdbcType=TIMESTAMP},
      </if>
    </set>
    where USER_CODE = #{userCode,jdbcType=BIGINT}
      and POSITION_ID = #{positionId,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.wechat.model.dbEntity.MdeSubscribedPositions" >
    update mde_subscribed_positions
    set DEPD_ID = #{depdId,jdbcType=INTEGER},
      POSITION_GRADE = #{positionGrade,jdbcType=INTEGER},
      VERSION_NO = #{versionNo,jdbcType=INTEGER},
      REMARKS = #{remarks,jdbcType=VARCHAR},
      DEL_FLAG = #{delFlag,jdbcType=INTEGER},
      CREATE_BY = #{createBy,jdbcType=VARCHAR},
      CREATE_DATE = #{createDate,jdbcType=TIMESTAMP},
      UPDATE_BY = #{updateBy,jdbcType=VARCHAR},
      UPDATE_DATE = #{updateDate,jdbcType=TIMESTAMP}
    where USER_CODE = #{userCode,jdbcType=BIGINT}
      and POSITION_ID = #{positionId,jdbcType=INTEGER}
  </update>
</mapper>