Commit 25186e73 authored by liming's avatar liming

获取我的排行功能

parent de58e965
......@@ -2,9 +2,11 @@ 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.SportType;
import com.antai.sport.http.server.repository.sport.entity.SportUser;
import com.antai.sport.http.server.repository.sport.entity.SportUserMonthRank;
import com.antai.sport.http.server.repository.sport.entity.SportUserSummary;
import com.antai.sport.http.server.repository.sport.entity.SportUserTrainingLog;
import com.antai.sport.http.server.repository.sport.mapper.SportUserMapper;
import com.antai.sport.http.server.repository.sport.mapper.SportUserMonthRankMapper;
import com.antai.sport.http.server.repository.sport.mapper.SportUserSummaryMapper;
import com.antai.sport.http.server.repository.sport.mapper.SportUserTrainingLogMapper;
......@@ -12,7 +14,10 @@ import com.antai.sport.http.server.server.api.business.traininglog.converter.Spo
import com.antai.sport.http.server.server.api.business.traininglog.dto.SportUserTrainingLogSummaryVO;
import com.antai.sport.http.server.server.api.business.traininglog.dto.SportUserTrainingLogVO;
import com.antai.sport.http.server.server.api.business.traininglog.mapper.SportUserTrainingLogBusinessMapper;
import com.antai.sport.http.server.server.api.business.user.converter.SportUserConverter;
import com.antai.sport.http.server.server.api.business.user.dto.ReqSportUserTrainingLog;
import com.antai.sport.http.server.server.api.business.user.dto.SportUserMonthRankResponseDTO;
import com.antai.sport.http.server.server.api.business.user.mapper.SportUserMonthRankBusinessMapper;
import com.antai.sport.http.server.server.api.common.dto.CyclingDataDTO;
import com.antai.sport.http.server.server.api.utils.ScoreUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
......@@ -32,12 +37,18 @@ public class SportUserTrainingLogService {
private SportUserSummaryMapper sportUserSummaryMapper;
@Resource
private SportUserMonthRankMapper sportUserMonthRankMapper;
@Resource
private SportUserMapper sportUserMapper;
@Resource
private SportUserTrainingLogBusinessMapper sportUserTrainingLogBusinessMapper;
@Resource
private SportUserMonthRankBusinessMapper sportUserMonthRankBusinessMapper;
@Resource
private SportUserTrainingLogConverter sportUserTrainingLogConverter;
@Resource
private SportUserConverter sportUserConverter;
public void createBicycleTrainingLog(Long playerId, Integer gameMode, Long sourceId, String map, String path, Integer praiseNum, CyclingDataDTO sportData) {
SportUserTrainingLog log = sportUserTrainingLogConverter.toSportUserTrainingLog(sportData);
......@@ -85,6 +96,7 @@ public class SportUserTrainingLogService {
SportUserMonthRank rank = sportUserMonthRankMapper.selectOne(rankQuery);
if (rank == null) {
rank = sportUserTrainingLogConverter.toSportUserMonthRank(log, year, month);
rank.setUpdateTime(rank.getCreateTime());
sportUserMonthRankMapper.insert(rank);
} else {
modifyRank(log, rank);
......@@ -113,8 +125,7 @@ public class SportUserTrainingLogService {
if (log.getTwentyMinutesWkg().compareTo(rank.getTwentyMinutesWkg()) == 1) {
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);
}
......@@ -161,4 +172,40 @@ public class SportUserTrainingLogService {
public List<SportUserTrainingLogVO> getSportUserTrainingLog(ReqSportUserTrainingLog param) {
return sportUserTrainingLogBusinessMapper.getSportUserTrainingLog(param.getPlayerId(), param.getDate(), param.getGameMode());
}
/**
* 获取我的排名
*
* @param userId
* @param type
* @param year
* @param month
* @return
*/
public SportUserMonthRankResponseDTO getMyRank(Long userId, Integer type, Integer year, Integer month) {
SportUserMonthRankResponseDTO result;
QueryWrapper<SportUserMonthRank> rankQuery = new QueryWrapper<>();
rankQuery.eq("player_id", userId);
rankQuery.eq("year", year);
rankQuery.eq("month", month);
SportUserMonthRank rank = sportUserMonthRankMapper.selectOne(rankQuery);
if (rank == null) {
result = new SportUserMonthRankResponseDTO();
result.setRank(0);
result.setTotalCalorie(0);
result.setOneMinutesFtp(BigDecimal.ZERO);
result.setFiveMinutesFtp(BigDecimal.ZERO);
result.setTwentyMinutesFtp(BigDecimal.ZERO);
} else {
result = sportUserConverter.toSportUserMonthRankResponseDTO(rank);
result.setRank(sportUserMonthRankBusinessMapper.getMyRank(type, rank.getScore(),rank.getTotalCalorie(),rank.getUpdateTime(), year, month));
}
SportUser user = sportUserMapper.selectById(userId);
result.setPlayerId(userId);
result.setAvatar(user.getAvatar());
result.setNickname(user.getNickname());
result.setWeight(user.getWeight());
return result;
}
}
......@@ -5,6 +5,7 @@ import com.antai.sport.http.server.server.api.business.traininglog.dto.SportUser
import com.antai.sport.http.server.server.api.business.traininglog.service.SportUserTrainingLogService;
import com.antai.sport.http.server.server.api.business.user.dto.ReqSportUserTrainingLog;
import com.antai.sport.http.server.server.api.business.user.dto.RespUserHomeInfo;
import com.antai.sport.http.server.server.api.business.user.dto.SportUserMonthRankResponseDTO;
import com.antai.sport.http.server.server.api.business.user.service.SportUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
......@@ -36,4 +37,10 @@ public class SportUserController {
public ResponseEntity<Result<List<SportUserTrainingLogVO>>> getSportUserTrainingLog(@RequestBody ReqSportUserTrainingLog param) {
return success(sportUserTrainingLogService.getSportUserTrainingLog(param));
}
@ApiOperation("查询我的排名 type: 1能力榜 2活跃度榜")
@GetMapping("/{userId}/{type}/rank")
public ResponseEntity<Result<SportUserMonthRankResponseDTO>> getMyRank(@PathVariable("userId") Long userId, @RequestParam Integer type, @RequestParam Integer year, @RequestParam Integer month) {
return success(sportUserTrainingLogService.getMyRank(userId, type, year, month));
}
}
package com.antai.sport.http.server.server.api.business.user.converter;
import com.antai.sport.http.server.repository.sport.entity.SportUserMonthRank;
import com.antai.sport.http.server.server.api.business.user.dto.SportUserMonthRankResponseDTO;
import org.mapstruct.Mapper;
@Mapper(componentModel = "spring")
public interface SportUserConverter {
SportUserMonthRankResponseDTO toSportUserMonthRankResponseDTO(SportUserMonthRank source);
}
package com.antai.sport.http.server.server.api.business.user.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
@ApiModel("排行榜查询对象")
public class SportUserMonthRankRequestDTO {
@ApiModelProperty("页号")
private Integer pageNo;
@ApiModelProperty("分页大小")
private Integer pageSize;
@ApiModelProperty("年份")
private Integer year;
@ApiModelProperty("月份")
private Integer month;
}
package com.antai.sport.http.server.server.api.business.user.dto;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDateTime;
@Data
public class SportUserMonthRankResponseDTO {
@ApiModelProperty("玩家id")
private Long playerId;
@ApiModelProperty("排名")
private Integer rank;
@ApiModelProperty("昵称")
private String nickname;
@ApiModelProperty("头像")
private String avatar;
@ApiModelProperty("体重")
private BigDecimal weight;
@ApiModelProperty("总计卡路里")
private Integer totalCalorie;
@ApiModelProperty("一分钟FTP")
private BigDecimal oneMinutesFtp;
@ApiModelProperty("五分钟FTP")
private BigDecimal fiveMinutesFtp;
@ApiModelProperty("二十分钟FTP")
private BigDecimal twentyMinutesFtp;
@ApiModelProperty("更新时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private LocalDateTime updateTime;
}
package com.antai.sport.http.server.server.api.business.user.mapper;
import org.apache.ibatis.annotations.Param;
import java.math.BigDecimal;
import java.time.LocalDateTime;
public interface SportUserMonthRankBusinessMapper {
Integer getMyRank(@Param("type") Integer type, @Param("score") BigDecimal score, @Param("totalCalorie") Integer totalCalorie,
@Param("updateTime") LocalDateTime updateTime,
@Param("year") Integer year, @Param("month") Integer month);
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.antai.sport.http.server.server.api.business.user.mapper.SportUserMonthRankBusinessMapper">
<select id="getMyRank" resultType="java.lang.Integer">
select count(1) + 1
from sport_user_month_rank
where year = #{year}
and month = #{month}
<if test="type = 1">
and (score &gt; #{score} or (score = #{score} and update_time &lt; #{updateTime} ))
</if>
<if test="type = 2">
and (total_calorie &gt; #{totalCalorie} or (total_calorie = #{totalCalorie} and update_time &lt; #{updateTime} ))
</if>
</select>
</mapper>
\ No newline at end of file
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