数据分析平台 导出测试FT记录
This commit is contained in:
parent
8aa2e451ab
commit
5fc153a475
@ -3,9 +3,11 @@ package test_data
|
||||
import (
|
||||
"bufio"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"github.com/shopspring/decimal"
|
||||
"github.com/spf13/viper"
|
||||
"github.com/xuri/excelize/v2"
|
||||
"gorm.io/gorm"
|
||||
"log"
|
||||
"math"
|
||||
"os"
|
||||
@ -1423,22 +1425,19 @@ func ExportScatter(req *request.Scatter) string {
|
||||
return strings.ReplaceAll(viper.GetString("domain"), "\\", "/") + filePath
|
||||
}
|
||||
|
||||
func ExportFT() string {
|
||||
//start := carbon.Now().SubWeek().Format("Y-m-d")
|
||||
//end := carbon.Now().Format("Y-m-d")
|
||||
func ExportFT(start, end string) string {
|
||||
//var fileHandles []*model.FileHandled
|
||||
//global.PostGreSQL.Where("ending_time != ? AND DATE(ending_time) BETWEEN ? AND ?", "", start, end).
|
||||
//global.PostGreSQL.Where("step = ? AND created_at BETWEEN ? AND ?", "FT", start, end).
|
||||
// Find(&fileHandles)
|
||||
|
||||
file := excelize.NewFile()
|
||||
var ftLists []*model.FTList
|
||||
//global.PostGreSQL.Where("order_date BETWEEN ? AND ?", start, end).Find(&ftLists)
|
||||
//global.PostGreSQL.Find(&ftLists)
|
||||
var a []string
|
||||
global.PostGreSQL.Model(&model.Report{}).Where("pbi != ?", "").Group("pbi").Select("pbi").Find(&a)
|
||||
global.PostGreSQL.Where("pbi IN ?", a).Find(&ftLists)
|
||||
//global.PostGreSQL.Where("product = ? AND lot = ? AND pbi = ?", "MP5016-5EC0", "S3S592", "M589-2306200001").Find(&ftLists)
|
||||
//var exportFTs []*model.ExportFT
|
||||
var pbis, lots []string
|
||||
global.PostGreSQL.Model(&model.Report{}).Where("pbi != ? AND created_at BETWEEN ? AND ?", "", start, end).
|
||||
Group("pbi").Select("pbi").Find(&pbis)
|
||||
global.PostGreSQL.Model(&model.Report{}).Where("lot != ? AND created_at BETWEEN ? AND ?", "", start, end).
|
||||
Group("lot").Select("lot").Find(&lots)
|
||||
global.PostGreSQL.Where("pbi IN ? AND lot IN ?", pbis, lots).Find(&ftLists)
|
||||
|
||||
sheetName := "FT记录总表"
|
||||
_, _ = file.NewSheet(sheetName)
|
||||
@ -1452,7 +1451,7 @@ func ExportFT() string {
|
||||
ftList.Product = strings.ReplaceAll(ftList.Product, "管装", "")
|
||||
var warning *model.Warning
|
||||
global.PostGreSQL.Where("step LIKE ? AND product LIKE ?", "%FT%", "%"+ftList.Product+"%").
|
||||
Preload("ProductionControl").Preload("PassProbabilityDiff").Preload("BinControl").
|
||||
Preload("PassProbabilityDiff").Preload("BinControl").
|
||||
Preload("SelectionDiffControl").Preload("StackingMaterialsWarning").Preload("HistogramSelection").
|
||||
Preload("ScatterSelection").Find(&warning)
|
||||
|
||||
@ -1461,6 +1460,9 @@ func ExportFT() string {
|
||||
var reports []*model.Report
|
||||
global.PostGreSQL.Where("step LIKE ? AND product = ? AND lot = ? AND pbi = ?",
|
||||
"%FT%", ftList.Product, ftList.Lot, ftList.PBI).Find(&reports)
|
||||
if len(reports) == 0 {
|
||||
continue
|
||||
}
|
||||
for _, report := range reports {
|
||||
reportTestQuantityDecimal, _ := decimal.NewFromString(report.TestQuantity)
|
||||
testQuantityDecimal, _ := decimal.NewFromString(testQuantity)
|
||||
@ -1525,41 +1527,6 @@ func ExportFT() string {
|
||||
bin10Decimal, _ := decimal.NewFromString(finalReport.Bin10)
|
||||
bin10, _ := bin10Decimal.Float64()
|
||||
hardBinCounter["BIN10"] += bin10
|
||||
//outlookFailDecimal, _ := decimal.NewFromString(finalReport.OutlookFail)
|
||||
//otherDecimal, _ := decimal.NewFromString(finalReport.Other)
|
||||
//bentStitchDecimal, _ := decimal.NewFromString(finalReport.BentStitch)
|
||||
//scrappedDecimal, _ := decimal.NewFromString(finalReport.Scrapped)
|
||||
|
||||
//if !reportTestQuantityDecimal.IsZero() {
|
||||
// finalReport.Bin1 = bin1Decimal.Div(reportTestQuantityDecimal).Round(4).Mul(decimal.NewFromInt(100)).
|
||||
// String() + "%"
|
||||
// finalReport.Bin2 = bin2Decimal.Div(reportTestQuantityDecimal).Round(4).Mul(decimal.NewFromInt(100)).
|
||||
// String() + "%"
|
||||
// finalReport.Bin3 = bin3Decimal.Div(reportTestQuantityDecimal).Round(4).Mul(decimal.NewFromInt(100)).
|
||||
// String() + "%"
|
||||
// finalReport.Bin4 = bin4Decimal.Div(reportTestQuantityDecimal).Round(4).Mul(decimal.NewFromInt(100)).
|
||||
// String() + "%"
|
||||
// finalReport.Bin5 = bin5Decimal.Div(reportTestQuantityDecimal).Round(4).Mul(decimal.NewFromInt(100)).
|
||||
// String() + "%"
|
||||
// finalReport.Bin6 = bin6Decimal.Div(reportTestQuantityDecimal).Round(4).Mul(decimal.NewFromInt(100)).
|
||||
// String() + "%"
|
||||
// finalReport.Bin7 = bin7Decimal.Div(reportTestQuantityDecimal).Round(4).Mul(decimal.NewFromInt(100)).
|
||||
// String() + "%"
|
||||
// finalReport.Bin8 = bin8Decimal.Div(reportTestQuantityDecimal).Round(4).Mul(decimal.NewFromInt(100)).
|
||||
// String() + "%"
|
||||
// finalReport.Bin9 = bin9Decimal.Div(reportTestQuantityDecimal).Round(4).Mul(decimal.NewFromInt(100)).
|
||||
// String() + "%"
|
||||
// finalReport.Bin10 = bin10Decimal.Div(reportTestQuantityDecimal).Round(4).Mul(decimal.NewFromInt(100)).
|
||||
// String() + "%"
|
||||
// finalReport.OutlookFail = outlookFailDecimal.Div(reportTestQuantityDecimal).Round(4).Mul(decimal.NewFromInt(100)).
|
||||
// String() + "%"
|
||||
// finalReport.Other = otherDecimal.Div(reportTestQuantityDecimal).Round(4).Mul(decimal.NewFromInt(100)).
|
||||
// String() + "%"
|
||||
// finalReport.BentStitch = bentStitchDecimal.Div(reportTestQuantityDecimal).Round(4).Mul(decimal.NewFromInt(100)).
|
||||
// String() + "%"
|
||||
// finalReport.Scrapped = scrappedDecimal.Div(reportTestQuantityDecimal).Round(4).Mul(decimal.NewFromInt(100)).
|
||||
// String() + "%"
|
||||
//}
|
||||
}
|
||||
var testQuantityDiff, passQuantityDiff string
|
||||
finalTestQuantityDecimal, _ := decimal.NewFromString(finalTestQuantity)
|
||||
@ -1570,6 +1537,7 @@ func ExportFT() string {
|
||||
testQuantityDiff = testQuantityDecimal.Sub(finalTestQuantityDecimal).Div(finalTestQuantityDecimal).Round(4).
|
||||
Mul(decimal.NewFromInt(100)).String() + "%"
|
||||
}
|
||||
|
||||
hardBinState := "正常"
|
||||
if !testQuantityDecimal.IsZero() {
|
||||
passQuantityDiff = passQuantityDecimal.Sub(finalPassQuantityDecimal).Div(passQuantityDecimal).Round(4).
|
||||
@ -1622,6 +1590,7 @@ func ExportFT() string {
|
||||
}
|
||||
if data[fieldMap["SOFT_BIN"]] == "1" {
|
||||
sitePassCounter[data[fieldMap["SITE_NUM"]]]++
|
||||
var needWarn bool
|
||||
for _, stackingMaterialsWarning := range warning.StackingMaterialsWarning {
|
||||
selectionDecimal, _ := decimal.NewFromString(data[fieldMap[stackingMaterialsWarning.Selection]])
|
||||
selectionFloat64, _ := selectionDecimal.Float64()
|
||||
@ -1648,10 +1617,13 @@ func ExportFT() string {
|
||||
})
|
||||
if midArray[0]-midArray[len(midArray)-1] >
|
||||
diff {
|
||||
stackingMaterials = "是"
|
||||
needWarn = true
|
||||
}
|
||||
}
|
||||
}
|
||||
if needWarn {
|
||||
stackingMaterials = "是"
|
||||
}
|
||||
} else {
|
||||
for _, stackingMaterialsWarning := range warning.StackingMaterialsWarning {
|
||||
stackingMaterialsArray[data[fieldMap["SITE_NUM"]]][stackingMaterialsWarning.Selection] = []float64{}
|
||||
@ -1757,25 +1729,28 @@ func ExportFT() string {
|
||||
_ = file.SetCellStyle(sheetName, "P"+strconv.Itoa(ftRecordIndex), "P"+strconv.Itoa(ftRecordIndex), ExportWarningStyle(file))
|
||||
}
|
||||
}
|
||||
//for _, productionControl := range warning.ProductionControl {
|
||||
// if productionControl.Factory == ftList.Factory {
|
||||
// testQuantityDiffStr := strings.ReplaceAll(testQuantityDiff, "%", "")
|
||||
// sDecimal, _ := decimal.NewFromString(testQuantityDiffStr)
|
||||
// testQuantityDiffHDecimal, _ := decimal.NewFromString(strings.ReplaceAll(productionControl.TestQuantityDiffH, "%", ""))
|
||||
// testQuantityDiffLDecimal, _ := decimal.NewFromString(strings.ReplaceAll(productionControl.TestQuantityDiffL, "%", ""))
|
||||
// if sDecimal.LessThan(testQuantityDiffLDecimal) || testQuantityDiffHDecimal.LessThan(sDecimal) {
|
||||
// _ = file.SetCellStyle(sheetName, "Q"+strconv.Itoa(ftRecordIndex), "Q"+strconv.Itoa(ftRecordIndex), ExportWarningStyle(file))
|
||||
// }
|
||||
// passQuantityDiffStr := strings.ReplaceAll(passQuantityDiff, "%", "")
|
||||
// saDecimal, _ := decimal.NewFromString(passQuantityDiffStr)
|
||||
// passQuantityDiffHDecimal, _ := decimal.NewFromString(strings.ReplaceAll(productionControl.PassQuantityDiffH, "%", ""))
|
||||
// passQuantityDiffLDecimal, _ := decimal.NewFromString(strings.ReplaceAll(productionControl.PassQuantityDiffL, "%", ""))
|
||||
// if saDecimal.LessThan(passQuantityDiffLDecimal) || passQuantityDiffHDecimal.LessThan(saDecimal) {
|
||||
// _ = file.SetCellStyle(sheetName, "R"+strconv.Itoa(ftRecordIndex), "R"+strconv.Itoa(ftRecordIndex), ExportWarningStyle(file))
|
||||
// }
|
||||
// break
|
||||
// }
|
||||
//}
|
||||
|
||||
var productionControl *model.ProductionControl
|
||||
if !errors.Is(global.PostGreSQL.Where("factory LIKE ?", "%"+ftList.Factory+"%").First(&productionControl).Error, gorm.ErrRecordNotFound) {
|
||||
if testQuantityDiff != "" {
|
||||
s := strings.ReplaceAll(testQuantityDiff, "%", "")
|
||||
sDecimal, _ := decimal.NewFromString(s)
|
||||
testQuantityDiffHDecimal, _ := decimal.NewFromString(productionControl.TestQuantityDiffH)
|
||||
testQuantityDiffLDecimal, _ := decimal.NewFromString(productionControl.TestQuantityDiffL)
|
||||
if sDecimal.LessThan(testQuantityDiffLDecimal) || testQuantityDiffHDecimal.LessThan(sDecimal) {
|
||||
_ = file.SetCellStyle(sheetName, "Q"+strconv.Itoa(ftRecordIndex), "Q"+strconv.Itoa(ftRecordIndex), ExportWarningStyle(file))
|
||||
}
|
||||
}
|
||||
if passQuantityDiff != "" {
|
||||
s := strings.ReplaceAll(passQuantityDiff, "%", "")
|
||||
sDecimal, _ := decimal.NewFromString(s)
|
||||
passQuantityDiffHDecimal, _ := decimal.NewFromString(productionControl.PassQuantityDiffH)
|
||||
passQuantityDiffLDecimal, _ := decimal.NewFromString(productionControl.PassQuantityDiffL)
|
||||
if sDecimal.LessThan(passQuantityDiffLDecimal) || passQuantityDiffHDecimal.LessThan(sDecimal) {
|
||||
_ = file.SetCellStyle(sheetName, "R"+strconv.Itoa(ftRecordIndex), "R"+strconv.Itoa(ftRecordIndex), ExportWarningStyle(file))
|
||||
}
|
||||
}
|
||||
}
|
||||
if hardBinState == "异常" {
|
||||
_ = file.SetCellStyle(sheetName, "S"+strconv.Itoa(ftRecordIndex), "S"+strconv.Itoa(ftRecordIndex), ExportWarningStyle(file))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user