1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- // Copyright 2019 github.com. All rights reserved.
- // Use of this source code is governed by github.com.
- package util
- import (
- "context"
- "dust-monitor/consts"
- "dust-monitor/errors"
- "dust-monitor/model"
- "dust-monitor/pb"
- pb_v1 "dust-monitor/pb/v1"
- "github.com/jaryhe/gopkgs/database"
- "github.com/jinzhu/gorm"
- "github.com/jaryhe/gopkgs/logger"
- "go.uber.org/zap"
- )
- /*
- var snKey map[string]*pb_v1.DeviceInfoReply
- // 初始化map
- func Init() {
- snKey = make(map[string]*pb_v1.DeviceInfoReply)
- }
- */
- // 获取key
- func GetKey(sn string) (*pb_v1.DeviceInfoReply, error) {
- reply, err := GetDeviceInfo(sn)
-
- return reply, err
- }
- // 从数据库中获取key
- func GetDeviceInfo(sn string) (*pb_v1.DeviceInfoReply, error) {
- req := &pb_v1.DeviceInfoRequest{Sn: sn, DeviceCode: consts.DustDeviceCode}
- reply, err := pb.SmartAuth.DeviceInfo(context.Background(), req)
- if err != nil {
- logger.Error("func",
- zap.String("call", "pb.SmartAuth.DeviceInfo"),
- zap.String("args", sn),
- zap.String("error", err.Error()))
- }
- return reply, err
- }
- func GetDustInfoByEcode(ecode string, sn string) (*model.DustExcessiveInfo, error) {
- p := &model.DustExcessiveInfo{}
- where := map[string]interface{}{
- "SN":sn,
- "ECode":ecode,
- }
- err := p.Find(database.DB(), where, nil)
- if err != nil && err != gorm.ErrRecordNotFound {
- return nil, errors.DataBaseError
- }
- if p.ID == 0 {
- return nil, errors.NoRecordError
- }
- return p, nil
- }
- func InsertDustExcessiveImg(p *model.DustExcessiveImg) error {
- err := p.Insert(database.DB())
- if err != nil {
- return errors.DataBaseError
- }
- return nil
- }
- // 获取国控值
- func GetDustStandard(province string, region string) (*pb_v1.WeatherEnviromentReply, error){
- req := &pb_v1.WeatherEnviromentRequest{
- Province:province,
- Region:region,
- }
- reply, err := pb.SmartThirdparty.WeatherEnviroment(context.Background(), req)
- if err != nil {
- logger.Error("func",
- zap.String("call", "pb.SmartThirdparty.WeatherEnviroment"),
- zap.String("args", region),
- zap.String("error", err.Error()))
- }
- return reply, err
- }
- func GetDustSns()(*pb_v1.GetAllDustSnReply, error) {
- req := &pb_v1.GetAllDustSnRequest{}
- reply, err := pb.SmartAuth.GetAllDustSn(context.Background(), req)
- if err != nil {
- logger.Error("func",
- zap.String("call", "pb.SmartAuth.GetAllDustSn"),
- zap.String("error", err.Error()))
- }
- return reply, err
- }
|