|
@@ -0,0 +1,97 @@
|
|
|
+package cn.efunbox.audio.controller;
|
|
|
+
|
|
|
+import cn.efunbox.audio.entity.Channel;
|
|
|
+import cn.efunbox.audio.entity.Grouping;
|
|
|
+import cn.efunbox.audio.entity.Rights;
|
|
|
+import cn.efunbox.audio.service.ChannelService;
|
|
|
+import cn.efunbox.audio.service.GroupingService;
|
|
|
+import cn.efunbox.audio.service.RightsService;
|
|
|
+import cn.efunbox.audio.util.ApiCode;
|
|
|
+import cn.efunbox.audio.util.HttpUtil;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by yao on 17-9-26.
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@Slf4j
|
|
|
+@RequestMapping(value = "/rights")
|
|
|
+public class RightsController {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ RightsService rightsService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ChannelService channelService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ GroupingService groupingService;
|
|
|
+
|
|
|
+ @RequestMapping(value = "/search" ,method = RequestMethod.POST)
|
|
|
+ public void Search(HttpServletRequest request, HttpServletResponse response){
|
|
|
+ String id = request.getParameter("rid");
|
|
|
+ String idChannel = request.getParameter("idChannel");
|
|
|
+ String idGroup = request.getParameter("idGroup");
|
|
|
+ if(id==null && idChannel==null && idGroup==null){
|
|
|
+ HttpUtil.responseApiCode(request, response, ApiCode.PARAMETER_ERROR);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<Rights> list = null;
|
|
|
+ if(id!=null && id.length()>0)
|
|
|
+ list = rightsService.SearchById(Long.valueOf(id));
|
|
|
+ else if(idChannel!=null && idGroup!=null)
|
|
|
+ list = rightsService.SearchByIdChannelAndIdGroup(Long.valueOf(idChannel), Long.valueOf(idGroup));
|
|
|
+ else if(idChannel!=null && idChannel.length()>0)
|
|
|
+ list = rightsService.SearchByIdChannel(Long.valueOf(idChannel));
|
|
|
+ else if(idGroup!=null && idGroup.length()>0)
|
|
|
+ list = rightsService.SearchByIdGroup(Long.valueOf(idGroup));
|
|
|
+
|
|
|
+ if(list==null || list.size()<1){
|
|
|
+ HttpUtil.responseApiCode(request, response, ApiCode.NOT_FOUND);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ HttpUtil.responseOkData(request, response, list);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping(value = "/insert", method = RequestMethod.POST)
|
|
|
+ public void Insert(HttpServletRequest request, HttpServletResponse response){
|
|
|
+ String idChannel = request.getParameter("idChannel");
|
|
|
+ String idGroup = request.getParameter("idGroup");
|
|
|
+ if(idChannel==null || idGroup==null){
|
|
|
+ HttpUtil.responseApiCode(request, response, ApiCode.PARAMETER_ERROR);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Rights> list = rightsService.SearchByIdChannelAndIdGroup(Long.valueOf(idChannel), Long.valueOf(idGroup));
|
|
|
+ if(list!=null && list.size()>0){
|
|
|
+ HttpUtil.responseApiCode(request, response, ApiCode.RECORD_EXIST);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<Channel> cList = channelService.SearchById(Long.valueOf(idChannel));
|
|
|
+ List<Grouping> gList = groupingService.SearchById(Long.valueOf(idGroup));
|
|
|
+ if(cList==null || cList.size()<1 || gList==null || gList.size()<1){
|
|
|
+ HttpUtil.responseApiCode(request, response, ApiCode.PARAMETER_ERROR);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Rights rights = new Rights();
|
|
|
+ rights.setIdChannel(cList.get(0).getId());
|
|
|
+ rights.setNameChannel(cList.get(0).getName());
|
|
|
+ rights.setIdGroup(gList.get(0).getId());
|
|
|
+ rights.setNameGroup(gList.get(0).getName());
|
|
|
+ rights = rightsService.Insert(rights);
|
|
|
+
|
|
|
+ HttpUtil.responseOutWithJson(request, response, rights);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|