public_edb.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789
  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. return
  214. }
  215. // 待处理的资产
  216. dataPublicItemList := make([]dataApproveSerice.SetDataPublicItem, 0)
  217. // 校验是否重复存在已公开、已提交的指标
  218. {
  219. edbInfoIdList := make([]int, 0)
  220. for _, item := range req.EdbInfoList {
  221. edbInfoIdList = append(edbInfoIdList, item.EdbInfoId)
  222. dataPublicItemList = append(dataPublicItemList, dataApproveSerice.SetDataPublicItem{
  223. DataId: item.EdbInfoId,
  224. ClassifyId: item.ClassifyId,
  225. })
  226. }
  227. list, err := data_manage.GetEdbInfoByIdList(edbInfoIdList)
  228. if err != nil {
  229. br.Msg = "保存失败!"
  230. br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
  231. return
  232. }
  233. for _, v := range list {
  234. if v.PublicStatus != utils.DataPublicDefault {
  235. br.Msg = `选择指标中存在已经公开/提交审批的指标,请仅选择未公开指标!`
  236. br.IsSendEmail = false
  237. return
  238. }
  239. }
  240. }
  241. // 校验是否开启了审批流
  242. opening, e := dataApproveSerice.CheckOpenApprove(utils.DataApproveTypeEdb)
  243. if e != nil {
  244. br.Msg = "操作失败"
  245. br.ErrMsg = "校验指标公开是否开启审批流失败, Err: " + e.Error()
  246. return
  247. }
  248. // 是否忽略审批
  249. var isIgnoreApprove bool
  250. {
  251. businessConf, e := models.GetBusinessConfByKey(models.IgnoreEdbApproveUserId)
  252. if e != nil {
  253. br.Msg = "获取失败"
  254. br.ErrMsg = "获取商家配置失败, Err: " + e.Error()
  255. return
  256. }
  257. ignoreEdbApproveUserIdList := strings.Split(businessConf.ConfVal, `,`)
  258. if utils.InArrayByStr(ignoreEdbApproveUserIdList, strconv.Itoa(c.SysUser.AdminId)) {
  259. isIgnoreApprove = true
  260. }
  261. }
  262. edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoList[0].EdbInfoId)
  263. if err != nil {
  264. br.Msg = "获取指标失败"
  265. br.ErrMsg = "获取指标失败:" + err.Error()
  266. return
  267. }
  268. title := edbInfo.EdbName
  269. if len(req.EdbInfoList) > 1 {
  270. title += `等指标`
  271. }
  272. title += `公开审批`
  273. // 没开启审批流、或者无需审批
  274. if !opening || isIgnoreApprove {
  275. err = dataApproveSerice.UpdatePublicByDataList(utils.DataApproveTypeEdb, dataApproveSerice.DataApproveStatePass, dataPublicItemList)
  276. } else {
  277. _, err = dataApproveSerice.SubmitDataApprove(utils.DataApproveTypeEdb, dataPublicItemList, title, strings.TrimSpace(req.Description), c.SysUser.AdminId, c.SysUser.RealName)
  278. if err != nil {
  279. br.Msg = "提交审批失败"
  280. br.ErrMsg = "提交审批失败, Err: " + err.Error()
  281. return
  282. }
  283. // 更新ES
  284. for _, dataPublicItem := range dataPublicItemList {
  285. data.AddOrEditEdbInfoToEs(dataPublicItem.DataId)
  286. }
  287. }
  288. if err != nil {
  289. br.Msg = "编辑失败"
  290. br.ErrMsg = "编辑失败,Err:" + err.Error()
  291. return
  292. }
  293. br.Ret = 200
  294. br.Success = true
  295. br.Msg = "保存成功"
  296. }
  297. // Cancel
  298. // @Title 撤销指标公开
  299. // @Description 撤销指标公开
  300. // @Param EdbInfoId query int true "指标id"
  301. // @Success 200 {object} data_manage.EdbInfo
  302. // @router /edb_info/public/cancel [post]
  303. func (c *EdbPublicController) Cancel() {
  304. br := new(models.BaseResponse).Init()
  305. defer func() {
  306. c.Data["json"] = br
  307. c.ServeJSON()
  308. }()
  309. // TODO 单个指标撤销的时候,需要校验状态,然后撤销
  310. sysUser := c.SysUser
  311. if sysUser == nil {
  312. br.Msg = "请登录"
  313. br.ErrMsg = "请登录,SysUser Is Empty"
  314. br.Ret = 408
  315. return
  316. }
  317. edbInfoId, _ := c.GetInt("EdbInfoId")
  318. if edbInfoId <= 0 {
  319. br.Msg = "参数错误"
  320. br.ErrMsg = "参数错误"
  321. return
  322. }
  323. var req request.SetEdbPublicReq
  324. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  325. if err != nil {
  326. br.Msg = "参数解析异常!"
  327. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  328. return
  329. }
  330. if len(req.EdbInfoList) <= 0 {
  331. br.Msg = `请选择指标`
  332. br.IsSendEmail = false
  333. return
  334. }
  335. // 待处理的资产
  336. dataPublicItemList := make([]dataApproveSerice.SetDataPublicItem, 0)
  337. // 校验是否重复存在已公开、已提交的指标
  338. {
  339. edbInfoIdList := make([]int, 0)
  340. for _, item := range req.EdbInfoList {
  341. edbInfoIdList = append(edbInfoIdList, item.EdbInfoId)
  342. dataPublicItemList = append(dataPublicItemList, dataApproveSerice.SetDataPublicItem{
  343. DataId: item.EdbInfoId,
  344. ClassifyId: item.ClassifyId,
  345. })
  346. }
  347. list, err := data_manage.GetEdbInfoByIdList(edbInfoIdList)
  348. if err != nil {
  349. br.Msg = "保存失败!"
  350. br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
  351. return
  352. }
  353. for _, v := range list {
  354. if v.PublicStatus != utils.DataPublicDefault {
  355. br.Msg = `选择指标中存在已经公开/提交审批的指标,请仅选择未公开指标!`
  356. br.IsSendEmail = false
  357. return
  358. }
  359. }
  360. }
  361. br.Ret = 200
  362. br.Success = true
  363. br.Msg = "保存成功"
  364. }
  365. // ListByEs
  366. // @Title 指标筛选接口
  367. // @Description 指标筛选接口
  368. // @Success 200 {object} data_manage.EdbInfoList
  369. // @Param request body request.SearchPublicEdbReq true "type json string"
  370. // @Success 200 {object} data_manage.EdbInfoFilterDataResp
  371. // @router /edb_info/public/list/es [post]
  372. func (c *EdbPublicController) ListByEs() {
  373. br := new(models.BaseResponse).Init()
  374. defer func() {
  375. c.Data["json"] = br
  376. c.ServeJSON()
  377. }()
  378. var req request.SearchPublicEdbReq
  379. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  380. if err != nil {
  381. br.Msg = "参数解析异常!"
  382. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  383. return
  384. }
  385. pageSize := req.PageSize
  386. currentIndex := req.CurrentIndex
  387. var total int64
  388. var startSize int
  389. if pageSize <= 0 {
  390. pageSize = utils.PageSize20
  391. }
  392. if currentIndex <= 0 {
  393. currentIndex = 1
  394. }
  395. startSize = paging.StartIndex(currentIndex, pageSize)
  396. // 获取查询参数
  397. keyword, searchEdbPublicList, sourceList, edbClassifyIdList, publicClassifyIdList, edbTypeList, edbInfoType, edbAuth, sortMap := data.GetSearchPar(req)
  398. total, edbInfoList, err := elastic.SearchEdbInfoDataByPublic(keyword, startSize, pageSize, searchEdbPublicList, sourceList, edbClassifyIdList, publicClassifyIdList, edbTypeList, edbInfoType, edbAuth, c.SysUser.AdminId, sortMap)
  399. if err != nil {
  400. edbInfoList = make([]*data_manage.EdbInfoList, 0)
  401. }
  402. page := paging.GetPaging(currentIndex, pageSize, int(total))
  403. edbInfoListLen := len(edbInfoList)
  404. // 因为是ES查找的,所以需要重新查一下指标的信息,主要是为了把是否授权字段找出来
  405. if len(edbInfoList) > 0 {
  406. // 图表map
  407. edbInfoMap := make(map[int]*data_manage.EdbInfo)
  408. classifyMap := make(map[int]*data_manage.EdbClassify)
  409. publicClassifyMap := make(map[int]*data_manage.EdbPublicClassify)
  410. // 指标id,分类id,公共分类id
  411. edbInfoIdList := make([]int, 0)
  412. tmpClassifyIdList := make([]int, 0)
  413. tmpPublicClassifyIdList := make([]int, 0)
  414. for _, v := range edbInfoList {
  415. v.ConvertToResp()
  416. v.EdbNameAlias = v.EdbName
  417. v.HaveOperaAuth = true
  418. edbInfoIdList = append(edbInfoIdList, v.EdbInfoId)
  419. }
  420. // 查找指标
  421. {
  422. tmpEdbList, err := data_manage.GetEdbInfoByIdList(edbInfoIdList)
  423. if err != nil {
  424. br.Msg = "获取失败"
  425. br.ErrMsg = "获取所有有权限的指标失败,Err:" + err.Error()
  426. return
  427. }
  428. for _, v := range tmpEdbList {
  429. edbInfoMap[v.EdbInfoId] = v
  430. tmpClassifyIdList = append(tmpClassifyIdList, v.ClassifyId)
  431. tmpPublicClassifyIdList = append(tmpPublicClassifyIdList, v.EdbPublicClassifyId)
  432. }
  433. }
  434. // 指标分类
  435. {
  436. tmpList, err := data_manage.GetEdbClassifyByIdList(tmpClassifyIdList)
  437. if err != nil {
  438. br.Msg = "获取失败"
  439. br.ErrMsg = "获取所有有权限的图表分类失败,Err:" + err.Error()
  440. return
  441. }
  442. for _, v := range tmpList {
  443. classifyMap[v.ClassifyId] = v
  444. }
  445. }
  446. // 公共分类
  447. {
  448. obj := data_manage.EdbPublicClassify{}
  449. tmpList, err := obj.GetEdbClassifyByIdList(tmpPublicClassifyIdList)
  450. if err != nil {
  451. br.Msg = "获取失败"
  452. br.ErrMsg = "获取所有有权限的公共分类失败,Err:" + err.Error()
  453. return
  454. }
  455. for _, v := range tmpList {
  456. publicClassifyMap[v.EdbPublicClassifyId] = v
  457. }
  458. }
  459. // 数据重新赋值
  460. for _, v := range edbInfoList {
  461. if tmpEdbInfo, ok := edbInfoMap[v.EdbInfoId]; ok {
  462. v.IsJoinPermission = tmpEdbInfo.IsJoinPermission
  463. }
  464. // 普通分类
  465. if classifyItem, ok := classifyMap[v.ClassifyId]; ok {
  466. v.ClassifyNamePath = classifyItem.ClassifyNamePath
  467. }
  468. // 公共分类
  469. if classifyItem, ok := publicClassifyMap[v.EdbPublicClassifyId]; ok {
  470. v.PublicClassifyNamePath = classifyItem.EdbPublicClassifyNamePath
  471. }
  472. }
  473. }
  474. for i := 0; i < edbInfoListLen; i++ {
  475. for j := 0; j < edbInfoListLen; j++ {
  476. if (edbInfoList[i].EdbNameAlias == edbInfoList[j].EdbNameAlias) &&
  477. (edbInfoList[i].EdbInfoId != edbInfoList[j].EdbInfoId) &&
  478. !(strings.Contains(edbInfoList[i].EdbName, edbInfoList[i].SourceName)) {
  479. edbInfoList[i].EdbName = edbInfoList[i].EdbName + "(" + edbInfoList[i].SourceName + ")"
  480. }
  481. }
  482. }
  483. resp := data_manage.EdbInfoFilterDataResp{
  484. Paging: page,
  485. List: edbInfoList,
  486. }
  487. br.Ret = 200
  488. br.Success = true
  489. br.Msg = "获取成功"
  490. br.Data = resp
  491. }
  492. // AllListByEs
  493. // @Title 指标筛选接口
  494. // @Description 指标筛选接口
  495. // @Success 200 {object} data_manage.EdbInfoList
  496. // @Param request body request.SearchEdbInfoShareReq true "type json string"
  497. // @Success 200 {object} data_manage.EdbInfoFilterDataResp
  498. // @router /edb_info/public/list/es/all [post]
  499. func (c *EdbPublicController) AllListByEs() {
  500. br := new(models.BaseResponse).Init()
  501. defer func() {
  502. c.Data["json"] = br
  503. c.ServeJSON()
  504. }()
  505. var req request.AllSearchPublicEdbReq
  506. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  507. if err != nil {
  508. br.Msg = "参数解析异常!"
  509. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  510. return
  511. }
  512. // 选择所有指标,所以需要通过es获取数据
  513. // 选中的指标id列表
  514. edbInfoList := make([]*data_manage.EdbInfoList, 0)
  515. // 选择所有指标,所以需要通过es获取数据
  516. if req.IsSelectAll {
  517. tmpEdbInfoList, err := data.GetAllEdbInfoListBySearchPublicEdbReq(req.SearchPublicEdbReq, c.SysUser.AdminId)
  518. if err != nil {
  519. br.Msg = "获取指标列表失败!"
  520. br.ErrMsg = "获取指标列表失败,Err:" + err.Error()
  521. return
  522. }
  523. // 如果有过滤指标,那么就过滤吧
  524. if len(req.NoEdbIdList) > 0 {
  525. noEdbIdMap := make(map[int]bool)
  526. for _, v := range req.NoEdbIdList {
  527. noEdbIdMap[v] = true
  528. }
  529. for _, v := range tmpEdbInfoList {
  530. if _, ok := noEdbIdMap[v.EdbInfoId]; !ok {
  531. // 如果不在未选中的指标id列表中,那么就加入到选中的指标id列表
  532. edbInfoList = append(edbInfoList, v)
  533. }
  534. }
  535. } else {
  536. edbInfoList = tmpEdbInfoList
  537. }
  538. // 因为是ES查找的,所以需要重新查一下指标的信息,主要是为了把是否授权字段找出来
  539. if len(edbInfoList) > 0 {
  540. edbInfoIdList := make([]int, 0)
  541. for _, v := range edbInfoList {
  542. v.ConvertToResp()
  543. v.EdbNameAlias = v.EdbName
  544. v.HaveOperaAuth = true
  545. edbInfoIdList = append(edbInfoIdList, v.EdbInfoId)
  546. }
  547. tmpEdbList, err := data_manage.GetEdbInfoByIdList(edbInfoIdList)
  548. if err != nil {
  549. br.Msg = "获取失败"
  550. br.ErrMsg = "获取所有有权限的指标失败,Err:" + err.Error()
  551. return
  552. }
  553. edbInfoMap := make(map[int]*data_manage.EdbInfo)
  554. for _, v := range tmpEdbList {
  555. edbInfoMap[v.EdbInfoId] = v
  556. }
  557. for _, v := range edbInfoList {
  558. tmpEdbInfo, ok := edbInfoMap[v.EdbInfoId]
  559. if !ok {
  560. continue
  561. }
  562. v.IsJoinPermission = tmpEdbInfo.IsJoinPermission
  563. }
  564. }
  565. } else {
  566. // 因为是ES查找的,所以需要重新查一下指标的信息,主要是为了把是否授权字段找出来
  567. if len(req.EdbIdList) > 0 {
  568. edbInfoList, err = data_manage.GetEdbInfoListByCond(` AND edb_info_id in (?) `, []interface{}{req.EdbIdList})
  569. if err != nil {
  570. br.Msg = "获取失败"
  571. br.ErrMsg = "获取所有有权限的指标失败,Err:" + err.Error()
  572. return
  573. }
  574. }
  575. }
  576. edbInfoListLen := len(edbInfoList)
  577. for i := 0; i < edbInfoListLen; i++ {
  578. for j := 0; j < edbInfoListLen; j++ {
  579. if (edbInfoList[i].EdbNameAlias == edbInfoList[j].EdbNameAlias) &&
  580. (edbInfoList[i].EdbInfoId != edbInfoList[j].EdbInfoId) &&
  581. !(strings.Contains(edbInfoList[i].EdbName, edbInfoList[i].SourceName)) {
  582. edbInfoList[i].EdbName = edbInfoList[i].EdbName + "(" + edbInfoList[i].SourceName + ")"
  583. }
  584. }
  585. }
  586. resp := data_manage.EdbInfoFilterDataResp{
  587. List: edbInfoList,
  588. }
  589. br.Ret = 200
  590. br.Success = true
  591. br.Msg = "获取成功"
  592. br.Data = resp
  593. }
  594. // BatchMoveEdb
  595. // @Title 指标批量移动接口
  596. // @Description 指标批量移动接口
  597. // @Param request body request.MoveEdbClassifyReq true "type json string"
  598. // @Success Ret=200 移动成功
  599. // @router /edb_info/public/batch_move [post]
  600. func (c *EdbPublicController) BatchMoveEdb() {
  601. br := new(models.BaseResponse).Init()
  602. defer func() {
  603. c.Data["json"] = br
  604. c.ServeJSON()
  605. }()
  606. var req request.MoveEdbClassifyReq
  607. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  608. if err != nil {
  609. br.Msg = "参数解析异常!"
  610. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  611. return
  612. }
  613. if req.NewClassifyId <= 0 {
  614. br.Msg = `请选择要转移的新分类`
  615. br.IsSendEmail = false
  616. return
  617. }
  618. // 校验分类
  619. obj := data_manage.EdbPublicClassify{}
  620. publicClassifyItem, err := obj.GetEdbClassifyById(req.NewClassifyId)
  621. if err != nil {
  622. br.Msg = "获取公共分类失败!"
  623. br.ErrMsg = "获取公共分类失败!" + err.Error()
  624. return
  625. }
  626. if publicClassifyItem.EdbPublicClassifyId <= 0 {
  627. br.Msg = "公共分类不存在!"
  628. br.ErrMsg = "公共分类不存在!"
  629. return
  630. }
  631. // 只是取公开
  632. req.SearchPublicEdbReq.EdbPublicList = []int{3}
  633. edbInfoIdList := make([]int, 0)
  634. if req.IsSelectAll {
  635. // 获取指标
  636. edbInfoList, err := data.GetAllEdbInfoListBySearchPublicEdbReq(req.SearchPublicEdbReq, c.SysUser.AdminId)
  637. if err != nil {
  638. br.Msg = "获取指标列表失败!"
  639. br.ErrMsg = "获取指标列表失败,Err:" + err.Error()
  640. return
  641. }
  642. // 如果有过滤指标,那么就过滤吧
  643. if len(req.NoEdbIdList) > 0 {
  644. noEdbIdMap := make(map[int]bool)
  645. for _, v := range req.NoEdbIdList {
  646. noEdbIdMap[v] = true
  647. }
  648. for _, edbInfo := range edbInfoList {
  649. if _, ok := noEdbIdMap[edbInfo.EdbInfoId]; !ok {
  650. if edbInfo.PublicStatus != utils.DataPublicSuccess {
  651. br.Msg = `存在未公开的指标:` + edbInfo.EdbName
  652. br.IsSendEmail = false
  653. return
  654. }
  655. // 如果不在未选中的指标id列表中,那么就加入到选中的指标id列表
  656. edbInfoIdList = append(edbInfoIdList, edbInfo.EdbInfoId)
  657. }
  658. }
  659. } else {
  660. for _, edbInfo := range edbInfoList {
  661. if edbInfo.PublicStatus != utils.DataPublicSuccess {
  662. br.Msg = `存在未公开的指标:` + edbInfo.EdbName
  663. br.IsSendEmail = false
  664. return
  665. }
  666. edbInfoIdList = append(edbInfoIdList, edbInfo.EdbInfoId)
  667. }
  668. }
  669. } else {
  670. edbInfoList, err := data_manage.GetEdbInfoListByCond(` AND edb_info_id in (?) `, []interface{}{req.EdbIdList})
  671. if err != nil {
  672. br.Msg = "获取失败"
  673. br.ErrMsg = "获取所有有权限的指标失败,Err:" + err.Error()
  674. return
  675. }
  676. for _, v := range edbInfoList {
  677. if v.PublicStatus != utils.DataPublicSuccess {
  678. br.Msg = `存在未公开的指标:` + v.EdbName
  679. br.IsSendEmail = false
  680. return
  681. }
  682. }
  683. edbInfoIdList = req.EdbIdList
  684. }
  685. num := len(edbInfoIdList)
  686. if num <= 0 {
  687. br.Msg = `请选择要移动的指标!`
  688. br.IsSendEmail = false
  689. return
  690. }
  691. if num > 100 {
  692. br.Msg = `最多只能选择100条指标!`
  693. br.IsSendEmail = false
  694. return
  695. }
  696. // 开始批量修改指标分类
  697. if len(edbInfoIdList) > 0 {
  698. err = data_manage.UpdatePublicClassifyIdByEdbInfoIdList(edbInfoIdList, req.NewClassifyId)
  699. if err != nil {
  700. br.Msg = `指标移动失败!`
  701. br.ErrMsg = `指标移动失败,ERR:` + err.Error()
  702. return
  703. }
  704. // 还得修改ES呢
  705. for _, v := range edbInfoIdList {
  706. data.AddOrEditEdbInfoToEs(v)
  707. }
  708. }
  709. br.Ret = 200
  710. br.Success = true
  711. br.Msg = "获取成功"
  712. }