From 055fabba11764ea206d29e79904551ae0983f39a Mon Sep 17 00:00:00 2001 From: jh_peng Date: Sat, 12 Oct 2024 17:16:09 +0800 Subject: [PATCH] =?UTF-8?q?V0=20=E5=AF=BC=E5=85=A5=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E3=80=81=E6=B5=8B=E8=AF=95=E5=8E=82=E9=80=89?= =?UTF-8?q?=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/erp/test.data.go | 28 ++++++++++++++++++++++++++++ api/test.data/upload.go | 25 +++++++++++++++++++++---- initialization/router.go | 2 ++ log/message.log | 15 +++++++++++++++ model/erp.go | 1 + model/excel.go | 3 ++- repository/MT737.go | 3 +++ repository/STS8200.go | 3 +++ repository/TQT601.go | 19 +++++++++++++------ repository/erp/erp.go | 12 ++++++++++++ repository/test.data/upload.go | 6 +++++- router/erp.go | 14 ++++++++++++++ 12 files changed, 119 insertions(+), 12 deletions(-) create mode 100644 api/erp/test.data.go create mode 100644 repository/erp/erp.go create mode 100644 router/erp.go diff --git a/api/erp/test.data.go b/api/erp/test.data.go new file mode 100644 index 0000000..26f9c80 --- /dev/null +++ b/api/erp/test.data.go @@ -0,0 +1,28 @@ +package erp + +import ( + "github.com/gin-gonic/gin" + "testData/model/response" + "testData/repository/erp" +) + +type ITestDataService interface { +} + +type TestDataService struct{} + +func InitTestDataService() *TestDataService { + return &TestDataService{} +} + +// @Tags 数据分析平台 +// @Summary 测试文件导入-测试厂选项 +// @Security ApiKeyAuth +// @accept application/json +// @Produce application/json +// -// @Param data body request.QuerySelection true "查询参数" +// @Success 200 {string} string "{"success":true,"data":{},"msg":"操作成功"}" +// @Router /testData/import/testFile/factorySelection [get] +func (S *TestDataService) FactorySelection(c *gin.Context) { + response.OkWithData(erp.GetFactorySelections(), c) +} diff --git a/api/test.data/upload.go b/api/test.data/upload.go index 25daecc..e11fe74 100644 --- a/api/test.data/upload.go +++ b/api/test.data/upload.go @@ -2,6 +2,7 @@ package test_data import ( "github.com/gin-gonic/gin" + "mime/multipart" "os" "path/filepath" "strings" @@ -36,7 +37,11 @@ func (D *UploadService) UploadAnswerFile(c *gin.Context) { response.FailWithMessage(err.Error(), c) return } - files := form.File["file"] + 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 @@ -57,11 +62,22 @@ func (D *UploadService) UploadAnswerFile(c *gin.Context) { return } factory := form.Value["factory"][0] + var subBatch string if len(form.Value["sub_batch"]) < 1 { - response.FailWithMessage("缺少子批次", c) + subBatch = "" + } else { + subBatch = form.Value["sub_batch"][0] + } + if len(form.Value["step"]) < 1 { + response.FailWithMessage("缺少工序", c) return } - 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 @@ -79,7 +95,7 @@ func (D *UploadService) UploadAnswerFile(c *gin.Context) { fileTexts := make([]*model.FileText, 0) for _, file := range files { suffix := file.Filename[strings.LastIndex(file.Filename, "."):] - fileName := time.Now().Format("20060102150405") + suffix + 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 { @@ -94,6 +110,7 @@ func (D *UploadService) UploadAnswerFile(c *gin.Context) { PBI: pbi, Lot: lot, SubBatch: subBatch, + WaferID: waferID, }) } diff --git a/initialization/router.go b/initialization/router.go index c9f7d83..1d6320d 100644 --- a/initialization/router.go +++ b/initialization/router.go @@ -32,6 +32,8 @@ func InitRouter() *gin.Engine { router.InitWarningRouter(testData) router.InitFinalReportExcelRouter(testData) router.InitImportRouter(testData) + + router.InitTestDataERPRouter(testData) } testDataUpload := r.Group("testData") testDataUploadService := testdata.InitUpload() diff --git a/log/message.log b/log/message.log index 76bfe5b..d26d224 100644 --- a/log/message.log +++ b/log/message.log @@ -1593,3 +1593,18 @@ 2024-10-11 14:50:17 INFO | 192.168.0.172 | 200 | 3.3515ms | POST | 未登录 | /testData/upload 2024-10-11 14:50:17 INFO | 192.168.0.172 | 200 | 16.5018ms | POST | 未登录 | /testData/upload 2024-10-11 15:00:15 INFO | 192.168.0.172 | 200 | 9m25.648566s | POST | 未登录 | /testData/upload +2024-10-12 10:05:41 INFO | 192.168.0.172 | 200 | 1.2534ms | POST | 未登录 | /testData/upload +2024-10-12 10:05:41 INFO | 192.168.0.172 | 200 | 0s | POST | 未登录 | /testData/upload +2024-10-12 10:05:41 INFO | 192.168.0.172 | 200 | 540.4µs | POST | 未登录 | /testData/upload +2024-10-12 10:05:41 INFO | 192.168.0.172 | 200 | 3.1513ms | POST | 未登录 | /testData/upload +2024-10-12 10:05:58 INFO | 192.168.0.172 | 200 | 24.0818ms | POST | 未登录 | /testData/upload +2024-10-12 10:05:58 INFO | 192.168.0.172 | 200 | 33.3799ms | POST | 未登录 | /testData/upload +2024-10-12 10:05:58 INFO | 192.168.0.172 | 200 | 39.0893ms | POST | 未登录 | /testData/upload +2024-10-12 10:05:58 INFO | 192.168.0.172 | 200 | 37.9752ms | POST | 未登录 | /testData/upload +2024-10-12 10:17:20 INFO | 192.168.0.172 | 200 | 1m53.7931364s | POST | 未登录 | /testData/upload +2024-10-12 10:18:05 INFO | 192.168.0.172 | 200 | 31.1169547s | POST | 未登录 | /testData/upload +2024-10-12 10:22:49 INFO | 192.168.0.172 | 200 | 4m11.2095059s | POST | 未登录 | /testData/upload +2024-10-12 10:23:19 INFO | 192.168.0.172 | 200 | 19.8354639s | POST | 未登录 | /testData/upload +2024-10-12 10:24:07 INFO | 192.168.0.172 | 200 | 34.1357627s | POST | 未登录 | /testData/upload +2024-10-12 10:25:24 INFO | 192.168.0.172 | 200 | 9.8706437s | POST | 未登录 | /testData/upload +2024-10-12 11:07:57 INFO | 192.168.0.172 | 200 | 3.6585071s | POST | 未登录 | /testData/upload diff --git a/model/erp.go b/model/erp.go index 56024a8..ebf487e 100644 --- a/model/erp.go +++ b/model/erp.go @@ -109,6 +109,7 @@ func (RvvFile) TableName() string { return "rvv_file" } type PmcFile struct { Pmc01 string `json:"pmc01"` // 厂商编号 + Pmc02 string `json:"pmc02"` // 厂商类型 Pmc03 string `json:"pmc03"` // 厂商名称 } diff --git a/model/excel.go b/model/excel.go index 5540fc4..ad647d0 100644 --- a/model/excel.go +++ b/model/excel.go @@ -18,7 +18,8 @@ type FileText struct { ProductName string `json:"product_name"` PBI string `json:"pbi"` Lot string `json:"lot" gorm:"comment:批次号"` - SubBatch string `json:"sub_batch" gorm:"子批次"` + SubBatch string `json:"sub_batch" gorm:"comment:子批次"` + WaferID string `json:"wafer_id" gorm:"comment:片号"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"-"` DeletedAt gorm.DeletedAt `gorm:"index" json:"-"` diff --git a/repository/MT737.go b/repository/MT737.go index a95f8c3..b771027 100644 --- a/repository/MT737.go +++ b/repository/MT737.go @@ -184,6 +184,9 @@ func MT737(summary, dataLog *model.FileText, step string) { log.Println("创建文件失败:", err) return } + if summary.WaferID != "" { + waferID = summary.WaferID + } if errors.Is(global.PostGreSQL.Where("name = ?", fileName).First(&fileHandled).Error, gorm.ErrRecordNotFound) { global.PostGreSQL.Create(&model.FileHandled{ Name: fileName, diff --git a/repository/STS8200.go b/repository/STS8200.go index 1010cc2..b6998f2 100644 --- a/repository/STS8200.go +++ b/repository/STS8200.go @@ -269,6 +269,9 @@ func HandleSTS8200Excel(fileText *model.FileText, step string) { log.Println("创建文件失败:", err) return } + if fileText.WaferID != "" { + waferID = fileText.WaferID + } if errors.Is(global.PostGreSQL.Where("name = ?", fileName).First(&fileHandled).Error, gorm.ErrRecordNotFound) { global.PostGreSQL.Create(&model.FileHandled{ Name: fileName, diff --git a/repository/TQT601.go b/repository/TQT601.go index dd6afde..84b406c 100644 --- a/repository/TQT601.go +++ b/repository/TQT601.go @@ -205,6 +205,9 @@ func HandlerTQT601Excel(fileText *model.FileText, step string) { } details["lot"] = fileText.Name[start+1 : end] } + if fileText.Lot != "" { + details["lot"] = fileText.Lot + } testProgram := details["TestProgram"] fileName := details["product"] + "_" + details["lot"] + "_" + details["Test_Code"] + ".csv" utils.MakeDir("/testData/test") @@ -221,12 +224,15 @@ func HandlerTQT601Excel(fileText *model.FileText, step string) { } if errors.Is(global.PostGreSQL.Where("name = ?", fileName).First(&fileHandled).Error, gorm.ErrRecordNotFound) { global.PostGreSQL.Create(&model.FileHandled{ - Name: fileName, - Path: filePath, - Size: "", - Factory: fileText.Factory, - Product: details["product"], - Step: details["Test_Code"], + Name: fileName, + Path: filePath, + Size: "", + Factory: fileText.Factory, + PBI: fileText.PBI, + Product: details["product"], + Step: details["Test_Code"], + //Lot: fileText.Lot, + SubBatch: fileText.SubBatch, Lot: details["lot"], TestMachineModel: "TQT601", TestMachine: details["TesterNO."], @@ -234,6 +240,7 @@ func HandlerTQT601Excel(fileText *model.FileText, step string) { BeginningTime: details["Beginning Time"], EndingTime: details["Ending Time"], TitleInfo: string(titleInfo), + WaferID: fileText.WaferID, }) } } diff --git a/repository/erp/erp.go b/repository/erp/erp.go new file mode 100644 index 0000000..a94f5bd --- /dev/null +++ b/repository/erp/erp.go @@ -0,0 +1,12 @@ +package erp + +import ( + "testData/global" + "testData/model" +) + +func GetFactorySelections() []string { + var factories []string + global.Oracle.Model(&model.PmcFile{}).Where("pmc02 IN ?", []string{"AB", "CPFT", "FT"}).Select("pmc03").Find(&factories) + return factories +} diff --git a/repository/test.data/upload.go b/repository/test.data/upload.go index 2be48e1..a6c6334 100644 --- a/repository/test.data/upload.go +++ b/repository/test.data/upload.go @@ -2,6 +2,7 @@ package test_data import ( "errors" + "sort" "testData/model" "testData/repository" ) @@ -10,6 +11,9 @@ func HandleUploadFiles(fileTexts []*model.FileText, step, machine string) error if step == "" { return errors.New("未输入工序") } + sort.Slice(fileTexts, func(i, j int) bool { + return fileTexts[i].Name < fileTexts[j].Name + }) if machine == "STS8200" { for _, fileText := range fileTexts { repository.HandleSTS8200Excel(fileText, step) @@ -20,7 +24,7 @@ func HandleUploadFiles(fileTexts []*model.FileText, step, machine string) error } } else if machine == "MT737" { for i := 0; i < len(fileTexts)/2; i++ { - repository.MT737(fileTexts[2*i], fileTexts[2*i+1], step) + repository.MT737(fileTexts[2*i+1], fileTexts[2*i], step) } } return nil diff --git a/router/erp.go b/router/erp.go new file mode 100644 index 0000000..5fd5eb8 --- /dev/null +++ b/router/erp.go @@ -0,0 +1,14 @@ +package router + +import ( + "github.com/gin-gonic/gin" + test_data "testData/api/erp" +) + +func InitTestDataERPRouter(R *gin.RouterGroup) { + testDataService := test_data.InitTestDataService() + testDataGroup := R.Group("") + { + testDataGroup.GET("import/testFile/factorySelection", testDataService.FactorySelection) + } +}