ppt_report.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "eta_gn/eta_api/models"
  5. "eta_gn/eta_api/models/system"
  6. "eta_gn/eta_api/services"
  7. "eta_gn/eta_api/utils"
  8. "fmt"
  9. "strconv"
  10. "strings"
  11. "time"
  12. "github.com/rdlucklib/rdluck_tools/paging"
  13. )
  14. // ReportClassify
  15. // @Title 获取ppt报告分类
  16. // @Description 获取ppt报告分类
  17. // @Param Source query int false "来源:1-我的;2-协作;3-公共"
  18. // @Success 200 {object} models.PptReportClassifyItem
  19. // @router /report/classify [get]
  20. func (this *PptV2Controller) ReportClassify() {
  21. br := new(models.BaseResponse).Init()
  22. defer func() {
  23. if br.ErrMsg == "" {
  24. br.IsSendEmail = false
  25. }
  26. this.Data["json"] = br
  27. this.ServeJSON()
  28. }()
  29. sysUser := this.SysUser
  30. if sysUser == nil {
  31. br.Msg = "请登录"
  32. br.ErrMsg = "请登录,SysUser Is Empty"
  33. return
  34. }
  35. source, _ := this.GetInt("Source", 1)
  36. if source < 1 || source > 3 {
  37. source = 1
  38. }
  39. // 获取PPT, source:1-我的;2-协作;3-公共
  40. pptList := make([]*models.PptV2, 0)
  41. {
  42. cond := ``
  43. pars := make([]interface{}, 0)
  44. switch source {
  45. case 1:
  46. cond += ` AND admin_id = ?`
  47. pars = append(pars, sysUser.AdminId)
  48. case 2:
  49. cond += ` AND collaborate_type = ? AND (admin_id = ? OR FIND_IN_SET(?, collaborate_users)) `
  50. pars = append(pars, utils.ReportWriteTypeGroup, sysUser.AdminId)
  51. case 3:
  52. cond += ` AND report_source = ? AND state = ?`
  53. pars = append(pars, utils.ReportSourceOuter, models.ReportStatePass)
  54. }
  55. pptOb := new(models.PptV2)
  56. list, e := pptOb.GetItemsByCondition(cond, pars, models.PptReportQueryFields, "modify_time DESC")
  57. if e != nil {
  58. br.Msg = "获取失败"
  59. br.ErrMsg = fmt.Sprintf("获取PPT失败, %v", e)
  60. return
  61. }
  62. pptList = list
  63. }
  64. classifyPpt := make(map[int][]*models.PptReportItem)
  65. for _, v := range pptList {
  66. // 当前编辑人
  67. t := v.Format2ReportItem(v)
  68. editor, e := services.UpdatePptEditing(v.PptId, 0, sysUser.AdminId, sysUser.RealName, false)
  69. if e != nil {
  70. br.Msg = "获取失败"
  71. br.ErrMsg = fmt.Sprintf("获取PPT编辑状态失败, err: %s", e.Error())
  72. return
  73. }
  74. t.Editor = editor
  75. // 权限
  76. if source == 1 || source == 2 {
  77. t.HasAuth = true
  78. } else {
  79. if v.AdminId == sysUser.AdminId {
  80. t.HasAuth = true
  81. }
  82. if t.HasAuth == false && v.CollaborateUsers != "" {
  83. authorArr := strings.Split(v.CollaborateUsers, ",")
  84. strId := strconv.Itoa(sysUser.AdminId)
  85. if utils.InArrayByStr(authorArr, strId) {
  86. t.HasAuth = true
  87. }
  88. }
  89. }
  90. if classifyPpt[v.ClassifyId] == nil {
  91. classifyPpt[v.ClassifyId] = make([]*models.PptReportItem, 0)
  92. }
  93. classifyPpt[v.ClassifyId] = append(classifyPpt[v.ClassifyId], t)
  94. }
  95. visibleUsers, err := models.GetClassifyVisibleAll()
  96. if err != nil {
  97. br.Msg = "获取失败"
  98. br.ErrMsg = fmt.Sprintf("获取可见用户失败, err: %s", err.Error())
  99. return
  100. }
  101. visibleUsersMap := make(map[int][]int)
  102. for _, v := range visibleUsers {
  103. visibleUsersMap[v.ClassifyId] = append(visibleUsersMap[v.ClassifyId], v.AdminId)
  104. }
  105. var resp []*models.PptReportClassifyItem
  106. // 获取分类
  107. classifies := make([]*models.Classify, 0)
  108. {
  109. // 获取所有分类
  110. ob := new(models.Classify)
  111. cond := ` AND enabled = ?`
  112. pars := make([]interface{}, 0)
  113. pars = append(pars, 1, utils.ReportTypePPT)
  114. list, e := ob.GetItemsByCondition(cond, pars, []string{}, "sort ASC, create_time ASC")
  115. if e != nil {
  116. br.Msg = "获取失败"
  117. br.ErrMsg = fmt.Sprintf("获取分类失败, %v", e)
  118. return
  119. }
  120. // 上级中的分类类型可能与最下层的不一致,但是要把上级也一起取出来, 所以这里要过滤一遍
  121. classifyIds := make([]int, 0)
  122. for _, v := range list {
  123. if v.ClassifyType != utils.ReportTypePPT {
  124. continue
  125. }
  126. // 没有PPT的分类也都过滤掉
  127. //if len(classifyPpt[v.Id]) == 0 {
  128. // continue
  129. //}
  130. // 根据LevelPath去处理
  131. pathArr := strings.Split(v.LevelPath, ",")
  132. for _, p := range pathArr {
  133. id, _ := strconv.Atoi(p)
  134. if id <= 0 {
  135. continue
  136. }
  137. if utils.InArrayByInt(classifyIds, id) {
  138. continue
  139. }
  140. classifyIds = append(classifyIds, id)
  141. }
  142. }
  143. // 过滤掉不在ID中的
  144. for _, v := range list {
  145. if !utils.InArrayByInt(classifyIds, v.Id) {
  146. continue
  147. }
  148. if visible, ok := visibleUsersMap[v.Id]; ok {
  149. if !utils.InArrayByInt(visible, sysUser.AdminId) {
  150. continue
  151. }
  152. }
  153. classifies = append(classifies, v)
  154. }
  155. }
  156. resp = services.GetPptReportClassifyTreeRecursive(classifies, 0, classifyPpt)
  157. resp = services.RecursiveFilterPptNoChildTreeClassify(resp)
  158. br.Data = resp
  159. br.Ret = 200
  160. br.Success = true
  161. br.Msg = "获取成功"
  162. }
  163. // ReportList
  164. // @Title 获取ppt报告列表-分页
  165. // @Description 获取ppt报告列表-分页
  166. // @Param Source query int false "来源:1-我的;2-协作;3-公共"
  167. // @Param ClassifyId query int false "分类ID"
  168. // @Param Keyword query string false "搜索关键词"
  169. // @Success 200 {object} models.PptPageReportResp
  170. // @router /report/list [get]
  171. func (this *PptV2Controller) ReportList() {
  172. br := new(models.BaseResponse).Init()
  173. defer func() {
  174. if br.ErrMsg == "" {
  175. br.IsSendEmail = false
  176. }
  177. this.Data["json"] = br
  178. this.ServeJSON()
  179. }()
  180. sysUser := this.SysUser
  181. if sysUser == nil {
  182. br.Msg = "请登录"
  183. br.ErrMsg = "请登录,SysUser Is Empty"
  184. return
  185. }
  186. pageSize, _ := this.GetInt("PageSize")
  187. currentIndex, _ := this.GetInt("CurrentIndex")
  188. source, _ := this.GetInt("Source", 1)
  189. if source < 1 || source > 3 {
  190. source = 1
  191. }
  192. classifyId, _ := this.GetInt("ClassifyId", 0)
  193. keyword := this.GetString("Keyword")
  194. var startSize int
  195. if pageSize <= 0 {
  196. pageSize = utils.PageSize20
  197. }
  198. if currentIndex <= 0 {
  199. currentIndex = 1
  200. }
  201. startSize = utils.StartIndex(currentIndex, pageSize)
  202. resp := new(models.PptPageReportResp)
  203. resp.List = make([]*models.PptReportItem, 0)
  204. // 获取PPT, source:1-我的;2-协作;3-公共
  205. pptList := make([]*models.PptV2, 0)
  206. cond := ``
  207. pars := make([]interface{}, 0)
  208. {
  209. switch source {
  210. case 1:
  211. cond += ` AND admin_id = ?`
  212. pars = append(pars, sysUser.AdminId)
  213. case 2:
  214. cond += ` AND collaborate_type = ? AND (admin_id = ? OR FIND_IN_SET(?, collaborate_users)) `
  215. pars = append(pars, utils.ReportWriteTypeGroup, sysUser.AdminId, sysUser.AdminId)
  216. case 3:
  217. cond += ` AND report_source = ? AND state = ?`
  218. pars = append(pars, utils.ReportSourceOuter, models.ReportStatePass)
  219. }
  220. if classifyId > 0 {
  221. // 查询分类及子集
  222. classifyOb := new(models.Classify)
  223. childCond := ` AND FIND_IN_SET(?, level_path)`
  224. childPars := make([]interface{}, 0)
  225. childPars = append(childPars, classifyId)
  226. children, e := classifyOb.GetItemsByCondition(childCond, childPars, []string{"id"}, "")
  227. if e != nil {
  228. br.Msg = "获取失败"
  229. br.ErrMsg = fmt.Sprintf("获取分类及子分类失败, %v", e)
  230. return
  231. }
  232. var childIds []int
  233. for _, v := range children {
  234. childIds = append(childIds, v.Id)
  235. }
  236. if len(childIds) == 0 {
  237. page := paging.GetPaging(currentIndex, pageSize, 0)
  238. resp.Paging = page
  239. br.Data = resp
  240. br.Ret = 200
  241. br.Success = true
  242. br.Msg = "获取成功"
  243. return
  244. }
  245. cond += ` AND classify_id IN (?)`
  246. pars = append(pars, childIds)
  247. }
  248. keyword = strings.TrimSpace(keyword)
  249. if keyword != "" {
  250. cond += ` AND title LIKE ?`
  251. pars = append(pars, fmt.Sprint("%", keyword, "%"))
  252. }
  253. }
  254. noVisibleClassifyIds, err := models.GetNoVisibleClassifyIdByAdminId(this.SysUser.AdminId)
  255. if err != nil {
  256. br.Msg = "获取失败"
  257. br.ErrMsg = "获取不可见分类id失败,Err:" + err.Error()
  258. return
  259. }
  260. if len(noVisibleClassifyIds) > 0 {
  261. cond += ` AND classify_id NOT IN (?) `
  262. pars = append(pars, noVisibleClassifyIds)
  263. }
  264. pptOb := new(models.PptV2)
  265. total, e := pptOb.GetCountByCondition(cond, pars)
  266. if e != nil {
  267. br.Msg = "获取失败"
  268. br.ErrMsg = fmt.Sprintf("获取PPT总数失败, %v", e)
  269. return
  270. }
  271. list, e := pptOb.GetPageItemsByCondition(cond, pars, models.PptReportQueryFields, "modify_time DESC", startSize, pageSize)
  272. if e != nil {
  273. br.Msg = "获取失败"
  274. br.ErrMsg = fmt.Sprintf("获取PPT失败, %v", e)
  275. return
  276. }
  277. pptList = list
  278. for _, v := range pptList {
  279. // 当前编辑人
  280. t := v.Format2ReportItem(v)
  281. editor, e := services.UpdatePptEditing(v.PptId, 0, sysUser.AdminId, sysUser.RealName, false)
  282. if e != nil {
  283. br.Msg = "获取失败"
  284. br.ErrMsg = fmt.Sprintf("获取PPT编辑状态失败, err: %s", e.Error())
  285. return
  286. }
  287. t.Editor = editor
  288. // 权限
  289. if source == 1 || source == 2 {
  290. t.HasAuth = true
  291. } else {
  292. if v.AdminId == sysUser.AdminId {
  293. t.HasAuth = true
  294. }
  295. if t.HasAuth == false && v.CollaborateUsers != "" {
  296. authorArr := strings.Split(v.CollaborateUsers, ",")
  297. strId := strconv.Itoa(sysUser.AdminId)
  298. if utils.InArrayByStr(authorArr, strId) {
  299. t.HasAuth = true
  300. }
  301. }
  302. }
  303. resp.List = append(resp.List, t)
  304. }
  305. page := paging.GetPaging(currentIndex, pageSize, total)
  306. resp.Paging = page
  307. br.Data = resp
  308. br.Ret = 200
  309. br.Success = true
  310. br.Msg = "获取成功"
  311. }
  312. // CreateReport
  313. // @Title 新增ppt报告
  314. // @Description 新增ppt报告
  315. // @Param request body models.PptReportCreateReq true "type json string"
  316. // @Success 200 Ret=200 新增成功
  317. // @router /report/add [post]
  318. func (this *PptV2Controller) CreateReport() {
  319. br := new(models.BaseResponse).Init()
  320. defer func() {
  321. if br.ErrMsg == "" {
  322. br.IsSendEmail = false
  323. }
  324. this.Data["json"] = br
  325. this.ServeJSON()
  326. }()
  327. sysUser := this.SysUser
  328. if sysUser == nil {
  329. br.Msg = "请登录"
  330. br.ErrMsg = "请登录,SysUser Is Empty"
  331. return
  332. }
  333. var req models.PptReportCreateReq
  334. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  335. br.Msg = "参数解析异常"
  336. br.ErrMsg = fmt.Sprintf("参数解析失败, %v", e)
  337. return
  338. }
  339. req.Title = strings.TrimSpace(req.Title)
  340. if req.Title == "" {
  341. br.Msg = "请输入标题"
  342. return
  343. }
  344. if req.AddType != 1 && req.AddType != 2 {
  345. req.AddType = 1
  346. }
  347. if req.ClassifyId <= 0 {
  348. br.Msg = "请选择分类"
  349. return
  350. }
  351. if req.CollaborateType != 1 && req.CollaborateType != 2 {
  352. br.Msg = "协作方式异常"
  353. br.ErrMsg = fmt.Sprintf("协作方式异常, %d", req.CollaborateType)
  354. return
  355. }
  356. if req.CollaborateType == 2 && len(req.CollaborateUserIds) == 0 {
  357. br.Msg = "请选择协作人"
  358. return
  359. }
  360. // 新报告
  361. newItem := new(models.PptV2)
  362. newItem.Title = req.Title
  363. newItem.AddType = req.AddType
  364. newItem.ClassifyId = req.ClassifyId
  365. newItem.CollaborateType = req.CollaborateType
  366. if len(req.CollaborateUserIds) > 0 {
  367. var partnerArr []string
  368. for _, v := range req.CollaborateUserIds {
  369. partnerArr = append(partnerArr, strconv.Itoa(v))
  370. }
  371. newItem.CollaborateUsers = strings.Trim(strings.Join(partnerArr, ","), `"`)
  372. }
  373. newItem.PptVersion = 2
  374. newItem.AdminId = sysUser.AdminId
  375. newItem.AdminRealName = sysUser.RealName
  376. newItem.ReportSource = utils.ReportSourceLocal // 固定本地PPT
  377. newItem.State = models.ReportStateUnpublished // 默认未发布
  378. newItem.CreateTime = time.Now()
  379. newItem.ModifyTime = time.Now()
  380. // 继承PPT内容
  381. if req.AddType == utils.ReportAddTypeInherit && req.InheritPptId > 0 {
  382. inheritPpt, e := models.GetPptV2ById(req.InheritPptId)
  383. if e != nil {
  384. if utils.IsErrNoRow(e) {
  385. br.Msg = "被继承报告不存在"
  386. return
  387. }
  388. br.Msg = "操作失败"
  389. br.ErrMsg = fmt.Sprintf("操作失败, %v", e)
  390. return
  391. }
  392. newItem.TemplateType = inheritPpt.TemplateType
  393. newItem.BackgroundImg = inheritPpt.BackgroundImg
  394. newItem.CurrentBackgroundImg = inheritPpt.CurrentBackgroundImg
  395. newItem.BackCoverImg = inheritPpt.BackCoverImg
  396. newItem.CurrentBackgroundImgId = inheritPpt.CurrentBackgroundImgId
  397. newItem.BackCoverImgId = inheritPpt.BackCoverImgId
  398. newItem.BackgroundImgId = inheritPpt.BackgroundImgId
  399. newItem.ReportType = inheritPpt.ReportType
  400. newItem.PptDate = inheritPpt.PptDate
  401. newItem.Content = inheritPpt.Content
  402. newItem.CoverContent = inheritPpt.CoverContent
  403. newItem.TitleSetting = inheritPpt.TitleSetting
  404. }
  405. // 非继承PPT,有内容时写入内容(如合并PPT时)
  406. if req.InheritPptId <= 0 {
  407. newItem.TemplateType = req.FirstPage.TemplateType
  408. newItem.BackgroundImg = req.FirstPage.ImgUrl
  409. newItem.CurrentBackgroundImg = req.FirstPage.CurrentBackgroundImg
  410. newItem.BackCoverImg = req.FirstPage.BackCoverImg
  411. newItem.CurrentBackgroundImgId = req.FirstPage.CurrentBackgroundImgId
  412. newItem.BackCoverImgId = req.FirstPage.BackCoverImgId
  413. newItem.BackgroundImgId = req.FirstPage.BackgroundImgId
  414. newItem.ReportType = req.FirstPage.ReportType
  415. newItem.PptDate = req.FirstPage.PptDate
  416. newItem.Content = req.Content
  417. newItem.CoverContent = req.CoverContent
  418. newItem.TitleSetting = req.TitleSetting
  419. }
  420. // 初始的PPT页数
  421. if newItem.Content != "" {
  422. var pageContents []services.PPTContent
  423. _ = json.Unmarshal([]byte(newItem.Content), &pageContents) // 这里转不过去问题也不大,编辑时自动保存会更新页数字段
  424. newItem.PptPage = len(pageContents)
  425. }
  426. newId, e := models.AddPptV2(newItem)
  427. if e != nil {
  428. br.Msg = "操作失败"
  429. br.ErrMsg = fmt.Sprintf("新增PPT报告失败, %v", e)
  430. return
  431. }
  432. // 更新报告分类计数
  433. go func() {
  434. _ = services.UpdateClassifyReportNum(req.ClassifyId)
  435. }()
  436. resp := models.AddPptResp{
  437. PptId: newId,
  438. }
  439. br.Data = resp
  440. br.Ret = 200
  441. br.Success = true
  442. br.Msg = "操作成功"
  443. }
  444. // AuthList
  445. // @Title 获取有权限的列表
  446. // @Description 获取有权限的列表
  447. // @Param PageSize query int true "每页数据条数"
  448. // @Param CurrentIndex query int true "当前页页码,从1开始"
  449. // @Param Keyword query string false "搜索关键词"
  450. // @Param ClassifyId query int false "分类ID"
  451. // @Success 200 {object} models.PptPageReportResp
  452. // @router /report/auth_list [get]
  453. func (this *PptV2Controller) AuthList() {
  454. br := new(models.BaseResponse).Init()
  455. defer func() {
  456. if br.ErrMsg == "" {
  457. br.IsSendEmail = false
  458. }
  459. this.Data["json"] = br
  460. this.ServeJSON()
  461. }()
  462. sysUser := this.SysUser
  463. if sysUser == nil {
  464. br.Msg = "请登录"
  465. br.ErrMsg = "请登录,SysUser Is Empty"
  466. br.Ret = 408
  467. return
  468. }
  469. pageSize, _ := this.GetInt("PageSize")
  470. currentIndex, _ := this.GetInt("CurrentIndex")
  471. keyword := this.GetString("Keyword")
  472. classifyId, _ := this.GetInt("ClassifyId", 0)
  473. var startSize int
  474. if pageSize <= 0 {
  475. pageSize = utils.PageSize20
  476. }
  477. if currentIndex <= 0 {
  478. currentIndex = 1
  479. }
  480. startSize = utils.StartIndex(currentIndex, pageSize)
  481. var pptList []*models.PptReportItem
  482. // 无相关搜索时,返回空集(其实我感觉没必要,没关键词查全部也属于正常=_=!)
  483. if keyword == `` && classifyId <= 0 {
  484. page := paging.GetPaging(currentIndex, pageSize, 0)
  485. resp := new(models.PptPageReportResp)
  486. resp.Paging = page
  487. resp.List = pptList
  488. br.Ret = 200
  489. br.Success = true
  490. br.Msg = "获取成功"
  491. br.Data = resp
  492. return
  493. }
  494. // 查询自己创建的以及协作人包含自己的报告、以及外部已审批报告
  495. var cond string
  496. var pars []interface{}
  497. cond += ` AND (admin_id = ? OR (admin_id <> ? AND FIND_IN_SET(?, collaborate_users)) OR (report_source = ? AND state = ?))`
  498. pars = append(pars, sysUser.AdminId, sysUser.AdminId, sysUser.AdminId, utils.ReportSourceOuter, models.ReportStatePass)
  499. if classifyId > 0 {
  500. cond += ` AND classify_id = ? `
  501. pars = append(pars, classifyId)
  502. }
  503. keyword = strings.TrimSpace(keyword)
  504. if keyword != `` {
  505. cond += ` AND title LIKE ? `
  506. pars = utils.GetLikeKeywordPars(pars, keyword, 1)
  507. }
  508. noVisisbleClassifyIds, err := models.GetNoVisibleClassifyIdByAdminId(sysUser.AdminId)
  509. if err != nil {
  510. br.Msg = "获取失败"
  511. br.ErrMsg = fmt.Sprintf("获取不可见分类失败, %v", err)
  512. return
  513. }
  514. if len(noVisisbleClassifyIds) > 0 {
  515. cond += ` AND classify_id NOT IN (?)`
  516. pars = append(pars, noVisisbleClassifyIds)
  517. }
  518. pptOb := new(models.PptV2)
  519. total, e := pptOb.GetCountByCondition(cond, pars)
  520. if e != nil {
  521. br.Msg = "获取失败"
  522. br.ErrMsg = fmt.Sprintf("获取PPT总数失败, %v", e)
  523. return
  524. }
  525. list, e := pptOb.GetPageItemsByCondition(cond, pars, models.PptReportQueryFields, "", startSize, pageSize)
  526. if e != nil {
  527. br.Msg = "获取失败"
  528. br.ErrMsg = fmt.Sprintf("获取PPT失败, %v", e)
  529. return
  530. }
  531. // 分类完整路径、协作人姓名
  532. classifyIdFull := make(map[int]string)
  533. {
  534. ob := new(models.Classify)
  535. classifies, e := ob.GetItemsByCondition("", make([]interface{}, 0), []string{}, "")
  536. if e != nil {
  537. br.Msg = "获取失败"
  538. br.ErrMsg = fmt.Sprintf("获取分类失败, %v", e)
  539. return
  540. }
  541. classifyIdName := make(map[string]string)
  542. for _, v := range classifies {
  543. classifyIdName[strconv.Itoa(v.Id)] = v.ClassifyName
  544. }
  545. for _, v := range classifies {
  546. arr := strings.Split(v.LevelPath, ",")
  547. if len(arr) == 0 {
  548. continue
  549. }
  550. var nameArr []string
  551. for _, a := range arr {
  552. n := classifyIdName[a]
  553. if n == "" {
  554. continue
  555. }
  556. nameArr = append(nameArr, n)
  557. }
  558. classifyIdFull[v.Id] = strings.Join(nameArr, "/")
  559. }
  560. }
  561. adminIdName := make(map[int]string)
  562. {
  563. cond := ` AND enabled = 1`
  564. pars := make([]interface{}, 0)
  565. sysAdmin, e := system.GetSysAdminList(cond, pars, []string{}, "")
  566. if e != nil {
  567. br.Msg = "获取失败"
  568. br.ErrMsg = "获取用户失败,Err:" + e.Error()
  569. return
  570. }
  571. for _, v := range sysAdmin {
  572. adminIdName[v.AdminId] = v.RealName
  573. }
  574. }
  575. // 格式化数据
  576. for _, v := range list {
  577. t := v.Format2ReportItem(v)
  578. t.HasAuth = true // 该列表固定有权限
  579. t.FullClassify = classifyIdFull[v.ClassifyId] // 分类的完整路径
  580. // 协作人
  581. if v.CollaborateUsers != "" {
  582. var authors []models.PptReportCollaborateUser
  583. authorArr := strings.Split(v.CollaborateUsers, ",")
  584. for _, au := range authorArr {
  585. uid, _ := strconv.Atoi(au)
  586. if uid <= 0 {
  587. continue
  588. }
  589. name := adminIdName[uid]
  590. if name == "" {
  591. continue
  592. }
  593. authors = append(authors, models.PptReportCollaborateUser{
  594. AdminId: uid,
  595. RealName: name,
  596. })
  597. }
  598. t.CollaborateUsers = authors
  599. }
  600. pptList = append(pptList, t)
  601. }
  602. page := paging.GetPaging(currentIndex, pageSize, total)
  603. resp := new(models.PptPageReportResp)
  604. resp.Paging = page
  605. resp.List = pptList
  606. br.Ret = 200
  607. br.Success = true
  608. br.Msg = "获取成功"
  609. br.Data = resp
  610. }