feat: 企标/通用导出功能
This commit is contained in:
@@ -86,4 +86,7 @@ public class FieldCommon {
|
|||||||
// 中文双引号
|
// 中文双引号
|
||||||
public static final String QUOTE = "“";
|
public static final String QUOTE = "“";
|
||||||
|
|
||||||
|
// Ids
|
||||||
|
public static final String IDS = "ids";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+20
-5
@@ -5,6 +5,7 @@ import com.jero.modules.laws.common.vo.ManyStandardSelectionBox;
|
|||||||
import com.jero.modules.laws.common.vo.ManyStandardSelectionBoxVO;
|
import com.jero.modules.laws.common.vo.ManyStandardSelectionBoxVO;
|
||||||
import com.jero.modules.tag.entity.LawsTag;
|
import com.jero.modules.tag.entity.LawsTag;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -22,11 +23,15 @@ public interface ILawsCommonService {
|
|||||||
**/
|
**/
|
||||||
IPage<Map<String,Object>> getCommonPage(Map<String, Object> parameterMap);
|
IPage<Map<String,Object>> getCommonPage(Map<String, Object> parameterMap);
|
||||||
|
|
||||||
/**
|
IPage<Map<String, Object>> getExportData(Map<String, Object> parameterMap, List<LawsTag> headers);
|
||||||
* @Author: liao
|
|
||||||
* @Date: 2023/8/24 9:09
|
List<LawsTag> getExportHeader(Map<String, Object> parameterMap);
|
||||||
* @Description: 获取通用表头
|
|
||||||
**/
|
/**
|
||||||
|
* @Author: liao
|
||||||
|
* @Date: 2023/8/24 9:09
|
||||||
|
* @Description: 获取通用表头
|
||||||
|
**/
|
||||||
List<LawsTag> getCommonHeader(String module);
|
List<LawsTag> getCommonHeader(String module);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -98,4 +103,14 @@ public interface ILawsCommonService {
|
|||||||
* @Description: 根据标准编号查询简单标准
|
* @Description: 根据标准编号查询简单标准
|
||||||
**/
|
**/
|
||||||
ManyStandardSelectionBox getSingleStandard(String standardNumber);
|
ManyStandardSelectionBox getSingleStandard(String standardNumber);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 三标通用导出
|
||||||
|
*/
|
||||||
|
void commonExport(HttpServletResponse response, Map<String, Object> parameterMap, String sheetName, String fileName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 三表通用带文件导出
|
||||||
|
*/
|
||||||
|
void exportDataWithFile(HttpServletResponse response, Map<String, Object> parameterMap, String sheetName, String fileName);
|
||||||
}
|
}
|
||||||
|
|||||||
+165
@@ -1,5 +1,6 @@
|
|||||||
package com.jero.modules.laws.common.service.impl;
|
package com.jero.modules.laws.common.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
@@ -33,13 +34,20 @@ import com.jero.modules.tag.entity.LawsTag;
|
|||||||
import com.jero.modules.tag.enums.TableNameEnum;
|
import com.jero.modules.tag.enums.TableNameEnum;
|
||||||
import com.jero.modules.tag.enums.LawsFieldTypeEnum;
|
import com.jero.modules.tag.enums.LawsFieldTypeEnum;
|
||||||
import com.jero.modules.tag.service.ILawsAreaService;
|
import com.jero.modules.tag.service.ILawsAreaService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.apache.poi.ss.usermodel.Cell;
|
||||||
|
import org.apache.poi.ss.usermodel.Row;
|
||||||
|
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
||||||
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||||
import org.apache.shiro.SecurityUtils;
|
import org.apache.shiro.SecurityUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -50,6 +58,7 @@ import java.util.stream.Collectors;
|
|||||||
* @Date: 2023/8/23 16:54
|
* @Date: 2023/8/23 16:54
|
||||||
* @Description: 通用
|
* @Description: 通用
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
@Component
|
@Component
|
||||||
public class LawsCommonServiceImpl implements ILawsCommonService {
|
public class LawsCommonServiceImpl implements ILawsCommonService {
|
||||||
|
|
||||||
@@ -114,6 +123,72 @@ public class LawsCommonServiceImpl implements ILawsCommonService {
|
|||||||
return infoPage;
|
return infoPage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IPage<Map<String, Object>> getExportData(Map<String, Object> parameterMap, List<LawsTag> fieldList) {
|
||||||
|
// 获取操作模块
|
||||||
|
String module = (String) parameterMap.get(FieldCommon.MODULE);
|
||||||
|
|
||||||
|
// 获取要操作的表名
|
||||||
|
String tableName = TableNameEnum.getTableName(module);
|
||||||
|
|
||||||
|
// 封装查询显示的字段
|
||||||
|
String selectField = getSelectField(fieldList);
|
||||||
|
|
||||||
|
// 筛选出查询列表显示的字段(不传id查列表)
|
||||||
|
List<LawsTag> fieldListSelect = fieldList.stream().filter(lawsTag -> YesOrNoEnum.YES.getValue()
|
||||||
|
.equals(lawsTag.getIsShowList().toString())).collect(Collectors.toList());
|
||||||
|
// 筛选出用于查询的字段
|
||||||
|
List<LawsTag> fieldListCondition = fieldList.stream().filter(lawsTag -> YesOrNoEnum.YES.getValue()
|
||||||
|
.equals(lawsTag.getIsQuery().toString())).collect(Collectors.toList());
|
||||||
|
|
||||||
|
int pageNo = 1;
|
||||||
|
int pageSize = Integer.MAX_VALUE;
|
||||||
|
IPage<Map<String,Object>> page = new Page<>(pageNo, pageSize);
|
||||||
|
|
||||||
|
// 封装查询条件
|
||||||
|
String selectCondition = getSelectCondition(parameterMap, fieldListCondition);
|
||||||
|
String ids = (String)parameterMap.get(FieldCommon.IDS);
|
||||||
|
// 勾选导出
|
||||||
|
if (StrUtil.isNotBlank(ids)) {
|
||||||
|
List<String> list = Arrays.asList(ids.split(","));
|
||||||
|
selectCondition = selectCondition.replace("where"," and");
|
||||||
|
String sql = "where id in (";
|
||||||
|
StringBuilder sql2 = new StringBuilder();
|
||||||
|
list.forEach(id -> {
|
||||||
|
sql2.append("'").append(id).append("',");
|
||||||
|
});
|
||||||
|
sql2.deleteCharAt(sql2.length() - 1).append(")");
|
||||||
|
sql = sql + sql2;
|
||||||
|
selectCondition = sql + selectCondition;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取分页查询结果
|
||||||
|
IPage<Map<String, Object>> infoPage = lawsCommonMapper.getCommonPage(page, tableName, selectField, selectCondition);
|
||||||
|
// 对返回的数据做处理
|
||||||
|
// 做字段翻译和拼接
|
||||||
|
infoPage.setRecords(processResultMapPageList(infoPage.getRecords(), fieldListSelect));
|
||||||
|
// 待处理
|
||||||
|
return infoPage;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<LawsTag> getExportHeader(Map<String, Object> parameterMap) {
|
||||||
|
// 获取操作模块
|
||||||
|
String module = (String) parameterMap.get(FieldCommon.MODULE);
|
||||||
|
|
||||||
|
// 获取要操作的表名
|
||||||
|
String tableName = TableNameEnum.getTableName(module);
|
||||||
|
// 获取全部字段
|
||||||
|
List<LawsTag> fieldList = lawsCommonMapper.getFieldList(tableName);
|
||||||
|
// 筛选表单显示的字段(传id查表单)
|
||||||
|
// 详情显示
|
||||||
|
fieldList = fieldList.stream()
|
||||||
|
.filter(lawsTag -> YesOrNoEnum.YES.getValue().equals(lawsTag.getIsShowForm().toString()))
|
||||||
|
.filter(lawsTag -> !lawsTag.getFieldShowType().equals("8"))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
return fieldList;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author: liao
|
* @Author: liao
|
||||||
* @Date: 2023/9/11 14:49
|
* @Date: 2023/9/11 14:49
|
||||||
@@ -736,6 +811,96 @@ public class LawsCommonServiceImpl implements ILawsCommonService {
|
|||||||
return lawsCommonMapper.getSingleStandard(standardNumber);
|
return lawsCommonMapper.getSingleStandard(standardNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void commonExport(HttpServletResponse response, Map<String, Object> parameterMap, String sheetName, String fileName) {
|
||||||
|
try {
|
||||||
|
// 创建表头
|
||||||
|
List<LawsTag> headers = this.getExportHeader(parameterMap);
|
||||||
|
// 获取数据
|
||||||
|
IPage<Map<String, Object>> commonPage = this.getExportData(parameterMap, headers);
|
||||||
|
List<Map<String, Object>> records = commonPage.getRecords();
|
||||||
|
|
||||||
|
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||||
|
XSSFSheet sheet = workbook.createSheet(sheetName);
|
||||||
|
|
||||||
|
Row headerRow = sheet.createRow(0);
|
||||||
|
for (int i = 0; i < headers.size(); i++) {
|
||||||
|
Cell headerCell = headerRow.createCell(i);
|
||||||
|
headerCell.setCellValue(headers.get(i).getDbFieldTxt());
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < records.size(); i++) {
|
||||||
|
Map<String, Object> dataRowMap = records.get(i);
|
||||||
|
Row dataRow = sheet.createRow(i + 1); // +1因为第一行是表头
|
||||||
|
|
||||||
|
for (int j = 0; j < headers.size(); j++) {
|
||||||
|
Cell dataCell = dataRow.createCell(j);
|
||||||
|
Object value = dataRowMap.get(headers.get(j).getDbFieldName());
|
||||||
|
if (value != null) {
|
||||||
|
dataCell.setCellValue(value.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置响应头和内容类型
|
||||||
|
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||||
|
response.setHeader("Content-Disposition", "attachment; filename=" + fileName + ".xlsx");
|
||||||
|
|
||||||
|
// 写出到响应流
|
||||||
|
workbook.write(response.getOutputStream());
|
||||||
|
workbook.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("导出excel异常", e);
|
||||||
|
throw new JeroBootException("导出excel异常", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void exportDataWithFile(HttpServletResponse response, Map<String, Object> parameterMap, String sheetName, String fileName) {
|
||||||
|
try {
|
||||||
|
// 创建表头
|
||||||
|
List<LawsTag> headers = this.getExportHeader(parameterMap);
|
||||||
|
// 获取数据
|
||||||
|
IPage<Map<String, Object>> commonPage = this.getExportData(parameterMap, headers);
|
||||||
|
List<Map<String, Object>> records = commonPage.getRecords();
|
||||||
|
|
||||||
|
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||||
|
XSSFSheet sheet = workbook.createSheet(sheetName);
|
||||||
|
|
||||||
|
Row headerRow = sheet.createRow(0);
|
||||||
|
for (int i = 0; i < headers.size(); i++) {
|
||||||
|
Cell headerCell = headerRow.createCell(i);
|
||||||
|
headerCell.setCellValue(headers.get(i).getDbFieldTxt());
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < records.size(); i++) {
|
||||||
|
Map<String, Object> dataRowMap = records.get(i);
|
||||||
|
Row dataRow = sheet.createRow(i + 1); // +1因为第一行是表头
|
||||||
|
|
||||||
|
for (int j = 0; j < headers.size(); j++) {
|
||||||
|
Cell dataCell = dataRow.createCell(j);
|
||||||
|
Object value = dataRowMap.get(headers.get(j).getDbFieldName());
|
||||||
|
if (value != null) {
|
||||||
|
dataCell.setCellValue(value.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置响应头和内容类型
|
||||||
|
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||||
|
response.setHeader("Content-Disposition", "attachment; filename=" + fileName + ".xlsx");
|
||||||
|
|
||||||
|
// 写出到响应流
|
||||||
|
workbook.write(response.getOutputStream());
|
||||||
|
workbook.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("导出excel异常", e);
|
||||||
|
throw new JeroBootException("导出excel异常", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author: liao
|
* @Author: liao
|
||||||
* @Date: 2023/8/24 9:53
|
* @Date: 2023/8/24 9:53
|
||||||
|
|||||||
+24
-1
@@ -1,5 +1,6 @@
|
|||||||
package com.jero.modules.laws.standard.controller;
|
package com.jero.modules.laws.standard.controller;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.jero.common.api.vo.Result;
|
import com.jero.common.api.vo.Result;
|
||||||
@@ -8,9 +9,9 @@ import com.jero.common.util.MessageUtils;
|
|||||||
import com.jero.modules.laws.common.constant.FieldCommon;
|
import com.jero.modules.laws.common.constant.FieldCommon;
|
||||||
import com.jero.modules.laws.common.constant.ResultCommon;
|
import com.jero.modules.laws.common.constant.ResultCommon;
|
||||||
import com.jero.modules.laws.common.service.ILawsCommonService;
|
import com.jero.modules.laws.common.service.ILawsCommonService;
|
||||||
import com.jero.modules.laws.enterprise.entity.EnterpriseStandardAuthDept;
|
|
||||||
import com.jero.modules.laws.enterprise.service.EnterpriseStandardAuthDeptService;
|
import com.jero.modules.laws.enterprise.service.EnterpriseStandardAuthDeptService;
|
||||||
import com.jero.modules.laws.enterprise.service.EnterpriseStandardAuthUserService;
|
import com.jero.modules.laws.enterprise.service.EnterpriseStandardAuthUserService;
|
||||||
|
import com.jero.modules.laws.standard.entity.LawsEnterpriseStandard;
|
||||||
import com.jero.modules.laws.standard.entity.LawsUpdateRecord;
|
import com.jero.modules.laws.standard.entity.LawsUpdateRecord;
|
||||||
import com.jero.modules.laws.standard.entity.StandardTempPermission;
|
import com.jero.modules.laws.standard.entity.StandardTempPermission;
|
||||||
import com.jero.modules.laws.standard.service.ILawsNodeRelationService;
|
import com.jero.modules.laws.standard.service.ILawsNodeRelationService;
|
||||||
@@ -21,10 +22,20 @@ import com.jero.modules.tag.entity.LawsTag;
|
|||||||
import com.jero.modules.tag.enums.TableNameEnum;
|
import com.jero.modules.tag.enums.TableNameEnum;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import org.apache.poi.ss.usermodel.Cell;
|
||||||
|
import org.apache.poi.ss.usermodel.Row;
|
||||||
|
import org.apache.poi.ss.usermodel.Sheet;
|
||||||
|
import org.apache.poi.ss.usermodel.Workbook;
|
||||||
|
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
||||||
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||||
|
import org.jeecgframework.poi.excel.ExcelExportUtil;
|
||||||
|
import org.jeecgframework.poi.excel.entity.ExportParams;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@@ -174,5 +185,17 @@ public class LawsEnterpriseController {
|
|||||||
return Result.OK();
|
return Result.OK();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@AutoLog(value = "企业法规标准-导出")
|
||||||
|
@ApiOperation(value="企业法规标准-导出", notes="企业法规标准-导出")
|
||||||
|
@PostMapping("/exportData")
|
||||||
|
public void exportData(HttpServletResponse response, @RequestBody Map<String,Object> parameterMap) {
|
||||||
|
lawsCommonService.commonExport(response, parameterMap, "企标导出", "企标导出");
|
||||||
|
}
|
||||||
|
|
||||||
|
@AutoLog(value = "企业法规标准-带文件导出")
|
||||||
|
@ApiOperation(value="企业法规标准-带文件导出", notes="企业法规标准-带文件导出")
|
||||||
|
@PostMapping("/exportDataWithFile")
|
||||||
|
public void exportDataWithFile(HttpServletResponse response, @RequestBody Map<String,Object> parameterMap) {
|
||||||
|
lawsCommonService.exportDataWithFile(response, parameterMap, "企标导出", "企标导出");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user