<?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.inkasso.factoring.system.message.dao.MessageDAO">


	<update id="batchUpdateStatus" parameterType="java.lang.Long">
          update kfb_sys_msg  set   read_status = true
          where  receive_user_id = #{userId} and  read_status = false
	</update>
    <select id="findVehicleLeaderMessage" resultType="com.inkasso.factoring.system.message.entity.MessageDO">
        select *
        from kfb_sys_msg a
        LEFT JOIN kfb_attached_vehicle_information b on a.object_id = b.id
        <where>
            b.whether_moveOut != 1
            <if test="tenantId != null">
                and a.tenant_id = #{tenantId}
            </if>
            <if test="businessType != null">
                and a.business_type like CONCAT(#{businessType}, '%' )
            </if>
            <if test="beginDate != null">
                and DATE_FORMAT( a.create_time, '%Y-%m' ) >= DATE_FORMAT(#{beginDate}, '%Y-%m' )
            </if>
            <if test="endDate != null">
                and DATE_FORMAT( a.create_time, '%Y-%m' ) &lt;= DATE_FORMAT(#{endDate}, '%Y-%m' )
            </if>
        </where>
    </select>

    <!-- 分页查询  通知消息 -->
  <select id="pageQuery"  resultType="com.inkasso.factoring.system.message.model.dto.MessageDTO">
        select
            *
        from kfb_sys_msg
        where  ( receive_user_id = #{queryMessageRequest.receiveUserId}  and tenant_id is null)
        <if test="queryMessageRequest.tenantId !=null ">
            or (receive_user_id = #{queryMessageRequest.receiveUserId}  and tenant_id = #{queryMessageRequest.tenantId})
        </if>
  </select>
</mapper>