Quellcode durchsuchen

增加对视频格式的支持

yaobo vor 7 Jahren
Ursprung
Commit
e816ec2f16

+ 24 - 0
src/main/java/cn/efunbox/audio/consts/MediaType.java

@@ -0,0 +1,24 @@
+package cn.efunbox.audio.consts;
+
+/**
+ * Created by yao on 17-9-26.
+ */
+public enum MediaType {
+    AUDIO(1,"音频"),
+    VIDEO(2,"视频");
+    private int code=1;
+    private String msg = "";
+
+    MediaType(int code, String msg){
+        this.code = code;
+        this.msg = msg;
+    }
+
+    public int getCode(){
+        return code;
+    }
+
+    public String getMsg(){
+        return msg;
+    }
+}

+ 15 - 8
src/main/java/cn/efunbox/audio/controller/AudioController.java

@@ -1,6 +1,7 @@
 package cn.efunbox.audio.controller;
 
 import cn.efunbox.audio.clients.AudioHttp;
+import cn.efunbox.audio.consts.MediaType;
 import cn.efunbox.audio.consts.Status;
 import cn.efunbox.audio.entity.*;
 import cn.efunbox.audio.service.*;
@@ -53,11 +54,14 @@ public class AudioController {
      */
     @RequestMapping(value = "/admsearch", method = RequestMethod.POST)
     public void AdminSearch(HttpServletRequest request, HttpServletResponse response){
+        String mediaType = request.getParameter("mediaType");
         String name = request.getParameter("name");
         String album = request.getParameter("album");
         String idGroup = request.getParameter("idGroup");
         String page = request.getParameter("page");
         String size = request.getParameter("size");
+        if(mediaType==null || mediaType.length()<1)
+            mediaType = "0";
         if(page==null || page.length()<1)
             page = "0";
         if(size==null || size.length()<1)
@@ -66,18 +70,18 @@ public class AudioController {
         Map<String,Object> map = new HashMap<>();
         List<Audio> list = null;
         if(idGroup!=null && idGroup.length()>0){
-            Page<Audio> pageRes = audioService.SearchByIdGroup(Long.valueOf(idGroup), Integer.valueOf(page), Integer.valueOf(size));
+            Page<Audio> pageRes = audioService.SearchByIdGroup(Integer.valueOf(mediaType), Long.valueOf(idGroup), Integer.valueOf(page), Integer.valueOf(size));
             map.put("data", pageRes.getContent());
             map.put("size", pageRes.getNumberOfElements());
             map.put("total", pageRes.getTotalElements());
         }else if(name!=null && name.length()>0  && album!=null && album.length()>0){
-            list = audioService.SearchByNameAlbum(name, album);
+            list = audioService.SearchByNameAlbum(Integer.valueOf(mediaType), name, album);
         }else if(name!=null && name.length()>0){
-            list = audioService.SearchByName(name);
+            list = audioService.SearchByName(Integer.valueOf(mediaType), name);
         }else if(album!=null && album.length()>0){
-            list = audioService.SearchByAlbum(album);
+            list = audioService.SearchByAlbum(Integer.valueOf(mediaType), album);
         }else{
-            Page<Audio> pageRes = audioService.SearchAll(Integer.valueOf(page), Integer.valueOf(size));
+            Page<Audio> pageRes = audioService.SearchAll(Integer.valueOf(mediaType), Integer.valueOf(page), Integer.valueOf(size));
             map.put("data", pageRes.getContent());
             map.put("size", pageRes.getNumberOfElements());
             map.put("total", pageRes.getTotalElements());
@@ -99,9 +103,12 @@ public class AudioController {
      */
     @RequestMapping(value = "/search", method = RequestMethod.POST)
     public void Search(HttpServletRequest request, HttpServletResponse response){
+        String mediaType = request.getParameter("mediaType");
         String id = request.getParameter("id");
         String name = request.getParameter("name");
         String album = request.getParameter("album");
+        if(mediaType==null || mediaType.length()<1)
+            mediaType = "0";
         if(name==null && album==null){
             HttpUtil.responseApiCode(request, response, ApiCode.PARAMETER_ERROR);
             return;
@@ -111,11 +118,11 @@ public class AudioController {
         List<Audio> list = null;
 //        System.out.println("album:"+album+",name:"+name);
         if(name!=null && name.length()>0  && album!=null && album.length()>0)
-            list = audioService.SearchByNameAlbum(name, album);
+            list = audioService.SearchByNameAlbum(Integer.valueOf(mediaType), name, album);
         else if(name!=null && name.length()>0)
-            list = audioService.SearchByName(name);
+            list = audioService.SearchByName(Integer.valueOf(mediaType), name);
         else
-            list = audioService.SearchByAlbum(album);
+            list = audioService.SearchByAlbum(Integer.valueOf(mediaType), album);
 
         if(list==null || list.size()<1){
             HttpUtil.responseApiCode(request, response, ApiCode.NOT_FOUND);

+ 4 - 1
src/main/java/cn/efunbox/audio/entity/Audio.java

@@ -13,7 +13,7 @@ import java.sql.Timestamp;
 import java.util.Date;
 
 /**
- * 音频资源
+ * 音频资源
  * Created by yao on 17-9-26.
  */
 
@@ -29,6 +29,9 @@ public class Audio implements Serializable, Cloneable {
     @GeneratedValue
     private Long id;
 
+    @Column
+    private Integer mediaType;
+
     //资源组编号
     @Column
     private Long idGroup;

+ 31 - 10
src/main/java/cn/efunbox/audio/impl/AudioServiceImpl.java

@@ -1,5 +1,6 @@
 package cn.efunbox.audio.impl;
 
+import cn.efunbox.audio.consts.MediaType;
 import cn.efunbox.audio.entity.Audio;
 import cn.efunbox.audio.entity.Device;
 import cn.efunbox.audio.repository.AudioRepo;
@@ -33,28 +34,40 @@ public class AudioServiceImpl implements AudioService {
     }
 
     @Override
-    public Page<Audio> SearchAll(int page, int size){
+    public Page<Audio> SearchAll(int mediaType, int page, int size){
         if(size<=0)
             size = 50;
         Pageable pageable = new PageRequest(page, size);
-        Page<Audio> list = audioRepo.findAll(pageable);
+        Page<Audio> list = null;
+        if(mediaType== MediaType.AUDIO.getCode() || mediaType==MediaType.VIDEO.getCode())
+            list = audioRepo.findByMediaType(mediaType, pageable);
+        else
+            list = audioRepo.findAll(pageable);
         return list;
     }
 
     @Override
-    public Page<Audio> SearchByIdGroup(Long idGroup, int page, int size){
+    public Page<Audio> SearchByIdGroup(int mediaType, Long idGroup, int page, int size){
         if(size<=0)
             size = 50;
         Pageable pageable = new PageRequest(page, size);
-        Page<Audio> list = audioRepo.findByIdGroup(idGroup, pageable);
+        Page<Audio> list = null;
+        if(mediaType== MediaType.AUDIO.getCode() || mediaType==MediaType.VIDEO.getCode())
+            list = audioRepo.findByMediaTypeAndIdGroup(mediaType, idGroup, pageable);
+        else
+            list = audioRepo.findByIdGroup(idGroup, pageable);
         return list;
     }
 
     @Override
-    public List<Audio> SearchByName(String name){
+    public List<Audio> SearchByName(int mediaType, String name){
         if(name==null || name.isEmpty())
             return null;
-        List<Audio> list = audioRepo.findByName(name);
+        List<Audio> list = null;
+        if(mediaType== MediaType.AUDIO.getCode() || mediaType==MediaType.VIDEO.getCode())
+            list = audioRepo.findByMediaTypeAndName(mediaType, name);
+        else
+            list = audioRepo.findByName(name);
 //        System.out.println("list1:"+list.toString());
         if(list==null)
             list = audioRepo.findByNameLike("%"+name+"%");
@@ -63,21 +76,29 @@ public class AudioServiceImpl implements AudioService {
     }
 
     @Override
-    public List<Audio> SearchByAlbum(String album){
+    public List<Audio> SearchByAlbum(int mediaType, String album){
         if(album==null || album.isEmpty())
             return null;
-        List<Audio> list = audioRepo.findByAlbum(album);
+        List<Audio> list = null;
+        if(mediaType== MediaType.AUDIO.getCode() || mediaType==MediaType.VIDEO.getCode())
+            list = audioRepo.findByMediaTypeAndAlbum(mediaType, album);
+        else
+            list = audioRepo.findByAlbum(album);
         if(list==null)
             list = audioRepo.findByAlbumLike(album);
         return list;
     }
 
     @Override
-    public List<Audio> SearchByNameAlbum(String name, String album){
+    public List<Audio> SearchByNameAlbum(int mediaType, String name, String album){
         if(name==null || name.isEmpty()
                 || album==null || album.isEmpty())
             return null;
-        List<Audio> list = audioRepo.findByNameAndAlbum(name, album);
+        List<Audio> list = null;
+        if(mediaType== MediaType.AUDIO.getCode() || mediaType==MediaType.VIDEO.getCode())
+            list = audioRepo.findByMediaTypeAndNameAndAlbum(mediaType, name, album);
+        else
+            list = audioRepo.findByNameAndAlbum(name, album);
         if(list==null)
             list = audioRepo.searchByNameAndAlbum(name, album);
 

+ 14 - 1
src/main/java/cn/efunbox/audio/repository/AudioRepo.java

@@ -21,21 +21,34 @@ public interface AudioRepo extends JpaRepository<Audio, Long> {
 
     Page<Audio> findAll(Pageable pageable);
 
+    Page<Audio> findByMediaType(Integer mediaType, Pageable pageable);
+
     List<Audio> findByName(String name);
 
+    List<Audio> findByMediaTypeAndName(Integer mediaType, String name);
+
     @Query("from Audio a where a.name LIKE :name")
     List<Audio> findByNameLike(String name);
 
+//    @Query("from Audio a where a.media_type=:mediaType and a.name LIKE :name")
+//    List<Audio> findByMediaTypeAndNameLike(Integer mediaType, String name);
+
     List<Audio> findByNameContaining(String name);
 
     Page<Audio> findByIdGroup(Long idGroup, Pageable pageable);
 
+    Page<Audio> findByMediaTypeAndIdGroup(Integer mediaType, Long idGroup, Pageable pageable);
+
     List<Audio> findByAlbum( String Album);
 
-    List<Audio> findByAlbumLike( String Album);
+    List<Audio> findByMediaTypeAndAlbum(Integer mediaType, String Album);
+
+    List<Audio> findByAlbumLike(String Album);
 
     List<Audio> findByNameAndAlbum(String name, String Album);
 
+    List<Audio> findByMediaTypeAndNameAndAlbum(Integer mediaType, String name, String Album);
+
     @Query("from Audio a where a.name like CONCAT('%',:name,'%') and a.album like CONCAT('%',:album,'%') ")
     List<Audio> searchByNameAndAlbum(@Param("name") String name, @Param("album") String album);
 }

+ 5 - 5
src/main/java/cn/efunbox/audio/service/AudioService.java

@@ -13,15 +13,15 @@ public interface AudioService {
 
     public Audio GetOne(Long id);
 
-    public Page<Audio> SearchAll(int page, int size);
+    public Page<Audio> SearchAll(int mediaType, int page, int size);
 
-    public Page<Audio> SearchByIdGroup(Long idGroup, int page, int size);
+    public Page<Audio> SearchByIdGroup(int mediaType, Long idGroup, int page, int size);
 
-    public List<Audio> SearchByName(String name);
+    public List<Audio> SearchByName(int mediaType, String name);
 
-    public List<Audio> SearchByAlbum(String album);
+    public List<Audio> SearchByAlbum(int mediaType, String album);
 
-    public List<Audio> SearchByNameAlbum(String name, String album);
+    public List<Audio> SearchByNameAlbum(int mediaType, String name, String album);
 
     public Audio Insert(Audio audio);