ppt_v2.go 34 KB

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