|
|
@@ -2,13 +2,23 @@ package com.sundot.airport.equipment.service.impl;
|
|
2
|
2
|
|
|
3
|
3
|
import java.util.List;
|
|
4
|
4
|
|
|
|
5
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
6
|
+import cn.hutool.core.util.ObjUtil;
|
|
|
7
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
5
|
8
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
9
|
+import com.sundot.airport.common.domain.BaseAttachment;
|
|
|
10
|
+import com.sundot.airport.common.enums.BaseAttachmentSourceTypeEnum;
|
|
|
11
|
+import com.sundot.airport.common.exception.ServiceException;
|
|
|
12
|
+import com.sundot.airport.common.service.IBaseAttachmentService;
|
|
6
|
13
|
import com.sundot.airport.common.utils.DateUtils;
|
|
|
14
|
+import com.sundot.airport.equipment.domain.EquipmentInspectionRecord;
|
|
|
15
|
+import com.sundot.airport.equipment.service.IEquipmentInspectionRecordService;
|
|
7
|
16
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
8
|
17
|
import org.springframework.stereotype.Service;
|
|
9
|
18
|
import com.sundot.airport.equipment.mapper.EquipmentLedgerMapper;
|
|
10
|
19
|
import com.sundot.airport.equipment.domain.EquipmentLedger;
|
|
11
|
20
|
import com.sundot.airport.equipment.service.IEquipmentLedgerService;
|
|
|
21
|
+import org.springframework.transaction.annotation.Transactional;
|
|
12
|
22
|
|
|
13
|
23
|
/**
|
|
14
|
24
|
* 设备台账Service业务层处理
|
|
|
@@ -20,6 +30,10 @@ import com.sundot.airport.equipment.service.IEquipmentLedgerService;
|
|
20
|
30
|
public class EquipmentLedgerServiceImpl extends ServiceImpl<EquipmentLedgerMapper, EquipmentLedger> implements IEquipmentLedgerService {
|
|
21
|
31
|
@Autowired
|
|
22
|
32
|
private EquipmentLedgerMapper equipmentLedgerMapper;
|
|
|
33
|
+ @Autowired
|
|
|
34
|
+ private IEquipmentInspectionRecordService equipmentInspectionRecordService;
|
|
|
35
|
+ @Autowired
|
|
|
36
|
+ private IBaseAttachmentService baseAttachmentService;
|
|
23
|
37
|
|
|
24
|
38
|
/**
|
|
25
|
39
|
* 查询设备台账
|
|
|
@@ -29,7 +43,20 @@ public class EquipmentLedgerServiceImpl extends ServiceImpl<EquipmentLedgerMappe
|
|
29
|
43
|
*/
|
|
30
|
44
|
@Override
|
|
31
|
45
|
public EquipmentLedger selectEquipmentLedgerById(Long id) {
|
|
32
|
|
- return equipmentLedgerMapper.selectEquipmentLedgerById(id);
|
|
|
46
|
+ EquipmentLedger result = equipmentLedgerMapper.selectEquipmentLedgerById(id);
|
|
|
47
|
+ if (ObjUtil.isNull(result)) {
|
|
|
48
|
+ return result;
|
|
|
49
|
+ }
|
|
|
50
|
+ LambdaQueryWrapper<EquipmentInspectionRecord> recordQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
51
|
+ recordQueryWrapper.eq(EquipmentInspectionRecord::getSourceId, result.getId());
|
|
|
52
|
+ List<EquipmentInspectionRecord> equipmentInspectionRecordList = equipmentInspectionRecordService.getBaseMapper().selectList(recordQueryWrapper);
|
|
|
53
|
+ result.setEquipmentInspectionRecordList(equipmentInspectionRecordList);
|
|
|
54
|
+ LambdaQueryWrapper<BaseAttachment> attachmentQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
55
|
+ attachmentQueryWrapper.eq(BaseAttachment::getSourceType, BaseAttachmentSourceTypeEnum.EQUIPMENT_LEDGER.getCode());
|
|
|
56
|
+ attachmentQueryWrapper.eq(BaseAttachment::getSourceId, result.getId());
|
|
|
57
|
+ List<BaseAttachment> baseAttachmentList = baseAttachmentService.getBaseMapper().selectList(attachmentQueryWrapper);
|
|
|
58
|
+ result.setBaseAttachmentList(baseAttachmentList);
|
|
|
59
|
+ return result;
|
|
33
|
60
|
}
|
|
34
|
61
|
|
|
35
|
62
|
/**
|
|
|
@@ -49,10 +76,36 @@ public class EquipmentLedgerServiceImpl extends ServiceImpl<EquipmentLedgerMappe
|
|
49
|
76
|
* @param equipmentLedger 设备台账
|
|
50
|
77
|
* @return 结果
|
|
51
|
78
|
*/
|
|
|
79
|
+ @Transactional(rollbackFor = Exception.class)
|
|
52
|
80
|
@Override
|
|
53
|
81
|
public int insertEquipmentLedger(EquipmentLedger equipmentLedger) {
|
|
|
82
|
+ EquipmentLedger temp = new EquipmentLedger();
|
|
|
83
|
+ temp.setEquipmentSerialNumber(equipmentLedger.getEquipmentSerialNumber());
|
|
|
84
|
+ List<EquipmentLedger> tempList = equipmentLedgerMapper.selectEquipmentLedgerList(temp);
|
|
|
85
|
+ if (CollUtil.isNotEmpty(tempList)) {
|
|
|
86
|
+ throw new ServiceException("该设备序列号已存在");
|
|
|
87
|
+ }
|
|
54
|
88
|
equipmentLedger.setCreateTime(DateUtils.getNowDate());
|
|
55
|
|
- return equipmentLedgerMapper.insertEquipmentLedger(equipmentLedger);
|
|
|
89
|
+ int result = equipmentLedgerMapper.insertEquipmentLedger(equipmentLedger);
|
|
|
90
|
+ if (CollUtil.isNotEmpty(equipmentLedger.getEquipmentInspectionRecordList())) {
|
|
|
91
|
+ equipmentLedger.getEquipmentInspectionRecordList().forEach(equipmentInspectionRecord -> {
|
|
|
92
|
+ equipmentInspectionRecord.setSourceId(equipmentLedger.getId());
|
|
|
93
|
+ equipmentInspectionRecord.setCreateBy(equipmentLedger.getCreateBy());
|
|
|
94
|
+ equipmentInspectionRecord.setCreateTime(DateUtils.getNowDate());
|
|
|
95
|
+ equipmentInspectionRecordService.insertEquipmentInspectionRecord(equipmentInspectionRecord);
|
|
|
96
|
+ });
|
|
|
97
|
+ }
|
|
|
98
|
+ if (CollUtil.isNotEmpty(equipmentLedger.getBaseAttachmentList())) {
|
|
|
99
|
+ equipmentLedger.getBaseAttachmentList().forEach(baseAttachment -> {
|
|
|
100
|
+ baseAttachment.setSourceType(BaseAttachmentSourceTypeEnum.EQUIPMENT_LEDGER.getCode());
|
|
|
101
|
+ baseAttachment.setSourceTypeName(BaseAttachmentSourceTypeEnum.EQUIPMENT_LEDGER.getInfo());
|
|
|
102
|
+ baseAttachment.setSourceId(equipmentLedger.getId());
|
|
|
103
|
+ baseAttachment.setCreateBy(equipmentLedger.getCreateBy());
|
|
|
104
|
+ baseAttachment.setCreateTime(DateUtils.getNowDate());
|
|
|
105
|
+ baseAttachmentService.insertBaseAttachment(baseAttachment);
|
|
|
106
|
+ });
|
|
|
107
|
+ }
|
|
|
108
|
+ return result;
|
|
56
|
109
|
}
|
|
57
|
110
|
|
|
58
|
111
|
/**
|
|
|
@@ -61,10 +114,51 @@ public class EquipmentLedgerServiceImpl extends ServiceImpl<EquipmentLedgerMappe
|
|
61
|
114
|
* @param equipmentLedger 设备台账
|
|
62
|
115
|
* @return 结果
|
|
63
|
116
|
*/
|
|
|
117
|
+ @Transactional(rollbackFor = Exception.class)
|
|
64
|
118
|
@Override
|
|
65
|
119
|
public int updateEquipmentLedger(EquipmentLedger equipmentLedger) {
|
|
66
|
120
|
equipmentLedger.setUpdateTime(DateUtils.getNowDate());
|
|
67
|
|
- return equipmentLedgerMapper.updateEquipmentLedger(equipmentLedger);
|
|
|
121
|
+ int result = equipmentLedgerMapper.updateEquipmentLedger(equipmentLedger);
|
|
|
122
|
+ // 删除旧数据
|
|
|
123
|
+ LambdaQueryWrapper<EquipmentInspectionRecord> recordOldQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
124
|
+ recordOldQueryWrapper.eq(EquipmentInspectionRecord::getSourceId, equipmentLedger.getId());
|
|
|
125
|
+ List<EquipmentInspectionRecord> equipmentInspectionRecordOldList = equipmentInspectionRecordService.getBaseMapper().selectList(recordOldQueryWrapper);
|
|
|
126
|
+ if (CollUtil.isNotEmpty(equipmentInspectionRecordOldList)) {
|
|
|
127
|
+ equipmentInspectionRecordService.removeBatchByIds(equipmentInspectionRecordOldList);
|
|
|
128
|
+ }
|
|
|
129
|
+ LambdaQueryWrapper<BaseAttachment> attachmentOldQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
130
|
+ attachmentOldQueryWrapper.eq(BaseAttachment::getSourceType, BaseAttachmentSourceTypeEnum.EQUIPMENT_LEDGER.getCode());
|
|
|
131
|
+ attachmentOldQueryWrapper.eq(BaseAttachment::getSourceId, equipmentLedger.getId());
|
|
|
132
|
+ List<BaseAttachment> baseAttachmentOldList = baseAttachmentService.getBaseMapper().selectList(attachmentOldQueryWrapper);
|
|
|
133
|
+ if (CollUtil.isNotEmpty(baseAttachmentOldList)) {
|
|
|
134
|
+ baseAttachmentService.removeBatchByIds(baseAttachmentOldList);
|
|
|
135
|
+ }
|
|
|
136
|
+ // 新增新数据
|
|
|
137
|
+ if (CollUtil.isNotEmpty(equipmentLedger.getEquipmentInspectionRecordList())) {
|
|
|
138
|
+ equipmentLedger.getEquipmentInspectionRecordList().forEach(equipmentInspectionRecord -> {
|
|
|
139
|
+ equipmentInspectionRecord.setId(null);
|
|
|
140
|
+ equipmentInspectionRecord.setSourceId(equipmentLedger.getId());
|
|
|
141
|
+ equipmentInspectionRecord.setCreateBy(equipmentLedger.getCreateBy());
|
|
|
142
|
+ equipmentInspectionRecord.setCreateTime(DateUtils.getNowDate());
|
|
|
143
|
+ equipmentInspectionRecord.setUpdateBy(equipmentLedger.getCreateBy());
|
|
|
144
|
+ equipmentInspectionRecord.setUpdateTime(DateUtils.getNowDate());
|
|
|
145
|
+ equipmentInspectionRecordService.insertEquipmentInspectionRecord(equipmentInspectionRecord);
|
|
|
146
|
+ });
|
|
|
147
|
+ }
|
|
|
148
|
+ if (CollUtil.isNotEmpty(equipmentLedger.getBaseAttachmentList())) {
|
|
|
149
|
+ equipmentLedger.getBaseAttachmentList().forEach(baseAttachment -> {
|
|
|
150
|
+ baseAttachment.setId(null);
|
|
|
151
|
+ baseAttachment.setSourceType(BaseAttachmentSourceTypeEnum.EQUIPMENT_LEDGER.getCode());
|
|
|
152
|
+ baseAttachment.setSourceTypeName(BaseAttachmentSourceTypeEnum.EQUIPMENT_LEDGER.getInfo());
|
|
|
153
|
+ baseAttachment.setSourceId(equipmentLedger.getId());
|
|
|
154
|
+ baseAttachment.setCreateBy(equipmentLedger.getCreateBy());
|
|
|
155
|
+ baseAttachment.setCreateTime(DateUtils.getNowDate());
|
|
|
156
|
+ baseAttachment.setUpdateBy(equipmentLedger.getCreateBy());
|
|
|
157
|
+ baseAttachment.setUpdateTime(DateUtils.getNowDate());
|
|
|
158
|
+ baseAttachmentService.insertBaseAttachment(baseAttachment);
|
|
|
159
|
+ });
|
|
|
160
|
+ }
|
|
|
161
|
+ return result;
|
|
68
|
162
|
}
|
|
69
|
163
|
|
|
70
|
164
|
/**
|
|
|
@@ -73,9 +167,26 @@ public class EquipmentLedgerServiceImpl extends ServiceImpl<EquipmentLedgerMappe
|
|
73
|
167
|
* @param ids 需要删除的设备台账主键
|
|
74
|
168
|
* @return 结果
|
|
75
|
169
|
*/
|
|
|
170
|
+ @Transactional(rollbackFor = Exception.class)
|
|
76
|
171
|
@Override
|
|
77
|
172
|
public int deleteEquipmentLedgerByIds(Long[] ids) {
|
|
78
|
|
- return equipmentLedgerMapper.deleteEquipmentLedgerByIds(ids);
|
|
|
173
|
+ int result = equipmentLedgerMapper.deleteEquipmentLedgerByIds(ids);
|
|
|
174
|
+ for (Long id : ids) {
|
|
|
175
|
+ LambdaQueryWrapper<EquipmentInspectionRecord> detailQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
176
|
+ detailQueryWrapper.eq(EquipmentInspectionRecord::getSourceId, id);
|
|
|
177
|
+ List<EquipmentInspectionRecord> equipmentInspectionRecordList = equipmentInspectionRecordService.getBaseMapper().selectList(detailQueryWrapper);
|
|
|
178
|
+ if (CollUtil.isNotEmpty(equipmentInspectionRecordList)) {
|
|
|
179
|
+ equipmentInspectionRecordService.removeBatchByIds(equipmentInspectionRecordList);
|
|
|
180
|
+ }
|
|
|
181
|
+ LambdaQueryWrapper<BaseAttachment> attachmentQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
182
|
+ attachmentQueryWrapper.eq(BaseAttachment::getSourceType, BaseAttachmentSourceTypeEnum.EQUIPMENT_LEDGER.getCode());
|
|
|
183
|
+ attachmentQueryWrapper.eq(BaseAttachment::getSourceId, id);
|
|
|
184
|
+ List<BaseAttachment> baseAttachmentList = baseAttachmentService.getBaseMapper().selectList(attachmentQueryWrapper);
|
|
|
185
|
+ if (CollUtil.isNotEmpty(baseAttachmentList)) {
|
|
|
186
|
+ baseAttachmentService.removeBatchByIds(baseAttachmentList);
|
|
|
187
|
+ }
|
|
|
188
|
+ }
|
|
|
189
|
+ return result;
|
|
79
|
190
|
}
|
|
80
|
191
|
|
|
81
|
192
|
/**
|
|
|
@@ -84,8 +195,23 @@ public class EquipmentLedgerServiceImpl extends ServiceImpl<EquipmentLedgerMappe
|
|
84
|
195
|
* @param id 设备台账主键
|
|
85
|
196
|
* @return 结果
|
|
86
|
197
|
*/
|
|
|
198
|
+ @Transactional(rollbackFor = Exception.class)
|
|
87
|
199
|
@Override
|
|
88
|
200
|
public int deleteEquipmentLedgerById(Long id) {
|
|
89
|
|
- return equipmentLedgerMapper.deleteEquipmentLedgerById(id);
|
|
|
201
|
+ int result = equipmentLedgerMapper.deleteEquipmentLedgerById(id);
|
|
|
202
|
+ LambdaQueryWrapper<EquipmentInspectionRecord> detailQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
203
|
+ detailQueryWrapper.eq(EquipmentInspectionRecord::getSourceId, id);
|
|
|
204
|
+ List<EquipmentInspectionRecord> equipmentInspectionRecordList = equipmentInspectionRecordService.getBaseMapper().selectList(detailQueryWrapper);
|
|
|
205
|
+ if (CollUtil.isNotEmpty(equipmentInspectionRecordList)) {
|
|
|
206
|
+ equipmentInspectionRecordService.removeBatchByIds(equipmentInspectionRecordList);
|
|
|
207
|
+ }
|
|
|
208
|
+ LambdaQueryWrapper<BaseAttachment> attachmentQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
209
|
+ attachmentQueryWrapper.eq(BaseAttachment::getSourceType, BaseAttachmentSourceTypeEnum.EQUIPMENT_LEDGER.getCode());
|
|
|
210
|
+ attachmentQueryWrapper.eq(BaseAttachment::getSourceId, id);
|
|
|
211
|
+ List<BaseAttachment> baseAttachmentList = baseAttachmentService.getBaseMapper().selectList(attachmentQueryWrapper);
|
|
|
212
|
+ if (CollUtil.isNotEmpty(baseAttachmentList)) {
|
|
|
213
|
+ baseAttachmentService.removeBatchByIds(baseAttachmentList);
|
|
|
214
|
+ }
|
|
|
215
|
+ return result;
|
|
90
|
216
|
}
|
|
91
|
217
|
}
|