提交 | 用户 | 时间
|
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); |
b40862
|
121 |
// 添加一条默认output |
D |
122 |
List<MmItemOutputEntity> mergeItemOutput = new ArrayList<>(1); |
|
123 |
MmItemOutputEntity entity = new MmItemOutputEntity(); |
|
124 |
entity.setPointid(mmPredictItemDto.getPointId()); |
|
125 |
entity.setResultName(mmPredictItemDto.getMmPredictItem().getItemname()); |
fde993
|
126 |
entity.setResultstr("result"); |
b40862
|
127 |
mergeItemOutput.add(entity); |
D |
128 |
mmPredictItemDto.setMmItemOutputList(mergeItemOutput); |
7fd198
|
129 |
} |
5c6007
|
130 |
mmPredictItemDao.insert(predictItem); |
7fd198
|
131 |
DmModuleItemEntity dmModuleItem = mmPredictItemDto.getDmModuleItem(); |
潘 |
132 |
dmModuleItem.setItemid(predictItem.getId()); |
|
133 |
dmModuleItemService.saveModuleItem(dmModuleItem); |
|
134 |
|
69bd5e
|
135 |
List<MmItemOutputEntity> mmItemOutput = mmPredictItemDto.getMmItemOutputList(); |
D |
136 |
mmItemOutput.forEach(e -> { |
|
137 |
e.setId(UUID.randomUUID().toString()); |
|
138 |
e.setItemid(predictItem.getId()); |
|
139 |
}); |
7fd198
|
140 |
mmItemOutputService.saveMmItemOutput(mmItemOutput); |
91343d
|
141 |
|
潘 |
142 |
// 清空缓存 |
|
143 |
clearCatch(); |
5d299c
|
144 |
} |
L |
145 |
|
e6753e
|
146 |
@DSTransactional(rollbackFor = Exception.class) |
7fd198
|
147 |
@Override |
潘 |
148 |
public void update(MmPredictItemDTO mmPredictItemDto) { |
|
149 |
MmPredictItemEntity predictItem = mmPredictItemDto.getMmPredictItem(); |
|
150 |
predictItem.setUpdateTime(new Date()); |
5d299c
|
151 |
mmPredictItemDao.updateById(predictItem); |
7fd198
|
152 |
MmItemTypeEntity itemType = mmItemTypeImpl.getById(predictItem.getItemtypeid()); |
5d299c
|
153 |
if (itemType != null && ItemTypeEnum.NORMAL_ITEM.getName().equals(itemType.getItemtypename())) { |
7fd198
|
154 |
MmPredictModelEntity mmPredictModel = mmPredictItemDto.getMmPredictModel(); |
潘 |
155 |
mmPredictModelService.update(mmPredictModel); |
|
156 |
|
|
157 |
List<MmModelArithSettingsEntity> mmModelArithSettingsList = mmPredictItemDto.getMmModelArithSettingsList(); |
|
158 |
mmModelArithSettingsList.forEach(item -> { |
|
159 |
item.setModelid(mmPredictModel.getId()); |
|
160 |
}); |
|
161 |
mmModelArithSettingsService.saveList(mmModelArithSettingsList); |
|
162 |
|
|
163 |
List<MmModelParamEntity> mmModelParamList = mmPredictItemDto.getMmModelParamList(); |
|
164 |
mmModelParamList.forEach(item -> { |
|
165 |
item.setModelid(mmPredictModel.getId()); |
|
166 |
}); |
|
167 |
mmModelParamService.saveList(mmModelParamList); |
5d299c
|
168 |
} else if (itemType != null && ItemTypeEnum.MERGE_ITEM.getName().equals(itemType.getItemtypename())) { |
7fd198
|
169 |
MmPredictMergeItemEntity mMmPredictMergeItem = mmPredictItemDto.getMmPredictMergeItem(); |
潘 |
170 |
mmPredictMergeItemService.update(mMmPredictMergeItem); |
b40862
|
171 |
// 修改默认output |
fde993
|
172 |
List<MmItemOutputEntity> mmItemOutputList = mmPredictItemDto.getMmItemOutputList(); |
D |
173 |
if (CollectionUtils.isEmpty(mmItemOutputList)) { |
|
174 |
mmItemOutputList = new ArrayList<>(1); |
|
175 |
MmItemOutputEntity entity = new MmItemOutputEntity(); |
|
176 |
entity.setPointid(mmPredictItemDto.getPointId()); |
|
177 |
entity.setResultName(mmPredictItemDto.getMmPredictItem().getItemname()); |
|
178 |
entity.setResultstr("result"); |
|
179 |
mmItemOutputList.add(entity); |
|
180 |
mmPredictItemDto.setMmItemOutputList(mmItemOutputList); |
|
181 |
} else { |
|
182 |
mmPredictItemDto.getMmItemOutputList().forEach(e -> e.setPointid(mmPredictItemDto.getPointId())); |
|
183 |
} |
7fd198
|
184 |
} |
潘 |
185 |
DmModuleItemEntity dmModuleItem = mmPredictItemDto.getDmModuleItem(); |
e6753e
|
186 |
if (!"".equals(dmModuleItem.getId()) && dmModuleItem.getId() != null) { |
5d299c
|
187 |
dmModuleItemService.update(dmModuleItem); |
L |
188 |
} |
69bd5e
|
189 |
mmItemOutputService.deleteByItemId(predictItem.getId()); |
D |
190 |
List<MmItemOutputEntity> mmItemOutput = mmPredictItemDto.getMmItemOutputList(); |
19a4fb
|
191 |
if (!CollectionUtils.isEmpty(mmItemOutput)) { |
D |
192 |
mmItemOutput.forEach(e -> { |
|
193 |
// 尽量保存原有id |
|
194 |
if (StringUtils.isBlank(e.getId())) { |
|
195 |
e.setId(UUID.randomUUID().toString()); |
|
196 |
} |
|
197 |
e.setItemid(predictItem.getId()); |
|
198 |
}); |
|
199 |
mmItemOutputService.saveMmItemOutput(mmItemOutput); |
|
200 |
} |
|
201 |
|
91343d
|
202 |
|
潘 |
203 |
// 清空缓存 |
|
204 |
clearCatch(); |
5d299c
|
205 |
} |
L |
206 |
|
e6753e
|
207 |
@DSTransactional(rollbackFor = Exception.class) |
7fd198
|
208 |
@Override |
潘 |
209 |
public void deleteBatch(String[] itemIds) { |
5c6007
|
210 |
mmPredictItemDao.deleteBatchIds(Arrays.asList(itemIds)); |
7fd198
|
211 |
mmPredictMergeItemService.deleteBatch(itemIds); |
潘 |
212 |
mmPredictModelService.deleteBatch(itemIds); |
|
213 |
mmItemOutputService.deleteBatch(itemIds); |
91343d
|
214 |
|
潘 |
215 |
// 清空缓存 |
|
216 |
clearCatch(); |
7fd198
|
217 |
} |
潘 |
218 |
|
|
219 |
@Override |
5c6007
|
220 |
public MmPredictItemDTO info(String id) { |
L |
221 |
MmPredictItemEntity predictItem = mmPredictItemDao.selectById(id); |
|
222 |
MmPredictItemDTO mmPredictItemDto = BeanUtils.toBean(predictItem, MmPredictItemDTO.class); |
7fd198
|
223 |
mmPredictItemDto.setMmPredictItem(predictItem); |
潘 |
224 |
mmPredictItemDto.setDmModuleItem(dmModuleItemService.getByItemid(id)); |
69bd5e
|
225 |
mmPredictItemDto.setMmItemOutputList(mmItemOutputService.getByItemid(id)); |
7fd198
|
226 |
MmItemTypeEntity itemType = mmItemTypeImpl.getById(predictItem.getItemtypeid()); |
5d299c
|
227 |
if (itemType != null && ItemTypeEnum.NORMAL_ITEM.getName().equals(itemType.getItemtypename())) { |
7fd198
|
228 |
MmPredictModelEntity mmPredictModel = mmPredictModelService.getByItemid(id); |
潘 |
229 |
mmPredictItemDto.setMmPredictModel(mmPredictModel); |
214275
|
230 |
mmPredictItemDto.setMmModelArithSettingsList(mmModelArithSettingsService.getByModelId(mmPredictModel.getId())); |
7fd198
|
231 |
mmPredictItemDto.setMmModelParamList(mmModelParamService.getByModelid(mmPredictModel.getId())); |
e6753e
|
232 |
mmPredictItemDto.setMmPredictMergeItem(new MmPredictMergeItemEntity()); |
5d299c
|
233 |
} else if (itemType != null && ItemTypeEnum.MERGE_ITEM.getName().equals(itemType.getItemtypename())) { |
7800dd
|
234 |
mmPredictItemDto.setMmPredictModel(new MmPredictModelEntity()); |
潘 |
235 |
mmPredictItemDto.setMmModelArithSettingsList(new ArrayList<>()); |
|
236 |
mmPredictItemDto.setMmModelParamList(new ArrayList<>()); |
|
237 |
mmPredictItemDto.setMmPredictMergeItem(new MmPredictMergeItemEntity()); |
7fd198
|
238 |
mmPredictItemDto.setMmPredictMergeItem(mmPredictMergeItemService.getByItemid(id)); |
b40862
|
239 |
if (!CollectionUtils.isEmpty(mmPredictItemDto.getMmItemOutputList())) { |
D |
240 |
mmPredictItemDto.setPointId(mmPredictItemDto.getMmItemOutputList().get(0).getPointid()); |
|
241 |
} |
7fd198
|
242 |
} |
潘 |
243 |
return mmPredictItemDto; |
|
244 |
} |
|
245 |
|
|
246 |
@Override |
|
247 |
public int check(MmPredictItemEntity mmPredictItem) { |
|
248 |
String id = mmPredictItem.getId(); |
|
249 |
String itemname = mmPredictItem.getItemname(); |
|
250 |
String itemno = mmPredictItem.getItemno(); |
|
251 |
QueryWrapper<MmPredictItemEntity> queryWrapper = new QueryWrapper<>(); |
|
252 |
queryWrapper.ne(StringUtils.isNotBlank(id), "id", id); |
|
253 |
queryWrapper.and(wrapper -> wrapper.eq("itemname", itemname).or().eq("itemno", itemno)); |
5c6007
|
254 |
List<MmPredictItemEntity> list = mmPredictItemDao.selectList(queryWrapper); |
7fd198
|
255 |
return list.size(); |
潘 |
256 |
} |
|
257 |
|
|
258 |
@Override |
|
259 |
public List<ItemVO> getByModuleId(String moduleId) { |
|
260 |
Map<String, Object> params = new HashMap<>(); |
1a2b62
|
261 |
params.put("MODULEID",moduleId); |
5c6007
|
262 |
return mmPredictItemDao.getByModuleId(params); |
7fd198
|
263 |
} |
潘 |
264 |
|
|
265 |
@Override |
|
266 |
public ItemVO getItemByItemNo(String itemNo) { |
|
267 |
if (StringUtils.isBlank(itemNo)) { |
|
268 |
return null; |
|
269 |
} |
|
270 |
Map<String, Object> params = new HashMap(1); |
|
271 |
params.put("ITEMNO", itemNo); |
5c6007
|
272 |
List<ItemVO> list = mmPredictItemDao.getItem(params); |
7fd198
|
273 |
if (CollectionUtils.isEmpty(list)) { |
潘 |
274 |
return null; |
|
275 |
} |
|
276 |
return list.get(0); |
|
277 |
} |
|
278 |
|
|
279 |
@Override |
91343d
|
280 |
public void clearCatch() { |
潘 |
281 |
itemVOHashMap.clear(); |
|
282 |
} |
|
283 |
|
|
284 |
@Override |
b82ba2
|
285 |
public ItemVO getItemByIdFromCache(String itemId) { |
7fd198
|
286 |
if (StringUtils.isBlank(itemId)) { |
潘 |
287 |
return null; |
|
288 |
} |
91343d
|
289 |
if (!itemVOHashMap.containsKey(itemId)) { |
潘 |
290 |
Map<String, Object> params = new HashMap<>(1); |
|
291 |
params.put("ITEMID", itemId); |
|
292 |
List<ItemVO> list = mmPredictItemDao.getItem(params); |
|
293 |
if (CollectionUtils.isEmpty(list)) { |
|
294 |
return null; |
|
295 |
} |
|
296 |
itemVOHashMap.put(itemId, list.get(0)); |
7fd198
|
297 |
} |
91343d
|
298 |
return itemVOHashMap.get(itemId); |
7fd198
|
299 |
} |
潘 |
300 |
|
|
301 |
@Override |
b82ba2
|
302 |
public ItemVO getItemById(String itemId) { |
D |
303 |
Map<String, Object> params = new HashMap<>(1); |
|
304 |
params.put("ITEMID", itemId); |
|
305 |
List<ItemVO> list = mmPredictItemDao.getItem(params); |
|
306 |
if (CollectionUtils.isEmpty(list)) { |
|
307 |
return null; |
|
308 |
} |
|
309 |
return list.get(0); |
|
310 |
} |
|
311 |
|
|
312 |
@Override |
19a4fb
|
313 |
public ItemVO getItemByOutPutId(String outPutId) { |
D |
314 |
if (StringUtils.isBlank(outPutId)) { |
|
315 |
return null; |
|
316 |
} |
|
317 |
MmItemOutputEntity outPutById = mmItemOutputService.getOutPutById(outPutId); |
|
318 |
if (ObjectUtils.isEmpty(outPutById)) { |
|
319 |
return null; |
|
320 |
} |
|
321 |
String itemId = outPutById.getItemid(); |
b82ba2
|
322 |
return getItemByIdFromCache(itemId); |
19a4fb
|
323 |
} |
D |
324 |
|
|
325 |
@Override |
7fd198
|
326 |
public MergeItemVO getMergeItemByItemId(String itemId) { |
潘 |
327 |
if (StringUtils.isBlank(itemId)) { |
|
328 |
return null; |
|
329 |
} |
|
330 |
Map<String, Object> params = new HashMap(1); |
|
331 |
params.put("ITEMID", itemId); |
5c6007
|
332 |
List<MergeItemVO> list = mmPredictItemDao.getMergeItemByItemId(params); |
7fd198
|
333 |
if (CollectionUtils.isEmpty(list)) { |
潘 |
334 |
return null; |
|
335 |
} |
|
336 |
return list.get(0); |
|
337 |
} |
|
338 |
} |