report_article.go 49 KB

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