فهرست منبع

Merge branch 'chart/14.5'

Roc 1 سال پیش
والد
کامیت
871a9cd98b
2فایلهای تغییر یافته به همراه42 افزوده شده و 19 حذف شده
  1. 38 19
      models/supply_analysis/base_from_stock_plant_data.go
  2. 4 0
      models/supply_analysis/variety_plant.go

+ 38 - 19
models/supply_analysis/base_from_stock_plant_data.go

@@ -45,22 +45,45 @@ func Calculate(varietyId int, sysUserId int, sysUserName string) (err error) {
 		return
 	}
 
+	// 产生的数据的结束日期
+	var lastDate time.Time
+	{
+		currDate := time.Now()
+		currHour := currDate.Hour()
+		if currHour < 22 {
+			lastDate, _ = time.ParseInLocation(utils.FormatDate, currDate.Format(utils.FormatDate), time.Local)
+		} else {
+			lastDate, _ = time.ParseInLocation(utils.FormatDate, currDate.AddDate(0, 0, 1).Format(utils.FormatDate), time.Local)
+		}
+		lastDate = lastDate.AddDate(1, 0, 0) //业务需要计算的数据日期往当前日期后面加上一年
+	}
+
 	// 维修数据的开始日期和结束日期
-	var startDate, endDate time.Time
+	var startDate time.Time
 	//所有设备在该日期的减产数
 	maintenanceDataMap := make(map[time.Time][]float64)
 
 	for _, plantInfo := range plantList {
+		if plantInfo.IsStop == 1 { // 如果是停产了,那么结束日期就是到 产生的数据的结束日期
+			plantInfo.ResumptionDate = lastDate
+		}
+		// 数据不全
+		if plantInfo.MaintenanceDate.IsZero() || plantInfo.ResumptionDate.IsZero() {
+			continue
+		}
+		// 日均产量减量为0,说明数据不全,不参与计算
+		if plantInfo.AverageDailyCapacityReduction == 0 {
+			continue
+		}
 		// 开始检修日期
 		if startDate.IsZero() || plantInfo.MaintenanceDate.Before(startDate) {
 			startDate = plantInfo.MaintenanceDate
 		}
+
 		// 结束检修日期
-		if endDate.IsZero() || plantInfo.ResumptionDate.After(endDate) {
-			endDate = plantInfo.ResumptionDate
-		}
+		resumptionDate := plantInfo.ResumptionDate
 
-		for tmpDate := plantInfo.MaintenanceDate; !tmpDate.After(plantInfo.ResumptionDate); tmpDate = tmpDate.AddDate(0, 0, 1) {
+		for tmpDate := plantInfo.MaintenanceDate; !tmpDate.After(resumptionDate); tmpDate = tmpDate.AddDate(0, 0, 1) {
 			dataList, ok := maintenanceDataMap[tmpDate]
 			if !ok {
 				dataList = make([]float64, 0)
@@ -70,17 +93,10 @@ func Calculate(varietyId int, sysUserId int, sysUserName string) (err error) {
 		}
 	}
 
-	// 产生的数据的结束日期
-	var lastDate time.Time
-
-	currDate := time.Now()
-	currHour := currDate.Hour()
-	if currHour < 22 {
-		lastDate, _ = time.ParseInLocation(utils.FormatDate, currDate.Format(utils.FormatDate), time.Local)
-	} else {
-		lastDate, _ = time.ParseInLocation(utils.FormatDate, currDate.AddDate(0, 0, 1).Format(utils.FormatDate), time.Local)
+	// 一个有用的装置都没有,那么就不需要计算了
+	if len(maintenanceDataMap) <= 0 {
+		return
 	}
-	lastDate = lastDate.AddDate(1, 0, 0) //业务需要计算的数据日期往当前日期后面加上一年
 
 	// 计算出数据
 	dataMap := make(map[time.Time]float64)
@@ -113,10 +129,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
+			}
 		}
 	}
 

+ 4 - 0
models/supply_analysis/variety_plant.go

@@ -18,6 +18,8 @@ type VarietyPlant struct {
 	AnnualCapacity                float64   `description:"年产能"`
 	Coefficient                   float64   `description:"降负系数"`
 	AverageDailyCapacityReduction float64   `description:"日均产量减量"`
+	IsStop                        int       `description:"是否停产,0:未停产;1:停产;默认未停产"`
+	Sort                          int       `description:"排序字段,越小越靠前"`
 	SysUserId                     int       `description:"添加人id"`
 	SysUserRealName               string    `description:"添加人真实姓名"`
 	ModifyTime                    time.Time `description:"最近一次更新时间"`
@@ -72,6 +74,8 @@ type VarietyPlantItem struct {
 	AnnualCapacity                float64            `description:"年产能"`
 	Coefficient                   float64            `description:"降负系数"`
 	AverageDailyCapacityReduction float64            `description:"日均产量减量"`
+	IsStop                        int                `description:"是否停产,0:未停产;1:停产;默认未停产"`
+	Sort                          int                `description:"排序字段,越小越靠前"`
 	SysUserId                     int                `description:"添加人id"`
 	SysUserRealName               string             `description:"添加人真实姓名"`
 	ModifyTime                    string             `description:"最近一次更新时间"`