classify.go 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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. SysUserId int `description:"创建人id"`
  87. SysUserRealName string `description:"创建人姓名"`
  88. VisibleBusinessIds string
  89. Disabled bool `description:"是否能选 true不能 false可以"`
  90. Children []*HelpDocClassifyItems
  91. }
  92. type HelpDocClassifyListResp struct {
  93. AllNodes []*HelpDocClassifyItems
  94. TwoLevelNodes []*HelpDocClassifyItems
  95. }
  96. type HelpDocClassifyDeleteCheckResp struct {
  97. DeleteStatus int `description:"检测状态:0:默认值,如果为0,继续走其他校验,1:该分类下关联不可删除,2:确认删除当前目录及包含的子目录吗"`
  98. TipsMsg string `description:"提示信息"`
  99. }
  100. type HelpDocClassifyDeleteCheckReq struct {
  101. HelpDocClassifyId int `description:"分类id"`
  102. ChartInfoId int `description:"指标id"`
  103. }
  104. func GetHelpDocClassifyByCondition(condition string, pars []interface{}) (item *HelpDocClassify, err error) {
  105. o := orm.NewOrm()
  106. sql := ` SELECT * FROM help_doc_classify WHERE 1=1 `
  107. if condition != "" {
  108. sql += condition
  109. }
  110. err = o.Raw(sql, pars).QueryRow(&item)
  111. return
  112. }
  113. // MoveHelpDocClassifyReq 移动分类请求参数
  114. type MoveHelpDocClassifyReq struct {
  115. ClassifyId int `description:"分类id"`
  116. ParentClassifyId int `description:"父级分类id"`
  117. PrevClassifyId int `description:"上一个兄弟节点分类id"`
  118. NextClassifyId int `description:"下一个兄弟节点分类id"`
  119. }
  120. // GetFirstHelpDocClassifyByParentId 获取当前父级分类下的排序第一条的数据
  121. func GetFirstHelpDocClassifyByParentId(parentId int) (item *HelpDocClassify, err error) {
  122. o := orm.NewOrm()
  123. sql := ` SELECT * FROM help_doc_classify WHERE parent_id=? order by sort asc,classify_id asc limit 1`
  124. err = o.Raw(sql, parentId).QueryRow(&item)
  125. return
  126. }
  127. // UpdateHelpDocClassifySortByParentId 根据父类id更新排序
  128. func UpdateHelpDocClassifySortByParentId(parentId, classifyId, nowSort int, updateSort string) (err error) {
  129. o := orm.NewOrm()
  130. sql := ` update help_doc_classify set sort = ` + updateSort + ` WHERE parent_id=? and sort > ? `
  131. if classifyId > 0 {
  132. sql += ` or ( classify_id > ` + fmt.Sprint(classifyId) + ` and sort= ` + fmt.Sprint(nowSort) + `)`
  133. }
  134. _, err = o.Raw(sql, parentId, nowSort).Exec()
  135. return
  136. }
  137. // Update 更新分类基础信息
  138. func (HelpDocClassify *HelpDocClassify) Update(cols []string) (err error) {
  139. o := orm.NewOrm()
  140. _, err = o.Update(HelpDocClassify, cols...)
  141. return
  142. }
  143. // GetHelpDocClassifyMaxSort 获取分类下最大的排序数
  144. func GetHelpDocClassifyMaxSort(parentId int) (sort int, err error) {
  145. o := orm.NewOrm()
  146. sql := `SELECT Max(sort) AS sort FROM help_doc_classify WHERE parent_id=? `
  147. err = o.Raw(sql, parentId).QueryRow(&sort)
  148. return
  149. }
  150. type HelpDocClassifyView struct {
  151. HelpDocClassifyId int `orm:"column(classify_id);pk"`
  152. HelpDocClassifyName string `description:"分类名称"`
  153. ParentId int `description:"父级id"`
  154. }
  155. func EditHelpDocClassifySysUser(classifyId, sysUserId int, HelpDocClassifyName string) (err error) {
  156. o := orm.NewOrm()
  157. sql := `UPDATE help_doc_classify SET sys_user_id=?,sys_user_real_name=?,modify_time=NOW() WHERE parent_id=? AND level=3 `
  158. _, err = o.Raw(sql, sysUserId, HelpDocClassifyName, classifyId).Exec()
  159. return
  160. }
  161. func GetHelpDocClassifyChildCounts(parentId int) (count int, err error) {
  162. o := orm.NewOrm()
  163. sql := `SELECT COUNT(1) AS count FROM help_doc_classify WHERE parent_id=? `
  164. err = o.Raw(sql, parentId).QueryRow(&count)
  165. return
  166. }
  167. func GetHelpDocCounts(classifyId int) (count int, err error) {
  168. o := orm.NewOrm()
  169. sql := `SELECT COUNT(1) AS count FROM help_doc WHERE classify_id=? `
  170. err = o.Raw(sql, classifyId).QueryRow(&count)
  171. return
  172. }
  173. // DeleteHelpDocClassify 删除分类
  174. func DeleteHelpDocClassify(classifyId int) (err error) {
  175. o := orm.NewOrm()
  176. sql := ` DELETE FROM help_doc_classify WHERE classify_id =? `
  177. _, err = o.Raw(sql, classifyId).Exec()
  178. return
  179. }
  180. // MoveClassifyReq 移动分类请求参数
  181. type MoveClassifyReq struct {
  182. ClassifyId int `description:"分类id"`
  183. ParentClassifyId int `description:"父级分类id"`
  184. PrevClassifyId int `description:"上一个兄弟节点分类id"`
  185. NextClassifyId int `description:"下一个兄弟节点分类id"`
  186. }
  187. // GetHelpDocClassifyLevel
  188. func GetHelpDocClassifyLevel() (items []*HelpDocClassifyItems, err error) {
  189. o := orm.NewOrm()
  190. sql := ``
  191. sql = ` SELECT * FROM help_doc_classify WHERE level IN (1,2) `
  192. _, err = o.Raw(sql).QueryRows(&items)
  193. return
  194. }
  195. type EditHelpDocClassifyVisibleReq struct {
  196. HelpDocClassifyId int `description:"分类id"`
  197. VisibleBusinessIds string
  198. }
  199. func EditHelpDocClassifyVisible(classifyId int, visibleBusinessIds string) (err error) {
  200. o := orm.NewOrm()
  201. sql := `UPDATE help_doc_classify SET visible_business_ids=?, modify_time=NOW() WHERE classify_id=? `
  202. _, err = o.Raw(sql, visibleBusinessIds, classifyId).Exec()
  203. return
  204. }
  205. func AddAllHelpDocClassifyVisible(businessId int) (err error) {
  206. o := orm.NewOrm()
  207. sql := `UPDATE help_doc_classify set visible_business_ids=CONCAT(visible_business_ids,",", ?) where visible_business_ids !=""`
  208. _, err = o.Raw(sql, businessId).Exec()
  209. if err != nil {
  210. return
  211. }
  212. sql = `UPDATE help_doc_classify set visible_business_ids=CONCAT(visible_business_ids, ?) where visible_business_ids =""`
  213. _, err = o.Raw(sql, businessId).Exec()
  214. return
  215. }
  216. func GetAllHelpDocClassify() (items []*HelpDocClassifyItems, err error) {
  217. o := orm.NewOrm()
  218. sql := `SELECT * FROM help_doc_classify `
  219. _, err = o.Raw(sql).QueryRows(&items)
  220. return
  221. }
  222. func GetAllHelpDocClassifyByKeyword(keyword string) (items []*HelpDocClassifyItems, err error) {
  223. o := orm.NewOrm()
  224. sql := `SELECT * FROM help_doc_classify WHERE classify_name LIKE '%` + keyword + `%' `
  225. _, err = o.Raw(sql).QueryRows(&items)
  226. return
  227. }