article.go 24 KB

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