2023-01-11 18:05:29 +08:00
|
|
|
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"
|
2023-03-24 08:42:28 +08:00
|
|
|
"strconv"
|
2023-01-11 18:05:29 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
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"]
|
2023-03-24 08:42:28 +08:00
|
|
|
val := form.Value["scene"]
|
|
|
|
scene := val[0]
|
2023-01-11 18:05:29 +08:00
|
|
|
if len(scene) < 1 {
|
|
|
|
scene = "other"
|
|
|
|
}
|
2023-03-24 08:42:28 +08:00
|
|
|
datasetId, _ := strconv.ParseInt(form.Value["datasetId"][0], 10, 64)
|
2023-01-11 18:05:29 +08:00
|
|
|
req = proto.UploadFileRequest{
|
2023-03-24 08:42:28 +08:00
|
|
|
Creator: userInfo.UserId,
|
|
|
|
Scene: scene,
|
|
|
|
Files: files,
|
|
|
|
DatasetId: datasetId,
|
2023-01-11 18:05:29 +08:00
|
|
|
}
|
|
|
|
data, err = repo.UploadFile(c, req)
|
|
|
|
go s.SaveLog("文件上传", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
|
|
|
|
return
|
|
|
|
}
|
2023-04-24 15:21:17 +08:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
2023-05-18 11:01:34 +08:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|