|
@@ -10,6 +10,7 @@ import com.caimei.model.po.ProductParamPo;
|
|
|
import com.caimei.model.po.UploadFilePo;
|
|
|
import com.caimei.model.vo.AuthFormVo;
|
|
|
import com.caimei.model.vo.AuthVo;
|
|
|
+import com.caimei.model.vo.ClubUserVo;
|
|
|
import com.caimei.model.vo.ProductFormVo;
|
|
|
import com.caimei.service.auth.DownloadService;
|
|
|
import com.caimei.service.auth.UploadService;
|
|
@@ -484,4 +485,123 @@ public class DownloadServiceImpl implements DownloadService {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 下载用户信息
|
|
|
+ * @param clubUserIds
|
|
|
+ * @param response
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResponseJson downloadClubuserlistInfo(String clubUserIds, HttpServletResponse response) {
|
|
|
+ //导出的用户表名
|
|
|
+ String fileName=new String("用户信息.xlsx".getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1);
|
|
|
+ //获取用户信息
|
|
|
+ List<ClubUserVo> clubUserVosList = authMapper.getclubuserInfo(clubUserIds);
|
|
|
+ try {
|
|
|
+ OutputStream outputStream = response.getOutputStream();
|
|
|
+ response.reset();
|
|
|
+ response.setHeader("Access-Control-Allow-Origin", "*");
|
|
|
+ response.setHeader("Access-Control-Allow-Credentials", "true");
|
|
|
+ response.setHeader("Content-disposition",
|
|
|
+ "attachment; filename="+fileName);
|
|
|
+// response.setContentType("application/vnd.ms-excel"); -- xls
|
|
|
+ response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
+ return generateClubUserExcel(clubUserVosList,outputStream);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return ResponseJson.error("导出失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private ResponseJson generateClubUserExcel(List<ClubUserVo> clubUserVosList, OutputStream outputStream) {
|
|
|
+ try {
|
|
|
+ XSSFWorkbook workbook = new XSSFWorkbook();
|
|
|
+ // 创建机构工作表
|
|
|
+ XSSFSheet authPartySheet = workbook.createSheet("用户信息");
|
|
|
+ // sheet样式定义
|
|
|
+ XSSFCellStyle topCellStyle = PoiUtils.getXSSFTopCellStyle(workbook);
|
|
|
+ XSSFCellStyle customCellStyle = PoiUtils.getXSSFCustomCellStyle(workbook);
|
|
|
+ // 创建列头行
|
|
|
+ XSSFRow authTopRow = authPartySheet.createRow(0);
|
|
|
+ // 添加列头单元格
|
|
|
+ String[] rowName = {"序号", "机构名称", "手机号", "注册时间",
|
|
|
+ "认证状态", "用户状态"};
|
|
|
+ for (int i = 0; i < rowName.length; i++) {
|
|
|
+ XSSFCell authTopRowCell = authTopRow.createCell(i);
|
|
|
+ authTopRowCell.setCellType(CellType.valueOf("STRING"));
|
|
|
+ XSSFRichTextString columnText = new XSSFRichTextString(rowName[i]);
|
|
|
+ authTopRowCell.setCellValue(columnText);
|
|
|
+ authTopRowCell.setCellStyle(topCellStyle);
|
|
|
+ }
|
|
|
+ // 行索引
|
|
|
+ AtomicInteger authPartyRowNum = new AtomicInteger(1);
|
|
|
+ int serialNum=1;
|
|
|
+// clubUserVosList.forEach(club -> {
|
|
|
+ for (ClubUserVo club:clubUserVosList) {
|
|
|
+ // 创建机构行
|
|
|
+ XSSFRow authRow = authPartySheet.createRow(authPartyRowNum.get());
|
|
|
+ // 组装机构数据
|
|
|
+ List<String> authData = new ArrayList<>();
|
|
|
+ authData.add(serialNum + "");
|
|
|
+ authData.add(club.getName());
|
|
|
+ authData.add(club.getMobile());
|
|
|
+ SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm");
|
|
|
+ Date authDate = club.getAddTime();
|
|
|
+ if (null != authDate) {
|
|
|
+ authData.add(format.format(authDate));
|
|
|
+ } else {
|
|
|
+ authData.add("");
|
|
|
+ }
|
|
|
+ authData.add(club.getAuthenticationStatus());
|
|
|
+ authData.add(club.getStatus() + "");
|
|
|
+ for (int j = 0; j < authData.size(); j++) {
|
|
|
+ XSSFCell authCell = authRow.createCell(j);
|
|
|
+ authCell.setCellStyle(customCellStyle);
|
|
|
+// if (j == 7) {
|
|
|
+// authCell.setCellType(CellType.NUMERIC);
|
|
|
+// authCell.setCellValue(Integer.parseInt(authData.get(j)));
|
|
|
+// } else {
|
|
|
+ authCell.setCellType(CellType.valueOf("STRING"));
|
|
|
+ XSSFRichTextString authCellValue = new XSSFRichTextString(authData.get(j));
|
|
|
+ authCell.setCellValue(authCellValue);
|
|
|
+// }
|
|
|
+ }
|
|
|
+ authPartyRowNum.getAndIncrement();
|
|
|
+ serialNum++;
|
|
|
+ }
|
|
|
+// });
|
|
|
+ // 让列宽随着导出的列长自动适应
|
|
|
+ for (int colNum = 0; colNum < rowName.length; colNum++) {
|
|
|
+ int productColumnWidth = authPartySheet.getColumnWidth(colNum) / 256;
|
|
|
+ for (int rowNum = 0; rowNum < authPartySheet.getLastRowNum(); rowNum++) {
|
|
|
+ XSSFRow currentRow;
|
|
|
+ // 当前行未被使用过
|
|
|
+ if (authPartySheet.getRow(rowNum) == null) {
|
|
|
+ currentRow = authPartySheet.createRow(rowNum);
|
|
|
+ } else {
|
|
|
+ currentRow = authPartySheet.getRow(rowNum);
|
|
|
+ }
|
|
|
+ if (currentRow.getCell(colNum) != null) {
|
|
|
+ XSSFCell currentCell = currentRow.getCell(colNum);
|
|
|
+ if (currentCell.getCellTypeEnum().equals(CellType.valueOf("STRING"))) {
|
|
|
+ int length = currentCell.getStringCellValue()
|
|
|
+ .getBytes().length;
|
|
|
+ if (productColumnWidth < length) {
|
|
|
+ productColumnWidth = length;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ authPartySheet.setColumnWidth(colNum, (productColumnWidth + 4) * 256);
|
|
|
+ }
|
|
|
+ outputStream.flush();
|
|
|
+ workbook.write(outputStream);
|
|
|
+ outputStream.close();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return ResponseJson.error("导出失败");
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
}
|