package com.newvideo.controller.admin.api; import java.io.PrintWriter; import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.annotation.Resource; import net.sf.json.JSONObject; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.newvideo.domain.DetailSystem; import com.newvideo.domain.VideoBanQuan; import com.newvideo.domain.VideoBanQuanVideo; import com.newvideo.domain.VideoInfo; import com.newvideo.domain.web.BanquanKeyAdmin; import com.newvideo.domain.web.BanquanVideoAdmin; import com.newvideo.service.imp.BanQuanService; import com.newvideo.service.imp.VideoService; import com.newvideo.util.Constant; import com.newvideo.util.StringUtil; import com.newvideo.web.tag.PageEntity; @Controller @RequestMapping("admin/new/api/copyright") public class CopyRightController { @Resource private BanQuanService banQuanService; @Resource private VideoService videoService; @RequestMapping("copyRightList") public void getCopyRightList(int pageIndex,String key,int detailsystem,PrintWriter out){ List list = banQuanService.getBanquanVideoAdmin(key, detailsystem, pageIndex); long count = banQuanService.getBanquanVideoAdminCount(key, detailsystem); PageEntity pe = new PageEntity(); pe.setPageIndex(pageIndex); pe.setPageSize(Constant.pageCount); Map map = new HashMap(); map.put("key", key); map.put("detailsystem", detailsystem + ""); pe.setParams(map); pe.setTotalCount((int) count); JSONObject json =new JSONObject(); json.put("code", "0"); json.put("pageEntity", pe); Gson gson =new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create(); json.put("copyRightList",gson.toJson(list)); out.print(json); } @RequestMapping(value="setCopyRightDetailSystem") public void set(String id,String detailSystem,String type,PrintWriter out){ if("add".equals(type)){ List list = new ArrayList(); VideoBanQuanVideo video = new VideoBanQuanVideo(); video.setCreatetime(System.currentTimeMillis() + ""); video.setDetailSystem(new DetailSystem(detailSystem)); video.setInfo(new VideoInfo(id)); video.setName(videoService.getVideoInfo(id).getName()); video.setShow(true); list.add(video); banQuanService.addBanQuanVideo(list); out.print("yes"); }else if("delete".equals(type)){ banQuanService.deleteBanQuanVideoAdmin(id, detailSystem); out.print("yes"); } } @RequestMapping(value="setDetailSystemByCopyRightKey") public void setDetailSystemByCopyRightKey(String id,String detailSystem,String type,PrintWriter out){ System.out.println("id---"+id); System.out.println("detailSystem-"+detailSystem); if("add".equals(type)){ List list = new ArrayList(); VideoBanQuan video = new VideoBanQuan(); video.setCreatetime(System.currentTimeMillis() + ""); video.setDetailSystem(new DetailSystem(detailSystem)); video.setName(id); video.setShow(true); list.add(video); banQuanService.addBanQuanKey(list); out.print("yes"); }else if("delete".equals(type)){ banQuanService.deleteBanQuanKeyAdmin(id, detailSystem); out.print("yes"); } } @RequestMapping("addCopyRirhtVideo") public void addCopyRirhtVideo(String ids,String detailSystems,PrintWriter out){ System.out.println("ids-"+ids); System.out.println("detailSystems-"+detailSystems); if (!StringUtil.isNullOrEmpty(ids)) { if (ids.endsWith(",")) ids = ids.substring(0, ids.length() - 1); } String[] systemArr = null; if (!StringUtil.isNullOrEmpty(detailSystems)) { systemArr = detailSystems.split(","); } String[] idArr = ids.split(","); List list = new ArrayList(); if(ids == null || "".equals(ids.trim())){ out.print("no"); return; } VideoBanQuanVideo video = null; if(systemArr != null && systemArr.length>0){ for (String sys : systemArr){ for (String id : idArr) { video=new VideoBanQuanVideo(); video.setCreatetime(System.currentTimeMillis() + ""); video.setDetailSystem(new DetailSystem(sys)); video.setInfo(new VideoInfo(id)); video.setName(videoService.getVideoInfo(id).getName()); video.setShow(true); list.add(video); } } }else{ out.append("no"); return; } banQuanService.addBanQuanVideo(list); out.append("yes"); } @RequestMapping("addCopyRightKey") public void addCopyRightKey(@RequestParam String[] ids,String detailSystems,PrintWriter out){ String[] systems = null; if (!StringUtil.isNullOrEmpty(detailSystems)) { systems = detailSystems.split(","); } if(ids==null || ids.length ==0){ out.print("no"); return; } List list = null; if (systems != null){ list = new ArrayList(); for (String sy : systems) for (String st : ids) { VideoBanQuan video = new VideoBanQuan(); video.setCreatetime(System.currentTimeMillis() + ""); video.setDetailSystem(new DetailSystem(sy)); video.setName(st); video.setShow(true); list.add(video); } } if(list != null && list.size() > 0 ){ banQuanService.addBanQuanKey(list); out.print("yes"); }else{ out.print("no"); } } @RequestMapping("deleteCopyRightVideo") public void deleteCopyRightVideo(String ids,PrintWriter out){ if(ids!=null && !"".equals(ids.trim())){ String[] idArr = ids.split(","); for (String id : idArr) { banQuanService.deleteBanQuanVideoByVID(id); } out.print("yes"); } } @RequestMapping("deleteCopyRightKey") public void deleteCopyRightKey(String[] ids,PrintWriter out){ if(ids == null || ids.length == 0){ out.print("no"); return; } for (String st : ids) { banQuanService.deleteBanQuanKeyByKey(st); } out.print("yes"); } /** * 搜索屏蔽 */ @RequestMapping("copyRightKeyList") public void copyRightKeyList(int pageIndex,String key,int detailsystem,PrintWriter out) { if (pageIndex == 0){ pageIndex = 1; } List list = banQuanService.getBanquanKeyAdmin(key, detailsystem, pageIndex); long count = banQuanService.getBanquanKeyAdminCount(key, detailsystem); PageEntity pe = new PageEntity(); pe.setPageIndex(pageIndex); pe.setPageSize(Constant.pageCount); Map map = new HashMap(); map.put("key", key); map.put("detailsystem", detailsystem + ""); pe.setParams(map); pe.setTotalCount((int) count); JSONObject json =new JSONObject(); json.put("code", "0"); json.put("pageEntity", pe); Gson gson =new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create(); json.put("copyRightKeyAdminList", gson.toJson(list)); out.print(json); return; } }