作者 tangxvhui

更新

... ... @@ -9,12 +9,29 @@ import (
)
type CreateProductRecordCommand struct {
// 生产记录ID
ProductRecordId int `cname:"生产记录ID" json:"productRecordId" valid:"Required"`
// 企业id
CompanyId int `cname:"企业id" json:"companyId" valid:"Required"`
// 组织ID
OrgId int `cname:"组织ID" json:"orgId" valid:"Required"`
// 车间ID
WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
// 生产线ID
LineId int `cname:"生产线ID" json:"lineId" valid:"Required"`
// 工段ID
SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"`
WorkerId int `cname:"工人ID" json:"workId" valid:"Required"`
//生气计划id
ProductPlanId int `cname:"生气计划id" json:"productPlanId" valid:"Required"`
CreatedDate string `cname:"日期" json:"createdDate" valid:"Required"`
//重量
Weigh float64 ``
}
func (createProductRecordCommand *CreateProductRecordCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (createProductRecordCommand *CreateProductRecordCommand) ValidateCommand() error {
... ...
... ... @@ -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
}
... ...
... ... @@ -3,13 +3,14 @@ package domainService
import (
"errors"
"fmt"
"time"
"github.com/linmadan/egglib-go/core/application"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/repository"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
"time"
)
type PGProductRecordService struct {
... ... @@ -37,6 +38,8 @@ type SubmitOptions struct {
UnitConversionId int `cname:"物料ID" json:"unitConversionId"`
// 重量
Weigh float64 `cname:"重量" json:"weigh" valid:"Required"`
//日期
CreatedAt time.Time `cname:"日期" json:"createdAt" `
}
// SubmitProductRecord 提交生产记录
... ... @@ -127,6 +130,12 @@ func (ptr *PGProductRecordService) SubmitProductRecord(productRecordType int, qu
},
Ext: domain.NewExt(org.OrgName),
}
if !request.CreatedAt.IsZero() {
//管理页面上手动添加记录时,有填写日期
record.CreatedAt = request.CreatedAt
}
if record, err = productRecordRepository.Save(record); err != nil {
return nil, err
}
... ...