diff --git a/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/controller/admin/GoodsController.java b/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/controller/admin/GoodsController.java index f2fcc1a81..1819c5b0a 100644 --- a/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/controller/admin/GoodsController.java +++ b/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/controller/admin/GoodsController.java @@ -32,8 +32,8 @@ public class GoodsController { @ApiOperation(value = "商品分页列表") @GetMapping("/page") public Result list( - @ApiParam("页码") long pageNum, - @ApiParam("每页数量") long pageSize, + @ApiParam(value = "页码", example = "1") long pageNum, + @ApiParam(value = "每页数量", example = "10") long pageSize, @ApiParam("商品分类ID") Long categoryId, @ApiParam("商品名称") String name ) { @@ -44,42 +44,47 @@ public class GoodsController { @ApiOperation(value = "商品详情") @ApiImplicitParam(name = "id", value = "商品id", required = true, paramType = "path", dataType = "Long") @GetMapping("/{id}") - public Result detail(@PathVariable Long id) { + public Result detail( + @ApiParam("商品ID") @PathVariable Long id + ) { GoodsDetailVO goodsDetail = iPmsSpuService.getGoodsById(id); return Result.success(goodsDetail); } @ApiOperation(value = "新增商品") - @ApiImplicitParam(name = "goodsForm", value = "实体JSON对象", required = true, paramType = "body", dataType = "GoodsFormDTO") @PostMapping - public Result add(@RequestBody GoodsFormDTO goodsForm) { + public Result addGoods( + @RequestBody GoodsFormDTO goodsForm + ) { boolean result = iPmsSpuService.addGoods(goodsForm); return Result.judge(result); } @ApiOperation(value = "修改商品") - @ApiImplicitParam(name = "id", value = "商品id", required = true, paramType = "path", dataType = "Long") @PutMapping(value = "/{id}") - public Result update(@PathVariable Long id, @RequestBody GoodsFormDTO goods) { + public Result update( + @ApiParam("商品ID") @PathVariable Long id, + @RequestBody GoodsFormDTO goods + ) { boolean result = iPmsSpuService.updateGoods(goods); return Result.judge(result); } @ApiOperation(value = "删除商品") - @ApiImplicitParam(name = "ids", value = "id集合,以英文逗号','分隔", required = true, paramType = "query", dataType = "String") @DeleteMapping("/{ids}") - public Result delete(@PathVariable String ids) { + public Result delete( + @ApiParam("id集合,以英文逗号(,)分隔") @PathVariable String ids + ) { boolean result = iPmsSpuService.removeByGoodsIds(Arrays.asList(ids.split(",")).stream().map(id -> Long.parseLong(id)).collect(Collectors.toList())); return Result.judge(result); } @ApiOperation(value = "选择性修改商品") - @ApiImplicitParams({ - @ApiImplicitParam(name = "id", value = "商品ID", required = true, paramType = "path", dataType = "Long"), - @ApiImplicitParam(name = "spu", value = "实体JSON对象", required = true, paramType = "body", dataType = "PmsSpu") - }) @PatchMapping(value = "/{id}") - public Result patch(@PathVariable Integer id, @RequestBody PmsSpu spu) { + public Result patch( + @ApiParam("商品ID") @PathVariable Long id, + @RequestBody PmsSpu spu + ) { LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper().eq(PmsSpu::getId, id); updateWrapper.set(spu.getStatus() != null, PmsSpu::getStatus, spu.getStatus()); boolean update = iPmsSpuService.update(updateWrapper); diff --git a/youlai-admin/admin-boot/src/main/java/com/youlai/admin/mapper/SysUserMapper.java b/youlai-admin/admin-boot/src/main/java/com/youlai/admin/mapper/SysUserMapper.java index c3f55aa4b..1778b09ea 100644 --- a/youlai-admin/admin-boot/src/main/java/com/youlai/admin/mapper/SysUserMapper.java +++ b/youlai-admin/admin-boot/src/main/java/com/youlai/admin/mapper/SysUserMapper.java @@ -12,7 +12,7 @@ import java.util.List; @Mapper public interface SysUserMapper extends BaseMapper { - @InterceptorIgnore(storeAlias = "d") + @InterceptorIgnore(deptAlias = "d") List list(Page page, SysUser user); UserAuthDTO getByUsername(String username); diff --git a/youlai-common/common-mybatis/src/main/java/com/youlai/common/mybatis/handler/DataPermissionHandlerImpl.java b/youlai-common/common-mybatis/src/main/java/com/youlai/common/mybatis/handler/DataPermissionHandlerImpl.java index f92083aa8..c4a35432f 100644 --- a/youlai-common/common-mybatis/src/main/java/com/youlai/common/mybatis/handler/DataPermissionHandlerImpl.java +++ b/youlai-common/common-mybatis/src/main/java/com/youlai/common/mybatis/handler/DataPermissionHandlerImpl.java @@ -38,11 +38,11 @@ public class DataPermissionHandlerImpl implements DataPermissionHandler { if (ObjectUtils.isNotEmpty(annotation) && (method.getName().equals(methodName) || (method.getName() + "_COUNT").equals(methodName))) { // 获取当前的用户角色 List roles = JwtUtils.getRoles(); - if( !roles.isEmpty() && roles.contains(GlobalConstants.ROOT_ROLE_CODE)) { + if (!roles.isEmpty() && roles.contains(GlobalConstants.ROOT_ROLE_CODE)) { // 如果是超级管理员则放行 return where; - }else{ - return dataScopeFilter(annotation.dataPermission(),annotation.storeAlias(), where); + } else { + return dataScopeFilter(annotation.deptAlias(), where); } } } @@ -58,33 +58,30 @@ public class DataPermissionHandlerImpl implements DataPermissionHandler { * @param where 当前查询条件 * @return 构建后查询条件 */ - public static Expression dataScopeFilter(String dataPermission,String storeAlias, Expression where) { - Expression expression = null; - if(dataPermission.equals("1")){ - return where; - }else{ - EqualsTo equalsTo = new EqualsTo(new Column(StrUtil.isEmpty(storeAlias)?"id":storeAlias+".id"),getDeptId()); - expression = ObjectUtils.isNotEmpty(expression) ? new AndExpression(expression, equalsTo) : equalsTo; - LikeExpression likeExpression = new LikeExpression(); - Function left = new Function(); - left.setName("concat"); - left.setParameters(new ExpressionList().addExpressions(new StringValue(","),new Column("tree_path"),new StringValue(","))); - likeExpression.setLeftExpression(left); - Function right = new Function(); - right.setName("concat"); - right.setParameters(new ExpressionList().addExpressions(new StringValue("%,"),getDeptId(),new StringValue("%,"))); - likeExpression.setRightExpression(right); - expression = ObjectUtils.isNotEmpty(expression) ? new OrExpression(expression, likeExpression) : expression; - } + public static Expression dataScopeFilter(String deptAlias, Expression where) { + Expression expression = new EqualsTo(new Column(StrUtil.isEmpty(deptAlias) ? "id" : deptAlias + ".id"), getDeptId()); + LikeExpression likeExpression = new LikeExpression(); + Function left = new Function(); + left.setName("concat"); + left.setParameters(new ExpressionList().addExpressions(new StringValue(","), new Column("tree_path"), new StringValue(","))); + likeExpression.setLeftExpression(left); + Function right = new Function(); + right.setName("concat"); + right.setParameters(new ExpressionList().addExpressions(new StringValue("%,"), getDeptId(), new StringValue("%,"))); + likeExpression.setRightExpression(right); + expression = ObjectUtils.isNotEmpty(expression) ? new OrExpression(expression, likeExpression) : expression; + return ObjectUtils.isNotEmpty(where) ? new AndExpression(where, new Parenthesis(expression)) : expression; } /** * 当前用户的部门id + * * @return */ - private static Expression getDeptId(){ - return new LongValue(JwtUtils.getJwtPayload().getLong("deptId")); + private static Expression getDeptId() { + LongValue deptId = new LongValue(JwtUtils.getJwtPayload().getLong("deptId")); + return deptId; } diff --git a/youlai-common/common-mybatis/src/main/java/com/youlai/common/mybatis/handler/InterceptorIgnore.java b/youlai-common/common-mybatis/src/main/java/com/youlai/common/mybatis/handler/InterceptorIgnore.java index d8e8194ee..64eabeac9 100644 --- a/youlai-common/common-mybatis/src/main/java/com/youlai/common/mybatis/handler/InterceptorIgnore.java +++ b/youlai-common/common-mybatis/src/main/java/com/youlai/common/mybatis/handler/InterceptorIgnore.java @@ -18,8 +18,7 @@ public @interface InterceptorIgnore { *

* 默认打开,需要注解关闭 */ - String dataPermission() default "0"; - String storeAlias() default ""; + String deptAlias() default ""; }