From 2e168d2c29642ee4a99f35793c4d75372ad84ab1 Mon Sep 17 00:00:00 2001 From: God <10745413@qq.com> Date: Wed, 2 Nov 2022 10:42:12 +0800 Subject: [PATCH 01/24] =?UTF-8?q?=E9=97=AE=E9=A2=98=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/yxt/common/base/utils/WordConvertUtils.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordConvertUtils.java b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordConvertUtils.java index dbef38f..6c5451a 100644 --- a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordConvertUtils.java +++ b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordConvertUtils.java @@ -22,8 +22,6 @@ public class WordConvertUtils { * 根据ftl模板生成word * * @param map 数据 - * @param typeName 模板名称 - * @param sourcePath 模板路径 * @param targetPath 保存目标路径 * @param fileName 文件名 */ From 0179700f44a0f783ad75b370a622272b461b2fb0 Mon Sep 17 00:00:00 2001 From: dimengzhe <251008545@qq.com> Date: Thu, 3 Nov 2022 10:49:52 +0800 Subject: [PATCH 02/24] =?UTF-8?q?=E6=8E=A8=E9=80=81=E6=AC=BE=E9=A1=B9?= =?UTF-8?q?=E7=A1=AE=E8=AE=A4=E3=80=81=E4=BB=A5=E5=8F=8A=E7=A7=BB=E5=8A=A8?= =?UTF-8?q?=E7=AB=AF=E8=8F=9C=E5=8D=95=E6=8E=92=E5=BA=8F=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yxt/common/base/config/component/DocPdfComponent.java | 1 - 1 file changed, 1 deletion(-) diff --git a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/config/component/DocPdfComponent.java b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/config/component/DocPdfComponent.java index 505ec44..df389cc 100644 --- a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/config/component/DocPdfComponent.java +++ b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/config/component/DocPdfComponent.java @@ -44,7 +44,6 @@ public class DocPdfComponent { * @return 返回word文件路径和链接路径 */ public Map creatWord(Map map, String typeName, String fileName) { -// String dateStr = DateUtils.dateConvertStr(new Date(), "yyyyMMdd"); String dateStr = DateUtil.format(new Date(), "yyyyMMdd"); String targetPath = uploadTemplateUrl + dateStr; try { From f01cf83968f87d92c9437dc8bbc33974fc7a2421 Mon Sep 17 00:00:00 2001 From: dimengzhe <251008545@qq.com> Date: Tue, 8 Nov 2022 19:24:11 +0800 Subject: [PATCH 03/24] =?UTF-8?q?=E9=87=91=E9=A2=9D=E6=95=B0=E5=AD=97?= =?UTF-8?q?=E8=BD=AC=E4=B8=BA=E5=A4=A7=E5=86=99=EF=BC=8C=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E4=B8=80=E5=8D=83=E4=B8=87=E5=85=83=E6=97=B6=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yxt/common/base/utils/TransformMoney.java | 197 ++++++++++++++++++ 1 file changed, 197 insertions(+) create mode 100644 yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/TransformMoney.java diff --git a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/TransformMoney.java b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/TransformMoney.java new file mode 100644 index 0000000..b736ddf --- /dev/null +++ b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/TransformMoney.java @@ -0,0 +1,197 @@ +package com.yxt.common.base.utils; + +import java.math.BigDecimal; + +/** + * @Author dimengzhe + * @Date 2022/11/8 19:10 + * @Description + */ +public class TransformMoney { + + /* +以下摘自百度百科:http://baike.baidu.com/view/359995.htm +大写数字规则 + 中文大写金额数字应用正楷或行书填写,如壹、贰、叁、肆、伍、陆、柒、捌、玖、拾、佰、仟、万、亿、元、角、分、零、整(正)等字样。不得用一、二(两)、三、四、五、六、七、八、九、十、廿、毛、另(或0)填写,不得自造简化字。如果金额数字书写中使用繁体字,如贰、陆、亿、万、圆的,也可。 + 中文大写金额数字到"元"为止的,在"元"之后,应写"整"(或"正")字,在"角"之后,可以不写"整"(或"正")字。大写金额数字有"分"的,"分"后面不写"整"(或"正")字。 + 中文大写金额数字前应标明"人民币"字样,大写金额数字有"分"的,"分"后面不写"整"(或"正")字。 + 中文大写金额数字前应标明"人民币"字样,大写金额数字应紧接"人民币"字样填写,不得留有空白。大写金额数字前未印"人民币"字样的,应加填"人民币"三字。在票据和结算凭证大写金额栏内不得预印固定的"仟、佰、拾、万、仟、佰、拾、元、角、分"字样。 + 阿拉伯数字小写金额数字中有"0"时,中文大写应按照汉语语言规律、金额数字构成和防止涂改的要求进行书写。举例如下: + 阿拉伯数字中间有"0"时,中文大写要写"零"字,如¥1409.50,应写成人民币壹仟肆佰零玖元伍角。 + 阿拉伯数字中间连续有几个"0"时,中文大写金额中间可以只写一个"零"字,如¥6007.14,应写成人民币陆仟零柒元壹角肆分。 + 阿拉伯金额数字万位和元位是"0",或者数字中间连续有几个"0",万位、元位也是"0",但千位、角位不是"0"时,中文大写金额中可以只写一个零字,也可以不写"零"字。如¥1680.32,应写成人民币壹仟陆佰捌拾元零叁角贰分,或者写成人民币壹仟陆佰捌拾元叁角贰分,又如¥107000.53,应写成人民币壹拾万柒仟元零伍角叁分,或者写成人民币壹拾万零柒仟元伍角叁分。 + 阿拉伯金额数字角位是"0",而分位不是"0"时,中文大写金额"元"后面应写"零"字。如¥16409.02,应写成人民币壹万陆仟肆佰零玖元零贰分;又如¥325.04,应写成人民币叁佰贰拾伍元零肆分。 +*/ + + static final String big = "零壹贰叁肆伍陆柒捌玖"; //大写 + static final String[] units = {"仟佰拾", "角分"}; //单位 + + + /** + * 双精度浮点数转换成字符串 + * 注: + * 1、如果直接用String.toString(double d)方法,超大数额会出现科学计数法的字符串; + * 2、如果整数部分超过15位数,低位部分可能出现误差,所以不支持超过15位整数的数值, + * 一般数据库设计金额字段时都不会超过15位整数,如oracle用Number(18,3)的类型表示,整数部分最多15位,小数点后保留3位有效数字。 + */ + public static String getDecimalStr(double d) { + //设置小数点后的精度,保留两位 + /*四舍五入结果参考: + 0.005,//0.01入 + 0.015,//0.01舍 + 0.025,//0.03入 + 0.035,//0.04入 + 0.045,//0.04舍 + 0.055,//0.06入(前一位是5则入) + */ + String str = new BigDecimal(d).setScale(2, BigDecimal.ROUND_HALF_UP).toString(); + + /* + //经过测试,以下三种方法都是可以用的: + //或1: + String str = new BigDecimal(d).setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString(); + + //或2: + DecimalFormat format = new DecimalFormat(); + format.applyPattern("#################0.00"); + String str = format.format(d); + + //或3: + DecimalFormat decimalFormat = new DecimalFormat(); + decimalFormat.setMinimumFractionDigits(2); + decimalFormat.setMaximumFractionDigits(2); + decimalFormat.setGroupingUsed(false); + decimalFormat.setMaximumIntegerDigits(15); + decimalFormat.setMinimumIntegerDigits(15); + str=decimalFormat.format(d); + */ + + //如果结果是整数,则去掉尾巴 + if (str.endsWith(".00")) { + str = str.replace(".00", ""); + } + return str; + } + + /** + * 金额是double类型的要先转换成字符串 + * + * @param money 金额 + */ + public static String transform(double money) { + String moneyStr = getDecimalStr(money); + return transform(moneyStr); + } + + /** + * 金额转换成大字 + * 我的思路: + * 1、double数值转换成数值字符串 + * 2、处理整数部分: + * 填充到16位,不足16位则前面补'0',然后右起分成四组,每组根据"x仟x佰x拾x"的规则转换成大写,若该组为"0000"则结果是"零"; + * 对这四组结果从高位到低位拼接起来,规则:[组4]万[组3]亿[组2]万[组1]圆。 + * 3、处理小数部分(不多说) + */ + public static String transform(String moneyStr) { + String[] parts = moneyStr.split("\\."); //区别整数、小数部分 + String result = ""; + + //处理整数部分 + int length = parts[0].length(); //整数部分的位数 + if (length > 15) { + return "金额太大,不能处理整数部分超过15位的金额!"; + } + String intPart = parts[0]; + + //填充到16位,因为是分4组,每组4个数字 + while (intPart.length() < 16) { + intPart = '0' + intPart; + } + //共分四组,右起四位一组,例如:0001,2003,0030,3400 + String[] groups = new String[4]; + for (int i = 0; i < groups.length; i++) { + int start = intPart.length() - (i + 1) * 4; //开始位置 + int end = intPart.length() - i * 4; //结束位置 + groups[i] = intPart.substring(start, end); + groups[i] = transformGroup(groups[i]); //当前组的四位数字转换成大写 + } + + //对这四组结果从高位到低位拼接起来,规则:[组4]万[组3]亿[组2]万[组1]圆 + for (int i = groups.length - 1; i >= 0; i--) { + if (i == 3) { //第四组:万亿级 + if (!"零".equals(groups[i])) { + result += groups[i] + "万"; + } + } else if (i == 2) { //第三组:亿级 + if (!"零".equals(groups[i])) { + result += groups[i] + "亿"; + } else { + if (result.length() > 0) { + result += "亿"; + } + } + } else if (i == 1) { //第二组:万级 + if (!"零".equals(groups[i])) { + result += groups[i] + "万"; + } else if (!groups[i].startsWith("零")) { + result += groups[i]; + } + } else { //第一组:千级 + if (!"零".equals(groups[i]) || result.length() == 0) { + result += groups[i]; + } + result += "元"; + } + } + if (!"零元".equals(result) && result.startsWith("零")) { + result = result.substring(1, result.length()); //最前面的可能出现的“零”去掉 + } + + //处理小数部分 + if (parts.length == 2) { + String decimalPart = parts[1]; //小数部分 + for (int i = 0; i < decimalPart.length(); i++) { + int num = Integer.valueOf(decimalPart.charAt(i) + ""); //提取数字,左起 + result += big.charAt(num) + "" + units[1].charAt(i); //数字变大写加上单位 + } + result = result.replace("零角", "零"); //去掉"零角"的"角" + result = result.replace("零分", ""); //去掉"零分" + } else { + result += "整"; //没有小数部分,则加上“整” + } + + return result; + } + + /** + * 处理整数部分的组,右起每四位是一组 + * + * @param group 四位数字字符串 + */ + public static String transformGroup(String group) { + String result = ""; + int length = group.length(); + for (int i = 0; i < length; i++) { + int digit = Integer.valueOf(group.charAt(i) + ""); //单个数字,左起 + String unit = ""; //单位 + if (i != length - 1) { + unit = units[0].charAt(i) + ""; + } + result += big.charAt(digit) + unit; //数字变大写加上单位 + } + + result = result.replace("零仟", "零"); + result = result.replace("零佰", "零"); + result = result.replace("零拾", "零"); + + while (result.contains("零零")) { + result = result.replace("零零", "零"); //如果有“零零”则变成一个“零” + } + + if (!"零".equals(result) && result.endsWith("零")) { + result = result.substring(0, result.length() - 1); //最未尾的可能出现的“零”去掉 + } + return result; + } + +} From c3531d323a81c55299844e9441b6851980984e99 Mon Sep 17 00:00:00 2001 From: God <10745413@qq.com> Date: Sat, 12 Nov 2022 11:23:09 +0800 Subject: [PATCH 04/24] =?UTF-8?q?=E9=97=AE=E9=A2=98=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/yxt/common/base/config/web/FileController.java | 1 - 1 file changed, 1 deletion(-) diff --git a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/config/web/FileController.java b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/config/web/FileController.java index 9474215..bb73538 100644 --- a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/config/web/FileController.java +++ b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/config/web/FileController.java @@ -100,7 +100,6 @@ public class FileController { @GetMapping("/download") public ResultBean download(@RequestParam(value = "filePath") String filePath, @RequestParam(value = "outFileName") String outFileName) { ResultBean rb = ResultBean.fireFail(); - File file = fileUploadComponent.findFileByPath(filePath); if (file == null) return rb.setMsg("文件不存在"); From 51cc18eec6c31f98c295554fe45307d324fd7428 Mon Sep 17 00:00:00 2001 From: dimengzhe <251008545@qq.com> Date: Wed, 16 Nov 2022 13:25:13 +0800 Subject: [PATCH 05/24] =?UTF-8?q?=E5=90=88=E5=90=8C=E5=AE=A1=E6=A0=B8?= =?UTF-8?q?=E5=90=8E=E6=9B=B4=E6=96=B0=E5=AE=A2=E6=88=B7=E6=A1=A3=E6=A1=88?= =?UTF-8?q?=E4=BB=A5=E5=8F=8A=E4=BA=A4=E8=BD=A6=E7=A1=AE=E8=AE=A4=E9=83=A8?= =?UTF-8?q?=E5=88=86=E6=A8=A1=E6=9D=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/base/utils/WordConvertUtils.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordConvertUtils.java b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordConvertUtils.java index 6c5451a..8d132b3 100644 --- a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordConvertUtils.java +++ b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordConvertUtils.java @@ -26,7 +26,7 @@ public class WordConvertUtils { * @param fileName 文件名 */ public static void creatWord(Map map, File file, String targetPath, String fileName, String dir) { - String curDate = DateUtils.dateConvertStr(new Date(), "yyyy年MM月dd日"); +// String curDate = DateUtils.dateConvertStr(new Date(), "yyyy年MM月dd日"); try { //Configuration 用于读取ftl文件 Configuration configuration = new Configuration(new Version("2.3.0")); @@ -44,12 +44,32 @@ public class WordConvertUtils { Template template = configuration.getTemplate(file.getName(), "utf-8"); Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), "utf-8"), 10240); template.process(map, out); + file.delete(); out.close(); } catch (Exception e) { e.printStackTrace(); } } + public static void inputStreamToFile(InputStream ins, File file) { + OutputStream os = null; + try { + os = new FileOutputStream(file); + + int bytesRead = 0; + byte[] buffer = new byte[8192]; + while ((bytesRead = ins.read(buffer, 0, 8192)) != -1) { + os.write(buffer, 0, bytesRead); + } + os.close(); + ins.close(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + /** * word转换为pdf * From a9f1ef33b5942ec981495885fed4de18cc07f8a7 Mon Sep 17 00:00:00 2001 From: dimengzhe <251008545@qq.com> Date: Wed, 16 Nov 2022 21:31:14 +0800 Subject: [PATCH 06/24] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/base/utils/WordConvertUtils.java | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordConvertUtils.java b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordConvertUtils.java index 8d132b3..1c38cac 100644 --- a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordConvertUtils.java +++ b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordConvertUtils.java @@ -8,7 +8,6 @@ import freemarker.template.Template; import freemarker.template.Version; import java.io.*; -import java.util.Date; import java.util.Map; /** @@ -51,6 +50,32 @@ public class WordConvertUtils { } } + public static void creatWord1(Map map, File file, String targetPath, String fileName, File dir) { +// String curDate = DateUtils.dateConvertStr(new Date(), "yyyy年MM月dd日"); + try { + //Configuration 用于读取ftl文件 + Configuration configuration = new Configuration(new Version("2.3.0")); + configuration.setDefaultEncoding("utf-8"); + //指定路径的第二种方式 + configuration.setDirectoryForTemplateLoading(dir); + //输出文档路径及名称 + File targetFile = new File(targetPath); + if (!targetFile.exists()) { + targetFile.mkdirs(); + } + targetPath = targetPath + fileName; + File outFile = new File(targetPath); + //以utf-8的编码读取ftl文件 + Template template = configuration.getTemplate(file.getName(), "utf-8"); + Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), "utf-8"), 10240); + template.process(map, out); + file.delete(); + out.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + public static void inputStreamToFile(InputStream ins, File file) { OutputStream os = null; try { From 46a52628430ba58c7fc4b973bec09070d3a3375c Mon Sep 17 00:00:00 2001 From: God <10745413@qq.com> Date: Thu, 17 Nov 2022 18:37:58 +0800 Subject: [PATCH 07/24] =?UTF-8?q?=E9=97=AE=E9=A2=98=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yxt/common/base/utils/WordObj.java | 237 ++++++++++++++++++ .../com/yxt/common/base/utils/WordUtils.java | 149 ++++++++++- 2 files changed, 384 insertions(+), 2 deletions(-) create mode 100644 yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordObj.java diff --git a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordObj.java b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordObj.java new file mode 100644 index 0000000..4d7a7c0 --- /dev/null +++ b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordObj.java @@ -0,0 +1,237 @@ +package com.yxt.common.base.utils; + +import com.jacob.activeX.ActiveXComponent; +import com.jacob.com.ComThread; +import com.jacob.com.Dispatch; +import com.jacob.com.Variant; + +public class WordObj { + public WordObj() + { + } + + private static WordObj instance; + + private Dispatch doc = null; + + private Dispatch activeWindow = null; + + private Dispatch docSelection = null; + + private Dispatch wrdDocs = null; + + private String fileName; + + private ActiveXComponent wrdCom; + + /** + * 获取Word操作静态实例对象 + * + * @return 报表汇总业务操作 + */ + public final static synchronized WordObj getInstance() + { + if (instance == null) + instance = new WordObj(); + return instance; + + } + + /** + * 初始化Word对象 + * + * @return 是否初始化成功 + */ + public boolean initWordObj() + { + boolean retFlag = false; + ComThread.InitSTA();// 初始化com的线程,非常重要!!使用结束后要调用 realease方法 + wrdCom = new ActiveXComponent("Word.Application"); + try + { + // 返回wrdCom.Documents的Dispatch + wrdDocs = wrdCom.getProperty("Documents").toDispatch(); + wrdCom.setProperty("Visible", new Variant(true)); + + retFlag = true; + } + catch (Exception e) + { + retFlag = false; + e.printStackTrace(); + } + return retFlag; + } + + /** + * 创建一个新的word文档 + * + */ + + public void createNewDocument() + { + doc = Dispatch.call(wrdDocs, "Add").toDispatch(); + docSelection = Dispatch.get(wrdCom, "Selection").toDispatch(); + + } + + /** + * 取得活动窗体对象 + * + */ + public void getActiveWindow() + { + // 取得活动窗体对象 + activeWindow = wrdCom.getProperty("ActiveWindow").toDispatch(); + + } + + /** + * 打开一个已存在的文档 + * + * @param docPath + */ + + public void openDocument(String docPath) + { + if (this.doc != null) + { + this.closeDocument(); + } + doc = Dispatch.call(wrdDocs, "Open", docPath).toDispatch(); + docSelection = Dispatch.get(wrdCom, "Selection").toDispatch(); + } + + /** + * 关闭当前word文档 + * + */ + public void closeDocument() + { + if (doc != null) + { + Dispatch.call(doc, "Save"); + Dispatch.call(doc, "Close", new Variant(0)); + doc = null; + } + } + + /** + * 文档设置水印 + * + * @param waterMarkStr 水印字符串 + */ + public void setWaterMark(String waterMarkStr) + { + // 取得活动窗格对象 + Dispatch activePan = Dispatch.get(activeWindow, "ActivePane") + .toDispatch(); + // 取得视窗对象 + Dispatch view = Dispatch.get(activePan, "View").toDispatch(); + //输入页眉内容 + Dispatch.put(view, "SeekView", new Variant(9)); + Dispatch headfooter = Dispatch.get(docSelection, "HeaderFooter") + .toDispatch(); + //取得图形对象 + Dispatch shapes = Dispatch.get(headfooter, "Shapes").toDispatch(); + //给文档全部加上水印 + Dispatch selection = Dispatch.call(shapes, "AddTextEffect", + new Variant(9), waterMarkStr, "宋体", new Variant(1), + new Variant(false), new Variant(false), new Variant(0), + new Variant(0)).toDispatch(); + Dispatch.call(selection, "Select"); + //设置水印参数 + Dispatch shapeRange = Dispatch.get(docSelection, "ShapeRange") + .toDispatch(); + Dispatch.put(shapeRange, "Name", "PowerPlusWaterMarkObject1"); + Dispatch textEffect = Dispatch.get(shapeRange, "TextEffect").toDispatch(); + Dispatch.put(textEffect, "NormalizedHeight", new Boolean(false)); + Dispatch line = Dispatch.get(shapeRange, "Line").toDispatch(); + Dispatch.put(line, "Visible", new Boolean(false)); + Dispatch fill = Dispatch.get(shapeRange, "Fill").toDispatch(); + Dispatch.put(fill, "Visible", new Boolean(true)); + //设置水印透明度 + Dispatch.put(fill, "Transparency", new Variant(0.5)); + Dispatch foreColor = Dispatch.get(fill, "ForeColor").toDispatch(); + //设置水印颜色 + Dispatch.put(foreColor, "RGB", new Variant(16711680)); + Dispatch.call(fill, "Solid"); + //设置水印旋转 + Dispatch.put(shapeRange, "Rotation", new Variant(315)); + Dispatch.put(shapeRange, "LockAspectRatio", new Boolean(true)); + Dispatch.put(shapeRange, "Height", new Variant(117.0709)); + Dispatch.put(shapeRange, "Width", new Variant(468.2835)); + Dispatch.put(shapeRange, "Left", new Variant(-999995)); + Dispatch.put(shapeRange, "Top", new Variant(-999995)); + Dispatch wrapFormat = Dispatch.get(shapeRange, "WrapFormat").toDispatch(); + //是否允许交叠 + Dispatch.put(wrapFormat, "AllowOverlap", new Variant(true)); + Dispatch.put(wrapFormat, "Side", new Variant(3)); + Dispatch.put(wrapFormat, "Type", new Variant(3)); + Dispatch.put(shapeRange, "RelativeHorizontalPosition", new Variant(0)); + Dispatch.put(shapeRange, "RelativeVerticalPosition", new Variant(0)); + Dispatch.put(view, "SeekView", new Variant(0)); + } + + + + /** + * 关闭Word资源 + * + * + */ + public void closeWordObj() + { + + // 关闭word文件 + wrdCom.invoke("Quit", new Variant[] {}); + // 释放com线程。根据jacob的帮助文档,com的线程回收不由java的垃圾回收器处理 + ComThread.Release(); + } + + /** + * 得到文件名 + * + * @return . + */ + public String getFileName() + { + return fileName; + } + + /** + * 设置文件名 + * + * @param fileName . + */ + public void setFileName(String fileName) + { + this.fileName = fileName; + } + + /** + * 测试功能 + * + */ + public static void main(String[] argv) + { + WordObj d = WordObj.getInstance(); + try + { + if (d.initWordObj()) + { + d.createNewDocument(); + d.getActiveWindow(); + d.setWaterMark("HEllo"); + // d.closeWordObj(); + } + else + System.out.println("初始化Word读写对象失败!"); + } + catch (Exception e) + { + d.closeWordObj(); + } + } + +} diff --git a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordUtils.java b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordUtils.java index 15a7bae..c06fa39 100644 --- a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordUtils.java +++ b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordUtils.java @@ -4,6 +4,7 @@ import cn.hutool.core.codec.Base64; import com.jacob.activeX.ActiveXComponent; import com.jacob.com.ComThread; import com.jacob.com.Dispatch; +import com.jacob.com.Variant; import freemarker.template.Configuration; import freemarker.template.Template; import freemarker.template.Version; @@ -84,6 +85,18 @@ public class WordUtils { * @param pdfName pdf名称 */ public static void doc2pdf(String wordFile, String pdfPath, String pdfName) { + doc2pdf( wordFile, pdfPath, pdfName,""); + } + + /** + * word转换为pdf + * + * @param wordFile word的路径 + * @param pdfPath pdf的路径 + * @param pdfName pdf名称 + * @param mark 水印 + */ + public static void doc2pdf(String wordFile, String pdfPath, String pdfName,String mark) { ActiveXComponent app = null; System.out.println("开始转换..."); long start = System.currentTimeMillis(); @@ -97,6 +110,8 @@ public class WordUtils { // 打开文档 document = Dispatch.call(documents, "Open", wordFile, false, true).toDispatch(); // 如果文件存在的话,不会覆盖,会直接报错,所以我们需要判断文件是否存在 + //addWatermark(wordFile,wordFile,mark); + //setWaterMark(app,mark); File targetFile = new File(pdfPath); if (!targetFile.exists()) { targetFile.mkdirs(); @@ -124,8 +139,6 @@ public class WordUtils { } } - - public static void main(String[] args) { Map dataMap = new HashMap(); String curDate = DateUtils.dateConvertStr(new Date(), "yyyy年MM月dd日"); @@ -199,4 +212,136 @@ public class WordUtils { this.remarks = remarks; } } + public static void addWatermark(String src, String des, String text) throws Exception { + ComThread.InitMTA(); + ActiveXComponent wordApp = new ActiveXComponent("word.Application"); + // 文档隐藏时进行应用操作 + wordApp.setProperty("Visible", new Variant(false)); + // 实例化模板Workbooks对象 + Dispatch documents = wordApp.getProperty("Documents").toDispatch(); + //打开文件 + Dispatch doc = Dispatch.call(documents, "Open", src, new Variant(false),new Variant(false)).toDispatch(); + Dispatch docSelect = Dispatch.get(wordApp, "Selection").toDispatch(); + //取得活动窗体对象 + Dispatch activeDoc = wordApp.getProperty("ActiveWindow").toDispatch(); + try { + //添加水印,多个水印 + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 4; j++) { + //取得活动窗体对象 + Dispatch activePan = Dispatch.get(activeDoc, "ActivePane").toDispatch(); + //取得视窗对象 + Dispatch view = Dispatch.get(activePan, "View").toDispatch(); + //打开页眉 + Dispatch.put(view, "SeekView", new Variant(9)); + //获取页眉和页脚 + Dispatch headfooter = Dispatch.get(docSelect, "HeaderFooter") + .toDispatch(); + //取得图形对象 + Dispatch shapes = Dispatch.get(headfooter, "Shapes").toDispatch(); + /**插入文字,并转为图片: + * 操作对象、方法、艺术字格式、水印内容、字体、字体大小、字体是否粗体、字体是否斜体、左边距、上边距 + */ + Dispatch selection = Dispatch.call(shapes, "AddTextEffect", + new Variant(9), text, "宋体", new Variant(10), + new Variant(false), new Variant(false), new Variant(0), + new Variant(0)).toDispatch(); + //选中当前文档水印 + Dispatch.call(selection, "Select"); + Dispatch shapeRange = Dispatch.get(docSelect, "ShapeRange") + .toDispatch(); + Dispatch textEffect = Dispatch.get(shapeRange, "TextEffect") + .toDispatch(); + Dispatch.put(textEffect, "NormalizedHeight", new Boolean(false)); + Dispatch line = Dispatch.get(shapeRange, "Line").toDispatch(); + Dispatch.put(line, "Visible", new Boolean(false)); + Dispatch fill = Dispatch.get(shapeRange, "Fill").toDispatch(); + Dispatch.put(fill, "Visible", new Boolean(true)); + // 设置水印透明度 + Dispatch.put(fill, "Transparency", new Variant(0.5)); + Dispatch foreColor = Dispatch.get(fill, "ForeColor").toDispatch(); + //设置水印颜色 + Dispatch.put(foreColor, "RGB", new Variant(16711620)); + Dispatch.call(fill, "Solid"); + // 设置水印旋转 + Dispatch.put(shapeRange, "Rotation", new Variant(315)); + Dispatch.put(shapeRange, "LockAspectRatio", new Boolean(true)); + //设置水印宽高 + Dispatch.put(shapeRange, "Height", new Variant(11)); + Dispatch.put(shapeRange, "Width", new Variant(90)); + //设置水印位置,相对左上角 + Dispatch.put(shapeRange, "Left", new Variant(j * 120 - 60)); + Dispatch.put(shapeRange, "Top", new Variant(i * 270)); + //恢复视图 + Dispatch.put(view, "SeekView", new Variant(0)); + } + } + //另存为目标文件 + Dispatch.call(doc, "SaveAS",des,new Variant(true) ); + } catch (Exception e) { + e.printStackTrace(); + } finally { + Dispatch.call(doc, "Close", new Variant(-1),new Variant(1),new Variant(true)); + if (wordApp != null) { + wordApp.invoke("Quit", new Variant[]{}); + } + ComThread.Release(); + } + } +/* + public static void setWaterMark(ActiveXComponent activeWindow,String waterMarkStr) + { + + + // 取得活动窗格对象 + Dispatch activePan = Dispatch.get(activeWindow, "ActivePane").toDispatch(); + // 取得视窗对象 + Dispatch view = Dispatch.get(activePan, "View").toDispatch(); + Dispatch docSelection=Dispatch.get(activeWindow, "Selection").toDispatch(); + //输入页眉内容 + Dispatch.put(view, "SeekView", new Variant(9)); + Dispatch headfooter = Dispatch.get(docSelection, "HeaderFooter") + .toDispatch(); + //取得图形对象 + Dispatch shapes = Dispatch.get(headfooter, "Shapes").toDispatch(); + //给文档全部加上水印 + Dispatch selection = Dispatch.call(shapes, "AddTextEffect", + new Variant(9), waterMarkStr, "宋体", new Variant(1), + new Variant(false), new Variant(false), new Variant(0), + new Variant(0)).toDispatch(); + Dispatch.call(selection, "Select"); + //设置水印参数 + Dispatch shapeRange = Dispatch.get(docSelection, "ShapeRange") + .toDispatch(); + Dispatch.put(shapeRange, "Name", "PowerPlusWaterMarkObject1"); + Dispatch textEffect = Dispatch.get(shapeRange, "TextEffect").toDispatch(); + Dispatch.put(textEffect, "NormalizedHeight", new Boolean(false)); + Dispatch line = Dispatch.get(shapeRange, "Line").toDispatch(); + Dispatch.put(line, "Visible", new Boolean(false)); + Dispatch fill = Dispatch.get(shapeRange, "Fill").toDispatch(); + Dispatch.put(fill, "Visible", new Boolean(true)); + //设置水印透明度 + Dispatch.put(fill, "Transparency", new Variant(0.5)); + Dispatch foreColor = Dispatch.get(fill, "ForeColor").toDispatch(); + //设置水印颜色 + Dispatch.put(foreColor, "RGB", new Variant(16711680)); + Dispatch.call(fill, "Solid"); + //设置水印旋转 + Dispatch.put(shapeRange, "Rotation", new Variant(315)); + Dispatch.put(shapeRange, "LockAspectRatio", new Boolean(true)); + Dispatch.put(shapeRange, "Height", new Variant(117.0709)); + Dispatch.put(shapeRange, "Width", new Variant(468.2835)); + Dispatch.put(shapeRange, "Left", new Variant(-999995)); + Dispatch.put(shapeRange, "Top", new Variant(-999995)); + Dispatch wrapFormat = Dispatch.get(shapeRange, "WrapFormat").toDispatch(); + //是否允许交叠 + Dispatch.put(wrapFormat, "AllowOverlap", new Variant(true)); + Dispatch.put(wrapFormat, "Side", new Variant(3)); + Dispatch.put(wrapFormat, "Type", new Variant(3)); + Dispatch.put(shapeRange, "RelativeHorizontalPosition", new Variant(0)); + Dispatch.put(shapeRange, "RelativeVerticalPosition", new Variant(0)); + Dispatch.put(view, "SeekView", new Variant(0)); + }*/ + + } From a2faad097cd26255555480d14e452e1658671cd9 Mon Sep 17 00:00:00 2001 From: dimengzhe <251008545@qq.com> Date: Thu, 17 Nov 2022 21:47:12 +0800 Subject: [PATCH 08/24] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/component/DocPdfComponent.java | 14 ++++ .../common/base/utils/WordConvertUtils.java | 64 +++++++++++++++++++ 2 files changed, 78 insertions(+) diff --git a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/config/component/DocPdfComponent.java b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/config/component/DocPdfComponent.java index df389cc..611e77c 100644 --- a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/config/component/DocPdfComponent.java +++ b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/config/component/DocPdfComponent.java @@ -35,6 +35,12 @@ public class DocPdfComponent { @Value("${templateUrl.prefixUrl:http://127.0.0.1:8080/template/}") private String prefixTemplateUrl; + @Value("${templateUrl.uploadPdfUrl:http://127.0.0.1:8080/template/pdf/}") + private String uploadPdfUrl; + + @Value("${templateUrl.prefixPdfUrl:http://127.0.0.1:8080/template/pdf/}") + private String prefixPdfUrl; + /** * 根据ftl模板生成word * @@ -170,4 +176,12 @@ public class DocPdfComponent { public String getPrefixTemplateUrl() { return prefixTemplateUrl; } + + public String getUploadPdfUrl() { + return uploadPdfUrl; + } + + public String getPrefixPdfUrl() { + return prefixPdfUrl; + } } diff --git a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordConvertUtils.java b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordConvertUtils.java index 1c38cac..ca7dcfc 100644 --- a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordConvertUtils.java +++ b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordConvertUtils.java @@ -1,5 +1,9 @@ package com.yxt.common.base.utils; +import com.itextpdf.text.BaseColor; +import com.itextpdf.text.Element; +import com.itextpdf.text.Rectangle; +import com.itextpdf.text.pdf.*; import com.jacob.activeX.ActiveXComponent; import com.jacob.com.ComThread; import com.jacob.com.Dispatch; @@ -138,7 +142,67 @@ public class WordConvertUtils { System.out.println("关闭文档"); // 如果没有这句话,winword.exe进程将不会关闭 ComThread.Release(); + new File(wordFile).delete(); } } + + /** + * @param inputFile 源文件全路径:你的PDF文件地址 + * @param outputFile 输出全路径:添加水印后生成PDF存放的地址 + * @param outDir 添加水印后生成PDF存放的目录 + * @param waterMarkName 你的水印 + * @return 注意:源文件全路径和输出全路径最好不要写同一样的,不然有可能会报“java.io.FileNotFoundException:请求的操作无法在使用用户映射区域打开的文件上执行”的错误 + */ + public static boolean waterMark(String inputFile, String outputFile, String outDir, String waterMarkName) { + try { + File targetFile = new File(outDir); + if (!targetFile.exists()) { + targetFile.mkdirs(); + } + PdfReader reader = new PdfReader(inputFile); + PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(outputFile)); + // 这里的字体设置比较关键,这个设置是支持中文的写法 + BaseFont base = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);// 使用系统字体 + int total = reader.getNumberOfPages() + 1; + PdfContentByte under; + Rectangle pageRect = null; + for (int i = 1; i < total; i++) { + pageRect = stamper.getReader().getPageSizeWithRotation(i); + // 计算水印X,Y坐标 +// float x = pageRect.getWidth() / 10; +// float y = pageRect.getHeight() / 10 - 10; + float x = 290; + float y = 400; + // 获得PDF最顶层 + under = stamper.getOverContent(i); + under.saveState(); + // set Transparency + PdfGState gs = new PdfGState(); + // 设置透明度为0.2 +// gs.setFillOpacity(1.f); + gs.setFillOpacity(0.3f); + under.setGState(gs); + under.restoreState(); + under.beginText(); + under.setFontAndSize(base, 35); +// under.setColorFill(BaseColor.ORANGE); + under.setColorFill(BaseColor.BLACK); + + // 水印文字成45度角倾斜 + under.showTextAligned(Element.ALIGN_CENTER, waterMarkName, x, y, 45); + // 添加水印文字 + under.endText(); + under.setLineWidth(1f); + under.stroke(); + } + stamper.close(); + reader.close(); + new File(inputFile).delete(); + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } } From d03748ea89034cc84e4708227a3ab0cbd614a631 Mon Sep 17 00:00:00 2001 From: dimengzhe <251008545@qq.com> Date: Thu, 17 Nov 2022 22:16:41 +0800 Subject: [PATCH 09/24] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yxt-common/yxt-common-base/pom.xml | 31 +++--- .../common/base/utils/WordConvertUtils.java | 27 +++++ yxt-parent/pom.xml | 100 ++++++++++-------- 3 files changed, 100 insertions(+), 58 deletions(-) diff --git a/yxt-common/yxt-common-base/pom.xml b/yxt-common/yxt-common-base/pom.xml index ff5d339..32ddefe 100644 --- a/yxt-common/yxt-common-base/pom.xml +++ b/yxt-common/yxt-common-base/pom.xml @@ -120,12 +120,6 @@ javase 3.3.2 - - - com.itextpdf - itextpdf - 5.4.3 - org.apache.httpcomponents httpclient @@ -165,17 +159,11 @@ hutool-all ${hutool.version} - org.freemarker freemarker 2.3.29 - - com.jacob - jacob - 1.18 - javax.xml.bind jaxb-api @@ -196,6 +184,25 @@ activation 1.1.1 + + com.jacob + jacob + 1.18 + + + com.itextpdf + itextpdf + 5.5.11 + + + com.itextpdf + itext-asian + 5.2.0 + + + org.apache.pdfbox + pdfbox + diff --git a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordConvertUtils.java b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordConvertUtils.java index ca7dcfc..2de10d2 100644 --- a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordConvertUtils.java +++ b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordConvertUtils.java @@ -10,8 +10,11 @@ import com.jacob.com.Dispatch; import freemarker.template.Configuration; import freemarker.template.Template; import freemarker.template.Version; +import org.apache.pdfbox.io.MemoryUsageSetting; +import org.apache.pdfbox.multipdf.PDFMergerUtility; import java.io.*; +import java.util.List; import java.util.Map; /** @@ -205,4 +208,28 @@ public class WordConvertUtils { return false; } } + + /** + * pdf合并 + * + * @param files 源文件的相对路径 例:["D:\anrui\upload\template\pdf\111.pdf","D:\anrui\upload\template\222.pdf"] + * @param targetPath 输出的pdf的路径 D:\anrui\upload\template\pdf\333.pdf + * @return + * @throws Exception + */ + public static File mulFile2One(List files, String targetPath) throws Exception { + PDFMergerUtility mergePdf = new PDFMergerUtility(); + for (File f : files) { + if (f.exists() && f.isFile()) { + // 循环添加要合并的pdf + mergePdf.addSource(f); + } + } + // 设置合并生成pdf文件名称 + mergePdf.setDestinationFileName(targetPath); + // 合并pdf + mergePdf.mergeDocuments(MemoryUsageSetting.setupMainMemoryOnly()); + //ToDo:根据需求实现是否要删除源文件 + return new File(targetPath); + } } diff --git a/yxt-parent/pom.xml b/yxt-parent/pom.xml index 58a8876..eeabf10 100644 --- a/yxt-parent/pom.xml +++ b/yxt-parent/pom.xml @@ -77,6 +77,8 @@ 4.1.2 6.5.0 + 2.0.25 + @@ -401,56 +403,62 @@ + + org.apache.pdfbox + pdfbox + ${pdfbox.version} + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - nexus-releases - http://nexus3.yyundong.com/repository/yxt-mvn-releases/ - - - nexus-snapshots - http://nexus3.yyundong.com/repository/yxt-mvn-snapshot/ - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + nexus-releases + http://nexus3.yyundong.com/repository/yxt-mvn-releases/ + + + nexus-snapshots + http://nexus3.yyundong.com/repository/yxt-mvn-snapshot/ + + \ No newline at end of file From 3e6d81546400ab51efcf363ab9008eced1836193 Mon Sep 17 00:00:00 2001 From: dimengzhe <251008545@qq.com> Date: Fri, 18 Nov 2022 09:25:26 +0800 Subject: [PATCH 10/24] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/yxt/common/base/utils/WordConvertUtils.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordConvertUtils.java b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordConvertUtils.java index 2de10d2..4528fe1 100644 --- a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordConvertUtils.java +++ b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordConvertUtils.java @@ -212,8 +212,8 @@ public class WordConvertUtils { /** * pdf合并 * - * @param files 源文件的相对路径 例:["D:\anrui\upload\template\pdf\111.pdf","D:\anrui\upload\template\222.pdf"] - * @param targetPath 输出的pdf的路径 D:\anrui\upload\template\pdf\333.pdf + * @param files 源文件的相对路径 + * @param targetPath 输出的pdf的路径 * @return * @throws Exception */ From f066b3cdec6b3b5f88dcbd675ccfe065ae5cd828 Mon Sep 17 00:00:00 2001 From: yxt_djz Date: Fri, 18 Nov 2022 09:40:45 +0800 Subject: [PATCH 11/24] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=B0=B4=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yxt/common/base/utils/WordUtils.java | 164 +++++++++--------- 1 file changed, 85 insertions(+), 79 deletions(-) diff --git a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordUtils.java b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordUtils.java index c06fa39..600adfc 100644 --- a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordUtils.java +++ b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordUtils.java @@ -110,7 +110,7 @@ public class WordUtils { // 打开文档 document = Dispatch.call(documents, "Open", wordFile, false, true).toDispatch(); // 如果文件存在的话,不会覆盖,会直接报错,所以我们需要判断文件是否存在 - //addWatermark(wordFile,wordFile,mark); + addWatermark(app,documents,document,wordFile,"D:\\anrui\\1.doc",mark); //setWaterMark(app,mark); File targetFile = new File(pdfPath); if (!targetFile.exists()) { @@ -139,88 +139,13 @@ public class WordUtils { } } - public static void main(String[] args) { - Map dataMap = new HashMap(); - String curDate = DateUtils.dateConvertStr(new Date(), "yyyy年MM月dd日"); - dataMap.put("partyA", "甲方卖出方"); - dataMap.put("partyB", "乙方买受方"); - // 图片 -// dataMap.put("imgStr1", getImageStr("D:\\fileTest\\name.png")); -// dataMap.put("imgStr2", getImageStr("D:\\fileTest\\zhang.png")); - // 列表 - Car car1 = new Car("奔驰", "1001", "v10"); - Car car2 = new Car("宝马", "1002", "v10"); - Car car3 = new Car("奥迪", "1003", "v10"); - List list = new ArrayList<>(); - list.add(car1); - list.add(car2); - list.add(car3); - dataMap.put("carList", list); - - dataMap.put("money", "1"); - dataMap.put("money1", "2"); - dataMap.put("money2", "3"); - dataMap.put("address", "河北省石家庄市桥西区"); - -// String typeName = "车辆登记合同"; - String typeName = "新车买卖合同(现车)"; // 模板名 - String sourcePath = "D:\\anrui\\"; // 模板路径 -// String fileName = "车辆登记合同New.doc"; - String fileName = "新车买.doc"; // 生成的word文件名 - String targetPath = sourcePath; // 生成文件路径 - - - creatWord(dataMap, typeName, sourcePath, targetPath, fileName); // 调用生成word方法 - String wordPath = targetPath + "\\" + fileName; // 新生成的word路径; - String pdfName = typeName + ".pdf"; // 生成pdf的文件名 - doc2pdf(wordPath, targetPath, pdfName); // 调用将word转换为pdf的方法 - - } - - public static class Car { - private String brand; - private String vinNo; - private String remarks; - - public Car(String brand, String vinNo, String remarks) { - this.brand = brand; - this.vinNo = vinNo; - this.remarks = remarks; - } - - public String getBrand() { - return brand; - } - - public void setBrand(String brand) { - this.brand = brand; - } - - public String getVinNo() { - return vinNo; - } - - public void setVinNo(String vinNo) { - this.vinNo = vinNo; - } - public String getRemarks() { - return remarks; - } - - public void setRemarks(String remarks) { - this.remarks = remarks; - } - } - public static void addWatermark(String src, String des, String text) throws Exception { + public static void addWatermark(ActiveXComponent wordApp, Dispatch documents,Dispatch doc,String src, String des, String text) throws Exception { ComThread.InitMTA(); - ActiveXComponent wordApp = new ActiveXComponent("word.Application"); // 文档隐藏时进行应用操作 wordApp.setProperty("Visible", new Variant(false)); // 实例化模板Workbooks对象 - Dispatch documents = wordApp.getProperty("Documents").toDispatch(); //打开文件 - Dispatch doc = Dispatch.call(documents, "Open", src, new Variant(false),new Variant(false)).toDispatch(); Dispatch docSelect = Dispatch.get(wordApp, "Selection").toDispatch(); //取得活动窗体对象 Dispatch activeDoc = wordApp.getProperty("ActiveWindow").toDispatch(); @@ -281,11 +206,20 @@ public class WordUtils { } catch (Exception e) { e.printStackTrace(); } finally { - Dispatch.call(doc, "Close", new Variant(-1),new Variant(1),new Variant(true)); + /* Dispatch.call(doc, "Close", new Variant(-1),new Variant(1),new Variant(true)); if (wordApp != null) { wordApp.invoke("Quit", new Variant[]{}); } - ComThread.Release(); + ComThread.Release();*/ + // 关闭文档 + // Dispatch.call(doc, "Close", false); + // 关闭office + // wordApp.invoke("Quit", 0); + System.out.println("关闭文档"); +// if (app != null) +// app.invoke("Quit", new Variant[]{}); + // 如果没有这句话,winword.exe进程将不会关闭 + // ComThread.Release(); } } /* @@ -343,5 +277,77 @@ public class WordUtils { Dispatch.put(view, "SeekView", new Variant(0)); }*/ + public static void main(String[] args) { + Map dataMap = new HashMap(); + String curDate = DateUtils.dateConvertStr(new Date(), "yyyy年MM月dd日"); + dataMap.put("partyA", "甲方卖出方"); + dataMap.put("partyB", "乙方买受方"); + // 图片 +// dataMap.put("imgStr1", getImageStr("D:\\fileTest\\name.png")); +// dataMap.put("imgStr2", getImageStr("D:\\fileTest\\zhang.png")); + // 列表 + Car car1 = new Car("奔驰", "1001", "v10"); + Car car2 = new Car("宝马", "1002", "v10"); + Car car3 = new Car("奥迪", "1003", "v10"); + List list = new ArrayList<>(); + list.add(car1); + list.add(car2); + list.add(car3); + dataMap.put("carList", list); + + dataMap.put("money", "1"); + dataMap.put("money1", "2"); + dataMap.put("money2", "3"); + dataMap.put("address", "河北省石家庄市桥西区"); + +// String typeName = "车辆登记合同"; + String typeName = "新车买卖合同(现车)"; // 模板名 + String sourcePath = "D:\\anrui\\"; // 模板路径 +// String fileName = "车辆登记合同New.doc"; + String fileName = "新车买.doc"; // 生成的word文件名 + String targetPath = sourcePath; // 生成文件路径 + + + creatWord(dataMap, typeName, sourcePath, targetPath, fileName); // 调用生成word方法 + String wordPath = targetPath + "\\" + fileName; // 新生成的word路径; + String pdfName = typeName + ".pdf"; // 生成pdf的文件名 + doc2pdf(wordPath, targetPath, pdfName); // 调用将word转换为pdf的方法 + } + + public static class Car { + private String brand; + private String vinNo; + private String remarks; + + public Car(String brand, String vinNo, String remarks) { + this.brand = brand; + this.vinNo = vinNo; + this.remarks = remarks; + } + + public String getBrand() { + return brand; + } + + public void setBrand(String brand) { + this.brand = brand; + } + + public String getVinNo() { + return vinNo; + } + + public void setVinNo(String vinNo) { + this.vinNo = vinNo; + } + + public String getRemarks() { + return remarks; + } + + public void setRemarks(String remarks) { + this.remarks = remarks; + } + } } From d43548e21a2df52effaef706068e08a16935e56a Mon Sep 17 00:00:00 2001 From: God <10745413@qq.com> Date: Fri, 18 Nov 2022 10:16:33 +0800 Subject: [PATCH 12/24] =?UTF-8?q?=E9=97=AE=E9=A2=98=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/yxt/common/base/utils/WordUtils.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordUtils.java b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordUtils.java index 600adfc..c0f0a3c 100644 --- a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordUtils.java +++ b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordUtils.java @@ -110,7 +110,9 @@ public class WordUtils { // 打开文档 document = Dispatch.call(documents, "Open", wordFile, false, true).toDispatch(); // 如果文件存在的话,不会覆盖,会直接报错,所以我们需要判断文件是否存在 - addWatermark(app,documents,document,wordFile,"D:\\anrui\\1.doc",mark); + if (StringUtils.isNotBlank(mark)){ + addWatermark(app,documents,document,wordFile,wordFile,mark); + } //setWaterMark(app,mark); File targetFile = new File(pdfPath); if (!targetFile.exists()) { @@ -158,7 +160,7 @@ public class WordUtils { //取得视窗对象 Dispatch view = Dispatch.get(activePan, "View").toDispatch(); //打开页眉 - Dispatch.put(view, "SeekView", new Variant(9)); + Dispatch.put(view, "SeekView", new Variant(1)); //获取页眉和页脚 Dispatch headfooter = Dispatch.get(docSelect, "HeaderFooter") .toDispatch(); From 594c444ee39aa26c2ede55866156b51cccfbf93a Mon Sep 17 00:00:00 2001 From: God <10745413@qq.com> Date: Fri, 18 Nov 2022 10:25:36 +0800 Subject: [PATCH 13/24] =?UTF-8?q?=E9=97=AE=E9=A2=98=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yxt/common/base/utils/WordObj.java | 237 ------------------ .../com/yxt/common/base/utils/WordUtils.java | 70 ------ 2 files changed, 307 deletions(-) delete mode 100644 yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordObj.java diff --git a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordObj.java b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordObj.java deleted file mode 100644 index 4d7a7c0..0000000 --- a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordObj.java +++ /dev/null @@ -1,237 +0,0 @@ -package com.yxt.common.base.utils; - -import com.jacob.activeX.ActiveXComponent; -import com.jacob.com.ComThread; -import com.jacob.com.Dispatch; -import com.jacob.com.Variant; - -public class WordObj { - public WordObj() - { - } - - private static WordObj instance; - - private Dispatch doc = null; - - private Dispatch activeWindow = null; - - private Dispatch docSelection = null; - - private Dispatch wrdDocs = null; - - private String fileName; - - private ActiveXComponent wrdCom; - - /** - * 获取Word操作静态实例对象 - * - * @return 报表汇总业务操作 - */ - public final static synchronized WordObj getInstance() - { - if (instance == null) - instance = new WordObj(); - return instance; - - } - - /** - * 初始化Word对象 - * - * @return 是否初始化成功 - */ - public boolean initWordObj() - { - boolean retFlag = false; - ComThread.InitSTA();// 初始化com的线程,非常重要!!使用结束后要调用 realease方法 - wrdCom = new ActiveXComponent("Word.Application"); - try - { - // 返回wrdCom.Documents的Dispatch - wrdDocs = wrdCom.getProperty("Documents").toDispatch(); - wrdCom.setProperty("Visible", new Variant(true)); - - retFlag = true; - } - catch (Exception e) - { - retFlag = false; - e.printStackTrace(); - } - return retFlag; - } - - /** - * 创建一个新的word文档 - * - */ - - public void createNewDocument() - { - doc = Dispatch.call(wrdDocs, "Add").toDispatch(); - docSelection = Dispatch.get(wrdCom, "Selection").toDispatch(); - - } - - /** - * 取得活动窗体对象 - * - */ - public void getActiveWindow() - { - // 取得活动窗体对象 - activeWindow = wrdCom.getProperty("ActiveWindow").toDispatch(); - - } - - /** - * 打开一个已存在的文档 - * - * @param docPath - */ - - public void openDocument(String docPath) - { - if (this.doc != null) - { - this.closeDocument(); - } - doc = Dispatch.call(wrdDocs, "Open", docPath).toDispatch(); - docSelection = Dispatch.get(wrdCom, "Selection").toDispatch(); - } - - /** - * 关闭当前word文档 - * - */ - public void closeDocument() - { - if (doc != null) - { - Dispatch.call(doc, "Save"); - Dispatch.call(doc, "Close", new Variant(0)); - doc = null; - } - } - - /** - * 文档设置水印 - * - * @param waterMarkStr 水印字符串 - */ - public void setWaterMark(String waterMarkStr) - { - // 取得活动窗格对象 - Dispatch activePan = Dispatch.get(activeWindow, "ActivePane") - .toDispatch(); - // 取得视窗对象 - Dispatch view = Dispatch.get(activePan, "View").toDispatch(); - //输入页眉内容 - Dispatch.put(view, "SeekView", new Variant(9)); - Dispatch headfooter = Dispatch.get(docSelection, "HeaderFooter") - .toDispatch(); - //取得图形对象 - Dispatch shapes = Dispatch.get(headfooter, "Shapes").toDispatch(); - //给文档全部加上水印 - Dispatch selection = Dispatch.call(shapes, "AddTextEffect", - new Variant(9), waterMarkStr, "宋体", new Variant(1), - new Variant(false), new Variant(false), new Variant(0), - new Variant(0)).toDispatch(); - Dispatch.call(selection, "Select"); - //设置水印参数 - Dispatch shapeRange = Dispatch.get(docSelection, "ShapeRange") - .toDispatch(); - Dispatch.put(shapeRange, "Name", "PowerPlusWaterMarkObject1"); - Dispatch textEffect = Dispatch.get(shapeRange, "TextEffect").toDispatch(); - Dispatch.put(textEffect, "NormalizedHeight", new Boolean(false)); - Dispatch line = Dispatch.get(shapeRange, "Line").toDispatch(); - Dispatch.put(line, "Visible", new Boolean(false)); - Dispatch fill = Dispatch.get(shapeRange, "Fill").toDispatch(); - Dispatch.put(fill, "Visible", new Boolean(true)); - //设置水印透明度 - Dispatch.put(fill, "Transparency", new Variant(0.5)); - Dispatch foreColor = Dispatch.get(fill, "ForeColor").toDispatch(); - //设置水印颜色 - Dispatch.put(foreColor, "RGB", new Variant(16711680)); - Dispatch.call(fill, "Solid"); - //设置水印旋转 - Dispatch.put(shapeRange, "Rotation", new Variant(315)); - Dispatch.put(shapeRange, "LockAspectRatio", new Boolean(true)); - Dispatch.put(shapeRange, "Height", new Variant(117.0709)); - Dispatch.put(shapeRange, "Width", new Variant(468.2835)); - Dispatch.put(shapeRange, "Left", new Variant(-999995)); - Dispatch.put(shapeRange, "Top", new Variant(-999995)); - Dispatch wrapFormat = Dispatch.get(shapeRange, "WrapFormat").toDispatch(); - //是否允许交叠 - Dispatch.put(wrapFormat, "AllowOverlap", new Variant(true)); - Dispatch.put(wrapFormat, "Side", new Variant(3)); - Dispatch.put(wrapFormat, "Type", new Variant(3)); - Dispatch.put(shapeRange, "RelativeHorizontalPosition", new Variant(0)); - Dispatch.put(shapeRange, "RelativeVerticalPosition", new Variant(0)); - Dispatch.put(view, "SeekView", new Variant(0)); - } - - - - /** - * 关闭Word资源 - * - * - */ - public void closeWordObj() - { - - // 关闭word文件 - wrdCom.invoke("Quit", new Variant[] {}); - // 释放com线程。根据jacob的帮助文档,com的线程回收不由java的垃圾回收器处理 - ComThread.Release(); - } - - /** - * 得到文件名 - * - * @return . - */ - public String getFileName() - { - return fileName; - } - - /** - * 设置文件名 - * - * @param fileName . - */ - public void setFileName(String fileName) - { - this.fileName = fileName; - } - - /** - * 测试功能 - * - */ - public static void main(String[] argv) - { - WordObj d = WordObj.getInstance(); - try - { - if (d.initWordObj()) - { - d.createNewDocument(); - d.getActiveWindow(); - d.setWaterMark("HEllo"); - // d.closeWordObj(); - } - else - System.out.println("初始化Word读写对象失败!"); - } - catch (Exception e) - { - d.closeWordObj(); - } - } - -} diff --git a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordUtils.java b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordUtils.java index c0f0a3c..deddf02 100644 --- a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordUtils.java +++ b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordUtils.java @@ -208,85 +208,15 @@ public class WordUtils { } catch (Exception e) { e.printStackTrace(); } finally { - /* Dispatch.call(doc, "Close", new Variant(-1),new Variant(1),new Variant(true)); - if (wordApp != null) { - wordApp.invoke("Quit", new Variant[]{}); - } - ComThread.Release();*/ - // 关闭文档 - // Dispatch.call(doc, "Close", false); - // 关闭office - // wordApp.invoke("Quit", 0); System.out.println("关闭文档"); -// if (app != null) -// app.invoke("Quit", new Variant[]{}); - // 如果没有这句话,winword.exe进程将不会关闭 - // ComThread.Release(); } } -/* - public static void setWaterMark(ActiveXComponent activeWindow,String waterMarkStr) - { - - - // 取得活动窗格对象 - Dispatch activePan = Dispatch.get(activeWindow, "ActivePane").toDispatch(); - // 取得视窗对象 - Dispatch view = Dispatch.get(activePan, "View").toDispatch(); - Dispatch docSelection=Dispatch.get(activeWindow, "Selection").toDispatch(); - //输入页眉内容 - Dispatch.put(view, "SeekView", new Variant(9)); - Dispatch headfooter = Dispatch.get(docSelection, "HeaderFooter") - .toDispatch(); - //取得图形对象 - Dispatch shapes = Dispatch.get(headfooter, "Shapes").toDispatch(); - //给文档全部加上水印 - Dispatch selection = Dispatch.call(shapes, "AddTextEffect", - new Variant(9), waterMarkStr, "宋体", new Variant(1), - new Variant(false), new Variant(false), new Variant(0), - new Variant(0)).toDispatch(); - Dispatch.call(selection, "Select"); - //设置水印参数 - Dispatch shapeRange = Dispatch.get(docSelection, "ShapeRange") - .toDispatch(); - Dispatch.put(shapeRange, "Name", "PowerPlusWaterMarkObject1"); - Dispatch textEffect = Dispatch.get(shapeRange, "TextEffect").toDispatch(); - Dispatch.put(textEffect, "NormalizedHeight", new Boolean(false)); - Dispatch line = Dispatch.get(shapeRange, "Line").toDispatch(); - Dispatch.put(line, "Visible", new Boolean(false)); - Dispatch fill = Dispatch.get(shapeRange, "Fill").toDispatch(); - Dispatch.put(fill, "Visible", new Boolean(true)); - //设置水印透明度 - Dispatch.put(fill, "Transparency", new Variant(0.5)); - Dispatch foreColor = Dispatch.get(fill, "ForeColor").toDispatch(); - //设置水印颜色 - Dispatch.put(foreColor, "RGB", new Variant(16711680)); - Dispatch.call(fill, "Solid"); - //设置水印旋转 - Dispatch.put(shapeRange, "Rotation", new Variant(315)); - Dispatch.put(shapeRange, "LockAspectRatio", new Boolean(true)); - Dispatch.put(shapeRange, "Height", new Variant(117.0709)); - Dispatch.put(shapeRange, "Width", new Variant(468.2835)); - Dispatch.put(shapeRange, "Left", new Variant(-999995)); - Dispatch.put(shapeRange, "Top", new Variant(-999995)); - Dispatch wrapFormat = Dispatch.get(shapeRange, "WrapFormat").toDispatch(); - //是否允许交叠 - Dispatch.put(wrapFormat, "AllowOverlap", new Variant(true)); - Dispatch.put(wrapFormat, "Side", new Variant(3)); - Dispatch.put(wrapFormat, "Type", new Variant(3)); - Dispatch.put(shapeRange, "RelativeHorizontalPosition", new Variant(0)); - Dispatch.put(shapeRange, "RelativeVerticalPosition", new Variant(0)); - Dispatch.put(view, "SeekView", new Variant(0)); - }*/ public static void main(String[] args) { Map dataMap = new HashMap(); String curDate = DateUtils.dateConvertStr(new Date(), "yyyy年MM月dd日"); dataMap.put("partyA", "甲方卖出方"); dataMap.put("partyB", "乙方买受方"); - // 图片 -// dataMap.put("imgStr1", getImageStr("D:\\fileTest\\name.png")); -// dataMap.put("imgStr2", getImageStr("D:\\fileTest\\zhang.png")); // 列表 Car car1 = new Car("奔驰", "1001", "v10"); Car car2 = new Car("宝马", "1002", "v10"); From bb155ed8b768a4faec63919447458b1435d7dccd Mon Sep 17 00:00:00 2001 From: God <10745413@qq.com> Date: Fri, 18 Nov 2022 13:38:46 +0800 Subject: [PATCH 14/24] =?UTF-8?q?=E9=97=AE=E9=A2=98=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/yxt/common/base/utils/WordUtils.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordUtils.java b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordUtils.java index deddf02..e9cf724 100644 --- a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordUtils.java +++ b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordUtils.java @@ -185,7 +185,7 @@ public class WordUtils { Dispatch fill = Dispatch.get(shapeRange, "Fill").toDispatch(); Dispatch.put(fill, "Visible", new Boolean(true)); // 设置水印透明度 - Dispatch.put(fill, "Transparency", new Variant(0.5)); + Dispatch.put(fill, "Transparency", new Variant(0.1)); Dispatch foreColor = Dispatch.get(fill, "ForeColor").toDispatch(); //设置水印颜色 Dispatch.put(foreColor, "RGB", new Variant(16711620)); @@ -194,8 +194,8 @@ public class WordUtils { Dispatch.put(shapeRange, "Rotation", new Variant(315)); Dispatch.put(shapeRange, "LockAspectRatio", new Boolean(true)); //设置水印宽高 - Dispatch.put(shapeRange, "Height", new Variant(11)); - Dispatch.put(shapeRange, "Width", new Variant(90)); + Dispatch.put(shapeRange, "Height", new Variant(2.2)); + Dispatch.put(shapeRange, "Width", new Variant(18)); //设置水印位置,相对左上角 Dispatch.put(shapeRange, "Left", new Variant(j * 120 - 60)); Dispatch.put(shapeRange, "Top", new Variant(i * 270)); From a4af8b8d53d6a82e453e4d3d9a3a1ba9e82a570a Mon Sep 17 00:00:00 2001 From: dimengzhe <251008545@qq.com> Date: Fri, 16 Dec 2022 12:28:12 +0800 Subject: [PATCH 15/24] =?UTF-8?q?=E9=94=80=E5=94=AE=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E8=AE=A9=E4=BB=B7=E6=9D=83=E9=99=90=E6=B7=BB=E5=8A=A0=E6=95=B0?= =?UTF-8?q?=E9=87=8F=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yxt-common/yxt-common-base/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/yxt-common/yxt-common-base/pom.xml b/yxt-common/yxt-common-base/pom.xml index 32ddefe..3cb7514 100644 --- a/yxt-common/yxt-common-base/pom.xml +++ b/yxt-common/yxt-common-base/pom.xml @@ -202,6 +202,7 @@ org.apache.pdfbox pdfbox + 2.0.25 From 7ce90b03e2ad4e8006217177ad8abd8db557ff10 Mon Sep 17 00:00:00 2001 From: dimengzhe <251008545@qq.com> Date: Wed, 22 Feb 2023 16:46:18 +0800 Subject: [PATCH 16/24] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yxt/common/base/utils/JPushServer.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/JPushServer.java b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/JPushServer.java index cdac8a4..6a5711e 100644 --- a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/JPushServer.java +++ b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/JPushServer.java @@ -141,6 +141,40 @@ public class JPushServer { } } + /** + * 待阅消息推送(使用别名) + * @param title 标题 + * @param content 内容 + * @param msg_type 消息类别 + */ + public static void sendPushAliass(String title, String content, String state, String name, String... alias) { + Map extras = new HashMap<>(); + extras.put("class_name", "com.anrui.android.activity.ReadActivity"); + extras.put("state", "0"); + extras.put("name", name); + ClientConfig clientConfig = ClientConfig.getInstance(); + final JPushClient jpushClient = new JPushClient(MASTER_SECRET, APP_KEY, null, clientConfig); + + final PushPayload payload = buildPushObject_android_and_iosAlias(title, content, URIACTIVITY, extras, alias); + try { + PushResult result = jpushClient.sendPush(payload); + System.out.println("Got result - " + result); + // 如果使用 NettyHttpClient,需要手动调用 close 方法退出进程 + // jpushClient.close(); + } catch (APIConnectionException e) { + System.out.println("Connection error. Should retry later. "+e); + System.out.println("Sendno: " + payload.getSendno()); + + } catch (APIRequestException e) { + System.out.println("Error response from JPush server. Should review and fix it. "+ e); + System.out.println("HTTP Status: " + e.getStatus()); + System.out.println("Error Code: " + e.getErrorCode()); + System.out.println("Error Message: " + e.getErrorMessage()); + System.out.println("Msg ID: " + e.getMsgId()); + System.out.println("Sendno: " + payload.getSendno()); + } + } + /** * (广播) * @param title 标题 From ac6c81d5e82a57d23619db267b3d6784fd0ee783 Mon Sep 17 00:00:00 2001 From: dimengzhe <251008545@qq.com> Date: Thu, 27 Apr 2023 17:40:42 +0800 Subject: [PATCH 17/24] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yxt/common/base/config/component/DocPdfComponent.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/config/component/DocPdfComponent.java b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/config/component/DocPdfComponent.java index 611e77c..5561fc1 100644 --- a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/config/component/DocPdfComponent.java +++ b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/config/component/DocPdfComponent.java @@ -35,11 +35,11 @@ public class DocPdfComponent { @Value("${templateUrl.prefixUrl:http://127.0.0.1:8080/template/}") private String prefixTemplateUrl; - @Value("${templateUrl.uploadPdfUrl:http://127.0.0.1:8080/template/pdf/}") +/* @Value("${templateUrl.uploadPdfUrl:http://127.0.0.1:8080/template/pdf/}") private String uploadPdfUrl; @Value("${templateUrl.prefixPdfUrl:http://127.0.0.1:8080/template/pdf/}") - private String prefixPdfUrl; + private String prefixPdfUrl;*/ /** * 根据ftl模板生成word @@ -177,11 +177,11 @@ public class DocPdfComponent { return prefixTemplateUrl; } - public String getUploadPdfUrl() { + /* public String getUploadPdfUrl() { return uploadPdfUrl; } public String getPrefixPdfUrl() { return prefixPdfUrl; - } + }*/ } From 45538c655ba65ab1b8401c45aa91f6117ee9c0a2 Mon Sep 17 00:00:00 2001 From: fanzongzhe <285169773@qq.com> Date: Wed, 24 May 2023 08:48:51 +0800 Subject: [PATCH 18/24] =?UTF-8?q?=E9=9A=8F=E8=BD=A6=E8=B5=84=E6=96=99?= =?UTF-8?q?=E4=BA=A4=E6=8E=A5=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/yxt/common/core/domain/BaseEntity.java | 1 - 1 file changed, 1 deletion(-) diff --git a/yxt-common/yxt-common-core/src/main/java/com/yxt/common/core/domain/BaseEntity.java b/yxt-common/yxt-common-core/src/main/java/com/yxt/common/core/domain/BaseEntity.java index c9380fe..5cf3770 100644 --- a/yxt-common/yxt-common-core/src/main/java/com/yxt/common/core/domain/BaseEntity.java +++ b/yxt-common/yxt-common-core/src/main/java/com/yxt/common/core/domain/BaseEntity.java @@ -130,7 +130,6 @@ public class BaseEntity extends EntityWithId { @ApiModelProperty("字符型编号") private String sid = UUID.randomUUID().toString(); - // @Version @ApiModelProperty("记录版本,锁") private Integer lockVersion = 0; From 2d2b09c4eade8931cabf061ca0b39788fa4bbcbb Mon Sep 17 00:00:00 2001 From: dimengzhe Date: Wed, 31 May 2023 16:28:39 +0800 Subject: [PATCH 19/24] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yxt/common/base/config/component/FileUploadComponent.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/config/component/FileUploadComponent.java b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/config/component/FileUploadComponent.java index 271348e..120f377 100644 --- a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/config/component/FileUploadComponent.java +++ b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/config/component/FileUploadComponent.java @@ -87,7 +87,8 @@ public class FileUploadComponent { //2021.10.16 截取文件后缀名以外的名字 String prefixName = fileName.substring(0, fileName.indexOf(".")); // 新文件名:文件原名称 + ‘-’ + 生成的时间戳 2021.10.16 - String filePath = prefixName + "_" + dateFileName() + suffixName; +// String filePath = prefixName + "_" + dateFileName() + suffixName; + String filePath = dateFileName() + suffixName; if (hasDateDir) { String dateStr = DateUtil.format(new Date(), "yyyyMMdd"); // 增加日期目录 From 12ef049b7f423c4e0fcb49d7d93314613795e625 Mon Sep 17 00:00:00 2001 From: fanzongzhe <285169773@qq.com> Date: Fri, 21 Jul 2023 16:04:38 +0800 Subject: [PATCH 20/24] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=BC=80=E7=A5=A8?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E5=A2=9E=E5=8A=A0=E8=BD=A6=E8=BE=86=E6=9F=A5?= =?UTF-8?q?=E7=9C=8B=E6=94=B6=E6=AC=BE=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/yxt/common/base/utils/WordConvertUtils.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordConvertUtils.java b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordConvertUtils.java index 4528fe1..bc30708 100644 --- a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordConvertUtils.java +++ b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordConvertUtils.java @@ -87,7 +87,6 @@ public class WordConvertUtils { OutputStream os = null; try { os = new FileOutputStream(file); - int bytesRead = 0; byte[] buffer = new byte[8192]; while ((bytesRead = ins.read(buffer, 0, 8192)) != -1) { @@ -147,7 +146,6 @@ public class WordConvertUtils { ComThread.Release(); new File(wordFile).delete(); } - } /** From fe2014fe6692f08e21180a3cfecbb4094e018429 Mon Sep 17 00:00:00 2001 From: dimengzhe Date: Wed, 9 Aug 2023 10:52:49 +0800 Subject: [PATCH 21/24] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/yxt/common/base/utils/JPushServer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/JPushServer.java b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/JPushServer.java index 6a5711e..d887bab 100644 --- a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/JPushServer.java +++ b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/JPushServer.java @@ -155,7 +155,7 @@ public class JPushServer { ClientConfig clientConfig = ClientConfig.getInstance(); final JPushClient jpushClient = new JPushClient(MASTER_SECRET, APP_KEY, null, clientConfig); - final PushPayload payload = buildPushObject_android_and_iosAlias(title, content, URIACTIVITY, extras, alias); + final PushPayload payload = buildPushObject_android_and_iosAlias(title, content, "com.anrui.android.activity.ReadActivity", extras, alias); try { PushResult result = jpushClient.sendPush(payload); System.out.println("Got result - " + result); From c26c9586dc2582bd5fe20766495f92410295d89a Mon Sep 17 00:00:00 2001 From: God <10745413@qq.com> Date: Tue, 23 Jan 2024 14:24:25 +0800 Subject: [PATCH 22/24] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yxt/common/base/config/component/DocPdfComponent.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/config/component/DocPdfComponent.java b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/config/component/DocPdfComponent.java index 5561fc1..947e876 100644 --- a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/config/component/DocPdfComponent.java +++ b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/config/component/DocPdfComponent.java @@ -32,7 +32,7 @@ public class DocPdfComponent { @Value("${templateUrl.uploadUrl:static/template/}") private String uploadTemplateUrl; - @Value("${templateUrl.prefixUrl:http://127.0.0.1:8080/template/}") + @Value("${templateUrl.prefixUrl:http://192.168.0.116:8080/template/}") private String prefixTemplateUrl; /* @Value("${templateUrl.uploadPdfUrl:http://127.0.0.1:8080/template/pdf/}") From eb3a9eb077e015c365b10ca2c6c5717dbdaa256a Mon Sep 17 00:00:00 2001 From: God <10745413@qq.com> Date: Tue, 23 Jan 2024 14:26:40 +0800 Subject: [PATCH 23/24] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yxt/common/base/config/component/DocPdfComponent.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/config/component/DocPdfComponent.java b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/config/component/DocPdfComponent.java index 947e876..5561fc1 100644 --- a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/config/component/DocPdfComponent.java +++ b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/config/component/DocPdfComponent.java @@ -32,7 +32,7 @@ public class DocPdfComponent { @Value("${templateUrl.uploadUrl:static/template/}") private String uploadTemplateUrl; - @Value("${templateUrl.prefixUrl:http://192.168.0.116:8080/template/}") + @Value("${templateUrl.prefixUrl:http://127.0.0.1:8080/template/}") private String prefixTemplateUrl; /* @Value("${templateUrl.uploadPdfUrl:http://127.0.0.1:8080/template/pdf/}") From b86311c2dc7994e730237366959641b14a385822 Mon Sep 17 00:00:00 2001 From: God <10745413@qq.com> Date: Mon, 5 Feb 2024 09:00:03 +0800 Subject: [PATCH 24/24] =?UTF-8?q?=E5=AE=B6=E8=AE=BF=E5=87=86=E5=A4=87?= =?UTF-8?q?=E7=94=9F=E6=88=90=E6=B6=88=E8=B4=B7=E5=90=88=E5=90=8C=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E8=B0=83=E6=95=B4=20=E5=8D=95=E8=BD=A6=E8=BF=94?= =?UTF-8?q?=E5=88=A9=E3=80=81=E9=A2=84=E6=8F=90=E3=80=81=E6=A0=B8=E5=AF=B9?= =?UTF-8?q?=E7=BB=84=E7=BB=87=E5=85=A8=E8=B7=AF=E5=BE=84=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=EF=BC=8C=E4=BC=98=E5=8C=96=E5=88=97=E8=A1=A8=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E4=B8=BA=E6=95=B0=E6=8D=AE=E6=9D=83=E6=9F=A5=E8=AF=A2=20?= =?UTF-8?q?=E4=B8=93=E9=A1=B9=E8=BF=94=E5=88=A9=E3=80=81=E9=A2=84=E6=8F=90?= =?UTF-8?q?=E3=80=81=E6=A0=B8=E5=AF=B9=E7=BB=84=E7=BB=87=E5=85=A8=E8=B7=AF?= =?UTF-8?q?=E5=BE=84=E5=AD=97=E6=AE=B5=EF=BC=8C=E4=BC=98=E5=8C=96=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E6=9F=A5=E8=AF=A2=E4=B8=BA=E6=95=B0=E6=8D=AE=E6=9D=83?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yxt/common/base/utils/TransformMoney.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/TransformMoney.java b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/TransformMoney.java index b736ddf..d94d1dd 100644 --- a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/TransformMoney.java +++ b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/TransformMoney.java @@ -150,16 +150,19 @@ public class TransformMoney { //处理小数部分 if (parts.length == 2) { String decimalPart = parts[1]; //小数部分 - for (int i = 0; i < decimalPart.length(); i++) { - int num = Integer.valueOf(decimalPart.charAt(i) + ""); //提取数字,左起 - result += big.charAt(num) + "" + units[1].charAt(i); //数字变大写加上单位 + if ("0".equals(decimalPart)){//小数为零,则加上“整” + result += "整"; + }else { + for (int i = 0; i < decimalPart.length(); i++) { + int num = Integer.valueOf(decimalPart.charAt(i) + ""); //提取数字,左起 + result += big.charAt(num) + "" + units[1].charAt(i); //数字变大写加上单位 + } + result = result.replace("零角", "零"); //去掉"零角"的"角" + result = result.replace("零分", ""); //去掉"零分" } - result = result.replace("零角", "零"); //去掉"零角"的"角" - result = result.replace("零分", ""); //去掉"零分" } else { result += "整"; //没有小数部分,则加上“整” } - return result; }