|
@@ -5,6 +5,8 @@ import cn.efunbox.audio.entity.Device;
|
|
import cn.efunbox.audio.service.AudioService;
|
|
import cn.efunbox.audio.service.AudioService;
|
|
import cn.efunbox.audio.service.DeviceService;
|
|
import cn.efunbox.audio.service.DeviceService;
|
|
import cn.efunbox.audio.util.ApiCode;
|
|
import cn.efunbox.audio.util.ApiCode;
|
|
|
|
+import cn.efunbox.audio.util.HttpUtil;
|
|
|
|
+import com.netflix.ribbon.proxy.annotation.Http;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
@@ -13,6 +15,7 @@ import org.springframework.web.bind.annotation.RequestParam;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -27,14 +30,12 @@ public class AudioController {
|
|
AudioService audioService;
|
|
AudioService audioService;
|
|
|
|
|
|
@RequestMapping(value = "/search" ,method = RequestMethod.POST)
|
|
@RequestMapping(value = "/search" ,method = RequestMethod.POST)
|
|
- public Map Search(HttpServletRequest request){
|
|
|
|
- Map map = new HashMap<>();
|
|
|
|
|
|
+ public void Search(HttpServletRequest request, HttpServletResponse response){
|
|
String name = request.getParameter("name");
|
|
String name = request.getParameter("name");
|
|
String album = request.getParameter("album");
|
|
String album = request.getParameter("album");
|
|
if(name==null && album==null){
|
|
if(name==null && album==null){
|
|
- map.put("code", ApiCode.PARAMETER_ERROR.getCode());
|
|
|
|
- map.put("msg", ApiCode.PARAMETER_ERROR.getMessage());
|
|
|
|
- return map;
|
|
|
|
|
|
+ HttpUtil.responseApiCode(request, response, ApiCode.PARAMETER_ERROR);
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
List<Audio> list = null;
|
|
List<Audio> list = null;
|
|
if(name!=null && name.length()>0 && album!=null && album.length()>0)
|
|
if(name!=null && name.length()>0 && album!=null && album.length()>0)
|
|
@@ -45,30 +46,25 @@ public class AudioController {
|
|
list = audioService.SearchByAlbum(album);
|
|
list = audioService.SearchByAlbum(album);
|
|
|
|
|
|
if(list==null || list.size()<1){
|
|
if(list==null || list.size()<1){
|
|
- map.put("code", ApiCode.NOT_FOUND.getCode());
|
|
|
|
- map.put("msg", ApiCode.NOT_FOUND.getMessage());
|
|
|
|
- return map;
|
|
|
|
|
|
+ HttpUtil.responseApiCode(request, response, ApiCode.NOT_FOUND);
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
|
|
|
|
Random random = new Random();
|
|
Random random = new Random();
|
|
int r = Math.abs(random.nextInt())%list.size();
|
|
int r = Math.abs(random.nextInt())%list.size();
|
|
- map.put("code", ApiCode.OK.getCode());
|
|
|
|
- map.put("data", list.get(r));
|
|
|
|
-
|
|
|
|
- return map;
|
|
|
|
|
|
+ HttpUtil.responseOkData(request, response, list.get(r));
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
|
|
|
|
@RequestMapping(value = "/insert", method = RequestMethod.POST)
|
|
@RequestMapping(value = "/insert", method = RequestMethod.POST)
|
|
- public Map Insert(HttpServletRequest request){
|
|
|
|
- Map map = new HashMap<>();
|
|
|
|
|
|
+ public void Insert(HttpServletRequest request, HttpServletResponse response){
|
|
String album = request.getParameter("album");
|
|
String album = request.getParameter("album");
|
|
String lesson = request.getParameter("lesson");
|
|
String lesson = request.getParameter("lesson");
|
|
String name = request.getParameter("name");
|
|
String name = request.getParameter("name");
|
|
String url = request.getParameter("url");
|
|
String url = request.getParameter("url");
|
|
if(album==null || name==null && url==null){
|
|
if(album==null || name==null && url==null){
|
|
- map.put("code", ApiCode.PARAMETER_ERROR.getCode());
|
|
|
|
- map.put("msg", ApiCode.PARAMETER_ERROR.getMessage());
|
|
|
|
- return map;
|
|
|
|
|
|
+ HttpUtil.responseApiCode(request, response, ApiCode.PARAMETER_ERROR);
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
|
|
|
|
Audio audio = new Audio();
|
|
Audio audio = new Audio();
|
|
@@ -80,9 +76,8 @@ public class AudioController {
|
|
audio.setCreated(new Date());
|
|
audio.setCreated(new Date());
|
|
audio = audioService.Insert(audio);
|
|
audio = audioService.Insert(audio);
|
|
|
|
|
|
- map.put("code", ApiCode.OK.getCode());
|
|
|
|
- map.put("data", audio);
|
|
|
|
- return map;
|
|
|
|
|
|
+ HttpUtil.responseOutWithJson(request, response, audio);
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|