Quellcode durchsuchen

Merge branch 'bzq/306_report_classify' of eta_gn_server/eta_api into master

baoziqiang vor 1 Monat
Ursprung
Commit
02f7286c9e

+ 2 - 1
.gitignore

@@ -19,4 +19,5 @@ eta_api.exe
 eta_api.exe~
 /static/tmpFile/*
 etalogs/
-/.vscode
+/.vscode
+test/

+ 62 - 2
controllers/classify.go

@@ -3,6 +3,8 @@ package controllers
 import (
 	"encoding/json"
 	"eta_gn/eta_api/models"
+	"eta_gn/eta_api/models/system"
+	"eta_gn/eta_api/models/system/response"
 	"eta_gn/eta_api/services"
 	"eta_gn/eta_api/utils"
 	"fmt"
@@ -76,7 +78,7 @@ func (this *ClassifyController) Add() {
 	}
 
 	// 新增分类
-	err, errMsg, isSentEmail := services.AddReportClassify(req.ClassifyName, req.ParentId, req.ClassifyType, req.IsRemind, req.RemindTime)
+	err, errMsg, isSentEmail := services.AddReportClassify(req.ClassifyName, req.ParentId, req.ClassifyType, req.IsRemind, req.RemindTime, req.VisibleUserIds)
 	if err != nil {
 		br.Msg = "添加失败"
 		if errMsg != "" {
@@ -325,7 +327,7 @@ func (this *ClassifyController) Edit() {
 	}
 
 	// 修改分类
-	err, errMsg, isSentEmail := services.EditReportClassify(req.ClassifyId, req.ClassifyName, req.IsRemind, req.RemindTime)
+	err, errMsg, isSentEmail := services.EditReportClassify(req.ClassifyId, req.ClassifyName, req.IsRemind, req.RemindTime, req.VisibleUserIds)
 	if err != nil {
 		br.Msg = "修改失败"
 		if errMsg != "" {
@@ -576,6 +578,21 @@ func (this *ClassifyController) ListClassify() {
 	}
 	list := originList
 
+	visibleUsers, err := models.GetClassifyVisibleAll()
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取失败,Err:" + err.Error()
+		return
+	}
+	visibleUserMap := make(map[int][]int)
+
+	for _, v := range visibleUsers {
+		visibleUserMap[v.ClassifyId] = append(visibleUserMap[v.ClassifyId], v.AdminId)
+	}
+
+	for i, v := range list {
+		list[i].VisiableUsers = visibleUserMap[v.Id]
+	}
 	// 指定分类类型(上级中的分类类型可能与最下层的不一致,但是要把上级也一起取出来, 这需求...=_=!)
 	if classifyType > 0 {
 		list = make([]*models.ClassifyList, 0)
@@ -603,6 +620,11 @@ func (this *ClassifyController) ListClassify() {
 			if !utils.InArrayByInt(classifyIds, v.Id) {
 				continue
 			}
+			if visible, ok := visibleUserMap[v.Id]; ok {
+				if !utils.InArrayByInt(visible, this.SysUser.AdminId) {
+					continue
+				}
+			}
 			list = append(list, v)
 		}
 	}
@@ -639,6 +661,8 @@ func (this *ClassifyController) ListClassify() {
 	services.SortClassifyListBySortAndCreateTime(list)
 	// 接着转换结构
 	list = services.GetClassifyListTreeRecursive(list, 0)
+	// 过滤掉没有子目录的分类
+	list = services.RecursiveFilterNoChildTreeClassify(list)
 
 	resp := new(models.ClassifyListResp)
 	resp.List = list
@@ -990,3 +1014,39 @@ func (this *ClassifyController) ClassifyPermissionV2() {
 	br.Msg = "获取成功"
 	br.Data = resp
 }
+
+// AdminList
+// @Title 用户列表
+// @Description 用户列表
+// @Success 200 {object} company.PermissionSetResp
+// @router /user/list [get]
+func (this *ClassifyController) AdminList() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	adminList, err := system.GetSysAdminListAll()
+	if err != nil {
+		br.Msg = "获取管理员列表失败"
+		br.ErrMsg = "获取管理员列表失败, Err: " + err.Error()
+	}
+
+	list := make([]*response.AdminItem, 0)
+	for _, v := range adminList {
+		item := new(response.AdminItem)
+		item.AdminId = v.AdminId
+		item.AdminName = v.AdminName
+		item.RealName = v.RealName
+		list = append(list, item)
+	}
+
+	resp := new(response.AdminListResp)
+	resp.List = list
+
+	br.Data = resp
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+}

+ 40 - 3
controllers/ppt_report.go

@@ -7,10 +7,11 @@ import (
 	"eta_gn/eta_api/services"
 	"eta_gn/eta_api/utils"
 	"fmt"
-	"github.com/rdlucklib/rdluck_tools/paging"
 	"strconv"
 	"strings"
 	"time"
+
+	"github.com/rdlucklib/rdluck_tools/paging"
 )
 
 // ReportClassify
@@ -98,8 +99,18 @@ func (this *PptV2Controller) ReportClassify() {
 		classifyPpt[v.ClassifyId] = append(classifyPpt[v.ClassifyId], t)
 	}
 
-	resp := make([]*models.PptReportClassifyItem, 0)
+	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)
 	{
@@ -145,11 +156,17 @@ func (this *PptV2Controller) ReportClassify() {
 			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
@@ -250,7 +267,16 @@ func (this *PptV2Controller) ReportList() {
 			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 {
@@ -501,6 +527,17 @@ func (this *PptV2Controller) AuthList() {
 		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 {

+ 23 - 2
controllers/report_v2.go

@@ -12,11 +12,12 @@ import (
 	"eta_gn/eta_api/services/data"
 	"eta_gn/eta_api/utils"
 	"fmt"
-	"github.com/rdlucklib/rdluck_tools/paging"
 	"html"
 	"strconv"
 	"strings"
 	"time"
+
+	"github.com/rdlucklib/rdluck_tools/paging"
 )
 
 // ListReport
@@ -78,7 +79,6 @@ func (this *ReportController) ListReport() {
 
 	var condition string
 	var pars []interface{}
-
 	if keyWord != "" {
 		condition += ` AND (a.title LIKE ? OR a.admin_real_name LIKE ? ) `
 		pars = utils.GetLikeKeywordPars(pars, keyWord, 2)
@@ -139,6 +139,17 @@ func (this *ReportController) ListReport() {
 		pars = append(pars, this.SysUser.AdminId, this.SysUser.AdminId)
 	}
 
+	noVisibleClassifyIds, err := models.GetNoVisibleClassifyIdByAdminId(this.SysUser.AdminId)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取不可见分类id失败,Err:" + err.Error()
+		return
+	}
+	if len(noVisibleClassifyIds) > 0 {
+		condition += ` AND ( CASE WHEN a.classify_id_third > 0 THEN a.classify_id_third WHEN a.classify_id_second > 0 THEN a.classify_id_second ELSE a.classify_id_first END) NOT IN (?) `
+		pars = append(pars, noVisibleClassifyIds)
+	}
+
 	// 共享报告需要连表查询,所以需要单独写
 	if filterReportType == 2 {
 		total, err = models.GetReportListCountByGrant(condition, pars)
@@ -908,6 +919,16 @@ func (this *ReportController) AuthorizedListReport() {
 
 	var err error
 	var total int
+	noVisibleClassifyIds, err := models.GetNoVisibleClassifyIdByAdminId(this.SysUser.AdminId)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取不可见分类id失败,Err:" + err.Error()
+		return
+	}
+	if len(noVisibleClassifyIds) > 0 {
+		condition += ` AND ( CASE WHEN a.classify_id_third > 0 THEN a.classify_id_third WHEN a.classify_id_second > 0 THEN a.classify_id_second ELSE a.classify_id_first END) NOT IN (?) `
+		pars = append(pars, noVisibleClassifyIds)
+	}
 
 	orCondition := `AND ( (a.is_public_publish = ? AND a.state in (2,6)) or a.admin_id = ? `
 	pars = append(pars, 1, this.SysUser.AdminId)

+ 42 - 3
models/classify.go

@@ -4,9 +4,10 @@ import (
 	"eta_gn/eta_api/global"
 	"eta_gn/eta_api/utils"
 	"fmt"
-	"github.com/rdlucklib/rdluck_tools/paging"
 	"strings"
 	"time"
+
+	"github.com/rdlucklib/rdluck_tools/paging"
 )
 
 type Classify struct {
@@ -56,6 +57,7 @@ type ClassifyAddReq struct {
 	ClassifyName          string `description:"分类名称"`
 	ParentId              int    `description:"父级分类id,没有父级分类传0"`
 	ChartPermissionIdList []int  `description:"权限id数组"`
+	VisibleUserIds        []int  `description:"可见用户id数组"`
 	ClassifyType          int    `description:"分类类型:1-研报;2-PPT"`
 	IsRemind              int    `description:"是否开启提醒:0-关闭;1-开启"`
 	RemindTime            string `description:"提醒时间:可选00:00-23:59"`
@@ -74,8 +76,44 @@ func GetClassifyById(classifyId int) (item *Classify, err error) {
 }
 
 // 添加分类
-func AddClassify(item *Classify) (err error) {
-	err = global.DmSQL["rddp"].Create(item).Error
+func AddClassify(item *Classify, parentId int, visibleUserIds []int) (err error) {
+	tx := global.DmSQL["rddp"].Begin()
+	defer func() {
+		if err != nil {
+			tx.Rollback()
+			return
+		}
+		tx.Commit()
+	}()
+	err = tx.Create(item).Error
+	if err != nil {
+		return
+	}
+	// 添加可见用户
+	if len(visibleUserIds) > 0 {
+		addMappingList := make([]ClassifyVisible, 0)
+		now := time.Now()
+		for _, visibleUserId := range visibleUserIds {
+			addMapping := ClassifyVisible{
+				ClassifyId: item.Id,
+				AdminId:    visibleUserId,
+				CreateTime: now,
+			}
+			addMappingList = append(addMappingList, addMapping)
+		}
+		err = tx.CreateInBatches(addMappingList, utils.MultiAddNum).Error
+		if err != nil {
+			return
+		}
+	}
+	// 删除父级分类可见权限
+	if parentId > 0 {
+		sql := `DELETE FROM classify_visible WHERE classify_id=? `
+		err = tx.Exec(sql, parentId).Error
+		if err != nil {
+			return
+		}
+	}
 	return
 }
 
@@ -159,6 +197,7 @@ type ClassifyList struct {
 	ClassifyMenuList      []*ClassifyMenu `gorm:"-"`
 	ChartPermissionIdList []int           `gorm:"-"`                                   //`description:"绑定的权限ID"`
 	LevelPath             string          `gorm:"column:level_path" json:"level_path"` //`description:"分类的层级路径,英文逗号分隔"`
+	VisiableUsers         []int           `gorm:"-"`
 }
 
 type ClassifyItem struct {

+ 87 - 0
models/classify_visible.go

@@ -0,0 +1,87 @@
+package models
+
+import (
+	"eta_gn/eta_api/global"
+	"eta_gn/eta_api/utils"
+	"time"
+)
+
+type ClassifyVisible struct {
+	ClassifyVisibleId int       `gorm:"column:classify_visible_id;primary_key"`
+	ClassifyId        int       `gorm:"column:classify_id"`
+	AdminId           int       `gorm:"column:admin_id"`
+	CreateTime        time.Time `gorm:"column:create_time"`
+}
+
+func (ClassifyVisible) TableName() string {
+	return "classify_visible"
+}
+
+func GetClassifyVisibleAll() (items []*ClassifyVisible, err error) {
+	sql := "SELECT * FROM classify_visible"
+	err = global.DmSQL["rddp"].Raw(sql).Find(&items).Error
+	return
+}
+
+func GetNoVisibleClassifyIdByAdminId(adminId int) (classifyIds []int, err error) {
+	sql := `SELECT classify_id FROM classify_visible GROUP BY classify_id HAVING SUM(CASE WHEN admin_id =? THEN 1 ELSE 0 END) = 0`
+	err = global.DmSQL["rddp"].Raw(sql, adminId).Find(&classifyIds).Error
+	return
+}
+
+func ExtendClassifyVisible(parentId, classifyId int, adminIds []int) (err error) {
+	tx := global.DmSQL["rddp"].Begin()
+	defer func() {
+		if err != nil {
+			tx.Rollback()
+			return
+		}
+		tx.Commit()
+	}()
+	err = tx.Table(ClassifyVisible{}.TableName()).Where("classify_id =?", parentId).Delete(&ClassifyVisible{}).Error
+	insertList := make([]ClassifyVisible, 0, len(adminIds))
+	for _, adminId := range adminIds {
+		classifyVisible := ClassifyVisible{
+			ClassifyId: classifyId,
+			AdminId:    adminId,
+			CreateTime: time.Now(),
+		}
+		insertList = append(insertList, classifyVisible)
+	}
+	err = tx.CreateInBatches(insertList, utils.MultiAddNum).Error
+	return
+}
+
+func UpdateClassifyVisible(classifyId int, adminId []int) (err error) {
+	tx := global.DmSQL["rddp"].Begin()
+	defer func() {
+		if err != nil {
+			tx.Rollback()
+			return
+		}
+		tx.Commit()
+	}()
+	err = tx.Table(ClassifyVisible{}.TableName()).Where("classify_id =?", classifyId).Delete(&ClassifyVisible{}).Error
+	if err != nil {
+		return
+	}
+	if len(adminId) > 0 {
+		insertList := make([]ClassifyVisible, 0, len(adminId))
+		for _, admin := range adminId {
+			classifyVisible := ClassifyVisible{
+				ClassifyId: classifyId,
+				AdminId:    admin,
+				CreateTime: time.Now(),
+			}
+			insertList = append(insertList, classifyVisible)
+		}
+		err = tx.CreateInBatches(insertList, utils.MultiAddNum).Error
+	}
+	return
+}
+
+func GetClassifyVisibleUserIdByClassifyId(classifyId int) (classifyVisibles []int, err error) {
+	db := global.DmSQL["rddp"]
+	err = db.Table(ClassifyVisible{}.TableName()).Where("classify_id =?", classifyId).Pluck("admin_id", &classifyVisibles).Error
+	return
+}

+ 35 - 0
models/ppt_v2.go

@@ -348,12 +348,47 @@ func (m *PptV2) GetPageItemsByCondition(condition string, pars []interface{}, fi
 	return
 }
 
+func (m *PptV2) GetPageItemsByConditionWithAdminId(condition string, pars []interface{}, fieldArr []string, orderRule string, adminId, startSize, pageSize int) (items []*PptV2, err error) {
+	fields := strings.Join(fieldArr, ",")
+	if len(fieldArr) == 0 {
+		fields = `*`
+	}
+	order := `ORDER BY create_time DESC`
+	if orderRule != "" {
+		order = ` ORDER BY ` + orderRule
+	}
+	sql := fmt.Sprintf(`
+	SELECT %s FROM %s WHERE 1=1 AND classify_id NOT IN (
+		SELECT DISTINCT "classify_id" FROM "classify_visible") %s
+	UNION ALL
+	SELECT %s FROM %s WHERE 1=1 AND classify_id IN (
+		SELECT DISTINCT "classify_id" FROM "classify_visible" WHERE "admin_id" = %d) %s %s LIMIT ?,? `, fields, m.TableName(), condition, fields, m.TableName(), adminId, condition, order)
+	pars = append(pars, pars...)
+	pars = append(pars, startSize, pageSize)
+	err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
+	return
+}
+
 func (m *PptV2) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
 	sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
 	err = global.DmSQL["rddp"].Raw(sql, pars...).Scan(&count).Error
 	return
 }
 
+func (m *PptV2) GetCountByConditionWithAdminId(condition string, pars []interface{}, adminId int) (count int, err error) {
+	sql := fmt.Sprintf(`
+	SELECT (
+		(SELECT COUNT(1) FROM %s WHERE 1=1 AND classify_id NOT IN (
+			SELECT DISTINCT "classify_id" FROM "classify_visible") %s)
+		+
+		(SELECT COUNT(1) FROM %s WHERE 1=1 AND classify_id IN (
+			SELECT DISTINCT "classify_id" FROM "classify_visible" WHERE "admin_id" = %d) %s)
+	) AS count `, m.TableName(), condition, m.TableName(), adminId, condition)
+	pars = append(pars, pars...)
+	err = global.DmSQL["rddp"].Raw(sql, pars...).Scan(&count).Error
+	return
+}
+
 // 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", "admin_id", "admin_real_name", "collaborate_type", "collaborate_users",

+ 138 - 3
models/report.go

@@ -6,10 +6,11 @@ import (
 	"eta_gn/eta_api/global"
 	"eta_gn/eta_api/utils"
 	"fmt"
-	"github.com/rdlucklib/rdluck_tools/paging"
-	"gorm.io/gorm"
 	"strings"
 	"time"
+
+	"github.com/rdlucklib/rdluck_tools/paging"
+	"gorm.io/gorm"
 )
 
 // 报告状态
@@ -181,6 +182,34 @@ func GetReportListCountV1(condition string, pars []interface{}) (count int, err
 	return
 }
 
+// func GetReportListCountV1(condition string, pars []interface{}) (count int, err error) {
+// 	sql := `SELECT COUNT(1) AS count  FROM report as a
+// 	LEFT JOIN classify_visible c ON (
+// 		CASE
+// 			WHEN a.classify_id_third > 0 THEN a.classify_id_third
+// 			WHEN a.classify_id_second > 0 THEN a.classify_id_second
+// 			ELSE a.classify_id_first
+// 		END
+// 	) = c.classify_id AND c.admin_id =?
+// 	WHERE 1=1 AND (c.admin_id IS NULL OR c.admin_id =?) AND a.id NOT IN (
+// 		SELECT id FROM report ta
+// 		JOIN classify_visible tb ON (
+// 			CASE
+// 				WHEN ta.classify_id_third > 0 THEN ta.classify_id_third
+// 				WHEN ta.classify_id_second > 0 THEN ta.classify_id_second
+// 				ELSE ta.classify_id_first
+// 			END
+// 		) = tb.classify_id
+// 		GROUP BY ta."id"
+// 		HAVING SUM(CASE WHEN tb.admin_id = ? THEN 1 ELSE 0 END) = 0
+// 	) `
+// 	if condition != "" {
+// 		sql += condition
+// 	}
+// 	err = global.DmSQL["rddp"].Raw(sql, pars...).Scan(&count).Error
+// 	return
+// }
+
 // GetReportListV1
 // @Description: 获取普通报告列表的数据
 // @author: Roc
@@ -204,6 +233,38 @@ func GetReportListV1(condition string, pars []interface{}, startSize, pageSize i
 	return
 }
 
+// func GetReportListV1(condition string, pars []interface{}, startSize, pageSize int) (items []*ReportList, err error) {
+// 	sql := `SELECT * FROM report as a
+// 	LEFT JOIN classify_visible c ON (
+// 		CASE
+// 			WHEN a.classify_id_third > 0 THEN a.classify_id_third
+// 			WHEN a.classify_id_second > 0 THEN a.classify_id_second
+// 			ELSE a.classify_id_first
+// 		END
+// 	) = c.classify_id AND c.admin_id =?
+// 	WHERE 1=1 AND (c.admin_id IS NULL OR c.admin_id =?) AND a.id NOT IN (
+// 		SELECT id FROM report ta
+// 		JOIN classify_visible tb ON (
+// 			CASE
+// 				WHEN ta.classify_id_third > 0 THEN ta.classify_id_third
+// 				WHEN ta.classify_id_second > 0 THEN ta.classify_id_second
+// 				ELSE ta.classify_id_first
+// 			END
+// 		) = tb.classify_id
+// 		GROUP BY ta."id"
+// 		HAVING SUM(CASE WHEN tb.admin_id = ? THEN 1 ELSE 0 END) = 0
+// 	) `
+// 	if condition != "" {
+// 		sql += condition
+// 	}
+// 	// 排序:1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过
+// 	sql += `ORDER BY FIELD(state,3,1,4,5,6,2), modify_time DESC LIMIT ?,?`
+// 	pars = append(pars, startSize)
+// 	pars = append(pars, pageSize)
+// 	err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
+// 	return
+// }
+
 type ReportPvUv struct {
 	ReportId int
 	PvTotal  int
@@ -231,7 +292,7 @@ func GetReportPvUvByReportIdList(reportIdList []int) (items []ReportPvUv, err er
 func GetReportListCountByGrant(condition string, pars []interface{}) (count int, err error) {
 	sql := `SELECT a.id  FROM report as a 
     JOIN report_grant b on a.id=b.report_id 
- WHERE 1=1  `
+	WHERE 1=1  `
 	if condition != "" {
 		sql += condition
 	}
@@ -242,6 +303,39 @@ func GetReportListCountByGrant(condition string, pars []interface{}) (count int,
 	return
 }
 
+// func GetReportListCountByGrant(condition string, pars []interface{}) (count int, err error) {
+// 	sql := `SELECT a.id  FROM report as a
+//     JOIN report_grant b on a.id=b.report_id
+// 	LEFT JOIN classify_visible c ON (
+// 		CASE
+// 			WHEN a.classify_id_third > 0 THEN a.classify_id_third
+// 			WHEN a.classify_id_second > 0 THEN a.classify_id_second
+// 			ELSE a.classify_id_first
+// 		END
+// 	) = c.classify_id AND c.admin_id =?
+// 	WHERE 1=1 AND (c.admin_id IS NULL OR c.admin_id =?) AND a.id NOT IN (
+// 		SELECT id FROM report ta
+// 		JOIN classify_visible tb ON (
+// 			CASE
+// 				WHEN ta.classify_id_third > 0 THEN ta.classify_id_third
+// 				WHEN ta.classify_id_second > 0 THEN ta.classify_id_second
+// 				ELSE ta.classify_id_first
+// 			END
+// 		) = tb.classify_id
+// 		GROUP BY ta."id"
+// 		HAVING SUM(CASE WHEN tb.admin_id = ? THEN 1 ELSE 0 END) = 0
+// 	) `
+// 	if condition != "" {
+// 		sql += condition
+// 	}
+// 	sql += " GROUP BY a.id "
+
+// 	sql = `SELECT COUNT(1) AS count  FROM (` + sql + `) d`
+
+// 	err = global.DmSQL["rddp"].Raw(sql, pars...).Scan(&count).Error
+// 	return
+// }
+
 // GetReportListByGrant
 // @Description: 获取共享报告列表的数据
 // @author: Roc
@@ -274,6 +368,47 @@ func GetReportListByGrant(condition string, pars []interface{}, startSize, pageS
 	return
 }
 
+// func GetReportListByGrant(condition string, pars []interface{}, startSize, pageSize int) (items []*ReportList, err error) {
+// 	sql := `SELECT a.id,a.add_type,a.classify_id_first,a.classify_name_first,a.classify_id_second,a.classify_name_second,a.title,a.abstract,a.author,a.frequency,a.create_time,a.modify_time,a.state,a.publish_time,a.pre_publish_time,a.stage,a.msg_is_send,a.pre_msg_send,a.video_url,a.video_name,a.video_play_seconds,a.report_code,a.video_size,a.report_version,a.ths_msg_is_send,a.has_chapter,a.chapter_type,a.old_report_id,a.msg_send_time,a.admin_id,a.admin_real_name,a.approve_time,a.approve_id,a.detail_img_url,a.detail_pdf_url,a.last_modify_admin_id,a.last_modify_admin_name,a.content_modify_time,a.pv,a.uv,a.canvas_color,a.need_splice,a.head_resource_id,a.end_resource_id,a.classify_id_third,a.classify_name_third,a.collaborate_type,a.report_layout,a.is_public_publish,a.report_create_time,a.inherit_report_id,a.voice_generate_type,a.report_source FROM report as a JOIN report_grant b on a.id = b.report_id
+// 	LEFT JOIN classify_visible c ON (
+// 		CASE
+// 			WHEN a.classify_id_third > 0 THEN a.classify_id_third
+// 			WHEN a.classify_id_second > 0 THEN a.classify_id_second
+// 			ELSE a.classify_id_first
+// 		END
+// 	) = c.classify_id AND c.admin_id =?
+// 	WHERE 1=1 AND (c.admin_id IS NULL OR c.admin_id =?) AND a.id NOT IN (
+// 		SELECT id FROM report ta
+// 		JOIN classify_visible tb ON (
+// 			CASE
+// 				WHEN ta.classify_id_third > 0 THEN ta.classify_id_third
+// 				WHEN ta.classify_id_second > 0 THEN ta.classify_id_second
+// 				ELSE ta.classify_id_first
+// 			END
+// 		) = tb.classify_id
+// 		GROUP BY ta."id"
+// 		HAVING SUM(CASE WHEN tb.admin_id = ? THEN 1 ELSE 0 END) = 0
+// 	) `
+// 	if condition != "" {
+// 		sql += condition
+// 	}
+// 	// 排序:1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过
+// 	sql += ` GROUP BY a.id,a.add_type,a.classify_id_first,a.classify_name_first,a.classify_id_second,a.classify_name_second,a.title,a.abstract,a.author,a.frequency,a.create_time,a.modify_time,a.state,a.publish_time,a.pre_publish_time,a.stage,a.msg_is_send,a.pre_msg_send,a.video_url,a.video_name,a.video_play_seconds,a.report_code,a.video_size,a.report_version,a.ths_msg_is_send,a.has_chapter,a.chapter_type,a.old_report_id,a.msg_send_time,a.admin_id,a.admin_real_name,a.approve_time,a.approve_id,a.detail_img_url,a.detail_pdf_url,a.last_modify_admin_id,a.last_modify_admin_name,a.content_modify_time,a.pv,a.uv,a.canvas_color,a.need_splice,a.head_resource_id,a.end_resource_id,a.classify_id_third,a.classify_name_third,a.collaborate_type,a.report_layout,a.is_public_publish,a.report_create_time,a.inherit_report_id,a.voice_generate_type,a.report_source
+
+// 		ORDER BY CASE a."state"
+//         WHEN 3 THEN 1
+//         WHEN 1 THEN 2
+//         WHEN 4 THEN 3
+//         WHEN 5 THEN 4
+//         WHEN 6 THEN 5
+//         ELSE 6
+//     END, a.modify_time DESC LIMIT ?,?`
+// 	pars = append(pars, startSize)
+// 	pars = append(pars, pageSize)
+// 	err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
+// 	return
+// }
+
 func GetReportListCount(condition string, pars []interface{}) (count int, err error) {
 	sql := `SELECT COUNT(1) AS count  FROM report WHERE 1=1 `
 	if condition != "" {

+ 9 - 0
models/system/response/sys_role_admin.go

@@ -40,3 +40,12 @@ type EnglishAuthRoleDetailResp struct {
 	RoleTypeCode string `description:"角色类型编码"`
 	AuthOk       bool   `description:"是否有权限"`
 }
+
+type AdminListResp struct {
+	List []*AdminItem
+}
+type AdminItem struct {
+	AdminId   int
+	AdminName string `description:"系统用户名称"`
+	RealName  string `description:"系统用户姓名"`
+}

+ 7 - 0
models/system/sys_admin.go

@@ -354,3 +354,10 @@ func GetSysAdminList(condition string, pars []interface{}, fieldArr []string, or
 	err = global.DEFAULT_DmSQL.Raw(sql, pars...).Find(&items).Error
 	return
 }
+
+// GetSysAdminListAll 获取所有admin列表
+func GetSysAdminListAll() (items []*Admin, err error) {
+	sql := `SELECT admin_id, admin_name, real_name  FROM "admin" `
+	err = global.DEFAULT_DmSQL.Raw(sql).Find(&items).Error
+	return
+}

+ 9 - 0
routers/commentsRouter.go

@@ -6460,6 +6460,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta_gn/eta_api/controllers:ClassifyController"] = append(beego.GlobalControllerRouter["eta_gn/eta_api/controllers:ClassifyController"],
+        beego.ControllerComments{
+            Method: "AdminList",
+            Router: `/user/list`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta_gn/eta_api/controllers:CompanyPermissionController"] = append(beego.GlobalControllerRouter["eta_gn/eta_api/controllers:CompanyPermissionController"],
         beego.ControllerComments{
             Method: "List",

+ 44 - 5
services/classify.go

@@ -193,7 +193,7 @@ func moveReportClassify(classifyInfo, prevClassify, nextClassify *models.Classif
 // @return err error
 // @return errMsg string
 // @return isSendEmail bool
-func AddReportClassify(classifyName string, parentId int, classifyType, isRemind int, remindTime string) (err error, errMsg string, isSendEmail bool) {
+func AddReportClassify(classifyName string, parentId int, classifyType, isRemind int, remindTime string, visibleUserIds []int) (err error, errMsg string, isSendEmail bool) {
 	isSendEmail = true
 	errMsg = `添加失败`
 	item, err := models.GetClassifyByName(classifyName, parentId)
@@ -276,8 +276,7 @@ func AddReportClassify(classifyName string, parentId int, classifyType, isRemind
 	classify.ClassifyType = classifyType
 	classify.IsRemind = isRemind
 	classify.RemindTime = remindTime
-
-	err = models.AddClassify(classify)
+	err = models.AddClassify(classify, parentId, visibleUserIds)
 	if err != nil {
 		return
 	}
@@ -297,8 +296,12 @@ func AddReportClassify(classifyName string, parentId int, classifyType, isRemind
 
 			// 继承父级分类审批流
 			//go inheritReportApproveFlow(parentClassifyItem, classify)
-
 			moveReportByAddClassify(parentClassifyItem, classify)
+			// err = models.UpdateClassifyVisible(classify.Id, visibleUserIds)
+			// if err != nil {
+			// 	errMsg = "添加分类可见权限失败"
+			// 	return
+			// }
 		}
 	}
 
@@ -317,6 +320,21 @@ func AddReportClassify(classifyName string, parentId int, classifyType, isRemind
 	return
 }
 
+// inheritParentClassifyVisibleUser 继承父类的可见用户
+// func inheritParentClassifyVisibleUser(parentClassifyId, currClassifyId int) (err error) {
+// 	parentUserIds, err := models.GetClassifyVisibleUserIdByClassifyId(parentClassifyId)
+// 	if err != nil {
+// 		return
+// 	}
+// 	currUserIds, err := models.GetClassifyVisibleUserIdByClassifyId(currClassifyId)
+// 	if err != nil {
+// 		return
+// 	}
+// 	parentUserIds = append(parentUserIds, currUserIds...)
+// 	err = models.ExtendClassifyVisible(parentClassifyId, currClassifyId, parentUserIds)
+// 	return
+// }
+
 // checkClassifyApprove
 // @Description: 判断分类是否存在待操作的审批单
 // @author: Roc
@@ -660,7 +678,7 @@ func inheritReportApproveFlow(parentClassifyItem, currClassifyItem *models.Class
 // @return err error
 // @return errMsg string
 // @return isSendEmail bool
-func EditReportClassify(classifyId int, classifyName string, isRemind int, remindTime string) (err error, errMsg string, isSendEmail bool) {
+func EditReportClassify(classifyId int, classifyName string, isRemind int, remindTime string, visibleUserIds []int) (err error, errMsg string, isSendEmail bool) {
 	isSendEmail = true
 	errMsg = `修改失败`
 
@@ -713,6 +731,11 @@ func EditReportClassify(classifyId int, classifyName string, isRemind int, remin
 	if err != nil {
 		return
 	}
+	err = models.UpdateClassifyVisible(item.Id, visibleUserIds)
+	if err != nil {
+		errMsg = "更新可见权限失败"
+		return
+	}
 	return
 }
 
@@ -791,6 +814,22 @@ func GetClassifyListTreeRecursive(list []*models.ClassifyList, parentId int) []*
 	return res
 }
 
+// RecursiveFilterNoChildTreeClassify 递归过滤没有子分类的分类
+func RecursiveFilterNoChildTreeClassify(list []*models.ClassifyList) []*models.ClassifyList {
+	res := make([]*models.ClassifyList, 0)
+	for _, v := range list {
+		v.Child = RecursiveFilterNoChildTreeClassify(v.Child)
+		if len(v.Child) == 0 && v.HasChild == 1 {
+			continue
+		}
+		if len(v.Child) == 0 {
+			v.Child = nil
+		}
+		res = append(res, v)
+	}
+	return res
+}
+
 // BySortAndCreateTime 用来排序,先按Sort字段升序排序,若Sort相同,则按照CreateTime字段升序排序。
 type BySortAndCreateTime []*models.ClassifyList
 

+ 15 - 0
services/ppt_report.go

@@ -30,6 +30,21 @@ func GetPptReportClassifyTreeRecursive(list []*models.Classify, parentId int, cl
 	return res
 }
 
+func RecursiveFilterPptNoChildTreeClassify(list []*models.PptReportClassifyItem) []*models.PptReportClassifyItem {
+	res := make([]*models.PptReportClassifyItem, 0)
+	for _, v := range list {
+		v.Child = RecursiveFilterPptNoChildTreeClassify(v.Child)
+		if len(v.Child) == 0 && v.HasChild == 1 {
+			continue
+		}
+		if len(v.Child) == 0 {
+			v.Child = nil
+		}
+		res = append(res, v)
+	}
+	return res
+}
+
 // 更新分类报告计数加个锁
 var classifyReportNumLock sync.Mutex