public_edb.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  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. var req request.CancelEdbPublicReq
  157. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  158. if err != nil {
  159. br.Msg = "参数解析异常!"
  160. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  161. return
  162. }
  163. edbInfoId := req.EdbInfoId
  164. if edbInfoId <= 0 {
  165. br.Msg = "参数错误"
  166. br.ErrMsg = "参数错误"
  167. return
  168. }
  169. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  170. if err != nil {
  171. br.Msg = "保存失败!"
  172. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  173. return
  174. }
  175. // 判断指标公共状态
  176. if !utils.InArrayByInt([]int{utils.DataPublicSuccess, utils.DataPublicReject, utils.DataPublicCommit}, edbInfo.PublicStatus) {
  177. br.Msg = "保存失败,指标公开状态异常!"
  178. br.ErrMsg = "保存失败,指标公开状态异常,public_status:" + fmt.Sprint(edbInfo.PublicStatus)
  179. return
  180. }
  181. // 如果公开状态是:已驳回、已提交,那么直接去撤销审批单
  182. if utils.InArrayByInt([]int{utils.DataPublicReject, utils.DataPublicCommit}, edbInfo.PublicStatus) {
  183. obj := data_approve.DataApproveRelation{}
  184. dataApproveId, err := obj.GetDataApproveIdByDataId(edbInfoId, utils.DataApproveTypeEdb)
  185. if err != nil {
  186. br.Msg = "保存失败!"
  187. br.ErrMsg = "获取审批单失败,Err:" + err.Error()
  188. return
  189. }
  190. // 撤销审批
  191. msg, e := dataApproveSerice.DataApproveCancel(dataApproveId, sysUser.AdminId, sysUser.RealName)
  192. if e != nil {
  193. if msg != "" {
  194. br.Msg = msg
  195. } else {
  196. br.Msg = "操作失败"
  197. }
  198. br.ErrMsg = "撤销审批失败, Err: " + e.Error()
  199. return
  200. }
  201. }
  202. checkUserIdList := []int{sysUser.AdminId}
  203. // 已经分享的用户
  204. {
  205. obj := data_manage.EdbInfoShare{}
  206. userIdList, err := obj.GetAllUserIdListByEdbInfoId(edbInfo.EdbInfoId)
  207. if err != nil {
  208. br.Msg = "设置失败!"
  209. br.ErrMsg = "设置失败,Err:" + err.Error()
  210. return
  211. }
  212. if len(userIdList) > 0 {
  213. checkUserIdList = append(checkUserIdList, userIdList...)
  214. }
  215. }
  216. noReferenced, otherUserIdList, err, tips := data.CheckEdbReferencedByOthers(edbInfo.EdbInfoType, []int{edbInfo.EdbInfoId}, checkUserIdList)
  217. if err != nil {
  218. br.Msg = "保存失败"
  219. if tips != "" {
  220. br.Msg = tips
  221. }
  222. br.ErrMsg = "撤销指标公开失败,查找指标的关联用户失败,Err:" + err.Error()
  223. return
  224. }
  225. if !noReferenced {
  226. userNameStr := ``
  227. if len(otherUserIdList) > 0 {
  228. userNameList := make([]string, 0)
  229. userList, err := system.GetAdminListByIdList(otherUserIdList)
  230. if err != nil {
  231. br.Msg = "保存失败"
  232. if tips != "" {
  233. br.Msg = tips
  234. }
  235. br.ErrMsg = "撤销指标公开失败,查找用户信息失败,Err:" + err.Error()
  236. return
  237. }
  238. for _, userInfo := range userList {
  239. userNameList = append(userNameList, userInfo.RealName)
  240. }
  241. userNameStr = strings.Join(userNameList, ",")
  242. }
  243. msg := `指标被其他用户使用,无法撤销公开`
  244. if userNameStr != "" {
  245. msg = fmt.Sprintf(`指标被用户%s使用,无法撤销公开`, userNameStr)
  246. }
  247. if tips != "" {
  248. msg = fmt.Sprintf(`%s,用户为:%s,无法撤销公开`, tips, userNameStr)
  249. }
  250. br.Msg = msg
  251. br.ErrMsg = "指标被其他用户共享,无法撤销公开,EdbInfoId:" + strconv.Itoa(edbInfo.EdbInfoId)
  252. br.IsSendEmail = false
  253. return
  254. }
  255. edbInfo.PublicStatus = utils.DataPublicDefault
  256. edbInfo.EdbPublicClassifyId = 0
  257. err = edbInfo.Update([]string{"PublicStatus", "EdbPublicClassifyId"})
  258. if err != nil {
  259. br.Msg = "保存失败"
  260. br.ErrMsg = "取消指标公共失败,Err:" + err.Error()
  261. return
  262. }
  263. // 修改ES数据
  264. data.AddOrEditEdbInfoToEs(edbInfo.EdbInfoId)
  265. // 指标收藏操作处理
  266. go cache.AddDataCollectHandler(edbInfo.EdbInfoId, utils.DataCollectTypeEdb)
  267. br.Ret = 200
  268. br.Success = true
  269. br.Msg = "操作成功"
  270. }
  271. // ListByEs
  272. // @Title 指标筛选接口
  273. // @Description 指标筛选接口
  274. // @Success 200 {object} data_manage.EdbInfoList
  275. // @Param request body request.SearchPublicEdbReq true "type json string"
  276. // @Success 200 {object} data_manage.EdbInfoFilterDataResp
  277. // @router /edb_info/public/list/es [post]
  278. func (c *EdbPublicController) ListByEs() {
  279. br := new(models.BaseResponse).Init()
  280. defer func() {
  281. c.Data["json"] = br
  282. c.ServeJSON()
  283. }()
  284. var req request.SearchPublicEdbReq
  285. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  286. if err != nil {
  287. br.Msg = "参数解析异常!"
  288. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  289. return
  290. }
  291. pageSize := req.PageSize
  292. currentIndex := req.CurrentIndex
  293. var total int64
  294. var startSize int
  295. if pageSize <= 0 {
  296. pageSize = utils.PageSize20
  297. }
  298. if currentIndex <= 0 {
  299. currentIndex = 1
  300. }
  301. startSize = paging.StartIndex(currentIndex, pageSize)
  302. // 获取查询参数
  303. keyword, searchEdbPublicList, sourceList, edbClassifyIdList, publicClassifyIdList, edbTypeList, edbInfoType, edbAuth, sortMap := data.GetSearchPar(req)
  304. total, edbInfoList, err := elastic.SearchEdbInfoDataByPublic(keyword, startSize, pageSize, searchEdbPublicList, sourceList, edbClassifyIdList, publicClassifyIdList, edbTypeList, edbInfoType, edbAuth, c.SysUser.AdminId, sortMap)
  305. if err != nil {
  306. edbInfoList = make([]*data_manage.EdbInfoList, 0)
  307. }
  308. page := paging.GetPaging(currentIndex, pageSize, int(total))
  309. edbInfoListLen := len(edbInfoList)
  310. // 因为是ES查找的,所以需要重新查一下指标的信息,主要是为了把是否授权字段找出来
  311. if len(edbInfoList) > 0 {
  312. // 图表map
  313. edbInfoMap := make(map[int]*data_manage.EdbInfo)
  314. classifyMap := make(map[int]*data_manage.EdbClassify)
  315. publicClassifyMap := make(map[int]*data_manage.EdbPublicClassify)
  316. // 指标id,分类id,公共分类id
  317. edbInfoIdList := make([]int, 0)
  318. tmpClassifyIdList := make([]int, 0)
  319. tmpPublicClassifyIdList := make([]int, 0)
  320. for _, v := range edbInfoList {
  321. v.ConvertToResp()
  322. v.EdbNameAlias = v.EdbName
  323. v.HaveOperaAuth = true
  324. edbInfoIdList = append(edbInfoIdList, v.EdbInfoId)
  325. }
  326. // 查找指标
  327. {
  328. tmpEdbList, err := data_manage.GetEdbInfoByIdList(edbInfoIdList)
  329. if err != nil {
  330. br.Msg = "获取失败"
  331. br.ErrMsg = "获取所有有权限的指标失败,Err:" + err.Error()
  332. return
  333. }
  334. for _, v := range tmpEdbList {
  335. edbInfoMap[v.EdbInfoId] = v
  336. tmpClassifyIdList = append(tmpClassifyIdList, v.ClassifyId)
  337. tmpPublicClassifyIdList = append(tmpPublicClassifyIdList, v.EdbPublicClassifyId)
  338. }
  339. }
  340. // 指标分类
  341. {
  342. tmpList, err := data_manage.GetEdbClassifyByIdList(tmpClassifyIdList)
  343. if err != nil {
  344. br.Msg = "获取失败"
  345. br.ErrMsg = "获取所有有权限的图表分类失败,Err:" + err.Error()
  346. return
  347. }
  348. for _, v := range tmpList {
  349. classifyMap[v.ClassifyId] = v
  350. }
  351. }
  352. // 公共分类
  353. {
  354. obj := data_manage.EdbPublicClassify{}
  355. tmpList, err := obj.GetEdbClassifyByIdList(tmpPublicClassifyIdList)
  356. if err != nil {
  357. br.Msg = "获取失败"
  358. br.ErrMsg = "获取所有有权限的公共分类失败,Err:" + err.Error()
  359. return
  360. }
  361. for _, v := range tmpList {
  362. publicClassifyMap[v.EdbPublicClassifyId] = v
  363. }
  364. }
  365. // 数据重新赋值
  366. for _, v := range edbInfoList {
  367. if tmpEdbInfo, ok := edbInfoMap[v.EdbInfoId]; ok {
  368. v.IsJoinPermission = tmpEdbInfo.IsJoinPermission
  369. }
  370. // 普通分类
  371. if classifyItem, ok := classifyMap[v.ClassifyId]; ok {
  372. v.ClassifyNamePath = classifyItem.ClassifyNamePath
  373. }
  374. // 公共分类
  375. if classifyItem, ok := publicClassifyMap[v.EdbPublicClassifyId]; ok {
  376. v.PublicClassifyNamePath = classifyItem.EdbPublicClassifyNamePath
  377. }
  378. }
  379. }
  380. for i := 0; i < edbInfoListLen; i++ {
  381. for j := 0; j < edbInfoListLen; j++ {
  382. if (edbInfoList[i].EdbNameAlias == edbInfoList[j].EdbNameAlias) &&
  383. (edbInfoList[i].EdbInfoId != edbInfoList[j].EdbInfoId) &&
  384. !(strings.Contains(edbInfoList[i].EdbName, edbInfoList[i].SourceName)) {
  385. edbInfoList[i].EdbName = edbInfoList[i].EdbName + "(" + edbInfoList[i].SourceName + ")"
  386. }
  387. }
  388. }
  389. resp := data_manage.EdbInfoFilterDataResp{
  390. Paging: page,
  391. List: edbInfoList,
  392. }
  393. br.Ret = 200
  394. br.Success = true
  395. br.Msg = "获取成功"
  396. br.Data = resp
  397. }
  398. // AllListByEs
  399. // @Title 指标筛选接口
  400. // @Description 指标筛选接口
  401. // @Success 200 {object} data_manage.EdbInfoList
  402. // @Param request body request.SearchEdbInfoShareReq true "type json string"
  403. // @Success 200 {object} data_manage.EdbInfoFilterDataResp
  404. // @router /edb_info/public/list/es/all [post]
  405. func (c *EdbPublicController) AllListByEs() {
  406. br := new(models.BaseResponse).Init()
  407. defer func() {
  408. c.Data["json"] = br
  409. c.ServeJSON()
  410. }()
  411. var req request.AllSearchPublicEdbReq
  412. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  413. if err != nil {
  414. br.Msg = "参数解析异常!"
  415. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  416. return
  417. }
  418. // 选择所有指标,所以需要通过es获取数据
  419. // 选中的指标id列表
  420. edbInfoList := make([]*data_manage.EdbInfoList, 0)
  421. // 选择所有指标,所以需要通过es获取数据
  422. if req.IsSelectAll {
  423. tmpEdbInfoList, err := data.GetAllEdbInfoListBySearchPublicEdbReq(req.SearchPublicEdbReq, c.SysUser.AdminId)
  424. if err != nil {
  425. br.Msg = "获取指标列表失败!"
  426. br.ErrMsg = "获取指标列表失败,Err:" + err.Error()
  427. return
  428. }
  429. // 如果有过滤指标,那么就过滤吧
  430. if len(req.NoEdbIdList) > 0 {
  431. noEdbIdMap := make(map[int]bool)
  432. for _, v := range req.NoEdbIdList {
  433. noEdbIdMap[v] = true
  434. }
  435. for _, v := range tmpEdbInfoList {
  436. if _, ok := noEdbIdMap[v.EdbInfoId]; !ok {
  437. // 如果不在未选中的指标id列表中,那么就加入到选中的指标id列表
  438. edbInfoList = append(edbInfoList, v)
  439. }
  440. }
  441. } else {
  442. edbInfoList = tmpEdbInfoList
  443. }
  444. // 因为是ES查找的,所以需要重新查一下指标的信息,主要是为了把是否授权字段找出来
  445. if len(edbInfoList) > 0 {
  446. edbInfoIdList := make([]int, 0)
  447. for _, v := range edbInfoList {
  448. v.ConvertToResp()
  449. v.EdbNameAlias = v.EdbName
  450. v.HaveOperaAuth = true
  451. edbInfoIdList = append(edbInfoIdList, v.EdbInfoId)
  452. }
  453. tmpEdbList, err := data_manage.GetEdbInfoByIdList(edbInfoIdList)
  454. if err != nil {
  455. br.Msg = "获取失败"
  456. br.ErrMsg = "获取所有有权限的指标失败,Err:" + err.Error()
  457. return
  458. }
  459. edbInfoMap := make(map[int]*data_manage.EdbInfo)
  460. for _, v := range tmpEdbList {
  461. edbInfoMap[v.EdbInfoId] = v
  462. }
  463. for _, v := range edbInfoList {
  464. tmpEdbInfo, ok := edbInfoMap[v.EdbInfoId]
  465. if !ok {
  466. continue
  467. }
  468. v.IsJoinPermission = tmpEdbInfo.IsJoinPermission
  469. }
  470. }
  471. } else {
  472. // 因为是ES查找的,所以需要重新查一下指标的信息,主要是为了把是否授权字段找出来
  473. if len(req.EdbIdList) > 0 {
  474. edbInfoList, err = data_manage.GetEdbInfoListByCond(` AND edb_info_id in (?) `, []interface{}{req.EdbIdList})
  475. if err != nil {
  476. br.Msg = "获取失败"
  477. br.ErrMsg = "获取所有有权限的指标失败,Err:" + err.Error()
  478. return
  479. }
  480. }
  481. }
  482. edbInfoListLen := len(edbInfoList)
  483. for i := 0; i < edbInfoListLen; i++ {
  484. for j := 0; j < edbInfoListLen; j++ {
  485. if (edbInfoList[i].EdbNameAlias == edbInfoList[j].EdbNameAlias) &&
  486. (edbInfoList[i].EdbInfoId != edbInfoList[j].EdbInfoId) &&
  487. !(strings.Contains(edbInfoList[i].EdbName, edbInfoList[i].SourceName)) {
  488. edbInfoList[i].EdbName = edbInfoList[i].EdbName + "(" + edbInfoList[i].SourceName + ")"
  489. }
  490. }
  491. }
  492. resp := data_manage.EdbInfoFilterDataResp{
  493. List: edbInfoList,
  494. }
  495. br.Ret = 200
  496. br.Success = true
  497. br.Msg = "获取成功"
  498. br.Data = resp
  499. }
  500. // BatchMoveEdb
  501. // @Title 指标批量移动接口
  502. // @Description 指标批量移动接口
  503. // @Param request body request.MoveEdbClassifyReq true "type json string"
  504. // @Success Ret=200 移动成功
  505. // @router /edb_info/public/batch_move [post]
  506. func (c *EdbPublicController) BatchMoveEdb() {
  507. br := new(models.BaseResponse).Init()
  508. defer func() {
  509. c.Data["json"] = br
  510. c.ServeJSON()
  511. }()
  512. var req request.MoveEdbClassifyReq
  513. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  514. if err != nil {
  515. br.Msg = "参数解析异常!"
  516. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  517. return
  518. }
  519. if req.NewClassifyId <= 0 {
  520. br.Msg = `请选择要转移的新分类`
  521. br.IsSendEmail = false
  522. return
  523. }
  524. // 校验分类
  525. obj := data_manage.EdbPublicClassify{}
  526. publicClassifyItem, err := obj.GetEdbClassifyById(req.NewClassifyId)
  527. if err != nil {
  528. br.Msg = "获取公共分类失败!"
  529. br.ErrMsg = "获取公共分类失败!" + err.Error()
  530. return
  531. }
  532. if publicClassifyItem.EdbPublicClassifyId <= 0 {
  533. br.Msg = "公共分类不存在!"
  534. br.ErrMsg = "公共分类不存在!"
  535. return
  536. }
  537. // 只是取公开
  538. req.SearchPublicEdbReq.EdbPublicList = []int{3}
  539. edbInfoIdList := make([]int, 0)
  540. if req.IsSelectAll {
  541. // 获取指标
  542. edbInfoList, err := data.GetAllEdbInfoListBySearchPublicEdbReq(req.SearchPublicEdbReq, c.SysUser.AdminId)
  543. if err != nil {
  544. br.Msg = "获取指标列表失败!"
  545. br.ErrMsg = "获取指标列表失败,Err:" + err.Error()
  546. return
  547. }
  548. // 如果有过滤指标,那么就过滤吧
  549. if len(req.NoEdbIdList) > 0 {
  550. noEdbIdMap := make(map[int]bool)
  551. for _, v := range req.NoEdbIdList {
  552. noEdbIdMap[v] = true
  553. }
  554. for _, edbInfo := range edbInfoList {
  555. if _, ok := noEdbIdMap[edbInfo.EdbInfoId]; !ok {
  556. if edbInfo.PublicStatus != utils.DataPublicSuccess {
  557. br.Msg = `存在未公开的指标:` + edbInfo.EdbName
  558. br.IsSendEmail = false
  559. return
  560. }
  561. // 如果不在未选中的指标id列表中,那么就加入到选中的指标id列表
  562. edbInfoIdList = append(edbInfoIdList, edbInfo.EdbInfoId)
  563. }
  564. }
  565. } else {
  566. for _, edbInfo := range edbInfoList {
  567. if edbInfo.PublicStatus != utils.DataPublicSuccess {
  568. br.Msg = `存在未公开的指标:` + edbInfo.EdbName
  569. br.IsSendEmail = false
  570. return
  571. }
  572. edbInfoIdList = append(edbInfoIdList, edbInfo.EdbInfoId)
  573. }
  574. }
  575. } else {
  576. edbInfoList, err := data_manage.GetEdbInfoListByCond(` AND edb_info_id in (?) `, []interface{}{req.EdbIdList})
  577. if err != nil {
  578. br.Msg = "获取失败"
  579. br.ErrMsg = "获取所有有权限的指标失败,Err:" + err.Error()
  580. return
  581. }
  582. for _, v := range edbInfoList {
  583. if v.PublicStatus != utils.DataPublicSuccess {
  584. br.Msg = `存在未公开的指标:` + v.EdbName
  585. br.IsSendEmail = false
  586. return
  587. }
  588. }
  589. edbInfoIdList = req.EdbIdList
  590. }
  591. num := len(edbInfoIdList)
  592. if num <= 0 {
  593. br.Msg = `请选择要移动的指标!`
  594. br.IsSendEmail = false
  595. return
  596. }
  597. if num > 100 {
  598. br.Msg = `最多只能选择100条指标!`
  599. br.IsSendEmail = false
  600. return
  601. }
  602. // 开始批量修改指标分类
  603. if len(edbInfoIdList) > 0 {
  604. err = data_manage.UpdatePublicClassifyIdByEdbInfoIdList(edbInfoIdList, req.NewClassifyId)
  605. if err != nil {
  606. br.Msg = `指标移动失败!`
  607. br.ErrMsg = `指标移动失败,ERR:` + err.Error()
  608. return
  609. }
  610. // 还得修改ES呢
  611. for _, v := range edbInfoIdList {
  612. data.AddOrEditEdbInfoToEs(v)
  613. }
  614. }
  615. br.Ret = 200
  616. br.Success = true
  617. br.Msg = "获取成功"
  618. }