From 64cdd035e17fd61bfb1fcae005576f094b49daa4 Mon Sep 17 00:00:00 2001 From: PIG AI Date: Thu, 29 May 2025 10:43:05 +0800 Subject: [PATCH] =?UTF-8?q?feat(app):=20=E6=96=B0=E5=A2=9E=E5=B7=A5?= =?UTF-8?q?=E4=BD=9C=E5=8F=B0=E8=8F=9C=E5=8D=95=E6=9D=83=E9=99=90=E8=BF=87?= =?UTF-8?q?=E6=BB=A4=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在AppIndexServiceImpl中实现基于角色权限的菜单过滤 - 新增WORKBENCH页面类型枚举 - 为AppRole添加menuId字段存储权限菜单 - 扩展AppRoleService提供菜单查询接口 - 优化AppArticleCollectEntity增加image和visit字段 --- .../api/entity/AppArticleCollectEntity.java | 116 +++++---- .../pigx/app/api/entity/AppPageEntity.java | 2 + .../pigx/app/api/entity/AppRole.java | 10 +- .../pigx/app/api/enums/PageTypeEnums.java | 7 +- .../AppArticleCollectController.java | 165 ++++++------ .../app/controller/AppRoleController.java | 241 ++++++++++-------- .../pigx/app/service/AppRoleService.java | 19 ++ .../app/service/impl/AppIndexServiceImpl.java | 53 +++- .../app/service/impl/AppRoleServiceImpl.java | 31 ++- 9 files changed, 385 insertions(+), 259 deletions(-) diff --git a/pigx-app-server/pigx-app-server-api/src/main/java/com/pig4cloud/pigx/app/api/entity/AppArticleCollectEntity.java b/pigx-app-server/pigx-app-server-api/src/main/java/com/pig4cloud/pigx/app/api/entity/AppArticleCollectEntity.java index fcbf5b63b..2e6c27813 100644 --- a/pigx-app-server/pigx-app-server-api/src/main/java/com/pig4cloud/pigx/app/api/entity/AppArticleCollectEntity.java +++ b/pigx-app-server/pigx-app-server-api/src/main/java/com/pig4cloud/pigx/app/api/entity/AppArticleCollectEntity.java @@ -22,65 +22,77 @@ import java.time.LocalDateTime; @Schema(description = "文章收藏表") public class AppArticleCollectEntity extends Model { - /** - * 主键 - */ - @TableId(type = IdType.ASSIGN_ID) - @Schema(description = "主键") - private Long id; + /** + * 主键 + */ + @TableId(type = IdType.ASSIGN_ID) + @Schema(description = "主键") + private Long id; - /** - * 用户ID - */ - @Schema(description = "用户ID") - private Long userId; + /** + * 用户ID + */ + @Schema(description = "用户ID") + private Long userId; - /** - * 文章ID - */ - @Schema(description = "文章ID") - private Long articleId; + /** + * 文章ID + */ + @Schema(description = "文章ID") + private Long articleId; - /** - * 文章标题 - */ - @TableField(exist = false) - private String title; + /** + * 文章标题 + */ + @TableField(exist = false) + private String title; - /** - * 创建人 - */ - @TableField(fill = FieldFill.INSERT) - @Schema(description = "创建人") - private String createBy; + /** + * 创建人 + */ + @TableField(fill = FieldFill.INSERT) + @Schema(description = "创建人") + private String createBy; - /** - * 创建时间 - */ - @TableField(fill = FieldFill.INSERT) - @Schema(description = "创建时间") - private LocalDateTime createTime; + /** + * 创建时间 + */ + @TableField(fill = FieldFill.INSERT) + @Schema(description = "创建时间") + private LocalDateTime createTime; - /** - * 更新人 - */ - @TableField(fill = FieldFill.INSERT_UPDATE) - @Schema(description = "更新人") - private String updateBy; + /** + * 更新人 + */ + @TableField(fill = FieldFill.INSERT_UPDATE) + @Schema(description = "更新人") + private String updateBy; - /** - * 更新时间 - */ - @TableField(fill = FieldFill.INSERT_UPDATE) - @Schema(description = "更新时间") - private LocalDateTime updateTime; + /** + * 更新时间 + */ + @TableField(fill = FieldFill.INSERT_UPDATE) + @Schema(description = "更新时间") + private LocalDateTime updateTime; - /** - * 是否删除 - */ - @TableLogic - @TableField(fill = FieldFill.INSERT) - @Schema(description = "是否删除") - private String delFlag; + /** + * 是否删除 + */ + @TableLogic + @TableField(fill = FieldFill.INSERT) + @Schema(description = "是否删除") + private String delFlag; + + /** + * 图片 + */ + @TableField(exist = false) + private String image; + + /** + * 访问次数 + */ + @TableField(exist = false) + private Long visit; } diff --git a/pigx-app-server/pigx-app-server-api/src/main/java/com/pig4cloud/pigx/app/api/entity/AppPageEntity.java b/pigx-app-server/pigx-app-server-api/src/main/java/com/pig4cloud/pigx/app/api/entity/AppPageEntity.java index 12c7eeffb..df989d5af 100644 --- a/pigx-app-server/pigx-app-server-api/src/main/java/com/pig4cloud/pigx/app/api/entity/AppPageEntity.java +++ b/pigx-app-server/pigx-app-server-api/src/main/java/com/pig4cloud/pigx/app/api/entity/AppPageEntity.java @@ -6,6 +6,7 @@ import com.pig4cloud.pigx.common.core.util.TenantTable; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import lombok.EqualsAndHashCode; +import lombok.experimental.FieldNameConstants; import java.time.LocalDateTime; @@ -18,6 +19,7 @@ import java.time.LocalDateTime; @Data @TenantTable @TableName("app_page") +@FieldNameConstants @EqualsAndHashCode(callSuper = true) @Schema(description = "页面") public class AppPageEntity extends Model { diff --git a/pigx-app-server/pigx-app-server-api/src/main/java/com/pig4cloud/pigx/app/api/entity/AppRole.java b/pigx-app-server/pigx-app-server-api/src/main/java/com/pig4cloud/pigx/app/api/entity/AppRole.java index ec63649a6..bc77a8eb2 100644 --- a/pigx-app-server/pigx-app-server-api/src/main/java/com/pig4cloud/pigx/app/api/entity/AppRole.java +++ b/pigx-app-server/pigx-app-server-api/src/main/java/com/pig4cloud/pigx/app/api/entity/AppRole.java @@ -63,11 +63,17 @@ public class AppRole extends Model { private String roleCode; /** - * roleDesc + * 角色描述 */ - @Schema(description = "roleDesc") + @Schema(description = "角色描述") private String roleDesc; + /** + * 菜单ID列表 + */ + @Schema(description = "菜单ID列表") + private String menuId; + /** * 创建人 */ diff --git a/pigx-app-server/pigx-app-server-api/src/main/java/com/pig4cloud/pigx/app/api/enums/PageTypeEnums.java b/pigx-app-server/pigx-app-server-api/src/main/java/com/pig4cloud/pigx/app/api/enums/PageTypeEnums.java index 75339dbef..e336022c1 100644 --- a/pigx-app-server/pigx-app-server-api/src/main/java/com/pig4cloud/pigx/app/api/enums/PageTypeEnums.java +++ b/pigx-app-server/pigx-app-server-api/src/main/java/com/pig4cloud/pigx/app/api/enums/PageTypeEnums.java @@ -18,7 +18,12 @@ public enum PageTypeEnums { /** * 客服设置 */ - SERVICE(3, "客服设置"); + SERVICE(3, "客服设置"), + + /** + * 工作台属性 + */ + WORKBENCH(4, "工作台"); private final Integer pageType; diff --git a/pigx-app-server/pigx-app-server-biz/src/main/java/com/pig4cloud/pigx/app/controller/AppArticleCollectController.java b/pigx-app-server/pigx-app-server-biz/src/main/java/com/pig4cloud/pigx/app/controller/AppArticleCollectController.java index 334831cc3..de5325326 100644 --- a/pigx-app-server/pigx-app-server-biz/src/main/java/com/pig4cloud/pigx/app/controller/AppArticleCollectController.java +++ b/pigx-app-server/pigx-app-server-biz/src/main/java/com/pig4cloud/pigx/app/controller/AppArticleCollectController.java @@ -35,92 +35,97 @@ import java.util.List; @SecurityRequirement(name = HttpHeaders.AUTHORIZATION) public class AppArticleCollectController { - private final AppArticleCollectService appArticleCollectService; + private final AppArticleCollectService appArticleCollectService; - /** - * 分页查询 - * @param page 分页对象 - * @param appArticleCollect 文章收藏表 - * @return - */ - @Operation(summary = "分页查询", description = "分页查询") - @GetMapping("/page") - public R getAppArticleCollectPage(@ParameterObject Page page) { - MPJLambdaWrapper wrapper = new MPJLambdaWrapper() - .selectAll(AppArticleCollectEntity.class) - .select(AppArticleEntity::getTitle) - .leftJoin(AppArticleEntity.class, AppArticleEntity::getId, AppArticleCollectEntity::getArticleId) - .eq(AppArticleCollectEntity::getUserId, SecurityUtils.getUser().getId()); - return R.ok(appArticleCollectService.selectJoinListPage(page, AppArticleCollectEntity.class, wrapper)); - } + /** + * 分页查询文章收藏信息。 + * + * @param page 分页查询参数对象 + * @return 返回分页结果对象,包含文章收藏信息列表 + */ + @Operation(summary = "分页查询", description = "分页查询") + @GetMapping("/page") + public R getAppArticleCollectPage(@ParameterObject Page page) { + MPJLambdaWrapper wrapper = new MPJLambdaWrapper() + .selectAll(AppArticleCollectEntity.class) + .select(AppArticleEntity::getTitle, AppArticleEntity::getImage, AppArticleEntity::getVisit) + .leftJoin(AppArticleEntity.class, AppArticleEntity::getId, AppArticleCollectEntity::getArticleId) + .eq(AppArticleCollectEntity::getUserId, SecurityUtils.getUser().getId()); + return R.ok(appArticleCollectService.selectJoinListPage(page, AppArticleCollectEntity.class, wrapper)); + } - /** - * 通过id查询文章收藏表 - * @param id id - * @return R - */ - @Operation(summary = "通过id查询", description = "通过id查询") - @GetMapping("/{id}") - public R getById(@PathVariable("id") Long id) { - return R.ok(appArticleCollectService.getById(id)); - } + /** + * 通过id查询文章收藏表 + * + * @param id id + * @return R + */ + @Operation(summary = "通过id查询", description = "通过id查询") + @GetMapping("/{id}") + public R getById(@PathVariable("id") Long id) { + return R.ok(appArticleCollectService.getById(id)); + } - /** - * 新增文章收藏表 - * @param appArticleCollect 文章收藏表 - * @return R - */ - @Operation(summary = "新增文章收藏表", description = "新增文章收藏表") - @SysLog("新增文章收藏表") - @PostMapping - public R save(@RequestBody AppArticleCollectEntity appArticleCollect) { - return R.ok(appArticleCollectService.saveArticleCollect(appArticleCollect)); - } + /** + * 新增文章收藏表 + * + * @param appArticleCollect 文章收藏表 + * @return R + */ + @Operation(summary = "新增文章收藏表", description = "新增文章收藏表") + @SysLog("新增文章收藏表") + @PostMapping + public R save(@RequestBody AppArticleCollectEntity appArticleCollect) { + return R.ok(appArticleCollectService.saveArticleCollect(appArticleCollect)); + } - /** - * 修改文章收藏表 - * @param appArticleCollect 文章收藏表 - * @return R - */ - @Operation(summary = "修改文章收藏表", description = "修改文章收藏表") - @SysLog("修改文章收藏表") - @PutMapping - public R updateById(@RequestBody AppArticleCollectEntity appArticleCollect) { - return R.ok(appArticleCollectService.updateById(appArticleCollect)); - } + /** + * 修改文章收藏表 + * + * @param appArticleCollect 文章收藏表 + * @return R + */ + @Operation(summary = "修改文章收藏表", description = "修改文章收藏表") + @SysLog("修改文章收藏表") + @PutMapping + public R updateById(@RequestBody AppArticleCollectEntity appArticleCollect) { + return R.ok(appArticleCollectService.updateById(appArticleCollect)); + } - /** - * 通过id删除文章收藏表 - * @param ids id列表 - * @return R - */ - @Operation(summary = "通过id删除文章收藏表", description = "通过id删除文章收藏表") - @SysLog("通过id删除文章收藏表") - @DeleteMapping - public R removeById(@RequestBody Long[] ids) { - return R.ok(appArticleCollectService.removeBatchByIds(CollUtil.toList(ids))); - } + /** + * 通过id删除文章收藏表 + * + * @param ids id列表 + * @return R + */ + @Operation(summary = "通过id删除文章收藏表", description = "通过id删除文章收藏表") + @SysLog("通过id删除文章收藏表") + @DeleteMapping + public R removeById(@RequestBody Long[] ids) { + return R.ok(appArticleCollectService.removeBatchByIds(CollUtil.toList(ids))); + } - @Operation(summary = "通过文章id删除文章收藏表", description = "通过文章id删除文章收藏表") - @SysLog("通过文章id删除文章收藏表") - @DeleteMapping("/{articleId}") - public R removeByArticleId(@PathVariable String articleId) { - Long id = SecurityUtils.getUser().getId(); - return R.ok(appArticleCollectService.remove(Wrappers.lambdaQuery() - .eq(AppArticleCollectEntity::getUserId, id) - .eq(AppArticleCollectEntity::getArticleId, articleId))); - } + @Operation(summary = "通过文章id删除文章收藏表", description = "通过文章id删除文章收藏表") + @SysLog("通过文章id删除文章收藏表") + @DeleteMapping("/{articleId}") + public R removeByArticleId(@PathVariable String articleId) { + Long id = SecurityUtils.getUser().getId(); + return R.ok(appArticleCollectService.remove(Wrappers.lambdaQuery() + .eq(AppArticleCollectEntity::getUserId, id) + .eq(AppArticleCollectEntity::getArticleId, articleId))); + } - /** - * 导出excel 表格 - * @param appArticleCollect 查询条件 - * @return excel 文件流 - */ - @ResponseExcel - @GetMapping("/export") - @HasPermission("app_collect_export") - public List export(AppArticleCollectEntity appArticleCollect) { - return appArticleCollectService.list(Wrappers.query(appArticleCollect)); - } + /** + * 导出excel 表格 + * + * @param appArticleCollect 查询条件 + * @return excel 文件流 + */ + @ResponseExcel + @GetMapping("/export") + @HasPermission("app_collect_export") + public List export(AppArticleCollectEntity appArticleCollect) { + return appArticleCollectService.list(Wrappers.query(appArticleCollect)); + } } diff --git a/pigx-app-server/pigx-app-server-biz/src/main/java/com/pig4cloud/pigx/app/controller/AppRoleController.java b/pigx-app-server/pigx-app-server-biz/src/main/java/com/pig4cloud/pigx/app/controller/AppRoleController.java index 38fd7bf35..969d2a561 100644 --- a/pigx-app-server/pigx-app-server-biz/src/main/java/com/pig4cloud/pigx/app/controller/AppRoleController.java +++ b/pigx-app-server/pigx-app-server-biz/src/main/java/com/pig4cloud/pigx/app/controller/AppRoleController.java @@ -51,125 +51,146 @@ import java.util.List; @SecurityRequirement(name = HttpHeaders.AUTHORIZATION) public class AppRoleController { - private final AppRoleService appRoleService; + private final AppRoleService appRoleService; - /** - * 分页查询 - * @param page 分页对象 - * @param appRole app角色表 - * @return - */ - @Operation(summary = "分页查询", description = "分页查询") - @GetMapping("/page") - public R getAppRolePage(Page page, AppRole appRole) { - return R.ok(appRoleService.page(page, Wrappers.lambdaQuery() - .like(StrUtil.isNotBlank(appRole.getRoleName()), AppRole::getRoleName, appRole.getRoleName()))); - } + /** + * 分页查询 + * + * @param page 分页对象 + * @param appRole app角色表 + * @return + */ + @Operation(summary = "分页查询", description = "分页查询") + @GetMapping("/page") + public R getAppRolePage(Page page, AppRole appRole) { + return R.ok(appRoleService.page(page, Wrappers.lambdaQuery() + .like(StrUtil.isNotBlank(appRole.getRoleName()), AppRole::getRoleName, appRole.getRoleName()))); + } - /** - * 查询全部角色 - * @return - */ - @Operation(summary = "查询全部", description = "查询全部") - @GetMapping("/list") - public R list() { - return R.ok(appRoleService.list(Wrappers.emptyWrapper())); - } + /** + * 查询全部角色 + * + * @return + */ + @Operation(summary = "查询全部", description = "查询全部") + @GetMapping("/list") + public R list() { + return R.ok(appRoleService.list(Wrappers.emptyWrapper())); + } - /** - * 通过id查询app角色表 - * @param roleId id - * @return R - */ - @Operation(summary = "通过id查询", description = "通过id查询") - @GetMapping("/{roleId}") - public R getById(@PathVariable("roleId") Long roleId) { - return R.ok(appRoleService.getById(roleId)); - } + /** + * 通过id查询app角色表 + * + * @param roleId id + * @return R + */ + @Operation(summary = "通过id查询", description = "通过id查询") + @GetMapping("/{roleId}") + public R getById(@PathVariable("roleId") Long roleId) { + return R.ok(appRoleService.getById(roleId)); + } - /** - * 通过roleName查询app角色表 - * @param roleName roleName - * @return R - */ - @Operation(summary = "通过id查询", description = "通过id查询") - @GetMapping("/details/{roleName}") - public R getByUserName(@PathVariable("roleName") String roleName) { - return R.ok(appRoleService.getOne(Wrappers.lambdaQuery().eq(AppRole::getRoleName, roleName))); - } + /** + * 通过roleName查询app角色表 + * + * @param roleName roleName + * @return R + */ + @Operation(summary = "通过id查询", description = "通过id查询") + @GetMapping("/details/{roleName}") + public R getByUserName(@PathVariable("roleName") String roleName) { + return R.ok(appRoleService.getOne(Wrappers.lambdaQuery().eq(AppRole::getRoleName, roleName))); + } - /** - * 通过roleCode查询app角色表 - * @param roleCode roleCode - * @return R - */ - @Operation(summary = "通过roleCode查询", description = "通过roleCode查询") - @GetMapping("/detailsByCode/{roleCode}") - public R getByPhone(@PathVariable("roleCode") String roleCode) { - return R.ok(appRoleService.getOne(Wrappers.lambdaQuery().eq(AppRole::getRoleCode, roleCode))); - } + /** + * 通过roleCode查询app角色表 + * + * @param roleCode roleCode + * @return R + */ + @Operation(summary = "通过roleCode查询", description = "通过roleCode查询") + @GetMapping("/detailsByCode/{roleCode}") + public R getByPhone(@PathVariable("roleCode") String roleCode) { + return R.ok(appRoleService.getOne(Wrappers.lambdaQuery().eq(AppRole::getRoleCode, roleCode))); + } - /** - * 新增app角色表 - * @param appRole app角色表 - * @return R - */ - @Operation(summary = "新增app角色表", description = "新增app角色表") - @SysLog("新增app角色表") - @PostMapping - @HasPermission("app_approle_add") - public R save(@RequestBody AppRole appRole) { - return R.ok(appRoleService.save(appRole)); - } + /** + * 新增app角色表 + * + * @param appRole app角色表 + * @return R + */ + @Operation(summary = "新增app角色表", description = "新增app角色表") + @SysLog("新增app角色表") + @PostMapping + @HasPermission("app_approle_add") + public R save(@RequestBody AppRole appRole) { + return R.ok(appRoleService.save(appRole)); + } - /** - * 修改app角色表 - * @param appRole app角色表 - * @return R - */ - @Operation(summary = "修改app角色表", description = "修改app角色表") - @SysLog("修改app角色表") - @PutMapping - @HasPermission("app_approle_edit") - public R updateById(@RequestBody AppRole appRole) { - return R.ok(appRoleService.updateById(appRole)); - } + /** + * 修改app角色表 + * + * @param appRole app角色表 + * @return R + */ + @Operation(summary = "修改app角色表", description = "修改app角色表") + @SysLog("修改app角色表") + @PutMapping + @HasPermission("app_approle_edit") + public R updateById(@RequestBody AppRole appRole) { + return R.ok(appRoleService.updateById(appRole)); + } - /** - * 通过ids批量删除app角色表 - * @param ids roleIds - * @return R - */ - @Operation(summary = "通过ids批量删除app角色表", description = "通过ids批量删除app角色表") - @SysLog("通过ids批量删除app角色表") - @DeleteMapping - @HasPermission("app_approle_del") - public R removeById(@RequestBody Long[] ids) { - return R.ok(appRoleService.deleteRoleByIds(ids)); - } + /** + * 通过ids批量删除app角色表 + * + * @param ids roleIds + * @return R + */ + @Operation(summary = "通过ids批量删除app角色表", description = "通过ids批量删除app角色表") + @SysLog("通过ids批量删除app角色表") + @DeleteMapping + @HasPermission("app_approle_del") + public R removeById(@RequestBody Long[] ids) { + return R.ok(appRoleService.deleteRoleByIds(ids)); + } - /** - * 导出excel 表格 - * @param appRole 查询条件 - * @return excel 文件流 - */ - @ResponseExcel - @GetMapping("/export") - @HasPermission("app_approle_export") - public List export(AppRole appRole) { - return appRoleService.list(Wrappers.query(appRole)); - } + /** + * 导出excel 表格 + * + * @param appRole 查询条件 + * @return excel 文件流 + */ + @ResponseExcel + @GetMapping("/export") + @HasPermission("app_approle_export") + public List export(AppRole appRole) { + return appRoleService.list(Wrappers.query(appRole)); + } + + /** + * 导入角色 + * + * @param excelVOList 角色列表 + * @param bindingResult 错误信息列表 + * @return ok fail + */ + @PostMapping("/import") + @HasPermission("app_approle_export") + public R importRole(@RequestExcel List excelVOList, BindingResult bindingResult) { + return appRoleService.importRole(excelVOList, bindingResult); + } + + /** + * 获取工作台菜单列表 + * + * @return 返回封装了菜单列表的结果对象 + */ + @GetMapping("/menu") + public R menu() { + return R.ok(appRoleService.listMenu()); + } - /** - * 导入角色 - * @param excelVOList 角色列表 - * @param bindingResult 错误信息列表 - * @return ok fail - */ - @PostMapping("/import") - @HasPermission("app_approle_export") - public R importRole(@RequestExcel List excelVOList, BindingResult bindingResult) { - return appRoleService.importRole(excelVOList, bindingResult); - } } diff --git a/pigx-app-server/pigx-app-server-biz/src/main/java/com/pig4cloud/pigx/app/service/AppRoleService.java b/pigx-app-server/pigx-app-server-biz/src/main/java/com/pig4cloud/pigx/app/service/AppRoleService.java index a1cb464d4..1f7ce9b76 100644 --- a/pigx-app-server/pigx-app-server-biz/src/main/java/com/pig4cloud/pigx/app/service/AppRoleService.java +++ b/pigx-app-server/pigx-app-server-biz/src/main/java/com/pig4cloud/pigx/app/service/AppRoleService.java @@ -18,6 +18,7 @@ package com.pig4cloud.pigx.app.service; import com.baomidou.mybatisplus.extension.service.IService; +import com.pig4cloud.pigx.app.api.entity.AppPageEntity; import com.pig4cloud.pigx.app.api.entity.AppRole; import com.pig4cloud.pigx.app.api.vo.AppRoleExcelVO; import com.pig4cloud.pigx.common.core.util.R; @@ -33,6 +34,12 @@ import java.util.List; */ public interface AppRoleService extends IService { + /** + * 根据用户ID查询角色列表 + * + * @param userId 用户ID + * @return 对应用户ID的角色列表 + */ List findRolesByUserId(Long userId); /** @@ -41,6 +48,18 @@ public interface AppRoleService extends IService { */ Boolean deleteRoleByIds(Long[] ids); + /** + * 导入角色信息方法 + * + * @param excelVOList 角色信息的Excel视图对象列表 + * @param bindingResult 数据绑定结果,用于校验 + */ R importRole(List excelVOList, BindingResult bindingResult); + /** + * 获取列表菜单对象 + * + * @return 列表菜单对象的实例 + */ + AppPageEntity listMenu(); } diff --git a/pigx-app-server/pigx-app-server-biz/src/main/java/com/pig4cloud/pigx/app/service/impl/AppIndexServiceImpl.java b/pigx-app-server/pigx-app-server-biz/src/main/java/com/pig4cloud/pigx/app/service/impl/AppIndexServiceImpl.java index 73e3831ed..2f84d4868 100644 --- a/pigx-app-server/pigx-app-server-biz/src/main/java/com/pig4cloud/pigx/app/service/impl/AppIndexServiceImpl.java +++ b/pigx-app-server/pigx-app-server-biz/src/main/java/com/pig4cloud/pigx/app/service/impl/AppIndexServiceImpl.java @@ -1,12 +1,18 @@ package com.pig4cloud.pigx.app.service.impl; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.CharUtil; +import cn.hutool.core.util.StrUtil; +import cn.hutool.json.JSONArray; +import cn.hutool.json.JSONObject; +import cn.hutool.json.JSONUtil; import com.baomidou.mybatisplus.core.toolkit.Wrappers; -import com.pig4cloud.pigx.app.api.entity.AppArticleEntity; import com.pig4cloud.pigx.app.api.entity.AppPageEntity; +import com.pig4cloud.pigx.app.api.entity.AppRole; import com.pig4cloud.pigx.app.api.entity.AppTabbarEntity; import com.pig4cloud.pigx.app.api.enums.PageTypeEnums; -import com.pig4cloud.pigx.app.mapper.AppArticleMapper; import com.pig4cloud.pigx.app.mapper.AppPageMapper; +import com.pig4cloud.pigx.app.mapper.AppRoleMapper; import com.pig4cloud.pigx.app.mapper.AppTabbarMapper; import com.pig4cloud.pigx.app.service.AppIndexService; import lombok.RequiredArgsConstructor; @@ -15,6 +21,7 @@ import org.springframework.stereotype.Service; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Objects; /** * app 页面控制 @@ -27,10 +34,10 @@ import java.util.Map; @RequiredArgsConstructor public class AppIndexServiceImpl implements AppIndexService { - private final AppArticleMapper appArticleMapper; - private final AppTabbarMapper appTabbarMapper; + private final AppRoleMapper appRoleMapper; + private final AppPageMapper appPageMapper; /** @@ -44,10 +51,7 @@ public class AppIndexServiceImpl implements AppIndexService { .orderByDesc(AppPageEntity::getCreateTime), false ); - List articleList = appArticleMapper - .selectList(Wrappers.lambdaQuery().orderByDesc(AppArticleEntity::getSort)); response.put("pages", appPageEntity); - response.put("article", articleList); return response; } @@ -73,8 +77,39 @@ public class AppIndexServiceImpl implements AppIndexService { */ @Override public AppPageEntity decorate(Integer pageType) { - return appPageMapper.selectOne(Wrappers.lambdaQuery().eq(AppPageEntity::getPageType, pageType) - .orderByDesc(AppPageEntity::getCreateTime), false); + AppPageEntity appPage = appPageMapper.selectOne( + Wrappers.lambdaQuery() + .eq(AppPageEntity::getPageType, pageType) + .orderByDesc(AppPageEntity::getCreateTime), + false + ); + + // 如果是工作台页面类型 + if (!Objects.equals(PageTypeEnums.WORKBENCH.getPageType(), pageType) || appPage == null) { + return appPage; + } + + AppRole appRole = appRoleMapper.selectById(1); // 角色ID根据实际业务调整 + List menuIdList = StrUtil.split(appRole.getMenuId(), CharUtil.COMMA); + + if (CollUtil.isEmpty(menuIdList)) { + return appPage; + } + + JSONArray pageDataArray = JSONUtil.parseArray(appPage.getPageData()); + for (Object groupObj : pageDataArray) { + JSONObject group = (JSONObject) groupObj; + JSONArray itemArray = group.getJSONObject("content").getJSONArray("data"); + + // 使用 removeIf 进行过滤 + itemArray.removeIf(item -> { + String menuId = ((JSONObject) item).getStr(AppPageEntity.Fields.id); + return StrUtil.isNotBlank(menuId) && !menuIdList.contains(menuId); + }); + } + + appPage.setPageData(pageDataArray.toStringPretty()); + return appPage; } } diff --git a/pigx-app-server/pigx-app-server-biz/src/main/java/com/pig4cloud/pigx/app/service/impl/AppRoleServiceImpl.java b/pigx-app-server/pigx-app-server-biz/src/main/java/com/pig4cloud/pigx/app/service/impl/AppRoleServiceImpl.java index b4a8293a4..8d8349838 100644 --- a/pigx-app-server/pigx-app-server-biz/src/main/java/com/pig4cloud/pigx/app/service/impl/AppRoleServiceImpl.java +++ b/pigx-app-server/pigx-app-server-biz/src/main/java/com/pig4cloud/pigx/app/service/impl/AppRoleServiceImpl.java @@ -17,16 +17,20 @@ package com.pig4cloud.pigx.app.service.impl; import cn.hutool.core.collection.CollUtil; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.pig4cloud.pigx.app.api.entity.AppPageEntity; import com.pig4cloud.pigx.app.api.entity.AppRole; +import com.pig4cloud.pigx.app.api.enums.PageTypeEnums; import com.pig4cloud.pigx.app.api.vo.AppRoleExcelVO; +import com.pig4cloud.pigx.app.mapper.AppPageMapper; import com.pig4cloud.pigx.app.mapper.AppRoleMapper; import com.pig4cloud.pigx.app.service.AppRoleService; import com.pig4cloud.pigx.common.core.exception.ErrorCodes; import com.pig4cloud.pigx.common.core.util.MsgUtils; import com.pig4cloud.pigx.common.core.util.R; import com.pig4cloud.pigx.common.excel.vo.ErrorMessage; -import lombok.AllArgsConstructor; +import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.validation.BindingResult; @@ -35,15 +39,21 @@ import java.util.List; import java.util.Set; /** - * app角色表 + * APP角色服务实现类 + *

+ * 提供对APP角色相关的业务操作实现。 * - * @author aeizzz - * @date 2022-12-07 09:52:03 + * @author lengleng + * @date 2025/05/29 */ @Service -@AllArgsConstructor +@RequiredArgsConstructor public class AppRoleServiceImpl extends ServiceImpl implements AppRoleService { + private final AppPageMapper appPageMapper; + + private final AppRoleMapper appRoleMapper; + @Override public List findRolesByUserId(Long userId) { return baseMapper.listRolesByUserId(userId); @@ -102,6 +112,17 @@ public class AppRoleServiceImpl extends ServiceImpl impl } + /** + * 获取列表菜单对象 + * + * @return 列表菜单对象的实例 + */ + @Override + public AppPageEntity listMenu() { + return appPageMapper.selectOne(Wrappers.lambdaQuery() + .eq(AppPageEntity::getPageType, PageTypeEnums.WORKBENCH.getPageType())); + } + private void insertExcelRole(AppRoleExcelVO excel) { AppRole appRole = new AppRole(); appRole.setRoleName(excel.getRoleName());