...
|
...
|
@@ -6,8 +6,12 @@ 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/productPlan/command"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productPlan/dto"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productPlan/query"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
// 生产计划服务
|
...
|
...
|
@@ -15,8 +19,8 @@ type ProductPlanService struct { |
|
|
}
|
|
|
|
|
|
// 创建生产计划服务
|
|
|
func (productPlanService *ProductPlanService) CreateProductPlan(createProductPlanCommand *command.CreateProductPlanCommand) (interface{}, error) {
|
|
|
if err := createProductPlanCommand.ValidateCommand(); err != nil {
|
|
|
func (productPlanService *ProductPlanService) CreateProductPlan(cmd *command.CreateProductPlanCommand) (interface{}, error) {
|
|
|
if err := cmd.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
...
|
...
|
@@ -29,34 +33,55 @@ func (productPlanService *ProductPlanService) CreateProductPlan(createProductPla |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
newProductPlan := &domain.ProductPlan{
|
|
|
CompanyId: createProductPlanCommand.CompanyId,
|
|
|
OrgId: createProductPlanCommand.OrgId,
|
|
|
//WorkshopId: createProductPlanCommand.WorkshopId,
|
|
|
BatchNumber: createProductPlanCommand.BatchNumber,
|
|
|
ProductDate: createProductPlanCommand.ProductDate,
|
|
|
WorkOn: createProductPlanCommand.WorkOn,
|
|
|
Machine: createProductPlanCommand.Machine,
|
|
|
PlanProductName: createProductPlanCommand.PlanProductName,
|
|
|
//PlanDevoted: createProductPlanCommand.PlanDevoted,
|
|
|
Remark: createProductPlanCommand.Remark,
|
|
|
}
|
|
|
var productPlanRepository domain.ProductPlanRepository
|
|
|
if value, err := factory.CreateProductPlanRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
var productPlan *domain.ProductPlan
|
|
|
productPlanRepository, _, _ = factory.FastPgProductPlan(transactionContext, 0)
|
|
|
// 检查批次号是否有重复的
|
|
|
if item, err := productPlanRepository.FindOne(map[string]interface{}{"companyId": cmd.CompanyId, "orgId": cmd.OrgId, "batchNumber": cmd.BatchNumber}); err == nil && item != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "批次号重复")
|
|
|
}
|
|
|
|
|
|
_, workshop, err := factory.FastPgWorkshop(transactionContext, cmd.WorkshopId)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
var userService = domainService.NewUserService()
|
|
|
var org *domain.Org
|
|
|
org, err = userService.Organization(cmd.OrgId)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
productPlanRepository = value
|
|
|
}
|
|
|
if productPlan, err := productPlanRepository.Save(newProductPlan); err != nil {
|
|
|
|
|
|
newProductPlan := &domain.ProductPlan{
|
|
|
CompanyId: cmd.CompanyId,
|
|
|
OrgId: cmd.OrgId,
|
|
|
BatchNumber: cmd.BatchNumber,
|
|
|
ProductDate: cmd.ProductDateTime,
|
|
|
Workshop: workshop.CloneSample(),
|
|
|
WorkOn: cmd.WorkOn,
|
|
|
Machine: cmd.Machine,
|
|
|
PlanProductName: cmd.PlanProductName,
|
|
|
PlanDevoted: &domain.UnitQuantity{
|
|
|
Unit: cmd.Unit,
|
|
|
Quantity: cmd.Quantity,
|
|
|
Weight: cmd.Weight,
|
|
|
},
|
|
|
PlanStatus: domain.PlanOffline,
|
|
|
WorkStation: &domain.WorkStation{},
|
|
|
Remark: cmd.Remark,
|
|
|
CreatedAt: time.Now(),
|
|
|
UpdatedAt: time.Now(),
|
|
|
Ext: domain.NewExt(org.OrgName),
|
|
|
}
|
|
|
if productPlan, err = productPlanRepository.Save(newProductPlan); 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 productPlan, nil
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
// 返回生产计划服务
|
...
|
...
|
@@ -92,7 +117,9 @@ func (productPlanService *ProductPlanService) GetProductPlan(getProductPlanQuery |
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return productPlan, nil
|
|
|
result := &dto.ProductPlanDto{}
|
|
|
result.LoadDto(productPlan, 0)
|
|
|
return result, nil
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
@@ -341,6 +368,46 @@ func (productPlanService *ProductPlanService) UpdateProductPlan(updateProductPla |
|
|
}
|
|
|
}
|
|
|
|
|
|
// 搜索生产计划服务列表
|
|
|
func (productPlanService *ProductPlanService) SearchProductPlan(operateInfo *domain.OperateInfo, cmd *query.SearchProductPlanQuery) (int64, interface{}, error) {
|
|
|
if err := cmd.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 productPlanRepository domain.ProductPlanRepository
|
|
|
if value, err := factory.CreateProductPlanRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
productPlanRepository = value
|
|
|
}
|
|
|
count, productPlans, err := productPlanRepository.Find(utils.ObjectToMap(cmd))
|
|
|
if err != nil {
|
|
|
return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
var result = make([]*dto.ProductPlanDto, 0)
|
|
|
for i := range productPlans {
|
|
|
item := productPlans[i]
|
|
|
newItem := &dto.ProductPlanDto{}
|
|
|
newItem.LoadDto(item, operateInfo.OrgId)
|
|
|
result = append(result, newItem)
|
|
|
}
|
|
|
return count, result, nil
|
|
|
}
|
|
|
|
|
|
func NewProductPlanService(options map[string]interface{}) *ProductPlanService {
|
|
|
newProductPlanService := &ProductPlanService{}
|
|
|
return newProductPlanService
|
...
|
...
|
|