report_article.go 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381
  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. IsCollect bool `description:"是否收藏:true,已收藏,false:未收藏"`
  443. IsInterviewApply bool `description:"是否申请访谈:true,已申请,false:未申请"`
  444. BodyText string `description:"内容"`
  445. InterviewApplyStatus string `description:"当前访谈申请状态:'待邀请','待访谈','已完成','已取消'"`
  446. InterviewDate string `description:"访谈时间"`
  447. ExpertBackground string `description:"专家背景"`
  448. ExpertNumber string `description:"专家编号"`
  449. Department string `description:"作者"`
  450. ArticleIdMd5 string `description:"纪要id"`
  451. IsClass int `description:"是否归类,1是,0否"`
  452. IsSummary int `description:"是否是纪要库,1是,0否"`
  453. CategoryId int `description:"分类ID"`
  454. FileLink string `description:"下载预览链接"`
  455. ReportType int `description:"报告类型,2产业报告,1行业报告"`
  456. }
  457. func GetArticleDetailById(articleId int) (item *ArticleDetail, err error) {
  458. o := orm.NewOrm()
  459. sql := `SELECT * FROM cygx_article WHERE id = ? `
  460. err = o.Raw(sql, articleId).QueryRow(&item)
  461. return
  462. }
  463. // 修改报告匹配类型
  464. type UpdateReportMatchTypeNameRep struct {
  465. MatchID int `orm:"column(id);"description:"匹配ID"`
  466. ReportId int `description:"报告id"`
  467. }
  468. // 手动修改匹配类型
  469. func UpdateReportMatchTypeName(matchTypeName string, reportType, categoryId, reportId, isSummary, isClass int) (err error) {
  470. o := orm.NewOrm()
  471. to, err := o.Begin()
  472. if err != nil {
  473. return
  474. }
  475. defer func() {
  476. if err != nil {
  477. fmt.Println(err)
  478. _ = to.Rollback()
  479. } else {
  480. _ = to.Commit()
  481. }
  482. }()
  483. sql := ""
  484. //fmt.Println(sql)
  485. if isSummary == 0 {
  486. //删除关联产业
  487. sql = ` DELETE FROM cygx_industrial_article_group_management WHERE cygx_article_id = ?`
  488. _, err = to.Raw(sql, reportId).Exec()
  489. if err != nil {
  490. return
  491. }
  492. //删除关联标的
  493. sql = ` DELETE FROM cygx_industrial_article_group_subject WHERE cygx_article_id = ?`
  494. _, err = to.Raw(sql, reportId).Exec()
  495. if err != nil {
  496. return
  497. }
  498. }
  499. //修改文章是否过滤字段
  500. if reportType == 1 {
  501. sql = `UPDATE cygx_article SET match_type_name=?, report_type=? ,category_id=?, is_class = 1, is_custom = 1 WHERE id=? `
  502. } else {
  503. sql = `UPDATE cygx_article SET match_type_name=?, report_type=? ,category_id=?, is_class = 0, is_custom = 1 WHERE id=? `
  504. }
  505. if isSummary == 1 && isClass == 1 {
  506. sql = `UPDATE cygx_article SET match_type_name=?, report_type=? ,category_id=?, is_class = 1, is_custom = 1 WHERE id=? `
  507. }
  508. _, err = to.Raw(sql, matchTypeName, reportType, categoryId, reportId).Exec()
  509. return
  510. }
  511. func GetArticleDetailByMd5Id(md5Id string) (item *ArticleDetail, err error) {
  512. o := orm.NewOrm()
  513. sql := `SELECT *FROM cygx_article WHERE article_id_md5 = ? `
  514. err = o.Raw(sql, md5Id).QueryRow(&item)
  515. return
  516. }
  517. type ReportAddRep struct {
  518. ArticleId int `description:"报告id"`
  519. Title string `description:"标题"`
  520. Abstract string `description:"摘要"`
  521. Body string `description:"内容"`
  522. DoType int `description:"操作类型 0,保存 、1,发布"`
  523. SellerAndMobile string `description:"作者"`
  524. ChartPermissionId int `description:"行业id"`
  525. IndustrialManagementIds string `description:"产业id 多个用 , 隔开"`
  526. IndustrialSubjectIds string `description:"标的id 多个用 , 隔开"`
  527. PublishDate string `description:"发布时间 列如 2020-03-23"`
  528. }
  529. // 添加报告文章
  530. func AddAReportrticle(item *CygxArticle, chartPermissionId int, industryName, subjectName string, itemDepartment *CygxArticleDepartment, industrialManagementIds, industrialSubjectIds string) (newId int64, err error) {
  531. var newDepartmentId int64
  532. var total int
  533. itemIndustrialManagementGroup := new(CygxIndustrialArticleGroupManagement)
  534. itemIndustrialSubjectGroup := new(CygxIndustrialArticleGroupSubject)
  535. o := orm.NewOrm()
  536. to, err := o.Begin()
  537. if err != nil {
  538. return
  539. }
  540. defer func() {
  541. if err != nil {
  542. _ = to.Rollback()
  543. } else {
  544. _ = to.Commit()
  545. }
  546. }()
  547. if itemDepartment.NickName != "" {
  548. //判断作者是否存在,如果没有则新增
  549. total, err = GetArticleDepartmentCount(itemDepartment.NickName, itemDepartment.Remarks)
  550. if err != nil {
  551. return
  552. }
  553. if total == 0 {
  554. newDepartmentId, err = to.Insert(itemDepartment)
  555. if err != nil {
  556. return
  557. }
  558. } else {
  559. departmentDetail := new(CygxArticleDepartmentRep)
  560. departmentDetail, err = GetArticleDepartmentDateil(itemDepartment.NickName, itemDepartment.Remarks)
  561. if err != nil {
  562. return
  563. }
  564. newDepartmentId = int64(departmentDetail.DepartmentId)
  565. }
  566. item.DepartmentId = int(newDepartmentId)
  567. }
  568. newId, err = to.Insert(item) // 新增文章
  569. if err != nil {
  570. return
  571. }
  572. //添加产业与文章的关联
  573. industrialManagementIdList := strings.Split(industrialManagementIds, ",")
  574. for _, v := range industrialManagementIdList {
  575. newIndustrialId, _ := strconv.Atoi(v)
  576. itemIndustrialManagementGroup.CreateTime = time.Now()
  577. itemIndustrialManagementGroup.CygxArticleId = int(newId)
  578. itemIndustrialManagementGroup.ArticleId = item.ArticleId
  579. itemIndustrialManagementGroup.IndustrialManagementId = newIndustrialId
  580. _, err = AddCygxIndustrialArticleGroupManagement(itemIndustrialManagementGroup)
  581. if err != nil {
  582. return
  583. }
  584. }
  585. //添加标的与文章的关联
  586. if industrialSubjectIds != "" {
  587. industrialSubjectIdList := strings.Split(industrialSubjectIds, ",")
  588. for _, v := range industrialSubjectIdList {
  589. industrialSubjectId, _ := strconv.Atoi(v)
  590. itemIndustrialSubjectGroup.CygxArticleId = int(newId)
  591. itemIndustrialSubjectGroup.ArticleId = item.ArticleId
  592. itemIndustrialSubjectGroup.IndustrialSubjectId = industrialSubjectId
  593. itemIndustrialSubjectGroup.CreateTime = time.Now()
  594. _, err = AddCygxIndustrialArticleGroupSubject(itemIndustrialSubjectGroup)
  595. if err != nil {
  596. return
  597. }
  598. }
  599. }
  600. return
  601. }
  602. // 修改报告文章
  603. func EditReportrticle(item *CygxArticle, chartPermissionId int, industryName, subjectName string, oldPublishStatus int, itemDepartment *CygxArticleDepartment, industrialManagementIds, industrialSubjectIds string) (err error) {
  604. var sql string
  605. var newDepartmentId int64
  606. var total int
  607. newId := item.SummaryManageId
  608. itemIndustrialManagementGroup := new(CygxIndustrialArticleGroupManagement)
  609. itemIndustrialSubjectGroup := new(CygxIndustrialArticleGroupSubject)
  610. o := orm.NewOrm()
  611. to, err := o.Begin()
  612. if err != nil {
  613. return
  614. }
  615. defer func() {
  616. if err != nil {
  617. _ = to.Rollback()
  618. } else {
  619. _ = to.Commit()
  620. }
  621. }()
  622. if itemDepartment.NickName != "" {
  623. //判断作者是否存在,如果没有则新增
  624. total, err = GetArticleDepartmentCount(itemDepartment.NickName, itemDepartment.Remarks)
  625. if err != nil {
  626. return
  627. }
  628. if total == 0 {
  629. newDepartmentId, err = to.Insert(itemDepartment)
  630. if err != nil {
  631. return
  632. }
  633. } else {
  634. departmentDetail := new(CygxArticleDepartmentRep)
  635. departmentDetail, err = GetArticleDepartmentDateil(itemDepartment.NickName, itemDepartment.Remarks)
  636. if err != nil {
  637. return
  638. }
  639. newDepartmentId = int64(departmentDetail.DepartmentId)
  640. }
  641. item.DepartmentId = int(newDepartmentId)
  642. }
  643. sql = ` UPDATE cygx_article SET
  644. category_name=?,
  645. title=?,
  646. abstract=?,
  647. body=?,
  648. body_text=?,
  649. publish_status=?,
  650. last_updated_time = ?,
  651. seller_and_mobile=?,
  652. expert_background =?,
  653. expert_number=? ,
  654. interview_date=?,
  655. file_link=? ,
  656. chart_permission_ids =?,
  657. article_type_id =?,
  658. article_type_name =?,
  659. admin_id =?,
  660. admin_name =?,
  661. is_summary =?,
  662. is_report =?,
  663. department_id =?,
  664. publish_date =?,
  665. report_link =?
  666. WHERE article_id =?`
  667. _, 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()
  668. if err != nil {
  669. return
  670. }
  671. //删除文章关联行业 (避免截断表时产生的脏数据,故不用update而是先删除再增加)
  672. sql = ` DELETE FROM cygx_industrial_article_group_management WHERE article_id = ?`
  673. _, err = to.Raw(sql, item.ArticleId).Exec()
  674. if err != nil {
  675. return
  676. }
  677. //删除文章关联标的
  678. sql = ` DELETE FROM cygx_industrial_article_group_subject WHERE article_id = ?`
  679. _, err = to.Raw(sql, item.ArticleId).Exec()
  680. if err != nil {
  681. return
  682. }
  683. //添加产业与文章的关联
  684. industrialManagementIdList := strings.Split(industrialManagementIds, ",")
  685. for _, v := range industrialManagementIdList {
  686. newIndustrialId, _ := strconv.Atoi(v)
  687. itemIndustrialManagementGroup.CreateTime = time.Now()
  688. itemIndustrialManagementGroup.CygxArticleId = int(newId)
  689. itemIndustrialManagementGroup.ArticleId = item.ArticleId
  690. itemIndustrialManagementGroup.IndustrialManagementId = newIndustrialId
  691. _, err = AddCygxIndustrialArticleGroupManagement(itemIndustrialManagementGroup)
  692. if err != nil {
  693. return
  694. }
  695. }
  696. //添加标的与文章的关联
  697. if industrialSubjectIds != "" {
  698. industrialSubjectIdList := strings.Split(industrialSubjectIds, ",")
  699. for _, v := range industrialSubjectIdList {
  700. industrialSubjectId, _ := strconv.Atoi(v)
  701. itemIndustrialSubjectGroup.CygxArticleId = int(newId)
  702. itemIndustrialSubjectGroup.ArticleId = item.ArticleId
  703. itemIndustrialSubjectGroup.IndustrialSubjectId = industrialSubjectId
  704. itemIndustrialSubjectGroup.CreateTime = time.Now()
  705. _, err = AddCygxIndustrialArticleGroupSubject(itemIndustrialSubjectGroup)
  706. if err != nil {
  707. return
  708. }
  709. }
  710. }
  711. return
  712. }
  713. type CygxArticleReport struct {
  714. ArticleId int `description:"文章ID"`
  715. Title string `description:"标题"`
  716. Abstract string `description:"摘要"`
  717. Body string `description:"内容"`
  718. PublishStatus int `description:"发布状态,0未发布 ,1已发布"`
  719. PublishDate string `description:"发布时间"`
  720. CreateDate time.Time `description:"创建时间"`
  721. LastUpdatedTime time.Time `description:"更新时间"`
  722. ArticleIdMd5 string `description:"ID,md5值"`
  723. SellerAndMobile string `description:"作者(姓名与手机号)"`
  724. SubjectName string `description:"标的名称"`
  725. IndustryName string `description:"产业名称"`
  726. DepartmentId int `description:"作者id"`
  727. ChartPermissionIds string `description:"行业ID ,多个用 , 隔开"`
  728. ArticleTypeId int `description:"文章类型ID"`
  729. ArticleTypeName string `description:"文章类型名称"`
  730. ReportLink string `description:"报告链接"`
  731. ChartPermissionId int `description:"行业id"`
  732. ListIndustrial []*IndustrialActivityGroupManagementRep
  733. ListSubject []*SubjectActivityGroupManagementRep
  734. }
  735. // 通过纪要ID获取文章详情
  736. func GetArticleIdInfoByreportIdEdit(articleId int) (item *CygxArticleReport, err error) {
  737. o := orm.NewOrm()
  738. sql := `SELECT
  739. a.* ,m.industry_name,
  740. GROUP_CONCAT(DISTINCT s.subject_name SEPARATOR ',') AS subject_name
  741. FROM
  742. cygx_article as a
  743. INNER JOIN cygx_industrial_article_group_management as mg ON mg.cygx_article_id = a.id
  744. INNER JOIN cygx_industrial_management as m ON m.industrial_management_id = mg.industrial_management_id
  745. LEFT JOIN cygx_industrial_article_group_subject as sg ON sg.cygx_article_id = a.id
  746. LEFT JOIN cygx_industrial_subject as s ON s.industrial_subject_id = sg.industrial_subject_id
  747. WHERE
  748. a.article_id = ?`
  749. err = o.Raw(sql, articleId).QueryRow(&item)
  750. return
  751. }
  752. // 修改文章关联的标的ID
  753. func UpdateSubjecIds(subjecIds string, industrialManagementId, articleId int) (err error) {
  754. o := orm.NewOrm()
  755. var industrialAndSubjectIds string
  756. industrialAndSubjectIds = strings.Replace(strings.Replace(subjecIds, "{|1|}", "", -1), "{|2|}", "", -1)
  757. fmt.Println(industrialAndSubjectIds)
  758. sql := `UPDATE cygx_article SET subject_ids=? ,industrial_management_id =?, industrial_and_subject_ids = ? WHERE article_id = ?`
  759. _, err = o.Raw(sql, subjecIds, industrialManagementId, industrialAndSubjectIds, articleId).Exec()
  760. return
  761. }
  762. // 删除研选报告,以及相关归类,收藏
  763. func DeleteArticleReport(articleId int) (err error) {
  764. o := orm.NewOrm()
  765. to, err := o.Begin()
  766. if err != nil {
  767. return
  768. }
  769. defer func() {
  770. if err != nil {
  771. fmt.Println(err)
  772. _ = to.Rollback()
  773. } else {
  774. _ = to.Commit()
  775. }
  776. }()
  777. sql := ""
  778. //删除关联产业
  779. sql = ` DELETE FROM cygx_industrial_article_group_management WHERE article_id = ?`
  780. _, err = to.Raw(sql, articleId).Exec()
  781. if err != nil {
  782. return
  783. }
  784. //删除关联标的
  785. sql = ` DELETE FROM cygx_industrial_article_group_subject WHERE article_id = ?`
  786. _, err = to.Raw(sql, articleId).Exec()
  787. if err != nil {
  788. return
  789. }
  790. //删除关联收藏
  791. sql = ` DELETE FROM cygx_article_collect WHERE article_id = ?`
  792. _, err = to.Raw(sql, articleId).Exec()
  793. if err != nil {
  794. return
  795. }
  796. //删除阅读记录
  797. sql = ` DELETE FROM cygx_article_history_record WHERE article_id = ?`
  798. _, err = to.Raw(sql, articleId).Exec()
  799. if err != nil {
  800. return
  801. }
  802. //删除阅读记录
  803. sql = ` DELETE FROM cygx_article_history_record_newpv WHERE article_id = ?`
  804. _, err = to.Raw(sql, articleId).Exec()
  805. if err != nil {
  806. return
  807. }
  808. //删除报告
  809. sql = ` DELETE FROM cygx_article WHERE article_id = ?`
  810. _, err = to.Raw(sql, articleId).Exec()
  811. return
  812. }
  813. type AddArticleRoadshowEssenceRep struct {
  814. ArticleId int `description:"文章ID 0 新增,大于0 修改"`
  815. Title string `description:"标题"`
  816. SellerAndMobile string `description:"作者(姓名与手机号)"`
  817. PublishDate string `description:"发布时间"`
  818. ChartPermissionId int `description:"行业ID"`
  819. IndustrialManagementId string `description:"产业id,多个用 , 英文逗号隔开"`
  820. IndustrialSubjectIdStr string `description:"标的id多个用 , 英文逗号隔开"`
  821. Abstract string `description:"摘要"`
  822. Body string `description:"内容"`
  823. ReportLink string `description:"报告链接"`
  824. DoType int `description:"操作方式,1发布,0保存"`
  825. }
  826. // 添加报告文章
  827. func AddArticleRoadshowEssence(item *CygxArticle, industryIds, subjectIds string) (newId int64, err error) {
  828. itemIndustrialManagementGroup := new(CygxIndustrialArticleGroupManagement)
  829. itemIndustrialSubjectGroup := new(CygxIndustrialArticleGroupSubject)
  830. o := orm.NewOrm()
  831. to, err := o.Begin()
  832. if err != nil {
  833. return
  834. }
  835. defer func() {
  836. if err != nil {
  837. _ = to.Rollback()
  838. } else {
  839. _ = to.Commit()
  840. }
  841. }()
  842. newId, err = to.Insert(item) // 新增文章
  843. if err != nil {
  844. return
  845. }
  846. //添加产业与文章的关联
  847. industrialStrList := strings.Split(industryIds, ",")
  848. for _, v := range industrialStrList {
  849. itemIndustrialManagementGroup.CreateTime = time.Now()
  850. itemIndustrialManagementGroup.CygxArticleId = int(newId)
  851. itemIndustrialManagementGroup.ArticleId = item.ArticleId
  852. industryId, _ := strconv.Atoi(v)
  853. itemIndustrialManagementGroup.IndustrialManagementId = industryId
  854. _, err = AddCygxIndustrialArticleGroupManagement(itemIndustrialManagementGroup)
  855. if err != nil {
  856. return
  857. }
  858. }
  859. //添加标的与文章的关联
  860. if subjectIds != "" {
  861. slice := strings.Split(subjectIds, ",") //标的处理、添加标的与产业的关联、标的与文章的关联
  862. for _, v := range slice {
  863. itemIndustrialSubjectGroup.CygxArticleId = int(newId)
  864. itemIndustrialSubjectGroup.ArticleId = item.ArticleId
  865. subjectId, _ := strconv.Atoi(v)
  866. itemIndustrialSubjectGroup.IndustrialSubjectId = subjectId
  867. itemIndustrialSubjectGroup.CreateTime = time.Now()
  868. _, err = AddCygxIndustrialArticleGroupSubject(itemIndustrialSubjectGroup)
  869. if err != nil {
  870. return
  871. }
  872. }
  873. }
  874. return
  875. }
  876. // 修改报告文章
  877. func UpdateArticleRoadshowEssence(item *CygxArticle, industryIds, subjectIds string) (err error) {
  878. itemIndustrialManagementGroup := new(CygxIndustrialArticleGroupManagement)
  879. itemIndustrialSubjectGroup := new(CygxIndustrialArticleGroupSubject)
  880. o := orm.NewOrm()
  881. to, err := o.Begin()
  882. if err != nil {
  883. return
  884. }
  885. defer func() {
  886. if err != nil {
  887. _ = to.Rollback()
  888. } else {
  889. _ = to.Commit()
  890. }
  891. }()
  892. newId := item.SummaryManageId
  893. 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 = ?`
  894. _, 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()
  895. if err != nil {
  896. return
  897. }
  898. //删除文章关联行业 (避免截断表时产生的脏数据,故不用update而是先删除再增加)
  899. sql = ` DELETE FROM cygx_industrial_article_group_management WHERE article_id = ?`
  900. _, err = to.Raw(sql, item.ArticleId).Exec()
  901. if err != nil {
  902. return
  903. }
  904. //删除文章关联标的
  905. sql = ` DELETE FROM cygx_industrial_article_group_subject WHERE article_id = ?`
  906. _, err = to.Raw(sql, item.ArticleId).Exec()
  907. if err != nil {
  908. return
  909. }
  910. //添加产业与文章的关联
  911. industrialStrList := strings.Split(industryIds, ",")
  912. for _, v := range industrialStrList {
  913. itemIndustrialManagementGroup.CreateTime = time.Now()
  914. itemIndustrialManagementGroup.CygxArticleId = int(newId)
  915. itemIndustrialManagementGroup.ArticleId = item.ArticleId
  916. industryId, _ := strconv.Atoi(v)
  917. itemIndustrialManagementGroup.IndustrialManagementId = industryId
  918. _, err = AddCygxIndustrialArticleGroupManagement(itemIndustrialManagementGroup)
  919. if err != nil {
  920. return
  921. }
  922. }
  923. //添加标的与文章的关联
  924. if subjectIds != "" {
  925. slice := strings.Split(subjectIds, ",") //标的处理、添加标的与产业的关联、标的与文章的关联
  926. for _, v := range slice {
  927. itemIndustrialSubjectGroup.CygxArticleId = int(newId)
  928. itemIndustrialSubjectGroup.ArticleId = item.ArticleId
  929. subjectId, _ := strconv.Atoi(v)
  930. itemIndustrialSubjectGroup.IndustrialSubjectId = subjectId
  931. itemIndustrialSubjectGroup.CreateTime = time.Now()
  932. _, err = AddCygxIndustrialArticleGroupSubject(itemIndustrialSubjectGroup)
  933. if err != nil {
  934. return
  935. }
  936. }
  937. }
  938. return
  939. }
  940. type ArticleRoadshowEssenceDetail struct {
  941. ArticleId int `description:"文章ID"`
  942. Title string `description:"标题"`
  943. SellerAndMobile string `description:"作者(姓名与手机号)"`
  944. PublishDate string `description:"发布时间"`
  945. ChartPermissionId int `orm:"column(chart_permission_ids);"description:"行业ID"`
  946. PermissionName string `orm:"column(category_name);"description:"行业名称"`
  947. IndustrialManagementId string `description:"产业id,多个用 , 英文逗号隔开"`
  948. IndustryName string `description:"产业名称"`
  949. IndustrialSubjectIdStr string `description:"标的id多个用 , 英文逗号隔开"`
  950. SubjectName string `description:"标的名称"`
  951. Abstract string `description:"摘要"`
  952. Body string `description:"内容"`
  953. ReportLink string `description:"报告链接"`
  954. PublishStatus int `description:"发布状态,0未发布 ,1已发布"`
  955. }
  956. // 文章详情
  957. func GetArticleRoadshowEssenceDetail(articleId int) (item *ArticleRoadshowEssenceDetail, err error) {
  958. o := orm.NewOrm()
  959. sql := `SELECT
  960. art.* ,
  961. GROUP_CONCAT( DISTINCT mg.industrial_management_id SEPARATOR ',' ) AS industrial_management_id ,
  962. GROUP_CONCAT( DISTINCT m.industry_name SEPARATOR ',' ) AS industry_name,
  963. GROUP_CONCAT( DISTINCT sg.industrial_subject_id SEPARATOR ',' ) AS industrial_subject_id_str ,
  964. GROUP_CONCAT( DISTINCT s.subject_name SEPARATOR ',' ) AS subject_name
  965. FROM
  966. cygx_article as art
  967. LEFT JOIN cygx_industrial_article_group_management as mg ON mg.article_id = art.article_id
  968. LEFT JOIN cygx_industrial_management as m ON m.industrial_management_id = mg.industrial_management_id
  969. LEFT JOIN cygx_industrial_article_group_subject as sg ON sg.article_id = art.article_id
  970. LEFT JOIN cygx_industrial_subject as s ON s.industrial_subject_id = sg.industrial_subject_id
  971. WHERE
  972. art.article_id = ?`
  973. err = o.Raw(sql, articleId).QueryRow(&item)
  974. return
  975. }
  976. // 列表
  977. func GetArticleRoadshowEssenceList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxResearchSummaryRep, err error) {
  978. o := orm.NewOrm()
  979. sql := `SELECT *,
  980. (SELECT COUNT(1) FROM cygx_article_history_record AS h WHERE h.article_id=art.article_id) AS pv,
  981. (SELECT COUNT(DISTINCT user_id) FROM cygx_article_history_record AS h WHERE h.article_id=art.article_id) AS uv
  982. FROM cygx_article as art WHERE 1= 1 `
  983. if condition != "" {
  984. sql += condition
  985. }
  986. sql += ` LIMIT ?,?`
  987. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  988. return
  989. }
  990. // 列表
  991. func GetArticlList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxArticle, err error) {
  992. o := orm.NewOrm()
  993. sql := `SELECT *
  994. FROM cygx_article as art WHERE 1= 1 `
  995. if condition != "" {
  996. sql += condition
  997. }
  998. sql += ` LIMIT ?,?`
  999. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  1000. return
  1001. }
  1002. // 修改发布状态
  1003. func RoadshowEssencePublishAndCancel(item *CygxResearchSummaryRep) (err error) {
  1004. o := orm.NewOrm()
  1005. sql := `UPDATE cygx_article SET publish_status=? , last_updated_time= ?, periods= ?,admin_id =? ,admin_name =? ,have_publish = 1 WHERE article_id=? `
  1006. _, err = o.Raw(sql, item.PublishStatus, time.Now(), item.Periods, item.AdminId, item.AdminName, item.ArticleId).Exec()
  1007. return
  1008. }
  1009. ////获取数量
  1010. //func GetCygxArticleCountNew(condition string, pars []interface{}) (count int, err error) {
  1011. // sqlCount := ` SELECT COUNT(1) AS count FROM cygx_article as art WHERE 1= 1 `
  1012. // if condition != "" {
  1013. // sqlCount += condition
  1014. // }
  1015. // o := orm.NewOrm()
  1016. // err = o.Raw(sqlCount, pars).QueryRow(&count)
  1017. // return
  1018. //}
  1019. func UpdateArticleInfoVideo(reportId int, tbName, videoUrl, videoName, videoSize string, playSeconds float64) (err error) {
  1020. o := orm.NewOrm()
  1021. sql := `UPDATE ` + tbName + ` SET video_url=?,video_name=?,video_play_seconds=?,video_size=? WHERE article_id=? `
  1022. _, err = o.Raw(sql, videoUrl, videoName, playSeconds, videoSize, reportId).Exec()
  1023. return
  1024. }
  1025. // 客户其他行为数据导出 start
  1026. type CygxArticleCollect struct {
  1027. ArticleId int `description:"文章id"`
  1028. UserId int `description:"用户ID"`
  1029. Title string `description:"标题"`
  1030. CreateTime string `description:"创建时间"`
  1031. PublishDate string `description:"发布时间"`
  1032. PermissionName string `description:"行业"`
  1033. IndustryName string `description:"产业名称"`
  1034. SubjectName string `description:"关联标的"`
  1035. MatchTypeName string `description:"报告类型"`
  1036. CategoryId string `description:"分类ID"`
  1037. }
  1038. type CygxArticleIndustry struct {
  1039. UserId int `description:"用户ID"`
  1040. IndustrialManagementId int `description:"产业id"`
  1041. CreateTime string `description:"创建时间"`
  1042. IndustryName string `description:"产业名称"`
  1043. }
  1044. type ArticleDepartment struct {
  1045. DepartmentId int `description:"主键ID"`
  1046. NickName string `description:"昵称"`
  1047. UserId int `description:"用户ID"`
  1048. IndustrialManagementId int `description:"产业id"`
  1049. CreateTime string `description:"创建时间"`
  1050. IndustryName string `description:"产业名称"`
  1051. }
  1052. type KeyWord struct {
  1053. UserId int `description:"用户ID"`
  1054. CreateTime string `description:"创建时间"`
  1055. KeyWord string `description:"关键词"`
  1056. }
  1057. type CompanyOtherHistoryList struct {
  1058. Mobile string `description:"手机号"`
  1059. Email string `description:"邮箱"`
  1060. RealName string `description:"姓名"`
  1061. ListArticle []*CygxArticleCollect
  1062. ListIndustrial []*CygxArticleIndustry
  1063. ListDepartment []*ArticleDepartment
  1064. ListKeyWord []*KeyWord
  1065. }
  1066. type CompanyOtherHistoryListResp struct {
  1067. List []*CompanyOtherHistoryList
  1068. }
  1069. // 文章列表
  1070. func GetArticleCollectList(condition string) (items []*CygxArticleCollect, err error) {
  1071. o := orm.NewOrm()
  1072. sql := `SELECT
  1073. c.*,
  1074. a.title,
  1075. a.publish_date,
  1076. a.category_id,
  1077. a.match_type_name,
  1078. (SELECT
  1079. GROUP_CONCAT( DISTINCT m.industry_name SEPARATOR ',' ) AS industry_name
  1080. FROM
  1081. cygx_industrial_management AS m
  1082. WHERE
  1083. 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,
  1084. (SELECT
  1085. GROUP_CONCAT( DISTINCT s.subject_name SEPARATOR ',' ) AS subject_name
  1086. FROM
  1087. cygx_industrial_subject AS s
  1088. WHERE
  1089. 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
  1090. FROM
  1091. cygx_article_collect AS c
  1092. INNER JOIN cygx_article AS a ON a.article_id = c.article_id
  1093. WHERE 1=1`
  1094. if condition != "" {
  1095. sql += condition
  1096. }
  1097. _, err = o.Raw(sql).QueryRows(&items)
  1098. return
  1099. }
  1100. // 产业列表
  1101. func GetCygxIndustryList(companyId int) (items []*CygxArticleIndustry, err error) {
  1102. o := orm.NewOrm()
  1103. sql := `SELECT
  1104. f.user_id,f.create_time,m.industrial_management_id,m.industry_name
  1105. FROM
  1106. cygx_industry_fllow AS f
  1107. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = f.industrial_management_id
  1108. WHERE
  1109. 1 = 1
  1110. AND f.company_id = ?`
  1111. _, err = o.Raw(sql, companyId).QueryRows(&items)
  1112. return
  1113. }
  1114. // 作者列表
  1115. func GetArticleDepartmentList(companyId int) (items []*ArticleDepartment, err error) {
  1116. o := orm.NewOrm()
  1117. sql := `SELECT
  1118. f.user_id,f.create_time,m.department_id,m.nick_name,
  1119. (SELECT
  1120. GROUP_CONCAT( DISTINCT m.industry_name SEPARATOR ',' ) AS industry_name
  1121. FROM
  1122. cygx_industrial_management AS m
  1123. WHERE
  1124. 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
  1125. FROM
  1126. cygx_article_department_follow AS f
  1127. INNER JOIN cygx_article_department AS m ON m.department_id = f.department_id
  1128. WHERE
  1129. 1 = 1
  1130. AND f.company_id = ?`
  1131. _, err = o.Raw(sql, companyId).QueryRows(&items)
  1132. return
  1133. }
  1134. // 关键词列表
  1135. func GetCygxSearchKeyWordList(userIdStr string) (items []*KeyWord, err error) {
  1136. o := orm.NewOrm()
  1137. sql := `SELECT * FROM cygx_search_key_word WHERE user_id IN (` + userIdStr + `)`
  1138. _, err = o.Raw(sql).QueryRows(&items)
  1139. return
  1140. }
  1141. // 关键词列表
  1142. func GetCygxUserSearchKeyWordList(userIdStr string) (items []*KeyWord, err error) {
  1143. o := orm.NewOrm()
  1144. sql := `SELECT * FROM cygx_user_search_key_word WHERE user_id IN (` + userIdStr + `) AND page_type IN ('ReortSearch','HomeSearch')`
  1145. _, err = o.Raw(sql).QueryRows(&items)
  1146. return
  1147. } //end
  1148. type CreateTimesResp struct {
  1149. CreateTimes string `description:"创建时间"`
  1150. }
  1151. type CompanyArticleCountResp struct {
  1152. CreateTimes string `description:"创建时间"`
  1153. ReadSum int `description:"总阅读数"`
  1154. YiyaoSum int `description:"医药阅读数"`
  1155. XiaofeiSum int `description:"医药阅读数"`
  1156. KejiSum int `description:"医药阅读数"`
  1157. ZhizaoSum int `description:"医药阅读数"`
  1158. CelueSum int `description:"医药阅读数"`
  1159. YanxuanSum int `description:"医药阅读数"`
  1160. }
  1161. type CompanyArticleCountListResp struct {
  1162. List []*CompanyArticleCountResp
  1163. }
  1164. func GetCompanyHistoryRecordPvGroupDate(mobiles, emails string) (item []*CreateTimesResp, err error) {
  1165. o := orm.NewOrm()
  1166. sql := ` SELECT date_format(create_time,'%Y-%m') as create_times FROM cygx_article_history_record_all AS h
  1167. INNER JOIN cygx_article art ON art.article_id = h.article_id
  1168. 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 `
  1169. _, err = o.Raw(sql).QueryRows(&item)
  1170. return
  1171. }
  1172. func GetCompanyHistoryRecordPv(mobiles, emails string) (item []*CompanyHistoryRecordNewPvRep, err error) {
  1173. o := orm.NewOrm()
  1174. sql := ` SELECT
  1175. a.title,
  1176. a.category_id,
  1177. date_format(h.create_time,'%Y-%m') as create_time,
  1178. m.chart_permission_name as permission_name
  1179. FROM
  1180. cygx_article_history_record_all AS h
  1181. INNER JOIN cygx_article AS a ON a.article_id = h.article_id
  1182. LEFT JOIN cygx_report_mapping AS m ON a.category_id = m.category_id
  1183. WHERE h.mobile IN (` + mobiles + `) AND h.is_del = 0 OR( h.email IN (` + emails + `) AND h.email <>'' AND h.is_del = 0 )
  1184. ORDER BY
  1185. h.create_time DESC `
  1186. _, err = o.Raw(sql).QueryRows(&item)
  1187. return
  1188. }
  1189. type CygxCelueArticleHistoryRecord struct {
  1190. Id int `orm:"column(id);pk"`
  1191. ArticleId int `description:"文章ID"`
  1192. CelueHistoryId int `description:"策略平台记录的ID"`
  1193. CreateTime string `description:"本地创建时间"`
  1194. CreateDateApi time.Time `description:"图表创建时间"`
  1195. Mobile string `description:"手机号"`
  1196. CompanyName string `description:"公司名称"`
  1197. RealName string `description:"用户姓名"`
  1198. }
  1199. func GetArticleHistoryRecordMobile(articleIds string) (mobiles string, err error) {
  1200. sql := `SELECT GROUP_CONCAT( DISTINCT mobile SEPARATOR ',' ) as mobiles FROM cygx_article_history_record_newpv WHERE article_id IN (` + articleIds + `) AND mobile!= ''`
  1201. o := orm.NewOrm()
  1202. err = o.Raw(sql).QueryRow(&mobiles)
  1203. return
  1204. }
  1205. func GetCygxCelueArticleHistoryRecordPv(articleIds, mobiles string) (item []*ArticleHistoryRep, err error) {
  1206. o := orm.NewOrm()
  1207. sql := `SELECT * FROM cygx_celue_article_history_record WHERE article_id IN ( ` + articleIds + ` ) AND `
  1208. if mobiles != "" {
  1209. sql += ` AND mobile NOT IN ( ` + mobiles + `)`
  1210. }
  1211. sql += ` ORDER BY create_time DESC `
  1212. _, err = o.Raw(sql).QueryRows(&item)
  1213. return
  1214. }
  1215. func GetCygxCelueArticleHistoryRecordPvAll(articleIds string) (item []*ArticleHistoryRep, err error) {
  1216. o := orm.NewOrm()
  1217. sql := `SELECT * FROM cygx_article_history_record_all as h WHERE article_id IN ( ` + articleIds + ` ) AND h.is_del = 0 AND h.platfor = 2 `
  1218. sql += ` ORDER BY create_time DESC `
  1219. _, err = o.Raw(sql).QueryRows(&item)
  1220. return
  1221. }
  1222. func GetCygxCelueArticleComapnyName(mobiles string) (item []*ArticleHistoryRep, err error) {
  1223. o := orm.NewOrm()
  1224. sql := `SELECT
  1225. c.company_name,a.real_name,u.mobile
  1226. FROM
  1227. wx_user AS u
  1228. INNER JOIN company as c ON c.company_id = u.company_id
  1229. INNER JOIN company_product as p ON p.company_id = c.company_id
  1230. INNER JOIN admin as a On a.admin_id = p.seller_id
  1231. WHERE p.product_id = 2
  1232. AND u.mobile IN ( ` + mobiles + `) GROUP BY u.mobile `
  1233. _, err = o.Raw(sql).QueryRows(&item)
  1234. return
  1235. }
  1236. type ArticleDetailResp struct {
  1237. ArticleId int `description:"文章ID"`
  1238. Title string `description:"标题"`
  1239. Abstract string `description:"摘要"`
  1240. Body string `description:"内容"`
  1241. PublishStatus int `description:"发布状态,0未发布 ,1已发布"`
  1242. PublishDate string `description:"发布时间"`
  1243. CreateDate time.Time `description:"创建时间"`
  1244. LastUpdatedTime time.Time `description:"更新时间"`
  1245. ArticleIdMd5 string `description:"ID,md5值"`
  1246. SellerAndMobile string `description:"作者(姓名与手机号)"`
  1247. SubjectName string `description:"标的名称"`
  1248. IndustryName string `description:"产业名称"`
  1249. DepartmentId int `description:"作者id"`
  1250. ChartPermissionIds string `description:"行业ID ,多个用 , 隔开"`
  1251. ArticleTypeId int `description:"文章类型ID"`
  1252. ArticleTypeName string `description:"文章类型名称"`
  1253. ListIndustrial []*IndustrialActivityGroupManagementRep
  1254. ListSubject []*SubjectActivityGroupManagementRep
  1255. ImgUrl string `description:"头像url"`
  1256. NickName string `description:"昵称"`
  1257. ReportLink string `description:"报告链接"`
  1258. }
  1259. // GetArticleIdsFromIndustryAndSubjectGroupByKeyword 产业/标的关键词获取文章IDs
  1260. func GetArticleIdsFromIndustryAndSubjectGroupByKeyword(keyword string) (ids []int, err error) {
  1261. sql := `SELECT DISTINCT
  1262. mg.article_id
  1263. FROM
  1264. cygx_industrial_article_group_management AS mg
  1265. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  1266. WHERE
  1267. 1 = 1
  1268. AND m.industry_name LIKE ?
  1269. UNION
  1270. SELECT DISTINCT
  1271. sg.article_id
  1272. FROM
  1273. cygx_industrial_article_group_subject AS sg
  1274. INNER JOIN cygx_industrial_subject AS s ON s.industrial_subject_id = sg.industrial_subject_id
  1275. WHERE
  1276. 1 = 1
  1277. AND s.subject_name LIKE ?`
  1278. _, err = orm.NewOrm().Raw(sql, keyword, keyword).QueryRows(&ids)
  1279. return
  1280. }
  1281. type SummaryArticleStock struct {
  1282. Id int `description:"新ID"`
  1283. ArticleId int `description:"文章id"`
  1284. Stock string `description:"个股标签"`
  1285. }
  1286. // 综述报告
  1287. func GetArticleStock() (items []*SummaryArticleStock, err error) {
  1288. o := orm.NewOrm()
  1289. sql := `SELECT
  1290. stock,article_id
  1291. FROM
  1292. cygx_article AS art
  1293. WHERE
  1294. 1 = 1
  1295. AND type_name = '综述报告' `
  1296. _, err = o.Raw(sql).QueryRows(&items)
  1297. return
  1298. }