V0 自动抓取测试文件处理

This commit is contained in:
jh_peng 2024-10-31 18:39:17 +08:00
parent 42187b33d0
commit c261e37772
18 changed files with 251 additions and 155 deletions

View File

@ -7,7 +7,6 @@ import (
"path/filepath" "path/filepath"
"testData/model" "testData/model"
"testData/model/response" "testData/model/response"
"testData/repository"
test_data "testData/repository/test.data" test_data "testData/repository/test.data"
"testData/request" "testData/request"
"testData/utils" "testData/utils"
@ -75,14 +74,15 @@ func (D *ImportService) ImportTestFile(c *gin.Context) {
return return
} }
repository.HandleSTS8200Excel(&model.FileText{ test_data.HandleSTS8200Excel(&model.FileText{
Name: file.Filename, Name: file.Filename,
Path: filePath, Path: filePath,
Size: utils.FormatFileSize(float64(file.Size)), //Size: utils.FormatFileSize(float64(file.Size)),
Factory: factory, Factory: factory,
ProductName: productName, ProductName: productName,
Lot: lot, Lot: lot,
SubBatch: subBatch}, step) SubBatch: subBatch,
Procedure: step})
response.Ok(c) response.Ok(c)
} }

View File

@ -106,7 +106,8 @@ func (D *UploadService) UploadAnswerFile(c *gin.Context) {
PBI: pbi, PBI: pbi,
Lot: lot, Lot: lot,
SubBatch: subBatch, SubBatch: subBatch,
WaferID: waferID, ChipNum: waferID,
Procedure: step,
}) })
} }

View File

@ -39,6 +39,6 @@ func InitPostgres() {
postgresDB.SetConnMaxLifetime(time.Hour) postgresDB.SetConnMaxLifetime(time.Hour)
_ = db.AutoMigrate(&model.FileHandled{}) _ = db.AutoMigrate(&model.FileHandled{})
global.PostGreSQL = db global.PostGreSQL = db
_ = global.PostGreSQL.AutoMigrate(&model.FileHandled{}) _ = global.PostGreSQL.AutoMigrate(&model.FileHandled{}, &model.Report{})
} }
} }

View File

@ -1640,3 +1640,14 @@
2024-10-30 11:33:22 INFO | 192.168.0.172 | 200 | 2m21.7066369s | POST | 未登录 | /testData/report/ft 2024-10-30 11:33:22 INFO | 192.168.0.172 | 200 | 2m21.7066369s | POST | 未登录 | /testData/report/ft
2024-10-30 11:33:29 INFO | 192.168.0.172 | 200 | 3.7144008s | POST | 未登录 | /testData/report/ft 2024-10-30 11:33:29 INFO | 192.168.0.172 | 200 | 3.7144008s | POST | 未登录 | /testData/report/ft
2024-10-30 11:34:02 INFO | 192.168.0.172 | 200 | 47.8578ms | POST | 未登录 | /testData/report/cp 2024-10-30 11:34:02 INFO | 192.168.0.172 | 200 | 47.8578ms | POST | 未登录 | /testData/report/cp
2024-10-31 15:36:47 INFO | 192.168.0.172 | 200 | 2.121ms | POST | 未登录 | /testData/report/probabilitySelection/product
2024-10-31 15:36:58 INFO | 192.168.0.172 | 200 | 1.1216ms | POST | 未登录 | /testData/report/probabilitySelection/product
2024-10-31 15:38:17 INFO | 192.168.0.172 | 200 | 1.3155ms | POST | 未登录 | /testData/report/probabilitySelection/product
2024-10-31 15:38:46 INFO | 192.168.0.172 | 200 | 2.5735ms | POST | 未登录 | /testData/report/probabilitySelection/product
2024-10-31 15:46:41 INFO | 192.168.0.172 | 200 | 7m49.8073103s | POST | 未登录 | /testData/report/probabilitySelection/product
2024-10-31 15:46:41 INFO | 192.168.0.172 | 200 | 3.0877ms | POST | 未登录 | /testData/report/fTPassProbabilityByFactory
2024-10-31 15:46:57 INFO | 192.168.0.172 | 200 | 3.3459679s | POST | 未登录 | /testData/chart/productSelection
2024-10-31 15:47:17 INFO | 192.168.0.172 | 200 | 2.5755ms | POST | 未登录 | /testData/chart/lotSelection
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

View File

@ -29,6 +29,7 @@ func main() {
initialization.InitCronListCron() initialization.InitCronListCron()
initialization.InitEmailCron() initialization.InitEmailCron()
//repository.TestFilesHandlerCron()
//var fileHandles []*model.FileHandled //var fileHandles []*model.FileHandled
//global.PostGreSQL.Where("lot = ? AND step = ?", "S3S592", "FT").Find(&fileHandles) //global.PostGreSQL.Where("lot = ? AND step = ?", "S3S592", "FT").Find(&fileHandles)

View File

@ -9,17 +9,19 @@ type FileText struct {
ID uint `gorm:"primaryKey" json:"id"` ID uint `gorm:"primaryKey" json:"id"`
Name string `json:"name" gorm:"comment:文件名;index"` Name string `json:"name" gorm:"comment:文件名;index"`
Path string `json:"path" gorm:"comment:文件路径;index"` Path string `json:"path" gorm:"comment:文件路径;index"`
Size string `json:"size" gorm:"comment:文件大小"` ModTime time.Time `json:"modtime" gorm:"comment:文件修改时间"`
ModTime int64 `json:"modtime" gorm:"comment:文件修改时间"`
IsCsv bool `json:"isCsv" gorm:"comment:是否为csv文件"`
Sha1 string `json:"sha1" gorm:"comment:文件sha1值"` Sha1 string `json:"sha1" gorm:"comment:文件sha1值"`
Factory string `json:"factory" gorm:"comment:厂商"` Factory string `json:"factory" gorm:"comment:厂商"`
Processed bool `json:"processed" gorm:"comment:是否已处理"` Processed bool `json:"processed" gorm:"comment:是否已处理"`
ProductName string `json:"product_name"` ProductName string `json:"product_name"`
PathLot string `json:"path_lot" gorm:"comment:文件路径中的批号"`
Lot string `json:"lot" gorm:"comment:真实批号"`
SubBatch string `json:"sub_batch" gorm:"comment:子批次号"`
PBI string `json:"pbi"` PBI string `json:"pbi"`
Lot string `json:"lot" gorm:"comment:批次号"` Procedure string `json:"procedure"`
SubBatch string `json:"sub_batch" gorm:"comment:子批次"` IsRead bool `json:"is_read" gorm:"comment:是否已从文件中读产品名、批号等信息"`
WaferID string `json:"wafer_id" gorm:"comment:片号"` ChipNum string `json:"chipnum" gorm:"comment:晶圆片号"`
Doubt bool `json:"doubt" gorm:"comment:文件名中取的值存在疑义,需要人工判断"`
CreatedAt time.Time `json:"created_at"` CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"-"` UpdatedAt time.Time `json:"-"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"` DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`

View File

@ -28,13 +28,13 @@ func ChangDian() {
if err != nil { if err != nil {
log.Println(err) log.Println(err)
} }
var step string //var step string
if strings.Contains(fileText.Name, "RT") { //if strings.Contains(fileText.Name, "RT") {
step = "RT" // step = "RT"
} else { //} else {
step = "FT" // step = "FT"
} //}
HandleSTS8200Excel(fileText, step) //HandleSTS8200Excel(fileText, step)
file.Close() file.Close()
} }
} }

View File

@ -1,7 +1,6 @@
package repository package repository
import ( import (
"strings"
"testData/global" "testData/global"
"testData/model" "testData/model"
) )
@ -13,13 +12,13 @@ func ChengTe() {
Where("factory = ?", "chengte"). Where("factory = ?", "chengte").
Where("name LIKE ? AND name NOT LIKE ? AND name NOT LIKE ? AND name NOT LIKE ? AND name NOT LIKE ?", Where("name LIKE ? AND name NOT LIKE ? AND name NOT LIKE ? AND name NOT LIKE ? AND name NOT LIKE ?",
"%FT%", "%FT_LV%", "%FT_EQC%", "%FT_QC%", "%FT_NT%").Find(&fileTexts) "%FT%", "%FT_LV%", "%FT_EQC%", "%FT_QC%", "%FT_NT%").Find(&fileTexts)
for _, fileText := range fileTexts { //for _, fileText := range fileTexts {
var step string //var step string
if strings.Contains(fileText.Name, "RT") { //if strings.Contains(fileText.Name, "RT") {
step = "RT" // step = "RT"
} else { //} else {
step = "FT" // step = "FT"
} //}
HandlerTQT601Excel(fileText, step) //test_data.HandlerTQT601Excel(fileText, step)
} //}
} }

View File

@ -21,25 +21,25 @@ func SaiMeiKe() {
strings.ToLower(path.Ext(fileText.Name)) != ".xls" && strings.ToLower(path.Ext(fileText.Name)) != ".xlsx" { strings.ToLower(path.Ext(fileText.Name)) != ".xls" && strings.ToLower(path.Ext(fileText.Name)) != ".xlsx" {
continue continue
} }
var step string //var step string
if len(fileText.Name) > 8 { //if len(fileText.Name) > 8 {
if fileText.Name[len(fileText.Name)-7:] == "cp1.csv" { // if fileText.Name[len(fileText.Name)-7:] == "cp1.csv" {
step = "CP1" // step = "CP1"
} else if fileText.Name[len(fileText.Name)-7:] == "cp2.csv" { // } else if fileText.Name[len(fileText.Name)-7:] == "cp2.csv" {
step = "CP2" // step = "CP2"
} // }
} //}
messages := strings.Split(fileText.Name, "_") //messages := strings.Split(fileText.Name, "_")
if len(messages) >= 3 { //if len(messages) >= 3 {
if strings.Contains(messages[2], "r") { // if strings.Contains(messages[2], "r") {
step = "RT" // step = "RT"
} else if strings.Contains(messages[2], "t") { // } else if strings.Contains(messages[2], "t") {
step = "FT" // step = "FT"
} // }
} //}
if step == "" { //if step == "" {
continue // continue
} //}
HandleSTS8200Excel(fileText, step) //HandleSTS8200Excel(fileText, step)
} }
} }

View File

@ -1,4 +1,4 @@
package repository package test_data
import ( import (
"bytes" "bytes"
@ -22,7 +22,7 @@ import (
"testData/utils" "testData/utils"
) )
func MT737(summary, dataLog *model.FileText, step string) { func MT737(summary, dataLog *model.FileText) {
summaryRows := make([][]string, 0) summaryRows := make([][]string, 0)
if strings.ToLower(path.Ext(summary.Name)) == ".csv" { if strings.ToLower(path.Ext(summary.Name)) == ".csv" {
csvBytes, err := ioutil.ReadFile(summary.Path) csvBytes, err := ioutil.ReadFile(summary.Path)
@ -154,25 +154,26 @@ func MT737(summary, dataLog *model.FileText, step string) {
} }
} }
if details["Test_Code"] == "" { //if details["Test_Code"] == "" {
details["Test_Code"] = step // details["Test_Code"] = step
} //}
sbinHbin, _ := json.Marshal(&sBinMap) sbinHbin, _ := json.Marshal(&sBinMap)
fileName := summary.ProductName + "_" + summary.Lot + "_" + details["Test_Code"] + ".csv" fileName := summary.ProductName + "_" + summary.Lot + "_" + details["Test_Code"] + ".csv"
var waferID string var waferID string
if summary.Factory == "yaxinwei" { waferID = summary.ChipNum
if step == "CP1" || step == "CP2" { //if summary.Factory == "yaxinwei" {
if summary.Procedure == "CP1" || summary.Procedure == "CP2" {
length := len(summary.Name) length := len(summary.Name)
waferID = summary.Name[length-10 : length-8] waferID = summary.Name[length-10 : length-8]
fileName = summary.ProductName + "_" + summary.Lot + "_" + waferID + "_" + details["Test_Code"] + ".csv" fileName = summary.ProductName + "_" + summary.Lot + "_" + waferID + "_" + summary.Procedure + ".csv"
} else { } else {
if strings.Index(summary.SubBatch, "-") != strings.LastIndex(summary.SubBatch, "-") { if strings.Index(summary.SubBatch, "-") != strings.LastIndex(summary.SubBatch, "-") {
summary.SubBatch = summary.SubBatch[:strings.LastIndex(summary.SubBatch, "-")] summary.SubBatch = summary.SubBatch[:strings.LastIndex(summary.SubBatch, "-")]
} }
fileName = summary.ProductName + "_" + summary.Lot + "_" + summary.SubBatch + "_" + details["Test_Code"] + ".csv" fileName = summary.ProductName + "_" + summary.Lot + "_" + summary.SubBatch + "_" + summary.Procedure + ".csv"
}
} }
//}
dirPath := filepath.Join("/testData/test/" + summary.Factory) dirPath := filepath.Join("/testData/test/" + summary.Factory)
utils.MakeDir(dirPath) utils.MakeDir(dirPath)
filePath := filepath.Join(dirPath, fileName) filePath := filepath.Join(dirPath, fileName)
@ -184,8 +185,8 @@ func MT737(summary, dataLog *model.FileText, step string) {
log.Println("创建文件失败:", err) log.Println("创建文件失败:", err)
return return
} }
if summary.WaferID != "" { if summary.ChipNum != "" {
waferID = summary.WaferID waferID = summary.ChipNum
} }
if errors.Is(global.PostGreSQL.Where("name = ?", fileName).First(&fileHandled).Error, gorm.ErrRecordNotFound) { if errors.Is(global.PostGreSQL.Where("name = ?", fileName).First(&fileHandled).Error, gorm.ErrRecordNotFound) {
global.PostGreSQL.Create(&model.FileHandled{ global.PostGreSQL.Create(&model.FileHandled{
@ -195,7 +196,7 @@ func MT737(summary, dataLog *model.FileText, step string) {
Product: summary.ProductName, Product: summary.ProductName,
PBI: summary.PBI, PBI: summary.PBI,
Factory: summary.Factory, Factory: summary.Factory,
Step: details["Test_Code"], Step: summary.Procedure,
Lot: summary.Lot, Lot: summary.Lot,
SubBatch: summary.SubBatch, SubBatch: summary.SubBatch,
TestMachineModel: "MT737", TestMachineModel: "MT737",

View File

@ -1,4 +1,4 @@
package repository package test_data
import ( import (
"bytes" "bytes"
@ -21,7 +21,7 @@ import (
"testData/utils" "testData/utils"
) )
func HandleSTS8200Excel(fileText *model.FileText, step string) { func HandleSTS8200Excel(fileText *model.FileText) {
rows := make([][]string, 0) rows := make([][]string, 0)
if strings.ToLower(path.Ext(fileText.Name)) == ".csv" { if strings.ToLower(path.Ext(fileText.Name)) == ".csv" {
csvBytes, err := ioutil.ReadFile(fileText.Path) csvBytes, err := ioutil.ReadFile(fileText.Path)
@ -194,68 +194,74 @@ func HandleSTS8200Excel(fileText *model.FileText, step string) {
return return
} }
if details["Test_Code"] == "" { //if details["Test_Code"] == "" {
details["Test_Code"] = step // details["Test_Code"] = step
} else { //} else {
details["Test_Code"] = details["Test_Code"][:2] // details["Test_Code"] = details["Test_Code"][:2]
} //}
strReader := transform.NewReader(bytes.NewReader([]byte(details["Device_Name"])), simplifiedchinese.GBK.NewDecoder()) //strReader := transform.NewReader(bytes.NewReader([]byte(details["Device_Name"])), simplifiedchinese.GBK.NewDecoder())
product, _ := ioutil.ReadAll(strReader) //product, _ := ioutil.ReadAll(strReader)
if string(product) == "" { //if string(product) == "" {
product = []byte(fileText.ProductName) // product = []byte(fileText.ProductName)
} //}
testProgram := details["Program"][strings.LastIndex(details["Program"], "\\")+1:] testProgram := details["Program"][strings.LastIndex(details["Program"], "\\")+1:]
sbinHbin, _ := json.Marshal(&sBinMap) sbinHbin, _ := json.Marshal(&sBinMap)
titleInfo, _ := json.Marshal(&titleInfoMap) titleInfo, _ := json.Marshal(&titleInfoMap)
paramsSbin, _ := json.Marshal(&paramsMap) paramsSbin, _ := json.Marshal(&paramsMap)
fileName := string(product) + "_" + fileText.Lot + "_" + details["Test_Code"] + ".csv" var fileName string
var waferID string if fileText.Procedure == "CP" {
if fileText.Factory == "saimeike" { fileName = fileText.ProductName + "_" + fileText.Lot + "_" + fileText.ChipNum + "_" + fileText.Procedure + ".csv"
if step == "CP1" || step == "CP2" {
length := len(fileText.Name)
waferID = fileText.Name[length-10 : length-8]
fileName = string(product) + "_" + fileText.Lot + "_" + waferID + "_" + details["Test_Code"] + ".csv"
} else { } else {
if strings.Index(fileText.SubBatch, "-") != strings.LastIndex(fileText.SubBatch, "-") { fileName = fileText.ProductName + "_" + fileText.Lot + "_" + fileText.SubBatch + "_" + fileText.Procedure + ".csv"
fileText.SubBatch = fileText.SubBatch[:strings.LastIndex(fileText.SubBatch, "-")]
}
fileName = string(product) + "_" + fileText.Lot + "_" + fileText.SubBatch + "_" + details["Test_Code"] + ".csv"
}
} else if fileText.Factory == "xinde" {
s := strings.Split(fileText.Name, "_")
if len(s) < 5 {
log.Println("文件名格式有误,文件路径为:", fileText.Path)
return
}
waferIDStr := s[len(s)-3]
if len(waferIDStr) < 5 {
log.Println("文件名格式有误,文件路径为:", fileText.Path)
return
}
splitIndex := strings.Index(waferIDStr, "-")
if splitIndex == -1 {
log.Println("文件名格式有误,文件路径为:", fileText.Path)
return
}
waferID = waferIDStr[splitIndex+1 : splitIndex+3]
if _, ok := details["WAFER_ID"]; ok {
details["Test_Code"] = "CP"
if len(waferIDStr[:splitIndex]) < 8 {
fileText.Lot = strings.ToUpper(waferIDStr[:splitIndex])
}
fileText.SubBatch = ""
fileName = string(product) + "_" + fileText.Lot + "_" + waferID + "_" + details["Test_Code"] + ".csv"
}
} else if fileText.Factory == "qipai" {
//details["Test_Code"]
} else if fileText.Factory == "changdian" {
if details["Device_Name"] == "" {
log.Println("文件缺少产品型号信息,文件路径为:", fileText.Path)
return
}
product = []byte(details["Device_Name"])
fileName = details["Device_Name"] + "_" + fileText.Lot + "_" + fileText.SubBatch + "_" + details["Test_Code"] + ".csv"
} }
//fileName := string(product) + "_" + fileText.Lot + "_" + details["Test_Code"] + ".csv"
//var waferID string
//if fileText.Factory == "saimeike" {
// if step == "CP1" || step == "CP2" {
// length := len(fileText.Name)
// waferID = fileText.Name[length-10 : length-8]
// fileName = string(product) + "_" + fileText.Lot + "_" + waferID + "_" + details["Test_Code"] + ".csv"
// } else {
// if strings.Index(fileText.SubBatch, "-") != strings.LastIndex(fileText.SubBatch, "-") {
// fileText.SubBatch = fileText.SubBatch[:strings.LastIndex(fileText.SubBatch, "-")]
// }
// fileName = string(product) + "_" + fileText.Lot + "_" + fileText.SubBatch + "_" + details["Test_Code"] + ".csv"
// }
//} else if fileText.Factory == "xinde" {
// s := strings.Split(fileText.Name, "_")
// if len(s) < 5 {
// log.Println("文件名格式有误,文件路径为:", fileText.Path)
// return
// }
// waferIDStr := s[len(s)-3]
// if len(waferIDStr) < 5 {
// log.Println("文件名格式有误,文件路径为:", fileText.Path)
// return
// }
// splitIndex := strings.Index(waferIDStr, "-")
// if splitIndex == -1 {
// log.Println("文件名格式有误,文件路径为:", fileText.Path)
// return
// }
// waferID = waferIDStr[splitIndex+1 : splitIndex+3]
// if _, ok := details["WAFER_ID"]; ok {
// details["Test_Code"] = "CP"
// if len(waferIDStr[:splitIndex]) < 8 {
// fileText.Lot = strings.ToUpper(waferIDStr[:splitIndex])
// }
// fileText.SubBatch = ""
// fileName = string(product) + "_" + fileText.Lot + "_" + waferID + "_" + details["Test_Code"] + ".csv"
// }
//} else if fileText.Factory == "qipai" {
// //details["Test_Code"]
//} else if fileText.Factory == "changdian" {
// if details["Device_Name"] == "" {
// log.Println("文件缺少产品型号信息,文件路径为:", fileText.Path)
// return
// }
// product = []byte(details["Device_Name"])
// fileName = details["Device_Name"] + "_" + fileText.Lot + "_" + fileText.SubBatch + "_" + details["Test_Code"] + ".csv"
//}
//strings.ReplaceAll(fileText.Lot, ".", "-") //strings.ReplaceAll(fileText.Lot, ".", "-")
dirPath := filepath.Join("/testData/test/" + fileText.Factory) dirPath := filepath.Join("/testData/test/" + fileText.Factory)
utils.MakeDir(dirPath) utils.MakeDir(dirPath)
@ -269,18 +275,38 @@ func HandleSTS8200Excel(fileText *model.FileText, step string) {
log.Println("创建文件失败:", err) log.Println("创建文件失败:", err)
return return
} }
if fileText.WaferID != "" { //if fileText.ChipNum != "" {
waferID = fileText.WaferID // waferID = fileText.ChipNum
} //}
if errors.Is(global.PostGreSQL.Where("name = ?", fileName).First(&fileHandled).Error, gorm.ErrRecordNotFound) { if errors.Is(global.PostGreSQL.Where("name = ?", fileName).First(&fileHandled).Error, gorm.ErrRecordNotFound) {
//global.PostGreSQL.Create(&model.FileHandled{
// Name: fileName,
// Path: filePath,
// Size: "",
// Product: string(product),
// PBI: fileText.PBI,
// Factory: fileText.Factory,
// Step: details["Test_Code"],
// Lot: fileText.Lot,
// SubBatch: fileText.SubBatch,
// TestMachineModel: "STS8200",
// TestMachine: details["Tester ID"],
// TestProgram: testProgram,
// BeginningTime: details["Beginning Time"],
// EndingTime: details["Ending Time"],
// SbinHbin: string(sbinHbin),
// ParamsSbin: string(paramsSbin),
// TitleInfo: string(titleInfo),
// WaferID: waferID,
//})
global.PostGreSQL.Create(&model.FileHandled{ global.PostGreSQL.Create(&model.FileHandled{
Name: fileName, Name: fileName,
Path: filePath, Path: filePath,
Size: "", Size: "",
Product: string(product), Product: fileText.ProductName,
PBI: fileText.PBI, PBI: fileText.PBI,
Factory: fileText.Factory, Factory: fileText.Factory,
Step: details["Test_Code"], Step: fileText.Procedure,
Lot: fileText.Lot, Lot: fileText.Lot,
SubBatch: fileText.SubBatch, SubBatch: fileText.SubBatch,
TestMachineModel: "STS8200", TestMachineModel: "STS8200",
@ -291,7 +317,7 @@ func HandleSTS8200Excel(fileText *model.FileText, step string) {
SbinHbin: string(sbinHbin), SbinHbin: string(sbinHbin),
ParamsSbin: string(paramsSbin), ParamsSbin: string(paramsSbin),
TitleInfo: string(titleInfo), TitleInfo: string(titleInfo),
WaferID: waferID, WaferID: fileText.ChipNum,
}) })
} }
} }
@ -315,8 +341,10 @@ func HandleSTS8200Excel(fileText *model.FileText, step string) {
return return
} }
global.PostGreSQL.Model(&fileHandled).Where("name = ?", fileName).Updates(map[string]interface{}{ global.PostGreSQL.Model(&fileHandled).Where("name = ?", fileName).Updates(map[string]interface{}{
"product": string(product), "product": fileText.ProductName,
"step": details["Test_Code"], "step": fileText.Procedure,
//"product": string(product),
//"step": details["Test_Code"],
"test_machine_model": "STS8200", "test_machine_model": "STS8200",
"test_machine": details["Tester ID"], "test_machine": details["Tester ID"],
"test_program": testProgram, "test_program": testProgram,
@ -327,4 +355,25 @@ func HandleSTS8200Excel(fileText *model.FileText, step string) {
"title_info": string(titleInfo), "title_info": string(titleInfo),
"size": utils.FormatFileSize(float64(newFile.Size())), "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,
}
global.PostGreSQL.Transaction(func(tx *gorm.DB) error {
tx.Create(report)
tx.Find(&report)
return nil
})
if fileText.Procedure == "CP" {
SaveCP(report)
} else {
SaveFT(report)
}
} }

View File

@ -1,4 +1,4 @@
package repository package test_data
import ( import (
"encoding/csv" "encoding/csv"
@ -240,7 +240,7 @@ func HandlerTQT601Excel(fileText *model.FileText, step string) {
BeginningTime: details["Beginning Time"], BeginningTime: details["Beginning Time"],
EndingTime: details["Ending Time"], EndingTime: details["Ending Time"],
TitleInfo: string(titleInfo), TitleInfo: string(titleInfo),
WaferID: fileText.WaferID, WaferID: fileText.ChipNum,
}) })
} }
} }

View File

@ -12,7 +12,7 @@ func ProductSelection(r *request.ChartSelection) []string {
startDate := now.SubMonths(12).Format("Y-m-d") startDate := now.SubMonths(12).Format("Y-m-d")
var products []string var products []string
global.PostGreSQL.Model(&model.FileHandled{}).Where("step = ? AND created_at BETWEEN Date(?) AND Date(?)", global.PostGreSQL.Model(&model.FileHandled{}).Where("step = ? AND created_at BETWEEN Date(?) AND Date(?)",
r.Step, startDate, now.Format("Y-m-d")).Group("product").Select("product").Find(&products) r.Step, startDate, now.AddDay().Format("Y-m-d")).Group("product").Select("product").Find(&products)
//if strings.Contains(r.Step, "FT") { //if strings.Contains(r.Step, "FT") {
// global.PostGreSQL.Model(&model.FTList{}).Group("product").Select("product").Find(&products) // global.PostGreSQL.Model(&model.FTList{}).Group("product").Select("product").Find(&products)
//} else if strings.Contains(r.Step, "CP") { //} else if strings.Contains(r.Step, "CP") {
@ -26,7 +26,7 @@ func LotSelection(r *request.ChartSelection) []string {
startDate := now.SubMonths(12).Format("Y-m-d") startDate := now.SubMonths(12).Format("Y-m-d")
var lots []string var lots []string
global.PostGreSQL.Model(&model.FileHandled{}).Where("step = ? AND product = ? AND created_at BETWEEN Date(?) AND Date(?)", global.PostGreSQL.Model(&model.FileHandled{}).Where("step = ? AND product = ? AND created_at BETWEEN Date(?) AND Date(?)",
r.Step, r.Product, startDate, now.Format("Y-m-d")).Group("lot").Select("lot").Find(&lots) r.Step, r.Product, startDate, now.AddDay().Format("Y-m-d")).Group("lot").Select("lot").Find(&lots)
return lots return lots
} }
@ -35,7 +35,7 @@ func PBISelection(r *request.ChartSelection) []string {
startDate := now.SubMonths(12).Format("Y-m-d") startDate := now.SubMonths(12).Format("Y-m-d")
var pbis []string var pbis []string
global.PostGreSQL.Model(&model.FileHandled{}).Where("step = ? AND product = ? AND lot = ? AND created_at BETWEEN Date(?) AND Date(?)", global.PostGreSQL.Model(&model.FileHandled{}).Where("step = ? AND product = ? AND lot = ? AND created_at BETWEEN Date(?) AND Date(?)",
r.Step, r.Product, r.Lot, startDate, now.Format("Y-m-d")).Group("pbi").Select("pbi").Find(&pbis) r.Step, r.Product, r.Lot, startDate, now.AddDay().Format("Y-m-d")).Group("pbi").Select("pbi").Find(&pbis)
return pbis return pbis
} }
@ -44,7 +44,7 @@ func SubBatchSelection(r *request.ChartSelection) []string {
startDate := now.SubMonths(12).Format("Y-m-d") startDate := now.SubMonths(12).Format("Y-m-d")
var subBatch []string var subBatch []string
global.PostGreSQL.Model(&model.FileHandled{}).Where("step = ? AND product = ? AND lot = ? AND pbi = ? AND created_at BETWEEN Date(?) AND Date(?)", global.PostGreSQL.Model(&model.FileHandled{}).Where("step = ? AND product = ? AND lot = ? AND pbi = ? AND created_at BETWEEN Date(?) AND Date(?)",
r.Step, r.Product, r.Lot, r.PBI, startDate, now.Format("Y-m-d")).Group("sub_batch").Select("sub_batch").Find(&subBatch) r.Step, r.Product, r.Lot, r.PBI, startDate, now.AddDay().Format("Y-m-d")).Group("sub_batch").Select("sub_batch").Find(&subBatch)
return subBatch return subBatch
} }
@ -53,6 +53,6 @@ func WaferIDSelection(r *request.ChartSelection) []string {
startDate := now.SubMonths(12).Format("Y-m-d") startDate := now.SubMonths(12).Format("Y-m-d")
var waferIDs []string var waferIDs []string
global.PostGreSQL.Model(&model.FileHandled{}).Where("step = ? AND product = ? AND lot = ? AND pbi = ? AND created_at BETWEEN Date(?) AND Date(?)", global.PostGreSQL.Model(&model.FileHandled{}).Where("step = ? AND product = ? AND lot = ? AND pbi = ? AND created_at BETWEEN Date(?) AND Date(?)",
r.Step, r.Product, r.Lot, r.PBI, startDate, now.Format("Y-m-d")).Group("wafer_id").Select("wafer_id").Find(&waferIDs) r.Step, r.Product, r.Lot, r.PBI, startDate, now.AddDay().Format("Y-m-d")).Group("wafer_id").Select("wafer_id").Find(&waferIDs)
return waferIDs return waferIDs
} }

View File

@ -1,6 +1,7 @@
package test_data package test_data
import ( import (
"gitee.com/golang-module/carbon/v2"
"testData/global" "testData/global"
"testData/model" "testData/model"
"testData/request" "testData/request"
@ -8,14 +9,14 @@ import (
func GetProductSelection(r *request.ProbabilitySelection) []string { func GetProductSelection(r *request.ProbabilitySelection) []string {
var products []string var products []string
global.PostGreSQL.Model(&model.Report{}).Where("step = ? AND created_at BETWEEN Date(?) AND Date(?)", global.PostGreSQL.Debug().Model(&model.Report{}).Where("step = ? AND created_at BETWEEN Date(?) AND Date(?)",
r.Step, r.StartDate, r.EndDate).Group("product").Select("product").Find(&products) r.Step, r.StartDate, carbon.Parse(r.EndDate).AddDay().Format("Y-m-d")).Group("product").Select("product").Find(&products)
return products return products
} }
func GetLotSelection(r *request.ProbabilitySelection) []string { func GetLotSelection(r *request.ProbabilitySelection) []string {
var lots []string var lots []string
global.PostGreSQL.Model(&model.Report{}).Where("step = ? AND created_at BETWEEN Date(?) AND Date(?)", global.PostGreSQL.Model(&model.Report{}).Where("step = ? AND created_at BETWEEN Date(?) AND Date(?)",
r.Step, r.StartDate, r.EndDate).Group("lot").Select("lot").Find(&lots) r.Step, r.StartDate, carbon.Parse(r.EndDate).AddDay().Format("Y-m-d")).Group("lot").Select("lot").Find(&lots)
return lots return lots
} }

View File

@ -4,6 +4,7 @@ import (
"bufio" "bufio"
"encoding/json" "encoding/json"
"errors" "errors"
"fmt"
"gitee.com/golang-module/carbon/v2" "gitee.com/golang-module/carbon/v2"
"github.com/shopspring/decimal" "github.com/shopspring/decimal"
"github.com/xuri/excelize/v2" "github.com/xuri/excelize/v2"
@ -613,12 +614,19 @@ func SaveCP(report *model.Report) { //pbi, product, lot, waferID string,
func SaveFT(report *model.Report) { //pbi, product, lot, subBatch string, func SaveFT(report *model.Report) { //pbi, product, lot, subBatch string,
var ftFile *model.FileHandled var ftFile *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)
global.PostGreSQL.Where("pbi = ? AND product = ? AND lot = ? AND sub_batch = ? AND step = ?", global.PostGreSQL.Where("pbi = ? AND product = ? AND lot = ? AND sub_batch = ? AND step = ?",
report.PBI, report.Product, report.Lot, report.SubBatch, "FT").Find(&ftFile) report.PBI, report.Product, report.Lot, report.SubBatch, "FT").Find(&ftFile)
if _, err := os.Stat(ftFile.Path); err != nil {
log.Println(fmt.Sprintf("pbi = %s AND product = %s AND lot = %s AND sub_batch = %s",
report.PBI, report.Product, report.Lot, report.SubBatch))
log.Println("该文件不存在")
}
ft, err := os.Open(ftFile.Path) ft, err := os.Open(ftFile.Path)
if err != nil { if err != nil {
log.Println(err) log.Println(ftFile.Path, ":", err)
return return
} }
defer ft.Close() defer ft.Close()
@ -739,10 +747,14 @@ func SaveFT(report *model.Report) { //pbi, product, lot, subBatch string,
} }
sumDecimal := decimal.NewFromInt(int64(sum)) sumDecimal := decimal.NewFromInt(int64(sum))
passDecimal := decimal.NewFromInt(int64(pass)) passDecimal := decimal.NewFromInt(int64(pass))
var passProbability string
if !sumDecimal.IsZero() {
passProbability = passDecimal.Div(sumDecimal).Mul(decimal.NewFromInt(100)).Round(2).String() + "%"
}
global.PostGreSQL.Model(&siteReport).Updates(map[string]interface{}{ global.PostGreSQL.Model(&siteReport).Updates(map[string]interface{}{
"test_quantity": sumDecimal.String(), "test_quantity": sumDecimal.String(),
"pass_quantity": passDecimal.String(), "pass_quantity": passDecimal.String(),
"pass_probability": passDecimal.Div(sumDecimal).Mul(decimal.NewFromInt(100)).Round(2).String() + "%", "pass_probability": passProbability,
}) })
} }
global.PostGreSQL.Create(&binFail) global.PostGreSQL.Create(&binFail)

View File

@ -4,7 +4,6 @@ import (
"errors" "errors"
"sort" "sort"
"testData/model" "testData/model"
"testData/repository"
) )
func HandleUploadFiles(fileTexts []*model.FileText, step, machine string) error { func HandleUploadFiles(fileTexts []*model.FileText, step, machine string) error {
@ -16,15 +15,15 @@ func HandleUploadFiles(fileTexts []*model.FileText, step, machine string) error
}) })
if machine == "STS8200" { if machine == "STS8200" {
for _, fileText := range fileTexts { for _, fileText := range fileTexts {
repository.HandleSTS8200Excel(fileText, step) HandleSTS8200Excel(fileText)
} }
} else if machine == "TQT601" { } else if machine == "TQT601" {
for _, fileText := range fileTexts { //for _, fileText := range fileTexts {
repository.HandlerTQT601Excel(fileText, step) // HandlerTQT601Excel(fileText)
} //}
} else if machine == "MT737" { } else if machine == "MT737" {
for i := 0; i < len(fileTexts)/2; i++ { for i := 0; i < len(fileTexts)/2; i++ {
repository.MT737(fileTexts[2*i+1], fileTexts[2*i], step) MT737(fileTexts[2*i+1], fileTexts[2*i])
} }
} }
return nil return nil

View File

@ -0,0 +1,20 @@
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)
for _, fileText := range fileTexts {
test_data.HandleSTS8200Excel(fileText)
}
fmt.Println("执行时间:", time.Since(start))
}

View File

@ -24,6 +24,6 @@ func XinDe() {
if fileText.ProductName == "" || fileText.Lot == "" { if fileText.ProductName == "" || fileText.Lot == "" {
continue continue
} }
HandleSTS8200Excel(fileText, "") //HandleSTS8200Excel(fileText, "")
} }
} }