增加搜索接口
This commit is contained in:
parent
41ba4227e9
commit
85bb0630b6
|
|
@ -1,8 +1,11 @@
|
|||
package com.mdd.front.controller;
|
||||
|
||||
import com.mdd.common.core.AjaxResult;
|
||||
import com.mdd.common.core.PageResult;
|
||||
import com.mdd.common.validator.annotation.IDMust;
|
||||
import com.mdd.front.service.IIndexService;
|
||||
import com.mdd.front.validate.PageParam;
|
||||
import com.mdd.front.vo.article.ArticleListVo;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
|
@ -79,9 +82,22 @@ public class IndexController {
|
|||
* @author fzr
|
||||
* @return Object
|
||||
*/
|
||||
@GetMapping("/hotSearch")
|
||||
public Object hotSearch() {
|
||||
List<String> list = iIndexService.hotSearch();
|
||||
return AjaxResult.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索
|
||||
*
|
||||
* @author fzr
|
||||
* @return Object
|
||||
*/
|
||||
@GetMapping("/search")
|
||||
public Object search() {
|
||||
List<String> list = iIndexService.search();
|
||||
public Object search(@Validated PageParam pageParam,
|
||||
@RequestParam Map<String, String> params) {
|
||||
PageResult<ArticleListVo> list = iIndexService.search(pageParam, params);
|
||||
return AjaxResult.success(list);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,9 @@
|
|||
package com.mdd.front.service;
|
||||
|
||||
import com.mdd.common.core.PageResult;
|
||||
import com.mdd.front.validate.PageParam;
|
||||
import com.mdd.front.vo.article.ArticleListVo;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
|
@ -47,6 +51,15 @@ public interface IIndexService {
|
|||
* @author fzr
|
||||
* @return List<String>
|
||||
*/
|
||||
List<String> search();
|
||||
List<String> hotSearch();
|
||||
|
||||
/**
|
||||
* 搜索
|
||||
*
|
||||
* @author fzr
|
||||
* @param pageParam 分页参数
|
||||
* @param params 搜索参数
|
||||
* @return PageResult<ArticleListVo>
|
||||
*/
|
||||
PageResult<ArticleListVo> search(PageParam pageParam, Map<String, String> params);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,12 @@
|
|||
package com.mdd.front.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Assert;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.github.yulichang.query.MPJQueryWrapper;
|
||||
import com.mdd.common.config.GlobalConfig;
|
||||
import com.mdd.common.core.PageResult;
|
||||
import com.mdd.common.entity.article.Article;
|
||||
import com.mdd.common.entity.decorate.DecoratePage;
|
||||
import com.mdd.common.entity.decorate.DecorateTabbar;
|
||||
|
|
@ -13,6 +17,8 @@ import com.mdd.common.mapper.decorate.DecorateTabbarMapper;
|
|||
import com.mdd.common.mapper.setting.HotSearchMapper;
|
||||
import com.mdd.common.utils.*;
|
||||
import com.mdd.front.service.IIndexService;
|
||||
import com.mdd.front.validate.PageParam;
|
||||
import com.mdd.front.vo.article.ArticleListVo;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
|
@ -176,7 +182,7 @@ public class IndexServiceImpl implements IIndexService {
|
|||
* @return List<String>
|
||||
*/
|
||||
@Override
|
||||
public List<String> search() {
|
||||
public List<String> hotSearch() {
|
||||
String isHotSearch = ConfigUtil.get("search", "isHotSearch", "0");
|
||||
|
||||
List<String> list = new LinkedList<>();
|
||||
|
|
@ -193,4 +199,38 @@ public class IndexServiceImpl implements IIndexService {
|
|||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索
|
||||
*
|
||||
* @author fzr
|
||||
* @param pageParam 分页参数
|
||||
* @param params 搜索参数
|
||||
* @return PageResult<ArticleListVo>
|
||||
*/
|
||||
public PageResult<ArticleListVo> search(PageParam pageParam, Map<String, String> params) {
|
||||
Integer pageNo = pageParam.getPageNo();
|
||||
Integer pageSize = pageParam.getPageSize();
|
||||
|
||||
MPJQueryWrapper<Article> mpjQueryWrapper = new MPJQueryWrapper<Article>()
|
||||
.selectAll(Article.class)
|
||||
.select("ac.name as category")
|
||||
.innerJoin("?_article_category ac ON ac.id=t.cid".replace("?_", GlobalConfig.tablePrefix))
|
||||
.eq("t.is_delete", 0)
|
||||
.like("t.title", params.get("keyword"))
|
||||
.orderByDesc(Arrays.asList("t.sort", "t.id"));
|
||||
|
||||
IPage<ArticleListVo> iPage = articleMapper.selectJoinPage(
|
||||
new Page<>(pageNo, pageSize),
|
||||
ArticleListVo.class,
|
||||
mpjQueryWrapper);
|
||||
|
||||
for (ArticleListVo vo : iPage.getRecords()) {
|
||||
vo.setCollect(false);
|
||||
vo.setImage(UrlUtil.toAbsoluteUrl(vo.getImage()));
|
||||
vo.setCreateTime(TimeUtil.timestampToDate(vo.getCreateTime()));
|
||||
}
|
||||
|
||||
return PageResult.iPageHandle(iPage);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue