chart_info_share.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722
  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. chartInfo, err := data_manage.GetChartInfoById(chartInfoId)
  49. if err != nil {
  50. br.Msg = "获取失败"
  51. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  52. return
  53. }
  54. if chartInfo.SysUserId != sysUser.AdminId {
  55. br.Msg = "您没有权限设置共享"
  56. br.ErrMsg = "您没有权限设置共享,ChartInfoId:" + strconv.Itoa(chartInfoId)
  57. br.IsSendEmail = false
  58. return
  59. }
  60. resp := response.ChartInfoShareUserResp{}
  61. obj := data_manage.ChartInfoShare{}
  62. list, err := obj.GetListByChartInfoId(chartInfoId)
  63. if err != nil {
  64. br.Msg = `获取失败`
  65. br.ErrMsg = `获取失败:` + err.Error()
  66. return
  67. }
  68. resp.List = list
  69. br.Ret = 200
  70. br.Success = true
  71. br.Msg = "获取成功"
  72. br.Data = resp
  73. }
  74. // Save
  75. // @Title 单个图表设置共享
  76. // @Description 单个图表设置共享
  77. // @Param request body request.SetChartInfoShareReq true "type json string"
  78. // @Success 200 {object} data_manage.ChartInfo
  79. // @router /chart_info/share/save [post]
  80. func (c *ChartInfoShareController) Save() {
  81. br := new(models.BaseResponse).Init()
  82. defer func() {
  83. c.Data["json"] = br
  84. c.ServeJSON()
  85. }()
  86. sysUser := c.SysUser
  87. if sysUser == nil {
  88. br.Msg = "请登录"
  89. br.ErrMsg = "请登录,SysUser Is Empty"
  90. br.Ret = 408
  91. return
  92. }
  93. var req request.SetChartInfoShareReq
  94. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  95. if err != nil {
  96. br.Msg = "参数解析异常!"
  97. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  98. return
  99. }
  100. if req.ChartInfoId <= 0 {
  101. br.Msg = `请选择图表`
  102. br.IsSendEmail = false
  103. return
  104. }
  105. chartItem, err := data_manage.GetChartInfoById(req.ChartInfoId)
  106. if err != nil {
  107. br.Msg = "查找图表失败"
  108. br.ErrMsg = "查找图表失败,Err:" + err.Error()
  109. return
  110. }
  111. if chartItem.ChartInfoId <= 0 {
  112. br.Msg = "图表不存在"
  113. br.ErrMsg = "图表不存在,ChartInfoId:" + strconv.Itoa(req.ChartInfoId)
  114. br.IsSendEmail = false
  115. return
  116. }
  117. if chartItem.SysUserId != c.SysUser.AdminId {
  118. br.Msg = "您没有权限设置共享"
  119. br.ErrMsg = "您没有权限设置共享,EdbInfoId:" + strconv.Itoa(req.ChartInfoId)
  120. br.IsSendEmail = false
  121. return
  122. }
  123. obj := data_manage.ChartInfoShare{}
  124. err = obj.SaveChartInfoShare([]int{req.ChartInfoId}, req.UserIdList, req.ShareType)
  125. if err != nil {
  126. br.Msg = `保存失败`
  127. br.ErrMsg = `保存失败:` + err.Error()
  128. return
  129. }
  130. // 更新es
  131. data.AddOrEditChartInfoToEs(req.ChartInfoId)
  132. br.Ret = 200
  133. br.Success = true
  134. br.Msg = "保存成功"
  135. }
  136. // Tree
  137. // @Title 获取共享图表的分类/图表树
  138. // @Description 获取共享图表的分类/图表树
  139. // @Success 200 {object} response.ChartShareListResp
  140. // @router /chart_info/share/tree [get]
  141. func (c *ChartInfoShareController) Tree() {
  142. br := new(models.BaseResponse).Init()
  143. defer func() {
  144. c.Data["json"] = br
  145. c.ServeJSON()
  146. }()
  147. sysUser := c.SysUser
  148. if sysUser == nil {
  149. br.Msg = "请登录"
  150. br.ErrMsg = "请登录,SysUser Is Empty"
  151. br.Ret = 408
  152. return
  153. }
  154. resp := response.ChartShareListResp{}
  155. // 我共享的
  156. {
  157. sendList, err := data.GetAllShareChartListByFromUserId(sysUser.AdminId)
  158. if err != nil {
  159. br.Msg = "获取失败"
  160. br.ErrMsg = "获取我共享的图表列表信息失败,Err:" + err.Error()
  161. return
  162. }
  163. nodeList, err := data.GetChartClassifyItemListByShareChartInfoQueryList(sendList)
  164. if err != nil {
  165. br.Msg = "获取失败"
  166. br.ErrMsg = "获取我共享出去的图表列表分类结构信息失败,Err:" + err.Error()
  167. return
  168. }
  169. var sortList data_manage.UserShareChartClassifyItemList
  170. sortList = nodeList
  171. sort.Sort(sortList)
  172. resp.Send = sortList
  173. }
  174. // 我收到的
  175. {
  176. sendList, err := data.GetAllShareChartListByReceivedUserId(sysUser.AdminId)
  177. if err != nil {
  178. br.Msg = "获取失败"
  179. br.ErrMsg = "获取我共享的图表列表信息失败,Err:" + err.Error()
  180. return
  181. }
  182. nodeList, err := data.GetChartClassifyItemListByShareChartInfoQueryList(sendList)
  183. if err != nil {
  184. br.Msg = "获取失败"
  185. br.ErrMsg = "获取我收到共享的图表列表分类结构信息失败,Err:" + err.Error()
  186. return
  187. }
  188. receivedMap := make(map[int]int)
  189. var receivedList data_manage.UserShareChartClassifyItemList
  190. for _, v := range nodeList {
  191. index, ok := receivedMap[v.SysUserId]
  192. if !ok {
  193. index = len(receivedMap)
  194. item := &data_manage.UserShareChartClassifyItem{
  195. UserId: v.SysUserId,
  196. UserName: v.SysUserRealName,
  197. ChartInfoId: 0,
  198. ChartClassifyId: v.SysUserId,
  199. ChartClassifyName: v.SysUserRealName,
  200. ChartClassifyNameEn: v.SysUserRealName,
  201. ParentId: 0,
  202. Level: 0,
  203. Sort: 0,
  204. UniqueCode: utils.MD5(fmt.Sprint(v.SysUserId, "_", v.SysUserRealName)),
  205. Source: 0,
  206. SourceName: "",
  207. SysUserId: v.SysUserId,
  208. SysUserRealName: v.SysUserRealName,
  209. DateType: 0,
  210. StartDate: "",
  211. EndDate: "",
  212. ChartType: 0,
  213. Calendar: "",
  214. SeasonStartDate: "",
  215. SeasonEndDate: "",
  216. Children: []*data_manage.UserShareChartClassifyItem{},
  217. Button: data_manage.ChartClassifyItemsButton{},
  218. IsJoinPermission: 0,
  219. HaveOperaAuth: true,
  220. ChartClassifyIdPath: "",
  221. }
  222. receivedList = append(receivedList, item)
  223. }
  224. receivedList[index].Children = append(receivedList[index].Children, v)
  225. receivedMap[v.SysUserId] = index
  226. }
  227. sort.Sort(receivedList)
  228. resp.Received = receivedList
  229. }
  230. br.Ret = 200
  231. br.Success = true
  232. br.Msg = "获取成功"
  233. br.Data = resp
  234. }
  235. // List
  236. // @Title 图表列表接口
  237. // @Description 图表列表接口
  238. // @Param PageSize query int true "每页数据条数"
  239. // @Param CurrentIndex query int true "当前页页码,从1开始"
  240. // @Param ClassifyId query int true "分类id"
  241. // @Param FilterSource query int false "共享图表的列表数据来源,0:我共享的;1:别人共享给我的"
  242. // @Param ClassifyId query int false "分类id"
  243. // @Param UserId query int false "所属用户id"
  244. // @Success 200 {object} response.ChartInfoChartListResp
  245. // @router /chart_info/share/list [get]
  246. func (c *ChartInfoShareController) List() {
  247. br := new(models.BaseResponse).Init()
  248. defer func() {
  249. if br.ErrMsg == "" {
  250. br.IsSendEmail = false
  251. }
  252. c.Data["json"] = br
  253. c.ServeJSON()
  254. }()
  255. sysUser := c.SysUser
  256. if sysUser == nil {
  257. br.Msg = "请登录"
  258. br.ErrMsg = "请登录,SysUser Is Empty"
  259. br.Ret = 408
  260. return
  261. }
  262. // 分页
  263. pageSize, _ := c.GetInt("PageSize")
  264. currentIndex, _ := c.GetInt("CurrentIndex")
  265. filterSource, _ := c.GetInt("FilterSource")
  266. var total int
  267. page := paging.GetPaging(currentIndex, pageSize, total)
  268. var startSize int
  269. if pageSize <= 0 {
  270. pageSize = utils.PageSize20
  271. }
  272. if currentIndex <= 0 {
  273. currentIndex = 1
  274. }
  275. startSize = paging.StartIndex(currentIndex, pageSize)
  276. // 基础图表
  277. var condition string
  278. var pars []interface{}
  279. condition += ` AND source = ? `
  280. pars = append(pars, utils.CHART_TYPE_CURVE)
  281. // 用户筛选
  282. userId, _ := c.GetInt("UserId")
  283. if userId > 0 {
  284. condition += ` AND b.sys_user_id = ? `
  285. pars = append(pars, userId)
  286. }
  287. // 分类筛选
  288. classifyId, _ := c.GetInt("ClassifyId")
  289. if classifyId > 0 {
  290. childClassify, e, _ := data.GetChildChartClassifyByClassifyId(classifyId)
  291. if e != nil && !utils.IsErrNoRow(e) {
  292. br.Msg = "获取失败"
  293. br.ErrMsg = "获取分类信息失败, GetChartClassify,Err:" + e.Error()
  294. return
  295. }
  296. var classifyIds []int
  297. for _, v := range childClassify {
  298. classifyIds = append(classifyIds, v.ChartClassifyId)
  299. }
  300. condition += fmt.Sprintf(` AND b.chart_classify_id IN (%s) `, utils.GetOrmInReplace(len(classifyIds)))
  301. pars = append(pars, classifyIds)
  302. }
  303. switch filterSource {
  304. case 1: // 别人共享给我的
  305. condition += ` AND a.sys_user_id = ? AND b.sys_user_id != ? `
  306. pars = append(pars, sysUser.AdminId, sysUser.AdminId)
  307. default: // 我共享的
  308. condition += ` AND b.sys_user_id = ? `
  309. pars = append(pars, sysUser.AdminId)
  310. }
  311. obj := data_manage.ChartInfoShare{}
  312. dataCount, respList, err := obj.GetShareChartInfoListPageList(condition, pars, startSize, pageSize)
  313. if err != nil {
  314. br.Msg = "获取失败"
  315. br.ErrMsg = fmt.Sprintf("获取分享图表列表失败, %v", err)
  316. return
  317. }
  318. editShareEdbInfoIdMap, err := data.GetAllEditSharedChartInfoIdMapByReceivedUserId(c.SysUser.AdminId)
  319. if err != nil {
  320. br.Msg = "获取失败"
  321. br.ErrMsg = "获取所有有编辑权限的分享指标失败,Err:" + err.Error()
  322. return
  323. }
  324. for _, chartInfo := range respList {
  325. chartInfo.HaveOperaAuth = true
  326. button := data.GetChartOpButton(c.SysUser, chartInfo.SysUserId, chartInfo.ChartInfoId, chartInfo.HaveOperaAuth, editShareEdbInfoIdMap)
  327. chartInfo.Button.IsEdit = button.OpButton
  328. chartInfo.Button.IsCopy = button.DeleteButton
  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. shareUserNameMap := make(map[int]bool)
  450. for _, userId := range v.SharedUserIdList {
  451. userName, ok := sysUserMap[userId]
  452. if !ok {
  453. continue
  454. }
  455. if _, ok = shareUserNameMap[userId]; ok {
  456. continue
  457. }
  458. shareUserNameMap[userId] = true
  459. shareUserNameList = append(shareUserNameList, userName)
  460. }
  461. if len(shareUserNameList) > 0 {
  462. shareUserName = strings.Join(shareUserNameList, `,`)
  463. }
  464. v.SharedUserName = shareUserName
  465. }
  466. }
  467. resp := data_manage.ChartInfoFilterDataResp{
  468. Paging: page,
  469. List: chartInfoList,
  470. }
  471. br.Ret = 200
  472. br.Success = true
  473. br.Msg = "获取成功"
  474. br.Data = resp
  475. }
  476. // BatchSave
  477. // @Title 批量图表设置共享
  478. // @Description 批量图表设置共享
  479. // @Param request body request.SetChartSharePermissionReq true "type json string"
  480. // @Success 200 {object} data_manage.ChartInfo
  481. // @router /chart_info/share/batch_save [post]
  482. func (c *ChartInfoShareController) BatchSave() {
  483. br := new(models.BaseResponse).Init()
  484. defer func() {
  485. c.Data["json"] = br
  486. c.ServeJSON()
  487. }()
  488. sysUser := c.SysUser
  489. if sysUser == nil {
  490. br.Msg = "请登录"
  491. br.ErrMsg = "请登录,SysUser Is Empty"
  492. br.Ret = 408
  493. return
  494. }
  495. var req request.SetChartSharePermissionReq
  496. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  497. if err != nil {
  498. br.Msg = "参数解析异常!"
  499. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  500. return
  501. }
  502. // 选中的图表id列表
  503. selectChartInfoIdList := make([]int, 0)
  504. // 选择所有图表,所以需要通过es获取数据
  505. if req.IsSelectAll {
  506. allEsChartInfoIdList, err := getAllChartInfoIdListByShared(req, c.SysUser.AdminId)
  507. if err != nil {
  508. br.Msg = "设置失败!"
  509. br.ErrMsg = "设置失败,Err:" + err.Error()
  510. return
  511. }
  512. if len(req.NoChartIdList) <= 0 {
  513. selectChartInfoIdList = allEsChartInfoIdList
  514. } else {
  515. noChartIdMap := make(map[int]bool)
  516. for _, v := range req.NoChartIdList {
  517. noChartIdMap[v] = true
  518. }
  519. for _, v := range allEsChartInfoIdList {
  520. if _, ok := noChartIdMap[v]; !ok {
  521. // 如果不在未选中的图表id列表中,那么就加入到选中的图表id列表
  522. selectChartInfoIdList = append(selectChartInfoIdList, v)
  523. }
  524. }
  525. }
  526. } else {
  527. selectChartInfoIdList = req.ChartIdList
  528. }
  529. num := len(selectChartInfoIdList)
  530. if num > 30 {
  531. br.Msg = `图表数量不能超过30个`
  532. br.IsSendEmail = false
  533. return
  534. }
  535. // 设置
  536. if num > 0 {
  537. obj := data_manage.ChartInfoShare{}
  538. err = obj.SaveChartInfoShare(selectChartInfoIdList, req.UserIdList, req.ShareType)
  539. if err != nil {
  540. br.Msg = `保存失败`
  541. br.ErrMsg = `保存失败:` + err.Error()
  542. return
  543. }
  544. // 更新es
  545. for _, chartInfoId := range selectChartInfoIdList {
  546. data.AddOrEditChartInfoToEs(chartInfoId)
  547. }
  548. }
  549. br.Ret = 200
  550. br.Success = true
  551. br.Msg = "保存成功"
  552. }
  553. // getAllChartInfoIdListByShared
  554. // @Description: 获取所有的图表id列表
  555. // @author: Roc
  556. // @datetime 2024-12-10 17:51:35
  557. // @param req request.SetChartSharePermissionReq
  558. // @param userId int
  559. // @return chartInfoIdList []int
  560. // @return err error
  561. func getAllChartInfoIdListByShared(req request.SetChartSharePermissionReq, userId int) (chartInfoIdList []int, err error) {
  562. keyword := req.Keyword
  563. keyword = strings.TrimSpace(keyword) //移除字符串首尾空格
  564. //图表来源
  565. sourceList := []int{utils.CHART_TYPE_CURVE}
  566. // 图表分享状态:1-未共享;2-已共享。可多选,多选用英文,隔开;默认是未共享
  567. chartShareList := req.ChartShareList
  568. if len(chartShareList) <= 0 {
  569. chartShareList = []int{1}
  570. }
  571. chartShare := 1 // 0:全部,1:未共享,2:已共享
  572. lenChartShareList := len(chartShareList)
  573. if len(chartShareList) > 0 {
  574. if lenChartShareList > 1 {
  575. chartShare = 0
  576. } else {
  577. chartShare = chartShareList[0]
  578. }
  579. }
  580. // 图表类型
  581. chartTypeList := req.ChartTypeList
  582. // 图表分享状态:1-未共享;2-已共享。可多选,多选用英文,隔开;默认是未共享
  583. chartClassifyIdList := req.ClassifyIdList
  584. chartAuth := 1 // 选择范围是:只有我的图表
  585. sortMap := make(map[string]string)
  586. // 如果没有搜索关键词,则默认根据图表编码倒序排序
  587. if keyword == `` {
  588. sortMap["ChartInfoId"] = `desc`
  589. }
  590. _, chartInfoList, err := getAllChartInfoDataByShared(keyword, 1, chartShare, sourceList, chartTypeList, chartClassifyIdList, chartAuth, userId, sortMap)
  591. if err != nil {
  592. return
  593. }
  594. // 返回图表id列表
  595. for _, v := range chartInfoList {
  596. chartInfoIdList = append(chartInfoIdList, v.ChartInfoId)
  597. }
  598. return
  599. }
  600. // getAllChartInfoDataByShared
  601. // @Description: 获取所有的图表列表(设置共享的时候)
  602. // @author: Roc
  603. // @datetime 2024-12-10 17:51:18
  604. // @param keyword string
  605. // @param currPage int
  606. // @param chartShare int
  607. // @param sourceList []int
  608. // @param classifyIdList []int
  609. // @param chartAuth int
  610. // @param sysUserId int
  611. // @param sortMap map[string]string
  612. // @return total int64
  613. // @return list []*data_manage.ChartInfoView
  614. // @return err error
  615. 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) {
  616. // 每页获取数据的数量
  617. pageSize := 5000
  618. var startSize int
  619. if currPage <= 0 {
  620. currPage = 1
  621. }
  622. startSize = paging.StartIndex(currPage, pageSize)
  623. total, list, err = elastic.SearchChartInfoDataByShared(keyword, startSize, pageSize, chartShare, sourceList, chartTypeList, classifyIdList, chartAuth, sysUserId, sortMap)
  624. if err != nil {
  625. return
  626. }
  627. page := paging.GetPaging(currPage, pageSize, int(total))
  628. if !page.IsEnd {
  629. _, nextList, tmpErr := getAllChartInfoDataByShared(keyword, page.NextIndex, chartShare, sourceList, chartTypeList, classifyIdList, chartAuth, sysUserId, sortMap)
  630. if tmpErr != nil {
  631. err = tmpErr
  632. return
  633. }
  634. list = append(list, nextList...)
  635. }
  636. return
  637. }