article.go 24 KB

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