feat: 代理管理添加批量操作功能,用户管理添加到期时间列
- 代理管理页面添加批量解封、批量封禁、批量删除功能 - 后端添加代理批量操作API - 用户管理添加独立的到期时间列 - 修复应用管理和日志记录页面顶部卡片图标颜色
This commit is contained in:
@@ -23,6 +23,8 @@ func SetupAgentsRoutes(r *gin.RouterGroup) {
|
||||
agents.DELETE("/:id", handleDeleteAgent)
|
||||
agents.GET("/:id/cards", handleGetAgentCards)
|
||||
agents.PUT("/:id/cards", handleUpdateAgentCards)
|
||||
agents.POST("/batch/status", handleBatchUpdateAgentStatus)
|
||||
agents.DELETE("/batch", handleBatchDeleteAgents)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -583,3 +585,63 @@ func handleUpdateAgentCards(c *gin.Context) {
|
||||
"message": "更新成功",
|
||||
})
|
||||
}
|
||||
|
||||
func handleBatchUpdateAgentStatus(c *gin.Context) {
|
||||
var req struct {
|
||||
AgentIDs []uint `json:"agent_ids" binding:"required"`
|
||||
Status string `json:"status" binding:"required,oneof=active inactive banned"`
|
||||
}
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
response.Error(c, 400, "参数错误")
|
||||
return
|
||||
}
|
||||
|
||||
if len(req.AgentIDs) == 0 {
|
||||
response.Error(c, 400, "请选择要操作的代理")
|
||||
return
|
||||
}
|
||||
|
||||
if err := database.DB.Model(&model.User{}).
|
||||
Where("id IN ? AND role = ?", req.AgentIDs, "agent").
|
||||
Update("status", req.Status).Error; err != nil {
|
||||
response.Error(c, 500, "批量更新状态失败")
|
||||
return
|
||||
}
|
||||
|
||||
service.LogOperation(c, "batch_update_status", "agent", nil, fmt.Sprintf("批量更新代理状态: %d个代理 -> %s", len(req.AgentIDs), req.Status), nil)
|
||||
|
||||
response.Success(c, gin.H{
|
||||
"updated": len(req.AgentIDs),
|
||||
})
|
||||
}
|
||||
|
||||
func handleBatchDeleteAgents(c *gin.Context) {
|
||||
var req struct {
|
||||
AgentIDs []uint `json:"agent_ids" binding:"required"`
|
||||
}
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
response.Error(c, 400, "参数错误")
|
||||
return
|
||||
}
|
||||
|
||||
if len(req.AgentIDs) == 0 {
|
||||
response.Error(c, 400, "请选择要删除的代理")
|
||||
return
|
||||
}
|
||||
|
||||
for _, agentID := range req.AgentIDs {
|
||||
var user model.User
|
||||
if err := database.DB.Where("id = ? AND role = ?", agentID, "agent").First(&user).Error; err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
database.DB.Model(&model.User{}).Where("parent_agent_id = ?", user.ID).Update("parent_agent_id", nil)
|
||||
database.DB.Delete(&user)
|
||||
}
|
||||
|
||||
service.LogOperation(c, "batch_delete", "agent", nil, fmt.Sprintf("批量删除代理: %d个", len(req.AgentIDs)), nil)
|
||||
|
||||
response.Success(c, gin.H{
|
||||
"deleted": len(req.AgentIDs),
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user