sap.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package service
  2. import (
  3. "time"
  4. "github.com/pkg/errors"
  5. log "github.com/sirupsen/logrus"
  6. "kpt.xdmy/apiserver/model"
  7. "kpt.xdmy/apiserver/model/http"
  8. "kpt.xdmy/pkg/util"
  9. )
  10. func (s *Service) AddSapLog(p http.SapDest, err error) {
  11. b, e := util.Marshal(p)
  12. if e != nil {
  13. log.Error(e)
  14. return
  15. }
  16. d := p.GetDest()
  17. l := model.SapLog{
  18. Url: d.Url,
  19. Name: d.BussTp,
  20. Status: d.Status,
  21. MsgText: d.MessText,
  22. Param: string(b),
  23. CreatedAt: time.Now(),
  24. }
  25. if err != nil {
  26. l.Flag = 1
  27. }
  28. if e := s.d.DB.Create(&l).Error; e != nil {
  29. log.Error(e)
  30. } else {
  31. log.Infof("create sap log:%s ", p.GetUrl())
  32. }
  33. }
  34. func (s *Service) SyncSap(r http.SapDest, rp interface{}) (err error) {
  35. req, e := s.http.NewRequest("POST", r.GetUrl(), r)
  36. if e != nil {
  37. return errors.Wrapf(e, "SyncSap")
  38. }
  39. s.http.SetBasicAuth(req)
  40. if err = s.http.Do(req, &rp); err != nil {
  41. err = errors.Wrapf(err, "SyncSap")
  42. }
  43. return
  44. }
  45. func (s *Service) SyncSrm(r http.SapDest, rp interface{}, data interface{}) (err error) {
  46. req, e := s.http.NewRequest("POST", r.GetUrl(), data)
  47. if e != nil {
  48. return errors.Wrapf(e, "SyncSap")
  49. }
  50. s.http.SetSrmBasicAuth(req)
  51. if err = s.http.Do(req, rp); err != nil {
  52. err = errors.Wrapf(err, "SyncSap")
  53. }
  54. return
  55. }