report_article.go 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387
  1. package cygx
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "hongze/hz_crm_api/utils"
  7. "strconv"
  8. "strings"
  9. "time"
  10. )
  11. type ShowButton struct {
  12. IsShowButton bool `description:"是否展示操作按钮"`
  13. }
  14. type ReportArticleAdd struct {
  15. SubjectName string `description:"标的名称"`
  16. IndustrialManagementId int `description:"产业id"`
  17. }
  18. // 报告归类入参
  19. type ReportArticleClassificationResp struct {
  20. ReportId int `description:"报告id"`
  21. IndustrialManagementId string `description:"产业id"`
  22. //IndustrialManagementIdStr string `description:"产业id多个用 , 逗号隔开 1,2"`
  23. IndustrialSubjectIdStr string `description:"标的id多个用 , 逗号隔开 1,2"`
  24. }
  25. type CygxReportArticleID struct {
  26. ReportId int `orm:"column(id);pk"description:"报告id"`
  27. }
  28. type CygxReportArticle struct {
  29. ReportId int `orm:"column(id);pk"description:"报告id"`
  30. ArticleId int `description:"文章id"`
  31. Title string `description:"标题"`
  32. PublishDate string `description:"发布时间"`
  33. CreateDate string `description:"创建时间"`
  34. LastUpdatedTime string `description:"更新时间"`
  35. PermissionName string `orm:"column(chart_permission_name);" description:"行业"`
  36. ChartPermissionId int `description:"行业id"`
  37. SubCategoryName string `description:"主题"`
  38. MatchTypeName string `description:"匹配类型"`
  39. IndustryName string `description:"产业名称"`
  40. IndustryIdStr string `description:"产业ID"`
  41. SubjectNameStr string `description:"关联标的"`
  42. SubjectIdStr string `description:"关联Id"`
  43. IsClass int `description:"是否归类 1是、0否"`
  44. IsFilter int `description:"是否过滤 1是、0否"`
  45. ArticleIdMd5 string `description:"文章加密ID"`
  46. CategoryId int `description:"文章分类id"`
  47. ShowButton bool `description:"是否展示过滤归类按钮"`
  48. Pv int `description:"PV"`
  49. Uv int `description:"UV"`
  50. ClPv int `description:"策略平台PV"`
  51. ClUv int `description:"策略平台UV"`
  52. PublishStatus int `description:"发布状态,0未发布 ,1已发布"`
  53. CommentNum int `description:"留言数量"`
  54. NickName string `description:"作者昵称"`
  55. CollectionNum int `description:"收藏"`
  56. Stock string `description:"个股标签(上海策略品台同步)"`
  57. FieldName string `description:"产业标签(上海策略品台同步)"`
  58. Label string `description:"标签"`
  59. ListIndustrial []*IndustrialActivityGroupManagementRep
  60. ListSubject []*SubjectActivityGroupManagementRep
  61. }
  62. type GetReportArticleListRep struct {
  63. Paging *paging.PagingItem `description:"分页数据"`
  64. List []*CygxReportArticle
  65. }
  66. // 新增
  67. func AddReportArticle(item *CygxReportArticle) (err error) {
  68. o := orm.NewOrm()
  69. _, err = o.Insert(item)
  70. return
  71. }
  72. // 列表
  73. func GetReportArticleList(condition string, pars []interface{}, startSize, pageSize, isClass int) (items []*CygxReportArticle, err error) {
  74. o := orm.NewOrm()
  75. sql := ``
  76. if isClass == 1 {
  77. sql = `SELECT
  78. art.title,
  79. art.article_id,
  80. art.category_id,
  81. art.publish_date,
  82. art.is_class,
  83. art.publish_status,
  84. art.is_filter,
  85. art.stock,
  86. art.field_name,
  87. art.id,
  88. art.article_id_md5,
  89. re.chart_permission_name,
  90. re.match_type_name,
  91. ret.sub_category_name,
  92. re.chart_permission_id
  93. FROM
  94. cygx_article AS art
  95. LEFT JOIN cygx_report_mapping AS ret ON ret.category_id = art.category_id_two
  96. LEFT JOIN cygx_report_mapping AS re ON re.category_id = art.category_id
  97. LEFT JOIN cygx_industrial_article_group_management as man ON man.article_id = art.article_id
  98. WHERE 1 = 1 `
  99. } else {
  100. sql = `SELECT
  101. art.title,
  102. art.article_id,
  103. art.category_id,
  104. art.publish_date,
  105. art.is_class,
  106. art.is_filter,
  107. art.id,
  108. art.article_id_md5,
  109. art.stock,
  110. art.field_name,
  111. re.chart_permission_name,
  112. re.match_type_name,
  113. re.sub_category_name,
  114. re.chart_permission_id FROM cygx_article as art
  115. LEFT JOIN cygx_report_mapping AS ret ON ret.category_id = art.category_id_two
  116. LEFT JOIN cygx_report_mapping AS re ON re.category_id = art.category_id
  117. WHERE 1=1 `
  118. }
  119. if condition != "" {
  120. sql += condition
  121. }
  122. sql += `LIMIT ?,?`
  123. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  124. return
  125. }
  126. // 获取文章PV、UV
  127. func GetReportArticleListPvUv(condition string) (items []*CygxReportArticle, err error) {
  128. o := orm.NewOrm()
  129. sql := `SELECT
  130. ( SELECT COUNT( 1 ) FROM cygx_article_history_record_all AS h INNER JOIN wx_user AS u ON u.user_id = h.user_id WHERE h.article_id = art.article_id AND h.platfor = 1 AND h.company_id != ` + strconv.Itoa(utils.HZ_COMPANY_ID) + ` ) AS pv,
  131. (SELECT COUNT( DISTINCT h.user_id ) FROM cygx_article_history_record_all AS h INNER JOIN wx_user AS u ON u.user_id = h.user_id WHERE h.article_id = art.article_id AND h.platfor = 1 AND h.company_id != ` + strconv.Itoa(utils.HZ_COMPANY_ID) + ` ) AS uv,
  132. ( SELECT COUNT( 1 ) FROM cygx_article_history_record_all AS h WHERE h.article_id = art.article_id AND h.platfor = 2 AND is_del = 0 AND h.company_id != ` + strconv.Itoa(utils.HZ_COMPANY_ID) + ` ) AS cl_pv,
  133. (SELECT COUNT( DISTINCT h.user_id ) FROM cygx_article_history_record_all AS h WHERE h.article_id = art.article_id AND h.platfor = 2 AND is_del = 0 AND h.company_id != ` + strconv.Itoa(utils.HZ_COMPANY_ID) + ` ) AS cl_uv,
  134. ( SELECT COUNT( 1 ) FROM cygx_article_collect AS c INNER JOIN wx_user AS u ON u.user_id = c.user_id WHERE c.article_id = art.article_id ) AS collection_num,
  135. art.article_id
  136. FROM
  137. cygx_article AS art
  138. LEFT JOIN cygx_report_mapping AS re ON re.category_id = art.category_id_two
  139. LEFT JOIN cygx_industrial_article_group_management as man ON man.article_id = art.article_id
  140. WHERE 1 = 1 `
  141. if condition != "" {
  142. sql += condition
  143. }
  144. _, err = o.Raw(sql).QueryRows(&items)
  145. return
  146. }
  147. // 获取数量
  148. func GetReportArticleCount(condition string, pars []interface{}) (count int, err error) {
  149. sqlCount := ``
  150. sqlCount = ` SELECT COUNT(1) as count FROM (SELECT art.article_id
  151. FROM cygx_article AS art
  152. LEFT JOIN cygx_report_mapping AS ret ON ret.category_id = art.category_id_two
  153. LEFT JOIN cygx_report_mapping AS re ON re.category_id = art.category_id
  154. LEFT JOIN cygx_industrial_article_group_management AS man ON man.article_id = art.article_id WHERE 1= 1 ` + condition + ` GROUP BY art.article_id) as a `
  155. o := orm.NewOrm()
  156. err = o.Raw(sqlCount, pars).QueryRow(&count)
  157. return
  158. }
  159. // 获取数量
  160. func GetCygxArticleCount(condition string, pars []interface{}) (count int, err error) {
  161. o := orm.NewOrm()
  162. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_article as art WHERE 1= 1 `
  163. if condition != "" {
  164. sqlCount += condition
  165. }
  166. err = o.Raw(sqlCount, pars).QueryRow(&count)
  167. return
  168. }
  169. //修改
  170. //func EditReportArticle(item *CygxReportArticle) (err error) {
  171. // sql := `UPDATE cygx_industrial_subject SET subject_name=? WHERE industrial_subject_id=? `
  172. // o := orm.NewOrm()
  173. // _, err = o.Raw(sql, item.SubjectName, item.ReportArticleId).Exec()
  174. // return
  175. //}
  176. // 过滤
  177. func FilterReportArticle(reportArticleId int) (err error) {
  178. o := orm.NewOrm()
  179. to, err := o.Begin()
  180. if err != nil {
  181. return
  182. }
  183. defer func() {
  184. if err != nil {
  185. _ = to.Rollback()
  186. } else {
  187. _ = to.Commit()
  188. }
  189. }()
  190. //修改文章状态
  191. sql := `UPDATE cygx_article SET is_filter=1, is_class=0 WHERE id=? `
  192. _, err = to.Raw(sql, reportArticleId).Exec()
  193. if err != nil {
  194. return
  195. }
  196. //删除关联产业
  197. sql = ` DELETE FROM cygx_industrial_article_group_management WHERE cygx_article_id = ?`
  198. _, err = to.Raw(sql, reportArticleId).Exec()
  199. if err != nil {
  200. return
  201. }
  202. //删除关联标的
  203. sql = ` DELETE FROM cygx_industrial_article_group_subject WHERE cygx_article_id = ?`
  204. _, err = to.Raw(sql, reportArticleId).Exec()
  205. if err != nil {
  206. return
  207. }
  208. return
  209. }
  210. type CygxReportArticleItems struct {
  211. ReportId int `orm:"column(id);pk"description:"报告主键id"`
  212. ArticleId int `description:"文章ID"`
  213. IsFilter int `description:"是否过滤"`
  214. IsClass int `description:"是否归类"`
  215. ReportType int `description:"报告类型,1行业报告,2产业报告"`
  216. Title string `description:"标题"`
  217. PublishDate string `description:"发布时间"`
  218. Abstract string `description:"摘要"`
  219. }
  220. func GetReportArticleId(reportArticleId int) (items *CygxReportArticleItems, err error) {
  221. o := orm.NewOrm()
  222. sql := ` SELECT * FROM cygx_article WHERE id=? `
  223. err = o.Raw(sql, reportArticleId).QueryRow(&items)
  224. return
  225. }
  226. // 报告分类第一次添加
  227. func ReportArticleClassificationAdd(reportId, industrialManagementId, articleId int, ndustrialSubjectIdStr string) (err error) {
  228. o := orm.NewOrm()
  229. to, err := o.Begin()
  230. if err != nil {
  231. return
  232. }
  233. defer func() {
  234. if err != nil {
  235. _ = to.Rollback()
  236. } else {
  237. _ = to.Commit()
  238. }
  239. }()
  240. //修改文章是否归类字段
  241. sql := `UPDATE cygx_article SET is_filter=0, is_class=1 WHERE id=? `
  242. _, err = to.Raw(sql, reportId).Exec()
  243. if err != nil {
  244. return
  245. }
  246. //添加文章关联标的
  247. if ndustrialSubjectIdStr != "" {
  248. strList := strings.Split(ndustrialSubjectIdStr, ",")
  249. for _, v := range strList {
  250. sql := `INSERT INTO cygx_industrial_article_group_subject ( cygx_article_id, article_id, industrial_subject_id, create_time ) VALUES ( ?, ?, ?, ? )`
  251. _, err = to.Raw(sql, reportId, articleId, v, time.Now()).Exec()
  252. if err != nil {
  253. return
  254. }
  255. }
  256. }
  257. //添加文章关联行业
  258. sql = ` INSERT INTO cygx_industrial_article_group_management ( cygx_article_id, article_id, industrial_management_id, create_time ) VALUES ( ?, ?, ?, ? )`
  259. _, err = to.Raw(sql, reportId, articleId, industrialManagementId, time.Now()).Exec()
  260. if err != nil {
  261. return
  262. }
  263. fmt.Println("新增关联")
  264. return
  265. }
  266. // 报告分类的新增与修改
  267. func ReportArticleClassificationEdit(reportId, industrialManagementId, articleId int, ndustrialSubjectIdStr string) (err error) {
  268. o := orm.NewOrm()
  269. to, err := o.Begin()
  270. if err != nil {
  271. return
  272. }
  273. defer func() {
  274. if err != nil {
  275. _ = to.Rollback()
  276. } else {
  277. _ = to.Commit()
  278. }
  279. }()
  280. //修改文章是否过滤字段
  281. //sql := `UPDATE cygx_article SET is_filter=0 WHERE id=? `
  282. sql := `UPDATE cygx_article SET is_filter=0, is_class=1 WHERE id=? `
  283. _, err = to.Raw(sql, reportId).Exec()
  284. if err != nil {
  285. return
  286. }
  287. //删除文章关联标的
  288. sql = ` DELETE FROM cygx_industrial_article_group_subject WHERE cygx_article_id = ?`
  289. _, err = to.Raw(sql, reportId).Exec()
  290. if err != nil {
  291. return
  292. }
  293. //添加文章关联标的
  294. if ndustrialSubjectIdStr != "" {
  295. strList := strings.Split(ndustrialSubjectIdStr, ",")
  296. for _, v := range strList {
  297. sql := `INSERT INTO cygx_industrial_article_group_subject ( cygx_article_id, article_id, industrial_subject_id, create_time ) VALUES ( ?, ?, ?, ? )`
  298. _, err = to.Raw(sql, reportId, articleId, v, time.Now()).Exec()
  299. if err != nil {
  300. return
  301. }
  302. }
  303. }
  304. //删除文章关联行业 (避免截断表时产生的脏数据,故不用update而是先删除再增加)
  305. sql = ` DELETE FROM cygx_industrial_article_group_management WHERE cygx_article_id = ?`
  306. _, err = to.Raw(sql, reportId).Exec()
  307. if err != nil {
  308. return
  309. }
  310. //添加文章关联行业
  311. sql = ` INSERT INTO cygx_industrial_article_group_management ( cygx_article_id, article_id, industrial_management_id, create_time ) VALUES ( ?, ?, ?, ? )`
  312. _, err = to.Raw(sql, reportId, articleId, industrialManagementId, time.Now()).Exec()
  313. if err != nil {
  314. return
  315. }
  316. fmt.Println("修改关联")
  317. return
  318. }
  319. type PermissionMappingCategoryRep struct {
  320. CategoryId int `description:"文章分类id"`
  321. }
  322. func GetPermissionMappingCategoryID() (item []*PermissionMappingCategoryRep, err error) {
  323. o := orm.NewOrm()
  324. sql := ` SELECT category_id FROM cygx_report_mapping WHERE report_type = 1 AND category_id not IN (67) GROUP BY category_id `
  325. _, err = o.Raw(sql).QueryRows(&item)
  326. return
  327. }
  328. // 报告分类的新增与修改
  329. func ReportArticleClassificationEditNew(reportId int, industrialManagementIdStr string, articleId int, ndustrialSubjectIdStr string) (err error) {
  330. o := orm.NewOrm()
  331. to, err := o.Begin()
  332. if err != nil {
  333. return
  334. }
  335. defer func() {
  336. if err != nil {
  337. _ = to.Rollback()
  338. } else {
  339. _ = to.Commit()
  340. }
  341. }()
  342. //修改文章是否过滤字段
  343. //sql := `UPDATE cygx_article SET is_filter=0 WHERE id=? `
  344. sql := `UPDATE cygx_article SET is_filter=0, is_class=1 WHERE id=? `
  345. _, err = to.Raw(sql, reportId).Exec()
  346. if err != nil {
  347. return
  348. }
  349. //删除文章关联标的
  350. sql = ` DELETE FROM cygx_industrial_article_group_subject WHERE cygx_article_id = ?`
  351. _, err = to.Raw(sql, reportId).Exec()
  352. if err != nil {
  353. return
  354. }
  355. //添加文章关联标的
  356. if ndustrialSubjectIdStr != "0" && ndustrialSubjectIdStr != "" {
  357. strList := strings.Split(ndustrialSubjectIdStr, ",")
  358. for _, v := range strList {
  359. sql := `INSERT INTO cygx_industrial_article_group_subject ( cygx_article_id, article_id, industrial_subject_id, create_time ) VALUES ( ?, ?, ?, ? )`
  360. _, err = to.Raw(sql, reportId, articleId, v, time.Now()).Exec()
  361. if err != nil {
  362. return
  363. }
  364. }
  365. }
  366. //删除文章关联行业 (避免截断表时产生的脏数据,故不用update而是先删除再增加)
  367. sql = ` DELETE FROM cygx_industrial_article_group_management WHERE cygx_article_id = ?`
  368. _, err = to.Raw(sql, reportId).Exec()
  369. if err != nil {
  370. return
  371. }
  372. //添加文章关联行业
  373. industrialStrList := strings.Split(industrialManagementIdStr, ",")
  374. for _, v := range industrialStrList {
  375. sql = ` INSERT INTO cygx_industrial_article_group_management ( cygx_article_id, article_id, industrial_management_id, create_time ) VALUES ( ?, ?, ?, ? )`
  376. _, err = to.Raw(sql, reportId, articleId, v, time.Now()).Exec()
  377. if err != nil {
  378. return
  379. }
  380. }
  381. return
  382. }
  383. // 报告阅读明细下载
  384. type ReportExportRep struct {
  385. Id string `description:"客户姓名"`
  386. RealName string `description:"客户姓名"`
  387. CompanyName string `description:"公司名称"`
  388. CreateTime string `description:"阅读时间"`
  389. SellerName string `description:"销售名称"`
  390. StopTime string `停留时间:"停留时间"`
  391. }
  392. func GetReportExportRep(article_id int, sqlStr string) (item []*ReportExportRep, err error) {
  393. o := orm.NewOrm()
  394. sql := ` SELECT h.create_time,h.company_name,h.stop_time,u.real_name , p.seller_name,h.id
  395. FROM
  396. cygx_article_history_record_newpv AS h
  397. LEFT JOIN wx_user AS u ON u.user_id = h.user_id
  398. LEFT JOIN cygx_article AS art ON art.article_id = h.article_id
  399. LEFT JOIN company_product AS p ON p.company_id = u.company_id
  400. WHERE art.id = ?` + sqlStr
  401. fmt.Println(sql)
  402. _, err = o.Raw(sql, article_id).QueryRows(&item)
  403. return
  404. }
  405. // 报告关联的匹配类型
  406. type ReportMatchTypeName struct {
  407. MatchID string `orm:"column(id);"description:"匹配ID"`
  408. MatchTypeName string `description:"匹配类型"`
  409. }
  410. type ReportMatchTypeNameList struct {
  411. List []*ReportMatchTypeName
  412. }
  413. func GetMatchTypeName(categoryId int) (items []*ReportMatchTypeName, err error) {
  414. o := orm.NewOrm()
  415. sql := `SELECT * FROM cygx_report_mapping
  416. WHERE
  417. chart_permission_id = (
  418. SELECT
  419. chart_permission_id
  420. FROM
  421. cygx_report_mapping
  422. WHERE
  423. category_id = ? LIMIT 1
  424. )
  425. AND match_type_name <>''
  426. GROUP BY match_type_name
  427. ORDER BY id ASC `
  428. _, err = o.Raw(sql, categoryId).QueryRows(&items)
  429. return
  430. }
  431. type ArticleDetail struct {
  432. ArticleId int `description:"报告id"`
  433. Title string `description:"标题"`
  434. TitleEn string `description:"英文标题 "`
  435. UpdateFrequency string `description:"更新周期"`
  436. CreateDate string `description:"创建时间"`
  437. PublishDate string `description:"发布时间"`
  438. Body string `description:"内容"`
  439. Abstract string `description:"摘要"`
  440. CategoryName string `description:"一级分类"`
  441. SubCategoryName string `description:"二级分类"`
  442. MatchTypeName string `description:"匹配类型"`
  443. IsCollect bool `description:"是否收藏:true,已收藏,false:未收藏"`
  444. IsInterviewApply bool `description:"是否申请访谈:true,已申请,false:未申请"`
  445. BodyText string `description:"内容"`
  446. InterviewApplyStatus string `description:"当前访谈申请状态:'待邀请','待访谈','已完成','已取消'"`
  447. InterviewDate string `description:"访谈时间"`
  448. ExpertBackground string `description:"专家背景"`
  449. ExpertNumber string `description:"专家编号"`
  450. Department string `description:"作者"`
  451. ArticleIdMd5 string `description:"纪要id"`
  452. IsClass int `description:"是否归类,1是,0否"`
  453. IsSummary int `description:"是否是纪要库,1是,0否"`
  454. CategoryId int `description:"分类ID"`
  455. FileLink string `description:"下载预览链接"`
  456. ReportType int `description:"报告类型,2产业报告,1行业报告"`
  457. TypeName string `description:"策略平台类型字段名称"`
  458. ArticleTypeId int `description:"文章类型ID"`
  459. ArticleTypeName string `description:"文章类型名称"`
  460. }
  461. func GetArticleDetailById(articleId int) (item *ArticleDetail, err error) {
  462. o := orm.NewOrm()
  463. sql := `SELECT * FROM cygx_article WHERE id = ? `
  464. err = o.Raw(sql, articleId).QueryRow(&item)
  465. return
  466. }
  467. func GetArticleDetailByArticleId(articleId int) (item *ArticleDetail, err error) {
  468. o := orm.NewOrm()
  469. sql := `SELECT * FROM cygx_article WHERE article_id = ? `
  470. err = o.Raw(sql, articleId).QueryRow(&item)
  471. return
  472. }
  473. // 修改报告匹配类型
  474. type UpdateReportMatchTypeNameRep struct {
  475. MatchID int `orm:"column(id);"description:"匹配ID"`
  476. ReportId int `description:"报告id"`
  477. }
  478. // 手动修改匹配类型
  479. func UpdateReportMatchTypeName(matchTypeName string, reportType, categoryId, reportId, isSummary, isClass int) (err error) {
  480. o := orm.NewOrm()
  481. to, err := o.Begin()
  482. if err != nil {
  483. return
  484. }
  485. defer func() {
  486. if err != nil {
  487. fmt.Println(err)
  488. _ = to.Rollback()
  489. } else {
  490. _ = to.Commit()
  491. }
  492. }()
  493. sql := ""
  494. //fmt.Println(sql)
  495. if isSummary == 0 {
  496. //删除关联产业
  497. sql = ` DELETE FROM cygx_industrial_article_group_management WHERE cygx_article_id = ?`
  498. _, err = to.Raw(sql, reportId).Exec()
  499. if err != nil {
  500. return
  501. }
  502. //删除关联标的
  503. sql = ` DELETE FROM cygx_industrial_article_group_subject WHERE cygx_article_id = ?`
  504. _, err = to.Raw(sql, reportId).Exec()
  505. if err != nil {
  506. return
  507. }
  508. }
  509. //修改文章是否过滤字段
  510. if reportType == 1 {
  511. sql = `UPDATE cygx_article SET match_type_name=?, report_type=? ,category_id=?, is_class = 1, is_custom = 1 WHERE id=? `
  512. } else {
  513. sql = `UPDATE cygx_article SET match_type_name=?, report_type=? ,category_id=?, is_class = 0, is_custom = 1 WHERE id=? `
  514. }
  515. if isSummary == 1 && isClass == 1 {
  516. sql = `UPDATE cygx_article SET match_type_name=?, report_type=? ,category_id=?, is_class = 1, is_custom = 1 WHERE id=? `
  517. }
  518. _, err = to.Raw(sql, matchTypeName, reportType, categoryId, reportId).Exec()
  519. return
  520. }
  521. func GetArticleDetailByMd5Id(md5Id string) (item *ArticleDetail, err error) {
  522. o := orm.NewOrm()
  523. sql := `SELECT *FROM cygx_article WHERE article_id_md5 = ? `
  524. err = o.Raw(sql, md5Id).QueryRow(&item)
  525. return
  526. }
  527. type ReportAddRep struct {
  528. ArticleId int `description:"报告id"`
  529. Title string `description:"标题"`
  530. Abstract string `description:"摘要"`
  531. Body string `description:"内容"`
  532. DoType int `description:"操作类型 0,保存 、1,发布"`
  533. SellerAndMobile string `description:"作者"`
  534. ChartPermissionId int `description:"行业id"`
  535. IndustrialManagementIds string `description:"产业id 多个用 , 隔开"`
  536. IndustrialSubjectIds string `description:"标的id 多个用 , 隔开"`
  537. PublishDate string `description:"发布时间 列如 2020-03-23"`
  538. }
  539. // 添加报告文章
  540. func AddAReportrticle(item *CygxArticle, chartPermissionId int, industryName, subjectName string, itemDepartment *CygxArticleDepartment, industrialManagementIds, industrialSubjectIds string) (newId int64, err error) {
  541. var newDepartmentId int64
  542. var total int
  543. itemIndustrialManagementGroup := new(CygxIndustrialArticleGroupManagement)
  544. itemIndustrialSubjectGroup := new(CygxIndustrialArticleGroupSubject)
  545. o := orm.NewOrm()
  546. to, err := o.Begin()
  547. if err != nil {
  548. return
  549. }
  550. defer func() {
  551. if err != nil {
  552. _ = to.Rollback()
  553. } else {
  554. _ = to.Commit()
  555. }
  556. }()
  557. if itemDepartment.NickName != "" {
  558. //判断作者是否存在,如果没有则新增
  559. total, err = GetArticleDepartmentCount(itemDepartment.NickName, itemDepartment.Remarks)
  560. if err != nil {
  561. return
  562. }
  563. if total == 0 {
  564. newDepartmentId, err = to.Insert(itemDepartment)
  565. if err != nil {
  566. return
  567. }
  568. } else {
  569. departmentDetail := new(CygxArticleDepartmentRep)
  570. departmentDetail, err = GetArticleDepartmentDateil(itemDepartment.NickName, itemDepartment.Remarks)
  571. if err != nil {
  572. return
  573. }
  574. newDepartmentId = int64(departmentDetail.DepartmentId)
  575. }
  576. item.DepartmentId = int(newDepartmentId)
  577. }
  578. newId, err = to.Insert(item) // 新增文章
  579. if err != nil {
  580. return
  581. }
  582. //添加产业与文章的关联
  583. industrialManagementIdList := strings.Split(industrialManagementIds, ",")
  584. for _, v := range industrialManagementIdList {
  585. newIndustrialId, _ := strconv.Atoi(v)
  586. itemIndustrialManagementGroup.CreateTime = time.Now()
  587. itemIndustrialManagementGroup.CygxArticleId = int(newId)
  588. itemIndustrialManagementGroup.ArticleId = item.ArticleId
  589. itemIndustrialManagementGroup.IndustrialManagementId = newIndustrialId
  590. _, err = AddCygxIndustrialArticleGroupManagement(itemIndustrialManagementGroup)
  591. if err != nil {
  592. return
  593. }
  594. }
  595. //添加标的与文章的关联
  596. if industrialSubjectIds != "" {
  597. industrialSubjectIdList := strings.Split(industrialSubjectIds, ",")
  598. for _, v := range industrialSubjectIdList {
  599. industrialSubjectId, _ := strconv.Atoi(v)
  600. itemIndustrialSubjectGroup.CygxArticleId = int(newId)
  601. itemIndustrialSubjectGroup.ArticleId = item.ArticleId
  602. itemIndustrialSubjectGroup.IndustrialSubjectId = industrialSubjectId
  603. itemIndustrialSubjectGroup.CreateTime = time.Now()
  604. _, err = AddCygxIndustrialArticleGroupSubject(itemIndustrialSubjectGroup)
  605. if err != nil {
  606. return
  607. }
  608. }
  609. }
  610. return
  611. }
  612. // 修改报告文章
  613. func EditReportrticle(item *CygxArticle, chartPermissionId int, industryName, subjectName string, oldPublishStatus int, itemDepartment *CygxArticleDepartment, industrialManagementIds, industrialSubjectIds string) (err error) {
  614. var sql string
  615. var newDepartmentId int64
  616. var total int
  617. newId := item.SummaryManageId
  618. itemIndustrialManagementGroup := new(CygxIndustrialArticleGroupManagement)
  619. itemIndustrialSubjectGroup := new(CygxIndustrialArticleGroupSubject)
  620. o := orm.NewOrm()
  621. to, err := o.Begin()
  622. if err != nil {
  623. return
  624. }
  625. defer func() {
  626. if err != nil {
  627. _ = to.Rollback()
  628. } else {
  629. _ = to.Commit()
  630. }
  631. }()
  632. if itemDepartment.NickName != "" {
  633. //判断作者是否存在,如果没有则新增
  634. total, err = GetArticleDepartmentCount(itemDepartment.NickName, itemDepartment.Remarks)
  635. if err != nil {
  636. return
  637. }
  638. if total == 0 {
  639. newDepartmentId, err = to.Insert(itemDepartment)
  640. if err != nil {
  641. return
  642. }
  643. } else {
  644. departmentDetail := new(CygxArticleDepartmentRep)
  645. departmentDetail, err = GetArticleDepartmentDateil(itemDepartment.NickName, itemDepartment.Remarks)
  646. if err != nil {
  647. return
  648. }
  649. newDepartmentId = int64(departmentDetail.DepartmentId)
  650. }
  651. item.DepartmentId = int(newDepartmentId)
  652. }
  653. sql = ` UPDATE cygx_article SET
  654. category_name=?,
  655. title=?,
  656. abstract=?,
  657. body=?,
  658. body_text=?,
  659. publish_status=?,
  660. last_updated_time = ?,
  661. seller_and_mobile=?,
  662. expert_background =?,
  663. expert_number=? ,
  664. interview_date=?,
  665. file_link=? ,
  666. chart_permission_ids =?,
  667. article_type_id =?,
  668. article_type_name =?,
  669. admin_id =?,
  670. admin_name =?,
  671. is_summary =?,
  672. is_report =?,
  673. department_id =?,
  674. publish_date =?,
  675. report_link =?
  676. WHERE article_id =?`
  677. _, err = to.Raw(sql, item.CategoryName, item.Title, item.Abstract, item.Body, item.BodyText, item.PublishStatus, item.LastUpdatedTime, item.SellerAndMobile, item.ExpertBackground, item.ExpertNumber, item.InterviewDate, item.FileLink, item.ChartPermissionIds, item.ArticleTypeId, item.ArticleTypeName, item.AdminId, item.AdminName, item.IsSummary, item.IsReport, item.DepartmentId, item.PublishDate, item.ReportLink, item.ArticleId).Exec()
  678. if err != nil {
  679. return
  680. }
  681. //删除文章关联行业 (避免截断表时产生的脏数据,故不用update而是先删除再增加)
  682. sql = ` DELETE FROM cygx_industrial_article_group_management WHERE article_id = ?`
  683. _, err = to.Raw(sql, item.ArticleId).Exec()
  684. if err != nil {
  685. return
  686. }
  687. //删除文章关联标的
  688. sql = ` DELETE FROM cygx_industrial_article_group_subject WHERE article_id = ?`
  689. _, err = to.Raw(sql, item.ArticleId).Exec()
  690. if err != nil {
  691. return
  692. }
  693. //添加产业与文章的关联
  694. industrialManagementIdList := strings.Split(industrialManagementIds, ",")
  695. for _, v := range industrialManagementIdList {
  696. newIndustrialId, _ := strconv.Atoi(v)
  697. itemIndustrialManagementGroup.CreateTime = time.Now()
  698. itemIndustrialManagementGroup.CygxArticleId = int(newId)
  699. itemIndustrialManagementGroup.ArticleId = item.ArticleId
  700. itemIndustrialManagementGroup.IndustrialManagementId = newIndustrialId
  701. _, err = AddCygxIndustrialArticleGroupManagement(itemIndustrialManagementGroup)
  702. if err != nil {
  703. return
  704. }
  705. }
  706. //添加标的与文章的关联
  707. if industrialSubjectIds != "" {
  708. industrialSubjectIdList := strings.Split(industrialSubjectIds, ",")
  709. for _, v := range industrialSubjectIdList {
  710. industrialSubjectId, _ := strconv.Atoi(v)
  711. itemIndustrialSubjectGroup.CygxArticleId = int(newId)
  712. itemIndustrialSubjectGroup.ArticleId = item.ArticleId
  713. itemIndustrialSubjectGroup.IndustrialSubjectId = industrialSubjectId
  714. itemIndustrialSubjectGroup.CreateTime = time.Now()
  715. _, err = AddCygxIndustrialArticleGroupSubject(itemIndustrialSubjectGroup)
  716. if err != nil {
  717. return
  718. }
  719. }
  720. }
  721. return
  722. }
  723. type CygxArticleReport struct {
  724. ArticleId int `description:"文章ID"`
  725. Title string `description:"标题"`
  726. Abstract string `description:"摘要"`
  727. Body string `description:"内容"`
  728. PublishStatus int `description:"发布状态,0未发布 ,1已发布"`
  729. PublishDate string `description:"发布时间"`
  730. CreateDate time.Time `description:"创建时间"`
  731. LastUpdatedTime time.Time `description:"更新时间"`
  732. ArticleIdMd5 string `description:"ID,md5值"`
  733. SellerAndMobile string `description:"作者(姓名与手机号)"`
  734. SubjectName string `description:"标的名称"`
  735. IndustryName string `description:"产业名称"`
  736. DepartmentId int `description:"作者id"`
  737. ChartPermissionIds string `description:"行业ID ,多个用 , 隔开"`
  738. ArticleTypeId int `description:"文章类型ID"`
  739. ArticleTypeName string `description:"文章类型名称"`
  740. ReportLink string `description:"报告链接"`
  741. ChartPermissionId int `description:"行业id"`
  742. ListIndustrial []*IndustrialActivityGroupManagementRep
  743. ListSubject []*SubjectActivityGroupManagementRep
  744. }
  745. // 通过纪要ID获取文章详情
  746. func GetArticleIdInfoByreportIdEdit(articleId int) (item *CygxArticleReport, err error) {
  747. o := orm.NewOrm()
  748. sql := `SELECT
  749. a.* ,m.industry_name,
  750. GROUP_CONCAT(DISTINCT s.subject_name SEPARATOR ',') AS subject_name
  751. FROM
  752. cygx_article as a
  753. INNER JOIN cygx_industrial_article_group_management as mg ON mg.cygx_article_id = a.id
  754. INNER JOIN cygx_industrial_management as m ON m.industrial_management_id = mg.industrial_management_id
  755. LEFT JOIN cygx_industrial_article_group_subject as sg ON sg.cygx_article_id = a.id
  756. LEFT JOIN cygx_industrial_subject as s ON s.industrial_subject_id = sg.industrial_subject_id
  757. WHERE
  758. a.article_id = ?`
  759. err = o.Raw(sql, articleId).QueryRow(&item)
  760. return
  761. }
  762. // 修改文章关联的标的ID
  763. func UpdateSubjecIds(subjecIds string, industrialManagementId, articleId int) (err error) {
  764. o := orm.NewOrm()
  765. var industrialAndSubjectIds string
  766. industrialAndSubjectIds = strings.Replace(strings.Replace(subjecIds, "{|1|}", "", -1), "{|2|}", "", -1)
  767. fmt.Println(industrialAndSubjectIds)
  768. sql := `UPDATE cygx_article SET subject_ids=? ,industrial_management_id =?, industrial_and_subject_ids = ? WHERE article_id = ?`
  769. _, err = o.Raw(sql, subjecIds, industrialManagementId, industrialAndSubjectIds, articleId).Exec()
  770. return
  771. }
  772. // 删除研选报告,以及相关归类,收藏
  773. func DeleteArticleReport(articleId int) (err error) {
  774. o := orm.NewOrm()
  775. to, err := o.Begin()
  776. if err != nil {
  777. return
  778. }
  779. defer func() {
  780. if err != nil {
  781. fmt.Println(err)
  782. _ = to.Rollback()
  783. } else {
  784. _ = to.Commit()
  785. }
  786. }()
  787. sql := ""
  788. //删除关联产业
  789. sql = ` DELETE FROM cygx_industrial_article_group_management WHERE article_id = ?`
  790. _, err = to.Raw(sql, articleId).Exec()
  791. if err != nil {
  792. return
  793. }
  794. //删除关联标的
  795. sql = ` DELETE FROM cygx_industrial_article_group_subject WHERE article_id = ?`
  796. _, err = to.Raw(sql, articleId).Exec()
  797. if err != nil {
  798. return
  799. }
  800. //删除关联收藏
  801. sql = ` DELETE FROM cygx_article_collect WHERE article_id = ?`
  802. _, err = to.Raw(sql, articleId).Exec()
  803. if err != nil {
  804. return
  805. }
  806. //删除阅读记录
  807. sql = ` DELETE FROM cygx_article_history_record WHERE article_id = ?`
  808. _, err = to.Raw(sql, articleId).Exec()
  809. if err != nil {
  810. return
  811. }
  812. //删除阅读记录
  813. sql = ` DELETE FROM cygx_article_history_record_newpv WHERE article_id = ?`
  814. _, err = to.Raw(sql, articleId).Exec()
  815. if err != nil {
  816. return
  817. }
  818. //删除报告
  819. sql = ` DELETE FROM cygx_article WHERE article_id = ?`
  820. _, err = to.Raw(sql, articleId).Exec()
  821. return
  822. }
  823. type AddArticleRoadshowEssenceRep struct {
  824. ArticleId int `description:"文章ID 0 新增,大于0 修改"`
  825. Title string `description:"标题"`
  826. SellerAndMobile string `description:"作者(姓名与手机号)"`
  827. PublishDate string `description:"发布时间"`
  828. ChartPermissionId int `description:"行业ID"`
  829. IndustrialManagementId string `description:"产业id,多个用 , 英文逗号隔开"`
  830. IndustrialSubjectIdStr string `description:"标的id多个用 , 英文逗号隔开"`
  831. Abstract string `description:"摘要"`
  832. Body string `description:"内容"`
  833. ReportLink string `description:"报告链接"`
  834. DoType int `description:"操作方式,1发布,0保存"`
  835. }
  836. // 添加报告文章
  837. func AddArticleRoadshowEssence(item *CygxArticle, industryIds, subjectIds string) (newId int64, err error) {
  838. itemIndustrialManagementGroup := new(CygxIndustrialArticleGroupManagement)
  839. itemIndustrialSubjectGroup := new(CygxIndustrialArticleGroupSubject)
  840. o := orm.NewOrm()
  841. to, err := o.Begin()
  842. if err != nil {
  843. return
  844. }
  845. defer func() {
  846. if err != nil {
  847. _ = to.Rollback()
  848. } else {
  849. _ = to.Commit()
  850. }
  851. }()
  852. newId, err = to.Insert(item) // 新增文章
  853. if err != nil {
  854. return
  855. }
  856. //添加产业与文章的关联
  857. industrialStrList := strings.Split(industryIds, ",")
  858. for _, v := range industrialStrList {
  859. itemIndustrialManagementGroup.CreateTime = time.Now()
  860. itemIndustrialManagementGroup.CygxArticleId = int(newId)
  861. itemIndustrialManagementGroup.ArticleId = item.ArticleId
  862. industryId, _ := strconv.Atoi(v)
  863. itemIndustrialManagementGroup.IndustrialManagementId = industryId
  864. _, err = AddCygxIndustrialArticleGroupManagement(itemIndustrialManagementGroup)
  865. if err != nil {
  866. return
  867. }
  868. }
  869. //添加标的与文章的关联
  870. if subjectIds != "" {
  871. slice := strings.Split(subjectIds, ",") //标的处理、添加标的与产业的关联、标的与文章的关联
  872. for _, v := range slice {
  873. itemIndustrialSubjectGroup.CygxArticleId = int(newId)
  874. itemIndustrialSubjectGroup.ArticleId = item.ArticleId
  875. subjectId, _ := strconv.Atoi(v)
  876. itemIndustrialSubjectGroup.IndustrialSubjectId = subjectId
  877. itemIndustrialSubjectGroup.CreateTime = time.Now()
  878. _, err = AddCygxIndustrialArticleGroupSubject(itemIndustrialSubjectGroup)
  879. if err != nil {
  880. return
  881. }
  882. }
  883. }
  884. return
  885. }
  886. // 修改报告文章
  887. func UpdateArticleRoadshowEssence(item *CygxArticle, industryIds, subjectIds string) (err error) {
  888. itemIndustrialManagementGroup := new(CygxIndustrialArticleGroupManagement)
  889. itemIndustrialSubjectGroup := new(CygxIndustrialArticleGroupSubject)
  890. o := orm.NewOrm()
  891. to, err := o.Begin()
  892. if err != nil {
  893. return
  894. }
  895. defer func() {
  896. if err != nil {
  897. _ = to.Rollback()
  898. } else {
  899. _ = to.Commit()
  900. }
  901. }()
  902. newId := item.SummaryManageId
  903. sql := `UPDATE cygx_article SET title=? ,seller_and_mobile =?, chart_permission_ids = ?, abstract = ?, body = ?, body_text = ?, report_link = ? ,have_publish = ? ,publish_status = ? ,periods = ? ,link_article_id = ?,publish_date = ?, category_id = ? ,admin_id =? ,admin_name =? WHERE article_id = ?`
  904. _, err = to.Raw(sql, item.Title, item.SellerAndMobile, item.ChartPermissionIds, item.Abstract, item.Body, item.BodyText, item.ReportLink, item.HavePublish, item.PublishStatus, item.Periods, item.LinkArticleId, item.PublishDate, item.CategoryId, item.AdminId, item.AdminName, item.ArticleId).Exec()
  905. if err != nil {
  906. return
  907. }
  908. //删除文章关联行业 (避免截断表时产生的脏数据,故不用update而是先删除再增加)
  909. sql = ` DELETE FROM cygx_industrial_article_group_management WHERE article_id = ?`
  910. _, err = to.Raw(sql, item.ArticleId).Exec()
  911. if err != nil {
  912. return
  913. }
  914. //删除文章关联标的
  915. sql = ` DELETE FROM cygx_industrial_article_group_subject WHERE article_id = ?`
  916. _, err = to.Raw(sql, item.ArticleId).Exec()
  917. if err != nil {
  918. return
  919. }
  920. //添加产业与文章的关联
  921. industrialStrList := strings.Split(industryIds, ",")
  922. for _, v := range industrialStrList {
  923. itemIndustrialManagementGroup.CreateTime = time.Now()
  924. itemIndustrialManagementGroup.CygxArticleId = int(newId)
  925. itemIndustrialManagementGroup.ArticleId = item.ArticleId
  926. industryId, _ := strconv.Atoi(v)
  927. itemIndustrialManagementGroup.IndustrialManagementId = industryId
  928. _, err = AddCygxIndustrialArticleGroupManagement(itemIndustrialManagementGroup)
  929. if err != nil {
  930. return
  931. }
  932. }
  933. //添加标的与文章的关联
  934. if subjectIds != "" {
  935. slice := strings.Split(subjectIds, ",") //标的处理、添加标的与产业的关联、标的与文章的关联
  936. for _, v := range slice {
  937. itemIndustrialSubjectGroup.CygxArticleId = int(newId)
  938. itemIndustrialSubjectGroup.ArticleId = item.ArticleId
  939. subjectId, _ := strconv.Atoi(v)
  940. itemIndustrialSubjectGroup.IndustrialSubjectId = subjectId
  941. itemIndustrialSubjectGroup.CreateTime = time.Now()
  942. _, err = AddCygxIndustrialArticleGroupSubject(itemIndustrialSubjectGroup)
  943. if err != nil {
  944. return
  945. }
  946. }
  947. }
  948. return
  949. }
  950. type ArticleRoadshowEssenceDetail struct {
  951. ArticleId int `description:"文章ID"`
  952. Title string `description:"标题"`
  953. SellerAndMobile string `description:"作者(姓名与手机号)"`
  954. PublishDate string `description:"发布时间"`
  955. ChartPermissionId int `orm:"column(chart_permission_ids);"description:"行业ID"`
  956. PermissionName string `orm:"column(category_name);"description:"行业名称"`
  957. IndustrialManagementId string `description:"产业id,多个用 , 英文逗号隔开"`
  958. IndustryName string `description:"产业名称"`
  959. IndustrialSubjectIdStr string `description:"标的id多个用 , 英文逗号隔开"`
  960. SubjectName string `description:"标的名称"`
  961. Abstract string `description:"摘要"`
  962. Body string `description:"内容"`
  963. ReportLink string `description:"报告链接"`
  964. PublishStatus int `description:"发布状态,0未发布 ,1已发布"`
  965. }
  966. // 文章详情
  967. func GetArticleRoadshowEssenceDetail(articleId int) (item *ArticleRoadshowEssenceDetail, err error) {
  968. o := orm.NewOrm()
  969. sql := `SELECT
  970. art.* ,
  971. GROUP_CONCAT( DISTINCT mg.industrial_management_id SEPARATOR ',' ) AS industrial_management_id ,
  972. GROUP_CONCAT( DISTINCT m.industry_name SEPARATOR ',' ) AS industry_name,
  973. GROUP_CONCAT( DISTINCT sg.industrial_subject_id SEPARATOR ',' ) AS industrial_subject_id_str ,
  974. GROUP_CONCAT( DISTINCT s.subject_name SEPARATOR ',' ) AS subject_name
  975. FROM
  976. cygx_article as art
  977. LEFT JOIN cygx_industrial_article_group_management as mg ON mg.article_id = art.article_id
  978. LEFT JOIN cygx_industrial_management as m ON m.industrial_management_id = mg.industrial_management_id
  979. LEFT JOIN cygx_industrial_article_group_subject as sg ON sg.article_id = art.article_id
  980. LEFT JOIN cygx_industrial_subject as s ON s.industrial_subject_id = sg.industrial_subject_id
  981. WHERE
  982. art.article_id = ?`
  983. err = o.Raw(sql, articleId).QueryRow(&item)
  984. return
  985. }
  986. // 列表
  987. func GetArticleRoadshowEssenceList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxResearchSummaryRep, err error) {
  988. o := orm.NewOrm()
  989. sql := `SELECT *,
  990. (SELECT COUNT(1) FROM cygx_article_history_record AS h WHERE h.article_id=art.article_id) AS pv,
  991. (SELECT COUNT(DISTINCT user_id) FROM cygx_article_history_record AS h WHERE h.article_id=art.article_id) AS uv
  992. FROM cygx_article as art WHERE 1= 1 `
  993. if condition != "" {
  994. sql += condition
  995. }
  996. sql += ` LIMIT ?,?`
  997. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  998. return
  999. }
  1000. // 列表
  1001. func GetArticlList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxArticle, err error) {
  1002. o := orm.NewOrm()
  1003. sql := `SELECT *
  1004. FROM cygx_article as art WHERE 1= 1 `
  1005. if condition != "" {
  1006. sql += condition
  1007. }
  1008. sql += ` LIMIT ?,?`
  1009. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  1010. return
  1011. }
  1012. // GetArticleListByIdList 根据报告id列表获取报告列表
  1013. func GetArticleListByIdList(articleLIdList []int) (items []*CygxArticle, err error) {
  1014. num := len(articleLIdList)
  1015. if num <= 0 {
  1016. return
  1017. }
  1018. o := orm.NewOrm()
  1019. sql := `SELECT * FROM cygx_article as art WHERE 1= 1 AND article_id in (` + utils.GetOrmInReplace(num) + `)`
  1020. _, err = o.Raw(sql, articleLIdList).QueryRows(&items)
  1021. return
  1022. }
  1023. // RoadshowEssencePublishAndCancel 修改发布状态
  1024. func RoadshowEssencePublishAndCancel(item *CygxResearchSummaryRep) (err error) {
  1025. o := orm.NewOrm()
  1026. sql := `UPDATE cygx_article SET publish_status=? , last_updated_time= ?, periods= ?,admin_id =? ,admin_name =? ,have_publish = 1 WHERE article_id=? `
  1027. _, err = o.Raw(sql, item.PublishStatus, time.Now(), item.Periods, item.AdminId, item.AdminName, item.ArticleId).Exec()
  1028. return
  1029. }
  1030. ////获取数量
  1031. //func GetCygxArticleCountNew(condition string, pars []interface{}) (count int, err error) {
  1032. // sqlCount := ` SELECT COUNT(1) AS count FROM cygx_article as art WHERE 1= 1 `
  1033. // if condition != "" {
  1034. // sqlCount += condition
  1035. // }
  1036. // o := orm.NewOrm()
  1037. // err = o.Raw(sqlCount, pars).QueryRow(&count)
  1038. // return
  1039. //}
  1040. func UpdateArticleInfoVideo(reportId int, tbName, videoUrl, videoName, videoSize string, playSeconds float64) (err error) {
  1041. o := orm.NewOrm()
  1042. sql := `UPDATE ` + tbName + ` SET video_url=?,video_name=?,video_play_seconds=?,video_size=? WHERE article_id=? `
  1043. _, err = o.Raw(sql, videoUrl, videoName, playSeconds, videoSize, reportId).Exec()
  1044. return
  1045. }
  1046. // 客户其他行为数据导出 start
  1047. type CygxArticleCollect struct {
  1048. ArticleId int `description:"文章id"`
  1049. UserId int `description:"用户ID"`
  1050. Title string `description:"标题"`
  1051. CreateTime string `description:"创建时间"`
  1052. PublishDate string `description:"发布时间"`
  1053. PermissionName string `description:"行业"`
  1054. IndustryName string `description:"产业名称"`
  1055. SubjectName string `description:"关联标的"`
  1056. MatchTypeName string `description:"报告类型"`
  1057. CategoryId string `description:"分类ID"`
  1058. }
  1059. type CygxArticleIndustry struct {
  1060. UserId int `description:"用户ID"`
  1061. IndustrialManagementId int `description:"产业id"`
  1062. CreateTime string `description:"创建时间"`
  1063. IndustryName string `description:"产业名称"`
  1064. }
  1065. type ArticleDepartment struct {
  1066. DepartmentId int `description:"主键ID"`
  1067. NickName string `description:"昵称"`
  1068. UserId int `description:"用户ID"`
  1069. IndustrialManagementId int `description:"产业id"`
  1070. CreateTime string `description:"创建时间"`
  1071. IndustryName string `description:"产业名称"`
  1072. }
  1073. type KeyWord struct {
  1074. UserId int `description:"用户ID"`
  1075. CreateTime string `description:"创建时间"`
  1076. KeyWord string `description:"关键词"`
  1077. }
  1078. type CompanyOtherHistoryList struct {
  1079. Mobile string `description:"手机号"`
  1080. Email string `description:"邮箱"`
  1081. RealName string `description:"姓名"`
  1082. ListArticle []*CygxArticleCollect
  1083. ListIndustrial []*CygxArticleIndustry
  1084. ListDepartment []*ArticleDepartment
  1085. ListKeyWord []*KeyWord
  1086. }
  1087. type CompanyOtherHistoryListResp struct {
  1088. List []*CompanyOtherHistoryList
  1089. }
  1090. // 文章列表
  1091. func GetArticleCollectList(condition string) (items []*CygxArticleCollect, err error) {
  1092. o := orm.NewOrm()
  1093. sql := `SELECT
  1094. c.*,
  1095. a.title,
  1096. a.publish_date,
  1097. a.category_id,
  1098. a.match_type_name,
  1099. (SELECT
  1100. GROUP_CONCAT( DISTINCT m.industry_name SEPARATOR ',' ) AS industry_name
  1101. FROM
  1102. cygx_industrial_management AS m
  1103. WHERE
  1104. industrial_management_id IN ( SELECT industrial_management_id FROM cygx_industrial_article_group_management AS mg WHERE mg.article_id = c.article_id )) AS industry_name,
  1105. (SELECT
  1106. GROUP_CONCAT( DISTINCT s.subject_name SEPARATOR ',' ) AS subject_name
  1107. FROM
  1108. cygx_industrial_subject AS s
  1109. WHERE
  1110. industrial_subject_id IN ( SELECT industrial_subject_id FROM cygx_industrial_article_group_subject AS sg WHERE sg.article_id = c.article_id )) AS subject_name
  1111. FROM
  1112. cygx_article_collect AS c
  1113. INNER JOIN cygx_article AS a ON a.article_id = c.article_id
  1114. WHERE 1=1`
  1115. if condition != "" {
  1116. sql += condition
  1117. }
  1118. _, err = o.Raw(sql).QueryRows(&items)
  1119. return
  1120. }
  1121. // 产业列表
  1122. func GetCygxIndustryList(companyId int) (items []*CygxArticleIndustry, err error) {
  1123. o := orm.NewOrm()
  1124. sql := `SELECT
  1125. f.user_id,f.create_time,m.industrial_management_id,m.industry_name
  1126. FROM
  1127. cygx_industry_fllow AS f
  1128. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = f.industrial_management_id
  1129. WHERE
  1130. 1 = 1
  1131. AND f.company_id = ?`
  1132. _, err = o.Raw(sql, companyId).QueryRows(&items)
  1133. return
  1134. }
  1135. // 作者列表
  1136. func GetArticleDepartmentList(companyId int) (items []*ArticleDepartment, err error) {
  1137. o := orm.NewOrm()
  1138. sql := `SELECT
  1139. f.user_id,f.create_time,m.department_id,m.nick_name,
  1140. (SELECT
  1141. GROUP_CONCAT( DISTINCT m.industry_name SEPARATOR ',' ) AS industry_name
  1142. FROM
  1143. cygx_industrial_management AS m
  1144. WHERE
  1145. industrial_management_id IN ( SELECT industrial_management_id FROM cygx_industrial_article_group_management AS mg WHERE mg.article_id IN(SELECT article_id FROM cygx_article WHERE department_id = f.department_id) )) AS industry_name
  1146. FROM
  1147. cygx_article_department_follow AS f
  1148. INNER JOIN cygx_article_department AS m ON m.department_id = f.department_id
  1149. WHERE
  1150. 1 = 1
  1151. AND f.company_id = ?`
  1152. _, err = o.Raw(sql, companyId).QueryRows(&items)
  1153. return
  1154. }
  1155. // 关键词列表
  1156. func GetCygxSearchKeyWordList(userIdStr string) (items []*KeyWord, err error) {
  1157. o := orm.NewOrm()
  1158. sql := `SELECT * FROM cygx_search_key_word WHERE user_id IN (` + userIdStr + `)`
  1159. _, err = o.Raw(sql).QueryRows(&items)
  1160. return
  1161. }
  1162. // 关键词列表
  1163. func GetCygxUserSearchKeyWordList(userIdStr string) (items []*KeyWord, err error) {
  1164. o := orm.NewOrm()
  1165. sql := `SELECT * FROM cygx_user_search_key_word WHERE user_id IN (` + userIdStr + `) AND page_type IN ('ReortSearch','HomeSearch')`
  1166. _, err = o.Raw(sql).QueryRows(&items)
  1167. return
  1168. } //end
  1169. type CreateTimesResp struct {
  1170. CreateTimes string `description:"创建时间"`
  1171. }
  1172. type CompanyArticleCountResp struct {
  1173. CreateTimes string `description:"创建时间"`
  1174. ReadSum int `description:"总阅读数"`
  1175. YiyaoSum int `description:"医药阅读数"`
  1176. XiaofeiSum int `description:"医药阅读数"`
  1177. KejiSum int `description:"医药阅读数"`
  1178. ZhizaoSum int `description:"医药阅读数"`
  1179. CelueSum int `description:"医药阅读数"`
  1180. YanxuanSum int `description:"医药阅读数"`
  1181. }
  1182. type CompanyArticleCountListResp struct {
  1183. List []*CompanyArticleCountResp
  1184. }
  1185. func GetCompanyHistoryRecordPvGroupDate(mobiles, emails string) (item []*CreateTimesResp, err error) {
  1186. o := orm.NewOrm()
  1187. sql := ` SELECT date_format(create_time,'%Y-%m') as create_times FROM cygx_article_history_record_all AS h
  1188. INNER JOIN cygx_article art ON art.article_id = h.article_id
  1189. WHERE h.mobile IN (` + mobiles + `) AND h.is_del = 0 OR( h.email IN (` + emails + `) AND h.email <>'' AND h.is_del = 0 ) GROUP BY create_times ORDER BY create_times DESC `
  1190. _, err = o.Raw(sql).QueryRows(&item)
  1191. return
  1192. }
  1193. func GetCompanyHistoryRecordPv(mobiles, emails string) (item []*CompanyHistoryRecordNewPvRep, err error) {
  1194. o := orm.NewOrm()
  1195. sql := ` SELECT
  1196. a.title,
  1197. a.category_id,
  1198. date_format(h.create_time,'%Y-%m') as create_time,
  1199. m.chart_permission_name as permission_name
  1200. FROM
  1201. cygx_article_history_record_all AS h
  1202. INNER JOIN cygx_article AS a ON a.article_id = h.article_id
  1203. LEFT JOIN cygx_report_mapping AS m ON a.category_id = m.category_id
  1204. WHERE h.mobile IN (` + mobiles + `) AND h.is_del = 0 OR( h.email IN (` + emails + `) AND h.email <>'' AND h.is_del = 0 )
  1205. ORDER BY
  1206. h.create_time DESC `
  1207. _, err = o.Raw(sql).QueryRows(&item)
  1208. return
  1209. }
  1210. type CygxCelueArticleHistoryRecord struct {
  1211. Id int `orm:"column(id);pk"`
  1212. ArticleId int `description:"文章ID"`
  1213. CelueHistoryId int `description:"策略平台记录的ID"`
  1214. CreateTime string `description:"本地创建时间"`
  1215. CreateDateApi time.Time `description:"图表创建时间"`
  1216. Mobile string `description:"手机号"`
  1217. CompanyName string `description:"公司名称"`
  1218. RealName string `description:"用户姓名"`
  1219. }
  1220. func GetCygxCelueArticleHistoryRecordPvAll(articleIds string) (item []*ArticleHistoryRep, err error) {
  1221. o := orm.NewOrm()
  1222. sql := `SELECT * FROM cygx_article_history_record_all as h WHERE article_id IN ( ` + articleIds + ` ) AND h.is_del = 0 AND h.company_id != 16 AND h.platfor = 2 `
  1223. sql += ` ORDER BY create_time DESC `
  1224. _, err = o.Raw(sql).QueryRows(&item)
  1225. return
  1226. }
  1227. func GetCygxCelueArticleComapnyName(mobiles string) (item []*ArticleHistoryRep, err error) {
  1228. o := orm.NewOrm()
  1229. sql := `SELECT
  1230. c.company_name,a.real_name,u.mobile
  1231. FROM
  1232. wx_user AS u
  1233. INNER JOIN company as c ON c.company_id = u.company_id
  1234. INNER JOIN company_product as p ON p.company_id = c.company_id
  1235. INNER JOIN admin as a On a.admin_id = p.seller_id
  1236. WHERE p.product_id = 2
  1237. AND u.mobile IN ( ` + mobiles + `) GROUP BY u.mobile `
  1238. _, err = o.Raw(sql).QueryRows(&item)
  1239. return
  1240. }
  1241. type ArticleDetailResp struct {
  1242. ArticleId int `description:"文章ID"`
  1243. Title string `description:"标题"`
  1244. Abstract string `description:"摘要"`
  1245. Body string `description:"内容"`
  1246. PublishStatus int `description:"发布状态,0未发布 ,1已发布"`
  1247. PublishDate string `description:"发布时间"`
  1248. CreateDate time.Time `description:"创建时间"`
  1249. LastUpdatedTime time.Time `description:"更新时间"`
  1250. ArticleIdMd5 string `description:"ID,md5值"`
  1251. SellerAndMobile string `description:"作者(姓名与手机号)"`
  1252. SubjectName string `description:"标的名称"`
  1253. IndustryName string `description:"产业名称"`
  1254. DepartmentId int `description:"作者id"`
  1255. ChartPermissionIds string `description:"行业ID ,多个用 , 隔开"`
  1256. ArticleTypeId int `description:"文章类型ID"`
  1257. ArticleTypeName string `description:"文章类型名称"`
  1258. ListIndustrial []*IndustrialActivityGroupManagementRep
  1259. ListSubject []*SubjectActivityGroupManagementRep
  1260. ImgUrl string `description:"头像url"`
  1261. NickName string `description:"昵称"`
  1262. ReportLink string `description:"报告链接"`
  1263. }
  1264. // GetArticleIdsFromIndustryAndSubjectGroupByKeyword 产业/标的关键词获取文章IDs
  1265. func GetArticleIdsFromIndustryAndSubjectGroupByKeyword(keyword string) (ids []int, err error) {
  1266. sql := `SELECT DISTINCT
  1267. mg.article_id
  1268. FROM
  1269. cygx_industrial_article_group_management AS mg
  1270. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  1271. WHERE
  1272. 1 = 1
  1273. AND m.industry_name LIKE ?
  1274. UNION
  1275. SELECT DISTINCT
  1276. sg.article_id
  1277. FROM
  1278. cygx_industrial_article_group_subject AS sg
  1279. INNER JOIN cygx_industrial_subject AS s ON s.industrial_subject_id = sg.industrial_subject_id
  1280. WHERE
  1281. 1 = 1
  1282. AND s.subject_name LIKE ?`
  1283. _, err = orm.NewOrm().Raw(sql, keyword, keyword).QueryRows(&ids)
  1284. return
  1285. }
  1286. type SummaryArticleStock struct {
  1287. Id int `description:"新ID"`
  1288. ArticleId int `description:"文章id"`
  1289. Stock string `description:"个股标签"`
  1290. }
  1291. // 综述报告
  1292. func GetArticleStock() (items []*SummaryArticleStock, err error) {
  1293. o := orm.NewOrm()
  1294. sql := `SELECT
  1295. stock,article_id
  1296. FROM
  1297. cygx_article AS art
  1298. WHERE
  1299. 1 = 1
  1300. AND type_name = '综述报告' `
  1301. _, err = o.Raw(sql).QueryRows(&items)
  1302. return
  1303. }