...
|
...
|
@@ -7,6 +7,7 @@ import ( |
|
|
"github.com/linmadan/egglib-go/utils/tool_funs"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productMaterial/command"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productMaterial/dto"
|
|
|
"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"
|
...
|
...
|
@@ -49,7 +50,7 @@ func (productMaterialService *ProductMaterialService) CreateProductMaterial(oper |
|
|
}
|
|
|
//var productMaterial *domain.ProductMaterial
|
|
|
materialService, _ := domainService.NewPGMaterialService(transactionContext.(*pgTransaction.TransactionContext))
|
|
|
if _, err = materialService.AddMaterial(operateInfo, newProductMaterial); err != nil {
|
|
|
if _, err := materialService.AddMaterial(operateInfo, newProductMaterial); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
...
|
...
|
@@ -58,8 +59,8 @@ func (productMaterialService *ProductMaterialService) CreateProductMaterial(oper |
|
|
return struct{}{}, nil
|
|
|
}
|
|
|
|
|
|
// 返回生产物料服务
|
|
|
func (productMaterialService *ProductMaterialService) GetProductMaterial(getProductMaterialQuery *query.GetProductMaterialQuery) (interface{}, error) {
|
|
|
// 返回生产物料服务单个
|
|
|
func (productMaterialService *ProductMaterialService) GetProductMaterial(operateInfo *domain.OperateInfo, getProductMaterialQuery *query.GetProductMaterialQuery) (interface{}, error) {
|
|
|
if err := getProductMaterialQuery.ValidateQuery(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
...
|
...
|
@@ -88,15 +89,25 @@ func (productMaterialService *ProductMaterialService) GetProductMaterial(getProd |
|
|
if productMaterial == nil {
|
|
|
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)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if len(ProductMaterialGroupIdName) == 0 {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
one := dto.DtoProductMaterial(productMaterial)
|
|
|
one.ProductMaterialGroupIdName = ProductMaterialGroupIdName
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return productMaterial, nil
|
|
|
return one, nil
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 返回生产物料服务列表
|
|
|
func (productMaterialService *ProductMaterialService) ListProductMaterial(listProductMaterialQuery *query.ListProductMaterialQuery) (interface{}, error) {
|
|
|
// 返回生产物料服务列表,未用
|
|
|
func (productMaterialService *ProductMaterialService) ListProductMaterial(operateInfo *domain.OperateInfo, listProductMaterialQuery *query.ListProductMaterialQuery) (interface{}, error) {
|
|
|
if err := listProductMaterialQuery.ValidateQuery(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
...
|
...
|
@@ -118,21 +129,80 @@ func (productMaterialService *ProductMaterialService) ListProductMaterial(listPr |
|
|
} else {
|
|
|
productMaterialRepository = value
|
|
|
}
|
|
|
var results []*dto.DtoMaterial
|
|
|
if listProductMaterialQuery.ProductMaterialGroupId != 0 {
|
|
|
materialService, _ := domainService.NewPGMaterialService(transactionContext.(*pgTransaction.TransactionContext))
|
|
|
_, ProductMaterialGroupIds, err := materialService.AllMaterialGroupChild(operateInfo, listProductMaterialQuery.ProductMaterialGroupId)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
listProductMaterialQuery.ProductMaterialGroupIds = ProductMaterialGroupIds
|
|
|
}
|
|
|
listProductMaterialQuery.CompanyId = operateInfo.CompanyId
|
|
|
if count, productMaterials, err := productMaterialRepository.Find(tool_funs.SimpleStructToMap(listProductMaterialQuery)); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
for _, productMaterial := range productMaterials {
|
|
|
results = append(results, dto.DtoProductMaterial(productMaterial))
|
|
|
}
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return map[string]interface{}{
|
|
|
"count": count,
|
|
|
"productMaterials": productMaterials,
|
|
|
"productMaterials": results,
|
|
|
}, nil
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 返回生产物料服务列表
|
|
|
func (productMaterialService *ProductMaterialService) SearchProductMaterial(operateInfo *domain.OperateInfo, listProductMaterialQuery *query.ListProductMaterialQuery) (int64, []*dto.DtoMaterial, error) {
|
|
|
if err := listProductMaterialQuery.ValidateQuery(); err != nil {
|
|
|
return 0, nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
if err := transactionContext.StartTransaction(); err != nil {
|
|
|
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
var productMaterialRepository domain.ProductMaterialRepository
|
|
|
if value, err := factory.CreateProductMaterialRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
productMaterialRepository = value
|
|
|
}
|
|
|
var results []*dto.DtoMaterial
|
|
|
if listProductMaterialQuery.ProductMaterialGroupId != 0 {
|
|
|
materialService, _ := domainService.NewPGMaterialService(transactionContext.(*pgTransaction.TransactionContext))
|
|
|
_, ProductMaterialGroupIds, err := materialService.AllMaterialGroupChild(operateInfo, listProductMaterialQuery.ProductMaterialGroupId)
|
|
|
if err != nil {
|
|
|
return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
listProductMaterialQuery.ProductMaterialGroupIds = ProductMaterialGroupIds
|
|
|
}
|
|
|
listProductMaterialQuery.CompanyId = operateInfo.CompanyId
|
|
|
count, productMaterials, err := productMaterialRepository.Find(tool_funs.SimpleStructToMap(listProductMaterialQuery))
|
|
|
if err != nil {
|
|
|
return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
for _, productMaterial := range productMaterials {
|
|
|
results = append(results, dto.DtoProductMaterial(productMaterial))
|
|
|
}
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return count, results, err
|
|
|
}
|
|
|
|
|
|
// 移除生产物料服务
|
|
|
func (productMaterialService *ProductMaterialService) RemoveProductMaterial(removeProductMaterialCommand *command.RemoveProductMaterialCommand) (interface{}, error) {
|
|
|
func (productMaterialService *ProductMaterialService) RemoveProductMaterial(operateInfo *domain.OperateInfo, removeProductMaterialCommand *command.RemoveProductMaterialCommand) (interface{}, error) {
|
|
|
if err := removeProductMaterialCommand.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
...
|
...
|
@@ -154,7 +224,7 @@ func (productMaterialService *ProductMaterialService) RemoveProductMaterial(remo |
|
|
} else {
|
|
|
productMaterialRepository = value
|
|
|
}
|
|
|
productMaterial, err := productMaterialRepository.FindOne(map[string]interface{}{"productMaterialId": removeProductMaterialCommand.ProductMaterialId})
|
|
|
productMaterial, err := productMaterialRepository.FindOne(map[string]interface{}{"companyId": operateInfo.CompanyId, "productMaterialId": removeProductMaterialCommand.ProductMaterialId})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
...
|
...
|
@@ -172,8 +242,8 @@ func (productMaterialService *ProductMaterialService) RemoveProductMaterial(remo |
|
|
}
|
|
|
|
|
|
// 更新生产物料服务
|
|
|
func (productMaterialService *ProductMaterialService) UpdateProductMaterial(updateProductMaterialCommand *command.UpdateProductMaterialCommand) (interface{}, error) {
|
|
|
if err := updateProductMaterialCommand.ValidateCommand(); err != nil {
|
|
|
func (productMaterialService *ProductMaterialService) UpdateProductMaterial(operateInfo *domain.OperateInfo, cmd *command.UpdateProductMaterialCommand) (interface{}, error) {
|
|
|
if err := cmd.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
...
|
...
|
@@ -194,24 +264,80 @@ func (productMaterialService *ProductMaterialService) UpdateProductMaterial(upda |
|
|
} else {
|
|
|
productMaterialRepository = value
|
|
|
}
|
|
|
productMaterial, err := productMaterialRepository.FindOne(map[string]interface{}{"productMaterialId": updateProductMaterialCommand.ProductMaterialId})
|
|
|
productMaterial, err := productMaterialRepository.FindOne(map[string]interface{}{"productMaterialId": 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(updateProductMaterialCommand.ProductMaterialId)))
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(cmd.ProductMaterialId)))
|
|
|
}
|
|
|
if err := productMaterial.Update(tool_funs.SimpleStructToMap(updateProductMaterialCommand)); err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
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,
|
|
|
}
|
|
|
if productMaterial, err := productMaterialRepository.Save(productMaterial); err != nil {
|
|
|
materialService, _ := domainService.NewPGMaterialService(transactionContext.(*pgTransaction.TransactionContext))
|
|
|
data, err := materialService.UpdateMaterial(operateInfo, newProductMaterial)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
}
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return productMaterial, nil
|
|
|
return data, nil
|
|
|
}
|
|
|
|
|
|
// 批量移除生产物料服务
|
|
|
func (productMaterialService *ProductMaterialService) BatchRemoveProductMaterial(operateInfo *domain.OperateInfo, batchRemoveProductMaterialCommand *command.BatchRemoveProductMaterialCommand) (interface{}, error) {
|
|
|
if err := batchRemoveProductMaterialCommand.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
if err := transactionContext.StartTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
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
|
|
|
}
|
|
|
for i := range batchRemoveProductMaterialCommand.ProductMaterialIds {
|
|
|
ProductMaterialId := batchRemoveProductMaterialCommand.ProductMaterialIds[i]
|
|
|
productMaterial, err := productMaterialRepository.FindOne(map[string]interface{}{"companyId": operateInfo.CompanyId, "productMaterialId": 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(ProductMaterialId)))
|
|
|
}
|
|
|
if _, err := productMaterialRepository.Remove(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 struct{}{}, nil
|
|
|
|
|
|
}
|
|
|
|
|
|
func NewProductMaterialService(options map[string]interface{}) *ProductMaterialService {
|
...
|
...
|
|