ppt_v2.go 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "eta_gn/eta_api/models"
  5. "eta_gn/eta_api/models/company"
  6. "eta_gn/eta_api/services"
  7. "eta_gn/eta_api/services/ppt"
  8. "eta_gn/eta_api/utils"
  9. "fmt"
  10. _ "image/gif"
  11. _ "image/jpeg"
  12. _ "image/png"
  13. "os"
  14. "path"
  15. "strconv"
  16. "strings"
  17. "time"
  18. "github.com/rdlucklib/rdluck_tools/paging"
  19. )
  20. // PptV2Controller 新版ppt模块
  21. type PptV2Controller struct {
  22. BaseAuthController
  23. }
  24. // PptV2CommonController 新版ppt公共模块
  25. type PptV2CommonController struct {
  26. BaseCommonController
  27. }
  28. // ListPpt
  29. // @Title 获取ppt列表
  30. // @Description 获取ppt列表接口
  31. // @Param PageSize query int true "每页数据条数"
  32. // @Param CurrentIndex query int true "当前页页码,从1开始"
  33. // @Param KeyWord query string true "搜索关键词"
  34. // @Success 200 {object} models.PptV2ListResp
  35. // @router /list [get]
  36. func (this *PptV2Controller) ListPpt() {
  37. br := new(models.BaseResponse).Init()
  38. defer func() {
  39. this.Data["json"] = br
  40. this.ServeJSON()
  41. }()
  42. sysUser := this.SysUser
  43. if sysUser == nil {
  44. br.Msg = "请登录"
  45. br.ErrMsg = "请登录,SysUser Is Empty"
  46. return
  47. }
  48. pageSize, _ := this.GetInt("PageSize")
  49. currentIndex, _ := this.GetInt("CurrentIndex")
  50. keyWord := this.GetString("KeyWord")
  51. var startSize int
  52. if pageSize <= 0 {
  53. pageSize = utils.PageSize20
  54. }
  55. if currentIndex <= 0 {
  56. currentIndex = 1
  57. }
  58. startSize = utils.StartIndex(currentIndex, pageSize)
  59. var condition string
  60. var pars []interface{}
  61. if keyWord != "" {
  62. condition += ` AND (title LIKE ? OR admin_real_name LIKE ? ) `
  63. pars = utils.GetLikeKeywordPars(pars, keyWord, 2)
  64. }
  65. total, err := models.GetPptV2ListCount(condition, pars)
  66. if err != nil {
  67. br.Msg = "获取失败"
  68. br.ErrMsg = "获取失败,Err:" + err.Error()
  69. return
  70. }
  71. list, err := models.GetPptV2List(condition, pars, startSize, pageSize)
  72. if err != nil {
  73. br.Msg = "获取失败"
  74. br.ErrMsg = "获取失败,Err:" + err.Error()
  75. return
  76. }
  77. lenList := len(list)
  78. for i := 0; i < lenList; i++ {
  79. adminId := list[i].AdminId
  80. if adminId == sysUser.AdminId || sysUser.Role == "admin" {
  81. list[i].IsAuth = true
  82. } else {
  83. list[i].IsAuth = false
  84. }
  85. }
  86. page := paging.GetPaging(currentIndex, pageSize, total)
  87. resp := new(models.PptV2ListResp)
  88. resp.Paging = page
  89. resp.List = list
  90. br.Ret = 200
  91. br.Success = true
  92. br.Msg = "获取成功"
  93. br.Data = resp
  94. }
  95. // AddPpt
  96. // @Title 新增ppt
  97. // @Description 新增ppt接口
  98. // @Param request body models.AddPptV2Req true "type json string"
  99. // @Success 200 Ret=200 新增成功
  100. // @router /add [post]
  101. func (this *PptV2Controller) AddPpt() {
  102. br := new(models.BaseResponse).Init()
  103. defer func() {
  104. this.Data["json"] = br
  105. this.ServeJSON()
  106. }()
  107. var req models.AddPptV2Req
  108. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  109. if err != nil {
  110. br.Msg = "参数解析异常!"
  111. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  112. return
  113. }
  114. if req.FirstPage.Title == "" {
  115. br.Msg = "标题不能为空"
  116. return
  117. }
  118. var newId int64
  119. var msg string
  120. if req.PptId <= 0 {
  121. if req.GroupId == 0 {
  122. br.Msg = "请输入目录ID"
  123. return
  124. }
  125. //item, err := models.GetPptV2ByTitleAndId(req.FirstPage.Title, this.SysUser.AdminId)
  126. //if err != nil && !utils.IsErrNoRow(err) {
  127. // br.Msg = "获取数据异常!"
  128. // br.ErrMsg = "获取数据异常,Err:" + err.Error()
  129. // return
  130. //}
  131. //if item != nil && item.PptId > 0 && item.PptId != int(req.PptId) {
  132. // br.Msg = "标题已存在,不可重复添加"
  133. // br.IsSendEmail = false
  134. // return
  135. //}
  136. pptInfo := &models.PptV2{
  137. //PptId: 0,
  138. TemplateType: req.FirstPage.TemplateType,
  139. BackgroundImg: req.FirstPage.ImgUrl,
  140. Title: req.FirstPage.Title,
  141. ReportType: req.FirstPage.ReportType,
  142. PptDate: req.FirstPage.PptDate,
  143. Content: req.Content,
  144. CoverContent: req.CoverContent,
  145. CreateTime: time.Now(),
  146. ModifyTime: time.Now(),
  147. AdminId: this.SysUser.AdminId,
  148. AdminRealName: this.SysUser.RealName,
  149. PptVersion: 2,
  150. TitleSetting: req.TitleSetting,
  151. }
  152. newId, err = models.AddPptV2(pptInfo)
  153. if err != nil {
  154. br.Msg = "新增失败"
  155. br.ErrMsg = "新增失败,Err:" + err.Error()
  156. return
  157. }
  158. //新增ppt和目录映射
  159. _, err = ppt.AddGroupPptMapping(newId, req.GroupId, this.SysUser.AdminId, this.SysUser.RealName)
  160. if err != nil {
  161. br.Msg = err.Error()
  162. return
  163. }
  164. msg = "新增成功"
  165. } else {
  166. newId = req.PptId
  167. pptInfo, err := models.GetPptV2ById(int(req.PptId))
  168. if err != nil {
  169. br.Msg = "信息获取失败"
  170. br.ErrMsg = "信息获取失败,Err:" + err.Error()
  171. return
  172. }
  173. pptInfo.TemplateType = req.FirstPage.TemplateType
  174. pptInfo.BackgroundImg = req.FirstPage.ImgUrl
  175. pptInfo.Title = req.FirstPage.Title
  176. pptInfo.ReportType = req.FirstPage.ReportType
  177. pptInfo.PptDate = req.FirstPage.PptDate
  178. pptInfo.Content = req.Content
  179. pptInfo.CoverContent = req.CoverContent
  180. pptInfo.ModifyTime = time.Now()
  181. pptInfo.TitleSetting = req.TitleSetting
  182. err = pptInfo.Update([]string{"TemplateType", "BackgroundImg", "Title", "ReportType", "PptDate", "Content", "ModifyTime", "CoverContent", "TitleSetting"})
  183. msg = "保存成功"
  184. }
  185. resp := models.AddPptResp{
  186. PptId: newId,
  187. }
  188. br.Ret = 200
  189. br.Success = true
  190. br.Msg = msg
  191. br.Data = resp
  192. }
  193. // EditPpt
  194. // @Title 编辑ppt
  195. // @Description 编辑ppt接口
  196. // @Param request body models.AddPptV2Req true "type json string"
  197. // @Success 200 Ret=200 编辑成功
  198. // @router /edit [post]
  199. func (this *PptV2Controller) EditPpt() {
  200. br := new(models.BaseResponse).Init()
  201. defer func() {
  202. this.Data["json"] = br
  203. this.ServeJSON()
  204. }()
  205. var req models.AddPptV2Req
  206. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  207. if err != nil {
  208. br.Msg = "参数解析异常!"
  209. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  210. return
  211. }
  212. if req.FirstPage.Title == "" {
  213. br.Msg = "标题不能为空"
  214. return
  215. }
  216. pptInfo, err := models.GetPptV2ById(int(req.PptId))
  217. if err != nil {
  218. br.Msg = "信息获取失败"
  219. br.ErrMsg = "信息获取失败,Err:" + err.Error()
  220. return
  221. }
  222. // 协作人权限
  223. if pptInfo.AdminId != this.SysUser.AdminId {
  224. if pptInfo.CollaborateType != utils.ReportWriteTypeGroup {
  225. br.Msg = "非协作人无权操作"
  226. return
  227. }
  228. if pptInfo.CollaborateUsers == "" {
  229. br.Msg = "非协作人无权操作"
  230. return
  231. }
  232. partnerArr := strings.Split(pptInfo.CollaborateUsers, ",")
  233. if !utils.InArrayByStr(partnerArr, fmt.Sprint(this.SysUser.AdminId)) {
  234. br.Msg = "非协作人无权操作"
  235. return
  236. }
  237. }
  238. // 修改
  239. pptInfo.TemplateType = req.FirstPage.TemplateType
  240. pptInfo.BackgroundImg = req.FirstPage.ImgUrl
  241. pptInfo.CurrentBackgroundImg = req.FirstPage.CurrentBackgroundImg
  242. pptInfo.BackCoverImg = req.FirstPage.BackCoverImg
  243. pptInfo.CurrentBackgroundImgId = req.FirstPage.CurrentBackgroundImgId
  244. pptInfo.BackCoverImgId = req.FirstPage.BackCoverImgId
  245. pptInfo.BackgroundImgId = req.FirstPage.BackgroundImgId
  246. pptInfo.Title = req.FirstPage.Title
  247. pptInfo.ReportType = req.FirstPage.ReportType
  248. pptInfo.PptDate = req.FirstPage.PptDate
  249. pptInfo.Content = req.Content
  250. pptInfo.CoverContent = req.CoverContent
  251. pptInfo.ModifyTime = time.Now()
  252. pptInfo.TitleSetting = req.TitleSetting
  253. err = pptInfo.Update([]string{"TemplateType", "BackgroundImg", "CurrentBackgroundImg", "BackCoverImg", "CurrentBackgroundImgId", "BackCoverImgId", "BackgroundImgId", "Title", "ReportType", "PptDate", "Content", "ModifyTime", "CoverContent", "TitleSetting"})
  254. if err != nil {
  255. br.Msg = "编辑失败"
  256. br.ErrMsg = "编辑失败,Err:" + err.Error()
  257. return
  258. }
  259. //pptMap, err := models.GetPptMappingByPptId(req.PptId)
  260. //if err != nil {
  261. // br.Msg = `该PPT信息不存在, 保存失败`
  262. // br.ErrMsg = `该PPT信息不存在, 保存失败, Err` + err.Error()
  263. // br.IsSendEmail = false
  264. // return
  265. //}
  266. //pptMapList, err := models.GetPptMappingListByGroupId(pptMap.GroupId)
  267. //if err != nil {
  268. // br.ErrMsg = "PPT目录信息异常"
  269. // return
  270. //}
  271. //count, err := models.GetPptMappingByGroupPptCountId(pptMap.GroupPptId, this.SysUser.AdminId)
  272. //if err != nil {
  273. // br.Msg = "查询映射关系失败"
  274. // br.ErrMsg = "查询映射关系失败, 保存失败, Err:" + err.Error()
  275. // return
  276. //}
  277. //if !pptMap.IsMoved && len(pptMapList) > 1 && count > 0 {
  278. // // 如果没有人为移动位置, 默认将当前ppt置顶
  279. // err = ppt.MoveGroupPpt(pptMap.GroupId, pptMap.GroupPptId, pptMapList[0].GroupPptId, 0, this.SysUser.AdminId)
  280. // if err != nil {
  281. // br.Msg = err.Error()
  282. // br.ErrMsg = "移动失败,Err:" + err.Error()
  283. // return
  284. // }
  285. //}
  286. // 版本记录
  287. historyInfo := &models.PptV2History{
  288. PptId: pptInfo.PptId,
  289. TemplateType: pptInfo.TemplateType,
  290. BackgroundImg: pptInfo.BackgroundImg,
  291. Title: pptInfo.Title,
  292. ReportType: pptInfo.ReportType,
  293. PptDate: pptInfo.PptDate,
  294. Content: pptInfo.Content,
  295. CoverContent: pptInfo.CoverContent,
  296. AdminId: this.SysUser.AdminId,
  297. AdminRealName: this.SysUser.RealName,
  298. CreateTime: time.Now(),
  299. TitleSetting: pptInfo.TitleSetting,
  300. }
  301. err = historyInfo.Add()
  302. if err != nil {
  303. br.Msg = "保存失败"
  304. br.ErrMsg = "保存PPT版本失败, Err: " + err.Error()
  305. return
  306. }
  307. // 日志记录
  308. {
  309. logInfo := &models.PptV2SaveLog{
  310. PptId: pptInfo.PptId,
  311. TemplateType: pptInfo.TemplateType,
  312. BackgroundImg: pptInfo.BackgroundImg,
  313. CurrentBackgroundImg: pptInfo.CurrentBackgroundImg,
  314. BackCoverImg: pptInfo.BackCoverImg,
  315. Title: pptInfo.Title,
  316. ReportType: pptInfo.ReportType,
  317. PptDate: pptInfo.PptDate,
  318. Content: pptInfo.Content,
  319. CoverContent: pptInfo.CoverContent,
  320. AdminId: this.SysUser.AdminId,
  321. AdminRealName: this.SysUser.RealName,
  322. CreateTime: time.Now(),
  323. }
  324. _, err = models.AddPptV2SaveLog(logInfo)
  325. }
  326. resp := models.AddPptResp{
  327. PptId: req.PptId,
  328. }
  329. br.Ret = 200
  330. br.Success = true
  331. br.Msg = "编辑成功"
  332. br.IsAddLog = true
  333. br.Data = resp
  334. }
  335. // DeletePpt
  336. // @Title 删除ppt
  337. // @Description 删除ppt接口
  338. // @Param request body models.DeletePptV2Req true "type json string"
  339. // @Success 200 Ret=200 删除成功
  340. // @router /delete [post]
  341. func (this *PptV2Controller) DeletePpt() {
  342. br := new(models.BaseResponse).Init()
  343. defer func() {
  344. this.Data["json"] = br
  345. this.ServeJSON()
  346. }()
  347. var req models.DeletePptV2Req
  348. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  349. if err != nil {
  350. br.Msg = "参数解析异常!"
  351. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  352. return
  353. }
  354. if req.PptId <= 0 {
  355. br.Msg = "参数错误"
  356. return
  357. }
  358. pptInfo, err := models.GetPptV2ById(req.PptId)
  359. if err != nil {
  360. br.Msg = "ppt不存在"
  361. return
  362. }
  363. if pptInfo.AdminId != this.SysUser.AdminId {
  364. br.Msg = "无权删除"
  365. return
  366. }
  367. if pptInfo.ReportSource != utils.ReportSourceLocal {
  368. br.Msg = "仅允许删除系统内部报告"
  369. return
  370. }
  371. err = models.DeletePptV2(req.PptId)
  372. if err != nil {
  373. br.Msg = "删除失败"
  374. br.ErrMsg = "删除失败,Err:" + err.Error()
  375. return
  376. }
  377. //如果该ppt存在单个共享记录,则删除共享
  378. err = ppt.DeleteGroupPpt(req.PptId)
  379. if err != nil {
  380. br.Msg = "删除失败"
  381. br.ErrMsg = "删除失败,Err:" + err.Error()
  382. return
  383. }
  384. // 更新报告计数
  385. go func() {
  386. _ = services.UpdateClassifyReportNum(pptInfo.ClassifyId)
  387. }()
  388. br.Ret = 200
  389. br.Success = true
  390. br.IsAddLog = true
  391. br.Msg = "删除成功"
  392. }
  393. // DetailPpt
  394. // @Title 获取ppt详情
  395. // @Description 获取ppt详情接口
  396. // @Param PptId query int true "PptId"
  397. // @Success 200 {object} models.PptV2
  398. // @router /detail [get]
  399. func (this *PptV2Controller) DetailPpt() {
  400. br := new(models.BaseResponse).Init()
  401. defer func() {
  402. if br.ErrMsg == "" {
  403. br.IsSendEmail = false
  404. }
  405. this.Data["json"] = br
  406. this.ServeJSON()
  407. }()
  408. sysUser := this.SysUser
  409. if sysUser == nil {
  410. br.Msg = "请登录"
  411. br.ErrMsg = "请登录,SysUser Is Empty"
  412. br.Ret = 408
  413. return
  414. }
  415. pptId, _ := this.GetInt("PptId")
  416. pptInfo, err := models.GetPptV2ById(pptId)
  417. if err != nil {
  418. br.Msg = "信息获取失败"
  419. br.ErrMsg = "信息获取失败,Err:" + err.Error()
  420. return
  421. }
  422. // 权限
  423. var hasAuth bool
  424. if pptInfo.AdminId == sysUser.AdminId {
  425. hasAuth = true
  426. }
  427. if hasAuth == false && pptInfo.CollaborateUsers != "" {
  428. authorArr := strings.Split(pptInfo.CollaborateUsers, ",")
  429. strId := strconv.Itoa(sysUser.AdminId)
  430. if utils.InArrayByStr(authorArr, strId) {
  431. hasAuth = true
  432. }
  433. }
  434. // 编辑中
  435. editor, e := services.UpdatePptEditing(pptId, 0, sysUser.AdminId, sysUser.RealName, false)
  436. if e != nil {
  437. br.Msg = "操作失败"
  438. br.ErrMsg = "更新编辑状态失败, err: " + e.Error()
  439. return
  440. }
  441. resp := new(models.PPTDetailResp)
  442. resp.PptV2 = pptInfo
  443. resp.Editor = editor
  444. resp.HasAuth = hasAuth
  445. br.Ret = 200
  446. br.Success = true
  447. br.Msg = "获取成功"
  448. br.Data = resp
  449. }
  450. // DownloadPptx
  451. // @Title ppt下载
  452. // @Description ppt下载
  453. // @Param PptId query int true "PptId"
  454. // @Success 200 下载成功
  455. // @router /downloadpptx [get]
  456. func (this *PptV2CommonController) DownloadPptx() {
  457. br := new(models.BaseResponse).Init()
  458. defer func() {
  459. this.Data["json"] = br
  460. this.ServeJSON()
  461. }()
  462. pptId, err := this.GetInt("PptId")
  463. if err != nil {
  464. br.Msg = "参数错误"
  465. br.ErrMsg = "获取,pptId,Err:" + err.Error()
  466. return
  467. }
  468. pptInfo, err := models.GetPptV2ById(pptId)
  469. if err != nil {
  470. br.Msg = "获取信息失败"
  471. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  472. return
  473. }
  474. filePath := pptInfo.PptxUrl
  475. fileName := pptInfo.Title + ".pptx"
  476. this.Ctx.Output.Download(filePath, fileName)
  477. br.Success = true
  478. br.Ret = 200
  479. br.Msg = "下载成功"
  480. return
  481. }
  482. // Publish
  483. // @Title 发布接口
  484. // @Description 发布接口
  485. // @Param request body models.SavePptV2PathReq true "type json string"
  486. // @Success Ret=200 发布成功
  487. // @router /publish [post]
  488. func (this *PptV2Controller) Publish() {
  489. br := new(models.BaseResponse).Init()
  490. defer func() {
  491. if br.ErrMsg == "" {
  492. br.IsSendEmail = false
  493. }
  494. this.Data["json"] = br
  495. this.ServeJSON()
  496. }()
  497. var req models.SavePptV2PathReq
  498. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  499. if err != nil {
  500. br.Msg = "参数解析异常!"
  501. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  502. return
  503. }
  504. pptId := req.PptId
  505. if pptId <= 0 {
  506. br.Msg = "参数错误"
  507. return
  508. }
  509. req.PptxUrl = strings.TrimSpace(req.PptxUrl)
  510. if req.PptxUrl == "" {
  511. br.Msg = "文件地址为空"
  512. return
  513. }
  514. //err = models.EditPptV2Path(pptId, req.PptxUrl)
  515. //if err != nil {
  516. // br.Msg = "发布失败"
  517. // br.ErrMsg = "发布失败,Err:" + err.Error()
  518. // return
  519. //}
  520. pptItem, e := models.GetPptV2ById(pptId)
  521. if e != nil {
  522. if utils.IsErrNoRow(e) {
  523. br.Msg = "PPT不存在, 请刷新页面"
  524. return
  525. }
  526. br.Msg = "操作失败"
  527. br.ErrMsg = fmt.Sprintf("获取PPT失败, %v", e)
  528. return
  529. }
  530. stateOrigin := pptItem.State
  531. var updateCols []string
  532. updateCols = append(updateCols, "PptxUrl", "ModifyTime")
  533. pptItem.PptxUrl = req.PptxUrl
  534. pptItem.ModifyTime = time.Now()
  535. // 本地PPT(不加限制, 想发布就发布)
  536. if pptItem.ReportSource == utils.ReportSourceLocal {
  537. updateCols = append(updateCols, "State", "PublishTime")
  538. pptItem.State = models.ReportStatePublished
  539. pptItem.PublishTime = time.Now()
  540. }
  541. // 外部PPT
  542. if pptItem.ReportSource == utils.ReportSourceOuter {
  543. // 报告状态
  544. if pptItem.OutReportId == "" {
  545. br.Msg = "PPT异常"
  546. br.ErrMsg = fmt.Sprintf("PPT外部报告ID为空, ID: %d", pptId)
  547. return
  548. }
  549. if pptItem.State != models.ReportStateWaitSubmit && pptItem.State != models.ReportStateRefused {
  550. br.Msg = "状态异常, 不允许提交"
  551. br.ErrMsg = fmt.Sprintf("PPT报告状态异常, %d", pptItem.State)
  552. return
  553. }
  554. updateCols = append(updateCols, "SubmitTime", "State")
  555. pptItem.SubmitTime = time.Now()
  556. pptItem.State = models.ReportStateWaitApprove
  557. }
  558. // 更新PPT
  559. if e = pptItem.Update(updateCols); e != nil {
  560. br.Msg = "操作失败"
  561. br.ErrMsg = fmt.Sprintf("更新PPT失败, %v", e)
  562. return
  563. }
  564. //添加发布记录
  565. {
  566. record := new(models.PptV2PublishRecord)
  567. record.CreateTime = time.Now()
  568. record.PptId = pptId
  569. record.PptUrl = req.PptxUrl
  570. go models.AddPptV2PublishRecord(record)
  571. }
  572. // 回调智力共享审批
  573. go func() {
  574. if pptItem.ReportSource != utils.ReportSourceOuter {
  575. return
  576. }
  577. outId, _ := strconv.Atoi(pptItem.OutReportId)
  578. // 若回调失败, 则恢复提交前状态(先这么处理吧,允许再次提交)
  579. e = services.OuterReportCallBack(outId, pptItem.Title, req.PptxUrl, ".pptx")
  580. if e != nil {
  581. pptItem.State = stateOrigin
  582. _ = pptItem.Update([]string{"State"})
  583. }
  584. }()
  585. br.Ret = 200
  586. br.Success = true
  587. br.Msg = "发布成功"
  588. br.IsAddLog = true
  589. return
  590. }
  591. // PptUpload
  592. // @Title ppt上传
  593. // @Description ppt上传
  594. // @Param PptId query int true "PptId"
  595. // @Success 200 新增成功
  596. // @router /pptUpload [post]
  597. func (this *PptV2Controller) PptUpload() {
  598. br := new(models.BaseResponse).Init()
  599. defer func() {
  600. this.Data["json"] = br
  601. this.ServeJSON()
  602. }()
  603. pptId, _ := this.GetInt("PptId", 0)
  604. if pptId <= 0 {
  605. br.Msg = "参数错误"
  606. return
  607. }
  608. _, err := models.GetPptV2ById(pptId)
  609. if err != nil {
  610. br.Msg = "获取数据失败"
  611. br.ErrMsg = "获取PPT详情失败,Err:" + err.Error()
  612. return
  613. }
  614. f, h, err := this.GetFile("file")
  615. if err != nil {
  616. br.Msg = "获取资源信息失败"
  617. br.ErrMsg = "获取资源信息失败,Err:" + err.Error()
  618. return
  619. }
  620. defer func() {
  621. _ = f.Close()
  622. }()
  623. uploadFileName := h.Filename //上传的文件名
  624. ext := path.Ext(h.Filename)
  625. dateDir := time.Now().Format("20060102")
  626. uploadDir := utils.STATIC_DIR + "ppt/" + dateDir
  627. err = os.MkdirAll(uploadDir, utils.DIR_MOD)
  628. if err != nil {
  629. br.Msg = "存储目录创建失败"
  630. br.ErrMsg = "存储目录创建失败,Err:" + err.Error()
  631. return
  632. }
  633. randStr := utils.GetRandStringNoSpecialChar(28)
  634. fileName := randStr + ext
  635. fpath := uploadDir + "/" + fileName
  636. if err = this.SaveToFile("file", fpath); err != nil {
  637. br.Msg = "文件上传失败"
  638. br.ErrMsg = "文件上传失败,Err:" + err.Error()
  639. return
  640. }
  641. defer func() {
  642. _ = os.Remove(fpath)
  643. }()
  644. hzUploadDir := utils.RESOURCE_DIR + "ppt/"
  645. savePptxToOssPath := hzUploadDir + time.Now().Format("200601/20060102/")
  646. //pptName := strings.Replace(pptItem.Title, "\n", "", -1)
  647. //pptName = strings.TrimSuffix(pptName, " ")
  648. pptName := utils.GetRandStringNoSpecialChar(28)
  649. savePptxToOssPath += pptName + ".pptx"
  650. //上传到阿里云 和 minio
  651. pptxUrl := ``
  652. ossClient := services.NewOssClient()
  653. if ossClient == nil {
  654. br.Msg = "上传失败"
  655. br.ErrMsg = "初始化OSS服务失败"
  656. return
  657. }
  658. pptxUrl, err = ossClient.UploadFile(fileName, fpath, savePptxToOssPath)
  659. if err != nil {
  660. br.Msg = "文件上传失败"
  661. br.ErrMsg = "文件上传失败,Err:" + err.Error()
  662. return
  663. }
  664. resp := models.ResourceResp{
  665. ResourceUrl: pptxUrl,
  666. ResourceName: uploadFileName,
  667. }
  668. br.Msg = "上传成功"
  669. br.Ret = 200
  670. br.Success = true
  671. br.Data = resp
  672. return
  673. }
  674. // SaveLog
  675. // @Title 定时ppt操作日志记录
  676. // @Description 定时ppt操作日志记录
  677. // @Param request body models.AddPptV2Req true "type json string"
  678. // @Success 200 新增成功
  679. // @router /saveLog [post]
  680. func (this *PptV2Controller) SaveLog() {
  681. br := new(models.BaseResponse).Init()
  682. defer func() {
  683. if br.ErrMsg == "" {
  684. br.IsSendEmail = false
  685. }
  686. this.Data["json"] = br
  687. this.ServeJSON()
  688. }()
  689. sysUser := this.SysUser
  690. if sysUser == nil {
  691. br.Msg = "请登录"
  692. br.ErrMsg = "请登录,SysUser Is Empty"
  693. br.Ret = 408
  694. return
  695. }
  696. var req models.AddPptV2Req
  697. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  698. if err != nil {
  699. br.Msg = "参数解析异常!"
  700. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  701. return
  702. }
  703. if req.FirstPage.Title == "" {
  704. br.Msg = "标题不能为空"
  705. return
  706. }
  707. var pptContent []services.PPTContent
  708. err = json.Unmarshal([]byte(req.Content), &pptContent)
  709. if err != nil {
  710. br.Msg = "参数解析异常!"
  711. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  712. return
  713. }
  714. // 获取ppt
  715. //item, err := models.GetPptV2ByTitleAndId(req.FirstPage.Title, this.SysUser.AdminId)
  716. //if err != nil && !utils.IsErrNoRow(err) {
  717. // br.Msg = "获取数据异常!"
  718. // br.ErrMsg = "获取数据异常,Err:" + err.Error()
  719. // return
  720. //}
  721. //if item != nil && item.PptId > 0 && item.PptId != int(req.PptId) {
  722. // br.Msg = "标题已存在,不可重复添加"
  723. // br.IsSendEmail = false
  724. // return
  725. //}
  726. //变更ppt内容
  727. pptItem, e := models.GetPptV2ById(int(req.PptId))
  728. if e != nil {
  729. if utils.IsErrNoRow(e) {
  730. br.Msg = "PPT已被删除, 请刷新页面"
  731. return
  732. }
  733. br.Msg = "信息获取失败"
  734. br.ErrMsg = "信息获取失败,Err:" + e.Error()
  735. return
  736. }
  737. // 标记编辑状态
  738. if pptItem.PptId > 0 {
  739. _, e = services.UpdatePptEditing(pptItem.PptId, 1, sysUser.AdminId, sysUser.RealName, false)
  740. if e != nil {
  741. br.Msg = "操作失败"
  742. br.ErrMsg = "更新编辑状态失败, err: " + e.Error()
  743. return
  744. }
  745. }
  746. pptItem.TemplateType = req.FirstPage.TemplateType
  747. pptItem.BackgroundImg = req.FirstPage.ImgUrl
  748. pptItem.CurrentBackgroundImg = req.FirstPage.CurrentBackgroundImg
  749. pptItem.BackCoverImg = req.FirstPage.BackCoverImg
  750. pptItem.CurrentBackgroundImgId = req.FirstPage.CurrentBackgroundImgId
  751. pptItem.BackCoverImgId = req.FirstPage.BackCoverImgId
  752. pptItem.BackgroundImgId = req.FirstPage.BackgroundImgId
  753. pptItem.Title = req.FirstPage.Title
  754. pptItem.ReportType = req.FirstPage.ReportType
  755. pptItem.PptDate = req.FirstPage.PptDate
  756. pptItem.Content = req.Content
  757. pptItem.ModifyTime = time.Now()
  758. pptItem.TitleSetting = req.TitleSetting
  759. pptItem.PptPage = len(pptContent)
  760. err = pptItem.Update([]string{"TemplateType", "BackgroundImg", "CurrentBackgroundImg", "BackCoverImg", "CurrentBackgroundImgId", "BackCoverImgId", "BackgroundImgId", "Title", "ReportType", "PptDate", "Content", "ModifyTime", "TitleSetting", "ppt_page"})
  761. if err != nil {
  762. br.Msg = "自动保存失败"
  763. br.ErrMsg = fmt.Sprintf("自动保存PPT失败, ID: %d, Err: %v", pptItem.PptId, err)
  764. return
  765. }
  766. // 将更新后的PPT, 置顶
  767. //pptMap, err := models.GetPptMappingByPptId(int64(req.PptId))
  768. //if err != nil {
  769. // br.Msg = `该PPT信息不存在, 保存失败`
  770. // br.ErrMsg = `该PPT信息不存在, 保存失败, Err` + err.Error()
  771. // br.IsSendEmail = false
  772. // return
  773. //}
  774. //pptMapList, err := models.GetPptMappingListByGroupId(pptMap.GroupId)
  775. //if err != nil {
  776. // br.ErrMsg = "PPT目录信息异常"
  777. // return
  778. //}
  779. //count, err := models.GetPptMappingByGroupPptCountId(pptMap.GroupPptId, this.SysUser.AdminId)
  780. //if err != nil {
  781. // br.Msg = "查询映射关系失败"
  782. // br.ErrMsg = "查询映射关系失败, 保存失败, Err:" + err.Error()
  783. // return
  784. //}
  785. //if !pptMap.IsMoved && len(pptMapList) > 1 && count > 0 {
  786. // // 如果没有人为移动位置, 且当前用户有权限, 默认将当前ppt置顶
  787. // err = ppt.MoveGroupPpt(pptMap.GroupId, pptMap.GroupPptId, pptMapList[0].GroupPptId, 0, this.SysUser.AdminId)
  788. // if err != nil {
  789. // br.Msg = err.Error()
  790. // br.ErrMsg = "移动失败,Err:" + err.Error()
  791. // return
  792. // }
  793. //}
  794. //日志记录
  795. logInfo := &models.PptV2SaveLog{
  796. PptId: int(req.PptId),
  797. TemplateType: req.FirstPage.TemplateType,
  798. BackgroundImg: req.FirstPage.ImgUrl,
  799. CurrentBackgroundImg: req.FirstPage.CurrentBackgroundImg,
  800. BackCoverImg: req.FirstPage.BackCoverImg,
  801. Title: req.FirstPage.Title,
  802. ReportType: req.FirstPage.ReportType,
  803. PptDate: req.FirstPage.PptDate,
  804. Content: req.Content,
  805. CoverContent: req.CoverContent,
  806. AdminId: this.SysUser.AdminId,
  807. AdminRealName: this.SysUser.RealName,
  808. CreateTime: time.Now(),
  809. TitleSetting: req.TitleSetting,
  810. }
  811. _, e = models.AddPptV2SaveLog(logInfo)
  812. if e != nil {
  813. br.Msg = "保存失败"
  814. br.ErrMsg = "保存PPT日志失败, Err: " + e.Error()
  815. return
  816. }
  817. br.Ret = 200
  818. br.Success = true
  819. br.Msg = "保存成功"
  820. }
  821. // GetConfig
  822. // @Title 获取ppt配置
  823. // @Description 获取ppt列表接口
  824. // @Param PageSize query int true "每页数据条数"
  825. // @Param CurrentIndex query int true "当前页页码,从1开始"
  826. // @Param KeyWord query string true "搜索关键词"
  827. // @Success 200 {object} models.PptV2ListResp
  828. // @router /config [get]
  829. func (this *PptV2Controller) GetConfig() {
  830. br := new(models.BaseResponse).Init()
  831. defer func() {
  832. this.Data["json"] = br
  833. this.ServeJSON()
  834. }()
  835. crmConfig, err := company.GetConfigDetailByCode("ppt_limit")
  836. if err != nil {
  837. br.Msg = "获取配置失败"
  838. br.ErrMsg = "获取配置失败"
  839. br.IsSendEmail = false
  840. return
  841. }
  842. resp := new(models.PptV2ConfigResp)
  843. err = json.Unmarshal([]byte(crmConfig.ConfigValue), resp)
  844. if err != nil {
  845. br.Msg = "获取配置失败"
  846. br.ErrMsg = "获取配置失败;err:" + err.Error()
  847. br.IsSendEmail = false
  848. return
  849. }
  850. br.Ret = 200
  851. br.Success = true
  852. br.Msg = "获取成功"
  853. br.Data = resp
  854. }
  855. // ToReport
  856. // @Title PPT转报告
  857. // @Description PPT转报告
  858. // @Param request body models.PPT2ReportReq true "type json string"
  859. // @Success 200 Ret=200 转换成功
  860. // @router /to_report [post]
  861. func (this *PptV2Controller) ToReport() {
  862. br := new(models.BaseResponse).Init()
  863. defer func() {
  864. this.Data["json"] = br
  865. this.ServeJSON()
  866. }()
  867. sysUser := this.SysUser
  868. if sysUser == nil {
  869. br.Msg = "请登录"
  870. br.ErrMsg = "请登录,SysUser Is Empty"
  871. br.Ret = 408
  872. return
  873. }
  874. var req models.PPT2ReportReq
  875. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  876. if err != nil {
  877. br.Msg = "参数解析异常!"
  878. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  879. return
  880. }
  881. if req.PptId == 0 {
  882. br.Msg = "参数有误"
  883. return
  884. }
  885. reportId, reportCode, msg, e := services.SavePPTReport(req.PptId, req.ClassifyId, req.Title, sysUser)
  886. if e != nil {
  887. br.Msg = msg
  888. br.ErrMsg = "PPT转报告失败, Err: " + e.Error()
  889. return
  890. }
  891. resp := &models.PPT2ReportResp{
  892. ReportId: reportId,
  893. ReportCode: reportCode,
  894. }
  895. br.Ret = 200
  896. br.Success = true
  897. br.Msg = "转换成功"
  898. br.IsAddLog = true
  899. br.Data = resp
  900. }
  901. // Grant
  902. // @Title 分配ppt权限
  903. // @Description 分配ppt权限接口
  904. // @Param request body models.GrantPptReq true "type json string"
  905. // @Success 200 Ret=200 分配成功
  906. // @router /grant [post]
  907. func (this *PptV2Controller) Grant() {
  908. br := new(models.BaseResponse).Init()
  909. defer func() {
  910. this.Data["json"] = br
  911. this.ServeJSON()
  912. }()
  913. var req models.GrantPptReq
  914. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  915. if err != nil {
  916. br.Msg = "参数解析异常!"
  917. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  918. return
  919. }
  920. if req.PptId <= 0 {
  921. br.Msg = "参数错误"
  922. return
  923. }
  924. // 查找ppt信息
  925. pptInfo, err := models.GetPptV2ById(req.PptId)
  926. if err != nil {
  927. br.Msg = "ppt不存在"
  928. return
  929. }
  930. if pptInfo.AdminId != this.SysUser.AdminId {
  931. br.Msg = "无权配置"
  932. return
  933. }
  934. // 分配
  935. err, errMsg := ppt.GrantPpt(req.PptId, req.GrantType, req.AdminIdStr, this.SysUser.AdminId)
  936. if errMsg != `` {
  937. br.Msg = errMsg
  938. br.ErrMsg = errMsg
  939. if err != nil {
  940. br.ErrMsg = errMsg + ";Err:" + err.Error()
  941. } else {
  942. br.IsSendEmail = false
  943. }
  944. return
  945. }
  946. br.Ret = 200
  947. br.Success = true
  948. br.IsAddLog = true
  949. br.Msg = "分配成功"
  950. }
  951. // CancelGrant
  952. // @Title 取消分配ppt权限
  953. // @Description 取消分配ppt权限
  954. // @Param request body models.DeletePptV2Req true "type json string"
  955. // @Success 200 Ret=200 分配成功
  956. // @router /grant/cancel [post]
  957. func (this *PptV2Controller) CancelGrant() {
  958. br := new(models.BaseResponse).Init()
  959. defer func() {
  960. this.Data["json"] = br
  961. this.ServeJSON()
  962. }()
  963. var req models.DeletePptV2Req
  964. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  965. if err != nil {
  966. br.Msg = "参数解析异常!"
  967. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  968. return
  969. }
  970. if req.PptId <= 0 {
  971. br.Msg = "参数错误"
  972. return
  973. }
  974. // 查找ppt信息
  975. pptInfo, err := models.GetPptV2ById(req.PptId)
  976. if err != nil {
  977. br.Msg = "ppt不存在"
  978. return
  979. }
  980. if pptInfo.AdminId != this.SysUser.AdminId {
  981. br.Msg = "无权取消配置"
  982. return
  983. }
  984. // 分配
  985. err, errMsg := ppt.DeleteGrantPpt(req.PptId)
  986. if errMsg != `` {
  987. br.Msg = errMsg
  988. br.ErrMsg = errMsg
  989. if err != nil {
  990. br.ErrMsg = errMsg + ";Err:" + err.Error()
  991. } else {
  992. br.IsSendEmail = false
  993. }
  994. return
  995. }
  996. br.Ret = 200
  997. br.Success = true
  998. br.IsAddLog = true
  999. br.Msg = "取消成功"
  1000. }
  1001. // GrantInfo
  1002. // @Title 获取分配ppt权限详情
  1003. // @Description 获取分配ppt权限详情接口
  1004. // @Param PptId query int true "ppt的id"
  1005. // @Success 200 {object} models.GrantInfoResp
  1006. // @router /grant/info [get]
  1007. func (this *PptV2Controller) GrantInfo() {
  1008. br := new(models.BaseResponse).Init()
  1009. defer func() {
  1010. this.Data["json"] = br
  1011. this.ServeJSON()
  1012. }()
  1013. pptId, _ := this.GetInt("PptId")
  1014. if pptId <= 0 {
  1015. br.Msg = "参数错误"
  1016. return
  1017. }
  1018. // 查找ppt信息
  1019. pptInfo, err := models.GetPptV2ById(pptId)
  1020. if err != nil {
  1021. br.Msg = "ppt不存在"
  1022. return
  1023. }
  1024. if pptInfo.AdminId != this.SysUser.AdminId {
  1025. br.Msg = "无权配置"
  1026. return
  1027. }
  1028. pptGrantInfoList, err := models.GetPPtGrantInfo(pptId)
  1029. if err != nil {
  1030. br.Msg = "信息获取失败"
  1031. br.ErrMsg = "信息获取失败,Err:" + err.Error()
  1032. return
  1033. }
  1034. if len(pptGrantInfoList) <= 0 {
  1035. br.Msg = "未配置"
  1036. br.IsSendEmail = false
  1037. return
  1038. }
  1039. grantType := 0
  1040. var adminIdStr string
  1041. if pptGrantInfoList[0].DepartmentId > 0 { //分配类型;1:全部ficc研究员;2:指定成员
  1042. grantType = 1
  1043. } else {
  1044. grantType = 2
  1045. adminIdsList := make([]string, 0)
  1046. for _, v := range pptGrantInfoList {
  1047. adminIdsList = append(adminIdsList, strconv.Itoa(int(v.GrantAdminId)))
  1048. }
  1049. adminIdStr = strings.Join(adminIdsList, ",")
  1050. }
  1051. br.Ret = 200
  1052. br.Success = true
  1053. br.Data = models.GrantInfoResp{
  1054. PptId: pptId,
  1055. GrantType: grantType,
  1056. AdminIdStr: adminIdStr,
  1057. }
  1058. br.Msg = "分配成功"
  1059. }
  1060. // TitleCheck
  1061. // @Title 校验标题是否重复
  1062. // @Description 校验标题是否重复接口
  1063. // @Param Title query int true "标题"
  1064. // @Success 200 Ret=200 编辑成功
  1065. // @router /titleCheck [get]
  1066. func (this *PptV2Controller) TitleCheck() {
  1067. br := new(models.BaseResponse).Init()
  1068. defer func() {
  1069. this.Data["json"] = br
  1070. this.ServeJSON()
  1071. }()
  1072. title := this.GetString("Title")
  1073. pptId, _ := this.GetInt("PptId")
  1074. if title == "" {
  1075. br.Msg = "标题不能为空"
  1076. return
  1077. }
  1078. item, err := models.GetPptV2ByTitleAndId(title, this.SysUser.AdminId)
  1079. if err != nil && !utils.IsErrNoRow(err) {
  1080. br.Msg = "获取数据异常!"
  1081. br.ErrMsg = "获取数据异常,Err:" + err.Error()
  1082. return
  1083. }
  1084. if item != nil && item.PptId > 0 && item.PptId != pptId {
  1085. br.Msg = "标题已存在,不可重复添加"
  1086. br.IsSendEmail = false
  1087. return
  1088. }
  1089. br.Ret = 200
  1090. br.Success = true
  1091. br.Msg = "校验成功"
  1092. }
  1093. // Editing
  1094. // @Title 标记/查询编辑状态
  1095. // @Description 标记/查询编辑状态
  1096. // @Param request body models.PPTEditingReq true "type json string"
  1097. // @Success 200 Ret=200 操作成功
  1098. // @router /editing [post]
  1099. func (this *PptV2Controller) Editing() {
  1100. br := new(models.BaseResponse).Init()
  1101. defer func() {
  1102. if br.ErrMsg == "" {
  1103. br.IsSendEmail = false
  1104. }
  1105. this.Data["json"] = br
  1106. this.ServeJSON()
  1107. }()
  1108. sysUser := this.SysUser
  1109. if sysUser == nil {
  1110. br.Msg = "请登录"
  1111. br.ErrMsg = "请登录,SysUser Is Empty"
  1112. br.Ret = 408
  1113. return
  1114. }
  1115. var req models.PPTEditingReq
  1116. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1117. if err != nil {
  1118. br.Msg = "参数解析异常!"
  1119. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1120. return
  1121. }
  1122. if req.PptId <= 0 {
  1123. br.Msg = "参数有误"
  1124. return
  1125. }
  1126. if req.Status < 0 {
  1127. br.Msg = "标记状态异常"
  1128. return
  1129. }
  1130. editor, e := services.UpdatePptEditing(req.PptId, req.Status, sysUser.AdminId, sysUser.RealName, false)
  1131. if e != nil {
  1132. br.Msg = "操作失败"
  1133. br.ErrMsg = "更新编辑状态失败, err: " + e.Error()
  1134. return
  1135. }
  1136. br.Data = editor
  1137. br.Ret = 200
  1138. br.Success = true
  1139. br.Msg = "操作成功"
  1140. }