package handler import ( "fmt" "github.com/gin-gonic/gin" "hpds-iot-web/internal/proto" "hpds-iot-web/internal/service" "hpds-iot-web/model" e "hpds-iot-web/pkg/err" ) func (s HandlerService) ModelList(c *gin.Context) (data interface{}, err error) { repo := service.NewModelService(s.AppConfig, s.Engine, s.Logger) us, _ := c.Get("operatorUser") userInfo := us.(*model.SystemUser) var req proto.ModelRequest err = c.ShouldBindJSON(&req) if err != nil { go s.SaveLog("ModelList", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "") return nil, e.NewValidErr(err) } if req.Size < 1 { req.Size = 20 } if req.Size > 100 { req.Size = 100 } if req.Page < 1 { req.Page = 1 } data, err = repo.ModelList(c, req) go s.SaveLog("获取模型列表", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "") return } func (s HandlerService) AddModel(c *gin.Context) (data interface{}, err error) { repo := service.NewModelService(s.AppConfig, s.Engine, s.Logger) us, _ := c.Get("operatorUser") userInfo := us.(*model.SystemUser) var req proto.ModelItemRequest err = c.ShouldBindJSON(&req) if err != nil { go s.SaveLog("AddModel", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "") return nil, e.NewValidErr(err) } data, err = repo.AddModel(c, req) go s.SaveLog("新增模型", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "") return } func (s HandlerService) EditModel(c *gin.Context) (data interface{}, err error) { repo := service.NewModelService(s.AppConfig, s.Engine, s.Logger) us, _ := c.Get("operatorUser") userInfo := us.(*model.SystemUser) var req proto.ModelItemRequest err = c.ShouldBindJSON(&req) if err != nil { go s.SaveLog("EditModel", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "") return nil, e.NewValidErr(err) } data, err = repo.EditModel(c, req) go s.SaveLog("新增模型", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "") return } func (s HandlerService) DelModel(c *gin.Context) (data interface{}, err error) { repo := service.NewModelService(s.AppConfig, s.Engine, s.Logger) us, _ := c.Get("operatorUser") userInfo := us.(*model.SystemUser) var req proto.ModelItemRequest err = c.ShouldBindJSON(&req) if err != nil { go s.SaveLog("EditModel", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "") return nil, e.NewValidErr(err) } data, err = repo.DelModel(c, req) go s.SaveLog("删除模型", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "") return } func (s HandlerService) ModelIssue(c *gin.Context) (data interface{}, err error) { repo := service.NewModelService(s.AppConfig, s.Engine, s.Logger) us, _ := c.Get("operatorUser") userInfo := us.(*model.SystemUser) var req proto.ModelIssueRequest err = c.ShouldBindJSON(&req) if err != nil { go s.SaveLog("ModelIssue", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "") return nil, e.NewValidErr(err) } data, err = repo.ModelIssue(c, req) go s.SaveLog("模型下发", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "") return } func (s HandlerService) ModelIssueLog(c *gin.Context) (data interface{}, err error) { repo := service.NewModelService(s.AppConfig, s.Engine, s.Logger) us, _ := c.Get("operatorUser") userInfo := us.(*model.SystemUser) var req proto.ModelIssueLogRequest err = c.ShouldBindJSON(&req) if err != nil { go s.SaveLog("ModelIssueLog", "Manage", "", "", ToString(req), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "") return nil, e.NewValidErr(err) } if req.Size < 1 { req.Size = 20 } if req.Size > 100 { req.Size = 100 } if req.Page < 1 { req.Page = 1 } data, err = repo.ModelIssueLog(c, req) go s.SaveLog("查看模型下发日志", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "") return } func (s HandlerService) GetModelWorkflow(c *gin.Context) (data interface{}, err error) { repo := service.NewModelService(s.AppConfig, s.Engine, s.Logger) us, _ := c.Get("operatorUser") userInfo := us.(*model.SystemUser) var req proto.ModelItemRequest err = c.ShouldBindJSON(&req) if err != nil { go s.SaveLog("ModelIssue", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "") return nil, e.NewValidErr(err) } data, err = repo.GetModelWorkflow(c, req) go s.SaveLog("获取模型工作流", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "") return }