作者 yangfu

refactor: 计划管理、工位

... ... @@ -11,6 +11,8 @@ type ProductGroupEmployeesDto struct {
UserId int `json:"userId,omitempty"`
// 用户姓名
UserName string `json:"userName,omitempty"`
// 生产小组ID
ProductGroupId int `json:"productGroupId,omitempty"`
// 班组名称
GroupName string `json:"groupName,omitempty"`
// 上班班次 1:全天 2:白班 4:中班 8:夜班
... ... @@ -34,6 +36,7 @@ func NewGroupEmployee(group *domain.ProductGroup, u *domain.User) *ProductGroupE
item := &ProductGroupEmployeesDto{}
item.UserId = u.UserId
item.UserName = u.UserName
item.ProductGroupId = group.ProductGroupId
item.GroupName = group.GroupName
workOns := domain.WorkOnDescription(group.WorkOn)
item.WorkOnDescription = strings.Join(workOns, ",")
... ...
... ... @@ -9,8 +9,26 @@ import (
)
type ReceiveMaterialCommand struct {
// 企业id
CompanyId int `cname:"企业id" json:"companyId" valid:"Required"`
// 组织ID
OrgId int `cname:"组织ID" json:"orgId" valid:"Required"`
// 生产计划ID
ProductPlanId int `cname:"生产计划ID" json:"productPlanId" valid:"Required"`
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
ProductId int `cname:"产品" json:"productId" valid:"Required"`
// 重量
Weigh float64 `cname:"重量" json:"weigh" valid:"Required"`
}
func (receiveMaterialCommand *ReceiveMaterialCommand) Valid(validation *validation.Validation) {
... ...
... ... @@ -9,8 +9,26 @@ import (
)
type ReturnMaterialCommand struct {
// 企业id
CompanyId int `cname:"企业id" json:"companyId" valid:"Required"`
// 组织ID
OrgId int `cname:"组织ID" json:"orgId" valid:"Required"`
// 生产计划ID
ProductPlanId int `cname:"生产计划ID" json:"productPlanId" valid:"Required"`
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
ProductId int `cname:"产品" json:"productId" valid:"Required"`
// 重量
Weigh float64 `cname:"重量" json:"weigh" valid:"Required"`
}
func (returnMaterialCommand *ReturnMaterialCommand) Valid(validation *validation.Validation) {
... ...
... ... @@ -2,6 +2,18 @@ package domain
import "time"
const (
RecordTypeReceiveMaterial = 1 // 领料
RecordTypeReturnMaterial = 2 // 退料
RecordTypeWeigh = 4 // 称重
RecordTypeSecondLevelWeigh = 8 // 二级品称重
)
const (
ProductRecordNotApprove = 1 // 未审核
ProductRecordApproved = 2 // 已审核
)
// 生产记录
type ProductRecord struct {
// 生产记录ID
... ...
... ... @@ -3,14 +3,28 @@ package domain
// 生产记录信息 (物料、批次、产能(产能、领料、退料、二级品))
type ProductRecordInfo struct {
// 产能
ProductWeigh int `json:"productWeigh,omitempty"`
Weigh float64 `json:"weigh,omitempty"`
// 产能 - 审核前
WeighBefore float64 `json:"weighBefore,omitempty"`
// 产能-审核后
WeighAfter float64 `json:"weighAfter,omitempty"`
// 审核状态 1:未审核 2:已审核
ApproveStatus int64 `json:"approveStatus"`
// 审核时间
ApproveAt int64 `json:"approveAt"`
// 物料信息
Material *UnitConversion `json:"material,omitempty"`
// 生产计划信息(批次)
ProductPlan *ProductPlan `json:"productPlan,omitempty"`
// 单位换算ID
UnitConversionId int `json:"unitConversionId,omitempty"`
// 生产计划ID
ProductPlanId int `json:"productPlanId,omitempty"`
// 计划的产品名称
PlanProductName string `json:"planProductName,omitempty"`
// 批号
BatchNumber string `json:"batchNumber,omitempty"`
// 生产小组ID
ProductGroupId int `json:"productGroupId,omitempty"`
... ...
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
}
}
... ...
... ... @@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"github.com/beego/beego/v2/core/validation"
jsonlib "github.com/linmadan/egglib-go/utils/json"
"io"
"reflect"
... ... @@ -332,3 +333,13 @@ func ToArrayString(inputs []int) []string {
}
return result
}
func LoadQueryObject(queryOption map[string]interface{}, obj interface{}) error {
jsonlib.UnmarshalFromString(jsonlib.MarshalToString(queryOption), obj)
validation := validation.Validation{}
result, err := validation.Valid(obj)
if !result && len(validation.Errors) > 0 {
return validation.Errors[0]
}
return err
}
... ...