...
|
...
|
@@ -11,6 +11,7 @@ import ( |
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productMaterial/query"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
// 生产物料服务
|
...
|
...
|
@@ -90,15 +91,19 @@ func (productMaterialService *ProductMaterialService) GetProductMaterial(operate |
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getProductMaterialQuery.ProductMaterialId)))
|
|
|
} else {
|
|
|
materialService, _ := domainService.NewPGMaterialService(transactionContext.(*pgTransaction.TransactionContext))
|
|
|
ProductMaterialGroupIdName, _, err := materialService.AllMaterialGroupParent(operateInfo, productMaterial.ProductMaterialGroupId)
|
|
|
productMaterialGroupIdNames, _, err := materialService.AllMaterialGroupParent(operateInfo, productMaterial.ProductMaterialGroupId)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if len(ProductMaterialGroupIdName) == 0 {
|
|
|
if len(productMaterialGroupIdNames) == 0 {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
var productMaterialGroups []int
|
|
|
for _, productMaterialGroupIdName := range productMaterialGroupIdNames {
|
|
|
productMaterialGroups = append(productMaterialGroups, productMaterialGroupIdName.ProductMaterialGroupId)
|
|
|
}
|
|
|
one := dto.DtoProductMaterial(productMaterial)
|
|
|
one.ProductMaterialGroupIdName = ProductMaterialGroupIdName
|
|
|
one.ProductMaterialGroups = productMaterialGroups
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
...
|
...
|
@@ -156,7 +161,7 @@ func (productMaterialService *ProductMaterialService) ListProductMaterial(operat |
|
|
}
|
|
|
|
|
|
// 返回生产物料服务列表
|
|
|
func (productMaterialService *ProductMaterialService) SearchProductMaterial(operateInfo *domain.OperateInfo, listProductMaterialQuery *query.ListProductMaterialQuery) (int64, []*dto.DtoMaterial, error) {
|
|
|
func (productMaterialService *ProductMaterialService) SearchProductMaterial(operateInfo *domain.OperateInfo, listProductMaterialQuery *query.SearchProductMaterialQuery) (int64, []*dto.DtoMaterial, error) {
|
|
|
if err := listProductMaterialQuery.ValidateQuery(); err != nil {
|
|
|
return 0, nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
...
|
...
|
@@ -178,7 +183,7 @@ func (productMaterialService *ProductMaterialService) SearchProductMaterial(oper |
|
|
} else {
|
|
|
productMaterialRepository = value
|
|
|
}
|
|
|
var results []*dto.DtoMaterial
|
|
|
results := make([]*dto.DtoMaterial, 0)
|
|
|
if listProductMaterialQuery.ProductMaterialGroupId != 0 {
|
|
|
materialService, _ := domainService.NewPGMaterialService(transactionContext.(*pgTransaction.TransactionContext))
|
|
|
_, ProductMaterialGroupIds, err := materialService.AllMaterialGroupChild(operateInfo, listProductMaterialQuery.ProductMaterialGroupId)
|
...
|
...
|
@@ -256,45 +261,30 @@ func (productMaterialService *ProductMaterialService) UpdateProductMaterial(oper |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
var productMaterialRepository domain.ProductMaterialRepository
|
|
|
if value, err := factory.CreateProductMaterialRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
productMaterialRepository = value
|
|
|
}
|
|
|
productMaterial, err := productMaterialRepository.FindOne(map[string]interface{}{"productMaterialId": cmd.ProductMaterialId})
|
|
|
productMaterialRepository, productMaterial, err := factory.FastProductMaterial(transactionContext, cmd.ProductMaterialId)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if productMaterial == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(cmd.ProductMaterialId)))
|
|
|
}
|
|
|
newProductMaterial := &domain.ProductMaterial{ //赋值
|
|
|
ProductMaterialId: cmd.ProductMaterialId,
|
|
|
ProductMaterialGroupId: cmd.ProductMaterialGroupId,
|
|
|
MaterialName: cmd.MaterialName,
|
|
|
MaterialNumber: productMaterial.MaterialNumber,
|
|
|
MaterialAttribute: &domain.MaterialAttribute{Attribute: cmd.MaterialAttribute},
|
|
|
MaterialCategory: &domain.MaterialCategory{Category: cmd.MaterialCategory},
|
|
|
ProductMaterialExt: &domain.MaterialExt{
|
|
|
Specification: cmd.Specification,
|
|
|
Unit: cmd.Unit,
|
|
|
ExpiredDay: cmd.ExpiredDay,
|
|
|
Remark: cmd.Remark,
|
|
|
},
|
|
|
CreatedAt: productMaterial.CreatedAt,
|
|
|
}
|
|
|
materialService, _ := domainService.NewPGMaterialService(transactionContext.(*pgTransaction.TransactionContext))
|
|
|
data, err := materialService.UpdateMaterial(operateInfo, newProductMaterial)
|
|
|
if err != nil {
|
|
|
|
|
|
productMaterial.ProductMaterialGroupId = cmd.ProductMaterialGroupId
|
|
|
productMaterial.MaterialName = cmd.MaterialName
|
|
|
productMaterial.MaterialAttribute.Attribute = cmd.MaterialAttribute
|
|
|
productMaterial.MaterialCategory.Category = cmd.MaterialCategory
|
|
|
productMaterial.ProductMaterialExt = &domain.MaterialExt{
|
|
|
Specification: cmd.Specification,
|
|
|
Unit: cmd.Unit,
|
|
|
ExpiredDay: cmd.ExpiredDay,
|
|
|
Remark: cmd.Remark,
|
|
|
}
|
|
|
productMaterial.UpdatedAt = time.Now()
|
|
|
|
|
|
if _, err := productMaterialRepository.Save(productMaterial); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return data, nil
|
|
|
return struct{}{}, nil
|
|
|
}
|
|
|
|
|
|
// 批量移除生产物料服务
|
...
|
...
|
|