diff --git a/services/ap/implments/Balance.service.impl.go b/services/ap/implments/Balance.service.impl.go index 6bee31d..9b89ce3 100644 --- a/services/ap/implments/Balance.service.impl.go +++ b/services/ap/implments/Balance.service.impl.go @@ -615,7 +615,7 @@ func (impl *BalanceServiceImplement) SaveCustomerArticleDemand(user *global.User var ( //mainselectArticleDemandList []model.ArticleDemand - resouceId string + resouceId string ) //data_ArticleResource := make([]model.ArticleResource, 0, 10) @@ -649,14 +649,13 @@ func (impl *BalanceServiceImplement) SaveCustomerArticleDemand(user *global.User //保存 for _, mapInfo := range mapList { - data_ArticleDemand_new, _, err := impl.RefreshCustomerArticleDemand(user, mapInfo["AP_ArticleDemand-ArtId"], mapList) - if err != nil { - return nil, err - } - err = dao_ArticleDemand.Update(&data_ArticleDemand_new) + data_ArticleDemand_new, _, err := impl.RefreshCustomerArticleDemand(user, mapInfo["AP_ArticleDemand-ArtId"], mapList) + if err != nil { + return nil, err + } + err = dao_ArticleDemand.Update(&data_ArticleDemand_new) } - //data_ArticleResource, err = dao_ArticleResource.Select([]grmi.Predicate{meta.ArticleResource_PlantNr.NewPredicate(grmi.Equal, user.PlantNr), meta.ArticleResource_ResourceId.NewPredicate(grmi.Equal, resouceId)}, nil) //if err != nil { // return nil, grmi.NewDataBaseError(err) @@ -2822,7 +2821,7 @@ func (impl *BalanceServiceImplement) PublishMpsPlan(user *global.User, version s Key: utils.ValueToString(prePlanOrderVersion.PlanOrderId, ""), Info: *prePlanOrderVersion, }) - } else { + } else { log, _ := logger.NewLogger(user.UserId, "Balance") log.Error("前一半发布计划已取消, 前一半计划ID:" + prePlanOrderVersion.PlanOrderId) } @@ -2895,13 +2894,13 @@ func (impl *BalanceServiceImplement) PublishMpsPlan(user *global.User, version s } planOrder := model.PlanOrder{ PlanOrderId: planOrderId, - Pos: pos, - PlantNr: user.PlantNr, - ArtId: info.ArtId, - VersionNr: data_PlanOrderVersion.VersionNr, - DemandKey: info.DemandKey, - ProjectId: info.ProjectId, - CustomerId: info.CustomerId, + Pos: pos, + PlantNr: user.PlantNr, + ArtId: info.ArtId, + VersionNr: data_PlanOrderVersion.VersionNr, + DemandKey: info.DemandKey, + ProjectId: info.ProjectId, + CustomerId: info.CustomerId, //Descr PlanDate: date, PlanYear: info.DemandYear, @@ -3249,6 +3248,7 @@ func (impl *BalanceServiceImplement) RefreshBalanceData(user *global.User) error MinCoverPeriodType: "W", ResourceId: resourceId, } + firstDemandList = append(firstDemandList, firstArticleDemand) } } @@ -3257,21 +3257,33 @@ func (impl *BalanceServiceImplement) RefreshBalanceData(user *global.User) error //聚合 keyArtIdMap := make(map[string]map[string]model.ArticleDemand) - for index, _ := range firstDemandList { - _, isIn := keyArtIdMap[firstDemandList[index].ArtId] - if !isIn { - keyArtIdMap[firstDemandList[index].ArtId] = make(map[string]model.ArticleDemand) - keyArtIdMap[firstDemandList[index].ArtId][firstDemandList[index].DemandKey] = firstDemandList[index] - } else { - _, isIn := keyArtIdMap[firstDemandList[index].ArtId][firstDemandList[index].DemandKey] - if !isIn { - keyArtIdMap[firstDemandList[index].ArtId][firstDemandList[index].DemandKey] = firstDemandList[index] + for index, v := range firstDemandList { + if info, ok := keyArtIdMap[v.ArtId]; ok { + if _info, _ok := info[v.DemandKey]; _ok { + _info.ForecastDemandQty += v.ForecastDemandQty + keyArtIdMap[firstDemandList[index].ArtId][firstDemandList[index].DemandKey] = _info + } else { - value := keyArtIdMap[firstDemandList[index].ArtId][firstDemandList[index].DemandKey] - value.ForecastDemandQty += firstDemandList[index].ForecastDemandQty - keyArtIdMap[firstDemandList[index].ArtId][firstDemandList[index].DemandKey] = value + keyArtIdMap[v.ArtId][v.DemandKey] = v } - } + } else { + keyArtIdMap[v.ArtId] = make(map[string]model.ArticleDemand) + keyArtIdMap[v.ArtId][v.DemandKey] = v + } + //_, isIn := keyArtIdMap[firstDemandList[index].ArtId] + //if !isIn { + // keyArtIdMap[firstDemandList[index].ArtId] = make(map[string]model.ArticleDemand) + // keyArtIdMap[firstDemandList[index].ArtId][firstDemandList[index].DemandKey] = firstDemandList[index] + //} else { + // _, isIn := keyArtIdMap[firstDemandList[index].ArtId][firstDemandList[index].DemandKey] + // if !isIn { + // keyArtIdMap[firstDemandList[index].ArtId][firstDemandList[index].DemandKey] = firstDemandList[index] + // } else { + // value := keyArtIdMap[firstDemandList[index].ArtId][firstDemandList[index].DemandKey] + // value.ForecastDemandQty += firstDemandList[index].ForecastDemandQty + // keyArtIdMap[firstDemandList[index].ArtId][firstDemandList[index].DemandKey] = value + // } + //} } for _, value1 := range keyArtIdMap { @@ -3557,4 +3569,4 @@ func (impl *BalanceServiceImplement) MpsPlanExport(user *global.User, CustArtSto return "", grmi.NewBusinessError("导出失败,请重试") } return pathLi[1], nil -} \ No newline at end of file +}