classify.go 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. package eta
  2. import (
  3. "hongze/hz_crm_eta/global"
  4. "hongze/hz_crm_eta/utils"
  5. "time"
  6. )
  7. type Classify struct {
  8. Id int `gorm:"column:id;primary_key;AUTO_INCREMENT;NOT NULL"`
  9. ClassifyName string `gorm:"column:classify_name;default:;comment:'分类名称'"`
  10. Sort int `gorm:"column:sort;default:0;comment:'排序'"`
  11. ParentId int `gorm:"column:parent_id;default:0;comment:'父级分类id'"`
  12. CreateTime time.Time `gorm:"column:create_time;default:CURRENT_TIMESTAMP"`
  13. ModifyTime time.Time `gorm:"column:modify_time;default:CURRENT_TIMESTAMP"`
  14. Abstract string `gorm:"column:abstract;default:;comment:'栏目简介'"`
  15. Descript string `gorm:"column:descript;default:;comment:'分享描述'"`
  16. ReportAuthor string `gorm:"column:report_author;default:;comment:'栏目作者'"`
  17. AuthorDescript string `gorm:"column:author_descript;default:;comment:'作者简介'"`
  18. ReportImgUrl string `gorm:"column:report_img_url;default:;comment:'报告配图'"`
  19. HeadImgUrl string `gorm:"column:head_img_url;default:;comment:'头部banner'"`
  20. AvatarImgUrl string `gorm:"column:avatar_img_url;default:;comment:'头像'"`
  21. ColumnImgUrl string `gorm:"column:column_img_url;default:;comment:'栏目配图'"`
  22. IsHomeColumn int `gorm:"column:is_home_column;default:0;comment:'1:首页专栏'"`
  23. HomeImgUrl string `gorm:"column:home_img_url;default:;comment:'首页配图'"`
  24. ClassifyLabel string `gorm:"column:classify_label;default:"`
  25. ShowType int `gorm:"column:show_type;default:0;NOT NULL;comment:'展示类型:1-列表 2-专栏 3-品种'"`
  26. HasTeleconference int `gorm:"column:has_teleconference;default:0;NOT NULL;comment:'是否有电话会 0-否 1-是'"`
  27. VipTitle string `gorm:"column:vip_title;default:NULL;comment:'研究员头衔'"`
  28. YbIconUrl string `gorm:"column:yb_icon_url;default:;comment:'研报3.0已购页面icon图片地址'"`
  29. YbBgUrl string `gorm:"column:yb_bg_url;default:;comment:'研报3.0已购详情背景图地址'"`
  30. IsShow int `gorm:"column:is_show;default:1;NOT NULL;comment:'是否展示报告:1,展示该分类下的报告,0隐藏分类下的报告'"`
  31. YbFiccSort int `gorm:"column:yb_ficc_sort;default:0;comment:'研报小程序端ficc页面排序'"`
  32. YbFiccIcon string `gorm:"column:yb_ficc_icon;default:NULL;comment:'研报小程序端ficc页码图标'"`
  33. YbFiccPcIcon string `gorm:"column:yb_ficc_pc_icon;default:NULL;comment:'研报 pc端ficc页码图标'"`
  34. YbListImg string `gorm:"column:yb_list_img;default:;NOT NULL;comment:'研报小程序-列表封面图'"`
  35. YbShareBgImg string `gorm:"column:yb_share_bg_img;default:;NOT NULL;comment:'研报小程序-报告分享背景图'"`
  36. YbRightBanner string `gorm:"column:yb_right_banner;default:NULL;comment:'Pc端详情页,右侧,报告合集背景图'"`
  37. RelateTel int `gorm:"column:relate_tel;default:0;NOT NULL;comment:'是否在电话会中可选: 0-否; 1-是'"`
  38. RelateVideo int `gorm:"column:relate_video;default:0;NOT NULL;comment:'是否在路演视频中可选: 0-否; 1-是'"`
  39. IsMassSend int `gorm:"column:is_mass_send;default:0;comment:'1:群发,0:非群发'"`
  40. Enabled int `gorm:"column:enabled;default:1;comment:'是否可用'"`
  41. Level int `description:"层级"`
  42. HasChild int `description:"是否有子级别,0:下面没有子分类,1:下面有子分类;默认:0"`
  43. ReportDetailShowType int `description:"报告详情的展示类型:1-拼接;2:目录"`
  44. }
  45. func (c *Classify) TableName() string {
  46. return "classify"
  47. }
  48. type ClassifyListItem struct {
  49. Id int `description:"id"`
  50. ClassifyName string `description:"分类名称"`
  51. Sort int `description:"排序"`
  52. ParentId int `description:"父级分类id"`
  53. CreateTime time.Time `description:"创建时间"`
  54. ModifyTime time.Time `description:"修改时间"`
  55. Abstract string `description:"简介"`
  56. Descript string `description:"描述"`
  57. ClassifyLabel string `description:"分类标签"`
  58. ShowType int `description:"展示类型:1-列表 2-专栏"`
  59. HasTeleconference int `description:"是否有电话会:0-否 1-是"`
  60. IsShow int `description:"是否在小程序显示:1-显示 0-隐藏"`
  61. YbFiccSort int `description:"小程序FICC页排序"`
  62. YbFiccIcon string `description:"小程序FICC页icon"`
  63. YbFiccPcIcon string `description:"小程序PC端FICC页背景图"`
  64. YbIconUrl string `description:"小程序已购页icon"`
  65. YbBgUrl string `description:"小程序已购详情背景图"`
  66. YbListImg string `description:"小程序研报列表封面图"`
  67. YbShareBgImg string `description:"小程序研报详情分享背景图"`
  68. YbRightBanner string `description:"Pc端详情页,右侧,报告合集背景图"`
  69. RelateTel int `description:"是否在电话会中可选: 0-否; 1-是"`
  70. RelateVideo int `description:"是否在路演视频中可选: 0-否; 1-是"`
  71. Enabled int `description:"是否可用,1可用,0禁用"`
  72. }
  73. type ClassifyList struct {
  74. ClassifyListItem
  75. Child []*ClassifyItem
  76. ClassifyMenuList []*ClassifyMenu
  77. }
  78. type ClassifyItem struct {
  79. Classify
  80. ClassifyMenuId int `description:"二级分类-子目录ID"`
  81. ClassifyMenuList []*ClassifyMenu
  82. ChartPermissionIdList []int `description:"绑定的权限ID"`
  83. }
  84. // 获取分类列表
  85. func GetClassifyList(keyWord, companyType string, hideDayWeek int) (items []*ClassifyListItem, err error) {
  86. sql := ``
  87. companyTypeSqlStr := ``
  88. if companyType == "ficc" {
  89. companyTypeSqlStr = " AND id != 40 AND parent_id != 40 "
  90. } else if companyType == "权益" {
  91. companyTypeSqlStr = " AND (id = 40 or parent_id = 40) "
  92. }
  93. pars := make([]interface{}, 0)
  94. if keyWord != "" {
  95. sql = `SELECT * FROM (
  96. SELECT * FROM classify
  97. WHERE parent_id=0 ` + companyTypeSqlStr + ` AND classify_name LIKE ?
  98. UNION
  99. SELECT * FROM classify
  100. WHERE id IN( SELECT parent_id FROM classify
  101. WHERE parent_id>0 ` + companyTypeSqlStr + ` AND classify_name LIKE ? )
  102. )AS t
  103. ORDER BY sort ASC,create_time ASC`
  104. pars = utils.GetLikeKeywordPars(pars, keyWord, 2)
  105. } else {
  106. sql = `SELECT * FROM classify WHERE parent_id=0 ` + companyTypeSqlStr
  107. if hideDayWeek == 1 {
  108. sql += ` AND classify_name <> '晨报' AND classify_name <> '周报' `
  109. }
  110. sql += ` ORDER BY sort ASC, create_time ASC`
  111. }
  112. pars = append(pars)
  113. err = global.MYSQL["rddp"].Raw(sql, pars...).Scan(&items).Error
  114. return
  115. }
  116. func GetClassifyChildByParentIds(parentId []int, keyWord string) (items []*Classify, err error) {
  117. parentIdLen := len(parentId)
  118. if parentIdLen == 0 {
  119. return
  120. }
  121. sql := ``
  122. pars := make([]interface{}, 0)
  123. pars = append(pars, parentId)
  124. if keyWord != "" {
  125. sql = `SELECT * FROM classify WHERE parent_id IN (?) AND classify_name LIKE ? ORDER BY create_time ASC `
  126. pars = append(pars, utils.GetLikeKeyword(keyWord))
  127. } else {
  128. sql = `SELECT * FROM classify WHERE parent_id IN (?) ORDER BY create_time ASC `
  129. }
  130. err = global.MYSQL["rddp"].Raw(sql, pars...).Scan(&items).Error
  131. return
  132. }
  133. func GetClassifyChild(parentId int, keyWord string) (items []*Classify, err error) {
  134. sql := ``
  135. pars := make([]interface{}, 0)
  136. if keyWord != "" {
  137. sql = `SELECT * FROM classify WHERE classify_name LIKE ? AND parent_id=? ORDER BY create_time ASC `
  138. pars = append(pars, utils.GetLikeKeyword(keyWord))
  139. } else {
  140. sql = `SELECT * FROM classify WHERE parent_id=? ORDER BY create_time ASC `
  141. }
  142. pars = append(pars, parentId)
  143. err = global.MYSQL["rddp"].Raw(sql, pars...).Scan(&items).Error
  144. return
  145. }
  146. type ClassifyListReq struct {
  147. Keyword string
  148. CompanyType string
  149. HideDayWeek int
  150. }
  151. type ClassifyListResp struct {
  152. List []*ClassifyListV2
  153. }
  154. type ClassifySetEnabledReq struct {
  155. ClassifyId int `description:"分类ID"`
  156. Enabled int `description:"是否可用,1可用,0禁用"`
  157. }
  158. func (c *Classify) SetEnabled(id, enabled int) (err error) {
  159. tx := global.MYSQL["rddp"].Begin()
  160. defer func() {
  161. if err != nil {
  162. tx.Rollback()
  163. } else {
  164. tx.Commit()
  165. }
  166. }()
  167. sql := ` UPDATE classify SET enabled =? WHERE id = ?`
  168. err = tx.Exec(sql, enabled, id).Error
  169. if err != nil {
  170. return
  171. }
  172. sql = ` UPDATE classify SET enabled =? WHERE parent_id = ?`
  173. err = tx.Exec(sql, enabled, id).Error
  174. if err != nil {
  175. return
  176. }
  177. return
  178. }
  179. // GetClassifyById 查询分类
  180. func (c *Classify) GetClassifyById(classifyId int) (item *Classify, err error) {
  181. err = global.MYSQL["rddp"].Where("id = ?", classifyId).First(&item).Error
  182. return
  183. }
  184. type EditClassifyReq struct {
  185. ClassifyId int `description:"分类ID"`
  186. /*Abstract string `description:"栏目简介"`
  187. Descript string `description:"分享描述"`
  188. ReportAuthor string `description:"栏目作者"`
  189. AuthorDescript string `description:"作者简介"`
  190. ColumnImgUrl string `description:"栏目配图"`
  191. ReportImgUrl string `description:"报告配图"`
  192. HeadImgUrl string `description:"头部banner"`
  193. AvatarImgUrl string `description:"头像"`
  194. HomeImgUrl string `description:"首页配图"`
  195. HasTeleconference int `description:"是否有电话会:0-否 1-是"`
  196. VipTitle string `description:"研究员头衔"`*/
  197. //Sort int `description:"后台排序"`
  198. ShowType int `description:"展示类型:1-列表 2-专栏"`
  199. MenuList []*ClassifyMenuSaveReq `description:"子目录列表"`
  200. ClassifyLabel string `description:"分类标签"`
  201. IsShow int `description:"是否在小程序显示:1-显示 0-隐藏"`
  202. YbFiccSort int `description:"小程序FICC页排序"`
  203. YbFiccIcon string `description:"小程序FICC页icon"`
  204. YbFiccPcIcon string `description:"小程序PC端FICC页背景图"`
  205. YbIconUrl string `description:"小程序已购页icon"`
  206. YbBgUrl string `description:"小程序已购详情背景图"`
  207. YbListImg string `description:"小程序研报列表封面图"`
  208. YbShareBgImg string `description:"小程序研报详情分享背景图"`
  209. YbRightBanner string `description:"Pc端详情页,右侧,报告合集背景图"`
  210. ClassifyMenuId int `description:"二级分类-子目录ID"`
  211. RelateTel int `description:"是否在电话会中可选: 0-否; 1-是"`
  212. RelateVideo int `description:"是否在路演视频中可选: 0-否; 1-是"`
  213. ReportDetailShowType int `description:"报告详情的展示类型:1-拼接;2:目录"`
  214. }
  215. // ClassifyMenuSaveReq 保存分类子目录请求体
  216. type ClassifyMenuSaveReq struct {
  217. MenuId int `description:"子目录ID, 0为新增, 大于0为编辑"`
  218. MenuName string `description:"子目录名称"`
  219. }
  220. // UpdateClassify 更新权限
  221. func (c *Classify) UpdateClassify(cols []string) (err error) {
  222. err = global.MYSQL["rddp"].Model(c).Select(cols).Updates(c).Error
  223. return
  224. }
  225. // UpdateChildClassifyRelateSetting 更新子分类关联设置
  226. func (c *Classify) UpdateChildClassifyRelateSetting(parentId, relateTel, relateVideo int) (err error) {
  227. sql := `UPDATE classify SET relate_tel = ?, relate_video = ? WHERE parent_id = ?`
  228. err = global.MYSQL["rddp"].Exec(sql, relateTel, relateVideo, parentId).Error
  229. return
  230. }
  231. type ClassifyListV2 struct {
  232. Id int `orm:"column(id);pk"`
  233. ClassifyName string `description:"分类名称"`
  234. Sort int `description:"排序"`
  235. ParentId int `description:"父级分类id"`
  236. CreateTime time.Time `description:"创建时间"`
  237. ModifyTime time.Time `description:"修改时间"`
  238. Abstract string `description:"简介"`
  239. Descript string `description:"描述"`
  240. ClassifyLabel string `description:"分类标签"`
  241. ShowType int `description:"展示类型:1-列表 2-专栏"`
  242. HasTeleconference int `description:"是否有电话会:0-否 1-是"`
  243. IsShow int `description:"是否在小程序显示:1-显示 0-隐藏"`
  244. YbFiccSort int `description:"小程序FICC页排序"`
  245. YbFiccIcon string `description:"小程序FICC页icon"`
  246. YbFiccPcIcon string `description:"小程序PC端FICC页背景图"`
  247. YbIconUrl string `description:"小程序已购页icon"`
  248. YbBgUrl string `description:"小程序已购详情背景图"`
  249. YbListImg string `description:"小程序研报列表封面图"`
  250. YbShareBgImg string `description:"小程序研报详情分享背景图"`
  251. YbRightBanner string `description:"Pc端详情页,右侧,报告合集背景图"`
  252. RelateTel int `description:"是否在电话会中可选: 0-否; 1-是"`
  253. RelateVideo int `description:"是否在路演视频中可选: 0-否; 1-是"`
  254. Enabled int `description:"是否可用,1可用,0禁用"`
  255. Child []*ClassifyListV2 `gorm:"-"`
  256. ClassifyMenuId int `description:"二级分类-子目录ID"`
  257. ClassifyMenuList []*ClassifyMenu `gorm:"-"`
  258. ChartPermissionIdList []int `description:"绑定的权限ID" gorm:"-"`
  259. Level int `description:"层级"`
  260. HasChild int `description:"是否有子级别,0:下面没有子分类,1:下面有子分类;默认:0"`
  261. ReportDetailShowType int `description:"报告详情的展示类型:1-拼接;2:目录"`
  262. }
  263. // GetClassifyListByKeyword
  264. // @Description: 获取分类列表
  265. // @author: Roc
  266. // @datetime 2024-06-19 09:49:33
  267. // @param keyWord string
  268. // @param enabled int
  269. // @return items []*ClassifyList
  270. // @return err error
  271. func GetClassifyListByKeyword(keyWord string) (items []*ClassifyListV2, err error) {
  272. sql := ``
  273. pars := make([]interface{}, 0)
  274. sql = `SELECT * FROM classify WHERE 1=1 `
  275. if keyWord != `` {
  276. sql += ` AND classify_name LIKE ? `
  277. pars = utils.GetLikeKeywordPars(pars, keyWord, 1)
  278. }
  279. sql += ` ORDER BY sort ASC, create_time ASC`
  280. err = global.MYSQL["rddp"].Raw(sql, pars...).Find(&items).Error
  281. return
  282. }
  283. // GetClassifyListByParentIdList
  284. // @Description: 获取分类列表
  285. // @author: Roc
  286. // @datetime 2024-06-19 09:49:33
  287. // @param keyWord string
  288. // @param enabled int
  289. // @return items []*ClassifyList
  290. // @return err error
  291. func GetClassifyListByParentIdList(parentClassifyIdList []int) (items []*ClassifyListV2, err error) {
  292. num := len(parentClassifyIdList)
  293. if num <= 0 {
  294. return
  295. }
  296. sql := `SELECT * FROM classify WHERE id in (?) ORDER BY sort ASC, create_time ASC `
  297. err = global.MYSQL["rddp"].Raw(sql, parentClassifyIdList).Find(&items).Error
  298. return
  299. }