package rag import ( "database/sql" "eta/eta_api/global" "eta/eta_api/utils" "fmt" "time" ) // RagEtaReport eta报告 type RagEtaReport struct { RagEtaReportID int `gorm:"primaryKey;column:rag_eta_report_id" json:"-"` ReportID int `gorm:"column:report_id" json:"reportId"` // 报告id ReportChapterID int `gorm:"column:report_chapter_id" json:"reportChapterId"` // 报告章节id Title string `gorm:"column:title" json:"title"` // 报告标题(完整标题,含期数) Author string `gorm:"column:author" json:"author"` // 作者 TextContent string `gorm:"column:text_content" json:"textContent"` // 报告内容(去除html) VectorKey string `gorm:"column:vector_key" json:"vectorKey"` // 向量库的key PublishTime time.Time `gorm:"column:publish_time" json:"publishTime"` // 发布时间 ModifyTime time.Time `gorm:"column:modify_time" json:"modifyTime"` // 修改时间 CreateTime time.Time `gorm:"column:create_time" json:"createTime"` // 新增时间 } // TableName get sql table name.获取数据库表名 func (m *RagEtaReport) TableName() string { return "rag_eta_report" } // RagEtaReportColumns get sql column name.获取数据库列名 var RagEtaReportColumns = struct { RagEtaReportID string ReportID string ReportChapterID string Title string Author string TextContent string VectorKey string PublishTime string ModifyTime string CreateTime string }{ RagEtaReportID: "rag_eta_report_id", ReportID: "report_id", ReportChapterID: "report_chapter_id", Title: "title", Author: "author", TextContent: "text_content", VectorKey: "vector_key", PublishTime: "publish_time", ModifyTime: "modify_time", CreateTime: "create_time", } type RagEtaReportView struct { RagEtaReportID int `gorm:"primaryKey;column:rag_eta_report_id" json:"-"` ReportID int `gorm:"column:report_id" json:"reportId"` // 报告id ReportChapterID int `gorm:"column:report_chapter_id" json:"reportChapterId"` // 报告章节id Title string `gorm:"column:title" json:"title"` // 报告标题(完整标题,含期数) Author string `gorm:"column:author" json:"author"` // 作者 TextContent string `gorm:"column:text_content" json:"textContent"` // 报告内容(去除html) VectorKey string `gorm:"column:vector_key" json:"vectorKey"` // 向量库的key PublishTime time.Time `gorm:"column:publish_time" json:"publishTime"` // 发布时间 ModifyTime time.Time `gorm:"column:modify_time" json:"modifyTime"` // 修改时间 CreateTime time.Time `gorm:"column:create_time" json:"createTime"` // 新增时间 } func (m *RagEtaReport) ToView() RagEtaReportView { var publishTime, modifyTime, createTime string if !m.PublishTime.IsZero() { publishTime = m.PublishTime.Format(utils.FormatDateTime) } if !m.CreateTime.IsZero() { createTime = m.CreateTime.Format(utils.FormatDateTime) } if !m.ModifyTime.IsZero() { modifyTime = m.ModifyTime.Format(utils.FormatDateTime) } return RagEtaReportView{ RagEtaReportID: 0, ReportID: 0, ReportChapterID: 0, Title: "", Author: "", TextContent: "", VectorKey: "", PublishTime: time.Time{}, ModifyTime: time.Time{}, CreateTime: time.Time{}, } } func (m *RagEtaReport) ListToViewList(list []*RagEtaReport) (RagEtaReportViewList []RagEtaReportView) { RagEtaReportViewList = make([]RagEtaReportView, 0) for _, v := range list { RagEtaReportViewList = append(RagEtaReportViewList, v.ToView()) } return } func (m *RagEtaReport) Create() (err error) { err = global.DbMap[utils.DbNameAI].Create(&m).Error return } func (m *RagEtaReport) Update(updateCols []string) (err error) { err = global.DbMap[utils.DbNameAI].Select(updateCols).Updates(&m).Error return } func (m *RagEtaReport) GetById(id int) (item *RagEtaReport, err error) { err = global.DbMap[utils.DbNameAI].Where(fmt.Sprintf("%s = ?", RagEtaReportColumns.RagEtaReportID), id).First(&item).Error return } func (m *RagEtaReport) GetListByCondition(field, condition string, pars []interface{}, startSize, pageSize int) (items []*RagEtaReport, err error) { if field == "" { field = "*" } sqlStr := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 AND is_deleted=0 %s order by article_create_time desc,wechat_article_id desc LIMIT ?,?`, field, m.TableName(), condition) pars = append(pars, startSize, pageSize) err = global.DbMap[utils.DbNameAI].Raw(sqlStr, pars...).Find(&items).Error return } func (m *RagEtaReport) GetCountByCondition(condition string, pars []interface{}) (total int, err error) { var intNull sql.NullInt64 sqlStr := fmt.Sprintf(`SELECT COUNT(1) total FROM %s WHERE 1=1 AND is_deleted=0 %s`, m.TableName(), condition) err = global.DbMap[utils.DbNameAI].Raw(sqlStr, pars...).Scan(&intNull).Error if err == nil && intNull.Valid { total = int(intNull.Int64) } return } func (m *RagEtaReport) GetPageListByCondition(condition string, pars []interface{}, startSize, pageSize int) (total int, items []*RagEtaReport, err error) { total, err = m.GetCountByCondition(condition, pars) if err != nil { return } if total > 0 { items, err = m.GetListByCondition(`wechat_article_id,wechat_platform_id,fake_id,title,link,cover_url,description,country,province,city,article_create_time,modify_time,create_time`, condition, pars, startSize, pageSize) } return }