super whitelist
This commit is contained in:
parent
b32267d897
commit
ffeaaed7e1
@ -283,3 +283,167 @@ func (bpa *WhiteListApi) UploadExcel(c *gin.Context) {
|
|||||||
"message": "添加成功",
|
"message": "添加成功",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (bpa *WhiteListApi) ListSuper(c *gin.Context) {
|
||||||
|
req := struct {
|
||||||
|
PageDto system.PageDto `json:"page_dto"`
|
||||||
|
}{}
|
||||||
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"code": 1,
|
||||||
|
"message": err.Error(),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
sql := "SELECT * FROM t_super_whitelist WHERE 1=1"
|
||||||
|
params := []string{}
|
||||||
|
result := []system.SuperWhiteListItem{}
|
||||||
|
f5.GetGoStyleDb().PageQuery(
|
||||||
|
constant.CONF_DB,
|
||||||
|
q5.ToInt32(req.PageDto.PageSize),
|
||||||
|
q5.ToInt32(req.PageDto.Page),
|
||||||
|
sql,
|
||||||
|
params,
|
||||||
|
f5.GetDbFilter().Comp([]f5.DbQueryFilter{}...),
|
||||||
|
"",
|
||||||
|
func(err error, pg *f5.Pagination) {
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"code": 1,
|
||||||
|
"message": err.Error(),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for pg.Rows.Next() {
|
||||||
|
p := q5.NewSliceElement(&result)
|
||||||
|
(*p).Identity = pg.Rows.GetByName("user_identity")
|
||||||
|
(*p).Enable = q5.SafeToInt32(pg.Rows.GetByName("enable"))
|
||||||
|
(*p).CreateTime = q5.SafeToInt32(pg.Rows.GetByName("createtime"))
|
||||||
|
(*p).ModifyTime = q5.SafeToInt32(pg.Rows.GetByName("modifytime"))
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"code": 0,
|
||||||
|
"message": "获取成功",
|
||||||
|
"data": result,
|
||||||
|
"total": pg.Total,
|
||||||
|
"total_page": pg.TotalPages,
|
||||||
|
"cur_page": pg.CurrentPage,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (bpa *WhiteListApi) AddSuper(c *gin.Context) {
|
||||||
|
req := struct {
|
||||||
|
Identity string `binding:"required" json:"user_identity"`
|
||||||
|
Enable int32 `json:"enable"`
|
||||||
|
}{}
|
||||||
|
|
||||||
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"code": 1,
|
||||||
|
"message": err.Error(),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if req.Identity == "" || req.Enable < 0 || req.Enable > 1 {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"code": 1,
|
||||||
|
"message": "",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
info := new(system.SuperWhiteListItem)
|
||||||
|
|
||||||
|
var count int64 = 0
|
||||||
|
db := f5.GetApp().GetOrmDb(constant.CONF_DB).Table(info.TableName()).Where("user_identity = ?", req.Identity)
|
||||||
|
err := db.Count(&count).Error
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"code": 1,
|
||||||
|
"message": "系统繁忙",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
} else if count > 0 {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"code": 1,
|
||||||
|
"message": "数据存在",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
info.Identity = req.Identity
|
||||||
|
info.Enable = req.Enable
|
||||||
|
nowDaySeconds := int32(f5.GetApp().GetRealSeconds())
|
||||||
|
info.CreateTime = nowDaySeconds
|
||||||
|
info.ModifyTime = nowDaySeconds
|
||||||
|
if err := f5.GetApp().GetOrmDb(constant.CONF_DB).Create(info).Error; err != nil {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"code": 1,
|
||||||
|
"message": err.Error(),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"code": 0,
|
||||||
|
"message": "添加成功",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (bpa *WhiteListApi) EditSuper(c *gin.Context) {
|
||||||
|
req := struct {
|
||||||
|
Identity string `binding:"required" json:"user_identity"`
|
||||||
|
Enable int32 `json:"enable"`
|
||||||
|
}{}
|
||||||
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"code": 1,
|
||||||
|
"message": err.Error(),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if req.Identity == "" || req.Enable < 0 || req.Enable > 1 {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"code": 1,
|
||||||
|
"message": "",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
item := new(system.SuperWhiteListItem)
|
||||||
|
db := f5.GetApp().GetOrmDb(constant.CONF_DB)
|
||||||
|
if err := db.Take(item, "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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if item.Enable != req.Enable {
|
||||||
|
item.Enable = req.Enable
|
||||||
|
item.ModifyTime = int32(f5.GetApp().GetRealSeconds())
|
||||||
|
if err := db.Where("user_identity = ?", req.Identity).Save(item).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": "",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
@ -11,3 +11,14 @@ type WhiteListItem struct {
|
|||||||
func (WhiteListItem) TableName() string {
|
func (WhiteListItem) TableName() string {
|
||||||
return "t_whitelist"
|
return "t_whitelist"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (SuperWhiteListItem) TableName() string {
|
||||||
|
return "t_super_whitelist"
|
||||||
|
}
|
||||||
|
@ -20,4 +20,11 @@ func (this *WhiteListRoute) InitWhiteListRouter(priRouter *gin.RouterGroup) {
|
|||||||
group.POST("list", middleware.Permission("api/v1/white_list/list", api.List))
|
group.POST("list", middleware.Permission("api/v1/white_list/list", api.List))
|
||||||
group.POST("uploadExcel", middleware.Permission("api/v1/white_list/uploadExcel", api.UploadExcel))
|
group.POST("uploadExcel", middleware.Permission("api/v1/white_list/uploadExcel", api.UploadExcel))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
supergroup := priRouter.Group("super_whitelist")
|
||||||
|
supergroup.POST("add", middleware.Permission("api/v1/super_whitelist/add", api.AddSuper))
|
||||||
|
supergroup.POST("list", middleware.Permission("api/v1/super_whitelist/list", api.ListSuper))
|
||||||
|
supergroup.POST("edit", middleware.Permission("api/v1/super_whitelist/edit", api.EditSuper))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user