Commit b91baa10885833f98ff982af326b5fedf3ed5ce1
1 parent
5cba275e
Exists in
master
excel 下载并获取流 修改
Showing
2 changed files
with
10 additions
and
13 deletions
Show diff stats
src/main/java/com/jevon/controller/LearnController.java
@@ -18,14 +18,12 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook; | @@ -18,14 +18,12 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook; | ||
18 | import org.apache.poi.ss.usermodel.*; | 18 | import org.apache.poi.ss.usermodel.*; |
19 | import org.apache.poi.xssf.usermodel.XSSFWorkbook; | 19 | import org.apache.poi.xssf.usermodel.XSSFWorkbook; |
20 | import org.springframework.beans.factory.annotation.Autowired; | 20 | import org.springframework.beans.factory.annotation.Autowired; |
21 | -import org.springframework.beans.factory.annotation.Value; | ||
22 | import org.springframework.web.bind.annotation.RequestBody; | 21 | import org.springframework.web.bind.annotation.RequestBody; |
23 | import org.springframework.web.bind.annotation.RequestMapping; | 22 | import org.springframework.web.bind.annotation.RequestMapping; |
24 | import org.springframework.web.bind.annotation.RequestMethod; | 23 | import org.springframework.web.bind.annotation.RequestMethod; |
25 | import org.springframework.web.bind.annotation.RestController; | 24 | import org.springframework.web.bind.annotation.RestController; |
26 | 25 | ||
27 | import java.io.File; | 26 | import java.io.File; |
28 | -import java.io.FileInputStream; | ||
29 | import java.io.InputStream; | 27 | import java.io.InputStream; |
30 | import java.util.*; | 28 | import java.util.*; |
31 | 29 | ||
@@ -63,11 +61,6 @@ public class LearnController { | @@ -63,11 +61,6 @@ public class LearnController { | ||
63 | @Autowired | 61 | @Autowired |
64 | ChapterService chapterService; | 62 | ChapterService chapterService; |
65 | 63 | ||
66 | - @Value("${remoting.url}") | ||
67 | - private String url ; | ||
68 | - @Value("${remoting.prefixFile}") | ||
69 | - private String staticUrl ; | ||
70 | - | ||
71 | @ApiOperation("获取列表") | 64 | @ApiOperation("获取列表") |
72 | @RequestMapping(value = "getList", method = RequestMethod.POST) | 65 | @RequestMapping(value = "getList", method = RequestMethod.POST) |
73 | public List<Analyse> getList(){ | 66 | public List<Analyse> getList(){ |
src/main/java/com/jevon/controller/ScheduleInitController.java
@@ -29,6 +29,7 @@ import org.springframework.web.bind.annotation.RestController; | @@ -29,6 +29,7 @@ import org.springframework.web.bind.annotation.RestController; | ||
29 | import javax.servlet.http.HttpServletRequest; | 29 | import javax.servlet.http.HttpServletRequest; |
30 | import java.io.File; | 30 | import java.io.File; |
31 | import java.io.FileInputStream; | 31 | import java.io.FileInputStream; |
32 | +import java.io.InputStream; | ||
32 | import java.util.*; | 33 | import java.util.*; |
33 | 34 | ||
34 | @RestController | 35 | @RestController |
@@ -62,8 +63,6 @@ public class ScheduleInitController { | @@ -62,8 +63,6 @@ public class ScheduleInitController { | ||
62 | 63 | ||
63 | @Value("${remoting.url}") | 64 | @Value("${remoting.url}") |
64 | private String url ; | 65 | private String url ; |
65 | - @Value("${remoting.prefixFile}") | ||
66 | - private String staticUrl ; | ||
67 | 66 | ||
68 | @ApiOperation("创建排课计划 ") | 67 | @ApiOperation("创建排课计划 ") |
69 | @RequestMapping(value = "createSchedule", method = RequestMethod.POST) | 68 | @RequestMapping(value = "createSchedule", method = RequestMethod.POST) |
@@ -207,15 +206,20 @@ public class ScheduleInitController { | @@ -207,15 +206,20 @@ public class ScheduleInitController { | ||
207 | teacherClassService.deleteBySchoolAndTeam(temp); | 206 | teacherClassService.deleteBySchoolAndTeam(temp); |
208 | } | 207 | } |
209 | String fileUrl = initTeacherCourseReqVo.getUrl(); | 208 | String fileUrl = initTeacherCourseReqVo.getUrl(); |
210 | - fileUrl = fileUrl.replace(url, staticUrl); | ||
211 | File excelFile = new File(fileUrl); | 209 | File excelFile = new File(fileUrl); |
212 | // 获得工作簿 | 210 | // 获得工作簿 |
213 | - String file = excelFile.getName(); | ||
214 | Workbook workbook = null; | 211 | Workbook workbook = null; |
212 | + String file = excelFile.getName(); | ||
213 | + InputStream inputStream = HttpClientUtils.GetFileInputStream(initTeacherCourseReqVo.getUrl()); | ||
214 | + if(inputStream == null){ | ||
215 | + baseVo.setMessage("路径不存在"); | ||
216 | + baseVo.setSuccess(false); | ||
217 | + return baseVo; | ||
218 | + } | ||
215 | if (file.endsWith("xls")) { | 219 | if (file.endsWith("xls")) { |
216 | - workbook = new HSSFWorkbook(new FileInputStream(excelFile)); | 220 | + workbook = new HSSFWorkbook(inputStream); |
217 | } else { | 221 | } else { |
218 | - workbook = new XSSFWorkbook(new FileInputStream(excelFile)); | 222 | + workbook = new XSSFWorkbook(inputStream); |
219 | } | 223 | } |
220 | // 获得工作表 | 224 | // 获得工作表 |
221 | Sheet sheet = workbook.getSheetAt(0); | 225 | Sheet sheet = workbook.getSheetAt(0); |