...
|
...
|
@@ -2,7 +2,10 @@ package service |
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
"time"
|
|
|
|
|
|
"github.com/linmadan/egglib-go/core/application"
|
|
|
"github.com/linmadan/egglib-go/transaction/pg"
|
|
|
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
|
|
|
"github.com/linmadan/egglib-go/utils/tool_funs"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
|
...
|
...
|
@@ -12,13 +15,17 @@ import ( |
|
|
"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"
|
|
|
)
|
|
|
|
|
|
// 生产记录服务
|
|
|
type ProductRecordService struct {
|
|
|
}
|
|
|
|
|
|
func NewProductRecordService(options map[string]interface{}) *ProductRecordService {
|
|
|
newProductRecordService := &ProductRecordService{}
|
|
|
return newProductRecordService
|
|
|
}
|
|
|
|
|
|
// 生产记录审核
|
|
|
func (productRecordService *ProductRecordService) ApproveProductRecord(cmd *command.ApproveProductRecordCommand) (interface{}, error) {
|
|
|
if err := cmd.ValidateCommand(); err != nil {
|
...
|
...
|
@@ -35,7 +42,7 @@ func (productRecordService *ProductRecordService) ApproveProductRecord(cmd *comm |
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
svr, err := domainService.NewPGProductRecordService(transactionContext.(*pgTransaction.TransactionContext))
|
|
|
svr, _ := domainService.NewPGProductRecordService(transactionContext.(*pgTransaction.TransactionContext))
|
|
|
if _, err = svr.Approve(cmd.ProductRecordId, cmd.ApproveUserId, cmd.WeighAfter, time.Now()); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
...
|
...
|
@@ -47,8 +54,8 @@ func (productRecordService *ProductRecordService) ApproveProductRecord(cmd *comm |
|
|
}
|
|
|
|
|
|
// 创建生产记录服务
|
|
|
func (productRecordService *ProductRecordService) CreateProductRecord(createProductRecordCommand *command.CreateProductRecordCommand) (interface{}, error) {
|
|
|
if err := createProductRecordCommand.ValidateCommand(); err != nil {
|
|
|
func (productRecordService *ProductRecordService) CreateProductRecord(param *command.CreateProductRecordCommand) (interface{}, error) {
|
|
|
if err := param.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
...
|
...
|
@@ -61,25 +68,29 @@ func (productRecordService *ProductRecordService) CreateProductRecord(createProd |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
newProductRecord := &domain.ProductRecord{
|
|
|
ProductRecordId: createProductRecordCommand.ProductRecordId,
|
|
|
}
|
|
|
var productRecordRepository domain.ProductRecordRepository
|
|
|
if value, err := factory.CreateProductRecordRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
productRecordDomainService, _ := domainService.NewPGProductRecordService(transactionContext.(*pg.TransactionContext))
|
|
|
submitProductRecordCommand := domainService.SubmitOptions{
|
|
|
CompanyId: param.CompanyId,
|
|
|
OrgId: param.OrgId,
|
|
|
ProductPlanId: param.ProductPlanId,
|
|
|
WorkshopId: param.WorkshopId,
|
|
|
LineId: param.LineId,
|
|
|
SectionId: param.SectionId,
|
|
|
ProductGroupId: 0,
|
|
|
EmployeeId: param.WorkerId,
|
|
|
UnitConversionId: 0,
|
|
|
Weigh: 0.0,
|
|
|
CreatedAt: time.Time{},
|
|
|
}
|
|
|
_, err = productRecordDomainService.SubmitProductRecord(domain.RecordTypeSecondLevelWeigh, tool_funs.SimpleStructToMap(submitProductRecordCommand))
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
productRecordRepository = value
|
|
|
}
|
|
|
if productRecord, err := productRecordRepository.Save(newProductRecord); 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 productRecord, nil
|
|
|
}
|
|
|
return nil, nil
|
|
|
|
|
|
}
|
|
|
|
|
|
// 返回生产记录服务
|
...
|
...
|
@@ -369,8 +380,3 @@ func (productRecordService *ProductRecordService) CancelProductRecord(cmd *comma |
|
|
}
|
|
|
return struct{}{}, nil
|
|
|
} |
|
|
|
|
|
func NewProductRecordService(options map[string]interface{}) *ProductRecordService {
|
|
|
newProductRecordService := &ProductRecordService{}
|
|
|
return newProductRecordService
|
|
|
} |
...
|
...
|
|