|
@@ -72,6 +72,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.core.io.ByteArrayResource;
|
|
|
import org.springframework.core.io.Resource;
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
+import org.springframework.http.ContentDisposition;
|
|
|
import org.springframework.http.HttpHeaders;
|
|
|
import org.springframework.http.MediaType;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
@@ -95,6 +96,7 @@ import java.math.BigInteger;
|
|
|
import java.math.MathContext;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.net.URLEncoder;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
import java.util.function.Function;
|
|
@@ -4477,8 +4479,8 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
|
|
|
@Override
|
|
|
public ResponseEntity<Resource> exportTree(Long contractId, HttpServletResponse response) throws IOException, InvalidFormatException {
|
|
|
- String templatePath = "/mnt/sdc/Users/hongchuangyanfa/Desktop/excel/gcdcTemplate.xlsx";
|
|
|
- //String templatePath = "C:\\upload\\excel\\gcdc.xlsx";
|
|
|
+ //String templatePath = "/mnt/sdc/Users/hongchuangyanfa/Desktop/excel/gcdcTemplate.xlsx";
|
|
|
+ String templatePath = "C:\\upload\\excel\\gcdc.xlsx";
|
|
|
// 查询数据
|
|
|
String sql = "select * from m_wbs_tree_contract where contract_id = " + contractId +
|
|
|
" and is_deleted = 0 and type = 1 and node_type != 6 and p_id != 0";
|
|
@@ -4504,8 +4506,8 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
.collect(Collectors.toMap(
|
|
|
WbsTreeContract::getPKeyId,
|
|
|
unit -> list.stream()
|
|
|
- .filter(item -> item.getAncestors() != null &&
|
|
|
- item.getAncestors().contains(unit.getPKeyId().toString()))
|
|
|
+ .filter(item -> item.getAncestorsPId() != null &&
|
|
|
+ item.getAncestorsPId().contains(unit.getPKeyId().toString()))
|
|
|
.collect(Collectors.toList())
|
|
|
));
|
|
|
|
|
@@ -4513,15 +4515,17 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
for (Map.Entry<Long, List<WbsTreeContract>> entry : unitProjectMap.entrySet()) {
|
|
|
Long unitId = entry.getKey();
|
|
|
List<WbsTreeContract> unitProjects = entry.getValue();
|
|
|
-
|
|
|
- // 获取单位工程名称
|
|
|
- String unitName = unitProjects.stream()
|
|
|
- .filter(item -> item.getPKeyId().equals(unitId))
|
|
|
- .findFirst()
|
|
|
- .map(WbsTreeContract::getNodeName)
|
|
|
- .orElse("未知单位工程");
|
|
|
+ String sql1="Select * from m_wbs_tree_contract where p_key_id="+unitId;
|
|
|
+ WbsTreeContract unitNode=jdbcTemplate.queryForObject(sql1,new BeanPropertyRowMapper<>(WbsTreeContract.class));
|
|
|
+ unitProjects.add(unitNode);
|
|
|
+// // 获取单位工程名称
|
|
|
+// String unitName = unitProjects.stream()
|
|
|
+// .filter(item -> item.getPKeyId().equals(unitId))
|
|
|
+// .findFirst()
|
|
|
+// .map(WbsTreeContract::getNodeName)
|
|
|
+// .orElse("未知单位工程");
|
|
|
// 创建安全的sheet名称
|
|
|
- String safeUnitName = unitName.replaceAll("[\\\\/*\\[\\]:?]", "_");
|
|
|
+ String safeUnitName = unitNode.getNodeName().replaceAll("[\\\\/*\\[\\]:?]", "_");
|
|
|
if (safeUnitName.length() > 31) {
|
|
|
safeUnitName = safeUnitName.substring(0, 31);
|
|
|
}
|
|
@@ -4547,8 +4551,8 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
}
|
|
|
|
|
|
//保存文件到本地(本地测试放开,正式环境不需要)
|
|
|
-// String outputPath = "C:\\upload\\excel\\111.xlsx";
|
|
|
-// saveWorkbookToFile(workbook, outputPath);
|
|
|
+ String outputPath = "C:\\upload\\excel\\111.xlsx";
|
|
|
+ saveWorkbookToFile(workbook, outputPath);
|
|
|
|
|
|
// 同时返回给浏览器下载
|
|
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
|
@@ -4558,13 +4562,15 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
ByteArrayResource resource = new ByteArrayResource(outputStream.toByteArray());
|
|
|
|
|
|
|
|
|
- // 对中文文件名进行URL编码
|
|
|
+ // 在return语句前:
|
|
|
String filename = "划分导出(请勿修改隐藏列).xlsx";
|
|
|
- String encodedFilename = URLEncoder.encode(filename, "UTF-8")
|
|
|
- .replaceAll("\\+", "%20"); // 替换+号为%20,确保兼容性
|
|
|
+ String encodedFilename = URLEncoder.encode(filename, String.valueOf(StandardCharsets.UTF_8))
|
|
|
+ .replaceAll("\\+", "%20");
|
|
|
+
|
|
|
+ String contentDisposition = "attachment; filename=\"" + filename + "\"; filename*=utf-8''" + encodedFilename;
|
|
|
|
|
|
return ResponseEntity.ok()
|
|
|
- .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + encodedFilename + "\"; filename*=utf-8''" + encodedFilename)
|
|
|
+ .header(HttpHeaders.CONTENT_DISPOSITION, contentDisposition)
|
|
|
.contentType(MediaType.APPLICATION_OCTET_STREAM)
|
|
|
.contentLength(resource.contentLength())
|
|
|
.body(resource);
|
|
@@ -4795,13 +4801,14 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
Row row = sheet.createRow(rowNum);
|
|
|
|
|
|
// 解析祖级节点
|
|
|
- String[] ancestors = leafNode.getAncestors().split(",");
|
|
|
+ String[] ancestors = leafNode.getAncestorsPId().split(",");
|
|
|
|
|
|
// 转换为 List<Long>
|
|
|
List<Long> ancestorIds = Arrays.stream(ancestors)
|
|
|
.map(Long::parseLong)
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
+ ancestorIds.add(leafNode.getPKeyId());
|
|
|
// 根据叶子节点类型填充各级工程数据
|
|
|
fillEngineeringDataByLeafType(row, unitProjects, ancestorIds, mergeMap, rowNum, centerStyle, leafNode.getNodeType());
|
|
|
|
|
@@ -5143,29 +5150,34 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
|
|
|
// 合并单列并设置样式(检查是否已存在)
|
|
|
private void mergeSingleColumnIfNotExists(Sheet sheet, int col, int startRow, int endRow, CellStyle style, Set<String> mergedRegions) {
|
|
|
- String regionKey = col + ":" + startRow + ":" + endRow;
|
|
|
-
|
|
|
- if (!mergedRegions.contains(regionKey)) {
|
|
|
- CellRangeAddress mergedRegion = new CellRangeAddress(startRow, endRow, col, col);
|
|
|
-
|
|
|
- // 检查是否已经存在相同的合并区域
|
|
|
- boolean alreadyExists = false;
|
|
|
- for (int i = 0; i < sheet.getNumMergedRegions(); i++) {
|
|
|
- CellRangeAddress existingRegion = sheet.getMergedRegion(i);
|
|
|
- if (existingRegion.getFirstColumn() == col &&
|
|
|
- existingRegion.getFirstRow() == startRow &&
|
|
|
- existingRegion.getLastRow() == endRow) {
|
|
|
- alreadyExists = true;
|
|
|
- break;
|
|
|
+ try {
|
|
|
+ String regionKey = col + ":" + startRow + ":" + endRow;
|
|
|
+
|
|
|
+ if (!mergedRegions.contains(regionKey)) {
|
|
|
+ CellRangeAddress mergedRegion = new CellRangeAddress(startRow, endRow, col, col);
|
|
|
+
|
|
|
+ // 检查是否已经存在相同的合并区域
|
|
|
+ boolean alreadyExists = false;
|
|
|
+ for (int i = 0; i < sheet.getNumMergedRegions(); i++) {
|
|
|
+ CellRangeAddress existingRegion = sheet.getMergedRegion(i);
|
|
|
+ if (existingRegion.getFirstColumn() == col &&
|
|
|
+ existingRegion.getFirstRow() == startRow &&
|
|
|
+ existingRegion.getLastRow() == endRow) {
|
|
|
+ alreadyExists = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- if (!alreadyExists) {
|
|
|
- sheet.addMergedRegion(mergedRegion);
|
|
|
- setMergedRegionStyle(sheet, mergedRegion, style);
|
|
|
- mergedRegions.add(regionKey);
|
|
|
+ if (!alreadyExists) {
|
|
|
+ sheet.addMergedRegion(mergedRegion);
|
|
|
+ setMergedRegionStyle(sheet, mergedRegion, style);
|
|
|
+ mergedRegions.add(regionKey);
|
|
|
+ }
|
|
|
}
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
// 判断是否是名称列
|