作者 yangfu

fix: 车间产能统计修改 、 温度保留精度

... ... @@ -124,7 +124,7 @@ func (deviceCollectionService *DeviceCollectionService) DeviceCollection(createD
//计算区间的产能
if v, ok := newDeviceCollection.Values["Count"]; ok {
newDeviceCollection.Values["total"] = v // 记录原始值
newDeviceCollection.Values["Total"] = v // 记录原始值
newDeviceCollection.Values["Count"] = 0
curCount, errCurCount := strconv.Atoi(utils.AssertString(v))
lastCount, errLastCount := strconv.Atoi(utils.AssertString(lastDeviceCollectionRecord.Values["Count"]))
... ... @@ -143,29 +143,26 @@ func (deviceCollectionService *DeviceCollectionService) DeviceCollection(createD
newDeviceCollection.ProductCount = count
}
}
_, valErr := newDeviceCollection.Valid()
if _, valErr := newDeviceCollection.Valid(); valErr != nil {
newDeviceCollection.ResetProductCountToZero()
}
// TODO:测试假数据,后期注释掉
//if createDeviceCollectionCommand.DeviceType == domain.DeviceTypeChuanChuanJi {
// newDeviceCollection.Values["Count"] = rand.Intn(300)
// newDeviceCollection.StartupStatus = 1
// newDeviceCollection.ComStatus = 1
//}
deviceCollection, err := deviceCollectionRepository.Save(newDeviceCollection)
if err != nil {
if newDeviceCollection, err = deviceCollectionRepository.Save(newDeviceCollection); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if valErr == nil {
err = domainService.SendWorkshopDeviceData(deviceCollection)
}
if err != nil {
if err = domainService.SendWorkshopDeviceData(newDeviceCollection); err != nil {
log.Logger.Error("车间设备数据加入redis失败:" + err.Error())
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 map[string]interface{}{
"deviceCollection": deviceCollection,
}, nil
return nil, nil
}
... ...
... ... @@ -103,8 +103,6 @@ func (data *DeviceCollection) Valid() (bool, error) {
result = false
)
if data.ProductCount > DeviceMaxSingleProductCount {
data.ProductCount = 0
data.Values["Count"] = 0
return result, fmt.Errorf("设备数据异常: 生产数量超过:%v", DeviceMaxSingleProductCount)
}
if data.StartupStatus == 0 {
... ... @@ -115,3 +113,10 @@ func (data *DeviceCollection) Valid() (bool, error) {
}
return true, nil
}
func (data *DeviceCollection) ResetProductCountToZero() {
data.ProductCount = 0
if data.Values != nil {
data.Values["Count"] = 0
}
}
... ...
... ... @@ -53,15 +53,17 @@ func (deviceDailyRunningRecord *DeviceDailyRunningRecord) Update(data map[string
return nil
}
func (deviceDailyRunningRecord *DeviceDailyRunningRecord) AddDeviceRunningData(t time.Time, data *DeviceRunningData) bool {
func (deviceDailyRunningRecord *DeviceDailyRunningRecord) AddDeviceRunningData(data *DeviceRunningData) bool {
t := data.CollectionTime
deviceDailyRunningRecord.DeviceRunningRecordInfo.AddDeviceRunningData(t, data)
now := time.Now().Unix()
if ok, _ := data.Valid(); !ok {
return false
}
if t.Unix() > (now-DefaultCollectionTimeSpan) && t.Unix() < (now+DefaultCollectionTimeSpan) {
ts := t.Local().Unix()
if ts > (now-DefaultCollectionTimeSpan) && ts < (now+DefaultCollectionTimeSpan) {
deviceDailyRunningRecord.UpdatedAt = t
return false
return true
}
deviceDailyRunningRecord.UpdatedAt = time.Now()
return true
... ...
... ... @@ -28,7 +28,6 @@ func (ptr *PGWorkshopDataConsumeService) Consume(companyId, orgId int, record *d
planId int
err error
plan *domain.ProductPlanDispatchRecord
//datetime time.Time
)
var (
deviceRepository, _ = repository.NewDeviceRepository(ptr.transactionContext)
... ... @@ -67,7 +66,6 @@ func (ptr *PGWorkshopDataConsumeService) Consume(companyId, orgId int, record *d
var saveErr error
if deviceDailyRecord, saveErr = ptr.saveDeviceDailyRunningRecord(companyId, orgId, workStation, device, planId, deviceRunningData); err != nil {
//log.Logger.Error(saveErr.Error())
return nil, err
}
defer func() {
... ... @@ -94,20 +92,16 @@ func (ptr *PGWorkshopDataConsumeService) Consume(companyId, orgId int, record *d
}
// 2.更新 设备每日运行记录(汇总) - redis更新 十分钟异步刷库
if addSuccess := deviceDailyRecord.AddDeviceRunningData(deviceRunningData.CollectionTime, deviceRunningData); addSuccess {
if addSuccess := deviceDailyRecord.AddDeviceRunningData(deviceRunningData); addSuccess {
// 3.保存设备生产记录 (统计车间、员工产能) 批次跟数量不为空
if record.DeviceType == domain.DeviceTypeChuanChuanJi && plan != nil && deviceRunningData.Count > 0 {
productRecord, _ := ptr.newProductRecord(companyId, orgId, workStation, device, deviceRunningData, plan)
//SendProductRecordStaticsJob(productRecord)
productRecordService, _ := NewPGProductRecordService(ptr.transactionContext)
productRecordService.EmployeeProductStatics(productRecord)
productRecordService.WorkshopProductStatics(productRecord)
}
}
if err = redis.SaveDeviceDailyRunningRecord(deviceDailyRecord); err != nil {
//log.Logger.Error(err.Error())
return nil, err
}
return nil, nil
... ... @@ -155,16 +149,16 @@ func (ptr *PGWorkshopDataConsumeService) newDeviceRunningData(record *domain.Dev
if err != nil {
break
}
data.Temp1 = deviceYouZhaJi.FrontTemp
data.Temp2 = deviceYouZhaJi.BackTemp
data.Temp1 = utils.Truncate(deviceYouZhaJi.FrontTemp, 1)
data.Temp2 = utils.Truncate(deviceYouZhaJi.BackTemp, 1)
} else {
deviceYouZhaJi := &domain.DeviceYouZhaJi2{}
err = json.Unmarshal(mBytes, deviceYouZhaJi)
if err != nil {
break
}
data.Temp1 = deviceYouZhaJi.Temp1
data.Temp2 = deviceYouZhaJi.Temp2
data.Temp1 = utils.Truncate(deviceYouZhaJi.Temp1, 1)
data.Temp2 = utils.Truncate(deviceYouZhaJi.Temp2, 1)
}
break
//串串机
... ... @@ -189,7 +183,7 @@ func (ptr *PGWorkshopDataConsumeService) newDeviceRunningData(record *domain.Dev
if err != nil {
break
}
data.Temp1 = deviceSuDongXian.CurrTemp
data.Temp1 = utils.Truncate(deviceSuDongXian.CurrTemp, 1)
break
//封口机
case domain.DeviceTypeFengKouJi:
... ...