classify.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. package models
  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 Classify struct {
  10. Id int `gorm:"column:id;primaryKey" json:"id"` //`orm:"column(id);pk" gorm:"primaryKey" `
  11. ClassifyName string `gorm:"column:classify_name" json:"classify_name"` //`description:"分类名称"`
  12. Sort int `gorm:"column:sort" json:"sort"` //`json:"-"`
  13. ParentId int `gorm:"column:parent_id" json:"parent_id"` //`description:"父级分类id"`
  14. CreateTime time.Time `gorm:"column:create_time" json:"create_time"` //`description:"创建时间"`
  15. ModifyTime time.Time `gorm:"column:modify_time" json:"modify_time"` //`description:"修改时间"`
  16. Abstract string `gorm:"column:abstract" json:"abstract"` //`description:"栏目简介"`
  17. Descript string `gorm:"column:descript" json:"descript"` //`description:"分享描述"`
  18. ReportAuthor string `gorm:"column:report_author" json:"report_author"` //`description:"栏目作者"`
  19. AuthorDescript string `gorm:"column:author_descript" json:"author_descript"` //`description:"作者简介"`
  20. ColumnImgUrl string `gorm:"column:column_img_url" json:"column_img_url"` //`description:"栏目配图"`
  21. HeadImgUrl string `gorm:"column:head_img_url" json:"head_img_url"` //`description:"头部banner"`
  22. AvatarImgUrl string `gorm:"column:avatar_img_url" json:"avatar_img_url"` //`description:"头像"`
  23. ReportImgUrl string `gorm:"column:report_img_url" json:"report_img_url"` //`description:"报告配图"`
  24. HomeImgUrl string `gorm:"column:home_img_url" json:"home_img_url"` //`description:"首页配图"`
  25. ClassifyLabel string `gorm:"column:classify_label" json:"classify_label"` //`description:"分类标签"`
  26. ShowType int `gorm:"column:show_type" json:"show_type"` //`description:"展示类型:1-列表 2-专栏"`
  27. HasTeleconference int `gorm:"column:has_teleconference" json:"has_teleconference"` //`description:"是否有电话会:0-否 1-是"`
  28. VipTitle string `gorm:"column:vip_title" json:"vip_title"` //`description:"研究员头衔"`
  29. IsShow int `gorm:"column:is_show" json:"is_show"` //`description:"是否在小程序显示:1-显示 0-隐藏"`
  30. YbFiccSort int `gorm:"column:yb_ficc_sort" json:"yb_ficc_sort"` //`description:"小程序FICC页排序"`
  31. YbFiccIcon string `gorm:"column:yb_ficc_icon" json:"yb_ficc_icon"` // `description:"小程序FICC页icon"`
  32. YbFiccPcIcon string `gorm:"column:yb_ficc_pc_icon" json:"yb_ficc_pc_icon"` //`description:"小程序PC端FICC页背景图"`
  33. YbIconUrl string `gorm:"column:yb_icon_url" json:"yb_icon_url"` //`description:"小程序已购页icon"`
  34. YbBgUrl string `gorm:"column:yb_bg_url" json:"yb_bg_url"` //`description:"小程序已购详情背景图"`
  35. YbListImg string `gorm:"column:yb_list_img" json:"yb_list_img"` //`description:"小程序研报列表封面图"`
  36. YbShareBgImg string `gorm:"column:yb_share_bg_img" json:"yb_share_bg_img"` //`description:"小程序研报详情分享背景图"`
  37. YbRightBanner string `gorm:"column:yb_right_banner" json:"yb_right_banner"` //`description:"Pc端详情页,右侧,报告合集背景图"`
  38. RelateTel int `gorm:"column:relate_tel" json:"relate_tel"` //`description:"是否在电话会中可选: 0-否; 1-是"`
  39. RelateVideo int `gorm:"column:relate_video" json:"relate_video"` //`description:"是否在路演视频中可选: 0-否; 1-是"`
  40. IsMassSend int `gorm:"column:is_mass_send" json:"is_mass_send"` //`description:"1:群发,0:非群发"`
  41. Enabled int `gorm:"column:enabled" json:"enabled"` //`description:"是否可用,1可用,0禁用"`
  42. Level int `gorm:"column:level" json:"level"` //`description:"层级"`
  43. HasChild int `gorm:"column:has_child" json:"has_child"` //`description:"是否有子级别,0:下面没有子分类,1:下面有子分类;默认:0"`
  44. ReportDetailShowType int `gorm:"column:report_detail_show_type" json:"report_detail_show_type"` //`description:"报告详情的展示类型:1-拼接;2:目录"`
  45. }
  46. type ClassifyAddReq struct {
  47. ClassifyName string `description:"分类名称"`
  48. ParentId int `description:"父级分类id,没有父级分类传0"`
  49. ChartPermissionIdList []int `description:"权限id数组"`
  50. }
  51. func GetClassifyByName(classifyName string, parentId int) (item *Classify, err error) {
  52. sql := `SELECT * FROM classify WHERE classify_name=? AND parent_id=? `
  53. err = global.DmSQL["rddp"].Raw(sql, classifyName, parentId).First(&item).Error
  54. return
  55. }
  56. func GetClassifyById(classifyId int) (item *Classify, err error) {
  57. sql := `SELECT * FROM classify WHERE id=? `
  58. err = global.DmSQL["rddp"].Raw(sql, classifyId).First(&item).Error
  59. return
  60. }
  61. func AddClassify(item *Classify) (err error) {
  62. err = global.DmSQL["rddp"].Create(item).Error
  63. return
  64. }
  65. func GetReportCountByClassifyId(classifyId int) (count int, err error) {
  66. sql := `SELECT COUNT(1) as num FROM report WHERE classify_id_second=? `
  67. err = global.DmSQL["rddp"].Raw(sql, classifyId).First(&count).Error
  68. return
  69. }
  70. func GetClassifySubCountByClassifyId(classifyId int) (count int, err error) {
  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 = global.DmSQL["rddp"].Raw(sql, classifyId).First(&count).Error
  75. return
  76. }
  77. func GetClassifySubCountByParentId(classifyId int) (count int, err error) {
  78. sqlCount := `
  79. SELECT COUNT(1) as num FROM classify AS a
  80. WHERE a.parent_id=? `
  81. err = global.DmSQL["rddp"].Raw(sqlCount, classifyId).Scan(&count).Error
  82. return
  83. }
  84. func DeleteClassify(classifyId int) (err error) {
  85. sql := `DELETE FROM classify WHERE id=? `
  86. err = global.DmSQL["rddp"].Exec(sql, classifyId).Error
  87. if err != nil {
  88. return
  89. }
  90. deleteImgSql := `DELETE FROM banner WHERE classify_id=? `
  91. err = global.DmSQL["rddp"].Exec(deleteImgSql, classifyId).Error
  92. return
  93. }
  94. func FindByIdClassify(classifyId int) (item *Classify, err error) {
  95. sql := `SELECT * FROM classify WHERE id=? `
  96. err = global.DmSQL["rddp"].Raw(sql, classifyId).First(&item).Error
  97. return
  98. }
  99. type ClassifyList struct {
  100. Id int `gorm:"column:id"` //`orm:"column(id);pk" gorm:"primaryKey" `
  101. ClassifyName string `gorm:"column:classify_name"` //`description:"分类名称"`
  102. Sort int `gorm:"column:sort"` //`description:"排序"`
  103. ParentId int `gorm:"column:parent_id"` //`description:"父级分类id"`
  104. CreateTime time.Time `gorm:"column:create_time"` //`description:"创建时间"`
  105. ModifyTime time.Time `gorm:"column:modify_time"` //`description:"修改时间"`
  106. Abstract string `gorm:"column:abstract"` //`description:"简介"`
  107. Descript string `gorm:"column:descript"` //`description:"描述"`
  108. ClassifyLabel string `gorm:"column:classify_label"` //`description:"分类标签"`
  109. ShowType int `gorm:"column:show_type"` //`description:"展示类型:1-列表 2-专栏"`
  110. HasTeleconference int `gorm:"column:has_teleconference"` //`description:"是否有电话会:0-否 1-是"`
  111. IsShow int `gorm:"column:is_show"` //`description:"是否在小程序显示:1-显示 0-隐藏"`
  112. YbFiccSort int `gorm:"column:yb_ficc_sort"` //`description:"小程序FICC页排序"`
  113. YbFiccIcon string `gorm:"column:yb_ficc_icon"` // `description:"小程序FICC页icon"`
  114. YbFiccPcIcon string `gorm:"column:yb_ficc_pc_icon"` //`description:"小程序PC端FICC页背景图"`
  115. YbIconUrl string `gorm:"column:yb_icon_url"` //`description:"小程序已购页icon"`
  116. YbBgUrl string `gorm:"column:yb_bg_url"` //`description:"小程序已购详情背景图"`
  117. YbListImg string `gorm:"column:yb_list_img"` //`description:"小程序研报列表封面图"`
  118. YbShareBgImg string `gorm:"column:yb_share_bg_img"` //`description:"小程序研报详情分享背景图"`
  119. YbRightBanner string `gorm:"column:yb_right_banner"` //`description:"Pc端详情页,右侧,报告合集背景图"`
  120. RelateTel int `gorm:"column:relate_tel"` //`description:"是否在电话会中可选: 0-否; 1-是"`
  121. RelateVideo int `gorm:"column:relate_video"` //`description:"是否在路演视频中可选: 0-否; 1-是"`
  122. Enabled int `gorm:"column:enabled"` //`description:"是否可用,1可用,0禁用"`
  123. Child []*ClassifyList `gorm:"-"`
  124. ClassifyMenuId int `gorm:"-"` //`description:"二级分类-子目录ID"`
  125. ClassifyMenuList []*ClassifyMenu `gorm:"-"`
  126. ChartPermissionIdList []int `gorm:"-"` // `description:"绑定的权限ID"`
  127. Level int `gorm:"column:level"` //`description:"层级"`
  128. HasChild int `gorm:"column:has_child"` //`description:"是否有子级别,0:下面没有子分类,1:下面有子分类;默认:0"`
  129. }
  130. type ClassifyItem struct {
  131. Classify
  132. ClassifyMenuId int `description:"二级分类-子目录ID"`
  133. ClassifyMenuList []*ClassifyMenu
  134. ChartPermissionIdList []int `description:"绑定的权限ID"`
  135. Child []*ClassifyItem
  136. }
  137. type ClassifyListResp struct {
  138. List []*ClassifyList
  139. }
  140. type ClassifyPermissionListResp struct {
  141. List []*ClassifyList
  142. Paging *paging.PagingItem `description:"分页数据"`
  143. }
  144. type CheckDeleteClassifyReq struct {
  145. ClassifyId int `description:"分类ID"`
  146. }
  147. type CheckDeleteClassifyResp struct {
  148. Code int `description:"编码:0:检测成功,可进行删除,1:分类不存在,2:该分类有关联报告,不允许删除,3:二级分类有关联报告,不允许删除,4:该分类下有关联分类,是否确认全部删除"`
  149. Msg string `description:"描述信息"`
  150. }
  151. type DeleteClassifyReq struct {
  152. ClassifyId int `description:"分类ID"`
  153. }
  154. type EditClassifyReq struct {
  155. ClassifyId int `description:"分类ID"`
  156. ClassifyAddReq
  157. }
  158. type FindByIdClassifyReq struct {
  159. ClassifyId int `description:"分类ID"`
  160. }
  161. func GetClassifyChild(parentId int, keyWord string) (items []*Classify, err error) {
  162. sql := ``
  163. pars := make([]interface{}, 0)
  164. if keyWord != "" {
  165. sql = `SELECT * FROM classify WHERE classify_name LIKE ? AND parent_id=? ORDER BY create_time ASC `
  166. pars = append(pars, utils.GetLikeKeyword(keyWord))
  167. } else {
  168. sql = `SELECT * FROM classify WHERE parent_id=? ORDER BY create_time ASC `
  169. }
  170. pars = append(pars, parentId)
  171. err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
  172. return
  173. }
  174. type EditClassifyPermissionReq struct {
  175. ClassifyId int `description:"分类ID"`
  176. ChartPermissionIdList []int `description:"权限id数组"`
  177. }
  178. func GetAllClassify() (list []*Classify, err error) {
  179. sql := ` SELECT * FROM classify `
  180. err = global.DmSQL["rddp"].Raw(sql).Find(&list).Error
  181. return
  182. }
  183. func (classifyInfo *Classify) UpdateClassify(cols []string) (err error) {
  184. err = global.DmSQL["rddp"].Select(cols).Updates(classifyInfo).Error
  185. return
  186. }
  187. type SimpleClassifyList struct {
  188. Id int `description:"分类ID"`
  189. ClassifyName string `description:"分类名称"`
  190. ParentId int `description:"父级ID"`
  191. Sort int `description:"排序"`
  192. Child []*SimpleClassifyList
  193. }
  194. func GetClassifyByCondition(condition, orderRule string, pars []interface{}) (items []*SimpleClassifyList, err error) {
  195. sql := `SELECT * FROM classify WHERE 1 = 1 `
  196. if condition != `` {
  197. sql += condition
  198. }
  199. order := `sort ASC, create_time ASC`
  200. if orderRule != `` {
  201. order = orderRule
  202. }
  203. sql += ` ORDER BY ` + order
  204. err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
  205. return
  206. }
  207. type RelateTelSecClassifyWithPermissions struct {
  208. Id int `description:"分类ID"`
  209. ClassifyName string `description:"分类名称"`
  210. ChartPermissionIds string `description:"权限IDs"`
  211. }
  212. func UpdateClassifySortByParentId(parentId, permissionId, nowSort int, updateSort string) (err error) {
  213. sql := ` update classify set sort = ` + updateSort + ` WHERE parent_id=? AND sort > ? `
  214. if permissionId > 0 {
  215. sql += ` or ( id > ` + fmt.Sprint(permissionId) + ` and sort = ` + fmt.Sprint(nowSort) + `)`
  216. }
  217. err = global.DmSQL["rddp"].Exec(sql, parentId, nowSort).Error
  218. return
  219. }
  220. func (classifyInfo *Classify) GetMaxSortByParentId(parentId int) (maxSort int, err error) {
  221. sql := `SELECT COALESCE(MAX(sort), 0) AS sort FROM classify WHERE parent_id = ? `
  222. err = global.DmSQL["rddp"].Raw(sql, parentId).Scan(&maxSort).Error
  223. return
  224. }
  225. func (classifyInfo *Classify) GetMaxSort() (maxSort int, err error) {
  226. sql := `SELECT COALESCE(MAX(sort), 0) AS sort FROM classify`
  227. err = global.DmSQL["rddp"].Raw(sql).Scan(&maxSort).Error
  228. return
  229. }
  230. func (classifyInfo *Classify) GetFirstClassifyByParentId(parentId int) (item *Classify, err error) {
  231. sql := `SELECT * FROM classify WHERE parent_id = ? order by sort asc, id asc limit 1`
  232. err = global.DmSQL["rddp"].Raw(sql, parentId).First(&item).Error
  233. return
  234. }
  235. type ClassifyMoveReq struct {
  236. ClassifyId int `description:"分类ID"`
  237. PrevClassifyId int `description:"上一个兄弟节点分类id"`
  238. NextClassifyId int `description:"下一个兄弟节点分类id"`
  239. }
  240. type ClassifySetEnabledReq struct {
  241. ClassifyId int `description:"分类ID"`
  242. Enabled int `description:"是否可用,1可用,0禁用"`
  243. }
  244. func (classifyInfo *Classify) SetEnabled(id, enabled int) (err error) {
  245. to := global.DmSQL["rddp"].Begin()
  246. defer func() {
  247. if err != nil {
  248. _ = to.Rollback()
  249. } else {
  250. _ = to.Commit()
  251. }
  252. }()
  253. sql := ` UPDATE classify SET enabled =? WHERE id = ?`
  254. err = to.Exec(sql, enabled, id).Error
  255. if err != nil {
  256. return
  257. }
  258. sql = ` UPDATE classify SET enabled =? WHERE parent_id = ?`
  259. err = to.Exec(sql, enabled, id).Error
  260. if err != nil {
  261. return
  262. }
  263. return
  264. }
  265. func GetCountClassifyChildByParentId(parentId int) (total int, err error) {
  266. sql := `SELECT count(1) AS total FROM classify WHERE parent_id = ? `
  267. err = global.DmSQL["rddp"].Raw(sql, parentId).Scan(&total).Error
  268. return
  269. }
  270. func GetClassifyListByKeyword(keyWord string, enabled int) (items []*ClassifyList, err error) {
  271. sql := ``
  272. pars := make([]interface{}, 0)
  273. sql = `SELECT * FROM classify WHERE 1=1 `
  274. if enabled == 1 {
  275. sql += ` AND enabled = 1 `
  276. }
  277. if keyWord != `` {
  278. sql += ` AND classify_name LIKE ? `
  279. pars = utils.GetLikeKeywordPars(pars, keyWord, 1)
  280. }
  281. sql += ` ORDER BY sort ASC, create_time ASC`
  282. err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
  283. return
  284. }
  285. func GetClassifyListByParentIdList(parentClassifyIdList []int) (items []*ClassifyList, err error) {
  286. num := len(parentClassifyIdList)
  287. if num <= 0 {
  288. return
  289. }
  290. sql := `SELECT * FROM classify WHERE id in (` + utils.GetOrmInReplace(num) + `) ORDER BY sort ASC, create_time ASC`
  291. err = global.DmSQL["rddp"].Raw(sql, parentClassifyIdList).Find(&items).Error
  292. return
  293. }
  294. func GetClassifyListByIdList(classifyIdList []int) (items []*Classify, err error) {
  295. num := len(classifyIdList)
  296. if num <= 0 {
  297. return
  298. }
  299. sql := `SELECT * FROM classify WHERE id IN (` + utils.GetOrmInReplace(num) + `) `
  300. err = global.DmSQL["rddp"].Raw(sql, classifyIdList).Find(&items).Error
  301. return
  302. }