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