research_summary.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. package cygx
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "time"
  7. )
  8. type CygxResearchSummary struct {
  9. ArticleId int `orm:"column(article_id);pk"description:"报告id"`
  10. Title string `description:"标题"`
  11. Department string `description:"作者"`
  12. Abstract string `description:"摘要"`
  13. PublishStatus int `description:"发布状态,1已发布,0未发布"`
  14. PublishDate time.Time `description:"发布时间"`
  15. CreateTime time.Time `description:"创建时间"`
  16. LastUpdatedTime time.Time `description:"最后一次更新时间"`
  17. Periods string `description:"期数"`
  18. HavePublish int `description:"是否发布过,1是,0否"`
  19. AdminId int `description:"销售/管理员ID"`
  20. AdminName string `description:"销售/管理员姓名"`
  21. }
  22. type CygxResearchSummaryRep struct {
  23. ArticleId int `orm:"column(article_id);pk"description:"报告id"`
  24. Title string `description:"标题"`
  25. Department string `description:"作者"`
  26. Abstract string `description:"摘要"`
  27. PublishStatus int `description:"发布状态,1已发布,0未发布"`
  28. PublishDate string `description:"发布时间"`
  29. CreateTime string `description:"创建时间"`
  30. LastUpdatedTime string `description:"最后一次更新时间"`
  31. Periods string `description:"期数"`
  32. HavePublish int `description:"是否发布过,1是,0否"`
  33. Pv int `description:"PV"`
  34. Uv int `description:"Uv"`
  35. AdminId int `description:"销售/管理员ID"`
  36. AdminName string `description:"销售/管理员姓名"`
  37. VisibleRange int `description:"设置可见范围1全部,0内部"`
  38. IsSendWxMsg int `description:"是否推送过微信模版消息,1是,0否"`
  39. }
  40. type CygxResearchSummaryListRep struct {
  41. Paging *paging.PagingItem `description:"分页数据"`
  42. List []*CygxResearchSummaryRep
  43. }
  44. type AddCygxResearchSummary struct {
  45. ArticleId int `description:"报告Id ,传0时新增,大于0时修改"`
  46. Title string `description:"标题"`
  47. Department string `description:"作者"`
  48. Abstract string `description:"摘要"`
  49. DoType int `description:"操作方式,1发布,0保存"`
  50. PublishDate string `description:"发布时间"`
  51. Content *CygxRSlFirstList `description:"内容"`
  52. }
  53. type DetailCygxResearchSummaryRep struct {
  54. ArticleId int `description:"报告Id ,传0时新增,大于0时修改"`
  55. Title string `description:"标题"`
  56. Department string `description:"作者"`
  57. Abstract string `description:"摘要"`
  58. PublishDate string `description:"发布时间"`
  59. PublishStatus int `description:"发布状态,1已发布,0未发布"`
  60. SortSdbg string `description:"深度报告排序"`
  61. ListSdbg []*CygxRSlChartPermissionIco `description:"类型——’SDBG:深度报告片篇’"`
  62. SortCydyjy string `description:"产业调研纪要排序"`
  63. ListCydyjy []*CygxRSlChartPermissionIco `description:"类型——’CYDYJY:产业调研纪要’"`
  64. SortSjdp string `description:"事件点评排序"`
  65. ListSsgs []*CygxRSlChartPermissionIco `description:"类型——’SSGS:上市公司调研纪要篇’"`
  66. SortSsgs string `description:"上市公司调研纪要篇排序"`
  67. ListSjdp []*AddCygxResearchSummaryLog `description:"类型——’SJDP:事件点评"`
  68. SortBzchjh string `description:"本周晨会精华排序"`
  69. ListBzchjh []*CygxRSlChartPermissionIco `description:"类型——’BZCHJH:本周晨会精华’"`
  70. SortYanx string `description:"研选排序"`
  71. ListYanx []*CygxRSlChartPermissionIco `description:"类型——’YANX:研选’"`
  72. }
  73. type DetailCygxResearchSummaryTmpRep struct {
  74. Title string `description:"标题"`
  75. Department string `description:"作者"`
  76. Abstract string `description:"摘要"`
  77. PublishDate string `description:"发布时间"`
  78. SortSdbg string `description:"深度报告排序"`
  79. ListSdbg []*CygxRSlChartPermissionIcoTmp `description:"类型——’SDBG:深度报告片篇’"`
  80. SortCydyjy string `description:"产业调研纪要排序"`
  81. ListCydyjy []*CygxRSlChartPermissionIcoTmp `description:"类型——’CYDYJY:产业调研纪要’"`
  82. SortSjdp string `description:"事件点评排序"`
  83. ListSjdp []*AddCygxResearchSummaryLog `description:"类型——’SJDP:事件点评"`
  84. SortBzchjh string `description:"本周晨会精华排序"`
  85. ListBzchjh []*CygxRSlChartPermissionIcoTmp `description:"类型——’BZCHJH:本周晨会精华’"`
  86. SortSsgs string `description:"上市公司调研纪要篇排序"`
  87. ListSsgs []*CygxRSlChartPermissionIcoTmp `description:"类型——’SSGS:上市公司调研纪要篇’"`
  88. SortYanx string `description:"研选排序"`
  89. ListYanx []*CygxRSlChartPermissionIcoTmp `description:"类型——’YANX:研选’"`
  90. }
  91. type ResearchSummaryId struct {
  92. ArticleId int `description:"报告Id"`
  93. }
  94. // 添加
  95. func AddCygxResearchSummaryOrm(itme *CygxResearchSummary, items []*CygxResearchSummaryLog) (newArtId int64, err error) {
  96. o := orm.NewOrmUsingDB("hz_cygx")
  97. to, err := o.Begin()
  98. if err != nil {
  99. return
  100. }
  101. defer func() {
  102. if err != nil {
  103. fmt.Println(err)
  104. _ = to.Rollback()
  105. } else {
  106. _ = to.Commit()
  107. }
  108. }()
  109. newArtId, err = to.Insert(itme)
  110. if err != nil {
  111. return
  112. }
  113. for _, v := range items {
  114. v.ArticleId = int(newArtId)
  115. _, err = to.Insert(v)
  116. if err != nil {
  117. return
  118. }
  119. }
  120. return
  121. }
  122. // 编辑
  123. func UpdateCygxResearchSummaryOrm(item *CygxResearchSummary, items []*CygxResearchSummaryLog) (newId int64, err error) {
  124. o := orm.NewOrmUsingDB("hz_cygx")
  125. to, err := o.Begin()
  126. if err != nil {
  127. return
  128. }
  129. defer func() {
  130. if err != nil {
  131. fmt.Println(err)
  132. _ = to.Rollback()
  133. } else {
  134. _ = to.Commit()
  135. }
  136. }()
  137. articleId := item.ArticleId
  138. sql := `UPDATE cygx_research_summary SET title=?, department=? ,abstract = ?,publish_status = ?,publish_date = ?,last_updated_time = ?,periods = ?,admin_id =? ,admin_name =?,have_publish = ? WHERE article_id=?`
  139. _, err = to.Raw(sql, item.Title, item.Department, item.Abstract, item.PublishStatus, item.PublishDate, item.LastUpdatedTime, item.Periods, item.AdminId, item.AdminName, item.HavePublish, articleId).Exec()
  140. if err != nil {
  141. return
  142. }
  143. sql = ` DELETE FROM cygx_research_summary_log WHERE article_id = ?`
  144. _, err = to.Raw(sql, articleId).Exec()
  145. if err != nil {
  146. return
  147. }
  148. for _, v := range items {
  149. v.ArticleId = articleId
  150. newId, err = to.Insert(v)
  151. if err != nil {
  152. return
  153. }
  154. }
  155. return
  156. }
  157. // 获取数量
  158. func GetCygxResearchSummary(condition string, pars []interface{}) (count int, err error) {
  159. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_research_summary as rs WHERE 1= 1 `
  160. if condition != "" {
  161. sqlCount += condition
  162. }
  163. o := orm.NewOrmUsingDB("hz_cygx")
  164. err = o.Raw(sqlCount, pars).QueryRow(&count)
  165. return
  166. }
  167. // 通过纪要ID获取活动详情
  168. func GetCygxResearchSummaryInfoById(articleId int) (item *CygxResearchSummaryRep, err error) {
  169. o := orm.NewOrmUsingDB("hz_cygx")
  170. sql := `SELECT * FROM cygx_research_summary WHERE article_id=?`
  171. err = o.Raw(sql, articleId).QueryRow(&item)
  172. return
  173. }
  174. // 删除数据
  175. func DeleteCygxResearchSummary(articleId int) (err error) {
  176. o := orm.NewOrmUsingDB("hz_cygx")
  177. to, err := o.Begin()
  178. if err != nil {
  179. return
  180. }
  181. defer func() {
  182. if err != nil {
  183. fmt.Println(err)
  184. _ = to.Rollback()
  185. } else {
  186. _ = to.Commit()
  187. }
  188. }()
  189. sql := ` DELETE FROM cygx_research_summary WHERE article_id=? `
  190. _, err = to.Raw(sql, articleId).Exec()
  191. if err != nil {
  192. return
  193. }
  194. sql = ` DELETE FROM cygx_research_summary_log WHERE article_id = ?`
  195. _, err = to.Raw(sql, articleId).Exec()
  196. return
  197. }
  198. // 列表
  199. func GetResearchSummaryList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxResearchSummaryRep, err error) {
  200. o := orm.NewOrmUsingDB("hz_cygx")
  201. sql := `SELECT *,
  202. (SELECT COUNT(1) FROM cygx_report_history_record AS h WHERE h.article_id=rs.article_id AND report_type = 'bzyjhz' AND h.company_id != 16) AS pv,
  203. (SELECT COUNT(DISTINCT user_id) FROM cygx_report_history_record AS h WHERE h.article_id=rs.article_id AND report_type = 'bzyjhz' AND h.company_id != 16 ) AS uv
  204. FROM cygx_research_summary as rs WHERE 1= 1 `
  205. if condition != "" {
  206. sql += condition
  207. }
  208. sql += ` ORDER BY rs.publish_date DESC LIMIT ?,?`
  209. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  210. return
  211. }
  212. // 修改发布状态
  213. func ResearchSummaryPublishAndCancel(item *CygxResearchSummaryRep) (err error) {
  214. o := orm.NewOrmUsingDB("hz_cygx")
  215. sql := `UPDATE cygx_research_summary SET publish_status=? , last_updated_time= ?, periods= ? ,admin_id =? ,admin_name =? ,have_publish = 1 WHERE article_id=? `
  216. _, err = o.Raw(sql, item.PublishStatus, time.Now(), item.Periods, item.AdminId, item.AdminName, item.ArticleId).Exec()
  217. return
  218. }
  219. // 修改可见范围
  220. func ResearchSummaryVisibleRange(item *CygxResearchSummaryRep) (err error) {
  221. o := orm.NewOrmUsingDB("hz_cygx")
  222. sql := `UPDATE cygx_research_summary SET is_send_wx_msg = 1, visible_range=? , last_updated_time= ?,admin_id =? ,admin_name =? WHERE article_id=? `
  223. _, err = o.Raw(sql, item.VisibleRange, time.Now(), item.AdminId, item.AdminName, item.ArticleId).Exec()
  224. return
  225. }
  226. type DetailCygxResearchSummaryTmpRepS struct {
  227. List []*CygxRSlChartPermissionIcoTmps `description:"类型——’SDBG:深度报告片篇’"`
  228. }
  229. type CygxRSlChartPermissionIcoTmps struct {
  230. ChartPermissionId int `description:"行业ID"`
  231. ChartPermissionName string `description:"行业名称"`
  232. List []string
  233. //List make([]string, 0)
  234. }
  235. // 列表
  236. func GetResearchSummarylogListFirst(articleId int) (items []*ResearchSummaryChartPermission, err error) {
  237. o := orm.NewOrmUsingDB("hz_cygx")
  238. sql := `SELECT l.*
  239. FROM cygx_research_summary_log AS l
  240. WHERE l.article_id = ?
  241. GROUP BY l.type
  242. ORDER BY l.sort ASC`
  243. _, err = o.Raw(sql, articleId).QueryRows(&items)
  244. return
  245. }
  246. type ResearchSummaryChartPermission struct {
  247. ListName string `description:"列表名称"`
  248. IcoLink string `orm:"column(image_url)"description:"图标链接"`
  249. Type string `description:"类型'SDBG深度报告片篇,’CYDYJY:产业调研纪要’,’SJDP事件点评,’BZCHJH:本周晨会精华’"`
  250. List []*CygxResearchSummaryLogSecond
  251. }
  252. type CygxResearchSummaryLogSecond struct {
  253. PermissionName string `description:"行业名称"`
  254. ChartPermissionId int `description:"行业ID"`
  255. IcoLink string `orm:"column(image_url)"description:"图标链接"`
  256. List []*CygxResearchSummaryLogThird
  257. }
  258. type CygxResearchSummaryLogThird struct {
  259. Body string `description:"内容"`
  260. }
  261. // 列表
  262. func GetResearchSummarylogSonListSecond(articleId int, artType string) (items []*CygxResearchSummaryLogSecond, err error) {
  263. o := orm.NewOrmUsingDB("hz_cygx")
  264. sql := `SELECT l.*
  265. FROM
  266. cygx_research_summary_log AS l
  267. WHERE l.article_id = ? AND l.type =?
  268. GROUP BY l.chart_permission_id
  269. ORDER BY l.chart_permission_sort ASC`
  270. _, err = o.Raw(sql, articleId, artType).QueryRows(&items)
  271. return
  272. }
  273. // 列表
  274. func GetResearchSummarylogSonListThird(articleId, chartPermissionId int, artType string) (items []*CygxResearchSummaryLogThird, err error) {
  275. o := orm.NewOrmUsingDB("hz_cygx")
  276. sql := `SELECT l.link_article_id,l.body ,a.video_url
  277. FROM cygx_research_summary_log AS l
  278. LEFT JOIN cygx_article as a ON a.article_id = l.link_article_id
  279. WHERE l.article_id = ? AND l.type =? AND l.chart_permission_id = ?
  280. ORDER BY l.chart_permission_sort ASC `
  281. _, err = o.Raw(sql, articleId, artType, chartPermissionId).QueryRows(&items)
  282. return
  283. }