|
@@ -114,7 +114,7 @@ func CreatePptReport(outReportId, classifyId int, title string, topicEndTime tim
|
|
|
cond := ` AND report_source = ? AND classify_id = ? AND state = ?`
|
|
|
pars := make([]interface{}, 0)
|
|
|
pars = append(pars, utils.ReportSourceOuter, classifyId, models.ReportStatePass)
|
|
|
- inheritItem, _ = ob.GetItemByCondition(cond, pars, "")
|
|
|
+ inheritItem, _ = ob.GetItemByCondition(cond, pars, "create_time DESC")
|
|
|
}
|
|
|
if inheritItem != nil && inheritItem.PptId > 0 {
|
|
|
newItem.TemplateType = inheritItem.TemplateType
|
|
@@ -172,7 +172,7 @@ func UpdateClassifyReportNum(classifyId int) (err error) {
|
|
|
cond += ` AND classify_id_third = ?`
|
|
|
}
|
|
|
pars := make([]interface{}, 0)
|
|
|
- pars = append(pars, classifyId, classifyId)
|
|
|
+ pars = append(pars, classifyId)
|
|
|
count, e := reportOb.GetCountByCondition(cond, pars)
|
|
|
if e != nil {
|
|
|
err = fmt.Errorf("获取报告计数失败, %v", e)
|
|
@@ -305,7 +305,7 @@ func CreateReport(outReportId, classifyId int, title string, topicEndTime time.T
|
|
|
|
|
|
// 各级分类信息
|
|
|
var classifyIdFirst, classifyIdSecond, classifyIdThird int
|
|
|
- var classifyNameFirst, classifyNameSecond, classifyNameThird string
|
|
|
+ var classifyNameFirst, classifyNameSecond, classifyNameThird, classifyName string
|
|
|
{
|
|
|
classifyOb := new(models.Classify)
|
|
|
classifies, e := classifyOb.GetItemsByCondition(``, make([]interface{}, 0), []string{}, "")
|
|
@@ -322,6 +322,7 @@ func CreateReport(outReportId, classifyId int, title string, topicEndTime time.T
|
|
|
err = fmt.Errorf("分类不存在, ID: %d", classifyId)
|
|
|
return
|
|
|
}
|
|
|
+ classifyName = thisClassify.ClassifyName
|
|
|
|
|
|
// 根据levelPath确认各级分类信息
|
|
|
levelArr := strings.Split(thisClassify.LevelPath, ",")
|
|
@@ -409,13 +410,14 @@ func CreateReport(outReportId, classifyId int, title string, topicEndTime time.T
|
|
|
|
|
|
// 自动继承该分类上一篇外部报告(审批通过的)
|
|
|
newChapters := make([]*models.ReportChapter, 0)
|
|
|
+ chapterGrantsMapping := make(map[int][]int)
|
|
|
inheritItem := new(models.Report)
|
|
|
{
|
|
|
ob := new(models.Report)
|
|
|
cond := ` AND report_source = ? AND state = ? AND classify_id_first = ? AND classify_id_second = ? AND classify_id_third = ?`
|
|
|
pars := make([]interface{}, 0)
|
|
|
pars = append(pars, utils.ReportSourceOuter, models.ReportStatePass, classifyIdFirst, classifyIdSecond, classifyIdThird)
|
|
|
- inheritItem, _ = ob.GetItemByCondition(cond, pars, "")
|
|
|
+ inheritItem, _ = ob.GetItemByCondition(cond, pars, "create_time DESC")
|
|
|
}
|
|
|
if inheritItem != nil && inheritItem.Id > 0 {
|
|
|
newItem.InheritReportId = inheritItem.Id
|
|
@@ -439,25 +441,75 @@ func CreateReport(outReportId, classifyId int, title string, topicEndTime time.T
|
|
|
err = fmt.Errorf("获取继承报告章节失败, %v", e)
|
|
|
return
|
|
|
}
|
|
|
- for _, v := range inheritChapters {
|
|
|
- v.ReportChapterId = 0
|
|
|
- v.ReportId = 0
|
|
|
- v.ClassifyIdFirst = classifyIdFirst
|
|
|
- v.ClassifyNameFirst = classifyNameFirst
|
|
|
- v.PublishState = 1 // 未发布
|
|
|
- v.CreateTime = time.Now()
|
|
|
- v.ModifyTime = time.Now()
|
|
|
- v.ContentModifyTime = time.Now()
|
|
|
- v.LastModifyAdminId = creatorAdmin.AdminId
|
|
|
- v.LastModifyAdminName = creatorAdmin.RealName
|
|
|
- newChapters = append(newChapters, v)
|
|
|
- }
|
|
|
+ if len(inheritChapters) > 0 {
|
|
|
+ var originChapterIds []int
|
|
|
+ for _, v := range inheritChapters {
|
|
|
+ originChapterIds = append(originChapterIds, v.ReportChapterId)
|
|
|
+ //v.ReportChapterId = 0 // 此处不置空,插入时需要做新ID和旧ID的匹配
|
|
|
+ v.ReportId = 0
|
|
|
+ v.ClassifyIdFirst = classifyIdFirst
|
|
|
+ v.ClassifyNameFirst = classifyNameFirst
|
|
|
+ v.PublishState = 1 // 未发布
|
|
|
+ v.CreateTime = time.Now()
|
|
|
+ v.ModifyTime = time.Now()
|
|
|
+ v.ContentModifyTime = time.Now()
|
|
|
+ v.LastModifyAdminId = creatorAdmin.AdminId
|
|
|
+ v.LastModifyAdminName = creatorAdmin.RealName
|
|
|
+ newChapters = append(newChapters, v)
|
|
|
+ }
|
|
|
|
|
|
- // TODO:继承的协作人
|
|
|
+ // 这里需要继承原章节的授权,保留在报告协作人中依旧存在的,移除不在报告协作人中的
|
|
|
+ chapterGrantsOb := new(models.ReportChapterGrant)
|
|
|
+ chapterGrantsCond := ` AND report_chapter_id IN (?)`
|
|
|
+ chapterGrantsPars := make([]interface{}, 0)
|
|
|
+ chapterGrantsPars = append(chapterGrantsPars, originChapterIds)
|
|
|
+ originChapterGrants, e := chapterGrantsOb.GetItemsByCondition(chapterGrantsCond, chapterGrantsPars, []string{}, "")
|
|
|
+ if e != nil {
|
|
|
+ err = fmt.Errorf("获取继承章节授权失败, %v", e)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, v := range originChapterGrants {
|
|
|
+ if utils.InArrayByInt(partnerIds, v.AdminId) {
|
|
|
+ chapterGrantsMapping[v.ReportChapterId] = append(chapterGrantsMapping[v.ReportChapterId], v.AdminId)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 找不到继承报告,则找下分类是否有对应的章节设置
|
|
|
+ typesOb := new(models.ReportChapterType)
|
|
|
+ typesCond := ` AND report_classify_id = ?`
|
|
|
+ typesPars := make([]interface{}, 0)
|
|
|
+ typesPars = append(typesPars, classifyId)
|
|
|
+ chapterTypes, e := typesOb.GetItemsByCondition(typesCond, typesPars, []string{}, "")
|
|
|
+ if e != nil {
|
|
|
+ err = fmt.Errorf("获取报告分类章节设置失败, %v", e)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 新增默认章节
|
|
|
+ for _, v := range chapterTypes {
|
|
|
+ cp := new(models.ReportChapter)
|
|
|
+ cp.AddType = 1
|
|
|
+ cp.Title = v.ReportChapterTypeName
|
|
|
+ cp.ReportType = v.ResearchType
|
|
|
+ cp.ClassifyIdFirst = classifyId
|
|
|
+ cp.ClassifyNameFirst = classifyName
|
|
|
+ cp.TypeId = v.ReportChapterTypeId
|
|
|
+ cp.TypeName = v.ReportChapterTypeName
|
|
|
+ cp.PublishState = 1
|
|
|
+ cp.Sort = v.Sort
|
|
|
+ cp.CreateTime = newItem.CreateTime
|
|
|
+ cp.ModifyTime = time.Now()
|
|
|
+ cp.LastModifyAdminId = newItem.LastModifyAdminId
|
|
|
+ cp.LastModifyAdminName = newItem.LastModifyAdminName
|
|
|
+ cp.ContentModifyTime = time.Now()
|
|
|
+ cp.ReportLayout = newItem.ReportLayout
|
|
|
+ cp.ReportCreateTime = time.Now()
|
|
|
+ newChapters = append(newChapters, cp)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// 新增报告、章节以及协作人权限
|
|
|
- newId, e := newItem.CreateReportAndChapters(newItem, newChapters, newGrants)
|
|
|
+ newId, e := newItem.CreateReportAndChapters(newItem, newChapters, newGrants, chapterGrantsMapping)
|
|
|
if e != nil {
|
|
|
err = fmt.Errorf("新增报告、章节及授权失败, %v", e)
|
|
|
return
|