作者 yangfu

refactor: 车间数据消费增加日志

... ... @@ -151,6 +151,7 @@ func (deviceCollectionService *DeviceCollectionService) DeviceCollection(createD
// newDeviceCollection.Values["Count"] = rand.Intn(300)
// newDeviceCollection.StartupStatus = 1
// newDeviceCollection.ComStatus = 1
// newDeviceCollection.CollectionTime = time.Date(2022,4,18,7,0,0,0,time.Local)
//}
if newDeviceCollection, err = deviceCollectionRepository.Save(newDeviceCollection); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ...
... ... @@ -70,7 +70,7 @@ func (ptr *PGWorkshopDataConsumeService) Consume(companyId, orgId int, record *d
}
defer func() {
if saveErr != nil {
redis.RemoveDeviceDailyRunningRecord(time.Now(), deviceRunningData.DeviceCode)
redis.RemoveDeviceDailyRunningRecord(deviceRunningData.CollectionTime, deviceRunningData.DeviceCode)
}
}()
}
... ... @@ -96,8 +96,9 @@ func (ptr *PGWorkshopDataConsumeService) Consume(companyId, orgId int, record *d
if addSuccess := deviceDailyRecord.AddDeviceRunningData(deviceRunningData); addSuccess {
// 3.保存设备生产记录 (统计车间、员工产能) 批次跟数量不为空
if record.DeviceType == domain.DeviceTypeChuanChuanJi && plan != nil && deviceRunningData.Count > 0 {
log.Logger.Debug(fmt.Sprintf("设备统计 设备:%v 当前数量:%v 增加数量:%v",
log.Logger.Debug(fmt.Sprintf("设备统计 设备:%v(%v) 当前数量:%v 增加数量:%v",
deviceDailyRecord.DeviceCode,
deviceDailyRecord.ProductDate.Local().Format("2006-01-02"),
deviceRunningRecord.DeviceRunningRecordInfo.TodayTotal,
deviceRunningRecord.DeviceRunningRecordInfo.Count))
productRecord, _ := ptr.newProductRecord(companyId, orgId, workStation, device, deviceRunningData, plan)
... ... @@ -300,7 +301,7 @@ func (ptr *PGWorkshopDataConsumeService) saveDeviceDailyRunningRecord(companyId,
DeviceCode: device.DeviceCode,
ProductDate: utils.GetZeroTime(data.CollectionTime),
DeviceRunningRecordInfo: recordInfo,
CreatedAt: time.Now(),
CreatedAt: data.CollectionTime,
UpdatedAt: time.Now(),
}
if record, err = deviceDailyRunningRecordRepository.Save(record); err != nil {
... ...
... ... @@ -6,6 +6,7 @@ import (
"github.com/go-redis/redis"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
"time"
)
... ... @@ -13,6 +14,7 @@ import (
func GetDeviceDailyRunningRecord(t time.Time, deviceCode string) (*domain.DeviceDailyRunningRecord, error) {
client := GetRedis()
key := DeviceDailyRunningRecordKey(t, deviceCode)
log.Logger.Debug(fmt.Sprintf("Redis Device:%v GET Key:%v", deviceCode, key))
return getDeviceDailyRunningRecord(client, key)
}
... ... @@ -32,7 +34,8 @@ func getDeviceDailyRunningRecord(client *redis.Client, key string) (*domain.Devi
// 保存每日设备运行数据
func SaveDeviceDailyRunningRecord(record *domain.DeviceDailyRunningRecord) error {
client := GetRedis()
key := DeviceDailyRunningRecordKey(record.ProductDate.Local(), record.DeviceCode)
key := DeviceDailyRunningRecordKey(record.ProductDate, record.DeviceCode)
log.Logger.Debug(fmt.Sprintf("Redis Device:%v SET Key:%v Count:%v", record.DeviceCode, key, record.DeviceRunningRecordInfo.Count))
recordData, err := json.Marshal(record)
result := client.Set(key, recordData, time.Hour*24*5)
_, err = result.Result()
... ... @@ -42,7 +45,7 @@ func SaveDeviceDailyRunningRecord(record *domain.DeviceDailyRunningRecord) error
// 保存每日设备运行数据
func RemoveDeviceDailyRunningRecord(t time.Time, deviceCode string) error {
client := GetRedis()
key := DeviceDailyRunningRecordKey(t.Local(), deviceCode)
key := DeviceDailyRunningRecordKey(t, deviceCode)
result := client.Del(key)
_, err := result.Result()
return err
... ...
... ... @@ -68,6 +68,7 @@ func timeParse() {
fmt.Println("1. str: ", str)
t, _ := time.Parse(TIME_LAYOUT, str)
fmt.Println("2. Parse time: ", t)
fmt.Println("2.1. Parse time: ", t.Local(), t.Local().Local())
tStr := t.Format(TIME_LAYOUT)
fmt.Println("3. Format time str: ", tStr)
name, offset := t.Zone()
... ...
package mqtt
import (
"fmt"
pahomqtt "github.com/eclipse/paho.mqtt.golang"
logimp "github.com/linmadan/egglib-go/log"
"github.com/linmadan/egglib-go/utils/json"
... ... @@ -32,6 +33,7 @@ func OnReceiveData(client pahomqtt.Client, message pahomqtt.Message) {
collectionTime, _ = time.ParseInLocation("2006-01-02 - 15:04:05", t.(string), time.Local)
}
if collectionTime.IsZero() {
log.Logger.Error(fmt.Sprintf("采集时间有误:%v ", collectionTime), map[string]interface{}{"data": message})
return
}
var mBytes []byte
... ...