edb_info_share.go 19 KB

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