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