Parcourir la source

fix:研报和PPT创建新增摘要字段,修改观点创建逻辑

zqbao il y a 3 mois
Parent
commit
e1457baa66

+ 12 - 6
controllers/report_open.go

@@ -141,6 +141,7 @@ func (this *ReportOpenController) ReportCreate() {
 		br.Msg = "请输入课题结束时间"
 		return
 	}
+	req.Abstract = strings.TrimSpace(req.Abstract)
 	topicTime, e := time.ParseInLocation(utils.FormatDateTime, req.EndTime, time.Local)
 	if e != nil {
 		br.Msg = "课题结束时间格式有误"
@@ -189,7 +190,7 @@ func (this *ReportOpenController) ReportCreate() {
 	// 研报类型
 	var reportId int
 	if classify.ClassifyType == utils.ReportTypeDefault {
-		reportId, e = services.CreateReport(req.ReportId, req.ClassifyId, req.Title, topicTime, req.Creator, req.Authors)
+		reportId, e = services.CreateReport(req.ReportId, req.ClassifyId, req.Title, req.Abstract, topicTime, req.Creator, req.Authors)
 		if e != nil {
 			br.Msg = "操作失败"
 			br.ErrMsg = fmt.Sprintf("新增报告失败, %v", e)
@@ -199,7 +200,7 @@ func (this *ReportOpenController) ReportCreate() {
 
 	// PPT类型
 	if classify.ClassifyType == utils.ReportTypePPT {
-		reportId, e = services.CreatePptReport(req.ReportId, req.ClassifyId, req.Title, topicTime, req.Creator, req.Authors)
+		reportId, e = services.CreatePptReport(req.ReportId, req.ClassifyId, req.Title, req.Abstract, topicTime, req.Creator, req.Authors)
 		if e != nil {
 			br.Msg = "操作失败"
 			br.ErrMsg = fmt.Sprintf("新增PPT报告失败, %v", e)
@@ -243,6 +244,7 @@ func (this *ReportOpenController) ReportModify() {
 		br.ErrMsg = fmt.Sprintf("智力共享报告ID有误, %d", req.ReportId)
 		return
 	}
+	req.Abstract = strings.TrimSpace(req.Abstract)
 	req.Title = strings.TrimSpace(req.Title)
 	if req.Title == "" {
 		br.Msg = "请输入报告标题"
@@ -271,7 +273,7 @@ func (this *ReportOpenController) ReportModify() {
 			br.Msg = "报告已发布,不可编辑"
 			return
 		}
-		if e = services.EditReport(reportExist, req.Title, topicTime, req.Authors); e != nil {
+		if e = services.EditReport(reportExist, req.Title, req.Abstract, topicTime, req.Authors); e != nil {
 			br.Msg = "操作失败"
 			br.ErrMsg = fmt.Sprintf("编辑报告失败, %v", e)
 			return
@@ -284,7 +286,7 @@ func (this *ReportOpenController) ReportModify() {
 			br.Msg = "报告已发布,不可编辑"
 			return
 		}
-		if e = services.EditPptReport(pptExist, req.Title, topicTime, req.Authors); e != nil {
+		if e = services.EditPptReport(pptExist, req.Title, req.Abstract, topicTime, req.Authors); e != nil {
 			br.Msg = "操作失败"
 			br.ErrMsg = fmt.Sprintf("编辑PPT报告失败, %v", e)
 			return
@@ -416,7 +418,10 @@ func (this *ReportOpenController) ReportApprove() {
 					} else {
 						classifyId = v.ClassifyIdFirst
 					}
-
+					v.Abstract = strings.TrimSpace(v.Abstract)
+					if v.Abstract == "" {
+						return
+					}
 					classifyId, err := knowledge.ReportKnowledgeResourceClassifyCheckAndSave(classifyId)
 					if err != nil {
 						utils.FileLog.Error(fmt.Sprintf("ReportKnowledgeResourceClassifyCheckAndSave-报告分类保存失败,reportId:%d,classifyId:%d,err: %v", v.Id, classifyId, err))
@@ -524,6 +529,7 @@ func (this *ReportOpenController) ReportApprove() {
 				}()
 				go func() {
 					// 审批通过,将摘要加入知识资源库观点中
+					v.Abstract = strings.TrimSpace(v.Abstract)
 					if v.Abstract == "" {
 						return
 					}
@@ -714,7 +720,7 @@ func (this *ReportOpenController) ViewPointSave() {
 		br.Msg = "观点日期不能为空"
 		return
 	}
-	dataDate, err := time.Parse(utils.FormatDateTime, req.DataDate)
+	dataDate, err := time.ParseInLocation(utils.FormatDateTime, req.DataDate, time.Local)
 	if err != nil {
 		br.Msg = "观点日期格式不正确"
 		return

+ 2 - 0
models/report_open.go

@@ -5,6 +5,7 @@ type ReportCreateReq struct {
 	ReportId   int      `description:"智力共享报告ID"`
 	ClassifyId int      `description:"分类ID"`
 	Title      string   `description:"报告标题"`
+	Abstract   string   `description:"报告摘要"`
 	EndTime    string   `description:"课题结束时间"`
 	Creator    string   `description:"创建人工号"`
 	Authors    []string `description:"作者工号"`
@@ -20,6 +21,7 @@ type ReportCreateResp struct {
 type ReportModifyReq struct {
 	ReportId int      `description:"智力共享报告ID"`
 	Title    string   `description:"报告标题"`
+	Abstract string   `description:"报告摘要"`
 	EndTime  string   `description:"课题结束时间"`
 	Authors  []string `description:"作者工号"`
 	Operator string   `description:"操作人工号"`

+ 5 - 6
services/knowledge/knowledge_resource.go

@@ -136,11 +136,11 @@ func ViewPointSave(outId, adminId int, adminRealName, title, content, sourceFrom
 	obj := new(models.KnowledgeResource)
 	knowledgeResource, err := obj.GetKnowledgeResourceByOutId(outId)
 	esObj := new(models.KnowledgeResource)
-	if err != nil {
-		if !utils.IsErrNoRow(err) {
-			msg = "观点保存失败"
-			return
-		}
+	if err != nil && !utils.IsErrNoRow(err) {
+		msg = "观点保存失败"
+		return
+	}
+	if outId <= 0 || utils.IsErrNoRow(err) {
 		// 创建新的知识资源库
 		err = nil
 		obj.ResourceType = models.KnowledgeResourceTypeOpinion
@@ -161,7 +161,6 @@ func ViewPointSave(outId, adminId int, adminRealName, title, content, sourceFrom
 		obj.SourceFrom = sourceFrom
 		obj.StartTime = startTime
 		obj.IsFile = 0
-		obj.OutId = outId
 		err = obj.Create([]string{})
 		if err != nil {
 			msg = "观点保存失败"

+ 10 - 6
services/report_open.go

@@ -62,7 +62,7 @@ func GetReportByOutReportId(outReportId int) (reportItem *models.Report, pptItem
 }
 
 // CreatePptReport 创建PPT报告
-func CreatePptReport(outReportId, classifyId int, title string, topicEndTime time.Time, creator string, authors []string) (reportId int, err error) {
+func CreatePptReport(outReportId, classifyId int, title, abstract string, topicEndTime time.Time, creator string, authors []string) (reportId int, err error) {
 	defer func() {
 		if err != nil {
 			utils.FileLog.Info(fmt.Sprintf("创建外部PPT报告失败, OutReportId: %d, %v", outReportId, err))
@@ -94,6 +94,7 @@ func CreatePptReport(outReportId, classifyId int, title string, topicEndTime tim
 	// 新建PPT基础信息
 	newItem := new(models.PptV2)
 	newItem.Title = title
+	newItem.Abstract = abstract
 	newItem.AddType = utils.ReportAddTypeInherit
 	newItem.ClassifyId = classifyId
 	newItem.CollaborateType = utils.ReportWriteTypeGroup
@@ -287,7 +288,7 @@ func CountParentClassifyReportNumRecursive(list []*models.Classify, parentId int
 }
 
 // CreateReport 创建报告
-func CreateReport(outReportId, classifyId int, title string, topicEndTime time.Time, creator string, authors []string) (reportId int, err error) {
+func CreateReport(outReportId, classifyId int, title, abstract string, topicEndTime time.Time, creator string, authors []string) (reportId int, err error) {
 	defer func() {
 		if err != nil {
 			utils.FileLog.Info(fmt.Sprintf("创建外部报告失败, OutReportId: %d, %v", outReportId, err))
@@ -372,6 +373,7 @@ func CreateReport(outReportId, classifyId int, title string, topicEndTime time.T
 
 	// 新报告信息
 	newItem := new(models.Report)
+	newItem.Abstract = abstract
 	newItem.AddType = utils.ReportAddTypeInherit // 固定继承
 	newItem.ReportVersion = 2                    // 固定新版报告
 	newItem.ClassifyIdFirst = classifyIdFirst
@@ -545,7 +547,7 @@ func CreateReport(outReportId, classifyId int, title string, topicEndTime time.T
 }
 
 // EditReport 编辑报告
-func EditReport(reportItem *models.Report, title string, topicEndTime time.Time, authors []string) (err error) {
+func EditReport(reportItem *models.Report, title, abstract string, topicEndTime time.Time, authors []string) (err error) {
 	if reportItem == nil {
 		err = fmt.Errorf("报告信息有误")
 		return
@@ -629,10 +631,11 @@ func EditReport(reportItem *models.Report, title string, topicEndTime time.Time,
 	}
 
 	// 更新报告和移除授权
+	reportItem.Abstract = abstract
 	reportItem.Title = title
 	reportItem.TopicEndTime = topicEndTime
 	reportItem.ModifyTime = time.Now()
-	updateCols := []string{"Title", "TopicEndTime", "ModifyTime"}
+	updateCols := []string{"Title", "Abstract", "TopicEndTime", "ModifyTime"}
 	if e := reportItem.EditReportAndClearGrant(reportItem, updateCols, chapterIds, removePartner); e != nil {
 		err = fmt.Errorf("更新报告失败, %v", e)
 		return
@@ -641,7 +644,7 @@ func EditReport(reportItem *models.Report, title string, topicEndTime time.Time,
 }
 
 // EditPptReport 编辑PPT报告
-func EditPptReport(pptItem *models.PptV2, title string, topicEndTime time.Time, authors []string) (err error) {
+func EditPptReport(pptItem *models.PptV2, title, abstract string, topicEndTime time.Time, authors []string) (err error) {
 	if pptItem == nil {
 		err = fmt.Errorf("PPT报告信息有误")
 		return
@@ -672,6 +675,7 @@ func EditPptReport(pptItem *models.PptV2, title string, topicEndTime time.Time,
 	// 新建PPT基础信息
 	pptItem.Title = title
 	pptItem.TopicEndTime = topicEndTime
+	pptItem.Abstract = abstract
 	if len(authors) > 0 {
 		var partnerArr []string
 		for _, v := range authors {
@@ -684,7 +688,7 @@ func EditPptReport(pptItem *models.PptV2, title string, topicEndTime time.Time,
 		}
 		pptItem.CollaborateUsers = strings.Trim(strings.Join(partnerArr, ","), `"`)
 	}
-	updateCols := []string{"Title", "TopicEndTime", "CollaborateUsers"}
+	updateCols := []string{"Title", "Abstract", "TopicEndTime", "CollaborateUsers"}
 	if e := pptItem.Update(updateCols); e != nil {
 		err = fmt.Errorf("更新PPT报告失败, %v", e)
 		return