<?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.cool.store.mapper.BankdocMapper">
  <resultMap id="BaseResultMap" type="com.cool.store.entity.BankdocDO">
    <result column="code" jdbcType="VARCHAR" property="code" />
    <result column="combinenum" jdbcType="VARCHAR" property="combinenum" />
    <result column="enablestate" jdbcType="DECIMAL" property="enablestate" />
    <result column="iscustbank" jdbcType="CHAR" property="iscustbank" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="pk_banktype" jdbcType="VARCHAR" property="pkBanktype" />
  </resultMap>
  <insert id="insertSelective" parameterType="com.cool.store.entity.BankdocDO">
    insert into xfsg_bankdoc
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="code != null">
        code,
      </if>
      <if test="combinenum != null">
        combinenum,
      </if>
      <if test="enablestate != null">
        enablestate,
      </if>
      <if test="iscustbank != null">
        iscustbank,
      </if>
      <if test="name != null">
        name,
      </if>
      <if test="pkBanktype != null">
        pk_banktype,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="code != null">
        #{code,jdbcType=VARCHAR},
      </if>
      <if test="combinenum != null">
        #{combinenum,jdbcType=VARCHAR},
      </if>
      <if test="enablestate != null">
        #{enablestate,jdbcType=DECIMAL},
      </if>
      <if test="iscustbank != null">
        #{iscustbank,jdbcType=CHAR},
      </if>
      <if test="name != null">
        #{name,jdbcType=VARCHAR},
      </if>
      <if test="pkBanktype != null">
        #{pkBanktype,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <sql id="dynamicQuery">
    <trim prefix="WHERE" prefixOverrides="AND | OR">
      <if test="null != code">
         and t.code = #{code,jdbcType=VARCHAR}
      </if>
      <if test="null != combinenum">
         and t.combinenum = #{combinenum,jdbcType=VARCHAR}
      </if>
      <if test="null != enablestate">
         and t.enablestate = #{enablestate,jdbcType=DECIMAL}
      </if>
      <if test="null != iscustbank">
         and t.iscustbank = #{iscustbank,jdbcType=CHAR}
      </if>
      <if test="null != name">
         and t.name = #{name,jdbcType=VARCHAR}
      </if>
      <if test="null != pkBanktype">
         and t.pk_banktype = #{pkBanktype,jdbcType=VARCHAR}
      </if>
    </trim>
  </sql>

  <select id="listBranchBank" resultMap="BaseResultMap">
    SELECT doc.* FROM xfsg_banktype type left join xfsg_bankdoc doc on  doc.enablestate = 2 and doc.iscustbank = 'N'
        and doc.pk_banktype = type.pk_banktype and type.code = #{bankCode}
        <if test="keyword != null and keyword != ''">
          and (doc.code  like concat('%',#{keyword},'%') or doc.name like concat('%',#{keyword},'%'))
        </if>
    where doc.code is not null and doc.name is not null
    order by doc.name
  </select>

</mapper>