<?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.ozs.mapper.MsgWebPushMapper">

    <select id="webAlarmNum" parameterType="java.lang.String" resultType="java.lang.Integer">
        select count(1) from msg_web_push where status = 1
        <if test="userId != null and userId != ''">
            and receive_by = #{userId}
        </if>
    </select>

    <select id="webAlarm" parameterType="java.lang.String" resultType="com.ozs.entity.MsgAlarm">
        select b.*, a.push_id as msgId
        from msg_web_push AS a
        join msg_alarm AS b on a.alarm_id = b.alarm_id
        where a.status = 1
        <if test="userId != null and userId != ''">
            and a.receive_by = #{userId}
        </if>
    </select>

    <select id="messageMore" parameterType="com.ozs.entity.vo.MsgAlarmVo" resultType="com.ozs.entity.MsgAlarm">
        select b.*, a.status, a.push_id as msgId
        from msg_web_push AS a
        join msg_alarm AS b on a.alarm_id = b.alarm_id
        join base_railway_management AS c on b.railway_code = c.railway_code
        <where>
            <if test="userId != null and userId != ''">
                and a.receive_by = #{userId}
            </if>
            <if test="status != null and status != ''">
                and a.status = #{status}
            </if>
            <if test="alarmType != null and alarmType != ''">
                and b.alarm_type = #{alarmType}
            </if>
            <if test="beginAlarmTime != null and beginAlarmTime != ''">
                and b.alarm_time &gt;= #{beginAlarmTime}
            </if>
            <if test="endAlarmTime != null and endAlarmTime != ''">
                and b.alarm_time &lt;= #{endAlarmTime}
            </if>
            <if test="isRelease != null and isRelease != ''">
                and b.is_release = #{isRelease}
            </if>
            <if test="railwayCode != null and railwayCode != ''">
                and c.railway_code = #{railwayCode}
            </if>
<!--            <if test="beginMile != null and beginMile != ''">-->
<!--                and c.begin_mile &gt;= #{beginMile}-->
<!--            </if>-->
<!--            <if test="endMile != null and endMile != ''">-->
<!--                and c.end_mile &lt;= #{endMile}-->
<!--            </if>-->
        </where>
    </select>

    <select id="messageMoreNum" parameterType="com.ozs.entity.vo.MsgAlarmVo" resultType="java.util.Map">
        select count(1)  as count, SUM(CASE status WHEN '1' THEN 1 ELSE 0 end) AS noCount from msg_web_push
        <where>
            <if test="userId != null and userId != ''">
                and receive_by = #{userId}
            </if>
        </where>
    </select>

    <update id="updateByPushId" parameterType="com.ozs.entity.MsgWebPush">
        update msg_web_push
        <set>
            <if test="status != null and status != 0">
                status = #{status}
            </if>
        </set>
        <where>
            <if test="pushId != null and pushId != ''">
                and push_id = #{pushId}
            </if>
            <if test="id != null and id != 0">
                and id = #{id}
            </if>
        </where>
    </update>

    <update id="readAll" parameterType="java.lang.String">
        update msg_web_push
        <set>
            status = 2
        </set>
        where receive_by = #{userId} and status = 1
    </update>

    <select id="getByUserId" parameterType="java.lang.String" resultType="com.ozs.entity.MsgWebPush">
        select * from msg_web_push where online = '2' and receive_by = #{userId}
    </select>
</mapper>
