<?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.love.mapper.UserPlanMapper">

    <!-- 关联查询sql -->
    <sql id="selectSql">
        SELECT a.*,b.role_name as roleName,c.name as gradeName
        FROM love_user_plan a
        LEFT JOIN sys_role b ON a.role_id = b.role_id
        LEFT JOIN shop_user_grade c ON a.grade_id = c.grade_id
        <where>
            <if test="param.planId != null">
                AND a.plan_id = #{param.planId}
            </if>
            <if test="param.type != null">
              AND a.type = #{param.type}
            </if>
            <if test="param.name != null">
                AND a.name LIKE CONCAT('%', #{param.name}, '%')
            </if>
            <if test="param.subName != null">
                AND a.sub_name LIKE CONCAT('%', #{param.subName}, '%')
            </if>
            <if test="param.roleId != null">
                AND a.role_id = #{param.roleId}
            </if>
            <if test="param.gradeId != null">
              AND a.grade_id = #{param.gradeId}
            </if>
            <if test="param.icon != null">
                AND a.icon LIKE CONCAT('%', #{param.icon}, '%')
            </if>
            <if test="param.sortNumber != null">
                AND a.sort_number = #{param.sortNumber}
            </if>
            <if test="param.comments != null">
                AND a.comments LIKE CONCAT('%', #{param.comments}, '%')
            </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.createTimeStart != null">
                AND a.create_time &gt;= #{param.createTimeStart}
            </if>
            <if test="param.createTimeEnd != null">
                AND a.create_time &lt;= #{param.createTimeEnd}
            </if>
        </where>
    </sql>

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

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

</mapper>
