article.go 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "hongze/hongze_web_mfyx/models/order"
  5. "strings"
  6. "time"
  7. )
  8. type CygxArticle struct {
  9. Id int `orm:"column(id);pk"`
  10. ArticleId int `description:"文章id"`
  11. Title string `description:"标题"`
  12. TitleEn string `description:"英文标题 "`
  13. UpdateFrequency string `description:"更新周期"`
  14. CreateDate string `description:"创建时间"`
  15. PublishDate string `description:"发布时间"`
  16. Body string `description:"内容"`
  17. BodyText string `description:"内容"`
  18. Abstract string `description:"摘要"`
  19. CategoryName string `description:"一级分类"`
  20. SubCategoryName string `description:"二级分类"`
  21. PublishStatus int `description:"发布状态"`
  22. CategoryId int `description:"分类id"`
  23. CategoryIdTwo int `description:"分类id用作修改匹配类型使用"`
  24. ExpertBackground string `description:"专家背景"`
  25. ExpertNumber string `description:"专家编号"`
  26. InterviewDate string `description:"访谈日期"`
  27. Department string `description:"作者"`
  28. ArticleIdMd5 string `description:"ID,md5值"`
  29. IsClass int `description:"是否归类,1是,0否"`
  30. IsSummary int `description:"是否是纪要库,1是,0否"`
  31. IsReport int `description:"是否属于报告,1是,0否"`
  32. ReportType int `description:"报告类型,1行业报告,2产业报告,0无"`
  33. FileLink string `description:"下载预览链接"`
  34. MatchTypeName string `description:"匹配类型"`
  35. Periods string `description:"期数"`
  36. ReportLink string `description:"报告链接"`
  37. ArticleType string `description:"文章类型 文章类型,lyjh:路演精华 "`
  38. HavePublish int `description:"是否发布过,1是 ,0 否"`
  39. Source int `description:"来源 0策略平台同步,1小程序后台添加"`
  40. SellerAndMobile string `description:"销售和手机号"`
  41. VideoUrl string `description:"音频文件URL"`
  42. VideoName string `description:"音频文件名称"`
  43. VideoPlaySeconds string `description:"音频播放时长"`
  44. Stock string `description:"个股标签"`
  45. FieldName string `description:"产业标签"`
  46. Annotation string `description:"核心观点"`
  47. TypeName string `description:"策略平台报告类型"`
  48. ModifyTimeByCl string `description:"策略平台报告更新时间"`
  49. CeLueFieldId int `description:"策略平台领域ID"`
  50. }
  51. type ArticleDetail struct {
  52. ArticleId int `description:"报告id"`
  53. ArticleIdMd5 string `description:"报告MD5id"`
  54. IsReport int `description:"是否属于报告,1是,0否"`
  55. Title string `description:"标题"`
  56. CategoryName string `description:"一级分类"`
  57. CategoryId int `description:"分类ID"`
  58. CreateDate string `description:"创建时间"`
  59. PublishDate string `description:"发布时间"`
  60. Body string `description:"内容"`
  61. Abstract string `description:"摘要"`
  62. Annotation string `description:"核心观点"`
  63. IsInterviewApply bool `description:"是否申请访谈:true,已申请,false:未申请"`
  64. InterviewApplyStatus string `description:"当前访谈申请状态:'待邀请','待访谈','已完成','已取消'"`
  65. IsFollow bool `description:"是否关注,1是,0否"`
  66. FollowNum int `description:"关注数量"`
  67. IsCollect bool `description:"是否收藏:true,已收藏,false:未收藏"`
  68. CollectionNum int `description:"收藏数量"`
  69. DepartmentId int `description:"作者ID"`
  70. DepartmentImgUrl string `description:"作者头像"`
  71. NickName string `description:"作者昵称"`
  72. HttpUrl string `description:"文章链接跳转地址"`
  73. IsNeedJump bool `description:"是否需要跳转链接地址"`
  74. Seller SellerResp `description:"作者昵称"`
  75. DepartmentDetail *DepartmentResp `description:"作者昵称"`
  76. Disclaimers string `description:"免责声明"`
  77. IsSpecialArticle bool `description:"是否属于专项调研报告"`
  78. SubCategoryName string `description:"二级分类"`
  79. ArticleTypeId int `description:"文章类型ID"`
  80. IsApplyAppointmentExpert bool `description:"是否属于专家访谈"`
  81. ShareImg string `description:"分享图片"`
  82. ChartPermissionName string `description:"行业名称"`
  83. VmpAuthorization string `description:"策略平台的token"`
  84. }
  85. type CygxArticleIdReq struct {
  86. ArticleId int `description:"文章id"`
  87. }
  88. type SellerResp struct {
  89. SellerMobile string `description:"销售手机号"`
  90. SellerName string `description:"销售名称"`
  91. }
  92. type ArticleDetailResp struct {
  93. IsResearch bool `description:"是否属于研选"`
  94. Mobile string `description:"用户手机号"`
  95. PopupMsg string `description:"权限弹窗信息"`
  96. SellerMobile string `description:"销售电话"`
  97. SellerName string `description:"销售姓名"`
  98. Detail *ArticleDetail
  99. IsSpecialArticle bool `description:"是否属于专项调研报告"`
  100. HasPermission int `description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,已提交过申请,4:无该行业权限,未提交过申请,5:潜在客户,未提交过申请,6:潜在客户,已提交过申请"`
  101. PopupPriceMsg string `description:"价格弹窗信息"`
  102. IsShowWxPay bool `description:"是否展示微信支付"`
  103. IsCompanyApply bool `description:"机构是否申请过试用"`
  104. IsNeedBusinessCard bool `description:"是否需要上传名片"`
  105. GoodsList []*order.CygxGoodsResp `description:"商品信息"`
  106. }
  107. func GetArticleDetailById(articleId int) (item *ArticleDetail, err error) {
  108. o := orm.NewOrm()
  109. sql := `SELECT * FROM cygx_article WHERE article_id = ? AND publish_status = 1 `
  110. err = o.Raw(sql, articleId).QueryRow(&item)
  111. return
  112. }
  113. func GetArticlePermission(companyId int) (item *ChartPermissionItemResp, err error) {
  114. o := orm.NewOrm()
  115. sql := `SELECT
  116. a.chart_permission_name as permission_name,a.match_type_name
  117. FROM
  118. cygx_report_mapping AS a
  119. WHERE
  120. a.category_id = ? LIMIT 1 `
  121. err = o.Raw(sql, companyId).QueryRow(&item)
  122. //_, err = o.Raw(sql, companyId).QueryRows(&item)
  123. return
  124. }
  125. type ArticleFollowDetail struct {
  126. DNum int `description:"作者被关注的数量"`
  127. MdNum int `description:"本人是否关注这个作者"`
  128. AcNum int `description:"文章被收藏的数量"`
  129. MacNum int `description:"本人是否收藏这个文章"`
  130. }
  131. // 获取文章被关注被收藏的详情
  132. func GetArticleFollowDetail(articleId, uid int) (item *ArticleFollowDetail, err error) {
  133. //d_num 作者被关注的数量 、 md_num 本人是否关注这个作者 、ac_num 文章被收藏的数量 、 mac_num 本人是否收藏这个文章
  134. o := orm.NewOrm()
  135. sql := ` SELECT
  136. ( SELECT count( 1 ) FROM cygx_article_department_follow AS af WHERE af.department_id = art.department_id AND af.type = 1 ) AS d_num,
  137. ( SELECT count( 1 ) FROM cygx_article_department_follow AS af WHERE af.department_id = art.department_id AND af.type = 1 AND af.user_id = ? ) AS md_num,
  138. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = art.article_id ) AS ac_num,
  139. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = art.article_id AND ac.user_id = ? ) AS mac_num
  140. FROM
  141. cygx_article AS art
  142. LEFT JOIN cygx_article_department_follow AS af ON af.department_id = art.department_id
  143. LEFT JOIN cygx_article_collect AS ac ON ac.article_id = art.article_id
  144. WHERE
  145. art.article_id = ?
  146. GROUP BY art.article_id `
  147. err = o.Raw(sql, uid, uid, articleId).QueryRow(&item)
  148. return
  149. }
  150. func GetArticleCountById(articleId int) (count int, err error) {
  151. o := orm.NewOrm()
  152. sql := `SELECT COUNT(1) AS count FROM cygx_article WHERE article_id = ? `
  153. err = o.Raw(sql, articleId).QueryRow(&count)
  154. return
  155. }
  156. // 用户收藏榜start
  157. type ArticleCollectionResp struct {
  158. ArticleId int `description:"文章id"`
  159. Title string `description:"标题"`
  160. PublishDate string `description:"发布时间"`
  161. DepartmentId int `description:"作者Id"`
  162. NickName string `description:"作者昵称"`
  163. IsCollect bool `description:"本人是否收藏"`
  164. Pv int `description:"PV"`
  165. CollectNum int `description:"收藏人数"`
  166. Source int `description:"来源 1:弘则资源包(报告)、2:研选主题(报告)"`
  167. List []*IndustrialManagementResp `description:"产业列表"`
  168. Body string `description:"内容"`
  169. Abstract string `description:"摘要"`
  170. Annotation string `description:"核心观点"`
  171. CategoryName string `description:"一级分类"`
  172. SubCategoryName string `description:"二级分类"`
  173. IsResearch bool `description:"是否属于研选"`
  174. ImgUrlPc string `description:"图片链接"`
  175. CategoryId string `description:"文章分类"`
  176. HttpUrl string `description:"文章链接跳转地址"`
  177. IsNeedJump bool `description:"是否需要跳转链接地址"`
  178. MyCollectNum int `description:"本人是否收藏数量"`
  179. ArticleTypeId int `description:"文章类型ID"`
  180. IsSpecial int `description:"是否为研选专栏"`
  181. SpecialTags string `description:"研选专栏标签"`
  182. UserId int `description:"作者id"`
  183. SpecialType int `description:"专栏类型 1:笔记,2:观点"`
  184. }
  185. // 列表
  186. func GetArticleCollectionList(condition string, userId int) (items []*ArticleCollectionResp, err error) {
  187. o := orm.NewOrm()
  188. sql := `SELECT
  189. a.article_id,
  190. a.title,
  191. date_format( a.publish_date, '%Y-%m-%d' ) AS publish_date,
  192. m.industry_name,
  193. m.industrial_management_id,
  194. d.nick_name,
  195. d.department_id,
  196. ( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
  197. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id ) AS collect_num,
  198. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id AND DATE_SUB( CURDATE(), INTERVAL 30 DAY ) <= date( ac.create_time ) ) AS collect_num_order,
  199. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id AND user_id = ? ) AS my_collect_num
  200. FROM
  201. cygx_article AS a
  202. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  203. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  204. INNER JOIN cygx_article_department AS d ON d.department_id = a.department_id
  205. WHERE
  206. 1 = 1 AND a.publish_status = 1 `
  207. if condition != "" {
  208. sql += condition
  209. }
  210. _, err = o.Raw(sql, userId).QueryRows(&items)
  211. return
  212. } //end
  213. type ArticleCollectionLIstResp struct {
  214. List []*ArticleCollectionResp
  215. }
  216. type CygxArticleEs struct {
  217. Id int `orm:"column(id);pk"`
  218. ArticleId int `description:"文章id"`
  219. Title string `description:"标题"`
  220. TitleEn string `description:"英文标题 "`
  221. UpdateFrequency string `description:"更新周期"`
  222. CreateDate string `description:"创建时间"`
  223. PublishDate string `description:"发布时间"`
  224. Body string `description:"内容"`
  225. BodyText string `description:"内容"`
  226. Abstract string `description:"摘要"`
  227. CategoryName string `description:"一级分类"`
  228. SubCategoryName string `description:"二级分类"`
  229. PublishStatus int `description:"发布状态"`
  230. CategoryId string `description:"分类id"`
  231. ExpertBackground string `description:"专家背景"`
  232. ExpertNumber string `description:"专家编号"`
  233. InterviewDate string `description:"访谈日期"`
  234. Department string `description:"作者"`
  235. ArticleIdMd5 string `description:"ID,md5值"`
  236. IsClass int `description:"是否归类,1是,0否"`
  237. IsSummary bool `description:"是否是纪要库,1是,0否"`
  238. IsReport bool `description:"是否属于报告,1是,0否"`
  239. ReportType int `description:"报告类型,1行业报告,2产业报告,0无"`
  240. FileLink string `description:"下载预览链接"`
  241. MatchTypeName string `description:"匹配类型"`
  242. }
  243. // 获取文章列表
  244. func GetArticleList(condition string, pars []interface{}) (items []*ArticleDetail, err error) {
  245. o := orm.NewOrm()
  246. sql := `SELECT article_id FROM cygx_article WHERE 1= 1 ` + condition
  247. _, err = o.Raw(sql, pars).QueryRows(&items)
  248. return
  249. }
  250. func GetArticleDetailByIdStr(articleIdStr string) (items []*ArticleDetail, err error) {
  251. o := orm.NewOrm()
  252. sql := `SELECT art.*,d.nick_name FROM
  253. cygx_article AS art
  254. LEFT JOIN cygx_article_department AS d ON d.department_id = art.department_id WHERE article_id IN(` + articleIdStr + `) `
  255. _, err = o.Raw(sql).QueryRows(&items)
  256. return
  257. }
  258. // 检查用户是否阅读某一分类最新文章
  259. func GetUserIsReadThisNewCategoryArticleCount(categoryId, uid int) (count int, err error) {
  260. sqlCount := `SELECT COUNT(1) as count FROM
  261. cygx_article_history_record
  262. WHERE
  263. article_id = ( SELECT article_id FROM cygx_article WHERE category_id = ? ORDER BY publish_date DESC LIMIT 0, 1 )
  264. AND user_id = ?`
  265. o := orm.NewOrm()
  266. err = o.Raw(sqlCount, categoryId, uid).QueryRow(&count)
  267. return
  268. }
  269. // 获取最新文章
  270. func GetNewArticleByCategoryId(categoryId int) (item *ArticleDetail, err error) {
  271. o := orm.NewOrm()
  272. sql := ` SELECT * FROM cygx_article WHERE category_id = ? ORDER BY publish_date DESC LIMIT 0, 1`
  273. err = o.Raw(sql, categoryId).QueryRow(&item)
  274. return
  275. }
  276. func GetArticleDetailByIdMd5(articleIdMd5 string) (item *ArticleDetail, err error) {
  277. o := orm.NewOrm()
  278. sql := `SELECT * FROM cygx_article WHERE article_id_md5 = ? `
  279. err = o.Raw(sql, articleIdMd5).QueryRow(&item)
  280. return
  281. }
  282. type SummaryArticleStock struct {
  283. Id int `description:"新ID"`
  284. ArticleId int `description:"文章id"`
  285. Stock string `description:"个股标签"`
  286. }
  287. type SummaryArticleStockResp struct {
  288. List []*SummaryArticleStock
  289. }
  290. // 综述报告
  291. func GetArticleStock() (items []*SummaryArticleStock, err error) {
  292. o := orm.NewOrm()
  293. sql := `SELECT
  294. stock,article_id
  295. FROM
  296. cygx_article AS art
  297. WHERE
  298. 1 = 1
  299. AND type_name = '综述报告' `
  300. _, err = o.Raw(sql).QueryRows(&items)
  301. return
  302. }
  303. // 列表
  304. func GetCygxCygxArticleList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxArticle, err error) {
  305. o := orm.NewOrm()
  306. sql := `SELECT * FROM cygx_article as art WHERE 1= 1 `
  307. if condition != "" {
  308. sql += condition
  309. }
  310. sql += ` LIMIT ?,? `
  311. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  312. return
  313. }
  314. // 获取数量
  315. func GetCygxArticleCount(condition string, pars []interface{}) (count int, err error) {
  316. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_article as art WHERE 1= 1 `
  317. if condition != "" {
  318. sqlCount += condition
  319. }
  320. o := orm.NewOrm()
  321. err = o.Raw(sqlCount, pars).QueryRow(&count)
  322. return
  323. }
  324. // 列表
  325. func GetCygxCygxArticleListByCondition(articleTypesCond, activityTypesCond, industryStr, subjectNameStr, articleTypeStr string) (artIds, actIds, mmIds string, err error) {
  326. o := orm.NewOrm()
  327. artSql := `SELECT GROUP_CONCAT(DISTINCT art.article_id SEPARATOR ',') AS art_ids FROM cygx_article as art `
  328. actSql := ` SELECT GROUP_CONCAT(DISTINCT act.activity_id SEPARATOR ',') AS act_ids FROM cygx_activity as act `
  329. mmSql := ` SELECT GROUP_CONCAT(DISTINCT mmc.id SEPARATOR ',') AS mm_ids FROM cygx_morning_meeting_review_chapter as mmc `
  330. if industryStr != "" {
  331. artSql += ` INNER JOIN cygx_industrial_article_group_management AS iam ON iam.article_id = art.article_id
  332. INNER JOIN cygx_industrial_management AS im ON im.industrial_management_id=iam.industrial_management_id `
  333. actSql += ` INNER JOIN cygx_industrial_activity_group_management AS iam ON iam.activity_id = act.activity_id
  334. INNER JOIN cygx_industrial_management AS im ON im.industrial_management_id=iam.industrial_management_id `
  335. mmSql += ` INNER JOIN cygx_morning_meeting_reviews AS mm ON mmc.meeting_id = mm.id
  336. INNER JOIN cygx_industrial_management AS im ON im.industrial_management_id=mmc.industry_id `
  337. }
  338. if subjectNameStr != "" {
  339. artSql += ` INNER JOIN cygx_industrial_article_group_subject AS ias ON ias.article_id = art.article_id
  340. INNER JOIN cygx_industrial_subject AS cis ON cis.industrial_subject_id=ias.industrial_subject_id `
  341. actSql += ` INNER JOIN cygx_industrial_activity_group_subject AS ias ON ias.activity_id = act.activity_id
  342. INNER JOIN cygx_industrial_subject AS cis ON cis.industrial_subject_id=ias.industrial_subject_id `
  343. mmSql += ` IINNER JOIN cygx_morning_meeting_reviews AS mm ON mmc.meeting_id = mm.id
  344. INNER JOIN cygx_industrial_subject AS cis ON cis.industrial_subject_id=mmc.industrial_subject_ids `
  345. }
  346. artSql += ` WHERE 1=1 `
  347. if articleTypesCond != "" || (articleTypesCond == "" && activityTypesCond == "") {
  348. if industryStr != "" && subjectNameStr != "" {
  349. artSql += articleTypesCond + ` AND (im.industry_name In (` + industryStr + `) OR cis.subject_name In (` + subjectNameStr + `) )`
  350. } else if industryStr == "" && subjectNameStr != "" {
  351. artSql += articleTypesCond + ` AND cis.subject_name In (` + subjectNameStr + `) `
  352. } else if industryStr != "" && subjectNameStr == "" {
  353. artSql += articleTypesCond + ` AND im.industry_name In (` + industryStr + `) `
  354. } else {
  355. artSql += articleTypesCond
  356. }
  357. err = o.Raw(artSql).QueryRow(&artIds)
  358. if err != nil {
  359. return
  360. }
  361. }
  362. actSql += ` WHERE 1=1 `
  363. if activityTypesCond != "" || (articleTypesCond == "" && activityTypesCond == "") {
  364. if industryStr != "" && subjectNameStr != "" {
  365. actSql += activityTypesCond + ` AND (im.industry_name In (` + industryStr + `) OR cis.subject_name In (` + subjectNameStr + `) )`
  366. } else if industryStr == "" && subjectNameStr != "" {
  367. actSql += activityTypesCond + ` AND cis.subject_name In (` + subjectNameStr + `) `
  368. } else if industryStr != "" && subjectNameStr == "" {
  369. actSql += activityTypesCond + ` AND im.industry_name In (` + industryStr + `) `
  370. } else {
  371. actSql += activityTypesCond
  372. }
  373. err = o.Raw(actSql).QueryRow(&actIds)
  374. if err != nil {
  375. return
  376. }
  377. }
  378. if strings.Contains(articleTypeStr, "晨会精华") {
  379. mmSql += ` WHERE 1=1 `
  380. if industryStr != "" && subjectNameStr != "" {
  381. mmSql += ` AND (im.industry_name In (` + industryStr + `) OR cis.subject_name In (` + subjectNameStr + `) )`
  382. } else if industryStr == "" && subjectNameStr != "" {
  383. mmSql += ` AND cis.subject_name In (` + subjectNameStr + `) `
  384. } else if industryStr != "" && subjectNameStr == "" {
  385. mmSql += ` AND im.industry_name In (` + industryStr + `) `
  386. }
  387. err = o.Raw(mmSql).QueryRow(&mmIds)
  388. if err != nil {
  389. return
  390. }
  391. }
  392. return
  393. }
  394. // 单个tag时用,取合集
  395. func GetCygxCygxArticleListByConditionSoloTag(articleTypeCondSlice, activityTypesCondSlice, industriesCondSlice, subjectNamesSlice, articleTypeSlice []string) (artIds, actIds, mmIds string, err error) {
  396. o := orm.NewOrm()
  397. artSql := `SELECT GROUP_CONCAT(DISTINCT art.article_id SEPARATOR ',') AS art_ids FROM cygx_article as art `
  398. actSql := ` SELECT GROUP_CONCAT(DISTINCT act.activity_id SEPARATOR ',') AS act_ids FROM cygx_activity as act `
  399. mmSql := ` SELECT GROUP_CONCAT(DISTINCT mmc.id SEPARATOR ',') AS mm_ids FROM cygx_morning_meeting_review_chapter as mmc `
  400. for _, s := range industriesCondSlice {
  401. if s != "" {
  402. artSql += ` INNER JOIN cygx_industrial_article_group_management AS iam ON iam.article_id = art.article_id
  403. INNER JOIN cygx_industrial_management AS im ON im.industrial_management_id=iam.industrial_management_id `
  404. actSql += ` INNER JOIN cygx_industrial_activity_group_management AS iam ON iam.activity_id = act.activity_id
  405. INNER JOIN cygx_industrial_management AS im ON im.industrial_management_id=iam.industrial_management_id `
  406. mmSql += ` INNER JOIN cygx_morning_meeting_reviews AS mm ON mmc.meeting_id = mm.id
  407. INNER JOIN cygx_industrial_management AS im ON im.industrial_management_id=mmc.industry_id `
  408. break
  409. }
  410. }
  411. for _, s := range subjectNamesSlice {
  412. if s != "" {
  413. artSql += ` INNER JOIN cygx_industrial_article_group_subject AS ias ON ias.article_id = art.article_id
  414. INNER JOIN cygx_industrial_subject AS cis ON cis.industrial_subject_id=ias.industrial_subject_id `
  415. actSql += ` INNER JOIN cygx_industrial_activity_group_subject AS ias ON ias.activity_id = act.activity_id
  416. INNER JOIN cygx_industrial_subject AS cis ON cis.industrial_subject_id=ias.industrial_subject_id `
  417. mmSql += ` IINNER JOIN cygx_morning_meeting_reviews AS mm ON mmc.meeting_id = mm.id
  418. INNER JOIN cygx_industrial_subject AS cis ON cis.industrial_subject_id=mmc.industrial_subject_ids `
  419. break
  420. }
  421. }
  422. artSql += ` WHERE 1=1 AND ((1=1 `
  423. actSql += ` WHERE 1=1 AND ((1=1 `
  424. mmSql += ` WHERE 1=1 AND ((1=1 `
  425. var isNeedArt, isNeedAct, isNeedMm bool
  426. for i, _ := range articleTypeCondSlice {
  427. articleTypesCond := articleTypeCondSlice[i]
  428. activityTypesCond := activityTypesCondSlice[i]
  429. industryStr := industriesCondSlice[i]
  430. subjectNameStr := subjectNamesSlice[i]
  431. articleTypeStr := articleTypeSlice[i]
  432. if articleTypesCond != "" || (articleTypesCond == "" && activityTypesCond == "") {
  433. if industryStr != "" && subjectNameStr != "" {
  434. artSql += articleTypesCond + ` AND (im.industry_name In (` + industryStr + `) OR cis.subject_name In (` + subjectNameStr + `) )`
  435. } else if industryStr == "" && subjectNameStr != "" {
  436. artSql += articleTypesCond + ` AND cis.subject_name In (` + subjectNameStr + `) `
  437. } else if industryStr != "" && subjectNameStr == "" {
  438. artSql += articleTypesCond + ` AND im.industry_name In (` + industryStr + `) `
  439. } else {
  440. artSql += articleTypesCond
  441. }
  442. if i == len(articleTypeCondSlice)-1 {
  443. artSql += `)) `
  444. } else {
  445. artSql += `) OR (1=1 `
  446. }
  447. isNeedArt = true
  448. }
  449. if activityTypesCond != "" || (articleTypesCond == "" && activityTypesCond == "") {
  450. if industryStr != "" && subjectNameStr != "" {
  451. actSql += activityTypesCond + ` AND (im.industry_name In (` + industryStr + `) OR cis.subject_name In (` + subjectNameStr + `) )`
  452. } else if industryStr == "" && subjectNameStr != "" {
  453. actSql += activityTypesCond + ` AND cis.subject_name In (` + subjectNameStr + `) `
  454. } else if industryStr != "" && subjectNameStr == "" {
  455. actSql += activityTypesCond + ` AND im.industry_name In (` + industryStr + `) `
  456. } else {
  457. actSql += activityTypesCond
  458. }
  459. if i == len(articleTypeCondSlice)-1 {
  460. actSql += `)) `
  461. } else {
  462. actSql += `) OR (1=1 `
  463. }
  464. isNeedAct = true
  465. }
  466. if strings.Contains(articleTypeStr, "晨会精华") {
  467. if industryStr != "" && subjectNameStr != "" {
  468. mmSql += ` AND (im.industry_name In (` + industryStr + `) OR cis.subject_name In (` + subjectNameStr + `) )`
  469. } else if industryStr == "" && subjectNameStr != "" {
  470. mmSql += ` AND cis.subject_name In (` + subjectNameStr + `) `
  471. } else if industryStr != "" && subjectNameStr == "" {
  472. mmSql += ` AND im.industry_name In (` + industryStr + `) `
  473. }
  474. if i == len(articleTypeCondSlice)-1 {
  475. mmSql += `)) `
  476. } else {
  477. mmSql += `) OR (1=1 `
  478. }
  479. isNeedMm = true
  480. }
  481. }
  482. if isNeedArt {
  483. err = o.Raw(artSql).QueryRow(&artIds)
  484. if err != nil {
  485. return
  486. }
  487. }
  488. if isNeedAct {
  489. err = o.Raw(actSql).QueryRow(&actIds)
  490. if err != nil {
  491. return
  492. }
  493. }
  494. if isNeedMm {
  495. err = o.Raw(mmSql).QueryRow(&mmIds)
  496. if err != nil {
  497. return
  498. }
  499. }
  500. return
  501. }
  502. // 列表
  503. func GetCygxCygxArticleIdList(condition string, pars []interface{}) (items []*CygxArticle, err error) {
  504. o := orm.NewOrm()
  505. sql := `SELECT article_id FROM cygx_article as art WHERE 1= 1 `
  506. if condition != "" {
  507. sql += condition
  508. }
  509. _, err = o.Raw(sql, pars).QueryRows(&items)
  510. return
  511. }
  512. type ArticleDetailResultApi struct {
  513. Data ArticleResultApidate `json:"data"`
  514. Code int `json:"code"`
  515. Msg string `json:"msg"`
  516. }
  517. type ArticleResultApidate struct {
  518. ArticleId int `json:"id"`
  519. Title string `json:"title"`
  520. File string `json:"file"`
  521. TitleEn string `json:"title_en"`
  522. Frequency string `json:"frequency"`
  523. CreateDate string `json:"create_date"`
  524. UpdateDate string `json:"update_date"`
  525. PublishDate time.Time `json:"publish_date"`
  526. PublishStatus int `json:"publish_status"`
  527. IndustrId int `json:"industry_id"`
  528. SeriesId int `json:"series_id"`
  529. Series ArticleSeries `json:"series"`
  530. Content ArticleResultApiContent `json:"content"`
  531. Author ArticleResultApiAuthor `json:"author"`
  532. Industry ArticleResultApiIndustry `json:"industry"`
  533. Type ArticleResultApiType `json:"type"`
  534. Stock []string `json:"stock"`
  535. Field ArticleField `json:"field"`
  536. Corpus Corpus `json:"corpus"`
  537. Cover string `json:"cover"`
  538. TypeId int `json:"type_id"`
  539. IsActive bool `json:"is_active"`
  540. }
  541. type ArticleSeries struct {
  542. Name string `json:"name"`
  543. }
  544. type ArticleResultApiContent struct {
  545. ArticleId int `json:"id"`
  546. Body string `json:"body"`
  547. Abstract string `json:"abstract"`
  548. Annotation string `json:"annotation"`
  549. }
  550. type ArticleResultApiAuthor struct {
  551. PhoneNumber string `json:"phone_number"`
  552. Name string `json:"name"`
  553. }
  554. type ArticleResultApiIndustry struct {
  555. Name string `json:"name"`
  556. }
  557. type ArticleResultApiType struct {
  558. Name string `json:"name"`
  559. }
  560. type ArticleField struct {
  561. Id int `json:"id"`
  562. Name string `json:"name"`
  563. Description string `json:"description"`
  564. IndustryId int `json:"industry_id"`
  565. }
  566. type Corpus struct {
  567. Id int `json:"id"`
  568. ArticleId int `json:"article_id"`
  569. Corpus string `json:"corpus"`
  570. }