ppt_english.go 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/models"
  5. "eta/eta_api/models/company"
  6. "eta/eta_api/models/data_manage/excel"
  7. "eta/eta_api/models/ppt_english"
  8. "eta/eta_api/services"
  9. "eta/eta_api/services/ppt"
  10. "eta/eta_api/utils"
  11. _ "image/gif"
  12. _ "image/jpeg"
  13. _ "image/png"
  14. "os"
  15. "path"
  16. "strconv"
  17. "strings"
  18. "time"
  19. "github.com/rdlucklib/rdluck_tools/paging"
  20. )
  21. // PptEnglishController 新版ppt模块
  22. type PptEnglishController struct {
  23. BaseAuthController
  24. }
  25. // PptEnglishCommonController 新版ppt公共模块
  26. type PptEnglishCommonController 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} ppt_english.PptEnglishListResp
  36. // @router /list [get]
  37. func (this *PptEnglishController) 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 := ppt_english.GetPptEnglishListCount(condition, pars)
  67. if err != nil {
  68. br.Msg = "获取失败"
  69. br.ErrMsg = "获取失败,Err:" + err.Error()
  70. return
  71. }
  72. list, err := ppt_english.GetPptEnglishList(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(ppt_english.PptEnglishListResp)
  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 ppt_english.AddPptEnglishReq true "type json string"
  100. // @Success 200 Ret=200 新增成功
  101. // @router /add [post]
  102. func (this *PptEnglishController) AddPpt() {
  103. br := new(models.BaseResponse).Init()
  104. defer func() {
  105. this.Data["json"] = br
  106. this.ServeJSON()
  107. }()
  108. var req ppt_english.AddPptEnglishReq
  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 := ppt_english.GetPptEnglishByTitleAndId(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 {
  133. br.Msg = "标题已存在,不可重复添加"
  134. br.IsSendEmail = false
  135. return
  136. }
  137. pptInfo := &ppt_english.PptEnglish{
  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. CoverContent: req.CoverContent,
  146. CreateTime: time.Now(),
  147. ModifyTime: time.Now(),
  148. AdminId: this.SysUser.AdminId,
  149. AdminRealName: this.SysUser.RealName,
  150. TitleSetting: req.TitleSetting,
  151. }
  152. newId, err = ppt_english.AddPptEnglish(pptInfo)
  153. if err != nil {
  154. br.Msg = "新增失败"
  155. br.ErrMsg = "新增失败,Err:" + err.Error()
  156. return
  157. }
  158. //新增ppt和目录映射
  159. _, err = ppt.AddGroupPptEnglishMapping(newId, req.GroupId, this.SysUser.AdminId, this.SysUser.RealName)
  160. if err != nil {
  161. br.Msg = err.Error()
  162. return
  163. }
  164. msg = "新增成功"
  165. excelReferences := make([]*excel.ReferencedExcelConfig, 0)
  166. for _, r := range req.ExcelReferences {
  167. refItem := excel.ReferencedExcelConfig{
  168. UniqueCode: r.UniqueCode,
  169. ReferencedId: int(newId),
  170. FromScene: utils.TableReferencedByEnPPT,
  171. Uuid: r.Uuid,
  172. WidthList: r.WidthList,
  173. HeightList: r.HeightList,
  174. OpUserId: this.SysUser.AdminId,
  175. OpUserName: this.SysUser.RealName,
  176. CreateTime: time.Now(),
  177. ModifyTime: time.Now(),
  178. }
  179. excelReferences = append(excelReferences, &refItem)
  180. }
  181. if len(excelReferences) > 0 {
  182. err = excel.AddReferencedExcelConfig(excelReferences)
  183. if err != nil {
  184. br.Msg = "新增引用失败"
  185. br.ErrMsg = "新增引用失败,Err:" + err.Error()
  186. return
  187. }
  188. }
  189. // 合并ppt后,将ppt的表格关系做处理
  190. if len(req.MergePptIdList) > 0 {
  191. services.HandlerMergePptTableReferenced(req.MergePptIdList, int(newId), this.SysUser.AdminId, this.SysUser.RealName, utils.TableReferencedByEnPPT)
  192. }
  193. } else {
  194. newId = req.PptId
  195. pptInfo, err := ppt_english.GetPptEnglishById(int(req.PptId))
  196. if err != nil {
  197. br.Msg = "信息获取失败"
  198. br.ErrMsg = "信息获取失败,Err:" + err.Error()
  199. return
  200. }
  201. pptInfo.TemplateType = req.FirstPage.TemplateType
  202. pptInfo.BackgroundImg = req.FirstPage.ImgUrl
  203. pptInfo.Title = req.FirstPage.Title
  204. pptInfo.ReportType = req.FirstPage.ReportType
  205. pptInfo.PptDate = req.FirstPage.PptDate
  206. pptInfo.Content = req.Content
  207. pptInfo.CoverContent = req.CoverContent
  208. pptInfo.ModifyTime = time.Now()
  209. pptInfo.TitleSetting = req.TitleSetting
  210. err = pptInfo.Update([]string{"TemplateType", "BackgroundImg", "Title", "ReportType", "PptDate", "Content", "ModifyTime", "CoverContent", "TitleSetting"})
  211. msg = "保存成功"
  212. }
  213. resp := ppt_english.AddPptEnglishResp{
  214. PptId: newId,
  215. }
  216. br.Ret = 200
  217. br.Success = true
  218. br.Msg = msg
  219. br.Data = resp
  220. }
  221. // EditPpt
  222. // @Title 编辑ppt
  223. // @Description 编辑ppt接口
  224. // @Param request body ppt_english.AddPptEnglishReq true "type json string"
  225. // @Success 200 Ret=200 编辑成功
  226. // @router /edit [post]
  227. func (this *PptEnglishController) EditPpt() {
  228. br := new(models.BaseResponse).Init()
  229. defer func() {
  230. this.Data["json"] = br
  231. this.ServeJSON()
  232. }()
  233. var req ppt_english.AddPptEnglishReq
  234. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  235. if err != nil {
  236. br.Msg = "参数解析异常!"
  237. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  238. return
  239. }
  240. if req.FirstPage.Title == "" {
  241. br.Msg = "标题不能为空"
  242. return
  243. }
  244. item, err := ppt_english.GetPptEnglishByTitleAndId(req.FirstPage.Title, this.SysUser.AdminId)
  245. if err != nil && err.Error() != utils.ErrNoRow() {
  246. br.Msg = "获取数据异常!"
  247. br.ErrMsg = "获取数据异常,Err:" + err.Error()
  248. return
  249. }
  250. if item != nil && item.PptId != int(req.PptId) {
  251. br.Msg = "标题已存在,不可重复添加"
  252. br.IsSendEmail = false
  253. return
  254. }
  255. pptInfo, err := ppt_english.GetPptEnglishById(int(req.PptId))
  256. if err != nil {
  257. br.Msg = "信息获取失败"
  258. br.ErrMsg = "信息获取失败,Err:" + err.Error()
  259. return
  260. }
  261. // 判断权限
  262. if pptInfo.AdminId != this.SysUser.AdminId {
  263. _, err := ppt_english.GetPPtGrantConf(pptInfo.PptId, this.SysUser.AdminId)
  264. if err != nil {
  265. if err.Error() == utils.ErrNoRow() {
  266. br.Msg = `该PPT已取消共享,保存失败`
  267. br.ErrMsg = `该PPT已取消共享,保存失败`
  268. br.IsSendEmail = false
  269. } else {
  270. br.Msg = `保存失败`
  271. br.ErrMsg = `保存失败,ERR:` + err.Error()
  272. }
  273. return
  274. }
  275. }
  276. // 修改
  277. pptInfo.TemplateType = req.FirstPage.TemplateType
  278. pptInfo.BackgroundImg = req.FirstPage.ImgUrl
  279. pptInfo.Title = req.FirstPage.Title
  280. pptInfo.ReportType = req.FirstPage.ReportType
  281. pptInfo.PptDate = req.FirstPage.PptDate
  282. pptInfo.Content = req.Content
  283. pptInfo.CoverContent = req.CoverContent
  284. pptInfo.ModifyTime = time.Now()
  285. pptInfo.TitleSetting = req.TitleSetting
  286. err = pptInfo.Update([]string{"TemplateType", "BackgroundImg", "Title", "ReportType", "PptDate", "Content", "ModifyTime", "CoverContent", "TitleSetting"})
  287. if err != nil {
  288. br.Msg = "编辑失败"
  289. br.ErrMsg = "编辑失败,Err:" + err.Error()
  290. return
  291. }
  292. pptMap, err := ppt_english.GetPptMappingByPptId(req.PptId)
  293. if err != nil {
  294. br.Msg = `该PPT信息不存在, 保存失败`
  295. br.ErrMsg = `该PPT信息不存在, 保存失败, Err` + err.Error()
  296. br.IsSendEmail = false
  297. return
  298. }
  299. pptMapList, err := ppt_english.GetPptMappingListByGroupIdDesc(pptMap.GroupId)
  300. if err != nil {
  301. br.ErrMsg = "PPT目录信息异常"
  302. return
  303. }
  304. count, err := ppt_english.GetPptMappingCountByGroupPptId(pptMap.GroupPptId, this.SysUser.AdminId)
  305. if err != nil {
  306. br.Msg = "获取英文PPT和用户权限关系失败"
  307. br.ErrMsg = "获取英文PPT和用户权限关系失败, Err:" + err.Error()
  308. return
  309. }
  310. if !pptMap.IsMoved && len(pptMapList) > 1 && count > 0 {
  311. // 如果没有人为移动位置, 默认将当前ppt置顶
  312. err = ppt.MoveGroupPptEnglish(pptMap.GroupId, pptMap.GroupPptId, pptMapList[0].GroupPptId, 0, this.SysUser.AdminId)
  313. if err != nil {
  314. br.Msg = err.Error()
  315. br.ErrMsg = "移动失败,Err:" + err.Error()
  316. return
  317. }
  318. }
  319. // 日志记录
  320. {
  321. logInfo := &ppt_english.PptEnglishSaveLog{
  322. PptId: pptInfo.PptId,
  323. TemplateType: pptInfo.TemplateType,
  324. BackgroundImg: pptInfo.BackgroundImg,
  325. Title: pptInfo.Title,
  326. ReportType: pptInfo.ReportType,
  327. PptDate: pptInfo.PptDate,
  328. Content: pptInfo.Content,
  329. CoverContent: pptInfo.CoverContent,
  330. AdminId: this.SysUser.AdminId,
  331. AdminRealName: this.SysUser.RealName,
  332. CreateTime: time.Now(),
  333. TitleSetting: req.TitleSetting,
  334. }
  335. _, err = ppt_english.AddPptEnglishSaveLog(logInfo)
  336. }
  337. resp := ppt_english.AddPptEnglishResp{
  338. PptId: req.PptId,
  339. }
  340. br.Ret = 200
  341. br.Success = true
  342. br.Msg = "编辑成功"
  343. br.IsAddLog = true
  344. br.Data = resp
  345. }
  346. // DeletePpt
  347. // @Title 删除ppt
  348. // @Description 删除ppt接口
  349. // @Param request body ppt_english.DeletePptEnglishReq true "type json string"
  350. // @Success 200 Ret=200 删除成功
  351. // @router /delete [post]
  352. func (this *PptEnglishController) DeletePpt() {
  353. br := new(models.BaseResponse).Init()
  354. defer func() {
  355. this.Data["json"] = br
  356. this.ServeJSON()
  357. }()
  358. var req ppt_english.DeletePptEnglishReq
  359. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  360. if err != nil {
  361. br.Msg = "参数解析异常!"
  362. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  363. return
  364. }
  365. if req.PptId <= 0 {
  366. br.Msg = "参数错误"
  367. return
  368. }
  369. pptInfo, err := ppt_english.GetPptEnglishById(req.PptId)
  370. if err != nil {
  371. br.Msg = "ppt不存在"
  372. return
  373. }
  374. if pptInfo.AdminId != this.SysUser.AdminId {
  375. br.Msg = "无权删除"
  376. return
  377. }
  378. err = ppt_english.DeletePptEnglish(req.PptId)
  379. if err != nil {
  380. br.Msg = "删除失败"
  381. br.ErrMsg = "删除失败,Err:" + err.Error()
  382. return
  383. }
  384. //如果该ppt存在单个共享记录,则删除共享
  385. err = ppt.DeleteGroupPptEnglish(req.PptId)
  386. if err != nil {
  387. br.Msg = "删除失败"
  388. br.ErrMsg = "删除失败,Err:" + err.Error()
  389. return
  390. }
  391. br.Ret = 200
  392. br.Success = true
  393. br.IsAddLog = true
  394. br.Msg = "删除成功"
  395. }
  396. // DetailPpt
  397. // @Title 获取ppt详情
  398. // @Description 获取ppt详情接口
  399. // @Param PptId query int true "PptId"
  400. // @Success 200 {object} ppt_english.PptEnglish
  401. // @router /detail [get]
  402. func (this *PptEnglishController) DetailPpt() {
  403. br := new(models.BaseResponse).Init()
  404. defer func() {
  405. if br.ErrMsg == "" {
  406. br.IsSendEmail = false
  407. }
  408. this.Data["json"] = br
  409. this.ServeJSON()
  410. }()
  411. sysUser := this.SysUser
  412. if sysUser == nil {
  413. br.Msg = "请登录"
  414. br.ErrMsg = "请登录,SysUser Is Empty"
  415. br.Ret = 408
  416. return
  417. }
  418. pptId, _ := this.GetInt("PptId")
  419. pptInfo, err := ppt_english.GetPptEnglishById(pptId)
  420. if err != nil {
  421. br.Msg = "信息获取失败"
  422. br.ErrMsg = "信息获取失败,Err:" + err.Error()
  423. return
  424. }
  425. // 查询编辑中
  426. editor, e := services.UpdatePptEditing(pptId, 0, sysUser.AdminId, sysUser.RealName, true)
  427. if e != nil {
  428. br.Msg = "操作失败"
  429. br.ErrMsg = "更新编辑状态失败, err: " + e.Error()
  430. return
  431. }
  432. resp := new(ppt_english.EnglishPPTDetailResp)
  433. resp.PptEnglish = pptInfo
  434. resp.Editor = editor
  435. br.Ret = 200
  436. br.Success = true
  437. br.Msg = "获取成功"
  438. br.Data = resp
  439. }
  440. // DownloadPptx
  441. // @Title ppt下载
  442. // @Description ppt下载
  443. // @Param PptId query int true "PptId"
  444. // @Success 200 下载成功
  445. // @router /downloadpptx [get]
  446. func (this *PptEnglishCommonController) DownloadPptx() {
  447. br := new(models.BaseResponse).Init()
  448. defer func() {
  449. this.Data["json"] = br
  450. this.ServeJSON()
  451. }()
  452. pptId, err := this.GetInt("PptId")
  453. if err != nil {
  454. br.Msg = "参数错误"
  455. br.ErrMsg = "获取,pptId,Err:" + err.Error()
  456. return
  457. }
  458. pptInfo, err := ppt_english.GetPptEnglishById(pptId)
  459. if err != nil {
  460. br.Msg = "获取信息失败"
  461. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  462. return
  463. }
  464. filePath := pptInfo.PptxUrl
  465. fileName := pptInfo.Title + ".pptx"
  466. this.Ctx.Output.Download(filePath, fileName)
  467. br.Success = true
  468. br.Ret = 200
  469. br.Msg = "下载成功"
  470. return
  471. }
  472. // Publish
  473. // @Title 发布接口
  474. // @Description 发布接口
  475. // @Param request body ppt_english.SavePptEnglishPathReq true "type json string"
  476. // @Success Ret=200 发布成功
  477. // @router /publish [post]
  478. func (this *PptEnglishController) Publish() {
  479. br := new(models.BaseResponse).Init()
  480. defer func() {
  481. this.Data["json"] = br
  482. this.ServeJSON()
  483. }()
  484. //SavePptEnglishPathReq
  485. //PptEnglishPublishReq
  486. var req ppt_english.SavePptEnglishPathReq
  487. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  488. if err != nil {
  489. br.Msg = "参数解析异常!"
  490. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  491. return
  492. }
  493. pptId := req.PptId
  494. if pptId <= 0 {
  495. br.Msg = "参数错误"
  496. return
  497. }
  498. err = ppt_english.EditPptEnglishPath(pptId, req.PptxUrl)
  499. if err != nil {
  500. br.Msg = "发布失败"
  501. br.ErrMsg = "发布失败,Err:" + err.Error()
  502. return
  503. }
  504. //添加发布记录
  505. {
  506. record := new(ppt_english.PptEnglishPublishRecord)
  507. record.CreateTime = time.Now()
  508. record.PptId = pptId
  509. record.PptUrl = req.PptxUrl
  510. go ppt_english.AddPptEnglishPublishRecord(record)
  511. }
  512. br.Ret = 200
  513. br.Success = true
  514. br.Msg = "发布成功"
  515. br.IsAddLog = true
  516. return
  517. }
  518. // PptUpload
  519. // @Title ppt上传
  520. // @Description ppt上传
  521. // @Param PptId query int true "PptId"
  522. // @Success 200 新增成功
  523. // @router /pptUpload [post]
  524. func (this *PptEnglishController) PptUpload() {
  525. br := new(models.BaseResponse).Init()
  526. defer func() {
  527. this.Data["json"] = br
  528. this.ServeJSON()
  529. }()
  530. pptId, _ := this.GetInt("PptId", 0)
  531. if pptId <= 0 {
  532. br.Msg = "参数错误"
  533. return
  534. }
  535. _, err := ppt_english.GetPptEnglishById(pptId)
  536. if err != nil {
  537. br.Msg = "获取数据失败"
  538. br.ErrMsg = "获取PPT详情失败,Err:" + err.Error()
  539. return
  540. }
  541. f, h, err := this.GetFile("file")
  542. if err != nil {
  543. br.Msg = "获取资源信息失败"
  544. br.ErrMsg = "获取资源信息失败,Err:" + err.Error()
  545. return
  546. }
  547. uploadFileName := h.Filename //上传的文件名
  548. ext := path.Ext(h.Filename)
  549. dateDir := time.Now().Format("20060102")
  550. uploadDir := utils.STATIC_DIR + "hongze/" + dateDir
  551. err = os.MkdirAll(uploadDir, utils.DIR_MOD)
  552. if err != nil {
  553. br.Msg = "存储目录创建失败"
  554. br.ErrMsg = "存储目录创建失败,Err:" + err.Error()
  555. return
  556. }
  557. randStr := utils.GetRandStringNoSpecialChar(28)
  558. fileName := randStr + ext
  559. fpath := uploadDir + "/" + fileName
  560. defer f.Close() //关闭上传文件
  561. err = this.SaveToFile("file", fpath)
  562. if err != nil {
  563. br.Msg = "文件上传失败"
  564. br.ErrMsg = "文件上传失败,Err:" + err.Error()
  565. return
  566. }
  567. hzUploadDir := "ppt/"
  568. savePptxToOssPath := hzUploadDir + time.Now().Format("200601/20060102/")
  569. //pptName := strings.Replace(pptItem.Title, "\n", "", -1)
  570. //pptName = strings.TrimSuffix(pptName, " ")
  571. pptName := utils.GetRandStringNoSpecialChar(28)
  572. savePptxToOssPath += pptName + ".pptx"
  573. defer func() {
  574. _ = os.Remove(fpath)
  575. }()
  576. //上传到阿里云 和 minio
  577. pptxUrl := ``
  578. //if utils.ObjectStorageClient == "minio" {
  579. // err = services.UploadFileToMinIo("", fpath, savePptxToOssPath)
  580. // if err != nil {
  581. // br.Msg = "文件上传失败"
  582. // br.ErrMsg = "文件上传失败,Err:" + err.Error()
  583. // return
  584. // }
  585. // pptxUrl = utils.MinIoImghost + savePptxToOssPath
  586. //} else {
  587. // err = services.UploadFileToAliyun("", fpath, savePptxToOssPath)
  588. // if err != nil {
  589. // br.Msg = "文件上传失败"
  590. // br.ErrMsg = "文件上传失败,Err:" + err.Error()
  591. // return
  592. // }
  593. // pptxUrl = utils.Imghost + savePptxToOssPath
  594. //}
  595. ossClient := services.NewOssClient()
  596. if ossClient == nil {
  597. br.Msg = "上传失败"
  598. br.ErrMsg = "初始化OSS服务失败"
  599. return
  600. }
  601. pptxUrl, err = ossClient.UploadFile("", fpath, savePptxToOssPath)
  602. if err != nil {
  603. br.Msg = "文件上传失败"
  604. br.ErrMsg = "文件上传失败,Err:" + err.Error()
  605. return
  606. }
  607. item := &models.Resource{
  608. //Id: 0,
  609. ResourceUrl: pptxUrl,
  610. CreateTime: time.Now(),
  611. ResourceType: 4,
  612. }
  613. newId, err := models.AddResource(item)
  614. if err != nil {
  615. br.Msg = "资源上传失败"
  616. br.ErrMsg = "资源上传失败,Err:" + err.Error()
  617. return
  618. }
  619. resp := models.ResourceResp{
  620. Id: newId,
  621. ResourceUrl: pptxUrl,
  622. ResourceName: uploadFileName,
  623. }
  624. br.Msg = "上传成功"
  625. br.Ret = 200
  626. br.Success = true
  627. br.Data = resp
  628. return
  629. }
  630. // SaveLog
  631. // @Title 定时ppt操作日志记录
  632. // @Description 定时ppt操作日志记录
  633. // @Param request body ppt_english.AddPptEnglishReq true "type json string"
  634. // @Success 200 新增成功
  635. // @router /saveLog [post]
  636. func (this *PptEnglishController) SaveLog() {
  637. br := new(models.BaseResponse).Init()
  638. defer func() {
  639. if br.ErrMsg == "" {
  640. br.IsSendEmail = false
  641. }
  642. this.Data["json"] = br
  643. this.ServeJSON()
  644. }()
  645. sysUser := this.SysUser
  646. if sysUser == nil {
  647. br.Msg = "请登录"
  648. br.ErrMsg = "请登录,SysUser Is Empty"
  649. br.Ret = 408
  650. return
  651. }
  652. var req ppt_english.AddPptEnglishReq
  653. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  654. if err != nil {
  655. br.Msg = "参数解析异常!"
  656. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  657. return
  658. }
  659. if req.FirstPage.Title == "" {
  660. br.Msg = "标题不能为空"
  661. return
  662. }
  663. var pageContent []services.PPTContent
  664. err = json.Unmarshal([]byte(req.Content), &pageContent)
  665. if err != nil {
  666. br.Msg = "参数解析异常!"
  667. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  668. return
  669. }
  670. // 获取ppt
  671. item, err := ppt_english.GetPptEnglishByTitleAndId(req.FirstPage.Title, this.SysUser.AdminId)
  672. if err != nil && err.Error() != utils.ErrNoRow() {
  673. br.Msg = "获取数据异常!"
  674. br.ErrMsg = "获取数据异常,Err:" + err.Error()
  675. return
  676. }
  677. if item != nil && item.PptId != int(req.PptId) {
  678. br.Msg = "标题已存在,不可重复添加"
  679. br.IsSendEmail = false
  680. return
  681. }
  682. //变更ppt内容
  683. pptItem, e := ppt_english.GetPptEnglishById(int(req.PptId))
  684. if e != nil {
  685. if e.Error() == utils.ErrNoRow() {
  686. br.Msg = "PPT已被删除, 请刷新页面"
  687. return
  688. }
  689. br.Msg = "信息获取失败"
  690. br.ErrMsg = "信息获取失败,Err:" + e.Error()
  691. return
  692. }
  693. // 标记编辑状态
  694. if pptItem.PptId > 0 {
  695. _, e = services.UpdatePptEditing(pptItem.PptId, 1, sysUser.AdminId, sysUser.RealName, true)
  696. if e != nil {
  697. br.Msg = "操作失败"
  698. br.ErrMsg = "更新编辑状态失败, err: " + e.Error()
  699. return
  700. }
  701. }
  702. pptItem.TemplateType = req.FirstPage.TemplateType
  703. pptItem.BackgroundImg = req.FirstPage.ImgUrl
  704. pptItem.Title = req.FirstPage.Title
  705. pptItem.ReportType = req.FirstPage.ReportType
  706. pptItem.PptDate = req.FirstPage.PptDate
  707. pptItem.Content = req.Content
  708. pptItem.ModifyTime = time.Now()
  709. pptItem.PptPage = len(pageContent)
  710. err = pptItem.Update([]string{"TemplateType", "BackgroundImg", "Title", "ReportType", "PptDate", "Content", "ModifyTime", "ppt_page"})
  711. pptMap, err := ppt_english.GetPptMappingByPptId(req.PptId)
  712. if err != nil {
  713. br.Msg = `该PPT信息不存在, 保存失败`
  714. br.ErrMsg = `该PPT信息不存在, 保存失败, Err` + err.Error()
  715. br.IsSendEmail = false
  716. return
  717. }
  718. pptMapList, err := ppt_english.GetPptMappingListByGroupIdDesc(pptMap.GroupId)
  719. if err != nil {
  720. br.ErrMsg = "PPT目录信息异常"
  721. return
  722. }
  723. count, err := ppt_english.GetPptMappingCountByGroupPptId(pptMap.GroupPptId, this.SysUser.AdminId)
  724. if err != nil {
  725. br.Msg = "获取英文PPT和用户权限关系失败"
  726. br.ErrMsg = "获取英文PPT和用户权限关系失败, Err:" + err.Error()
  727. return
  728. }
  729. if !pptMap.IsMoved && len(pptMapList) > 1 && count > 0 {
  730. // 如果没有人为移动位置, 且当前用户有权限, 默认将当前ppt置顶
  731. err = ppt.MoveGroupPptEnglish(pptMap.GroupId, pptMap.GroupPptId, pptMapList[0].GroupPptId, 0, this.SysUser.AdminId)
  732. if err != nil {
  733. br.Msg = err.Error()
  734. br.ErrMsg = "移动失败,Err:" + err.Error()
  735. return
  736. }
  737. }
  738. //日志记录
  739. logInfo := &ppt_english.PptEnglishSaveLog{
  740. PptId: int(req.PptId),
  741. TemplateType: req.FirstPage.TemplateType,
  742. BackgroundImg: req.FirstPage.ImgUrl,
  743. Title: req.FirstPage.Title,
  744. ReportType: req.FirstPage.ReportType,
  745. PptDate: req.FirstPage.PptDate,
  746. Content: req.Content,
  747. CoverContent: req.CoverContent,
  748. AdminId: this.SysUser.AdminId,
  749. AdminRealName: this.SysUser.RealName,
  750. CreateTime: time.Now(),
  751. TitleSetting: req.TitleSetting,
  752. }
  753. _, err = ppt_english.AddPptEnglishSaveLog(logInfo)
  754. if err != nil {
  755. br.Msg = "保存失败"
  756. br.ErrMsg = "保存PPT日志失败, Err: " + err.Error()
  757. return
  758. }
  759. br.Ret = 200
  760. br.Success = true
  761. br.Msg = "保存成功"
  762. }
  763. // GetConfig
  764. // @Title 获取ppt配置
  765. // @Description 获取ppt列表接口
  766. // @Param PageSize query int true "每页数据条数"
  767. // @Param CurrentIndex query int true "当前页页码,从1开始"
  768. // @Param KeyWord query string true "搜索关键词"
  769. // @Success 200 {object} ppt_english.PptEnglishListResp
  770. // @router /config [get]
  771. func (this *PptEnglishController) GetConfig() {
  772. br := new(models.BaseResponse).Init()
  773. defer func() {
  774. this.Data["json"] = br
  775. this.ServeJSON()
  776. }()
  777. crmConfig, err := company.GetConfigDetailByCode("ppt_limit")
  778. if err != nil {
  779. br.Msg = "获取配置失败"
  780. br.ErrMsg = "获取配置失败"
  781. br.IsSendEmail = false
  782. return
  783. }
  784. resp := new(ppt_english.PptEnglishConfigResp)
  785. err = json.Unmarshal([]byte(crmConfig.ConfigValue), resp)
  786. if err != nil {
  787. br.Msg = "获取配置失败"
  788. br.ErrMsg = "获取配置失败;err:" + err.Error()
  789. br.IsSendEmail = false
  790. return
  791. }
  792. br.Ret = 200
  793. br.Success = true
  794. br.Msg = "获取成功"
  795. br.Data = resp
  796. }
  797. // Grant
  798. // @Title 分配ppt权限
  799. // @Description 分配ppt权限接口
  800. // @Param request body ppt_english.GrantPptReq true "type json string"
  801. // @Success 200 Ret=200 分配成功
  802. // @router /grant [post]
  803. func (this *PptEnglishController) Grant() {
  804. br := new(models.BaseResponse).Init()
  805. defer func() {
  806. this.Data["json"] = br
  807. this.ServeJSON()
  808. }()
  809. var req ppt_english.GrantPptReq
  810. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  811. if err != nil {
  812. br.Msg = "参数解析异常!"
  813. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  814. return
  815. }
  816. if req.PptId <= 0 {
  817. br.Msg = "参数错误"
  818. return
  819. }
  820. // 查找ppt信息
  821. pptInfo, err := ppt_english.GetPptEnglishById(req.PptId)
  822. if err != nil {
  823. br.Msg = "ppt不存在"
  824. return
  825. }
  826. if pptInfo.AdminId != this.SysUser.AdminId {
  827. br.Msg = "无权配置"
  828. return
  829. }
  830. // 分配
  831. err, errMsg := ppt.GrantPptEnglish(req.PptId, req.GrantType, req.AdminIdStr, this.SysUser.AdminId)
  832. if errMsg != `` {
  833. br.Msg = errMsg
  834. br.ErrMsg = errMsg
  835. if err != nil {
  836. br.ErrMsg = errMsg + ";Err:" + err.Error()
  837. } else {
  838. br.IsSendEmail = false
  839. }
  840. return
  841. }
  842. br.Ret = 200
  843. br.Success = true
  844. br.IsAddLog = true
  845. br.Msg = "分配成功"
  846. }
  847. // CancelGrant
  848. // @Title 取消分配ppt权限
  849. // @Description 取消分配ppt权限
  850. // @Param request body ppt_english.DeletePptEnglishReq true "type json string"
  851. // @Success 200 Ret=200 分配成功
  852. // @router /grant/cancel [post]
  853. func (this *PptEnglishController) CancelGrant() {
  854. br := new(models.BaseResponse).Init()
  855. defer func() {
  856. this.Data["json"] = br
  857. this.ServeJSON()
  858. }()
  859. var req ppt_english.DeletePptEnglishReq
  860. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  861. if err != nil {
  862. br.Msg = "参数解析异常!"
  863. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  864. return
  865. }
  866. if req.PptId <= 0 {
  867. br.Msg = "参数错误"
  868. return
  869. }
  870. // 查找ppt信息
  871. pptInfo, err := ppt_english.GetPptEnglishById(req.PptId)
  872. if err != nil {
  873. br.Msg = "ppt不存在"
  874. return
  875. }
  876. if pptInfo.AdminId != this.SysUser.AdminId {
  877. br.Msg = "无权取消配置"
  878. return
  879. }
  880. // 分配
  881. err, errMsg := ppt.DeleteGrantPptEnglish(req.PptId)
  882. if errMsg != `` {
  883. br.Msg = errMsg
  884. br.ErrMsg = errMsg
  885. if err != nil {
  886. br.ErrMsg = errMsg + ";Err:" + err.Error()
  887. } else {
  888. br.IsSendEmail = false
  889. }
  890. return
  891. }
  892. br.Ret = 200
  893. br.Success = true
  894. br.IsAddLog = true
  895. br.Msg = "取消成功"
  896. }
  897. // GrantInfo
  898. // @Title 获取分配ppt权限详情
  899. // @Description 获取分配ppt权限详情接口
  900. // @Param PptId query int true "ppt的id"
  901. // @Success 200 {object} ppt_english.GrantInfoResp
  902. // @router /grant/info [get]
  903. func (this *PptEnglishController) GrantInfo() {
  904. br := new(models.BaseResponse).Init()
  905. defer func() {
  906. this.Data["json"] = br
  907. this.ServeJSON()
  908. }()
  909. pptId, _ := this.GetInt("PptId")
  910. if pptId <= 0 {
  911. br.Msg = "参数错误"
  912. return
  913. }
  914. // 查找ppt信息
  915. pptInfo, err := ppt_english.GetPptEnglishById(pptId)
  916. if err != nil {
  917. br.Msg = "ppt不存在"
  918. return
  919. }
  920. if pptInfo.AdminId != this.SysUser.AdminId {
  921. br.Msg = "无权配置"
  922. return
  923. }
  924. pptGrantInfoList, err := ppt_english.GetPPtGrantInfo(pptId)
  925. if err != nil {
  926. br.Msg = "信息获取失败"
  927. br.ErrMsg = "信息获取失败,Err:" + err.Error()
  928. return
  929. }
  930. if len(pptGrantInfoList) <= 0 {
  931. br.Msg = "未配置"
  932. br.IsSendEmail = false
  933. return
  934. }
  935. grantType := 0
  936. var adminIdStr string
  937. if pptGrantInfoList[0].DepartmentId > 0 { //分配类型;1:全部ficc研究员;2:指定成员
  938. grantType = 1
  939. } else {
  940. grantType = 2
  941. adminIdsList := make([]string, 0)
  942. for _, v := range pptGrantInfoList {
  943. adminIdsList = append(adminIdsList, strconv.Itoa(int(v.GrantAdminId)))
  944. }
  945. adminIdStr = strings.Join(adminIdsList, ",")
  946. }
  947. br.Ret = 200
  948. br.Success = true
  949. br.Data = ppt_english.GrantInfoResp{
  950. PptId: pptId,
  951. GrantType: grantType,
  952. AdminIdStr: adminIdStr,
  953. }
  954. br.Msg = "分配成功"
  955. }
  956. // ToReport
  957. // @Title 英文PPT转报告
  958. // @Description PPT转报告
  959. // @Param request body ppt_english.EnglishPPT2ReportReq true "type json string"
  960. // @Success 200 Ret=200 转换成功
  961. // @router /toReport [post]
  962. func (this *PptEnglishController) ToReport() {
  963. br := new(models.BaseResponse).Init()
  964. defer func() {
  965. this.Data["json"] = br
  966. this.ServeJSON()
  967. }()
  968. sysUser := this.SysUser
  969. if sysUser == nil {
  970. br.Msg = "请登录"
  971. br.ErrMsg = "请登录,SysUser Is Empty"
  972. br.Ret = 408
  973. return
  974. }
  975. var req ppt_english.EnglishPPT2ReportReq
  976. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  977. if err != nil {
  978. br.Msg = "参数解析异常!"
  979. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  980. return
  981. }
  982. if req.PptId == 0 {
  983. br.Msg = "参数有误"
  984. return
  985. }
  986. reportId, reportCode, msg, e := services.SaveEnglishPPTReport(req.PptId, req.ClassifyIdFirst, req.ClassifyIdSecond, req.Title, req.Abstract, sysUser)
  987. if e != nil {
  988. br.Msg = msg
  989. br.ErrMsg = "PPT转报告失败, Err: " + e.Error()
  990. return
  991. }
  992. resp := &models.PPT2ReportResp{
  993. ReportId: reportId,
  994. ReportCode: reportCode,
  995. }
  996. br.Ret = 200
  997. br.Success = true
  998. br.Msg = "转换成功"
  999. br.IsAddLog = true
  1000. br.Data = resp
  1001. }
  1002. // TitleCheck
  1003. // @Title 校验标题是否重复
  1004. // @Description 校验标题是否重复接口
  1005. // @Param Title query int true "标题"
  1006. // @Success 200 Ret=200 编辑成功
  1007. // @router /titleCheck [get]
  1008. func (this *PptEnglishController) TitleCheck() {
  1009. br := new(models.BaseResponse).Init()
  1010. defer func() {
  1011. this.Data["json"] = br
  1012. this.ServeJSON()
  1013. }()
  1014. title := this.GetString("Title")
  1015. pptId, _ := this.GetInt("PptId")
  1016. if title == "" {
  1017. br.Msg = "标题不能为空"
  1018. return
  1019. }
  1020. item, err := ppt_english.GetPptEnglishByTitleAndId(title, this.SysUser.AdminId)
  1021. if err != nil && err.Error() != utils.ErrNoRow() {
  1022. br.Msg = "获取数据异常!"
  1023. br.ErrMsg = "获取数据异常,Err:" + err.Error()
  1024. return
  1025. }
  1026. if item != nil && item.PptId != pptId {
  1027. br.Msg = "标题已存在,不可重复添加"
  1028. br.IsSendEmail = false
  1029. return
  1030. }
  1031. br.Ret = 200
  1032. br.Success = true
  1033. br.Msg = "校验成功"
  1034. }
  1035. // Editing
  1036. // @Title 标记/查询编辑状态
  1037. // @Description 标记/查询编辑状态
  1038. // @Param request body models.PPTEditingReq true "type json string"
  1039. // @Success 200 Ret=200 操作成功
  1040. // @router /editing [post]
  1041. func (this *PptEnglishController) Editing() {
  1042. br := new(models.BaseResponse).Init()
  1043. defer func() {
  1044. if br.ErrMsg == "" {
  1045. br.IsSendEmail = false
  1046. }
  1047. this.Data["json"] = br
  1048. this.ServeJSON()
  1049. }()
  1050. sysUser := this.SysUser
  1051. if sysUser == nil {
  1052. br.Msg = "请登录"
  1053. br.ErrMsg = "请登录,SysUser Is Empty"
  1054. br.Ret = 408
  1055. return
  1056. }
  1057. var req models.PPTEditingReq
  1058. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1059. if err != nil {
  1060. br.Msg = "参数解析异常!"
  1061. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1062. return
  1063. }
  1064. if req.PptId <= 0 {
  1065. br.Msg = "参数有误"
  1066. return
  1067. }
  1068. if req.Status < 0 {
  1069. br.Msg = "标记状态异常"
  1070. return
  1071. }
  1072. editor, e := services.UpdatePptEditing(req.PptId, req.Status, sysUser.AdminId, sysUser.RealName, true)
  1073. if e != nil {
  1074. br.Msg = "操作失败"
  1075. br.ErrMsg = "更新编辑状态失败, err: " + e.Error()
  1076. return
  1077. }
  1078. br.Data = editor
  1079. br.Ret = 200
  1080. br.Success = true
  1081. br.Msg = "操作成功"
  1082. }