report_selection.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  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 CygxReportSelection struct {
  9. ArticleId int `orm:"column(article_id);pk"description:"报告id"`
  10. AddType string `description:"更新方式 1重新编辑 ,2 继承往期"`
  11. Title string `description:"标题"`
  12. Department 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. InheritPeriods string `description:"继承期数"`
  20. ProductDescription string `description:"产品说明"`
  21. UpdateDescription string `description:"更新说明"`
  22. FocusOn string `description:"近期重点关注方向"`
  23. AdminId int `description:"销售/管理员ID"`
  24. AdminName string `description:"销售/管理员姓名"`
  25. MarketStrategy string `description:"市场策略核心逻辑汇总"`
  26. ReportLink string `description:"报告链接"`
  27. }
  28. type CygxReportSelectionRep struct {
  29. ArticleId int `orm:"column(article_id);pk"description:"报告id"`
  30. AddType string `description:"更新方式 1重新编辑 ,2 继承往期"`
  31. Title string `description:"标题"`
  32. Department string `description:"作者"`
  33. PublishStatus int `description:"发布状态,1已发布,0未发布"`
  34. PublishDate string `description:"发布时间"`
  35. CreateTime string `description:"创建时间"`
  36. LastUpdatedTime string `description:"最后一次更新时间"`
  37. Periods string `description:"期数"`
  38. HavePublish int `description:"是否发布过,1是,0否"`
  39. Pv int `description:"PV"`
  40. Uv int `description:"Uv"`
  41. ProductDescription string `description:"产品说明"`
  42. UpdateDescription string `description:"更新说明"`
  43. FocusOn string `description:"近期重点关注方向"`
  44. InheritPeriods string `description:"继承期数"`
  45. AdminId int `description:"销售/管理员ID"`
  46. AdminName string `description:"销售/管理员姓名"`
  47. MarketStrategy string `description:"市场策略核心逻辑汇总"`
  48. ReportLink string `description:"报告链接"`
  49. VisibleRange int `description:"设置可见范围1全部,0内部"`
  50. IsSendWxMsg int `description:"是否推送过微信模版消息,1是,0否"`
  51. }
  52. type CygxReportSelectionListRep struct {
  53. Paging *paging.PagingItem `description:"分页数据"`
  54. List []*CygxReportSelectionRep
  55. }
  56. type AddCygxReportSelection struct {
  57. ArticleId int `description:"报告Id ,传0时新增,大于0时修改"`
  58. AddType string `description:"更新方式 1重新编辑 ,2 继承往期"`
  59. InheritPeriods string `description:"继承期数"`
  60. Title string `description:"标题"`
  61. Department string `description:"作者"`
  62. PublishDate string `description:"发布时间"`
  63. ProductDescription string `description:"产品说明"`
  64. UpdateDescription string `description:"更新说明"`
  65. FocusOn string `description:"近期重点关注方向"`
  66. DoType int `description:"操作方式,1发布,0保存"`
  67. MarketStrategy string `description:"市场策略核心逻辑汇总"`
  68. ReportLink string `description:"报告链接"`
  69. List []*AddCygxReportSelectionLog `description:"标的列表内容"`
  70. ListChartSummary []*AddCygxReportSelectionChartLog `description:"行业核心逻辑汇总列表"`
  71. }
  72. type OverviewArticle struct {
  73. ArticleId int `description:"文章ID"`
  74. Title string `description:"文章标题"`
  75. }
  76. type DetailCygxReportSelectionRep struct {
  77. ArticleId int `description:"报告Id ,传0时新增,大于0时修改"`
  78. AddType string `description:"更新方式 1重新编辑 ,2 继承往期"`
  79. Title string `description:"标题"`
  80. Department string `description:"作者"`
  81. PublishStatus int `description:"发布状态,1已发布,0未发布"`
  82. PublishDate string `description:"发布时间"`
  83. CreateTime string `description:"创建时间"`
  84. LastUpdatedTime string `description:"最后一次更新时间"`
  85. Periods string `description:"期数"`
  86. HavePublish int `description:"是否发布过,1是,0否"`
  87. InheritPeriods string `description:"继承期数"`
  88. InheritPeriodsName string `description:"继承期数名称"`
  89. ProductDescription string `description:"产品说明"`
  90. UpdateDescription string `description:"更新说明"`
  91. FocusOn string `description:"近期重点关注方向"`
  92. MarketStrategy string `description:"市场策略核心逻辑汇总"`
  93. ReportLink string `description:"报告链接"`
  94. List []*CygxReportSelectionChart `description:"内容列表"`
  95. }
  96. type HistoryReportSelectionRep struct {
  97. Count int `description:"数量"`
  98. List []*HistoryReportSelectionChart `description:"内容列表"`
  99. }
  100. type HistoryReportSelectionChart struct {
  101. //ChartPermissionId int `description:"行业ID"`
  102. ChartPermissionName string `description:"行业名称"`
  103. List []*HistoryReportSelectionLogResp `description:"列表内容’"`
  104. }
  105. type HistoryReportSelectionLogResp struct {
  106. IndustrialSubjectId string `description:"标的ID"`
  107. SubjectName string `description:"标的名称"`
  108. Count int `description:"数量"`
  109. }
  110. type ReportSelectionId struct {
  111. ArticleId int `description:"报告ID"`
  112. }
  113. // 添加
  114. func AddCygxReportSelectionOrm(itme *CygxReportSelection, items []*CygxReportSelectionLog, itemsChart []*CygxReportSelectionChartLog) (newArtId int64, err error) {
  115. o := orm.NewOrm()
  116. to, err := o.Begin()
  117. if err != nil {
  118. return
  119. }
  120. defer func() {
  121. if err != nil {
  122. fmt.Println(err)
  123. _ = to.Rollback()
  124. } else {
  125. _ = to.Commit()
  126. }
  127. }()
  128. newArtId, err = to.Insert(itme)
  129. if err != nil {
  130. return
  131. }
  132. for _, v := range items {
  133. v.ArticleId = int(newArtId)
  134. _, err = to.Insert(v)
  135. if err != nil {
  136. return
  137. }
  138. }
  139. for _, v := range itemsChart {
  140. v.ArticleId = int(newArtId)
  141. _, err = to.Insert(v)
  142. if err != nil {
  143. return
  144. }
  145. }
  146. return
  147. }
  148. // 编辑
  149. func UpdateCygxReportSelectionOrm(item *CygxReportSelection, items []*CygxReportSelectionLog, itemsChart []*CygxReportSelectionChartLog) (newId int64, err error) {
  150. o := orm.NewOrm()
  151. to, err := o.Begin()
  152. if err != nil {
  153. return
  154. }
  155. defer func() {
  156. if err != nil {
  157. fmt.Println(err)
  158. _ = to.Rollback()
  159. } else {
  160. _ = to.Commit()
  161. }
  162. }()
  163. articleId := item.ArticleId
  164. fmt.Println("m文章ID", articleId)
  165. sql := `UPDATE cygx_report_selection SET title=?, department=? ,add_type = ?, inherit_periods= ? ,product_description=?,update_description=?,focus_on=?, publish_status = ?,publish_date = ?,last_updated_time = ?,periods = ?,admin_id =? ,admin_name =? ,have_publish = ?,market_strategy = ?,report_link = ? WHERE article_id=?`
  166. _, err = to.Raw(sql, item.Title, item.Department, item.AddType, item.InheritPeriods, item.ProductDescription, item.UpdateDescription, item.FocusOn, item.PublishStatus, item.PublishDate, item.LastUpdatedTime, item.Periods, item.AdminId, item.AdminName, item.HavePublish, item.MarketStrategy, item.ReportLink, articleId).Exec()
  167. if err != nil {
  168. return
  169. }
  170. sql = ` DELETE FROM cygx_report_selection_log WHERE article_id = ?`
  171. _, err = to.Raw(sql, articleId).Exec()
  172. if err != nil {
  173. return
  174. }
  175. for _, v := range items {
  176. v.ArticleId = articleId
  177. newId, err = to.Insert(v)
  178. if err != nil {
  179. return
  180. }
  181. }
  182. sql = ` DELETE FROM cygx_report_selection_chart_log WHERE article_id = ?`
  183. _, err = to.Raw(sql, articleId).Exec()
  184. if err != nil {
  185. return
  186. }
  187. for _, v := range itemsChart {
  188. v.ArticleId = articleId
  189. newId, err = to.Insert(v)
  190. if err != nil {
  191. return
  192. }
  193. }
  194. return
  195. }
  196. // 获取数量
  197. func GetCygxReportSelection(condition string, pars []interface{}) (count int, err error) {
  198. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_report_selection as rs WHERE 1= 1 `
  199. if condition != "" {
  200. sqlCount += condition
  201. }
  202. o := orm.NewOrm()
  203. err = o.Raw(sqlCount, pars).QueryRow(&count)
  204. return
  205. }
  206. // 通过纪要ID获取活动详情
  207. func GetCygxReportSelectionInfoById(articleId int) (item *CygxReportSelectionRep, err error) {
  208. o := orm.NewOrm()
  209. sql := `SELECT * FROM cygx_report_selection WHERE article_id=?`
  210. err = o.Raw(sql, articleId).QueryRow(&item)
  211. return
  212. }
  213. // 通过纪要ID获取活动详情
  214. func GetCygxReportSelectionInfoByPeriods(periods string) (item *CygxReportSelectionRep, err error) {
  215. o := orm.NewOrm()
  216. sql := `SELECT * FROM cygx_report_selection WHERE periods=?`
  217. err = o.Raw(sql, periods).QueryRow(&item)
  218. return
  219. }
  220. // 删除数据
  221. func DeleteCygxReportSelection(articleId int) (err error) {
  222. o := orm.NewOrm()
  223. to, err := o.Begin()
  224. if err != nil {
  225. return
  226. }
  227. defer func() {
  228. if err != nil {
  229. fmt.Println(err)
  230. _ = to.Rollback()
  231. } else {
  232. _ = to.Commit()
  233. }
  234. }()
  235. sql := ` DELETE FROM cygx_report_selection WHERE article_id=? `
  236. _, err = to.Raw(sql, articleId).Exec()
  237. if err != nil {
  238. return
  239. }
  240. sql = ` DELETE FROM cygx_report_selection_log WHERE article_id = ?`
  241. _, err = to.Raw(sql, articleId).Exec()
  242. return
  243. }
  244. // 列表
  245. func GetReportSelectionList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxReportSelectionRep, err error) {
  246. o := orm.NewOrm()
  247. sql := `SELECT *,
  248. (SELECT COUNT(1) FROM cygx_report_history_record AS h WHERE h.article_id=rs.article_id AND report_type = 'bgjx' AND h.company_id != 16 ) AS pv,
  249. (SELECT COUNT(DISTINCT user_id) FROM cygx_report_history_record AS h WHERE h.article_id=rs.article_id AND report_type = 'bgjx' AND h.company_id != 16 ) AS uv
  250. FROM cygx_report_selection as rs WHERE 1= 1 `
  251. if condition != "" {
  252. sql += condition
  253. }
  254. sql += ` ORDER BY rs.publish_date DESC LIMIT ?,?`
  255. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  256. return
  257. }
  258. // 修改发布状态
  259. func ReportSelectionPublishAndCancel(item *CygxReportSelectionRep) (err error) {
  260. o := orm.NewOrm()
  261. sql := `UPDATE cygx_report_selection SET publish_status=? , last_updated_time= ?, periods= ? ,admin_id =? ,admin_name =? ,have_publish = 1 WHERE article_id=? `
  262. _, err = o.Raw(sql, item.PublishStatus, time.Now(), item.Periods, item.AdminId, item.AdminName, item.ArticleId).Exec()
  263. return
  264. }
  265. // 修改可见范围
  266. func ReportSelectionVisibleRange(item *CygxReportSelectionRep) (err error) {
  267. o := orm.NewOrm()
  268. sql := `UPDATE cygx_report_selection SET is_send_wx_msg = 1, visible_range=? , last_updated_time= ?,admin_id =? ,admin_name =? WHERE article_id=? `
  269. _, err = o.Raw(sql, item.VisibleRange, time.Now(), item.AdminId, item.AdminName, item.ArticleId).Exec()
  270. return
  271. }
  272. type CygxReportSelectionPeriodsRep struct {
  273. Periods string `description:"继承期数"`
  274. InheritPeriodsName string `description:"继承期数"`
  275. }
  276. type CygxReportSelectionPeriodsListRep struct {
  277. Paging *paging.PagingItem `description:"分页数据"`
  278. List []*CygxReportSelectionPeriodsRep
  279. }
  280. // 期数列表
  281. func GetReportSelectionListPeriods(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxReportSelectionPeriodsRep, err error) {
  282. o := orm.NewOrm()
  283. sql := `SELECT periods FROM cygx_report_selection as rs WHERE have_publish = 1`
  284. if condition != "" {
  285. sql += condition
  286. }
  287. sql += ` ORDER BY rs.periods DESC LIMIT ?,?`
  288. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  289. return
  290. }
  291. type ReportSelectionChartPermission struct {
  292. PermissionName string `description:"权限名称"`
  293. IcoLink string `orm:"column(image_url)"description:"图标链接"`
  294. List []*CygxReportSelectionLogDetail
  295. }
  296. type CygxReportSelectionLogDetail struct {
  297. IndustrialManagementId string `description:"产业Id"`
  298. SubjectName string `description:"标的名称"`
  299. Body string `description:"内容"`
  300. }
  301. // 列表
  302. func GetReportSelectionlogSonListAll(articleId, chartPermissionId int) (items []*CygxReportSelectionLogDetail, err error) {
  303. o := orm.NewOrm()
  304. sql := `SELECT c.permission_name ,s.subject_name , l.*
  305. FROM
  306. cygx_report_selection_log AS l
  307. INNER JOIN chart_permission AS c ON c.chart_permission_id = l.chart_permission_id
  308. INNER JOIN cygx_industrial_subject AS s ON s.industrial_subject_id = l.industrial_subject_id
  309. WHERE l.article_id = ? AND l.chart_permission_id =?`
  310. _, err = o.Raw(sql, articleId, chartPermissionId).QueryRows(&items)
  311. return
  312. }
  313. // 获取,bgjx:报告精选、bzyjhz:本周研究汇总、szjyhz:上周纪要汇总 阅读记录
  314. func GetReportSelectionHistoryList(articleId int, condition string) (items []*ArticleHistoryRep, err error) {
  315. o := orm.NewOrm()
  316. sql := `SELECT
  317. h.real_name,
  318. h.mobile,
  319. h.company_name,
  320. h.seller_name,
  321. h.create_time
  322. FROM
  323. cygx_report_history_record AS h
  324. WHERE
  325. h.article_id = ? AND h.company_id != 16 `
  326. if condition != "" {
  327. sql = sql + condition + ` GROUP BY h.id`
  328. }
  329. _, err = o.Raw(sql, articleId).QueryRows(&items)
  330. return
  331. }
  332. type CygxArticleIdAndTableResp struct {
  333. Title string `description:"标题"`
  334. }
  335. // 通过纪要ID获取不同类型报告的title详情
  336. func GetArticleInfoByIdAndTable(table string, articleId int) (item *CygxArticleIdAndTableResp, err error) {
  337. o := orm.NewOrm()
  338. sql := `SELECT title FROM ` + table + ` WHERE article_id=?`
  339. err = o.Raw(sql, articleId).QueryRow(&item)
  340. return
  341. }