smm_api.go 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. package data_manage
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/models"
  5. "eta/eta_api/models/data_manage"
  6. "eta/eta_api/utils"
  7. "fmt"
  8. "github.com/rdlucklib/rdluck_tools/paging"
  9. "strings"
  10. )
  11. // SmmIndexList
  12. // @Title 有色api数据指标列表
  13. // @Description 有色api数据指标列表
  14. // @Success 200 {object} data_manage.SmmClassify
  15. // @router /smm/api/list [post]
  16. func (this *EdbInfoController) SmmApiList() {
  17. br := new(models.BaseResponse).Init()
  18. defer func() {
  19. this.Data["json"] = br
  20. this.ServeJSON()
  21. }()
  22. sysUser := this.SysUser
  23. if sysUser == nil {
  24. br.Msg = "请登录"
  25. br.ErrMsg = "请登录,SysUser Is Empty"
  26. br.Ret = 408
  27. return
  28. }
  29. var req data_manage.SmmIndexListReq
  30. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  31. if err != nil {
  32. br.Msg = "参数解析异常!"
  33. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  34. return
  35. }
  36. types := req.Types
  37. frequency := req.Frequency
  38. dataState := req.DataState
  39. keyword := req.Keyword
  40. indexCodes := req.IndexCodes
  41. sortType := req.SortType
  42. sortParam := req.SortParam
  43. pageSize := req.PageSize
  44. currentIndex := req.CurrentIndex
  45. if sortType == "" {
  46. sortType = "desc"
  47. }
  48. var startSize int
  49. if pageSize <= 0 {
  50. pageSize = utils.PageSize20
  51. }
  52. if currentIndex <= 0 {
  53. currentIndex = 1
  54. }
  55. startSize = utils.StartIndex(currentIndex, pageSize)
  56. var condition string
  57. var pars []interface{}
  58. if len(types) > 0 {
  59. condition += " AND ( "
  60. for _, v := range types {
  61. typeArr := strings.Split(v,",")
  62. for i, v := range typeArr {
  63. if i == 0 {
  64. condition += " ( "
  65. }
  66. typeStr := "type_"
  67. typeStr += fmt.Sprintf("%d", i+1)
  68. condition += typeStr+" =? "
  69. pars = append(pars, v)
  70. if i == len(typeArr) - 1 {
  71. condition += " ) "
  72. } else {
  73. condition += " AND "
  74. }
  75. }
  76. condition += " OR "
  77. }
  78. condition = strings.Trim(condition, "OR ")
  79. condition += " ) "
  80. }
  81. if frequency != "" {
  82. frequencyArr := strings.Split(frequency,",")
  83. condition += ` AND frequency IN (` + utils.GetOrmInReplace(len(frequencyArr)) + `) `
  84. pars = append(pars, frequencyArr)
  85. }
  86. if dataState != "" {
  87. stateArr := strings.Split(dataState,",")
  88. if strings.Contains(dataState, "normal") {
  89. stateArr = append(stateArr, "")
  90. condition += ` AND data_state IN (` + utils.GetOrmInReplace(len(stateArr)) + `) `
  91. pars = append(pars, stateArr)
  92. } else {
  93. condition += ` AND data_state IN (` + utils.GetOrmInReplace(len(stateArr)) + `) `
  94. pars = append(pars, stateArr)
  95. }
  96. }
  97. if keyword != "" {
  98. keyWordArr := strings.Split(keyword, " ")
  99. if len(keyWordArr) > 0 {
  100. condition += " AND ( "
  101. for _, v := range keyWordArr {
  102. condition += ` CONCAT(index_name,index_code) LIKE '%` + v + `%' OR`
  103. }
  104. condition = strings.TrimRight(condition, "OR")
  105. condition += " ) "
  106. }
  107. }
  108. if indexCodes != "" {
  109. indexCodeArr := strings.Split(indexCodes,",")
  110. indexCodeStr := ""
  111. for _, v := range indexCodeArr {
  112. indexCodeStr += "'" + v + "',"
  113. }
  114. indexCodeStr = strings.TrimRight(indexCodeStr, ",")
  115. condition += " AND index_code IN (" + indexCodeStr + ") "
  116. }
  117. sortStr := ``
  118. if sortParam != `` {
  119. sortStr = fmt.Sprintf("%s %s,modify_time desc ", utils.PascalToSnake(sortParam), sortType)
  120. } else {
  121. sortStr = " modify_time desc "
  122. }
  123. total, err := data_manage.GetSmmIndexDataListCount(condition, pars)
  124. if err!= nil {
  125. br.Msg = "获取指标总数失败"
  126. br.ErrMsg = "获取指标总数失败,Err:" + err.Error()
  127. return
  128. }
  129. indexList, err := data_manage.GetSmmIndexDataList(condition, sortStr, pars, startSize, pageSize)
  130. if err != nil {
  131. br.Msg = "获取指标列表失败"
  132. br.ErrMsg = "获取指标列表失败,Err:" + err.Error()
  133. return
  134. }
  135. for _, v := range indexList {
  136. v.TypeAll = v.Type1 + "/" + v.Type2 + "/" + v.Type3
  137. }
  138. page := paging.GetPaging(currentIndex, pageSize, total)
  139. var ret data_manage.BaseFromSmmIndexListResp
  140. ret.List = indexList
  141. ret.Paging = page
  142. br.Ret = 200
  143. br.Success = true
  144. br.Msg = "获取成功"
  145. br.Data = ret
  146. }
  147. // SmmApiTypeList
  148. // @Title 有色api数据分类列表
  149. // @Description 有色api数据分类列表
  150. // @Success 200 {object} data_manage.SmmClassify
  151. // @router /smm/api/type/list [get]
  152. func (this *EdbInfoController) SmmApiTypeList() {
  153. br := new(models.BaseResponse).Init()
  154. defer func() {
  155. this.Data["json"] = br
  156. this.ServeJSON()
  157. }()
  158. sysUser := this.SysUser
  159. if sysUser == nil {
  160. br.Msg = "请登录"
  161. br.ErrMsg = "请登录,SysUser Is Empty"
  162. br.Ret = 408
  163. return
  164. }
  165. typeList, err := data_manage.GetBaseFromSmmIndexTypeList()
  166. if err != nil {
  167. br.Msg = "获取指标列表失败"
  168. br.ErrMsg = "获取指标列表失败,Err:" + err.Error()
  169. return
  170. }
  171. resp := make([]data_manage.TypeListRespItem, 0)
  172. typeMap := make(map[string]map[string][]string)
  173. //type2Map := make(map[string][]string)
  174. //type2Map := make(map[string]data_manage.TypeListRespItem)
  175. // 初始化
  176. for _, v := range typeList {
  177. if v.Type1 != ""{
  178. if _, ok := typeMap[v.Type1];!ok {
  179. typeMap[v.Type1] = make(map[string][]string)
  180. } else {
  181. if _, ok := typeMap[v.Type1][v.Type2];!ok {
  182. typeMap[v.Type1][v.Type2] = make([]string, 0)
  183. }
  184. }
  185. }
  186. }
  187. for _, v := range typeList {
  188. if v.Type1 != ""{
  189. typeMap[v.Type1][v.Type2] = append(typeMap[v.Type1][v.Type2], v.Type3)
  190. }
  191. }
  192. for type1, type2Map := range typeMap {
  193. var item data_manage.TypeListRespItem
  194. item.Type = type1
  195. for type2, type3List := range type2Map {
  196. var child data_manage.TypeListRespItem
  197. child.Type = type2
  198. for _, type3 := range type3List {
  199. child.Child = append(child.Child, data_manage.TypeListRespItem{type3,nil})
  200. }
  201. item.Child = append(item.Child, child)
  202. }
  203. resp = append(resp, item)
  204. }
  205. br.Ret = 200
  206. br.Success = true
  207. br.Msg = "获取成功"
  208. br.Data = resp
  209. }