team_add.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package provincial_department
  2. import (
  3. "context"
  4. "encoding/json"
  5. "fmt"
  6. "github.com/tidwall/gjson"
  7. "go.uber.org/zap"
  8. "smart-provincial/errors"
  9. "smart-provincial/pb/v1"
  10. "smart-provincial/thirdparty"
  11. "strings"
  12. "smart-provincial/parser"
  13. "github.com/jaryhe/gopkgs/logger"
  14. )
  15. func ProvincialPostTeam(ctx context.Context, req *v1.ProvincialPostTeamRequest)(reply *v1.ProvincialPostTeamReply, err error) {
  16. token, err := Login()
  17. if err != nil {
  18. return nil, err
  19. }
  20. data := map[string]interface{}{
  21. "Code":req.Code,
  22. "TeamSysNo":req.TeamSysNo,
  23. "TeamName":req.TeamName,
  24. "CorpCode":req.CorpCode,
  25. "CorpName":req.CorpName,
  26. "TeamLeaderName":req.TeamLeaderName,
  27. "TeamLeaderPhone":req.TeamLeaderPhone,
  28. }
  29. datas := []map[string]interface{}{}
  30. datas = append(datas, data)
  31. param := map[string]interface{}{
  32. "type":"项目班组信息",
  33. "datas":datas,
  34. }
  35. bytes, err := thirdparty.ProvincialPost(parser.Conf.ThirdParty.Provincial.ProjectUploadApi, token, param)
  36. fmt.Printf("provincial add team %s,%v\n", bytes, err)
  37. if err != nil {
  38. s, _ := json.Marshal(param)
  39. logger.Error("thirdpary provincial add team",
  40. zap.String("call", parser.Conf.ThirdParty.Provincial.ProjectUploadApi),
  41. zap.String("param", string(s)),
  42. zap.String("error", err.Error()))
  43. return nil, errors.ProvincialProjectUploadError
  44. }
  45. ack := gjson.GetBytes(bytes, "ack_code").String()
  46. if strings.ToUpper(ack) != "SUCCESS" {
  47. s, _ := json.Marshal(param)
  48. logger.Error("thirdpary provincial add team",
  49. zap.String("call", parser.Conf.ThirdParty.Provincial.ProjectUploadApi),
  50. zap.String("param", string(s)),
  51. zap.String("error",string(bytes)))
  52. return nil, errors.ProvincialProjectUploadError
  53. }
  54. id := gjson.GetBytes(bytes, "ID").String()
  55. reply.Id = id
  56. reply = &v1.ProvincialPostTeamReply{}
  57. return reply, nil
  58. }