|
@@ -10,6 +10,8 @@ import com.google.common.collect.Maps;
|
|
import com.yonge.cooleshow.auth.api.client.SysUserFeignService;
|
|
import com.yonge.cooleshow.auth.api.client.SysUserFeignService;
|
|
import com.yonge.cooleshow.auth.api.entity.SysUser;
|
|
import com.yonge.cooleshow.auth.api.entity.SysUser;
|
|
import com.yonge.cooleshow.biz.dal.dao.ActivityPlanDao;
|
|
import com.yonge.cooleshow.biz.dal.dao.ActivityPlanDao;
|
|
|
|
+import com.yonge.cooleshow.biz.dal.dao.StudentDao;
|
|
|
|
+import com.yonge.cooleshow.biz.dal.dao.SubjectDao;
|
|
import com.yonge.cooleshow.biz.dal.dto.ActivityPlanDto;
|
|
import com.yonge.cooleshow.biz.dal.dto.ActivityPlanDto;
|
|
import com.yonge.cooleshow.biz.dal.dto.ActivityPlanPayDto;
|
|
import com.yonge.cooleshow.biz.dal.dto.ActivityPlanPayDto;
|
|
import com.yonge.cooleshow.biz.dal.dto.ActivityPlanRewardDto;
|
|
import com.yonge.cooleshow.biz.dal.dto.ActivityPlanRewardDto;
|
|
@@ -23,10 +25,13 @@ import com.yonge.cooleshow.biz.dal.entity.ActivityPlan;
|
|
import com.yonge.cooleshow.biz.dal.entity.ActivityPlanReward;
|
|
import com.yonge.cooleshow.biz.dal.entity.ActivityPlanReward;
|
|
import com.yonge.cooleshow.biz.dal.entity.ActivityRegistration;
|
|
import com.yonge.cooleshow.biz.dal.entity.ActivityRegistration;
|
|
import com.yonge.cooleshow.biz.dal.entity.ActivityReward;
|
|
import com.yonge.cooleshow.biz.dal.entity.ActivityReward;
|
|
|
|
+import com.yonge.cooleshow.biz.dal.entity.Student;
|
|
|
|
+import com.yonge.cooleshow.biz.dal.entity.Subject;
|
|
import com.yonge.cooleshow.biz.dal.enums.ClientEnum;
|
|
import com.yonge.cooleshow.biz.dal.enums.ClientEnum;
|
|
import com.yonge.cooleshow.biz.dal.enums.EQueryOp;
|
|
import com.yonge.cooleshow.biz.dal.enums.EQueryOp;
|
|
import com.yonge.cooleshow.biz.dal.enums.MK;
|
|
import com.yonge.cooleshow.biz.dal.enums.MK;
|
|
import com.yonge.cooleshow.biz.dal.enums.MessageTypeEnum;
|
|
import com.yonge.cooleshow.biz.dal.enums.MessageTypeEnum;
|
|
|
|
+import com.yonge.cooleshow.biz.dal.enums.activity.ActivityRankingMethodEnum;
|
|
import com.yonge.cooleshow.biz.dal.service.ActivityEvaluationRecordService;
|
|
import com.yonge.cooleshow.biz.dal.service.ActivityEvaluationRecordService;
|
|
import com.yonge.cooleshow.biz.dal.service.ActivityEvaluationService;
|
|
import com.yonge.cooleshow.biz.dal.service.ActivityEvaluationService;
|
|
import com.yonge.cooleshow.biz.dal.service.ActivityPlanEvaluationService;
|
|
import com.yonge.cooleshow.biz.dal.service.ActivityPlanEvaluationService;
|
|
@@ -35,9 +40,11 @@ import com.yonge.cooleshow.biz.dal.service.ActivityPlanService;
|
|
import com.yonge.cooleshow.biz.dal.service.ActivityPlanStandardService;
|
|
import com.yonge.cooleshow.biz.dal.service.ActivityPlanStandardService;
|
|
import com.yonge.cooleshow.biz.dal.service.ActivityRegistrationService;
|
|
import com.yonge.cooleshow.biz.dal.service.ActivityRegistrationService;
|
|
import com.yonge.cooleshow.biz.dal.service.ActivityRewardService;
|
|
import com.yonge.cooleshow.biz.dal.service.ActivityRewardService;
|
|
|
|
+import com.yonge.cooleshow.biz.dal.service.SubjectService;
|
|
import com.yonge.cooleshow.biz.dal.service.SysMessageService;
|
|
import com.yonge.cooleshow.biz.dal.service.SysMessageService;
|
|
import com.yonge.cooleshow.biz.dal.vo.ActivityMusicVo;
|
|
import com.yonge.cooleshow.biz.dal.vo.ActivityMusicVo;
|
|
import com.yonge.cooleshow.biz.dal.vo.ActivityPlanVo;
|
|
import com.yonge.cooleshow.biz.dal.vo.ActivityPlanVo;
|
|
|
|
+import com.yonge.cooleshow.biz.dal.vo.ActivityRankingVo;
|
|
import com.yonge.cooleshow.biz.dal.vo.MusicActivityVo;
|
|
import com.yonge.cooleshow.biz.dal.vo.MusicActivityVo;
|
|
import com.yonge.cooleshow.biz.dal.vo.UserOrderDetailVo;
|
|
import com.yonge.cooleshow.biz.dal.vo.UserOrderDetailVo;
|
|
import com.yonge.cooleshow.biz.dal.vo.activity.ActivityTeacherWrapper;
|
|
import com.yonge.cooleshow.biz.dal.vo.activity.ActivityTeacherWrapper;
|
|
@@ -117,6 +124,10 @@ public class ActivityPlanServiceImpl extends ServiceImpl<ActivityPlanDao, Activi
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private RedissonClient redissonClient;
|
|
private RedissonClient redissonClient;
|
|
|
|
+ @Autowired
|
|
|
|
+ private StudentDao studentMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private SubjectService subjectService;
|
|
|
|
|
|
//保存/更新拓展字段
|
|
//保存/更新拓展字段
|
|
private static final Map<ActivityTypeEnum, Consumer<ActivityPlanDto>> saveOrUpdateExpand = new HashMap<>();
|
|
private static final Map<ActivityTypeEnum, Consumer<ActivityPlanDto>> saveOrUpdateExpand = new HashMap<>();
|
|
@@ -488,6 +499,11 @@ public class ActivityPlanServiceImpl extends ServiceImpl<ActivityPlanDao, Activi
|
|
@Override
|
|
@Override
|
|
public MusicActivityVo getActivityInfo(Long activityPlanId, SysUser user) {
|
|
public MusicActivityVo getActivityInfo(Long activityPlanId, SysUser user) {
|
|
ActivityPlan activityPlan = this.getById(activityPlanId);
|
|
ActivityPlan activityPlan = this.getById(activityPlanId);
|
|
|
|
+
|
|
|
|
+ if (Objects.isNull(activityPlan)) {
|
|
|
|
+ throw new BizException("无效的活动ID");
|
|
|
|
+ }
|
|
|
|
+
|
|
if (activityPlan.getActivityState() != 1) {
|
|
if (activityPlan.getActivityState() != 1) {
|
|
activityPlan.setActivityState(0);
|
|
activityPlan.setActivityState(0);
|
|
}
|
|
}
|
|
@@ -501,9 +517,124 @@ public class ActivityPlanServiceImpl extends ServiceImpl<ActivityPlanDao, Activi
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- // 活动曲目
|
|
|
|
- List<ActivityMusicVo> activityMusicVoList = activityEvaluationService.getActivityMusic(activityPlanId, userId);
|
|
|
|
- activityVo.setActivityMusicVoList(activityMusicVoList);
|
|
|
|
|
|
+ // 评测活动曲目信息
|
|
|
|
+ if (ActivityTypeEnum.EVALUATION == activityPlan.getActivityType()) {
|
|
|
|
+
|
|
|
|
+ // 活动曲目
|
|
|
|
+ List<ActivityMusicVo> activityMusicVoList = activityEvaluationService.getActivityMusic(activityPlanId, userId);
|
|
|
|
+ activityVo.setActivityMusicVoList(activityMusicVoList);
|
|
|
|
+
|
|
|
|
+ // 评测难度
|
|
|
|
+ String evaluationDifficulty = baseMapper.selectActivityPlanEvaluation(activityPlanId);
|
|
|
|
+ activityVo.setEvaluationDifficulty(evaluationDifficulty);
|
|
|
|
+
|
|
|
|
+ // 单曲排名
|
|
|
|
+ if (ActivityRankingMethodEnum.MUSIC_RANKING == activityPlan.getRankingMethod()) {
|
|
|
|
+
|
|
|
|
+ for (ActivityMusicVo item : activityVo.getActivityMusicVoList()) {
|
|
|
|
+
|
|
|
|
+ item.setEvaluationDifficulty(evaluationDifficulty);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 计算评测活动声部最高分
|
|
|
|
+ if (ActivityRankingMethodEnum.TOTAL_SCORE == activityPlan.getRankingMethod()) {
|
|
|
|
+
|
|
|
|
+ Map<String, List<ActivityMusicVo>> collect = activityMusicVoList.stream()
|
|
|
|
+ .collect(Collectors.groupingBy(x -> x.getSubjectId().split(",")[0]));
|
|
|
|
+
|
|
|
|
+ // 曲目难度
|
|
|
|
+ Map<Integer, String> difficultyMap = Maps.newHashMap();
|
|
|
|
+ difficultyMap.put(0, "BEGINNER");
|
|
|
|
+ difficultyMap.put(1, "ADVANCED");
|
|
|
|
+ difficultyMap.put(2, "PERFORMER");
|
|
|
|
+ // FIXME:临时增加声部曲目难度字段
|
|
|
|
+ for (Map.Entry<String, List<ActivityMusicVo>> entry : collect.entrySet()) {
|
|
|
|
+
|
|
|
|
+ int index = 0;
|
|
|
|
+ for (ActivityMusicVo item : entry.getValue()) {
|
|
|
|
+
|
|
|
|
+ if (StringUtils.isEmpty(item.getEvaluationDifficulty())) {
|
|
|
|
+
|
|
|
|
+ item.setEvaluationDifficulty(difficultyMap.getOrDefault(index, "PERFORMER"));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ index += 1;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 计算声部评测最高分
|
|
|
|
+ Map<String, ActivityRankingVo> highestScoreMap = Maps.newConcurrentMap();
|
|
|
|
+ collect.entrySet().parallelStream().forEach(item -> {
|
|
|
|
+
|
|
|
|
+ // 单声部计算用户总分排名用户信息
|
|
|
|
+ List<ActivityRankingVo> records = getBaseMapper().selectActivityHighestScoreRankingInfo(activityPlanId, Long.parseLong(item.getKey()),
|
|
|
|
+ 1D, 1);
|
|
|
|
+
|
|
|
|
+ if (CollectionUtils.isNotEmpty(records)) {
|
|
|
|
+
|
|
|
|
+ highestScoreMap.put(item.getKey(), records.get(0));
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ // 用户学生身份声部信息
|
|
|
|
+ List<Long> userIds = highestScoreMap.values().stream()
|
|
|
|
+ .map(ActivityRankingVo::getUserId).distinct().collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+ Map<Long, Long> userSubjectMap = Maps.newHashMap();
|
|
|
|
+ Map<Long, String> subjectNameMap = Maps.newHashMap();
|
|
|
|
+ if (CollectionUtils.isNotEmpty(userIds)) {
|
|
|
|
+
|
|
|
|
+ userSubjectMap = studentMapper.selectList(Wrappers.<Student>lambdaQuery().in(Student::getUserId, userIds)).stream()
|
|
|
|
+ .filter(x -> Objects.nonNull(x.getSubjectId()))
|
|
|
|
+ .collect(Collectors.toMap(Student::getUserId, x -> Long.parseLong(Optional.ofNullable(x.getSubjectId()).orElse("0").split(",")[0]), (o, n) -> n));
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ subjectNameMap = subjectService.findBySubjectByIdList(Lists.newArrayList(userSubjectMap.values())).stream()
|
|
|
|
+ .collect(Collectors.toMap(Subject::getId, Subject::getName, (o, n) -> n));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ List<MusicActivityVo.SubjectInfo> subjectInfos = Lists.newArrayList();
|
|
|
|
+ ActivityMusicVo musicVo;
|
|
|
|
+ ActivityRankingVo ranking;
|
|
|
|
+ for (Map.Entry<String, List<ActivityMusicVo>> entry : collect.entrySet()) {
|
|
|
|
+
|
|
|
|
+ if (CollectionUtils.isEmpty(entry.getValue())) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ musicVo = entry.getValue().get(0);
|
|
|
|
+
|
|
|
|
+ MusicActivityVo.SubjectInfo subjectInfo = MusicActivityVo.SubjectInfo.builder()
|
|
|
|
+ .subjectId(musicVo.getSubjectId().split(",")[0])
|
|
|
|
+ .subjectName(musicVo.getMusicSubject())
|
|
|
|
+ .join(entry.getValue().stream().anyMatch(x -> x.getJoin() == YesOrNoEnum.YES) ? 1 : 0)
|
|
|
|
+ .userId(0L)
|
|
|
|
+ .username("")
|
|
|
|
+ .userAvatar("")
|
|
|
|
+ .userSubject("")
|
|
|
|
+ .score(0D)
|
|
|
|
+ .musicNums(entry.getValue().size())
|
|
|
|
+ .build();
|
|
|
|
+ subjectInfos.add(subjectInfo);
|
|
|
|
+
|
|
|
|
+ // 最高分记录
|
|
|
|
+ if (highestScoreMap.containsKey(entry.getKey())) {
|
|
|
|
+
|
|
|
|
+ ranking = highestScoreMap.get(entry.getKey());
|
|
|
|
+
|
|
|
|
+ subjectInfo.userId(ranking.getUserId())
|
|
|
|
+ .username(ranking.getUsername())
|
|
|
|
+ .userAvatar(ranking.getUserAvatar())
|
|
|
|
+ .userSubject(subjectNameMap.getOrDefault(userSubjectMap.get(ranking.getUserId()), ""))
|
|
|
|
+ .score(ranking.getScore());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ activityVo.setSubjectInfos(subjectInfos);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
// 报名状态
|
|
// 报名状态
|
|
activityVo.setJoin(activityRegistrationService.getRegistration(userId, activityPlanId));
|
|
activityVo.setJoin(activityRegistrationService.getRegistration(userId, activityPlanId));
|
|
@@ -512,10 +643,6 @@ public class ActivityPlanServiceImpl extends ServiceImpl<ActivityPlanDao, Activi
|
|
List<ActivityReward> activityRewardList = activityRewardService.getActivityReward(activityPlanId);
|
|
List<ActivityReward> activityRewardList = activityRewardService.getActivityReward(activityPlanId);
|
|
activityVo.setActivityRewardList(activityRewardList);
|
|
activityVo.setActivityRewardList(activityRewardList);
|
|
|
|
|
|
- // 评测难度
|
|
|
|
- String evaluationDifficulty = baseMapper.selectActivityPlanEvaluation(activityPlanId);
|
|
|
|
-
|
|
|
|
- activityVo.setEvaluationDifficulty(evaluationDifficulty);
|
|
|
|
return activityVo;
|
|
return activityVo;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -634,34 +761,53 @@ public class ActivityPlanServiceImpl extends ServiceImpl<ActivityPlanDao, Activi
|
|
// 方法调整为异常执行,预防HTTP接口调用返回超时响应
|
|
// 方法调整为异常执行,预防HTTP接口调用返回超时响应
|
|
ThreadPool.getExecutor().submit(() -> {
|
|
ThreadPool.getExecutor().submit(() -> {
|
|
|
|
|
|
- List<ActivityPlan> list = baseMapper.activityState();
|
|
|
|
- for (ActivityPlan plan : list) {
|
|
|
|
- DistributedLock.of(redissonClient)
|
|
|
|
- .runIfLockToFunction(CacheNameEnum.LOCK_ACTIVITY_STOCK.getRedisKey(plan.getId())
|
|
|
|
- , (id) -> {
|
|
|
|
- ActivityPlan activityPlan = getById(id);
|
|
|
|
- if (activityPlan.getActivityState() == 0) {
|
|
|
|
- activityPlan.setActivityState(1);
|
|
|
|
- baseMapper.updateById(activityPlan);
|
|
|
|
-
|
|
|
|
- //开始活动
|
|
|
|
- Consumer<Long> afterFunction = startActivity.get(activityPlan.getActivityType());
|
|
|
|
- if (!Objects.isNull(afterFunction)) {
|
|
|
|
- afterFunction.accept(activityPlan.getId());
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- activityPlan.setActivityState(0);
|
|
|
|
- activityPlan.setRewardFlag(1);
|
|
|
|
- baseMapper.updateById(activityPlan);
|
|
|
|
-
|
|
|
|
- //完成活动
|
|
|
|
- Consumer<Long> afterFunction = successActivity.get(activityPlan.getActivityType());
|
|
|
|
- if (!Objects.isNull(afterFunction)) {
|
|
|
|
- afterFunction.accept(activityPlan.getId());
|
|
|
|
|
|
+ RLock lock = redissonClient.getLock(CacheNameEnum.LOCK_EVALUATION_CRON.getCode());
|
|
|
|
+ try {
|
|
|
|
+ if (lock.isLocked()) {
|
|
|
|
+ log.warn("activityState {}, lockName={}", DateTime.now().toString(MK.TIME_PATTERN), lock.getName());
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 增加达标活动计算同步标识,前一个请求未执行完时忽略后续执行请求
|
|
|
|
+ lock.lock();
|
|
|
|
+
|
|
|
|
+ List<ActivityPlan> list = baseMapper.activityState();
|
|
|
|
+ for (ActivityPlan plan : list) {
|
|
|
|
+ DistributedLock.of(redissonClient)
|
|
|
|
+ .runIfLockToFunction(CacheNameEnum.LOCK_ACTIVITY_STOCK.getRedisKey(plan.getId())
|
|
|
|
+ , (id) -> {
|
|
|
|
+ ActivityPlan activityPlan = getById(id);
|
|
|
|
+ if (activityPlan.getActivityState() == 0) {
|
|
|
|
+ activityPlan.setActivityState(1);
|
|
|
|
+ baseMapper.updateById(activityPlan);
|
|
|
|
+
|
|
|
|
+ //开始活动
|
|
|
|
+ Consumer<Long> afterFunction = startActivity.get(activityPlan.getActivityType());
|
|
|
|
+ if (!Objects.isNull(afterFunction)) {
|
|
|
|
+ afterFunction.accept(activityPlan.getId());
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ activityPlan.setActivityState(0);
|
|
|
|
+ activityPlan.setRewardFlag(1);
|
|
|
|
+ baseMapper.updateById(activityPlan);
|
|
|
|
+
|
|
|
|
+ //完成活动
|
|
|
|
+ Consumer<Long> afterFunction = successActivity.get(activityPlan.getActivityType());
|
|
|
|
+ if (!Objects.isNull(afterFunction)) {
|
|
|
|
+ afterFunction.accept(activityPlan.getId());
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- }
|
|
|
|
- return true;
|
|
|
|
- }, plan.getId(), 10l);
|
|
|
|
|
|
+ return true;
|
|
|
|
+ }, plan.getId(), 10l);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.error("activityState time={}", DateTime.now().toString(MK.TIME_PATTERN), e);
|
|
|
|
+ } finally {
|
|
|
|
+ // 释放锁
|
|
|
|
+ if (lock.isLocked() && lock.isHeldByCurrentThread()) {
|
|
|
|
+ lock.unlock(); // 删除同步标识
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
});
|
|
});
|