Compare commits
No commits in common. "feature/update-dify" and "feature/email" have entirely different histories.
feature/up
...
feature/em
8
pom.xml
8
pom.xml
@ -32,7 +32,6 @@
|
||||
<mapstruct.version>1.6.2</mapstruct.version>
|
||||
<fastjson.version>2.0.53</fastjson.version>
|
||||
<docker-maven-plugin.version>0.44.0</docker-maven-plugin.version>
|
||||
<poi-tl.version>1.12.2</poi-tl.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<!-- <dependency>-->
|
||||
@ -132,13 +131,6 @@
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.deepoove</groupId>
|
||||
<artifactId>poi-tl</artifactId>
|
||||
<version>${poi-tl.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.springframework.boot</groupId>-->
|
||||
<!-- <artifactId>spring-boot-starter-data-r2dbc</artifactId>-->
|
||||
|
@ -1,35 +0,0 @@
|
||||
package com.zsc.edu.dify.framework.generateDocx;
|
||||
|
||||
import com.deepoove.poi.XWPFTemplate;
|
||||
import com.zsc.edu.dify.framework.generateDocx.styleConfig.styleDataWrapper;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author Ding
|
||||
*/
|
||||
public class generateDocx {
|
||||
public String generateSpider4(List<Map<String, Object>> rawData) {
|
||||
UUID uuid = UUID.randomUUID();
|
||||
String target = "storage/temp/" + uuid + ".docx";
|
||||
String resource = "src/main/resources/docxTemplate/model.docx";
|
||||
String back = uuid + ".docx";
|
||||
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
|
||||
List<Map<String, Object>> styledData = styleDataWrapper.wrap(rawData);
|
||||
|
||||
data.put("context", styledData);
|
||||
|
||||
try (XWPFTemplate template = XWPFTemplate.compile(resource).render(data)) {
|
||||
template.writeToFile(target);
|
||||
return back;
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
package com.zsc.edu.dify.framework.generateDocx.styleConfig;
|
||||
|
||||
import com.deepoove.poi.data.style.Style;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @description 创建特定样式
|
||||
* @author Ding
|
||||
*/
|
||||
@Data
|
||||
public class labelStyles {
|
||||
private final Style titleStyle;
|
||||
private final Style textStyle;
|
||||
|
||||
// 私有构造函数,强制通过工厂方法创建
|
||||
private labelStyles(Style titleStyle, Style textStyle) {
|
||||
this.titleStyle = titleStyle;
|
||||
this.textStyle = textStyle;
|
||||
}
|
||||
|
||||
// 工厂方法:初始化默认样式
|
||||
public static labelStyles createDefault() {
|
||||
Style titleStyle = new Style();
|
||||
titleStyle.setBold(true);
|
||||
titleStyle.setFontSize(20);
|
||||
|
||||
Style textStyle = new Style();
|
||||
textStyle.setFontSize(11);
|
||||
|
||||
return new labelStyles(titleStyle, textStyle);
|
||||
}
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
package com.zsc.edu.dify.framework.generateDocx.styleConfig;
|
||||
|
||||
import com.deepoove.poi.data.ParagraphRenderData;
|
||||
import com.deepoove.poi.data.Paragraphs;
|
||||
import com.deepoove.poi.data.TextRenderData;
|
||||
import com.deepoove.poi.data.style.Style;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
/**
|
||||
* @description 用于将样式与字段绑定
|
||||
* @author Ding
|
||||
*/
|
||||
public class styleDataWrapper {
|
||||
static labelStyles styles = labelStyles.createDefault();
|
||||
|
||||
// 定义标签与样式映射规则。标题用一个样式,其他标签用一个样式
|
||||
private static final Map<String, Style> STYLE_MAPPING = Map.of(
|
||||
"title", styles.getTitleStyle(),
|
||||
"*", styles.getTextStyle()
|
||||
);
|
||||
|
||||
public static List<Map<String, Object>> wrap(List<Map<String, Object>> rawData) {
|
||||
return rawData.stream()
|
||||
.map(styleDataWrapper::processMap)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
// 为每个字段绑定特定的样式
|
||||
private static Map<String, Object> processMap(Map<String, Object> rawMap) {
|
||||
Map<String, Object> styledMap = new HashMap<>();
|
||||
rawMap.forEach((key, value) -> {
|
||||
Style style = STYLE_MAPPING.getOrDefault(key, STYLE_MAPPING.get("*"));
|
||||
TextRenderData textRenderData = new TextRenderData(value.toString(), style);
|
||||
styledMap.put(key, textRenderData);
|
||||
});
|
||||
return styledMap;
|
||||
}
|
||||
}
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user