|
@@ -1,43 +1,52 @@
|
|
|
package com.yonge.cooleshow.biz.dal.service.impl;
|
|
|
|
|
|
-import java.math.BigDecimal;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Optional;
|
|
|
-
|
|
|
-import com.google.common.collect.Lists;
|
|
|
-import com.yonge.cooleshow.biz.dal.entity.ActivityPlan;
|
|
|
-import com.yonge.cooleshow.biz.dal.enums.activity.ActivityRankingRuleEnum;
|
|
|
-import com.yonge.cooleshow.biz.dal.service.ActivityPlanService;
|
|
|
-import org.apache.commons.collections.CollectionUtils;
|
|
|
-import org.slf4j.Logger;
|
|
|
-import org.slf4j.LoggerFactory;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
import com.yonge.cooleshow.biz.dal.dao.ActivityEvaluationRecordDao;
|
|
|
import com.yonge.cooleshow.biz.dal.dto.search.ActivityEvaluationRecordSearch;
|
|
|
import com.yonge.cooleshow.biz.dal.entity.ActivityEvaluation;
|
|
|
import com.yonge.cooleshow.biz.dal.entity.ActivityEvaluationRecord;
|
|
|
+import com.yonge.cooleshow.biz.dal.entity.ActivityPlan;
|
|
|
+import com.yonge.cooleshow.biz.dal.entity.MusicSheet;
|
|
|
+import com.yonge.cooleshow.biz.dal.enums.activity.ActivityRankingMethodEnum;
|
|
|
import com.yonge.cooleshow.biz.dal.service.ActivityEvaluationRecordService;
|
|
|
import com.yonge.cooleshow.biz.dal.service.ActivityEvaluationService;
|
|
|
+import com.yonge.cooleshow.biz.dal.service.ActivityPlanService;
|
|
|
+import com.yonge.cooleshow.biz.dal.service.MusicSheetService;
|
|
|
import com.yonge.cooleshow.biz.dal.vo.ActivityEvaluationRecordVo;
|
|
|
import com.yonge.cooleshow.biz.dal.vo.ActivityRankingVo;
|
|
|
import com.yonge.cooleshow.common.enums.ActivityResourceEnum;
|
|
|
import com.yonge.toolset.base.exception.BizException;
|
|
|
+import com.yonge.toolset.base.util.ThreadPool;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
+import org.joda.time.DateTime;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.Comparator;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.Optional;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
public class ActivityEvaluationRecordServiceImpl extends ServiceImpl<ActivityEvaluationRecordDao, ActivityEvaluationRecord> implements ActivityEvaluationRecordService {
|
|
|
- private final static Logger log = LoggerFactory.getLogger(ActivityEvaluationRecordServiceImpl.class);
|
|
|
|
|
|
@Autowired
|
|
|
private ActivityEvaluationService activityEvaluationService;
|
|
|
-
|
|
|
+ @Autowired
|
|
|
+ private ActivityEvaluationRecordService activityEvaluationRecordService;
|
|
|
@Autowired
|
|
|
private ActivityPlanService activityPlanService;
|
|
|
+ @Autowired
|
|
|
+ private MusicSheetService musicSheetService;
|
|
|
|
|
|
@Override
|
|
|
public ActivityEvaluationRecordVo detail(Long id) {
|
|
@@ -63,10 +72,13 @@ public class ActivityEvaluationRecordServiceImpl extends ServiceImpl<ActivityEva
|
|
|
if (activityEvaluation == null) {
|
|
|
throw new BizException("未找到评测项目");
|
|
|
}
|
|
|
+
|
|
|
+ // 记录曲目评测试分数
|
|
|
ActivityEvaluationRecord activityEvaluationRecord = new ActivityEvaluationRecord();
|
|
|
activityEvaluationRecord.setActivityId(activityEvaluation.getActivityId());
|
|
|
activityEvaluationRecord.setUserId(userId);
|
|
|
activityEvaluationRecord.setEvaluationId(evaluationId);
|
|
|
+ activityEvaluationRecord.setResourceId(activityEvaluation.getMusicSheetId());
|
|
|
activityEvaluationRecord.setCreateTime(new Date());
|
|
|
activityEvaluationRecord.setScore(score == null ? 0:score.doubleValue());
|
|
|
|
|
@@ -77,6 +89,96 @@ public class ActivityEvaluationRecordServiceImpl extends ServiceImpl<ActivityEva
|
|
|
activityEvaluationRecord.setTimes(lastestRecord.getTimes() + 1);
|
|
|
}
|
|
|
save(activityEvaluationRecord);
|
|
|
+
|
|
|
+ // 活动信息
|
|
|
+ ActivityPlan activity = activityPlanService.getById(activityEvaluation.getActivityId());
|
|
|
+ if (ActivityRankingMethodEnum.TOTAL_SCORE == activity.getRankingMethod()) {
|
|
|
+
|
|
|
+ // 若为总分评测,计算声部分数
|
|
|
+ ThreadPool.getExecutor().submit(() -> {
|
|
|
+
|
|
|
+ List<ActivityEvaluationRecord> records = activityEvaluationRecordService.list(Wrappers.<ActivityEvaluationRecord>lambdaQuery()
|
|
|
+ .eq(ActivityEvaluationRecord::getActivityId, activityEvaluation.getActivityId())
|
|
|
+ .eq(ActivityEvaluationRecord::getUserId, userId));
|
|
|
+
|
|
|
+ // 用户当前声部所有评测数据,获取单曲最高进行加和计算为声部最高分
|
|
|
+ Map<Long, Double> highestScoreMap = records.stream()
|
|
|
+ .filter(x -> Optional.ofNullable(x.getScore()).orElse(0D) > 0)
|
|
|
+ .collect(Collectors.groupingBy(ActivityEvaluationRecord::getEvaluationId,
|
|
|
+ Collectors.mapping(ActivityEvaluationRecord::getScore, Collectors.toSet())))
|
|
|
+ .entrySet().stream()
|
|
|
+ .collect(Collectors.toMap(Map.Entry::getKey,
|
|
|
+ x -> x.getValue().stream().mapToDouble(Double::doubleValue).max().orElse(0D), (o, n) -> n));
|
|
|
+
|
|
|
+ // 最高分
|
|
|
+ double sumScore = highestScoreMap.values().stream().mapToDouble(Double::doubleValue).sum();
|
|
|
+
|
|
|
+ // 获取最高分的时间为每个单曲最高分的记录时间
|
|
|
+ Map<Long, Long> highestScoreTimeMap = records.stream()
|
|
|
+ .filter(x -> highestScoreMap.getOrDefault(x.getEvaluationId(), -1D).doubleValue() == x.getScore())
|
|
|
+ .collect(Collectors.groupingBy(ActivityEvaluationRecord::getEvaluationId, Collectors.mapping(x -> x.getCreateTime().getTime(), Collectors.toSet())))
|
|
|
+ .entrySet().stream()
|
|
|
+ .collect(Collectors.toMap(Map.Entry::getKey,
|
|
|
+ x -> x.getValue().stream().mapToLong(Long::longValue).max().orElse(0L), (o, n) -> n));
|
|
|
+
|
|
|
+ // 最高分时间
|
|
|
+ long highScoreTime = highestScoreTimeMap.values().stream().mapToLong(Long::longValue).max().orElse(DateTime.now().getMillis());
|
|
|
+
|
|
|
+ // 若分总相同,最高分时间相同,则根据用户活动报名时间进行排序
|
|
|
+ Date registrationTime = records.stream()
|
|
|
+ .filter(x -> Objects.isNull(x.getScore()))
|
|
|
+ .min(Comparator.comparing(ActivityEvaluationRecord::getId))
|
|
|
+ .map(ActivityEvaluationRecord::getCreateTime).orElse(DateTime.now().toDate());
|
|
|
+
|
|
|
+ // 查询用户声部评分记录
|
|
|
+ ActivityEvaluationRecord evaluationRecord = activityEvaluationRecordService.getOne(Wrappers.<ActivityEvaluationRecord>lambdaQuery()
|
|
|
+ .eq(ActivityEvaluationRecord::getActivityId, activity.getId())
|
|
|
+ .eq(ActivityEvaluationRecord::getUserId, userId)
|
|
|
+ .eq(ActivityEvaluationRecord::getRankingMethod, activity.getRankingMethod())
|
|
|
+ );
|
|
|
+
|
|
|
+ if (Objects.isNull(evaluationRecord)) {
|
|
|
+
|
|
|
+ MusicSheet musicSheet = musicSheetService.getById(activityEvaluation.getMusicSheetId());
|
|
|
+
|
|
|
+ long subjectId = 0;
|
|
|
+ if (Objects.nonNull(musicSheet)) {
|
|
|
+ subjectId = Long.parseLong(musicSheet.getMusicSubject().split(",")[0]);
|
|
|
+ }
|
|
|
+ // 添加用户声部总分记录
|
|
|
+ ActivityEvaluationRecord record = new ActivityEvaluationRecord();
|
|
|
+
|
|
|
+ record.setActivityId(activityEvaluation.getActivityId());
|
|
|
+ record.setUserId(userId);
|
|
|
+ record.setEvaluationId(0L);
|
|
|
+ // 声部ID
|
|
|
+ record.setResourceId(subjectId);
|
|
|
+ record.setRegistrationTime(registrationTime.getTime());
|
|
|
+ record.setRankingMethod(activity.getRankingMethod());
|
|
|
+ record.setTimes(0);
|
|
|
+ // 最高分时间
|
|
|
+ record.setCreateTime(new DateTime(highScoreTime).toDate());
|
|
|
+ record.setScore(sumScore);
|
|
|
+
|
|
|
+ save(record);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新最高分记录
|
|
|
+ if (Objects.nonNull(evaluationRecord)
|
|
|
+ && evaluationRecord.getScore() < sumScore) {
|
|
|
+
|
|
|
+ ActivityEvaluationRecord record = new ActivityEvaluationRecord();
|
|
|
+
|
|
|
+ record.setId(evaluationRecord.getId());
|
|
|
+ record.setScore(sumScore);
|
|
|
+ record.setCreateTime(new DateTime(highScoreTime).toDate());
|
|
|
+
|
|
|
+ updateById(record);
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|