123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- package rag
- import (
- "database/sql"
- "eta/eta_api/global"
- "eta/eta_api/utils"
- "fmt"
- "time"
- )
- type WechatArticleAbstract struct {
- WechatArticleAbstractId int `gorm:"column:wechat_article_abstract_id;type:int(9) UNSIGNED;primaryKey;not null;" description:"wechat_article_abstract_id"`
- WechatArticleId int `gorm:"column:wechat_article_id;type:int(9) UNSIGNED;comment:关联的微信报告id;default:0;" description:"关联的微信报告id"`
- Content string `gorm:"column:content;type:longtext;comment:摘要内容;" description:"content"` // 摘要内容
- Version int `gorm:"column:version;type:int(10) UNSIGNED;comment:版本号;default:1;" description:"版本号"`
- VectorKey string `gorm:"column:vector_key;type:varchar(255);comment:向量key标识;" json:"vector_key"` // 向量key标识
- ModifyTime time.Time `gorm:"column:modify_time;type:datetime;default:NULL;" description:"modify_time"`
- CreateTime time.Time `gorm:"column:create_time;type:datetime;default:NULL;" description:"create_time"`
- }
- // TableName get sql table name.获取数据库表名
- func (m *WechatArticleAbstract) TableName() string {
- return "wechat_article_abstract"
- }
- // WechatArticleAbstractColumns get sql column name.获取数据库列名
- var WechatArticleAbstractColumns = struct {
- WechatArticleAbstractID string
- WechatArticleID string
- Content string
- Version string
- ModifyTime string
- CreateTime string
- }{
- WechatArticleAbstractID: "wechat_article_abstract_id",
- WechatArticleID: "wechat_article_id",
- Content: "content",
- Version: "version",
- ModifyTime: "modify_time",
- CreateTime: "create_time",
- }
- func (m *WechatArticleAbstract) Create() (err error) {
- err = global.DbMap[utils.DbNameAI].Create(&m).Error
- return
- }
- func (m *WechatArticleAbstract) Update(updateCols []string) (err error) {
- err = global.DbMap[utils.DbNameAI].Select(updateCols).Updates(&m).Error
- return
- }
- func (m *WechatArticleAbstract) GetById(id int) (item *WechatArticleAbstract, err error) {
- err = global.DbMap[utils.DbNameAI].Where(fmt.Sprintf("%s = ?", WechatArticleAbstractColumns.WechatArticleAbstractID), id).First(&item).Error
- return
- }
- // GetByWechatArticleId
- // @Description: 根据报告id获取摘要
- // @author: Roc
- // @receiver m
- // @datetime 2025-03-07 10:00:59
- // @param id int
- // @return item *WechatArticleAbstract
- // @return err error
- func (m *WechatArticleAbstract) GetByWechatArticleId(id int) (item *WechatArticleAbstract, err error) {
- err = global.DbMap[utils.DbNameAI].Where(fmt.Sprintf("%s = ?", WechatArticleAbstractColumns.WechatArticleID), id).Order(fmt.Sprintf(`%s DESC`, WechatArticleAbstractColumns.WechatArticleAbstractID)).First(&item).Error
- return
- }
- func (m *WechatArticleAbstract) GetListByPlatformCondition(field, condition string, pars []interface{}, startSize, pageSize int) (items []*WechatArticleAndPlatform, err error) {
- if field == "" {
- field = "*"
- }
- sqlStr := fmt.Sprintf(`SELECT %s FROM %s AS a
- JOIN wechat_platform AS b ON a.wechat_platform_id=b.wechat_platform_id
- JOIN wechat_platform AS b ON a.wechat_platform_id=b.wechat_platform_id
- WHERE 1=1 AND a.is_deleted=0 %s order by a.article_create_time DESC,a.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 *WechatArticleAbstract) GetCountByPlatformCondition(condition string, pars []interface{}) (total int, err error) {
- var intNull sql.NullInt64
- sqlStr := fmt.Sprintf(`SELECT COUNT(1) total FROM %s AS a
- JOIN wechat_platform AS b ON a.wechat_platform_id=b.wechat_platform_id
- WHERE 1=1 AND a.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 *WechatArticleAbstract) GetPageListByPlatformCondition(condition string, pars []interface{}, startSize, pageSize int) (total int, items []*WechatArticleAndPlatform, err error) {
- total, err = m.GetCountByPlatformCondition(condition, pars)
- if err != nil {
- return
- }
- if total > 0 {
- items, err = m.GetListByPlatformCondition(`a.wechat_article_id,a.wechat_platform_id,a.fake_id,a.title,a.link,a.cover_url,a.description,a.country,a.province,a.city,a.article_create_time,a.modify_time,a.create_time,b.nickname,b.round_head_img`, condition, pars, startSize, pageSize)
- }
- return
- }
|