kongzy
2024-07-01 47a751cb301d05276ae5d75145d57b2d090fe4e1
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
<?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.nanometer.smartlab.dao.SysContainerSensorsDao">
  <resultMap id="BaseResultMap" type="com.nanometer.smartlab.entity.SysContainerSensors">
    <id column="id" jdbcType="VARCHAR" property="id" />
    <result column="container_id" jdbcType="VARCHAR" property="containerId" />
    <result column="warehouse_container_name" jdbcType="VARCHAR" property="warehouseContainerName" />
    <result column="laboratory_container_name" jdbcType="VARCHAR" property="laboratoryContainerName" />
    <result column="temp" jdbcType="DOUBLE" property="temp" />
    <result column="humidity" jdbcType="INTEGER" property="humidity" />
    <result column="voc1" jdbcType="DOUBLE" property="voc1" />
    <result column="flag" jdbcType="INTEGER" property="flag" />
    <result column="type" jdbcType="TINYINT" property="type" />
    <result column="laboratory_name" jdbcType="VARCHAR" property="laboratoryName" />
    <result column="warehouse_name" jdbcType="VARCHAR" property="warehouseName" />
    <result column="laboratory_id" jdbcType="VARCHAR" property="laboratoryId" />
    <result column="warehouse_id" jdbcType="VARCHAR" property="warehouseId" />
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
  </resultMap>
  <sql id="Base_Column_List">
    id, container_id, temp, humidity, voc1, flag, type, update_time
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from sys_container_sensors
    where id = #{id,jdbcType=VARCHAR}
  </select>
  <delete id="deleteByPrimaryKey" >
    delete from sys_container_sensors
    where id = #{id,jdbcType=VARCHAR}
  </delete>
  <insert id="insertSelective" parameterType="com.nanometer.smartlab.entity.SysContainerSensors" useGeneratedKeys = "true" keyProperty = "id">
    insert into sys_container_sensors
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="containerId != null">
        container_id,
      </if>
      <if test="temp != null">
        temp,
      </if>
      <if test="humidity != null">
        humidity,
      </if>
      <if test="voc1 != null">
        voc1,
      </if>
      <if test="flag != null">
        flag,
      </if>
      <if test="type != null">
        type,
      </if>
      <if test="updateTime != null">
        update_time,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="containerId != null">
        #{containerId,jdbcType=VARCHAR},
      </if>
      <if test="temp != null">
        #{temp,jdbcType=DOUBLE},
      </if>
      <if test="humidity != null">
        #{humidity,jdbcType=INTEGER},
      </if>
      <if test="voc1 != null">
        #{voc1,jdbcType=INTEGER},
      </if>
      <if test="flag != null">
        #{flag,jdbcType=INTEGER},
      </if>
      <if test="type != null">
        #{type,jdbcType=BIT},
      </if>
      <if test="updateTime != null">
        #{updateTime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.nanometer.smartlab.entity.SysContainerSensors">
    update sys_container_sensors
    <set>
      <if test="containerId != null">
        container_id = #{containerId,jdbcType=VARCHAR},
      </if>
      <if test="temp != null">
        temp = #{temp,jdbcType=DOUBLE},
      </if>
      <if test="humidity != null">
        humidity = #{humidity,jdbcType=INTEGER},
      </if>
      <if test="voc1 != null">
        voc1 = #{voc1,jdbcType=INTEGER},
      </if>
      <if test="flag != null">
        flag = #{flag,jdbcType=INTEGER},
      </if>
      <if test="type != null">
        type = #{type,jdbcType=BIT},
      </if>
      <if test="updateTime != null">
        update_time = #{updateTime,jdbcType=TIMESTAMP},
      </if>
    </set>
    where id = #{id,jdbcType=VARCHAR}
  </update>
  <sql id="sql_where">
    <where>
      <if test="containerId != null ">
         and container_id = #{containerId,jdbcType=VARCHAR}
      </if>
      <if test="temp != null ">
         and temp = #{temp,jdbcType=DOUBLE}
      </if>
      <if test="humidity != null ">
         and humidity = #{humidity,jdbcType=INTEGER}
      </if>
      <if test="voc1 != null ">
         and voc1 = #{voc1,jdbcType=INTEGER}
      </if>
      <if test="flag != null ">
         and flag = #{flag,jdbcType=INTEGER}
      </if>
      <if test="type != null ">
         and type = #{type,jdbcType=BIT}
      </if>
      <if test="updateTime != null ">
         and update_time = #{updateTime,jdbcType=TIMESTAMP}
      </if>
      <if test="laboratoryName != null ">
        and l.name = #{laboratoryName,jdbcType=VARCHAR}
      </if>
      <if test="warehouseName != null ">
        and w.name = #{warehouseName,jdbcType=VARCHAR}
      </if>
      <if test="laboratoryNameLike != null ">
        and l.name like CONCAT('%','${laboratoryName}','%')
      </if>
      <if test="warehouseNameLike != null ">
        and w.name like CONCAT('%','${warehouseName}','%')
      </if>
      <if test="containerNameLike != null ">
        and (lc.name like CONCAT('%','${containerNameLike}','%') or wc.name like CONCAT('%','${containerNameLike}','%'))
      </if>
      <if test="laboratoryOrwarehouseNameLike != null">
        and (l.name like CONCAT('%','${laboratoryOrwarehouseNameLike}','%') or w.name like CONCAT('%','${laboratoryOrwarehouseNameLike}','%'))
      </if>
      <if test="beginUpdateTime != null ">
        and s.update_time >= #{beginUpdateTime}
      </if>
      <if test="endUpdateTime != null ">
        and s.update_time &lt;= #{endUpdateTime}
      </if>
    </where>
  </sql>
  <sql id="sql_limit">
    <if test="offset != null and limit != null">
      limit #{offset} , #{limit}
    </if>
  </sql>
  <sql id="sql_order">
    <if test="orderby != null">
      order by ${orderby}
    </if>
  </sql>
  <sql id="sql_groupby">
    <if test="groupby != null">
      group by ${groupby}
    </if>
  </sql>
  <select id="getListBySelective" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    select s.*,l.name laboratory_name,w.name warehouse_name,l.id laboratory_id,lc.name as laboratory_container_name, wc.name as warehouse_container_name, w.id warehouse_id from sys_container_sensors s
    left join sys_warehouse_container wc on wc.id = s.container_id
    left join sys_warehouse w on w.id = wc.warehouse_id
    left join sys_laboratory_container lc on lc.id = s.container_id
    left join sys_laboratory l on l.id = lc.laboratory_id
    <include refid="sql_where" />
    <include refid="sql_groupby" />
    <include refid="sql_order" />
    <include refid="sql_limit" />
  </select>
  <select id="countBySelective" parameterType="java.util.HashMap" resultType="int">
    select count(*) from (
     select count(distinct container_id) from sys_container_sensors s
    left join sys_warehouse_container wc on wc.id = s.container_id
    left join sys_warehouse w on w.id = wc.warehouse_id
    left join sys_laboratory_container lc on lc.id = s.container_id
    left join sys_laboratory l on l.id = lc.laboratory_id
    <include refid="sql_where" />
    <include refid="sql_groupby" />
    ) t
  </select>
 
  <select id="selectAll" parameterType="java.util.Map" resultType="com.nanometer.smartlab.entity.dto.ContainerStatusMngDto">
 
    SELECT slc.id,slc.temp, slc.humidity,slc.voc1 ,sl.name as laboratoryName,slc.name laboratoryContainerName,slc.flag,
    CASE
    WHEN substring(flag, 1,1) = '1' THEN TRUE ELSE FALSE END AS lowTempAlert,
    CASE
    WHEN substring(flag, 2,1) = '1' THEN TRUE ELSE FALSE END AS highTempAlert,
    CASE
    WHEN substring(flag, 3,1) = '1' THEN TRUE ELSE FALSE END AS lowHumidityAlert,
    CASE
    WHEN substring(flag, 4,1) = '1' THEN TRUE ELSE FALSE END AS highHumidityAlert,
    CASE
    WHEN substring(flag, 5,1) = '1' THEN TRUE ELSE FALSE END AS voc1Alert
    from sys_laboratory_container  slc
    LEFT JOIN sys_laboratory sl ON sl.id = slc.laboratory_id
 
    <where>
      slc.valid_flag=1
      <if test="laboratoryName != null and laboratoryName!=''">
        and sl.name like CONCAT('%','${laboratoryName}','%')
      </if>
      <if test="laboratoryContainerName != null and laboratoryContainerName!=''">
        and slc.name like CONCAT('%','${laboratoryContainerName}','%')
      </if>
    </where>
      ORDER BY
      slc.update_time DESC
      <include refid="sql_limit" />
 
  </select>
 
  <select id="countAll" resultType="int">
    select count(slc.id)
    from sys_laboratory_container  slc
    LEFT JOIN sys_laboratory sl ON sl.id = slc.laboratory_id
    <where>
    slc.valid_flag=1
    <if test="laboratoryName != null and laboratoryName!=''">
      and sl.name like CONCAT('%','${laboratoryName}','%')
    </if>
    <if test="laboratoryContainerName != null and laboratoryContainerName!=''">
      and slc.name like CONCAT('%','${laboratoryContainerName}','%')
    </if>
    </where>
    ORDER BY
    slc.update_time DESC
  </select>
    <select id="getRowData" resultType="com.nanometer.smartlab.entity.dto.ContainerStatusMngDto">
        SELECT slc.id,slc.temp, slc.humidity,slc.voc1 ,sl.name as laboratoryName,slc.name laboratoryContainerName,slc.flag,
    CASE
    WHEN substring(flag, 1,1) = '1' THEN TRUE ELSE FALSE END AS lowTempAlert,
    CASE
    WHEN substring(flag, 2,1) = '1' THEN TRUE ELSE FALSE END AS highTempAlert,
    CASE
    WHEN substring(flag, 3,1) = '1' THEN TRUE ELSE FALSE END AS lowHumidityAlert,
    CASE
    WHEN substring(flag, 4,1) = '1' THEN TRUE ELSE FALSE END AS highHumidityAlert,
    CASE
    WHEN substring(flag, 5,1) = '1' THEN TRUE ELSE FALSE END AS voc1Alert
    from sys_laboratory_container  slc
    LEFT JOIN sys_laboratory sl ON sl.id = slc.laboratory_id
    where slc.id = #{id}
 
 
    </select>
  <select id="selectMaxTemperature" resultType="java.util.Map">
    select max(s.temp) maxTemperature,min(s.temp) minTemperature
    from sys_container_sensors as s
    where
    s.container_id = #{id}
    and s.update_time &gt;= #{beginDate}
      <if test="endDate != null">
        and s.update_time &lt; #{endDate}
      </if>
  </select>
  <select id="selectMaxHumidity" resultType="java.util.Map">
    select max(s.humidity) maxHumidity, min(s.humidity) minHumidity
    from sys_container_sensors as s
    where
    s.container_id = #{id}
    and s.update_time &gt;= #{beginDate}
    <if test="endDate != null">
      and s.update_time &lt; #{endDate}
    </if>
  </select>
  <select id="selectMaxVoc" resultType="java.util.Map">
    select max(s.voc1) maxVoc, min(s.voc1) minVoc
    from sys_container_sensors as s
    where
    s.container_id = #{id}
    and s.update_time &gt;= #{beginDate}
    <if test="endDate != null">
      and s.update_time &lt; #{endDate}
    </if>
  </select>
</mapper>