|
@@ -0,0 +1,90 @@
|
|
|
+package com.jpsoft.smart.modules.base.controller;
|
|
|
+
|
|
|
+import com.github.pagehelper.Page;
|
|
|
+import com.jpsoft.smart.config.OSSConfig;
|
|
|
+import com.jpsoft.smart.modules.base.entity.PersonInfo;
|
|
|
+import com.jpsoft.smart.modules.base.service.PersonInfoService;
|
|
|
+import com.jpsoft.smart.modules.common.dto.MessageResult;
|
|
|
+import com.jpsoft.smart.modules.common.dto.Sort;
|
|
|
+import com.jpsoft.smart.modules.common.utils.CheckIdCard;
|
|
|
+import com.jpsoft.smart.modules.common.utils.OSSUtil;
|
|
|
+import com.jpsoft.smart.modules.common.utils.POIUtils;
|
|
|
+import com.jpsoft.smart.modules.common.utils.PojoUtils;
|
|
|
+import com.jpsoft.smart.modules.sys.entity.User;
|
|
|
+import com.jpsoft.smart.modules.sys.service.UserService;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiImplicitParam;
|
|
|
+import io.swagger.annotations.ApiImplicitParams;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFCell;
|
|
|
+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.ss.usermodel.Cell;
|
|
|
+import org.apache.poi.ss.usermodel.Sheet;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.ByteArrayInputStream;
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+@RestController
|
|
|
+@RequestMapping("/base/personInfo")
|
|
|
+@Api(description = "personInfo")
|
|
|
+public class PersonInfoExportController {
|
|
|
+ private Logger logger = LoggerFactory.getLogger(getClass());
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OSSConfig ossConfig;
|
|
|
+ @Autowired
|
|
|
+ private PersonInfoService personInfoService;
|
|
|
+ @Autowired
|
|
|
+ private UserService userService;
|
|
|
+
|
|
|
+ @ApiOperation(value="导出人员")
|
|
|
+ @PostMapping("exportXls")
|
|
|
+ public MessageResult<String> exportXls(HttpServletRequest request, HttpServletResponse response){
|
|
|
+ MessageResult<String> msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ //创建hssfWorkbook
|
|
|
+ HSSFWorkbook workbook = new HSSFWorkbook();
|
|
|
+
|
|
|
+ //创建工作簿
|
|
|
+ HSSFSheet sheet = workbook.createSheet();
|
|
|
+
|
|
|
+ //创建标题
|
|
|
+ HSSFRow row = sheet.createRow(0);
|
|
|
+ HSSFCell cell = row.createCell(0);
|
|
|
+ cell.setCellValue("商品信息汇总");
|
|
|
+
|
|
|
+
|
|
|
+ //将exal输出到哪个文件夹中
|
|
|
+ //FileOutputStream fileOutputStream = new FileOutputStream(new File("C:\\Users\\D.K\\Desktop\\test.xls"));
|
|
|
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
|
+ workbook.write(out);
|
|
|
+ workbook.close();
|
|
|
+
|
|
|
+ String fileName = new String("导出数据".getBytes("UTF-8"), "iso-8859-1");
|
|
|
+ response.setContentType("application/x-msdownload");
|
|
|
+ response.setHeader("Content-Disposition", "attachment;fileName=" + fileName + ".xls");
|
|
|
+ response.getOutputStream().write(out.toByteArray());
|
|
|
+ response.getOutputStream().flush();
|
|
|
+ }
|
|
|
+ catch(Exception ex){
|
|
|
+ logger.error(ex.getMessage(),ex);
|
|
|
+
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage(ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+}
|