From ddaa44400aa478058ffe9349d59904a130b7ce9c Mon Sep 17 00:00:00 2001
From: feiyu02 <risaku@163.com>
Date: 星期四, 28 八月 2025 17:33:11 +0800
Subject: [PATCH] 2025.8.28 1. 新增走航任务统计功能(待完成)

---
 src/main/kotlin/com/flightfeather/uav/common/file/Docx4jGenerator.kt |  228 ++++++++++++++++++++++++++++----------------------------
 1 files changed, 114 insertions(+), 114 deletions(-)

diff --git a/src/main/kotlin/com/flightfeather/uav/common/file/Docx4jGenerator.kt b/src/main/kotlin/com/flightfeather/uav/common/file/Docx4jGenerator.kt
index d33e105..8b14f83 100644
--- a/src/main/kotlin/com/flightfeather/uav/common/file/Docx4jGenerator.kt
+++ b/src/main/kotlin/com/flightfeather/uav/common/file/Docx4jGenerator.kt
@@ -1,114 +1,114 @@
-package com.flightfeather.uav.common.file
-
-import freemarker.template.Configuration
-import freemarker.template.Template
-
-import org.docx4j.openpackaging.packages.WordprocessingMLPackage
-import org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart
-import java.io.ByteArrayInputStream
-import java.io.ByteArrayOutputStream
-import java.io.File
-import java.io.OutputStreamWriter
-import java.nio.charset.StandardCharsets
-
-/**
- * Word鏂囦欢鐢熸垚鍣紙鍩轰簬Docx4j + FreeMarker锛�
- * @date 2025/8/28 09:29
- * @author feiyu
- */
-class Docx4jGenerator(
-    private val templatePath: String,
-    private val freemarkerConfig: Configuration = defaultFreemarkerConfig()
-) {
-    private var wordMLPackage: WordprocessingMLPackage? = null
-    private var mainDocumentPart: MainDocumentPart? = null
-
-    /**
-     * 鍒涘缓Word鏂囨。鍖�
-     */
-    fun loadTemplate(): Docx4jGenerator {
-        wordMLPackage = WordprocessingMLPackage.createPackage()
-        mainDocumentPart = wordMLPackage?.mainDocumentPart
-
-        return this
-    }
-
-    /**
-     * 浣跨敤FreeMarker濉厖妯℃澘鏁版嵁
-     */
-    fun fillData(dataModel: Map<String, Any>): Docx4jGenerator {
-        val template = freemarkerConfig.getTemplate(templatePath.substringAfterLast("/"))
-        val xmlContent = renderTemplate(template, dataModel)
-
-        mainDocumentPart?.unmarshal(ByteArrayInputStream(xmlContent.toByteArray(StandardCharsets.UTF_8)))
-        return this
-    }
-
-    /**
-     * 娣诲姞鍥剧墖鍒癢ord鏂囨。
-     * @param imagePath 鍥剧墖璺緞
-     * @param width 瀹藉害(鍍忕礌)
-     * @param height 楂樺害(鍍忕礌)
-     * @param paragraphId 娈佃惤ID锛屾寚瀹氬浘鐗囨彃鍏ヤ綅缃�
-     */
-    fun addImage(imagePath: String, width: Int, height: Int, paragraphId: String): Docx4jGenerator {
-        // 瀹炵幇鍥剧墖娣诲姞閫昏緫
-        return this
-    }
-
-    /**
-     * 娣诲姞琛ㄦ牸鍒癢ord鏂囨。
-     * @param data 琛ㄦ牸鏁版嵁
-     * @param paragraphId 娈佃惤ID锛屾寚瀹氳〃鏍兼彃鍏ヤ綅缃�
-     */
-    fun addTable(data: List<List<String>>, paragraphId: String): Docx4jGenerator {
-        // 瀹炵幇琛ㄦ牸娣诲姞閫昏緫
-        return this
-    }
-
-    /**
-     * 淇濆瓨鐢熸垚鐨刉ord鏂囦欢
-     * @param outputPath 杈撳嚭鏂囦欢璺緞
-     */
-    fun save(outputPath: String) {
-        wordMLPackage?.save(File(outputPath))
-    }
-
-    /**
-     * 浣跨敤FreeMarker娓叉煋妯℃澘
-     */
-    private fun renderTemplate(template: Template, dataModel: Map<String, Any>): String {
-        val outputStream = ByteArrayOutputStream()
-        val writer = OutputStreamWriter(outputStream, StandardCharsets.UTF_8)
-        template.process(dataModel, writer)
-        writer.flush()
-        return outputStream.toString(StandardCharsets.UTF_8.name())
-    }
-
-    companion object {
-        /**
-         * 榛樿FreeMarker閰嶇疆
-         */
-        fun defaultFreemarkerConfig(): Configuration {
-            val config = Configuration(Configuration.VERSION_2_3_31)
-            config.defaultEncoding = "UTF-8"
-            config.setClassForTemplateLoading(Docx4jGenerator::class.java, "/templates")
-            return config
-        }
-
-        /**
-         * 绠�鍖栬皟鐢ㄧ殑闈欐�佹柟娉�
-         */
-        fun generate(
-            templatePath: String,
-            outputPath: String,
-            dataModel: Map<String, Any>,
-            config: Configuration = defaultFreemarkerConfig()
-        ) {
-            Docx4jGenerator(templatePath, config)
-                .loadTemplate()
-                .fillData(dataModel)
-                .save(outputPath)
-        }
-    }
-}
\ No newline at end of file
+//package com.flightfeather.uav.common.file
+//
+//import freemarker.template.Configuration
+//import freemarker.template.Template
+//
+//import org.docx4j.openpackaging.packages.WordprocessingMLPackage
+//import org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart
+//import java.io.ByteArrayInputStream
+//import java.io.ByteArrayOutputStream
+//import java.io.File
+//import java.io.OutputStreamWriter
+//import java.nio.charset.StandardCharsets
+//
+///**
+// * Word鏂囦欢鐢熸垚鍣紙鍩轰簬Docx4j + FreeMarker锛�
+// * @date 2025/8/28 09:29
+// * @author feiyu
+// */
+//class Docx4jGenerator(
+//    private val templatePath: String,
+//    private val freemarkerConfig: Configuration = defaultFreemarkerConfig()
+//) {
+//    private var wordMLPackage: WordprocessingMLPackage? = null
+//    private var mainDocumentPart: MainDocumentPart? = null
+//
+//    /**
+//     * 鍒涘缓Word鏂囨。鍖�
+//     */
+//    fun loadTemplate(): Docx4jGenerator {
+//        wordMLPackage = WordprocessingMLPackage.createPackage()
+//        mainDocumentPart = wordMLPackage?.mainDocumentPart
+//
+//        return this
+//    }
+//
+//    /**
+//     * 浣跨敤FreeMarker濉厖妯℃澘鏁版嵁
+//     */
+//    fun fillData(dataModel: Map<String, Any>): Docx4jGenerator {
+//        val template = freemarkerConfig.getTemplate(templatePath.substringAfterLast("/"))
+//        val xmlContent = renderTemplate(template, dataModel)
+//
+//        mainDocumentPart?.unmarshal(ByteArrayInputStream(xmlContent.toByteArray(StandardCharsets.UTF_8)))
+//        return this
+//    }
+//
+//    /**
+//     * 娣诲姞鍥剧墖鍒癢ord鏂囨。
+//     * @param imagePath 鍥剧墖璺緞
+//     * @param width 瀹藉害(鍍忕礌)
+//     * @param height 楂樺害(鍍忕礌)
+//     * @param paragraphId 娈佃惤ID锛屾寚瀹氬浘鐗囨彃鍏ヤ綅缃�
+//     */
+//    fun addImage(imagePath: String, width: Int, height: Int, paragraphId: String): Docx4jGenerator {
+//        // 瀹炵幇鍥剧墖娣诲姞閫昏緫
+//        return this
+//    }
+//
+//    /**
+//     * 娣诲姞琛ㄦ牸鍒癢ord鏂囨。
+//     * @param data 琛ㄦ牸鏁版嵁
+//     * @param paragraphId 娈佃惤ID锛屾寚瀹氳〃鏍兼彃鍏ヤ綅缃�
+//     */
+//    fun addTable(data: List<List<String>>, paragraphId: String): Docx4jGenerator {
+//        // 瀹炵幇琛ㄦ牸娣诲姞閫昏緫
+//        return this
+//    }
+//
+//    /**
+//     * 淇濆瓨鐢熸垚鐨刉ord鏂囦欢
+//     * @param outputPath 杈撳嚭鏂囦欢璺緞
+//     */
+//    fun save(outputPath: String) {
+//        wordMLPackage?.save(File(outputPath))
+//    }
+//
+//    /**
+//     * 浣跨敤FreeMarker娓叉煋妯℃澘
+//     */
+//    private fun renderTemplate(template: Template, dataModel: Map<String, Any>): String {
+//        val outputStream = ByteArrayOutputStream()
+//        val writer = OutputStreamWriter(outputStream, StandardCharsets.UTF_8)
+//        template.process(dataModel, writer)
+//        writer.flush()
+//        return outputStream.toString(StandardCharsets.UTF_8.name())
+//    }
+//
+//    companion object {
+//        /**
+//         * 榛樿FreeMarker閰嶇疆
+//         */
+//        fun defaultFreemarkerConfig(): Configuration {
+//            val config = Configuration(Configuration.VERSION_2_3_31)
+//            config.defaultEncoding = "UTF-8"
+//            config.setClassForTemplateLoading(Docx4jGenerator::class.java, "/templates")
+//            return config
+//        }
+//
+//        /**
+//         * 绠�鍖栬皟鐢ㄧ殑闈欐�佹柟娉�
+//         */
+//        fun generate(
+//            templatePath: String,
+//            outputPath: String,
+//            dataModel: Map<String, Any>,
+//            config: Configuration = defaultFreemarkerConfig()
+//        ) {
+//            Docx4jGenerator(templatePath, config)
+//                .loadTemplate()
+//                .fillData(dataModel)
+//                .save(outputPath)
+//        }
+//    }
+//}
\ No newline at end of file

--
Gitblit v1.9.3