package com.yeshi.buwan.controller.admin; import java.io.PrintWriter; import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.List; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import com.yeshi.buwan.domain.system.DetailSystem; import com.yeshi.buwan.domain.HomeAd; import com.yeshi.buwan.domain.HomeNotice; import com.yeshi.buwan.domain.HomeType; import com.yeshi.buwan.domain.HotSearch; import com.yeshi.buwan.domain.HotVideoType; import com.yeshi.buwan.domain.RecommendAd; import com.yeshi.buwan.domain.SuperHomeNotice; import com.yeshi.buwan.domain.SuperHotSearch; import com.yeshi.buwan.domain.SuperHotType; import com.yeshi.buwan.domain.SuperRecommendAd; import com.yeshi.buwan.domain.SuperUserBanner; import com.yeshi.buwan.domain.SuperVideoType; import com.yeshi.buwan.domain.UserBanner; import com.yeshi.buwan.domain.VideoBanQuan; import com.yeshi.buwan.domain.VideoBanQuanVideo; import com.yeshi.buwan.domain.VideoInfo; import com.yeshi.buwan.domain.VideoType; import com.yeshi.buwan.service.imp.AdService; import com.yeshi.buwan.service.imp.BanQuanService; import com.yeshi.buwan.service.imp.ClassService; import com.yeshi.buwan.service.imp.HomeAdService; import com.yeshi.buwan.service.imp.HomeNoticeService; import com.yeshi.buwan.service.imp.HomeTypeService; import com.yeshi.buwan.service.imp.HotVideoTypeService; import com.yeshi.buwan.service.imp.SearchService; import com.yeshi.buwan.service.imp.UserBannerService; import com.yeshi.buwan.service.imp.VideoService; import com.yeshi.buwan.util.StringUtil; import net.sf.json.JSONArray; import net.sf.json.JSONObject; @Controller @RequestMapping("") public class BanQuanController { @Resource private BanQuanService banQuanService; @Resource private HomeAdService homeAdService; @Resource private HomeTypeService homeTypeService; @Resource private ClassService classService; @Resource private AdService adService; @Resource private VideoService videoService; @Resource private SearchService searchService; @Resource private HotVideoTypeService hotVideoTypeService; @Resource private UserBannerService userBannerService; @Resource private HomeNoticeService homeNoticeService; @RequestMapping(value = "/BanQuanServlet", method = RequestMethod.GET) public void get(HttpServletRequest request, PrintWriter out) { try { request.setCharacterEncoding("UTF-8"); } catch (UnsupportedEncodingException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } String type = request.getParameter("type"); if (type.equalsIgnoreCase("getSystemHomeAd")) { List list = homeAdService.getSuperHomeAdList(request.getParameter("id")); JSONArray array = new JSONArray(); if (list != null) { for (HomeAd ad : list) { JSONObject object = new JSONObject(); object.put("Id", ad.getId()); object.put("Picture", ad.getPicture()); array.add(object); } } out.print(array.toString()); } else if (type.equalsIgnoreCase("changeBanQuanShow")) {// VideoBanQuanVideo video = banQuanService.getBanQuanVideo(request.getParameter("id")); video.setShow(!video.isShow()); banQuanService.updateVideoBanQuanVideo(video); out.print("SUCCESS"); } else if (type.equalsIgnoreCase("changeBanQuanKeyShow")) {// VideoBanQuan video = banQuanService.getBanQuanKey(request.getParameter("id")); video.setShow(!video.isShow()); banQuanService.updateVideoBanQuan(video); out.print("SUCCESS"); } else if (type.equalsIgnoreCase("addBanQuanVideo")) {// 版权视频添加 String ids = request.getParameter("ids"); String system = request.getParameter("system"); if (!StringUtil.isNullOrEmpty(ids)) { if (ids.endsWith(",")) ids = ids.substring(0, ids.length() - 1); } String[] systems = null; if (!StringUtil.isNullOrEmpty(system)) { systems = system.split(","); } String[] idss = ids.split(","); List list = new ArrayList<>(); for (String sy : systems) for (String st : idss) { VideoBanQuanVideo video = new VideoBanQuanVideo(); video.setCreatetime(System.currentTimeMillis() + ""); video.setDetailSystem(new DetailSystem(sy)); video.setInfo(new VideoInfo(st)); video.setName(videoService.getVideoInfo(st).getName()); video.setShow(true); list.add(video); } banQuanService.addBanQuanVideo(list); out.print("SUCCESS"); } else if (type.equalsIgnoreCase("addBanQuanKey")) {// 版权视频添加 String ids = request.getParameter("ids"); try { ids = new String(ids.getBytes("ISO-8859-1"), "UTF-8"); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } String system = request.getParameter("system"); if (!StringUtil.isNullOrEmpty(ids)) { if (ids.endsWith(",")) ids = ids.substring(0, ids.length() - 1); } String[] systems = null; if (!StringUtil.isNullOrEmpty(system)) { systems = system.split(","); } String[] idss = ids.split(","); List list = new ArrayList<>(); if (systems != null) for (String sy : systems) for (String st : idss) { VideoBanQuan video = new VideoBanQuan(); video.setCreatetime(System.currentTimeMillis() + ""); video.setDetailSystem(new DetailSystem(sy)); video.setName(st); video.setShow(true); list.add(video); } banQuanService.addBanQuanKey(list); out.print("SUCCESS"); } else if (type.equalsIgnoreCase("deleteBanQuanVideo")) {// 版权视频添加 String system = request.getParameter("system"); String ids = request.getParameter("ids"); if (!StringUtil.isNullOrEmpty(ids)) { if (ids.endsWith(",")) ids = ids.substring(0, ids.length() - 1); } String[] systems = null; if (!StringUtil.isNullOrEmpty(system)) { systems = system.split(","); } String[] idss = ids.split(","); if (systems != null) for (String sy : systems) for (String st : idss) { banQuanService.deleteBanQuanVideoAdmin(st, sy); } out.print("SUCCESS"); } else if (type.equalsIgnoreCase("deleteBanQuanKey")) {// 版权视频添加 String ids = request.getParameter("ids"); try { ids = new String(ids.getBytes("ISO-8859-1"), "UTF-8"); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } String system = request.getParameter("system"); if (!StringUtil.isNullOrEmpty(ids)) { if (ids.endsWith(",")) ids = ids.substring(0, ids.length() - 1); } String[] systems = null; if (!StringUtil.isNullOrEmpty(system)) { systems = system.split(","); } String[] idss = ids.split(","); if (systems != null) for (String sy : systems) for (String st : idss) { banQuanService.deleteBanQuanKeyAdmin(st, sy); } out.print("SUCCESS"); } else if (type.equalsIgnoreCase("deleteBanQuanKeyAll")) {// 版权视频添加 String ids = request.getParameter("ids"); try { ids = new String(ids.getBytes("ISO-8859-1"), "UTF-8"); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (!StringUtil.isNullOrEmpty(ids)) { if (ids.endsWith(",")) ids = ids.substring(0, ids.length() - 1); } String[] idss = ids.split(","); for (String st : idss) { banQuanService.deleteBanQuanKeyByKey(st); } out.print("SUCCESS"); } else if (type.equalsIgnoreCase("deleteBanQuanVideoAll")) {// 版权视频添加 String ids = request.getParameter("ids"); if (!StringUtil.isNullOrEmpty(ids)) { if (ids.endsWith(",")) ids = ids.substring(0, ids.length() - 1); } String[] idss = ids.split(","); for (String st : idss) { banQuanService.deleteBanQuanVideoByVID(st); } out.print("SUCCESS"); } } @RequestMapping(value = "/BanQuanServlet", method = RequestMethod.POST) public String post(HttpServletRequest req, HttpServletResponse resp, PrintWriter out) { try { req.setCharacterEncoding("UTF-8"); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } String type = req.getParameter("type"); if (type.equalsIgnoreCase("updateSuperHomeAd")) {// 更新超级首页广告 String detailSystemId = req.getParameter("id"); String[] ads = req.getParameterValues("homeadids"); if (ads.length > 0)// 添加广告 { List list = new ArrayList<>(); for (String ad : ads) { list.add(new HomeAd(ad)); } homeAdService.updateSuperHomeAdList(detailSystemId, list); } req.setAttribute("id", detailSystemId); return "super_homead_edit"; } else if (type.equalsIgnoreCase("updateSuperHomeType")) {// 更新超级首页广告 String detailSystemId = req.getParameter("id"); String[] ads = req.getParameterValues("homeadids"); if (ads != null && ads.length > 0)// 添加广告 { List list = new ArrayList<>(); for (String ad : ads) { list.add(new HomeType(ad)); } homeTypeService.updateSuperHomeTypeList(detailSystemId, list); } req.setAttribute("id", detailSystemId); return "super_hometype_edit"; } else if (type.equalsIgnoreCase("updateSuperVideoType")) {// 更新超级首页广告 String detailSystemId = req.getParameter("id"); String[] ads = req.getParameterValues("homeadids"); String[] pictures = req.getParameterValues("pictures"); if (ads != null && ads.length > 0)// 添加广告 { List list = new ArrayList<>(); for (int i = 0; i < ads.length; i++) { SuperVideoType vt = new SuperVideoType(); vt.setCreatetime(System.currentTimeMillis() + ""); vt.setDetailSystem(new DetailSystem(detailSystemId)); vt.setPicture(pictures[i]); vt.setType(new VideoType(Integer.parseInt(ads[i]))); list.add(vt); } classService.updateSuperVideoTypeList(detailSystemId, list); } req.setAttribute("id", detailSystemId); return "super_videotype_edit"; } else if (type.equalsIgnoreCase("updateSuperHotType")) {// 更新超级首页广告 String detailSystemId = req.getParameter("id"); String[] ads = req.getParameterValues("homeadids"); if (ads != null && ads.length > 0)// 添加广告 { List list = new ArrayList<>(); for (int i = 0; i < ads.length; i++) { SuperHotType vt = new SuperHotType(); vt.setCreatetime(System.currentTimeMillis() + ""); vt.setDetailSystem(new DetailSystem(detailSystemId)); vt.setHotType(new HotVideoType(ads[i])); list.add(vt); } hotVideoTypeService.updateSuperHotTypeList(detailSystemId, list); } req.setAttribute("id", detailSystemId); return "super_hottype_edit"; } else if (type.equalsIgnoreCase("updateSuperHotSearch")) {// 更新超级首页广告 String detailSystemId = req.getParameter("id"); String[] ads = req.getParameterValues("homeadids"); if (ads != null && ads.length > 0)// 添加广告 { List list = new ArrayList<>(); for (int i = 0; i < ads.length; i++) { SuperHotSearch vt = new SuperHotSearch(); vt.setCreatetime(System.currentTimeMillis() + ""); vt.setDetailSystem(new DetailSystem(detailSystemId)); vt.setHotSearch(new HotSearch(ads[i])); list.add(vt); } searchService.updateSuperHotSearchList(detailSystemId, list); } req.setAttribute("id", detailSystemId); return "super_hotsearch_edit"; } else if (type.equalsIgnoreCase("updateSuperRecommendAd")) {// 更新超级首页广告 String detailSystemId = req.getParameter("id"); String[] ads = req.getParameterValues("homeadids"); if (ads != null && ads.length > 0)// 添加广告 { List list = new ArrayList<>(); for (int i = 0; i < ads.length; i++) { SuperRecommendAd vt = new SuperRecommendAd(); vt.setCreatetime(System.currentTimeMillis() + ""); vt.setDetailSystem(new DetailSystem(detailSystemId)); vt.setRecommendAd(new RecommendAd(ads[i])); list.add(vt); } adService.updateSuperRecommendAdList(detailSystemId, list); } req.setAttribute("id", detailSystemId); return "super_recommendad_edit"; } else if (type.equalsIgnoreCase("updateSuperUserBanner")) {// 更新超级首页广告 String detailSystemId = req.getParameter("id"); String[] ads = req.getParameterValues("homeadids"); if (ads != null && ads.length > 0)// 添加广告 { List list = new ArrayList<>(); for (int i = 0; i < ads.length; i++) { SuperUserBanner vt = new SuperUserBanner(); vt.setCreatetime(System.currentTimeMillis() + ""); vt.setDetailSystem(new DetailSystem(detailSystemId)); vt.setUserBanner(new UserBanner(ads[i])); list.add(vt); } userBannerService.updateSuperUserBannerList(detailSystemId, list); } req.setAttribute("id", detailSystemId); return "super_userbanner_edit"; } else if (type.equalsIgnoreCase("updateSuperHomeNotice")) {// 更新小黄条 String detailSystemId = req.getParameter("id"); String[] ads = req.getParameterValues("homeadids"); if (ads != null && ads.length > 0)// 添加广告 { List list = new ArrayList<>(); for (int i = 0; i < ads.length; i++) { SuperHomeNotice vt = new SuperHomeNotice(); vt.setCreatetime(System.currentTimeMillis() + ""); vt.setDetailSystem(new DetailSystem(detailSystemId)); vt.setHomeNotice(new HomeNotice(ads[i])); list.add(vt); } homeNoticeService.updateSuperHomeNoticeList(detailSystemId, list); } req.setAttribute("id", detailSystemId); return "super_homenotice_edit"; } return ""; } }