<?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.ruoyi.system.mapper.TShouhuanInfoMapper">

    <resultMap type="TShouhuanInfo" id="TShouhuanInfoResult">
        <result property="id" column="id"/>
        <result property="facilityId" column="facility_id"/>
        <result property="deviceIdCode" column="device_id_code"/>
        <result property="version" column="version"/>
        <result property="gpsLong" column="gps_long"/>
        <result property="gpsLat" column="gps_lat"/>
        <result property="useGpsLong" column="use_gps_long"/>
        <result property="useGpsLat" column="use_gps_lat"/>
        <result property="useMac" column="use_mac"/>
        <result property="speed" column="speed"/>
        <result property="direction" column="direction"/>
        <result property="poster" column="poster"/>
        <result property="electricQuantity" column="electric_quantity"/>
        <result property="stepNumber" column="step_number"/>
        <result property="rollNumber" column="roll_number"/>
        <result property="terminalStatus" column="terminal_status"/>
        <result property="onlineStatis" column="online_statis"/>
        <result property="temp" column="temp"/>
        <result property="bloodHeightPressure" column="blood_height_pressure"/>
        <result property="bloodLowPressure" column="blood_low_pressure"/>
        <result property="heartRate" column="heart_rate"/>
        <result property="oxygen" column="oxygen"/>
        <result property="offlinetime" column="offlinetime"/>
        <result property="onlinetime" column="onlinetime"/>
        <result property="gpsUpdateTime" column="gps_update_time"/>
        <result property="bloodUpdateTime" column="blood_update_time"/>
        <result property="heartUpdateTime" column="heart_update_time"/>
        <result property="tempUpdateTime" column="temp_update_time"/>
        <result property="oxygenUpdateTime" column="oxygen_update_time"/>
        <result property="electricQuantityUpdateTime" column="electric_quantity_update_time"/>
        <result property="stepNumberUpdateTime" column="step_number_update_time"/>
        <result property="rollNumberUpdateTime" column="roll_number_update_time"/>
        <result property="terminalStatusUpdateTime" column="terminal_status_update_time"/>
        <result property="createtime" column="createtime"/>
        <result property="updatetime" column="updatetime"/>
        <result property="accesstype" column="accesstype"/>
        <result property="addressDesc" column="address_desc"/>
        <result property="isGps" column="is_gps"/>
    </resultMap>

    <sql id="selectTShouhuanInfoVo">
        select id,
               facility_id,
               device_id_code,
               version,
               gps_long,
               gps_lat,
               use_gps_long,
               use_gps_lat,
               use_mac,
               speed,
               direction,
               poster,
               electric_quantity,
               step_number,
               roll_number,
               terminal_status,
               online_statis,
               temp,
               blood_height_pressure,
               blood_low_pressure,
               heart_rate,
               oxygen,
               offlinetime,
               onlinetime,
               gps_update_time,
               blood_update_time,
               heart_update_time,
               temp_update_time,
               oxygen_update_time,
               electric_quantity_update_time,
               step_number_update_time,
               roll_number_update_time,
               terminal_status_update_time,
               createtime,
               updatetime,
               accesstype,
               address_desc,
               is_gps
        from t_shouhuan_info
    </sql>

    <select id="selectTShouhuanInfoList" parameterType="TShouhuanInfo" resultMap="TShouhuanInfoResult">
        <include refid="selectTShouhuanInfoVo"/>
        <where>
            <if test="facilityId != null ">and facility_id = #{facilityId}</if>
            <if test="deviceIdCode != null  and deviceIdCode != ''">and device_id_code = #{deviceIdCode}</if>
            <if test="version != null  and version != ''">and version = #{version}</if>
            <if test="gpsLong != null ">and gps_long = #{gpsLong}</if>
            <if test="gpsLat != null ">and gps_lat = #{gpsLat}</if>
            <if test="useGpsLong != null ">and use_gps_long = #{useGpsLong}</if>
            <if test="useGpsLat != null ">and use_gps_lat = #{useGpsLat}</if>
            <if test="useMac != null  and useMac != ''">and use_mac = #{useMac}</if>
            <if test="speed != null ">and speed = #{speed}</if>
            <if test="direction != null ">and direction = #{direction}</if>
            <if test="poster != null ">and poster = #{poster}</if>
            <if test="electricQuantity != null ">and electric_quantity = #{electricQuantity}</if>
            <if test="stepNumber != null ">and step_number = #{stepNumber}</if>
            <if test="rollNumber != null ">and roll_number = #{rollNumber}</if>
            <if test="terminalStatus != null  and terminalStatus != ''">and terminal_status = #{terminalStatus}</if>
            <if test="onlineStatis != null ">and online_statis = #{onlineStatis}</if>
            <if test="temp != null ">and temp = #{temp}</if>
            <if test="bloodHeightPressure != null ">and blood_height_pressure = #{bloodHeightPressure}</if>
            <if test="bloodLowPressure != null ">and blood_low_pressure = #{bloodLowPressure}</if>
            <if test="heartRate != null ">and heart_rate = #{heartRate}</if>
            <if test="oxygen != null ">and oxygen = #{oxygen}</if>
            <if test="offlinetime != null ">and offlinetime = #{offlinetime}</if>
            <if test="onlinetime != null ">and onlinetime = #{onlinetime}</if>
            <if test="gpsUpdateTime != null ">and gps_update_time = #{gpsUpdateTime}</if>
            <if test="bloodUpdateTime != null ">and blood_update_time = #{bloodUpdateTime}</if>
            <if test="heartUpdateTime != null ">and heart_update_time = #{heartUpdateTime}</if>
            <if test="tempUpdateTime != null ">and temp_update_time = #{tempUpdateTime}</if>
            <if test="oxygenUpdateTime != null ">and oxygen_update_time = #{oxygenUpdateTime}</if>
            <if test="electricQuantityUpdateTime != null ">and electric_quantity_update_time =
                #{electricQuantityUpdateTime}
            </if>
            <if test="stepNumberUpdateTime != null ">and step_number_update_time = #{stepNumberUpdateTime}</if>
            <if test="rollNumberUpdateTime != null ">and roll_number_update_time = #{rollNumberUpdateTime}</if>
            <if test="terminalStatusUpdateTime != null ">and terminal_status_update_time = #{terminalStatusUpdateTime}
            </if>
            <if test="createtime != null ">and createtime = #{createtime}</if>
            <if test="updatetime != null ">and updatetime = #{updatetime}</if>
            <if test="accesstype != null ">and accesstype = #{accesstype}</if>
            <if test="addressDesc != null  and addressDesc != ''">and address_desc = #{addressDesc}</if>
            <if test="isGps != null ">and is_gps = #{isGps}</if>
        </where>
    </select>

    <select id="selectTShouhuanInfoById" parameterType="Long" resultMap="TShouhuanInfoResult">
        <include refid="selectTShouhuanInfoVo"/>
        where id = #{id}
    </select>
    <select id="selectTShouhuanInfo" parameterType="TShouhuanInfo" resultMap="TShouhuanInfoResult">
        <include refid="selectTShouhuanInfoVo"/>
    </select>
    <select id="selectMapGpsView" resultType="com.ruoyi.system.domain.dto.MapGpsDto">
        SELECT gps_long, gps_lat, use_gps_long, use_gps_lat
        FROM `t_shouhuan_info`
    </select>

    <select id="selectTShouhuanInfoListBydeviceIdCode" parameterType="string" resultMap="TShouhuanInfoResult">
        <include refid="selectTShouhuanInfoVo"/>
        where device_id_code = #{device_id_code}
    </select>
    <select id="selectTShouhuanInfoPercentage" resultType="java.lang.Double">
        SELECT (COUNT(*) * 100 / (SELECT COUNT(*) FROM t_device_list))
        FROM t_shouhuan_info
        WHERE online_statis = 1;
    </select>
    <select id="selectTShouhuanInfoAllCount" resultType="java.lang.Integer">
        SELECT COUNT(*)
        FROM t_device_list;
    </select>
    <select id="selectTShouhuanInfoAllOnlineCount" resultType="java.lang.Integer">
        SELECT COUNT(*)
        FROM t_shouhuan_info
        WHERE online_statis = 1;
    </select>
    <select id="selectTShouhuanInfoAllUnOnlineCount" resultType="java.lang.Integer">
        SELECT ((SELECT COUNT(*) FROM t_device_list) - COUNT(*))
        FROM t_shouhuan_info
        WHERE online_statis = 1;
    </select>

    <insert id="insertTShouhuanInfo" parameterType="TShouhuanInfo" useGeneratedKeys="true" keyProperty="id">
        insert into t_shouhuan_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="facilityId != null">facility_id,</if>
            <if test="deviceIdCode != null">device_id_code,</if>
            <if test="version != null">version,</if>
            <if test="gpsLong != null">gps_long,</if>
            <if test="gpsLat != null">gps_lat,</if>
            <if test="useGpsLong != null">use_gps_long,</if>
            <if test="useGpsLat != null">use_gps_lat,</if>
            <if test="useMac != null">use_mac,</if>
            <if test="speed != null">speed,</if>
            <if test="direction != null">direction,</if>
            <if test="poster != null">poster,</if>
            <if test="electricQuantity != null">electric_quantity,</if>
            <if test="stepNumber != null">step_number,</if>
            <if test="rollNumber != null">roll_number,</if>
            <if test="terminalStatus != null">terminal_status,</if>
            <if test="onlineStatis != null">online_statis,</if>
            <if test="temp != null">temp,</if>
            <if test="bloodHeightPressure != null">blood_height_pressure,</if>
            <if test="bloodLowPressure != null">blood_low_pressure,</if>
            <if test="heartRate != null">heart_rate,</if>
            <if test="oxygen != null">oxygen,</if>
            <if test="offlinetime != null">offlinetime,</if>
            <if test="onlinetime != null">onlinetime,</if>
            <if test="gpsUpdateTime != null">gps_update_time,</if>
            <if test="bloodUpdateTime != null">blood_update_time,</if>
            <if test="heartUpdateTime != null">heart_update_time,</if>
            <if test="tempUpdateTime != null">temp_update_time,</if>
            <if test="oxygenUpdateTime != null">oxygen_update_time,</if>
            <if test="electricQuantityUpdateTime != null">electric_quantity_update_time,</if>
            <if test="stepNumberUpdateTime != null">step_number_update_time,</if>
            <if test="rollNumberUpdateTime != null">roll_number_update_time,</if>
            <if test="terminalStatusUpdateTime != null">terminal_status_update_time,</if>
            <if test="createtime != null">createtime,</if>
            <if test="updatetime != null">updatetime,</if>
            <if test="accesstype != null">accesstype,</if>
            <if test="addressDesc != null">address_desc,</if>
            <if test="isGps != null">is_gps,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="facilityId != null">#{facilityId},</if>
            <if test="deviceIdCode != null">#{deviceIdCode},</if>
            <if test="version != null">#{version},</if>
            <if test="gpsLong != null">#{gpsLong},</if>
            <if test="gpsLat != null">#{gpsLat},</if>
            <if test="useGpsLong != null">#{useGpsLong},</if>
            <if test="useGpsLat != null">#{useGpsLat},</if>
            <if test="useMac != null">#{useMac},</if>
            <if test="speed != null">#{speed},</if>
            <if test="direction != null">#{direction},</if>
            <if test="poster != null">#{poster},</if>
            <if test="electricQuantity != null">#{electricQuantity},</if>
            <if test="stepNumber != null">#{stepNumber},</if>
            <if test="rollNumber != null">#{rollNumber},</if>
            <if test="terminalStatus != null">#{terminalStatus},</if>
            <if test="onlineStatis != null">#{onlineStatis},</if>
            <if test="temp != null">#{temp},</if>
            <if test="bloodHeightPressure != null">#{bloodHeightPressure},</if>
            <if test="bloodLowPressure != null">#{bloodLowPressure},</if>
            <if test="heartRate != null">#{heartRate},</if>
            <if test="oxygen != null">#{oxygen},</if>
            <if test="offlinetime != null">#{offlinetime},</if>
            <if test="onlinetime != null">#{onlinetime},</if>
            <if test="gpsUpdateTime != null">#{gpsUpdateTime},</if>
            <if test="bloodUpdateTime != null">#{bloodUpdateTime},</if>
            <if test="heartUpdateTime != null">#{heartUpdateTime},</if>
            <if test="tempUpdateTime != null">#{tempUpdateTime},</if>
            <if test="oxygenUpdateTime != null">#{oxygenUpdateTime},</if>
            <if test="electricQuantityUpdateTime != null">#{electricQuantityUpdateTime},</if>
            <if test="stepNumberUpdateTime != null">#{stepNumberUpdateTime},</if>
            <if test="rollNumberUpdateTime != null">#{rollNumberUpdateTime},</if>
            <if test="terminalStatusUpdateTime != null">#{terminalStatusUpdateTime},</if>
            <if test="createtime != null">#{createtime},</if>
            <if test="updatetime != null">#{updatetime},</if>
            <if test="accesstype != null">#{accesstype},</if>
            <if test="addressDesc != null">#{addressDesc},</if>
            <if test="isGps != null">#{isGps},</if>
        </trim>
    </insert>

    <update id="updateTShouhuanInfo" parameterType="TShouhuanInfo">
        update t_shouhuan_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="facilityId != null">facility_id = #{facilityId},</if>
            <if test="deviceIdCode != null">device_id_code = #{deviceIdCode},</if>
            <if test="version != null">version = #{version},</if>
            <if test="gpsLong != null">gps_long = #{gpsLong},</if>
            <if test="gpsLat != null">gps_lat = #{gpsLat},</if>
            <if test="useGpsLong != null">use_gps_long = #{useGpsLong},</if>
            <if test="useGpsLat != null">use_gps_lat = #{useGpsLat},</if>
            <if test="useMac != null">use_mac = #{useMac},</if>
            <if test="speed != null">speed = #{speed},</if>
            <if test="direction != null">direction = #{direction},</if>
            <if test="poster != null">poster = #{poster},</if>
            <if test="electricQuantity != null">electric_quantity = #{electricQuantity},</if>
            <if test="stepNumber != null">step_number = #{stepNumber},</if>
            <if test="rollNumber != null">roll_number = #{rollNumber},</if>
            <if test="terminalStatus != null">terminal_status = #{terminalStatus},</if>
            <if test="onlineStatis != null">online_statis = #{onlineStatis},</if>
            <if test="temp != null">temp = #{temp},</if>
            <if test="bloodHeightPressure != null">blood_height_pressure = #{bloodHeightPressure},</if>
            <if test="bloodLowPressure != null">blood_low_pressure = #{bloodLowPressure},</if>
            <if test="heartRate != null">heart_rate = #{heartRate},</if>
            <if test="oxygen != null">oxygen = #{oxygen},</if>
            <if test="offlinetime != null">offlinetime = #{offlinetime},</if>
            <if test="onlinetime != null">onlinetime = #{onlinetime},</if>
            <if test="gpsUpdateTime != null">gps_update_time = #{gpsUpdateTime},</if>
            <if test="bloodUpdateTime != null">blood_update_time = #{bloodUpdateTime},</if>
            <if test="heartUpdateTime != null">heart_update_time = #{heartUpdateTime},</if>
            <if test="tempUpdateTime != null">temp_update_time = #{tempUpdateTime},</if>
            <if test="oxygenUpdateTime != null">oxygen_update_time = #{oxygenUpdateTime},</if>
            <if test="electricQuantityUpdateTime != null">electric_quantity_update_time =
                #{electricQuantityUpdateTime},
            </if>
            <if test="stepNumberUpdateTime != null">step_number_update_time = #{stepNumberUpdateTime},</if>
            <if test="rollNumberUpdateTime != null">roll_number_update_time = #{rollNumberUpdateTime},</if>
            <if test="terminalStatusUpdateTime != null">terminal_status_update_time = #{terminalStatusUpdateTime},</if>
            <if test="createtime != null">createtime = #{createtime},</if>
            <if test="updatetime != null">updatetime = #{updatetime},</if>
            <if test="accesstype != null">accesstype = #{accesstype},</if>
            <if test="addressDesc != null">address_desc = #{addressDesc},</if>
            <if test="isGps != null">is_gps = #{isGps},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTShouhuanInfoById" parameterType="Long">
        delete
        from t_shouhuan_info
        where id = #{id}
    </delete>

    <delete id="deleteTShouhuanInfoByIds" parameterType="String">
        delete from t_shouhuan_info where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>