406 lines
17 KiB
XML
406 lines
17 KiB
XML
<?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.fuyuanshen.equipment.mapper.DeviceMapper">
|
|
<resultMap id="BaseResultMap" type="com.fuyuanshen.equipment.domain.Device">
|
|
<id column="id" property="id"/>
|
|
<result column="device_type" property="deviceType"/>
|
|
<result column="customer_id" property="customerId"/>
|
|
<result column="device_no" property="deviceNo"/>
|
|
<result column="device_name" property="deviceName"/>
|
|
<result column="device_pic" property="devicePic"/>
|
|
<result column="device_mac" property="deviceMac"/>
|
|
<result column="device_sn" property="deviceSn"/>
|
|
<result column="device_status" property="deviceStatus"/>
|
|
<result column="remark" property="remark"/>
|
|
<result column="create_by" property="createBy"/>
|
|
<result column="update_by" property="updateBy"/>
|
|
<result column="create_time" property="createTime"/>
|
|
<result column="update_time" property="updateTime"/>
|
|
<result column="binding_status" property="bindingStatus"/>
|
|
</resultMap>
|
|
|
|
<sql id="Base_Column_List">
|
|
id
|
|
, device_type, customer_id, device_name, device_pic, device_mac, device_sn,
|
|
remark, create_by, update_by, create_time, update_time
|
|
</sql>
|
|
|
|
<sql id="device_Column_List">
|
|
d
|
|
.
|
|
id
|
|
,d.device_type,
|
|
d.customer_id, d.device_name, d.device_pic, d.device_mac,
|
|
d.device_sn, d.remark, d.create_by, d.update_by, d.create_time, d.update_time,
|
|
d.binding_status, d.device_status, d.current_owner_id, d.original_owner_id, d.customer_name,
|
|
d.device_imei, d.longitude, d.latitude, d.tenant_id
|
|
</sql>
|
|
|
|
<!-- 分页查询设备 -->
|
|
<select id="findAll" resultType="com.fuyuanshen.equipment.domain.Device">
|
|
SELECT *
|
|
FROM (
|
|
SELECT
|
|
da.id AS id, d.id AS deviceId, d.device_name, d.bluetooth_name, d.group_id,
|
|
d.pub_topic, d.sub_topic, d.device_pic,
|
|
d.device_mac, d.device_sn, d.update_by,
|
|
d.device_imei, d.update_time, dg.id AS device_type,
|
|
d.remark, d.binding_status, t.type_name AS typeName,
|
|
da.assignee_id AS customerId, da.assignee_name AS customerName,
|
|
da.active AS deviceStatus, da.create_time AS create_time,
|
|
da.assigner_name AS createByName, da.id AS assignId,
|
|
ROW_NUMBER() OVER (PARTITION BY d.id ORDER BY da.create_time DESC) AS rn
|
|
FROM device d
|
|
LEFT JOIN device_type t ON d.device_type = t.id
|
|
LEFT JOIN device_type_grants dg ON dg.device_type_id = t.id
|
|
LEFT JOIN device_assignments da ON da.device_id = d.id
|
|
<where>
|
|
<!-- 时间范围等其他条件保持原样 -->
|
|
<if test="criteria.deviceName != null and criteria.deviceName.trim() != ''">
|
|
and d.device_name like concat('%', TRIM(#{criteria.deviceName}), '%')
|
|
</if>
|
|
<if test="criteria.deviceMac != null">
|
|
and d.device_mac = #{criteria.deviceMac}
|
|
</if>
|
|
<if test="criteria.deviceImei != null">
|
|
and d.device_imei = #{criteria.deviceImei}
|
|
</if>
|
|
<if test="criteria.deviceType != null">
|
|
and d.device_type = #{criteria.deviceType}
|
|
</if>
|
|
<if test="criteria.deviceStatus != null">
|
|
and da.active = #{criteria.deviceStatus}
|
|
</if>
|
|
<if test="criteria.groupId != null">
|
|
and d.group_id = #{criteria.groupId}
|
|
</if>
|
|
<if test="criteria.communicationMode != null">
|
|
and t.communication_mode = #{criteria.communicationMode}
|
|
</if>
|
|
<if test="criteria.params.beginTime != null and criteria.params.endTime != null">
|
|
and da.create_time between #{criteria.params.beginTime} and #{criteria.params.endTime}
|
|
</if>
|
|
<!-- 管理员可以查看所有设备,普通用户只能查看自己的设备 -->
|
|
<if test="criteria.isAdmin != true">
|
|
AND da.assignee_id = #{criteria.currentOwnerId}
|
|
AND dg.customer_id = #{criteria.currentOwnerId}
|
|
</if>
|
|
</where>
|
|
) AS ranked
|
|
WHERE rn = 1
|
|
ORDER BY create_time DESC
|
|
</select>
|
|
|
|
|
|
<select id="findAllDevices" resultType="com.fuyuanshen.equipment.domain.Device">
|
|
select
|
|
d.id, d.customer_id, d.device_name,d.bluetooth_name,
|
|
d.device_pic, d.device_mac, d.device_sn, d.create_by, d.update_by,
|
|
d.create_time, d.update_time, d.longitude, d.latitude, d.remark
|
|
from device d
|
|
<where>
|
|
<if test="criteria.deviceName != null and criteria.deviceName.trim() != ''">
|
|
and d.device_name like concat('%', TRIM(#{criteria.deviceName}), '%')
|
|
</if>
|
|
<if test="criteria.deviceMac != null">
|
|
and d.device_mac = #{criteria.deviceMac}
|
|
</if>
|
|
<if test="criteria.deviceTypeId != null">
|
|
and d.device_type = #{criteria.deviceTypeId}
|
|
</if>
|
|
<if test="criteria.createTime != null and criteria.createTime.size() != 0">
|
|
and d.create_time between #{criteria.createTime[0]} and #{criteria.createTime[1]}
|
|
</if>
|
|
</where>
|
|
order by d.id desc
|
|
</select>
|
|
|
|
<!-- 根据条件查询 -->
|
|
<select id="findDevices" resultType="com.fuyuanshen.equipment.domain.Device"
|
|
parameterType="com.fuyuanshen.equipment.domain.query.DeviceQueryCriteria">
|
|
SELECT d.*
|
|
FROM device d
|
|
<where>
|
|
<!-- 时间范围等其他条件保持原样 -->
|
|
<if test="criteria.deviceName != null and criteria.deviceName.trim() != ''">
|
|
and d.device_name like concat('%', TRIM(#{criteria.deviceName}), '%')
|
|
</if>
|
|
<if test="criteria.deviceMac != null">
|
|
and d.device_mac = #{criteria.deviceMac}
|
|
</if>
|
|
<if test="criteria.deviceImei != null">
|
|
and d.device_imei = #{criteria.deviceImei}
|
|
</if>
|
|
<if test="criteria.deviceType != null">
|
|
and d.device_type = #{criteria.deviceType}
|
|
</if>
|
|
<if test="criteria.deviceStatus != null">
|
|
and d.device_status = #{criteria.deviceStatus}
|
|
</if>
|
|
<if test="criteria.currentOwnerId != null">
|
|
and d.current_owner_id = #{criteria.currentOwnerId}
|
|
</if>
|
|
<if test="criteria.params.beginTime != null and criteria.params.endTime != null">
|
|
and d.create_time between #{criteria.params.beginTime} and #{criteria.params.endTime}
|
|
</if>
|
|
</where>
|
|
</select>
|
|
|
|
<!-- 查询APP绑定设备列表 -->
|
|
<select id="queryAppBindDeviceList" resultType="com.fuyuanshen.equipment.domain.vo.AppDeviceVo">
|
|
select d.id, d.device_name, d.device_name,
|
|
d.device_name,
|
|
d.device_mac,
|
|
d.device_sn,
|
|
d.device_imei,
|
|
d.device_pic,
|
|
dt.type_name,
|
|
dt.communication_mode,
|
|
d.bluetooth_name,
|
|
dt.app_model_dictionary detailPageUrl,
|
|
c.binding_time
|
|
from device d
|
|
inner join device_type dt on d.device_type = dt.id
|
|
inner join app_device_bind_record c on d.id = c.device_id
|
|
where c.binding_user_id = #{criteria.bindingUserId}
|
|
<if test="criteria.deviceType != null">
|
|
and d.device_type = #{criteria.deviceType}
|
|
</if>
|
|
<if test="criteria.deviceName != null">
|
|
and d.device_name = #{criteria.deviceName}
|
|
</if>
|
|
<if test="criteria.deviceMac != null">
|
|
and d.device_mac = #{criteria.deviceMac}
|
|
</if>
|
|
<if test="criteria.deviceImei != null">
|
|
and d.device_imei = #{criteria.deviceImei}
|
|
</if>
|
|
</select>
|
|
|
|
|
|
<select id="queryAppDeviceList" resultType="com.fuyuanshen.equipment.domain.vo.AppDeviceVo">
|
|
select d.id,
|
|
d.device_name,
|
|
d.device_mac,
|
|
d.device_sn,
|
|
d.device_imei,
|
|
d.device_pic,
|
|
dt.type_name,
|
|
dt.communication_mode,
|
|
dt.app_model_dictionary detailPageUrl,
|
|
d.bluetooth_name
|
|
from device d
|
|
inner join device_type dt on d.device_type = dt.id
|
|
where d.binding_user_id = #{criteria.bindingUserId}
|
|
<if test="criteria.deviceType != null">
|
|
and d.device_type = #{criteria.deviceType}
|
|
</if>
|
|
<if test="criteria.deviceName != null">
|
|
and d.device_name = #{criteria.deviceName}
|
|
</if>
|
|
<if test="criteria.deviceMac != null">
|
|
and d.device_mac = #{criteria.deviceMac}
|
|
</if>
|
|
<if test="criteria.deviceImei != null">
|
|
and d.device_imei = #{criteria.deviceImei}
|
|
</if>
|
|
</select>
|
|
|
|
<!-- 获取分配设备的客户 -->
|
|
<select id="getAssignCustomer" resultType="com.fuyuanshen.equipment.domain.Device">
|
|
SELECT *
|
|
FROM device
|
|
WHERE original_device_id = #{customerId}
|
|
AND device_status = 1
|
|
</select>
|
|
|
|
<!-- 获取设备链 -->
|
|
<select id="findByOriginalDeviceId" resultType="com.fuyuanshen.equipment.domain.Device"
|
|
parameterType="java.lang.Long">
|
|
SELECT id, original_device_id
|
|
FROM device
|
|
WHERE original_device_id = #{originalDeviceId}
|
|
</select>
|
|
<select id="getDeviceInfo" resultType="com.fuyuanshen.equipment.domain.vo.AppDeviceVo">
|
|
select d.id,
|
|
d.device_name,
|
|
d.device_name,
|
|
d.device_name,
|
|
d.device_mac,
|
|
d.device_sn,
|
|
d.device_imei,
|
|
d.device_pic,
|
|
dt.type_name,
|
|
dt.communication_mode,
|
|
d.bluetooth_name,
|
|
dt.app_model_dictionary detailPageUrl
|
|
from device d
|
|
inner join device_type dt on d.device_type = dt.id
|
|
where d.device_mac = #{deviceMac}
|
|
</select>
|
|
<select id="queryWebDeviceList" resultType="com.fuyuanshen.equipment.domain.vo.WebDeviceVo">
|
|
select d.id, d.device_name, d.device_name,
|
|
d.device_name,
|
|
d.device_mac,
|
|
d.device_sn,
|
|
d.device_imei,
|
|
d.device_pic,
|
|
dt.type_name,
|
|
dt.communication_mode,
|
|
d.bluetooth_name,
|
|
dt.pc_model_dictionary detailPageUrl,
|
|
ap.name personnelBy,
|
|
d.device_status,
|
|
c.binding_time
|
|
from device d
|
|
inner join device_type dt on d.device_type = dt.id
|
|
inner join app_device_bind_record c on d.id = c.device_id
|
|
left join app_personnel_info ap on ap.device_id = d.id
|
|
where dt.communication_mode = 0
|
|
<if test="criteria.deviceType != null">
|
|
and d.device_type = #{criteria.deviceType}
|
|
</if>
|
|
<if test="criteria.deviceName != null and criteria.deviceName != ''">
|
|
and d.device_name like concat('%', #{criteria.deviceName}, '%')
|
|
</if>
|
|
<if test="criteria.deviceImei != null and criteria.deviceImei != ''">
|
|
and (d.device_imei = #{criteria.deviceImei}
|
|
</if>
|
|
<if test="criteria.content != null and criteria.content != ''">
|
|
AND d.device_imei = #{criteria.content} or d.device_mac = #{criteria.content}
|
|
</if>
|
|
<if test="criteria.deviceStatus != null">
|
|
and d.device_status = #{criteria.deviceStatus}
|
|
</if>
|
|
<if test="criteria.personnelBy != null and criteria.personnelBy != ''">
|
|
and ap.name like concat('%', #{criteria.personnelBy}, '%')
|
|
</if>
|
|
<if test="criteria.communicationMode != null">
|
|
and dt.communication_mode = #{criteria.communicationMode}
|
|
</if>
|
|
<if test="criteria.groupId != null">
|
|
and d.group_id = #{criteria.groupId}
|
|
</if>
|
|
</select>
|
|
<select id="getLocationHistory" resultType="com.fuyuanshen.equipment.domain.vo.LocationHistoryVo">
|
|
select a.id,a.device_name,a.device_type,b.type_name deviceTypeName,a.device_imei,a.device_mac from device a
|
|
inner join device_type b on a.device_type = b.id
|
|
|
|
<if test="bo.deviceType != null">
|
|
AND b.id = #{bo.deviceType}
|
|
</if>
|
|
<if test="bo.deviceName != null and bo.deviceName != ''">
|
|
AND a.device_name like concat('%',#{bo.deviceName},'%')
|
|
</if>
|
|
<if test="bo.deviceMac != null and bo.deviceMac != ''">
|
|
AND a.device_mac = #{bo.deviceMac}
|
|
</if>
|
|
<if test="bo.deviceImei != null and bo.deviceImei != ''">
|
|
AND a.device_imei = #{bo.deviceImei}
|
|
</if>
|
|
<if test="bo.content != null and bo.content != ''">
|
|
AND a.device_imei = #{bo.content} or a.device_mac = #{bo.content}
|
|
</if>
|
|
<if test="bo.startTime != null and bo.startTime != ''">
|
|
AND a.create_time <![CDATA[>=]]> #{bo.startTime}
|
|
</if>
|
|
<if test="bo.endTime != null and bo.endTime != ''">
|
|
AND a.create_time <![CDATA[<=]]> #{bo.endTime}
|
|
</if>
|
|
<if test="bo.groupId != null">
|
|
and a.group_id = #{bo.groupId}
|
|
</if>
|
|
ORDER BY
|
|
a.create_time DESC
|
|
</select>
|
|
|
|
<!-- 获取数据总览 -->
|
|
<select id="getDataOverview" resultType="com.fuyuanshen.equipment.domain.vo.DataOverviewVo">
|
|
SELECT (SELECT COUNT(1) FROM device) AS devicesNumber,
|
|
(SELECT COUNT(1) FROM device WHERE device_status = 1) AS equipmentOnline,
|
|
(SELECT COUNT(1) FROM device WHERE DATE (create_time) = CURDATE()) AS bindingNew, (
|
|
SELECT COUNT (1)
|
|
FROM device
|
|
WHERE device_status = 2) AS equipmentAbnormal
|
|
</select>
|
|
|
|
<!-- 获取设备分类 -->
|
|
<select id="getEquipmentClassification"
|
|
resultType="com.fuyuanshen.equipment.domain.vo.EquipmentClassificationVo">
|
|
SELECT (SELECT COUNT(1)
|
|
FROM device d
|
|
INNER JOIN device_type dt ON d.device_type = dt.id
|
|
WHERE dt.communication_mode = 0) AS equipment4G,
|
|
(SELECT COUNT(1)
|
|
FROM device d
|
|
INNER JOIN device_type dt ON d.device_type = dt.id
|
|
WHERE dt.communication_mode = 1) AS deviceBluetooth,
|
|
(SELECT COUNT(1)
|
|
FROM device d
|
|
INNER JOIN device_type dt ON d.device_type = dt.id
|
|
WHERE dt.communication_mode = 2) AS devices4GAndBluetooth
|
|
</select>
|
|
|
|
<!-- 获取告警信息 -->
|
|
<select id="getAlarmInformation" resultType="com.fuyuanshen.equipment.domain.vo.AlarmInformationVo">
|
|
SELECT (SELECT COUNT(1) FROM device_alarm WHERE treatment_state = 0 AND DATE (create_time) = CURDATE()) AS alarmsTotal, (
|
|
SELECT COUNT (1)
|
|
FROM device_alarm
|
|
WHERE treatment_state = 0
|
|
AND DATE (create_time) = CURDATE()) AS processingAlarm
|
|
, (
|
|
SELECT COUNT (1)
|
|
FROM device_alarm
|
|
WHERE device_action = 0
|
|
AND DATE (create_time) = CURDATE()) AS alarmForced
|
|
, (
|
|
SELECT COUNT (1)
|
|
FROM device_alarm
|
|
WHERE device_action = 1
|
|
AND DATE (create_time) = CURDATE()) AS intrusionImpact
|
|
, (
|
|
SELECT COUNT (1)
|
|
FROM device_alarm
|
|
WHERE device_action = 2
|
|
AND DATE (create_time) = CURDATE()) AS alarmManual
|
|
, (
|
|
SELECT COUNT (1)
|
|
FROM device_alarm
|
|
WHERE device_action = 3 AND DATE (create_time) = CURDATE()) AS fenceElectronic
|
|
|
|
</select>
|
|
|
|
<!-- 获取设备使用数据 -->
|
|
<select id="getEquipmentUsageData" resultType="map">
|
|
SELECT COUNT(CASE WHEN MONTH (dl.create_time) = 1 THEN 1 END) AS m1,
|
|
COUNT(CASE WHEN MONTH (dl.create_time) = 2 THEN 1 END) AS m2,
|
|
COUNT(CASE WHEN MONTH (dl.create_time) = 3 THEN 1 END) AS m3,
|
|
COUNT(CASE WHEN MONTH (dl.create_time) = 4 THEN 1 END) AS m4,
|
|
COUNT(CASE WHEN MONTH (dl.create_time) = 5 THEN 1 END) AS m5,
|
|
COUNT(CASE WHEN MONTH (dl.create_time) = 6 THEN 1 END) AS m6,
|
|
COUNT(CASE WHEN MONTH (dl.create_time) = 7 THEN 1 END) AS m7,
|
|
COUNT(CASE WHEN MONTH (dl.create_time) = 8 THEN 1 END) AS m8,
|
|
COUNT(CASE WHEN MONTH (dl.create_time) = 9 THEN 1 END) AS m9,
|
|
COUNT(CASE WHEN MONTH (dl.create_time) = 10 THEN 1 END) AS m10,
|
|
COUNT(CASE WHEN MONTH (dl.create_time) = 11 THEN 1 END) AS m11,
|
|
COUNT(CASE WHEN MONTH (dl.create_time) = 12 THEN 1 END) AS m12
|
|
FROM device_log dl
|
|
LEFT JOIN device d ON dl.device_id = d.id
|
|
LEFT JOIN device_type dt ON d.device_type = dt.id
|
|
WHERE dt.id = #{deviceId}
|
|
AND (
|
|
(#{range} = 1 AND dl.create_time >= DATE_SUB(NOW(), INTERVAL 6 MONTH)) OR
|
|
(#{range} = 2 AND dl.create_time >= DATE_SUB(NOW(), INTERVAL 12 MONTH))
|
|
)
|
|
</select>
|
|
|
|
<select id="getUsageDataForMonth" resultType="java.lang.Integer">
|
|
SELECT COUNT(*)
|
|
FROM device_log dl
|
|
WHERE dl.device_id = #{deviceId}
|
|
AND YEAR (
|
|
dl.create_time) = #{year}
|
|
AND MONTH (dl.create_time) = #{month}
|
|
</select>
|
|
|
|
</mapper> |