package test_data import ( "github.com/gin-gonic/gin" "os" "path/filepath" "testData/model" "testData/model/response" "testData/repository" "testData/utils" ) type IImportService interface { } type ImportService struct{} func InitImportService() *ImportService { return &ImportService{} } // @Tags 解答系统-上传文件管理 // @Summary 上传回答附件 // @Security ApiKeyAuth // @accept multipart/form-data // @Param file formData file true "file" // @Param factory formData string true "factory" // @Param product_name formData string true "product_name" // @Param lot formData string true "lot" // @Param sub_batch formData string true "sub_batch" // @Param step formData string true "step" // @Produce application/json // @Success 200 {string} string "{"success":true,"data":{},"msg":"操作成功"}" // @Router /testData/import/testFile [post] func (D *ImportService) ImportTestFile(c *gin.Context) { file, err := c.FormFile("file") if err != nil { response.FailWithMessage(err.Error(), c) return } filePath := filepath.Join("testData", "导入测试文件") os.MkdirAll(filePath, os.ModePerm) filePath = filepath.Join(filePath, file.Filename) if _, err = os.Stat(filePath); err == nil { response.FailWithMessage(err.Error(), c) return } if err = c.SaveUploadedFile(file, filePath); err != nil { response.FailWithMessage(err.Error(), c) return } factory, isExist := c.GetPostForm("factory") if !isExist { response.FailWithMessage("缺少厂商信息", c) return } productName, isExist := c.GetPostForm("product_name") if !isExist { response.FailWithMessage("缺少产品信息", c) return } lot, isExist := c.GetPostForm("lot") if !isExist { response.FailWithMessage("缺少批次信息", c) return } subBatch, _ := c.GetPostForm("sub_batch") step, isExist := c.GetPostForm("step") if !isExist { response.FailWithMessage("缺少工序信息", c) return } repository.HandleSTS8200Excel(&model.FileText{ Name: file.Filename, Path: filePath, Size: utils.FormatFileSize(float64(file.Size)), Factory: factory, ProductName: productName, Lot: lot, SubBatch: subBatch}, step) response.Ok(c) }