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