xufenglei
2017-12-07 dba72443e05e7b0a52ee85bfd9f4641aebc42c60
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?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">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed Nov 29 16:17:59 CST 2017.
    -->
    <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="operate_user_id" jdbcType="INTEGER" property="operateUserId" />
    <result column="state" jdbcType="CHAR" property="state" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="install_time" jdbcType="TIMESTAMP" property="installTime" />
    <result column="monitor_point_id" jdbcType="INTEGER" property="monitorPointId" />
    <result column="device_version_id" jdbcType="INTEGER" property="deviceVersionId" />
  </resultMap>
     <select id="getDeviceStatesByAccount" resultType="map">
        SELECT
            COUNT( d.state ) count,
            d.state 
        FROM
            device d
        <if test="orgIds != null and orgIds.size &gt; 0">
            ,monitor_point mp
        WHERE
            d.monitor_point_id = mp.id 
            AND mp.organization_id IN
            <foreach close=")" collection="orgIds" item="listItem" open="(" separator=",">
                #{listItem}
            </foreach>
        </if>
        GROUP BY d.state
    </select>
    <select id="getSensorsByDevice" resultType="map">
        SELECT
            s.`key`,
            s.`name` 
        FROM
            sensor s,
            device d,
            device_version_sensor dvs 
        WHERE
            d.mac = #{mac}
            AND d.device_version_id = dvs.version_id 
            AND dvs.sensor_id = s.id 
        ORDER BY
            s.id
    </select>
</mapper>