12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- package provincial_department
- import (
- "context"
- "fmt"
- "github.com/tidwall/gjson"
- "go.uber.org/zap"
- "smart-provincial/errors"
- "smart-provincial/pb/v1"
- "smart-provincial/thirdparty"
- "strconv"
- "strings"
- "smart-provincial/parser"
- "github.com/jaryhe/gopkgs/logger"
- )
- func ProvincialGetProjectCode(ctx context.Context, req *v1.ProvincialGetProjectCodeRequest)(reply *v1.ProvincialGetProjectCodeReply, err error) {
- token, err := Login()
- if err != nil {
- return nil, err
- }
- areaCode, _ := strconv.Atoi(req.AreaCode)
- data := map[string]interface{}{
- "Name":req.Name,
- "Category":req.Category,
- "AreaCode":areaCode,
- }
- bytes, err := thirdparty.ProvincialPost(parser.Conf.ThirdParty.Provincial.ProjectCodeApi, token, data)
- fmt.Printf("provincial get project code: %s,%v\n", bytes, err)
- if err != nil {
- logger.Error("thirdpary get project code",
- zap.String("call", parser.Conf.ThirdParty.Provincial.ProjectCodeApi),
- zap.String("error", err.Error()))
- return nil, errors.ProvincialProjectCodeError
- }
- ack := gjson.GetBytes(bytes, "ack_code").String()
- if strings.ToUpper(ack) != "SUCCESS" {
- logger.Error("thirdpary get project code",
- zap.String("call", parser.Conf.ThirdParty.Provincial.ProjectCodeApi),
- zap.String("error",string(bytes)))
- return nil, errors.ProvincialProjectCodeError
- }
- projectCode := gjson.GetBytes(bytes, "Code").String()
- if projectCode == "" {
- logger.Error("thirdpary get project code",
- zap.String("call", parser.Conf.ThirdParty.Provincial.ProjectCodeApi),
- zap.String("error",string(bytes)))
- return nil, errors.ProvincialProjectCodeError
- }
- reply = &v1.ProvincialGetProjectCodeReply{
- Code:projectCode,
- }
- return reply, nil
- }
|