Commit 62dfaa50 authored by yanzg's avatar yanzg

Merge remote-tracking branch 'origin/master'

parents 754ac705 a9331864
......@@ -16,6 +16,7 @@
<module>yzg-util-mq</module>
<module>yzg-util-image</module>
<module>yzg-util-print</module>
<module>yzg-util-chinese</module>
</modules>
<properties>
......@@ -147,6 +148,12 @@
<artifactId>yzg-util-print</artifactId>
<version>${yzg.version}</version>
</dependency>
<dependency>
<groupId>com.yanzuoguang</groupId>
<artifactId>yzg-util-chinese</artifactId>
<version>${yzg.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
......
......@@ -1061,10 +1061,28 @@ public class StringHelper {
* @return 处理后的值对象
*/
public static String getCodeString(String from, Object target) {
return getCodeStringArray(from, target);
}
/**
* 获取字段替换值
*
* @param from 来源字符串
* @param targets  值对象
* @return 处理后的值对象
*/
public static String getCodeStringArray(String from, Object... targets) {
return getFormat(from, StringHelper.EMPTY, new StringFormatHandle() {
@Override
public void addPos(StringBuilder sb, String gorup, String fieldFull, String field, String command) {
String value = StringHelper.getFirst(ObjectHelper.getString(target, field), EMPTY);
String value = StringHelper.EMPTY;
for (Object target : targets) {
value = StringHelper.getFirst(ObjectHelper.getString(target, field), EMPTY);
if (!StringHelper.isEmpty(value)) {
break;
}
}
sb.append(value);
}
});
......
package helper;
import com.yanzuoguang.util.helper.ByteHelper;
import org.junit.Assert;
import org.junit.Test;
public class TestByteHelper {
......
package helper;
import base.DemoVo;
import com.yanzuoguang.util.helper.FileHelper;
import com.yanzuoguang.util.helper.SfzhUtil;
import com.yanzuoguang.util.helper.StringHelper;
import com.yanzuoguang.util.helper.TypeHelper;
import com.yanzuoguang.util.helper.*;
import com.yanzuoguang.util.vo.ResponseResult;
import helper.vo.ResponseDataMainResult;
import org.junit.Test;
......@@ -42,4 +39,162 @@ public class TestSfzUtil {
}
return f.getAbsolutePath();
}
@Test
public void testYzg() {
validateIdCard18("430524198711048161");
validateIdCard18("43052419871104817X");
validateIdCard18("441424199203131841");
validateIdCard18("44142419920313185X");
}
/**
* 验证18位身份编码是否合法
*
* @param idCard 身份编码
* @return 是否合法
*/
public static boolean validateIdCard18(String idCard) {
System.out.println("来源身份证:" + idCard);
boolean bTrue = false;
if (idCard.length() == 18) {
// 前17位
String code17 = idCard.substring(0, 17);
System.out.println("前17位:" + code17);
// 第18位
String code18 = idCard.substring(17, 18);
System.out.println("第18位" + code18);
if (isNum(code17)) {
char[] cArr = code17.toCharArray();
System.out.println("转换成键盘的位置:" + JsonHelper.serialize(cArr));
if (cArr != null) {
int[] iCard = converCharToInt(cArr);
System.out.println("转换成整形:" + JsonHelper.serialize(iCard));
int iSum17 = getPowerSum(iCard);
// 获取校验位
String val = getCheckCode18(iSum17);
if (val.length() > 0 && val.equalsIgnoreCase(code18)) {
bTrue = true;
}
}
}
}
return bTrue;
}
/**
* 数字验证
*
* @param val
* @return 提取的数字。
*/
public static boolean isNum(String val) {
return val == null || "".equals(val) ? false : val.matches("^[0-9]*$");
}
/**
* 将字符数组转换成数字数组
*
* @param ca 字符数组
* @return 数字数组
*/
public static int[] converCharToInt(char[] ca) {
int len = ca.length;
int[] iArr = new int[len];
try {
for (int i = 0; i < len; i++) {
iArr[i] = Integer.parseInt(String.valueOf(ca[i]));
}
} catch (NumberFormatException e) {
e.printStackTrace();
}
return iArr;
}
/**
* 将身份证的每位和对应位的加权因子相乘之后,再得到和值
*
* @param iArr
* @return 身份证编码。
*/
public static int getPowerSum(int[] iArr) {
int iSum = 0;
System.out.println("将前17位加上:" + JsonHelper.serialize(power));
if (power.length == iArr.length) {
for (int i = 0; i < iArr.length; i++) {
int from = iSum;
iSum = iSum + iArr[i] * power[i];
System.out.println(String.format("%d位: %d = %d + %d * %d ", i, iSum, from, iArr[i], power[i]));
}
}
return iSum;
}
/**
* 将power和值与11取模获得余数进行校验码判断
*
* @param iSum
* @return 校验位
*/
public static String getCheckCode18(int iSum) {
String sCode = "";
switch (iSum % 11) {
case 10:
sCode = "2";
break;
case 9:
sCode = "3";
break;
case 8:
sCode = "4";
break;
case 7:
sCode = "5";
break;
case 6:
sCode = "6";
break;
case 5:
sCode = "7";
break;
case 4:
sCode = "8";
break;
case 3:
sCode = "9";
break;
case 2:
sCode = "X";
break;
case 1:
sCode = "0";
break;
case 0:
sCode = "1";
break;
default:
sCode = "";
break;
}
System.out.println(String.format("%d %% 11 = %d -> %s", iSum, iSum % 11, sCode));
return sCode;
}
/**
* 每位加权因子
*/
public static final int power[] = {
7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2
};
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>yzg-util</artifactId>
<groupId>com.yanzuoguang</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>yzg-util-chinese</artifactId>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<baidu.aip>4.12.0</baidu.aip>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>com.yanzuoguang</groupId>
<artifactId>yzg-util-base</artifactId>
</dependency>
<dependency>
<groupId>com.belerweb</groupId>
<artifactId>pinyin4j</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>com.baidu.aip</groupId>
<artifactId>java-sdk</artifactId>
<version>${baidu.aip}</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package com.yanzuoguang.util;
import com.baidu.aip.speech.AipSpeech;
import com.baidu.aip.speech.TtsResponse;
import com.baidu.aip.util.Util;
import com.yanzuoguang.util.exception.CodeException;
import com.yanzuoguang.util.helper.JsonHelper;
import com.yanzuoguang.util.helper.StringHelper;
import com.yanzuoguang.util.vo.BaiduConfig;
import com.yanzuoguang.util.vo.HanziVo;
import net.sourceforge.pinyin4j.PinyinHelper;
import org.json.JSONObject;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.regex.Pattern;
/**
* 构造函数
* <p>
* 百度语音合成接口文档: https://ai.baidu.com/ai-doc/SPEECH/sk38y8hb7
*
* @author 颜佐光
*/
public class ChineseHelper {
/***
* ^[\u2E80-\u9FFF]+$ 匹配所有东亚区的语言
* ^[\u4E00-\u9FFF]+$ 匹配简体和繁体
* ^[\u4E00-\u9FA5]+$ 匹配简体
*/
private static Pattern pattern = Pattern.compile("^[\u4E00-\u9FFF]+$");
/**
* 获取汉字全拼
*
* @param from 来源汉字
* @return
*/
public static List<HanziVo> getPinyin(String from) {
if (StringHelper.isEmpty(from)) {
return new ArrayList<>(0);
}
List<HanziVo> rets = new ArrayList<>(from.length() / 2);
for (int i = 0; i < from.length(); i++) {
char unit = from.charAt(i);
HanziVo hanzi = new HanziVo();
hanzi.setFrom(unit);
// 是汉字,则转拼音
if (pattern.matcher(String.valueOf(unit)).find()) {
try {
String[] items = PinyinHelper.toHanyuPinyinStringArray(unit);
hanzi.setTos(items);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
rets.add(hanzi);
}
return rets;
}
/**
* 生成语音
*
* @param config 配置
* @param from 语音文字 合成的文本,使用UTF-8编码, 请注意文本长度必须小于1024字节
* @param to 目标文件
*/
public static void saveVideo(BaiduConfig config, String from, File to) {
// 初始化一个AipSpeech
AipSpeech client = new AipSpeech(config.getAppId(), config.getApiKey(), config.getSecretKey());
// 可选:设置网络连接参数
if (config.getConnectionTimeoutInMillis() > 0) {
client.setConnectionTimeoutInMillis(config.getConnectionTimeoutInMillis());
}
if (config.getSocketTimeoutInMillis() > 0) {
client.setSocketTimeoutInMillis(config.getSocketTimeoutInMillis());
}
// 可选:设置代理服务器地址, http和socket二选一,或者均不设置
// 设置http代理
if (!StringHelper.isEmpty(config.getHttpProxyHost()) && config.getHttpProxyPort() > 0) {
client.setHttpProxy(config.getHttpProxyHost(), config.getHttpProxyPort());
}
// 设置socket代理
else if (!StringHelper.isEmpty(config.getSocketProxyHost()) && config.getSocketProxyPort() > 0) {
client.setSocketProxy(config.getSocketProxyHost(), config.getSocketProxyPort());
}
// 可选:设置log4j日志输出格式,若不设置,则使用默认配置
// 也可以直接通过jvm启动参数设置此环境变量
// System.setProperty("aip.log4j.conf", "path/to/your/log4j.properties");
// 设置可选参数
HashMap<String, Object> options = new HashMap<String, Object>();
options.put("spd", config.getSpd());
options.put("pit", config.getPit());
options.put("per", config.getPer());
options.put("vol", config.getVol());
// 调用接口
TtsResponse res = client.synthesis(from, config.getLang(), config.getCtp(), options);
byte[] data = res.getData();
JSONObject res1 = res.getResult();
if (data != null) {
try {
Util.writeBytesToFileSystem(data, to.getAbsolutePath());
} catch (IOException e) {
throw new RuntimeException(e);
}
} else {
System.out.println(JsonHelper.serialize(res1, true));
int code = res1.getInt("err_no");
String message = res1.getString("err_msg");
throw new CodeException(StringHelper.toString(code), message, res1);
}
}
}
package com.yanzuoguang.util.vo;
/**
* 百度语音配置
*
* @author 颜佐光
*/
public class BaiduConfig extends BaseVo {
/**
* 百度App_ID
*/
private String appId;
/**
* 百度apiKey
*/
private String apiKey;
/**
* 百度secretKey
*/
private String secretKey;
/**
* 设置网络连接参数
*/
private int connectionTimeoutInMillis;
/**
* 设置网络连接参数
*/
private int socketTimeoutInMillis;
/**
* 设置http代理服务器
*/
private String httpProxyHost;
/**
* 设置http代理端口
*/
private int httpProxyPort;
/**
* 设置http代理服务器
*/
private String socketProxyHost;
/**
* 设置http代理端口
*/
private int socketProxyPort;
/**
* 语言,默认中文
*/
private String lang = "zh";
/**
* ctp
*/
private int ctp = 1;
/**
* 语速,取值0-9,默认为5中语速
*/
private int spd = 5;
/**
* 音调,取值0-9,默认为5中语调
*/
private int pit = 5;
/**
* 音量,取值0-15,默认为5中音量 否
*/
private int vol = 15;
/**
* 发音人选择,0为女声,1为男声, 3为情感合成-度逍遥,4为情感合成-度丫丫,默认为普通女 否
*/
private int per = 0;
public BaiduConfig() {
}
public BaiduConfig(String appId, String apiKey, String secretKey) {
this.appId = appId;
this.apiKey = apiKey;
this.secretKey = secretKey;
}
public String getAppId() {
return appId;
}
public void setAppId(String appId) {
this.appId = appId;
}
public String getApiKey() {
return apiKey;
}
public void setApiKey(String apiKey) {
this.apiKey = apiKey;
}
public String getSecretKey() {
return secretKey;
}
public void setSecretKey(String secretKey) {
this.secretKey = secretKey;
}
public int getConnectionTimeoutInMillis() {
return connectionTimeoutInMillis;
}
public void setConnectionTimeoutInMillis(int connectionTimeoutInMillis) {
this.connectionTimeoutInMillis = connectionTimeoutInMillis;
}
public int getSocketTimeoutInMillis() {
return socketTimeoutInMillis;
}
public void setSocketTimeoutInMillis(int socketTimeoutInMillis) {
this.socketTimeoutInMillis = socketTimeoutInMillis;
}
public String getHttpProxyHost() {
return httpProxyHost;
}
public void setHttpProxyHost(String httpProxyHost) {
this.httpProxyHost = httpProxyHost;
}
public int getHttpProxyPort() {
return httpProxyPort;
}
public void setHttpProxyPort(int httpProxyPort) {
this.httpProxyPort = httpProxyPort;
}
public String getSocketProxyHost() {
return socketProxyHost;
}
public void setSocketProxyHost(String socketProxyHost) {
this.socketProxyHost = socketProxyHost;
}
public int getSocketProxyPort() {
return socketProxyPort;
}
public void setSocketProxyPort(int socketProxyPort) {
this.socketProxyPort = socketProxyPort;
}
public String getLang() {
return lang;
}
public void setLang(String lang) {
this.lang = lang;
}
public int getCtp() {
return ctp;
}
public void setCtp(int ctp) {
this.ctp = ctp;
}
public int getSpd() {
return spd;
}
public void setSpd(int spd) {
this.spd = spd;
}
public int getPit() {
return pit;
}
public void setPit(int pit) {
this.pit = pit;
}
public int getVol() {
return vol;
}
public void setVol(int vol) {
this.vol = vol;
}
public int getPer() {
return per;
}
public void setPer(int per) {
this.per = per;
}
}
package com.yanzuoguang.util.vo;
/**
* 汉字处理
*/
public class HanziVo {
/**
* 来源汉字
*/
private char from;
/**
* 目标拼音
*/
private String[] tos;
public char getFrom() {
return from;
}
public void setFrom(char from) {
this.from = from;
}
public String[] getTos() {
return tos;
}
public void setTos(String[] tos) {
this.tos = tos;
}
}
package helper;
import com.yanzuoguang.util.ChineseHelper;
import com.yanzuoguang.util.vo.BaiduConfig;
import com.yanzuoguang.util.vo.HanziVo;
import com.yanzuoguang.util.helper.JsonHelper;
import org.junit.Test;
import java.io.File;
import java.util.List;
public class TestChineseHelper {
@Test
public void testConvert() {
String text = "颜佐光还喜欢游泳";
List<HanziVo> items = ChineseHelper.getPinyin(text);
System.out.println("json:" + JsonHelper.serialize(items, true));
}
@Test
public void testConvertMp3() {
String text = "三分钟前,由北京市顺义区二经路与二纬路交汇处北侧,北京首都国际机场T3航站楼 去往 东城区北三环东路36号喜来登大酒店(北京金隅店)";
BaiduConfig config = new BaiduConfig(
"20624068",
"aeo4CBIjiW4wLuiIAKD4ZMrk",
"BLzIf80xq6v1cN4n231dSGPYqD1GDHy8");
ChineseHelper.saveVideo(config, text, getTargetFile("test.mp3"));
}
@Test
public void testConvertMp3Yzg() {
String text = "成人票15元";
BaiduConfig config = new BaiduConfig(
"20624068",
"aeo4CBIjiW4wLuiIAKD4ZMrk",
"BLzIf80xq6v1cN4n231dSGPYqD1GDHy8");
ChineseHelper.saveVideo(config, text, getTargetFile("product.mp3"));
}
private File getTargetFile(String to) {
// 注意,路径应为文件在工程中的相对路径
File f = new File("target/" + to);
return f;
}
}
{
"PageWidth": 73,
"PageHeight": 50,
"MarginTop": 125,
"MarginRight": 0,
"MarginBottom": 0,
"MarginLeft": 0,
"PrintAngle": 0,
"Items": [
{
"Name": "OrderId",
"Type": 1,
"IsVisible": true,
"Top": 4.266013763896241,
"Left": 25.329221810481734,
"Width": 39.926945473795655,
"Height": 4.235044997353096,
"Font": "微软雅黑,9pt,style=Underline",
"TextAlign": 1,
"Format": "订单编号:{0}",
"FormatValue": "订单编号:"
},
{
"Name": "createDate",
"Type": 1,
"IsVisible": true,
"Top": 14.942985706723134,
"Left": 25.34970884065643,
"Width": 46.9081524616199,
"Height": 4.235044997353096,
"Font": "微软雅黑,9pt,style=Underline",
"TextAlign": 1,
"Format": "出票时间:{0}",
"FormatValue": "出票时间:2019-10-16 16:11:01"
},
{
"Name": "codeNo",
"Type": 2,
"IsVisible": true,
"Top": 4.51799894123875,
"Left": 5.020275277924827,
"Width": 18.073398623610373,
"Height": 18.073398623610373,
"Font": "微软雅黑,9pt,style=Underline",
"TextAlign": 1,
"Format": "",
"FormatValue": "01234567890123"
},
{
"Name": "codeNo",
"Type": 1,
"IsVisible": true,
"Top": 9.331815775542616,
"Left": 25.329221810481734,
"Width": 40.72922181048174,
"Height": 4.235044997353096,
"Font": "微软雅黑,9pt,style=Underline",
"TextAlign": 1,
"Format": "电子券号:{0}",
"FormatValue": "电子券号:01234567890123"
},
{
"Name": "channelName",
"Type": 1,
"IsVisible": true,
"Top": 29.861302276336687,
"Left": 5.065802011646373,
"Width": 43.971678136580195,
"Height": 4.235044997353096,
"Font": "微软雅黑,9pt,style=Underline",
"TextAlign": 1,
"Format": "渠道来源:{0}",
"FormatValue": "渠道来源:窗口"
},
{
"Name": "buyNum",
"Type": 1,
"IsVisible": true,
"Top": 34.676283748014825,
"Left": 5.067840127051349,
"Width": 33.0574377977766,
"Height": 5.558496559025939,
"Font": "微软雅黑,12pt,style=Underline",
"TextAlign": 1,
"Format": "可用人数:{0}",
"FormatValue": "可用人数:1"
},
{
"Name": "Common",
"Type": 0,
"IsVisible": true,
"Top": 40.497617787188986,
"Left": 5.012122816304924,
"Width": 65.82530439385918,
"Height": 8.99947061937533,
"Font": "微软雅黑,9pt,style=Underline",
"TextAlign": 1,
"Format": "索道门票限当日22:00前使用,巴士门票限当日19:00前使用,一经售出不可退换(北站售)",
"FormatValue": "索道门票限当日22:00前使用,巴士门票限当日19:00前使用,一经售出不可退换(北站售)"
},
{
"Name": "productName",
"Type": 1,
"IsVisible": true,
"Top": 24.795976707252514,
"Left": 5.065802011646373,
"Width": 46.883271572260455,
"Height": 4.235044997353096,
"Font": "微软雅黑,9pt,style=Underline",
"TextAlign": 1,
"Format": "客票类别:{0:*:2,2,1}",
"FormatValue": "客票类别:途比达门票(自动修改)"
},
{
"Name": "PlayerType",
"Type": 1,
"IsVisible": true,
"Top": 19.730121757543674,
"Left": 25.329221810481734,
"Width": 26.35322922181048,
"Height": 4.235044997353096,
"Font": "微软雅黑,9pt,style=Underline",
"TextAlign": 1,
"Format": "游客类型:{0}",
"FormatValue": "游客类型:"
},
{
"Name": "salePriceTotal",
"Type": 1,
"IsVisible": true,
"Top": 34.66225516146109,
"Left": 39.194547379565904,
"Width": 29.2649550026469,
"Height": 5.558496559025939,
"Font": "微软雅黑,12pt,style=Underline",
"TextAlign": 1,
"Format": "票价:{0}",
"FormatValue": "票价:20"
}
]
}
\ No newline at end of file
{
"PageWidth": 73,
"PageHeight": 50,
"MarginTop": 125,
"MarginRight": 0,
"MarginBottom": 0,
"MarginLeft": 0,
"PrintAngle": 0,
"Items": [
{
"Name": "codeNo",
"Type": 2,
"IsVisible": true,
"Top": 1.9355849655902593,
"Left": 2.399322392800424,
"Width": 20.219031233456857,
"Height": 20.219031233456857,
"Font": "微软雅黑,9pt,style=Underline",
"TextAlign": 1,
"Format": "01234567890123",
"FormatValue": "01234567890123"
},
{
"Name": "codeNo",
"Type": 1,
"IsVisible": true,
"Top": 6.087877183695076,
"Left": 24.086818422445738,
"Width": 46.18845950238221,
"Height": 4.499735309687665,
"Font": "微软雅黑,9pt,style=Bold,Italic,Underline,",
"TextAlign": 1,
"Format": "电子券号:{0}",
"FormatValue": "电子券号:01234567890123"
},
{
"Name": "createDate",
"Type": 1,
"IsVisible": true,
"Top": 11.463102170460562,
"Left": 24.29563260984648,
"Width": 46.99920592906299,
"Height": 5.2938062466913705,
"Font": "微软雅黑,9pt,style=Underline",
"TextAlign": 1,
"Format": "出票时间:{0}",
"FormatValue": "出票时间:2019-10-16 16:11:01"
},
{
"Name": "productName",
"Type": 1,
"IsVisible": true,
"Top": 1.0073028057173108,
"Left": 24.29563260984648,
"Width": 42.54896770778189,
"Height": 4.238353626257279,
"Font": "微软雅黑,9pt,style=Bold",
"TextAlign": 1,
"Format": "客票类别:{0}",
"FormatValue": "客票类别:途比达门票(自动修改)"
},
{
"Name": "channelName",
"Type": 1,
"IsVisible": true,
"Top": 17.1644785600847,
"Left": 24.37673372154579,
"Width": 44.35230280571731,
"Height": 4.499735309687665,
"Font": "微软雅黑,9pt,style=Underline",
"TextAlign": 1,
"Format": "旅行社:{0}",
"FormatValue": "旅行社:窗口"
},
{
"Name": "buyNum",
"Type": 1,
"IsVisible": true,
"Top": 22.768501852832188,
"Left": 24.37673372154579,
"Width": 16.979883536262573,
"Height": 4.238353626257279,
"Font": "微软雅黑,9pt,style=Bold",
"TextAlign": 1,
"Format": "人数:{0}",
"FormatValue": "人数:1"
},
{
"Name": "Common",
"Type": 0,
"IsVisible": true,
"Top": 32.66278454208576,
"Left": 2.794547379565908,
"Width": 68.45897300158813,
"Height": 8.476707252514558,
"Font": "微软雅黑,9pt,style=Underline",
"TextAlign": 1,
"Format": "门票限当日 22:00 前使用,一经售出不可退换(南站票)",
"FormatValue": "门票限当日 22:00 前使用,一经售出不可退换(南站票)"
},
{
"Name": "visitorCardId",
"Type": 1,
"IsVisible": true,
"Top": 27.665696135521436,
"Left": 27.99655902593965,
"Width": 34.66119640021175,
"Height": 4.238353626257279,
"Font": "微软雅黑,9pt,style=Underline",
"TextAlign": 1,
"Format": " ",
"FormatValue": " "
},
{
"Name": "sortNo",
"Type": 1,
"IsVisible": true,
"Top": 42.024351508734775,
"Left": 2.4116728427739544,
"Width": 25.671651667548968,
"Height": 5.558496559025939,
"Font": "微软雅黑,12pt,style=Bold",
"TextAlign": 1,
"Format": "排号:{0}",
"FormatValue": "排号:2"
},
{
"Name": "sortNoTime",
"Type": 1,
"IsVisible": true,
"Top": 42.0857596611964,
"Left": 27.561143462149285,
"Width": 145.51032292218105,
"Height": 5.823186871360509,
"Font": "微软雅黑,9pt,style=Bold",
"TextAlign": 1,
"Format": "预计排队进入时间:{0}",
"FormatValue": "预计排队进入时间:12:55"
},
{
"Name": "visitorName",
"Type": 1,
"IsVisible": true,
"Top": 27.795659078877712,
"Left": 2.4175304393859185,
"Width": 24.477236633139224,
"Height": 4.800820539968237,
"Font": "微软雅黑,9pt,style=Underline",
"TextAlign": 1,
"Format": "导游:{0}",
"FormatValue": "导游:颜佐光"
}
]
}
\ No newline at end of file
package com.yanzuoguang.util;
import net.coobird.thumbnailator.Thumbnails;
import javax.imageio.IIOImage;
import javax.imageio.ImageIO;
import javax.imageio.ImageWriteParam;
import javax.imageio.ImageWriter;
import javax.imageio.stream.ImageOutputStream;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
/**
* 图片处理程序
*
* @author 颜佐光
*/
public class ImageHelper {
public static final float DEFAULT_SIZE = 1f;
public static final float DEFAULT_QUALITY = 1f;
/**
* 压缩图片
*
* @param srcFilePath 来源路径
* @param descFilePath  目标路径
* @param quality 质量程度,取值0~1范围内
* @param size 大小程度,取值0~1范围内
* @throws IOException
*/
public static void compressPicBySystem(String srcFilePath, String descFilePath,
float quality, float size) throws IOException {
// 设置默认值
if (size == 0) {
size = 1;
}
if (quality == 0) {
quality = 1;
}
File input = new File(srcFilePath);
BufferedImage image = ImageIO.read(input);
// 压缩图片大小
if (size < 1) {
int toWidth = (int) (image.getWidth() * size);
int toHeight = (int) (image.getHeight() * size);
BufferedImage buffImage = new BufferedImage(toWidth, toHeight, BufferedImage.TYPE_INT_RGB);
buffImage.getGraphics().drawImage(image.getScaledInstance(toWidth, toHeight, Image.SCALE_SMOOTH),
0, 0, null);
image = buffImage;
}
// 先指定Output,才能调用writer.write方法
File output = new File(descFilePath);
// 指定写图片的方式为 jpg
ImageWriter writer = null;
OutputStream out = null;
ImageOutputStream ios = null;
try {
writer = ImageIO.getImageWritersByFormatName("jpg").next();
out = new FileOutputStream(output);
ios = ImageIO.createImageOutputStream(out);
writer.setOutput(ios);
ImageWriteParam param = writer.getDefaultWriteParam();
if (param.canWriteCompressed()) {
// 指定压缩方式为MODE_EXPLICIT
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
// param.set
// 压缩程度,参数quality是取值0~1范围内
param.setCompressionQuality(quality);
}
// 调用write方法,向输入流写图片
writer.write(null, new IIOImage(image, null, null), param);
} finally {
if (out != null) {
out.close();
}
if (ios != null) {
ios.close();
}
if (writer != null) {
writer.dispose();
}
}
}
/**
* 压缩图片
*
* @param srcFilePath 来源路径
* @param descFilePath  目标路径
* @throws IOException
*/
public static void compressPic(String srcFilePath, String descFilePath) throws IOException {
compressPic(srcFilePath, descFilePath, DEFAULT_QUALITY, DEFAULT_SIZE);
}
/**
* 压缩图片
*
* @param srcFilePath 来源路径
* @param descFilePath  目标路径
* @param quality 压缩程度,参数quality是取值0~1范围内
* @throws IOException
*/
public static void compressPic(String srcFilePath, String descFilePath, float quality) throws IOException {
compressPic(srcFilePath, descFilePath, quality, DEFAULT_SIZE);
}
/**
* 压缩图片
*
* @param srcFilePath 来源路径
* @param descFilePath  目标路径
* @param quality 质量程度,取值0~1范围内
* @param size 大小程度,取值0~1范围内
* @throws IOException
*/
public static void compressPic(String srcFilePath, String descFilePath, float quality, float size) throws IOException {
Thumbnails
// 来源目录
.of(srcFilePath)
// 按比例缩小
.scale(size)
// 质量压缩
.outputQuality(quality)
// 目标文件
.toFile(descFilePath);
}
}
......@@ -2,23 +2,15 @@ package com.yanzuoguang.util;
import com.yanzuoguang.util.log.Log;
import it.sauronsoftware.jave.*;
import net.coobird.thumbnailator.Thumbnails;
import org.bytedeco.javacv.FFmpegFrameGrabber;
import org.bytedeco.javacv.Frame;
import org.bytedeco.javacv.Java2DFrameConverter;
import javax.imageio.IIOImage;
import javax.imageio.ImageIO;
import javax.imageio.ImageWriteParam;
import javax.imageio.ImageWriter;
import javax.imageio.stream.ImageOutputStream;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.awt.image.RenderedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
/**
* 视频帮助类
......@@ -27,12 +19,10 @@ import java.io.OutputStream;
*
* @author 颜佐光
*/
public class MediaHelper {
public class MediaHelper extends ImageHelper {
public static final int FIRST_FRAME = 5;
public static final int DEFAULT_BIT_RATE = 372 * 1000;
public static final float DEFAULT_SIZE = 1f;
public static final float DEFAULT_QUALITY = 1f;
public static final String FORMAT_EMPTY = "";
public static final String FORMAT_FLV = "flv";
......@@ -365,116 +355,4 @@ public class MediaHelper {
return bufferedImage;
}
/**
* 压缩图片
*
* @param srcFilePath 来源路径
* @param descFilePath  目标路径
* @param quality 质量程度,取值0~1范围内
* @param size 大小程度,取值0~1范围内
* @throws IOException
*/
public static void compressPicBySystem(String srcFilePath, String descFilePath,
float quality, float size) throws IOException {
// 设置默认值
if (size == 0) {
size = 1;
}
if (quality == 0) {
quality = 1;
}
File input = new File(srcFilePath);
BufferedImage image = ImageIO.read(input);
// 压缩图片大小
if (size < 1) {
int toWidth = (int) (image.getWidth() * size);
int toHeight = (int) (image.getHeight() * size);
BufferedImage buffImage = new BufferedImage(toWidth, toHeight, BufferedImage.TYPE_INT_RGB);
buffImage.getGraphics().drawImage(image.getScaledInstance(toWidth, toHeight, Image.SCALE_SMOOTH),
0, 0, null);
image = buffImage;
}
// 先指定Output,才能调用writer.write方法
File output = new File(descFilePath);
// 指定写图片的方式为 jpg
ImageWriter writer = null;
OutputStream out = null;
ImageOutputStream ios = null;
try {
writer = ImageIO.getImageWritersByFormatName("jpg").next();
out = new FileOutputStream(output);
ios = ImageIO.createImageOutputStream(out);
writer.setOutput(ios);
ImageWriteParam param = writer.getDefaultWriteParam();
if (param.canWriteCompressed()) {
// 指定压缩方式为MODE_EXPLICIT
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
// param.set
// 压缩程度,参数quality是取值0~1范围内
param.setCompressionQuality(quality);
}
// 调用write方法,向输入流写图片
writer.write(null, new IIOImage(image, null, null), param);
} finally {
if (out != null) {
out.close();
}
if (ios != null) {
ios.close();
}
if (writer != null) {
writer.dispose();
}
}
}
/**
* 压缩图片
*
* @param srcFilePath 来源路径
* @param descFilePath  目标路径
* @throws IOException
*/
public static void compressPic(String srcFilePath, String descFilePath) throws IOException {
compressPic(srcFilePath, descFilePath, DEFAULT_QUALITY, DEFAULT_SIZE);
}
/**
* 压缩图片
*
* @param srcFilePath 来源路径
* @param descFilePath  目标路径
* @param quality 压缩程度,参数quality是取值0~1范围内
* @throws IOException
*/
public static void compressPic(String srcFilePath, String descFilePath, float quality) throws IOException {
compressPic(srcFilePath, descFilePath, quality, DEFAULT_SIZE);
}
/**
* 压缩图片
*
* @param srcFilePath 来源路径
* @param descFilePath  目标路径
* @param quality 质量程度,取值0~1范围内
* @param size 大小程度,取值0~1范围内
* @throws IOException
*/
public static void compressPic(String srcFilePath, String descFilePath, float quality, float size) throws IOException {
Thumbnails
// 来源目录
.of(srcFilePath)
// 按比例缩小
.scale(size)
// 质量压缩
.outputQuality(quality)
// 目标文件
.toFile(descFilePath);
}
}
......@@ -82,6 +82,17 @@ public class MessageVo extends BaseVo implements InitDao {
public MessageVo() {
}
/**
* 构造函数
*
* @param exchangeNameRouteKey 交换器名称+路由键
* @param message 消息内容
*/
public MessageVo(String exchangeNameRouteKey, String message) {
this(exchangeNameRouteKey, exchangeNameRouteKey, message);
}
/**
* 构造函数
*
......@@ -95,6 +106,17 @@ public class MessageVo extends BaseVo implements InitDao {
this.message = message;
}
/**
* 构造函数
*
* @param exchangeNameRouteKey 交换器名称+路由键
* @param message 消息内容
* @param dedTime 过期时间
*/
public MessageVo(String exchangeNameRouteKey, String message, long dedTime) {
this(exchangeNameRouteKey, exchangeNameRouteKey, message, dedTime);
}
/**
* 构造函数
*
......@@ -110,6 +132,17 @@ public class MessageVo extends BaseVo implements InitDao {
this.dedTime = dedTime;
}
/**
* 构造函数
*
* @param exchangeNameRouteKey 交换器名称+路由键
* @param message 消息内容
* @param dedTime 过期时间
*/
public MessageVo(String exchangeNameRouteKey, String message, long dedTime, boolean dedTimeDefine) {
this(exchangeNameRouteKey, exchangeNameRouteKey, message, dedTime, dedTimeDefine);
}
/**
* 构造函数
*
......
......@@ -9,6 +9,7 @@ import com.yanzuoguang.util.vo.InitDao;
/**
* 创建队列
*
* @author 颜佐光
*/
@TableAnnotation("Queue_Queue")
......@@ -87,7 +88,7 @@ public class QueueVo extends BaseVo implements InitDao {
/**
* 构造函数
*/
public QueueVo(){
public QueueVo() {
}
/**
......@@ -104,6 +105,18 @@ public class QueueVo extends BaseVo implements InitDao {
this.routeKey = routeKey;
}
/**
* 构造函数,用于创建延迟队列。</p>
* 会创建queueName、exchangeName并且通过routeKey绑定。
*
* @param queueName 队列名称,交换器名称,路由键
*/
public QueueVo(String queueName) {
this.queueName = queueName;
this.exchangeName = queueName;
this.routeKey = queueName;
}
/**
* 构造函数,用于创建延迟队列。</p>
* 创建 queueName、exchangeName 并且通过 routeKey 绑定, 创建 dedQueueName、dedExchangeName 并且通过 dedRouteKey 绑定,
......@@ -127,6 +140,26 @@ public class QueueVo extends BaseVo implements InitDao {
this.dedRouteKey = dedRouteKey;
}
/**
* 构造函数,用于创建延迟队列。</p>
* 创建 queueName、exchangeName 并且通过 routeKey 绑定, 创建 dedQueueName、dedExchangeName 并且通过 dedRouteKey 绑定,
* 将 queueName 的死信队列设置为 dedExchangeName 和 dedRouteKey .
*
* @param queueName 队列名称,路由键,交换器名称
* @param dedTime 死信时间
* @param dedQueueName 死信交换器名称,死信交换队列名称,死信路由键
*/
public QueueVo(String queueName, long dedTime, String dedQueueName) {
this.queueName = queueName;
this.exchangeName = queueName;
this.routeKey = queueName;
this.dedTime = dedTime;
this.dedExchangeName = dedQueueName;
this.dedQueueName = dedQueueName;
this.dedRouteKey = dedQueueName;
}
public String getQueueId() {
return queueId;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment