数据分析平台 记录回货信息抓取规则调整

This commit is contained in:
jh_peng 2025-04-07 11:43:22 +08:00
parent c366465744
commit fb6fbcb717

View File

@ -302,10 +302,38 @@ func CronABList() {
//} //}
passProbability = decimal.NewFromFloat(passQuantity).Div(decimal.NewFromFloat(tcSfd.TcSfd05)). passProbability = decimal.NewFromFloat(passQuantity).Div(decimal.NewFromFloat(tcSfd.TcSfd05)).
Round(4).Mul(decimal.NewFromFloat(100)).String() Round(4).Mul(decimal.NewFromFloat(100)).String()
var abList *model.ABList
global.PostGreSQL.Where("pbi = ? AND outsourcing_pbi = ?",
tcSfc.TcSfc01, tcSfd.TcSfd13).Find(&abList)
global.PostGreSQL.Transaction(func(tx *gorm.DB) error { global.PostGreSQL.Transaction(func(tx *gorm.DB) error {
var abList *model.ABList var abListStocks []*model.ABListStock
tx.Where("pbi = ? AND outsourcing_pbi = ?", global.PostGreSQL.Where("ab_list_id = ?", abList.ID).Find(&abListStocks)
tcSfc.TcSfc01, tcSfd.TcSfd13).Find(&abList) var addABListStocks []*model.ABListStock
for k, v := range orderDateStockMap {
var isHandled bool
for _, abListStock := range abListStocks {
if abListStock.ReturnDate == k {
isHandled = true
}
}
if !isHandled {
addABListStocks = append(addABListStocks, &model.ABListStock{
ABListID: abList.ID,
ReturnDate: k,
PassQuantity: v[0],
FailQuantity: v[1],
})
}
}
var deleteABListStocks []*model.ABListStock
for _, abListStock := range abListStocks {
if _, ok := orderDateStockMap[abListStock.ReturnDate]; !ok {
deleteABListStocks = append(deleteABListStocks, abListStock)
}
}
global.PostGreSQL.Create(&addABListStocks)
global.PostGreSQL.Delete(&deleteABListStocks)
tx.Model(&abList).Where("pbi = ? AND outsourcing_pbi = ?", tx.Model(&abList).Where("pbi = ? AND outsourcing_pbi = ?",
tcSfc.TcSfc01, tcSfd.TcSfd13).Updates(map[string]interface{}{ tcSfc.TcSfc01, tcSfd.TcSfd13).Updates(map[string]interface{}{
"status": status, "status": status,
@ -318,32 +346,14 @@ func CronABList() {
"online_quantity": tcSfd.TcSfd05 - returnQuantity, "online_quantity": tcSfd.TcSfd05 - returnQuantity,
"pass_probability": passProbability + "%", "pass_probability": passProbability + "%",
}) })
tx.Where("ab_list_id = ?", abList.ID).Delete(&model.ABListStock{}) //tx.Where("ab_list_id = ?", abList.ID).Delete(&model.ABListStock{})
for k, v := range orderDateStockMap {
tx.Create(&model.ABListStock{
ABListID: abList.ID,
ReturnDate: k,
PassQuantity: v[0],
FailQuantity: v[1],
})
}
//for k, v := range orderDateStockMap { //for k, v := range orderDateStockMap {
// var abListStock *model.ABListStock // tx.Create(&model.ABListStock{
// if errors.Is(global.PostGreSQL.Where("ab_list_id = ? AND return_date = ?", abList.ID, k). // ABListID: abList.ID,
// First(&abListStock).Error, gorm.ErrRecordNotFound) { // ReturnDate: k,
// global.PostGreSQL.Create(&model.ABListStock{ // PassQuantity: v[0],
// ABListID: abList.ID, // FailQuantity: v[1],
// ReturnDate: k, // })
// PassQuantity: v[0],
// FailQuantity: v[1],
// })
// } else {
// global.PostGreSQL.Model(&abListStock).Where("ab_list_id = ? AND return_date = ?", abList.ID, k).
// Updates(map[string]interface{}{
// "pass_quantity": v[0],
// "fail_quantity": v[1],
// })
// }
//} //}
return nil return nil
}) })
@ -546,6 +556,34 @@ func CronBPList() {
global.PostGreSQL.Where("pbi = ? AND outsourcing_pbi = ?", global.PostGreSQL.Where("pbi = ? AND outsourcing_pbi = ?",
tcSfc.TcSfc01, tcSfd.TcSfd13).Find(&bpList) tcSfc.TcSfc01, tcSfd.TcSfd13).Find(&bpList)
global.PostGreSQL.Transaction(func(tx *gorm.DB) error { global.PostGreSQL.Transaction(func(tx *gorm.DB) error {
var bpListStocks []*model.BPListStock
global.PostGreSQL.Where("bp_list_id = ?", bpList.ID).Find(&bpListStocks)
var addBPListStocks []*model.BPListStock
for k, v := range orderDateStockMap {
var isHandled bool
for _, bpListStock := range bpListStocks {
if bpListStock.ReturnDate == k {
isHandled = true
}
}
if !isHandled {
addBPListStocks = append(addBPListStocks, &model.BPListStock{
BPListID: bpList.ID,
ReturnDate: k,
Quantity: v[0],
DieQuantity: v[1],
})
}
}
var deleteBPListStocks []*model.BPListStock
for _, bpListStock := range bpListStocks {
if _, ok := orderDateStockMap[bpListStock.ReturnDate]; !ok {
deleteBPListStocks = append(deleteBPListStocks, bpListStock)
}
}
global.PostGreSQL.Create(&addBPListStocks)
global.PostGreSQL.Delete(&deleteBPListStocks)
global.PostGreSQL.Model(&bpList).Where("pbi = ? AND outsourcing_pbi = ?", global.PostGreSQL.Model(&bpList).Where("pbi = ? AND outsourcing_pbi = ?",
tcSfc.TcSfc01, tcSfd.TcSfd13).Updates(map[string]interface{}{ tcSfc.TcSfc01, tcSfd.TcSfd13).Updates(map[string]interface{}{
"status": status, "status": status,
@ -553,24 +591,24 @@ func CronBPList() {
"return_quantity": returnQuantity, "return_quantity": returnQuantity,
"die_quantity": dieQuantity, "die_quantity": dieQuantity,
}) })
for k, v := range orderDateStockMap { //for k, v := range orderDateStockMap {
var bpListStock *model.BPListStock // var bpListStock *model.BPListStock
if errors.Is(global.PostGreSQL.Where("bp_list_id = ? AND return_date = ?", bpList.ID, k). // if errors.Is(global.PostGreSQL.Where("bp_list_id = ? AND return_date = ?", bpList.ID, k).
First(&bpListStock).Error, gorm.ErrRecordNotFound) { // First(&bpListStock).Error, gorm.ErrRecordNotFound) {
global.PostGreSQL.Create(&model.BPListStock{ // global.PostGreSQL.Create(&model.BPListStock{
BPListID: bpList.ID, // BPListID: bpList.ID,
ReturnDate: k, // ReturnDate: k,
Quantity: v[0], // Quantity: v[0],
DieQuantity: v[1], // DieQuantity: v[1],
}) // })
} else { // } else {
global.PostGreSQL.Model(&bpListStock).Where("bp_list_id = ? AND return_date = ?", bpList.ID, k). // global.PostGreSQL.Model(&bpListStock).Where("bp_list_id = ? AND return_date = ?", bpList.ID, k).
Updates(map[string]interface{}{ // Updates(map[string]interface{}{
"quantity": v[0], // "quantity": v[0],
"die_quantity": v[1], // "die_quantity": v[1],
}) // })
} // }
} //}
return nil return nil
}) })
} }
@ -733,6 +771,34 @@ func CronCPList() {
global.PostGreSQL.Where("pbi = ? AND outsourcing_pbi = ?", global.PostGreSQL.Where("pbi = ? AND outsourcing_pbi = ?",
tcSfc.TcSfc01, tcSfd.TcSfd13).Find(&cpList) tcSfc.TcSfc01, tcSfd.TcSfd13).Find(&cpList)
global.PostGreSQL.Transaction(func(tx *gorm.DB) error { global.PostGreSQL.Transaction(func(tx *gorm.DB) error {
var cpListStocks []*model.CPListStock
global.PostGreSQL.Where("cp_list_id = ?", cpList.ID).Find(&cpListStocks)
var addCPListStocks []*model.CPListStock
for k, v := range orderDateStockMap {
var isHandled bool
for _, cpListStock := range cpListStocks {
if cpListStock.ReturnDate == k {
isHandled = true
}
}
if !isHandled {
addCPListStocks = append(addCPListStocks, &model.CPListStock{
CPListID: cpList.ID,
ReturnDate: k,
Quantity: v[0],
DieQuantity: v[1],
})
}
}
var deleteCPListStocks []*model.CPListStock
for _, cpListStock := range cpListStocks {
if _, ok := orderDateStockMap[cpListStock.ReturnDate]; !ok {
deleteCPListStocks = append(deleteCPListStocks, cpListStock)
}
}
global.PostGreSQL.Create(&addCPListStocks)
global.PostGreSQL.Delete(&deleteCPListStocks)
global.PostGreSQL.Model(&cpList).Where("pbi = ? AND outsourcing_pbi = ?", global.PostGreSQL.Model(&cpList).Where("pbi = ? AND outsourcing_pbi = ?",
tcSfc.TcSfc01, tcSfd.TcSfd13).Updates(map[string]interface{}{ tcSfc.TcSfc01, tcSfd.TcSfd13).Updates(map[string]interface{}{
"status": status, "status": status,
@ -740,24 +806,24 @@ func CronCPList() {
"return_quantity": returnQuantity, "return_quantity": returnQuantity,
"die_quantity": dieQuantity, "die_quantity": dieQuantity,
}) })
for k, v := range orderDateStockMap { //for k, v := range orderDateStockMap {
var cpListStock *model.CPListStock // var cpListStock *model.CPListStock
if errors.Is(global.PostGreSQL.Where("cp_list_id = ? AND return_date = ?", cpList.ID, k). // if errors.Is(global.PostGreSQL.Where("cp_list_id = ? AND return_date = ?", cpList.ID, k).
First(&cpListStock).Error, gorm.ErrRecordNotFound) { // First(&cpListStock).Error, gorm.ErrRecordNotFound) {
global.PostGreSQL.Create(&model.CPListStock{ // global.PostGreSQL.Create(&model.CPListStock{
CPListID: cpList.ID, // CPListID: cpList.ID,
ReturnDate: k, // ReturnDate: k,
Quantity: v[0], // Quantity: v[0],
DieQuantity: v[1], // DieQuantity: v[1],
}) // })
} else { // } else {
global.PostGreSQL.Model(&cpListStock).Where("cp_list_id = ? AND return_date = ?", cpList.ID, k). // global.PostGreSQL.Model(&cpListStock).Where("cp_list_id = ? AND return_date = ?", cpList.ID, k).
Updates(map[string]interface{}{ // Updates(map[string]interface{}{
"quantity": v[0], // "quantity": v[0],
"die_quantity": v[1], // "die_quantity": v[1],
}) // })
} // }
} //}
return nil return nil
}) })
} }
@ -1031,6 +1097,34 @@ func CronFTList() {
global.PostGreSQL.Where("pbi = ? AND outsourcing_pbi = ?", global.PostGreSQL.Where("pbi = ? AND outsourcing_pbi = ?",
tcSfc.TcSfc01, tcSfd.TcSfd13).Find(&ftList) tcSfc.TcSfc01, tcSfd.TcSfd13).Find(&ftList)
global.PostGreSQL.Transaction(func(tx *gorm.DB) error { global.PostGreSQL.Transaction(func(tx *gorm.DB) error {
var ftListStocks []*model.FTListStock
global.PostGreSQL.Where("ft_list_id = ?", ftList.ID).Find(&ftListStocks)
var addFTListStocks []*model.FTListStock
for k, v := range orderDateStockMap {
var isHandled bool
for _, ftListStock := range ftListStocks {
if ftListStock.ReturnDate == k {
isHandled = true
}
}
if !isHandled {
addFTListStocks = append(addFTListStocks, &model.FTListStock{
FTListID: ftList.ID,
ReturnDate: k,
PassQuantity: v[0],
FailQuantity: v[1],
})
}
}
var deleteFTListStocks []*model.FTListStock
for _, ftListStock := range ftListStocks {
if _, ok := orderDateStockMap[ftListStock.ReturnDate]; !ok {
deleteFTListStocks = append(deleteFTListStocks, ftListStock)
}
}
global.PostGreSQL.Create(&addFTListStocks)
global.PostGreSQL.Delete(&deleteFTListStocks)
global.PostGreSQL.Model(&ftList).Where("pbi = ? AND outsourcing_pbi = ?", global.PostGreSQL.Model(&ftList).Where("pbi = ? AND outsourcing_pbi = ?",
tcSfc.TcSfc01, tcSfd.TcSfd13).Updates(map[string]interface{}{ tcSfc.TcSfc01, tcSfd.TcSfd13).Updates(map[string]interface{}{
"wafer_product": waferProduct, "wafer_product": waferProduct,
@ -1041,24 +1135,24 @@ func CronFTList() {
"fail_quantity": failQuantity, "fail_quantity": failQuantity,
"test_program_version": tcSfd.TcImbFile.TcImb04, "test_program_version": tcSfd.TcImbFile.TcImb04,
}) })
for k, v := range orderDateStockMap { //for k, v := range orderDateStockMap {
var ftListStock *model.FTListStock // var ftListStock *model.FTListStock
if errors.Is(global.PostGreSQL.Where("ft_list_id = ? AND return_date = ?", ftList.ID, k). // if errors.Is(global.PostGreSQL.Where("ft_list_id = ? AND return_date = ?", ftList.ID, k).
First(&ftListStock).Error, gorm.ErrRecordNotFound) { // First(&ftListStock).Error, gorm.ErrRecordNotFound) {
global.PostGreSQL.Create(&model.FTListStock{ // global.PostGreSQL.Create(&model.FTListStock{
FTListID: ftList.ID, // FTListID: ftList.ID,
ReturnDate: k, // ReturnDate: k,
PassQuantity: v[0], // PassQuantity: v[0],
FailQuantity: v[1], // FailQuantity: v[1],
}) // })
} else { // } else {
global.PostGreSQL.Model(&ftListStock).Where("ft_list_id = ? AND return_date = ?", ftList.ID, k). // global.PostGreSQL.Model(&ftListStock).Where("ft_list_id = ? AND return_date = ?", ftList.ID, k).
Updates(map[string]interface{}{ // Updates(map[string]interface{}{
"pass_quantity": v[0], // "pass_quantity": v[0],
"fail_quantity": v[1], // "fail_quantity": v[1],
}) // })
} // }
} //}
return nil return nil
}) })
} }
@ -1345,6 +1439,34 @@ func CronTRList() {
global.PostGreSQL.Where("pbi = ? AND outsourcing_pbi = ?", global.PostGreSQL.Where("pbi = ? AND outsourcing_pbi = ?",
tcSfc.TcSfc01, tcSfd.TcSfd13).Find(&trList) tcSfc.TcSfc01, tcSfd.TcSfd13).Find(&trList)
global.PostGreSQL.Transaction(func(tx *gorm.DB) error { global.PostGreSQL.Transaction(func(tx *gorm.DB) error {
var trListStocks []*model.TRListStock
global.PostGreSQL.Where("tr_list_id = ?", trList.ID).Find(&trListStocks)
var addTRListStocks []*model.TRListStock
for k, v := range orderDateStockMap {
var isHandled bool
for _, trListStock := range trListStocks {
if trListStock.ReturnDate == k {
isHandled = true
}
}
if !isHandled {
addTRListStocks = append(addTRListStocks, &model.TRListStock{
TRListID: trList.ID,
ReturnDate: k,
PassQuantity: v[0],
FailQuantity: v[1],
})
}
}
var deleteTRListStocks []*model.TRListStock
for _, trListStock := range trListStocks {
if _, ok := orderDateStockMap[trListStock.ReturnDate]; !ok {
deleteTRListStocks = append(deleteTRListStocks, trListStock)
}
}
global.PostGreSQL.Create(&addTRListStocks)
global.PostGreSQL.Delete(&deleteTRListStocks)
global.PostGreSQL.Model(&trList).Where("pbi = ? AND outsourcing_pbi = ?", global.PostGreSQL.Model(&trList).Where("pbi = ? AND outsourcing_pbi = ?",
tcSfc.TcSfc01, tcSfd.TcSfd13).Updates(map[string]interface{}{ tcSfc.TcSfc01, tcSfd.TcSfd13).Updates(map[string]interface{}{
"status": status, "status": status,
@ -1352,24 +1474,24 @@ func CronTRList() {
"pass_quantity": passQuantity, "pass_quantity": passQuantity,
"fail_quantity": failQuantity, "fail_quantity": failQuantity,
}) })
for k, v := range orderDateStockMap { //for k, v := range orderDateStockMap {
var trListStock *model.TRListStock // var trListStock *model.TRListStock
if errors.Is(global.PostGreSQL.Where("tr_list_id = ? AND return_date = ?", trList.ID, k). // if errors.Is(global.PostGreSQL.Where("tr_list_id = ? AND return_date = ?", trList.ID, k).
First(&trListStock).Error, gorm.ErrRecordNotFound) { // First(&trListStock).Error, gorm.ErrRecordNotFound) {
global.PostGreSQL.Create(&model.TRListStock{ // global.PostGreSQL.Create(&model.TRListStock{
TRListID: trList.ID, // TRListID: trList.ID,
ReturnDate: k, // ReturnDate: k,
PassQuantity: v[0], // PassQuantity: v[0],
FailQuantity: v[1], // FailQuantity: v[1],
}) // })
} else { // } else {
global.PostGreSQL.Model(&trListStock).Where("tr_list_id = ? AND return_date = ?", trList.ID, k). // global.PostGreSQL.Model(&trListStock).Where("tr_list_id = ? AND return_date = ?", trList.ID, k).
Updates(map[string]interface{}{ // Updates(map[string]interface{}{
"pass_quantity": v[0], // "pass_quantity": v[0],
"fail_quantity": v[1], // "fail_quantity": v[1],
}) // })
} // }
} //}
return nil return nil
}) })
} }