Browse Source

优化报告相关功能并添加日志

- 优化 GetReportById函数,通过新增 convertReportToReportDetail 函数处理报告信息转换- 改进报告时间字段处理,使用统一的日期时间格式- 在报告查询中增加日志输出,便于调试和监控
Roc 5 months ago
parent
commit
8ac0f4606e
3 changed files with 65 additions and 25 deletions
  1. 1 1
      controllers/base_auth.go
  2. 1 0
      controllers/report_v2.go
  3. 63 24
      models/report.go

+ 1 - 1
controllers/base_auth.go

@@ -234,7 +234,7 @@ func (c *BaseAuthController) Prepare() {
 
 			fmt.Println("uri:", uri)
 
-			fmt.Println(apiMap)
+			//fmt.Println(apiMap)
 			if !apiMap[uri] {
 				c.JSON(models.BaseResponse{Ret: 403, Msg: "无权访问!", ErrMsg: "无权访问!"}, false, false)
 				c.StopRun()

+ 1 - 0
controllers/report_v2.go

@@ -1002,6 +1002,7 @@ func (this *ReportController) BaseDetail() {
 		br.ErrMsg = "获取失败,Err:" + err.Error()
 		return
 	}
+	fmt.Println(reportInfo)
 
 	// 基础信息就不获取章节信息了
 	chapterList := make([]*models.ReportChapter, 0)

+ 63 - 24
models/report.go

@@ -1,6 +1,7 @@
 package models
 
 import (
+	"encoding/json"
 	"errors"
 	"eta_gn/eta_api/global"
 	"eta_gn/eta_api/utils"
@@ -348,36 +349,74 @@ type ReportDetail struct {
 	ReportCode         string `gorm:"column:report_code" description:"报告唯一编码"`
 
 	// eta1.8.3(研报改版)相关内容
-	ContentStruct       string    `gorm:"column:content_struct" description:"内容组件"`
-	LastModifyAdminId   int       `gorm:"column:last_modify_admin_id" description:"最后更新人ID"`
-	LastModifyAdminName string    `gorm:"column:last_modify_admin_name" description:"最后更新人姓名"`
-	ContentModifyTime   time.Time `gorm:"column:content_modify_time" description:"内容更新时间"`
-	Pv                  int       `gorm:"column:pv" description:"pv"`
-	Uv                  int       `gorm:"column:uv" description:"uv"`
-	HeadImg             string    `gorm:"column:head_img" description:"报告头图地址"`
-	EndImg              string    `gorm:"column:end_img" description:"报告尾图地址"`
-	HeadStyle           string    `gorm:"column:head_style" description:"版头样式"`
-	EndStyle            string    `gorm:"column:end_style" description:"版尾样式"`
-	CanvasColor         string    `gorm:"column:canvas_color" description:"画布颜色"`
-	NeedSplice          int       `gorm:"column:need_splice" description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
-	HeadResourceId      int       `gorm:"column:head_resource_id" description:"版头资源ID"`
-	EndResourceId       int       `gorm:"column:end_resource_id" description:"版尾资源ID"`
-	ClassifyIdThird     int       `gorm:"column:classify_id_third" description:"三级分类id"`
-	ClassifyNameThird   string    `gorm:"column:classify_name_third" description:"三级分类名称"`
-	CollaborateType     int8      `gorm:"column:collaborate_type" description:"协作方式,1:个人,2:多人协作。默认:1"`
-	ReportLayout        int8      `gorm:"column:report_layout" description:"报告布局,1:常规布局,2:智能布局。默认:1"`
-	IsPublicPublish     int8      `gorm:"column:is_public_publish" description:"是否公开发布,1:是,2:否"`
-	ReportCreateTime    time.Time `gorm:"column:report_create_time" description:"报告时间创建时间"`
+	ContentStruct       string `gorm:"column:content_struct" description:"内容组件"`
+	LastModifyAdminId   int    `gorm:"column:last_modify_admin_id" description:"最后更新人ID"`
+	LastModifyAdminName string `gorm:"column:last_modify_admin_name" description:"最后更新人姓名"`
+	ContentModifyTime   string `gorm:"column:content_modify_time" description:"内容更新时间"`
+	Pv                  int    `gorm:"column:pv" description:"pv"`
+	Uv                  int    `gorm:"column:uv" description:"uv"`
+	HeadImg             string `gorm:"column:head_img" description:"报告头图地址"`
+	EndImg              string `gorm:"column:end_img" description:"报告尾图地址"`
+	HeadStyle           string `gorm:"column:head_style" description:"版头样式"`
+	EndStyle            string `gorm:"column:end_style" description:"版尾样式"`
+	CanvasColor         string `gorm:"column:canvas_color" description:"画布颜色"`
+	NeedSplice          int    `gorm:"column:need_splice" description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
+	HeadResourceId      int    `gorm:"column:head_resource_id" description:"版头资源ID"`
+	EndResourceId       int    `gorm:"column:end_resource_id" description:"版尾资源ID"`
+	ClassifyIdThird     int    `gorm:"column:classify_id_third" description:"三级分类id"`
+	ClassifyNameThird   string `gorm:"column:classify_name_third" description:"三级分类名称"`
+	CollaborateType     int8   `gorm:"column:collaborate_type" description:"协作方式,1:个人,2:多人协作。默认:1"`
+	ReportLayout        int8   `gorm:"column:report_layout" description:"报告布局,1:常规布局,2:智能布局。默认:1"`
+	IsPublicPublish     int8   `gorm:"column:is_public_publish" description:"是否公开发布,1:是,2:否"`
+	ReportCreateTime    string `gorm:"column:report_create_time" description:"报告时间创建时间"`
 }
 
 func GetReportById(reportId int) (item *ReportDetail, err error) {
-	//o := orm.NewOrmUsingDB("rddp")
-	sql := `SELECT * FROM report WHERE id=?`
-	//err = o.Raw(sql, reportId).QueryRow(&item)
-	err = global.DmSQL["rddp"].Raw(sql, reportId).First(&item).Error
+	reportInfo, err := GetReportByReportId(reportId)
+	if err != nil {
+		return
+	}
+
+	item, err = convertReportToReportDetail(*reportInfo)
+
 	return
 }
 
+func convertReportToReportDetail(report Report) (*ReportDetail, error) {
+	jsonBytes, err := json.Marshal(report)
+	if err != nil {
+		return nil, fmt.Errorf("failed to marshal input: %w", err)
+	}
+
+	reportDetail := new(ReportDetail)
+	err = json.Unmarshal(jsonBytes, reportDetail)
+	if err != nil {
+		return nil, fmt.Errorf("failed to unmarshal input: %w", err)
+	}
+
+	// 对于时间类型的字段,需要转换为字符串
+	reportDetail.CreateTime = report.CreateTime.Format(utils.FormatDateTime)
+	reportDetail.ModifyTime = report.ModifyTime.Format(utils.FormatDateTime)
+	if !report.PublishTime.IsZero() {
+		reportDetail.PublishTime = report.PublishTime.Format(utils.FormatDateTime)
+	} else {
+		reportDetail.PublishTime = ``
+	}
+	if !report.ContentModifyTime.IsZero() {
+		reportDetail.ContentModifyTime = report.ContentModifyTime.Format(utils.FormatDateTime)
+	} else {
+		reportDetail.ContentModifyTime = ``
+	}
+
+	if !report.ReportCreateTime.IsZero() {
+		reportDetail.ReportCreateTime = report.ReportCreateTime.Format(utils.FormatDateTime)
+	} else {
+		reportDetail.ReportCreateTime = ``
+	}
+
+	return reportDetail, nil
+}
+
 // GetSimpleReportByIds 根据报告ID查询报告基本信息
 func GetSimpleReportByIds(reportIds []int) (list []*Report, err error) {
 	if len(reportIds) == 0 {