staff_add.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 ProvincialPostStaff(ctx context.Context, req *v1.ProvincialPostStaffRequest)(reply *v1.ProvincialPostStaffReply, 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. "WorkerName":req.WorkerName,
  27. "IsTeamLeader":req.IsTeamLeader,
  28. "IDCardType":req.IdCardType,
  29. "IDCardNumber":req.IdCardNumber,
  30. "Age":req.Age,
  31. "Gender":req.Gender,
  32. "Nation":req.Nation,
  33. "Address":req.Address,
  34. "headImage":req.HeadImage,
  35. "PoliticsType":req.PoliticsType,
  36. "CultureLevelType":req.CultureLevelType,
  37. "GrantOrg":req.GrantOrg,
  38. "WorkType":req.WorkType,
  39. "NativePlace":req.NativePlace,
  40. "Mobile":req.Mobile,
  41. "HasContract":req.HasContract,
  42. }
  43. datas := []map[string]interface{}{}
  44. datas = append(datas, data)
  45. param := map[string]interface{}{
  46. "type":"建筑工人信息",
  47. "datas":datas,
  48. }
  49. bytes, err := thirdparty.ProvincialPost(parser.Conf.ThirdParty.Provincial.ProjectUploadApi, token, param)
  50. fmt.Printf("provincial add staff: %s,%v\n", bytes, err)
  51. if err != nil {
  52. s, _ := json.Marshal(param)
  53. logger.Error("thirdpary provincial add staff",
  54. zap.String("call", parser.Conf.ThirdParty.Provincial.ProjectUploadApi),
  55. zap.String("param", string(s)),
  56. zap.String("error", err.Error()))
  57. return nil, errors.ProvincialProjectUploadError
  58. }
  59. ack := gjson.GetBytes(bytes, "ack_code").String()
  60. if strings.ToUpper(ack) != "SUCCESS" {
  61. s, _ := json.Marshal(param)
  62. logger.Error("thirdpary provincial add staff",
  63. zap.String("call", parser.Conf.ThirdParty.Provincial.ProjectUploadApi),
  64. zap.String("param", string(s)),
  65. zap.String("error",string(bytes)))
  66. return nil, errors.ProvincialProjectUploadError
  67. }
  68. id := gjson.GetBytes(bytes, "ID").String()
  69. reply.Id = id
  70. reply = &v1.ProvincialPostStaffReply{}
  71. return reply, nil
  72. }