12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- package cn.efunbox.audio.controller;
- import cn.efunbox.audio.entity.Audio;
- import cn.efunbox.audio.entity.Channel;
- import cn.efunbox.audio.service.AudioService;
- import cn.efunbox.audio.service.ChannelService;
- 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.Date;
- import java.util.List;
- import java.util.Random;
- /**
- * Created by yao on 17-9-26.
- */
- @RestController
- @Slf4j
- @RequestMapping(value = "/channel")
- public class ChannelController {
- @Autowired
- ChannelService channelService;
- @RequestMapping(value = "/search" ,method = RequestMethod.POST)
- public void Search(HttpServletRequest request, HttpServletResponse response){
- String name = request.getParameter("name");
- String id = request.getParameter("cid");
- if(name==null && id==null){
- HttpUtil.responseApiCode(request, response, ApiCode.PARAMETER_ERROR);
- return;
- }
- List<Channel> list = null;
- if(id!=null && id.length()>0)
- list = channelService.SearchById(Long.valueOf(id));
- else if(name!=null && name.length()>0)
- list = channelService.SearchByName(name);
- 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 name = request.getParameter("name");
- String idFather = request.getParameter("idFather");
- if(name==null){
- HttpUtil.responseApiCode(request, response, ApiCode.PARAMETER_ERROR);
- return;
- }
- if(idFather==null || idFather.length()==0)
- idFather = "0";
- List<Channel> list = channelService.SearchByName(name);
- if(list!=null && list.size()>0){
- HttpUtil.responseApiCode(request, response, ApiCode.RECORD_EXIST);
- return;
- }
- Channel channel = new Channel();
- channel.setName(name);
- channel.setIdFather(Long.valueOf(idFather));
- channel = channelService.Insert(channel);
- HttpUtil.responseOutWithJson(request, response, channel);
- return;
- }
- }
|