123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341 |
- package controllers
- import (
- "encoding/json"
- "eta_gn/eta_api/models"
- "eta_gn/eta_api/services"
- "eta_gn/eta_api/utils"
- "fmt"
- "github.com/rdlucklib/rdluck_tools/paging"
- "strconv"
- "strings"
- "time"
- )
- // ReportClassify
- // @Title 获取ppt报告分类
- // @Description 获取ppt报告分类
- // @Param Source query int false "来源:1-我的;2-协作;3-公共"
- // @Success 200 {object} models.PptReportClassifyItem
- // @router /report/classify [get]
- func (this *PptV2Controller) ReportClassify() {
- 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"
- return
- }
- source, _ := this.GetInt("Source", 1)
- if source < 1 || source > 3 {
- source = 1
- }
- fmt.Println(sysUser.AdminId)
- // 获取PPT, source:1-我的;2-协作;3-公共
- pptList := make([]*models.PptV2, 0)
- {
- cond := ``
- pars := make([]interface{}, 0)
- switch source {
- case 1:
- cond += ` AND admin_id = ?`
- pars = append(pars, sysUser.AdminId)
- case 2:
- cond += ` AND collaborate_type = ? AND FIND_IN_SET(?, collaborate_users) `
- pars = append(pars, utils.ReportWriteTypeGroup, sysUser.AdminId)
- case 3:
- cond += ` AND report_source = ?`
- pars = append(pars, utils.ReportSourceOuter)
- }
- pptOb := new(models.PptV2)
- list, e := pptOb.GetItemsByCondition(cond, pars, models.PptReportQueryFields, "")
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = fmt.Sprintf("获取PPT失败, %v", e)
- return
- }
- pptList = list
- }
- classifyPpt := make(map[int][]*models.PptReportItem)
- for _, v := range pptList {
- if classifyPpt[v.ClassifyId] == nil {
- classifyPpt[v.ClassifyId] = make([]*models.PptReportItem, 0)
- }
- classifyPpt[v.ClassifyId] = append(classifyPpt[v.ClassifyId], v.Format2ReportItem(v))
- }
- resp := make([]*models.PptReportClassifyItem, 0)
- // 获取分类
- classifies := make([]*models.Classify, 0)
- {
- ob := new(models.Classify)
- cond := ` AND enabled = ? AND classify_type = ?`
- pars := make([]interface{}, 0)
- pars = append(pars, 1, utils.ReportTypePPT)
- list, e := ob.GetItemsByCondition(cond, pars, []string{}, "sort ASC, create_time ASC")
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = fmt.Sprintf("获取分类失败, %v", e)
- return
- }
- classifies = list
- }
- resp = services.GetPptReportClassifyTreeRecursive(classifies, 0, classifyPpt)
- br.Data = resp
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
- // ReportList
- // @Title 获取ppt报告列表-分页
- // @Description 获取ppt报告列表-分页
- // @Param Source query int false "来源:1-我的;2-协作;3-公共"
- // @Param ClassifyId query int false "分类ID"
- // @Param Keyword query string false "搜索关键词"
- // @Success 200 {object} models.PptPageReportResp
- // @router /report/list [get]
- func (this *PptV2Controller) ReportList() {
- 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"
- return
- }
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- source, _ := this.GetInt("Source", 1)
- if source < 1 || source > 3 {
- source = 1
- }
- classifyId, _ := this.GetInt("ClassifyId", 0)
- keyword := this.GetString("Keyword")
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = utils.StartIndex(currentIndex, pageSize)
- // 获取PPT, source:1-我的;2-协作;3-公共
- pptList := make([]*models.PptV2, 0)
- cond := ``
- pars := make([]interface{}, 0)
- {
- switch source {
- case 1:
- cond += ` AND admin_id = ?`
- pars = append(pars, sysUser.AdminId)
- case 2:
- cond += ` AND collaborate_type = ? AND FIND_IN_SET(?, collaborate_users) `
- pars = append(pars, utils.ReportWriteTypeGroup, sysUser.AdminId)
- case 3:
- cond += ` AND report_source = ?`
- pars = append(pars, utils.ReportSourceOuter)
- }
- if classifyId > 0 {
- cond += ` AND classify_id = ?`
- pars = append(pars, classifyId)
- }
- keyword = strings.TrimSpace(keyword)
- if keyword != "" {
- cond += ` AND title LIKE ?`
- pars = append(pars, fmt.Sprint("%", keyword, "%"))
- }
- }
- pptOb := new(models.PptV2)
- total, e := pptOb.GetCountByCondition(cond, pars)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = fmt.Sprintf("获取PPT总数失败, %v", e)
- return
- }
- list, e := pptOb.GetPageItemsByCondition(cond, pars, models.PptReportQueryFields, "", startSize, pageSize)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = fmt.Sprintf("获取PPT失败, %v", e)
- return
- }
- pptList = list
- resp := new(models.PptPageReportResp)
- resp.List = make([]*models.PptReportItem, 0)
- for _, v := range pptList {
- resp.List = append(resp.List, v.Format2ReportItem(v))
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp.Paging = page
- br.Data = resp
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
- // CreateReport
- // @Title 新增ppt报告
- // @Description 新增ppt报告
- // @Param request body models.PptReportCreateReq true "type json string"
- // @Success 200 Ret=200 新增成功
- // @router /report/add [post]
- func (this *PptV2Controller) CreateReport() {
- 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"
- return
- }
- var req models.PptReportCreateReq
- if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
- br.Msg = "参数解析异常"
- br.ErrMsg = fmt.Sprintf("参数解析失败, %v", e)
- return
- }
- req.Title = strings.TrimSpace(req.Title)
- if req.Title == "" {
- br.Msg = "请输入标题"
- return
- }
- if req.AddType != 1 && req.AddType != 2 {
- br.Msg = "新增方式异常"
- br.ErrMsg = fmt.Sprintf("新增方式异常, %d", req.AddType)
- return
- }
- if req.ClassifyId <= 0 {
- br.Msg = "请选择分类"
- return
- }
- if req.CollaborateType != 1 && req.CollaborateType != 2 {
- br.Msg = "协作方式异常"
- br.ErrMsg = fmt.Sprintf("协作方式异常, %d", req.CollaborateType)
- return
- }
- if req.CollaborateType == 2 && len(req.CollaborateUserIds) == 0 {
- br.Msg = "请选择协作人"
- return
- }
- // 新报告
- newItem := new(models.PptV2)
- newItem.Title = req.Title
- newItem.AddType = req.AddType
- newItem.ClassifyId = req.ClassifyId
- newItem.CollaborateType = req.CollaborateType
- if len(req.CollaborateUserIds) > 0 {
- var partnerArr []string
- for _, v := range req.CollaborateUserIds {
- partnerArr = append(partnerArr, strconv.Itoa(v))
- }
- newItem.CollaborateUsers = strings.Trim(strings.Join(partnerArr, ","), `"`)
- }
- newItem.PptVersion = 2
- newItem.AdminId = sysUser.AdminId
- newItem.AdminRealName = sysUser.RealName
- newItem.ReportSource = utils.ReportSourceLocal // 固定本地PPT
- newItem.State = models.ReportStateUnpublished // 默认未发布
- newItem.CreateTime = time.Now()
- newItem.ModifyTime = time.Now()
- // 继承PPT内容
- if req.AddType == utils.ReportAddTypeInherit && req.InheritPptId > 0 {
- inheritPpt, e := models.GetPptV2ById(req.InheritPptId)
- if e != nil {
- if utils.IsErrNoRow(e) {
- br.Msg = "被继承报告不存在"
- return
- }
- br.Msg = "操作失败"
- br.ErrMsg = fmt.Sprintf("操作失败, %v", e)
- return
- }
- newItem.TemplateType = inheritPpt.TemplateType
- newItem.BackgroundImg = inheritPpt.BackgroundImg
- newItem.ReportType = inheritPpt.ReportType
- newItem.PptDate = inheritPpt.PptDate
- newItem.Content = inheritPpt.Content
- newItem.CoverContent = inheritPpt.CoverContent
- newItem.TitleSetting = inheritPpt.TitleSetting
- }
- newId, e := models.AddPptV2(newItem)
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = fmt.Sprintf("新增PPT报告失败, %v", e)
- return
- }
- // 更新报告分类计数
- go func() {
- _ = services.UpdateClassifyReportNum(req.ClassifyId)
- }()
- resp := models.AddPptResp{
- PptId: newId,
- }
- br.Data = resp
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
- // SubmitReport
- // @Title 提交报告
- // @Description 提交报告
- // @Param request body models.PptReportCreateReq true "type json string"
- // @Success 200 Ret=200 新增成功
- // @router /report/submit [post]
- func (this *PptV2Controller) SubmitReport() {
- 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"
- return
- }
- //var req models.PptReportCreateReq
- //if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
- // br.Msg = "参数解析异常"
- // br.ErrMsg = fmt.Sprintf("参数解析失败, %v", e)
- // return
- //}
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
|