...
|
...
|
@@ -98,7 +98,7 @@ func (ptr *PGWorkshopDataConsumeService) Consume(companyId, orgId int, record *d |
|
|
if record.DeviceType == domain.DeviceTypeChuanChuanJi && plan != nil && deviceRunningData.Count > 0 {
|
|
|
log.Logger.Debug(fmt.Sprintf("设备统计 设备:%v(%v) 当前数量:%v 增加数量:%v",
|
|
|
deviceDailyRecord.DeviceCode,
|
|
|
deviceDailyRecord.ProductDate.Local().Format("2006-01-02"),
|
|
|
deviceDailyRecord.DeviceRunningRecordInfo.ProductDate,
|
|
|
deviceRunningRecord.DeviceRunningRecordInfo.TodayTotal,
|
|
|
deviceRunningRecord.DeviceRunningRecordInfo.Count))
|
|
|
productRecord, _ := ptr.newProductRecord(companyId, orgId, workStation, device, deviceRunningData, plan)
|
...
|
...
|
@@ -110,19 +110,20 @@ func (ptr *PGWorkshopDataConsumeService) Consume(companyId, orgId int, record *d |
|
|
SendProductRecordStaticsJob(productRecord)
|
|
|
}
|
|
|
}
|
|
|
if err = redis.SaveDeviceDailyRunningRecord(deviceDailyRecord); err != nil {
|
|
|
if err = redis.SaveDeviceDailyRunningRecordByKey(deviceDailyRecord.RedisKey, deviceDailyRecord); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
return nil, nil
|
|
|
}
|
|
|
|
|
|
// 设备运行数据
|
|
|
func (ptr *PGWorkshopDataConsumeService) newDeviceRunningData(record *domain.DeviceCollection) (*domain.DeviceRunningData, error) {
|
|
|
var err error
|
|
|
var unitQuantity float64 = DefaultCCJUnitQuantity // 单位数量
|
|
|
var data = &domain.DeviceRunningData{
|
|
|
DeviceCollectionId: record.DeviceCollectionId,
|
|
|
WorkShopName: record.WorkShopName,
|
|
|
CollectionTime: record.CollectionTime,
|
|
|
CollectionTime: record.CollectionTime.Local(),
|
|
|
DeviceCode: record.DeviceSn,
|
|
|
DeviceType: record.DeviceType,
|
|
|
StartupStatus: int(record.StartupStatus),
|
...
|
...
|
@@ -160,6 +161,7 @@ func (ptr *PGWorkshopDataConsumeService) newDeviceRunningData(record *domain.Dev |
|
|
}
|
|
|
data.Temp1 = utils.Truncate(deviceYouZhaJi.FrontTemp, 1)
|
|
|
data.Temp2 = utils.Truncate(deviceYouZhaJi.BackTemp, 1)
|
|
|
data.Alarm = deviceYouZhaJi.Alarm
|
|
|
} else {
|
|
|
deviceYouZhaJi := &domain.DeviceYouZhaJi2{}
|
|
|
err = json.Unmarshal(mBytes, deviceYouZhaJi)
|
...
|
...
|
@@ -168,6 +170,7 @@ func (ptr *PGWorkshopDataConsumeService) newDeviceRunningData(record *domain.Dev |
|
|
}
|
|
|
data.Temp1 = utils.Truncate(deviceYouZhaJi.Temp1, 1)
|
|
|
data.Temp2 = utils.Truncate(deviceYouZhaJi.Temp2, 1)
|
|
|
data.Alarm = deviceYouZhaJi.Alarm
|
|
|
}
|
|
|
break
|
|
|
//串串机
|
...
|
...
|
@@ -193,6 +196,7 @@ func (ptr *PGWorkshopDataConsumeService) newDeviceRunningData(record *domain.Dev |
|
|
break
|
|
|
}
|
|
|
data.Temp1 = utils.Truncate(deviceSuDongXian.CurrTemp, 1)
|
|
|
data.Alarm = deviceSuDongXian.Alarm
|
|
|
break
|
|
|
//封口机
|
|
|
case domain.DeviceTypeFengKouJi:
|
...
|
...
|
@@ -231,6 +235,7 @@ func (ptr *PGWorkshopDataConsumeService) newDeviceRunningData(record *domain.Dev |
|
|
return data, nil
|
|
|
}
|
|
|
|
|
|
// 设备运行记录
|
|
|
func (ptr *PGWorkshopDataConsumeService) newDeviceRunningRecord(companyId, orgId int, workStation *domain.WorkStation, device *domain.Device, data *domain.DeviceRunningData) (*domain.DeviceRunningRecord, error) {
|
|
|
return &domain.DeviceRunningRecord{
|
|
|
CompanyId: companyId,
|
...
|
...
|
@@ -239,10 +244,11 @@ func (ptr *PGWorkshopDataConsumeService) newDeviceRunningRecord(companyId, orgId |
|
|
DeviceId: device.DeviceId,
|
|
|
DeviceCode: device.DeviceCode,
|
|
|
DeviceRunningRecordInfo: data,
|
|
|
CreatedAt: data.CollectionTime,
|
|
|
CreatedAt: data.CollectionTime.Local(),
|
|
|
}, nil
|
|
|
}
|
|
|
|
|
|
// 生产记录
|
|
|
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,
|
...
|
...
|
@@ -250,7 +256,7 @@ func (ptr *PGWorkshopDataConsumeService) newProductRecord(companyId int, orgId i |
|
|
WorkStation: workStation,
|
|
|
ProductRecordType: domain.RecordTypeWeigh,
|
|
|
ProductWorker: &domain.User{},
|
|
|
CreatedAt: data.CollectionTime,
|
|
|
CreatedAt: data.CollectionTime.Local(),
|
|
|
UpdatedAt: time.Now(),
|
|
|
ProductRecordInfo: &domain.ProductRecordInfo{
|
|
|
ProductDate: data.CollectionTime.Local().Format("2006-01-02"),
|
...
|
...
|
@@ -279,31 +285,33 @@ func (ptr *PGWorkshopDataConsumeService) saveDeviceDailyRunningRecord(companyId, |
|
|
if record, err = deviceDailyRunningRecordRepository.FindOne(map[string]interface{}{
|
|
|
"workStationId": workStation.WorkStationId,
|
|
|
"deviceCode": data.DeviceCode,
|
|
|
"productDate": utils.GetZeroTime(data.CollectionTime),
|
|
|
"productDate": utils.GetZeroTime(data.CollectionTime.Local()),
|
|
|
}); err != nil {
|
|
|
if err != domain.ErrorNotFound {
|
|
|
return nil, err
|
|
|
}
|
|
|
}
|
|
|
if record != nil {
|
|
|
|
|
|
record.RedisKey = redis.DeviceDailyRunningRecordKeyByTimeStr(record.DeviceRunningRecordInfo.ProductDate, record.DeviceCode)
|
|
|
return record, nil
|
|
|
}
|
|
|
recordInfo := domain.NewDeviceRunningRecordInfo()
|
|
|
recordInfo.ProductPlanId = planId
|
|
|
recordInfo.DeviceName = device.DeviceName
|
|
|
recordInfo.OrgName = device.Ext.OrgName
|
|
|
recordInfo.ProductDate = data.CollectionTime.Local().Format("2006-01-02")
|
|
|
record = &domain.DeviceDailyRunningRecord{
|
|
|
CompanyId: companyId,
|
|
|
OrgId: orgId,
|
|
|
WorkStation: workStation,
|
|
|
DeviceId: device.DeviceId,
|
|
|
DeviceCode: device.DeviceCode,
|
|
|
ProductDate: utils.GetZeroTime(data.CollectionTime),
|
|
|
ProductDate: utils.GetZeroTime(data.CollectionTime.Local()),
|
|
|
DeviceRunningRecordInfo: recordInfo,
|
|
|
CreatedAt: data.CollectionTime,
|
|
|
CreatedAt: data.CollectionTime.Local(),
|
|
|
UpdatedAt: time.Now(),
|
|
|
}
|
|
|
record.RedisKey = redis.DeviceDailyRunningRecordKeyByTimeStr(record.DeviceRunningRecordInfo.ProductDate, record.DeviceCode)
|
|
|
if record, err = deviceDailyRunningRecordRepository.Save(record); err != nil {
|
|
|
return nil, err
|
|
|
}
|
...
|
...
|
|