RightsController.java 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package cn.efunbox.audio.controller;
  2. import cn.efunbox.audio.entity.Channel;
  3. import cn.efunbox.audio.entity.Grouping;
  4. import cn.efunbox.audio.entity.Rights;
  5. import cn.efunbox.audio.service.ChannelService;
  6. import cn.efunbox.audio.service.GroupingService;
  7. import cn.efunbox.audio.service.RightsService;
  8. import cn.efunbox.audio.utils.ApiCode;
  9. import cn.efunbox.audio.utils.HttpUtil;
  10. import lombok.extern.slf4j.Slf4j;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.web.bind.annotation.RequestMapping;
  13. import org.springframework.web.bind.annotation.RequestMethod;
  14. import org.springframework.web.bind.annotation.RestController;
  15. import javax.servlet.http.HttpServletRequest;
  16. import javax.servlet.http.HttpServletResponse;
  17. import java.util.List;
  18. /**
  19. * Created by yao on 17-9-26.
  20. */
  21. @RestController
  22. @Slf4j
  23. @RequestMapping(value = "/rights")
  24. public class RightsController {
  25. @Autowired
  26. RightsService rightsService;
  27. @Autowired
  28. ChannelService channelService;
  29. @Autowired
  30. GroupingService groupingService;
  31. @RequestMapping(value = "/search" ,method = RequestMethod.POST)
  32. public void Search(HttpServletRequest request, HttpServletResponse response){
  33. String id = request.getParameter("rid");
  34. String idChannel = request.getParameter("idChannel");
  35. String idGroup = request.getParameter("idGroup");
  36. if(id==null && idChannel==null && idGroup==null){
  37. HttpUtil.responseApiCode(request, response, ApiCode.PARAMETER_ERROR);
  38. return;
  39. }
  40. List<Rights> list = null;
  41. if(id!=null && id.length()>0)
  42. list = rightsService.SearchById(Long.valueOf(id));
  43. else if(idChannel!=null && idGroup!=null)
  44. list = rightsService.SearchByIdChannelAndIdGroup(Long.valueOf(idChannel), Long.valueOf(idGroup));
  45. else if(idChannel!=null && idChannel.length()>0)
  46. list = rightsService.SearchByIdChannel(Long.valueOf(idChannel));
  47. else if(idGroup!=null && idGroup.length()>0)
  48. list = rightsService.SearchByIdGroup(Long.valueOf(idGroup));
  49. if(list==null || list.size()<1){
  50. HttpUtil.responseApiCode(request, response, ApiCode.NOT_FOUND);
  51. return;
  52. }
  53. HttpUtil.responseOkData(request, response, list);
  54. return;
  55. }
  56. @RequestMapping(value = "/insert", method = RequestMethod.POST)
  57. public void Insert(HttpServletRequest request, HttpServletResponse response){
  58. String idChannel = request.getParameter("idChannel");
  59. String idGroup = request.getParameter("idGroup");
  60. if(idChannel==null || idGroup==null){
  61. HttpUtil.responseApiCode(request, response, ApiCode.PARAMETER_ERROR);
  62. return;
  63. }
  64. List<Rights> list = rightsService.SearchByIdChannelAndIdGroup(Long.valueOf(idChannel), Long.valueOf(idGroup));
  65. if(list!=null && list.size()>0){
  66. HttpUtil.responseApiCode(request, response, ApiCode.RECORD_EXIST);
  67. return;
  68. }
  69. List<Channel> cList = channelService.SearchById(Long.valueOf(idChannel));
  70. List<Grouping> gList = groupingService.SearchById(Long.valueOf(idGroup));
  71. if(cList==null || cList.size()<1 || gList==null || gList.size()<1){
  72. HttpUtil.responseApiCode(request, response, ApiCode.PARAMETER_ERROR);
  73. return;
  74. }
  75. Rights rights = new Rights();
  76. rights.setIdChannel(cList.get(0).getId());
  77. rights.setNameChannel(cList.get(0).getName());
  78. rights.setIdGroup(gList.get(0).getId());
  79. rights.setNameGroup(gList.get(0).getName());
  80. rights = rightsService.Insert(rights);
  81. HttpUtil.responseOutWithJson(request, response, rights);
  82. return;
  83. }
  84. }