123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921 |
- package controllers
- import (
- "encoding/json"
- "fmt"
- "github.com/rdlucklib/rdluck_tools/paging"
- "hongze/hongze_ETA_mobile_api/models"
- "hongze/hongze_ETA_mobile_api/models/company"
- "hongze/hongze_ETA_mobile_api/models/ppt_english"
- "hongze/hongze_ETA_mobile_api/services/ppt"
- "hongze/hongze_ETA_mobile_api/utils"
- _ "image/gif"
- _ "image/jpeg"
- _ "image/png"
- "strconv"
- "strings"
- "time"
- )
- // 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 = append(pars, "%"+keyWord+"%", "%"+keyWord+"%")
- }
- 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
- }
- }
- 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 newId int64
- var msg string
- if req.PptId <= 0 {
- if req.GroupId == 0 {
- br.Msg = "请输入目录ID"
- return
- }
- item, err := models.GetPptV2ByTitle(req.FirstPage.Title)
- 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 := &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,
- CreateTime: time.Now(),
- ModifyTime: time.Now(),
- AdminId: this.SysUser.AdminId,
- AdminRealName: this.SysUser.RealName,
- PptVersion: 2,
- }
- 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 = "新增成功"
- } 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.ModifyTime = time.Now()
- err = pptInfo.Update([]string{"TemplateType", "BackgroundImg", "Title", "ReportType", "PptDate", "Content", "ModifyTime"})
- 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
- }
- item, err := models.GetPptV2ByTitle(req.FirstPage.Title)
- 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.ModifyTime = time.Now()
- err = pptInfo.Update([]string{"TemplateType", "BackgroundImg", "Title", "ReportType", "PptDate", "Content", "ModifyTime"})
- if err != nil {
- br.Msg = "编辑失败"
- 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,
- 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() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- pptId, _ := this.GetInt("PptId")
- pptInfo, err := models.GetPptV2ById(pptId)
- if err != nil {
- br.Msg = "信息获取失败"
- br.ErrMsg = "信息获取失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = pptInfo
- }
- // 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
- }
- //添加发布记录
- {
- 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
- }
- // 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() {
- 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
- }
- // 获取ppt
- item, err := models.GetPptV2ByTitle(req.FirstPage.Title)
- 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内容
- _, 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.ModifyTime = time.Now()
- //err = pptInfo.Update([]string{"TemplateType", "BackgroundImg", "Title", "ReportType", "PptDate", "Content", "ModifyTime"})
- //日志记录
- 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,
- AdminId: this.SysUser.AdminId,
- AdminRealName: this.SysUser.RealName,
- CreateTime: time.Now(),
- }
- _, err = models.AddPptV2SaveLog(logInfo)
- if err != nil {
- }
- 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
- }
- // 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
- }
- _, 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: origin.BackgroundImg,
- Title: newTitle,
- ReportType: origin.ReportType,
- PptDate: origin.PptDate,
- Content: origin.Content,
- CreateTime: time.Now(),
- ModifyTime: time.Now(),
- AdminId: this.SysUser.AdminId,
- AdminRealName: this.SysUser.RealName,
- }
- 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,
- 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 = "操作成功"
- }
|