table.go 3.8 KB

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