<?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.fjhx.message.mapper.UMessageMapper">

    <select id="getClassMessage" resultType="java.util.Map">
        SELECT
        t2.SourceType AS sourceType,
        Count( 1 ) AS count
        FROM
        u_messageread t1
        LEFT JOIN u_message t2 ON t1.LinkMessageId = t2.ID
        LEFT JOIN u_user t3 ON t1.ReceiverId = t3.ID
        <where>
            t3.JobNo = #{userNo}
            AND t1.ReadState = #{readState}
            <if test="search neq null and search neq '' ">
                AND INSTR( t2.Content, #{search} ) > 0
            </if>
        </where>
        GROUP BY
        t2.SourceType
    </select>
    <select id="getList" resultType="com.fjhx.entity.message.UMessage">
        SELECT
        t1.ID,
        t2.IsDelete,
        t2.CreatedTime,
        t2.UpdatedTime,
        t2.SourceType,
        t2.Content,
        t2.SenderId,
        t2.ObejctType,
        t2.LinkId,
        t2.DealWithType
        FROM
        u_messageread t1
        LEFT JOIN u_message t2 ON t1.LinkMessageId = t2.ID
        LEFT JOIN u_user t3 ON t1.ReceiverId = t3.ID
        <include refid="list_condition"/>
        ORDER BY t2.CreatedTime DESC
        <include refid="com.fjhx.supplier.mapper.SupplierMapper.sql_limit"/>
    </select>
    <select id="getListCount" resultType="java.lang.Integer">
        SELECT
        count(1)
        FROM
        u_messageread t1
        LEFT JOIN u_message t2 ON t1.LinkMessageId = t2.ID
        LEFT JOIN u_user t3 ON t1.ReceiverId = t3.ID
        <include refid="list_condition"/>
    </select>
    <sql id="list_condition">
        <where>
            t3.JobNo = #{userNo}
            AND t1.ReadState = #{readState}
            <if test="sourceType neq null ">
                AND SourceType = #{sourceType}
            </if>
            <if test="search neq null and search neq '' ">
                AND INSTR( t2.Content, #{search} ) > 0
            </if>
        </where>
    </sql>
</mapper>
