Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
poc-api
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
poc
poc-api
Commits
e8ea5053
Commit
e8ea5053
authored
Mar 07, 2025
by
alex yao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:内容导出
parent
7eeb97f0
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
72 additions
and
56 deletions
+72
-56
pom.xml
pom.xml
+7
-4
ContentReportDto.java
src/main/java/cn/com/poc/expose/dto/ContentReportDto.java
+28
-0
MarkdownToWordDto.java
src/main/java/cn/com/poc/expose/dto/MarkdownToWordDto.java
+0
-18
ContentReportRest.java
src/main/java/cn/com/poc/expose/rest/ContentReportRest.java
+3
-3
ContentReportRestImpl.java
...va/cn/com/poc/expose/rest/impl/ContentReportRestImpl.java
+28
-15
KnowledgeServiceTest.java
src/test/java/cn/com/poc/knowledge/KnowledgeServiceTest.java
+6
-16
No files found.
pom.xml
View file @
e8ea5053
...
@@ -212,13 +212,13 @@
...
@@ -212,13 +212,13 @@
</exclusions>
</exclusions>
</dependency>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
<dependency>
<dependency>
<groupId>
org.apache.poi
</groupId>
<groupId>
org.apache.poi
</groupId>
<artifactId>
poi-ooxml
</artifactId>
<artifactId>
poi-ooxml
</artifactId>
<version>
4.1.2
</version>
<version>
4.1.2
</version>
</dependency>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml-schemas -->
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml-schemas -->
<dependency>
<dependency>
<groupId>
org.apache.poi
</groupId>
<groupId>
org.apache.poi
</groupId>
<artifactId>
poi-ooxml-schemas
</artifactId>
<artifactId>
poi-ooxml-schemas
</artifactId>
...
@@ -352,8 +352,6 @@
...
@@ -352,8 +352,6 @@
<artifactId>
flexmark-all
</artifactId>
<artifactId>
flexmark-all
</artifactId>
<version>
0.62.2
</version>
<version>
0.62.2
</version>
</dependency>
</dependency>
<!-- Apache POI for generating Word documents -->
</dependencies>
</dependencies>
...
@@ -417,5 +415,10 @@
...
@@ -417,5 +415,10 @@
<name>
Nexus aliyun
</name>
<name>
Nexus aliyun
</name>
<url>
http://maven.aliyun.com/nexus/content/groups/public
</url>
<url>
http://maven.aliyun.com/nexus/content/groups/public
</url>
</repository>
</repository>
<repository>
<id>
com.e-iceblue
</id>
<name>
e-iceblue
</name>
<url>
https://repo.e-iceblue.cn/repository/maven-public/
</url>
</repository>
</repositories>
</repositories>
</project>
</project>
src/main/java/cn/com/poc/expose/dto/ContentReportDto.java
0 → 100644
View file @
e8ea5053
package
cn
.
com
.
poc
.
expose
.
dto
;
/**
* @author alex.yao
* @date 2025/3/7
*/
public
class
ContentReportDto
{
private
String
content
;
private
String
reportType
;
public
String
getContent
()
{
return
content
;
}
public
void
setContent
(
String
content
)
{
this
.
content
=
content
;
}
public
String
getReportType
()
{
return
reportType
;
}
public
void
setReportType
(
String
reportType
)
{
this
.
reportType
=
reportType
;
}
}
src/main/java/cn/com/poc/expose/dto/MarkdownToWordDto.java
deleted
100644 → 0
View file @
7eeb97f0
package
cn
.
com
.
poc
.
expose
.
dto
;
/**
* @author alex.yao
* @date 2025/3/7
*/
public
class
MarkdownToWordDto
{
private
String
markdown
;
public
String
getMarkdown
()
{
return
markdown
;
}
public
void
setMarkdown
(
String
markdown
)
{
this
.
markdown
=
markdown
;
}
}
src/main/java/cn/com/poc/expose/rest/
Markdown2Word
Rest.java
→
src/main/java/cn/com/poc/expose/rest/
ContentReport
Rest.java
View file @
e8ea5053
package
cn
.
com
.
poc
.
expose
.
rest
;
package
cn
.
com
.
poc
.
expose
.
rest
;
import
cn.com.poc.expose.dto.
MarkdownToWord
Dto
;
import
cn.com.poc.expose.dto.
ContentReport
Dto
;
import
cn.com.yict.framemax.core.rest.BaseRest
;
import
cn.com.yict.framemax.core.rest.BaseRest
;
import
cn.com.yict.framemax.web.permission.Access
;
import
cn.com.yict.framemax.web.permission.Access
;
import
cn.com.yict.framemax.web.permission.Permission
;
import
cn.com.yict.framemax.web.permission.Permission
;
...
@@ -13,9 +13,9 @@ import java.io.IOException;
...
@@ -13,9 +13,9 @@ import java.io.IOException;
* @date 2025/3/7
* @date 2025/3/7
*/
*/
@Permission
(
Access
.
Anonymous
)
@Permission
(
Access
.
Anonymous
)
public
interface
Markdown2Word
Rest
extends
BaseRest
{
public
interface
ContentReport
Rest
extends
BaseRest
{
String
markdown2Word
(
@RequestBody
MarkdownToWord
Dto
dto
)
throws
IOException
;
String
report
(
@RequestBody
ContentReport
Dto
dto
)
throws
IOException
;
}
}
src/main/java/cn/com/poc/expose/rest/impl/
Markdown2Word
RestImpl.java
→
src/main/java/cn/com/poc/expose/rest/impl/
ContentReport
RestImpl.java
View file @
e8ea5053
...
@@ -3,42 +3,59 @@ package cn.com.poc.expose.rest.impl;
...
@@ -3,42 +3,59 @@ package cn.com.poc.expose.rest.impl;
import
cn.com.poc.common.service.BosConfigService
;
import
cn.com.poc.common.service.BosConfigService
;
import
cn.com.poc.common.utils.StringUtils
;
import
cn.com.poc.common.utils.StringUtils
;
import
cn.com.poc.common.utils.UUIDTool
;
import
cn.com.poc.common.utils.UUIDTool
;
import
cn.com.poc.expose.dto.
MarkdownToWord
Dto
;
import
cn.com.poc.expose.dto.
ContentReport
Dto
;
import
cn.com.poc.expose.rest.
Markdown2Word
Rest
;
import
cn.com.poc.expose.rest.
ContentReport
Rest
;
import
cn.com.yict.framemax.core.exception.BusinessException
;
import
cn.com.yict.framemax.core.exception.BusinessException
;
import
com.itextpdf.text.pdf.PdfWriter
;
import
com.vladsch.flexmark.html.HtmlRenderer
;
import
com.vladsch.flexmark.html.HtmlRenderer
;
import
com.vladsch.flexmark.parser.Parser
;
import
com.vladsch.flexmark.parser.Parser
;
import
com.vladsch.flexmark.util.ast.Document
;
import
com.vladsch.flexmark.util.ast.Document
;
import
org.apache.pdfbox.io.RandomAccessBuffer
;
import
org.apache.pdfbox.io.RandomAccessBufferedFileInputStream
;
import
org.apache.pdfbox.pdfparser.PDFParser
;
import
org.apache.pdfbox.pdmodel.PDDocument
;
import
org.apache.poi.poifs.filesystem.DirectoryEntry
;
import
org.apache.poi.poifs.filesystem.DirectoryEntry
;
import
org.apache.poi.poifs.filesystem.POIFSFileSystem
;
import
org.apache.poi.poifs.filesystem.POIFSFileSystem
;
import
org.apache.poi.xwpf.usermodel.XWPFDocument
;
import
org.apache.poi.xwpf.usermodel.*
;
import
org.apache.poi.xwpf.usermodel.XWPFParagraph
;
import
org.apache.poi.xwpf.usermodel.XWPFRun
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
java.io.*
;
import
java.io.*
;
import
java.
util.UUID
;
import
java.
nio.charset.StandardCharsets
;
/**
/**
* @author alex.yao
* @author alex.yao
* @date 2025/3/7
* @date 2025/3/7
*/
*/
@Component
@Component
public
class
Markdown2WordRestImpl
implements
Markdown2Word
Rest
{
public
class
ContentReportRestImpl
implements
ContentReport
Rest
{
@Resource
@Resource
private
BosConfigService
bosConfigService
;
private
BosConfigService
bosConfigService
;
@Override
@Override
public
String
markdown2Word
(
MarkdownToWord
Dto
dto
)
throws
IOException
{
public
String
report
(
ContentReport
Dto
dto
)
throws
IOException
{
String
markdown
=
dto
.
get
Markdown
();
String
markdown
=
dto
.
get
Content
();
if
(
StringUtils
.
isBlank
(
markdown
))
{
if
(
StringUtils
.
isBlank
(
markdown
))
{
throw
new
BusinessException
(
"markdown is blank"
);
throw
new
BusinessException
(
"markdown is blank"
);
}
}
String
reportType
=
dto
.
getReportType
();
File
file
=
File
.
createTempFile
(
UUIDTool
.
getUUID
(),
"."
+
reportType
);
String
result
=
""
;
if
(
"docx"
.
equals
(
reportType
)
||
"doc"
.
equals
(
reportType
))
{
String
htmlContent
=
convertMarkdownToHtml
(
markdown
);
String
htmlContent
=
convertMarkdownToHtml
(
markdown
);
return
convertHtmlToWord
(
htmlContent
);
result
=
convertHtmlToWord
(
htmlContent
);
}
else
if
(
"html"
.
equals
(
reportType
))
{
String
htmlContent
=
convertMarkdownToHtml
(
markdown
);
result
=
bosConfigService
.
uploadFileByByteArray2Oss
(
htmlContent
.
getBytes
(),
UUIDTool
.
getUUID
(),
reportType
);
}
else
if
(
"md"
.
equals
(
reportType
))
{
result
=
bosConfigService
.
uploadFileByByteArray2Oss
(
markdown
.
getBytes
(),
UUIDTool
.
getUUID
(),
reportType
);
}
else
{
throw
new
BusinessException
(
"reportType is not supported"
);
}
file
.
delete
();
return
result
;
}
}
private
String
convertMarkdownToHtml
(
String
markdown
)
{
private
String
convertMarkdownToHtml
(
String
markdown
)
{
...
@@ -50,10 +67,6 @@ public class Markdown2WordRestImpl implements Markdown2WordRest {
...
@@ -50,10 +67,6 @@ public class Markdown2WordRestImpl implements Markdown2WordRest {
private
String
convertHtmlToWord
(
String
html
)
throws
IOException
{
private
String
convertHtmlToWord
(
String
html
)
throws
IOException
{
File
file
=
File
.
createTempFile
(
UUIDTool
.
getUUID
(),
".docx"
);
File
file
=
File
.
createTempFile
(
UUIDTool
.
getUUID
(),
".docx"
);
XWPFDocument
document
=
new
XWPFDocument
();
XWPFParagraph
paragraph
=
document
.
createParagraph
();
XWPFRun
run
=
paragraph
.
createRun
();
run
.
setText
(
html
);
FileOutputStream
outputStream
=
new
FileOutputStream
(
file
);
FileOutputStream
outputStream
=
new
FileOutputStream
(
file
);
ByteArrayInputStream
bais
=
new
ByteArrayInputStream
(
html
.
getBytes
());
//将字节数组包装到流中
ByteArrayInputStream
bais
=
new
ByteArrayInputStream
(
html
.
getBytes
());
//将字节数组包装到流中
POIFSFileSystem
poifs
=
new
POIFSFileSystem
();
POIFSFileSystem
poifs
=
new
POIFSFileSystem
();
...
...
src/test/java/cn/com/poc/knowledge/KnowledgeServiceTest.java
View file @
e8ea5053
...
@@ -3,13 +3,11 @@ package cn.com.poc.knowledge;
...
@@ -3,13 +3,11 @@ package cn.com.poc.knowledge;
import
cn.com.poc.knowledge.aggregate.KnowledgeService
;
import
cn.com.poc.knowledge.aggregate.KnowledgeService
;
import
cn.com.yict.framemax.core.spring.SingleContextInitializer
;
import
cn.com.yict.framemax.core.spring.SingleContextInitializer
;
import
com.vladsch.flexmark.html.HtmlRenderer
;
import
com.vladsch.flexmark.html.HtmlRenderer
;
import
com.vladsch.flexmark.parser.Parser
;
import
com.vladsch.flexmark.util.ast.Document
;
import
com.vladsch.flexmark.util.ast.Document
;
import
org.apache.poi.openxml4j.exceptions.InvalidFormatException
;
import
org.apache.poi.poifs.filesystem.DirectoryEntry
;
import
org.apache.poi.poifs.filesystem.DirectoryEntry
;
import
org.apache.poi.poifs.filesystem.DocumentEntry
;
import
org.apache.poi.poifs.filesystem.POIFSFileSystem
;
import
org.apache.poi.poifs.filesystem.POIFSFileSystem
;
import
org.apache.poi.xwpf.usermodel.XWPFDocument
;
import
org.apache.poi.xwpf.usermodel.XWPFParagraph
;
import
org.apache.poi.xwpf.usermodel.XWPFRun
;
import
org.junit.Before
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.junit.runner.RunWith
;
...
@@ -17,10 +15,11 @@ import org.mockito.MockitoAnnotations;
...
@@ -17,10 +15,11 @@ import org.mockito.MockitoAnnotations;
import
org.springframework.test.context.ContextConfiguration
;
import
org.springframework.test.context.ContextConfiguration
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
org.springframework.test.context.web.WebAppConfiguration
;
import
org.springframework.test.context.web.WebAppConfiguration
;
import
com.vladsch.flexmark.parser.Parser
;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
java.io.*
;
import
java.io.ByteArrayInputStream
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.nio.file.Files
;
import
java.nio.file.Files
;
import
java.nio.file.Paths
;
import
java.nio.file.Paths
;
...
@@ -49,10 +48,7 @@ public class KnowledgeServiceTest {
...
@@ -49,10 +48,7 @@ public class KnowledgeServiceTest {
// @Test
// @Test
public
static
void
main
(
String
[]
args
)
throws
IOException
{
public
static
void
main
(
String
[]
args
)
throws
IOException
,
InvalidFormatException
{
// Document doc = new Document("Input.md");
// doc.save("Output.docx");
String
markdownContent
=
readMarkdownFile
(
"C:\\Users\\52747\\Desktop\\1.md"
);
String
markdownContent
=
readMarkdownFile
(
"C:\\Users\\52747\\Desktop\\1.md"
);
String
htmlContent
=
convertMarkdownToHtml
(
markdownContent
);
String
htmlContent
=
convertMarkdownToHtml
(
markdownContent
);
convertHtmlToWord
(
htmlContent
,
"C:\\Users\\52747\\Desktop\\1.docx"
);
convertHtmlToWord
(
htmlContent
,
"C:\\Users\\52747\\Desktop\\1.docx"
);
...
@@ -75,17 +71,11 @@ public class KnowledgeServiceTest {
...
@@ -75,17 +71,11 @@ public class KnowledgeServiceTest {
}
}
private
static
void
convertHtmlToWord
(
String
html
,
String
outputPath
)
throws
IOException
{
private
static
void
convertHtmlToWord
(
String
html
,
String
outputPath
)
throws
IOException
{
XWPFDocument
document
=
new
XWPFDocument
();
XWPFParagraph
paragraph
=
document
.
createParagraph
();
XWPFRun
run
=
paragraph
.
createRun
();
run
.
setText
(
html
);
FileOutputStream
outputStream
=
new
FileOutputStream
(
outputPath
);
FileOutputStream
outputStream
=
new
FileOutputStream
(
outputPath
);
ByteArrayInputStream
bais
=
new
ByteArrayInputStream
(
html
.
getBytes
());
//将字节数组包装到流中
ByteArrayInputStream
bais
=
new
ByteArrayInputStream
(
html
.
getBytes
());
//将字节数组包装到流中
POIFSFileSystem
poifs
=
new
POIFSFileSystem
();
POIFSFileSystem
poifs
=
new
POIFSFileSystem
();
DirectoryEntry
directory
=
poifs
.
getRoot
();
DirectoryEntry
directory
=
poifs
.
getRoot
();
directory
.
createDocument
(
"WordDocument"
,
bais
);
directory
.
createDocument
(
"WordDocument"
,
bais
);
poifs
.
writeFilesystem
(
outputStream
);
poifs
.
writeFilesystem
(
outputStream
);
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment