修复:对齐作品和购物车美甲师可用性

This commit is contained in:
xiaowang
2026-03-27 11:51:43 +08:00
parent b1fc6c3b79
commit d2c693e6a1
6 changed files with 172 additions and 17 deletions
@@ -9,16 +9,14 @@ import com.xiaowang.yuminailcore.entity.CouponDO;
import com.xiaowang.yuminailcore.entity.ProductDO;
import com.xiaowang.yuminailcore.entity.ShopDO;
import com.xiaowang.yuminailcore.entity.TagDO;
import com.xiaowang.yuminailcore.entity.UserDO;
import com.xiaowang.yuminailcore.mapper.CouponMapper;
import com.xiaowang.yuminailcore.mapper.ProductMapper;
import com.xiaowang.yuminailcore.mapper.ShopMapper;
import com.xiaowang.yuminailcore.mapper.TagMapper;
import com.xiaowang.yuminailcore.mapper.UserMapper;
import com.xiaowang.yuminailcore.service.ObjectStorageFileService;
import com.xiaowang.yuminailcore.service.ProductService;
import com.xiaowang.yuminailcore.service.TagService;
import com.xiaowang.yuminailcore.support.UserShopBindingSupport;
import com.xiaowang.yuminailcore.support.BookableArtistSupport;
import com.xiaowang.yuminailcore.vo.ObjectStorageFileVO;
import com.xiaowang.yuminailcore.vo.PageResultVO;
import com.xiaowang.yuminailcore.vo.ProductVO;
@@ -48,11 +46,10 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im
private final ProductMapper productMapper;
private final TagService tagService;
private final ObjectStorageFileService objectStorageFileService;
private final UserMapper userMapper;
private final CouponMapper couponMapper;
private final ShopMapper shopMapper;
private final TagMapper tagMapper;
private final UserShopBindingSupport userShopBindingSupport;
private final BookableArtistSupport bookableArtistSupport;
@Override
public Long createProduct(ProductDTO productDTO) {
@@ -66,7 +63,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im
productDO.setPrice(productDTO.getPrice());
productDO.setTags(productDTO.getTags());
productDO.setApproximateDuration(productDTO.getApproximateDuration());
productDO.setBookableArtists(productDTO.getBookableArtists());
productDO.setBookableArtists(bookableArtistSupport.filterValidBookableArtists(productDTO.getShopId(), productDTO.getBookableArtists()));
productDO.setAvailableCoupons(productDTO.getAvailableCoupons());
productDO.setIsDelete(0);
productMapper.insert(productDO);
@@ -88,7 +85,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im
productDO.setPrice(productDTO.getPrice());
productDO.setTags(productDTO.getTags());
productDO.setApproximateDuration(productDTO.getApproximateDuration());
productDO.setBookableArtists(productDTO.getBookableArtists());
productDO.setBookableArtists(bookableArtistSupport.filterValidBookableArtists(productDTO.getShopId(), productDTO.getBookableArtists()));
productDO.setAvailableCoupons(productDTO.getAvailableCoupons());
return productMapper.updateById(productDO) > 0;
}
@@ -189,7 +186,10 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im
productVO.setLikeCount(productDO.getLikeCount());
productVO.setCollectCount(productDO.getCollectCount());
productVO.setApproximateDuration(productDO.getApproximateDuration());
String validBookableArtists = bookableArtistSupport.filterValidBookableArtists(productDO.getShopId(), productDO.getBookableArtists());
productVO.setBookableArtists(productDO.getBookableArtists());
productVO.setAvailableBookableArtistCount(countBookableArtists(validBookableArtists));
productVO.setBookableArtistRestricted(StringUtils.hasText(productDO.getBookableArtists()));
productVO.setAvailableCoupons(productDO.getAvailableCoupons());
productVO.setCreateTime(productDO.getCreateTime());
productVO.setUpdateTime(productDO.getUpdateTime());
@@ -290,15 +290,8 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im
throw new RuntimeException("可预约美甲师配置格式不正确");
}
UserDO artist = userMapper.selectById(artistId);
if (artist == null || Integer.valueOf(1).equals(artist.getIsDelete())) {
throw new RuntimeException("存在无效的美甲师配置");
}
if (!Integer.valueOf(3).equals(artist.getType())) {
throw new RuntimeException("存在非美甲师账号被配置到可预约列表");
}
if (!userShopBindingSupport.isUserAccessibleInShop(artistId, shopId)) {
throw new RuntimeException("不可跨店铺配置可预约美甲师");
if (!bookableArtistSupport.isValidBookableArtist(shopId, artistId)) {
throw new RuntimeException("存在无效、已停用或不属于当前店铺的美甲师配置");
}
}
}
@@ -345,6 +338,16 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im
return shopDO == null ? null : shopDO.getShopName();
}
private int countBookableArtists(String bookableArtists) {
if (!StringUtils.hasText(bookableArtists)) {
return 0;
}
return (int) java.util.Arrays.stream(bookableArtists.split(","))
.map(String::trim)
.filter(StringUtils::hasText)
.count();
}
private boolean containsAnyTagId(String tags, Set<String> targetTagIds) {
if (!StringUtils.hasText(tags) || targetTagIds == null || targetTagIds.isEmpty()) {
return false;
@@ -0,0 +1,62 @@
package com.xiaowang.yuminailcore.support;
import com.xiaowang.yuminailcore.entity.UserDO;
import com.xiaowang.yuminailcore.mapper.UserMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.stream.Collectors;
@Component
@RequiredArgsConstructor
public class BookableArtistSupport {
private final UserMapper userMapper;
private final UserShopBindingSupport userShopBindingSupport;
public boolean isValidBookableArtist(Long shopId, Long artistId) {
if (artistId == null || artistId <= 0) {
return false;
}
UserDO artist = userMapper.selectById(artistId);
if (artist == null || Integer.valueOf(1).equals(artist.getIsDelete())) {
return false;
}
if (!Integer.valueOf(3).equals(artist.getType())) {
return false;
}
if (!Integer.valueOf(1).equals(artist.getStatus())) {
return false;
}
return shopId == null || shopId <= 0 || userShopBindingSupport.isUserAccessibleInShop(artistId, shopId);
}
public String filterValidBookableArtists(Long shopId, String rawBookableArtists) {
if (!StringUtils.hasText(rawBookableArtists)) {
return "";
}
Set<Long> validArtistIds = new LinkedHashSet<>();
for (String artistIdText : rawBookableArtists.split(",")) {
if (!StringUtils.hasText(artistIdText)) {
continue;
}
try {
Long artistId = Long.parseLong(artistIdText.trim());
if (isValidBookableArtist(shopId, artistId)) {
validArtistIds.add(artistId);
}
} catch (NumberFormatException ignored) {
// Ignore invalid configured IDs and only expose currently valid artists.
}
}
return validArtistIds.stream()
.map(String::valueOf)
.collect(Collectors.joining(","));
}
}
@@ -92,6 +92,16 @@ public class ProductVO {
*/
private String bookableArtists;
/**
* 当前仍可预约的美甲师数量
*/
private Integer availableBookableArtistCount;
/**
* 商品是否配置了限定美甲师
*/
private Boolean bookableArtistRestricted;
/**
* 可用的优惠券ID集合,多个ID以逗号分隔
*/