123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338 |
- package ai_summary
- import (
- "fmt"
- "time"
- "github.com/beego/beego/v2/client/orm"
- "github.com/rdlucklib/rdluck_tools/paging"
- )
- type AiSummaryClassify struct {
- AiSummaryClassifyId int `orm:"column(ai_summary_classify_id);pk"` // ai纪要分类id
- ClassifyName string // 分类名称
- ParentId int // 父级id
- CreateTime time.Time // 创建时间
- ModifyTime time.Time // 修改时间
- SysUserId int // 创建人id,使用指针表示可为空
- SysUserRealName string // 创建人姓名
- Level int // 层级
- Sort int // 排序字段,越小越靠前,默认值:10
- RootId int // 顶级ID
- HasData int `description:"是否含有指标数据"`
- }
- func AddAiSummaryClassify(item *AiSummaryClassify) (lastId int64, err error) {
- o := orm.NewOrm()
- lastId, err = o.Insert(item)
- return
- }
- type AiSummaryClassifyItems struct {
- AiSummaryClassifyId int
- Title string `description:"标题" json:"-"`
- ClassifyName string `description:"分类名称"`
- ParentId int `description:"父级id"`
- HasData int `description:"是否含有指标数据"`
- CreateTime time.Time `description:"创建时间"`
- ModifyTime time.Time `description:"修改时间"`
- SysUserId int `description:"创建人id"`
- SysUserRealName string `description:"创建人姓名"`
- Level int `description:"层级"`
- Sort int `description:"排序字段,越小越靠前,默认值:10"`
- AiSummaryId int `description:"纪要id"`
- UniqueCode string `description:"唯一编码"`
- Children []*AiSummaryClassifyItems
- }
- type AiSummaryClassifyListResp struct {
- AllNodes []*AiSummaryClassifyItems
- }
- // GetAiSummaryClassifyByParentId
- func GetAiSummaryClassifyByParentId(parentId int) (items []*AiSummaryClassifyItems, err error) {
- o := orm.NewOrm()
- sql := ` SELECT * FROM ai_summary_classify WHERE parent_id=? order by sort asc,ai_summary_classify_id asc`
- _, err = o.Raw(sql, parentId).QueryRows(&items)
- return
- }
- // GetAiSummaryInfoByAdminId 获取所有我创建的纪要,用于分类展示
- func GetAiSummaryInfoByAdminId(adminId int) (items []*AiSummaryClassifyItems, err error) {
- o := orm.NewOrm()
- sql := ` SELECT
- a.*,
- b.ai_summary_classify_id,
- b.classify_name
- FROM
- ai_summary AS a
- JOIN ai_summary_classify AS b ON a.classify_id = b.ai_summary_classify_id
- WHERE
- a.sys_user_id = ?
- ORDER BY
- a.sort ASC,
- a.create_time ASC `
- _, err = o.Raw(sql, adminId).QueryRows(&items)
- return
- }
- // GetAiSummaryClassifyAndInfoByParentId
- func GetAiSummaryClassifyAndInfoByParentId(parentId int) (items []*AiSummaryClassifyItems, err error) {
- o := orm.NewOrm()
- sql := ` SELECT
- 0 AS ai_summary_id,
- ai_summary_classify_id,
- classify_name,
- parent_id,
- create_time,
- modify_time,
- sys_user_id,
- sys_user_real_name AS sys_user_real_name,
- sort,
- level
- FROM
- ai_summary_classify
- WHERE
- parent_id = ? UNION ALL
- SELECT
- ai_summary_id,
- classify_id as ai_summary_classify_id,
- title AS classify_name,
- 0 AS parent_id,
- create_time,
- modify_time,
- sys_user_id,
- sys_user_real_name,
- sort,
- 0 AS level
- FROM
- ai_summary
- WHERE
- classify_id = ?
- ORDER BY
- sort ASC,
- ai_summary_classify_id ASC`
- _, err = o.Raw(sql, parentId, parentId).QueryRows(&items)
- return
- }
- type AddAiSummaryClassifyReq struct {
- ClassifyName string `description:"分类名称"`
- ParentId int `description:"父级id,第一级传0"`
- Level int `description:"层级,第一级传0,其余传上一级的层级"`
- }
- func GetAiSummaryClassifyCount(classifyName string, parentId int) (count int, err error) {
- o := orm.NewOrm()
- sql := `SELECT COUNT(1) AS count FROM ai_summary_classify WHERE parent_id=? AND classify_name=? `
- err = o.Raw(sql, parentId, classifyName).QueryRow(&count)
- return
- }
- // GetAiSummaryClassifyMaxSort 获取ai纪要下最大的排序数
- func GetAiSummaryClassifyMaxSort(parentId int) (sort int, err error) {
- o := orm.NewOrm()
- sql := `SELECT Max(sort) AS sort FROM ai_summary_classify WHERE parent_id=? `
- err = o.Raw(sql, parentId).QueryRow(&sort)
- return
- }
- type EditAiSummaryClassifyReq struct {
- ClassifyName string `description:"分类名称"`
- AiSummaryClassifyId int `description:"分类id"`
- }
- func EditSandboxClassify(classifyId int, classifyName string) (err error) {
- o := orm.NewOrm()
- sql := `UPDATE ai_summary_classify SET classify_name=?, modify_time=NOW() WHERE ai_summary_classify_id=? `
- _, err = o.Raw(sql, classifyName, classifyId).Exec()
- return
- }
- type AiSummaryClassifyDeleteCheckReq struct {
- AiSummaryClassifyId int `description:"分类id"`
- }
- func GetAiSummaryInfoCountByClassifyId(classifyId int) (count int, err error) {
- o := orm.NewOrm()
- sql := ` SELECT COUNT(1) AS count FROM ai_summary AS a
- WHERE a.classify_id IN(
- SELECT t.ai_summary_classify_id FROM
- (
- SELECT rd.*
- FROM (SELECT * FROM ai_summary_classify WHERE parent_id IS NOT NULL) rd,
- (SELECT @pid := ?) pd
- WHERE FIND_IN_SET(parent_id, @pid) > 0
- AND @pid := CONCAT(@pid, ',', ai_summary_classify_id)
- UNION SELECT * FROM ai_summary_classify WHERE ai_summary_classify_id = @pid
- )AS t
- ) `
- err = o.Raw(sql, classifyId).QueryRow(&count)
- return
- }
- type DeleteAiSummaryClassifyReq struct {
- AiSummaryClassifyId int `description:"分类id"`
- AiSummaryId int `description:"纪要id"`
- }
- func DeleteAiSummaryClassify(classifyId int) (err error) {
- o := orm.NewOrm()
- sql := ` DELETE FROM ai_summary_classify
- WHERE ai_summary_classify_id IN(
- SELECT t.ai_summary_classify_id FROM
- (
- SELECT rd.*
- FROM (SELECT * FROM ai_summary_classify WHERE parent_id IS NOT NULL) rd,
- (SELECT @pid := ?) pd
- WHERE FIND_IN_SET(parent_id, @pid) > 0
- AND @pid := CONCAT(@pid, ',', ai_summary_classify_id)
- UNION SELECT * FROM ai_summary_classify WHERE ai_summary_classify_id = @pid
- )AS t
- ) `
- _, err = o.Raw(sql, classifyId).Exec()
- return
- }
- // MoveAiSummaryClassifyReq 移动纪要分类请求参数
- type MoveAiSummaryClassifyReq struct {
- AiSummaryClassifyId int `description:"分类id"`
- AiSummaryId int `description:"纪要ID"`
- ParentClassifyId int `description:"父级分类id 移动纪要时为目标分类id"`
- PrevId int `description:"上一个兄弟节点分类id"`
- NextId int `description:"下一个兄弟节点分类id"`
- PrevType int `description:"上一个兄弟节点类型 1分类 2纪要 "`
- NextType int `description:"上一个兄弟节点类型 1分类 2纪要 "`
- }
- func GetAiSummaryClassifyById(classifyId int) (item *AiSummaryClassify, err error) {
- o := orm.NewOrm()
- sql := `SELECT * FROM ai_summary_classify WHERE ai_summary_classify_id=? `
- err = o.Raw(sql, classifyId).QueryRow(&item)
- return
- }
- func GetAiSummaryClassifyCountById(classifyId int) (count int, err error) {
- o := orm.NewOrm()
- sql := `SELECT count(1) AS count FROM ai_summary_classify WHERE ai_summary_classify_id=? `
- err = o.Raw(sql, classifyId).QueryRow(&count)
- return
- }
- // Update 更新沙盘分类基础信息
- func (aiSummaryClassify *AiSummaryClassify) Update(cols []string) (err error) {
- o := orm.NewOrm()
- _, err = o.Update(aiSummaryClassify, cols...)
- return
- }
- // GetFirstAiSummaryClassifyByParentId 获取当前父级沙盘分类下的排序第一条的数据
- func GetFirstAiSummaryClassifyByParentId(parentId int) (item *AiSummaryClassify, err error) {
- o := orm.NewOrm()
- sql := ` SELECT * FROM ai_summary_classify WHERE parent_id=? order by sort asc,ai_summary_classify_id asc limit 1`
- err = o.Raw(sql, parentId).QueryRow(&item)
- return
- }
- // UpdateSandboxClassifySortByParentId 根据沙盘父类id更新排序
- func UpdateAiSummaryClassifySortByParentId(parentId, classifyId, nowSort int, updateSort string) (err error) {
- o := orm.NewOrm()
- sql := ` update ai_summary_classify set sort = ` + updateSort + ` WHERE parent_id=? and sort > ? `
- if classifyId > 0 {
- sql += ` or ( ai_summary_classify_id > ` + fmt.Sprint(classifyId) + ` and sort= ` + fmt.Sprint(nowSort) + `)`
- }
- _, err = o.Raw(sql, parentId, nowSort).Exec()
- return
- }
- // 获取所有子级分类id
- func GetAiSummaryClassifySubcategories(classifyId int) (Ids string, err error) {
- o := orm.NewOrm()
- sql := `SELECT GROUP_CONCAT(ai_summary_classify_id) AS ids
- FROM (
- SELECT @pv := ? AS ai_summary_classify_id
- UNION ALL
- SELECT sc.ai_summary_classify_id
- FROM ai_summary_classify sc
- JOIN (SELECT @pv := ?) initial
- WHERE sc.parent_id = @pv
- ) subcategories; `
- err = o.Raw(sql, classifyId, classifyId).QueryRow(&Ids)
- return
- }
- func GetAiSummaryClassify(aiSummaryClassify int) (aiSummaryClassifyIds string, err error) {
- o := orm.NewOrm()
- sql := `SELECT GROUP_CONCAT(t.ai_summary_classify_id) AS ai_summary_classify_id FROM (
- SELECT a.ai_summary_classify_id FROM ai_summary_classify AS a
- WHERE a.ai_summary_classify_id=?
- UNION ALL
- SELECT a.ai_summary_classify_id FROM ai_summary_classify AS a
- WHERE a.parent_id=? UNION ALL
- SELECT
- ai_summary_classify_id
- FROM
- ai_summary_classify
- WHERE
- parent_id IN ( SELECT ai_summary_classify_id FROM ai_summary_classify WHERE parent_id = ? )
- )AS t`
- err = o.Raw(sql, aiSummaryClassify, aiSummaryClassify, aiSummaryClassify).QueryRow(&aiSummaryClassifyIds)
- return
- }
- func GetAiSummaryAllParentByClassifyId(aiSummaryClassifyId int) (ids string, err error) {
- o := orm.NewOrm()
- sql := `SELECT
- GROUP_CONCAT(DISTINCT m.ai_summary_classify_id ORDER BY m.level) AS ids
- FROM
- (
- SELECT
- @id AS _id,(
- SELECT
- @id := parent_id
- FROM
- ai_summary_classify
- WHERE
- ai_summary_classify_id = _id
- )
- FROM
- (
- SELECT
- @id :=(
- SELECT
- parent_id
- FROM
- ai_summary_classify
- WHERE
- ai_summary_classify_id = ?
- )) vm,
- ai_summary_classify m
- WHERE
- @id IS NOT NULL
- ) vm
- INNER JOIN ai_summary_classify m
- WHERE
- ai_summary_classify_id = vm._id `
- err = o.Raw(sql, aiSummaryClassifyId).QueryRow(&ids)
- return
- }
- type AiSummaryListResp struct {
- Paging *paging.PagingItem
- List []*AiSummaryItems
- }
- // GetAiSummaryClassifyAll
- func GetAiSummaryClassifyAll() (items []*AiSummaryClassifyItems, err error) {
- o := orm.NewOrm()
- sql := ` SELECT * FROM ai_summary_classify WHERE parent_id<>0 order by sort asc,ai_summary_classify_id asc`
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- func GetAiSummaryClassifyAllIncludeParent() (items []*AiSummaryClassifyItems, err error) {
- o := orm.NewOrm()
- sql := ` SELECT * FROM ai_summary_classify order by sort asc,ai_summary_classify_id asc`
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
|