于紫祥_1901
2020-08-13 72bfd6cfe47b48a183ea3795054dabdcffb543d7
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<?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.SensorMapper">
    <resultMap id="BaseResultMap" type="com.moral.entity.Sensor">
        <id column="id" property="id" jdbcType="INTEGER"/>
        <result column="name" property="name" jdbcType="VARCHAR"/>
        <result column="sensor_key" property="sensorKey" jdbcType="VARCHAR"/>
        <result column="upper" property="upper" jdbcType="DOUBLE"/>
        <result column="lower" property="lower" jdbcType="DOUBLE"/>
        <result column="unit" property="unit" jdbcType="VARCHAR"/>
        <result column="description" property="description" jdbcType="VARCHAR"/>
    </resultMap>
    <sql id="Base_Column_List">
    id, name, sensor_key, upper, lower, unit, description
  </sql>
    <select id="selectByVersionId" resultMap="BaseResultMap" parameterType="java.lang.Integer">
        select
        <include refid="Base_Column_List"/>
        from sensor sen
        where EXISTS
        ( select id
        from device_version_sensor dvs
        where sen.id = dvs.sensor_id and dvs.device_version_id = #{deviceVersionId,jdbcType=INTEGER}
        )
    </select>
    <select id="selectByVersionNo" resultMap="BaseResultMap" parameterType="java.lang.Integer">
        select
        <include refid="Base_Column_List"/>
        from sensor sen
        where EXISTS
        ( select id
        from device_version_sensor dvs
        where sen.id = dvs.sensor_id
        and dvs.device_version_id in
        (
        select dev.id from device_version dev
        where dev.version = #{deviceVersionNo,jdbcType=INTEGER}
        )
        )
    </select>
    <select id="selectByVersionNos" resultMap="BaseResultMap" parameterType="java.util.List">
        select
        <include refid="Base_Column_List"/>
        from sensor sen
        where EXISTS
        ( select id
        from device_version_sensor dvs
        where sen.id = dvs.sensor_id
        and dvs.device_version_id in
        (
        select dev.id from device_version dev
        <where>
            1 > 1
            <if test="versionNos!=null and versionNos.size() > 0">
                or dev.version in
                <foreach collection="versionNos" item="versionNo" open="(" close=")" separator=",">
                    #{versionNo,jdbcType=INTEGER}
                </foreach>
            </if>
        </where>
        )
        )
    </select>
 
    <select id="getSensorsByDeviceVersionId" resultType="java.util.Map">
        SELECT
            s.* 
        FROM
            device_version_sensor dvs,
            sensor s 
        WHERE
            dvs.sensor_id = s.id 
            AND dvs.device_version_id = #{deviceVersionId}        
    </select>
 
    <select id="getSensorsByCriteria" resultMap="BaseResultMap">
        SELECT
        DISTINCT s.*
        FROM
        sensor s,
        device_version_sensor dvs,
        device d,
        monitor_point mp
        WHERE
        s.id = dvs.sensor_id
        AND dvs.device_version_id = d.device_version_id
        AND d.monitor_point_id = mp.id
        <if test="provinceCode != null">
            AND mp.province_code = #{provinceCode}
        </if>
        <if test="cityCode != null">
            AND mp.city_code = #{cityCode}
        </if>
        <if test="areaCode != null">
            AND mp.area_code = #{areaCode}
        </if>
        <if test="monitorPointId != null">
            AND mp.id = #{monitorPointId}
        </if>
        <if test="mac != null">
            AND d.mac = #{mac}
        </if>
        <if test="professionId != null">
            AND d.profession_id = #{professionId}
        </if>
    </select>
    <select id="selectByOrgId" resultMap="BaseResultMap">
          select * from sensor sen where sen.id in
            (
               select DISTINCT sensor_id from device_version_sensor dvs
                 where dvs.device_version_id
                 in (
                        select DISTINCT device_version_id from device dev where
                        EXISTS (select * from monitor_point mpt where
                         mpt.organization_id = #{organizationId,jdbcType=INTEGER} and mpt.id = dev.monitor_point_id
                         OR EXISTS  (
                                      SELECT * from dictionary_data
                                      where dict_data_key = 'auth_config_super_org' and dict_data_value = #{organizationId,jdbcType=INTEGER}
                                      )
                                )
                  )
              )
             order by sen.id asc
    </select>
 
    <select id="getSensorBySensorKey" resultType="java.util.Map">
        SELECT *
        FROM sensor
        WHERE sensor_key = #{sensor_key}
    </select>
 
    <select id="getSensorByDeviceId" resultType="java.util.Map">
        SELECT DISTINCT d.id,d.monitor_point_id,s.*
        FROM device d,device_version dv,device_version_sensor dvs,sensor s
        WHERE d.device_version_id = dvs.device_version_id
        AND dvs.sensor_id = s.id
        AND d.id = #{id}
    </select>
 
    <select id="getSensorByMonitorPointId" resultType="java.util.Map">
        SELECT DISTINCT s.sensor_key sensorKey,s.unit,s.name,s.description,s.id
        FROM device d,device_version dv,device_version_sensor dvs,sensor s
        WHERE d.device_version_id = dvs.device_version_id
        AND dvs.sensor_id = s.id
        AND d.monitor_point_id = #{monitor_point_id}
    </select>
 
    <select id="getSensorsByMac" resultMap="BaseResultMap">
        SELECT
        DISTINCT s.*
        FROM
        sensor s,
        device_version_sensor dvs,
        device d
        WHERE
        s.id = dvs.sensor_id
        AND dvs.device_version_id = d.device_version_id
        <if test="mac != null">
            AND d.mac = #{mac}
        </if>
    </select>
 
    <select id="getSensorsInfoByMac" resultMap="BaseResultMap">
        SELECT
        DISTINCT s.*
        FROM
        sensor s,
        device_version_sensor dvs,
        device d
        WHERE
        s.id = dvs.sensor_id
        AND dvs.device_version_id = d.device_version_id
        <if test="mac != null">
            AND d.mac = #{mac}
        </if>
    </select>
 
    <select id="selectSenosrsByOrgId" resultMap="BaseResultMap">
        select
        distinct dvs.sensor_id as id,
        s.name,s.sensor_key,s.unit,s.description
        from
        device_version_sensor dvs,
        sensor s
        where
        dvs.device_version_id
        in(
        select
        distinct d.device_version_id
        from
        device d
        where
        d.mac in
        <foreach collection="macs" open="(" separator="," close=")"
                 item="mac">
            #{mac}
        </foreach>
        )
        and dvs.sensor_id=s.id
    </select>
</mapper>