<?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.brilliance.isc.mda.dao.AtpbchMapper">

    <resultMap id="BaseResultMap" type="com.brilliance.isc.bo.Atpbch">
            <result property="id"     column="id"     jdbcType="VARCHAR"/>
            <result property="branch" column="BRANCH" jdbcType="VARCHAR"/>
            <result property="frmtyp" column="FRMTYP" jdbcType="CHAR"/>
            <result property="inifrm" column="INIFRM" jdbcType="CHAR"/>
            <result property="flg" column="FLG" jdbcType="CHAR"/>
            <result property="negflg" column="NEGFLG" jdbcType="CHAR"/>
    </resultMap>

    <sql id="Base_Column_List">
        ID,BRANCH,FRMTYP,INIFRM,FLG,NEGFLG
    </sql>
    <select id="selectByBranchAndInifrm" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from atpbch
        where
        BRANCH = #{branch,jdbcType=VARCHAR}
        AND INIFRM = #{inifrm,jdbcType=VARCHAR}
    </select>
    <select id="selecDistinctByInifrm" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from atpbch
        where 1=1
         and INIFRM = #{inifrm,jdbcType=VARCHAR}
        limit 1
    </select>

    <select id="selectByPrimaryKey" resultMap="BaseResultMap">
        select
            <include refid="Base_Column_List" />
        from atpbch
        where id = #{id,jdbcType=VARCHAR}
    </select>

    <delete id="deleteByPrimaryKey">
        delete from atpbch
        where id = #{id,jdbcType=VARCHAR}
    </delete>

    <insert id="insert">
        insert into atpbch (<include refid="Base_Column_List" />)
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            #{id,jdbcType=VARCHAR},
            #{branch,jdbcType=VARCHAR},
            #{frmtyp,jdbcType=VARCHAR},
            #{inifrm,jdbcType=VARCHAR},
            #{flg,jdbcType=VARCHAR},
            #{negflg,jdbcType=VARCHAR},
        </trim>
    </insert>

    <insert id="insertSelective">
        insert into atpbch
        <trim prefix="(" suffix=")" suffixOverrides=",">

            <if test="branch != null">branch,</if>
            <if test="frmtyp != null">frmtyp,</if>
            <if test="inifrm != null">inifrm,</if>
            <if test="flg != null">flg,</if>
            <if test="negflg != null">negflg,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">

            <if test="branch != null">#{branch,jdbcType=VARCHAR}, </if>
            <if test="frmtyp != null">#{frmtyp,jdbcType=VARCHAR}, </if>
            <if test="inifrm != null">#{inifrm,jdbcType=VARCHAR}, </if>
            <if test="flg != null">#{flg,jdbcType=VARCHAR}, </if>
            <if test="negflg != null">#{negflg,jdbcType=VARCHAR}, </if>
        </trim>
    </insert>

    <update id="updateByPrimaryKeySelective">
        update atpbch
        <set>
            <if test="branch != null">branch = #{branch,jdbcType=VARCHAR},</if>
            <if test="frmtyp != null">frmtyp = #{frmtyp,jdbcType=VARCHAR},</if>
            <if test="inifrm != null">inifrm = #{inifrm,jdbcType=VARCHAR},</if>
            <if test="flg != null">flg = #{flg,jdbcType=VARCHAR},</if>
            <if test="negflg != null">negflg = #{negflg,jdbcType=VARCHAR},</if>
        </set>
        where id = #{id,jdbcType=VARCHAR}
    </update>

    <update id="updateByPrimaryKey">
        update atpbch
        <set>
            branch = #{branch,jdbcType=VARCHAR},
            frmtyp = #{frmtyp,jdbcType=VARCHAR},
            inifrm = #{inifrm,jdbcType=VARCHAR},
            flg = #{flg,jdbcType=VARCHAR},
            negflg = #{negflg,jdbcType=VARCHAR},
        </set>
        where id = #{id,jdbcType=VARCHAR}
    </update>

    <delete id="deleteByIds">
        delete from atpbch where id in
        <foreach item="item" index="index" collection="collection" open="(" separator="," close=")">
            #{item}
        </foreach>
    </delete>

    <update id="dyncUpdate">
        update atpbch
        <set>
            <if test="module.branch != null">branch = #{module.branch,jdbcType=VARCHAR},</if>
            <if test="module.frmtyp != null">frmtyp = #{module.frmtyp,jdbcType=VARCHAR},</if>
            <if test="module.inifrm != null">inifrm = #{module.inifrm,jdbcType=VARCHAR},</if>
            <if test="module.flg != null">flg = #{module.flg,jdbcType=VARCHAR},</if>
            <if test="module.negflg != null">negflg = #{module.negflg,jdbcType=VARCHAR},</if>
        </set>
        ${conditions}
    </update>

    <delete id="dyncDelete">
        ${sql}
    </delete>

    <select id="dyncRead" resultMap="BaseResultMap">
        ${sql}
    </select>

    <select id="atpbchSelectOne" resultMap="BaseResultMap">
        select id,branch,frmtyp,inifrm,flg,negflg
        from atpbch where frmtyp = #{frmtyp} and branch = #{branch}
    </select>

    <select id="listFuzzyByRecord" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from atpbch
        <where>
            <if test="branchList != null and branchList.size() !=0">
                branch in
                <foreach collection="branchList" item="item" index="index" open="(" close=")" separator=",">
                    #{item}
                </foreach>
            </if>
            <if test="frmtyp != null and frmtyp != ''">
                and frmtyp like concat(concat ('%',#{frmtyp}),'%')
            </if>
            <if test="inifrm != null and inifrm != ''">
                and inifrm = #{inifrm,jdbcType=VARCHAR}
            </if>
            <if test="negflg != null and negflg != ''">
                and negflg = #{negflg,jdbcType=VARCHAR}
            </if>
        </where>
    </select>

    <select id="selectByRecord" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from atpbch
        where
        branch = #{branch,jdbcType=VARCHAR}
        and frmtyp = #{frmtyp,jdbcType=VARCHAR}
        and inifrm = #{inifrm,jdbcType=VARCHAR}
    </select>

    
    <select id="selectByBo" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from atpbch
        <where>
        <if test="branch != null and branch != ''">
            and branch = #{branch,jdbcType=VARCHAR}
        </if>
        <if test="frmtyp != null and frmtyp != ''">
            and frmtyp = #{frmtyp,jdbcType=VARCHAR}
        </if>
        <if test="inifrm != null and inifrm != ''">
            and inifrm = #{inifrm,jdbcType=VARCHAR}
        </if>
        <if test="flg != null and flg != ''">
            and flg = #{flg,jdbcType=VARCHAR}
        </if>
        <if test="negflg != null and negflg != ''">
            and negflg = #{negflg,jdbcType=VARCHAR}
        </if>
        </where>
        limit 1
    </select>
    <select id="selectByFrmtypAndBranchAndFlg" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from atpbch
        where
        FRMTYP = #{frmtyp,jdbcType=VARCHAR}
        AND BRANCH = #{branch,jdbcType=VARCHAR}
        AND FLG = #{flg,jdbcType=VARCHAR}
    </select>
    <select id="selectAtpbchByBranchAndNegflg" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from atpbch
        where BRANCH = #{branch,jdbcType=VARCHAR}
        AND NEGFLG = #{negflg,jdbcType=VARCHAR}
    </select>
    <select id="selectAtpbchByFrmtypAndBranchAndFlg" resultType="com.brilliance.isc.bo.Atpbch">
        select
        <include refid="Base_Column_List"/>
        from atpbch
        where FRMTYP = #{frmtyp,jdbcType=VARCHAR}
        AND BRANCH = #{branch,jdbcType=VARCHAR}
        AND FLG = #{flg,jdbcType=VARCHAR}
        limit 1
    </select>
    <select id="selectOrderFrm" resultMap="BaseResultMap">
        select INIFRM  from atpbch a where branch = '3500'
    </select>
</mapper>