findrecordlogic.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package logic
  2. import (
  3. "app.yhyue.com/moapp/jyResourcesCenter/rpc/resourcesCenterclient"
  4. "context"
  5. "log"
  6. "app.yhyue.com/moapp/jyResourcesCenter/api/internal/svc"
  7. "app.yhyue.com/moapp/jyResourcesCenter/api/internal/types"
  8. "github.com/tal-tech/go-zero/core/logx"
  9. )
  10. type FindRecordLogic struct {
  11. logx.Logger
  12. ctx context.Context
  13. svcCtx *svc.ServiceContext
  14. }
  15. func NewFindRecordLogic(ctx context.Context, svcCtx *svc.ServiceContext) FindRecordLogic {
  16. return FindRecordLogic{
  17. Logger: logx.WithContext(ctx),
  18. ctx: ctx,
  19. svcCtx: svcCtx,
  20. }
  21. }
  22. func (l *FindRecordLogic) FindRecord(req types.RecordReq) (*types.RecordRes, error) {
  23. // todo: add your logic here and delete this line
  24. result := &types.RecordRes{}
  25. log.Println(req)
  26. lsi := l.svcCtx.ResourcesCenter
  27. resp, err := lsi.FindConsumeRecord(l.ctx, &resourcesCenterclient.RecordReq{
  28. AccountId: req.AccountId,
  29. UserId: req.UserId,
  30. PageSize: req.PageSize,
  31. Page: req.Page,
  32. State: req.State,
  33. })
  34. if err != nil {
  35. return nil, err
  36. }
  37. data := make([]map[string]interface{}, 0)
  38. if len(resp.Data) > 0 {
  39. for _, val := range resp.Data {
  40. data = append(data, map[string]interface{}{
  41. "id": val.Id,
  42. "deductionNumb": val.DeductionNumb,
  43. "exportNum": val.ExportNum,
  44. "exportTime": val.ExportTime,
  45. "name": val.Name,
  46. "resourceType": val.ResourceType,
  47. "ruleId": val.RuleId,
  48. "searchCriteria": val.SearchCriteria,
  49. "source": val.Source,
  50. "url": val.Url,
  51. "userId": val.UserId,
  52. "remarks": val.Remarks,
  53. })
  54. }
  55. }
  56. result.Code = resp.Code
  57. result.Message = resp.Message
  58. result.Data = data
  59. result.Count = resp.Count
  60. return result, nil
  61. }