作者 yangfu

fix :采集时间异常修复

... ... @@ -153,6 +153,8 @@ func (deviceCollectionService *DeviceCollectionService) DeviceCollection(createD
// newDeviceCollection.ComStatus = 1
// newDeviceCollection.CollectionTime = time.Date(2022,4,18,7,0,0,0,time.Local)
//}
// !!!!!!! 注意:保存到库以后 collect_time 变成了 UTC时间,后续处理的时候都要加上collectTime.Local()
if newDeviceCollection, err = deviceCollectionRepository.Save(newDeviceCollection); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ...
... ... @@ -116,13 +116,14 @@ func (ptr *PGWorkshopDataConsumeService) Consume(companyId, orgId int, record *d
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),
... ... @@ -234,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,
... ... @@ -242,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,
... ... @@ -253,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"),
... ... @@ -303,9 +306,9 @@ func (ptr *PGWorkshopDataConsumeService) saveDeviceDailyRunningRecord(companyId,
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)
... ...