|
|
@ -3,11 +3,14 @@ |
|
|
|
package implments |
|
|
|
|
|
|
|
import ( |
|
|
|
"fmt" |
|
|
|
baseDal "leit.com/LAPP_CHEERSSON_BACKEND/dao/base" |
|
|
|
dal "leit.com/LAPP_CHEERSSON_BACKEND/dao/me" |
|
|
|
"leit.com/LAPP_CHEERSSON_BACKEND/db" |
|
|
|
"leit.com/LAPP_CHEERSSON_BACKEND/global" |
|
|
|
"leit.com/LAPP_CHEERSSON_BACKEND/grmi" |
|
|
|
meta "leit.com/LAPP_CHEERSSON_BACKEND/meta/me" |
|
|
|
baseModel "leit.com/LAPP_CHEERSSON_BACKEND/models/base" |
|
|
|
model "leit.com/LAPP_CHEERSSON_BACKEND/models/me" |
|
|
|
) |
|
|
|
|
|
|
@ -112,18 +115,98 @@ func (impl *BomLstServiceImplement) InsertOne(user *global.User, entity *model.B |
|
|
|
engine := db.Eloquent.Master() |
|
|
|
session := engine.NewSession() |
|
|
|
defer session.Close() |
|
|
|
if err := session.Begin(); err != nil { |
|
|
|
fmt.Println(err.Error()) |
|
|
|
return err |
|
|
|
} |
|
|
|
dao := dal.NewBomLstDAO(session, user.PlantNr, user.UserId) |
|
|
|
headDao := dal.NewBomHeadDAO(session, user.PlantNr, user.UserId) |
|
|
|
record, err := dao.SelectOne(entity.BomId, entity.FmatNr, entity.CmatNr) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
if record != nil { |
|
|
|
_ = session.Rollback() |
|
|
|
return grmi.NewBusinessError("已经存在相同主键的记录!") |
|
|
|
} |
|
|
|
err = dao.InsertOne(entity) |
|
|
|
if err != nil { |
|
|
|
_ = session.Rollback() |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
articleDao := baseDal.NewArticleDAO(session, user.PlantNr, user.UserId) |
|
|
|
article, err := articleDao.SelectOne(entity.FmatNr) |
|
|
|
if err != nil { |
|
|
|
_ = session.Rollback() |
|
|
|
return grmi.NewBusinessError("查询物料数据失败, error:" + err.Error()) |
|
|
|
} |
|
|
|
if article == nil { |
|
|
|
_ = session.Rollback() |
|
|
|
return grmi.NewBusinessError("不存在对应的物料数据") |
|
|
|
} |
|
|
|
if article.ArtSpec1 != baseModel.ART_TYPE_FINISHED && article.ArtSpec1 != baseModel.ART_TYPE_VIRTUAL { |
|
|
|
_ = session.Rollback() |
|
|
|
return grmi.NewBusinessError("传递的物料不是总成或虚拟物料ID,artId:" + article.ArtId) |
|
|
|
} |
|
|
|
|
|
|
|
article2, err := articleDao.SelectOne(entity.CmatNr) |
|
|
|
if err != nil { |
|
|
|
_ = session.Rollback() |
|
|
|
return grmi.NewBusinessError("查询物料数据失败, error:" + err.Error()) |
|
|
|
} |
|
|
|
if article2 == nil { |
|
|
|
_ = session.Rollback() |
|
|
|
return grmi.NewBusinessError("不存在对应的物料数据") |
|
|
|
} |
|
|
|
//if article.ArtSpec1 == baseModel.ART_TYPE_VIRTUAL{
|
|
|
|
// if article2.ArtSpec1 != baseModel.ART_TYPE_FINISHED {
|
|
|
|
// _ = session.Rollback()
|
|
|
|
// return grmi.NewBusinessError("传递的子物料不是总成, artId:" + article2.ArtId)
|
|
|
|
// }
|
|
|
|
//} else {
|
|
|
|
// if article2.ArtSpec1 == baseModel.ART_TYPE_FINISHED || article2.ArtSpec1 == baseModel.ART_TYPE_VIRTUAL {
|
|
|
|
// _ = session.Rollback()
|
|
|
|
// return grmi.NewBusinessError("传递的物料是总成或虚拟物料ID, artId:" + article2.ArtId)
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
if entity.FmatNr == entity.CmatNr{ |
|
|
|
_ = session.Rollback() |
|
|
|
return grmi.NewBusinessError("上级和下级物料ID相同") |
|
|
|
} |
|
|
|
bomHead, err := headDao.SelectOne(entity.BomId) |
|
|
|
if err != nil { |
|
|
|
_ = session.Rollback() |
|
|
|
return err |
|
|
|
} |
|
|
|
if bomHead == nil { |
|
|
|
article, err := articleDao.SelectOne(entity.BomId) |
|
|
|
if err != nil { |
|
|
|
_ = session.Rollback() |
|
|
|
return err |
|
|
|
} |
|
|
|
if article == nil { |
|
|
|
_ = session.Rollback() |
|
|
|
return grmi.NewBusinessError("总成不存在") |
|
|
|
} |
|
|
|
if article.ArtSpec1 != baseModel.ART_TYPE_FINISHED && article.ArtSpec1 != baseModel.ART_TYPE_VIRTUAL { |
|
|
|
_ = session.Rollback() |
|
|
|
return grmi.NewBusinessError("传递的物料不是总成或虚拟物料ID") |
|
|
|
} |
|
|
|
headData := model.BomHead{ |
|
|
|
BomId: entity.BomId, |
|
|
|
MatNr: entity.BomId, |
|
|
|
Descr: article.Descr1, |
|
|
|
} |
|
|
|
err = headDao.InsertOne(&headData) |
|
|
|
if err != nil { |
|
|
|
_ = session.Rollback() |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
_ = session.Commit() |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|