...
|
...
|
@@ -48,6 +48,7 @@ func (ptr *PGWorkshopDataConsumeService) Consume(companyId, orgId int, record *d |
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
if deviceDailyRecord != nil {
|
|
|
workStation = deviceDailyRecord.WorkStation
|
|
|
planId = deviceDailyRecord.DeviceRunningRecordInfo.ProductPlanId
|
...
|
...
|
@@ -64,15 +65,7 @@ func (ptr *PGWorkshopDataConsumeService) Consume(companyId, orgId int, record *d |
|
|
return nil, nil
|
|
|
}
|
|
|
workStation = device.WorkStation
|
|
|
// 封箱机、串串机需要定位到批次
|
|
|
if record.DeviceType == domain.DeviceTypeFengXiangJi || record.DeviceType == domain.DeviceTypeChuanChuanJi {
|
|
|
datetime, _ = time.Parse("2006-01-02", deviceRunningData.Date)
|
|
|
if plan, err = ptr.findDeviceProductPlan(companyId, orgId, workStation.WorkStationId, datetime, deviceRunningData.ProductType); err != nil {
|
|
|
log.Logger.Error(err.Error())
|
|
|
} else {
|
|
|
planId = plan.PlanDispatchRecordExt.ProductPlanId
|
|
|
}
|
|
|
}
|
|
|
|
|
|
var saveErr error
|
|
|
if deviceDailyRecord, saveErr = ptr.saveDeviceDailyRunningRecord(companyId, orgId, workStation, device, planId, deviceRunningData); err != nil {
|
|
|
return nil, err
|
...
|
...
|
@@ -84,14 +77,25 @@ func (ptr *PGWorkshopDataConsumeService) Consume(companyId, orgId int, record *d |
|
|
}()
|
|
|
}
|
|
|
|
|
|
// 封箱机、串串机需要定位到批次
|
|
|
if record.DeviceType == domain.DeviceTypeFengXiangJi || record.DeviceType == domain.DeviceTypeChuanChuanJi {
|
|
|
datetime, _ = time.Parse("2006-01-02", deviceRunningData.Date)
|
|
|
if plan, err = ptr.findDeviceProductPlan(companyId, orgId, workStation.WorkStationId, datetime, deviceRunningData.ProductType); err != nil {
|
|
|
log.Logger.Error(err.Error())
|
|
|
} else {
|
|
|
planId = plan.PlanDispatchRecordExt.ProductPlanId
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 1.保存设备运行记录
|
|
|
deviceRunningRecord, _ = ptr.newDeviceRunningRecord(companyId, orgId, workStation, device, deviceRunningData)
|
|
|
if _, err = deviceRunningRecordRepository.Save(deviceRunningRecord); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
// 2.保存设备生产记录
|
|
|
if record.DeviceType == domain.DeviceTypeChuanChuanJi {
|
|
|
productRecord, _ := ptr.newProductRecord(companyId, orgId, workStation, device, deviceRunningData, planId)
|
|
|
if record.DeviceType == domain.DeviceTypeChuanChuanJi && plan != nil {
|
|
|
|
|
|
productRecord, _ := ptr.newProductRecord(companyId, orgId, workStation, device, deviceRunningData, plan)
|
|
|
//if _, err = deviceRunningRecordRepository.Save(deviceRunningRecord); err != nil {
|
|
|
// return nil, err
|
|
|
//}
|
...
|
...
|
@@ -217,7 +221,7 @@ func (ptr *PGWorkshopDataConsumeService) newDeviceRunningRecord(companyId, orgId |
|
|
}, nil
|
|
|
}
|
|
|
|
|
|
func (ptr *PGWorkshopDataConsumeService) newProductRecord(companyId int, orgId int, workStation *domain.WorkStation, device *domain.Device, data *domain.DeviceRunningData, planId int) (*domain.ProductRecord, error) {
|
|
|
func (ptr *PGWorkshopDataConsumeService) newProductRecord(companyId int, orgId int, workStation *domain.WorkStation, device *domain.Device, data *domain.DeviceRunningData, plan *domain.ProductPlanDispatchRecord) (*domain.ProductRecord, error) {
|
|
|
result := &domain.ProductRecord{
|
|
|
CompanyId: companyId,
|
|
|
OrgId: orgId,
|
...
|
...
|
@@ -227,12 +231,14 @@ func (ptr *PGWorkshopDataConsumeService) newProductRecord(companyId int, orgId i |
|
|
CreatedAt: data.CollectionTime,
|
|
|
UpdatedAt: time.Now(),
|
|
|
ProductRecordInfo: &domain.ProductRecordInfo{
|
|
|
ProductDate: data.CollectionTime.Local().Format("2006-01-02"),
|
|
|
Original: float64(data.Count),
|
|
|
Weigh: float64(data.Count) * DefaultCCJUnitQuantity,
|
|
|
WeighBefore: float64(data.Count) * DefaultCCJUnitQuantity,
|
|
|
ApproveStatus: domain.AttendanceNotApprove,
|
|
|
ProductPlanId: planId,
|
|
|
ProductDate: data.CollectionTime.Local().Format("2006-01-02"),
|
|
|
Original: float64(data.Count),
|
|
|
Weigh: float64(data.Count) * DefaultCCJUnitQuantity,
|
|
|
WeighBefore: float64(data.Count) * DefaultCCJUnitQuantity,
|
|
|
ApproveStatus: domain.AttendanceNotApprove,
|
|
|
ProductPlanId: plan.PlanDispatchRecordExt.ProductPlanId,
|
|
|
PlanProductName: plan.PlanDispatchRecordExt.PlanProductName,
|
|
|
BatchNumber: plan.BatchNumber,
|
|
|
},
|
|
|
Ext: domain.NewExt(""),
|
|
|
}
|
...
|
...
|
|