| | |
| | | package com.yeshi.buwan.controller.admin; |
| | | |
| | | import java.io.PrintWriter; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.util.HashMap; |
| | | import java.util.LinkedList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | import net.sf.json.JSONArray; |
| | | import net.sf.json.JSONObject; |
| | | |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestMethod; |
| | | |
| | | import com.google.gson.Gson; |
| | | import com.google.gson.GsonBuilder; |
| | | import com.yeshi.buwan.domain.DetailSystem; |
| | | import com.yeshi.buwan.domain.HomeVideo; |
| | | import com.yeshi.buwan.domain.HotVideoType; |
| | | import com.yeshi.buwan.domain.SuperHotType; |
| | | import com.yeshi.buwan.domain.SuperVideoType; |
| | | import com.yeshi.buwan.domain.VideoType; |
| | | import com.yeshi.buwan.domain.*; |
| | | import com.yeshi.buwan.domain.system.DetailSystem; |
| | | import com.yeshi.buwan.domain.web.CategoryRecommendVideoAdmin; |
| | | import com.yeshi.buwan.service.imp.ClassService; |
| | | import com.yeshi.buwan.service.imp.HomeTypeService; |
| | | import com.yeshi.buwan.service.imp.HotVideoTypeService; |
| | | import com.yeshi.buwan.service.imp.SystemService; |
| | | import com.yeshi.buwan.service.imp.recommend.CategoryRecommendVideoService; |
| | | import com.yeshi.buwan.util.Constant; |
| | | import com.yeshi.buwan.service.inter.recommend.HomeVideoService; |
| | | import com.yeshi.buwan.util.StringUtil; |
| | | import com.yeshi.buwan.util.SystemUtil; |
| | | import com.yeshi.buwan.web.tag.PageEntity; |
| | | import net.sf.json.JSONArray; |
| | | import net.sf.json.JSONObject; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestMethod; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import javax.servlet.http.HttpSession; |
| | | import java.io.PrintWriter; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | @Controller |
| | | @RequestMapping("") |
| | | public class ClassAdminController { |
| | | |
| | | @Resource |
| | | private HotVideoTypeService hotVideoTypeService; |
| | | @Resource |
| | | private HotVideoTypeService hotVideoTypeService; |
| | | |
| | | @Resource |
| | | private ClassService classService; |
| | | @Resource |
| | | private ClassService classService; |
| | | |
| | | @Resource |
| | | private HomeTypeService homeTypeService; |
| | | |
| | | @Resource |
| | | private CategoryRecommendVideoService categoryRecommendVideoService; |
| | | |
| | | @Resource |
| | | private SystemService systemService; |
| | | |
| | | private String key; |
| | | private int pageIndex; |
| | | private int detailsystem; |
| | | |
| | | |
| | | public CategoryRecommendVideoService getCategoryRecommendVideoService() { |
| | | return categoryRecommendVideoService; |
| | | } |
| | | @Resource |
| | | private HomeTypeService homeTypeService; |
| | | |
| | | public void setCategoryRecommendVideoService( |
| | | CategoryRecommendVideoService categoryRecommendVideoService) { |
| | | this.categoryRecommendVideoService = categoryRecommendVideoService; |
| | | } |
| | | @Resource |
| | | private HomeVideoService homeVideoService; |
| | | |
| | | public SystemService getSystemService() { |
| | | return systemService; |
| | | } |
| | | @Resource |
| | | private CategoryRecommendVideoService categoryRecommendVideoService; |
| | | |
| | | public void setSystemService(SystemService systemService) { |
| | | this.systemService = systemService; |
| | | } |
| | | private String key; |
| | | private int pageIndex; |
| | | private int detailsystem; |
| | | |
| | | public String getKey() { |
| | | return key; |
| | | } |
| | | |
| | | public void setKey(String key) { |
| | | this.key = key; |
| | | } |
| | | public String getKey() { |
| | | return key; |
| | | } |
| | | |
| | | public int getPageIndex() { |
| | | return pageIndex; |
| | | } |
| | | public void setKey(String key) { |
| | | this.key = key; |
| | | } |
| | | |
| | | public void setPageIndex(int pageIndex) { |
| | | this.pageIndex = pageIndex; |
| | | } |
| | | public int getPageIndex() { |
| | | return pageIndex; |
| | | } |
| | | |
| | | public int getDetailsystem() { |
| | | return detailsystem; |
| | | } |
| | | public void setPageIndex(int pageIndex) { |
| | | this.pageIndex = pageIndex; |
| | | } |
| | | |
| | | public void setDetailsystem(int detailsystem) { |
| | | this.detailsystem = detailsystem; |
| | | } |
| | | public int getDetailsystem() { |
| | | return detailsystem; |
| | | } |
| | | |
| | | public HotVideoTypeService getHotVideoTypeService() { |
| | | return hotVideoTypeService; |
| | | } |
| | | public void setDetailsystem(int detailsystem) { |
| | | this.detailsystem = detailsystem; |
| | | } |
| | | |
| | | public void setHotVideoTypeService(HotVideoTypeService hotVideoTypeService) { |
| | | this.hotVideoTypeService = hotVideoTypeService; |
| | | } |
| | | |
| | | public ClassService getClassService() { |
| | | return classService; |
| | | } |
| | | @RequestMapping(value = "/ClassAdminServlet", method = RequestMethod.GET) |
| | | public String get(HttpServletRequest req, PrintWriter out) { |
| | | try { |
| | | req.setCharacterEncoding("UTF-8"); |
| | | } catch (UnsupportedEncodingException e1) { |
| | | e1.printStackTrace(); |
| | | } |
| | | String type = req.getParameter("type"); |
| | | System.out.println("type--" + type); |
| | | if (type.equalsIgnoreCase("deleteHotType")) { |
| | | hotVideoTypeService.deleteHotType(new HotVideoType(req.getParameter("id"))); |
| | | |
| | | public void setClassService(ClassService classService) { |
| | | this.classService = classService; |
| | | } |
| | | return "hottype_list"; |
| | | } else if (type.equalsIgnoreCase("getVideoType")) { |
| | | String parentId = req.getParameter("parentId"); |
| | | java.util.List<VideoType> list = classService.getFirstTypeList(parentId); |
| | | JSONArray array = new JSONArray(); |
| | | for (VideoType t : list) { |
| | | JSONObject object = new JSONObject(); |
| | | object.put("Id", t.getId()); |
| | | object.put("Name", t.getName()); |
| | | array.add(object); |
| | | } |
| | | Gson gson = new Gson(); |
| | | gson.toJson(array); |
| | | out.print(gson.toJson(array)); |
| | | out.close(); |
| | | } else if (type.equalsIgnoreCase("deleteVideoTypeAll")) { |
| | | String ids = req.getParameter("ids"); |
| | | if (!StringUtil.isNullOrEmpty(ids)) { |
| | | if (ids.endsWith(",")) |
| | | ids = ids.substring(0, ids.length() - 1); |
| | | } |
| | | String[] idss = ids.split(","); |
| | | for (String st : idss) { |
| | | classService.deleteVideoType(st); |
| | | } |
| | | out.print("SUCCESS"); |
| | | } else if (type.equalsIgnoreCase("addSuperVideoType")) {// 分类分派 |
| | | String ids = req.getParameter("ids"); |
| | | String system = req.getParameter("system"); |
| | | String icon = req.getParameter("pictures"); |
| | | SuperVideoType svt = new SuperVideoType(); |
| | | svt.setCreatetime(System.currentTimeMillis() + ""); |
| | | svt.setDetailSystem(new DetailSystem(system)); |
| | | svt.setPicture(icon); |
| | | svt.setType(new VideoType(Long.parseLong(ids))); |
| | | classService.addSuperVideoType(svt); |
| | | out.print("SUCCESS"); |
| | | } else if (type.equalsIgnoreCase("deleteSuperVideoType")) { |
| | | String ids = req.getParameter("ids"); |
| | | String system = req.getParameter("system"); |
| | | classService.deleteVideoTypeAdmin(ids, system); |
| | | out.print("SUCCESS"); |
| | | } else if (type.equalsIgnoreCase("deleteHotTypeAll")) { |
| | | String ids = req.getParameter("ids"); |
| | | if (!StringUtil.isNullOrEmpty(ids)) { |
| | | if (ids.endsWith(",")) |
| | | ids = ids.substring(0, ids.length() - 1); |
| | | } |
| | | String[] idss = ids.split(","); |
| | | for (String st : idss) { |
| | | hotVideoTypeService.deleteHotType(new HotVideoType(st)); |
| | | } |
| | | out.print("SUCCESS"); |
| | | } else if (type.equalsIgnoreCase("addSuperHotType")) {// 分类分派 |
| | | String ids = req.getParameter("ids"); |
| | | String system = req.getParameter("system"); |
| | | SuperHotType svt = new SuperHotType(); |
| | | svt.setCreatetime(System.currentTimeMillis() + ""); |
| | | svt.setDetailSystem(new DetailSystem(system)); |
| | | svt.setHotType(new HotVideoType(ids)); |
| | | hotVideoTypeService.addSuperHotType(svt); |
| | | out.print("SUCCESS"); |
| | | } else if (type.equalsIgnoreCase("deleteSuperHotType")) { |
| | | String ids = req.getParameter("ids"); |
| | | String system = req.getParameter("system"); |
| | | classService.deleteHotTypeAdmin(ids, system); |
| | | out.print("SUCCESS"); |
| | | } else if (type.equalsIgnoreCase("changeHomeVideoPicture")) { |
| | | String homevideid = req.getParameter("id"); |
| | | String picture = req.getParameter("picture"); |
| | | HomeVideo hv = homeTypeService.getHomeVideoById(homevideid); |
| | | hv.setPicture(picture); |
| | | homeVideoService.updateHomeVideo(hv); |
| | | out.print("SUCCESS"); |
| | | } |
| | | return ""; |
| | | } |
| | | |
| | | public HomeTypeService getHomeTypeService() { |
| | | return homeTypeService; |
| | | } |
| | | @RequestMapping(value = "/ClassAdminServlet", method = RequestMethod.POST) |
| | | public String post(HttpServletRequest req, HttpServletResponse resp, PrintWriter out) { |
| | | try { |
| | | req.setCharacterEncoding("UTF-8"); |
| | | } catch (UnsupportedEncodingException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | public void setHomeTypeService(HomeTypeService homeTypeService) { |
| | | this.homeTypeService = homeTypeService; |
| | | } |
| | | String type = req.getParameter("type"); |
| | | if (type.equalsIgnoreCase("addHotType")) { |
| | | String step1 = req.getParameter("step1"); |
| | | String step2 = req.getParameter("step2"); |
| | | HotVideoType hotType = new HotVideoType(); |
| | | hotType.setAddType(1); |
| | | hotType.setCreatetime(System.currentTimeMillis() + ""); |
| | | if (!StringUtil.isNullOrEmpty(step2)) { |
| | | hotType.setType(new VideoType(Long.parseLong(step2))); |
| | | hotVideoTypeService.addHotType(hotType); |
| | | } else if (!StringUtil.isNullOrEmpty(step1)) { |
| | | hotType.setType(new VideoType(Long.parseLong(step1))); |
| | | hotVideoTypeService.addHotType(hotType); |
| | | } |
| | | |
| | | @RequestMapping(value = "/ClassAdminServlet", method = RequestMethod.GET) |
| | | public String get(HttpServletRequest req, PrintWriter out) { |
| | | try { |
| | | req.setCharacterEncoding("UTF-8"); |
| | | } catch (UnsupportedEncodingException e1) { |
| | | e1.printStackTrace(); |
| | | } |
| | | String type = req.getParameter("type"); |
| | | System.out.println("type--"+type); |
| | | if (type.equalsIgnoreCase("deleteHotType")) { |
| | | hotVideoTypeService.deleteHotType(new HotVideoType(req.getParameter("id"))); |
| | | return "hottype_add"; |
| | | } |
| | | return ""; |
| | | } |
| | | |
| | | return "hottype_list"; |
| | | } else if (type.equalsIgnoreCase("getVideoType")) { |
| | | String parentId = req.getParameter("parentId"); |
| | | java.util.List<VideoType> list = classService.getFirstTypeList(parentId); |
| | | JSONArray array = new JSONArray(); |
| | | for (VideoType t : list) { |
| | | JSONObject object = new JSONObject(); |
| | | object.put("Id", t.getId()); |
| | | object.put("Name", t.getName()); |
| | | array.add(object); |
| | | } |
| | | Gson gson = new Gson(); |
| | | gson.toJson(array); |
| | | out.print(gson.toJson(array)); |
| | | out.close(); |
| | | } else if (type.equalsIgnoreCase("deleteVideoTypeAll")) { |
| | | String ids = req.getParameter("ids"); |
| | | if (!StringUtil.isNullOrEmpty(ids)) { |
| | | if (ids.endsWith(",")) |
| | | ids = ids.substring(0, ids.length() - 1); |
| | | } |
| | | String[] idss = ids.split(","); |
| | | for (String st : idss) { |
| | | classService.deleteVideoType(st); |
| | | } |
| | | out.print("SUCCESS"); |
| | | } else if (type.equalsIgnoreCase("addSuperVideoType")) {// 分类分派 |
| | | String ids = req.getParameter("ids"); |
| | | String system = req.getParameter("system"); |
| | | String icon = req.getParameter("pictures"); |
| | | SuperVideoType svt = new SuperVideoType(); |
| | | svt.setCreatetime(System.currentTimeMillis() + ""); |
| | | svt.setDetailSystem(new DetailSystem(system)); |
| | | svt.setPicture(icon); |
| | | svt.setType(new VideoType(Long.parseLong(ids))); |
| | | classService.addSuperVideoType(svt); |
| | | out.print("SUCCESS"); |
| | | } else if (type.equalsIgnoreCase("deleteSuperVideoType")) { |
| | | String ids = req.getParameter("ids"); |
| | | String system = req.getParameter("system"); |
| | | classService.deleteVideoTypeAdmin(ids, system); |
| | | out.print("SUCCESS"); |
| | | } else if (type.equalsIgnoreCase("deleteHotTypeAll")) { |
| | | String ids = req.getParameter("ids"); |
| | | if (!StringUtil.isNullOrEmpty(ids)) { |
| | | if (ids.endsWith(",")) |
| | | ids = ids.substring(0, ids.length() - 1); |
| | | } |
| | | String[] idss = ids.split(","); |
| | | for (String st : idss) { |
| | | hotVideoTypeService.deleteHotType(new HotVideoType(st)); |
| | | } |
| | | out.print("SUCCESS"); |
| | | } else if (type.equalsIgnoreCase("addSuperHotType")) {// 分类分派 |
| | | String ids = req.getParameter("ids"); |
| | | String system = req.getParameter("system"); |
| | | SuperHotType svt = new SuperHotType(); |
| | | svt.setCreatetime(System.currentTimeMillis() + ""); |
| | | svt.setDetailSystem(new DetailSystem(system)); |
| | | svt.setHotType(new HotVideoType(ids)); |
| | | hotVideoTypeService.addSuperHotType(svt); |
| | | out.print("SUCCESS"); |
| | | } else if (type.equalsIgnoreCase("deleteSuperHotType")) { |
| | | String ids = req.getParameter("ids"); |
| | | String system = req.getParameter("system"); |
| | | classService.deleteHotTypeAdmin(ids, system); |
| | | out.print("SUCCESS"); |
| | | } else if (type.equalsIgnoreCase("changeHomeVideoPicture")) { |
| | | String homevideid = req.getParameter("id"); |
| | | String picture = req.getParameter("picture"); |
| | | HomeVideo hv = homeTypeService.getHomeVideoById(homevideid); |
| | | hv.setPicture(picture); |
| | | homeTypeService.updateHomeVideo(hv); |
| | | out.print("SUCCESS"); |
| | | } |
| | | return ""; |
| | | } |
| | | /** |
| | | * 关键字搜索列表 |
| | | * |
| | | * @return |
| | | */ |
| | | @RequestMapping("/search") |
| | | public void categoryRecommendVideoList(HttpServletRequest request, HttpSession session, PrintWriter out) { |
| | | if (pageIndex == 0) |
| | | pageIndex = 1; |
| | | key = request.getParameter("key"); |
| | | String videotype = request.getParameter("videotype"); |
| | | videotype = StringUtil.isNullOrEmpty(videotype) ? "150" : videotype; |
| | | |
| | | @RequestMapping(value = "/ClassAdminServlet", method = RequestMethod.POST) |
| | | public String post(HttpServletRequest req, HttpServletResponse resp, PrintWriter out) { |
| | | try { |
| | | req.setCharacterEncoding("UTF-8"); |
| | | } catch (UnsupportedEncodingException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | String type = req.getParameter("type"); |
| | | if (type.equalsIgnoreCase("addHotType")) { |
| | | String step1 = req.getParameter("step1"); |
| | | String step2 = req.getParameter("step2"); |
| | | HotVideoType hotType = new HotVideoType(); |
| | | hotType.setAddType(1); |
| | | hotType.setCreatetime(System.currentTimeMillis() + ""); |
| | | if (!StringUtil.isNullOrEmpty(step2)) { |
| | | hotType.setType(new VideoType(Long.parseLong(step2))); |
| | | hotVideoTypeService.addHotType(hotType); |
| | | } else if (!StringUtil.isNullOrEmpty(step1)) { |
| | | hotType.setType(new VideoType(Long.parseLong(step1))); |
| | | hotVideoTypeService.addHotType(hotType); |
| | | } |
| | | |
| | | return "hottype_add"; |
| | | } |
| | | return ""; |
| | | } |
| | | |
| | | /** |
| | | * 关键字搜索列表 |
| | | * |
| | | * @return |
| | | */ |
| | | @RequestMapping("/search") |
| | | public void categoryRecommendVideoList(HttpServletRequest request,PrintWriter out) { |
| | | if (pageIndex == 0) |
| | | pageIndex = 1; |
| | | key = request.getParameter("key"); |
| | | String videotype = request.getParameter("videotype"); |
| | | videotype = StringUtil.isNullOrEmpty(videotype) ? "150" : videotype; |
| | | |
| | | List<CategoryRecommendVideoAdmin> list = categoryRecommendVideoService.getCategoryRecommendVideoAdmin(key, |
| | | Integer.parseInt(videotype), detailsystem, pageIndex); |
| | | long count = categoryRecommendVideoService.getCategoryRecommendVideoAdminCount(key, Integer.parseInt(videotype), |
| | | detailsystem); |
| | | PageEntity pe = new PageEntity(); |
| | | pe.setPageIndex(pageIndex); |
| | | pe.setPageSize(1); |
| | | Map<String, String> map = new HashMap<String, String>(); |
| | | map.put("key", key); |
| | | map.put("detailsystem", detailsystem + ""); |
| | | map.put("videotype", videotype + ""); |
| | | pe.setParams(map); |
| | | pe.setTotalCount((int) count); |
| | | Gson gson=new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create(); |
| | | JSONObject root = new JSONObject(); |
| | | root.put("code", "0"); |
| | | root.put("pageEntity", pe); |
| | | String json = gson.toJson(list); |
| | | root.put("crv", json); |
| | | List<CategoryRecommendVideoAdmin> list = categoryRecommendVideoService.getCategoryRecommendVideoAdmin(key, |
| | | Integer.parseInt(videotype), SystemUtil.getAdminSelectedSystemId(session), detailsystem, pageIndex); |
| | | long count = categoryRecommendVideoService.getCategoryRecommendVideoAdminCount(key, Integer.parseInt(videotype), |
| | | SystemUtil.getAdminSelectedSystemId(session), detailsystem); |
| | | PageEntity pe = new PageEntity(); |
| | | pe.setPageIndex(pageIndex); |
| | | pe.setPageSize(1); |
| | | Map<String, String> map = new HashMap<String, String>(); |
| | | map.put("key", key); |
| | | map.put("detailsystem", detailsystem + ""); |
| | | map.put("videotype", videotype + ""); |
| | | pe.setParams(map); |
| | | pe.setTotalCount((int) count); |
| | | Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create(); |
| | | JSONObject root = new JSONObject(); |
| | | root.put("code", "0"); |
| | | root.put("pageEntity", pe); |
| | | String json = gson.toJson(list); |
| | | root.put("crv", json); |
| | | // for (CategoryRecommendVideoAdmin categoryRecommendVideoAdmin : list) { |
| | | // System.out.println(categoryRecommendVideoAdmin.getCategoryRecommendVideo().getCategoryRecommendVideo()); |
| | | // root.put("categoryRecommendVideoAdmin", gson.toJson(categoryRecommendVideoAdmin.getCategoryRecommendVideo().getCategoryRecommendVideo())); |
| | | // } |
| | | System.out.println(root.toString()); |
| | | out.print(root); |
| | | System.out.println(root.toString()); |
| | | out.print(root); |
| | | // dataMap.put("categoryRecommendVideoAdminList", list); |
| | | List<DetailSystem> detailSystemList = systemService.getDetailSystemList(); |
| | | // dataMap.put("detailSystemList", detailSystemList); |
| | | List<VideoType> typeList = classService.getFirstTypeList(""); |
| | | // dataMap.put("videoTypeList", typeList); |
| | | // json.put("data", data); |
| | | // System.out.println("jsonStr---------"+jsonStr); |
| | | // out.print(jsonStr); |
| | | |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | } |