Browse Source

mps erp修改

pull/142/head
DESKTOP-4672LME\Xu Tengfei 3 years ago
parent
commit
7e5eace9bf
11 changed files with 8791 additions and 281 deletions
  1. +3
    -1
      meta/ap/MpsSetting.meta.go
  2. +1
    -0
      models/ap/MpsSetting.model.go
  3. +182
    -117
      services/ap/implments/Balance.service.impl.go
  4. +1
    -0
      services/ap/implments/MpsSetting.service.impl.go
  5. +80
    -151
      services/erp/erp.go
  6. +4
    -1
      task/k3cloud.go
  7. +3
    -3
      utils/k3cloud/service/PRD_MO.go
  8. +1
    -1
      utils/k3cloud/service/PUR_PurchaseOrder.go
  9. +1
    -1
      utils/k3cloud/service/sal_saleorder.go
  10. +8515
    -0
      utils/k3cloud/table/SAL_XORDER.json
  11. +0
    -6
      web/controllers/ap/ap.go

+ 3
- 1
meta/ap/MpsSetting.meta.go View File

@ -35,6 +35,7 @@ var MpsSetting_DefaultMaxCoverPeriodType = grmi.NewField("DefaultMaxCoverPeriodT
var MpsSetting_LastModify = grmi.NewField("LastModify", "[AP_MpsSetting].LastModify", "lastmodify", grmi.TypeDateTime)
var MpsSetting_LastUser = grmi.NewField("LastUser", "[AP_MpsSetting].LastUser", "lastuser", grmi.TypeString)
var MpsSetting_CreateTime = grmi.NewField("CreateTime", "[AP_MpsSetting].CreateTime", "createtime", grmi.TypeDateTime)
var MpsSetting_SalesOrderFetchLeadTimeByDay = grmi.NewField("SalesOrderFetchLeadTimeByDay", "[AP_MpsSetting].SalesOrderFetchLeadTimeByDay", "salesorderfetchleadtimebyday", grmi.TypeInt)
/******************************************************************************
*
@ -68,6 +69,7 @@ var MpsSetting = grmi.NewEntity(
MpsSetting_LastModify.Name: MpsSetting_LastModify,
MpsSetting_LastUser.Name: MpsSetting_LastUser,
MpsSetting_CreateTime.Name: MpsSetting_CreateTime,
MpsSetting_SalesOrderFetchLeadTimeByDay.Name: MpsSetting_SalesOrderFetchLeadTimeByDay,
},
[]string{"PlantNr"},
[]string{"Descr", "MpsRule", "MpsStartDaysDeviation", "MpsStartWeeksDeviation", "MpsStartMonthsDeviation", "UseCustDemandLockToggle", "DefaultLockDays", "DefaultLockWeeks", "DefaultLockMonths", "UseFixedStockCoverToggle", "DefaultMinCoverPeriod", "DefaultMaxCoverPeriod", "DefaultMinCoverPeriodType", "DefaultMaxCoverPeriodType", "LastUser"})
[]string{"Descr", "MpsRule", "MpsStartDaysDeviation", "MpsStartWeeksDeviation", "MpsStartMonthsDeviation", "UseCustDemandLockToggle", "DefaultLockDays", "DefaultLockWeeks", "DefaultLockMonths", "UseFixedStockCoverToggle", "DefaultMinCoverPeriod", "DefaultMaxCoverPeriod", "DefaultMinCoverPeriodType", "DefaultMaxCoverPeriodType", "LastUser","SalesOrderFetchLeadTimeByDay"})

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

@ -39,6 +39,7 @@ type MpsSetting struct {
LastModify grmi.DateTime `xorm:"datetime 'LastModify' not null updated" json:"AP_MpsSetting-LastModify"`
LastUser string `xorm:"nvarchar(20) 'LastUser' not null" json:"AP_MpsSetting-LastUser"`
CreateTime grmi.DateTime `xorm:"datetime 'CreateTime' not null created" json:"AP_MpsSetting-CreateTime"`
SalesOrderFetchLeadTimeByDay int `xorm:"int 'SalesOrderFetchLeadTimeByDay' not null" json:"AP_MpsSetting-SalesOrderFetchLeadTimeByDay"`
}
/******************************************************************************


+ 182
- 117
services/ap/implments/Balance.service.impl.go View File

@ -142,7 +142,11 @@ func (impl *BalanceServiceImplement) GetCustomerArticleDemand(user *global.User,
return nil, grmi.NewDataBaseError(err)
}
data_ArticleStockLevel, err := dao_ArticleStockLevel.Select([]grmi.Predicate{meta.ArticleStockLevel_PlantNr.NewPredicate(grmi.Equal, user.PlantNr)}, nil)
data_ArticleStock, err := dao_ArticleStock.Select([]grmi.Predicate{}, nil)
if err != nil {
return nil, grmi.NewDataBaseError(err)
}
data_ArticleStockLevel, err := dao_ArticleStockLevel.Select([]grmi.Predicate{}, nil)
if err != nil {
return nil, grmi.NewDataBaseError(err)
}
@ -167,19 +171,12 @@ func (impl *BalanceServiceImplement) GetCustomerArticleDemand(user *global.User,
}
for _, artStockInfo := range artStockList {
if artStockInfo.ArtId == artInfo.ArtId {
switch artStockInfo.StockType {
case "FG":
custArtStockInfo.FGStock = artStockInfo.FGQty
case "SFG":
custArtStockInfo.SFGStock = artStockInfo.SFGQty
case "WIP":
custArtStockInfo.WIPStock = artStockInfo.WIPQty
case "PUC":
custArtStockInfo.PUCStock = artStockInfo.PUCQty
case "OSC":
custArtStockInfo.OSCStock = artStockInfo.OSCQty
}
break
break
}
}
data = append(data, custArtStockInfo)
@ -210,7 +207,7 @@ func (impl *BalanceServiceImplement) GetCustomerArticleDemand(user *global.User,
//if err != nil {
// return nil, grmi.NewDataBaseError(err)
//}
data_ArticleDemand_new, err := impl.refreshMpsArticleDemand(false, data_ArticleStockLevel, data_ArticleDemand, data_ArticleResourceLst, mpsSettingOne)
data_ArticleDemand_new, err := impl.refreshMpsArticleDemand(false, data_ArticleStock, data_ArticleStockLevel, data_ArticleDemand, data_ArticleResourceLst, mpsSettingOne)
if err != nil {
return nil, grmi.NewDataBaseError(err)
}
@ -230,6 +227,22 @@ func (impl *BalanceServiceImplement) GetCustomerArticleDemand(user *global.User,
}
data = data[:size]
var keyList []string
for _, info:= range data{
for _, key := range info.ArticleDemandLst{
isIn:= false
for _, keyNow := range keyList{
if key.DemandKey == keyNow{
isIn = true
break
}
}
if !isIn{
keyList = append(keyList, key.DemandKey)
}
}
}
sort.Strings(keyList)
//var CustArtStockItemLst []model.CustArtStockItem
var CustArtStockaLL model.CustArtStockItem
CustArtStockaLL.ItemLst = *new([]map[string]string)
@ -245,10 +258,10 @@ func (impl *BalanceServiceImplement) GetCustomerArticleDemand(user *global.User,
CustArtStockaLL.SortKeys = append(CustArtStockaLL.SortKeys, "AP_ArticleDemand-Descr1")
//CustArtStockaLL.SortKeys = append(CustArtStockaLL.SortKeys, "AP_ArticleDemand-CustomerId")
CustArtStockaLL.SortKeys = append(CustArtStockaLL.SortKeys, "AP_ArticleDemand-FGStock")
CustArtStockaLL.SortKeys = append(CustArtStockaLL.SortKeys, "AP_ArticleDemand-SFGStock")
//CustArtStockaLL.SortKeys = append(CustArtStockaLL.SortKeys, "AP_ArticleDemand-SFGStock")
CustArtStockaLL.SortKeys = append(CustArtStockaLL.SortKeys, "AP_ArticleDemand-WIPStock")
CustArtStockaLL.SortKeys = append(CustArtStockaLL.SortKeys, "AP_ArticleDemand-PUCStock")
CustArtStockaLL.SortKeys = append(CustArtStockaLL.SortKeys, "AP_ArticleDemand-OSCStock")
//CustArtStockaLL.SortKeys = append(CustArtStockaLL.SortKeys, "AP_ArticleDemand-OSCStock")
}
CustArtStockItem.ItemLst[i]["AP_ArticleDemand-ArtId"] = info.ArtId
@ -256,16 +269,27 @@ func (impl *BalanceServiceImplement) GetCustomerArticleDemand(user *global.User,
CustArtStockItem.ItemLst[i]["AP_ArticleDemand-Descr1"] = info.Descr1
//CustArtStockItem.ItemLst[i]["AP_ArticleDemand-CustomerId"] = info.CustomerId
CustArtStockItem.ItemLst[i]["AP_ArticleDemand-FGStock"] = utils.FloatToString(info.FGStock, 2)
CustArtStockItem.ItemLst[i]["AP_ArticleDemand-SFGStock"] = utils.FloatToString(info.SFGStock, 2)
//CustArtStockItem.ItemLst[i]["AP_ArticleDemand-SFGStock"] = utils.FloatToString(info.SFGStock, 2)
CustArtStockItem.ItemLst[i]["AP_ArticleDemand-WIPStock"] = utils.FloatToString(info.WIPStock, 2)
CustArtStockItem.ItemLst[i]["AP_ArticleDemand-PUCStock"] = utils.FloatToString(info.PUCStock, 2)
CustArtStockItem.ItemLst[i]["AP_ArticleDemand-OSCStock"] = utils.FloatToString(info.OSCStock, 2)
//CustArtStockItem.ItemLst[i]["AP_ArticleDemand-OSCStock"] = utils.FloatToString(info.OSCStock, 2)
for _,key := range keyList{
var detail *model.ArticleDemand
for _, nowDetail := range info.ArticleDemandLst {
if nowDetail.DemandKey == key{
detail = &nowDetail
break
}
}
if detail == nil{
detail = new(model.ArticleDemand)
detail.DemandKey = key
}
for _, detail := range info.ArticleDemandLst {
if i == 0 && index == 0 {
CustArtStockaLL.SortKeys = append(CustArtStockaLL.SortKeys, detail.DemandKey)
}
switch i {
case 0:
CustArtStockItem.ItemLst[i]["AP_ArticleDemand-Label"] = "AP_ArticleDemand-NetDemandQty"
@ -298,11 +322,8 @@ func (impl *BalanceServiceImplement) GetCustomerArticleDemand(user *global.User,
CustArtStockItem.ItemLst[i]["AP_ArticleDemand-Label"] = "AP_ArticleDemand-EndingInventory"
CustArtStockItem.ItemLst[i][detail.DemandKey] = utils.FloatToString(detail.EndingInventory, 2)
}
//CustArtStockItem.CustArtStockDetail["Label"] = *new(model.ArticleDemand)
//CustArtStockItem.ItemLst[i][detail.DemandKey] = utils.ValueToString(detail.NetDemandQty, "")
//CustArtStockItem.CustArtStockDetail[detail.DemandKey] = detail
}
}
CustArtStockaLL.ItemLst = append(CustArtStockaLL.ItemLst, CustArtStockItem.ItemLst...)
}
@ -319,7 +340,7 @@ func (impl *BalanceServiceImplement) RefreshCustomerArticleDemand(user *global.U
//dao_CustArtlst := dal.NewCustArtlstDAO(session, user.PlantNr, user.UserId)
dao_ArticleDemand := dal.NewArticleDemandDAO(session, user.PlantNr, user.UserId)
dao_ArticleStock := dal_base.NewArticleStockDAO(session, user.PlantNr, user.UserId)
dao_ArticleStockLevel := dal.NewArticleStockLevelDAO(session, user.PlantNr, user.UserId)
//dao_ArticleStockLevel := dal.NewArticleStockLevelDAO(session, user.PlantNr, user.UserId)
artResourceDao := dal.NewArticleResourceDAO(session, user.PlantNr, user.UserId)
//dao_CustDemandModel := dal.NewCustDemandModelDAO(session, user.PlantNr, user.UserId)
//dao_Customer := dal_base.NewCustomerDAO(session, user.PlantNr, user.UserId)
@ -350,7 +371,12 @@ func (impl *BalanceServiceImplement) RefreshCustomerArticleDemand(user *global.U
return nil, nil, grmi.NewDataBaseError(err)
}
data_ArticleStockLevel, err := dao_ArticleStockLevel.Select([]grmi.Predicate{meta.ArticleStockLevel_PlantNr.NewPredicate(grmi.Equal, user.PlantNr)}, nil)
dao_ArticleStockLevel := dal.NewArticleStockLevelDAO(session, user.PlantNr, user.UserId)
data_ArticleStockLevel, err := dao_ArticleStockLevel.Select([]grmi.Predicate{}, nil)
if err != nil {
return nil, nil, grmi.NewDataBaseError(err)
}
data_ArticleStock, err := dao_ArticleStock.Select([]grmi.Predicate{meta.ArticleStockLevel_PlantNr.NewPredicate(grmi.Equal, user.PlantNr)}, nil)
if err != nil {
return nil, nil, grmi.NewDataBaseError(err)
}
@ -453,7 +479,7 @@ func (impl *BalanceServiceImplement) RefreshCustomerArticleDemand(user *global.U
}
}
data_ArticleDemand_new, err := impl.refreshMpsArticleDemand(true, data_ArticleStockLevel, data_ArticleDemand, data_ArticleResourceLst, mpsSettingOne)
data_ArticleDemand_new, err := impl.refreshMpsArticleDemand(true, data_ArticleStock,data_ArticleStockLevel, data_ArticleDemand, data_ArticleResourceLst, mpsSettingOne)
if err != nil {
return nil, nil, grmi.NewDataBaseError(err)
}
@ -480,18 +506,11 @@ func (impl *BalanceServiceImplement) RefreshCustomerArticleDemand(user *global.U
}
for _, artStockInfo := range artStockList {
if artStockInfo.ArtId == ArtId {
switch artStockInfo.StockType {
case "FG":
custArtStockInfo.FGStock = artStockInfo.FGQty
case "SFG":
custArtStockInfo.SFGStock = artStockInfo.SFGQty
case "WIP":
custArtStockInfo.WIPStock = artStockInfo.WIPQty
case "PUC":
custArtStockInfo.PUCStock = artStockInfo.PUCQty
case "OSC":
custArtStockInfo.OSCStock = artStockInfo.OSCQty
}
custArtStockInfo.FGStock = artStockInfo.FGQty
custArtStockInfo.SFGStock = artStockInfo.SFGQty
custArtStockInfo.WIPStock = artStockInfo.WIPQty
custArtStockInfo.PUCStock = artStockInfo.PUCQty
custArtStockInfo.OSCStock = artStockInfo.OSCQty
break
}
}
@ -514,10 +533,10 @@ func (impl *BalanceServiceImplement) RefreshCustomerArticleDemand(user *global.U
CustArtStockaLL.SortKeys = append(CustArtStockaLL.SortKeys, "AP_ArticleDemand-Descr1")
//CustArtStockaLL.SortKeys = append(CustArtStockaLL.SortKeys, "AP_ArticleDemand-CustomerId")
CustArtStockaLL.SortKeys = append(CustArtStockaLL.SortKeys, "AP_ArticleDemand-FGStock")
CustArtStockaLL.SortKeys = append(CustArtStockaLL.SortKeys, "AP_ArticleDemand-SFGStock")
//CustArtStockaLL.SortKeys = append(CustArtStockaLL.SortKeys, "AP_ArticleDemand-SFGStock")
CustArtStockaLL.SortKeys = append(CustArtStockaLL.SortKeys, "AP_ArticleDemand-WIPStock")
CustArtStockaLL.SortKeys = append(CustArtStockaLL.SortKeys, "AP_ArticleDemand-PUCStock")
CustArtStockaLL.SortKeys = append(CustArtStockaLL.SortKeys, "AP_ArticleDemand-OSCStock")
//CustArtStockaLL.SortKeys = append(CustArtStockaLL.SortKeys, "AP_ArticleDemand-OSCStock")
}
CustArtStockItem.ItemLst[i]["AP_ArticleDemand-ArtId"] = info.ArtId
@ -525,10 +544,10 @@ func (impl *BalanceServiceImplement) RefreshCustomerArticleDemand(user *global.U
CustArtStockItem.ItemLst[i]["AP_ArticleDemand-Descr1"] = info.Descr1
//CustArtStockItem.ItemLst[i]["AP_ArticleDemand-CustomerId"] = info.CustomerId
CustArtStockItem.ItemLst[i]["AP_ArticleDemand-FGStock"] = utils.FloatToString(info.FGStock, 2)
CustArtStockItem.ItemLst[i]["AP_ArticleDemand-SFGStock"] = utils.FloatToString(info.SFGStock, 2)
//CustArtStockItem.ItemLst[i]["AP_ArticleDemand-SFGStock"] = utils.FloatToString(info.SFGStock, 2)
CustArtStockItem.ItemLst[i]["AP_ArticleDemand-WIPStock"] = utils.FloatToString(info.WIPStock, 2)
CustArtStockItem.ItemLst[i]["AP_ArticleDemand-PUCStock"] = utils.FloatToString(info.PUCStock, 2)
CustArtStockItem.ItemLst[i]["AP_ArticleDemand-OSCStock"] = utils.FloatToString(info.OSCStock, 2)
//CustArtStockItem.ItemLst[i]["AP_ArticleDemand-OSCStock"] = utils.FloatToString(info.OSCStock, 2)
for _, detail := range info.ArticleDemandLst {
if i == 0 && index == 0 {
@ -1063,6 +1082,8 @@ func (impl *BalanceServiceImplement) CustomerOrderReviewOne(user *global.User, q
dao_CustDemandModel := dal.NewCustDemandModelDAO(session, user.PlantNr, user.UserId)
dao_Customer := dal_base.NewCustomerDAO(session, user.PlantNr, user.UserId)
dao_MpsSetting := dal.NewMpsSettingDAO(session, user.PlantNr, user.UserId)
dao_ArticleStock := dal_base.NewArticleStockDAO(session, user.PlantNr, user.UserId)
dao_ArticleStockLevel := dal.NewArticleStockLevelDAO(session, user.PlantNr, user.UserId)
data_plant, err := dao_plant.SelectOne(user.PlantNr)
if err != nil {
@ -1097,12 +1118,15 @@ func (impl *BalanceServiceImplement) CustomerOrderReviewOne(user *global.User, q
if data_ArticleDemand == nil {
return nil, grmi.NewBusinessError("未查询到客户订单")
}
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)
data_ArticleStock, err := dao_ArticleStock.Select([]grmi.Predicate{}, nil)
if err != nil {
return nil, grmi.NewDataBaseError(err)
}
data_ArticleStockLevel, err := dao_ArticleStockLevel.Select([]grmi.Predicate{}, nil)
if err != nil {
return nil, grmi.NewDataBaseError(err)
}
var rockData []model.ArticleDemand
for index, info := range data_ArticleDemand {
if info.DemandKey[len(info.DemandKey)-1:len(info.DemandKey)] == "*" {
@ -1113,7 +1137,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(false, data_ArticleStockLevel, data_ArticleDemand, data_ArticleResourceLst, mpsSettingOne)
data_ArticleDemand_new, err := impl.refreshMpsArticleDemand(false, data_ArticleStock,data_ArticleStockLevel, data_ArticleDemand, data_ArticleResourceLst, mpsSettingOne)
if err != nil {
return nil, grmi.NewDataBaseError(err)
}
@ -1149,10 +1173,6 @@ func (impl *BalanceServiceImplement) CustomerOrderReviewOne(user *global.User, q
if err != nil {
return nil, grmi.NewDataBaseError(err)
}
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)
}
data_ArticleDemand, err = dao_ArticleDemand.Select([]grmi.Predicate{meta.ArticleDemand_PlantNr.NewPredicate(grmi.Equal, user.PlantNr)}, nil)
if err != nil {
@ -1170,7 +1190,7 @@ func (impl *BalanceServiceImplement) CustomerOrderReviewOne(user *global.User, q
}
}
_, mainmpsGroupLst, _, err2, done := impl.makeMpsGroup(false, user, articleResource.ResourceId, "", mainselectArticleDemandList, data_ArticleStockLevel, articleDemandListMap, dao_Customer, dao_CustDemandModel, data_ArticleResource, mpsSettingOne)
_, mainmpsGroupLst, _, err2, done := impl.makeMpsGroup(data_ArticleStock,false, user, articleResource.ResourceId, "", mainselectArticleDemandList, data_ArticleStockLevel, articleDemandListMap, dao_Customer, dao_CustDemandModel, data_ArticleResource, mpsSettingOne)
if done {
return nil, err2
}
@ -1486,7 +1506,7 @@ func (impl *BalanceServiceImplement) CustomerOrderReviewExport(user *global.User
return result, err
}
func (impl *BalanceServiceImplement) refreshMpsArticleDemand(isRefresh bool, data_ArticleStockLevel []model.ArticleStockLevel, data_ArticleDemand []model.ArticleDemand, data_ArticleResource []model.ArticleResource, mpsSetting *model.MpsSetting) ([]model.ArticleDemand, error) {
func (impl *BalanceServiceImplement) refreshMpsArticleDemand(isRefresh bool, data_ArticleStock []model_base.ArticleStock,data_ArticleStockLevel []model.ArticleStockLevel, data_ArticleDemand []model.ArticleDemand, data_ArticleResource []model.ArticleResource, mpsSetting *model.MpsSetting) ([]model.ArticleDemand, error) {
if data_ArticleDemand == nil || len(data_ArticleDemand) == 0 {
fmt.Println(data_ArticleDemand)
return nil, nil
@ -1509,23 +1529,23 @@ func (impl *BalanceServiceImplement) refreshMpsArticleDemand(isRefresh bool, dat
// lockWeek = mpsSetting.DefaultLockWeeks
//}
//
////2.计算最小覆盖周期和最大覆盖周期
//for index, _ := range data_ArticleDemand {
// if mpsSetting.UseFixedStockCoverToggle {
// data_ArticleDemand[index].MinCoverPeriod = mpsSetting.DefaultMinCoverPeriod
// data_ArticleDemand[index].MaxCoverPeriod = mpsSetting.DefaultMaxCoverPeriod
// } else {
// //查询周期
// for _, articleStockLevelInfo := range data_ArticleStockLevel {
// if articleStockLevelInfo.ArtId == data_ArticleDemand[index].ArtId && articleStockLevelInfo.MinCoverPeriodType == data_ArticleDemand[0].DemandPeriodType {
// data_ArticleDemand[index].MinCoverPeriod = articleStockLevelInfo.MinCoverPeriod
// }
// if articleStockLevelInfo.ArtId == data_ArticleDemand[index].ArtId && articleStockLevelInfo.MaxCoverPeriodType == data_ArticleDemand[0].DemandPeriodType {
// data_ArticleDemand[index].MaxCoverPeriod = articleStockLevelInfo.MaxCoverPeriod
// }
// }
// }
//}
//2.计算最小覆盖周期和最大覆盖周期
for index, _ := range data_ArticleDemand {
if mpsSetting.UseFixedStockCoverToggle {
data_ArticleDemand[index].MinCoverPeriod = mpsSetting.DefaultMinCoverPeriod
data_ArticleDemand[index].MaxCoverPeriod = mpsSetting.DefaultMaxCoverPeriod
} else {
//查询周期
for _, articleStockLevelInfo := range data_ArticleStockLevel {
if articleStockLevelInfo.ArtId == data_ArticleDemand[index].ArtId && articleStockLevelInfo.MinCoverPeriodType == data_ArticleDemand[0].DemandPeriodType {
data_ArticleDemand[index].MinCoverPeriod = articleStockLevelInfo.MinCoverPeriod
}
if articleStockLevelInfo.ArtId == data_ArticleDemand[index].ArtId && articleStockLevelInfo.MaxCoverPeriodType == data_ArticleDemand[0].DemandPeriodType {
data_ArticleDemand[index].MaxCoverPeriod = articleStockLevelInfo.MaxCoverPeriod
}
}
}
}
//
////需求周期 > 当前时间+ mps策略表偏离周数 并且 需求周期 < (当前时间+吸收期+最大覆盖周期)
//startIndex, endIndex := 0, 0
@ -1548,15 +1568,14 @@ func (impl *BalanceServiceImplement) refreshMpsArticleDemand(isRefresh bool, dat
for index, _ := range data_ArticleDemand {
//期初库存
//if index == 0 {
// //todo
// //STK_InventoryStruct := _struct.STK_InventoryStruct{
// // FormId: "STK_Inventory",
// // FieldKeys: "FMaterialId.FNumber,FBaseQty",
// //}
// //utilService.STK_InventoryInit().GetSTK_Inventory(STK_InventoryStruct)
// data_ArticleDemand[index].OpeningInventory = 80.0
//}
if index == 0 {
for _, articleStock := range data_ArticleStock{
if articleStock.ArtId == data_ArticleDemand[index].ArtId{
data_ArticleDemand[index].OpeningInventory =articleStock.FGQty
break
}
}
}
//最小库存水平
MinInventory := 0.0
@ -1764,6 +1783,12 @@ func (impl *BalanceServiceImplement) GetMpsPlan(user *global.User, resouceId, se
dao_Customer := dal_base.NewCustomerDAO(session, user.PlantNr, user.UserId)
dao_MpsSetting := dal.NewMpsSettingDAO(session, user.PlantNr, user.UserId)
dao_ArticleStock := dal_base.NewArticleStockDAO(session, user.PlantNr, user.UserId)
data_ArticleStock, err := dao_ArticleStock.Select([]grmi.Predicate{}, nil)
if err != nil {
return nil, grmi.NewDataBaseError(err)
}
dao_plant := dal_base.NewPlantDAO(session, user.UserId)
data_plant, err := dao_plant.SelectOne(user.PlantNr)
@ -1812,7 +1837,7 @@ func (impl *BalanceServiceImplement) GetMpsPlan(user *global.User, resouceId, se
var rockData []model.ArticleDemand
for index, info := range data_ArticleDemand {
if info.DemandKey[len(info.DemandKey)-1:len(info.DemandKey)] == "!" {
if info.DemandKey[len(info.DemandKey)-1:len(info.DemandKey)] == "*" {
rockData = append(rockData, info)
data_ArticleDemand = append(data_ArticleDemand[:index], data_ArticleDemand[index+1:]...)
}
@ -1839,7 +1864,7 @@ func (impl *BalanceServiceImplement) GetMpsPlan(user *global.User, resouceId, se
}
}
alternativeArticleDemandList, mpsGroupLst, plan, err2, done := impl.makeMpsGroup(false, user, AlternativeResource.AlternativeResourceId, secondresourceid, alternativeselectArticleDemandList, data_ArticleStockLevel, articleDemandListMap, dao_Customer, dao_CustDemandModel, data_ArticleResource, mpsSettingOne)
alternativeArticleDemandList, mpsGroupLst, plan, err2, done := impl.makeMpsGroup(data_ArticleStock,false, user, AlternativeResource.AlternativeResourceId, secondresourceid, alternativeselectArticleDemandList, data_ArticleStockLevel, articleDemandListMap, dao_Customer, dao_CustDemandModel, data_ArticleResource, mpsSettingOne)
if done {
return plan, err2
}
@ -1862,7 +1887,7 @@ func (impl *BalanceServiceImplement) GetMpsPlan(user *global.User, resouceId, se
}
}
mainArticleDemandList, mainmpsGroupLst, plan, err2, done := impl.makeMpsGroup(false, user, resouceId, secondresourceid, mainselectArticleDemandList, data_ArticleStockLevel, articleDemandListMap, dao_Customer, dao_CustDemandModel, data_ArticleResource, mpsSettingOne)
mainArticleDemandList, mainmpsGroupLst, plan, err2, done := impl.makeMpsGroup(data_ArticleStock,false, user, resouceId, secondresourceid, mainselectArticleDemandList, data_ArticleStockLevel, articleDemandListMap, dao_Customer, dao_CustDemandModel, data_ArticleResource, mpsSettingOne)
if done {
return plan, err2
}
@ -1886,7 +1911,7 @@ func (impl *BalanceServiceImplement) GetMpsPlan(user *global.User, resouceId, se
}
}
}
secondArticleDemandList, mpsGroupLst, plan, err2, done := impl.makeMpsGroup(false, user, resouceId, secondresourceid, secondselectArticleDemandList, data_ArticleStockLevel, articleDemandListMap, dao_Customer, dao_CustDemandModel, data_ArticleResource, mpsSettingOne)
secondArticleDemandList, mpsGroupLst, plan, err2, done := impl.makeMpsGroup(data_ArticleStock,false, user, resouceId, secondresourceid, secondselectArticleDemandList, data_ArticleStockLevel, articleDemandListMap, dao_Customer, dao_CustDemandModel, data_ArticleResource, mpsSettingOne)
if done {
return plan, err2
}
@ -1908,7 +1933,7 @@ func (impl *BalanceServiceImplement) GetMpsPlan(user *global.User, resouceId, se
}
}
}
secondArticleDemandList, mpsGroupLst, plan, err2, done := impl.makeMpsGroup(false, user, resouceId, secondresourceid, secondselectArticleDemandList, data_ArticleStockLevel, articleDemandListMap, dao_Customer, dao_CustDemandModel, data_ArticleResource, mpsSettingOne)
secondArticleDemandList, mpsGroupLst, plan, err2, done := impl.makeMpsGroup(data_ArticleStock,false, user, resouceId, secondresourceid, secondselectArticleDemandList, data_ArticleStockLevel, articleDemandListMap, dao_Customer, dao_CustDemandModel, data_ArticleResource, mpsSettingOne)
if done {
return plan, err2
}
@ -1921,11 +1946,12 @@ func (impl *BalanceServiceImplement) GetMpsPlan(user *global.User, resouceId, se
return mpsPlan, err
}
func (impl *BalanceServiceImplement) makeMpsGroup(isrefresh bool, user *global.User, resouceId string, secondresourceid string, selectArticleDemandList []model.ArticleDemand, data_ArticleStockLevel []model.ArticleStockLevel, articleDemandListMap map[string][]model.ArticleDemand, dao_Customer dal_base.CustomerDAO, dao_CustDemandModel dal.CustDemandModelDAO, data_ArticleResource []model.ArticleResource, mpsSettingOne *model.MpsSetting) ([]model.ArticleDemand, []model.ArticleResourceMpsGroup, *model.MpsPlan, error, bool) {
func (impl *BalanceServiceImplement) makeMpsGroup(data_ArticleStock []model_base.ArticleStock, isrefresh bool, user *global.User, resouceId string, secondresourceid string, selectArticleDemandList []model.ArticleDemand, data_ArticleStockLevel []model.ArticleStockLevel, articleDemandListMap map[string][]model.ArticleDemand, dao_Customer dal_base.CustomerDAO, dao_CustDemandModel dal.CustDemandModelDAO, data_ArticleResource []model.ArticleResource, mpsSettingOne *model.MpsSetting) ([]model.ArticleDemand, []model.ArticleResourceMpsGroup, *model.MpsPlan, error, bool) {
var (
finalArticleDemandList []model.ArticleDemand
mpsGroupLst []model.ArticleResourceMpsGroup
)
//2.计算最小覆盖周期和最大覆盖周期
for index, _ := range selectArticleDemandList {
if mpsSettingOne.UseFixedStockCoverToggle {
@ -1974,7 +2000,7 @@ func (impl *BalanceServiceImplement) makeMpsGroup(isrefresh bool, user *global.U
//if err != nil {
// return nil, nil, nil, grmi.NewDataBaseError(err), true
//}
ArticleDemandList, err := impl.refreshMpsArticleDemand(isrefresh, data_ArticleStockLevel, group, data_ArticleResource, mpsSettingOne)
ArticleDemandList, err := impl.refreshMpsArticleDemand(isrefresh, data_ArticleStock,data_ArticleStockLevel, group, data_ArticleResource, mpsSettingOne)
if err != nil || ArticleDemandList == nil {
return nil, nil, nil, err, true
}
@ -2064,7 +2090,11 @@ func (impl *BalanceServiceImplement) MpsPlan(user *global.User, resouceId, secon
if err != nil {
return nil, grmi.NewDataBaseError(err)
}
dao_ArticleStock := dal_base.NewArticleStockDAO(session, user.PlantNr, user.UserId)
data_ArticleStock, err := dao_ArticleStock.Select([]grmi.Predicate{}, nil)
if err != nil {
return nil, grmi.NewDataBaseError(err)
}
//dao_ArticleResource := dal.NewArticleResourceDAO(session, user.PlantNr, user.UserId)
dao_ArticleStockLevel := dal.NewArticleStockLevelDAO(session, user.PlantNr, user.UserId)
dao_ArticleAlternativeResource := dal.NewArticleAlternativeResourceDAO(session, user.PlantNr, user.UserId)
@ -2142,7 +2172,7 @@ func (impl *BalanceServiceImplement) MpsPlan(user *global.User, resouceId, secon
mpsPlan.ArticleDemandLst = append(mpsPlan.ArticleDemandLst, groupArticleInfo.ArticleDemandLst...)
}
for _, ArticleAlternativeDemand := range mpsPlan.ArticleAlternativeDemandLst {
for index, ArticleAlternativeDemand := range mpsPlan.ArticleAlternativeDemandLst {
for _, info := range ArticleAlternativeDemand {
if info.NetDemandQty == 0 {
continue
@ -2151,7 +2181,8 @@ func (impl *BalanceServiceImplement) MpsPlan(user *global.User, resouceId, secon
if len(demandWeek) == 1 {
demandWeek = "0" + demandWeek
}
demandKey := strconv.Itoa(info.DemandYear) + "." + demandWeek + "_" + info.ResourceId + "*"
//demandKey := strconv.Itoa(info.DemandYear) + "." + demandWeek + "_" + info.ResourceId + "*"
demandKey := strconv.Itoa(info.DemandYear) + "." + demandWeek
AlternativeDemandInfo := model.ArticleDemand{
PlantNr: info.PlantNr,
ArtId: info.ArtId,
@ -2178,7 +2209,7 @@ func (impl *BalanceServiceImplement) MpsPlan(user *global.User, resouceId, secon
CanWrite: false,
}
mpsPlan.ArticleDemandLst = append(mpsPlan.ArticleDemandLst, AlternativeDemandInfo)
mpsPlan.ArticleAlternativeDemandLst[index] = append(mpsPlan.ArticleAlternativeDemandLst[index], AlternativeDemandInfo)
}
}
@ -2187,7 +2218,6 @@ func (impl *BalanceServiceImplement) MpsPlan(user *global.User, resouceId, secon
}
dao_CustArtlst := dal.NewCustArtlstDAO(session, user.PlantNr, user.UserId)
dao_ArticleStock := dal_base.NewArticleStockDAO(session, user.PlantNr, user.UserId)
artResourceDao := dal.NewArticleResourceDAO(session, user.PlantNr, user.UserId)
//dao_CustDemandModel := dal.NewCustDemandModelDAO(session, user.PlantNr, user.UserId)
//dao_Customer := dal_base.NewCustomerDAO(session, user.PlantNr, user.UserId)
@ -2222,18 +2252,11 @@ func (impl *BalanceServiceImplement) MpsPlan(user *global.User, resouceId, secon
}
for _, artStockInfo := range artStockList {
if artStockInfo.ArtId == custArtInfo.ArtId {
switch artStockInfo.StockType {
case "FG":
custArtStockInfo.FGStock = artStockInfo.FGQty
case "SFG":
custArtStockInfo.SFGStock = artStockInfo.SFGQty
case "WIP":
custArtStockInfo.WIPStock = artStockInfo.WIPQty
case "PUC":
custArtStockInfo.PUCStock = artStockInfo.PUCQty
case "OSC":
custArtStockInfo.OSCStock = artStockInfo.OSCQty
}
custArtStockInfo.FGStock = artStockInfo.FGQty
custArtStockInfo.SFGStock = artStockInfo.SFGQty
custArtStockInfo.WIPStock = artStockInfo.WIPQty
custArtStockInfo.PUCStock = artStockInfo.PUCQty
custArtStockInfo.OSCStock = artStockInfo.OSCQty
break
}
}
@ -2258,13 +2281,29 @@ func (impl *BalanceServiceImplement) MpsPlan(user *global.User, resouceId, secon
}
var data_ArticleResourceLst []model.ArticleResource
data_ArticleResourceLst = append(data_ArticleResourceLst, *articleResource)
data_ArticleDemand_new, err := impl.refreshMpsArticleDemand(false, data_ArticleStockLevel, data_ArticleDemand, data_ArticleResourceLst, mpsSettingOne)
data_ArticleDemand_new, err := impl.refreshMpsArticleDemand(false, data_ArticleStock,data_ArticleStockLevel, data_ArticleDemand, data_ArticleResourceLst, mpsSettingOne)
if err != nil {
return nil, grmi.NewDataBaseError(err)
}
data[index].ArticleDemandLst = data_ArticleDemand_new
}
var keyList []string
for _, info:= range data{
for _, key := range info.ArticleDemandLst{
isIn:= false
for _, keyNow := range keyList{
if key.DemandKey == keyNow{
isIn = true
break
}
}
if !isIn{
keyList = append(keyList, key.DemandKey)
}
}
}
sort.Strings(keyList)
//var CustArtStockItemLst []model.CustArtStockItem
var CustArtStockaLL model.CustArtStockItem
CustArtStockaLL.ItemLst = *new([]map[string]string)
@ -2280,10 +2319,10 @@ func (impl *BalanceServiceImplement) MpsPlan(user *global.User, resouceId, secon
CustArtStockaLL.SortKeys = append(CustArtStockaLL.SortKeys, "AP_ArticleDemand-Descr1")
//CustArtStockaLL.SortKeys = append(CustArtStockaLL.SortKeys, "AP_ArticleDemand-CustomerId")
CustArtStockaLL.SortKeys = append(CustArtStockaLL.SortKeys, "AP_ArticleDemand-FGStock")
CustArtStockaLL.SortKeys = append(CustArtStockaLL.SortKeys, "AP_ArticleDemand-SFGStock")
//CustArtStockaLL.SortKeys = append(CustArtStockaLL.SortKeys, "AP_ArticleDemand-SFGStock")
CustArtStockaLL.SortKeys = append(CustArtStockaLL.SortKeys, "AP_ArticleDemand-WIPStock")
CustArtStockaLL.SortKeys = append(CustArtStockaLL.SortKeys, "AP_ArticleDemand-PUCStock")
CustArtStockaLL.SortKeys = append(CustArtStockaLL.SortKeys, "AP_ArticleDemand-OSCStock")
//CustArtStockaLL.SortKeys = append(CustArtStockaLL.SortKeys, "AP_ArticleDemand-OSCStock")
}
CustArtStockItem.ItemLst[i]["AP_ArticleDemand-ArtId"] = info.ArtId
@ -2291,16 +2330,27 @@ func (impl *BalanceServiceImplement) MpsPlan(user *global.User, resouceId, secon
CustArtStockItem.ItemLst[i]["AP_ArticleDemand-Descr1"] = info.Descr1
//CustArtStockItem.ItemLst[i]["AP_ArticleDemand-CustomerId"] = info.CustomerId
CustArtStockItem.ItemLst[i]["AP_ArticleDemand-FGStock"] = utils.FloatToString(info.FGStock, 2)
CustArtStockItem.ItemLst[i]["AP_ArticleDemand-SFGStock"] = utils.FloatToString(info.SFGStock, 2)
//CustArtStockItem.ItemLst[i]["AP_ArticleDemand-SFGStock"] = utils.FloatToString(info.SFGStock, 2)
CustArtStockItem.ItemLst[i]["AP_ArticleDemand-WIPStock"] = utils.FloatToString(info.WIPStock, 2)
CustArtStockItem.ItemLst[i]["AP_ArticleDemand-PUCStock"] = utils.FloatToString(info.PUCStock, 2)
CustArtStockItem.ItemLst[i]["AP_ArticleDemand-OSCStock"] = utils.FloatToString(info.OSCStock, 2)
//CustArtStockItem.ItemLst[i]["AP_ArticleDemand-OSCStock"] = utils.FloatToString(info.OSCStock, 2)
for _,key := range keyList{
var detail *model.ArticleDemand
for _, nowDetail := range info.ArticleDemandLst {
if nowDetail.DemandKey == key{
detail = &nowDetail
break
}
}
if detail == nil{
detail = new(model.ArticleDemand)
detail.DemandKey = key
}
for _, detail := range info.ArticleDemandLst {
if i == 0 && index == 0 {
CustArtStockaLL.SortKeys = append(CustArtStockaLL.SortKeys, detail.DemandKey)
}
switch i {
case 0:
CustArtStockItem.ItemLst[i]["AP_ArticleDemand-Label"] = "AP_ArticleDemand-NetDemandQty"
@ -2333,11 +2383,8 @@ func (impl *BalanceServiceImplement) MpsPlan(user *global.User, resouceId, secon
CustArtStockItem.ItemLst[i]["AP_ArticleDemand-Label"] = "AP_ArticleDemand-EndingInventory"
CustArtStockItem.ItemLst[i][detail.DemandKey] = utils.FloatToString(detail.EndingInventory, 2)
}
//CustArtStockItem.CustArtStockDetail["Label"] = *new(model.ArticleDemand)
//CustArtStockItem.ItemLst[i][detail.DemandKey] = utils.ValueToString(detail.NetDemandQty, "")
//CustArtStockItem.CustArtStockDetail[detail.DemandKey] = detail
}
}
CustArtStockaLL.ItemLst = append(CustArtStockaLL.ItemLst, CustArtStockItem.ItemLst...)
}
@ -2797,6 +2844,22 @@ func (impl *BalanceServiceImplement) RefreshBalanceData(user *global.User) error
return grmi.NewBusinessError("不存在客户需求版本详细数据")
}
dao_MpsSetting := dal.NewMpsSettingDAO(session, user.PlantNr, user.UserId)
dao_plant := dal_base.NewPlantDAO(session, user.UserId)
data_plant, err := dao_plant.SelectOne(user.PlantNr)
if err != nil {
return grmi.NewDataBaseError(err)
}
mpsSettingOne, err := dao_MpsSetting.SelectOne(data_plant.DefaultMpsSettingNr)
if err != nil || mpsSettingOne == nil {
return grmi.NewDataBaseError(err)
}
frontday := mpsSettingOne.SalesOrderFetchLeadTimeByDay
var articleMap = make(map[string]int)
for _, info := range demandLstLi {
_, isIn := articleMap[info.ArtId]
@ -2854,7 +2917,8 @@ func (impl *BalanceServiceImplement) RefreshBalanceData(user *global.User) error
demandWeek = "0" + demandWeek
}
demandKey := strconv.Itoa(info.DemandYear) + "." + demandWeek + "_" + resourceId
//demandKey := strconv.Itoa(info.DemandYear) + "." + demandWeek + "_" + resourceId
demandKey := strconv.Itoa(info.DemandYear) + "." + demandWeek
custArticleList, err := dao_CustArticle.Select([]grmi.Predicate{meta.CustArtlst_ArtId.NewPredicate(grmi.Equal, info.ArtId)}, nil)
if err != nil {
@ -2884,9 +2948,9 @@ func (impl *BalanceServiceImplement) RefreshBalanceData(user *global.User) error
}
}
//需求周期 > 当前时间+ mps策略表偏离周数 并且 需求周期 < (当前时间+吸收期+最大覆盖周期)
//需求周期 + mps策略表偏离天数 > 当前时间+ 并且 需求周期 < (当前时间+吸收期+最大覆盖周期)
weekTimeNow := utils.WeekDayMondayZeroTs(timeNow)
weekTimeDemand := utils.WeekDayMondayZeroTs(info.DemandDate.Restore())
weekTimeDemand := utils.WeekDayMondayZeroTs(info.DemandDate.Restore().Add(time.Duration(frontday*24*7) * time.Hour))
if weekTimeNow.After(weekTimeDemand) {
continue
}
@ -2920,6 +2984,7 @@ func (impl *BalanceServiceImplement) RefreshBalanceData(user *global.User) error
MinCoverPeriod: MinCoverPeriod,
MaxCoverPeriod: MaxCoverPeriod,
MinCoverPeriodType: "W",
ResourceId: resourceId,
}
firstDemandList = append(firstDemandList, firstArticleDemand)
}
@ -2956,10 +3021,10 @@ func (impl *BalanceServiceImplement) RefreshBalanceData(user *global.User) error
}
go func() {
// 期初库存
err := erp.GetArticleDemandErpQty(user.PlantNr, user.UserId, &alldata_Article)
if err != nil {
}
//// 期初库存
//err := erp.GetArticleDemandErpQty(user.PlantNr, user.UserId, &alldata_Article)
//if err != nil {
//}
// 订单需求
err = erp.GetOrderQty(user.PlantNr, user.UserId, &alldata_Article)
if err != nil {


+ 1
- 0
services/ap/implments/MpsSetting.service.impl.go View File

@ -41,6 +41,7 @@ var DefaultConditionOfMpsSetting = grmi.NewCondition(
meta.MpsSetting_LastModify.UrlParameterName: grmi.NewConditionItem(meta.MpsSetting_LastModify, grmi.Approximate, false),
meta.MpsSetting_LastUser.UrlParameterName: grmi.NewConditionItem(meta.MpsSetting_LastUser, grmi.Equal, false),
meta.MpsSetting_CreateTime.UrlParameterName: grmi.NewConditionItem(meta.MpsSetting_CreateTime, grmi.Approximate, false),
meta.MpsSetting_SalesOrderFetchLeadTimeByDay.UrlParameterName: grmi.NewConditionItem(meta.MpsSetting_SalesOrderFetchLeadTimeByDay, grmi.Equal, false),
},
nil,
)


+ 80
- 151
services/erp/erp.go View File

@ -9,8 +9,10 @@ import (
"leit.com/LAPP_CHEERSSON_BACKEND/grmi"
meta "leit.com/LAPP_CHEERSSON_BACKEND/meta/ap"
model "leit.com/LAPP_CHEERSSON_BACKEND/models/base"
"leit.com/LAPP_CHEERSSON_BACKEND/utils"
utilService "leit.com/LAPP_CHEERSSON_BACKEND/utils/k3cloud/service"
"strconv"
"time"
)
func PublishPlan(PlantNr int, UserId string) {
@ -362,7 +364,7 @@ func GetArticleDemandErpQty(PlantNr int, UserId string, allData *[]model.Article
for _, info := range dataList{
FMaterialId := info[0].(string)
var articleOne *model.Article
ok, err := session.Table("Article").Where("PlantNr = ? and FMaterialId = ?", PlantNr, FMaterialId).Get(articleOne)
ok, err := session.Table("Article").Where("PlantNr = ? and ArtId = ?", PlantNr, FMaterialId).Get(articleOne)
if err != nil {
_ = session.Rollback()
return errors.New("查询系统物料失败, error:" + err.Error())
@ -413,58 +415,50 @@ func GetOrderQty(PlantNr int, UserId string, allData *[]model.Article) (err erro
return errors.New("查询物料需求数据失败, error:" + err.Error())
}
var FMaterialIdList []int
for _, articleInfo := range *allData {
// 在MDS中存在 在金蝶中不存在
if articleInfo.FMaterialId == 0 {
continue
}
for _, articleDemandInfo := range articleDemandList {
if articleInfo.ArtId == articleDemandInfo.ArtId {
FMaterialIdList = append(FMaterialIdList, articleInfo.FMaterialId)
}
}
}
//var FMaterialIdList []string
//for _, articleInfo := range *allData {
// // 在MDS中存在 在金蝶中不存在
// if articleInfo.FMaterialId == 0 {
// continue
// }
// for _, articleDemandInfo := range articleDemandList {
// if articleInfo.ArtId == articleDemandInfo.ArtId {
// FMaterialIdList = append(FMaterialIdList, articleInfo.ArtId)
// }
// }
//}
FilerString := ""
for index, FMaterialId := range FMaterialIdList {
if index > 0 {
FilerString += " Or "
}
FMaterialIdS := strconv.Itoa(FMaterialId)
FilerString += "FMaterialId = " + FMaterialIdS
}
//for index, FMaterialId := range FMaterialIdList {
// if index > 0 {
// FilerString += " Or "
// }
// FMaterialIdS := FMaterialId
// FilerString += "FMaterialId = " + FMaterialIdS
//}
FilerString += "FDocumentStatus = 'C'"
dataList := utilService.SaleOrderInit_Dingdanxuqiu().SaleOrderSearch(FilerString, "")
articleQtyMap := make(map[string]float64)
for _, info := range dataList{
FMaterialId := info[0].(string)
var articleOne *model.Article
ok, err := session.Table("Article").Where("PlantNr = ? and FMaterialId = ?", PlantNr, FMaterialId).Get(articleOne)
if err != nil {
_ = session.Rollback()
return errors.New("查询系统物料失败, error:" + err.Error())
}
if !ok {
fmt.Println("金蝶物料在系统中不存在, 物料ID:" + FMaterialId)
continue
for index, _ := range articleDemandList {
articleDemandList[index].OrderQty = 0
for _, info := range dataList{
ArtId := info[0].(string)
Qty := info[1].(float64)
Time, _ := time.ParseInLocation("2006-01-02T15:04:05", utils.ValueToString(info[2], ""), utils.TimezoneLocation)
Time = utils.WeekDayMondayZeroTs(Time)
ArticleTime := utils.WeekDayMondayZeroTs(articleDemandList[index].DemandDate.Restore())
if Time == ArticleTime && ArtId == articleDemandList[index].ArtId{
articleDemandList[index].OrderQty += Qty
err := dao_ArticleDemand.UpdateOne(&articleDemandList[index])
fmt.Println(articleDemandList[index].ArtId,articleDemandList[index].OrderQty)
if err != nil {
_ = session.Rollback()
return grmi.NewBusinessError("更新物料需求数据失败, error:" + err.Error())
}
}
}
articleQtyMap[articleOne.ArtId] = info[1].(float64)
}
for _, articleDemandInfo := range articleDemandList {
qty, isOk := articleQtyMap[articleDemandInfo.ArtId]
if isOk{
articleDemandInfo.WipQty = qty
}
err := dao_ArticleDemand.UpdateOne(&articleDemandInfo)
if err != nil {
_ = session.Rollback()
return grmi.NewBusinessError("更新物料需求数据失败, error:" + err.Error())
}
}
_ = session.Commit()
return nil
@ -481,13 +475,6 @@ func GetWaigouQty(PlantNr int, UserId string, allData *[]model.Article) (err err
return
}
//Article := make([]model.Article, 0)
//err = session.Table("Article").Find(&Article)
//if err != nil {
// _ = session.Rollback()
// return errors.New("查询系统物料失败, error:" + err.Error())
//}
dao_ArticleDemand := dal.NewArticleDemandDAO(session, PlantNr, UserId)
articleDemandList, err := dao_ArticleDemand.Select([]grmi.Predicate{}, nil)
if err != nil {
@ -495,56 +482,30 @@ func GetWaigouQty(PlantNr int, UserId string, allData *[]model.Article) (err err
return errors.New("查询物料需求数据失败, error:" + err.Error())
}
var FMaterialIdList []int
for _, articleInfo := range *allData {
// 在MDS中存在 在金蝶中不存在
if articleInfo.FMaterialId == 0 {
continue
}
for _, articleDemandInfo := range articleDemandList {
if articleInfo.ArtId == articleDemandInfo.ArtId {
FMaterialIdList = append(FMaterialIdList, articleInfo.FMaterialId)
}
}
}
FilerString := ""
for index, FMaterialId := range FMaterialIdList {
if index > 0 {
FilerString += " Or "
}
FMaterialIdS := strconv.Itoa(FMaterialId)
FilerString += "FMaterialId = " + FMaterialIdS
}
dataList := utilService.PUR_Requisition_Init().Search(FilerString, "")
articleQtyMap := make(map[string]float64)
for _, info := range dataList{
FMaterialId := info[0].(string)
var articleOne *model.Article
ok, err := session.Table("Article").Where("PlantNr = ? and FMaterialId = ?", PlantNr, FMaterialId).Get(&articleOne)
if err != nil {
_ = session.Rollback()
return errors.New("查询系统物料失败, error:" + err.Error())
}
if !ok {
fmt.Println("金蝶物料在系统中不存在, 物料ID:" + FMaterialId)
continue
FilerString += "FDocumentStatus = 'C'"
dataList := utilService.PUR_PurchaseOrder_Init().Search("", "")
for index, _ := range articleDemandList {
articleDemandList[index].OutSourcingQty = 0
for _, info := range dataList{
ArtId := info[0].(string)
Qty := info[1].(float64)
Time, _ := time.ParseInLocation("2006-01-02T15:04:05", utils.ValueToString(info[2], ""), utils.TimezoneLocation)
Time = utils.WeekDayMondayZeroTs(Time)
ArticleTime := utils.WeekDayMondayZeroTs(articleDemandList[index].DemandDate.Restore())
if Time == ArticleTime && ArtId == articleDemandList[index].ArtId{
articleDemandList[index].OutSourcingQty += Qty
err := dao_ArticleDemand.UpdateOne(&articleDemandList[index])
fmt.Println(articleDemandList[index].ArtId,articleDemandList[index].OutSourcingQty)
if err != nil {
_ = session.Rollback()
return grmi.NewBusinessError("更新物料需求数据失败, error:" + err.Error())
}
}
}
articleQtyMap[articleOne.ArtId] = info[1].(float64)
}
for _, articleDemandInfo := range articleDemandList {
qty, isOk := articleQtyMap[articleDemandInfo.ArtId]
if isOk{
articleDemandInfo.OutSourcingQty = qty
}
err := dao_ArticleDemand.UpdateOne(&articleDemandInfo)
if err != nil {
_ = session.Rollback()
return errors.New("更新物料需求数据失败, error:" + err.Error())
}
}
_ = session.Commit()
return nil
@ -561,65 +522,33 @@ func GetDuliQty(PlantNr int, UserId string, allData *[]model.Article) (err error
return
}
//Article := make([]model.Article, 0)
//err = session.Table("Article").Find(&Article)
//if err != nil {
// _ = session.Rollback()
// return errors.New("查询系统物料失败, error:" + err.Error())
//}
dao_ArticleDemand := dal.NewArticleDemandDAO(session, PlantNr, UserId)
articleDemandList, err := dao_ArticleDemand.Select([]grmi.Predicate{}, nil)
if err != nil {
_ = session.Rollback()
return errors.New("查询系统物料需求数据失败, error:" + err.Error())
}
var FMaterialIdList []int
for _, articleInfo := range *allData {
// 在MDS中存在 在金蝶中不存在
if articleInfo.FMaterialId == 0 {
continue
}
for _, articleDemandInfo := range articleDemandList {
if articleInfo.ArtId == articleDemandInfo.ArtId {
FMaterialIdList = append(FMaterialIdList, articleInfo.FMaterialId)
}
}
}
FilerString := ""
for index, FMaterialId := range FMaterialIdList {
if index > 0 {
FilerString += " Or "
}
FMaterialIdS := strconv.Itoa(FMaterialId)
FilerString += "FMaterialId = " + FMaterialIdS
}
dataList := utilService.PRD_MO_Init_Duli().Search(FilerString, "")
articleQtyMap := make(map[string]float64)
for _, info := range dataList{
FMaterialId := info[0].(string)
var articleOne *model.Article
ok, err := session.Table("Article").Where("PlantNr = ? and FMaterialId = ?", PlantNr, FMaterialId).Get(articleOne)
if err != nil {
_ = session.Rollback()
return errors.New("查询系统物料失败, error:" + err.Error())
}
if !ok {
fmt.Println("金蝶物料在系统中不存在, 物料ID:" + FMaterialId)
continue
}
articleQtyMap[articleOne.ArtId] = info[1].(float64)
}
for _, articleDemandInfo := range articleDemandList {
qty, isOk := articleQtyMap[articleDemandInfo.ArtId]
if isOk{
articleDemandInfo.IndependentDemandQty = qty
}
err = dao_ArticleDemand.UpdateOne(&articleDemandInfo)
if err != nil {
_ = session.Rollback()
return errors.New("更新系统物料需求数据失败, error:" + err.Error())
FilerString += "FDocumentStatus = 'C'"
dataList := utilService.PRD_MO_Init_Duli().Search("", "")
for index, _ := range articleDemandList {
articleDemandList[index].IndependentDemandQty = 0
for _, info := range dataList{
ArtId := info[0].(string)
Qty := info[1].(float64)
Time, _ := time.ParseInLocation("2006-01-02T15:04:05", utils.ValueToString(info[2], ""), utils.TimezoneLocation)
Time = utils.WeekDayMondayZeroTs(Time)
ArticleTime := utils.WeekDayMondayZeroTs(articleDemandList[index].DemandDate.Restore())
if Time == ArticleTime && ArtId == articleDemandList[index].ArtId{
articleDemandList[index].IndependentDemandQty += Qty
err := dao_ArticleDemand.UpdateOne(&articleDemandList[index])
fmt.Println(articleDemandList[index].ArtId,articleDemandList[index].IndependentDemandQty)
if err != nil {
_ = session.Rollback()
return grmi.NewBusinessError("更新物料需求数据失败, error:" + err.Error())
}
}
}
}


+ 4
- 1
task/k3cloud.go View File

@ -28,8 +28,11 @@ var serviceOfStdef = svr.NewStdefService()
var serviceOfCustArtlst = svrAp.NewCustArtlstService()
var serviceOfProject = svrMe.NewProjectService()
var serviceOfUom = svr.NewUomService()
var balanceService = svrAp.NewBalanceService()
func TaskInit() {
time.AfterFunc(10*time.Second, func() {
balanceService.RefreshData()
})
go func() {
timer := time.NewTicker(30 * time.Second)
for {


+ 3
- 3
utils/k3cloud/service/PRD_MO.go View File

@ -20,7 +20,7 @@ func PRD_MO_Init_Zhaizhi() *PRD_MO_Service {
K3config: utils2.K3Obj,
FormID: "PRD_MO",
FieldKeys: "FMaterialId.FNumber,FNoStockInQty",
FUseOrgKey: "FPrdOrgId="+utils2.K3Obj.FUseOrgId,
FUseOrgKey: "FPrdOrgId="+utils2.K3Obj.FUseOrgId + " And FReqType = 1",
}
return voucher
}
@ -39,8 +39,8 @@ func PRD_MO_Init_Duli() *PRD_MO_Service {
voucher := &PRD_MO_Service{
K3config: utils2.K3Obj,
FormID: "PRD_MO",
FieldKeys: "FMaterialId.FNumber,FNoStockInQty",
FUseOrgKey: "FPrdOrgId="+utils2.K3Obj.FUseOrgId + "And FReqType = 2",
FieldKeys: "FMaterialId.FNumber,FNoStockInQty,FPlanFinishDate",
FUseOrgKey: "FPrdOrgId="+utils2.K3Obj.FUseOrgId + " And FReqType = 2",
}
return voucher
}


+ 1
- 1
utils/k3cloud/service/PUR_PurchaseOrder.go View File

@ -19,7 +19,7 @@ func PUR_PurchaseOrder_Init() *PUR_PurchaseOrder_Service {
voucher := &PUR_PurchaseOrder_Service{
K3config: utils2.K3Obj,
FormID: "PUR_PurchaseOrder",
FieldKeys: "FMaterialId.FNumber,FRemainStockINQty",
FieldKeys: "FMaterialId.FNumber,FRemainStockINQty,FDeliveryDate",
FUseOrgKey: "FReceiveOrgId="+utils2.K3Obj.FUseOrgId,
}
return voucher


+ 1
- 1
utils/k3cloud/service/sal_saleorder.go View File

@ -26,7 +26,7 @@ func SaleOrderInit_Dingdanxuqiu() *SaleOrderService {
cust := &SaleOrderService{
K3config: utils.K3Obj,
FormID: "SAL_SaleOrder",
FieldKeys: "FSaleOrgId,FDeliRemainQty,FBillNo,FDate,FCustId,FMaterialId,FQty,FDeliveryDate,FCloseStatus,FCancelStatus,FSignStatus,FDocumentStatus",
FieldKeys: "FMaterialId.FNumber,FDeliRemainQty,FPlanDate",
FUseOrgKey: "FStockOrgId=" + utils.K3Obj.FUseOrgId,
}
return cust


+ 8515
- 0
utils/k3cloud/table/SAL_XORDER.json
File diff suppressed because it is too large
View File


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

@ -6,7 +6,6 @@ import (
"github.com/kataras/iris/v12/core/router"
"leit.com/LAPP_CHEERSSON_BACKEND/grmi"
svr "leit.com/LAPP_CHEERSSON_BACKEND/services/ap"
"time"
)
/******************************************************************************
@ -738,9 +737,4 @@ func init() {
// 注册路由
RegisterRoutes()
var balanceService = svr.NewBalanceService()
time.AfterFunc(10*time.Second, func() {
balanceService.RefreshData()
})
}

Loading…
Cancel
Save