فهرست منبع

fix:报告权限

Roc 7 ماه پیش
والد
کامیت
49b9d6e99a
3فایلهای تغییر یافته به همراه49 افزوده شده و 4 حذف شده
  1. 46 2
      controllers/report_v2.go
  2. 2 1
      models/report.go
  3. 1 1
      models/report_chapter.go

+ 46 - 2
controllers/report_v2.go

@@ -173,11 +173,11 @@ func (this *ReportController) ListReport() {
 	if listLen > 0 {
 		pvMap := make(map[int]int)
 		uvMap := make(map[int]int)
-		reportIdArr := make([]string, 0)
+		reportIdArr := make([]int, 0)
 		syncReportIdArr := make([]string, 0)      // 同步过来的报告IDs
 		oldAndNewReportIdMap := make(map[int]int) // 旧报告和新报告的id对应关系
 		for i := 0; i < listLen; i++ {
-			reportIdArr = append(reportIdArr, strconv.Itoa(list[i].Id))
+			reportIdArr = append(reportIdArr, list[i].Id)
 			if list[i].OldReportId > 0 && list[i].ReportLayout == 1 {
 				syncReportIdArr = append(syncReportIdArr, strconv.Itoa(list[i].OldReportId))
 				oldAndNewReportIdMap[list[i].OldReportId] = list[i].Id
@@ -249,6 +249,50 @@ func (this *ReportController) ListReport() {
 			list[i].Pv = pvMap[list[i].Id]
 			list[i].Uv = uvMap[list[i].Id]
 		}
+
+		// 多人协作的协作报告,需要判断是否可编辑
+		{
+			grantObj := report.ReportGrant{}
+			grantList, err := grantObj.GetGrantListByIdList(reportIdArr)
+			if err != nil {
+				br.Msg = "获取失败"
+				br.ErrMsg = "获取报告授权失败,Err:" + err.Error()
+				return
+			}
+
+			//grantMap := make(map[报告id]map[用户id]bool)
+			grantMap := make(map[int]map[int]bool)
+			for _, v := range grantList {
+				grantUserMap, ok := grantMap[v.ReportId]
+				if !ok {
+					grantUserMap = make(map[int]bool)
+				}
+				grantUserMap[v.AdminId] = true
+			}
+
+			for i, item := range list {
+				if item.AdminId == this.SysUser.AdminId {
+					list[i].HasAuth = true
+					continue
+				}
+
+				// 查找授权
+				var hasAuth bool
+				grantUserMap, ok := grantMap[item.Id]
+
+				// 如果报告根本没有授权用户,说明没有授权当前用户
+				if !ok {
+					continue
+				}
+				_, ok = grantUserMap[this.SysUser.AdminId]
+				list[i].HasAuth = hasAuth
+				// 如果报告关联用户找到,说明有授权当前用户
+				if ok {
+					list[i].HasAuth = true
+				}
+			}
+
+		}
 	}
 
 	for _, item := range list {

+ 2 - 1
models/report.go

@@ -123,6 +123,7 @@ type ReportList struct {
 	OldReportId        int                       `description:"research_report表ID, 大于0则表示该报告为老后台同步过来的"`
 	MsgSendTime        string                    `description:"模版消息发送时间"`
 	CanEdit            bool                      `description:"是否可编辑"`
+	HasAuth            bool                      `description:"是否可操作"`
 	Editor             string                    `description:"编辑人"`
 	AdminId            int                       `description:"创建者账号"`
 	AdminRealName      string                    `description:"创建者姓名"`
@@ -201,7 +202,7 @@ type ReportPvUv struct {
 	UvTotal  int
 }
 
-func GetReportPvUvByReportIdList(reportIdList []string) (items []ReportPvUv, err error) {
+func GetReportPvUvByReportIdList(reportIdList []int) (items []ReportPvUv, err error) {
 	num := len(reportIdList)
 	if num <= 0 {
 		return

+ 1 - 1
models/report_chapter.go

@@ -304,7 +304,7 @@ func GetReportChapterVideoList(reportId int) (list []*ReportChapterVideoList, er
 }
 
 // GetReportChapterVideoListByReportIds 根据报告ID集合获取报告章节音频列表
-func GetReportChapterVideoListByReportIds(reportIds []string) (list []*ReportChapterVideoList, err error) {
+func GetReportChapterVideoListByReportIds(reportIds []int) (list []*ReportChapterVideoList, err error) {
 	if len(reportIds) == 0 {
 		return
 	}