Browse Source

修改mps功能

pull/70/head
DESKTOP-4672LME\Xu Tengfei 3 years ago
parent
commit
17d9a6857a
9 changed files with 435 additions and 189 deletions
  1. +1
    -0
      models/ap/ArticleDemand.model.go
  2. +6
    -0
      models/ap/ap.go
  3. +2
    -0
      services/ap/ArticleResource.service.go
  4. +3
    -1
      services/ap/Balance.service.go
  5. +15
    -0
      services/ap/implments/ArticleResource.service.impl.go
  6. +310
    -178
      services/ap/implments/Balance.service.impl.go
  7. +23
    -0
      web/controllers/ap/ArticleResource.rest.go
  8. +72
    -10
      web/controllers/ap/Balance.rest.go
  9. +3
    -0
      web/controllers/ap/ap.go

+ 1
- 0
models/ap/ArticleDemand.model.go View File

@ -54,6 +54,7 @@ type ArticleDemand struct {
MinCoverPeriod float64 `xorm:"-" json:"AP_ArticleDemand-MinCoverPeriod"`
MinCoverPeriodType string `xorm:"-" json:"AP_ArticleDemand-MinCoverPeriodType"`
ResourceWorkTime float64 `xorm:"-" json:"AP_ArticleDemand-ResourceWorkTime"` //资源产量
MidBatchQuantity int `xorm:"-" json:"AP_ArticleDemand-MidBatchQuantity"` //每次削减量
}


+ 6
- 0
models/ap/ap.go View File

@ -193,8 +193,14 @@ type ReviewInfo struct{
type MpsPlan struct {
ArticleResourceMpsGroupLst []ArticleResourceMpsGroup `json:"ArticleResourceMpsGroupLst"` //资源分组信息
ArticleDemandLst []ArticleDemand `json:"ArticleDemandLst"` //需求分组信息
ArticleAlternativeDemandLst []ArticleDemand `json:"ArticleAlternativeDemandLst"` //替代资源需求分组信息
}
type MpsPlan_DemandList struct {
ArticleDemandLst []ArticleDemand `json:"ArticleDemandLst"` //需求分组信息
}
// 资源分组信息
type ArticleResourceMpsGroup struct {
Time grmi.Date `json:"Time"`


+ 2
- 0
services/ap/ArticleResource.service.go View File

@ -81,6 +81,8 @@ type ArticleResourceService interface {
*
******************************************************************************/
SelectOne(*global.User, string, string) (*model.ArticleResource, error)
Search(*global.User, string) (*model.ArticleResource, error)
/******************************************************************************
*
* @Function Name : UpdateOne


+ 3
- 1
services/ap/Balance.service.go View File

@ -22,13 +22,15 @@ import (
******************************************************************************/
type BalanceService interface {
GetCustomerArticleDemand(user *global.User,CustomerId string,ArtId string)([]model.ArticleDemand, error)
SaveCustomerArticleDemand(user *global.User, ArticleDemandLst *[]model.ArticleDemand) (error)
RefreshCustomerArticleDemand(user *global.User, ArticleDemandLst *[]model.ArticleDemand) ([]model.ArticleDemand,error)
GetResourceCapacityAndDemand(user *global.User, urlParameters map[string]string) (result []model.ResourceLoad, err error)
CustomerOrderReview(user *global.User, urlParameters map[string]string)(result *model.CustomerOrderReviewInfo, err error)
CustomerOrderReviewList(user *global.User, CustomerOrderReviewInfoLst []model.CustomerOrderReviewInfo)(result []model.CustomerOrderReviewInfo, err error)
CustomerOrderReviewUpload(user *global.User, savePath string) (result []model.CustomerOrderReviewInfo, err error)
CustomerOrderReviewExport(user *global.User, CustomerOrderReviewInfoLst []model.CustomerOrderReviewInfo) (result string, err error)
GetMpsPlan(user *global.User,resouceId,secondresourceid string) ([]model.ArticleResourceMpsGroup,error)
MpsPlan(user *global.User,resouceId,secondresourceid string,mpsType int,mpsPlan *model.MpsPlan) (*model.MpsPlan,error)
MpsPlan(user *global.User,resouceId,secondresourceid string,mpsType int,mpsPlan *model.MpsPlan,selectArticleDemandList []model.ArticleDemand) (*model.MpsPlan,error)
SaveMpsPlan(user *global.User, ArticleDemandLst *[]model.ArticleDemand) (error)
RefreshBalanceData() (error)


+ 15
- 0
services/ap/implments/ArticleResource.service.impl.go View File

@ -178,6 +178,21 @@ func (impl *ArticleResourceServiceImplement) SelectOne(user *global.User, artId
return result, nil
}
func (impl *ArticleResourceServiceImplement) Search(user *global.User, artId string) (*model.ArticleResource, error) {
grmi.Log(user, "/services/ap/implments/ArticleResource.service.impl.go", "Search", "查询一个ArticleResource")
engine := db.Eloquent.Master()
session := engine.NewSession()
defer session.Close()
dao := dal.NewArticleResourceDAO(session, user.PlantNr, user.UserId)
articleResource, err := dao.SelectOneByArtId(artId)
if err != nil {
return nil, grmi.NewDataBaseError(err)
}
return articleResource, nil
}
/******************************************************************************
*
* @Reference leit.com/LAPP_CHEERSSON_BACKEND/services/ap/ArticleResourceService.UpdateOne


+ 310
- 178
services/ap/implments/Balance.service.impl.go View File

@ -22,6 +22,9 @@ import (
var alldata_ArticleDemand []model.ArticleDemand
var alldata_ArticleStockLevel []model.ArticleStockLevel
var alldata_ArticleResource []model.ArticleResource
var alldata_Resource []model.Resource
var alldata_Article []model_base.Article
/******************************************************************************
*
* @Struct Name : BalanceServiceImplement
@ -79,12 +82,47 @@ func (impl *BalanceServiceImplement) GetCustomerArticleDemand(user *global.User,
}
var data_ArticleResourceLst []model.ArticleResource
data_ArticleResourceLst = append(data_ArticleResourceLst, *articleResource)
data_ArticleDemand_new, err := impl.refreshMpsArticleDemand(data_ArticleStockLevel, data_ArticleDemand, data_ArticleResourceLst)
data_ArticleDemand_new, err := impl.refreshMpsArticleDemand(false, data_ArticleStockLevel, data_ArticleDemand, data_ArticleResourceLst)
if err != nil {
return nil, err
}
return data_ArticleDemand_new, nil
}
func (impl *BalanceServiceImplement) RefreshCustomerArticleDemand(user *global.User, ArticleDemandLst *[]model.ArticleDemand) ([]model.ArticleDemand, error) {
engine := db.Eloquent.Master()
session := engine.NewSession()
defer session.Close()
dao_ArticleStockLevel := dal.NewArticleStockLevelDAO(session, user.PlantNr, user.UserId)
data_ArticleStockLevel, err := dao_ArticleStockLevel.Select([]grmi.Predicate{meta.ArticleStockLevel_PlantNr.NewPredicate(grmi.Equal, user.PlantNr)}, nil)
if err != nil {
return nil, grmi.NewDataBaseError(err)
}
artResourceDao := dal.NewArticleResourceDAO(session, user.PlantNr, user.UserId)
articleResource, err := artResourceDao.SelectOneByArtId((*ArticleDemandLst)[0].ArtId)
if err != nil {
return nil, grmi.NewDataBaseError(err)
}
var data_ArticleResourceLst []model.ArticleResource
data_ArticleResourceLst = append(data_ArticleResourceLst, *articleResource)
data_ArticleDemand_new, err := impl.refreshMpsArticleDemand(true, data_ArticleStockLevel, *ArticleDemandLst, data_ArticleResourceLst)
if err != nil {
return nil, err
}
return data_ArticleDemand_new, err
}
func (impl *BalanceServiceImplement) SaveCustomerArticleDemand(user *global.User, ArticleDemandLst *[]model.ArticleDemand) error {
engine := db.Eloquent.Master()
session := engine.NewSession()
defer session.Close()
dao_ArticleDemand := dal.NewArticleDemandDAO(session, user.PlantNr, user.UserId)
err := dao_ArticleDemand.Update(ArticleDemandLst)
return err
}
func (impl *BalanceServiceImplement) GetResourceCapacityAndDemand(user *global.User, urlParameters map[string]string) (result []model.ResourceLoad, err error) {
@ -136,7 +174,6 @@ func (impl *BalanceServiceImplement) GetResourceCapacityAndDemand(user *global.U
return nil, grmi.NewBusinessError("不存在客户需求数据")
}
// 查询需求详细数据
demandLstLi, err := demandDetailDao.Select([]grmi.Predicate{meta.CustDemandVerDetail_VersionId.NewPredicate(grmi.Equal, version)}, []grmi.Field{meta.CustDemandVerDetail_ArtId, meta.CustDemandVerDetail_DemandDate})
if err != nil {
@ -155,7 +192,7 @@ func (impl *BalanceServiceImplement) GetResourceCapacityAndDemand(user *global.U
//if demandEndDate.Sub(endDate) < 0 {
// return nil, grmi.NewBusinessError("查询结束日期大于需求版本最大日期")
//}
for index, demandDetail := range demandLstLi{
for index, demandDetail := range demandLstLi {
// 校验查询的日期必须在版本开始和结束日期之间
// 计算需求周的起始日期和结束日期
weekStartDate := demandDetail.DemandDate.Restore().AddDate(0, 0, -int(demandDetail.DemandDate.Restore().Weekday()))
@ -193,7 +230,7 @@ func (impl *BalanceServiceImplement) GetResourceCapacityAndDemand(user *global.U
// 聚合按物料需求详细数据
demandArtMap := make(map[string][]model.CustDemandVerDetail)
// 查询需求模型
for _, demandHeadInfo := range demandHeadList{
for _, demandHeadInfo := range demandHeadList {
demandModel, err := demandModelDao.SelectOne(demandHeadInfo.CreateMode)
if err != nil {
return nil, grmi.NewBusinessError("查询客户需求模型失败, error:" + err.Error())
@ -214,7 +251,6 @@ func (impl *BalanceServiceImplement) GetResourceCapacityAndDemand(user *global.U
}
}
// 计算查询时间段内物料需求数量
demandArtQtyMap := make(map[string]float64)
for artId, demandDetailLi := range demandArtMap {
@ -323,7 +359,7 @@ func (impl *BalanceServiceImplement) GetResourceCapacityAndDemand(user *global.U
secondResourceSvr := NewSecondaryResourceServiceImplement()
// 计算物料关联资源的产能
for resourceId, timeData := range demandResourceTime {
if resourceId == ""{
if resourceId == "" {
continue
}
if searchResourceId != "" {
@ -338,30 +374,30 @@ func (impl *BalanceServiceImplement) GetResourceCapacityAndDemand(user *global.U
}
var resouceDemandLst []model.ResourceDemand
for _, resourceInfo := range resourceLi{
for _, demandInfo := range demandLstLi{
if resourceInfo.ArtId == demandInfo.ArtId{
for _, resourceInfo := range resourceLi {
for _, demandInfo := range demandLstLi {
if resourceInfo.ArtId == demandInfo.ArtId {
data_customer, err := dao_customer.SelectOne(demandInfo.CustomerId)
if err != nil {
return nil, grmi.NewDataBaseError(err)
}
resouceDemandLst = append(resouceDemandLst, model.ResourceDemand{
CustomerName: data_customer.Name1,
ArtId: demandInfo.ArtId,
Qty: demandInfo.DemandQtyMath,
ArtId: demandInfo.ArtId,
Qty: demandInfo.DemandQtyMath,
})
}
}
}
data := model.ResourceLoad{
ResourceId: resourceId,
ResourceDesc: resource.Resource.Descr,
ResourceType: "first",
DemandTime: int(math.Ceil(timeData)),
Uom: "小时",
ResourceId: resourceId,
ResourceDesc: resource.Resource.Descr,
ResourceType: "first",
DemandTime: int(math.Ceil(timeData)),
Uom: "小时",
ResourceDemandLst: resouceDemandLst,
}
workTime, err := resourceSvr.CalculateResourceWorkTime(user, resourceId ,start, end)
workTime, err := resourceSvr.CalculateResourceWorkTime(user, resourceId, start, end)
if err != nil {
return nil, err
}
@ -370,7 +406,7 @@ func (impl *BalanceServiceImplement) GetResourceCapacityAndDemand(user *global.U
result = append(result, data)
}
for resourceId, timeData := range demandSecondResourceTime {
if resourceId == ""{
if resourceId == "" {
continue
}
if searchSecondResourceId != "" {
@ -379,28 +415,28 @@ func (impl *BalanceServiceImplement) GetResourceCapacityAndDemand(user *global.U
}
}
var resouceDemandLst []model.ResourceDemand
for _, resourceInfo := range resourceLi{
for _, demandInfo := range demandLstLi{
if resourceInfo.ArtId == demandInfo.ArtId{
for _, resourceInfo := range resourceLi {
for _, demandInfo := range demandLstLi {
if resourceInfo.ArtId == demandInfo.ArtId {
data_customer, err := dao_customer.SelectOne(demandInfo.CustomerId)
if err != nil {
return nil, grmi.NewDataBaseError(err)
}
resouceDemandLst = append(resouceDemandLst, model.ResourceDemand{
CustomerName: data_customer.Name1,
ArtId: demandInfo.ArtId,
Qty: demandInfo.DemandQtyMath,
ArtId: demandInfo.ArtId,
Qty: demandInfo.DemandQtyMath,
})
}
}
}
resource := secondResourceMap[resourceId]
data := model.ResourceLoad{
ResourceId: resourceId,
ResourceDesc: resource.SecondaryResource.Descr,
ResourceType: "second",
DemandTime: int(math.Ceil(timeData)),
Uom: "小时",
ResourceId: resourceId,
ResourceDesc: resource.SecondaryResource.Descr,
ResourceType: "second",
DemandTime: int(math.Ceil(timeData)),
Uom: "小时",
ResourceDemandLst: resouceDemandLst,
}
workTime, err := secondResourceSvr.CalculateResourceWorkTime(user, resourceId, start, end)
@ -420,7 +456,7 @@ func (impl *BalanceServiceImplement) CustomerOrderReviewList(user *global.User,
for _, info := range CustomerOrderReviewInfoLst {
myTime := ""
if info.ExpectedDate != nil{
if info.ExpectedDate != nil {
myTime = info.ExpectedDate.ToString()
}
resultOne, err := impl.CustomerOrderReviewOne(user, utils.ValueToString(info.Qty, ""), err, info.ArtId, info.CustomerId, myTime)
@ -488,7 +524,7 @@ func (impl *BalanceServiceImplement) CustomerOrderReviewOne(user *global.User, q
var data_ArticleResourceLst []model.ArticleResource
data_ArticleResourceLst = append(data_ArticleResourceLst, *articleResource)
data_ArticleDemand_new, err := impl.refreshMpsArticleDemand(data_ArticleStockLevel, data_ArticleDemand, data_ArticleResourceLst)
data_ArticleDemand_new, err := impl.refreshMpsArticleDemand(false, data_ArticleStockLevel, data_ArticleDemand, data_ArticleResourceLst)
if err != nil {
return nil, grmi.NewDataBaseError(err)
}
@ -507,13 +543,12 @@ func (impl *BalanceServiceImplement) CustomerOrderReviewOne(user *global.User, q
CapacityPercentage = data_resource.CapacityPercentage
}
for index, demandInfo := range data_ArticleDemand_new {
if reviewQty <= 0 {
break
}
workTime, err := impl.getWorkTime(user, articleResource.ResourceId,"", "W", demandInfo.DemandDate)
workTime, err := impl.getWorkTime(user, articleResource.ResourceId, "", "W", demandInfo.DemandDate)
if err != nil {
return nil, grmi.NewDataBaseError(err)
}
@ -672,12 +707,12 @@ func (impl *BalanceServiceImplement) CustomerOrderReviewOne(user *global.User, q
case "M":
for i := 0; i < data_customer.DeliveryFrontTime; i++ {
myTime := grmi.Date(result.ReplyDate.Restore().AddDate(0, -1, 0))
result.ReplyDate = &myTime
result.ReplyDate = &myTime
}
case "W":
for i := 0; i < data_customer.DeliveryFrontTime; i++ {
myTime := grmi.Date(result.ReplyDate.Restore().AddDate(0, 0, -7))
result.ReplyDate = &myTime
result.ReplyDate = &myTime
}
}
}
@ -721,7 +756,7 @@ func (impl *BalanceServiceImplement) CustomerOrderReviewUpload(user *global.User
case 2:
CustomerOrderReviewInfo.Qty = utils.ValueToFloat(colCell, 0.0)
case 3:
if colCell == ""{
if colCell == "" {
continue
}
demandTime, err := time.ParseInLocation("1/2/2006", colCell, utils.TimezoneLocation)
@ -747,7 +782,7 @@ func (impl *BalanceServiceImplement) CustomerOrderReviewExport(user *global.User
var inter []interface{}
for _, info := range CustomerOrderReviewInfoLst {
myTime := ""
if info.ExpectedDate != nil{
if info.ExpectedDate != nil {
myTime = info.ExpectedDate.ToString()
}
CustomerOrderReview, err := impl.CustomerOrderReviewOne(user, utils.ValueToString(info.Qty, ""), err, info.ArtId, info.CustomerId, myTime)
@ -767,7 +802,7 @@ func (impl *BalanceServiceImplement) CustomerOrderReviewExport(user *global.User
return result, err
}
func (impl *BalanceServiceImplement) refreshMpsArticleDemand(data_ArticleStockLevel []model.ArticleStockLevel, data_ArticleDemand []model.ArticleDemand, data_ArticleResource []model.ArticleResource) ([]model.ArticleDemand, error) {
func (impl *BalanceServiceImplement) refreshMpsArticleDemand(isRefresh bool,data_ArticleStockLevel []model.ArticleStockLevel, data_ArticleDemand []model.ArticleDemand, data_ArticleResource []model.ArticleResource) ([]model.ArticleDemand, error) {
for index, articleDemandInfo := range data_ArticleDemand {
//查询周期
MinCoverPeriod, MaxCoverPeriod := 0.0, 0.0
@ -814,18 +849,21 @@ func (impl *BalanceServiceImplement) refreshMpsArticleDemand(data_ArticleStockLe
//MPS 计划量 = 0
//END IF
//计算需求
for index, articleDemandInfo := range data_ArticleDemand {
needQty := articleDemandInfo.IndependentDemandQty + articleDemandInfo.OutSourcingQty + articleDemandInfo.OrderQty
if articleDemandInfo.ForecastDemandQty > articleDemandInfo.OrderQty{
needQty = articleDemandInfo.ForecastDemandQty + articleDemandInfo.OutSourcingQty + articleDemandInfo.OrderQty
for index, articleDemandInfo := range data_ArticleDemand {
needQty := articleDemandInfo.IndependentDemandQty + articleDemandInfo.OutSourcingQty + articleDemandInfo.OrderQty
if articleDemandInfo.ForecastDemandQty > articleDemandInfo.OrderQty {
needQty = articleDemandInfo.ForecastDemandQty + articleDemandInfo.OutSourcingQty + articleDemandInfo.OrderQty
}
data_ArticleDemand[index].NeedQty = needQty
}
data_ArticleDemand[index].NeedQty = needQty
}
if articleDemandInfo.OpeningInventory-articleDemandInfo.NeedQty < articleDemandInfo.MinInventory {
articleDemandInfo.NetDemandQty = articleDemandInfo.TargetInventory - (articleDemandInfo.OpeningInventory - articleDemandInfo.NeedQty)
} else {
articleDemandInfo.NetDemandQty = 0
if !isRefresh {
if articleDemandInfo.OpeningInventory-articleDemandInfo.NeedQty < articleDemandInfo.MinInventory {
articleDemandInfo.NetDemandQty = articleDemandInfo.TargetInventory - (articleDemandInfo.OpeningInventory - articleDemandInfo.NeedQty)
} else {
articleDemandInfo.NetDemandQty = 0
}
}
// 期末库存
@ -872,12 +910,6 @@ func (impl *BalanceServiceImplement) refreshMpsArticleDemand(data_ArticleStockLe
// 重置产量
func (impl *BalanceServiceImplement) resetMpsArticleDemand(data_ArticleStockLevel []model.ArticleStockLevel, data_ArticleDemand []model.ArticleDemand, cutArticleDemand *model.ArticleDemand) ([]model.ArticleDemand, error) {
//计算需求
for index, articleDemandInfo := range data_ArticleDemand {
needQty := articleDemandInfo.IndependentDemandQty + articleDemandInfo.ForecastDemandQty + articleDemandInfo.OutSourcingQty + articleDemandInfo.OrderQty
data_ArticleDemand[index].NeedQty = needQty
}
for index, articleDemandInfo := range data_ArticleDemand {
//查询周期
MinCoverPeriod, MaxCoverPeriod := 0.0, 0.0
@ -892,10 +924,8 @@ func (impl *BalanceServiceImplement) resetMpsArticleDemand(data_ArticleStockLeve
//期初库存
if index == 0 {
////todo
//articleDemandInfo.OpeningInventory = 80.0
} else {
articleDemandInfo.OpeningInventory = data_ArticleDemand[index-1].EndingInventory
//todo
data_ArticleDemand[index].OpeningInventory = 80.0
}
//最小库存水平
@ -903,7 +933,7 @@ func (impl *BalanceServiceImplement) resetMpsArticleDemand(data_ArticleStockLeve
for i := 1; i <= int(MinCoverPeriod); i++ {
now := i + index
if now < len(data_ArticleDemand) {
MinInventory += data_ArticleDemand[now].NeedQty
MinInventory += data_ArticleDemand[now].ForecastDemandQty
}
}
articleDemandInfo.MinInventory = MinInventory
@ -913,7 +943,7 @@ func (impl *BalanceServiceImplement) resetMpsArticleDemand(data_ArticleStockLeve
for i := 1; i <= int(MaxCoverPeriod); i++ {
now := i + index
if now < len(data_ArticleDemand) {
TargetInventory += data_ArticleDemand[now].NeedQty
TargetInventory += data_ArticleDemand[now].ForecastDemandQty
}
}
articleDemandInfo.TargetInventory = TargetInventory
@ -925,6 +955,15 @@ func (impl *BalanceServiceImplement) resetMpsArticleDemand(data_ArticleStockLeve
//不触发生产
//MPS 计划量 = 0
//END IF
//计算需求
for index, articleDemandInfo := range data_ArticleDemand {
needQty := articleDemandInfo.IndependentDemandQty + articleDemandInfo.OutSourcingQty + articleDemandInfo.OrderQty
if articleDemandInfo.ForecastDemandQty > articleDemandInfo.OrderQty {
needQty = articleDemandInfo.ForecastDemandQty + articleDemandInfo.OutSourcingQty + articleDemandInfo.OrderQty
}
data_ArticleDemand[index].NeedQty = needQty
}
if articleDemandInfo.OpeningInventory-articleDemandInfo.NeedQty < articleDemandInfo.MinInventory {
articleDemandInfo.NetDemandQty = articleDemandInfo.TargetInventory - (articleDemandInfo.OpeningInventory - articleDemandInfo.NeedQty)
} else {
@ -932,7 +971,7 @@ func (impl *BalanceServiceImplement) resetMpsArticleDemand(data_ArticleStockLeve
}
// 重设mps产量
if articleDemandInfo.PlantNr == cutArticleDemand.PlantNr && articleDemandInfo.ArtId == articleDemandInfo.ArtId && articleDemandInfo.DemandKey == cutArticleDemand.DemandKey {
if articleDemandInfo.PlantNr == cutArticleDemand.PlantNr && articleDemandInfo.ArtId == cutArticleDemand.ArtId && articleDemandInfo.DemandKey == cutArticleDemand.DemandKey {
articleDemandInfo.NetDemandQty = cutArticleDemand.NetDemandQty
}
@ -943,11 +982,16 @@ func (impl *BalanceServiceImplement) resetMpsArticleDemand(data_ArticleStockLeve
data_ArticleDemand[index].TargetInventory = articleDemandInfo.TargetInventory
data_ArticleDemand[index].NetDemandQty = articleDemandInfo.NetDemandQty
data_ArticleDemand[index].EndingInventory = articleDemandInfo.EndingInventory
if index != len(data_ArticleDemand)-1 {
data_ArticleDemand[index+1].OpeningInventory = data_ArticleDemand[index].EndingInventory
}
}
return data_ArticleDemand, nil
}
func (impl *BalanceServiceImplement) GetMpsPlan(user *global.User, resouceId,secondresourceid string) ([]model.ArticleResourceMpsGroup, error) {
func (impl *BalanceServiceImplement) GetMpsPlan(user *global.User, resouceId, secondresourceid string) ([]model.ArticleResourceMpsGroup, error) {
grmi.Log(user, "/services/ap/implments/Balance.service.impl.go", "GetMpsPlan", "GetMpsPlan")
@ -1003,7 +1047,20 @@ func (impl *BalanceServiceImplement) GetMpsPlan(user *global.User, resouceId,sec
}
}
selectArticleDemandList, err = impl.refreshMpsArticleDemand(data_ArticleStockLevel, selectArticleDemandList, data_ArticleResource)
for index, selectArticleDemandInfo := range selectArticleDemandList {
for _, articleDemandInfo := range alldata_Article {
if selectArticleDemandInfo.ArtId == articleDemandInfo.ArtId {
// todo
if articleDemandInfo.MidBatchQuantity == 0 {
articleDemandInfo.MidBatchQuantity = 20
}
selectArticleDemandList[index].MidBatchQuantity = articleDemandInfo.MidBatchQuantity
break
}
}
}
selectArticleDemandList, err = impl.refreshMpsArticleDemand(false,data_ArticleStockLevel, selectArticleDemandList, data_ArticleResource)
if err != nil || selectArticleDemandList == nil {
return nil, err
}
@ -1014,7 +1071,7 @@ func (impl *BalanceServiceImplement) GetMpsPlan(user *global.User, resouceId,sec
TimeType: selectArticleDemandList[0].DemandPeriodType,
DemandKey: selectArticleDemandList[0].DemandKey,
}
workTime, err := impl.getWorkTime(user, resouceId,secondresourceid, mpsGroupInfo.TimeType, mpsGroupInfo.Time)
workTime, err := impl.getWorkTime(user, resouceId, secondresourceid, mpsGroupInfo.TimeType, mpsGroupInfo.Time)
if err != nil {
return nil, err
}
@ -1037,7 +1094,7 @@ func (impl *BalanceServiceImplement) GetMpsPlan(user *global.User, resouceId,sec
TimeType: selectArticleDemandInfo.DemandPeriodType,
DemandKey: selectArticleDemandInfo.DemandKey,
}
workTime, err := impl.getWorkTime(user, resouceId,secondresourceid, mpsGroupInfo.TimeType, mpsGroupInfo.Time)
workTime, err := impl.getWorkTime(user, resouceId, secondresourceid, mpsGroupInfo.TimeType, mpsGroupInfo.Time)
if err != nil {
return nil, err
}
@ -1055,7 +1112,7 @@ func (impl *BalanceServiceImplement) GetMpsPlan(user *global.User, resouceId,sec
mpsGroupLst[index].MpsGroupWorkTime += info.MpsWorkTime
}
sort.Slice(mpsGroupLst[index].ArticleDemandLst, func(i, j int) bool {
return mpsGroupLst[index].ArticleDemandLst[i].MpsWorkTime < mpsGroupLst[index].ArticleDemandLst[j].MpsWorkTime
return mpsGroupLst[index].ArticleDemandLst[i].MinCoverPeriod < mpsGroupLst[index].ArticleDemandLst[j].MinCoverPeriod
})
}
@ -1067,7 +1124,7 @@ func (impl *BalanceServiceImplement) GetMpsPlan(user *global.User, resouceId,sec
return mpsGroupLst, err
}
func (impl *BalanceServiceImplement) MpsPlan(user *global.User, resouceId,secondresourceid string, mpsType int, mpsPlan *model.MpsPlan) (*model.MpsPlan, error) {
func (impl *BalanceServiceImplement) MpsPlan(user *global.User, resouceId, secondresourceid string, mpsType int, mpsPlan *model.MpsPlan,selectArticleDemandList []model.ArticleDemand) (*model.MpsPlan, error) {
grmi.Log(user, "/services/ap/implments/Balance.service.impl.go", "MpsPlan", "MpsPlan")
@ -1075,9 +1132,9 @@ func (impl *BalanceServiceImplement) MpsPlan(user *global.User, resouceId,second
session := engine.NewSession()
defer session.Close()
var finalResouceId string
if resouceId!=""{
if resouceId != "" {
finalResouceId = resouceId
}else{
} else {
finalResouceId = secondresourceid
}
@ -1102,6 +1159,81 @@ func (impl *BalanceServiceImplement) MpsPlan(user *global.User, resouceId,second
return nil, grmi.NewDataBaseError(err)
}
if selectArticleDemandList!= nil{
mpsPlan = new(model.MpsPlan)
mpsPlan.ArticleResourceMpsGroupLst = make([]model.ArticleResourceMpsGroup,0)
for index, selectArticleDemandInfo := range selectArticleDemandList {
for _, articleDemandInfo := range alldata_Article {
if selectArticleDemandInfo.ArtId == articleDemandInfo.ArtId {
// todo
if articleDemandInfo.MidBatchQuantity == 0 {
articleDemandInfo.MidBatchQuantity = 20
}
selectArticleDemandList[index].MidBatchQuantity = articleDemandInfo.MidBatchQuantity
break
}
}
}
selectArticleDemandList, err = impl.refreshMpsArticleDemand(false,data_ArticleStockLevel, selectArticleDemandList, data_ArticleResource)
if err != nil || selectArticleDemandList == nil {
return nil, err
}
// mps分组
mpsGroupInfo := &model.ArticleResourceMpsGroup{
Time: selectArticleDemandList[0].DemandDate,
TimeType: selectArticleDemandList[0].DemandPeriodType,
DemandKey: selectArticleDemandList[0].DemandKey,
}
workTime, err := impl.getWorkTime(user, resouceId, secondresourceid, mpsGroupInfo.TimeType, mpsGroupInfo.Time)
if err != nil {
return nil, err
}
mpsGroupInfo.ResourceWorkTime = math.Ceil(workTime)
mpsGroupInfo.ArticleDemandLst = append(mpsGroupInfo.ArticleDemandLst, selectArticleDemandList[0])
mpsPlan.ArticleResourceMpsGroupLst = append(mpsPlan.ArticleResourceMpsGroupLst, *mpsGroupInfo)
mpsIndex := 0
for selectIndex, selectArticleDemandInfo := range selectArticleDemandList {
if selectIndex == 0 {
continue
}
if mpsPlan.ArticleResourceMpsGroupLst[mpsIndex].DemandKey == selectArticleDemandInfo.DemandKey {
mpsPlan.ArticleResourceMpsGroupLst[mpsIndex].ArticleDemandLst = append(mpsPlan.ArticleResourceMpsGroupLst[mpsIndex].ArticleDemandLst, selectArticleDemandInfo)
} else {
mpsGroupInfo := &model.ArticleResourceMpsGroup{
Time: selectArticleDemandInfo.DemandDate,
TimeType: selectArticleDemandInfo.DemandPeriodType,
DemandKey: selectArticleDemandInfo.DemandKey,
}
workTime, err := impl.getWorkTime(user, resouceId, secondresourceid, mpsGroupInfo.TimeType, mpsGroupInfo.Time)
if err != nil {
return nil, err
}
mpsGroupInfo.ResourceWorkTime = math.Ceil(workTime)
mpsGroupInfo.ArticleDemandLst = append(mpsGroupInfo.ArticleDemandLst, selectArticleDemandInfo)
mpsPlan.ArticleResourceMpsGroupLst = append(mpsPlan.ArticleResourceMpsGroupLst, *mpsGroupInfo)
mpsIndex += 1
}
}
// 柱排序
for index, mpsGroupInfo := range mpsPlan.ArticleResourceMpsGroupLst {
for _, info := range mpsGroupInfo.ArticleDemandLst {
mpsPlan.ArticleResourceMpsGroupLst[index].MpsGroupWorkTime += info.MpsWorkTime
}
sort.Slice(mpsPlan.ArticleResourceMpsGroupLst[index].ArticleDemandLst, func(i, j int) bool {
return mpsPlan.ArticleResourceMpsGroupLst[index].ArticleDemandLst[i].MinCoverPeriod < mpsPlan.ArticleResourceMpsGroupLst[index].ArticleDemandLst[j].MinCoverPeriod
})
}
}
switch mpsType {
case 1:
// 有效产能约束
@ -1143,120 +1275,117 @@ func (impl *BalanceServiceImplement) MpsPlan(user *global.User, resouceId,second
}
case 5:
}
// 统计
for index, mpsGroupInfo := range mpsPlan.ArticleResourceMpsGroupLst {
mpsPlan.ArticleResourceMpsGroupLst[index].MpsGroupWorkTime = 0
for _, info := range mpsGroupInfo.ArticleDemandLst {
mpsPlan.ArticleResourceMpsGroupLst[index].MpsGroupWorkTime += info.MpsWorkTime
}
}
for _, groupArticleInfo := range mpsPlan.ArticleResourceMpsGroupLst{
mpsPlan.ArticleDemandLst = append(mpsPlan.ArticleDemandLst, groupArticleInfo.ArticleDemandLst ...)
}
return mpsPlan, err
}
func (impl *BalanceServiceImplement) MpsPlanFit(user *global.User, mpsPlan *model.MpsPlan, data_ArticleAlternativeResource []model.ArticleAlternativeResource, data_ArticleStockLevel []model.ArticleStockLevel, data_ArticleResource []model.ArticleResource) (*model.MpsPlan, error) {
var err error
for _, mpsGroupInfo := range mpsPlan.ArticleResourceMpsGroupLst {
//超出量
outWorkTime := mpsGroupInfo.MpsGroupWorkTime - mpsGroupInfo.ResourceWorkTime
var outArticleDemandLst []model.ArticleDemand // 过量列表
nowWorkTime := 0.0
for _, ArticleDemandInfo := range mpsGroupInfo.ArticleDemandLst {
nowWorkTime += ArticleDemandInfo.MpsWorkTime
if nowWorkTime > mpsGroupInfo.ResourceWorkTime {
outArticleDemandLst = append(outArticleDemandLst, ArticleDemandInfo)
if len(outArticleDemandLst)-1 == 0 {
outTimeOne := nowWorkTime - mpsGroupInfo.ResourceWorkTime
outArticleDemandLst[len(outArticleDemandLst)-1].MpsWorkTime = outArticleDemandLst[len(outArticleDemandLst)-1].MpsWorkTime - outTimeOne
}
}
}
//过量转移
for _, outArticleDemandInfo := range outArticleDemandLst {
if outWorkTime < 0 {
break
}
//替代资源
var AlternativeResourceIdLst []model.ArticleAlternativeResource
for _, articleAlternativeResourceInfo := range data_ArticleAlternativeResource {
if articleAlternativeResourceInfo.ArtId == outArticleDemandInfo.ArtId {
AlternativeResourceIdLst = append(AlternativeResourceIdLst, articleAlternativeResourceInfo)
}
}
sort.Slice(AlternativeResourceIdLst, func(i, j int) bool {
return AlternativeResourceIdLst[i].Priority > AlternativeResourceIdLst[j].Priority
})
//剩余 移动
leftWorkTime := outArticleDemandInfo.MpsWorkTime
moveWorkTime := 0.0
for _, AlternativeResourceIdInfo := range AlternativeResourceIdLst {
if leftWorkTime <= 0 {
for index, mpsGroupInfo := range mpsPlan.ArticleResourceMpsGroupLst {
outWorkTime := 0.0
outWorkTime = mpsGroupInfo.MpsGroupWorkTime - mpsGroupInfo.ResourceWorkTime
for {
// 过量
if outWorkTime > 0 {
length := len(mpsGroupInfo.ArticleDemandLst)
if length == 0 {
break
}
AlternativeResourceMpsGroup, err := impl.GetMpsPlan(user, AlternativeResourceIdInfo.AlternativeResourceId,"")
if err != nil {
return nil, err
}
for _, AlternativeResourceMpsInfo := range AlternativeResourceMpsGroup {
emptyWorkTime := AlternativeResourceMpsInfo.MpsGroupWorkTime - AlternativeResourceMpsInfo.ResourceWorkTime
if emptyWorkTime < 0 {
continue
}
if leftWorkTime < emptyWorkTime {
//空余产能过剩
moveWorkTime = leftWorkTime
leftWorkTime = 0.0
} else {
//空余产能不足
moveWorkTime = leftWorkTime - emptyWorkTime
leftWorkTime = emptyWorkTime
isDelete := false
cutWorkTime := float64(mpsGroupInfo.ArticleDemandLst[length-1].MidBatchQuantity) //压缩量
if mpsGroupInfo.ArticleDemandLst[length-1].MpsWorkTime <= cutWorkTime {
cutWorkTime = mpsGroupInfo.ArticleDemandLst[length-1].MpsWorkTime
outWorkTime = outWorkTime - mpsGroupInfo.ArticleDemandLst[length-1].MpsWorkTime
isDelete = true
} else {
outWorkTime = outWorkTime - cutWorkTime
mpsGroupInfo.ArticleDemandLst[length-1].MpsWorkTime -= cutWorkTime
}
//替代资源
var AlternativeResourceIdLst []model.ArticleAlternativeResource
for _, articleAlternativeResourceInfo := range data_ArticleAlternativeResource {
if articleAlternativeResourceInfo.ArtId == mpsGroupInfo.ArticleDemandLst[length-1].ArtId {
AlternativeResourceIdLst = append(AlternativeResourceIdLst, articleAlternativeResourceInfo)
}
}
//增加
var newArticleDemandInfo *model.ArticleDemand
CopyStruct(outArticleDemandLst, newArticleDemandInfo)
newArticleDemandInfo.MpsWorkTime = moveWorkTime
sort.Slice(AlternativeResourceIdLst, func(i, j int) bool {
return AlternativeResourceIdLst[i].Priority > AlternativeResourceIdLst[j].Priority
})
mpsPlan.ArticleDemandLst, err = impl.resetMpsArticleDemand(data_ArticleStockLevel, mpsPlan.ArticleDemandLst, newArticleDemandInfo)
//剩余 移动
for _, AlternativeResourceIdInfo := range AlternativeResourceIdLst {
AlternativeResourceMpsGroup, err := impl.GetMpsPlan(user, AlternativeResourceIdInfo.AlternativeResourceId, "")
if err != nil {
return nil, err
}
for _, mpsGroupInfo := range mpsPlan.ArticleResourceMpsGroupLst {
mpsGroupInfo.ArticleDemandLst = nil
for _, dataDemandInfo := range mpsPlan.ArticleDemandLst {
if mpsGroupInfo.DemandKey == dataDemandInfo.DemandKey {
mpsGroupInfo.ArticleDemandLst = append(mpsGroupInfo.ArticleDemandLst, dataDemandInfo)
}
for _, AlternativeResourceMpsInfo := range AlternativeResourceMpsGroup {
emptyWorkTime := AlternativeResourceMpsInfo.MpsGroupWorkTime - AlternativeResourceMpsInfo.ResourceWorkTime
if emptyWorkTime < 0 {
continue
}
}
//删除
outArticleDemandInfo.MpsWorkTime -= moveWorkTime
for _, articleResourceInfo := range data_ArticleResource {
if articleResourceInfo.ArtId == outArticleDemandInfo.ArtId {
outArticleDemandInfo.NetDemandQty = outArticleDemandInfo.MpsWorkTime * articleResourceInfo.QuantityPerHour
break
if cutWorkTime < emptyWorkTime {
//空余产能过剩
} else {
//空余产能不足
continue
}
}
mpsPlan.ArticleDemandLst, err = impl.resetMpsArticleDemand(data_ArticleStockLevel, mpsPlan.ArticleDemandLst, &outArticleDemandInfo)
if err != nil {
return nil, err
}
for _, mpsGroupInfo := range mpsPlan.ArticleResourceMpsGroupLst {
mpsGroupInfo.ArticleDemandLst = nil
for _, selectArticleDemandInfo := range mpsPlan.ArticleDemandLst {
if mpsGroupInfo.DemandKey == selectArticleDemandInfo.DemandKey {
mpsGroupInfo.ArticleDemandLst = append(mpsGroupInfo.ArticleDemandLst, selectArticleDemandInfo)
//减少
for _, articleResourceInfo := range data_ArticleResource {
if articleResourceInfo.ArtId == mpsGroupInfo.ArticleDemandLst[length-1].ArtId {
mpsGroupInfo.ArticleDemandLst[length-1].NetDemandQty = mpsGroupInfo.ArticleDemandLst[length-1].MpsWorkTime * articleResourceInfo.QuantityPerHour
break
}
}
}
outWorkTime -= moveWorkTime
for _, info := range mpsGroupInfo.ArticleDemandLst {
for index2, info2 := range mpsPlan.ArticleDemandLst {
if info.DemandKey == info2.DemandKey && info.ArtId == info2.ArtId {
mpsPlan.ArticleDemandLst[index2].NetDemandQty = info.NetDemandQty
}
}
}
//增加
aj, _ := json.Marshal(mpsGroupInfo.ArticleDemandLst[length-1])
newArticleDemandInfo := new(model.ArticleDemand)
_ = json.Unmarshal(aj, newArticleDemandInfo)
mpsPlan.ArticleAlternativeDemandLst = append(mpsPlan.ArticleAlternativeDemandLst, *newArticleDemandInfo)
if isDelete {
mpsGroupInfo.ArticleDemandLst = mpsGroupInfo.ArticleDemandLst[:length-1] //删除末尾元素
}
outWorkTime -= cutWorkTime
}
}
}else{
break
}
}
mpsPlan.ArticleResourceMpsGroupLst[index] = mpsGroupInfo
}
return mpsPlan, err
}
func (impl *BalanceServiceImplement) MpsPlanConstraint(mpsPlan *model.MpsPlan, data_ArticleResource []model.ArticleResource, data_ArticleStockLevel []model.ArticleStockLevel) (*model.MpsPlan, error) {
var err error
for _, mpsGroupInfo := range mpsPlan.ArticleResourceMpsGroupLst {
for index, mpsGroupInfo := range mpsPlan.ArticleResourceMpsGroupLst {
outWorkTime := 0.0
outWorkTime = mpsGroupInfo.MpsGroupWorkTime - mpsGroupInfo.ResourceWorkTime
for {
@ -1266,44 +1395,45 @@ func (impl *BalanceServiceImplement) MpsPlanConstraint(mpsPlan *model.MpsPlan, d
if length == 0 {
break
}
topArticleDemand := mpsGroupInfo.ArticleDemandLst[length-1]
cutWorkTime := 0.0 //压缩量
if topArticleDemand.MpsWorkTime <= outWorkTime {
cutWorkTime = topArticleDemand.MpsWorkTime
outWorkTime = outWorkTime - topArticleDemand.MpsWorkTime
mpsGroupInfo.ArticleDemandLst = mpsGroupInfo.ArticleDemandLst[:length-1] //删除末尾元素
isDelete := false
cutWorkTime := float64(mpsGroupInfo.ArticleDemandLst[length-1].MidBatchQuantity) //压缩量
if mpsGroupInfo.ArticleDemandLst[length-1].MpsWorkTime <= cutWorkTime {
cutWorkTime = mpsGroupInfo.ArticleDemandLst[length-1].MpsWorkTime
outWorkTime = outWorkTime - mpsGroupInfo.ArticleDemandLst[length-1].MpsWorkTime
isDelete = true
} else {
cutWorkTime = outWorkTime
outWorkTime = 0
outWorkTime = outWorkTime - cutWorkTime
mpsGroupInfo.ArticleDemandLst[length-1].MpsWorkTime -= cutWorkTime
}
topArticleDemand.MpsWorkTime -= cutWorkTime
//压缩
for _, articleResourceInfo := range data_ArticleResource {
if articleResourceInfo.ArtId == topArticleDemand.ArtId {
topArticleDemand.NetDemandQty = topArticleDemand.MpsWorkTime * articleResourceInfo.QuantityPerHour
if articleResourceInfo.ArtId == mpsGroupInfo.ArticleDemandLst[length-1].ArtId {
mpsGroupInfo.ArticleDemandLst[length-1].NetDemandQty = mpsGroupInfo.ArticleDemandLst[length-1].MpsWorkTime * articleResourceInfo.QuantityPerHour
break
}
}
mpsPlan.ArticleDemandLst, err = impl.resetMpsArticleDemand(data_ArticleStockLevel, mpsPlan.ArticleDemandLst, &topArticleDemand)
if err != nil {
return nil, err
}
for _, mpsGroupInfo := range mpsPlan.ArticleResourceMpsGroupLst {
mpsGroupInfo.ArticleDemandLst = nil
for _, dataDemandInfo := range mpsPlan.ArticleDemandLst {
if mpsGroupInfo.DemandKey == dataDemandInfo.DemandKey {
mpsGroupInfo.ArticleDemandLst = append(mpsGroupInfo.ArticleDemandLst, dataDemandInfo)
for _, info := range mpsGroupInfo.ArticleDemandLst {
for index2, info2 := range mpsPlan.ArticleDemandLst {
if info.DemandKey == info2.DemandKey && info.ArtId == info2.ArtId {
mpsPlan.ArticleDemandLst[index2].NetDemandQty = info.NetDemandQty
}
}
}
if isDelete {
mpsGroupInfo.ArticleDemandLst = mpsGroupInfo.ArticleDemandLst[:length-1] //删除末尾元素
}
} else {
break
}
}
mpsPlan.ArticleResourceMpsGroupLst[index] = mpsGroupInfo
}
return mpsPlan, err
}
@ -1321,7 +1451,7 @@ func (impl *BalanceServiceImplement) SaveMpsPlan(user *global.User, ArticleDeman
return err
}
func (impl *BalanceServiceImplement) getWorkTime(user *global.User, resouceId,secondresourceid string, timeType string, nowtime grmi.Date) (workTime float64, err error) {
func (impl *BalanceServiceImplement) getWorkTime(user *global.User, resouceId, secondresourceid string, timeType string, nowtime grmi.Date) (workTime float64, err error) {
switch timeType {
case "Y":
@ -1329,14 +1459,14 @@ func (impl *BalanceServiceImplement) getWorkTime(user *global.User, resouceId,se
case "W":
startTime := utils.WeekDayMondayZeroTs(nowtime.Restore())
if resouceId != ""{
if resouceId != "" {
resourceSvr := NewResourceServiceImplement()
workTime, err = resourceSvr.CalculateResourceWorkTime(user, resouceId, startTime.Format(grmi.DateOutFormat), startTime.Add(time.Hour*24*7).Format(grmi.DateOutFormat))
if err != nil {
return 0, err
}
}
if secondresourceid != ""{
if secondresourceid != "" {
resourceSvr := NewSecondaryResourceServiceImplement()
workTime, err = resourceSvr.CalculateResourceWorkTime(user, resouceId, startTime.Format(grmi.DateOutFormat), startTime.Add(time.Hour*24*7).Format(grmi.DateOutFormat))
if err != nil {
@ -1364,7 +1494,7 @@ func CopyStruct(src, dst interface{}) {
}
}
func (impl *BalanceServiceImplement) RefreshBalanceData()(error){
func (impl *BalanceServiceImplement) RefreshBalanceData() error {
var err error
go func() {
@ -1378,7 +1508,6 @@ func (impl *BalanceServiceImplement) RefreshBalanceData()(error){
model_base.Mem_Customer = make([]model_base.Customer, 0)
err = session.Table("Customer").Find(&model_base.Mem_Customer)
alldata_ArticleDemand = make([]model.ArticleDemand, 0)
session.Table("AP_ArticleDemand").Find(&alldata_ArticleDemand)
@ -1387,6 +1516,9 @@ func (impl *BalanceServiceImplement) RefreshBalanceData()(error){
alldata_ArticleResource = make([]model.ArticleResource, 0)
session.Table("AP_ArticleResource").Find(&alldata_ArticleResource)
alldata_Article = make([]model_base.Article, 0)
session.Table("Article").Find(&alldata_Article)
}()
return err


+ 23
- 0
web/controllers/ap/ArticleResource.rest.go View File

@ -193,6 +193,29 @@ func RegisterSelectOneArticleResource(party router.Party, path string, method fu
})
}
func RegisterSearchArticleResource(party router.Party, path string, method func(*global.User, string) (*model.ArticleResource, error)) {
party.Get(path+"/{artId:string}", func(ctx iris.Context) {
user, ok := jwts.ParseToken(ctx)
if !ok {
supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil)
return
}
artId := ctx.Params().GetString("artId")
result, err := method(user, artId)
if err != nil {
supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil)
return
}
if result == nil {
supports.Error(ctx, iris.StatusNotFound, supports.NotFound, nil)
return
}
supports.Ok(ctx, supports.OptionSuccess, result)
})
}
/******************************************************************************
*
* @Function Name : RegisterUpdateOneArticleResource


+ 72
- 10
web/controllers/ap/Balance.rest.go View File

@ -545,12 +545,12 @@ func RegisterGetMpsPlan(party router.Party, path string, method func(*global.Use
})
}
func RegisterMpsPlan(party router.Party, path string, method func(user *global.User,resouceId,secondresourceid string,mpsType int,mpsPlan *model.MpsPlan) (*model.MpsPlan,error)) {
func RegisterMpsPlan(party router.Party, path string, method func(user *global.User,resouceId,secondresourceid string,mpsType int,mpsPlan *model.MpsPlan,selectArticleDemandList []model.ArticleDemand) (*model.MpsPlan,error)) {
RegisterMpsPlanFunc(party, "POST", path, method)
}
func RegisterMpsPlanFunc(party router.Party, httpMethod string, path string, method func(user *global.User,resouceId,secondresourceid string,mpsType int,mpsPlan *model.MpsPlan) (*model.MpsPlan,error)) {
func RegisterMpsPlanFunc(party router.Party, httpMethod string, path string, method func(user *global.User,resouceId,secondresourceid string,mpsType int,mpsPlan *model.MpsPlan,selectArticleDemandList []model.ArticleDemand) (*model.MpsPlan,error)) {
party.Handle(httpMethod, path, func(ctx iris.Context) {
user, ok := jwts.ParseToken(ctx)
@ -564,18 +564,25 @@ func RegisterMpsPlanFunc(party router.Party, httpMethod string, path string, met
entitys := new(model.MpsPlan)
info := ctx.FormValue("data")
err := json.Unmarshal([]byte(info), &entitys)
if err != nil {
supports.Error(ctx, iris.StatusBadRequest, "json解析错误:"+err.Error(), nil)
return
if info != "" {
err := json.Unmarshal([]byte(info), &entitys)
if err != nil {
supports.Error(ctx, iris.StatusBadRequest, "json解析错误:"+err.Error(), nil)
return
}
}
if entitys == nil {
supports.Error(ctx, iris.StatusBadRequest, "抱歉未找到原有信息:"+err.Error(), nil)
return
selectArticleDemandList := new(model.MpsPlan_DemandList)
info2 := ctx.FormValue("demandlistdata")
if info2 != ""{
err2 := json.Unmarshal([]byte(info2), &selectArticleDemandList)
if err2 != nil {
supports.Error(ctx, iris.StatusBadRequest, "json解析错误:"+err2.Error(), nil)
return
}
}
result, err := method(user, resouceId,secondresourceid, utils.ValueToInt(mpsType,0), entitys)
result, err := method(user, resouceId,secondresourceid, utils.ValueToInt(mpsType,0), entitys, selectArticleDemandList.ArticleDemandLst)
if err != nil {
supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil)
return
@ -627,4 +634,59 @@ func RegisterRefreshData(party router.Party, path string, method func() error) {
}
supports.Ok(ctx, supports.OptionSuccess, nil)
})
}
func RegisterSaveBalance(party router.Party, path string, method func(*global.User, *[]model.ArticleDemand) error) {
party.Handle("POST", path, func(ctx iris.Context) {
user, ok := jwts.ParseToken(ctx)
if !ok {
supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil)
return
}
entities := make([]model.ArticleDemand, 0, 10)
err := ctx.ReadJSON(&entities)
if err != nil {
supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil)
return
}
err = method(user, &entities)
if err != nil {
supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil)
return
}
supports.Ok(ctx, supports.OptionSuccess, nil)
})
}
func RegisterRefreshBalance(party router.Party, path string, method func(*global.User, *[]model.ArticleDemand)([]model.ArticleDemand, error)){
party.Handle("POST", path, func(ctx iris.Context) {
user, ok := jwts.ParseToken(ctx)
if !ok {
supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil)
return
}
entities := make([]model.ArticleDemand, 0, 10)
err := ctx.ReadJSON(&entities)
if err != nil {
supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil)
return
}
result, err := method(user, &entities)
if err != nil {
supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil)
return
}
if result == nil {
supports.Error(ctx, iris.StatusNotFound, supports.NotFound, nil)
return
}
supports.Ok(ctx, supports.OptionSuccess, result)
})
}

+ 3
- 0
web/controllers/ap/ap.go View File

@ -347,6 +347,7 @@ func RegisterRoutes() {
RegisterUpdateOneArticleResource(articleresource, "/updateone", serviceOfArticleResource.UpdateOne)
// ArticleResource修改多条
// RegisterUpdateArticleResource(articleresource, "/update", serviceOfArticleResource.Update)
RegisterSearchArticleResource(articleresource, "/search", serviceOfArticleResource.Search)
// ArticleAlternativeResource的路由组
articlealternativeresource := party.Party("/articlealternativeresource")
@ -544,6 +545,8 @@ func RegisterRoutes() {
balance := party.Party("/balance")
var balanceService = svr.NewBalanceService()
RegisterSelectOneBalance(balance, "/getcustomerarticledemand", balanceService.GetCustomerArticleDemand)
RegisterSaveBalance(balance, "/savecustomerarticledemand", balanceService.SaveCustomerArticleDemand)
RegisterRefreshBalance(balance, "/refreshcustomerarticledemand", balanceService.RefreshCustomerArticleDemand)
RegisterSelectBalance(balance, "/getresourcecapacityanddemand", balanceService.GetResourceCapacityAndDemand)
RegisterCustomerOrderReview(balance, "/customerorderreview", balanceService.CustomerOrderReview)
RegisterCustomerOrderReviewList(balance, "/customerorderreviewlist", balanceService.CustomerOrderReviewList)


Loading…
Cancel
Save