作者 tangxvhui

更新

@@ -9,12 +9,29 @@ import ( @@ -9,12 +9,29 @@ import (
9 ) 9 )
10 10
11 type CreateProductRecordCommand struct { 11 type CreateProductRecordCommand struct {
12 - // 生产记录ID  
13 - ProductRecordId int `cname:"生产记录ID" json:"productRecordId" valid:"Required"` 12 + // 企业id
  13 + CompanyId int `cname:"企业id" json:"companyId" valid:"Required"`
  14 + // 组织ID
  15 + OrgId int `cname:"组织ID" json:"orgId" valid:"Required"`
  16 + // 车间ID
  17 + WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
  18 + // 生产线ID
  19 + LineId int `cname:"生产线ID" json:"lineId" valid:"Required"`
  20 + // 工段ID
  21 + SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"`
  22 +
  23 + WorkerId int `cname:"工人ID" json:"workId" valid:"Required"`
  24 +
  25 + //生气计划id
  26 + ProductPlanId int `cname:"生气计划id" json:"productPlanId" valid:"Required"`
  27 +
  28 + CreatedDate string `cname:"日期" json:"createdDate" valid:"Required"`
  29 + //重量
  30 + Weigh float64 ``
14 } 31 }
15 32
16 func (createProductRecordCommand *CreateProductRecordCommand) Valid(validation *validation.Validation) { 33 func (createProductRecordCommand *CreateProductRecordCommand) Valid(validation *validation.Validation) {
17 - validation.SetError("CustomValid", "未实现的自定义认证") 34 +
18 } 35 }
19 36
20 func (createProductRecordCommand *CreateProductRecordCommand) ValidateCommand() error { 37 func (createProductRecordCommand *CreateProductRecordCommand) ValidateCommand() error {
@@ -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 -}  
@@ -3,13 +3,14 @@ package domainService @@ -3,13 +3,14 @@ package domainService
3 import ( 3 import (
4 "errors" 4 "errors"
5 "fmt" 5 "fmt"
  6 + "time"
  7 +
6 "github.com/linmadan/egglib-go/core/application" 8 "github.com/linmadan/egglib-go/core/application"
7 pgTransaction "github.com/linmadan/egglib-go/transaction/pg" 9 pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" 10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
9 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/repository" 11 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/repository"
10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" 12 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
11 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log" 13 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
12 - "time"  
13 ) 14 )
14 15
15 type PGProductRecordService struct { 16 type PGProductRecordService struct {
@@ -37,6 +38,8 @@ type SubmitOptions struct { @@ -37,6 +38,8 @@ type SubmitOptions struct {
37 UnitConversionId int `cname:"物料ID" json:"unitConversionId"` 38 UnitConversionId int `cname:"物料ID" json:"unitConversionId"`
38 // 重量 39 // 重量
39 Weigh float64 `cname:"重量" json:"weigh" valid:"Required"` 40 Weigh float64 `cname:"重量" json:"weigh" valid:"Required"`
  41 + //日期
  42 + CreatedAt time.Time `cname:"日期" json:"createdAt" `
40 } 43 }
41 44
42 // SubmitProductRecord 提交生产记录 45 // SubmitProductRecord 提交生产记录
@@ -127,6 +130,12 @@ func (ptr *PGProductRecordService) SubmitProductRecord(productRecordType int, qu @@ -127,6 +130,12 @@ func (ptr *PGProductRecordService) SubmitProductRecord(productRecordType int, qu
127 }, 130 },
128 Ext: domain.NewExt(org.OrgName), 131 Ext: domain.NewExt(org.OrgName),
129 } 132 }
  133 +
  134 + if !request.CreatedAt.IsZero() {
  135 + //管理页面上手动添加记录时,有填写日期
  136 + record.CreatedAt = request.CreatedAt
  137 + }
  138 +
130 if record, err = productRecordRepository.Save(record); err != nil { 139 if record, err = productRecordRepository.Save(record); err != nil {
131 return nil, err 140 return nil, err
132 } 141 }