|
|
@ -1,5 +1,6 @@
|
|
|
|
package com.ruoyi.gysl.service.impl;
|
|
|
|
package com.ruoyi.gysl.service.impl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.io.resource.ClassPathResource;
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
import com.ruoyi.common.annotation.Excel;
|
|
|
|
import com.ruoyi.common.annotation.Excel;
|
|
|
@ -22,13 +23,19 @@ import org.apache.poi.xssf.usermodel.XSSFCell;
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFRow;
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFRow;
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
|
|
|
|
|
|
|
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
|
|
|
|
|
|
|
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
|
|
|
|
|
|
|
|
import org.apache.poi.xwpf.usermodel.XWPFRun;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.io.Serializable;
|
|
|
|
import java.io.Serializable;
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Objects;
|
|
|
|
import java.util.Objects;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
|
@ -473,4 +480,29 @@ public class BasicInformationServiceImpl extends ServiceImpl<BasicInformationMap
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return basicInformationResponse;
|
|
|
|
return basicInformationResponse;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void generateDocument(String filePath, Map<String, String> data) throws Exception {
|
|
|
|
|
|
|
|
// 加载模板文件
|
|
|
|
|
|
|
|
try (InputStream inputStream = new ClassPathResource("template.docx").getStream()) {
|
|
|
|
|
|
|
|
XWPFDocument document = new XWPFDocument(inputStream);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 替换模板中的占位符
|
|
|
|
|
|
|
|
for (XWPFParagraph paragraph : document.getParagraphs()) {
|
|
|
|
|
|
|
|
for (String key : data.keySet()) {
|
|
|
|
|
|
|
|
String text = paragraph.getText();
|
|
|
|
|
|
|
|
if (text.contains("{" + key + "}")) {
|
|
|
|
|
|
|
|
text = text.replace("{" + key + "}", data.get(key));
|
|
|
|
|
|
|
|
paragraph.removeRun(0); // 删除原有内容
|
|
|
|
|
|
|
|
XWPFRun run = paragraph.createRun();
|
|
|
|
|
|
|
|
run.setText(text); // 设置替换后的内容
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 输出生成的文档
|
|
|
|
|
|
|
|
try (FileOutputStream out = new FileOutputStream(filePath)) {
|
|
|
|
|
|
|
|
document.write(out);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|