正在显示
7 个修改的文件
包含
210 行增加
和
3 行删除
| @@ -11,6 +11,8 @@ type ProductGroupEmployeesDto struct { | @@ -11,6 +11,8 @@ type ProductGroupEmployeesDto struct { | ||
| 11 | UserId int `json:"userId,omitempty"` | 11 | UserId int `json:"userId,omitempty"` |
| 12 | // 用户姓名 | 12 | // 用户姓名 |
| 13 | UserName string `json:"userName,omitempty"` | 13 | UserName string `json:"userName,omitempty"` |
| 14 | + // 生产小组ID | ||
| 15 | + ProductGroupId int `json:"productGroupId,omitempty"` | ||
| 14 | // 班组名称 | 16 | // 班组名称 |
| 15 | GroupName string `json:"groupName,omitempty"` | 17 | GroupName string `json:"groupName,omitempty"` |
| 16 | // 上班班次 1:全天 2:白班 4:中班 8:夜班 | 18 | // 上班班次 1:全天 2:白班 4:中班 8:夜班 |
| @@ -34,6 +36,7 @@ func NewGroupEmployee(group *domain.ProductGroup, u *domain.User) *ProductGroupE | @@ -34,6 +36,7 @@ func NewGroupEmployee(group *domain.ProductGroup, u *domain.User) *ProductGroupE | ||
| 34 | item := &ProductGroupEmployeesDto{} | 36 | item := &ProductGroupEmployeesDto{} |
| 35 | item.UserId = u.UserId | 37 | item.UserId = u.UserId |
| 36 | item.UserName = u.UserName | 38 | item.UserName = u.UserName |
| 39 | + item.ProductGroupId = group.ProductGroupId | ||
| 37 | item.GroupName = group.GroupName | 40 | item.GroupName = group.GroupName |
| 38 | workOns := domain.WorkOnDescription(group.WorkOn) | 41 | workOns := domain.WorkOnDescription(group.WorkOn) |
| 39 | item.WorkOnDescription = strings.Join(workOns, ",") | 42 | item.WorkOnDescription = strings.Join(workOns, ",") |
| @@ -9,8 +9,26 @@ import ( | @@ -9,8 +9,26 @@ import ( | ||
| 9 | ) | 9 | ) |
| 10 | 10 | ||
| 11 | type ReceiveMaterialCommand struct { | 11 | type ReceiveMaterialCommand struct { |
| 12 | + // 企业id | ||
| 13 | + CompanyId int `cname:"企业id" json:"companyId" valid:"Required"` | ||
| 14 | + // 组织ID | ||
| 15 | + OrgId int `cname:"组织ID" json:"orgId" valid:"Required"` | ||
| 12 | // 生产计划ID | 16 | // 生产计划ID |
| 13 | - ProductPlanId int `cname:"生产计划ID" json:"productPlanId" valid:"Required"` | 17 | + ProductPlanId int `cname:"生产计划" json:"productPlanId" valid:"Required"` |
| 18 | + // 车间ID | ||
| 19 | + WorkshopId int `cname:"车间" json:"workshopId" valid:"Required"` | ||
| 20 | + // 生产线ID | ||
| 21 | + LineId int `cname:"生产线" json:"lineId" valid:"Required"` | ||
| 22 | + // 工段ID | ||
| 23 | + SectionId int `cname:"工段" json:"sectionId" valid:"Required"` | ||
| 24 | + // 生产小组ID | ||
| 25 | + ProductGroupId int `cname:"生产小组" json:"productGroupId" valid:"Required"` | ||
| 26 | + // 员工Id 用户唯一标识 | ||
| 27 | + EmployeeId int `cname:"员工" json:"employeeId" valid:"Required"` | ||
| 28 | + // 产品ID | ||
| 29 | + ProductId int `cname:"产品" json:"productId" valid:"Required"` | ||
| 30 | + // 重量 | ||
| 31 | + Weigh float64 `cname:"重量" json:"weigh" valid:"Required"` | ||
| 14 | } | 32 | } |
| 15 | 33 | ||
| 16 | func (receiveMaterialCommand *ReceiveMaterialCommand) Valid(validation *validation.Validation) { | 34 | func (receiveMaterialCommand *ReceiveMaterialCommand) Valid(validation *validation.Validation) { |
| @@ -9,8 +9,26 @@ import ( | @@ -9,8 +9,26 @@ import ( | ||
| 9 | ) | 9 | ) |
| 10 | 10 | ||
| 11 | type ReturnMaterialCommand struct { | 11 | type ReturnMaterialCommand struct { |
| 12 | + // 企业id | ||
| 13 | + CompanyId int `cname:"企业id" json:"companyId" valid:"Required"` | ||
| 14 | + // 组织ID | ||
| 15 | + OrgId int `cname:"组织ID" json:"orgId" valid:"Required"` | ||
| 12 | // 生产计划ID | 16 | // 生产计划ID |
| 13 | - ProductPlanId int `cname:"生产计划ID" json:"productPlanId" valid:"Required"` | 17 | + ProductPlanId int `cname:"生产计划" json:"productPlanId" valid:"Required"` |
| 18 | + // 车间ID | ||
| 19 | + WorkshopId int `cname:"车间" json:"workshopId" valid:"Required"` | ||
| 20 | + // 生产线ID | ||
| 21 | + LineId int `cname:"生产线" json:"lineId" valid:"Required"` | ||
| 22 | + // 工段ID | ||
| 23 | + SectionId int `cname:"工段" json:"sectionId" valid:"Required"` | ||
| 24 | + // 生产小组ID | ||
| 25 | + ProductGroupId int `cname:"生产小组" json:"productGroupId" valid:"Required"` | ||
| 26 | + // 员工Id 用户唯一标识 | ||
| 27 | + EmployeeId int `cname:"员工" json:"employeeId" valid:"Required"` | ||
| 28 | + // 产品ID | ||
| 29 | + ProductId int `cname:"产品" json:"productId" valid:"Required"` | ||
| 30 | + // 重量 | ||
| 31 | + Weigh float64 `cname:"重量" json:"weigh" valid:"Required"` | ||
| 14 | } | 32 | } |
| 15 | 33 | ||
| 16 | func (returnMaterialCommand *ReturnMaterialCommand) Valid(validation *validation.Validation) { | 34 | func (returnMaterialCommand *ReturnMaterialCommand) Valid(validation *validation.Validation) { |
| @@ -2,6 +2,18 @@ package domain | @@ -2,6 +2,18 @@ package domain | ||
| 2 | 2 | ||
| 3 | import "time" | 3 | import "time" |
| 4 | 4 | ||
| 5 | +const ( | ||
| 6 | + RecordTypeReceiveMaterial = 1 // 领料 | ||
| 7 | + RecordTypeReturnMaterial = 2 // 退料 | ||
| 8 | + RecordTypeWeigh = 4 // 称重 | ||
| 9 | + RecordTypeSecondLevelWeigh = 8 // 二级品称重 | ||
| 10 | +) | ||
| 11 | + | ||
| 12 | +const ( | ||
| 13 | + ProductRecordNotApprove = 1 // 未审核 | ||
| 14 | + ProductRecordApproved = 2 // 已审核 | ||
| 15 | +) | ||
| 16 | + | ||
| 5 | // 生产记录 | 17 | // 生产记录 |
| 6 | type ProductRecord struct { | 18 | type ProductRecord struct { |
| 7 | // 生产记录ID | 19 | // 生产记录ID |
| @@ -3,14 +3,28 @@ package domain | @@ -3,14 +3,28 @@ package domain | ||
| 3 | // 生产记录信息 (物料、批次、产能(产能、领料、退料、二级品)) | 3 | // 生产记录信息 (物料、批次、产能(产能、领料、退料、二级品)) |
| 4 | type ProductRecordInfo struct { | 4 | type ProductRecordInfo struct { |
| 5 | // 产能 | 5 | // 产能 |
| 6 | - ProductWeigh int `json:"productWeigh,omitempty"` | 6 | + Weigh float64 `json:"weigh,omitempty"` |
| 7 | + // 产能 - 审核前 | ||
| 8 | + WeighBefore float64 `json:"weighBefore,omitempty"` | ||
| 9 | + // 产能-审核后 | ||
| 10 | + WeighAfter float64 `json:"weighAfter,omitempty"` | ||
| 11 | + // 审核状态 1:未审核 2:已审核 | ||
| 12 | + ApproveStatus int64 `json:"approveStatus"` | ||
| 13 | + // 审核时间 | ||
| 14 | + ApproveAt int64 `json:"approveAt"` | ||
| 7 | // 物料信息 | 15 | // 物料信息 |
| 8 | Material *UnitConversion `json:"material,omitempty"` | 16 | Material *UnitConversion `json:"material,omitempty"` |
| 9 | // 生产计划信息(批次) | 17 | // 生产计划信息(批次) |
| 10 | ProductPlan *ProductPlan `json:"productPlan,omitempty"` | 18 | ProductPlan *ProductPlan `json:"productPlan,omitempty"` |
| 19 | + // 单位换算ID | ||
| 20 | + UnitConversionId int `json:"unitConversionId,omitempty"` | ||
| 11 | 21 | ||
| 12 | // 生产计划ID | 22 | // 生产计划ID |
| 13 | ProductPlanId int `json:"productPlanId,omitempty"` | 23 | ProductPlanId int `json:"productPlanId,omitempty"` |
| 24 | + // 计划的产品名称 | ||
| 25 | + PlanProductName string `json:"planProductName,omitempty"` | ||
| 26 | + // 批号 | ||
| 27 | + BatchNumber string `json:"batchNumber,omitempty"` | ||
| 14 | 28 | ||
| 15 | // 生产小组ID | 29 | // 生产小组ID |
| 16 | ProductGroupId int `json:"productGroupId,omitempty"` | 30 | ProductGroupId int `json:"productGroupId,omitempty"` |
| 1 | +package domainService | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "github.com/linmadan/egglib-go/core/application" | ||
| 6 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
| 7 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" | ||
| 8 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/repository" | ||
| 9 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" | ||
| 10 | + "time" | ||
| 11 | +) | ||
| 12 | + | ||
| 13 | +type PGProductRecordService struct { | ||
| 14 | + transactionContext *pgTransaction.TransactionContext | ||
| 15 | +} | ||
| 16 | + | ||
| 17 | +type SubmitOptions struct { | ||
| 18 | + // 企业id | ||
| 19 | + CompanyId int `cname:"企业id" json:"companyId" valid:"Required"` | ||
| 20 | + // 组织ID | ||
| 21 | + OrgId int `cname:"组织ID" json:"orgId" valid:"Required"` | ||
| 22 | + // 生产计划ID | ||
| 23 | + ProductPlanId int `cname:"生产计划" json:"productPlanId" valid:"Required"` | ||
| 24 | + // 车间ID | ||
| 25 | + WorkshopId int `cname:"车间" json:"workshopId" valid:"Required"` | ||
| 26 | + // 生产线ID | ||
| 27 | + LineId int `cname:"生产线" json:"lineId" valid:"Required"` | ||
| 28 | + // 工段ID | ||
| 29 | + SectionId int `cname:"工段" json:"sectionId" valid:"Required"` | ||
| 30 | + // 生产小组ID | ||
| 31 | + ProductGroupId int `cname:"生产小组" json:"productGroupId" valid:"Required"` | ||
| 32 | + // 员工Id 用户唯一标识 | ||
| 33 | + EmployeeId int `cname:"员工" json:"employeeId" valid:"Required"` | ||
| 34 | + // 物料ID | ||
| 35 | + UnitConversionId int `cname:"物料ID" json:"unitConversionId" valid:"Required"` | ||
| 36 | + // 重量 | ||
| 37 | + Weigh float64 `cname:"重量" json:"weigh" valid:"Required"` | ||
| 38 | +} | ||
| 39 | + | ||
| 40 | +// SubmitProductRecord 提交生产记录 | ||
| 41 | +func (ptr *PGProductRecordService) SubmitProductRecord(productRecordType int, queryOptions map[string]interface{}) (interface{}, error) { | ||
| 42 | + var request = &SubmitOptions{} | ||
| 43 | + if err := utils.LoadQueryObject(queryOptions, &request); err != nil { | ||
| 44 | + return nil, err | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + productPlanRepository, _ := repository.NewProductPlanRepository(ptr.transactionContext) | ||
| 48 | + //productGroupRepository,_:= repository.NewProductGroupRepository(ptr.transactionContext) | ||
| 49 | + workshopRepository, _ := repository.NewWorkshopRepository(ptr.transactionContext) | ||
| 50 | + unitConversionRepository, _ := repository.NewUnitConversionRepository(ptr.transactionContext) | ||
| 51 | + productRecordRepository, _ := repository.NewProductRecordRepository(ptr.transactionContext) | ||
| 52 | + | ||
| 53 | + // 1.初始化 | ||
| 54 | + var ( | ||
| 55 | + plan *domain.ProductPlan | ||
| 56 | + //group *domain.ProductGroup | ||
| 57 | + workshop *domain.Workshop | ||
| 58 | + workstation *domain.WorkStation | ||
| 59 | + uc *domain.UnitConversion | ||
| 60 | + err error | ||
| 61 | + weight float64 = request.Weigh | ||
| 62 | + ) | ||
| 63 | + if plan, err = productPlanRepository.FindOne(map[string]interface{}{"productPlanId": request.ProductPlanId}); err != nil { | ||
| 64 | + return nil, err | ||
| 65 | + } | ||
| 66 | + //if group,err = productGroupRepository.FindOne(map[string]interface{}{"productGroupId":request.ProductGroupId});err!=nil{ | ||
| 67 | + // return nil, err | ||
| 68 | + //} | ||
| 69 | + if workshop, err = workshopRepository.FindOne(map[string]interface{}{"workshopId": request.WorkshopId}); err != nil { | ||
| 70 | + return nil, err | ||
| 71 | + } | ||
| 72 | + if uc, err = unitConversionRepository.FindOne(map[string]interface{}{"unitConversionId": request.UnitConversionId}); err != nil { | ||
| 73 | + return nil, err | ||
| 74 | + } | ||
| 75 | + if workstation, err = workshop.FindWorkStation(request.WorkshopId, request.LineId, request.SectionId); err != nil { | ||
| 76 | + return nil, err | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + var user *domain.User | ||
| 80 | + userService := NewUserService() | ||
| 81 | + user, err = userService.User(request.EmployeeId) | ||
| 82 | + if err != nil { | ||
| 83 | + return nil, err | ||
| 84 | + } | ||
| 85 | + | ||
| 86 | + var org *domain.Org | ||
| 87 | + org, err = userService.Organization(request.OrgId) | ||
| 88 | + if err != nil { | ||
| 89 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + // 领料、退料需要换算产能 | ||
| 93 | + if productRecordType == domain.RecordTypeReceiveMaterial || productRecordType == domain.RecordTypeReturnMaterial { | ||
| 94 | + weight = (weight / uc.FromUnitQuantity.Quantity) * uc.ToUnitQuantity.Quantity | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + record := &domain.ProductRecord{ | ||
| 98 | + CompanyId: request.CompanyId, | ||
| 99 | + OrgId: request.OrgId, | ||
| 100 | + ProductRecordType: productRecordType, | ||
| 101 | + ProductWorker: user, | ||
| 102 | + WorkStation: workstation, | ||
| 103 | + CreatedAt: time.Now(), | ||
| 104 | + UpdatedAt: time.Now(), | ||
| 105 | + ProductRecordInfo: &domain.ProductRecordInfo{ | ||
| 106 | + Weigh: weight, | ||
| 107 | + WeighBefore: weight, | ||
| 108 | + UnitConversionId: request.UnitConversionId, | ||
| 109 | + ApproveStatus: domain.ProductRecordNotApprove, | ||
| 110 | + ProductPlanId: request.ProductPlanId, | ||
| 111 | + BatchNumber: plan.BatchNumber, | ||
| 112 | + PlanProductName: plan.PlanProductName, | ||
| 113 | + ProductGroupId: request.ProductGroupId, | ||
| 114 | + }, | ||
| 115 | + Ext: domain.NewExt(org.OrgName), | ||
| 116 | + } | ||
| 117 | + if record, err = productRecordRepository.Save(record); err != nil { | ||
| 118 | + return nil, err | ||
| 119 | + } | ||
| 120 | + return nil, nil | ||
| 121 | +} | ||
| 122 | + | ||
| 123 | +func NewPGProductRecordService(transactionContext *pgTransaction.TransactionContext) (*PGProductRecordService, error) { | ||
| 124 | + if transactionContext == nil { | ||
| 125 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
| 126 | + } else { | ||
| 127 | + return &PGProductRecordService{ | ||
| 128 | + transactionContext: transactionContext, | ||
| 129 | + }, nil | ||
| 130 | + } | ||
| 131 | +} |
| @@ -4,6 +4,7 @@ import ( | @@ -4,6 +4,7 @@ import ( | ||
| 4 | "bytes" | 4 | "bytes" |
| 5 | "encoding/json" | 5 | "encoding/json" |
| 6 | "fmt" | 6 | "fmt" |
| 7 | + "github.com/beego/beego/v2/core/validation" | ||
| 7 | jsonlib "github.com/linmadan/egglib-go/utils/json" | 8 | jsonlib "github.com/linmadan/egglib-go/utils/json" |
| 8 | "io" | 9 | "io" |
| 9 | "reflect" | 10 | "reflect" |
| @@ -332,3 +333,13 @@ func ToArrayString(inputs []int) []string { | @@ -332,3 +333,13 @@ func ToArrayString(inputs []int) []string { | ||
| 332 | } | 333 | } |
| 333 | return result | 334 | return result |
| 334 | } | 335 | } |
| 336 | + | ||
| 337 | +func LoadQueryObject(queryOption map[string]interface{}, obj interface{}) error { | ||
| 338 | + jsonlib.UnmarshalFromString(jsonlib.MarshalToString(queryOption), obj) | ||
| 339 | + validation := validation.Validation{} | ||
| 340 | + result, err := validation.Valid(obj) | ||
| 341 | + if !result && len(validation.Errors) > 0 { | ||
| 342 | + return validation.Errors[0] | ||
| 343 | + } | ||
| 344 | + return err | ||
| 345 | +} |
-
请 注册 或 登录 后发表评论