From 178d6e7507ef4806ca02692c4ee24bb98dba8362 Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期二, 19 三月 2024 19:19:46 +0800
Subject: [PATCH] 生丝检验部分逻辑修正

---
 service/fineness.go |   93 ++++++++++++++++++++++++++--------------------
 1 files changed, 52 insertions(+), 41 deletions(-)

diff --git a/service/fineness.go b/service/fineness.go
index fc3635b..e44e1ab 100644
--- a/service/fineness.go
+++ b/service/fineness.go
@@ -15,54 +15,65 @@
 	if err != nil {
 		return err
 	}
-	//鏁寸悊鎴愭楠岃〃鐨勬暟鎹粨鏋�
-	finenessRoundingItemMap := make(map[int]map[float32]*models.FinenessRoundingItem)
-	for _, item := range finenessRegister.FinenessList {
-		if finenessRoundingItemMap[item.Position] == nil {
-			finenessRoundingItemMap[item.Position] = make(map[float32]*models.FinenessRoundingItem, 0)
+	finenessCheckItems := make([]*models.FinenessCheckItem, 0)
+	var lastCarNo int
+	var roundingItemMap map[float32]*models.FinenessRoundingItem
+	var allFinenessList []decimal.Decimal
+	var personFinenessList []decimal.Decimal
+	var carCheckNumber = 0 //鍗曚釜car宸叉鏌ユ牱鏈暟
+	endCarMap, err := GetWorkshopEndCarMap(finenessRegister.Workshop, finenessRegister.WorkshopGroup)
+	if err != nil {
+		return err
+	}
+	var item *models.FinenessCheckItem
+	var deviation decimal.Decimal
+	var finenessGrade string
+	for _, finenessItem := range finenessRegister.FinenessList {
+		roundedHalfFineness := ToRoundedHalfFineness(finenessItem.Fineness)
+		fineness := decimal.NewFromFloat32(roundedHalfFineness)
+		allFinenessList = append(allFinenessList, fineness)
+		personFinenessList = append(personFinenessList, fineness)
+		carCheckNumber++
+		if carCheckNumber == constvar.EveryPersonCarCheckNumber {
+			carCheckNumber = 0
+			if endCarMap[finenessItem.Position] { //璧板埌浜嗘煇涓汉鏈�鍚庣殑杞﹀彿,姣忎汉绠椾竴娆″亸宸拰绛夌骇
+				deviation = utils.Deviation(personFinenessList)
+				finenessGrade = CalcFinenessGrade(item.Deviation, item.TotalDeviation, item.Cleanliness, item.Purity, item.TwiceChange, standardMap)
+				personFinenessList = personFinenessList[:0]
+			}
 		}
-		roundedHalfFineness := ToRoundedHalfFineness(item.Fineness)
-		if finenessRoundingItemMap[item.Position][roundedHalfFineness] == nil {
-			finenessRoundingItemMap[item.Position][roundedHalfFineness] = &models.FinenessRoundingItem{
-				Fineness: decimal.NewFromFloat32(roundedHalfFineness),
+		if lastCarNo != finenessItem.Position { //姣忎釜杞﹀彿瀛樹竴涓猰odels.FinenessCheckItem
+			roundingItems := make([]*models.FinenessRoundingItem, 0, len(roundingItemMap))
+			for _, v := range roundingItemMap {
+				roundingItems = append(roundingItems, &models.FinenessRoundingItem{
+					Fineness: v.Fineness,
+					Quantity: v.Quantity,
+				})
+			}
+			item = &models.FinenessCheckItem{
+				FinenessRegisterID:   finenessRegister.ID,
+				Position:             lastCarNo,
+				FinenessRoundingItem: roundingItems,
+				Deviation:            deviation,
+				FinenessGrade:        finenessGrade,
+				Remark:               "",
+			}
+
+			finenessCheckItems = append(finenessCheckItems, item)
+			lastCarNo = finenessItem.Position
+			roundingItemMap = make(map[float32]*models.FinenessRoundingItem, 0)
+		}
+
+		if roundingItemMap[roundedHalfFineness] == nil {
+			roundingItemMap[roundedHalfFineness] = &models.FinenessRoundingItem{
+				Fineness: fineness,
 				Quantity: 1,
 			}
 		} else {
-			finenessRoundingItemMap[item.Position][roundedHalfFineness].Quantity++
+			roundingItemMap[roundedHalfFineness].Quantity++
 		}
 	}
-	finenessCheckItems := make([]*models.FinenessCheckItem, 0)
-	var allFinenessList []decimal.Decimal
-	var personEndFlag bool //璧板埌浜嗘煇涓汉鏈�鍚庣殑杞﹀彿
-	var finenessList []decimal.Decimal
-	var step = 3 //涓存椂鎸変竴涓汉涓変釜杞﹀彿绠椼��
-	for pos, roundingItemMap := range finenessRoundingItemMap {
-		roundingItems := make([]*models.FinenessRoundingItem, 0, len(roundingItemMap))
-		for _, v := range roundingItemMap {
-			roundingItems = append(roundingItems, v)
-			finenessList = append(finenessList, v.Fineness)
-			allFinenessList = append(allFinenessList, v.Fineness)
-		}
 
-		item := &models.FinenessCheckItem{
-			FinenessRegisterID:   finenessRegister.ID,
-			Position:             pos,
-			FinenessRoundingItem: roundingItems,
-			Remark:               "",
-		}
-		if pos%step == 0 {
-			personEndFlag = true
-		} else {
-			personEndFlag = false
-		}
-		if personEndFlag {
-			item.Deviation = utils.Deviation(finenessList)
-			item.FinenessGrade = CalcFinenessGrade(item.Deviation, item.TotalDeviation, item.Cleanliness, item.Purity, item.TwiceChange, standardMap)
-			finenessList = finenessList[:0]
-		}
-
-		finenessCheckItems = append(finenessCheckItems, item)
-	}
 	finenessCheck := models.FinenessCheck{
 		FinenessRegisterID:       finenessRegister.ID,
 		AverageFineness:          utils.Average(allFinenessList),

--
Gitblit v1.8.0