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
42fd6d20
Commit
42fd6d20
authored
Apr 13, 2022
by
liming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
用户主页数据统计
parent
97c0ab9e
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
227 additions
and
2 deletions
+227
-2
SportUserTrainingLogSummaryVO.java
...siness/traininglog/dto/SportUserTrainingLogSummaryVO.java
+20
-0
SportUserTrainingLogBusinessMapper.java
...raininglog/mapper/SportUserTrainingLogBusinessMapper.java
+16
-0
SportUserTrainingLogService.java
...ness/traininglog/service/SportUserTrainingLogService.java
+40
-2
SportUserController.java
...ver/api/business/user/controller/SportUserController.java
+30
-0
RespUserHomeInfo.java
...server/server/api/business/user/dto/RespUserHomeInfo.java
+31
-0
SportUserSummaryBusinessMapper.java
.../business/user/mapper/SportUserSummaryBusinessMapper.java
+2
-0
SportUserService.java
...er/server/api/business/user/service/SportUserService.java
+64
-0
SportUserTrainingLogBusinessMapper.xml
...mapper/traininglog/SportUserTrainingLogBusinessMapper.xml
+17
-0
SportUserSummaryBuisnessMapper.xml
.../resources/mapper/user/SportUserSummaryBuisnessMapper.xml
+7
-0
No files found.
server-api/src/main/java/com/antai/sport/http/server/server/api/business/traininglog/dto/SportUserTrainingLogSummaryVO.java
0 → 100644
View file @
42fd6d20
package
com
.
antai
.
sport
.
http
.
server
.
server
.
api
.
business
.
traininglog
.
dto
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
java.math.BigDecimal
;
@ApiModel
(
"用户运动数据汇总"
)
@Data
public
class
SportUserTrainingLogSummaryVO
{
@ApiModelProperty
(
"时长(秒)"
)
private
Integer
totalDuration
;
@ApiModelProperty
(
"累计距离"
)
private
BigDecimal
totalDistance
;
@ApiModelProperty
(
"累计爬坡高度"
)
private
BigDecimal
totalClimbDistance
;
@ApiModelProperty
(
"单次最长记录"
)
private
BigDecimal
longestDistance
;
}
server-api/src/main/java/com/antai/sport/http/server/server/api/business/traininglog/mapper/SportUserTrainingLogBusinessMapper.java
0 → 100644
View file @
42fd6d20
package
com
.
antai
.
sport
.
http
.
server
.
server
.
api
.
business
.
traininglog
.
mapper
;
import
com.antai.sport.http.server.repository.sport.entity.SportUserTrainingLog
;
import
com.antai.sport.http.server.server.api.business.traininglog.dto.SportUserTrainingLogSummaryVO
;
import
org.apache.ibatis.annotations.Param
;
import
java.time.LocalDate
;
public
interface
SportUserTrainingLogBusinessMapper
{
SportUserTrainingLog
getLongestTrainingLog
(
@Param
(
"sportType"
)
Integer
sportType
,
@Param
(
"userId"
)
Long
userId
);
SportUserTrainingLogSummaryVO
getTrainingLogSummary
(
@Param
(
"sportType"
)
Integer
sportType
,
@Param
(
"userId"
)
Long
userId
,
@Param
(
"beginDate"
)
LocalDate
beginDate
,
@Param
(
"endDate"
)
LocalDate
endDate
);
}
server-api/src/main/java/com/antai/sport/http/server/server/api/business/traininglog/service/SportUserTrainingLogService.java
View file @
42fd6d20
...
@@ -7,6 +7,8 @@ import com.antai.sport.http.server.repository.sport.entity.SportUserTrainingLog;
...
@@ -7,6 +7,8 @@ import com.antai.sport.http.server.repository.sport.entity.SportUserTrainingLog;
import
com.antai.sport.http.server.repository.sport.mapper.SportUserSummaryMapper
;
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.repository.sport.mapper.SportUserTrainingLogMapper
;
import
com.antai.sport.http.server.server.api.business.traininglog.converter.SportUserTrainingLogConverter
;
import
com.antai.sport.http.server.server.api.business.traininglog.converter.SportUserTrainingLogConverter
;
import
com.antai.sport.http.server.server.api.business.traininglog.dto.SportUserTrainingLogSummaryVO
;
import
com.antai.sport.http.server.server.api.business.traininglog.mapper.SportUserTrainingLogBusinessMapper
;
import
com.antai.sport.http.server.server.api.common.dto.CyclingDataDTO
;
import
com.antai.sport.http.server.server.api.common.dto.CyclingDataDTO
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
...
@@ -15,7 +17,6 @@ import javax.annotation.Resource;
...
@@ -15,7 +17,6 @@ import javax.annotation.Resource;
import
java.math.BigDecimal
;
import
java.math.BigDecimal
;
import
java.time.LocalDate
;
import
java.time.LocalDate
;
import
java.time.LocalDateTime
;
import
java.time.LocalDateTime
;
import
java.time.format.DateTimeFormatter
;
@Service
@Service
public
class
SportUserTrainingLogService
{
public
class
SportUserTrainingLogService
{
...
@@ -24,6 +25,9 @@ public class SportUserTrainingLogService {
...
@@ -24,6 +25,9 @@ public class SportUserTrainingLogService {
@Resource
@Resource
private
SportUserSummaryMapper
sportUserSummaryMapper
;
private
SportUserSummaryMapper
sportUserSummaryMapper
;
@Resource
private
SportUserTrainingLogBusinessMapper
sportUserTrainingLogBusinessMapper
;
@Resource
@Resource
private
SportUserTrainingLogConverter
sportUserTrainingLogConverter
;
private
SportUserTrainingLogConverter
sportUserTrainingLogConverter
;
...
@@ -50,10 +54,11 @@ public class SportUserTrainingLogService {
...
@@ -50,10 +54,11 @@ public class SportUserTrainingLogService {
if
(
summary
==
null
)
{
if
(
summary
==
null
)
{
summary
=
new
SportUserSummary
();
summary
=
new
SportUserSummary
();
summary
.
setUserId
(
playerId
);
summary
.
setUserId
(
playerId
);
summary
.
setType
(
SportType
.
BICYCLE
);
summary
.
setType
(
SportType
.
BICYCLE
);
summary
.
setTotalDistance
(
BigDecimal
.
ZERO
);
summary
.
setTotalDistance
(
BigDecimal
.
ZERO
);
summary
.
setTotalClimbDistance
(
BigDecimal
.
ZERO
);
summary
.
setTotalClimbDistance
(
BigDecimal
.
ZERO
);
summary
.
setTotalDuration
(
0
);
summary
.
setTotalDuration
(
0
);
summary
.
setTotalPraiseNum
(
0
);
}
}
summary
.
setTotalDuration
(
summary
.
getTotalDuration
()
+
log
.
getDuration
());
summary
.
setTotalDuration
(
summary
.
getTotalDuration
()
+
log
.
getDuration
());
summary
.
setTotalDistance
(
summary
.
getTotalDistance
().
add
(
log
.
getDistance
()));
summary
.
setTotalDistance
(
summary
.
getTotalDistance
().
add
(
log
.
getDistance
()));
...
@@ -65,4 +70,37 @@ public class SportUserTrainingLogService {
...
@@ -65,4 +70,37 @@ public class SportUserTrainingLogService {
}
}
}
}
/**
* 获取用户某个运动下的最长记录
*
* @param sportType
* @param userId
* @return
*/
public
SportUserTrainingLog
getLongestTrainingLog
(
Integer
sportType
,
Long
userId
)
{
return
sportUserTrainingLogBusinessMapper
.
getLongestTrainingLog
(
sportType
,
userId
);
}
/**
* 获取时间范围内运动数据汇总
*
* @param sportType 运动类型
* @param userId 用户Id
* @param daysCondition 统计天数
* @return
*/
public
SportUserTrainingLogSummaryVO
getTrainingLogSummary
(
Integer
sportType
,
Long
userId
,
Integer
daysCondition
)
{
LocalDate
now
=
LocalDate
.
now
();
LocalDate
beginDate
=
now
.
minusDays
(
daysCondition
-
1
);
SportUserTrainingLogSummaryVO
summaryVO
=
sportUserTrainingLogBusinessMapper
.
getTrainingLogSummary
(
sportType
,
userId
,
beginDate
,
now
);
if
(
summaryVO
==
null
)
{
summaryVO
=
new
SportUserTrainingLogSummaryVO
();
summaryVO
.
setLongestDistance
(
BigDecimal
.
ZERO
);
summaryVO
.
setTotalDistance
(
BigDecimal
.
ZERO
);
summaryVO
.
setTotalClimbDistance
(
BigDecimal
.
ZERO
);
summaryVO
.
setTotalDuration
(
0
);
}
return
summaryVO
;
}
}
}
server-api/src/main/java/com/antai/sport/http/server/server/api/business/user/controller/SportUserController.java
0 → 100644
View file @
42fd6d20
package
com
.
antai
.
sport
.
http
.
server
.
server
.
api
.
business
.
user
.
controller
;
import
com.antai.sport.http.server.common.base.Result
;
import
com.antai.sport.http.server.server.api.business.user.dto.RespUserHomeInfo
;
import
com.antai.sport.http.server.server.api.business.user.service.SportUserService
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.annotation.Resource
;
import
static
com
.
antai
.
sport
.
http
.
server
.
common
.
util
.
ResultUtil
.
success
;
@Api
(
tags
=
{
"用户相关接口"
})
@RestController
@RequestMapping
(
"user"
)
public
class
SportUserController
{
@Resource
private
SportUserService
sportUserService
;
@ApiOperation
(
"查询用户主页数据"
)
@GetMapping
(
"{userId}"
)
public
ResponseEntity
<
Result
<
RespUserHomeInfo
>>
getUserHomeInfo
(
@PathVariable
(
"userId"
)
Long
userId
)
{
return
success
(
sportUserService
.
getUserHomeInfo
(
userId
));
}
}
server-api/src/main/java/com/antai/sport/http/server/server/api/business/user/dto/RespUserHomeInfo.java
0 → 100644
View file @
42fd6d20
package
com
.
antai
.
sport
.
http
.
server
.
server
.
api
.
business
.
user
.
dto
;
import
com.antai.sport.http.server.server.api.business.traininglog.dto.SportUserTrainingLogSummaryVO
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
java.math.BigDecimal
;
@Data
@ApiModel
(
"用户主页汇总统计数据"
)
public
class
RespUserHomeInfo
{
@ApiModelProperty
(
"用户id"
)
private
Long
id
;
@ApiModelProperty
(
"用户昵称"
)
private
String
nickname
;
@ApiModelProperty
(
"头像"
)
private
String
avatar
;
@ApiModelProperty
(
"ftp"
)
private
Integer
ftp
;
@ApiModelProperty
(
"功体比"
)
private
BigDecimal
wkg
;
@ApiModelProperty
(
"观看次数"
)
private
Integer
views
;
@ApiModelProperty
(
"7天数据汇总"
)
private
SportUserTrainingLogSummaryVO
weekSummary
;
@ApiModelProperty
(
"30天数据汇总"
)
private
SportUserTrainingLogSummaryVO
monthSummary
;
@ApiModelProperty
(
"全部数据汇总"
)
private
SportUserTrainingLogSummaryVO
totalSummary
;
}
server-api/src/main/java/com/antai/sport/http/server/server/api/business/user/mapper/SportUserSummaryBusinessMapper.java
View file @
42fd6d20
package
com
.
antai
.
sport
.
http
.
server
.
server
.
api
.
business
.
user
.
mapper
;
package
com
.
antai
.
sport
.
http
.
server
.
server
.
api
.
business
.
user
.
mapper
;
import
com.antai.sport.http.server.repository.sport.entity.SportUserSummary
;
import
org.apache.ibatis.annotations.Param
;
import
org.apache.ibatis.annotations.Param
;
public
interface
SportUserSummaryBusinessMapper
{
public
interface
SportUserSummaryBusinessMapper
{
int
updateUserPraise
(
@Param
(
"userId"
)
Long
userId
,
@Param
(
"sportType"
)
Integer
sportType
);
int
updateUserPraise
(
@Param
(
"userId"
)
Long
userId
,
@Param
(
"sportType"
)
Integer
sportType
);
SportUserSummary
selectBySportTypeAndUserId
(
@Param
(
"userId"
)
Long
userId
,
@Param
(
"sportType"
)
Integer
sportType
);
}
}
server-api/src/main/java/com/antai/sport/http/server/server/api/business/user/service/SportUserService.java
0 → 100644
View file @
42fd6d20
package
com
.
antai
.
sport
.
http
.
server
.
server
.
api
.
business
.
user
.
service
;
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.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.server.api.business.traininglog.service.SportUserTrainingLogService
;
import
com.antai.sport.http.server.server.api.business.user.dto.RespUserHomeInfo
;
import
com.antai.sport.http.server.server.api.business.traininglog.dto.SportUserTrainingLogSummaryVO
;
import
com.antai.sport.http.server.server.api.business.user.mapper.SportUserSummaryBusinessMapper
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
java.math.BigDecimal
;
import
java.math.RoundingMode
;
@Service
public
class
SportUserService
{
@Resource
private
SportUserMapper
sportUserMapper
;
@Resource
private
SportUserSummaryBusinessMapper
sportUserSummaryBusinessMapper
;
@Resource
private
SportUserTrainingLogService
sportUserTrainingLogService
;
public
RespUserHomeInfo
getUserHomeInfo
(
Long
userId
)
{
RespUserHomeInfo
resp
=
new
RespUserHomeInfo
();
SportUser
sportUser
=
sportUserMapper
.
selectById
(
userId
);
SportUserSummary
sportUserSummary
=
sportUserSummaryBusinessMapper
.
selectBySportTypeAndUserId
(
userId
,
SportType
.
BICYCLE
);
resp
.
setId
(
sportUser
.
getId
());
resp
.
setAvatar
(
sportUser
.
getAvatar
());
resp
.
setNickname
(
sportUser
.
getNickname
());
resp
.
setViews
(
sportUserSummary
.
getViews
()
==
null
?
0
:
sportUserSummary
.
getViews
());
resp
.
setFtp
(
sportUser
.
getFtp
()
==
null
?
0
:
sportUser
.
getFtp
());
if
(
sportUser
.
getFtp
()
==
null
||
sportUser
.
getWeight
()
==
null
)
{
resp
.
setWkg
(
BigDecimal
.
ZERO
);
}
else
{
resp
.
setWkg
(
BigDecimal
.
valueOf
(
sportUser
.
getFtp
()).
divide
(
sportUser
.
getWeight
(),
1
,
RoundingMode
.
HALF_UP
));
}
//组装全部汇总数据
SportUserTrainingLogSummaryVO
totalSummary
=
new
SportUserTrainingLogSummaryVO
();
totalSummary
.
setTotalDistance
(
sportUserSummary
.
getTotalDistance
());
totalSummary
.
setTotalClimbDistance
(
sportUserSummary
.
getTotalClimbDistance
());
totalSummary
.
setTotalDuration
(
sportUserSummary
.
getTotalDuration
());
SportUserTrainingLog
longestTrainingLog
=
sportUserTrainingLogService
.
getLongestTrainingLog
(
SportType
.
BICYCLE
,
userId
);
if
(
longestTrainingLog
==
null
){
totalSummary
.
setLongestDistance
(
BigDecimal
.
ZERO
);
}
else
{
totalSummary
.
setLongestDistance
(
longestTrainingLog
.
getDistance
());
}
resp
.
setTotalSummary
(
totalSummary
);
//查询7天数据汇总
resp
.
setWeekSummary
(
sportUserTrainingLogService
.
getTrainingLogSummary
(
SportType
.
BICYCLE
,
userId
,
7
));
//查询30天数据汇总
resp
.
setMonthSummary
(
sportUserTrainingLogService
.
getTrainingLogSummary
(
SportType
.
BICYCLE
,
userId
,
30
));
return
resp
;
}
}
server-api/src/main/resources/mapper/traininglog/SportUserTrainingLogBusinessMapper.xml
0 → 100644
View file @
42fd6d20
<?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.traininglog.mapper.SportUserTrainingLogBusinessMapper"
>
<select
id=
"getLongestTrainingLog"
resultType=
"com.antai.sport.http.server.repository.sport.entity.SportUserTrainingLog"
>
select * from sport_user_training_log
where player_id = #{userId} and sport_type = #{sportType}
order by distance desc limit 1
</select>
<select
id=
"getTrainingLogSummary"
resultType=
"com.antai.sport.http.server.server.api.business.traininglog.dto.SportUserTrainingLogSummaryVO"
>
select ifnull(sum(duration),0) as totalDuration, ifnull(sum(distance),0) as totalDistance,
ifnull(sum(climb_distance),0) as totalClimbDistance,ifnull(max(distance),0) as longestDistance
from sport_user_training_log
where player_id = #{userId} and sport_type = #{sportType}
and create_date
>
= #{beginDate} and create_date
<
= #{endDate}
</select>
</mapper>
\ No newline at end of file
server-api/src/main/resources/mapper/user/SportUserSummaryBuisnessMapper.xml
View file @
42fd6d20
...
@@ -6,4 +6,11 @@
...
@@ -6,4 +6,11 @@
set total_praise_num = ifnull(total_praise_num, 0) + 1
set total_praise_num = ifnull(total_praise_num, 0) + 1
where user_id = #{userId} and type = #{sportType}
where user_id = #{userId} and type = #{sportType}
</update>
</update>
<select
id=
"selectBySportTypeAndUserId"
resultType=
"com.antai.sport.http.server.repository.sport.entity.SportUserSummary"
>
select *
from sport_user_summary
where user_id = #{userId} and type = #{sportType}
</select>
</mapper>
</mapper>
\ No newline at end of file
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