<?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.MsgAppPushMapper">
    <resultMap id="MsgAppPushVoResult" type="com.ozs.entity.vo.MsgAppPushVo">
        <id column="id" property="id"/>
        <result column="alarm_id" property="alarmId"/>
        <result column="receive_by" property="receiveBy"/>
        <result column="status" property="status"/>
        <result column="create_by" property="createBy"/>
        <result column="create_time" property="createTime"/>
        <result column="update_by" property="updateBy"/>
        <result column="update_time" property="updateTime"/>
        <result column="remark" property="remark"/>
        <result column="lineDir" property="lineDir"/>
        <result column="railwayName" property="railwayName"/>
        <result column="railwayType" property="railwayType"/>
        <result column="alarmMile" property="alarmMile"/>
        <result column="alarmType" property="alarmType"/>
        <result column="imageUrl" property="imageUrl"/>
        <association property="baseCameraManagement" javaType="com.ozs.entity.BaseCameraManagement">
            <id column="id" property="id"/>
            <result column="railway_code" property="railwayCode"/>
            <result column="channel" property="channel"/>
            <result column="install_mile" property="installMile"/>
            <result column="begin_mile" property="beginMile"/>
            <result column="end_mile" property="endMile"/>
            <result column="install_longitude" property="installLongitude"/>
            <result column="install_latitude" property="installLatitude"/>
        </association>
    </resultMap>
    <select id="alarmPushMsg" resultMap="MsgAppPushVoResult" parameterType="com.ozs.entity.vo.MsgAppPushVo">
        select
        m.id,
        m.alarm_id,
        m.receive_by,
        a.line_dir AS lineDir,
        a.alarm_mile AS alarmMile,
        a.alarm_type AS alarmType,
        m.status,
        m.create_by,
        m.create_time,
        m.update_by,
        m.update_time,
        m.remark,
        b.railway_code AS railway_code,
        r.railway_name AS railwayName,
        r.railway_type AS railwayType,
        b.channel AS channel,
        b.install_mile AS install_mile,
        b.begin_mile AS begin_mile,
        b.end_mile AS end_mile,
        b.install_longitude AS install_longitude,
        b.install_latitude AS install_latitude
        from msg_app_push m join
        msg_alarm AS a on m.alarm_id=a.alarm_id join
        base_camera_management AS b on a.camera_code=b.camera_code join
        base_railway_management AS r on b.railway_code=r.railway_code
        <where>
            <if test="status != null and status != 0">
                and status = #{status}
            </if>
            <if test="receiveBy != null and receiveBy != ''">
                and receive_by = #{receiveBy}
            </if>
        </where>
    </select>

    <update id="update" parameterType="com.ozs.entity.MsgAppPush">
        update msg_app_push
        <set>
            <if test="status != null and status != 0">
                status = #{status},
            </if>
            <if test="updateBy != null and updateBy != ''">
                update_by = #{updateBy},
            </if>
            update_time = sysdate()
        </set>
        <where>
            <if test="pushId != null and pushId != ''">
                and push_id = #{pushId}
            </if>
            <if test="id != null and id != 0">
                and push_id = #{id}
            </if>
        </where>
    </update>

    <select id="messageMoreApp" parameterType="com.ozs.entity.vo.MsgAlarmVo" resultType="com.ozs.entity.MsgAlarm">
        select b.*, a.status, a.push_id as msgId
        from msg_app_push AS a
        join msg_alarm AS b on a.alarm_id = b.alarm_id
        join base_camera_management AS c on b.camera_code = c.camera_code
        <where>
            <if test="userId != null and userId != ''">
                and a.receive_by = #{userId}
            </if>
            <if test="status != null and status != 0">
                and a.status = #{status}
            </if>
        </where>
    </select>
</mapper>
