report_article.go 50 KB

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