From a57228be1c54c19e1668db2464bae0373d982d1e Mon Sep 17 00:00:00 2001 From: jh_peng Date: Wed, 20 Nov 2024 11:43:51 +0800 Subject: [PATCH] =?UTF-8?q?V0=20AB=E4=BF=A1=E6=81=AF=E6=8A=93=E5=8F=96?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- repository/test.data/report.list.cron.go | 49 ++++++++++++++---------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/repository/test.data/report.list.cron.go b/repository/test.data/report.list.cron.go index 28fd5f6..e127c26 100644 --- a/repository/test.data/report.list.cron.go +++ b/repository/test.data/report.list.cron.go @@ -223,7 +223,7 @@ func CronWaferList() { func CronABList() { var oldTcSfcFile []*model.TcSfcFile var abListIDs []string - global.PostGreSQL.Model(&model.ABList{}).Where("status = ?", "未结案"). + global.PostGreSQL.Model(&model.ABList{}).Where("status = ?", "未结案").Find(&abListIDs). Select("pbi").Group("pbi").Find(&abListIDs) _ = global.Oracle.Transaction(func(tx *gorm.DB) error { page := len(abListIDs)/200 + 1 @@ -304,9 +304,9 @@ func CronABList() { Round(4).Mul(decimal.NewFromFloat(100)).String() global.PostGreSQL.Transaction(func(tx *gorm.DB) error { var abList *model.ABList - global.PostGreSQL.Where("pbi = ? AND outsourcing_pbi = ?", + tx.Where("pbi = ? AND outsourcing_pbi = ?", tcSfc.TcSfc01, tcSfd.TcSfd13).Find(&abList) - global.PostGreSQL.Model(&abList).Where("pbi = ? AND outsourcing_pbi = ?", + tx.Model(&abList).Where("pbi = ? AND outsourcing_pbi = ?", tcSfc.TcSfc01, tcSfd.TcSfd13).Updates(map[string]interface{}{ "status": status, "quantity": quantity, @@ -318,24 +318,33 @@ func CronABList() { "online_quantity": tcSfd.TcSfd05 - returnQuantity, "pass_probability": passProbability + "%", }) + tx.Where("ab_list_id = ?", abList.ID).Delete(&model.ABListStock{}) for k, v := range orderDateStockMap { - var abListStock *model.ABListStock - if errors.Is(global.PostGreSQL.Where("ab_list_id = ? AND return_date = ?", abList.ID, k). - First(&abListStock).Error, gorm.ErrRecordNotFound) { - global.PostGreSQL.Create(&model.ABListStock{ - ABListID: abList.ID, - 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], - }) - } + tx.Create(&model.ABListStock{ + ABListID: abList.ID, + ReturnDate: k, + PassQuantity: v[0], + FailQuantity: v[1], + }) } + //for k, v := range orderDateStockMap { + // var abListStock *model.ABListStock + // if errors.Is(global.PostGreSQL.Where("ab_list_id = ? AND return_date = ?", abList.ID, k). + // First(&abListStock).Error, gorm.ErrRecordNotFound) { + // global.PostGreSQL.Create(&model.ABListStock{ + // ABListID: abList.ID, + // 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 }) } @@ -427,7 +436,7 @@ func CronABList() { quantity, _ = decimal.NewFromFloat(quantity).Round(6).Float64() var passProbability string - if strings.Contains(tcSfc.TcSfc01, "M596") { + if strings.Contains(tcSfc.TcSfc01, "M596") && passQuantity == 0 { var reports []*model.Report global.PostGreSQL.Where("pbi = ? AND product = ? AND lot = ?", tcSfc.TcSfc01, tcSfd.ImaFile.Ima02, tcSfd.TcSfd06).Find(&reports)