소스 검색

word生成

LAPTOP-FO2T5SIU\35838 8 달 전
부모
커밋
ed1f2e0b6d

+ 1 - 1
pom.xml

@@ -64,7 +64,7 @@
         <jdom>1.1</jdom>
         <spring.websocket>5.0.4.RELEASE</spring.websocket>
         <spring.messaging>5.3.27</spring.messaging>
-        <rock.star.frame>0.5.11</rock.star.frame>
+        <rock.star.frame>0.6.3</rock.star.frame>
         <rock.star.system>0.2.8.7</rock.star.system>
         <rock.star.user>0.2.2</rock.star.user>
         <rock.star.wx>0.2.3</rock.star.wx>

+ 19 - 2
pro-base/pom.xml

@@ -59,11 +59,28 @@
             <artifactId>hutool-all</artifactId>
             <version>5.7.4</version>
         </dependency>
+<!--        <dependency>-->
+<!--            <groupId>org.apache.poi</groupId>-->
+<!--            <artifactId>ooxml-schemas</artifactId>-->
+<!--            <version>1.1</version>-->
+<!--        </dependency>-->
+        <dependency>
+            <groupId>org.apache.poi</groupId>
+            <artifactId>poi</artifactId>
+            <version>4.1.2</version>
+        </dependency>
         <dependency>
             <groupId>org.apache.poi</groupId>
-            <artifactId>ooxml-schemas</artifactId>
-            <version>1.1</version>
+            <artifactId>poi-ooxml</artifactId>
+            <version>4.1.2</version>
         </dependency>
+        <dependency>
+            <groupId>org.apache.poi</groupId>
+            <artifactId>poi-ooxml-schemas</artifactId>
+            <version>4.1.2</version>
+        </dependency>
+
+
         <dependency>
             <groupId>commons-io</groupId>
             <artifactId>commons-io</artifactId>

+ 8 - 3
pro-base/src/main/java/com/idea/customerManagement/controller/RoomSelectionInfoController.java

@@ -7,10 +7,10 @@ import com.rockstar.common.domain.AjaxResult;
 import io.swagger.annotations.Api;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.*;
 
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 import java.util.List;
 
 @Controller
@@ -92,5 +92,10 @@ public class RoomSelectionInfoController extends BaseController {
         return modelService.getById(id);
     }
 
+    @GetMapping(value = "download",produces = {"application/json;charset=UTF-8"})
+    public void download(RoomSelectionInfoDto model, HttpServletRequest request, HttpServletResponse response) {
+        modelService.downLoad(model,request,response);
+    }
+
 
 }

+ 42 - 6
pro-base/src/main/java/com/idea/customerManagement/service/RoomSelectionInfoService.java

@@ -10,18 +10,18 @@ import com.idea.customerManagement.dto.RoomSelectionInfoDto;
 import com.idea.customerManagement.mapper.CustomerManagementMapper;
 import com.idea.customerManagement.mapper.RoomSelectionInfoExtendMapper;
 import com.idea.customerManagement.mapper.RoomSelectionInfoMapper;
-import com.idea.customerManagement.model.CustomerManagement;
-import com.idea.customerManagement.model.RoomSelectionInfo;
-import com.idea.customerManagement.model.RoomSelectionInfoExample;
+import com.idea.customerManagement.model.*;
+import com.idea.util.DateUtils;
+import com.idea.util.ReplaceWord;
 import com.rockstar.common.base.BaseService;
 import com.rockstar.shiro.util.ShiroUtils;
 import org.apache.commons.collections.CollectionUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.util.Arrays;
-import java.util.Date;
-import java.util.List;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.util.*;
 
 @Service
 public class RoomSelectionInfoService implements BaseService<RoomSelectionInfo, RoomSelectionInfoExample> {
@@ -36,6 +36,8 @@ public class RoomSelectionInfoService implements BaseService<RoomSelectionInfo,
     private ParkRoomExtendMapper roomExtendMapper;
     @Autowired
     private ContractManageService contractManageService;
+    @Autowired
+    private BuyerService buyerService;
 
 
     @Override
@@ -211,5 +213,39 @@ public class RoomSelectionInfoService implements BaseService<RoomSelectionInfo,
         return selectByPrimaryKey(id);
     }
 
+    public void downLoad(RoomSelectionInfoDto model,HttpServletRequest request, HttpServletResponse response) {
+
+        String filePath = "/home/project/settleDown/tem/roomConfirmationSheet.docx";
+        String fileName = "房源确认单.docx";
+        String customerManagementId = model.getCustomerManagementId();
+        BuyerExample buyerExample = new BuyerExample();
+        buyerExample.setOrderByClause("order_num asc");
+        buyerExample.createCriteria().andCustomerManagementIdEqualTo(customerManagementId);
+        List<Buyer> buyers = buyerService.selectByExample(buyerExample);
+        if(CollectionUtils.isNotEmpty(buyers)){
+            Buyer buyer = buyers.get(0);
+            ParkRoomResponse roomResponse = roomExtendMapper.getFullName(model.getHouseId());
+            String fullName = roomResponse.getGroupName() + roomResponse.getDiscName() + roomResponse.getBuildName()
+                    + roomResponse.getRoomNo();
+            String loginName = ShiroUtils.getLoginName();
+            String roomChooseDate = DateUtils.parseDateToStr(DateUtils.DATE_CH, new Date());
+
+            Map<String, Object> data = new HashMap<>();
+            HashMap<String, Object> picData = new HashMap<>();
+            data.put("${name}", buyer.getName());
+            data.put("${identityCard}", buyer.getIdentityCard());
+            data.put("${address}", fullName);
+            data.put("${area}", roomResponse.getPredictionBuildArea());
+            data.put("${roomNumber}", roomResponse.getRoomNumber());
+            data.put("${roomChooseDate}", roomChooseDate);
+            data.put("${username}", loginName);
+            ReplaceWord.operateWord(response,filePath,fileName,data, picData);
+        }
+
+
+
+
+    }
+
 
 }

+ 4 - 4
pro-base/src/main/java/com/idea/pro/service/SafeRequestInfo.java

@@ -26,9 +26,9 @@ public class SafeRequestInfo implements SafeUrlModel {
         return true;
     }
 
-//    @Override
-//    public boolean checkSafe(HttpServletRequest httpServletRequest) {
-//        return false;
-//    }
+    @Override
+    public boolean checkSafe(HttpServletRequest httpServletRequest) {
+        return true;
+    }
 
 }

+ 369 - 0
pro-base/src/main/java/com/idea/util/DateUtils.java

@@ -0,0 +1,369 @@
+package com.idea.util;
+
+import org.apache.commons.lang3.time.DateFormatUtils;
+
+import java.lang.management.ManagementFactory;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.time.*;
+import java.util.Calendar;
+import java.util.Date;
+
+/**
+ * 时间工具类
+ *
+ * @author assets
+ */
+public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
+    public static String YYYY = "yyyy";
+
+    public static String YYYY_MM = "yyyy-MM";
+
+    public static String YYYY_MM_DD = "yyyy-MM-dd";
+
+    public static String YYYYMMDDHHMMSS = "yyyyMMddHHmmss";
+
+    public static String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
+
+    public final static String DATE_CH = "yyyy年MM月dd日";
+
+    private static String[] parsePatterns = {
+            "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM",
+            "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyy/MM",
+            "yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm", "yyyy.MM", "yyyyMMddHHmmss","yyyy年MM月dd日"};
+
+    /**
+     * 获取当前Date型日期
+     *
+     * @return Date() 当前日期
+     */
+    public static Date getNowDate() {
+        return new Date();
+    }
+
+    /**
+     * 获取当前日期, 默认格式为yyyy-MM-dd
+     *
+     * @return String
+     */
+    public static String getDate() {
+        return dateTimeNow(YYYY_MM_DD);
+    }
+
+    public static final String getTime() {
+        return dateTimeNow(YYYY_MM_DD_HH_MM_SS);
+    }
+
+    public static final String dateTimeNow() {
+        return dateTimeNow(YYYYMMDDHHMMSS);
+    }
+
+    public static final String dateTimeNow(final String format) {
+        return parseDateToStr(format, new Date());
+    }
+
+    public static final String dateTime(final Date date) {
+        return parseDateToStr(YYYY_MM_DD, date);
+    }
+
+    public static final String parseDateToStr(final String format, final Date date) {
+        return new SimpleDateFormat(format).format(date);
+    }
+
+    public static final Date dateTime(final String format, final String ts) {
+        try {
+            return new SimpleDateFormat(format).parse(ts);
+        } catch (ParseException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    /**
+     * 日期路径 即年/月/日 如2018/08/08
+     */
+    public static final String datePath() {
+        Date now = new Date();
+        return DateFormatUtils.format(now, "yyyy/MM/dd");
+    }
+
+    /**
+     * 日期路径 即年/月/日 如20180808
+     */
+    public static final String dateTime() {
+        Date now = new Date();
+        return DateFormatUtils.format(now, "yyyyMMdd");
+    }
+
+    /**
+     * 日期型字符串转化为日期 格式
+     */
+    public static Date parseDate(Object str) {
+        if (str == null) {
+            return null;
+        }
+        try {
+            return parseDate(str.toString(), parsePatterns);
+        } catch (ParseException e) {
+            return null;
+        }
+    }
+
+    /**
+     * 获取服务器启动时间
+     */
+    public static Date getServerStartDate() {
+        long time = ManagementFactory.getRuntimeMXBean().getStartTime();
+        return new Date(time);
+    }
+
+    /**
+     * 计算两个时间差
+     */
+    public static String getDatePoor(Date endDate, Date nowDate) {
+        long nd = 1000 * 24 * 60 * 60;
+        long nh = 1000 * 60 * 60;
+        long nm = 1000 * 60;
+        // long ns = 1000;
+        // 获得两个时间的毫秒时间差异
+        long diff = endDate.getTime() - nowDate.getTime();
+        // 计算差多少天
+        long day = diff / nd;
+        // 计算差多少小时
+        long hour = diff % nd / nh;
+        // 计算差多少分钟
+        long min = diff % nd % nh / nm;
+        // 计算差多少秒//输出结果
+        // long sec = diff % nd % nh % nm / ns;
+        return day + "天" + hour + "小时" + min + "分钟";
+    }
+
+    /**
+     * 增加 LocalDateTime ==> Date
+     */
+    public static Date toDate(LocalDateTime temporalAccessor) {
+        ZonedDateTime zdt = temporalAccessor.atZone(ZoneId.systemDefault());
+        return Date.from(zdt.toInstant());
+    }
+
+    /**
+     * 增加 LocalDate ==> Date
+     */
+    public static Date toDate(LocalDate temporalAccessor) {
+        LocalDateTime localDateTime = LocalDateTime.of(temporalAccessor, LocalTime.of(0, 0, 0));
+        ZonedDateTime zdt = localDateTime.atZone(ZoneId.systemDefault());
+        return Date.from(zdt.toInstant());
+    }
+
+    /**
+     * 计算两个日期之间相差的天数
+     *
+     * @param smdate 较小的时间
+     * @param bdate  较大的时间
+     * @return 相差天数
+     * @throws ParseException
+     */
+    public static int daysBetween(Date smdate, Date bdate) throws ParseException {
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        smdate = sdf.parse(sdf.format(smdate));
+        bdate = sdf.parse(sdf.format(bdate));
+        Calendar cal = Calendar.getInstance();
+        cal.setTime(smdate);
+        long time1 = cal.getTimeInMillis();
+        cal.setTime(bdate);
+        long time2 = cal.getTimeInMillis();
+        long between_days = (time2 - time1) / (1000 * 3600 * 24);
+
+        return Integer.parseInt(String.valueOf(between_days));
+    }
+
+    /**
+     * 获取随机时间字符串
+     *
+     * @return
+     */
+    public static String getTimeNum() {
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
+        String timespan = sdf.format(new Date());
+        String random = (System.currentTimeMillis() + "").substring(11);
+        String timeNum = timespan + random;
+        return timeNum;
+    }
+
+    /**
+     * 计算两个时间差几年
+     */
+    public static Integer dayComparePrecise(Date fromDate, Date toDate) {
+        Calendar from = Calendar.getInstance();
+        from.setTime(fromDate);
+        Calendar to = Calendar.getInstance();
+        to.setTime(toDate);
+        int fromYear = from.get(Calendar.YEAR);
+        int toYear = to.get(Calendar.YEAR);
+        int year = toYear - fromYear;
+        return year;
+    }
+
+
+    /**
+     * 验证日期是否真实有效
+     *
+     * @param var
+     * @return
+     */
+    public static String isValid(String var) {
+        try {
+
+//            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd").withResolverStyle(ResolverStyle.SMART);
+//            formatter.format( LocalDate.parse(var,formatter));
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+            sdf.setLenient(false);
+            sdf.format(sdf.parse(var));
+        } catch (Exception e) {
+            return null;
+        }
+        return "1";
+
+    }
+
+    public static String dateStr(Date date, String pattern) {
+        if (date == null) {
+            return "/";
+        }
+        SimpleDateFormat dateformat = new SimpleDateFormat(pattern);
+        String dateStr = dateformat.format(date);
+        return dateStr;
+    }
+
+    /**
+     * 获取年份
+     *
+     * @param date
+     * @param amount
+     * @return
+     */
+    public static String getYear(Date date, int amount) {
+        Calendar c = Calendar.getInstance();
+        c.setTime(date);
+        c.add(Calendar.YEAR, amount);
+        int year = c.get(Calendar.YEAR);
+        return String.valueOf(year);
+    }
+
+    /**
+     * 获取月份
+     *
+     * @param date
+     * @param amount
+     * @return
+     */
+    public static String getMonth(Date date, int amount) {
+        Calendar c = Calendar.getInstance();
+        c.setTime(date);
+        c.add(Calendar.MONTH, amount);
+        int month = c.get(Calendar.MONTH) + 1;
+        return String.valueOf(month);
+    }
+
+    /**
+     * 获取天
+     *
+     * @param date
+     * @param amount
+     * @return
+     */
+    public static String getDay(Date date, int amount) {
+        Calendar c = Calendar.getInstance();
+        c.setTime(date);
+        c.add(Calendar.DAY_OF_MONTH, amount);
+        int day = c.get(Calendar.DAY_OF_MONTH);
+        return String.valueOf(day);
+    }
+
+    /**
+     * 计算两个日期相差的月份
+     * 该方法的计算不考虑日对月数的影响,比如2020-06-30与2020-07-01计算的结果依然是相差1个月
+     *
+     * @param largeDate
+     * @param smallDate
+     * @return
+     */
+    public static int getMonthDiff(Date largeDate, Date smallDate) {
+        Calendar c1 = Calendar.getInstance();
+        Calendar c2 = Calendar.getInstance();
+        c1.setTime(largeDate);
+        c2.setTime(smallDate);
+        int year1 = c1.get(Calendar.YEAR);
+        int year2 = c2.get(Calendar.YEAR);
+        int month1 = c1.get(Calendar.MONTH);
+        int month2 = c2.get(Calendar.MONTH);
+        // 获取年的差值
+        int yearInterval = year1 - year2;
+        // 获取月数差值
+        int monthInterval = month1 - month2;
+        int monthsDiff = yearInterval * 12 + monthInterval;
+        return Math.abs(monthsDiff);
+    }
+
+    /**
+     * 增加月份
+     * @param date
+     * @param amount
+     * @return
+     */
+    public static Date addMonth(Date date, int amount) {
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(date);
+        calendar.add(Calendar.MONTH, amount); //把日期往后增加一个月,负数减一个月
+        date = calendar.getTime();
+        return date;
+    }
+
+    /**
+     * 获取年月的最后一天
+     * @param yearMonth
+     * @return
+     */
+    public static String getLastDayOfMonth(String yearMonth) {
+        int year = Integer.parseInt(yearMonth.split("-")[0]);  //年
+        int month = Integer.parseInt(yearMonth.split("-")[1]); //月
+        Calendar cal = Calendar.getInstance();
+        // 设置年份
+        cal.set(Calendar.YEAR, year);
+        // 设置月份
+        // cal.set(Calendar.MONTH, month - 1);
+        cal.set(Calendar.MONTH, month); //设置当前月的上一个月
+        // 获取某月最大天数
+        //int lastDay = cal.getActualMaximum(Calendar.DATE);
+        int lastDay = cal.getMinimum(Calendar.DATE); //获取月份中的最小值,即第一天
+        // 设置日历中月份的最大天数
+        //cal.set(Calendar.DAY_OF_MONTH, lastDay);
+        cal.set(Calendar.DAY_OF_MONTH, lastDay - 1); //上月的第一天减去1就是当月的最后一天
+        // 格式化日期
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        return sdf.format(cal.getTime());
+    }
+
+
+    //时间戳转换日期方法
+    public static String stampToDateStr(String value) {
+        String res;
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        long lt = new Long(value);
+        Date date = new Date(lt);
+        res = simpleDateFormat.format(date);
+        return res;
+    }
+
+    //时间戳转换日期方法
+    public static Date stampToDate(String value) {
+        long lt = new Long(value);
+        return new Date(lt);
+    }
+
+    public static void main(String[] args) {
+        System.out.println(stampToDate("20231212091303"));
+        System.out.println(parseDateToStr(YYYY_MM_DD_HH_MM_SS,stampToDate("20231212091303")));
+        System.out.println(parseDate("20231212091303"));
+    }
+
+}

+ 298 - 0
pro-base/src/main/java/com/idea/util/ReplaceWord.java

@@ -0,0 +1,298 @@
+package com.idea.util;
+
+import org.apache.poi.util.Units;
+import org.apache.poi.xwpf.usermodel.*;
+
+import javax.servlet.http.HttpServletResponse;
+import java.io.*;
+import java.net.URLEncoder;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @version V1.0
+ * @Description:Word模板数据填充
+ * @Date: 2022/11/16 17:47
+ */
+public class ReplaceWord {
+
+    /***
+     * @Description :替换段落文本
+     * @param document docx解析对象
+     * @param textMap  需要替换的信息集合
+     * @return void
+     * @Date 2022/11/17 17:22
+     */
+    public static void changeText(XWPFDocument document, Map<String, Object> textMap) {
+        // 获取段落集合
+        Iterator<XWPFParagraph> iterator = document.getParagraphsIterator();
+        XWPFParagraph paragraph = null;
+        while (iterator.hasNext()) {
+            paragraph = iterator.next();
+            // 判断此段落是否需要替换
+            if (checkText(paragraph.getText())) {
+                replaceValue(paragraph, textMap);
+            }
+        }
+    }
+
+    /***
+     * @Description :检查文本中是否包含指定的字符(此处为“$”)
+     * @param text
+     * @return boolean
+     * @Date 2022/11/17 17:22
+     */
+    public static boolean checkText(String text) {
+        boolean check = false;
+        if (text.contains("$")) {
+            check = true;
+        }
+        return check;
+    }
+
+    /**
+     * 替换图片
+     *
+     * @param document
+     * @param picData
+     * @throws Exception
+     */
+
+    public static void changePic(XWPFDocument document, Map<String, Object> picData) throws Exception {
+        // 获取段落集合
+        Iterator<XWPFParagraph> iterator = document.getParagraphsIterator();
+        XWPFParagraph paragraph;
+        while (iterator.hasNext()) {
+            paragraph = iterator.next();
+            // 判断此段落是否需要替换
+            String text = paragraph.getText();
+            if (checkText(text)) {
+                replacePicValue(paragraph, picData);
+            }
+        }
+    }
+
+    /***
+     * @Description :替换表格内的文字
+     * @param document
+     * @param data
+     * @return void
+     * @Date 2022/11/18 11:29
+     */
+    public static void changeTableText(XWPFDocument document, Map<String, Object> data) {
+        // 获取文件的表格
+        Iterator<XWPFTable> tableList = document.getTablesIterator();
+        XWPFTable table;
+        List<XWPFTableRow> rows;
+        List<XWPFTableCell> cells;
+        // 循环所有需要进行替换的文本,进行替换
+        while (tableList.hasNext()) {
+            table = tableList.next();
+            if (checkText(table.getText())) {
+                rows = table.getRows();
+                // 遍历表格,并替换模板
+                for (XWPFTableRow row : rows) {
+                    cells = row.getTableCells();
+                    for (XWPFTableCell cell : cells) {
+                        // 判断单元格是否需要替换
+                        if (checkText(cell.getText())) {
+                            List<XWPFParagraph> paragraphs = cell.getParagraphs();
+                            for (XWPFParagraph paragraph : paragraphs) {
+                                replaceValue(paragraph, data);
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    /***
+     * @Description :替换表格内图片
+     * @param document
+     * @param picData
+     * @return void
+     * @Date 2022/11/18 11:29
+     */
+    public static void changeTablePic(XWPFDocument document, Map<String, Object> picData) throws Exception {
+        // 获取文件的表格
+        Iterator<XWPFTable> tableList = document.getTablesIterator();
+        XWPFTable table;
+        List<XWPFTableRow> rows;
+        List<XWPFTableCell> cells;
+        // 循环所有需要进行替换的文本,进行替换
+        while (tableList.hasNext()) {
+            table = tableList.next();
+            if (checkText(table.getText())) {
+                rows = table.getRows();
+                // 遍历表格,并替换模板
+                for (XWPFTableRow row : rows) {
+                    cells = row.getTableCells();
+                    for (XWPFTableCell cell : cells) {
+                        // 判断单元格是否需要替换
+                        if (checkText(cell.getText())) {
+                            List<XWPFParagraph> paragraphs = cell.getParagraphs();
+                            for (XWPFParagraph paragraph : paragraphs) {
+                                replacePicValue(paragraph, picData);
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    /***
+     * @Description :替换内容
+     * @param paragraph
+     * @param textMap
+     * @return void
+     * @Date 2022/11/18 11:33
+     */
+    public static void replaceValue(XWPFParagraph paragraph, Map<String, Object> textMap) {
+        XWPFRun run, nextRun;
+        String runsText;
+        List<XWPFRun> runs = paragraph.getRuns();
+        for (int i = 0; i < runs.size(); i++) {
+            run = runs.get(i);
+            runsText = run.getText(0);
+            if (runsText.contains("${") || (runsText.contains("$") && runs.get(i + 1).getText(0).substring(0, 1).equals("{"))) {
+                while (!runsText.contains("}")) {
+                    nextRun = runs.get(i + 1);
+                    runsText = runsText + nextRun.getText(0);
+                    //删除该节点下的数据
+                    paragraph.removeRun(i + 1);
+                }
+                Object value = changeValue(runsText, textMap);
+                //判断key在Map中是否存在
+                if (textMap.containsKey(runsText)) {
+                    run.setText(value.toString(), 0);
+                } else {
+                    //如果匹配不到,则不修改
+                    run.setText(runsText, 0);
+                }
+            }
+        }
+    }
+
+    /***
+     * @Description :替换图片内容
+     * @param paragraph
+     * @param picData
+     * @return void
+     * @Date 2022/11/18 11:33
+     */
+    public static void replacePicValue(XWPFParagraph paragraph, Map<String, Object> picData) throws Exception {
+        List<XWPFRun> runs = paragraph.getRuns();
+        for (XWPFRun run : runs) {
+            Object value = changeValue(run.toString(), picData);
+            if (picData.containsKey(run.toString())) {
+                //清空内容
+                run.setText("", 0);
+                FileInputStream is = new FileInputStream((String) value);
+                //图片宽度、高度
+                int width = Units.toEMU(100), height = Units.toEMU(100);
+                //添加图片信息,段落高度需要在模板中自行调整
+                run.addPicture(is, XWPFDocument.PICTURE_TYPE_PNG, (String) value, width, height);
+            }
+        }
+    }
+
+    /***
+     * @Description :匹配参数
+     * @param value
+     * @param textMap
+     * @return java.lang.Object
+     * @Date 2022/11/18 11:33
+     */
+    public static Object changeValue(String value, Map<String, Object> textMap) {
+        Object valu = "";
+        for (Map.Entry<String, Object> textSet : textMap.entrySet()) {
+            // 匹配模板与替换值 格式${key}
+            String key = textSet.getKey();
+            if (value.contains(key)) {
+                valu = textSet.getValue();
+            }
+        }
+        return valu;
+    }
+
+
+    public static void main(String[] args) throws Exception {
+        Map<String, Object> data = new HashMap<>();
+        Map<String, Object> picData = new HashMap<>();
+//        data.put("${aab999}", "123456789");
+        data.put("${aac003}", "刘毅");
+//        data.put("${aac147}", "43102119001212109X");
+//        data.put("${aae004}", "刘毅");
+//        data.put("${aae005}", "13800000000");
+//        data.put("${aae013}", "");
+//        data.put("${aae123}", "刘毅");
+//        data.put("${aae123_1}", "");
+//        data.put("${aae123_2}", "");
+//        data.put("${aae124}", "刘小毅");
+//        data.put("${aae124_1}", "");
+//        data.put("${aae124_2}", "");
+//        picData.put("${aac013}", "C:\\Users\\Liu\\Pictures\\26ed64f74a659d46d6db0fd979bc0142.jpeg");
+        operateWord(data, picData);
+    }
+
+    public static void operateWord(Map<String, Object> data, Map<String, Object> picData){
+        try {
+            FileInputStream is = new FileInputStream("C:\\Users\\35838\\Desktop\\中低收入家庭购买共有产权保障房房源确认单(惠景).docx");
+            XWPFDocument document = new XWPFDocument(is);
+            if (data.size() > 0) {
+                // 替换掉表格之外的文本(仅限文本)
+                ReplaceWord.changeText(document, data);
+                // 替换表格内的文本对象
+                ReplaceWord.changeTableText(document, data);
+            }
+            if (picData.size() > 0) {
+                // 替换内容图片
+                ReplaceWord.changePic(document, picData);
+                // 替换表格内的图片对象
+                ReplaceWord.changeTablePic(document, picData);
+            }
+            FileOutputStream out = new FileOutputStream("C:\\Users\\35838\\Desktop\\test2" + ".docx");
+            document.write(out);
+        } catch (FileNotFoundException e) {
+            e.printStackTrace();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    public static void operateWord(HttpServletResponse response,String filePath,String fileName, Map<String, Object> data, Map<String, Object> picData){
+        try {
+            FileInputStream is = new FileInputStream(filePath);
+            XWPFDocument document = new XWPFDocument(is);
+            if (data.size() > 0) {
+                // 替换掉表格之外的文本(仅限文本)
+                ReplaceWord.changeText(document, data);
+                // 替换表格内的文本对象
+                ReplaceWord.changeTableText(document, data);
+            }
+            if (picData.size() > 0) {
+                // 替换内容图片
+                ReplaceWord.changePic(document, picData);
+                // 替换表格内的图片对象
+                ReplaceWord.changeTablePic(document, picData);
+            }
+            response.setContentType("text/html;charset=UTF-8");
+            response.setContentType("application/msword");
+            response.setHeader("Content-disposition", "attachment; filename=" + URLEncoder.encode(fileName, "utf-8"));
+            BufferedOutputStream bos = new BufferedOutputStream(response.getOutputStream());
+            document.write(bos);
+            bos.close();
+        } catch (FileNotFoundException e) {
+            e.printStackTrace();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+
+}
+

+ 2 - 0
pro-base/src/main/resources/mybatis/buildManage/ParkRoomExtendMapper.xml

@@ -81,6 +81,8 @@
       park_floor_disc.id discId,
       mnp_building.id buildId,
       park_room.id,
+      park_room.room_number,
+      park_room.prediction_build_area,
       park_floor_disc.subscription_funds
     FROM
       park_room