作者 yangfu

Merge remote-tracking branch 'origin/test'

@@ -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); 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 }
@@ -32,7 +32,7 @@ type UpdateDeviceCommand struct { @@ -32,7 +32,7 @@ type UpdateDeviceCommand struct {
32 // 风险等级 1:高 2:中 3:低 32 // 风险等级 1:高 2:中 3:低
33 RiskLevel int `cname:"风险等级 1:高 2:中 3:低" json:"riskLevel" valid:"Required"` 33 RiskLevel int `cname:"风险等级 1:高 2:中 3:低" json:"riskLevel" valid:"Required"`
34 // 标准工时 34 // 标准工时
35 - UnitProductionSecTime int `cname:"标准工时" json:"unitProductionSecTime"` 35 + UnitProductionSecTime float64 `cname:"标准工时" json:"unitProductionSecTime"`
36 } 36 }
37 37
38 func (updateDeviceCommand *UpdateDeviceCommand) Valid(validation *validation.Validation) { 38 func (updateDeviceCommand *UpdateDeviceCommand) Valid(validation *validation.Validation) {
@@ -153,6 +153,8 @@ func (deviceCollectionService *DeviceCollectionService) DeviceCollection(createD @@ -153,6 +153,8 @@ func (deviceCollectionService *DeviceCollectionService) DeviceCollection(createD
153 // newDeviceCollection.ComStatus = 1 153 // newDeviceCollection.ComStatus = 1
154 // newDeviceCollection.CollectionTime = time.Date(2022,4,18,7,0,0,0,time.Local) 154 // newDeviceCollection.CollectionTime = time.Date(2022,4,18,7,0,0,0,time.Local)
155 //} 155 //}
  156 +
  157 + // !!!!!!! 注意:保存到库以后 collect_time 变成了 UTC时间,后续处理的时候都要加上collectTime.Local()
156 if newDeviceCollection, err = deviceCollectionRepository.Save(newDeviceCollection); err != nil { 158 if newDeviceCollection, err = deviceCollectionRepository.Save(newDeviceCollection); err != nil {
157 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 159 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
158 } 160 }
1 package syncdata 1 package syncdata
2 2
3 import ( 3 import (
  4 + "fmt"
4 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant" 5 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant"
5 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" 6 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
6 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService" 7 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService"
@@ -523,16 +524,25 @@ func (srv *PullDataK3CloudService) SyncDataProductPlan(ptr *pgTransaction.Transa @@ -523,16 +524,25 @@ func (srv *PullDataK3CloudService) SyncDataProductPlan(ptr *pgTransaction.Transa
523 continue 524 continue
524 } 525 }
525 // 计划信息 526 // 计划信息
526 - plan, err = productPlanRepository.FindOne(map[string]interface{}{"companyId": cid, "orgId": oid, "batchNumber": v.BillNo}) 527 + plan, err = productPlanRepository.FindOne(map[string]interface{}{"companyId": cid, "orgId": oid, "erpBillNo": v.BillNo, "productCode": v.MaterialNumber})
527 if err == nil && plan != nil { 528 if err == nil && plan != nil {
528 - plan.UpdatedAt = time.Now() 529 + //plan.UpdatedAt = time.Now()
  530 + continue
  531 + }
  532 + count, _, errFindPlan := productPlanRepository.Find(map[string]interface{}{"companyId": cid, "orgId": oid, "erpBillNo": v.BillNo, "productCode": v.MaterialNumber})
  533 + if errFindPlan != nil {
529 continue 534 continue
530 } 535 }
  536 + /* ERP系统BillNO + MaterialNumber 唯一 会重复,需要做自增格式化处理*/
  537 + batchNumber := fmt.Sprintf("%v-1", v.BillNo)
  538 + if count >= 1 {
  539 + batchNumber = fmt.Sprintf("%v-%v", v.BillNo, count)
  540 + }
531 if err == domain.ErrorNotFound { 541 if err == domain.ErrorNotFound {
532 plan = &domain.ProductPlan{ 542 plan = &domain.ProductPlan{
533 CompanyId: cid, 543 CompanyId: cid,
534 OrgId: oid, 544 OrgId: oid,
535 - BatchNumber: v.BillNo, 545 + BatchNumber: batchNumber,
536 ProductDate: v.PlanStartDate, 546 ProductDate: v.PlanStartDate,
537 Workshop: workshop.CloneSample(), 547 Workshop: workshop.CloneSample(),
538 WorkOn: 0, 548 WorkOn: 0,
@@ -557,6 +567,7 @@ func (srv *PullDataK3CloudService) SyncDataProductPlan(ptr *pgTransaction.Transa @@ -557,6 +567,7 @@ func (srv *PullDataK3CloudService) SyncDataProductPlan(ptr *pgTransaction.Transa
557 ProductCode: product.ProductCode, 567 ProductCode: product.ProductCode,
558 ProductName: product.ProductName, 568 ProductName: product.ProductName,
559 DevotedUnit: "份", 569 DevotedUnit: "份",
  570 + ErpBillNo: v.BillNo,
560 }) 571 })
561 plan.PlanProductName = product.ProductName 572 plan.PlanProductName = product.ProductName
562 plan.Remark = v.Description 573 plan.Remark = v.Description
@@ -20,16 +20,16 @@ var MQTT_TOPIC = "/MQTT" @@ -20,16 +20,16 @@ var MQTT_TOPIC = "/MQTT"
20 //var MQTT_USER = "" 20 //var MQTT_USER = ""
21 //var MQTT_PASSWORD = "" 21 //var MQTT_PASSWORD = ""
22 22
23 -var MQTT_HOST = "175.24.122.87"  
24 -var MQTT_PORT = "1883"  
25 -var MQTT_USER = "user111"  
26 -var MQTT_PASSWORD = "user111" 23 +//var MQTT_HOST = "175.24.122.87"
  24 +//var MQTT_PORT = "1883"
  25 +//var MQTT_USER = "user111"
  26 +//var MQTT_PASSWORD = "user111"
27 27
28 //内网测试地址 28 //内网测试地址
29 -//var MQTT_HOST = "192.168.100.222"  
30 -//var MQTT_PORT = "1883"  
31 -//var MQTT_USER = "admin"  
32 -//var MQTT_PASSWORD = "123456" 29 +var MQTT_HOST = "47.97.5.102"
  30 +var MQTT_PORT = "6000"
  31 +var MQTT_USER = "admin"
  32 +var MQTT_PASSWORD = "123456"
33 33
34 func init() { 34 func init() {
35 if os.Getenv("MQTT_HOST") != "" { 35 if os.Getenv("MQTT_HOST") != "" {
@@ -36,12 +36,12 @@ type DeviceChuanChuanJi struct { @@ -36,12 +36,12 @@ type DeviceChuanChuanJi struct {
36 Month int `json:"Month"` // 月 36 Month int `json:"Month"` // 月
37 Day int `json:"Day"` // 日 37 Day int `json:"Day"` // 日
38 ProductType int `json:"ProductType"` 38 ProductType int `json:"ProductType"`
39 - //ProductType1 string `json:"ProductType1"` // 产品类型:当前产品种类  
40 } 39 }
41 40
42 // 速冻线 41 // 速冻线
43 type DeviceSuDongXian struct { 42 type DeviceSuDongXian struct {
44 CurrTemp float64 `json:"CurrTemp"` // 当前温度:当前温度 43 CurrTemp float64 `json:"CurrTemp"` // 当前温度:当前温度
  44 + Alarm int `json:"alarm"` // 报警
45 } 45 }
46 46
47 // 封口机 47 // 封口机
@@ -51,7 +51,6 @@ type DeviceFengKouJi struct { @@ -51,7 +51,6 @@ type DeviceFengKouJi struct {
51 Month int `json:"Month"` // 月 51 Month int `json:"Month"` // 月
52 Day int `json:"Day"` // 日 52 Day int `json:"Day"` // 日
53 ProductType int `json:"ProductType"` 53 ProductType int `json:"ProductType"`
54 - //ProductType1 string `json:"ProductType1"` // 产品类型:当前产品种类  
55 } 54 }
56 55
57 // 封箱机 56 // 封箱机
@@ -61,7 +60,6 @@ type DeviceFengXiangJi struct { @@ -61,7 +60,6 @@ type DeviceFengXiangJi struct {
61 Month int `json:"Month"` // 月 60 Month int `json:"Month"` // 月
62 Day int `json:"Day"` // 日 61 Day int `json:"Day"` // 日
63 ProductType int `json:"ProductType"` 62 ProductType int `json:"ProductType"`
64 - //ProductType1 string `json:"ProductType1"` // 产品类型:当前产品种类  
65 } 63 }
66 64
67 func ProductTypeToProductCode(productType int) string { 65 func ProductTypeToProductCode(productType int) string {
@@ -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,15 +71,19 @@ func (deviceDailyRunningRecord *DeviceDailyRunningRecord) AddDeviceRunningData(d @@ -69,15 +71,19 @@ 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
79 // 设备运行记录信息 83 // 设备运行记录信息
80 type DeviceRunningRecordInfo struct { 84 type DeviceRunningRecordInfo struct {
  85 + // 日期
  86 + ProductDate string `json:"productDate"`
81 // 设备类型 87 // 设备类型
82 DeviceType string `json:"deviceType"` 88 DeviceType string `json:"deviceType"`
83 // 当前状态 89 // 当前状态
@@ -133,7 +139,7 @@ func (d *DeviceRunningRecordInfo) AddDeviceRunningData(t time.Time, data *Device @@ -133,7 +139,7 @@ func (d *DeviceRunningRecordInfo) AddDeviceRunningData(t time.Time, data *Device
133 if len(d.DeviceType) == 0 { 139 if len(d.DeviceType) == 0 {
134 d.DeviceType = data.DeviceType 140 d.DeviceType = data.DeviceType
135 } 141 }
136 - d.CurrentStatus = data.StartupStatus | (1 << data.ComStatus) 142 + d.CurrentStatus = data.StartupStatus | (data.ComStatus << 1) | (data.Alarm << 2)
137 d.ResetUpTime() 143 d.ResetUpTime()
138 d.Count += data.Count 144 d.Count += data.Count
139 //d.Temp = data.FrontTemp 145 //d.Temp = data.FrontTemp
@@ -163,6 +169,7 @@ func (d *DeviceRunningRecordInfo) AddTimeLineDeviceStatus(t time.Time, data *Dev @@ -163,6 +169,7 @@ func (d *DeviceRunningRecordInfo) AddTimeLineDeviceStatus(t time.Time, data *Dev
163 } 169 }
164 v.UpdateUp(t, data.StartupStatus) 170 v.UpdateUp(t, data.StartupStatus)
165 v.UpdateCom(t, data.ComStatus) 171 v.UpdateCom(t, data.ComStatus)
  172 + v.UpdateAlarm(t, data.Alarm)
166 } 173 }
167 174
168 // 重置运行时长 175 // 重置运行时长
@@ -197,9 +204,14 @@ func (d *DeviceRunningRecordInfo) HourDeviceStatusDetail(endTime int) map[string @@ -197,9 +204,14 @@ func (d *DeviceRunningRecordInfo) HourDeviceStatusDetail(endTime int) map[string
197 err := make([][]int, 0) 204 err := make([][]int, 0)
198 var begin, end int = 0, 0 205 var begin, end int = 0, 0
199 /* 206 /*
200 - 1.故障: 1 0 \ 0 0 207 + 旧: 1.故障: 1 0 \ 0 0
201 2.正常: 1 1 208 2.正常: 1 1
202 3.停机:0 1 209 3.停机:0 1
  210 +
  211 + 新: 只要未开机,就是待机中状态
  212 + 1.故障: 1 0 0 / 1 0 1 / 1 1 1 / 1/5/7
  213 + 2.正常: 1 1 0 3
  214 + 3.停机:0 0 0 / 0 1 0 / 0 0 1 / 0 1 1 0/2/4/6
203 */ 215 */
204 var status = 1 216 var status = 1
205 // 添加数据 217 // 添加数据
@@ -225,13 +237,13 @@ func (d *DeviceRunningRecordInfo) HourDeviceStatusDetail(endTime int) map[string @@ -225,13 +237,13 @@ func (d *DeviceRunningRecordInfo) HourDeviceStatusDetail(endTime int) map[string
225 if com&index > 0 { 237 if com&index > 0 {
226 val |= 2 238 val |= 2
227 } 239 }
228 - if val == 1 { 240 + if val == 1 || val == 5 || val == 7 {
229 return 1 //故障 241 return 1 //故障
230 } 242 }
231 if val == 3 { 243 if val == 3 {
232 return 2 //正常 244 return 2 //正常
233 } 245 }
234 - if val == 2 || val == 0 { 246 + if val == 0 || val == 2 || val == 4 || val == 6 {
235 return 3 //停机 247 return 3 //停机
236 } 248 }
237 return 3 // 停机 249 return 3 // 停机
@@ -292,6 +304,8 @@ type HourDeviceStatus struct { @@ -292,6 +304,8 @@ type HourDeviceStatus struct {
292 Up int `json:"up"` 304 Up int `json:"up"`
293 // 通讯 305 // 通讯
294 Com int `json:"com"` 306 Com int `json:"com"`
  307 + // 报警
  308 + Alarm int `json:"alarm"`
295 } 309 }
296 310
297 // 更新启动状态 311 // 更新启动状态
@@ -322,6 +336,20 @@ func (d *HourDeviceStatus) UpdateCom(t time.Time, c int) { @@ -322,6 +336,20 @@ func (d *HourDeviceStatus) UpdateCom(t time.Time, c int) {
322 return 336 return
323 } 337 }
324 338
  339 +// 更新报警状态
  340 +func (d *HourDeviceStatus) UpdateAlarm(t time.Time, c int) {
  341 + m := t.Minute()
  342 + bit := 1 << (m / d.Window)
  343 + if c&1 == 0 {
  344 + return
  345 + }
  346 + if d.Alarm&bit > 0 {
  347 + return
  348 + }
  349 + d.Alarm |= bit
  350 + return
  351 +}
  352 +
325 // 计算状态持续的时间 353 // 计算状态持续的时间
326 func (d *HourDeviceStatus) CountTime(v int) time.Duration { 354 func (d *HourDeviceStatus) CountTime(v int) time.Duration {
327 l := 60 / d.Window 355 l := 60 / d.Window
@@ -344,5 +372,6 @@ func NewHourDeviceStatus() *HourDeviceStatus { @@ -344,5 +372,6 @@ func NewHourDeviceStatus() *HourDeviceStatus {
344 Window: DefaultTimeWindow, 372 Window: DefaultTimeWindow,
345 Up: 0, 373 Up: 0,
346 Com: 0, 374 Com: 0,
  375 + Alarm: 0,
347 } 376 }
348 } 377 }
@@ -25,6 +25,8 @@ type DeviceRunningData struct { @@ -25,6 +25,8 @@ type DeviceRunningData struct {
25 StartupStatus int `json:"startupStatus"` 25 StartupStatus int `json:"startupStatus"`
26 // 通讯状态:1:通讯正常,0:设备未上电或与采集端通讯故障 26 // 通讯状态:1:通讯正常,0:设备未上电或与采集端通讯故障
27 ComStatus int `json:"comStatus"` 27 ComStatus int `json:"comStatus"`
  28 + // 报警状态:1:故障,0:正常
  29 + Alarm int `json:"alarm"`
28 30
29 // 附加数据 31 // 附加数据
30 // 匹配数目 32 // 匹配数目
@@ -12,4 +12,6 @@ type ProductPlanExt struct { @@ -12,4 +12,6 @@ type ProductPlanExt struct {
12 //ProductSpec *UnitQuantity `json:"productSpec,omitempty"` 12 //ProductSpec *UnitQuantity `json:"productSpec,omitempty"`
13 // 投入量规格 默认份 13 // 投入量规格 默认份
14 DevotedUnit string `json:"devotedUnit" ` 14 DevotedUnit string `json:"devotedUnit" `
  15 + // ERP系统里面的 bill_no
  16 + ErpBillNo string `json:"erpBillNo" `
15 } 17 }
@@ -164,7 +164,7 @@ from ts_product_list @@ -164,7 +164,7 @@ from ts_product_list
164 func (dao *DeviceDailyRunningRecordDao) DeviceRunningInfo(companyId, orgId int, deviceCode string, result interface{}) error { 164 func (dao *DeviceDailyRunningRecordDao) DeviceRunningInfo(companyId, orgId int, deviceCode string, result interface{}) error {
165 tx := dao.transactionContext.PgTx 165 tx := dao.transactionContext.PgTx
166 sql := fmt.Sprintf(` 166 sql := fmt.Sprintf(`
167 -select * from device_running_info(?,?,?); 167 +select * from manufacture.device_running_info(?,?,?);
168 `) 168 `)
169 if _, err := tx.Query(result, sql, deviceCode, companyId, orgId); err != nil { 169 if _, err := tx.Query(result, sql, deviceCode, companyId, orgId); err != nil {
170 return err 170 return err
@@ -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,19 +110,20 @@ func (ptr *PGWorkshopDataConsumeService) Consume(companyId, orgId int, record *d @@ -110,19 +110,20 @@ func (ptr *PGWorkshopDataConsumeService) Consume(companyId, orgId int, record *d
110 SendProductRecordStaticsJob(productRecord) 110 SendProductRecordStaticsJob(productRecord)
111 } 111 }
112 } 112 }
113 - if err = redis.SaveDeviceDailyRunningRecord(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
117 } 117 }
118 118
  119 +// 设备运行数据
119 func (ptr *PGWorkshopDataConsumeService) newDeviceRunningData(record *domain.DeviceCollection) (*domain.DeviceRunningData, error) { 120 func (ptr *PGWorkshopDataConsumeService) newDeviceRunningData(record *domain.DeviceCollection) (*domain.DeviceRunningData, error) {
120 var err error 121 var err error
121 var unitQuantity float64 = DefaultCCJUnitQuantity // 单位数量 122 var unitQuantity float64 = DefaultCCJUnitQuantity // 单位数量
122 var data = &domain.DeviceRunningData{ 123 var data = &domain.DeviceRunningData{
123 DeviceCollectionId: record.DeviceCollectionId, 124 DeviceCollectionId: record.DeviceCollectionId,
124 WorkShopName: record.WorkShopName, 125 WorkShopName: record.WorkShopName,
125 - CollectionTime: record.CollectionTime, 126 + CollectionTime: record.CollectionTime.Local(),
126 DeviceCode: record.DeviceSn, 127 DeviceCode: record.DeviceSn,
127 DeviceType: record.DeviceType, 128 DeviceType: record.DeviceType,
128 StartupStatus: int(record.StartupStatus), 129 StartupStatus: int(record.StartupStatus),
@@ -160,6 +161,7 @@ func (ptr *PGWorkshopDataConsumeService) newDeviceRunningData(record *domain.Dev @@ -160,6 +161,7 @@ func (ptr *PGWorkshopDataConsumeService) newDeviceRunningData(record *domain.Dev
160 } 161 }
161 data.Temp1 = utils.Truncate(deviceYouZhaJi.FrontTemp, 1) 162 data.Temp1 = utils.Truncate(deviceYouZhaJi.FrontTemp, 1)
162 data.Temp2 = utils.Truncate(deviceYouZhaJi.BackTemp, 1) 163 data.Temp2 = utils.Truncate(deviceYouZhaJi.BackTemp, 1)
  164 + data.Alarm = deviceYouZhaJi.Alarm
163 } else { 165 } else {
164 deviceYouZhaJi := &domain.DeviceYouZhaJi2{} 166 deviceYouZhaJi := &domain.DeviceYouZhaJi2{}
165 err = json.Unmarshal(mBytes, deviceYouZhaJi) 167 err = json.Unmarshal(mBytes, deviceYouZhaJi)
@@ -168,6 +170,7 @@ func (ptr *PGWorkshopDataConsumeService) newDeviceRunningData(record *domain.Dev @@ -168,6 +170,7 @@ func (ptr *PGWorkshopDataConsumeService) newDeviceRunningData(record *domain.Dev
168 } 170 }
169 data.Temp1 = utils.Truncate(deviceYouZhaJi.Temp1, 1) 171 data.Temp1 = utils.Truncate(deviceYouZhaJi.Temp1, 1)
170 data.Temp2 = utils.Truncate(deviceYouZhaJi.Temp2, 1) 172 data.Temp2 = utils.Truncate(deviceYouZhaJi.Temp2, 1)
  173 + data.Alarm = deviceYouZhaJi.Alarm
171 } 174 }
172 break 175 break
173 //串串机 176 //串串机
@@ -193,6 +196,7 @@ func (ptr *PGWorkshopDataConsumeService) newDeviceRunningData(record *domain.Dev @@ -193,6 +196,7 @@ func (ptr *PGWorkshopDataConsumeService) newDeviceRunningData(record *domain.Dev
193 break 196 break
194 } 197 }
195 data.Temp1 = utils.Truncate(deviceSuDongXian.CurrTemp, 1) 198 data.Temp1 = utils.Truncate(deviceSuDongXian.CurrTemp, 1)
  199 + data.Alarm = deviceSuDongXian.Alarm
196 break 200 break
197 //封口机 201 //封口机
198 case domain.DeviceTypeFengKouJi: 202 case domain.DeviceTypeFengKouJi:
@@ -231,6 +235,7 @@ func (ptr *PGWorkshopDataConsumeService) newDeviceRunningData(record *domain.Dev @@ -231,6 +235,7 @@ func (ptr *PGWorkshopDataConsumeService) newDeviceRunningData(record *domain.Dev
231 return data, nil 235 return data, nil
232 } 236 }
233 237
  238 +// 设备运行记录
234 func (ptr *PGWorkshopDataConsumeService) newDeviceRunningRecord(companyId, orgId int, workStation *domain.WorkStation, device *domain.Device, data *domain.DeviceRunningData) (*domain.DeviceRunningRecord, error) { 239 func (ptr *PGWorkshopDataConsumeService) newDeviceRunningRecord(companyId, orgId int, workStation *domain.WorkStation, device *domain.Device, data *domain.DeviceRunningData) (*domain.DeviceRunningRecord, error) {
235 return &domain.DeviceRunningRecord{ 240 return &domain.DeviceRunningRecord{
236 CompanyId: companyId, 241 CompanyId: companyId,
@@ -239,10 +244,11 @@ func (ptr *PGWorkshopDataConsumeService) newDeviceRunningRecord(companyId, orgId @@ -239,10 +244,11 @@ func (ptr *PGWorkshopDataConsumeService) newDeviceRunningRecord(companyId, orgId
239 DeviceId: device.DeviceId, 244 DeviceId: device.DeviceId,
240 DeviceCode: device.DeviceCode, 245 DeviceCode: device.DeviceCode,
241 DeviceRunningRecordInfo: data, 246 DeviceRunningRecordInfo: data,
242 - CreatedAt: data.CollectionTime, 247 + CreatedAt: data.CollectionTime.Local(),
243 }, nil 248 }, nil
244 } 249 }
245 250
  251 +// 生产记录
246 func (ptr *PGWorkshopDataConsumeService) newProductRecord(companyId int, orgId int, workStation *domain.WorkStation, device *domain.Device, data *domain.DeviceRunningData, plan *domain.ProductPlanDispatchRecord) (*domain.ProductRecord, error) { 252 func (ptr *PGWorkshopDataConsumeService) newProductRecord(companyId int, orgId int, workStation *domain.WorkStation, device *domain.Device, data *domain.DeviceRunningData, plan *domain.ProductPlanDispatchRecord) (*domain.ProductRecord, error) {
247 result := &domain.ProductRecord{ 253 result := &domain.ProductRecord{
248 CompanyId: companyId, 254 CompanyId: companyId,
@@ -250,7 +256,7 @@ func (ptr *PGWorkshopDataConsumeService) newProductRecord(companyId int, orgId i @@ -250,7 +256,7 @@ func (ptr *PGWorkshopDataConsumeService) newProductRecord(companyId int, orgId i
250 WorkStation: workStation, 256 WorkStation: workStation,
251 ProductRecordType: domain.RecordTypeWeigh, 257 ProductRecordType: domain.RecordTypeWeigh,
252 ProductWorker: &domain.User{}, 258 ProductWorker: &domain.User{},
253 - CreatedAt: data.CollectionTime, 259 + CreatedAt: data.CollectionTime.Local(),
254 UpdatedAt: time.Now(), 260 UpdatedAt: time.Now(),
255 ProductRecordInfo: &domain.ProductRecordInfo{ 261 ProductRecordInfo: &domain.ProductRecordInfo{
256 ProductDate: data.CollectionTime.Local().Format("2006-01-02"), 262 ProductDate: data.CollectionTime.Local().Format("2006-01-02"),
@@ -279,31 +285,33 @@ func (ptr *PGWorkshopDataConsumeService) saveDeviceDailyRunningRecord(companyId, @@ -279,31 +285,33 @@ func (ptr *PGWorkshopDataConsumeService) saveDeviceDailyRunningRecord(companyId,
279 if record, err = deviceDailyRunningRecordRepository.FindOne(map[string]interface{}{ 285 if record, err = deviceDailyRunningRecordRepository.FindOne(map[string]interface{}{
280 "workStationId": workStation.WorkStationId, 286 "workStationId": workStation.WorkStationId,
281 "deviceCode": data.DeviceCode, 287 "deviceCode": data.DeviceCode,
282 - "productDate": utils.GetZeroTime(data.CollectionTime), 288 + "productDate": utils.GetZeroTime(data.CollectionTime.Local()),
283 }); err != nil { 289 }); err != nil {
284 if err != domain.ErrorNotFound { 290 if err != domain.ErrorNotFound {
285 return nil, err 291 return nil, err
286 } 292 }
287 } 293 }
288 if record != nil { 294 if record != nil {
289 - 295 + record.RedisKey = redis.DeviceDailyRunningRecordKeyByTimeStr(record.DeviceRunningRecordInfo.ProductDate, record.DeviceCode)
290 return record, nil 296 return record, nil
291 } 297 }
292 recordInfo := domain.NewDeviceRunningRecordInfo() 298 recordInfo := domain.NewDeviceRunningRecordInfo()
293 recordInfo.ProductPlanId = planId 299 recordInfo.ProductPlanId = planId
294 recordInfo.DeviceName = device.DeviceName 300 recordInfo.DeviceName = device.DeviceName
295 recordInfo.OrgName = device.Ext.OrgName 301 recordInfo.OrgName = device.Ext.OrgName
  302 + recordInfo.ProductDate = data.CollectionTime.Local().Format("2006-01-02")
296 record = &domain.DeviceDailyRunningRecord{ 303 record = &domain.DeviceDailyRunningRecord{
297 CompanyId: companyId, 304 CompanyId: companyId,
298 OrgId: orgId, 305 OrgId: orgId,
299 WorkStation: workStation, 306 WorkStation: workStation,
300 DeviceId: device.DeviceId, 307 DeviceId: device.DeviceId,
301 DeviceCode: device.DeviceCode, 308 DeviceCode: device.DeviceCode,
302 - ProductDate: utils.GetZeroTime(data.CollectionTime), 309 + ProductDate: utils.GetZeroTime(data.CollectionTime.Local()),
303 DeviceRunningRecordInfo: recordInfo, 310 DeviceRunningRecordInfo: recordInfo,
304 - CreatedAt: data.CollectionTime, 311 + CreatedAt: data.CollectionTime.Local(),
305 UpdatedAt: time.Now(), 312 UpdatedAt: time.Now(),
306 } 313 }
  314 + record.RedisKey = redis.DeviceDailyRunningRecordKeyByTimeStr(record.DeviceRunningRecordInfo.ProductDate, record.DeviceCode)
307 if record, err = deviceDailyRunningRecordRepository.Save(record); err != nil { 315 if record, err = deviceDailyRunningRecordRepository.Save(record); err != nil {
308 return nil, err 316 return nil, err
309 } 317 }
@@ -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 }
@@ -32,16 +34,28 @@ func getDeviceDailyRunningRecord(client *redis.Client, key string) (*domain.Devi @@ -32,16 +34,28 @@ func getDeviceDailyRunningRecord(client *redis.Client, key string) (*domain.Devi
32 } 34 }
33 35
34 // 保存每日设备运行数据 36 // 保存每日设备运行数据
35 -func SaveDeviceDailyRunningRecord(record *domain.DeviceDailyRunningRecord) error { 37 +func SaveDeviceDailyRunningRecord(t time.Time, record *domain.DeviceDailyRunningRecord) error {
36 client := GetRedis() 38 client := GetRedis()
37 - key := DeviceDailyRunningRecordKey(record.ProductDate, record.DeviceCode)  
38 - log.Logger.Debug(fmt.Sprintf("Redis Device:%v SET Key:%v Count:%v", record.DeviceCode, key, record.DeviceRunningRecordInfo.Count)) 39 + key := DeviceDailyRunningRecordKey(t, record.DeviceCode)
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
@@ -151,6 +151,12 @@ func (repository *ProductPlanRepository) FindOne(queryOptions map[string]interfa @@ -151,6 +151,12 @@ func (repository *ProductPlanRepository) FindOne(queryOptions map[string]interfa
151 query.SetWhereByQueryOption("company_id = ?", "companyId") 151 query.SetWhereByQueryOption("company_id = ?", "companyId")
152 query.SetWhereByQueryOption("org_id = ?", "orgId") 152 query.SetWhereByQueryOption("org_id = ?", "orgId")
153 query.SetWhereByQueryOption("batch_number=?", "batchNumber") 153 query.SetWhereByQueryOption("batch_number=?", "batchNumber")
  154 + if v, ok := queryOptions["erpBillNo"]; ok && len(v.(string)) > 0 {
  155 + query.Where(fmt.Sprintf(`ext#>'{productPlanExt,erpBillNo}' = '"%v"'`, v))
  156 + }
  157 + if v, ok := queryOptions["productCode"]; ok && len(v.(string)) > 0 {
  158 + query.Where(fmt.Sprintf(`ext#>'{productPlanExt,productCode}' = '"%v"'`, v))
  159 + }
154 if v, ok := queryOptions["includeDeleted"]; ok && v.(bool) { 160 if v, ok := queryOptions["includeDeleted"]; ok && v.(bool) {
155 query.AllWithDeleted() 161 query.AllWithDeleted()
156 } 162 }
@@ -181,6 +187,12 @@ func (repository *ProductPlanRepository) Find(queryOptions map[string]interface{ @@ -181,6 +187,12 @@ func (repository *ProductPlanRepository) Find(queryOptions map[string]interface{
181 if v, ok := queryOptions["workshopName"]; ok && len(v.(string)) > 0 { 187 if v, ok := queryOptions["workshopName"]; ok && len(v.(string)) > 0 {
182 query.Where(fmt.Sprintf(`workshop->>'workshopName' like '%%%v%%'`, v)) 188 query.Where(fmt.Sprintf(`workshop->>'workshopName' like '%%%v%%'`, v))
183 } 189 }
  190 + if v, ok := queryOptions["erpBillNo"]; ok && len(v.(string)) > 0 {
  191 + query.Where(fmt.Sprintf(`ext#>'{productPlanExt,erpBillNo}' = '"%v"'`, v))
  192 + }
  193 + if v, ok := queryOptions["productCode"]; ok && len(v.(string)) > 0 {
  194 + query.Where(fmt.Sprintf(`ext#>'{productPlanExt,productCode}' = '"%v"'`, v))
  195 + }
184 query.SetWhereByQueryOption("plan_status=?", "planStatus") 196 query.SetWhereByQueryOption("plan_status=?", "planStatus")
185 query.SetOffsetAndLimit(domain.MaxQueryRow) 197 query.SetOffsetAndLimit(domain.MaxQueryRow)
186 query.SetOrderDirect("product_plan_id", "DESC") 198 query.SetOrderDirect("product_plan_id", "DESC")
  1 +package utils
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/linmadan/egglib-go/utils/json"
  6 + "testing"
  7 + "time"
  8 +)
  9 +
  10 +type User struct {
  11 + Age time.Time
  12 + AgeZero time.Time
  13 + AgeZeroFormat string
  14 +}
  15 +
  16 +func TestTimeParseInLocal(t *testing.T) {
  17 + timeStr := "2022-01-02 1:00:00"
  18 + tl, _ := time.ParseInLocation("2006-01-02 15:04:05", timeStr, time.Local)
  19 + u1 := User{
  20 + Age: tl,
  21 + AgeZero: GetZeroTime(tl),
  22 + }
  23 + u1.AgeZeroFormat = u1.AgeZero.Format("2006-01-02")
  24 +
  25 + fmt.Println(json.MarshalToString(u1), u1.Age.Local())
  26 + timeMarsh(&u1)
  27 +}
  28 +
  29 +func timeMarsh(u *User) {
  30 + var u2 = &User{}
  31 + u1Data, _ := json.Marshal(u)
  32 + json.Unmarshal(u1Data, u2)
  33 +
  34 + fmt.Println("时间:", u2.Age, u2.Age.Local(), u2.AgeZero)
  35 +}
@@ -55,7 +55,7 @@ func TestComputeTimeDuration(t *testing.T) { @@ -55,7 +55,7 @@ func TestComputeTimeDuration(t *testing.T) {
55 } 55 }
56 } 56 }
57 57
58 -const TIME_LAYOUT = "2006-01-02 03:04:05" 58 +const TIME_LAYOUT = "2006-01-02 15:04:05"
59 59
60 func TestTimeParse(t *testing.T) { 60 func TestTimeParse(t *testing.T) {
61 fmt.Println(int(-1)) 61 fmt.Println(int(-1))
@@ -64,11 +64,13 @@ func TestTimeParse(t *testing.T) { @@ -64,11 +64,13 @@ func TestTimeParse(t *testing.T) {
64 64
65 func timeParse() { 65 func timeParse() {
66 fmt.Println("0. now: ", time.Now()) 66 fmt.Println("0. now: ", time.Now())
67 - str := "2018-09-10 10:00:00" 67 + str := "2018-09-10 16:00:00"
68 fmt.Println("1. str: ", str) 68 fmt.Println("1. str: ", str)
69 - t, _ := time.Parse(TIME_LAYOUT, str)  
70 - fmt.Println("2. Parse time: ", t) 69 + t, err := time.Parse(TIME_LAYOUT, str)
  70 + fmt.Println("2. Parse time: ", t, err)
71 fmt.Println("2.1. Parse time: ", t.Local(), t.Local().Local()) 71 fmt.Println("2.1. Parse time: ", t.Local(), t.Local().Local())
  72 + parseInLocal, _ := time.ParseInLocation(TIME_LAYOUT, str, time.Local)
  73 + fmt.Println("2.2 parse in local", parseInLocal, parseInLocal.Local())
72 tStr := t.Format(TIME_LAYOUT) 74 tStr := t.Format(TIME_LAYOUT)
73 fmt.Println("3. Format time str: ", tStr) 75 fmt.Println("3. Format time str: ", tStr)
74 name, offset := t.Zone() 76 name, offset := t.Zone()
@@ -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)