提交 | 用户 | 时间
|
7fd198
|
1 |
package com.iailab.module.model.mcs.pre.service.impl; |
潘 |
2 |
|
e6753e
|
3 |
import com.baomidou.dynamic.datasource.annotation.DSTransactional; |
7fd198
|
4 |
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
137356
|
5 |
import com.baomidou.mybatisplus.core.metadata.IPage; |
5c6007
|
6 |
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
7fd198
|
7 |
import com.iailab.framework.common.pojo.PageResult; |
5c6007
|
8 |
import com.iailab.framework.common.util.object.BeanUtils; |
7fd198
|
9 |
import com.iailab.module.model.mcs.pre.dao.MmPredictItemDao; |
潘 |
10 |
import com.iailab.module.model.mcs.pre.dto.MmPredictItemDTO; |
|
11 |
import com.iailab.module.model.mcs.pre.entity.*; |
|
12 |
import com.iailab.module.model.mcs.pre.enums.ItemIncreaseCodeEnum; |
|
13 |
import com.iailab.module.model.mcs.pre.enums.ItemTypeEnum; |
|
14 |
import com.iailab.module.model.mcs.pre.service.MmPredictItemService; |
48c57b
|
15 |
import com.iailab.module.model.mcs.pre.service.MmSequenceNumService; |
5c6007
|
16 |
import com.iailab.module.model.mcs.pre.vo.MmPredictItemPageReqVO; |
137356
|
17 |
import com.iailab.module.model.mcs.pre.vo.MmPredictItemRespVO; |
7fd198
|
18 |
import com.iailab.module.model.mdk.vo.ItemVO; |
潘 |
19 |
import com.iailab.module.model.mdk.vo.MergeItemVO; |
19a4fb
|
20 |
import org.apache.commons.lang3.ObjectUtils; |
7fd198
|
21 |
import org.apache.commons.lang3.StringUtils; |
潘 |
22 |
import org.springframework.beans.factory.annotation.Autowired; |
|
23 |
import org.springframework.stereotype.Service; |
|
24 |
import org.springframework.util.CollectionUtils; |
|
25 |
|
|
26 |
import java.util.*; |
|
27 |
|
|
28 |
/** |
|
29 |
* @author PanZhibao |
|
30 |
* @date 2021年04月26日 14:03 |
|
31 |
*/ |
5c6007
|
32 |
@Service |
L |
33 |
public class MmPredictItemServiceImpl extends ServiceImpl<MmPredictItemDao, MmPredictItemEntity> implements MmPredictItemService { |
7fd198
|
34 |
|
潘 |
35 |
@Autowired |
|
36 |
private DmModuleItemServiceImpl dmModuleItemService; |
|
37 |
|
|
38 |
@Autowired |
|
39 |
private MmItemOutputServiceImpl mmItemOutputService; |
|
40 |
|
|
41 |
@Autowired |
|
42 |
private MmPredictModelServiceImpl mmPredictModelService; |
|
43 |
|
|
44 |
@Autowired |
|
45 |
private MmModelArithSettingsServiceImpl mmModelArithSettingsService; |
|
46 |
|
|
47 |
@Autowired |
|
48 |
private MmModelParamServiceImpl mmModelParamService; |
|
49 |
|
|
50 |
@Autowired |
|
51 |
private MmPredictMergeItemServiceImpl mmPredictMergeItemService; |
|
52 |
|
|
53 |
@Autowired |
|
54 |
private MmItemTypeImpl mmItemTypeImpl; |
|
55 |
|
|
56 |
@Autowired |
48c57b
|
57 |
private MmSequenceNumService sequenceNumService; |
7fd198
|
58 |
|
5c6007
|
59 |
@Autowired |
L |
60 |
private MmPredictItemDao mmPredictItemDao; |
7fd198
|
61 |
|
91343d
|
62 |
private static HashMap<String, ItemVO> itemVOHashMap = new HashMap<>(); |
潘 |
63 |
|
5c6007
|
64 |
@Override |
137356
|
65 |
public PageResult<MmPredictItemRespVO> queryPage(MmPredictItemPageReqVO reqVO) { |
潘 |
66 |
IPage<MmPredictItemRespVO> page = mmPredictItemDao.selectPage(reqVO); |
|
67 |
|
6d6394
|
68 |
return new PageResult<>(page.getRecords(), page.getTotal()); |
7fd198
|
69 |
} |
5d299c
|
70 |
|
7fd198
|
71 |
@Override |
a97b38
|
72 |
public List<MmPredictItemRespVO> list(Map<String, Object> params) { |
潘 |
73 |
return mmPredictItemDao.queryList(params); |
5c6007
|
74 |
} |
L |
75 |
|
9f049d
|
76 |
@Override |
J |
77 |
public MmPredictItemEntity getById(String id) { |
|
78 |
return mmPredictItemDao.selectById(id); |
|
79 |
} |
|
80 |
|
e6753e
|
81 |
@DSTransactional(rollbackFor = Exception.class) |
5c6007
|
82 |
@Override |
5d299c
|
83 |
public void add(MmPredictItemDTO mmPredictItemDto) { |
7fd198
|
84 |
MmPredictItemEntity predictItem = mmPredictItemDto.getMmPredictItem(); |
潘 |
85 |
predictItem.setId(UUID.randomUUID().toString()); |
|
86 |
predictItem.setCreateTime(new Date()); |
|
87 |
predictItem.setUpdateTime(new Date()); |
|
88 |
|
|
89 |
MmItemTypeEntity itemType = mmItemTypeImpl.getById(predictItem.getItemtypeid()); |
5d299c
|
90 |
if (itemType != null && ItemTypeEnum.NORMAL_ITEM.getName().equals(itemType.getItemtypename())) { |
48c57b
|
91 |
MmSequenceNumEntity sequenceNumEntity = sequenceNumService.getAndIncreaseByCode(ItemIncreaseCodeEnum.IM.toString()); |
7fd198
|
92 |
String str = String.format("%010d", sequenceNumEntity.getSequenceNum()); |
潘 |
93 |
predictItem.setItemno(sequenceNumEntity.getPrefix() + str); |
|
94 |
|
|
95 |
MmPredictModelEntity mmPredictModel = mmPredictItemDto.getMmPredictModel(); |
48c57b
|
96 |
MmSequenceNumEntity preMdlSequenceNumEntity = sequenceNumService.getAndIncreaseByCode(ItemIncreaseCodeEnum.PRE_MDL.toString()); |
7fd198
|
97 |
String preMdlStr = String.format("%04d", preMdlSequenceNumEntity.getSequenceNum()); |
潘 |
98 |
mmPredictModel.setModelno(preMdlSequenceNumEntity.getPrefix() + preMdlStr); |
|
99 |
mmPredictModel.setItemid(predictItem.getId()); |
|
100 |
mmPredictModelService.savePredictModel(mmPredictModel); |
|
101 |
|
|
102 |
List<MmModelArithSettingsEntity> mmModelArithSettingsList = mmPredictItemDto.getMmModelArithSettingsList(); |
|
103 |
mmModelArithSettingsList.forEach(item -> { |
|
104 |
item.setModelid(mmPredictModel.getId()); |
|
105 |
}); |
|
106 |
mmModelArithSettingsService.saveList(mmModelArithSettingsList); |
|
107 |
|
|
108 |
List<MmModelParamEntity> mmModelParamList = mmPredictItemDto.getMmModelParamList(); |
|
109 |
mmModelParamList.forEach(item -> { |
|
110 |
item.setModelid(mmPredictModel.getId()); |
|
111 |
}); |
|
112 |
mmModelParamService.saveList(mmModelParamList); |
5d299c
|
113 |
} else if (itemType != null && ItemTypeEnum.MERGE_ITEM.getName().equals(itemType.getItemtypename())) { |
48c57b
|
114 |
MmSequenceNumEntity sequenceNumEntity = sequenceNumService.getAndIncreaseByCode(ItemIncreaseCodeEnum.IC.toString()); |
7fd198
|
115 |
String str = String.format("%010d", sequenceNumEntity.getSequenceNum()); |
潘 |
116 |
predictItem.setItemno(sequenceNumEntity.getPrefix() + str); |
|
117 |
|
|
118 |
MmPredictMergeItemEntity mMmPredictMergeItem = mmPredictItemDto.getMmPredictMergeItem(); |
|
119 |
mMmPredictMergeItem.setItemid(predictItem.getId()); |
|
120 |
mmPredictMergeItemService.savePredictMergeItem(mMmPredictMergeItem); |
|
121 |
} |
5c6007
|
122 |
mmPredictItemDao.insert(predictItem); |
7fd198
|
123 |
DmModuleItemEntity dmModuleItem = mmPredictItemDto.getDmModuleItem(); |
潘 |
124 |
dmModuleItem.setItemid(predictItem.getId()); |
|
125 |
dmModuleItemService.saveModuleItem(dmModuleItem); |
|
126 |
|
69bd5e
|
127 |
List<MmItemOutputEntity> mmItemOutput = mmPredictItemDto.getMmItemOutputList(); |
D |
128 |
mmItemOutput.forEach(e -> { |
|
129 |
e.setId(UUID.randomUUID().toString()); |
|
130 |
e.setItemid(predictItem.getId()); |
|
131 |
}); |
7fd198
|
132 |
mmItemOutputService.saveMmItemOutput(mmItemOutput); |
91343d
|
133 |
|
潘 |
134 |
// 清空缓存 |
|
135 |
clearCatch(); |
5d299c
|
136 |
} |
L |
137 |
|
e6753e
|
138 |
@DSTransactional(rollbackFor = Exception.class) |
7fd198
|
139 |
@Override |
潘 |
140 |
public void update(MmPredictItemDTO mmPredictItemDto) { |
|
141 |
MmPredictItemEntity predictItem = mmPredictItemDto.getMmPredictItem(); |
|
142 |
predictItem.setUpdateTime(new Date()); |
5d299c
|
143 |
mmPredictItemDao.updateById(predictItem); |
7fd198
|
144 |
MmItemTypeEntity itemType = mmItemTypeImpl.getById(predictItem.getItemtypeid()); |
5d299c
|
145 |
if (itemType != null && ItemTypeEnum.NORMAL_ITEM.getName().equals(itemType.getItemtypename())) { |
7fd198
|
146 |
MmPredictModelEntity mmPredictModel = mmPredictItemDto.getMmPredictModel(); |
潘 |
147 |
mmPredictModelService.update(mmPredictModel); |
|
148 |
|
|
149 |
List<MmModelArithSettingsEntity> mmModelArithSettingsList = mmPredictItemDto.getMmModelArithSettingsList(); |
|
150 |
mmModelArithSettingsList.forEach(item -> { |
|
151 |
item.setModelid(mmPredictModel.getId()); |
|
152 |
}); |
|
153 |
mmModelArithSettingsService.saveList(mmModelArithSettingsList); |
|
154 |
|
|
155 |
List<MmModelParamEntity> mmModelParamList = mmPredictItemDto.getMmModelParamList(); |
|
156 |
mmModelParamList.forEach(item -> { |
|
157 |
item.setModelid(mmPredictModel.getId()); |
|
158 |
}); |
|
159 |
mmModelParamService.saveList(mmModelParamList); |
5d299c
|
160 |
} else if (itemType != null && ItemTypeEnum.MERGE_ITEM.getName().equals(itemType.getItemtypename())) { |
7fd198
|
161 |
MmPredictMergeItemEntity mMmPredictMergeItem = mmPredictItemDto.getMmPredictMergeItem(); |
潘 |
162 |
mmPredictMergeItemService.update(mMmPredictMergeItem); |
|
163 |
} |
|
164 |
DmModuleItemEntity dmModuleItem = mmPredictItemDto.getDmModuleItem(); |
e6753e
|
165 |
if (!"".equals(dmModuleItem.getId()) && dmModuleItem.getId() != null) { |
5d299c
|
166 |
dmModuleItemService.update(dmModuleItem); |
L |
167 |
} |
69bd5e
|
168 |
mmItemOutputService.deleteByItemId(predictItem.getId()); |
D |
169 |
List<MmItemOutputEntity> mmItemOutput = mmPredictItemDto.getMmItemOutputList(); |
19a4fb
|
170 |
if (!CollectionUtils.isEmpty(mmItemOutput)) { |
D |
171 |
mmItemOutput.forEach(e -> { |
|
172 |
// 尽量保存原有id |
|
173 |
if (StringUtils.isBlank(e.getId())) { |
|
174 |
e.setId(UUID.randomUUID().toString()); |
|
175 |
} |
|
176 |
e.setItemid(predictItem.getId()); |
|
177 |
}); |
|
178 |
mmItemOutputService.saveMmItemOutput(mmItemOutput); |
|
179 |
} |
|
180 |
|
91343d
|
181 |
|
潘 |
182 |
// 清空缓存 |
|
183 |
clearCatch(); |
5d299c
|
184 |
} |
L |
185 |
|
e6753e
|
186 |
@DSTransactional(rollbackFor = Exception.class) |
7fd198
|
187 |
@Override |
潘 |
188 |
public void deleteBatch(String[] itemIds) { |
5c6007
|
189 |
mmPredictItemDao.deleteBatchIds(Arrays.asList(itemIds)); |
7fd198
|
190 |
mmPredictMergeItemService.deleteBatch(itemIds); |
潘 |
191 |
mmPredictModelService.deleteBatch(itemIds); |
|
192 |
mmItemOutputService.deleteBatch(itemIds); |
91343d
|
193 |
|
潘 |
194 |
// 清空缓存 |
|
195 |
clearCatch(); |
7fd198
|
196 |
} |
潘 |
197 |
|
|
198 |
@Override |
5c6007
|
199 |
public MmPredictItemDTO info(String id) { |
L |
200 |
MmPredictItemEntity predictItem = mmPredictItemDao.selectById(id); |
|
201 |
MmPredictItemDTO mmPredictItemDto = BeanUtils.toBean(predictItem, MmPredictItemDTO.class); |
7fd198
|
202 |
mmPredictItemDto.setMmPredictItem(predictItem); |
潘 |
203 |
mmPredictItemDto.setDmModuleItem(dmModuleItemService.getByItemid(id)); |
69bd5e
|
204 |
mmPredictItemDto.setMmItemOutputList(mmItemOutputService.getByItemid(id)); |
7fd198
|
205 |
MmItemTypeEntity itemType = mmItemTypeImpl.getById(predictItem.getItemtypeid()); |
5d299c
|
206 |
if (itemType != null && ItemTypeEnum.NORMAL_ITEM.getName().equals(itemType.getItemtypename())) { |
7fd198
|
207 |
MmPredictModelEntity mmPredictModel = mmPredictModelService.getByItemid(id); |
潘 |
208 |
mmPredictItemDto.setMmPredictModel(mmPredictModel); |
214275
|
209 |
mmPredictItemDto.setMmModelArithSettingsList(mmModelArithSettingsService.getByModelId(mmPredictModel.getId())); |
7fd198
|
210 |
mmPredictItemDto.setMmModelParamList(mmModelParamService.getByModelid(mmPredictModel.getId())); |
e6753e
|
211 |
mmPredictItemDto.setMmPredictMergeItem(new MmPredictMergeItemEntity()); |
5d299c
|
212 |
} else if (itemType != null && ItemTypeEnum.MERGE_ITEM.getName().equals(itemType.getItemtypename())) { |
7800dd
|
213 |
mmPredictItemDto.setMmPredictModel(new MmPredictModelEntity()); |
潘 |
214 |
mmPredictItemDto.setMmModelArithSettingsList(new ArrayList<>()); |
|
215 |
mmPredictItemDto.setMmModelParamList(new ArrayList<>()); |
|
216 |
mmPredictItemDto.setMmPredictMergeItem(new MmPredictMergeItemEntity()); |
7fd198
|
217 |
mmPredictItemDto.setMmPredictMergeItem(mmPredictMergeItemService.getByItemid(id)); |
潘 |
218 |
} |
|
219 |
return mmPredictItemDto; |
|
220 |
} |
|
221 |
|
|
222 |
@Override |
|
223 |
public int check(MmPredictItemEntity mmPredictItem) { |
|
224 |
String id = mmPredictItem.getId(); |
|
225 |
String itemname = mmPredictItem.getItemname(); |
|
226 |
String itemno = mmPredictItem.getItemno(); |
|
227 |
QueryWrapper<MmPredictItemEntity> queryWrapper = new QueryWrapper<>(); |
|
228 |
queryWrapper.ne(StringUtils.isNotBlank(id), "id", id); |
|
229 |
queryWrapper.and(wrapper -> wrapper.eq("itemname", itemname).or().eq("itemno", itemno)); |
5c6007
|
230 |
List<MmPredictItemEntity> list = mmPredictItemDao.selectList(queryWrapper); |
7fd198
|
231 |
return list.size(); |
潘 |
232 |
} |
|
233 |
|
|
234 |
@Override |
|
235 |
public List<ItemVO> getByModuleId(String moduleId) { |
|
236 |
Map<String, Object> params = new HashMap<>(); |
1a2b62
|
237 |
params.put("MODULEID",moduleId); |
5c6007
|
238 |
return mmPredictItemDao.getByModuleId(params); |
7fd198
|
239 |
} |
潘 |
240 |
|
|
241 |
@Override |
|
242 |
public ItemVO getItemByItemNo(String itemNo) { |
|
243 |
if (StringUtils.isBlank(itemNo)) { |
|
244 |
return null; |
|
245 |
} |
|
246 |
Map<String, Object> params = new HashMap(1); |
|
247 |
params.put("ITEMNO", itemNo); |
5c6007
|
248 |
List<ItemVO> list = mmPredictItemDao.getItem(params); |
7fd198
|
249 |
if (CollectionUtils.isEmpty(list)) { |
潘 |
250 |
return null; |
|
251 |
} |
|
252 |
return list.get(0); |
|
253 |
} |
|
254 |
|
|
255 |
@Override |
91343d
|
256 |
public void clearCatch() { |
潘 |
257 |
itemVOHashMap.clear(); |
|
258 |
} |
|
259 |
|
|
260 |
@Override |
b82ba2
|
261 |
public ItemVO getItemByIdFromCache(String itemId) { |
7fd198
|
262 |
if (StringUtils.isBlank(itemId)) { |
潘 |
263 |
return null; |
|
264 |
} |
91343d
|
265 |
if (!itemVOHashMap.containsKey(itemId)) { |
潘 |
266 |
Map<String, Object> params = new HashMap<>(1); |
|
267 |
params.put("ITEMID", itemId); |
|
268 |
List<ItemVO> list = mmPredictItemDao.getItem(params); |
|
269 |
if (CollectionUtils.isEmpty(list)) { |
|
270 |
return null; |
|
271 |
} |
|
272 |
itemVOHashMap.put(itemId, list.get(0)); |
7fd198
|
273 |
} |
91343d
|
274 |
return itemVOHashMap.get(itemId); |
7fd198
|
275 |
} |
潘 |
276 |
|
|
277 |
@Override |
b82ba2
|
278 |
public ItemVO getItemById(String itemId) { |
D |
279 |
Map<String, Object> params = new HashMap<>(1); |
|
280 |
params.put("ITEMID", itemId); |
|
281 |
List<ItemVO> list = mmPredictItemDao.getItem(params); |
|
282 |
if (CollectionUtils.isEmpty(list)) { |
|
283 |
return null; |
|
284 |
} |
|
285 |
return list.get(0); |
|
286 |
} |
|
287 |
|
|
288 |
@Override |
19a4fb
|
289 |
public ItemVO getItemByOutPutId(String outPutId) { |
D |
290 |
if (StringUtils.isBlank(outPutId)) { |
|
291 |
return null; |
|
292 |
} |
|
293 |
MmItemOutputEntity outPutById = mmItemOutputService.getOutPutById(outPutId); |
|
294 |
if (ObjectUtils.isEmpty(outPutById)) { |
|
295 |
return null; |
|
296 |
} |
|
297 |
String itemId = outPutById.getItemid(); |
b82ba2
|
298 |
return getItemByIdFromCache(itemId); |
19a4fb
|
299 |
} |
D |
300 |
|
|
301 |
@Override |
7fd198
|
302 |
public MergeItemVO getMergeItemByItemId(String itemId) { |
潘 |
303 |
if (StringUtils.isBlank(itemId)) { |
|
304 |
return null; |
|
305 |
} |
|
306 |
Map<String, Object> params = new HashMap(1); |
|
307 |
params.put("ITEMID", itemId); |
5c6007
|
308 |
List<MergeItemVO> list = mmPredictItemDao.getMergeItemByItemId(params); |
7fd198
|
309 |
if (CollectionUtils.isEmpty(list)) { |
潘 |
310 |
return null; |
|
311 |
} |
|
312 |
return list.get(0); |
|
313 |
} |
|
314 |
} |