edb_public.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764
  1. package data_manage
  2. import (
  3. "encoding/json"
  4. "eta_gn/eta_api/controllers"
  5. "eta_gn/eta_api/models"
  6. "eta_gn/eta_api/models/data_manage"
  7. "eta_gn/eta_api/models/data_manage/request"
  8. "eta_gn/eta_api/services/data"
  9. dataApproveSerice "eta_gn/eta_api/services/data/data_approve"
  10. "eta_gn/eta_api/services/elastic"
  11. "eta_gn/eta_api/utils"
  12. "github.com/rdlucklib/rdluck_tools/paging"
  13. "strconv"
  14. "strings"
  15. )
  16. // EdbPublicController 公共指标
  17. type EdbPublicController struct {
  18. controllers.BaseAuthController
  19. }
  20. // RemoveCheck
  21. // @Title 删除检测接口
  22. // @Description 删除检测接口
  23. // @Param request body data_manage.ClassifyDeleteCheckReq true "type json string"
  24. // @Success 200 Ret=200 检测成功
  25. // @router /edb_public/remove/check [post]
  26. func (c *EdbPublicController) RemoveCheck() {
  27. // TODO
  28. br := new(models.BaseResponse).Init()
  29. defer func() {
  30. c.Data["json"] = br
  31. c.ServeJSON()
  32. }()
  33. var req data_manage.ClassifyDeleteCheckReq
  34. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  35. if err != nil {
  36. br.Msg = "参数解析异常!"
  37. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  38. return
  39. }
  40. if req.ClassifyId < 0 && req.EdbInfoId <= 0 {
  41. br.Msg = "参数错误"
  42. br.IsSendEmail = false
  43. return
  44. }
  45. deleteStatus, tipsMsg, tableList, err, errMsg := data.DeleteEdbPublicCheck(req.EdbInfoId, c.SysUser)
  46. if errMsg != `` {
  47. br.Msg = errMsg
  48. br.ErrMsg = errMsg
  49. if err != nil {
  50. br.ErrMsg = err.Error()
  51. } else {
  52. br.IsSendEmail = false
  53. }
  54. return
  55. }
  56. if c.Lang == "en" {
  57. if utils.ViperConfig.InConfig(tipsMsg) {
  58. tipsMsg = utils.ViperConfig.GetString(tipsMsg)
  59. }
  60. }
  61. //var deleteStatus int
  62. //var tipsMsg string
  63. ////删除公共分类
  64. //if req.ClassifyId > 0 && req.EdbInfoId == 0 {
  65. // //判断公共分类下,是否含有指标
  66. // count, err := data_manage.GetEdbInfoCountByClassifyId(req.ClassifyId)
  67. // if err != nil {
  68. // br.Msg = "删除失败"
  69. // br.ErrMsg = "公共分类下是否含有指标失败,Err:" + err.Error()
  70. // return
  71. // }
  72. //
  73. // if count > 0 {
  74. // deleteStatus = 1
  75. // tipsMsg = "若目录关联指标不可删除"
  76. // }
  77. //}
  78. //
  79. //if deleteStatus != 1 && req.EdbInfoId == 0 {
  80. // classifyCount, err := data_manage.GetClassifyCountByClassifyId(req.ClassifyId)
  81. // if err != nil && !utils.IsErrNoRow(err) {
  82. // br.Msg = "删除失败"
  83. // br.ErrMsg = "公共分类下是否含有指标失败,Err:" + err.Error()
  84. // return
  85. // }
  86. // if classifyCount > 0 {
  87. // deleteStatus = 2
  88. // tipsMsg = "确认删除当前目录及包含的子目录吗"
  89. // }
  90. //}
  91. //
  92. ////删除指标
  93. //if req.EdbInfoId > 0 {
  94. // //判断指标是否用于作图,如果用于作图,则不可删除
  95. // chartCount, err := data_manage.GetChartEdbMappingCount(req.EdbInfoId)
  96. // if err != nil && !utils.IsErrNoRow(err) {
  97. // br.Msg = "删除失败"
  98. // br.ErrMsg = "判断指标是否被用于作图失败,Err:" + err.Error()
  99. // return
  100. // }
  101. // if chartCount > 0 {
  102. // deleteStatus = 3
  103. // tipsMsg = "当前指标已用作画图,不可删除"
  104. // }
  105. // //判断指标是否用于计算
  106. // {
  107. // calculateCount, err := data_manage.GetEdbInfoCalculateMappingCount(req.EdbInfoId)
  108. // if err != nil && !utils.IsErrNoRow(err) {
  109. // br.Msg = "删除失败"
  110. // br.ErrMsg = "判断指标是否被用于计算失败,GetEdbInfoCalculateCount Err:" + err.Error()
  111. // return
  112. // }
  113. // if calculateCount > 0 {
  114. // deleteStatus = 4
  115. // tipsMsg = "当前指标已用作,指标运算,不可删除"
  116. // }
  117. // }
  118. //}
  119. resp := new(data_manage.ClassifyDeleteCheckResp)
  120. resp.DeleteStatus = deleteStatus
  121. resp.TipsMsg = tipsMsg
  122. resp.TableList = tableList
  123. br.Ret = 200
  124. br.Msg = "检测成功"
  125. br.Success = true
  126. br.Data = resp
  127. }
  128. // Remove
  129. // @Title 删除公共分类/指标
  130. // @Description 删除公共分类/指标接口
  131. // @Param request body data_manage.DeleteEdbClassifyReq true "type json string"
  132. // @Success 200 Ret=200 删除成功
  133. // @router /edb_public/remove [post]
  134. func (c *EdbPublicController) Remove() {
  135. // TODO
  136. br := new(models.BaseResponse).Init()
  137. defer func() {
  138. c.Data["json"] = br
  139. c.ServeJSON()
  140. }()
  141. sysUser := c.SysUser
  142. if sysUser == nil {
  143. br.Msg = "请登录"
  144. br.ErrMsg = "请登录,SysUser Is Empty"
  145. br.Ret = 408
  146. return
  147. }
  148. var req data_manage.DeleteEdbClassifyReq
  149. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  150. if err != nil {
  151. br.Msg = "参数解析异常!"
  152. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  153. return
  154. }
  155. if req.ClassifyId < 0 && req.EdbInfoId <= 0 {
  156. br.Msg = "参数错误"
  157. br.IsSendEmail = false
  158. return
  159. }
  160. nextItem, _, err, errMsg := data.Delete(req.ClassifyId, req.EdbInfoId, sysUser, string(c.Ctx.Input.RequestBody), c.Ctx.Input.URI())
  161. if errMsg != `` {
  162. br.Msg = errMsg
  163. br.ErrMsg = errMsg
  164. if err != nil {
  165. br.ErrMsg = err.Error()
  166. } else {
  167. br.IsSendEmail = false
  168. }
  169. return
  170. }
  171. resp := data_manage.AddEdbInfoResp{}
  172. if nextItem != nil {
  173. resp = data_manage.AddEdbInfoResp{
  174. EdbInfoId: nextItem.EdbInfoId,
  175. UniqueCode: nextItem.UniqueCode,
  176. }
  177. }
  178. br.Ret = 200
  179. br.Msg = "删除成功"
  180. br.Success = true
  181. br.IsAddLog = true
  182. br.Data = resp
  183. }
  184. // Save
  185. // @Title 单个指标设置公开
  186. // @Description 单个指标设置公开
  187. // @Param request body request.SetEdbInfoShareReq true "type json string"
  188. // @Success 200 {object} data_manage.EdbInfo
  189. // @router /edb_info/public/save [post]
  190. func (c *EdbPublicController) Save() {
  191. br := new(models.BaseResponse).Init()
  192. defer func() {
  193. c.Data["json"] = br
  194. c.ServeJSON()
  195. }()
  196. sysUser := c.SysUser
  197. if sysUser == nil {
  198. br.Msg = "请登录"
  199. br.ErrMsg = "请登录,SysUser Is Empty"
  200. br.Ret = 408
  201. return
  202. }
  203. var req request.SetEdbPublicReq
  204. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  205. if err != nil {
  206. br.Msg = "参数解析异常!"
  207. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  208. return
  209. }
  210. if len(req.EdbInfoList) <= 0 {
  211. br.Msg = `请选择指标`
  212. br.IsSendEmail = false
  213. }
  214. // 待处理的资产
  215. dataPublicItemList := make([]dataApproveSerice.SetDataPublicItem, 0)
  216. // 校验是否重复存在已公开、已提交的指标
  217. {
  218. edbInfoIdList := make([]int, 0)
  219. for _, item := range req.EdbInfoList {
  220. edbInfoIdList = append(edbInfoIdList, item.EdbInfoId)
  221. dataPublicItemList = append(dataPublicItemList, dataApproveSerice.SetDataPublicItem{
  222. DataId: item.EdbInfoId,
  223. ClassifyId: item.ClassifyId,
  224. })
  225. }
  226. list, err := data_manage.GetEdbInfoByIdList(edbInfoIdList)
  227. if err != nil {
  228. br.Msg = "保存失败!"
  229. br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
  230. return
  231. }
  232. for _, v := range list {
  233. if v.PublicStatus != utils.EdbPublicDefault {
  234. br.Msg = `选择指标中存在已经公开/提交审批的指标,请仅选择未公开指标!`
  235. br.IsSendEmail = false
  236. return
  237. }
  238. }
  239. }
  240. // 校验是否开启了审批流
  241. opening, e := dataApproveSerice.CheckOpenApprove(dataApproveSerice.DataTypeEdb)
  242. if e != nil {
  243. br.Msg = "操作失败"
  244. br.ErrMsg = "校验指标公开是否开启审批流失败, Err: " + e.Error()
  245. return
  246. }
  247. // 是否忽略审批
  248. var isIgnoreApprove bool
  249. {
  250. businessConf, e := models.GetBusinessConfByKey(models.IgnoreEdbApproveUserId)
  251. if e != nil {
  252. br.Msg = "获取失败"
  253. br.ErrMsg = "获取商家配置失败, Err: " + e.Error()
  254. return
  255. }
  256. ignoreEdbApproveUserIdList := strings.Split(businessConf.ConfVal, `,`)
  257. if utils.InArrayByStr(ignoreEdbApproveUserIdList, strconv.Itoa(c.SysUser.AdminId)) {
  258. isIgnoreApprove = true
  259. }
  260. }
  261. edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoList[0].EdbInfoId)
  262. if err != nil {
  263. br.Msg = "获取指标失败"
  264. br.ErrMsg = "获取指标失败:" + err.Error()
  265. return
  266. }
  267. title := edbInfo.EdbName
  268. if len(req.EdbInfoList) > 1 {
  269. title += `等指标`
  270. }
  271. title += `公开审批`
  272. // 没开启审批流、或者无需审批
  273. if !opening || isIgnoreApprove {
  274. err = dataApproveSerice.UpdatePublicByDataList(dataApproveSerice.DataTypeEdb, dataApproveSerice.DataApproveStatePass, dataPublicItemList)
  275. } else {
  276. _, err = dataApproveSerice.SubmitDataApprove(dataApproveSerice.DataTypeEdb, dataPublicItemList, title, strings.TrimSpace(req.Description), c.SysUser.AdminId, c.SysUser.RealName)
  277. if err != nil {
  278. br.Msg = "提交审批失败"
  279. br.ErrMsg = "提交审批失败, Err: " + err.Error()
  280. return
  281. }
  282. }
  283. if err != nil {
  284. br.Msg = "编辑失败"
  285. br.ErrMsg = "编辑失败,Err:" + err.Error()
  286. return
  287. }
  288. br.Ret = 200
  289. br.Success = true
  290. br.Msg = "保存成功"
  291. }
  292. // Cancel
  293. // @Title 撤销指标公开
  294. // @Description 撤销指标公开
  295. // @Param EdbInfoId query int true "指标id"
  296. // @Success 200 {object} data_manage.EdbInfo
  297. // @router /edb_info/public/cancel [post]
  298. func (c *EdbPublicController) Cancel() {
  299. br := new(models.BaseResponse).Init()
  300. defer func() {
  301. c.Data["json"] = br
  302. c.ServeJSON()
  303. }()
  304. // TODO 单个指标撤销的时候,需要校验状态,然后撤销
  305. sysUser := c.SysUser
  306. if sysUser == nil {
  307. br.Msg = "请登录"
  308. br.ErrMsg = "请登录,SysUser Is Empty"
  309. br.Ret = 408
  310. return
  311. }
  312. edbInfoId, _ := c.GetInt("EdbInfoId")
  313. if edbInfoId <= 0 {
  314. br.Msg = "参数错误"
  315. br.ErrMsg = "参数错误"
  316. return
  317. }
  318. var req request.SetEdbPublicReq
  319. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  320. if err != nil {
  321. br.Msg = "参数解析异常!"
  322. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  323. return
  324. }
  325. if len(req.EdbInfoList) <= 0 {
  326. br.Msg = `请选择指标`
  327. br.IsSendEmail = false
  328. }
  329. // 待处理的资产
  330. dataPublicItemList := make([]dataApproveSerice.SetDataPublicItem, 0)
  331. // 校验是否重复存在已公开、已提交的指标
  332. {
  333. edbInfoIdList := make([]int, 0)
  334. for _, item := range req.EdbInfoList {
  335. edbInfoIdList = append(edbInfoIdList, item.EdbInfoId)
  336. dataPublicItemList = append(dataPublicItemList, dataApproveSerice.SetDataPublicItem{
  337. DataId: item.EdbInfoId,
  338. ClassifyId: item.ClassifyId,
  339. })
  340. }
  341. list, err := data_manage.GetEdbInfoByIdList(edbInfoIdList)
  342. if err != nil {
  343. br.Msg = "保存失败!"
  344. br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
  345. return
  346. }
  347. for _, v := range list {
  348. if v.PublicStatus != utils.EdbPublicDefault {
  349. br.Msg = `选择指标中存在已经公开/提交审批的指标,请仅选择未公开指标!`
  350. br.IsSendEmail = false
  351. return
  352. }
  353. }
  354. }
  355. // 校验是否开启了审批流
  356. opening, e := dataApproveSerice.CheckOpenApprove(dataApproveSerice.DataTypeEdb)
  357. if e != nil {
  358. br.Msg = "操作失败"
  359. br.ErrMsg = "校验指标公开是否开启审批流失败, Err: " + e.Error()
  360. return
  361. }
  362. // 是否忽略审批
  363. var isIgnoreApprove bool
  364. {
  365. businessConf, e := models.GetBusinessConfByKey(models.IgnoreEdbApproveUserId)
  366. if e != nil {
  367. br.Msg = "获取失败"
  368. br.ErrMsg = "获取商家配置失败, Err: " + e.Error()
  369. return
  370. }
  371. ignoreEdbApproveUserIdList := strings.Split(businessConf.ConfVal, `,`)
  372. if utils.InArrayByStr(ignoreEdbApproveUserIdList, strconv.Itoa(c.SysUser.AdminId)) {
  373. isIgnoreApprove = true
  374. }
  375. }
  376. edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoList[0].EdbInfoId)
  377. if err != nil {
  378. br.Msg = "获取指标失败"
  379. br.ErrMsg = "获取指标失败:" + err.Error()
  380. return
  381. }
  382. title := edbInfo.EdbName
  383. if len(req.EdbInfoList) > 1 {
  384. title += `等指标`
  385. }
  386. title += `公开审批`
  387. // 没开启审批流、或者无需审批
  388. if !opening || isIgnoreApprove {
  389. err = dataApproveSerice.UpdatePublicByDataList(dataApproveSerice.DataTypeEdb, dataApproveSerice.DataApproveStatePass, dataPublicItemList)
  390. } else {
  391. _, err = dataApproveSerice.SubmitDataApprove(dataApproveSerice.DataTypeEdb, dataPublicItemList, title, strings.TrimSpace(req.Description), c.SysUser.AdminId, c.SysUser.RealName)
  392. if err != nil {
  393. br.Msg = "提交审批失败"
  394. br.ErrMsg = "提交审批失败, Err: " + err.Error()
  395. return
  396. }
  397. }
  398. if err != nil {
  399. br.Msg = "编辑失败"
  400. br.ErrMsg = "编辑失败,Err:" + err.Error()
  401. return
  402. }
  403. br.Ret = 200
  404. br.Success = true
  405. br.Msg = "保存成功"
  406. }
  407. // ListByEs
  408. // @Title 指标筛选接口
  409. // @Description 指标筛选接口
  410. // @Success 200 {object} data_manage.EdbInfoList
  411. // @Param request body request.SearchPublicEdbReq true "type json string"
  412. // @Success 200 {object} data_manage.EdbInfoFilterDataResp
  413. // @router /edb_info/public/list/es [post]
  414. func (c *EdbPublicController) ListByEs() {
  415. br := new(models.BaseResponse).Init()
  416. defer func() {
  417. c.Data["json"] = br
  418. c.ServeJSON()
  419. }()
  420. var req request.SearchPublicEdbReq
  421. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  422. if err != nil {
  423. br.Msg = "参数解析异常!"
  424. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  425. return
  426. }
  427. pageSize := req.PageSize
  428. currentIndex := req.CurrentIndex
  429. var total int64
  430. var startSize int
  431. if pageSize <= 0 {
  432. pageSize = utils.PageSize20
  433. }
  434. if currentIndex <= 0 {
  435. currentIndex = 1
  436. }
  437. startSize = paging.StartIndex(currentIndex, pageSize)
  438. // 获取查询参数
  439. keyword, searchEdbPublicList, sourceList, edbClassifyIdList, edbTypeList, edbInfoType, edbAuth, sortMap := getSearchPar(req)
  440. total, edbInfoList, err := elastic.SearchEdbInfoDataByPublic(keyword, startSize, pageSize, searchEdbPublicList, sourceList, edbClassifyIdList, edbTypeList, edbInfoType, edbAuth, c.SysUser.AdminId, sortMap)
  441. if err != nil {
  442. edbInfoList = make([]*data_manage.EdbInfoList, 0)
  443. }
  444. page := paging.GetPaging(currentIndex, pageSize, int(total))
  445. edbInfoListLen := len(edbInfoList)
  446. // 因为是ES查找的,所以需要重新查一下指标的信息,主要是为了把是否授权字段找出来
  447. if len(edbInfoList) > 0 {
  448. edbInfoIdList := make([]int, 0)
  449. for _, v := range edbInfoList {
  450. v.ConvertToResp()
  451. v.EdbNameAlias = v.EdbName
  452. v.HaveOperaAuth = true
  453. edbInfoIdList = append(edbInfoIdList, v.EdbInfoId)
  454. }
  455. tmpEdbList, err := data_manage.GetEdbInfoByIdList(edbInfoIdList)
  456. if err != nil {
  457. br.Msg = "获取失败"
  458. br.ErrMsg = "获取所有有权限的指标失败,Err:" + err.Error()
  459. return
  460. }
  461. edbInfoMap := make(map[int]*data_manage.EdbInfo)
  462. for _, v := range tmpEdbList {
  463. edbInfoMap[v.EdbInfoId] = v
  464. }
  465. for _, v := range edbInfoList {
  466. tmpEdbInfo, ok := edbInfoMap[v.EdbInfoId]
  467. if !ok {
  468. continue
  469. }
  470. v.IsJoinPermission = tmpEdbInfo.IsJoinPermission
  471. }
  472. }
  473. for i := 0; i < edbInfoListLen; i++ {
  474. for j := 0; j < edbInfoListLen; j++ {
  475. if (edbInfoList[i].EdbNameAlias == edbInfoList[j].EdbNameAlias) &&
  476. (edbInfoList[i].EdbInfoId != edbInfoList[j].EdbInfoId) &&
  477. !(strings.Contains(edbInfoList[i].EdbName, edbInfoList[i].SourceName)) {
  478. edbInfoList[i].EdbName = edbInfoList[i].EdbName + "(" + edbInfoList[i].SourceName + ")"
  479. }
  480. }
  481. }
  482. resp := data_manage.EdbInfoFilterDataResp{
  483. Paging: page,
  484. List: edbInfoList,
  485. }
  486. br.Ret = 200
  487. br.Success = true
  488. br.Msg = "获取成功"
  489. br.Data = resp
  490. }
  491. // AllListByEs
  492. // @Title 指标筛选接口
  493. // @Description 指标筛选接口
  494. // @Success 200 {object} data_manage.EdbInfoList
  495. // @Param request body request.SearchEdbInfoShareReq true "type json string"
  496. // @Success 200 {object} data_manage.EdbInfoFilterDataResp
  497. // @router /edb_info/public/list/es/all [post]
  498. func (c *EdbPublicController) AllListByEs() {
  499. br := new(models.BaseResponse).Init()
  500. defer func() {
  501. c.Data["json"] = br
  502. c.ServeJSON()
  503. }()
  504. var req request.AllSearchPublicEdbReq
  505. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  506. if err != nil {
  507. br.Msg = "参数解析异常!"
  508. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  509. return
  510. }
  511. // 选择所有指标,所以需要通过es获取数据
  512. edbInfoList := make([]*data_manage.EdbInfoList, 0)
  513. tmpEdbInfoList, err := getAllEdbInfoListByPublic(req, c.SysUser.AdminId)
  514. // 如果有过滤指标,那么就过滤吧
  515. if len(req.NoEdbIdList) > 0 {
  516. noEdbIdMap := make(map[int]bool)
  517. for _, v := range req.NoEdbIdList {
  518. noEdbIdMap[v] = true
  519. }
  520. for _, v := range tmpEdbInfoList {
  521. if _, ok := noEdbIdMap[v.EdbInfoId]; !ok {
  522. // 如果不在未选中的指标id列表中,那么就加入到选中的指标id列表
  523. edbInfoList = append(edbInfoList, v)
  524. }
  525. }
  526. } else {
  527. edbInfoList = tmpEdbInfoList
  528. }
  529. edbInfoListLen := len(edbInfoList)
  530. // 因为是ES查找的,所以需要重新查一下指标的信息,主要是为了把是否授权字段找出来
  531. if len(edbInfoList) > 0 {
  532. edbInfoIdList := make([]int, 0)
  533. for _, v := range edbInfoList {
  534. v.ConvertToResp()
  535. v.EdbNameAlias = v.EdbName
  536. v.HaveOperaAuth = true
  537. edbInfoIdList = append(edbInfoIdList, v.EdbInfoId)
  538. }
  539. tmpEdbList, err := data_manage.GetEdbInfoByIdList(edbInfoIdList)
  540. if err != nil {
  541. br.Msg = "获取失败"
  542. br.ErrMsg = "获取所有有权限的指标失败,Err:" + err.Error()
  543. return
  544. }
  545. edbInfoMap := make(map[int]*data_manage.EdbInfo)
  546. for _, v := range tmpEdbList {
  547. edbInfoMap[v.EdbInfoId] = v
  548. }
  549. for _, v := range edbInfoList {
  550. tmpEdbInfo, ok := edbInfoMap[v.EdbInfoId]
  551. if !ok {
  552. continue
  553. }
  554. v.IsJoinPermission = tmpEdbInfo.IsJoinPermission
  555. }
  556. }
  557. for i := 0; i < edbInfoListLen; i++ {
  558. for j := 0; j < edbInfoListLen; j++ {
  559. if (edbInfoList[i].EdbNameAlias == edbInfoList[j].EdbNameAlias) &&
  560. (edbInfoList[i].EdbInfoId != edbInfoList[j].EdbInfoId) &&
  561. !(strings.Contains(edbInfoList[i].EdbName, edbInfoList[i].SourceName)) {
  562. edbInfoList[i].EdbName = edbInfoList[i].EdbName + "(" + edbInfoList[i].SourceName + ")"
  563. }
  564. }
  565. }
  566. resp := data_manage.EdbInfoFilterDataResp{
  567. List: edbInfoList,
  568. }
  569. br.Ret = 200
  570. br.Success = true
  571. br.Msg = "获取成功"
  572. br.Data = resp
  573. }
  574. // getSearchPar
  575. // @Description: 获取查询参数
  576. // @author: Roc
  577. // @datetime 2024-12-05 14:13:25
  578. // @param req request.SearchPublicEdbReq
  579. // @return keyword string
  580. // @return searchEdbPublicList []int
  581. // @return sourceList []int
  582. // @return classifyIdList []int
  583. // @return edbTypeList []int
  584. // @return edbInfoType int
  585. // @return edbAuth int
  586. // @return sortMap map[string]string
  587. func getSearchPar(req request.SearchPublicEdbReq) (keyword string, searchEdbPublicList, sourceList, classifyIdList, edbTypeList []int, edbInfoType, edbAuth int, sortMap map[string]string) {
  588. keyword = req.Keyword
  589. keyword = strings.TrimSpace(keyword) //移除字符串首尾空格
  590. //指标来源
  591. sourceList = req.SourceList
  592. // 选择的分类
  593. classifyIdList = req.ClassifyIdList
  594. // 指标公开状态:1:未公开,2:已提交;3:已公开。可多选,默认是未公开
  595. edbPublicList := req.EdbPublicList
  596. if len(edbPublicList) <= 0 {
  597. edbPublicList = []int{1}
  598. }
  599. edbInfoType = 0 // 普通指标
  600. edbTypeList = []int{2} // 普通指标中的计算指标
  601. edbAuth = 1 // 选择范围是:只有我的指标
  602. searchEdbPublicList = make([]int, 0) // 0:全部,1:未公开,2:已提交;3:已公开
  603. if len(edbPublicList) > 0 && !utils.InArrayByInt(edbPublicList, 0) {
  604. // 不含全部
  605. for _, v := range edbPublicList {
  606. switch v {
  607. case 1: // 未公开
  608. searchEdbPublicList = append(searchEdbPublicList, utils.EdbPublicDefault)
  609. case 2: // 已提交
  610. searchEdbPublicList = append(searchEdbPublicList, utils.EdbPublicCommit, utils.EdbPublicReject)
  611. case 3: // 已公开
  612. searchEdbPublicList = append(searchEdbPublicList, utils.EdbPublicSuccess)
  613. }
  614. }
  615. } else {
  616. searchEdbPublicList = []int{0, 1, 2, 3}
  617. }
  618. sortMap = make(map[string]string)
  619. // 如果没有搜索关键词,则默认根据指标编码倒序排序
  620. if keyword == `` {
  621. sortMap["EdbInfoId"] = `desc`
  622. }
  623. return
  624. }
  625. // getAllEdbInfoListByPublic
  626. // @Description: 获取所有的指标列表
  627. // @author: Roc
  628. // @datetime 2024-12-04 15:43:14
  629. // @param req request.SetEdbChartPermissionReq
  630. // @param userId int
  631. // @return edbInfoIdList []*data_manage.EdbInfoList
  632. // @return err error
  633. func getAllEdbInfoListByPublic(req request.AllSearchPublicEdbReq, userId int) (edbInfoList []*data_manage.EdbInfoList, err error) {
  634. // 获取查询参数
  635. keyword, searchEdbPublicList, sourceList, edbClassifyIdList, edbTypeList, edbInfoType, edbAuth, sortMap := getSearchPar(req.SearchPublicEdbReq)
  636. _, edbInfoList, err = getAllEdbInfoDataByPublic(keyword, 1, searchEdbPublicList, sourceList, edbClassifyIdList, edbTypeList, edbInfoType, edbAuth, userId, sortMap)
  637. if err != nil {
  638. return
  639. }
  640. return
  641. }
  642. // getAllEdbInfoDataByShared
  643. // @Description: 获取所有的指标列表(设置公开的时候)
  644. // @author: Roc
  645. // @datetime 2024-12-04 15:27:53
  646. // @param keyword string
  647. // @param currPage int
  648. // @param edbShare int
  649. // @param sourceList []int
  650. // @param classifyIdList []int
  651. // @param edbTypeList []int
  652. // @param edbInfoType int
  653. // @param edbAuth int
  654. // @param sysUserId int
  655. // @param sortMap map[string]string
  656. // @return total int64
  657. // @return list []*data_manage.EdbInfoList
  658. // @return err error
  659. func getAllEdbInfoDataByPublic(keyword string, currPage int, searchEdbPublicList, sourceList, classifyIdList, edbTypeList []int, edbInfoType, edbAuth, sysUserId int, sortMap map[string]string) (total int64, list []*data_manage.EdbInfoList, err error) {
  660. // 每页获取数据的数量
  661. pageSize := 5000
  662. var startSize int
  663. if currPage <= 0 {
  664. currPage = 1
  665. }
  666. startSize = paging.StartIndex(currPage, pageSize)
  667. total, list, err = elastic.SearchEdbInfoDataByPublic(keyword, startSize, pageSize, searchEdbPublicList, sourceList, classifyIdList, edbTypeList, edbInfoType, edbAuth, sysUserId, sortMap)
  668. if err != nil {
  669. return
  670. }
  671. page := paging.GetPaging(currPage, pageSize, int(total))
  672. if !page.IsEnd {
  673. _, nextList, tmpErr := getAllEdbInfoDataByPublic(keyword, page.NextIndex, searchEdbPublicList, sourceList, classifyIdList, edbTypeList, edbInfoType, edbAuth, sysUserId, sortMap)
  674. if tmpErr != nil {
  675. err = tmpErr
  676. return
  677. }
  678. list = append(list, nextList...)
  679. }
  680. return
  681. }