|
@@ -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
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|