report_article.go 50 KB

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