wind_data.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  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. // WindClassify
  14. // @Title wind指标分类
  15. // @Description wind指标分类
  16. // @Success 200 {object} data_manage.BaseFromYongyiClassify
  17. // @router /wind/classify [get]
  18. func (this *EdbInfoController) WindClassify() {
  19. br := new(models.BaseResponse).Init()
  20. defer func() {
  21. this.Data["json"] = br
  22. this.ServeJSON()
  23. }()
  24. // 默认查一级分类和一级分类下的指标信息,
  25. // 如果是 子级分类,查询该子级分类的下一级分类和指标信息
  26. // 增加标识判断是文件夹还是指标列表
  27. parentId, _ := this.GetInt("ParentId")
  28. // 特殊处理顶级分类
  29. rootList, err := data_manage.GetEdbClassifyByParentId(parentId, 0, 0)
  30. if err != nil && !utils.IsErrNoRow(err) {
  31. br.Msg = "获取失败"
  32. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  33. return
  34. }
  35. realRootMap := make(map[int]struct{})
  36. if parentId == 0 {
  37. // 查询wind指标的所有一级分类
  38. classifyIdList, e := data_manage.GetEdbClassifyIdListBySource(utils.DATA_SOURCE_WIND)
  39. if e != nil && !utils.IsErrNoRow(e) {
  40. br.Msg = "获取失败"
  41. br.ErrMsg = "获取分类列表失败,Err:" + e.Error()
  42. return
  43. }
  44. if len(classifyIdList) == 0 {
  45. resp := new(data_manage.EdbClassifyListResp)
  46. br.Ret = 200
  47. br.Success = true
  48. br.Msg = "获取成功"
  49. br.Data = resp
  50. return
  51. }
  52. // 查询wind指标的所有一级分类下的指标信息
  53. rootIds, e := data_manage.GetEdbClassifyRootIdsByClassifyIds(classifyIdList)
  54. if e != nil && !utils.IsErrNoRow(e) {
  55. br.Msg = "获取失败"
  56. br.ErrMsg = "获取分类列表失败,Err:" + e.Error()
  57. return
  58. }
  59. for _, v := range rootIds {
  60. realRootMap[v] = struct{}{}
  61. }
  62. }
  63. nodeAll := make([]*data_manage.EdbClassifyItems, 0)
  64. var sortList data_manage.EdbClassifyItemList
  65. if parentId > 0 {
  66. // 查询挂在当前分类上的指标列表
  67. // 获取当前账号的不可见指标
  68. obj := data_manage.EdbInfoNoPermissionAdmin{}
  69. confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
  70. if err != nil && !utils.IsErrNoRow(err) {
  71. br.Msg = "获取失败"
  72. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  73. return
  74. }
  75. noPermissionEdbInfoIdMap := make(map[int]bool)
  76. for _, v := range confList {
  77. noPermissionEdbInfoIdMap[v.EdbInfoId] = true
  78. }
  79. allEdbInfo, err := data_manage.GetEdbInfoByClassifyIdAndSource(parentId, 0, utils.DATA_SOURCE_WIND)
  80. if err != nil {
  81. br.Msg = "获取指标数据失败"
  82. br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
  83. return
  84. }
  85. if len(allEdbInfo) > 0 {
  86. // 查询当前子分类信息
  87. /*currClassify, err := data_manage.GetEdbClassifyById(parentId)
  88. if err != nil {
  89. br.Msg = "获取失败"
  90. br.ErrMsg = "获取当前分类信息失败,Err:" + err.Error()
  91. return
  92. }
  93. // 获取所有有权限的指标和分类
  94. permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
  95. if err != nil {
  96. br.Msg = "获取失败"
  97. br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
  98. return
  99. }*/
  100. for _, v := range allEdbInfo {
  101. // 如果指标不可见,那么就不返回该指标
  102. if _, ok := noPermissionEdbInfoIdMap[v.EdbInfoId]; ok {
  103. continue
  104. }
  105. //v.HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(v.IsJoinPermission, currClassify.IsJoinPermission, v.EdbInfoId, v.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  106. /*button := data.GetEdbOpButton(this.SysUser, v.SysUserId, v.EdbType, utils.EDB_INFO_TYPE, v.HaveOperaAuth)
  107. button.AddButton = false //不管有没有权限,指标都是没有添加按钮的
  108. v.Button = button*/
  109. v.Children = make([]*data_manage.EdbClassifyItems, 0)
  110. v.ParentId = parentId
  111. nodeAll = append(nodeAll, v)
  112. }
  113. }
  114. }
  115. if len(rootList) > 0 {
  116. // 已授权分类id
  117. /*permissionClassifyIdList, err := data_manage_permission.GetUserEdbClassifyPermissionList(this.SysUser.AdminId, 0)
  118. if err != nil {
  119. br.Msg = "获取失败"
  120. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  121. return
  122. }*/
  123. for _, v := range rootList {
  124. // 数据权限
  125. /*v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList)
  126. // 按钮权限
  127. button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth)
  128. v.Button = button*/
  129. if _, ok := realRootMap[v.ClassifyId]; !ok && parentId == 0 { //查询一级分类时,过滤
  130. continue
  131. }
  132. v.Children = make([]*data_manage.EdbClassifyItems, 0)
  133. nodeAll = append(nodeAll, v)
  134. }
  135. }
  136. if len(nodeAll) > 0 {
  137. //根据sort值排序
  138. sortList = nodeAll
  139. sort.Sort(sortList)
  140. }
  141. language := `CN`
  142. // 指标显示的语言
  143. {
  144. configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.EdbLanguageVar)
  145. if configDetail != nil {
  146. language = configDetail.ConfigValue
  147. } else {
  148. configDetail, _ = system.GetDefaultConfigDetailByCode(system.EdbLanguageVar)
  149. if configDetail != nil {
  150. language = configDetail.ConfigValue
  151. }
  152. }
  153. }
  154. resp := new(data_manage.EdbClassifyListResp)
  155. resp.AllNodes = sortList
  156. resp.Language = language
  157. br.Ret = 200
  158. br.Success = true
  159. br.Msg = "获取成功"
  160. br.Data = resp
  161. }
  162. // WindEdbInfoList
  163. // @Title wind指标列表接口
  164. // @Description wind指标列表接口
  165. // @Param PageSize query int true "每页数据条数"
  166. // @Param CurrentIndex query int true "当前页页码,从1开始"
  167. // @Param ClassifyId query int true "分类id"
  168. // @Success 200 {object} response.EdbInfoChartListResp
  169. // @router /wind/index [get]
  170. func (this *EdbInfoController) WindEdbInfoList() {
  171. br := new(models.BaseResponse).Init()
  172. defer func() {
  173. if br.ErrMsg == "" {
  174. br.IsSendEmail = false
  175. }
  176. this.Data["json"] = br
  177. this.ServeJSON()
  178. }()
  179. sysUser := this.SysUser
  180. if sysUser == nil {
  181. br.Msg = "请登录"
  182. br.ErrMsg = "请登录,SysUser Is Empty"
  183. br.Ret = 408
  184. return
  185. }
  186. // 分页
  187. pageSize, _ := this.GetInt("PageSize")
  188. currentIndex, _ := this.GetInt("CurrentIndex")
  189. var total int
  190. page := paging.GetPaging(currentIndex, pageSize, total)
  191. var startSize int
  192. if pageSize <= 0 {
  193. pageSize = utils.PageSize20
  194. }
  195. if currentIndex <= 0 {
  196. currentIndex = 1
  197. }
  198. startSize = paging.StartIndex(currentIndex, pageSize)
  199. // wind基础指标
  200. var condition string
  201. var pars []interface{}
  202. condition += ` AND edb_info_type = ? AND source =? AND edb_type=?`
  203. pars = append(pars, 0, utils.DATA_SOURCE_WIND, 1)
  204. // 分类筛选
  205. classifyId, _ := this.GetInt("ClassifyId")
  206. edbInfoId, _ := this.GetInt("EdbInfoId")
  207. if classifyId > 0 {
  208. childClassify, e, _ := data.GetChildClassifyByClassifyId(classifyId)
  209. if e != nil && !utils.IsErrNoRow(e) {
  210. br.Msg = "获取失败"
  211. br.ErrMsg = "获取分类信息失败, GetEdbClassify,Err:" + e.Error()
  212. return
  213. }
  214. var classifyIds []int
  215. for _, v := range childClassify {
  216. classifyIds = append(classifyIds, v.ClassifyId)
  217. }
  218. condition += fmt.Sprintf(` AND classify_id IN (%s) `, utils.GetOrmInReplace(len(classifyIds)))
  219. pars = append(pars, classifyIds)
  220. }
  221. if edbInfoId > 0 {
  222. condition += ` AND edb_info_id = ?`
  223. pars = append(pars, edbInfoId)
  224. }
  225. // 获取当前账号的不可见指标
  226. obj := data_manage.EdbInfoNoPermissionAdmin{}
  227. confList, e := obj.GetAllListByAdminId(this.SysUser.AdminId)
  228. if e != nil {
  229. br.Msg = "获取失败"
  230. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + e.Error()
  231. return
  232. }
  233. noPermissionEdbInfoIdList := make([]int, 0)
  234. for _, v := range confList {
  235. noPermissionEdbInfoIdList = append(noPermissionEdbInfoIdList, v.EdbInfoId)
  236. }
  237. noPermissionEdbInfoIdNum := len(noPermissionEdbInfoIdList)
  238. if noPermissionEdbInfoIdNum > 0 {
  239. condition += ` AND edb_info_id NOT IN (` + utils.GetOrmInReplace(noPermissionEdbInfoIdNum) + `) `
  240. pars = append(pars, noPermissionEdbInfoIdList)
  241. }
  242. list := make([]*data_manage.WindEdbInfoList, 0)
  243. // 获取指标信息
  244. dataCount, edbList, e := data_manage.GetEdbInfoFilterList(condition, pars, startSize, pageSize)
  245. if e != nil {
  246. br.Msg = "获取失败"
  247. br.ErrMsg = "获取普通指标列表失败, Err:" + e.Error()
  248. return
  249. }
  250. page = paging.GetPaging(currentIndex, pageSize, int(dataCount))
  251. if len(edbList) > 0 {
  252. classifyMap := make(map[int]*data_manage.EdbClassify)
  253. targetClassifyList := make([]*data_manage.EdbClassifyItems, 0)
  254. if edbInfoId > 0 && classifyId == 0 {
  255. classifyId = edbList[0].ClassifyId
  256. }
  257. if classifyId > 0 { // todo 当没有传入分类ID时,如何处理 同一个分类ID,顶级分类是一样的
  258. targetClassify, err := data_manage.GetEdbClassifyById(classifyId)
  259. if err != nil {
  260. if utils.IsErrNoRow(err) {
  261. br.Msg = "当前分类不存在"
  262. return
  263. }
  264. br.Msg = "获取失败"
  265. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  266. return
  267. }
  268. targetClassifyList, err = data_manage.GetEdbClassifyByRootIdLevel(targetClassify.RootId, targetClassify.ClassifyType, "")
  269. if err != nil && !utils.IsErrNoRow(err) {
  270. br.Msg = "获取失败"
  271. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  272. return
  273. }
  274. classifyIds := make([]int, 0)
  275. for _, v := range edbList {
  276. classifyIds = append(classifyIds, v.ClassifyId)
  277. }
  278. //查询分类信息
  279. classifyList, err := data_manage.GetEdbClassifyByIdList(classifyIds)
  280. if err != nil {
  281. br.Msg = "获取失败"
  282. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  283. return
  284. }
  285. for _, v := range classifyList {
  286. classifyMap[v.ClassifyId] = v
  287. }
  288. }
  289. for _, v := range edbList {
  290. //查询目录
  291. targetClassify, ok := classifyMap[v.ClassifyId]
  292. if !ok {
  293. br.Msg = "当前分类不存在"
  294. return
  295. }
  296. classifyList, err, errMsg := data.GetFullClassifyByRootId(targetClassify, targetClassifyList)
  297. if err != nil {
  298. br.Msg = err.Error()
  299. br.ErrMsg = errMsg
  300. return
  301. }
  302. tmp := &data_manage.WindEdbInfoList{
  303. EdbInfoList: v,
  304. ClassifyList: classifyList,
  305. }
  306. list = append(list, tmp)
  307. }
  308. }
  309. resp := response.WindEdbInfoListResp{
  310. Paging: page,
  311. List: list,
  312. }
  313. br.Ret = 200
  314. br.Success = true
  315. br.Msg = "获取成功"
  316. br.Data = resp
  317. }