minutes_summary.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  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 CygxMinutesSummary 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 CygxMinutesSummaryRep 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 CygxMinutesSummaryListRep struct {
  41. Paging *paging.PagingItem `description:"分页数据"`
  42. List []*CygxMinutesSummaryRep
  43. }
  44. type AddCygxMinutesSummary 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 *CygxMinutesList `description:"内容"`
  52. List []*CygxMSlChartPermission `description:"内容"`
  53. }
  54. type DetailCygxMinutesSummaryRep struct {
  55. ArticleId int `description:"报告Id ,传0时新增,大于0时修改"`
  56. Title string `description:"标题"`
  57. Department string `description:"作者"`
  58. Abstract string `description:"摘要"`
  59. PublishDate string `description:"发布时间"`
  60. PublishStatus int `description:"发布状态,1已发布,0未发布"`
  61. //List []*CygxRSlChartPermissionIco `description:"内容列表"`
  62. SortCydyjy string `description:"产业调研纪要排序"`
  63. ListCydyjy []*CygxRSlChartPermissionIco `description:"类型——’CYDYJY:产业调研纪要’"`
  64. ListSsgs []*CygxRSlChartPermissionIco `description:"类型——’SSGS:上市公司调研纪要篇’"`
  65. SortSsgs string `description:"上市公司调研纪要篇排序"`
  66. SortYanx string `description:"研选排序"`
  67. ListYanx []*AddCygxMinutesSummaryLog `description:"类型——’YANX:研选’"`
  68. }
  69. type CygxMinutesList struct {
  70. ListCydyjy []*CygxRSlChartPermission `description:"类型——’CYDYJY:产业调研纪要’"`
  71. SortCydyjy string `description:"产业调研纪要排序"`
  72. ListSsgs []*CygxRSlChartPermission `description:"类型——’SSGS:上市公司调研纪要篇’"`
  73. SortSsgs string `description:"上市公司调研纪要篇排序"`
  74. ListYanx []*AddCygxMinutesSummaryLog `description:"类型——’YANX:研选’"`
  75. SortYanx string `description:"研选排序"`
  76. }
  77. type DetailCygxMinutesSummaryTmpRep struct {
  78. Title string `description:"标题"`
  79. Department string `description:"作者"`
  80. Abstract string `description:"摘要"`
  81. PublishDate string `description:"发布时间"`
  82. SortSdbg string `description:"深度报告排序"`
  83. ListSdbg []*CygxRSlChartPermissionIcoTmp `description:"类型——’SDBG:深度报告片篇’"`
  84. SortCydyjy string `description:"产业调研纪要排序"`
  85. ListCydyjy []*CygxRSlChartPermissionIcoTmp `description:"类型——’CYDYJY:产业调研纪要’"`
  86. SortSjdp string `description:"事件点评排序"`
  87. ListSjdp []*AddCygxMinutesSummaryLog `description:"类型——’SJDP:事件点评"`
  88. SortBzchjh string `description:"本周晨会精华排序"`
  89. ListBzchjh []*CygxRSlChartPermissionIcoTmp `description:"类型——’BZCHJH:本周晨会精华’"`
  90. }
  91. type MinutesSummaryId struct {
  92. ArticleId int `description:"报告Id"`
  93. }
  94. // 添加
  95. func AddCygxMinutesSummaryOrm(itme *CygxMinutesSummary, items []*CygxMinutesSummaryLog) (newArtId int64, err error) {
  96. o := orm.NewOrm()
  97. //o.Begin()
  98. //defer func() {
  99. // fmt.Println(err)
  100. // if err == nil {
  101. // o.Commit()
  102. // } else {
  103. // o.Rollback()
  104. // }
  105. //}()
  106. newArtId, err = o.Insert(itme)
  107. if err != nil {
  108. return
  109. }
  110. for _, v := range items {
  111. v.ArticleId = int(newArtId)
  112. _, err = o.Insert(v)
  113. if err != nil {
  114. return
  115. }
  116. }
  117. return
  118. }
  119. // 编辑
  120. func UpdateCygxMinutesSummaryOrm(item *CygxMinutesSummary, items []*CygxMinutesSummaryLog) (newId int64, err error) {
  121. o := orm.NewOrmUsingDB("hz_cygx")
  122. to, err := o.Begin()
  123. if err != nil {
  124. return
  125. }
  126. defer func() {
  127. if err != nil {
  128. fmt.Println(err)
  129. _ = to.Rollback()
  130. } else {
  131. _ = to.Commit()
  132. }
  133. }()
  134. articleId := item.ArticleId
  135. fmt.Println("m文章ID", articleId)
  136. sql := `UPDATE cygx_minutes_summary SET title=?, department=? ,abstract = ?,publish_status = ?,publish_date = ?,last_updated_time = ?,periods = ?,admin_id =? ,admin_name =? ,have_publish = ? WHERE article_id=?`
  137. _, 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()
  138. if err != nil {
  139. return
  140. }
  141. sql = ` DELETE FROM cygx_minutes_summary_log WHERE article_id = ?`
  142. _, err = to.Raw(sql, articleId).Exec()
  143. if err != nil {
  144. return
  145. }
  146. for _, v := range items {
  147. v.ArticleId = articleId
  148. newId, err = to.Insert(v)
  149. if err != nil {
  150. return
  151. }
  152. }
  153. return
  154. }
  155. // 获取数量
  156. func GetCygxMinutesSummary(condition string, pars []interface{}) (count int, err error) {
  157. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_minutes_summary as rs WHERE 1= 1 `
  158. if condition != "" {
  159. sqlCount += condition
  160. }
  161. o := orm.NewOrmUsingDB("hz_cygx")
  162. err = o.Raw(sqlCount, pars).QueryRow(&count)
  163. return
  164. }
  165. // 通过纪要ID获取活动详情
  166. func GetCygxMinutesSummaryInfoById(articleId int) (item *CygxMinutesSummaryRep, err error) {
  167. o := orm.NewOrmUsingDB("hz_cygx")
  168. sql := `SELECT * FROM cygx_minutes_summary WHERE article_id=?`
  169. err = o.Raw(sql, articleId).QueryRow(&item)
  170. return
  171. }
  172. // 删除数据
  173. func DeleteCygxMinutesSummary(articleId int) (err error) {
  174. o := orm.NewOrmUsingDB("hz_cygx")
  175. to, err := o.Begin()
  176. if err != nil {
  177. return
  178. }
  179. defer func() {
  180. if err != nil {
  181. fmt.Println(err)
  182. _ = to.Rollback()
  183. } else {
  184. _ = to.Commit()
  185. }
  186. }()
  187. sql := ` DELETE FROM cygx_minutes_summary WHERE article_id=? `
  188. _, err = to.Raw(sql, articleId).Exec()
  189. if err != nil {
  190. return
  191. }
  192. sql = ` DELETE FROM cygx_minutes_summary_log WHERE article_id = ?`
  193. _, err = to.Raw(sql, articleId).Exec()
  194. return
  195. }
  196. // 列表
  197. func GetMinutesSummaryList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxMinutesSummaryRep, err error) {
  198. o := orm.NewOrmUsingDB("hz_cygx")
  199. sql := `SELECT *,
  200. (SELECT COUNT(1) FROM cygx_report_history_record AS h WHERE h.article_id=rs.article_id AND report_type = 'szjyhz' AND h.company_id != 16 ) AS pv,
  201. (SELECT COUNT(DISTINCT user_id) FROM cygx_report_history_record AS h WHERE h.article_id=rs.article_id AND report_type = 'szjyhz' AND h.company_id != 16 ) AS uv
  202. FROM cygx_minutes_summary as rs WHERE 1= 1 `
  203. if condition != "" {
  204. sql += condition
  205. }
  206. sql += ` ORDER BY rs.publish_date DESC LIMIT ?,?`
  207. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  208. return
  209. }
  210. // 修改发布状态
  211. func MinutesSummaryPublishAndCancel(item *CygxMinutesSummaryRep) (err error) {
  212. o := orm.NewOrmUsingDB("hz_cygx")
  213. sql := `UPDATE cygx_minutes_summary SET publish_status=? , last_updated_time= ?, periods= ? , admin_id= ? , admin_name= ? ,have_publish = 1 WHERE article_id=? `
  214. _, err = o.Raw(sql, item.PublishStatus, time.Now(), item.Periods, item.AdminId, item.AdminName, item.ArticleId).Exec()
  215. return
  216. }
  217. // 修改可见范围
  218. func MinutesSummaryVisibleRange(item *CygxMinutesSummaryRep) (err error) {
  219. o := orm.NewOrmUsingDB("hz_cygx")
  220. sql := `UPDATE cygx_minutes_summary SET is_send_wx_msg = 1, visible_range=? , last_updated_time= ?,admin_id =? ,admin_name =? WHERE article_id=? `
  221. _, err = o.Raw(sql, item.VisibleRange, time.Now(), item.AdminId, item.AdminName, item.ArticleId).Exec()
  222. return
  223. }
  224. // 列表
  225. func GetMinutesSummarylogListAll(articleId int) (items []*ResearchSummaryChartPermission, err error) {
  226. o := orm.NewOrmUsingDB("hz_cygx")
  227. //sql := `SELECT c.permission_name ,c.image_url,l.*
  228. // FROM
  229. // cygx_minutes_summary_log AS l
  230. // INNER JOIN chart_permission AS c ON c.chart_permission_id = l.chart_permission_id
  231. // WHERE l.article_id = ?
  232. // GROUP BY l.chart_permission_id
  233. // ORDER BY l.chart_permission_sort ASC `
  234. sql := `SELECT l.*
  235. FROM cygx_minutes_summary_log AS l
  236. WHERE l.article_id = ?
  237. GROUP BY l.type
  238. ORDER BY l.sort ASC `
  239. _, err = o.Raw(sql, articleId).QueryRows(&items)
  240. return
  241. }
  242. // 列表
  243. func GetMinutesSummarylogSonListSecond(articleId int, artType string) (items []*CygxResearchSummaryLogSecond, err error) {
  244. o := orm.NewOrmUsingDB("hz_cygx")
  245. sql := `SELECT l.*
  246. FROM
  247. cygx_minutes_summary_log AS l
  248. WHERE l.article_id = ? AND l.type =?
  249. GROUP BY l.chart_permission_id
  250. ORDER BY l.chart_permission_sort ASC`
  251. _, err = o.Raw(sql, articleId, artType).QueryRows(&items)
  252. return
  253. }
  254. // 列表
  255. func GetMinutesSummarylogListThird(articleId, chartPermissionId int, artType string) (items []*CygxResearchSummaryLogThird, err error) {
  256. o := orm.NewOrmUsingDB("hz_cygx")
  257. sql := `SELECT l.link_article_id,l.body ,a.video_url
  258. FROM cygx_minutes_summary_log AS l
  259. LEFT JOIN cygx_article as a ON a.article_id = l.link_article_id
  260. WHERE l.article_id = ? AND l.type =? AND l.chart_permission_id = ?
  261. ORDER BY l.chart_permission_sort ASC `
  262. _, err = o.Raw(sql, articleId, artType, chartPermissionId).QueryRows(&items)
  263. return
  264. }
  265. type MinutesSummaryChartPermission struct {
  266. PermissionName string `description:"行业名称"`
  267. ChartPermissionId int `description:"行业ID"`
  268. MinutesSummary string `orm:"column(image_url)"description:"图标链接"`
  269. List []*CygxMinutesSummaryLogDetail
  270. }
  271. type CygxMinutesSummaryLogDetail struct {
  272. Body string `description:"内容"`
  273. ReportLink string `orm:"column(link_article_id)"description:"报告链接"`
  274. VideoUrl string `description:"链接"`
  275. IsHaveVideo bool `description:"是否含有音频文件"`
  276. }
  277. // 列表
  278. func GetMinutesSummarylogSonListAll(articleId, chartPermissionId int) (items []*CygxMinutesSummaryLogDetail, err error) {
  279. o := orm.NewOrmUsingDB("hz_cygx")
  280. sql := `SELECT l.link_article_id,l.body ,a.video_url
  281. FROM
  282. cygx_minutes_summary_log AS l
  283. LEFT JOIN cygx_article as a ON a.article_id = l.link_article_id
  284. WHERE l.article_id = ? AND l.chart_permission_id =?`
  285. _, err = o.Raw(sql, articleId, chartPermissionId).QueryRows(&items)
  286. return
  287. }