<?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.userTemplateButton.dao.impl.SysUserTemplateButtonDaoImpl">

    <resultMap id="get-SysUserTemplateButtonEntity-result" type="com.hzya.frame.sys.userTemplateButton.entity.SysUserTemplateButtonEntity" >
        <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="buttonId" column="button_id" jdbcType="VARCHAR"/>
        <result property="userId" column="user_id" 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 = "SysUserTemplateButtonEntity_Base_Column_List">
        id
       ,template_id 
        ,service_name 
        ,button_id 
        ,user_id 
        ,sorts 
        ,create_user_id 
        ,create_time 
        ,modify_user_id 
        ,modify_time 
        ,sts 
        ,org_id 
     </sql>
 <!-- 查询 采用==查询 -->
 <select id="entity_list_base" resultMap="get-SysUserTemplateButtonEntity-result" parameterType = "com.hzya.frame.sys.userTemplateButton.entity.SysUserTemplateButtonEntity">
    select
    <include refid="SysUserTemplateButtonEntity_Base_Column_List" />
    from sys_user_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="buttonId != null and buttonId != ''"> and button_id = #{buttonId} </if>
        <if test="userId != null and userId != ''"> and user_id = #{userId} </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 == 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.userTemplateButton.entity.SysUserTemplateButtonEntity">
        select  count(1)   from sys_user_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="buttonId != null and buttonId != ''"> and button_id = #{buttonId} </if>
        <if test="userId != null and userId != ''"> and user_id = #{userId} </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-SysUserTemplateButtonEntity-result" parameterType = "com.hzya.frame.sys.userTemplateButton.entity.SysUserTemplateButtonEntity">
    select
    <include refid="SysUserTemplateButtonEntity_Base_Column_List" />
    from sys_user_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="buttonId != null and buttonId != ''"> and button_id like concat('%',#{buttonId},'%') </if>
        <if test="userId != null and userId != ''"> and user_id like concat('%',#{userId},'%') </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-SysUserTemplateButtonEntity-result" parameterType = "com.hzya.frame.sys.userTemplateButton.entity.SysUserTemplateButtonEntity">
    select
    <include refid="SysUserTemplateButtonEntity_Base_Column_List" />
    from sys_user_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="buttonId != null and buttonId != ''"> or button_id = #{buttonId} </if>
        <if test="userId != null and userId != ''"> or user_id = #{userId} </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.userTemplateButton.entity.SysUserTemplateButtonEntity" keyProperty="id" useGeneratedKeys="true">
    insert into sys_user_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="buttonId != null and buttonId != ''"> button_id , </if>
        <if test="userId != null and userId != ''"> user_id , </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="sorts == null ">sorts,</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="buttonId != null and buttonId != ''"> #{buttonId} ,</if>
        <if test="userId != null and userId != ''"> #{userId} ,</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="sorts == null ">(select (max(IFNULL( a.sorts, 0 )) + 1) as sort from sys_user_template_button a WHERE a.sts = 'Y' ),</if>
     <if test="sts == null ">'Y',</if>
 </trim>
  )  
</insert>
<!-- 批量新增 -->
<insert id="SysUserTemplateButtonEntityInsertBatch" keyProperty="id" useGeneratedKeys="true">
  insert into sys_user_template_button(template_id, service_name, button_id, user_id, 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.buttonId},#{entity.userId},#{entity.sorts},#{entity.createUserId},#{entity.createTime},#{entity.modifyUserId},#{entity.modifyTime},#{entity.sts},#{entity.orgId}, 'Y')
    </foreach>
</insert>
<!-- 批量新增或者修改-->
<insert id="SysUserTemplateButtonEntityInsertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
    insert into sys_user_template_button(template_id, service_name, button_id, user_id, 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.buttonId}, #{entity.userId}, #{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),
    button_id = values(button_id),
    user_id = values(user_id),
    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.userTemplateButton.entity.SysUserTemplateButtonEntity" >
update sys_user_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="buttonId != null and buttonId != ''"> button_id = #{buttonId},</if>
    <if test="userId != null and userId != ''"> user_id = #{userId},</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.userTemplateButton.entity.SysUserTemplateButtonEntity" >
update sys_user_template_button  set sts= 'N'
where id = #{id}
</update>
<!-- 多条件逻辑删除 -->
<update id="entity_logicDelete_Multi_Condition" parameterType = "com.hzya.frame.sys.userTemplateButton.entity.SysUserTemplateButtonEntity" >
update sys_user_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="buttonId != null and buttonId != ''"> or button_id = #{buttonId} </if>
        <if test="userId != null and userId != ''"> or user_id = #{userId} </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_user_template_button where id = #{id}
</delete>

</mapper>

