From f3e21652694e2370da4958449825cf4212e9daec Mon Sep 17 00:00:00 2001 From: yangduo Date: Wed, 28 Aug 2024 14:35:43 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E9=BB=91=E7=99=BD=E5=90=8D?= =?UTF-8?q?=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adminserver/api/v1/system/block_player.go | 156 +++++++------- server/adminserver/api/v1/system/whitelist.go | 196 ++++++++---------- .../adminserver/model/system/block_player.go | 7 +- server/adminserver/model/system/whitelist.go | 10 +- .../adminserver/router/system/block_player.go | 2 +- server/adminserver/router/system/whitelist.go | 4 +- 6 files changed, 171 insertions(+), 204 deletions(-) diff --git a/server/adminserver/api/v1/system/block_player.go b/server/adminserver/api/v1/system/block_player.go index f1b1d9cd..465a44c8 100644 --- a/server/adminserver/api/v1/system/block_player.go +++ b/server/adminserver/api/v1/system/block_player.go @@ -30,10 +30,10 @@ func (bpa *BlockPlayerApi) List(c *gin.Context) { constant.CONF_DB, q5.ToInt32(req.PageDto.PageSize), q5.ToInt32(req.PageDto.Page), - "SELECT * FROM t_blockplayer WHERE 1=1 AND deleted = 0", + "SELECT * FROM t_blacklist WHERE 1=1", []string{}, f5.GetDbFilter().Comp([]f5.DbQueryFilter{}...), - " ORDER BY account_id ", + " ORDER BY user_identity ", func(err error, pg *f5.Pagination) { if err != nil { c.JSON(http.StatusOK, gin.H{ @@ -45,8 +45,8 @@ func (bpa *BlockPlayerApi) List(c *gin.Context) { for pg.Rows.Next() { p := new(system.BlockPlayer) - p.Blocked = q5.SafeToInt32(pg.Rows.GetByName("blocked")) - p.Account = pg.Rows.GetByName("account_id") + p.Enable = q5.SafeToInt32(pg.Rows.GetByName("enable")) + p.Identity = pg.Rows.GetByName("user_identity") p.CreateTime = q5.SafeToInt32(pg.Rows.GetByName("createtime")) p.ModifyTime = q5.SafeToInt32(pg.Rows.GetByName("modifytime")) q5.AppendSlice(&result, p) @@ -64,7 +64,8 @@ func (bpa *BlockPlayerApi) List(c *gin.Context) { func (bpa *BlockPlayerApi) Add(c *gin.Context) { req := struct { - Account string `binding:"required" json:"account_id"` + Identity string `binding:"required" json:"user_identity"` + Enable int32 `json:"enable"` }{} if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusOK, gin.H{ @@ -74,34 +75,20 @@ func (bpa *BlockPlayerApi) Add(c *gin.Context) { return } - info := new(system.BlockPlayer) - nowDaySeconds := int32(f5.GetApp().GetRealSeconds()) - var count int64 = 0 - db := f5.GetApp().GetOrmDb(constant.CONF_DB).Table("t_blockplayer").Where("account_id =?", req.Account) + db := f5.GetApp().GetOrmDb(constant.CONF_DB).Table("t_blacklist").Where("user_identity =?", req.Identity) if err := db.Count(&count).Error; err == nil && count > 0 { - db.Take(info) - if info.Deleted == 0 { - c.JSON(http.StatusOK, gin.H{ - "code": 1, - "message": "数据存在", - }) - } else { - info.Blocked = 1 - info.Deleted = 0 - info.ModifyTime = nowDaySeconds - db.Save(info) - - c.JSON(http.StatusOK, gin.H{ - "code": 0, - "message": "添加成功", - }) - } + c.JSON(http.StatusOK, gin.H{ + "code": 1, + "message": "数据存在", + }) return } - info.Account = req.Account - info.Blocked = 1 + info := new(system.BlockPlayer) + nowDaySeconds := int32(f5.GetApp().GetRealSeconds()) + info.Identity = req.Identity + info.Enable = req.Enable info.CreateTime = nowDaySeconds info.ModifyTime = nowDaySeconds if err := f5.GetApp().GetOrmDb(constant.CONF_DB).Create(info).Error; err != nil { @@ -119,8 +106,8 @@ func (bpa *BlockPlayerApi) Add(c *gin.Context) { func (bpa *BlockPlayerApi) Edit(c *gin.Context) { req := struct { - Account string `binding:"required" json:"account_id"` - Blocked int32 `json:"blocked"` + Identity string `binding:"required" json:"user_identity"` + Enable int32 `json:"enable"` }{} if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusOK, gin.H{ @@ -132,7 +119,7 @@ func (bpa *BlockPlayerApi) Edit(c *gin.Context) { blockplayer := new(system.BlockPlayer) db := f5.GetApp().GetOrmDb(constant.CONF_DB) - if err := db.Take(blockplayer, "account_id = ? AND deleted = 0", req.Account).Error; err != nil { + if err := db.Take(blockplayer, "user_identity = ?", req.Identity).Error; err != nil { if !f5.IsOrmErrRecordNotFound(err) { c.JSON(http.StatusOK, gin.H{ "code": 500, @@ -148,15 +135,16 @@ func (bpa *BlockPlayerApi) Edit(c *gin.Context) { } } - nowDaySeconds := int32(f5.GetApp().GetRealSeconds()) - blockplayer.Blocked = req.Blocked - blockplayer.ModifyTime = nowDaySeconds - if err := db.Where("account_id = ?", req.Account).Save(blockplayer).Error; err != nil { - c.JSON(http.StatusOK, gin.H{ - "code": 500, - "message": "sever internal error:" + err.Error(), - }) - return + if blockplayer.Enable != req.Enable { + blockplayer.Enable = req.Enable + blockplayer.ModifyTime = int32(f5.GetApp().GetRealSeconds()) + if err := db.Where("user_identity = ?", req.Identity).Save(blockplayer).Error; err != nil { + c.JSON(http.StatusOK, gin.H{ + "code": 500, + "message": "sever internal error:" + err.Error(), + }) + return + } } c.JSON(http.StatusOK, gin.H{ "code": 0, @@ -165,49 +153,49 @@ func (bpa *BlockPlayerApi) Edit(c *gin.Context) { } func (bpa *BlockPlayerApi) Del(c *gin.Context) { - req := struct { - Account string `binding:"required" json:"account_id"` - }{} - if err := c.ShouldBindJSON(&req); err != nil { - c.JSON(http.StatusOK, gin.H{ - "code": 1, - "message": err.Error(), - }) - return - } + // req := struct { + // Identity string `binding:"required" json:"user_identity"` + // }{} + // if err := c.ShouldBindJSON(&req); err != nil { + // c.JSON(http.StatusOK, gin.H{ + // "code": 1, + // "message": err.Error(), + // }) + // return + // } - blockplayer := new(system.BlockPlayer) - db := f5.GetApp().GetOrmDb(constant.CONF_DB) - if err := db.Take(blockplayer, "account_id = ? AND deleted = 0", req.Account).Error; err != nil { - if !f5.IsOrmErrRecordNotFound(err) { - c.JSON(http.StatusOK, gin.H{ - "code": 500, - "message": "sever internal error:" + err.Error(), - }) - return - } else { - c.JSON(http.StatusOK, gin.H{ - "code": 2, - "message": "无法查到记录", - }) - return - } - } else { - } - nowDaySeconds := int32(f5.GetApp().GetRealSeconds()) - blockplayer.Deleted = 1 - blockplayer.ModifyTime = nowDaySeconds - if err := db.Where("account_id = ?", req.Account).Save(blockplayer).Error; err != nil { - c.JSON(http.StatusOK, gin.H{ - "code": 500, - "message": "sever internal error:" + err.Error(), - }) - return - } - c.JSON(http.StatusOK, gin.H{ - "code": 0, - "message": "", - }) + // blockplayer := new(system.BlockPlayer) + // db := f5.GetApp().GetOrmDb(constant.CONF_DB) + // if err := db.Take(blockplayer, "user_identity = ?", req.Identity).Error; err != nil { + // if !f5.IsOrmErrRecordNotFound(err) { + // c.JSON(http.StatusOK, gin.H{ + // "code": 500, + // "message": "sever internal error:" + err.Error(), + // }) + // return + // } else { + // c.JSON(http.StatusOK, gin.H{ + // "code": 2, + // "message": "无法查到记录", + // }) + // return + // } + // } else { + // } + // nowDaySeconds := int32(f5.GetApp().GetRealSeconds()) + // blockplayer.Deleted = 1 + // blockplayer.ModifyTime = nowDaySeconds + // if err := db.Where("user_identity = ?", req.Identity).Save(blockplayer).Error; err != nil { + // c.JSON(http.StatusOK, gin.H{ + // "code": 500, + // "message": "sever internal error:" + err.Error(), + // }) + // return + // } + // c.JSON(http.StatusOK, gin.H{ + // "code": 0, + // "message": "", + // }) } func (bpa *BlockPlayerApi) UploadExcel(c *gin.Context) { @@ -242,8 +230,8 @@ func (bpa *BlockPlayerApi) UploadExcel(c *gin.Context) { continue } member := new(system.BlockPlayer) - member.Account = row[0] - member.Blocked = 1 + member.Identity = row[0] + member.Enable = 1 member.CreateTime = nowDaySeconds member.ModifyTime = nowDaySeconds blockplayers = append(blockplayers, member) diff --git a/server/adminserver/api/v1/system/whitelist.go b/server/adminserver/api/v1/system/whitelist.go index b45fa2f1..a0c15e33 100644 --- a/server/adminserver/api/v1/system/whitelist.go +++ b/server/adminserver/api/v1/system/whitelist.go @@ -16,7 +16,6 @@ type WhiteListApi struct { func (bpa *WhiteListApi) List(c *gin.Context) { req := struct { - Type string `json:"type"` PageDto system.PageDto `json:"page_dto"` }{} if err := c.ShouldBindJSON(&req); err != nil { @@ -26,12 +25,8 @@ func (bpa *WhiteListApi) List(c *gin.Context) { }) return } - sql := "SELECT * FROM t_whitelist WHERE 1=1 AND deleted = 0" - params := []string{} - if req.Type != "" { - sql += " AND type = ?" - params = append(params, req.Type) - } + sql := "SELECT * FROM t_whitelist WHERE 1=1" + params := []string{} result := []*system.WhiteListItem{} f5.GetGoStyleDb().PageQuery( constant.CONF_DB, @@ -40,7 +35,7 @@ func (bpa *WhiteListApi) List(c *gin.Context) { sql, params, f5.GetDbFilter().Comp([]f5.DbQueryFilter{}...), - " ORDER BY account_id ", + " ORDER BY user_identity ", func(err error, pg *f5.Pagination) { if err != nil { c.JSON(http.StatusOK, gin.H{ @@ -52,8 +47,8 @@ func (bpa *WhiteListApi) List(c *gin.Context) { for pg.Rows.Next() { p := new(system.WhiteListItem) - p.Type = pg.Rows.GetByName("type") - p.Account = pg.Rows.GetByName("account_id") + p.Enable = q5.SafeToInt32(pg.Rows.GetByName("enable")) + p.Identity = pg.Rows.GetByName("user_identity") p.CreateTime = q5.SafeToInt32(pg.Rows.GetByName("createtime")) p.ModifyTime = q5.SafeToInt32(pg.Rows.GetByName("modifytime")) q5.AppendSlice(&result, p) @@ -71,8 +66,8 @@ func (bpa *WhiteListApi) List(c *gin.Context) { func (bpa *WhiteListApi) Add(c *gin.Context) { req := struct { - Account string `binding:"required" json:"account_id"` - Type string `binding:"required" json:"type"` + Identity string `binding:"required" json:"user_identity"` + Enable int32 `json:"enable"` }{} if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusOK, gin.H{ @@ -86,29 +81,17 @@ func (bpa *WhiteListApi) Add(c *gin.Context) { nowDaySeconds := int32(f5.GetApp().GetRealSeconds()) var count int64 = 0 - db := f5.GetApp().GetOrmDb(constant.CONF_DB).Table("t_whitelist").Where("account_id = ? AND type = ?", req.Account, req.Type) + db := f5.GetApp().GetOrmDb(constant.CONF_DB).Table("t_whitelist").Where("user_identity = ?", req.Identity) if err := db.Count(&count).Error; err == nil && count > 0 { - db.Take(info) - if info.Deleted == 0 { - c.JSON(http.StatusOK, gin.H{ - "code": 1, - "message": "数据存在", - }) - } else { - info.Deleted = 0 - info.ModifyTime = nowDaySeconds - db.Save(info) - - c.JSON(http.StatusOK, gin.H{ - "code": 0, - "message": "添加成功", - }) - } + c.JSON(http.StatusOK, gin.H{ + "code": 1, + "message": "数据存在", + }) return } - info.Account = req.Account - info.Type = req.Type + info.Identity = req.Identity + info.Enable = req.Enable info.CreateTime = nowDaySeconds info.ModifyTime = nowDaySeconds if err := f5.GetApp().GetOrmDb(constant.CONF_DB).Create(info).Error; err != nil { @@ -125,56 +108,9 @@ func (bpa *WhiteListApi) Add(c *gin.Context) { } func (bpa *WhiteListApi) Edit(c *gin.Context) { - // req := struct { - // Account string `binding:"required" json:"account_id"` - // Type string `json:"type"` - // }{} - // if err := c.ShouldBindJSON(&req); err != nil { - // c.JSON(http.StatusOK, gin.H{ - // "code": 1, - // "message": err.Error(), - // }) - // return - // } - - // whitelistitem := new(system.WhiteListItem) - // db := f5.GetApp().GetOrmDb(constant.CONF_DB) - // if err := db.Take(whitelistitem, "account_id =?", req.Account).Error; err != nil { - // if !f5.IsOrmErrRecordNotFound(err) { - // c.JSON(http.StatusOK, gin.H{ - // "code": 500, - // "message": "sever internal error:" + err.Error(), - // }) - // return - // } else { - // c.JSON(http.StatusOK, gin.H{ - // "code": 2, - // "message": "无法查到记录", - // }) - // return - // } - // } - - // nowDaySeconds := int32(f5.GetApp().GetRealSeconds()) - // whiteListItem.Blocked = req.Blocked - // whiteListItem.ModifyTime = nowDaySeconds - // if err := db.Where("account_id = ?", req.Account).Save(whiteListItem).Error; err != nil { - // c.JSON(http.StatusOK, gin.H{ - // "code": 500, - // "message": "sever internal error:" + err.Error(), - // }) - // return - // } - // c.JSON(http.StatusOK, gin.H{ - // "code": 0, - // "message": "", - // }) -} - -func (bpa *WhiteListApi) Del(c *gin.Context) { req := struct { - Account string `binding:"required" json:"account_id"` - Type string `json:"type"` + Identity string `binding:"required" json:"user_identity"` + Enable int32 `json:"enable"` }{} if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusOK, gin.H{ @@ -185,12 +121,8 @@ func (bpa *WhiteListApi) Del(c *gin.Context) { } whiteListItem := new(system.WhiteListItem) - db := f5.GetApp().GetOrmDb(constant.CONF_DB).Where("account_id = ?", req.Account) - if req.Type != "" { - db = db.Where("type = ?", req.Type) - } - - if err := db.Take(whiteListItem).Error; err != nil { + db := f5.GetApp().GetOrmDb(constant.CONF_DB) + if err := db.Take(whiteListItem, "user_identity =?", req.Identity).Error; err != nil { if !f5.IsOrmErrRecordNotFound(err) { c.JSON(http.StatusOK, gin.H{ "code": 500, @@ -204,33 +136,86 @@ func (bpa *WhiteListApi) Del(c *gin.Context) { }) return } - } else { - if whiteListItem.Deleted == 1 { - c.JSON(http.StatusOK, gin.H{ - "code": 2, - "message": "无法查到记录", - }) + } + if whiteListItem.Enable != req.Enable { + nowDaySeconds := int32(f5.GetApp().GetRealSeconds()) + whiteListItem.Enable = req.Enable + whiteListItem.ModifyTime = nowDaySeconds + if err := db.Where("user_identity = ?", req.Identity).Save(whiteListItem).Error; err != nil { + c.JSON(http.StatusOK, gin.H{ + "code": 500, + "message": "sever internal error:" + err.Error(), + }) return } } - nowDaySeconds := int32(f5.GetApp().GetRealSeconds()) - whiteListItem.Deleted = 1 - whiteListItem.ModifyTime = nowDaySeconds - - if err := db.Save(whiteListItem).Error; err != nil { - c.JSON(http.StatusOK, gin.H{ - "code": 500, - "message": "sever internal error:" + err.Error(), - }) - return - } c.JSON(http.StatusOK, gin.H{ "code": 0, "message": "", }) } +func (bpa *WhiteListApi) Del(c *gin.Context) { + // req := struct { + // Account string `binding:"required" json:"user_identity"` + // Type string `json:"type"` + // }{} + // if err := c.ShouldBindJSON(&req); err != nil { + // c.JSON(http.StatusOK, gin.H{ + // "code": 1, + // "message": err.Error(), + // }) + // return + // } + + // whiteListItem := new(system.WhiteListItem) + // db := f5.GetApp().GetOrmDb(constant.CONF_DB).Where("user_identity = ?", req.Account) + // if req.Type != "" { + // db = db.Where("type = ?", req.Type) + // } + + // if err := db.Take(whiteListItem).Error; err != nil { + // if !f5.IsOrmErrRecordNotFound(err) { + // c.JSON(http.StatusOK, gin.H{ + // "code": 500, + // "message": "sever internal error:" + err.Error(), + // }) + // return + // } else { + // c.JSON(http.StatusOK, gin.H{ + // "code": 2, + // "message": "无法查到记录", + // }) + // return + // } + // } else { + // if whiteListItem.Deleted == 1 { + // c.JSON(http.StatusOK, gin.H{ + // "code": 2, + // "message": "无法查到记录", + // }) + + // return + // } + // } + // nowDaySeconds := int32(f5.GetApp().GetRealSeconds()) + // whiteListItem.Deleted = 1 + // whiteListItem.ModifyTime = nowDaySeconds + + // if err := db.Save(whiteListItem).Error; err != nil { + // c.JSON(http.StatusOK, gin.H{ + // "code": 500, + // "message": "sever internal error:" + err.Error(), + // }) + // return + // } + // c.JSON(http.StatusOK, gin.H{ + // "code": 0, + // "message": "", + // }) +} + func (bpa *WhiteListApi) UploadExcel(c *gin.Context) { file, _, err := c.Request.FormFile("file") if err != nil { @@ -263,9 +248,8 @@ func (bpa *WhiteListApi) UploadExcel(c *gin.Context) { continue } member := new(system.WhiteListItem) - member.Account = row[0] - member.Type = row[1] - member.Deleted = 0 + member.Identity = row[0] + member.Enable = 1 member.CreateTime = nowDaySeconds member.ModifyTime = nowDaySeconds whitelist = append(whitelist, member) diff --git a/server/adminserver/model/system/block_player.go b/server/adminserver/model/system/block_player.go index 4b3b5f1e..e3af4ed8 100644 --- a/server/adminserver/model/system/block_player.go +++ b/server/adminserver/model/system/block_player.go @@ -1,13 +1,12 @@ package system type BlockPlayer struct { - Account string `gorm:"column:account_id" json:"account_id"` - Blocked int32 `gorm:"column:blocked" json:"blocked"` - Deleted int32 `gorm:"column:deleted" json:"deleted"` + Identity string `gorm:"column:user_identity" json:"user_identity"` + Enable int32 `gorm:"column:enable" json:"enable"` CreateTime int32 `gorm:"column:createtime" json:"createtime"` ModifyTime int32 `gorm:"column:modifytime" json:"modifytime"` } func (BlockPlayer) TableName() string { - return "t_blockplayer" + return "t_blacklist" } diff --git a/server/adminserver/model/system/whitelist.go b/server/adminserver/model/system/whitelist.go index fb528b1e..7038942b 100644 --- a/server/adminserver/model/system/whitelist.go +++ b/server/adminserver/model/system/whitelist.go @@ -1,9 +1,8 @@ package system type WhiteListItem struct { - Account string `gorm:"column:account_id" json:"account_id"` - Type string `gorm:"column:type" json:"type"` - Deleted int32 `gorm:"column:deleted" json:"deleted"` + Identity string `gorm:"column:user_identity" json:"user_identity"` + Enable int32 `gorm:"column:enable" json:"enable"` CreateTime int32 `gorm:"column:createtime" json:"createtime"` ModifyTime int32 `gorm:"column:modifytime" json:"modifytime"` } @@ -13,10 +12,7 @@ func (WhiteListItem) TableName() string { } type SuperWhiteListItem struct { - Identity string `gorm:"column:user_identity" json:"user_identity"` - Enable int32 `gorm:"column:enable" json:"enable"` - CreateTime int32 `gorm:"column:createtime" json:"createtime"` - ModifyTime int32 `gorm:"column:modifytime" json:"modifytime"` + WhiteListItem } func (SuperWhiteListItem) TableName() string { diff --git a/server/adminserver/router/system/block_player.go b/server/adminserver/router/system/block_player.go index e38cb9bf..74b428e2 100644 --- a/server/adminserver/router/system/block_player.go +++ b/server/adminserver/router/system/block_player.go @@ -16,7 +16,7 @@ func (this *BlockPlayerRoute) InitBlockPlayerRouter(priRouter *gin.RouterGroup) { group.POST("add", middleware.Permission("api/v1/block_player/add", api.Add)) group.POST("edit", middleware.Permission("api/v1/block_player/edit", api.Edit)) - group.POST("del", middleware.Permission("api/v1/block_player/del", api.Del)) + // group.POST("del", middleware.Permission("api/v1/block_player/del", api.Del)) group.POST("list", middleware.Permission("api/v1/block_player/list", api.List)) group.POST("uploadExcel", middleware.Permission("api/v1/block_player/uploadExcel", api.UploadExcel)) } diff --git a/server/adminserver/router/system/whitelist.go b/server/adminserver/router/system/whitelist.go index 731008f3..64e7c99e 100644 --- a/server/adminserver/router/system/whitelist.go +++ b/server/adminserver/router/system/whitelist.go @@ -15,8 +15,8 @@ func (this *WhiteListRoute) InitWhiteListRouter(priRouter *gin.RouterGroup) { api := v1.ApiGroupApp.SystemApiGroup.WhiteListApi { group.POST("add", middleware.Permission("api/v1/white_list/add", api.Add)) - //group.POST("edit", middleware.Permission("api/v1/white_list/edit", api.Edit)) - group.POST("del", middleware.Permission("api/v1/white_list/del", api.Del)) + group.POST("edit", middleware.Permission("api/v1/white_list/edit", api.Edit)) + // group.POST("del", middleware.Permission("api/v1/white_list/del", api.Del)) group.POST("list", middleware.Permission("api/v1/white_list/list", api.List)) group.POST("uploadExcel", middleware.Permission("api/v1/white_list/uploadExcel", api.UploadExcel)) }