123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- package tower
- import (
- "context"
- "fmt"
- "github.com/jaryhe/gopkgs/database"
- "github.com/jaryhe/gopkgs/logger"
- "go.uber.org/zap"
- "smart-government-management/errors"
- "smart-government-management/model"
- "smart-government-management/pb/v1"
- )
- type TowerInfo struct {
- Time string `json:"time"`
- // 回转角度值
- BackTurn float64 `json:"back_turn"`
- // 幅度值
- Scope float64 `json:"scope"`
- // 吊钩离地面的距离
- Hight float64 `json:"hight"`
- // 吊钩所掉重物的重量
- Weight float64 `json:"weight"`
- // 当前力矩所占最大力矩的百分比
- Moment int `json:"moment"`
- // 电池电量
- Battery int `json:"battery"`
- // 风速
- WindSpeed float64 `json:"wind_speed"`
- // 塔身倾斜度 X 向
- AngleX float64 `json:"angle_x"`
- // 塔身倾斜度 Y 向
- AngleY float64 `json:"angle_y"`
- }
- type TowerInfoMean struct {
- Time string `json:"time"`
- // 回转角度值
- BackTurn float64 `json:"mean_back_turn"`
- // 幅度值
- Scope float64 `json:"mean_scope"`
- // 吊钩离地面的距离
- Hight float64 `json:"mean_hight"`
- // 吊钩所掉重物的重量
- Weight float64 `json:"mean_weight"`
- // 当前力矩所占最大力矩的百分比
- Moment int `json:"mean_moment"`
- // 电池电量
- Battery int `json:"mean_battery"`
- // 风速
- WindSpeed float64 `json:"mean_wind_speed"`
- // 塔身倾斜度 X 向
- AngleX float64 `json:"mean_angle_x"`
- // 塔身倾斜度 Y 向
- AngleY float64 `json:"mean_angle_y"`
- }
- func getTowerDbName(dtype int32) string {
- return "tower_monitor_2"
- }
- func LatestTowerMonitorData(ctx context.Context, req *v1.LatestTowerMonitorDataRequest)(reply *v1.LatestTowerMonitorDataReply, err error) {
- if req.Sn == "" {
- // 获取一个扬尘设备
- p := model.TDevice{}
- where := map[string]interface{}{
- "device_code":model.DeviceTypeTower,
- "verify_status":1,
- "status":1,
- }
- err = p.Find(database.DB(), where)
- if err != nil {
- return nil, errors.DataBaseError
- }
- if p.Id == 0 {
- return &v1.LatestTowerMonitorDataReply{Data:&v1.TowerMonitorData{}}, nil
- }
- req.Sn = p.Sn
- }
- dbname := getTowerDbName(req.Type)
- array := []TowerInfo{}
- sql := fmt.Sprintf("select * from \"%s\" order by time desc limit 1 tz('Asia/Shanghai')", req.Sn)
- _, err = model.QueryInfluxdb(sql, dbname, &array)
- if err != nil {
- logger.Error("LatestDustMonitorData",
- zap.String("err", err.Error()))
- return nil, errors.DataBaseError
- }
- reply = &v1.LatestTowerMonitorDataReply{}
- if len(array) == 0 {
- return &v1.LatestTowerMonitorDataReply{Data:&v1.TowerMonitorData{}}, nil
- }
- reply.Data = &v1.TowerMonitorData{}
- reply.Data.Date = array[0].Time
- reply.Data.AngleY = array[0].AngleY
- reply.Data.AngleX = array[0].AngleX
- reply.Data.WindSpeed = array[0].WindSpeed
- reply.Data.Battery = fmt.Sprintf("%d", array[0].Battery)+"%"
- reply.Data.Weight = array[0].Weight
- reply.Data.Hight = array[0].Hight
- reply.Data.Scope = array[0].Scope
- reply.Data.BackTurn = array[0].BackTurn
- reply.Data.Moment = fmt.Sprintf("%d", array[0].Moment)+"%"
- return reply, nil
- }
|