Bläddra i källkod

优化了照片组管理

hyy 6 månader sedan
förälder
incheckning
9f1bf99fa4

+ 9 - 0
yudao-module-museums/yudao-module-museums-biz/src/main/java/cn/iocoder/yudao/module/museums/controller/admin/photos/PhotosController.java

@@ -92,4 +92,13 @@ public class PhotosController {
                         BeanUtils.toBean(list, PhotosRespVO.class));
     }
 
+    @GetMapping("/photos")
+    @Operation(summary = "获得指定照片组的照片列表")
+    @PreAuthorize("@ss.hasPermission('museums:photos:query')")
+    public CommonResult<List<PhotosRespVO>> getPhotosByGroupId(@RequestParam Integer groupId) {
+        List<PhotosDO> photosList = photosService.getPhotosByGroupId(groupId);
+        return success(BeanUtils.toBean(photosList, PhotosRespVO.class));
+    }
+
+
 }

+ 4 - 0
yudao-module-museums/yudao-module-museums-biz/src/main/java/cn/iocoder/yudao/module/museums/dal/mysql/photos/PhotosMapper.java

@@ -8,6 +8,7 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
 import cn.iocoder.yudao.module.museums.dal.dataobject.photos.PhotosDO;
 import org.apache.ibatis.annotations.Mapper;
 import cn.iocoder.yudao.module.museums.controller.admin.photos.vo.*;
+import org.apache.ibatis.annotations.Select;
 
 /**
  * 博物馆照片 Mapper
@@ -26,4 +27,7 @@ public interface PhotosMapper extends BaseMapperX<PhotosDO> {
                 .orderByDesc(PhotosDO::getId));
     }
 
+    @Select("SELECT * FROM museums_photos WHERE group_id = #{groupId} AND deleted = 0")
+    List<PhotosDO> selectByGroupId(Integer groupId);
+
 }

+ 8 - 7
yudao-module-museums/yudao-module-museums-biz/src/main/java/cn/iocoder/yudao/module/museums/service/photos/PhotosService.java

@@ -53,11 +53,12 @@ public interface PhotosService {
      */
     PageResult<PhotosDO> getPhotosPage(PhotosPageReqVO pageReqVO);
 
-//    /**
-//     * 保存照片
-//     *
-//     * @param file 照片压缩包
-//     * @param groupId 照片组ID
-//     */
-//    void savePhotos(MultipartFile file, Integer groupId);
+    /**
+     * 根据照片组 ID 获得照片列表
+     *
+     * @param groupId 照片组 ID
+     * @return 照片列表
+     */
+    List<PhotosDO> getPhotosByGroupId(Integer groupId);
+
 }

+ 5 - 32
yudao-module-museums/yudao-module-museums-biz/src/main/java/cn/iocoder/yudao/module/museums/service/photos/PhotosServiceImpl.java

@@ -80,37 +80,10 @@ public class PhotosServiceImpl implements PhotosService {
     }
 
 
-//    @Override
-//    public void savePhotos(MultipartFile file, Integer groupId) {
-//        // 1. 确保文件不为空且是压缩文件
-//        if (file == null || !file.getOriginalFilename().endsWith(".zip")) {
-//            throw new IllegalArgumentException("上传的文件必须是一个压缩包");
-//        }
-//
-//        try {
-//            // 2. 创建临时目录来存储解压的文件
-//            File tempDir = Files.createTempDirectory("photos").toFile();
-//            ZipInputStream zis = new ZipInputStream(file.getInputStream());
-//            ZipEntry zipEntry;
-//
-//            while ((zipEntry = zis.getNextEntry()) != null) {
-//                // 3. 读取文件内容并保存
-//                byte[] content = zis.readAllBytes();
-//                String photoUrl = createFile(tempDir.getAbsolutePath() + "/" + zipEntry.getName(), content);
-//
-//                // 4. 保存照片信息到数据库
-//                PhotosDO photo = new PhotosDO();
-//                photo.setGroupId(groupId); // 设置照片组ID
-//                photo.setPhotoUrl(photoUrl); // 设置照片URL
-//                photosMapper.insert(photo); // 假设你有这个 Mapper
-//                zis.closeEntry();
-//            }
-//
-//            zis.close();
-//
-//        } catch (IOException e) {
-//            throw new RuntimeException("处理上传文件时发生错误", e);
-//        }
-//    }
+    @Override
+    public List<PhotosDO> getPhotosByGroupId(Integer groupId) {
+        return photosMapper.selectByGroupId(groupId);
+    }
+
 
 }