138 lines
3.8 KiB
Go
138 lines
3.8 KiB
Go
package test_data
|
|
|
|
import (
|
|
"gitee.com/golang-module/carbon/v2"
|
|
"github.com/gin-gonic/gin"
|
|
"os"
|
|
"path/filepath"
|
|
"testData/model"
|
|
"testData/model/response"
|
|
"testData/repository"
|
|
test_data "testData/repository/test.data"
|
|
"testData/request"
|
|
"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)
|
|
}
|
|
|
|
// @Tags 数据分析平台-导入文件
|
|
// @Summary 上传结批报告
|
|
// @Security ApiKeyAuth
|
|
// @accept multipart/form-data
|
|
// @Param file formData file true "file"
|
|
// @Produce application/json
|
|
// @Success 200 {string} string "{"success":true,"data":{},"msg":"操作成功"}"
|
|
// @Router /testData/import/finalReport [post]
|
|
func (D *ImportService) ImportFinalReport(c *gin.Context) {
|
|
file, err := c.FormFile("file")
|
|
if err != nil {
|
|
response.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
|
|
filePath := filepath.Join("files", carbon.Now().Format("Y-m"), "结批报告")
|
|
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
|
|
}
|
|
|
|
response.OkWithData(gin.H{"file_path": filePath}, c)
|
|
}
|
|
|
|
// @Tags 数据分析平台-导入文件
|
|
// @Summary 导入结批报告
|
|
// @Security ApiKeyAuth
|
|
// @accept multipart/form-data
|
|
// -// @Param file formData file true "file"
|
|
// @Param data body request.ImportFinalReport true "查询参数"
|
|
// @Produce application/json
|
|
// @Success 200 {string} string "{"success":true,"data":{},"msg":"操作成功"}"
|
|
// @Router /testData/import/finalReport/commit [post]
|
|
func (D *ImportService) ImportFinalReportCommit(c *gin.Context) {
|
|
r := request.ImportFinalReport{}
|
|
_ = c.ShouldBind(&r)
|
|
if msg, ok := utils.ValidateInfo2CN(r); !ok {
|
|
response.FailWithMessage(msg, c)
|
|
return
|
|
}
|
|
test_data.ImportFinalReport(&r)
|
|
response.Ok(c)
|
|
}
|