<?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.xhpc.activity.mapper.XhpcClearingBankMapper">
    <resultMap id="BaseResultMap" type="com.xhpc.activity.domain.XhpcClearingBankDomain">
        <id column="clearing_bank_id" jdbcType="BIGINT" property="clearingBankId"/>
        <result column="operator_id" jdbcType="BIGINT" property="operatorId"/>
        <result column="operator_name" jdbcType="VARCHAR" property="operatorName"/>
        <result column="area_code" jdbcType="INTEGER" property="areaCode"/>
        <result column="bank_name" jdbcType="VARCHAR" property="bankName"/>
        <result column="operator_account" jdbcType="VARCHAR" property="operatorAccount"/>
        <result column="bank_no" jdbcType="VARCHAR" property="bankNo"/>
        <result column="address" jdbcType="VARCHAR" property="address"/>
        <result column="contact_name" jdbcType="VARCHAR" property="contactName"/>
        <result column="contact_phone" jdbcType="VARCHAR" property="contactPhone"/>
        <result column="remark" jdbcType="VARCHAR" property="remark"/>
        <result column="status" jdbcType="INTEGER" property="status"/>
        <result column="del_flag" jdbcType="INTEGER" property="delFlag"/>
        <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
        <result column="create_by" jdbcType="VARCHAR" property="createBy"/>
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
        <result column="update_by" jdbcType="VARCHAR" property="updateBy"/>
        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
    </resultMap>
    <sql id="Base_Column_List">
        clearing_bank_id
        , operator_id, operator_name, area_code, bank_name, operator_account,
    bank_no, address, contact_name, contact_phone, remark, `status`, del_flag, tenant_id, create_by,
    create_time, update_by, update_time
    </sql>


    <update id="deleteLogicByPrimaryKey">
        update xhpc_clearing_bank
        set del_flag=2
        where clearing_bank_id = #{clearingBankId,jdbcType=BIGINT}
    </update>


    <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from xhpc_clearing_bank
        where clearing_bank_id = #{clearingBankId,jdbcType=BIGINT}
    </select>


    <select id="selectByParams" resultType="com.xhpc.activity.domain.XhpcClearingBankDomain">
        select
        <include refid="Base_Column_List"/>
        from xhpc_clearing_bank
        where del_flag=0
        <if test="params.status!=null and params.status!=''">
            and status=#{params.status}
        </if>
        <if test="params.tenantId!=null and params.tenantId!=''">
            and tenant_id=#{params.tenantId}
        </if>
        <if test="params.operatorId != null and params.operatorId!=''">
            and operator_id=#{params.operatorId}
        </if>
    </select>


    <select id="selectOneByOperatorId" resultType="com.xhpc.activity.domain.XhpcClearingBankDomain">
        select
        <include refid="Base_Column_List"/>
        from xhpc_clearing_bank
        where del_flag=0 and status=1 and operator_id=#{operatorId}
        order by update_time desc limit 1
    </select>


    <select id="selectOneMapByOperatorId" resultType="java.util.Map">
        select operator_name as 'operatorName', bank_name as 'bankName', bank_no as 'bankNo', contact_phone as 'contactPhone', contact_name as 'contactName'
        from xhpc_clearing_bank
        where del_flag = 0
          and status = 1
          and operator_id = #{operatorId}
        order by update_time desc limit 1
    </select>


    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
        delete
        from xhpc_clearing_bank
        where clearing_bank_id = #{clearingBankId,jdbcType=BIGINT}
    </delete>


    <update id="deleteLogicByOperatorId">
        update xhpc_clearing_bank
        set del_flag=2
        where operator_id = #{operatorId}
    </update>


    <insert id="insert" keyColumn="clearing_bank_id" keyProperty="clearingBankId"
            parameterType="com.xhpc.activity.domain.XhpcClearingBankDomain" useGeneratedKeys="true">
        insert into xhpc_clearing_bank (operator_id, operator_name, area_code,
                                        bank_name, operator_account, bank_no,
                                        address, contact_name, contact_phone,
                                        remark, `status`, del_flag,
                                        tenant_id, create_by, create_time,
                                        update_by, update_time)
        values (#{operatorId,jdbcType=BIGINT}, #{operatorName,jdbcType=VARCHAR}, #{areaCode,jdbcType=INTEGER},
                #{bankName,jdbcType=VARCHAR}, #{operatorAccount,jdbcType=VARCHAR}, #{bankNo,jdbcType=VARCHAR},
                #{address,jdbcType=VARCHAR}, #{contactName,jdbcType=VARCHAR}, #{contactPhone,jdbcType=VARCHAR},
                #{remark,jdbcType=VARCHAR}, 1, 0,
                #{tenantId,jdbcType=VARCHAR}, #{createBy,jdbcType=VARCHAR}, sysdate(),
                #{updateBy,jdbcType=VARCHAR}, sysdate())
    </insert>


    <update id="updateByPrimaryKey" parameterType="com.xhpc.activity.domain.XhpcClearingBankDomain">
        update xhpc_clearing_bank
        set operator_id      = #{operatorId,jdbcType=BIGINT},
            operator_name    = #{operatorName,jdbcType=VARCHAR},
            area_code        = #{areaCode,jdbcType=INTEGER},
            bank_name        = #{bankName,jdbcType=VARCHAR},
            operator_account = #{operatorAccount,jdbcType=VARCHAR},
            bank_no          = #{bankNo,jdbcType=VARCHAR},
            address          = #{address,jdbcType=VARCHAR},
            contact_name   = #{contactName,jdbcType=VARCHAR},
            contact_phone   = #{contactPhone,jdbcType=VARCHAR},
            remark           = #{remark,jdbcType=VARCHAR},
            `status`         = #{status,jdbcType=INTEGER},
            update_by        = #{updateBy,jdbcType=VARCHAR},
            update_time      = sysdate()
        where clearing_bank_id = #{clearingBankId,jdbcType=BIGINT}
    </update>

</mapper>