12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367 |
- package controllers
- import (
- "encoding/json"
- "eta/eta_api/models"
- "eta/eta_api/models/company"
- "eta/eta_api/models/data_manage/excel"
- "eta/eta_api/models/ppt_english"
- "eta/eta_api/services"
- "eta/eta_api/services/ppt"
- "eta/eta_api/utils"
- "fmt"
- _ "image/gif"
- _ "image/jpeg"
- _ "image/png"
- "os"
- "path"
- "strconv"
- "strings"
- "time"
- "github.com/rdlucklib/rdluck_tools/paging"
- )
- // PptV2Controller 新版ppt模块
- type PptV2Controller struct {
- BaseAuthController
- }
- // PptV2CommonController 新版ppt公共模块
- type PptV2CommonController struct {
- BaseCommonController
- }
- // ListPpt
- // @Title 获取ppt列表
- // @Description 获取ppt列表接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param KeyWord query string true "搜索关键词"
- // @Success 200 {object} models.PptV2ListResp
- // @router /list [get]
- func (this *PptV2Controller) ListPpt() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- return
- }
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- keyWord := this.GetString("KeyWord")
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = utils.StartIndex(currentIndex, pageSize)
- var condition string
- var pars []interface{}
- if keyWord != "" {
- condition += ` AND (title LIKE ? OR admin_real_name LIKE ? ) `
- pars = utils.GetLikeKeywordPars(pars, keyWord, 2)
- }
- total, err := models.GetPptV2ListCount(condition, pars)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- list, err := models.GetPptV2List(condition, pars, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- lenList := len(list)
- for i := 0; i < lenList; i++ {
- adminId := list[i].AdminId
- if adminId == sysUser.AdminId || sysUser.Role == "admin" {
- list[i].IsAuth = true
- } else {
- list[i].IsAuth = false
- }
- if list[i].PptPage == 0 {
- var pptContent []services.PPTContent
- er := json.Unmarshal([]byte(list[i].Content), &pptContent)
- if er != nil {
- br.Msg = "content参数解析失败"
- br.ErrMsg = "content参数解析失败, Err:" + er.Error()
- return
- }
- list[i].PptPage = len(pptContent)
- }
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp := new(models.PptV2ListResp)
- resp.Paging = page
- resp.List = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // AddPpt
- // @Title 新增ppt
- // @Description 新增ppt接口
- // @Param request body models.AddPptV2Req true "type json string"
- // @Success 200 Ret=200 新增成功
- // @router /add [post]
- func (this *PptV2Controller) AddPpt() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.AddPptV2Req
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.FirstPage.Title == "" {
- br.Msg = "标题不能为空"
- return
- }
- var pptContent []services.PPTContent
- err = json.Unmarshal([]byte(req.Content), &pptContent)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- var newId int64
- var msg string
- if req.PptId <= 0 {
- if req.GroupId == 0 {
- br.Msg = "请输入目录ID"
- return
- }
- item, err := models.GetPptV2ByTitleAndId(req.FirstPage.Title, this.SysUser.AdminId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取数据异常!"
- br.ErrMsg = "获取数据异常,Err:" + err.Error()
- return
- }
- if item != nil && item.PptId != int(req.PptId) {
- br.Msg = "标题已存在,不可重复添加"
- br.IsSendEmail = false
- return
- }
- pptInfo := &models.PptV2{
- //PptId: 0,
- TemplateType: req.FirstPage.TemplateType,
- BackgroundImg: req.FirstPage.ImgUrl,
- Title: req.FirstPage.Title,
- ReportType: req.FirstPage.ReportType,
- PptDate: req.FirstPage.PptDate,
- Content: req.Content,
- CoverContent: req.CoverContent,
- CreateTime: time.Now(),
- ModifyTime: time.Now(),
- AdminId: this.SysUser.AdminId,
- AdminRealName: this.SysUser.RealName,
- PptVersion: 2,
- PptPage: len(pptContent),
- TitleSetting: req.TitleSetting,
- }
- newId, err = models.AddPptV2(pptInfo)
- if err != nil {
- br.Msg = "新增失败"
- br.ErrMsg = "新增失败,Err:" + err.Error()
- return
- }
- //新增ppt和目录映射
- _, err = ppt.AddGroupPptMapping(newId, req.GroupId, this.SysUser.AdminId, this.SysUser.RealName)
- if err != nil {
- br.Msg = err.Error()
- return
- }
- msg = "新增成功"
- excelReferences := make([]*excel.ReferencedExcelConfig, len(req.ExcelReferences))
- for _, r := range req.ExcelReferences {
- refItem := excel.ReferencedExcelConfig{
- UniqueCode: r.UniqueCode,
- ReferencedId: int(newId),
- FromScene: 4,
- Uuid: r.Uuid,
- WidthList: r.WidthList,
- HeightList: r.HeightList,
- OpUserId: this.SysUser.AdminId,
- OpUserName: this.SysUser.RealName,
- CreateTime: time.Now(),
- ModifyTime: time.Now(),
- }
- excelReferences = append(excelReferences, &refItem)
- }
- err = excel.AddReferencedExcelConfig(excelReferences)
- if err != nil {
- br.Msg = "新增引用失败"
- br.ErrMsg = "新增引用失败,Err:" + err.Error()
- return
- }
- } else {
- newId = req.PptId
- pptInfo, err := models.GetPptV2ById(int(req.PptId))
- if err != nil {
- br.Msg = "信息获取失败"
- br.ErrMsg = "信息获取失败,Err:" + err.Error()
- return
- }
- pptInfo.TemplateType = req.FirstPage.TemplateType
- pptInfo.BackgroundImg = req.FirstPage.ImgUrl
- pptInfo.Title = req.FirstPage.Title
- pptInfo.ReportType = req.FirstPage.ReportType
- pptInfo.PptDate = req.FirstPage.PptDate
- pptInfo.Content = req.Content
- pptInfo.CoverContent = req.CoverContent
- pptInfo.ModifyTime = time.Now()
- pptInfo.PptPage = len(pptContent)
- pptInfo.TitleSetting = req.TitleSetting
- err = pptInfo.Update([]string{"TemplateType", "BackgroundImg", "Title", "ReportType", "PptDate", "Content", "ModifyTime", "CoverContent", "ppt_page", "TitleSetting"})
- msg = "保存成功"
- }
- resp := models.AddPptResp{
- PptId: newId,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = msg
- br.Data = resp
- }
- // EditPpt
- // @Title 编辑ppt
- // @Description 编辑ppt接口
- // @Param request body models.AddPptV2Req true "type json string"
- // @Success 200 Ret=200 编辑成功
- // @router /edit [post]
- func (this *PptV2Controller) EditPpt() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.AddPptV2Req
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.FirstPage.Title == "" {
- br.Msg = "标题不能为空"
- return
- }
- var pptContent []services.PPTContent
- err = json.Unmarshal([]byte(req.Content), &pptContent)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- item, err := models.GetPptV2ByTitleAndId(req.FirstPage.Title, this.SysUser.AdminId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取数据异常!"
- br.ErrMsg = "获取数据异常,Err:" + err.Error()
- return
- }
- if item != nil && item.PptId != int(req.PptId) {
- br.Msg = "标题已存在,不可重复添加"
- br.IsSendEmail = false
- return
- }
- pptInfo, err := models.GetPptV2ById(int(req.PptId))
- if err != nil {
- br.Msg = "信息获取失败"
- br.ErrMsg = "信息获取失败,Err:" + err.Error()
- return
- }
- // 判断权限
- if pptInfo.AdminId != this.SysUser.AdminId {
- _, err := models.GetPPtGrantConf(pptInfo.PptId, this.SysUser.AdminId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- br.Msg = `该PPT已取消共享,保存失败`
- br.ErrMsg = `该PPT已取消共享,保存失败`
- br.IsSendEmail = false
- } else {
- br.Msg = `保存失败`
- br.ErrMsg = `保存失败,ERR:` + err.Error()
- }
- return
- }
- }
- // 修改
- pptInfo.TemplateType = req.FirstPage.TemplateType
- pptInfo.BackgroundImg = req.FirstPage.ImgUrl
- pptInfo.Title = req.FirstPage.Title
- pptInfo.ReportType = req.FirstPage.ReportType
- pptInfo.PptDate = req.FirstPage.PptDate
- pptInfo.Content = req.Content
- pptInfo.CoverContent = req.CoverContent
- pptInfo.ModifyTime = time.Now()
- pptInfo.PptPage = len(pptContent)
- pptInfo.TitleSetting = req.TitleSetting
- err = pptInfo.Update([]string{"TemplateType", "BackgroundImg", "Title", "ReportType", "PptDate", "Content", "ModifyTime", "CoverContent", "ppt_page", "TitleSetting"})
- if err != nil {
- br.Msg = "编辑失败"
- br.ErrMsg = "编辑失败,Err:" + err.Error()
- return
- }
- pptMap, err := models.GetPptMappingByPptId(req.PptId)
- if err != nil {
- br.Msg = `该PPT信息不存在, 保存失败`
- br.ErrMsg = `该PPT信息不存在, 保存失败, Err` + err.Error()
- br.IsSendEmail = false
- return
- }
- pptMapList, err := models.GetPptMappingListByGroupId(pptMap.GroupId)
- if err != nil {
- br.ErrMsg = "PPT目录信息异常"
- return
- }
- count, err := models.GetPptMappingByGroupPptCountId(pptMap.GroupPptId, this.SysUser.AdminId)
- if err != nil {
- br.Msg = "查询映射关系失败"
- br.ErrMsg = "查询映射关系失败, 保存失败, Err:" + err.Error()
- return
- }
- if !pptMap.IsMoved && len(pptMapList) > 1 && count > 0 {
- // 如果没有人为移动位置, 默认将当前ppt置顶
- err = ppt.MoveGroupPpt(pptMap.GroupId, pptMap.GroupPptId, pptMapList[0].GroupPptId, 0, this.SysUser.AdminId)
- if err != nil {
- br.Msg = err.Error()
- br.ErrMsg = "移动失败,Err:" + err.Error()
- return
- }
- }
- // 日志记录
- {
- logInfo := &models.PptV2SaveLog{
- PptId: pptInfo.PptId,
- TemplateType: pptInfo.TemplateType,
- BackgroundImg: pptInfo.BackgroundImg,
- Title: pptInfo.Title,
- ReportType: pptInfo.ReportType,
- PptDate: pptInfo.PptDate,
- Content: pptInfo.Content,
- CoverContent: pptInfo.CoverContent,
- AdminId: this.SysUser.AdminId,
- AdminRealName: this.SysUser.RealName,
- CreateTime: time.Now(),
- }
- _, err = models.AddPptV2SaveLog(logInfo)
- }
- resp := models.AddPptResp{
- PptId: req.PptId,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "编辑成功"
- br.IsAddLog = true
- br.Data = resp
- }
- // DeletePpt
- // @Title 删除ppt
- // @Description 删除ppt接口
- // @Param request body models.DeletePptV2Req true "type json string"
- // @Success 200 Ret=200 删除成功
- // @router /delete [post]
- func (this *PptV2Controller) DeletePpt() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.DeletePptV2Req
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.PptId <= 0 {
- br.Msg = "参数错误"
- return
- }
- pptInfo, err := models.GetPptV2ById(req.PptId)
- if err != nil {
- br.Msg = "ppt不存在"
- return
- }
- if pptInfo.AdminId != this.SysUser.AdminId {
- br.Msg = "无权删除"
- return
- }
- err = models.DeletePptV2(req.PptId)
- if err != nil {
- br.Msg = "删除失败"
- br.ErrMsg = "删除失败,Err:" + err.Error()
- return
- }
- //如果该ppt存在单个共享记录,则删除共享
- err = ppt.DeleteGroupPpt(req.PptId)
- if err != nil {
- br.Msg = "删除失败"
- br.ErrMsg = "删除失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.IsAddLog = true
- br.Msg = "删除成功"
- }
- // DetailPpt
- // @Title 获取ppt详情
- // @Description 获取ppt详情接口
- // @Param PptId query int true "PptId"
- // @Success 200 {object} models.PptV2
- // @router /detail [get]
- func (this *PptV2Controller) DetailPpt() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- pptId, _ := this.GetInt("PptId")
- pptInfo, err := models.GetPptV2ById(pptId)
- if err != nil {
- br.Msg = "信息获取失败"
- br.ErrMsg = "信息获取失败,Err:" + err.Error()
- return
- }
- // 编辑中
- editor, e := services.UpdatePptEditing(pptId, 0, sysUser.AdminId, sysUser.RealName, false)
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "更新编辑状态失败, err: " + e.Error()
- return
- }
- resp := new(models.PPTDetailResp)
- resp.PptV2 = pptInfo
- resp.Editor = editor
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // DownloadPptx
- // @Title ppt下载
- // @Description ppt下载
- // @Param PptId query int true "PptId"
- // @Success 200 下载成功
- // @router /downloadpptx [get]
- func (this *PptV2CommonController) DownloadPptx() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- pptId, err := this.GetInt("PptId")
- if err != nil {
- br.Msg = "参数错误"
- br.ErrMsg = "获取,pptId,Err:" + err.Error()
- return
- }
- pptInfo, err := models.GetPptV2ById(pptId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取信息失败,Err:" + err.Error()
- return
- }
- filePath := pptInfo.PptxUrl
- fileName := pptInfo.Title + ".pptx"
- this.Ctx.Output.Download(filePath, fileName)
- br.Success = true
- br.Ret = 200
- br.Msg = "下载成功"
- return
- }
- // Publish
- // @Title 发布接口
- // @Description 发布接口
- // @Param request body models.SavePptV2PathReq true "type json string"
- // @Success Ret=200 发布成功
- // @router /publish [post]
- func (this *PptV2Controller) Publish() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- //SavePptV2PathReq
- //PptV2PublishReq
- var req models.SavePptV2PathReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- pptId := req.PptId
- if pptId <= 0 {
- br.Msg = "参数错误"
- return
- }
- err = models.EditPptV2Path(pptId, req.PptxUrl)
- if err != nil {
- br.Msg = "发布失败"
- br.ErrMsg = "发布失败,Err:" + err.Error()
- return
- }
- pptMap, err := models.GetPptMappingByPptId(int64(req.PptId))
- if err != nil {
- br.Msg = `该PPT信息不存在, 保存失败`
- br.ErrMsg = `该PPT信息不存在, 保存失败, Err` + err.Error()
- br.IsSendEmail = false
- return
- }
- pptMapList, err := models.GetPptMappingListByGroupId(pptMap.GroupId)
- if err != nil {
- br.ErrMsg = "PPT目录信息异常"
- return
- }
- if !pptMap.IsMoved && len(pptMapList) > 1 {
- // 如果没有人为移动位置, 默认将当前ppt置顶
- err = ppt.MoveGroupPpt(pptMap.GroupId, pptMap.GroupPptId, pptMapList[0].GroupPptId, 0, this.SysUser.AdminId)
- if err != nil {
- br.Msg = err.Error()
- br.ErrMsg = "移动失败,Err:" + err.Error()
- return
- }
- }
- //添加发布记录
- {
- record := new(models.PptV2PublishRecord)
- record.CreateTime = time.Now()
- record.PptId = pptId
- record.PptUrl = req.PptxUrl
- go models.AddPptV2PublishRecord(record)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "发布成功"
- br.IsAddLog = true
- return
- }
- // PptUpload
- // @Title ppt上传
- // @Description ppt上传
- // @Param PptId query int true "PptId"
- // @Success 200 新增成功
- // @router /pptUpload [post]
- func (this *PptV2Controller) PptUpload() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- pptId, _ := this.GetInt("PptId", 0)
- if pptId <= 0 {
- br.Msg = "参数错误"
- return
- }
- _, err := models.GetPptV2ById(pptId)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取PPT详情失败,Err:" + err.Error()
- return
- }
- f, h, err := this.GetFile("file")
- if err != nil {
- br.Msg = "获取资源信息失败"
- br.ErrMsg = "获取资源信息失败,Err:" + err.Error()
- return
- }
- defer func() {
- _ = f.Close()
- }()
- uploadFileName := h.Filename //上传的文件名
- ext := path.Ext(h.Filename)
- dateDir := time.Now().Format("20060102")
- uploadDir := utils.STATIC_DIR + "ppt/" + dateDir
- err = os.MkdirAll(uploadDir, utils.DIR_MOD)
- if err != nil {
- br.Msg = "存储目录创建失败"
- br.ErrMsg = "存储目录创建失败,Err:" + err.Error()
- return
- }
- randStr := utils.GetRandStringNoSpecialChar(28)
- fileName := randStr + ext
- fpath := uploadDir + "/" + fileName
- if err = this.SaveToFile("file", fpath); err != nil {
- br.Msg = "文件上传失败"
- br.ErrMsg = "文件上传失败,Err:" + err.Error()
- return
- }
- defer func() {
- _ = os.Remove(fpath)
- }()
- hzUploadDir := utils.RESOURCE_DIR + "ppt/"
- savePptxToOssPath := hzUploadDir + time.Now().Format("200601/20060102/")
- //pptName := strings.Replace(pptItem.Title, "\n", "", -1)
- //pptName = strings.TrimSuffix(pptName, " ")
- pptName := utils.GetRandStringNoSpecialChar(28)
- savePptxToOssPath += pptName + ".pptx"
- //上传到阿里云 和 minio
- pptxUrl := ``
- ossClient := services.NewOssClient()
- if ossClient == nil {
- br.Msg = "上传失败"
- br.ErrMsg = "初始化OSS服务失败"
- return
- }
- pptxUrl, err = ossClient.UploadFile(fileName, fpath, savePptxToOssPath)
- if err != nil {
- br.Msg = "文件上传失败"
- br.ErrMsg = "文件上传失败,Err:" + err.Error()
- return
- }
- resp := models.ResourceResp{
- ResourceUrl: pptxUrl,
- ResourceName: uploadFileName,
- }
- br.Msg = "上传成功"
- br.Ret = 200
- br.Success = true
- br.Data = resp
- return
- }
- // SaveLog
- // @Title 定时ppt操作日志记录
- // @Description 定时ppt操作日志记录
- // @Param request body models.AddPptV2Req true "type json string"
- // @Success 200 新增成功
- // @router /saveLog [post]
- func (this *PptV2Controller) SaveLog() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req models.AddPptV2Req
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.FirstPage.Title == "" {
- br.Msg = "标题不能为空"
- return
- }
- var pptContent []services.PPTContent
- err = json.Unmarshal([]byte(req.Content), &pptContent)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- // 获取ppt
- item, err := models.GetPptV2ByTitleAndId(req.FirstPage.Title, this.SysUser.AdminId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取数据异常!"
- br.ErrMsg = "获取数据异常,Err:" + err.Error()
- return
- }
- if item != nil && item.PptId != int(req.PptId) {
- br.Msg = "标题已存在,不可重复添加"
- br.IsSendEmail = false
- return
- }
- //变更ppt内容
- pptItem, e := models.GetPptV2ById(int(req.PptId))
- if e != nil {
- if e.Error() == utils.ErrNoRow() {
- br.Msg = "PPT已被删除, 请刷新页面"
- return
- }
- br.Msg = "信息获取失败"
- br.ErrMsg = "信息获取失败,Err:" + e.Error()
- return
- }
- // 标记编辑状态
- if pptItem.PptId > 0 {
- _, e = services.UpdatePptEditing(pptItem.PptId, 1, sysUser.AdminId, sysUser.RealName, false)
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "更新编辑状态失败, err: " + e.Error()
- return
- }
- }
- pptItem.TemplateType = req.FirstPage.TemplateType
- pptItem.BackgroundImg = req.FirstPage.ImgUrl
- pptItem.Title = req.FirstPage.Title
- pptItem.ReportType = req.FirstPage.ReportType
- pptItem.PptDate = req.FirstPage.PptDate
- pptItem.Content = req.Content
- pptItem.ModifyTime = time.Now()
- pptItem.TitleSetting = req.TitleSetting
- pptItem.PptPage = len(pptContent)
- err = pptItem.Update([]string{"TemplateType", "BackgroundImg", "Title", "ReportType", "PptDate", "Content", "ModifyTime", "ppt_page", "TitleSetting"})
- // 将更新后的PPT, 置顶
- pptMap, err := models.GetPptMappingByPptId(int64(req.PptId))
- if err != nil {
- br.Msg = `该PPT信息不存在, 保存失败`
- br.ErrMsg = `该PPT信息不存在, 保存失败, Err` + err.Error()
- br.IsSendEmail = false
- return
- }
- pptMapList, err := models.GetPptMappingListByGroupId(pptMap.GroupId)
- if err != nil {
- br.ErrMsg = "PPT目录信息异常"
- return
- }
- count, err := models.GetPptMappingByGroupPptCountId(pptMap.GroupPptId, this.SysUser.AdminId)
- if err != nil {
- br.Msg = "查询映射关系失败"
- br.ErrMsg = "查询映射关系失败, 保存失败, Err:" + err.Error()
- return
- }
- if !pptMap.IsMoved && len(pptMapList) > 1 && count > 0 {
- // 如果没有人为移动位置, 且当前用户有权限, 默认将当前ppt置顶
- err = ppt.MoveGroupPpt(pptMap.GroupId, pptMap.GroupPptId, pptMapList[0].GroupPptId, 0, this.SysUser.AdminId)
- if err != nil {
- br.Msg = err.Error()
- br.ErrMsg = "移动失败,Err:" + err.Error()
- return
- }
- }
- //日志记录
- logInfo := &models.PptV2SaveLog{
- PptId: int(req.PptId),
- TemplateType: req.FirstPage.TemplateType,
- BackgroundImg: req.FirstPage.ImgUrl,
- Title: req.FirstPage.Title,
- ReportType: req.FirstPage.ReportType,
- PptDate: req.FirstPage.PptDate,
- Content: req.Content,
- CoverContent: req.CoverContent,
- AdminId: this.SysUser.AdminId,
- AdminRealName: this.SysUser.RealName,
- CreateTime: time.Now(),
- TitleSetting: req.TitleSetting,
- }
- _, e = models.AddPptV2SaveLog(logInfo)
- if e != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "保存PPT日志失败, Err: " + e.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- }
- // GetConfig
- // @Title 获取ppt配置
- // @Description 获取ppt列表接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param KeyWord query string true "搜索关键词"
- // @Success 200 {object} models.PptV2ListResp
- // @router /config [get]
- func (this *PptV2Controller) GetConfig() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- crmConfig, err := company.GetConfigDetailByCode("ppt_limit")
- if err != nil {
- br.Msg = "获取配置失败"
- br.ErrMsg = "获取配置失败"
- br.IsSendEmail = false
- return
- }
- resp := new(models.PptV2ConfigResp)
- err = json.Unmarshal([]byte(crmConfig.ConfigValue), resp)
- if err != nil {
- br.Msg = "获取配置失败"
- br.ErrMsg = "获取配置失败;err:" + err.Error()
- br.IsSendEmail = false
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // ToReport
- // @Title PPT转报告
- // @Description PPT转报告
- // @Param request body models.PPT2ReportReq true "type json string"
- // @Success 200 Ret=200 转换成功
- // @router /to_report [post]
- func (this *PptV2Controller) ToReport() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req models.PPT2ReportReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.PptId == 0 {
- br.Msg = "参数有误"
- return
- }
- reportId, reportCode, msg, e := services.SavePPTReport(req.PptId, req.ClassifyId, req.Title, sysUser)
- if e != nil {
- br.Msg = msg
- br.ErrMsg = "PPT转报告失败, Err: " + e.Error()
- return
- }
- resp := &models.PPT2ReportResp{
- ReportId: reportId,
- ReportCode: reportCode,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "转换成功"
- br.IsAddLog = true
- br.Data = resp
- }
- // Grant
- // @Title 分配ppt权限
- // @Description 分配ppt权限接口
- // @Param request body models.GrantPptReq true "type json string"
- // @Success 200 Ret=200 分配成功
- // @router /grant [post]
- func (this *PptV2Controller) Grant() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.GrantPptReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.PptId <= 0 {
- br.Msg = "参数错误"
- return
- }
- // 查找ppt信息
- pptInfo, err := models.GetPptV2ById(req.PptId)
- if err != nil {
- br.Msg = "ppt不存在"
- return
- }
- if pptInfo.AdminId != this.SysUser.AdminId {
- br.Msg = "无权配置"
- return
- }
- // 分配
- err, errMsg := ppt.GrantPpt(req.PptId, req.GrantType, req.AdminIdStr, this.SysUser.AdminId)
- if errMsg != `` {
- br.Msg = errMsg
- br.ErrMsg = errMsg
- if err != nil {
- br.ErrMsg = errMsg + ";Err:" + err.Error()
- } else {
- br.IsSendEmail = false
- }
- return
- }
- br.Ret = 200
- br.Success = true
- br.IsAddLog = true
- br.Msg = "分配成功"
- }
- // CancelGrant
- // @Title 取消分配ppt权限
- // @Description 取消分配ppt权限
- // @Param request body models.DeletePptV2Req true "type json string"
- // @Success 200 Ret=200 分配成功
- // @router /grant/cancel [post]
- func (this *PptV2Controller) CancelGrant() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.DeletePptV2Req
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.PptId <= 0 {
- br.Msg = "参数错误"
- return
- }
- // 查找ppt信息
- pptInfo, err := models.GetPptV2ById(req.PptId)
- if err != nil {
- br.Msg = "ppt不存在"
- return
- }
- if pptInfo.AdminId != this.SysUser.AdminId {
- br.Msg = "无权取消配置"
- return
- }
- // 分配
- err, errMsg := ppt.DeleteGrantPpt(req.PptId)
- if errMsg != `` {
- br.Msg = errMsg
- br.ErrMsg = errMsg
- if err != nil {
- br.ErrMsg = errMsg + ";Err:" + err.Error()
- } else {
- br.IsSendEmail = false
- }
- return
- }
- br.Ret = 200
- br.Success = true
- br.IsAddLog = true
- br.Msg = "取消成功"
- }
- // GrantInfo
- // @Title 获取分配ppt权限详情
- // @Description 获取分配ppt权限详情接口
- // @Param PptId query int true "ppt的id"
- // @Success 200 {object} models.GrantInfoResp
- // @router /grant/info [get]
- func (this *PptV2Controller) GrantInfo() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- pptId, _ := this.GetInt("PptId")
- if pptId <= 0 {
- br.Msg = "参数错误"
- return
- }
- // 查找ppt信息
- pptInfo, err := models.GetPptV2ById(pptId)
- if err != nil {
- br.Msg = "ppt不存在"
- return
- }
- if pptInfo.AdminId != this.SysUser.AdminId {
- br.Msg = "无权配置"
- return
- }
- pptGrantInfoList, err := models.GetPPtGrantInfo(pptId)
- if err != nil {
- br.Msg = "信息获取失败"
- br.ErrMsg = "信息获取失败,Err:" + err.Error()
- return
- }
- if len(pptGrantInfoList) <= 0 {
- br.Msg = "未配置"
- br.IsSendEmail = false
- return
- }
- grantType := 0
- var adminIdStr string
- if pptGrantInfoList[0].DepartmentId > 0 { //分配类型;1:全部ficc研究员;2:指定成员
- grantType = 1
- } else {
- grantType = 2
- adminIdsList := make([]string, 0)
- for _, v := range pptGrantInfoList {
- adminIdsList = append(adminIdsList, strconv.Itoa(int(v.GrantAdminId)))
- }
- adminIdStr = strings.Join(adminIdsList, ",")
- }
- br.Ret = 200
- br.Success = true
- br.Data = models.GrantInfoResp{
- PptId: pptId,
- GrantType: grantType,
- AdminIdStr: adminIdStr,
- }
- br.Msg = "分配成功"
- }
- // ToEn
- // @Title 中文PPT转英文
- // @Description 中文PPT转英文
- // @Param request body models.EnPPT2CnReq true "type json string"
- // @Success 200 Ret=200 新增成功
- // @router /toEn [post]
- func (this *PptV2Controller) ToEn() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.EnPPT2CnReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.PptId <= 0 {
- br.Msg = "请选择PPT"
- return
- }
- if req.GroupId <= 0 {
- br.Msg = "请选择目录"
- return
- }
- origin, e := models.GetPptV2ById(req.PptId)
- if e != nil {
- br.Msg = "原PPT信息有误"
- br.ErrMsg = "获取原PPT失败, Err: " + e.Error()
- return
- }
- // 从基础配置中取出第一张封面图, 作为英文PPT的图片, 没有则取原PPT背景图
- conf, e := models.GetBusinessConf()
- if e != nil {
- br.Msg = "获取PPT图配置失败"
- br.ErrMsg = "获取PPT图配置失败, Err: " + e.Error()
- return
- }
- coverImg := ""
- if conf[models.BusinessConfEnPptCoverImgs] != "" {
- imgArr := strings.Split(conf[models.BusinessConfEnPptCoverImgs], ",")
- if len(imgArr) > 0 {
- coverImg = imgArr[0]
- }
- }
- if coverImg == "" {
- coverImg = origin.BackgroundImg
- }
- _, e = ppt_english.GetPptGroupByGroupIdAdminId(int64(req.GroupId), this.SysUser.AdminId)
- if e != nil {
- br.Msg = "目录信息有误"
- br.ErrMsg = "获取转换的英文PPT目录失败, Err: " + e.Error()
- return
- }
- // 同一PPT可重复转换, 但是标题不能重复, 所以此处进行一个处理, 在原标题后+(int)作为新标题
- newTitle, e := ppt.GetEnglishCopyUsableTitle(origin.Title)
- if e != nil {
- br.Msg = "标题信息有误"
- br.ErrMsg = "获取可用标题失败, Err: " + e.Error()
- return
- }
- var newId int64
- pptInfo := &ppt_english.PptEnglish{
- TemplateType: origin.TemplateType,
- BackgroundImg: coverImg,
- Title: newTitle,
- ReportType: origin.ReportType,
- PptDate: origin.PptDate,
- Content: origin.Content,
- CoverContent: origin.CoverContent,
- CreateTime: time.Now(),
- ModifyTime: time.Now(),
- AdminId: this.SysUser.AdminId,
- AdminRealName: this.SysUser.RealName,
- TitleSetting: origin.TitleSetting,
- }
- newId, e = ppt_english.AddPptEnglish(pptInfo)
- if e != nil {
- br.Msg = "转换失败"
- br.ErrMsg = "转换英文PPT失败, Err: " + e.Error()
- return
- }
- // 新增ppt和目录映射
- _, e = ppt.AddGroupPptEnglishMapping(newId, int64(req.GroupId), this.SysUser.AdminId, this.SysUser.RealName)
- if e != nil {
- br.Msg = "转换失败"
- br.ErrMsg = "新增英文PPT和目录映射失败, Err: " + e.Error()
- return
- }
- resp := ppt_english.AddPptEnglishResp{
- PptId: newId,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- br.Data = resp
- }
- // BatchToEn
- // @Title 中文PPT批量转英文
- // @Description 中文PPT转英文
- // @Param request body models.BatchEnPPT2CnReq true "type json string"
- // @Success 200 Ret=200 新增成功
- // @router /batchToEn [post]
- func (this *PptV2Controller) BatchToEn() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.BatchEnPPT2CnReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.PptIds == "" {
- br.Msg = "请选择PPT"
- return
- }
- if req.GroupId <= 0 {
- br.Msg = "请选择目录"
- return
- }
- pptIds := utils.JoinStr2IntArr(req.PptIds, ",")
- if len(pptIds) == 0 {
- br.Msg = "请选择PPT"
- return
- }
- ppts, e := models.GetPptV2ByIds(pptIds)
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "获取原PPT列表失败, Err: " + e.Error()
- return
- }
- if len(ppts) == 0 {
- br.Msg = "请选择PPT"
- return
- }
- _, e = ppt_english.GetPptGroupByGroupIdAdminId(int64(req.GroupId), this.SysUser.AdminId)
- if e != nil {
- br.Msg = "目录信息有误"
- br.ErrMsg = "获取转换的英文PPT目录失败, Err: " + e.Error()
- return
- }
- // 批量转换
- nowTime := time.Now().Local()
- for i := range ppts {
- origin := ppts[i]
- // 同一PPT可重复转换, 但是标题不能重复, 所以此处进行一个处理, 在原标题后+(int)作为新标题
- newTitle, e := ppt.GetEnglishCopyUsableTitle(origin.Title)
- if e != nil {
- br.Msg = "标题信息有误"
- br.ErrMsg = "获取可用标题失败, Err: " + e.Error()
- return
- }
- var newId int64
- pptInfo := &ppt_english.PptEnglish{
- TemplateType: origin.TemplateType,
- BackgroundImg: origin.BackgroundImg,
- Title: newTitle,
- ReportType: origin.ReportType,
- PptDate: origin.PptDate,
- Content: origin.Content,
- CoverContent: origin.CoverContent,
- CreateTime: nowTime,
- ModifyTime: nowTime,
- AdminId: this.SysUser.AdminId,
- AdminRealName: this.SysUser.RealName,
- }
- newId, e = ppt_english.AddPptEnglish(pptInfo)
- if e != nil {
- br.Msg = fmt.Sprintf("PPT: %s, 转换失败", ppts[i].Title)
- br.ErrMsg = "转换英文PPT失败, Err: " + e.Error()
- return
- }
- // 新增ppt和目录映射
- _, e = ppt.AddGroupPptEnglishMapping(newId, int64(req.GroupId), this.SysUser.AdminId, this.SysUser.RealName)
- if e != nil {
- br.Msg = fmt.Sprintf("PPT: %s, 转换失败", ppts[i].Title)
- br.ErrMsg = "新增英文PPT和目录映射失败, Err: " + e.Error()
- return
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
- // TitleCheck
- // @Title 校验标题是否重复
- // @Description 校验标题是否重复接口
- // @Param Title query int true "标题"
- // @Success 200 Ret=200 编辑成功
- // @router /titleCheck [get]
- func (this *PptV2Controller) TitleCheck() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- title := this.GetString("Title")
- pptId, _ := this.GetInt("PptId")
- if title == "" {
- br.Msg = "标题不能为空"
- return
- }
- item, err := models.GetPptV2ByTitleAndId(title, this.SysUser.AdminId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取数据异常!"
- br.ErrMsg = "获取数据异常,Err:" + err.Error()
- return
- }
- if item != nil && item.PptId != pptId {
- br.Msg = "标题已存在,不可重复添加"
- br.IsSendEmail = false
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "校验成功"
- }
- // Editing
- // @Title 标记/查询编辑状态
- // @Description 标记/查询编辑状态
- // @Param request body models.PPTEditingReq true "type json string"
- // @Success 200 Ret=200 操作成功
- // @router /editing [post]
- func (this *PptV2Controller) Editing() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req models.PPTEditingReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.PptId <= 0 {
- br.Msg = "参数有误"
- return
- }
- if req.Status < 0 {
- br.Msg = "标记状态异常"
- return
- }
- editor, e := services.UpdatePptEditing(req.PptId, req.Status, sysUser.AdminId, sysUser.RealName, false)
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "更新编辑状态失败, err: " + e.Error()
- return
- }
- br.Data = editor
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
|