7.8
15832144755
2021-07-08 2080267e3245f0df9efc621c279922dc5ebb7c8e
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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
package com.hxzkoa.services;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import com.hxzkoa.json.tb_collector;
import com.hxzkoa.json.tb_gas;
import com.hxzkoa.json.tb_gas_history;
import com.hxzkoa.json.tb_tag;
import com.hxzkoa.util.Config;
import com.hxzkoa.util.ModifyConfig;
 
@Service
public class GasService {
    @PersistenceContext
    private EntityManager em;
    @Autowired
    private CaozuoService cs;
    
    public List<tb_gas> getSensorManagement() {
        String sql = null;
        Query query = null;
        sql = "SELECT id,wei_zhi,gas_type,nong_du,status,collect_ip,tong_dao,waring_zhi,ip,x,y,addtime FROM tb_gas";
        query = this.em.createNativeQuery(sql);
        List resultList = query.getResultList();
        List<tb_gas> tb_gasList = new ArrayList<tb_gas>();
        if (resultList.size() > 0) {
            for (int i = 0; i < resultList.size(); i++) {
                tb_gas gas = new tb_gas();
                Object[] obj = (Object[]) resultList.get(i);
                gas.setId((int) obj[0]);
                gas.setWei_zhi(obj[1] == null ? "" : obj[1].toString());
                gas.setGas_type(obj[2] == null ? "" : obj[2].toString());
                gas.setNong_du(obj[3] == null ? "" : obj[3].toString());
                gas.setStatus(obj[4] == null ? "" : obj[4].toString());
                gas.setCollect_ip(obj[5] == null ? "" : obj[5].toString());
                gas.setTong_dao(obj[6] == null ? "" : obj[6].toString());
                gas.setWaring_zhi(obj[7] == null ? "" : obj[7].toString());
                gas.setIp(obj[8] == null ? "" : obj[8].toString());
                gas.setX(obj[9] == null ? "" : obj[9].toString());
                gas.setY(obj[10] == null ? "" : obj[10].toString());
                gas.setAddtime(obj[11] == null ? "" : obj[11].toString());
                tb_gasList.add(gas);
            }
        }
        return tb_gasList;
    }
    
    public List<tb_gas> getSensorManagement(int page) {
        int perPage = Integer.parseInt(ModifyConfig.readData(Config.getPageConfig(), "perPage"));
        int start = (page - 1) * perPage;
        int end = perPage;
        String sql = null;
        Query query = null;
        sql = "SELECT id,wei_zhi,gas_type,nong_du,status,collect_ip,tong_dao,waring_zhi,ip,x,y,addtime FROM tb_gas LIMIT :start,:end";
        query = this.em.createNativeQuery(sql);
        query.setParameter("start", start);
        query.setParameter("end", end);
        List resultList = query.getResultList();
        List<tb_gas> tb_gasList = new ArrayList<tb_gas>();
        if (resultList.size() > 0) {
            for (int i = 0; i < resultList.size(); i++) {
                tb_gas gas = new tb_gas();
                Object[] obj = (Object[]) resultList.get(i);
                gas.setId((int) obj[0]);
                gas.setWei_zhi(obj[1] == null ? "" : obj[1].toString());
                gas.setGas_type(obj[2] == null ? "" : obj[2].toString());
                gas.setNong_du(obj[3] == null ? "" : obj[3].toString());
                gas.setStatus(obj[4] == null ? "" : obj[4].toString());
                gas.setCollect_ip(obj[5] == null ? "" : obj[5].toString());
                gas.setTong_dao(obj[6] == null ? "" : obj[6].toString());
                gas.setWaring_zhi(obj[7] == null ? "" : obj[7].toString());
                gas.setIp(obj[8] == null ? "" : obj[8].toString());
                gas.setX(obj[9] == null ? "" : obj[9].toString());
                gas.setY(obj[10] == null ? "" : obj[10].toString());
                gas.setAddtime(obj[11] == null ? "" : obj[11].toString());
                tb_gasList.add(gas);
            }
        }
        return tb_gasList;
    }
 
    public int getSensorManagementCount() {
        String sql = null;
        Query query = null;
        sql = "SELECT count(1) FROM tb_gas";
        query = this.em.createNativeQuery(sql);
        return Integer.parseInt(query.getSingleResult().toString());
    }
 
    public List<tb_gas> searchSensorManagement(String input) {
        int id = Integer.parseInt(input);
        String sql = null;
        Query query = null;
        sql = "SELECT id,wei_zhi,gas_type,nong_du,status,collect_ip,tong_dao,waring_zhi,ip,x,y,addtime FROM tb_gas WHERE id = :id";
        query = this.em.createNativeQuery(sql);
        query.setParameter("id", id);
        List resultList = query.getResultList();
        List<tb_gas> tb_gasList = new ArrayList<tb_gas>();
        if (resultList.size() > 0) {
            for (int i = 0; i < resultList.size(); i++) {
                tb_gas gas = new tb_gas();
                Object[] obj = (Object[]) resultList.get(i);
                gas.setId((int) obj[0]);
                gas.setWei_zhi(obj[1] == null ? "" : obj[1].toString());
                gas.setGas_type(obj[2] == null ? "" : obj[2].toString());
                gas.setNong_du(obj[3] == null ? "" : obj[3].toString());
                gas.setStatus(obj[4] == null ? "" : obj[4].toString());
                gas.setCollect_ip(obj[5] == null ? "" : obj[5].toString());
                gas.setTong_dao(obj[6] == null ? "" : obj[6].toString());
                gas.setWaring_zhi(obj[7] == null ? "" : obj[7].toString());
                gas.setIp(obj[8] == null ? "" : obj[8].toString()); 
                gas.setX(obj[9] == null ? "" : obj[9].toString());
                gas.setY(obj[10] == null ? "" : obj[10].toString());
                gas.setAddtime(obj[11] == null ? "" : obj[11].toString());
                tb_gasList.add(gas);
            }
        }
        return tb_gasList;
    }
 
    @Transactional
    public void sensorManagement_delete(String[] checkVal) {
        String sql = null;
        Query query = null;
        for (int i = 0; i < checkVal.length; i++) {
            int id = Integer.parseInt(checkVal[i]);
            sql = "DELETE FROM tb_gas WHERE id = :id";
            cs.tb_caozuo("tb_gas", 2);
            query = this.em.createNativeQuery(sql);
            query.setParameter("id", id);
            query.executeUpdate();
        }
    }
 
    @Transactional
    public void sensorManagement_deleteAll() {
        String sql = null;
        Query query = null;
        sql = "DELETE FROM tb_gas";
        cs.tb_caozuo("tb_gas", 2);
        query = this.em.createNativeQuery(sql);
        query.executeUpdate();
    }
    
    public List<tb_collector> getcollectorList() {
        String sql = null;
        Query query = null;
        sql = "SELECT macid,ip,macname FROM tb_collector";
        query = this.em.createNativeQuery(sql);
        List resultList = query.getResultList();
        List<tb_collector> tb_collectorList = new ArrayList<tb_collector>();
        if (resultList.size() > 0) {
            for (int i = 0; i < resultList.size(); i++) {
                tb_collector collector = new tb_collector();
                Object[] obj = (Object[]) resultList.get(i);
                collector.setMacid((int) obj[0]);
                collector.setIp(obj[1] == null ? "" : obj[1].toString());
                collector.setMacname(obj[2] == null ? "" : obj[2].toString());
                tb_collectorList.add(collector);
            }
        }
        return tb_collectorList;
    }
    
    public List<tb_collector> getmacName(String gasMacid) {
        String sql = null;
        Query query = null;
        sql = "SELECT id,macname FROM tb_collector WHERE macid = :id ";
        query = this.em.createNativeQuery(sql);
        query.setParameter("id", gasMacid);
        List resultList = query.getResultList();
        List<tb_collector> tb_collectorList = new ArrayList<tb_collector>();
        if (resultList.size() > 0) {
            for (int i = 0; i < resultList.size(); i++) {
                tb_collector gas = new tb_collector();
                Object[] obj = (Object[]) resultList.get(i);
                gas.setMacname(obj[1] == null ? "" : obj[1].toString());
                tb_collectorList.add(gas);
            }
        }
        return tb_collectorList;
    }
    
    @Transactional
    public int sensorManagement_add(tb_gas gas) {
        String sql = null;
        Query query = null;
        sql = "INSERT INTO tb_gas(id,gas_type,collect_ip,tong_dao,waring_zhi,ip,x,y,addtime,wei_zhi,nong_du,status) VALUES(:id,:gas_type,:collect_ip,:tong_dao,:waring_zhi,:ip,:x,:y,now(),:wei_zhi,:nong_du,:status)";
        cs.tb_caozuo("tb_gas", 1);
        query = this.em.createNativeQuery(sql);
        query.setParameter("id", gas.getId());
        query.setParameter("gas_type", gas.getGas_type());
        query.setParameter("collect_ip", gas.getCollect_ip());
        query.setParameter("tong_dao", gas.getTong_dao());
        query.setParameter("waring_zhi", gas.getWaring_zhi());
        query.setParameter("ip", gas.getIp());
        query.setParameter("x", gas.getX());
        query.setParameter("y", gas.getY());
        query.setParameter("nong_du", "0");
        query.setParameter("status", "正常");
        query.setParameter("wei_zhi", gas.getWei_zhi());
        int executeUpdate = query.executeUpdate();
        return executeUpdate;
    }
    
    @Transactional
    public int sensor_exist(String id) {
        String sql = null;
        Query query = null;
        sql = "SELECT count(1) FROM tb_gas WHERE id= :id";
        query = this.em.createNativeQuery(sql);
        query.setParameter("id", id);
        return Integer.parseInt(query.getSingleResult().toString());
    }
    
    @Transactional
    public int sensorManagement_modify(tb_gas gas) {
        String sql = null;
        Query query = null;
        sql = "UPDATE tb_gas SET gas_type = :gas_type,collect_ip = :collect_ip,tong_dao = :tong_dao,waring_zhi = :waring_zhi,ip = :ip,x = :x,y = :y,wei_zhi = :wei_zhi,addtime = now() WHERE id= :id";
        cs.tb_caozuo("tb_gas", 3);
        query = this.em.createNativeQuery(sql);
        query.setParameter("id", gas.getId());
        query.setParameter("gas_type", gas.getGas_type());
        query.setParameter("collect_ip", gas.getCollect_ip());
        query.setParameter("tong_dao", gas.getTong_dao());
        query.setParameter("waring_zhi", gas.getWaring_zhi());
        query.setParameter("ip", gas.getIp());
        query.setParameter("x", gas.getX());
        query.setParameter("y", gas.getY());
        query.setParameter("wei_zhi", gas.getWei_zhi());
        int executeUpdate = query.executeUpdate();
        return executeUpdate;
    }
    
    public List<tb_gas_history> getHistoricalDetection() {
        String sql = null;
        Query query = null;
        sql = "SELECT id,macid,name,type,x,y,deep,waring,addtime FROM tb_gas_history";
        query = this.em.createNativeQuery(sql);
        List resultList = query.getResultList();
        List<tb_gas_history> tb_gas_historyList = new ArrayList<tb_gas_history>();
        if (resultList.size() > 0) {
            for (int i = 0; i < resultList.size(); i++) {
                tb_gas_history gas_history = new tb_gas_history();
                Object[] obj = (Object[]) resultList.get(i);
                gas_history.setId((int) obj[0]);
                gas_history.setMacid(obj[1] == null ? "" : obj[1].toString());
                gas_history.setName(obj[2] == null ? "" : obj[2].toString());
                gas_history.setType(obj[3] == null ? "" : obj[3].toString());
                gas_history.setX((int) obj[4]);
                gas_history.setY((int) obj[5]);
                gas_history.setDeep(obj[6] == null ? "" : obj[6].toString());
                gas_history.setWaring(obj[7] == null ? "" : obj[7].toString());
                gas_history.setAddtime(obj[8] == null ? "" : obj[8].toString());
                tb_gas_historyList.add(gas_history);
            }
        }
        return tb_gas_historyList;
    }
 
    public List<tb_gas_history> getHistoricalDetection(int page) {
        int perPage = Integer.parseInt(ModifyConfig.readData(Config.getPageConfig(), "perPage"));
        int start = (page - 1) * perPage;
        int end = perPage;
        String sql = null;
        Query query = null;
        sql = "SELECT id,macid,name,type,x,y,deep,waring,addtime FROM tb_gas_history LIMIT :start,:end";
        query = this.em.createNativeQuery(sql);
        query.setParameter("start", start);
        query.setParameter("end", end);
        List resultList = query.getResultList();
        List<tb_gas_history> tb_gas_historyList = new ArrayList<tb_gas_history>();
        if (resultList.size() > 0) {
            for (int i = 0; i < resultList.size(); i++) {
                tb_gas_history gas_history = new tb_gas_history();
                Object[] obj = (Object[]) resultList.get(i);
                gas_history.setId((int) obj[0]);
                gas_history.setMacid(obj[1] == null ? "" : obj[1].toString());
                gas_history.setName(obj[2] == null ? "" : obj[2].toString());
                gas_history.setType(obj[3] == null ? "" : obj[3].toString());
                gas_history.setX(obj[4] == null ? (int)-1 :(int) obj[4]);
                gas_history.setY(obj[5] == null ? (int)-1 :(int) obj[5]);
                gas_history.setDeep(obj[6] == null ? "" : obj[6].toString());
                gas_history.setWaring(obj[7] == null ? "" : obj[7].toString());
                gas_history.setAddtime(obj[8] == null ? "" : obj[8].toString());
                tb_gas_historyList.add(gas_history);
            }
        }
        return tb_gas_historyList;
    }
 
    public List<tb_gas_history> searchHistoricalDetection(String input) {
        int id = Integer.parseInt(input);
        String sql = null;
        Query query = null;
        sql = "SELECT id,macid,name,type,x,y,deep,waring,addtime FROM tb_gas_history WHERE id = :id";
        query = this.em.createNativeQuery(sql);
        query.setParameter("id", id);
        List resultList = query.getResultList();
        List<tb_gas_history> tb_gas_historyList = new ArrayList<tb_gas_history>();
        if (resultList.size() > 0) {
            for (int i = 0; i < resultList.size(); i++) {
                tb_gas_history gas_history = new tb_gas_history();
                Object[] obj = (Object[]) resultList.get(i);
                gas_history.setId((int) obj[0]);
                gas_history.setMacid(obj[1] == null ? "" : obj[1].toString());
                gas_history.setName(obj[2] == null ? "" : obj[2].toString());
                gas_history.setType(obj[3] == null ? "" : obj[3].toString());
                gas_history.setX((int) obj[4]);
                gas_history.setY((int) obj[5]);
                gas_history.setDeep(obj[6] == null ? "" : obj[6].toString());
                gas_history.setWaring(obj[7] == null ? "" : obj[7].toString());
                gas_history.setAddtime(obj[8] == null ? "" : obj[8].toString());
                tb_gas_historyList.add(gas_history);
            }
        }
        return tb_gas_historyList;
    }
 
    public int getHistoricalDetectionCount() {
        String sql = null;
        Query query = null;
        sql = "SELECT count(1) FROM tb_gas_history";
        query = this.em.createNativeQuery(sql);
        return Integer.parseInt(query.getSingleResult().toString());
    }
 
    @Transactional
    public void historicalDetection_delete(String[] checkVal) {
        String sql = null;
        Query query = null;
        for (int i = 0; i < checkVal.length; i++) {
            int id = Integer.parseInt(checkVal[i]);
            sql = "DELETE FROM tb_gas_history WHERE id = :id";
            cs.tb_caozuo("tb_gas_history", 2);
            query = this.em.createNativeQuery(sql);
            query.setParameter("id", id);
            query.executeUpdate();
        }
    }
 
    @Transactional
    public void historicalDetection_deleteAll() {
        String sql = null;
        Query query = null;
        sql = "DELETE FROM tb_gas_history";
        cs.tb_caozuo("tb_gas_history", 2);
        query = this.em.createNativeQuery(sql);
        query.executeUpdate();
    }
 
    public List<tb_collector> getCollectorManagement() {
        String sql = null;
        Query query = null;
        sql = "SELECT id,macid,startip,datlenth,ip,macname,posx,posy,addtime FROM tb_collector";
        query = this.em.createNativeQuery(sql);
        List resultList = query.getResultList();
        List<tb_collector> tb_collectorList = new ArrayList<tb_collector>();
        if (resultList.size() > 0) {
            for (int i = 0; i < resultList.size(); i++) {
                tb_collector collector = new tb_collector();
                Object[] obj = (Object[]) resultList.get(i);
                collector.setId((int) obj[0]);
                collector.setMacid((int) obj[1]);
                collector.setStartip((int) obj[2]);
                collector.setDatlenth((int) obj[3]);
                collector.setIp(obj[4] == null ? "" : obj[4].toString());
                collector.setMacname(obj[5] == null ? "" : obj[5].toString());
                collector.setPosx((int) obj[6]);
                collector.setPosy((int) obj[7]);
                collector.setAddtime((Date) obj[8]);
                tb_collectorList.add(collector);
            }
        }
        return tb_collectorList;
    }
    
    public List<tb_collector> getCollectorManagement(int page) {
        int perPage = Integer.parseInt(ModifyConfig.readData(Config.getPageConfig(), "perPage"));
        int start = (page - 1) * perPage;
        int end = perPage;
        String sql = null;
        Query query = null;
        sql = "SELECT id,macid,startip,datlenth,ip,macname,posx,posy,addtime FROM tb_collector LIMIT :start,:end";
        query = this.em.createNativeQuery(sql);
        query.setParameter("start", start);
        query.setParameter("end", end);
        List resultList = query.getResultList();
        List<tb_collector> tb_collectorList = new ArrayList<tb_collector>();
        if (resultList.size() > 0) {
            for (int i = 0; i < resultList.size(); i++) {
                tb_collector collector = new tb_collector();
                Object[] obj = (Object[]) resultList.get(i);
                collector.setId((int) obj[0]);
                collector.setMacid((int) obj[1]);
                collector.setStartip((int) obj[2]);
                collector.setDatlenth((int) obj[3]);
                collector.setIp(obj[4] == null ? "" : obj[4].toString());
                collector.setMacname(obj[5] == null ? "" : obj[5].toString());
                collector.setPosx((int) obj[6]);
                collector.setPosy((int) obj[7]);
                collector.setAddtime((Date) obj[8]);
                tb_collectorList.add(collector);
            }
        }
        return tb_collectorList;
    }
 
    public List<tb_collector> searchCollectorManagement(String input) {
 
        int id = Integer.parseInt(input);
        String sql = null;
        Query query = null;
        sql = "SELECT id,macid,startip,datlenth,ip,macname,posx,posy,addtime FROM tb_collector WHERE id = :id";
        query = this.em.createNativeQuery(sql);
        query.setParameter("id", id);
        List resultList = query.getResultList();
        List<tb_collector> tb_collectorList = new ArrayList<tb_collector>();
        if (resultList.size() > 0) {
            for (int i = 0; i < resultList.size(); i++) {
                tb_collector collector = new tb_collector();
                Object[] obj = (Object[]) resultList.get(i);
                collector.setId((int) obj[0]);
                collector.setMacid((int) obj[1]);
                collector.setStartip((int) obj[2]);
                collector.setDatlenth((int) obj[3]);
                collector.setIp(obj[4] == null ? "" : obj[4].toString());
                collector.setMacname(obj[5] == null ? "" : obj[5].toString());
                collector.setPosx((int) obj[6]);
                collector.setPosy((int) obj[7]);
                collector.setAddtime((Date) obj[8]);
                tb_collectorList.add(collector);
            }
        }
        return tb_collectorList;
    }
 
    public int getCollectorManagementCount() {
        String sql = null;
        Query query = null;
        sql = "SELECT count(1) FROM tb_collector";
        query = this.em.createNativeQuery(sql);
        return Integer.parseInt(query.getSingleResult().toString());
    }
 
    @Transactional
    public void collectorManagement_delete(String[] checkVal) {
        String sql = null;
        Query query = null;
        for (int i = 0; i < checkVal.length; i++) {
            int id = Integer.parseInt(checkVal[i]);
            sql = "DELETE FROM tb_collector WHERE id = :id";
            cs.tb_caozuo("tb_collector", 2);
            query = this.em.createNativeQuery(sql);
            query.setParameter("id", id);
            query.executeUpdate();
        }
    }
 
    @Transactional
    public void collectorManagement_deleteAll() {
        String sql = null;
        Query query = null;
        sql = "DELETE FROM tb_collector";
        cs.tb_caozuo("tb_collector", 2);
        query = this.em.createNativeQuery(sql);
        query.executeUpdate();
    }
    
    @Transactional
    public int collectorManagement_add(tb_collector collector) {
        String sql = null;
        Query query = null;
        sql = "INSERT INTO tb_collector(macid,startip,datlenth,ip,macname,posx,posy,addtime) VALUES(:macid,:startip,:datlenth,:ip,:macname,:posx,:posy,now())";
        cs.tb_caozuo("tb_collector", 1);
        query = this.em.createNativeQuery(sql);
        query.setParameter("macid", collector.getMacid());
        query.setParameter("startip", collector.getStartip());
        query.setParameter("datlenth", collector.getDatlenth());
        query.setParameter("ip", collector.getIp());
        query.setParameter("macname", collector.getMacname());
        query.setParameter("posx", collector.getPosx());
        query.setParameter("posy", collector.getPosy());
        int executeUpdate = query.executeUpdate();
        return executeUpdate;
    }
    
    
    @Transactional
    public int collectorManagement_modify(tb_collector collector) {
        String sql = null;
        Query query = null;
        sql = "UPDATE tb_collector SET macid = :macid,startip = :startip,datlenth = :datlenth,ip = :ip,macname = :macname,posx = :posx,posy = :posy,addtime = now() WHERE id= :id";
        cs.tb_caozuo("tb_collector", 3);
        query = this.em.createNativeQuery(sql);
        query.setParameter("id", collector.getId());
        query.setParameter("macid", collector.getMacid());
        query.setParameter("startip", collector.getStartip());
        query.setParameter("datlenth", collector.getDatlenth());
        query.setParameter("ip", collector.getIp());
        query.setParameter("macname", collector.getMacname());
        query.setParameter("posx", collector.getPosx());
        query.setParameter("posy", collector.getPosy());
        int executeUpdate = query.executeUpdate();
        return executeUpdate;
    }
    
    /**获取某个采集仪所占用的通道数意思就是安装了几个气体传感器*/
    @Transactional
    public int getGasNumber(String ip) {
        String sql = null;
        Query query = null;
        sql = "SELECT count(1) FROM tb_gas WHERE ip = :ip";
        query = this.em.createNativeQuery(sql);
        query.setParameter("ip", ip);
        return Integer.parseInt(query.getSingleResult().toString());    
    }
    
    public List<tb_gas> getGas(String tong_dao ,String ip ) {
        String sql = null;
        Query query = null;
        sql = "SELECT id,wei_zhi,gas_type,nong_du,status,collect_ip,tong_dao,waring_zhi,ip,x,y,addtime FROM tb_gas WHERE ip=:ip AND tong_dao=:tong_dao ";
        query = this.em.createNativeQuery(sql);
        query.setParameter("ip", ip);
        query.setParameter("tong_dao", tong_dao);
        List resultList = query.getResultList();
        List<tb_gas> tb_gasList = new ArrayList<tb_gas>();
        if (resultList.size() > 0) {
            for (int i = 0; i < resultList.size(); i++) {
                tb_gas gas = new tb_gas();
                Object[] obj = (Object[]) resultList.get(i);
                gas.setId((int) obj[0]);
                gas.setWei_zhi(obj[1] == null ? "" : obj[1].toString());
                gas.setGas_type(obj[2] == null ? "" : obj[2].toString());
                gas.setNong_du(obj[3] == null ? "" : obj[3].toString());
                gas.setStatus(obj[4] == null ? "" : obj[4].toString());
                gas.setCollect_ip(obj[5] == null ? "" : obj[5].toString());
                gas.setTong_dao(obj[6] == null ? "" : obj[6].toString());
                gas.setWaring_zhi(obj[7] == null ? "" : obj[7].toString());
                gas.setIp(obj[8] == null ? "" : obj[8].toString());
                gas.setX(obj[9] == null ? "" : obj[9].toString());
                gas.setY(obj[10] == null ? "" : obj[10].toString());
                gas.setAddtime(obj[11] == null ? "" : obj[11].toString());
                tb_gasList.add(gas);
            }
        }
        return tb_gasList;
    }
    
    @Transactional
    public void modifyWarning(tb_gas gas) {
        String sql = null;
        Query query = null;
        sql = "UPDATE tb_gas SET status = :status,nong_du=:nong_du,addtime=now() WHERE id= :id";
        cs.tb_caozuo("tb_gas", 3);
        query = this.em.createNativeQuery(sql);
        query.setParameter("id", gas.getId());
        query.setParameter("status", gas.getStatus());
        query.setParameter("nong_du", gas.getNong_du());
        query.executeUpdate();
    }
    
 
}