Răsfoiți Sursa

PPT报告接口

hsun 4 luni în urmă
părinte
comite
a710e5011c
6 a modificat fișierele cu 293 adăugiri și 14 ștergeri
  1. 220 3
      controllers/ppt_report.go
  2. 14 0
      controllers/ppt_v2.go
  3. 1 0
      models/classify.go
  4. 20 10
      models/ppt_v2.go
  5. 9 0
      routers/commentsRouter.go
  6. 29 1
      services/classify.go

+ 220 - 3
controllers/ppt_report.go

@@ -3,6 +3,7 @@ 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"
@@ -37,7 +38,6 @@ func (this *PptV2Controller) ReportClassify() {
 	if source < 1 || source > 3 {
 		source = 1
 	}
-	fmt.Println(sysUser.AdminId)
 
 	// 获取PPT, source:1-我的;2-协作;3-公共
 	pptList := make([]*models.PptV2, 0)
@@ -66,10 +66,36 @@ func (this *PptV2Controller) ReportClassify() {
 	}
 	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], v.Format2ReportItem(v))
+		classifyPpt[v.ClassifyId] = append(classifyPpt[v.ClassifyId], t)
 	}
 
 	resp := make([]*models.PptReportClassifyItem, 0)
@@ -183,7 +209,33 @@ func (this *PptV2Controller) ReportList() {
 	resp := new(models.PptPageReportResp)
 	resp.List = make([]*models.PptReportItem, 0)
 	for _, v := range pptList {
-		resp.List = append(resp.List, v.Format2ReportItem(v))
+		// 当前编辑人
+		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)
@@ -339,3 +391,168 @@ func (this *PptV2Controller) SubmitReport() {
 	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)))`
+	pars = append(pars, sysUser.AdminId, sysUser.AdminId, sysUser.AdminId)
+	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)
+	}
+	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
+}

+ 14 - 0
controllers/ppt_v2.go

@@ -438,6 +438,19 @@ func (this *PptV2Controller) DetailPpt() {
 		return
 	}
 
+	// 权限
+	var hasAuth bool
+	if pptInfo.AdminId == sysUser.AdminId {
+		hasAuth = true
+	}
+	if hasAuth == false && pptInfo.CollaborateUsers != "" {
+		authorArr := strings.Split(pptInfo.CollaborateUsers, ",")
+		strId := strconv.Itoa(sysUser.AdminId)
+		if utils.InArrayByStr(authorArr, strId) {
+			hasAuth = true
+		}
+	}
+
 	// 编辑中
 	editor, e := services.UpdatePptEditing(pptId, 0, sysUser.AdminId, sysUser.RealName, false)
 	if e != nil {
@@ -448,6 +461,7 @@ func (this *PptV2Controller) DetailPpt() {
 	resp := new(models.PPTDetailResp)
 	resp.PptV2 = pptInfo
 	resp.Editor = editor
+	resp.HasAuth = hasAuth
 
 	br.Ret = 200
 	br.Success = true

+ 1 - 0
models/classify.go

@@ -49,6 +49,7 @@ type Classify struct {
 	IsRemind             int       `gorm:"column:is_remind" json:"is_remind"`                             //`description:"是否开启提醒:0-关闭;1-开启"`
 	RemindTime           string    `gorm:"column:remind_time" json:"remind_time"`                         //`description:"提醒时间:可选00:00-23:59"`
 	ReportNum            int       `gorm:"column:report_num" json:"report_num"`                           //`description:"分类下的报告数"`
+	LevelPath            string    `gorm:"column:level_path" json:"level_path"`                           //`description:"分类的层级路径,英文逗号分隔"`
 }
 
 type ClassifyAddReq struct {

+ 20 - 10
models/ppt_v2.go

@@ -302,7 +302,8 @@ type PPTEditingReq struct {
 // PPTDetailResp PPT详情响应体
 type PPTDetailResp struct {
 	*PptV2
-	Editor PPTEditingCache `description:"编辑人信息"`
+	Editor  PPTEditingCache `description:"编辑人信息"`
+	HasAuth bool            `description:"是否有权限"`
 }
 
 // PPTEditingCache PPT编辑缓存信息
@@ -354,7 +355,7 @@ func (m *PptV2) GetCountByCondition(condition string, pars []interface{}) (count
 
 // PptReportQueryFields 除富文本的常用查询字段
 var PptReportQueryFields = []string{
-	"ppt_id", "title", "classify_id", "ppt_version", "pptx_url", "ppt_page", "title_setting", "state", "report_source", "publish_time", "submit_time", "approve_time", "create_time", "modify_time",
+	"ppt_id", "title", "classify_id", "ppt_version", "pptx_url", "ppt_page", "title_setting", "state", "report_source", "publish_time", "submit_time", "approve_time", "create_time", "modify_time", "admin_id", "collaborate_type", "collaborate_users",
 }
 
 type PptReportItem struct {
@@ -365,14 +366,23 @@ type PptReportItem struct {
 	PptxUrl    string `description:"pptx下载地址"`
 	PptPage    int    `description:"PPT总页数"`
 	//Content      string `description:"内容"`
-	TitleSetting string `description:"PPT标题设置"`
-	State        int    `description:"报告状态:1-未发布;2-已发布;3-待提交;4-待审批;5-已驳回;6-已通过"`
-	ReportSource int    `description:"报告来源:1-系统内;2-智力共享"`
-	PublishTime  string `description:"发布时间"`
-	SubmitTime   string `description:"提交时间"`
-	ApproveTime  string `description:"审批时间"`
-	CreateTime   string `description:"创建时间"`
-	ModifyTime   string `description:"更新时间"`
+	TitleSetting     string                     `description:"PPT标题设置"`
+	State            int                        `description:"报告状态:1-未发布;2-已发布;3-待提交;4-待审批;5-已驳回;6-已通过"`
+	ReportSource     int                        `description:"报告来源:1-系统内;2-智力共享"`
+	PublishTime      string                     `description:"发布时间"`
+	SubmitTime       string                     `description:"提交时间"`
+	ApproveTime      string                     `description:"审批时间"`
+	CreateTime       string                     `description:"创建时间"`
+	ModifyTime       string                     `description:"更新时间"`
+	FullClassify     string                     `description:"分类完整路径, /分隔"`
+	CollaborateUsers []PptReportCollaborateUser `description:"协作人信息"`
+	HasAuth          bool                       `description:"是否创建人/协作人"`
+	Editor           PPTEditingCache            `description:"编辑人信息"`
+}
+
+type PptReportCollaborateUser struct {
+	AdminId  int    `description:"用户ID"`
+	RealName string `description:"用户姓名"`
 }
 
 func (m *PptV2) Format2ReportItem(origin *PptV2) (item *PptReportItem) {

+ 9 - 0
routers/commentsRouter.go

@@ -6676,6 +6676,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta_gn/eta_api/controllers:PptV2Controller"] = append(beego.GlobalControllerRouter["eta_gn/eta_api/controllers:PptV2Controller"],
+        beego.ControllerComments{
+            Method: "AuthList",
+            Router: `/report/auth_list`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta_gn/eta_api/controllers:PptV2Controller"] = append(beego.GlobalControllerRouter["eta_gn/eta_api/controllers:PptV2Controller"],
         beego.ControllerComments{
             Method: "ReportClassify",

+ 29 - 1
services/classify.go

@@ -7,6 +7,7 @@ import (
 	"eta_gn/eta_api/utils"
 	"fmt"
 	"sort"
+	"strconv"
 	"time"
 )
 
@@ -218,6 +219,7 @@ func AddReportClassify(classifyName string, parentId int, classifyType, isRemind
 	// 父级分类下的子分类数量
 	var childClassifyCount int
 
+	var levelPath string
 	if parentId > 0 {
 		// 获取父级分类信息
 		parentClassifyItem, err = models.GetClassifyById(parentId)
@@ -229,6 +231,7 @@ func AddReportClassify(classifyName string, parentId int, classifyType, isRemind
 			return
 		}
 		level = parentClassifyItem.Level + 1
+		levelPath = parentClassifyItem.LevelPath // 这里只是一半,新增后后面跟上新分类ID
 
 		if level > 3 {
 			errMsg = "分类层级不可超过三级"
@@ -299,6 +302,17 @@ func AddReportClassify(classifyName string, parentId int, classifyType, isRemind
 		}
 	}
 
+	// 更新分类的LevelPath
+	if parentId == 0 {
+		levelPath = strconv.Itoa(classify.Id)
+	} else {
+		levelPath = fmt.Sprintf("%s,%d", levelPath, classify.Id)
+	}
+	classify.LevelPath = levelPath
+	if e := classify.UpdateClassify([]string{"levelPath"}); e != nil {
+		err = fmt.Errorf("更新分类层级路径失败, %v", e)
+		return
+	}
 	return
 }
 
@@ -622,6 +636,20 @@ func EditReportClassify(classifyId int, classifyName string, isRemind int, remin
 	}
 	//originName := item.ClassifyName
 
+	// 分类层级路径
+	if item.ParentId == 0 {
+		item.LevelPath = strconv.Itoa(item.Id)
+	}
+	if item.ParentId > 0 {
+		classifyParent, e := models.GetClassifyById(item.ParentId)
+		if e != nil {
+			errMsg = "父级分类有误"
+			err = fmt.Errorf("获取父级分类失败, %v", e)
+			return
+		}
+		item.LevelPath = fmt.Sprintf("%s,%d", classifyParent.LevelPath, item.Id)
+	}
+
 	// 重名校验
 	existName, e := models.GetClassifyByName(classifyName, item.ParentId)
 	if e != nil && !utils.IsErrNoRow(e) {
@@ -641,7 +669,7 @@ func EditReportClassify(classifyId int, classifyName string, isRemind int, remin
 	item.ModifyTime = time.Now().Local()
 
 	cols := make([]string, 0)
-	cols = append(cols, "ClassifyName", "IsRemind", "RemindTime", "ModifyTime")
+	cols = append(cols, "ClassifyName", "IsRemind", "RemindTime", "ModifyTime", "LevelPath")
 	err = item.UpdateClassify(cols)
 	if err != nil {
 		return