123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- 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.utils.ApiCode;
- import cn.efunbox.audio.utils.HttpUtil;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.RequestBody;
- 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.Date;
- 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;
- // }
- @RequestMapping(value = "/insert", method = RequestMethod.POST)
- public void Insert(HttpServletRequest request, HttpServletResponse response, @RequestBody Rights rights){
- if(rights.getIdChannel()==null || rights.getIdGroup()==null){
- HttpUtil.responseApiCode(request, response, ApiCode.PARAMETER_ERROR);
- return;
- }
- List<Rights> list = rightsService.SearchByIdChannelAndIdGroup(rights.getIdChannel(), rights.getIdGroup());
- if(list!=null && list.size()>0){
- HttpUtil.responseApiCode(request, response, ApiCode.RECORD_EXIST);
- return;
- }
- List<Channel> cList = channelService.SearchById(rights.getIdChannel());
- List<Grouping> gList = groupingService.SearchById(rights.getIdGroup());
- if(cList==null || cList.size()<1 || gList==null || gList.size()<1){
- HttpUtil.responseApiCode(request, response, ApiCode.PARAMETER_ERROR);
- return;
- }
- rights.setNameChannel(cList.get(0).getName());
- rights.setNameGroup(gList.get(0).getName());
- rights.setCreated(new Date());
- rights = rightsService.Insert(rights);
- HttpUtil.responseOutWithJson(request, response, rights);
- return;
- }
- }
|