|
@@ -0,0 +1,272 @@
|
|
|
+package rag
|
|
|
+
|
|
|
+import (
|
|
|
+ "database/sql"
|
|
|
+ "eta/eta_api/global"
|
|
|
+ "eta/eta_api/utils"
|
|
|
+ "fmt"
|
|
|
+ "time"
|
|
|
+)
|
|
|
+
|
|
|
+// EtaReportAbstract 报告摘要
|
|
|
+type RagEtaReportAbstract struct {
|
|
|
+ RagEtaReportAbstractID int `gorm:"primaryKey;column:rag_eta_report_abstract_id" json:"-"`
|
|
|
+ RagEtaReportID int `gorm:"column:rag_eta_report_id" json:"ragEtaReportId"` // ETA报告id
|
|
|
+ Content string `gorm:"column:content" json:"content"` // 摘要内容
|
|
|
+ QuestionID int `gorm:"column:question_id" json:"questionId"` // 提示词Id
|
|
|
+ QuestionContent string `gorm:"column:question_content" json:"questionContent"`
|
|
|
+ Version int `gorm:"column:version" json:"version"` // 版本号
|
|
|
+ Tags string `gorm:"column:tags" json:"tags"` // 标签
|
|
|
+ VectorKey string `gorm:"column:vector_key" json:"vectorKey"` // 向量key标识
|
|
|
+ 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 *RagEtaReportAbstract) TableName() string {
|
|
|
+ return "eta_report_abstract"
|
|
|
+}
|
|
|
+
|
|
|
+// EtaReportAbstractColumns get sql column name.获取数据库列名
|
|
|
+var EtaReportAbstractColumns = struct {
|
|
|
+ RagEtaReportAbstractID string
|
|
|
+ RagEtaReportID string
|
|
|
+ Content string
|
|
|
+ QuestionID string
|
|
|
+ QuestionContent string
|
|
|
+ Version string
|
|
|
+ Tags string
|
|
|
+ VectorKey string
|
|
|
+ ModifyTime string
|
|
|
+ CreateTime string
|
|
|
+}{
|
|
|
+ RagEtaReportAbstractID: "rag_eta_report_abstract_id",
|
|
|
+ RagEtaReportID: "rag_eta_report_id",
|
|
|
+ Content: "content",
|
|
|
+ QuestionID: "question_id",
|
|
|
+ QuestionContent: "question_content",
|
|
|
+ Version: "version",
|
|
|
+ Tags: "tags",
|
|
|
+ VectorKey: "vector_key",
|
|
|
+ ModifyTime: "modify_time",
|
|
|
+ CreateTime: "create_time",
|
|
|
+}
|
|
|
+
|
|
|
+func (m *RagEtaReportAbstract) Create() (err error) {
|
|
|
+ err = global.DbMap[utils.DbNameAI].Create(&m).Error
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func (m *RagEtaReportAbstract) Update(updateCols []string) (err error) {
|
|
|
+ err = global.DbMap[utils.DbNameAI].Select(updateCols).Updates(&m).Error
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func (m *RagEtaReportAbstract) Del() (err error) {
|
|
|
+ err = global.DbMap[utils.DbNameAI].Delete(&m).Error
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func (m *RagEtaReportAbstract) GetById(id int) (item *RagEtaReportAbstract, err error) {
|
|
|
+ err = global.DbMap[utils.DbNameAI].Where(fmt.Sprintf("%s = ?", EtaReportAbstractColumns.RagEtaReportAbstractID), id).First(&item).Error
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func (m *RagEtaReportAbstract) GetByIdList(idList []int) (items []*RagEtaReportAbstract, err error) {
|
|
|
+ err = global.DbMap[utils.DbNameAI].Where(fmt.Sprintf("%s in (?) ", EtaReportAbstractColumns.RagEtaReportAbstractID), idList).Find(&items).Error
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func (m *RagEtaReportAbstract) GetListByCondition(field, condition string, pars []interface{}, startSize, pageSize int) (items []*RagEtaReportAbstract, err error) {
|
|
|
+ if field == "" {
|
|
|
+ field = "*"
|
|
|
+ }
|
|
|
+ sqlStr := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s order by rag_eta_report_abstract_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 *RagEtaReportAbstract) DelByIdList(idList []int) (err error) {
|
|
|
+ if len(idList) <= 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ sqlStr := fmt.Sprintf(`delete from %s where %s in (?)`, m.TableName(), EtaReportAbstractColumns.RagEtaReportAbstractID)
|
|
|
+ err = global.DbMap[utils.DbNameAI].Exec(sqlStr, idList).Error
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// GetByWechatArticleId
|
|
|
+// @Description: 根据报告id获取摘要
|
|
|
+// @author: Roc
|
|
|
+// @receiver m
|
|
|
+// @datetime 2025-03-07 10:00:59
|
|
|
+// @param id int
|
|
|
+// @return item *RagEtaReportAbstract
|
|
|
+// @return err error
|
|
|
+func (m *RagEtaReportAbstract) GetByWechatArticleId(id int) (item *RagEtaReportAbstract, err error) {
|
|
|
+ err = global.DbMap[utils.DbNameAI].Where(fmt.Sprintf("%s = ?", EtaReportAbstractColumns.RagEtaReportID), id).Order(fmt.Sprintf(`%s DESC`, EtaReportAbstractColumns.RagEtaReportAbstractID)).First(&item).Error
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+type EtaReportAbstractView struct {
|
|
|
+ RagEtaReportAbstractID int `gorm:"primaryKey;column:rag_eta_report_abstract_id" json:"-"`
|
|
|
+ RagEtaReportID int `gorm:"column:rag_eta_report_id" json:"ragEtaReportId"` // ETA报告id
|
|
|
+ Abstract string `gorm:"column:abstract;type:longtext;comment:摘要内容;" description:"摘要内容"`
|
|
|
+ QuestionID int `gorm:"column:question_id" json:"questionId"` // 提示词Id
|
|
|
+ QuestionContent string `gorm:"column:question_content" json:"questionContent"`
|
|
|
+ Version int `gorm:"column:version" json:"version"` // 版本号
|
|
|
+ Tags string `gorm:"column:tags" json:"tags"` // 标签
|
|
|
+ VectorKey string `gorm:"column:vector_key" json:"vectorKey"` // 向量key标识
|
|
|
+ ModifyTime string `gorm:"column:modify_time;type:datetime;default:NULL;" description:"modify_time"`
|
|
|
+ CreateTime string `gorm:"column:create_time;type:datetime;default:NULL;" description:"create_time"`
|
|
|
+ Title string `gorm:"column:title;type:varchar(255);comment:标题;" description:"标题"`
|
|
|
+ Link string `gorm:"column:link;type:varchar(255);comment:链接;" description:"链接"`
|
|
|
+}
|
|
|
+
|
|
|
+type RagEtaReportAbstractItem struct {
|
|
|
+ RagEtaReportAbstractID int `gorm:"primaryKey;column:rag_eta_report_abstract_id" json:"-"`
|
|
|
+ RagEtaReportID int `gorm:"column:rag_eta_report_id" json:"ragEtaReportId"` // ETA报告id
|
|
|
+ Abstract string `gorm:"column:abstract;type:longtext;comment:摘要内容;" description:"摘要内容"`
|
|
|
+ QuestionID int `gorm:"column:question_id" json:"questionId"` // 提示词Id
|
|
|
+ QuestionContent string `gorm:"column:question_content" json:"questionContent"`
|
|
|
+ Version int `gorm:"column:version" json:"version"` // 版本号
|
|
|
+ Tags string `gorm:"column:tags" json:"tags"` // 标签
|
|
|
+ VectorKey string `gorm:"column:vector_key" json:"vectorKey"` // 向量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"`
|
|
|
+ Title string `gorm:"column:title;type:varchar(255);comment:标题;" description:"标题"`
|
|
|
+ Link string `gorm:"column:link;type:varchar(255);comment:链接;" description:"链接"`
|
|
|
+}
|
|
|
+
|
|
|
+func (m *RagEtaReportAbstractItem) ToView() EtaReportAbstractView {
|
|
|
+ return EtaReportAbstractView{
|
|
|
+ RagEtaReportAbstractID: m.RagEtaReportAbstractID,
|
|
|
+ RagEtaReportID: m.RagEtaReportID,
|
|
|
+ Abstract: m.Abstract,
|
|
|
+ Version: m.Version,
|
|
|
+ VectorKey: m.VectorKey,
|
|
|
+ ModifyTime: utils.DateStrToDateTimeStr(m.ModifyTime),
|
|
|
+ CreateTime: utils.DateStrToDateTimeStr(m.CreateTime),
|
|
|
+ Title: m.Title,
|
|
|
+ Link: m.Link,
|
|
|
+ QuestionID: m.QuestionID,
|
|
|
+ Tags: m.Tags,
|
|
|
+ QuestionContent: m.QuestionContent,
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func (m *RagEtaReportAbstract) EtaReportAbstractItem(list []*RagEtaReportAbstractItem) (etaReportAbstractViewList []EtaReportAbstractView) {
|
|
|
+ etaReportAbstractViewList = make([]EtaReportAbstractView, 0)
|
|
|
+
|
|
|
+ for _, v := range list {
|
|
|
+ etaReportAbstractViewList = append(etaReportAbstractViewList, v.ToView())
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func (m *RagEtaReportAbstract) GetListByPlatformCondition(field, condition string, pars []interface{}, startSize, pageSize int) (items []*RagEtaReportAbstractItem, err error) {
|
|
|
+ if field == "" {
|
|
|
+ field = "*"
|
|
|
+ }
|
|
|
+ sqlStr := fmt.Sprintf(`SELECT %s FROM %s AS a
|
|
|
+ JOIN wechat_article AS b ON a.rag_eta_report_id=b.rag_eta_report_id
|
|
|
+ JOIN wechat_platform AS c ON b.wechat_platform_id=c.wechat_platform_id
|
|
|
+ WHERE 1=1 AND b.is_deleted=0 %s order by a.modify_time DESC,a.rag_eta_report_abstract_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 *RagEtaReportAbstract) 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_article AS b ON a.rag_eta_report_id=b.rag_eta_report_id
|
|
|
+ JOIN wechat_platform AS c ON b.wechat_platform_id=c.wechat_platform_id
|
|
|
+ WHERE 1=1 AND b.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 *RagEtaReportAbstract) GetPageListByPlatformCondition(condition string, pars []interface{}, startSize, pageSize int) (total int, items []*RagEtaReportAbstractItem, err error) {
|
|
|
+
|
|
|
+ total, err = m.GetCountByPlatformCondition(condition, pars)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if total > 0 {
|
|
|
+ items, err = m.GetListByPlatformCondition(`a.rag_eta_report_abstract_id,a.rag_eta_report_id,a.content AS abstract,a.version,a.vector_key,b.title,b.link,a.modify_time,a.create_time`, condition, pars, startSize, pageSize)
|
|
|
+ }
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func (m *RagEtaReportAbstract) GetListByTagAndPlatformCondition(field, condition string, pars []interface{}, startSize, pageSize int) (items []*RagEtaReportAbstractItem, err error) {
|
|
|
+ if field == "" {
|
|
|
+ field = "*"
|
|
|
+ }
|
|
|
+ sqlStr := fmt.Sprintf(`SELECT %s FROM %s AS a
|
|
|
+ JOIN wechat_article AS b ON a.rag_eta_report_id=b.rag_eta_report_id
|
|
|
+ JOIN wechat_platform AS c ON b.wechat_platform_id=c.wechat_platform_id
|
|
|
+ JOIN wechat_platform_tag_mapping AS d ON c.wechat_platform_id=d.wechat_platform_id
|
|
|
+ WHERE 1=1 AND b.is_deleted=0 %s order by a.modify_time DESC,a.rag_eta_report_abstract_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 *RagEtaReportAbstract) GetCountByTagAndPlatformCondition(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_article AS b ON a.rag_eta_report_id=b.rag_eta_report_id
|
|
|
+ JOIN wechat_platform AS c ON b.wechat_platform_id=c.wechat_platform_id
|
|
|
+ JOIN wechat_platform_tag_mapping AS d ON c.wechat_platform_id=d.wechat_platform_id
|
|
|
+ WHERE 1=1 AND b.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 *RagEtaReportAbstract) GetPageListByTagAndPlatformCondition(condition string, pars []interface{}, startSize, pageSize int) (total int, items []*RagEtaReportAbstractItem, err error) {
|
|
|
+
|
|
|
+ total, err = m.GetCountByTagAndPlatformCondition(condition, pars)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if total > 0 {
|
|
|
+ items, err = m.GetListByTagAndPlatformCondition(`a.rag_eta_report_abstract_id,a.rag_eta_report_id,a.content AS abstract,a.version,a.vector_key,a.modify_time,a.create_time,b.title,b.link,d.tag_id`, condition, pars, startSize, pageSize)
|
|
|
+ }
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// DelVectorKey
|
|
|
+// @Description: 批量删除向量库
|
|
|
+// @author: Roc
|
|
|
+// @receiver m
|
|
|
+// @datetime 2025-03-12 16:47:52
|
|
|
+// @param ragEtaReportAbstractIdList []int
|
|
|
+// @return err error
|
|
|
+func (m *RagEtaReportAbstract) DelVectorKey(ragEtaReportAbstractIdList []int) (err error) {
|
|
|
+ sqlStr := fmt.Sprintf(`UPDATE %s set vector_key = '' WHERE rag_eta_report_abstract_id IN (?)`, m.TableName())
|
|
|
+ err = global.DbMap[utils.DbNameAI].Exec(sqlStr, ragEtaReportAbstractIdList).Error
|
|
|
+
|
|
|
+ return
|
|
|
+}
|