From d73687bc6115007145b4aab050e4e29ff87fd8ae Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期一, 01 三月 2021 18:44:36 +0800 Subject: [PATCH] 布丸代码优化 --- src/main/java/com/yeshi/buwan/controller/admin/api/ClassController.java | 586 ++++++++++++++++++++++++++++------------------------------ 1 files changed, 286 insertions(+), 300 deletions(-) diff --git a/src/main/java/com/yeshi/buwan/controller/admin/api/ClassController.java b/src/main/java/com/yeshi/buwan/controller/admin/api/ClassController.java index c3bd146..f776669 100644 --- a/src/main/java/com/yeshi/buwan/controller/admin/api/ClassController.java +++ b/src/main/java/com/yeshi/buwan/controller/admin/api/ClassController.java @@ -7,8 +7,10 @@ import java.util.Map; import javax.annotation.Resource; - +import javax.servlet.http.HttpSession; + +import com.yeshi.buwan.util.*; import net.sf.json.JSONArray; import net.sf.json.JSONObject; @@ -32,325 +34,309 @@ import com.yeshi.buwan.service.imp.HomeTypeService; 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.util.EhcacheUtil; -import com.yeshi.buwan.util.JsonUtil; -import com.yeshi.buwan.util.StringUtil; import com.yeshi.buwan.web.tag.PageEntity; @Controller @RequestMapping("admin/new/api/class") public class ClassController { - @Resource - private ClassService classService; + @Resource + private ClassService classService; - @Resource - private HomeTypeService homeTypeService; + @Resource + private HomeTypeService homeTypeService; - @Resource - private CategoryRecommendVideoService categoryRecommendVideoService; + @Resource + private CategoryRecommendVideoService categoryRecommendVideoService; - @Resource - private SystemService systemService; - - @Resource - private CategoryAreaService categoryAreaService; + @Resource + private SystemService systemService; - @RequestMapping(value = "/getnextclass", method = RequestMethod.POST) - public void getNextClass(int pid, PrintWriter out) { - System.out.println("pid--" + pid); - List<VideoType> list; - if (pid <= 0) - list = classService.getNextTypeList(""); - else - list = classService.getNextTypeList(pid + ""); + @Resource + private CategoryAreaService categoryAreaService; - JSONArray array = new JSONArray(); - if (list != null) - for (VideoType type : list) { - JSONObject obj = new JSONObject(); - obj.put("id", type.getId()); - obj.put("name", type.getName()); - array.add(obj); - } - JSONObject object = new JSONObject(); - object.put("code", 0); - object.put("data", array); - out.print(object); - } - @RequestMapping("getAllFirstClass") - public void getAllFirstClass(PrintWriter out){ - List<VideoType> list = classService.getAllVideoType(); - JSONArray array = new JSONArray(); - if (list != null) - for (VideoType type : list) { - JSONObject obj = new JSONObject(); - obj.put("id", type.getId()); - obj.put("name", type.getName()); - array.add(obj); - } - JSONObject object = new JSONObject(); - object.put("code", 0); - object.put("data", array); - out.print(object); - } + @RequestMapping(value = "/getnextclass", method = RequestMethod.POST) + public void getNextClass(int pid, PrintWriter out) { + System.out.println("pid--" + pid); + List<VideoType> list; + if (pid <= 0) + list = classService.getNextTypeList(""); + else + list = classService.getNextTypeList(pid + ""); - @RequestMapping(value = "/gethometypelist", method = RequestMethod.POST) - public void getHomeTypeList(int pid, PrintWriter out) { - List<HomeType> list = homeTypeService.getHomeType(); + JSONArray array = new JSONArray(); + if (list != null) + for (VideoType type : list) { + JSONObject obj = new JSONObject(); + obj.put("id", type.getId()); + obj.put("name", type.getName()); + array.add(obj); + } + JSONObject object = new JSONObject(); + object.put("code", 0); + object.put("data", array); + out.print(object); + } - JSONArray array = new JSONArray(); - if (list != null) - for (HomeType type : list) { - JSONObject obj = new JSONObject(); - obj.put("id", type.getId()); - obj.put("name", type.getName()); - array.add(obj); - } - JSONObject object = new JSONObject(); - object.put("code", 0); - object.put("data", array); - out.print(object); - } + @RequestMapping("getAllFirstClass") + public void getAllFirstClass(PrintWriter out) { + List<VideoType> list = classService.getAllVideoType(); + JSONArray array = new JSONArray(); + if (list != null) + for (VideoType type : list) { + JSONObject obj = new JSONObject(); + obj.put("id", type.getId()); + obj.put("name", type.getName()); + array.add(obj); + } + JSONObject object = new JSONObject(); + object.put("code", 0); + object.put("data", array); + out.print(object); + } - @RequestMapping(value = "/addhomevideos", method = RequestMethod.POST) - public void addHomeVideos(int hometypeid, String videos, String pictures, - String tags, PrintWriter out) { - String[] videoStr = videos.split(","); - String[] pictureStr = pictures.split(","); - String[] tagStr = tags.split(","); + @RequestMapping(value = "/gethometypelist", method = RequestMethod.POST) + public void getHomeTypeList(int pid, PrintWriter out) { + List<HomeType> list = homeTypeService.getHomeType(); - List<HomeVideo> list = new ArrayList<HomeVideo>(); - for (int i = 0; i < videoStr.length; i++) { - HomeVideo hv = new HomeVideo(); - hv.setCreatetime(System.currentTimeMillis() + ""); - hv.setTag(tagStr[i]); - hv.setPicture(pictureStr[i]); - hv.setType(new HomeType(hometypeid + "")); - hv.setVideo(new VideoInfo(videoStr[i])); - } + JSONArray array = new JSONArray(); + if (list != null) + for (HomeType type : list) { + JSONObject obj = new JSONObject(); + obj.put("id", type.getId()); + obj.put("name", type.getName()); + array.add(obj); + } + JSONObject object = new JSONObject(); + object.put("code", 0); + object.put("data", array); + out.print(object); + } - homeTypeService.addHomeTypeVideo(list); - JSONObject object = new JSONObject(); - object.put("code", 0); - object.put("msg", "娣诲姞鎴愬姛"); - out.print(object); - } - - /** - * 鎼滅储 - * @param key - * @param detailsystem - * @param videotype - * @param page - * @param out - */ - @RequestMapping(value = "/getseachList",method=RequestMethod.POST) - public void categoryRecommendVideoList(String key, String detailsystem, - String videotype, String page, PrintWriter out) { - - if(detailsystem==null || "".equals(detailsystem.trim())){ - detailsystem="0"; - } - - if(page==null || "".equals(page.trim())){ - page="1"; - } - - int pageIndex = Integer.parseInt(page); - if (pageIndex == 0) - pageIndex = 1; + @RequestMapping(value = "/addhomevideos", method = RequestMethod.POST) + public void addHomeVideos(int hometypeid, String videos, String pictures, + String tags, PrintWriter out) { + String[] videoStr = videos.split(","); + String[] pictureStr = pictures.split(","); + String[] tagStr = tags.split(","); - videotype = StringUtil.isNullOrEmpty(videotype) ? "150" : videotype; - - List<CategoryRecommendVideoAdmin> list = categoryRecommendVideoService - .getCategoryRecommendVideoAdmin(key, - Integer.parseInt(videotype), Integer.parseInt(detailsystem), pageIndex); - long count = categoryRecommendVideoService - .getCategoryRecommendVideoAdminCount(key, - Integer.parseInt(videotype), Integer.parseInt(detailsystem)); - PageEntity pe = new PageEntity(); - pe.setPageIndex(pageIndex); - pe.setPageSize(Constant.pageCount); - 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); - // 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); - } - - @RequestMapping(value="/deleteCategoryRecommendVideo",method=RequestMethod.POST) - public void deleteCategoryRecommendVideo(String ids,PrintWriter out) { - - if(ids == null || ids.trim().length()==0){ - return; - } - String[] idArr = ids.split(","); - for (String id : idArr) { - System.out.println(id); - categoryRecommendVideoService.deleteCategoryRecommendVideo(new CategoryRecommendVideo(id)); - } - out.print("yes"); - } - - @RequestMapping(value="/getCategoryRecommendVideo",method=RequestMethod.POST) - public void getCategoryRecommendVideo(String id,PrintWriter out) { + List<HomeVideo> list = new ArrayList<HomeVideo>(); + for (int i = 0; i < videoStr.length; i++) { + HomeVideo hv = new HomeVideo(); + hv.setCreatetime(System.currentTimeMillis() + ""); + hv.setTag(tagStr[i]); + hv.setPicture(pictureStr[i]); + hv.setType(new HomeType(hometypeid + "")); + hv.setVideo(new VideoInfo(videoStr[i])); + } + + homeTypeService.addHomeTypeVideo(list); + JSONObject object = new JSONObject(); + object.put("code", 0); + object.put("msg", "娣诲姞鎴愬姛"); + out.print(object); + } + + /** + * 鎼滅储 + * + * @param key + * @param detailsystem + * @param videotype + * @param page + * @param out + */ + @RequestMapping(value = "/getseachList", method = RequestMethod.POST) + public void categoryRecommendVideoList(String key, String detailsystem, + String videotype, String page, HttpSession session, PrintWriter out) { + + if (detailsystem == null || "".equals(detailsystem.trim())) { + detailsystem = "0"; + } + + if (page == null || "".equals(page.trim())) { + page = "1"; + } + + int pageIndex = Integer.parseInt(page); + if (pageIndex == 0) + pageIndex = 1; + + videotype = StringUtil.isNullOrEmpty(videotype) ? "150" : videotype; + + List<CategoryRecommendVideoAdmin> list = categoryRecommendVideoService + .getCategoryRecommendVideoAdmin(key, + Integer.parseInt(videotype), SystemUtil.getAdminSelectedSystemId(session), Integer.parseInt(detailsystem), pageIndex); + long count = categoryRecommendVideoService + .getCategoryRecommendVideoAdminCount(key, + Integer.parseInt(videotype), SystemUtil.getAdminSelectedSystemId(session), Integer.parseInt(detailsystem)); + PageEntity pe = new PageEntity(); + pe.setPageIndex(pageIndex); + pe.setPageSize(Constant.pageCount); + 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); + System.out.println(root.toString()); + out.print(root); + } + + @RequestMapping(value = "/deleteCategoryRecommendVideo", method = RequestMethod.POST) + public void deleteCategoryRecommendVideo(String ids, PrintWriter out) { + + if (ids == null || ids.trim().length() == 0) { + return; + } + String[] idArr = ids.split(","); + for (String id : idArr) { + System.out.println(id); + categoryRecommendVideoService.deleteCategoryRecommendVideo(new CategoryRecommendVideo(id)); + } + out.print("yes"); + } + + @RequestMapping(value = "/getCategoryRecommendVideo", method = RequestMethod.POST) + public void getCategoryRecommendVideo(String id, PrintWriter out) { // id = StringUtil.isNullOrEmpty(id) ? request.getAttribute("id").toString() : id; - Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation() - .create(); - JSONObject root = new JSONObject(); - CategoryRecommendVideo categoryRecommendVideo = categoryRecommendVideoService.getCategoryRecommendVideoById(id); - if(categoryRecommendVideo != null){ - String json = gson.toJson(categoryRecommendVideo); - root.put("code", "0"); - root.put("crv", json); - }else{ - root.put("code", "1"); - root.put("crv", null); - } - out.print(root); - - //request.setAttribute("videoTypeList", classService.getFirstTypeList("")); + Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation() + .create(); + JSONObject root = new JSONObject(); + CategoryRecommendVideo categoryRecommendVideo = categoryRecommendVideoService.getCategoryRecommendVideoById(id); + if (categoryRecommendVideo != null) { + String json = gson.toJson(categoryRecommendVideo); + root.put("code", "0"); + root.put("crv", json); + } else { + root.put("code", "1"); + root.put("crv", null); + } + out.print(root); + + //request.setAttribute("videoTypeList", classService.getFirstTypeList("")); // request.setAttribute("systemList", systemService.getSystemList()); // request.setAttribute("categoryRecommendVideo", categoryRecommendVideo); - return ; - } - - @RequestMapping(value="/setCategoryRecommendVideo",method=RequestMethod.POST) - public void updateCategoryRecommendVideo(String id,String beizhu,String desc,int orderby,String picture,String videoid,String videotype,PrintWriter out) { - - //id涓虹┖鍒欐柊鍔� - if(id == null || "".equals(id.trim())){ - CategoryRecommendVideo newCategoryRecommendVideo=new CategoryRecommendVideo(); - newCategoryRecommendVideo.setBeizhu(beizhu); - newCategoryRecommendVideo.setCreatetime(System.currentTimeMillis() + ""); - newCategoryRecommendVideo.setDesc(desc); -// categoryRecommendVideo.setJpos(jpos); - newCategoryRecommendVideo.setOrderby(orderby); - newCategoryRecommendVideo.setPicture(picture); - newCategoryRecommendVideo.setVideoInfo(new VideoInfo(videoid)); - newCategoryRecommendVideo.setVideoType(new VideoType(Long.parseLong(videotype))); - categoryRecommendVideoService.addCategoryRecommendVideo(newCategoryRecommendVideo); - - SuperCategoryRecommendVideo sz=null; - List<DetailSystem> list = systemService.getDetailSystemList(); - for (DetailSystem ds : list) { - sz= new SuperCategoryRecommendVideo(); - sz.setDetailSystem(new DetailSystem(ds.getId())); - sz.setCategoryRecommendVideo(newCategoryRecommendVideo); - categoryRecommendVideoService.addSuperCategoryRecommendVideo(sz); - } - - out.print("yes"); - return; - } - CategoryRecommendVideo categoryRecommendVideo = categoryRecommendVideoService.getCategoryRecommendVideoById(id); - categoryRecommendVideo.setBeizhu(beizhu); - categoryRecommendVideo.setCreatetime(System.currentTimeMillis() + ""); - categoryRecommendVideo.setDesc(desc); + return; + } + + @RequestMapping(value = "/setCategoryRecommendVideo", method = RequestMethod.POST) + public void updateCategoryRecommendVideo(String id, String beizhu, String desc, int orderby, String picture, String videoid, String videotype, HttpSession session, PrintWriter out) { + + //id涓虹┖鍒欐柊鍔� + if (id == null || "".equals(id.trim())) { + CategoryRecommendVideo newCategoryRecommendVideo = new CategoryRecommendVideo(); + newCategoryRecommendVideo.setBeizhu(beizhu); + newCategoryRecommendVideo.setCreatetime(System.currentTimeMillis() + ""); + newCategoryRecommendVideo.setDesc(desc); + newCategoryRecommendVideo.setOrderby(orderby); + newCategoryRecommendVideo.setPicture(picture); + newCategoryRecommendVideo.setVideoInfo(new VideoInfo(videoid)); + newCategoryRecommendVideo.setVideoType(new VideoType(Long.parseLong(videotype))); + newCategoryRecommendVideo.setSystem(SystemUtil.getAdminSelectedSystem(session)); + + categoryRecommendVideoService.addCategoryRecommendVideo(newCategoryRecommendVideo); + + SuperCategoryRecommendVideo sz = null; + List<DetailSystem> list = systemService.getDetailSystemList(SystemUtil.getAdminSelectedSystem(session).getId()); + for (DetailSystem ds : list) { + sz = new SuperCategoryRecommendVideo(); + sz.setDetailSystem(new DetailSystem(ds.getId())); + sz.setCategoryRecommendVideo(newCategoryRecommendVideo); + categoryRecommendVideoService.addSuperCategoryRecommendVideo(sz); + } + + out.print("yes"); + return; + } + CategoryRecommendVideo categoryRecommendVideo = categoryRecommendVideoService.getCategoryRecommendVideoById(id); + categoryRecommendVideo.setBeizhu(beizhu); + categoryRecommendVideo.setCreatetime(System.currentTimeMillis() + ""); + categoryRecommendVideo.setDesc(desc); // categoryRecommendVideo.setJpos(jpos); - categoryRecommendVideo.setOrderby(orderby); - categoryRecommendVideo.setPicture(picture); - categoryRecommendVideo.setVideoInfo(new VideoInfo(videoid)); - categoryRecommendVideo.setVideoType(new VideoType(Long.parseLong(videotype))); - categoryRecommendVideoService.updateCategoryRecommendVideo(categoryRecommendVideo); - out.print("yes"); - return ; - } - - - @RequestMapping(value = "/CategoryRecommendVideoAdminServlet", method = RequestMethod.POST) - public void set(String type, String id, String systemid,PrintWriter out) { - - System.out.println("type--"+type); - System.out.println("id--"+id); - System.out.println("systemid--"+systemid); - - if ("add".equalsIgnoreCase(type)) {// 鑾峰彇鏉ユ簮鍒楄〃 - if (!StringUtil.isNullOrEmpty(systemid) && !StringUtil.isNullOrEmpty(id)) { - SuperCategoryRecommendVideo sz=new SuperCategoryRecommendVideo(); - sz.setDetailSystem(new DetailSystem(systemid)); - sz.setCategoryRecommendVideo(new CategoryRecommendVideo(id)); - categoryRecommendVideoService.addSuperCategoryRecommendVideo(sz); - } - out.print("yes"); - } else if ("delete".equalsIgnoreCase(type)) { - if (!StringUtil.isNullOrEmpty(systemid) && !StringUtil.isNullOrEmpty(id)) { - categoryRecommendVideoService.deleteCategoryRecommendVideoAdmin(id, systemid); - } - out.print("yes"); - } - } - - @RequestMapping("getAreaList") - public void getAreaList(long cid,PrintWriter out){ - List<CategoryContry> list = categoryAreaService.getCategoryContryListByCid(cid+""); - if(list.size() ==0){ - out.print( JsonUtil.loadFalseAdmin("鍔犺浇閿欒")); - return; - } - List<CategoryContry> categoryContryList = categoryAreaService.categoryContryList(list.get(0).getId()+""); - PageEntity pe = new PageEntity(); - pe.setPageIndex(1); - pe.setPageSize(categoryContryList.size()); - pe.setTotalCount(categoryContryList.size()); - JSONObject data = new JSONObject(); - Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create(); - data.put("pe", pe); - data.put("list", gson.toJson(categoryContryList)); - String json = JsonUtil.loadTrueAdmin(data); - out.print(json); - } - - @RequestMapping("getArea") - public void getArea(long id,PrintWriter out){ - CategoryContry area = categoryAreaService.getCategoryArea(id+""); - if(area == null){ - out.print(JsonUtil.loadFalseAdmin("")); - return; - } - Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create(); - out.print(JsonUtil.loadTrueAdmin(gson.toJson(area))); - } - - @RequestMapping("updateArea") - public void updateArea(long id,int orderBy,PrintWriter out){ - CategoryContry area = categoryAreaService.getCategoryArea(id+""); - if(area == null){ - out.print(JsonUtil.loadFalseAdmin("")); - return; - } - area.setOrderby(orderBy); - categoryAreaService.updateArea(area); - out.print(JsonUtil.loadTrueAdmin("")); - } - - + categoryRecommendVideo.setOrderby(orderby); + categoryRecommendVideo.setPicture(picture); + categoryRecommendVideo.setVideoInfo(new VideoInfo(videoid)); + categoryRecommendVideo.setVideoType(new VideoType(Long.parseLong(videotype))); + categoryRecommendVideoService.updateCategoryRecommendVideo(categoryRecommendVideo); + out.print("yes"); + return; + } + + + @RequestMapping(value = "/CategoryRecommendVideoAdminServlet", method = RequestMethod.POST) + public void set(String type, String id, String systemid, PrintWriter out) { + + System.out.println("type--" + type); + System.out.println("id--" + id); + System.out.println("systemid--" + systemid); + + if ("add".equalsIgnoreCase(type)) {// 鑾峰彇鏉ユ簮鍒楄〃 + if (!StringUtil.isNullOrEmpty(systemid) && !StringUtil.isNullOrEmpty(id)) { + SuperCategoryRecommendVideo sz = new SuperCategoryRecommendVideo(); + sz.setDetailSystem(new DetailSystem(systemid)); + sz.setCategoryRecommendVideo(new CategoryRecommendVideo(id)); + categoryRecommendVideoService.addSuperCategoryRecommendVideo(sz); + } + out.print("yes"); + } else if ("delete".equalsIgnoreCase(type)) { + if (!StringUtil.isNullOrEmpty(systemid) && !StringUtil.isNullOrEmpty(id)) { + categoryRecommendVideoService.deleteCategoryRecommendVideoAdmin(id, systemid); + } + out.print("yes"); + } + } + + @RequestMapping("getAreaList") + public void getAreaList(long cid, PrintWriter out) { + List<CategoryContry> list = categoryAreaService.getCategoryContryListByCid(cid + ""); + if (list.size() == 0) { + out.print(JsonUtil.loadFalseAdmin("鍔犺浇閿欒")); + return; + } + List<CategoryContry> categoryContryList = categoryAreaService.categoryContryList(list.get(0).getId() + ""); + PageEntity pe = new PageEntity(); + pe.setPageIndex(1); + pe.setPageSize(categoryContryList.size()); + pe.setTotalCount(categoryContryList.size()); + JSONObject data = new JSONObject(); + Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create(); + data.put("pe", pe); + data.put("list", gson.toJson(categoryContryList)); + String json = JsonUtil.loadTrueAdmin(data); + out.print(json); + } + + @RequestMapping("getArea") + public void getArea(long id, PrintWriter out) { + CategoryContry area = categoryAreaService.getCategoryArea(id + ""); + if (area == null) { + out.print(JsonUtil.loadFalseAdmin("")); + return; + } + Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create(); + out.print(JsonUtil.loadTrueAdmin(gson.toJson(area))); + } + + @RequestMapping("updateArea") + public void updateArea(long id, int orderBy, PrintWriter out) { + CategoryContry area = categoryAreaService.getCategoryArea(id + ""); + if (area == null) { + out.print(JsonUtil.loadFalseAdmin("")); + return; + } + area.setOrderby(orderBy); + categoryAreaService.updateArea(area); + out.print(JsonUtil.loadTrueAdmin("")); + } + + } -- Gitblit v1.8.0