|
|
package domainService
|
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
"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"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
type PGProductRecordService struct {
|
|
|
transactionContext *pgTransaction.TransactionContext
|
|
|
}
|
|
|
|
|
|
type SubmitOptions struct {
|
|
|
// 企业id
|
|
|
CompanyId int `cname:"企业id" json:"companyId" valid:"Required"`
|
|
|
// 组织ID
|
|
|
OrgId int `cname:"组织ID" json:"orgId" valid:"Required"`
|
|
|
// 生产计划ID
|
|
|
ProductPlanId int `cname:"生产计划" json:"productPlanId" valid:"Required"`
|
|
|
// 车间ID
|
|
|
WorkshopId int `cname:"车间" json:"workshopId" valid:"Required"`
|
|
|
// 生产线ID
|
|
|
LineId int `cname:"生产线" json:"lineId" valid:"Required"`
|
|
|
// 工段ID
|
|
|
SectionId int `cname:"工段" json:"sectionId" valid:"Required"`
|
|
|
// 生产小组ID
|
|
|
ProductGroupId int `cname:"生产小组" json:"productGroupId" valid:"Required"`
|
|
|
// 员工Id 用户唯一标识
|
|
|
EmployeeId int `cname:"员工" json:"employeeId" valid:"Required"`
|
|
|
// 物料ID
|
|
|
UnitConversionId int `cname:"物料ID" json:"unitConversionId" valid:"Required"`
|
|
|
// 重量
|
|
|
Weigh float64 `cname:"重量" json:"weigh" valid:"Required"`
|
|
|
}
|
|
|
|
|
|
// SubmitProductRecord 提交生产记录
|
|
|
func (ptr *PGProductRecordService) SubmitProductRecord(productRecordType int, queryOptions map[string]interface{}) (interface{}, error) {
|
|
|
var request = &SubmitOptions{}
|
|
|
if err := utils.LoadQueryObject(queryOptions, &request); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
productPlanRepository, _ := repository.NewProductPlanRepository(ptr.transactionContext)
|
|
|
//productGroupRepository,_:= repository.NewProductGroupRepository(ptr.transactionContext)
|
|
|
workshopRepository, _ := repository.NewWorkshopRepository(ptr.transactionContext)
|
|
|
unitConversionRepository, _ := repository.NewUnitConversionRepository(ptr.transactionContext)
|
|
|
productRecordRepository, _ := repository.NewProductRecordRepository(ptr.transactionContext)
|
|
|
|
|
|
// 1.初始化
|
|
|
var (
|
|
|
plan *domain.ProductPlan
|
|
|
//group *domain.ProductGroup
|
|
|
workshop *domain.Workshop
|
|
|
workstation *domain.WorkStation
|
|
|
uc *domain.UnitConversion
|
|
|
err error
|
|
|
weight float64 = request.Weigh
|
|
|
)
|
|
|
if plan, err = productPlanRepository.FindOne(map[string]interface{}{"productPlanId": request.ProductPlanId}); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
//if group,err = productGroupRepository.FindOne(map[string]interface{}{"productGroupId":request.ProductGroupId});err!=nil{
|
|
|
// return nil, err
|
|
|
//}
|
|
|
if workshop, err = workshopRepository.FindOne(map[string]interface{}{"workshopId": request.WorkshopId}); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
if uc, err = unitConversionRepository.FindOne(map[string]interface{}{"unitConversionId": request.UnitConversionId}); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
if workstation, err = workshop.FindWorkStation(request.WorkshopId, request.LineId, request.SectionId); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
var user *domain.User
|
|
|
userService := NewUserService()
|
|
|
user, err = userService.User(request.EmployeeId)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
var org *domain.Org
|
|
|
org, err = userService.Organization(request.OrgId)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
// 领料、退料需要换算产能
|
|
|
if productRecordType == domain.RecordTypeReceiveMaterial || productRecordType == domain.RecordTypeReturnMaterial {
|
|
|
weight = (weight / uc.FromUnitQuantity.Quantity) * uc.ToUnitQuantity.Quantity
|
|
|
}
|
|
|
|
|
|
record := &domain.ProductRecord{
|
|
|
CompanyId: request.CompanyId,
|
|
|
OrgId: request.OrgId,
|
|
|
ProductRecordType: productRecordType,
|
|
|
ProductWorker: user,
|
|
|
WorkStation: workstation,
|
|
|
CreatedAt: time.Now(),
|
|
|
UpdatedAt: time.Now(),
|
|
|
ProductRecordInfo: &domain.ProductRecordInfo{
|
|
|
Weigh: weight,
|
|
|
WeighBefore: weight,
|
|
|
UnitConversionId: request.UnitConversionId,
|
|
|
ApproveStatus: domain.ProductRecordNotApprove,
|
|
|
ProductPlanId: request.ProductPlanId,
|
|
|
BatchNumber: plan.BatchNumber,
|
|
|
PlanProductName: plan.PlanProductName,
|
|
|
ProductGroupId: request.ProductGroupId,
|
|
|
},
|
|
|
Ext: domain.NewExt(org.OrgName),
|
|
|
}
|
|
|
if record, err = productRecordRepository.Save(record); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
return nil, nil
|
|
|
}
|
|
|
|
|
|
func NewPGProductRecordService(transactionContext *pgTransaction.TransactionContext) (*PGProductRecordService, error) {
|
|
|
if transactionContext == nil {
|
|
|
return nil, fmt.Errorf("transactionContext参数不能为nil")
|
|
|
} else {
|
|
|
return &PGProductRecordService{
|
|
|
transactionContext: transactionContext,
|
|
|
}, nil
|
|
|
}
|
|
|
} |
...
|
...
|
|