<?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.gxwebsoft.common.system.mapper.PlugMapper">

    <!-- 关联查询sql -->
    <sql id="selectSql">
        SELECT a.*,b.tenant_name,c.company_name,c.short_name,c.domain
        FROM sys_plug a
        LEFT JOIN sys_tenant b ON a.tenant_id = b.tenant_id
        LEFT JOIN sys_company c ON a.tenant_id = c.tenant_id
        <where>
            <if test="param.plugId != null">
              AND a.plug_id = #{param.plugId}
            </if>
            <if test="param.menuId != null">
                AND a.menu_id = #{param.menuId}
            </if>
            <if test="param.parentId != null">
                AND a.parent_id = #{param.parentId}
            </if>
            <if test="param.title != null">
                AND a.title LIKE CONCAT('%', #{param.title}, '%')
            </if>
            <if test="param.path != null">
                AND a.path LIKE CONCAT('%', #{param.path}, '%')
            </if>
            <if test="param.component != null">
                AND a.component LIKE CONCAT('%', #{param.component}, '%')
            </if>
            <if test="param.menuType != null">
                AND a.menu_type = #{param.menuType}
            </if>
            <if test="param.sortNumber != null">
                AND a.sort_number = #{param.sortNumber}
            </if>
            <if test="param.authority != null">
                AND a.authority LIKE CONCAT('%', #{param.authority}, '%')
            </if>
            <if test="param.target != null">
                AND a.target LIKE CONCAT('%', #{param.target}, '%')
            </if>
            <if test="param.icon != null">
                AND a.icon LIKE CONCAT('%', #{param.icon}, '%')
            </if>
            <if test="param.color != null">
                AND a.color LIKE CONCAT('%', #{param.color}, '%')
            </if>
            <if test="param.hide != null">
                AND a.hide = #{param.hide}
            </if>
            <if test="param.active != null">
                AND a.active LIKE CONCAT('%', #{param.active}, '%')
            </if>
            <if test="param.meta != null">
                AND a.meta LIKE CONCAT('%', #{param.meta}, '%')
            </if>
            <if test="param.appId != null">
                AND a.app_id = #{param.appId}
            </if>
            <if test="param.userId != null">
              AND a.user_id = #{param.userId}
            </if>
            <if test="param.status != null">
              AND a.status = #{param.status}
            </if>
            <if test="param.deleted != null">
                AND a.deleted = #{param.deleted}
            </if>
            <if test="param.deleted == null">
                AND a.deleted = 0
            </if>
            <if test="param.merchantCode != null">
                AND a.merchant_code LIKE CONCAT('%', #{param.merchantCode}, '%')
            </if>
            <if test="param.createTimeStart != null">
                AND a.create_time &gt;= #{param.createTimeStart}
            </if>
            <if test="param.createTimeEnd != null">
                AND a.create_time &lt;= #{param.createTimeEnd}
            </if>
            <if test="param.keywords != null">
              AND (a.title LIKE CONCAT('%', #{param.keywords}, '%')
              OR a.menu_id = #{param.keywords}
              OR c.company_name LIKE CONCAT('%', #{param.keywords}, '%')
              OR c.short_name LIKE CONCAT('%', #{param.keywords}, '%')
              )
            </if>
        </where>
    </sql>

    <!-- 分页查询 -->
    <select id="selectPageRel" resultType="com.gxwebsoft.common.system.entity.Plug">
        <include refid="selectSql"></include>
    </select>

    <!-- 查询全部 -->
    <select id="selectListRel" resultType="com.gxwebsoft.common.system.entity.Plug">
        <include refid="selectSql"></include>
    </select>

    <select id="getMenuByClone" resultType="com.gxwebsoft.common.system.entity.Plug">
      <include refid="selectSql"></include>
    </select>

</mapper>
