edb_info_share.go 19 KB

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