<?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.chaozhanggui.dao.system.dao.TbPlussAccountMapper">
  <resultMap id="BaseResultMap" type="com.chaozhanggui.dao.system.entity.TbPlussAccount">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="userId" jdbcType="VARCHAR" property="userid" />
    <result column="idcardId" jdbcType="VARCHAR" property="idcardid" />
    <result column="bankCardId" jdbcType="VARCHAR" property="bankcardid" />
    <result column="certificateUrl" jdbcType="VARCHAR" property="certificateurl" />
    <result column="settleType" jdbcType="VARCHAR" property="settletype" />
    <result column="createTime" jdbcType="TIMESTAMP" property="createtime" />
    <result column="updateTime" jdbcType="TIMESTAMP" property="updatetime" />
    <result column="channelType" jdbcType="VARCHAR" property="channeltype" />
    <result column="valid" jdbcType="INTEGER" property="valid" />
  </resultMap>
  <resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="com.chaozhanggui.dao.system.entity.TbPlussAccount">
    <result column="bak" jdbcType="LONGVARCHAR" property="bak" />
  </resultMap>
  <sql id="Base_Column_List">
    id, userId, idcardId, bankCardId, certificateUrl, settleType, createTime, updateTime, 
    channelType, valid
  </sql>
  <sql id="Blob_Column_List">
    bak
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="ResultMapWithBLOBs">
    select 
    <include refid="Base_Column_List" />
    ,
    <include refid="Blob_Column_List" />
    from tb_pluss_account
    where id = #{id,jdbcType=INTEGER}
  </select>
    <select id="selectByUser" resultType="com.chaozhanggui.dao.system.entity.TbPlussAccount">
      select
      <include refid="Base_Column_List" />
      from tb_pluss_account
      WHERE
        userId = #{userId}
        AND channelType = #{channelType}
      LIMIT 1
    </select>
  <select id="selectByAccount" resultType="com.chaozhanggui.dao.system.entity.TbPlussAccount">
    select
    <include refid="Base_Column_List" />
    from tb_pluss_account
    <where>
      <if test="id!= null">
        and id = #{id}
      </if>
      <if test="userid!= null">
        and userId = #{userid}
      </if>
      <if test="idcardid!= null">
        and idcardId = #{idcardid}
      </if>
      <if test="bankcardid!= null">
        and bankCardId = #{bankcardid}
      </if>
      <if test="certificateurl!= null">
        and certificateUrl = #{certificateurl}
      </if>
      <if test="settletype!= null">
        and settleType = #{settletype}
      </if>
      <if test="channeltype!= null">
        and channelType = #{channeltype}
      </if>
      <if test="valid!= null">
        and valid = #{valid}
      </if>
      limit 1
    </where>
  </select>
  <select id="selectCountIdCardId" resultType="java.lang.Integer">
    SELECT COUNT( 1 )
    FROM tb_pluss_account
    <where>
      <if test="userId != null">
          userId = #{userId}
      </if>
      <if test="idCardId!= null">
        and idcardId = #{idCardId}
      </if>
    </where>
  </select>
  <select id="selectCountBankCard" resultType="java.lang.Integer">
    SELECT COUNT( 1 )
    FROM tb_pluss_account
    <where>
      <if test="userId != null">
        userId = #{userId}
      </if>
      <if test="bankCardId!= null">
        and bankCardId = #{bankCardId}
      </if>
    </where>
  </select>
  <select id="selectByAccountD1" resultType="com.chaozhanggui.dao.system.entity.TbPlussAccount">
    select
    <include refid="Base_Column_List" />
    from tb_pluss_account
    <where>
      <if test="userId != null">
         userId = #{userId}
      </if>
      <if test="channelType!= null">
        and channelType = #{channelType}
      </if>
    </where>
    limit 1
  </select>
  <select id="selectMicroMbiAccountNum" resultType="java.lang.Integer">
    SELECT count(DISTINCT mbi.userId) count FROM tb_pluss_merchant_base_info mbi
      LEFT JOIN tb_pluss_account account ON account.userId = mbi.userId
      LEFT JOIN tb_pluss_id_card ic ON account.userId = ic.userId AND account.idCardId = ic.id
      LEFT JOIN tb_pluss_merchant_channel_status mcs ON mcs.merchantCode = mbi.merchantCode
    WHERE merchantType = 1
      AND mcs.`status` IN (3)
      AND ic.certNo = #{certNo}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from tb_pluss_account
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.chaozhanggui.dao.system.entity.TbPlussAccount">
    insert into tb_pluss_account (id, userId, idcardId, 
      bankCardId, certificateUrl, settleType, 
      createTime, updateTime, channelType, 
      valid, bak)
    values (#{id,jdbcType=INTEGER}, #{userid,jdbcType=VARCHAR}, #{idcardid,jdbcType=VARCHAR}, 
      #{bankcardid,jdbcType=VARCHAR}, #{certificateurl,jdbcType=VARCHAR}, #{settletype,jdbcType=VARCHAR}, 
      #{createtime,jdbcType=TIMESTAMP}, #{updatetime,jdbcType=TIMESTAMP}, #{channeltype,jdbcType=VARCHAR}, 
      #{valid,jdbcType=INTEGER}, #{bak,jdbcType=LONGVARCHAR})
  </insert>
  <insert id="insertSelective" parameterType="com.chaozhanggui.dao.system.entity.TbPlussAccount">
    insert into tb_pluss_account
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="userid != null">
        userId,
      </if>
      <if test="idcardid != null">
        idcardId,
      </if>
      <if test="bankcardid != null">
        bankCardId,
      </if>
      <if test="certificateurl != null">
        certificateUrl,
      </if>
      <if test="settletype != null">
        settleType,
      </if>
      <if test="createtime != null">
        createTime,
      </if>
      <if test="updatetime != null">
        updateTime,
      </if>
      <if test="channeltype != null">
        channelType,
      </if>
      <if test="valid != null">
        valid,
      </if>
      <if test="bak != null">
        bak,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=INTEGER},
      </if>
      <if test="userid != null">
        #{userid,jdbcType=VARCHAR},
      </if>
      <if test="idcardid != null">
        #{idcardid,jdbcType=VARCHAR},
      </if>
      <if test="bankcardid != null">
        #{bankcardid,jdbcType=VARCHAR},
      </if>
      <if test="certificateurl != null">
        #{certificateurl,jdbcType=VARCHAR},
      </if>
      <if test="settletype != null">
        #{settletype,jdbcType=VARCHAR},
      </if>
      <if test="createtime != null">
        #{createtime,jdbcType=TIMESTAMP},
      </if>
      <if test="updatetime != null">
        #{updatetime,jdbcType=TIMESTAMP},
      </if>
      <if test="channeltype != null">
        #{channeltype,jdbcType=VARCHAR},
      </if>
      <if test="valid != null">
        #{valid,jdbcType=INTEGER},
      </if>
      <if test="bak != null">
        #{bak,jdbcType=LONGVARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.chaozhanggui.dao.system.entity.TbPlussAccount">
    update tb_pluss_account
    <set>
      <if test="userid != null">
        userId = #{userid,jdbcType=VARCHAR},
      </if>
      <if test="idcardid != null">
        idcardId = #{idcardid,jdbcType=VARCHAR},
      </if>
      <if test="bankcardid != null">
        bankCardId = #{bankcardid,jdbcType=VARCHAR},
      </if>
      <if test="certificateurl != null">
        certificateUrl = #{certificateurl,jdbcType=VARCHAR},
      </if>
      <if test="settletype != null">
        settleType = #{settletype,jdbcType=VARCHAR},
      </if>
      <if test="createtime != null">
        createTime = #{createtime,jdbcType=TIMESTAMP},
      </if>
      <if test="updatetime != null">
        updateTime = #{updatetime,jdbcType=TIMESTAMP},
      </if>
      <if test="channeltype != null">
        channelType = #{channeltype,jdbcType=VARCHAR},
      </if>
      <if test="valid != null">
        valid = #{valid,jdbcType=INTEGER},
      </if>
      <if test="bak != null">
        bak = #{bak,jdbcType=LONGVARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKeyWithBLOBs" parameterType="com.chaozhanggui.dao.system.entity.TbPlussAccount">
    update tb_pluss_account
    set userId = #{userid,jdbcType=VARCHAR},
      idcardId = #{idcardid,jdbcType=VARCHAR},
      bankCardId = #{bankcardid,jdbcType=VARCHAR},
      certificateUrl = #{certificateurl,jdbcType=VARCHAR},
      settleType = #{settletype,jdbcType=VARCHAR},
      createTime = #{createtime,jdbcType=TIMESTAMP},
      updateTime = #{updatetime,jdbcType=TIMESTAMP},
      channelType = #{channeltype,jdbcType=VARCHAR},
      valid = #{valid,jdbcType=INTEGER},
      bak = #{bak,jdbcType=LONGVARCHAR}
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.chaozhanggui.dao.system.entity.TbPlussAccount">
    update tb_pluss_account
    set userId = #{userid,jdbcType=VARCHAR},
      idcardId = #{idcardid,jdbcType=VARCHAR},
      bankCardId = #{bankcardid,jdbcType=VARCHAR},
      certificateUrl = #{certificateurl,jdbcType=VARCHAR},
      settleType = #{settletype,jdbcType=VARCHAR},
      createTime = #{createtime,jdbcType=TIMESTAMP},
      updateTime = #{updatetime,jdbcType=TIMESTAMP},
      channelType = #{channeltype,jdbcType=VARCHAR},
      valid = #{valid,jdbcType=INTEGER}
    where id = #{id,jdbcType=INTEGER}
  </update>
</mapper>