Эх сурвалжийг харах

Controller 参数中增加 HttpServletRequest

sunyj 8 жил өмнө
parent
commit
81c0190763

+ 15 - 9
src/main/java/com/uas/report/controller/FileController.java

@@ -5,6 +5,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
 import org.springframework.beans.factory.annotation.Autowired;
@@ -33,14 +34,15 @@ public class FileController {
 
 	@RequestMapping("/autoDeploy")
 	@ResponseBody
-	public String autoDeploy(String sourceUserName, String destinationUserNames) throws IOException {
+	public String autoDeploy(String sourceUserName, String destinationUserNames, HttpServletRequest request)
+			throws IOException {
 		return fileService.autoDeploy(sourceUserName, destinationUserNames);
 	}
 
 	@RequestMapping("/upload")
 	@ResponseBody
 	public String upload(String userName, String fileType, String filePath, Boolean isAbsolutePath,
-			@RequestParam("file") MultipartFile[] files) throws IOException {
+			@RequestParam("file") MultipartFile[] files, HttpServletRequest request) throws IOException {
 		userName = userName == null ? null : userName.toUpperCase();
 		// 未指定上传文件路径,则按照账套名称上传
 		// 该情况下,不会上传多个文件的
@@ -62,7 +64,8 @@ public class FileController {
 	 * @throws IOException
 	 */
 	@RequestMapping("/download")
-	public void download(String filePath, Boolean isAbsolutePath, HttpServletResponse response) throws IOException {
+	public void download(String filePath, Boolean isAbsolutePath, HttpServletRequest request,
+			HttpServletResponse response) throws IOException {
 		fileService.download(filePath, isAbsolutePath, response);
 	}
 
@@ -75,7 +78,8 @@ public class FileController {
 	 * @throws IOException
 	 */
 	@RequestMapping("/download/zip")
-	public void downloadZip(String userName, HttpServletResponse response) throws IOException {
+	public void downloadZip(String userName, HttpServletRequest request, HttpServletResponse response)
+			throws IOException {
 		userName = userName == null ? null : userName.toUpperCase();
 		fileService.downloadZip(userName, response);
 	}
@@ -91,7 +95,8 @@ public class FileController {
 	 * @throws IOException
 	 */
 	@RequestMapping("/download/jrxml")
-	public void downloadJrxml(String userName, String reportName, HttpServletResponse response) throws IOException {
+	public void downloadJrxml(String userName, String reportName, HttpServletRequest request,
+			HttpServletResponse response) throws IOException {
 		userName = userName == null ? null : userName.toUpperCase();
 		fileService.download(fileService.getJrxmlFilePath(userName, reportName), true, response);
 	}
@@ -105,8 +110,8 @@ public class FileController {
 	 */
 	@RequestMapping("/standardJrxmls")
 	@ResponseBody
-	public Map<String, Object> standardJrxmls(String userName, String onlyData, HttpServletResponse response)
-			throws IOException {
+	public Map<String, Object> standardJrxmls(String userName, String onlyData, HttpServletRequest request,
+			HttpServletResponse response) throws IOException {
 		userName = userName == null ? null : userName.toUpperCase();
 		// onlyData为真,只返回字节数据(自动部署时只获取标准模板字节数据),否则下载标准模板zip
 		if (!StringUtils.isEmpty(onlyData) && (onlyData.equals("1") || onlyData.equals("true"))) {
@@ -123,13 +128,14 @@ public class FileController {
 
 	@RequestMapping("/delete")
 	@ResponseBody
-	public String delete(String filePath, Boolean isAbsolutePath) throws IOException {
+	public String delete(String filePath, Boolean isAbsolutePath, HttpServletRequest request) throws IOException {
 		return "Deleted... " + fileService.delete(filePath, isAbsolutePath);
 	}
 
 	@RequestMapping("/listFiles")
 	@ResponseBody
-	public List<Map<String, Object>> listFiles(String filePath, Boolean isAbsolutePath) throws IOException {
+	public List<Map<String, Object>> listFiles(String filePath, Boolean isAbsolutePath, HttpServletRequest request)
+			throws IOException {
 		return fileService.listFiles(filePath, isAbsolutePath);
 	}
 }

+ 5 - 3
src/main/java/com/uas/report/controller/ResourceController.java

@@ -4,6 +4,8 @@ import java.io.IOException;
 import java.net.URISyntaxException;
 import java.util.List;
 
+import javax.servlet.http.HttpServletRequest;
+
 import org.apache.http.client.ClientProtocolException;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
@@ -21,7 +23,7 @@ public class ResourceController {
 
 	@RequestMapping("/sync")
 	@ResponseBody
-	public List<Resource> syncResources(String userName)
+	public List<Resource> syncResources(String userName, HttpServletRequest request)
 			throws ClientProtocolException, URISyntaxException, IOException {
 		userName = userName == null ? null : userName.toUpperCase();
 		return resourceService.syncResources(userName);
@@ -29,14 +31,14 @@ public class ResourceController {
 
 	@RequestMapping("")
 	@ResponseBody
-	public List<Resource> getResources(String folderPath)
+	public List<Resource> getResources(String folderPath, HttpServletRequest request)
 			throws ClientProtocolException, URISyntaxException, IOException {
 		return resourceService.getRemoteResources(folderPath);
 	}
 
 	@RequestMapping("/download")
 	@ResponseBody
-	public String downloadFile(String filePath, String mimeType, String exportPath)
+	public String downloadFile(String filePath, String mimeType, String exportPath, HttpServletRequest request)
 			throws ClientProtocolException, URISyntaxException, IOException {
 		resourceService.downloadFile(filePath, mimeType, exportPath);
 		return "已下载文件至" + exportPath;

+ 9 - 7
src/main/java/com/uas/report/controller/ScheduleController.java

@@ -2,6 +2,8 @@ package com.uas.report.controller;
 
 import java.util.List;
 
+import javax.servlet.http.HttpServletRequest;
+
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -24,33 +26,33 @@ public class ScheduleController {
 
 	@RequestMapping("/deleteGeneratedFiles")
 	@ResponseBody
-	public String deleteGeneratedFiles(@RequestParam(required = true) Integer taskPeriod) {
+	public String deleteGeneratedFiles(@RequestParam(required = true) Integer taskPeriod, HttpServletRequest request) {
 		String message = "已开启:" + fileService.newDeleteGeneratedFilesTask(taskPeriod);
-		restart();
+		restart(request);
 		return message;
 	}
 
 	@RequestMapping("/tasks")
 	@ResponseBody
-	public List<TaskInformation> allTaskInformations() {
+	public List<TaskInformation> allTaskInformations(HttpServletRequest request) {
 		return taskService.allTaskInformations();
 	}
 
 	@RequestMapping("/start")
 	@ResponseBody
-	public String start() {
+	public String start(HttpServletRequest request) {
 		return taskService.start();
 	}
 
 	@RequestMapping("/stop")
 	@ResponseBody
-	public String stop() {
+	public String stop(HttpServletRequest request) {
 		return taskService.stop();
 	}
 
 	@RequestMapping("/restart")
 	@ResponseBody
-	public String restart() {
+	public String restart(HttpServletRequest request) {
 		if (!taskService.isStopped()) {
 			taskService.stop();
 		}
@@ -59,7 +61,7 @@ public class ScheduleController {
 
 	@RequestMapping("/isStopped")
 	@ResponseBody
-	public boolean isStopped() {
+	public boolean isStopped(HttpServletRequest request) {
 		return taskService.isStopped();
 	}
 }