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 | 18 | import org.apache.poi.ss.usermodel.*; | 
| 19 | 19 | import org.apache.poi.xssf.usermodel.XSSFWorkbook; | 
| 20 | 20 | import org.springframework.beans.factory.annotation.Autowired; | 
| 21 | -import org.springframework.beans.factory.annotation.Value; | |
| 22 | 21 | import org.springframework.web.bind.annotation.RequestBody; | 
| 23 | 22 | import org.springframework.web.bind.annotation.RequestMapping; | 
| 24 | 23 | import org.springframework.web.bind.annotation.RequestMethod; | 
| 25 | 24 | import org.springframework.web.bind.annotation.RestController; | 
| 26 | 25 | |
| 27 | 26 | import java.io.File; | 
| 28 | -import java.io.FileInputStream; | |
| 29 | 27 | import java.io.InputStream; | 
| 30 | 28 | import java.util.*; | 
| 31 | 29 | |
| ... | ... | @@ -63,11 +61,6 @@ public class LearnController { | 
| 63 | 61 | @Autowired | 
| 64 | 62 | ChapterService chapterService; | 
| 65 | 63 | |
| 66 | - @Value("${remoting.url}") | |
| 67 | - private String url ; | |
| 68 | - @Value("${remoting.prefixFile}") | |
| 69 | - private String staticUrl ; | |
| 70 | - | |
| 71 | 64 | @ApiOperation("获取列表") | 
| 72 | 65 | @RequestMapping(value = "getList", method = RequestMethod.POST) | 
| 73 | 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 | 29 | import javax.servlet.http.HttpServletRequest; | 
| 30 | 30 | import java.io.File; | 
| 31 | 31 | import java.io.FileInputStream; | 
| 32 | +import java.io.InputStream; | |
| 32 | 33 | import java.util.*; | 
| 33 | 34 | |
| 34 | 35 | @RestController | 
| ... | ... | @@ -62,8 +63,6 @@ public class ScheduleInitController { | 
| 62 | 63 | |
| 63 | 64 | @Value("${remoting.url}") | 
| 64 | 65 | private String url ; | 
| 65 | - @Value("${remoting.prefixFile}") | |
| 66 | - private String staticUrl ; | |
| 67 | 66 | |
| 68 | 67 | @ApiOperation("创建排课计划 ") | 
| 69 | 68 | @RequestMapping(value = "createSchedule", method = RequestMethod.POST) | 
| ... | ... | @@ -207,15 +206,20 @@ public class ScheduleInitController { | 
| 207 | 206 | teacherClassService.deleteBySchoolAndTeam(temp); | 
| 208 | 207 | } | 
| 209 | 208 | String fileUrl = initTeacherCourseReqVo.getUrl(); | 
| 210 | - fileUrl = fileUrl.replace(url, staticUrl); | |
| 211 | 209 | File excelFile = new File(fileUrl); | 
| 212 | 210 | // 获得工作簿 | 
| 213 | - String file = excelFile.getName(); | |
| 214 | 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 | 219 | if (file.endsWith("xls")) { | 
| 216 | - workbook = new HSSFWorkbook(new FileInputStream(excelFile)); | |
| 220 | + workbook = new HSSFWorkbook(inputStream); | |
| 217 | 221 | } else { | 
| 218 | - workbook = new XSSFWorkbook(new FileInputStream(excelFile)); | |
| 222 | + workbook = new XSSFWorkbook(inputStream); | |
| 219 | 223 | } | 
| 220 | 224 | // 获得工作表 | 
| 221 | 225 | Sheet sheet = workbook.getSheetAt(0); | ... | ... |