|
@@ -0,0 +1,691 @@
|
|
|
|
+package cn.cslg.permission.service;
|
|
|
|
+
|
|
|
|
+import cn.cslg.permission.common.model.vo.*;
|
|
|
|
+import cn.cslg.permission.common.utils.CacheUtils;
|
|
|
|
+import cn.cslg.permission.common.utils.FileUtils;
|
|
|
|
+import cn.cslg.permission.common.utils.LoginUtils;
|
|
|
|
+import cn.cslg.permission.domain.LoginRecord;
|
|
|
|
+import cn.cslg.permission.domain.Personnel;
|
|
|
|
+import cn.cslg.permission.domain.Tenant;
|
|
|
|
+import cn.cslg.permission.exception.XiaoShiException;
|
|
|
|
+import cn.hutool.core.util.IdUtil;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
+import com.google.gson.Gson;
|
|
|
|
+import com.google.gson.reflect.TypeToken;
|
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import okhttp3.MediaType;
|
|
|
|
+import okhttp3.OkHttpClient;
|
|
|
|
+import okhttp3.Request;
|
|
|
|
+import okhttp3.RequestBody;
|
|
|
|
+import org.apache.poi.ss.usermodel.*;
|
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+
|
|
|
|
+import java.io.FileNotFoundException;
|
|
|
|
+import java.io.FileOutputStream;
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import java.lang.reflect.Type;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Objects;
|
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * 导出报表
|
|
|
|
+ * @Author xiexiang
|
|
|
|
+ * @Date 2023/8/2
|
|
|
|
+ */
|
|
|
|
+@Slf4j
|
|
|
|
+@Service
|
|
|
|
+@RequiredArgsConstructor
|
|
|
|
+public class Export2ExcelService {
|
|
|
|
+ private String PASUrl = "http://localhost:8877";
|
|
|
|
+ private String RMSUrl = "http://localhost:8872";
|
|
|
|
+ private String PCSUrl = "http://localhost:8871";
|
|
|
|
+ private final FileUtils fileUtils;
|
|
|
|
+ private final CacheUtils cacheUtils;
|
|
|
|
+ private final LoginUtils loginUtils;
|
|
|
|
+ private final PersonnelService personnelService;
|
|
|
|
+ private final TenantService tenantService;
|
|
|
|
+ private final LoginRecordService loginRecordService;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 租户专题库使用情况报表
|
|
|
|
+ * @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;
|
|
|
|
+ //查询数据
|
|
|
|
+ List<ProjectUsedByTenantVO> projectUsedByTenantVOS = this.getProjectData(tenantIds);
|
|
|
|
+ //配置导出excel
|
|
|
|
+ try (FileOutputStream fileOut = new FileOutputStream(outPath)){
|
|
|
|
+ //创建excel
|
|
|
|
+ Workbook workbook = new XSSFWorkbook();
|
|
|
|
+ //创建sheet页
|
|
|
|
+ Sheet sheet = workbook.createSheet("租户专题库使用报表");
|
|
|
|
+ //创建标题行
|
|
|
|
+ Row headerRow = sheet.createRow(0);
|
|
|
|
+ String[] headers = {"租户","专题库数量","专题库名称","专利数量"};
|
|
|
|
+ for(int i = 0; i < headers.length; i++){
|
|
|
|
+ Cell cell = headerRow.createCell(i);
|
|
|
|
+ cell.setCellValue(headers[i]);
|
|
|
|
+ }
|
|
|
|
+ //字体
|
|
|
|
+ Font headerFont = workbook.createFont();
|
|
|
|
+ headerFont.setBold(true);
|
|
|
|
+ CellStyle headerCellStyle = workbook.createCellStyle();
|
|
|
|
+ headerCellStyle.setFont(headerFont);
|
|
|
|
+ //开始插入数据的行数
|
|
|
|
+ int rowNum = 1;
|
|
|
|
+ //填充数据
|
|
|
|
+ for(ProjectUsedByTenantVO projectUsedByTenantVO : projectUsedByTenantVOS){
|
|
|
|
+ Row row = sheet.createRow(rowNum++);
|
|
|
|
+ row.createCell(0).setCellValue(projectUsedByTenantVO.getTenantName());
|
|
|
|
+ row.createCell(1).setCellValue(projectUsedByTenantVO.getProjectNum());
|
|
|
|
+ row.createCell(2).setCellValue(projectUsedByTenantVO.getProjectName());
|
|
|
|
+ row.createCell(3).setCellValue(projectUsedByTenantVO.getPatentNum());
|
|
|
|
+ }
|
|
|
|
+// //自动调整列宽
|
|
|
|
+// for(int i = 0; i < headers.length; i++){
|
|
|
|
+// sheet.autoSizeColumn(i);
|
|
|
|
+// }
|
|
|
|
+ sheet.setColumnWidth(0, 256 * 30);
|
|
|
|
+ sheet.setColumnWidth(1, 256 * 20);
|
|
|
|
+ sheet.setColumnWidth(2, 256 * 20);
|
|
|
|
+ sheet.setColumnWidth(3, 256 * 20);
|
|
|
|
+ workbook.write(fileOut);
|
|
|
|
+ } catch (FileNotFoundException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ /**
|
|
|
|
+ * 返回租户专题库使用情况对象集合
|
|
|
|
+ * @return
|
|
|
|
+ * @throws IOException
|
|
|
|
+ */
|
|
|
|
+ public List<ProjectUsedByTenantVO> getProjectData(List<Integer> tenantIds) throws IOException {
|
|
|
|
+ String data = this.getProjectUsedByTenantFromPAS(tenantIds);
|
|
|
|
+ Gson gson = new Gson();
|
|
|
|
+ Type listType = new TypeToken<List<ProjectUsedByTenantVO>>(){}.getType();
|
|
|
|
+ List<ProjectUsedByTenantVO> projectUsedByTenantVOS = gson.fromJson(data, listType);
|
|
|
|
+ return projectUsedByTenantVOS;
|
|
|
|
+ }
|
|
|
|
+ /**
|
|
|
|
+ * 调用分析系统查询接口
|
|
|
|
+ * @return
|
|
|
|
+ * @throws IOException
|
|
|
|
+ */
|
|
|
|
+ public String getProjectUsedByTenantFromPAS(List<Integer> tenantIds) throws IOException {
|
|
|
|
+ String param = new Gson().toJson(tenantIds);
|
|
|
|
+ RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), param);
|
|
|
|
+ OkHttpClient okHttpClient = new OkHttpClient.Builder()
|
|
|
|
+ .connectTimeout(60, TimeUnit.SECONDS)
|
|
|
|
+ .writeTimeout(60, TimeUnit.SECONDS)
|
|
|
|
+ .readTimeout(60, TimeUnit.SECONDS)
|
|
|
|
+ .build();
|
|
|
|
+ Request request = new Request.Builder()
|
|
|
|
+ .url(PASUrl + "/api/v2/usedByTenant/query")
|
|
|
|
+ .post(requestBody)
|
|
|
|
+ .build();
|
|
|
|
+ return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //---------------------------------租户专题库使用情况报表-------------------------------------------------------
|
|
|
|
+ //----------------------------------------------------------------------------------------------------------
|
|
|
|
+ //----------------------------------------------------------------------------------------------------------
|
|
|
|
+ //----------------------------------------------------------------------------------------------------------
|
|
|
|
+ //----------------------------------------------------------------------------------------------------------
|
|
|
|
+ //----------------------------------------------------------------------------------------------------------
|
|
|
|
+ //----------------------------------------------------------------------------------------------------------
|
|
|
|
+ //-----------------------------------------租户人员报表-------------------------------------------------------
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 租户人员报表
|
|
|
|
+ * @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;
|
|
|
|
+ //查询数据
|
|
|
|
+ List<PersonnelNameVO> personnelNameVOS = this.getPersonnelNameData(tenantIds);
|
|
|
|
+ //配置导出excel
|
|
|
|
+ try (FileOutputStream fileOut = new FileOutputStream(outPath)){
|
|
|
|
+ //创建excel
|
|
|
|
+ Workbook workbook = new XSSFWorkbook();
|
|
|
|
+ //创建sheet页
|
|
|
|
+ Sheet sheet = workbook.createSheet("租户人员表");
|
|
|
|
+ //创建标题行
|
|
|
|
+ Row headerRow = sheet.createRow(0);
|
|
|
|
+ String[] headers = {"租户","人员数量","人员名称","账号"};
|
|
|
|
+ for(int i = 0; i < headers.length; i++){
|
|
|
|
+ Cell cell = headerRow.createCell(i);
|
|
|
|
+ cell.setCellValue(headers[i]);
|
|
|
|
+ }
|
|
|
|
+ //字体
|
|
|
|
+ Font headerFont = workbook.createFont();
|
|
|
|
+ headerFont.setBold(true);
|
|
|
|
+ CellStyle headerCellStyle = workbook.createCellStyle();
|
|
|
|
+ headerCellStyle.setFont(headerFont);
|
|
|
|
+ //开始插入数据的行数
|
|
|
|
+ int rowNum = 1;
|
|
|
|
+ //填充数据
|
|
|
|
+ for(PersonnelNameVO personnelNameVO : personnelNameVOS){
|
|
|
|
+ Row row = sheet.createRow(rowNum++);
|
|
|
|
+ row.createCell(0).setCellValue(personnelNameVO.getTenantName());
|
|
|
|
+ row.createCell(1).setCellValue(personnelNameVO.getPersonnelNum());
|
|
|
|
+ row.createCell(2).setCellValue(personnelNameVO.getPersonnelName());
|
|
|
|
+ row.createCell(3).setCellValue(personnelNameVO.getPersonnelUserName());
|
|
|
|
+ }
|
|
|
|
+// //自动调整列宽
|
|
|
|
+// for(int i = 0; i < headers.length; i++){
|
|
|
|
+// sheet.autoSizeColumn(i);
|
|
|
|
+// }
|
|
|
|
+ sheet.setColumnWidth(0, 256 * 30);
|
|
|
|
+ sheet.setColumnWidth(1, 256 * 20);
|
|
|
|
+ sheet.setColumnWidth(2, 256 * 20);
|
|
|
|
+ sheet.setColumnWidth(3, 256 * 20);
|
|
|
|
+ workbook.write(fileOut);
|
|
|
|
+ } catch (FileNotFoundException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ /**
|
|
|
|
+ * 查询租户人员信息
|
|
|
|
+ * @param tenantIds
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public List<PersonnelNameVO> getPersonnelNameData(List<Integer> tenantIds){
|
|
|
|
+ List<PersonnelNameVO> personnelNameVOS = new ArrayList<>();
|
|
|
|
+ if(tenantIds.size() == 0){
|
|
|
|
+ List<Tenant> tenants = tenantService.list();
|
|
|
|
+ tenantIds = tenants.stream().map(Tenant::getId).collect(Collectors.toList());
|
|
|
|
+ System.out.println(tenantIds);
|
|
|
|
+ }
|
|
|
|
+ for(Integer tenantId : tenantIds){
|
|
|
|
+ //租户名
|
|
|
|
+ Tenant tenant = tenantService.getById(tenantId);
|
|
|
|
+ String tenantName = tenant.getTenantName();
|
|
|
|
+ LambdaQueryWrapper<Personnel> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
+ queryWrapper.eq(Personnel::getTenantId, tenantId);
|
|
|
|
+ Long count = personnelService.count(queryWrapper);
|
|
|
|
+ if(count > 0){
|
|
|
|
+ //人员数量
|
|
|
|
+ Integer personnelNum = Long.valueOf(count).intValue();
|
|
|
|
+ List<Personnel> personnels = personnelService.list(queryWrapper);
|
|
|
|
+ for(Personnel personnel : personnels){
|
|
|
|
+ PersonnelNameVO personnelNameVO = new PersonnelNameVO();
|
|
|
|
+ //租户
|
|
|
|
+ personnelNameVO.setTenantName(tenantName);
|
|
|
|
+ //人员数量
|
|
|
|
+ personnelNameVO.setPersonnelNum(personnelNum);
|
|
|
|
+ //人员名称
|
|
|
|
+ personnelNameVO.setPersonnelName(personnel.getPersonnelName());
|
|
|
|
+ //账号
|
|
|
|
+ personnelNameVO.setPersonnelUserName(personnel.getPersonnelUserName());
|
|
|
|
+ personnelNameVOS.add(personnelNameVO);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ PersonnelNameVO personnelNameVO = new PersonnelNameVO();
|
|
|
|
+ //租户
|
|
|
|
+ personnelNameVO.setTenantName(tenantName);
|
|
|
|
+ //人员数量
|
|
|
|
+ personnelNameVO.setPersonnelNum(0);
|
|
|
|
+ personnelNameVOS.add(personnelNameVO);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return personnelNameVOS;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //-----------------------------------------租户人员报表-------------------------------------------------------
|
|
|
|
+ //----------------------------------------------------------------------------------------------------------
|
|
|
|
+ //----------------------------------------------------------------------------------------------------------
|
|
|
|
+ //----------------------------------------------------------------------------------------------------------
|
|
|
|
+ //----------------------------------------------------------------------------------------------------------
|
|
|
|
+ //----------------------------------------------------------------------------------------------------------
|
|
|
|
+ //----------------------------------------------------------------------------------------------------------
|
|
|
|
+ //-----------------------------------租户报告使用情况报表-------------------------------------------------------
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 租户报告使用情况报表
|
|
|
|
+ * @throws IOException
|
|
|
|
+ */
|
|
|
|
+ public void exportReportTenant(List<Integer> tenantIds) throws IOException {
|
|
|
|
+ //需要导出到excel的对象集合,查询数据
|
|
|
|
+ List<ReportUsedByTenantVO> reportUsedByTenantVOS = this.reportStr2Object(tenantIds);
|
|
|
|
+ //保存生成excel的地址
|
|
|
|
+ String fileName = IdUtil.simpleUUID() + ".xls";
|
|
|
|
+ String directoryName = fileUtils.createDirectory();
|
|
|
|
+ String outPath = fileUtils.getSavePath(directoryName) + fileName;
|
|
|
|
+ //配置导出excel
|
|
|
|
+ try (FileOutputStream fileOut = new FileOutputStream(outPath)){
|
|
|
|
+ //创建excel
|
|
|
|
+ Workbook workbook = new XSSFWorkbook();
|
|
|
|
+ //创建sheet页
|
|
|
|
+ Sheet sheet = workbook.createSheet("租户报告使用报表");
|
|
|
|
+ //创建标题行
|
|
|
|
+ Row headerRow = sheet.createRow(0);
|
|
|
|
+ String[] headers = {"租户","报告数量","报告名称"};
|
|
|
|
+ for(int i = 0; i < headers.length; i++){
|
|
|
|
+ Cell cell = headerRow.createCell(i);
|
|
|
|
+ cell.setCellValue(headers[i]);
|
|
|
|
+ }
|
|
|
|
+ //字体
|
|
|
|
+ Font headerFont = workbook.createFont();
|
|
|
|
+ headerFont.setBold(true);
|
|
|
|
+ CellStyle headerCellStyle = workbook.createCellStyle();
|
|
|
|
+ headerCellStyle.setFont(headerFont);
|
|
|
|
+ //开始插入数据的行数
|
|
|
|
+ int rowNum = 1;
|
|
|
|
+ //填充数据
|
|
|
|
+ for(ReportUsedByTenantVO reportUsedByTenantVO : reportUsedByTenantVOS){
|
|
|
|
+ Row row = sheet.createRow(rowNum++);
|
|
|
|
+ row.createCell(0).setCellValue(reportUsedByTenantVO.getTenantName());
|
|
|
|
+ row.createCell(1).setCellValue(reportUsedByTenantVO.getReportNum());
|
|
|
|
+ row.createCell(2).setCellValue(reportUsedByTenantVO.getReportName());
|
|
|
|
+ }
|
|
|
|
+// //自动调整列宽
|
|
|
|
+// for(int i = 0; i < headers.length; i++){
|
|
|
|
+// sheet.autoSizeColumn(i);
|
|
|
|
+// }
|
|
|
|
+ sheet.setColumnWidth(0, 256 * 30);
|
|
|
|
+ sheet.setColumnWidth(1, 256 * 20);
|
|
|
|
+ sheet.setColumnWidth(2, 256 * 20);
|
|
|
|
+ workbook.write(fileOut);
|
|
|
|
+ } catch (FileNotFoundException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ /**
|
|
|
|
+ * 租户报告报表字符串转对象集合
|
|
|
|
+ * @return
|
|
|
|
+ * @throws IOException
|
|
|
|
+ */
|
|
|
|
+ public List<ReportUsedByTenantVO> reportStr2Object(List<Integer> tenantIds) throws IOException {
|
|
|
|
+ String reData = this.getReportDataFromRMS(tenantIds);
|
|
|
|
+ Gson gson = new Gson();
|
|
|
|
+ Type listType = new TypeToken<List<ReportUsedByTenantVO>>(){}.getType();
|
|
|
|
+ List<ReportUsedByTenantVO> tenantVos = gson.fromJson(reData, listType);
|
|
|
|
+ return tenantVos;
|
|
|
|
+ }
|
|
|
|
+ /**
|
|
|
|
+ * 从报告系统获取租户报告使用情况
|
|
|
|
+ * @return
|
|
|
|
+ * @throws IOException
|
|
|
|
+ */
|
|
|
|
+ public String getReportDataFromRMS(List<Integer> tenantIds) throws IOException {
|
|
|
|
+ String param = new Gson().toJson(tenantIds);
|
|
|
|
+ RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), param);
|
|
|
|
+ OkHttpClient okHttpClient = new OkHttpClient.Builder()
|
|
|
|
+ .connectTimeout(60, TimeUnit.SECONDS)
|
|
|
|
+ .writeTimeout(60, TimeUnit.SECONDS)
|
|
|
|
+ .readTimeout(60, TimeUnit.SECONDS)
|
|
|
|
+ .build();
|
|
|
|
+ Request request = new Request.Builder()
|
|
|
|
+ .url("http://localhost:8872" + "/api/report/api/report/queryReportNameUsedByTenant")
|
|
|
|
+ .post(requestBody)
|
|
|
|
+ .build();
|
|
|
|
+ return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
|
|
|
|
+ }
|
|
|
|
+ /**
|
|
|
|
+ * 查出所有租户,并且查出租户下的人员
|
|
|
|
+ */
|
|
|
|
+ public List<ReportTenantVO> getTenantPerson(List<Integer> tenantIds){
|
|
|
|
+ List<ReportTenantVO> reportTenantVOS = new ArrayList<>();
|
|
|
|
+ //放入空集合,查询全部
|
|
|
|
+ List<Tenant> tenants = tenantService.getTenantIdAndName(tenantIds);
|
|
|
|
+ //遍历,装载
|
|
|
|
+ for(Tenant tenant : tenants){
|
|
|
|
+ ReportTenantVO reportTenantVO = new ReportTenantVO();
|
|
|
|
+ //租户id
|
|
|
|
+ reportTenantVO.setTenantId(tenant.getId());
|
|
|
|
+ //租户名
|
|
|
|
+ reportTenantVO.setTenantName(tenant.getTenantName());
|
|
|
|
+ //人员ids
|
|
|
|
+ LambdaQueryWrapper<Personnel> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
+ queryWrapper.eq(Personnel::getTenantId, tenant.getId());
|
|
|
|
+ List<Personnel> personnels = personnelService.list(queryWrapper);
|
|
|
|
+ List<Integer> personnelIds = personnels.stream().map(Personnel::getId).collect(Collectors.toList());
|
|
|
|
+ reportTenantVO.setPersonnelIds(personnelIds);
|
|
|
|
+ reportTenantVOS.add(reportTenantVO);
|
|
|
|
+ }
|
|
|
|
+ return reportTenantVOS;
|
|
|
|
+ }
|
|
|
|
+ //-----------------------------------租户报告使用情况报表-------------------------------------------------------
|
|
|
|
+ //----------------------------------------------------------------------------------------------------------
|
|
|
|
+ //----------------------------------------------------------------------------------------------------------
|
|
|
|
+ //----------------------------------------------------------------------------------------------------------
|
|
|
|
+ //----------------------------------------------------------------------------------------------------------
|
|
|
|
+ //----------------------------------------------------------------------------------------------------------
|
|
|
|
+ //----------------------------------------------------------------------------------------------------------
|
|
|
|
+ //-----------------------------------租户被分享专题库报表-------------------------------------------------------
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 租户被分享专题库报表
|
|
|
|
+ * @throws IOException
|
|
|
|
+ */
|
|
|
|
+ public void 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)){
|
|
|
|
+ //创建excel
|
|
|
|
+ Workbook workbook = new XSSFWorkbook();
|
|
|
|
+ //创建sheet页
|
|
|
|
+ Sheet sheet = workbook.createSheet("租户被分享专题库报表");
|
|
|
|
+ //创建标题行
|
|
|
|
+ Row headerRow = sheet.createRow(0);
|
|
|
|
+ String[] headers = {"租户","被分享专题库数量","被分享专题库"};
|
|
|
|
+ for(int i = 0; i < headers.length; i++){
|
|
|
|
+ Cell cell = headerRow.createCell(i);
|
|
|
|
+ cell.setCellValue(headers[i]);
|
|
|
|
+ }
|
|
|
|
+ //字体
|
|
|
|
+ Font headerFont = workbook.createFont();
|
|
|
|
+ headerFont.setBold(true);
|
|
|
|
+ CellStyle headerCellStyle = workbook.createCellStyle();
|
|
|
|
+ headerCellStyle.setFont(headerFont);
|
|
|
|
+ //开始插入数据的行数
|
|
|
|
+ int rowNum = 1;
|
|
|
|
+ //填充数据
|
|
|
|
+ for(ProjectSharedTenantVO projectSharedTenantVO : projectSharedTenantVOS){
|
|
|
|
+ Row row = sheet.createRow(rowNum++);
|
|
|
|
+ row.createCell(0).setCellValue(projectSharedTenantVO.getTenantName());
|
|
|
|
+ row.createCell(1).setCellValue(projectSharedTenantVO.getProjectNum());
|
|
|
|
+ row.createCell(2).setCellValue(projectSharedTenantVO.getProjectName());
|
|
|
|
+ }
|
|
|
|
+// //自动调整列宽
|
|
|
|
+// for(int i = 0; i < headers.length; i++){
|
|
|
|
+// sheet.autoSizeColumn(i);
|
|
|
|
+// }
|
|
|
|
+ sheet.setColumnWidth(0, 256 * 30);
|
|
|
|
+ sheet.setColumnWidth(1, 256 * 20);
|
|
|
|
+ sheet.setColumnWidth(2, 256 * 20);
|
|
|
|
+ workbook.write(fileOut);
|
|
|
|
+ } catch (FileNotFoundException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 返回租户被分享专题库对象集合
|
|
|
|
+ * @return
|
|
|
|
+ * @throws IOException
|
|
|
|
+ */
|
|
|
|
+ public List<ProjectSharedTenantVO> getProjectSharedData(List<Integer> tenantIds) throws IOException {
|
|
|
|
+ String data = this.getProjectSharedTenantFromPAS(tenantIds);
|
|
|
|
+ Gson gson = new Gson();
|
|
|
|
+ Type listType = new TypeToken<List<ProjectSharedTenantVO>>(){}.getType();
|
|
|
|
+ List<ProjectSharedTenantVO> projectSharedTenantVOS = gson.fromJson(data, listType);
|
|
|
|
+ return projectSharedTenantVOS;
|
|
|
|
+ }
|
|
|
|
+ /**
|
|
|
|
+ * 调用分析系统查询接口
|
|
|
|
+ * @return
|
|
|
|
+ * @throws IOException
|
|
|
|
+ */
|
|
|
|
+ public String getProjectSharedTenantFromPAS(List<Integer> tenantIds) throws IOException {
|
|
|
|
+ String param = new Gson().toJson(tenantIds);
|
|
|
|
+ RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), param);
|
|
|
|
+ OkHttpClient okHttpClient = new OkHttpClient.Builder()
|
|
|
|
+ .connectTimeout(60, TimeUnit.SECONDS)
|
|
|
|
+ .writeTimeout(60, TimeUnit.SECONDS)
|
|
|
|
+ .readTimeout(60, TimeUnit.SECONDS)
|
|
|
|
+ .build();
|
|
|
|
+ Request request = new Request.Builder()
|
|
|
|
+ .url(PASUrl + "/api/v2/usedByTenant/projectShared")
|
|
|
|
+ .post(requestBody)
|
|
|
|
+ .build();
|
|
|
|
+ return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //-----------------------------------租户被分享专题库报表-------------------------------------------------------
|
|
|
|
+ //----------------------------------------------------------------------------------------------------------
|
|
|
|
+ //----------------------------------------------------------------------------------------------------------
|
|
|
|
+ //----------------------------------------------------------------------------------------------------------
|
|
|
|
+ //----------------------------------------------------------------------------------------------------------
|
|
|
|
+ //----------------------------------------------------------------------------------------------------------
|
|
|
|
+ //----------------------------------------------------------------------------------------------------------
|
|
|
|
+ //-----------------------------------------租户汇总报表-------------------------------------------------------
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 导出汇总报表
|
|
|
|
+ * @param tenantIds
|
|
|
|
+ * @throws IOException
|
|
|
|
+ */
|
|
|
|
+ public void exportTotal(List<Integer> tenantIds) throws IOException {
|
|
|
|
+ List<TotalDataVO> totalDataVOS = new ArrayList<>();
|
|
|
|
+ if(tenantIds.size() > 0) {
|
|
|
|
+ for (Integer tenantId : tenantIds) {
|
|
|
|
+ TotalDataVO totalDataVO = this.getTotalData(tenantId);
|
|
|
|
+ totalDataVOS.add(totalDataVO);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ List<Tenant> tenants = tenantService.getTenantIdAndName(tenantIds);
|
|
|
|
+ for(Tenant tenant : tenants){
|
|
|
|
+ TotalDataVO totalDataVO = this.getTotalData(tenant.getId());
|
|
|
|
+ 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)){
|
|
|
|
+ //创建excel
|
|
|
|
+ Workbook workbook = new XSSFWorkbook();
|
|
|
|
+ //创建sheet页
|
|
|
|
+ Sheet sheet = workbook.createSheet("汇总报表");
|
|
|
|
+ //创建标题行
|
|
|
|
+ Row headerRow = sheet.createRow(0);
|
|
|
|
+ headerRow.setHeightInPoints(30); //设置行高为30个点
|
|
|
|
+ String[] headers = {"租户","报告数量","专题库数量","人员数量","专题库被分享数量"};
|
|
|
|
+ for(int i = 0; i < headers.length; i++){
|
|
|
|
+ Cell cell = headerRow.createCell(i);
|
|
|
|
+ cell.setCellValue(headers[i]);
|
|
|
|
+ }
|
|
|
|
+ //开始插入数据的行数
|
|
|
|
+ int rowNum = 1;
|
|
|
|
+ //填充数据
|
|
|
|
+ for(TotalDataVO totalDataVO : totalDataVOS){
|
|
|
|
+ Row row = sheet.createRow(rowNum++);
|
|
|
|
+ row.createCell(0).setCellValue(totalDataVO.getTenantName());
|
|
|
|
+ row.createCell(1).setCellValue(totalDataVO.getReportNum());
|
|
|
|
+ row.createCell(2).setCellValue(totalDataVO.getProjectNum());
|
|
|
|
+ row.createCell(3).setCellValue(totalDataVO.getPersonnelNum());
|
|
|
|
+ row.createCell(4).setCellValue(totalDataVO.getProjectSharedNum());
|
|
|
|
+ }
|
|
|
|
+ //字体
|
|
|
|
+ Font headerFont = workbook.createFont();
|
|
|
|
+ //粗体
|
|
|
|
+ headerFont.setBold(true);
|
|
|
|
+ CellStyle headerCellStyle = workbook.createCellStyle();
|
|
|
|
+ headerCellStyle.setVerticalAlignment(VerticalAlignment.CENTER); //文字垂直居中
|
|
|
|
+ //将字体应用于单元格样式
|
|
|
|
+ headerCellStyle.setFont(headerFont);
|
|
|
|
+ sheet.setColumnWidth(0, 256 * 30);
|
|
|
|
+ sheet.setColumnWidth(1, 256 * 20);
|
|
|
|
+ sheet.setColumnWidth(2, 256 * 20);
|
|
|
|
+ sheet.setColumnWidth(3, 256 * 20);
|
|
|
|
+ sheet.setColumnWidth(4, 256 * 20);
|
|
|
|
+ workbook.write(fileOut);
|
|
|
|
+ } catch (FileNotFoundException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 装载单个租户的汇总报表数据
|
|
|
|
+ * @param tenantId
|
|
|
|
+ * @return
|
|
|
|
+ * @throws IOException
|
|
|
|
+ */
|
|
|
|
+ public TotalDataVO getTotalData(Integer tenantId) throws IOException {
|
|
|
|
+ TotalDataVO totalDataVO = new TotalDataVO();
|
|
|
|
+ Tenant tenant = tenantService.getById(tenantId);
|
|
|
|
+ if(tenant != null) {
|
|
|
|
+ List<Integer> tenantIds = new ArrayList<>();
|
|
|
|
+ tenantIds.add(tenant.getId());
|
|
|
|
+ //租户名
|
|
|
|
+ totalDataVO.setTenantName(tenant.getTenantName());
|
|
|
|
+ //租户下人员数量
|
|
|
|
+ List<PersonnelNameVO> personnelNameVOS = this.getPersonnelNameData(tenantIds);
|
|
|
|
+ totalDataVO.setPersonnelNum(personnelNameVOS.get(0).getPersonnelNum());
|
|
|
|
+ //报告数量
|
|
|
|
+ String reportNumStr = this.getReportNumOfTotal(tenantId);
|
|
|
|
+ Integer reportNum = Integer.parseInt(reportNumStr);
|
|
|
|
+ totalDataVO.setReportNum(reportNum);
|
|
|
|
+ //专题库数量
|
|
|
|
+ List<ProjectUsedByTenantVO> projectUsedByTenantVOS = this.getProjectData(tenantIds);
|
|
|
|
+ Integer projectNum = projectUsedByTenantVOS.get(0).getProjectNum();
|
|
|
|
+ totalDataVO.setProjectNum(projectNum);
|
|
|
|
+ //被分享专题库数量
|
|
|
|
+ List<ProjectSharedTenantVO> projectSharedTenantVOS = this.getProjectSharedData(tenantIds);
|
|
|
|
+ Integer projectSharedNum = projectSharedTenantVOS.get(0).getProjectNum();
|
|
|
|
+ totalDataVO.setProjectSharedNum(projectSharedNum);
|
|
|
|
+ }
|
|
|
|
+ return totalDataVO;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 传给报告系统接口租户id 返回报告数量
|
|
|
|
+ * @return
|
|
|
|
+ * @throws IOException
|
|
|
|
+ */
|
|
|
|
+ public String getReportNumOfTotal(Integer tenantId) throws IOException {
|
|
|
|
+ OkHttpClient okHttpClient = new OkHttpClient.Builder()
|
|
|
|
+ .connectTimeout(60, TimeUnit.SECONDS)
|
|
|
|
+ .writeTimeout(60, TimeUnit.SECONDS)
|
|
|
|
+ .readTimeout(60, TimeUnit.SECONDS)
|
|
|
|
+ .build();
|
|
|
|
+ Request request = new Request.Builder()
|
|
|
|
+ .url("http://localhost:8872" + "/api/report/api/report/queryReportNumOfTotal?tenantId=" + tenantId)
|
|
|
|
+ .get()
|
|
|
|
+ .build();
|
|
|
|
+ return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
|
|
|
|
+ }
|
|
|
|
+ //-----------------------------------------租户汇总报表-------------------------------------------------------
|
|
|
|
+ //----------------------------------------------------------------------------------------------------------
|
|
|
|
+ //----------------------------------------------------------------------------------------------------------
|
|
|
|
+ //----------------------------------------------------------------------------------------------------------
|
|
|
|
+ //----------------------------------------------------------------------------------------------------------
|
|
|
|
+ //----------------------------------------------------------------------------------------------------------
|
|
|
|
+ //----------------------------------------登录日志导出报表------------------------------------------------------
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 登陆日志报表导出
|
|
|
|
+ * @param queryType
|
|
|
|
+ * @throws IOException
|
|
|
|
+ */
|
|
|
|
+ public void exportLoginRecord(Integer queryType) 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;
|
|
|
|
+ //配置导出excel
|
|
|
|
+ try (FileOutputStream fileOut = new FileOutputStream(outPath)){
|
|
|
|
+ //创建excel
|
|
|
|
+ Workbook workbook = new XSSFWorkbook();
|
|
|
|
+ //创建sheet页
|
|
|
|
+ Sheet sheet = workbook.createSheet("登录日志报表");
|
|
|
|
+ //创建标题行
|
|
|
|
+ Row headerRow = sheet.createRow(0);
|
|
|
|
+ String[] headers = {"租户","用户名","IP","创建时间","登录结果","登录系统","浏览器","操作系统"};
|
|
|
|
+ for(int i = 0; i < headers.length; i++){
|
|
|
|
+ Cell cell = headerRow.createCell(i);
|
|
|
|
+ cell.setCellValue(headers[i]);
|
|
|
|
+ }
|
|
|
|
+ //字体
|
|
|
|
+ Font headerFont = workbook.createFont();
|
|
|
|
+ headerFont.setBold(true);
|
|
|
|
+ CellStyle headerCellStyle = workbook.createCellStyle();
|
|
|
|
+ headerCellStyle.setFont(headerFont);
|
|
|
|
+ //开始插入数据的行数
|
|
|
|
+ int rowNum = 1;
|
|
|
|
+ //填充数据
|
|
|
|
+ for(LoginRecordExportVO loginRecordExportVO : loginRecordExportVOS){
|
|
|
|
+ Row row = sheet.createRow(rowNum++);
|
|
|
|
+ row.createCell(0).setCellValue(loginRecordExportVO.getTenantName());
|
|
|
|
+ row.createCell(1).setCellValue(loginRecordExportVO.getPersonnelUserName());
|
|
|
|
+ row.createCell(2).setCellValue(loginRecordExportVO.getLoginIp());
|
|
|
|
+ row.createCell(3).setCellValue(loginRecordExportVO.getCreateTime());
|
|
|
|
+ row.createCell(4).setCellValue(loginRecordExportVO.getLoginResult());
|
|
|
|
+ row.createCell(5).setCellValue(loginRecordExportVO.getLoginSystemName());
|
|
|
|
+ row.createCell(6).setCellValue(loginRecordExportVO.getBrowser());
|
|
|
|
+ row.createCell(7).setCellValue(loginRecordExportVO.getLoginOs());
|
|
|
|
+ }
|
|
|
|
+// //自动调整列宽
|
|
|
|
+// for(int i = 0; i < headers.length; i++){
|
|
|
|
+// sheet.autoSizeColumn(i);
|
|
|
|
+// }
|
|
|
|
+ sheet.setColumnWidth(0, 256 * 30);
|
|
|
|
+ sheet.setColumnWidth(1, 256 * 20);
|
|
|
|
+ sheet.setColumnWidth(2, 256 * 20);
|
|
|
|
+ sheet.setColumnWidth(3, 256 * 20);
|
|
|
|
+ sheet.setColumnWidth(4, 256 * 20);
|
|
|
|
+ sheet.setColumnWidth(5, 256 * 20);
|
|
|
|
+ sheet.setColumnWidth(6, 256 * 20);
|
|
|
|
+ sheet.setColumnWidth(7, 256 * 20);
|
|
|
|
+ workbook.write(fileOut);
|
|
|
|
+ } catch (FileNotFoundException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 装载登录日志Excel信息
|
|
|
|
+ * @param queryType
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public List<LoginRecordExportVO> loadLoginRecordData(Integer queryType){
|
|
|
|
+ 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);
|
|
|
|
+ } else {
|
|
|
|
+ throw new XiaoShiException("导出失败");
|
|
|
|
+ }
|
|
|
|
+ for(LoginRecord loginRecord : loginRecords){
|
|
|
|
+ LoginRecordExportVO loginRecordExportVO = new LoginRecordExportVO();
|
|
|
|
+ BeanUtils.copyProperties(loginRecord, loginRecordExportVO);
|
|
|
|
+ Tenant tenant = tenantService.getById(loginRecord.getTenantId());
|
|
|
|
+ loginRecordExportVO.setTenantName(tenant.getTenantName());
|
|
|
|
+ Personnel personnel = personnelService.getById(loginRecord.getPersonnelId());
|
|
|
|
+ loginRecordExportVO.setPersonnelUserName(personnel.getPersonnelUserName());
|
|
|
|
+ if(loginRecord.getLoginSystem().equals(0)){
|
|
|
|
+ loginRecordExportVO.setLoginSystemName("权限系统");
|
|
|
|
+ loginRecordExportVOS.add(loginRecordExportVO);
|
|
|
|
+ } else if(loginRecord.getLoginSystem().equals(1)){
|
|
|
|
+ loginRecordExportVO.setLoginSystemName("分析系统");
|
|
|
|
+ loginRecordExportVOS.add(loginRecordExportVO);
|
|
|
|
+ } else if(loginRecord.getLoginSystem().equals(2)){
|
|
|
|
+ loginRecordExportVO.setLoginSystemName("报告系统");
|
|
|
|
+ loginRecordExportVOS.add(loginRecordExportVO);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return loginRecordExportVOS;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|