chart.go 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "time"
  6. )
  7. type ChartResultApi struct {
  8. Data []ChartResultApidate `json:"data"`
  9. Code int `json:"code"`
  10. Msg string `json:"msg"`
  11. }
  12. type ChartFavoritesResultApi struct {
  13. Data []ChartInfo `json:"data"`
  14. Code int `json:"code"`
  15. Msg string `json:"msg"`
  16. Pagination Pagination `json:"pagination"`
  17. }
  18. type Pagination struct {
  19. Total int `json:"total"`
  20. Page int `json:"id"`
  21. PageSize int `json:"page_size"`
  22. PageTotal int `json:"page_total"`
  23. }
  24. type ChartInfo struct {
  25. ChartInfo *ChartResultApidate `json:"chart_info"`
  26. ChartId int `json:"chart_id"`
  27. }
  28. type ChartResultApidate struct {
  29. ChartId int `json:"id"`
  30. PtagId int `json:"ptag_id"`
  31. CtagId int `json:"ctag_id"`
  32. Title string `json:"title"`
  33. TitleEn string `json:"title_en"`
  34. CreateDate string `json:"create_date"`
  35. UpdateDate string `json:"update_date"`
  36. PublishStatus int `json:"publish_status"`
  37. Cover string `json:"cover"`
  38. Iframe string `json:"iframe"`
  39. Ptag Ptag `json:"ptag"`
  40. Ctag Ptag `json:"ctag"`
  41. PtagTwo Ptag `json:"ptag1"`
  42. CtagTwo Ptag `json:"ctag1"`
  43. }
  44. type Ptag struct {
  45. Id int `json:"id"`
  46. Name string `json:"name"`
  47. Description string `json:"description"`
  48. }
  49. type Ctag struct {
  50. Id int `json:"id"`
  51. Name string `json:"name"`
  52. Description string `json:"description"`
  53. PtagId int `json:"ptag_id"`
  54. }
  55. type CygxChart struct {
  56. Id int `orm:"column(id);pk"`
  57. ChartId int `description:"图表id"`
  58. PtagId int `description:"图表父类分类id"`
  59. CtagId int `description:"图表子类分类id"`
  60. PtagIdTwo int `description:"图表父类分类id"`
  61. CtagIdTwo int `description:"图表子类分类id"`
  62. Title string `description:"标题"`
  63. TitleEn string `description:"英文标题 "`
  64. CreateDate string `description:"本地创建时间"`
  65. CreateDateApi time.Time `description:"图表创建时间"`
  66. PublishStatus int `description:"发布状态"`
  67. PtagName string `description:"父类名称"`
  68. CtagName string `description:"子类名称"`
  69. Cover string `description:"图表图片"`
  70. Iframe string `description:"图表详情跳转地址"`
  71. PtagNameTwo string `description:"父类名称"`
  72. CtagNameTwo string `description:"子类名称"`
  73. }
  74. type CygxChartDetail struct {
  75. ChartId int `description:"图表id"`
  76. Title string `description:"标题"`
  77. TitleEn string `description:"英文标题 "`
  78. IsCollection bool `description:"是否收藏 "`
  79. CollectionNum int `description:"本人收藏数量 "`
  80. HttpUrl string `orm:"column(iframe)";description:"文章链接跳转地址"`
  81. }
  82. func GetChartCountById(chartId int) (count int, err error) {
  83. o := orm.NewOrm()
  84. sql := `SELECT COUNT(1) AS count FROM cygx_chart WHERE chart_id = ? `
  85. err = o.Raw(sql, chartId).QueryRow(&count)
  86. return
  87. }
  88. //新增图表
  89. func AddCygxChart(item *CygxChart) (lastId int64, err error) {
  90. o := orm.NewOrm()
  91. lastId, err = o.Insert(item)
  92. return
  93. }
  94. //标签分类
  95. type ChartPtagResultApi struct {
  96. Data []ChartPtagResultApidate `json:"data"`
  97. Code int `json:"code"`
  98. Msg string `json:"msg"`
  99. }
  100. type ChartPtagResultApidate struct {
  101. ChartPermissionId int `json:"id"`
  102. ChartPermissionName string `json:"name"`
  103. Ctag []Ctag `json:"ctag"`
  104. }
  105. type ChartPtagResp struct {
  106. ChartPermissionId int `description:"分类ID"`
  107. PermissionName string `description:"分类名称"`
  108. List []*CtagResp `description:"子分类"`
  109. }
  110. type CtagResp struct {
  111. CtagId int `description:"子分类ID"`
  112. Name string `description:"子分类名称"`
  113. }
  114. type ChartUserTokenResult struct {
  115. AccessToken string `json:"access_token"`
  116. }
  117. type ChartUserTokenResultApi struct {
  118. Data ChartUserTokenResult `json:"data"`
  119. Code int `json:"code"`
  120. Msg string `json:"msg"`
  121. }
  122. type HomeChartListResp struct {
  123. ChartId int `description:"图表ID"`
  124. Title string `description:"标题"`
  125. TitleEn string `description:"英文标题 "`
  126. CreateDate string `description:"创建时间"`
  127. PtagName string `description:"父类名称"`
  128. CtagName string `description:"子类名称"`
  129. PtagNameTwo string `description:"父类名称"`
  130. CtagNameTwo string `description:"子类名称"`
  131. CtagNamePc string `description:"Pc端所有的分类名称"`
  132. BodyHtml string `orm:"column(cover)";description:"图片链接"`
  133. HttpUrl string `orm:"column(iframe)";description:"文章链接跳转地址"`
  134. IsNeedJump bool `description:"是否需要跳转链接地址"`
  135. IsTop bool `description:"是否置顶"`
  136. NumTop int `description:"置顶数量"`
  137. Source int `description:"来源 1:文章, 2:图表"`
  138. }
  139. type HomeChartListItem struct {
  140. IsBindingMobile bool `description:"是否绑定过手机号"`
  141. Paging *paging.PagingItem
  142. List []*HomeChartListResp `description:"图表列表"`
  143. }
  144. type ChartCollectReq struct {
  145. ChartId int `description:"图表ID"`
  146. }
  147. //获取图表列表
  148. func GetChartList(condition string, pars []interface{}, startSize, pageSize int) (items []*HomeChartListResp, err error) {
  149. o := orm.NewOrm()
  150. sql := ` SELECT * FROM cygx_chart AS a WHERE a.publish_status=1 `
  151. if condition != "" {
  152. sql += condition
  153. }
  154. sql += ` ORDER BY create_date DESC LIMIT ?,? `
  155. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  156. return
  157. }
  158. ////获取图表列表
  159. //func GetChartCtagIds(ctagId int ) (items []*HomeChartListResp, err error) {
  160. // o := orm.NewOrm()
  161. // sql := ` SELECT * FROM cygx_chart AS a WHERE a.publish_status=1 AND ctag_id = 1 ORDER BY create_date DESC LIMIT 2 `
  162. // _, err = o.Raw(sql,ctagId).QueryRows(&items)
  163. // return
  164. //}
  165. //获取图表列表
  166. func GetChartListCollection(chartIds string, userId, startSize, pageSize int) (items []*HomeChartListResp, err error) {
  167. o := orm.NewOrm()
  168. sql := ` SELECT a.*,
  169. t.create_time AS t_create_time,
  170. c.create_time AS c_create_time,
  171. ( SELECT COUNT(*) FROM cygx_chart_top AS t WHERE t.chart_id = a.chart_id AND t.user_id = ? ) AS num_top,
  172. ( SELECT COUNT(*) FROM cygx_chart_collect AS c WHERE c.chart_id = a.chart_id AND c.user_id = ? ) AS num_c
  173. FROM
  174. cygx_chart AS a
  175. LEFT JOIN cygx_chart_top AS t ON t.chart_id = a.chart_id
  176. LEFT JOIN cygx_chart_collect AS c ON c.chart_id = a.chart_id
  177. WHERE
  178. a.publish_status = 1
  179. AND a.chart_id IN (` + chartIds + `)
  180. GROUP BY
  181. a.chart_id
  182. ORDER BY
  183. t_create_time DESC,
  184. c_create_time DESC LIMIT ?,? `
  185. _, err = o.Raw(sql, userId, userId, startSize, pageSize).QueryRows(&items)
  186. return
  187. }
  188. //获取图表列表本地
  189. func GetChartListCollectionWithCygx(userId, startSize, pageSize int) (items []*HomeChartListResp, err error) {
  190. o := orm.NewOrm()
  191. sql := ` SELECT
  192. a.*,
  193. t.create_time AS t_create_time,
  194. c.create_time AS c_create_time,
  195. ( SELECT COUNT(*) FROM cygx_chart_top AS t WHERE t.chart_id = a.chart_id AND t.user_id = ? ) AS num_top,
  196. ( SELECT COUNT(*) FROM cygx_chart_collect AS c WHERE c.chart_id = a.chart_id AND c.user_id = ? ) AS num_c
  197. FROM
  198. cygx_chart_collect AS c
  199. INNER JOIN cygx_chart AS a ON c.chart_id = a.chart_id
  200. LEFT JOIN cygx_chart_top AS t ON t.chart_id = a.chart_id
  201. WHERE
  202. a.publish_status = 1
  203. AND c.user_id =?
  204. GROUP BY
  205. a.chart_id
  206. ORDER BY
  207. t_create_time DESC,
  208. c_create_time DESC LIMIT ?,? `
  209. _, err = o.Raw(sql, userId, userId, userId, startSize, pageSize).QueryRows(&items)
  210. return
  211. }
  212. func GetChartListConfig() (items []*HomeChartListResp, err error) {
  213. o := orm.NewOrm()
  214. sql := ` SELECT * FROM cygx_chart AS a WHERE a.publish_status=1 AND ctag_id IN (7,8,9,10) GROUP BY ctag_id ORDER BY create_date DESC LIMIT 4 `
  215. _, err = o.Raw(sql).QueryRows(&items)
  216. return
  217. }
  218. //获取图表数量
  219. func GetChartCount(condition string, pars []interface{}) (count int, err error) {
  220. o := orm.NewOrm()
  221. sql := `SELECT COUNT(1) AS count
  222. FROM cygx_chart AS a
  223. WHERE a.publish_status=1 `
  224. if condition != "" {
  225. sql += condition
  226. }
  227. err = o.Raw(sql, pars).QueryRow(&count)
  228. return
  229. }
  230. func GetChartDetailById(chartId, uid int) (item *CygxChartDetail, err error) {
  231. o := orm.NewOrm()
  232. sql := `SELECT * ,( SELECT COUNT( 1 ) FROM cygx_chart_collect AS c WHERE c.chart_id = a.chart_id AND c.user_id = ? ) AS collection_num
  233. FROM
  234. cygx_chart as a
  235. WHERE
  236. a.chart_id =? `
  237. err = o.Raw(sql, uid, chartId).QueryRow(&item)
  238. return
  239. }