fix :统计修改
fix :统计修改 fix :统计修改 fix :统计修改 fix :统计修改 fix :统计修改 fix :统计修改
正在显示
8 个修改的文件
包含
80 行增加
和
19 行删除
@@ -91,7 +91,7 @@ func AutoFlushDeviceDailyRunningRecordOEE(ctx context.Context) error { | @@ -91,7 +91,7 @@ func AutoFlushDeviceDailyRunningRecordOEE(ctx context.Context) error { | ||
91 | log.Logger.Error(err.Error()) | 91 | log.Logger.Error(err.Error()) |
92 | continue | 92 | continue |
93 | } | 93 | } |
94 | - if err := redis.SaveDeviceDailyRunningRecord(v.ProductDate, v); err != nil { | 94 | + if err := redis.SaveDeviceDailyRunningRecordByKey(v.RedisKey, v); err != nil { |
95 | log.Logger.Error(err.Error(), map[string]interface{}{"task": "定时刷新设备每日运行记录"}) | 95 | log.Logger.Error(err.Error(), map[string]interface{}{"task": "定时刷新设备每日运行记录"}) |
96 | continue | 96 | continue |
97 | } | 97 | } |
@@ -33,6 +33,8 @@ type DeviceDailyRunningRecord struct { | @@ -33,6 +33,8 @@ type DeviceDailyRunningRecord struct { | ||
33 | UpdatedAt time.Time `json:"updatedAt"` | 33 | UpdatedAt time.Time `json:"updatedAt"` |
34 | // 删除时间 | 34 | // 删除时间 |
35 | DeletedAt time.Time `json:"deletedAt"` | 35 | DeletedAt time.Time `json:"deletedAt"` |
36 | + | ||
37 | + RedisKey string `json:"-"` | ||
36 | } | 38 | } |
37 | 39 | ||
38 | type DeviceDailyRunningRecordRepository interface { | 40 | type DeviceDailyRunningRecordRepository interface { |
@@ -69,10 +71,12 @@ func (deviceDailyRunningRecord *DeviceDailyRunningRecord) AddDeviceRunningData(d | @@ -69,10 +71,12 @@ func (deviceDailyRunningRecord *DeviceDailyRunningRecord) AddDeviceRunningData(d | ||
69 | } | 71 | } |
70 | 72 | ||
71 | func (deviceDailyRunningRecord *DeviceDailyRunningRecord) String() string { | 73 | func (deviceDailyRunningRecord *DeviceDailyRunningRecord) String() string { |
72 | - return fmt.Sprintf("记录ID:%v 工段:%v 设备:%v", | 74 | + return fmt.Sprintf("记录ID:%v 工段:%v 设备:%v 数量:%v(%v)", |
73 | deviceDailyRunningRecord.DeviceDailyRunningRecordId, | 75 | deviceDailyRunningRecord.DeviceDailyRunningRecordId, |
74 | deviceDailyRunningRecord.WorkStation.SectionName, | 76 | deviceDailyRunningRecord.WorkStation.SectionName, |
75 | deviceDailyRunningRecord.DeviceCode, | 77 | deviceDailyRunningRecord.DeviceCode, |
78 | + deviceDailyRunningRecord.DeviceRunningRecordInfo.Count, | ||
79 | + deviceDailyRunningRecord.DeviceRunningRecordInfo.ProductDate, | ||
76 | ) | 80 | ) |
77 | } | 81 | } |
78 | 82 |
@@ -98,7 +98,7 @@ func (ptr *PGWorkshopDataConsumeService) Consume(companyId, orgId int, record *d | @@ -98,7 +98,7 @@ func (ptr *PGWorkshopDataConsumeService) Consume(companyId, orgId int, record *d | ||
98 | if record.DeviceType == domain.DeviceTypeChuanChuanJi && plan != nil && deviceRunningData.Count > 0 { | 98 | if record.DeviceType == domain.DeviceTypeChuanChuanJi && plan != nil && deviceRunningData.Count > 0 { |
99 | log.Logger.Debug(fmt.Sprintf("设备统计 设备:%v(%v) 当前数量:%v 增加数量:%v", | 99 | log.Logger.Debug(fmt.Sprintf("设备统计 设备:%v(%v) 当前数量:%v 增加数量:%v", |
100 | deviceDailyRecord.DeviceCode, | 100 | deviceDailyRecord.DeviceCode, |
101 | - deviceDailyRecord.ProductDate.Local().Format("2006-01-02"), | 101 | + deviceDailyRecord.DeviceRunningRecordInfo.ProductDate, |
102 | deviceRunningRecord.DeviceRunningRecordInfo.TodayTotal, | 102 | deviceRunningRecord.DeviceRunningRecordInfo.TodayTotal, |
103 | deviceRunningRecord.DeviceRunningRecordInfo.Count)) | 103 | deviceRunningRecord.DeviceRunningRecordInfo.Count)) |
104 | productRecord, _ := ptr.newProductRecord(companyId, orgId, workStation, device, deviceRunningData, plan) | 104 | productRecord, _ := ptr.newProductRecord(companyId, orgId, workStation, device, deviceRunningData, plan) |
@@ -110,7 +110,7 @@ func (ptr *PGWorkshopDataConsumeService) Consume(companyId, orgId int, record *d | @@ -110,7 +110,7 @@ func (ptr *PGWorkshopDataConsumeService) Consume(companyId, orgId int, record *d | ||
110 | SendProductRecordStaticsJob(productRecord) | 110 | SendProductRecordStaticsJob(productRecord) |
111 | } | 111 | } |
112 | } | 112 | } |
113 | - if err = redis.SaveDeviceDailyRunningRecord(deviceRunningData.CollectionTime, deviceDailyRecord); err != nil { | 113 | + if err = redis.SaveDeviceDailyRunningRecordByKey(deviceDailyRecord.RedisKey, deviceDailyRecord); err != nil { |
114 | return nil, err | 114 | return nil, err |
115 | } | 115 | } |
116 | return nil, nil | 116 | return nil, nil |
@@ -282,21 +282,21 @@ func (ptr *PGWorkshopDataConsumeService) saveDeviceDailyRunningRecord(companyId, | @@ -282,21 +282,21 @@ func (ptr *PGWorkshopDataConsumeService) saveDeviceDailyRunningRecord(companyId, | ||
282 | if record, err = deviceDailyRunningRecordRepository.FindOne(map[string]interface{}{ | 282 | if record, err = deviceDailyRunningRecordRepository.FindOne(map[string]interface{}{ |
283 | "workStationId": workStation.WorkStationId, | 283 | "workStationId": workStation.WorkStationId, |
284 | "deviceCode": data.DeviceCode, | 284 | "deviceCode": data.DeviceCode, |
285 | - "productDate": utils.GetZeroTime(data.CollectionTime), | 285 | + "productDate": utils.GetZeroTime(data.CollectionTime.Local()), |
286 | }); err != nil { | 286 | }); err != nil { |
287 | if err != domain.ErrorNotFound { | 287 | if err != domain.ErrorNotFound { |
288 | return nil, err | 288 | return nil, err |
289 | } | 289 | } |
290 | } | 290 | } |
291 | if record != nil { | 291 | if record != nil { |
292 | - | 292 | + record.RedisKey = redis.DeviceDailyRunningRecordKeyByTimeStr(record.DeviceRunningRecordInfo.ProductDate, record.DeviceCode) |
293 | return record, nil | 293 | return record, nil |
294 | } | 294 | } |
295 | recordInfo := domain.NewDeviceRunningRecordInfo() | 295 | recordInfo := domain.NewDeviceRunningRecordInfo() |
296 | recordInfo.ProductPlanId = planId | 296 | recordInfo.ProductPlanId = planId |
297 | recordInfo.DeviceName = device.DeviceName | 297 | recordInfo.DeviceName = device.DeviceName |
298 | recordInfo.OrgName = device.Ext.OrgName | 298 | recordInfo.OrgName = device.Ext.OrgName |
299 | - recordInfo.ProductDate = data.CollectionTime.Format("2006-01-02") | 299 | + recordInfo.ProductDate = data.CollectionTime.Local().Format("2006-01-02") |
300 | record = &domain.DeviceDailyRunningRecord{ | 300 | record = &domain.DeviceDailyRunningRecord{ |
301 | CompanyId: companyId, | 301 | CompanyId: companyId, |
302 | OrgId: orgId, | 302 | OrgId: orgId, |
@@ -308,6 +308,7 @@ func (ptr *PGWorkshopDataConsumeService) saveDeviceDailyRunningRecord(companyId, | @@ -308,6 +308,7 @@ func (ptr *PGWorkshopDataConsumeService) saveDeviceDailyRunningRecord(companyId, | ||
308 | CreatedAt: data.CollectionTime, | 308 | CreatedAt: data.CollectionTime, |
309 | UpdatedAt: time.Now(), | 309 | UpdatedAt: time.Now(), |
310 | } | 310 | } |
311 | + record.RedisKey = redis.DeviceDailyRunningRecordKeyByTimeStr(record.DeviceRunningRecordInfo.ProductDate, record.DeviceCode) | ||
311 | if record, err = deviceDailyRunningRecordRepository.Save(record); err != nil { | 312 | if record, err = deviceDailyRunningRecordRepository.Save(record); err != nil { |
312 | return nil, err | 313 | return nil, err |
313 | } | 314 | } |
@@ -14,8 +14,9 @@ import ( | @@ -14,8 +14,9 @@ import ( | ||
14 | func GetDeviceDailyRunningRecord(t time.Time, deviceCode string) (*domain.DeviceDailyRunningRecord, error) { | 14 | func GetDeviceDailyRunningRecord(t time.Time, deviceCode string) (*domain.DeviceDailyRunningRecord, error) { |
15 | client := GetRedis() | 15 | client := GetRedis() |
16 | key := DeviceDailyRunningRecordKey(t, deviceCode) | 16 | key := DeviceDailyRunningRecordKey(t, deviceCode) |
17 | - log.Logger.Debug(fmt.Sprintf("Redis Device:%v GET Key:%v", deviceCode, key)) | ||
18 | - return getDeviceDailyRunningRecord(client, key) | 17 | + record, err := getDeviceDailyRunningRecord(client, key) |
18 | + log.Logger.Debug(fmt.Sprintf("Redis Device:%v GET Key:%v Value:%v", deviceCode, key, record)) | ||
19 | + return record, err | ||
19 | } | 20 | } |
20 | 21 | ||
21 | func getDeviceDailyRunningRecord(client *redis.Client, key string) (*domain.DeviceDailyRunningRecord, error) { | 22 | func getDeviceDailyRunningRecord(client *redis.Client, key string) (*domain.DeviceDailyRunningRecord, error) { |
@@ -25,6 +26,7 @@ func getDeviceDailyRunningRecord(client *redis.Client, key string) (*domain.Devi | @@ -25,6 +26,7 @@ func getDeviceDailyRunningRecord(client *redis.Client, key string) (*domain.Devi | ||
25 | return nil, domain.ErrorNotFound | 26 | return nil, domain.ErrorNotFound |
26 | } | 27 | } |
27 | var record = &domain.DeviceDailyRunningRecord{} | 28 | var record = &domain.DeviceDailyRunningRecord{} |
29 | + record.RedisKey = key | ||
28 | if err = json.Unmarshal(data, record); err != nil { | 30 | if err = json.Unmarshal(data, record); err != nil { |
29 | return nil, err | 31 | return nil, err |
30 | } | 32 | } |
@@ -35,13 +37,25 @@ func getDeviceDailyRunningRecord(client *redis.Client, key string) (*domain.Devi | @@ -35,13 +37,25 @@ func getDeviceDailyRunningRecord(client *redis.Client, key string) (*domain.Devi | ||
35 | func SaveDeviceDailyRunningRecord(t time.Time, record *domain.DeviceDailyRunningRecord) error { | 37 | func SaveDeviceDailyRunningRecord(t time.Time, record *domain.DeviceDailyRunningRecord) error { |
36 | client := GetRedis() | 38 | client := GetRedis() |
37 | key := DeviceDailyRunningRecordKey(t, record.DeviceCode) | 39 | key := DeviceDailyRunningRecordKey(t, record.DeviceCode) |
38 | - log.Logger.Debug(fmt.Sprintf("Redis Device:%v SET Key:%v Count:%v", record.DeviceCode, key, record.DeviceRunningRecordInfo.Count)) | ||
39 | recordData, err := json.Marshal(record) | 40 | recordData, err := json.Marshal(record) |
40 | result := client.Set(key, recordData, time.Hour*24*5) | 41 | result := client.Set(key, recordData, time.Hour*24*5) |
41 | _, err = result.Result() | 42 | _, err = result.Result() |
42 | return err | 43 | return err |
43 | } | 44 | } |
44 | 45 | ||
46 | +// 保存每日设备运行数据 - 按键值 | ||
47 | +func SaveDeviceDailyRunningRecordByKey(key string, record *domain.DeviceDailyRunningRecord) error { | ||
48 | + client := GetRedis() | ||
49 | + recordData, err := json.Marshal(record) | ||
50 | + if err != nil { | ||
51 | + return err | ||
52 | + } | ||
53 | + log.Logger.Debug(fmt.Sprintf("Redis Device:%v SET Key:%v Value:%v", record.DeviceCode, key, record)) | ||
54 | + result := client.Set(key, recordData, time.Hour*24*5) | ||
55 | + _, err = result.Result() | ||
56 | + return err | ||
57 | +} | ||
58 | + | ||
45 | // 保存每日设备运行数据 | 59 | // 保存每日设备运行数据 |
46 | func RemoveDeviceDailyRunningRecord(t time.Time, deviceCode string) error { | 60 | func RemoveDeviceDailyRunningRecord(t time.Time, deviceCode string) error { |
47 | client := GetRedis() | 61 | client := GetRedis() |
@@ -51,11 +65,25 @@ func RemoveDeviceDailyRunningRecord(t time.Time, deviceCode string) error { | @@ -51,11 +65,25 @@ func RemoveDeviceDailyRunningRecord(t time.Time, deviceCode string) error { | ||
51 | return err | 65 | return err |
52 | } | 66 | } |
53 | 67 | ||
68 | +// 保存每日设备运行数据 | ||
69 | +func RemoveDeviceDailyRunningRecordByKey(key string) error { | ||
70 | + client := GetRedis() | ||
71 | + //key := DeviceDailyRunningRecordKey(t, deviceCode) | ||
72 | + result := client.Del(key) | ||
73 | + _, err := result.Result() | ||
74 | + return err | ||
75 | +} | ||
76 | + | ||
54 | func DeviceDailyRunningRecordKey(t time.Time, deviceCode string) string { | 77 | func DeviceDailyRunningRecordKey(t time.Time, deviceCode string) string { |
55 | str := fmt.Sprintf("%v:device-daily-record:%v-%v:%v:%v", constant.CACHE_PREFIX, constant.MANUFACTURE_DEFAULT_COMPANYID, constant.MANUFACTURE_DEFAULT_ORGID, t.Local().Format("2006-01-02"), deviceCode) | 78 | str := fmt.Sprintf("%v:device-daily-record:%v-%v:%v:%v", constant.CACHE_PREFIX, constant.MANUFACTURE_DEFAULT_COMPANYID, constant.MANUFACTURE_DEFAULT_ORGID, t.Local().Format("2006-01-02"), deviceCode) |
56 | return str | 79 | return str |
57 | } | 80 | } |
58 | 81 | ||
82 | +func DeviceDailyRunningRecordKeyByTimeStr(timeStr string, deviceCode string) string { | ||
83 | + str := fmt.Sprintf("%v:device-daily-record:%v-%v:%v:%v", constant.CACHE_PREFIX, constant.MANUFACTURE_DEFAULT_COMPANYID, constant.MANUFACTURE_DEFAULT_ORGID, timeStr, deviceCode) | ||
84 | + return str | ||
85 | +} | ||
86 | + | ||
59 | // 获取设备每日所有数据记录 | 87 | // 获取设备每日所有数据记录 |
60 | func GetDeviceDailyAllRecord(t time.Time) ([]*domain.DeviceDailyRunningRecord, error) { | 88 | func GetDeviceDailyAllRecord(t time.Time) ([]*domain.DeviceDailyRunningRecord, error) { |
61 | client := GetRedis() | 89 | client := GetRedis() |
@@ -70,6 +98,7 @@ func GetDeviceDailyAllRecord(t time.Time) ([]*domain.DeviceDailyRunningRecord, e | @@ -70,6 +98,7 @@ func GetDeviceDailyAllRecord(t time.Time) ([]*domain.DeviceDailyRunningRecord, e | ||
70 | if err != nil { | 98 | if err != nil { |
71 | return nil, err | 99 | return nil, err |
72 | } | 100 | } |
101 | + record.RedisKey = v | ||
73 | records = append(records, record) | 102 | records = append(records, record) |
74 | } | 103 | } |
75 | return records, nil | 104 | return records, nil |
@@ -23,12 +23,13 @@ func TestTimeParseInLocal(t *testing.T) { | @@ -23,12 +23,13 @@ func TestTimeParseInLocal(t *testing.T) { | ||
23 | u1.AgeZeroFormat = u1.AgeZero.Format("2006-01-02") | 23 | u1.AgeZeroFormat = u1.AgeZero.Format("2006-01-02") |
24 | 24 | ||
25 | fmt.Println(json.MarshalToString(u1), u1.Age.Local()) | 25 | fmt.Println(json.MarshalToString(u1), u1.Age.Local()) |
26 | + timeMarsh(&u1) | ||
27 | +} | ||
26 | 28 | ||
27 | - u2 := User{ | ||
28 | - Age: tl, | ||
29 | - AgeZero: GetZeroTimeWithLocal(tl, time.Local), | ||
30 | - } | ||
31 | - u2.AgeZeroFormat = u2.AgeZero.Format("2006-01-02") | 29 | +func timeMarsh(u *User) { |
30 | + var u2 = &User{} | ||
31 | + u1Data, _ := json.Marshal(u) | ||
32 | + json.Unmarshal(u1Data, u2) | ||
32 | 33 | ||
33 | - fmt.Println(json.MarshalToString(u2), u2.Age.Local()) | 34 | + fmt.Println("时间:", u2.Age, u2.Age.Local(), u2.AgeZero) |
34 | } | 35 | } |
@@ -119,6 +119,31 @@ func (controller *StatisticsController) TaskHandler() func(ctx *context.Context) | @@ -119,6 +119,31 @@ func (controller *StatisticsController) TaskHandler() func(ctx *context.Context) | ||
119 | } | 119 | } |
120 | Response(ctx, response, nil) | 120 | Response(ctx, response, nil) |
121 | break | 121 | break |
122 | + case "10": | ||
123 | + t := ctx.Input.Query("t") | ||
124 | + c, _ := strconv.Atoi(ctx.Input.Query("c")) | ||
125 | + if len(t) != 0 { | ||
126 | + if v, err := time.ParseInLocation("2006-01-02 - 15:04:05", t, time.UTC); err == nil { | ||
127 | + domainService.SendWorkshopDeviceData(&domain.DeviceCollection{ | ||
128 | + DeviceCollectionId: time.Now().Unix(), | ||
129 | + WorkShopName: "NG", | ||
130 | + CollectionTime: v, | ||
131 | + DeviceSn: "CCJ1", | ||
132 | + DeviceType: "CCJ", | ||
133 | + StartupStatus: 1, | ||
134 | + ComStatus: 1, | ||
135 | + ProductCount: c, | ||
136 | + Values: map[string]interface{}{ | ||
137 | + "Count": c, | ||
138 | + "Year": 2022, | ||
139 | + "Month": 3, | ||
140 | + "Day": 8, | ||
141 | + "ProductType": 2, | ||
142 | + }, | ||
143 | + LatestUpdateTime: time.Now(), | ||
144 | + }) | ||
145 | + } | ||
146 | + } | ||
122 | } | 147 | } |
123 | Response(ctx, nil, nil) | 148 | Response(ctx, nil, nil) |
124 | } | 149 | } |
@@ -22,13 +22,14 @@ func Start(log logimp.Logger) { | @@ -22,13 +22,14 @@ func Start(log logimp.Logger) { | ||
22 | 22 | ||
23 | func OnReceiveData(client pahomqtt.Client, message pahomqtt.Message) { | 23 | func OnReceiveData(client pahomqtt.Client, message pahomqtt.Message) { |
24 | payload := make(map[string]interface{}) | 24 | payload := make(map[string]interface{}) |
25 | + var collectionTime time.Time | ||
25 | err := json.Unmarshal(message.Payload(), &payload) | 26 | err := json.Unmarshal(message.Payload(), &payload) |
26 | if err != nil { | 27 | if err != nil { |
27 | log.Logger.Error("车间数据json解析失败:" + err.Error()) | 28 | log.Logger.Error("车间数据json解析失败:" + err.Error()) |
28 | return | 29 | return |
29 | } | 30 | } |
30 | if workShop, ok := payload["WorkShop"]; ok { | 31 | if workShop, ok := payload["WorkShop"]; ok { |
31 | - var collectionTime time.Time | 32 | + |
32 | if t, ok := payload["UpTime"]; ok { | 33 | if t, ok := payload["UpTime"]; ok { |
33 | collectionTime, _ = time.ParseInLocation("2006-01-02 - 15:04:05", t.(string), time.Local) | 34 | collectionTime, _ = time.ParseInLocation("2006-01-02 - 15:04:05", t.(string), time.Local) |
34 | } | 35 | } |
@@ -153,7 +154,7 @@ func OnReceiveData(client pahomqtt.Client, message pahomqtt.Message) { | @@ -153,7 +154,7 @@ func OnReceiveData(client pahomqtt.Client, message pahomqtt.Message) { | ||
153 | } | 154 | } |
154 | //TODO:日志先注释 | 155 | //TODO:日志先注释 |
155 | if err == nil { | 156 | if err == nil { |
156 | - log.Logger.Info("MQTT", map[string]interface{}{ | 157 | + log.Logger.Info(fmt.Sprintf("MQTT:%v", collectionTime), map[string]interface{}{ |
157 | "Topic": message.Topic(), | 158 | "Topic": message.Topic(), |
158 | "MessageId": message.MessageID(), | 159 | "MessageId": message.MessageID(), |
159 | "Message": payload, | 160 | "Message": payload, |
@@ -19,7 +19,7 @@ func WorkshopDataConsumer(c context.Context, t *asynq.Task) error { | @@ -19,7 +19,7 @@ func WorkshopDataConsumer(c context.Context, t *asynq.Task) error { | ||
19 | return err | 19 | return err |
20 | } | 20 | } |
21 | log.Logger.Debug(fmt.Sprintf("【车间数据消费】 消费 设备:%v 消息号:%v 时间:%v ", cmd.DeviceCollection.DeviceSn, cmd.DeviceCollectionId, cmd.CollectionTime), | 21 | log.Logger.Debug(fmt.Sprintf("【车间数据消费】 消费 设备:%v 消息号:%v 时间:%v ", cmd.DeviceCollection.DeviceSn, cmd.DeviceCollectionId, cmd.CollectionTime), |
22 | - map[string]interface{}{"p-message": cmd.DeviceCollection}) | 22 | + map[string]interface{}{"p-message": string(t.Payload())}) |
23 | cmd.CompanyId = constant.MANUFACTURE_DEFAULT_COMPANYID | 23 | cmd.CompanyId = constant.MANUFACTURE_DEFAULT_COMPANYID |
24 | cmd.OrgId = constant.MANUFACTURE_DEFAULT_ORGID | 24 | cmd.OrgId = constant.MANUFACTURE_DEFAULT_ORGID |
25 | _, err := svr.WorkshopConsume(cmd) | 25 | _, err := svr.WorkshopConsume(cmd) |
-
请 注册 或 登录 后发表评论