classify.go 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. package help_doc
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "time"
  6. )
  7. type HelpDocClassify struct {
  8. ClassifyId int `orm:"column(classify_id);pk"`
  9. ClassifyName string `description:"分类名称"`
  10. ParentId int `description:"父级id"`
  11. CreateTime time.Time `description:"创建时间"`
  12. ModifyTime time.Time `description:"修改时间"`
  13. SysUserId int `description:"创建人id"`
  14. SysUserRealName string `description:"创建人姓名"`
  15. Level int `description:"层级"`
  16. Sort int `description:"排序字段,越小越靠前,默认值:10"`
  17. }
  18. func AddHelpDocClassify(item *HelpDocClassify) (lastId int64, err error) {
  19. o := orm.NewOrm()
  20. lastId, err = o.Insert(item)
  21. return
  22. }
  23. type AddHelpDocClassifyReq struct {
  24. HelpDocClassifyName string `description:"分类名称"`
  25. ParentId int `description:"父级id,第一级传0"`
  26. Level int `description:"层级,第一级传0,其余传上一级的层级"`
  27. }
  28. func GetHelpDocClassifyCount(HelpDocClassifyName string, parentId int) (count int, err error) {
  29. o := orm.NewOrm()
  30. sql := `SELECT COUNT(1) AS count FROM help_doc_classify WHERE parent_id=? AND classify_name=? `
  31. err = o.Raw(sql, parentId, HelpDocClassifyName).QueryRow(&count)
  32. return
  33. }
  34. type EditHelpDocClassifyReq struct {
  35. HelpDocClassifyName string `description:"分类名称"`
  36. HelpDocClassifyId int `description:"分类id"`
  37. }
  38. func GetHelpDocClassifyById(classifyId int) (item *HelpDocClassify, err error) {
  39. o := orm.NewOrm()
  40. sql := `SELECT * FROM help_doc_classify WHERE classify_id=? `
  41. err = o.Raw(sql, classifyId).QueryRow(&item)
  42. return
  43. }
  44. func GetHelpDocClassifyCountById(classifyId int) (count int, err error) {
  45. o := orm.NewOrm()
  46. sql := `SELECT count(1) AS count FROM help_doc_classify WHERE classify_id=? `
  47. err = o.Raw(sql, classifyId).QueryRow(&count)
  48. return
  49. }
  50. func EditHelpDocClassify(classifyId int, HelpDocClassifyName string) (err error) {
  51. o := orm.NewOrm()
  52. sql := `UPDATE help_doc_classify SET classify_name=?, modify_time=NOW() WHERE classify_id=? `
  53. _, err = o.Raw(sql, HelpDocClassifyName, classifyId).Exec()
  54. return
  55. }
  56. // GetHelpDocClassifyByParentId
  57. func GetHelpDocClassifyByParentId(parentId int, keyWord string) (items []HelpDocClassifyItems, err error) {
  58. o := orm.NewOrm()
  59. sql := ``
  60. if keyWord != ""{
  61. sql = ` SELECT * FROM help_doc_classify WHERE parent_id=? AND (classify_name LIKE '%` + keyWord + `%' ) order by sort asc,classify_id asc`
  62. } else {
  63. sql = ` SELECT * FROM help_doc_classify WHERE parent_id=? order by sort asc,classify_id asc`
  64. }
  65. _, err = o.Raw(sql, parentId).QueryRows(&items)
  66. return
  67. }
  68. // GetHelpDocClassifyAll
  69. func GetHelpDocClassifyAll(keyWord string) (items []*HelpDocClassifyItems, err error) {
  70. o := orm.NewOrm()
  71. sql := ``
  72. if keyWord != ""{
  73. sql = ` SELECT * FROM help_doc_classify WHERE parent_id<>0 AND (classify_name LIKE '%` + keyWord + `%' ) order by sort asc,classify_id asc`
  74. } else {
  75. sql = ` SELECT * FROM help_doc_classify WHERE parent_id<>0 order by sort asc,classify_id asc`
  76. }
  77. _, err = o.Raw(sql).QueryRows(&items)
  78. return
  79. }
  80. type HelpDocClassifyItems struct {
  81. ClassifyId int `description:"分类id"`
  82. ClassifyName string
  83. ParentId int
  84. Level int `description:"层级"`
  85. Sort int `description:"排序字段,越小越靠前,默认值:10"`
  86. SourceName string `description:"来源名称"`
  87. SysUserId int `description:"创建人id"`
  88. SysUserRealName string `description:"创建人姓名"`
  89. Children []*HelpDocClassifyItems
  90. }
  91. type HelpDocClassifyListResp struct {
  92. AllNodes []*HelpDocClassifyItems
  93. TwoLevelNodes []*HelpDocClassifyItems
  94. }
  95. type HelpDocClassifyDeleteCheckResp struct {
  96. DeleteStatus int `description:"检测状态:0:默认值,如果为0,继续走其他校验,1:该分类下关联不可删除,2:确认删除当前目录及包含的子目录吗"`
  97. TipsMsg string `description:"提示信息"`
  98. }
  99. type HelpDocClassifyDeleteCheckReq struct {
  100. HelpDocClassifyId int `description:"分类id"`
  101. ChartInfoId int `description:"指标id"`
  102. }
  103. func GetHelpDocClassifyByCondition(condition string, pars []interface{}) (item *HelpDocClassify, err error) {
  104. o := orm.NewOrm()
  105. sql := ` SELECT * FROM help_doc_classify WHERE 1=1 `
  106. if condition != "" {
  107. sql += condition
  108. }
  109. err = o.Raw(sql, pars).QueryRow(&item)
  110. return
  111. }
  112. // MoveHelpDocClassifyReq 移动分类请求参数
  113. type MoveHelpDocClassifyReq struct {
  114. ClassifyId int `description:"分类id"`
  115. ParentClassifyId int `description:"父级分类id"`
  116. PrevClassifyId int `description:"上一个兄弟节点分类id"`
  117. NextClassifyId int `description:"下一个兄弟节点分类id"`
  118. }
  119. // GetFirstHelpDocClassifyByParentId 获取当前父级分类下的排序第一条的数据
  120. func GetFirstHelpDocClassifyByParentId(parentId int) (item *HelpDocClassify, err error) {
  121. o := orm.NewOrm()
  122. sql := ` SELECT * FROM help_doc_classify WHERE parent_id=? order by sort asc,classify_id asc limit 1`
  123. err = o.Raw(sql, parentId).QueryRow(&item)
  124. return
  125. }
  126. // UpdateHelpDocClassifySortByParentId 根据父类id更新排序
  127. func UpdateHelpDocClassifySortByParentId(parentId, classifyId, nowSort int, updateSort string) (err error) {
  128. o := orm.NewOrm()
  129. sql := ` update help_doc_classify set sort = ` + updateSort + ` WHERE parent_id=? and sort > ? `
  130. if classifyId > 0 {
  131. sql += ` or ( classify_id > ` + fmt.Sprint(classifyId) + ` and sort= ` + fmt.Sprint(nowSort) + `)`
  132. }
  133. _, err = o.Raw(sql, parentId, nowSort).Exec()
  134. return
  135. }
  136. // Update 更新分类基础信息
  137. func (HelpDocClassify *HelpDocClassify) Update(cols []string) (err error) {
  138. o := orm.NewOrm()
  139. _, err = o.Update(HelpDocClassify, cols...)
  140. return
  141. }
  142. // GetHelpDocClassifyMaxSort 获取分类下最大的排序数
  143. func GetHelpDocClassifyMaxSort(parentId int) (sort int, err error) {
  144. o := orm.NewOrm()
  145. sql := `SELECT Max(sort) AS sort FROM help_doc_classify WHERE parent_id=? `
  146. err = o.Raw(sql, parentId).QueryRow(&sort)
  147. return
  148. }
  149. type HelpDocClassifyView struct {
  150. HelpDocClassifyId int `orm:"column(classify_id);pk"`
  151. HelpDocClassifyName string `description:"分类名称"`
  152. ParentId int `description:"父级id"`
  153. }
  154. func EditHelpDocClassifySysUser(classifyId, sysUserId int, HelpDocClassifyName string) (err error) {
  155. o := orm.NewOrm()
  156. sql := `UPDATE help_doc_classify SET sys_user_id=?,sys_user_real_name=?,modify_time=NOW() WHERE parent_id=? AND level=3 `
  157. _, err = o.Raw(sql, sysUserId, HelpDocClassifyName, classifyId).Exec()
  158. return
  159. }
  160. func GetHelpDocClassifyChildCounts(parentId int) (count int, err error) {
  161. o := orm.NewOrm()
  162. sql := `SELECT COUNT(1) AS count FROM help_doc_classify WHERE parent_id=? `
  163. err = o.Raw(sql, parentId).QueryRow(&count)
  164. return
  165. }
  166. func GetHelpDocCounts(classifyId int) (count int, err error) {
  167. o := orm.NewOrm()
  168. sql := `SELECT COUNT(1) AS count FROM help_doc WHERE classify_id=? `
  169. err = o.Raw(sql, classifyId).QueryRow(&count)
  170. return
  171. }
  172. // DeleteHelpDocClassify 删除分类
  173. func DeleteHelpDocClassify(classifyId int) (err error) {
  174. o := orm.NewOrm()
  175. sql := ` DELETE FROM help_doc_classify WHERE classify_id =? `
  176. _, err = o.Raw(sql, classifyId).Exec()
  177. return
  178. }
  179. // MoveClassifyReq 移动分类请求参数
  180. type MoveClassifyReq struct {
  181. ClassifyId int `description:"分类id"`
  182. ParentClassifyId int `description:"父级分类id"`
  183. PrevClassifyId int `description:"上一个兄弟节点分类id"`
  184. NextClassifyId int `description:"下一个兄弟节点分类id"`
  185. }
  186. // GetHelpDocClassifyLevel
  187. func GetHelpDocClassifyLevel() (items []*HelpDocClassifyItems, err error) {
  188. o := orm.NewOrm()
  189. sql := ``
  190. sql = ` SELECT * FROM help_doc_classify WHERE level IN (1,2) `
  191. _, err = o.Raw(sql).QueryRows(&items)
  192. return
  193. }
  194. type EditHelpDocClassifyVisibleReq struct {
  195. HelpDocClassifyId int `description:"分类id"`
  196. VisibleBusinessIds string
  197. }
  198. func EditHelpDocClassifyVisible(classifyId int, visibleBusinessIds string) (err error) {
  199. o := orm.NewOrm()
  200. sql := `UPDATE help_doc_classify SET visible_business_ids=?, modify_time=NOW() WHERE classify_id=? `
  201. _, err = o.Raw(sql, visibleBusinessIds, classifyId).Exec()
  202. return
  203. }