From a13fed47af82face4e82761503d11b5f1d7eca32 Mon Sep 17 00:00:00 2001 From: OTTO <731554297@qq.com> Date: Mon, 18 Dec 2023 09:51:46 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E5=88=86=E9=A1=B5=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E5=A2=9E=E5=BC=BA):=20=E5=A4=84=E7=90=86CMS=E5=BE=AE=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E4=B8=AD=E6=96=87=E7=AB=A0=E7=9B=B8=E5=85=B3=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/web/controller/BaseController.java | 48 +++++++------------ .../cms/doc/controller/CmsDocController.java | 9 ++-- .../cms/doc/controller/OpenController.java | 39 +++++++-------- 3 files changed, 42 insertions(+), 54 deletions(-) diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/web/controller/BaseController.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/web/controller/BaseController.java index 47064ca1c..6876bd0a5 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/web/controller/BaseController.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/web/controller/BaseController.java @@ -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 GenericsTableDataInfo getAllGenericsDataTableToPage(List list) { + GenericsTableDataInfo 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); } diff --git a/ruoyi-modules/ruoyi-cms/src/main/java/com/ruoyi/cms/doc/controller/CmsDocController.java b/ruoyi-modules/ruoyi-cms/src/main/java/com/ruoyi/cms/doc/controller/CmsDocController.java index 782a214a3..9388522ff 100644 --- a/ruoyi-modules/ruoyi-cms/src/main/java/com/ruoyi/cms/doc/controller/CmsDocController.java +++ b/ruoyi-modules/ruoyi-cms/src/main/java/com/ruoyi/cms/doc/controller/CmsDocController.java @@ -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 dirList(@ApiParam(name = "zoneId", value = "专区Id") @PathVariable("zoneId") Long zoneId) { Long deptId = cmsDocService.getDeptIdByZoneId(zoneId); List 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 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); } /** diff --git a/ruoyi-modules/ruoyi-cms/src/main/java/com/ruoyi/cms/doc/controller/OpenController.java b/ruoyi-modules/ruoyi-cms/src/main/java/com/ruoyi/cms/doc/controller/OpenController.java index a83949f8d..39dc9cc44 100644 --- a/ruoyi-modules/ruoyi-cms/src/main/java/com/ruoyi/cms/doc/controller/OpenController.java +++ b/ruoyi-modules/ruoyi-cms/src/main/java/com/ruoyi/cms/doc/controller/OpenController.java @@ -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 dirList(@ApiParam(name = "zoneId", value = "专区Id") @PathVariable("zoneId") Long zoneId) { Long deptId = cmsDocService.getDeptIdByZoneId(zoneId); List 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 docList(@ApiParam(name = "dirId", value = "栏目Id") @PathVariable("dirId") Long dirId , CmsDocSearchVo cmsDocSearchVo) { cmsDocSearchVo.setIsOpen(true); List 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 docContentList(@ApiParam(name = "dirId", value = "栏目Id") @PathVariable("dirId") Long dirId) { List 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 docOverviewList(@ApiParam(name = "zoneId", value = "专区Id") @PathVariable("zoneId") Long zoneId) { Long deptId = cmsDocService.getDeptIdByZoneId(zoneId); List 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 homePageDocList(@ApiParam(name = "zoneId", value = "专区Id") @PathVariable("zoneId") Long zoneId) { Long deptId = cmsDocService.getDeptIdByZoneId(zoneId); List 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 hotDocListByDir(@ApiParam(name = "dirId", value = "栏目Id") @PathVariable("dirId") Long dirId) { List 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 hotDocListByDept(@ApiParam(name = "zoneId", value = "专区Id") @PathVariable("zoneId") Long zoneId) { Long deptId = cmsDocService.getDeptIdByZoneId(zoneId); List 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 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 getDirInfo(@ApiParam(name = "dirId", value = "栏目Id") @PathVariable("dirId") Long dirId) { + return genericsSuccess(cmsDocService.selectCmsDirById(dirId, true)); } /**