|
|
@@ -70,7 +70,7 @@ public class ProductService {
|
|
|
return productMapper.selectById(id);
|
|
|
}
|
|
|
|
|
|
- public Result<Map<String, Object>> list(ProductListQueryDTO query, Long userId) {
|
|
|
+ public Result<Map<String, Object>> list(ProductListQueryDTO query, Long userId, String role) {
|
|
|
Page<Product> page = new Page<>(query.getPage(), query.getSize());
|
|
|
LambdaQueryWrapper<Product> wrapper = new LambdaQueryWrapper<Product>()
|
|
|
.eq(Product::getStatus, "on_shelf");
|
|
|
@@ -97,6 +97,13 @@ wrapper.in(Product::getId, productIds)
|
|
|
if (userId == null) {
|
|
|
wrapper.ne(Product::getMemberEligible, "yes");
|
|
|
}
|
|
|
+ // 可见角色过滤:visible_roles 为 NULL 时全部可见,否则仅匹配用户角色
|
|
|
+ if (userId == null) {
|
|
|
+ wrapper.isNull(Product::getVisibleRoles);
|
|
|
+ } else if (role != null && !role.isEmpty()) {
|
|
|
+ wrapper.and(w -> w.isNull(Product::getVisibleRoles)
|
|
|
+ .or().apply("JSON_CONTAINS(visible_roles, JSON_QUOTE({0}))", role));
|
|
|
+ }
|
|
|
if (query.getProductType() != null && !query.getProductType().isEmpty()) {
|
|
|
wrapper.eq(Product::getProductType, query.getProductType());
|
|
|
}
|
|
|
@@ -482,6 +489,7 @@ wrapper.in(Product::getId, productIds)
|
|
|
copy.setDeliveryMethod(original.getDeliveryMethod());
|
|
|
copy.setMinQuantity(original.getMinQuantity());
|
|
|
copy.setSortOrder(original.getSortOrder());
|
|
|
+ copy.setVisibleRoles(original.getVisibleRoles());
|
|
|
copy.setCreatedAt(new Date());
|
|
|
copy.setUpdatedAt(new Date());
|
|
|
productMapper.insert(copy);
|