ImportController.java
1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.bckefu.controller;
import com.bckefu.entity.ContactsEntity;
import com.bckefu.excel.ExcelImportUtil;
import com.bckefu.excel.entity.ImportParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
/**
* @author : caoliang
* @date : 2017/11/14 下午4:09
*/
@RestController
@RequestMapping("import")
public class ImportController {
Logger logger = LoggerFactory.getLogger(ImportController.class);
@ApiOperation(value = "导入测试", tags = "1.0.0")
@PostMapping("")
public ResponseEntity importExcel(@RequestParam("file") MultipartFile multipartFile) throws Exception {
if (multipartFile == null || multipartFile.isEmpty()) {
return new ResponseEntity("FILE ", HttpStatus.BAD_REQUEST);
}
ImportParams params = new ImportParams();
long start = System.currentTimeMillis();
List<ContactsEntity> list = ExcelImportUtil.importExcel(multipartFile.getInputStream(), ContactsEntity.class, params);
logger.info("导入耗时 : {} 毫秒", System.currentTimeMillis() - start);
logger.info("导入行数 : {}", list.size());
return new ResponseEntity(list, HttpStatus.OK);
}
}