Skip to content

Commit

Permalink
fix:修复设备详情中数据状态显示Bug
Browse files Browse the repository at this point in the history
  • Loading branch information
microrain authored and microrain committed Mar 4, 2024
1 parent 75356d4 commit 38b6fde
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
6 changes: 3 additions & 3 deletions internal/logic/product/dev_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -834,8 +834,8 @@ func (s *sDevDevice) RunStatus(ctx context.Context, deviceKey string) (out *mode
out = new(model.DeviceRunStatusOutput)
out.Status = dcache.GetDeviceStatus(ctx, deviceKey)

//获取数据示例
deviceValueList := dcache.GetDeviceDetailData(context.Background(), deviceKey)
//获取数据
deviceValueList := dcache.GetDeviceDetailData(context.Background(), deviceKey, consts.MsgTypePropertyReport, consts.MsgTypeGatewayBatch)
if len(deviceValueList) == 0 {
return
}
Expand Down Expand Up @@ -973,7 +973,7 @@ func (s *sDevDevice) GetProperty(ctx context.Context, in *model.DeviceGetPropert

// GetPropertyList 设备属性详情列表
func (s *sDevDevice) GetPropertyList(ctx context.Context, in *model.DeviceGetPropertyListInput) (out *model.DeviceGetPropertyListOutput, err error) {
resultList, total, currentPage := dcache.GetDeviceDetailDataByPage(ctx, in.DeviceKey, in.PageNum, in.PageSize)
resultList, total, currentPage := dcache.GetDeviceDetailDataByPage(ctx, in.DeviceKey, in.PageNum, in.PageSize, consts.MsgTypePropertyReport, consts.MsgTypeGatewayBatch)
if err != nil {
return
}
Expand Down
39 changes: 30 additions & 9 deletions pkg/dcache/device_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ func InertDeviceLog(ctx context.Context, logType, deviceKey string, obj interfac
}

// GetDeviceDetailData 获取设备解析后的详细数据
func GetDeviceDetailData(ctx context.Context, deviceKey string) (res []map[string]iotModel.ReportPropertyNode) {
func GetDeviceDetailData(ctx context.Context, deviceKey string, dataType ...string) (res []map[string]iotModel.ReportPropertyNode) {
// 从设备缓存数据库获取数据
dataList, err := DB().GetData(context.Background(), deviceKey)
dataList, err := DB().GetData(ctx, deviceKey)
if err != nil {
g.Log().Debugf(ctx, "Failed to get data: %v", err)
return
Expand All @@ -45,13 +45,23 @@ func GetDeviceDetailData(ctx context.Context, deviceKey string) (res []map[strin
if err := json.Unmarshal([]byte(data), &value); err != nil {
g.Log().Debugf(ctx, "Failed to unmarshal data: %v", err)
}

// 基于物模型解析数据
tmp, err := service.DevTSLParse().ParseData(ctx, deviceKey, []byte(value.Content))
dataContent, err := service.DevTSLParse().ParseData(ctx, deviceKey, []byte(value.Content))
if err != nil {
return
continue
}
if len(dataContent) == 0 {
continue
}
if len(dataType) > 0 {
for _, vt := range dataType {
if vt == value.Type {
res = append(res, dataContent)
}
}
} else {
res = append(res, dataContent)
}
res = append(res, tmp)
}
return
}
Expand Down Expand Up @@ -80,7 +90,7 @@ func GetDeviceDetailDataByLatest(ctx context.Context, deviceKey string) (res iot
}

// GetDeviceDetailDataByPage 按分页获取设备详细数据,分页参数: pageNum 为页码, pageSize 为每页数量
func GetDeviceDetailDataByPage(ctx context.Context, deviceKey string, pageNum, pageSize int) (res []map[string]iotModel.ReportPropertyNode, total, currentPage int) {
func GetDeviceDetailDataByPage(ctx context.Context, deviceKey string, pageNum, pageSize int, dataType ...string) (res []map[string]iotModel.ReportPropertyNode, total, currentPage int) {
// 获取 list 的名称
listName := DeviceDataCachePrefix + deviceKey

Expand Down Expand Up @@ -123,11 +133,22 @@ func GetDeviceDetailDataByPage(ctx context.Context, deviceKey string, pageNum, p
}

// 基于物模型解析数据
tmp, err := service.DevTSLParse().ParseData(ctx, deviceKey, []byte(value.Content))
dataContent, err := service.DevTSLParse().ParseData(ctx, deviceKey, []byte(value.Content))
if err != nil {
return
}
res = append(res, tmp)
if len(dataContent) == 0 {
continue
}
if len(dataType) > 0 {
for _, vt := range dataType {
if vt == value.Type {
res = append(res, dataContent)
}
}
} else {
res = append(res, dataContent)
}
}
return
}

0 comments on commit 38b6fde

Please sign in to comment.