Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
<groupId>com.yxt</groupId>
|
||||
<artifactId>yxt-common-base</artifactId>
|
||||
<version>0.0.1</version>
|
||||
<description>yxt-common-base</description>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
@@ -175,8 +176,36 @@
|
||||
<artifactId>jacob</artifactId>
|
||||
<version>1.18</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>javax.xml.bind</groupId>
|
||||
<artifactId>jaxb-api</artifactId>
|
||||
<version>2.3.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.xml.bind</groupId>
|
||||
<artifactId>jaxb-impl</artifactId>
|
||||
<version>2.3.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jaxb</groupId>
|
||||
<artifactId>jaxb-runtime</artifactId>
|
||||
<version>2.3.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.activation</groupId>
|
||||
<artifactId>activation</artifactId>
|
||||
<version>1.1.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
<distributionManagement>
|
||||
<repository>
|
||||
<id>nexus-releases</id>
|
||||
<url>http://nexus3.yyundong.com/repository/yxt-mvn-releases/</url>
|
||||
</repository>
|
||||
<snapshotRepository>
|
||||
<id>nexus-snapshots</id>
|
||||
<url>http://nexus3.yyundong.com/repository/yxt-mvn-snapshot/</url>
|
||||
</snapshotRepository>
|
||||
</distributionManagement>
|
||||
</project>
|
||||
@@ -1,9 +1,8 @@
|
||||
package com.yxt.common.base.config.captcha;
|
||||
|
||||
|
||||
import cn.hutool.core.codec.Base64;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
import sun.misc.BASE64Decoder;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
@@ -89,12 +88,12 @@ public class ImageUtils {
|
||||
return false;
|
||||
}
|
||||
|
||||
BASE64Decoder decoder = new BASE64Decoder();
|
||||
// BASE64Decoder decoder = new BASE64Decoder();
|
||||
OutputStream out = null;
|
||||
try {
|
||||
out = new FileOutputStream(imgFilePath);
|
||||
// Base64解码
|
||||
byte[] b = decoder.decodeBuffer(imgData);
|
||||
byte[] b = Base64.decode(imgData);
|
||||
for (int i = 0; i < b.length; ++i) {
|
||||
// 调整异常数据
|
||||
if (b[i] < 0) {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package com.yxt.common.base.config.captcha.factory.impl;
|
||||
|
||||
import cn.hutool.core.codec.Base64;
|
||||
import com.yxt.common.base.config.captcha.CaptchaBaseParam;
|
||||
import com.yxt.common.base.config.captcha.CaptchaException;
|
||||
import com.yxt.common.core.vo.CaptchaBaseVO;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import sun.misc.BASE64Encoder;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.*;
|
||||
@@ -75,8 +75,7 @@ public abstract class AbstractCaptcha {
|
||||
throw new CaptchaException("ImageIO.write is error", e);
|
||||
}
|
||||
byte[] bytes = baos.toByteArray();
|
||||
BASE64Encoder encoder = new sun.misc.BASE64Encoder();
|
||||
return encoder.encodeBuffer(bytes).trim();
|
||||
return Base64.encode(bytes).trim();
|
||||
}
|
||||
|
||||
public String getJigsawUrlOrPath() {
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package com.yxt.common.base.config.captcha.factory.impl;
|
||||
|
||||
import cn.hutool.core.codec.Base64;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.yxt.common.base.config.captcha.CaptchaBaseParam;
|
||||
import com.yxt.common.base.config.captcha.CaptchaException;
|
||||
import com.yxt.common.core.vo.BlockPuzzleCaptchaVO;
|
||||
import com.yxt.common.core.vo.CaptchaBaseVO;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import sun.misc.BASE64Encoder;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.*;
|
||||
@@ -87,10 +87,9 @@ public class BlockPuzzleCaptcha extends AbstractCaptcha {
|
||||
// 源图生成遮罩
|
||||
byte[] oriCopyImages = DealOriPictureByTemplate(originalImage, jigsawImage, x, 0);
|
||||
|
||||
BASE64Encoder encoder = new sun.misc.BASE64Encoder();
|
||||
dataVO.setOriginalImageBase64(encoder.encode(oriCopyImages));
|
||||
dataVO.setOriginalImageBase64(Base64.encode(oriCopyImages));
|
||||
dataVO.setPoint(point);
|
||||
dataVO.setJigsawImageBase64(encoder.encode(jigsawImages));
|
||||
dataVO.setJigsawImageBase64(Base64.encode(jigsawImages));
|
||||
return dataVO;
|
||||
} catch (Exception e){
|
||||
throw new CaptchaException(e);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.yxt.common.base.config.component;
|
||||
|
||||
import cn.hutool.core.codec.Base64;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.jacob.activeX.ActiveXComponent;
|
||||
import com.jacob.com.Dispatch;
|
||||
import com.yxt.common.base.utils.DateUtils;
|
||||
@@ -10,7 +12,6 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
import sun.misc.BASE64Encoder;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Date;
|
||||
@@ -43,7 +44,8 @@ public class DocPdfComponent {
|
||||
* @return 返回word文件路径和链接路径
|
||||
*/
|
||||
public Map<String, String> creatWord(Map<String, Object> map, String typeName, String fileName) {
|
||||
String dateStr = DateUtils.dateConvertStr(new Date(), "yyyyMMdd");
|
||||
// String dateStr = DateUtils.dateConvertStr(new Date(), "yyyyMMdd");
|
||||
String dateStr = DateUtil.format(new Date(), "yyyyMMdd");
|
||||
String targetPath = uploadTemplateUrl + dateStr;
|
||||
try {
|
||||
//Configuration 用于读取ftl文件
|
||||
@@ -77,6 +79,7 @@ public class DocPdfComponent {
|
||||
|
||||
/**
|
||||
* 图片文件转换
|
||||
*
|
||||
* @param imgPath
|
||||
* @return
|
||||
*/
|
||||
@@ -92,12 +95,12 @@ public class DocPdfComponent {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
BASE64Encoder encoder = new BASE64Encoder();
|
||||
return encoder.encode(data);
|
||||
return Base64.encode(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* word转换为pdf
|
||||
*
|
||||
* @param wordFile word的路径
|
||||
* @param pdfName pdf名称
|
||||
* @return 返回pdf文件路径和链接路径
|
||||
@@ -128,8 +131,10 @@ public class DocPdfComponent {
|
||||
Dispatch.call(document, "SaveAs", pdfFile, 17);
|
||||
// 关闭文档
|
||||
Dispatch.call(document, "Close", false);
|
||||
String prefixUrl = prefixTemplateUrl + pdfFile.replace(uploadTemplateUrl, "");
|
||||
// String prefixUrl = prefixTemplateUrl + pdfFile.replace(uploadTemplateUrl, "");
|
||||
resultMap.put("uploadTemplateUrl", pdfFile); // 文件路径
|
||||
pdfFile = targetPath + "/" + pdfName;
|
||||
String prefixUrl = prefixTemplateUrl + pdfFile.replace(uploadTemplateUrl, "");
|
||||
resultMap.put("prefixTemplateUrl", prefixUrl); // 链接路径
|
||||
} catch (Exception e) {
|
||||
log.error("转换失败" + e.getMessage());
|
||||
@@ -142,6 +147,7 @@ public class DocPdfComponent {
|
||||
|
||||
/**
|
||||
* 根据ftl模板生成word并转为pdf
|
||||
*
|
||||
* @param map
|
||||
* @param typeName
|
||||
* @param docName
|
||||
|
||||
@@ -76,6 +76,7 @@ public class FileBatchUploadComponent {
|
||||
String fileName = file.getOriginalFilename();
|
||||
// 后缀名
|
||||
String suffixName = fileName.substring(fileName.lastIndexOf("."));
|
||||
suffixName = suffixName.toLowerCase();
|
||||
if (suffixName.equals(".pdf")) { // pdf文件
|
||||
ResultBean<FileUploadResult> resultBean = fileUploadComponent.uploadFile(file);
|
||||
FileUploadResult uploadResult = resultBean.getData();
|
||||
|
||||
@@ -205,7 +205,7 @@ public class FileUploadComponent {
|
||||
return uploadFile(file, false, relativePath);
|
||||
}
|
||||
|
||||
private String dateFileName() {
|
||||
public String dateFileName() {
|
||||
return DateUtil.format(new Date(), "yyyyMMddHHmmssSSS") + RandomUtil.randomNumbers(3);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,209 @@
|
||||
package com.yxt.common.base.utils;
|
||||
|
||||
import cn.hutool.extra.pinyin.PinyinUtil;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author dimengzhe
|
||||
* @Date 2022/9/28 15:54
|
||||
* @Description
|
||||
*/
|
||||
public class HanZiConverterPinYin {
|
||||
|
||||
public HanZiConverterPinYin() {
|
||||
// 初始化汉字拼音字母对照表
|
||||
initChinesePinyinComparisonMapList();
|
||||
}
|
||||
|
||||
/**
|
||||
* 汉字拼音字母对照表
|
||||
*/
|
||||
private List<ChinesePinyinComparisonMap> chinesePinyinComparisonMapList;
|
||||
|
||||
/**
|
||||
* 初始化汉字拼音字母对照表
|
||||
*/
|
||||
private void initChinesePinyinComparisonMapList() {
|
||||
chinesePinyinComparisonMapList = new ArrayList<ChinesePinyinComparisonMap>();
|
||||
|
||||
chinesePinyinComparisonMapList.add(new ChinesePinyinComparisonMap(-20319, -20284, 'A'));
|
||||
chinesePinyinComparisonMapList.add(new ChinesePinyinComparisonMap(-20283, -19776, 'B'));
|
||||
chinesePinyinComparisonMapList.add(new ChinesePinyinComparisonMap(-19775, -19219, 'C'));
|
||||
chinesePinyinComparisonMapList.add(new ChinesePinyinComparisonMap(-19218, -18711, 'D'));
|
||||
chinesePinyinComparisonMapList.add(new ChinesePinyinComparisonMap(-18710, -18527, 'E'));
|
||||
chinesePinyinComparisonMapList.add(new ChinesePinyinComparisonMap(-18526, -18240, 'F'));
|
||||
chinesePinyinComparisonMapList.add(new ChinesePinyinComparisonMap(-18239, -17923, 'G'));
|
||||
chinesePinyinComparisonMapList.add(new ChinesePinyinComparisonMap(-17922, -17418, 'H'));
|
||||
chinesePinyinComparisonMapList.add(new ChinesePinyinComparisonMap(-17417, -16475, 'J'));
|
||||
chinesePinyinComparisonMapList.add(new ChinesePinyinComparisonMap(-16474, -16213, 'K'));
|
||||
chinesePinyinComparisonMapList.add(new ChinesePinyinComparisonMap(-16212, -15641, 'L'));
|
||||
chinesePinyinComparisonMapList.add(new ChinesePinyinComparisonMap(-15640, -15166, 'M'));
|
||||
chinesePinyinComparisonMapList.add(new ChinesePinyinComparisonMap(-15165, -14923, 'N'));
|
||||
chinesePinyinComparisonMapList.add(new ChinesePinyinComparisonMap(-14922, -14915, 'O'));
|
||||
chinesePinyinComparisonMapList.add(new ChinesePinyinComparisonMap(-14914, -14631, 'P'));
|
||||
chinesePinyinComparisonMapList.add(new ChinesePinyinComparisonMap(-14630, -14150, 'Q'));
|
||||
chinesePinyinComparisonMapList.add(new ChinesePinyinComparisonMap(-14149, -14091, 'R'));
|
||||
chinesePinyinComparisonMapList.add(new ChinesePinyinComparisonMap(-14090, -13319, 'S'));
|
||||
chinesePinyinComparisonMapList.add(new ChinesePinyinComparisonMap(-13318, -12839, 'T'));
|
||||
chinesePinyinComparisonMapList.add(new ChinesePinyinComparisonMap(-12838, -12557, 'W'));
|
||||
chinesePinyinComparisonMapList.add(new ChinesePinyinComparisonMap(-12556, -11848, 'X'));
|
||||
chinesePinyinComparisonMapList.add(new ChinesePinyinComparisonMap(-11847, -11056, 'Y'));
|
||||
chinesePinyinComparisonMapList.add(new ChinesePinyinComparisonMap(-11055, -10247, 'Z'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 遍历获取首字母
|
||||
*/
|
||||
public char getPY(char c) throws Exception {
|
||||
byte[] bytes = String.valueOf(c).getBytes("GBK");
|
||||
|
||||
//双字节汉字处理
|
||||
if (bytes.length == 2) {
|
||||
|
||||
int hightByte = 256 + bytes[0];
|
||||
int lowByte = 256 + bytes[1];
|
||||
int asc = (256 * hightByte + lowByte) - 256 * 256;
|
||||
|
||||
// 遍历转换
|
||||
for (ChinesePinyinComparisonMap map : this.chinesePinyinComparisonMapList) {
|
||||
if (asc >= map.getSAscll() && asc <= map.getEAscll()) {
|
||||
return map.getCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 单字节或其他直接输入,不执行编码
|
||||
return c;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取汉字拼音
|
||||
*/
|
||||
public String getHanZiPY(String str) {
|
||||
try {
|
||||
StringBuilder pyStrBd = new StringBuilder();
|
||||
|
||||
for (char c : str.toCharArray()) {
|
||||
pyStrBd.append(getPY(c));
|
||||
}
|
||||
|
||||
return pyStrBd.toString();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 汉字拼音字母对照类
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
private class ChinesePinyinComparisonMap {
|
||||
// 区间开头
|
||||
private int sAscll;
|
||||
|
||||
// 区间结尾
|
||||
private int eAscll;
|
||||
|
||||
// 对应字母
|
||||
private char code;
|
||||
}
|
||||
|
||||
private static final Map<String, Object> DYZMAP = setDYZMap();
|
||||
|
||||
private static Map<String, Object> setDYZMap() {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("仇", "QIU");
|
||||
map.put("柏", "BO");
|
||||
map.put("牟", "MU");
|
||||
map.put("颉", "XIE");
|
||||
map.put("解", "XIE");
|
||||
map.put("尉", "YU");
|
||||
map.put("奇", "JI");
|
||||
map.put("单", "SHAN");
|
||||
map.put("谌", "SHEN");
|
||||
map.put("乐", "YUE");
|
||||
map.put("召", "SHAO");
|
||||
map.put("朴", "PIAO");
|
||||
map.put("区", "OU");
|
||||
map.put("查", "ZHA");
|
||||
map.put("曾", "ZENG");
|
||||
map.put("缪", "MIAO");
|
||||
map.put("晟", "CHENG");
|
||||
map.put("员", "YUN");
|
||||
map.put("贠", "YUN");
|
||||
map.put("黑", "HE");
|
||||
map.put("重", "CHONG");
|
||||
map.put("秘", "BI");
|
||||
map.put("冼", "XIAN");
|
||||
map.put("折", "SHE");
|
||||
map.put("翟", "ZHAI");
|
||||
map.put("盖", "GE");
|
||||
map.put("万俟", "MOQI");
|
||||
map.put("尉迟", "YUCHI");
|
||||
return map;
|
||||
}
|
||||
|
||||
public static String getPinYinFirst(String str) {
|
||||
HanZiConverterPinYin hanZiConverterPinYin = new HanZiConverterPinYin();
|
||||
char firstChar = str.toCharArray()[0];
|
||||
String firstString = "";
|
||||
if (Character.toString(firstChar).matches("^[\u4e00-\u9fa5]+$")) { // 为中文
|
||||
char[] charPinYinChar = PinYinUtils.getCharPinYinChar(firstChar);
|
||||
String result = "";
|
||||
if (DYZMAP.containsKey(Character.toString(firstChar))) {
|
||||
result = DYZMAP.get(Character.toString(firstChar)).toString().substring(0, 1);
|
||||
} else {
|
||||
result = StringUtils.join(charPinYinChar[0]);
|
||||
}
|
||||
firstString = result.toUpperCase();
|
||||
} else if (Character.toString(firstChar).matches("^[a-zA-Z]")) { // 为英文字母
|
||||
firstString = Character.toString(firstChar).toUpperCase();
|
||||
}
|
||||
|
||||
// String code = hanZiConverterPinYin.getHanZiPY(str);
|
||||
String code = PinyinUtil.getFirstLetter(str, "");
|
||||
StringBuffer buffer = new StringBuffer(code);
|
||||
code = buffer.replace(0, 1, firstString).toString();
|
||||
code = code.toUpperCase();
|
||||
System.out.println(code);
|
||||
return code;
|
||||
}
|
||||
|
||||
//测试
|
||||
public static void main(String[] args) {
|
||||
HanZiConverterPinYin hanZiConverterPinYin = new HanZiConverterPinYin();
|
||||
String str = "王佳琪";
|
||||
char firstChar = str.toCharArray()[0];
|
||||
String firstString = "";
|
||||
if (Character.toString(firstChar).matches("^[\u4e00-\u9fa5]+$")) { // 为中文
|
||||
char[] charPinYinChar = PinYinUtils.getCharPinYinChar(firstChar);
|
||||
String result = "";
|
||||
if (DYZMAP.containsKey(Character.toString(firstChar))) {
|
||||
result = DYZMAP.get(Character.toString(firstChar)).toString().substring(0, 1);
|
||||
} else {
|
||||
result = StringUtils.join(charPinYinChar[0]);
|
||||
}
|
||||
firstString = result.toUpperCase();
|
||||
} else if (Character.toString(firstChar).matches("^[a-zA-Z]")) { // 为英文字母
|
||||
firstString = Character.toString(firstChar).toUpperCase();
|
||||
}
|
||||
|
||||
// String code = hanZiConverterPinYin.getHanZiPY(str);
|
||||
String code = PinyinUtil.getFirstLetter("王佳琪", ""); //c-s
|
||||
StringBuffer buffer = new StringBuffer(code);
|
||||
code = buffer.replace(0, 1, firstString).toString();
|
||||
code = code.toUpperCase();
|
||||
System.out.println(code);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,220 @@
|
||||
package com.yxt.common.base.utils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* @Author dimengzhe
|
||||
* @Date 2022/8/17 11:26
|
||||
* @Description
|
||||
*/
|
||||
public class MoneyToChineseUtils {
|
||||
|
||||
/**
|
||||
* 不考虑分隔符的正确性
|
||||
*/
|
||||
private static final Pattern AMOUNT_PATTERN = Pattern.compile("^(0|[1-9]\\d{0,11})\\.(\\d\\d)$");
|
||||
private static final char[] RMB_NUMS = "零壹贰叁肆伍陆柒捌玖".toCharArray();
|
||||
private static final String[] UNITS = {"元", "角", "分", "整"};
|
||||
private static final String[] U1 = {"", "拾", "佰", "仟"};
|
||||
private static final String[] U2 = {"", "万", "亿"};
|
||||
|
||||
/**
|
||||
* 将金额(整数部分等于或少于12位,小数部分2位)转换为中文大写形式.
|
||||
*
|
||||
* @param money 金额数字
|
||||
* @return 中文大写
|
||||
*/
|
||||
public static String convert(Double money) {
|
||||
money = Math.abs(money);
|
||||
if (Double.valueOf(0).equals(money)) {
|
||||
return "零元整";
|
||||
}
|
||||
String amount = moneyFormat(money);
|
||||
// 去掉分隔符
|
||||
amount = amount.replace(",", "");
|
||||
// 验证金额正确性
|
||||
|
||||
Matcher matcher = AMOUNT_PATTERN.matcher(amount);
|
||||
if (!matcher.find()) {
|
||||
|
||||
}
|
||||
// 整数部分
|
||||
String integer = matcher.group(1);
|
||||
// 小数部分
|
||||
String fraction = matcher.group(2);
|
||||
|
||||
String result = "";
|
||||
if (!integer.equals("0")) {
|
||||
// 整数部分
|
||||
result += integer2rmb(integer) + UNITS[0];
|
||||
}
|
||||
if (fraction.equals("00")) {
|
||||
// 添加[整]
|
||||
result += UNITS[3];
|
||||
} else if (fraction.startsWith("0") && integer.equals("0")) {
|
||||
// 去掉分前面的[零]
|
||||
result += fraction2rmb(fraction).substring(1);
|
||||
} else {
|
||||
// 小数部分
|
||||
result += fraction2rmb(fraction);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将金额小数部分转换为中文大写
|
||||
*/
|
||||
private static String fraction2rmb(String fraction) {
|
||||
// 角
|
||||
char jiao = fraction.charAt(0);
|
||||
// 分
|
||||
char fen = fraction.charAt(1);
|
||||
return (RMB_NUMS[jiao - '0'] + (jiao > '0' ? UNITS[1] : "")) + (fen > '0' ? RMB_NUMS[fen - '0'] + UNITS[2] : "");
|
||||
}
|
||||
|
||||
/**
|
||||
* 将金额整数部分转换为中文大写
|
||||
*
|
||||
* @param integer
|
||||
* @return
|
||||
*/
|
||||
private static String integer2rmb(String integer) {
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
// 从个位数开始转换
|
||||
int i, j;
|
||||
for (i = integer.length() - 1, j = 0; i >= 0; i--, j++) {
|
||||
char n = integer.charAt(i);
|
||||
if (n == '0') {
|
||||
// 当n是0且n的右边一位不是0时,插入[零]
|
||||
if (i < integer.length() - 1 && integer.charAt(i + 1) != '0') {
|
||||
buffer.append(RMB_NUMS[0]);
|
||||
}
|
||||
// 插入[万]或者[亿]
|
||||
if (j % 4 == 0) {
|
||||
if (i > 0 && integer.charAt(i - 1) != '0'
|
||||
|| i > 1 && integer.charAt(i - 2) != '0'
|
||||
|| i > 2 && integer.charAt(i - 3) != '0') {
|
||||
buffer.append(U2[j / 4]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (j % 4 == 0) {
|
||||
// 插入[万]或者[亿]
|
||||
buffer.append(U2[j / 4]);
|
||||
}
|
||||
// 插入[拾]、[佰]或[仟]
|
||||
buffer.append(U1[j % 4]);
|
||||
// 插入数字
|
||||
buffer.append(RMB_NUMS[n - '0']);
|
||||
}
|
||||
}
|
||||
return buffer.reverse().toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 对金额的格式调整到分
|
||||
*
|
||||
* @param preMoney
|
||||
* @return
|
||||
*/
|
||||
public static String moneyFormat(Double preMoney) {
|
||||
//23->23.00
|
||||
String money = preMoney.toString();
|
||||
StringBuffer sb = new StringBuffer();
|
||||
if (money == null) {
|
||||
return "0.00";
|
||||
}
|
||||
int index = money.indexOf(".");
|
||||
if (index == -1) {
|
||||
return money + ".00";
|
||||
} else {
|
||||
//整数部分
|
||||
String s0 = money.substring(0, index);
|
||||
//小数部分
|
||||
String s1 = money.substring(index + 1);
|
||||
if (s1.length() == 1) {
|
||||
//小数点后一位
|
||||
s1 = s1 + "0";
|
||||
} else if (s1.length() > 2) {
|
||||
//如果超过3位小数,截取2位就可以了
|
||||
s1 = s1.substring(0, 2);
|
||||
}
|
||||
sb.append(s0);
|
||||
sb.append(".");
|
||||
sb.append(s1);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 对金额的格式调整到分
|
||||
*
|
||||
* @param preMoney
|
||||
* @return
|
||||
*/
|
||||
public static String moneyFormat(BigDecimal preMoney) {
|
||||
//23->23.00
|
||||
String money = preMoney.toString();
|
||||
StringBuffer sb = new StringBuffer();
|
||||
if (money == null) {
|
||||
return "0.00";
|
||||
}
|
||||
int index = money.indexOf(".");
|
||||
if (index == -1) {
|
||||
return money + ".00";
|
||||
} else {
|
||||
//整数部分
|
||||
String s0 = money.substring(0, index);
|
||||
//小数部分
|
||||
String s1 = money.substring(index + 1);
|
||||
if (s1.length() == 1) {
|
||||
//小数点后一位
|
||||
s1 = s1 + "0";
|
||||
} else if (s1.length() > 2) {
|
||||
//如果超过3位小数,截取2位就可以了
|
||||
s1 = s1.substring(0, 2);
|
||||
}
|
||||
sb.append(s0);
|
||||
sb.append(".");
|
||||
sb.append(s1);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 对金额的格式调整到分
|
||||
*
|
||||
* @param preMoney
|
||||
* @return
|
||||
*/
|
||||
public static String moneyFormat(String preMoney) {
|
||||
//23->23.00
|
||||
String money = preMoney;
|
||||
StringBuffer sb = new StringBuffer();
|
||||
if (money == null) {
|
||||
return "0.00";
|
||||
}
|
||||
int index = money.indexOf(".");
|
||||
if (index == -1) {
|
||||
return money + ".00";
|
||||
} else {
|
||||
//整数部分
|
||||
String s0 = money.substring(0, index);
|
||||
//小数部分
|
||||
String s1 = money.substring(index + 1);
|
||||
if (s1.length() == 1) {
|
||||
//小数点后一位
|
||||
s1 = s1 + "0";
|
||||
} else if (s1.length() > 2) {
|
||||
//如果超过3位小数,截取2位就可以了
|
||||
s1 = s1.substring(0, 2);
|
||||
}
|
||||
sb.append(s0);
|
||||
sb.append(".");
|
||||
sb.append(s1);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
package com.yxt.common.base.utils;
|
||||
|
||||
import com.jacob.activeX.ActiveXComponent;
|
||||
import com.jacob.com.ComThread;
|
||||
import com.jacob.com.Dispatch;
|
||||
import freemarker.template.Configuration;
|
||||
import freemarker.template.Template;
|
||||
import freemarker.template.Version;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author dimengzhe
|
||||
* @Date 2022/10/18 17:11
|
||||
* @Description
|
||||
*/
|
||||
public class WordConvertUtils {
|
||||
|
||||
/**
|
||||
* 根据ftl模板生成word
|
||||
*
|
||||
* @param map 数据
|
||||
* @param typeName 模板名称
|
||||
* @param sourcePath 模板路径
|
||||
* @param targetPath 保存目标路径
|
||||
* @param fileName 文件名
|
||||
*/
|
||||
public static void creatWord(Map<String, Object> map, File file, String targetPath, String fileName, String 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(new File(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);
|
||||
out.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* word转换为pdf
|
||||
*
|
||||
* @param wordFile word的路径
|
||||
* @param pdfPath pdf的路径
|
||||
* @param pdfName pdf名称
|
||||
*/
|
||||
public static void doc2pdf(String wordFile, String pdfPath, String pdfName) {
|
||||
ActiveXComponent app = null;
|
||||
System.out.println("开始转换...");
|
||||
long start = System.currentTimeMillis();
|
||||
Dispatch document = null;
|
||||
try {
|
||||
ComThread.InitSTA();
|
||||
// 打开word
|
||||
app = new ActiveXComponent("Word.Application");
|
||||
// 获得word中所有打开的文档
|
||||
Dispatch documents = app.getProperty("Documents").toDispatch();
|
||||
// 打开文档
|
||||
document = Dispatch.call(documents, "Open", wordFile, false, true).toDispatch();
|
||||
// 如果文件存在的话,不会覆盖,会直接报错,所以我们需要判断文件是否存在
|
||||
File targetFile = new File(pdfPath);
|
||||
if (!targetFile.exists()) {
|
||||
targetFile.mkdirs();
|
||||
}
|
||||
String pdfFile = pdfPath + pdfName;
|
||||
File target = new File(pdfFile);
|
||||
if (target.exists()) {
|
||||
target.delete();
|
||||
}
|
||||
Dispatch.call(document, "SaveAs", pdfFile, 17);
|
||||
long end = System.currentTimeMillis();
|
||||
System.out.println("转换完成..用时:" + (end - start) + "ms.");
|
||||
} catch (Exception e) {
|
||||
System.out.println("转换失败" + e.getMessage());
|
||||
} finally {
|
||||
// 关闭文档
|
||||
Dispatch.call(document, "Close", false);
|
||||
// 关闭office
|
||||
app.invoke("Quit", 0);
|
||||
System.out.println("关闭文档");
|
||||
// 如果没有这句话,winword.exe进程将不会关闭
|
||||
ComThread.Release();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,12 @@
|
||||
package com.yxt.common.base.utils;
|
||||
|
||||
import cn.hutool.core.codec.Base64;
|
||||
import com.jacob.activeX.ActiveXComponent;
|
||||
import com.jacob.com.ComThread;
|
||||
import com.jacob.com.Dispatch;
|
||||
import freemarker.template.Configuration;
|
||||
import freemarker.template.Template;
|
||||
import freemarker.template.Version;
|
||||
import sun.misc.BASE64Encoder;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
@@ -72,8 +73,7 @@ public class WordUtils {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
BASE64Encoder encoder = new BASE64Encoder();
|
||||
return encoder.encode(data);
|
||||
return Base64.encode(data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -86,13 +86,16 @@ public class WordUtils {
|
||||
public static void doc2pdf(String wordFile, String pdfPath, String pdfName) {
|
||||
ActiveXComponent app = null;
|
||||
System.out.println("开始转换...");
|
||||
long start = System.currentTimeMillis();
|
||||
Dispatch document = null;
|
||||
try {
|
||||
ComThread.InitSTA();
|
||||
// 打开word
|
||||
app = new ActiveXComponent("Word.Application");
|
||||
// 获得word中所有打开的文档
|
||||
Dispatch documents = app.getProperty("Documents").toDispatch();
|
||||
// 打开文档
|
||||
Dispatch document = Dispatch.call(documents, "Open", wordFile, false, true).toDispatch();
|
||||
document = Dispatch.call(documents, "Open", wordFile, false, true).toDispatch();
|
||||
// 如果文件存在的话,不会覆盖,会直接报错,所以我们需要判断文件是否存在
|
||||
File targetFile = new File(pdfPath);
|
||||
if (!targetFile.exists()) {
|
||||
@@ -104,14 +107,22 @@ public class WordUtils {
|
||||
target.delete();
|
||||
}
|
||||
Dispatch.call(document, "SaveAs", pdfFile, 17);
|
||||
// 关闭文档
|
||||
Dispatch.call(document, "Close", false);
|
||||
long end = System.currentTimeMillis();
|
||||
System.out.println("转换完成..用时:" + (end - start) + "ms.");
|
||||
} catch (Exception e) {
|
||||
System.out.println("转换失败" + e.getMessage());
|
||||
} finally {
|
||||
// 关闭文档
|
||||
Dispatch.call(document, "Close", false);
|
||||
// 关闭office
|
||||
app.invoke("Quit", 0);
|
||||
System.out.println("关闭文档");
|
||||
// if (app != null)
|
||||
// app.invoke("Quit", new Variant[]{});
|
||||
// 如果没有这句话,winword.exe进程将不会关闭
|
||||
ComThread.Release();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
<groupId>com.yxt</groupId>
|
||||
<artifactId>yxt-common-core</artifactId>
|
||||
<version>0.0.1</version>
|
||||
<description>yxt-common-core===test00bbbbb</description>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
@@ -55,4 +56,15 @@
|
||||
<version>1.2.73</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<distributionManagement>
|
||||
<repository>
|
||||
<id>nexus-releases</id>
|
||||
<url>http://nexus3.yyundong.com/repository/yxt-mvn-releases/</url>
|
||||
</repository>
|
||||
<snapshotRepository>
|
||||
<id>nexus-snapshots</id>
|
||||
<url>http://nexus3.yyundong.com/repository/yxt-mvn-snapshot/</url>
|
||||
</snapshotRepository>
|
||||
</distributionManagement>
|
||||
</project>
|
||||
@@ -9,7 +9,7 @@
|
||||
<version>0.0.1</version>
|
||||
<packaging>pom</packaging>
|
||||
<name>根项目yxt-parent</name>
|
||||
<description>宇信通框架的根项目,用来维护使用到依赖库的版本。各子项目或独立项目都应</description>
|
||||
<description>宇信通框架的根项目,用来维护使用到依赖库的版本。各子项目或独立项目都应统一版本</description>
|
||||
|
||||
|
||||
<properties>
|
||||
@@ -69,7 +69,7 @@
|
||||
<!-- Hutool组件 -->
|
||||
<hutool.version>5.4.0</hutool.version>
|
||||
<hibernate-validator.version>6.0.20.Final</hibernate-validator.version>
|
||||
<lombok.version>1.18.12</lombok.version>
|
||||
<lombok.version>1.18.24</lombok.version>
|
||||
<jedis.version>3.1.0</jedis.version>
|
||||
<java-jwt.version>3.10.1</java-jwt.version>
|
||||
<redis.version>2.2.9.RELEASE</redis.version>
|
||||
@@ -401,49 +401,56 @@
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
</dependencies>
|
||||
|
||||
<repositories>
|
||||
<!-- <repositories>-->
|
||||
<!-- <repository>-->
|
||||
<!-- <id>aliyun-central</id>-->
|
||||
<!-- <url>https://maven.aliyun.com/repository/central</url>-->
|
||||
<!-- </repository>-->
|
||||
<!-- <repository>-->
|
||||
<!-- <id>aliyun-public</id>-->
|
||||
<!-- <url>https://maven.aliyun.com/repository/public</url>-->
|
||||
<!-- </repository>-->
|
||||
<!-- <repository>-->
|
||||
<!-- <id>aliyun-google</id>-->
|
||||
<!-- <url>https://maven.aliyun.com/repository/google</url>-->
|
||||
<!-- </repository>-->
|
||||
<!-- <repository>-->
|
||||
<!-- <id>aliyun-spring</id>-->
|
||||
<!-- <url>https://maven.aliyun.com/repository/spring</url>-->
|
||||
<!-- </repository>-->
|
||||
<!-- </repositories>-->
|
||||
<!-- <pluginRepositories>-->
|
||||
<!-- <pluginRepository>-->
|
||||
<!-- <id>aliyun-central</id>-->
|
||||
<!-- <url>https://maven.aliyun.com/repository/central</url>-->
|
||||
<!-- </pluginRepository>-->
|
||||
<!-- <pluginRepository>-->
|
||||
<!-- <id>aliyun-public</id>-->
|
||||
<!-- <url>https://maven.aliyun.com/repository/public</url>-->
|
||||
<!-- </pluginRepository>-->
|
||||
<!-- <pluginRepository>-->
|
||||
<!-- <id>aliyun-google</id>-->
|
||||
<!-- <url>https://maven.aliyun.com/repository/google</url>-->
|
||||
<!-- </pluginRepository>-->
|
||||
<!-- <pluginRepository>-->
|
||||
<!-- <id>aliyun-spring</id>-->
|
||||
<!-- <url>https://maven.aliyun.com/repository/spring</url>-->
|
||||
<!-- </pluginRepository>-->
|
||||
<!-- </pluginRepositories>-->
|
||||
<distributionManagement>
|
||||
<repository>
|
||||
<id>aliyun-central</id>
|
||||
<url>https://maven.aliyun.com/repository/central</url>
|
||||
<id>nexus-releases</id>
|
||||
<url>http://nexus3.yyundong.com/repository/yxt-mvn-releases/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>aliyun-public</id>
|
||||
<url>https://maven.aliyun.com/repository/public</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>aliyun-google</id>
|
||||
<url>https://maven.aliyun.com/repository/google</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>aliyun-spring</id>
|
||||
<url>https://maven.aliyun.com/repository/spring</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>aliyun-central</id>
|
||||
<url>https://maven.aliyun.com/repository/central</url>
|
||||
</pluginRepository>
|
||||
<pluginRepository>
|
||||
<id>aliyun-public</id>
|
||||
<url>https://maven.aliyun.com/repository/public</url>
|
||||
</pluginRepository>
|
||||
<pluginRepository>
|
||||
<id>aliyun-google</id>
|
||||
<url>https://maven.aliyun.com/repository/google</url>
|
||||
</pluginRepository>
|
||||
<pluginRepository>
|
||||
<id>aliyun-spring</id>
|
||||
<url>https://maven.aliyun.com/repository/spring</url>
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
<snapshotRepository>
|
||||
<id>nexus-snapshots</id>
|
||||
<url>http://nexus3.yyundong.com/repository/yxt-mvn-snapshot/</url>
|
||||
</snapshotRepository>
|
||||
</distributionManagement>
|
||||
</project>
|
||||
Reference in New Issue
Block a user