|
|
@@ -1,6 +1,8 @@
|
|
1
|
1
|
package com.sundot.airport.equipment.service.impl;
|
|
2
|
2
|
|
|
3
|
3
|
import java.util.List;
|
|
|
4
|
+import java.util.Map;
|
|
|
5
|
+import java.util.stream.Collectors;
|
|
4
|
6
|
|
|
5
|
7
|
import cn.hutool.core.collection.CollUtil;
|
|
6
|
8
|
import cn.hutool.core.util.ObjUtil;
|
|
|
@@ -8,6 +10,8 @@ import cn.hutool.core.util.StrUtil;
|
|
8
|
10
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
9
|
11
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
10
|
12
|
import com.sundot.airport.common.constant.Constants;
|
|
|
13
|
+import com.sundot.airport.common.core.domain.entity.SysDictData;
|
|
|
14
|
+import com.sundot.airport.common.core.domain.entity.SysUser;
|
|
11
|
15
|
import com.sundot.airport.common.core.redis.RedisSerialGenerator;
|
|
12
|
16
|
import com.sundot.airport.common.domain.BaseAttachment;
|
|
13
|
17
|
import com.sundot.airport.common.enums.BaseAttachmentSourceTypeEnum;
|
|
|
@@ -19,6 +23,8 @@ import com.sundot.airport.common.utils.DateUtils;
|
|
19
|
23
|
import com.sundot.airport.common.utils.EquipmentDateUtils;
|
|
20
|
24
|
import com.sundot.airport.equipment.domain.EquipmentInspectionRecord;
|
|
21
|
25
|
import com.sundot.airport.equipment.service.IEquipmentInspectionRecordService;
|
|
|
26
|
+import com.sundot.airport.system.service.ISysDictDataService;
|
|
|
27
|
+import com.sundot.airport.system.service.ISysUserService;
|
|
22
|
28
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
23
|
29
|
import org.springframework.stereotype.Service;
|
|
24
|
30
|
import com.sundot.airport.equipment.mapper.EquipmentLedgerMapper;
|
|
|
@@ -42,6 +48,10 @@ public class EquipmentLedgerServiceImpl extends ServiceImpl<EquipmentLedgerMappe
|
|
42
|
48
|
private IBaseAttachmentService baseAttachmentService;
|
|
43
|
49
|
@Autowired
|
|
44
|
50
|
private RedisSerialGenerator redisSerialGenerator;
|
|
|
51
|
+ @Autowired
|
|
|
52
|
+ private ISysDictDataService sysDictDataService;
|
|
|
53
|
+ @Autowired
|
|
|
54
|
+ private ISysUserService sysUserService;
|
|
45
|
55
|
|
|
46
|
56
|
/**
|
|
47
|
57
|
* 查询设备台账
|
|
|
@@ -268,4 +278,107 @@ public class EquipmentLedgerServiceImpl extends ServiceImpl<EquipmentLedgerMappe
|
|
268
|
278
|
public List<EquipmentLedger> selectTwoWeeksUpcomingInspectionList() {
|
|
269
|
279
|
return equipmentLedgerMapper.selectTwoWeeksUpcomingInspectionList();
|
|
270
|
280
|
}
|
|
|
281
|
+
|
|
|
282
|
+ /**
|
|
|
283
|
+ * 导入设备台账数据
|
|
|
284
|
+ *
|
|
|
285
|
+ * @param list 数据列表
|
|
|
286
|
+ * @param isUpdateSupport 是否更新支持,如果已存在,则进行更新数据
|
|
|
287
|
+ * @return 结果
|
|
|
288
|
+ */
|
|
|
289
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
290
|
+ @Override
|
|
|
291
|
+ public String importData(List<EquipmentLedger> list, boolean isUpdateSupport) {
|
|
|
292
|
+ if (CollUtil.isEmpty(list)) {
|
|
|
293
|
+ throw new ServiceException("导入设备台账数据不能为空!");
|
|
|
294
|
+ }
|
|
|
295
|
+
|
|
|
296
|
+ List<SysUser> sysUserListAll = sysUserService.selectUserAll();
|
|
|
297
|
+ Map<String, Long> sysUserMap = sysUserListAll.stream().collect(Collectors.toMap(SysUser::getNickName, SysUser::getUserId, (oldValue, newValue) -> newValue));
|
|
|
298
|
+
|
|
|
299
|
+ SysDictData equipmentUsageStatusQuery = new SysDictData();
|
|
|
300
|
+ equipmentUsageStatusQuery.setDictType("equipment_usage_status");
|
|
|
301
|
+ List<SysDictData> equipmentUsageStatusList = sysDictDataService.selectDictDataList(equipmentUsageStatusQuery);
|
|
|
302
|
+ Map<String, String> equipmentUsageStatusMap = equipmentUsageStatusList.stream().collect(Collectors.toMap(SysDictData::getDictLabel, SysDictData::getDictValue));
|
|
|
303
|
+
|
|
|
304
|
+ int successNum = 0;
|
|
|
305
|
+ int failureNum = 0;
|
|
|
306
|
+ StringBuilder successMsg = new StringBuilder();
|
|
|
307
|
+ StringBuilder failureMsg = new StringBuilder();
|
|
|
308
|
+
|
|
|
309
|
+ for (EquipmentLedger data : list) {
|
|
|
310
|
+ // 根据名称填充ID字段
|
|
|
311
|
+ fillIdsByName(data, sysUserMap, equipmentUsageStatusMap);
|
|
|
312
|
+ try {
|
|
|
313
|
+ if (ObjUtil.isNull(data.getEquipmentSerialNumber())) {
|
|
|
314
|
+ failureNum++;
|
|
|
315
|
+ failureMsg.append("<br/>" + failureNum + "、设备序列号【" + data.getEquipmentSerialNumber() + "】、设备名称【" + data.getEquipmentName() + "】设备序列号不能为空");
|
|
|
316
|
+ continue;
|
|
|
317
|
+ }
|
|
|
318
|
+ if (ObjUtil.isNull(data.getEquipmentName())) {
|
|
|
319
|
+ failureNum++;
|
|
|
320
|
+ failureMsg.append("<br/>" + failureNum + "、设备序列号【" + data.getEquipmentSerialNumber() + "】、设备名称【" + data.getEquipmentName() + "】设备名称不能为空");
|
|
|
321
|
+ continue;
|
|
|
322
|
+ }
|
|
|
323
|
+
|
|
|
324
|
+ // 查询是否已存在(根据【设备序列号】唯一)
|
|
|
325
|
+ EquipmentLedger queryParam = new EquipmentLedger();
|
|
|
326
|
+ queryParam.setEquipmentSerialNumber(data.getEquipmentSerialNumber());
|
|
|
327
|
+ List<EquipmentLedger> existingList = equipmentLedgerMapper.selectEquipmentLedgerList(queryParam);
|
|
|
328
|
+
|
|
|
329
|
+ if (CollUtil.isEmpty(existingList)) {
|
|
|
330
|
+ // 新增
|
|
|
331
|
+ data.setEquipmentCode(redisSerialGenerator.generate(Constants.EQUIPMENT_LEDGER));
|
|
|
332
|
+ data.setCreateTime(DateUtils.getNowDate());
|
|
|
333
|
+ equipmentLedgerMapper.insertEquipmentLedger(data);
|
|
|
334
|
+ successNum++;
|
|
|
335
|
+ successMsg.append("<br/>" + successNum + "、设备序列号【" + data.getEquipmentSerialNumber() + "】、设备名称【" + data.getEquipmentName() + "】导入成功");
|
|
|
336
|
+ } else if (isUpdateSupport) {
|
|
|
337
|
+ // 更新
|
|
|
338
|
+ EquipmentLedger old = existingList.get(0);
|
|
|
339
|
+ data.setId(old.getId());
|
|
|
340
|
+ data.setEquipmentCode(old.getEquipmentCode());
|
|
|
341
|
+ data.setUpdateTime(DateUtils.getNowDate());
|
|
|
342
|
+ equipmentLedgerMapper.updateEquipmentLedger(data);
|
|
|
343
|
+ successNum++;
|
|
|
344
|
+ successMsg.append("<br/>" + successNum + "、设备序列号【" + data.getEquipmentSerialNumber() + "】、设备名称【" + data.getEquipmentName() + "】更新成功");
|
|
|
345
|
+ } else {
|
|
|
346
|
+ failureNum++;
|
|
|
347
|
+ failureMsg.append("<br/>" + failureNum + "、设备序列号【" + data.getEquipmentSerialNumber() + "】、设备名称【" + data.getEquipmentName() + "】已存在");
|
|
|
348
|
+ }
|
|
|
349
|
+ } catch (Exception e) {
|
|
|
350
|
+ failureNum++;
|
|
|
351
|
+ String msg = "<br/>" + failureNum + "、设备序列号【" + data.getEquipmentSerialNumber() + "】、设备名称【" + data.getEquipmentName() + "】导入失败:";
|
|
|
352
|
+ failureMsg.append(msg + e.getMessage());
|
|
|
353
|
+ }
|
|
|
354
|
+ }
|
|
|
355
|
+
|
|
|
356
|
+ if (failureNum > 0) {
|
|
|
357
|
+ failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
|
|
|
358
|
+ throw new ServiceException(failureMsg.toString());
|
|
|
359
|
+ } else {
|
|
|
360
|
+ successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:");
|
|
|
361
|
+ }
|
|
|
362
|
+ return successMsg.toString();
|
|
|
363
|
+ }
|
|
|
364
|
+
|
|
|
365
|
+ /**
|
|
|
366
|
+ * 根据名称填充ID字段
|
|
|
367
|
+ *
|
|
|
368
|
+ * @param data 速率数据
|
|
|
369
|
+ */
|
|
|
370
|
+ private void fillIdsByName(EquipmentLedger data, Map<String, Long> sysUserMap, Map<String, String> equipmentUsageStatusMap) {
|
|
|
371
|
+ // 定/自检小组组长
|
|
|
372
|
+ if (ObjUtil.isNotNull(data.getInspectionTeamLeaderName())) {
|
|
|
373
|
+ data.setInspectionTeamLeaderId(sysUserMap.get(data.getInspectionTeamLeaderName()));
|
|
|
374
|
+ }
|
|
|
375
|
+ // 定/自检小组组员1
|
|
|
376
|
+ if (ObjUtil.isNotNull(data.getInspectionTeamMember1Name())) {
|
|
|
377
|
+ data.setInspectionTeamMember1Id(sysUserMap.get(data.getInspectionTeamMember1Name()));
|
|
|
378
|
+ }
|
|
|
379
|
+ // 定/自检小组组员2
|
|
|
380
|
+ if (ObjUtil.isNotNull(data.getInspectionTeamMember2Name())) {
|
|
|
381
|
+ data.setInspectionTeamMember2Id(sysUserMap.get(data.getInspectionTeamMember2Name()));
|
|
|
382
|
+ }
|
|
|
383
|
+ }
|
|
271
|
384
|
}
|