<?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.cms.mapper.CmsAppFieldMapper">

    <!-- 关联查询sql -->
    <sql id="selectSql">
        SELECT a.*, b.user_id
        FROM cms_app_field a
        LEFT JOIN cms_app b ON a.tenant_id = b.tenant_id
        <where>
            <if test="param.id != null">
                AND a.id = #{param.id}
            </if>
            <if test="param.type != null">
                AND a.type = #{param.type}
            </if>
            <if test="param.lang != null">
              AND a.lang = #{param.lang}
            </if>
            <if test="param.name != null">
                AND a.name LIKE CONCAT('%', #{param.name}, '%')
            </if>
            <if test="param.defaultValue != null">
                AND a.default_value LIKE CONCAT('%', #{param.defaultValue}, '%')
            </if>
            <if test="param.modifyRange != null">
                AND a.modify_range LIKE CONCAT('%', #{param.modifyRange}, '%')
            </if>
            <if test="param.comments != null">
                AND a.comments LIKE CONCAT('%', #{param.comments}, '%')
            </if>
            <if test="param.style != null">
                AND a.style LIKE CONCAT('%', #{param.style}, '%')
            </if>
            <if test="param.value != null">
                AND a.value LIKE CONCAT('%', #{param.value}, '%')
            </if>
            <if test="param.sortNumber != null">
                AND a.sort_number = #{param.sortNumber}
            </if>
            <if test="param.userId != null">
              AND b.user_id = #{param.userId}
            </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>
            <if test="param.keywords != null">
              AND (a.comments  LIKE CONCAT('%', #{param.keywords}, '%')
              OR a.value LIKE CONCAT('%', #{param.keywords}, '%')
              OR a.name LIKE CONCAT('%', #{param.keywords}, '%')
              )
            </if>
        </where>
    </sql>

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

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


    <select id="selectListAllRel" resultType="com.gxwebsoft.cms.entity.CmsAppField">
      <include refid="selectSql"></include>
    </select>



</mapper>
