1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192 |
- 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"
- _ "image/gif"
- _ "image/jpeg"
- _ "image/png"
- "os"
- "path"
- "strconv"
- "strings"
- "time"
- "github.com/rdlucklib/rdluck_tools/paging"
- )
- // PptEnglishController 新版ppt模块
- type PptEnglishController struct {
- BaseAuthController
- }
- // PptEnglishCommonController 新版ppt公共模块
- type PptEnglishCommonController 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} ppt_english.PptEnglishListResp
- // @router /list [get]
- func (this *PptEnglishController) 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 := ppt_english.GetPptEnglishListCount(condition, pars)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- list, err := ppt_english.GetPptEnglishList(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(ppt_english.PptEnglishListResp)
- 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 ppt_english.AddPptEnglishReq true "type json string"
- // @Success 200 Ret=200 新增成功
- // @router /add [post]
- func (this *PptEnglishController) AddPpt() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req ppt_english.AddPptEnglishReq
- 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 := ppt_english.GetPptEnglishByTitleAndId(req.FirstPage.Title, this.SysUser.AdminId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取数据异常!"
- br.ErrMsg = "获取数据异常,Err:" + err.Error()
- return
- }
- if item != nil {
- br.Msg = "标题已存在,不可重复添加"
- br.IsSendEmail = false
- return
- }
- pptInfo := &ppt_english.PptEnglish{
- //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,
- TitleSetting: req.TitleSetting,
- }
- newId, err = ppt_english.AddPptEnglish(pptInfo)
- if err != nil {
- br.Msg = "新增失败"
- br.ErrMsg = "新增失败,Err:" + err.Error()
- return
- }
- //新增ppt和目录映射
- _, err = ppt.AddGroupPptEnglishMapping(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: 5,
- 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 := ppt_english.GetPptEnglishById(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 := ppt_english.AddPptEnglishResp{
- PptId: newId,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = msg
- br.Data = resp
- }
- // EditPpt
- // @Title 编辑ppt
- // @Description 编辑ppt接口
- // @Param request body ppt_english.AddPptEnglishReq true "type json string"
- // @Success 200 Ret=200 编辑成功
- // @router /edit [post]
- func (this *PptEnglishController) EditPpt() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req ppt_english.AddPptEnglishReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- var pptContent []services.PPTContent
- err = json.Unmarshal([]byte(req.Content), &pptContent)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.FirstPage.Title == "" {
- br.Msg = "标题不能为空"
- return
- }
- item, err := ppt_english.GetPptEnglishByTitleAndId(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 := ppt_english.GetPptEnglishById(int(req.PptId))
- if err != nil {
- br.Msg = "信息获取失败"
- br.ErrMsg = "信息获取失败,Err:" + err.Error()
- return
- }
- // 判断权限
- if pptInfo.AdminId != this.SysUser.AdminId {
- _, err := ppt_english.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 := ppt_english.GetPptMappingByPptId(req.PptId)
- if err != nil {
- br.Msg = `该PPT信息不存在, 保存失败`
- br.ErrMsg = `该PPT信息不存在, 保存失败, Err` + err.Error()
- br.IsSendEmail = false
- return
- }
- pptMapList, err := ppt_english.GetPptMappingListByGroupIdDesc(pptMap.GroupId)
- if err != nil {
- br.ErrMsg = "PPT目录信息异常"
- return
- }
- count, err := ppt_english.GetPptMappingCountByGroupPptId(pptMap.GroupPptId, this.SysUser.AdminId)
- if err != nil {
- br.Msg = "获取英文PPT和用户权限关系失败"
- br.ErrMsg = "获取英文PPT和用户权限关系失败, Err:" + err.Error()
- return
- }
- if !pptMap.IsMoved && len(pptMapList) > 1 && count > 0 {
- // 如果没有人为移动位置, 默认将当前ppt置顶
- err = ppt.MoveGroupPptEnglish(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 := &ppt_english.PptEnglishSaveLog{
- 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(),
- TitleSetting: req.TitleSetting,
- }
- _, err = ppt_english.AddPptEnglishSaveLog(logInfo)
- }
- resp := ppt_english.AddPptEnglishResp{
- 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 ppt_english.DeletePptEnglishReq true "type json string"
- // @Success 200 Ret=200 删除成功
- // @router /delete [post]
- func (this *PptEnglishController) DeletePpt() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req ppt_english.DeletePptEnglishReq
- 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 := ppt_english.GetPptEnglishById(req.PptId)
- if err != nil {
- br.Msg = "ppt不存在"
- return
- }
- if pptInfo.AdminId != this.SysUser.AdminId {
- br.Msg = "无权删除"
- return
- }
- err = ppt_english.DeletePptEnglish(req.PptId)
- if err != nil {
- br.Msg = "删除失败"
- br.ErrMsg = "删除失败,Err:" + err.Error()
- return
- }
- //如果该ppt存在单个共享记录,则删除共享
- err = ppt.DeleteGroupPptEnglish(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} ppt_english.PptEnglish
- // @router /detail [get]
- func (this *PptEnglishController) 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 := ppt_english.GetPptEnglishById(pptId)
- if err != nil {
- br.Msg = "信息获取失败"
- br.ErrMsg = "信息获取失败,Err:" + err.Error()
- return
- }
- // 查询编辑中
- editor, e := services.UpdatePptEditing(pptId, 0, sysUser.AdminId, sysUser.RealName, true)
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "更新编辑状态失败, err: " + e.Error()
- return
- }
- resp := new(ppt_english.EnglishPPTDetailResp)
- resp.PptEnglish = 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 *PptEnglishCommonController) 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 := ppt_english.GetPptEnglishById(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 ppt_english.SavePptEnglishPathReq true "type json string"
- // @Success Ret=200 发布成功
- // @router /publish [post]
- func (this *PptEnglishController) Publish() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- //SavePptEnglishPathReq
- //PptEnglishPublishReq
- var req ppt_english.SavePptEnglishPathReq
- 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 = ppt_english.EditPptEnglishPath(pptId, req.PptxUrl)
- if err != nil {
- br.Msg = "发布失败"
- br.ErrMsg = "发布失败,Err:" + err.Error()
- return
- }
- pptMap, err := ppt_english.GetPptMappingByPptId(int64(req.PptId))
- if err != nil {
- br.Msg = `该PPT信息不存在, 保存失败`
- br.ErrMsg = `该PPT信息不存在, 保存失败, Err` + err.Error()
- br.IsSendEmail = false
- return
- }
- pptMapList, err := ppt_english.GetPptMappingListByGroupIdDesc(pptMap.GroupId)
- if err != nil {
- br.ErrMsg = "PPT目录信息异常"
- return
- }
- if !pptMap.IsMoved && len(pptMapList) > 1 {
- // 如果没有人为移动位置, 默认将当前ppt置顶
- err = ppt.MoveGroupPptEnglish(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(ppt_english.PptEnglishPublishRecord)
- record.CreateTime = time.Now()
- record.PptId = pptId
- record.PptUrl = req.PptxUrl
- go ppt_english.AddPptEnglishPublishRecord(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 *PptEnglishController) 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 := ppt_english.GetPptEnglishById(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
- }
- uploadFileName := h.Filename //上传的文件名
- ext := path.Ext(h.Filename)
- dateDir := time.Now().Format("20060102")
- uploadDir := utils.STATIC_DIR + "hongze/" + 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
- defer f.Close() //关闭上传文件
- err = this.SaveToFile("file", fpath)
- if err != nil {
- br.Msg = "文件上传失败"
- br.ErrMsg = "文件上传失败,Err:" + err.Error()
- return
- }
- hzUploadDir := "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"
- defer func() {
- _ = os.Remove(fpath)
- }()
- //上传到阿里云 和 minio
- pptxUrl := ``
- //if utils.ObjectStorageClient == "minio" {
- // err = services.UploadFileToMinIo("", fpath, savePptxToOssPath)
- // if err != nil {
- // br.Msg = "文件上传失败"
- // br.ErrMsg = "文件上传失败,Err:" + err.Error()
- // return
- // }
- // pptxUrl = utils.MinIoImghost + savePptxToOssPath
- //} else {
- // err = services.UploadFileToAliyun("", fpath, savePptxToOssPath)
- // if err != nil {
- // br.Msg = "文件上传失败"
- // br.ErrMsg = "文件上传失败,Err:" + err.Error()
- // return
- // }
- // pptxUrl = utils.Imghost + savePptxToOssPath
- //}
- ossClient := services.NewOssClient()
- if ossClient == nil {
- br.Msg = "上传失败"
- br.ErrMsg = "初始化OSS服务失败"
- return
- }
- pptxUrl, err = ossClient.UploadFile("", fpath, savePptxToOssPath)
- if err != nil {
- br.Msg = "文件上传失败"
- br.ErrMsg = "文件上传失败,Err:" + err.Error()
- return
- }
- item := &models.Resource{
- //Id: 0,
- ResourceUrl: pptxUrl,
- CreateTime: time.Now(),
- ResourceType: 4,
- }
- newId, err := models.AddResource(item)
- if err != nil {
- br.Msg = "资源上传失败"
- br.ErrMsg = "资源上传失败,Err:" + err.Error()
- return
- }
- resp := models.ResourceResp{
- Id: newId,
- ResourceUrl: pptxUrl,
- ResourceName: uploadFileName,
- }
- br.Msg = "上传成功"
- br.Ret = 200
- br.Success = true
- br.Data = resp
- return
- }
- // SaveLog
- // @Title 定时ppt操作日志记录
- // @Description 定时ppt操作日志记录
- // @Param request body ppt_english.AddPptEnglishReq true "type json string"
- // @Success 200 新增成功
- // @router /saveLog [post]
- func (this *PptEnglishController) 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 ppt_english.AddPptEnglishReq
- 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 pageContent []services.PPTContent
- err = json.Unmarshal([]byte(req.Content), &pageContent)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- // 获取ppt
- item, err := ppt_english.GetPptEnglishByTitleAndId(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 := ppt_english.GetPptEnglishById(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, true)
- 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.PptPage = len(pageContent)
- err = pptItem.Update([]string{"TemplateType", "BackgroundImg", "Title", "ReportType", "PptDate", "Content", "ModifyTime", "ppt_page"})
- pptMap, err := ppt_english.GetPptMappingByPptId(req.PptId)
- if err != nil {
- br.Msg = `该PPT信息不存在, 保存失败`
- br.ErrMsg = `该PPT信息不存在, 保存失败, Err` + err.Error()
- br.IsSendEmail = false
- return
- }
- pptMapList, err := ppt_english.GetPptMappingListByGroupIdDesc(pptMap.GroupId)
- if err != nil {
- br.ErrMsg = "PPT目录信息异常"
- return
- }
- count, err := ppt_english.GetPptMappingCountByGroupPptId(pptMap.GroupPptId, this.SysUser.AdminId)
- if err != nil {
- br.Msg = "获取英文PPT和用户权限关系失败"
- br.ErrMsg = "获取英文PPT和用户权限关系失败, Err:" + err.Error()
- return
- }
- if !pptMap.IsMoved && len(pptMapList) > 1 && count > 0 {
- // 如果没有人为移动位置, 且当前用户有权限, 默认将当前ppt置顶
- err = ppt.MoveGroupPptEnglish(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 := &ppt_english.PptEnglishSaveLog{
- 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,
- }
- _, err = ppt_english.AddPptEnglishSaveLog(logInfo)
- if err != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "保存PPT日志失败, Err: " + err.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} ppt_english.PptEnglishListResp
- // @router /config [get]
- func (this *PptEnglishController) 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(ppt_english.PptEnglishConfigResp)
- 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
- }
- // Grant
- // @Title 分配ppt权限
- // @Description 分配ppt权限接口
- // @Param request body ppt_english.GrantPptReq true "type json string"
- // @Success 200 Ret=200 分配成功
- // @router /grant [post]
- func (this *PptEnglishController) Grant() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req ppt_english.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 := ppt_english.GetPptEnglishById(req.PptId)
- if err != nil {
- br.Msg = "ppt不存在"
- return
- }
- if pptInfo.AdminId != this.SysUser.AdminId {
- br.Msg = "无权配置"
- return
- }
- // 分配
- err, errMsg := ppt.GrantPptEnglish(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 ppt_english.DeletePptEnglishReq true "type json string"
- // @Success 200 Ret=200 分配成功
- // @router /grant/cancel [post]
- func (this *PptEnglishController) CancelGrant() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req ppt_english.DeletePptEnglishReq
- 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 := ppt_english.GetPptEnglishById(req.PptId)
- if err != nil {
- br.Msg = "ppt不存在"
- return
- }
- if pptInfo.AdminId != this.SysUser.AdminId {
- br.Msg = "无权取消配置"
- return
- }
- // 分配
- err, errMsg := ppt.DeleteGrantPptEnglish(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} ppt_english.GrantInfoResp
- // @router /grant/info [get]
- func (this *PptEnglishController) 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 := ppt_english.GetPptEnglishById(pptId)
- if err != nil {
- br.Msg = "ppt不存在"
- return
- }
- if pptInfo.AdminId != this.SysUser.AdminId {
- br.Msg = "无权配置"
- return
- }
- pptGrantInfoList, err := ppt_english.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 = ppt_english.GrantInfoResp{
- PptId: pptId,
- GrantType: grantType,
- AdminIdStr: adminIdStr,
- }
- br.Msg = "分配成功"
- }
- // ToReport
- // @Title 英文PPT转报告
- // @Description PPT转报告
- // @Param request body ppt_english.EnglishPPT2ReportReq true "type json string"
- // @Success 200 Ret=200 转换成功
- // @router /toReport [post]
- func (this *PptEnglishController) 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 ppt_english.EnglishPPT2ReportReq
- 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.SaveEnglishPPTReport(req.PptId, req.ClassifyIdFirst, req.ClassifyIdSecond, req.Title, req.Abstract, 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
- }
- // TitleCheck
- // @Title 校验标题是否重复
- // @Description 校验标题是否重复接口
- // @Param Title query int true "标题"
- // @Success 200 Ret=200 编辑成功
- // @router /titleCheck [get]
- func (this *PptEnglishController) 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 := ppt_english.GetPptEnglishByTitleAndId(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 *PptEnglishController) 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, true)
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "更新编辑状态失败, err: " + e.Error()
- return
- }
- br.Data = editor
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
|