提交 | 用户 | 时间
|
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 |
|
5c6007
|
61 |
@Override |
137356
|
62 |
public PageResult<MmPredictItemRespVO> queryPage(MmPredictItemPageReqVO reqVO) { |
潘 |
63 |
IPage<MmPredictItemRespVO> page = mmPredictItemDao.selectPage(reqVO); |
|
64 |
|
6d6394
|
65 |
return new PageResult<>(page.getRecords(), page.getTotal()); |
7fd198
|
66 |
} |
5d299c
|
67 |
|
7fd198
|
68 |
@Override |
a97b38
|
69 |
public List<MmPredictItemRespVO> list(Map<String, Object> params) { |
潘 |
70 |
return mmPredictItemDao.queryList(params); |
5c6007
|
71 |
} |
L |
72 |
|
9f049d
|
73 |
@Override |
J |
74 |
public MmPredictItemEntity getById(String id) { |
|
75 |
return mmPredictItemDao.selectById(id); |
|
76 |
} |
|
77 |
|
|
78 |
@Override |
|
79 |
public List<Object[]> getHisData(String itemId, Date startTime, Date endTime) { |
|
80 |
List<Object[]> result = new ArrayList<>(); |
|
81 |
return result; |
|
82 |
} |
|
83 |
|
e6753e
|
84 |
@DSTransactional(rollbackFor = Exception.class) |
5c6007
|
85 |
@Override |
5d299c
|
86 |
public void add(MmPredictItemDTO mmPredictItemDto) { |
7fd198
|
87 |
MmPredictItemEntity predictItem = mmPredictItemDto.getMmPredictItem(); |
潘 |
88 |
predictItem.setId(UUID.randomUUID().toString()); |
|
89 |
predictItem.setCreateTime(new Date()); |
|
90 |
predictItem.setUpdateTime(new Date()); |
|
91 |
|
|
92 |
MmItemTypeEntity itemType = mmItemTypeImpl.getById(predictItem.getItemtypeid()); |
5d299c
|
93 |
if (itemType != null && ItemTypeEnum.NORMAL_ITEM.getName().equals(itemType.getItemtypename())) { |
48c57b
|
94 |
MmSequenceNumEntity sequenceNumEntity = sequenceNumService.getAndIncreaseByCode(ItemIncreaseCodeEnum.IM.toString()); |
7fd198
|
95 |
String str = String.format("%010d", sequenceNumEntity.getSequenceNum()); |
潘 |
96 |
predictItem.setItemno(sequenceNumEntity.getPrefix() + str); |
|
97 |
|
|
98 |
MmPredictModelEntity mmPredictModel = mmPredictItemDto.getMmPredictModel(); |
48c57b
|
99 |
MmSequenceNumEntity preMdlSequenceNumEntity = sequenceNumService.getAndIncreaseByCode(ItemIncreaseCodeEnum.PRE_MDL.toString()); |
7fd198
|
100 |
String preMdlStr = String.format("%04d", preMdlSequenceNumEntity.getSequenceNum()); |
潘 |
101 |
mmPredictModel.setModelno(preMdlSequenceNumEntity.getPrefix() + preMdlStr); |
|
102 |
mmPredictModel.setItemid(predictItem.getId()); |
|
103 |
mmPredictModelService.savePredictModel(mmPredictModel); |
|
104 |
|
|
105 |
List<MmModelArithSettingsEntity> mmModelArithSettingsList = mmPredictItemDto.getMmModelArithSettingsList(); |
|
106 |
mmModelArithSettingsList.forEach(item -> { |
|
107 |
item.setModelid(mmPredictModel.getId()); |
|
108 |
}); |
|
109 |
mmModelArithSettingsService.saveList(mmModelArithSettingsList); |
|
110 |
|
|
111 |
List<MmModelParamEntity> mmModelParamList = mmPredictItemDto.getMmModelParamList(); |
|
112 |
mmModelParamList.forEach(item -> { |
|
113 |
item.setModelid(mmPredictModel.getId()); |
|
114 |
}); |
|
115 |
mmModelParamService.saveList(mmModelParamList); |
5d299c
|
116 |
} else if (itemType != null && ItemTypeEnum.MERGE_ITEM.getName().equals(itemType.getItemtypename())) { |
48c57b
|
117 |
MmSequenceNumEntity sequenceNumEntity = sequenceNumService.getAndIncreaseByCode(ItemIncreaseCodeEnum.IC.toString()); |
7fd198
|
118 |
String str = String.format("%010d", sequenceNumEntity.getSequenceNum()); |
潘 |
119 |
predictItem.setItemno(sequenceNumEntity.getPrefix() + str); |
|
120 |
|
|
121 |
MmPredictMergeItemEntity mMmPredictMergeItem = mmPredictItemDto.getMmPredictMergeItem(); |
|
122 |
mMmPredictMergeItem.setItemid(predictItem.getId()); |
|
123 |
mmPredictMergeItemService.savePredictMergeItem(mMmPredictMergeItem); |
|
124 |
} |
5c6007
|
125 |
mmPredictItemDao.insert(predictItem); |
7fd198
|
126 |
DmModuleItemEntity dmModuleItem = mmPredictItemDto.getDmModuleItem(); |
潘 |
127 |
dmModuleItem.setItemid(predictItem.getId()); |
|
128 |
dmModuleItemService.saveModuleItem(dmModuleItem); |
|
129 |
|
69bd5e
|
130 |
List<MmItemOutputEntity> mmItemOutput = mmPredictItemDto.getMmItemOutputList(); |
D |
131 |
mmItemOutput.forEach(e -> { |
|
132 |
e.setId(UUID.randomUUID().toString()); |
|
133 |
e.setItemid(predictItem.getId()); |
|
134 |
}); |
7fd198
|
135 |
mmItemOutputService.saveMmItemOutput(mmItemOutput); |
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(); |
|
170 |
mmItemOutput.forEach(e -> { |
|
171 |
e.setId(UUID.randomUUID().toString()); |
|
172 |
e.setItemid(predictItem.getId()); |
|
173 |
}); |
|
174 |
mmItemOutputService.saveMmItemOutput(mmItemOutput); |
5d299c
|
175 |
} |
L |
176 |
|
e6753e
|
177 |
@DSTransactional(rollbackFor = Exception.class) |
7fd198
|
178 |
@Override |
潘 |
179 |
public void deleteBatch(String[] itemIds) { |
5c6007
|
180 |
mmPredictItemDao.deleteBatchIds(Arrays.asList(itemIds)); |
7fd198
|
181 |
mmPredictMergeItemService.deleteBatch(itemIds); |
潘 |
182 |
mmPredictModelService.deleteBatch(itemIds); |
|
183 |
mmItemOutputService.deleteBatch(itemIds); |
|
184 |
} |
|
185 |
|
|
186 |
@Override |
5c6007
|
187 |
public MmPredictItemDTO info(String id) { |
L |
188 |
MmPredictItemEntity predictItem = mmPredictItemDao.selectById(id); |
|
189 |
MmPredictItemDTO mmPredictItemDto = BeanUtils.toBean(predictItem, MmPredictItemDTO.class); |
7fd198
|
190 |
mmPredictItemDto.setMmPredictItem(predictItem); |
潘 |
191 |
mmPredictItemDto.setDmModuleItem(dmModuleItemService.getByItemid(id)); |
69bd5e
|
192 |
mmPredictItemDto.setMmItemOutputList(mmItemOutputService.getByItemid(id)); |
7fd198
|
193 |
MmItemTypeEntity itemType = mmItemTypeImpl.getById(predictItem.getItemtypeid()); |
5d299c
|
194 |
if (itemType != null && ItemTypeEnum.NORMAL_ITEM.getName().equals(itemType.getItemtypename())) { |
7fd198
|
195 |
MmPredictModelEntity mmPredictModel = mmPredictModelService.getByItemid(id); |
潘 |
196 |
mmPredictItemDto.setMmPredictModel(mmPredictModel); |
|
197 |
mmPredictItemDto.setMmModelArithSettingsList(mmModelArithSettingsService.getByModelid(mmPredictModel.getId())); |
|
198 |
mmPredictItemDto.setMmModelParamList(mmModelParamService.getByModelid(mmPredictModel.getId())); |
e6753e
|
199 |
mmPredictItemDto.setMmPredictMergeItem(new MmPredictMergeItemEntity()); |
5d299c
|
200 |
} else if (itemType != null && ItemTypeEnum.MERGE_ITEM.getName().equals(itemType.getItemtypename())) { |
7800dd
|
201 |
mmPredictItemDto.setMmPredictModel(new MmPredictModelEntity()); |
潘 |
202 |
mmPredictItemDto.setMmModelArithSettingsList(new ArrayList<>()); |
|
203 |
mmPredictItemDto.setMmModelParamList(new ArrayList<>()); |
|
204 |
mmPredictItemDto.setMmPredictMergeItem(new MmPredictMergeItemEntity()); |
7fd198
|
205 |
mmPredictItemDto.setMmPredictMergeItem(mmPredictMergeItemService.getByItemid(id)); |
潘 |
206 |
} |
|
207 |
return mmPredictItemDto; |
|
208 |
} |
|
209 |
|
|
210 |
@Override |
|
211 |
public int check(MmPredictItemEntity mmPredictItem) { |
|
212 |
String id = mmPredictItem.getId(); |
|
213 |
String itemname = mmPredictItem.getItemname(); |
|
214 |
String itemno = mmPredictItem.getItemno(); |
|
215 |
QueryWrapper<MmPredictItemEntity> queryWrapper = new QueryWrapper<>(); |
|
216 |
queryWrapper.ne(StringUtils.isNotBlank(id), "id", id); |
|
217 |
queryWrapper.and(wrapper -> wrapper.eq("itemname", itemname).or().eq("itemno", itemno)); |
5c6007
|
218 |
List<MmPredictItemEntity> list = mmPredictItemDao.selectList(queryWrapper); |
7fd198
|
219 |
return list.size(); |
潘 |
220 |
} |
|
221 |
|
|
222 |
@Override |
|
223 |
public List<ItemVO> getByModuleId(String moduleId) { |
|
224 |
Map<String, Object> params = new HashMap<>(); |
1a2b62
|
225 |
params.put("MODULEID",moduleId); |
5c6007
|
226 |
return mmPredictItemDao.getByModuleId(params); |
7fd198
|
227 |
} |
潘 |
228 |
|
|
229 |
@Override |
|
230 |
public ItemVO getItemByItemNo(String itemNo) { |
|
231 |
if (StringUtils.isBlank(itemNo)) { |
|
232 |
return null; |
|
233 |
} |
|
234 |
Map<String, Object> params = new HashMap(1); |
|
235 |
params.put("ITEMNO", itemNo); |
5c6007
|
236 |
List<ItemVO> list = mmPredictItemDao.getItem(params); |
7fd198
|
237 |
if (CollectionUtils.isEmpty(list)) { |
潘 |
238 |
return null; |
|
239 |
} |
|
240 |
return list.get(0); |
|
241 |
} |
|
242 |
|
|
243 |
@Override |
|
244 |
public ItemVO getItemById(String itemId) { |
|
245 |
if (StringUtils.isBlank(itemId)) { |
|
246 |
return null; |
|
247 |
} |
|
248 |
Map<String, Object> params = new HashMap(1); |
|
249 |
params.put("ITEMID", itemId); |
5c6007
|
250 |
List<ItemVO> list = mmPredictItemDao.getItem(params); |
7fd198
|
251 |
if (CollectionUtils.isEmpty(list)) { |
潘 |
252 |
return null; |
|
253 |
} |
|
254 |
return list.get(0); |
|
255 |
} |
|
256 |
|
|
257 |
@Override |
|
258 |
public MergeItemVO getMergeItemByItemId(String itemId) { |
|
259 |
if (StringUtils.isBlank(itemId)) { |
|
260 |
return null; |
|
261 |
} |
|
262 |
Map<String, Object> params = new HashMap(1); |
|
263 |
params.put("ITEMID", itemId); |
5c6007
|
264 |
List<MergeItemVO> list = mmPredictItemDao.getMergeItemByItemId(params); |
7fd198
|
265 |
if (CollectionUtils.isEmpty(list)) { |
潘 |
266 |
return null; |
|
267 |
} |
|
268 |
return list.get(0); |
|
269 |
} |
|
270 |
} |