Commit ae1a9b36 by Lem

PC首页资讯

parent 8b4d0ec0
package com.live.common.domain.dto.api;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class GetArticleListByPCResponse {
private String tagName;
private List<GetArticleListByPCInfo> articles;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public static class GetArticleListByPCInfo {
private Integer id;
private String title;
}
}
...@@ -47,6 +47,9 @@ public class Article extends BaseEntity { ...@@ -47,6 +47,9 @@ public class Article extends BaseEntity {
private String tagId; private String tagId;
//0足球 1篮球
private Integer sportsId;
private int fakeLike; private int fakeLike;
} }
...@@ -15,7 +15,7 @@ public enum SystemConfigEnum { ...@@ -15,7 +15,7 @@ public enum SystemConfigEnum {
BASKETBALL_LEAGUE_RANK_COMPETITION("BASKETBALL_LEAGUE_RANK_COMPETITION", "篮球积分榜更新赛事"), BASKETBALL_LEAGUE_RANK_COMPETITION("BASKETBALL_LEAGUE_RANK_COMPETITION", "篮球积分榜更新赛事"),
PC_HOME_ARTICLE("PC_HOME_ARTICLE", "PC首页资讯类型ID"),
; ;
@Getter @Getter
......
...@@ -14,6 +14,8 @@ public interface ArticleService { ...@@ -14,6 +14,8 @@ public interface ArticleService {
ResponseData<?> getArticleType(); ResponseData<?> getArticleType();
ResponseData<?> getArticleListByPC(HttpServletRequest request);
ResponseData<?> getTopArticleList(HttpServletRequest request); ResponseData<?> getTopArticleList(HttpServletRequest request);
ResponseData<?> getArticleListByTagId(ArticleByTagIdRequest tagIdRequest, HttpServletRequest request); ResponseData<?> getArticleListByTagId(ArticleByTagIdRequest tagIdRequest, HttpServletRequest request);
......
...@@ -14,6 +14,7 @@ import com.live.common.domain.request.*; ...@@ -14,6 +14,7 @@ import com.live.common.domain.request.*;
import com.live.common.domain.request.back.ArticleListRequest; import com.live.common.domain.request.back.ArticleListRequest;
import com.live.common.domain.request.back.EditArticleInfoRequest; import com.live.common.domain.request.back.EditArticleInfoRequest;
import com.live.common.enums.StatusEnum; import com.live.common.enums.StatusEnum;
import com.live.common.enums.SystemConfigEnum;
import com.live.common.mapper.*; import com.live.common.mapper.*;
import com.live.common.service.ArticleService; import com.live.common.service.ArticleService;
import com.live.common.service.RedisUtilsService; import com.live.common.service.RedisUtilsService;
...@@ -50,6 +51,8 @@ public class ArticleServiceImpl implements ArticleService { ...@@ -50,6 +51,8 @@ public class ArticleServiceImpl implements ArticleService {
private RedisUtilsService redisUtilsService; private RedisUtilsService redisUtilsService;
@Resource @Resource
private ArticleLikeMapper articleLikeMapper; private ArticleLikeMapper articleLikeMapper;
@Resource
private SystemConfigMapper systemConfigMapper;
@Override @Override
public ResponseData<?> getArticleTopTagList() { public ResponseData<?> getArticleTopTagList() {
...@@ -89,6 +92,93 @@ public class ArticleServiceImpl implements ArticleService { ...@@ -89,6 +92,93 @@ public class ArticleServiceImpl implements ArticleService {
} }
@Override @Override
public ResponseData<?> getArticleListByPC(HttpServletRequest request) {
List<SystemConfig> systemConfigs = systemConfigMapper.selectList(Wrappers.<SystemConfig>lambdaQuery()
.eq(SystemConfig::getConfigName, SystemConfigEnum.PC_HOME_ARTICLE.getTitle())
.eq(SystemConfig::getDeleted, 0)
);
List<GetArticleListByPCResponse> articleResponses = new LinkedList<>();
for (SystemConfig config : systemConfigs) {
Tag tag = tagMapper.selectById(config.getConfigValue());
if (tag == null)
continue;
QueryWrapper<Article> wrapper = new QueryWrapper<>();
wrapper.eq("deleted", StatusEnum.ENABLE.getCode());
wrapper.eq("content_type", 0);
wrapper.apply("FIND_IN_SET({0},tag_id)", config.getConfigValue());
wrapper.orderByDesc("create_time");
wrapper.last(String.format(" limit %s,%s", 0, 10));
List<Article> articles = articleMapper.selectList(wrapper);
articleResponses.add(GetArticleListByPCResponse.builder()
.tagName(tag.getTagName())
.articles(articles.stream().map(b -> GetArticleListByPCResponse.
GetArticleListByPCInfo.builder()
.id(b.getId())
.title(b.getTitle())
.build()).collect(Collectors.toList()))
.build());
}
//足球
QueryWrapper<Article> wrapper = new QueryWrapper<>();
wrapper.eq("deleted", StatusEnum.ENABLE.getCode());
wrapper.eq("content_type", 0);
wrapper.eq("sports_id", 0);
wrapper.orderByDesc("create_time");
wrapper.last(String.format(" limit %s,%s", 0, 10));
List<Article> articles = articleMapper.selectList(wrapper);
articleResponses.add(GetArticleListByPCResponse.builder()
.tagName("足球")
.articles(articles.stream().map(b -> GetArticleListByPCResponse.
GetArticleListByPCInfo.builder()
.id(b.getId())
.title(b.getTitle())
.build()).collect(Collectors.toList()))
.build());
//篮球
wrapper = new QueryWrapper<>();
wrapper.eq("deleted", StatusEnum.ENABLE.getCode());
wrapper.eq("content_type", 0);
wrapper.eq("sports_id", 1);
wrapper.orderByDesc("create_time");
wrapper.last(String.format(" limit %s,%s", 0, 10));
articles = articleMapper.selectList(wrapper);
articleResponses.add(GetArticleListByPCResponse.builder()
.tagName("篮球")
.articles(articles.stream().map(b -> GetArticleListByPCResponse.
GetArticleListByPCInfo.builder()
.id(b.getId())
.title(b.getTitle())
.build()).collect(Collectors.toList()))
.build());
//热门
wrapper = new QueryWrapper<>();
wrapper.eq("deleted", StatusEnum.ENABLE.getCode());
wrapper.eq("content_type", 0);
wrapper.eq("hot_news", 1);
wrapper.orderByDesc("create_time");
wrapper.last(String.format(" limit %s,%s", 0, 10));
articles = articleMapper.selectList(wrapper);
articleResponses.add(GetArticleListByPCResponse.builder()
.tagName("热门")
.articles(articles.stream().map(b -> GetArticleListByPCResponse.
GetArticleListByPCInfo.builder()
.id(b.getId())
.title(b.getTitle())
.build()).collect(Collectors.toList()))
.build());
return ResponseData.successResponse(articleResponses);
}
@Override
public ResponseData<?> getTopArticleList(HttpServletRequest request) { public ResponseData<?> getTopArticleList(HttpServletRequest request) {
List<Article> articles = articleMapper.selectList(Wrappers.<Article>lambdaQuery() List<Article> articles = articleMapper.selectList(Wrappers.<Article>lambdaQuery()
.eq(Article::getDeleted, StatusEnum.ENABLE.getCode()) .eq(Article::getDeleted, StatusEnum.ENABLE.getCode())
...@@ -423,7 +513,7 @@ public class ArticleServiceImpl implements ArticleService { ...@@ -423,7 +513,7 @@ public class ArticleServiceImpl implements ArticleService {
@Override @Override
public ResponseData<?> articleSearch(ArticleSearchRequest commonPage, HttpServletRequest request) { public ResponseData<?> articleSearch(ArticleSearchRequest commonPage, HttpServletRequest request) {
if(StringUtils.isBlank(commonPage.getSearchContent())) if (StringUtils.isBlank(commonPage.getSearchContent()))
return ResponseData.fail400Response("请输入搜索内容"); return ResponseData.fail400Response("请输入搜索内容");
int jumpNum = (commonPage.getPageNum() - 1) * commonPage.getPageSize(); int jumpNum = (commonPage.getPageNum() - 1) * commonPage.getPageSize();
...@@ -469,7 +559,7 @@ public class ArticleServiceImpl implements ArticleService { ...@@ -469,7 +559,7 @@ public class ArticleServiceImpl implements ArticleService {
public ResponseData<?> collectArticle(CommonIntId commonIntId, int type, HttpServletRequest request) { public ResponseData<?> collectArticle(CommonIntId commonIntId, int type, HttpServletRequest request) {
try { try {
Article article = articleMapper.selectById(commonIntId.getId()); Article article = articleMapper.selectById(commonIntId.getId());
if(article == null) if (article == null)
return ResponseData.fail400Response("文章不存在"); return ResponseData.fail400Response("文章不存在");
String phone = CommonMethod.getUserPhone(request); String phone = CommonMethod.getUserPhone(request);
...@@ -477,13 +567,13 @@ public class ArticleServiceImpl implements ArticleService { ...@@ -477,13 +567,13 @@ public class ArticleServiceImpl implements ArticleService {
.eq(User::getPhone, phone) .eq(User::getPhone, phone)
); );
if(type == 0) { if (type == 0) {
userReserveMapper.insert(UserReserve.builder() userReserveMapper.insert(UserReserve.builder()
.userId(account.getId()) .userId(account.getId())
.matchId(String.valueOf(article.getId())) .matchId(String.valueOf(article.getId()))
.type(2) .type(2)
.build()); .build());
} else if(type == 1){ } else if (type == 1) {
userReserveMapper.delete(Wrappers.<UserReserve>lambdaQuery() userReserveMapper.delete(Wrappers.<UserReserve>lambdaQuery()
.eq(UserReserve::getUserId, account.getId()) .eq(UserReserve::getUserId, account.getId())
.eq(UserReserve::getType, 2) .eq(UserReserve::getType, 2)
......
...@@ -13,7 +13,7 @@ public interface CrawlMatchService { ...@@ -13,7 +13,7 @@ public interface CrawlMatchService {
void crawlMatchStageScore(String url); void crawlMatchStageScore(String url);
void crawlScheduleArticle(String url); void crawlScheduleArticle(String url, Integer sportsId);
void updateMatchList(); void updateMatchList();
......
...@@ -155,13 +155,13 @@ public class ScheduledService { ...@@ -155,13 +155,13 @@ public class ScheduledService {
.build()); .build());
crawStrategyFactory.getCrawMatchService(CrawlPlatformEnum.ARTICLE24BWZ.getCode()) crawStrategyFactory.getCrawMatchService(CrawlPlatformEnum.ARTICLE24BWZ.getCode())
.crawlScheduleArticle("https://www.24zbw.com/news/lanqiu/"); .crawlScheduleArticle("https://www.24zbw.com/news/lanqiu/", 1);
taskScheduler.schedule(() -> crawStrategyFactory.getCrawMatchService(CrawlPlatformEnum.ARTICLE24BWZ.getCode()) taskScheduler.schedule(() -> crawStrategyFactory.getCrawMatchService(CrawlPlatformEnum.ARTICLE24BWZ.getCode())
.crawlScheduleArticle("https://www.24zbw.com/news/zuqiu/"), Instant.now().plusSeconds(2 * 60)); .crawlScheduleArticle("https://www.24zbw.com/news/zuqiu/", 0), Instant.now().plusSeconds(2 * 60));
taskScheduler.schedule(() -> crawStrategyFactory.getCrawMatchService(CrawlPlatformEnum.ARTICLE24BWZ.getCode()) taskScheduler.schedule(() -> crawStrategyFactory.getCrawMatchService(CrawlPlatformEnum.ARTICLE24BWZ.getCode())
.crawlScheduleArticle("https://www.24zbw.com/news/tag/shenshuiqu/"), Instant.now().plusSeconds(4 * 60)); .crawlScheduleArticle("https://www.24zbw.com/news/tag/shenshuiqu/", null), Instant.now().plusSeconds(4 * 60));
} }
// /** // /**
......
...@@ -68,7 +68,7 @@ public class Crawl24ZBWServiceImpl implements CrawlMatchService { ...@@ -68,7 +68,7 @@ public class Crawl24ZBWServiceImpl implements CrawlMatchService {
} }
@Override @Override
public void crawlScheduleArticle(String jUrl) { public void crawlScheduleArticle(String jUrl, Integer sportsId) {
try { try {
Map<String, TemporarilyInfo> coverMap = new HashMap<>(); Map<String, TemporarilyInfo> coverMap = new HashMap<>();
for (int i = 1; i < 51; i++) { for (int i = 1; i < 51; i++) {
...@@ -110,7 +110,7 @@ public class Crawl24ZBWServiceImpl implements CrawlMatchService { ...@@ -110,7 +110,7 @@ public class Crawl24ZBWServiceImpl implements CrawlMatchService {
threadPoolExecutor.execute(() -> { threadPoolExecutor.execute(() -> {
try { try {
dealWithPcInfo(infoUrl, coverMap.get(infoUrl)); dealWithPcInfo(infoUrl, coverMap.get(infoUrl), sportsId);
} catch (IOException e) { } catch (IOException e) {
log.error("爬取失败链接:{} errorInfo:{}", infoUrl, e.getMessage()); log.error("爬取失败链接:{} errorInfo:{}", infoUrl, e.getMessage());
} }
...@@ -121,7 +121,7 @@ public class Crawl24ZBWServiceImpl implements CrawlMatchService { ...@@ -121,7 +121,7 @@ public class Crawl24ZBWServiceImpl implements CrawlMatchService {
} }
} }
private void dealWithPcInfo(String url, TemporarilyInfo temporarilyInfo) throws RuntimeException, IOException { private void dealWithPcInfo(String url, TemporarilyInfo temporarilyInfo, Integer sportsId) throws RuntimeException, IOException {
Document doc = Jsoup.connect(url) Document doc = Jsoup.connect(url)
.timeout(30000) .timeout(30000)
.userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36") .userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36")
...@@ -214,6 +214,7 @@ public class Crawl24ZBWServiceImpl implements CrawlMatchService { ...@@ -214,6 +214,7 @@ public class Crawl24ZBWServiceImpl implements CrawlMatchService {
.tagId(tagId.toString()) .tagId(tagId.toString())
.createTime(new Date()) .createTime(new Date())
.contentType(contentType) .contentType(contentType)
.sportsId(sportsId)
.releaseTime(DateUtil.parse(temporarilyInfo.getReleaseTime(), DateUtil.YMDHM_)) .releaseTime(DateUtil.parse(temporarilyInfo.getReleaseTime(), DateUtil.YMDHM_))
.fakeLike(IdGen.generatorNum(30, 900)) .fakeLike(IdGen.generatorNum(30, 900))
.build()); .build());
......
...@@ -1675,7 +1675,7 @@ public class CrawlAlStatServiceImpl implements CrawlMatchService { ...@@ -1675,7 +1675,7 @@ public class CrawlAlStatServiceImpl implements CrawlMatchService {
} }
@Override @Override
public void crawlScheduleArticle(String Url) { public void crawlScheduleArticle(String Url, Integer sportsId) {
} }
@Override @Override
......
...@@ -146,7 +146,7 @@ public class CrawlSequoiaServiceImpl implements CrawlMatchService { ...@@ -146,7 +146,7 @@ public class CrawlSequoiaServiceImpl implements CrawlMatchService {
} }
@Override @Override
public void crawlScheduleArticle(String url) { public void crawlScheduleArticle(String url, Integer sportsId) {
} }
......
...@@ -148,7 +148,7 @@ public class CrawlSportLive360ServiceImpl implements CrawlMatchService { ...@@ -148,7 +148,7 @@ public class CrawlSportLive360ServiceImpl implements CrawlMatchService {
} }
@Override @Override
public void crawlScheduleArticle(String url) { public void crawlScheduleArticle(String url, Integer sportsId) {
} }
......
...@@ -143,7 +143,7 @@ public class CrawlUUQiuServiceImpl implements CrawlMatchService { ...@@ -143,7 +143,7 @@ public class CrawlUUQiuServiceImpl implements CrawlMatchService {
} }
@Override @Override
public void crawlScheduleArticle(String url) { public void crawlScheduleArticle(String url, Integer sportsId) {
} }
......
...@@ -43,7 +43,9 @@ public class IntercaptorConfig implements WebMvcConfigurer { ...@@ -43,7 +43,9 @@ public class IntercaptorConfig implements WebMvcConfigurer {
"/article/getTopArticleList", "/article/getTopArticleList",
"/article/getArticleListByTagId", "/article/getArticleListByTagId",
"/article/getArticleInfoById", "/article/getArticleInfoById",
"/article/articleSearch") "/article/articleSearch",
"/article/getArticleListByPC"
)
; ;
} }
......
...@@ -47,6 +47,19 @@ public class ArticleController { ...@@ -47,6 +47,19 @@ public class ArticleController {
return articleService.getArticleType(); return articleService.getArticleType();
} }
@GetMapping(value = "/getArticleListByPC")
@ApiOperation(value = "PC获取首页")
@ApiResponses({
@ApiResponse(code = 200, message = "成功处理请求"),
@ApiResponse(code = 401, message = "没有权限访问该服务"),
@ApiResponse(code = 403, message = "权限不足无法访问该服务"),
@ApiResponse(code = 404, message = "未发现该服务"),
@ApiResponse(code = 500, message = "服务器内部错误")
})
public ResponseData<?> getArticleListByPC(HttpServletRequest request) {
return articleService.getArticleListByPC(request);
}
@GetMapping(value = "/getTopArticleList") @GetMapping(value = "/getTopArticleList")
@ApiOperation(value = "获取资讯首页头部轮播文章") @ApiOperation(value = "获取资讯首页头部轮播文章")
@ApiResponses({ @ApiResponses({
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment