ebike_factory_api_third.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package third
  2. import (
  3. "context"
  4. "go-template/business/dto"
  5. "go-template/business/exception"
  6. "gitea.ckfah.com/cjjy/gocommon/pkg/cerror"
  7. "gitea.ckfah.com/cjjy/gocommon/pkg/logger"
  8. "gitea.ckfah.com/cjjy/gocommon/pkg/net/httpclent"
  9. )
  10. // doc:
  11. type ebikeFactoryApi struct {
  12. }
  13. func NewEbikeFactoryApi() *ebikeFactoryApi {
  14. return new(ebikeFactoryApi)
  15. }
  16. func (*ebikeFactoryApi) GetServerName() string {
  17. return "ebike-factory-api"
  18. }
  19. // 统一抽象一个方法,方便管理
  20. func (this *ebikeFactoryApi) httpRequest(ctx context.Context, path string, params interface{}, result interface{}, options ...httpclent.Option) error {
  21. return httpclent.HttpRequestAndDecode(ctx, this.GetServerName(), path, params, result, append(options, httpclent.NacosServerHostOption)...)
  22. }
  23. func (this *ebikeFactoryApi) GetOpWorkerDetailById(ctx context.Context, opWorkerId uint64) (*dto.OpWorkerDetailData, cerror.Cerror) {
  24. path := "/service/v1/op-worker/search-by-ids"
  25. params := map[string]interface{}{
  26. "ids": []uint64{opWorkerId},
  27. }
  28. response := dto.GetOpWorkerDetailResponse{}
  29. err := this.httpRequest(ctx, path, params, &response)
  30. if err != nil {
  31. // 三方日志要打印warn日志,如果必要的话才打印error日志
  32. logger.Warnc(ctx, "[GetOpWorkerDetail] err,op_worker_id=%d,err=%v", opWorkerId, err)
  33. return nil, exception.GetOpWorkerDetailError("获取op_worker信息失败")
  34. }
  35. if response.Data == nil || len(response.Data) == 0 {
  36. logger.Warnc(ctx, "[GetOpWorkerDetail] not fond op_worker,op_worker_id=%d", opWorkerId)
  37. return nil, nil
  38. }
  39. return &response.Data[0], nil
  40. }