<?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.menuConfig.dao.impl.SysMenuConfigDaoImpl">

    <resultMap id="get-SysMenuConfigEntity-result" type="com.hzya.frame.sysnew.menuConfig.entity.SysMenuConfigEntity">
        <result property="id" column="id" jdbcType="VARCHAR"/>
        <result property="parentMenuId" column="parent_menu_id" jdbcType="VARCHAR"/>
        <result property="menuName" column="menu_name" jdbcType="VARCHAR"/>
        <result property="menuEnglishName" column="menu_english_name" jdbcType="VARCHAR"/>
        <result property="menuIcon" column="menu_icon" jdbcType="VARCHAR"/>
        <result property="formId" column="form_id" jdbcType="VARCHAR"/>
        <result property="route" column="route" jdbcType="VARCHAR"/>
        <result property="options" column="options" jdbcType="VARCHAR"/>
        <result property="menuPage" column="menu_page" jdbcType="VARCHAR"/>
        <result property="remark" column="remark" jdbcType="VARCHAR"/>
        <result property="visibles" column="visibles" jdbcType="VARCHAR"/>
        <result property="showType" column="show_type" 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"/>
        <result property="parentMenuName" column="parent_menu_name" jdbcType="VARCHAR"/>
    </resultMap>
    <!-- 查询的字段-->
    <sql id="SysMenuConfigEntity_Base_Column_List">
        id
       ,parent_menu_id 
        ,menu_name
        ,menu_english_name 
        ,menu_icon 
        ,form_id
        ,route
        ,options
        ,menu_page
        ,remark 
        ,visibles 
        ,show_type 
        ,sorts 
        ,create_user_id 
        ,create_time 
        ,modify_user_id 
        ,modify_time 
        ,sts 
        ,org_id 
        ,company_id 
     </sql>
    <!--通过ID获取数据 -->
    <select id="entity_get" resultMap="get-SysMenuConfigEntity-result">
        select
        a.id
       ,a.parent_menu_id
       ,p.menu_name as parent_menu_name
        ,a.menu_name
        ,a.menu_english_name
        ,a.menu_icon
        ,a.form_id
        ,a.route
        ,a.options
        ,a.menu_page
        ,a.remark
        ,a.visibles
        ,a.show_type
        ,a.sorts
        ,a.create_user_id
        ,a.create_time
        ,a.modify_user_id
        ,a.modify_time
        ,a.sts
        ,a.org_id
        ,a.company_id
        from sys_menu_config a
        LEFT JOIN sys_menu_config p on p.id =  a.parent_menu_id  and p.sts = 'Y'
        where a.id = #{ id } and a.sts='Y'
    </select>
    <!-- 查询 采用==查询 -->
    <select id="entity_list_base" resultMap="get-SysMenuConfigEntity-result"
            parameterType="com.hzya.frame.sysnew.menuConfig.entity.SysMenuConfigEntity">
        select
        <include refid="SysMenuConfigEntity_Base_Column_List"/>
        from sys_menu_config
        <trim prefix="where" prefixOverrides="and">
            <if test="id != null and id != ''">and id = #{id}</if>
            <if test="parentMenuId != null and parentMenuId != ''">and parent_menu_id = #{parentMenuId}</if>
            <if test="menuName != null and menuName != ''">and menu_name = #{menuName}</if>
            <if test="menuEnglishName != null and menuEnglishName != ''">and menu_english_name = #{menuEnglishName}</if>
            <if test="menuIcon != null and menuIcon != ''">and menu_icon = #{menuIcon}</if>
            <if test="formId != null and formId != ''">and form_id = #{formId}</if>
            <if test="route != null and route != ''">and route = #{route}</if>
            <if test="options != null and options != ''">and options = #{options}</if>
            <if test="menuPage != null and menuPage != ''">and menu_page = #{menuPage}</if>
            <if test="remark != null and remark != ''">and remark = #{remark}</if>
            <if test="visibles != null and visibles != ''">and visibles = #{visibles}</if>
            <if test="showType != null and showType != ''">and show_type = #{showType}</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.menuConfig.entity.SysMenuConfigEntity">
        select count(1) from sys_menu_config
        <trim prefix="where" prefixOverrides="and">
            <if test="id != null and id != ''">and id = #{id}</if>
            <if test="parentMenuId != null and parentMenuId != ''">and parent_menu_id = #{parentMenuId}</if>
            <if test="menuName != null and menuName != ''">and menu_name = #{menuName}</if>
            <if test="menuEnglishName != null and menuEnglishName != ''">and menu_english_name = #{menuEnglishName}</if>
            <if test="menuIcon != null and menuIcon != ''">and menu_icon = #{menuIcon}</if>
            <if test="formId != null and formId != ''">and form_id = #{formId}</if>
            <if test="route != null and route != ''">and route = #{route}</if>
            <if test="options != null and options != ''">and options = #{options}</if>
            <if test="menuPage != null and menuPage != ''">and menu_page = #{menuPage}</if>
            <if test="remark != null and remark != ''">and remark = #{remark}</if>
            <if test="visibles != null and visibles != ''">and visibles = #{visibles}</if>
            <if test="showType != null and showType != ''">and show_type = #{showType}</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-SysMenuConfigEntity-result"
            parameterType="com.hzya.frame.sysnew.menuConfig.entity.SysMenuConfigEntity">
        select
        <include refid="SysMenuConfigEntity_Base_Column_List"/>
        from sys_menu_config
        <trim prefix="where" prefixOverrides="and">
            <if test="id != null and id != ''">and id like concat('%',#{id},'%')</if>
            <if test="parentMenuId != null and parentMenuId != ''">and parent_menu_id like
                concat('%',#{parentMenuId},'%')
            </if>
            <if test="menuName != null and menuName != ''">and menu_name like concat('%',#{menuName},'%')</if>
            <if test="menuEnglishName != null and menuEnglishName != ''">and menu_english_name like
                concat('%',#{menuEnglishName},'%')
            </if>
            <if test="menuIcon != null and menuIcon != ''">and menu_icon like concat('%',#{menuIcon},'%')</if>
            <if test="formId != null and formId != ''">and form_id like concat('%',#{formId},'%')</if>
            <if test="route != null and route != ''">and route like concat('%',#{route},'%')</if>
            <if test="options != null and options != ''">and options like concat('%',#{options},'%')</if>
            <if test="menuPage != null and menuPage != ''">and menu_page like concat('%',#{menuPage},'%')</if>
            <if test="remark != null and remark != ''">and remark like concat('%',#{remark},'%')</if>
            <if test="visibles != null and visibles != ''">and visibles like concat('%',#{visibles},'%')</if>
            <if test="showType != null and showType != ''">and show_type like concat('%',#{showType},'%')</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="SysMenuConfigentity_list_or" resultMap="get-SysMenuConfigEntity-result"
            parameterType="com.hzya.frame.sysnew.menuConfig.entity.SysMenuConfigEntity">
        select
        <include refid="SysMenuConfigEntity_Base_Column_List"/>
        from sys_menu_config
        <trim prefix="where" prefixOverrides="and">
            <if test="id != null and id != ''">or id = #{id}</if>
            <if test="parentMenuId != null and parentMenuId != ''">or parent_menu_id = #{parentMenuId}</if>
            <if test="menuName != null and menuName != ''">or menu_name = #{menuName}</if>
            <if test="menuEnglishName != null and menuEnglishName != ''">or menu_english_name = #{menuEnglishName}</if>
            <if test="menuIcon != null and menuIcon != ''">or menu_icon = #{menuIcon}</if>
            <if test="formId != null and formId != ''">or form_id = #{formId}</if>
            <if test="route != null and route != ''">or route = #{route}</if>
            <if test="options != null and options != ''">or options = #{options}</if>
            <if test="menuPage != null and menuPage != ''">or menu_page = #{menuPage}</if>
            <if test="remark != null and remark != ''">or remark = #{remark}</if>
            <if test="visibles != null and visibles != ''">or visibles = #{visibles}</if>
            <if test="showType != null and showType != ''">or show_type = #{showType}</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.menuConfig.entity.SysMenuConfigEntity"
    >
        insert into sys_menu_config(
        <trim suffix="" suffixOverrides=",">
            <if test="id != null and id != ''">id ,</if>
            <if test="parentMenuId != null and parentMenuId != ''">parent_menu_id ,</if>
            <if test="menuName != null and menuName != ''">menu_name ,</if>
            <if test="menuEnglishName != null and menuEnglishName != ''">menu_english_name ,</if>
            <if test="menuIcon != null and menuIcon != ''">menu_icon ,</if>
            <if test="formId != null and formId != ''">form_id ,</if>
            <if test="route != null and route != ''">route ,</if>
            <if test="options != null and options != ''">options ,</if>
            <if test="menuPage != null and menuPage != ''">menu_page ,</if>
            <if test="remark != null and remark != ''">remark ,</if>
            <if test="visibles != null and visibles != ''">visibles ,</if>
            <if test="showType != null and showType != ''">show_type ,</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="parentMenuId != null and parentMenuId != ''">#{parentMenuId} ,</if>
            <if test="menuName != null and menuName != ''">#{menuName} ,</if>
            <if test="menuEnglishName != null and menuEnglishName != ''">#{menuEnglishName} ,</if>
            <if test="menuIcon != null and menuIcon != ''">#{menuIcon} ,</if>
            <if test="formId != null and formId != ''">#{formId} ,</if>
            <if test="route != null and route != ''">#{route} ,</if>
            <if test="options != null and options != ''">#{options} ,</if>
            <if test="menuPage != null and menuPage != ''">#{menuPage} ,</if>
            <if test="remark != null and remark != ''">#{remark} ,</if>
            <if test="visibles != null and visibles != ''">#{visibles} ,</if>
            <if test="showType != null and showType != ''">#{showType} ,</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_menu_config(parent_menu_id, menu_name, menu_english_name, menu_icon, form_id, route,options,
        menu_page, remark, visibles, show_type, 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.parentMenuId},#{entity.menuName},#{entity.menuEnglishName},#{entity.menuIcon},#{entity.formId},#{entity.route},#{entity.options},#{entity.menuPage},#{entity.remark},#{entity.visibles},#{entity.showType},#{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_menu_config(parent_menu_id, menu_name, menu_english_name, menu_icon,form_id, route,options,
        menu_page, remark, visibles, show_type, sorts, create_user_id, create_time, modify_user_id, modify_time, sts,
        org_id, company_id)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.parentMenuId},#{entity.menuName},#{entity.menuEnglishName},#{entity.menuIcon},#{entity.formId},#{entity.route},#{entity.options},#{entity.menuPage},#{entity.remark},#{entity.visibles},#{entity.showType},#{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
        parent_menu_id = values(parent_menu_id),
        menu_name = values(menu_name),
        menu_english_name = values(menu_english_name),
        menu_icon = values(menu_icon),
        form_id = values(form_id),
        route = values(route),
        options = values(options),
        menu_page = values(menu_page),
        remark = values(remark),
        visibles = values(visibles),
        show_type = values(show_type),
        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.menuConfig.entity.SysMenuConfigEntity">
        update sys_menu_config set
        <trim suffix="" suffixOverrides=",">
            <if test="parentMenuId != null and parentMenuId != ''">parent_menu_id = #{parentMenuId},</if>
            <if test="menuName != null and menuName != ''">menu_name = #{menuName},</if>
            <if test="menuEnglishName != null and menuEnglishName != ''">menu_english_name = #{menuEnglishName},</if>
            <if test="menuIcon != null and menuIcon != ''">menu_icon = #{menuIcon},</if>
            <if test="formId != null and formId != ''">form_id = #{formId},</if>
            <if test="route != null and route != ''">route = #{route},</if>
            <if test="options != null and options != ''">options = #{options},</if>
            <if test="menuPage != null and menuPage != ''">menu_page = #{menuPage},</if>
            <if test="remark != null and remark != ''">remark = #{remark},</if>
            <if test="visibles != null and visibles != ''">visibles = #{visibles},</if>
            <if test="showType != null and showType != ''">show_type = #{showType},</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.menuConfig.entity.SysMenuConfigEntity">
update sys_menu_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.menuConfig.entity.SysMenuConfigEntity">
        update sys_menu_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="parentMenuId != null and parentMenuId != ''">and parent_menu_id = #{parentMenuId}</if>
            <if test="menuName != null and menuName != ''">and menu_name = #{menuName}</if>
            <if test="menuEnglishName != null and menuEnglishName != ''">and menu_english_name = #{menuEnglishName}</if>
            <if test="menuIcon != null and menuIcon != ''">and menu_icon = #{menuIcon}</if>
            <if test="formId != null and formId != ''">and form_id = #{formId}</if>
            <if test="route != null and route != ''">and route = #{route}</if>
            <if test="options != null and options != ''">and options = #{options}</if>
            <if test="menuPage != null and menuPage != ''">and menu_page = #{menuPage}</if>
            <if test="remark != null and remark != ''">and remark = #{remark}</if>
            <if test="visibles != null and visibles != ''">and visibles = #{visibles}</if>
            <if test="showType != null and showType != ''">and show_type = #{showType}</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_menu_config where id = #{id}
</delete>
    <!-- 查询 采用==查询 -->
    <select id="queryUserMenu" resultMap="get-SysMenuConfigEntity-result"
            parameterType="com.hzya.frame.sysnew.menuConfig.entity.SysMenuConfigEntity">
        select
        <include refid="SysMenuConfigEntity_Base_Column_List"/>
        from sys_menu_config
        <trim prefix="where" prefixOverrides="and">
            <if test="id != null and id != ''">and id = #{id}</if>
            <if test="parentMenuId != null and parentMenuId != ''">and parent_menu_id = #{parentMenuId}</if>
            <if test="menuName != null and menuName != ''">and menu_name = #{menuName}</if>
            <if test="menuEnglishName != null and menuEnglishName != ''">and menu_english_name = #{menuEnglishName}</if>
            <if test="menuIcon != null and menuIcon != ''">and menu_icon = #{menuIcon}</if>
            <if test="formId != null and formId != ''">and form_id = #{formId}</if>
            <if test="route != null and route != ''">and route = #{route}</if>
            <if test="options != null and options != ''">and options = #{options}</if>
            <if test="menuPage != null and menuPage != ''">and menu_page = #{menuPage}</if>
            <if test="remark != null and remark != ''">and remark = #{remark}</if>
            <if test="visibles != null and visibles != ''">and visibles = #{visibles}</if>
            <if test="showType != null and showType != ''">and show_type = #{showType}</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>
            <if test="userId != null and userId != ''">
                and ( id in (
                SELECT
                menu_id from sys_popedom_menu WHERE object_id = #{userId} and kind_id = '1' and sts = 'Y'
                )
                OR
                id in (
                SELECT
                menu_id from sys_popedom_menu WHERE object_id in (SELECT
                role_id from sys_user_roles WHERE user_id = #{userId} and sts = 'Y') and kind_id = '2' and sts = 'Y'
                ) )
            </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>
</mapper>

