chart.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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 HomeChartListResp struct {
  124. ChartId int `description:"图表ID"`
  125. Title string `description:"标题"`
  126. TitleEn string `description:"英文标题 "`
  127. CreateDate string `description:"创建时间"`
  128. PtagName string `description:"父类名称"`
  129. CtagName string `description:"子类名称"`
  130. PtagNameTwo string `description:"父类名称"`
  131. CtagNameTwo string `description:"子类名称"`
  132. CtagNamePc string `description:"Pc端所有的分类名称"`
  133. BodyHtml string `orm:"column(cover)";description:"图片链接"`
  134. HttpUrl string `orm:"column(iframe)";description:"文章链接跳转地址"`
  135. IsNeedJump bool `description:"是否需要跳转链接地址"`
  136. IsTop bool `description:"是否置顶"`
  137. NumTop int `description:"置顶数量"`
  138. Source int `description:"来源 1:文章, 2:图表"`
  139. }
  140. type HomeChartListItem struct {
  141. IsBindingMobile bool `description:"是否绑定过手机号"`
  142. Paging *paging.PagingItem
  143. List []*HomeChartListResp `description:"图表列表"`
  144. }
  145. type ChartCollectReq struct {
  146. ChartId int `description:"图表ID"`
  147. }
  148. // 获取图表列表
  149. func GetChartList(condition string, pars []interface{}, startSize, pageSize int) (items []*HomeChartListResp, err error) {
  150. o := orm.NewOrm()
  151. sql := ` SELECT * FROM cygx_chart AS a WHERE a.publish_status=1 `
  152. if condition != "" {
  153. sql += condition
  154. }
  155. sql += ` ORDER BY chart_id DESC LIMIT ?,? `
  156. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  157. return
  158. }
  159. // 获取所有同步过来的图表
  160. func GetChartListAll() (items []*HomeChartListResp, err error) {
  161. o := orm.NewOrm()
  162. sql := ` SELECT chart_id FROM cygx_chart `
  163. _, err = o.Raw(sql).QueryRows(&items)
  164. return
  165. }
  166. ////获取图表列表
  167. //func GetChartCtagIds(ctagId int ) (items []*HomeChartListResp, err error) {
  168. // o := orm.NewOrm()
  169. // sql := ` SELECT * FROM cygx_chart AS a WHERE a.publish_status=1 AND ctag_id = 1 ORDER BY create_date DESC LIMIT 2 `
  170. // _, err = o.Raw(sql,ctagId).QueryRows(&items)
  171. // return
  172. //}
  173. // 获取图表列表
  174. func GetChartListCollection(chartIds string, userId, startSize, pageSize int) (items []*HomeChartListResp, err error) {
  175. o := orm.NewOrm()
  176. sql := ` SELECT a.*,
  177. t.create_time AS t_create_time,
  178. c.create_time AS c_create_time,
  179. ( SELECT COUNT(*) FROM cygx_chart_top AS t WHERE t.chart_id = a.chart_id AND t.user_id = ? ) AS num_top,
  180. ( SELECT COUNT(*) FROM cygx_chart_collect AS c WHERE c.chart_id = a.chart_id AND c.user_id = ? ) AS num_c
  181. FROM
  182. cygx_chart_all AS a
  183. LEFT JOIN cygx_chart_top AS t ON t.chart_id = a.chart_id
  184. LEFT JOIN cygx_chart_collect AS c ON c.chart_id = a.chart_id
  185. WHERE
  186. 1=1
  187. AND a.chart_id IN (` + chartIds + `)
  188. GROUP BY
  189. a.chart_id
  190. ORDER BY
  191. t_create_time DESC,
  192. c_create_time DESC LIMIT ?,? `
  193. _, err = o.Raw(sql, userId, userId, startSize, pageSize).QueryRows(&items)
  194. return
  195. }
  196. // 获取图表列表
  197. func GetChartListCollectionNew(condition string, pars []interface{}, userId, startSize, pageSize int) (items []*HomeChartListResp, err error) {
  198. o := orm.NewOrm()
  199. sql := ` SELECT a.*,
  200. t.create_time AS t_create_time,
  201. c.create_time AS c_create_time,
  202. ( SELECT COUNT(*) FROM cygx_chart_top AS t WHERE t.chart_id = a.chart_id AND t.user_id = ? ) AS is_top,
  203. ( SELECT COUNT(*) FROM cygx_chart_collect AS c WHERE c.chart_id = a.chart_id AND c.user_id = ? ) AS num_c
  204. FROM
  205. cygx_chart_all AS a
  206. LEFT JOIN cygx_chart_top AS t ON t.chart_id = a.chart_id
  207. LEFT JOIN cygx_chart_collect AS c ON c.chart_id = a.chart_id
  208. WHERE
  209. 1=1
  210. ` + condition + `
  211. GROUP BY
  212. a.chart_id
  213. ORDER BY
  214. t_create_time DESC,
  215. c_create_time DESC LIMIT ?,? `
  216. _, err = o.Raw(sql, userId, userId, pars, startSize, pageSize).QueryRows(&items)
  217. return
  218. }
  219. // 获取图表列表本地
  220. func GetChartListCollectionWithCygx(userId, startSize, pageSize int) (items []*HomeChartListResp, err error) {
  221. o := orm.NewOrm()
  222. sql := ` SELECT
  223. a.*,
  224. t.create_time AS t_create_time,
  225. c.create_time AS c_create_time,
  226. ( SELECT COUNT(*) FROM cygx_chart_top AS t WHERE t.chart_id = a.chart_id AND t.user_id = ? ) AS num_top,
  227. ( SELECT COUNT(*) FROM cygx_chart_collect AS c WHERE c.chart_id = a.chart_id AND c.user_id = ? ) AS num_c
  228. FROM
  229. cygx_chart_collect AS c
  230. INNER JOIN cygx_chart AS a ON c.chart_id = a.chart_id
  231. LEFT JOIN cygx_chart_top AS t ON t.chart_id = a.chart_id
  232. WHERE
  233. 1=1
  234. AND c.user_id =?
  235. GROUP BY
  236. a.chart_id
  237. ORDER BY
  238. t_create_time DESC,
  239. c_create_time DESC LIMIT ?,? `
  240. _, err = o.Raw(sql, userId, userId, userId, startSize, pageSize).QueryRows(&items)
  241. return
  242. }
  243. func GetChartListConfig() (items []*HomeChartListResp, err error) {
  244. o := orm.NewOrm()
  245. 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 `
  246. _, err = o.Raw(sql).QueryRows(&items)
  247. return
  248. }
  249. // 获取图表数量
  250. func GetChartCount(condition string, pars []interface{}) (count int, err error) {
  251. o := orm.NewOrm()
  252. sql := `SELECT COUNT(1) AS count
  253. FROM cygx_chart AS a
  254. WHERE a.publish_status=1 `
  255. if condition != "" {
  256. sql += condition
  257. }
  258. err = o.Raw(sql, pars).QueryRow(&count)
  259. return
  260. }
  261. // 获取图表数量
  262. func GetChartCollentCount(condition string, pars []interface{}) (count int, err error) {
  263. o := orm.NewOrm()
  264. sql := `SELECT COUNT(1) AS count
  265. FROM cygx_chart_all AS a
  266. WHERE 1=1 `
  267. if condition != "" {
  268. sql += condition
  269. }
  270. err = o.Raw(sql, pars).QueryRow(&count)
  271. return
  272. }
  273. func GetChartDetailById(chartId, uid int) (item *CygxChartDetail, err error) {
  274. o := orm.NewOrm()
  275. 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
  276. FROM
  277. cygx_chart_all as a
  278. WHERE
  279. a.chart_id =? `
  280. err = o.Raw(sql, uid, chartId).QueryRow(&item)
  281. return
  282. }