认证-参数项模板下载,导出

This commit is contained in:
liyawei
2022-04-27 11:36:35 +08:00
parent 15047882ac
commit 51a66483a0
13 changed files with 805 additions and 31 deletions
@@ -1,12 +1,14 @@
package com.jero.modules.cert.template.controller;
import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jero.common.api.vo.Result;
import com.jero.common.aspect.annotation.AutoLog;
import com.jero.common.system.base.controller.JeroController;
import com.jero.modules.cert.template.vo.ParamsInfoVO;
import com.jero.modules.cert.template.entity.ParamsInfoEO;
import com.jero.modules.cert.template.service.IParamsInfoEOService;
import io.swagger.annotations.Api;
@@ -16,7 +18,6 @@ import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -24,7 +25,7 @@ import java.util.Arrays;
import java.util.List;
/**
/**
* @Description: 参数项基本信息表
* @Author: jero-boot
* @Date: 2022-04-22
@@ -176,15 +177,33 @@ public class ParamsInfoEOController extends JeroController<ParamsInfoEO, IParams
return Result.OK(paramsInfoEO);
}
@AutoLog(value = "参数项基本信息表-模板下载")
@ApiOperation(value = "参数项基本信息表-模板下载", notes="参数项基本信息表-模板下载")
@GetMapping(value = "/exportTemplate")
public void exportTemplate(@RequestParam(name = "cut") String cut,
@RequestParam(name = "templateName", required = false) String templateName,
HttpServletResponse response,
HttpServletRequest request) throws Exception {
paramsInfoEOService.exportTemplate(cut,templateName,response,request);
}
/**
* 导出excel
*
* @param request
* @param paramsInfoEO
* @param parameter
*/
@RequestMapping(value = "/exportXls")
public ModelAndView exportXls(HttpServletRequest request, ParamsInfoEO paramsInfoEO) {
return super.exportXls(request, paramsInfoEO, ParamsInfoEO.class, "参数项基本信息表");
@RequestMapping(value = "/exportParamsInfoZip")
public void exportParamsInfoZip(@RequestParam(value = "cut") String cut,
@RequestParam(value = "exportName", required = false) String exportName,
@RequestParam(value = "paramsInfoVO", required = false) String parameter,
HttpServletResponse response,
HttpServletRequest request) {
ParamsInfoVO paramsInfoVO = new ParamsInfoVO();
if (StringUtils.isNotBlank(parameter)) {
paramsInfoVO = JSONObject.parseObject(parameter, ParamsInfoVO.class);
}
paramsInfoEOService.exportParamsInfo(cut, paramsInfoVO, exportName, response, request);
}
/**
@@ -59,32 +59,30 @@ public class CertCategoryParamsInfoEO implements Serializable {
private String sysOrgCode;
/**编号*/
@Excel(name = "编号", width = 15)
@Excel(name = "*编号", width = 15, orderNum = "2")
@ApiModelProperty(value = "编号")
private String paramsNumber;
/**参数名称*/
@Excel(name = "参数名称", width = 15)
@Excel(name = "*参数名称", width = 15, orderNum = "3")
@ApiModelProperty(value = "参数名称")
private String paramsName;
/**参数说明*/
@Excel(name = "参数说明", width = 15)
@Excel(name = "参数说明", width = 36, orderNum = "4")
@ApiModelProperty(value = "参数说明")
private String description;
/**nio编号*/
@Excel(name = "nio编号", width = 15)
@Excel(name = "*nio编号", width = 15, orderNum = "1")
@ApiModelProperty(value = "nio编号")
private String nioNumber;
/**所属认证类别*/
@Excel(name = "所属认证类别", width = 15)
@ApiModelProperty(value = "所属认证类别")
private String certCategory;
/**参数模板id*/
@Excel(name = "参数模板id", width = 15)
@ApiModelProperty(value = "参数模板id")
private String paramsTemplateId;
@@ -62,71 +62,73 @@ public class ParamsInfoEO implements Serializable {
private String sysOrgCode;
/**nio编号*/
@Excel(name = "nio编号", width = 15)
@Excel(name = "*nio编号", width = 15)
@ApiModelProperty(value = "nio编号")
private String nioNumber;
/**是否必填*/
@Excel(name = "是否必填", width = 15)
@Excel(name = "*是否必填", width = 15, replace = {"是_1","否_0"})
@ApiModelProperty(value = "是否必填")
private String isMust;
/**参数名称*/
@Excel(name = "参数名称", width = 15)
@Excel(name = "*参数名称", width = 15)
@ApiModelProperty(value = "参数名称")
private String paramsName;
/**技术领域*/
@Excel(name = "技术领域", width = 15)
@Excel(name = "*技术领域", width = 15, dicCode = "technology_territory")
@Dict(dicCode = "technology_territory")
@ApiModelProperty(value = "技术领域")
private String technologyTerritory;
/**参数批次*/
@Excel(name = "参数批次", width = 15)
@Excel(name = "*参数批次", width = 15, dicCode = "params_batch")
@Dict(dicCode = "params_batch")
@ApiModelProperty(value = "参数批次")
private String paramsBatch;
/**责任领域*/
@Excel(name = "责任领域", width = 15)
@Excel(name = "*责任领域", width = 15, dicCode = "duty_territory")
@Dict(dicCode = "duty_territory")
@ApiModelProperty(value = "责任领域")
private String dutyTerritory;
/**参数说明*/
@Excel(name = "参数说明", width = 15)
@Excel(name = "参数说明", width = 36)
@ApiModelProperty(value = "参数说明")
private String description;
/**认证类别*/
@Excel(name = "认证类别", width = 15)
@Excel(name = "认证类别", width = 15, dicCode = "cert_category")
@Dict(dicCode = "cert_category")
@ApiModelProperty(value = "认证类别")
private String certCategory;
/**控件类型*/
@Excel(name = "控件类型", width = 15)
@Excel(name = "*控件类型", width = 15, replace = {"文本_1","下拉单选_2","下拉多选_3","附件_4","文本+下拉单选_5","文本+下拉多选_6","文本+附件_7","下拉单选+附件_8","下拉多选+附件_9","文本+下拉单选+附件_10"})
@ApiModelProperty(value = "控件类型")
private String controlType;
/**控件备选值*/
@Excel(name = "控件备选值", width = 15)
@ApiModelProperty(value = "控件备选值")
private String controlValues;
/**控件校验*/
@Excel(name = "控件校验", width = 15)
@Excel(name = "控件校验", width = 15, replace = {"无_1","中文_2","正整数_3","正浮点数_4","整数或小数_5","一位小数_6","两位小数_7","三位小数_8","四位小数_9"})
@ApiModelProperty(value = "控件校验")
private String controlVerify;
/**控件备选值*/
@Excel(name = "控件备选值", width = 15)
@ApiModelProperty(value = "控件备选值")
private String controlValues;
/**附件模板*/
@Excel(name = "附件模板", width = 15)
@ApiModelProperty(value = "附件模板")
private String fileTemplateConnectId;
@Excel(name = "附件模板", width = 15)
@TableField(exist = false)
private String fileTemplateName; //附件模板文件名
/**参数模板id*/
@Excel(name = "参数模板id", width = 15)
@ApiModelProperty(value = "参数模板id")
private String paramsTemplateId;
@@ -14,6 +14,11 @@ import java.util.List;
*/
public interface CertCategoryParamsInfoEOMapper extends BaseMapper<CertCategoryParamsInfoEO> {
/***
* 根据多个nio编号查询
* @param nioNumber
* @return
*/
List<CertCategoryParamsInfoEO> selectListByNioNumber(@Param("nioNumber") String nioNumber);
int deleteByNioNumberList(@Param("list") List<String> nioNumberList);
@@ -1,7 +1,11 @@
package com.jero.modules.cert.template.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jero.modules.cert.template.vo.ParamsInfoVO;
import com.jero.modules.cert.template.entity.ParamsInfoEO;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* @Description: 参数项基本信息表
@@ -11,4 +15,5 @@ import com.jero.modules.cert.template.entity.ParamsInfoEO;
*/
public interface ParamsInfoEOMapper extends BaseMapper<ParamsInfoEO> {
List<ParamsInfoEO> selectListWithCert(@Param("paramsInfoVO") ParamsInfoVO paramsInfoVO);
}
@@ -19,7 +19,10 @@
<select id="selectListByNioNumber" resultMap="CertCategoryParamsInfoEOResultMap" parameterType="java.lang.String">
select *
from cert_category_params_info
where nio_number = #{nioNumber}
where nio_number in
<foreach collection="nioNumber.split(',')" index="index" separator="," open="(" close=")" item="item">
#{item}
</foreach>
</select>
<delete id="deleteByNioNumberList" parameterType="java.util.List">
@@ -22,4 +22,94 @@
<result column="file_template_connect_id" property="fileTemplateConnectId" />
<result column="params_template_id" property="paramsTemplateId" />
</resultMap>
<resultMap id="ParamsInfoEOResultMapWithCert" type="com.jero.modules.cert.template.entity.ParamsInfoEO">
<id column="id" property="id" />
<result column="create_by" property="createBy" />
<result column="create_time" property="createTime" />
<result column="update_by" property="updateBy" />
<result column="update_time" property="updateTime" />
<result column="sys_org_code" property="sysOrgCode" />
<result column="nio_number" property="nioNumber" />
<result column="is_must" property="isMust" />
<result column="params_name" property="paramsName" />
<result column="technology_territory" property="technologyTerritory" />
<result column="params_batch" property="paramsBatch" />
<result column="duty_territory" property="dutyTerritory" />
<result column="description" property="description" />
<result column="cert_category" property="certCategory" />
<result column="control_type" property="controlType" />
<result column="control_values" property="controlValues" />
<result column="control_verify" property="controlVerify" />
<result column="file_template_connect_id" property="fileTemplateConnectId" />
<result column="params_template_id" property="paramsTemplateId" />
<collection property="certCategoryParamsInfoEOList" javaType="java.util.List" ofType="com.jero.modules.cert.template.entity.CertCategoryParamsInfoEO">
<id column="ccpi_id" property="id" />
<result column="ccpi_params_number" property="paramsNumber" />
<result column="ccpi_params_name" property="paramsName" />
<result column="ccpi_description" property="description" />
<result column="ccpi_nio_number" property="nioNumber" />
<result column="ccpi_cert_category" property="certCategory" />
<result column="ccpi_params_template_id" property="paramsTemplateId" />
</collection>
</resultMap>
<sql id="BaseColumnList">
pi.id as id,
pi.create_by as create_by,
pi.create_time as create_time,
pi.update_by as update_by,
pi.update_time as update_time,
pi.sys_org_code as sys_org_code,
pi.nio_number as nio_number,
pi.is_must as is_must,
pi.params_name as params_name,
pi.technology_territory as technology_territory,
pi.params_batch as params_batch ,
pi.duty_territory as duty_territory,
pi.description as description,
pi.cert_category as cert_category,
pi.control_type as control_type,
pi.control_values as control_values,
pi.control_verify as control_verify,
pi.file_template_connect_id as file_template_connect_id,
pi.params_template_id as params_template_id,
ccpi.id as ccpi_id,
ccpi.params_number as ccpi_params_number,
ccpi.params_name as ccpi_params_name,
ccpi.description as ccpi_description,
ccpi.nio_number as ccpi_nio_number,
ccpi.cert_category as ccpi_cert_category,
ccpi.params_template_id as ccpi_params_template_id
</sql>
<sql id="BaseQuerySql">
<where>
<if test="paramsInfoVO != null">
<if test="paramsInfoVO.nioNumber !=null and paramsInfoVO.nioNumber !=''">
AND nio_number LIKE CONCAT(CONCAT('%',#{paramsInfoVO.nioNumber}),'%')
</if>
<if test="paramsInfoVO.paramsName !=null and paramsInfoVO.paramsName !=''">
AND params_name LIKE CONCAT(CONCAT('%',#{paramsInfoVO.paramsName}),'%')
</if>
<if test="paramsInfoVO.ids !=null and paramsInfoVO.ids !=''">
and id in
<foreach collection="paramsInfoVO.ids.split(',')" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
</if>
</where>
</sql>
<select id="selectListWithCert" resultMap="ParamsInfoEOResultMapWithCert" parameterType="com.jero.modules.cert.template.vo.ParamsInfoVO">
select tmp_tb.* from(
select
<include refid="BaseColumnList"/>
from params_info pi
left join cert_category_params_info ccpi on pi.nio_number = ccpi.nio_number
) tmp_tb
<include refid="BaseQuerySql"/>
</select>
</mapper>
@@ -1,7 +1,12 @@
package com.jero.modules.cert.template.service;
import com.jero.modules.cert.template.entity.ParamsInfoEO;
import com.baomidou.mybatisplus.extension.service.IService;
import com.jero.modules.cert.template.vo.ParamsInfoVO;
import com.jero.modules.cert.template.entity.ParamsInfoEO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
/**
@@ -58,4 +63,22 @@ public interface IParamsInfoEOService extends IService<ParamsInfoEO> {
* @return
*/
List<ParamsInfoEO> queryList();
/**
* 模板下载
* @param cut
* @param response
* @param request
*/
void exportTemplate(String cut, String templateName, HttpServletResponse response, HttpServletRequest request) throws IOException;
/**
* 导出压缩包
* @param cut
* @param paramsInfoVO
* @param exportExcelName
* @param response
* @param request
*/
void exportParamsInfo(String cut, ParamsInfoVO paramsInfoVO, String exportExcelName, HttpServletResponse response, HttpServletRequest request);
}
@@ -2,22 +2,43 @@ package com.jero.modules.cert.template.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.ZipUtil;
import com.aliyuncs.utils.IOUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jero.common.constant.enums.CutEnum;
import com.jero.common.exception.JeroBootException;
import com.jero.modules.cert.template.entity.CertCategoryParamsInfoEO;
import com.jero.modules.cert.template.entity.ParamsInfoEO;
import com.jero.modules.cert.template.mapper.ParamsInfoEOMapper;
import com.jero.modules.cert.template.service.ICertCategoryParamsInfoEOService;
import com.jero.modules.cert.template.service.IParamsInfoEOService;
import com.jero.modules.cert.template.utils.CommonExcelExportStyler;
import com.jero.modules.cert.template.vo.CertCategoryParamsInfoEnExport;
import com.jero.modules.cert.template.vo.ParamsInfoEnExport;
import com.jero.modules.cert.template.vo.ParamsInfoVO;
import com.jero.modules.oss.entity.OSSFile;
import com.jero.modules.oss.service.IOSSFileService;
import com.jero.modules.split.common.ReadExcel;
import com.jero.modules.system.entity.SysDictItem;
import com.jero.modules.system.service.ISysDictItemService;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Workbook;
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.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.*;
import java.util.stream.Collectors;
@@ -36,6 +57,11 @@ public class ParamsInfoEOServiceImpl extends ServiceImpl<ParamsInfoEOMapper, Par
@Autowired
private IOSSFileService ossFileService;
@Autowired
private ISysDictItemService sysDictItemService;
@Value(value = "${jero.path.upload}")
private String uploadpath;
/**
* 保存
*
@@ -148,6 +174,7 @@ public class ParamsInfoEOServiceImpl extends ServiceImpl<ParamsInfoEOMapper, Par
ParamsInfoEO paramsInfoEO = getById(id);
String nioNumber = paramsInfoEO.getNioNumber();
certCategoryParamsInfoEOService.deleteByNioNumberList(Arrays.asList(nioNumber));
// TODO 关联删除附件模板文件信息和文件
removeById(id);
}
@@ -166,6 +193,7 @@ public class ParamsInfoEOServiceImpl extends ServiceImpl<ParamsInfoEOMapper, Par
List<String> nioNumberList = paramsInfoEOList.stream().map(ParamsInfoEO::getNioNumber).collect(Collectors.toList());
// 关联删除认证类别参数项
certCategoryParamsInfoEOService.deleteByNioNumberList(nioNumberList);
// TODO 关联删除附件模板文件信息和文件
}
removeByIds(ids);
@@ -195,4 +223,255 @@ public class ParamsInfoEOServiceImpl extends ServiceImpl<ParamsInfoEOMapper, Par
public List<ParamsInfoEO> queryList() {
return list();
}
@Override
public void exportTemplate(String cut, String templateName, HttpServletResponse response, HttpServletRequest request) throws IOException {
Workbook workbook = null;
OutputStream os = null;
try {
//判断导出文件名称
String fileName = "";
if(StringUtils.isEmpty(templateName)){
fileName="参数项模板";
}else{
fileName = templateName;
}
// 导出sheet列表
List<Map<String, Object>> sheetsList = new ArrayList<>();
// 基本参数项
ExportParams bussExportParams = new ExportParams();
bussExportParams.setSheetName("企业参数表");
bussExportParams.setType(ExcelType.XSSF); // 解决HSSFRichTextString cannot cast XSSFRichTextString问题
bussExportParams.setStyle(CommonExcelExportStyler.class);
Map<String, Object> bussExportMap = new HashMap<>();
bussExportMap.put("title", bussExportParams);
bussExportMap.put("entity", ParamsInfoEO.class);
if (CutEnum.CN.getValue().equals(cut)) {
bussExportMap.put("data", new ArrayList<ParamsInfoEO>());
} else if (CutEnum.EN.getValue().equals(cut)) {
bussExportMap.put("data", new ArrayList<ParamsInfoEnExport>());
}
sheetsList.add(bussExportMap);
// 认证类别参数项
List<SysDictItem> sysDictItemList = sysDictItemService.selectItemsByDictCode("cert_category");
List<String> certCategoryNameList = sysDictItemList.stream().map(SysDictItem::getItemText).collect(Collectors.toList());
if (CollectionUtil.isNotEmpty(certCategoryNameList)) {
for (String certCategoryName : certCategoryNameList) {
ExportParams certExportParams = new ExportParams();
certExportParams.setSheetName(certCategoryName);
certExportParams.setType(ExcelType.XSSF); // 解决HSSFRichTextString cannot cast XSSFRichTextString问题
certExportParams.setStyle(CommonExcelExportStyler.class);
Map<String, Object> certExportMap = new HashMap<>();
certExportMap.put("title", certExportParams);
certExportMap.put("entity", CertCategoryParamsInfoEO.class);
if (CutEnum.CN.getValue().equals(cut)) {
certExportMap.put("data", new ArrayList<CertCategoryParamsInfoEO>());
} else if (CutEnum.EN.getValue().equals(cut)) {
certExportMap.put("data", new ArrayList<CertCategoryParamsInfoEnExport>());
}
sheetsList.add(certExportMap);
}
}
workbook = ExcelExportUtil.exportExcel(sheetsList, ExcelType.XSSF);
response.setCharacterEncoding("UTF-8");
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setHeader("Content-Disposition",
"attachment; filename=" + ReadExcel.encodeFileName(fileName + ".xlsx", request));
response.flushBuffer();
os = response.getOutputStream();
workbook.write(os);
} catch (IOException e) {
log.error("发生异常,异常信息为:"+e.getMessage(), e);
throw new JeroBootException("下载文件失败,请重试");
}finally {
IOUtils.closeQuietly(os);
try {
if (workbook != null) {
workbook.close();
}
} catch (IOException e) {
log.error("发生异常,异常信息为:"+e.getMessage(), e);
}
}
}
@Override
public void exportParamsInfo(String cut, ParamsInfoVO paramsInfoVO, String exportExcelName, HttpServletResponse response, HttpServletRequest request) {
Workbook workbook = null;
OutputStream os = null;
OutputStream excelOS = null;
try{
//判断导出文件名称
String exportName = "";
if(StringUtils.isEmpty(exportName)){
exportName="参数项导出数据";
}else{
exportName = exportExcelName;
}
//创建临时文件夹
String fileNowPath = uploadpath + "/tempZip/" + UUID.randomUUID().toString().replace("-","") + File.separator + exportName;
File nowFile = new File(fileNowPath);
if (nowFile.exists()){ // 若创建文件夹存在,删除重新创建
nowFile.delete();
}
nowFile.mkdirs();
String fileName = exportName + ".xlsx";
// 查询导出数据
List<ParamsInfoEO> paramsInfoEOList = baseMapper.selectListWithCert(paramsInfoVO);
if (CollectionUtil.isEmpty(paramsInfoEOList)) {
throw new JeroBootException("没有可导出的数据");
}
List<OSSFile> fileTemplateList = new ArrayList<>();
for (ParamsInfoEO paramsInfoEO : paramsInfoEOList) {
String fileTemplateConnectId = paramsInfoEO.getFileTemplateConnectId();
if (StringUtils.isNotBlank(fileTemplateConnectId)) {
List<OSSFile> ossFileList = ossFileService.getFileInfosByConnectId(fileTemplateConnectId);
List<String> fileNameList = ossFileList.stream().map(OSSFile::getFileName).collect(Collectors.toList());
paramsInfoEO.setFileTemplateName(StringUtils.join(fileNameList, ","));
fileTemplateList.addAll(ossFileList);
}
}
// 查询导出参数项中认证类别最大级
List<String> nioNumber = paramsInfoEOList.stream().map(ParamsInfoEO::getNioNumber).collect(Collectors.toList());
List<CertCategoryParamsInfoEO> certCategoryParamsInfoEOList = certCategoryParamsInfoEOService.selectListByNioNumber(StringUtils.join(nioNumber, ","));
List<String> certCategoryNameList = new ArrayList<>();
Map<String, String> certCategoryMap = new HashMap<>();
if (CollectionUtil.isNotEmpty(certCategoryParamsInfoEOList)) {
List<String> certCategoryList = certCategoryParamsInfoEOList.stream().map(CertCategoryParamsInfoEO::getCertCategory).distinct().collect(Collectors.toList());
List<SysDictItem> sysDictItemList = sysDictItemService.selectItemsByDictCode("cert_category");
List<String> finalCertCategoryList = certCategoryList;
certCategoryNameList = sysDictItemList.stream().filter(e-> finalCertCategoryList.contains(e.getItemValue())).map(SysDictItem::getItemText).collect(Collectors.toList());
certCategoryMap = sysDictItemList.stream().filter(e-> finalCertCategoryList.contains(e.getItemValue())).collect(Collectors.toMap(c->c.getItemText(),c->c.getItemValue()));
}
//导出数据
List<Map<String, Object>> sheetsList = new ArrayList<>();
// 创建参数对象(用来设定excel得sheet得内容等信息)
ExportParams bussExportParams = new ExportParams();
// 设置sheet得名称
bussExportParams.setSheetName("企业参数表");
bussExportParams.setType(ExcelType.XSSF); // 解决HSSFRichTextString cannot cast XSSFRichTextString问题
bussExportParams.setStyle(CommonExcelExportStyler.class);
// 创建sheet1使用得map
Map<String, Object> bussExportMap = new HashMap<>();
// title的参数为ExportParams类型,目前仅仅在ExportParams中设置了sheetName
bussExportMap.put("title", bussExportParams);
// 模版导出对应得实体类型
bussExportMap.put("entity", ParamsInfoEO.class);
// sheet中要填充得数据
bussExportMap.put("data", paramsInfoEOList);
sheetsList.add(bussExportMap);
// 导出认证类别参数项
if (CollectionUtil.isNotEmpty(certCategoryNameList)) {
// 所有数据
List<CertCategoryParamsInfoEO> certCategoryParamsInfoListExport = new ArrayList<>();
for (ParamsInfoEO paramsInfoEO : paramsInfoEOList) {
List<CertCategoryParamsInfoEO> categoryParamsInfoEOList = paramsInfoEO.getCertCategoryParamsInfoEOList();
certCategoryParamsInfoListExport.addAll(categoryParamsInfoEOList);
}
if (CollectionUtil.isNotEmpty(certCategoryParamsInfoListExport)) {
for (String certCategoryName : certCategoryNameList) {
// 当前认证类别数据
Map<String, String> finalCertCategoryMap = certCategoryMap;
List<CertCategoryParamsInfoEO> certCategoryParamsInfoExport = certCategoryParamsInfoListExport.stream()
.filter(e -> finalCertCategoryMap.get(certCategoryName).equals(e.getCertCategory()))
.collect(Collectors.toList());
if (CollectionUtil.isNotEmpty(certCategoryParamsInfoExport)) {
ExportParams certExportParams = new ExportParams();
certExportParams.setSheetName(certCategoryName);
certExportParams.setType(ExcelType.XSSF); // 解决HSSFRichTextString cannot cast XSSFRichTextString问题
certExportParams.setStyle(CommonExcelExportStyler.class);
Map<String, Object> certExportMap = new HashMap<>();
certExportMap.put("title", certExportParams);
certExportMap.put("entity", CertCategoryParamsInfoEO.class);
certExportMap.put("data", certCategoryParamsInfoExport);
sheetsList.add(certExportMap);
}
}
}
}
workbook = ExcelExportUtil.exportExcel(sheetsList, ExcelType.XSSF);
//下载附件模板对应文件
if (fileTemplateList != null && !fileTemplateList.isEmpty()) {
fileTemplateList = fileTemplateList.stream().distinct().collect(Collectors.toList());
downLoadFileList(fileTemplateList,fileNowPath);
}
String repFileName = fileName.replaceAll("/","_");
excelOS = new FileOutputStream(fileNowPath + File.separator + repFileName);
response.setHeader("Content-Disposition",
"attachment; filename=\""+ ReadExcel.encodeFileName(exportName+".zip", request) +"\"");
response.setContentType("application/force-download");
response.flushBuffer();
os = response.getOutputStream();
workbook.write(excelOS);
excelOS.flush();
excelOS.close();
ZipUtil.zip(fileNowPath,fileNowPath+".zip");
FileInputStream fis = new FileInputStream(fileNowPath+".zip");
int len = 0;
while ((len = fis.read()) != -1) {
os.write(len);
}
os.flush();
os.close(); // 后开先关
fis.close(); // 先开后关
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new JeroBootException("下载文件失败,请重试");
} finally {
IOUtils.closeQuietly(os);
IOUtils.closeQuietly(excelOS);
}
}
private void downLoadFileList(List<OSSFile> fileTemplateList,String fileNowPath) throws IOException {
for(OSSFile fileExportDto : fileTemplateList){
String oldPath = fileExportDto.getUrl();
String newPath = fileNowPath + File.separator + fileExportDto.getFileName();
File oldFile = new File(oldPath);
if (oldFile.exists()){
copyFile(oldPath, newPath);
}
}
}
private void copyFile(String srcPath, String destPath) throws IOException {
BufferedInputStream bis = new BufferedInputStream(Files.newInputStream(Paths.get(srcPath)));
BufferedOutputStream bos =
new BufferedOutputStream(Files.newOutputStream(Paths.get(destPath),
StandardOpenOption.CREATE,
StandardOpenOption.TRUNCATE_EXISTING,
StandardOpenOption.WRITE));
// 打开输入流
// FileInputStream fis = new FileInputStream(srcPath);
// 打开输出流
// FileOutputStream fos = new FileOutputStream(destPath);
// 读取和写入信息
byte[] bytes = new byte[1024 * 1024];
int len;
while ((len = bis.read(bytes)) > 0) {
bos.write(bytes, 0, len);
}
// 关闭流 先开后关 后开先关
bos.close(); // 后开先关
bis.close(); // 先开后关
}
}
@@ -0,0 +1,147 @@
package com.jero.modules.cert.template.utils;
import org.apache.poi.ss.usermodel.*;
import org.jeecgframework.poi.excel.entity.params.ExcelExportEntity;
import org.jeecgframework.poi.excel.export.styler.IExcelExportStyler;
/**
* @Description
* @Author liyawei
* @Create 2021/8/10 - 16:23
*/
public class CommonExcelExportStyler implements IExcelExportStyler {
private static final short STRING_FORMAT = (short) BuiltinFormats.getBuiltinFormat("TEXT");
private static final short FONT_SIZE_TEN = 10;
private static final short FONT_SIZE_ELEVEN = 11;
private static final short FONT_SIZE_TWELVE = 12;
/**
* 大标题样式
*/
private CellStyle headerStyle;
/**
* 每列标题样式
*/
private CellStyle titleStyle;
/**
* 数据行样式
*/
private CellStyle styles;
public CommonExcelExportStyler(Workbook workbook) {
this.init(workbook);
}
/**
* 初始化样式
*
* @param workbook
*/
private void init(Workbook workbook) {
// workbook.setSheetName(0,"sheet1");
this.headerStyle = initHeaderStyle(workbook);
this.titleStyle = initTitleStyle(workbook);
this.styles = initDataStyle(workbook);
}
/**
* 大标题样式
*
* @param color
* @return
*/
@Override
public CellStyle getHeaderStyle(short color) {
return headerStyle;
}
/**
* 每列标题样式
*
* @param color
* @return
*/
@Override
public CellStyle getTitleStyle(short color) {
return titleStyle;
}
/**
* 数据行样式
*
* @param parity 可以用来表示奇偶行
* @param entity 数据内容
* @return 样式
*/
@Override
public CellStyle getStyles(boolean parity, ExcelExportEntity entity) {
return styles;
}
/**
* 初始化--大标题样式
*
* @param workbook
* @return
*/
private CellStyle initHeaderStyle(Workbook workbook) {
CellStyle style = getBaseCellStyle(workbook);
style.setFont(getFont(workbook, FONT_SIZE_TWELVE, true));
return style;
}
/**
* 初始化--大标题样式
*
* @param workbook
* @return
*/
private CellStyle initTitleStyle(Workbook workbook) {
CellStyle style = getBaseCellStyle(workbook);
style.setFont(getFont(workbook, FONT_SIZE_ELEVEN, false));
return style;
}
/**
* 初始化--数据行样式
*
* @param workbook
* @return
*/
private CellStyle initDataStyle(Workbook workbook) {
CellStyle style = getBaseCellStyle(workbook);
style.setFont(getFont(workbook, FONT_SIZE_ELEVEN, false));
return style;
}
/**
* 基础样式
*
* @return
*/
private CellStyle getBaseCellStyle(Workbook workbook) {
CellStyle style = workbook.createCellStyle();
style.setBorderBottom(BorderStyle.THIN); // 下边框
style.setBorderLeft(BorderStyle.THIN); // 左边框
style.setBorderTop(BorderStyle.THIN); // 上边框
style.setBorderRight(BorderStyle.THIN); // 右边框
style.setAlignment(HorizontalAlignment.CENTER); // 水平居中
style.setVerticalAlignment(VerticalAlignment.BOTTOM); // 上下居中
style.setWrapText(true); // 设置自动换行
return style;
}
/**
* 字体样式
*
* @param size 字体大小
* @param isBold 是否加粗
* @return
*/
private Font getFont(Workbook workbook, short size, boolean isBold) {
Font font = workbook.createFont();
font.setFontName("宋体"); // 字体样式
font.setBold(isBold); // 是否加粗
font.setFontHeightInPoints(size); // 字体大小
return font;
}
}
@@ -0,0 +1,74 @@
package com.jero.modules.cert.template.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.jero.modules.cert.template.entity.CertCategoryParamsInfoEO;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.jeecgframework.poi.excel.annotation.Excel;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.List;
/**
* @Author: liyawei
* @Description:
* @Date: Created in 15:14 2022/4/25
*/
@Data
public class CertCategoryParamsInfoEnExport {
/**主键*/
@ApiModelProperty(value = "主键")
private String id;
/**创建人*/
@ApiModelProperty(value = "创建人")
private String createBy;
/**创建日期*/
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "创建日期")
private java.util.Date createTime;
/**更新人*/
@ApiModelProperty(value = "更新人")
private String updateBy;
/**更新日期*/
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "更新日期")
private java.util.Date updateTime;
/**所属部门*/
@ApiModelProperty(value = "所属部门")
private String sysOrgCode;
/**编号*/
@Excel(name = "*number", width = 15, orderNum = "2")
@ApiModelProperty(value = "编号")
private String paramsNumber;
/**参数名称*/
@Excel(name = "*params name", width = 15, orderNum = "3")
@ApiModelProperty(value = "参数名称")
private String paramsName;
/**参数说明*/
@Excel(name = "description", width = 36, orderNum = "4")
@ApiModelProperty(value = "参数说明")
private String description;
/**nio编号*/
@Excel(name = "*nio number", width = 15, orderNum = "1")
@ApiModelProperty(value = "nio编号")
private String nioNumber;
/**所属认证类别*/
@ApiModelProperty(value = "所属认证类别")
private String certCategory;
/**参数模板id*/
@ApiModelProperty(value = "参数模板id")
private String paramsTemplateId;
}
@@ -0,0 +1,113 @@
package com.jero.modules.cert.template.vo;
import com.baomidou.mybatisplus.annotation.TableField;
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.springframework.format.annotation.DateTimeFormat;
/**
* @Author: liyawei
* @Description:
* @Date: Created in 15:14 2022/4/25
*/
@Data
public class ParamsInfoEnExport {
/**主键*/
@ApiModelProperty(value = "主键")
private String id;
/**创建人*/
@ApiModelProperty(value = "创建人")
private String createBy;
/**创建日期*/
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "创建日期")
private java.util.Date createTime;
/**更新人*/
@ApiModelProperty(value = "更新人")
private String updateBy;
/**更新日期*/
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "更新日期")
private java.util.Date updateTime;
/**所属部门*/
@ApiModelProperty(value = "所属部门")
private String sysOrgCode;
/**nio编号*/
@Excel(name = "*nio number", width = 15)
@ApiModelProperty(value = "nio编号")
private String nioNumber;
/**是否必填*/
@Excel(name = "*is must", width = 15, replace = {"yes_1","no_0"})
@ApiModelProperty(value = "是否必填")
private String isMust;
/**参数名称*/
@Excel(name = "*param name", width = 15)
@ApiModelProperty(value = "参数名称")
private String paramsName;
/**技术领域*/
@Excel(name = "*technology territory", width = 15, dicCode = "technology_territory")
@Dict(dicCode = "technology_territory")
@ApiModelProperty(value = "技术领域")
private String technologyTerritory;
/**参数批次*/
@Excel(name = "*params batch", width = 15, dicCode = "params_batch")
@Dict(dicCode = "params_batch")
@ApiModelProperty(value = "参数批次")
private String paramsBatch;
/**责任领域*/
@Excel(name = "*duty territory", width = 15, dicCode = "duty_territory")
@Dict(dicCode = "duty_territory")
@ApiModelProperty(value = "责任领域")
private String dutyTerritory;
/**参数说明*/
@Excel(name = "description", width = 36)
@ApiModelProperty(value = "参数说明")
private String description;
/**认证类别*/
@Excel(name = "cert category", width = 15, dicCode = "cert_category")
@Dict(dicCode = "cert_category")
@ApiModelProperty(value = "认证类别")
private String certCategory;
/**控件类型*/
@Excel(name = "*control type", width = 15, replace = {"text_1","pull single_2","pull more_3","file_4","text+pull single_5","text+pull more_6","text+file_7","pull single+file_8","pull more+file_9","text+pull single+file_10"})
@ApiModelProperty(value = "控件类型")
private String controlType;
/**控件校验*/
@Excel(name = "control verify", width = 15, replace = {"null_1","chinese_2","positive integer_3","positive float_4","integer decimaL_5","decimal one_6","decimal two_7","decimal three_8","decimal four_9"})
@ApiModelProperty(value = "控件校验")
private String controlVerify;
/**控件备选值*/
@Excel(name = "control values", width = 15)
@ApiModelProperty(value = "控件备选值")
private String controlValues;
/**附件模板*/
@ApiModelProperty(value = "附件模板")
private String fileTemplateConnectId;
@Excel(name = "file template", width = 15)
@TableField(exist = false)
private String fileTemplateName; //附件模板文件名
}
@@ -0,0 +1,16 @@
package com.jero.modules.cert.template.vo;
import lombok.Data;
/**
* @Author: liyawei
* @Description:
* @Date: Created in 10:37 2022/4/25
*/
@Data
public class ParamsInfoVO {
private String nioNumber; // nio编号
private String paramsName; // 参数名称
private String dutyTerritory; // 责任领域
private String ids; // 勾选的参数项id
}