package service import ( "time" "github.com/pkg/errors" log "github.com/sirupsen/logrus" "kpt.xdmy/apiserver/model" "kpt.xdmy/apiserver/model/http" "kpt.xdmy/pkg/util" ) func (s *Service) AddSapLog(p http.SapDest, err error) { b, e := util.Marshal(p) if e != nil { log.Error(e) return } d := p.GetDest() l := model.SapLog{ Url: d.Url, Name: d.BussTp, Status: d.Status, MsgText: d.MessText, Param: string(b), CreatedAt: time.Now(), } if err != nil { l.Flag = 1 } if e := s.d.DB.Create(&l).Error; e != nil { log.Error(e) } else { log.Infof("create sap log:%s ", p.GetUrl()) } } func (s *Service) SyncSap(r http.SapDest, rp interface{}) (err error) { req, e := s.http.NewRequest("POST", r.GetUrl(), r) if e != nil { return errors.Wrapf(e, "SyncSap") } s.http.SetBasicAuth(req) if err = s.http.Do(req, &rp); err != nil { err = errors.Wrapf(err, "SyncSap") } return } func (s *Service) SyncSrm(r http.SapDest, rp interface{}, data interface{}) (err error) { req, e := s.http.NewRequest("POST", r.GetUrl(), data) if e != nil { return errors.Wrapf(e, "SyncSap") } s.http.SetSrmBasicAuth(req) if err = s.http.Do(req, rp); err != nil { err = errors.Wrapf(err, "SyncSap") } return }