<?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.hzya.frame.plugin.lets.dao.impl.BdCustbankDaoImpl">

    <resultMap id="get-BdCustbankEntity-result" type="com.hzya.frame.plugin.lets.entity.BdCustbankEntity">
        <result property="accaddr" column="accaddr" jdbcType="VARCHAR"/>
        <result property="accname" column="accname" jdbcType="VARCHAR"/>
        <result property="account" column="account" jdbcType="VARCHAR"/>
        <result property="defflag" column="defflag" jdbcType="VARCHAR"/>
        <result property="dr" column="dr" jdbcType="INTEGER"/>
        <result property="memo" column="memo" jdbcType="VARCHAR"/>
        <result property="pkAccbank" column="pk_accbank" jdbcType="VARCHAR"/>
        <result property="pkCorp" column="pk_corp" jdbcType="VARCHAR"/>
        <result property="pkCubasdoc" column="pk_cubasdoc" jdbcType="VARCHAR"/>
        <result property="pkCurrtype" column="pk_currtype" jdbcType="VARCHAR"/>
        <result property="pkCustbank" column="pk_custbank" jdbcType="VARCHAR"/>
        <result property="ts" column="ts" jdbcType="VARCHAR"/>
    </resultMap>
    <!-- 查询的字段-->
    <sql id="BdCustbankEntity_Base_Column_List">
        accaddr
        ,accname
        ,account 
        ,defflag 
        ,dr 
        ,memo 
        ,pk_accbank 
        ,pk_corp 
        ,pk_cubasdoc 
        ,pk_currtype 
        ,pk_custbank 
        ,ts
    </sql>
    <!-- 查询 采用==查询 -->
    <select id="entity_list_base" resultMap="get-BdCustbankEntity-result"
            parameterType="com.hzya.frame.plugin.lets.entity.BdCustbankEntity">
        select
        <include refid="BdCustbankEntity_Base_Column_List"/>
        from bd_custbank
        <trim prefix="where" prefixOverrides="and">
            <if test="accaddr != null and accaddr != ''">and accaddr = #{accaddr}</if>
            <if test="accname != null and accname != ''">and accname = #{accname}</if>
            <if test="account != null and account != ''">and account = #{account}</if>
            <if test="defflag != null and defflag != ''">and defflag = #{defflag}</if>
            <if test="dr != null">and dr = #{dr}</if>
            <if test="memo != null and memo != ''">and memo = #{memo}</if>
            <if test="pkAccbank != null and pkAccbank != ''">and pk_accbank = #{pkAccbank}</if>
            <if test="pkCorp != null and pkCorp != ''">and pk_corp = #{pkCorp}</if>
            <if test="pkCubasdoc != null and pkCubasdoc != ''">and pk_cubasdoc = #{pkCubasdoc}</if>
            <if test="pkCurrtype != null and pkCurrtype != ''">and pk_currtype = #{pkCurrtype}</if>
            <if test="pkCustbank != null and pkCustbank != ''">and pk_custbank = #{pkCustbank}</if>
            <if test="ts != null and ts != ''">and ts = #{ts}</if>
            and sts='Y'
        </trim>
        <if test=" sort == null or sort == ''.toString() ">order by sorts asc</if>
        <if test=" sort !='' and sort!=null and order !='' and order!=null ">order by ${sort} ${order}</if>
    </select>

    <!-- 查询符合条件的数量 -->
    <select id="entity_count" resultType="Integer" parameterType="com.hzya.frame.plugin.lets.entity.BdCustbankEntity">
        select count(1) from bd_custbank
        <trim prefix="where" prefixOverrides="and">
            <if test="accaddr != null and accaddr != ''">and accaddr = #{accaddr}</if>
            <if test="accname != null and accname != ''">and accname = #{accname}</if>
            <if test="account != null and account != ''">and account = #{account}</if>
            <if test="defflag != null and defflag != ''">and defflag = #{defflag}</if>
            <if test="dr != null">and dr = #{dr}</if>
            <if test="memo != null and memo != ''">and memo = #{memo}</if>
            <if test="pkAccbank != null and pkAccbank != ''">and pk_accbank = #{pkAccbank}</if>
            <if test="pkCorp != null and pkCorp != ''">and pk_corp = #{pkCorp}</if>
            <if test="pkCubasdoc != null and pkCubasdoc != ''">and pk_cubasdoc = #{pkCubasdoc}</if>
            <if test="pkCurrtype != null and pkCurrtype != ''">and pk_currtype = #{pkCurrtype}</if>
            <if test="pkCustbank != null and pkCustbank != ''">and pk_custbank = #{pkCustbank}</if>
            <if test="ts != null and ts != ''">and ts = #{ts}</if>
            and sts='Y'
        </trim>
        <if test=" sort == null or sort == ''.toString() ">order by sorts asc</if>
        <if test=" sort !='' and sort!=null and order !='' and order!=null ">order by ${sort} ${order}</if>
    </select>

    <!-- 分页查询列表 采用like格式 -->
    <select id="entity_list_like" resultMap="get-BdCustbankEntity-result"
            parameterType="com.hzya.frame.plugin.lets.entity.BdCustbankEntity">
        select
        <include refid="BdCustbankEntity_Base_Column_List"/>
        from bd_custbank
        <trim prefix="where" prefixOverrides="and">
            <if test="accaddr != null and accaddr != ''">and accaddr like concat('%',#{accaddr},'%')</if>
            <if test="accname != null and accname != ''">and accname like concat('%',#{accname},'%')</if>
            <if test="account != null and account != ''">and account like concat('%',#{account},'%')</if>
            <if test="defflag != null and defflag != ''">and defflag like concat('%',#{defflag},'%')</if>
            <if test="dr != null">and dr like concat('%',#{dr},'%')</if>
            <if test="memo != null and memo != ''">and memo like concat('%',#{memo},'%')</if>
            <if test="pkAccbank != null and pkAccbank != ''">and pk_accbank like concat('%',#{pkAccbank},'%')</if>
            <if test="pkCorp != null and pkCorp != ''">and pk_corp like concat('%',#{pkCorp},'%')</if>
            <if test="pkCubasdoc != null and pkCubasdoc != ''">and pk_cubasdoc like concat('%',#{pkCubasdoc},'%')</if>
            <if test="pkCurrtype != null and pkCurrtype != ''">and pk_currtype like concat('%',#{pkCurrtype},'%')</if>
            <if test="pkCustbank != null and pkCustbank != ''">and pk_custbank like concat('%',#{pkCustbank},'%')</if>
            <if test="ts != null and ts != ''">and ts like concat('%',#{ts},'%')</if>
            and sts='Y'
        </trim>
        <if test=" sort == null or sort == ''.toString() ">order by sorts asc</if>
        <if test=" sort !='' and sort!=null and order !='' and order!=null ">order by ${sort} ${order}</if>
    </select>

    <!-- 查询列表 字段采用or格式 -->
    <select id="BdCustbankentity_list_or" resultMap="get-BdCustbankEntity-result"
            parameterType="com.hzya.frame.plugin.lets.entity.BdCustbankEntity">
        select
        <include refid="BdCustbankEntity_Base_Column_List"/>
        from bd_custbank
        <trim prefix="where" prefixOverrides="and">
            <if test="accaddr != null and accaddr != ''">or accaddr = #{accaddr}</if>
            <if test="accname != null and accname != ''">or accname = #{accname}</if>
            <if test="account != null and account != ''">or account = #{account}</if>
            <if test="defflag != null and defflag != ''">or defflag = #{defflag}</if>
            <if test="dr != null">or dr = #{dr}</if>
            <if test="memo != null and memo != ''">or memo = #{memo}</if>
            <if test="pkAccbank != null and pkAccbank != ''">or pk_accbank = #{pkAccbank}</if>
            <if test="pkCorp != null and pkCorp != ''">or pk_corp = #{pkCorp}</if>
            <if test="pkCubasdoc != null and pkCubasdoc != ''">or pk_cubasdoc = #{pkCubasdoc}</if>
            <if test="pkCurrtype != null and pkCurrtype != ''">or pk_currtype = #{pkCurrtype}</if>
            <if test="pkCustbank != null and pkCustbank != ''">or pk_custbank = #{pkCustbank}</if>
            <if test="ts != null and ts != ''">or ts = #{ts}</if>
            and sts='Y'
        </trim>
        <if test=" sort == null or sort == ''.toString()  ">order by sorts asc</if>
        <if test=" sort !='' and sort!=null and order !='' and order!=null ">order by ${sort} ${order}</if>
    </select>

    <!--新增所有列-->
    <insert id="entity_insert" parameterType="com.hzya.frame.plugin.lets.entity.BdCustbankEntity"
            keyProperty="pkCustbank" useGeneratedKeys="true">
        insert into bd_custbank(
        <trim suffix="" suffixOverrides=",">
            <if test="accaddr != null and accaddr != ''">accaddr ,</if>
            <if test="accname != null and accname != ''">accname ,</if>
            <if test="account != null and account != ''">account ,</if>
            <if test="defflag != null and defflag != ''">defflag ,</if>
            <if test="dr != null">dr ,</if>
            <if test="memo != null and memo != ''">memo ,</if>
            <if test="pkAccbank != null and pkAccbank != ''">pk_accbank ,</if>
            <if test="pkCorp != null and pkCorp != ''">pk_corp ,</if>
            <if test="pkCubasdoc != null and pkCubasdoc != ''">pk_cubasdoc ,</if>
            <if test="pkCurrtype != null and pkCurrtype != ''">pk_currtype ,</if>
            <if test="pkCustbank != null and pkCustbank != ''">pk_custbank ,</if>
            <if test="ts != null and ts != ''">ts ,</if>
            <if test="sorts == null ">sorts,</if>
            <if test="sts == null ">sts,</if>
        </trim>
        )values(
        <trim suffix="" suffixOverrides=",">
            <if test="accaddr != null and accaddr != ''">#{accaddr} ,</if>
            <if test="accname != null and accname != ''">#{accname} ,</if>
            <if test="account != null and account != ''">#{account} ,</if>
            <if test="defflag != null and defflag != ''">#{defflag} ,</if>
            <if test="dr != null">#{dr} ,</if>
            <if test="memo != null and memo != ''">#{memo} ,</if>
            <if test="pkAccbank != null and pkAccbank != ''">#{pkAccbank} ,</if>
            <if test="pkCorp != null and pkCorp != ''">#{pkCorp} ,</if>
            <if test="pkCubasdoc != null and pkCubasdoc != ''">#{pkCubasdoc} ,</if>
            <if test="pkCurrtype != null and pkCurrtype != ''">#{pkCurrtype} ,</if>
            <if test="pkCustbank != null and pkCustbank != ''">#{pkCustbank} ,</if>
            <if test="ts != null and ts != ''">#{ts} ,</if>
            <if test="sorts == null ">(select (max(IFNULL( a.sorts, 0 )) + 1) as sort from bd_custbank a WHERE a.sts =
                'Y' ),
            </if>
            <if test="sts == null ">'Y',</if>
        </trim>
        )
    </insert>
    <!-- 批量新增 -->
    <insert id="entityInsertBatch" keyProperty="pkCustbank" useGeneratedKeys="true">
        insert into bd_custbank(accaddr, accname, account, defflag, dr, memo, pk_accbank, pk_corp, pk_cubasdoc,
        pk_currtype, ts, sts)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.accaddr},#{entity.accname},#{entity.account},#{entity.defflag},#{entity.dr},#{entity.memo},#{entity.pkAccbank},#{entity.pkCorp},#{entity.pkCubasdoc},#{entity.pkCurrtype},#{entity.ts},
            'Y')
        </foreach>
    </insert>
    <!-- 批量新增或者修改-->
    <insert id="entityInsertOrUpdateBatch" keyProperty="pkCustbank" useGeneratedKeys="true">
        insert into bd_custbank(accaddr, accname, account, defflag, dr, memo, pk_accbank, pk_corp, pk_cubasdoc,
        pk_currtype, ts)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.accaddr},#{entity.accname},#{entity.account},#{entity.defflag},#{entity.dr},#{entity.memo},#{entity.pkAccbank},#{entity.pkCorp},#{entity.pkCubasdoc},#{entity.pkCurrtype},#{entity.ts})
        </foreach>
        on duplicate key update
        accaddr = values(accaddr),
        accname = values(accname),
        account = values(account),
        defflag = values(defflag),
        dr = values(dr),
        memo = values(memo),
        pk_accbank = values(pk_accbank),
        pk_corp = values(pk_corp),
        pk_cubasdoc = values(pk_cubasdoc),
        pk_currtype = values(pk_currtype),
        ts = values(ts)
    </insert>
    <!--通过主键修改方法-->
    <update id="entity_update" parameterType="com.hzya.frame.plugin.lets.entity.BdCustbankEntity">
        update bd_custbank set
        <trim suffix="" suffixOverrides=",">
            <if test="accaddr != null and accaddr != ''">accaddr = #{accaddr},</if>
            <if test="accname != null and accname != ''">accname = #{accname},</if>
            <if test="account != null and account != ''">account = #{account},</if>
            <if test="defflag != null and defflag != ''">defflag = #{defflag},</if>
            <if test="dr != null">dr = #{dr},</if>
            <if test="memo != null and memo != ''">memo = #{memo},</if>
            <if test="pkAccbank != null and pkAccbank != ''">pk_accbank = #{pkAccbank},</if>
            <if test="pkCorp != null and pkCorp != ''">pk_corp = #{pkCorp},</if>
            <if test="pkCubasdoc != null and pkCubasdoc != ''">pk_cubasdoc = #{pkCubasdoc},</if>
            <if test="pkCurrtype != null and pkCurrtype != ''">pk_currtype = #{pkCurrtype},</if>
            <if test="ts != null and ts != ''">ts = #{ts},</if>
        </trim>
        where pk_custbank = #{pkCustbank}
    </update>
    <!-- 逻辑删除 -->
    <update id="entity_logicDelete" parameterType="com.hzya.frame.plugin.lets.entity.BdCustbankEntity">
        update bd_custbank
        set sts= 'N',
            modify_time = #{modify_time},
            modify_user_id = #{modify_user_id}
        where pk_custbank = #{pkCustbank}
    </update>
    <!-- 多条件逻辑删除 -->
    <update id="entity_logicDelete_Multi_Condition" parameterType="com.hzya.frame.plugin.lets.entity.BdCustbankEntity">
        update bd_custbank set sts= 'N' ,modify_time = #{modify_time},modify_user_id = #{modify_user_id}
        <trim prefix="where" prefixOverrides="and">
            <if test="accaddr != null and accaddr != ''">and accaddr = #{accaddr}</if>
            <if test="accname != null and accname != ''">and accname = #{accname}</if>
            <if test="account != null and account != ''">and account = #{account}</if>
            <if test="defflag != null and defflag != ''">and defflag = #{defflag}</if>
            <if test="dr != null">and dr = #{dr}</if>
            <if test="memo != null and memo != ''">and memo = #{memo}</if>
            <if test="pkAccbank != null and pkAccbank != ''">and pk_accbank = #{pkAccbank}</if>
            <if test="pkCorp != null and pkCorp != ''">and pk_corp = #{pkCorp}</if>
            <if test="pkCubasdoc != null and pkCubasdoc != ''">and pk_cubasdoc = #{pkCubasdoc}</if>
            <if test="pkCurrtype != null and pkCurrtype != ''">and pk_currtype = #{pkCurrtype}</if>
            <if test="pkCustbank != null and pkCustbank != ''">and pk_custbank = #{pkCustbank}</if>
            <if test="ts != null and ts != ''">and ts = #{ts}</if>
            and sts='Y'
        </trim>
    </update>
    <!--通过主键删除-->
    <delete id="entity_delete">
        delete
        from bd_custbank
        where pk_custbank = #{pkCustbank}
    </delete>

</mapper>

