staff_attendance.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 ProvincialPostStaffAttendance(ctx context.Context, req *v1.ProvincialPostStaffAttendanceRequest)(reply *v1.ProvincialPostStaffAttendanceReply, 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. "WorkerName":req.WorkerName,
  25. "IDCardType":req.IdCardType,
  26. "IDCardNumber":req.IdCardNumber,
  27. "Direction":req.Direction,
  28. "Date":req.Date,
  29. }
  30. datas := []map[string]interface{}{}
  31. datas = append(datas, data)
  32. param := map[string]interface{}{
  33. "type":"考勤信息",
  34. "datas":datas,
  35. }
  36. bytes, err := thirdparty.ProvincialPost(parser.Conf.ThirdParty.Provincial.ProjectUploadApi, token, param)
  37. fmt.Printf("provincial add staff attendance %s,%v\n", bytes, err)
  38. if err != nil {
  39. s, _ := json.Marshal(param)
  40. logger.Error("thirdpary provincial add staff attendance",
  41. zap.String("call", parser.Conf.ThirdParty.Provincial.ProjectUploadApi),
  42. zap.String("param", string(s)),
  43. zap.String("error", err.Error()))
  44. return nil, errors.ProvincialProjectUploadError
  45. }
  46. ack := gjson.GetBytes(bytes, "ack_code").String()
  47. if strings.ToUpper(ack) != "SUCCESS" {
  48. s, _ := json.Marshal(param)
  49. logger.Error("thirdpary provincial add staff attendance",
  50. zap.String("call", parser.Conf.ThirdParty.Provincial.ProjectUploadApi),
  51. zap.String("param", string(s)),
  52. zap.String("error",string(bytes)))
  53. return nil, errors.ProvincialProjectUploadError
  54. }
  55. id := gjson.GetBytes(bytes, "ID").String()
  56. reply.Id = id
  57. reply = &v1.ProvincialPostStaffAttendanceReply{}
  58. return reply, nil
  59. }