package ai_summary import ( "eta_gn/eta_api/global" "fmt" "time" ) type AiSummary struct { AiSummaryId int `gorm:"primaryKey;column:ai_summary_id;type:int(10) unsigned;not null"` // ai纪要id SaDocId int `gorm:"index:idx_doc_id;column:sa_doc_id;type:int(10) unsigned;not null;default:0"` // 文档ID OriginTitle string `gorm:"column:origin_title;type:varchar(255)"` // 原始内容标题 OriginContent string `gorm:"column:origin_content;type:text"` // 原始内容 ClassifyId int `gorm:"column:classify_id;type:int(11);not null"` // 分类id Title string `gorm:"column:title;type:varchar(255);not null;default:''"` // 文档标题 CreateTime time.Time `gorm:"column:create_time;type:datetime"` // 创建时间 ModifyTime time.Time `gorm:"column:modify_time;type:datetime"` // 更新时间 OpenaiFileName string `gorm:"column:openai_file_name;type:varchar(255);default:''"` // 文件名称 OpenaiFilePath string `gorm:"column:openai_file_path;type:varchar(255);default:''"` // 文件路径 SummaryContent string `gorm:"column:summary_content;type:longtext"` // ai纪要内容 Sort int `gorm:"column:sort;type:int(9) unsigned;default:10"` // 排序字段,越小越靠前,默认值:10 SysUserId int `gorm:"column:sys_user_id;type:int(11)"` // 创建人id SysUserRealName string `gorm:"column:sys_user_real_name;type:varchar(50)"` // 创建人姓名 } type AiSummaryItems struct { AiSummaryId int `gorm:"primaryKey;column:ai_summary_id;type:int(10) unsigned;not null"` // ai纪要id SaDocId int `gorm:"index:idx_doc_id;column:sa_doc_id;type:int(10) unsigned;not null;default:0"` // 文档ID OriginTitle string `gorm:"column:origin_title;type:varchar(255)"` // 原始内容标题 OriginContent string `gorm:"column:origin_content;type:text"` // 原始内容 ClassifyId int `gorm:"column:classify_id;type:int(11);not null"` // 分类id Title string `gorm:"column:title;type:varchar(255);not null;default:''"` // 文档标题 CreateTime string `gorm:"column:create_time;type:datetime"` // 创建时间 ModifyTime string `gorm:"column:modify_time;type:datetime"` // 更新时间 OpenaiFileName string `gorm:"column:openai_file_name;type:varchar(255);default:''"` // 文件名称 OpenaiFilePath string `gorm:"column:openai_file_path;type:varchar(255);default:''"` // 文件路径 SummaryContent string `gorm:"column:summary_content;type:longtext"` // ai纪要内容 Sort int `gorm:"column:sort;type:int(9) unsigned;default:10"` // 排序字段,越小越靠前,默认值:10 SysUserId int `gorm:"column:sys_user_id;type:int(11)"` // 创建人id SysUserRealName string `gorm:"column:sys_user_real_name;type:varchar(50)"` // 创建人姓名 ParentIds string `gorm:"-"` } // GetAiSummaryById 根据纪要id获取详情 func GetAiSummaryById(aiSummaryId int) (sandboxInfo *AiSummary, err error) { sql := `select * from ai_summary where ai_summary_id = ? ` err = global.DEFAULT_DmSQL.Raw(sql, aiSummaryId).First(&sandboxInfo).Error return } // GetAiSummaryItemById 根据纪要id获取详情 func GetAiSummaryItemById(aiSummaryId int) (sandboxInfo *AiSummaryItems, err error) { sql := `select * from ai_summary where ai_summary_id = ? ` err = global.DEFAULT_DmSQL.Raw(sql, aiSummaryId).First(&sandboxInfo).Error return } // DelAiSummaryById 根据纪要id删除纪要 func DelAiSummaryById(aiSummaryId int) (err error) { sql := `delete from ai_summary where ai_summary_id = ? ` err = global.DEFAULT_DmSQL.Exec(sql, aiSummaryId).Error return } func MoveAiSummary(aiSummaryId, classifyId int) (err error) { sql := `UPDATE ai_summary SET classify_id = ? WHERE ai_summary_id = ?` err = global.DEFAULT_DmSQL.Exec(sql, classifyId, aiSummaryId).Error return } // GetFirstAiSummaryByClassifyId 获取当前分类下,且排序数相同 的排序第一条的数据 func GetFirstAiSummaryByClassifyId(classifyId int) (item *AiSummary, err error) { sql := ` SELECT * FROM ai_summary WHERE classify_id=? order by sort asc,ai_summary_id asc limit 1` err = global.DEFAULT_DmSQL.Raw(sql, classifyId).First(&item).Error return } func (aiSummary *AiSummary) Update(cols []string) (err error) { err = global.DEFAULT_DmSQL.Select(cols).Updates(aiSummary).Error return } // UpdateAiSummarySortByClassifyId 根据纪要id更新排序 func UpdateAiSummarySortByClassifyId(classifyId, nowSort, prevAiSummaryId int, updateSort string) (err error) { sql := ` update ai_summary set sort = ` + updateSort + ` WHERE classify_id=? AND ` if prevAiSummaryId > 0 { sql += ` (sort > ? or (ai_summary_id > ` + fmt.Sprint(prevAiSummaryId) + ` and sort = ` + fmt.Sprint(nowSort) + `))` } err = global.DEFAULT_DmSQL.Exec(sql, classifyId, nowSort).Error return } func GetAiSummaryListByCondition(condition string, pars []interface{}, startSize, pageSize int) (item []*AiSummaryItems, err error) { sql := ` SELECT * FROM ai_summary WHERE 1=1 ` if condition != "" { sql += condition } sql += " ORDER BY create_time DESC LIMIT ?,? " pars = append(pars, startSize) pars = append(pars, pageSize) err = global.DEFAULT_DmSQL.Raw(sql, pars...).Find(&item).Error return } func GetAiSummaryListCountByCondition(condition string, pars []interface{}) (count int, err error) { sql := ` SELECT COUNT(1) AS count FROM ai_summary WHERE 1=1 ` if condition != "" { sql += condition } err = global.DEFAULT_DmSQL.Raw(sql, pars...).Scan(&count).Error return } func AddAiSummary(item *AiSummary) (lastId int64, err error) { err = global.DEFAULT_DmSQL.Create(item).Error lastId = int64(item.AiSummaryId) return } type AddAiSummaryReq struct { SaDocId int // 文档ID OriginContent string // 原始内容 SummaryContent string // 纪要内容 ClassifyId int // 分类id Title string // 文档标题 OpenaiFileName string // 文件名称 OpenaiFilePath string // 文件路径 OriginTitle string // 原文标题 } type GenerateAiSummaryReq struct { AiChatTopicId int `description:"主题id"` OriginContent string // 原始内容 OpenaiFileId []string `description:"openai返回的文件id"` Model string `description:"模型名称"` Prompt string `description:"提示词"` SaDocId int // 文档ID } // GetAiSummaryMaxSort 获取ai纪要下最大的排序数 func GetAiSummaryMaxSort(classifyId int) (sort int, err error) { sql := `SELECT COALESCE(MAX(sort), 0) AS sort FROM ai_summary WHERE parent_id=? ` err = global.DEFAULT_DmSQL.Raw(sql, classifyId).Scan(&sort).Error return } type AiSummaryAddResp struct { AiSummaryId int UniqueCode string // 唯一编码 ParentId int } type AiSummaryDetailResp struct { *AiSummaryItems SaDocTitle string `description:"文档库标题"` SaDocClassifyId int `description:"文档库分类id"` } func GetSummaryCountByCondition(condition string, pars []interface{}) (count int, err error) { sql := ` SELECT COUNT(1) AS count FROM ai_summary WHERE 1=1 ` if condition != "" { sql += condition } err = global.DEFAULT_DmSQL.Raw(sql, pars...).Scan(&count).Error return }