123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- package ai_summary
- import (
- "fmt"
- "github.com/beego/beego/v2/client/orm"
- "time"
- )
- type AiSummary struct {
- AiSummaryId int `orm:"column(ai_summary_id);pk"`
- SaDocId int
- OriginContent string
- SummaryContent string
- ClassifyId int
- SysUserId int
- SysUserRealName string
- Title string
- CreateTime time.Time
- ModifyTime time.Time
- OpenaiFileName string
- OpenaiFilePath string
- OriginTitle string
- Sort int
- }
- type AiSummaryItems struct {
- AiSummaryId int `orm:"column(ai_summary_id);pk"`
- SaDocId int
- OriginContent string
- OriginTitle string
- SummaryContent string
- ClassifyId int
- SysUserId int
- SysUserRealName string
- Title string
- CreateTime string
- ModifyTime string
- OpenaiFileName string
- OpenaiFilePath string
- Sort int
- ParentIds string
- }
- func GetAiChatTopicList(sysUserId int) (item []*AiSummary, err error) {
- sql := ` SELECT * FROM ai_summary WHERE classify_id=? ORDER BY create_time DESC `
- o := orm.NewOrm()
- _, err = o.Raw(sql, sysUserId).QueryRows(&item)
- return
- }
- func GetAiSummaryById(aiSummaryId int) (sandboxInfo *AiSummary, err error) {
- o := orm.NewOrm()
- sql := `select * from ai_summary where ai_summary_id = ? `
- err = o.Raw(sql, aiSummaryId).QueryRow(&sandboxInfo)
- return
- }
- func GetAiSummaryItemById(aiSummaryId int) (sandboxInfo *AiSummaryItems, err error) {
- o := orm.NewOrm()
- sql := `select * from ai_summary where ai_summary_id = ? `
- err = o.Raw(sql, aiSummaryId).QueryRow(&sandboxInfo)
- return
- }
- func DelAiSummaryById(aiSummaryId int) (err error) {
- o := orm.NewOrm()
- sql := `delete from ai_summary where ai_summary_id = ? `
- _, err = o.Raw(sql, aiSummaryId).Exec()
- return
- }
- func MoveAiSummary(aiSummaryId, classifyId int) (err error) {
- o := orm.NewOrm()
- sql := ` UPDATE ai_summary
- SET
- classify_id = ?
- WHERE ai_summary_id = ?`
- _, err = o.Raw(sql, classifyId, aiSummaryId).Exec()
- return
- }
- func GetFirstAiSummaryByClassifyId(classifyId int) (item *AiSummary, err error) {
- o := orm.NewOrm()
- sql := ` SELECT * FROM ai_summary WHERE classify_id=? order by sort asc,ai_summary_id asc limit 1`
- err = o.Raw(sql, classifyId).QueryRow(&item)
- return
- }
- func (aiSummary *AiSummary) Update(cols []string) (err error) {
- o := orm.NewOrm()
- _, err = o.Update(aiSummary, cols...)
- return
- }
- func UpdateAiSummarySortByClassifyId(classifyId, nowSort, prevAiSummaryId int, updateSort string) (err error) {
- o := orm.NewOrm()
- 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 = o.Raw(sql, classifyId, nowSort).Exec()
- return
- }
- func GetAiSummaryListByCondition(condition string, pars []interface{}, startSize, pageSize int) (item []*AiSummaryItems, err error) {
- o := orm.NewOrm()
- sql := ` SELECT * FROM ai_summary WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- sql += " ORDER BY create_time DESC LIMIT ?,? "
- _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&item)
- return
- }
- func GetAiSummaryListCountByCondition(condition string, pars []interface{}) (count int, err error) {
- o := orm.NewOrm()
- sql := ` SELECT COUNT(1) AS count FROM ai_summary WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- err = o.Raw(sql, pars).QueryRow(&count)
- return
- }
- func AddAiSummary(item *AiSummary) (lastId int64, err error) {
- o := orm.NewOrm()
- lastId, err = o.Insert(item)
- return
- }
- type AddAiSummaryReq struct {
- SaDocId int
- OriginContent string
- SummaryContent string
- ClassifyId int
- 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
- }
- func GetAiSummaryMaxSort(classifyId int) (sort int, err error) {
- o := orm.NewOrm()
- sql := `SELECT Max(sort) AS sort FROM ai_summary WHERE parent_id=? `
- err = o.Raw(sql, classifyId).QueryRow(&sort)
- return
- }
- type AiSummaryAddResp struct {
- AiSummaryId int
- UniqueCode string
- ParentId int
- }
- type AiSummaryDetailResp struct {
- *AiSummaryItems
- SaDocTitle string `description:"文档库标题"`
- SaDocClassifyId int `description:"文档库分类id"`
- }
|