商品添加店铺权限数据控制过滤器

This commit is contained in:
liyj 2025-06-16 16:41:11 +08:00
parent 76e14d4bd0
commit 108ab7443f

View File

@ -0,0 +1,26 @@
package com.suisung.mall.common.utils;
import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import static com.suisung.mall.common.utils.ContextUtil.getCurrentUser;
public class FilterUtils <T>{
/**
* 应用店铺数据权限过滤
* @param queryWrapper 查询条件
*/
public void applyStoreFilter(QueryWrapper<T> queryWrapper) {
if (getCurrentUser().isStore()) {
queryWrapper.eq("store_id", getCurrentUserStoreId());
}
}
/**
* 获取当前用户的店铺ID店员返回店铺ID管理员返回null
*/
public Integer getCurrentUserStoreId() {
return getCurrentUser().isStore() ?
Convert.toInt(getCurrentUser().getStore_id()) :
null;
}
}