修改UAT问题

This commit is contained in:
gaosong
2023-10-22 16:52:36 +08:00
parent 0c5cbb19d5
commit f048ac4238
15 changed files with 949 additions and 47 deletions
@@ -10,6 +10,7 @@ import com.jero.common.system.base.controller.JeroController;
import com.jero.common.system.query.QueryGenerator;
import com.jero.modules.cert.collect.entity.ParamsCollectManifestEO;
import com.jero.modules.cert.collect.service.IParamsCollectManifestEOService;
import com.jero.modules.cert.collect.service.IParamsCollectManifestHistoryEOService;
import com.jero.modules.cert.collect.vo.ParamsCollectManifestVO;
import com.jero.modules.system.entity.SysUser;
import com.jero.modules.system.service.ISysUserService;
@@ -43,6 +44,8 @@ import java.util.stream.Collectors;
public class ParamsCollectManifestEOController extends JeroController<ParamsCollectManifestEO, IParamsCollectManifestEOService> {
@Autowired
private IParamsCollectManifestEOService paramsCollectManifestEOService;
@Autowired
private IParamsCollectManifestHistoryEOService paramsCollectManifestHistoryEOService;
@Autowired
private ISysUserService sysUserService;
@@ -531,7 +534,12 @@ public class ParamsCollectManifestEOController extends JeroController<ParamsColl
public void exportAll(ParamsCollectManifestVO paramsCollectManifestVO,
HttpServletResponse response,
HttpServletRequest request) {
paramsCollectManifestEOService.exportAll(paramsCollectManifestVO, response, request);
if(StringUtils.isNotBlank(paramsCollectManifestVO.getIsHistory())&&paramsCollectManifestVO.getIsHistory().equals("1")){
paramsCollectManifestHistoryEOService.exportAll(paramsCollectManifestVO, response, request);
}else{
paramsCollectManifestEOService.exportAll(paramsCollectManifestVO, response, request);
}
}
@ApiOperation(value = "参数项收集清单-填写人角色下导出")
@@ -84,7 +84,7 @@
#{item}
</foreach>
</if>
and control_type != '11'
order by nio_number asc
</select>
</mapper>
@@ -3,8 +3,10 @@ package com.jero.modules.cert.collect.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import com.jero.modules.cert.collect.entity.ParamsCollectManifestHistoryEO;
import com.jero.modules.cert.collect.vo.ParamsCollectManifestVO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
@@ -42,4 +44,7 @@ public interface IParamsCollectManifestHistoryEOService extends IService<ParamsC
*/
boolean deleteByIds(List<String> ids);
void exportAll(ParamsCollectManifestVO paramsCollectManifestVO, HttpServletResponse response, HttpServletRequest request);
}
@@ -3525,6 +3525,7 @@ public class ParamsCollectManifestEOServiceImpl extends ServiceImpl<ParamsCollec
addReportEO.setId(reportId);
addReportEO.setOldParamsManifestId(paramsManifestId);
addReportEO.setVersion(paramsManifestEO.getVersion());
addReportEO.setProjectVersion(paramsManifestEO.getProjectVersion());
addReportEO.setParamsTemplatePublishVersion(paramsManifestEO.getParamsTemplatePublishVersion());
paramsReportEOService.add(addReportEO);
}
@@ -3607,7 +3608,7 @@ public class ParamsCollectManifestEOServiceImpl extends ServiceImpl<ParamsCollec
@Override
public void exportAll(ParamsCollectManifestVO paramsCollectManifestVO, HttpServletResponse response, HttpServletRequest request) {
OutputStream os = null;
// OutputStream os = null;
OutputStream excelOS = null;
XSSFWorkbook workbook = new XSSFWorkbook();
String fileOriName = "参数项清单导出信息";
@@ -3721,7 +3722,7 @@ public class ParamsCollectManifestEOServiceImpl extends ServiceImpl<ParamsCollec
"attachment; filename=\"" + ReadExcel.encodeFileName(fileOriName + ".zip", request) + "\"");
response.setContentType("application/force-download");
response.flushBuffer();
os = response.getOutputStream();
// os = response.getOutputStream();
workbook.write(excelOS);
excelOS.flush();
excelOS.close();
@@ -3766,8 +3767,8 @@ public class ParamsCollectManifestEOServiceImpl extends ServiceImpl<ParamsCollec
// webSocket.sendMessage(obj.toJSONString());
//
// uploadFileio.close();
os.flush();
os.close(); // 后开先关
// os.flush();
// os.close(); // 后开先关
// fis.close(); // 先开后关
pce.setState(ExportStateEnum.SUCCESSFULLY.getValue());
pce.setFileId(ossFile.getId());
@@ -3786,7 +3787,7 @@ public class ParamsCollectManifestEOServiceImpl extends ServiceImpl<ParamsCollec
}
}
} finally {
IOUtils.closeQuietly(os);
// IOUtils.closeQuietly(os);
IOUtils.closeQuietly(excelOS);
File tempZipFile = new File(uploadpath + "/tempZip");
FileUtil.deleteContents(tempZipFile);
@@ -2,36 +2,62 @@ package com.jero.modules.cert.collect.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.ZipUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.jero.common.constant.enums.CutEnum;
import com.jero.common.constant.enums.ModuleEnum;
import com.jero.common.constant.enums.YesOrNoEnum;
import com.jero.common.exception.JeroBootException;
import com.jero.common.system.query.QueryGenerator;
import com.jero.common.system.vo.LoginUser;
import com.jero.common.util.oss.CosBootUtil;
import com.jero.generater.modules.online.cgform.entity.OnlCgformField;
import com.jero.generater.modules.online.cgform.service.impl.OnlCgformFieldServiceImpl;
import com.jero.modules.cert.collect.entity.*;
import com.jero.modules.cert.collect.enums.CollectManifestStateEnum;
import com.jero.modules.cert.collect.enums.CollectManifestUserTypeEnum;
import com.jero.modules.cert.collect.enums.ConfigDataTypeEnum;
import com.jero.modules.cert.collect.enums.ExportStateEnum;
import com.jero.modules.cert.collect.mapper.ParamsCollectManifestHistoryEOMapper;
import com.jero.modules.cert.collect.service.IParamsCollectExportService;
import com.jero.modules.cert.collect.service.IParamsCollectManifestHistoryEOService;
import com.jero.modules.cert.collect.service.IParamsConfigDataHistoryEOService;
import com.jero.modules.cert.collect.service.IParamsConfigHistoryEOService;
import com.jero.modules.cert.collect.vo.ParamsCollectManifestVO;
import com.jero.modules.cert.collect.vo.ParamsConfigDataVO;
import com.jero.modules.cert.template.entity.CertCategoryParamsInfoPublishEO;
import com.jero.modules.cert.template.enums.ControlTypeEnum;
import com.jero.modules.cert.template.service.ICertCategoryParamsInfoPublishEOService;
import com.jero.modules.ocr.util.LineHumpUtil;
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.collections4.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.util.IOUtils;
import org.apache.poi.xssf.usermodel.*;
import org.apache.shiro.SecurityUtils;
import org.aspectj.util.FileUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.lang.reflect.Field;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
@@ -62,6 +88,12 @@ public class ParamsCollectManifestHistoryEOServiceImpl extends ServiceImpl<Param
@Autowired
private IOSSFileService ossFileService;
@Autowired
private IParamsCollectExportService paramsCollectExportService;
@Autowired
private ICertCategoryParamsInfoPublishEOService certCategoryParamsInfoPublishEOService;
@Value(value = "${jero.path.upload}")
private String uploadpath;
private ParamsConfigDataHistoryEO getConfigDataEOByConfigIdAndCollectManifestId(String configId, String collectManifestId, List<ParamsConfigDataHistoryEO> paramsConfigDataEOList) {
@@ -606,4 +638,524 @@ public class ParamsCollectManifestHistoryEOServiceImpl extends ServiceImpl<Param
// }
// return map;
// }
@Override
public void exportAll(ParamsCollectManifestVO paramsCollectManifestVO, HttpServletResponse response, HttpServletRequest request) {
OutputStream os = null;
OutputStream excelOS = null;
XSSFWorkbook workbook = new XSSFWorkbook();
String fileOriName = "参数项清单导出信息";
if (CutEnum.EN.getValue().equals(paramsCollectManifestVO.getCut())) {
fileOriName = "Params info export data";
}
if (StringUtils.isNotEmpty(paramsCollectManifestVO.getExportName())) {
fileOriName = paramsCollectManifestVO.getExportName();
}
//创建导出记录
ParamsCollectExport pce = new ParamsCollectExport();
String pceId = UUID.randomUUID().toString().replace("-", "");
pce.setId(pceId);
pce.setParamsManifestId(paramsCollectManifestVO.getParamsManifestId());
pce.setState(ExportStateEnum.EXPORTING.getValue());
pce.setFileName(fileOriName+ ".zip");
Thread thread1 = new Thread(new Runnable() {
@Override
public void run() {
paramsCollectExportService.add(pce);
}
});
thread1.start();
//创建临时文件夹
String fileNowPath = uploadpath + "/tempZip/" + UUID.randomUUID().toString().replace("-", "") + File.separator + fileOriName;
File nowFile = new File(fileNowPath);
if (nowFile.exists()) {
nowFile.delete();
}
nowFile.mkdirs();
try {
String fileName = fileOriName + ".xlsx";
// 设置表格相关属性
String sheetName = "参数项清单信息";
if (CutEnum.EN.getValue().equals(paramsCollectManifestVO.getCut())) {
sheetName = "Params data";
}
XSSFSheet sheetItems = workbook.createSheet(sheetName);
String[] titles = getWorkbookTitleForExport(paramsCollectManifestVO); // 获取表头
String[] headers = titles[1].split(",");
XSSFCellStyle cellStyle = workbook.createCellStyle();
cellStyle.setWrapText(true);
// cellStyle.setAlignment(XSSFCellStyle.ALIGN_CENTER);
cellStyle.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER);
XSSFCellStyle cellStyle1 = workbook.createCellStyle();
cellStyle1.setAlignment(XSSFCellStyle.ALIGN_CENTER);
XSSFCellStyle cellStyleLink = workbook.createCellStyle();
XSSFFont font = workbook.createFont();
font.setColor(HSSFColor.LIGHT_BLUE.index);
cellStyleLink.setFont(font);
cellStyleLink.setWrapText(true);
// 查询需要导出的字段
String field = titles[0]; // 字符串形式
List<String> fieldList = Arrays.asList(field.split(",")); // list形式
// 查询导出数据
List<Map<String, Object>> allParamsInfoList = queryForExportAll(paramsCollectManifestVO); // id记得去掉
// 开始处理工作表
List<OSSFile> allRelevFileList = new ArrayList<>();
// 在excel表中添加表头
XSSFRow row = sheetItems.createRow(0);
for (int i = 0; i < headers.length; i++) {
XSSFCell cell = row.createCell(i);
XSSFRichTextString text = new XSSFRichTextString(headers[i]);
cell.setCellValue(text);
cell.setCellStyle(cellStyle1);
sheetItems.setColumnWidth(i, 20 * 256); // 设置单元格宽度
}
Map<String, String> fileNowPathMap = new HashMap<>();
//放文字内容
int allRow = 0;
for (int rowNum = 0; rowNum < allParamsInfoList.size(); rowNum++) {
Map<String, Object> exportDto = allParamsInfoList.get(rowNum);
// 处理文件
List<OSSFile> fileList = (List<OSSFile>) exportDto.get("fileList");
if (CollectionUtil.isNotEmpty(fileList)) {
allRelevFileList.addAll(fileList);
fileList.forEach(file -> {
fileNowPathMap.put(file.getId(), fileNowPath + File.separator + exportDto.get("nio_number"));
});
}
allRow++;
XSSFRow row1 = sheetItems.createRow(allRow);
for (int cellNum = 0; cellNum < fieldList.size(); cellNum++) {
if (ObjectUtils.isNotEmpty(exportDto.get(fieldList.get(cellNum)))) {
row1.createCell(cellNum).setCellValue(exportDto.get(fieldList.get(cellNum)).toString());
row1.getCell(cellNum).setCellStyle(cellStyle);
}
}
}
//下载关联文件内容
if (allRelevFileList != null && !allRelevFileList.isEmpty()) {
allRelevFileList = allRelevFileList.stream().distinct().collect(Collectors.toList());
downLoadFileList(allRelevFileList, fileNowPathMap);
}
String repFileName = fileName.replaceAll("/", "_");
excelOS = new FileOutputStream(fileNowPath + File.separator + repFileName);
response.setHeader("Content-Disposition",
"attachment; filename=\"" + ReadExcel.encodeFileName(fileOriName + ".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);
// }
// 将导出文件上传到cos上
String uploadFileName = fileOriName + ".zip";
InputStream uploadFileio = new FileInputStream(new File(fileNowPath+".zip"));
MultipartFile mFile = new MockMultipartFile(uploadFileName, uploadFileName, "text/plain", uploadFileio); // 用于上传
OSSFile ossFile = ossFileService.uploadLocalOfCos(mFile, "/manifest", "", CutEnum.CN.getValue()); // 上传导出的压缩包
//
// // 系统向用户发消息
// LoginUser currentUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); // 获取当前登录人
// String msgTitle = "The file " + paramsCollectManifestVO.getExportName() + " that you exported has been generated.";
// String content = "The file " + paramsCollectManifestVO.getExportName() + " that you exported has been generated, please click download.";
//
// String href = "<a href='/jero-boot/sys/common/downLoadFile?id=" + ossFile.getId() + "'" + " target='_blank'>download</a>.";
// String contentInfo = "The file " + paramsCollectManifestVO.getExportName() + " that you exported has been generated, please click " + href;
//
// SysAnnouncement sysAnnouncement = new SysAnnouncement();
// sysAnnouncement.setDelFlag("0");
// sysAnnouncement.setSendStatus("0");
// sysAnnouncement.setSendTime(new Date());
// sysAnnouncement.setMsgCategory(MessageTypeEnum.PUSH.getValue()); //消息类型:转发推送
// sysAnnouncement.setInitiator(MessageTypeEnum.SYSTEMATIC_NOTIFICATION.getName()); // 发起人:系统
// sysAnnouncement.setMsgType(CommonConstant.MSG_TYPE_UESR);//指定用户
// sysAnnouncement.setTitile(msgTitle);
// sysAnnouncement.setMsgContent(content);
// sysAnnouncement.setMsgContentInfo(contentInfo);
// sysAnnouncement.setUserIds(currentUser.getId()); // 发送给当前导出人
// sysAnnouncementService.saveAnnouncement(sysAnnouncement);
//
// JSONObject obj = new JSONObject();
// obj.put(WebsocketConst.MSG_CMD, WebsocketConst.CMD_TOPIC);
// obj.put(WebsocketConst.MSG_ID, currentUser.getId());
// obj.put(WebsocketConst.MSG_TXT, contentInfo);
// webSocket.sendMessage(obj.toJSONString());
//
// uploadFileio.close();
os.flush();
os.close(); // 后开先关
// fis.close(); // 先开后关
pce.setState(ExportStateEnum.SUCCESSFULLY.getValue());
pce.setFileId(ossFile.getId());
paramsCollectExportService.updateById(pce);
} catch (Exception e) {
pce.setState(ExportStateEnum.FAILURE.getValue());
paramsCollectExportService.updateById(pce);
if (e instanceof JeroBootException) {
throw new JeroBootException(e.getMessage());
} else {
log.error(e.getMessage(), e);
if (CutEnum.EN.getValue().equals(paramsCollectManifestVO.getCut())) {
throw new JeroBootException("Failed to download file, please try again");
} else {
throw new JeroBootException("下载文件失败,请重试");
}
}
} finally {
IOUtils.closeQuietly(os);
IOUtils.closeQuietly(excelOS);
File tempZipFile = new File(uploadpath + "/tempZip");
FileUtil.deleteContents(tempZipFile);
}
}
private String[] getWorkbookTitleForExport(ParamsCollectManifestVO paramsCollectManifestVO) {
String cut = paramsCollectManifestVO.getCut();
String paramsManifestId = paramsCollectManifestVO.getParamsManifestId();
List<OnlCgformField> fieldList = onlCgformFieldService.getFieldList(ModuleEnum.PARAMS_COLLECT_MANIFEST.getValue());
List<String> dbFieldNameList = new LinkedList<>();
List<String> dbFieldList = new LinkedList<>();
if (fieldList.size() != 0) {
//过滤列表字段(is_show_list-->列表是否显示0否 1是)
fieldList = fieldList.stream().filter(e -> YesOrNoEnum.YES.getValue().equals(String.valueOf(e.getIsShowList()))).collect(Collectors.toList());
}
// 固定列
int indexOfDescription = 1; // 参数名称的位置
for (int i = 0; i < fieldList.size(); i++) {
OnlCgformField onlCgformField = fieldList.get(i);
String dbFieldName = onlCgformField.getDbFieldName();
if (!"deadline".equals(dbFieldName) && !"cert_category".equals(dbFieldName)) {
dbFieldList.add(dbFieldName);
if (CutEnum.CN.getValue().equals(cut)) {
dbFieldNameList.add(onlCgformField.getDbFieldTxt()); // 字段中文名
} else {
dbFieldNameList.add(onlCgformField.getDbFieldEnName()); // 字段英文名
}
if ("params_name".equals(dbFieldName)) {
indexOfDescription = i;
}
}
}
// 认证类别列
List<String> dbFieldNameListCC = new LinkedList<>();
List<String> dbFieldListCC = new LinkedList<>();
// 查询所有认证类别
List<SysDictItem> sysDictItemList = sysDictItemService.selectItemsByDictCode("cert_category");
if (CutEnum.EN.getValue().equals(cut)) {
sysDictItemList.forEach(sysDictItem -> {
dbFieldListCC.add(sysDictItem.getItemValue());
dbFieldNameListCC.add(sysDictItem.getEnName() + " Number");
});
} else {
sysDictItemList.forEach(sysDictItem -> {
dbFieldListCC.add(sysDictItem.getItemValue());
dbFieldNameListCC.add(sysDictItem.getItemText() + "编号");
});
}
// 配置列
List<String> dbFieldNameListConfig = new LinkedList<>();
List<String> dbFieldListConfig = new LinkedList<>();
List<ParamsConfigHistoryEO> paramsConfigEOList = paramsConfigHistoryEOService.queryList(paramsManifestId);
for (ParamsConfigHistoryEO paramsConfigEO : paramsConfigEOList) {
dbFieldListConfig.add(paramsConfigEO.getId());
dbFieldNameListConfig.add(paramsConfigEO.getConfigName());
}
// 插入认证类别列
dbFieldList.addAll(indexOfDescription, dbFieldListCC);
dbFieldNameList.addAll(indexOfDescription, dbFieldNameListCC);
// 插入配置列
dbFieldList.addAll(dbFieldListConfig);
dbFieldNameList.addAll(dbFieldNameListConfig);
String[] title = new String[2];
String dbFieldStr = StringUtils.join(dbFieldList, ",");
String dbFieldNameStr = StringUtils.join(dbFieldNameList, ",");
title[0] = dbFieldStr;
title[1] = dbFieldNameStr;
return title;
}
private List<Map<String, Object>> queryForExportAll(ParamsCollectManifestVO paramsCollectManifestVO) {
String paramsManifestId = paramsCollectManifestVO.getParamsManifestId();
String paramsTemplateId = paramsCollectManifestVO.getParamsTemplateId();
Integer paramsTemplatePublishVersion = paramsCollectManifestVO.getParamsTemplatePublishVersion();
String cut = paramsCollectManifestVO.getCut();
LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
ParamsCollectManifestEO queryEO = new ParamsCollectManifestEO();
queryEO.setParamsManifestId(paramsManifestId);
String userTypes = paramsCollectManifestVO.getUserTypes();
if (userTypes != null && CollectManifestUserTypeEnum.SDT.getValue().equals(userTypes)) {
queryEO.setUserTypes(CollectManifestUserTypeEnum.SDT.getValue());
queryEO.setSdt(loginUser.getUsername());
}
List<Map<String, Object>> dataList = paramsCollectManifestHistoryEOMapper.listInfoForExport(queryEO, null); // 查询导出数据
if (dataList == null || dataList.isEmpty()) {
// 没有查到数据,进行提示
if (CutEnum.EN.getValue().equals(paramsCollectManifestVO.getCut())) {
throw new JeroBootException("No data, unable to export");
} else {
throw new JeroBootException("无数据,无法导出");
}
}
List<ParamsConfigHistoryEO> paramsConfigEOList = paramsConfigHistoryEOService.queryList(paramsManifestId); // 查询所有配置列
List<String> paramsConfigIdList = paramsConfigEOList.stream().map(ParamsConfigEO::getId).collect(Collectors.toList());
List<ParamsConfigDataHistoryEO> paramsConfigDataEOList = paramsConfigDataHistoryEOService.queryListByConfigIdList(paramsConfigIdList); // 查询所有配置数据
List<Map<String,Object>> exportDataList = new ArrayList<>();
// 配置列多行数据处理
for (Map<String, Object> data : dataList) {
String controlType = (String)data.get("control_type");
if("0".equals(paramsCollectManifestVO.getExportOption()) && "11".equals(controlType)){
//不要标题
continue;
}
String id = (String) data.get("id");
Map<String, List<ParamsConfigDataEO>> paramsConfigDataMap = paramsConfigDataEOList.stream().filter(configDataEO -> {
boolean flag = false;
if (StringUtils.equals(configDataEO.getParamsCollectManifestId(), id)) {
flag = true;
}
return flag;
}).collect(Collectors.groupingBy(configDataEO -> configDataEO.getParamsConfigId()));
List<Map<String, Object>> paramsConfigDataCountList = new ArrayList<>();
for (Map.Entry<String, List<ParamsConfigDataEO>> map : paramsConfigDataMap.entrySet()) {
Map<String, Object> paramsConfigDataCountMap = new HashMap<>();
paramsConfigDataCountMap.put("key", map.getKey());
paramsConfigDataCountMap.put("paramsConfigDataCount", map.getValue().size());
paramsConfigDataCountMap.put("value", map.getValue());
paramsConfigDataCountList.add(paramsConfigDataCountMap);
}
// 排序 配置数据总数倒序排序
Collections.sort(paramsConfigDataCountList, new Comparator<Map<String, Object>>() {
@Override
public int compare(Map<String, Object> o1, Map<String, Object> o2) {
return o2.get("paramsConfigDataCount").toString().compareTo(o1.get("paramsConfigDataCount").toString());
}
});
// 获取出最多行的配置列。
if (!paramsConfigDataCountList.isEmpty()) {
Map<String, Object> paramsConfigDataMaxCountMap = paramsConfigDataCountList.get(0);
String key = (String) paramsConfigDataMaxCountMap.get("key");
List<ParamsConfigDataEO> paramsConfigDataEOs = paramsConfigDataMap.get(key);
for (ParamsConfigDataEO paramsConfigDataEO : paramsConfigDataEOs) {
Map<String, Object> dataTemp = new HashMap<>();
data.entrySet().forEach(o -> dataTemp.put(o.getKey(), o.getValue()));
exportDataList.add(dataTemp);
}
} else {
exportDataList.add(data);
}
}
List<String> nioNumberList = dataList.stream().map(m -> (String) m.get("nio_number")).collect(Collectors.toList());
List<CertCategoryParamsInfoPublishEO> certCategoryParamsInfoPublishEOList = certCategoryParamsInfoPublishEOService.queryListByVersionAndNio(paramsTemplateId, paramsTemplatePublishVersion, nioNumberList); //查询所有认证类别参数项
// 查询责任领域数据字典
List<SysDictItem> sysDictItemList = sysDictItemService.selectItemsByDictCode("duty_territory");
Map<String, String> dutyTerritoryMap = new HashMap<>();
if (CutEnum.EN.getValue().equals(cut)) {
dutyTerritoryMap = sysDictItemList.stream().collect(Collectors.toMap(c -> c.getItemValue(), c -> c.getEnName()));
} else {
dutyTerritoryMap = sysDictItemList.stream().collect(Collectors.toMap(c -> c.getItemValue(), c -> c.getItemText()));
}
// 状态
Map<String, String> stateMap = CollectManifestStateEnum.toMap(cut);
// 插入配置列和认证类别列数据
for (Map<String, Object> record1 : exportDataList) {
String paramsCollectManifestId = (String) record1.get("id");
String nioNumber = (String) record1.get("nio_number");
String dutyTerritory = (String) record1.get("duty_territory");
String state = (String) record1.get("state");
String control_type = record1.get("control_type").toString();
//references_col -> #a# #
if (!Objects.isNull(record1.get("references_col"))) {
String references_col = record1.get("references_col").toString();
if (StringUtils.isNotEmpty(references_col)) {
String[] references_colArr = references_col.split("#");
if (StringUtils.equals(control_type, ControlTypeEnum.FILE.getValue())) {
String fileId = references_colArr[2];
List<OSSFile> fileInfos = this.ossFileService.getFileInfos(fileId);
String fileName = fileInfos.stream().map(OSSFile::getFileName).collect(Collectors.joining(","));
references_col = "#" + references_colArr[0] + "#" + references_colArr[1] + "#" + fileName;
} else if (StringUtils.equals(control_type, ControlTypeEnum.TEXT_FILE.getValue())
|| StringUtils.equals(control_type, ControlTypeEnum.PULL_SINGLE_FILE.getValue())
|| StringUtils.equals(control_type, ControlTypeEnum.PULL_MORE_FILE.getValue())) {
String fileId = references_colArr[2];
List<OSSFile> fileInfos = this.ossFileService.getFileInfos(fileId);
String fileName = fileInfos.stream().map(OSSFile::getFileName).collect(Collectors.joining(","));
references_col = "#" + references_colArr[0] + "#" + references_colArr[1] + "#" + fileName;
} else if (StringUtils.equals(control_type, ControlTypeEnum.TEXT_PULL_SINGLE_FILE.getValue())) {
String fileId = references_colArr[2];
List<OSSFile> fileInfos = this.ossFileService.getFileInfos(fileId);
String fileName = fileInfos.stream().map(OSSFile::getFileName).collect(Collectors.joining(","));
references_col = "#" + references_colArr[0] + "#" + references_colArr[1] + "#" + fileName;
}
StringBuilder references_colSb = new StringBuilder();
for (String col : references_col.split("#")) {
if (StringUtils.isNotEmpty(col) && !StringUtils.equals(col, " ")) {
references_colSb.append(col).append("#");
}
}
if (StringUtils.isNotEmpty(references_colSb)) {
references_col = references_colSb.substring(0, references_colSb.length() - 1);
} else {
references_col = references_colSb.toString();
}
record1.put("references_col", references_col);
}
}
// 处理负责领域
record1.put("duty_territory", dutyTerritoryMap.get(dutyTerritory));
// 处理状态
record1.put("state", stateMap.get(state));
// 认证类别列
List<CertCategoryParamsInfoPublishEO> certCategoryParamsInfoPublishEOS = certCategoryParamsInfoPublishEOList.stream().filter(e -> nioNumber.equals(e.getNioNumber())).collect(Collectors.toList());
if (CollectionUtil.isNotEmpty(certCategoryParamsInfoPublishEOS)) {
certCategoryParamsInfoPublishEOS.forEach(certCategoryParamsInfoPublishEO -> {
record1.put(certCategoryParamsInfoPublishEO.getCertCategory(), certCategoryParamsInfoPublishEO.getParamsNumber());
});
}
// 配置列
if (CollectionUtil.isNotEmpty(paramsConfigEOList)) {
List<OSSFile> fileList = new ArrayList<>();
paramsConfigEOList.forEach(paramsConfigEO -> { // 参数配置
String paramsConfigId = paramsConfigEO.getId();
List<ParamsConfigDataEO> paramsConfigDataEOS = paramsConfigDataEOList.stream().filter(e -> {
boolean flag = false;
if(StringUtils.equals(paramsConfigId,e.getParamsConfigId()) && StringUtils.equals(paramsCollectManifestId,e.getParamsCollectManifestId())){
flag = true;
}
return flag;
}).collect(Collectors.toList()); // 参数配置数据
StringBuilder configDataBuilder = new StringBuilder(); // 重新组合配置数据
if (CollectionUtil.isNotEmpty(paramsConfigDataEOS)) {
ParamsConfigDataEO paramsConfigDataEO = paramsConfigDataEOS.get(0);
if (StringUtils.isNotEmpty(paramsConfigDataEO.getTextData())) {
configDataBuilder.append(paramsConfigDataEO.getTextData()).append("#");
}
if (StringUtils.isNotEmpty(paramsConfigDataEO.getPullData())) {
configDataBuilder.append(paramsConfigDataEO.getPullData()).append("#");
}
if (StringUtils.isNotEmpty(paramsConfigDataEO.getFileConnectId())) {
List<OSSFile> ossFileList = ossFileService.getFileInfosByConnectId(paramsConfigDataEO.getFileConnectId());
if (CollectionUtil.isNotEmpty(ossFileList)) {
configDataBuilder.append(nioNumber).append("/").append(ossFileList.get(0).getFileName()).append("#");
fileList.addAll(ossFileList);
}
}
paramsConfigDataEOList.remove(paramsConfigDataEO);
}
String configData = configDataBuilder.toString();
if (configData.contains("#")) {
configData = configData.substring(0, configData.lastIndexOf("#"));
}
record1.put(paramsConfigEO.getId(), configData);
});
record1.put("fileList", fileList);
}
}
return exportDataList;
}
private void downLoadFileList(List<OSSFile> fileTemplateList, Map<String, String> fileNowPathMap) {
for (OSSFile fileExportDto : fileTemplateList) {
String fileNowPath = fileNowPathMap.get(fileExportDto.getId());
File nowFile = new File(fileNowPath);
if (nowFile.exists()) {
nowFile.delete();
}
nowFile.mkdirs();
String oldPath = fileExportDto.getUrl();
String newPath = fileNowPath + File.separator + fileExportDto.getFileName();
if (CosBootUtil.doesObjectExist(oldPath)) {
try (InputStream in = CosBootUtil.download(oldPath);) {
copyFile(in, newPath);
} catch (IOException e) {
e.printStackTrace();
log.error(e.getMessage(), e);
}
}
}
}
private void copyFile(InputStream in, String destPath) throws IOException {
BufferedInputStream bis = new BufferedInputStream(in);
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(); // 先开后关
}
}
@@ -110,4 +110,8 @@ public class ParamsCollectManifestVO {
//是否导出标题 ”1“ 是 ”0“否
@TableField(exist = false)
private String exportOption;
//是否是历史版本 ”1“ 是 ”0“否
@TableField(exist = false)
private String isHistory;
}
@@ -123,14 +123,20 @@ public class ParamsReportEOController extends JeroController<ParamsReportEO, IPa
String market = getMarket(paramsReportEO, targetMarketList, row);
if(StringUtils.isNotBlank(row.getProjectName())){
if(StringUtils.isBlank(market)){
row.setProjectName(row.getProjectName()+ "-00");
row.setProjectName(row.getProjectName());
}else{
row.setProjectName(row.getProjectName()+"-" +market+ "-00");
row.setProjectName(row.getProjectName()+"-" +market);
}
row.setPageName(row.getProjectName());
}else{
row.setPageName("");
}
String projectVersion = row.getProjectVersion();
if(StringUtils.isNotBlank(row.getProjectVersion())){
row.setProjectName(row.getProjectName() + "-" + row.getProjectVersion());
}else{
row.setProjectName(row.getProjectName()+"-00");
}
}
String orderBy = paramsReportEO.getOrderBy();
String orderByField = paramsReportEO.getOrderByField();
@@ -81,6 +81,9 @@ public class ParamsReportEO implements Serializable {
@ApiModelProperty(value = "目标市场")
private String targetMarket;
@ApiModelProperty(value = "相关项目版本")
private String projectVersion;
@TableField(exist = false)
private String cut;
@@ -22,6 +22,7 @@
pr.id as id,
pr.old_params_manifest_id as old_params_manifest_id,
pr.version as version,
pr.project_version,
pr.params_template_publish_version as params_template_publish_version,
pr.create_by as create_by,
pr.create_time as create_time,
@@ -17,10 +17,13 @@ import com.jero.common.system.vo.LoginUser;
import com.jero.common.util.oss.CosBootUtil;
import com.jero.generater.modules.online.cgform.entity.OnlCgformField;
import com.jero.generater.modules.online.cgform.service.impl.OnlCgformFieldServiceImpl;
import com.jero.modules.cert.collect.entity.ParamsCollectExport;
import com.jero.modules.cert.collect.entity.ParamsConfigDataEO;
import com.jero.modules.cert.collect.entity.ParamsConfigEO;
import com.jero.modules.cert.collect.enums.CollectManifestStateEnum;
import com.jero.modules.cert.collect.enums.ConfigDataTypeEnum;
import com.jero.modules.cert.collect.enums.ExportStateEnum;
import com.jero.modules.cert.collect.service.IParamsCollectExportService;
import com.jero.modules.cert.collect.vo.ParamsConfigDataVO;
import com.jero.modules.cert.report.entity.*;
import com.jero.modules.cert.report.enums.ExportTemplateStateEnum;
@@ -116,6 +119,8 @@ public class ParamsReportDetailEOServiceImpl extends ServiceImpl<ParamsReportDet
@Autowired
private IReportCertCategoryParamsInfoEOService reportCertCategoryParamsInfoEOService;
@Autowired
private IParamsCollectExportService paramsCollectExportService;
@Value(value = "${jero.path.upload}")
private String uploadpath;
@@ -2381,7 +2386,7 @@ public class ParamsReportDetailEOServiceImpl extends ServiceImpl<ParamsReportDet
@Override
public void exportGeneral(ParamsReportDetailVO paramsReportDetailVO, HttpServletResponse response, HttpServletRequest request) {
OutputStream os = null;
// OutputStream os = null;
OutputStream excelOS = null;
XSSFWorkbook workbook = new XSSFWorkbook();
String fileOriName = "一般导出";
@@ -2391,6 +2396,20 @@ public class ParamsReportDetailEOServiceImpl extends ServiceImpl<ParamsReportDet
if (StringUtils.isNotEmpty(paramsReportDetailVO.getExportName())) {
fileOriName = paramsReportDetailVO.getExportName();
}
//创建导出记录
ParamsCollectExport pce = new ParamsCollectExport();
String pceId = UUID.randomUUID().toString().replace("-", "");
pce.setId(pceId);
pce.setParamsManifestId(paramsReportDetailVO.getParamsManifestId());
pce.setState(ExportStateEnum.EXPORTING.getValue());
pce.setFileName(fileOriName+ ".zip");
Thread thread1 = new Thread(new Runnable() {
@Override
public void run() {
paramsCollectExportService.add(pce);
}
});
thread1.start();
//创建临时文件夹
String fileNowPath = uploadpath + "/tempZip/" + UUID.randomUUID().toString().replace("-", "") + File.separator + fileOriName;
File nowFile = new File(fileNowPath);
@@ -2485,16 +2504,16 @@ public class ParamsReportDetailEOServiceImpl extends ServiceImpl<ParamsReportDet
"attachment; filename=\"" + ReadExcel.encodeFileName(fileOriName + ".zip", request) + "\"");
response.setContentType("application/force-download");
response.flushBuffer();
os = response.getOutputStream();
// 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);
}
// FileInputStream fis = new FileInputStream(fileNowPath + ".zip");
// int len = 0;
// while ((len = fis.read()) != -1) {
// os.write(len);
// }
// 添加导出历史
String uploadFileName = fileOriName + ".zip";
@@ -2508,11 +2527,16 @@ public class ParamsReportDetailEOServiceImpl extends ServiceImpl<ParamsReportDet
paramsReportExportHistoryEO.setExportTime(new Date());
paramsReportExportHistoryEOService.add(paramsReportExportHistoryEO);
uploadFileio.close();
os.flush();
os.close(); // 后开先关
fis.close(); // 先开后关
// uploadFileio.close();
// os.flush();
// os.close(); // 后开先关
// fis.close(); // 先开后关
pce.setState(ExportStateEnum.SUCCESSFULLY.getValue());
pce.setFileId(ossFile.getId());
paramsCollectExportService.updateById(pce);
} catch (Exception e) {
pce.setState(ExportStateEnum.FAILURE.getValue());
paramsCollectExportService.updateById(pce);
e.printStackTrace();
log.error(e.getMessage(), e);
if (CutEnum.EN.getValue().equals(paramsReportDetailVO.getCut())) {
@@ -2520,8 +2544,9 @@ public class ParamsReportDetailEOServiceImpl extends ServiceImpl<ParamsReportDet
} else {
throw new JeroBootException("下载文件失败,请重试");
}
} finally {
IOUtils.closeQuietly(os);
// IOUtils.closeQuietly(os);
IOUtils.closeQuietly(excelOS);
File tempZipFile = new File(uploadpath + "/tempZip");
FileUtil.deleteContents(tempZipFile);