report_selection.go 14 KB

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