ywf пре 8 часа
родитељ
комит
b193804ec3

+ 2 - 1
onemap-api/onemap-api-system/src/main/java/com/onemap/system/api/factory/SpatialFallbackFactory.java

@@ -14,6 +14,7 @@ public class SpatialFallbackFactory implements FallbackFactory<SpatialService> {
 
     @Override
     public SpatialService create(Throwable cause) {
+        log.error("调用空间服务 onemap-spatial 失败,已进入降级处理", cause);
         return new SpatialService() {
             @Override
             public RequestResult getImage(WktsVo wktsVo) {
@@ -31,4 +32,4 @@ public class SpatialFallbackFactory implements FallbackFactory<SpatialService> {
             }
         };
     }
-}
+}

+ 98 - 28
onemap-modules/onemap-analyse/src/main/java/com/onemap/analyse/service/impl/ReportServiceImpl.java

@@ -26,6 +26,7 @@ import com.onemap.system.api.ApplyService;
 import com.onemap.system.api.SpatialService;
 import com.onemap.system.api.domain.PolygonDataVo;
 import com.onemap.system.api.domain.WktsVo;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.io.FileUtils;
 import org.apache.poi.util.Units;
 import org.apache.poi.xwpf.usermodel.*;
@@ -43,6 +44,7 @@ import java.util.*;
  * 生成报告
  */
 @Service
+@Slf4j
 public class ReportServiceImpl implements IReportService {
     @Resource
     private FzxzMapper fzxzMapper;
@@ -81,10 +83,14 @@ public class ReportServiceImpl implements IReportService {
 
     // 根据选址任务生成报告
     public FzxzReport createReport(String bsm, List<String> dkIds) {
+        long startTime = System.currentTimeMillis();
+        log.info("[选址报告] 开始生成,bsm={},dkIds={},temp={}", bsm, dkIds, temp);
         // 保存生成报告日志
         iLogService.saveLog(bsm, "智能选址", "开始生成选址报告", "info");
 
         FzxzEntityDTO res = fzxzMapper.GetFzxzByBsm(bsm);
+        log.info("[选址报告] 查询任务完成,bsm={},任务存在={},geomId={}", bsm, res != null,
+                res == null ? null : res.getGeomId());
         FzxzReport fzxzReport = new FzxzReport();
         if (res != null) {
             // 文件硬盘真实路径
@@ -95,10 +101,20 @@ public class ReportServiceImpl implements IReportService {
 
             File f = new File(allPath);
             if (!f.exists()) {
-                f.mkdirs();
+                boolean created = f.mkdirs();
+                log.info("[选址报告] 创建目录,bsm={},path={},created={},exists={}",
+                        bsm, f.getAbsolutePath(), created, f.exists());
             }
             String reportPath = "选址报告_" + timeStamp + ".docx";
-            createReport(res, allPath + "/" + reportPath, dkIds);
+            String fullReportPath = allPath + "/" + reportPath;
+            log.info("[选址报告] 准备写入Word,bsm={},path={}", bsm, fullReportPath);
+            createReport(res, fullReportPath, dkIds);
+            File wordFile = new File(fullReportPath);
+            File pdfFile = new File(fullReportPath.replace(".docx", ".pdf"));
+            log.info("[选址报告] 生成调用结束,bsm={},wordExists={},wordBytes={},pdfExists={},pdfBytes={},耗时={}ms",
+                    bsm, wordFile.exists(), wordFile.exists() ? wordFile.length() : -1,
+                    pdfFile.exists(), pdfFile.exists() ? pdfFile.length() : -1,
+                    System.currentTimeMillis() - startTime);
             // 生成返回结果
             fzxzReport.setReportFile(filePath + "/" + reportPath);
             fzxzReport.setReportPdfFile(filePath + "/" + reportPath.replace(".docx", ".pdf"));
@@ -125,13 +141,22 @@ public class ReportServiceImpl implements IReportService {
      * @param dkIds      没有就导出全部地块
      */
     private void createReport(FzxzEntityDTO res, String reportPath, List<String> dkIds) {
-        GeomRes geomRes = shpFileMapper.getOne(res.getGeomId());
+        long startTime = System.currentTimeMillis();
+        String stage = "查询选址范围";
+        log.info("[选址报告] 进入文档生成,bsm={},geomId={},dkIds={},path={}",
+                res.getBsm(), res.getGeomId(), dkIds, reportPath);
+        GeomRes geomRes = null;
 
         // List<String> imgList = ReportImg(res, xzbsmList);
         // 创建document文档对象对象实例
         XWPFDocument document = null;
         OutputStream outputStream = null;// 把doc输出到输出流
         try {
+            geomRes = shpFileMapper.getOne(res.getGeomId());
+            log.info("[选址报告] 选址范围查询完成,bsm={},geomExists={},geomLength={}",
+                    res.getBsm(), geomRes != null,
+                    geomRes == null || geomRes.getGeom() == null ? -1 : geomRes.getGeom().length());
+            stage = "创建Word文档";
             document = new XWPFDocument();
             int pos = 0;
             // 0、文本标题
@@ -174,6 +199,7 @@ public class ReportServiceImpl implements IReportService {
             tabYzTitles.add(tableTitle);
 
             // 获取全部的因子,用于进行因子分类
+            stage = "查询并整理影响因子";
             QueryWrapper<FzxzFactorDTO> factorWrapper = new QueryWrapper<>();
             factorWrapper.eq("status", 1);
             factorWrapper.orderByAsc("order_index");
@@ -192,6 +218,8 @@ public class ReportServiceImpl implements IReportService {
             QueryWrapper<FactorUseDTO> wrapper = new QueryWrapper<>();
             wrapper.eq("task_id", res.getBsm());
             List<FactorUseDTO> fzxzXzyzDTOList = fzxzXzyzMapper.selectList(wrapper);
+            log.info("[选址报告] 影响因子查询完成,bsm={},配置因子数={},任务因子数={}",
+                    res.getBsm(), fzxzFactorDTOS.size(), fzxzXzyzDTOList.size());
             List<Map<String, Object>> dataTablelist = new ArrayList<>();
             for (int i = 0; i < fzxzXzyzDTOList.size(); i++) {
                 FactorUseDTO factorUseDTO = fzxzXzyzDTOList.get(i);
@@ -225,13 +253,17 @@ public class ReportServiceImpl implements IReportService {
             NpoiHelper.content(document, fwfx, pos++);
 
             // // 获取插入图片
+            stage = "生成选址范围图片";
             ReportImage reportImage = getWktImage(geomRes.getGeom(), 400);
-
-            XWPFParagraph imageParagraph = document.createParagraph();
-            imageParagraph.setAlignment(ParagraphAlignment.CENTER); // Center align the image
-            XWPFRun imageRun = imageParagraph.createRun();
-            imageRun.addPicture(reportImage.getInputStream(), XWPFDocument.PICTURE_TYPE_PNG, null, Units.toEMU(reportImage.getUseWidth()), Units.toEMU(reportImage.getUseHeight()));
-            pos++;
+            if (reportImage != null) {
+                XWPFParagraph imageParagraph = document.createParagraph();
+                imageParagraph.setAlignment(ParagraphAlignment.CENTER); // Center align the image
+                XWPFRun imageRun = imageParagraph.createRun();
+                imageRun.addPicture(reportImage.getInputStream(), XWPFDocument.PICTURE_TYPE_PNG, null, Units.toEMU(reportImage.getUseWidth()), Units.toEMU(reportImage.getUseHeight()));
+                pos++;
+            } else {
+                NpoiHelper.content(document, "(选址范围示意图暂无法生成)", pos++, ParagraphAlignment.CENTER);
+            }
 
             // 添加分页
             XWPFParagraph pageBreakParagraph1 = document.createParagraph();
@@ -240,8 +272,11 @@ public class ReportServiceImpl implements IReportService {
             pos++;
 
             // 三、选址分析
+            stage = "查询意向地块";
             NpoiHelper.catalog(document, "三、选址分析", pos++);
             List<SelectionResDTO> fzxzJgGisDTOList = fzxzResMapper.getListByRwbsm(res.getBsm(), dkIds);
+            log.info("[选址报告] 意向地块查询完成,bsm={},dkIds={},地块数={}",
+                    res.getBsm(), dkIds, fzxzJgGisDTOList.size());
             String ydmc = res.getYdmc();
             if (!StringUtils.isEmpty(ydmc)) {
                 if (ydmc.lastIndexOf("用地") == ydmc.length() - 2) {
@@ -253,13 +288,16 @@ public class ReportServiceImpl implements IReportService {
             }
 
             // 获取规划信息
+            stage = "查询规划图层配置";
             List<Map<String, String>> tableSortRes = getCascadeList();
+            log.info("[选址报告] 规划图层配置查询完成,bsm={},配置数={}", res.getBsm(), tableSortRes.size());
             PolygonDataVo polygonDataVo = new PolygonDataVo();
             polygonDataVo.setSourceLayerId(tableSortRes.get(0).get("tableId"));
             polygonDataVo.setSourceLayerType("1");
 
             // 遍历地块信息
             for (int i = 0; i < fzxzJgGisDTOList.size(); i++) {
+                stage = "生成第" + (i + 1) + "个地块内容";
                 if (i != 0) {
                     // 添加分页
                     XWPFParagraph pageBreakParagraph2 = document.createParagraph();
@@ -319,8 +357,12 @@ public class ReportServiceImpl implements IReportService {
                 ReportImage imageTable = getWktImage(geomWkt, 300);
                 XWPFParagraph paraImag = row.getCell(0).addParagraph();
                 paraImag.setAlignment(ParagraphAlignment.CENTER); // 居中对齐
-                XWPFRun run = paraImag.createRun();
-                run.addPicture(imageTable.getInputStream(), XWPFDocument.PICTURE_TYPE_PNG, null, Units.toEMU(imageTable.getUseWidth()), Units.toEMU(imageTable.getUseHeight()));
+                if (imageTable != null) {
+                    XWPFRun run = paraImag.createRun();
+                    run.addPicture(imageTable.getInputStream(), XWPFDocument.PICTURE_TYPE_PNG, null, Units.toEMU(imageTable.getUseWidth()), Units.toEMU(imageTable.getUseHeight()));
+                } else {
+                    paraImag.createRun().setText("地块位置示意图暂无法生成");
+                }
 
                 /**
                  * 2、地块规划信息
@@ -425,7 +467,7 @@ public class ReportServiceImpl implements IReportService {
                     if (wktInfos.size() == 2) continue;
 
                     String imagePath = reportImg(wktInfos);
-                    if (imagePath.equals("")) continue;
+                    if (StringUtils.isEmpty(imagePath)) continue;
                     // 获取插入标题、图片
                     NpoiHelper.content(document, "", pos++, ParagraphAlignment.CENTER);
                     // 图片标题
@@ -436,27 +478,39 @@ public class ReportServiceImpl implements IReportService {
                     }
 
                     ReportImage reportImageFactor = getPathImage(imagePath, 400);
-
-                    XWPFParagraph imageParagraphFactor = document.createParagraph();
-                    imageParagraphFactor.setAlignment(ParagraphAlignment.CENTER); // Center align the image
-                    XWPFRun imageRunFactor = imageParagraphFactor.createRun();
-                    imageRunFactor.addBreak();
-                    imageRunFactor.addPicture(reportImageFactor.getInputStream(), XWPFDocument.PICTURE_TYPE_PNG, null, Units.toEMU(reportImageFactor.getUseWidth()), Units.toEMU(reportImageFactor.getUseHeight()));
-                    pos++;
+                    if (reportImageFactor != null) {
+                        XWPFParagraph imageParagraphFactor = document.createParagraph();
+                        imageParagraphFactor.setAlignment(ParagraphAlignment.CENTER); // Center align the image
+                        XWPFRun imageRunFactor = imageParagraphFactor.createRun();
+                        imageRunFactor.addBreak();
+                        imageRunFactor.addPicture(reportImageFactor.getInputStream(), XWPFDocument.PICTURE_TYPE_PNG, null, Units.toEMU(reportImageFactor.getUseWidth()), Units.toEMU(reportImageFactor.getUseHeight()));
+                        pos++;
+                    }
 
                 }
             }
             File fileDoc = new File(reportPath);
+            stage = "写入Word文件";
+            log.info("[选址报告] 开始写入Word,bsm={},path={},父目录存在={}",
+                    res.getBsm(), fileDoc.getAbsolutePath(), fileDoc.getParentFile().exists());
             if (fileDoc.exists()) {
                 FileUtils.forceDelete(fileDoc);
             }
             // word文件输出流
             outputStream = new FileOutputStream(reportPath);
             document.write(outputStream);
+            outputStream.flush();
+            log.info("[选址报告] Word写入完成,bsm={},path={},exists={},bytes={},耗时={}ms",
+                    res.getBsm(), fileDoc.getAbsolutePath(), fileDoc.exists(),
+                    fileDoc.exists() ? fileDoc.length() : -1, System.currentTimeMillis() - startTime);
         } catch (Exception e) {
-            e.printStackTrace();
+            File failedFile = new File(reportPath);
+            log.error("[选址报告] 生成失败,bsm={},stage={},path={},exists={},bytes={}",
+                    res.getBsm(), stage, failedFile.getAbsolutePath(), failedFile.exists(),
+                    failedFile.exists() ? failedFile.length() : -1, e);
             // 插入任务日志
-            iLogService.saveLog(res.getBsm(), "辅助选址", "生成选址报告错误:" + e.getMessage(), "error");
+            iLogService.saveLog(res.getBsm(), "辅助选址",
+                    "生成选址报告错误,阶段:" + stage + ",异常:" + e.getClass().getName() + ",信息:" + e.getMessage(), "error");
         } finally {
             if (document != null) {
                 try {
@@ -475,8 +529,11 @@ public class ReportServiceImpl implements IReportService {
         }
         // 转PDF
         String outfilepath = reportPath.replace(".docx", ".pdf");
-        NpoiHelper.doc2pdf(reportPath, outfilepath);
-        System.out.println(outfilepath);
+        boolean pdfResult = NpoiHelper.doc2pdf(reportPath, outfilepath);
+        File pdfFile = new File(outfilepath);
+        log.info("[选址报告] PDF转换结束,bsm={},result={},path={},exists={},bytes={}",
+                res.getBsm(), pdfResult, pdfFile.getAbsolutePath(), pdfFile.exists(),
+                pdfFile.exists() ? pdfFile.length() : -1);
     }
 
 
@@ -618,6 +675,9 @@ public class ReportServiceImpl implements IReportService {
         wktsVo.getWktInfos().add(wktInfo);
 
         RequestResult requestResult = spatialService.getImage(wktsVo);
+        log.info("[选址报告] 单范围图片服务返回,success={},code={},message={},data={}",
+                requestResult.isSuccess(), requestResult.get("code"), requestResult.get("message"),
+                requestResult.get("data"));
         if (requestResult.isSuccess()) {
             Map<String, String> map = (Map<String, String>) requestResult.get("data");
             path = map.get("path");
@@ -638,6 +698,9 @@ public class ReportServiceImpl implements IReportService {
         wktsVo.setWktInfos(wktInfos);
 
         RequestResult requestResult = spatialService.getImage(wktsVo);
+        log.info("[选址报告] 多范围图片服务返回,wktCount={},success={},code={},message={},data={}",
+                wktInfos.size(), requestResult.isSuccess(), requestResult.get("code"),
+                requestResult.get("message"), requestResult.get("data"));
         if (requestResult.isSuccess()) {
             Map<String, String> map = (Map<String, String>) requestResult.get("data");
             path = map.get("path");
@@ -667,12 +730,19 @@ public class ReportServiceImpl implements IReportService {
      * @throws IOException
      */
     private ReportImage getPathImage(String path, int with) throws IOException {
+        File imageFile = StringUtils.isEmpty(path) ? null : new File(path);
+        log.info("[选址报告] 准备读取图片,path={},exists={},bytes={}", path,
+                imageFile != null && imageFile.exists(),
+                imageFile != null && imageFile.exists() ? imageFile.length() : -1);
+        if (imageFile == null || !imageFile.isFile() || imageFile.length() == 0) {
+            return null;
+        }
         ReportImage reportImage = new ReportImage();
-
-        System.out.println("图片路径path:" + path);
-
-        InputStream is = new FileInputStream(path);
-        BufferedImage bufferedImage = ImageIO.read(new File(path));
+        BufferedImage bufferedImage = ImageIO.read(imageFile);
+        if (bufferedImage == null) {
+            return null;
+        }
+        InputStream is = new FileInputStream(imageFile);
         int originalWidth = bufferedImage.getWidth();
         int originalHeight = bufferedImage.getHeight();
         int useWidth = with; // Set the desired width

+ 1 - 1
onemap-modules/onemap-file/pom.xml

@@ -214,4 +214,4 @@
         </plugins>
     </build>
 
-</project>
+</project>

+ 5 - 5
onemap-modules/onemap-model/src/main/java/com/onemap/sanya/controller/spatial/ZDAnalyseController.java

@@ -389,15 +389,15 @@ public class ZDAnalyseController extends BaseController {
             jtmj = getaDouble(instertArea, jtdlData, jtmj, dlmc,dlbm, index);
                 jtFeatures.add(superMapFreature);
                 //青苗判断
-                if (smflCode.startsWith(dlbm)) {
+                if (dlbm != null && dlbm.startsWith(smflCode)) {
                     smMj += instertArea;
                     qmFreatures.add(superMapFreature);
-                } else if (nzwflCode.startsWith(dlbm)){
-                    jjzwMj += instertArea;
-                    qmFreatures.add(superMapFreature);
-                } else if (jjzwflCode.startsWith(dlbm)) {
+                } else if (dlbm != null && dlbm.startsWith(nzwflCode)){
                     nzwMj += instertArea;
                     qmFreatures.add(superMapFreature);
+                } else if (dlbm != null && dlbm.startsWith(jjzwflCode)) {
+                    jjzwMj += instertArea;
+                    qmFreatures.add(superMapFreature);
 
                 }
             } else {

+ 12 - 4
onemap-modules/onemap-spatial/src/main/java/com/onemap/spatial/controller/ImageController.java

@@ -3,6 +3,7 @@ package com.onemap.spatial.controller;
 import com.onemap.common.core.web.domain.RequestResult;
 import com.onemap.spatial.domain.WktsVo;
 import com.onemap.spatial.service.IImageService;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -14,15 +15,22 @@ import java.util.Map;
 
 @RestController
 @RequestMapping("/image")
+@Slf4j
 public class ImageController {
     @Resource
     private IImageService imageService;
 
     @PostMapping("/sensing")
     public RequestResult getImage(@RequestBody WktsVo wktsVo) throws Exception {
-        String path = imageService.getSensingImage(wktsVo);
-        Map<String, String> map = new HashMap<>();
-        map.put("path", path);
-        return RequestResult.success(map);
+        try {
+            String path = imageService.getSensingImage(wktsVo);
+            Map<String, String> map = new HashMap<>();
+            map.put("path", path);
+            return RequestResult.success(map);
+        } catch (Exception e) {
+            int wktCount = wktsVo == null || wktsVo.getWktInfos() == null ? 0 : wktsVo.getWktInfos().size();
+            log.error("生成选址报告地图图片失败,wktCount={}", wktCount, e);
+            throw e;
+        }
     }
 }

+ 3 - 1
onemap-modules/onemap-spatial/src/main/java/com/onemap/spatial/service/impl/ShpFileSaveServiceImpl.java

@@ -151,7 +151,9 @@ public class ShpFileSaveServiceImpl implements IShpFileSaveService {
                 attributesList.add(h.getLocalName());
                 Map<String, String> attributesMap = new LinkedHashMap<>();
                 if (!h.getLocalName().toLowerCase().equals("the_geom")) {
-                    attributesMap.put("key", h.getLocalName().toLowerCase());
+                    // id 为系统生成的主键字段,SHP 属性中的同名字段需避免与其冲突。
+                    String fieldName = "id".equalsIgnoreCase(h.getLocalName()) ? "shpId" : h.getLocalName().toLowerCase();
+                    attributesMap.put("key", fieldName);
                     attributesMap.put("value", type);
                     tableCommsList.add(attributesMap);
                 }