<?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.jkcredit.invoice.mapper.customer.CustomerChangeInfoMapper">
  <resultMap id="BaseResultMap" type="com.jkcredit.invoice.model.entity.customer.CustomerEtcChangeInfo">
    <result column="customerId" jdbcType="VARCHAR" property="customerId" />
    <result column="companyName" jdbcType="VARCHAR" property="companyName" />
    <result column="companyNum" jdbcType="VARCHAR" property="companyNum" />
    <result column="targetCompanyName" jdbcType="VARCHAR" property="targetCompanyName" />
    <result column="targetCompanyNum" jdbcType="VARCHAR" property="targetCompanyNum" />
    <result column="applyId" jdbcType="VARCHAR" property="applyId" />
    <result column="changeTime" jdbcType="VARCHAR" property="changeTime" />
    <result column="info" jdbcType="VARCHAR" property="info" />
  </resultMap>
  <sql id="Base_Column_List">
     customerId,companyName,companyNum,targetCompanyName,targetcompanyNum,applyId,changeTime,info
  </sql>
    <select id="selectAllByPage" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from t_change_card_info
        <where>
            <if test="custometEtcChangeInfo.customerId != null and custometEtcChangeInfo.customerId != ''">
                and  customerId = BINARY #{custometEtcChangeInfo.customerId}
            </if>

            <if test="custometEtcChangeInfo.companyName != null and custometEtcChangeInfo.companyName != ''">
                and  companyName = BINARY #{custometEtcChangeInfo.companyName}
            </if>
        </where>
    </select>
    <resultMap id="cardsMap" type="java.util.Map">
        <result column="cardId" jdbcType="VARCHAR" property="cardId" />
    </resultMap>
    <select id="selectChangeCards" parameterType="java.lang.String" resultMap="cardsMap">
        select cardId from t_change_card where applyId = BINARY #{applyId}
    </select>
  <insert id="insertCardChangeInfo" parameterType="com.jkcredit.invoice.model.entity.customer.CustomerEtcChangeInfo">
      insert into t_change_card_info (customerId,companyName,companyNum,targetCompanyName,targetcompanyNum,applyId,changeTime,info)
      values (#{customerId,jdbcType=VARCHAR},#{companyName,jdbcType=VARCHAR}, #{companyNum,jdbcType=VARCHAR}, #{targetCompanyName,jdbcType=VARCHAR},
      #{targetCompanyNum,jdbcType=VARCHAR}, #{applyId,jdbcType=VARCHAR}, #{changeTime,jdbcType=VARCHAR},
      #{info,jdbcType=VARCHAR})
  </insert>

  <insert id="insertChangeCard" parameterType="java.util.Map">
      insert into t_change_card (applyId,cardId) VALUES (#{applyId,jdbcType=VARCHAR},#{cardId,jdbcType=VARCHAR})
  </insert>
</mapper>