chart_info_share.go 19 KB

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