ppt_report.go 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "eta_gn/eta_api/models"
  5. "eta_gn/eta_api/services"
  6. "eta_gn/eta_api/utils"
  7. "fmt"
  8. "github.com/rdlucklib/rdluck_tools/paging"
  9. "strconv"
  10. "strings"
  11. "time"
  12. )
  13. // ReportClassify
  14. // @Title 获取ppt报告分类
  15. // @Description 获取ppt报告分类
  16. // @Param Source query int false "来源:1-我的;2-协作;3-公共"
  17. // @Success 200 {object} models.PptReportClassifyItem
  18. // @router /report/classify [get]
  19. func (this *PptV2Controller) ReportClassify() {
  20. br := new(models.BaseResponse).Init()
  21. defer func() {
  22. if br.ErrMsg == "" {
  23. br.IsSendEmail = false
  24. }
  25. this.Data["json"] = br
  26. this.ServeJSON()
  27. }()
  28. sysUser := this.SysUser
  29. if sysUser == nil {
  30. br.Msg = "请登录"
  31. br.ErrMsg = "请登录,SysUser Is Empty"
  32. return
  33. }
  34. source, _ := this.GetInt("Source", 1)
  35. if source < 1 || source > 3 {
  36. source = 1
  37. }
  38. fmt.Println(sysUser.AdminId)
  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 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. if classifyPpt[v.ClassifyId] == nil {
  67. classifyPpt[v.ClassifyId] = make([]*models.PptReportItem, 0)
  68. }
  69. classifyPpt[v.ClassifyId] = append(classifyPpt[v.ClassifyId], v.Format2ReportItem(v))
  70. }
  71. resp := make([]*models.PptReportClassifyItem, 0)
  72. // 获取分类
  73. classifies := make([]*models.Classify, 0)
  74. {
  75. ob := new(models.Classify)
  76. cond := ` AND enabled = ? AND classify_type = ?`
  77. pars := make([]interface{}, 0)
  78. pars = append(pars, 1, utils.ReportTypePPT)
  79. list, e := ob.GetItemsByCondition(cond, pars, []string{}, "sort ASC, create_time ASC")
  80. if e != nil {
  81. br.Msg = "获取失败"
  82. br.ErrMsg = fmt.Sprintf("获取分类失败, %v", e)
  83. return
  84. }
  85. classifies = list
  86. }
  87. resp = services.GetPptReportClassifyTreeRecursive(classifies, 0, classifyPpt)
  88. br.Data = resp
  89. br.Ret = 200
  90. br.Success = true
  91. br.Msg = "获取成功"
  92. }
  93. // ReportList
  94. // @Title 获取ppt报告列表-分页
  95. // @Description 获取ppt报告列表-分页
  96. // @Param Source query int false "来源:1-我的;2-协作;3-公共"
  97. // @Param ClassifyId query int false "分类ID"
  98. // @Param Keyword query string false "搜索关键词"
  99. // @Success 200 {object} models.PptPageReportResp
  100. // @router /report/list [get]
  101. func (this *PptV2Controller) ReportList() {
  102. br := new(models.BaseResponse).Init()
  103. defer func() {
  104. if br.ErrMsg == "" {
  105. br.IsSendEmail = false
  106. }
  107. this.Data["json"] = br
  108. this.ServeJSON()
  109. }()
  110. sysUser := this.SysUser
  111. if sysUser == nil {
  112. br.Msg = "请登录"
  113. br.ErrMsg = "请登录,SysUser Is Empty"
  114. return
  115. }
  116. pageSize, _ := this.GetInt("PageSize")
  117. currentIndex, _ := this.GetInt("CurrentIndex")
  118. source, _ := this.GetInt("Source", 1)
  119. if source < 1 || source > 3 {
  120. source = 1
  121. }
  122. classifyId, _ := this.GetInt("ClassifyId", 0)
  123. keyword := this.GetString("Keyword")
  124. var startSize int
  125. if pageSize <= 0 {
  126. pageSize = utils.PageSize20
  127. }
  128. if currentIndex <= 0 {
  129. currentIndex = 1
  130. }
  131. startSize = utils.StartIndex(currentIndex, pageSize)
  132. // 获取PPT, source:1-我的;2-协作;3-公共
  133. pptList := make([]*models.PptV2, 0)
  134. cond := ``
  135. pars := make([]interface{}, 0)
  136. {
  137. switch source {
  138. case 1:
  139. cond += ` AND admin_id = ?`
  140. pars = append(pars, sysUser.AdminId)
  141. case 2:
  142. cond += ` AND collaborate_type = ? AND FIND_IN_SET(?, collaborate_users) `
  143. pars = append(pars, utils.ReportWriteTypeGroup, sysUser.AdminId)
  144. case 3:
  145. cond += ` AND report_source = ?`
  146. pars = append(pars, utils.ReportSourceOuter)
  147. }
  148. if classifyId > 0 {
  149. cond += ` AND classify_id = ?`
  150. pars = append(pars, classifyId)
  151. }
  152. keyword = strings.TrimSpace(keyword)
  153. if keyword != "" {
  154. cond += ` AND title LIKE ?`
  155. pars = append(pars, fmt.Sprint("%", keyword, "%"))
  156. }
  157. }
  158. pptOb := new(models.PptV2)
  159. total, e := pptOb.GetCountByCondition(cond, pars)
  160. if e != nil {
  161. br.Msg = "获取失败"
  162. br.ErrMsg = fmt.Sprintf("获取PPT总数失败, %v", e)
  163. return
  164. }
  165. list, e := pptOb.GetPageItemsByCondition(cond, pars, models.PptReportQueryFields, "", startSize, pageSize)
  166. if e != nil {
  167. br.Msg = "获取失败"
  168. br.ErrMsg = fmt.Sprintf("获取PPT失败, %v", e)
  169. return
  170. }
  171. pptList = list
  172. resp := new(models.PptPageReportResp)
  173. resp.List = make([]*models.PptReportItem, 0)
  174. for _, v := range pptList {
  175. resp.List = append(resp.List, v.Format2ReportItem(v))
  176. }
  177. page := paging.GetPaging(currentIndex, pageSize, total)
  178. resp.Paging = page
  179. br.Data = resp
  180. br.Ret = 200
  181. br.Success = true
  182. br.Msg = "获取成功"
  183. }
  184. // CreateReport
  185. // @Title 新增ppt报告
  186. // @Description 新增ppt报告
  187. // @Param request body models.PptReportCreateReq true "type json string"
  188. // @Success 200 Ret=200 新增成功
  189. // @router /report/add [post]
  190. func (this *PptV2Controller) CreateReport() {
  191. br := new(models.BaseResponse).Init()
  192. defer func() {
  193. if br.ErrMsg == "" {
  194. br.IsSendEmail = false
  195. }
  196. this.Data["json"] = br
  197. this.ServeJSON()
  198. }()
  199. sysUser := this.SysUser
  200. if sysUser == nil {
  201. br.Msg = "请登录"
  202. br.ErrMsg = "请登录,SysUser Is Empty"
  203. return
  204. }
  205. var req models.PptReportCreateReq
  206. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  207. br.Msg = "参数解析异常"
  208. br.ErrMsg = fmt.Sprintf("参数解析失败, %v", e)
  209. return
  210. }
  211. req.Title = strings.TrimSpace(req.Title)
  212. if req.Title == "" {
  213. br.Msg = "请输入标题"
  214. return
  215. }
  216. if req.AddType != 1 && req.AddType != 2 {
  217. br.Msg = "新增方式异常"
  218. br.ErrMsg = fmt.Sprintf("新增方式异常, %d", req.AddType)
  219. return
  220. }
  221. if req.ClassifyId <= 0 {
  222. br.Msg = "请选择分类"
  223. return
  224. }
  225. if req.CollaborateType != 1 && req.CollaborateType != 2 {
  226. br.Msg = "协作方式异常"
  227. br.ErrMsg = fmt.Sprintf("协作方式异常, %d", req.CollaborateType)
  228. return
  229. }
  230. if req.CollaborateType == 2 && len(req.CollaborateUserIds) == 0 {
  231. br.Msg = "请选择协作人"
  232. return
  233. }
  234. // 新报告
  235. newItem := new(models.PptV2)
  236. newItem.Title = req.Title
  237. newItem.AddType = req.AddType
  238. newItem.ClassifyId = req.ClassifyId
  239. newItem.CollaborateType = req.CollaborateType
  240. if len(req.CollaborateUserIds) > 0 {
  241. var partnerArr []string
  242. for _, v := range req.CollaborateUserIds {
  243. partnerArr = append(partnerArr, strconv.Itoa(v))
  244. }
  245. newItem.CollaborateUsers = strings.Trim(strings.Join(partnerArr, ","), `"`)
  246. }
  247. newItem.PptVersion = 2
  248. newItem.AdminId = sysUser.AdminId
  249. newItem.AdminRealName = sysUser.RealName
  250. newItem.ReportSource = utils.ReportSourceLocal // 固定本地PPT
  251. newItem.State = models.ReportStateUnpublished // 默认未发布
  252. newItem.CreateTime = time.Now()
  253. newItem.ModifyTime = time.Now()
  254. // 继承PPT内容
  255. if req.AddType == utils.ReportAddTypeInherit && req.InheritPptId > 0 {
  256. inheritPpt, e := models.GetPptV2ById(req.InheritPptId)
  257. if e != nil {
  258. if utils.IsErrNoRow(e) {
  259. br.Msg = "被继承报告不存在"
  260. return
  261. }
  262. br.Msg = "操作失败"
  263. br.ErrMsg = fmt.Sprintf("操作失败, %v", e)
  264. return
  265. }
  266. newItem.TemplateType = inheritPpt.TemplateType
  267. newItem.BackgroundImg = inheritPpt.BackgroundImg
  268. newItem.ReportType = inheritPpt.ReportType
  269. newItem.PptDate = inheritPpt.PptDate
  270. newItem.Content = inheritPpt.Content
  271. newItem.CoverContent = inheritPpt.CoverContent
  272. newItem.TitleSetting = inheritPpt.TitleSetting
  273. }
  274. newId, e := models.AddPptV2(newItem)
  275. if e != nil {
  276. br.Msg = "操作失败"
  277. br.ErrMsg = fmt.Sprintf("新增PPT报告失败, %v", e)
  278. return
  279. }
  280. // 更新报告分类计数
  281. go func() {
  282. _ = services.UpdateClassifyReportNum(req.ClassifyId)
  283. }()
  284. resp := models.AddPptResp{
  285. PptId: newId,
  286. }
  287. br.Data = resp
  288. br.Ret = 200
  289. br.Success = true
  290. br.Msg = "操作成功"
  291. }
  292. // SubmitReport
  293. // @Title 提交报告
  294. // @Description 提交报告
  295. // @Param request body models.PptReportCreateReq true "type json string"
  296. // @Success 200 Ret=200 新增成功
  297. // @router /report/submit [post]
  298. func (this *PptV2Controller) SubmitReport() {
  299. br := new(models.BaseResponse).Init()
  300. defer func() {
  301. if br.ErrMsg == "" {
  302. br.IsSendEmail = false
  303. }
  304. this.Data["json"] = br
  305. this.ServeJSON()
  306. }()
  307. sysUser := this.SysUser
  308. if sysUser == nil {
  309. br.Msg = "请登录"
  310. br.ErrMsg = "请登录,SysUser Is Empty"
  311. return
  312. }
  313. //var req models.PptReportCreateReq
  314. //if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  315. // br.Msg = "参数解析异常"
  316. // br.ErrMsg = fmt.Sprintf("参数解析失败, %v", e)
  317. // return
  318. //}
  319. br.Ret = 200
  320. br.Success = true
  321. br.Msg = "操作成功"
  322. }