ppt_v2.go 31 KB

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