...
|
...
|
@@ -4,6 +4,7 @@ import ( |
|
|
"fmt"
|
|
|
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/dao"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/repository"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
|
|
|
"sort"
|
...
|
...
|
@@ -66,6 +67,10 @@ func (ptr *PGMaterialService) AddMaterialGroup(opt *domain.OperateInfo, item *do |
|
|
parent *domain.ProductMaterialGroup
|
|
|
newProductMaterialGroup *domain.ProductMaterialGroup
|
|
|
productMaterialGroupRepository, _ = repository.NewProductMaterialGroupRepository(ptr.transactionContext)
|
|
|
|
|
|
productMaterialGroupDao *dao.ProductMaterialGroupDao
|
|
|
latestNumber string
|
|
|
total int
|
|
|
)
|
|
|
if user, err = NewUserService().User(opt.UserId); err != nil {
|
|
|
return nil, err
|
...
|
...
|
@@ -81,6 +86,12 @@ func (ptr *PGMaterialService) AddMaterialGroup(opt *domain.OperateInfo, item *do |
|
|
if newProductMaterialGroup, err = productMaterialGroupRepository.FindOne(map[string]interface{}{"companyId": opt.CompanyId, "materialGroupNumber": item.MaterialGroupNumber}); err == nil || newProductMaterialGroup != nil {
|
|
|
return nil, fmt.Errorf("物料分组编码已存在")
|
|
|
}
|
|
|
productMaterialGroupDao, _ = dao.NewProductMaterialGroupDao(ptr.transactionContext)
|
|
|
latestNumber, total, err = productMaterialGroupDao.CurrentGroupLatestNumber(opt.CompanyId, item.Pid)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
newProductMaterialGroup = &domain.ProductMaterialGroup{
|
|
|
CompanyId: opt.CompanyId,
|
|
|
OrgId: opt.OrgId,
|
...
|
...
|
@@ -92,16 +103,17 @@ func (ptr *PGMaterialService) AddMaterialGroup(opt *domain.OperateInfo, item *do |
|
|
UpdatedAt: time.Now(),
|
|
|
Ext: domain.NewExt(org.OrgName).WithOperator(user),
|
|
|
}
|
|
|
newProductMaterialGroup.MaterialGroupNumber = newProductMaterialGroup.GroupNumberComposeUp(parent, latestNumber, total)
|
|
|
newProductMaterialGroup, err = productMaterialGroupRepository.Save(newProductMaterialGroup)
|
|
|
return newProductMaterialGroup, err
|
|
|
}
|
|
|
|
|
|
func (ptr *PGMaterialService) UpdateMaterialGroup(opt *domain.OperateInfo, item *domain.ProductMaterialGroup) (*domain.ProductMaterialGroup, error) {
|
|
|
var (
|
|
|
user *domain.User
|
|
|
org *domain.Org
|
|
|
err error
|
|
|
parent *domain.ProductMaterialGroup
|
|
|
user *domain.User
|
|
|
org *domain.Org
|
|
|
err error
|
|
|
//parent *domain.ProductMaterialGroup
|
|
|
productMaterialGroup *domain.ProductMaterialGroup
|
|
|
productMaterialGroupRepository, _ = repository.NewProductMaterialGroupRepository(ptr.transactionContext)
|
|
|
)
|
...
|
...
|
@@ -111,24 +123,25 @@ func (ptr *PGMaterialService) UpdateMaterialGroup(opt *domain.OperateInfo, item |
|
|
if org, err = NewUserService().Organization(opt.OrgId); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
if item.ProductMaterialGroupId == item.Pid {
|
|
|
return nil, fmt.Errorf("当前物料分组不能做为自己上级")
|
|
|
}
|
|
|
//if item.ProductMaterialGroupId == item.Pid {
|
|
|
// return nil, fmt.Errorf("当前物料分组不能做为自己上级")
|
|
|
//}
|
|
|
if productMaterialGroup, err = productMaterialGroupRepository.FindOne(map[string]interface{}{"companyId": opt.CompanyId, "productMaterialGroupId": item.ProductMaterialGroupId}); err != nil || productMaterialGroup == nil {
|
|
|
return nil, fmt.Errorf("物料分组不存在")
|
|
|
}
|
|
|
if item.Pid != productMaterialGroup.ProductMaterialGroupId && item.Pid != 0 {
|
|
|
if parent, err = productMaterialGroupRepository.FindOne(map[string]interface{}{"companyId": opt.CompanyId, "productMaterialGroupId": item.Pid}); err != nil || parent == nil {
|
|
|
return nil, fmt.Errorf("上级物料分组不存在")
|
|
|
}
|
|
|
}
|
|
|
if productMaterialGroup.MaterialGroupNumber != item.MaterialGroupNumber {
|
|
|
if group, err := productMaterialGroupRepository.FindOne(map[string]interface{}{"companyId": opt.CompanyId, "materialGroupNumber": item.MaterialGroupNumber}); err == nil || group != nil {
|
|
|
return nil, fmt.Errorf("物料分组编码已存在")
|
|
|
}
|
|
|
}
|
|
|
|
|
|
productMaterialGroup.MaterialGroupNumber = item.MaterialGroupNumber
|
|
|
//if item.Pid != productMaterialGroup.ProductMaterialGroupId && item.Pid != 0 {
|
|
|
// if parent, err = productMaterialGroupRepository.FindOne(map[string]interface{}{"companyId": opt.CompanyId, "productMaterialGroupId": item.Pid}); err != nil || parent == nil {
|
|
|
// return nil, fmt.Errorf("上级物料分组不存在")
|
|
|
// }
|
|
|
//}
|
|
|
//if productMaterialGroup.MaterialGroupNumber != item.MaterialGroupNumber {
|
|
|
// if group, err := productMaterialGroupRepository.FindOne(map[string]interface{}{"companyId": opt.CompanyId, "materialGroupNumber": item.MaterialGroupNumber}); err == nil || group != nil {
|
|
|
// return nil, fmt.Errorf("物料分组编码已存在")
|
|
|
// }
|
|
|
//}
|
|
|
//productMaterialGroup.MaterialGroupNumber = item.MaterialGroupNumber
|
|
|
|
|
|
productMaterialGroup.MaterialGroupName = item.MaterialGroupName
|
|
|
productMaterialGroup.UpdatedAt = item.UpdatedAt
|
|
|
productMaterialGroup.Ext = domain.NewExt(org.OrgName).WithOperator(user)
|
...
|
...
|
|