作者 yangfu

feat: 生产记录上报

... ... @@ -97,7 +97,7 @@ func (productJobService *ProductJobService) GetProductJob(getProductJobQuery *qu
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
productJob.WorkStation, _ = workshop.FindWorkStation(productJob.WorkStation.WorkshopId, productJob.WorkStation.LineId, productJob.WorkStation.SectionId)
productJob.WorkStation.Principal = workshop.Principal
newJobDto := &dto.ProductJobDto{}
newJobDto.LoadDto(productJob, 0)
... ...
... ... @@ -25,8 +25,8 @@ type ReceiveMaterialCommand struct {
ProductGroupId int `cname:"生产小组" json:"productGroupId" valid:"Required"`
// 员工Id 用户唯一标识
EmployeeId int `cname:"员工" json:"employeeId" valid:"Required"`
// 产品ID
ProductId int `cname:"产品" json:"productId" valid:"Required"`
// 物料ID
UnitConversionId int `cname:"物料ID" json:"unitConversionId" valid:"Required"`
// 重量
Weigh float64 `cname:"重量" json:"weigh" valid:"Required"`
}
... ...
... ... @@ -25,8 +25,8 @@ type ReturnMaterialCommand struct {
ProductGroupId int `cname:"生产小组" json:"productGroupId" valid:"Required"`
// 员工Id 用户唯一标识
EmployeeId int `cname:"员工" json:"employeeId" valid:"Required"`
// 产品ID
ProductId int `cname:"产品" json:"productId" valid:"Required"`
// 物料ID
UnitConversionId int `cname:"物料ID" json:"unitConversionId" valid:"Required"`
// 重量
Weigh float64 `cname:"重量" json:"weigh" valid:"Required"`
}
... ...
... ... @@ -9,8 +9,26 @@ import (
)
type SubmitProductRecordCommand 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
UnitConversionId int `cname:"物料ID" json:"unitConversionId" valid:"Required"`
// 重量
Weigh float64 `cname:"重量" json:"weigh" valid:"Required"`
}
func (submitProductRecordCommand *SubmitProductRecordCommand) Valid(validation *validation.Validation) {
... ...
... ... @@ -3,6 +3,7 @@ package service
import (
"fmt"
"github.com/linmadan/egglib-go/core/application"
"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"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productPlan/command"
... ... @@ -483,10 +484,17 @@ func (productPlanService *ProductPlanService) ReceiveMaterial(receiveMaterialCom
defer func() {
transactionContext.RollbackTransaction()
}()
productRecordService, _ := domainService.NewPGProductRecordService(transactionContext.(*pg.TransactionContext))
_, err = productRecordService.SubmitProductRecord(domain.RecordTypeReceiveMaterial, tool_funs.SimpleStructToMap(receiveMaterialCommand))
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
return struct{}{}, nil
}
// 退料
... ... @@ -504,10 +512,18 @@ func (productPlanService *ProductPlanService) ReturnMaterial(returnMaterialComma
defer func() {
transactionContext.RollbackTransaction()
}()
productRecordService, _ := domainService.NewPGProductRecordService(transactionContext.(*pg.TransactionContext))
_, err = productRecordService.SubmitProductRecord(domain.RecordTypeReturnMaterial, tool_funs.SimpleStructToMap(returnMaterialCommand))
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
return struct{}{}, nil
}
// 提交成品记录 (成品 二级品)
... ... @@ -525,10 +541,17 @@ func (productPlanService *ProductPlanService) SubmitProductRecord(submitProductR
defer func() {
transactionContext.RollbackTransaction()
}()
productRecordService, _ := domainService.NewPGProductRecordService(transactionContext.(*pg.TransactionContext))
_, err = productRecordService.SubmitProductRecord(domain.RecordTypeSecondLevelWeigh, tool_funs.SimpleStructToMap(submitProductRecordCommand))
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
return struct{}{}, nil
}
func NewProductPlanService(options map[string]interface{}) *ProductPlanService {
... ...
... ... @@ -2,7 +2,11 @@ package domain
// 生产记录信息 (物料、批次、产能(产能、领料、退料、二级品))
type ProductRecordInfo struct {
// 产能
// 生产日期
ProductDate string `json:"productDate"`
// 原始上报数据
OriginalWeigh float64 `json:"originalWeigh,omitempty"`
// 换算后的产能
Weigh float64 `json:"weigh,omitempty"`
// 产能 - 审核前
WeighBefore float64 `json:"weighBefore,omitempty"`
... ... @@ -13,9 +17,9 @@ type ProductRecordInfo struct {
// 审核时间
ApproveAt int64 `json:"approveAt"`
// 物料信息
Material *UnitConversion `json:"material,omitempty"`
//Material *UnitConversion `json:"material,omitempty"`
// 生产计划信息(批次)
ProductPlan *ProductPlan `json:"productPlan,omitempty"`
//ProductPlan *ProductPlan `json:"productPlan,omitempty"`
// 单位换算ID
UnitConversionId int `json:"unitConversionId,omitempty"`
... ...
... ... @@ -40,7 +40,7 @@ type SubmitOptions struct {
// SubmitProductRecord 提交生产记录
func (ptr *PGProductRecordService) SubmitProductRecord(productRecordType int, queryOptions map[string]interface{}) (interface{}, error) {
var request = &SubmitOptions{}
if err := utils.LoadQueryObject(queryOptions, &request); err != nil {
if err := utils.LoadQueryObject(queryOptions, request); err != nil {
return nil, err
}
... ... @@ -103,6 +103,8 @@ func (ptr *PGProductRecordService) SubmitProductRecord(productRecordType int, qu
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
ProductRecordInfo: &domain.ProductRecordInfo{
ProductDate: plan.ProductDate.Format("2006-01-02"),
OriginalWeigh: request.Weigh,
Weigh: weight,
WeighBefore: weight,
UnitConversionId: request.UnitConversionId,
... ...
... ... @@ -38,19 +38,13 @@ func (repository *ProductRecordRepository) Save(productRecord *domain.ProductRec
"product_record_info",
"ext",
}
insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields)
insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "product_record_id", "deleted_at"))
insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "product_record_id", "deleted_at"))
returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "productRecord_id")
updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "product_record_id", "deleted_at")
updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields)
tx := repository.transactionContext.PgTx
if productRecord.Identify() == nil {
productRecordId, err := repository.nextIdentify()
if err != nil {
return productRecord, err
} else {
productRecord.ProductRecordId = int(productRecordId)
}
if _, err := tx.QueryOne(
pg.Scan(
&productRecord.ProductRecordId,
... ... @@ -65,8 +59,8 @@ func (repository *ProductRecordRepository) Save(productRecord *domain.ProductRec
&productRecord.ProductRecordInfo,
&productRecord.Ext,
),
fmt.Sprintf("INSERT INTO product_records (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
productRecord.ProductRecordId,
fmt.Sprintf("INSERT INTO manufacture.product_records (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
//productRecord.ProductRecordId,
productRecord.CompanyId,
productRecord.OrgId,
productRecord.ProductRecordType,
... ... @@ -74,7 +68,7 @@ func (repository *ProductRecordRepository) Save(productRecord *domain.ProductRec
productRecord.WorkStation,
productRecord.CreatedAt,
productRecord.UpdatedAt,
productRecord.DeletedAt,
//productRecord.DeletedAt,
productRecord.ProductRecordInfo,
productRecord.Ext,
); err != nil {
... ... @@ -95,8 +89,8 @@ func (repository *ProductRecordRepository) Save(productRecord *domain.ProductRec
&productRecord.ProductRecordInfo,
&productRecord.Ext,
),
fmt.Sprintf("UPDATE product_records SET %s WHERE product_record_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
productRecord.ProductRecordId,
fmt.Sprintf("UPDATE manufacture.product_records SET %s WHERE product_record_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
//productRecord.ProductRecordId,
productRecord.CompanyId,
productRecord.OrgId,
productRecord.ProductRecordType,
... ... @@ -104,7 +98,7 @@ func (repository *ProductRecordRepository) Save(productRecord *domain.ProductRec
productRecord.WorkStation,
productRecord.CreatedAt,
productRecord.UpdatedAt,
productRecord.DeletedAt,
//productRecord.DeletedAt,
productRecord.ProductRecordInfo,
productRecord.Ext,
productRecord.Identify(),
... ...
... ... @@ -64,17 +64,23 @@ func (controller *ProductPlanController) ListProductPlan() {
func (controller *ProductPlanController) ReceiveMaterial() {
productPlanService := service.NewProductPlanService(nil)
receiveMaterialCommand := &command.ReceiveMaterialCommand{}
Must(controller.Unmarshal(receiveMaterialCommand))
data, err := productPlanService.ReceiveMaterial(receiveMaterialCommand)
cmd := &command.ReceiveMaterialCommand{}
Must(controller.Unmarshal(cmd))
operateInfo := ParseOperateInfo(controller.BaseController)
cmd.CompanyId = operateInfo.CompanyId
cmd.OrgId = operateInfo.OrgId
data, err := productPlanService.ReceiveMaterial(cmd)
controller.Response(data, err)
}
func (controller *ProductPlanController) ReturnMaterial() {
productPlanService := service.NewProductPlanService(nil)
returnMaterialCommand := &command.ReturnMaterialCommand{}
Must(controller.Unmarshal(returnMaterialCommand))
data, err := productPlanService.ReturnMaterial(returnMaterialCommand)
cmd := &command.ReturnMaterialCommand{}
Must(controller.Unmarshal(cmd))
operateInfo := ParseOperateInfo(controller.BaseController)
cmd.CompanyId = operateInfo.CompanyId
cmd.OrgId = operateInfo.OrgId
data, err := productPlanService.ReturnMaterial(cmd)
controller.Response(data, err)
}
... ... @@ -104,9 +110,12 @@ func (controller *ProductPlanController) Switch() {
func (controller *ProductPlanController) SubmitProductRecord() {
productPlanService := service.NewProductPlanService(nil)
submitProductRecordCommand := &command.SubmitProductRecordCommand{}
Must(controller.Unmarshal(submitProductRecordCommand))
data, err := productPlanService.SubmitProductRecord(submitProductRecordCommand)
cmd := &command.SubmitProductRecordCommand{}
Must(controller.Unmarshal(cmd))
operateInfo := ParseOperateInfo(controller.BaseController)
cmd.CompanyId = operateInfo.CompanyId
cmd.OrgId = operateInfo.OrgId
data, err := productPlanService.SubmitProductRecord(cmd)
controller.Response(data, err)
}
... ...