<?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.yonge.cooleshow.biz.dal.mapper.SysSuggestionV2Mapper">

	<resultMap id="BaseResultMap" type="com.yonge.cooleshow.biz.dal.entity.SysSuggestionV2">
        <result column="id_" property="id" />
        <result column="suggestion_type_id_" property="suggestionTypeId" />
        <result column="mobile_no_" property="mobileNo" />
        <result column="type_" property="type" />
        <result column="title_" property="title" />
        <result column="content_" property="content" />
        <result column="attachment_urls_" property="attachmentUrls" />
        <result column="user_id_" property="userId" />
        <result column="client_type_" property="clientType" />
        <result column="user_agent_" property="userAgent" />
        <result column="create_time_" property="createTime" />
        <result column="handle_status_" property="handleStatus" />
        <result column="handle_time_" property="handleTime" />
        <result column="handle_by_" property="handleBy" />
        <result column="handle_attitude_" property="handleAttitude" />
        <result column="feedback_" property="feedback" />
        <result column="feedback_content_" property="feedbackContent" />
    </resultMap>

    <!-- 表字段 -->
    <sql id="baseColumns">
         t.id_ as id
        ,t.suggestion_type_id_ as suggestionTypeId
        , t.mobile_no_ as mobileNo
        , t.type_ as type
        , t.title_ as title
        , t.content_ as content
        , t.attachment_urls_ as attachmentUrls
        , t.user_id_ as userId
        , t.client_type_ as clientType
        , t.user_agent_ as userAgent
        , t.create_time_ as createTime
        , t.handle_status_ as handleStatus
        , t.handle_time_ as handleTime
        , t.handle_by_ as handleBy
        , t.handle_attitude_ as handleAttitude
        , t.feedback_ as feedback
        , t.feedback_content_ as feedbackContent
    </sql>

    <select id="selectPage" resultType="com.yonge.cooleshow.biz.dal.wrapper.SysSuggestionWrapper$SysSuggestion">
		SELECT
        	<include refid="baseColumns" />,
        sst.name_ as suggestionTypeName
		FROM sys_suggestion t
        LEFT JOIN sys_suggestion_type sst on t.suggestion_type_id_ = sst.id_
        <if test="param.keyword!=null and param.keyword.trim()!=''">
            LEFT JOIN sys_user su2 ON su2.id_ = t.user_id_
        </if>
        <if test="param.handleName != null and param.handleName.trim() != ''">
            LEFT JOIN sys_user su ON su.id_ = t.handle_by_
        </if>
        <where>
            <if test="param.keyword!=null and param.keyword.trim()!=''">
                AND (
                su2.username_ LIKE CONCAT('%', #{param.keyword}, '%')
                or
                su2.phone_ LIKE CONCAT('%', #{param.keyword}, '%')
                )
            </if>
            <if test="param.type != null">
                AND t.type_ = #{param.type}
            </if>
		    <if test="param.clientType != null">
                AND t.client_type_ = #{param.clientType}
            </if>
            <if test="param.startTime!=null">
                AND t.create_time_ >= #{param.startTime}
            </if>
            <if test="param.endTime!=null">
                AND #{param.endTime} >= t.create_time_
            </if>
            <if test="param.suggestionTypeId != null">
                AND t.suggestion_type_id_ = #{param.suggestionTypeId}
            </if>
            <if test="param.suggestionTypeName != null and param.suggestionTypeName.trim() != ''">
                AND sst.name_ = #{param.suggestionTypeName}
            </if>
            <if test="param.handleStatus != null">
                AND t.handle_status_ = #{param.handleStatus}
            </if>
            <if test="param.handleBy != null">
                AND t.handle_by_ = #{param.handleBy}
            </if>
            <if test="param.handleName != null and param.handleName.trim() != ''">
                AND su.username_ LIKE CONCAT('%', #{param.handleName}, '%')
            </if>
            <if test="param.handStartTime != null">
                AND t.handle_time_ >= #{param.handStartTime}
            </if>
            <if test="param.handEndTime != null">
                AND #{param.handEndTime} >= t.handle_time_
            </if>
            <if test="param.handleAttitude != null">
                AND t.handle_attitude_ = #{param.handleAttitude}
            </if>
            <if test="param.feedback != null">
                AND t.feedback_ = #{param.feedback}
            </if>
            <if test="param.userId != null">
                AND t.user_id_ = #{param.userId}
            </if>
        </where>
        ORDER BY t.id_ DESC
	</select>

</mapper>
