EqpDaoImpl.java
14.1 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
363
package com.zteits.park.dao.impl;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import com.zteits.clouds.api.dto.park.dto.*;
import com.zteits.clouds.api.dto.pda.param.QueryEqpByPlNoAndOrtherRequest;
import com.zteits.park.constant.ParkConstant;
import com.zteits.park.service.telecomiot.deviceManagement.DeleteDirectlyConnectedDevice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xiaoleilu.hutool.util.CollectionUtil;
import com.zteits.clouds.api.apibase.constants.DataStatusEnum;
import com.zteits.clouds.api.apibase.constants.ErrorType;
import com.zteits.clouds.api.apibase.exception.BizException;
import com.zteits.clouds.api.dto.park.param.QueryEqpRequest;
import com.zteits.park.constant.EqpConstant;
import com.zteits.park.dao.EqpDao;
import com.zteits.park.domain.TpPEqp;
import com.zteits.park.domain.TpPEqpExample;
import com.zteits.park.domain.TpPEqpExample.Criteria;
import com.zteits.park.mapper.TpPEqpMapper;
import com.zteits.park.mapper.smapper.TpPEqpSMapper;
import org.springframework.transaction.annotation.Transactional;
@Component
public class EqpDaoImpl implements EqpDao {
@Autowired
private TpPEqpMapper tpPEqpMapper;
@Autowired
private TpPEqpSMapper tpPEqpSMapper;
@Override
public List<TpPEqp> selectEqpByEqpNo(String eqpNo) {
if(StringUtils.isBlank(eqpNo)){
return null;
}
TpPEqpExample example = new TpPEqpExample();
example.createCriteria().andEqpNoEqualTo(eqpNo)
.andDataStateEqualTo(DataStatusEnum.DATA_STATUS_VALID.value());
return tpPEqpMapper.selectByExample(example );
}
@Override
public List<TpPEqp> selectEqpByEqpNo(Long orgId, String eqpNo) {
if(StringUtils.isBlank(eqpNo)){
return null;
}
if(null == orgId){
return null;
}
TpPEqpExample example = new TpPEqpExample();
example.createCriteria().andEqpNoEqualTo(eqpNo)
.andOrgIdEqualTo(orgId)
.andDataStateEqualTo(DataStatusEnum.DATA_STATUS_VALID.value());
return tpPEqpMapper.selectByExample(example );
}
@Override
public TpPEqp selectEqpByBerthNo(String berthNo, String plNo,int eqpType,Integer usedType) {
TpPEqpExample example = new TpPEqpExample();
Criteria sql = example.createCriteria();
sql.andBerthNoEqualTo(berthNo)
.andPlNoEqualTo(plNo)
.andEqpTypeEqualTo(eqpType)
.andDataStateEqualTo(DataStatusEnum.DATA_STATUS_VALID.value());
if(usedType!=null){
sql.andUsedTypeEqualTo(usedType);
}
List<TpPEqp> tpPEqps = tpPEqpMapper.selectByExample(example );
if(CollectionUtils.isEmpty(tpPEqps)){
return null;
}
return tpPEqps.get(0);
}
@Override
public TpPEqp selectEqpByEqpNoAndFactory(String eqpNo, String factoryNo) {
TpPEqpExample example = new TpPEqpExample();
example.createCriteria().andEqpNoEqualTo(eqpNo)
.andFactoryNoEqualTo(factoryNo)
.andDataStateEqualTo(DataStatusEnum.DATA_STATUS_VALID.value());
List<TpPEqp> tpPEqps = tpPEqpMapper.selectByExample(example );
if(CollectionUtils.isEmpty(tpPEqps)){
return null;
}
if(tpPEqps.size()>1){
throw new BizException(ErrorType.BIZ_ERROR,"根据厂家编号["+factoryNo+"]和设备编号["+eqpNo+"]查询到多条设备信息");
}
return tpPEqps.get(0);
}
@Override
public int updateEqpStatusById(String eqpIsOnline, String electricity, String voltag, Date inoutTime,
Long id,String gatewayNo,Integer magRssi) {
TpPEqp record = new TpPEqp();
record.setElectricity(electricity);
record.setEqpIsOnline(eqpIsOnline);
record.setVoltag(voltag);
record.setHeartbeatTime(inoutTime==null?new Date():inoutTime);
record.setInOutTime(inoutTime);
record.setId(id);
record.setGatewayNo(gatewayNo);
record.setRssi(magRssi);
record.setModifyTime(new Date());
return tpPEqpMapper.updateByPrimaryKeySelective(record );
}
@Override
public int updateEqpStatusByEqpNo(String eqpIsOnline, Date heartbeatTime, List<String> eqpNo,Integer eqpType) {
TpPEqpExample example = new TpPEqpExample();
Criteria sql = example.createCriteria();
sql.andEqpNoIn(eqpNo);
sql.andEqpTypeEqualTo(eqpType);
sql.andDataStateEqualTo(DataStatusEnum.DATA_STATUS_VALID.value());
TpPEqp record = new TpPEqp();
record.setEqpIsOnline(eqpIsOnline);
record.setHeartbeatTime(heartbeatTime==null?new Date():heartbeatTime);
record.setModifyTime(new Date());
return tpPEqpMapper.updateByExampleSelective(record, example);
}
@Override
public Integer batchUpdateEqpStateForFault(String plNo,Integer eqpType) {
if(StringUtils.isBlank(plNo)){
return 0;
}
TpPEqpExample example = new TpPEqpExample();
example.createCriteria().andPlNoEqualTo(plNo)
.andEqpTypeEqualTo(eqpType)
.andDataStateEqualTo(DataStatusEnum.DATA_STATUS_VALID.value());
TpPEqp record = new TpPEqp();
record.setEqpIsOnline(EqpConstant.IS_ONLINE.OFF_LINE);
record.setModifyTime(new Date());
return tpPEqpMapper.updateByExampleSelective(record, example);
}
@Override
public int updateEqpStatusByBerthsNo(String eqpIsOnline, List<String> berthNos, String plNo,
Integer eqpType) {
TpPEqpExample example = new TpPEqpExample();
Criteria sql = example.createCriteria();
sql.andBerthNoIn(berthNos)
.andPlNoEqualTo(plNo)
.andEqpTypeEqualTo(eqpType);
sql.andDataStateEqualTo(DataStatusEnum.DATA_STATUS_VALID.value());
TpPEqp record = new TpPEqp();
record.setEqpIsOnline(eqpIsOnline);
record.setHeartbeatTime(new Date());
record.setModifyTime(new Date());
return tpPEqpMapper.updateByExampleSelective(record, example);
}
@Override
public Map<String, List<Integer>> queryEqpTypeByPlNos(List<String> plNos) {
Map<String, List<Integer>> listMap = new HashMap<>();
if (CollectionUtil.isEmpty(plNos)) {
return listMap;
}
List<Map<String, Object>> mapResult = tpPEqpSMapper.queryEqpTypeByPlNos(plNos);
for (Map<String, Object> tempMap : mapResult) {
String plNo = (String)tempMap.get("key");
List<Integer> eqpTypesIds = new ArrayList<>();
String[] temps = ((String)tempMap.get("value")).split(",");
for (String temp : temps) {
eqpTypesIds.add(Integer.valueOf(temp));
}
listMap.put(plNo, eqpTypesIds);
}
return listMap;
}
@Override
public PageInfo<TpPEqp> queryEqpsForPage(QueryEqpRequest request) {
//设置分页信息
PageHelper.startPage(request.getBaseRequest().getPageNum(), request.getBaseRequest().getPageSize());
// TpPEqpExample example = new TpPEqpExample();
// Criteria sql = example.createCriteria();
// Criteria sql2 = example.createCriteria();
// if(CollectionUtil.isNotEmpty(request.getPlNos())){
// sql.andPlNoIn(request.getPlNos());
// sql2.andPlNoIn(request.getPlNos());
// }
//
// if(!StringUtils.isBlank(request.getBerthNo())){
// sql.andBerthNoLike('%'+request.getBerthNo()+'%');
// sql2.andBerthNoLike('%'+request.getBerthNo()+'%');
// }
// if(!StringUtils.isBlank(request.getEqpIsOnline())){
// sql.andEqpIsOnlineEqualTo(request.getEqpIsOnline());
// sql2.andEqpIsOnlineEqualTo(request.getEqpIsOnline());
// }
// if(!StringUtils.isBlank(request.getEqpNo())){
// sql.andEqpNoLike('%'+request.getEqpNo()+'%');
// sql2.andEqpNoLike('%'+request.getEqpNo()+'%');
// }
// if(CollectionUtils.isNotEmpty(request.getFactoryNos())){
// sql.andFactoryNoIn(request.getFactoryNos());
// sql2.andFactoryNoIn(request.getFactoryNos());
// }
// if(null != request.getOrgId()){
// sql.andOrgIdEqualTo(request.getOrgId());
// sql2.andOrgIdEqualTo(request.getOrgId());
// }
// if(null != request.getHeartbeatTime()){
// sql.andHeartbeatTimeLessThanOrEqualTo(request.getHeartbeatTime());
// sql2.andHeartbeatTimeLessThanOrEqualTo(request.getHeartbeatTime());
// }
// if(null != request.getInOutTime()){
// sql.andInOutTimeLessThanOrEqualTo(request.getInOutTime());
// sql2.andInOutTimeLessThanOrEqualTo(request.getInOutTime());
// }
//
// sql.andDataStateEqualTo(DataStatusEnum.DATA_STATUS_VALID.value());
// sql2.andDataStateEqualTo(DataStatusEnum.DATA_STATUS_VALID.value());
// if(request.getUsedType()!=null){
// if(request.getUsedType() == 20){
// sql.andUsedTypeEqualTo(request.getUsedType());
// }
// if(request.getUsedType() == 10){
// sql.andUsedTypeIsNull();
// sql2.andUsedTypeNotEqualTo(20);
// example.or(sql2);
// }
// }
// example.setOrderByClause("create_time DESC");
// List<TpPEqp> tpPEqps = tpPEqpMapper.selectByExample(example );
List<TpPEqp> tpPEqps = tpPEqpSMapper.queryEqpsForPage(request);
return (tpPEqps != null && tpPEqps.size() >0) ? new PageInfo<TpPEqp>(tpPEqps) : new PageInfo<TpPEqp>(new ArrayList<TpPEqp>());
}
@Override
public void insertEqpInfo(TpPEqp tpPEqp) {
tpPEqpMapper.insertSelective(tpPEqp);
}
@Override
public void deleteEqpsByIds(List<Long> ids,Long opId) {
if(CollectionUtils.isEmpty(ids)){
return;
}
TpPEqpExample example = new TpPEqpExample();
example.createCriteria().andIdIn(ids);
TpPEqp record = new TpPEqp();
record.setDataState(DataStatusEnum.DATA_STATUS_NO_VALID.value());
record.setModifyOp(opId);
record.setModifyTime(new Date());
record.setOptFlg(ParkConstant.OptFlag.DELETE);
tpPEqpMapper.updateByExampleSelective(record , example );
}
@Override
@Transactional
public void deleteEqpById(TpPEqpDTO eqpDTO, Long opId,String appId,String secret,String baseUrl) {
//判断是否为电信IOT
if(eqpDTO.getJoinMethod()==null || eqpDTO.getJoinMethod()== ParkConstant.JoinMethod.DEVICE_JOIN){
}else if(eqpDTO.getJoinMethod()==ParkConstant.JoinMethod.TELECOM_IOT){
//调用电信删除接口
DeleteDirectlyConnectedDevice.execute(eqpDTO.getDeviceId(),appId,secret,baseUrl);
}
TpPEqpExample example = new TpPEqpExample();
example.createCriteria().andIdEqualTo(eqpDTO.getId());
TpPEqp record = new TpPEqp();
record.setDataState(DataStatusEnum.DATA_STATUS_NO_VALID.value());
record.setModifyOp(opId);
record.setModifyTime(new Date());
tpPEqpMapper.updateByExampleSelective(record , example );
}
@Override
public void updateEqpInfoById(TpPEqp tpPEqp) {
tpPEqpMapper.updateByPrimaryKeySelective(tpPEqp);
}
@Override
public Map<Integer, StatisticEqpCountByEqpTypeDTO> statisticEqpCountGroupByEqpType(QueryEqpRequest request) {
List<StatisticEqpCountByEqpTypeDTO> byEqpTypeDTOs = tpPEqpSMapper.statisticEqpCountGroupByEqpType(request);
if(CollectionUtil.isEmpty(byEqpTypeDTOs)){
return null;
}
return byEqpTypeDTOs.stream().collect(Collectors.toMap(StatisticEqpCountByEqpTypeDTO::getEqpType, Function.identity()));
}
@Override
public Map<String, List<StatisticEqpCountByPlNoDTO>> statisticEqpCountGroupByPlNo(QueryEqpRequest request) {
List<StatisticEqpCountByPlNoDTO> byplNoDTOs = tpPEqpSMapper.statisticEqpCountGroupByPlNo(request);
if(CollectionUtil.isEmpty(byplNoDTOs)){
return null;
}
return byplNoDTOs.stream().collect(Collectors.groupingBy(StatisticEqpCountByPlNoDTO::getPlNo));
}
@Override
public Map<Long, List<StatisticEqpCountByCountryDTO>> statisticEqpCountGroupByCountry(QueryEqpRequest request) {
List<StatisticEqpCountByCountryDTO> byplNoDTOs = tpPEqpSMapper.statisticEqpCountGroupByCountry(request);
if(CollectionUtil.isEmpty(byplNoDTOs)){
return null;
}
return byplNoDTOs.stream().collect(Collectors.groupingBy(StatisticEqpCountByCountryDTO::getPlCountryId));
}
/**
* 批量插入地磁信息.<br/>
* @param tpPEqp
* @return
*/
@Override
public int batchInsertEqp(List<TpPEqp> tpPEqp) {
int bactInsetCount = tpPEqpSMapper.batchInsertEqp(tpPEqp);
return bactInsetCount;
}
@Override
public int bindEqpHostByIds(List<Long> ids,String hostNo,Long opId) {
if(CollectionUtils.isEmpty(ids)){
return 0;
}
TpPEqpExample example = new TpPEqpExample();
example.createCriteria().andIdIn(ids);
TpPEqp record = new TpPEqp();
record.setModifyOp(opId);
record.setModifyTime(new Date());
record.setGatewayNo(hostNo);
return tpPEqpMapper.updateByExampleSelective(record , example );
}
@Override
public int updateEqpById(TpPEqp tpPEqp) {
return tpPEqpMapper.updateByPrimaryKeySelective(tpPEqp);
}
@Override
public Long queryEqpCountByPlNo(String plNo, Integer eqpType,Integer userType,String isOnline) {
TpPEqpExample example = new TpPEqpExample();
example.createCriteria().andDataStateEqualTo(DataStatusEnum.DATA_STATUS_VALID.value())
.andEqpIsOnlineEqualTo(isOnline).andPlNoEqualTo(plNo)
.andEqpTypeEqualTo(eqpType).andUsedTypeEqualTo(userType);
return tpPEqpMapper.countByExample(example);
}
@Override
public List<BerthsDTO> queryEqpInfoByPlNoAndOther(QueryEqpByPlNoAndOrtherRequest request) {
return tpPEqpSMapper.queryEqpInfoByPlNoAndOther(request);
}
}