classify.go 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. package models
  2. import (
  3. "eta_gn/eta_task/global"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "time"
  6. )
  7. type Classify struct {
  8. Id int `gorm:"column:id;primaryKey"` // `orm:"column(id);pk"`
  9. ClassifyName string `description:"分类名称"`
  10. Sort int `json:"-"`
  11. ParentId int `description:"父级分类id"`
  12. CreateTime time.Time `description:"创建时间"`
  13. ModifyTime time.Time `description:"修改时间"`
  14. Abstract string `description:"栏目简介"`
  15. Descript string `description:"分享描述"`
  16. ReportAuthor string `description:"栏目作者"`
  17. AuthorDescript string `description:"作者简介"`
  18. ColumnImgUrl string `description:"栏目配图"`
  19. HeadImgUrl string `description:"头部banner"`
  20. AvatarImgUrl string `description:"头像"`
  21. ReportImgUrl string `description:"报告配图"`
  22. HomeImgUrl string `description:"首页配图"`
  23. ClassifyLabel string `description:"分类标签"`
  24. IsMassSend int `description:"1:群发,0:非群发"`
  25. }
  26. type ClassifyAddReq struct {
  27. ClassifyName string `description:"分类名称"`
  28. ParentId int `description:"父级分类id,没有父级分类传0"`
  29. Abstract string `description:"栏目简介"`
  30. Descript string `description:"分享描述"`
  31. ReportAuthor string `description:"栏目作者"`
  32. AuthorDescript string `description:"作者简介"`
  33. ColumnImgUrl string `description:"栏目配图"`
  34. ReportImgUrl string `description:"报告配图"`
  35. HeadImgUrl string `description:"头部banner"`
  36. AvatarImgUrl string `description:"头像"`
  37. HomeImgUrl string `description:"首页配图"`
  38. ClassifyLabel string `description:"分类标签"`
  39. }
  40. //func GetClassifyByName(classifyName string, parentId int) (item *Classify, err error) {
  41. // sql := `SELECT * FROM classify WHERE classify_name=? AND parent_id=? `
  42. // o := orm.NewOrmUsingDB("rddp")
  43. // err = o.Raw(sql, classifyName, parentId).QueryRow(&item)
  44. // return
  45. //}
  46. func GetClassifyById(classifyId int) (item *Classify, err error) {
  47. //sql := `SELECT * FROM classify WHERE id=? `
  48. //o := orm.NewOrmUsingDB("rddp")
  49. //err = o.Raw(sql, classifyId).QueryRow(&item)
  50. sql := `SELECT * FROM classify WHERE id=? `
  51. err = global.DmSQL["data"].Raw(sql, classifyId).Find(&item).Error
  52. return
  53. }
  54. //
  55. //// 添加分类
  56. //func AddClassify(item *Classify) (err error) {
  57. // o := orm.NewOrmUsingDB("rddp")
  58. // _, err = o.Insert(item)
  59. // return
  60. //}
  61. //
  62. //func GetReportCountByClassifyId(classifyId int) (count int, err error) {
  63. // o := orm.NewOrmUsingDB("rddp")
  64. // sql := `SELECT COUNT(1) AS count FROM report WHERE classify_id_second=? `
  65. // err = o.Raw(sql, classifyId).QueryRow(&count)
  66. // return
  67. //}
  68. //
  69. //func GetClassifySubCountByClassifyId(classifyId int) (count int, err error) {
  70. // o := orm.NewOrmUsingDB("rddp")
  71. // sql := `SELECT COUNT(1) as num FROM classify AS a
  72. // INNER JOIN report AS b ON a.id=b.classify_id_second
  73. // WHERE a.parent_id=? `
  74. // err = o.Raw(sql, classifyId).QueryRow(&count)
  75. // return
  76. //}
  77. //
  78. //func GetClassifySubCountByParentId(classifyId int) (count int, err error) {
  79. // sqlCount := `
  80. // SELECT COUNT(1) as num FROM classify AS a
  81. // WHERE a.parent_id=? `
  82. // o := orm.NewOrmUsingDB("rddp")
  83. // err = o.Raw(sqlCount, classifyId).QueryRow(&count)
  84. // return
  85. //}
  86. //
  87. //// 删除分类
  88. //func DeleteClassify(classifyId int) (err error) {
  89. // sql := `DELETE FROM classify WHERE id=? `
  90. // o := orm.NewOrmUsingDB("rddp")
  91. // _, err = o.Raw(sql, classifyId).Exec()
  92. // if err != nil {
  93. // return
  94. // }
  95. // deleteImgSql := `DELETE FROM banner WHERE classify_id=? `
  96. // _, err = o.Raw(deleteImgSql, classifyId).Exec()
  97. // return
  98. //}
  99. //
  100. //// classifyName, abstract, descript string, parentId, classifyId int
  101. //// 修改分类
  102. //func EditClassify(req *EditClassifyReq) (err error) {
  103. // o := orm.NewOrmUsingDB("rddp")
  104. // sql := `UPDATE classify SET classify_name = ?,abstract=?, parent_id= ?,descript=?,report_author=?,author_descript=?,column_img_url=?,head_img_url=?,avatar_img_url=?,report_img_url=?,home_img_url=?,classify_label=?, modify_time= NOW() WHERE id = ? `
  105. // _, err = o.Raw(sql, req.ClassifyName, req.Abstract, req.ParentId, req.Descript, req.ReportAuthor, req.AuthorDescript, req.ColumnImgUrl, req.HeadImgUrl, req.AvatarImgUrl, req.ReportImgUrl, req.HomeImgUrl, req.ClassifyLabel, req.ClassifyId).Exec()
  106. // return
  107. //}
  108. //
  109. ////获取父级分类
  110. //
  111. //func ParentClassify() (items []*Classify, err error) {
  112. // sql := `SELECT * FROM classify WHERE parent_id=0 order by id desc `
  113. // o := orm.NewOrmUsingDB("rddp")
  114. // _, err = o.Raw(sql).QueryRows(&items)
  115. // return
  116. //}
  117. //
  118. //// 根据id获取分类详情
  119. //func FindByIdClassify(classifyId int) (item *Classify, err error) {
  120. // sql := `SELECT * FROM classify WHERE id=? `
  121. // o := orm.NewOrmUsingDB("rddp")
  122. // err = o.Raw(sql, classifyId).QueryRow(&item)
  123. // return
  124. //}
  125. type ClassifyList struct {
  126. Id int `gorm:"column:id;primaryKey"` // `orm:"column(id);pk"`
  127. ClassifyName string `description:"分类名称"`
  128. Sort int `json:"-"`
  129. ParentId int `description:"父级分类id"`
  130. CreateTime time.Time `description:"创建时间"`
  131. ModifyTime time.Time `description:"修改时间"`
  132. Abstract string `description:"简介"`
  133. Descript string `description:"描述"`
  134. ClassifyLabel string `description:"分类标签"`
  135. Child []*Classify `gorm:"-"`
  136. }
  137. type ClassifyListResp struct {
  138. List []*ClassifyList `gorm:"-"`
  139. Paging *paging.PagingItem `description:"分页数据"`
  140. }
  141. //
  142. //// 获取分类列表
  143. //func GetClassifyList(startSize, pageSize int, keyWord, companyType string) (items []*ClassifyList, err error) {
  144. // sql := ``
  145. // companyTypeSqlStr := ``
  146. // if companyType == "ficc" {
  147. // companyTypeSqlStr = " AND id != 40 AND parent_id != 40 "
  148. // } else if companyType == "权益" {
  149. // companyTypeSqlStr = " AND (id = 40 or parent_id = 40) "
  150. // }
  151. // if keyWord != "" {
  152. // sql = `SELECT * FROM (
  153. // SELECT * FROM classify
  154. // WHERE parent_id=0 ` + companyTypeSqlStr + ` AND classify_name LIKE '%` + keyWord + `%'
  155. // UNION
  156. // SELECT * FROM classify
  157. // WHERE id IN(SELECT parent_id FROM classify
  158. // WHERE parent_id>0 ` + companyTypeSqlStr + ` AND classify_name LIKE '%` + keyWord + `%')
  159. // )AS t
  160. // ORDER BY create_time ASC
  161. // LIMIT ?,? `
  162. // } else {
  163. // sql = `SELECT * FROM classify WHERE parent_id=0 ` + companyTypeSqlStr + ` ORDER BY create_time ASC LIMIT ?,? `
  164. // }
  165. // o := orm.NewOrmUsingDB("rddp")
  166. // _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
  167. // return
  168. //}
  169. //
  170. //func GetClassifyListCount(keyWord, companyType string) (count int, err error) {
  171. // sqlCount := ``
  172. //
  173. // companyTypeSqlStr := ``
  174. // if companyType == "ficc" {
  175. // companyTypeSqlStr = " AND id != 40 AND parent_id != 40 "
  176. // } else if companyType == "权益" {
  177. // companyTypeSqlStr = " AND (id = 40 or parent_id = 40) "
  178. // }
  179. // if keyWord != "" {
  180. // sqlCount = `SELECT COUNT(1) AS count FROM (
  181. // SELECT * FROM classify
  182. // WHERE parent_id=0 ` + companyTypeSqlStr + ` AND classify_name LIKE '%` + keyWord + `%'
  183. // UNION
  184. // SELECT * FROM classify
  185. // WHERE id IN(SELECT parent_id FROM classify
  186. // WHERE parent_id>0 ` + companyTypeSqlStr + ` AND classify_name LIKE '%` + keyWord + `%')
  187. // )AS t `
  188. //
  189. // } else {
  190. // sqlCount = `SELECT COUNT(1) AS count FROM classify WHERE parent_id=0 ` + companyTypeSqlStr
  191. // }
  192. // o := orm.NewOrmUsingDB("rddp")
  193. // err = o.Raw(sqlCount).QueryRow(&count)
  194. // return
  195. //}
  196. type CheckDeleteClassifyReq struct {
  197. ClassifyId int `description:"分类ID"`
  198. }
  199. type CheckDeleteClassifyResp struct {
  200. Code int `description:"编码:0:检测成功,可进行删除,1:分类不存在,2:该分类有关联报告,不允许删除,3:二级分类有关联报告,不允许删除,4:该分类下有关联分类,是否确认全部删除"`
  201. Msg string `description:"描述信息"`
  202. }
  203. type DeleteClassifyReq struct {
  204. ClassifyId int `description:"分类ID"`
  205. }
  206. type EditClassifyReq struct {
  207. ClassifyId int `description:"分类ID"`
  208. ClassifyName string `description:"分类名称"`
  209. ParentId int `description:"父级分类id"`
  210. Abstract string `description:"栏目简介"`
  211. Descript string `description:"分享描述"`
  212. ReportAuthor string `description:"栏目作者"`
  213. AuthorDescript string `description:"作者简介"`
  214. ColumnImgUrl string `description:"栏目配图"`
  215. HeadImgUrl string `description:"头部banner"`
  216. AvatarImgUrl string `description:"头像"`
  217. ReportImgUrl string `description:"报告配图"`
  218. HomeImgUrl string `description:"首页配图"`
  219. ClassifyLabel string `description:"分类标签"`
  220. }
  221. type FindByIdClassifyReq struct {
  222. ClassifyId int `description:"分类ID"`
  223. }
  224. //func GetClassifyChild(parentId int, keyWord string) (items []*Classify, err error) {
  225. // o := orm.NewOrmUsingDB("rddp")
  226. // sql := ``
  227. // if keyWord != "" {
  228. // sql = `SELECT * FROM classify WHERE parent_id=? AND classify_name LIKE '%` + keyWord + `%' ORDER BY create_time ASC `
  229. // } else {
  230. // sql = `SELECT * FROM classify WHERE parent_id=? ORDER BY create_time ASC `
  231. // }
  232. // _, err = o.Raw(sql, parentId).QueryRows(&items)
  233. // return
  234. //}