重构网站导航管理实其更具人性化

This commit is contained in:
gxwebsoft
2024-03-21 00:04:26 +08:00
parent 06a8bdec83
commit f31ba27d21
12 changed files with 107 additions and 19 deletions
@@ -1,5 +1,6 @@
package com.gxwebsoft.cms.controller; package com.gxwebsoft.cms.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.gxwebsoft.cms.entity.Article; import com.gxwebsoft.cms.entity.Article;
import com.gxwebsoft.cms.entity.ArticleCategory; import com.gxwebsoft.cms.entity.ArticleCategory;
import com.gxwebsoft.cms.param.ArticleCategoryParam; import com.gxwebsoft.cms.param.ArticleCategoryParam;
@@ -67,9 +68,11 @@ public class ArticleCategoryController extends BaseController {
public ApiResult<ArticleCategory> get(@PathVariable("id") Integer id) { public ApiResult<ArticleCategory> get(@PathVariable("id") Integer id) {
// 使用关联查询 // 使用关联查询
ArticleCategory category = articleCategoryService.getByIdRel(id); ArticleCategory category = articleCategoryService.getByIdRel(id);
if (!category.getParentId().equals(0)) { if(category != null){
final ArticleCategory parentCategory = articleCategoryService.getById(category.getParentId()); if (!category.getParentId().equals(0)) {
category.setParentName(parentCategory.getTitle()); final ArticleCategory parentCategory = articleCategoryService.getById(category.getParentId());
category.setParentName(parentCategory.getTitle());
}
} }
return success(category); return success(category);
} }
@@ -100,6 +103,9 @@ public class ArticleCategoryController extends BaseController {
@ApiOperation("删除文章分类表") @ApiOperation("删除文章分类表")
@DeleteMapping("/{id}") @DeleteMapping("/{id}")
public ApiResult<?> remove(@PathVariable("id") Integer id) { public ApiResult<?> remove(@PathVariable("id") Integer id) {
if (articleService.count(new LambdaQueryWrapper<Article>().eq(Article::getCategoryId,id)) > 0) {
return fail("请先删除栏目下的文章");
}
if (articleCategoryService.removeById(id)) { if (articleCategoryService.removeById(id)) {
return success("删除成功"); return success("删除成功");
} }
@@ -127,10 +133,22 @@ public class ArticleCategoryController extends BaseController {
@ApiOperation("批量删除文章分类表") @ApiOperation("批量删除文章分类表")
@DeleteMapping("/batch") @DeleteMapping("/batch")
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) { public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
final int count = articleService.count(new LambdaQueryWrapper<Article>().in(Article::getCategoryId, ids));
System.out.println("count = " + count);
if (articleService.count(new LambdaQueryWrapper<Article>().in(Article::getCategoryId,ids)) > 0) {
return fail("请先删除栏目下的文章");
}
if (articleCategoryService.removeByIds(ids)) { if (articleCategoryService.removeByIds(ids)) {
return success("删除成功"); return success("删除成功");
} }
return fail("删除失败"); return fail("删除失败");
} }
@ApiOperation("检查分类是否存在")
@GetMapping("/existence")
public ApiResult<?> existence(ExistenceParam<ArticleCategory> param) {
if (param.isExistence(articleCategoryService, ArticleCategory::getUserId)) {
return success(param.getValue() + "已存在");
}
return fail(param.getValue() + "不存在");
}
} }
@@ -1,5 +1,6 @@
package com.gxwebsoft.cms.controller; package com.gxwebsoft.cms.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.gxwebsoft.cms.entity.Design; import com.gxwebsoft.cms.entity.Design;
import com.gxwebsoft.cms.param.DesignParam; import com.gxwebsoft.cms.param.DesignParam;
import com.gxwebsoft.cms.service.DesignService; import com.gxwebsoft.cms.service.DesignService;
@@ -54,6 +55,9 @@ public class DesignController extends BaseController {
if (loginUser != null) { if (loginUser != null) {
design.setUserId(loginUser.getUserId()); design.setUserId(loginUser.getUserId());
} }
if (designService.count(new LambdaQueryWrapper<Design>().eq(Design::getPath,design.getPath())) > 0) {
return fail("路由地址已存在");
}
if (designService.save(design)) { if (designService.save(design)) {
return success("添加成功"); return success("添加成功");
} }
@@ -1,5 +1,6 @@
package com.gxwebsoft.cms.controller; package com.gxwebsoft.cms.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.gxwebsoft.cms.entity.Navigation; import com.gxwebsoft.cms.entity.Navigation;
import com.gxwebsoft.cms.param.NavigationParam; import com.gxwebsoft.cms.param.NavigationParam;
import com.gxwebsoft.cms.service.NavigationService; import com.gxwebsoft.cms.service.NavigationService;
@@ -55,6 +56,9 @@ public class NavigationController extends BaseController {
if (loginUser != null) { if (loginUser != null) {
navigation.setUserId(loginUser.getUserId()); navigation.setUserId(loginUser.getUserId());
} }
if (navigationService.count(new LambdaQueryWrapper<Navigation>().eq(Navigation::getPath,navigation.getPath())) > 0) {
return fail("路由地址已存在");
}
if (navigationService.save(navigation)) { if (navigationService.save(navigation)) {
return success("添加成功"); return success("添加成功");
} }
@@ -64,6 +68,9 @@ public class NavigationController extends BaseController {
@ApiOperation("修改网站导航记录表") @ApiOperation("修改网站导航记录表")
@PutMapping() @PutMapping()
public ApiResult<?> update(@RequestBody Navigation navigation) { public ApiResult<?> update(@RequestBody Navigation navigation) {
if (navigationService.count(new LambdaQueryWrapper<Navigation>().ne(Navigation::getNavigationId,navigation.getNavigationId()).eq(Navigation::getPath,navigation.getPath())) > 0) {
return fail("路由地址已存在");
}
if (navigationService.updateById(navigation)) { if (navigationService.updateById(navigation)) {
return success("修改成功"); return success("修改成功");
} }
@@ -106,4 +113,12 @@ public class NavigationController extends BaseController {
return fail("删除失败"); return fail("删除失败");
} }
@ApiOperation("检查分类是否存在")
@GetMapping("/existence")
public ApiResult<?> existence(ExistenceParam<Navigation> param) {
if (navigationService.count(new LambdaQueryWrapper<Navigation>().eq(Navigation::getPath, param.getValue()).ne(Navigation::getNavigationId,param.getId()))> 0) {
return success(param.getValue() + "已存在");
}
return fail(param.getValue() + "不存在");
}
} }
@@ -6,15 +6,13 @@ import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.gxwebsoft.cms.entity.Ad;
import com.gxwebsoft.cms.entity.ArticleCategory; import com.gxwebsoft.cms.entity.ArticleCategory;
import com.gxwebsoft.cms.entity.Navigation;
import com.gxwebsoft.cms.entity.Website; import com.gxwebsoft.cms.entity.Website;
import com.gxwebsoft.cms.param.ArticleCategoryParam; import com.gxwebsoft.cms.param.ArticleCategoryParam;
import com.gxwebsoft.cms.param.NavigationParam;
import com.gxwebsoft.cms.param.WebsiteParam; import com.gxwebsoft.cms.param.WebsiteParam;
import com.gxwebsoft.cms.service.ArticleCategoryService; import com.gxwebsoft.cms.service.*;
import com.gxwebsoft.cms.service.NavigationService;
import com.gxwebsoft.cms.service.WebsiteFieldService;
import com.gxwebsoft.cms.service.WebsiteService;
import com.gxwebsoft.common.core.security.JwtUtil; import com.gxwebsoft.common.core.security.JwtUtil;
import com.gxwebsoft.common.core.utils.RedisUtil; import com.gxwebsoft.common.core.utils.RedisUtil;
import com.gxwebsoft.common.core.web.*; import com.gxwebsoft.common.core.web.*;
@@ -48,6 +46,8 @@ public class WebsiteController extends BaseController {
@Resource @Resource
private NavigationService navigationService; private NavigationService navigationService;
@Resource @Resource
private AdService adService;
@Resource
private ArticleCategoryService articleCategoryService; private ArticleCategoryService articleCategoryService;
@Resource @Resource
private LinkService linkService; private LinkService linkService;
@@ -62,9 +62,9 @@ public class WebsiteController extends BaseController {
final String siteInfo = redisUtil.get(key); final String siteInfo = redisUtil.get(key);
// 从缓存读取信息 // 从缓存读取信息
if(StrUtil.isNotBlank(siteInfo)){ // if(StrUtil.isNotBlank(siteInfo)){
return success(JSONObject.parseObject(siteInfo,Website.class)); // return success(JSONObject.parseObject(siteInfo,Website.class));
} // }
// 获取站点信息 // 获取站点信息
final WebsiteParam websiteParam = new WebsiteParam(); final WebsiteParam websiteParam = new WebsiteParam();
@@ -129,7 +129,12 @@ public class WebsiteController extends BaseController {
website.setFields(websiteFieldService.list()); website.setFields(websiteFieldService.list());
// 附加自定义导航 // 附加自定义导航
website.setNavigations(navigationService.list(new LambdaQueryWrapper<Navigation>().eq(Navigation::getStatus,0))); final NavigationParam navigationParam = new NavigationParam();
navigationParam.setHide(0);
website.setNavigations(navigationService.listRel(navigationParam));
// 读取幻灯片广告
website.setAds(adService.list(new LambdaQueryWrapper<Ad>().like(Ad::getName,"幻灯片").last("limit 10")));
// 提取文章分类作为网站导航 // 提取文章分类作为网站导航
final ArticleCategoryParam param = new ArticleCategoryParam(); final ArticleCategoryParam param = new ArticleCategoryParam();
@@ -58,6 +58,9 @@ public class ArticleCategory implements Serializable {
@ApiModelProperty(value = "用户ID") @ApiModelProperty(value = "用户ID")
private Integer userId; private Integer userId;
@ApiModelProperty(value = "文章数量")
private Integer count;
@ApiModelProperty(value = "排序(数字越小越靠前)") @ApiModelProperty(value = "排序(数字越小越靠前)")
private Integer sortNumber; private Integer sortNumber;
@@ -1,6 +1,7 @@
package com.gxwebsoft.cms.entity; package com.gxwebsoft.cms.entity;
import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
@@ -28,6 +29,9 @@ public class Navigation implements Serializable {
@TableId(value = "navigation_id", type = IdType.AUTO) @TableId(value = "navigation_id", type = IdType.AUTO)
private Integer navigationId; private Integer navigationId;
@ApiModelProperty(value = "类型 0菜单 1单页内容 2外部链接")
private Integer type;
@ApiModelProperty(value = "上级id, 0是顶级") @ApiModelProperty(value = "上级id, 0是顶级")
private Integer parentId; private Integer parentId;
@@ -52,12 +56,24 @@ public class Navigation implements Serializable {
@ApiModelProperty(value = "是否隐藏, 0否, 1是(仅注册路由不显示在左侧菜单)") @ApiModelProperty(value = "是否隐藏, 0否, 1是(仅注册路由不显示在左侧菜单)")
private Integer hide; private Integer hide;
@ApiModelProperty(value = "位置 0不限 1顶部 2底部")
private Integer position;
@ApiModelProperty(value = "菜单侧栏选中的path") @ApiModelProperty(value = "菜单侧栏选中的path")
private String active; private String active;
@ApiModelProperty(value = "其它路由元信息") @ApiModelProperty(value = "其它路由元信息")
private String meta; private String meta;
@ApiModelProperty(value = "页面ID")
private Integer pageId;
@ApiModelProperty(value = "文章分类ID")
private Integer articleCategoryId;
@ApiModelProperty(value = "文章分类ID")
private Integer articleId;
@ApiModelProperty(value = "用户ID") @ApiModelProperty(value = "用户ID")
private Integer userId; private Integer userId;
@@ -76,4 +92,8 @@ public class Navigation implements Serializable {
@ApiModelProperty(value = "注册时间") @ApiModelProperty(value = "注册时间")
private Date createTime; private Date createTime;
@ApiModelProperty(value = "页面名称")
@TableField(exist = false)
private String pageName;
} }
@@ -137,6 +137,10 @@ public class Website implements Serializable {
@TableField(exist = false) @TableField(exist = false)
private List<Navigation> navigations; private List<Navigation> navigations;
@ApiModelProperty(value = "站点广告")
@TableField(exist = false)
private List<Ad> ads;
@ApiModelProperty(value = "文章分类") @ApiModelProperty(value = "文章分类")
@TableField(exist = false) @TableField(exist = false)
private List<ArticleCategory> categoryList; private List<ArticleCategory> categoryList;
@@ -101,6 +101,10 @@
<if test="param.createTimeEnd != null"> <if test="param.createTimeEnd != null">
AND a.create_time &lt;= #{param.createTimeEnd} AND a.create_time &lt;= #{param.createTimeEnd}
</if> </if>
<if test="param.keywords != null">
AND (a.title LIKE CONCAT('%', #{param.keywords}, '%')
)
</if>
</where> </where>
</sql> </sql>
@@ -4,8 +4,9 @@
<!-- 关联查询sql --> <!-- 关联查询sql -->
<sql id="selectSql"> <sql id="selectSql">
SELECT a.* SELECT a.*,b.name as pageName
FROM cms_navigation a FROM cms_navigation a
LEFT JOIN cms_design b ON a.page_id = b.page_id
<where> <where>
<if test="param.navigationId != null"> <if test="param.navigationId != null">
AND a.navigation_id = #{param.navigationId} AND a.navigation_id = #{param.navigationId}
@@ -17,7 +18,7 @@
AND a.title LIKE CONCAT('%', #{param.title}, '%') AND a.title LIKE CONCAT('%', #{param.title}, '%')
</if> </if>
<if test="param.path != null"> <if test="param.path != null">
AND a.path LIKE CONCAT('%', #{param.path}, '%') AND a.path = #{param.path}
</if> </if>
<if test="param.component != null"> <if test="param.component != null">
AND a.component LIKE CONCAT('%', #{param.component}, '%') AND a.component LIKE CONCAT('%', #{param.component}, '%')
@@ -34,6 +35,12 @@
<if test="param.hide != null"> <if test="param.hide != null">
AND a.hide = #{param.hide} AND a.hide = #{param.hide}
</if> </if>
<if test="param.position != null">
AND a.position = #{param.position}
</if>
<if test="param.pageId != null">
AND a.page_id = #{param.pageId}
</if>
<if test="param.active != null"> <if test="param.active != null">
AND a.active LIKE CONCAT('%', #{param.active}, '%') AND a.active LIKE CONCAT('%', #{param.active}, '%')
</if> </if>
@@ -34,6 +34,7 @@ public class NavigationParam extends BaseParam {
private String title; private String title;
@ApiModelProperty(value = "菜单路由地址") @ApiModelProperty(value = "菜单路由地址")
@QueryField(type = QueryType.EQ)
private String path; private String path;
@ApiModelProperty(value = "菜单组件地址, 目录可为空") @ApiModelProperty(value = "菜单组件地址, 目录可为空")
@@ -52,6 +53,10 @@ public class NavigationParam extends BaseParam {
@QueryField(type = QueryType.EQ) @QueryField(type = QueryType.EQ)
private Integer hide; private Integer hide;
@ApiModelProperty(value = "位置, 0不限, 1顶部 2底部")
@QueryField(type = QueryType.EQ)
private Integer position;
@ApiModelProperty(value = "菜单侧栏选中的path") @ApiModelProperty(value = "菜单侧栏选中的path")
private String active; private String active;
@@ -73,4 +78,8 @@ public class NavigationParam extends BaseParam {
@QueryField(type = QueryType.EQ) @QueryField(type = QueryType.EQ)
private Integer status; private Integer status;
@ApiModelProperty(value = "页面ID")
@QueryField(type = QueryType.EQ)
private Integer pageId;
} }
@@ -23,7 +23,7 @@ public class NavigationServiceImpl extends ServiceImpl<NavigationMapper, Navigat
@Override @Override
public PageResult<Navigation> pageRel(NavigationParam param) { public PageResult<Navigation> pageRel(NavigationParam param) {
PageParam<Navigation, NavigationParam> page = new PageParam<>(param); PageParam<Navigation, NavigationParam> page = new PageParam<>(param);
page.setDefaultOrder("sort_number desc,create_time desc"); page.setDefaultOrder("sort_number asc,navigation_id asc");
List<Navigation> list = baseMapper.selectPageRel(page, param); List<Navigation> list = baseMapper.selectPageRel(page, param);
return new PageResult<>(list, page.getTotal()); return new PageResult<>(list, page.getTotal());
} }
@@ -33,7 +33,7 @@ public class NavigationServiceImpl extends ServiceImpl<NavigationMapper, Navigat
List<Navigation> list = baseMapper.selectListRel(param); List<Navigation> list = baseMapper.selectListRel(param);
// 排序 // 排序
PageParam<Navigation, NavigationParam> page = new PageParam<>(); PageParam<Navigation, NavigationParam> page = new PageParam<>();
page.setDefaultOrder("sort_number desc,create_time desc"); page.setDefaultOrder("sort_number asc,navigation_id asc");
return page.sortRecords(list); return page.sortRecords(list);
} }
@@ -46,8 +46,7 @@ public class AppController extends BaseController {
public ApiResult<Map<String, Integer>> data() { public ApiResult<Map<String, Integer>> data() {
Map<String, Integer> data = new HashMap<>(); Map<String, Integer> data = new HashMap<>();
Integer totalNum = appService.count( Integer totalNum = appService.count(
new LambdaQueryWrapper<App>() new LambdaQueryWrapper<>()
.ne(App::getAppStatus, "已下架")
); );
Integer totalNum2 = appService.count( Integer totalNum2 = appService.count(
new LambdaQueryWrapper<App>() new LambdaQueryWrapper<App>()