<?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.MdeIntvContactsMapper">
  <resultMap id="BaseResultMap" type="com.wechat.model.dbEntity.MdeIntvContacts">
    <id column="CONT_ID" jdbcType="INTEGER" property="contId" />
    <result column="USER_CODE" jdbcType="VARCHAR" property="userCode" />
    <result column="ENT_CONTACTS" jdbcType="VARCHAR" property="entContacts" />
    <result column="ENT_CONTACT_INFO" jdbcType="VARCHAR" property="entContactInfo" />
    <result column="DEFAULT_FLG" jdbcType="CHAR" property="defaultFlg" />
    <result column="VERSION_NO" jdbcType="INTEGER" property="versionNo" />
    <result column="CREATE_BY" jdbcType="VARCHAR" property="createBy" />
    <result column="CREATE_DATE" jdbcType="TIMESTAMP" property="createDate" />
    <result column="UPDATE_BY" jdbcType="VARCHAR" property="updateBy" />
    <result column="UPDATE_DATE" jdbcType="TIMESTAMP" property="updateDate" />
    <result column="REMARKS" jdbcType="VARCHAR" property="remarks" />
    <result column="DEL_FLAG" jdbcType="CHAR" property="delFlag" />
  </resultMap>
  <sql id="Base_Column_List">
    CONT_ID, USER_CODE, ENT_CONTACTS, ENT_CONTACT_INFO, DEFAULT_FLG, VERSION_NO, CREATE_BY, 
    CREATE_DATE, UPDATE_BY, UPDATE_DATE, REMARKS, DEL_FLAG
  </sql>
  <select id="getContacts" resultType="com.wechat.model.dto.IntvContactsDto">
    select 
	    CONT_ID           as contId,
		USER_CODE         as userCode,
		ENT_CONTACTS      as entContacts,
		ENT_CONTACT_INFO  as entContactInfo,
		DEFAULT_FLG       as defaultFlg
    from mde_intv_contacts
    where USER_CODE = #{userCode}
      and DEL_FLAG = '0'
  </select>
  
  
  <delete id="delContact" parameterType="java.util.Map">
    delete from mde_intv_contacts
    where CONT_ID = #{contId}
      and USER_CODE = #{userCode}
  </delete>
  
  <insert id="insert" parameterType="com.wechat.model.dbEntity.MdeIntvContacts">
    insert into mde_intv_contacts (USER_CODE, ENT_CONTACTS, 
      ENT_CONTACT_INFO, DEFAULT_FLG, 
      CREATE_BY, CREATE_DATE, UPDATE_BY, 
      UPDATE_DATE, REMARKS
      )
    values (#{userCode,jdbcType=VARCHAR}, #{entContacts,jdbcType=VARCHAR}, 
      #{entContactInfo,jdbcType=VARCHAR}, #{defaultFlg,jdbcType=CHAR}, 
      #{createBy,jdbcType=VARCHAR}, #{createDate,jdbcType=TIMESTAMP}, #{updateBy,jdbcType=VARCHAR}, 
      #{updateDate,jdbcType=TIMESTAMP}, #{remarks,jdbcType=VARCHAR}
      )
  </insert>
  
  <update id="updateByPrimaryKeySelective" parameterType="com.wechat.model.dbEntity.MdeIntvContacts">
    update mde_intv_contacts
    <set>
      <if test="userCode != null">
        USER_CODE = #{userCode,jdbcType=VARCHAR},
      </if>
      <if test="entContacts != null">
        ENT_CONTACTS = #{entContacts,jdbcType=VARCHAR},
      </if>
      <if test="entContactInfo != null">
        ENT_CONTACT_INFO = #{entContactInfo,jdbcType=VARCHAR},
      </if>
      <if test="defaultFlg != null">
        DEFAULT_FLG = #{defaultFlg,jdbcType=CHAR},
      </if>
      <if test="versionNo != null">
        VERSION_NO = #{versionNo,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>
      <if test="remarks != null">
        REMARKS = #{remarks,jdbcType=VARCHAR},
      </if>
      <if test="delFlag != null">
        DEL_FLAG = #{delFlag,jdbcType=CHAR},
      </if>
    </set>
    where CONT_ID = #{contId,jdbcType=INTEGER}
  </update>
  
  <update id="update" parameterType="com.wechat.model.dbEntity.MdeIntvContacts">
    update mde_intv_contacts
    set 
      ENT_CONTACTS = #{entContacts,jdbcType=VARCHAR},
      ENT_CONTACT_INFO = #{entContactInfo,jdbcType=VARCHAR},
      DEFAULT_FLG = #{defaultFlg,jdbcType=CHAR},
      VERSION_NO = version_no +1,
      UPDATE_BY = #{updateBy,jdbcType=VARCHAR},
      UPDATE_DATE = #{updateDate,jdbcType=TIMESTAMP},
      REMARKS = #{remarks,jdbcType=VARCHAR}
    where CONT_ID = #{contId}
    and USER_CODE = #{userCode}
  </update>
  
  <update id="updateNondefault" parameterType="com.wechat.model.dbEntity.MdeIntvContacts">
    update mde_intv_contacts
    set 
      DEFAULT_FLG = '0',
      VERSION_NO = version_no +1,
      UPDATE_BY = #{updateBy,jdbcType=VARCHAR},
      UPDATE_DATE = #{updateDate,jdbcType=TIMESTAMP}
    where  USER_CODE = #{userCode}
  </update>
  
</mapper>