getInvoiceRecord.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package handler
  2. import (
  3. "youngee_b_api/consts"
  4. "youngee_b_api/db"
  5. "youngee_b_api/middleware"
  6. "youngee_b_api/model/http_model"
  7. "youngee_b_api/util"
  8. "github.com/gin-gonic/gin"
  9. "github.com/sirupsen/logrus"
  10. )
  11. func WrapGetInvoiceRecordHandler(ctx *gin.Context) {
  12. handler := newGetInvoiceRecordHandler(ctx)
  13. baseRun(handler)
  14. }
  15. type GetInvoiceRecordHandler struct {
  16. ctx *gin.Context
  17. req *http_model.GetInvoiceRecordRequest
  18. resp *http_model.CommonResponse
  19. }
  20. func (g GetInvoiceRecordHandler) getContext() *gin.Context {
  21. return g.ctx
  22. }
  23. func (g GetInvoiceRecordHandler) getResponse() interface{} {
  24. return g.resp
  25. }
  26. func (g GetInvoiceRecordHandler) getRequest() interface{} {
  27. return g.req
  28. }
  29. func (g GetInvoiceRecordHandler) run() {
  30. enterpriseID := middleware.GetSessionAuth(g.ctx).EnterpriseID
  31. data, err := db.GetInvoiceRecords(g.ctx, g.req, enterpriseID)
  32. if err != nil {
  33. // 数据库查询失败,返回5001
  34. logrus.Errorf("[GetInvoiceRecordHandler] call GetInvoiceRecords err:%+v\n", err)
  35. util.HandlerPackErrorResp(g.resp, consts.ErrorInternal, "")
  36. logrus.Info("GetInvoiceRecords fail,req:%+v", g.req)
  37. return
  38. }
  39. g.resp.Data = data
  40. }
  41. func (g GetInvoiceRecordHandler) checkParam() error {
  42. return nil
  43. }
  44. func newGetInvoiceRecordHandler(ctx *gin.Context) *GetInvoiceRecordHandler {
  45. return &GetInvoiceRecordHandler{
  46. ctx: ctx,
  47. req: http_model.NewGetInvoiceRecordRequest(),
  48. resp: http_model.NewGetInvoiceRecordResponse(),
  49. }
  50. }