12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- package tower
- import (
- "context"
- "fmt"
- "smart-site-management/errors"
- "smart-site-management/model"
- v1 "smart-site-management/pb/v1"
- )
- func getTowerLast(sn string, projectId int64) (reply *v1.IotLastReply, err error) {
- treq := &v1.LatestTowerMonitorDataRequest{
- Sn:sn,
- ProjectId:projectId,
- }
- treply, err := LatestTowerMonitorData(context.Background(), treq)
- if err != nil {
- return nil, err
- }
- reply = &v1.IotLastReply{}
- item := &v1.IotDataItem{}
- item.Name = "回转"
- item.Value = fmt.Sprintf("%.1f", treply.Data.BackTurn)
- item.Unit = "°"
- reply.List = append(reply.List, item)
- item = &v1.IotDataItem{}
- item.Name = "幅度"
- item.Value = fmt.Sprintf("%.1f", treply.Data.Scope)
- item.Unit = "m"
- reply.List = append(reply.List, item)
- item = &v1.IotDataItem{}
- item.Name = "高度"
- item.Value = fmt.Sprintf("%.1f", treply.Data.Hight)
- item.Unit = "m"
- reply.List = append(reply.List, item)
- item = &v1.IotDataItem{}
- item.Name = "称重"
- item.Value = fmt.Sprintf("%.2f", treply.Data.Weight)
- item.Unit = "t"
- reply.List = append(reply.List, item)
- item = &v1.IotDataItem{}
- item.Name = "力矩"
- item.Value = fmt.Sprintf("%v", treply.Data.Moment)
- item.Unit = ""
- reply.List = append(reply.List, item)
- item = &v1.IotDataItem{}
- item.Name = "电池电量"
- item.Value = fmt.Sprintf("%v", treply.Data.Battery)
- item.Unit = ""
- reply.List = append(reply.List, item)
- item = &v1.IotDataItem{}
- item.Name = "风速"
- item.Value = fmt.Sprintf("%.1f", treply.Data.WindSpeed)
- item.Unit = "m/s"
- reply.List = append(reply.List, item)
- item = &v1.IotDataItem{}
- item.Name = "塔身倾角X"
- item.Value = fmt.Sprintf("%.1f", treply.Data.AngleX)
- item.Unit = "°"
- reply.List = append(reply.List, item)
- item = &v1.IotDataItem{}
- item.Name = "塔身倾角Y"
- item.Value = fmt.Sprintf("%.1f", treply.Data.AngleY)
- item.Unit = "°"
- reply.List = append(reply.List, item)
- return reply, nil
- }
- func IotLast(ctx context.Context, req *v1.IotLastRequest) (reply *v1.IotLastReply, err error) {
- if req.ProjectId < 1 || req.Sn == "" || req.DeviceCode < 1{
- return nil, errors.ParamsError
- }
- switch req.DeviceCode {
- case model.DeviceTypeTower:
- return getTowerLast(req.Sn, req.ProjectId)
- }
- return &v1.IotLastReply{}, nil
- }
|