Jelajahi Sumber

fix:重新计算存量装置的bug修复

Roc 1 tahun lalu
induk
melakukan
ef3997a269
1 mengubah file dengan 10 tambahan dan 7 penghapusan
  1. 10 7
      models/supply_analysis/base_from_stock_plant_data.go

+ 10 - 7
models/supply_analysis/base_from_stock_plant_data.go

@@ -64,6 +64,9 @@ func Calculate(varietyId int, sysUserId int, sysUserName string) (err error) {
 	maintenanceDataMap := make(map[time.Time][]float64)
 	maintenanceDataMap := make(map[time.Time][]float64)
 
 
 	for _, plantInfo := range plantList {
 	for _, plantInfo := range plantList {
+		if plantInfo.IsStop == 1 { // 如果是停产了,那么结束日期就是到 产生的数据的结束日期
+			plantInfo.ResumptionDate = lastDate
+		}
 		// 数据不全
 		// 数据不全
 		if plantInfo.MaintenanceDate.IsZero() || plantInfo.ResumptionDate.IsZero() {
 		if plantInfo.MaintenanceDate.IsZero() || plantInfo.ResumptionDate.IsZero() {
 			continue
 			continue
@@ -79,9 +82,6 @@ func Calculate(varietyId int, sysUserId int, sysUserName string) (err error) {
 
 
 		// 结束检修日期
 		// 结束检修日期
 		resumptionDate := plantInfo.ResumptionDate
 		resumptionDate := plantInfo.ResumptionDate
-		if plantInfo.IsStop == 1 { // 如果是停产了,那么结束日期就是到 产生的数据的结束日期
-			resumptionDate = lastDate
-		}
 
 
 		for tmpDate := plantInfo.MaintenanceDate; !tmpDate.After(resumptionDate); tmpDate = tmpDate.AddDate(0, 0, 1) {
 		for tmpDate := plantInfo.MaintenanceDate; !tmpDate.After(resumptionDate); tmpDate = tmpDate.AddDate(0, 0, 1) {
 			dataList, ok := maintenanceDataMap[tmpDate]
 			dataList, ok := maintenanceDataMap[tmpDate]
@@ -124,10 +124,13 @@ func Calculate(varietyId int, sysUserId int, sysUserName string) (err error) {
 		}
 		}
 	}()
 	}()
 
 
-	for _, varietyEdbInfo := range varietyEdbInfoList {
-		err = calculateEdb(to, varietyEdbInfo, dataMap, startDate, lastDate)
-		if err != nil {
-			return
+	// 有数据的话,那就参与计算
+	if len(dataMap) > 0 {
+		for _, varietyEdbInfo := range varietyEdbInfoList {
+			err = calculateEdb(to, varietyEdbInfo, dataMap, startDate, lastDate)
+			if err != nil {
+				return
+			}
 		}
 		}
 	}
 	}