|
@@ -3,12 +3,27 @@ package com.zksy.property.service.impl;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
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.zksy.property.domain.ARentalContent;
|
|
|
import com.zksy.property.domain.ARentalContract;
|
|
import com.zksy.property.domain.ARentalContract;
|
|
|
|
|
+import com.zksy.property.service.ARentalContentService;
|
|
|
import com.zksy.property.service.ARentalContractService;
|
|
import com.zksy.property.service.ARentalContractService;
|
|
|
import com.zksy.property.mapper.ARentalContractMapper;
|
|
import com.zksy.property.mapper.ARentalContractMapper;
|
|
|
|
|
+import org.apache.poi.hwpf.HWPFDocument;
|
|
|
|
|
+import org.apache.poi.hwpf.usermodel.Bookmarks;
|
|
|
|
|
+import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
|
|
|
|
+import org.apache.poi.xwpf.usermodel.XWPFParagraph;
|
|
|
|
|
+import org.apache.poi.xwpf.usermodel.XWPFRun;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.core.io.ClassPathResource;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
+import java.io.*;
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+import java.util.regex.Matcher;
|
|
|
|
|
+import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @author Administrator
|
|
* @author Administrator
|
|
@@ -19,6 +34,9 @@ import java.util.List;
|
|
|
public class ARentalContractServiceImpl extends ServiceImpl<ARentalContractMapper, ARentalContract>
|
|
public class ARentalContractServiceImpl extends ServiceImpl<ARentalContractMapper, ARentalContract>
|
|
|
implements ARentalContractService{
|
|
implements ARentalContractService{
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private ARentalContentService aRentalContentService;
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public Page<ARentalContract> findByPage(long pageNum, long pageSize, String tenantName, String contractNumber, String contractStatus) {
|
|
public Page<ARentalContract> findByPage(long pageNum, long pageSize, String tenantName, String contractNumber, String contractStatus) {
|
|
|
Page<ARentalContract> page = new Page<>(pageNum,pageSize);
|
|
Page<ARentalContract> page = new Page<>(pageNum,pageSize);
|
|
@@ -39,6 +57,215 @@ public class ARentalContractServiceImpl extends ServiceImpl<ARentalContractMappe
|
|
|
List<ARentalContract> list = this.list(queryWrapper);
|
|
List<ARentalContract> list = this.list(queryWrapper);
|
|
|
return list;
|
|
return list;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public String generatorRental(String mark) {
|
|
|
|
|
+ switch ( mark){
|
|
|
|
|
+ case "1":{
|
|
|
|
|
+ HashMap<String, String> contentMap = new HashMap<>();
|
|
|
|
|
+ contentMap.put("a1", "张三");
|
|
|
|
|
+ contentMap.put("a2", "123456789");
|
|
|
|
|
+
|
|
|
|
|
+ try (InputStream inputStream = new ClassPathResource("templates/1.docx").getInputStream()) {
|
|
|
|
|
+ XWPFDocument document = new XWPFDocument(inputStream);
|
|
|
|
|
+
|
|
|
|
|
+ // 遍历所有段落并进行占位符替换
|
|
|
|
|
+ for (XWPFParagraph paragraph : document.getParagraphs()) {
|
|
|
|
|
+ List<XWPFRun> runs = paragraph.getRuns();
|
|
|
|
|
+ if (runs == null || runs.isEmpty()) continue;
|
|
|
|
|
+
|
|
|
|
|
+ List<XWPFRun> modifiableRuns = new ArrayList<>(runs);
|
|
|
|
|
+ int index = 0;
|
|
|
|
|
+
|
|
|
|
|
+ while (index < modifiableRuns.size()) {
|
|
|
|
|
+ XWPFRun run = modifiableRuns.get(index);
|
|
|
|
|
+
|
|
|
|
|
+ // 检查 run 是否有效
|
|
|
|
|
+ if (run.getParent() == null) {
|
|
|
|
|
+ index++;
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ String text;
|
|
|
|
|
+ try {
|
|
|
|
|
+ text = run.getText(0);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ index++;
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (text == null || text.isEmpty()) {
|
|
|
|
|
+ index++;
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Matcher matcher = Pattern.compile("\\$\\{(.+?)\\}").matcher(text);
|
|
|
|
|
+ if (matcher.find()) {
|
|
|
|
|
+ // 存在占位符,进行替换
|
|
|
|
|
+ do {
|
|
|
|
|
+ String key = matcher.group(1);
|
|
|
|
|
+ String replacement = contentMap.getOrDefault(key, "未知字段");
|
|
|
|
|
+
|
|
|
|
|
+ // 替换当前 Run 中的占位符内容
|
|
|
|
|
+ text = text.replace("${" + key + "}", replacement);
|
|
|
|
|
+ } while (matcher.find());
|
|
|
|
|
+
|
|
|
|
|
+ // 只更新当前 Run 的文本内容,不删除或清空整个段落
|
|
|
|
|
+ run.setText(text, 0);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ index++;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 可选:保存修改后的文档到新文件
|
|
|
|
|
+ try (FileOutputStream outputStream = new FileOutputStream("C:\\Users\\hxb\\Downloads\\已替换合同.docx")) {
|
|
|
|
|
+ document.write(outputStream);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ case "2":{
|
|
|
|
|
+ HashMap<String, String> contentMap = new HashMap<>();
|
|
|
|
|
+ contentMap.put("b1", "张三");
|
|
|
|
|
+ contentMap.put("b2", "123456789");
|
|
|
|
|
+
|
|
|
|
|
+ try (InputStream inputStream = new ClassPathResource("templates/2.docx").getInputStream()) {
|
|
|
|
|
+ XWPFDocument document = new XWPFDocument(inputStream);
|
|
|
|
|
+
|
|
|
|
|
+ // 遍历所有段落并进行占位符替换
|
|
|
|
|
+ for (XWPFParagraph paragraph : document.getParagraphs()) {
|
|
|
|
|
+ List<XWPFRun> runs = paragraph.getRuns();
|
|
|
|
|
+ if (runs == null || runs.isEmpty()) continue;
|
|
|
|
|
+
|
|
|
|
|
+ List<XWPFRun> modifiableRuns = new ArrayList<>(runs);
|
|
|
|
|
+ int index = 0;
|
|
|
|
|
+
|
|
|
|
|
+ while (index < modifiableRuns.size()) {
|
|
|
|
|
+ XWPFRun run = modifiableRuns.get(index);
|
|
|
|
|
+
|
|
|
|
|
+ // 检查 run 是否有效
|
|
|
|
|
+ if (run.getParent() == null) {
|
|
|
|
|
+ index++;
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ String text;
|
|
|
|
|
+ try {
|
|
|
|
|
+ text = run.getText(0);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ index++;
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (text == null || text.isEmpty()) {
|
|
|
|
|
+ index++;
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Matcher matcher = Pattern.compile("\\$\\{(.+?)\\}").matcher(text);
|
|
|
|
|
+ if (matcher.find()) {
|
|
|
|
|
+ // 存在占位符,进行替换
|
|
|
|
|
+ do {
|
|
|
|
|
+ String key = matcher.group(1);
|
|
|
|
|
+ String replacement = contentMap.getOrDefault(key, "未知字段");
|
|
|
|
|
+
|
|
|
|
|
+ // 替换当前 Run 中的占位符内容
|
|
|
|
|
+ text = text.replace("${" + key + "}", replacement);
|
|
|
|
|
+ } while (matcher.find());
|
|
|
|
|
+
|
|
|
|
|
+ // 只更新当前 Run 的文本内容,不删除或清空整个段落
|
|
|
|
|
+ run.setText(text, 0);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ index++;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 可选:保存修改后的文档到新文件
|
|
|
|
|
+ try (FileOutputStream outputStream = new FileOutputStream("C:\\Users\\hxb\\Downloads\\已替换合同.docx")) {
|
|
|
|
|
+ document.write(outputStream);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ case "3":{
|
|
|
|
|
+ HashMap<String, String> contentMap = new HashMap<>();
|
|
|
|
|
+ contentMap.put("c1", "张三");
|
|
|
|
|
+ contentMap.put("c2", "123456789");
|
|
|
|
|
+
|
|
|
|
|
+ try (InputStream inputStream = new ClassPathResource("templates/3.docx").getInputStream()) {
|
|
|
|
|
+ XWPFDocument document = new XWPFDocument(inputStream);
|
|
|
|
|
+
|
|
|
|
|
+ // 遍历所有段落并进行占位符替换
|
|
|
|
|
+ for (XWPFParagraph paragraph : document.getParagraphs()) {
|
|
|
|
|
+ List<XWPFRun> runs = paragraph.getRuns();
|
|
|
|
|
+ if (runs == null || runs.isEmpty()) continue;
|
|
|
|
|
+
|
|
|
|
|
+ List<XWPFRun> modifiableRuns = new ArrayList<>(runs);
|
|
|
|
|
+ int index = 0;
|
|
|
|
|
+
|
|
|
|
|
+ while (index < modifiableRuns.size()) {
|
|
|
|
|
+ XWPFRun run = modifiableRuns.get(index);
|
|
|
|
|
+
|
|
|
|
|
+ // 检查 run 是否有效
|
|
|
|
|
+ if (run.getParent() == null) {
|
|
|
|
|
+ index++;
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ String text;
|
|
|
|
|
+ try {
|
|
|
|
|
+ text = run.getText(0);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ index++;
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (text == null || text.isEmpty()) {
|
|
|
|
|
+ index++;
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Matcher matcher = Pattern.compile("\\$\\{(.+?)\\}").matcher(text);
|
|
|
|
|
+ if (matcher.find()) {
|
|
|
|
|
+ // 存在占位符,进行替换
|
|
|
|
|
+ do {
|
|
|
|
|
+ String key = matcher.group(1);
|
|
|
|
|
+ String replacement = contentMap.getOrDefault(key, "未知字段");
|
|
|
|
|
+
|
|
|
|
|
+ // 替换当前 Run 中的占位符内容
|
|
|
|
|
+ text = text.replace("${" + key + "}", replacement);
|
|
|
|
|
+ } while (matcher.find());
|
|
|
|
|
+
|
|
|
|
|
+ // 只更新当前 Run 的文本内容,不删除或清空整个段落
|
|
|
|
|
+ run.setText(text, 0);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ index++;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 可选:保存修改后的文档到新文件
|
|
|
|
|
+ try (FileOutputStream outputStream = new FileOutputStream("C:\\Users\\hxb\\Downloads\\已替换合同.docx")) {
|
|
|
|
|
+ document.write(outputStream);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ return "";
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|