347 lines
15 KiB
Go
347 lines
15 KiB
Go
package test_data
|
|
|
|
import (
|
|
"github.com/shopspring/decimal"
|
|
"github.com/spf13/viper"
|
|
"github.com/xuri/excelize/v2"
|
|
"gorm.io/gorm"
|
|
"path/filepath"
|
|
"strconv"
|
|
"strings"
|
|
"testData/global"
|
|
"testData/model"
|
|
"testData/utils"
|
|
"time"
|
|
)
|
|
|
|
func ExportWaferList() string {
|
|
f := excelize.NewFile()
|
|
sheetName := f.GetSheetName(0)
|
|
_ = f.SetPanes(sheetName, &excelize.Panes{
|
|
Freeze: true,
|
|
YSplit: 1,
|
|
TopLeftCell: "A1",
|
|
ActivePane: "topLeft",
|
|
})
|
|
_ = f.SetSheetRow(sheetName, "A1", &[]interface{}{"状态", "下单日期", "订单号", "晶圆型号", "晶圆厂", "晶圆尺寸", "投片数量",
|
|
"在线数量", "回货数量", "回货日期", "回货批次"})
|
|
var waferLists []*model.WaferList
|
|
global.PostGreSQL.Preload("WaferStock", func(db *gorm.DB) *gorm.DB {
|
|
return db.Order("return_date")
|
|
}).Find(&waferLists)
|
|
for index, waferList := range waferLists {
|
|
var returnDate, returnLot string
|
|
if len(waferList.WaferStock) > 0 {
|
|
returnDate = waferList.WaferStock[0].ReturnDate
|
|
returnLot = waferList.WaferStock[0].Lot
|
|
}
|
|
_ = f.SetSheetRow(sheetName, "A"+strconv.Itoa(index+2), &[]interface{}{waferList.Status, waferList.OrderDate, waferList.PBI,
|
|
waferList.Product, waferList.Factory, waferList.WaferSize, waferList.Quantity,
|
|
waferList.OnlineQuantity, waferList.ReturnQuantity, returnDate, returnLot})
|
|
}
|
|
_ = f.SetColWidth(sheetName, "B", "K", 20)
|
|
filePath := time.Now().Format("Wafer记录2006-01-02_150405.xlsx")
|
|
filePath = filepath.Join(utils.MakeSavePath("记录"), filePath)
|
|
_ = f.SaveAs(filePath)
|
|
f.Close()
|
|
return strings.ReplaceAll(viper.GetString("domain"), "\\", "/") + filePath
|
|
}
|
|
|
|
func ExportABList() string {
|
|
f := excelize.NewFile()
|
|
sheetName := f.GetSheetName(0)
|
|
_ = f.SetPanes(sheetName, &excelize.Panes{
|
|
Freeze: true,
|
|
YSplit: 1,
|
|
TopLeftCell: "A1",
|
|
ActivePane: "topLeft",
|
|
})
|
|
_ = f.SetSheetRow(sheetName, "A1", &[]interface{}{"状态", "下单日期", "订单号", "成品型号", "晶圆型号", "封装", "封装厂", "批号", "片号",
|
|
"订单数量", "在线数量", "良率", "出库数", "入库数", "回货日期", "封装良品", "封装不良品"})
|
|
var abLists []*model.ABList
|
|
global.PostGreSQL.Order("pbi").Preload("ABListStock", func(db *gorm.DB) *gorm.DB {
|
|
return db.Order("return_date")
|
|
}).Find(&abLists)
|
|
for index, abList := range abLists {
|
|
var returnDate string
|
|
if len(abList.ABListStock) > 0 {
|
|
returnDate = abList.ABListStock[0].ReturnDate
|
|
}
|
|
_ = f.SetSheetRow(sheetName, "A"+strconv.Itoa(index+2), &[]interface{}{abList.Status, abList.OrderDate, abList.PBI,
|
|
abList.Product, abList.WaferProduct, abList.Package, abList.Factory, abList.Lot, abList.WaferID, abList.Quantity,
|
|
abList.OnlineQuantity, abList.PassProbability, abList.StockOutQuantity, abList.StockInQuantity,
|
|
returnDate, abList.PassQuantity, abList.FailQuantity})
|
|
}
|
|
_ = f.SetColWidth(sheetName, "B", "Q", 20)
|
|
filePath := time.Now().Format("AB记录2006-01-02_150405.xlsx")
|
|
filePath = filepath.Join(utils.MakeSavePath("记录"), filePath)
|
|
_ = f.SaveAs(filePath)
|
|
f.Close()
|
|
return strings.ReplaceAll(viper.GetString("domain"), "\\", "/") + filePath
|
|
}
|
|
|
|
func ExportBPList() string {
|
|
f := excelize.NewFile()
|
|
sheetName := f.GetSheetName(0)
|
|
_ = f.SetPanes(sheetName, &excelize.Panes{
|
|
Freeze: true,
|
|
YSplit: 1,
|
|
TopLeftCell: "A1",
|
|
ActivePane: "topLeft",
|
|
})
|
|
_ = f.SetSheetRow(sheetName, "A1", &[]interface{}{"状态", "下单日期", "订单号", "晶圆型号", "封装", "CP测试厂", "批号", "片号",
|
|
"订单数量", "在线数量", "回货日期", "到货数量", "DIE数量"})
|
|
var bpLists []*model.BPList
|
|
global.PostGreSQL.Order("pbi").Preload("BPListStock", func(db *gorm.DB) *gorm.DB {
|
|
return db.Order("return_date")
|
|
}).Find(&bpLists)
|
|
for index, bpList := range bpLists {
|
|
var returnDate string
|
|
if len(bpList.BPListStock) > 0 {
|
|
returnDate = bpList.BPListStock[0].ReturnDate
|
|
}
|
|
_ = f.SetSheetRow(sheetName, "A"+strconv.Itoa(index+2), &[]interface{}{bpList.Status, bpList.OrderDate, bpList.PBI,
|
|
bpList.Product, bpList.Package, bpList.Factory, bpList.Lot, bpList.WaferID, bpList.Quantity,
|
|
bpList.OnlineQuantity, returnDate, bpList.ReturnQuantity, bpList.DieQuantity})
|
|
}
|
|
_ = f.SetColWidth(sheetName, "B", "M", 20)
|
|
filePath := time.Now().Format("BP记录2006-01-02_150405.xlsx")
|
|
filePath = filepath.Join(utils.MakeSavePath("记录"), filePath)
|
|
_ = f.SaveAs(filePath)
|
|
f.Close()
|
|
return strings.ReplaceAll(viper.GetString("domain"), "\\", "/") + filePath
|
|
}
|
|
|
|
func ExportCPList() string {
|
|
f := excelize.NewFile()
|
|
sheetName := f.GetSheetName(0)
|
|
_ = f.SetPanes(sheetName, &excelize.Panes{
|
|
Freeze: true,
|
|
YSplit: 1,
|
|
TopLeftCell: "A1",
|
|
ActivePane: "topLeft",
|
|
})
|
|
_ = f.SetSheetRow(sheetName, "A1", &[]interface{}{"状态", "下单日期", "订单号", "晶圆型号", "封装", "CP测试厂", "批号", "片号",
|
|
"订单数量", "在线数量", "测试程序", "回货日期", "到货数量", "DIE数量"})
|
|
var cpLists []*model.CPList
|
|
global.PostGreSQL.Order("pbi").Preload("CPListStock", func(db *gorm.DB) *gorm.DB {
|
|
return db.Order("return_date")
|
|
}).Find(&cpLists)
|
|
for index, cpList := range cpLists {
|
|
var returnDate string
|
|
if len(cpList.CPListStock) > 0 {
|
|
returnDate = cpList.CPListStock[0].ReturnDate
|
|
}
|
|
_ = f.SetSheetRow(sheetName, "A"+strconv.Itoa(index+2), &[]interface{}{cpList.Status, cpList.OrderDate, cpList.PBI,
|
|
cpList.Product, cpList.Package, cpList.Factory, cpList.Lot, cpList.WaferID, cpList.Quantity,
|
|
cpList.OnlineQuantity, cpList.TestProgram, returnDate, cpList.ReturnQuantity, cpList.DieQuantity})
|
|
}
|
|
_ = f.SetColWidth(sheetName, "B", "M", 20)
|
|
filePath := time.Now().Format("CP记录2006-01-02_150405.xlsx")
|
|
filePath = filepath.Join(utils.MakeSavePath("记录"), filePath)
|
|
_ = f.SaveAs(filePath)
|
|
f.Close()
|
|
return strings.ReplaceAll(viper.GetString("domain"), "\\", "/") + filePath
|
|
}
|
|
|
|
//func ExportFTList() string {
|
|
// f := excelize.NewFile()
|
|
// sheetName := f.GetSheetName(0)
|
|
// _ = f.SetSheetRow(sheetName, "A1", &[]interface{}{"状态", "下单日期", "订单号", "成品型号", "晶圆型号", "封装", "FT测试厂", "批号", "丝印",
|
|
// "订单数量", "在线数量", "FT测试程序", "回货日期", "回货数量", "FT良品", "FT不良品"})
|
|
// var ftLists []*model.FTList
|
|
// global.PostGreSQL.Order("pbi").Preload("FTListStock", func(db *gorm.DB) *gorm.DB {
|
|
// return db.Order("return_date")
|
|
// }).Find(&ftLists)
|
|
// for index, ftList := range ftLists {
|
|
// var returnDate string
|
|
// if len(ftList.FTListStock) > 0 {
|
|
// returnDate = ftList.FTListStock[0].ReturnDate
|
|
// }
|
|
// _ = f.SetSheetRow(sheetName, "A"+strconv.Itoa(index+2), &[]interface{}{ftList.Status, ftList.OrderDate, ftList.PBI,
|
|
// ftList.Product, ftList.WaferProduct, ftList.Package, ftList.Factory, ftList.Lot, ftList.Seal, ftList.Quantity,
|
|
// ftList.OnlineQuantity, ftList.TestProgram, returnDate, ftList.ReturnQuantity, ftList.PassQuantity, ftList.FailQuantity})
|
|
// }
|
|
// _ = f.SetColWidth(sheetName, "B", "P", 20)
|
|
// filePath := time.Now().Format("FT记录2006-01-02_150405.xlsx")
|
|
// filePath = filepath.Join(utils.MakeSavePath("记录"), filePath)
|
|
// _ = f.SaveAs(filePath)
|
|
// f.Close()
|
|
// return strings.ReplaceAll(viper.GetString("domain"), "\\", "/") + filePath
|
|
//}
|
|
|
|
func ExportFTList() string {
|
|
f := excelize.NewFile()
|
|
sheetName := f.GetSheetName(0)
|
|
_ = f.SetPanes(sheetName, &excelize.Panes{
|
|
Freeze: true,
|
|
YSplit: 1,
|
|
TopLeftCell: "A1",
|
|
ActivePane: "topLeft",
|
|
})
|
|
_ = f.SetSheetRow(sheetName, "A1", &[]interface{}{"状态", "下单日期", "订单号", "成品型号", "晶圆型号", "封装", "FT测试厂", "批号", "丝印",
|
|
"订单数量", "在线数量", "FT测试程序", "回货日期", "回货数量", "FT良品", "FT不良品", "回收率", "测试数量", "良品数量", "测试良率", "结批测试数量", "结批良品数量", "结批良率"})
|
|
var ftLists []*model.FTList
|
|
global.PostGreSQL.Order("pbi").Preload("FTListStock", func(db *gorm.DB) *gorm.DB {
|
|
return db.Order("return_date")
|
|
}).Find(&ftLists)
|
|
for index, ftList := range ftLists {
|
|
var returnDate string
|
|
if len(ftList.FTListStock) > 0 {
|
|
returnDate = ftList.FTListStock[0].ReturnDate
|
|
}
|
|
var reports []*model.Report
|
|
global.PostGreSQL.Where("pbi = ? AND lot = ? AND step LIKE ?", ftList.PBI, ftList.Lot, "%FT%").
|
|
Order("pbi").
|
|
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")
|
|
}).Find(&reports)
|
|
|
|
var testQuantity, passQuantity, firstPassQuantity float64
|
|
var passProbability, returnProbability string
|
|
for _, report := range reports {
|
|
reportFirstPassQuantity, _ := decimal.NewFromString(report.FirstPassQuantity)
|
|
listFirstPassQuantity := decimal.NewFromFloat(firstPassQuantity)
|
|
reportTestQuantity, _ := decimal.NewFromString(report.TestQuantity)
|
|
reportPassQuantity, _ := decimal.NewFromString(report.PassQuantity)
|
|
listTestQuantity := decimal.NewFromFloat(testQuantity)
|
|
listPassQuantity := decimal.NewFromFloat(passQuantity)
|
|
testQuantity, _ = reportTestQuantity.Add(listTestQuantity).Float64()
|
|
passQuantity, _ = reportPassQuantity.Add(listPassQuantity).Float64()
|
|
if reportTestQuantity.Add(listTestQuantity).IsZero() {
|
|
passProbability = "0%"
|
|
} else {
|
|
passProbability = reportPassQuantity.Add(listPassQuantity).Div(reportTestQuantity.Add(listTestQuantity)).
|
|
Round(4).Mul(decimal.NewFromInt(100)).String() + "%"
|
|
}
|
|
|
|
firstPassQuantity, _ = reportFirstPassQuantity.Add(listFirstPassQuantity).Float64()
|
|
}
|
|
|
|
var finalReports []*model.FinalReport
|
|
global.PostGreSQL.Where("pbi = ? AND product = ? AND lot = ? AND step LIKE ?",
|
|
ftList.PBI, ftList.Product, ftList.Lot, "FT").Find(&finalReports)
|
|
var reportPassProbability string
|
|
var reportTestQuantity, reportPassQuantity float64
|
|
reportHardBinFailMap := make(map[string]float64)
|
|
for _, finalReport := range finalReports {
|
|
reportTestQuantityDecimal := decimal.NewFromFloat(reportTestQuantity)
|
|
reportPassQuantityDecimal := decimal.NewFromFloat(reportPassQuantity)
|
|
finalReportTestQuantityDecimal, _ := decimal.NewFromString(finalReport.ReportTestQuantity)
|
|
finalReportPassQuantityDecimal, _ := decimal.NewFromString(finalReport.ReportPassQuantity)
|
|
reportTestQuantity, _ = reportTestQuantityDecimal.Add(finalReportTestQuantityDecimal).Float64()
|
|
reportPassQuantity, _ = reportPassQuantityDecimal.Add(finalReportPassQuantityDecimal).Float64()
|
|
bin1Decimal, _ := decimal.NewFromString(finalReport.Bin1)
|
|
if !bin1Decimal.IsZero() {
|
|
bin1, _ := bin1Decimal.Float64()
|
|
reportHardBinFailMap["1"] += bin1
|
|
}
|
|
bin2Decimal, _ := decimal.NewFromString(finalReport.Bin2)
|
|
if !bin2Decimal.IsZero() {
|
|
bin2, _ := bin2Decimal.Float64()
|
|
reportHardBinFailMap["2"] += bin2
|
|
}
|
|
bin3Decimal, _ := decimal.NewFromString(finalReport.Bin3)
|
|
if !bin3Decimal.IsZero() {
|
|
bin3, _ := bin3Decimal.Float64()
|
|
reportHardBinFailMap["3"] += bin3
|
|
}
|
|
bin4Decimal, _ := decimal.NewFromString(finalReport.Bin4)
|
|
if !bin4Decimal.IsZero() {
|
|
bin4, _ := bin4Decimal.Float64()
|
|
reportHardBinFailMap["4"] += bin4
|
|
}
|
|
bin5Decimal, _ := decimal.NewFromString(finalReport.Bin5)
|
|
if !bin5Decimal.IsZero() {
|
|
bin5, _ := bin5Decimal.Float64()
|
|
reportHardBinFailMap["5"] += bin5
|
|
}
|
|
bin6Decimal, _ := decimal.NewFromString(finalReport.Bin6)
|
|
if !bin6Decimal.IsZero() {
|
|
bin6, _ := bin6Decimal.Float64()
|
|
reportHardBinFailMap["6"] += bin6
|
|
}
|
|
bin7Decimal, _ := decimal.NewFromString(finalReport.Bin7)
|
|
if !bin7Decimal.IsZero() {
|
|
bin7, _ := bin7Decimal.Float64()
|
|
reportHardBinFailMap["7"] += bin7
|
|
}
|
|
bin8Decimal, _ := decimal.NewFromString(finalReport.Bin8)
|
|
if !bin8Decimal.IsZero() {
|
|
bin8, _ := bin8Decimal.Float64()
|
|
reportHardBinFailMap["8"] += bin8
|
|
}
|
|
bin9Decimal, _ := decimal.NewFromString(finalReport.Bin9)
|
|
if !bin9Decimal.IsZero() {
|
|
bin9, _ := bin9Decimal.Float64()
|
|
reportHardBinFailMap["9"] += bin9
|
|
}
|
|
bin10Decimal, _ := decimal.NewFromString(finalReport.Bin10)
|
|
if !bin10Decimal.IsZero() {
|
|
bin10, _ := bin10Decimal.Float64()
|
|
reportHardBinFailMap["10"] += bin10
|
|
}
|
|
}
|
|
finalReportTestQuantityDecimal := decimal.NewFromFloat(reportTestQuantity)
|
|
finalReportPassQuantityDecimal := decimal.NewFromFloat(reportPassQuantity)
|
|
if !finalReportTestQuantityDecimal.IsZero() {
|
|
reportPassProbability = finalReportPassQuantityDecimal.Div(finalReportTestQuantityDecimal).Round(4).
|
|
Mul(decimal.NewFromInt(100)).String() + "%"
|
|
}
|
|
|
|
testQuantityDecimal := decimal.NewFromFloat(testQuantity)
|
|
firstPassQuantityDecimal := decimal.NewFromFloat(firstPassQuantity)
|
|
passQuantityDecimal := decimal.NewFromFloat(passQuantity)
|
|
if !testQuantityDecimal.IsZero() {
|
|
probability := passQuantityDecimal.Sub(firstPassQuantityDecimal).Div(testQuantityDecimal).Round(4).
|
|
Mul(decimal.NewFromInt(100))
|
|
returnProbability = probability.String() + "%"
|
|
}
|
|
|
|
_ = f.SetSheetRow(sheetName, "A"+strconv.Itoa(index+2), &[]interface{}{ftList.Status, ftList.OrderDate, ftList.PBI,
|
|
ftList.Product, ftList.WaferProduct, ftList.Package, ftList.Factory, ftList.Lot, ftList.Seal, ftList.Quantity,
|
|
ftList.OnlineQuantity, ftList.TestProgram, returnDate, ftList.ReturnQuantity, ftList.PassQuantity, ftList.FailQuantity,
|
|
returnProbability, testQuantity, passQuantity, passProbability, reportTestQuantity, reportPassQuantity, reportPassProbability})
|
|
}
|
|
_ = f.SetColWidth(sheetName, "B", "P", 20)
|
|
filePath := time.Now().Format("FT记录2006-01-02_150405.xlsx")
|
|
filePath = filepath.Join(utils.MakeSavePath("记录"), filePath)
|
|
_ = f.SaveAs(filePath)
|
|
f.Close()
|
|
return strings.ReplaceAll(viper.GetString("domain"), "\\", "/") + filePath
|
|
}
|
|
|
|
func ExportTRList() string {
|
|
f := excelize.NewFile()
|
|
sheetName := f.GetSheetName(0)
|
|
_ = f.SetPanes(sheetName, &excelize.Panes{
|
|
Freeze: true,
|
|
YSplit: 1,
|
|
TopLeftCell: "A1",
|
|
ActivePane: "topLeft",
|
|
})
|
|
_ = f.SetSheetRow(sheetName, "A1", &[]interface{}{"状态", "下单日期", "订单号", "成品型号", "晶圆型号", "封装", "封装厂", "批号",
|
|
"订单数量", "在线数量", "回货日期", "封装良品", "封装不良品"})
|
|
var trLists []*model.TRList
|
|
global.PostGreSQL.Order("pbi").Preload("TRListStock", func(db *gorm.DB) *gorm.DB {
|
|
return db.Order("return_date")
|
|
}).Find(&trLists)
|
|
for index, abList := range trLists {
|
|
var returnDate string
|
|
if len(abList.TRListStock) > 0 {
|
|
returnDate = abList.TRListStock[0].ReturnDate
|
|
}
|
|
_ = f.SetSheetRow(sheetName, "A"+strconv.Itoa(index+2), &[]interface{}{abList.Status, abList.OrderDate, abList.PBI,
|
|
abList.Product, abList.WaferProduct, abList.Package, abList.Factory, abList.Lot, abList.Quantity,
|
|
abList.OnlineQuantity, returnDate, abList.PassQuantity, abList.FailQuantity})
|
|
}
|
|
_ = f.SetColWidth(sheetName, "B", "M", 20)
|
|
filePath := time.Now().Format("TR记录2006-01-02_150405.xlsx")
|
|
filePath = filepath.Join(utils.MakeSavePath("记录"), filePath)
|
|
_ = f.SaveAs(filePath)
|
|
f.Close()
|
|
return strings.ReplaceAll(viper.GetString("domain"), "\\", "/") + filePath
|
|
}
|