[FIX]解决变量暴露的问题,尽量使用方法变量

This commit is contained in:
virus 2019-11-16 15:18:44 +08:00
parent a332676040
commit aa9c9b34a5
32 changed files with 296 additions and 335 deletions

View File

@ -36,12 +36,11 @@ func PushArea(c echo.Context) error {
// 入库处理(已经有的更新,没有的创建数据)
if findArea, findErr := area.FindAreaByRwID(swagArea.Data.RwID); findErr == nil {
// 数据存在,做更新处理
area.BuildArea.ID = findArea.ID
if updateErr := swagArea.Data.UpdateArea(); updateErr == nil {
if uArea, updateErr := swagArea.Data.UpdateArea(findArea.ID); updateErr == nil {
message := map[string]interface{}{
"code": e.UpdateAreaSuccess,
"message": e.GetMsg(e.UpdateAreaSuccess),
"data": area.BuildArea,
"data": uArea,
}
return c.JSON(http.StatusOK, message)
} else {
@ -54,11 +53,11 @@ func PushArea(c echo.Context) error {
}
} else {
// 数据不存在,做创建处理
if createErr := swagArea.Data.CreateArea(); createErr == nil {
if cArea, createErr := swagArea.Data.CreateArea(); createErr == nil {
message := map[string]interface{}{
"code": e.CreateAreaSuccess,
"message": e.GetMsg(e.CreateAreaSuccess),
"data": area.BuildArea,
"data": cArea,
}
return c.JSON(http.StatusOK, message)
} else {

View File

@ -36,12 +36,11 @@ func PushCourse(c echo.Context) error {
// 入库处理(已经有的更新,没有的创建数据)
if findCourse, findErr := course.FindCourseByRwID(swagCourse.Data.RwID); findErr == nil {
// 数据存在,做更新处理
course.BuildCourse.ID = findCourse.ID
if updateErr := swagCourse.Data.UpdateCourse(); updateErr == nil {
if uCourse, updateErr := swagCourse.Data.UpdateCourse(findCourse.ID); updateErr == nil {
message := map[string]interface{}{
"code": e.UpdateCourseSuccess,
"message": e.GetMsg(e.UpdateCourseSuccess),
"data": course.BuildCourse,
"data": uCourse,
}
return c.JSON(http.StatusOK, message)
} else {
@ -53,11 +52,11 @@ func PushCourse(c echo.Context) error {
}
} else {
// 数据不存在,做创建处理
if createErr := swagCourse.Data.CreateCourse(); createErr == nil {
if cCourse, createErr := swagCourse.Data.CreateCourse(); createErr == nil {
message := map[string]interface{}{
"code": e.CreateCourseSuccess,
"message": e.GetMsg(e.CreateCourseSuccess),
"data": course.BuildCourse,
"data": cCourse,
}
return c.JSON(http.StatusOK, message)
} else {

View File

@ -36,12 +36,11 @@ func PushEquipment(c echo.Context) error {
// 入库处理(已经有的更新,没有的创建数据)
if findEquipment, findErr := equipment.FindEquipmentByRwID(swagEquipment.Data.RwID); findErr == nil {
// 数据存在,做更新处理
equipment.BuildEquipment.ID = findEquipment.ID
if updateErr := swagEquipment.Data.UpdateEquipment(); updateErr == nil {
if uEquipment, updateErr := swagEquipment.Data.UpdateEquipment(findEquipment.ID); updateErr == nil {
message := map[string]interface{}{
"code": e.UpdateEquipmentSuccess,
"message": e.GetMsg(e.UpdateEquipmentSuccess),
"data": findEquipment,
"data": uEquipment,
}
return c.JSON(http.StatusOK, message)
} else {
@ -53,11 +52,11 @@ func PushEquipment(c echo.Context) error {
}
} else {
// 数据不存在,做创建处理
if createErr := swagEquipment.Data.CreateEquipment(); createErr == nil {
if cEquipment, createErr := swagEquipment.Data.CreateEquipment(); createErr == nil {
message := map[string]interface{}{
"code": e.CreateEquipmentSuccess,
"message": e.GetMsg(e.CreateEquipmentSuccess),
"data": equipment.BuildEquipment,
"data": cEquipment,
}
return c.JSON(http.StatusOK, message)
} else {

View File

@ -36,12 +36,11 @@ func PushLeague(c echo.Context) error {
// 入库处理(已经有的更新,没有的创建数据)
if findLeague, findErr := league.FindLeagueByRwID(swagLeague.Data.RwID); findErr == nil {
// 数据存在,做更新处理
league.BuildLeague.ID = findLeague.ID
if updateErr := swagLeague.Data.UpdateLeague(); updateErr == nil {
if uLeague, updateErr := swagLeague.Data.UpdateLeague(findLeague.ID); updateErr == nil {
message := map[string]interface{}{
"code": e.UpdateLeagueSuccess,
"message": e.GetMsg(e.UpdateLeagueSuccess),
"data": league.BuildLeague,
"data": uLeague,
}
return c.JSON(http.StatusOK, message)
} else {
@ -53,11 +52,11 @@ func PushLeague(c echo.Context) error {
}
} else {
// 数据不存在,做创建处理
if createErr := swagLeague.Data.CreateLeague(); createErr == nil {
if cLeague, createErr := swagLeague.Data.CreateLeague(); createErr == nil {
message := map[string]interface{}{
"code": e.CreateLeagueSuccess,
"message": e.GetMsg(e.CreateLeagueSuccess),
"data": league.BuildLeague,
"data": cLeague,
}
return c.JSON(http.StatusOK, message)
} else {

View File

@ -36,12 +36,11 @@ func PushRole(c echo.Context) error {
// 入库处理(已经有的更新,没有的创建数据)
if findRole, findErr := role.FindRoleByRwID(swagRole.Data.RwID); findErr == nil {
// 数据存在,做更新处理
role.BuildRole.ID = findRole.ID
if updateErr := swagRole.Data.UpdateRole(); updateErr == nil {
if uRole, updateErr := swagRole.Data.UpdateRole(findRole.ID); updateErr == nil {
message := map[string]interface{}{
"code": e.UpdateRoleSuccess,
"message": e.GetMsg(e.UpdateRoleSuccess),
"date": role.BuildRole,
"date": uRole,
}
return c.JSON(http.StatusOK, message)
} else {
@ -53,11 +52,11 @@ func PushRole(c echo.Context) error {
}
} else {
// 数据不存在,做创建处理
if createErr := swagRole.Data.CreateRole(); createErr == nil {
if cRole, createErr := swagRole.Data.CreateRole(); createErr == nil {
message := map[string]interface{}{
"code": e.CreateRoleSuccess,
"message": e.GetMsg(e.CreateRoleSuccess),
"data": role.BuildRole,
"data": cRole,
}
return c.JSON(http.StatusOK, message)
} else {

View File

@ -36,12 +36,11 @@ func PushSeries(c echo.Context) error {
// 入库处理(已经有的更新,没有的创建数据)
if findSeries, findErr := series.FindSeriesByRwID(swagSeries.Data.RwID); findErr == nil {
// 数据存在,做更新处理
series.BuildSeries.ID = findSeries.ID
if updateErr := swagSeries.Data.UpdateSeries(); updateErr == nil {
if uSeries, updateErr := swagSeries.Data.UpdateSeries(findSeries.ID); updateErr == nil {
message := map[string]interface{}{
"code": e.UpdateSeriesSuccess,
"message": e.GetMsg(e.UpdateSeriesSuccess),
"data": series.BuildSeries,
"data": uSeries,
}
return c.JSON(http.StatusOK, message)
} else {
@ -53,11 +52,11 @@ func PushSeries(c echo.Context) error {
}
} else {
// 数据不存在,做创建处理
if createErr := swagSeries.Data.CreateSeries(); createErr == nil {
if cSeries, createErr := swagSeries.Data.CreateSeries(); createErr == nil {
message := map[string]interface{}{
"code": e.CreateSeriesSuccess,
"message": e.GetMsg(e.CreateSeriesSuccess),
"data": series.BuildSeries,
"data": cSeries,
}
return c.JSON(http.StatusOK, message)
} else {

View File

@ -36,12 +36,11 @@ func PushSkill(c echo.Context) error {
// 入库处理(已经有的更新,没有的创建数据)
if findSkill, findErr := skill.FindSkillByRwID(swagSkill.Data.RwID); findErr == nil {
// 数据存在,做更新处理
skill.BuildSkill.ID = findSkill.ID
if updateErr := swagSkill.Data.UpdateSkill(); updateErr == nil {
if uSkill, updateErr := swagSkill.Data.UpdateSkill(findSkill.ID); updateErr == nil {
message := map[string]interface{}{
"code": e.UpdateSkillSuccess,
"message": e.GetMsg(e.UpdateSkillSuccess),
"data": skill.BuildSkill,
"data": uSkill,
}
return c.JSON(http.StatusOK, message)
} else {
@ -53,11 +52,11 @@ func PushSkill(c echo.Context) error {
}
} else {
// 数据不存在,做创建处理
if createErr := swagSkill.Data.CreateSkill(); createErr == nil {
if cSkill, createErr := swagSkill.Data.CreateSkill(); createErr == nil {
message := map[string]interface{}{
"code": e.CreateSkillSuccess,
"message": e.GetMsg(e.CreateSkillSuccess),
"data": skill.BuildSkill,
"data": cSkill,
}
return c.JSON(http.StatusOK, message)
} else {

View File

@ -36,12 +36,11 @@ func PushTeam(c echo.Context) error {
// 入库处理(已经有的更新,没有的创建数据)
if findTeam, findErr := team.FindTeamByRwID(swagTeam.Data.RwID); findErr == nil {
// 数据存在,做更新处理
team.BuildTeam.ID = findTeam.ID
if updateErr := swagTeam.Data.UpdateTeam(); updateErr == nil {
if uTeam, updateErr := swagTeam.Data.UpdateTeam(findTeam.ID); updateErr == nil {
message := map[string]interface{}{
"code": e.UpdateTeamSuccess,
"message": e.GetMsg(e.UpdateTeamSuccess),
"data": team.BuildTeam,
"data": uTeam,
}
return c.JSON(http.StatusOK, message)
} else {
@ -53,11 +52,11 @@ func PushTeam(c echo.Context) error {
}
} else {
// 数据不存在,做创建处理
if createErr := swagTeam.Data.CreateTeam(); createErr == nil {
if cTeam, createErr := swagTeam.Data.CreateTeam(); createErr == nil {
message := map[string]interface{}{
"code": e.CreateTeamSuccess,
"message": e.GetMsg(e.CreateTeamSuccess),
"data": team.BuildTeam,
"data": cTeam,
}
return c.JSON(http.StatusOK, message)
} else {

View File

@ -20,7 +20,7 @@ func InitData(limit int) {
return
}
player.InitPlayerListData(10)
player.InitPlayerListData(limit)
var offset, total int
@ -30,7 +30,7 @@ func InitData(limit int) {
if _, fErr := game.FindGameByRwID(item.RwID); fErr == nil {
continue
} else {
if createErr := item.CreateGame(); createErr == nil {
if _, createErr := item.CreateGame(); createErr == nil {
area.InitAreaListData(item.RwID, limit)
equipment.InitEquipmentListData(item.RwID, limit)
role.InitRoleListData(item.RwID, limit)

View File

@ -13,6 +13,10 @@ type Course struct {
EndTime int64 `json:"end_time"` // 赛事结束时间
}
func (course Course) Error() string {
panic("implement me")
}
func (Course) TableName() string {
return "courses"
}

View File

@ -15,8 +15,6 @@ type Area struct {
Description string `json:"description"`
}
var BuildArea models.Area
func FindAreaByRwID(rwID int64) (findArea models.Area, findErr error) {
if rwID <= 0 {
findErr = errors.New("赛区B端ID不能小于或者等于0")
@ -31,30 +29,30 @@ func FindAreaByRwID(rwID int64) (findArea models.Area, findErr error) {
return
}
func (area *Area) CreateArea() (createErr error) {
BuildArea.ID = 0
if createErr = area.BuildArea(); createErr != nil {
func (area *Area) CreateArea() (createdArea models.Area, createErr error) {
if createdArea, createErr = area.BuildArea(createdArea); createErr != nil {
return
}
_, createErr = util.Engine.Insert(&BuildArea)
_, createErr = util.Engine.Insert(&createdArea)
return
}
func (area *Area) UpdateArea() (updateErr error) {
if updateErr = area.BuildArea(); updateErr != nil {
func (area *Area) UpdateArea(areaID int64) (updatedArea models.Area, updateErr error) {
updatedArea.ID = areaID
if updatedArea, updateErr = area.BuildArea(updatedArea); updateErr != nil {
return
}
_, updateErr = util.Engine.ID(BuildArea.ID).Cols(
_, updateErr = util.Engine.ID(updatedArea.ID).Cols(
"game_id", "name", "area",
"description").Update(&BuildArea)
"description").Update(&updatedArea)
return
}
func (area *Area) BuildArea() (buildErr error) {
func (area *Area) BuildArea(buildArea models.Area) (builderArea models.Area, buildErr error) {
if area.RwID <= 0 {
buildErr = errors.New("B端ID不能小于或者等于0")
return
@ -74,13 +72,13 @@ func (area *Area) BuildArea() (buildErr error) {
buildErr = errors.New("赛区游戏不存在!")
return
} else {
BuildArea.GameID = mGame.ID
buildArea.GameID = mGame.ID
}
BuildArea.RwID = area.RwID
BuildArea.Name = area.Name
BuildArea.Area = area.Area
BuildArea.Description = area.Description
buildArea.RwID = area.RwID
buildArea.Name = area.Name
buildArea.Area = area.Area
buildArea.Description = area.Description
return
return buildArea, nil
}

View File

@ -53,11 +53,10 @@ func InitAreaListData(rwGameID int64, limit int) {
for _, item := range areaListRep.Result.Items {
if fArea, fErr := FindAreaByRwID(item.RwID); fErr == nil {
BuildArea.ID = fArea.ID
updateErr := item.UpdateArea()
_, updateErr := item.UpdateArea(fArea.ID)
fmt.Println(updateErr)
} else {
createErr := item.CreateArea()
_, createErr := item.CreateArea()
fmt.Println(createErr)
}
}

View File

@ -22,8 +22,6 @@ type Course struct {
League league.League `json:"league"`
}
var BuildCourse models.Course
func FindCourseByRwID(rwID int64) (findCourse models.Course, findErr error) {
if rwID <= 0 {
findErr = errors.New("赛事B端ID不能小于或者等于0")
@ -38,8 +36,7 @@ func FindCourseByRwID(rwID int64) (findCourse models.Course, findErr error) {
return
}
func (course *Course) CreateCourse() (createErr error) {
BuildCourse.ID = 0
func (course *Course) CreateCourse() (createdCourse models.Course, createErr error) {
// 开启事务
session := util.Engine.NewSession()
defer session.Close()
@ -52,10 +49,9 @@ func (course *Course) CreateCourse() (createErr error) {
if course.RwLeagueID > 0 {
if fLeague, findErr := league.FindLeagueByRwID(course.League.RwID); findErr == nil {
// 找到联赛
league.BuildLeague.ID = fLeague.ID
if createErr = course.League.BuildLeague(); createErr == nil {
if fLeague, createErr = course.League.BuildLeague(fLeague); createErr == nil {
// 参数正常提交到session
if i, err := session.ID(league.BuildLeague.ID).Update(&league.BuildLeague); err != nil || i != 1 {
if i, err := session.ID(fLeague.ID).Update(&fLeague); err != nil || i != 1 {
createErr = errors.New(fmt.Sprintf("赛事所属联赛更新失败: %v", err))
_ = session.Rollback()
return
@ -66,9 +62,9 @@ func (course *Course) CreateCourse() (createErr error) {
}
} else {
// 没找到对应的联赛
if createErr = course.League.BuildLeague(); createErr == nil {
if fLeague, createErr = course.League.BuildLeague(fLeague); createErr == nil {
// 参数正常提交到session
if _, err := session.Insert(&league.BuildLeague); err != nil {
if _, err := session.Insert(&fLeague); err != nil {
createErr = errors.New(fmt.Sprintf("赛事所属联赛创建失败: %v", err))
_ = session.Rollback()
return
@ -80,12 +76,12 @@ func (course *Course) CreateCourse() (createErr error) {
}
}
if createErr = course.BuildCourse(); createErr != nil {
if createdCourse, createErr = course.BuildCourse(createdCourse); createErr != nil {
return
}
// 创建赛事
if _, err := session.Insert(&BuildCourse); err != nil {
if _, err := session.Insert(&createdCourse); err != nil {
createErr = errors.New(fmt.Sprintf("赛事创建失败: %v", err))
_ = session.Rollback()
return
@ -100,7 +96,8 @@ func (course *Course) CreateCourse() (createErr error) {
return
}
func (course *Course) UpdateCourse() (updateErr error) {
func (course *Course) UpdateCourse(courseID int64) (updateCourse models.Course, updateErr error) {
updateCourse.ID = courseID
// 开启事务
session := util.Engine.NewSession()
defer session.Close()
@ -114,15 +111,14 @@ func (course *Course) UpdateCourse() (updateErr error) {
if course.RwLeagueID > 0 {
if fLeague, findErr := league.FindLeagueByRwID(course.League.RwID); findErr == nil {
// 找到联赛
league.BuildLeague.ID = fLeague.ID
if updateErr = course.League.BuildLeague(); updateErr == nil {
if fLeague, updateErr = course.League.BuildLeague(fLeague); updateErr == nil {
// 参数正常提交到session
if i, err := session.ID(league.BuildLeague.ID).Cols(
if i, err := session.ID(fLeague.ID).Cols(
"name", "short_name", "bonus",
"bonus_type", "alias", "logo",
"organizer", "level", "local",
"game_type", "limit_team", "description",
"game_id", "area_id").Update(&league.BuildLeague); err != nil || i != 1 {
"game_id", "area_id").Update(&fLeague); err != nil || i != 1 {
updateErr = errors.New(fmt.Sprintf("赛事所属联赛更新失败: %v", err))
_ = session.Rollback()
return
@ -133,9 +129,9 @@ func (course *Course) UpdateCourse() (updateErr error) {
}
} else {
// 没找到对应的联赛
if updateErr = course.League.BuildLeague(); updateErr == nil {
if fLeague, updateErr = course.League.BuildLeague(fLeague); updateErr == nil {
// 参数正常,提交到 session
if _, err := session.Insert(&league.BuildLeague); err != nil {
if _, err := session.Insert(&fLeague); err != nil {
updateErr = errors.New(fmt.Sprintf("赛事所属联赛创建失败: %v", err))
_ = session.Rollback()
return
@ -147,15 +143,15 @@ func (course *Course) UpdateCourse() (updateErr error) {
}
}
if updateErr = course.BuildCourse(); updateErr != nil {
if updateCourse, updateErr = course.BuildCourse(updateCourse); updateErr != nil {
return
}
// 更新赛事
if i, err := session.ID(BuildCourse.ID).Cols(
if i, err := session.ID(updateCourse.ID).Cols(
"name", "start_time", "end_time",
"description", "game_id", "league_id",
"area_id").Update(&BuildCourse); err != nil || i != 1 {
"area_id").Update(&updateCourse); err != nil || i != 1 {
updateErr = errors.New(fmt.Sprintf("赛程更新失败:%v", err))
_ = session.Rollback()
return
@ -171,7 +167,7 @@ func (course *Course) UpdateCourse() (updateErr error) {
}
func (course *Course) BuildCourse() (buildErr error) {
func (course *Course) BuildCourse(buildCourse models.Course) (builderCourse models.Course, buildErr error) {
if course.RwID <= 0 {
buildErr = errors.New("赛事B端ID不能小于或者等于0")
return
@ -196,7 +192,7 @@ func (course *Course) BuildCourse() (buildErr error) {
buildErr = errors.New("赛事游戏不存在!")
return
} else {
BuildCourse.GameID = mGame.ID
buildCourse.GameID = mGame.ID
}
if course.RwLeagueID > 0 {
@ -204,7 +200,7 @@ func (course *Course) BuildCourse() (buildErr error) {
buildErr = errors.New("赛事联赛不存在!")
return
} else {
BuildCourse.LeagueID = mLeague.ID
buildCourse.LeagueID = mLeague.ID
}
}
@ -213,15 +209,15 @@ func (course *Course) BuildCourse() (buildErr error) {
buildErr = errors.New("赛事赛区不存在!")
return
} else {
BuildCourse.AreaID = mArea.ID
buildCourse.AreaID = mArea.ID
}
}
BuildCourse.RwID = course.RwID
BuildCourse.Name = course.Name
BuildCourse.StartTime = course.StartTime
BuildCourse.EndTime = course.EndTime
BuildCourse.Description = course.Description
buildCourse.RwID = course.RwID
buildCourse.Name = course.Name
buildCourse.StartTime = course.StartTime
buildCourse.EndTime = course.EndTime
buildCourse.Description = course.Description
return
return buildCourse, nil
}

View File

@ -37,11 +37,10 @@ func InitCourseListData(rwGameID int64, rwAreaID int64, rwLeagueID int64, limit
for _, item := range courseListRep.Result.Items {
if fCourse, fErr := FindCourseByRwID(item.RwID); fErr == nil {
BuildCourse.ID = fCourse.ID
updateErr := item.UpdateCourse()
_, updateErr := item.UpdateCourse(fCourse.ID)
fmt.Println(updateErr)
} else {
createErr := item.CreateCourse()
_, createErr := item.CreateCourse()
fmt.Println(createErr)
}
}

View File

@ -34,30 +34,30 @@ func FindEquipmentByRwID(rwID int64) (findEquipment models.Equipment, findErr er
return
}
func (equipment *Equipment) CreateEquipment() (createErr error) {
BuildEquipment.ID = 0
if createErr = equipment.BuildEquipment(); createErr != nil {
func (equipment *Equipment) CreateEquipment() (createdEquipment models.Equipment, createErr error) {
if createdEquipment, createErr = equipment.BuildEquipment(createdEquipment); createErr != nil {
return
}
_, createErr = util.Engine.Insert(&BuildEquipment)
_, createErr = util.Engine.Insert(&createdEquipment)
return
}
func (equipment *Equipment) UpdateEquipment() (updateErr error) {
if updateErr = equipment.BuildEquipment(); updateErr != nil {
func (equipment *Equipment) UpdateEquipment(equipmentID int64) (updatedEquipment models.Equipment, updateErr error) {
updatedEquipment.ID = equipmentID
if updatedEquipment, updateErr = equipment.BuildEquipment(updatedEquipment); updateErr != nil {
return
}
_, updateErr = util.Engine.ID(BuildEquipment.ID).Cols(
_, updateErr = util.Engine.ID(updatedEquipment.ID).Cols(
"name", "name_english", "alias",
"description", "icon", "game_id").Update(&BuildEquipment)
"description", "icon", "game_id").Update(&updatedEquipment)
return
}
func (equipment *Equipment) BuildEquipment() (buildErr error) {
func (equipment *Equipment) BuildEquipment(buildEquipment models.Equipment) (builderEquipment models.Equipment, buildErr error) {
if equipment.RwID <= 0 {
buildErr = errors.New("装备B端ID不能小于或者等于0")
return
@ -97,15 +97,15 @@ func (equipment *Equipment) BuildEquipment() (buildErr error) {
buildErr = errors.New("装备游戏不存在!")
return
} else {
BuildEquipment.GameID = mGame.ID
buildEquipment.GameID = mGame.ID
}
BuildEquipment.RwID = equipment.RwID
BuildEquipment.Name = equipment.Name
BuildEquipment.NameEnglish = equipment.NameEnglish
BuildEquipment.Alias = equipment.Alias
BuildEquipment.Description = equipment.Description
BuildEquipment.Icon = equipment.Icon
buildEquipment.RwID = equipment.RwID
buildEquipment.Name = equipment.Name
buildEquipment.NameEnglish = equipment.NameEnglish
buildEquipment.Alias = equipment.Alias
buildEquipment.Description = equipment.Description
buildEquipment.Icon = equipment.Icon
return
return buildEquipment, nil
}

View File

@ -54,11 +54,10 @@ func InitEquipmentListData(rwGameID int64, limit int) {
for _, item := range equipmentListRep.Result.Items {
if fEquipment, fErr := FindEquipmentByRwID(item.RwID); fErr == nil {
BuildEquipment.ID = fEquipment.ID
updateErr := item.UpdateEquipment()
_, updateErr := item.UpdateEquipment(fEquipment.ID)
fmt.Println(updateErr)
} else {
createErr := item.CreateEquipment()
_, createErr := item.CreateEquipment()
fmt.Println(createErr)
}
}

View File

@ -13,8 +13,6 @@ type Game struct {
Code string `json:"code"`
}
var BuildGame models.Game
func FindGameByRwID(rwID int64) (findGame models.Game, findErr error) {
if rwID <= 0 {
findErr = errors.New("游戏B端ID不能小于或者等于0")
@ -28,18 +26,17 @@ func FindGameByRwID(rwID int64) (findGame models.Game, findErr error) {
return
}
func (game *Game) CreateGame() (createErr error) {
BuildGame.ID = 0
if createErr = game.BuildGame(); createErr != nil {
func (game *Game) CreateGame() (createdGame models.Game, createErr error) {
if createdGame, createErr = game.BuildGame(createdGame); createErr != nil {
return
}
_, createErr = util.Engine.Insert(&BuildGame)
_, createErr = util.Engine.Insert(&createdGame)
return
}
func (game *Game) BuildGame() (buildErr error) {
func (game *Game) BuildGame(buildGame models.Game) (builderGame models.Game, buildErr error) {
if game.RwID <= 0 {
buildErr = errors.New("B端ID不能小于或者等于0")
return
@ -60,10 +57,10 @@ func (game *Game) BuildGame() (buildErr error) {
return
}
BuildGame.RwID = game.RwID
BuildGame.Name = game.Name
BuildGame.ShortName = game.ShortName
BuildGame.Code = game.Code
buildGame.RwID = game.RwID
buildGame.Name = game.Name
buildGame.ShortName = game.ShortName
buildGame.Code = game.Code
return
return buildGame, nil
}

View File

@ -27,8 +27,6 @@ type League struct {
Description string `json:"description"`
}
var BuildLeague models.League
func FindLeagueByRwID(rwID int64) (findLeague models.League, findErr error) {
if rwID <= 0 {
findErr = errors.New("联赛B端ID不能小于或者等于0")
@ -43,33 +41,33 @@ func FindLeagueByRwID(rwID int64) (findLeague models.League, findErr error) {
return
}
func (league *League)CreateLeague() (createErr error) {
BuildLeague.ID = 0
if createErr = league.BuildLeague(); createErr != nil {
func (league *League) CreateLeague() (createdLeague models.League, createErr error) {
if createdLeague, createErr = league.BuildLeague(createdLeague); createErr != nil {
return
}
_, createErr = util.Engine.Insert(&BuildLeague)
_, createErr = util.Engine.Insert(&createdLeague)
return
}
func (league *League) UpdateLeague() (updateErr error) {
if updateErr = league.BuildLeague(); updateErr != nil {
func (league *League) UpdateLeague(leagueID int64) (updatedLeague models.League, updateErr error) {
updatedLeague.ID = leagueID
if updatedLeague, updateErr = league.BuildLeague(updatedLeague); updateErr != nil {
return
}
_, updateErr = util.Engine.ID(BuildLeague.ID).Cols(
_, updateErr = util.Engine.ID(updatedLeague.ID).Cols(
"name", "short_name", "bonus",
"bonus_type", "alias", "logo",
"organizer", "level", "local",
"game_type", "limit_team", "description",
"game_id", "area_id").Update(&BuildLeague)
"game_id", "area_id").Update(&updatedLeague)
return
}
func (league *League) BuildLeague() (buildErr error) {
func (league *League) BuildLeague(buildLeague models.League) (builderLeague models.League, buildErr error) {
if league.RwID <= 0 {
buildErr = errors.New("联赛B端ID不能小于或者等于0")
return
@ -119,7 +117,7 @@ func (league *League) BuildLeague() (buildErr error) {
buildErr = errors.New("联赛游戏不存在!")
return
} else {
BuildLeague.GameID = mGame.ID
buildLeague.GameID = mGame.ID
}
if league.RwAreaID > 0 {
@ -127,23 +125,23 @@ func (league *League) BuildLeague() (buildErr error) {
buildErr = errors.New("联赛赛区不存在!")
return
} else {
BuildLeague.AreaID = mArea.ID
buildLeague.AreaID = mArea.ID
}
}
BuildLeague.RwID = league.RwID
BuildLeague.Name = league.Name
BuildLeague.ShortName = league.ShortName
BuildLeague.Bonus = league.Bonus
BuildLeague.BonusType = league.BonusType
BuildLeague.Alias = league.Alias
BuildLeague.Logo = league.Logo
BuildLeague.Organizer = league.Organizer
BuildLeague.Level = league.Level
BuildLeague.Local = league.Local
BuildLeague.GameType = league.GameType
BuildLeague.LimitTeam = league.LimitTeam
BuildLeague.Description = league.Description
buildLeague.RwID = league.RwID
buildLeague.Name = league.Name
buildLeague.ShortName = league.ShortName
buildLeague.Bonus = league.Bonus
buildLeague.BonusType = league.BonusType
buildLeague.Alias = league.Alias
buildLeague.Logo = league.Logo
buildLeague.Organizer = league.Organizer
buildLeague.Level = league.Level
buildLeague.Local = league.Local
buildLeague.GameType = league.GameType
buildLeague.LimitTeam = league.LimitTeam
buildLeague.Description = league.Description
return
return buildLeague, nil
}

View File

@ -61,11 +61,10 @@ func InitLeagueListData(rwGameID int64, rwAreaID int64, limit int) {
for _, item := range leagueListRep.Result.Items {
if fLeague, fErr := FindLeagueByRwID(item.RwID); fErr == nil {
BuildLeague.ID = fLeague.ID
updateErr := item.UpdateLeague()
_, updateErr := item.UpdateLeague(fLeague.ID)
fmt.Println(updateErr)
} else {
createErr := item.CreateLeague()
_, createErr := item.CreateLeague()
fmt.Println(createErr)
}
}

View File

@ -63,7 +63,6 @@ func FindEventByRwID(rwID int64) (findEvent lol.Event, findErr error) {
}
func (event *Event) CreateEvent() (createdEvent lol.Event, createErr error) {
var buildEvent lol.Event
var eventContent []JsonItem
if createErr = json.Unmarshal([]byte(event.MatchJson), &eventContent); createErr != nil {
return
@ -74,7 +73,7 @@ func (event *Event) CreateEvent() (createdEvent lol.Event, createErr error) {
createErr = errors.New("事件所属比赛不存在!")
return
} else {
buildEvent.MatchID = fMatch.ID
createdEvent.MatchID = fMatch.ID
}
} else {
createErr = errors.New("事件所属比赛不能为空!")
@ -86,7 +85,7 @@ func (event *Event) CreateEvent() (createdEvent lol.Event, createErr error) {
}
}
if createdEvent, createErr = event.BuildEvent(buildEvent); createErr != nil {
if createdEvent, createErr = event.BuildEvent(createdEvent); createErr != nil {
return
}
@ -96,14 +95,13 @@ func (event *Event) CreateEvent() (createdEvent lol.Event, createErr error) {
}
func (event *Event) UpdateEvent(eventID int64) (updatedEvent lol.Event, updateErr error) {
var buildEvent lol.Event
buildEvent.ID = eventID
if updatedEvent, updateErr = event.BuildEvent(buildEvent); updateErr != nil {
updatedEvent.ID = eventID
if updatedEvent, updateErr = event.BuildEvent(updatedEvent); updateErr != nil {
return
}
_, updateErr = util.Engine.ID(updatedEvent.ID).Cols(
"game", "series_id", "event_json").Update(&updatedEvent)
"game_id", "series_id", "event_json").Update(&updatedEvent)
return
}
@ -133,7 +131,5 @@ func (event *Event) BuildEvent(buildEvent lol.Event) (builderEvent lol.Event, bu
buildEvent.RwID = event.RwID
buildEvent.EventJson = event.MatchJson
builderEvent = buildEvent
return
return buildEvent, nil
}

View File

@ -95,8 +95,7 @@ func FindMatchByRwID(rwID int64) (findMatch lol.Match, findErr error) {
}
func (match *Match) CreateMatch() (createdMatch lol.Match, createErr error) {
var buildMatch lol.Match
if createdMatch, createErr = match.BuildMatch(buildMatch); createErr != nil {
if createdMatch, createErr = match.BuildMatch(createdMatch); createErr != nil {
return
}
@ -106,9 +105,8 @@ func (match *Match) CreateMatch() (createdMatch lol.Match, createErr error) {
}
func (match *Match) UpdateMatch(matchID int64) (updatedMatch lol.Match, updateErr error) {
var buildMatch lol.Match
buildMatch.ID = matchID
if updatedMatch, updateErr = match.BuildMatch(buildMatch); updateErr != nil {
updatedMatch.ID = matchID
if updatedMatch, updateErr = match.BuildMatch(updatedMatch); updateErr != nil {
return
}
@ -364,7 +362,5 @@ func (match *Match) BuildMatch(buildMatch lol.Match) (builderMatch lol.Match, bu
buildMatch.TeamDiff.GoldDiff = append(buildMatch.TeamDiff.GoldDiff, goldDiff)
builderMatch = buildMatch
return
return buildMatch, nil
}

View File

@ -16,8 +16,6 @@ type Player struct {
ExtendInfo string `json:"extend_info"`
}
var BuildPlayer models.Player
func FindPlayerByRwID(rwID int64) (findPlayer models.Player, findErr error) {
if rwID <= 0 {
findErr = errors.New("B端ID不能小于或者等于0")
@ -33,30 +31,30 @@ func FindPlayerByRwID(rwID int64) (findPlayer models.Player, findErr error) {
}
func (player *Player) CreatePlayer() (createErr error) {
BuildPlayer.ID = 0
if createErr = player.BuildPlayer(); createErr != nil {
func (player *Player) CreatePlayer() (createdPlayer models.Player, createErr error) {
if createdPlayer, createErr = player.BuildPlayer(createdPlayer); createErr != nil {
return
}
_, createErr = util.Engine.Insert(&BuildPlayer)
_, createErr = util.Engine.Insert(&createdPlayer)
return
}
func (player *Player) UpdatePlayer() (updateErr error) {
if updateErr = player.BuildPlayer(); updateErr != nil {
func (player *Player) UpdatePlayer(playeID int64) (updatedPlayer models.Player, updateErr error) {
updatedPlayer.ID = playeID
if updatedPlayer, updateErr = player.BuildPlayer(updatedPlayer); updateErr != nil {
return
}
_, updateErr = util.Engine.ID(BuildPlayer.ID).Cols(
_, updateErr = util.Engine.ID(updatedPlayer.ID).Cols(
"name", "name_english", "alias",
"description", "icon", "game_id").Update(&BuildPlayer)
"description", "icon", "game_id").Update(&updatedPlayer)
return
}
func (player *Player) BuildPlayer() (buildErr error) {
func (player *Player) BuildPlayer(buildPlayer models.Player) (builderPlayer models.Player, buildErr error) {
if player.RwID <= 0 {
buildErr = errors.New("队员B端ID不能小于或者等于0")
return
@ -82,14 +80,14 @@ func (player *Player) BuildPlayer() (buildErr error) {
// return
//}
BuildPlayer.RwID = player.RwID
BuildPlayer.Name = player.Name
BuildPlayer.NameEnglish = player.NameEnglish
BuildPlayer.Alias = player.Alias
BuildPlayer.Country = player.Country
BuildPlayer.TeamPlayerPosition = player.TeamPlayerPosition
BuildPlayer.ExtendInfo = player.ExtendInfo
buildPlayer.RwID = player.RwID
buildPlayer.Name = player.Name
buildPlayer.NameEnglish = player.NameEnglish
buildPlayer.Alias = player.Alias
buildPlayer.Country = player.Country
buildPlayer.TeamPlayerPosition = player.TeamPlayerPosition
buildPlayer.ExtendInfo = player.ExtendInfo
return
return buildPlayer, nil
}

View File

@ -78,11 +78,10 @@ func InitPlayerListData(limit int) {
for _, item := range teamListRep.Result.Items {
if fPlayer, fErr := FindPlayerByRwID(item.RwID); fErr == nil {
BuildPlayer.ID = fPlayer.ID
updateErr := item.UpdatePlayer()
_, updateErr := item.UpdatePlayer(fPlayer.ID)
fmt.Println(updateErr)
} else {
createErr := item.CreatePlayer()
_, createErr := item.CreatePlayer()
fmt.Println(createErr)
}
}

View File

@ -18,8 +18,6 @@ type Role struct {
Info string `json:"info"`
}
var BuildRole models.Role
func FindRoleByRwID(rwID int64) (findRole models.Role, findErr error) {
if rwID <= 0 {
findErr = errors.New("B端ID不能小于或者等于0")
@ -34,30 +32,30 @@ func FindRoleByRwID(rwID int64) (findRole models.Role, findErr error) {
return
}
func (role *Role)CreateRole() (createErr error) {
BuildRole.ID = 0
if createErr = role.BuildRole(); createErr != nil {
func (role *Role)CreateRole() (createdRole models.Role, createErr error) {
if createdRole, createErr = role.BuildRole(createdRole); createErr != nil {
return
}
_, createErr = util.Engine.Insert(&BuildRole)
_, createErr = util.Engine.Insert(&createdRole)
return
}
func (role *Role) UpdateRole() (updateErr error) {
if updateErr = role.BuildRole(); updateErr != nil {
func (role *Role) UpdateRole(roleID int64) (updatedRole models.Role, updateErr error) {
updatedRole.ID = roleID
if updatedRole, updateErr = role.BuildRole(updatedRole); updateErr != nil {
return
}
_, updateErr = util.Engine.ID(BuildRole.ID).Cols(
_, updateErr = util.Engine.ID(updatedRole.ID).Cols(
"name", "name_english", "icon",
"alias", "description", "game_id").Update(&BuildRole)
"alias", "description", "game_id").Update(&updatedRole)
return
}
func (role *Role) BuildRole() (buildErr error) {
func (role *Role) BuildRole(buildRole models.Role) (builderRole models.Role, buildErr error) {
if role.RwID <= 0 {
buildErr = errors.New("英雄B端ID不能小于或者等于0")
return
@ -97,15 +95,15 @@ func (role *Role) BuildRole() (buildErr error) {
buildErr = errors.New("英雄游戏不存在!")
return
} else {
BuildRole.GameID = mGame.ID
buildRole.GameID = mGame.ID
}
BuildRole.RwID = role.RwID
BuildRole.Name = role.Name
BuildRole.NameEnglish = role.NameEnglish
BuildRole.Icon = role.Icon
BuildRole.Alias = role.Alias
BuildRole.Description = role.Description
buildRole.RwID = role.RwID
buildRole.Name = role.Name
buildRole.NameEnglish = role.NameEnglish
buildRole.Icon = role.Icon
buildRole.Alias = role.Alias
buildRole.Description = role.Description
return
}

View File

@ -53,11 +53,10 @@ func InitRoleListData(rwGameID int64, limit int) {
for _, item := range roleListRep.Result.Items {
if fRole, fErr := FindRoleByRwID(item.RwID); fErr == nil {
BuildRole.ID = fRole.ID
updateErr := item.UpdateRole()
_, updateErr := item.UpdateRole(fRole.ID)
fmt.Println(updateErr)
} else {
createErr := item.CreateRole()
_, createErr := item.CreateRole()
fmt.Println(createErr)
}
}

View File

@ -33,8 +33,6 @@ type Team struct {
Score int `json:"score"`
}
var BuildSeries models.Series
func FindSeriesByRwID(rwID int64) (findSeries models.Series, findErr error) {
if rwID <= 0 {
findErr = errors.New("系列赛B端ID不能小于或者等于0")
@ -49,8 +47,7 @@ func FindSeriesByRwID(rwID int64) (findSeries models.Series, findErr error) {
return
}
func (series *Series) CreateSeries() (createErr error) {
BuildSeries.ID = 0
func (series *Series) CreateSeries() (createdSeries models.Series, createErr error) {
// 开启事务
session := util.Engine.NewSession()
defer session.Close()
@ -64,10 +61,9 @@ func (series *Series) CreateSeries() (createErr error) {
if fLeague, findErr := league.FindLeagueByRwID(series.RwLeagueID); findErr == nil {
// 找到联赛
if series.Course.League.RwID > 0 {
league.BuildLeague.ID = fLeague.ID
if createErr = series.Course.League.BuildLeague(); createErr == nil {
if fLeague, createErr = series.Course.League.BuildLeague(fLeague); createErr == nil {
// 参数正常提交到session
if i, err := session.ID(league.BuildLeague.ID).Update(&league.BuildLeague); err != nil || i != 1 {
if i, err := session.ID(fLeague.ID).Update(&fLeague); err != nil || i != 1 {
createErr = errors.New(fmt.Sprintf("系列赛关联赛事所属联赛更新失败: %v", err))
_ = session.Rollback()
return
@ -80,10 +76,9 @@ func (series *Series) CreateSeries() (createErr error) {
} else {
// 没找到对应的联赛
if series.Course.League.RwID > 0 {
league.BuildLeague.ID = 0
if createErr = series.Course.League.BuildLeague(); createErr == nil {
if fLeague, createErr = series.Course.League.BuildLeague(fLeague); createErr == nil {
// 参数正常提交到session
if _, err := session.Insert(&league.BuildLeague); err != nil {
if _, err := session.Insert(&fLeague); err != nil {
createErr = errors.New(fmt.Sprintf("系列赛关联赛事所属联赛创建失败: %v", err))
_ = session.Rollback()
return
@ -100,10 +95,12 @@ func (series *Series) CreateSeries() (createErr error) {
if fCourse, findErr := course.FindCourseByRwID(series.RwCourseID); findErr == nil {
// 找到赛事
if series.Course.RwID > 0 {
course.BuildCourse.ID = fCourse.ID
if createErr = series.Course.BuildCourse(); createErr == nil {
var buildCourse models.Course
var updatedCourse models.Course
buildCourse.ID = fCourse.ID
if updatedCourse, createErr = series.Course.BuildCourse(buildCourse); createErr == nil {
// 参数正常提交到session
if i, err := session.ID(course.BuildCourse.ID).Update(&course.BuildCourse); err != nil || i != 1 {
if i, err := session.ID(updatedCourse.ID).Update(&updatedCourse); err != nil || i != 1 {
createErr = errors.New(fmt.Sprintf("系列赛关联赛事更新失败: %v", err))
_ = session.Rollback()
return
@ -116,10 +113,11 @@ func (series *Series) CreateSeries() (createErr error) {
} else {
// 没找到对应的联赛
if series.Course.League.RwID > 0 {
course.BuildCourse.ID = 0
if createErr = series.Course.BuildCourse(); createErr == nil {
var buildCourse models.Course
var createdCourse models.Course
if createdCourse, createErr = series.Course.BuildCourse(buildCourse); createErr == nil {
// 参数正常提交到session
if _, err := session.Insert(&course.BuildCourse); err != nil {
if _, err := session.Insert(&createdCourse); err != nil {
createErr = errors.New(fmt.Sprintf("系列赛关联赛事创建失败: %v", err))
_ = session.Rollback()
return
@ -131,12 +129,12 @@ func (series *Series) CreateSeries() (createErr error) {
}
}
}
if createErr = series.BuildSeries(); createErr != nil {
if createdSeries, createErr = series.BuildSeries(createdSeries); createErr != nil {
return
}
// 创建系列赛
if _, err := session.Insert(&BuildSeries); err != nil {
if _, err := session.Insert(&createdSeries); err != nil {
createErr = errors.New(fmt.Sprintf("系列赛创建失败:%v", err))
_ = session.Rollback()
return
@ -150,7 +148,8 @@ func (series *Series) CreateSeries() (createErr error) {
return
}
func (series *Series) UpdateSeries() (updateErr error) {
func (series *Series) UpdateSeries(seriesID int64) (updatedSeries models.Series, updateErr error) {
updatedSeries.ID = seriesID
// 开启事务
session := util.Engine.NewSession()
defer session.Close()
@ -165,10 +164,9 @@ func (series *Series) UpdateSeries() (updateErr error) {
if fLeague, findErr := league.FindLeagueByRwID(series.RwLeagueID); findErr == nil {
// 找到联赛
if series.Course.League.RwID > 0 {
league.BuildLeague.ID = fLeague.ID
if updateErr = series.Course.League.BuildLeague(); updateErr == nil {
if fLeague, updateErr = series.Course.League.BuildLeague(fLeague); updateErr == nil {
// 参数正常提交到session
if i, err := session.ID(league.BuildLeague.ID).Update(&league.BuildLeague); err != nil || i != 1 {
if i, err := session.ID(fLeague.ID).Update(&fLeague); err != nil || i != 1 {
updateErr = errors.New(fmt.Sprintf("系列赛关联赛事所属联赛更新失败: %v", err))
_ = session.Rollback()
return
@ -181,10 +179,9 @@ func (series *Series) UpdateSeries() (updateErr error) {
} else {
// 没找到对应的联赛
if series.Course.League.RwID > 0 {
league.BuildLeague.ID = 0
if updateErr = series.Course.League.BuildLeague(); updateErr == nil {
if fLeague, updateErr = series.Course.League.BuildLeague(fLeague); updateErr == nil {
// 参数正常提交到session
if _, err := session.Insert(&league.BuildLeague); err != nil {
if _, err := session.Insert(&fLeague); err != nil {
updateErr = errors.New(fmt.Sprintf("系列赛关联赛事所属联赛创建失败: %v", err))
_ = session.Rollback()
return
@ -201,10 +198,12 @@ func (series *Series) UpdateSeries() (updateErr error) {
if fCourse, findErr := course.FindCourseByRwID(series.RwCourseID); findErr == nil {
// 找到赛事
if series.Course.RwID > 0 {
course.BuildCourse.ID = fCourse.ID
if updateErr = series.Course.BuildCourse(); updateErr == nil {
var buildCourse models.Course
var updatedCourse models.Course
buildCourse.ID = fCourse.ID
if updatedCourse, updateErr = series.Course.BuildCourse(buildCourse); updateErr == nil {
// 参数正常提交到session
if i, err := session.ID(course.BuildCourse.ID).Update(&course.BuildCourse); err != nil || i != 1 {
if i, err := session.ID(updatedCourse.ID).Update(&updatedCourse); err != nil || i != 1 {
updateErr = errors.New(fmt.Sprintf("系列赛关联赛事更新失败: %v", err))
_ = session.Rollback()
return
@ -217,10 +216,11 @@ func (series *Series) UpdateSeries() (updateErr error) {
} else {
// 没找到对应的联赛
if series.Course.RwID > 0 {
course.BuildCourse.ID = 0
if updateErr = series.Course.BuildCourse(); updateErr == nil {
var buildCourse models.Course
var createdCourse models.Course
if createdCourse, updateErr = series.Course.BuildCourse(buildCourse); updateErr == nil {
// 参数正常提交到session
if _, err := session.Insert(&course.BuildCourse); err != nil {
if _, err := session.Insert(&createdCourse); err != nil {
updateErr = errors.New(fmt.Sprintf("系列赛关联赛事创建失败: %v", err))
_ = session.Rollback()
return
@ -233,15 +233,15 @@ func (series *Series) UpdateSeries() (updateErr error) {
}
}
if updateErr = series.BuildSeries(); updateErr != nil {
if updatedSeries, updateErr = series.BuildSeries(updatedSeries); updateErr != nil {
return
}
// 更新系列赛
if _, err := session.ID(BuildSeries.ID).Cols(
if _, err := session.ID(updatedSeries.ID).Cols(
"status", "start_time", "end_time",
"season_info", "description", "info",
"game_id", "area_id").Update(&BuildSeries); err != nil {
"game_id", "area_id").Update(&updatedSeries); err != nil {
updateErr = errors.New(fmt.Sprintf("系列赛更新失败:%v", err))
_ = session.Rollback()
return
@ -255,7 +255,7 @@ func (series *Series) UpdateSeries() (updateErr error) {
return
}
func (series *Series) BuildSeries() (buildErr error) {
func (series *Series) BuildSeries(buildSeries models.Series) (builderSeries models.Series, buildErr error) {
if series.RwID <= 0 {
buildErr = errors.New("系列赛B端ID不能小于或者等于0")
return
@ -295,7 +295,7 @@ func (series *Series) BuildSeries() (buildErr error) {
buildErr = errors.New("赛事游戏不存在!")
return
} else {
BuildSeries.GameID = mGame.ID
buildSeries.GameID = mGame.ID
}
if series.RwAreaID > 0 {
@ -303,17 +303,17 @@ func (series *Series) BuildSeries() (buildErr error) {
buildErr = errors.New("赛事赛区不存在!")
return
} else {
BuildSeries.AreaID = mArea.ID
buildSeries.AreaID = mArea.ID
}
}
BuildSeries.RwID = series.RwID
BuildSeries.Status = series.Status
BuildSeries.StartTime = series.StartTime
BuildSeries.EndTime = series.EndTime
BuildSeries.SeasonInfo = series.SeasonInfo
BuildSeries.Description = series.Description
BuildSeries.Info = info
buildSeries.RwID = series.RwID
buildSeries.Status = series.Status
buildSeries.StartTime = series.StartTime
buildSeries.EndTime = series.EndTime
buildSeries.SeasonInfo = series.SeasonInfo
buildSeries.Description = series.Description
buildSeries.Info = info
return
return buildSeries, nil
}

View File

@ -108,10 +108,11 @@ func InitSeriesListData(rwGameID int64, rwAreaID int64, rwLeagueID int64, rwCour
for _, item := range seriesListRep.Result.Items {
fmt.Println(item)
if fSeries, fErr := FindSeriesByRwID(item.RwID); fErr == nil {
BuildSeries.ID = fSeries.ID
_ = item.UpdateSeries()
_, updateErr := item.UpdateSeries(fSeries.ID)
fmt.Println(updateErr)
} else {
_ = item.CreateSeries()
_, createErr := item.CreateSeries()
fmt.Println(createErr)
}
}
offset += limit

View File

@ -21,8 +21,6 @@ type Skill struct {
Icon string `json:"icon"`
}
var BuildSkill models.Skill
func FindSkillByRwID(rwID int64) (findSkill models.Skill, findErr error) {
if rwID <= 0 {
findErr = errors.New("B端ID不能小于或者等于0")
@ -37,30 +35,30 @@ func FindSkillByRwID(rwID int64) (findSkill models.Skill, findErr error) {
return
}
func (skill *Skill) CreateSkill() (createErr error) {
BuildSkill.ID = 0
if createErr = skill.BuildSkill(); createErr != nil {
func (skill *Skill) CreateSkill() (createdSkill models.Skill, createErr error) {
if createdSkill, createErr = skill.BuildSkill(createdSkill); createErr != nil {
return
}
_, createErr = util.Engine.Insert(&BuildSkill)
_, createErr = util.Engine.Insert(&createdSkill)
return
}
func (skill *Skill) UpdateSkill() (updateErr error) {
if updateErr = skill.BuildSkill(); updateErr != nil {
func (skill *Skill) UpdateSkill(skillID int64) (updatedSkill models.Skill, updateErr error) {
updatedSkill.ID = skillID
if updatedSkill, updateErr = skill.BuildSkill(updatedSkill); updateErr != nil {
return
}
_, updateErr = util.Engine.ID(BuildSkill.ID).Cols(
_, updateErr = util.Engine.ID(updatedSkill.ID).Cols(
"name", "name_english", "alias",
"description", "icon").Update(&BuildSkill)
"description", "icon").Update(&updatedSkill)
return
}
func (skill *Skill) BuildSkill() (buildErr error) {
func (skill *Skill) BuildSkill(buildSkill models.Skill) (builderSkill models.Skill, buildErr error) {
if skill.RwID <= 0 {
buildErr = errors.New("B端ID不能小于或者等于0")
return
@ -95,14 +93,14 @@ func (skill *Skill) BuildSkill() (buildErr error) {
buildErr = errors.New("技能游戏不存在!")
return
} else {
BuildSkill.GameID = mGame.ID
buildSkill.GameID = mGame.ID
}
if skill.RwRoleID > 0 {
if mRole, err := role.FindRoleByRwID(skill.RwRoleID); err != nil {
buildErr = errors.New("技能英雄不存在!")
} else {
BuildSkill.RoleId = mRole.ID
buildSkill.RoleId = mRole.ID
}
}
@ -110,16 +108,16 @@ func (skill *Skill) BuildSkill() (buildErr error) {
if mEquipment, err := equipment.FindEquipmentByRwID(skill.RwEquipmentID); err != nil {
buildErr = errors.New("技能装备不存在!")
} else {
BuildSkill.EquipmentId = mEquipment.ID
buildSkill.EquipmentId = mEquipment.ID
}
}
BuildSkill.RwID = skill.RwID
BuildSkill.Name = skill.Name
BuildSkill.NameEnglish = skill.NameEnglish
BuildSkill.Alias = skill.Alias
BuildSkill.Description = skill.Description
BuildSkill.Icon = skill.Icon
buildSkill.RwID = skill.RwID
buildSkill.Name = skill.Name
buildSkill.NameEnglish = skill.NameEnglish
buildSkill.Alias = skill.Alias
buildSkill.Description = skill.Description
buildSkill.Icon = skill.Icon
return
return buildSkill, nil
}

View File

@ -36,11 +36,10 @@ func InitSkillListData(rwGameID int64, limit int) {
for _, item := range skillListRep.Result.Items {
if fSkill, fErr := FindSkillByRwID(item.RwID); fErr == nil {
BuildSkill.ID = fSkill.ID
updateErr := item.UpdateSkill()
_, updateErr := item.UpdateSkill(fSkill.ID)
fmt.Println(updateErr)
} else {
createErr := item.CreateSkill()
_, createErr := item.CreateSkill()
fmt.Println(createErr)
}
}

View File

@ -25,8 +25,6 @@ type Team struct {
Players []player.Player `json:"players"`
}
var BuildTeam models.Team
func FindTeamByRwID(rwID int64) (findTeam models.Team, findErr error) {
if rwID <= 0 {
findErr = errors.New("B端ID不能小于或者等于0")
@ -41,8 +39,7 @@ func FindTeamByRwID(rwID int64) (findTeam models.Team, findErr error) {
return
}
func (team *Team) CreateTeam() (createErr error) {
BuildTeam.ID = 0
func (team *Team) CreateTeam() (createdTeam models.Team, createErr error) {
// 开启事务
session := util.Engine.NewSession()
defer session.Close()
@ -53,28 +50,27 @@ func (team *Team) CreateTeam() (createErr error) {
return
}
if createErr = team.BuildTeam(); createErr != nil {
if createdTeam, createErr = team.BuildTeam(createdTeam); createErr != nil {
return
}
// 创建队伍
if _, err := session.Insert(&BuildTeam); err != nil {
if _, err := session.Insert(&createdTeam); err != nil {
createErr = errors.New(fmt.Sprintf("队伍创建失败:%v", err))
_ = session.Rollback()
return
}
if len(team.Players) > 0 {
player.BuildPlayer.TeamID = BuildTeam.ID
for _, p := range team.Players {
// 查找该队员是否已经存在
if fPlayer, err := player.FindPlayerByRwID(p.RwID); err == nil {
// 已存在,更新该队员
player.BuildPlayer.ID = fPlayer.ID
if playerErr := p.BuildPlayer(); playerErr == nil {
if i, err := session.ID(player.BuildPlayer.ID).Cols(
fPlayer.TeamID = createdTeam.ID
if fPlayer, playerErr := p.BuildPlayer(fPlayer); playerErr == nil {
if i, err := session.ID(fPlayer.ID).Cols(
"name", "name_english", "alias",
"country", "team_player_position", "extend_info").Update(&player.BuildPlayer); err != nil || i != 1 {
"country", "team_player_position", "extend_info").Update(&fPlayer); err != nil || i != 1 {
createErr = errors.New(fmt.Sprintf("rw_id为%d的队员更新失败", p.RwID))
_ = session.Rollback()
return
@ -86,12 +82,12 @@ func (team *Team) CreateTeam() (createErr error) {
}
} else {
// 不存在,创建该队员
player.BuildPlayer.ID = 0
if playerErr := p.BuildPlayer(); playerErr != nil {
fPlayer.TeamID = createdTeam.ID
if fPlayer, playerErr := p.BuildPlayer(fPlayer); playerErr != nil {
createErr = errors.New(fmt.Sprintf("rw_id为%d的队员参数错误%s", p.RwID, err))
return
} else {
if _, err := session.Insert(&player.BuildPlayer); err != nil {
if _, err := session.Insert(&fPlayer); err != nil {
createErr = errors.New(fmt.Sprintf("rw_id为%d的队员创建失败", p.RwID))
_ = session.Rollback()
return
@ -110,8 +106,9 @@ func (team *Team) CreateTeam() (createErr error) {
return
}
func (team *Team) UpdateTeam() (updateErr error) {
if updateErr = team.BuildTeam(); updateErr != nil {
func (team *Team) UpdateTeam(teamID int64) (updatedTeam models.Team, updateErr error) {
updatedTeam.ID = teamID
if updatedTeam, updateErr = team.BuildTeam(updatedTeam); updateErr != nil {
return
}
@ -126,26 +123,25 @@ func (team *Team) UpdateTeam() (updateErr error) {
}
// 创建队伍
if _, err := session.ID(BuildTeam.ID).Cols(
if _, err := session.ID(updatedTeam.ID).Cols(
"game_type", "name", "name_english",
"short_name", "local", "country",
"area", "alias", "logo", "game_id").Update(&BuildTeam); err != nil {
"area", "alias", "logo", "game_id").Update(&updatedTeam); err != nil {
updateErr = errors.New(fmt.Sprintf("队伍更新失败:%v", err))
_ = session.Rollback()
return
}
if len(team.Players) > 0 {
player.BuildPlayer.TeamID = BuildTeam.ID
for _, p := range team.Players {
// 查找该队员是否已经存在
if fPlayer, err := player.FindPlayerByRwID(p.RwID); err == nil {
// 已存在,更新该队员
player.BuildPlayer.ID = fPlayer.ID
if playerErr := p.BuildPlayer(); playerErr == nil {
if i, err := session.ID(player.BuildPlayer.ID).Cols(
fPlayer.TeamID = updatedTeam.ID
if fPlayer, playerErr := p.BuildPlayer(fPlayer); playerErr == nil {
if i, err := session.ID(fPlayer.ID).Cols(
"name", "name_english", "alias",
"country", "team_player_position", "extend_info").Update(&player.BuildPlayer); err != nil || i != 1 {
"country", "team_player_position", "extend_info").Update(&fPlayer); err != nil || i != 1 {
updateErr = errors.New(fmt.Sprintf("rw_id为%d的队员更新失败", p.RwID))
_ = session.Rollback()
return
@ -157,12 +153,11 @@ func (team *Team) UpdateTeam() (updateErr error) {
}
} else {
// 不存在,创建该队员
player.BuildPlayer.ID = 0
if playerErr := p.BuildPlayer(); playerErr != nil {
if fPlayer, playerErr := p.BuildPlayer(fPlayer); playerErr != nil {
updateErr = errors.New(fmt.Sprintf("rw_id为%d的队员参数错误%s", p.RwID, err))
return
} else {
if _, err := session.Insert(&player.BuildPlayer); err != nil {
if _, err := session.Insert(&fPlayer); err != nil {
updateErr = errors.New(fmt.Sprintf("rw_id为%d的队员创建失败", p.RwID))
_ = session.Rollback()
return
@ -181,7 +176,7 @@ func (team *Team) UpdateTeam() (updateErr error) {
return
}
func (team *Team) BuildTeam() (buildErr error) {
func (team *Team) BuildTeam(buildTeam models.Team) (builderTeam models.Team, buildErr error) {
if team.RwID <= 0 {
buildErr = errors.New("队伍B端ID不能小于或者等于0")
return
@ -235,17 +230,17 @@ func (team *Team) BuildTeam() (buildErr error) {
return
}
BuildTeam.RwID = team.RwID
BuildTeam.GameType = team.GameType
BuildTeam.Name = team.Name
BuildTeam.NameEnglish = team.NameEnglish
BuildTeam.ShortName = team.ShortName
BuildTeam.Local = team.Local
BuildTeam.Country = strings.ToUpper(team.Country)
BuildTeam.Area = team.Area
BuildTeam.Alias = team.Alias
BuildTeam.Logo = team.Logo
BuildTeam.GameID = team.RwGameID
buildTeam.RwID = team.RwID
buildTeam.GameType = team.GameType
buildTeam.Name = team.Name
buildTeam.NameEnglish = team.NameEnglish
buildTeam.ShortName = team.ShortName
buildTeam.Local = team.Local
buildTeam.Country = strings.ToUpper(team.Country)
buildTeam.Area = team.Area
buildTeam.Alias = team.Alias
buildTeam.Logo = team.Logo
buildTeam.GameID = team.RwGameID
return
return buildTeam, nil
}

View File

@ -80,10 +80,11 @@ func InitTeamListData(rwGameID int64, limit int) {
for _, item := range teamListRep.Result.Items {
fmt.Println(item)
if fTeam, fErr := FindTeamByRwID(item.RwID); fErr == nil {
BuildTeam.ID = fTeam.ID
_ = item.UpdateTeam()
_, updateErr := item.UpdateTeam(fTeam.ID)
fmt.Println(updateErr)
} else {
_ = item.CreateTeam()
_, createErr := item.CreateTeam()
fmt.Println(createErr)
}
}
offset += limit

View File

@ -69,9 +69,9 @@ func init() {
Config.RiseWinterUrl = config.GetString("server.risewinter_url")
}
Config.RiseWinterTenantID, _ = strconv.Atoi(os.Getenv("RISEWINTER_TENANT_ID"))
Config.RiseWinterTenantID, _ = strconv.ParseInt(os.Getenv("RISEWINTER_TENANT_ID"), 10, 64)
if Config.RiseWinterTenantID == 0 {
Config.RiseWinterTenantID = config.GetInt("server.risewinter_tenant_id")
Config.RiseWinterTenantID = int64(config.GetInt("server.risewinter_tenant_id"))
}
Config.WhiteIp = os.Getenv("WHITE_IP")