project_add.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 ProvincialPostProject(ctx context.Context, req *v1.ProvincialPostProjectRequest)(reply *v1.ProvincialPostProjectReply, err error) {
  16. token, err := Login()
  17. if err != nil {
  18. return nil, err
  19. }
  20. data := map[string]interface{}{
  21. "Code":req.ProjectCode,
  22. "Name":req.ProjectName,
  23. "Category":req.ProjectCategory,
  24. //"OwnerName":req.OwnerName,
  25. "ConstructType":req.ConstructType,
  26. "InvestType":req.InvestType,
  27. //"BuildCorporationCode":req.BuildCorporationCode,
  28. "BuildingArea":req.BuildingArea,
  29. "AreaCode":req.AreaCode,
  30. "Address":req.Address,
  31. "Invest":req.Invest,
  32. "Scale":req.Scale,
  33. //"PrjSize":req.PrjSize,
  34. "StartDate":req.StartDate,
  35. //"CompleteDate":req.CompleteDate,
  36. //"PrjStatus":req.PrjStatus,
  37. }
  38. datas := []map[string]interface{}{}
  39. datas = append(datas, data)
  40. param := map[string]interface{}{
  41. "type":"项目基本信息",
  42. "datas":datas,
  43. }
  44. bytes, err := thirdparty.ProvincialPost(parser.Conf.ThirdParty.Provincial.ProjectUploadApi, token, param)
  45. fmt.Printf("provincial project add: %s,%v\n", bytes, err)
  46. if err != nil {
  47. s, _ := json.Marshal(param)
  48. logger.Error("thirdpary provincial project add",
  49. zap.String("call", parser.Conf.ThirdParty.Provincial.ProjectUploadApi),
  50. zap.String("param", string(s)),
  51. zap.String("error", err.Error()))
  52. return nil, errors.ProvincialProjectUploadError
  53. }
  54. ack := gjson.GetBytes(bytes, "ack_code").String()
  55. if strings.ToUpper(ack) != "SUCCESS" {
  56. s, _ := json.Marshal(param)
  57. logger.Error("thirdpary provincial project add",
  58. zap.String("call", parser.Conf.ThirdParty.Provincial.ProjectUploadApi),
  59. zap.String("param", string(s)),
  60. zap.String("error",string(bytes)))
  61. return nil, errors.ProvincialProjectUploadError
  62. }
  63. id := gjson.GetBytes(bytes, "ID").String()
  64. reply.Id = id
  65. reply = &v1.ProvincialPostProjectReply{}
  66. return reply, nil
  67. }