From 1539b3c70bea790fe97a87a305389b45e8f9357a Mon Sep 17 00:00:00 2001
From: haoyanbin <605649647@qq.com>
Date: Sat, 15 Jan 2022 17:30:36 +0800
Subject: [PATCH] 1

---
 app/operate/apis/org_team_team.go             | 33 +++++++++---
 app/operate/service/org_club_team.go          |  5 +-
 app/operate/service/org_match_evaluate.go     |  1 +
 app/operate/service/org_team_match.go         |  1 +
 .../service/org_team_match_evaluate.go        |  1 +
 app/operate/service/org_team_player.go        |  1 +
 app/operate/service/org_team_team.go          | 50 ++++++++++---------
 app/operate/service/org_team_user.go          |  1 +
 8 files changed, 59 insertions(+), 34 deletions(-)

diff --git a/app/operate/apis/org_team_team.go b/app/operate/apis/org_team_team.go
index 77da1df..39c20a0 100644
--- a/app/operate/apis/org_team_team.go
+++ b/app/operate/apis/org_team_team.go
@@ -2,6 +2,8 @@ package apis
 
 import (
 	"fmt"
+	cDto "go-admin/common/dto"
+	"strconv"
 
 	"github.com/gin-gonic/gin"
 	"github.com/go-admin-team/go-admin-core/sdk/api"
@@ -62,8 +64,8 @@ func (e OrgTeamTeam) GetPage(c *gin.Context) {
 // @Router /api/v1/org-team-team/get-match [get]
 // @Security Bearer
 func (e OrgTeamTeam) GetPageMatch(c *gin.Context) {
-	req := dto.OrgTeamGetPageReq{}
-	s := service.OrgTeam{}
+	req := dto.GetPageMatchTeamTeamReq{}
+	s := service.OrgTeamTeam{}
 	err := e.MakeContext(c).
 		MakeOrm().
 		Bind(&req).
@@ -76,16 +78,33 @@ func (e OrgTeamTeam) GetPageMatch(c *gin.Context) {
 	}
 
 	p := actions.GetPermissionFromContext(c)
-	list := make([]dto.OrgTeamGetPageReply, 0)
-	var count int64
+	reply := new(dto.GetPageMatchReply)
 
-	err = s.GetPage(&req, p, &list, &count)
+	replyGetMatchInfo := new(cDto.PageMatchInfo)
+	err = s.GetMatchInfo(strconv.Itoa(req.TeamId), p, replyGetMatchInfo)
 	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
 	}
+	reply.MatchInfo = *replyGetMatchInfo
 
-	e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
+	replyGetRoundsScoring := make([]cDto.RoundsScoring, 0)
+	err = s.GetRoundsScoring(replyGetMatchInfo.PlayerId, replyGetMatchInfo.Rounds, &replyGetRoundsScoring)
+	if err != nil {
+		e.Error(500, err, fmt.Sprintf("获取比赛球员信息 失败,\r\n失败信息 %s", err.Error()))
+		return
+	}
+	reply.RoundsScoring = replyGetRoundsScoring
+
+	replyGetTotalScoring := make([]cDto.TotalScoring, 0)
+	err = s.GetTotalScoring(replyGetMatchInfo.PlayerId, replyGetMatchInfo.Rounds, replyGetMatchInfo.SeasonId, &replyGetTotalScoring)
+	if err != nil {
+		e.Error(500, err, fmt.Sprintf("获取比赛球员信息 失败,\r\n失败信息 %s", err.Error()))
+		return
+	}
+	reply.TotalScoring = replyGetTotalScoring
+
+	e.OK(reply, "查询成功")
 }
 
 // Get <球队>获取球队表现比赛详情
diff --git a/app/operate/service/org_club_team.go b/app/operate/service/org_club_team.go
index 0fcd494..9b562d0 100644
--- a/app/operate/service/org_club_team.go
+++ b/app/operate/service/org_club_team.go
@@ -35,7 +35,7 @@ func (e *OrgClubTeam) GetPage(c *dto.OrgClubTeamGetPageReq, p *actions.DataPermi
 			cDto.MakeCondition(c.GetNeedSearch()),
 			cDto.Paginate(c.GetPageSize(), c.GetPageIndex()),
 			actions.Permission(data.TableName(), p),
-			cDto.PassDel("ompt"),
+			cDto.PassDel("omtp"),
 		).
 		Group("omtp.team_id").
 		Find(list).Limit(-1).Offset(-1).
@@ -132,7 +132,6 @@ func (e *OrgClubTeam) statisticsScoring(teamId string, rounds string, seasonId s
 	var err error
 	field := ""
 
-	//if statistics == "sum" {
 	field += "sum(omtp.scoring)as scoring," +
 		"sum(omtp.rebound)as rebound," +
 		"sum(omtp.assist)as assist," +
@@ -142,7 +141,6 @@ func (e *OrgClubTeam) statisticsScoring(teamId string, rounds string, seasonId s
 		"sum(omtp.foul)as foul," +
 		"sum(omtp.two_point_shot)as two_point_shot," +
 		"sum(omtp.three_point_shot)as three_point_shot"
-	//}
 
 	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").
@@ -158,7 +156,6 @@ func (e *OrgClubTeam) statisticsScoring(teamId string, rounds string, seasonId s
 			Select(field).
 			Scopes(cDto.SetWhere("om", "season_id", seasonId)).
 			Count(&teamCount).Error
-		//_, _, teamCount := e.GetPageForTeam(seasonId)
 
 		data.Scoring = utils.GetAvg(data.Scoring, teamCount)
 		data.Rebound = utils.GetAvg(data.Rebound, teamCount)
diff --git a/app/operate/service/org_match_evaluate.go b/app/operate/service/org_match_evaluate.go
index 152ad4d..a48bf28 100644
--- a/app/operate/service/org_match_evaluate.go
+++ b/app/operate/service/org_match_evaluate.go
@@ -32,6 +32,7 @@ func (e *OrgMatchEvaluate) GetPage(c *dto.OrgMatchEvaluateGetPageReq, p *actions
 			cDto.MakeCondition(c.GetNeedSearch()),
 			cDto.Paginate(c.GetPageSize(), c.GetPageIndex()),
 			actions.Permission("omtp", p),
+			cDto.PassDel("omtp"),
 		).
 		Find(list).Limit(-1).Offset(-1).
 		Count(count).Error
diff --git a/app/operate/service/org_team_match.go b/app/operate/service/org_team_match.go
index 5061f09..3b25392 100644
--- a/app/operate/service/org_team_match.go
+++ b/app/operate/service/org_team_match.go
@@ -34,6 +34,7 @@ func (e *OrgTeamMatch) GetPage(c *dto.OrgTeamMatchGetPageReq, p *actions.DataPer
 			cDto.MakeCondition(c.GetNeedSearch()),
 			cDto.Paginate(c.GetPageSize(), c.GetPageIndex()),
 			actions.Permission(data.TableName(), p),
+			cDto.PassDel("om"),
 		).
 		Find(list).Limit(-1).Offset(-1).
 		Count(count).Error
diff --git a/app/operate/service/org_team_match_evaluate.go b/app/operate/service/org_team_match_evaluate.go
index adad2d4..982bbbd 100644
--- a/app/operate/service/org_team_match_evaluate.go
+++ b/app/operate/service/org_team_match_evaluate.go
@@ -32,6 +32,7 @@ func (e *OrgTeamMatchEvaluate) GetPage(c *dto.OrgMatchEvaluateGetPageReq, p *act
 			cDto.MakeCondition(c.GetNeedSearch()),
 			cDto.Paginate(c.GetPageSize(), c.GetPageIndex()),
 			actions.Permission("omtp", p),
+			cDto.PassDel("omtp"),
 		).
 		Find(list).Limit(-1).Offset(-1).
 		Count(count).Error
diff --git a/app/operate/service/org_team_player.go b/app/operate/service/org_team_player.go
index 880701c..b32c19d 100644
--- a/app/operate/service/org_team_player.go
+++ b/app/operate/service/org_team_player.go
@@ -30,6 +30,7 @@ func (e *OrgTeamPlayer) GetPage(c *dto.OrgTeamPlayerGetPageReq, p *actions.DataP
 			cDto.MakeCondition(c.GetNeedSearch()),
 			cDto.Paginate(c.GetPageSize(), c.GetPageIndex()),
 			actions.Permission("omtp", p),
+			cDto.PassDel("omtp"),
 		).
 		Find(list).Limit(-1).Offset(-1).
 		Count(count).Error
diff --git a/app/operate/service/org_team_team.go b/app/operate/service/org_team_team.go
index 1a2b83a..5c5e8b3 100644
--- a/app/operate/service/org_team_team.go
+++ b/app/operate/service/org_team_team.go
@@ -35,6 +35,7 @@ func (e *OrgTeamTeam) GetPage(c *dto.OrgTeamTeamGetPageReq, p *actions.DataPermi
 			cDto.MakeCondition(c.GetNeedSearch()),
 			cDto.Paginate(c.GetPageSize(), c.GetPageIndex()),
 			actions.Permission(data.TableName(), p),
+			cDto.PassDel("omtp"),
 		).
 		Group("omtp.team_id").
 		Find(list).Limit(-1).Offset(-1).
@@ -131,17 +132,15 @@ func (e *OrgTeamTeam) statisticsScoring(teamId string, rounds string, seasonId s
 	var err error
 	field := ""
 
-	if statistics == "sum" {
-		field += "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"
-	}
+	field += "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"
 
 	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").
@@ -151,7 +150,12 @@ func (e *OrgTeamTeam) statisticsScoring(teamId string, rounds string, seasonId s
 		First(data).Error
 
 	if statistics == "avg" {
-		_, _, teamCount := e.GetPageForTeam(seasonId)
+		var teamCount int64 = 0
+		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").
+			Select(field).
+			Scopes(cDto.SetWhere("om", "season_id", seasonId)).
+			Count(&teamCount).Error
 
 		data.Scoring = utils.GetAvg(data.Scoring, teamCount)
 		data.Rebound = utils.GetAvg(data.Rebound, teamCount)
@@ -222,7 +226,7 @@ func (e *OrgTeamTeam) rankingScoring(replyGetPlayerRank []models.OrgMatchTeamPla
 		return replyGetPlayerRank[i].Scoring > replyGetPlayerRank[j].Scoring
 	})
 	for k, v := range replyGetPlayerRank {
-		if v.PlayerId == playerId {
+		if v.TeamId == playerId {
 			scoring.Scoring = strconv.Itoa(k + 1)
 		}
 	}
@@ -232,7 +236,7 @@ func (e *OrgTeamTeam) rankingRebound(replyGetPlayerRank []models.OrgMatchTeamPla
 		return replyGetPlayerRank[i].Rebound > replyGetPlayerRank[j].Rebound
 	})
 	for k, v := range replyGetPlayerRank {
-		if v.PlayerId == playerId {
+		if v.TeamId == playerId {
 			scoring.Rebound = strconv.Itoa(k + 1)
 		}
 	}
@@ -242,7 +246,7 @@ func (e *OrgTeamTeam) rankingAssist(replyGetPlayerRank []models.OrgMatchTeamPlay
 		return replyGetPlayerRank[i].Assist > replyGetPlayerRank[j].Assist
 	})
 	for k, v := range replyGetPlayerRank {
-		if v.PlayerId == playerId {
+		if v.TeamId == playerId {
 			scoring.Assist = strconv.Itoa(k + 1)
 		}
 	}
@@ -252,7 +256,7 @@ func (e *OrgTeamTeam) rankingSteal(replyGetPlayerRank []models.OrgMatchTeamPlaye
 		return replyGetPlayerRank[i].Steal > replyGetPlayerRank[j].Steal
 	})
 	for k, v := range replyGetPlayerRank {
-		if v.PlayerId == playerId {
+		if v.TeamId == playerId {
 			scoring.Steal = strconv.Itoa(k + 1)
 		}
 	}
@@ -262,7 +266,7 @@ func (e *OrgTeamTeam) rankingFreeThrow(replyGetPlayerRank []models.OrgMatchTeamP
 		return replyGetPlayerRank[i].FreeThrow > replyGetPlayerRank[j].FreeThrow
 	})
 	for k, v := range replyGetPlayerRank {
-		if v.PlayerId == playerId {
+		if v.TeamId == playerId {
 			scoring.FreeThrow = strconv.Itoa(k + 1)
 		}
 	}
@@ -272,7 +276,7 @@ func (e *OrgTeamTeam) rankingBlockShot(replyGetPlayerRank []models.OrgMatchTeamP
 		return replyGetPlayerRank[i].BlockShot > replyGetPlayerRank[j].BlockShot
 	})
 	for k, v := range replyGetPlayerRank {
-		if v.PlayerId == playerId {
+		if v.TeamId == playerId {
 			scoring.BlockShot = strconv.Itoa(k + 1)
 		}
 	}
@@ -282,7 +286,7 @@ func (e *OrgTeamTeam) rankingFoul(replyGetPlayerRank []models.OrgMatchTeamPlayer
 		return replyGetPlayerRank[i].Foul > replyGetPlayerRank[j].Foul
 	})
 	for k, v := range replyGetPlayerRank {
-		if v.PlayerId == playerId {
+		if v.TeamId == playerId {
 			scoring.Foul = strconv.Itoa(k + 1)
 		}
 	}
@@ -292,7 +296,7 @@ func (e *OrgTeamTeam) rankingTwoPointShot(replyGetPlayerRank []models.OrgMatchTe
 		return replyGetPlayerRank[i].TwoPointShot > replyGetPlayerRank[j].TwoPointShot
 	})
 	for k, v := range replyGetPlayerRank {
-		if v.PlayerId == playerId {
+		if v.TeamId == playerId {
 			scoring.TwoPointShot = strconv.Itoa(k + 1)
 		}
 	}
@@ -302,7 +306,7 @@ func (e *OrgTeamTeam) rankingThreePointShot(replyGetPlayerRank []models.OrgMatch
 		return replyGetPlayerRank[i].ThreePointShot > replyGetPlayerRank[j].ThreePointShot
 	})
 	for k, v := range replyGetPlayerRank {
-		if v.PlayerId == playerId {
+		if v.TeamId == playerId {
 			scoring.ThreePointShot = strconv.Itoa(k + 1)
 		}
 	}
@@ -310,7 +314,7 @@ func (e *OrgTeamTeam) rankingThreePointShot(replyGetPlayerRank []models.OrgMatch
 
 func (e *OrgTeamTeam) statisticsRanking(seasonId string, data *[]models.OrgMatchTeamPlayer) error {
 	var err error
-	field := "team_id," +
+	field := "omtp.team_id," +
 		"sum(omtp.scoring)as scoring," +
 		"sum(omtp.rebound)as rebound," +
 		"sum(omtp.assist)as assist," +
@@ -324,7 +328,7 @@ func (e *OrgTeamTeam) statisticsRanking(seasonId string, data *[]models.OrgMatch
 		Select(field).
 		Joins("left join org_match as om on omtp.match_id = om.id and omtp.rounds = om.rounds").
 		Where("om.season_id = ?", seasonId).
-		Group("team_id").
+		Group("omtp.team_id").
 		Find(&data).Error
 
 	if err != nil {
diff --git a/app/operate/service/org_team_user.go b/app/operate/service/org_team_user.go
index 1511564..03dfe46 100644
--- a/app/operate/service/org_team_user.go
+++ b/app/operate/service/org_team_user.go
@@ -33,6 +33,7 @@ func (e *OrgTeamUser) GetPage(c *dto.OrgTeamUserGetPageReq, p *actions.DataPermi
 			cDto.MakeCondition(c.GetNeedSearch()),
 			cDto.Paginate(c.GetPageSize(), c.GetPageIndex()),
 			actions.Permission(data.TableName(), p),
+			cDto.PassDel("otu"),
 		).
 		Find(list).Limit(-1).Offset(-1).
 		Count(count).Error
-- 
2.18.1