...
|
...
|
@@ -3,8 +3,13 @@ package crontab |
|
|
import (
|
|
|
"context"
|
|
|
"fmt"
|
|
|
"github.com/linmadan/egglib-go/transaction/pg"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/dao"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/redis"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
|
|
|
"time"
|
|
|
)
|
...
|
...
|
@@ -40,6 +45,9 @@ func AutoFlushDeviceDailyRunningRecordOEE(ctx context.Context) error { |
|
|
log.Logger.Error(err.Error())
|
|
|
return err
|
|
|
}
|
|
|
total := 24 * 60 * 60
|
|
|
deviceRepository, _, _ := factory.FastPgDevice(transactionContext, 0)
|
|
|
workshopProductRecordDao, _ := dao.NewWorkshopProductRecordDao(transactionContext.(*pg.TransactionContext))
|
|
|
|
|
|
for _, v := range records {
|
|
|
//if v.UpdatedAt.Add(time.Minute * 5).Before(time.Now()) {
|
...
|
...
|
@@ -47,26 +55,47 @@ func AutoFlushDeviceDailyRunningRecordOEE(ctx context.Context) error { |
|
|
// continue
|
|
|
//}
|
|
|
|
|
|
var (
|
|
|
pu float64 = 100
|
|
|
qu float64 = 100
|
|
|
)
|
|
|
|
|
|
// 更新设备效率 OEE = tu * pu * qu
|
|
|
/*
|
|
|
pu 性能利用
|
|
|
设备标准工时,
|
|
|
没有配置设备标准工时的为100
|
|
|
*/
|
|
|
//pu :=100
|
|
|
//if v.DeviceRunningRecordInfo
|
|
|
// 设备数据(标准工时)
|
|
|
|
|
|
// 只计算串串机
|
|
|
if v.DeviceRunningRecordInfo.DeviceType == domain.DeviceTypeChuanChuanJi {
|
|
|
// 设备数据(标准工时)
|
|
|
device, err := deviceRepository.FindOne(map[string]interface{}{"deviceId": v.DeviceId})
|
|
|
if device != nil && err == nil {
|
|
|
if device.Ext.DeviceExt != nil {
|
|
|
pu = utils.Round(float64((v.DeviceRunningRecordInfo.Count*100.0)/(total/device.Ext.DeviceExt.UnitProductionSecTime)), 1)
|
|
|
}
|
|
|
}
|
|
|
// 工段对应二级品数据
|
|
|
|
|
|
v.DeviceRunningRecordInfo.ResetOEE(0, 0)
|
|
|
record, err := workshopProductRecordDao.WorkStationProductRecord(v.CompanyId, v.OrgId, v.WorkStation.WorkStationId, t)
|
|
|
if record != nil && err == nil {
|
|
|
qu = float64(v.DeviceRunningRecordInfo.Count) * domainService.DefaultCCJUnitQuantity
|
|
|
qu = utils.Round((qu-record.SecondLevelWeigh)*100/qu, 1)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
v.DeviceRunningRecordInfo.ResetOEE(pu, qu)
|
|
|
|
|
|
if _, err := deviceDailyRunningRecordRepository.Save(v); err != nil {
|
|
|
log.Logger.Error(err.Error())
|
|
|
continue
|
|
|
} else {
|
|
|
log.Logger.Debug(fmt.Sprintf("【定时刷新设备每日运行记录-OEE】 刷新记录 %v", v))
|
|
|
}
|
|
|
if err := redis.SaveDeviceDailyRunningRecord(v); err != nil {
|
|
|
log.Logger.Error(err.Error())
|
|
|
continue
|
|
|
}
|
|
|
log.Logger.Debug(fmt.Sprintf("【定时刷新设备每日运行记录-OEE】 刷新记录 %v", v))
|
|
|
}
|
|
|
|
|
|
if err = transactionContext.CommitTransaction(); err != nil {
|
...
|
...
|
|