<?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.MdeInterestedAddsMapper" >
  <resultMap id="BaseResultMap" type="com.wechat.model.dbEntity.MdeInterestedAdds" >
    <id column="USER_CODE" property="userCode" jdbcType="BIGINT" />
    <id column="INTD_CITY" property="intdCity" jdbcType="VARCHAR" />
    <result column="INTD_PROVINCE" property="intdProvince" jdbcType="VARCHAR" />
    <result column="INTD_PROVINCE_NAME" property="intdProvinceName" jdbcType="VARCHAR" />
    <result column="INTD_CITY_NAME" property="intdCityName" jdbcType="VARCHAR" />
    <result column="SORT" property="sort" jdbcType="TINYINT" />
    <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>

  
  <delete id="deleteByUsercode" parameterType="String" >
    delete from mde_interested_adds
    where USER_CODE = #{userCode}
  </delete>
  
  <insert id="insert" parameterType="com.wechat.model.dbEntity.MdeInterestedAdds" >
    insert into mde_interested_adds (USER_CODE, INTD_CITY, INTD_PROVINCE, INTD_PROVINCE_NAME, INTD_CITY_NAME,
      SORT, CREATE_BY, CREATE_DATE, 
      UPDATE_BY, UPDATE_DATE)
    values (#{userCode,jdbcType=BIGINT}, #{intdCity,jdbcType=VARCHAR}, #{intdProvince}, #{intdProvinceName}, #{intdCityName},
      #{sort,jdbcType=TINYINT}, #{createBy,jdbcType=VARCHAR}, #{createDate,jdbcType=TIMESTAMP}, 
      #{updateBy,jdbcType=VARCHAR}, #{updateDate,jdbcType=TIMESTAMP})
  </insert>
  
  <select id="getIntAddsByUserCode" resultType="com.wechat.model.requestDto.InterestedAddsReq" >
    SELECT
		a.INTD_CITY AS intdCity,
		a.INTD_PROVINCE AS intdProvince,
		a.INTD_PROVINCE_NAME AS intdProvinceName,
		a.SORT AS sort,
		<choose>
			<when test="lang != null and lang == 'en'.toString()">
				d.name_en as intdCityName
			</when>
			<otherwise>
				d.name as intdCityName
			</otherwise>
		</choose>
	FROM
		MDE_INTERESTED_ADDS a
		left join sys_area d on d.code=a.INTD_CITY
	WHERE
		a.USER_CODE = #{userCode}
		AND a.DEL_FLAG = '0'
  </select>
  
  
  <update id="updateByPrimaryKeySelective" parameterType="com.wechat.model.dbEntity.MdeInterestedAdds" >
    update mde_interested_adds
    <set >
      <if test="intdProvince != null" >
        INTD_PROVINCE = #{intdProvince,jdbcType=VARCHAR},
      </if>
      <if test="sort != null" >
        SORT = #{sort,jdbcType=TINYINT},
      </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 INTD_CITY = #{intdCity,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.wechat.model.dbEntity.MdeInterestedAdds" >
    update mde_interested_adds
    set INTD_PROVINCE = #{intdProvince,jdbcType=VARCHAR},
      SORT = #{sort,jdbcType=TINYINT},
      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 INTD_CITY = #{intdCity,jdbcType=VARCHAR}
  </update>
</mapper>