Ver código fonte

修改/findAlbum接口

wangys 5 anos atrás
pai
commit
43c9ca3f67

+ 2 - 2
src/main/java/cn/efunbox/audio/config/Config.java

@@ -45,8 +45,8 @@ public class Config extends WebMvcConfigurerAdapter{
     @Override
     public void addInterceptors(InterceptorRegistry registry) {
         registry.addInterceptor(authInterceptor())
-                .addPathPatterns("/audio/search","/audio/searchList","/audio/info/{audioId}")
-                .excludePathPatterns("/device/**", "/error","/audio/*");
+                .addPathPatterns("/audio/search","/audio/searchList","/audio/info/{audioId}", "/device/findAlbum");
+//                .excludePathPatterns("/device/**", "/error","/audio/*");
 
         registry.addInterceptor(adminInterceptor())
                 .addPathPatterns("/**", "/device/update", "/device/delete")

+ 3 - 6
src/main/java/cn/efunbox/audio/controller/DeviceController.java

@@ -18,10 +18,7 @@ import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.data.domain.Page;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
@@ -347,11 +344,11 @@ public class DeviceController {
 
 
     @RequestMapping(value = "/findAlbum", method = RequestMethod.GET)
-    public void findAlbum(HttpServletRequest request, HttpServletResponse response, String idDevice){
+    public void findAlbum(HttpServletRequest request, HttpServletResponse response, String id){
 
         Map<String,Object> map = new HashMap<>();
 
-        map.put("albums",  deviceService.findAlbum(idDevice));
+        map.put("albums",  deviceService.findAlbum(id));
         HttpUtil.responseOkData(request, response, map);
     }
 

+ 4 - 4
src/main/java/cn/efunbox/audio/impl/DeviceServiceImpl.java

@@ -160,17 +160,17 @@ public class DeviceServiceImpl implements DeviceService {
     }
 
     @Override
-    public List<Album> findAlbum(String idDevice) {
-        List<Device> devices = deviceRepo.findByDevice(idDevice);
+    public List<Album> findAlbum(String id) {
+        Device devices = deviceRepo.findById(Long.valueOf(id));
         if(Objects.isNull(devices)){
             return null;
         }
-        List<Album> albums = albumRepo.findAlbum(idDevice);
+        List<Album> albums = albumRepo.findAlbum(id);
         albums.stream().forEach(album -> {
             if(Objects.nonNull(album.getImage())){
                 album.setImage(imgURL + album.getImage());
             }
         });
-        return albumRepo.findAlbum(idDevice);
+        return albumRepo.findAlbum(id);
     }
 }

+ 6 - 6
src/main/java/cn/efunbox/audio/repository/AlbumRepo.java

@@ -27,10 +27,10 @@ public interface AlbumRepo extends ProjectJpaRepository<Album, BigInteger> {
     List<Album> findByIdIn(List<BigInteger> albumIds);
 
     @Query(value = "" +
-            "select DISTINCT al.* FROM  device d\n" +
-            "JOIN channel c ON d.id_channel = c.id\n" +
-            "JOIN rights r ON c.id = r.id_channel\n" +
-            "JOIN audio au ON au.id_group = r.id_group\n" +
-            "JOIN album al ON al.id = au.album_id where d.id_device = :idDevice order by al.id", nativeQuery = true)
-    List<Album> findAlbum(@Param("idDevice") String idDevice);
+            "select DISTINCT al.* FROM  device d " +
+            "JOIN channel c ON d.id_channel = c.id " +
+            "JOIN rights r ON c.id = r.id_channel " +
+            "JOIN audio au ON au.id_group = r.id_group " +
+            "JOIN album al ON al.id = au.album_id where d.id = :id order by al.id", nativeQuery = true)
+    List<Album> findAlbum(@Param("id") String id);
 }