dialysis_board_api_controller.go 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/service"
  5. "XT_New/utils"
  6. "time"
  7. "github.com/astaxie/beego"
  8. )
  9. func DialysisBoardAPIControllerRegistRouter() {
  10. beego.Router("/api/dialysis/board", &DialysisBoardAPIController{}, "get:BoardData")
  11. }
  12. type DialysisBoardAPIController struct {
  13. BaseAuthAPIController
  14. }
  15. func (c *DialysisBoardAPIController) BoardData() {
  16. page, _ := c.GetInt64("page", 0)
  17. if page <= 0 {
  18. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  19. return
  20. }
  21. nowTimeUinx := time.Now()
  22. today := nowTimeUinx.Format("2006-01-02")
  23. week := nowTimeUinx.Weekday()
  24. timeLayout := "2006-01-02"
  25. loc, _ := time.LoadLocation("Local")
  26. todayTime, err := time.ParseInLocation(timeLayout, today, loc)
  27. if err != nil {
  28. utils.ErrorLog("%v", err)
  29. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  30. return
  31. }
  32. var limit int64 = 10
  33. offset := (page - 1) * limit
  34. todayTimeStamp := todayTime.Unix()
  35. adminUserInfo := c.GetAdminUserInfo()
  36. boards, err := service.GetDialysisBoard(adminUserInfo.CurrentOrgId, todayTimeStamp, offset, limit)
  37. if err != nil {
  38. utils.ErrorLog("%v", err)
  39. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  40. return
  41. }
  42. c.ServeSuccessJSON(map[string]interface{}{
  43. "today": today,
  44. "week": week,
  45. "boards": boards,
  46. })
  47. }