119 lines
3.1 KiB
Go
119 lines
3.1 KiB
Go
package test_data
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"mime/multipart"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testData/model"
|
|
"testData/model/response"
|
|
test_data "testData/repository/test.data"
|
|
"time"
|
|
)
|
|
|
|
type UploadService struct {
|
|
}
|
|
|
|
func InitUpload() *UploadService {
|
|
return &UploadService{}
|
|
}
|
|
|
|
// @Tags 数据分析平台
|
|
// @Summary 上传没录入文件
|
|
// @Security ApiKeyAuth
|
|
// @accept multipart/form-data
|
|
// @Param file formData file true "file"
|
|
// @Param value formData file true "product_name"
|
|
// @Param value formData file true "lot"
|
|
// @Param value formData file true "sub_batch"
|
|
// -// @Param data body request.SelectionLimit true "参数极限"
|
|
// @Produce application/json
|
|
// @Success 200 {string} string "{"success":true,"data":{},"msg":"操作成功"}"
|
|
// @Router /testData/upload [post]
|
|
func (D *UploadService) UploadAnswerFile(c *gin.Context) {
|
|
form, err := c.MultipartForm()
|
|
if err != nil {
|
|
response.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
filesMap := form.File
|
|
var files []*multipart.FileHeader
|
|
for _, v := range filesMap {
|
|
files = append(files, v...)
|
|
}
|
|
if len(form.Value["pbi"]) < 1 {
|
|
response.FailWithMessage("请输入PBI信息", c)
|
|
return
|
|
}
|
|
pbi := form.Value["pbi"][0]
|
|
if len(form.Value["product"]) < 1 {
|
|
response.FailWithMessage("请输入产品信息", c)
|
|
return
|
|
}
|
|
productName := form.Value["product"][0]
|
|
if len(form.Value["lot"]) < 1 {
|
|
response.FailWithMessage("请输入批次信息", c)
|
|
return
|
|
}
|
|
lot := form.Value["lot"][0]
|
|
if len(form.Value["factory"]) < 1 {
|
|
response.FailWithMessage("请选择测试厂信息", c)
|
|
return
|
|
}
|
|
factory := form.Value["factory"][0]
|
|
var subBatch string
|
|
if len(form.Value["sub_batch"]) < 1 {
|
|
subBatch = ""
|
|
} else {
|
|
subBatch = form.Value["sub_batch"][0]
|
|
}
|
|
var waferID string
|
|
if len(form.Value["wafer_id"]) < 1 {
|
|
waferID = ""
|
|
} else {
|
|
waferID = form.Value["wafer_id"][0]
|
|
}
|
|
if len(form.Value["step"]) < 1 {
|
|
response.FailWithMessage("缺少工序", c)
|
|
return
|
|
}
|
|
step := form.Value["step"][0]
|
|
if len(form.Value["test_machine"]) < 1 {
|
|
response.FailWithMessage("请选择机台类型", c)
|
|
return
|
|
}
|
|
machine := form.Value["test_machine"][0]
|
|
if (lot == "" && subBatch == "") || productName == "" || step == "" || machine == "" {
|
|
response.FailWithMessage("必要信息不全", c)
|
|
return
|
|
}
|
|
fileTexts := make([]*model.FileText, 0)
|
|
for _, file := range files {
|
|
suffix := file.Filename[strings.LastIndex(file.Filename, "."):]
|
|
fileName := file.Filename[:strings.LastIndex(file.Filename, ".")] + time.Now().Format("20060102150405") + suffix
|
|
os.MkdirAll("/testData/siyuanUpload", os.ModePerm)
|
|
filePath := filepath.Join("/testData/siyuanUpload", fileName)
|
|
if err = c.SaveUploadedFile(file, filePath); err != nil {
|
|
response.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
fileTexts = append(fileTexts, &model.FileText{
|
|
Name: fileName,
|
|
Path: filePath,
|
|
Factory: factory,
|
|
ProductName: productName,
|
|
PBI: pbi,
|
|
Lot: lot,
|
|
SubBatch: subBatch,
|
|
WaferID: waferID,
|
|
})
|
|
}
|
|
|
|
if err = test_data.HandleUploadFiles(fileTexts, step, machine); err != nil {
|
|
response.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
response.Ok(c)
|
|
}
|