|
@@ -17,19 +17,20 @@ import java.util.stream.Collectors;
|
|
|
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.yonge.cooleshow.biz.dal.enums.ClientEnum;
|
|
|
-import com.yonge.cooleshow.biz.dal.service.ActivityEvaluationRecordService;
|
|
|
+import com.yonge.cooleshow.biz.dal.service.MusicCompareRecordStatService;
|
|
|
import com.yonge.cooleshow.biz.dal.service.SysConfigService;
|
|
|
import com.yonge.cooleshow.biz.dal.wrapper.StatGroupWrapper;
|
|
|
import com.yonge.cooleshow.biz.dal.wrapper.music.MusicCompareWrapper;
|
|
|
import com.yonge.cooleshow.common.constant.SysConfigConstant;
|
|
|
import com.yonge.toolset.base.util.ThreadPool;
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.joda.time.DateTime;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
-import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
@@ -67,6 +68,8 @@ public class SysMusicCompareRecordServiceImpl extends BaseServiceImpl<Long, SysM
|
|
|
|
|
|
@Autowired
|
|
|
private MusicSheetDao musicSheetDao;
|
|
|
+ @Autowired
|
|
|
+ private MusicCompareRecordStatService musicCompareRecordStatService;
|
|
|
|
|
|
@Override
|
|
|
public BaseDAO<Long, SysMusicCompareRecord> getDAO() {
|
|
@@ -86,6 +89,22 @@ public class SysMusicCompareRecordServiceImpl extends BaseServiceImpl<Long, SysM
|
|
|
ClientEnum clientType = Optional.of(ClientEnum.valueOf(bean.getClientId().toUpperCase()))
|
|
|
.orElse(ClientEnum.STUDENT);
|
|
|
|
|
|
+ // 单曲统计
|
|
|
+ MusicCompareWrapper.RecordInfo musicStatRecord = MusicCompareWrapper.RecordInfo.builder()
|
|
|
+ .musicSheetId(bean.getMusicSheetId())
|
|
|
+ .clientId(clientType)
|
|
|
+ .userId(0L)
|
|
|
+ .recentTime(DateTime.now().getMillis())
|
|
|
+ .build();
|
|
|
+
|
|
|
+ // 用户单曲统计
|
|
|
+ MusicCompareWrapper.RecordInfo userStatRecord = MusicCompareWrapper.RecordInfo.builder()
|
|
|
+ .musicSheetId(bean.getMusicSheetId())
|
|
|
+ .clientId(clientType)
|
|
|
+ .userId(bean.getUserId())
|
|
|
+ .recentTime(DateTime.now().getMillis())
|
|
|
+ .build();
|
|
|
+
|
|
|
// 按练习、评测分别进行统计
|
|
|
Lists.newArrayList(FeatureType.values()).parallelStream().forEach(dataType -> {
|
|
|
|
|
@@ -95,21 +114,53 @@ public class SysMusicCompareRecordServiceImpl extends BaseServiceImpl<Long, SysM
|
|
|
.feature(dataType)
|
|
|
.build();
|
|
|
|
|
|
+ // 曲目统计
|
|
|
+ List<StatGroupWrapper> musicWrappers = sysMusicCompareRecordDao.selectMusicCompareRecordStatInfo(queryInfo);
|
|
|
+
|
|
|
+ // 用户曲目统计
|
|
|
+ queryInfo.setUserId(bean.getUserId());
|
|
|
+
|
|
|
+ List<StatGroupWrapper> userMusicWrappers = sysMusicCompareRecordDao.selectMusicCompareRecordStatInfo(queryInfo);
|
|
|
+
|
|
|
switch (dataType) {
|
|
|
case CLOUD_STUDY_TRAIN: // 练习
|
|
|
{
|
|
|
// 先统计练习曲目
|
|
|
- List<StatGroupWrapper> groupWrappers = sysMusicCompareRecordDao.selectMusicCompareRecordStatInfo(queryInfo);
|
|
|
+ if (CollectionUtils.isNotEmpty(musicWrappers)) {
|
|
|
+
|
|
|
+ StatGroupWrapper wrapper = musicWrappers.get(0);
|
|
|
+
|
|
|
+ musicStatRecord.trainDuration(wrapper.getNumber().longValue())
|
|
|
+ .trainFrequency(wrapper.getTotal().longValue());
|
|
|
+ }
|
|
|
|
|
|
// 在按用户统计
|
|
|
+ if (CollectionUtils.isNotEmpty(userMusicWrappers)) {
|
|
|
+ StatGroupWrapper wrapper = userMusicWrappers.get(0);
|
|
|
|
|
|
+ userStatRecord.trainDuration(wrapper.getNumber().longValue())
|
|
|
+ .trainFrequency(wrapper.getTotal().longValue());
|
|
|
+ }
|
|
|
}
|
|
|
break;
|
|
|
case CLOUD_STUDY_EVALUATION: // 评测
|
|
|
{
|
|
|
// 先统计评测曲目
|
|
|
+ if (CollectionUtils.isNotEmpty(musicWrappers)) {
|
|
|
+
|
|
|
+ StatGroupWrapper wrapper = musicWrappers.get(0);
|
|
|
+
|
|
|
+ musicStatRecord.evaluateDuration(wrapper.getNumber().longValue())
|
|
|
+ .evaluateFrequency(wrapper.getTotal().longValue());
|
|
|
+ }
|
|
|
|
|
|
// 在按用户统计
|
|
|
+ if (CollectionUtils.isNotEmpty(userMusicWrappers)) {
|
|
|
+ StatGroupWrapper wrapper = userMusicWrappers.get(0);
|
|
|
+
|
|
|
+ userStatRecord.evaluateDuration(wrapper.getNumber().longValue())
|
|
|
+ .evaluateFrequency(wrapper.getTotal().longValue());
|
|
|
+ }
|
|
|
}
|
|
|
break;
|
|
|
default:
|
|
@@ -117,6 +168,10 @@ public class SysMusicCompareRecordServiceImpl extends BaseServiceImpl<Long, SysM
|
|
|
}
|
|
|
});
|
|
|
|
|
|
+ List<MusicCompareWrapper.RecordInfo> recordInfos = Lists.newArrayList(musicStatRecord, userStatRecord);
|
|
|
+
|
|
|
+ musicCompareRecordStatService.batchUpdateMusicCompareRecordStat(recordInfos);
|
|
|
+
|
|
|
} catch (Exception e) {
|
|
|
log.error("MusicCompareRecordStat userId={}, musicId={}", bean.getUserId(), bean.getMusicSheetId(), e);
|
|
|
}
|