Browse Source

fix:编辑

zqbao 8 months ago
parent
commit
1b1ac9424f
3 changed files with 45 additions and 41 deletions
  1. 29 40
      controllers/report_pdf.go
  2. 10 0
      models/request/report_pdf.go
  3. 6 1
      utils/config.go

+ 29 - 40
controllers/report_pdf.go

@@ -46,12 +46,7 @@ func (this *ReportPdfController) Author() {
 // Add
 // @Title 添加研报
 // @Description 添加研报
-// @Param   PdfUrl   query   file  true       "文件URL"
-// @Param   Title   query   string  true       "标题"
-// @Param   Author   query   string  true       "作者名称"
-// @Param   Abstract   query   string  true       "摘要"
-// @Param   ClassifyIdFirst   query   int  true       "一级分类id"
-// @Param   ClassifyIdSecond   query   int  true       "二级分类id"
+// @Param	request	body request.ReportPdfAddReq true "type json string"
 // @Success 200 {object} models.ReportAuthorResp
 // @router /add [post]
 func (this *ReportPdfController) Add() {
@@ -154,7 +149,7 @@ func (this *ReportPdfController) UploadPdf() {
 		br.ErrMsg = "文件上传失败,Err:" + err.Error()
 		return
 	}
-	pdfUploadDir := "pdf/"
+	pdfUploadDir := utils.RESOURCE_DIR + "pdf/"
 	savePdfToOssPath := pdfUploadDir + time.Now().Format("200601/20060102/")
 	pptName := utils.GetRandStringNoSpecialChar(28)
 	savePdfToOssPath += pptName + ".pdf"
@@ -349,13 +344,7 @@ func (this *ReportPdfController) List() {
 // Edit
 // @Title 编辑研报
 // @Description 编辑研报
-// @Param   ReportPdfId   query   string  true       "pdf研报id"
-// @Param   PdfUrl   query   file  true       "文件URL"
-// @Param   Title   query   string  true       "标题"
-// @Param   Author   query   string  true       "作者名称"
-// @Param   Abstract   query   string  true       "摘要"
-// @Param   ClassifyIdFirst   query   int  true       "一级分类id"
-// @Param   ClassifyIdSecond   query   int  true       "二级分类id"
+// @Param	request	body request.ReportPdfEditReq true "type json string"
 // @Success 200 {object} models.ReportAuthorResp
 // @router /edit [post]
 func (this *ReportPdfController) Edit() {
@@ -364,26 +353,26 @@ func (this *ReportPdfController) Edit() {
 		this.Data["json"] = br
 		this.ServeJSON()
 	}()
-	pdfUrl := this.GetString("PdfUrl")
-	author := this.GetString("Author")
-	ReportPdfId, _ := this.GetInt("ReportPdfId")
-	abstract := this.GetString("Abstract")
-	classifyIdFirst, _ := this.GetInt("ClassifyIdFirst")
-	classifyIdSecond, _ := this.GetInt("ClassifyIdSecond")
-	title := this.GetString("Title")
-	if classifyIdFirst <= 0 {
+
+	var req request.ReportPdfEditReq
+	if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
+		br.Msg = "参数错误"
+		br.ErrMsg = "参数错误,Err:" + err.Error()
+		return
+	}
+	if req.ClassifyIdFirst <= 0 {
 		br.Msg = "请选择研报所属的一级分类"
 		return
 	}
-	if classifyIdSecond <= 0 {
+	if req.ClassifyIdSecond <= 0 {
 		br.Msg = "请选择研报所属的二级分类"
 		return
 	}
-	if pdfUrl == "" {
+	if req.PdfUrl == "" {
 		br.Msg = "请上传研报文件"
 		return
 	}
-	reportPdf, err := models.GetReportPdfById(ReportPdfId)
+	reportPdf, err := models.GetReportPdfById(req.ReportPdfId)
 	if err != nil {
 		if err.Error() == utils.ErrNoRow() {
 			br.Msg = "研报不存在或已删除,请刷新页面"
@@ -394,32 +383,32 @@ func (this *ReportPdfController) Edit() {
 		return
 	}
 
-	nameFirst, err := models.GetClassifyById(classifyIdFirst)
+	nameFirst, err := models.GetClassifyById(req.ClassifyIdFirst)
 	if err != nil {
-		br.Msg = "文件上传失败"
+		br.Msg = "文件编辑失败"
 		br.ErrMsg = "一级类名获取失败,Err:" + err.Error()
 		return
 	}
-	nameSecond, err := models.GetClassifyById(classifyIdSecond)
+	nameSecond, err := models.GetClassifyById(req.ClassifyIdSecond)
 	if err != nil {
-		br.Msg = "文件上传失败"
+		br.Msg = "文件编辑失败"
 		br.ErrMsg = "二级类名获取失败,Err:" + err.Error()
 		return
 	}
-	if reportPdf.Title != title || reportPdf.ClassifyIdFirst != classifyIdFirst || reportPdf.ClassifyIdSecond != classifyIdSecond || reportPdf.Author != author || reportPdf.Abstract != abstract || reportPdf.PdfUrl != pdfUrl {
-		reportPdf.Title = title
-		reportPdf.ClassifyIdFirst = classifyIdFirst
-		reportPdf.ClassifyIdSecond = classifyIdSecond
+	if reportPdf.Title != req.Title || reportPdf.ClassifyIdFirst != req.ClassifyIdFirst || reportPdf.ClassifyIdSecond != req.ClassifyIdSecond || reportPdf.Author != req.Author || reportPdf.Abstract != req.Abstract || reportPdf.PdfUrl != req.PdfUrl {
+		reportPdf.Title = req.Title
+		reportPdf.ClassifyIdFirst = req.ClassifyIdFirst
+		reportPdf.ClassifyIdSecond = req.ClassifyIdSecond
 		reportPdf.ClassifyNameFirst = nameFirst.ClassifyName
 		reportPdf.ClassifyNameSecond = nameSecond.ClassifyName
-		reportPdf.Author = author
-		reportPdf.Abstract = abstract
-		reportPdf.PdfUrl = pdfUrl
+		reportPdf.Author = req.Author
+		reportPdf.Abstract = req.Abstract
+		reportPdf.PdfUrl = req.PdfUrl
 		reportPdf.ModifyTime = time.Now()
 		err = reportPdf.Update([]string{"title", "classify_id_first", "classify_id_second", "classify_name_first", "classify_name_second", "author", "abstract", "pdf_url", "modify_time"})
 		if err != nil {
-			br.Msg = "文件上传失败"
-			br.ErrMsg = "文件上传失败,Err:" + err.Error()
+			br.Msg = "文件更新失败"
+			br.ErrMsg = "文件更新失败,Err:" + err.Error()
 			return
 		}
 	}
@@ -457,7 +446,7 @@ func (this *ReportPdfController) Publish() {
 	}
 	reportPdf.State = utils.ReportStatusUp
 	reportPdf.PublishTime = time.Now()
-	err = reportPdf.Update([]string{"status", "publish_time"})
+	err = reportPdf.Update([]string{"state", "publish_time"})
 	if err != nil {
 		br.Msg = "发布研报失败"
 		br.ErrMsg = "发布研报失败,系统错误,Err:" + err.Error()
@@ -496,7 +485,7 @@ func (this *ReportPdfController) PublishCancel() {
 		return
 	}
 	reportPdf.State = utils.ReportStatusDown
-	err = reportPdf.Update([]string{"status"})
+	err = reportPdf.Update([]string{"state"})
 	if err != nil {
 		br.Msg = "发布研报失败"
 		br.ErrMsg = "发布研报失败,系统错误,Err:" + err.Error()

+ 10 - 0
models/request/report_pdf.go

@@ -8,3 +8,13 @@ type ReportPdfAddReq struct {
 	ClassifyIdFirst  int    `description:"一级分类id"`
 	ClassifyIdSecond int    `description:"二级分类id"`
 }
+
+type ReportPdfEditReq struct {
+	ReportPdfId      int    `description:"id"`
+	PdfUrl           string `description:"pdf文件URL"`
+	Title            string `description:"标题"`
+	Author           string `description:"作者"`
+	Abstract         string `description:"摘要"`
+	ClassifyIdFirst  int    `description:"一级分类id"`
+	ClassifyIdSecond int    `description:"二级分类id"`
+}

+ 6 - 1
utils/config.go

@@ -41,7 +41,8 @@ var (
 
 // 基础配置
 var (
-	STATIC_DIR string
+	STATIC_DIR   string
+	RESOURCE_DIR string
 )
 
 var (
@@ -116,6 +117,10 @@ func init() {
 	if STATIC_DIR == "" {
 		STATIC_DIR = "./static"
 	}
+	RESOURCE_DIR = config["resource_dir"]
+	if RESOURCE_DIR == "" {
+		RESOURCE_DIR = "dongwu/"
+	}
 
 	// 初始化缓存
 	redisClient, err := initRedis(config["redis_type"], config["beego_cache"])