Commit fbcdc0d0 authored by haoyanbin's avatar haoyanbin

teamrankinfo

parent 4b568a67
...@@ -5,10 +5,11 @@ import ( ...@@ -5,10 +5,11 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/go-admin-team/go-admin-core/sdk/api" "github.com/go-admin-team/go-admin-core/sdk/api"
_ "github.com/go-admin-team/go-admin-core/sdk/pkg/response" _ "github.com/go-admin-team/go-admin-core/sdk/pkg/response"
"go-admin/app/mobile/service" "go-admin/app/mobile/service"
"go-admin/app/mobile/service/dto" "go-admin/app/mobile/service/dto"
"go-admin/common/actions" "go-admin/common/actions"
"go-admin/common/utils"
"strconv"
) )
type OrgPlayerRank struct { type OrgPlayerRank struct {
...@@ -89,6 +90,76 @@ func (e OrgPlayerRank) GetPageTeam(c *gin.Context) { ...@@ -89,6 +90,76 @@ func (e OrgPlayerRank) GetPageTeam(c *gin.Context) {
e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功") e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
} }
// GetPage <手机端>获取球队排名详情
// @Summary <手机端>获取球队排名详情
// @Description <手机端>获取球队排名详情
// @Tags <手机端>比赛排名
// @Param data body dto.OrgPlayerRankInfoGetReq true "data"
// @Success 200 {string} string "{"code": 200, "data": [...]}"
// @Router /mobile/v1/org-player-rank/team-info [get]
// @Security Bearer
func (e OrgPlayerRank) GetPageTeamInfo(c *gin.Context) {
req := dto.OrgPlayerRankInfoGetReq{}
s := service.OrgPlayerRank{}
err := e.MakeContext(c).
MakeOrm().
Bind(&req).
MakeService(&s.Service).
Errors
if err != nil {
e.Logger.Error(err)
e.Error(500, err, err.Error())
return
}
reply := dto.OrgPlayerRankInfoGetReply{}
//获取基本信息
err = s.GetTeamInfoData(req.TeamId, req.SeasonId, &reply)
//获取排名数据
err = s.GetRankTeamInfo(req.TeamId, req.SeasonId, &reply)
//获取平均值数据
list := make([]dto.OrgPlayerRankGetPageReply, 0)
var count int64
err = s.GetPageTeamInfo(req.TeamId, req.SeasonId, &list, &count)
if err != nil {
e.Error(500, err, fmt.Sprintf("获取球队 失败,\r\n失败信息 %s", err.Error()))
return
}
var sumScoring, sumRebound, sumAssist, sumSteal, sumFreeThrow, sumBlockShot, sumFoul, sumTwoPointShot, sumThreePointShot int
for _, v := range list {
sumScoring += utils.StringToInt(v.Scoring)
sumRebound += utils.StringToInt(v.Rebound)
sumAssist += utils.StringToInt(v.Assist)
sumSteal += utils.StringToInt(v.Steal)
sumFreeThrow += utils.StringToInt(v.FreeThrow)
sumBlockShot += utils.StringToInt(v.BlockShot)
sumFoul += utils.StringToInt(v.Foul)
sumTwoPointShot += utils.StringToInt(v.TwoPointShot)
sumThreePointShot += utils.StringToInt(v.ThreePointShot)
}
reply.Scoring = strconv.FormatFloat(float64(sumScoring)/float64(count), 'f', 2, 64)
reply.Rebound = strconv.FormatFloat(float64(sumRebound)/float64(count), 'f', 2, 64)
reply.Assist = strconv.FormatFloat(float64(sumAssist)/float64(count), 'f', 2, 64)
reply.Steal = strconv.FormatFloat(float64(sumSteal)/float64(count), 'f', 2, 64)
reply.FreeThrow = strconv.FormatFloat(float64(sumFreeThrow)/float64(count), 'f', 2, 64)
reply.BlockShot = strconv.FormatFloat(float64(sumBlockShot)/float64(count), 'f', 2, 64)
reply.Foul = strconv.FormatFloat(float64(sumFoul)/float64(count), 'f', 2, 64)
reply.TwoPointShot = strconv.FormatFloat(float64(sumTwoPointShot)/float64(count), 'f', 2, 64)
reply.ThreePointShot = strconv.FormatFloat(float64(sumThreePointShot)/float64(count), 'f', 2, 64)
//获取球员列表
replyPlayerList := make([]dto.OrgPlayerGetPageReply, 0)
err = s.GetTeamInfoPlayerList(req.TeamId, &replyPlayerList)
reply.PlayerList = replyPlayerList
e.OK(reply, "查询成功")
}
// GetPage <手机端>获取联赛列表 // GetPage <手机端>获取联赛列表
// @Summary <手机端>获取联赛列表 // @Summary <手机端>获取联赛列表
// @Description <手机端>获取联赛列表 // @Description <手机端>获取联赛列表
......
...@@ -16,6 +16,7 @@ func registerOrgPlayerRankRouter(v1 *gin.RouterGroup) { ...@@ -16,6 +16,7 @@ func registerOrgPlayerRankRouter(v1 *gin.RouterGroup) {
{ {
r.GET("", api.GetPage) r.GET("", api.GetPage)
r.GET("/team", api.GetPageTeam) r.GET("/team", api.GetPageTeam)
r.GET("/team-info", api.GetPageTeamInfo)
r.GET("/league", api.GetPageLeague) r.GET("/league", api.GetPageLeague)
} }
} }
...@@ -25,6 +25,55 @@ type OrgPlayerRankGetPageReply struct { ...@@ -25,6 +25,55 @@ type OrgPlayerRankGetPageReply struct {
dto.TotalScoring dto.TotalScoring
} }
type OrgPlayerRankInfoGetReq struct {
dto.Pagination `search:"-"`
LeagueId string `form:"leagueId" search:"type:exact;column:league_id;table:om" comment:"联赛级别id"` //联赛级别id
SeasonId string `form:"seasonId" search:"type:exact;column:season_id;table:om" comment:"赛季id"` //赛季id
TeamId string `form:"teamId" search:"-"` //
}
type OrgPlayerRankInfoGetReply struct {
Id string `json:"id"`
LeagueName string `json:"leagueName"`
TeamName string `json:"teamName"`
ClubName string `json:"clubName"`
ClubLogo string `json:"clubLogo"`
ClubQrcode string `json:"clubQrcode"`
SeasonName string `json:"seasonName" comment:"赛季名称"`
CompositeRank string `json:"compositeRank" comment:"综合排名"`
CountWin string `json:"countWin" comment:"胜场"`
CountLose string `json:"countLose" comment:"败场"`
CountIntegral string `json:"countIntegral" comment:"总积分"`
CountMatch string `json:"countMatch" comment:"总场次"`
ScoringRank string `json:"scoringRank" comment:"得分"`
ReboundRank string `json:"reboundRank" comment:"篮板"`
AssistRank string `json:"assistRank" comment:"助攻"`
StealRank string `json:"stealRank" comment:"抢断"`
FreeThrowRank string `json:"freeThrowRank" comment:"罚球"`
BlockShotRank string `json:"blockShotRank" comment:"盖帽"`
FoulRank string `json:"foulRank" comment:"犯规"`
TwoPointShotRank string `json:"twoPointShotRank" comment:"2分进球数量"`
ThreePointShotRank string `json:"threePointShotRank" comment:"3分进球数量"`
PlayerList []OrgPlayerGetPageReply `json:"playerList" comment:"球员列表"`
dto.TotalScoring
}
type OrgPlayerRankInfoGetData struct {
Id string `json:"id"`
LeagueName string `json:"leagueName"`
TeamName string `json:"teamName"`
ClubName string `json:"clubName"`
ClubLogo string `json:"clubLogo"`
ClubQrcode string `json:"clubQrcode"`
SeasonName string `json:"seasonName" comment:"赛季名称"`
TeamAId string `json:"teamAId" comment:"a队id"`
TeamBId string `json:"teamBId" comment:"b队id"`
TeamAScore string `json:"teamAScore" comment:"a队比分"`
TeamBScore string `json:"teamBScore" comment:"b队比分"`
TeamAIntegral string `json:"teamAIntegral" comment:"a队积分"`
TeamBIntegral string `json:"teamBIntegral" comment:"b队积分"`
}
type GetPageMatchPlayerRankReq struct { type GetPageMatchPlayerRankReq struct {
Id string `form:"id" json:"id"` Id string `form:"id" json:"id"`
} }
......
...@@ -141,6 +141,192 @@ func (e *OrgPlayerRank) GetPageTeam(c *dto.OrgPlayerRankGetPageReq, p *actions.D ...@@ -141,6 +141,192 @@ func (e *OrgPlayerRank) GetPageTeam(c *dto.OrgPlayerRankGetPageReq, p *actions.D
return nil return nil
} }
// GetPage 获取OrgMatchEvaluate列表
func (e *OrgPlayerRank) GetPageTeamInfo(teamId string, seasonId string, list *[]dto.OrgPlayerRankGetPageReply, count *int64) error {
var err error
err = e.Orm.Table("org_match_team_player as omtp").
Select("omtp.team_id as id,"+
"sum(omtp.scoring)as scoring,"+
"sum(omtp.rebound)as rebound,"+
"sum(omtp.assist)as assist,"+
"sum(omtp.steal)as steal,"+
"sum(omtp.free_throw)as free_throw,"+
"sum(omtp.block_shot)as block_shot,"+
"sum(omtp.foul)as foul,"+
"sum(omtp.two_point_shot)as two_point_shot,"+
"sum(omtp.three_point_shot)as three_point_shot").
Joins("left join org_match as om on omtp.match_id = om.id and omtp.rounds = om.rounds").
Scopes(
cDto.PassDel("omtp"),
cDto.SetWhere("om", "season_id", seasonId),
).
Where("omtp.team_id=?", teamId).
Find(list).Limit(-1).Offset(-1).
Count(count).Error
if err != nil {
e.Log.Errorf("OrgClubPlayer GetPage error:%s \r\n", err)
return err
}
return nil
}
// GetPage 获取OrgMatchEvaluate列表
func (e *OrgPlayerRank) GetTeamInfoData(teamId string, seasonId string, data *dto.OrgPlayerRankInfoGetReply) error {
var err error
list := make([]dto.OrgPlayerRankInfoGetData, 0)
err = e.Orm.Table("org_match as om").
Select("om.id, ol.league_name, os.season_name, oc.club_name, oc.club_logo, ot.team_name,"+
"om.team_a_id,om.team_b_id,om.team_a_score,om.team_b_score,om.team_a_integral,om.team_b_integral").
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_club as oc on oc.id = om.club_id").
Joins("left join org_team as ot on ot.id = om.team_id").
Scopes(
cDto.PassDel("om"),
cDto.SetWhere("om", "season_id", seasonId),
).
Where("om.team_a_id=? or om.team_a_id=?", teamId, teamId).
Find(&list).Error
if err != nil {
e.Log.Errorf("OrgClubPlayer GetPage error:%s \r\n", err)
return err
}
var countWin, countLose, countIntegral, countMatch = 0, 0, 0, 0
for _, v := range list {
countMatch += 1
if v.TeamAId == teamId {
if v.TeamAScore > v.TeamBScore {
countWin += 1
} else {
countLose += 1
}
countIntegral += utils.StringToInt(v.TeamAIntegral)
}
if v.TeamBId == teamId {
if v.TeamAScore > v.TeamBScore {
countLose += 1
} else {
countWin += 1
}
countIntegral += utils.StringToInt(v.TeamBIntegral)
}
}
data.LeagueName = list[0].LeagueName
data.SeasonName = list[0].SeasonName
data.ClubName = list[0].ClubName
data.ClubLogo = list[0].ClubLogo
data.TeamName = list[0].TeamName
data.CountWin = strconv.Itoa(countWin)
data.CountLose = strconv.Itoa(countLose)
data.CountIntegral = strconv.Itoa(countIntegral)
data.CountMatch = strconv.Itoa(countMatch)
return nil
}
// GetPage 获取OrgMatchEvaluate列表
func (e *OrgPlayerRank) GetTeamInfoPlayerList(teamId string, list *[]dto.OrgPlayerGetPageReply) error {
var err error
err = e.Orm.Table("org_player as op").
Select("op.id,op.player_name,op.player_number,op.player_img,op.position,op.sex,op.status").
Scopes(
cDto.PassDel("op"),
).
Where("op.team_id=?", teamId).
Find(list).Error
if err != nil {
e.Log.Errorf("OrgPlayerService GetPage error:%s \r\n", err)
return err
}
return nil
}
// GetPage 获取OrgMatchEvaluate列表
func (e *OrgPlayerRank) GetRankTeamInfo(teamId string, seasonId string, data *dto.OrgPlayerRankInfoGetReply) error {
var err error
list := make([]dto.OrgPlayerRankGetPageReply, 0)
err = e.Orm.Table("org_match_team_player as omtp").
Select("omtp.team_id as id,"+
"sum(omtp.scoring)as scoring,"+
"sum(omtp.rebound)as rebound,"+
"sum(omtp.assist)as assist,"+
"sum(omtp.steal)as steal,"+
"sum(omtp.free_throw)as free_throw,"+
"sum(omtp.block_shot)as block_shot,"+
"sum(omtp.foul)as foul,"+
"sum(omtp.two_point_shot)as two_point_shot,"+
"sum(omtp.three_point_shot)as three_point_shot").
Joins("left join org_match as om on omtp.match_id = om.id and omtp.rounds = om.rounds").
Scopes(
cDto.PassDel("omtp"),
cDto.SetWhere("om", "season_id", seasonId),
).
Group("omtp.team_id").
Find(&list).Error
if err != nil {
e.Log.Errorf("OrgClubPlayer GetPage error:%s \r\n", err)
return err
}
e.rankingScoring(&list)
for _, v := range list {
if v.Id == teamId {
data.ScoringRank = v.Rank
}
}
e.rankingRebound(&list)
for _, v := range list {
if v.Id == teamId {
data.ReboundRank = v.Rank
}
}
e.rankingSteal(&list)
for _, v := range list {
if v.Id == teamId {
data.ScoringRank = v.Rank
}
}
e.rankingFreeThrow(&list)
for _, v := range list {
if v.Id == teamId {
data.FreeThrowRank = v.Rank
}
}
e.rankingBlockShot(&list)
for _, v := range list {
if v.Id == teamId {
data.BlockShotRank = v.Rank
}
}
e.rankingFoul(&list)
for _, v := range list {
if v.Id == teamId {
data.FoulRank = v.Rank
}
}
e.rankingTwoPointShot(&list)
for _, v := range list {
if v.Id == teamId {
data.TwoPointShotRank = v.Rank
}
}
e.rankingThreePointShot(&list)
for _, v := range list {
if v.Id == teamId {
data.ThreePointShotRank = v.Rank
}
}
return nil
}
func (e *OrgPlayerRank) rankingScoring(list *[]dto.OrgPlayerRankGetPageReply) { func (e *OrgPlayerRank) rankingScoring(list *[]dto.OrgPlayerRankGetPageReply) {
listData := *list listData := *list
sort.Slice(listData, func(i, j int) bool { sort.Slice(listData, func(i, j int) bool {
......
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