<?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.ics.admin.mapper.SuggestionMapper">

    <resultMap type="com.ics.admin.domain.Suggestion" id="SuggestionResult">
        <result property="id" column="id"/>
        <result property="sn" column="sn"/>
        <result property="content" column="content"/>
        <result property="images" column="images" jdbcType="LONGVARCHAR"
                javaType="java.util.ArrayList" typeHandler="com.ics.admin.handler.BannerImageHandler"/>
        <result property="status" column="status"/>
        <result property="isAnonymous" column="is_anonymous"/>
        <result property="userId" column="user_id"/>
        <result property="createUserId" column="create_user_id"/>
        <result property="processingTime" column="processing_time"/>
        <result property="version" column="version"/>
        <result property="deleteFlag" column="delete_flag"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="tenantId" column="tenant_id"/>
        <result property="parkId" column="park_id"/>
        <association property="park" javaType="com.ics.admin.domain.Park" resultMap="ParkResult"/>
        <association property="user" javaType="com.ics.system.domain.User" resultMap="UserResult"/>
    </resultMap>

    <resultMap id="ParkResult" type="com.ics.admin.domain.Park">
        <id property="id" column="pid"/>
        <result property="name" column="pname"/>
    </resultMap>

    <resultMap id="UserResult" type="com.ics.system.domain.User">
        <id property="id" column="userId"/>
        <id property="username" column="username"/>
        <result property="mobile" column="mobile"/>
    </resultMap>

    <sql id="selectSuggestionVo">
        SELECT s.id,
               s.sn,
               s.content,
               s.images,
               s.STATUS,
               s.is_anonymous,
               s.VERSION,
               s.delete_flag,
               s.create_by,
               s.create_time,
               s.processing_time,
               s.update_by,
               s.update_time,
               s.tenant_id,
               s.park_id,
               s.create_user_id,
               ip.id   AS pid,
               ip.name AS pname,
               u.id    AS userId,
               u.username,
               u.mobile
        FROM ics_suggestion AS s
                 LEFT JOIN sys_user AS u ON s.user_id = u.id
                 LEFT JOIN ics_park AS ip ON ip.id = s.park_id
    </sql>

    <select id="selectSuggestionList" parameterType="Suggestion" resultMap="SuggestionResult">
        <include refid="selectSuggestionVo"/>
        <where>
            <if test="sn != null  and sn != ''">AND s.sn LIKE CONCAT('%', #{sn}, '%')</if>
            <if test="id != null  and id != ''">AND s.id = #{id}</if>
            <if test="createUserId != null  and createUserId != ''">AND s.create_user_id = #{createUserId}</if>
            <if test="status != null  and status != ''">AND s.status = #{status}</if>
            AND s.delete_flag = 0
        </where>
    </select>

    <select id="selectSuggestionById" parameterType="Long" resultMap="SuggestionResult">
        <include refid="selectSuggestionVo"/>
        WHERE s.id = #{id}
    </select>
</mapper>