<?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.sysnew.buttonConfig.dao.impl.SysButtonConfigDaoImpl">

    <resultMap id="get-SysButtonConfigEntity-result" type="com.hzya.frame.sysnew.buttonConfig.entity.SysButtonConfigEntity" >
       <result property="id" column="id" jdbcType="VARCHAR"/>
           <result property="code" column="code" jdbcType="VARCHAR"/>
           <result property="nameCh" column="name_ch" jdbcType="VARCHAR"/>
           <result property="nameEn" column="name_en" jdbcType="VARCHAR"/>
           <result property="menuId" column="menu_id" jdbcType="VARCHAR"/>
           <result property="iconName" column="icon_name" jdbcType="VARCHAR"/>
           <result property="styles" column="styles" jdbcType="VARCHAR"/>
           <result property="btnFunction" column="btn_function" jdbcType="VARCHAR"/>
           <result property="remark" column="remark" jdbcType="VARCHAR"/>
           <result property="sorts" column="sorts" jdbcType="INTEGER"/>
           <result property="create_user_id" column="create_user_id" jdbcType="VARCHAR"/>
           <result property="create_time" column="create_time" jdbcType="TIMESTAMP"/>
           <result property="modify_user_id" column="modify_user_id" jdbcType="VARCHAR"/>
           <result property="modify_time" column="modify_time" jdbcType="TIMESTAMP"/>
           <result property="sts" column="sts" jdbcType="VARCHAR"/>
           <result property="org_id" column="org_id" jdbcType="VARCHAR"/>
           <result property="companyId" column="company_id" jdbcType="VARCHAR"/>
        </resultMap>
    <!-- 查询的字段-->
    <sql id = "SysButtonConfigEntity_Base_Column_List">
        id
       ,code 
        ,name_ch 
        ,name_en 
        ,menu_id 
        ,icon_name 
        ,styles 
        ,btn_function 
        ,remark 
        ,sorts 
        ,create_user_id 
        ,create_time 
        ,modify_user_id 
        ,modify_time 
        ,sts 
        ,org_id 
        ,company_id 
     </sql>
    <!--通过ID获取数据 -->
    <select id="entity_get" resultMap="get-SysButtonConfigEntity-result">
        select
        <include refid="SysButtonConfigEntity_Base_Column_List" />
        from sys_button_config where id = #{ id } and sts='Y'
    </select>
 <!-- 查询 采用==查询 -->
 <select id="entity_list_base" resultMap="get-SysButtonConfigEntity-result" parameterType = "com.hzya.frame.sysnew.buttonConfig.entity.SysButtonConfigEntity">
    select
    <include refid="SysButtonConfigEntity_Base_Column_List" />
    from sys_button_config
    <trim prefix="where" prefixOverrides="and"> 
        <if test="id != null and id != ''"> and id = #{id} </if>
            <if test="code != null and code != ''"> and code = #{code} </if>
            <if test="nameCh != null and nameCh != ''"> and name_ch = #{nameCh} </if>
            <if test="nameEn != null and nameEn != ''"> and name_en = #{nameEn} </if>
            <if test="menuId != null and menuId != ''"> and menu_id = #{menuId} </if>
            <if test="iconName != null and iconName != ''"> and icon_name = #{iconName} </if>
            <if test="styles != null and styles != ''"> and styles = #{styles} </if>
            <if test="btnFunction != null and btnFunction != ''"> and btn_function = #{btnFunction} </if>
            <if test="remark != null and remark != ''"> and remark = #{remark} </if>
            <if test="sorts != null"> and sorts = #{sorts} </if>
            <if test="create_user_id != null and create_user_id != ''"> and create_user_id = #{create_user_id} </if>
            <if test="create_time != null"> and create_time = #{create_time} </if>
            <if test="modify_user_id != null and modify_user_id != ''"> and modify_user_id = #{modify_user_id} </if>
            <if test="modify_time != null"> and modify_time = #{modify_time} </if>
            <if test="sts != null and sts != ''"> and sts = #{sts} </if>
            <if test="org_id != null and org_id != ''"> and org_id = #{org_id} </if>
            <if test="companyId != null and companyId != ''"> and company_id = #{companyId} </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.sysnew.buttonConfig.entity.SysButtonConfigEntity">
        select  count(1)   from sys_button_config
    <trim prefix="where" prefixOverrides="and"> 
        <if test="id != null and id != ''"> and id = #{id} </if>
            <if test="code != null and code != ''"> and code = #{code} </if>
            <if test="nameCh != null and nameCh != ''"> and name_ch = #{nameCh} </if>
            <if test="nameEn != null and nameEn != ''"> and name_en = #{nameEn} </if>
            <if test="menuId != null and menuId != ''"> and menu_id = #{menuId} </if>
            <if test="iconName != null and iconName != ''"> and icon_name = #{iconName} </if>
            <if test="styles != null and styles != ''"> and styles = #{styles} </if>
            <if test="btnFunction != null and btnFunction != ''"> and btn_function = #{btnFunction} </if>
            <if test="remark != null and remark != ''"> and remark = #{remark} </if>
            <if test="sorts != null"> and sorts = #{sorts} </if>
            <if test="create_user_id != null and create_user_id != ''"> and create_user_id = #{create_user_id} </if>
            <if test="create_time != null"> and create_time = #{create_time} </if>
            <if test="modify_user_id != null and modify_user_id != ''"> and modify_user_id = #{modify_user_id} </if>
            <if test="modify_time != null"> and modify_time = #{modify_time} </if>
            <if test="sts != null and sts != ''"> and sts = #{sts} </if>
            <if test="org_id != null and org_id != ''"> and org_id = #{org_id} </if>
            <if test="companyId != null and companyId != ''"> and company_id = #{companyId} </if>
            and sts='Y'
    </trim>
    </select>

    <!-- 分页查询列表 采用like格式 -->
<select id="entity_list_like" resultMap="get-SysButtonConfigEntity-result" parameterType = "com.hzya.frame.sysnew.buttonConfig.entity.SysButtonConfigEntity">
    select
    <include refid="SysButtonConfigEntity_Base_Column_List" />
    from sys_button_config
    <trim prefix="where" prefixOverrides="and"> 
        <if test="id != null and id != ''"> and id like concat('%',#{id},'%') </if>
            <if test="code != null and code != ''"> and code like concat('%',#{code},'%') </if>
            <if test="nameCh != null and nameCh != ''"> and name_ch like concat('%',#{nameCh},'%') </if>
            <if test="nameEn != null and nameEn != ''"> and name_en like concat('%',#{nameEn},'%') </if>
            <if test="menuId != null and menuId != ''"> and menu_id = #{menuId} </if>
            <if test="iconName != null and iconName != ''"> and icon_name like concat('%',#{iconName},'%') </if>
            <if test="styles != null and styles != ''"> and styles like concat('%',#{styles},'%') </if>
            <if test="btnFunction != null and btnFunction != ''"> and btn_function like concat('%',#{btnFunction},'%') </if>
            <if test="remark != null and remark != ''"> and remark like concat('%',#{remark},'%') </if>
            <if test="sorts != null"> and sorts like concat('%',#{sorts},'%') </if>
            <if test="create_user_id != null and create_user_id != ''"> and create_user_id like concat('%',#{create_user_id},'%') </if>
            <if test="create_time != null"> and create_time like concat('%',#{create_time},'%') </if>
            <if test="modify_user_id != null and modify_user_id != ''"> and modify_user_id like concat('%',#{modify_user_id},'%') </if>
            <if test="modify_time != null"> and modify_time like concat('%',#{modify_time},'%') </if>
            <if test="sts != null and sts != ''"> and sts like concat('%',#{sts},'%') </if>
            <if test="org_id != null and org_id != ''"> and org_id like concat('%',#{org_id},'%') </if>
            <if test="companyId != null and companyId != ''"> and company_id like concat('%',#{companyId},'%') </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="SysButtonConfigentity_list_or" resultMap="get-SysButtonConfigEntity-result" parameterType = "com.hzya.frame.sysnew.buttonConfig.entity.SysButtonConfigEntity">
    select
    <include refid="SysButtonConfigEntity_Base_Column_List" />
    from sys_button_config
    <trim prefix="where" prefixOverrides="and"> 
         <if test="id != null and id != ''"> or id = #{id} </if>
             <if test="code != null and code != ''"> or code = #{code} </if>
             <if test="nameCh != null and nameCh != ''"> or name_ch = #{nameCh} </if>
             <if test="nameEn != null and nameEn != ''"> or name_en = #{nameEn} </if>
             <if test="menuId != null and menuId != ''"> or menu_id = #{menuId} </if>
             <if test="iconName != null and iconName != ''"> or icon_name = #{iconName} </if>
             <if test="styles != null and styles != ''"> or styles = #{styles} </if>
             <if test="btnFunction != null and btnFunction != ''"> or btn_function = #{btnFunction} </if>
             <if test="remark != null and remark != ''"> or remark = #{remark} </if>
             <if test="sorts != null"> or sorts = #{sorts} </if>
             <if test="create_user_id != null and create_user_id != ''"> or create_user_id = #{create_user_id} </if>
              <if test="create_time != null"> or create_time = #{create_time} </if>
              <if test="modify_user_id != null and modify_user_id != ''"> or modify_user_id = #{modify_user_id} </if>
              <if test="modify_time != null"> or modify_time = #{modify_time} </if>
              <if test="sts != null and sts != ''"> or sts = #{sts} </if>
             <if test="org_id != null and org_id != ''"> or org_id = #{org_id} </if>
              <if test="companyId != null and companyId != ''"> or company_id = #{companyId} </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.sysnew.buttonConfig.entity.SysButtonConfigEntity"  >
    insert into sys_button_config(
  <trim suffix="" suffixOverrides=",">
       <if test="id != null and id != ''"> id , </if>
            <if test="code != null and code != ''"> code , </if>
            <if test="nameCh != null and nameCh != ''"> name_ch , </if>
            <if test="nameEn != null and nameEn != ''"> name_en , </if>
            <if test="menuId != null and menuId != ''"> menu_id , </if>
            <if test="iconName != null and iconName != ''"> icon_name , </if>
            <if test="styles != null and styles != ''"> styles , </if>
            <if test="btnFunction != null and btnFunction != ''"> btn_function , </if>
            <if test="remark != null and remark != ''"> remark , </if>
            <if test="sorts != null"> sorts , </if>
            <if test="create_user_id != null and create_user_id != ''"> create_user_id , </if>
            <if test="create_time != null"> create_time , </if>
            <if test="modify_user_id != null and modify_user_id != ''"> modify_user_id , </if>
            <if test="modify_time != null"> modify_time , </if>
            <if test="sts != null and sts != ''"> sts , </if>
            <if test="org_id != null and org_id != ''"> org_id , </if>
            <if test="companyId != null and companyId != ''"> company_id , </if>
    <if test="sts == null ">sts,</if>
  </trim>
  )values(
 <trim suffix="" suffixOverrides=",">
       <if test="id != null and id != ''"> #{id} ,</if>
            <if test="code != null and code != ''"> #{code} ,</if>
            <if test="nameCh != null and nameCh != ''"> #{nameCh} ,</if>
            <if test="nameEn != null and nameEn != ''"> #{nameEn} ,</if>
            <if test="menuId != null and menuId != ''"> #{menuId} ,</if>
            <if test="iconName != null and iconName != ''"> #{iconName} ,</if>
            <if test="styles != null and styles != ''"> #{styles} ,</if>
            <if test="btnFunction != null and btnFunction != ''"> #{btnFunction} ,</if>
            <if test="remark != null and remark != ''"> #{remark} ,</if>
            <if test="sorts != null"> #{sorts} ,</if>
            <if test="create_user_id != null and create_user_id != ''"> #{create_user_id} ,</if>
            <if test="create_time != null"> #{create_time} ,</if>
            <if test="modify_user_id != null and modify_user_id != ''"> #{modify_user_id} ,</if>
            <if test="modify_time != null"> #{modify_time} ,</if>
            <if test="sts != null and sts != ''"> #{sts} ,</if>
            <if test="org_id != null and org_id != ''"> #{org_id} ,</if>
            <if test="companyId != null and companyId != ''"> #{companyId} ,</if>
    <if test="sts == null ">'Y',</if>
  </trim>
  )  
</insert>
<!-- 批量新增 -->
<insert id="entityInsertBatch"  >
  insert into sys_button_config(code, name_ch, name_en, menu_id, icon_name, styles, btn_function, remark, sorts, create_user_id, create_time, modify_user_id, modify_time, sts, org_id, company_id,  sts) 
    values
    <foreach collection="entities" item="entity" separator=",">
    (#{entity.code},#{entity.nameCh},#{entity.nameEn},#{entity.menuId},#{entity.iconName},#{entity.styles},#{entity.btnFunction},#{entity.remark},#{entity.sorts},#{entity.create_user_id},#{entity.create_time},#{entity.modify_user_id},#{entity.modify_time},#{entity.sts},#{entity.org_id},#{entity.companyId}, 'Y')
    </foreach>
</insert>
<!-- 批量新增或者修改-->
<insert id="entityInsertOrUpdateBatch"  >
    insert into sys_button_config(code, name_ch, name_en, menu_id, icon_name, styles, btn_function, remark, sorts, create_user_id, create_time, modify_user_id, modify_time, sts, org_id, company_id)
    values
    <foreach collection="entities" item="entity" separator=",">
    (#{entity.code},#{entity.nameCh},#{entity.nameEn},#{entity.menuId},#{entity.iconName},#{entity.styles},#{entity.btnFunction},#{entity.remark},#{entity.sorts},#{entity.create_user_id},#{entity.create_time},#{entity.modify_user_id},#{entity.modify_time},#{entity.sts},#{entity.org_id},#{entity.companyId})
    </foreach>
    on duplicate key update
    code = values(code),
    name_ch = values(name_ch),
    name_en = values(name_en),
    menu_id = values(menu_id),
    icon_name = values(icon_name),
    styles = values(styles),
    btn_function = values(btn_function),
    remark = values(remark),
    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),
    company_id = values(company_id)</insert>
<!--通过主键修改方法-->
<update id="entity_update" parameterType = "com.hzya.frame.sysnew.buttonConfig.entity.SysButtonConfigEntity" >
update sys_button_config  set
<trim suffix="" suffixOverrides=",">
  <if test="code != null and code != ''"> code = #{code},</if>
  <if test="nameCh != null and nameCh != ''"> name_ch = #{nameCh},</if>
  <if test="nameEn != null and nameEn != ''"> name_en = #{nameEn},</if>
  <if test="menuId != null and menuId != ''"> menu_id = #{menuId},</if>
  <if test="iconName != null and iconName != ''"> icon_name = #{iconName},</if>
  <if test="styles != null and styles != ''"> styles = #{styles},</if>
  <if test="btnFunction != null and btnFunction != ''"> btn_function = #{btnFunction},</if>
  <if test="remark != null and remark != ''"> remark = #{remark},</if>
  <if test="sorts != null"> sorts = #{sorts},</if>
  <if test="create_user_id != null and create_user_id != ''"> create_user_id = #{create_user_id},</if>
    <if test="create_time != null"> create_time = #{create_time},</if>
    <if test="modify_user_id != null and modify_user_id != ''"> modify_user_id = #{modify_user_id},</if>
    <if test="modify_time != null"> modify_time = #{modify_time},</if>
    <if test="sts != null and sts != ''"> sts = #{sts},</if>
  <if test="org_id != null and org_id != ''"> org_id = #{org_id},</if>
    <if test="companyId != null and companyId != ''"> company_id = #{companyId},</if>
</trim>
where id = #{id}
</update>
<!-- 逻辑删除 -->
<update id="entity_logicDelete" parameterType = "com.hzya.frame.sysnew.buttonConfig.entity.SysButtonConfigEntity" >
update sys_button_config  set sts= 'N' ,modify_time = #{modify_time},modify_user_id = #{modify_user_id}
where id = #{id}
</update>
<!-- 多条件逻辑删除 -->
<update id="entity_logicDelete_Multi_Condition" parameterType = "com.hzya.frame.sysnew.buttonConfig.entity.SysButtonConfigEntity" >
update sys_button_config  set sts= 'N' ,modify_time = #{modify_time},modify_user_id = #{modify_user_id}
 <trim prefix="where" prefixOverrides="and"> 
        <if test="id != null and id != ''"> and id = #{id} </if>
            <if test="code != null and code != ''"> and code = #{code} </if>
            <if test="nameCh != null and nameCh != ''"> and name_ch = #{nameCh} </if>
            <if test="nameEn != null and nameEn != ''"> and name_en = #{nameEn} </if>
            <if test="menuId != null and menuId != ''"> and menu_id = #{menuId} </if>
            <if test="iconName != null and iconName != ''"> and icon_name = #{iconName} </if>
            <if test="styles != null and styles != ''"> and styles = #{styles} </if>
            <if test="btnFunction != null and btnFunction != ''"> and btn_function = #{btnFunction} </if>
            <if test="remark != null and remark != ''"> and remark = #{remark} </if>
            <if test="sorts != null"> and sorts = #{sorts} </if>
                                                                <if test="sts != null and sts != ''"> and sts = #{sts} </if>
                         <if test="companyId != null and companyId != ''"> and company_id = #{companyId} </if>
            and sts='Y'
    </trim>
</update>
<!--通过主键删除-->
<delete id="entity_delete">
    delete from sys_button_config where id = #{id}
</delete>
    <select id="getUserButton" resultMap="get-SysButtonConfigEntity-result" parameterType = "com.hzya.frame.sysnew.buttonConfig.entity.SysButtonConfigEntity">
SELECT
	*
FROM
	sys_button_config
WHERE
	(
		id IN (
		SELECT
			operate
		FROM
			sys_popedom_operate
		WHERE
						 menu_id = #{menuId}
		AND	object_id = #{userId}
			AND kind_id = '1'
			AND sts = 'Y'
		)
		OR id IN (
		SELECT
			operate
		FROM
			sys_popedom_operate
		WHERE
			object_id IN (
			SELECT
				role_id
			FROM
				sys_user_roles
			WHERE
				user_id = #{userId}
				AND sts = 'Y'
			)
				AND menu_id = #{menuId}
			AND kind_id = '2'
			AND sts = 'Y'
		))
	AND sts = 'Y'
order by sorts asc
    </select>
</mapper>

