Roc 7 months ago
parent
commit
e4d0221a58
6 changed files with 88 additions and 37 deletions
  1. 46 2
      controllers/report_v2.go
  2. 4 3
      models/report.go
  3. 1 1
      models/report_chapter.go
  4. 6 0
      services/classify.go
  5. 0 31
      services/report.go
  6. 31 0
      services/report_v2.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 {

+ 4 - 3
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
@@ -249,12 +250,12 @@ func GetReportListCountByGrant(condition string, pars []interface{}) (count int,
 func GetReportListByGrant(condition string, pars []interface{}, startSize, pageSize int) (items []*ReportList, err error) {
 	o := orm.NewOrmUsingDB("rddp")
 
-	sql := `SELECT * FROM report as a JOIN report_grant b on a.id = b.report_id  WHERE 1=1  `
+	sql := `SELECT a.* FROM report as a JOIN report_grant b on a.id = b.report_id  WHERE 1=1  `
 	if condition != "" {
 		sql += condition
 	}
 	// 排序:1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过
-	sql += ` GROUP BY a.id ORDER BY FIELD(state,3,1,4,5,6,2), modify_time DESC LIMIT ?,?`
+	sql += ` GROUP BY a.id ORDER BY FIELD(state,3,1,4,5,6,2), a.modify_time DESC LIMIT ?,?`
 	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
 	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
 	}

+ 6 - 0
services/classify.go

@@ -560,6 +560,12 @@ func inheritReportChapterType(parentClassifyId, currClassifyId int) (err error)
 	obj := models.ReportChapterType{}
 	err = obj.MultiCreate(addList)
 
+	// 修改CRM权限
+	go func() {
+		var syncReq ChapterTypeSyncReq
+		_, _ = ReportChapterTypeSync(&syncReq)
+	}()
+
 	return
 }
 

+ 0 - 31
services/report.go

@@ -307,37 +307,6 @@ func updateReportChapterEsByChapter(chapterInfo *models.ReportChapter) (err erro
 	return
 }
 
-// DeleteReportAndChapter 删除报告及章节
-func DeleteReportAndChapter(reportId int) (err error) {
-	reportInfo, err := models.GetReportByReportId(reportId)
-	if err != nil {
-		err = errors.New("报告信息有误, Err: " + err.Error())
-		return
-	}
-	if reportInfo.State == 2 {
-		err = errors.New("报告已发布,不可删除")
-		return
-	}
-	// 更新ES
-	_ = UpdateReportEs(reportId, 1)
-	// 删除
-	if reportInfo.HasChapter == 1 && (reportInfo.ChapterType == utils.REPORT_TYPE_DAY || reportInfo.ChapterType == utils.REPORT_TYPE_WEEK) {
-		err = models.DeleteDayWeekReportAndChapter(reportId)
-	} else {
-		err = models.DeleteReport(reportId)
-	}
-	if err != nil {
-		err = errors.New("删除失败, Err: " + err.Error())
-		return
-	}
-	// 重置PPT关联报告
-	go func() {
-		_ = ResetPPTReport(reportId, false)
-	}()
-
-	return
-}
-
 // 替换报告内容中的base64图片
 func replaceReportBase64ToImg(content string) (newContent string, err error) {
 	if content == "" {

+ 31 - 0
services/report_v2.go

@@ -1257,6 +1257,37 @@ func PublishChapterReport(reportInfo *models.Report, reportUrl string, sysUser *
 	return
 }
 
+// DeleteReportAndChapter 删除报告及章节
+func DeleteReportAndChapter(reportId int) (err error) {
+	reportInfo, err := models.GetReportByReportId(reportId)
+	if err != nil {
+		err = errors.New("报告信息有误, Err: " + err.Error())
+		return
+	}
+	if reportInfo.State == 2 {
+		err = errors.New("报告已发布,不可删除")
+		return
+	}
+	// 更新ES
+	_ = UpdateReportEs(reportId, 1)
+	// 删除
+	if reportInfo.HasChapter == 1 {
+		err = models.DeleteDayWeekReportAndChapter(reportId)
+	} else {
+		err = models.DeleteReport(reportId)
+	}
+	if err != nil {
+		err = errors.New("删除失败, Err: " + err.Error())
+		return
+	}
+	// 重置PPT关联报告
+	go func() {
+		_ = ResetPPTReport(reportId, false)
+	}()
+
+	return
+}
+
 // getMinClassify
 // @Description: 获取最小分类ID
 // @author: Roc