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" "strconv" ) func (s HandlerService) UploadFile(c *gin.Context) (data interface{}, err error) { repo := service.NewFileService(s.AppConfig, s.Engine, s.Logger) us, _ := c.Get("operatorUser") userInfo := us.(*model.SystemUser) var req proto.UploadFileRequest form, err := c.MultipartForm() if err != nil { go s.SaveLog("UploadFile", "Manage", "", "", userInfo.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "") return nil, e.NewValidErr(err) } files := form.File["file"] val := form.Value["scene"] scene := val[0] if len(scene) < 1 { scene = "other" } datasetId, _ := strconv.ParseInt(form.Value["datasetId"][0], 10, 64) req = proto.UploadFileRequest{ Creator: userInfo.UserId, Scene: scene, Files: files, DatasetId: datasetId, } data, err = repo.UploadFile(c, req) go s.SaveLog("文件上传", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "") return } func (s HandlerService) FileList(c *gin.Context) (data interface{}, err error) { repo := service.NewFileService(s.AppConfig, s.Engine, s.Logger) us, _ := c.Get("operatorUser") userInfo := us.(*model.SystemUser) var req proto.DatasetItemRequest err = c.ShouldBindJSON(&req) if err != nil { go s.SaveLog("FileList", "FileManage", "", "", 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 > 1000 { req.Size = 1000 } if req.Page < 1 { req.Page = 1 } data, err = repo.FileList(c, req) go s.SaveLog("获取数据集详情", "FileManage", "", "", ToString(data), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "") return } func (s HandlerService) FileLabel(c *gin.Context) (data interface{}, err error) { repo := service.NewFileService(s.AppConfig, s.Engine, s.Logger) us, _ := c.Get("operatorUser") userInfo := us.(*model.SystemUser) var req proto.FileLabelRequest err = c.ShouldBindJSON(&req) if err != nil { go s.SaveLog("FileLabel", "FileManage", "", "", ToString(req), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "") return nil, e.NewValidErr(err) } data, err = repo.FileLabel(c, req) go s.SaveLog("标注文件", "FileManage", "", "", ToString(data), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "") return }