diff --git a/initialization/cron.go b/initialization/cron.go index beb12a5..360b7c6 100644 --- a/initialization/cron.go +++ b/initialization/cron.go @@ -44,3 +44,17 @@ func InitEmailCron() { } c.Start() } + +func InitTestFilesHandlerCron() { + c := cron.New(cron.WithChain(cron.SkipIfStillRunning(cron.DefaultLogger))) + _, err := c.AddFunc("*/30 * * * *", func() { + fmt.Println(carbon.Now().Format("Y-m-d H:i:s") + "TestFilesHandlerCron start") + repository.TestFilesHandlerCron() + fmt.Println(carbon.Now().Format("Y-m-d H:i:s") + "TestFilesHandlerCron finish") + }) + if err != nil { + global.Log.Errorf("InitTestFilesHandlerCron AddFunc error: %s", err) + log.Fatalln(err) + } + c.Start() +} diff --git a/log/message.log b/log/message.log index 9796d36..341c363 100644 --- a/log/message.log +++ b/log/message.log @@ -1651,3 +1651,5 @@ 2024-10-31 15:47:19 INFO | 192.168.0.172 | 200 | 1.5652ms | POST | 未登录 | /testData/chart/pbiSelection 2024-10-31 15:47:22 INFO | 192.168.0.172 | 200 | 1.891ms | POST | 未登录 | /testData/chart/lotSelection 2024-10-31 15:47:22 INFO | 192.168.0.172 | 200 | 2.351ms | POST | 未登录 | /testData/selection +2024-11-01 11:14:20 INFO | 192.168.0.172 | 200 | 5.2831464s | POST | 未登录 | /testData/report/ft +2024-11-01 14:00:34 INFO | 192.168.0.172 | 200 | 55.4809ms | POST | 未登录 | /testData/report/cp diff --git a/main.go b/main.go index ce76f98..9181115 100644 --- a/main.go +++ b/main.go @@ -29,7 +29,7 @@ func main() { initialization.InitCronListCron() initialization.InitEmailCron() - //repository.TestFilesHandlerCron() + //initialization.InitTestFilesHandlerCron() //var fileHandles []*model.FileHandled //global.PostGreSQL.Where("lot = ? AND step = ?", "S3S592", "FT").Find(&fileHandles) diff --git a/repository/test.data/STS8200.go b/repository/test.data/STS8200.go index 0ca10f6..a3054bb 100644 --- a/repository/test.data/STS8200.go +++ b/repository/test.data/STS8200.go @@ -355,22 +355,22 @@ func HandleSTS8200Excel(fileText *model.FileText) { "title_info": string(titleInfo), "size": utils.FormatFileSize(float64(newFile.Size())), }) - report := &model.Report{ - Product: fileText.ProductName, - PBI: fileText.PBI, - Factory: fileText.Factory, - Step: fileText.Procedure, - Lot: fileText.Lot, - SubBatch: fileText.SubBatch, - TestMachine: details["Tester ID"], - TestProgram: testProgram, - WaferID: fileText.ChipNum, + var report *model.Report + if errors.Is(global.PostGreSQL.Where("product = ? AND pbi = ? AND factory = ? AND lot = ? AND step = ? AND sub_batch = ? AND wafer_id = ?", + fileText.ProductName, fileText.PBI, fileText.Factory, fileText.Lot, fileText.Procedure, fileText.SubBatch, fileText.ChipNum).First(&report).Error, gorm.ErrRecordNotFound) { + report = &model.Report{ + Product: fileText.ProductName, + PBI: fileText.PBI, + Factory: fileText.Factory, + Step: fileText.Procedure, + Lot: fileText.Lot, + SubBatch: fileText.SubBatch, + TestMachine: details["Tester ID"], + TestProgram: testProgram, + WaferID: fileText.ChipNum, + } + global.PostGreSQL.Create(&report) } - global.PostGreSQL.Transaction(func(tx *gorm.DB) error { - tx.Create(report) - tx.Find(&report) - return nil - }) if fileText.Procedure == "CP" { SaveCP(report) } else { diff --git a/repository/test.data/report.list.cron.go b/repository/test.data/report.list.cron.go index eb5f613..4cc4dec 100644 --- a/repository/test.data/report.list.cron.go +++ b/repository/test.data/report.list.cron.go @@ -915,7 +915,6 @@ func CronFTList() { passQuantity += idd.Idd13 } } - } } var ftList *model.FTList diff --git a/repository/test.data/report.list.go b/repository/test.data/report.list.go index e8f01c5..3907f3e 100644 --- a/repository/test.data/report.list.go +++ b/repository/test.data/report.list.go @@ -4,6 +4,8 @@ import ( "github.com/shopspring/decimal" "gorm.io/gorm" "sort" + "strconv" + "strings" "testData/global" "testData/model" "testData/request" @@ -423,9 +425,28 @@ func CPList(r *request.CPList) ([]*model.CPShowList, int64) { SoftBinFailMap: make(map[string]float64), HardBinFailMap: make(map[string]float64), } + var waferIDs []string + waferIDGroups := strings.Split(cpList.WaferID, ",") + for _, waferIDGroup := range waferIDGroups { + if strings.Contains(waferIDGroup, "-") { + waferIDGroup = strings.ReplaceAll(waferIDGroup, "#", "") + waferIDLimits := strings.Split(waferIDGroup, "-") + startWaferID, _ := strconv.Atoi(waferIDLimits[0]) + endWaferID, _ := strconv.Atoi(waferIDLimits[1]) + for i := startWaferID; i <= endWaferID; i++ { + if i < 10 { + waferIDs = append(waferIDs, "0"+strconv.Itoa(i)) + } else { + waferIDs = append(waferIDs, strconv.Itoa(i)) + } + } + } else { + waferIDs = append(waferIDs, strings.ReplaceAll(waferIDGroup, "#", "")) + } + } var reports []*model.Report - global.PostGreSQL.Where("pbi = ? AND product = ? AND lot = ? AND step LIKE ?", cpList.PBI, cpList.Product, cpList.Lot, "%CP%"). - Order("pbi"). + global.PostGreSQL.Where("pbi = ? AND product = ? AND lot = ? AND step LIKE ? AND wafer_id IN ?", + cpList.PBI, cpList.Product, cpList.Lot, "%CP%", waferIDs).Order("pbi"). Preload("BinFail", func(db *gorm.DB) *gorm.DB { return db.Where("report_site_id = ?", "0") }).Preload("Site", func(db *gorm.DB) *gorm.DB { @@ -696,9 +717,8 @@ func CPList(r *request.CPList) ([]*model.CPShowList, int64) { }) for hardBin, hardBinQuantity := range hardBinFailMap { - var finalReport *model.FinalReport - global.PostGreSQL.Where("step = ? AND pbi = ? AND lot = ? AND sub_batch = ?", report.Step, report.PBI, report.Lot, - report.SubBatch).Find(&finalReport) + //var finalReport *model.FinalReport + //global.PostGreSQL.Where("step = ? AND pbi = ? AND lot = ?", report.Step, report.PBI, report.Lot).Find(&finalReport) hardBinQuantityDecimal := decimal.NewFromFloat(hardBinQuantity) var quantity float64 var reportProportion string @@ -950,7 +970,7 @@ func FTList(r *request.FTList) ([]*model.FTShowList, int64) { } var ftLists []*model.FTList var total int64 - global.PostGreSQL.Where(sql).Order("order_date desc").Find(&ftLists).Count(&total). + global.PostGreSQL.Debug().Where(sql).Order("order_date desc").Find(&ftLists).Count(&total). Offset(r.Page * r.PageSize).Limit(r.PageSize). Preload("FTListStock").Find(&ftLists) var ftShowLists []*model.FTShowList diff --git a/repository/test.file.handler.go b/repository/test.file.handler.go index 5832647..9f5b92a 100644 --- a/repository/test.file.handler.go +++ b/repository/test.file.handler.go @@ -1,20 +1,19 @@ package repository import ( - "fmt" "testData/global" "testData/model" "testData/repository/test.data" - "time" ) func TestFilesHandlerCron() { - start := time.Now() var fileTexts []*model.FileText - //global.PostGreSQL.Where("processed = ?", false).Group("pbi,lot,procedure").Select("pbi,lot,procedure").Find(&fileTexts) - global.PostGreSQL.Where("processed = ? AND factory != ?", false, "江苏芯德").Order("procedure").Find(&fileTexts) + //global.PostGreSQL.Where("processed = ? AND doubt = ? AND factory != ?", false, false, "江苏芯德").Order("procedure").Find(&fileTexts) + global.PostGreSQL.Where("processed = ? AND doubt = ?", false, false).Order("procedure").Find(&fileTexts) for _, fileText := range fileTexts { test_data.HandleSTS8200Excel(fileText) + global.PostGreSQL.Model(&fileTexts).Updates(map[string]interface{}{ + "processed": true, + }) } - fmt.Println("执行时间:", time.Since(start)) }