mirror of
https://gitee.com/youlaitech/youlai-mall.git
synced 2024-12-22 12:48:59 +08:00
refactor: 商品分页参数调整
This commit is contained in:
parent
0f9ffc8974
commit
10c9ab50c9
@ -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<PmsSpu> updateWrapper = new LambdaUpdateWrapper<PmsSpu>().eq(PmsSpu::getId, id);
|
||||
updateWrapper.set(spu.getStatus() != null, PmsSpu::getStatus, spu.getStatus());
|
||||
boolean update = iPmsSpuService.update(updateWrapper);
|
||||
|
@ -12,7 +12,7 @@ import java.util.List;
|
||||
@Mapper
|
||||
public interface SysUserMapper extends BaseMapper<SysUser> {
|
||||
|
||||
@InterceptorIgnore(storeAlias = "d")
|
||||
@InterceptorIgnore(deptAlias = "d")
|
||||
List<SysUser> list(Page<SysUser> page, SysUser user);
|
||||
|
||||
UserAuthDTO getByUsername(String username);
|
||||
|
@ -38,11 +38,11 @@ public class DataPermissionHandlerImpl implements DataPermissionHandler {
|
||||
if (ObjectUtils.isNotEmpty(annotation) && (method.getName().equals(methodName) || (method.getName() + "_COUNT").equals(methodName))) {
|
||||
// 获取当前的用户角色
|
||||
List<String> 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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -18,8 +18,7 @@ public @interface InterceptorIgnore {
|
||||
* <p>
|
||||
* 默认打开,需要注解关闭
|
||||
*/
|
||||
String dataPermission() default "0";
|
||||
|
||||
String storeAlias() default "";
|
||||
String deptAlias() default "";
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user