xufenglei
2019-03-25 1830f5429730a40f7d2f17ca748a80a4b1046c21
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
<?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>
</mapper>