public_chart.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  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. // TODO 单个图表撤销的时候,需要校验状态,然后撤销
  150. sysUser := c.SysUser
  151. if sysUser == nil {
  152. br.Msg = "请登录"
  153. br.ErrMsg = "请登录,SysUser Is Empty"
  154. br.Ret = 408
  155. return
  156. }
  157. var req request.CancelChartPublicReq
  158. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  159. if err != nil {
  160. br.Msg = "参数解析异常!"
  161. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  162. return
  163. }
  164. chartInfoId := req.ChartInfoId
  165. if chartInfoId <= 0 {
  166. br.Msg = "参数错误"
  167. br.ErrMsg = "参数错误"
  168. return
  169. }
  170. chartInfo, err := data_manage.GetChartInfoById(chartInfoId)
  171. if err != nil {
  172. br.Msg = "保存失败!"
  173. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  174. return
  175. }
  176. // 判断图表公共状态
  177. if !utils.InArrayByInt([]int{utils.DataPublicSuccess, utils.DataPublicReject, utils.DataPublicCommit}, chartInfo.PublicStatus) {
  178. br.Msg = "保存失败,图表公开状态异常!"
  179. br.ErrMsg = "保存失败,图表公开状态异常,public_status:" + fmt.Sprint(chartInfo.PublicStatus)
  180. return
  181. }
  182. // 如果公开状态是:已驳回、已提交,那么直接去撤销审批单
  183. if utils.InArrayByInt([]int{utils.DataPublicReject, utils.DataPublicCommit}, chartInfo.PublicStatus) {
  184. obj := data_approve.DataApproveRelation{}
  185. dataApproveId, err := obj.GetDataApproveIdByDataId(chartInfoId, utils.DataApproveTypeChart)
  186. if err != nil {
  187. br.Msg = "保存失败!"
  188. br.ErrMsg = "获取审批单失败,Err:" + err.Error()
  189. return
  190. }
  191. // 撤销审批
  192. msg, e := dataApproveSerice.DataApproveCancel(dataApproveId, sysUser.AdminId, sysUser.RealName)
  193. if e != nil {
  194. if msg != "" {
  195. br.Msg = msg
  196. } else {
  197. br.Msg = "操作失败"
  198. }
  199. br.ErrMsg = "撤销审批失败, Err: " + e.Error()
  200. return
  201. }
  202. }
  203. checkUserIdList := []int{sysUser.AdminId}
  204. // 已经分享的用户
  205. {
  206. obj := data_manage.ChartInfoShare{}
  207. userIdList, err := obj.GetAllUserIdListByChartInfoId(chartInfo.ChartInfoId)
  208. if err != nil {
  209. br.Msg = "设置失败!"
  210. br.ErrMsg = "设置失败,Err:" + err.Error()
  211. return
  212. }
  213. if len(userIdList) > 0 {
  214. checkUserIdList = append(checkUserIdList, userIdList...)
  215. }
  216. }
  217. noReferenced, otherUserIdList, err, tips := data.CheckChartReferencedByOthers([]int{chartInfo.ChartInfoId}, []string{chartInfo.UniqueCode}, checkUserIdList)
  218. if err != nil {
  219. br.Msg = "保存失败"
  220. if tips != "" {
  221. br.Msg = tips
  222. }
  223. br.ErrMsg = "撤销图表公开失败,查找图表的关联用户失败,Err:" + err.Error()
  224. return
  225. }
  226. if !noReferenced {
  227. userNameStr := ``
  228. if len(otherUserIdList) > 0 {
  229. userNameList := make([]string, 0)
  230. userList, err := system.GetAdminListByIdList(otherUserIdList)
  231. if err != nil {
  232. br.Msg = "保存失败"
  233. if tips != "" {
  234. br.Msg = tips
  235. }
  236. br.ErrMsg = "撤销图表公开失败,查找用户信息失败,Err:" + err.Error()
  237. return
  238. }
  239. for _, userInfo := range userList {
  240. userNameList = append(userNameList, userInfo.RealName)
  241. }
  242. userNameStr = strings.Join(userNameList, ",")
  243. }
  244. msg := `图表被其他用户使用,无法撤销公开`
  245. if userNameStr != "" {
  246. msg = fmt.Sprintf(`图表被用户%s使用,无法撤销公开`, userNameStr)
  247. }
  248. if tips != "" {
  249. msg = fmt.Sprintf(`%s,用户为:%s,无法撤销公开`, tips, userNameStr)
  250. }
  251. br.Msg = msg
  252. br.ErrMsg = "图表被其他用户共享,无法撤销公开,ChartInfoId:" + strconv.Itoa(chartInfo.ChartInfoId)
  253. br.IsSendEmail = false
  254. return
  255. }
  256. chartInfo.PublicStatus = utils.DataPublicDefault
  257. chartInfo.ChartPublicClassifyId = 0
  258. err = chartInfo.Update([]string{"PublicStatus", "ChartPublicClassifyId"})
  259. if err != nil {
  260. br.Msg = "保存失败"
  261. br.ErrMsg = "取消图表公共失败,Err:" + err.Error()
  262. return
  263. }
  264. // 修改ES数据
  265. data.AddOrEditChartInfoToEs(chartInfo.ChartInfoId)
  266. // 图表收藏操作处理
  267. go cache.AddDataCollectHandler(chartInfo.ChartInfoId, utils.DataCollectTypeChart)
  268. br.Ret = 200
  269. br.Success = true
  270. br.Msg = "保存成功"
  271. }
  272. // ListByEs
  273. // @Title 图表筛选接口
  274. // @Description 图表筛选接口
  275. // @Success 200 {object} data_manage.ChartInfoList
  276. // @Param request body request.SearchPublicChartReq true "type json string"
  277. // @Success 200 {object} data_manage.ChartInfoFilterDataResp
  278. // @router /chart_info/public/list/es [post]
  279. func (c *ChartPublicController) ListByEs() {
  280. br := new(models.BaseResponse).Init()
  281. defer func() {
  282. c.Data["json"] = br
  283. c.ServeJSON()
  284. }()
  285. var req request.SearchPublicChartReq
  286. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  287. if err != nil {
  288. br.Msg = "参数解析异常!"
  289. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  290. return
  291. }
  292. pageSize := req.PageSize
  293. currentIndex := req.CurrentIndex
  294. var total int64
  295. var startSize int
  296. if pageSize <= 0 {
  297. pageSize = utils.PageSize20
  298. }
  299. if currentIndex <= 0 {
  300. currentIndex = 1
  301. }
  302. startSize = paging.StartIndex(currentIndex, pageSize)
  303. // 获取查询参数
  304. keyword, searchChartPublicList, sourceList, chartTypeList, chartClassifyIdList, publicClassifyIdList, chartAuth, sortMap := data.GetChartSearchPar(req)
  305. total, chartInfoList, err := elastic.SearchChartInfoDataByPublic(keyword, startSize, pageSize, searchChartPublicList, sourceList, chartTypeList, chartClassifyIdList, publicClassifyIdList, chartAuth, c.SysUser.AdminId, sortMap)
  306. if err != nil {
  307. chartInfoList = make([]*data_manage.ChartInfoView, 0)
  308. }
  309. page := paging.GetPaging(currentIndex, pageSize, int(total))
  310. // 因为是ES查找的,所以需要重新查一下图表的信息,主要是为了把是否授权字段找出来
  311. if len(chartInfoList) > 0 {
  312. // 图表map信息
  313. chartInfoMap := make(map[int]*data_manage.ChartInfo)
  314. classifyMap := make(map[int]*data_manage.ChartClassify)
  315. publicClassifyMap := make(map[int]*data_manage.ChartPublicClassify)
  316. // 图表id,分类id,公共分类id
  317. chartInfoIdList := make([]int, 0)
  318. tmpClassifyIdList := make([]int, 0)
  319. tmpPublicClassifyIdList := make([]int, 0)
  320. for _, v := range chartInfoList {
  321. v.ConvertToResp()
  322. v.HaveOperaAuth = true
  323. chartInfoIdList = append(chartInfoIdList, v.ChartInfoId)
  324. tmpClassifyIdList = append(tmpClassifyIdList, v.ChartClassifyId)
  325. tmpPublicClassifyIdList = append(tmpPublicClassifyIdList, v.ChartPublicClassifyId)
  326. }
  327. // 获取所有有权限的图表
  328. {
  329. tmpChartList, err := data_manage.GetChartInfoByIdList(chartInfoIdList)
  330. if err != nil {
  331. br.Msg = "获取失败"
  332. br.ErrMsg = "获取所有有权限的图表失败,Err:" + err.Error()
  333. return
  334. }
  335. for _, v := range tmpChartList {
  336. chartInfoMap[v.ChartInfoId] = v
  337. }
  338. }
  339. // 图表分类
  340. {
  341. tmpList, err := data_manage.GetChartClassifyByIdList(tmpClassifyIdList)
  342. if err != nil {
  343. br.Msg = "获取失败"
  344. br.ErrMsg = "获取所有有权限的图表分类失败,Err:" + err.Error()
  345. return
  346. }
  347. for _, v := range tmpList {
  348. classifyMap[v.ChartClassifyId] = v
  349. }
  350. }
  351. // 公共分类
  352. {
  353. obj := data_manage.ChartPublicClassify{}
  354. tmpList, err := obj.GetChartClassifyByIdList(tmpPublicClassifyIdList)
  355. if err != nil {
  356. br.Msg = "获取失败"
  357. br.ErrMsg = "获取所有有权限的公共分类失败,Err:" + err.Error()
  358. return
  359. }
  360. for _, v := range tmpList {
  361. publicClassifyMap[v.ChartPublicClassifyId] = v
  362. }
  363. }
  364. // 数据重新赋值
  365. for _, v := range chartInfoList {
  366. if tmpChartInfo, ok := chartInfoMap[v.ChartInfoId]; ok {
  367. v.IsJoinPermission = tmpChartInfo.IsJoinPermission
  368. }
  369. // 普通分类
  370. if classifyItem, ok := classifyMap[v.ChartClassifyId]; ok {
  371. v.ClassifyNamePath = classifyItem.ChartClassifyNamePath
  372. }
  373. // 公共分类
  374. if classifyItem, ok := publicClassifyMap[v.ChartPublicClassifyId]; ok {
  375. v.PublicClassifyNamePath = classifyItem.ChartPublicClassifyNamePath
  376. }
  377. }
  378. }
  379. resp := data_manage.ChartInfoFilterDataResp{
  380. Paging: page,
  381. List: chartInfoList,
  382. }
  383. br.Ret = 200
  384. br.Success = true
  385. br.Msg = "获取成功"
  386. br.Data = resp
  387. }
  388. // AllListByEs
  389. // @Title 图表筛选接口
  390. // @Description 图表筛选接口
  391. // @Success 200 {object} data_manage.ChartInfoList
  392. // @Param request body request.SearchChartInfoShareReq true "type json string"
  393. // @Success 200 {object} data_manage.ChartInfoFilterDataResp
  394. // @router /chart_info/public/list/es/all [post]
  395. func (c *ChartPublicController) AllListByEs() {
  396. br := new(models.BaseResponse).Init()
  397. defer func() {
  398. c.Data["json"] = br
  399. c.ServeJSON()
  400. }()
  401. var req request.AllSearchPublicChartReq
  402. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  403. if err != nil {
  404. br.Msg = "参数解析异常!"
  405. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  406. return
  407. }
  408. // 选择所有图表,所以需要通过es获取数据
  409. // 选中的图表id列表
  410. chartInfoList := make([]*data_manage.ChartInfoView, 0)
  411. // 选择所有图表,所以需要通过es获取数据
  412. if req.IsSelectAll {
  413. tmpChartInfoList, err := data.GetAllChartInfoListBySearchPublicChartReq(req.SearchPublicChartReq, c.SysUser.AdminId)
  414. if err != nil {
  415. br.Msg = "获取图表列表失败!"
  416. br.ErrMsg = "获取图表列表失败,Err:" + err.Error()
  417. return
  418. }
  419. // 如果有过滤图表,那么就过滤吧
  420. if len(req.NoChartIdList) > 0 {
  421. noChartIdMap := make(map[int]bool)
  422. for _, v := range req.NoChartIdList {
  423. noChartIdMap[v] = true
  424. }
  425. for _, v := range tmpChartInfoList {
  426. if _, ok := noChartIdMap[v.ChartInfoId]; !ok {
  427. // 如果不在未选中的图表id列表中,那么就加入到选中的图表id列表
  428. chartInfoList = append(chartInfoList, v)
  429. }
  430. }
  431. } else {
  432. chartInfoList = tmpChartInfoList
  433. }
  434. // 因为是ES查找的,所以需要重新查一下图表的信息,主要是为了把是否授权字段找出来
  435. if len(chartInfoList) > 0 {
  436. chartInfoIdList := make([]int, 0)
  437. for _, v := range chartInfoList {
  438. v.ConvertToResp()
  439. v.HaveOperaAuth = true
  440. chartInfoIdList = append(chartInfoIdList, v.ChartInfoId)
  441. }
  442. tmpChartList, err := data_manage.GetChartInfoByIdList(chartInfoIdList)
  443. if err != nil {
  444. br.Msg = "获取失败"
  445. br.ErrMsg = "获取所有有权限的图表失败,Err:" + err.Error()
  446. return
  447. }
  448. chartInfoMap := make(map[int]*data_manage.ChartInfo)
  449. for _, v := range tmpChartList {
  450. chartInfoMap[v.ChartInfoId] = v
  451. }
  452. for _, v := range chartInfoList {
  453. tmpChartInfo, ok := chartInfoMap[v.ChartInfoId]
  454. if !ok {
  455. continue
  456. }
  457. v.IsJoinPermission = tmpChartInfo.IsJoinPermission
  458. }
  459. }
  460. } else {
  461. // 因为是ES查找的,所以需要重新查一下图表的信息,主要是为了把是否授权字段找出来
  462. if len(req.ChartIdList) > 0 {
  463. chartInfoList, err = data_manage.GetChartInfoViewByIdList(req.ChartIdList)
  464. if err != nil {
  465. br.Msg = "获取失败"
  466. br.ErrMsg = "获取所有有权限的图表失败,Err:" + err.Error()
  467. return
  468. }
  469. }
  470. }
  471. resp := data_manage.ChartInfoFilterDataResp{
  472. List: chartInfoList,
  473. }
  474. br.Ret = 200
  475. br.Success = true
  476. br.Msg = "获取成功"
  477. br.Data = resp
  478. }
  479. // BatchMove
  480. // @Title 图表批量移动接口
  481. // @Description 图表批量移动接口
  482. // @Param request body request.MoveChartClassifyReq true "type json string"
  483. // @Success Ret=200 移动成功
  484. // @router /chart_info/public/batch_move [post]
  485. func (c *ChartPublicController) BatchMove() {
  486. br := new(models.BaseResponse).Init()
  487. defer func() {
  488. c.Data["json"] = br
  489. c.ServeJSON()
  490. }()
  491. var req request.MoveChartClassifyReq
  492. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  493. if err != nil {
  494. br.Msg = "参数解析异常!"
  495. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  496. return
  497. }
  498. if req.NewClassifyId <= 0 {
  499. br.Msg = `请选择要转移的新分类`
  500. br.IsSendEmail = false
  501. return
  502. }
  503. // 校验分类
  504. obj := data_manage.ChartPublicClassify{}
  505. publicClassifyItem, err := obj.GetChartClassifyById(req.NewClassifyId)
  506. if err != nil {
  507. br.Msg = "获取公共分类失败!"
  508. br.ErrMsg = "获取公共分类失败!" + err.Error()
  509. return
  510. }
  511. if publicClassifyItem.ChartPublicClassifyId <= 0 {
  512. br.Msg = "公共分类不存在!"
  513. br.ErrMsg = "公共分类不存在!"
  514. return
  515. }
  516. // 只是取公开
  517. req.SearchPublicChartReq.ChartPublicList = []int{3}
  518. chartInfoIdList := make([]int, 0)
  519. if req.IsSelectAll {
  520. // 获取图表
  521. chartInfoList, err := data.GetAllChartInfoListBySearchPublicChartReq(req.SearchPublicChartReq, c.SysUser.AdminId)
  522. if err != nil {
  523. br.Msg = "获取图表列表失败!"
  524. br.ErrMsg = "获取图表列表失败,Err:" + err.Error()
  525. return
  526. }
  527. // 如果有过滤图表,那么就过滤吧
  528. if len(req.NoChartIdList) > 0 {
  529. noChartIdMap := make(map[int]bool)
  530. for _, v := range req.NoChartIdList {
  531. noChartIdMap[v] = true
  532. }
  533. for _, chartInfo := range chartInfoList {
  534. if _, ok := noChartIdMap[chartInfo.ChartInfoId]; !ok {
  535. if chartInfo.PublicStatus != utils.DataPublicSuccess {
  536. br.Msg = `存在未公开的图表:` + chartInfo.ChartName
  537. br.IsSendEmail = false
  538. return
  539. }
  540. // 如果不在未选中的图表id列表中,那么就加入到选中的图表id列表
  541. chartInfoIdList = append(chartInfoIdList, chartInfo.ChartInfoId)
  542. }
  543. }
  544. } else {
  545. for _, chartInfo := range chartInfoList {
  546. if chartInfo.PublicStatus != utils.DataPublicSuccess {
  547. br.Msg = `存在未公开的图表:` + chartInfo.ChartName
  548. br.IsSendEmail = false
  549. return
  550. }
  551. chartInfoIdList = append(chartInfoIdList, chartInfo.ChartInfoId)
  552. }
  553. }
  554. } else {
  555. chartInfoList, err := data_manage.GetChartInfoViewByIdList(req.ChartIdList)
  556. if err != nil {
  557. br.Msg = "获取失败"
  558. br.ErrMsg = "获取所有有权限的图表失败,Err:" + err.Error()
  559. return
  560. }
  561. for _, v := range chartInfoList {
  562. if v.PublicStatus != utils.DataPublicSuccess {
  563. br.Msg = `存在未公开的图表:` + v.ChartName
  564. br.IsSendEmail = false
  565. return
  566. }
  567. }
  568. chartInfoIdList = req.ChartIdList
  569. }
  570. num := len(chartInfoIdList)
  571. if num <= 0 {
  572. br.Msg = `请选择要移动的图表!`
  573. br.IsSendEmail = false
  574. return
  575. }
  576. if num > 100 {
  577. br.Msg = `最多只能选择100条图表!`
  578. br.IsSendEmail = false
  579. return
  580. }
  581. // 开始批量修改图表分类
  582. if len(chartInfoIdList) > 0 {
  583. err = data_manage.UpdatePublicClassifyIdByChartInfoIdList(chartInfoIdList, req.NewClassifyId)
  584. if err != nil {
  585. br.Msg = `图表移动失败!`
  586. br.ErrMsg = `图表移动失败,ERR:` + err.Error()
  587. return
  588. }
  589. }
  590. br.Ret = 200
  591. br.Success = true
  592. br.Msg = "获取成功"
  593. }