| <?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.api.mapper.DeviceMapper"> | 
|   | 
|     <!-- 通用查询映射结果 --> | 
|     <resultMap id="BaseResultMap" type="com.moral.api.entity.Device"> | 
|         <id column="id" property="id"/> | 
|         <result column="name" property="name"/> | 
|         <result column="mac" property="mac"/> | 
|         <result column="address" property="address"/> | 
|         <result column="longitude" property="longitude"/> | 
|         <result column="latitude" property="latitude"/> | 
|         <result column="state" property="state"/> | 
|         <result column="operate_ids" property="operateIds"/> | 
|         <result column="monitor_point_id" property="monitorPointId"/> | 
|         <result column="organization_id" property="organizationId"/> | 
|         <result column="guid" property="guid"/> | 
|         <result column="device_version_id" property="deviceVersionId"/> | 
|         <result column="profession" property="profession"/> | 
|         <result column="tech" property="tech"/> | 
|         <result column="detector" property="detector"/> | 
|         <result column="purchaser" property="purchaser"/> | 
|         <result column="create_time" property="createTime"/> | 
|         <result column="update_time" property="updateTime"/> | 
|         <result column="install_time" property="installTime"/> | 
|         <result column="is_delete" property="isDelete"/> | 
|         <result column="extend" property="extend"/> | 
|         <result column="town_code" property="townCode"/> | 
|     </resultMap> | 
|   | 
|     <resultMap id="resultMap" type="com.moral.api.pojo.vo.device.DeviceVO" extends="BaseResultMap"> | 
|         <!--工艺--> | 
|         <result column="tech_name" property="techName"/> | 
|   | 
|         <!--设备检测器--> | 
|         <result column="detector_name" property="detectorName"/> | 
|   | 
|         <!--采购商--> | 
|         <result column="purchaser_name" property="purchaserName"/> | 
|   | 
|         <!--组织--> | 
|         <association property="organization" javaType="com.moral.api.entity.Organization"> | 
|             <result column="org_id" property="id"/> | 
|             <result column="org_name" property="name"/> | 
|         </association> | 
|   | 
|         <!--站点--> | 
|         <association property="monitorPoint" javaType="com.moral.api.entity.MonitorPoint"> | 
|             <result column="mp_id" property="id"/> | 
|             <result column="mp_name" property="name"/> | 
|             <result column="mp_area_code" property="areaCode"/> | 
|             <result column="mp_city_code" property="cityCode"/> | 
|             <result column="mp_province_code" property="provinceCode"/> | 
|         </association> | 
|   | 
|         <!--国控站点--> | 
|         <association property="govMonitorPoint" javaType="com.moral.api.entity.GovMonitorPoint"> | 
|             <result column="gmp_guid" property="guid"/> | 
|             <result column="gmp_name" property="name"/> | 
|         </association> | 
|   | 
|         <!--型号--> | 
|         <association property="version" javaType="com.moral.api.entity.Version"> | 
|             <result column="version_id" property="id"/> | 
|             <result column="version_name" property="name"/> | 
|         </association> | 
|   | 
|         <!--乡镇街道--> | 
|         <association property="town" javaType="java.util.HashMap"> | 
|             <result column="town_code" property="townCode"/> | 
|             <result column="town_name" property="townName"/> | 
|         </association> | 
|   | 
|         <!--设备维护人--> | 
|         <collection property="operators" ofType="com.moral.api.entity.ManageAccount"> | 
|             <result column="operate_id" property="id" jdbcType="INTEGER"/> | 
|             <result column="operate_name" property="userName" jdbcType="VARCHAR"/> | 
|         </collection> | 
|   | 
|         <!--行业--> | 
|         <collection property="professions" ofType="java.util.HashMap"> | 
|             <result column="profession_key" property="dataKey" jdbcType="INTEGER"/> | 
|             <result column="profession_value" property="dataValue" jdbcType="VARCHAR"/> | 
|         </collection> | 
|     </resultMap> | 
|   | 
|     <resultMap id="queryDeviceUnitAlarmInfoMap" type="com.moral.api.entity.Device"> | 
|         <id column="d.id" property="id"/> | 
|         <result column="d.name" property="name"/> | 
|         <result column="d.mac" property="mac"/> | 
|         <result column="d.address" property="address"/> | 
|         <result column="d.longitude" property="longitude"/> | 
|         <result column="d.latitude" property="latitude"/> | 
|         <result column="d.operate_ids" property="operateIds"/> | 
|         <result column="d.monitor_point_id" property="monitorPointId"/> | 
|         <result column="d.organization_id" property="organizationId"/> | 
|         <result column="oua.version_id" property="deviceVersionId"/> | 
|         <result column="d.profession" property="profession"/> | 
|         <result column="d.tech" property="tech"/> | 
|         <result column="d.detector" property="detector"/> | 
|         <result column="d.purchaser" property="purchaser"/> | 
|         <result column="d.extend" property="extend" javaType="String" /> | 
|         <association property="version" column="d.device_version_id" javaType="com.moral.api.entity.Version"> | 
|             <id column="v.id" property="id"></id> | 
|             <result column="v.name" property="name"></result> | 
|             <collection column="d.device_version_id" property="sensors" ofType="com.moral.api.entity.Sensor"> | 
|                 <result column="oua.sensor_code" property="code" ></result> | 
|                 <result column="oua.unit_key" property="unitKey"></result> | 
|                 <result column="oua.show_unit_key" property="showUnitKey"></result> | 
|                 <result column="oua.alarm_level" property="alarmLevel" javaType="String" ></result> | 
|             </collection> | 
|         </association> | 
|     </resultMap> | 
|   | 
|     <select id="selectDeviceInfoById" resultMap="resultMap"> | 
|         SELECT | 
|             d.id, | 
|             d.`name`, | 
|             d.mac, | 
|             d.address, | 
|             d.longitude, | 
|             d.latitude, | 
|             d.operate_ids, | 
|             d.organization_id, | 
|             d.monitor_point_id, | 
|             d.device_version_id, | 
|             d.profession, | 
|             d.tech, | 
|             d.detector, | 
|             d.purchaser, | 
|             d.create_time, | 
|             d.install_time, | 
|             d.extend, | 
|             d.town_code, | 
|             sa.area_name town_name, | 
|             o.id org_id, | 
|             o.`name` org_name, | 
|             mp.id mp_id, | 
|             mp.`name` mp_name, | 
|             mp.area_code mp_area_code, | 
|             mp.city_code mp_city_code, | 
|             mp.province_code mp_province_code, | 
|             gmp.guid gmp_guid, | 
|             gmp.name gmp_name, | 
|             ma.id operate_id, | 
|             v.id version_id, | 
|             v.`name` version_name, | 
|             ma.user_name operate_name, | 
|             profession.dataKey profession_key, | 
|             profession.dataValue profession_value, | 
|             tech.dataValue tech_name, | 
|             detector.dataValue detector_name, | 
|             purchaser.dataValue purchaser_name | 
|         FROM device d | 
|                  LEFT JOIN version v | 
|                            on d.device_version_id=v.id | 
|                  LEFT JOIN `organization` o | 
|                            ON d.organization_id = o.id | 
|                  LEFT JOIN `monitor_point` mp | 
|                            ON mp.id = d.monitor_point_id | 
|                  LEFT JOIN `gov_monitor_point` gmp | 
|                            ON gmp.guid = d.guid | 
|                  LEFT JOIN `manage_account` ma | 
|                            ON FIND_IN_SET | 
|                                ( | 
|                                    ma.id, (SELECT operate_ids FROM device WHERE id = d.id) | 
|                                ) | 
|                  LEFT JOIN `sys_area` sa | 
|                            ON d.town_code = sa.area_code | 
|                  LEFT JOIN | 
|              ( | 
|                  SELECT sdt.`name`, sdd.dataKey, sdd.dataValue | 
|                  FROM sys_dict_type sdt, | 
|                       sys_dict_data sdd | 
|                  WHERE sdt.id = sdd.dict_type_id | 
|                  AND sdt.`name` = 'profession' | 
|                  AND sdd.is_delete = '0' | 
|              ) profession | 
|              ON FIND_IN_SET | 
|              ( | 
|                  profession.dataKey, (SELECT profession FROM device WHERE id = d.id) | 
|              ) | 
|   | 
|                  LEFT JOIN | 
|              ( | 
|                  SELECT sdt.`name`, sdd.dataKey, sdd.dataValue | 
|                  FROM sys_dict_type sdt, | 
|                       sys_dict_data sdd | 
|                  WHERE sdt.id = sdd.dict_type_id | 
|                  AND sdt.`name` = 'tech' | 
|                  AND sdd.is_delete = '0' | 
|              ) tech | 
|              ON d.tech = tech.dataKey | 
|   | 
|                  LEFT JOIN | 
|              ( | 
|                  SELECT sdt.`name`, sdd.dataKey, sdd.dataValue | 
|                  FROM sys_dict_type sdt, | 
|                       sys_dict_data sdd | 
|                  WHERE sdt.id = sdd.dict_type_id | 
|                  AND sdt.`name` = 'detector' | 
|                  AND sdd.is_delete = '0' | 
|              ) detector | 
|              ON d.detector = detector.dataKey | 
|   | 
|                  LEFT JOIN | 
|              ( | 
|                  SELECT sdt.`name`, sdd.dataKey, sdd.dataValue | 
|                  FROM sys_dict_type sdt, | 
|                       sys_dict_data sdd | 
|                  WHERE sdt.id = sdd.dict_type_id | 
|                  AND sdt.`name` = 'purchaser' | 
|                  AND sdd.is_delete = '0' | 
|              ) purchaser | 
|              ON d.purchaser = purchaser.dataKey | 
|         WHERE d.id = #{deviceId} | 
|     </select> | 
|   | 
|     <select id="queryDeviceUnitAlarmInfo" resultMap="queryDeviceUnitAlarmInfoMap"> | 
|         select | 
|             d.id as `d.id`, | 
|             d.mac as `d.mac`, | 
|             d.name as `d.name`, | 
|             d.address as `d.address`, | 
|             d.longitude as `d.longitude`, | 
|             d.latitude as `d.latitude`, | 
|             d.operate_ids as `d.operate_ids`, | 
|             d.monitor_point_id as `d.monitor_point_id`, | 
|             d.organization_id as `d.organization_id`, | 
|             d.profession as `d.profession`, | 
|             d.tech as `d.tech`, | 
|             d.detector as `d.detector`, | 
|             d.purchaser as `d.purchaser`, | 
|             d.extend as `d.extend`, | 
|             oua.version_id as `oua.version_id`, | 
|             oua.sensor_code as `oua.sensor_code`, | 
|             oua.unit_key as `oua.unit_key`, | 
|             oua.show_unit_key as `oua.show_unit_key`, | 
|             oua.alarm_level as `oua.alarm_level`, | 
|             v.id as `v.id`, | 
|             v.name as `v.name` | 
|         from | 
|             device d | 
|         join | 
|             version v | 
|         on | 
|             v.`id` = d.`device_version_id` and v.`is_delete` = 0 | 
|         join | 
|             organization_unit_alarm oua | 
|         on | 
|             d.`device_version_id` = oua.`version_id`   and d.`organization_id` = oua.`organization_id` and oua.`is_delete` = 0 | 
|         where | 
|             d.`is_delete` = 0; | 
|     </select> | 
|   | 
|   | 
| </mapper> |