ppt_report.go 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  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. "github.com/rdlucklib/rdluck_tools/paging"
  10. "strconv"
  11. "strings"
  12. "time"
  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 = ?`
  53. pars = append(pars, utils.ReportSourceOuter)
  54. }
  55. pptOb := new(models.PptV2)
  56. list, e := pptOb.GetItemsByCondition(cond, pars, models.PptReportQueryFields, "")
  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. resp := make([]*models.PptReportClassifyItem, 0)
  96. // 获取分类
  97. classifies := make([]*models.Classify, 0)
  98. {
  99. ob := new(models.Classify)
  100. cond := ` AND enabled = ? AND classify_type = ?`
  101. pars := make([]interface{}, 0)
  102. pars = append(pars, 1, utils.ReportTypePPT)
  103. list, e := ob.GetItemsByCondition(cond, pars, []string{}, "sort ASC, create_time ASC")
  104. if e != nil {
  105. br.Msg = "获取失败"
  106. br.ErrMsg = fmt.Sprintf("获取分类失败, %v", e)
  107. return
  108. }
  109. classifies = list
  110. }
  111. resp = services.GetPptReportClassifyTreeRecursive(classifies, 0, classifyPpt)
  112. br.Data = resp
  113. br.Ret = 200
  114. br.Success = true
  115. br.Msg = "获取成功"
  116. }
  117. // ReportList
  118. // @Title 获取ppt报告列表-分页
  119. // @Description 获取ppt报告列表-分页
  120. // @Param Source query int false "来源:1-我的;2-协作;3-公共"
  121. // @Param ClassifyId query int false "分类ID"
  122. // @Param Keyword query string false "搜索关键词"
  123. // @Success 200 {object} models.PptPageReportResp
  124. // @router /report/list [get]
  125. func (this *PptV2Controller) ReportList() {
  126. br := new(models.BaseResponse).Init()
  127. defer func() {
  128. if br.ErrMsg == "" {
  129. br.IsSendEmail = false
  130. }
  131. this.Data["json"] = br
  132. this.ServeJSON()
  133. }()
  134. sysUser := this.SysUser
  135. if sysUser == nil {
  136. br.Msg = "请登录"
  137. br.ErrMsg = "请登录,SysUser Is Empty"
  138. return
  139. }
  140. pageSize, _ := this.GetInt("PageSize")
  141. currentIndex, _ := this.GetInt("CurrentIndex")
  142. source, _ := this.GetInt("Source", 1)
  143. if source < 1 || source > 3 {
  144. source = 1
  145. }
  146. classifyId, _ := this.GetInt("ClassifyId", 0)
  147. keyword := this.GetString("Keyword")
  148. var startSize int
  149. if pageSize <= 0 {
  150. pageSize = utils.PageSize20
  151. }
  152. if currentIndex <= 0 {
  153. currentIndex = 1
  154. }
  155. startSize = utils.StartIndex(currentIndex, pageSize)
  156. resp := new(models.PptPageReportResp)
  157. resp.List = make([]*models.PptReportItem, 0)
  158. // 获取PPT, source:1-我的;2-协作;3-公共
  159. pptList := make([]*models.PptV2, 0)
  160. cond := ``
  161. pars := make([]interface{}, 0)
  162. {
  163. switch source {
  164. case 1:
  165. cond += ` AND admin_id = ?`
  166. pars = append(pars, sysUser.AdminId)
  167. case 2:
  168. cond += ` AND collaborate_type = ? AND (admin_id = ? OR FIND_IN_SET(?, collaborate_users)) `
  169. pars = append(pars, utils.ReportWriteTypeGroup, sysUser.AdminId, sysUser.AdminId)
  170. case 3:
  171. cond += ` AND report_source = ?`
  172. pars = append(pars, utils.ReportSourceOuter)
  173. }
  174. if classifyId > 0 {
  175. // 查询分类及子集
  176. classifyOb := new(models.Classify)
  177. childCond := ` AND FIND_IN_SET(?, level_path)`
  178. childPars := make([]interface{}, 0)
  179. childPars = append(childPars, classifyId)
  180. children, e := classifyOb.GetItemsByCondition(childCond, childPars, []string{"id"}, "")
  181. if e != nil {
  182. br.Msg = "获取失败"
  183. br.ErrMsg = fmt.Sprintf("获取分类及子分类失败, %v", e)
  184. return
  185. }
  186. var childIds []int
  187. for _, v := range children {
  188. childIds = append(childIds, v.Id)
  189. }
  190. if len(childIds) == 0 {
  191. page := paging.GetPaging(currentIndex, pageSize, 0)
  192. resp.Paging = page
  193. br.Data = resp
  194. br.Ret = 200
  195. br.Success = true
  196. br.Msg = "获取成功"
  197. return
  198. }
  199. cond += ` AND classify_id IN (?)`
  200. pars = append(pars, childIds)
  201. }
  202. keyword = strings.TrimSpace(keyword)
  203. if keyword != "" {
  204. cond += ` AND title LIKE ?`
  205. pars = append(pars, fmt.Sprint("%", keyword, "%"))
  206. }
  207. }
  208. pptOb := new(models.PptV2)
  209. total, e := pptOb.GetCountByCondition(cond, pars)
  210. if e != nil {
  211. br.Msg = "获取失败"
  212. br.ErrMsg = fmt.Sprintf("获取PPT总数失败, %v", e)
  213. return
  214. }
  215. list, e := pptOb.GetPageItemsByCondition(cond, pars, models.PptReportQueryFields, "", startSize, pageSize)
  216. if e != nil {
  217. br.Msg = "获取失败"
  218. br.ErrMsg = fmt.Sprintf("获取PPT失败, %v", e)
  219. return
  220. }
  221. pptList = list
  222. for _, v := range pptList {
  223. // 当前编辑人
  224. t := v.Format2ReportItem(v)
  225. editor, e := services.UpdatePptEditing(v.PptId, 0, sysUser.AdminId, sysUser.RealName, false)
  226. if e != nil {
  227. br.Msg = "获取失败"
  228. br.ErrMsg = fmt.Sprintf("获取PPT编辑状态失败, err: %s", e.Error())
  229. return
  230. }
  231. t.Editor = editor
  232. // 权限
  233. if source == 1 || source == 2 {
  234. t.HasAuth = true
  235. } else {
  236. if v.AdminId == sysUser.AdminId {
  237. t.HasAuth = true
  238. }
  239. if t.HasAuth == false && v.CollaborateUsers != "" {
  240. authorArr := strings.Split(v.CollaborateUsers, ",")
  241. strId := strconv.Itoa(sysUser.AdminId)
  242. if utils.InArrayByStr(authorArr, strId) {
  243. t.HasAuth = true
  244. }
  245. }
  246. }
  247. resp.List = append(resp.List, t)
  248. }
  249. page := paging.GetPaging(currentIndex, pageSize, total)
  250. resp.Paging = page
  251. br.Data = resp
  252. br.Ret = 200
  253. br.Success = true
  254. br.Msg = "获取成功"
  255. }
  256. // CreateReport
  257. // @Title 新增ppt报告
  258. // @Description 新增ppt报告
  259. // @Param request body models.PptReportCreateReq true "type json string"
  260. // @Success 200 Ret=200 新增成功
  261. // @router /report/add [post]
  262. func (this *PptV2Controller) CreateReport() {
  263. br := new(models.BaseResponse).Init()
  264. defer func() {
  265. if br.ErrMsg == "" {
  266. br.IsSendEmail = false
  267. }
  268. this.Data["json"] = br
  269. this.ServeJSON()
  270. }()
  271. sysUser := this.SysUser
  272. if sysUser == nil {
  273. br.Msg = "请登录"
  274. br.ErrMsg = "请登录,SysUser Is Empty"
  275. return
  276. }
  277. var req models.PptReportCreateReq
  278. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  279. br.Msg = "参数解析异常"
  280. br.ErrMsg = fmt.Sprintf("参数解析失败, %v", e)
  281. return
  282. }
  283. req.Title = strings.TrimSpace(req.Title)
  284. if req.Title == "" {
  285. br.Msg = "请输入标题"
  286. return
  287. }
  288. if req.AddType != 1 && req.AddType != 2 {
  289. req.AddType = 1
  290. }
  291. if req.ClassifyId <= 0 {
  292. br.Msg = "请选择分类"
  293. return
  294. }
  295. if req.CollaborateType != 1 && req.CollaborateType != 2 {
  296. br.Msg = "协作方式异常"
  297. br.ErrMsg = fmt.Sprintf("协作方式异常, %d", req.CollaborateType)
  298. return
  299. }
  300. if req.CollaborateType == 2 && len(req.CollaborateUserIds) == 0 {
  301. br.Msg = "请选择协作人"
  302. return
  303. }
  304. // 新报告
  305. newItem := new(models.PptV2)
  306. newItem.Title = req.Title
  307. newItem.AddType = req.AddType
  308. newItem.ClassifyId = req.ClassifyId
  309. newItem.CollaborateType = req.CollaborateType
  310. if len(req.CollaborateUserIds) > 0 {
  311. var partnerArr []string
  312. for _, v := range req.CollaborateUserIds {
  313. partnerArr = append(partnerArr, strconv.Itoa(v))
  314. }
  315. newItem.CollaborateUsers = strings.Trim(strings.Join(partnerArr, ","), `"`)
  316. }
  317. newItem.PptVersion = 2
  318. newItem.AdminId = sysUser.AdminId
  319. newItem.AdminRealName = sysUser.RealName
  320. newItem.ReportSource = utils.ReportSourceLocal // 固定本地PPT
  321. newItem.State = models.ReportStateUnpublished // 默认未发布
  322. newItem.CreateTime = time.Now()
  323. newItem.ModifyTime = time.Now()
  324. // 继承PPT内容
  325. if req.AddType == utils.ReportAddTypeInherit && req.InheritPptId > 0 {
  326. inheritPpt, e := models.GetPptV2ById(req.InheritPptId)
  327. if e != nil {
  328. if utils.IsErrNoRow(e) {
  329. br.Msg = "被继承报告不存在"
  330. return
  331. }
  332. br.Msg = "操作失败"
  333. br.ErrMsg = fmt.Sprintf("操作失败, %v", e)
  334. return
  335. }
  336. newItem.TemplateType = inheritPpt.TemplateType
  337. newItem.BackgroundImg = inheritPpt.BackgroundImg
  338. newItem.ReportType = inheritPpt.ReportType
  339. newItem.PptDate = inheritPpt.PptDate
  340. newItem.Content = inheritPpt.Content
  341. newItem.CoverContent = inheritPpt.CoverContent
  342. newItem.TitleSetting = inheritPpt.TitleSetting
  343. }
  344. // 非继承PPT,有内容时写入内容(如合并PPT时)
  345. if req.InheritPptId <= 0 {
  346. newItem.TemplateType = req.FirstPage.TemplateType
  347. newItem.BackgroundImg = req.FirstPage.ImgUrl
  348. newItem.ReportType = req.FirstPage.ReportType
  349. newItem.PptDate = req.FirstPage.PptDate
  350. newItem.Content = req.Content
  351. newItem.CoverContent = req.CoverContent
  352. newItem.TitleSetting = req.TitleSetting
  353. }
  354. newId, e := models.AddPptV2(newItem)
  355. if e != nil {
  356. br.Msg = "操作失败"
  357. br.ErrMsg = fmt.Sprintf("新增PPT报告失败, %v", e)
  358. return
  359. }
  360. // 更新报告分类计数
  361. go func() {
  362. _ = services.UpdateClassifyReportNum(req.ClassifyId)
  363. }()
  364. resp := models.AddPptResp{
  365. PptId: newId,
  366. }
  367. br.Data = resp
  368. br.Ret = 200
  369. br.Success = true
  370. br.Msg = "操作成功"
  371. }
  372. // AuthList
  373. // @Title 获取有权限的列表
  374. // @Description 获取有权限的列表
  375. // @Param PageSize query int true "每页数据条数"
  376. // @Param CurrentIndex query int true "当前页页码,从1开始"
  377. // @Param Keyword query string false "搜索关键词"
  378. // @Param ClassifyId query int false "分类ID"
  379. // @Success 200 {object} models.PptPageReportResp
  380. // @router /report/auth_list [get]
  381. func (this *PptV2Controller) AuthList() {
  382. br := new(models.BaseResponse).Init()
  383. defer func() {
  384. if br.ErrMsg == "" {
  385. br.IsSendEmail = false
  386. }
  387. this.Data["json"] = br
  388. this.ServeJSON()
  389. }()
  390. sysUser := this.SysUser
  391. if sysUser == nil {
  392. br.Msg = "请登录"
  393. br.ErrMsg = "请登录,SysUser Is Empty"
  394. br.Ret = 408
  395. return
  396. }
  397. pageSize, _ := this.GetInt("PageSize")
  398. currentIndex, _ := this.GetInt("CurrentIndex")
  399. keyword := this.GetString("Keyword")
  400. classifyId, _ := this.GetInt("ClassifyId", 0)
  401. var startSize int
  402. if pageSize <= 0 {
  403. pageSize = utils.PageSize20
  404. }
  405. if currentIndex <= 0 {
  406. currentIndex = 1
  407. }
  408. startSize = utils.StartIndex(currentIndex, pageSize)
  409. var pptList []*models.PptReportItem
  410. // 无相关搜索,返回空集
  411. //if keyword == `` && classifyId <= 0 {
  412. // page := paging.GetPaging(currentIndex, pageSize, 0)
  413. // resp := new(models.PptPageReportResp)
  414. // resp.Paging = page
  415. // resp.List = pptList
  416. // br.Ret = 200
  417. // br.Success = true
  418. // br.Msg = "获取成功"
  419. // br.Data = resp
  420. // return
  421. //}
  422. // 查询自己创建的以及协作人包含自己的报告
  423. var cond string
  424. var pars []interface{}
  425. cond += ` AND (admin_id = ? OR (admin_id <> ? AND FIND_IN_SET(?, collaborate_users)))`
  426. pars = append(pars, sysUser.AdminId, sysUser.AdminId, sysUser.AdminId)
  427. if classifyId > 0 {
  428. cond += ` AND classify_id = ? `
  429. pars = append(pars, classifyId)
  430. }
  431. keyword = strings.TrimSpace(keyword)
  432. if keyword != `` {
  433. cond += ` AND title LIKE ? `
  434. pars = utils.GetLikeKeywordPars(pars, keyword, 1)
  435. }
  436. pptOb := new(models.PptV2)
  437. total, e := pptOb.GetCountByCondition(cond, pars)
  438. if e != nil {
  439. br.Msg = "获取失败"
  440. br.ErrMsg = fmt.Sprintf("获取PPT总数失败, %v", e)
  441. return
  442. }
  443. list, e := pptOb.GetPageItemsByCondition(cond, pars, models.PptReportQueryFields, "", startSize, pageSize)
  444. if e != nil {
  445. br.Msg = "获取失败"
  446. br.ErrMsg = fmt.Sprintf("获取PPT失败, %v", e)
  447. return
  448. }
  449. // 分类完整路径、协作人姓名
  450. classifyIdFull := make(map[int]string)
  451. {
  452. ob := new(models.Classify)
  453. classifies, e := ob.GetItemsByCondition("", make([]interface{}, 0), []string{}, "")
  454. if e != nil {
  455. br.Msg = "获取失败"
  456. br.ErrMsg = fmt.Sprintf("获取分类失败, %v", e)
  457. return
  458. }
  459. classifyIdName := make(map[string]string)
  460. for _, v := range classifies {
  461. classifyIdName[strconv.Itoa(v.Id)] = v.ClassifyName
  462. }
  463. for _, v := range classifies {
  464. arr := strings.Split(v.LevelPath, ",")
  465. if len(arr) == 0 {
  466. continue
  467. }
  468. var nameArr []string
  469. for _, a := range arr {
  470. n := classifyIdName[a]
  471. if n == "" {
  472. continue
  473. }
  474. nameArr = append(nameArr, n)
  475. }
  476. classifyIdFull[v.Id] = strings.Join(nameArr, "/")
  477. }
  478. }
  479. adminIdName := make(map[int]string)
  480. {
  481. cond := ` AND enabled = 1`
  482. pars := make([]interface{}, 0)
  483. sysAdmin, e := system.GetSysAdminList(cond, pars, []string{}, "")
  484. if e != nil {
  485. br.Msg = "获取失败"
  486. br.ErrMsg = "获取用户失败,Err:" + e.Error()
  487. return
  488. }
  489. for _, v := range sysAdmin {
  490. adminIdName[v.AdminId] = v.RealName
  491. }
  492. }
  493. // 格式化数据
  494. for _, v := range list {
  495. t := v.Format2ReportItem(v)
  496. t.HasAuth = true // 该列表固定有权限
  497. t.FullClassify = classifyIdFull[v.ClassifyId] // 分类的完整路径
  498. // 协作人
  499. if v.CollaborateUsers != "" {
  500. var authors []models.PptReportCollaborateUser
  501. authorArr := strings.Split(v.CollaborateUsers, ",")
  502. for _, au := range authorArr {
  503. uid, _ := strconv.Atoi(au)
  504. if uid <= 0 {
  505. continue
  506. }
  507. name := adminIdName[uid]
  508. if name == "" {
  509. continue
  510. }
  511. authors = append(authors, models.PptReportCollaborateUser{
  512. AdminId: uid,
  513. RealName: name,
  514. })
  515. }
  516. t.CollaborateUsers = authors
  517. }
  518. pptList = append(pptList, t)
  519. }
  520. page := paging.GetPaging(currentIndex, pageSize, total)
  521. resp := new(models.PptPageReportResp)
  522. resp.Paging = page
  523. resp.List = pptList
  524. br.Ret = 200
  525. br.Success = true
  526. br.Msg = "获取成功"
  527. br.Data = resp
  528. }