Commit 0a18d50b authored by jiaorz's avatar jiaorz

修改出车bug

parent f5072981
...@@ -20,4 +20,14 @@ public class RandomListDto { ...@@ -20,4 +20,14 @@ public class RandomListDto {
*/ */
private Integer location; private Integer location;
/**
* 新闻类型
*/
private Integer newsType;
/**
* 新闻id
*/
private Integer newsId;
} }
...@@ -77,18 +77,18 @@ public class ArticleBiz extends BaseBiz<ArticleMapper, Article> { ...@@ -77,18 +77,18 @@ public class ArticleBiz extends BaseBiz<ArticleMapper, Article> {
* @param id * @param id
* @return * @return
*/ */
public List getThree( Integer type,Integer id) { public List getThree( Integer type, Integer number, Integer id) {
number = number == null ? RANDOM_NUMBER : number;
List<Article> articleList = mapper.getArticleList(type,null,id); List<Article> articleList = mapper.getArticleList(type,null,id);
if (!Objects.isNull(articleList)) { if (!Objects.isNull(articleList)) {
int size = articleList.size(); int size = articleList.size();
if (RANDOM_NUMBER >= size) { if (number >= size) {
return articleList; return articleList;
} else { } else {
Random random = new Random(); Random random = new Random();
int r = random.nextInt(size - RANDOM_NUMBER + 1); int r = random.nextInt(size - number + 1);
List<Article> result = new ArrayList<>(); List<Article> result = new ArrayList<>();
for (int i = 0; i < RANDOM_NUMBER.intValue(); i++) { for (int i = 0; i < number.intValue(); i++) {
int index = i + r; int index = i + r;
result.add(articleList.get(index)); result.add(articleList.get(index));
} }
......
...@@ -37,7 +37,7 @@ public class RandomListBiz { ...@@ -37,7 +37,7 @@ public class RandomListBiz {
* @param number 随机数,默认是2 * @param number 随机数,默认是2
* @return * @return
*/ */
public ObjectRestResponse getRandomList(Integer type, Integer number, Integer location) { public ObjectRestResponse getRandomList(Integer type, Integer number, Integer location, Integer id, Integer newsType) {
if(type != null) { if(type != null) {
number = number == null ? 2 : number; number = number == null ? 2 : number;
switch (TypeEnum.getByValue(type)) { switch (TypeEnum.getByValue(type)) {
...@@ -50,7 +50,7 @@ public class RandomListBiz { ...@@ -50,7 +50,7 @@ public class RandomListBiz {
case ACTIVITY: case ACTIVITY:
return ObjectRestResponse.succ(summitActivityBiz.getHostWithSummitActivity(number, location)); return ObjectRestResponse.succ(summitActivityBiz.getHostWithSummitActivity(number, location));
case NEWS: case NEWS:
return ObjectRestResponse.succ(articleBiz.getThree(type, number, id));
} }
} }
return ObjectRestResponse.succ(); return ObjectRestResponse.succ();
......
...@@ -19,7 +19,7 @@ public class RandomListController { ...@@ -19,7 +19,7 @@ public class RandomListController {
if(randomListDto == null) { if(randomListDto == null) {
return ObjectRestResponse.paramIsEmpty(); return ObjectRestResponse.paramIsEmpty();
} }
return randomListBiz.getRandomList(randomListDto.getType(), randomListDto.getNumber(), randomListDto.getLocation()); return randomListBiz.getRandomList(randomListDto.getType(), randomListDto.getNumber(), randomListDto.getLocation(), randomListDto.getNewsId(), randomListDto.getNewsType());
} }
} }
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