|
|
@@ -12,11 +12,13 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
import shop.alien.entity.store.SportsEquipmentFacility;
|
|
|
import shop.alien.entity.store.StoreImg;
|
|
|
+import shop.alien.entity.store.vo.SportsEquipmentFacilityCategoryVo;
|
|
|
import shop.alien.entity.store.vo.SportsEquipmentFacilityVo;
|
|
|
import shop.alien.mapper.SportsEquipmentFacilityMapper;
|
|
|
import shop.alien.mapper.StoreImgMapper;
|
|
|
import shop.alien.store.service.SportsEquipmentFacilityService;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -88,9 +90,15 @@ public class SportsEquipmentFacilityServiceImpl extends ServiceImpl<SportsEquipm
|
|
|
}
|
|
|
// 保存设施信息
|
|
|
boolean result = this.save(facility);
|
|
|
- if (result && !CollectionUtils.isEmpty(imageList)) {
|
|
|
- // 保存图片
|
|
|
- saveImages(facility.getId(), facility.getStoreId(), imageList);
|
|
|
+ if (result && !CollectionUtils.isEmpty(imageList) && facility.getFacilityCategory() != null) {
|
|
|
+ // 删除该分类下的旧图片(如果存在)
|
|
|
+ LambdaQueryWrapper<StoreImg> deleteWrapper = new LambdaQueryWrapper<>();
|
|
|
+ deleteWrapper.eq(StoreImg::getStoreId, facility.getStoreId())
|
|
|
+ .eq(StoreImg::getBusinessId, facility.getFacilityCategory())
|
|
|
+ .eq(StoreImg::getImgType, IMG_TYPE_SPORTS_EQUIPMENT);
|
|
|
+ storeImgMapper.delete(deleteWrapper);
|
|
|
+ // 保存新图片,business_id存储facility_category
|
|
|
+ saveImages(facility.getFacilityCategory(), facility.getStoreId(), imageList);
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
@@ -103,38 +111,94 @@ public class SportsEquipmentFacilityServiceImpl extends ServiceImpl<SportsEquipm
|
|
|
}
|
|
|
// 更新设施信息
|
|
|
boolean result = this.updateById(facility);
|
|
|
- if (result && !CollectionUtils.isEmpty(imageList)) {
|
|
|
- // 删除旧图片
|
|
|
+ if (result && !CollectionUtils.isEmpty(imageList) && facility.getFacilityCategory() != null) {
|
|
|
+ // 删除该分类下的旧图片
|
|
|
LambdaQueryWrapper<StoreImg> deleteWrapper = new LambdaQueryWrapper<>();
|
|
|
- deleteWrapper.eq(StoreImg::getBusinessId, facility.getId())
|
|
|
+ deleteWrapper.eq(StoreImg::getStoreId, facility.getStoreId())
|
|
|
+ .eq(StoreImg::getBusinessId, facility.getFacilityCategory())
|
|
|
.eq(StoreImg::getImgType, IMG_TYPE_SPORTS_EQUIPMENT);
|
|
|
storeImgMapper.delete(deleteWrapper);
|
|
|
- // 保存新图片
|
|
|
- saveImages(facility.getId(), facility.getStoreId(), imageList);
|
|
|
+ // 保存新图片,business_id存储facility_category
|
|
|
+ saveImages(facility.getFacilityCategory(), facility.getStoreId(), imageList);
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public boolean deleteFacility(Integer id) {
|
|
|
- // 删除图片
|
|
|
- LambdaQueryWrapper<StoreImg> deleteWrapper = new LambdaQueryWrapper<>();
|
|
|
- deleteWrapper.eq(StoreImg::getBusinessId, id)
|
|
|
- .eq(StoreImg::getImgType, IMG_TYPE_SPORTS_EQUIPMENT);
|
|
|
- storeImgMapper.delete(deleteWrapper);
|
|
|
+ // 注意:图片和设施没有关系,只和facility_category有关系,所以删除设施时不删除图片
|
|
|
// 删除设施
|
|
|
return this.removeById(id);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<SportsEquipmentFacilityCategoryVo> getCategorySummary(Integer storeId) {
|
|
|
+ List<SportsEquipmentFacilityCategoryVo> result = new ArrayList<>();
|
|
|
+
|
|
|
+ // 遍历所有分类(1:有氧区, 2:力量区, 3:单功能机械区)
|
|
|
+ for (int category = 1; category < FACILITY_CATEGORY_NAMES.length; category++) {
|
|
|
+ SportsEquipmentFacilityCategoryVo categoryVo = new SportsEquipmentFacilityCategoryVo();
|
|
|
+ categoryVo.setFacilityCategory(category);
|
|
|
+ categoryVo.setFacilityCategoryName(FACILITY_CATEGORY_NAMES[category]);
|
|
|
+
|
|
|
+ // 查询该分类下的设备列表(不分页)
|
|
|
+ LambdaQueryWrapper<SportsEquipmentFacility> facilityWrapper = new LambdaQueryWrapper<>();
|
|
|
+ facilityWrapper.eq(SportsEquipmentFacility::getStoreId, storeId)
|
|
|
+ .eq(SportsEquipmentFacility::getFacilityCategory, category);
|
|
|
+ facilityWrapper.orderByDesc(SportsEquipmentFacility::getCreatedTime);
|
|
|
+ List<SportsEquipmentFacility> facilityList = facilityMapper.selectList(facilityWrapper);
|
|
|
+
|
|
|
+ // 设置设备数量
|
|
|
+ categoryVo.setFacilityCount(facilityList != null ? facilityList.size() : 0);
|
|
|
+
|
|
|
+ // 转换为VO列表(不包含图片,避免重复查询)
|
|
|
+ List<SportsEquipmentFacilityVo> facilityVoList = new ArrayList<>();
|
|
|
+ if (!CollectionUtils.isEmpty(facilityList)) {
|
|
|
+ for (SportsEquipmentFacility facility : facilityList) {
|
|
|
+ SportsEquipmentFacilityVo vo = new SportsEquipmentFacilityVo();
|
|
|
+ BeanUtils.copyProperties(facility, vo);
|
|
|
+ // 设置分类名称
|
|
|
+ vo.setFacilityCategoryName(FACILITY_CATEGORY_NAMES[category]);
|
|
|
+ // 设置显示状态文本
|
|
|
+ if (facility.getDisplayInStoreDetail() != null) {
|
|
|
+ vo.setDisplayInStoreDetailText(facility.getDisplayInStoreDetail() == 1 ? "显示" : "隐藏");
|
|
|
+ }
|
|
|
+ facilityVoList.add(vo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ categoryVo.setFacilityList(facilityVoList);
|
|
|
+
|
|
|
+ // 查询该分类下的图片列表
|
|
|
+ LambdaQueryWrapper<StoreImg> imageWrapper = new LambdaQueryWrapper<>();
|
|
|
+ imageWrapper.eq(StoreImg::getStoreId, storeId)
|
|
|
+ .eq(StoreImg::getBusinessId, category)
|
|
|
+ .eq(StoreImg::getImgType, IMG_TYPE_SPORTS_EQUIPMENT);
|
|
|
+ imageWrapper.orderByAsc(StoreImg::getImgSort);
|
|
|
+ List<StoreImg> imageList = storeImgMapper.selectList(imageWrapper);
|
|
|
+ if (!CollectionUtils.isEmpty(imageList)) {
|
|
|
+ categoryVo.setImageList(imageList.stream().map(StoreImg::getImgUrl)
|
|
|
+ .collect(Collectors.toList()));
|
|
|
+ }
|
|
|
+
|
|
|
+ result.add(categoryVo);
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 保存图片
|
|
|
+ *
|
|
|
+ * @param facilityCategory 设施分类
|
|
|
+ * @param storeId 门店ID
|
|
|
+ * @param imageList 图片列表
|
|
|
*/
|
|
|
- private void saveImages(Integer facilityId, Integer storeId, List<String> imageList) {
|
|
|
+ private void saveImages(Integer facilityCategory, Integer storeId, List<String> imageList) {
|
|
|
for (int i = 0; i < imageList.size(); i++) {
|
|
|
StoreImg storeImg = new StoreImg();
|
|
|
storeImg.setStoreId(storeId);
|
|
|
storeImg.setImgType(IMG_TYPE_SPORTS_EQUIPMENT);
|
|
|
- storeImg.setBusinessId(facilityId);
|
|
|
+ storeImg.setBusinessId(facilityCategory); // business_id存储facility_category
|
|
|
storeImg.setImgUrl(imageList.get(i));
|
|
|
storeImg.setImgSort(i + 1);
|
|
|
storeImg.setImgDescription("运动器材设施实景图片");
|
|
|
@@ -157,9 +221,10 @@ public class SportsEquipmentFacilityServiceImpl extends ServiceImpl<SportsEquipm
|
|
|
if (facility.getDisplayInStoreDetail() != null) {
|
|
|
vo.setDisplayInStoreDetailText(facility.getDisplayInStoreDetail() == 1 ? "显示" : "隐藏");
|
|
|
}
|
|
|
- // 查询图片列表
|
|
|
+ // 查询图片列表,根据store_id和facility_category查询
|
|
|
LambdaQueryWrapper<StoreImg> imageWrapper = new LambdaQueryWrapper<>();
|
|
|
- imageWrapper.eq(StoreImg::getBusinessId, facility.getId())
|
|
|
+ imageWrapper.eq(StoreImg::getStoreId, facility.getStoreId())
|
|
|
+ .eq(StoreImg::getBusinessId, facility.getFacilityCategory())
|
|
|
.eq(StoreImg::getImgType, IMG_TYPE_SPORTS_EQUIPMENT);
|
|
|
imageWrapper.orderByAsc(StoreImg::getImgSort);
|
|
|
List<StoreImg> imageList = storeImgMapper.selectList(imageWrapper);
|