chart_info_share.go 19 KB

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