<?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.moral.mapper.DeviceMapper">
|
<resultMap id="BaseResultMap" type="com.moral.entity.Device">
|
<id column="id" jdbcType="INTEGER" property="id" />
|
<result column="name" jdbcType="VARCHAR" property="name" />
|
<result column="address" jdbcType="VARCHAR" property="address" />
|
<result column="longitude" jdbcType="REAL" property="longitude" />
|
<result column="latitude" jdbcType="REAL" property="latitude" />
|
<result column="mac" jdbcType="VARCHAR" property="mac" />
|
<result column="state" jdbcType="VARCHAR" property="state" />
|
<result column="operate_user_id" jdbcType="INTEGER" property="operateUserId" />
|
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
|
<result column="install_time" jdbcType="TIMESTAMP" property="installTime" />
|
<result column="is_delete" jdbcType="CHAR" property="isDelete" />
|
<result column="monitor_point_id" jdbcType="INTEGER" property="monitorPointId" />
|
<result column="device_version_id" jdbcType="INTEGER" property="deviceVersionId" />
|
<result column="profession_id" jdbcType="INTEGER" property="professionId" />
|
<association property="deviceVersion" javaType="com.moral.entity.DeviceVersion">
|
<result column="device_version_id" property="id" jdbcType="INTEGER" />
|
<result column="device_version_value" property="version" jdbcType="INTEGER" />
|
</association>
|
<association property="density" javaType="com.moral.entity.Density">
|
<result column="limit_val" property="limitVal" jdbcType="OTHER" />
|
</association>
|
<association property="monitorPoint" javaType="com.moral.entity.MonitorPoint">
|
<result column="province_code" property="provinceCode" jdbcType="INTEGER" />
|
<result column="city_code" property="cityCode" jdbcType="INTEGER" />
|
<result column="area_code" property="areaCode" jdbcType="INTEGER" />
|
</association>
|
<association property="deviceProperty" javaType="com.moral.entity.DeviceProperty">
|
<result column="device_tech" property="deviceTech" jdbcType="INTEGER" />
|
<result column="device_source" property="deviceSource" jdbcType="VARCHAR" />
|
<result column="ext_C" property="extC" jdbcType="VARCHAR" />
|
<result column="ext_D" property="extD" jdbcType="VARCHAR" />
|
</association>
|
</resultMap>
|
<resultMap id="BaseResultWithOrgIdsMap" type="com.moral.entity.Device" extends="BaseResultMap">
|
<collection property="organizationIds" column="id" select="selectOrganizationIds"></collection>
|
</resultMap>
|
<!-- resultMap引用 -->
|
<select id="selectOrganizationIds" resultType="INTEGER">
|
call proc_organizationIds_GetByDeviceId(#{id,jdbcType=INTEGER});
|
</select>
|
<select id="selectWithMacByNotState" resultMap="BaseResultMap">
|
<![CDATA[
|
select id,mac,state
|
from device WHERE state <> #{state,jdbcType=VARCHAR}
|
]]>
|
</select>
|
<sql id="Base_Column_List">
|
id, name, address, longitude, latitude, mac, operate_user_id, create_time,state, install_time,
|
monitor_point_id, device_version_id,is_delete
|
</sql>
|
<sql id="simple_Column_List">
|
dev.id, dev.name, dev.address, dev.mac, dev.device_version_id, dev.monitor_point_id,dev.profession_id,dev.is_delete
|
</sql>
|
<select id="selectWithOrgIdsByMac" parameterType="java.lang.String" resultMap="BaseResultWithOrgIdsMap">
|
select
|
<include refid="simple_Column_List" /> ,
|
dvn.version as device_version_value,
|
den.limit_val,
|
mp.province_code,
|
mp.city_code,
|
mp.area_code,
|
dp.device_tech,
|
dp.device_source,
|
dp.ext_C,
|
dp.ext_D
|
from device dev left join device_version dvn on dev.device_version_id = dvn.id
|
left join device_property dp on dev.id = dp.id
|
left join density den on dev.profession_id = den.profession_id and dp.device_tech = den.tech
|
left join monitor_point mp on mp.id = dev.monitor_point_id
|
where mac = #{mac,jdbcType=VARCHAR}
|
</select>
|
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
|
select
|
<include refid="Base_Column_List" />
|
from device
|
where id = #{id,jdbcType=INTEGER}
|
</select>
|
|
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
|
delete from device
|
where id = #{id,jdbcType=INTEGER}
|
</delete>
|
<insert id="insert" parameterType="com.moral.entity.Device" >
|
insert into device (id, name, address,
|
longitude, latitude, mac,
|
operate_user_id, state, create_time,
|
install_time, monitor_point_id, device_version_id
|
)
|
values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{address,jdbcType=VARCHAR},
|
#{longitude,jdbcType=REAL}, #{latitude,jdbcType=REAL}, #{mac,jdbcType=VARCHAR},
|
#{operateUserId,jdbcType=INTEGER}, #{state,jdbcType=CHAR}, #{createTime,jdbcType=TIMESTAMP},
|
#{installTime,jdbcType=TIMESTAMP}, #{monitorPointId,jdbcType=INTEGER}, #{deviceVersionId,jdbcType=INTEGER}
|
)
|
</insert>
|
<insert id="insertSelective" parameterType="com.moral.entity.Device" >
|
insert into device
|
<trim prefix="(" suffix=")" suffixOverrides="," >
|
<if test="id != null" >
|
id,
|
</if>
|
<if test="name != null" >
|
name,
|
</if>
|
<if test="address != null" >
|
address,
|
</if>
|
<if test="longitude != null" >
|
longitude,
|
</if>
|
<if test="latitude != null" >
|
latitude,
|
</if>
|
<if test="mac != null" >
|
mac,
|
</if>
|
<if test="operateUserId != null" >
|
operate_user_id,
|
</if>
|
<if test="state != null" >
|
state,
|
</if>
|
<if test="createTime != null" >
|
create_time,
|
</if>
|
<if test="installTime != null" >
|
install_time,
|
</if>
|
<if test="monitorPointId != null" >
|
monitor_point_id,
|
</if>
|
<if test="deviceVersionId != null" >
|
device_version_id,
|
</if>
|
</trim>
|
<trim prefix="values (" suffix=")" suffixOverrides="," >
|
<if test="id != null" >
|
#{id,jdbcType=INTEGER},
|
</if>
|
<if test="name != null" >
|
#{name,jdbcType=VARCHAR},
|
</if>
|
<if test="address != null" >
|
#{address,jdbcType=VARCHAR},
|
</if>
|
<if test="longitude != null" >
|
#{longitude,jdbcType=REAL},
|
</if>
|
<if test="latitude != null" >
|
#{latitude,jdbcType=REAL},
|
</if>
|
<if test="mac != null" >
|
#{mac,jdbcType=VARCHAR},
|
</if>
|
<if test="operateUserId != null" >
|
#{operateUserId,jdbcType=INTEGER},
|
</if>
|
<if test="state != null" >
|
#{state,jdbcType=CHAR},
|
</if>
|
<if test="createTime != null" >
|
#{createTime,jdbcType=TIMESTAMP},
|
</if>
|
<if test="installTime != null" >
|
#{installTime,jdbcType=TIMESTAMP},
|
</if>
|
<if test="monitorPointId != null" >
|
#{monitorPointId,jdbcType=INTEGER},
|
</if>
|
<if test="deviceVersionId != null" >
|
#{deviceVersionId,jdbcType=INTEGER},
|
</if>
|
</trim>
|
</insert>
|
<update id="updateChangedStateById">
|
<![CDATA[
|
update device
|
set
|
state = #{state,jdbcType=CHAR}
|
where id = #{id,jdbcType=INTEGER} and state <> #{state,jdbcType=CHAR}
|
]]>
|
</update>
|
<update id="updateByPrimaryKeySelective" parameterType="com.moral.entity.Device" >
|
update device
|
<set >
|
<if test="name != null" >
|
name = #{name,jdbcType=VARCHAR},
|
</if>
|
<if test="address != null" >
|
address = #{address,jdbcType=VARCHAR},
|
</if>
|
<if test="longitude != null" >
|
longitude = #{longitude,jdbcType=REAL},
|
</if>
|
<if test="latitude != null" >
|
latitude = #{latitude,jdbcType=REAL},
|
</if>
|
<if test="mac != null" >
|
mac = #{mac,jdbcType=VARCHAR},
|
</if>
|
<if test="operateUserId != null" >
|
operate_user_id = #{operateUserId,jdbcType=INTEGER},
|
</if>
|
<if test="state != null" >
|
state = #{state,jdbcType=CHAR},
|
</if>
|
<if test="createTime != null" >
|
create_time = #{createTime,jdbcType=TIMESTAMP},
|
</if>
|
<if test="installTime != null" >
|
install_time = #{installTime,jdbcType=TIMESTAMP},
|
</if>
|
<if test="monitorPointId != null" >
|
monitor_point_id = #{monitorPointId,jdbcType=INTEGER},
|
</if>
|
<if test="deviceVersionId != null" >
|
device_version_id = #{deviceVersionId,jdbcType=INTEGER},
|
</if>
|
</set>
|
where id = #{id,jdbcType=INTEGER}
|
</update>
|
<update id="updateByPrimaryKey" parameterType="com.moral.entity.Device" >
|
update device
|
set name = #{name,jdbcType=VARCHAR},
|
address = #{address,jdbcType=VARCHAR},
|
longitude = #{longitude,jdbcType=REAL},
|
latitude = #{latitude,jdbcType=REAL},
|
mac = #{mac,jdbcType=VARCHAR},
|
operate_user_id = #{operateUserId,jdbcType=INTEGER},
|
state = #{state,jdbcType=CHAR},
|
create_time = #{createTime,jdbcType=TIMESTAMP},
|
install_time = #{installTime,jdbcType=TIMESTAMP},
|
monitor_point_id = #{monitorPointId,jdbcType=INTEGER},
|
device_version_id = #{deviceVersionId,jdbcType=INTEGER}
|
where id = #{id,jdbcType=INTEGER}
|
</update>
|
<select id="getChangshuMacs" resultType="map">
|
SELECT
|
d.mac,
|
( SELECT JSON_KEYS ( VALUE ) FROM history h WHERE mac = d.mac LIMIT 1 ) sensorKeys
|
FROM
|
monitor_point mp,
|
device d
|
WHERE
|
mp.id = d.monitor_point_id
|
AND mp.area_code = 320581
|
AND d.is_delete = '0';
|
</select>
|
<select id="getMacAndSensorkeyByOrganizationid" resultType="map">
|
SELECT d.mac, (SELECT JSON_KEYS ( VALUE ) FROM history h WHERE mac = d.mac LIMIT 1) sensorKeys
|
FROM monitor_point mp, device d
|
WHERE mp.id = d.monitor_point_id
|
AND mp.organization_id IN
|
<foreach collection="organizationIdList" index="index" item="organizationId" open="(" separator="," close=")">
|
#{organizationId}
|
</foreach>
|
AND d.is_delete = '0';
|
</select>
|
|
<select id="getMacs" resultType="java.lang.String">
|
select
|
mac
|
from
|
device
|
where is_delete = '0'
|
</select>
|
|
<select id="getMacByOrganizationid" resultType="string">
|
SELECT d.mac
|
FROM monitor_point mp, device d
|
WHERE mp.id = d.monitor_point_id
|
AND mp.organization_id IN
|
<foreach collection="organizationIdList" index="index" item="organizationId" open="(" separator="," close=")">
|
#{organizationId}
|
</foreach>
|
AND d.is_delete = '0'
|
</select>
|
|
<select id="macAndOrganizationIdMap" resultType="java.util.LinkedHashMap">
|
select mac,organization_id as organizationId
|
FROM monitor_point m,device d
|
WHERE m.id=d.monitor_point_id
|
and d.mac in
|
<foreach collection="macs" open="(" separator="," close=")"
|
item="mac">
|
#{mac}
|
</foreach>
|
</select>
|
|
<select id="getMacsByMonitorPointIds" resultType="java.lang.String">
|
select mac from device where monitor_point_id in
|
<foreach item="item" collection="list" index="index" open="(" separator="," close=")">#{item}</foreach>
|
and is_delete=0;
|
</select>
|
|
<select id="getAllByMacList" resultType="java.util.Map">
|
select * from device
|
where mac in
|
<foreach item="item" collection="list" index="index" open="(" separator="," close=")">#{item}</foreach>
|
</select>
|
|
<select id="getOfflineDevice" resultType="java.util.Map">
|
SELECT name,mac
|
from device
|
WHERE state=4 and is_delete=0 and monitor_point_id in
|
(SELECT id FROM monitor_point WHERE city_code!=130900 or (city_code=130900 and organization_id in (60, 65, 159, 165, 166) and id!=56 and id!=83 and id!=84))
|
and mac not in (SELECT mac FROM special_device_config);
|
</select>
|
|
<select id="getOfflineDeviceOfDiseaseCenter" resultType="java.util.Map">
|
SELECT name,mac
|
FROM `device`
|
WHERE state=4 and is_delete=0
|
and monitor_point_id in(
|
SELECT id FROM monitor_point WHERE organization_id=#{orgId}
|
);
|
</select>
|
|
<select id="getAllDeviceByOrg" resultType="java.util.Map">
|
SELECT name,mac
|
FROM `device`
|
WHERE is_delete=0
|
and monitor_point_id in(
|
SELECT id FROM monitor_point WHERE organization_id=#{orgId}
|
);
|
</select>
|
</mapper>
|