game switch serverlist

This commit is contained in:
yangduo 2024-09-20 19:00:32 +08:00
parent e09b1f18f6
commit fbb6812101

View File

@ -1,6 +1,7 @@
package system package system
import ( import (
"encoding/json"
"f5" "f5"
"fmt" "fmt"
"main/constant" "main/constant"
@ -54,7 +55,8 @@ func (this *GameSwitchApi) List(c *gin.Context) {
page := c.DefaultQuery("page", "") page := c.DefaultQuery("page", "")
result := []struct { result := []struct {
system.GameSwitch system.GameSwitch
Remark string `json:"remark"` Servers []int32 `json:"serverList"`
Remark string `json:"remark"`
}{} }{}
f5.GetGoStyleDb().PageQuery( f5.GetGoStyleDb().PageQuery(
constant.CONF_DB, constant.CONF_DB,
@ -82,6 +84,8 @@ func (this *GameSwitchApi) List(c *gin.Context) {
if exist { if exist {
p.Remark = desc p.Remark = desc
} }
p.Servers = make([]int32, 0)
json.Unmarshal([]byte(pg.Rows.GetByName("server_list")), &p.Servers)
p.AuditOpen = q5.SafeToInt32(pg.Rows.GetByName("audit_is_open")) p.AuditOpen = q5.SafeToInt32(pg.Rows.GetByName("audit_is_open"))
p.CreateTime = q5.SafeToInt32(pg.Rows.GetByName("createtime")) p.CreateTime = q5.SafeToInt32(pg.Rows.GetByName("createtime"))
p.ModifyTime = q5.SafeToInt32(pg.Rows.GetByName("modifytime")) p.ModifyTime = q5.SafeToInt32(pg.Rows.GetByName("modifytime"))
@ -139,10 +143,11 @@ func (this *GameSwitchApi) Add(c *gin.Context) {
func (this *GameSwitchApi) Edit(c *gin.Context) { func (this *GameSwitchApi) Edit(c *gin.Context) {
req := struct { req := struct {
Name string `binding:"required" json:"switch_name"` Name string `binding:"required" json:"switch_name"`
Open *int32 `binding:"required" json:"is_open"` Open *int32 `binding:"required" json:"is_open"`
AuditOpen *int32 `binding:"required" json:"audit_is_open"` Servers []int32 `json:"serverList"`
Remark string `json:"remark"` AuditOpen *int32 `binding:"required" json:"audit_is_open"`
Remark string `json:"remark"`
}{} }{}
if err := c.ShouldBindJSON(&req); err != nil { if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
@ -151,7 +156,10 @@ func (this *GameSwitchApi) Edit(c *gin.Context) {
}) })
return return
} }
gswitch := new(system.GameSwitch) gswitch := new(struct {
system.GameSwitch
Servers string `gorm:"column:server_list" json:"serverList"`
})
db := f5.GetApp().GetOrmDb(constant.CONF_DB) db := f5.GetApp().GetOrmDb(constant.CONF_DB)
if err := db.Take(gswitch, "switch_name = ?", req.Name).Error; err != nil { if err := db.Take(gswitch, "switch_name = ?", req.Name).Error; err != nil {
if !f5.IsOrmErrRecordNotFound(err) { if !f5.IsOrmErrRecordNotFound(err) {
@ -171,6 +179,8 @@ func (this *GameSwitchApi) Edit(c *gin.Context) {
nowDaySeconds := int32(f5.GetApp().GetRealSeconds()) nowDaySeconds := int32(f5.GetApp().GetRealSeconds())
gswitch.Opened = *req.Open gswitch.Opened = *req.Open
serverbytes,_ := json.Marshal(req.Servers)
gswitch.Servers = string(serverbytes)
gswitch.AuditOpen = *req.AuditOpen gswitch.AuditOpen = *req.AuditOpen
gswitch.ModifyTime = nowDaySeconds gswitch.ModifyTime = nowDaySeconds
if err := db.Where("switch_name = ?", req.Name).Save(gswitch).Error; err != nil { if err := db.Where("switch_name = ?", req.Name).Save(gswitch).Error; err != nil {