|
|
@ -1,6 +1,7 @@ |
|
|
|
package erp |
|
|
|
|
|
|
|
import ( |
|
|
|
"errors" |
|
|
|
"fmt" |
|
|
|
dal "leit.com/LAPP_CHEERSSON_BACKEND/dao/ap" |
|
|
|
dal_base "leit.com/LAPP_CHEERSSON_BACKEND/dao/base" |
|
|
@ -12,15 +13,15 @@ import ( |
|
|
|
"strconv" |
|
|
|
) |
|
|
|
|
|
|
|
func PublishPlan(PlantNr int,UserId string){ |
|
|
|
func PublishPlan(PlantNr int, UserId string) { |
|
|
|
engine := db.Eloquent.Master() |
|
|
|
session := engine.NewSession() |
|
|
|
defer session.Close() |
|
|
|
|
|
|
|
dao_version := dal.NewPlanOrderVersionDAO(session, PlantNr,UserId) |
|
|
|
dao_plan := dal.NewPlanOrderDAO(session, PlantNr,UserId) |
|
|
|
planVersionList ,err := dao_version.Select([]grmi.Predicate{meta.PlanOrderVersion_Status.NewPredicate(grmi.Equal, 20)}, nil) |
|
|
|
if err!=nil{ |
|
|
|
dao_version := dal.NewPlanOrderVersionDAO(session, PlantNr, UserId) |
|
|
|
dao_plan := dal.NewPlanOrderDAO(session, PlantNr, UserId) |
|
|
|
planVersionList, err := dao_version.Select([]grmi.Predicate{meta.PlanOrderVersion_Status.NewPredicate(grmi.Equal, 20)}, nil) |
|
|
|
if err != nil { |
|
|
|
fmt.Println(err) |
|
|
|
return |
|
|
|
} |
|
|
@ -28,14 +29,14 @@ func PublishPlan(PlantNr int,UserId string){ |
|
|
|
return |
|
|
|
} |
|
|
|
_ = session.Begin() |
|
|
|
for _, planVersionInfo := range planVersionList{ |
|
|
|
for _, planVersionInfo := range planVersionList { |
|
|
|
planList, err := dao_plan.Select([]grmi.Predicate{meta.PlanOrder_VersionNr.NewPredicate(grmi.Equal, planVersionInfo.VersionNr)}, nil) |
|
|
|
if err!=nil{ |
|
|
|
if err != nil { |
|
|
|
return |
|
|
|
} |
|
|
|
for _, info := range planList{ |
|
|
|
err = utilService.PLN_PLANORDER_Init().Save(PlantNr,UserId,&info) |
|
|
|
if err != nil{ |
|
|
|
for _, info := range planList { |
|
|
|
err = utilService.PLN_PLANORDER_Init().Save(PlantNr, UserId, &info) |
|
|
|
if err != nil { |
|
|
|
fmt.Println(err) |
|
|
|
return |
|
|
|
} |
|
|
@ -43,7 +44,7 @@ func PublishPlan(PlantNr int,UserId string){ |
|
|
|
|
|
|
|
planVersionInfo.Status = 26 |
|
|
|
err = dao_version.UpdateOne(&planVersionInfo) |
|
|
|
if err != nil{ |
|
|
|
if err != nil { |
|
|
|
fmt.Println(err) |
|
|
|
return |
|
|
|
} |
|
|
@ -53,12 +54,12 @@ func PublishPlan(PlantNr int,UserId string){ |
|
|
|
} |
|
|
|
|
|
|
|
//即时库存 期初库存
|
|
|
|
func GetQiChuQty(PlantNr int,UserId,CustomerId string){ |
|
|
|
func GetQiChuQty(PlantNr int, UserId, CustomerId string) { |
|
|
|
engine := db.Eloquent.Master() |
|
|
|
session := engine.NewSession() |
|
|
|
defer session.Close() |
|
|
|
|
|
|
|
dao := dal_base.NewArticleStockDAO(session, PlantNr,UserId) |
|
|
|
dao := dal_base.NewArticleStockDAO(session, PlantNr, UserId) |
|
|
|
_ = session.Begin() |
|
|
|
|
|
|
|
ArticleStockStart := make([]model.ArticleStock, 0) |
|
|
@ -67,76 +68,76 @@ func GetQiChuQty(PlantNr int,UserId,CustomerId string){ |
|
|
|
Article := make([]model.Article, 0) |
|
|
|
session.Table("Article").Find(&Article) |
|
|
|
|
|
|
|
dao_ArticleDemand := dal.NewArticleDemandDAO(session, PlantNr,UserId) |
|
|
|
articleDemandList, err := dao_ArticleDemand.Select([]grmi.Predicate{meta.ArticleDemand_PlantNr.NewPredicate(grmi.Equal, PlantNr),meta.ArticleDemand_CustomerId.NewPredicate(grmi.Equal, CustomerId)}, nil) |
|
|
|
if err!=nil{ |
|
|
|
dao_ArticleDemand := dal.NewArticleDemandDAO(session, PlantNr, UserId) |
|
|
|
articleDemandList, err := dao_ArticleDemand.Select([]grmi.Predicate{meta.ArticleDemand_PlantNr.NewPredicate(grmi.Equal, PlantNr), meta.ArticleDemand_CustomerId.NewPredicate(grmi.Equal, CustomerId)}, nil) |
|
|
|
if err != nil { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
var FMaterialIdList []int |
|
|
|
for _, articleInfo := range Article{ |
|
|
|
for _, articleDemandInfo := range articleDemandList{ |
|
|
|
if articleInfo.ArtId == articleDemandInfo.ArtId{ |
|
|
|
for _, articleInfo := range Article { |
|
|
|
for _, articleDemandInfo := range articleDemandList { |
|
|
|
if articleInfo.ArtId == articleDemandInfo.ArtId { |
|
|
|
FMaterialIdList = append(FMaterialIdList, articleInfo.FMaterialId) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
FilerString := "" |
|
|
|
for index, FMaterialId := range FMaterialIdList{ |
|
|
|
if index > 0{ |
|
|
|
for index, FMaterialId := range FMaterialIdList { |
|
|
|
if index > 0 { |
|
|
|
FilerString += " Or " |
|
|
|
} |
|
|
|
FMaterialIdS := strconv.Itoa(FMaterialId) |
|
|
|
FilerString += "FMaterialId = " + FMaterialIdS |
|
|
|
} |
|
|
|
dataList := utilService.STK_InventoryInit().Search(FilerString,"") |
|
|
|
dataList := utilService.STK_InventoryInit().Search(FilerString, "") |
|
|
|
StockType := "QCKC" |
|
|
|
|
|
|
|
//即时库存
|
|
|
|
articlestockMap := make(map[int]float64) |
|
|
|
for _, info := range dataList{ |
|
|
|
FMaterialId := info[0].(int) |
|
|
|
for _, info := range dataList { |
|
|
|
FMaterialId := int(info[0].(float64)) |
|
|
|
_, isIn := articlestockMap[FMaterialId] |
|
|
|
if isIn{ |
|
|
|
if isIn { |
|
|
|
articlestockMap[FMaterialId] += info[1].(float64) |
|
|
|
}else{ |
|
|
|
} else { |
|
|
|
articlestockMap[FMaterialId] = info[1].(float64) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
data := make([]model.ArticleStock, 0) |
|
|
|
for _, info := range ArticleStockStart{ |
|
|
|
for FMaterialId, qty := range articlestockMap{ |
|
|
|
if info.FMaterialId == FMaterialId{ |
|
|
|
for _, info := range ArticleStockStart { |
|
|
|
for FMaterialId, qty := range articlestockMap { |
|
|
|
if info.FMaterialId == FMaterialId { |
|
|
|
sql := "update `ArticleStock` set ActualStock = ? where PlantNr = ? AND FMaterialId = ? And StockType = ?" |
|
|
|
if _, err := session.Table("ArticleStock").Exec(sql, qty, PlantNr, FMaterialId, StockType); err != nil { |
|
|
|
if _, err := session.Table("ArticleStock").Exec(sql, qty, PlantNr, FMaterialId, StockType); err != nil { |
|
|
|
fmt.Println(err) |
|
|
|
_ = session.Rollback() |
|
|
|
} |
|
|
|
}else{ |
|
|
|
} else { |
|
|
|
var selectArticle model.Article |
|
|
|
for _, info := range Article{ |
|
|
|
if info.FMaterialId == FMaterialId{ |
|
|
|
for _, info := range Article { |
|
|
|
if info.FMaterialId == FMaterialId { |
|
|
|
selectArticle = info |
|
|
|
break |
|
|
|
} |
|
|
|
} |
|
|
|
articleStockInfo := model.ArticleStock{ |
|
|
|
ArtId:selectArticle.ArtId, |
|
|
|
StockType: StockType, |
|
|
|
ArtId: selectArticle.ArtId, |
|
|
|
StockType: StockType, |
|
|
|
ActualStock: qty, |
|
|
|
} |
|
|
|
data = append(data,articleStockInfo ) |
|
|
|
data = append(data, articleStockInfo) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if len(data) > 20{ |
|
|
|
if len(data) > 20 { |
|
|
|
var _detail []model.ArticleStock |
|
|
|
for k,v := range data{ |
|
|
|
for k, v := range data { |
|
|
|
_detail = append(_detail, v) |
|
|
|
if (k>0 && k%20==0) || k+1 == len(data) { |
|
|
|
if (k > 0 && k%20 == 0) || k+1 == len(data) { |
|
|
|
err := dao.Insert(&_detail) |
|
|
|
if err != nil { |
|
|
|
_ = session.Rollback() |
|
|
@ -145,7 +146,7 @@ func GetQiChuQty(PlantNr int,UserId,CustomerId string){ |
|
|
|
_detail = []model.ArticleStock{} |
|
|
|
} |
|
|
|
} |
|
|
|
}else{ |
|
|
|
} else { |
|
|
|
err := dao.Insert(&data) |
|
|
|
if err != nil { |
|
|
|
_ = session.Rollback() |
|
|
@ -155,255 +156,300 @@ func GetQiChuQty(PlantNr int,UserId,CustomerId string){ |
|
|
|
_ = session.Commit() |
|
|
|
} |
|
|
|
|
|
|
|
func GetArticleDemandErpQty(PlantNr int,UserId,CustomerId string){ |
|
|
|
func GetArticleDemandErpQty(PlantNr int, UserId, CustomerId string, allData *[]model.Article) (err error) { |
|
|
|
engine := db.Eloquent.Master() |
|
|
|
session := engine.NewSession() |
|
|
|
defer session.Close() |
|
|
|
|
|
|
|
_ = session.Begin() |
|
|
|
|
|
|
|
Article := make([]model.Article, 0) |
|
|
|
session.Table("Article").Find(&Article) |
|
|
|
if err = session.Begin(); err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
dao_ArticleDemand := dal.NewArticleDemandDAO(session, PlantNr,UserId) |
|
|
|
articleDemandList, err := dao_ArticleDemand.Select([]grmi.Predicate{meta.ArticleDemand_PlantNr.NewPredicate(grmi.Equal, PlantNr),meta.ArticleDemand_CustomerId.NewPredicate(grmi.Equal, CustomerId)}, nil) |
|
|
|
if err!=nil{ |
|
|
|
session.Rollback() |
|
|
|
//Article := make([]model.Article, 0)
|
|
|
|
//err = session.Table("Article").Find(&Article)
|
|
|
|
//if err != nil {
|
|
|
|
// return err
|
|
|
|
//}
|
|
|
|
dao_ArticleDemand := dal.NewArticleDemandDAO(session, PlantNr, UserId) |
|
|
|
articleDemandList, err := dao_ArticleDemand.Select([]grmi.Predicate{meta.ArticleDemand_CustomerId.NewPredicate(grmi.Equal, CustomerId)}, nil) |
|
|
|
if err != nil { |
|
|
|
_ = session.Rollback() |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
var FMaterialIdList []int |
|
|
|
for _, articleInfo := range Article{ |
|
|
|
for _, articleDemandInfo := range articleDemandList{ |
|
|
|
if articleInfo.ArtId == articleDemandInfo.ArtId{ |
|
|
|
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{ |
|
|
|
for index, FMaterialId := range FMaterialIdList { |
|
|
|
if index > 0 { |
|
|
|
FilerString += " Or " |
|
|
|
} |
|
|
|
FMaterialIdS := strconv.Itoa(FMaterialId) |
|
|
|
FilerString += "FMaterialId = " + FMaterialIdS |
|
|
|
} |
|
|
|
dataList := utilService.STK_InventoryInit().Search(FilerString,"") |
|
|
|
dataList := utilService.STK_InventoryInit().Search(FilerString, "") |
|
|
|
|
|
|
|
articleQtyMap := make(map[string]float64) |
|
|
|
for _, info := range dataList { |
|
|
|
FMaterialId := info[0].(int) |
|
|
|
FMaterialId := info[0].(float64) |
|
|
|
var articleOne *model.Article |
|
|
|
_, err := session.Table("Article").Where("PlantNr = ? and UserId = ? and FMaterialId = ?", PlantNr, UserId,FMaterialId).Get(&articleOne) |
|
|
|
if err!=nil{ |
|
|
|
fmt.Println(err) |
|
|
|
session.Rollback() |
|
|
|
return |
|
|
|
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("物料在金蝶中存在, 在MDS中不存在, FMaterialId:" + strconv.Itoa(int(FMaterialId))) |
|
|
|
continue |
|
|
|
} |
|
|
|
articleQtyMap[articleOne.ArtId] = info[1].(float64) |
|
|
|
} |
|
|
|
|
|
|
|
for _, articleDemandInfo := range articleDemandList{ |
|
|
|
for _, articleDemandInfo := range articleDemandList { |
|
|
|
articleDemandInfo.OpeningInventory = articleQtyMap[articleDemandInfo.ArtId] |
|
|
|
err := dao_ArticleDemand.UpdateOne(&articleDemandInfo) |
|
|
|
if err!=nil{ |
|
|
|
fmt.Println(err) |
|
|
|
session.Rollback() |
|
|
|
return |
|
|
|
if err != nil { |
|
|
|
_ = session.Rollback() |
|
|
|
return errors.New("更新物料需求数据失败, error:" + err.Error()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
_ = session.Commit() |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
//在制库存
|
|
|
|
func GetOrderQty(PlantNr int,UserId string,CustomerId string){ |
|
|
|
func GetOrderQty(PlantNr int, UserId string, CustomerId string, allData *[]model.Article) (err error) { |
|
|
|
engine := db.Eloquent.Master() |
|
|
|
session := engine.NewSession() |
|
|
|
defer session.Close() |
|
|
|
|
|
|
|
_ = session.Begin() |
|
|
|
|
|
|
|
Article := make([]model.Article, 0) |
|
|
|
session.Table("Article").Find(&Article) |
|
|
|
|
|
|
|
dao_ArticleDemand := dal.NewArticleDemandDAO(session, PlantNr,UserId) |
|
|
|
articleDemandList, err := dao_ArticleDemand.Select([]grmi.Predicate{meta.ArticleDemand_PlantNr.NewPredicate(grmi.Equal, PlantNr),meta.ArticleDemand_CustomerId.NewPredicate(grmi.Equal, CustomerId)}, nil) |
|
|
|
if err!=nil{ |
|
|
|
session.Rollback() |
|
|
|
if err = session.Begin(); err != nil { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
//Article := make([]model.Article, 0)
|
|
|
|
//err = session.Table("Article").Find(&Article)
|
|
|
|
//if err != nil {
|
|
|
|
// return errors.New("查询系统物料失败, error:" + err.Error())
|
|
|
|
//}
|
|
|
|
|
|
|
|
dao_ArticleDemand := dal.NewArticleDemandDAO(session, PlantNr, UserId) |
|
|
|
articleDemandList, err := dao_ArticleDemand.Select([]grmi.Predicate{meta.ArticleDemand_CustomerId.NewPredicate(grmi.Equal, CustomerId)}, nil) |
|
|
|
if err != nil { |
|
|
|
_ = session.Rollback() |
|
|
|
return errors.New("查询物料需求数据失败, error:" + err.Error()) |
|
|
|
} |
|
|
|
|
|
|
|
var FMaterialIdList []int |
|
|
|
for _, articleInfo := range Article{ |
|
|
|
for _, articleDemandInfo := range articleDemandList{ |
|
|
|
if articleInfo.ArtId == articleDemandInfo.ArtId{ |
|
|
|
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{ |
|
|
|
for index, FMaterialId := range FMaterialIdList { |
|
|
|
if index > 0 { |
|
|
|
FilerString += " Or " |
|
|
|
} |
|
|
|
FMaterialIdS := strconv.Itoa(FMaterialId) |
|
|
|
FilerString += "FMaterialId = " + FMaterialIdS |
|
|
|
} |
|
|
|
|
|
|
|
dataList := utilService.PLN_PLANORDER_Init().Search(FilerString,"") |
|
|
|
dataList := utilService.PLN_PLANORDER_Init().Search(FilerString, "") |
|
|
|
|
|
|
|
articleQtyMap := make(map[string]float64) |
|
|
|
for _, info := range dataList { |
|
|
|
FMaterialId := info[0].(int) |
|
|
|
FMaterialId := info[0].(float64) |
|
|
|
var articleOne *model.Article |
|
|
|
_, err := session.Table("Article").Where("PlantNr = ? and UserId = ? and FMaterialId = ?", PlantNr, UserId,FMaterialId).Get(&articleOne) |
|
|
|
if err!=nil{ |
|
|
|
fmt.Println(err) |
|
|
|
session.Rollback() |
|
|
|
return |
|
|
|
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:" + strconv.Itoa(int(FMaterialId))) |
|
|
|
continue |
|
|
|
} |
|
|
|
articleQtyMap[articleOne.ArtId] = info[1].(float64) |
|
|
|
} |
|
|
|
|
|
|
|
for _, articleDemandInfo := range articleDemandList{ |
|
|
|
for _, articleDemandInfo := range articleDemandList { |
|
|
|
articleDemandInfo.WipQty = articleQtyMap[articleDemandInfo.ArtId] |
|
|
|
err := dao_ArticleDemand.UpdateOne(&articleDemandInfo) |
|
|
|
if err!=nil{ |
|
|
|
fmt.Println(err) |
|
|
|
session.Rollback() |
|
|
|
return |
|
|
|
if err != nil { |
|
|
|
_ = session.Rollback() |
|
|
|
return grmi.NewBusinessError("更新物料需求数据失败, error:" + err.Error()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
_ = session.Commit() |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
//外购量
|
|
|
|
//到货日期 入库数量 物料编码
|
|
|
|
func GetWaigouQty(PlantNr int,UserId string,CustomerId string){ |
|
|
|
func GetWaigouQty(PlantNr int, UserId string, CustomerId string, allData *[]model.Article) (err error) { |
|
|
|
engine := db.Eloquent.Master() |
|
|
|
session := engine.NewSession() |
|
|
|
defer session.Close() |
|
|
|
|
|
|
|
_ = session.Begin() |
|
|
|
|
|
|
|
Article := make([]model.Article, 0) |
|
|
|
session.Table("Article").Find(&Article) |
|
|
|
|
|
|
|
dao_ArticleDemand := dal.NewArticleDemandDAO(session, PlantNr,UserId) |
|
|
|
articleDemandList, err := dao_ArticleDemand.Select([]grmi.Predicate{meta.ArticleDemand_PlantNr.NewPredicate(grmi.Equal, PlantNr),meta.ArticleDemand_CustomerId.NewPredicate(grmi.Equal, CustomerId)}, nil) |
|
|
|
if err!=nil{ |
|
|
|
session.Rollback() |
|
|
|
if err = session.Begin(); err != nil { |
|
|
|
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{meta.ArticleDemand_PlantNr.NewPredicate(grmi.Equal, PlantNr), meta.ArticleDemand_CustomerId.NewPredicate(grmi.Equal, CustomerId)}, nil) |
|
|
|
if err != nil { |
|
|
|
_ = session.Rollback() |
|
|
|
return errors.New("查询物料需求数据失败, error:" + err.Error()) |
|
|
|
} |
|
|
|
|
|
|
|
var FMaterialIdList []int |
|
|
|
for _, articleInfo := range Article{ |
|
|
|
for _, articleDemandInfo := range articleDemandList{ |
|
|
|
if articleInfo.ArtId == articleDemandInfo.ArtId{ |
|
|
|
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{ |
|
|
|
for index, FMaterialId := range FMaterialIdList { |
|
|
|
if index > 0 { |
|
|
|
FilerString += " Or " |
|
|
|
} |
|
|
|
FMaterialIdS := strconv.Itoa(FMaterialId) |
|
|
|
FilerString += "FMaterialId = " + FMaterialIdS |
|
|
|
} |
|
|
|
|
|
|
|
dataList := utilService.PUR_Requisition_Init().Search(FilerString,"") |
|
|
|
dataList := utilService.PUR_Requisition_Init().Search(FilerString, "") |
|
|
|
articleQtyMap := make(map[string]float64) |
|
|
|
for _, info := range dataList { |
|
|
|
FMaterialId := info[0].(int) |
|
|
|
FMaterialId := info[0].(float64) |
|
|
|
var articleOne *model.Article |
|
|
|
_, err := session.Table("Article").Where("PlantNr = ? and UserId = ? and FMaterialId = ?", PlantNr, UserId,FMaterialId).Get(&articleOne) |
|
|
|
if err!=nil{ |
|
|
|
fmt.Println(err) |
|
|
|
session.Rollback() |
|
|
|
return |
|
|
|
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:" + strconv.Itoa(int(FMaterialId))) |
|
|
|
continue |
|
|
|
} |
|
|
|
articleQtyMap[articleOne.ArtId] = info[1].(float64) |
|
|
|
} |
|
|
|
|
|
|
|
for _, articleDemandInfo := range articleDemandList{ |
|
|
|
for _, articleDemandInfo := range articleDemandList { |
|
|
|
articleDemandInfo.OutSourcingQty = articleQtyMap[articleDemandInfo.ArtId] |
|
|
|
err := dao_ArticleDemand.UpdateOne(&articleDemandInfo) |
|
|
|
if err!=nil{ |
|
|
|
fmt.Println(err) |
|
|
|
session.Rollback() |
|
|
|
return |
|
|
|
if err != nil { |
|
|
|
_ = session.Rollback() |
|
|
|
return errors.New("更新物料需求数据失败, error:" + err.Error()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
_ = session.Commit() |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//独立需求
|
|
|
|
//需求日期 需求数量 物料编码
|
|
|
|
func GetDuliQty(PlantNr int,UserId string,CustomerId string){ |
|
|
|
func GetDuliQty(PlantNr int, UserId string, CustomerId string, allData *[]model.Article) (err error) { |
|
|
|
engine := db.Eloquent.Master() |
|
|
|
session := engine.NewSession() |
|
|
|
defer session.Close() |
|
|
|
|
|
|
|
_ = session.Begin() |
|
|
|
|
|
|
|
Article := make([]model.Article, 0) |
|
|
|
session.Table("Article").Find(&Article) |
|
|
|
|
|
|
|
dao_ArticleDemand := dal.NewArticleDemandDAO(session, PlantNr,UserId) |
|
|
|
articleDemandList, err := dao_ArticleDemand.Select([]grmi.Predicate{meta.ArticleDemand_PlantNr.NewPredicate(grmi.Equal, PlantNr),meta.ArticleDemand_CustomerId.NewPredicate(grmi.Equal, CustomerId)}, nil) |
|
|
|
if err!=nil{ |
|
|
|
session.Rollback() |
|
|
|
if err = session.Begin(); err != nil { |
|
|
|
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{meta.ArticleDemand_CustomerId.NewPredicate(grmi.Equal, CustomerId)}, nil) |
|
|
|
if err != nil { |
|
|
|
_ = session.Rollback() |
|
|
|
return errors.New("查询系统物料需求数据失败, error:" + err.Error()) |
|
|
|
} |
|
|
|
var FMaterialIdList []int |
|
|
|
for _, articleInfo := range Article{ |
|
|
|
for _, articleDemandInfo := range articleDemandList{ |
|
|
|
if articleInfo.ArtId == articleDemandInfo.ArtId{ |
|
|
|
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{ |
|
|
|
for index, FMaterialId := range FMaterialIdList { |
|
|
|
if index > 0 { |
|
|
|
FilerString += " Or " |
|
|
|
} |
|
|
|
FMaterialIdS := strconv.Itoa(FMaterialId) |
|
|
|
FilerString += "FMaterialId = " + FMaterialIdS |
|
|
|
} |
|
|
|
|
|
|
|
dataList := utilService.REM_IndepenReqPlan_Init().Search(FilerString,"") |
|
|
|
dataList := utilService.REM_IndepenReqPlan_Init().Search(FilerString, "") |
|
|
|
articleQtyMap := make(map[string]float64) |
|
|
|
for _, info := range dataList { |
|
|
|
FMaterialId := info[0].(int) |
|
|
|
FMaterialId := info[0].(float64) |
|
|
|
var articleOne *model.Article |
|
|
|
_, err := session.Table("Article").Where("PlantNr = ? and UserId = ? and FMaterialId = ?", PlantNr, UserId,FMaterialId).Get(&articleOne) |
|
|
|
if err!=nil{ |
|
|
|
fmt.Println(err) |
|
|
|
session.Rollback() |
|
|
|
return |
|
|
|
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:" + strconv.Itoa(int(FMaterialId))) |
|
|
|
continue |
|
|
|
} |
|
|
|
articleQtyMap[articleOne.ArtId] = info[1].(float64) |
|
|
|
} |
|
|
|
|
|
|
|
for _, articleDemandInfo := range articleDemandList{ |
|
|
|
for _, articleDemandInfo := range articleDemandList { |
|
|
|
articleDemandInfo.IndependentDemandQty = articleQtyMap[articleDemandInfo.ArtId] |
|
|
|
err := dao_ArticleDemand.UpdateOne(&articleDemandInfo) |
|
|
|
if err!=nil{ |
|
|
|
fmt.Println(err) |
|
|
|
session.Rollback() |
|
|
|
return |
|
|
|
err = dao_ArticleDemand.UpdateOne(&articleDemandInfo) |
|
|
|
if err != nil { |
|
|
|
_ = session.Rollback() |
|
|
|
return errors.New("更新系统物料需求数据失败, error:" + err.Error()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
_ = session.Commit() |
|
|
|
return nil |
|
|
|
} |