Browse Source

fix:创建章节报告时,自动关联配置中的品种

Roc 8 months ago
parent
commit
72f45eb5b1
2 changed files with 25 additions and 8 deletions
  1. 13 1
      models/report_v2.go
  2. 12 7
      services/report_v2.go

+ 13 - 1
models/report_v2.go

@@ -73,6 +73,18 @@ func AddReportAndChapter(reportItem *Report, allGrantUserList []*report.ReportGr
 				}
 			}
 
+			// 新增报告章节关联的品种
+			if len(addReportChapter.GrantPermissionList) > 0 {
+				permissionList := addReportChapter.GrantPermissionList
+				for _, v := range permissionList {
+					v.ReportChapterId = chapterItem.ReportChapterId
+				}
+				_, err = to.InsertMulti(500, permissionList)
+				if err != nil {
+					return
+				}
+			}
+
 		}
 	}
 
@@ -170,7 +182,7 @@ func AddChapterBaseInfoAndPermission(reportChapterInfo *ReportChapter, addReport
 		}
 	}
 
-	// 新增报告章节的品种配置
+	// 新增报告章节关联的品种配置
 	if len(addChapterPermissionMap) > 0 {
 		for k, _ := range addChapterPermissionMap {
 			addChapterPermissionMap[k].ReportChapterId = reportChapterInfo.ReportChapterId

+ 12 - 7
services/report_v2.go

@@ -337,17 +337,22 @@ func getAddChapter(reportInfo *models.Report, minClassifyId, inheritReportId int
 			err = fmt.Errorf("获取章节类型权限列表失败, Err: " + e.Error())
 			return
 		}
+		hasPermissionMap := make(map[string]bool)
 		for _, v := range mappingList {
 			tmpChapterTypePermissionList, ok := currChapterTypePermissionListMap[v.ReportChapterTypeId]
 			if !ok {
 				tmpChapterTypePermissionList = make([]*report.ReportChapterPermissionMapping, 0)
 			}
-			currChapterTypePermissionListMap[v.ReportChapterTypeId] = append(tmpChapterTypePermissionList, &report.ReportChapterPermissionMapping{
-				ReportChapterPermissionMappingId: 0,
-				ReportChapterId:                  0,
-				ChartPermissionId:                v.ChartPermissionId,
-				CreateTime:                       time.Now(),
-			})
+			key := fmt.Sprint(v.ReportChapterTypeId, "-", v.ChartPermissionId)
+			if _, has := hasPermissionMap[key]; !has {
+				hasPermissionMap[key] = true
+				currChapterTypePermissionListMap[v.ReportChapterTypeId] = append(tmpChapterTypePermissionList, &report.ReportChapterPermissionMapping{
+					ReportChapterPermissionMappingId: 0,
+					ReportChapterId:                  0,
+					ChartPermissionId:                v.ChartPermissionId,
+					CreateTime:                       time.Now(),
+				})
+			}
 		}
 	}
 
@@ -534,7 +539,7 @@ func getAddChapter(reportInfo *models.Report, minClassifyId, inheritReportId int
 			chapterItem.ReportCreateTime = time.Now()
 
 			// 默认配置:从当前分类下配置的章节类型id所关联的品种列表
-			tmpChapterPermissionList, ok = currChapterTypePermissionListMap[v.TypeId]
+			tmpChapterPermissionList, ok = currChapterTypePermissionListMap[typeItem.ReportChapterTypeId]
 			if !ok {
 				tmpChapterPermissionList = make([]*report.ReportChapterPermissionMapping, 0)
 			}