ai_summary_classify.go 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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. func GetAiSummaryClassifyByParentId(parentId int) (items []*AiSummaryClassifyItems, err error) {
  47. sql := ` SELECT * FROM ai_summary_classify WHERE parent_id=? order by sort asc,ai_summary_classify_id asc`
  48. err = global.DEFAULT_DmSQL.Raw(sql, parentId).Find(&items).Error
  49. return
  50. }
  51. func GetAiSummaryInfoByAdminId(adminId int) (items []*AiSummaryClassifyItems, err error) {
  52. sql := ` SELECT
  53. a.*,
  54. b.ai_summary_classify_id,
  55. b.classify_name
  56. FROM
  57. ai_summary AS a
  58. JOIN ai_summary_classify AS b ON a.classify_id = b.ai_summary_classify_id
  59. WHERE
  60. a.sys_user_id = ?
  61. ORDER BY
  62. a.sort ASC,
  63. a.create_time ASC `
  64. err = global.DEFAULT_DmSQL.Raw(sql, adminId).Find(&items).Error
  65. return
  66. }
  67. func GetAiSummaryClassifyAndInfoByParentId(parentId int) (items []*AiSummaryClassifyItems, err error) {
  68. sql := ` SELECT
  69. 0 AS ai_summary_id,
  70. ai_summary_classify_id,
  71. classify_name,
  72. parent_id,
  73. create_time,
  74. modify_time,
  75. sys_user_id,
  76. sys_user_real_name AS sys_user_real_name,
  77. sort,
  78. level
  79. FROM
  80. ai_summary_classify
  81. WHERE
  82. parent_id = ? UNION ALL
  83. SELECT
  84. ai_summary_id,
  85. classify_id as ai_summary_classify_id,
  86. title AS classify_name,
  87. 0 AS parent_id,
  88. create_time,
  89. modify_time,
  90. sys_user_id,
  91. sys_user_real_name,
  92. sort,
  93. 0 AS level
  94. FROM
  95. ai_summary
  96. WHERE
  97. classify_id = ?
  98. ORDER BY
  99. sort ASC,
  100. ai_summary_classify_id ASC`
  101. err = global.DEFAULT_DmSQL.Raw(sql, parentId, parentId).Find(&items).Error
  102. return
  103. }
  104. type AddAiSummaryClassifyReq struct {
  105. ClassifyName string `description:"分类名称"`
  106. ParentId int `description:"父级id,第一级传0"`
  107. Level int `description:"层级,第一级传0,其余传上一级的层级"`
  108. }
  109. func GetAiSummaryClassifyCount(classifyName string, parentId int) (count int, err error) {
  110. sql := `SELECT COUNT(1) AS count FROM ai_summary_classify WHERE parent_id=? AND classify_name=? `
  111. err = global.DEFAULT_DmSQL.Raw(sql, parentId, classifyName).Scan(&count).Error
  112. return
  113. }
  114. func GetAiSummaryClassifyMaxSort(parentId int) (sort int, err error) {
  115. sql := `SELECT COALESCE(MAX(sort), 0) AS sort FROM ai_summary_classify WHERE parent_id=? `
  116. err = global.DEFAULT_DmSQL.Raw(sql, parentId).Scan(&sort).Error
  117. return
  118. }
  119. type EditAiSummaryClassifyReq struct {
  120. ClassifyName string `description:"分类名称"`
  121. AiSummaryClassifyId int `description:"分类id"`
  122. }
  123. func EditSandboxClassify(classifyId int, classifyName string) (err error) {
  124. sql := `UPDATE ai_summary_classify SET classify_name=?, modify_time=NOW() WHERE ai_summary_classify_id=? `
  125. err = global.DEFAULT_DmSQL.Exec(sql, classifyName, classifyId).Error
  126. return
  127. }
  128. type AiSummaryClassifyDeleteCheckReq struct {
  129. AiSummaryClassifyId int `description:"分类id"`
  130. }
  131. func GetAiSummaryInfoCountByClassifyId(classifyId int) (count int, err error) {
  132. sql := ` SELECT COUNT(1) AS count FROM ai_summary AS a
  133. WHERE a.classify_id IN(
  134. SELECT t.ai_summary_classify_id FROM
  135. (
  136. SELECT rd.*
  137. FROM (SELECT * FROM ai_summary_classify WHERE parent_id IS NOT NULL) rd,
  138. (SELECT @pid := ?) pd
  139. WHERE FIND_IN_SET(parent_id, @pid) > 0
  140. AND @pid := CONCAT(@pid, ',', ai_summary_classify_id)
  141. UNION SELECT * FROM ai_summary_classify WHERE ai_summary_classify_id = @pid
  142. )AS t
  143. ) `
  144. err = global.DEFAULT_DmSQL.Raw(sql, classifyId).Scan(&count).Error
  145. return
  146. }
  147. type DeleteAiSummaryClassifyReq struct {
  148. AiSummaryClassifyId int `description:"分类id"`
  149. AiSummaryId int `description:"纪要id"`
  150. }
  151. type MoveAiSummaryClassifyReq struct {
  152. AiSummaryClassifyId int `description:"分类id"`
  153. AiSummaryId int `description:"纪要ID"`
  154. ParentClassifyId int `description:"父级分类id 移动纪要时为目标分类id"`
  155. PrevId int `description:"上一个兄弟节点分类id"`
  156. NextId int `description:"下一个兄弟节点分类id"`
  157. PrevType int `description:"上一个兄弟节点类型 1分类 2纪要 "`
  158. NextType int `description:"上一个兄弟节点类型 1分类 2纪要 "`
  159. }
  160. func GetAiSummaryClassifyById(classifyId int) (item *AiSummaryClassify, err error) {
  161. sql := `SELECT * FROM ai_summary_classify WHERE ai_summary_classify_id=? `
  162. err = global.DEFAULT_DmSQL.Raw(sql, classifyId).First(&item).Error
  163. return
  164. }
  165. func GetAiSummaryClassifyCountById(classifyId int) (count int, err error) {
  166. sql := `SELECT count(1) AS count FROM ai_summary_classify WHERE ai_summary_classify_id=? `
  167. err = global.DEFAULT_DmSQL.Raw(sql, classifyId).Scan(&count).Error
  168. return
  169. }
  170. func (aiSummaryClassify *AiSummaryClassify) Update(cols []string) (err error) {
  171. err = global.DEFAULT_DmSQL.Select(cols).Updates(aiSummaryClassify).Error
  172. return
  173. }
  174. func GetFirstAiSummaryClassifyByParentId(parentId int) (item *AiSummaryClassify, err error) {
  175. sql := ` SELECT * FROM ai_summary_classify WHERE parent_id=? order by sort asc,ai_summary_classify_id asc limit 1`
  176. err = global.DEFAULT_DmSQL.Raw(sql, parentId).First(&item).Error
  177. return
  178. }
  179. func UpdateAiSummaryClassifySortByParentId(parentId, classifyId, nowSort int, updateSort string) (err error) {
  180. sql := ` update ai_summary_classify set sort = ` + updateSort + ` WHERE parent_id=? and sort > ? `
  181. if classifyId > 0 {
  182. sql += ` or ( ai_summary_classify_id > ` + fmt.Sprint(classifyId) + ` and sort= ` + fmt.Sprint(nowSort) + `)`
  183. }
  184. err = global.DEFAULT_DmSQL.Exec(sql, parentId, nowSort).Error
  185. return
  186. }
  187. func GetAiSummaryClassify(aiSummaryClassify int) (aiSummaryClassifyIds string, err error) {
  188. sql := `SELECT LISTAGG(t.ai_summary_classify_id) AS ai_summary_classify_id FROM (
  189. SELECT a.ai_summary_classify_id FROM ai_summary_classify AS a
  190. WHERE a.ai_summary_classify_id=?
  191. UNION ALL
  192. SELECT a.ai_summary_classify_id FROM ai_summary_classify AS a
  193. WHERE a.parent_id=? UNION ALL
  194. SELECT
  195. ai_summary_classify_id
  196. FROM
  197. ai_summary_classify
  198. WHERE
  199. parent_id IN ( SELECT ai_summary_classify_id FROM ai_summary_classify WHERE parent_id = ? )
  200. )AS t`
  201. err = global.DEFAULT_DmSQL.Raw(sql, aiSummaryClassify, aiSummaryClassify, aiSummaryClassify).Scan(&aiSummaryClassifyIds).Error
  202. return
  203. }
  204. type AiSummaryListResp struct {
  205. Paging *paging.PagingItem
  206. List []*AiSummaryItems
  207. }
  208. func GetAiSummaryClassifyAll() (items []*AiSummaryClassifyItems, err error) {
  209. sql := ` SELECT * FROM ai_summary_classify WHERE parent_id<>0 order by sort asc,ai_summary_classify_id asc`
  210. err = global.DEFAULT_DmSQL.Raw(sql).Find(&items).Error
  211. return
  212. }
  213. func DeleteAiSummaryClassifyByIds(ids []int) (err error) {
  214. sql := ` DELETE FROM ai_summary_classify WHERE ai_summary_classify_id in (` + utils.GetOrmInReplace(len(ids)) + `)`
  215. err = global.DEFAULT_DmSQL.Exec(sql, ids).Error
  216. return
  217. }