许鹏程
2023-08-04 a26fbe729817216bcf53b13945fe6300caa89997
打印模板 打印流程审批意见
已修改3个文件
64 ■■■■■ 文件已修改
pom.xml 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/product/print/service/PrintRealizeService.java 39 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/product/print/util/DynamicTableRenderPolicy.java 21 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pom.xml
@@ -34,6 +34,10 @@
            <artifactId>product-server-admin</artifactId>
        </dependency>
        <dependency>
            <groupId>com.lx</groupId>
            <artifactId>product-server-tool-flow</artifactId>
        </dependency>
        <dependency>
            <groupId>com.deepoove</groupId>
            <artifactId>poi-tl</artifactId>
            <version>1.10.5</version>
src/main/java/com/product/print/service/PrintRealizeService.java
@@ -3,6 +3,8 @@
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.net.URLEncodeUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.alibaba.fastjson.JSONArray;
import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.config.Configure;
import com.deepoove.poi.config.ConfigureBuilder;
@@ -21,8 +23,10 @@
import com.product.print.config.CmnConst;
import com.product.print.service.ide.IPrintRealizeService;
import com.product.print.util.DynamicTableRenderPolicy;
import com.product.tool.flow.service.FlowDetailService;
import com.product.util.BaseUtil;
import com.product.util.SystemParamReplace;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -161,6 +165,7 @@
        if (fieldSetEntity == null || StringUtils.isEmpty(fieldSetEntity.getString(CmnConst.PRINT_TEMPLATE))) {
            throw new BaseException(CmnCode.PRINT_CONFIG_NOT_EXIST.getValue(), CmnCode.PRINT_CONFIG_NOT_EXIST.getText());
        }
        return fieldSetEntity;
    }
@@ -174,6 +179,29 @@
     * @throws BaseException 异常
     */
    private String replaceTemplateFileOut(FieldSetEntity printConf, FieldSetEntity fse, boolean isConvertPdf) throws BaseException {
        Object[] fields = fse.getFields();
        for (int i = 0; i < fields.length; i++) {
            String field = fields[i].toString();
            FieldSetEntity metaEntity = fse.getMeta().getFieldMeta(field);
            String fieldType = metaEntity.getString("field_type");
            //判断是否拥有流程标识
            if ("flowsign".equals(fieldType)) {
                if (StringUtils.equalsAny(fse.getString(field), "1", "2")) {
                    //流程办理中或办结 获取流程意见
                    FieldSetEntity flowTask = getBaseDao().getFieldSetByFilter("product_sys_flow_task", "table_name=? and record_uuid=?", new Object[]{fse.getTableName(), fse.getUUID()}, false);
                    if (flowTask != null) {
                        String taskUuid = flowTask.getString(CmnConst.UUID);
                        //获取流程意见
                        FlowDetailService flowDetailService = SpringUtil.getBean(FlowDetailService.class);
                        JSONArray opinion = flowDetailService.getHistoryInfo(taskUuid);
                        fse.setValue("~flow_opinion~", opinion);
                    }
                }
                break;
            }
        }
        // 打印模板附件uuid
        String template_uuid = printConf.getString(CmnConst.PRINT_TEMPLATE);
        // 获取打印模板
@@ -186,6 +214,9 @@
        String localTempPathWord = Global.getSystemConfig("temp.dir", "") + File.separator + "temp_print_" + tempKey + ".docx";
        replaceWord(localTempPathWord, file.getPath(), fse);
        file.delete();
        String replaceParams = SystemParamReplace.replaceParams(printConf.getString(CmnConst.PRINT_FILE_NAME), fse);
        printConf.setValue(CmnConst.PRINT_FILE_NAME, replaceParams);
        if (isConvertPdf) {
            try {
                // 替换后的pdf临时路径
@@ -217,6 +248,10 @@
     * @param dataFse      替换数据
     */
    public static void replaceWord(String outPath, String templatePath, FieldSetEntity dataFse) {
        JSONArray flowOpinion = (JSONArray) dataFse.getObject("~flow_opinion~");
        if (flowOpinion != null) {
            dataFse.remove("~flow_opinion~");
        }
        //转换数据为复选框
        dataConvertCheckedData(dataFse);
        //克隆一份values
@@ -230,6 +265,10 @@
                config.bind(entry.getKey(), new DynamicTableRenderPolicy(entry.getKey()));
            }
        }
        if(flowOpinion!=null && flowOpinion.size()>0){
            cloneValues.put("lx_flow_opinion", flowOpinion);
            config.bind("lx_flow_opinion", new DynamicTableRenderPolicy("lx_flow_opinion"));
        }
        try {
            //检查输出文件是否存在,不存在则创建
            FileUtil.touch(outPath);
src/main/java/com/product/print/util/DynamicTableRenderPolicy.java
@@ -9,6 +9,7 @@
import com.product.print.config.CmnCode;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.xwpf.usermodel.*;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STVerticalAlignRun;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@@ -133,9 +134,7 @@
                XWPFTableCell cell;
                //判断row中第j个单元格是否存在
                if (row.getTableCells().size() > j) {
                    cell = row.getTableCells().get(j);
                    //清空单元格内容
                    cell.removeParagraph(0);
                    cell = row.getCell(j);
                } else {
                    cell = row.createCell();
                }
@@ -149,8 +148,21 @@
                if (value == null) {
                    value = "";
                }
                //设置单元格的值
                String text = cell.getText();
                //删除单元格中的旧内容
                if (!StringUtils.isEmpty(text)) {
                    List<XWPFParagraph> paragraphs = cell.getParagraphs();
                    if(paragraphs.size()>1){
                        cell.removeParagraph(1);
                    }
                    List<XWPFRun> runs = paragraphs.get(0).getRuns();
                    //清空文字
                    for (int k = 0; k < runs.size(); k++) {
                        runs.get(k).setText("", 0);
                    }
                }
                cell.setText(value.toString());
            }
        }
        //删除起始行
@@ -248,6 +260,7 @@
            }
            copyTableCell(cell1, cell2);
        }
    }
    /**