ai_summary_classify.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. package ai_summary
  2. import (
  3. "eta_gn/eta_api/global"
  4. "eta_gn/eta_api/utils"
  5. "fmt"
  6. "github.com/rdlucklib/rdluck_tools/paging"
  7. "time"
  8. )
  9. type AiSummaryClassify struct {
  10. AiSummaryClassifyId int `gorm:"primaryKey;column:ai_summary_classify_id;type:int(11);not null"`
  11. ClassifyName string `gorm:"column:classify_name;type:varchar(255);not null;default:''"` // 分类名称
  12. ParentId int `gorm:"column:parent_id;type:int(11);not null;default:0"` // 父级id
  13. CreateTime time.Time `gorm:"column:create_time;type:datetime"` // 创建时间
  14. ModifyTime time.Time `gorm:"column:modify_time;type:datetime"` // 修改时间
  15. SysUserId int `gorm:"index:idx_sys_user_id;column:sys_user_id;type:int(11)"` // 创建人id
  16. SysUserRealName string `gorm:"column:sys_user_real_name;type:varchar(50)"` // 创建人姓名
  17. Level int `gorm:"column:level;type:int(11);default:0"` // 层级
  18. Sort int `gorm:"column:sort;type:int(9) unsigned;default:10"` // 排序字段,越小越靠前,默认值:10
  19. RootId int `gorm:"column:root_id;type:int(11);not null;default:0"` // 顶级ID
  20. HasData int `gorm:"column:has_data;type:tinyint(4);default:0"` // 是否存在指标数据:1有,2:无
  21. }
  22. func AddAiSummaryClassify(item *AiSummaryClassify) (lastId int64, err error) {
  23. err = global.DEFAULT_DmSQL.Create(item).Error
  24. lastId = int64(item.AiSummaryClassifyId)
  25. return
  26. }
  27. type AiSummaryClassifyItems struct {
  28. AiSummaryClassifyId int `gorm:"primaryKey;column:ai_summary_classify_id;type:int(11);not null"`
  29. ClassifyName string `gorm:"column:classify_name;type:varchar(255);not null;default:''"` // 分类名称
  30. ParentId int `gorm:"column:parent_id;type:int(11);not null;default:0"` // 父级id
  31. CreateTime time.Time `gorm:"column:create_time;type:datetime"` // 创建时间
  32. ModifyTime time.Time `gorm:"column:modify_time;type:datetime"` // 修改时间
  33. SysUserId int `gorm:"index:idx_sys_user_id;column:sys_user_id;type:int(11)"` // 创建人id
  34. SysUserRealName string `gorm:"column:sys_user_real_name;type:varchar(50)"` // 创建人姓名
  35. Level int `gorm:"column:level;type:int(11);default:0"` // 层级
  36. Sort int `gorm:"column:sort;type:int(9) unsigned;default:10"` // 排序字段,越小越靠前,默认值:10
  37. RootId int `gorm:"column:root_id;type:int(11);not null;default:0"` // 顶级ID
  38. HasData int `gorm:"column:has_data;type:tinyint(4);default:0"` // 是否存在指标数据:1有,2:无
  39. AiSummaryId int `description:"纪要id" gorm:"ai_summary_id"`
  40. UniqueCode string `description:"唯一编码" gorm:"-"`
  41. Children []*AiSummaryClassifyItems `gorm:"-"`
  42. }
  43. type AiSummaryClassifyListResp struct {
  44. AllNodes []*AiSummaryClassifyItems
  45. }
  46. // GetAiSummaryClassifyByParentId
  47. func GetAiSummaryClassifyByParentId(parentId int) (items []*AiSummaryClassifyItems, err error) {
  48. sql := ` SELECT * FROM ai_summary_classify WHERE parent_id=? order by sort asc,ai_summary_classify_id asc`
  49. err = global.DEFAULT_DmSQL.Raw(sql, parentId).Find(&items).Error
  50. return
  51. }
  52. // GetAiSummaryInfoByAdminId 获取所有我创建的纪要,用于分类展示
  53. func GetAiSummaryInfoByAdminId(adminId int) (items []*AiSummaryClassifyItems, err error) {
  54. sql := ` SELECT
  55. a.*,
  56. b.ai_summary_classify_id,
  57. b.classify_name
  58. FROM
  59. ai_summary AS a
  60. JOIN ai_summary_classify AS b ON a.classify_id = b.ai_summary_classify_id
  61. WHERE
  62. a.sys_user_id = ?
  63. ORDER BY
  64. a.sort ASC,
  65. a.create_time ASC `
  66. err = global.DEFAULT_DmSQL.Raw(sql, adminId).Find(&items).Error
  67. return
  68. }
  69. // GetAiSummaryClassifyAndInfoByParentId
  70. func GetAiSummaryClassifyAndInfoByParentId(parentId int) (items []*AiSummaryClassifyItems, err error) {
  71. sql := ` SELECT
  72. 0 AS ai_summary_id,
  73. ai_summary_classify_id,
  74. classify_name,
  75. parent_id,
  76. create_time,
  77. modify_time,
  78. sys_user_id,
  79. sys_user_real_name AS sys_user_real_name,
  80. sort,
  81. level
  82. FROM
  83. ai_summary_classify
  84. WHERE
  85. parent_id = ? UNION ALL
  86. SELECT
  87. ai_summary_id,
  88. classify_id as ai_summary_classify_id,
  89. title AS classify_name,
  90. 0 AS parent_id,
  91. create_time,
  92. modify_time,
  93. sys_user_id,
  94. sys_user_real_name,
  95. sort,
  96. 0 AS level
  97. FROM
  98. ai_summary
  99. WHERE
  100. classify_id = ?
  101. ORDER BY
  102. sort ASC,
  103. ai_summary_classify_id ASC`
  104. err = global.DEFAULT_DmSQL.Raw(sql, parentId, parentId).Find(&items).Error
  105. return
  106. }
  107. type AddAiSummaryClassifyReq struct {
  108. ClassifyName string `description:"分类名称"`
  109. ParentId int `description:"父级id,第一级传0"`
  110. Level int `description:"层级,第一级传0,其余传上一级的层级"`
  111. }
  112. func GetAiSummaryClassifyCount(classifyName string, parentId int) (count int, err error) {
  113. sql := `SELECT COUNT(1) AS count FROM ai_summary_classify WHERE parent_id=? AND classify_name=? `
  114. err = global.DEFAULT_DmSQL.Raw(sql, parentId, classifyName).Scan(&count).Error
  115. return
  116. }
  117. // GetAiSummaryClassifyMaxSort 获取ai纪要下最大的排序数
  118. func GetAiSummaryClassifyMaxSort(parentId int) (sort int, err error) {
  119. sql := `SELECT COALESCE(MAX(sort), 0) AS sort FROM ai_summary_classify WHERE parent_id=? `
  120. err = global.DEFAULT_DmSQL.Raw(sql, parentId).Scan(&sort).Error
  121. return
  122. }
  123. type EditAiSummaryClassifyReq struct {
  124. ClassifyName string `description:"分类名称"`
  125. AiSummaryClassifyId int `description:"分类id"`
  126. }
  127. func EditSandboxClassify(classifyId int, classifyName string) (err error) {
  128. sql := `UPDATE ai_summary_classify SET classify_name=?, modify_time=NOW() WHERE ai_summary_classify_id=? `
  129. err = global.DEFAULT_DmSQL.Exec(sql, classifyName, classifyId).Error
  130. return
  131. }
  132. type AiSummaryClassifyDeleteCheckReq struct {
  133. AiSummaryClassifyId int `description:"分类id"`
  134. }
  135. func GetAiSummaryInfoCountByClassifyId(classifyId int) (count int, err error) {
  136. var pars []interface{}
  137. var sql string
  138. sql = `WITH RECURSIVE ai_summary_classify_cte (ai_summary_classify_id, parent_id) AS (
  139. SELECT ai_summary_classify_id, parent_id
  140. FROM ai_summary_classify
  141. WHERE parent_id = ?
  142. UNION ALL
  143. SELECT c.ai_summary_classify_id, c.parent_id
  144. FROM ai_summary_classify c
  145. INNER JOIN ai_summary_classify_cte ct ON c.parent_id = ct.ai_summary_classify_id
  146. )
  147. SELECT COUNT(1) AS count
  148. FROM ai_summary a
  149. WHERE a.classify_id IN (
  150. SELECT ai_summary_classify_id
  151. FROM ai_summary_classify_cte
  152. UNION
  153. SELECT ai_summary_classify_id
  154. FROM ai_summary_classify
  155. WHERE ai_summary_classify_id = ?
  156. )`
  157. pars = append(pars, classifyId, classifyId)
  158. err = global.DEFAULT_DmSQL.Raw(sql, pars...).Scan(&count).Error
  159. return
  160. }
  161. type DeleteAiSummaryClassifyReq struct {
  162. AiSummaryClassifyId int `description:"分类id"`
  163. AiSummaryId int `description:"纪要id"`
  164. }
  165. // MoveAiSummaryClassifyReq 移动纪要分类请求参数
  166. type MoveAiSummaryClassifyReq struct {
  167. AiSummaryClassifyId int `description:"分类id"`
  168. AiSummaryId int `description:"纪要ID"`
  169. ParentClassifyId int `description:"父级分类id 移动纪要时为目标分类id"`
  170. PrevId int `description:"上一个兄弟节点分类id"`
  171. NextId int `description:"下一个兄弟节点分类id"`
  172. PrevType int `description:"上一个兄弟节点类型 1分类 2纪要 "`
  173. NextType int `description:"上一个兄弟节点类型 1分类 2纪要 "`
  174. }
  175. func GetAiSummaryClassifyById(classifyId int) (item *AiSummaryClassify, err error) {
  176. sql := `SELECT * FROM ai_summary_classify WHERE ai_summary_classify_id=? `
  177. err = global.DEFAULT_DmSQL.Raw(sql, classifyId).First(&item).Error
  178. return
  179. }
  180. func GetAiSummaryClassifyCountById(classifyId int) (count int, err error) {
  181. sql := `SELECT count(1) AS count FROM ai_summary_classify WHERE ai_summary_classify_id=? `
  182. err = global.DEFAULT_DmSQL.Raw(sql, classifyId).Scan(&count).Error
  183. return
  184. }
  185. // Update 更新沙盘分类基础信息
  186. func (aiSummaryClassify *AiSummaryClassify) Update(cols []string) (err error) {
  187. err = global.DEFAULT_DmSQL.Select(cols).Updates(aiSummaryClassify).Error
  188. return
  189. }
  190. // GetFirstAiSummaryClassifyByParentId 获取当前父级沙盘分类下的排序第一条的数据
  191. func GetFirstAiSummaryClassifyByParentId(parentId int) (item *AiSummaryClassify, err error) {
  192. sql := ` SELECT * FROM ai_summary_classify WHERE parent_id=? order by sort asc,ai_summary_classify_id asc limit 1`
  193. err = global.DEFAULT_DmSQL.Raw(sql, parentId).First(&item).Error
  194. return
  195. }
  196. // UpdateAiSummaryClassifySortByParentId 根据沙盘父类id更新排序
  197. func UpdateAiSummaryClassifySortByParentId(parentId, classifyId, nowSort int, updateSort string) (err error) {
  198. sql := ` update ai_summary_classify set sort = ` + updateSort + ` WHERE parent_id=? and sort > ? `
  199. if classifyId > 0 {
  200. sql += ` or ( ai_summary_classify_id > ` + fmt.Sprint(classifyId) + ` and sort= ` + fmt.Sprint(nowSort) + `)`
  201. }
  202. err = global.DEFAULT_DmSQL.Exec(sql, parentId, nowSort).Error
  203. return
  204. }
  205. func GetAiSummaryClassify(aiSummaryClassify int) (aiSummaryClassifyIds string, err error) {
  206. sql := `SELECT LISTAGG(t.ai_summary_classify_id) AS ai_summary_classify_id FROM (
  207. SELECT a.ai_summary_classify_id FROM ai_summary_classify AS a
  208. WHERE a.ai_summary_classify_id=?
  209. UNION ALL
  210. SELECT a.ai_summary_classify_id FROM ai_summary_classify AS a
  211. WHERE a.parent_id=? UNION ALL
  212. SELECT
  213. ai_summary_classify_id
  214. FROM
  215. ai_summary_classify
  216. WHERE
  217. parent_id IN ( SELECT ai_summary_classify_id FROM ai_summary_classify WHERE parent_id = ? )
  218. )AS t`
  219. err = global.DEFAULT_DmSQL.Raw(sql, aiSummaryClassify, aiSummaryClassify, aiSummaryClassify).Scan(&aiSummaryClassifyIds).Error
  220. return
  221. }
  222. type AiSummaryListResp struct {
  223. Paging *paging.PagingItem
  224. List []*AiSummaryItems
  225. }
  226. // GetAiSummaryClassifyAll
  227. func GetAiSummaryClassifyAll() (items []*AiSummaryClassifyItems, err error) {
  228. sql := ` SELECT * FROM ai_summary_classify WHERE parent_id<>0 order by sort asc,ai_summary_classify_id asc`
  229. err = global.DEFAULT_DmSQL.Raw(sql).Find(&items).Error
  230. return
  231. }
  232. // delBYids
  233. func DeleteAiSummaryClassifyByIds(ids []int) (err error) {
  234. sql := ` DELETE FROM ai_summary_classify WHERE ai_summary_classify_id in (` + utils.GetOrmInReplace(len(ids)) + `)`
  235. err = global.DEFAULT_DmSQL.Exec(sql, ids).Error
  236. return
  237. }