浏览代码

Merge branch 'chart/14.5' into debug

Roc 1 年之前
父节点
当前提交
71b4fdaa92

+ 13 - 12
controllers/future_good/future_good_edb_info.go

@@ -9,7 +9,6 @@ import (
 	"hongze/hongze_edb_lib/models/future_good"
 	"hongze/hongze_edb_lib/services"
 	"hongze/hongze_edb_lib/utils"
-	"strings"
 	"time"
 )
 
@@ -253,19 +252,21 @@ func (this *FutureGoodEdbInfoController) RefreshRelation() {
 		return
 	}
 
-	errMsgList := make([]string, 0)
-	for _, v := range list {
-		err, errMsg := logic.RefreshByChartId(v.ChartInfoId)
-		if err != nil {
-			errMsgList = append(errMsgList, fmt.Sprint(v.ChartInfoId, "更新失败,"+errMsg))
+	go func() {
+		errMsgList := make([]string, 0)
+		for _, v := range list {
+			err, errMsg := logic.RefreshByChartId(v.ChartInfoId)
+			if err != nil {
+				errMsgList = append(errMsgList, fmt.Sprint(v.ChartInfoId, "更新失败,"+errMsg))
+			}
 		}
-	}
 
-	if len(errMsgList) > 0 {
-		br.Msg = "部分刷新失败"
-		br.ErrMsg = "部分刷新失败,Err:" + strings.Join(errMsgList, ";")
-		return
-	}
+		if len(errMsgList) > 0 {
+			//br.Msg = "部分刷新失败"
+			//br.ErrMsg = "部分刷新失败,Err:" + strings.Join(errMsgList, ";")
+			return
+		}
+	}()
 
 	br.Ret = 200
 	br.Success = true

+ 27 - 16
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.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
+		if plantInfo.IsStop == 1 { // 如果是停产了,那么结束日期就是到 产生的数据的结束日期
+			resumptionDate = lastDate
 		}
 
-		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,18 +93,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:"最近一次更新时间"`