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