public_edb.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  1. package data_manage
  2. import (
  3. "encoding/json"
  4. "eta_gn/eta_api/cache"
  5. "eta_gn/eta_api/controllers"
  6. "eta_gn/eta_api/models"
  7. "eta_gn/eta_api/models/data_manage"
  8. "eta_gn/eta_api/models/data_manage/data_approve"
  9. "eta_gn/eta_api/models/data_manage/request"
  10. "eta_gn/eta_api/models/system"
  11. "eta_gn/eta_api/services/data"
  12. dataApproveSerice "eta_gn/eta_api/services/data/data_approve"
  13. "eta_gn/eta_api/services/elastic"
  14. "eta_gn/eta_api/utils"
  15. "fmt"
  16. "github.com/rdlucklib/rdluck_tools/paging"
  17. "strconv"
  18. "strings"
  19. )
  20. // EdbPublicController 公共指标
  21. type EdbPublicController struct {
  22. controllers.BaseAuthController
  23. }
  24. // Save
  25. // @Title 单个指标设置公开
  26. // @Description 单个指标设置公开
  27. // @Param request body request.SetEdbInfoShareReq true "type json string"
  28. // @Success 200 {object} data_manage.EdbInfo
  29. // @router /edb_info/public/save [post]
  30. func (c *EdbPublicController) Save() {
  31. br := new(models.BaseResponse).Init()
  32. defer func() {
  33. c.Data["json"] = br
  34. c.ServeJSON()
  35. }()
  36. sysUser := c.SysUser
  37. if sysUser == nil {
  38. br.Msg = "请登录"
  39. br.ErrMsg = "请登录,SysUser Is Empty"
  40. br.Ret = 408
  41. return
  42. }
  43. var req request.SetEdbPublicReq
  44. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  45. if err != nil {
  46. br.Msg = "参数解析异常!"
  47. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  48. return
  49. }
  50. if len(req.EdbInfoList) <= 0 {
  51. br.Msg = `请选择指标`
  52. br.IsSendEmail = false
  53. return
  54. }
  55. // 待处理的资产
  56. dataPublicItemList := make([]dataApproveSerice.SetDataPublicItem, 0)
  57. // 校验是否重复存在已公开、已提交的指标
  58. {
  59. edbInfoIdList := make([]int, 0)
  60. for _, item := range req.EdbInfoList {
  61. edbInfoIdList = append(edbInfoIdList, item.EdbInfoId)
  62. dataPublicItemList = append(dataPublicItemList, dataApproveSerice.SetDataPublicItem{
  63. DataId: item.EdbInfoId,
  64. ClassifyId: item.ClassifyId,
  65. })
  66. }
  67. list, err := data_manage.GetEdbInfoByIdList(edbInfoIdList)
  68. if err != nil {
  69. br.Msg = "保存失败!"
  70. br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
  71. return
  72. }
  73. for _, v := range list {
  74. if v.PublicStatus != utils.DataPublicDefault {
  75. br.Msg = `选择指标中存在已经公开/提交审批的指标,请仅选择未公开指标!`
  76. br.IsSendEmail = false
  77. return
  78. }
  79. }
  80. }
  81. // 校验是否开启了审批流
  82. opening, e := dataApproveSerice.CheckOpenApprove(utils.DataApproveTypeEdb)
  83. if e != nil {
  84. br.Msg = "操作失败"
  85. br.ErrMsg = "校验指标公开是否开启审批流失败, Err: " + e.Error()
  86. return
  87. }
  88. // 是否忽略审批
  89. var isIgnoreApprove bool
  90. {
  91. businessConf, e := models.GetBusinessConfByKey(models.IgnoreEdbApproveUserId)
  92. if e != nil {
  93. br.Msg = "获取失败"
  94. br.ErrMsg = "获取商家配置失败, Err: " + e.Error()
  95. return
  96. }
  97. ignoreEdbApproveUserIdList := strings.Split(businessConf.ConfVal, `,`)
  98. if utils.InArrayByStr(ignoreEdbApproveUserIdList, strconv.Itoa(c.SysUser.AdminId)) {
  99. isIgnoreApprove = true
  100. }
  101. }
  102. edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoList[0].EdbInfoId)
  103. if err != nil {
  104. br.Msg = "获取指标失败"
  105. br.ErrMsg = "获取指标失败:" + err.Error()
  106. return
  107. }
  108. title := edbInfo.EdbName
  109. if len(req.EdbInfoList) > 1 {
  110. title += `等指标`
  111. }
  112. title += `公开审批`
  113. // 没开启审批流、或者无需审批
  114. if !opening || isIgnoreApprove {
  115. err = dataApproveSerice.UpdatePublicByDataList(utils.DataApproveTypeEdb, dataApproveSerice.DataApproveStatePass, dataPublicItemList)
  116. } else {
  117. _, err = dataApproveSerice.SubmitDataApprove(utils.DataApproveTypeEdb, dataPublicItemList, title, strings.TrimSpace(req.Description), c.SysUser.AdminId, c.SysUser.RealName)
  118. if err != nil {
  119. br.Msg = "提交审批失败"
  120. br.ErrMsg = "提交审批失败, Err: " + err.Error()
  121. return
  122. }
  123. // 更新ES
  124. for _, dataPublicItem := range dataPublicItemList {
  125. data.AddOrEditEdbInfoToEs(dataPublicItem.DataId)
  126. }
  127. }
  128. if err != nil {
  129. br.Msg = "编辑失败"
  130. br.ErrMsg = "编辑失败,Err:" + err.Error()
  131. return
  132. }
  133. br.Ret = 200
  134. br.Success = true
  135. br.Msg = "保存成功"
  136. }
  137. // Cancel
  138. // @Title 撤销指标公开
  139. // @Description 撤销指标公开
  140. // @Param EdbInfoId query int true "指标id"
  141. // @Success 200 {object} data_manage.EdbInfo
  142. // @router /edb_info/public/cancel [post]
  143. func (c *EdbPublicController) Cancel() {
  144. br := new(models.BaseResponse).Init()
  145. defer func() {
  146. c.Data["json"] = br
  147. c.ServeJSON()
  148. }()
  149. sysUser := c.SysUser
  150. if sysUser == nil {
  151. br.Msg = "请登录"
  152. br.ErrMsg = "请登录,SysUser Is Empty"
  153. br.Ret = 408
  154. return
  155. }
  156. edbInfoId, _ := c.GetInt("EdbInfoId")
  157. if edbInfoId <= 0 {
  158. br.Msg = "参数错误"
  159. br.ErrMsg = "参数错误"
  160. return
  161. }
  162. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  163. if err != nil {
  164. br.Msg = "保存失败!"
  165. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  166. return
  167. }
  168. // 判断指标公共状态
  169. if !utils.InArrayByInt([]int{utils.DataPublicSuccess, utils.DataPublicReject, utils.DataPublicCommit}, edbInfo.PublicStatus) {
  170. br.Msg = "保存失败,指标公开状态异常!"
  171. br.ErrMsg = "保存失败,指标公开状态异常,public_status:" + fmt.Sprint(edbInfo.PublicStatus)
  172. return
  173. }
  174. // 如果公开状态是:已驳回、已提交,那么直接去撤销审批单
  175. if utils.InArrayByInt([]int{utils.DataPublicReject, utils.DataPublicCommit}, edbInfo.PublicStatus) {
  176. obj := data_approve.DataApproveRelation{}
  177. dataApproveId, err := obj.GetDataApproveIdByDataId(edbInfoId, utils.DataApproveTypeEdb)
  178. if err != nil {
  179. br.Msg = "保存失败!"
  180. br.ErrMsg = "获取审批单失败,Err:" + err.Error()
  181. return
  182. }
  183. // 撤销审批
  184. msg, e := dataApproveSerice.DataApproveCancel(dataApproveId, sysUser.AdminId, sysUser.RealName)
  185. if e != nil {
  186. if msg != "" {
  187. br.Msg = msg
  188. } else {
  189. br.Msg = "操作失败"
  190. }
  191. br.ErrMsg = "撤销审批失败, Err: " + e.Error()
  192. return
  193. }
  194. }
  195. checkUserIdList := []int{sysUser.AdminId}
  196. noReferenced, otherUserIdList, err, tips := data.CheckEdbReferencedByOthers(edbInfo.EdbInfoType, []int{edbInfo.EdbInfoId}, checkUserIdList)
  197. if err != nil {
  198. br.Msg = "保存失败"
  199. if tips != "" {
  200. br.Msg = tips
  201. }
  202. br.ErrMsg = "撤销指标公开失败,查找指标的关联用户失败,Err:" + err.Error()
  203. return
  204. }
  205. if !noReferenced {
  206. userNameStr := ``
  207. if len(otherUserIdList) > 0 {
  208. userNameList := make([]string, 0)
  209. userList, err := system.GetAdminListByIdList(otherUserIdList)
  210. if err != nil {
  211. br.Msg = "保存失败"
  212. if tips != "" {
  213. br.Msg = tips
  214. }
  215. br.ErrMsg = "撤销指标公开失败,查找用户信息失败,Err:" + err.Error()
  216. return
  217. }
  218. for _, userInfo := range userList {
  219. userNameList = append(userNameList, userInfo.RealName)
  220. }
  221. userNameStr = strings.Join(userNameList, ",")
  222. }
  223. msg := `指标被其他用户使用,无法撤销公开`
  224. if userNameStr != "" {
  225. msg = fmt.Sprintf(`指标被用户%s使用,无法撤销公开`, userNameStr)
  226. }
  227. if tips != "" {
  228. msg = fmt.Sprintf(`%s,用户为:%s,无法撤销公开`, tips, userNameStr)
  229. }
  230. br.Msg = msg
  231. br.ErrMsg = "指标被其他用户共享,无法撤销公开,EdbInfoId:" + strconv.Itoa(edbInfo.EdbInfoId)
  232. br.IsSendEmail = false
  233. return
  234. }
  235. edbInfo.PublicStatus = utils.DataPublicDefault
  236. edbInfo.EdbPublicClassifyId = 0
  237. err = edbInfo.Update([]string{"PublicStatus", "EdbPublicClassifyId"})
  238. if err != nil {
  239. br.Msg = "保存失败"
  240. br.ErrMsg = "取消指标公共失败,Err:" + err.Error()
  241. return
  242. }
  243. // 修改ES数据
  244. data.AddOrEditEdbInfoToEs(edbInfo.EdbInfoId)
  245. // 指标收藏操作处理
  246. go cache.AddDataCollectHandler(edbInfo.EdbInfoId, utils.DataCollectTypeEdb)
  247. br.Ret = 200
  248. br.Success = true
  249. br.Msg = "操作成功"
  250. }
  251. // ListByEs
  252. // @Title 指标筛选接口
  253. // @Description 指标筛选接口
  254. // @Success 200 {object} data_manage.EdbInfoList
  255. // @Param request body request.SearchPublicEdbReq true "type json string"
  256. // @Success 200 {object} data_manage.EdbInfoFilterDataResp
  257. // @router /edb_info/public/list/es [post]
  258. func (c *EdbPublicController) ListByEs() {
  259. br := new(models.BaseResponse).Init()
  260. defer func() {
  261. c.Data["json"] = br
  262. c.ServeJSON()
  263. }()
  264. var req request.SearchPublicEdbReq
  265. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  266. if err != nil {
  267. br.Msg = "参数解析异常!"
  268. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  269. return
  270. }
  271. pageSize := req.PageSize
  272. currentIndex := req.CurrentIndex
  273. var total int64
  274. var startSize int
  275. if pageSize <= 0 {
  276. pageSize = utils.PageSize20
  277. }
  278. if currentIndex <= 0 {
  279. currentIndex = 1
  280. }
  281. startSize = paging.StartIndex(currentIndex, pageSize)
  282. // 获取查询参数
  283. keyword, searchEdbPublicList, sourceList, edbClassifyIdList, publicClassifyIdList, edbTypeList, edbInfoType, edbAuth, sortMap := data.GetSearchPar(req)
  284. total, edbInfoList, err := elastic.SearchEdbInfoDataByPublic(keyword, startSize, pageSize, searchEdbPublicList, sourceList, edbClassifyIdList, publicClassifyIdList, edbTypeList, edbInfoType, edbAuth, c.SysUser.AdminId, sortMap)
  285. if err != nil {
  286. edbInfoList = make([]*data_manage.EdbInfoList, 0)
  287. }
  288. page := paging.GetPaging(currentIndex, pageSize, int(total))
  289. edbInfoListLen := len(edbInfoList)
  290. // 因为是ES查找的,所以需要重新查一下指标的信息,主要是为了把是否授权字段找出来
  291. if len(edbInfoList) > 0 {
  292. // 图表map
  293. edbInfoMap := make(map[int]*data_manage.EdbInfo)
  294. classifyMap := make(map[int]*data_manage.EdbClassify)
  295. publicClassifyMap := make(map[int]*data_manage.EdbPublicClassify)
  296. // 指标id,分类id,公共分类id
  297. edbInfoIdList := make([]int, 0)
  298. tmpClassifyIdList := make([]int, 0)
  299. tmpPublicClassifyIdList := make([]int, 0)
  300. for _, v := range edbInfoList {
  301. v.ConvertToResp()
  302. v.EdbNameAlias = v.EdbName
  303. v.HaveOperaAuth = true
  304. edbInfoIdList = append(edbInfoIdList, v.EdbInfoId)
  305. }
  306. // 查找指标
  307. {
  308. tmpEdbList, err := data_manage.GetEdbInfoByIdList(edbInfoIdList)
  309. if err != nil {
  310. br.Msg = "获取失败"
  311. br.ErrMsg = "获取所有有权限的指标失败,Err:" + err.Error()
  312. return
  313. }
  314. for _, v := range tmpEdbList {
  315. edbInfoMap[v.EdbInfoId] = v
  316. tmpClassifyIdList = append(tmpClassifyIdList, v.ClassifyId)
  317. tmpPublicClassifyIdList = append(tmpPublicClassifyIdList, v.EdbPublicClassifyId)
  318. }
  319. }
  320. // 指标分类
  321. {
  322. tmpList, err := data_manage.GetEdbClassifyByIdList(tmpClassifyIdList)
  323. if err != nil {
  324. br.Msg = "获取失败"
  325. br.ErrMsg = "获取所有有权限的图表分类失败,Err:" + err.Error()
  326. return
  327. }
  328. for _, v := range tmpList {
  329. classifyMap[v.ClassifyId] = v
  330. }
  331. }
  332. // 公共分类
  333. {
  334. obj := data_manage.EdbPublicClassify{}
  335. tmpList, err := obj.GetEdbClassifyByIdList(tmpPublicClassifyIdList)
  336. if err != nil {
  337. br.Msg = "获取失败"
  338. br.ErrMsg = "获取所有有权限的公共分类失败,Err:" + err.Error()
  339. return
  340. }
  341. for _, v := range tmpList {
  342. publicClassifyMap[v.EdbPublicClassifyId] = v
  343. }
  344. }
  345. // 数据重新赋值
  346. for _, v := range edbInfoList {
  347. if tmpEdbInfo, ok := edbInfoMap[v.EdbInfoId]; ok {
  348. v.IsJoinPermission = tmpEdbInfo.IsJoinPermission
  349. }
  350. // 普通分类
  351. if classifyItem, ok := classifyMap[v.ClassifyId]; ok {
  352. v.ClassifyNamePath = classifyItem.ClassifyNamePath
  353. }
  354. // 公共分类
  355. if classifyItem, ok := publicClassifyMap[v.EdbPublicClassifyId]; ok {
  356. v.PublicClassifyNamePath = classifyItem.EdbPublicClassifyNamePath
  357. }
  358. }
  359. }
  360. for i := 0; i < edbInfoListLen; i++ {
  361. for j := 0; j < edbInfoListLen; j++ {
  362. if (edbInfoList[i].EdbNameAlias == edbInfoList[j].EdbNameAlias) &&
  363. (edbInfoList[i].EdbInfoId != edbInfoList[j].EdbInfoId) &&
  364. !(strings.Contains(edbInfoList[i].EdbName, edbInfoList[i].SourceName)) {
  365. edbInfoList[i].EdbName = edbInfoList[i].EdbName + "(" + edbInfoList[i].SourceName + ")"
  366. }
  367. }
  368. }
  369. resp := data_manage.EdbInfoFilterDataResp{
  370. Paging: page,
  371. List: edbInfoList,
  372. }
  373. br.Ret = 200
  374. br.Success = true
  375. br.Msg = "获取成功"
  376. br.Data = resp
  377. }
  378. // AllListByEs
  379. // @Title 指标筛选接口
  380. // @Description 指标筛选接口
  381. // @Success 200 {object} data_manage.EdbInfoList
  382. // @Param request body request.SearchEdbInfoShareReq true "type json string"
  383. // @Success 200 {object} data_manage.EdbInfoFilterDataResp
  384. // @router /edb_info/public/list/es/all [post]
  385. func (c *EdbPublicController) AllListByEs() {
  386. br := new(models.BaseResponse).Init()
  387. defer func() {
  388. c.Data["json"] = br
  389. c.ServeJSON()
  390. }()
  391. var req request.AllSearchPublicEdbReq
  392. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  393. if err != nil {
  394. br.Msg = "参数解析异常!"
  395. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  396. return
  397. }
  398. // 选择所有指标,所以需要通过es获取数据
  399. // 选中的指标id列表
  400. edbInfoList := make([]*data_manage.EdbInfoList, 0)
  401. // 选择所有指标,所以需要通过es获取数据
  402. if req.IsSelectAll {
  403. tmpEdbInfoList, err := data.GetAllEdbInfoListBySearchPublicEdbReq(req.SearchPublicEdbReq, c.SysUser.AdminId)
  404. if err != nil {
  405. br.Msg = "获取指标列表失败!"
  406. br.ErrMsg = "获取指标列表失败,Err:" + err.Error()
  407. return
  408. }
  409. // 如果有过滤指标,那么就过滤吧
  410. if len(req.NoEdbIdList) > 0 {
  411. noEdbIdMap := make(map[int]bool)
  412. for _, v := range req.NoEdbIdList {
  413. noEdbIdMap[v] = true
  414. }
  415. for _, v := range tmpEdbInfoList {
  416. if _, ok := noEdbIdMap[v.EdbInfoId]; !ok {
  417. // 如果不在未选中的指标id列表中,那么就加入到选中的指标id列表
  418. edbInfoList = append(edbInfoList, v)
  419. }
  420. }
  421. } else {
  422. edbInfoList = tmpEdbInfoList
  423. }
  424. // 因为是ES查找的,所以需要重新查一下指标的信息,主要是为了把是否授权字段找出来
  425. if len(edbInfoList) > 0 {
  426. edbInfoIdList := make([]int, 0)
  427. for _, v := range edbInfoList {
  428. v.ConvertToResp()
  429. v.EdbNameAlias = v.EdbName
  430. v.HaveOperaAuth = true
  431. edbInfoIdList = append(edbInfoIdList, v.EdbInfoId)
  432. }
  433. tmpEdbList, err := data_manage.GetEdbInfoByIdList(edbInfoIdList)
  434. if err != nil {
  435. br.Msg = "获取失败"
  436. br.ErrMsg = "获取所有有权限的指标失败,Err:" + err.Error()
  437. return
  438. }
  439. edbInfoMap := make(map[int]*data_manage.EdbInfo)
  440. for _, v := range tmpEdbList {
  441. edbInfoMap[v.EdbInfoId] = v
  442. }
  443. for _, v := range edbInfoList {
  444. tmpEdbInfo, ok := edbInfoMap[v.EdbInfoId]
  445. if !ok {
  446. continue
  447. }
  448. v.IsJoinPermission = tmpEdbInfo.IsJoinPermission
  449. }
  450. }
  451. } else {
  452. // 因为是ES查找的,所以需要重新查一下指标的信息,主要是为了把是否授权字段找出来
  453. if len(req.EdbIdList) > 0 {
  454. edbInfoList, err = data_manage.GetEdbInfoListByCond(` AND edb_info_id in (?) `, []interface{}{req.EdbIdList})
  455. if err != nil {
  456. br.Msg = "获取失败"
  457. br.ErrMsg = "获取所有有权限的指标失败,Err:" + err.Error()
  458. return
  459. }
  460. }
  461. }
  462. edbInfoListLen := len(edbInfoList)
  463. for i := 0; i < edbInfoListLen; i++ {
  464. for j := 0; j < edbInfoListLen; j++ {
  465. if (edbInfoList[i].EdbNameAlias == edbInfoList[j].EdbNameAlias) &&
  466. (edbInfoList[i].EdbInfoId != edbInfoList[j].EdbInfoId) &&
  467. !(strings.Contains(edbInfoList[i].EdbName, edbInfoList[i].SourceName)) {
  468. edbInfoList[i].EdbName = edbInfoList[i].EdbName + "(" + edbInfoList[i].SourceName + ")"
  469. }
  470. }
  471. }
  472. resp := data_manage.EdbInfoFilterDataResp{
  473. List: edbInfoList,
  474. }
  475. br.Ret = 200
  476. br.Success = true
  477. br.Msg = "获取成功"
  478. br.Data = resp
  479. }
  480. // BatchMoveEdb
  481. // @Title 指标批量移动接口
  482. // @Description 指标批量移动接口
  483. // @Param request body request.MoveEdbClassifyReq true "type json string"
  484. // @Success Ret=200 移动成功
  485. // @router /edb_info/public/batch_move [post]
  486. func (c *EdbPublicController) BatchMoveEdb() {
  487. br := new(models.BaseResponse).Init()
  488. defer func() {
  489. c.Data["json"] = br
  490. c.ServeJSON()
  491. }()
  492. var req request.MoveEdbClassifyReq
  493. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  494. if err != nil {
  495. br.Msg = "参数解析异常!"
  496. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  497. return
  498. }
  499. if req.NewClassifyId <= 0 {
  500. br.Msg = `请选择要转移的新分类`
  501. br.IsSendEmail = false
  502. return
  503. }
  504. // 校验分类
  505. obj := data_manage.EdbPublicClassify{}
  506. publicClassifyItem, err := obj.GetEdbClassifyById(req.NewClassifyId)
  507. if err != nil {
  508. br.Msg = "获取公共分类失败!"
  509. br.ErrMsg = "获取公共分类失败!" + err.Error()
  510. return
  511. }
  512. if publicClassifyItem.EdbPublicClassifyId <= 0 {
  513. br.Msg = "公共分类不存在!"
  514. br.ErrMsg = "公共分类不存在!"
  515. return
  516. }
  517. // 只是取公开
  518. req.SearchPublicEdbReq.EdbPublicList = []int{3}
  519. edbInfoIdList := make([]int, 0)
  520. if req.IsSelectAll {
  521. // 获取指标
  522. edbInfoList, err := data.GetAllEdbInfoListBySearchPublicEdbReq(req.SearchPublicEdbReq, c.SysUser.AdminId)
  523. if err != nil {
  524. br.Msg = "获取指标列表失败!"
  525. br.ErrMsg = "获取指标列表失败,Err:" + err.Error()
  526. return
  527. }
  528. // 如果有过滤指标,那么就过滤吧
  529. if len(req.NoEdbIdList) > 0 {
  530. noEdbIdMap := make(map[int]bool)
  531. for _, v := range req.NoEdbIdList {
  532. noEdbIdMap[v] = true
  533. }
  534. for _, edbInfo := range edbInfoList {
  535. if _, ok := noEdbIdMap[edbInfo.EdbInfoId]; !ok {
  536. if edbInfo.PublicStatus != utils.DataPublicSuccess {
  537. br.Msg = `存在未公开的指标:` + edbInfo.EdbName
  538. br.IsSendEmail = false
  539. return
  540. }
  541. // 如果不在未选中的指标id列表中,那么就加入到选中的指标id列表
  542. edbInfoIdList = append(edbInfoIdList, edbInfo.EdbInfoId)
  543. }
  544. }
  545. } else {
  546. for _, edbInfo := range edbInfoList {
  547. if edbInfo.PublicStatus != utils.DataPublicSuccess {
  548. br.Msg = `存在未公开的指标:` + edbInfo.EdbName
  549. br.IsSendEmail = false
  550. return
  551. }
  552. edbInfoIdList = append(edbInfoIdList, edbInfo.EdbInfoId)
  553. }
  554. }
  555. } else {
  556. edbInfoList, err := data_manage.GetEdbInfoListByCond(` AND edb_info_id in (?) `, []interface{}{req.EdbIdList})
  557. if err != nil {
  558. br.Msg = "获取失败"
  559. br.ErrMsg = "获取所有有权限的指标失败,Err:" + err.Error()
  560. return
  561. }
  562. for _, v := range edbInfoList {
  563. if v.PublicStatus != utils.DataPublicSuccess {
  564. br.Msg = `存在未公开的指标:` + v.EdbName
  565. br.IsSendEmail = false
  566. return
  567. }
  568. }
  569. edbInfoIdList = req.EdbIdList
  570. }
  571. num := len(edbInfoIdList)
  572. if num <= 0 {
  573. br.Msg = `请选择要移动的指标!`
  574. br.IsSendEmail = false
  575. return
  576. }
  577. if num > 100 {
  578. br.Msg = `最多只能选择100条指标!`
  579. br.IsSendEmail = false
  580. return
  581. }
  582. // 开始批量修改指标分类
  583. if len(edbInfoIdList) > 0 {
  584. err = data_manage.UpdatePublicClassifyIdByEdbInfoIdList(edbInfoIdList, req.NewClassifyId)
  585. if err != nil {
  586. br.Msg = `指标移动失败!`
  587. br.ErrMsg = `指标移动失败,ERR:` + err.Error()
  588. return
  589. }
  590. // 还得修改ES呢
  591. for _, v := range edbInfoIdList {
  592. data.AddOrEditEdbInfoToEs(v)
  593. }
  594. }
  595. br.Ret = 200
  596. br.Success = true
  597. br.Msg = "获取成功"
  598. }