wind_data.go 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. package data_manage
  2. import (
  3. "eta_gn/eta_api/models"
  4. "eta_gn/eta_api/models/data_manage"
  5. "eta_gn/eta_api/models/data_manage/response"
  6. "eta_gn/eta_api/models/system"
  7. "eta_gn/eta_api/services/data"
  8. "eta_gn/eta_api/utils"
  9. "fmt"
  10. "github.com/rdlucklib/rdluck_tools/paging"
  11. "sort"
  12. )
  13. // @router /wind/classify [get]
  14. func (this *EdbInfoController) WindClassify() {
  15. br := new(models.BaseResponse).Init()
  16. defer func() {
  17. this.Data["json"] = br
  18. this.ServeJSON()
  19. }()
  20. parentId, _ := this.GetInt("ParentId")
  21. rootList, err := data_manage.GetEdbClassifyByParentId(parentId, 0)
  22. if err != nil && !utils.IsErrNoRow(err) {
  23. br.Msg = "获取失败"
  24. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  25. return
  26. }
  27. realRootMap := make(map[int]struct{})
  28. if parentId == 0 {
  29. classifyIdList, e := data_manage.GetEdbClassifyIdListBySource(utils.DATA_SOURCE_WIND)
  30. if e != nil && !utils.IsErrNoRow(e) {
  31. br.Msg = "获取失败"
  32. br.ErrMsg = "获取分类列表失败,Err:" + e.Error()
  33. return
  34. }
  35. if len(classifyIdList) == 0 {
  36. resp := new(data_manage.EdbClassifyListResp)
  37. br.Ret = 200
  38. br.Success = true
  39. br.Msg = "获取成功"
  40. br.Data = resp
  41. return
  42. }
  43. rootIds, e := data_manage.GetEdbClassifyRootIdsByClassifyIds(classifyIdList)
  44. if e != nil && !utils.IsErrNoRow(e) {
  45. br.Msg = "获取失败"
  46. br.ErrMsg = "获取分类列表失败,Err:" + e.Error()
  47. return
  48. }
  49. for _, v := range rootIds {
  50. realRootMap[v] = struct{}{}
  51. }
  52. }
  53. nodeAll := make([]*data_manage.EdbClassifyItems, 0)
  54. var sortList data_manage.EdbClassifyItemList
  55. if parentId > 0 {
  56. obj := data_manage.EdbInfoNoPermissionAdmin{}
  57. confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
  58. if err != nil && !utils.IsErrNoRow(err) {
  59. br.Msg = "获取失败"
  60. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  61. return
  62. }
  63. noPermissionEdbInfoIdMap := make(map[int]bool)
  64. for _, v := range confList {
  65. noPermissionEdbInfoIdMap[v.EdbInfoId] = true
  66. }
  67. allEdbInfo, err := data_manage.GetEdbInfoByClassifyIdAndSource(parentId, 0, utils.DATA_SOURCE_WIND)
  68. if err != nil {
  69. br.Msg = "获取指标数据失败"
  70. br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
  71. return
  72. }
  73. if len(allEdbInfo) > 0 {
  74. for _, v := range allEdbInfo {
  75. if _, ok := noPermissionEdbInfoIdMap[v.EdbInfoId]; ok {
  76. continue
  77. }
  78. v.Children = make([]*data_manage.EdbClassifyItems, 0)
  79. v.ParentId = parentId
  80. nodeAll = append(nodeAll, v)
  81. }
  82. }
  83. }
  84. if len(rootList) > 0 {
  85. for _, v := range rootList {
  86. if _, ok := realRootMap[v.ClassifyId]; !ok && parentId == 0 { //查询一级分类时,过滤
  87. continue
  88. }
  89. v.Children = make([]*data_manage.EdbClassifyItems, 0)
  90. nodeAll = append(nodeAll, v)
  91. }
  92. }
  93. if len(nodeAll) > 0 {
  94. sortList = nodeAll
  95. sort.Sort(sortList)
  96. }
  97. language := `CN`
  98. {
  99. configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.EdbLanguageVar)
  100. if configDetail != nil {
  101. language = configDetail.ConfigValue
  102. } else {
  103. configDetail, _ = system.GetDefaultConfigDetailByCode(system.EdbLanguageVar)
  104. if configDetail != nil {
  105. language = configDetail.ConfigValue
  106. }
  107. }
  108. }
  109. resp := new(data_manage.EdbClassifyListResp)
  110. resp.AllNodes = sortList
  111. resp.Language = language
  112. br.Ret = 200
  113. br.Success = true
  114. br.Msg = "获取成功"
  115. br.Data = resp
  116. }
  117. // @router /wind/index [get]
  118. func (this *EdbInfoController) WindEdbInfoList() {
  119. br := new(models.BaseResponse).Init()
  120. defer func() {
  121. if br.ErrMsg == "" {
  122. br.IsSendEmail = false
  123. }
  124. this.Data["json"] = br
  125. this.ServeJSON()
  126. }()
  127. sysUser := this.SysUser
  128. if sysUser == nil {
  129. br.Msg = "请登录"
  130. br.ErrMsg = "请登录,SysUser Is Empty"
  131. br.Ret = 408
  132. return
  133. }
  134. pageSize, _ := this.GetInt("PageSize")
  135. currentIndex, _ := this.GetInt("CurrentIndex")
  136. var total int
  137. page := paging.GetPaging(currentIndex, pageSize, total)
  138. var startSize int
  139. if pageSize <= 0 {
  140. pageSize = utils.PageSize20
  141. }
  142. if currentIndex <= 0 {
  143. currentIndex = 1
  144. }
  145. startSize = paging.StartIndex(currentIndex, pageSize)
  146. var condition string
  147. var pars []interface{}
  148. condition += ` AND edb_info_type = ? AND source =? AND edb_type=?`
  149. pars = append(pars, 0, utils.DATA_SOURCE_WIND, 1)
  150. classifyId, _ := this.GetInt("ClassifyId")
  151. edbInfoId, _ := this.GetInt("EdbInfoId")
  152. if classifyId > 0 {
  153. childClassify, e, _ := data.GetChildClassifyByClassifyId(classifyId)
  154. if e != nil && !utils.IsErrNoRow(e) {
  155. br.Msg = "获取失败"
  156. br.ErrMsg = "获取分类信息失败, GetEdbClassify,Err:" + e.Error()
  157. return
  158. }
  159. var classifyIds []int
  160. for _, v := range childClassify {
  161. classifyIds = append(classifyIds, v.ClassifyId)
  162. }
  163. condition += fmt.Sprintf(` AND classify_id IN (%s) `, utils.GetOrmInReplace(len(classifyIds)))
  164. pars = append(pars, classifyIds)
  165. }
  166. if edbInfoId > 0 {
  167. condition += ` AND edb_info_id = ?`
  168. pars = append(pars, edbInfoId)
  169. }
  170. obj := data_manage.EdbInfoNoPermissionAdmin{}
  171. confList, e := obj.GetAllListByAdminId(this.SysUser.AdminId)
  172. if e != nil {
  173. br.Msg = "获取失败"
  174. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + e.Error()
  175. return
  176. }
  177. noPermissionEdbInfoIdList := make([]int, 0)
  178. for _, v := range confList {
  179. noPermissionEdbInfoIdList = append(noPermissionEdbInfoIdList, v.EdbInfoId)
  180. }
  181. noPermissionEdbInfoIdNum := len(noPermissionEdbInfoIdList)
  182. if noPermissionEdbInfoIdNum > 0 {
  183. condition += ` AND edb_info_id NOT IN (` + utils.GetOrmInReplace(noPermissionEdbInfoIdNum) + `) `
  184. pars = append(pars, noPermissionEdbInfoIdList)
  185. }
  186. list := make([]*data_manage.WindEdbInfoList, 0)
  187. dataCount, edbList, e := data_manage.GetEdbInfoFilterList(condition, pars, startSize, pageSize)
  188. if e != nil {
  189. br.Msg = "获取失败"
  190. br.ErrMsg = "获取普通指标列表失败, Err:" + e.Error()
  191. return
  192. }
  193. page = paging.GetPaging(currentIndex, pageSize, int(dataCount))
  194. if len(edbList) > 0 {
  195. classifyMap := make(map[int]*data_manage.EdbClassify)
  196. targetClassifyList := make([]*data_manage.EdbClassifyItems, 0)
  197. if edbInfoId > 0 && classifyId == 0 {
  198. classifyId = edbList[0].ClassifyId
  199. }
  200. if classifyId > 0 { // todo 当没有传入分类ID时,如何处理 同一个分类ID,顶级分类是一样的
  201. targetClassify, err := data_manage.GetEdbClassifyById(classifyId)
  202. if err != nil {
  203. if utils.IsErrNoRow(err) {
  204. br.Msg = "当前分类不存在"
  205. return
  206. }
  207. br.Msg = "获取失败"
  208. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  209. return
  210. }
  211. targetClassifyList, err = data_manage.GetEdbClassifyByRootIdLevel(targetClassify.RootId, targetClassify.ClassifyType, "")
  212. if err != nil && !utils.IsErrNoRow(err) {
  213. br.Msg = "获取失败"
  214. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  215. return
  216. }
  217. classifyIds := make([]int, 0)
  218. for _, v := range edbList {
  219. classifyIds = append(classifyIds, v.ClassifyId)
  220. }
  221. classifyList, err := data_manage.GetEdbClassifyByIdList(classifyIds)
  222. if err != nil {
  223. br.Msg = "获取失败"
  224. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  225. return
  226. }
  227. for _, v := range classifyList {
  228. classifyMap[v.ClassifyId] = v
  229. }
  230. }
  231. for _, v := range edbList {
  232. targetClassify, ok := classifyMap[v.ClassifyId]
  233. if !ok {
  234. br.Msg = "当前分类不存在"
  235. return
  236. }
  237. classifyList, err, errMsg := data.GetFullClassifyByRootId(targetClassify, targetClassifyList)
  238. if err != nil {
  239. br.Msg = err.Error()
  240. br.ErrMsg = errMsg
  241. return
  242. }
  243. tmp := &data_manage.WindEdbInfoList{
  244. EdbInfoList: v,
  245. ClassifyList: classifyList,
  246. }
  247. list = append(list, tmp)
  248. }
  249. }
  250. resp := response.WindEdbInfoListResp{
  251. Paging: page,
  252. List: list,
  253. }
  254. br.Ret = 200
  255. br.Success = true
  256. br.Msg = "获取成功"
  257. br.Data = resp
  258. }