ppt_english.go 30 KB

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