punch_clock_page_logic.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package user
  2. import (
  3. "context"
  4. "fmt"
  5. "git.i2edu.net/i2/i2-bill-api/internal/utils"
  6. "net/http"
  7. "strconv"
  8. "time"
  9. "git.i2edu.net/i2/i2-bill-api/internal/svc"
  10. "git.i2edu.net/i2/i2-bill-api/internal/types"
  11. "git.i2edu.net/i2/go-zero/core/logx"
  12. )
  13. type PunchClockPageLogic struct {
  14. logx.Logger
  15. ctx context.Context
  16. svcCtx *svc.ServiceContext
  17. }
  18. func NewPunchClockPageLogic(ctx context.Context, svcCtx *svc.ServiceContext) PunchClockPageLogic {
  19. return PunchClockPageLogic{
  20. Logger: logx.WithContext(ctx),
  21. ctx: ctx,
  22. svcCtx: svcCtx,
  23. }
  24. }
  25. func (l *PunchClockPageLogic) PunchClockPage(r *http.Request) (*types.Response, error) {
  26. // todo: add your logic here and delete this line
  27. r.ParseForm()
  28. create_time_sta := r.Form.Get("date_sta")
  29. create_time_end := r.Form.Get("date_end")
  30. page, _ := strconv.Atoi(r.Form.Get("page"))
  31. rows, _ := strconv.Atoi(r.Form.Get("rows"))
  32. sort := r.Form.Get("__sort__")
  33. userId := fmt.Sprintf("%d", l.svcCtx.GetUserIdByJwt(l.ctx))
  34. if create_time_end != "" {
  35. end, err := time.Parse("2006-01-02", create_time_end)
  36. if err != nil {
  37. return &types.Response{500, err.Error(), nil}, nil
  38. }
  39. create_time_end = end.Add(time.Second*24*60*60 - 1*time.Second).Format("2006-01-02 15:04:05")
  40. }
  41. if sort == "" {
  42. sort = "id desc"
  43. }
  44. paramMap_i_t := map[string]interface{}{
  45. "page": page,
  46. "rows": rows,
  47. "create_time_sta": create_time_sta,
  48. "create_time_end": create_time_end,
  49. "user_id": userId,
  50. "__sort__": sort,
  51. }
  52. res, err := utils.PageSearch(l.svcCtx.DB, "i2bill_acquirer_attendance_record", "page", "i2bill_acquirer_attendance_record", paramMap_i_t)
  53. if err != nil {
  54. return &types.Response{500, err.Error(), nil}, nil
  55. }
  56. return &types.Response{200, "", res}, nil
  57. }