吉安感知网项目-后端
rain
2026-01-23 7473859cd3ee464fde053435f7c2da5aab71aa9b
drone-service/drone-gd/src/main/java/org/sxkj/gd/workorder/utils/GdPatrolReportWordUtil.java
@@ -38,6 +38,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springblade.core.tool.utils.StringUtil;
import org.sxkj.gd.utils.GdGeoAddressUtil;
import org.sxkj.gd.workorder.entity.GdPatrolTaskEntity;
import org.sxkj.gd.workorder.entity.GdTaskResultEntity;
@@ -101,9 +102,13 @@
            CompletableFuture<Map<String, byte[]>> qrCodeFuture = CompletableFuture.supplyAsync(
                () -> preloadQrCodes(results), RESOURCE_EXECUTOR
            );
            CompletableFuture.allOf(imageFuture, qrCodeFuture).join();
            CompletableFuture<Map<String, String>> addressFuture = CompletableFuture.supplyAsync(
                () -> preloadAddresses(results), RESOURCE_EXECUTOR
            );
            CompletableFuture.allOf(imageFuture, qrCodeFuture, addressFuture).join();
            Map<String, byte[]> imageCache = imageFuture.get();
            Map<String, byte[]> qrCodeCache = qrCodeFuture.get();
            Map<String, String> addressCache = addressFuture.get();
            createTitle(document, title);
            createSectionHeader(document, "一、任务详情");
@@ -111,7 +116,7 @@
            int resultCount = results.size();
            createSectionHeader(document, "二、巡查结果(" + resultCount + "件)");
            addResultDetails(document, results, imageCache, qrCodeCache);
            addResultDetails(document, results, imageCache, qrCodeCache, addressCache);
            document.write(fos);
            return reportFile;
@@ -163,7 +168,8 @@
    private static void addResultDetails(XWPFDocument document,
                                         List<GdTaskResultEntity> results,
                                         Map<String, byte[]> imageCache,
                                         Map<String, byte[]> qrCodeCache)
                                         Map<String, byte[]> qrCodeCache,
                                         Map<String, String> addressCache)
        throws IOException, InvalidFormatException {
        if (results == null || results.isEmpty()) {
            addDetailItem(document, "/");
@@ -209,7 +215,8 @@
            currentRow++;
            setTableCellWithBoldAndCenter(resultTable, currentRow, 1, "成果地址");
            setTableCellWithSpacing(resultTable, currentRow, 2, "/");
            String address = getAddressFromCache(result, addressCache);
            setTableCellWithSpacing(resultTable, currentRow, 2, formatString(address));
            currentRow++;
            setTableCellWithBoldAndCenter(resultTable, currentRow, 1, "成果定位");
@@ -554,6 +561,39 @@
        return qrCodeCache;
    }
    private static Map<String, String> preloadAddresses(List<GdTaskResultEntity> results) {
        if (results == null || results.isEmpty()) {
            return Collections.emptyMap();
        }
        List<GdTaskResultEntity> needAddressResults = results.stream()
            .filter(result -> result.getLongitude() != null && result.getLatitude() != null)
            .collect(Collectors.toList());
        if (needAddressResults.isEmpty()) {
            return Collections.emptyMap();
        }
        Map<String, String> addressCache = new ConcurrentHashMap<>();
        List<CompletableFuture<Void>> futures = needAddressResults.stream()
            .map(result -> CompletableFuture.runAsync(() -> {
                String key = buildCoordinateKey(result.getLongitude(), result.getLatitude());
                if (StringUtil.isBlank(key) || addressCache.containsKey(key)) {
                    return;
                }
                String address = GdGeoAddressUtil.getFormattedAddress(result.getLongitude(), result.getLatitude());
                if (!StringUtil.isBlank(address)) {
                    addressCache.put(key, address);
                }
            }, RESOURCE_EXECUTOR))
            .collect(Collectors.toList());
        try {
            CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join();
        } catch (Exception e) {
            logger.error("等待成果地址获取完成时发生异常", e);
        }
        return addressCache;
    }
    private static byte[] downloadImage(String urlString) throws IOException {
        URL url = new URL(urlString);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
@@ -628,6 +668,24 @@
        return String.format(Locale.CHINA, "%.6f", coordinate);
    }
    private static String getAddressFromCache(GdTaskResultEntity result, Map<String, String> addressCache) {
        if (result == null || addressCache == null || addressCache.isEmpty()) {
            return null;
        }
        String key = buildCoordinateKey(result.getLongitude(), result.getLatitude());
        if (StringUtil.isBlank(key)) {
            return null;
        }
        return addressCache.get(key);
    }
    private static String buildCoordinateKey(Double longitude, Double latitude) {
        if (longitude == null || latitude == null) {
            return "";
        }
        return formatCoordinateValue(longitude) + "," + formatCoordinateValue(latitude);
    }
    private static int findImageFormat(String url) {
        String cleanUrl = url;
        int queryIndex = url.indexOf("?");