<?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.sys.templateButton.dao.impl.SysTemplateButtonDaoImpl">

    <resultMap id="get-SysTemplateButtonEntity-result"
               type="com.hzya.frame.sys.templateButton.entity.SysTemplateButtonEntity">
        <result property="id" column="id" jdbcType="VARCHAR"/>
        <result property="templateId" column="template_id" jdbcType="VARCHAR"/>
        <result property="serviceName" column="service_name" jdbcType="VARCHAR"/>
        <result property="tableName" column="table_name" jdbcType="VARCHAR"/>
        <result property="buttonType" column="button_type" jdbcType="VARCHAR"/>
        <result property="buttonTitle" column="button_title" jdbcType="VARCHAR"/>
        <result property="buttonStyle" column="button_style" jdbcType="VARCHAR"/>
        <result property="buttonSort" column="button_sort" jdbcType="VARCHAR"/>
        <result property="buttonIcon" column="button_icon" jdbcType="VARCHAR"/>
        <result property="sorts" column="sorts" jdbcType="INTEGER"/>
        <result property="createUserId" column="create_user_id" jdbcType="VARCHAR"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
        <result property="modifyUserId" column="modify_user_id" jdbcType="VARCHAR"/>
        <result property="modifyTime" column="modify_time" jdbcType="TIMESTAMP"/>
        <result property="sts" column="sts" jdbcType="VARCHAR"/>
        <result property="orgId" column="org_id" jdbcType="VARCHAR"/>
    </resultMap>
    <!-- 查询的字段-->
    <sql id="SysTemplateButtonEntity_Base_Column_List">
        id
       ,template_id 
        ,service_name 
        ,table_name 
        ,button_type 
        ,button_title 
        ,button_style 
        ,button_sort 
        ,button_icon 
        ,sorts 
        ,create_user_id 
        ,create_time 
        ,modify_user_id 
        ,modify_time 
        ,sts 
        ,org_id 
     </sql>
    <!-- 查询 采用==查询 -->
    <select id="entity_list_base" resultMap="get-SysTemplateButtonEntity-result"
            parameterType="com.hzya.frame.sys.templateButton.entity.SysTemplateButtonEntity">
        select
        <include refid="SysTemplateButtonEntity_Base_Column_List"/>
        from sys_template_button
        <trim prefix="where" prefixOverrides="and">
            <if test="id != null and id != ''">and id = #{id}</if>
            <if test="templateId != null and templateId != ''">and template_id = #{templateId}</if>
            <if test="serviceName != null and serviceName != ''">and service_name = #{serviceName}</if>
            <if test="tableName != null and tableName != ''">and table_name = #{tableName}</if>
            <if test="buttonType != null and buttonType != ''">and button_type = #{buttonType}</if>
            <if test="buttonTitle != null and buttonTitle != ''">and button_title = #{buttonTitle}</if>
            <if test="buttonStyle != null and buttonStyle != ''">and button_style = #{buttonStyle}</if>
            <if test="buttonSort != null and buttonSort != ''">and button_sort = #{buttonSort}</if>
            <if test="buttonIcon != null and buttonIcon != ''">and button_icon = #{buttonIcon}</if>
            <if test="sorts != null">and sorts = #{sorts}</if>
            <if test="createUserId != null and createUserId != ''">and create_user_id = #{createUserId}</if>
            <if test="createTime != null">and create_time = #{createTime}</if>
            <if test="modifyUserId != null and modifyUserId != ''">and modify_user_id = #{modifyUserId}</if>
            <if test="modifyTime != null">and modify_time = #{modifyTime}</if>
            <if test="sts != null and sts != ''">and sts = #{sts}</if>
            <if test="orgId != null and orgId != ''">and org_id = #{orgId}</if>
            <if test="sysUserTemplateButtonEntities != null and sysUserTemplateButtonEntities.size>0">
                AND id in
                <foreach collection="sysUserTemplateButtonEntities" item="item" index="index" open="(" close=")" separator=",">
                    #{item.buttonId}
                </foreach>
            </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.sys.templateButton.entity.SysTemplateButtonEntity">
        select count(1) from sys_template_button
        <trim prefix="where" prefixOverrides="and">
            <if test="id != null and id != ''">and id = #{id}</if>
            <if test="templateId != null and templateId != ''">and template_id = #{templateId}</if>
            <if test="serviceName != null and serviceName != ''">and service_name = #{serviceName}</if>
            <if test="tableName != null and tableName != ''">and table_name = #{tableName}</if>
            <if test="buttonType != null and buttonType != ''">and button_type = #{buttonType}</if>
            <if test="buttonTitle != null and buttonTitle != ''">and button_title = #{buttonTitle}</if>
            <if test="buttonStyle != null and buttonStyle != ''">and button_style = #{buttonStyle}</if>
            <if test="buttonSort != null and buttonSort != ''">and button_sort = #{buttonSort}</if>
            <if test="buttonIcon != null and buttonIcon != ''">and button_icon = #{buttonIcon}</if>
            <if test="sorts != null">and sorts = #{sorts}</if>
            <if test="createUserId != null and createUserId != ''">and create_user_id = #{createUserId}</if>
            <if test="createTime != null">and create_time = #{createTime}</if>
            <if test="modifyUserId != null and modifyUserId != ''">and modify_user_id = #{modifyUserId}</if>
            <if test="modifyTime != null">and modify_time = #{modifyTime}</if>
            <if test="sts != null and sts != ''">and sts = #{sts}</if>
            <if test="orgId != null and orgId != ''">and org_id = #{orgId}</if>
            and sts='Y'
        </trim>
        <if test=" 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-SysTemplateButtonEntity-result"
            parameterType="com.hzya.frame.sys.templateButton.entity.SysTemplateButtonEntity">
        select
        <include refid="SysTemplateButtonEntity_Base_Column_List"/>
        from sys_template_button
        <trim prefix="where" prefixOverrides="and">
            <if test="id != null and id != ''">and id like concat('%',#{id},'%')</if>
            <if test="templateId != null and templateId != ''">and template_id like concat('%',#{templateId},'%')</if>
            <if test="serviceName != null and serviceName != ''">and service_name like concat('%',#{serviceName},'%')
            </if>
            <if test="tableName != null and tableName != ''">and table_name like concat('%',#{tableName},'%')</if>
            <if test="buttonType != null and buttonType != ''">and button_type like concat('%',#{buttonType},'%')</if>
            <if test="buttonTitle != null and buttonTitle != ''">and button_title like concat('%',#{buttonTitle},'%')
            </if>
            <if test="buttonStyle != null and buttonStyle != ''">and button_style like concat('%',#{buttonStyle},'%')
            </if>
            <if test="buttonSort != null and buttonSort != ''">and button_sort like concat('%',#{buttonSort},'%')</if>
            <if test="buttonIcon != null and buttonIcon != ''">and button_icon like concat('%',#{buttonIcon},'%')</if>
            <if test="sorts != null">and sorts like concat('%',#{sorts},'%')</if>
            <if test="createUserId != null and createUserId != ''">and create_user_id like
                concat('%',#{createUserId},'%')
            </if>
            <if test="createTime != null">and create_time like concat('%',#{createTime},'%')</if>
            <if test="modifyUserId != null and modifyUserId != ''">and modify_user_id like
                concat('%',#{modifyUserId},'%')
            </if>
            <if test="modifyTime != null">and modify_time like concat('%',#{modifyTime},'%')</if>
            <if test="sts != null and sts != ''">and sts like concat('%',#{sts},'%')</if>
            <if test="orgId != null and orgId != ''">and org_id like concat('%',#{orgId},'%')</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="entity_list_or" resultMap="get-SysTemplateButtonEntity-result"
            parameterType="com.hzya.frame.sys.templateButton.entity.SysTemplateButtonEntity">
        select
        <include refid="SysTemplateButtonEntity_Base_Column_List"/>
        from sys_template_button
        <trim prefix="where" prefixOverrides="and">
            <if test="id != null and id != ''">or id = #{id}</if>
            <if test="templateId != null and templateId != ''">or template_id = #{templateId}</if>
            <if test="serviceName != null and serviceName != ''">or service_name = #{serviceName}</if>
            <if test="tableName != null and tableName != ''">or table_name = #{tableName}</if>
            <if test="buttonType != null and buttonType != ''">or button_type = #{buttonType}</if>
            <if test="buttonTitle != null and buttonTitle != ''">or button_title = #{buttonTitle}</if>
            <if test="buttonStyle != null and buttonStyle != ''">or button_style = #{buttonStyle}</if>
            <if test="buttonSort != null and buttonSort != ''">or button_sort = #{buttonSort}</if>
            <if test="buttonIcon != null and buttonIcon != ''">or button_icon = #{buttonIcon}</if>
            <if test="sorts != null">or sorts = #{sorts}</if>
            <if test="createUserId != null and createUserId != ''">or create_user_id = #{createUserId}</if>
            <if test="createTime != null">or create_time = #{createTime}</if>
            <if test="modifyUserId != null and modifyUserId != ''">or modify_user_id = #{modifyUserId}</if>
            <if test="modifyTime != null">or modify_time = #{modifyTime}</if>
            <if test="sts != null and sts != ''">or sts = #{sts}</if>
            <if test="orgId != null and orgId != ''">or org_id = #{orgId}</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.sys.templateButton.entity.SysTemplateButtonEntity"
           >
        insert into sys_template_button(
        <trim suffix="" suffixOverrides=",">
            <if test="id != null and id != ''">id ,</if>
            <if test="templateId != null and templateId != ''">template_id ,</if>
            <if test="serviceName != null and serviceName != ''">service_name ,</if>
            <if test="tableName != null and tableName != ''">table_name ,</if>
            <if test="buttonType != null and buttonType != ''">button_type ,</if>
            <if test="buttonTitle != null and buttonTitle != ''">button_title ,</if>
            <if test="buttonStyle != null and buttonStyle != ''">button_style ,</if>
            <if test="buttonSort != null and buttonSort != ''">button_sort ,</if>
            <if test="buttonIcon != null and buttonIcon != ''">button_icon ,</if>
            <if test="sorts != null">sorts ,</if>
            <if test="createUserId != null and createUserId != ''">create_user_id ,</if>
            <if test="createTime != null">create_time ,</if>
            <if test="modifyUserId != null and modifyUserId != ''">modify_user_id ,</if>
            <if test="modifyTime != null">modify_time ,</if>
            <if test="sts != null and sts != ''">sts ,</if>
            <if test="orgId != null and orgId != ''">org_id ,</if>
            <if test="sts == null ">sts,</if>
        </trim>
        )values(
        <trim suffix="" suffixOverrides=",">
            <if test="id != null and id != ''">#{id} ,</if>
            <if test="templateId != null and templateId != ''">#{templateId} ,</if>
            <if test="serviceName != null and serviceName != ''">#{serviceName} ,</if>
            <if test="tableName != null and tableName != ''">#{tableName} ,</if>
            <if test="buttonType != null and buttonType != ''">#{buttonType} ,</if>
            <if test="buttonTitle != null and buttonTitle != ''">#{buttonTitle} ,</if>
            <if test="buttonStyle != null and buttonStyle != ''">#{buttonStyle} ,</if>
            <if test="buttonSort != null and buttonSort != ''">#{buttonSort} ,</if>
            <if test="buttonIcon != null and buttonIcon != ''">#{buttonIcon} ,</if>
            <if test="sorts != null">#{sorts} ,</if>
            <if test="createUserId != null and createUserId != ''">#{createUserId} ,</if>
            <if test="createTime != null">#{createTime} ,</if>
            <if test="modifyUserId != null and modifyUserId != ''">#{modifyUserId} ,</if>
            <if test="modifyTime != null">#{modifyTime} ,</if>
            <if test="sts != null and sts != ''">#{sts} ,</if>
            <if test="orgId != null and orgId != ''">#{orgId} ,</if>

            <if test="sts == null ">'Y',</if>
        </trim>
        )
    </insert>
    <!-- 批量新增 -->
    <insert id="SysTemplateButtonEntityInsertBatch" >
        insert into sys_template_button(template_id, service_name, table_name, button_type, button_title, button_style,
        button_sort, button_icon, sorts, create_user_id, create_time, modify_user_id, modify_time, sts, org_id, sts)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.templateId},#{entity.serviceName},#{entity.tableName},#{entity.buttonType},#{entity.buttonTitle},#{entity.buttonStyle},#{entity.buttonSort},#{entity.buttonIcon},#{entity.sorts},#{entity.createUserId},#{entity.createTime},#{entity.modifyUserId},#{entity.modifyTime},#{entity.sts},#{entity.orgId},
            'Y')
        </foreach>
    </insert>
    <!-- 批量新增或者修改-->
    <insert id="SysTemplateButtonEntityInsertOrUpdateBatch" >
        insert into sys_template_button(template_id, service_name, table_name, button_type, button_title, button_style,
        button_sort, button_icon, sorts, create_user_id, create_time, modify_user_id, modify_time, sts, org_id)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.templateId}, #{entity.serviceName}, #{entity.tableName}, #{entity.buttonType},
            #{entity.buttonTitle}, #{entity.buttonStyle}, #{entity.buttonSort}, #{entity.buttonIcon}, #{entity.sorts},
            #{entity.createUserId}, #{entity.createTime}, #{entity.modifyUserId}, #{entity.modifyTime}, #{entity.sts},
            #{entity.orgId})
        </foreach>
        on duplicate key update
        template_id = values(template_id),
        service_name = values(service_name),
        table_name = values(table_name),
        button_type = values(button_type),
        button_title = values(button_title),
        button_style = values(button_style),
        button_sort = values(button_sort),
        button_icon = values(button_icon),
        sorts = values(sorts),
        create_user_id = values(create_user_id),
        create_time = values(create_time),
        modify_user_id = values(modify_user_id),
        modify_time = values(modify_time),
        sts = values(sts),
        org_id = values(org_id)
    </insert>
    <!--通过主键修改方法-->
    <update id="entity_update"
            parameterType="com.hzya.frame.sys.templateButton.entity.SysTemplateButtonEntity">
        update sys_template_button set
        <trim suffix="" suffixOverrides=",">
            <if test="templateId != null and templateId != ''">template_id = #{templateId},</if>
            <if test="serviceName != null and serviceName != ''">service_name = #{serviceName},</if>
            <if test="tableName != null and tableName != ''">table_name = #{tableName},</if>
            <if test="buttonType != null and buttonType != ''">button_type = #{buttonType},</if>
            <if test="buttonTitle != null and buttonTitle != ''">button_title = #{buttonTitle},</if>
            <if test="buttonStyle != null and buttonStyle != ''">button_style = #{buttonStyle},</if>
            <if test="buttonSort != null and buttonSort != ''">button_sort = #{buttonSort},</if>
            <if test="buttonIcon != null and buttonIcon != ''">button_icon = #{buttonIcon},</if>
            <if test="sorts != null">sorts = #{sorts},</if>
            <if test="createUserId != null and createUserId != ''">create_user_id = #{createUserId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="modifyUserId != null and modifyUserId != ''">modify_user_id = #{modifyUserId},</if>
            <if test="modifyTime != null">modify_time = #{modifyTime},</if>
            <if test="sts != null and sts != ''">sts = #{sts},</if>
            <if test="orgId != null and orgId != ''">org_id = #{orgId},</if>
        </trim>
        where id = #{id}
    </update>
    <!-- 逻辑删除 -->
    <update id="entity_logicDelete"
            parameterType="com.hzya.frame.sys.templateButton.entity.SysTemplateButtonEntity">
update sys_template_button  set sts= 'N'
where id = #{id}
</update>
    <!-- 多条件逻辑删除 -->
    <update id="entity_logicDelete_Multi_Condition"
            parameterType="com.hzya.frame.sys.templateButton.entity.SysTemplateButtonEntity">
        update sys_template_button set sts= 'N'
        <trim prefix="where" prefixOverrides="or">
            <if test="id != null and id != ''">or id = #{id}</if>
            <if test="templateId != null and templateId != ''">or template_id = #{templateId}</if>
            <if test="serviceName != null and serviceName != ''">or service_name = #{serviceName}</if>
            <if test="tableName != null and tableName != ''">or table_name = #{tableName}</if>
            <if test="buttonType != null and buttonType != ''">or button_type = #{buttonType}</if>
            <if test="buttonTitle != null and buttonTitle != ''">or button_title = #{buttonTitle}</if>
            <if test="buttonStyle != null and buttonStyle != ''">or button_style = #{buttonStyle}</if>
            <if test="buttonSort != null and buttonSort != ''">or button_sort = #{buttonSort}</if>
            <if test="buttonIcon != null and buttonIcon != ''">or button_icon = #{buttonIcon}</if>
            <if test="sorts != null">or sorts = #{sorts}</if>
            <if test="createUserId != null and createUserId != ''">or create_user_id = #{createUserId}</if>
            <if test="createTime != null">or create_time = #{createTime}</if>
            <if test="modifyUserId != null and modifyUserId != ''">or modify_user_id = #{modifyUserId}</if>
            <if test="modifyTime != null">or modify_time = #{modifyTime}</if>
            <if test="sts != null and sts != ''">or sts = #{sts}</if>
            <if test="orgId != null and orgId != ''">or org_id = #{orgId}</if>
            and sts='Y'
        </trim>
    </update>
    <!--通过主键删除-->
    <delete id="deleteById">
    delete from sys_template_button where id = #{id}
</delete>

</mapper>

