Commit c990fede authored by liming's avatar liming

用户运动积分结算

parent 988d6884
package com.antai.sport.http.server.constants;
public class GameCurrencyLogType {
public static final Integer ADD = 1;
public static final Integer SUBTRACT = 2;
}
...@@ -2,6 +2,8 @@ package com.antai.sport.http.server.repository.shop.entity; ...@@ -2,6 +2,8 @@ package com.antai.sport.http.server.repository.shop.entity;
import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import java.math.BigDecimal;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.io.Serializable; import java.io.Serializable;
import lombok.Data; import lombok.Data;
...@@ -35,7 +37,7 @@ public class SportUserGameCurrencyMatchRule implements Serializable { ...@@ -35,7 +37,7 @@ public class SportUserGameCurrencyMatchRule implements Serializable {
/** /**
* 倍率 * 倍率
*/ */
private Integer rate; private BigDecimal rate;
/** /**
* 排名启示值 * 排名启示值
......
package com.antai.sport.http.server.server.api.business.traininglog.service; package com.antai.sport.http.server.server.api.business.traininglog.service;
import com.antai.sport.http.server.constants.DeleteStatus; import com.antai.sport.http.server.constants.*;
import com.antai.sport.http.server.constants.GameMode;
import com.antai.sport.http.server.constants.RankType;
import com.antai.sport.http.server.constants.SportType;
import com.antai.sport.http.server.repository.club.entity.Club; import com.antai.sport.http.server.repository.club.entity.Club;
import com.antai.sport.http.server.repository.club.entity.ClubMember; import com.antai.sport.http.server.repository.club.entity.ClubMember;
import com.antai.sport.http.server.repository.club.mapper.ClubMapper; import com.antai.sport.http.server.repository.club.mapper.ClubMapper;
import com.antai.sport.http.server.repository.club.mapper.ClubMemberMapper; import com.antai.sport.http.server.repository.club.mapper.ClubMemberMapper;
import com.antai.sport.http.server.repository.roommode.entity.RoomMode; import com.antai.sport.http.server.repository.roommode.entity.RoomMode;
import com.antai.sport.http.server.repository.roommode.mapper.RoomModeMapper; import com.antai.sport.http.server.repository.roommode.mapper.RoomModeMapper;
import com.antai.sport.http.server.repository.shop.entity.SportUserGameCurrency;
import com.antai.sport.http.server.repository.shop.entity.SportUserGameCurrencyBaseRule;
import com.antai.sport.http.server.repository.shop.entity.SportUserGameCurrencyLog;
import com.antai.sport.http.server.repository.shop.entity.SportUserGameCurrencyMatchRule;
import com.antai.sport.http.server.repository.shop.mapper.SportUserGameCurrencyBaseRuleMapper;
import com.antai.sport.http.server.repository.shop.mapper.SportUserGameCurrencyLogMapper;
import com.antai.sport.http.server.repository.shop.mapper.SportUserGameCurrencyMapper;
import com.antai.sport.http.server.repository.shop.mapper.SportUserGameCurrencyMatchRuleMapper;
import com.antai.sport.http.server.repository.simplematch.entity.SimpleMatch; import com.antai.sport.http.server.repository.simplematch.entity.SimpleMatch;
import com.antai.sport.http.server.repository.simplematch.mapper.SimpleMatchMapper; import com.antai.sport.http.server.repository.simplematch.mapper.SimpleMatchMapper;
import com.antai.sport.http.server.repository.sport.entity.*; import com.antai.sport.http.server.repository.sport.entity.*;
...@@ -82,7 +87,8 @@ public class SportUserTrainingLogService { ...@@ -82,7 +87,8 @@ public class SportUserTrainingLogService {
@Resource @Resource
private SportUserConverter sportUserConverter; private SportUserConverter sportUserConverter;
public void createBicycleTrainingLog(Long playerId, Integer gameMode, Long sourceId, String sourceName, String map, String path, Integer praiseNum, CyclingDataDTO sportData) { public void createBicycleTrainingLog(Long playerId, Integer gameMode, Long sourceId, String sourceName,
String map, String path, Integer praiseNum, CyclingDataDTO sportData) {
SportUserTrainingLog log = sportUserTrainingLogConverter.toSportUserTrainingLog(sportData); SportUserTrainingLog log = sportUserTrainingLogConverter.toSportUserTrainingLog(sportData);
log.setSportType(SportType.BICYCLE); log.setSportType(SportType.BICYCLE);
log.setGameMode(gameMode); log.setGameMode(gameMode);
...@@ -96,7 +102,8 @@ public class SportUserTrainingLogService { ...@@ -96,7 +102,8 @@ public class SportUserTrainingLogService {
log.setCreateDate(LocalDate.now()); log.setCreateDate(LocalDate.now());
//处理是否俱乐部日志 //处理是否俱乐部日志
QueryWrapper<ClubMember> clubMemberQuery = new QueryWrapper<>(); QueryWrapper<ClubMember> clubMemberQuery = new QueryWrapper<>();
clubMemberQuery.lambda().eq(ClubMember::getSportUserId, playerId).eq(ClubMember::getDeleted, DeleteStatus.UNDELETED); clubMemberQuery.lambda().eq(ClubMember::getSportUserId, playerId).eq(ClubMember::getDeleted,
DeleteStatus.UNDELETED);
ClubMember clubMember = clubMemberMapper.selectOne(clubMemberQuery); ClubMember clubMember = clubMemberMapper.selectOne(clubMemberQuery);
if (clubMember != null) { if (clubMember != null) {
log.setClubId(clubMember.getClubId()); log.setClubId(clubMember.getClubId());
...@@ -110,6 +117,63 @@ public class SportUserTrainingLogService { ...@@ -110,6 +117,63 @@ public class SportUserTrainingLogService {
this.modifyMonthRank(playerId, log); this.modifyMonthRank(playerId, log);
//处理总排行 //处理总排行
this.modifyTotalRank(playerId, log); this.modifyTotalRank(playerId, log);
//处理玩家积分
this.handleSportUserCurrency(playerId, log.getId(), log.getCalorie(), gameMode, log.getMatchRank());
}
@Resource
private SportUserGameCurrencyBaseRuleMapper sportUserGameCurrencyBaseRuleMapper;
@Resource
private SportUserGameCurrencyMapper sportUserGameCurrencyMapper;
@Resource
private SportUserGameCurrencyLogMapper sportUserGameCurrencyLogMapper;
@Resource
private SportUserGameCurrencyMatchRuleMapper sportUserGameCurrencyMatchRuleMapper;
/**
* 处理用户积分
*
* @param playerId
* @param gameMode
* @param rank
*/
public void handleSportUserCurrency(Long playerId, Long logId, Integer calorie, Integer gameMode, Integer rank) {
if (calorie == null || calorie == 0) {
return;
}
List<SportUserGameCurrencyBaseRule> baseRule = sportUserGameCurrencyBaseRuleMapper.selectList(null);
if (baseRule.size() == 0 || baseRule.get(0).getCoefficient() == null) {
return;
}
Integer coefficient = baseRule.get(0).getCoefficient();
Integer currency = calorie / coefficient;
SportUserGameCurrencyMatchRule matchRule =
sportUserGameCurrencyMatchRuleMapper.selectOne(new QueryWrapper<SportUserGameCurrencyMatchRule>().lambda().eq(SportUserGameCurrencyMatchRule::getGameMode, gameMode).le(SportUserGameCurrencyMatchRule::getRankStart, rank).ge(SportUserGameCurrencyMatchRule::getRankEnd, rank));
if (matchRule != null && matchRule.getRate() != null) {
currency = matchRule.getRate().multiply(BigDecimal.valueOf(currency)).intValue();
}
SportUserGameCurrency userGameCurrency =
sportUserGameCurrencyMapper.selectOne(new QueryWrapper<SportUserGameCurrency>().lambda().eq(SportUserGameCurrency::getSportUserId, playerId));
if (userGameCurrency == null) {
userGameCurrency = new SportUserGameCurrency();
userGameCurrency.setSportUserId(playerId);
userGameCurrency.setAmmount(currency);
userGameCurrency.setCtDate(LocalDateTime.now());
sportUserGameCurrencyMapper.insert(userGameCurrency);
} else {
userGameCurrency.setAmmount(userGameCurrency.getAmmount() + currency);
sportUserGameCurrencyMapper.updateById(userGameCurrency);
}
SportUserGameCurrencyLog gameCurrencyLog = new SportUserGameCurrencyLog();
gameCurrencyLog.setSportUserId(playerId);
gameCurrencyLog.setAmmount(currency);
gameCurrencyLog.setSourceId(logId);
gameCurrencyLog.setCtDate(LocalDateTime.now());
gameCurrencyLog.setType(GameCurrencyLogType.ADD);
sportUserGameCurrencyLogMapper.insert(gameCurrencyLog);
} }
/** /**
...@@ -200,7 +264,9 @@ public class SportUserTrainingLogService { ...@@ -200,7 +264,9 @@ public class SportUserTrainingLogService {
if (log.getTwentyMinutesWkg().compareTo(rank.getTwentyMinutesWkg()) == 1) { if (log.getTwentyMinutesWkg().compareTo(rank.getTwentyMinutesWkg()) == 1) {
rank.setTwentyMinutesWkg(log.getTwentyMinutesWkg()); rank.setTwentyMinutesWkg(log.getTwentyMinutesWkg());
} }
rank.setScore(ScoreUtils.calculate(rank.getOneMinutesFtp(), rank.getFiveMinutesFtp(), rank.getTwentyMinutesFtp(), rank.getOneMinutesWkg(), rank.getFiveMinutesWkg(), rank.getTwentyMinutesWkg())); rank.setScore(ScoreUtils.calculate(rank.getOneMinutesFtp(), rank.getFiveMinutesFtp(),
rank.getTwentyMinutesFtp(), rank.getOneMinutesWkg(), rank.getFiveMinutesWkg(),
rank.getTwentyMinutesWkg()));
sportUserMonthRankMapper.updateById(rank); sportUserMonthRankMapper.updateById(rank);
} }
...@@ -239,7 +305,9 @@ public class SportUserTrainingLogService { ...@@ -239,7 +305,9 @@ public class SportUserTrainingLogService {
if (log.getTwentyMinutesWkg().compareTo(rank.getTwentyMinutesWkg()) == 1) { if (log.getTwentyMinutesWkg().compareTo(rank.getTwentyMinutesWkg()) == 1) {
rank.setTwentyMinutesWkg(log.getTwentyMinutesWkg()); rank.setTwentyMinutesWkg(log.getTwentyMinutesWkg());
} }
rank.setScore(ScoreUtils.calculate(rank.getOneMinutesFtp(), rank.getFiveMinutesFtp(), rank.getTwentyMinutesFtp(), rank.getOneMinutesWkg(), rank.getFiveMinutesWkg(), rank.getTwentyMinutesWkg())); rank.setScore(ScoreUtils.calculate(rank.getOneMinutesFtp(), rank.getFiveMinutesFtp(),
rank.getTwentyMinutesFtp(), rank.getOneMinutesWkg(), rank.getFiveMinutesWkg(),
rank.getTwentyMinutesWkg()));
sportUserRankMapper.updateById(rank); sportUserRankMapper.updateById(rank);
} }
...@@ -265,7 +333,8 @@ public class SportUserTrainingLogService { ...@@ -265,7 +333,8 @@ public class SportUserTrainingLogService {
public SportUserTrainingLogSummaryVO getTrainingLogSummary(Integer sportType, Long userId, Integer daysCondition) { public SportUserTrainingLogSummaryVO getTrainingLogSummary(Integer sportType, Long userId, Integer daysCondition) {
LocalDate now = LocalDate.now(); LocalDate now = LocalDate.now();
LocalDate beginDate = now.minusDays(daysCondition - 1); LocalDate beginDate = now.minusDays(daysCondition - 1);
SportUserTrainingLogSummaryVO summaryVO = sportUserTrainingLogBusinessMapper.getTrainingLogSummary(sportType, userId, beginDate, now); SportUserTrainingLogSummaryVO summaryVO = sportUserTrainingLogBusinessMapper.getTrainingLogSummary(sportType,
userId, beginDate, now);
if (summaryVO == null) { if (summaryVO == null) {
summaryVO = new SportUserTrainingLogSummaryVO(); summaryVO = new SportUserTrainingLogSummaryVO();
summaryVO.setLongestDistance(BigDecimal.ZERO); summaryVO.setLongestDistance(BigDecimal.ZERO);
...@@ -283,7 +352,8 @@ public class SportUserTrainingLogService { ...@@ -283,7 +352,8 @@ public class SportUserTrainingLogService {
* @return * @return
*/ */
public List<SportUserTrainingLogVO> getSportUserTrainingLog(ReqSportUserTrainingLog param) { public List<SportUserTrainingLogVO> getSportUserTrainingLog(ReqSportUserTrainingLog param) {
return sportUserTrainingLogBusinessMapper.getSportUserTrainingLog(param.getPlayerId(), param.getDate(), param.getGameMode()); return sportUserTrainingLogBusinessMapper.getSportUserTrainingLog(param.getPlayerId(), param.getDate(),
param.getGameMode());
} }
/** /**
...@@ -312,7 +382,8 @@ public class SportUserTrainingLogService { ...@@ -312,7 +382,8 @@ public class SportUserTrainingLogService {
result.setScore(BigDecimal.ZERO); result.setScore(BigDecimal.ZERO);
} else { } else {
result = sportUserConverter.toSportUserMonthRankResponseDTO(rank); result = sportUserConverter.toSportUserMonthRankResponseDTO(rank);
result.setRank(sportUserMonthRankBusinessMapper.getMyRank(type, rank.getScore(), rank.getTotalCalorie(), rank.getUpdateTime(), year, month)); result.setRank(sportUserMonthRankBusinessMapper.getMyRank(type, rank.getScore(), rank.getTotalCalorie(),
rank.getUpdateTime(), year, month));
} }
SportUser user = sportUserMapper.selectById(userId); SportUser user = sportUserMapper.selectById(userId);
...@@ -355,14 +426,16 @@ public class SportUserTrainingLogService { ...@@ -355,14 +426,16 @@ public class SportUserTrainingLogService {
LocalDate beginDate = LocalDate.of(year, month, 1); LocalDate beginDate = LocalDate.of(year, month, 1);
LocalDate endDate = beginDate.plusMonths(1); LocalDate endDate = beginDate.plusMonths(1);
LocalDate today = LocalDate.now(); LocalDate today = LocalDate.now();
List<ScheduleResponseDTO> trainList = sportUserTrainingLogBusinessMapper.getMonthTrainingSummary(userId, beginDate, endDate, today); List<ScheduleResponseDTO> trainList = sportUserTrainingLogBusinessMapper.getMonthTrainingSummary(userId,
beginDate, endDate, today);
trainList.forEach(item -> { trainList.forEach(item -> {
item.setActive(true); item.setActive(true);
item.setScheduleList(new ArrayList<>()); item.setScheduleList(new ArrayList<>());
resultMap.put(item.getDay(), item); resultMap.put(item.getDay(), item);
}); });
List<SimpleMatchUserScheduleVO> userScheduleList = simpleMatchBusinessMapper.getUserRegistSchedule(userId, beginDate, endDate, today); List<SimpleMatchUserScheduleVO> userScheduleList = simpleMatchBusinessMapper.getUserRegistSchedule(userId,
beginDate, endDate, today);
userScheduleList.forEach(item -> { userScheduleList.forEach(item -> {
if (!resultMap.containsKey(item.getDay())) { if (!resultMap.containsKey(item.getDay())) {
ScheduleResponseDTO scheduleResponseDTO = new ScheduleResponseDTO(); ScheduleResponseDTO scheduleResponseDTO = new ScheduleResponseDTO();
...@@ -378,7 +451,8 @@ public class SportUserTrainingLogService { ...@@ -378,7 +451,8 @@ public class SportUserTrainingLogService {
resultMap.get(item.getDay()).getScheduleList().add(schedule); resultMap.get(item.getDay()).getScheduleList().add(schedule);
}); });
List<TeamTrainingUserScheduleVO> teamTrainingUserScheduleList = teamTrainingBusinessMapper.getUserRegistSchedule(userId, beginDate, endDate, today); List<TeamTrainingUserScheduleVO> teamTrainingUserScheduleList =
teamTrainingBusinessMapper.getUserRegistSchedule(userId, beginDate, endDate, today);
teamTrainingUserScheduleList.forEach(item -> { teamTrainingUserScheduleList.forEach(item -> {
if (!resultMap.containsKey(item.getDay())) { if (!resultMap.containsKey(item.getDay())) {
ScheduleResponseDTO scheduleResponseDTO = new ScheduleResponseDTO(); ScheduleResponseDTO scheduleResponseDTO = new ScheduleResponseDTO();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment