ChannelController.java 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package cn.efunbox.audio.controller;
  2. import cn.efunbox.audio.entity.Audio;
  3. import cn.efunbox.audio.entity.Channel;
  4. import cn.efunbox.audio.service.AudioService;
  5. import cn.efunbox.audio.service.ChannelService;
  6. import cn.efunbox.audio.util.ApiCode;
  7. import cn.efunbox.audio.util.HttpUtil;
  8. import lombok.extern.slf4j.Slf4j;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.web.bind.annotation.RequestMapping;
  11. import org.springframework.web.bind.annotation.RequestMethod;
  12. import org.springframework.web.bind.annotation.RestController;
  13. import javax.servlet.http.HttpServletRequest;
  14. import javax.servlet.http.HttpServletResponse;
  15. import java.util.Date;
  16. import java.util.List;
  17. import java.util.Random;
  18. /**
  19. * Created by yao on 17-9-26.
  20. */
  21. @RestController
  22. @Slf4j
  23. @RequestMapping(value = "/channel")
  24. public class ChannelController {
  25. @Autowired
  26. ChannelService channelService;
  27. @RequestMapping(value = "/search" ,method = RequestMethod.POST)
  28. public void Search(HttpServletRequest request, HttpServletResponse response){
  29. String name = request.getParameter("name");
  30. String id = request.getParameter("cid");
  31. if(name==null && id==null){
  32. HttpUtil.responseApiCode(request, response, ApiCode.PARAMETER_ERROR);
  33. return;
  34. }
  35. List<Channel> list = null;
  36. if(id!=null && id.length()>0)
  37. list = channelService.SearchById(Long.valueOf(id));
  38. else if(name!=null && name.length()>0)
  39. list = channelService.SearchByName(name);
  40. if(list==null || list.size()<1){
  41. HttpUtil.responseApiCode(request, response, ApiCode.NOT_FOUND);
  42. return;
  43. }
  44. HttpUtil.responseOkData(request, response, list);
  45. return;
  46. }
  47. @RequestMapping(value = "/insert", method = RequestMethod.POST)
  48. public void Insert(HttpServletRequest request, HttpServletResponse response){
  49. String name = request.getParameter("name");
  50. String idFather = request.getParameter("idFather");
  51. if(name==null){
  52. HttpUtil.responseApiCode(request, response, ApiCode.PARAMETER_ERROR);
  53. return;
  54. }
  55. if(idFather==null || idFather.length()==0)
  56. idFather = "0";
  57. List<Channel> list = channelService.SearchByName(name);
  58. if(list!=null && list.size()>0){
  59. HttpUtil.responseApiCode(request, response, ApiCode.RECORD_EXIST);
  60. return;
  61. }
  62. Channel channel = new Channel();
  63. channel.setName(name);
  64. channel.setIdFather(Long.valueOf(idFather));
  65. channel = channelService.Insert(channel);
  66. HttpUtil.responseOutWithJson(request, response, channel);
  67. return;
  68. }
  69. }