Browse Source

改进报告模型和时间处理

- 将报告模型中的 MsgSendTime 和 ApproveTime 字段类型从 string 更改为 *global.LocalTime,以更好地处理时间信息
- 修改 LocalTime 的 MarshalJSON 方法,增加对零时间值的处理,避免转换为空字符串时出现错误
Roc 5 months ago
parent
commit
483e624d7e
2 changed files with 5 additions and 2 deletions
  1. 3 0
      global/dm.go
  2. 2 2
      models/report.go

+ 3 - 0
global/dm.go

@@ -115,6 +115,9 @@ func connectDm(dsn, aliasName string, newLogger logger.Interface, dmSqlMap map[s
 
 func (t *LocalTime) MarshalJSON() ([]byte, error) {
 	tTime := time.Time(*t)
+	if tTime.IsZero() {
+		return []byte("\"\""), nil
+	}
 	return []byte(fmt.Sprintf("\"%v\"", tTime.Format("2006-01-02 15:04:05"))), nil
 }
 

+ 2 - 2
models/report.go

@@ -125,13 +125,13 @@ type ReportList struct {
 	ChapterType        string                    `gorm:"column:chapter_type" description:"章节类型 day-晨报 week-周报"`
 	ChapterVideoList   []*ReportChapterVideoList `gorm:"-" description:"章节音频列表"` // 不映射到数据库
 	OldReportId        int                       `gorm:"column:old_report_id" description:"research_report表ID, 大于0则表示该报告为老后台同步过来的"`
-	MsgSendTime        string                    `gorm:"column:msg_send_time" description:"模版消息发送时间"`
+	MsgSendTime        *global.LocalTime         `gorm:"column:msg_send_time" description:"模版消息发送时间"`
 	CanEdit            bool                      `gorm:"column:can_edit" description:"是否可编辑"`
 	HasAuth            bool                      `gorm:"column:has_auth" description:"是否可操作"`
 	Editor             string                    `gorm:"column:editor" description:"编辑人"`
 	AdminId            int                       `gorm:"column:admin_id" description:"创建者账号"`
 	AdminRealName      string                    `gorm:"column:admin_real_name" description:"创建者姓名"`
-	ApproveTime        string                    `gorm:"column:approve_time" description:"审批时间"`
+	ApproveTime        *global.LocalTime         `gorm:"column:approve_time" description:"审批时间"`
 	DetailImgUrl       string                    `gorm:"column:detail_img_url" description:"报告详情长图地址"`
 	DetailPdfUrl       string                    `gorm:"column:detail_pdf_url" description:"报告详情PDF地址"`