From 844b27d298daca54e54d6f98c61a93da88909e5c Mon Sep 17 00:00:00 2001
From: leomonM <2233021400@qq.com>
Date: Fri, 22 Aug 2025 19:19:00 +0800
Subject: [PATCH] 枚举字段
---
oying-system/src/main/java/com/oying/modules/pc/category/service/impl/PlatformCategoryServiceImpl.java | 64 ++++++++++++++++++++-----------
1 files changed, 41 insertions(+), 23 deletions(-)
diff --git a/oying-system/src/main/java/com/oying/modules/pc/category/service/impl/PlatformCategoryServiceImpl.java b/oying-system/src/main/java/com/oying/modules/pc/category/service/impl/PlatformCategoryServiceImpl.java
index 5b220a6..0424129 100644
--- a/oying-system/src/main/java/com/oying/modules/pc/category/service/impl/PlatformCategoryServiceImpl.java
+++ b/oying-system/src/main/java/com/oying/modules/pc/category/service/impl/PlatformCategoryServiceImpl.java
@@ -1,26 +1,35 @@
package com.oying.modules.pc.category.service.impl;
+import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.bean.copier.CopyOptions;
+import cn.hutool.core.collection.CollectionUtil;
+import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.ObjUtil;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.oying.exception.EntityExistException;
-import com.oying.modules.pc.category.converter.PlatformCategoryDtoAssembler;
+import com.oying.exception.EntityNotFoundException;
+import com.oying.modules.pc.category.converter.PlatformCategoryAssembler;
import com.oying.modules.pc.category.domain.PlatformCategory;
import com.oying.modules.pc.category.domain.dto.PlatformCategoryCreateRequest;
import com.oying.modules.pc.category.domain.dto.PlatformCategoryQueryCriteria;
import com.oying.modules.pc.category.domain.dto.PlatformCategoryUpdateDto;
-import com.oying.modules.pc.category.domain.dto.PlatformCategoryUpdateRequest;
import com.oying.modules.pc.category.mapper.PlatformCategoryMapper;
import com.oying.modules.pc.category.service.PlatformCategoryService;
+import com.oying.modules.pc.common.ValueUpdate;
+import com.oying.modules.pc.store.domain.StoreQualification;
+import com.oying.modules.pc.utils.ImageUtils;
+import com.oying.service.BucketStorageService;
import com.oying.utils.PageResult;
import com.oying.utils.PageUtil;
-import com.oying.utils.SecurityUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Optional;
+import java.util.stream.Collectors;
/**
* 平台类目服务实现
@@ -33,6 +42,7 @@
public class PlatformCategoryServiceImpl extends ServiceImpl<PlatformCategoryMapper, PlatformCategory> implements PlatformCategoryService {
private final PlatformCategoryMapper platformCategoryMapper;
+ private final BucketStorageService bucketStorageService;
@Override
public PageResult<PlatformCategory> queryAll(PlatformCategoryQueryCriteria criteria, Page<Object> page) {
@@ -45,18 +55,16 @@
}
@Override
+ public List<PlatformCategory> queryBatchIds(List<Long> ids) {
+ LambdaQueryWrapper<PlatformCategory> wrapper = new LambdaQueryWrapper<>();
+ wrapper.in(PlatformCategory::getCategoryId, ids);
+ return platformCategoryMapper.selectList(wrapper);
+ }
+
+ @Override
@Transactional(rollbackFor = Exception.class)
public void create(PlatformCategoryCreateRequest request) {
-
- PlatformCategory platformCategoryCreate = new PlatformCategory();
- platformCategoryCreate.setName(request.getName());
- platformCategoryCreate.setSortWeight(request.getSortWeight());
- platformCategoryCreate.setIconId(request.getIconUploadFileId());
- platformCategoryCreate.setActive(request.getActive());
- platformCategoryCreate.setCreateBy(SecurityUtils.getCurrentUserId());
-
- // 使用处理图标文件
- platformCategoryMapper.insert(platformCategoryCreate);
+ platformCategoryMapper.insert(PlatformCategoryAssembler.to(request));
}
@Override
@@ -66,25 +74,35 @@
Long categoryId = updateDto.getCategoryId();
PlatformCategory existingPlatformCategory = this.getById(categoryId);
if (ObjUtil.isEmpty(existingPlatformCategory)) {
- throw new EntityExistException(PlatformCategory.class, "categoryId", Optional.ofNullable(categoryId).map(Object::toString).orElse("null"));
+ throw new EntityNotFoundException(PlatformCategory.class, "categoryId", Optional.ofNullable(categoryId).map(Object::toString).orElse("null"));
}
- PlatformCategory platformCategoryUpdate = new PlatformCategory();
- platformCategoryUpdate.setCategoryId(updateDto.getCategoryId());
- platformCategoryUpdate.setName(updateDto.getName());
- platformCategoryUpdate.setSortWeight(updateDto.getSortWeight());
- platformCategoryUpdate.setIconId(updateDto.getIconUploadFileId());
- platformCategoryUpdate.setActive(updateDto.getActive());
- existingPlatformCategory.copy(platformCategoryUpdate);
- existingPlatformCategory.setUpdateBy(SecurityUtils.getCurrentUserId());
+ // 新的类目数据
+ PlatformCategory newPlatformCategory = PlatformCategoryAssembler.to(updateDto);
+ // 记录图片值的变更
+ ValueUpdate<Long> iconValueUpdate = new ValueUpdate<>(newPlatformCategory.getIconId(), existingPlatformCategory.getIconId());
+ // 填充新的数据
+ existingPlatformCategory.copy(newPlatformCategory);
platformCategoryMapper.updateById(existingPlatformCategory);
+ // 删除旧图片原纪录
+ if (iconValueUpdate.isChangeAndOldValueNotEmpty()) {
+ bucketStorageService.deleteAll(ListUtil.toList(iconValueUpdate.getOldValue()));
+ }
- // 使用处理图标文件
}
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteAll(List<Long> ids) {
+ List<PlatformCategory> existingPlatformCategories = this.queryBatchIds(ids);
+ if (CollectionUtil.isEmpty(existingPlatformCategories)) {
+ throw new EntityNotFoundException(PlatformCategory.class, "platformCategoryIds", ids.toString());
+ }
platformCategoryMapper.deleteBatchIds(ids);
+ List<Long> storageIds = existingPlatformCategories.stream().map(PlatformCategory::getIconId).collect(Collectors.toList());
+ // 删除旧图片原记录
+ if (CollectionUtil.isNotEmpty(storageIds)) {
+ bucketStorageService.deleteAll(storageIds);
+ }
}
}
--
Gitblit v1.9.3