ppt_v2.go 31 KB

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