|
@@ -1698,3 +1698,214 @@ func EditChapterBaseInfoAndPermission(reportInfo *models.Report, reportChapterIn
|
|
|
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func DelChapter(reportInfo *models.Report, reportChapterInfo *models.ReportChapter, title string, permissionIdList []int, adminIdList []int) (err error, errMsg string) {
|
|
|
+ errMsg = "删除失败"
|
|
|
+
|
|
|
+ if reportInfo.State == 2 {
|
|
|
+ errMsg = "该报告已发布,不允许删除"
|
|
|
+ err = errors.New(errMsg)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ updateCols := make([]string, 0)
|
|
|
+
|
|
|
+ if title != `` {
|
|
|
+ reportChapterInfo.Title = title
|
|
|
+ reportChapterInfo.ModifyTime = time.Now()
|
|
|
+ updateCols = append(updateCols, "Title", "ModifyTime")
|
|
|
+ reportChapterInfo.UpdateChapter(updateCols)
|
|
|
+ }
|
|
|
+
|
|
|
+ reportGrantObj := report.ReportGrant{}
|
|
|
+ chapterGrantObj := report.ReportChapterGrant{}
|
|
|
+ chapterPermissionObj := report.ReportChapterPermissionMapping{}
|
|
|
+
|
|
|
+
|
|
|
+ addChapterAdminList := make([]*report.ReportChapterGrant, 0)
|
|
|
+
|
|
|
+ delReportChapterGrantIdList := make([]int, 0)
|
|
|
+
|
|
|
+
|
|
|
+ {
|
|
|
+
|
|
|
+ chapterGrantList, tmpErr := chapterGrantObj.GetGrantListById(reportChapterInfo.ReportChapterId)
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = tmpErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ currChapterAdminMap := make(map[int]*report.ReportChapterGrant)
|
|
|
+
|
|
|
+ delChapterAdminMap := make(map[int]*report.ReportChapterGrant)
|
|
|
+ for _, v := range chapterGrantList {
|
|
|
+ currChapterAdminMap[v.AdminId] = v
|
|
|
+ delChapterAdminMap[v.AdminId] = v
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, adminId := range adminIdList {
|
|
|
+ _, ok := currChapterAdminMap[adminId]
|
|
|
+
|
|
|
+ if ok {
|
|
|
+ delete(delChapterAdminMap, adminId)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
+ addChapterAdminList = append(addChapterAdminList, &report.ReportChapterGrant{
|
|
|
+
|
|
|
+ ReportChapterId: reportChapterInfo.ReportChapterId,
|
|
|
+ AdminId: adminId,
|
|
|
+ CreateTime: time.Now(),
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ for _, v := range delChapterAdminMap {
|
|
|
+ delReportChapterGrantIdList = append(delReportChapterGrantIdList, v.GrantId)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ otherChapterAdminMap := make(map[int]bool)
|
|
|
+ {
|
|
|
+
|
|
|
+ reportChapterIdList, tmpErr := models.GetReportChapterIdList(reportInfo.Id)
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = tmpErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(reportChapterIdList) > 0 {
|
|
|
+ list, tmpErr := chapterGrantObj.GetGrantListByIdList(reportChapterIdList)
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = tmpErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, v := range list {
|
|
|
+
|
|
|
+ if v.ReportChapterId == reportChapterInfo.ReportChapterId {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ otherChapterAdminMap[v.AdminId] = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ addReportAdminList := make([]*report.ReportGrant, 0)
|
|
|
+
|
|
|
+ delReportGrantIdList := make([]int, 0)
|
|
|
+
|
|
|
+
|
|
|
+ {
|
|
|
+
|
|
|
+ reportGrantList, tmpErr := reportGrantObj.GetGrantListById(reportInfo.Id)
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = tmpErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ currReportAdminMap := make(map[int]*report.ReportGrant)
|
|
|
+
|
|
|
+ delReportAdminMap := make(map[int]*report.ReportGrant)
|
|
|
+ for _, v := range reportGrantList {
|
|
|
+ currReportAdminMap[v.AdminId] = v
|
|
|
+ delReportAdminMap[v.AdminId] = v
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ for _, tmpAdminId := range adminIdList {
|
|
|
+ _, ok := currReportAdminMap[tmpAdminId]
|
|
|
+
|
|
|
+ if ok {
|
|
|
+ delete(delReportAdminMap, tmpAdminId)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ addReportAdminList = append(addReportAdminList, &report.ReportGrant{
|
|
|
+
|
|
|
+ ReportId: reportInfo.Id,
|
|
|
+ AdminId: tmpAdminId,
|
|
|
+ CreateTime: time.Now(),
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ for _, tmpAdminId := range delReportChapterGrantIdList {
|
|
|
+ _, ok := otherChapterAdminMap[tmpAdminId]
|
|
|
+
|
|
|
+ if ok {
|
|
|
+ delete(delReportAdminMap, tmpAdminId)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ for _, v := range delReportAdminMap {
|
|
|
+ delReportGrantIdList = append(delReportGrantIdList, v.GrantId)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ addChapterPermissionList := make([]*report.ReportChapterPermissionMapping, 0)
|
|
|
+
|
|
|
+ delChapterPermissionMappingIdList := make([]int, 0)
|
|
|
+
|
|
|
+
|
|
|
+ {
|
|
|
+
|
|
|
+ chapterPermissionList, tmpErr := chapterPermissionObj.GetPermissionListById(reportChapterInfo.ReportChapterId)
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = tmpErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ currChapterPermissionMap := make(map[int]*report.ReportChapterPermissionMapping)
|
|
|
+
|
|
|
+ delChapterPermissionMap := make(map[int]*report.ReportChapterPermissionMapping)
|
|
|
+ for _, v := range chapterPermissionList {
|
|
|
+ currChapterPermissionMap[v.ChartPermissionId] = v
|
|
|
+ delChapterPermissionMap[v.ChartPermissionId] = v
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, permissionId := range permissionIdList {
|
|
|
+ _, ok := currChapterPermissionMap[permissionId]
|
|
|
+
|
|
|
+ if ok {
|
|
|
+ delete(delChapterPermissionMap, permissionId)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
+ addChapterPermissionList = append(addChapterPermissionList, &report.ReportChapterPermissionMapping{
|
|
|
+
|
|
|
+ ReportChapterId: reportChapterInfo.ReportChapterId,
|
|
|
+ ChartPermissionId: permissionId,
|
|
|
+ CreateTime: time.Now(),
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ for _, v := range delChapterPermissionMap {
|
|
|
+ delChapterPermissionMappingIdList = append(delChapterPermissionMappingIdList, v.ReportChapterPermissionMappingId)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ err = models.EditChapterBaseInfoAndPermission(reportChapterInfo, updateCols, addReportAdminList, addChapterAdminList, addChapterPermissionList, delReportGrantIdList, delReportChapterGrantIdList, delChapterPermissionMappingIdList)
|
|
|
+
|
|
|
+ return
|
|
|
+}
|