Bladeren bron

根据deviceId获取专辑列表

wangys 5 jaren geleden
bovenliggende
commit
72b62158d0

+ 12 - 0
src/main/java/cn/efunbox/audio/controller/DeviceController.java

@@ -8,6 +8,7 @@ import cn.efunbox.audio.entity.Device;
 import cn.efunbox.audio.service.ChannelService;
 import cn.efunbox.audio.service.DeviceService;
 import cn.efunbox.audio.utils.ApiCode;
+import cn.efunbox.audio.utils.ApiResult;
 import cn.efunbox.audio.utils.Encrypt;
 import cn.efunbox.audio.utils.HttpUtil;
 import com.alibaba.fastjson.JSONArray;
@@ -343,4 +344,15 @@ public class DeviceController {
 //        return;
 //    }
 
+
+
+    @RequestMapping(value = "/findAlbum", method = RequestMethod.GET)
+    public void findAlbum(HttpServletRequest request, HttpServletResponse response, String idDevice){
+
+        Map<String,Object> map = new HashMap<>();
+
+        map.put("albums",  deviceService.findAlbum(idDevice));
+        HttpUtil.responseOkData(request, response, map);
+    }
+
 }

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

@@ -1,9 +1,13 @@
 package cn.efunbox.audio.impl;
 
 import cn.efunbox.audio.consts.Status;
+import cn.efunbox.audio.entity.Album;
 import cn.efunbox.audio.entity.Device;
+import cn.efunbox.audio.repository.AlbumRepo;
 import cn.efunbox.audio.repository.DeviceRepo;
 import cn.efunbox.audio.service.DeviceService;
+import cn.efunbox.audio.utils.ApiCode;
+import cn.efunbox.audio.utils.ApiResult;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
@@ -15,6 +19,7 @@ import org.springframework.util.CollectionUtils;
 import java.sql.Timestamp;
 import java.util.Date;
 import java.util.List;
+import java.util.Objects;
 import java.util.UUID;
 
 /**
@@ -26,6 +31,9 @@ public class DeviceServiceImpl implements DeviceService {
     @Autowired
     DeviceRepo deviceRepo;
 
+    @Autowired
+    AlbumRepo albumRepo;
+
     @Override
     public boolean CheckRegister(Long idChannel, String idDevice){
         List<Device> list = deviceRepo.findByChannelDevice(idChannel, idDevice);
@@ -146,4 +154,13 @@ public class DeviceServiceImpl implements DeviceService {
         }
         return null;
     }
+
+    @Override
+    public List<Album> findAlbum(String idDevice) {
+        List<Device> devices = deviceRepo.findByDevice(idDevice);
+        if(Objects.isNull(devices)){
+            return null;
+        }
+        return albumRepo.findAlbum(idDevice);
+    }
 }

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

@@ -4,6 +4,7 @@ import cn.efunbox.audio.entity.Album;
 import cn.efunbox.audio.repository.base.ProjectJpaRepository;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
 import org.springframework.stereotype.Repository;
 
 import javax.rmi.CORBA.PortableRemoteObjectDelegate;
@@ -24,4 +25,12 @@ 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);
 }

+ 4 - 0
src/main/java/cn/efunbox/audio/service/DeviceService.java

@@ -1,9 +1,12 @@
 package cn.efunbox.audio.service;
 
+import cn.efunbox.audio.entity.Album;
 import cn.efunbox.audio.entity.Device;
+import cn.efunbox.audio.utils.ApiResult;
 import org.springframework.data.domain.Page;
 
 import java.sql.Timestamp;
+import java.util.List;
 
 /**
  * Created by yao on 17-9-26.
@@ -31,4 +34,5 @@ public interface DeviceService {
     public void Delete(Long id);
 
     public Device findToken(Long idChannel, String idDevice);
+    public List<Album> findAlbum(String idDevice);
 }