AreaEquipmentServiceImpl.java
13.3 KB
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
package com.objecteye.service.impl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.objecteye.entity.*;
import com.objecteye.mapper.SyAreaEquipmentMapper;
import com.objecteye.mapper.SyEquipmentMapper;
import com.objecteye.service.AreaEquipmentService;
import com.objecteye.service.EquipmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
/**
* 服务实现层
*
* @author Administrator
*/
@Service
public class AreaEquipmentServiceImpl implements AreaEquipmentService {
@Autowired
private SyAreaEquipmentMapper areaEquipmentMapper;
@Autowired
private SyEquipmentMapper equipmentMapper;
private ArrayList<Integer> captureList = new ArrayList<>();
@Autowired
private EquipmentService equipmentService;
/**
* 查询全部
*/
@Override
public ArrayList<AreaEquipmentShow> findAll() {
SyAreaEquipmentExample example = new SyAreaEquipmentExample();
SyAreaEquipmentExample.Criteria criteria = example.createCriteria();
criteria.andParentIdEqualTo(0);
return getAll(0);
}
@Override
public ArrayList<AreaEquipmentShow> findAllEquip() {
SyAreaEquipmentExample example = new SyAreaEquipmentExample();
SyAreaEquipmentExample.Criteria criteria = example.createCriteria();
criteria.andParentIdEqualTo(0);
return getAllHandleEquip(0);
}
@Override
public ArrayList<AreaEquipmentShow> findAllEquipAndArea() {
SyAreaEquipmentExample example = new SyAreaEquipmentExample();
SyAreaEquipmentExample.Criteria criteria = example.createCriteria();
criteria.andParentIdEqualTo(0);
return getAllHandleEquipAndArea(0);
}
/**
* 查询全部设备id
*/
@Override
public List<Integer> findCaptureById(int id) {
captureList = new ArrayList<>();
return getAllCapture(id);
}
/**
* 查询全部设备id
*/
@Override
public List<HashMap<String, Object>> findCaptureMsgById(int id) {
List<Integer> captureById = findCaptureById(id);
List<HashMap<String, Object>> list = new ArrayList<>();
if (captureById != null && captureById.size() > 0) {
int size = captureById.size();
for (int i = 0; i < size; i++) {
HashMap<String, Object> map = new HashMap<>(16);
Integer id1 = captureById.get(i);
SyEquipment equipment = equipmentService.findOne(id1);
map.put("id", id1);
map.put("name", equipment.getEquipmentName());
map.put("status", equipment.getStatus());
list.add(map);
}
return list;
}
return null;
}
/**
* 按分页查询
*/
@Override
public PageResult findPage(int pageNum, int pageSize) {
PageHelper.startPage(pageNum, pageSize);
Page<SyAreaEquipment> page = (Page<SyAreaEquipment>) areaEquipmentMapper.selectByExample(null);
return new PageResult(page.getPages(), page.getResult());
}
/**
* 增加
*/
@Override
public int add(SyAreaEquipment areaEquipment) {
int insert = areaEquipmentMapper.insertSelective(areaEquipment);
return insert;
}
/**
* 修改
*/
@Override
public int update(SyAreaEquipment areaEquipment) {
return areaEquipmentMapper.updateByPrimaryKey(areaEquipment);
}
/**
* 根据ID获取实体
*
* @param id
* @return
*/
@Override
public SyAreaEquipment findOne(int id) {
return areaEquipmentMapper.selectByPrimaryKey(id);
}
/**
* 批量删除
*/
@Override
public void delete(int[] ids) {
for (int id : ids) {
SyAreaEquipment syAreaEquipment = areaEquipmentMapper.selectByPrimaryKey(id);
if (syAreaEquipment.getParentId() == 0) {
throw new RuntimeException("不予许删除根目录");
}
//得到所有子节点
List<SyAreaEquipment> list = getList(id);
//System.out.println(list);
int size = list.size();
if (list != null || size > 0) {
for (int i = 0; i < size; i++) {
//删除设备树中设备
SyAreaEquipment syAreaEquipment1 = list.get(i);
areaEquipmentMapper.deleteByPrimaryKey(syAreaEquipment1.getId());
//删除设备表中设备
Integer typeId = syAreaEquipment1.getTypeId();
equipmentMapper.deleteByPrimaryKey(typeId);
}
}
//删除区域
areaEquipmentMapper.deleteByPrimaryKey(id);
}
}
@Override
public int delete(int typeId) {
SyAreaEquipmentExample example = new SyAreaEquipmentExample();
SyAreaEquipmentExample.Criteria criteria = example.createCriteria();
criteria.andTypeIdEqualTo(typeId);
return areaEquipmentMapper.deleteByExample(example);
}
@Override
public PageResult findPage(SyAreaEquipment areaEquipment, int pageNum, int pageSize) {
PageHelper.startPage(pageNum, pageSize);
SyAreaEquipmentExample example = new SyAreaEquipmentExample();
SyAreaEquipmentExample.Criteria criteria = example.createCriteria();
if (areaEquipment != null) {
if (areaEquipment.getName() != null && areaEquipment.getName().length() > 0) {
criteria.andNameLike("%" + areaEquipment.getName() + "%");
}
}
Page<SyAreaEquipment> page = (Page<SyAreaEquipment>) areaEquipmentMapper.selectByExample(example);
return new PageResult(page.getPages(), page.getResult());
}
private List<SyAreaEquipment> getList(int parentId) {
SyAreaEquipmentExample example = new SyAreaEquipmentExample();
SyAreaEquipmentExample.Criteria criteria = example.createCriteria();
criteria.andParentIdEqualTo(parentId);
return areaEquipmentMapper.selectByExample(example);
}
private ArrayList<AreaEquipmentShow> getAllHandleEquip(int parentId) {
List<SyAreaEquipment> list = getList(parentId);
int size = list.size();
ArrayList<AreaEquipmentShow> areaEquipmentShows = new ArrayList<>();
if (size == 0) {
SyAreaEquipment syAreaEquipment = areaEquipmentMapper.selectByPrimaryKey(parentId);
AreaEquipmentShow areaEquipmentShow = new AreaEquipmentShow();
areaEquipmentShow.setId(syAreaEquipment.getId());
areaEquipmentShow.setParentId(syAreaEquipment.getParentId());
areaEquipmentShow.setIsEquipment(syAreaEquipment.getIsEquipment());
if (syAreaEquipment.getIsEquipment() == 0) {
areaEquipmentShow.setDisabled(true);
} else {
areaEquipmentShow.setDisabled(false);
}
areaEquipmentShow.setEquipmentNum(1);
areaEquipmentShow.setTitle(syAreaEquipment.getName());
areaEquipmentShow.setTypeId(syAreaEquipment.getTypeId());
areaEquipmentShow.setChildren(null);
return null;
}
for (int i = 0; i < size; i++) {
captureList = new ArrayList<>();
SyAreaEquipment syAreaEquipment = list.get(i);
AreaEquipmentShow areaEquipmentShow = new AreaEquipmentShow();
areaEquipmentShow.setId(syAreaEquipment.getId());
areaEquipmentShow.setIsEquipment(syAreaEquipment.getIsEquipment());
areaEquipmentShow.setParentId(syAreaEquipment.getParentId());
if (syAreaEquipment.getIsEquipment() == 0) {
areaEquipmentShow.setDisabled(true);
} else {
areaEquipmentShow.setDisabled(false);
}
List<Integer> captureById = findCaptureById(syAreaEquipment.getId());
if (captureById != null) {
areaEquipmentShow.setEquipmentNum(captureById.size());
}
areaEquipmentShow.setTitle(syAreaEquipment.getName());
areaEquipmentShow.setTypeId(syAreaEquipment.getTypeId());
areaEquipmentShow.setChildren(getAllHandleEquip(syAreaEquipment.getId()));
areaEquipmentShows.add(areaEquipmentShow);
}
return areaEquipmentShows;
}
private ArrayList<AreaEquipmentShow> getAllHandleEquipAndArea(int parentId) {
List<SyAreaEquipment> list = getList(parentId);
int size = list.size();
ArrayList<AreaEquipmentShow> areaEquipmentShows = new ArrayList<>();
if (size == 0) {
SyAreaEquipment syAreaEquipment = areaEquipmentMapper.selectByPrimaryKey(parentId);
AreaEquipmentShow areaEquipmentShow = new AreaEquipmentShow();
areaEquipmentShow.setId(syAreaEquipment.getId());
areaEquipmentShow.setParentId(syAreaEquipment.getParentId());
areaEquipmentShow.setIsEquipment(syAreaEquipment.getIsEquipment());
areaEquipmentShow.setEquipmentNum(1);
areaEquipmentShow.setTitle(syAreaEquipment.getName());
areaEquipmentShow.setTypeId(syAreaEquipment.getTypeId());
areaEquipmentShow.setChildren(null);
return null;
}
for (int i = 0; i < size; i++) {
captureList = new ArrayList<>();
SyAreaEquipment syAreaEquipment = list.get(i);
AreaEquipmentShow areaEquipmentShow = new AreaEquipmentShow();
areaEquipmentShow.setId(syAreaEquipment.getId());
areaEquipmentShow.setIsEquipment(syAreaEquipment.getIsEquipment());
areaEquipmentShow.setParentId(syAreaEquipment.getParentId());
List<Integer> captureById = findCaptureById(syAreaEquipment.getId());
if (captureById != null) {
areaEquipmentShow.setEquipmentNum(captureById.size());
}
areaEquipmentShow.setTitle(syAreaEquipment.getName());
areaEquipmentShow.setTypeId(syAreaEquipment.getTypeId());
areaEquipmentShow.setChildren(getAllHandleEquipAndArea(syAreaEquipment.getId()));
areaEquipmentShows.add(areaEquipmentShow);
}
return areaEquipmentShows;
}
private ArrayList<AreaEquipmentShow> getAll(int parentId) {
List<SyAreaEquipment> list = getList(parentId);
int size = list.size();
ArrayList<AreaEquipmentShow> areaEquipmentShows = new ArrayList<>();
if (size == 0) {
SyAreaEquipment syAreaEquipment = areaEquipmentMapper.selectByPrimaryKey(parentId);
AreaEquipmentShow areaEquipmentShow = new AreaEquipmentShow();
areaEquipmentShow.setId(syAreaEquipment.getId());
areaEquipmentShow.setParentId(syAreaEquipment.getParentId());
areaEquipmentShow.setIsEquipment(syAreaEquipment.getIsEquipment());
if (syAreaEquipment.getIsEquipment() == 0) {
areaEquipmentShow.setDisabled(false);
} else {
areaEquipmentShow.setDisabled(true);
}
areaEquipmentShow.setEquipmentNum(1);
areaEquipmentShow.setTitle(syAreaEquipment.getName());
areaEquipmentShow.setTypeId(syAreaEquipment.getTypeId());
areaEquipmentShow.setChildren(null);
return null;
}
for (int i = 0; i < size; i++) {
captureList = new ArrayList<>();
SyAreaEquipment syAreaEquipment = list.get(i);
AreaEquipmentShow areaEquipmentShow = new AreaEquipmentShow();
areaEquipmentShow.setId(syAreaEquipment.getId());
areaEquipmentShow.setIsEquipment(syAreaEquipment.getIsEquipment());
areaEquipmentShow.setParentId(syAreaEquipment.getParentId());
if (syAreaEquipment.getIsEquipment() == 0) {
areaEquipmentShow.setDisabled(false);
} else {
areaEquipmentShow.setDisabled(true);
}
List<Integer> captureById = findCaptureById(syAreaEquipment.getId());
if (captureById != null) {
areaEquipmentShow.setEquipmentNum(captureById.size());
}
areaEquipmentShow.setTitle(syAreaEquipment.getName());
areaEquipmentShow.setTypeId(syAreaEquipment.getTypeId());
areaEquipmentShow.setChildren(getAll(syAreaEquipment.getId()));
areaEquipmentShows.add(areaEquipmentShow);
}
return areaEquipmentShows;
}
private List<Integer> getAllCapture(int parentId) {
List<SyAreaEquipment> list = getList(parentId);
int size = list.size();
if (size == 0) {
SyAreaEquipment syAreaEquipment = areaEquipmentMapper.selectByPrimaryKey(parentId);
if (syAreaEquipment != null) {
Integer isEquipment = syAreaEquipment.getIsEquipment();
if (isEquipment == 1) {
captureList.add(syAreaEquipment.getTypeId());
}
return captureList;
}
return null;
}
for (int i = 0; i < size; i++) {
SyAreaEquipment syAreaEquipment = list.get(i);
getAllCapture(syAreaEquipment.getId());
}
return captureList;
}
}