优化下列代码。 List<TaskCompletedDTO> taskCompleted = taskCompletedService.selectUserByNow(starTime, endTime); for (TaskCompletedDTO dto : taskCompleted) { String taskGroupCode = dto.getTaskGroupCode(); //获取当前任务是签到还是阅读文章 String taskCode = dto.getTaskCode(); List<TaskRuleDetail> primaryData = taskRuleDetailMapper.selectTaskGroupListCode(taskGroupCode, taskCode); Map<String, Object> ruleDetail = getRuleDetail(taskCode, primaryData); //如果是签到那么为重复领取 //当天可完成次数 Object dayCompleteTaskMax = ruleDetail.get(CommonBusinessEnum.RuleDetailDataFieldEnum.DAY_COMPLETE_TASK_MAX.getValue()); Object checkInAttribute = ruleDetail.get(CommonBusinessEnum.RuleDetailDataFieldEnum.CHECK_IN_ATTRIBUTE.getValue()); Object readingArticle = ruleDetail.get(CommonBusinessEnum.RuleDetailDataFieldEnum.READING_ARTICLE_DURATION.getValue()); //分享商品和文章阅读判断当天完成次数 if (readingArticle != null) { if (dayCompleteTaskMax != null) { Integer dayCompleteTaskMax1 = (Integer) dayCompleteTaskMax; if (dayCompleteTaskMax1.compareTo(dto.getFinishCount()) < 0) { log.info("文章阅读或分享商品达完成上限后再次完成"); log.info("是否重复发放奖励"); return; } return; } } //签到(默认一天一次) if (checkInAttribute != null) { log.info("签到重复完成"); return; } //监控奖励是否重复发放(发放奖励的次数大于任务完成的次数奖励为重复发放) }
时间: 2023-02-13 17:55:23 浏览: 85
优化后的代码如下:
```
List<TaskCompletedDTO> taskCompleted = taskCompletedService.selectUserByNow(starTime, endTime);
for (TaskCompletedDTO dto : taskCompleted) {
String taskGroupCode = dto.getTaskGroupCode();
String taskCode = dto.getTaskCode();
List<TaskRuleDetail> primaryData = taskRuleDetailMapper.selectTaskGroupListCode(taskGroupCode, taskCode);
Map<String, Object> ruleDetail = getRuleDetail(taskCode, primaryData);
// 当天可完成次数
Integer dayCompleteTaskMax = (Integer) ruleDetail.get(CommonBusinessEnum.RuleDetailDataFieldEnum.DAY_COMPLETE_TASK_MAX.getValue());
// 签到属性
Boolean checkInAttribute = (Boolean) ruleDetail.get(CommonBusinessEnum.RuleDetailDataFieldEnum.CHECK_IN_ATTRIBUTE.getValue());
// 文章阅读时长
Integer readingArticle = (Integer) ruleDetail.get(CommonBusinessEnum.RuleDetailDataFieldEnum.READING_ARTICLE_DURATION.getValue());
// 判断是否为签到任务
if (checkInAttribute != null && checkInAttribute) {
log.info("签到重复完成");
return;
}
// 判断是否为文章阅读或分享商品任务
if (readingArticle != null && dayCompleteTaskMax != null) {
if (dayCompleteTaskMax < dto.getFinishCount()) {
log.info("文章阅读或分享商品达完成上限后再次完成");
log.info("是否重复发放奖励");
return;
}
return;
}
// 监控奖励是否重复发放(发放奖励的次数大于任务完成的次数奖励为重复发放)
}
```
对于任务完成情况的判断,应该先判断任务的类型是否为签到或文章阅读/分享商品,再根据任务的类型来判断是否重复完成。
在代码中,将原本的 `Object` 类
阅读全文