shichongfu
2023-06-09 bf033b57eaa739061cd3ede60f1fdc3c79b7c787
src/main/java/com/product/print/service/PrintRealizeService.java
@@ -2,7 +2,10 @@
import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.config.Configure;
import com.deepoove.poi.data.TextRenderData;
import com.deepoove.poi.data.style.Style;
import com.product.common.lang.StringUtils;
import com.product.core.cache.DataPoolCacheImpl;
import com.product.core.config.Global;
import com.product.core.entity.DataTableEntity;
import com.product.core.entity.FieldSetEntity;
@@ -80,6 +83,66 @@
    }
*/
    
    /**
     *    word打印复选框处理
     * @param fs
     */
    public static void dataConvertCheckedData(FieldSetEntity fse) {
       TextRenderData selSymbol = new TextRenderData(CmnConst.PRINT_CHECKED_CHAR, new Style(CmnConst.PRINT_FONT,14));
      TextRenderData unselSymbol = new TextRenderData(CmnConst.PRINT_UNCHECKED_CHAR, new Style(CmnConst.PRINT_FONT,14));
       //获取表单字段
       Object[] fields = fse.getMeta().getFields();
        if (fields != null) {
            for(int i = 0; i < fields.length; ++i) {
               //获取保存的数据值
               String dataSaveValue = fse.getString(fields[i] + CmnConst._SAVE_VALUE);
               if (!BaseUtil.strIsNull(dataSaveValue)) {
                  //获取每个字段的meta信息
                    FieldSetEntity meta = fse.getMeta().getFieldMeta(fields[i].toString());
                    if (meta != null && meta.getString(CmnConst.FIELD_REFERECE) != null && meta.getString(CmnConst.FIELD_REFERECE).indexOf("《")>-1) {
                       //数据对应参照信息
                       DataTableEntity dictInfos = getMetaAndCacheDictInfo(meta);
                       if (!BaseUtil.dataTableIsEmpty(dictInfos)) {
                          for (int j = 0; j < dictInfos.getRows(); j++) {
                             //获取每个参照对应值
                             String dict_value = dictInfos.getFieldSetEntity(j).getString(CmnConst.DICT_VALUE);
                             if (dataSaveValue.indexOf(dict_value)>-1) {
                           fse.setValue(fields[i]+"_" + dict_value, selSymbol);
                        }else {
                           fse.setValue(fields[i]+"_" + dict_value, unselSymbol);
                        }
                          }
                  }
                    }
            }
            }
        }
    }
    /**
     *    获取字段对应数据字典信息
     * @param fieldMate
     * @return
     */
    public static DataTableEntity getMetaAndCacheDictInfo(FieldSetEntity fieldMate) {
       if (fieldMate != null && fieldMate.getString(CmnConst.FIELD_REFERECE) != null) {
            int a = fieldMate.getString(CmnConst.FIELD_REFERECE).indexOf("《");
            int b = fieldMate.getString(CmnConst.FIELD_REFERECE).indexOf("》");
            if (b > 1 && a == 0) {
               return DataPoolCacheImpl.getInstance().getCacheData("数据字典配置信息", new String[]{fieldMate.getString(CmnConst.FIELD_REFERECE).substring(a + 1, b)});
            }
       }
       return null;
    }
    @Override
    public void printWord(FieldSetEntity fse, HttpServletResponse response) throws BaseException {
        // 打印配置uuid
@@ -129,6 +192,10 @@
                    configureBuilder.customPolicy(vv.getKey(), new HackLoopTableRenderPolicy());
                }
            }
            //复选框处理
            dataConvertCheckedData(fse);
            XWPFTemplate render = XWPFTemplate.compile(file, configureBuilder == null ? Configure.createDefault() : configureBuilder.build()).render(fse.getValues());
            render.write(is);
            render.close();
@@ -140,10 +207,10 @@
            response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
            
            String fileName = null;
            if(!BaseUtil.strIsNull(fieldSetEntity.getString("print_file_name"))) {
               fileName = SystemParamReplace.replaceParams(fieldSetEntity.getString("print_file_name"), fse);
            if(!BaseUtil.strIsNull(fieldSetEntity.getString(CmnConst.PRINT_FILE_NAME))) {
               fileName = SystemParamReplace.replaceParams(fieldSetEntity.getString(CmnConst.PRINT_FILE_NAME), fse);
            }else {
               fileName = fieldSetEntity.getString("print_name");
               fileName = fieldSetEntity.getString(CmnConst.PRINT_NAME);
         }
            fileName+=".docx";
            
@@ -233,7 +300,7 @@
            response.setContentType("multipart/form-data");
            response.setHeader("Content-Disposition", "attachment;");
            // 使用openOffice 转换为pdf
            pdfTemp = PdfConcurrenceUtil.convertToPdf(wordTemp.getPath(), localTempPathPdf);
            pdfTemp = PdfConcurrenceUtil.convertToPdf(wordTemp.getPath(), localTempPathPdf,"docx");
            InputStream isPdf = new FileInputStream(pdfTemp);
            int len;
            byte[] b = new byte[1024];