1648 lines
62 KiB
Go
1648 lines
62 KiB
Go
package test_data
|
|
|
|
import (
|
|
"errors"
|
|
"github.com/shopspring/decimal"
|
|
"gorm.io/gorm"
|
|
"strings"
|
|
"testData/global"
|
|
"testData/model"
|
|
)
|
|
|
|
func CronWaferList() {
|
|
//var waferLists []*model.WaferList
|
|
var pbis []string
|
|
global.PostGreSQL.Model(&model.WaferList{}).Where("status != ?", "结案").Select("pbi").Order("pbi").Find(&pbis) //.Find(&waferLists)
|
|
|
|
//for i := 0; i < 10; i++ {
|
|
// var a []string
|
|
// if i != 9 {
|
|
// a = pbis[i*100 : (i+1)*100]
|
|
// } else {
|
|
// a = pbis[i*100:]
|
|
// }
|
|
var oldPmms []*model.PmmFile
|
|
global.Oracle.Where("pmm01 IN ? AND pmm02 = ?", pbis, "WB0").
|
|
Preload("PmnFile", func(db *gorm.DB) *gorm.DB {
|
|
return db.Preload("ImaFile")
|
|
}).Preload("PmcFile").Preload("RvbFile", func(db *gorm.DB) *gorm.DB {
|
|
return db.Preload("ImaFile").Preload("IddFile").Order("rvb12 desc")
|
|
}).Order("pmm01 desc").Find(&oldPmms)
|
|
|
|
for _, pmm := range oldPmms {
|
|
var status string
|
|
if pmm.Pmm25 == "6" {
|
|
status = "结案"
|
|
} else {
|
|
status = "未结案"
|
|
}
|
|
for _, pmn := range pmm.PmnFile {
|
|
var returnQuantity, dieQuantity float64
|
|
for _, rvb := range pmm.RvbFile {
|
|
if rvb.Rvb03 == pmn.Pmn02 {
|
|
returnQuantity += rvb.Rvb82
|
|
dieQuantity += rvb.Rvb85
|
|
}
|
|
}
|
|
var waferList *model.WaferList
|
|
global.PostGreSQL.Where("pbi = ? AND product = ? AND wafer_size = ?",
|
|
pmm.Pmm01, pmn.ImaFile.Ima02, pmn.ImaFile.Ima021).Preload("WaferStock").Find(&waferList)
|
|
global.PostGreSQL.Model(&waferList).Updates(map[string]interface{}{
|
|
"status": status,
|
|
"online_quantity": pmn.Pmn20 - returnQuantity,
|
|
"return_quantity": returnQuantity,
|
|
"die_quantity": dieQuantity,
|
|
})
|
|
var waferStocks []*model.WaferStock
|
|
|
|
rvbMap := make(map[string][]interface{})
|
|
for _, rvb := range pmm.RvbFile {
|
|
name := rvb.Rvb38 + "~" + rvb.Rvb12.Format("2006-01-02")
|
|
if rvb.Rvb03 == pmn.Pmn02 {
|
|
if _, ok := rvbMap[name]; !ok {
|
|
var waferID string
|
|
for _, idd := range rvb.IddFile {
|
|
if rvb.Rvb38 == idd.Idd04 {
|
|
if !strings.Contains(waferID, "#"+idd.Idd05) {
|
|
waferID += "#" + idd.Idd05
|
|
}
|
|
}
|
|
}
|
|
rvbMap[name] = []interface{}{rvb.Rvb82, rvb.Rvb85, waferID, rvb.ImaFile.Ima02, rvb.ImaFile.Ima021}
|
|
} else {
|
|
waferID := rvbMap[name][2].(string)
|
|
for _, idd := range rvb.IddFile {
|
|
if rvb.Rvb38 == idd.Idd04 {
|
|
if !strings.Contains(waferID, "#"+idd.Idd05) {
|
|
waferID += "#" + idd.Idd05
|
|
}
|
|
}
|
|
}
|
|
rvbMap[name][0] = rvbMap[name][0].(float64) + rvb.Rvb82
|
|
rvbMap[name][1] = rvbMap[name][1].(float64) + rvb.Rvb85
|
|
}
|
|
}
|
|
}
|
|
for k, v := range rvbMap {
|
|
lot := strings.Split(k, "~")[0]
|
|
returnDate := strings.Split(k, "~")[1]
|
|
var isExist bool
|
|
for _, waferStock := range waferList.WaferStock {
|
|
if waferStock.Lot == lot && waferStock.WaferID == v[2].(string) && waferStock.ReturnDate == returnDate {
|
|
isExist = true
|
|
break
|
|
}
|
|
}
|
|
if !isExist {
|
|
waferStocks = append(waferStocks, &model.WaferStock{
|
|
WaferListID: waferList.ID,
|
|
PBI: waferList.PBI,
|
|
Product: v[3].(string),
|
|
Specification: v[4].(string),
|
|
ReturnDate: returnDate,
|
|
Lot: lot,
|
|
WaferID: v[2].(string),
|
|
ReturnQuantity: v[0].(float64),
|
|
DieQuantity: v[1].(float64),
|
|
})
|
|
}
|
|
}
|
|
global.PostGreSQL.Create(&waferStocks)
|
|
}
|
|
}
|
|
//}
|
|
|
|
var newPmms []*model.PmmFile
|
|
global.Oracle.Where("pmm02 = ? AND pmm25 != ?", "WB0", "6").Order("pmm01").
|
|
Preload("PmnFile", func(db *gorm.DB) *gorm.DB {
|
|
return db.Preload("ImaFile")
|
|
}).Preload("PmcFile").Preload("RvbFile", func(db *gorm.DB) *gorm.DB {
|
|
return db.Preload("ImaFile").Preload("IddFile").Order("rvb12 desc")
|
|
}).Find(&newPmms)
|
|
for _, pmm := range newPmms {
|
|
var status string
|
|
if pmm.Pmm25 == "6" {
|
|
status = "结案"
|
|
} else {
|
|
status = "未结案"
|
|
}
|
|
for _, pmn := range pmm.PmnFile {
|
|
var returnQuantity, dieQuantity float64
|
|
for _, rvb := range pmm.RvbFile {
|
|
if rvb.Rvb03 == pmn.Pmn02 {
|
|
returnQuantity += rvb.Rvb82
|
|
dieQuantity += rvb.Rvb85
|
|
}
|
|
}
|
|
var waferList *model.WaferList
|
|
if errors.Is(global.PostGreSQL.Where("pbi = ? AND product = ? AND wafer_size = ?",
|
|
pmm.Pmm01, pmn.ImaFile.Ima02, pmn.ImaFile.Ima021).First(&waferList).Error, gorm.ErrRecordNotFound) {
|
|
global.PostGreSQL.Create(&model.WaferList{
|
|
Status: status,
|
|
OrderDate: pmm.Pmm04.Format("2006-01-02"),
|
|
PBI: pmm.Pmm01,
|
|
Product: pmn.ImaFile.Ima02,
|
|
Factory: pmm.PmcFile.Pmc03,
|
|
WaferSize: pmn.ImaFile.Ima021,
|
|
Quantity: pmn.Pmn20,
|
|
OnlineQuantity: pmn.Pmn20 - returnQuantity,
|
|
ReturnQuantity: returnQuantity,
|
|
DieQuantity: dieQuantity,
|
|
})
|
|
} else {
|
|
global.PostGreSQL.Model(&waferList).Updates(map[string]interface{}{
|
|
"status": status,
|
|
"online_quantity": pmn.Pmn20 - returnQuantity,
|
|
"return_quantity": returnQuantity,
|
|
"die_quantity": dieQuantity,
|
|
})
|
|
}
|
|
global.PostGreSQL.Where("pbi = ? AND product = ? AND wafer_size = ?",
|
|
pmm.Pmm01, pmn.ImaFile.Ima02, pmn.ImaFile.Ima021).Preload("WaferStock").Find(&waferList)
|
|
|
|
var waferStocks []*model.WaferStock
|
|
|
|
rvbMap := make(map[string][]interface{})
|
|
for _, rvb := range pmm.RvbFile {
|
|
name := rvb.Rvb38 + "~" + rvb.Rvb12.Format("2006-01-02")
|
|
if rvb.Rvb03 == pmn.Pmn02 {
|
|
if _, ok := rvbMap[name]; !ok {
|
|
var waferID string
|
|
for _, idd := range rvb.IddFile {
|
|
if rvb.Rvb38 == idd.Idd04 {
|
|
if !strings.Contains(waferID, "#"+idd.Idd05) {
|
|
waferID += "#" + idd.Idd05
|
|
}
|
|
}
|
|
}
|
|
rvbMap[name] = []interface{}{rvb.Rvb82, rvb.Rvb85, waferID, rvb.ImaFile.Ima02, rvb.ImaFile.Ima021}
|
|
} else {
|
|
waferID := rvbMap[name][2].(string)
|
|
for _, idd := range rvb.IddFile {
|
|
if rvb.Rvb38 == idd.Idd04 {
|
|
if !strings.Contains(waferID, "#"+idd.Idd05) {
|
|
waferID += "#" + idd.Idd05
|
|
}
|
|
}
|
|
}
|
|
rvbMap[name][0] = rvbMap[name][0].(float64) + rvb.Rvb82
|
|
rvbMap[name][1] = rvbMap[name][1].(float64) + rvb.Rvb85
|
|
}
|
|
}
|
|
}
|
|
for k, v := range rvbMap {
|
|
lot := strings.Split(k, "~")[0]
|
|
returnDate := strings.Split(k, "~")[1]
|
|
var isExist bool
|
|
for _, waferStock := range waferList.WaferStock {
|
|
if waferStock.Lot == lot && waferStock.WaferID == v[2].(string) && waferStock.ReturnDate == returnDate {
|
|
isExist = true
|
|
break
|
|
}
|
|
}
|
|
if !isExist {
|
|
waferStocks = append(waferStocks, &model.WaferStock{
|
|
WaferListID: waferList.ID,
|
|
PBI: waferList.PBI,
|
|
Product: v[3].(string),
|
|
Specification: v[4].(string),
|
|
ReturnDate: returnDate,
|
|
Lot: lot,
|
|
WaferID: v[2].(string),
|
|
ReturnQuantity: v[0].(float64),
|
|
DieQuantity: v[1].(float64),
|
|
})
|
|
}
|
|
}
|
|
global.PostGreSQL.Create(&waferStocks)
|
|
}
|
|
}
|
|
}
|
|
|
|
func CronABList() {
|
|
var oldTcSfcFile []*model.TcSfcFile
|
|
var abListIDs []string
|
|
global.PostGreSQL.Model(&model.ABList{}).Where("status = ?", "未结案").
|
|
Select("pbi").Group("pbi").Find(&abListIDs)
|
|
_ = global.Oracle.Transaction(func(tx *gorm.DB) error {
|
|
page := len(abListIDs)/200 + 1
|
|
for i := 0; i < page; i++ {
|
|
var pageTcSfcFile []*model.TcSfcFile
|
|
var s []string
|
|
if i == page-1 {
|
|
s = abListIDs[i*200:]
|
|
} else {
|
|
s = abListIDs[i*200 : (i+1)*200]
|
|
}
|
|
tx.Where("tc_sfc01 IN ? AND tc_sfc08 LIKE ?", s, "%AB%").
|
|
Preload("TcSfdFile", func(db *gorm.DB) *gorm.DB {
|
|
return db.Preload("SfbFile").Preload("ImaFile").Preload("RvbFile", func(db *gorm.DB) *gorm.DB {
|
|
return db.Preload("IddFile").Preload("RvaFile")
|
|
})
|
|
}).Preload("TcSfeFile", func(db *gorm.DB) *gorm.DB {
|
|
return db.Preload("ImaFile")
|
|
}).
|
|
Preload("PmcFile").Find(&pageTcSfcFile)
|
|
oldTcSfcFile = append(oldTcSfcFile, pageTcSfcFile...)
|
|
}
|
|
return nil
|
|
})
|
|
for _, tcSfc := range oldTcSfcFile {
|
|
for _, tcSfd := range tcSfc.TcSfdFile {
|
|
status := "未结案"
|
|
if tcSfd.SfbFile.Sfb04 == "8" {
|
|
status = "结案"
|
|
} else if tcSfd.SfbFile.Sfb04 == "0" {
|
|
continue
|
|
}
|
|
var quantity float64 //, stockOutQuantity
|
|
for _, tcSfe := range tcSfc.TcSfeFile {
|
|
if tcSfe.TcSfe01 == tcSfc.TcSfc01 && tcSfe.TcSfe02 == tcSfd.TcSfd02 {
|
|
quantity += tcSfe.TcSfe12
|
|
//stockOutQuantity += tcSfe.TcSfe14
|
|
}
|
|
}
|
|
|
|
var returnQuantity, failQuantity, passQuantity float64
|
|
orderDateStockMap := make(map[string][]float64)
|
|
for _, rvb := range tcSfd.RvbFile {
|
|
if _, ok := orderDateStockMap[rvb.RvaFile.Rva06.Format("2006-01-02")]; !ok {
|
|
orderDateStockMap[rvb.RvaFile.Rva06.Format("2006-01-02")] = []float64{0, 0}
|
|
}
|
|
for _, idd := range rvb.IddFile {
|
|
if idd.Idd11 == rvb.Rvb02 {
|
|
returnQuantity += idd.Idd13
|
|
if idd.Idd06 == "BIN99" {
|
|
orderDateStockMap[rvb.RvaFile.Rva06.Format("2006-01-02")][1] += idd.Idd13
|
|
failQuantity += idd.Idd13
|
|
} else {
|
|
orderDateStockMap[rvb.RvaFile.Rva06.Format("2006-01-02")][0] += idd.Idd13
|
|
passQuantity += idd.Idd13
|
|
}
|
|
}
|
|
}
|
|
}
|
|
quantity, _ = decimal.NewFromFloat(quantity).Round(6).Float64()
|
|
|
|
var passProbability string
|
|
if strings.Contains(tcSfc.TcSfc01, "M596") {
|
|
var reports []*model.Report
|
|
global.PostGreSQL.Where("pbi = ? AND product = ? AND lot = ?", tcSfc.TcSfc01, tcSfd.ImaFile.Ima02,
|
|
tcSfd.TcSfd06).Find(&reports)
|
|
for _, report := range reports {
|
|
testQuantityDecimal, _ := decimal.NewFromString(report.TestQuantity)
|
|
testQuantityFloat, _ := testQuantityDecimal.Float64()
|
|
passQuantity += testQuantityFloat
|
|
}
|
|
}
|
|
//if stockOutQuantity != 0 {
|
|
// passProbability = decimal.NewFromFloat(passQuantity).Div(decimal.NewFromFloat(stockOutQuantity)).
|
|
// Round(4).Mul(decimal.NewFromFloat(100)).String()
|
|
//}
|
|
passProbability = decimal.NewFromFloat(passQuantity).Div(decimal.NewFromFloat(tcSfd.TcSfd05)).
|
|
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 = ?",
|
|
tcSfc.TcSfc01, tcSfd.TcSfd13).Find(&abList)
|
|
global.PostGreSQL.Model(&abList).Where("pbi = ? AND outsourcing_pbi = ?",
|
|
tcSfc.TcSfc01, tcSfd.TcSfd13).Updates(map[string]interface{}{
|
|
"status": status,
|
|
"quantity": quantity,
|
|
//"stock_out_quantity": stockOutQuantity,
|
|
"stock_out_quantity": tcSfd.TcSfd05,
|
|
"stock_in_quantity": returnQuantity,
|
|
"pass_quantity": passQuantity,
|
|
"fail_quantity": failQuantity,
|
|
"online_quantity": tcSfd.TcSfd05 - returnQuantity,
|
|
"pass_probability": passProbability + "%",
|
|
})
|
|
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
|
|
})
|
|
}
|
|
}
|
|
|
|
var newTcSfcFile []*model.TcSfcFile
|
|
global.PostGreSQL.Model(&model.ABList{}).Select("pbi").Group("pbi").Find(&abListIDs)
|
|
_ = global.Oracle.Transaction(func(tx *gorm.DB) error {
|
|
var tcSfcFilePBIs []string
|
|
tx.Model(&model.TcSfcFile{}).Where("tc_sfc01 NOT IN ? AND tc_sfc08 LIKE ? AND tc_sfc10 = ?", abListIDs, "%AB%").
|
|
Order("tc_sfc01").Select("tc_sfc01").Find(&tcSfcFilePBIs)
|
|
//tx.Model(&model.TcSfcFile{}).Where("tc_sfc08 LIKE ?", "%AB%").
|
|
// Order("tc_sfc01").Select("tc_sfc01").Find(&tcSfcFilePBIs)
|
|
page := len(tcSfcFilePBIs)/200 + 1
|
|
for i := 0; i < page; i++ {
|
|
var pageTcSfcFile []*model.TcSfcFile
|
|
var s []string
|
|
if i == page-1 {
|
|
s = tcSfcFilePBIs[i*200:]
|
|
} else {
|
|
s = tcSfcFilePBIs[i*200 : (i+1)*200]
|
|
}
|
|
tx.Where("tc_sfc01 IN ? AND tc_sfc08 LIKE ?", s, "%AB%"). // AND tc_sfc10 = ?, "N"
|
|
Preload("TcSfdFile", func(db *gorm.DB) *gorm.DB {
|
|
return db.Preload("SfbFile").Preload("ImaFile").Preload("RvbFile", func(db *gorm.DB) *gorm.DB {
|
|
return db.Preload("IddFile").Preload("RvaFile")
|
|
})
|
|
}).Preload("TcSfeFile", func(db *gorm.DB) *gorm.DB {
|
|
return db.Preload("ImaFile")
|
|
}).Preload("PmcFile").Find(&pageTcSfcFile)
|
|
newTcSfcFile = append(newTcSfcFile, pageTcSfcFile...)
|
|
}
|
|
return nil
|
|
})
|
|
|
|
for _, tcSfc := range newTcSfcFile {
|
|
for _, tcSfd := range tcSfc.TcSfdFile {
|
|
status := "未结案"
|
|
if tcSfd.SfbFile.Sfb04 == "8" {
|
|
status = "结案"
|
|
} else if tcSfd.SfbFile.Sfb04 == "0" {
|
|
continue
|
|
}
|
|
var waferProduct, waferID string
|
|
var quantity float64 //, stockOutQuantity
|
|
for _, tcSfe := range tcSfc.TcSfeFile {
|
|
if tcSfe.TcSfe01 == tcSfc.TcSfc01 && tcSfe.TcSfe02 == tcSfd.TcSfd02 {
|
|
quantity += tcSfe.TcSfe12
|
|
//stockOutQuantity += tcSfe.TcSfe14
|
|
if tcSfe.TcSfe17 == "Y" {
|
|
waferProduct = tcSfe.ImaFile.Ima02
|
|
waferID = tcSfe.TcSfe15
|
|
}
|
|
}
|
|
}
|
|
if waferProduct == "" && len(tcSfc.TcSfeFile) > 0 {
|
|
waferProduct = tcSfc.TcSfeFile[0].ImaFile.Ima02
|
|
}
|
|
var returnQuantity, failQuantity, passQuantity float64
|
|
orderDateStockMap := make(map[string][]float64)
|
|
for _, rvb := range tcSfd.RvbFile {
|
|
if _, ok := orderDateStockMap[rvb.RvaFile.Rva06.Format("2006-01-02")]; !ok {
|
|
orderDateStockMap[rvb.RvaFile.Rva06.Format("2006-01-02")] = []float64{0, 0}
|
|
}
|
|
for _, idd := range rvb.IddFile {
|
|
if idd.Idd11 == rvb.Rvb02 {
|
|
returnQuantity += idd.Idd13
|
|
if idd.Idd06 == "BIN99" {
|
|
orderDateStockMap[rvb.RvaFile.Rva06.Format("2006-01-02")][1] += idd.Idd13
|
|
failQuantity += idd.Idd13
|
|
} else {
|
|
orderDateStockMap[rvb.RvaFile.Rva06.Format("2006-01-02")][0] += idd.Idd13
|
|
passQuantity += idd.Idd13
|
|
}
|
|
}
|
|
}
|
|
}
|
|
quantity, _ = decimal.NewFromFloat(quantity).Round(6).Float64()
|
|
|
|
var passProbability string
|
|
if strings.Contains(tcSfc.TcSfc01, "M596") {
|
|
var reports []*model.Report
|
|
global.PostGreSQL.Where("pbi = ? AND product = ? AND lot = ?", tcSfc.TcSfc01, tcSfd.ImaFile.Ima02,
|
|
tcSfd.TcSfd06).Find(&reports)
|
|
for _, report := range reports {
|
|
testQuantityDecimal, _ := decimal.NewFromString(report.TestQuantity)
|
|
testQuantityFloat, _ := testQuantityDecimal.Float64()
|
|
passQuantity += testQuantityFloat
|
|
}
|
|
}
|
|
//if stockOutQuantity != 0 {
|
|
// passProbability = decimal.NewFromFloat(passQuantity).Div(decimal.NewFromFloat(stockOutQuantity)).
|
|
// Round(4).Mul(decimal.NewFromFloat(100)).String()
|
|
//}
|
|
passProbability = decimal.NewFromFloat(passQuantity).Div(decimal.NewFromFloat(tcSfd.TcSfd05)).
|
|
Round(4).Mul(decimal.NewFromFloat(100)).String()
|
|
global.PostGreSQL.Create(&model.ABList{
|
|
Status: status,
|
|
OrderDate: tcSfc.TcSfc02.Format("2006-01-02"),
|
|
PBI: tcSfc.TcSfc01,
|
|
OutsourcingPBI: tcSfd.TcSfd13,
|
|
Product: strings.ReplaceAll(strings.ReplaceAll(tcSfd.ImaFile.Ima02, "管装", ""), "白板", ""),
|
|
WaferProduct: waferProduct,
|
|
Package: tcSfd.ImaFile.Ima021,
|
|
Factory: tcSfc.PmcFile.Pmc03,
|
|
Lot: tcSfd.TcSfd06,
|
|
Seal: tcSfd.TcSfdUd02,
|
|
WaferID: waferID,
|
|
Quantity: quantity,
|
|
//StockOutQuantity: stockOutQuantity,
|
|
StockOutQuantity: tcSfd.TcSfd05,
|
|
StockInQuantity: returnQuantity,
|
|
PassQuantity: passQuantity,
|
|
FailQuantity: failQuantity,
|
|
OnlineQuantity: tcSfd.TcSfd05 - returnQuantity,
|
|
PassProbability: passProbability + "%",
|
|
})
|
|
var abList *model.ABList
|
|
global.PostGreSQL.Where("pbi = ? AND outsourcing_pbi = ?", tcSfc.TcSfc01, tcSfd.TcSfd13).Find(&abList)
|
|
|
|
var abListStock []*model.ABListStock
|
|
for k, v := range orderDateStockMap {
|
|
abListStock = append(abListStock, &model.ABListStock{
|
|
ABListID: abList.ID,
|
|
ReturnDate: k,
|
|
PassQuantity: v[0],
|
|
FailQuantity: v[1],
|
|
})
|
|
}
|
|
global.PostGreSQL.Create(&abListStock)
|
|
}
|
|
}
|
|
}
|
|
|
|
func CronBPList() {
|
|
var oldTcSfcFile []*model.TcSfcFile
|
|
var bpListIDs []string
|
|
global.PostGreSQL.Model(&model.BPList{}).Where("status = ?", "未结案").
|
|
Select("pbi").Group("pbi").Find(&bpListIDs)
|
|
_ = global.Oracle.Transaction(func(tx *gorm.DB) error {
|
|
page := len(bpListIDs)/200 + 1
|
|
for i := 0; i < page; i++ {
|
|
var pageTcSfcFile []*model.TcSfcFile
|
|
var s []string
|
|
if i == page-1 {
|
|
s = bpListIDs[i*200:]
|
|
} else {
|
|
s = bpListIDs[i*200 : (i+1)*200]
|
|
}
|
|
tx.Where("tc_sfc01 IN ? AND tc_sfc08 LIKE ?", s, "%MH%").
|
|
Preload("TcSfdFile", func(db *gorm.DB) *gorm.DB {
|
|
return db.Preload("SfbFile").Preload("ImaFile").Preload("RvbFile",
|
|
func(db *gorm.DB) *gorm.DB {
|
|
return db.Preload("IddFile").Preload("RvaFile")
|
|
})
|
|
}).Preload("TcSfeFile", func(db *gorm.DB) *gorm.DB {
|
|
return db.Preload("ImaFile")
|
|
}).
|
|
Preload("PmcFile").Find(&pageTcSfcFile)
|
|
oldTcSfcFile = append(oldTcSfcFile, pageTcSfcFile...)
|
|
}
|
|
return nil
|
|
})
|
|
for _, tcSfc := range oldTcSfcFile {
|
|
for _, tcSfd := range tcSfc.TcSfdFile {
|
|
status := "未结案"
|
|
if tcSfd.SfbFile.Sfb04 == "8" {
|
|
status = "结案"
|
|
} else if tcSfd.SfbFile.Sfb04 == "0" {
|
|
continue
|
|
}
|
|
|
|
var returnQuantity, dieQuantity float64
|
|
orderDateStockMap := make(map[string][]float64)
|
|
for _, rvb := range tcSfd.RvbFile {
|
|
if _, ok := orderDateStockMap[rvb.RvaFile.Rva06.Format("2006-01-02")]; !ok {
|
|
orderDateStockMap[rvb.RvaFile.Rva06.Format("2006-01-02")] = []float64{0, 0}
|
|
}
|
|
returnQuantity += rvb.Rvb30
|
|
dieQuantity += rvb.Rvb85
|
|
orderDateStockMap[rvb.RvaFile.Rva06.Format("2006-01-02")][0] += rvb.Rvb30
|
|
orderDateStockMap[rvb.RvaFile.Rva06.Format("2006-01-02")][1] += rvb.Rvb85
|
|
}
|
|
var bpList *model.BPList
|
|
global.PostGreSQL.Where("pbi = ? AND outsourcing_pbi = ?",
|
|
tcSfc.TcSfc01, tcSfd.TcSfd13).Find(&bpList)
|
|
global.PostGreSQL.Transaction(func(tx *gorm.DB) error {
|
|
global.PostGreSQL.Model(&bpList).Where("pbi = ? AND outsourcing_pbi = ?",
|
|
tcSfc.TcSfc01, tcSfd.TcSfd13).Updates(map[string]interface{}{
|
|
"status": status,
|
|
"online_quantity": tcSfd.TcSfd05 - returnQuantity,
|
|
"return_quantity": returnQuantity,
|
|
"die_quantity": dieQuantity,
|
|
})
|
|
for k, v := range orderDateStockMap {
|
|
var bpListStock *model.BPListStock
|
|
if errors.Is(global.PostGreSQL.Where("bp_list_id = ? AND return_date = ?", bpList.ID, k).
|
|
First(&bpListStock).Error, gorm.ErrRecordNotFound) {
|
|
global.PostGreSQL.Create(&model.BPListStock{
|
|
BPListID: bpList.ID,
|
|
ReturnDate: k,
|
|
Quantity: v[0],
|
|
DieQuantity: v[1],
|
|
})
|
|
} else {
|
|
global.PostGreSQL.Model(&bpListStock).Where("bp_list_id = ? AND return_date = ?", bpList.ID, k).
|
|
Updates(map[string]interface{}{
|
|
"quantity": v[0],
|
|
"die_quantity": v[1],
|
|
})
|
|
}
|
|
}
|
|
return nil
|
|
})
|
|
}
|
|
}
|
|
|
|
var newTcSfcFile []*model.TcSfcFile
|
|
global.PostGreSQL.Model(&model.BPList{}).Select("pbi").Group("pbi").Find(&bpListIDs)
|
|
_ = global.Oracle.Transaction(func(tx *gorm.DB) error {
|
|
var tcSfcFilePBIs []string
|
|
tx.Model(&model.TcSfcFile{}).Where("tc_sfc01 NOT IN ? AND tc_sfc08 LIKE ?", bpListIDs, "%MH%").
|
|
Order("tc_sfc01").Select("tc_sfc01").Find(&tcSfcFilePBIs)
|
|
//tx.Model(&model.TcSfcFile{}).Where("tc_sfc08 LIKE ?", "%MH%").
|
|
// Order("tc_sfc01").Select("tc_sfc01").Find(&tcSfcFilePBIs)
|
|
page := len(tcSfcFilePBIs)/200 + 1
|
|
for i := 0; i < page; i++ {
|
|
var pageTcSfcFile []*model.TcSfcFile
|
|
var s []string
|
|
if i == page-1 {
|
|
s = tcSfcFilePBIs[i*200:]
|
|
} else {
|
|
s = tcSfcFilePBIs[i*200 : (i+1)*200]
|
|
}
|
|
tx.Where("tc_sfc01 IN ? AND tc_sfc08 LIKE ?", s, "%MH%"). // AND tc_sfc10 = ?, "N"
|
|
Preload("TcSfdFile", func(db *gorm.DB) *gorm.DB {
|
|
return db.Preload("SfbFile").Preload("ImaFile").Preload("RvbFile", func(db *gorm.DB) *gorm.DB {
|
|
return db.Preload("IddFile").Preload("RvaFile")
|
|
})
|
|
}).Preload("TcSfeFile", func(db *gorm.DB) *gorm.DB {
|
|
return db.Preload("ImaFile")
|
|
}).Preload("PmcFile").Find(&pageTcSfcFile)
|
|
newTcSfcFile = append(newTcSfcFile, pageTcSfcFile...)
|
|
}
|
|
return nil
|
|
})
|
|
|
|
for _, tcSfc := range newTcSfcFile {
|
|
for _, tcSfd := range tcSfc.TcSfdFile {
|
|
status := "未结案"
|
|
if tcSfd.SfbFile.Sfb04 == "8" {
|
|
status = "结案"
|
|
} else if tcSfd.SfbFile.Sfb04 == "0" {
|
|
continue
|
|
}
|
|
var waferID string
|
|
for _, tcSfe := range tcSfc.TcSfeFile {
|
|
if tcSfe.TcSfe01 == tcSfc.TcSfc01 && tcSfe.TcSfe02 == tcSfd.TcSfd02 {
|
|
waferID = tcSfe.TcSfe15
|
|
}
|
|
}
|
|
var returnQuantity, dieQuantity float64
|
|
orderDateStockMap := make(map[string][]float64)
|
|
for _, rvb := range tcSfd.RvbFile {
|
|
if _, ok := orderDateStockMap[rvb.RvaFile.Rva06.Format("2006-01-02")]; !ok {
|
|
orderDateStockMap[rvb.RvaFile.Rva06.Format("2006-01-02")] = []float64{0, 0}
|
|
}
|
|
returnQuantity += rvb.Rvb30
|
|
dieQuantity += rvb.Rvb85
|
|
orderDateStockMap[rvb.RvaFile.Rva06.Format("2006-01-02")][0] += rvb.Rvb30
|
|
orderDateStockMap[rvb.RvaFile.Rva06.Format("2006-01-02")][1] += rvb.Rvb85
|
|
}
|
|
|
|
global.PostGreSQL.Create(&model.BPList{
|
|
Status: status,
|
|
OrderDate: tcSfc.TcSfc02.Format("2006-01-02"),
|
|
PBI: tcSfc.TcSfc01,
|
|
OutsourcingPBI: tcSfd.TcSfd13,
|
|
Product: tcSfd.ImaFile.Ima02,
|
|
Package: tcSfd.ImaFile.Ima021,
|
|
Factory: tcSfc.PmcFile.Pmc03,
|
|
Lot: tcSfd.TcSfd06,
|
|
WaferID: waferID,
|
|
Quantity: tcSfd.TcSfd05,
|
|
OnlineQuantity: tcSfd.TcSfd05 - returnQuantity,
|
|
ReturnQuantity: returnQuantity,
|
|
DieQuantity: dieQuantity,
|
|
})
|
|
var bpList *model.BPList
|
|
global.PostGreSQL.Where("pbi = ? AND outsourcing_pbi = ?", tcSfc.TcSfc01, tcSfd.TcSfd13).Find(&bpList)
|
|
|
|
var bpListStock []*model.BPListStock
|
|
for k, v := range orderDateStockMap {
|
|
bpListStock = append(bpListStock, &model.BPListStock{
|
|
BPListID: bpList.ID,
|
|
ReturnDate: k,
|
|
Quantity: v[0],
|
|
DieQuantity: v[1],
|
|
})
|
|
}
|
|
global.PostGreSQL.Create(&bpListStock)
|
|
}
|
|
}
|
|
}
|
|
|
|
func CronCPList() {
|
|
var oldTcSfcFile []*model.TcSfcFile
|
|
var cpListIDs []string
|
|
global.PostGreSQL.Model(&model.CPList{}).Where("status = ?", "未结案").
|
|
Select("pbi").Group("pbi").Find(&cpListIDs)
|
|
_ = global.Oracle.Transaction(func(tx *gorm.DB) error {
|
|
page := len(cpListIDs)/200 + 1
|
|
for i := 0; i < page; i++ {
|
|
var pageTcSfcFile []*model.TcSfcFile
|
|
var s []string
|
|
if i == page-1 {
|
|
s = cpListIDs[i*200:]
|
|
} else {
|
|
s = cpListIDs[i*200 : (i+1)*200]
|
|
}
|
|
tx.Where("tc_sfc01 IN ? AND tc_sfc08 = ?", s, "CP").
|
|
Preload("TcSfdFile", func(db *gorm.DB) *gorm.DB {
|
|
return db.Preload("SfbFile").Preload("ImaFile").Preload("TcImbFile").Preload("RvbFile", func(db *gorm.DB) *gorm.DB {
|
|
return db.Preload("IddFile").Preload("RvaFile")
|
|
})
|
|
}).Preload("TcSfeFile", func(db *gorm.DB) *gorm.DB {
|
|
return db.Preload("ImaFile")
|
|
}).
|
|
Preload("PmcFile").Find(&pageTcSfcFile)
|
|
oldTcSfcFile = append(oldTcSfcFile, pageTcSfcFile...)
|
|
}
|
|
return nil
|
|
})
|
|
for _, tcSfc := range oldTcSfcFile {
|
|
for _, tcSfd := range tcSfc.TcSfdFile {
|
|
status := "未结案"
|
|
if tcSfd.SfbFile.Sfb04 == "8" {
|
|
status = "结案"
|
|
} else if tcSfd.SfbFile.Sfb04 == "0" {
|
|
continue
|
|
}
|
|
|
|
var returnQuantity, dieQuantity float64
|
|
orderDateStockMap := make(map[string][]float64)
|
|
for _, rvb := range tcSfd.RvbFile {
|
|
if _, ok := orderDateStockMap[rvb.RvaFile.Rva06.Format("2006-01-02")]; !ok {
|
|
orderDateStockMap[rvb.RvaFile.Rva06.Format("2006-01-02")] = []float64{0, 0}
|
|
}
|
|
returnQuantity += rvb.Rvb30
|
|
dieQuantity += rvb.Rvb85
|
|
orderDateStockMap[rvb.RvaFile.Rva06.Format("2006-01-02")][0] += rvb.Rvb30
|
|
orderDateStockMap[rvb.RvaFile.Rva06.Format("2006-01-02")][1] += rvb.Rvb85
|
|
}
|
|
var cpList *model.CPList
|
|
global.PostGreSQL.Where("pbi = ? AND outsourcing_pbi = ?",
|
|
tcSfc.TcSfc01, tcSfd.TcSfd13).Find(&cpList)
|
|
global.PostGreSQL.Transaction(func(tx *gorm.DB) error {
|
|
global.PostGreSQL.Model(&cpList).Where("pbi = ? AND outsourcing_pbi = ?",
|
|
tcSfc.TcSfc01, tcSfd.TcSfd13).Updates(map[string]interface{}{
|
|
"status": status,
|
|
"online_quantity": tcSfd.TcSfd05 - returnQuantity,
|
|
"return_quantity": returnQuantity,
|
|
"die_quantity": dieQuantity,
|
|
})
|
|
for k, v := range orderDateStockMap {
|
|
var cpListStock *model.CPListStock
|
|
if errors.Is(global.PostGreSQL.Where("cp_list_id = ? AND return_date = ?", cpList.ID, k).
|
|
First(&cpListStock).Error, gorm.ErrRecordNotFound) {
|
|
global.PostGreSQL.Create(&model.CPListStock{
|
|
CPListID: cpList.ID,
|
|
ReturnDate: k,
|
|
Quantity: v[0],
|
|
DieQuantity: v[1],
|
|
})
|
|
} else {
|
|
global.PostGreSQL.Model(&cpListStock).Where("cp_list_id = ? AND return_date = ?", cpList.ID, k).
|
|
Updates(map[string]interface{}{
|
|
"quantity": v[0],
|
|
"die_quantity": v[1],
|
|
})
|
|
}
|
|
}
|
|
return nil
|
|
})
|
|
}
|
|
}
|
|
|
|
var newTcSfcFile []*model.TcSfcFile
|
|
global.PostGreSQL.Model(&model.CPList{}).Select("pbi").Group("pbi").Find(&cpListIDs)
|
|
_ = global.Oracle.Transaction(func(tx *gorm.DB) error {
|
|
var tcSfcFilePBIs []string
|
|
tx.Model(&model.TcSfcFile{}).Where("tc_sfc01 NOT IN ? AND tc_sfc08 = ?", cpListIDs, "CP").
|
|
Order("tc_sfc01").Select("tc_sfc01").Find(&tcSfcFilePBIs)
|
|
//tx.Model(&model.TcSfcFile{}).Where("tc_sfc08 = ?", "CP").
|
|
// Order("tc_sfc01").Select("tc_sfc01").Find(&tcSfcFilePBIs)
|
|
page := len(tcSfcFilePBIs)/200 + 1
|
|
for i := 0; i < page; i++ {
|
|
var pageTcSfcFile []*model.TcSfcFile
|
|
var s []string
|
|
if i == page-1 {
|
|
s = tcSfcFilePBIs[i*200:]
|
|
} else {
|
|
s = tcSfcFilePBIs[i*200 : (i+1)*200]
|
|
}
|
|
tx.Where("tc_sfc01 IN ? AND tc_sfc08 = ?", s, "CP").
|
|
Preload("TcSfdFile", func(db *gorm.DB) *gorm.DB {
|
|
return db.Preload("SfbFile").Preload("ImaFile").Preload("TcImbFile").Preload("RvbFile", func(db *gorm.DB) *gorm.DB {
|
|
return db.Preload("IddFile").Preload("RvaFile")
|
|
})
|
|
}).Preload("TcSfeFile", func(db *gorm.DB) *gorm.DB {
|
|
return db.Preload("ImaFile")
|
|
}).Preload("PmcFile").Find(&pageTcSfcFile)
|
|
newTcSfcFile = append(newTcSfcFile, pageTcSfcFile...)
|
|
}
|
|
return nil
|
|
})
|
|
|
|
for _, tcSfc := range newTcSfcFile {
|
|
for _, tcSfd := range tcSfc.TcSfdFile {
|
|
status := "未结案"
|
|
if tcSfd.SfbFile.Sfb04 == "8" {
|
|
status = "结案"
|
|
} else if tcSfd.SfbFile.Sfb04 == "0" {
|
|
continue
|
|
}
|
|
var waferID string
|
|
for _, tcSfe := range tcSfc.TcSfeFile {
|
|
if tcSfe.TcSfe01 == tcSfc.TcSfc01 && tcSfe.TcSfe02 == tcSfd.TcSfd02 {
|
|
waferID = tcSfe.TcSfe15
|
|
}
|
|
}
|
|
var returnQuantity, dieQuantity float64
|
|
orderDateStockMap := make(map[string][]float64)
|
|
for _, rvb := range tcSfd.RvbFile {
|
|
if _, ok := orderDateStockMap[rvb.RvaFile.Rva06.Format("2006-01-02")]; !ok {
|
|
orderDateStockMap[rvb.RvaFile.Rva06.Format("2006-01-02")] = []float64{0, 0}
|
|
}
|
|
returnQuantity += rvb.Rvb30
|
|
dieQuantity += rvb.Rvb85
|
|
orderDateStockMap[rvb.RvaFile.Rva06.Format("2006-01-02")][0] += rvb.Rvb30
|
|
orderDateStockMap[rvb.RvaFile.Rva06.Format("2006-01-02")][1] += rvb.Rvb85
|
|
}
|
|
|
|
global.PostGreSQL.Create(&model.CPList{
|
|
Status: status,
|
|
OrderDate: tcSfc.TcSfc02.Format("2006-01-02"),
|
|
PBI: tcSfc.TcSfc01,
|
|
OutsourcingPBI: tcSfd.TcSfd13,
|
|
Product: tcSfd.ImaFile.Ima02,
|
|
Package: tcSfd.ImaFile.Ima021,
|
|
Factory: tcSfc.PmcFile.Pmc03,
|
|
Lot: tcSfd.TcSfd06,
|
|
WaferID: waferID,
|
|
TestProgram: tcSfd.TcImbFile.TcImb03,
|
|
TestProgramVersion: tcSfd.TcImbFile.TcImb04,
|
|
Quantity: tcSfd.TcSfd05,
|
|
OnlineQuantity: tcSfd.TcSfd05 - returnQuantity,
|
|
ReturnQuantity: returnQuantity,
|
|
DieQuantity: dieQuantity,
|
|
})
|
|
var cpList *model.CPList
|
|
global.PostGreSQL.Where("pbi = ? AND outsourcing_pbi = ?", tcSfc.TcSfc01, tcSfd.TcSfd13).Find(&cpList)
|
|
|
|
var cpListStock []*model.CPListStock
|
|
for k, v := range orderDateStockMap {
|
|
cpListStock = append(cpListStock, &model.CPListStock{
|
|
CPListID: cpList.ID,
|
|
ReturnDate: k,
|
|
Quantity: v[0],
|
|
DieQuantity: v[1],
|
|
})
|
|
}
|
|
global.PostGreSQL.Create(&cpListStock)
|
|
}
|
|
}
|
|
}
|
|
|
|
func CronFTList() {
|
|
var oldTcSfcFile []*model.TcSfcFile
|
|
var cpListIDs []string
|
|
global.PostGreSQL.Model(&model.FTList{}).Where("status = ?", "未结案").
|
|
Select("pbi").Group("pbi").Find(&cpListIDs)
|
|
_ = global.Oracle.Transaction(func(tx *gorm.DB) error {
|
|
page := len(cpListIDs)/200 + 1
|
|
for i := 0; i < page; i++ {
|
|
var pageTcSfcFile []*model.TcSfcFile
|
|
var s []string
|
|
if i == page-1 {
|
|
s = cpListIDs[i*200:]
|
|
} else {
|
|
s = cpListIDs[i*200 : (i+1)*200]
|
|
}
|
|
tx.Where("tc_sfc01 IN ? AND tc_sfc08 LIKE ?", s, "%FT%").
|
|
Preload("TcSfdFile", func(db *gorm.DB) *gorm.DB {
|
|
return db.Preload("SfbFile").Preload("ImaFile").Preload("TcImbFile").Preload("RvbFile", func(db *gorm.DB) *gorm.DB {
|
|
return db.Preload("IddFile").Preload("RvaFile")
|
|
})
|
|
}).Preload("TcSfeFile", func(db *gorm.DB) *gorm.DB {
|
|
return db.Preload("ImaFile")
|
|
}).
|
|
Preload("PmcFile").Find(&pageTcSfcFile)
|
|
oldTcSfcFile = append(oldTcSfcFile, pageTcSfcFile...)
|
|
}
|
|
return nil
|
|
})
|
|
for _, tcSfc := range oldTcSfcFile {
|
|
for _, tcSfd := range tcSfc.TcSfdFile {
|
|
status := "未结案"
|
|
if tcSfd.SfbFile.Sfb04 == "8" {
|
|
status = "结案"
|
|
} else if tcSfd.SfbFile.Sfb04 == "0" {
|
|
continue
|
|
}
|
|
|
|
var returnQuantity, passQuantity, failQuantity float64
|
|
orderDateStockMap := make(map[string][]float64)
|
|
for _, rvb := range tcSfd.RvbFile {
|
|
if _, ok := orderDateStockMap[rvb.RvaFile.Rva06.Format("2006-01-02")]; !ok {
|
|
orderDateStockMap[rvb.RvaFile.Rva06.Format("2006-01-02")] = []float64{0, 0}
|
|
}
|
|
returnQuantity += rvb.Rvb30
|
|
for _, idd := range rvb.IddFile {
|
|
if idd.Idd11 == rvb.Rvb02 {
|
|
if idd.Idd06 == "BIN99" {
|
|
orderDateStockMap[rvb.RvaFile.Rva06.Format("2006-01-02")][1] += idd.Idd13
|
|
failQuantity += idd.Idd13
|
|
} else {
|
|
orderDateStockMap[rvb.RvaFile.Rva06.Format("2006-01-02")][0] += idd.Idd13
|
|
passQuantity += idd.Idd13
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
var ftList *model.FTList
|
|
global.PostGreSQL.Where("pbi = ? AND outsourcing_pbi = ?",
|
|
tcSfc.TcSfc01, tcSfd.TcSfd13).Find(&ftList)
|
|
global.PostGreSQL.Transaction(func(tx *gorm.DB) error {
|
|
global.PostGreSQL.Model(&ftList).Where("pbi = ? AND outsourcing_pbi = ?",
|
|
tcSfc.TcSfc01, tcSfd.TcSfd13).Updates(map[string]interface{}{
|
|
"status": status,
|
|
"online_quantity": tcSfd.TcSfd05 - returnQuantity,
|
|
"return_quantity": returnQuantity,
|
|
"pass_quantity": passQuantity,
|
|
"fail_quantity": failQuantity,
|
|
})
|
|
for k, v := range orderDateStockMap {
|
|
var ftListStock *model.FTListStock
|
|
if errors.Is(global.PostGreSQL.Where("ft_list_id = ? AND return_date = ?", ftList.ID, k).
|
|
First(&ftListStock).Error, gorm.ErrRecordNotFound) {
|
|
global.PostGreSQL.Create(&model.FTListStock{
|
|
FTListID: ftList.ID,
|
|
ReturnDate: k,
|
|
PassQuantity: v[0],
|
|
FailQuantity: v[1],
|
|
})
|
|
} else {
|
|
global.PostGreSQL.Model(&ftListStock).Where("ft_list_id = ? AND return_date = ?", ftList.ID, k).
|
|
Updates(map[string]interface{}{
|
|
"pass_quantity": v[0],
|
|
"fail_quantity": v[1],
|
|
})
|
|
}
|
|
}
|
|
return nil
|
|
})
|
|
}
|
|
}
|
|
|
|
var newTcSfcFile []*model.TcSfcFile
|
|
global.PostGreSQL.Model(&model.FTList{}).Select("pbi").Group("pbi").Find(&cpListIDs)
|
|
_ = global.Oracle.Transaction(func(tx *gorm.DB) error {
|
|
var tcSfcFilePBIs []string
|
|
tx.Model(&model.TcSfcFile{}).Where("tc_sfc01 NOT IN ? AND (tc_sfc01 LIKE ? AND tc_sfc08 = ?) OR (tc_sfc08 = ?)",
|
|
cpListIDs, "M596%", "ABFT", "FT").Order("tc_sfc01").Select("tc_sfc01").Find(&tcSfcFilePBIs)
|
|
//tx.Model(&model.TcSfcFile{}).Where("(tc_sfc01 LIKE ? AND tc_sfc08 = ?) OR (tc_sfc08 = ?)", "M596%", "ABFT", "FT").
|
|
// Order("tc_sfc01").Select("tc_sfc01").Find(&tcSfcFilePBIs)
|
|
page := len(tcSfcFilePBIs)/200 + 1
|
|
for i := 0; i < page; i++ {
|
|
var pageTcSfcFile []*model.TcSfcFile
|
|
var s []string
|
|
if i == page-1 {
|
|
s = tcSfcFilePBIs[i*200:]
|
|
} else {
|
|
s = tcSfcFilePBIs[i*200 : (i+1)*200]
|
|
}
|
|
tx.Where("tc_sfc01 IN ? AND tc_sfc08 LIKE ?", s, "%FT%").
|
|
Preload("TcSfdFile", func(db *gorm.DB) *gorm.DB {
|
|
return db.Preload("SfbFile").Preload("ImaFile").Preload("TcImbFile").Preload("RvbFile", func(db *gorm.DB) *gorm.DB {
|
|
return db.Preload("IddFile").Preload("RvaFile")
|
|
})
|
|
}).Preload("TcSfeFile", func(db *gorm.DB) *gorm.DB {
|
|
return db.Preload("ImaFile")
|
|
}).Preload("PmcFile").Find(&pageTcSfcFile)
|
|
newTcSfcFile = append(newTcSfcFile, pageTcSfcFile...)
|
|
}
|
|
return nil
|
|
})
|
|
|
|
for _, tcSfc := range newTcSfcFile {
|
|
for _, tcSfd := range tcSfc.TcSfdFile {
|
|
status := "未结案"
|
|
if tcSfd.SfbFile.Sfb04 == "8" {
|
|
status = "结案"
|
|
} else if tcSfd.SfbFile.Sfb04 == "0" {
|
|
continue
|
|
}
|
|
var waferProduct string
|
|
for _, tcSfe := range tcSfc.TcSfeFile {
|
|
if tcSfe.TcSfe01 == tcSfc.TcSfc01 && tcSfe.TcSfe02 == tcSfd.TcSfd02 {
|
|
waferProduct = tcSfe.ImaFile.Ima02
|
|
}
|
|
}
|
|
var returnQuantity, passQuantity, failQuantity float64
|
|
orderDateStockMap := make(map[string][]float64)
|
|
for _, rvb := range tcSfd.RvbFile {
|
|
if _, ok := orderDateStockMap[rvb.RvaFile.Rva06.Format("2006-01-02")]; !ok {
|
|
orderDateStockMap[rvb.RvaFile.Rva06.Format("2006-01-02")] = []float64{0, 0}
|
|
}
|
|
returnQuantity += rvb.Rvb30
|
|
for _, idd := range rvb.IddFile {
|
|
if idd.Idd11 == rvb.Rvb02 {
|
|
if idd.Idd06 == "BIN99" {
|
|
orderDateStockMap[rvb.RvaFile.Rva06.Format("2006-01-02")][1] += idd.Idd13
|
|
failQuantity += idd.Idd13
|
|
} else {
|
|
orderDateStockMap[rvb.RvaFile.Rva06.Format("2006-01-02")][0] += idd.Idd13
|
|
passQuantity += idd.Idd13
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
global.PostGreSQL.Create(&model.FTList{
|
|
Status: status,
|
|
OrderDate: tcSfc.TcSfc02.Format("2006-01-02"),
|
|
PBI: tcSfc.TcSfc01,
|
|
OutsourcingPBI: tcSfd.TcSfd13,
|
|
Product: strings.ReplaceAll(strings.ReplaceAll(tcSfd.ImaFile.Ima02, "管装", ""), "白板", ""),
|
|
WaferProduct: waferProduct,
|
|
Package: tcSfd.ImaFile.Ima021,
|
|
Factory: tcSfc.PmcFile.Pmc03,
|
|
Lot: tcSfd.TcSfd06,
|
|
Seal: tcSfd.TcSfdUd02,
|
|
TestProgram: tcSfd.TcImbFile.TcImb03,
|
|
TestProgramVersion: tcSfd.TcImbFile.TcImb04,
|
|
Quantity: tcSfd.TcSfd05,
|
|
OnlineQuantity: tcSfd.TcSfd05 - returnQuantity,
|
|
ReturnQuantity: returnQuantity,
|
|
PassQuantity: passQuantity,
|
|
FailQuantity: failQuantity,
|
|
})
|
|
var ftList *model.FTList
|
|
global.PostGreSQL.Where("pbi = ? AND outsourcing_pbi = ?", tcSfc.TcSfc01, tcSfd.TcSfd13).Find(&ftList)
|
|
var ftListStock []*model.FTListStock
|
|
for k, v := range orderDateStockMap {
|
|
ftListStock = append(ftListStock, &model.FTListStock{
|
|
FTListID: ftList.ID,
|
|
ReturnDate: k,
|
|
PassQuantity: v[0],
|
|
FailQuantity: v[1],
|
|
})
|
|
}
|
|
global.PostGreSQL.Create(&ftListStock)
|
|
}
|
|
}
|
|
}
|
|
|
|
func CronTRList() {
|
|
var oldTcSfcFile []*model.TcSfcFile
|
|
var trListIDs []string
|
|
global.PostGreSQL.Model(&model.TRList{}).Where("status = ?", "未结案").
|
|
Select("pbi").Group("pbi").Find(&trListIDs)
|
|
_ = global.Oracle.Transaction(func(tx *gorm.DB) error {
|
|
page := len(trListIDs)/200 + 1
|
|
for i := 0; i < page; i++ {
|
|
var pageTcSfcFile []*model.TcSfcFile
|
|
var s []string
|
|
if i == page-1 {
|
|
s = trListIDs[i*200:]
|
|
} else {
|
|
s = trListIDs[i*200 : (i+1)*200]
|
|
}
|
|
tx.Where("tc_sfc01 IN ? AND tc_sfc08 LIKE ?", s, "%TR%").
|
|
Preload("TcSfdFile", func(db *gorm.DB) *gorm.DB {
|
|
return db.Preload("SfbFile").Preload("ImaFile").Preload("RvbFile", func(db *gorm.DB) *gorm.DB {
|
|
return db.Preload("IddFile").Preload("RvaFile")
|
|
})
|
|
}).Preload("TcSfeFile", func(db *gorm.DB) *gorm.DB {
|
|
return db.Preload("ImaFile")
|
|
}).
|
|
Preload("PmcFile").Find(&pageTcSfcFile)
|
|
oldTcSfcFile = append(oldTcSfcFile, pageTcSfcFile...)
|
|
}
|
|
return nil
|
|
})
|
|
for _, tcSfc := range oldTcSfcFile {
|
|
for _, tcSfd := range tcSfc.TcSfdFile {
|
|
status := "未结案"
|
|
if tcSfd.SfbFile.Sfb04 == "8" {
|
|
status = "结案"
|
|
} else if tcSfd.SfbFile.Sfb04 == "0" {
|
|
continue
|
|
}
|
|
|
|
var returnQuantity, failQuantity, passQuantity float64
|
|
orderDateStockMap := make(map[string][]float64)
|
|
for _, rvb := range tcSfd.RvbFile {
|
|
if _, ok := orderDateStockMap[rvb.RvaFile.Rva06.Format("2006-01-02")]; !ok {
|
|
orderDateStockMap[rvb.RvaFile.Rva06.Format("2006-01-02")] = []float64{0, 0}
|
|
}
|
|
for _, idd := range rvb.IddFile {
|
|
if idd.Idd11 == rvb.Rvb02 {
|
|
returnQuantity += idd.Idd13
|
|
if idd.Idd06 == "BIN99" {
|
|
orderDateStockMap[rvb.RvaFile.Rva06.Format("2006-01-02")][1] += idd.Idd13
|
|
failQuantity += idd.Idd13
|
|
} else {
|
|
orderDateStockMap[rvb.RvaFile.Rva06.Format("2006-01-02")][0] += idd.Idd13
|
|
passQuantity += idd.Idd13
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
var trList *model.TRList
|
|
global.PostGreSQL.Where("pbi = ? AND outsourcing_pbi = ?",
|
|
tcSfc.TcSfc01, tcSfd.TcSfd13).Find(&trList)
|
|
global.PostGreSQL.Transaction(func(tx *gorm.DB) error {
|
|
global.PostGreSQL.Model(&trList).Where("pbi = ? AND outsourcing_pbi = ?",
|
|
tcSfc.TcSfc01, tcSfd.TcSfd13).Updates(map[string]interface{}{
|
|
"status": status,
|
|
"online_quantity": tcSfd.TcSfd05 - returnQuantity,
|
|
"pass_quantity": passQuantity,
|
|
"fail_quantity": failQuantity,
|
|
})
|
|
for k, v := range orderDateStockMap {
|
|
var trListStock *model.TRListStock
|
|
if errors.Is(global.PostGreSQL.Where("tr_list_id = ? AND return_date = ?", trList.ID, k).
|
|
First(&trListStock).Error, gorm.ErrRecordNotFound) {
|
|
global.PostGreSQL.Create(&model.TRListStock{
|
|
TRListID: trList.ID,
|
|
ReturnDate: k,
|
|
PassQuantity: v[0],
|
|
FailQuantity: v[1],
|
|
})
|
|
} else {
|
|
global.PostGreSQL.Model(&trListStock).Where("tr_list_id = ? AND return_date = ?", trList.ID, k).
|
|
Updates(map[string]interface{}{
|
|
"pass_quantity": v[0],
|
|
"fail_quantity": v[1],
|
|
})
|
|
}
|
|
}
|
|
return nil
|
|
})
|
|
}
|
|
}
|
|
|
|
var newTcSfcFile []*model.TcSfcFile
|
|
global.PostGreSQL.Model(&model.ABList{}).Select("pbi").Group("pbi").Find(&trListIDs)
|
|
_ = global.Oracle.Transaction(func(tx *gorm.DB) error {
|
|
var tcSfcFilePBIs []string
|
|
tx.Model(&model.TcSfcFile{}).Where("tc_sfc01 NOT IN ? AND tc_sfc08 LIKE ? AND tc_sfc10 = ?", trListIDs, "%TR%", "N").
|
|
Order("tc_sfc01").Select("tc_sfc01").Find(&tcSfcFilePBIs)
|
|
//tx.Model(&model.TcSfcFile{}).Where("tc_sfc08 LIKE ?", "%TR%").
|
|
// Order("tc_sfc01").Select("tc_sfc01").Find(&tcSfcFilePBIs)
|
|
page := len(tcSfcFilePBIs)/200 + 1
|
|
for i := 0; i < page; i++ {
|
|
var pageTcSfcFile []*model.TcSfcFile
|
|
var s []string
|
|
if i == page-1 {
|
|
s = tcSfcFilePBIs[i*200:]
|
|
} else {
|
|
s = tcSfcFilePBIs[i*200 : (i+1)*200]
|
|
}
|
|
tx.Where("tc_sfc01 IN ? AND tc_sfc08 LIKE ?", s, "%TR%"). // AND tc_sfc10 = ?, "N"
|
|
Preload("TcSfdFile", func(db *gorm.DB) *gorm.DB {
|
|
return db.Preload("SfbFile").Preload("ImaFile").Preload("RvbFile", func(db *gorm.DB) *gorm.DB {
|
|
return db.Preload("IddFile").Preload("RvaFile")
|
|
})
|
|
}).Preload("TcSfeFile", func(db *gorm.DB) *gorm.DB {
|
|
return db.Preload("ImaFile")
|
|
}).Preload("PmcFile").Find(&pageTcSfcFile)
|
|
newTcSfcFile = append(newTcSfcFile, pageTcSfcFile...)
|
|
}
|
|
return nil
|
|
})
|
|
|
|
for _, tcSfc := range newTcSfcFile {
|
|
for _, tcSfd := range tcSfc.TcSfdFile {
|
|
status := "未结案"
|
|
if tcSfd.SfbFile.Sfb04 == "8" {
|
|
status = "结案"
|
|
} else if tcSfd.SfbFile.Sfb04 == "0" {
|
|
continue
|
|
}
|
|
var waferProduct string
|
|
for _, tcSfe := range tcSfc.TcSfeFile {
|
|
if tcSfe.TcSfe01 == tcSfc.TcSfc01 && tcSfe.TcSfe02 == tcSfd.TcSfd02 {
|
|
waferProduct = tcSfe.ImaFile.Ima02
|
|
}
|
|
}
|
|
var returnQuantity, failQuantity, passQuantity float64
|
|
orderDateStockMap := make(map[string][]float64)
|
|
for _, rvb := range tcSfd.RvbFile {
|
|
if _, ok := orderDateStockMap[rvb.RvaFile.Rva06.Format("2006-01-02")]; !ok {
|
|
orderDateStockMap[rvb.RvaFile.Rva06.Format("2006-01-02")] = []float64{0, 0}
|
|
}
|
|
for _, idd := range rvb.IddFile {
|
|
if idd.Idd11 == rvb.Rvb02 {
|
|
returnQuantity += idd.Idd13
|
|
if idd.Idd06 == "BIN99" {
|
|
orderDateStockMap[rvb.RvaFile.Rva06.Format("2006-01-02")][1] += idd.Idd13
|
|
failQuantity += idd.Idd13
|
|
} else {
|
|
orderDateStockMap[rvb.RvaFile.Rva06.Format("2006-01-02")][0] += idd.Idd13
|
|
passQuantity += idd.Idd13
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
global.PostGreSQL.Create(&model.TRList{
|
|
Status: status,
|
|
OrderDate: tcSfc.TcSfc02.Format("2006-01-02"),
|
|
PBI: tcSfc.TcSfc01,
|
|
OutsourcingPBI: tcSfd.TcSfd13,
|
|
Product: tcSfd.ImaFile.Ima02,
|
|
WaferProduct: waferProduct,
|
|
Package: tcSfd.ImaFile.Ima021,
|
|
Factory: tcSfc.PmcFile.Pmc03,
|
|
Lot: tcSfd.TcSfd06,
|
|
Seal: tcSfd.TcSfdUd02,
|
|
Quantity: tcSfd.TcSfd05,
|
|
OnlineQuantity: tcSfd.TcSfd05 - returnQuantity,
|
|
PassQuantity: passQuantity,
|
|
FailQuantity: failQuantity,
|
|
})
|
|
var trList *model.TRList
|
|
global.PostGreSQL.Where("pbi = ? AND outsourcing_pbi = ?", tcSfc.TcSfc01, tcSfd.TcSfd13).Find(&trList)
|
|
|
|
var trListStock []*model.TRListStock
|
|
for k, v := range orderDateStockMap {
|
|
trListStock = append(trListStock, &model.TRListStock{
|
|
TRListID: trList.ID,
|
|
ReturnDate: k,
|
|
PassQuantity: v[0],
|
|
FailQuantity: v[1],
|
|
})
|
|
}
|
|
global.PostGreSQL.Create(&trListStock)
|
|
}
|
|
}
|
|
}
|
|
|
|
//func OldFTList(r *request.FTList) ([]*model.ReportList, int64) {
|
|
// var sql string
|
|
// if r.Product != "" {
|
|
// sql += "product = '" + r.Product + "'"
|
|
// }
|
|
// if r.Lot != "" {
|
|
// if sql == "" {
|
|
// sql += "lot ='" + r.Lot + "'"
|
|
// } else {
|
|
// sql += " AND lot = '" + r.Lot + "'"
|
|
// }
|
|
// }
|
|
// if r.Factory != "" {
|
|
// if sql == "" {
|
|
// sql += "factory ='" + r.Factory + "'"
|
|
// } else {
|
|
// sql += " AND factory = '" + r.Factory + "'"
|
|
// }
|
|
// }
|
|
// if r.TestProgram != "" {
|
|
// if sql == "" {
|
|
// sql += "test_program ='" + r.TestProgram + "'"
|
|
// } else {
|
|
// sql += " AND test_program = '" + r.TestProgram + "'"
|
|
// }
|
|
// }
|
|
// if r.PBI != "" {
|
|
// if sql == "" {
|
|
// sql += "pbi ='" + r.PBI + "'"
|
|
// } else {
|
|
// sql += " AND pbi = '" + r.PBI + "'"
|
|
// }
|
|
// }
|
|
// if r.OrderDate != "" {
|
|
// if sql == "" {
|
|
// sql += "order_date ='" + r.OrderDate + "'"
|
|
// } else {
|
|
// sql += " AND order_date = '" + r.OrderDate + "'"
|
|
// }
|
|
// }
|
|
// if r.Seal != "" {
|
|
// if sql == "" {
|
|
// sql += "seal ='" + r.Seal + "'"
|
|
// } else {
|
|
// sql += " AND seal = '" + r.Seal + "'"
|
|
// }
|
|
// }
|
|
// if r.Page > 0 {
|
|
// r.Page--
|
|
// }
|
|
// var reportList []*model.ReportList
|
|
// var total int64
|
|
// if r.QueryType == "List" {
|
|
// var reports []*model.Report
|
|
// global.PostGreSQL.Where("step = ?", "FT").Order("pbi").Find(&reports).Count(&total).
|
|
// Offset(r.Page * r.PageSize).Limit(r.PageSize).Find(&reports)
|
|
// for _, report := range reports {
|
|
// var finalReports []*model.FinalReport
|
|
// global.PostGreSQL.Where("pbi = ? AND product = ? AND lot = ? AND step = ?",
|
|
// report.PBI, report.Product, report.Lot, "FT").Find(&finalReports)
|
|
// var reportTestQuantity, reportPassQuantity, reportPassProbability string
|
|
// for _, finalReport := range finalReports {
|
|
// reportTestQuantityDecimal, _ := decimal.NewFromString(reportTestQuantity)
|
|
// reportPassQuantityDecimal, _ := decimal.NewFromString(reportPassQuantity)
|
|
// finalReportTestQuantityDecimal, _ := decimal.NewFromString(finalReport.ReportTestQuantity)
|
|
// finalReportPassQuantityDecimal, _ := decimal.NewFromString(finalReport.ReportPassQuantity)
|
|
// reportTestQuantity = reportTestQuantityDecimal.Add(finalReportTestQuantityDecimal).String()
|
|
// reportPassQuantity = reportPassQuantityDecimal.Add(finalReportPassQuantityDecimal).String()
|
|
// }
|
|
// reportTestQuantityDecimal, _ := decimal.NewFromString(reportTestQuantity)
|
|
// reportPassQuantityDecimal, _ := decimal.NewFromString(reportPassQuantity)
|
|
// if !reportTestQuantityDecimal.IsZero() {
|
|
// reportPassProbability = reportPassQuantityDecimal.Div(reportTestQuantityDecimal).
|
|
// Mul(decimal.NewFromInt(100)).Round(2).String() + "%"
|
|
// }
|
|
// isAppend := true
|
|
// for _, list := range reportList {
|
|
// if list.PBI == report.PBI {
|
|
// firstPassQuantity, _ := decimal.NewFromString(report.FirstPassQuantity)
|
|
// listFirstPassQuantity, _ := decimal.NewFromString(list.PassQuantity)
|
|
// testQuantity, _ := decimal.NewFromString(report.TestQuantity)
|
|
// passQuantity, _ := decimal.NewFromString(report.PassQuantity)
|
|
// listTestQuantity, _ := decimal.NewFromString(list.TestQuantity)
|
|
// listPassQuantity, _ := decimal.NewFromString(list.PassQuantity)
|
|
// list.TestQuantity = testQuantity.Add(listTestQuantity).String()
|
|
// list.PassQuantity = passQuantity.Add(listPassQuantity).String()
|
|
// list.PassProbability = passQuantity.Add(listPassQuantity).Div(testQuantity.Add(listTestQuantity)).
|
|
// Round(4).Mul(decimal.NewFromInt(100)).String() + "%"
|
|
//
|
|
// list.FirstPassQuantity = firstPassQuantity.Add(listFirstPassQuantity).String()
|
|
// list.PassProbability = firstPassQuantity.Add(listFirstPassQuantity).Div(testQuantity.Add(listTestQuantity)).
|
|
// Round(4).Mul(decimal.NewFromInt(100)).String() + "%"
|
|
//
|
|
// //reportTestQuantity, _ := decimal.NewFromString(finalReport.ReportTestQuantity)
|
|
// //reportPassQuantity, _ := decimal.NewFromString(finalReport.ReportPassQuantity)
|
|
// //listReportTestQuantity, _ := decimal.NewFromString(list.ReportTestQuantity)
|
|
// //listReportPassQuantity, _ := decimal.NewFromString(list.ReportPassQuantity)
|
|
// //if !reportTestQuantity.Add(listReportTestQuantity).IsZero() {
|
|
// // list.ReportTestQuantity = reportTestQuantity.Add(listReportTestQuantity).String()
|
|
// // list.ReportPassQuantity = reportPassQuantity.Add(listReportPassQuantity).String()
|
|
// // list.PassProbability = reportPassQuantity.Add(listReportPassQuantity).Div(reportTestQuantity.Add(listReportTestQuantity)).
|
|
// // Round(4).Mul(decimal.NewFromInt(100)).String() + "%"
|
|
// //}
|
|
// isAppend = false
|
|
// break
|
|
// }
|
|
// }
|
|
// if isAppend {
|
|
// reportList = append(reportList, &model.ReportList{
|
|
// Product: report.Product,
|
|
// Lot: report.Lot,
|
|
// Factory: report.Factory,
|
|
// TestMachine: report.TestMachine,
|
|
// TestProgram: report.TestProgram,
|
|
// PBI: report.PBI,
|
|
// OrderDate: report.OrderDate,
|
|
// Seal: report.Seal,
|
|
// TestQuantity: report.TestQuantity,
|
|
// FirstPassQuantity: report.FirstPassQuantity,
|
|
// FirstPassProbability: report.FirstPassProbability,
|
|
// PassQuantity: report.PassQuantity,
|
|
// PassProbability: report.PassProbability,
|
|
// ReportTestQuantity: reportTestQuantity,
|
|
// ReportPassQuantity: reportPassQuantity,
|
|
// ReportPassProbability: reportPassProbability,
|
|
// TestTime: report.TestTime,
|
|
// Step: "FT",
|
|
// StackingMaterials: report.StackingMaterials,
|
|
// })
|
|
// }
|
|
// }
|
|
// for _, reportlist := range reportList {
|
|
// var testQuantityDiffLabel, passQuantityDiffLabel, returnProbabilityLabel bool
|
|
// testQuantityDecimal, _ := decimal.NewFromString(reportlist.TestQuantity)
|
|
// reportTestQuantityDecimal, _ := decimal.NewFromString(reportlist.ReportTestQuantity)
|
|
// firstPassQuantityDecimal, _ := decimal.NewFromString(reportlist.FirstPassQuantity)
|
|
// passQuantityDecimal, _ := decimal.NewFromString(reportlist.PassQuantity)
|
|
// reportPassQuantityDecimal, _ := decimal.NewFromString(reportlist.ReportPassQuantity)
|
|
// if !testQuantityDecimal.IsZero() {
|
|
// diff := reportTestQuantityDecimal.Sub(testQuantityDecimal).Div(testQuantityDecimal).Round(4).
|
|
// Mul(decimal.NewFromInt(100))
|
|
// if reportTestQuantityDecimal.Sub(testQuantityDecimal).LessThan(decimal.NewFromInt(0)) ||
|
|
// decimal.NewFromInt(5).LessThanOrEqual(diff) {
|
|
// testQuantityDiffLabel = true
|
|
// }
|
|
// reportlist.TestQuantityDiff = diff.String() + "%"
|
|
// reportlist.TestQuantityDiffLabel = testQuantityDiffLabel
|
|
// probability := passQuantityDecimal.Sub(firstPassQuantityDecimal).Div(testQuantityDecimal).Round(4).
|
|
// Mul(decimal.NewFromInt(100))
|
|
// if probability.LessThan(decimal.NewFromInt(0)) ||
|
|
// decimal.NewFromInt(5).LessThanOrEqual(probability) {
|
|
// returnProbabilityLabel = true
|
|
// }
|
|
// reportlist.ReturnProbability = probability.String() + "%"
|
|
// reportlist.ReturnProbabilityLabel = returnProbabilityLabel
|
|
// }
|
|
// if !reportPassQuantityDecimal.IsZero() {
|
|
// diff := passQuantityDecimal.Sub(reportPassQuantityDecimal).Div(reportPassQuantityDecimal).Round(4).
|
|
// Mul(decimal.NewFromInt(100))
|
|
// if passQuantityDecimal.Sub(reportPassQuantityDecimal).LessThan(decimal.NewFromInt(0)) ||
|
|
// decimal.NewFromInt(5).LessThanOrEqual(diff) {
|
|
// passQuantityDiffLabel = true
|
|
// }
|
|
// reportlist.PassQuantityDiff = diff.String() + "%"
|
|
// reportlist.PassQuantityDiffLabel = passQuantityDiffLabel
|
|
// }
|
|
// }
|
|
// } else if r.QueryType == "Bin" {
|
|
// var reports []*model.Report
|
|
// global.PostGreSQL.Where("step = ?", "FT").Where(sql).
|
|
// Preload("BinFail", func(db *gorm.DB) *gorm.DB {
|
|
// return db.Where("report_site_id = ?", "0")
|
|
// }).Preload("Site", func(db *gorm.DB) *gorm.DB {
|
|
// return db.Preload("BinFail")
|
|
// }).Order("pbi").Find(&reports)
|
|
// for _, report := range reports {
|
|
// isAppend := true
|
|
// for _, list := range reportList {
|
|
// if list.PBI == report.PBI {
|
|
// reportTestQuantity, _ := decimal.NewFromString(report.TestQuantity)
|
|
// reportPassQuantity, _ := decimal.NewFromString(report.PassQuantity)
|
|
// listTestQuantity, _ := decimal.NewFromString(list.TestQuantity)
|
|
// listPassQuantity, _ := decimal.NewFromString(list.PassQuantity)
|
|
// list.TestQuantity = reportTestQuantity.Add(listTestQuantity).String()
|
|
// list.PassQuantity = reportPassQuantity.Add(listPassQuantity).String()
|
|
// list.PassProbability = reportPassQuantity.Add(listPassQuantity).Div(reportTestQuantity.Add(listTestQuantity)).
|
|
// Round(4).Mul(decimal.NewFromInt(100)).String() + "%"
|
|
// isAppend = false
|
|
// for _, binFail := range report.BinFail {
|
|
// quantityDecimal, _ := decimal.NewFromString(binFail.Quantity)
|
|
// quantity, _ := quantityDecimal.Float64()
|
|
// list.SoftBinFailMap[binFail.SoftBin] += quantity
|
|
// list.HardBinFailMap[binFail.HardBin] += quantity
|
|
// }
|
|
// for _, site := range report.Site {
|
|
// for _, reportSite := range list.Site {
|
|
// if reportSite.Site == site.Site {
|
|
// siteTestQuantity, _ := decimal.NewFromString(site.TestQuantity)
|
|
// sitePassQuantity, _ := decimal.NewFromString(site.PassQuantity)
|
|
// reportSiteTestQuantity, _ := decimal.NewFromString(reportSite.TestQuantity)
|
|
// reportSitePassQuantity, _ := decimal.NewFromString(reportSite.PassQuantity)
|
|
// reportSite.TestQuantity = siteTestQuantity.Add(reportSiteTestQuantity).String()
|
|
// reportSite.PassQuantity = sitePassQuantity.Add(reportSitePassQuantity).String()
|
|
// reportSite.PassProbability = sitePassQuantity.Add(reportSitePassQuantity).Div(siteTestQuantity.Add(reportSiteTestQuantity)).
|
|
// Round(4).Mul(decimal.NewFromInt(100)).String() + "%"
|
|
// for _, binFail := range site.BinFail {
|
|
// quantityDecimal, _ := decimal.NewFromString(binFail.Quantity)
|
|
// quantity, _ := quantityDecimal.Float64()
|
|
// reportSite.SoftBinFailMap[binFail.SoftBin] += quantity
|
|
// reportSite.HardBinFailMap[binFail.HardBin] += quantity
|
|
// }
|
|
// break
|
|
// }
|
|
// }
|
|
// }
|
|
// break
|
|
// }
|
|
// }
|
|
// if isAppend {
|
|
// softBinFail, hardBinFail := make(map[string]float64), make(map[string]float64)
|
|
// for _, binFail := range report.BinFail {
|
|
// quantityDecimal, _ := decimal.NewFromString(binFail.Quantity)
|
|
// quantity, _ := quantityDecimal.Float64()
|
|
// softBinFail[binFail.SoftBin] += quantity
|
|
// hardBinFail[binFail.HardBin] += quantity
|
|
// }
|
|
// var reportListSites []*model.ReportListSites
|
|
// for _, site := range report.Site {
|
|
// siteSoftBinFail, siteHardBinFail := make(map[string]float64), make(map[string]float64)
|
|
// for _, binFail := range site.BinFail {
|
|
// quantityDecimal, _ := decimal.NewFromString(binFail.Quantity)
|
|
// quantity, _ := quantityDecimal.Float64()
|
|
// siteSoftBinFail[binFail.SoftBin] += quantity
|
|
// siteHardBinFail[binFail.HardBin] += quantity
|
|
// }
|
|
// reportListSites = append(reportListSites, &model.ReportListSites{
|
|
// ID: site.ID,
|
|
// ReportID: site.ReportID,
|
|
// Site: site.Site,
|
|
// TestQuantity: site.TestQuantity,
|
|
// PassQuantity: site.PassQuantity,
|
|
// PassProbability: site.PassProbability,
|
|
// SoftBinFailMap: siteSoftBinFail,
|
|
// HardBinFailMap: siteHardBinFail,
|
|
// })
|
|
// }
|
|
// //var finalReport *model.FinalReport
|
|
// //if errors.Is(global.PostGreSQL.Where("pbi = ? AND product = ? AND lot = ?",
|
|
// // report.PBI, report.Product, report.Lot).Find(&finalReport).Error, gorm.ErrRecordNotFound) {
|
|
// // //finalReport.ReportTestQuantity = ""
|
|
// // //finalReport.ReportPassQuantity = ""
|
|
// // //finalReport.ReportPassProbability = ""
|
|
// //}
|
|
// reportList = append(reportList, &model.ReportList{
|
|
// Product: report.Product,
|
|
// Lot: report.Lot,
|
|
// Factory: report.Factory,
|
|
// TestMachine: report.TestMachine,
|
|
// TestProgram: report.TestProgram,
|
|
// PBI: report.PBI,
|
|
// OrderDate: report.OrderDate,
|
|
// Seal: report.Seal,
|
|
// TestQuantity: report.TestQuantity,
|
|
// FirstPassQuantity: report.FirstPassQuantity,
|
|
// FirstPassProbability: report.FirstPassProbability,
|
|
// PassQuantity: report.PassQuantity,
|
|
// PassProbability: report.PassProbability,
|
|
// //ReportTestQuantity: finalReport.ReportTestQuantity,
|
|
// //ReportPassQuantity: finalReport.ReportPassQuantity,
|
|
// //ReportPassProbability: finalReport.ReportPassProbability,
|
|
// TestTime: report.TestTime,
|
|
// Step: report.Step,
|
|
// SoftBinFailMap: softBinFail,
|
|
// HardBinFailMap: hardBinFail,
|
|
// Site: reportListSites,
|
|
// })
|
|
// }
|
|
// }
|
|
// for _, list := range reportList {
|
|
// testQuantity, _ := decimal.NewFromString(list.TestQuantity)
|
|
//
|
|
// var softBinFail, hardBinFail []*model.ReportBinFail
|
|
// for softBin, softBinQuantity := range list.SoftBinFailMap {
|
|
// softBinQuantityDecimal := decimal.NewFromFloat(softBinQuantity)
|
|
// softBinFail = append(softBinFail, &model.ReportBinFail{
|
|
// Bin: softBin,
|
|
// Quantity: softBinQuantity,
|
|
// Proportion: softBinQuantityDecimal.Div(testQuantity).Round(4).Mul(decimal.NewFromInt(100)).String() + "%",
|
|
// })
|
|
// }
|
|
// sort.Slice(softBinFail, func(i, j int) bool {
|
|
// return softBinFail[i].Quantity > softBinFail[j].Quantity
|
|
// })
|
|
// for hardBin, hardBinQuantity := range list.HardBinFailMap {
|
|
// hardBinQuantityDecimal := decimal.NewFromFloat(hardBinQuantity)
|
|
// hardBinFail = append(hardBinFail, &model.ReportBinFail{
|
|
// Bin: hardBin,
|
|
// Quantity: hardBinQuantity,
|
|
// Proportion: hardBinQuantityDecimal.Div(testQuantity).Round(4).Mul(decimal.NewFromInt(100)).String() + "%",
|
|
// })
|
|
// }
|
|
// sort.Slice(hardBinFail, func(i, j int) bool {
|
|
// return hardBinFail[i].Quantity > hardBinFail[j].Quantity
|
|
// })
|
|
// for _, site := range list.Site {
|
|
// var siteSoftBinFail, siteHardBinFail []*model.ReportBinFail
|
|
// for softBin, softBinQuantity := range site.SoftBinFailMap {
|
|
// siteSoftBinFail = append(siteSoftBinFail, &model.ReportBinFail{
|
|
// Bin: softBin,
|
|
// Quantity: softBinQuantity,
|
|
// })
|
|
// }
|
|
// sort.Slice(siteSoftBinFail, func(i, j int) bool {
|
|
// return siteSoftBinFail[i].Quantity > siteSoftBinFail[j].Quantity
|
|
// })
|
|
// for hardBin, hardBinQuantity := range site.HardBinFailMap {
|
|
// siteHardBinFail = append(siteHardBinFail, &model.ReportBinFail{
|
|
// Bin: hardBin,
|
|
// Quantity: hardBinQuantity,
|
|
// })
|
|
// }
|
|
// sort.Slice(siteHardBinFail, func(i, j int) bool {
|
|
// return siteHardBinFail[i].Quantity > siteHardBinFail[j].Quantity
|
|
// })
|
|
// site.SoftBinFail = siteSoftBinFail
|
|
// site.HardBinFail = siteHardBinFail
|
|
// }
|
|
// sort.Slice(list.Site, func(i, j int) bool {
|
|
// iDecimal, _ := decimal.NewFromString(list.Site[i].PassProbability[:len(list.Site[i].PassProbability)-1])
|
|
// jDecimal, _ := decimal.NewFromString(list.Site[j].PassProbability[:len(list.Site[j].PassProbability)-1])
|
|
// return jDecimal.LessThan(iDecimal)
|
|
// })
|
|
// list.SoftBinFail = softBinFail
|
|
// list.HardBinFail = hardBinFail
|
|
// }
|
|
// } else if r.QueryType == "SubBatch" {
|
|
// var reports []*model.Report
|
|
// global.PostGreSQL.Where("step = ?", "FT").Where(sql).
|
|
// Preload("BinFail", func(db *gorm.DB) *gorm.DB {
|
|
// return db.Where("report_site_id = ?", "0")
|
|
// }).Preload("Site", func(db *gorm.DB) *gorm.DB {
|
|
// return db.Preload("BinFail")
|
|
// }).Order("pbi").Find(&reports)
|
|
// for _, report := range reports {
|
|
// softBinFailMap, hardBinFailMap := make(map[string]float64), make(map[string]float64)
|
|
// for _, binFail := range report.BinFail {
|
|
// quantityDecimal, _ := decimal.NewFromString(binFail.Quantity)
|
|
// quantity, _ := quantityDecimal.Float64()
|
|
// softBinFailMap[binFail.SoftBin] += quantity
|
|
// hardBinFailMap[binFail.HardBin] += quantity
|
|
// }
|
|
// var reportListSites []*model.ReportListSites
|
|
// for _, site := range report.Site {
|
|
// siteSoftBinFailMap, siteHardBinFailMap := make(map[string]float64), make(map[string]float64)
|
|
// for _, binFail := range site.BinFail {
|
|
// quantityDecimal, _ := decimal.NewFromString(binFail.Quantity)
|
|
// quantity, _ := quantityDecimal.Float64()
|
|
// siteSoftBinFailMap[binFail.SoftBin] += quantity
|
|
// siteHardBinFailMap[binFail.HardBin] += quantity
|
|
// }
|
|
// var siteSoftBinFail, siteHardBinFail []*model.ReportBinFail
|
|
// for softBin, softBinQuantity := range siteSoftBinFailMap {
|
|
// siteSoftBinFail = append(siteSoftBinFail, &model.ReportBinFail{
|
|
// Bin: softBin,
|
|
// Quantity: softBinQuantity,
|
|
// })
|
|
// }
|
|
// sort.Slice(siteSoftBinFail, func(i, j int) bool {
|
|
// return siteSoftBinFail[i].Quantity > siteSoftBinFail[j].Quantity
|
|
// })
|
|
// for hardBin, hardBinQuantity := range siteHardBinFailMap {
|
|
// siteHardBinFail = append(siteHardBinFail, &model.ReportBinFail{
|
|
// Bin: hardBin,
|
|
// Quantity: hardBinQuantity,
|
|
// })
|
|
// }
|
|
// sort.Slice(siteHardBinFail, func(i, j int) bool {
|
|
// return siteHardBinFail[i].Quantity > siteHardBinFail[j].Quantity
|
|
// })
|
|
// reportListSites = append(reportListSites, &model.ReportListSites{
|
|
// ID: site.ID,
|
|
// ReportID: site.ReportID,
|
|
// Site: site.Site,
|
|
// TestQuantity: site.TestQuantity,
|
|
// PassQuantity: site.PassQuantity,
|
|
// PassProbability: site.PassProbability,
|
|
// SoftBinFailMap: siteSoftBinFailMap,
|
|
// HardBinFailMap: siteHardBinFailMap,
|
|
// SoftBinFail: siteSoftBinFail,
|
|
// HardBinFail: siteHardBinFail,
|
|
// })
|
|
// }
|
|
// sort.Slice(reportListSites, func(i, j int) bool {
|
|
// iDecimal, _ := decimal.NewFromString(reportListSites[i].PassProbability[:len(reportListSites[i].PassProbability)-1])
|
|
// jDecimal, _ := decimal.NewFromString(reportListSites[j].PassProbability[:len(reportListSites[j].PassProbability)-1])
|
|
// return jDecimal.LessThan(iDecimal)
|
|
// })
|
|
// testQuantityDecimal, _ := decimal.NewFromString(report.TestQuantity)
|
|
// var softBinFail, hardBinFail []*model.ReportBinFail
|
|
// for softBin, softBinQuantity := range softBinFailMap {
|
|
// softBinQuantityDecimal := decimal.NewFromFloat(softBinQuantity)
|
|
// softBinFail = append(softBinFail, &model.ReportBinFail{
|
|
// Bin: softBin,
|
|
// Quantity: softBinQuantity,
|
|
// Proportion: softBinQuantityDecimal.Div(testQuantityDecimal).Round(4).Mul(decimal.NewFromInt(100)).String() + "%",
|
|
// })
|
|
// }
|
|
// sort.Slice(softBinFail, func(i, j int) bool {
|
|
// return softBinFail[i].Quantity > softBinFail[j].Quantity
|
|
// })
|
|
// for hardBin, hardBinQuantity := range hardBinFailMap {
|
|
// hardBinQuantityDecimal := decimal.NewFromFloat(hardBinQuantity)
|
|
// hardBinFail = append(hardBinFail, &model.ReportBinFail{
|
|
// Bin: hardBin,
|
|
// Quantity: hardBinQuantity,
|
|
// Proportion: hardBinQuantityDecimal.Div(testQuantityDecimal).Round(4).Mul(decimal.NewFromInt(100)).String() + "%",
|
|
// })
|
|
// }
|
|
// sort.Slice(hardBinFail, func(i, j int) bool {
|
|
// return hardBinFail[i].Quantity > hardBinFail[j].Quantity
|
|
// })
|
|
// reportList = append(reportList, &model.ReportList{
|
|
// Product: report.Product,
|
|
// Lot: report.Lot,
|
|
// SubBatch: report.SubBatch,
|
|
// Factory: report.Factory,
|
|
// TestMachine: report.TestMachine,
|
|
// TestProgram: report.TestProgram,
|
|
// PBI: report.PBI,
|
|
// OrderDate: report.OrderDate,
|
|
// Seal: report.Seal,
|
|
// TestQuantity: report.TestQuantity,
|
|
// FirstPassQuantity: report.FirstPassQuantity,
|
|
// FirstPassProbability: report.FirstPassProbability,
|
|
// PassQuantity: report.PassQuantity,
|
|
// PassProbability: report.PassProbability,
|
|
// TestTime: report.TestTime,
|
|
// Step: report.Step,
|
|
// SoftBinFailMap: softBinFailMap,
|
|
// HardBinFailMap: hardBinFailMap,
|
|
// StackingMaterials: report.StackingMaterials,
|
|
// SoftBinFail: softBinFail,
|
|
// HardBinFail: hardBinFail,
|
|
// Site: reportListSites,
|
|
// })
|
|
// }
|
|
// sort.Slice(reportList, func(i, j int) bool {
|
|
// iDecimal, _ := decimal.NewFromString(reportList[i].PassProbability[:len(reportList[i].PassProbability)-1])
|
|
// jDecimal, _ := decimal.NewFromString(reportList[j].PassProbability[:len(reportList[j].PassProbability)-1])
|
|
// return jDecimal.LessThan(iDecimal)
|
|
// })
|
|
// }
|
|
// return reportList, total
|
|
//}
|