From 568ceeeb80839deb057ec69d2c443cb09d10a19b Mon Sep 17 00:00:00 2001 From: virus Date: Thu, 28 Nov 2019 10:25:51 +0800 Subject: [PATCH] =?UTF-8?q?[FIX]b=E7=AB=AF=E6=8E=A5=E5=8F=A3=E8=81=94?= =?UTF-8?q?=E8=B0=83=E4=B8=80=E4=BA=9Bbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- conf/config.toml | 2 +- main.go | 2 +- models/League.go | 2 +- models/dota2/Team.go | 11 ++++++++ modules/league/CurdLeague.go | 4 +-- modules/series/CurdSeries.go | 51 +++++++++++++++++++++--------------- modules/series/CurlSeries.go | 14 ++++++++++ util/Request.go | 2 +- 8 files changed, 61 insertions(+), 27 deletions(-) diff --git a/conf/config.toml b/conf/config.toml index 7cca6c9..6e00d6d 100644 --- a/conf/config.toml +++ b/conf/config.toml @@ -2,7 +2,7 @@ port="8080" debug=true env="production" -risewinter_url="http://apiv2-staging.risewinter.com:8080" +risewinter_url="http://bapi.stage.risewinter.cn" risewinter_tenant_id=2 white_ip="127.0.0.1,192.168.31.189,13.250.10.109,3.0.200.71" private_key_path="rsa/private_key.pem" diff --git a/main.go b/main.go index beab537..86d8892 100644 --- a/main.go +++ b/main.go @@ -45,8 +45,8 @@ func main() { // 日志初始化 log.Init() - log.Info("xxxxx") go initialize.InitData(5) + e.Logger.Fatal(e.Start(":" + util.Config.PORT)) } diff --git a/models/League.go b/models/League.go index c44d67b..c763987 100644 --- a/models/League.go +++ b/models/League.go @@ -14,7 +14,7 @@ type League struct { Alias []string `json:"alias"` // 联赛别名 Logo string `json:"logo"` // 联赛logo Organizer string `json:"organizer"` // 联赛组织者 - Level int `json:"lever"` // 联赛等级 + Level string `json:"lever"` // 联赛等级 Local string `json:"local"` // 联赛地区 LimitTeam int `json:"limit_team"` // 联赛队伍数量 Description string `json:"description"` // 联赛简介 diff --git a/models/dota2/Team.go b/models/dota2/Team.go index c61e86f..4213fb2 100644 --- a/models/dota2/Team.go +++ b/models/dota2/Team.go @@ -1,5 +1,7 @@ package dota2 +import "encoding/json" + // dota2队伍信息 type Team struct { Name string `json:"name"` // 队伍名称 @@ -18,3 +20,12 @@ type Team struct { BanRwRoleIDs []int64 `json:"bans_rw_role_ids"` // 队伍被禁英雄ID数组 Players []Player `json:"players"` // 队伍队员比赛数据 } + +func (t *Team) FromDB(bytes []byte) error { + return json.Unmarshal(bytes, t) +} + +func (t *Team) ToDB() (bytes []byte, err error) { + bytes, err = json.Marshal(t) + return +} diff --git a/modules/league/CurdLeague.go b/modules/league/CurdLeague.go index 4379070..0261a6e 100644 --- a/modules/league/CurdLeague.go +++ b/modules/league/CurdLeague.go @@ -18,7 +18,7 @@ type League struct { Alias []string `json:"alias"` Logo string `json:"logo"` Organizer string `json:"organizer"` - Level int `json:"level"` + Level string `json:"level"` Local string `json:"local"` RwGameID int64 `json:"game_id"` RwAreaID int64 `json:"area_id"` @@ -144,4 +144,4 @@ func (league *League) BuildLeague(buildLeague models.League) (builderLeague mode buildLeague.Description = league.Description return buildLeague, nil -} \ No newline at end of file +} diff --git a/modules/series/CurdSeries.go b/modules/series/CurdSeries.go index b402626..456308c 100644 --- a/modules/series/CurdSeries.go +++ b/modules/series/CurdSeries.go @@ -41,6 +41,7 @@ func FindSeriesByRwID(rwID int64) (findSeries models.Series, findErr error) { if has, err := util.Engine.Where("rw_id = ?", rwID).Desc("id").Get(&findSeries); err != nil || !has { findErr = errors.New("系列赛不存在!") + go InitSeriesDetailData(rwID) return } @@ -95,12 +96,9 @@ func (series *Series) CreateSeries() (createdSeries models.Series, createErr err if fCourse, findErr := course.FindCourseByRwID(series.RwCourseID); findErr == nil { // 找到赛事 if series.Course.RwID > 0 { - var buildCourse models.Course - var updatedCourse models.Course - buildCourse.ID = fCourse.ID - if updatedCourse, createErr = series.Course.BuildCourse(buildCourse); createErr == nil { + if fCourse, createErr = series.Course.BuildCourse(fCourse); createErr == nil { // 参数正常,提交到session - if i, err := session.ID(updatedCourse.ID).Update(&updatedCourse); err != nil || i != 1 { + if i, err := session.ID(fCourse.ID).Update(&fCourse); err != nil || i != 1 { createErr = errors.New(fmt.Sprintf("系列赛关联赛事更新失败: %v", err)) _ = session.Rollback() return @@ -113,11 +111,9 @@ func (series *Series) CreateSeries() (createdSeries models.Series, createErr err } else { // 没找到对应的联赛 if series.Course.League.RwID > 0 { - var buildCourse models.Course - var createdCourse models.Course - if createdCourse, createErr = series.Course.BuildCourse(buildCourse); createErr == nil { + if fCourse, createErr = series.Course.BuildCourse(fCourse); createErr == nil { // 参数正常,提交到session - if _, err := session.Insert(&createdCourse); err != nil { + if _, err := session.Insert(&fCourse); err != nil { createErr = errors.New(fmt.Sprintf("系列赛关联赛事创建失败: %v", err)) _ = session.Rollback() return @@ -198,12 +194,9 @@ func (series *Series) UpdateSeries(seriesID int64) (updatedSeries models.Series, if fCourse, findErr := course.FindCourseByRwID(series.RwCourseID); findErr == nil { // 找到赛事 if series.Course.RwID > 0 { - var buildCourse models.Course - var updatedCourse models.Course - buildCourse.ID = fCourse.ID - if updatedCourse, updateErr = series.Course.BuildCourse(buildCourse); updateErr == nil { + if fCourse, updateErr = series.Course.BuildCourse(fCourse); updateErr == nil { // 参数正常,提交到session - if i, err := session.ID(updatedCourse.ID).Update(&updatedCourse); err != nil || i != 1 { + if i, err := session.ID(fCourse.ID).Update(&fCourse); err != nil || i != 1 { updateErr = errors.New(fmt.Sprintf("系列赛关联赛事更新失败: %v", err)) _ = session.Rollback() return @@ -216,11 +209,9 @@ func (series *Series) UpdateSeries(seriesID int64) (updatedSeries models.Series, } else { // 没找到对应的联赛 if series.Course.RwID > 0 { - var buildCourse models.Course - var createdCourse models.Course - if createdCourse, updateErr = series.Course.BuildCourse(buildCourse); updateErr == nil { + if fCourse, updateErr = series.Course.BuildCourse(fCourse); updateErr == nil { // 参数正常,提交到session - if _, err := session.Insert(&createdCourse); err != nil { + if _, err := session.Insert(&fCourse); err != nil { updateErr = errors.New(fmt.Sprintf("系列赛关联赛事创建失败: %v", err)) _ = session.Rollback() return @@ -241,7 +232,7 @@ func (series *Series) UpdateSeries(seriesID int64) (updatedSeries models.Series, if _, err := session.ID(updatedSeries.ID).Cols( "status", "start_time", "end_time", "season_info", "description", "info", - "game_id", "area_id").Update(&updatedSeries); err != nil { + "game_id", "area_id", "course_id", "league_id").Update(&updatedSeries); err != nil { updateErr = errors.New(fmt.Sprintf("系列赛更新失败:%v", err)) _ = session.Rollback() return @@ -292,7 +283,7 @@ func (series *Series) BuildSeries(buildSeries models.Series) (builderSeries mode } if mGame, err := game.FindGameByRwID(series.RwGameID); err != nil { - buildErr = errors.New("赛事游戏不存在!") + buildErr = errors.New("系列赛游戏不存在!") return } else { buildSeries.GameID = mGame.ID @@ -300,13 +291,31 @@ func (series *Series) BuildSeries(buildSeries models.Series) (builderSeries mode if series.RwAreaID > 0 { if mArea, err := area.FindAreaByRwID(series.RwAreaID); err != nil { - buildErr = errors.New("赛事赛区不存在!") + buildErr = errors.New("系列赛赛区不存在!") return } else { buildSeries.AreaID = mArea.ID } } + if series.RwCourseID > 0 { + if mCourse, err := course.FindCourseByRwID(series.RwCourseID); err != nil { + buildErr = errors.New("系列赛赛事不存在!") + return + } else { + buildSeries.CourseID = mCourse.ID + } + } + + if series.RwLeagueID > 0 { + if mLeague, err := course.FindCourseByRwID(series.RwLeagueID); err != nil { + buildErr = errors.New("系列赛赛事不存在!") + return + } else { + buildSeries.LeagueID = mLeague.ID + } + } + buildSeries.RwID = series.RwID buildSeries.Status = series.Status buildSeries.StartTime = series.StartTime diff --git a/modules/series/CurlSeries.go b/modules/series/CurlSeries.go index 961d86d..453384e 100644 --- a/modules/series/CurlSeries.go +++ b/modules/series/CurlSeries.go @@ -3,7 +3,9 @@ package series import ( "encoding/json" "fmt" + "gitee.com/risewinter/sheep/models" "gitee.com/risewinter/sheep/util" + "runtime" "time" ) @@ -100,6 +102,18 @@ func CurlSeriesDetailRequest(rwSeriesID int64) (seriesDetailRep DetailResponse) return } +func InitSeriesDetailData(rwSeriesID int64) { + seriesDetailRep := CurlSeriesDetailRequest(rwSeriesID) + var findSeries models.Series + if has, err := util.Engine.Where("rw_id = ?", rwSeriesID).Desc("id").Get(&findSeries); err != nil || !has { + findSeries, _ = seriesDetailRep.Result.CreateSeries() + } else { + findSeries, _ = seriesDetailRep.Result.UpdateSeries(findSeries.ID) + } + + runtime.Goexit() +} + func InitSeriesListData(rwGameID int64, rwAreaID int64, rwLeagueID int64, rwCourseID int64, beginTime int64, endTime int64, status, limit int) { var offset, total int diff --git a/util/Request.go b/util/Request.go index d6daa5f..8747095 100644 --- a/util/Request.go +++ b/util/Request.go @@ -15,7 +15,7 @@ import ( // url: 请求地址 // response:请求返回的内容 func Get(url string, params map[string]interface{}) string { - client := http.Client{Timeout: 10 * time.Second} + client := http.Client{Timeout: 30 * time.Second} // 排序后的请求参数 signString := SignString(params) // 请求的地址