chart.go 8.4 KB

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