123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- package services
- import (
- "eta_gn/eta_api/models"
- "eta_gn/eta_api/models/report"
- "eta_gn/eta_api/utils"
- "fmt"
- "time"
- )
- func MoveReportChapter(req *models.ReportChapterMoveReq) (err error, errMsg string) {
- ob := new(models.ReportChapter)
- reportChapterId := req.ReportChapterId
- prevReportChapterId := req.PrevReportChapterId
- nextReportChapterId := req.NextReportChapterId
- var (
- reportChapter *models.ReportChapter
- prevReportChapter *models.ReportChapter
- nextReportChapter *models.ReportChapter
- prevSort int
- nextSort int
- )
- reportChapter, err = ob.GetReportChapterById(reportChapterId)
- if err != nil {
- if utils.IsErrNoRow(err) {
- errMsg = "当前报告章节不存在"
- err = fmt.Errorf("获取报告章节信息失败,Err:" + err.Error())
- return
- }
- errMsg = "移动失败"
- err = fmt.Errorf("获取章节信息失败,Err:" + err.Error())
- return
- } else if reportChapter.ReportChapterId == 0 {
- errMsg = "当前报告章节不存在"
- err = fmt.Errorf("获取报告章节信息失败,Err:" + err.Error())
- return
- }
- if prevReportChapterId > 0 {
- prevReportChapter, err = ob.GetReportChapterById(prevReportChapterId)
- if err != nil {
- errMsg = "移动失败"
- err = fmt.Errorf("获取上一个兄弟节点分类信息失败,Err:" + err.Error())
- return
- }
- prevSort = prevReportChapter.Sort
- }
- if nextReportChapterId > 0 {
- nextReportChapter, err = ob.GetReportChapterById(nextReportChapterId)
- if err != nil {
- errMsg = "移动失败"
- err = fmt.Errorf("获取下一个兄弟节点分类信息失败,Err:" + err.Error())
- return
- }
- nextSort = nextReportChapter.Sort
- }
- err, errMsg = moveReportChapter(reportChapter, prevReportChapter, nextReportChapter, reportChapter.ReportId, prevSort, nextSort)
- return
- }
- func moveReportChapter(reportChapter, prevReportChapter, nextReportChapter *models.ReportChapter, reportId int, prevSort, nextSort int) (err error, errMsg string) {
- ob := new(models.ReportChapter)
- updateCol := make([]string, 0)
- if prevSort > 0 {
- if nextSort > 0 {
- if prevSort == nextSort || prevSort == reportChapter.Sort {
- updateSortStr := `sort + 2`
- if prevReportChapter != nil {
- _ = ob.UpdateReportChapterSortByReportId(reportId, prevReportChapter.ReportChapterId, prevReportChapter.Sort, updateSortStr)
- } else {
- _ = ob.UpdateReportChapterSortByReportId(reportId, 0, prevSort, updateSortStr)
- }
- } else {
- if nextSort-prevSort == 1 {
- updateSortStr := `sort + 1`
- if prevReportChapter != nil {
- _ = ob.UpdateReportChapterSortByReportId(reportId, prevReportChapter.ReportChapterId, prevSort, updateSortStr)
- } else {
- _ = ob.UpdateReportChapterSortByReportId(reportId, 0, prevSort, updateSortStr)
- }
- }
- }
- }
- reportChapter.Sort = prevSort + 1
- reportChapter.ModifyTime = time.Now()
- updateCol = append(updateCol, "Sort", "ModifyTime")
- } else if prevReportChapter == nil && nextReportChapter == nil {
- var maxSort int
- maxSort, err = ob.GetMaxSortByReportId(reportId)
- if err != nil {
- errMsg = "移动失败"
- err = fmt.Errorf("查询组内排序信息失败,Err:" + err.Error())
- return
- }
- reportChapter.Sort = maxSort + 1 //那就是排在组内最后一位
- reportChapter.ModifyTime = time.Now()
- updateCol = append(updateCol, "Sort", "ModifyTime")
- } else {
- firstReportChapter, tmpErr := ob.GetFirstReportChapterByReportId(reportId)
- if tmpErr != nil && !utils.IsErrNoRow(tmpErr) {
- errMsg = "移动失败"
- err = fmt.Errorf("获取当前报告下,且排序数相同 的排序第一条的数据失败,Err:" + tmpErr.Error())
- return
- }
- if firstReportChapter != nil && firstReportChapter.ReportChapterId > 0 && firstReportChapter.Sort == 0 {
- updateSortStr := ` sort + 1 `
- _ = ob.UpdateReportChapterSortByReportId(reportId, firstReportChapter.ReportChapterId-1, 0, updateSortStr)
- }
- reportChapter.Sort = 0 //那就是排在第一位
- reportChapter.ModifyTime = time.Now()
- updateCol = append(updateCol, "Sort", "ModifyTime")
- }
- if len(updateCol) > 0 {
- err = reportChapter.UpdateChapter(updateCol)
- if err != nil {
- errMsg = "移动失败"
- err = fmt.Errorf("修改失败,Err:" + err.Error())
- return
- }
- }
- return
- }
- func CheckChapterAuthByAdminIdList(adminId, createAdminId int, grantAdminIdList []int) (isAuth bool) {
- if adminId == createAdminId {
- isAuth = true
- return
- }
- if utils.IsCheckInList(grantAdminIdList, adminId) {
- isAuth = true
- return
- }
- return
- }
- func CheckChapterAuthByReportChapterInfo(adminId, createAdminId int, reportChapterInfo *models.ReportChapter) (isAuth bool, err error) {
- if adminId == createAdminId {
- isAuth = true
- return
- }
- chapterGrantObj := report.ReportChapterGrant{}
- chapterGrantList, err := chapterGrantObj.GetGrantListById(reportChapterInfo.ReportChapterId)
- if err != nil {
- return
- }
- for _, v := range chapterGrantList {
- if v.AdminId == adminId {
- isAuth = true
- return
- }
- }
- return
- }
|