public_chart.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  1. package data_manage
  2. import (
  3. "encoding/json"
  4. "eta_gn/eta_api/cache"
  5. "eta_gn/eta_api/controllers"
  6. "eta_gn/eta_api/models"
  7. "eta_gn/eta_api/models/data_manage"
  8. "eta_gn/eta_api/models/data_manage/data_approve"
  9. "eta_gn/eta_api/models/data_manage/request"
  10. "eta_gn/eta_api/models/system"
  11. "eta_gn/eta_api/services/data"
  12. dataApproveSerice "eta_gn/eta_api/services/data/data_approve"
  13. "eta_gn/eta_api/services/elastic"
  14. "eta_gn/eta_api/utils"
  15. "fmt"
  16. "github.com/rdlucklib/rdluck_tools/paging"
  17. "strconv"
  18. "strings"
  19. )
  20. // ChartPublicController 公共图表
  21. type ChartPublicController struct {
  22. controllers.BaseAuthController
  23. }
  24. // Save
  25. // @Title 单个图表设置公开
  26. // @Description 单个图表设置公开
  27. // @Param request body request.SetChartInfoShareReq true "type json string"
  28. // @Success 200 {object} data_manage.ChartInfo
  29. // @router /chart_info/public/save [post]
  30. func (c *ChartPublicController) Save() {
  31. br := new(models.BaseResponse).Init()
  32. defer func() {
  33. c.Data["json"] = br
  34. c.ServeJSON()
  35. }()
  36. sysUser := c.SysUser
  37. if sysUser == nil {
  38. br.Msg = "请登录"
  39. br.ErrMsg = "请登录,SysUser Is Empty"
  40. br.Ret = 408
  41. return
  42. }
  43. var req request.SetChartPublicReq
  44. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  45. if err != nil {
  46. br.Msg = "参数解析异常!"
  47. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  48. return
  49. }
  50. if len(req.ChartInfoList) <= 0 {
  51. br.Msg = `请选择图表`
  52. br.IsSendEmail = false
  53. return
  54. }
  55. // 待处理的资产
  56. dataPublicItemList := make([]dataApproveSerice.SetDataPublicItem, 0)
  57. // 校验是否重复存在已公开、已提交的图表
  58. {
  59. chartInfoIdList := make([]int, 0)
  60. for _, item := range req.ChartInfoList {
  61. chartInfoIdList = append(chartInfoIdList, item.ChartInfoId)
  62. dataPublicItemList = append(dataPublicItemList, dataApproveSerice.SetDataPublicItem{
  63. DataId: item.ChartInfoId,
  64. ClassifyId: item.ClassifyId,
  65. })
  66. }
  67. list, err := data_manage.GetChartInfoByIdList(chartInfoIdList)
  68. if err != nil {
  69. br.Msg = "保存失败!"
  70. br.ErrMsg = "获取图表数据失败,Err:" + err.Error()
  71. return
  72. }
  73. for _, v := range list {
  74. if v.PublicStatus != utils.DataPublicDefault {
  75. br.Msg = `选择图表中存在已经公开/提交审批的图表,请仅选择未公开图表!`
  76. br.IsSendEmail = false
  77. return
  78. }
  79. }
  80. }
  81. // 校验是否开启了审批流
  82. opening, e := dataApproveSerice.CheckOpenApprove(utils.DataApproveTypeChart)
  83. if e != nil {
  84. br.Msg = "操作失败"
  85. br.ErrMsg = "校验图表公开是否开启审批流失败, Err: " + e.Error()
  86. return
  87. }
  88. // 是否忽略审批
  89. var isIgnoreApprove bool
  90. {
  91. businessConf, e := models.GetBusinessConfByKey(models.IgnoreChartApproveUserId)
  92. if e != nil {
  93. br.Msg = "获取失败"
  94. br.ErrMsg = "获取商家配置失败, Err: " + e.Error()
  95. return
  96. }
  97. ignoreChartApproveUserIdList := strings.Split(businessConf.ConfVal, `,`)
  98. if utils.InArrayByStr(ignoreChartApproveUserIdList, strconv.Itoa(c.SysUser.AdminId)) {
  99. isIgnoreApprove = true
  100. }
  101. }
  102. chartInfo, err := data_manage.GetChartInfoById(req.ChartInfoList[0].ChartInfoId)
  103. if err != nil {
  104. br.Msg = "获取图表失败"
  105. br.ErrMsg = "获取图表失败:" + err.Error()
  106. return
  107. }
  108. title := chartInfo.ChartName
  109. if len(req.ChartInfoList) > 1 {
  110. title += `等图表`
  111. }
  112. title += `公开审批`
  113. // 没开启审批流、或者无需审批
  114. if !opening || isIgnoreApprove {
  115. err = dataApproveSerice.UpdatePublicByDataList(utils.DataApproveTypeChart, dataApproveSerice.DataApproveStatePass, dataPublicItemList)
  116. } else {
  117. _, err = dataApproveSerice.SubmitDataApprove(utils.DataApproveTypeChart, dataPublicItemList, title, strings.TrimSpace(req.Description), c.SysUser.AdminId, c.SysUser.RealName)
  118. if err != nil {
  119. br.Msg = "提交审批失败"
  120. br.ErrMsg = "提交审批失败, Err: " + err.Error()
  121. return
  122. }
  123. // 更新ES
  124. for _, dataPublicItem := range dataPublicItemList {
  125. data.AddOrEditChartInfoToEs(dataPublicItem.DataId)
  126. }
  127. }
  128. if err != nil {
  129. br.Msg = "编辑失败"
  130. br.ErrMsg = "编辑失败,Err:" + err.Error()
  131. return
  132. }
  133. br.Ret = 200
  134. br.Success = true
  135. br.Msg = "保存成功"
  136. }
  137. // Cancel
  138. // @Title 撤销图表公开
  139. // @Description 撤销图表公开
  140. // @Param ChartInfoId query int true "图表id"
  141. // @Success 200 {object} data_manage.ChartInfo
  142. // @router /chart_info/public/cancel [post]
  143. func (c *ChartPublicController) Cancel() {
  144. br := new(models.BaseResponse).Init()
  145. defer func() {
  146. c.Data["json"] = br
  147. c.ServeJSON()
  148. }()
  149. sysUser := c.SysUser
  150. if sysUser == nil {
  151. br.Msg = "请登录"
  152. br.ErrMsg = "请登录,SysUser Is Empty"
  153. br.Ret = 408
  154. return
  155. }
  156. var req request.CancelChartPublicReq
  157. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  158. if err != nil {
  159. br.Msg = "参数解析异常!"
  160. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  161. return
  162. }
  163. chartInfoId := req.ChartInfoId
  164. if chartInfoId <= 0 {
  165. br.Msg = "参数错误"
  166. br.ErrMsg = "参数错误"
  167. return
  168. }
  169. chartInfo, err := data_manage.GetChartInfoById(chartInfoId)
  170. if err != nil {
  171. br.Msg = "保存失败!"
  172. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  173. return
  174. }
  175. // 判断图表公共状态
  176. if !utils.InArrayByInt([]int{utils.DataPublicSuccess, utils.DataPublicReject, utils.DataPublicCommit}, chartInfo.PublicStatus) {
  177. br.Msg = "保存失败,图表公开状态异常!"
  178. br.ErrMsg = "保存失败,图表公开状态异常,public_status:" + fmt.Sprint(chartInfo.PublicStatus)
  179. return
  180. }
  181. // 如果公开状态是:已驳回、已提交,那么直接去撤销审批单
  182. if utils.InArrayByInt([]int{utils.DataPublicReject, utils.DataPublicCommit}, chartInfo.PublicStatus) {
  183. obj := data_approve.DataApproveRelation{}
  184. dataApproveId, err := obj.GetDataApproveIdByDataId(chartInfoId, utils.DataApproveTypeChart)
  185. if err != nil {
  186. br.Msg = "保存失败!"
  187. br.ErrMsg = "获取审批单失败,Err:" + err.Error()
  188. return
  189. }
  190. // 撤销审批
  191. msg, e := dataApproveSerice.DataApproveCancel(dataApproveId, sysUser.AdminId, sysUser.RealName)
  192. if e != nil {
  193. if msg != "" {
  194. br.Msg = msg
  195. } else {
  196. br.Msg = "操作失败"
  197. }
  198. br.ErrMsg = "撤销审批失败, Err: " + e.Error()
  199. return
  200. }
  201. }
  202. checkUserIdList := []int{sysUser.AdminId}
  203. // 已经分享的用户
  204. {
  205. obj := data_manage.ChartInfoShare{}
  206. userIdList, err := obj.GetAllUserIdListByChartInfoId(chartInfo.ChartInfoId)
  207. if err != nil {
  208. br.Msg = "设置失败!"
  209. br.ErrMsg = "设置失败,Err:" + err.Error()
  210. return
  211. }
  212. if len(userIdList) > 0 {
  213. checkUserIdList = append(checkUserIdList, userIdList...)
  214. }
  215. }
  216. noReferenced, otherUserIdList, err, tips := data.CheckChartReferencedByOthers([]int{chartInfo.ChartInfoId}, []string{chartInfo.UniqueCode}, checkUserIdList)
  217. if err != nil {
  218. br.Msg = "保存失败"
  219. if tips != "" {
  220. br.Msg = tips
  221. }
  222. br.ErrMsg = "撤销图表公开失败,查找图表的关联用户失败,Err:" + err.Error()
  223. return
  224. }
  225. if !noReferenced {
  226. userNameStr := ``
  227. if len(otherUserIdList) > 0 {
  228. userNameList := make([]string, 0)
  229. userList, err := system.GetAdminListByIdList(otherUserIdList)
  230. if err != nil {
  231. br.Msg = "保存失败"
  232. if tips != "" {
  233. br.Msg = tips
  234. }
  235. br.ErrMsg = "撤销图表公开失败,查找用户信息失败,Err:" + err.Error()
  236. return
  237. }
  238. for _, userInfo := range userList {
  239. userNameList = append(userNameList, userInfo.RealName)
  240. }
  241. userNameStr = strings.Join(userNameList, ",")
  242. }
  243. msg := `图表被其他用户使用,无法撤销公开`
  244. if userNameStr != "" {
  245. msg = fmt.Sprintf(`图表被用户%s使用,无法撤销公开`, userNameStr)
  246. }
  247. if tips != "" {
  248. msg = fmt.Sprintf(`%s,用户为:%s,无法撤销公开`, tips, userNameStr)
  249. }
  250. br.Msg = msg
  251. br.ErrMsg = "图表被其他用户共享,无法撤销公开,ChartInfoId:" + strconv.Itoa(chartInfo.ChartInfoId)
  252. br.IsSendEmail = false
  253. return
  254. }
  255. chartInfo.PublicStatus = utils.DataPublicDefault
  256. chartInfo.ChartPublicClassifyId = 0
  257. err = chartInfo.Update([]string{"PublicStatus", "ChartPublicClassifyId"})
  258. if err != nil {
  259. br.Msg = "保存失败"
  260. br.ErrMsg = "取消图表公共失败,Err:" + err.Error()
  261. return
  262. }
  263. // 修改ES数据
  264. data.AddOrEditChartInfoToEs(chartInfo.ChartInfoId)
  265. // 图表收藏操作处理
  266. go cache.AddDataCollectHandler(chartInfo.ChartInfoId, utils.DataCollectTypeChart)
  267. br.Ret = 200
  268. br.Success = true
  269. br.Msg = "保存成功"
  270. }
  271. // ListByEs
  272. // @Title 图表筛选接口
  273. // @Description 图表筛选接口
  274. // @Success 200 {object} data_manage.ChartInfoList
  275. // @Param request body request.SearchPublicChartReq true "type json string"
  276. // @Success 200 {object} data_manage.ChartInfoFilterDataResp
  277. // @router /chart_info/public/list/es [post]
  278. func (c *ChartPublicController) ListByEs() {
  279. br := new(models.BaseResponse).Init()
  280. defer func() {
  281. c.Data["json"] = br
  282. c.ServeJSON()
  283. }()
  284. var req request.SearchPublicChartReq
  285. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  286. if err != nil {
  287. br.Msg = "参数解析异常!"
  288. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  289. return
  290. }
  291. pageSize := req.PageSize
  292. currentIndex := req.CurrentIndex
  293. var total int64
  294. var startSize int
  295. if pageSize <= 0 {
  296. pageSize = utils.PageSize20
  297. }
  298. if currentIndex <= 0 {
  299. currentIndex = 1
  300. }
  301. startSize = paging.StartIndex(currentIndex, pageSize)
  302. // 获取查询参数
  303. keyword, searchChartPublicList, sourceList, chartTypeList, chartClassifyIdList, publicClassifyIdList, chartAuth, sortMap := data.GetChartSearchPar(req)
  304. total, chartInfoList, err := elastic.SearchChartInfoDataByPublic(keyword, startSize, pageSize, searchChartPublicList, sourceList, chartTypeList, chartClassifyIdList, publicClassifyIdList, chartAuth, c.SysUser.AdminId, sortMap)
  305. if err != nil {
  306. chartInfoList = make([]*data_manage.ChartInfoView, 0)
  307. }
  308. page := paging.GetPaging(currentIndex, pageSize, int(total))
  309. // 因为是ES查找的,所以需要重新查一下图表的信息,主要是为了把是否授权字段找出来
  310. if len(chartInfoList) > 0 {
  311. // 图表map信息
  312. chartInfoMap := make(map[int]*data_manage.ChartInfo)
  313. classifyMap := make(map[int]*data_manage.ChartClassify)
  314. publicClassifyMap := make(map[int]*data_manage.ChartPublicClassify)
  315. chartTypeMap := make(map[int]*data_manage.ChartType)
  316. // 图表id,分类id,公共分类id
  317. chartInfoIdList := make([]int, 0)
  318. tmpClassifyIdList := make([]int, 0)
  319. tmpPublicClassifyIdList := make([]int, 0)
  320. currChartTypeList := make([]int, 0)
  321. for _, v := range chartInfoList {
  322. v.ConvertToResp()
  323. v.HaveOperaAuth = true
  324. chartInfoIdList = append(chartInfoIdList, v.ChartInfoId)
  325. tmpClassifyIdList = append(tmpClassifyIdList, v.ChartClassifyId)
  326. tmpPublicClassifyIdList = append(tmpPublicClassifyIdList, v.ChartPublicClassifyId)
  327. currChartTypeList = append(currChartTypeList, v.ChartType)
  328. }
  329. // 获取所有有权限的图表
  330. {
  331. tmpChartList, err := data_manage.GetChartInfoByIdList(chartInfoIdList)
  332. if err != nil {
  333. br.Msg = "获取失败"
  334. br.ErrMsg = "获取所有有权限的图表失败,Err:" + err.Error()
  335. return
  336. }
  337. for _, v := range tmpChartList {
  338. chartInfoMap[v.ChartInfoId] = v
  339. }
  340. }
  341. // 图表分类
  342. {
  343. tmpList, err := data_manage.GetChartClassifyByIdList(tmpClassifyIdList)
  344. if err != nil {
  345. br.Msg = "获取失败"
  346. br.ErrMsg = "获取所有有权限的图表分类失败,Err:" + err.Error()
  347. return
  348. }
  349. for _, v := range tmpList {
  350. classifyMap[v.ChartClassifyId] = v
  351. }
  352. }
  353. // 公共分类
  354. {
  355. obj := data_manage.ChartPublicClassify{}
  356. tmpList, err := obj.GetChartClassifyByIdList(tmpPublicClassifyIdList)
  357. if err != nil {
  358. br.Msg = "获取失败"
  359. br.ErrMsg = "获取所有有权限的公共分类失败,Err:" + err.Error()
  360. return
  361. }
  362. for _, v := range tmpList {
  363. publicClassifyMap[v.ChartPublicClassifyId] = v
  364. }
  365. }
  366. // 图表类型
  367. {
  368. tmpChartTypeList, err := data_manage.GetChartTypeListByIdList(currChartTypeList)
  369. if err != nil {
  370. br.Msg = "获取图表类型失败"
  371. br.ErrMsg = "获取图表类型失败,Err:" + err.Error()
  372. return
  373. }
  374. for _, v := range tmpChartTypeList {
  375. chartTypeMap[v.ChartTypeId] = v
  376. }
  377. }
  378. // 数据重新赋值
  379. for _, v := range chartInfoList {
  380. if tmpChartInfo, ok := chartInfoMap[v.ChartInfoId]; ok {
  381. v.IsJoinPermission = tmpChartInfo.IsJoinPermission
  382. }
  383. // 普通分类
  384. if classifyItem, ok := classifyMap[v.ChartClassifyId]; ok {
  385. v.ClassifyNamePath = classifyItem.ChartClassifyNamePath
  386. }
  387. // 公共分类
  388. if classifyItem, ok := publicClassifyMap[v.ChartPublicClassifyId]; ok {
  389. v.PublicClassifyNamePath = classifyItem.ChartPublicClassifyNamePath
  390. }
  391. // 图表类型名称
  392. if chartType, ok := chartTypeMap[v.ChartType]; ok {
  393. v.ChartTypeName = chartType.ChartTypeName
  394. }
  395. }
  396. }
  397. resp := data_manage.ChartInfoFilterDataResp{
  398. Paging: page,
  399. List: chartInfoList,
  400. }
  401. br.Ret = 200
  402. br.Success = true
  403. br.Msg = "获取成功"
  404. br.Data = resp
  405. }
  406. // AllListByEs
  407. // @Title 图表筛选接口
  408. // @Description 图表筛选接口
  409. // @Success 200 {object} data_manage.ChartInfoList
  410. // @Param request body request.SearchChartInfoShareReq true "type json string"
  411. // @Success 200 {object} data_manage.ChartInfoFilterDataResp
  412. // @router /chart_info/public/list/es/all [post]
  413. func (c *ChartPublicController) AllListByEs() {
  414. br := new(models.BaseResponse).Init()
  415. defer func() {
  416. c.Data["json"] = br
  417. c.ServeJSON()
  418. }()
  419. var req request.AllSearchPublicChartReq
  420. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  421. if err != nil {
  422. br.Msg = "参数解析异常!"
  423. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  424. return
  425. }
  426. // 选择所有图表,所以需要通过es获取数据
  427. // 选中的图表id列表
  428. chartInfoList := make([]*data_manage.ChartInfoView, 0)
  429. // 选择所有图表,所以需要通过es获取数据
  430. if req.IsSelectAll {
  431. tmpChartInfoList, err := data.GetAllChartInfoListBySearchPublicChartReq(req.SearchPublicChartReq, c.SysUser.AdminId)
  432. if err != nil {
  433. br.Msg = "获取图表列表失败!"
  434. br.ErrMsg = "获取图表列表失败,Err:" + err.Error()
  435. return
  436. }
  437. // 如果有过滤图表,那么就过滤吧
  438. if len(req.NoChartIdList) > 0 {
  439. noChartIdMap := make(map[int]bool)
  440. for _, v := range req.NoChartIdList {
  441. noChartIdMap[v] = true
  442. }
  443. for _, v := range tmpChartInfoList {
  444. if _, ok := noChartIdMap[v.ChartInfoId]; !ok {
  445. // 如果不在未选中的图表id列表中,那么就加入到选中的图表id列表
  446. chartInfoList = append(chartInfoList, v)
  447. }
  448. }
  449. } else {
  450. chartInfoList = tmpChartInfoList
  451. }
  452. // 因为是ES查找的,所以需要重新查一下图表的信息,主要是为了把是否授权字段找出来
  453. if len(chartInfoList) > 0 {
  454. chartInfoIdList := make([]int, 0)
  455. for _, v := range chartInfoList {
  456. v.ConvertToResp()
  457. v.HaveOperaAuth = true
  458. chartInfoIdList = append(chartInfoIdList, v.ChartInfoId)
  459. }
  460. tmpChartList, err := data_manage.GetChartInfoByIdList(chartInfoIdList)
  461. if err != nil {
  462. br.Msg = "获取失败"
  463. br.ErrMsg = "获取所有有权限的图表失败,Err:" + err.Error()
  464. return
  465. }
  466. chartInfoMap := make(map[int]*data_manage.ChartInfo)
  467. for _, v := range tmpChartList {
  468. chartInfoMap[v.ChartInfoId] = v
  469. }
  470. for _, v := range chartInfoList {
  471. tmpChartInfo, ok := chartInfoMap[v.ChartInfoId]
  472. if !ok {
  473. continue
  474. }
  475. v.IsJoinPermission = tmpChartInfo.IsJoinPermission
  476. }
  477. }
  478. } else {
  479. // 因为是ES查找的,所以需要重新查一下图表的信息,主要是为了把是否授权字段找出来
  480. if len(req.ChartIdList) > 0 {
  481. chartInfoList, err = data_manage.GetChartInfoViewByIdList(req.ChartIdList)
  482. if err != nil {
  483. br.Msg = "获取失败"
  484. br.ErrMsg = "获取所有有权限的图表失败,Err:" + err.Error()
  485. return
  486. }
  487. }
  488. }
  489. resp := data_manage.ChartInfoFilterDataResp{
  490. List: chartInfoList,
  491. }
  492. br.Ret = 200
  493. br.Success = true
  494. br.Msg = "获取成功"
  495. br.Data = resp
  496. }
  497. // BatchMove
  498. // @Title 图表批量移动接口
  499. // @Description 图表批量移动接口
  500. // @Param request body request.MoveChartClassifyReq true "type json string"
  501. // @Success Ret=200 移动成功
  502. // @router /chart_info/public/batch_move [post]
  503. func (c *ChartPublicController) BatchMove() {
  504. br := new(models.BaseResponse).Init()
  505. defer func() {
  506. c.Data["json"] = br
  507. c.ServeJSON()
  508. }()
  509. var req request.MoveChartClassifyReq
  510. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  511. if err != nil {
  512. br.Msg = "参数解析异常!"
  513. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  514. return
  515. }
  516. if req.NewClassifyId <= 0 {
  517. br.Msg = `请选择要转移的新分类`
  518. br.IsSendEmail = false
  519. return
  520. }
  521. // 校验分类
  522. obj := data_manage.ChartPublicClassify{}
  523. publicClassifyItem, err := obj.GetChartClassifyById(req.NewClassifyId)
  524. if err != nil {
  525. br.Msg = "获取公共分类失败!"
  526. br.ErrMsg = "获取公共分类失败!" + err.Error()
  527. return
  528. }
  529. if publicClassifyItem.ChartPublicClassifyId <= 0 {
  530. br.Msg = "公共分类不存在!"
  531. br.ErrMsg = "公共分类不存在!"
  532. return
  533. }
  534. // 只是取公开
  535. req.SearchPublicChartReq.ChartPublicList = []int{3}
  536. chartInfoIdList := make([]int, 0)
  537. if req.IsSelectAll {
  538. // 获取图表
  539. chartInfoList, err := data.GetAllChartInfoListBySearchPublicChartReq(req.SearchPublicChartReq, c.SysUser.AdminId)
  540. if err != nil {
  541. br.Msg = "获取图表列表失败!"
  542. br.ErrMsg = "获取图表列表失败,Err:" + err.Error()
  543. return
  544. }
  545. // 如果有过滤图表,那么就过滤吧
  546. if len(req.NoChartIdList) > 0 {
  547. noChartIdMap := make(map[int]bool)
  548. for _, v := range req.NoChartIdList {
  549. noChartIdMap[v] = true
  550. }
  551. for _, chartInfo := range chartInfoList {
  552. if _, ok := noChartIdMap[chartInfo.ChartInfoId]; !ok {
  553. if chartInfo.PublicStatus != utils.DataPublicSuccess {
  554. br.Msg = `存在未公开的图表:` + chartInfo.ChartName
  555. br.IsSendEmail = false
  556. return
  557. }
  558. // 如果不在未选中的图表id列表中,那么就加入到选中的图表id列表
  559. chartInfoIdList = append(chartInfoIdList, chartInfo.ChartInfoId)
  560. }
  561. }
  562. } else {
  563. for _, chartInfo := range chartInfoList {
  564. if chartInfo.PublicStatus != utils.DataPublicSuccess {
  565. br.Msg = `存在未公开的图表:` + chartInfo.ChartName
  566. br.IsSendEmail = false
  567. return
  568. }
  569. chartInfoIdList = append(chartInfoIdList, chartInfo.ChartInfoId)
  570. }
  571. }
  572. } else {
  573. chartInfoList, err := data_manage.GetChartInfoViewByIdList(req.ChartIdList)
  574. if err != nil {
  575. br.Msg = "获取失败"
  576. br.ErrMsg = "获取所有有权限的图表失败,Err:" + err.Error()
  577. return
  578. }
  579. for _, v := range chartInfoList {
  580. if v.PublicStatus != utils.DataPublicSuccess {
  581. br.Msg = `存在未公开的图表:` + v.ChartName
  582. br.IsSendEmail = false
  583. return
  584. }
  585. }
  586. chartInfoIdList = req.ChartIdList
  587. }
  588. num := len(chartInfoIdList)
  589. if num <= 0 {
  590. br.Msg = `请选择要移动的图表!`
  591. br.IsSendEmail = false
  592. return
  593. }
  594. if num > 100 {
  595. br.Msg = `最多只能选择100条图表!`
  596. br.IsSendEmail = false
  597. return
  598. }
  599. // 开始批量修改图表分类
  600. if len(chartInfoIdList) > 0 {
  601. err = data_manage.UpdatePublicClassifyIdByChartInfoIdList(chartInfoIdList, req.NewClassifyId)
  602. if err != nil {
  603. br.Msg = `图表移动失败!`
  604. br.ErrMsg = `图表移动失败,ERR:` + err.Error()
  605. return
  606. }
  607. }
  608. br.Ret = 200
  609. br.Success = true
  610. br.Msg = "获取成功"
  611. }