classify.go 10 KB

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