...
|
...
|
@@ -56,7 +56,7 @@ func (productRecordService *ProductRecordService) ApproveProductRecord(cmd *comm |
|
|
return struct{}{}, nil
|
|
|
}
|
|
|
|
|
|
// 创建生产记录服务
|
|
|
// 创建生产记录服务,二级品
|
|
|
func (productRecordService *ProductRecordService) CreateProductRecord(operateInfo *domain.OperateInfo, param *command.CreateProductRecordCommand) (interface{}, error) {
|
|
|
if err := param.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
...
|
...
|
@@ -117,44 +117,50 @@ func (productRecordService *ProductRecordService) CreateProductRecord(operateInf |
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, "获取车间工段数据失败"+err.Error())
|
|
|
}
|
|
|
|
|
|
productRecordData := &domain.ProductRecord{
|
|
|
ProductRecordId: param.ProductRecordId,
|
|
|
CompanyId: operateInfo.CompanyId,
|
|
|
OrgId: operateInfo.OrgId,
|
|
|
ProductRecordType: domain.RecordTypeSecondLevelWeigh,
|
|
|
ProductWorker: user,
|
|
|
WorkStation: workstation,
|
|
|
CreatedAt: dataTime,
|
|
|
UpdatedAt: time.Now(),
|
|
|
ProductRecordInfo: &domain.ProductRecordInfo{
|
|
|
ProductDate: productPlanData.ProductDate.Local().Format("2006-01-02"),
|
|
|
Original: param.Weigh,
|
|
|
Weigh: utils.Round(param.Weigh, 1),
|
|
|
WeighBefore: utils.Round(param.Weigh, 1),
|
|
|
UnitConversionId: 0,
|
|
|
ApproveStatus: domain.ProductRecordNotApprove,
|
|
|
ProductPlanId: productPlanData.ProductPlanId,
|
|
|
BatchNumber: productPlanData.BatchNumber,
|
|
|
PlanProductName: productPlanData.PlanProductName,
|
|
|
ProductGroupId: 0,
|
|
|
WorkOn: productPlanData.WorkOn,
|
|
|
},
|
|
|
Ext: domain.NewExt(org.OrgName),
|
|
|
}
|
|
|
//保存并审核
|
|
|
if param.SaveAndApprove {
|
|
|
productRecordData.Approve(user, param.Weigh, time.Now(), domain.ProductRecordApproved)
|
|
|
}
|
|
|
_, err = productRecordRepo.Save(productRecordData)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, "保存生产记录"+err.Error())
|
|
|
productRecordIds := []int{}
|
|
|
for _, workerId := range param.WorkerId {
|
|
|
workerData, err := userService.User(workerId)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, "获取员工数据错误,"+err.Error())
|
|
|
}
|
|
|
productRecordData := &domain.ProductRecord{
|
|
|
CompanyId: operateInfo.CompanyId,
|
|
|
OrgId: operateInfo.OrgId,
|
|
|
ProductRecordType: domain.RecordTypeSecondLevelWeigh,
|
|
|
ProductWorker: workerData,
|
|
|
WorkStation: workstation,
|
|
|
CreatedAt: dataTime,
|
|
|
UpdatedAt: time.Now(),
|
|
|
ProductRecordInfo: &domain.ProductRecordInfo{
|
|
|
ProductDate: productPlanData.ProductDate.Local().Format("2006-01-02"),
|
|
|
Original: param.Weigh,
|
|
|
Weigh: utils.Round(param.Weigh, 1),
|
|
|
WeighBefore: utils.Round(param.Weigh, 1),
|
|
|
UnitConversionId: 0,
|
|
|
ApproveStatus: domain.ProductRecordNotApprove,
|
|
|
ProductPlanId: productPlanData.ProductPlanId,
|
|
|
BatchNumber: productPlanData.BatchNumber,
|
|
|
PlanProductName: productPlanData.PlanProductName,
|
|
|
ProductGroupId: 0,
|
|
|
WorkOn: productPlanData.WorkOn,
|
|
|
},
|
|
|
Ext: domain.NewExt(org.OrgName),
|
|
|
}
|
|
|
//保存并审核
|
|
|
if param.SaveAndApprove {
|
|
|
productRecordData.Approve(user, param.Weigh, time.Now(), domain.ProductRecordApproved)
|
|
|
}
|
|
|
_, err = productRecordRepo.Save(productRecordData)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, "保存生产记录"+err.Error())
|
|
|
}
|
|
|
productRecordIds = append(productRecordIds, productRecordData.ProductRecordId)
|
|
|
}
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return map[string]interface{}{
|
|
|
"productRecordId": productRecordData.ProductRecordId,
|
|
|
"productRecordId": productRecordIds,
|
|
|
}, nil
|
|
|
}
|
|
|
|
...
|
...
|
|