package system import ( "github.com/gin-gonic/gin" "go.uber.org/zap" "sundynix-go/global" "sundynix-go/model/commom/request" "sundynix-go/model/commom/response" "sundynix-go/model/system" systemReq "sundynix-go/model/system/request" ) type ClientApi struct { } func (s *ClientApi) SaveClient(c *gin.Context) { var client system.Client err := c.ShouldBindJSON(&client) if err != nil { response.FailWithMsg(err.Error(), c) return } err = clientService.SaveClient(client) if err != nil { global.Logger.Error("保存客户端失败!", zap.Error(err)) response.FailWithMsg(err.Error(), c) return } response.OkWithMsg("保存客户端成功!", c) } func (s *ClientApi) UpdateClient(c *gin.Context) { var client system.Client err := c.ShouldBindJSON(&client) if err != nil { response.FailWithMsg(err.Error(), c) return } err = clientService.UpdateClient(client) if err != nil { global.Logger.Error("更新客户端失败!", zap.Error(err)) response.FailWithMsg(err.Error(), c) return } response.OkWithMsg("更新客户端成功!", c) } func (s *ClientApi) GetClientList(c *gin.Context) { var pageInfo systemReq.GetClientList err := c.ShouldBindJSON(&pageInfo) if err != nil { response.FailWithMsg(err.Error(), c) return } list, total, err := clientService.GetClientList(pageInfo) if err != nil { global.Logger.Error("获取客户端列表失败!", zap.Error(err)) response.FailWithMsg(err.Error(), c) return } response.OkWithData(response.PageResult{ List: list, Total: total, Page: pageInfo.Current, PageSize: pageInfo.PageSize, }, c) } func (s *ClientApi) Delete(c *gin.Context) { var ids request.IdsReq err := c.ShouldBindJSON(&ids) if err != nil { response.FailWithMsg(err.Error(), c) return } err = clientService.DeleteClientByIds(ids) if err != nil { global.Logger.Error("删除客户端失败!", zap.Error(err)) response.FailWithMsg(err.Error(), c) return } response.OkWithMsg("删除客户端成功!", c) } func (s *ClientApi) Detail(c *gin.Context) { var idInfo request.GetById err := c.ShouldBindJSON(&idInfo) if err != nil { response.FailWithMsg(err.Error(), c) return } client, err := clientService.GetClientById(idInfo.ID) if err != nil { global.Logger.Error("获取客户端详情失败!", zap.Error(err)) response.FailWithMsg(err.Error(), c) return } response.OkWithData(client, c) }