ai_summary_classify.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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. sql := ` SELECT COUNT(1) AS count FROM ai_summary AS a
  137. WHERE a.classify_id IN(
  138. SELECT t.ai_summary_classify_id FROM
  139. (
  140. SELECT rd.*
  141. FROM (SELECT * FROM ai_summary_classify WHERE parent_id IS NOT NULL) rd,
  142. (SELECT @pid := ?) pd
  143. WHERE FIND_IN_SET(parent_id, @pid) > 0
  144. AND @pid := CONCAT(@pid, ',', ai_summary_classify_id)
  145. UNION SELECT * FROM ai_summary_classify WHERE ai_summary_classify_id = @pid
  146. )AS t
  147. ) `
  148. err = global.DEFAULT_DmSQL.Raw(sql, classifyId).Scan(&count).Error
  149. return
  150. }
  151. type DeleteAiSummaryClassifyReq struct {
  152. AiSummaryClassifyId int `description:"分类id"`
  153. AiSummaryId int `description:"纪要id"`
  154. }
  155. // MoveAiSummaryClassifyReq 移动纪要分类请求参数
  156. type MoveAiSummaryClassifyReq struct {
  157. AiSummaryClassifyId int `description:"分类id"`
  158. AiSummaryId int `description:"纪要ID"`
  159. ParentClassifyId int `description:"父级分类id 移动纪要时为目标分类id"`
  160. PrevId int `description:"上一个兄弟节点分类id"`
  161. NextId int `description:"下一个兄弟节点分类id"`
  162. PrevType int `description:"上一个兄弟节点类型 1分类 2纪要 "`
  163. NextType int `description:"上一个兄弟节点类型 1分类 2纪要 "`
  164. }
  165. func GetAiSummaryClassifyById(classifyId int) (item *AiSummaryClassify, err error) {
  166. sql := `SELECT * FROM ai_summary_classify WHERE ai_summary_classify_id=? `
  167. err = global.DEFAULT_DmSQL.Raw(sql, classifyId).First(&item).Error
  168. return
  169. }
  170. func GetAiSummaryClassifyCountById(classifyId int) (count int, err error) {
  171. sql := `SELECT count(1) AS count FROM ai_summary_classify WHERE ai_summary_classify_id=? `
  172. err = global.DEFAULT_DmSQL.Raw(sql, classifyId).Scan(&count).Error
  173. return
  174. }
  175. // Update 更新沙盘分类基础信息
  176. func (aiSummaryClassify *AiSummaryClassify) Update(cols []string) (err error) {
  177. err = global.DEFAULT_DmSQL.Select(cols).Updates(aiSummaryClassify).Error
  178. return
  179. }
  180. // GetFirstAiSummaryClassifyByParentId 获取当前父级沙盘分类下的排序第一条的数据
  181. func GetFirstAiSummaryClassifyByParentId(parentId int) (item *AiSummaryClassify, err error) {
  182. sql := ` SELECT * FROM ai_summary_classify WHERE parent_id=? order by sort asc,ai_summary_classify_id asc limit 1`
  183. err = global.DEFAULT_DmSQL.Raw(sql, parentId).First(&item).Error
  184. return
  185. }
  186. // UpdateAiSummaryClassifySortByParentId 根据沙盘父类id更新排序
  187. func UpdateAiSummaryClassifySortByParentId(parentId, classifyId, nowSort int, updateSort string) (err error) {
  188. sql := ` update ai_summary_classify set sort = ` + updateSort + ` WHERE parent_id=? and sort > ? `
  189. if classifyId > 0 {
  190. sql += ` or ( ai_summary_classify_id > ` + fmt.Sprint(classifyId) + ` and sort= ` + fmt.Sprint(nowSort) + `)`
  191. }
  192. err = global.DEFAULT_DmSQL.Exec(sql, parentId, nowSort).Error
  193. return
  194. }
  195. func GetAiSummaryClassify(aiSummaryClassify int) (aiSummaryClassifyIds string, err error) {
  196. sql := `SELECT LISTAGG(t.ai_summary_classify_id) AS ai_summary_classify_id FROM (
  197. SELECT a.ai_summary_classify_id FROM ai_summary_classify AS a
  198. WHERE a.ai_summary_classify_id=?
  199. UNION ALL
  200. SELECT a.ai_summary_classify_id FROM ai_summary_classify AS a
  201. WHERE a.parent_id=? UNION ALL
  202. SELECT
  203. ai_summary_classify_id
  204. FROM
  205. ai_summary_classify
  206. WHERE
  207. parent_id IN ( SELECT ai_summary_classify_id FROM ai_summary_classify WHERE parent_id = ? )
  208. )AS t`
  209. err = global.DEFAULT_DmSQL.Raw(sql, aiSummaryClassify, aiSummaryClassify, aiSummaryClassify).Scan(&aiSummaryClassifyIds).Error
  210. return
  211. }
  212. type AiSummaryListResp struct {
  213. Paging *paging.PagingItem
  214. List []*AiSummaryItems
  215. }
  216. // GetAiSummaryClassifyAll
  217. func GetAiSummaryClassifyAll() (items []*AiSummaryClassifyItems, err error) {
  218. sql := ` SELECT * FROM ai_summary_classify WHERE parent_id<>0 order by sort asc,ai_summary_classify_id asc`
  219. err = global.DEFAULT_DmSQL.Raw(sql).Find(&items).Error
  220. return
  221. }
  222. // delBYids
  223. func DeleteAiSummaryClassifyByIds(ids []int) (err error) {
  224. sql := ` DELETE FROM ai_summary_classify WHERE ai_summary_classify_id in (` + utils.GetOrmInReplace(len(ids)) + `)`
  225. err = global.DEFAULT_DmSQL.Exec(sql, ids).Error
  226. return
  227. }