org_team_match_evaluate.go 6.31 KB
Newer Older
haoyanbin's avatar
haoyanbin committed
1 2 3
package apis

import (
haoyanbin's avatar
haoyanbin committed
4
	"fmt"
haoyanbin's avatar
1  
haoyanbin committed
5 6
	cDto "go-admin/common/dto"
	"strconv"
haoyanbin's avatar
haoyanbin committed
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

	"github.com/gin-gonic/gin"
	"github.com/go-admin-team/go-admin-core/sdk/api"
	"github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth/user"
	_ "github.com/go-admin-team/go-admin-core/sdk/pkg/response"

	"go-admin/app/operate/service"
	"go-admin/app/operate/service/dto"
	"go-admin/common/actions"
)

type OrgTeamMatchEvaluate struct {
	api.Api
}

haoyanbin's avatar
1  
haoyanbin committed
22 23 24 25 26 27 28
func (e OrgTeamMatchEvaluate) getTeamId(c *gin.Context) string {
	sOrgTeamUser := service.OrgTeamUser{}
	e.MakeContext(c).MakeOrm().MakeService(&sOrgTeamUser.Service)
	_, teamId := sOrgTeamUser.GetTeamId(user.GetUserId(c))
	return teamId
}

haoyanbin's avatar
haoyanbin committed
29 30 31 32 33 34 35 36 37 38
// GetPage <球队>教练评价列表
// @Summary <球队>教练评价列表
// @Description <球队>教练评价列表
// @Tags <球队>教练评价
// @Param pageSize query int false "页条数"
// @Param pageIndex query int false "页码"
// @Success 200 {string} string  "{"code": 200, "data": [...]}"
// @Router /api/v1/org-team-match-evaluate [get]
// @Security Bearer
func (e OrgTeamMatchEvaluate) GetPage(c *gin.Context) {
haoyanbin's avatar
haoyanbin committed
39 40
	req := dto.OrgTeamMatchEvaluateGetPageReq{}
	s := service.OrgTeamMatchEvaluate{}
haoyanbin's avatar
haoyanbin committed
41 42 43 44 45 46 47 48 49 50
	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
	}
haoyanbin's avatar
haoyanbin committed
51 52

	p := actions.GetPermissionFromContext(c)
haoyanbin's avatar
haoyanbin committed
53
	list := make([]dto.OrgTeamMatchEvaluateGetPageReply, 0)
haoyanbin's avatar
haoyanbin committed
54 55
	var count int64

haoyanbin's avatar
1  
haoyanbin committed
56
	req.TeamId = e.getTeamId(c)
haoyanbin's avatar
haoyanbin committed
57

haoyanbin's avatar
haoyanbin committed
58 59 60
	err = s.GetPage(&req, p, &list, &count)
	if err != nil {
		e.Error(500, err, fmt.Sprintf("获取比赛球员信息 失败,\r\n失败信息 %s", err.Error()))
haoyanbin's avatar
haoyanbin committed
61
		return
haoyanbin's avatar
haoyanbin committed
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
	}

	e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
}

// GetPage <球队>教练评价比赛列表
// @Summary <球队>教练评价比赛列表
// @Description <球队>教练评价比赛列表
// @Tags <球队>教练评价
// @Param pageSize query int false "页条数"
// @Param pageIndex query int false "页码"
// @Success 200 {string} string  "{"code": 200, "data": [...]}"
// @Router /api/v1/org-team-match-evaluate/get-match [get]
// @Security Bearer
func (e OrgTeamMatchEvaluate) GetPageMatch(c *gin.Context) {
haoyanbin's avatar
haoyanbin committed
77 78
	req := dto.GetPageTeamMatchReq{}
	s := service.OrgTeamMatchEvaluate{}
haoyanbin's avatar
haoyanbin committed
79 80 81 82 83 84 85 86 87 88 89 90
	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
	}

	p := actions.GetPermissionFromContext(c)
haoyanbin's avatar
haoyanbin committed
91
	reply := new(dto.GetPageTeamMatchReply)
haoyanbin's avatar
haoyanbin committed
92

haoyanbin's avatar
1  
haoyanbin committed
93 94
	replyGetMatchInfo := new(cDto.PageMatchInfo)
	err = s.GetMatchInfo(req.Id, p, replyGetMatchInfo)
haoyanbin's avatar
haoyanbin committed
95 96 97 98
	if err != nil {
		e.Error(500, err, fmt.Sprintf("获取比赛球员信息 失败,\r\n失败信息 %s", err.Error()))
		return
	}
haoyanbin's avatar
1  
haoyanbin committed
99
	reply.MatchInfo = *replyGetMatchInfo
haoyanbin's avatar
haoyanbin committed
100

haoyanbin's avatar
1  
haoyanbin committed
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
	replyGetRoundsScoring := make([]cDto.RoundsScoring, 0)
	err = s.GetRoundsScoring(replyGetMatchInfo.PlayerId, replyGetMatchInfo.Rounds, "0", &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, "查询成功")
haoyanbin's avatar
haoyanbin committed
118 119 120 121 122 123 124 125
}

// Get <球队>教练评价比赛详情
// @Summary <球队>教练评价比赛详情
// @Description <球队>教练评价比赛详情
// @Tags <球队>教练评价
// @Param id path string false "id"
// @Success 200 {string} string  "{"code": 200, "data": [...]}"
haoyanbin's avatar
haoyanbin committed
126
// @Router /api/v1/org-team-match-evaluate/{id} [get]
haoyanbin's avatar
haoyanbin committed
127 128 129 130
// @Security Bearer
func (e OrgTeamMatchEvaluate) Get(c *gin.Context) {
	req := dto.OrgMatchEvaluateGetReq{}
	s := service.OrgMatchEvaluate{}
haoyanbin's avatar
haoyanbin committed
131
	err := e.MakeContext(c).
haoyanbin's avatar
haoyanbin committed
132 133 134 135 136 137 138 139 140 141 142
		MakeOrm().
		Bind(&req).
		MakeService(&s.Service).
		Errors
	if err != nil {
		e.Logger.Error(err)
		e.Error(500, err, err.Error())
		return
	}

	p := actions.GetPermissionFromContext(c)
haoyanbin's avatar
1  
haoyanbin committed
143 144 145 146 147 148 149 150 151 152 153 154 155

	reply := new(dto.OrgMatchEvaluateGetReply)

	replyGetMatchInfo := new(cDto.PageMatchInfo)
	err = s.GetMatchInfo(strconv.Itoa(req.Id), p, replyGetMatchInfo)
	if err != nil {
		e.Error(500, err, fmt.Sprintf("获取比赛球员信息 失败,\r\n失败信息 %s", err.Error()))
		return
	}
	reply.MatchInfo = *replyGetMatchInfo

	replyGetRoundsScoring := make([]cDto.RoundsScoring, 0)
	err = s.GetRoundsScoring(replyGetMatchInfo.PlayerId, replyGetMatchInfo.Rounds, strconv.Itoa(req.Id), &replyGetRoundsScoring)
haoyanbin's avatar
haoyanbin committed
156
	if err != nil {
haoyanbin's avatar
1  
haoyanbin committed
157
		e.Error(500, err, fmt.Sprintf("获取比赛球员信息 失败,\r\n失败信息 %s", err.Error()))
haoyanbin's avatar
haoyanbin committed
158
		return
haoyanbin's avatar
haoyanbin committed
159
	}
haoyanbin's avatar
1  
haoyanbin committed
160
	reply.RoundsScoring = replyGetRoundsScoring
haoyanbin's avatar
haoyanbin committed
161

haoyanbin's avatar
1  
haoyanbin committed
162
	e.OK(reply, "查询成功")
haoyanbin's avatar
haoyanbin committed
163 164 165 166 167 168 169 170
}

// Update <球队>修改评价
// @Summary <球队>修改评价
// @Description <球队>修改评价
// @Tags <球队>教练评价
// @Accept application/json
// @Product application/json
haoyanbin's avatar
haoyanbin committed
171
// @Param data body dto.OrgTeamMatchEvaluateUpdateReq true "body"
haoyanbin's avatar
haoyanbin committed
172
// @Success 200 {string} string  	"{"code": 200, "message": "修改成功"}"
haoyanbin's avatar
haoyanbin committed
173
// @Router /api/v1/org-team-match-evaluate/{id} [put]
haoyanbin's avatar
haoyanbin committed
174 175
// @Security Bearer
func (e OrgTeamMatchEvaluate) Update(c *gin.Context) {
haoyanbin's avatar
haoyanbin committed
176 177
	req := dto.OrgTeamMatchEvaluateUpdateReq{}
	s := service.OrgTeamMatchEvaluate{}
haoyanbin's avatar
haoyanbin committed
178 179 180 181 182 183 184 185 186 187
	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
	}
haoyanbin's avatar
haoyanbin committed
188 189 190
	req.SetUpdateBy(user.GetUserId(c))
	p := actions.GetPermissionFromContext(c)

haoyanbin's avatar
haoyanbin committed
191 192 193 194 195 196
	if req.MatchId == "" || req.Rounds == "" || req.PlayerId == "" {
		e.Logger.Error(err)
		e.Error(500, err, "数据有误")
		return
	}

haoyanbin's avatar
1  
haoyanbin committed
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
	err, playerId := s.IsBeing(req.MatchId, req.Rounds, req.PlayerId)
	eId := 0
	if playerId == 0 {
		reqInsertData := dto.OrgMatchEvaluateInsertReq{
			MatchId:       req.MatchId,
			Rounds:        req.Rounds,
			PlayerId:      req.PlayerId,
			Content:       req.Content,
			ContentStatus: req.ContentStatus,
		}
		err, eId = s.Insert(&reqInsertData)
	} else {
		err, eId = s.Update(&req, p)
	}
	fmt.Println(eId)
haoyanbin's avatar
haoyanbin committed
212 213
	if err != nil {
		e.Error(500, err, fmt.Sprintf("修改比赛球员信息 失败,\r\n失败信息 %s", err.Error()))
haoyanbin's avatar
haoyanbin committed
214
		return
haoyanbin's avatar
haoyanbin committed
215
	}
haoyanbin's avatar
1  
haoyanbin committed
216

haoyanbin's avatar
haoyanbin committed
217
	e.OK(req.GetId(), "修改成功")
haoyanbin's avatar
haoyanbin committed
218
}