工具类,案件压缩包导入优化
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
package com.ruoyi.common.utils;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author wangqiong
|
||||
* @description 根据身份证号提取有效信息
|
||||
* @date 2023-12-11 11:45
|
||||
*/
|
||||
public class IdCardUtils {
|
||||
/**
|
||||
* 通过身份证号码获取出生日期、性别、年龄
|
||||
* @param certificateNo
|
||||
* @return 返回的出生日期格式:1990-01-01 性别格式:1-女,0-男
|
||||
*/
|
||||
public static Map<String, String> getBirAgeSex(String certificateNo) {
|
||||
String birthday = "";
|
||||
String age = "";
|
||||
String sexCode = "";
|
||||
|
||||
int year = Calendar.getInstance().get(Calendar.YEAR);
|
||||
char[] number = certificateNo.toCharArray();
|
||||
boolean flag = true;
|
||||
if (number.length == 15) {
|
||||
for (int x = 0; x < number.length; x++) {
|
||||
if (!flag) return new HashMap<String, String>();
|
||||
flag = Character.isDigit(number[x]);
|
||||
}
|
||||
} else if (number.length == 18) {
|
||||
for (int x = 0; x < number.length - 1; x++) {
|
||||
if (!flag) return new HashMap<String, String>();
|
||||
flag = Character.isDigit(number[x]);
|
||||
}
|
||||
}
|
||||
if (flag && certificateNo.length() == 15) {
|
||||
birthday = "19" + certificateNo.substring(6, 8) + "-"
|
||||
+ certificateNo.substring(8, 10) + "-"
|
||||
+ certificateNo.substring(10, 12);
|
||||
sexCode = Integer.parseInt(certificateNo.substring(certificateNo.length() - 3, certificateNo.length())) % 2 == 0 ? "1" : "0";
|
||||
age = (year - Integer.parseInt("19" + certificateNo.substring(6, 8))) + "";
|
||||
} else if (flag && certificateNo.length() == 18) {
|
||||
birthday = certificateNo.substring(6, 10) + "-"
|
||||
+ certificateNo.substring(10, 12) + "-"
|
||||
+ certificateNo.substring(12, 14);
|
||||
sexCode = Integer.parseInt(certificateNo.substring(certificateNo.length() - 4, certificateNo.length() - 1)) % 2 == 0 ? "1" : "0";
|
||||
age = (year - Integer.parseInt(certificateNo.substring(6, 10))) + "";
|
||||
}
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map.put("birthday", birthday);
|
||||
map.put("age", age);
|
||||
map.put("sexCode", sexCode);
|
||||
return map;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.ruoyi.common.utils;
|
||||
|
||||
import cn.hutool.core.lang.Snowflake;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.ruoyi.common.utils.uuid.UUID;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* 雪花算法工具类
|
||||
* zq
|
||||
* @since 2020/10/30 9:59
|
||||
**/
|
||||
public class IdWorkerUtil {
|
||||
private static final long EPOCH = 1479533469598L; //开始时间,固定一个小于当前时间的毫秒数
|
||||
private static final int max12bit = 4095;
|
||||
private static final long max41bit= 1099511627775L;
|
||||
private static String machineId = "" ; // 机器ID
|
||||
|
||||
/**
|
||||
*
|
||||
* 创建ID
|
||||
*
|
||||
* @return
|
||||
*
|
||||
*/
|
||||
public static Long getId(){
|
||||
|
||||
long time = System.currentTimeMillis() - EPOCH + max41bit;
|
||||
// 二进制的 毫秒级时间戳
|
||||
String base = Long.toBinaryString(time);
|
||||
|
||||
// 序列数
|
||||
String randomStr = StringUtils.leftPad(Integer.toBinaryString(new Random().nextInt(max12bit)),12,'0');
|
||||
if(StringUtils.isNotEmpty(machineId)){
|
||||
machineId = StringUtils.leftPad(machineId, 10, '0');
|
||||
}
|
||||
|
||||
//拼接
|
||||
String appendStr = base + machineId + randomStr;
|
||||
// 转化为十进制 返回
|
||||
BigInteger bi = new BigInteger(appendStr, 2);
|
||||
|
||||
return Long.valueOf(bi.toString());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.ruoyi.common.utils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
/**
|
||||
* @author wangqiong
|
||||
* @description 金额格式化
|
||||
* @date 2023-12-11 11:45
|
||||
*/
|
||||
public class MoneyFormatUtils {
|
||||
|
||||
/**
|
||||
* 增加千分位
|
||||
* @param money
|
||||
* @return
|
||||
*/
|
||||
public static String moneyFormat(String money) {
|
||||
// 金额格式化
|
||||
try {
|
||||
Double.parseDouble(money);
|
||||
|
||||
} catch (NumberFormatException e) {
|
||||
|
||||
String regEx = "[^0-9]";
|
||||
Pattern p = Pattern.compile(regEx);
|
||||
Matcher m = p.matcher(money);
|
||||
String result = m.replaceAll("").trim();
|
||||
BigDecimal bigDecimal = null;
|
||||
if (money.contains("百")) {
|
||||
bigDecimal = new BigDecimal(result).multiply(new BigDecimal("100"));
|
||||
} else if (money.contains("千")) {
|
||||
bigDecimal = new BigDecimal(result).multiply(new BigDecimal("1000"));
|
||||
} else if (money.contains("万")) {
|
||||
bigDecimal = new BigDecimal(result).multiply(new BigDecimal("10000"));
|
||||
} else if (money.contains("百万")) {
|
||||
bigDecimal = new BigDecimal(result).multiply(new BigDecimal("1000000"));
|
||||
} else if (money.contains("千万")) {
|
||||
bigDecimal = new BigDecimal(result).multiply(new BigDecimal("10000000"));
|
||||
} else if (money.contains("亿")) {
|
||||
bigDecimal = new BigDecimal(result).multiply(new BigDecimal("100000000"));
|
||||
}
|
||||
|
||||
NumberFormat format = NumberFormat.getInstance();
|
||||
return format.format(bigDecimal);
|
||||
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
package com.ruoyi.common.utils;
|
||||
|
||||
import org.apache.poi.hwpf.extractor.WordExtractor;
|
||||
import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* @author wangqiong
|
||||
* @description 读取文件内容
|
||||
* @date 2023-12-11 11:45
|
||||
*/
|
||||
public class ReadFileUtils {
|
||||
|
||||
|
||||
public static String readerTxtFile(String filePath){
|
||||
BufferedReader br=null;
|
||||
StringBuilder result=new StringBuilder();
|
||||
try {
|
||||
br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(filePath)),"GBK"));
|
||||
String line=null;
|
||||
while ((line=br.readLine())!=null) {
|
||||
result.append(line).append("\n");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (null!=br){
|
||||
try {
|
||||
br.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
public static String readWord(String filePath) throws Exception{
|
||||
|
||||
File file = new File(filePath);
|
||||
if(file.length()==0) return ""; // 需要操作原因是可能会空文件问题,如果不做处理,在下面读取中会报错
|
||||
StringBuffer sb = new StringBuffer();
|
||||
String buffer = "";
|
||||
try {
|
||||
if (filePath.endsWith(".doc")) {
|
||||
InputStream is = new FileInputStream(file);
|
||||
WordExtractor ex = new WordExtractor(is);
|
||||
buffer = ex.getText();
|
||||
if(buffer.length() > 0){
|
||||
//使用回车换行符分割字符串
|
||||
String [] arry = buffer.split("r\\n");
|
||||
for (String string : arry) {
|
||||
sb.append(string.trim());
|
||||
}
|
||||
}
|
||||
} else if (filePath.endsWith(".docx")) {
|
||||
FileInputStream fis = new FileInputStream(file);
|
||||
XWPFDocument xdoc = new XWPFDocument(fis);
|
||||
XWPFWordExtractor extractor = new XWPFWordExtractor(xdoc);
|
||||
buffer = extractor.getText();
|
||||
sb.append(buffer!=null?buffer:"");
|
||||
|
||||
|
||||
// OPCPackage opcPackage = POIXMLDocument.openPackage(filePath);
|
||||
// XWPFWordExtractor extractor = new XWPFWordExtractor(opcPackage);
|
||||
// buffer = extractor.getText();
|
||||
// if(buffer.length() > 0){
|
||||
// //使用换行符分割字符串
|
||||
// String [] arry = buffer.split("\n");
|
||||
// for (String string : arry) {
|
||||
// sb.append(string.trim());
|
||||
// }
|
||||
// }
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return sb.toString();
|
||||
} catch (Exception e) {
|
||||
System.out.print("error---->"+filePath);
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.ruoyi.common.utils;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author wangqiong
|
||||
* @description 获取bean工具类
|
||||
* @date 2023-12-11 11:45
|
||||
*/
|
||||
@Component
|
||||
public class SpringUtil implements ApplicationContextAware {
|
||||
private static ApplicationContext applicationContext;
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||
if(SpringUtil.applicationContext==null){
|
||||
SpringUtil.applicationContext=applicationContext;
|
||||
}
|
||||
}
|
||||
|
||||
public static ApplicationContext getApplicationContext(){
|
||||
return applicationContext;
|
||||
}
|
||||
|
||||
public static <T>T getBean(Class<T> clazz){
|
||||
return getApplicationContext().getBean(clazz);
|
||||
}
|
||||
|
||||
public static <T>T getBean(String name, Class<T> clazz){
|
||||
return getApplicationContext().getBean(name,clazz);
|
||||
}
|
||||
}
|
||||
@@ -288,4 +288,18 @@ public class FileUtils
|
||||
String baseName = FilenameUtils.getBaseName(fileName);
|
||||
return baseName;
|
||||
}
|
||||
/**
|
||||
* 获取文件后缀名
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
public static String getFileExtension(File file) {
|
||||
String name = file.getName();
|
||||
int lastIndexOfDot = name.lastIndexOf(".");
|
||||
if (lastIndexOfDot != -1 && lastIndexOfDot < name.length() - 1) {
|
||||
return name.substring(lastIndexOfDot + 1);
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+46
-1
@@ -185,7 +185,52 @@ public class MultipleThreadWorkUtil {
|
||||
mainLatch,threadLatch,rollBack,times);
|
||||
return returnList;
|
||||
}
|
||||
|
||||
public static <R,A>List<R> execListFun(MultipleThreadListParam<R,A> ...params){
|
||||
List<R> returnList=new ArrayList<>();
|
||||
if(ArrayUtil.isEmpty(params)){
|
||||
return returnList;
|
||||
}
|
||||
List<Integer> threadCountList=new ArrayList<>();
|
||||
for (MultipleThreadListParam param : params) {
|
||||
if(param.getList().size()<SIMPLE_TIME_COUNT){
|
||||
threadCountList.add(1);
|
||||
}else{
|
||||
if(param.getList().size()%SIMPLE_TIME_COUNT>0){
|
||||
threadCountList.add(param.getList().size()/SIMPLE_TIME_COUNT+1);
|
||||
}else{
|
||||
threadCountList.add(param.getList().size()/SIMPLE_TIME_COUNT);
|
||||
}
|
||||
}
|
||||
}
|
||||
int times=0;
|
||||
for (Integer count : threadCountList) {
|
||||
times+=count;
|
||||
}
|
||||
CountDownLatch mainLatch=new CountDownLatch(1);
|
||||
//监控子线程
|
||||
CountDownLatch threadLatch=new CountDownLatch(times);
|
||||
//根据子线程执行结果判断是否需要回滚
|
||||
BlockingDeque<Boolean> resultList=new LinkedBlockingDeque<>();
|
||||
//必须使用对象,如果使用变量会造成线程之间不能共享变量值
|
||||
RollBack rollBack=new RollBack(false);
|
||||
ExecutorService executorService=Executors.newFixedThreadPool(times);
|
||||
List<Future<R>> futureList=new ArrayList<>();
|
||||
for (int i = 0; i < params.length; i++) {
|
||||
MultipleThreadListParam param=params[i];
|
||||
for (int j = 0; j <threadCountList.get(i) ; j++) {
|
||||
if(j*SIMPLE_TIME_COUNT+SIMPLE_TIME_COUNT<param.getList().size()){
|
||||
Future<R> future=executorService.submit(new ExecThread(mainLatch,threadLatch,rollBack,resultList,param.getList().subList(j*SIMPLE_TIME_COUNT,j*SIMPLE_TIME_COUNT+SIMPLE_TIME_COUNT),param.getFunction()));
|
||||
futureList.add(future);
|
||||
}else{
|
||||
Future<R> future=executorService.submit(new ExecThread(mainLatch,threadLatch,rollBack,resultList,param.getList().subList(j*SIMPLE_TIME_COUNT,param.getList().size()),param.getFunction()));
|
||||
futureList.add(future);
|
||||
}
|
||||
}
|
||||
}
|
||||
setResult(executorService,returnList,futureList,resultList,
|
||||
mainLatch,threadLatch,rollBack,times);
|
||||
return returnList;
|
||||
}
|
||||
public static <R>List<R> execByIds(Function<String,R> execFun,String ids){
|
||||
List<R> returnList=new ArrayList<>();
|
||||
if(StrUtil.isEmpty(ids)){
|
||||
|
||||
Reference in New Issue
Block a user