123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647 |
- package controllers
- import (
- "encoding/json"
- "eta_gn/eta_api/models"
- "eta_gn/eta_api/models/system"
- "eta_gn/eta_api/services"
- "eta_gn/eta_api/utils"
- "fmt"
- "strconv"
- "strings"
- "time"
- "github.com/rdlucklib/rdluck_tools/paging"
- )
- // 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
- }
- // 获取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 (admin_id = ? OR FIND_IN_SET(?, collaborate_users)) `
- pars = append(pars, utils.ReportWriteTypeGroup, sysUser.AdminId)
- case 3:
- cond += ` AND report_source = ? AND state = ?`
- pars = append(pars, utils.ReportSourceOuter, models.ReportStatePass)
- }
- pptOb := new(models.PptV2)
- list, e := pptOb.GetItemsByCondition(cond, pars, models.PptReportQueryFields, "modify_time DESC")
- 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 {
- // 当前编辑人
- t := v.Format2ReportItem(v)
- editor, e := services.UpdatePptEditing(v.PptId, 0, sysUser.AdminId, sysUser.RealName, false)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = fmt.Sprintf("获取PPT编辑状态失败, err: %s", e.Error())
- return
- }
- t.Editor = editor
- // 权限
- if source == 1 || source == 2 {
- t.HasAuth = true
- } else {
- if v.AdminId == sysUser.AdminId {
- t.HasAuth = true
- }
- if t.HasAuth == false && v.CollaborateUsers != "" {
- authorArr := strings.Split(v.CollaborateUsers, ",")
- strId := strconv.Itoa(sysUser.AdminId)
- if utils.InArrayByStr(authorArr, strId) {
- t.HasAuth = true
- }
- }
- }
- if classifyPpt[v.ClassifyId] == nil {
- classifyPpt[v.ClassifyId] = make([]*models.PptReportItem, 0)
- }
- classifyPpt[v.ClassifyId] = append(classifyPpt[v.ClassifyId], t)
- }
- visibleUsers, err := models.GetClassifyVisibleAll()
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = fmt.Sprintf("获取可见用户失败, err: %s", err.Error())
- return
- }
- visibleUsersMap := make(map[int][]int)
- for _, v := range visibleUsers {
- visibleUsersMap[v.ClassifyId] = append(visibleUsersMap[v.ClassifyId], v.AdminId)
- }
- var resp []*models.PptReportClassifyItem
- // 获取分类
- classifies := make([]*models.Classify, 0)
- {
- // 获取所有分类
- ob := new(models.Classify)
- cond := ` AND enabled = ?`
- 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
- }
- // 上级中的分类类型可能与最下层的不一致,但是要把上级也一起取出来, 所以这里要过滤一遍
- classifyIds := make([]int, 0)
- for _, v := range list {
- if v.ClassifyType != utils.ReportTypePPT {
- continue
- }
- // 没有PPT的分类也都过滤掉
- //if len(classifyPpt[v.Id]) == 0 {
- // continue
- //}
- // 根据LevelPath去处理
- pathArr := strings.Split(v.LevelPath, ",")
- for _, p := range pathArr {
- id, _ := strconv.Atoi(p)
- if id <= 0 {
- continue
- }
- if utils.InArrayByInt(classifyIds, id) {
- continue
- }
- classifyIds = append(classifyIds, id)
- }
- }
- // 过滤掉不在ID中的
- for _, v := range list {
- if !utils.InArrayByInt(classifyIds, v.Id) {
- continue
- }
- if visible, ok := visibleUsersMap[v.Id]; ok {
- if !utils.InArrayByInt(visible, sysUser.AdminId) {
- continue
- }
- }
- classifies = append(classifies, v)
- }
- }
- resp = services.GetPptReportClassifyTreeRecursive(classifies, 0, classifyPpt)
- resp = services.RecursiveFilterPptNoChildTreeClassify(resp)
- 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)
- resp := new(models.PptPageReportResp)
- resp.List = make([]*models.PptReportItem, 0)
- // 获取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 (admin_id = ? OR FIND_IN_SET(?, collaborate_users)) `
- pars = append(pars, utils.ReportWriteTypeGroup, sysUser.AdminId, sysUser.AdminId)
- case 3:
- cond += ` AND report_source = ? AND state = ?`
- pars = append(pars, utils.ReportSourceOuter, models.ReportStatePass)
- }
- if classifyId > 0 {
- // 查询分类及子集
- classifyOb := new(models.Classify)
- childCond := ` AND FIND_IN_SET(?, level_path)`
- childPars := make([]interface{}, 0)
- childPars = append(childPars, classifyId)
- children, e := classifyOb.GetItemsByCondition(childCond, childPars, []string{"id"}, "")
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = fmt.Sprintf("获取分类及子分类失败, %v", e)
- return
- }
- var childIds []int
- for _, v := range children {
- childIds = append(childIds, v.Id)
- }
- if len(childIds) == 0 {
- page := paging.GetPaging(currentIndex, pageSize, 0)
- resp.Paging = page
- br.Data = resp
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- return
- }
- cond += ` AND classify_id IN (?)`
- pars = append(pars, childIds)
- }
- keyword = strings.TrimSpace(keyword)
- if keyword != "" {
- cond += ` AND title LIKE ?`
- pars = append(pars, fmt.Sprint("%", keyword, "%"))
- }
- }
- noVisibleClassifyIds, err := models.GetNoVisibleClassifyIdByAdminId(this.SysUser.AdminId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取不可见分类id失败,Err:" + err.Error()
- return
- }
- if len(noVisibleClassifyIds) > 0 {
- cond += ` AND classify_id NOT IN (?) `
- pars = append(pars, noVisibleClassifyIds)
- }
- 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, "modify_time DESC", startSize, pageSize)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = fmt.Sprintf("获取PPT失败, %v", e)
- return
- }
- pptList = list
- for _, v := range pptList {
- // 当前编辑人
- t := v.Format2ReportItem(v)
- editor, e := services.UpdatePptEditing(v.PptId, 0, sysUser.AdminId, sysUser.RealName, false)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = fmt.Sprintf("获取PPT编辑状态失败, err: %s", e.Error())
- return
- }
- t.Editor = editor
- // 权限
- if source == 1 || source == 2 {
- t.HasAuth = true
- } else {
- if v.AdminId == sysUser.AdminId {
- t.HasAuth = true
- }
- if t.HasAuth == false && v.CollaborateUsers != "" {
- authorArr := strings.Split(v.CollaborateUsers, ",")
- strId := strconv.Itoa(sysUser.AdminId)
- if utils.InArrayByStr(authorArr, strId) {
- t.HasAuth = true
- }
- }
- }
- resp.List = append(resp.List, t)
- }
- 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 {
- req.AddType = 1
- }
- 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.CurrentBackgroundImg = inheritPpt.CurrentBackgroundImg
- newItem.BackCoverImg = inheritPpt.BackCoverImg
- newItem.CurrentBackgroundImgId = inheritPpt.CurrentBackgroundImgId
- newItem.BackCoverImgId = inheritPpt.BackCoverImgId
- newItem.BackgroundImgId = inheritPpt.BackgroundImgId
- newItem.ReportType = inheritPpt.ReportType
- newItem.PptDate = inheritPpt.PptDate
- newItem.Content = inheritPpt.Content
- newItem.CoverContent = inheritPpt.CoverContent
- newItem.TitleSetting = inheritPpt.TitleSetting
- }
- // 非继承PPT,有内容时写入内容(如合并PPT时)
- if req.InheritPptId <= 0 {
- newItem.TemplateType = req.FirstPage.TemplateType
- newItem.BackgroundImg = req.FirstPage.ImgUrl
- newItem.CurrentBackgroundImg = req.FirstPage.CurrentBackgroundImg
- newItem.BackCoverImg = req.FirstPage.BackCoverImg
- newItem.CurrentBackgroundImgId = req.FirstPage.CurrentBackgroundImgId
- newItem.BackCoverImgId = req.FirstPage.BackCoverImgId
- newItem.BackgroundImgId = req.FirstPage.BackgroundImgId
- newItem.ReportType = req.FirstPage.ReportType
- newItem.PptDate = req.FirstPage.PptDate
- newItem.Content = req.Content
- newItem.CoverContent = req.CoverContent
- newItem.TitleSetting = req.TitleSetting
- }
- // 初始的PPT页数
- if newItem.Content != "" {
- var pageContents []services.PPTContent
- _ = json.Unmarshal([]byte(newItem.Content), &pageContents) // 这里转不过去问题也不大,编辑时自动保存会更新页数字段
- newItem.PptPage = len(pageContents)
- }
- 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 = "操作成功"
- }
- // AuthList
- // @Title 获取有权限的列表
- // @Description 获取有权限的列表
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param Keyword query string false "搜索关键词"
- // @Param ClassifyId query int false "分类ID"
- // @Success 200 {object} models.PptPageReportResp
- // @router /report/auth_list [get]
- func (this *PptV2Controller) AuthList() {
- 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
- }
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- keyword := this.GetString("Keyword")
- classifyId, _ := this.GetInt("ClassifyId", 0)
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = utils.StartIndex(currentIndex, pageSize)
- var pptList []*models.PptReportItem
- // 无相关搜索时,返回空集(其实我感觉没必要,没关键词查全部也属于正常=_=!)
- if keyword == `` && classifyId <= 0 {
- page := paging.GetPaging(currentIndex, pageSize, 0)
- resp := new(models.PptPageReportResp)
- resp.Paging = page
- resp.List = pptList
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- return
- }
- // 查询自己创建的以及协作人包含自己的报告、以及外部已审批报告
- var cond string
- var pars []interface{}
- cond += ` AND (admin_id = ? OR (admin_id <> ? AND FIND_IN_SET(?, collaborate_users)) OR (report_source = ? AND state = ?))`
- pars = append(pars, sysUser.AdminId, sysUser.AdminId, sysUser.AdminId, utils.ReportSourceOuter, models.ReportStatePass)
- if classifyId > 0 {
- cond += ` AND classify_id = ? `
- pars = append(pars, classifyId)
- }
- keyword = strings.TrimSpace(keyword)
- if keyword != `` {
- cond += ` AND title LIKE ? `
- pars = utils.GetLikeKeywordPars(pars, keyword, 1)
- }
- noVisisbleClassifyIds, err := models.GetNoVisibleClassifyIdByAdminId(sysUser.AdminId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = fmt.Sprintf("获取不可见分类失败, %v", err)
- return
- }
- if len(noVisisbleClassifyIds) > 0 {
- cond += ` AND classify_id NOT IN (?)`
- pars = append(pars, noVisisbleClassifyIds)
- }
- 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
- }
- // 分类完整路径、协作人姓名
- classifyIdFull := make(map[int]string)
- {
- ob := new(models.Classify)
- classifies, e := ob.GetItemsByCondition("", make([]interface{}, 0), []string{}, "")
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = fmt.Sprintf("获取分类失败, %v", e)
- return
- }
- classifyIdName := make(map[string]string)
- for _, v := range classifies {
- classifyIdName[strconv.Itoa(v.Id)] = v.ClassifyName
- }
- for _, v := range classifies {
- arr := strings.Split(v.LevelPath, ",")
- if len(arr) == 0 {
- continue
- }
- var nameArr []string
- for _, a := range arr {
- n := classifyIdName[a]
- if n == "" {
- continue
- }
- nameArr = append(nameArr, n)
- }
- classifyIdFull[v.Id] = strings.Join(nameArr, "/")
- }
- }
- adminIdName := make(map[int]string)
- {
- cond := ` AND enabled = 1`
- pars := make([]interface{}, 0)
- sysAdmin, e := system.GetSysAdminList(cond, pars, []string{}, "")
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取用户失败,Err:" + e.Error()
- return
- }
- for _, v := range sysAdmin {
- adminIdName[v.AdminId] = v.RealName
- }
- }
- // 格式化数据
- for _, v := range list {
- t := v.Format2ReportItem(v)
- t.HasAuth = true // 该列表固定有权限
- t.FullClassify = classifyIdFull[v.ClassifyId] // 分类的完整路径
- // 协作人
- if v.CollaborateUsers != "" {
- var authors []models.PptReportCollaborateUser
- authorArr := strings.Split(v.CollaborateUsers, ",")
- for _, au := range authorArr {
- uid, _ := strconv.Atoi(au)
- if uid <= 0 {
- continue
- }
- name := adminIdName[uid]
- if name == "" {
- continue
- }
- authors = append(authors, models.PptReportCollaborateUser{
- AdminId: uid,
- RealName: name,
- })
- }
- t.CollaborateUsers = authors
- }
- pptList = append(pptList, t)
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp := new(models.PptPageReportResp)
- resp.Paging = page
- resp.List = pptList
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
|