Эх сурвалжийг харах

feat:新增装置停产

Roc 1 жил өмнө
parent
commit
54de4dae44

+ 20 - 13
models/supply_analysis/base_from_stock_plant_data.go

@@ -45,6 +45,19 @@ 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
 	//所有设备在该日期的减产数
@@ -60,7 +73,13 @@ func Calculate(varietyId int, sysUserId int, sysUserName string) (err error) {
 			endDate = plantInfo.ResumptionDate
 		}
 
-		for tmpDate := plantInfo.MaintenanceDate; !tmpDate.After(plantInfo.ResumptionDate); tmpDate = tmpDate.AddDate(0, 0, 1) {
+		// 结束检修日期
+		resumptionDate := plantInfo.ResumptionDate
+		if plantInfo.IsStop == 1 { // 如果是停产了,那么结束日期就是到 产生的数据的结束日期
+			resumptionDate = lastDate
+		}
+
+		for tmpDate := plantInfo.MaintenanceDate; !tmpDate.After(resumptionDate); tmpDate = tmpDate.AddDate(0, 0, 1) {
 			dataList, ok := maintenanceDataMap[tmpDate]
 			if !ok {
 				dataList = make([]float64, 0)
@@ -70,18 +89,6 @@ 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)
-	}
-	lastDate = lastDate.AddDate(1, 0, 0) //业务需要计算的数据日期往当前日期后面加上一年
-
 	// 计算出数据
 	dataMap := make(map[time.Time]float64)
 	for tmpDate := startDate; !tmpDate.After(lastDate); tmpDate = tmpDate.AddDate(0, 0, 1) {

+ 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:"最近一次更新时间"`