article.go 23 KB

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