|
@@ -2,7 +2,10 @@ package service |
|
@@ -2,7 +2,10 @@ package service |
2
|
|
2
|
|
3
|
import (
|
3
|
import (
|
4
|
"fmt"
|
4
|
"fmt"
|
|
|
5
|
+ "time"
|
|
|
6
|
+
|
5
|
"github.com/linmadan/egglib-go/core/application"
|
7
|
"github.com/linmadan/egglib-go/core/application"
|
|
|
8
|
+ "github.com/linmadan/egglib-go/transaction/pg"
|
6
|
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
|
9
|
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
|
7
|
"github.com/linmadan/egglib-go/utils/tool_funs"
|
10
|
"github.com/linmadan/egglib-go/utils/tool_funs"
|
8
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
|
11
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
|
|
@@ -12,13 +15,17 @@ import ( |
|
@@ -12,13 +15,17 @@ import ( |
12
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
|
15
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
|
13
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService"
|
16
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService"
|
14
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
|
17
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
|
15
|
- "time"
|
|
|
16
|
)
|
18
|
)
|
17
|
|
19
|
|
18
|
// 生产记录服务
|
20
|
// 生产记录服务
|
19
|
type ProductRecordService struct {
|
21
|
type ProductRecordService struct {
|
20
|
}
|
22
|
}
|
21
|
|
23
|
|
|
|
24
|
+func NewProductRecordService(options map[string]interface{}) *ProductRecordService {
|
|
|
25
|
+ newProductRecordService := &ProductRecordService{}
|
|
|
26
|
+ return newProductRecordService
|
|
|
27
|
+}
|
|
|
28
|
+
|
22
|
// 生产记录审核
|
29
|
// 生产记录审核
|
23
|
func (productRecordService *ProductRecordService) ApproveProductRecord(cmd *command.ApproveProductRecordCommand) (interface{}, error) {
|
30
|
func (productRecordService *ProductRecordService) ApproveProductRecord(cmd *command.ApproveProductRecordCommand) (interface{}, error) {
|
24
|
if err := cmd.ValidateCommand(); err != nil {
|
31
|
if err := cmd.ValidateCommand(); err != nil {
|
|
@@ -35,7 +42,7 @@ func (productRecordService *ProductRecordService) ApproveProductRecord(cmd *comm |
|
@@ -35,7 +42,7 @@ func (productRecordService *ProductRecordService) ApproveProductRecord(cmd *comm |
35
|
transactionContext.RollbackTransaction()
|
42
|
transactionContext.RollbackTransaction()
|
36
|
}()
|
43
|
}()
|
37
|
|
44
|
|
38
|
- svr, err := domainService.NewPGProductRecordService(transactionContext.(*pgTransaction.TransactionContext))
|
45
|
+ svr, _ := domainService.NewPGProductRecordService(transactionContext.(*pgTransaction.TransactionContext))
|
39
|
if _, err = svr.Approve(cmd.ProductRecordId, cmd.ApproveUserId, cmd.WeighAfter, time.Now()); err != nil {
|
46
|
if _, err = svr.Approve(cmd.ProductRecordId, cmd.ApproveUserId, cmd.WeighAfter, time.Now()); err != nil {
|
40
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
47
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
41
|
}
|
48
|
}
|
|
@@ -47,8 +54,8 @@ func (productRecordService *ProductRecordService) ApproveProductRecord(cmd *comm |
|
@@ -47,8 +54,8 @@ func (productRecordService *ProductRecordService) ApproveProductRecord(cmd *comm |
47
|
}
|
54
|
}
|
48
|
|
55
|
|
49
|
// 创建生产记录服务
|
56
|
// 创建生产记录服务
|
50
|
-func (productRecordService *ProductRecordService) CreateProductRecord(createProductRecordCommand *command.CreateProductRecordCommand) (interface{}, error) {
|
|
|
51
|
- if err := createProductRecordCommand.ValidateCommand(); err != nil {
|
57
|
+func (productRecordService *ProductRecordService) CreateProductRecord(param *command.CreateProductRecordCommand) (interface{}, error) {
|
|
|
58
|
+ if err := param.ValidateCommand(); err != nil {
|
52
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
59
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
53
|
}
|
60
|
}
|
54
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
61
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
@@ -61,25 +68,29 @@ func (productRecordService *ProductRecordService) CreateProductRecord(createProd |
|
@@ -61,25 +68,29 @@ func (productRecordService *ProductRecordService) CreateProductRecord(createProd |
61
|
defer func() {
|
68
|
defer func() {
|
62
|
transactionContext.RollbackTransaction()
|
69
|
transactionContext.RollbackTransaction()
|
63
|
}()
|
70
|
}()
|
64
|
- newProductRecord := &domain.ProductRecord{
|
|
|
65
|
- ProductRecordId: createProductRecordCommand.ProductRecordId,
|
|
|
66
|
- }
|
|
|
67
|
- var productRecordRepository domain.ProductRecordRepository
|
|
|
68
|
- if value, err := factory.CreateProductRecordRepository(map[string]interface{}{
|
|
|
69
|
- "transactionContext": transactionContext,
|
|
|
70
|
- }); err != nil {
|
71
|
+ productRecordDomainService, _ := domainService.NewPGProductRecordService(transactionContext.(*pg.TransactionContext))
|
|
|
72
|
+ submitProductRecordCommand := domainService.SubmitOptions{
|
|
|
73
|
+ CompanyId: param.CompanyId,
|
|
|
74
|
+ OrgId: param.OrgId,
|
|
|
75
|
+ ProductPlanId: param.ProductPlanId,
|
|
|
76
|
+ WorkshopId: param.WorkshopId,
|
|
|
77
|
+ LineId: param.LineId,
|
|
|
78
|
+ SectionId: param.SectionId,
|
|
|
79
|
+ ProductGroupId: 0,
|
|
|
80
|
+ EmployeeId: param.WorkerId,
|
|
|
81
|
+ UnitConversionId: 0,
|
|
|
82
|
+ Weigh: 0.0,
|
|
|
83
|
+ CreatedAt: time.Time{},
|
|
|
84
|
+ }
|
|
|
85
|
+ _, err = productRecordDomainService.SubmitProductRecord(domain.RecordTypeSecondLevelWeigh, tool_funs.SimpleStructToMap(submitProductRecordCommand))
|
|
|
86
|
+ if err != nil {
|
71
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
87
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
72
|
- } else {
|
|
|
73
|
- productRecordRepository = value
|
|
|
74
|
}
|
88
|
}
|
75
|
- if productRecord, err := productRecordRepository.Save(newProductRecord); err != nil {
|
|
|
76
|
- return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
77
|
- } else {
|
|
|
78
|
- if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
79
|
- return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
80
|
- }
|
|
|
81
|
- return productRecord, nil
|
89
|
+ if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
90
|
+ return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
82
|
}
|
91
|
}
|
|
|
92
|
+ return nil, nil
|
|
|
93
|
+
|
83
|
}
|
94
|
}
|
84
|
|
95
|
|
85
|
// 返回生产记录服务
|
96
|
// 返回生产记录服务
|
|
@@ -369,8 +380,3 @@ func (productRecordService *ProductRecordService) CancelProductRecord(cmd *comma |
|
@@ -369,8 +380,3 @@ func (productRecordService *ProductRecordService) CancelProductRecord(cmd *comma |
369
|
}
|
380
|
}
|
370
|
return struct{}{}, nil
|
381
|
return struct{}{}, nil
|
371
|
} |
382
|
} |
372
|
-
|
|
|
373
|
-func NewProductRecordService(options map[string]interface{}) *ProductRecordService {
|
|
|
374
|
- newProductRecordService := &ProductRecordService{}
|
|
|
375
|
- return newProductRecordService
|
|
|
376
|
-} |
|
|