article.go 24 KB

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