edb_info_share.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  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/models/data_manage/response"
  9. "eta_gn/eta_api/models/system"
  10. "eta_gn/eta_api/services/data"
  11. "eta_gn/eta_api/services/elastic"
  12. "eta_gn/eta_api/utils"
  13. "fmt"
  14. "github.com/rdlucklib/rdluck_tools/paging"
  15. "strconv"
  16. "strings"
  17. )
  18. // EdbInfoShareController 数据管理
  19. type EdbInfoShareController struct {
  20. controllers.BaseAuthController
  21. }
  22. // UserList
  23. // @Title 获取指标设置共享的详情
  24. // @Description 获取指标详情接口
  25. // @Param EdbInfoId query int true "指标id"
  26. // @Success 200 {object} response.EdbInfoShareUserResp
  27. // @router /edb_info/share/user_list [get]
  28. func (c *EdbInfoShareController) UserList() {
  29. br := new(models.BaseResponse).Init()
  30. defer func() {
  31. c.Data["json"] = br
  32. c.ServeJSON()
  33. }()
  34. sysUser := c.SysUser
  35. if sysUser == nil {
  36. br.Msg = "请登录"
  37. br.ErrMsg = "请登录,SysUser Is Empty"
  38. br.Ret = 408
  39. return
  40. }
  41. edbInfoId, _ := c.GetInt("EdbInfoId")
  42. if edbInfoId <= 0 {
  43. br.Msg = "参数错误"
  44. br.ErrMsg = "参数错误"
  45. return
  46. }
  47. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  48. if err != nil {
  49. br.Msg = "获取失败"
  50. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  51. return
  52. }
  53. if edbInfo.SysUserId != sysUser.AdminId {
  54. br.Msg = "您没有权限设置共享"
  55. br.ErrMsg = "您没有权限设置共享,EdbInfoId:" + strconv.Itoa(edbInfo.EdbInfoId)
  56. br.IsSendEmail = false
  57. return
  58. }
  59. resp := response.EdbInfoShareUserResp{}
  60. obj := data_manage.EdbInfoShare{}
  61. list, err := obj.GetListByEdbInfoId(edbInfoId)
  62. if err != nil {
  63. br.Msg = `获取失败`
  64. br.ErrMsg = `获取失败:` + err.Error()
  65. return
  66. }
  67. resp.List = list
  68. br.Ret = 200
  69. br.Success = true
  70. br.Msg = "获取成功"
  71. br.Data = resp
  72. }
  73. // Save
  74. // @Title 单个指标设置共享
  75. // @Description 单个指标设置共享
  76. // @Param request body request.SetEdbInfoShareReq true "type json string"
  77. // @Success 200 {object} data_manage.EdbInfo
  78. // @router /edb_info/share/save [post]
  79. func (c *EdbInfoShareController) Save() {
  80. br := new(models.BaseResponse).Init()
  81. defer func() {
  82. c.Data["json"] = br
  83. c.ServeJSON()
  84. }()
  85. sysUser := c.SysUser
  86. if sysUser == nil {
  87. br.Msg = "请登录"
  88. br.ErrMsg = "请登录,SysUser Is Empty"
  89. br.Ret = 408
  90. return
  91. }
  92. var req request.SetEdbInfoShareReq
  93. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  94. if err != nil {
  95. br.Msg = "参数解析异常!"
  96. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  97. return
  98. }
  99. if req.EdbInfoId <= 0 {
  100. br.Msg = `请选择指标`
  101. br.IsSendEmail = false
  102. return
  103. }
  104. edbItem, err := data_manage.GetEdbInfoById(req.EdbInfoId)
  105. if err != nil {
  106. br.Msg = "查找指标失败"
  107. br.ErrMsg = "查找指标失败,Err:" + err.Error()
  108. return
  109. }
  110. if edbItem.EdbInfoId <= 0 {
  111. br.Msg = "指标不存在"
  112. br.ErrMsg = "指标不存在,ChartInfoId:" + strconv.Itoa(req.EdbInfoId)
  113. br.IsSendEmail = false
  114. return
  115. }
  116. if edbItem.SysUserId != c.SysUser.AdminId {
  117. br.Msg = "您没有权限设置共享"
  118. br.ErrMsg = "您没有权限设置共享,EdbInfoId:" + strconv.Itoa(req.EdbInfoId)
  119. br.IsSendEmail = false
  120. return
  121. }
  122. obj := data_manage.EdbInfoShare{}
  123. err = obj.SaveEdbInfoShare([]int{req.EdbInfoId}, req.UserIdList, req.ShareType)
  124. if err != nil {
  125. br.Msg = `保存失败`
  126. br.ErrMsg = `保存失败:` + err.Error()
  127. return
  128. }
  129. // 更新es
  130. data.AddOrEditEdbInfoToEs(req.EdbInfoId)
  131. br.Ret = 200
  132. br.Success = true
  133. br.Msg = "保存成功"
  134. }
  135. // Tree
  136. // @Title 获取共享指标的分类/指标树
  137. // @Description 获取共享指标的分类/指标树
  138. // @Success 200 {object} response.EdbShareListResp
  139. // @router /edb_info/share/tree [get]
  140. func (c *EdbInfoShareController) Tree() {
  141. br := new(models.BaseResponse).Init()
  142. defer func() {
  143. c.Data["json"] = br
  144. c.ServeJSON()
  145. }()
  146. sysUser := c.SysUser
  147. if sysUser == nil {
  148. br.Msg = "请登录"
  149. br.ErrMsg = "请登录,SysUser Is Empty"
  150. br.Ret = 408
  151. return
  152. }
  153. resp := response.EdbShareListResp{}
  154. // 我共享的
  155. {
  156. sendList, err := data.GetAllShareEdbListByFromUserId(sysUser.AdminId)
  157. if err != nil {
  158. br.Msg = "获取失败"
  159. br.ErrMsg = "获取我共享的指标列表信息失败,Err:" + err.Error()
  160. return
  161. }
  162. nodeList, err := data.GetEdbClassifyItemListByShareEdbInfoQueryList(sendList)
  163. if err != nil {
  164. br.Msg = "获取失败"
  165. br.ErrMsg = "获取我共享出去的指标列表分类结构信息失败,Err:" + err.Error()
  166. return
  167. }
  168. resp.Send = nodeList
  169. }
  170. // 我收到的
  171. {
  172. sendList, err := data.GetAllShareEdbListByReceivedUserId(sysUser.AdminId)
  173. if err != nil {
  174. br.Msg = "获取失败"
  175. br.ErrMsg = "获取我共享的指标列表信息失败,Err:" + err.Error()
  176. return
  177. }
  178. nodeList, err := data.GetEdbClassifyItemListByShareEdbInfoQueryList(sendList)
  179. if err != nil {
  180. br.Msg = "获取失败"
  181. br.ErrMsg = "获取我收到共享的指标列表分类结构信息失败,Err:" + err.Error()
  182. return
  183. }
  184. receivedMap := make(map[int]int)
  185. var receivedList data_manage.UserShareEdbClassifyItemList
  186. for _, v := range nodeList {
  187. index, ok := receivedMap[v.SysUserId]
  188. if !ok {
  189. index = len(receivedMap)
  190. item := &data_manage.UserShareEdbClassifyItem{
  191. UserId: v.SysUserId,
  192. UserName: v.SysUserRealName,
  193. EdbInfoId: 0,
  194. ClassifyId: v.SysUserId,
  195. ClassifyName: v.SysUserRealName,
  196. ClassifyType: 0,
  197. ClassifyNameEn: "",
  198. ParentId: 0,
  199. RootId: 0,
  200. Level: 0,
  201. Sort: 0,
  202. UniqueCode: utils.MD5(fmt.Sprint(v.SysUserId, "_", v.SysUserRealName)),
  203. Source: 0,
  204. SourceName: "",
  205. SysUserId: v.SysUserId,
  206. SysUserRealName: v.SysUserRealName,
  207. StartDate: "",
  208. EdbCode: "",
  209. EdbType: 0,
  210. Children: []*data_manage.UserShareEdbClassifyItem{},
  211. Button: data_manage.EdbClassifyItemsButton{},
  212. IsJoinPermission: 0,
  213. HaveOperaAuth: true,
  214. ClassifyIdPath: "",
  215. }
  216. receivedList = append(receivedList, item)
  217. }
  218. receivedList[index].Children = append(receivedList[index].Children, v)
  219. receivedMap[v.SysUserId] = index
  220. }
  221. resp.Received = receivedList
  222. }
  223. br.Ret = 200
  224. br.Success = true
  225. br.Msg = "获取成功"
  226. br.Data = resp
  227. }
  228. // List
  229. // @Title 指标列表接口
  230. // @Description 指标列表接口
  231. // @Param PageSize query int true "每页数据条数"
  232. // @Param CurrentIndex query int true "当前页页码,从1开始"
  233. // @Param ClassifyId query int true "分类id"
  234. // @Param FilterSource query int false "共享指标的列表数据来源,0:我共享的;1:别人共享给我的"
  235. // @Success 200 {object} response.EdbInfoChartListResp
  236. // @router /edb_info/share/list [get]
  237. func (c *EdbInfoShareController) List() {
  238. br := new(models.BaseResponse).Init()
  239. defer func() {
  240. if br.ErrMsg == "" {
  241. br.IsSendEmail = false
  242. }
  243. c.Data["json"] = br
  244. c.ServeJSON()
  245. }()
  246. sysUser := c.SysUser
  247. if sysUser == nil {
  248. br.Msg = "请登录"
  249. br.ErrMsg = "请登录,SysUser Is Empty"
  250. br.Ret = 408
  251. return
  252. }
  253. // 分页
  254. pageSize, _ := c.GetInt("PageSize")
  255. currentIndex, _ := c.GetInt("CurrentIndex")
  256. filterSource, _ := c.GetInt("FilterSource")
  257. var total int
  258. page := paging.GetPaging(currentIndex, pageSize, total)
  259. var startSize int
  260. if pageSize <= 0 {
  261. pageSize = utils.PageSize20
  262. }
  263. if currentIndex <= 0 {
  264. currentIndex = 1
  265. }
  266. startSize = paging.StartIndex(currentIndex, pageSize)
  267. // 基础指标
  268. var condition string
  269. var pars []interface{}
  270. condition += ` AND edb_info_type = ? `
  271. pars = append(pars, 0)
  272. // 指标类型
  273. edbType, _ := c.GetInt("EdbType", 0)
  274. if edbType > 0 {
  275. condition += ` AND edb_type = ? `
  276. pars = append(pars, edbType)
  277. }
  278. // 用户筛选
  279. userId, _ := c.GetInt("UserId")
  280. if userId > 0 {
  281. condition += ` AND b.sys_user_id = ? `
  282. pars = append(pars, userId)
  283. }
  284. // 分类筛选
  285. classifyId, _ := c.GetInt("ClassifyId")
  286. if classifyId > 0 {
  287. childClassify, e, _ := data.GetChildClassifyByClassifyId(classifyId)
  288. if e != nil && !utils.IsErrNoRow(e) {
  289. br.Msg = "获取失败"
  290. br.ErrMsg = "获取分类信息失败, GetEdbClassify,Err:" + e.Error()
  291. return
  292. }
  293. var classifyIds []int
  294. for _, v := range childClassify {
  295. classifyIds = append(classifyIds, v.ClassifyId)
  296. }
  297. condition += fmt.Sprintf(` AND b.classify_id IN (%s) `, utils.GetOrmInReplace(len(classifyIds)))
  298. pars = append(pars, classifyIds)
  299. }
  300. switch filterSource {
  301. case 1: // 别人共享给我的
  302. condition += ` AND a.sys_user_id = ? AND b.sys_user_id != ? `
  303. pars = append(pars, sysUser.AdminId, sysUser.AdminId)
  304. default: // 我共享的
  305. condition += ` AND b.sys_user_id = ? `
  306. pars = append(pars, sysUser.AdminId)
  307. }
  308. obj := data_manage.EdbInfoShare{}
  309. dataCount, respList, err := obj.GetShareEdbInfoListPageList(condition, pars, startSize, pageSize)
  310. if err != nil {
  311. br.Msg = "获取失败"
  312. br.ErrMsg = fmt.Sprintf("获取分享指标列表失败, %v", err)
  313. return
  314. }
  315. editShareEdbInfoIdMap, err := data.GetAllEditSharedEdbInfoIdMapByReceivedUserId(c.SysUser.AdminId)
  316. if err != nil {
  317. br.Msg = "获取失败"
  318. br.ErrMsg = "获取所有有编辑权限的分享指标失败,Err:" + err.Error()
  319. return
  320. }
  321. for _, edbInfo := range respList {
  322. edbInfo.HaveOperaAuth = true
  323. edbInfo.Button = data.GetEdbOpButton(c.SysUser, edbInfo.SysUserId, edbInfo.EdbInfoId, edbInfo.EdbType, edbInfo.EdbInfoType, edbInfo.HaveOperaAuth, editShareEdbInfoIdMap)
  324. }
  325. page = paging.GetPaging(currentIndex, pageSize, int(dataCount))
  326. resp := response.EdbInfoChartListResp{
  327. Paging: page,
  328. List: respList,
  329. }
  330. br.Ret = 200
  331. br.Success = true
  332. br.Msg = "获取成功"
  333. br.Data = resp
  334. }
  335. // ListByEs
  336. // @Title 指标筛选接口
  337. // @Description 指标筛选接口
  338. // @Success 200 {object} data_manage.EdbInfoList
  339. // @Param request body request.SearchEdbInfoShareReq true "type json string"
  340. // @Success 200 {object} data_manage.EdbInfoFilterDataResp
  341. // @router /edb_info/share/list/es [post]
  342. func (c *EdbInfoShareController) ListByEs() {
  343. br := new(models.BaseResponse).Init()
  344. defer func() {
  345. c.Data["json"] = br
  346. c.ServeJSON()
  347. }()
  348. var req request.SearchEdbInfoShareReq
  349. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  350. if err != nil {
  351. br.Msg = "参数解析异常!"
  352. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  353. return
  354. }
  355. pageSize := req.PageSize
  356. currentIndex := req.CurrentIndex
  357. var total int64
  358. var startSize int
  359. if pageSize <= 0 {
  360. pageSize = utils.PageSize20
  361. }
  362. if currentIndex <= 0 {
  363. currentIndex = 1
  364. }
  365. startSize = paging.StartIndex(currentIndex, pageSize)
  366. keyword := req.Keyword
  367. keyword = strings.TrimSpace(keyword) //移除字符串首尾空格
  368. //指标来源
  369. sourceList := req.SourceList
  370. edbInfoType := 0 // 普通指标
  371. edbTypeList := []int{utils.EdbTypeCalculate} // 普通指标中的计算指标
  372. // 指标分享状态:1-未共享;2-已共享。可多选,多选用英文,隔开;默认是未全部
  373. edbShareList := req.EdbShareList
  374. if len(edbShareList) <= 0 {
  375. edbShareList = []int{}
  376. }
  377. edbShare := 0 // 0:全部,1:未共享,2:已共享
  378. lenEdbShareList := len(edbShareList)
  379. if len(edbShareList) > 0 {
  380. if lenEdbShareList > 1 {
  381. edbShare = 0
  382. } else {
  383. edbShare = edbShareList[0]
  384. }
  385. }
  386. // 直指标所属分类id
  387. edbClassifyIdList := req.ClassifyIdList
  388. edbAuth := 1 // 选择范围是:只有我的指标
  389. var edbInfoList []*data_manage.EdbInfoList
  390. sortMap := make(map[string]string)
  391. // 如果没有搜索关键词,则默认根据指标编码倒序排序
  392. if keyword == `` {
  393. sortMap["EdbInfoId"] = `desc`
  394. }
  395. total, edbInfoList, err = elastic.SearchEdbInfoDataByShared(keyword, startSize, pageSize, edbShare, sourceList, edbClassifyIdList, edbTypeList, edbInfoType, edbAuth, c.SysUser.AdminId, sortMap)
  396. if err != nil {
  397. edbInfoList = make([]*data_manage.EdbInfoList, 0)
  398. }
  399. page := paging.GetPaging(currentIndex, pageSize, int(total))
  400. edbInfoListLen := len(edbInfoList)
  401. // 因为是ES查找的,所以需要重新查一下指标的信息,主要是为了把是否授权字段找出来
  402. if len(edbInfoList) > 0 {
  403. sysUserIdList := make([]int, 0)
  404. edbInfoIdList := make([]int, 0)
  405. for _, v := range edbInfoList {
  406. v.ConvertToResp()
  407. v.EdbNameAlias = v.EdbName
  408. v.HaveOperaAuth = true
  409. edbInfoIdList = append(edbInfoIdList, v.EdbInfoId)
  410. if v.SharedUserIdList != nil && len(v.SharedUserIdList) > 0 {
  411. sysUserIdList = append(sysUserIdList, v.SharedUserIdList...)
  412. }
  413. }
  414. // 获取指标数据
  415. tmpEdbList, err := data_manage.GetEdbInfoByIdList(edbInfoIdList)
  416. if err != nil {
  417. br.Msg = "获取失败"
  418. br.ErrMsg = "获取所有有权限的指标失败,Err:" + err.Error()
  419. return
  420. }
  421. edbInfoMap := make(map[int]*data_manage.EdbInfo)
  422. for _, v := range tmpEdbList {
  423. edbInfoMap[v.EdbInfoId] = v
  424. }
  425. // 获取用户数据
  426. sysUserMap := make(map[int]string)
  427. if len(sysUserIdList) > 0 {
  428. sysUserList, err := system.GetAdminListByIdList(sysUserIdList)
  429. if err != nil {
  430. br.Msg = "获取失败"
  431. br.ErrMsg = "获取分享用户列表失败,Err:" + err.Error()
  432. return
  433. }
  434. for _, v := range sysUserList {
  435. sysUserMap[v.AdminId] = v.RealName
  436. }
  437. }
  438. for _, v := range edbInfoList {
  439. tmpEdbInfo, ok := edbInfoMap[v.EdbInfoId]
  440. if !ok {
  441. continue
  442. }
  443. v.IsJoinPermission = tmpEdbInfo.IsJoinPermission
  444. // 分享人
  445. shareUserName := ``
  446. shareUserNameList := make([]string, 0)
  447. shareUserNameMap := make(map[int]bool)
  448. for _, userId := range v.SharedUserIdList {
  449. userName, ok := sysUserMap[userId]
  450. if !ok {
  451. continue
  452. }
  453. if _, ok = shareUserNameMap[userId]; ok {
  454. continue
  455. }
  456. shareUserNameMap[userId] = true
  457. shareUserNameList = append(shareUserNameList, userName)
  458. }
  459. if len(shareUserNameList) > 0 {
  460. shareUserName = strings.Join(shareUserNameList, `,`)
  461. }
  462. v.SharedUserName = shareUserName
  463. }
  464. }
  465. for i := 0; i < edbInfoListLen; i++ {
  466. for j := 0; j < edbInfoListLen; j++ {
  467. if (edbInfoList[i].EdbNameAlias == edbInfoList[j].EdbNameAlias) &&
  468. (edbInfoList[i].EdbInfoId != edbInfoList[j].EdbInfoId) &&
  469. !(strings.Contains(edbInfoList[i].EdbName, edbInfoList[i].SourceName)) {
  470. edbInfoList[i].EdbName = edbInfoList[i].EdbName + "(" + edbInfoList[i].SourceName + ")"
  471. }
  472. }
  473. }
  474. resp := data_manage.EdbInfoFilterDataResp{
  475. Paging: page,
  476. List: edbInfoList,
  477. }
  478. br.Ret = 200
  479. br.Success = true
  480. br.Msg = "获取成功"
  481. br.Data = resp
  482. }
  483. // BatchSave
  484. // @Title 批量指标设置共享
  485. // @Description 批量指标设置共享
  486. // @Param request body request.SetEdbSharePermissionReq true "type json string"
  487. // @Success 200 {object} data_manage.EdbInfo
  488. // @router /edb_info/share/batch_save [post]
  489. func (c *EdbInfoShareController) BatchSave() {
  490. br := new(models.BaseResponse).Init()
  491. defer func() {
  492. c.Data["json"] = br
  493. c.ServeJSON()
  494. }()
  495. sysUser := c.SysUser
  496. if sysUser == nil {
  497. br.Msg = "请登录"
  498. br.ErrMsg = "请登录,SysUser Is Empty"
  499. br.Ret = 408
  500. return
  501. }
  502. var req request.SetEdbSharePermissionReq
  503. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  504. if err != nil {
  505. br.Msg = "参数解析异常!"
  506. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  507. return
  508. }
  509. // 选中的指标id列表
  510. selectEdbInfoIdList := make([]int, 0)
  511. // 选择所有指标,所以需要通过es获取数据
  512. if req.IsSelectAll {
  513. allEsEdbInfoIdList, err := getAllEdbInfoIdListByShared(req, c.SysUser.AdminId)
  514. if err != nil {
  515. br.Msg = "设置失败!"
  516. br.ErrMsg = "设置失败,Err:" + err.Error()
  517. return
  518. }
  519. if len(req.NoEdbIdList) <= 0 {
  520. selectEdbInfoIdList = allEsEdbInfoIdList
  521. } else {
  522. noEdbIdMap := make(map[int]bool)
  523. for _, v := range req.NoEdbIdList {
  524. noEdbIdMap[v] = true
  525. }
  526. for _, v := range allEsEdbInfoIdList {
  527. if _, ok := noEdbIdMap[v]; !ok {
  528. // 如果不在未选中的指标id列表中,那么就加入到选中的指标id列表
  529. selectEdbInfoIdList = append(selectEdbInfoIdList, v)
  530. }
  531. }
  532. }
  533. } else {
  534. selectEdbInfoIdList = req.EdbIdList
  535. }
  536. num := len(selectEdbInfoIdList)
  537. if num > 30 {
  538. br.Msg = `指标数量不能超过30个`
  539. br.IsSendEmail = false
  540. return
  541. }
  542. // 设置
  543. if num > 0 {
  544. obj := data_manage.EdbInfoShare{}
  545. err = obj.SaveEdbInfoShare(selectEdbInfoIdList, req.UserIdList, req.ShareType)
  546. if err != nil {
  547. br.Msg = `保存失败`
  548. br.ErrMsg = `保存失败:` + err.Error()
  549. return
  550. }
  551. // 更新es
  552. for _, edbInfoId := range selectEdbInfoIdList {
  553. data.AddOrEditEdbInfoToEs(edbInfoId)
  554. }
  555. }
  556. br.Ret = 200
  557. br.Success = true
  558. br.Msg = "保存成功"
  559. }
  560. // getAllEdbInfoIdListByShared
  561. // @Description: 获取所有的指标id列表
  562. // @author: Roc
  563. // @datetime 2024-12-04 15:43:14
  564. // @param req request.SetEdbChartPermissionReq
  565. // @param userId int
  566. // @return edbInfoIdList []int
  567. // @return err error
  568. func getAllEdbInfoIdListByShared(req request.SetEdbSharePermissionReq, userId int) (edbInfoIdList []int, err error) {
  569. keyword := req.Keyword
  570. keyword = strings.TrimSpace(keyword) //移除字符串首尾空格
  571. //指标来源
  572. sourceList := req.SourceList
  573. edbInfoType := 0 // 普通指标
  574. edbTypeList := []int{utils.EdbTypeCalculate} // 普通指标中的计算指标
  575. // 指标分享状态:1-未共享;2-已共享。可多选,多选用英文,隔开;默认是未共享
  576. edbShareList := req.EdbShareList
  577. if len(edbShareList) <= 0 {
  578. edbShareList = []int{1}
  579. }
  580. edbShare := 1 // 0:全部,1:未共享,2:已共享
  581. lenEdbShareList := len(edbShareList)
  582. if len(edbShareList) > 0 {
  583. if lenEdbShareList > 1 {
  584. edbShare = 0
  585. } else {
  586. edbShare = edbShareList[0]
  587. }
  588. }
  589. // 指标分享状态:1-未共享;2-已共享。可多选,多选用英文,隔开;默认是未共享
  590. edbClassifyIdList := req.ClassifyIdList
  591. edbAuth := 1 // 选择范围是:只有我的指标
  592. sortMap := make(map[string]string)
  593. // 如果没有搜索关键词,则默认根据指标编码倒序排序
  594. if keyword == `` {
  595. sortMap["EdbInfoId"] = `desc`
  596. }
  597. _, edbInfoList, err := getAllEdbInfoDataByShared(keyword, 1, edbShare, sourceList, edbClassifyIdList, edbTypeList, edbInfoType, edbAuth, userId, sortMap)
  598. if err != nil {
  599. return
  600. }
  601. // 返回指标id列表
  602. for _, v := range edbInfoList {
  603. edbInfoIdList = append(edbInfoIdList, v.EdbInfoId)
  604. }
  605. return
  606. }
  607. // getAllEdbInfoDataByShared
  608. // @Description: 获取所有的指标列表(设置共享的时候)
  609. // @author: Roc
  610. // @datetime 2024-12-04 15:27:53
  611. // @param keyword string
  612. // @param currPage int
  613. // @param edbShare int
  614. // @param sourceList []int
  615. // @param classifyIdList []int
  616. // @param edbTypeList []int
  617. // @param edbInfoType int
  618. // @param edbAuth int
  619. // @param sysUserId int
  620. // @param sortMap map[string]string
  621. // @return total int64
  622. // @return list []*data_manage.EdbInfoList
  623. // @return err error
  624. func getAllEdbInfoDataByShared(keyword string, currPage, edbShare int, sourceList, classifyIdList, edbTypeList []int, edbInfoType, edbAuth, sysUserId int, sortMap map[string]string) (total int64, list []*data_manage.EdbInfoList, err error) {
  625. // 每页获取数据的数量
  626. pageSize := 5000
  627. var startSize int
  628. if currPage <= 0 {
  629. currPage = 1
  630. }
  631. startSize = paging.StartIndex(currPage, pageSize)
  632. total, list, err = elastic.SearchEdbInfoDataByShared(keyword, startSize, pageSize, edbShare, sourceList, classifyIdList, edbTypeList, edbInfoType, edbAuth, sysUserId, sortMap)
  633. if err != nil {
  634. return
  635. }
  636. page := paging.GetPaging(currPage, pageSize, int(total))
  637. if !page.IsEnd {
  638. _, nextList, tmpErr := getAllEdbInfoDataByShared(keyword, page.NextIndex, edbShare, sourceList, classifyIdList, edbTypeList, edbInfoType, edbAuth, sysUserId, sortMap)
  639. if tmpErr != nil {
  640. err = tmpErr
  641. return
  642. }
  643. list = append(list, nextList...)
  644. }
  645. return
  646. }