数据分析平台 报警设置窗口调整
This commit is contained in:
parent
0420975609
commit
01d57ff848
@ -67,6 +67,20 @@ func (S *SWarningService) ShowList(c *gin.Context) {
|
|||||||
response.OkWithData(gin.H{"warning": warning, "total": total}, c)
|
response.OkWithData(gin.H{"warning": warning, "total": total}, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Tags 数据分析平台
|
||||||
|
// @Summary 查询报警设置产品参考信息
|
||||||
|
// @Security ApiKeyAuth
|
||||||
|
// @accept application/json
|
||||||
|
// @Param product query string false "产品型号"
|
||||||
|
// @Param step query string false "工序"
|
||||||
|
// @Success 200 {string} string "{"success":true,"data":{},"msg":"操作成功"}"
|
||||||
|
// @Router /testData/warning/selection [get]
|
||||||
|
func (S *SWarningService) WarningSelection(c *gin.Context) {
|
||||||
|
product := c.Query("product")
|
||||||
|
step := c.Query("step")
|
||||||
|
response.OkWithData(test_data.GetWarningSelection(product, step), c)
|
||||||
|
}
|
||||||
|
|
||||||
// @Tags 数据分析平台
|
// @Tags 数据分析平台
|
||||||
// @Summary 删除报警设置信息
|
// @Summary 删除报警设置信息
|
||||||
// @Security ApiKeyAuth
|
// @Security ApiKeyAuth
|
||||||
|
@ -3,28 +3,11 @@ package test_data
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"strconv"
|
|
||||||
"testData/global"
|
"testData/global"
|
||||||
"testData/model"
|
"testData/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
func UpdateWarning(req *model.Warning) error {
|
func UpdateWarning(req *model.Warning) error {
|
||||||
_, err := strconv.ParseFloat(req.FirstPassProbabilityLimitL, 64)
|
|
||||||
if err != nil {
|
|
||||||
return errors.New("一次通过率下限必须是数字")
|
|
||||||
}
|
|
||||||
_, err = strconv.ParseFloat(req.ReturnProbabilityLimitH, 64)
|
|
||||||
if err != nil {
|
|
||||||
return errors.New("回收率上限必须是数字")
|
|
||||||
}
|
|
||||||
_, err = strconv.ParseFloat(req.PassProbabilityLimitL, 64)
|
|
||||||
if err != nil {
|
|
||||||
return errors.New("良率下限必须是数字")
|
|
||||||
}
|
|
||||||
_, err = strconv.ParseFloat(req.AveragePassProbability, 64)
|
|
||||||
if err != nil {
|
|
||||||
return errors.New("平均良率必须是数字")
|
|
||||||
}
|
|
||||||
var warning *model.Warning
|
var warning *model.Warning
|
||||||
if errors.Is(global.PostGreSQL.Where("product = ? AND step = ?", req.Product, req.Step).First(&warning).Error, gorm.ErrRecordNotFound) {
|
if errors.Is(global.PostGreSQL.Where("product = ? AND step = ?", req.Product, req.Step).First(&warning).Error, gorm.ErrRecordNotFound) {
|
||||||
global.PostGreSQL.Create(&model.Warning{
|
global.PostGreSQL.Create(&model.Warning{
|
||||||
@ -53,52 +36,24 @@ func UpdateWarning(req *model.Warning) error {
|
|||||||
for k := range req.PassProbabilityDiff {
|
for k := range req.PassProbabilityDiff {
|
||||||
req.PassProbabilityDiff[k].ID = 0
|
req.PassProbabilityDiff[k].ID = 0
|
||||||
req.PassProbabilityDiff[k].WarningID = warning.ID
|
req.PassProbabilityDiff[k].WarningID = warning.ID
|
||||||
_, err = strconv.ParseFloat(req.PassProbabilityDiff[k].SitePassProbabilityDiff, 64)
|
|
||||||
if err != nil {
|
|
||||||
return errors.New("良率差异设置必须是数字")
|
|
||||||
}
|
|
||||||
_, err = strconv.ParseFloat(req.PassProbabilityDiff[k].PassProbabilityDiff, 64)
|
|
||||||
if err != nil {
|
|
||||||
return errors.New("良率差异设置必须是数字")
|
|
||||||
}
|
|
||||||
_, err = strconv.ParseFloat(req.PassProbabilityDiff[k].PassProbabilityWave, 64)
|
|
||||||
if err != nil {
|
|
||||||
return errors.New("良率差异设置必须是数字")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
global.PostGreSQL.Where("warning_id = ?", warning.ID).Delete(&model.PassProbabilityDiff{})
|
global.PostGreSQL.Where("warning_id = ?", warning.ID).Delete(&model.PassProbabilityDiff{})
|
||||||
global.PostGreSQL.Create(&req.PassProbabilityDiff)
|
global.PostGreSQL.Create(&req.PassProbabilityDiff)
|
||||||
for k := range req.BinControl {
|
for k := range req.BinControl {
|
||||||
req.BinControl[k].ID = 0
|
req.BinControl[k].ID = 0
|
||||||
req.BinControl[k].WarningID = warning.ID
|
req.BinControl[k].WarningID = warning.ID
|
||||||
_, err = strconv.ParseFloat(req.BinControl[k].BinFailLimitH, 64)
|
|
||||||
if err != nil {
|
|
||||||
return errors.New("关键BIN设置必须是数字")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
global.PostGreSQL.Where("warning_id = ?", warning.ID).Delete(&model.BinControl{})
|
global.PostGreSQL.Where("warning_id = ?", warning.ID).Delete(&model.BinControl{})
|
||||||
global.PostGreSQL.Create(&req.BinControl)
|
global.PostGreSQL.Create(&req.BinControl)
|
||||||
for k := range req.SelectionDiffControl {
|
for k := range req.SelectionDiffControl {
|
||||||
req.SelectionDiffControl[k].ID = 0
|
req.SelectionDiffControl[k].ID = 0
|
||||||
req.SelectionDiffControl[k].WarningID = warning.ID
|
req.SelectionDiffControl[k].WarningID = warning.ID
|
||||||
_, err = strconv.ParseFloat(req.SelectionDiffControl[k].SiteDiff, 64)
|
|
||||||
if err != nil {
|
|
||||||
return errors.New("参数允许差异设置必须是数字")
|
|
||||||
}
|
|
||||||
_, err = strconv.ParseFloat(req.SelectionDiffControl[k].SubBatchDiff, 64)
|
|
||||||
if err != nil {
|
|
||||||
return errors.New("参数允许差异设置必须是数字")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
global.PostGreSQL.Where("warning_id = ?", warning.ID).Delete(&model.SelectionDiffControl{})
|
global.PostGreSQL.Where("warning_id = ?", warning.ID).Delete(&model.SelectionDiffControl{})
|
||||||
global.PostGreSQL.Create(&req.SelectionDiffControl)
|
global.PostGreSQL.Create(&req.SelectionDiffControl)
|
||||||
for k := range req.StackingMaterialsWarning {
|
for k := range req.StackingMaterialsWarning {
|
||||||
req.StackingMaterialsWarning[k].ID = 0
|
req.StackingMaterialsWarning[k].ID = 0
|
||||||
req.StackingMaterialsWarning[k].WarningID = warning.ID
|
req.StackingMaterialsWarning[k].WarningID = warning.ID
|
||||||
_, err = strconv.ParseFloat(req.StackingMaterialsWarning[k].Diff, 64)
|
|
||||||
if err != nil {
|
|
||||||
return errors.New("叠料报警设置必须是数字")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
global.PostGreSQL.Where("warning_id = ?", warning.ID).Delete(&model.StackingMaterialsWarning{})
|
global.PostGreSQL.Where("warning_id = ?", warning.ID).Delete(&model.StackingMaterialsWarning{})
|
||||||
global.PostGreSQL.Create(&req.StackingMaterialsWarning)
|
global.PostGreSQL.Create(&req.StackingMaterialsWarning)
|
||||||
|
93
repository/test.data/warning.selection.go
Normal file
93
repository/test.data/warning.selection.go
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
package test_data
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"encoding/json"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"sort"
|
||||||
|
"strings"
|
||||||
|
"testData/global"
|
||||||
|
"testData/model"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetWarningSelection(product, step string) map[string][]string {
|
||||||
|
var fileHandles []*model.FileHandled
|
||||||
|
global.PostGreSQL.Where("product LIKE ? AND step = ?", product+"%", step).
|
||||||
|
Limit(10).Order("created_at desc").Find(&fileHandles)
|
||||||
|
|
||||||
|
datas := make([][]string, 0)
|
||||||
|
fieldMap := make(map[string]int)
|
||||||
|
binMap := make(map[string]interface{})
|
||||||
|
var selection []string
|
||||||
|
for _, fileHandle := range fileHandles {
|
||||||
|
singleDatas := make([][]string, 0)
|
||||||
|
_ = json.Unmarshal([]byte(fileHandle.SbinHbin), &binMap)
|
||||||
|
f, err := os.Open(fileHandle.Path)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
}
|
||||||
|
scanner := bufio.NewScanner(f)
|
||||||
|
xyMap := make(map[string]int)
|
||||||
|
for scanner.Scan() {
|
||||||
|
line := scanner.Text()
|
||||||
|
s := strings.Split(line, ",")
|
||||||
|
if strings.Contains(fileHandle.Step, "CP") {
|
||||||
|
x := s[fieldMap["X_COORD"]]
|
||||||
|
y := s[fieldMap["Y_COORD"]]
|
||||||
|
if _, ok := xyMap[x+","+y]; !ok {
|
||||||
|
xyMap[x+","+y] = len(singleDatas)
|
||||||
|
singleDatas = append(singleDatas, s[:len(s)-1])
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
singleDatas = append(singleDatas, s[:len(s)-1])
|
||||||
|
}
|
||||||
|
if len(singleDatas) == 1 {
|
||||||
|
if strings.Contains(fileHandle.Step, "CP") {
|
||||||
|
selection = s[8 : len(s)-1]
|
||||||
|
} else {
|
||||||
|
selection = s[6 : len(s)-1]
|
||||||
|
}
|
||||||
|
for index, cell := range s {
|
||||||
|
if index == len(s)-1 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
fieldMap[cell] = index
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(singleDatas) >= 1 {
|
||||||
|
singleDatas = singleDatas[1:]
|
||||||
|
}
|
||||||
|
datas = append(datas, singleDatas...)
|
||||||
|
f.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
sBinMap := make(map[string]int)
|
||||||
|
for _, data := range datas {
|
||||||
|
sBinMap[data[fieldMap["SOFT_BIN"]]] += 1
|
||||||
|
}
|
||||||
|
hBinMap := make(map[string]int)
|
||||||
|
var sBin, hBin []string
|
||||||
|
for k := range sBinMap {
|
||||||
|
if _, ok := binMap[k]; ok {
|
||||||
|
sBin = append(sBin, k)
|
||||||
|
hBinMap[binMap[k].(string)] += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sort.Slice(sBin, func(i, j int) bool {
|
||||||
|
return sBinMap[sBin[i]] > sBinMap[sBin[j]]
|
||||||
|
})
|
||||||
|
for k := range hBinMap {
|
||||||
|
hBin = append(hBin, k)
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Slice(hBin, func(i, j int) bool {
|
||||||
|
return hBinMap[hBin[i]] > hBinMap[hBin[j]]
|
||||||
|
})
|
||||||
|
res := make(map[string][]string)
|
||||||
|
res["selection"] = selection
|
||||||
|
res["sbin"] = sBin
|
||||||
|
res["hbin"] = hBin
|
||||||
|
return res
|
||||||
|
}
|
@ -11,6 +11,7 @@ func InitWarningRouter(R *gin.RouterGroup) {
|
|||||||
{
|
{
|
||||||
warningGroup.POST("", warningService.Update)
|
warningGroup.POST("", warningService.Update)
|
||||||
warningGroup.GET("", warningService.ShowList)
|
warningGroup.GET("", warningService.ShowList)
|
||||||
|
warningGroup.GET("selection", warningService.WarningSelection)
|
||||||
warningGroup.DELETE("", warningService.Delete)
|
warningGroup.DELETE("", warningService.Delete)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user