|
@@ -1,5 +1,6 @@
|
|
|
package cn.cslg.permission.service;
|
|
|
|
|
|
+import cn.cslg.permission.common.model.dto.QueryLoginRecordDTO;
|
|
|
import cn.cslg.permission.common.model.vo.*;
|
|
|
import cn.cslg.permission.common.utils.CacheUtils;
|
|
|
import cn.cslg.permission.common.utils.FileUtils;
|
|
@@ -23,6 +24,7 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
import java.io.FileNotFoundException;
|
|
|
import java.io.FileOutputStream;
|
|
|
import java.io.IOException;
|
|
@@ -56,15 +58,11 @@ public class Export2ExcelService {
|
|
|
* 租户专题库使用情况报表
|
|
|
* @throws IOException
|
|
|
*/
|
|
|
- public void exportProjectNameToExcel(List<Integer> tenantIds) throws IOException {
|
|
|
- //保存生成excel的地址
|
|
|
- String fileName = IdUtil.simpleUUID() + ".xls";
|
|
|
- String directoryName = fileUtils.createDirectory();
|
|
|
- String outPath = fileUtils.getSavePath(directoryName) + fileName;
|
|
|
+ public byte[] exportProjectNameToExcel(List<Integer> tenantIds) throws IOException {
|
|
|
//查询数据
|
|
|
List<ProjectUsedByTenantVO> projectUsedByTenantVOS = this.getProjectData(tenantIds);
|
|
|
//配置导出excel
|
|
|
- try (FileOutputStream fileOut = new FileOutputStream(outPath)){
|
|
|
+ try (ByteArrayOutputStream out = new ByteArrayOutputStream()){
|
|
|
//创建excel
|
|
|
Workbook workbook = new XSSFWorkbook();
|
|
|
//创建sheet页
|
|
@@ -99,9 +97,10 @@ public class Export2ExcelService {
|
|
|
sheet.setColumnWidth(1, 256 * 20);
|
|
|
sheet.setColumnWidth(2, 256 * 20);
|
|
|
sheet.setColumnWidth(3, 256 * 20);
|
|
|
- workbook.write(fileOut);
|
|
|
+ workbook.write(out);
|
|
|
+ return out.toByteArray();
|
|
|
} catch (FileNotFoundException e) {
|
|
|
- e.printStackTrace();
|
|
|
+ throw new FileNotFoundException();
|
|
|
}
|
|
|
}
|
|
|
/**
|
|
@@ -149,15 +148,11 @@ public class Export2ExcelService {
|
|
|
* 租户人员报表
|
|
|
* @throws IOException
|
|
|
*/
|
|
|
- public void exportPersonnelNameToExcel(List<Integer> tenantIds) throws IOException {
|
|
|
- //保存生成excel的地址
|
|
|
- String fileName = IdUtil.simpleUUID() + ".xls";
|
|
|
- String directoryName = fileUtils.createDirectory();
|
|
|
- String outPath = fileUtils.getSavePath(directoryName) + fileName;
|
|
|
+ public byte[] exportPersonnelNameToExcel(List<Integer> tenantIds) throws IOException {
|
|
|
//查询数据
|
|
|
List<PersonnelNameVO> personnelNameVOS = this.getPersonnelNameData(tenantIds);
|
|
|
//配置导出excel
|
|
|
- try (FileOutputStream fileOut = new FileOutputStream(outPath)){
|
|
|
+ try (ByteArrayOutputStream out = new ByteArrayOutputStream()){
|
|
|
//创建excel
|
|
|
Workbook workbook = new XSSFWorkbook();
|
|
|
//创建sheet页
|
|
@@ -192,9 +187,10 @@ public class Export2ExcelService {
|
|
|
sheet.setColumnWidth(1, 256 * 20);
|
|
|
sheet.setColumnWidth(2, 256 * 20);
|
|
|
sheet.setColumnWidth(3, 256 * 20);
|
|
|
- workbook.write(fileOut);
|
|
|
+ workbook.write(out);
|
|
|
+ return out.toByteArray();
|
|
|
} catch (FileNotFoundException e) {
|
|
|
- e.printStackTrace();
|
|
|
+ throw new FileNotFoundException();
|
|
|
}
|
|
|
}
|
|
|
/**
|
|
@@ -257,7 +253,7 @@ public class Export2ExcelService {
|
|
|
* 租户报告使用情况报表
|
|
|
* @throws IOException
|
|
|
*/
|
|
|
- public void exportReportTenant(List<Integer> tenantIds) throws IOException {
|
|
|
+ public byte[] exportReportTenant(List<Integer> tenantIds) throws IOException {
|
|
|
//需要导出到excel的对象集合,查询数据
|
|
|
List<ReportUsedByTenantVO> reportUsedByTenantVOS = this.reportStr2Object(tenantIds);
|
|
|
//保存生成excel的地址
|
|
@@ -265,7 +261,7 @@ public class Export2ExcelService {
|
|
|
String directoryName = fileUtils.createDirectory();
|
|
|
String outPath = fileUtils.getSavePath(directoryName) + fileName;
|
|
|
//配置导出excel
|
|
|
- try (FileOutputStream fileOut = new FileOutputStream(outPath)){
|
|
|
+ try (ByteArrayOutputStream out = new ByteArrayOutputStream()){
|
|
|
//创建excel
|
|
|
Workbook workbook = new XSSFWorkbook();
|
|
|
//创建sheet页
|
|
@@ -298,9 +294,10 @@ public class Export2ExcelService {
|
|
|
sheet.setColumnWidth(0, 256 * 30);
|
|
|
sheet.setColumnWidth(1, 256 * 20);
|
|
|
sheet.setColumnWidth(2, 256 * 20);
|
|
|
- workbook.write(fileOut);
|
|
|
+ workbook.write(out);
|
|
|
+ return out.toByteArray();
|
|
|
} catch (FileNotFoundException e) {
|
|
|
- e.printStackTrace();
|
|
|
+ throw new FileNotFoundException();
|
|
|
}
|
|
|
}
|
|
|
/**
|
|
@@ -371,15 +368,11 @@ public class Export2ExcelService {
|
|
|
* 租户被分享专题库报表
|
|
|
* @throws IOException
|
|
|
*/
|
|
|
- public void exportProjectShared(List<Integer> tenantIds) throws IOException {
|
|
|
+ public byte[] exportProjectShared(List<Integer> tenantIds) throws IOException {
|
|
|
//需要导出到excel的对象集合,查询数据
|
|
|
List<ProjectSharedTenantVO> projectSharedTenantVOS = this.getProjectSharedData(tenantIds);
|
|
|
- //保存生成excel的地址
|
|
|
- String fileName = IdUtil.simpleUUID() + ".xls";
|
|
|
- String directoryName = fileUtils.createDirectory();
|
|
|
- String outPath = fileUtils.getSavePath(directoryName) + fileName;
|
|
|
//配置导出excel
|
|
|
- try (FileOutputStream fileOut = new FileOutputStream(outPath)){
|
|
|
+ try (ByteArrayOutputStream out = new ByteArrayOutputStream()){
|
|
|
//创建excel
|
|
|
Workbook workbook = new XSSFWorkbook();
|
|
|
//创建sheet页
|
|
@@ -412,9 +405,10 @@ public class Export2ExcelService {
|
|
|
sheet.setColumnWidth(0, 256 * 30);
|
|
|
sheet.setColumnWidth(1, 256 * 20);
|
|
|
sheet.setColumnWidth(2, 256 * 20);
|
|
|
- workbook.write(fileOut);
|
|
|
+ workbook.write(out);
|
|
|
+ return out.toByteArray();
|
|
|
} catch (FileNotFoundException e) {
|
|
|
- e.printStackTrace();
|
|
|
+ throw new FileNotFoundException();
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -463,8 +457,9 @@ public class Export2ExcelService {
|
|
|
* 导出汇总报表
|
|
|
* @param tenantIds
|
|
|
* @throws IOException
|
|
|
+ * @return
|
|
|
*/
|
|
|
- public void exportTotal(List<Integer> tenantIds) throws IOException {
|
|
|
+ public byte[] exportTotal(List<Integer> tenantIds) throws IOException {
|
|
|
List<TotalDataVO> totalDataVOS = new ArrayList<>();
|
|
|
if(tenantIds.size() > 0) {
|
|
|
for (Integer tenantId : tenantIds) {
|
|
@@ -478,12 +473,8 @@ public class Export2ExcelService {
|
|
|
totalDataVOS.add(totalDataVO);
|
|
|
}
|
|
|
}
|
|
|
- //保存生成excel的地址
|
|
|
- String fileName = IdUtil.simpleUUID() + ".xls";
|
|
|
- String directoryName = fileUtils.createDirectory();
|
|
|
- String outPath = fileUtils.getSavePath(directoryName) + fileName;
|
|
|
//配置导出excel
|
|
|
- try (FileOutputStream fileOut = new FileOutputStream(outPath)){
|
|
|
+ try (ByteArrayOutputStream out = new ByteArrayOutputStream()){
|
|
|
//创建excel
|
|
|
Workbook workbook = new XSSFWorkbook();
|
|
|
//创建sheet页
|
|
@@ -520,9 +511,10 @@ public class Export2ExcelService {
|
|
|
sheet.setColumnWidth(2, 256 * 20);
|
|
|
sheet.setColumnWidth(3, 256 * 20);
|
|
|
sheet.setColumnWidth(4, 256 * 20);
|
|
|
- workbook.write(fileOut);
|
|
|
+ workbook.write(out);
|
|
|
+ return out.toByteArray();
|
|
|
} catch (FileNotFoundException e) {
|
|
|
- e.printStackTrace();
|
|
|
+ throw new FileNotFoundException();
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -586,18 +578,15 @@ public class Export2ExcelService {
|
|
|
|
|
|
/**
|
|
|
* 登陆日志报表导出
|
|
|
- * @param queryType
|
|
|
+ * @param queryLoginRecordDTO
|
|
|
+ * @return
|
|
|
* @throws IOException
|
|
|
*/
|
|
|
- public void exportLoginRecord(Integer queryType) throws IOException {
|
|
|
+ public byte[] exportLoginRecord(QueryLoginRecordDTO queryLoginRecordDTO) throws IOException {
|
|
|
//需要导出到excel的对象集合,查询数据
|
|
|
- List<LoginRecordExportVO> loginRecordExportVOS = this.loadLoginRecordData(queryType);
|
|
|
- //保存生成excel的地址
|
|
|
- String fileName = IdUtil.simpleUUID() + ".xls";
|
|
|
- String directoryName = fileUtils.createDirectory();
|
|
|
- String outPath = fileUtils.getSavePath(directoryName) + fileName;
|
|
|
+ List<LoginRecordExportVO> loginRecordExportVOS = this.loadLoginRecordData(queryLoginRecordDTO);
|
|
|
//配置导出excel
|
|
|
- try (FileOutputStream fileOut = new FileOutputStream(outPath)){
|
|
|
+ try (ByteArrayOutputStream out = new ByteArrayOutputStream()){
|
|
|
//创建excel
|
|
|
Workbook workbook = new XSSFWorkbook();
|
|
|
//创建sheet页
|
|
@@ -640,30 +629,23 @@ public class Export2ExcelService {
|
|
|
sheet.setColumnWidth(5, 256 * 20);
|
|
|
sheet.setColumnWidth(6, 256 * 20);
|
|
|
sheet.setColumnWidth(7, 256 * 20);
|
|
|
- workbook.write(fileOut);
|
|
|
+ workbook.write(out);
|
|
|
+ return out.toByteArray();
|
|
|
} catch (FileNotFoundException e) {
|
|
|
- e.printStackTrace();
|
|
|
+ throw new XiaoShiException("下载失败");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 装载登录日志Excel信息
|
|
|
- * @param queryType
|
|
|
+ * @param queryLoginRecordDTO
|
|
|
* @return
|
|
|
*/
|
|
|
- public List<LoginRecordExportVO> loadLoginRecordData(Integer queryType){
|
|
|
+ public List<LoginRecordExportVO> loadLoginRecordData(QueryLoginRecordDTO queryLoginRecordDTO){
|
|
|
List<LoginRecordExportVO> loginRecordExportVOS = new ArrayList<>();
|
|
|
List<LoginRecord> loginRecords = new ArrayList<>();
|
|
|
- //获取当前登陆人信息
|
|
|
-// PersonnelVO personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
|
|
|
- if(queryType == null || queryType.equals(0)){
|
|
|
-// Integer id = personnelVO.getId();
|
|
|
- Integer id = 328;
|
|
|
- loginRecords = loginRecordService.getLoginRecord(id, queryType);
|
|
|
- } else if(queryType.equals(1)){
|
|
|
-// Integer id = personnelVO.getTenantId();
|
|
|
- Integer id = 1;
|
|
|
- loginRecords = loginRecordService.getLoginRecord(id, queryType);
|
|
|
+ if(queryLoginRecordDTO != null){
|
|
|
+ loginRecords = loginRecordService.getLoginRecord(queryLoginRecordDTO);
|
|
|
} else {
|
|
|
throw new XiaoShiException("导出失败");
|
|
|
}
|