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/VideoTypeAdminController.java |  320 ++++++++++++++++++++++++++--------------------------
 1 files changed, 161 insertions(+), 159 deletions(-)

diff --git a/src/main/java/com/yeshi/buwan/controller/admin/api/VideoTypeAdminController.java b/src/main/java/com/yeshi/buwan/controller/admin/api/VideoTypeAdminController.java
index d239788..601e07a 100644
--- a/src/main/java/com/yeshi/buwan/controller/admin/api/VideoTypeAdminController.java
+++ b/src/main/java/com/yeshi/buwan/controller/admin/api/VideoTypeAdminController.java
@@ -11,7 +11,9 @@
 import javax.annotation.Resource;
 import javax.servlet.ServletContext;
 import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
 
+import com.yeshi.buwan.util.SystemUtil;
 import net.sf.json.JSONObject;
 
 import org.springframework.stereotype.Controller;
@@ -34,165 +36,165 @@
 @Controller
 @RequestMapping("admin/new/api/videoType")
 public class VideoTypeAdminController {
-	
-	@Resource
-	private ClassService classService;
-	
-	@Resource
-	private SystemService systemService;
-	
-	private static final String IMGPATH="/upload/class";
-	
-	@RequestMapping("videoTypeList")
-	public void videoTypeList(int pageIndex,int detailsystem,int pid,PrintWriter out) {
-		if (pageIndex == 0)
-			pageIndex = 1;
 
-		List<com.yeshi.buwan.domain.web.VideoTypeAdmin> list = classService.getVideoTypeAdmin(detailsystem, pid,
-				pageIndex);
+    @Resource
+    private ClassService classService;
 
-		long count = classService.getVideoTypeAdminCount(detailsystem, pid);
-		PageEntity pe = new PageEntity();
-		pe.setPageIndex(pageIndex);
-		pe.setPageSize(Constant.pageCount);
-		Map<String, String> map = new HashMap<String, String>();
-		map.put("pid", pid + "");
-		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("videoTypeAdminList",gson.toJson(list));
-		out.print(json);
-		return ;
-	}
-	
-	@RequestMapping("getAllVideoType")
-	public void getAllVideoType(PrintWriter out){
-		List<VideoType> list = classService.getAllVideoType();
-		Gson gson =new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
-		JSONObject json=new JSONObject();
-		json.put("code", "0");
-		json.put("list", gson.toJson(list));
-		out.print(json);
-	}
-	
-	@RequestMapping("setSuperVideoType")
-	public void set(String type,String id,String icon,String detailSystem,PrintWriter out){
-		
-		if("add".equals(type)){
-			SuperVideoType svt = new SuperVideoType();
-			svt.setCreatetime(System.currentTimeMillis() + "");
-			svt.setDetailSystem(new DetailSystem(detailSystem));
-			svt.setPicture(icon.trim());
-			svt.setType(new VideoType(Long.parseLong(id)));
-			classService.addSuperVideoType(svt);
-			out.print("yes");
-		}else if("delete".equals(type)){
-			classService.deleteVideoTypeAdmin(id, detailSystem);
-			out.print("yes");
-		}
-	}
-	
-	@RequestMapping("getVideoType")
-	public void getVideoType(String id,PrintWriter out) {
-		VideoType vt = classService.getType(Long.parseLong(id));
-		JSONObject json = new JSONObject();
-		json.put("code", "0");
-		json.put("videoType", vt);
-		out.print(json);
-		return ;
-	}
-	
-	@RequestMapping("updateVideoType")
-	public void updateVideoType(String id,String orderby,String name,String beizhu,String iconFile,String iconUrl,String show,String showTitle,PrintWriter out) {
-		
-		VideoType vt = classService.getType(Long.parseLong(id));
-		vt.setOrderby(Integer.parseInt(orderby));
-		if (iconFile != null && !"".equals(iconFile.trim())) {// 淇濆瓨鍥剧墖
-				vt.setIcon(iconFile);
-		} else {
-			if (!StringUtil.isNullOrEmpty(iconUrl))
-				vt.setIcon(iconUrl);
-		}
-		vt.setName(name);
-		vt.setBeizhu(beizhu);
-		vt.setShow(show);
-		vt.setShowTitle(showTitle);
-		classService.updateType(vt);
-		out.print("yes");
-		return ;
-	}
-	
-	@RequestMapping("addVideoType")
-	public void addVideoType(String pid,String orderby,String name,String beizhu,String iconFile,String iconUrl,String show,String showTitle,PrintWriter out) {
-		
-		VideoType vt = new VideoType();
-		if (iconFile != null && !"".equals(iconFile.trim())) {// 淇濆瓨鍥剧墖
-			vt.setIcon(iconFile);
-	} else {
-		if (!StringUtil.isNullOrEmpty(iconUrl))
-			vt.setIcon(iconUrl);
-	}
-		vt.setName(name);
-		vt.setBeizhu(beizhu);
-		vt.setOrderby(Integer.parseInt(orderby));
-		vt.setShow(show);
-		vt.setCreatetime(String.valueOf(new Date().getTime()));
-		vt.setShowTitle(showTitle);
-		if (!StringUtil.isNullOrEmpty(pid) && !pid.equalsIgnoreCase("0")) {
-			vt.setParent(new VideoType(Long.parseLong(pid)));
-		}
-		System.out.println("vt.getIcon()--"+vt.getIcon());
-		classService.createType(vt);
-		out.print("yes");
-		return ;
-	}
-	
-	@RequestMapping(value="updateVideoTypeFile",method=RequestMethod.POST)
-	public void updateVideoTypeFile(@RequestParam("file") CommonsMultipartFile file,HttpServletRequest request,PrintWriter out){
-		ServletContext servletContext = request.getSession().getServletContext();
-		JSONObject json=new JSONObject();
-		if(file != null){
-			String root=servletContext.getRealPath(IMGPATH);
-			if (!new File(root).exists()){
-				new File(root).mkdirs();
-			}
-			 File newFile=new File(root+"/"+file.getOriginalFilename());
-			//閫氳繃CommonsMultipartFile鐨勬柟娉曠洿鎺ュ啓鏂囦欢锛堟敞鎰忚繖涓椂鍊欙級
-		     try {
-				file.transferTo(newFile);
-			     json.put("code", "0");
-			     json.put("path", IMGPATH+"/"+newFile.getName());
-			} catch (IllegalStateException e) {
-				e.printStackTrace();
-				json.put("code", "2");
-			} catch (IOException e) {
-				e.printStackTrace();
-				json.put("code", "2");
-			}finally{
-				out.print(json);
-			}
-		}else{
-			 json.put("code", "1");
-			 out.print(json);
-		}
-	}
-	
-	@RequestMapping("deleteVideoType")
-	public void deleteVideoType(String ids,PrintWriter out) {
-		String[] idArr = ids.split(",");
-		for (String id : idArr) {
-			System.out.println("id=="+id);
-			if("310".equals(id)){ //310鍋氱壒娈婂鐞嗕笉鍒犻櫎 20170915
-				continue;
-			}
-			classService.deleteVideoType(id);
-		}
-		out.print("yes");
-		return;
-	}
-	
+    @Resource
+    private SystemService systemService;
+
+    private static final String IMGPATH = "/upload/class";
+
+    @RequestMapping("videoTypeList")
+    public void videoTypeList(int pageIndex, int detailsystem, int pid, HttpSession session, PrintWriter out) {
+        if (pageIndex == 0)
+            pageIndex = 1;
+
+        List<com.yeshi.buwan.domain.web.VideoTypeAdmin> list = classService.getVideoTypeAdmin(SystemUtil.getAdminSelectedSystemId(session), detailsystem, pid,
+                pageIndex);
+
+        long count = classService.getVideoTypeAdminCount(detailsystem, pid);
+        PageEntity pe = new PageEntity();
+        pe.setPageIndex(pageIndex);
+        pe.setPageSize(Constant.pageCount);
+        Map<String, String> map = new HashMap<String, String>();
+        map.put("pid", pid + "");
+        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("videoTypeAdminList", gson.toJson(list));
+        out.print(json);
+        return;
+    }
+
+    @RequestMapping("getAllVideoType")
+    public void getAllVideoType(PrintWriter out) {
+        List<VideoType> list = classService.getAllVideoType();
+        Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
+        JSONObject json = new JSONObject();
+        json.put("code", "0");
+        json.put("list", gson.toJson(list));
+        out.print(json);
+    }
+
+    @RequestMapping("setSuperVideoType")
+    public void set(String type, String id, String icon, String detailSystem, PrintWriter out) {
+
+        if ("add".equals(type)) {
+            SuperVideoType svt = new SuperVideoType();
+            svt.setCreatetime(System.currentTimeMillis() + "");
+            svt.setDetailSystem(new DetailSystem(detailSystem));
+            svt.setPicture(icon.trim());
+            svt.setType(new VideoType(Long.parseLong(id)));
+            classService.addSuperVideoType(svt);
+            out.print("yes");
+        } else if ("delete".equals(type)) {
+            classService.deleteVideoTypeAdmin(id, detailSystem);
+            out.print("yes");
+        }
+    }
+
+    @RequestMapping("getVideoType")
+    public void getVideoType(String id, PrintWriter out) {
+        VideoType vt = classService.getType(Long.parseLong(id));
+        JSONObject json = new JSONObject();
+        json.put("code", "0");
+        json.put("videoType", vt);
+        out.print(json);
+        return;
+    }
+
+    @RequestMapping("updateVideoType")
+    public void updateVideoType(String id, String orderby, String name, String beizhu, String iconFile, String iconUrl, String show, String showTitle, PrintWriter out) {
+
+        VideoType vt = classService.getType(Long.parseLong(id));
+        vt.setOrderby(Integer.parseInt(orderby));
+        if (iconFile != null && !"".equals(iconFile.trim())) {// 淇濆瓨鍥剧墖
+            vt.setIcon(iconFile);
+        } else {
+            if (!StringUtil.isNullOrEmpty(iconUrl))
+                vt.setIcon(iconUrl);
+        }
+        vt.setName(name);
+        vt.setBeizhu(beizhu);
+        vt.setShow(show);
+        vt.setShowTitle(showTitle);
+        classService.updateType(vt);
+        out.print("yes");
+        return;
+    }
+
+    @RequestMapping("addVideoType")
+    public void addVideoType(String pid, String orderby, String name, String beizhu, String iconFile, String iconUrl, String show, String showTitle, PrintWriter out) {
+
+        VideoType vt = new VideoType();
+        if (iconFile != null && !"".equals(iconFile.trim())) {// 淇濆瓨鍥剧墖
+            vt.setIcon(iconFile);
+        } else {
+            if (!StringUtil.isNullOrEmpty(iconUrl))
+                vt.setIcon(iconUrl);
+        }
+        vt.setName(name);
+        vt.setBeizhu(beizhu);
+        vt.setOrderby(Integer.parseInt(orderby));
+        vt.setShow(show);
+        vt.setCreatetime(String.valueOf(new Date().getTime()));
+        vt.setShowTitle(showTitle);
+        if (!StringUtil.isNullOrEmpty(pid) && !pid.equalsIgnoreCase("0")) {
+            vt.setParent(new VideoType(Long.parseLong(pid)));
+        }
+        System.out.println("vt.getIcon()--" + vt.getIcon());
+        classService.createType(vt);
+        out.print("yes");
+        return;
+    }
+
+    @RequestMapping(value = "updateVideoTypeFile", method = RequestMethod.POST)
+    public void updateVideoTypeFile(@RequestParam("file") CommonsMultipartFile file, HttpServletRequest request, PrintWriter out) {
+        ServletContext servletContext = request.getSession().getServletContext();
+        JSONObject json = new JSONObject();
+        if (file != null) {
+            String root = servletContext.getRealPath(IMGPATH);
+            if (!new File(root).exists()) {
+                new File(root).mkdirs();
+            }
+            File newFile = new File(root + "/" + file.getOriginalFilename());
+            //閫氳繃CommonsMultipartFile鐨勬柟娉曠洿鎺ュ啓鏂囦欢锛堟敞鎰忚繖涓椂鍊欙級
+            try {
+                file.transferTo(newFile);
+                json.put("code", "0");
+                json.put("path", IMGPATH + "/" + newFile.getName());
+            } catch (IllegalStateException e) {
+                e.printStackTrace();
+                json.put("code", "2");
+            } catch (IOException e) {
+                e.printStackTrace();
+                json.put("code", "2");
+            } finally {
+                out.print(json);
+            }
+        } else {
+            json.put("code", "1");
+            out.print(json);
+        }
+    }
+
+    @RequestMapping("deleteVideoType")
+    public void deleteVideoType(String ids, PrintWriter out) {
+        String[] idArr = ids.split(",");
+        for (String id : idArr) {
+            System.out.println("id==" + id);
+            if ("310".equals(id)) { //310鍋氱壒娈婂鐞嗕笉鍒犻櫎 20170915
+                continue;
+            }
+            classService.deleteVideoType(id);
+        }
+        out.print("yes");
+        return;
+    }
+
 }

--
Gitblit v1.8.0