ppt_english.go 31 KB

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