...
|
...
|
@@ -7,9 +7,11 @@ 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"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
// 生产物料服务
|
...
|
...
|
@@ -49,7 +51,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 +60,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 +90,29 @@ 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))
|
|
|
productMaterialGroupIdNames, _, err := materialService.AllMaterialGroupParent(operateInfo, productMaterial.ProductMaterialGroupId)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
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.ProductMaterialGroups = productMaterialGroups
|
|
|
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 +134,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.SearchProductMaterialQuery) (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
|
|
|
}
|
|
|
results := make([]*dto.DtoMaterial, 0)
|
|
|
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 +229,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 +247,49 @@ 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)
|
|
|
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()
|
|
|
}()
|
|
|
productMaterialRepository, productMaterial, err := factory.FastProductMaterial(transactionContext, cmd.ProductMaterialId)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
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 struct{}{}, 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)
|
...
|
...
|
@@ -194,24 +310,24 @@ func (productMaterialService *ProductMaterialService) UpdateProductMaterial(upda |
|
|
} else {
|
|
|
productMaterialRepository = value
|
|
|
}
|
|
|
productMaterial, err := productMaterialRepository.FindOne(map[string]interface{}{"productMaterialId": updateProductMaterialCommand.ProductMaterialId})
|
|
|
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(updateProductMaterialCommand.ProductMaterialId)))
|
|
|
}
|
|
|
if err := productMaterial.Update(tool_funs.SimpleStructToMap(updateProductMaterialCommand)); err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(ProductMaterialId)))
|
|
|
}
|
|
|
if productMaterial, err := productMaterialRepository.Save(productMaterial); err != nil {
|
|
|
if _, err := productMaterialRepository.Remove(productMaterial); 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 struct{}{}, nil
|
|
|
|
|
|
}
|
|
|
|
|
|
func NewProductMaterialService(options map[string]interface{}) *ProductMaterialService {
|
...
|
...
|
|