Commit 684c36b5 authored by haoyanbin's avatar haoyanbin

1

parent 5c583e9d
...@@ -165,13 +165,21 @@ func (e OrgPlayer) GetInfo(c *gin.Context) { ...@@ -165,13 +165,21 @@ func (e OrgPlayer) GetInfo(c *gin.Context) {
reply := new(dto.OrgPlayerGetInfoReply) reply := new(dto.OrgPlayerGetInfoReply)
reply.OrgPlayerInfo = object reply.OrgPlayerInfo = object
replyOrgMatchInfo := new(dto.OrgMatchInfo) replyDataAvg := dto.OrgMatchInfo{}
err = s.StatisticsScoringAvg(strconv.Itoa(req.PlayerId), seasonId, "avg", replyOrgMatchInfo) err = s.StatisticsScoringAvg("", seasonId, "avg", &replyDataAvg)
if err != nil { if err != nil {
e.Error(500, err, fmt.Sprintf("获取比赛球员信息 失败,\r\n失败信息 %s", err.Error())) e.Error(500, err, fmt.Sprintf("获取比赛球员信息 失败,\r\n失败信息 %s", err.Error()))
return return
} }
reply.OrgMatchInfo = *replyOrgMatchInfo reply.DataAvg = replyDataAvg
replyOrgMatchInfo := dto.OrgMatchInfo{}
err = s.StatisticsScoringAvg(strconv.Itoa(req.PlayerId), seasonId, "avg", &replyOrgMatchInfo)
if err != nil {
e.Error(500, err, fmt.Sprintf("获取比赛球员信息 失败,\r\n失败信息 %s", err.Error()))
return
}
reply.OrgMatchInfo = replyOrgMatchInfo
err, matchId := s.GetMatchId(strconv.Itoa(req.PlayerId), seasonId) err, matchId := s.GetMatchId(strconv.Itoa(req.PlayerId), seasonId)
var count int64 var count int64
......
...@@ -74,10 +74,28 @@ type OrgPlayerGetInfoReq struct { ...@@ -74,10 +74,28 @@ type OrgPlayerGetInfoReq struct {
type OrgPlayerGetInfoReply struct { type OrgPlayerGetInfoReply struct {
OrgPlayerInfo OrgPlayerGetReply `json:"orgPlayerInfo"` OrgPlayerInfo OrgPlayerGetReply `json:"orgPlayerInfo"`
DataAvg OrgMatchInfo `json:"dataAvg"`
OrgMatchInfo OrgMatchInfo `json:"orgMatchInfo"` OrgMatchInfo OrgMatchInfo `json:"orgMatchInfo"`
RoundsScoring []OrgPlayerRoundsScoring `json:"roundsScoring"` RoundsScoring []OrgPlayerRoundsScoring `json:"roundsScoring"`
} }
type DataAvg struct {
//ScoringAvg string `json:"scoringAvg" comment:"得分"`
//ReboundAvg string `json:"reboundAvg" comment:"篮板"`
//AssistAvg string `json:"assistAvg" comment:"助攻"`
//StealAvg string `json:"stealAvg" comment:"抢断"`
//FreeThrowAvg string `json:"freeThrowAvg" comment:"罚球"`
//BlockShotAvg string `json:"blockShotAvg" comment:"盖帽"`
//FoulAvg string `json:"foulAvg" comment:"犯规"`
//TwoPointShotAvg string `json:"twoPointShotAvg" comment:"2分进球数量"`
//ThreePointShotAvg string `json:"threePointShotAvg" comment:"3分进球数量"`
Scoring string `json:"scoring" comment:"得分"`
Rebound string `json:"rebound" comment:"篮板"`
Assist string `json:"assist" comment:"助攻"`
Steal string `json:"steal" comment:"抢断"`
BlockShot string `json:"blockShot" comment:"盖帽"`
}
type OrgMatchInfo struct { type OrgMatchInfo struct {
Id string `json:"id"` Id string `json:"id"`
SeasonId string `json:"seasonId" comment:"赛季id"` SeasonId string `json:"seasonId" comment:"赛季id"`
......
...@@ -181,8 +181,8 @@ func (e *OrgPlayer) StatisticsScoringAvg(playerId string, seasonId string, stati ...@@ -181,8 +181,8 @@ func (e *OrgPlayer) StatisticsScoringAvg(playerId string, seasonId string, stati
Joins("left join org_match as om on omtp.match_id = om.id and omtp.rounds = om.rounds"). Joins("left join org_match as om on omtp.match_id = om.id and omtp.rounds = om.rounds").
Joins("left join org_league as ol on ol.id = om.league_id"). Joins("left join org_league as ol on ol.id = om.league_id").
Joins("left join org_season as os on os.id = om.season_id"). Joins("left join org_season as os on os.id = om.season_id").
Scopes(cDto.SetWhere("omtp", "player_id", playerId)).
Where("om.season_id = ?", seasonId). Where("om.season_id = ?", seasonId).
Where("omtp.player_id = ?", playerId).
Group("om.season_id"). Group("om.season_id").
First(data).Error First(data).Error
...@@ -191,7 +191,10 @@ func (e *OrgPlayer) StatisticsScoringAvg(playerId string, seasonId string, stati ...@@ -191,7 +191,10 @@ func (e *OrgPlayer) StatisticsScoringAvg(playerId string, seasonId string, stati
err = e.Orm.Table("org_match_team_player as omtp"). err = e.Orm.Table("org_match_team_player as omtp").
Joins("left join org_match as om on omtp.match_id = om.id and omtp.rounds = om.rounds"). Joins("left join org_match as om on omtp.match_id = om.id and omtp.rounds = om.rounds").
Select(field). Select(field).
Scopes(cDto.SetWhere("om", "season_id", seasonId)). Scopes(
cDto.SetWhere("om", "season_id", seasonId),
cDto.SetWhere("omtp", "player_id", playerId),
).
Count(&teamCount).Error Count(&teamCount).Error
data.Scoring = utils.GetAvg(data.Scoring, teamCount) data.Scoring = utils.GetAvg(data.Scoring, teamCount)
......
...@@ -22,8 +22,10 @@ func StringToInt(data string) int { ...@@ -22,8 +22,10 @@ func StringToInt(data string) int {
func GetAvg(data string, count int64) string { func GetAvg(data string, count int64) string {
floatData, _ := strconv.ParseFloat(data, 64) floatData, _ := strconv.ParseFloat(data, 64)
res := fmt.Sprintf("%.2f", floatData/float64(count)) return strconv.FormatFloat(floatData/float64(count), 'f', 2, 64)
return res
//res := fmt.Sprintf("%.2f", floatData/float64(count))
//return res
} }
func StringToFloat(data string) float64 { func StringToFloat(data string) float64 {
......
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