test_data/repository/test.data/report.list.go

1508 lines
54 KiB
Go

package test_data
import (
"github.com/shopspring/decimal"
"gorm.io/gorm"
"sort"
"testData/global"
"testData/model"
"testData/request"
)
func WaferList(r *request.WaferList) ([]*model.WaferList, int64) {
if r.Page > 0 {
r.Page--
}
var sql string
if r.Status != "" {
sql += "status = `" + r.Status + "`"
}
if r.OrderDate != "" {
if sql == "" {
sql += "order_date LIKE '%" + r.OrderDate + "%'"
} else {
sql += " AND order_date LIKE '%" + r.OrderDate + "%'"
}
}
if r.Product != "" {
if sql == "" {
sql += "product LIKE '%" + r.Product + "%'"
} else {
sql += " AND product LIKE '%" + r.Product + "%'"
}
}
if r.PBI != "" {
if sql == "" {
sql += "pbi LIKE '%" + r.PBI + "%'"
} else {
sql += " AND pbi LIKE '%" + r.PBI + "%'"
}
}
if r.Factory != "" {
if sql == "" {
sql += "factory LIKE '%" + r.Factory + "%'"
} else {
sql += " AND factory LIKE '%" + r.Factory + "%'"
}
}
if r.WaferSize != "" {
if sql == "" {
sql += "wafer_size LIKE '%" + r.WaferSize + "%'"
} else {
sql += " AND wafer_size LIKE '%" + r.WaferSize + "%'"
}
}
if r.Quantity != "" {
if sql == "" {
sql += "quantity = '" + r.Quantity + "'"
} else {
sql += " AND quantity = '" + r.Quantity + "'"
}
}
if r.OnlineQuantity != "" {
if sql == "" {
sql += "online_quantity = '" + r.OnlineQuantity + "'"
} else {
sql += " AND online_quantity = '" + r.OnlineQuantity + "'"
}
}
if r.ReturnQuantity != "" {
if sql == "" {
sql += "return_quantity = '" + r.ReturnQuantity + "'"
} else {
sql += " AND return_quantity = '" + r.ReturnQuantity + "'"
}
}
var waferList []*model.WaferList
var total int64
global.PostGreSQL.Where(sql).Order("order_date desc").Find(&waferList).Count(&total).
Offset(r.Page*r.PageSize).Limit(r.PageSize).Preload("WaferStock", func(db *gorm.DB) *gorm.DB {
return db.Order("return_date")
}).Find(&waferList)
return waferList, total
}
func ABList(r *request.ABList) ([]*model.ABList, int64) {
var sql string
if r.Status != "" {
sql += "status = '" + r.Status + "'"
}
if r.OrderDate != "" {
if sql != "" {
sql += " AND order_date LIKE '%" + r.OrderDate + "%'"
} else {
sql += "order_date LIKE '%" + r.OrderDate + "%'"
}
}
if r.PBI != "" {
if sql != "" {
sql += " AND pbi LIKE '%" + r.PBI + "%'"
} else {
sql += "pbi LIKE '%" + r.PBI + "%'"
}
}
if r.Product != "" {
if sql != "" {
sql += " AND product LIKE '%" + r.Product + "%'"
} else {
sql += "product LIKE '%" + r.Product + "%'"
}
}
if r.WaferProduct != "" {
if sql != "" {
sql += " AND wafer_product LIKE '%" + r.WaferProduct + "%'"
} else {
sql += "wafer_product LIKE '%" + r.WaferProduct + "%'"
}
}
if r.Package != "" {
if sql != "" {
sql += " AND package LIKE '%" + r.Package + "%'"
} else {
sql += "package LIKE '%" + r.Package + "%'"
}
}
if r.Factory != "" {
if sql != "" {
sql += " AND factory LIKE '%" + r.Factory + "%'"
} else {
sql += "factory LIKE '%" + r.Factory + "%'"
}
}
if r.Lot != "" {
if sql != "" {
sql += " AND lot LIKE '%" + r.Lot + "%'"
} else {
sql += "lot LIKE '%" + r.Lot + "%'"
}
}
if r.Seal != "" {
if sql != "" {
sql += " AND seal LIKE '%" + r.Seal + "%'"
} else {
sql += "seal LIKE '%" + r.Seal + "%'"
}
}
if r.WaferID != "" {
if sql != "" {
sql += " AND wafer_id LIKE '%" + r.WaferID + "%'"
} else {
sql += "wafer_id LIKE '%" + r.WaferID + "%'"
}
}
if r.Quantity != "" {
if sql != "" {
sql += " AND quantity = '" + r.Quantity + "'"
} else {
sql += "quantity = '" + r.Quantity + "'"
}
}
if r.OnlineQuantity != "" {
if sql != "" {
sql += " AND online_quantity = '" + r.OnlineQuantity + "'"
} else {
sql += "online_quantity = '" + r.OnlineQuantity + "'"
}
}
if r.PassProbability != "" {
if sql != "" {
sql += " AND pass_probability = '" + r.PassProbability + "'"
} else {
sql += "pass_probability = '" + r.PassProbability + "'"
}
}
if r.StockOutQuantity != "" {
if sql != "" {
sql += " AND stock_out_quantity = '" + r.StockOutQuantity + "'"
} else {
sql += "stock_out_quantity = '" + r.StockOutQuantity + "'"
}
}
if r.StockInQuantity != "" {
if sql != "" {
sql += " AND stock_in_quantity = '" + r.StockInQuantity + "'"
} else {
sql += "stock_in_quantity = '" + r.StockInQuantity + "'"
}
}
if r.PassQuantity != "" {
if sql != "" {
sql += " AND pass_quantity = '" + r.PassQuantity + "'"
} else {
sql += "pass_quantity = '" + r.PassQuantity + "'"
}
}
if r.FailQuantity != "" {
if sql != "" {
sql += " AND fail_quantity = '" + r.FailQuantity + "'"
} else {
sql += "fail_quantity = '" + r.FailQuantity + "'"
}
}
var abList []*model.ABList
var total int64
if r.Page > 0 {
r.Page--
}
global.PostGreSQL.Where(sql).Order("order_date desc").Find(&abList).Count(&total).Offset(r.Page * r.PageSize).Limit(r.PageSize).
Preload("ABListStock").Find(&abList)
return abList, total
}
func BPList(r *request.BPList) ([]*model.BPList, int64) {
var sql string
if r.Status != "" {
sql += "status = '" + r.Status + "'"
}
if r.OrderDate != "" {
if sql != "" {
sql += " AND order_date LIKE '%" + r.OrderDate + "%'"
} else {
sql += "order_date LIE '%" + r.OrderDate + "%'"
}
}
if r.PBI != "" {
if sql != "" {
sql += " AND pbi LIKE '%" + r.PBI + "%'"
} else {
sql += "pbi LIKE '%" + r.PBI + "%'"
}
}
if r.Product != "" {
if sql != "" {
sql += " AND product LIKE '%" + r.Product + "%'"
} else {
sql += "product LIKE '%" + r.Product + "%'"
}
}
if r.Package != "" {
if sql != "" {
sql += " AND package LIKE '%" + r.Package + "%'"
} else {
sql += "package LIKE '%" + r.Package + "%'"
}
}
if r.Factory != "" {
if sql != "" {
sql += " AND factory LIKE '%" + r.Factory + "%'"
} else {
sql += "factory LIKE '%" + r.Factory + "%'"
}
}
if r.Lot != "" {
if sql != "" {
sql += " AND lot LIKE '%" + r.Lot + "%'"
} else {
sql += "lot LIKE '%" + r.Lot + "%'"
}
}
if r.WaferID != "" {
if sql != "" {
sql += " AND wafer_id LIKE '%" + r.WaferID + "%'"
} else {
sql += "wafer_id LIKE '%" + r.WaferID + "%'"
}
}
if r.Quantity != "" {
if sql != "" {
sql += " AND quantity = '" + r.Quantity + "'"
} else {
sql += "quantity = '" + r.Quantity + "'"
}
}
if r.OnlineQuantity != "" {
if sql != "" {
sql += " AND online_quantity = '" + r.OnlineQuantity + "'"
} else {
sql += "online_quantity = '" + r.OnlineQuantity + "'"
}
}
if r.ReturnQuantity != "" {
if sql != "" {
sql += " AND return_quantity = '" + r.ReturnQuantity + "'"
} else {
sql += "return_quantity = '" + r.ReturnQuantity + "'"
}
}
if r.DieQuantity != "" {
if sql != "" {
sql += " AND die_quantity = '" + r.DieQuantity + "'"
} else {
sql += "die_quantity = '" + r.DieQuantity + "'"
}
}
var bpList []*model.BPList
var total int64
if r.Page > 0 {
r.Page--
}
global.PostGreSQL.Where(sql).Order("order_date desc").Find(&bpList).Count(&total).
Offset(r.Page * r.PageSize).Limit(r.PageSize).
Preload("BPListStock").Find(&bpList)
return bpList, total
}
func CPList(r *request.CPList) ([]*model.CPShowList, int64) {
var sql string
if r.Status != "" {
sql += "status = '" + r.Status + "'"
}
if r.OrderDate != "" {
if sql == "" {
sql += "order_date LIKE '%" + r.OrderDate + "%'"
} else {
sql += " AND order_date LIKE '%" + r.OrderDate + "%'"
}
}
if r.PBI != "" {
if sql == "" {
sql += "pbi LIKE '%" + r.PBI + "%'"
} else {
sql += " AND pbi LIKE '%" + r.PBI + "%'"
}
}
if r.Product != "" {
if sql == "" {
sql += "product LIKE '%" + r.Product + "%'"
} else {
sql += " AND product LIKE '%" + r.Product + "%'"
}
}
if r.Package != "" {
if sql == "" {
sql += "package LIKE '%" + r.Package + "%'"
} else {
sql += " AND package LIKE '%" + r.Package + "%'"
}
}
if r.Factory != "" {
if sql == "" {
sql += "factory LIKE '%" + r.Factory + "%'"
} else {
sql += " AND factory LIKE '%" + r.Factory + "%'"
}
}
if r.Lot != "" {
if sql == "" {
sql += "lot LIKE '%" + r.Lot + "%'"
} else {
sql += " AND lot LIKE '%" + r.Lot + "%'"
}
}
if r.WaferID != "" {
if sql == "" {
sql += "wafer_id LIKE '%" + r.WaferID + "%'"
} else {
sql += " AND wafer_id LIKE '%" + r.WaferID + "%'"
}
}
if r.TestProgram != "" {
if sql == "" {
sql += "test_program LIKE '%" + r.TestProgram + "%'"
} else {
sql += " AND test_program LIKE '%" + r.TestProgram + "%'"
}
}
if r.TestProgramVersion != "" {
if sql == "" {
sql += "test_program_version LIKE '%" + r.TestProgramVersion + "%'"
} else {
sql += " AND test_program_version LIKE '%" + r.TestProgramVersion + "%'"
}
}
if r.Quantity != "" {
if sql == "" {
sql += "quantity = '" + r.Quantity + "'"
} else {
sql += " AND quantity = '" + r.Quantity + "'"
}
}
if r.ReturnQuantity != "" {
if sql == "" {
sql += "return_quantity = '" + r.ReturnQuantity + "'"
} else {
sql += " AND return_quantity = '" + r.ReturnQuantity + "'"
}
}
if r.DieQuantity != "" {
if sql == "" {
sql += "die_quantity = '" + r.DieQuantity + "'"
} else {
sql += " AND die_quantity = '" + r.DieQuantity + "'"
}
}
if r.Page > 0 {
r.Page--
}
var cpLists []*model.CPList
var total int64
global.PostGreSQL.Where(sql).Order("order_date desc").Find(&cpLists).Count(&total).
Offset(r.Page * r.PageSize).Limit(r.PageSize).
Preload("CPListStock").Find(&cpLists)
var cpShowLists []*model.CPShowList
for _, cpList := range cpLists {
cpShowList := model.CPShowList{
Status: cpList.Status,
OrderDate: cpList.OrderDate,
PBI: cpList.PBI,
OutsourcingPBI: cpList.OutsourcingPBI,
Product: cpList.Product,
Package: cpList.Package,
Lot: cpList.Lot,
Factory: cpList.Factory,
WaferID: cpList.WaferID,
TestProgram: cpList.TestProgram,
TestProgramVersion: cpList.TestProgramVersion,
Quantity: cpList.Quantity,
OnlineQuantity: cpList.OnlineQuantity,
ReturnQuantity: cpList.ReturnQuantity,
DieQuantity: cpList.DieQuantity,
CPListStock: cpList.CPListStock,
SoftBinFailMap: make(map[string]float64),
HardBinFailMap: make(map[string]float64),
}
var reports []*model.Report
global.PostGreSQL.Where("pbi = ? AND product = ? AND lot = ? AND step LIKE ?", cpList.PBI, cpList.Product, cpList.Lot, "%CP%").
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)
for _, report := range reports {
//var finalReports []*model.FinalReport
//global.PostGreSQL.Where("pbi = ? AND product = ? AND lot = ? AND step LIKE ?",
// report.PBI, report.Product, report.Lot, "CP").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() + "%"
//}
firstPassQuantity, _ := decimal.NewFromString(report.FirstPassQuantity)
listFirstPassQuantity, _ := decimal.NewFromString(cpShowList.PassQuantity)
testQuantity, _ := decimal.NewFromString(report.TestQuantity)
passQuantity, _ := decimal.NewFromString(report.PassQuantity)
listTestQuantity, _ := decimal.NewFromString(cpShowList.TestQuantity)
listPassQuantity, _ := decimal.NewFromString(cpShowList.PassQuantity)
cpShowList.TestQuantity = testQuantity.Add(listTestQuantity).String()
cpShowList.PassQuantity = passQuantity.Add(listPassQuantity).String()
cpShowList.PassProbability = passQuantity.Add(listPassQuantity).Div(testQuantity.Add(listTestQuantity)).
Round(4).Mul(decimal.NewFromInt(100)).String() + "%"
cpShowList.FirstPassQuantity = firstPassQuantity.Add(listFirstPassQuantity).String()
cpShowList.FirstPassProbability = firstPassQuantity.Add(listFirstPassQuantity).Div(testQuantity.Add(listTestQuantity)).
Round(4).Mul(decimal.NewFromInt(100)).String() + "%"
softBinFailMap, hardBinFailMap := make(map[string]float64), make(map[string]float64)
for _, binFail := range report.BinFail {
quantityDecimal, _ := decimal.NewFromString(binFail.Quantity)
quantity, _ := quantityDecimal.Float64()
cpShowList.SoftBinFailMap[binFail.SoftBin] += quantity
cpShowList.HardBinFailMap[binFail.HardBin] += quantity
softBinFailMap[binFail.SoftBin] += quantity
hardBinFailMap[binFail.HardBin] += quantity
}
for _, site := range report.Site {
for _, reportSite := range cpShowList.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
}
}
}
}
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,
})
}
cpShowList = model.CPShowList{
Status: cpShowList.Status,
OrderDate: cpShowList.OrderDate,
PBI: cpShowList.PBI,
OutsourcingPBI: cpShowList.OutsourcingPBI,
Product: cpShowList.Product,
Package: cpShowList.Package,
Lot: cpShowList.Lot,
Factory: cpShowList.Factory,
WaferID: cpShowList.WaferID,
TestMachine: report.TestMachine,
TestProgram: cpShowList.TestProgram,
TestProgramVersion: cpShowList.TestProgramVersion,
Quantity: cpShowList.Quantity,
OnlineQuantity: cpShowList.OnlineQuantity,
ReturnQuantity: cpShowList.ReturnQuantity,
DieQuantity: cpShowList.DieQuantity,
CPListStock: cpShowList.CPListStock,
TestQuantity: report.TestQuantity,
FirstPassQuantity: report.FirstPassQuantity,
FirstPassProbability: report.FirstPassProbability,
PassQuantity: report.PassQuantity,
PassProbability: report.PassProbability,
//ReportTestQuantity: reportTestQuantity,
//ReportPassQuantity: reportPassQuantity,
//ReportPassProbability: reportPassProbability,
TestTime: report.TestTime,
StackingMaterials: report.StackingMaterials,
SoftBinFailMap: softBinFail,
HardBinFailMap: hardBinFail,
Site: reportListSites,
}
}
var finalReports []*model.FinalReport
global.PostGreSQL.Where("pbi = ? AND product = ? AND lot = ? AND step LIKE ?",
cpList.PBI, cpList.Product, cpList.Lot, "%CP%").Find(&finalReports)
var reportTestQuantity, reportPassQuantity, reportPassProbability string
reportHardBinFailMap := make(map[string]float64)
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()
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.NewFromString(reportTestQuantity)
finalReportPassQuantityDecimal, _ := decimal.NewFromString(reportPassQuantity)
if !finalReportTestQuantityDecimal.IsZero() {
reportPassProbability = finalReportPassQuantityDecimal.Div(finalReportTestQuantityDecimal).Round(4).
Mul(decimal.NewFromInt(100)).String() + "%"
}
cpShowList.ReportTestQuantity = reportTestQuantity
cpShowList.ReportPassQuantity = reportPassQuantity
cpShowList.ReportPassProbability = reportPassProbability
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,
})
}
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 {
var finalReport *model.FinalReport
global.PostGreSQL.Where("step = ? AND pbi = ? AND lot = ? AND sub_batch = ?", report.Step, report.PBI, report.Lot,
report.SubBatch).Find(&finalReport)
hardBinQuantityDecimal := decimal.NewFromFloat(hardBinQuantity)
var quantity float64
var reportProportion string
reportSoftBinQuantityDecimal := decimal.NewFromFloat(hardBinQuantity)
quantity = hardBinQuantity
reportProportion = reportSoftBinQuantityDecimal.Div(testQuantityDecimal).Round(4).
Mul(decimal.NewFromInt(100)).String() + "%"
hardBinFail = append(hardBinFail, &model.ReportBinFail{
Bin: hardBin,
Quantity: hardBinQuantity,
Proportion: hardBinQuantityDecimal.Div(testQuantityDecimal).Round(4).
Mul(decimal.NewFromInt(100)).String() + "%",
ReportQuantity: quantity,
ReportProportion: reportProportion,
})
}
sort.Slice(hardBinFail, func(i, j int) bool {
return hardBinFail[i].Quantity > hardBinFail[j].Quantity
})
cpShowList.WaferDetails = append(cpShowList.WaferDetails, model.ReportList{
OrderDate: cpShowList.OrderDate,
PBI: cpShowList.PBI,
Product: cpShowList.Product,
Lot: cpShowList.Lot,
SubBatch: report.SubBatch,
WaferID: report.WaferID,
Factory: cpShowList.Factory,
TestMachine: report.TestMachine,
TestProgram: cpShowList.TestProgram,
Seal: report.Seal,
TestQuantity: report.TestQuantity,
FirstPassQuantity: report.FirstPassQuantity,
FirstPassProbability: report.FirstPassProbability,
PassQuantity: report.PassQuantity,
PassProbability: report.PassProbability,
TestTime: report.TestTime,
Step: report.Step,
StackingMaterials: report.StackingMaterials,
SoftBinFailMap: softBinFailMap,
HardBinFailMap: hardBinFailMap,
SoftBinFail: softBinFail,
HardBinFail: hardBinFail,
Site: reportListSites,
})
}
sort.Slice(cpShowList.WaferDetails, func(i, j int) bool {
iDecimal, _ := decimal.NewFromString(cpShowList.WaferDetails[i].PassProbability[:len(cpShowList.WaferDetails[i].PassProbability)-1])
jDecimal, _ := decimal.NewFromString(cpShowList.WaferDetails[j].PassProbability[:len(cpShowList.WaferDetails[j].PassProbability)-1])
return jDecimal.LessThan(iDecimal)
})
var testQuantityDiffLabel, passQuantityDiffLabel, returnProbabilityLabel bool
testQuantityDecimal, _ := decimal.NewFromString(cpShowList.TestQuantity)
reportTestQuantityDecimal, _ := decimal.NewFromString(cpShowList.ReportTestQuantity)
firstPassQuantityDecimal, _ := decimal.NewFromString(cpShowList.FirstPassQuantity)
passQuantityDecimal, _ := decimal.NewFromString(cpShowList.PassQuantity)
reportPassQuantityDecimal, _ := decimal.NewFromString(cpShowList.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
}
cpShowList.TestQuantityDiff = diff.String() + "%"
cpShowList.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
}
cpShowList.ReturnProbability = probability.String() + "%"
cpShowList.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
}
cpShowList.PassQuantityDiff = diff.String() + "%"
cpShowList.PassQuantityDiffLabel = passQuantityDiffLabel
}
var softBinFail, hardBinFail []*model.ReportBinFail
for softBin, softBinQuantity := range cpShowList.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 cpShowList.HardBinFailMap {
hardBinQuantityDecimal := decimal.NewFromFloat(hardBinQuantity)
reportSoftBinQuantityDecimal := decimal.NewFromFloat(reportHardBinFailMap[hardBin])
hardBinFail = append(hardBinFail, &model.ReportBinFail{
Bin: hardBin,
Quantity: hardBinQuantity,
Proportion: hardBinQuantityDecimal.Div(testQuantityDecimal).Round(4).
Mul(decimal.NewFromInt(100)).String() + "%",
ReportQuantity: reportHardBinFailMap[hardBin],
ReportProportion: reportSoftBinQuantityDecimal.Div(testQuantityDecimal).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 cpShowList.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(cpShowList.Site, func(i, j int) bool {
iDecimal, _ := decimal.NewFromString(cpShowList.Site[i].PassProbability[:len(cpShowList.Site[i].PassProbability)-1])
jDecimal, _ := decimal.NewFromString(cpShowList.Site[j].PassProbability[:len(cpShowList.Site[j].PassProbability)-1])
return jDecimal.LessThan(iDecimal)
})
cpShowList.SoftBinFail = softBinFail
cpShowList.HardBinFail = hardBinFail
cpShowLists = append(cpShowLists, &cpShowList)
}
return cpShowLists, total
}
func FTList(r *request.FTList) ([]*model.FTShowList, int64) {
var sql string
if r.Status != "" {
sql += "status = '" + r.Status + "'"
}
if r.OrderDate != "" {
if sql == "" {
sql += "order_date LIKE '%" + r.OrderDate + "%'"
} else {
sql += " AND order_date LIKE '%" + r.OrderDate + "%'"
}
}
if r.PBI != "" {
if sql == "" {
sql += "pbi LIKE '%" + r.PBI + "%'"
} else {
sql += " AND pbi LIKE '%" + r.PBI + "%'"
}
}
if r.Product != "" {
if sql == "" {
sql += "product LIKE '%" + r.Product + "%'"
} else {
sql += " AND product LIKE '%" + r.Product + "%'"
}
}
if r.Package != "" {
if sql == "" {
sql += "package LIKE '%" + r.Package + "%'"
} else {
sql += " AND package LIKE '%" + r.Package + "%'"
}
}
if r.Factory != "" {
if sql == "" {
sql += "factory LIKE '%" + r.Factory + "%'"
} else {
sql += " AND factory LIKE '%" + r.Factory + "%'"
}
}
if r.Lot != "" {
if sql == "" {
sql += "lot LIKE '%" + r.Lot + "%'"
} else {
sql += " AND lot LIKE '%" + r.Lot + "%'"
}
}
if r.Seal != "" {
if sql == "" {
sql += "seal LIKE '%" + r.Seal + "%'"
} else {
sql += " AND seal LIKE '%" + r.Seal + "%'"
}
}
if r.TestProgram != "" {
if sql == "" {
sql += "test_program LIKE '%" + r.TestProgram + "%'"
} else {
sql += " AND test_program LIKE '%" + r.TestProgram + "%'"
}
}
if r.TestProgramVersion != "" {
if sql == "" {
sql += "test_program_version LIKE '%" + r.TestProgramVersion + "%'"
} else {
sql += " AND test_program_version LIKE '%" + r.TestProgramVersion + "%'"
}
}
if r.Quantity != "" {
if sql == "" {
sql += "quantity = '" + r.Quantity + "'"
} else {
sql += " AND quantity = '" + r.Quantity + "'"
}
}
if r.ReturnQuantity != "" {
if sql == "" {
sql += "return_quantity = '" + r.ReturnQuantity + "'"
} else {
sql += " AND return_quantity = '" + r.ReturnQuantity + "'"
}
}
if r.FTPassQuantity != "" {
if sql == "" {
sql += "pass_quantity = '" + r.FTPassQuantity + "'"
} else {
sql += " AND pass_quantity = '" + r.FTPassQuantity + "'"
}
}
if r.FTPassQuantity != "" {
if sql == "" {
sql += "fail_quantity = '" + r.FTPassQuantity + "'"
} else {
sql += " AND fail_quantity = '" + r.FTPassQuantity + "'"
}
}
if r.Page > 0 {
r.Page--
}
var ftLists []*model.FTList
var total int64
global.PostGreSQL.Where(sql).Order("order_date desc").Find(&ftLists).Count(&total).
Offset(r.Page * r.PageSize).Limit(r.PageSize).
Preload("FTListStock").Find(&ftLists)
var ftShowLists []*model.FTShowList
for _, ftList := range ftLists {
ftShowList := model.FTShowList{
Status: ftList.Status,
OrderDate: ftList.OrderDate,
PBI: ftList.PBI,
OutsourcingPBI: ftList.OutsourcingPBI,
Product: ftList.Product,
WaferProduct: ftList.WaferProduct,
Package: ftList.Package,
Lot: ftList.Lot,
Factory: ftList.Factory,
Seal: ftList.Seal,
TestProgram: ftList.TestProgram,
TestProgramVersion: ftList.TestProgramVersion,
Quantity: ftList.Quantity,
OnlineQuantity: ftList.OnlineQuantity,
ReturnQuantity: ftList.ReturnQuantity,
FTPassQuantity: ftList.PassQuantity,
FTFailQuantity: ftList.FailQuantity,
FTListStock: ftList.FTListStock,
SoftBinFailMap: make(map[string]float64),
HardBinFailMap: make(map[string]float64),
}
var reports []*model.Report
global.PostGreSQL.Where("pbi = ? AND product = ? AND lot = ? AND step LIKE ?", ftList.PBI, ftList.Product, 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)
for _, report := range reports {
//var finalReports []*model.FinalReport
//global.PostGreSQL.Where("pbi = ? AND product = ? AND lot = ? AND step LIKE ?",
// 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() + "%"
//}
firstPassQuantity, _ := decimal.NewFromString(report.FirstPassQuantity)
listFirstPassQuantity, _ := decimal.NewFromString(ftShowList.PassQuantity)
testQuantity, _ := decimal.NewFromString(report.TestQuantity)
passQuantity, _ := decimal.NewFromString(report.PassQuantity)
listTestQuantity, _ := decimal.NewFromString(ftShowList.TestQuantity)
listPassQuantity, _ := decimal.NewFromString(ftShowList.PassQuantity)
ftShowList.TestQuantity = testQuantity.Add(listTestQuantity).String()
ftShowList.PassQuantity = passQuantity.Add(listPassQuantity).String()
ftShowList.PassProbability = passQuantity.Add(listPassQuantity).Div(testQuantity.Add(listTestQuantity)).
Round(4).Mul(decimal.NewFromInt(100)).String() + "%"
ftShowList.FirstPassQuantity = firstPassQuantity.Add(listFirstPassQuantity).String()
ftShowList.FirstPassProbability = firstPassQuantity.Add(listFirstPassQuantity).Div(testQuantity.Add(listTestQuantity)).
Round(4).Mul(decimal.NewFromInt(100)).String() + "%"
softBinFailMap, hardBinFailMap := make(map[string]float64), make(map[string]float64)
for _, binFail := range report.BinFail {
quantityDecimal, _ := decimal.NewFromString(binFail.Quantity)
quantity, _ := quantityDecimal.Float64()
ftShowList.SoftBinFailMap[binFail.SoftBin] += quantity
ftShowList.HardBinFailMap[binFail.HardBin] += quantity
softBinFailMap[binFail.SoftBin] += quantity
hardBinFailMap[binFail.HardBin] += quantity
}
for _, site := range report.Site {
for _, reportSite := range ftShowList.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
}
}
}
}
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,
})
}
ftShowList = model.FTShowList{
Status: ftShowList.Status,
OrderDate: ftShowList.OrderDate,
PBI: ftShowList.PBI,
OutsourcingPBI: ftShowList.OutsourcingPBI,
Product: ftShowList.Product,
Package: ftShowList.Package,
Factory: ftShowList.Factory,
Lot: ftShowList.Lot,
Seal: ftShowList.Seal,
TestProgram: ftShowList.TestProgram,
TestProgramVersion: ftShowList.TestProgramVersion,
Quantity: ftShowList.Quantity,
OnlineQuantity: ftShowList.OnlineQuantity,
ReturnQuantity: ftShowList.ReturnQuantity,
FTPassQuantity: ftShowList.FTPassQuantity,
FTFailQuantity: ftShowList.FTFailQuantity,
FTListStock: ftShowList.FTListStock,
TestMachine: report.TestMachine,
TestQuantity: report.TestQuantity,
FirstPassQuantity: report.FirstPassQuantity,
FirstPassProbability: report.FirstPassProbability,
PassQuantity: report.PassQuantity,
PassProbability: report.PassProbability,
//ReportTestQuantity: reportTestQuantity,
//ReportPassQuantity: reportPassQuantity,
//ReportPassProbability: reportPassProbability,
TestTime: report.TestTime,
StackingMaterials: report.StackingMaterials,
SoftBinFailMap: softBinFail,
HardBinFailMap: hardBinFail,
Site: reportListSites,
}
}
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 reportTestQuantity, reportPassQuantity, reportPassProbability string
reportHardBinFailMap := make(map[string]float64)
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()
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.NewFromString(reportTestQuantity)
finalReportPassQuantityDecimal, _ := decimal.NewFromString(reportPassQuantity)
if !finalReportTestQuantityDecimal.IsZero() {
reportPassProbability = finalReportPassQuantityDecimal.Div(finalReportTestQuantityDecimal).Round(4).
Mul(decimal.NewFromInt(100)).String() + "%"
}
ftShowList.ReportTestQuantity = reportTestQuantity
ftShowList.ReportPassQuantity = reportPassQuantity
ftShowList.ReportPassProbability = reportPassProbability
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,
})
}
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 {
var finalReport *model.FinalReport
global.PostGreSQL.Where("step = ? AND pbi = ? AND lot = ? AND sub_batch = ?", report.Step, report.PBI, report.Lot,
report.SubBatch).Find(&finalReport)
hardBinQuantityDecimal := decimal.NewFromFloat(hardBinQuantity)
var quantity float64
var reportProportion string
reportSoftBinQuantityDecimal := decimal.NewFromFloat(hardBinQuantity)
quantity = hardBinQuantity
reportProportion = reportSoftBinQuantityDecimal.Div(testQuantityDecimal).Round(4).
Mul(decimal.NewFromInt(100)).String() + "%"
hardBinFail = append(hardBinFail, &model.ReportBinFail{
Bin: hardBin,
Quantity: hardBinQuantity,
Proportion: hardBinQuantityDecimal.Div(testQuantityDecimal).Round(4).
Mul(decimal.NewFromInt(100)).String() + "%",
ReportQuantity: quantity,
ReportProportion: reportProportion,
})
}
sort.Slice(hardBinFail, func(i, j int) bool {
return hardBinFail[i].Quantity > hardBinFail[j].Quantity
})
ftShowList.SubBatchDetails = append(ftShowList.SubBatchDetails, model.ReportList{
OrderDate: ftShowList.OrderDate,
PBI: ftShowList.PBI,
Product: ftShowList.Product,
Lot: ftShowList.Lot,
SubBatch: report.SubBatch,
WaferID: report.WaferID,
Factory: ftShowList.Factory,
TestMachine: report.TestMachine,
TestProgram: ftShowList.TestProgram,
Seal: report.Seal,
TestQuantity: report.TestQuantity,
FirstPassQuantity: report.FirstPassQuantity,
FirstPassProbability: report.FirstPassProbability,
PassQuantity: report.PassQuantity,
PassProbability: report.PassProbability,
TestTime: report.TestTime,
Step: report.Step,
StackingMaterials: report.StackingMaterials,
SoftBinFailMap: softBinFailMap,
HardBinFailMap: hardBinFailMap,
SoftBinFail: softBinFail,
HardBinFail: hardBinFail,
Site: reportListSites,
})
}
sort.Slice(ftShowList.SubBatchDetails, func(i, j int) bool {
iDecimal, _ := decimal.NewFromString(ftShowList.SubBatchDetails[i].PassProbability[:len(ftShowList.SubBatchDetails[i].PassProbability)-1])
jDecimal, _ := decimal.NewFromString(ftShowList.SubBatchDetails[j].PassProbability[:len(ftShowList.SubBatchDetails[j].PassProbability)-1])
return jDecimal.LessThan(iDecimal)
})
var testQuantityDiffLabel, passQuantityDiffLabel, returnProbabilityLabel bool
testQuantityDecimal, _ := decimal.NewFromString(ftShowList.TestQuantity)
reportTestQuantityDecimal, _ := decimal.NewFromString(ftShowList.ReportTestQuantity)
firstPassQuantityDecimal, _ := decimal.NewFromString(ftShowList.FirstPassQuantity)
passQuantityDecimal, _ := decimal.NewFromString(ftShowList.PassQuantity)
reportPassQuantityDecimal, _ := decimal.NewFromString(ftShowList.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
}
ftShowList.TestQuantityDiff = diff.String() + "%"
ftShowList.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
}
ftShowList.ReturnProbability = probability.String() + "%"
ftShowList.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
}
ftShowList.PassQuantityDiff = diff.String() + "%"
ftShowList.PassQuantityDiffLabel = passQuantityDiffLabel
}
var softBinFail, hardBinFail []*model.ReportBinFail
for softBin, softBinQuantity := range ftShowList.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 ftShowList.HardBinFailMap {
hardBinQuantityDecimal := decimal.NewFromFloat(hardBinQuantity)
reportSoftBinQuantityDecimal := decimal.NewFromFloat(reportHardBinFailMap[hardBin])
hardBinFail = append(hardBinFail, &model.ReportBinFail{
Bin: hardBin,
Quantity: hardBinQuantity,
Proportion: hardBinQuantityDecimal.Div(testQuantityDecimal).Round(4).
Mul(decimal.NewFromInt(100)).String() + "%",
ReportQuantity: reportHardBinFailMap[hardBin],
ReportProportion: reportSoftBinQuantityDecimal.Div(testQuantityDecimal).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 ftShowList.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(ftShowList.Site, func(i, j int) bool {
iDecimal, _ := decimal.NewFromString(ftShowList.Site[i].PassProbability[:len(ftShowList.Site[i].PassProbability)-1])
jDecimal, _ := decimal.NewFromString(ftShowList.Site[j].PassProbability[:len(ftShowList.Site[j].PassProbability)-1])
return jDecimal.LessThan(iDecimal)
})
ftShowList.SoftBinFail = softBinFail
ftShowList.HardBinFail = hardBinFail
ftShowLists = append(ftShowLists, &ftShowList)
}
return ftShowLists, total
}
func TRList(r *request.TRList) ([]*model.TRList, int64) {
var sql string
if r.Status != "" {
sql += "status = '" + r.Status + "'"
}
if r.OrderDate != "" {
if sql != "" {
sql += " AND order_date LIKE '%" + r.OrderDate + "%'"
} else {
sql += "order_date LIKE '%" + r.OrderDate + "%'"
}
}
if r.PBI != "" {
if sql != "" {
sql += " AND pbi LIKE '%" + r.PBI + "%'"
} else {
sql += "pbi LIKE '%" + r.PBI + "%'"
}
}
if r.Product != "" {
if sql != "" {
sql += " AND product LIKE '%" + r.Product + "%'"
} else {
sql += "product LIKE '%" + r.Product + "%'"
}
}
if r.WaferProduct != "" {
if sql != "" {
sql += " AND wafer_product LIKE '%" + r.WaferProduct + "%'"
} else {
sql += "wafer_product LIKE '%" + r.WaferProduct + "%'"
}
}
if r.Package != "" {
if sql != "" {
sql += " AND package LIKE '%" + r.Package + "%'"
} else {
sql += "package LIKE '%" + r.Package + "%'"
}
}
if r.Factory != "" {
if sql != "" {
sql += " AND factory LIKE '%" + r.Factory + "%'"
} else {
sql += "factory LIKE '%" + r.Factory + "%'"
}
}
if r.Lot != "" {
if sql != "" {
sql += " AND lot LIKE '%" + r.Lot + "%'"
} else {
sql += "lot LIKE '%" + r.Lot + "%'"
}
}
if r.Seal != "" {
if sql != "" {
sql += " AND seal LIKE '%" + r.Seal + "%'"
} else {
sql += "seal LIKE '%" + r.Seal + "%'"
}
}
if r.Quantity != "" {
if sql != "" {
sql += " AND quantity = '" + r.Quantity + "'"
} else {
sql += "quantity = '" + r.Quantity + "'"
}
}
if r.OnlineQuantity != "" {
if sql != "" {
sql += " AND online_quantity = '" + r.OnlineQuantity + "'"
} else {
sql += "online_quantity = '" + r.OnlineQuantity + "'"
}
}
if r.PassQuantity != "" {
if sql != "" {
sql += " AND pass_quantity = '" + r.PassQuantity + "'"
} else {
sql += "pass_quantity = '" + r.PassQuantity + "'"
}
}
if r.FailQuantity != "" {
if sql != "" {
sql += " AND fail_quantity = '" + r.FailQuantity + "'"
} else {
sql += "fail_quantity = '" + r.FailQuantity + "'"
}
}
var trList []*model.TRList
var total int64
if r.Page > 0 {
r.Page--
}
global.PostGreSQL.Where(sql).Order("order_date desc").Find(&trList).Count(&total).
Offset(r.Page * r.PageSize).Limit(r.PageSize).
Preload("TRListStock").Find(&trList)
return trList, total
}