feat(分页功能增强): 处理CMS微服务中文章相关接口

This commit is contained in:
OTTO 2023-12-18 09:51:46 +08:00
parent f71e934f7c
commit a13fed47af
3 changed files with 42 additions and 54 deletions

View File

@ -24,22 +24,18 @@ import java.util.List;
*
* @author ruoyi
*/
public class BaseController
{
public class BaseController {
protected final Logger logger = LoggerFactory.getLogger(this.getClass());
/**
* 将前台传递过来的日期格式的字符串自动转化为Date类型
*/
@InitBinder
public void initBinder(WebDataBinder binder)
{
public void initBinder(WebDataBinder binder) {
// Date 类型转换
binder.registerCustomEditor(Date.class, new PropertyEditorSupport()
{
binder.registerCustomEditor(Date.class, new PropertyEditorSupport() {
@Override
public void setAsText(String text)
{
public void setAsText(String text) {
setValue(DateUtils.parseDate(text));
}
});
@ -48,16 +44,14 @@ public class BaseController
/**
* 设置请求分页数据
*/
protected void startPage()
{
protected void startPage() {
PageUtils.startPage();
}
/**
* 清理分页的线程变量
*/
protected void clearPage()
{
protected void clearPage() {
PageUtils.clearPage();
}
@ -103,9 +97,8 @@ public class BaseController
/**
* 响应请求分页数据
*/
@SuppressWarnings({"rawtypes", "unchecked"})
protected TableDataInfo getAllDataTableToPage(List<?> list) {
TableDataInfo rspData = new TableDataInfo();
protected <T> GenericsTableDataInfo<T> getAllGenericsDataTableToPage(List<T> list) {
GenericsTableDataInfo<T> rspData = new GenericsTableDataInfo<>();
rspData.setCode(HttpStatus.SUCCESS);
int total = list.size();
rspData.setTotal(total);
@ -113,12 +106,12 @@ public class BaseController
if (StringUtils.isNotEmpty(orderByStr)) {
String isAscStr = ServletUtils.getParameter(Constants.IS_ASC);
if (StringUtils.isNotEmpty(orderByStr)) {
String ASCString = "asc";
String ascString = "asc";
boolean isAsc = true;
if (isAscStr != null && !ASCString.equals(isAscStr.toLowerCase())) {
if (isAscStr != null && !ascString.equals(isAscStr.toLowerCase())) {
isAsc = false;
}
list = SortUtils.sort(list, orderByStr, isAsc);
SortUtils.sort(list, orderByStr, isAsc);
}
}
if (StringUtils.isNotEmpty(ServletUtils.getParameter(Constants.PAGE_NUM))
@ -150,13 +143,11 @@ public class BaseController
}
list = list.subList(startIndex, endIndex);
}
//todo:暂不考虑 Boolean reasonable = pageDomain.getReasonable();
//todo:暂不考虑 Boolean reasonable = pageDomain.getReasonable();
}
rspData.setRows(list);
rspData.setMsg("查询成功");
return rspData;
}
@ -183,16 +174,14 @@ public class BaseController
/**
* 返回成功消息
*/
public AjaxResult success(String message)
{
public AjaxResult success(String message) {
return AjaxResult.success(message);
}
/**
* 返回成功消息
*/
public AjaxResult success(Object data)
{
public AjaxResult success(Object data) {
return AjaxResult.success(data);
}
@ -206,24 +195,21 @@ public class BaseController
/**
* 返回失败消息
*/
public AjaxResult error()
{
public AjaxResult error() {
return AjaxResult.error();
}
/**
* 返回失败消息
*/
public AjaxResult error(String message)
{
public AjaxResult error(String message) {
return AjaxResult.error(message);
}
/**
* 返回警告消息
*/
public AjaxResult warn(String message)
{
public AjaxResult warn(String message) {
return AjaxResult.warn(message);
}

View File

@ -5,6 +5,7 @@ import com.ruoyi.cms.doc.service.ICmsDocService;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.GenericsTableDataInfo;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
@ -42,10 +43,10 @@ public class CmsDocController extends BaseController {
@ApiImplicitParam(name = "orderByColumn", value = "排序列", paramType = "query", dataType = "String"),
@ApiImplicitParam(name = "isAsc", value = "排序的方向desc或者asc,默认asc", paramType = "query", dataType = "String")
})
public TableDataInfo dirList(@ApiParam(name = "zoneId", value = "专区Id") @PathVariable("zoneId") Long zoneId) {
public GenericsTableDataInfo<CmsDir> dirList(@ApiParam(name = "zoneId", value = "专区Id") @PathVariable("zoneId") Long zoneId) {
Long deptId = cmsDocService.getDeptIdByZoneId(zoneId);
List<CmsDir> list = cmsDocService.selectCmsDocDirList(deptId, false);
return getAllDataTableToPage(list);
return getAllGenericsDataTableToPage(list);
}
/**
@ -60,7 +61,7 @@ public class CmsDocController extends BaseController {
@ApiImplicitParam(name = "orderByColumn", value = "排序列", paramType = "query", dataType = "String"),
@ApiImplicitParam(name = "isAsc", value = "排序的方向desc或者asc,默认asc", paramType = "query", dataType = "String")
})
public TableDataInfo docList(
public GenericsTableDataInfo<CmsDocBaseDto> docList(
@ApiParam(name = "dirId", value = "栏目Id") @PathVariable("dirId") Long dirId
, CmsDocSearchVo cmsDocSearchVo) {
cmsDocSearchVo.setIsOpen(false);
@ -74,7 +75,7 @@ public class CmsDocController extends BaseController {
x.setEditable(editable);
});
return getAllDataTableToPage(list);
return getAllGenericsDataTableToPage(list);
}
/**

View File

@ -6,7 +6,8 @@ import com.ruoyi.cms.doc.service.ICmsDocCommentService;
import com.ruoyi.cms.doc.service.ICmsDocService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.core.web.domain.GenericsAjaxResult;
import com.ruoyi.common.core.web.page.GenericsTableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import io.swagger.annotations.*;
@ -43,10 +44,10 @@ public class OpenController extends BaseController {
@ApiImplicitParam(name = "orderByColumn", value = "排序列", paramType = "query", dataType = "String"),
@ApiImplicitParam(name = "isAsc", value = "排序的方向desc或者asc,默认asc", paramType = "query", dataType = "String")
})
public TableDataInfo dirList(@ApiParam(name = "zoneId", value = "专区Id") @PathVariable("zoneId") Long zoneId) {
public GenericsTableDataInfo<CmsDir> dirList(@ApiParam(name = "zoneId", value = "专区Id") @PathVariable("zoneId") Long zoneId) {
Long deptId = cmsDocService.getDeptIdByZoneId(zoneId);
List<CmsDir> list = cmsDocService.selectCmsDocDirList(deptId, true);
return getAllDataTableToPage(list);
return getAllGenericsDataTableToPage(list);
}
/**
@ -61,11 +62,11 @@ public class OpenController extends BaseController {
@ApiImplicitParam(name = "orderByColumn", value = "排序列", paramType = "query", dataType = "String"),
@ApiImplicitParam(name = "isAsc", value = "排序的方向desc或者asc,默认asc", paramType = "query", dataType = "String")
})
public TableDataInfo docList(@ApiParam(name = "dirId", value = "栏目Id") @PathVariable("dirId") Long dirId
public GenericsTableDataInfo<CmsDocBaseDto> docList(@ApiParam(name = "dirId", value = "栏目Id") @PathVariable("dirId") Long dirId
, CmsDocSearchVo cmsDocSearchVo) {
cmsDocSearchVo.setIsOpen(true);
List<CmsDocBaseDto> list = cmsDocService.selectCmsDocList(dirId, cmsDocSearchVo);
return getAllDataTableToPage(list);
return getAllGenericsDataTableToPage(list);
}
/**
@ -80,9 +81,9 @@ public class OpenController extends BaseController {
@ApiImplicitParam(name = "orderByColumn", value = "排序列", paramType = "query", dataType = "String"),
@ApiImplicitParam(name = "isAsc", value = "排序的方向desc或者asc,默认asc", paramType = "query", dataType = "String")
})
public TableDataInfo docContentList(@ApiParam(name = "dirId", value = "栏目Id") @PathVariable("dirId") Long dirId) {
public GenericsTableDataInfo<CmsDocDetailDto> docContentList(@ApiParam(name = "dirId", value = "栏目Id") @PathVariable("dirId") Long dirId) {
List<CmsDocDetailDto> list = cmsDocService.selectCmsDocDetailList(dirId);
return getAllDataTableToPage(list);
return getAllGenericsDataTableToPage(list);
}
/**
@ -90,10 +91,10 @@ public class OpenController extends BaseController {
*/
@GetMapping("/zone/{zoneId}/docOverviewList")
@ApiOperation("查询文章聚合列表")
public TableDataInfo docOverviewList(@ApiParam(name = "zoneId", value = "专区Id") @PathVariable("zoneId") Long zoneId) {
public GenericsTableDataInfo<CmsDocOverviewDto> docOverviewList(@ApiParam(name = "zoneId", value = "专区Id") @PathVariable("zoneId") Long zoneId) {
Long deptId = cmsDocService.getDeptIdByZoneId(zoneId);
List<CmsDocOverviewDto> list = cmsDocService.selectCmsDocOverviewList(deptId, true);
return getAllDataTableToPage(list);
return getAllGenericsDataTableToPage(list);
}
/**
@ -101,10 +102,10 @@ public class OpenController extends BaseController {
*/
@GetMapping("/zone/{zoneId}/homePageDocList")
@ApiOperation("查询首页文章列表")
public TableDataInfo homePageDocList(@ApiParam(name = "zoneId", value = "专区Id") @PathVariable("zoneId") Long zoneId) {
public GenericsTableDataInfo<CmsDocBaseDto> homePageDocList(@ApiParam(name = "zoneId", value = "专区Id") @PathVariable("zoneId") Long zoneId) {
Long deptId = cmsDocService.getDeptIdByZoneId(zoneId);
List<CmsDocBaseDto> list = cmsDocService.selectHomePageDocList(deptId);
return getAllDataTableToPage(list);
return getAllGenericsDataTableToPage(list);
}
/**
@ -116,9 +117,9 @@ public class OpenController extends BaseController {
@ApiImplicitParam(name = "pageNum", value = "当前记录起始索引", paramType = "query", dataType = "Integer"),
@ApiImplicitParam(name = "pageSize", value = "每页显示记录数", paramType = "query", dataType = "Integer")
})
public TableDataInfo hotDocListByDir(@ApiParam(name = "dirId", value = "栏目Id") @PathVariable("dirId") Long dirId) {
public GenericsTableDataInfo<HotCmsDocDto> hotDocListByDir(@ApiParam(name = "dirId", value = "栏目Id") @PathVariable("dirId") Long dirId) {
List<HotCmsDocDto> list = cmsDocService.selectHotCmsDocList(dirId);
return getAllDataTableToPage(list);
return getAllGenericsDataTableToPage(list);
}
/**
@ -130,10 +131,10 @@ public class OpenController extends BaseController {
@ApiImplicitParam(name = "pageNum", value = "当前记录起始索引", paramType = "query", dataType = "Integer"),
@ApiImplicitParam(name = "pageSize", value = "每页显示记录数", paramType = "query", dataType = "Integer")
})
public TableDataInfo hotDocListByDept(@ApiParam(name = "zoneId", value = "专区Id") @PathVariable("zoneId") Long zoneId) {
public GenericsTableDataInfo<HotCmsDocDto> hotDocListByDept(@ApiParam(name = "zoneId", value = "专区Id") @PathVariable("zoneId") Long zoneId) {
Long deptId = cmsDocService.getDeptIdByZoneId(zoneId);
List<HotCmsDocDto> list = cmsDocService.selectHotCmsDocListByDept(deptId);
return getAllDataTableToPage(list);
return getAllGenericsDataTableToPage(list);
}
/**
@ -141,8 +142,8 @@ public class OpenController extends BaseController {
*/
@ApiOperation("获取文章详细信息")
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@ApiParam(name = "id", value = "文章Id") @PathVariable("id") Long id, HttpServletRequest request) {
return success(cmsDocService.selectCmsDocById(id, true, request));
public GenericsAjaxResult<CmsDocDetailDto> getInfo(@ApiParam(name = "id", value = "文章Id") @PathVariable("id") Long id, HttpServletRequest request) {
return genericsSuccess(cmsDocService.selectCmsDocById(id, true, request));
}
/**
@ -150,8 +151,8 @@ public class OpenController extends BaseController {
*/
@ApiOperation("获取栏目详细信息")
@GetMapping(value = "/dir/{dirId}")
public AjaxResult getDirInfo(@ApiParam(name = "dirId", value = "栏目Id") @PathVariable("dirId") Long dirId) {
return success(cmsDocService.selectCmsDirById(dirId, true));
public GenericsAjaxResult<CmsDir> getDirInfo(@ApiParam(name = "dirId", value = "栏目Id") @PathVariable("dirId") Long dirId) {
return genericsSuccess(cmsDocService.selectCmsDirById(dirId, true));
}
/**