edb_info_share.go 20 KB

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