소스 검색

根据id、no,title来搜索资源平台

yaobo 7 년 전
부모
커밋
bcbeac4519

+ 18 - 1
src/main/java/cn/efunbox/audio/clients/AudioHttp.java

@@ -18,10 +18,27 @@ public class AudioHttp {
 
     @Value("${iaas.resource.search}")
     private  String urlResource;
+    @Value("${iaas.resource.searchNo}")
+    private  String urlResourceNo;
+    @Value("${iaas.resource.searchName}")
+    private  String urlResourceName;
 
-    public String GetResource(String idResource) {
+    public String SearchByIdResource(String idResource) {
         RestTemplate restTemplate = new RestTemplate();
         return restTemplate.getForEntity(urlResource+idResource, String.class).getBody();
     }
 
+    public String SearchByIdNo(String idNo) {
+        RestTemplate restTemplate = new RestTemplate();
+//        System.out.println(urlResourceNo+idNo);
+        return restTemplate.getForEntity(urlResourceNo+idNo, String.class).getBody();
+    }
+
+    public String SearchByName(String title, int type, int page, int size) {
+        RestTemplate restTemplate = new RestTemplate();
+        String url = urlResourceName+"?title="+title+"&type="+type+"&pageNum="+page+"&pageSize="+size;
+        System.out.println(url);
+        return restTemplate.getForEntity(url, String.class).getBody();
+    }
+
 }

+ 71 - 6
src/main/java/cn/efunbox/audio/controller/AudioController.java

@@ -101,6 +101,62 @@ public class AudioController {
     }
 
     /**
+     * 管理员搜索资源平台的接口
+     * @param request
+     * @param response
+     */
+    @RequestMapping(value = "/resource", method = RequestMethod.POST)
+    public void AdminLoadResource(HttpServletRequest request, HttpServletResponse response){
+        String name = request.getParameter("name");
+        String idResource = request.getParameter("idResource");
+        String idNo = request.getParameter("idNo");
+        String type = request.getParameter("type"); //资源类型, 音频,视频, 直播 取值{0,1,2}, 分别表示{视频,音频,直播}
+        String page = request.getParameter("page");
+        String size = request.getParameter("size");
+
+        JSONArray list = new JSONArray();
+        String res = null;
+        if((idResource!=null && idResource.length()>0)
+                || (idNo!=null && idNo.length()>0)){
+            if(idResource!=null && idResource.length()>0)
+                res = audioHttp.SearchByIdResource(idResource);
+            else
+                res = audioHttp.SearchByIdNo(idNo);
+//        System.out.println(res);
+            Map map = JSONObject.parseObject(res);
+            try{
+                if(map.get("code").toString().equalsIgnoreCase("200")){
+                    map = JSONObject.parseObject(map.get("data").toString());
+                    list.add(map);
+                }
+            }catch(Exception e){
+                System.out.println(e.getMessage());
+            }
+        }else if(name!=null && name.length()>0){
+            if(type==null || type.length()<1)
+                type = "0";
+            if(page==null || page.length()<1)
+                page = "1";
+            if(size==null || size.length()<1)
+                size = "10";
+            res = audioHttp.SearchByName(name, Integer.valueOf(type), Integer.valueOf(page), Integer.valueOf(size));
+//        System.out.println(res);
+            Map map = JSONObject.parseObject(res);
+            try{
+                if(map.get("code").toString().equalsIgnoreCase("200")){
+                    map = JSONObject.parseObject(map.get("data").toString());
+                    list = JSONArray.parseArray(map.get("list").toString());
+                }
+            }catch(Exception e){
+                System.out.println(e.getMessage());
+            }
+        }
+
+        HttpUtil.responseOkData(request, response, list);
+        return;
+    }
+
+    /**
      * 用户搜索接口
      * @param request
      * @param response
@@ -155,17 +211,26 @@ public class AudioController {
         int r = Math.abs(random.nextInt())%audioList.size();
         Audio audio = audioList.get(r);
         if(audio.getIdResource()!=null && audio.getIdResource().length()>0){
-            String res = audioHttp.GetResource(audio.getIdResource());
+            String res = audioHttp.SearchByIdResource(audio.getIdResource());
 //        System.out.println(res);
             Map map = JSONObject.parseObject(res);
             try{
                 if(map.get("code").toString().equalsIgnoreCase("200")){
                     map = JSONObject.parseObject(map.get("data").toString());
-                    JSONArray array = JSONArray.parseArray(map.get("audios").toString());
-                    map = JSONObject.parseObject(array.get(0).toString());
-                    String path = map.get("path").toString();
-                    path = path.replaceAll("\n","");
-                    audio.setUrl(path);
+                    if(map.get("type").toString().equalsIgnoreCase("1")){
+                        JSONArray array = JSONArray.parseArray(map.get("audios").toString());
+                        map = JSONObject.parseObject(array.get(0).toString());
+                        String path = map.get("fullPath").toString();
+                        path = path.replaceAll("\n","");
+                        audio.setUrl(path);
+                    }else if(map.get("type").toString().equalsIgnoreCase("0")){
+                        JSONArray array = JSONArray.parseArray(map.get("videos").toString());
+                        map = JSONObject.parseObject(array.get(0).toString());
+                        String path = map.get("fullPath").toString();
+                        path = path.replaceAll("\n","");
+                        audio.setUrl(path);
+                    }
+
 //                    System.out.println(path);
                 }
             }catch(Exception e){

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

@@ -68,7 +68,7 @@ public class DeviceController {
     public void Feigh(HttpServletRequest request, HttpServletResponse response,
             @RequestParam("idChannel")String idChannel, @RequestParam("mobile")String mobile){
 
-        String res = audioHttp.GetResource("653f6a0c-b997-11e7-9771-080027fcfc4b");
+        String res = audioHttp.SearchByIdResource("653f6a0c-b997-11e7-9771-080027fcfc4b");
         System.out.println(res);
         Map map = JSONObject.parseObject(res);
         if(map.get("code").toString().equalsIgnoreCase("200")){

+ 2 - 0
src/main/resources/application-dev.properties

@@ -12,6 +12,8 @@ eureka.client.serviceUrl.defaultZone= http://eureka3:8766/eureka/
 
 iaas.user.register=http://zuul.efunbox.cn/ucenter/v1/users
 iaas.resource.search=http://zuul.efunbox.cn/rcenter/v1/resources/
+iaas.resource.searchNo=http://zuul.efunbox.cn/rcenter/v1/resources/no/
+iaas.resource.searchName=http://zuul.efunbox.cn/rcenter/v1/resources/page
 iaas.user.audio.bizCode=1002
 iaas.user.audio.appCode=1002
 iaas.user.audio.platform=4

+ 2 - 0
src/main/resources/application-prd.properties

@@ -12,6 +12,8 @@ eureka.client.serviceUrl.defaultZone= http://eureka3:8766/eureka/
 
 iaas.user.register=http://zuul.ai160.com/ucenter/v1/users
 iaas.resource.search=http://zuul.ai160.com/rcenter/v1/resources/
+iaas.resource.searchNo=http://zuul.ai160.com/rcenter/v1/resources/no/
+iaas.resource.searchName=http://zuul.ai160.com/rcenter/v1/resources/page
 iaas.user.audio.bizCode=1002
 iaas.user.audio.appCode=1002
 iaas.user.audio.platform=4