table.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "eta/eta_chart_lib/models"
  5. "eta/eta_chart_lib/utils"
  6. "fmt"
  7. "time"
  8. )
  9. // TableController 表格
  10. type TableController struct {
  11. BaseAuthController
  12. }
  13. // TableInfoDetail
  14. // @Title 获取表格详情
  15. // @Description 获取表格详情接口
  16. // @Param UniqueCode query string true "表格唯一编码,如果是管理后台访问,传固定字符串:7c69b590249049942070ae9dcd5bf6dc"
  17. // @Success 200 {object} data_manage.TableInfoDetailResp
  18. // @router /detail [get]
  19. func (this *TableController) TableInfoDetail() {
  20. br := new(models.BaseResponse).Init()
  21. defer func() {
  22. this.Data["json"] = br
  23. this.ServeJSON()
  24. }()
  25. uniqueCode := this.GetString("UniqueCode")
  26. if uniqueCode == "" {
  27. br.Msg = "参数错误"
  28. br.ErrMsg = "参数错误,uniqueCode is empty"
  29. return
  30. }
  31. key := utils.HZ_TABLE_LIB_DETAIL + uniqueCode
  32. resp := new(models.TableInfoDetailResp)
  33. //判断是否有缓存
  34. if utils.Re == nil {
  35. if utils.Re == nil && utils.Rc.IsExist(key) {
  36. if data, err1 := utils.Rc.RedisBytes(key); err1 == nil {
  37. err := json.Unmarshal(data, &resp)
  38. if err == nil && resp != nil {
  39. br.Ret = 200
  40. br.Success = true
  41. br.Msg = "获取成功"
  42. br.Data = resp
  43. fmt.Println("source redis")
  44. return
  45. }
  46. }
  47. }
  48. }
  49. tableInfo, err := models.GetTableInfoByUniqueCode(uniqueCode)
  50. if err != nil {
  51. if err.Error() == utils.ErrNoRow() {
  52. br.Msg = "该表格已被删除,请刷新页面"
  53. br.ErrMsg = "该表格已被删除,请刷新页面,Err:" + err.Error()
  54. return
  55. }
  56. br.Msg = "获取失败"
  57. br.ErrMsg = "获取表格信息失败,Err:" + err.Error()
  58. return
  59. }
  60. dataList, err := models.GetTableDataListByTableInfoId(tableInfo.TableInfoId)
  61. if err != nil {
  62. br.Msg = "获取失败"
  63. br.ErrMsg = "获取表格数据失败,Err:" + err.Error()
  64. return
  65. }
  66. resp.TableInfo = tableInfo
  67. resp.TableDataList = dataList
  68. if utils.Re == nil {
  69. data, _ := json.Marshal(resp)
  70. utils.Rc.Put(key, data, 10*time.Minute)
  71. }
  72. br.Ret = 200
  73. br.Success = true
  74. br.Msg = "获取成功"
  75. br.Data = resp
  76. }