From 4839476d264e55a387beb8f9a0c6998de7e9c836 Mon Sep 17 00:00:00 2001 From: jh_peng Date: Tue, 19 Nov 2024 09:59:40 +0800 Subject: [PATCH] V0 --- repository/test.data/report.go | 126 ++++++++++++++++++--------------- 1 file changed, 70 insertions(+), 56 deletions(-) diff --git a/repository/test.data/report.go b/repository/test.data/report.go index 9ff746b..6ad65ff 100644 --- a/repository/test.data/report.go +++ b/repository/test.data/report.go @@ -612,43 +612,46 @@ func SaveCP(report *model.Report) { //pbi, product, lot, waferID string, } func SaveFT(report *model.Report) { //pbi, product, lot, subBatch string, - var ftFile *model.FileHandled + var ftFiles []*model.FileHandled global.PostGreSQL.Where("pbi = ? AND product = ? AND lot = ? AND sub_batch = ? AND step = ?", - report.PBI, report.Product, report.Lot, report.SubBatch, "FT").Find(&ftFile) - if _, err := os.Stat(ftFile.Path); err != nil { - log.Println("该文件不存在") - } - - ft, err := os.Open(ftFile.Path) - if err != nil { - log.Println(ftFile.Path, ":", err) - return - } - defer ft.Close() - scanner := bufio.NewScanner(ft) + report.PBI, report.Product, report.Lot, report.SubBatch, "FT").Find(&ftFiles) datas := make([][]string, 0) fieldMap := make(map[string]int) - for scanner.Scan() { - line := scanner.Text() - s := strings.Split(line, ",") - datas = append(datas, s[:len(s)-1]) - if len(datas) == 1 { - for index, cell := range s { - if index == len(s)-1 { - continue + sbinHbinMap := make(map[string]string) + for _, ftFile := range ftFiles { + fileDatas := make([][]string, 0) + if _, err := os.Stat(ftFile.Path); err != nil { + log.Println("该文件不存在") + } + + ft, err := os.Open(ftFile.Path) + if err != nil { + log.Println(ftFile.Path, ":", err) + return + } + scanner := bufio.NewScanner(ft) + for scanner.Scan() { + line := scanner.Text() + s := strings.Split(line, ",") + fileDatas = append(fileDatas, s[:len(s)-1]) + if len(fileDatas) == 1 { + for index, cell := range s { + if index == len(s)-1 { + continue + } + fieldMap[cell] = index } - fieldMap[cell] = index } } - } - if len(datas) >= 1 { - datas = datas[1:] + if len(datas) >= 1 { + datas = append(datas, fileDatas[1:]...) + } + ft.Close() + //sbinHbinMap := make(map[string]map[string]string) + sbinHbinByte := []byte(ftFile.SbinHbin) + _ = json.Unmarshal(sbinHbinByte, &sbinHbinMap) } - //sbinHbinMap := make(map[string]map[string]string) - sbinHbinMap := make(map[string]string) - sbinHbinByte := []byte(ftFile.SbinHbin) - _ = json.Unmarshal(sbinHbinByte, &sbinHbinMap) binCounter := make(map[string]int) siteCounters := make(map[string]map[string]int) for _, data := range datas { @@ -659,35 +662,41 @@ func SaveFT(report *model.Report) { //pbi, product, lot, subBatch string, siteCounters[data[fieldMap["SITE_NUM"]]][data[fieldMap["SOFT_BIN"]]]++ } - var rtFile *model.FileHandled + var rtFiles []*model.FileHandled var passCounter int if !errors.Is(global.PostGreSQL.Where("pbi = ? AND product = ? AND lot = ? AND sub_batch = ? AND step = ?", report.PBI, report.Product, report.Lot, report.SubBatch, "RT"). - Find(&rtFile).Error, gorm.ErrRecordNotFound) { - rt, err := os.Open(rtFile.Path) - if err != nil { - log.Println(err) - } - defer rt.Close() - rtScanner := bufio.NewScanner(rt) + Find(&rtFiles).Error, gorm.ErrRecordNotFound) { + rtDatas := make([][]string, 0) rtFieldMap := make(map[string]int) - for rtScanner.Scan() { - line := rtScanner.Text() - s := strings.Split(line, ",") - rtDatas = append(rtDatas, s[:len(s)-1]) - if len(rtDatas) == 1 { - for index, cell := range s { - if index == len(s)-1 { - continue + + for _, rtFile := range rtFiles { + fileDatas := make([][]string, 0) + rt, err := os.Open(rtFile.Path) + if err != nil { + log.Println(err) + } + rtScanner := bufio.NewScanner(rt) + for rtScanner.Scan() { + line := rtScanner.Text() + s := strings.Split(line, ",") + fileDatas = append(fileDatas, s[:len(s)-1]) + if len(fileDatas) == 1 { + for index, cell := range s { + if index == len(s)-1 { + continue + } + rtFieldMap[cell] = index } - rtFieldMap[cell] = index } } + rt.Close() + if len(rtDatas) >= 1 { + rtDatas = append(rtDatas, fileDatas[1:]...) + } } - if len(rtDatas) >= 1 { - rtDatas = rtDatas[1:] - } + for _, rtData := range rtDatas { if rtData[rtFieldMap["SOFT_BIN"]] == "1" { passCounter++ @@ -715,13 +724,18 @@ func SaveFT(report *model.Report) { //pbi, product, lot, subBatch string, }) } var siteReports []*model.ReportSites - for site := range siteCounters { - siteReports = append(siteReports, &model.ReportSites{ - ReportID: report.ID, - Site: site, - }) - } - global.PostGreSQL.Create(&siteReports) + global.PostGreSQL.Transaction(func(tx *gorm.DB) error { + for site := range siteCounters { + siteReports = append(siteReports, &model.ReportSites{ + ReportID: report.ID, + Site: site, + }) + + tx.Where("report_id = ?", report.ID).Delete(&model.ReportSites{}) + tx.Create(&siteReports) + } + return nil + }) siteReports = []*model.ReportSites{} global.PostGreSQL.Where("report_id = ?", report.ID).Find(&siteReports) for _, siteReport := range siteReports {