提交 | 用户 | 时间
|
7fd198
|
1 |
package com.iailab.module.model.mcs.pre.service.impl; |
潘 |
2 |
|
|
3 |
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
4 |
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
5 |
import com.iailab.framework.common.page.PageData; |
|
6 |
import com.iailab.framework.common.pojo.PageResult; |
|
7 |
import com.iailab.framework.common.service.impl.BaseServiceImpl; |
|
8 |
import com.iailab.module.model.mcs.pre.dao.MmPredictItemDao; |
|
9 |
import com.iailab.module.model.mcs.pre.dto.MmPredictItemDTO; |
|
10 |
import com.iailab.module.model.mcs.pre.entity.*; |
|
11 |
import com.iailab.module.model.mcs.pre.enums.ItemIncreaseCodeEnum; |
|
12 |
import com.iailab.module.model.mcs.pre.enums.ItemTypeEnum; |
|
13 |
import com.iailab.module.model.mcs.pre.service.MmPredictItemService; |
|
14 |
import com.iailab.module.model.mcs.pre.service.SequenceNumService; |
|
15 |
import com.iailab.module.model.mcs.pre.vo.MmPredictItemRespVO; |
|
16 |
import com.iailab.module.model.mdk.vo.ItemVO; |
|
17 |
import com.iailab.module.model.mdk.vo.MergeItemVO; |
|
18 |
import org.apache.commons.lang3.StringUtils; |
|
19 |
import org.springframework.beans.factory.annotation.Autowired; |
|
20 |
import org.springframework.stereotype.Service; |
|
21 |
import org.springframework.transaction.annotation.Transactional; |
|
22 |
import org.springframework.util.CollectionUtils; |
|
23 |
|
|
24 |
import javax.servlet.http.HttpServletRequest; |
|
25 |
import javax.servlet.http.HttpServletResponse; |
|
26 |
import java.text.SimpleDateFormat; |
|
27 |
import java.util.*; |
|
28 |
|
|
29 |
/** |
|
30 |
* @author PanZhibao |
|
31 |
* @date 2021年04月26日 14:03 |
|
32 |
*/ |
|
33 |
@Service("mmPredictItemService") |
|
34 |
public class MmPredictItemServiceImpl extends BaseServiceImpl<MmPredictItemDao, MmPredictItemEntity> implements MmPredictItemService { |
|
35 |
|
|
36 |
@Autowired |
|
37 |
private DmModuleItemServiceImpl dmModuleItemService; |
|
38 |
|
|
39 |
@Autowired |
|
40 |
private MmItemOutputServiceImpl mmItemOutputService; |
|
41 |
|
|
42 |
@Autowired |
|
43 |
private MmPredictModelServiceImpl mmPredictModelService; |
|
44 |
|
|
45 |
@Autowired |
|
46 |
private MmModelArithSettingsServiceImpl mmModelArithSettingsService; |
|
47 |
|
|
48 |
@Autowired |
|
49 |
private MmModelParamServiceImpl mmModelParamService; |
|
50 |
|
|
51 |
@Autowired |
|
52 |
private MmPredictMergeItemServiceImpl mmPredictMergeItemService; |
|
53 |
|
|
54 |
@Autowired |
|
55 |
private MmItemTypeImpl mmItemTypeImpl; |
|
56 |
|
|
57 |
@Autowired |
|
58 |
private SequenceNumService sequenceNumService; |
|
59 |
|
|
60 |
@Override |
|
61 |
public PageResult<MmPredictItemRespVO> getPageList(Map<String, Object> params) { |
|
62 |
PageResult<MmPredictItemRespVO> result = new PageResult(); |
|
63 |
IPage<MmPredictItemRespVO> page = baseDao.getPageList( |
|
64 |
getPage(params, "CREATE_TIME", false), |
|
65 |
params |
|
66 |
); |
|
67 |
result.setList(page.getRecords()); |
|
68 |
result.setTotal(page.getTotal()); |
|
69 |
return result; |
|
70 |
} |
|
71 |
|
|
72 |
private QueryWrapper<MmPredictItemEntity> getWrapper(Map<String, Object> params) { |
|
73 |
QueryWrapper<MmPredictItemEntity> wrapper = new QueryWrapper<>(); |
|
74 |
return wrapper; |
|
75 |
} |
|
76 |
|
|
77 |
@Override |
|
78 |
@Transactional(rollbackFor = Exception.class) |
|
79 |
public void savePredictItem(MmPredictItemDTO mmPredictItemDto) { |
|
80 |
MmPredictItemEntity predictItem = mmPredictItemDto.getMmPredictItem(); |
|
81 |
predictItem.setId(UUID.randomUUID().toString()); |
|
82 |
predictItem.setCreateTime(new Date()); |
|
83 |
predictItem.setUpdateTime(new Date()); |
|
84 |
|
|
85 |
MmItemTypeEntity itemType = mmItemTypeImpl.getById(predictItem.getItemtypeid()); |
|
86 |
if (ItemTypeEnum.NORMAL_ITEM.getName().equals(itemType.getItemtypename())) { |
|
87 |
SequenceNumEntity sequenceNumEntity = sequenceNumService.getAndIncreaseByCode(ItemIncreaseCodeEnum.IM.toString()); |
|
88 |
String str = String.format("%010d", sequenceNumEntity.getSequenceNum()); |
|
89 |
predictItem.setItemno(sequenceNumEntity.getPrefix() + str); |
|
90 |
|
|
91 |
MmPredictModelEntity mmPredictModel = mmPredictItemDto.getMmPredictModel(); |
|
92 |
SequenceNumEntity preMdlSequenceNumEntity = sequenceNumService.getAndIncreaseByCode(ItemIncreaseCodeEnum.PRE_MDL.toString()); |
|
93 |
String preMdlStr = String.format("%04d", preMdlSequenceNumEntity.getSequenceNum()); |
|
94 |
mmPredictModel.setModelno(preMdlSequenceNumEntity.getPrefix() + preMdlStr); |
|
95 |
mmPredictModel.setItemid(predictItem.getId()); |
|
96 |
mmPredictModelService.savePredictModel(mmPredictModel); |
|
97 |
|
|
98 |
List<MmModelArithSettingsEntity> mmModelArithSettingsList = mmPredictItemDto.getMmModelArithSettingsList(); |
|
99 |
mmModelArithSettingsList.forEach(item -> { |
|
100 |
item.setModelid(mmPredictModel.getId()); |
|
101 |
}); |
|
102 |
mmModelArithSettingsService.saveList(mmModelArithSettingsList); |
|
103 |
|
|
104 |
List<MmModelParamEntity> mmModelParamList = mmPredictItemDto.getMmModelParamList(); |
|
105 |
mmModelParamList.forEach(item -> { |
|
106 |
item.setModelid(mmPredictModel.getId()); |
|
107 |
}); |
|
108 |
mmModelParamService.saveList(mmModelParamList); |
|
109 |
} else if (ItemTypeEnum.MERGE_ITEM.getName().equals(itemType.getItemtypename())) { |
|
110 |
SequenceNumEntity sequenceNumEntity = sequenceNumService.getAndIncreaseByCode(ItemIncreaseCodeEnum.IC.toString()); |
|
111 |
String str = String.format("%010d", sequenceNumEntity.getSequenceNum()); |
|
112 |
predictItem.setItemno(sequenceNumEntity.getPrefix() + str); |
|
113 |
|
|
114 |
MmPredictMergeItemEntity mMmPredictMergeItem = mmPredictItemDto.getMmPredictMergeItem(); |
|
115 |
mMmPredictMergeItem.setItemid(predictItem.getId()); |
|
116 |
mmPredictMergeItemService.savePredictMergeItem(mMmPredictMergeItem); |
|
117 |
} |
|
118 |
insert(predictItem); |
|
119 |
DmModuleItemEntity dmModuleItem = mmPredictItemDto.getDmModuleItem(); |
|
120 |
dmModuleItem.setItemid(predictItem.getId()); |
|
121 |
dmModuleItemService.saveModuleItem(dmModuleItem); |
|
122 |
|
|
123 |
MmItemOutputEntity mmItemOutput = mmPredictItemDto.getMmItemOutput(); |
|
124 |
mmItemOutput.setItemid(predictItem.getId()); |
|
125 |
mmItemOutputService.saveMmItemOutput(mmItemOutput); |
|
126 |
} |
|
127 |
|
|
128 |
@Override |
|
129 |
@Transactional(rollbackFor = Exception.class) |
|
130 |
public void update(MmPredictItemDTO mmPredictItemDto) { |
|
131 |
MmPredictItemEntity predictItem = mmPredictItemDto.getMmPredictItem(); |
|
132 |
predictItem.setUpdateTime(new Date()); |
|
133 |
this.updateById(predictItem); |
|
134 |
MmItemTypeEntity itemType = mmItemTypeImpl.getById(predictItem.getItemtypeid()); |
|
135 |
if (ItemTypeEnum.NORMAL_ITEM.getName().equals(itemType.getItemtypename())) { |
|
136 |
MmPredictModelEntity mmPredictModel = mmPredictItemDto.getMmPredictModel(); |
|
137 |
mmPredictModelService.update(mmPredictModel); |
|
138 |
|
|
139 |
List<MmModelArithSettingsEntity> mmModelArithSettingsList = mmPredictItemDto.getMmModelArithSettingsList(); |
|
140 |
mmModelArithSettingsList.forEach(item -> { |
|
141 |
item.setModelid(mmPredictModel.getId()); |
|
142 |
}); |
|
143 |
mmModelArithSettingsService.saveList(mmModelArithSettingsList); |
|
144 |
|
|
145 |
List<MmModelParamEntity> mmModelParamList = mmPredictItemDto.getMmModelParamList(); |
|
146 |
mmModelParamList.forEach(item -> { |
|
147 |
item.setModelid(mmPredictModel.getId()); |
|
148 |
}); |
|
149 |
mmModelParamService.saveList(mmModelParamList); |
|
150 |
} else if (ItemTypeEnum.MERGE_ITEM.getName().equals(itemType.getItemtypename())) { |
|
151 |
MmPredictMergeItemEntity mMmPredictMergeItem = mmPredictItemDto.getMmPredictMergeItem(); |
|
152 |
mmPredictMergeItemService.update(mMmPredictMergeItem); |
|
153 |
} |
|
154 |
DmModuleItemEntity dmModuleItem = mmPredictItemDto.getDmModuleItem(); |
|
155 |
dmModuleItemService.update(dmModuleItem); |
|
156 |
|
|
157 |
MmItemOutputEntity mmItemOutput = mmPredictItemDto.getMmItemOutput(); |
|
158 |
mmItemOutputService.update(mmItemOutput); |
|
159 |
} |
|
160 |
|
|
161 |
@Override |
|
162 |
@Transactional(rollbackFor = Exception.class) |
|
163 |
public void deleteBatch(String[] itemIds) { |
|
164 |
deleteBatchIds(Arrays.asList(itemIds)); |
|
165 |
mmPredictMergeItemService.deleteBatch(itemIds); |
|
166 |
mmPredictModelService.deleteBatch(itemIds); |
|
167 |
mmItemOutputService.deleteBatch(itemIds); |
|
168 |
} |
|
169 |
|
|
170 |
@Override |
|
171 |
public MmPredictItemDTO getDetailById(String id, Map<String, Object> params) { |
|
172 |
MmPredictItemDTO mmPredictItemDto = new MmPredictItemDTO(); |
|
173 |
MmPredictItemEntity predictItem = selectById(id); |
|
174 |
mmPredictItemDto.setMmPredictItem(predictItem); |
|
175 |
mmPredictItemDto.setDmModuleItem(dmModuleItemService.getByItemid(id)); |
|
176 |
mmPredictItemDto.setMmItemOutput(mmItemOutputService.getByItemid(id)); |
|
177 |
MmItemTypeEntity itemType = mmItemTypeImpl.getById(predictItem.getItemtypeid()); |
|
178 |
if (ItemTypeEnum.NORMAL_ITEM.getName().equals(itemType.getItemtypename())) { |
|
179 |
MmPredictModelEntity mmPredictModel = mmPredictModelService.getByItemid(id); |
|
180 |
mmPredictItemDto.setMmPredictModel(mmPredictModel); |
|
181 |
mmPredictItemDto.setMmModelArithSettingsList(mmModelArithSettingsService.getByModelid(mmPredictModel.getId())); |
|
182 |
mmPredictItemDto.setMmModelParamList(mmModelParamService.getByModelid(mmPredictModel.getId())); |
|
183 |
} else if (ItemTypeEnum.MERGE_ITEM.getName().equals(itemType.getItemtypename())) { |
|
184 |
mmPredictItemDto.setMmPredictMergeItem(mmPredictMergeItemService.getByItemid(id)); |
|
185 |
} |
|
186 |
|
|
187 |
return mmPredictItemDto; |
|
188 |
} |
|
189 |
|
|
190 |
@Override |
|
191 |
public boolean exportItemResult(HttpServletResponse response, HttpServletRequest request, String id, Map<String, Object> params) { |
|
192 |
//MmPredictItemDTO mmPredictItemDto = this.getPredictValuesById(id, params); |
|
193 |
//List<MmItemResultEntity> itemResultList = mmPredictItemDto.getMmItemResultList(); |
|
194 |
|
|
195 |
return true; |
|
196 |
} |
|
197 |
|
|
198 |
@Override |
|
199 |
public int check(MmPredictItemEntity mmPredictItem) { |
|
200 |
String id = mmPredictItem.getId(); |
|
201 |
String itemname = mmPredictItem.getItemname(); |
|
202 |
String itemno = mmPredictItem.getItemno(); |
|
203 |
QueryWrapper<MmPredictItemEntity> queryWrapper = new QueryWrapper<>(); |
|
204 |
queryWrapper.ne(StringUtils.isNotBlank(id), "id", id); |
|
205 |
queryWrapper.and(wrapper -> wrapper.eq("itemname", itemname).or().eq("itemno", itemno)); |
|
206 |
List<MmPredictItemEntity> list = baseDao.selectList(queryWrapper); |
|
207 |
return list.size(); |
|
208 |
} |
|
209 |
|
|
210 |
@Override |
|
211 |
public Long count() { |
|
212 |
QueryWrapper<MmPredictItemEntity> queryWrapper = new QueryWrapper<>(); |
|
213 |
return baseDao.selectCount(queryWrapper); |
|
214 |
} |
|
215 |
|
|
216 |
@Override |
|
217 |
public List<ItemVO> getByModuleId(String moduleId) { |
|
218 |
Map<String, Object> params = new HashMap<>(); |
|
219 |
|
|
220 |
return baseDao.getByModuleId(params); |
|
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); |
|
230 |
List<ItemVO> list = baseDao.getItem(params); |
|
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); |
|
244 |
List<ItemVO> list = baseDao.getItem(params); |
|
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); |
|
258 |
List<MergeItemVO> list = baseDao.getMergeItemByItemId(params); |
|
259 |
if (CollectionUtils.isEmpty(list)) { |
|
260 |
return null; |
|
261 |
} |
|
262 |
return list.get(0); |
|
263 |
} |
|
264 |
} |