feat: 法规复合型评估库-导出

This commit is contained in:
2024-06-29 07:36:52 +08:00
parent 64cee85a9c
commit e5982e9289
9 changed files with 402 additions and 23 deletions
@@ -6,6 +6,7 @@ import com.jero.common.api.vo.Result;
import com.jero.common.aspect.annotation.AutoLog;
import com.jero.modules.assessmentLibrary.entity.LawsConformityAssessmentLibrary;
import com.jero.modules.assessmentLibrary.entity.LawsConformityAssessmentLibraryDetail;
import com.jero.modules.assessmentLibrary.entity.LawsEvaluationNotMetLibrary;
import com.jero.modules.assessmentLibrary.service.ILawsConformityAssessmentLibraryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@@ -17,6 +18,8 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@Api(tags = "法规符合性评估库-法规符合性评估库")
@RestController
@@ -58,7 +61,7 @@ public class LawsConformityAssessmentController {
@AutoLog(value = "法规符合性评估库-法规符合性评估库-查看")
@ApiOperation(value = "法规符合性评估库-法规符合性评估库-查看", notes = "法规符合性评估库-法规符合性评估库-查看")
@GetMapping(value = "/detail")
@ApiOperationSupport(order = 1)
@ApiOperationSupport(order = 2)
@RequiresPermissions("lawsConformityAssessment:detail")
public Result<IPage<LawsConformityAssessmentLibraryDetail>> detail(LawsConformityAssessmentLibraryDetail lawsConformityAssessmentLibraryDetail,
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
@@ -68,4 +71,15 @@ public class LawsConformityAssessmentController {
return Result.OK(pageList);
}
/**
* 导出excel
*/
@AutoLog(value = "法规符合性评估库-法规符合性评估库-导出")
@ApiOperation(value="法规符合性评估库-法规符合性评估库-导出", notes="法规符合性评估库-法规符合性评估库-导出")
@RequiresPermissions("lawsConformityAssessment:export")
@GetMapping(value = "/exportXls", produces = "application/zip")
public void exportXls(HttpServletResponse response, LawsConformityAssessmentLibrary lawsConformityAssessmentLibrary, HttpServletRequest req) {
lawsConformityAssessmentLibraryService.export(response, lawsConformityAssessmentLibrary, "法规符合性评估库", "法规符合性评估库", req);
}
}
@@ -32,7 +32,7 @@ import java.util.List;
* @Date: 2023-09-11
* @Version: V1.0
*/
@Api(tags="不符合项")
@Api(tags="法规符合性评估库-不符合项")
@RestController
@RequestMapping("/assessment/lawsEvaluationNotMet")
@Slf4j
@@ -44,8 +44,8 @@ public class LawsEvaluationNotMetController extends JeroController<LawsEvaluatio
/**
* 分页列表查询
*/
@AutoLog(value = "不符合项-分页列表查询")
@ApiOperation(value="不符合项-分页列表查询", notes="不符合项-分页列表查询")
@AutoLog(value = "法规符合性评估库-不符合项-分页列表查询")
@ApiOperation(value="法规符合性评估库-不符合项-分页列表查询", notes="法规符合性评估库-不符合项-分页列表查询")
@GetMapping(value = "/page")
@RequiresPermissions("lawsEvaluationNotMet:search")
public Result<IPage<LawsEvaluationNotMetLibrary>> queryPageList(@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
@@ -59,8 +59,8 @@ public class LawsEvaluationNotMetController extends JeroController<LawsEvaluatio
* 批量关闭
*/
@RequiresPermissions("lawsEvaluationNotMet:batchClose")
@AutoLog(value = "不符合项-批量关闭")
@ApiOperation(value="不符合项-批量关闭", notes="库-批量关闭")
@AutoLog(value = "法规符合性评估库-不符合项-批量关闭")
@ApiOperation(value="法规符合性评估库-不符合项-批量关闭", notes="法规符合性评估库-不符合项库-批量关闭")
@PostMapping(value = "/batchClose")
public Result<T> batchClose(@RequestBody LawsEvaluationNotMetLibrary lawsEvaluationNotMet) {
String ids = lawsEvaluationNotMet.getIds();
@@ -91,8 +91,8 @@ public class LawsEvaluationNotMetController extends JeroController<LawsEvaluatio
/**
* 导出excel
*/
@AutoLog(value = "不符合项-导出")
@ApiOperation(value="不符合项-导出", notes="库-导出")
@AutoLog(value = "法规符合性评估库-不符合项-导出")
@ApiOperation(value="法规符合性评估库-不符合项-导出", notes="法规符合性评估库-不符合项库-导出")
@RequiresPermissions("lawsEvaluationNotMet:export")
@GetMapping(value = "/exportXls")
public void exportXls(HttpServletResponse response, LawsEvaluationNotMetLibrary lawsEvaluationNotMet, HttpServletRequest req) {
@@ -0,0 +1,166 @@
package com.jero.modules.assessmentLibrary.entity.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.jero.common.aspect.annotation.Dict;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.jeecgframework.poi.excel.annotation.Excel;
import org.jeecgframework.poi.excel.annotation.ExcelCollection;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
import java.util.Collections;
import java.util.Date;
import java.util.List;
@Data
public class LawsConformityAssessmentLibraryExportVO implements Serializable {
/**
* 标准编号
*/
@Excel(name = "标准编号")
@ApiModelProperty(value = "标准编号")
private String standardNumber;
/**
* 标准名称
*/
@Excel(name = "标准名称")
@ApiModelProperty(value = "标准名称")
private String standardName;
/**
* 适用市场
*/
@Excel(name = "适用市场", dicCode = "market_state")
@ApiModelProperty(value = "适用市场")
@Dict(dicCode = "market_state")
private String applicableMarket;
/**
* 评估日期
*/
@Excel(name = "评估日期", format = "yyyy-MM-dd")
@ApiModelProperty(value = "评估日期")
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
@DateTimeFormat(pattern="yyyy-MM-dd")
private Date valuationTime;
/**
* 条款号
*/
@Excel(name = "条款号")
@ApiModelProperty(value = "条款号")
private String termNumber;
/**
* 条款内容
*/
@Excel(name = "条款内容")
@ApiModelProperty(value = "条款内容")
private String termContent;
/**
* 车型
*/
@Excel(name = "车型")
@ApiModelProperty(value = "车型")
private String model;
/**
* 车型状态
*/
@Excel(name = "车型状态", dicCode = "model_status")
@ApiModelProperty(value = "车型状态")
@Dict(dicCode = "model_status")
private String modelStatus;
/**
* 责任部门
*/
@Excel(name = "责任部门", dictTable = "sys_depart", dicCode = "id", dicText = "depart_name")
@ApiModelProperty(value = "责任部门")
@Dict(dictTable = "sys_depart", dicCode = "id", dicText = "depart_name")
private String authDept;
/**
* 评估人
*/
@Excel(name = "评估人", dictTable = "sys_user", dicCode = "id", dicText = "CONCAT(realname, '(', username, ')')")
@ApiModelProperty(value = "评估人")
@Dict(dictTable = "sys_user", dicCode = "id", dicText = "realname")
private String assessor;
/**
* 评估结果
*/
@Excel(name = "评估结果")
@ApiModelProperty(value = "评估结果")
private String result;
/**
* 不满足要求的现状
*/
@Excel(name = "不满足要求的现状")
@ApiModelProperty(value = "不满足要求的现状")
private String unsatisfiedRequire;
/**
* 整改方案
*/
@Excel(name = "整改方案")
@ApiModelProperty(value = "整改方案")
private String correctionSolution;
/**
* 整改周期
*/
@Excel(name = "整改周期", dicCode = "correction_period")
@ApiModelProperty(value = "整改周期")
@Dict(dicCode = "correction_period")
private String correctionPeriod;
/**
* 整改费用
*/
@Excel(name = "整改费用")
@ApiModelProperty(value = "整改费用")
private String correctionCost;
/**
* 与其他项目共用性
*/
@Excel(name = "与其他项目共用性")
@ApiModelProperty(value = "与其他项目共用性")
private String commonality;
/**
* 共用后本项目所需费用
*/
@Excel(name = "共用后本项目所需费用")
@ApiModelProperty(value = "共用后本项目所需费用")
private String commonalityCost;
/**
* 备注
*/
@Excel(name = "备注")
@ApiModelProperty(value = "备注")
private String remark;
/**
* 佐证材料
*/
@ApiModelProperty(value = "佐证材料")
private String material;
/**
* 佐证材料
*/
@ExcelCollection(name = "佐证材料")
@ApiModelProperty(value = "佐证材料")
private List<MaterialFile> materialFileList = Collections.emptyList();
}
@@ -0,0 +1,15 @@
package com.jero.modules.assessmentLibrary.entity.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.jeecgframework.poi.excel.annotation.Excel;
@Data
public class MaterialFile {
@ApiModelProperty(value = "id")
private String id;
@Excel(name = "佐证材料", width = 15)
@ApiModelProperty(value = "佐证材料")
private String fileName;
}
@@ -4,6 +4,10 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.jero.modules.assessmentLibrary.entity.LawsConformityAssessmentLibrary;
import com.baomidou.mybatisplus.extension.service.IService;
import com.jero.modules.assessmentLibrary.entity.LawsConformityAssessmentLibraryDetail;
import com.jero.modules.assessmentLibrary.entity.LawsEvaluationNotMetLibrary;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* @author ThinkBook
@@ -19,7 +23,8 @@ public interface ILawsConformityAssessmentLibraryService extends IService<LawsCo
* @param pageSize
* @return
*/
IPage<LawsConformityAssessmentLibrary> queryPage(LawsConformityAssessmentLibrary lawsConformityAssessmentLibrary, Integer pageNo, Integer pageSize);
IPage<LawsConformityAssessmentLibrary> queryPage(LawsConformityAssessmentLibrary lawsConformityAssessmentLibrary,
Integer pageNo, Integer pageSize);
/**
* 查看 分页列表
@@ -28,5 +33,14 @@ public interface ILawsConformityAssessmentLibraryService extends IService<LawsCo
* @param pageSize
* @return
*/
IPage<LawsConformityAssessmentLibraryDetail> detail(LawsConformityAssessmentLibraryDetail lawsConformityAssessmentLibraryDetail, Integer pageNo, Integer pageSize);
IPage<LawsConformityAssessmentLibraryDetail> detail(LawsConformityAssessmentLibraryDetail lawsConformityAssessmentLibraryDetail,
Integer pageNo, Integer pageSize);
/**
* 导出
* @param lawsConformityAssessmentLibrary
* @return
*/
void export(HttpServletResponse response, LawsConformityAssessmentLibrary lawsConformityAssessmentLibrary,
String fileName, String sheetName, HttpServletRequest req);
}
@@ -39,5 +39,6 @@ public interface ILawsEvaluationNotMetLibraryService extends IService<LawsEvalua
* @param fileName
* @param sheetName
*/
void export(HttpServletResponse response, LawsEvaluationNotMetLibrary lawsEvaluationNotMet, String fileName, String sheetName, HttpServletRequest req);
void export(HttpServletResponse response, LawsEvaluationNotMetLibrary lawsEvaluationNotMet, String fileName,
String sheetName, HttpServletRequest req);
}
@@ -1,34 +1,67 @@
package com.jero.modules.assessmentLibrary.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jero.common.exception.JeroBootException;
import com.jero.common.util.FileUtils;
import com.jero.common.util.MinioUtil;
import com.jero.common.util.ZipUtil;
import com.jero.modules.assessmentLibrary.entity.LawsConformityAssessmentLibrary;
import com.jero.modules.assessmentLibrary.entity.LawsConformityAssessmentLibraryDetail;
import com.jero.modules.assessmentLibrary.entity.vo.LawsConformityAssessmentLibraryExportVO;
import com.jero.modules.assessmentLibrary.entity.vo.MaterialFile;
import com.jero.modules.assessmentLibrary.service.ILawsConformityAssessmentLibraryService;
import com.jero.modules.assessmentLibrary.mapper.LawsConformityAssessmentLibraryMapper;
import com.jero.modules.laws.enterprise.entity.vo.DeclareFileList;
import com.jero.modules.laws.enterprise.entity.vo.EnterpriseStandardDeclareExcel;
import com.jero.modules.laws.enterprise.util.BeanCopyUtils;
import com.jero.modules.oss.entity.OSSFile;
import com.jero.modules.oss.service.IOSSFileService;
import com.jero.modules.system.util.SysWaterMarkUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.*;
import org.jeecgframework.poi.excel.ExcelExportUtil;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.enmus.ExcelType;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import static com.jero.modules.laws.common.constant.FieldCommon.STANDARD_NAME;
import static com.jero.modules.laws.common.constant.FieldCommon.STANDARD_NUMBER;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author ThinkBook
* @description 针对表【laws_conformity_assessment_library(法规符合性评估库)】的数据库操作Service实现
* @createDate 2024-06-24 14:47:19
*/
* @author ThinkBook
* @description 针对表【laws_conformity_assessment_library(法规符合性评估库)】的数据库操作Service实现
* @createDate 2024-06-24 14:47:19
*/
@Service
@Slf4j
public class LawsConformityAssessmentLibraryServiceImpl extends ServiceImpl<LawsConformityAssessmentLibraryMapper, LawsConformityAssessmentLibrary>
implements ILawsConformityAssessmentLibraryService {
implements ILawsConformityAssessmentLibraryService {
@Value("${jero.path.exportExcelTempPath}")
private String exportExcelTempPath;
@Resource
private IOSSFileService ossFileService;
private static final String EXPORT_EXCEL_TEMP = "exportExcelTemp";
@Resource
private SysWaterMarkUtil sysWaterMarkUtil;
@Resource
private LawsConformityAssessmentLibraryMapper lawsConformityAssessmentLibraryMapper;
@@ -71,6 +104,141 @@ public class LawsConformityAssessmentLibraryServiceImpl extends ServiceImpl<Laws
"CONCAT(u.realname, '(', u.username, ')')", lawsConformityAssessmentLibraryDetail.getAssessor());
return lawsConformityAssessmentLibraryMapper.detail(page, queryWrapper);
}
@Override
public void export(HttpServletResponse response, LawsConformityAssessmentLibrary lawsConformityAssessmentLibrary, String fileName, String sheetName, HttpServletRequest req) {
String url = exportExcelTempPath.replace(EXPORT_EXCEL_TEMP, fileName);
File file = new File(url);
if (!file.exists()) {
boolean mkdirs = file.mkdirs();
log.info("创建临时目录:{}", mkdirs);
}
try (FileOutputStream fos = new FileOutputStream(url + File.separator + fileName + ".xls")){
// 获取数据
IPage<LawsConformityAssessmentLibrary> data = this.queryPage(lawsConformityAssessmentLibrary, 1, Integer.MAX_VALUE);
List<LawsConformityAssessmentLibrary> records = data.getRecords();
// 找到每条数据的详细信息
Map<String, List<LawsConformityAssessmentLibraryDetail>> allDetailMap = new HashMap<>();
LawsConformityAssessmentLibraryDetail condition = new LawsConformityAssessmentLibraryDetail();
records.forEach(item -> {
condition.setBindId(item.getId());
IPage<LawsConformityAssessmentLibraryDetail> detail = this.detail(condition, 1, Integer.MAX_VALUE);
allDetailMap.put(item.getId(), detail.getRecords());
});
// 组合成导出数据
List<LawsConformityAssessmentLibraryExportVO> recordsExport = new ArrayList<>();
records.forEach(item -> {
List<LawsConformityAssessmentLibraryDetail> lawsConformityAssessmentLibraryDetails = allDetailMap.get(item.getId());
List<LawsConformityAssessmentLibraryExportVO> vos = BeanCopyUtils.copyBeanList(lawsConformityAssessmentLibraryDetails, LawsConformityAssessmentLibraryExportVO.class);
vos.forEach(e -> {
e.setStandardNumber(item.getStandardNumber());
e.setStandardName(item.getStandardName());
e.setApplicableMarket(item.getApplicableMarket());
e.setValuationTime(item.getValuationTime());
});
recordsExport.addAll(vos);
});
this.settleDocuments(url, recordsExport);
// 生成excel
ExportParams exportParams = new ExportParams();
exportParams.setType(ExcelType.HSSF);
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, LawsConformityAssessmentLibraryExportVO.class, recordsExport);
// 生成超链接
generateHyperlink(recordsExport, workbook);
// 导出excel
workbook.write(fos);
// 生成并导出zip
ZipUtil.toZip(url, response.getOutputStream(), response, true);
} catch (Exception e) {
log.error("导出excel异常", e);
throw new JeroBootException("导出excel异常", e);
} finally {
// 删除文件
if (new File(url).exists()) {
FileUtils.deleteFolders(url);
}
}
}
private static void generateHyperlink(List<LawsConformityAssessmentLibraryExportVO> vos, Workbook workbook) {
Sheet sheet = workbook.getSheetAt(0);
// 设置字体颜色、下划线
CellStyle cellStyle = workbook.createCellStyle();
Font font = workbook.createFont();
font.setColor(IndexedColors.BLUE.getIndex());
font.setUnderline(Font.U_SINGLE);
cellStyle.setFont(font);
cellStyle.setWrapText(true);
int i = 1;
for (LawsConformityAssessmentLibraryExportVO vo : vos) {
if (!Objects.isNull(vo.getMaterial()) && !vo.getMaterialFileList().isEmpty()) {
for (MaterialFile materialFile : vo.getMaterialFileList()) {
Row row = sheet.getRow(i);
Cell cell = row.getCell(6);
// 设置超链接 HYPERLINK("https://www.baidu.com", "百度")
cell.setCellFormula("HYPERLINK(\"" + materialFile.getFileName() + "\", \"" + materialFile.getFileName() + "\")");
cell.setCellStyle(cellStyle);
i += 1;
}
} else {
i += 1;
}
}
}
private void settleDocuments(String url, List<LawsConformityAssessmentLibraryExportVO> excelVos) throws
IOException {
for (LawsConformityAssessmentLibraryExportVO vo : excelVos) {
// 查询文件
if (StringUtils.isNotBlank(vo.getMaterial())) {
List<String> fileIdList = Arrays.asList(vo.getMaterial().split(","));
List<OSSFile> ossFileList = ossFileService.listByIds(fileIdList);
if (!ossFileList.isEmpty()) {
// 赋值
List<MaterialFile> materialFileList = com.jero.common.util.BeanCopyUtils.copyBeanList(ossFileList, MaterialFile.class);
vo.setMaterialFileList(materialFileList);
// 写出文件
for (OSSFile ossFile : ossFileList) {
InputStream inputStream = MinioUtil.getMinioFile(MinioUtil.getBucketName(), ossFile.getUrl());
// pdf加水印
if (StringUtils.endsWithIgnoreCase(ossFile.getFileName(), ".pdf")) {
inputStream = sysWaterMarkUtil.addWatermarkToPdf(inputStream);
}
// 导出文件
String filePath = url + File.separator + ossFile.getFileName();
writeToLocal(filePath, inputStream);
}
}
}
}
}
/**
* 将InputStream写入本地文件
*
* @param filePath
* @param input
* @throws IOException
*/
public void writeToLocal(String filePath, InputStream input)
throws IOException {
int index;
byte[] bytes = new byte[1024];
try (FileOutputStream downloadFile = new FileOutputStream(filePath)) {
while ((index = input.read(bytes)) != -1) {
downloadFile.write(bytes, 0, index);
downloadFile.flush();
}
} catch (Exception e) {
log.error("将InputStream写入本地失败:{}", e.getMessage());
} finally {
input.close();
}
}
}
@@ -79,7 +79,8 @@ public class LawsEvaluationNotMetLibraryServiceImpl extends ServiceImpl<LawsEval
}
@Override
public void export(HttpServletResponse response, LawsEvaluationNotMetLibrary lawsEvaluationNotMet, String fileName, String sheetName, HttpServletRequest req) {
public void export(HttpServletResponse response, LawsEvaluationNotMetLibrary lawsEvaluationNotMet, String fileName,
String sheetName, HttpServletRequest req) {
try {
// 获取数据
IPage<LawsEvaluationNotMetLibrary> lawsEvaluationNotMets = this.queryPage(lawsEvaluationNotMet, 1, Integer.MAX_VALUE, req);
@@ -57,7 +57,7 @@ public class LawsDomesticStandard implements Serializable {
@ApiModelProperty(value = "0表示未删除,1表示删除")
@TableLogic
private java.lang.Integer delFlag;
/**标准性质*/
/**类型*/
@Excel(name = "类型", width = 15)
@ApiModelProperty(value = "类型")
private java.lang.String type;