smm_api.go 6.0 KB

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