123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- package provincial_department
- import (
- "context"
- "encoding/json"
- "github.com/tidwall/gjson"
- "go.uber.org/zap"
- "smart-provincial/errors"
- "smart-provincial/pb/v1"
- "smart-provincial/thirdparty"
- "strings"
- "smart-provincial/parser"
- "github.com/jaryhe/gopkgs/logger"
- )
- func ProvincialPostDustDevice(ctx context.Context, req *v1.ProvincialPostDustDeviceRequest)(reply *v1.ProvincialPostDustDeviceReply, err error) {
- return &v1.ProvincialPostDustDeviceReply{}, nil
- token, err := Login()
- if err != nil {
- return nil, err
- }
- param := map[string]interface{}{
- "Code":req.Code,
- "Name":req.Name,
- "DeviceName":req.DeviceName,
- "DeviceID":req.DeviceId,
- "Manufacturer":req.Manufacturer,
- "Batch":req.Batch,
- "Unit":req.Unit,
- "DeviceModel":req.DeviceModel,
- }
- bytes, err := thirdparty.ProvincialPost(parser.Conf.ThirdParty.Provincial.DustDeviceUploadApi, token, param)
- if err != nil {
- s, _ := json.Marshal(param)
- logger.Error("thirdpary",
- zap.String("call", parser.Conf.ThirdParty.Provincial.DustDeviceUploadApi),
- zap.String("param", string(s)),
- zap.String("error", err.Error()))
- return nil, errors.ProvincialDustDeviceUploadError
- }
- ack := gjson.GetBytes(bytes, "ack_code").String()
- if strings.ToUpper(ack) != "SUCCESS" {
- s, _ := json.Marshal(param)
- logger.Error("thirdpary",
- zap.String("call", parser.Conf.ThirdParty.Provincial.DustDeviceUploadApi),
- zap.String("param", string(s)),
- zap.String("error",string(bytes)))
- return nil, errors.ProvincialDustDeviceUploadError
- }
- id := gjson.GetBytes(bytes, "ID").String()
- reply.Id = id
- reply = &v1.ProvincialPostDustDeviceReply{}
- return reply, nil
- }
|