|
@@ -28,6 +28,11 @@ import org.apache.poi.hssf.usermodel.HSSFRow;
|
|
|
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
|
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
|
|
+import org.apache.poi.ss.usermodel.Cell;
|
|
|
+import org.apache.poi.ss.usermodel.Row;
|
|
|
+import org.apache.poi.ss.usermodel.Sheet;
|
|
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -756,29 +761,34 @@ public class SettingController {
|
|
|
return ResponseHelp.success(rankList);
|
|
|
}
|
|
|
|
|
|
- @RequestMapping(value = "/rank/import", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE, method = RequestMethod.POST)
|
|
|
+ @RequestMapping(value = "/rank/import", method = RequestMethod.POST)
|
|
|
@ApiOperation(value = "导入排行数据", httpMethod = "POST")
|
|
|
- private Response<Boolean> importRank(@RequestParam("file") MultipartFile multipartFile) throws IOException {
|
|
|
+ private Response<Integer> importRank(@RequestParam("file") MultipartFile multipartFile) throws IOException {
|
|
|
// 删除所有排行数据, 并导入excel数据
|
|
|
// 读取文件
|
|
|
- InputStream is = new FileInputStream("002.xls");
|
|
|
+// InputStream is = new FileInputStream();
|
|
|
// 将文件流解析成 POI 文档
|
|
|
- POIFSFileSystem fs = new POIFSFileSystem(is);
|
|
|
- // 再将 POI 文档解析成 Excel 工作簿
|
|
|
- HSSFWorkbook wb = new HSSFWorkbook(fs);
|
|
|
- HSSFRow row = null;
|
|
|
- HSSFCell cell = null;
|
|
|
+ Workbook wb =null;
|
|
|
+ Row row = null;
|
|
|
+ Cell cell = null;
|
|
|
+
|
|
|
+ if (multipartFile.getOriginalFilename().contains(".xlsx")){
|
|
|
+ // 再将 POI 文档解析成 Excel 工作簿
|
|
|
+ wb = new XSSFWorkbook(multipartFile.getInputStream());
|
|
|
+ }else{
|
|
|
+ // 再将 POI 文档解析成 Excel 工作簿
|
|
|
+ wb = new HSSFWorkbook(multipartFile.getInputStream());
|
|
|
+ }
|
|
|
// 得到第 1 个工作簿
|
|
|
- HSSFSheet sheet = wb.getSheetAt(0);
|
|
|
- // 得到这一行一共有多少列
|
|
|
- int totalColumns = sheet.getRow(0).getPhysicalNumberOfCells();
|
|
|
+ Sheet sheet = wb.getSheetAt(0);
|
|
|
+ int totalColumns = 8; // total_score, total_rank, quant_score, quant_rank, verbal_score, verbal_rank
|
|
|
// 得到最后一行的坐标
|
|
|
Integer lastRowNum = sheet.getLastRowNum();
|
|
|
System.out.println("lastRowNum => " + lastRowNum);
|
|
|
|
|
|
+
|
|
|
List<Rank> rankList = new ArrayList<>();
|
|
|
Rank rank = null;
|
|
|
- String cellValue = null;
|
|
|
|
|
|
// 从第 2 行开始读
|
|
|
for(int i=1;i<=lastRowNum;i++){
|
|
@@ -787,14 +797,39 @@ public class SettingController {
|
|
|
for(int j=0;j<totalColumns;j++){
|
|
|
cell = row.getCell(j);
|
|
|
if(cell!=null){
|
|
|
- cellValue = cell.getStringCellValue();
|
|
|
- }else {
|
|
|
- cellValue = "【没有数据】";
|
|
|
+ switch(j){
|
|
|
+ case 0:
|
|
|
+ rank.setTotalScore((int) cell.getNumericCellValue());
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ rank.setTotalRank((int) cell.getNumericCellValue());
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ rank.setQuantScore((int) cell.getNumericCellValue());
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ rank.setQuantRank((int) cell.getNumericCellValue());
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ rank.setVerbalScore((int) cell.getNumericCellValue());
|
|
|
+ break;
|
|
|
+ case 5:
|
|
|
+ rank.setVerbalRank((int) cell.getNumericCellValue());
|
|
|
+ break;
|
|
|
+ case 6:
|
|
|
+ rank.setIrScore((int) cell.getNumericCellValue());
|
|
|
+ break;
|
|
|
+ case 7:
|
|
|
+ rank.setIrRank((int) cell.getNumericCellValue());
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ throw new ParameterException(String.format("%d行%d列数据为空", i, j));
|
|
|
}
|
|
|
}
|
|
|
rankList.add(rank);
|
|
|
}
|
|
|
rankService.replaceAll(rankList);
|
|
|
- return ResponseHelp.success(true);
|
|
|
+ return ResponseHelp.success(rankList.size());
|
|
|
}
|
|
|
}
|