<?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.app.mapper.AppEventMapper">

    <!-- 关联查询sql -->
    <sql id="selectSql">
        SELECT a.*, w.website_name, w.website_code, w.website_icon
        FROM app_event a
        LEFT JOIN cms_website w ON a.website_id = w.website_id AND w.deleted = 0
        <where>
            <if test="param.id != null">
                AND a.id = #{param.id}
            </if>
            <if test="param.websiteId != null">
                AND a.website_id = #{param.websiteId}
            </if>
            <if test="param.eventType != null and param.eventType != ''">
                AND a.event_type = #{param.eventType}
            </if>
            <if test="param.title != null and param.title != ''">
                AND a.title LIKE CONCAT('%', #{param.title}, '%')
            </if>
            <if test="param.operatorId != null">
                AND a.operator_id = #{param.operatorId}
            </if>
            <if test="param.refId != null">
                AND a.ref_id = #{param.refId}
            </if>
            <if test="param.refType != null and param.refType != ''">
                AND a.ref_type = #{param.refType}
            </if>
            <if test="param.status != null">
                AND a.status = #{param.status}
            </if>
            <if test="param.userId != null">
                AND a.user_id = #{param.userId}
            </if>
            <if test="param.tenantId != null">
                AND a.tenant_id = #{param.tenantId}
            </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 param.keywords != ''">
                AND (a.title LIKE CONCAT('%', #{param.keywords}, '%')
                  OR a.content LIKE CONCAT('%', #{param.keywords}, '%')
                )
            </if>
        </where>
        ORDER BY a.create_time DESC
    </sql>

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

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

</mapper>
