table.go 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. package common
  2. import (
  3. "mtp2_if/global/app"
  4. "mtp2_if/global/e"
  5. "mtp2_if/logger"
  6. "mtp2_if/models"
  7. "net/http"
  8. "github.com/gin-gonic/gin"
  9. )
  10. // QueryTraderMenuReq 查询交易端菜单请求参数
  11. type QueryTraderMenuReq struct {
  12. LoginID int `form:"loginid" binding:"required"`
  13. }
  14. // QueryTraderMenuRsp 交易端菜单
  15. type QueryTraderMenuRsp struct {
  16. QuoteMenu []models.QuotePrimaryMenu `json:"QuoteMenu"` // 报价牌分类菜单
  17. OperationMenu []models.OperationPrimaryMenu `json:"OperationMenu"` // 功能菜单
  18. }
  19. // QueryTraderMenu 查询交易端菜单
  20. // @Summary 查询交易端菜单
  21. // @Produce json
  22. // @Param loginid query int true "登录账号"
  23. // @Success 200 {object} QueryTraderMenuRsp
  24. // @Failure 500 {object} app.Response
  25. // @Router /Common/QueryTraderMenu [get]
  26. // @Tags 通用服务
  27. func QueryTraderMenu(c *gin.Context) {
  28. appG := app.Gin{C: c}
  29. // 获取请求参数
  30. var req QueryTraderMenuReq
  31. if err := appG.C.ShouldBindQuery(&req); err != nil {
  32. logger.GetLogger().Errorf("QueryTraderMenu failed: %s", err.Error())
  33. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  34. return
  35. }
  36. var queryTraderMenuRsp QueryTraderMenuRsp
  37. // 获取行情报价牌分类菜单
  38. if datas, err := models.GetQuoteMenu(req.LoginID); err == nil {
  39. queryTraderMenuRsp.QuoteMenu = datas
  40. } else {
  41. logger.GetLogger().Errorf("QueryTraderMenu failed: %s", err.Error())
  42. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_QUOTEMENU_FAIL, nil)
  43. return
  44. }
  45. // 获取功能菜单
  46. if datas, err := models.GetOperationMenu(); err == nil {
  47. queryTraderMenuRsp.OperationMenu = datas
  48. } else {
  49. logger.GetLogger().Errorf("QueryTraderMenu failed: %s", err.Error())
  50. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_OPERATIONMENU_FAIL, nil)
  51. return
  52. }
  53. // 查询成功
  54. logger.GetLogger().Debugln("QueryTraderMenu successed: %v", queryTraderMenuRsp)
  55. appG.Response(http.StatusOK, e.SUCCESS, queryTraderMenuRsp)
  56. }
  57. // GetPCMenus 获取PC交易端菜单
  58. // @Summary 获取PC交易端菜单
  59. // @Produce json
  60. // @Success 200 {array} models.OperationPrimaryMenu
  61. // @Failure 500 {object} app.Response
  62. // @Router /Common/GetPCMenus [get]
  63. // @Tags 通用服务
  64. func GetPCMenus(c *gin.Context) {
  65. appG := app.Gin{C: c}
  66. // 获取功能菜单
  67. datas, err := models.GetOperationMenu()
  68. if err != nil {
  69. logger.GetLogger().Errorf("GetPCMenus failed: %s", err.Error())
  70. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_OPERATIONMENU_FAIL, nil)
  71. return
  72. }
  73. // 查询成功
  74. logger.GetLogger().Debugln("GetPCMenus successed: %v", datas)
  75. appG.Response(http.StatusOK, e.SUCCESS, datas)
  76. }
  77. // QueryTableDefineReq 查询交易端列表头信息请求参数
  78. type QueryTableDefineReq struct {
  79. TableKey string `form:"tableKey"`
  80. TableType int `form:"tableType"`
  81. }
  82. // QueryTableDefineRsp 查询交易端列表头信息返回模型
  83. type QueryTableDefineRsp struct {
  84. models.Tabledefine `xorm:"extends"`
  85. Columns []models.Tablecolumnconfig `json:"columns" xorm:"-"` // 列头信息数组
  86. }
  87. // QueryTableDefine 查询交易端列表头信息
  88. // @Summary 查询交易端列表头信息
  89. // @Produce json
  90. // @Param tableKey query string false "表key"
  91. // @Param tableType query int false "列表类型 - 1:管理端 2:H5终端 3:移动终端"
  92. // @Success 200 {object} QueryTableDefineRsp
  93. // @Failure 500 {object} app.Response
  94. // @Router /Common/QueryTableDefine [get]
  95. // @Tags 通用服务
  96. func QueryTableDefine(c *gin.Context) {
  97. appG := app.Gin{C: c}
  98. // 获取请求参数
  99. var req QueryTableDefineReq
  100. if err := appG.C.ShouldBindQuery(&req); err != nil {
  101. logger.GetLogger().Errorf("QueryTableDefine failed: %s", err.Error())
  102. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  103. return
  104. }
  105. rst := make([]QueryTableDefineRsp, 0)
  106. // 获取表定义
  107. tableDefines, err := models.GetClientTableDefines(req.TableKey, req.TableType)
  108. if err != nil {
  109. logger.GetLogger().Errorf("QueryTableDefine failed: %s", err.Error())
  110. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  111. return
  112. }
  113. for i, v := range tableDefines {
  114. var queryTableDefineRsp QueryTableDefineRsp
  115. // 表数据
  116. queryTableDefineRsp.Tabledefine = tableDefines[i]
  117. // 获取列表数据
  118. tablecolumnconfigs, err := models.GetClientTableColumns(v.Tablekey, int(v.Tabletype))
  119. if err != nil {
  120. logger.GetLogger().Errorf("QueryTableDefine failed: %s", err.Error())
  121. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  122. return
  123. }
  124. queryTableDefineRsp.Columns = tablecolumnconfigs
  125. rst = append(rst, queryTableDefineRsp)
  126. }
  127. // 查询成功
  128. logger.GetLogger().Debugln("QueryTableDefine successed: %v", rst)
  129. appG.Response(http.StatusOK, e.SUCCESS, rst)
  130. }