Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
A
antai-sport-http-server
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
antai-sport
antai-sport-http-server
Commits
8f6861d4
Commit
8f6861d4
authored
May 12, 2022
by
liming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加卡路里和积分排行功能
parent
0dec45fb
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
304 additions
and
8 deletions
+304
-8
RoomModePlayerRecord.java
...rver/repository/roommode/entity/RoomModePlayerRecord.java
+10
-0
SimpleMatchPlayerRecord.java
...epository/simplematch/entity/SimpleMatchPlayerRecord.java
+10
-0
SportUserMonthRank.java
...tp/server/repository/sport/entity/SportUserMonthRank.java
+97
-0
SportUserTrainingLog.java
.../server/repository/sport/entity/SportUserTrainingLog.java
+14
-5
SportUserMonthRankMapper.java
...ver/repository/sport/mapper/SportUserMonthRankMapper.java
+16
-0
TourRecord.java
.../sport/http/server/repository/tour/entity/TourRecord.java
+10
-0
SportUserMonthRankMapper.xml
.../main/resources/mapper/sport/SportUserMonthRankMapper.xml
+5
-0
TourService.java
.../server/server/api/business/tour/service/TourService.java
+8
-0
SportUserTrainingLogConverter.java
.../traininglog/converter/SportUserTrainingLogConverter.java
+9
-0
SportUserTrainingLogService.java
...ness/traininglog/service/SportUserTrainingLogService.java
+48
-3
CyclingDataDTO.java
...ort/http/server/server/api/common/dto/CyclingDataDTO.java
+52
-0
ScoreUtils.java
.../antai/sport/http/server/server/api/utils/ScoreUtils.java
+25
-0
No files found.
repository/src/main/java/com/antai/sport/http/server/repository/roommode/entity/RoomModePlayerRecord.java
View file @
8f6861d4
...
...
@@ -68,6 +68,16 @@ public class RoomModePlayerRecord implements Serializable {
*/
private
BigDecimal
avgSpeed
;
private
Integer
calorie
;
private
BigDecimal
weight
;
private
BigDecimal
oneMinutesFtp
;
private
BigDecimal
fiveMinutesFtp
;
private
BigDecimal
twentyMinutesFtp
;
private
BigDecimal
oneMinutesWkg
;
private
BigDecimal
fiveMinutesWkg
;
private
BigDecimal
twentyMinutesWkg
;
private
BigDecimal
score
;
/**
* 比赛状态10:完成比赛 20:未完成比赛
*/
...
...
repository/src/main/java/com/antai/sport/http/server/repository/simplematch/entity/SimpleMatchPlayerRecord.java
View file @
8f6861d4
...
...
@@ -78,6 +78,16 @@ public class SimpleMatchPlayerRecord implements Serializable {
*/
private
BigDecimal
avgSpeed
;
private
Integer
calorie
;
private
BigDecimal
weight
;
private
BigDecimal
oneMinutesFtp
;
private
BigDecimal
fiveMinutesFtp
;
private
BigDecimal
twentyMinutesFtp
;
private
BigDecimal
oneMinutesWkg
;
private
BigDecimal
fiveMinutesWkg
;
private
BigDecimal
twentyMinutesWkg
;
private
BigDecimal
score
;
/**
* 获攒数量
*/
...
...
repository/src/main/java/com/antai/sport/http/server/repository/sport/entity/SportUserMonthRank.java
0 → 100644
View file @
8f6861d4
package
com
.
antai
.
sport
.
http
.
server
.
repository
.
sport
.
entity
;
import
java.math.BigDecimal
;
import
com.baomidou.mybatisplus.annotation.IdType
;
import
com.baomidou.mybatisplus.annotation.TableId
;
import
java.time.LocalDateTime
;
import
java.io.Serializable
;
import
lombok.Data
;
import
lombok.EqualsAndHashCode
;
/**
* <p>
*
* </p>
*
* @author liming
* @since 2022-05-12
*/
@Data
@EqualsAndHashCode
(
callSuper
=
false
)
public
class
SportUserMonthRank
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
/**
* 主键
*/
@TableId
(
value
=
"id"
,
type
=
IdType
.
AUTO
)
private
Long
id
;
/**
* 年
*/
private
Integer
year
;
/**
* 月
*/
private
Integer
month
;
/**
* 玩家id
*/
private
Long
playerId
;
/**
* 累计卡路里量
*/
private
Integer
totalCalorie
;
/**
* 1分钟平均最佳FTP
*/
private
BigDecimal
oneMinutesFtp
;
/**
* 5分钟平均最佳FTP
*/
private
BigDecimal
fiveMinutesFtp
;
/**
* 20分钟平均最佳FTP
*/
private
BigDecimal
twentyMinutesFtp
;
/**
* 1分钟平均最佳功体比
*/
private
BigDecimal
oneMinutesWkg
;
/**
* 5分钟平均最佳功体比
*/
private
BigDecimal
fiveMinutesWkg
;
/**
* 20分钟平均最佳功体比
*/
private
BigDecimal
twentyMinutesWkg
;
/**
* 得分
*/
private
BigDecimal
score
;
/**
* 创建时间
*/
private
LocalDateTime
createTime
;
/**
* 更新时间
*/
private
LocalDateTime
updateTime
;
}
repository/src/main/java/com/antai/sport/http/server/repository/sport/entity/SportUserTrainingLog.java
View file @
8f6861d4
...
...
@@ -65,11 +65,6 @@ public class SportUserTrainingLog implements Serializable {
*/
private
String
path
;
/**
* 卡路里
*/
private
Integer
calorie
;
/**
* 比赛用时(秒)
*/
...
...
@@ -100,6 +95,20 @@ public class SportUserTrainingLog implements Serializable {
*/
private
BigDecimal
avgSpeed
;
/**
* 卡路里
*/
private
Integer
calorie
;
private
BigDecimal
weight
;
private
BigDecimal
oneMinutesFtp
;
private
BigDecimal
fiveMinutesFtp
;
private
BigDecimal
twentyMinutesFtp
;
private
BigDecimal
oneMinutesWkg
;
private
BigDecimal
fiveMinutesWkg
;
private
BigDecimal
twentyMinutesWkg
;
private
BigDecimal
score
;
/**
* 获攒数量
*/
...
...
repository/src/main/java/com/antai/sport/http/server/repository/sport/mapper/SportUserMonthRankMapper.java
0 → 100644
View file @
8f6861d4
package
com
.
antai
.
sport
.
http
.
server
.
repository
.
sport
.
mapper
;
import
com.antai.sport.http.server.repository.sport.entity.SportUserMonthRank
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
/**
* <p>
* Mapper 接口
* </p>
*
* @author liming
* @since 2022-05-12
*/
public
interface
SportUserMonthRankMapper
extends
BaseMapper
<
SportUserMonthRank
>
{
}
repository/src/main/java/com/antai/sport/http/server/repository/tour/entity/TourRecord.java
View file @
8f6861d4
...
...
@@ -68,6 +68,16 @@ public class TourRecord implements Serializable {
*/
private
BigDecimal
avgSpeed
;
private
Integer
calorie
;
private
BigDecimal
weight
;
private
BigDecimal
oneMinutesFtp
;
private
BigDecimal
fiveMinutesFtp
;
private
BigDecimal
twentyMinutesFtp
;
private
BigDecimal
oneMinutesWkg
;
private
BigDecimal
fiveMinutesWkg
;
private
BigDecimal
twentyMinutesWkg
;
private
BigDecimal
score
;
/**
* 获攒数量
*/
...
...
repository/src/main/resources/mapper/sport/SportUserMonthRankMapper.xml
0 → 100644
View file @
8f6861d4
<?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.repository.sport.mapper.SportUserMonthRankMapper"
>
</mapper>
server-api/src/main/java/com/antai/sport/http/server/server/api/business/tour/service/TourService.java
View file @
8f6861d4
...
...
@@ -3,6 +3,8 @@ package com.antai.sport.http.server.server.api.business.tour.service;
import
com.antai.sport.http.server.constants.GameMode
;
import
com.antai.sport.http.server.constants.SportType
;
import
com.antai.sport.http.server.constants.TourRecordStatus
;
import
com.antai.sport.http.server.repository.sport.entity.SportUser
;
import
com.antai.sport.http.server.repository.sport.mapper.SportUserMapper
;
import
com.antai.sport.http.server.repository.tour.entity.TourRecord
;
import
com.antai.sport.http.server.repository.tour.mapper.TourRecordMapper
;
import
com.antai.sport.http.server.server.api.business.praise.service.PraiseService
;
...
...
@@ -15,6 +17,7 @@ import org.springframework.stereotype.Service;
import
org.springframework.transaction.annotation.Transactional
;
import
javax.annotation.Resource
;
import
java.math.RoundingMode
;
import
java.time.LocalDateTime
;
import
java.util.List
;
...
...
@@ -23,6 +26,8 @@ public class TourService {
@Resource
private
TourRecordMapper
tourRecordMapper
;
@Resource
private
SportUserMapper
sportUserMapper
;
@Resource
private
TourRecordConverter
tourRecordConverter
;
...
...
@@ -64,6 +69,8 @@ public class TourService {
tourRecordList
.
forEach
(
item
->
{
TourRecord
oldRecord
=
tourRecordMapper
.
selectById
(
item
.
getRecordId
());
if
(
oldRecord
!=
null
&&
oldRecord
.
getStatus
().
equals
(
TourRecordStatus
.
UNCOMMITTED
))
{
SportUser
user
=
sportUserMapper
.
selectById
(
oldRecord
.
getPlayerId
());
item
.
setWeight
(
user
.
getWeight
());
TourRecord
tourRecord
=
tourRecordConverter
.
convertToTourRecord
(
item
,
TourRecordStatus
.
COMMITTED
);
tourRecord
.
setPraiseNum
(
praiseService
.
getPraiseByGameModeAndRecordId
(
GameMode
.
TOUR
,
item
.
getRecordId
()));
tourRecordMapper
.
updateById
(
tourRecord
);
...
...
@@ -74,4 +81,5 @@ public class TourService {
}
});
}
}
server-api/src/main/java/com/antai/sport/http/server/server/api/business/traininglog/converter/SportUserTrainingLogConverter.java
View file @
8f6861d4
package
com
.
antai
.
sport
.
http
.
server
.
server
.
api
.
business
.
traininglog
.
converter
;
import
com.antai.sport.http.server.repository.sport.entity.SportUserMonthRank
;
import
com.antai.sport.http.server.repository.sport.entity.SportUserTrainingLog
;
import
com.antai.sport.http.server.server.api.common.dto.CyclingDataDTO
;
import
org.mapstruct.Mapper
;
import
org.mapstruct.Mapping
;
import
org.mapstruct.Mappings
;
@Mapper
(
componentModel
=
"spring"
)
public
interface
SportUserTrainingLogConverter
{
SportUserTrainingLog
toSportUserTrainingLog
(
CyclingDataDTO
source
);
@Mappings
({
@Mapping
(
source
=
"source.calorie"
,
target
=
"totalCalorie"
),
@Mapping
(
source
=
"year"
,
target
=
"year"
),
@Mapping
(
source
=
"month"
,
target
=
"month"
)
})
SportUserMonthRank
toSportUserMonthRank
(
SportUserTrainingLog
source
,
Integer
year
,
Integer
month
);
}
server-api/src/main/java/com/antai/sport/http/server/server/api/business/traininglog/service/SportUserTrainingLogService.java
View file @
8f6861d4
...
...
@@ -2,8 +2,10 @@ 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.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.SportUserMonthRankMapper
;
import
com.antai.sport.http.server.repository.sport.mapper.SportUserSummaryMapper
;
import
com.antai.sport.http.server.repository.sport.mapper.SportUserTrainingLogMapper
;
import
com.antai.sport.http.server.server.api.business.traininglog.converter.SportUserTrainingLogConverter
;
...
...
@@ -12,6 +14,7 @@ import com.antai.sport.http.server.server.api.business.traininglog.dto.SportUser
import
com.antai.sport.http.server.server.api.business.traininglog.mapper.SportUserTrainingLogBusinessMapper
;
import
com.antai.sport.http.server.server.api.business.user.dto.ReqSportUserTrainingLog
;
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
;
import
org.springframework.stereotype.Service
;
...
...
@@ -27,6 +30,8 @@ public class SportUserTrainingLogService {
private
SportUserTrainingLogMapper
sportUserTrainingLogMapper
;
@Resource
private
SportUserSummaryMapper
sportUserSummaryMapper
;
@Resource
private
SportUserMonthRankMapper
sportUserMonthRankMapper
;
@Resource
private
SportUserTrainingLogBusinessMapper
sportUserTrainingLogBusinessMapper
;
...
...
@@ -34,9 +39,7 @@ public class SportUserTrainingLogService {
@Resource
private
SportUserTrainingLogConverter
sportUserTrainingLogConverter
;
public
void
createBicycleTrainingLog
(
Long
playerId
,
Integer
gameMode
,
Long
sourceId
,
String
map
,
String
path
,
Integer
praiseNum
,
CyclingDataDTO
sportData
)
{
public
void
createBicycleTrainingLog
(
Long
playerId
,
Integer
gameMode
,
Long
sourceId
,
String
map
,
String
path
,
Integer
praiseNum
,
CyclingDataDTO
sportData
)
{
SportUserTrainingLog
log
=
sportUserTrainingLogConverter
.
toSportUserTrainingLog
(
sportData
);
log
.
setSportType
(
SportType
.
BICYCLE
);
log
.
setGameMode
(
gameMode
);
...
...
@@ -72,6 +75,48 @@ public class SportUserTrainingLogService {
sportUserSummaryMapper
.
updateById
(
summary
);
}
//处理月度排行
Integer
year
=
LocalDate
.
now
().
getYear
();
Integer
month
=
LocalDate
.
now
().
getMonthValue
();
QueryWrapper
<
SportUserMonthRank
>
rankQuery
=
new
QueryWrapper
<>();
rankQuery
.
eq
(
"year"
,
year
);
rankQuery
.
eq
(
"month"
,
month
);
rankQuery
.
eq
(
"player_id"
,
playerId
);
SportUserMonthRank
rank
=
sportUserMonthRankMapper
.
selectOne
(
rankQuery
);
if
(
rank
==
null
)
{
rank
=
sportUserTrainingLogConverter
.
toSportUserMonthRank
(
log
,
year
,
month
);
sportUserMonthRankMapper
.
insert
(
rank
);
}
else
{
modifyRank
(
log
,
rank
);
}
}
private
void
modifyRank
(
SportUserTrainingLog
log
,
SportUserMonthRank
rank
)
{
rank
.
setTotalCalorie
(
rank
.
getTotalCalorie
()
+
log
.
getCalorie
());
rank
.
setUpdateTime
(
LocalDateTime
.
now
());
if
(
log
.
getOneMinutesFtp
().
compareTo
(
rank
.
getOneMinutesFtp
())
==
1
)
{
rank
.
setOneMinutesFtp
(
log
.
getOneMinutesFtp
());
}
if
(
log
.
getFiveMinutesFtp
().
compareTo
(
rank
.
getFiveMinutesFtp
())
==
1
)
{
rank
.
setFiveMinutesFtp
(
log
.
getFiveMinutesFtp
());
}
if
(
log
.
getTwentyMinutesFtp
().
compareTo
(
rank
.
getTwentyMinutesFtp
())
==
1
)
{
rank
.
setTwentyMinutesFtp
(
log
.
getTwentyMinutesFtp
());
}
if
(
log
.
getOneMinutesWkg
().
compareTo
(
rank
.
getOneMinutesWkg
())
==
1
)
{
rank
.
setOneMinutesWkg
(
log
.
getOneMinutesWkg
());
}
if
(
log
.
getFiveMinutesWkg
().
compareTo
(
rank
.
getFiveMinutesWkg
())
==
1
)
{
rank
.
setFiveMinutesWkg
(
log
.
getFiveMinutesWkg
());
}
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
()));
sportUserMonthRankMapper
.
updateById
(
rank
);
}
/**
...
...
server-api/src/main/java/com/antai/sport/http/server/server/api/common/dto/CyclingDataDTO.java
View file @
8f6861d4
package
com
.
antai
.
sport
.
http
.
server
.
server
.
api
.
common
.
dto
;
import
com.antai.sport.http.server.server.api.utils.ScoreUtils
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
java.math.BigDecimal
;
import
java.math.RoundingMode
;
@Data
@ApiModel
(
"基础骑行数据上传对象"
)
...
...
@@ -23,4 +26,53 @@ public class CyclingDataDTO {
private
BigDecimal
avgFtp
;
@ApiModelProperty
(
"平均速度"
)
private
BigDecimal
avgSpeed
;
@ApiModelProperty
(
"卡路里"
)
private
Integer
calorie
;
@ApiModelProperty
(
"1分钟平均最佳功率"
)
private
BigDecimal
oneMinutesFtp
;
@ApiModelProperty
(
"5分钟平均最佳功率"
)
private
BigDecimal
fiveMinutesFtp
;
@ApiModelProperty
(
"20分钟平均最佳功率"
)
private
BigDecimal
twentyMinutesFtp
;
@ApiModelProperty
(
hidden
=
true
)
@JsonIgnore
private
BigDecimal
weight
;
@ApiModelProperty
(
hidden
=
true
)
@JsonIgnore
private
BigDecimal
oneMinutesWkg
;
@ApiModelProperty
(
hidden
=
true
)
@JsonIgnore
private
BigDecimal
fiveMinutesWkg
;
@ApiModelProperty
(
hidden
=
true
)
@JsonIgnore
private
BigDecimal
twentyMinutesWkg
;
@ApiModelProperty
(
hidden
=
true
)
@JsonIgnore
private
BigDecimal
score
;
public
void
setWeight
(
BigDecimal
weight
)
{
this
.
weight
=
weight
;
this
.
weight
=
this
.
weight
==
null
?
BigDecimal
.
ZERO
:
this
.
weight
;
this
.
oneMinutesFtp
=
this
.
oneMinutesFtp
==
null
?
BigDecimal
.
ZERO
:
this
.
oneMinutesFtp
;
this
.
fiveMinutesFtp
=
this
.
fiveMinutesFtp
==
null
?
BigDecimal
.
ZERO
:
this
.
fiveMinutesFtp
;
this
.
twentyMinutesFtp
=
this
.
twentyMinutesFtp
==
null
?
BigDecimal
.
ZERO
:
this
.
twentyMinutesFtp
;
this
.
calorie
=
this
.
calorie
==
null
?
0
:
this
.
calorie
;
this
.
oneMinutesWkg
=
handleWkg
(
this
.
oneMinutesFtp
,
this
.
weight
);
this
.
fiveMinutesWkg
=
handleWkg
(
this
.
fiveMinutesFtp
,
this
.
weight
);
this
.
twentyMinutesWkg
=
handleWkg
(
this
.
twentyMinutesFtp
,
this
.
weight
);
this
.
score
=
ScoreUtils
.
calculate
(
this
.
oneMinutesFtp
,
this
.
fiveMinutesFtp
,
this
.
twentyMinutesFtp
,
this
.
oneMinutesWkg
,
this
.
fiveMinutesWkg
,
this
.
twentyMinutesWkg
);
}
private
BigDecimal
handleWkg
(
BigDecimal
ftp
,
BigDecimal
weight
)
{
if
(
ftp
.
compareTo
(
BigDecimal
.
ZERO
)
==
0
||
weight
.
compareTo
(
BigDecimal
.
ZERO
)
==
0
)
{
return
BigDecimal
.
ZERO
;
}
else
{
return
ftp
.
divide
(
weight
,
1
,
RoundingMode
.
HALF_UP
);
}
}
}
server-api/src/main/java/com/antai/sport/http/server/server/api/utils/ScoreUtils.java
0 → 100644
View file @
8f6861d4
package
com
.
antai
.
sport
.
http
.
server
.
server
.
api
.
utils
;
import
java.math.BigDecimal
;
import
java.math.RoundingMode
;
public
class
ScoreUtils
{
public
static
BigDecimal
calculate
(
BigDecimal
oneMinutesFtp
,
BigDecimal
fiveMinutesFtp
,
BigDecimal
twentyMinutesFtp
,
BigDecimal
oneMinutesWkg
,
BigDecimal
fiveMinutesWkg
,
BigDecimal
twentyMinutesWkg
)
{
BigDecimal
s1
,
s2
,
s3
,
s4
,
s5
,
s6
;
s1
=
handeScore
(
oneMinutesFtp
,
BigDecimal
.
valueOf
(
1
));
s2
=
handeScore
(
fiveMinutesFtp
,
BigDecimal
.
valueOf
(
1.1
));
s3
=
handeScore
(
twentyMinutesFtp
,
BigDecimal
.
valueOf
(
1.4
));
s4
=
handeScore
(
oneMinutesWkg
,
BigDecimal
.
valueOf
(
50
));
s5
=
handeScore
(
fiveMinutesWkg
,
BigDecimal
.
valueOf
(
80
));
s6
=
handeScore
(
twentyMinutesWkg
,
BigDecimal
.
valueOf
(
100
));
return
s1
.
add
(
s2
).
add
(
s3
).
add
(
s4
).
add
(
s5
).
add
(
s6
);
}
private
static
BigDecimal
handeScore
(
BigDecimal
value
,
BigDecimal
coefficient
)
{
BigDecimal
result
=
value
.
multiply
(
coefficient
).
setScale
(
0
,
RoundingMode
.
HALF_UP
);
BigDecimal
max
=
BigDecimal
.
valueOf
(
600
);
return
result
.
compareTo
(
max
)
==
1
?
max
:
result
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment