RightsController.java 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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.RequestBody;
  13. import org.springframework.web.bind.annotation.RequestMapping;
  14. import org.springframework.web.bind.annotation.RequestMethod;
  15. import org.springframework.web.bind.annotation.RestController;
  16. import javax.servlet.http.HttpServletRequest;
  17. import javax.servlet.http.HttpServletResponse;
  18. import java.util.Date;
  19. import java.util.List;
  20. /**
  21. * Created by yao on 17-9-26.
  22. */
  23. @RestController
  24. @Slf4j
  25. @RequestMapping(value = "/rights")
  26. public class RightsController {
  27. @Autowired
  28. RightsService rightsService;
  29. @Autowired
  30. ChannelService channelService;
  31. @Autowired
  32. GroupingService groupingService;
  33. @RequestMapping(value = "/search" ,method = RequestMethod.POST)
  34. public void Search(HttpServletRequest request, HttpServletResponse response){
  35. String id = request.getParameter("rid");
  36. String idChannel = request.getParameter("idChannel");
  37. String idGroup = request.getParameter("idGroup");
  38. if(id==null && idChannel==null && idGroup==null){
  39. HttpUtil.responseApiCode(request, response, ApiCode.PARAMETER_ERROR);
  40. return;
  41. }
  42. List<Rights> list = null;
  43. if(id!=null && id.length()>0)
  44. list = rightsService.SearchById(Long.valueOf(id));
  45. else if(idChannel!=null && idGroup!=null)
  46. list = rightsService.SearchByIdChannelAndIdGroup(Long.valueOf(idChannel), Long.valueOf(idGroup));
  47. else if(idChannel!=null && idChannel.length()>0)
  48. list = rightsService.SearchByIdChannel(Long.valueOf(idChannel));
  49. else if(idGroup!=null && idGroup.length()>0)
  50. list = rightsService.SearchByIdGroup(Long.valueOf(idGroup));
  51. if(list==null || list.size()<1){
  52. HttpUtil.responseApiCode(request, response, ApiCode.NOT_FOUND);
  53. return;
  54. }
  55. HttpUtil.responseOkData(request, response, list);
  56. return;
  57. }
  58. // @RequestMapping(value = "/insert", method = RequestMethod.POST)
  59. // public void Insert(HttpServletRequest request, HttpServletResponse response){
  60. // String idChannel = request.getParameter("idChannel");
  61. // String idGroup = request.getParameter("idGroup");
  62. // if(idChannel==null || idGroup==null){
  63. // HttpUtil.responseApiCode(request, response, ApiCode.PARAMETER_ERROR);
  64. // return;
  65. // }
  66. //
  67. // List<Rights> list = rightsService.SearchByIdChannelAndIdGroup(Long.valueOf(idChannel), Long.valueOf(idGroup));
  68. // if(list!=null && list.size()>0){
  69. // HttpUtil.responseApiCode(request, response, ApiCode.RECORD_EXIST);
  70. // return;
  71. // }
  72. // List<Channel> cList = channelService.SearchById(Long.valueOf(idChannel));
  73. // List<Grouping> gList = groupingService.SearchById(Long.valueOf(idGroup));
  74. // if(cList==null || cList.size()<1 || gList==null || gList.size()<1){
  75. // HttpUtil.responseApiCode(request, response, ApiCode.PARAMETER_ERROR);
  76. // return;
  77. // }
  78. // Rights rights = new Rights();
  79. // rights.setIdChannel(cList.get(0).getId());
  80. // rights.setNameChannel(cList.get(0).getName());
  81. // rights.setIdGroup(gList.get(0).getId());
  82. // rights.setNameGroup(gList.get(0).getName());
  83. // rights = rightsService.Insert(rights);
  84. //
  85. // HttpUtil.responseOutWithJson(request, response, rights);
  86. // return;
  87. // }
  88. @RequestMapping(value = "/insert", method = RequestMethod.POST)
  89. public void Insert(HttpServletRequest request, HttpServletResponse response, @RequestBody Rights rights){
  90. if(rights.getIdChannel()==null || rights.getIdGroup()==null){
  91. HttpUtil.responseApiCode(request, response, ApiCode.PARAMETER_ERROR);
  92. return;
  93. }
  94. List<Rights> list = rightsService.SearchByIdChannelAndIdGroup(rights.getIdChannel(), rights.getIdGroup());
  95. if(list!=null && list.size()>0){
  96. HttpUtil.responseApiCode(request, response, ApiCode.RECORD_EXIST);
  97. return;
  98. }
  99. List<Channel> cList = channelService.SearchById(rights.getIdChannel());
  100. List<Grouping> gList = groupingService.SearchById(rights.getIdGroup());
  101. if(cList==null || cList.size()<1 || gList==null || gList.size()<1){
  102. HttpUtil.responseApiCode(request, response, ApiCode.PARAMETER_ERROR);
  103. return;
  104. }
  105. rights.setNameChannel(cList.get(0).getName());
  106. rights.setNameGroup(gList.get(0).getName());
  107. rights.setCreated(new Date());
  108. rights = rightsService.Insert(rights);
  109. HttpUtil.responseOutWithJson(request, response, rights);
  110. return;
  111. }
  112. }