<?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.BusbtnMapper">

    <resultMap id="BaseResultMap" type="com.brilliance.isc.bo.Busbtn">
            <id property="id" column="ID" jdbcType="BIGINT"/>
            <result property="bustyp" column="BUSTYP" jdbcType="CHAR"/>
            <result property="inifrm" column="INIFRM" jdbcType="CHAR"/>
            <result property="btnnam" column="BTNNAM" jdbcType="VARCHAR"/>
            <result property="isMain" column="IS_MAIN" jdbcType="CHAR"/>
            <result property="isShow" column="IS_SHOW" jdbcType="CHAR"/>
            <result property="sort" column="SORT" jdbcType="INTEGER"/>
    </resultMap>

    <sql id="Base_Column_List">
        ID,BUSTYP,INIFRM,
        BTNNAM,IS_MAIN,IS_SHOW,
        SORT
    </sql>
    <select id="selectByBustypAndIsShow" resultType="com.brilliance.isc.bo.Busbtn">
        select
            <include refid="Base_Column_List"/>
        from busbtn
        where BUSTYP = #{bustyp}
        and IS_SHOW = 'Y'
        order by SORT
    </select>

    <select id="selectByBustypAndIsShowAndBranch" resultType="com.brilliance.isc.bo.Busbtn">
        select
        b.bustyp bustyp,case when a.inifrm is null then b.inifrm else a.inifrm end  inifrm ,b.btnnam btnnam,b.IS_MAIN isMain,b.IS_SHOW isShow
        from busbtn b
        left join atpbch a on a.FRMTYP = b.INIFRM
        and a.branch = #{branch}
        and a.flg = 'X'
        where b.BUSTYP = #{bustyp}
        and b.IS_SHOW = 'Y'
        order by SORT
    </select>
    <select id="queryById" parameterType="long" resultType="com.brilliance.isc.bo.Busbtn">
        select
        <include refid="Base_Column_List"/>
        from busbtn
        where id = #{id}
    </select>
    <select id="queryAllByLimit" resultType="com.brilliance.isc.bo.Busbtn">
        select
        <include refid="Base_Column_List"/>
        from busbtn
        <where>
            <if test="bustyp != null and bustyp != ''">
               and bustyp = #{bustyp}
            </if>
            <if test="inifrm != null and inifrm != ''">
               and inifrm = #{inifrm}
            </if>
        </where>
        order by bustyp,sort
    </select>

    <insert id="insert">
        insert into busbtn(BUSTYP,INIFRM,BTNNAM,IS_MAIN,IS_SHOW,SORT)
        values(#{bustyp},#{inifrm},#{btnnam},#{isMain},#{isShow},#{sort})
    </insert>

    <update id="update">
        update busbtn
        <set>
            <if test="bustyp != null and bustyp != ''">
                bustyp = #{bustyp},
            </if>
            <if test="inifrm != null and inifrm != ''">
                inifrm = #{inifrm},
            </if>
            <if test="btnnam != null and btnnam != ''">
                btnnam = #{btnnam},
            </if>
            <if test="isMain != null and isMain != ''">
                is_main = #{isMain},
            </if>
            <if test="isShow != null and isShow != ''">
                is_show = #{isShow},
            </if>
            <if test="sort != null and sort != ''">
                sort = #{sort,jdbcType=INTEGER},
            </if>
        </set>
        where id = #{id,jdbcType=BIGINT}
    </update>

    <delete id="deleteById">
        delete from busbtn
        where id = #{id,jdbcType=BIGINT}
    </delete>
</mapper>