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