RightsController.java 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 idRights = request.getParameter("idRights");
  36. String idChannel = request.getParameter("idChannel");
  37. String idGroup = request.getParameter("idGroup");
  38. // if(idRights==null && idChannel==null && idGroup==null){
  39. // HttpUtil.responseApiCode(request, response, ApiCode.PARAMETER_ERROR);
  40. // return;
  41. // }
  42. List<Rights> list = null;
  43. if(idRights!=null && idRights.length()>0)
  44. list = rightsService.SearchById(Long.valueOf(idRights));
  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. else
  52. list = rightsService.SearchAll();
  53. // if(list==null || list.size()<1){
  54. // HttpUtil.responseApiCode(request, response, ApiCode.NOT_FOUND);
  55. // return;
  56. // }
  57. HttpUtil.responseOkData(request, response, list);
  58. return;
  59. }
  60. // @RequestMapping(value = "/insert", method = RequestMethod.POST)
  61. // public void Insert(HttpServletRequest request, HttpServletResponse response){
  62. // String idChannel = request.getParameter("idChannel");
  63. // String idGroup = request.getParameter("idGroup");
  64. // if(idChannel==null || idGroup==null){
  65. // HttpUtil.responseApiCode(request, response, ApiCode.PARAMETER_ERROR);
  66. // return;
  67. // }
  68. //
  69. // List<Rights> list = rightsService.SearchByIdChannelAndIdGroup(Long.valueOf(idChannel), Long.valueOf(idGroup));
  70. // if(list!=null && list.size()>0){
  71. // HttpUtil.responseApiCode(request, response, ApiCode.RECORD_EXIST);
  72. // return;
  73. // }
  74. // List<Channel> cList = channelService.SearchById(Long.valueOf(idChannel));
  75. // List<Grouping> gList = groupingService.SearchById(Long.valueOf(idGroup));
  76. // if(cList==null || cList.size()<1 || gList==null || gList.size()<1){
  77. // HttpUtil.responseApiCode(request, response, ApiCode.PARAMETER_ERROR);
  78. // return;
  79. // }
  80. // Rights rights = new Rights();
  81. // rights.setIdChannel(cList.get(0).getId());
  82. // rights.setNameChannel(cList.get(0).getName());
  83. // rights.setIdGroup(gList.get(0).getId());
  84. // rights.setNameGroup(gList.get(0).getName());
  85. // rights = rightsService.Insert(rights);
  86. //
  87. // HttpUtil.responseOutWithJson(request, response, rights);
  88. // return;
  89. // }
  90. @RequestMapping(value = "/insert", method = RequestMethod.POST)
  91. public void Insert(HttpServletRequest request, HttpServletResponse response, @RequestBody Rights rights){
  92. if(rights.getIdChannel()==null || rights.getIdGroup()==null){
  93. HttpUtil.responseApiCode(request, response, ApiCode.PARAMETER_ERROR);
  94. return;
  95. }
  96. List<Rights> list = rightsService.SearchByIdChannelAndIdGroup(rights.getIdChannel(), rights.getIdGroup());
  97. if(list!=null && list.size()>0){
  98. HttpUtil.responseApiCode(request, response, ApiCode.RECORD_EXIST);
  99. return;
  100. }
  101. List<Channel> cList = channelService.SearchById(rights.getIdChannel());
  102. List<Grouping> gList = groupingService.SearchById(rights.getIdGroup());
  103. if(cList==null || cList.size()<1 || gList==null || gList.size()<1){
  104. HttpUtil.responseApiCode(request, response, ApiCode.PARAMETER_ERROR);
  105. return;
  106. }
  107. rights.setNameChannel(cList.get(0).getName());
  108. rights.setNameGroup(gList.get(0).getName());
  109. rights.setCreated(new Date());
  110. rights = rightsService.Insert(rights);
  111. HttpUtil.responseOutWithJson(request, response, rights);
  112. return;
  113. }
  114. }