chart_info_share.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  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.UserShareChartClassifyItemList
  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.UserShareChartClassifyItemList
  204. for _, v := range nodeList {
  205. index, ok := receivedMap[v.SysUserId]
  206. if !ok {
  207. index = len(receivedMap)
  208. item := &data_manage.UserShareChartClassifyItem{
  209. UserId: v.SysUserId,
  210. ChartInfoId: 0,
  211. UserName: 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.UserShareChartClassifyItem{},
  229. Button: data_manage.ChartClassifyItemsButton{},
  230. IsJoinPermission: 0,
  231. HaveOperaAuth: true,
  232. ChartClassifyIdPath: "",
  233. }
  234. receivedList = append(receivedList, item)
  235. }
  236. receivedList[index].Children = append(receivedList[index].Children, v)
  237. receivedMap[v.SysUserId] = index
  238. }
  239. sort.Sort(receivedList)
  240. resp.Received = receivedList
  241. }
  242. br.Ret = 200
  243. br.Success = true
  244. br.Msg = "获取成功"
  245. br.Data = resp
  246. }
  247. // List
  248. // @Title 图表列表接口
  249. // @Description 图表列表接口
  250. // @Param PageSize query int true "每页数据条数"
  251. // @Param CurrentIndex query int true "当前页页码,从1开始"
  252. // @Param ClassifyId query int true "分类id"
  253. // @Param FilterSource query int false "共享图表的列表数据来源,0:我共享的;1:别人共享给我的"
  254. // @Param ClassifyId query int false "分类id"
  255. // @Param UserId query int false "所属用户id"
  256. // @Success 200 {object} response.ChartInfoChartListResp
  257. // @router /chart_info/share/list [get]
  258. func (c *ChartInfoShareController) List() {
  259. br := new(models.BaseResponse).Init()
  260. defer func() {
  261. if br.ErrMsg == "" {
  262. br.IsSendEmail = false
  263. }
  264. c.Data["json"] = br
  265. c.ServeJSON()
  266. }()
  267. sysUser := c.SysUser
  268. if sysUser == nil {
  269. br.Msg = "请登录"
  270. br.ErrMsg = "请登录,SysUser Is Empty"
  271. br.Ret = 408
  272. return
  273. }
  274. // 分页
  275. pageSize, _ := c.GetInt("PageSize")
  276. currentIndex, _ := c.GetInt("CurrentIndex")
  277. filterSource, _ := c.GetInt("FilterSource")
  278. var total int
  279. page := paging.GetPaging(currentIndex, pageSize, total)
  280. var startSize int
  281. if pageSize <= 0 {
  282. pageSize = utils.PageSize20
  283. }
  284. if currentIndex <= 0 {
  285. currentIndex = 1
  286. }
  287. startSize = paging.StartIndex(currentIndex, pageSize)
  288. // 基础图表
  289. var condition string
  290. var pars []interface{}
  291. condition += ` AND source = ? `
  292. pars = append(pars, utils.CHART_TYPE_CURVE)
  293. // 用户筛选
  294. userId, _ := c.GetInt("UserId")
  295. if userId > 0 {
  296. condition += ` AND b.sys_user_id = ? `
  297. pars = append(pars, userId)
  298. }
  299. // 分类筛选
  300. classifyId, _ := c.GetInt("ClassifyId")
  301. if classifyId > 0 {
  302. childClassify, e, _ := data.GetChildClassifyByClassifyId(classifyId)
  303. if e != nil && !utils.IsErrNoRow(e) {
  304. br.Msg = "获取失败"
  305. br.ErrMsg = "获取分类信息失败, GetChartClassify,Err:" + e.Error()
  306. return
  307. }
  308. var classifyIds []int
  309. for _, v := range childClassify {
  310. classifyIds = append(classifyIds, v.ClassifyId)
  311. }
  312. condition += fmt.Sprintf(` AND b.classify_id IN (%s) `, utils.GetOrmInReplace(len(classifyIds)))
  313. pars = append(pars, classifyIds)
  314. }
  315. switch filterSource {
  316. case 1: // 别人共享给我的
  317. condition += ` AND a.sys_user_id = ? AND b.sys_user_id != ? `
  318. pars = append(pars, sysUser.AdminId, sysUser.AdminId)
  319. default: // 我共享的
  320. condition += ` AND b.sys_user_id = ? `
  321. pars = append(pars, sysUser.AdminId)
  322. }
  323. obj := data_manage.ChartInfoShare{}
  324. dataCount, respList, err := obj.GetShareChartInfoListPageList(condition, pars, startSize, pageSize)
  325. if err != nil {
  326. br.Msg = "获取失败"
  327. br.ErrMsg = fmt.Sprintf("获取分享图表列表失败, %v", err)
  328. return
  329. }
  330. page = paging.GetPaging(currentIndex, pageSize, int(dataCount))
  331. resp := response.ChartInfoChartListResp{
  332. Paging: page,
  333. List: respList,
  334. }
  335. br.Ret = 200
  336. br.Success = true
  337. br.Msg = "获取成功"
  338. br.Data = resp
  339. }
  340. // ListByEs
  341. // @Title 图表筛选接口
  342. // @Description 图表筛选接口
  343. // @Success 200 {object} data_manage.ChartInfoList
  344. // @Param request body request.SearchChartInfoShareReq true "type json string"
  345. // @Success 200 {object} data_manage.ChartInfoFilterDataResp
  346. // @router /chart_info/share/list/es [post]
  347. func (c *ChartInfoShareController) ListByEs() {
  348. br := new(models.BaseResponse).Init()
  349. defer func() {
  350. c.Data["json"] = br
  351. c.ServeJSON()
  352. }()
  353. var req request.SearchChartInfoShareReq
  354. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  355. if err != nil {
  356. br.Msg = "参数解析异常!"
  357. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  358. return
  359. }
  360. pageSize := req.PageSize
  361. currentIndex := req.CurrentIndex
  362. var total int64
  363. var startSize int
  364. if pageSize <= 0 {
  365. pageSize = utils.PageSize20
  366. }
  367. if currentIndex <= 0 {
  368. currentIndex = 1
  369. }
  370. startSize = paging.StartIndex(currentIndex, pageSize)
  371. keyword := req.Keyword
  372. keyword = strings.TrimSpace(keyword) //移除字符串首尾空格
  373. sourceList := []int{utils.CHART_TYPE_CURVE}
  374. // 图表分享状态:1-未共享;2-已共享。可多选,多选用英文,隔开;默认是未全部
  375. chartShareList := req.ChartShareList
  376. if len(chartShareList) <= 0 {
  377. chartShareList = []int{}
  378. }
  379. chartShare := 0 // 0:全部,1:未共享,2:已共享
  380. lenChartShareList := len(chartShareList)
  381. if len(chartShareList) > 0 {
  382. if lenChartShareList > 1 {
  383. chartShare = 0
  384. } else {
  385. chartShare = chartShareList[0]
  386. }
  387. }
  388. // 图表类型
  389. chartTypeList := req.ChartTypeList
  390. // 直图表所属分类id
  391. chartClassifyIdList := req.ClassifyIdList
  392. chartAuth := 1 // 选择范围是:只有我的图表
  393. var chartInfoList []*data_manage.ChartInfoView
  394. sortMap := make(map[string]string)
  395. // 如果没有搜索关键词,则默认根据图表编码倒序排序
  396. if keyword == `` {
  397. sortMap["ChartInfoId"] = `desc`
  398. }
  399. total, chartInfoList, err = elastic.SearchChartInfoDataByShared(keyword, startSize, pageSize, chartShare, sourceList, chartTypeList, chartClassifyIdList, chartAuth, c.SysUser.AdminId, sortMap)
  400. if err != nil {
  401. chartInfoList = make([]*data_manage.ChartInfoView, 0)
  402. }
  403. page := paging.GetPaging(currentIndex, pageSize, int(total))
  404. // 因为是ES查找的,所以需要重新查一下图表的信息,主要是为了把是否授权字段找出来
  405. if len(chartInfoList) > 0 {
  406. sysUserIdList := make([]int, 0)
  407. chartInfoIdList := make([]int, 0)
  408. for _, v := range chartInfoList {
  409. v.ConvertToResp()
  410. v.HaveOperaAuth = true
  411. chartInfoIdList = append(chartInfoIdList, v.ChartInfoId)
  412. if v.SharedUserIdList != nil && len(v.SharedUserIdList) > 0 {
  413. sysUserIdList = append(sysUserIdList, v.SharedUserIdList...)
  414. }
  415. }
  416. // 获取图表数据
  417. tmpChartList, err := data_manage.GetChartInfoByIdList(chartInfoIdList)
  418. if err != nil {
  419. br.Msg = "获取失败"
  420. br.ErrMsg = "获取所有有权限的图表失败,Err:" + err.Error()
  421. return
  422. }
  423. chartInfoMap := make(map[int]*data_manage.ChartInfo)
  424. for _, v := range tmpChartList {
  425. chartInfoMap[v.ChartInfoId] = 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 chartInfoList {
  441. tmpChartInfo, ok := chartInfoMap[v.ChartInfoId]
  442. if !ok {
  443. continue
  444. }
  445. v.IsJoinPermission = tmpChartInfo.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. resp := data_manage.ChartInfoFilterDataResp{
  463. Paging: page,
  464. List: chartInfoList,
  465. }
  466. br.Ret = 200
  467. br.Success = true
  468. br.Msg = "获取成功"
  469. br.Data = resp
  470. }
  471. // BatchSave
  472. // @Title 批量图表设置共享
  473. // @Description 批量图表设置共享
  474. // @Param request body request.SetChartSharePermissionReq true "type json string"
  475. // @Success 200 {object} data_manage.ChartInfo
  476. // @router /chart_info/share/batch_save [post]
  477. func (c *ChartInfoShareController) BatchSave() {
  478. br := new(models.BaseResponse).Init()
  479. defer func() {
  480. c.Data["json"] = br
  481. c.ServeJSON()
  482. }()
  483. sysUser := c.SysUser
  484. if sysUser == nil {
  485. br.Msg = "请登录"
  486. br.ErrMsg = "请登录,SysUser Is Empty"
  487. br.Ret = 408
  488. return
  489. }
  490. var req request.SetChartSharePermissionReq
  491. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  492. if err != nil {
  493. br.Msg = "参数解析异常!"
  494. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  495. return
  496. }
  497. // 选中的图表id列表
  498. selectChartInfoIdList := make([]int, 0)
  499. // 选择所有图表,所以需要通过es获取数据
  500. if req.IsSelectAll {
  501. allEsChartInfoIdList, err := getAllChartInfoIdListByShared(req, c.SysUser.AdminId)
  502. if err != nil {
  503. br.Msg = "设置失败!"
  504. br.ErrMsg = "设置失败,Err:" + err.Error()
  505. return
  506. }
  507. if len(req.NoChartIdList) <= 0 {
  508. selectChartInfoIdList = allEsChartInfoIdList
  509. } else {
  510. noChartIdMap := make(map[int]bool)
  511. for _, v := range req.NoChartIdList {
  512. noChartIdMap[v] = true
  513. }
  514. for _, v := range allEsChartInfoIdList {
  515. if _, ok := noChartIdMap[v]; !ok {
  516. // 如果不在未选中的图表id列表中,那么就加入到选中的图表id列表
  517. selectChartInfoIdList = append(selectChartInfoIdList, v)
  518. }
  519. }
  520. }
  521. } else {
  522. selectChartInfoIdList = req.ChartIdList
  523. }
  524. num := len(selectChartInfoIdList)
  525. if num > 30 {
  526. br.Msg = `图表数量不能超过30个`
  527. br.IsSendEmail = false
  528. return
  529. }
  530. // 设置
  531. if num > 0 {
  532. obj := data_manage.ChartInfoShare{}
  533. err = obj.SaveChartInfoShare(selectChartInfoIdList, req.UserIdList, req.ShareType)
  534. if err != nil {
  535. br.Msg = `保存失败`
  536. br.ErrMsg = `保存失败:` + err.Error()
  537. return
  538. }
  539. // 更新es
  540. for _, chartInfoId := range selectChartInfoIdList {
  541. data.AddOrEditChartInfoToEs(chartInfoId)
  542. }
  543. }
  544. br.Ret = 200
  545. br.Success = true
  546. br.Msg = "保存成功"
  547. }
  548. // getAllChartInfoIdListByShared
  549. // @Description: 获取所有的图表id列表
  550. // @author: Roc
  551. // @datetime 2024-12-10 17:51:35
  552. // @param req request.SetChartSharePermissionReq
  553. // @param userId int
  554. // @return chartInfoIdList []int
  555. // @return err error
  556. func getAllChartInfoIdListByShared(req request.SetChartSharePermissionReq, userId int) (chartInfoIdList []int, err error) {
  557. keyword := req.Keyword
  558. keyword = strings.TrimSpace(keyword) //移除字符串首尾空格
  559. //图表来源
  560. sourceList := []int{utils.CHART_TYPE_CURVE}
  561. // 图表分享状态:1-未共享;2-已共享。可多选,多选用英文,隔开;默认是未共享
  562. chartShareList := req.ChartShareList
  563. if len(chartShareList) <= 0 {
  564. chartShareList = []int{1}
  565. }
  566. chartShare := 1 // 0:全部,1:未共享,2:已共享
  567. lenChartShareList := len(chartShareList)
  568. if len(chartShareList) > 0 {
  569. if lenChartShareList > 1 {
  570. chartShare = 0
  571. } else {
  572. chartShare = chartShareList[0]
  573. }
  574. }
  575. // 图表类型
  576. chartTypeList := req.ChartTypeList
  577. // 图表分享状态:1-未共享;2-已共享。可多选,多选用英文,隔开;默认是未共享
  578. chartClassifyIdList := req.ClassifyIdList
  579. chartAuth := 1 // 选择范围是:只有我的图表
  580. sortMap := make(map[string]string)
  581. // 如果没有搜索关键词,则默认根据图表编码倒序排序
  582. if keyword == `` {
  583. sortMap["ChartInfoId"] = `desc`
  584. }
  585. _, chartInfoList, err := getAllChartInfoDataByShared(keyword, 1, chartShare, sourceList, chartTypeList, chartClassifyIdList, chartAuth, userId, sortMap)
  586. if err != nil {
  587. return
  588. }
  589. // 返回图表id列表
  590. for _, v := range chartInfoList {
  591. chartInfoIdList = append(chartInfoIdList, v.ChartInfoId)
  592. }
  593. return
  594. }
  595. // getAllChartInfoDataByShared
  596. // @Description: 获取所有的图表列表(设置共享的时候)
  597. // @author: Roc
  598. // @datetime 2024-12-10 17:51:18
  599. // @param keyword string
  600. // @param currPage int
  601. // @param chartShare int
  602. // @param sourceList []int
  603. // @param classifyIdList []int
  604. // @param chartAuth int
  605. // @param sysUserId int
  606. // @param sortMap map[string]string
  607. // @return total int64
  608. // @return list []*data_manage.ChartInfoView
  609. // @return err error
  610. 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) {
  611. // 每页获取数据的数量
  612. pageSize := 5000
  613. var startSize int
  614. if currPage <= 0 {
  615. currPage = 1
  616. }
  617. startSize = paging.StartIndex(currPage, pageSize)
  618. total, list, err = elastic.SearchChartInfoDataByShared(keyword, startSize, pageSize, chartShare, sourceList, chartTypeList, classifyIdList, chartAuth, sysUserId, sortMap)
  619. if err != nil {
  620. return
  621. }
  622. page := paging.GetPaging(currPage, pageSize, int(total))
  623. if !page.IsEnd {
  624. _, nextList, tmpErr := getAllChartInfoDataByShared(keyword, page.NextIndex, chartShare, sourceList, chartTypeList, classifyIdList, chartAuth, sysUserId, sortMap)
  625. if tmpErr != nil {
  626. err = tmpErr
  627. return
  628. }
  629. list = append(list, nextList...)
  630. }
  631. return
  632. }