refactor: 商品分页参数调整

This commit is contained in:
郝先瑞 2022-01-05 23:51:15 +08:00
parent 0f9ffc8974
commit 10c9ab50c9
4 changed files with 41 additions and 40 deletions

View File

@ -32,8 +32,8 @@ public class GoodsController {
@ApiOperation(value = "商品分页列表") @ApiOperation(value = "商品分页列表")
@GetMapping("/page") @GetMapping("/page")
public Result list( public Result list(
@ApiParam("页码") long pageNum, @ApiParam(value = "页码", example = "1") long pageNum,
@ApiParam("每页数量") long pageSize, @ApiParam(value = "每页数量", example = "10") long pageSize,
@ApiParam("商品分类ID") Long categoryId, @ApiParam("商品分类ID") Long categoryId,
@ApiParam("商品名称") String name @ApiParam("商品名称") String name
) { ) {
@ -44,42 +44,47 @@ public class GoodsController {
@ApiOperation(value = "商品详情") @ApiOperation(value = "商品详情")
@ApiImplicitParam(name = "id", value = "商品id", required = true, paramType = "path", dataType = "Long") @ApiImplicitParam(name = "id", value = "商品id", required = true, paramType = "path", dataType = "Long")
@GetMapping("/{id}") @GetMapping("/{id}")
public Result detail(@PathVariable Long id) { public Result detail(
@ApiParam("商品ID") @PathVariable Long id
) {
GoodsDetailVO goodsDetail = iPmsSpuService.getGoodsById(id); GoodsDetailVO goodsDetail = iPmsSpuService.getGoodsById(id);
return Result.success(goodsDetail); return Result.success(goodsDetail);
} }
@ApiOperation(value = "新增商品") @ApiOperation(value = "新增商品")
@ApiImplicitParam(name = "goodsForm", value = "实体JSON对象", required = true, paramType = "body", dataType = "GoodsFormDTO")
@PostMapping @PostMapping
public Result add(@RequestBody GoodsFormDTO goodsForm) { public Result addGoods(
@RequestBody GoodsFormDTO goodsForm
) {
boolean result = iPmsSpuService.addGoods(goodsForm); boolean result = iPmsSpuService.addGoods(goodsForm);
return Result.judge(result); return Result.judge(result);
} }
@ApiOperation(value = "修改商品") @ApiOperation(value = "修改商品")
@ApiImplicitParam(name = "id", value = "商品id", required = true, paramType = "path", dataType = "Long")
@PutMapping(value = "/{id}") @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); boolean result = iPmsSpuService.updateGoods(goods);
return Result.judge(result); return Result.judge(result);
} }
@ApiOperation(value = "删除商品") @ApiOperation(value = "删除商品")
@ApiImplicitParam(name = "ids", value = "id集合,以英文逗号','分隔", required = true, paramType = "query", dataType = "String")
@DeleteMapping("/{ids}") @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())); boolean result = iPmsSpuService.removeByGoodsIds(Arrays.asList(ids.split(",")).stream().map(id -> Long.parseLong(id)).collect(Collectors.toList()));
return Result.judge(result); return Result.judge(result);
} }
@ApiOperation(value = "选择性修改商品") @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}") @PatchMapping(value = "/{id}")
public Result patch(@PathVariable Integer id, @RequestBody PmsSpu spu) { public Result patch(
@ApiParam("商品ID") @PathVariable Long id,
@RequestBody PmsSpu spu
) {
LambdaUpdateWrapper<PmsSpu> updateWrapper = new LambdaUpdateWrapper<PmsSpu>().eq(PmsSpu::getId, id); LambdaUpdateWrapper<PmsSpu> updateWrapper = new LambdaUpdateWrapper<PmsSpu>().eq(PmsSpu::getId, id);
updateWrapper.set(spu.getStatus() != null, PmsSpu::getStatus, spu.getStatus()); updateWrapper.set(spu.getStatus() != null, PmsSpu::getStatus, spu.getStatus());
boolean update = iPmsSpuService.update(updateWrapper); boolean update = iPmsSpuService.update(updateWrapper);

View File

@ -12,7 +12,7 @@ import java.util.List;
@Mapper @Mapper
public interface SysUserMapper extends BaseMapper<SysUser> { public interface SysUserMapper extends BaseMapper<SysUser> {
@InterceptorIgnore(storeAlias = "d") @InterceptorIgnore(deptAlias = "d")
List<SysUser> list(Page<SysUser> page, SysUser user); List<SysUser> list(Page<SysUser> page, SysUser user);
UserAuthDTO getByUsername(String username); UserAuthDTO getByUsername(String username);

View File

@ -42,7 +42,7 @@ public class DataPermissionHandlerImpl implements DataPermissionHandler {
// 如果是超级管理员则放行 // 如果是超级管理员则放行
return where; return where;
} else { } else {
return dataScopeFilter(annotation.dataPermission(),annotation.storeAlias(), where); return dataScopeFilter(annotation.deptAlias(), where);
} }
} }
} }
@ -58,13 +58,8 @@ public class DataPermissionHandlerImpl implements DataPermissionHandler {
* @param where 当前查询条件 * @param where 当前查询条件
* @return 构建后查询条件 * @return 构建后查询条件
*/ */
public static Expression dataScopeFilter(String dataPermission,String storeAlias, Expression where) { public static Expression dataScopeFilter(String deptAlias, Expression where) {
Expression expression = null; Expression expression = new EqualsTo(new Column(StrUtil.isEmpty(deptAlias) ? "id" : deptAlias + ".id"), getDeptId());
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(); LikeExpression likeExpression = new LikeExpression();
Function left = new Function(); Function left = new Function();
left.setName("concat"); left.setName("concat");
@ -75,16 +70,18 @@ public class DataPermissionHandlerImpl implements DataPermissionHandler {
right.setParameters(new ExpressionList().addExpressions(new StringValue("%,"), getDeptId(), new StringValue("%,"))); right.setParameters(new ExpressionList().addExpressions(new StringValue("%,"), getDeptId(), new StringValue("%,")));
likeExpression.setRightExpression(right); likeExpression.setRightExpression(right);
expression = ObjectUtils.isNotEmpty(expression) ? new OrExpression(expression, likeExpression) : expression; expression = ObjectUtils.isNotEmpty(expression) ? new OrExpression(expression, likeExpression) : expression;
}
return ObjectUtils.isNotEmpty(where) ? new AndExpression(where, new Parenthesis(expression)) : expression; return ObjectUtils.isNotEmpty(where) ? new AndExpression(where, new Parenthesis(expression)) : expression;
} }
/** /**
* 当前用户的部门id * 当前用户的部门id
*
* @return * @return
*/ */
private static Expression getDeptId() { private static Expression getDeptId() {
return new LongValue(JwtUtils.getJwtPayload().getLong("deptId")); LongValue deptId = new LongValue(JwtUtils.getJwtPayload().getLong("deptId"));
return deptId;
} }

View File

@ -18,8 +18,7 @@ public @interface InterceptorIgnore {
* <p> * <p>
* 默认打开需要注解关闭 * 默认打开需要注解关闭
*/ */
String dataPermission() default "0";
String storeAlias() default ""; String deptAlias() default "";
} }