Commit 62c7317cfb8c8cc2d3502704a6ff08cae36b5ebf
1 parent
381454c1
2022年7月26日15:05:44 增加能否修改主题字段
Showing
2 changed files
with
39 additions
and
37 deletions
fw-dalaran-domain/src/main/java/cn/fw/dalaran/domain/vo/ActivityThemeVo.java
fw-dalaran-service/src/main/java/cn/fw/dalaran/service/data/impl/ActivityThemeServiceImpl.java
... | ... | @@ -173,8 +173,7 @@ public class ActivityThemeServiceImpl extends ServiceImpl<ActivityThemeDao, Acti |
173 | 173 | List<String> oldTopic = Arrays.asList(theme.getTopic().split(",").clone()); |
174 | 174 | ArrayList<String> result = new ArrayList<>(newTopic); |
175 | 175 | result.retainAll(oldTopic); |
176 | - long timeSub = System.currentTimeMillis() - theme.getEndTime().getTime(); | |
177 | - if (timeSub > 24 * 3600 * 1000 + 1000) | |
176 | + if (this.themeHaveStopCatchData(theme.getEndTime())) | |
178 | 177 | throw new BusinessException("活动已经结束数据抓取, 不能再增加话题"); |
179 | 178 | if (result.size() < oldTopic.size()) |
180 | 179 | throw new BusinessException("不允许删除原有话题"); |
... | ... | @@ -199,8 +198,7 @@ public class ActivityThemeServiceImpl extends ServiceImpl<ActivityThemeDao, Acti |
199 | 198 | .peek(item -> item.setType(FileTypeEnum.THEME_COVER.getValue())) |
200 | 199 | .collect(Collectors.toList()); |
201 | 200 | ActivityTheme theme = this.getById(themeId); |
202 | - long timeSub = System.currentTimeMillis() - theme.getEndTime().getTime(); | |
203 | - if (timeSub > 24 * 3600 * 1000 + 1000) | |
201 | + if (this.themeHaveStopCatchData(theme.getEndTime())) | |
204 | 202 | throw new BusinessException("活动已经结束数据抓取, 不能再增加封面"); |
205 | 203 | this.saveFiles(themeId, fileList); |
206 | 204 | this.downloadAndConvertCover(theme, fileList); |
... | ... | @@ -223,17 +221,7 @@ public class ActivityThemeServiceImpl extends ServiceImpl<ActivityThemeDao, Acti |
223 | 221 | .list() |
224 | 222 | .stream() |
225 | 223 | .map(ActivityTheme::toVO) |
226 | - .peek(item -> item.setAllFileDesc(Optional.ofNullable( | |
227 | - themeFileService | |
228 | - .lambdaQuery() | |
229 | - .eq(ThemeFile::getThemeId, item.getId()) | |
230 | - .eq(ThemeFile::getType, FileTypeEnum.THEME_COVER.getValue()) | |
231 | - .list()) | |
232 | - .orElse(new ArrayList<>()) | |
233 | - .stream() | |
234 | - .map(ThemeFile::toVO) | |
235 | - .collect(Collectors.toList())) | |
236 | - ) | |
224 | + .peek(this::peekActivityThemeVo) | |
237 | 225 | .collect(Collectors.toList()); |
238 | 226 | } |
239 | 227 | |
... | ... | @@ -259,17 +247,7 @@ public class ActivityThemeServiceImpl extends ServiceImpl<ActivityThemeDao, Acti |
259 | 247 | } |
260 | 248 | pageList.setData(dbList.stream() |
261 | 249 | .map(ActivityTheme::toVO) |
262 | - .peek(item -> item.setAllFileDesc(Optional.ofNullable( | |
263 | - themeFileService | |
264 | - .lambdaQuery() | |
265 | - .eq(ThemeFile::getThemeId, item.getId()) | |
266 | - .eq(ThemeFile::getType, FileTypeEnum.THEME_COVER.getValue()) | |
267 | - .list()) | |
268 | - .orElse(new ArrayList<>()) | |
269 | - .stream() | |
270 | - .map(ThemeFile::toVO) | |
271 | - .collect(Collectors.toList())) | |
272 | - ) | |
250 | + .peek(this::peekActivityThemeVo) | |
273 | 251 | .collect(Collectors.toList()) |
274 | 252 | ); |
275 | 253 | return pageList; |
... | ... | @@ -298,17 +276,7 @@ public class ActivityThemeServiceImpl extends ServiceImpl<ActivityThemeDao, Acti |
298 | 276 | .stream() |
299 | 277 | .filter(item -> this.validDateOverlap(item.getStartTime(), item.getEndTime(), startTime, finalEndTime)) |
300 | 278 | .map(ActivityTheme::toVO) |
301 | - .peek(item -> item.setAllFileDesc(Optional.ofNullable( | |
302 | - themeFileService | |
303 | - .lambdaQuery() | |
304 | - .eq(ThemeFile::getThemeId, item.getId()) | |
305 | - .eq(ThemeFile::getType, FileTypeEnum.THEME_COVER.getValue()) | |
306 | - .list()) | |
307 | - .orElse(new ArrayList<>()) | |
308 | - .stream() | |
309 | - .map(ThemeFile::toVO) | |
310 | - .collect(Collectors.toList())) | |
311 | - ) | |
279 | + .peek(this::peekActivityThemeVo) | |
312 | 280 | .sorted(Comparator.comparing(ActivityThemeVo::getStartTime)) |
313 | 281 | .collect(Collectors.toList()) |
314 | 282 | ; |
... | ... | @@ -434,4 +402,34 @@ public class ActivityThemeServiceImpl extends ServiceImpl<ActivityThemeDao, Acti |
434 | 402 | .update(); |
435 | 403 | } |
436 | 404 | |
405 | + /** | |
406 | + * 判断主题是否结束数据抓取 | |
407 | + * | |
408 | + * @param themeEndTime 主题结束时间 | |
409 | + * @retur 主题是否结束数据抓取 | |
410 | + */ | |
411 | + private boolean themeHaveStopCatchData(Date themeEndTime) { | |
412 | + long timeSub = System.currentTimeMillis() - themeEndTime.getTime(); | |
413 | + return timeSub > 24 * 3600 * 1000 + 1000; | |
414 | + } | |
415 | + | |
416 | + /** | |
417 | + * 处理活动主题, 赋其他值 | |
418 | + * | |
419 | + * @param item 待处理的活动主题 | |
420 | + */ | |
421 | + private void peekActivityThemeVo(ActivityThemeVo item) { | |
422 | + item.setCanAlert(!this.themeHaveStopCatchData(item.getEndTime())); | |
423 | + item.setAllFileDesc(Optional.ofNullable( | |
424 | + themeFileService.lambdaQuery() | |
425 | + .eq(ThemeFile::getThemeId, item.getId()) | |
426 | + .eq(ThemeFile::getType, FileTypeEnum.THEME_COVER.getValue()) | |
427 | + .list()) | |
428 | + .orElse(new ArrayList<>()) | |
429 | + .stream() | |
430 | + .map(ThemeFile::toVO) | |
431 | + .collect(Collectors.toList()) | |
432 | + ); | |
433 | + } | |
434 | + | |
437 | 435 | } | ... | ... |