feat: 添加slrs业务子项目 修改问题文件
This commit is contained in:
@@ -0,0 +1,168 @@
|
||||
package com.adc.da.http;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class PageInfo<T> {
|
||||
private Integer pageNo;
|
||||
private Integer pageSize;
|
||||
private Long count;
|
||||
private Long pageCount;
|
||||
private List<T> list;
|
||||
private List<Map<String, Object>> title;
|
||||
private Map<String, String> ext;
|
||||
private String orderBy;
|
||||
|
||||
public PageInfo() {
|
||||
this.pageNo = 1;
|
||||
this.pageSize = 10;
|
||||
this.list = new ArrayList();
|
||||
this.title = new ArrayList();
|
||||
this.ext = new HashMap();
|
||||
this.orderBy = "";
|
||||
this.pageSize = 1;
|
||||
}
|
||||
|
||||
public PageInfo(HttpServletRequest request) {
|
||||
this.pageNo = 1;
|
||||
this.pageSize = 10;
|
||||
this.list = new ArrayList();
|
||||
this.title = new ArrayList();
|
||||
this.ext = new HashMap();
|
||||
this.orderBy = "";
|
||||
String no = request.getParameter("pageNo");
|
||||
if (StringUtils.isEmpty(no)) {
|
||||
this.setPageNo(1);
|
||||
} else if (StringUtils.isNumeric(no)) {
|
||||
this.setPageNo(Integer.parseInt(no));
|
||||
}
|
||||
|
||||
String size = request.getParameter("pageSize");
|
||||
if (StringUtils.isEmpty(size)) {
|
||||
this.setPageSize(10);
|
||||
}
|
||||
|
||||
if (StringUtils.isNumeric(size)) {
|
||||
this.setPageSize(Integer.parseInt(size));
|
||||
}
|
||||
|
||||
String orderByParam = request.getParameter("orderBy");
|
||||
if (StringUtils.isNotBlank(orderByParam)) {
|
||||
this.setOrderBy(orderByParam);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public PageInfo(Integer pageNo, Integer pageSize) {
|
||||
this(pageNo, pageSize, 0L);
|
||||
}
|
||||
|
||||
public PageInfo(Integer pageNo, Integer pageSize, Long count) {
|
||||
this(pageNo, pageSize, count, new ArrayList());
|
||||
}
|
||||
|
||||
public PageInfo(Integer pageNo, Integer pageSize, Long count, List<T> list) {
|
||||
this.pageNo = 1;
|
||||
this.pageSize = 10;
|
||||
this.list = new ArrayList();
|
||||
this.title = new ArrayList();
|
||||
this.ext = new HashMap();
|
||||
this.orderBy = "";
|
||||
if (pageNo == null) {
|
||||
pageNo = 1;
|
||||
}
|
||||
|
||||
if (pageSize == null) {
|
||||
pageSize = 10;
|
||||
}
|
||||
|
||||
this.setCount(count);
|
||||
this.setPageNo(Math.abs(pageNo));
|
||||
this.setPageSize(Math.abs(pageSize));
|
||||
this.setList(list);
|
||||
}
|
||||
|
||||
public Long getCount() {
|
||||
return this.count;
|
||||
}
|
||||
|
||||
public void setCount(Long count) {
|
||||
this.count = count;
|
||||
if ((long) this.pageSize >= count) {
|
||||
this.pageNo = 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Integer getPageNo() {
|
||||
return this.pageNo;
|
||||
}
|
||||
|
||||
public void setPageNo(Integer pageNo) {
|
||||
this.pageNo = pageNo;
|
||||
}
|
||||
|
||||
public Integer getPageSize() {
|
||||
return this.pageSize;
|
||||
}
|
||||
|
||||
public void setPageSize(Integer pageSize) {
|
||||
this.pageSize = pageSize <= 0 ? 10 : pageSize;
|
||||
}
|
||||
|
||||
public List<T> getList() {
|
||||
return this.list;
|
||||
}
|
||||
|
||||
public PageInfo<T> setList(List<T> list) {
|
||||
this.list = list;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getOrderBy() {
|
||||
return this.orderBy;
|
||||
}
|
||||
|
||||
public void setOrderBy(String orderBy) {
|
||||
this.orderBy = orderBy;
|
||||
}
|
||||
|
||||
public Map<String, String> getExt() {
|
||||
return this.ext;
|
||||
}
|
||||
|
||||
public void setExt(Map<String, String> ext) {
|
||||
this.ext = ext;
|
||||
}
|
||||
|
||||
public Long getPageCount() {
|
||||
if (this.count % (long) this.pageSize != 0L) {
|
||||
this.pageCount = this.count / (long) this.pageSize + 1L;
|
||||
} else {
|
||||
this.pageCount = this.count / (long) this.pageSize;
|
||||
}
|
||||
|
||||
if (this.pageCount < 1L) {
|
||||
this.pageCount = 1L;
|
||||
}
|
||||
|
||||
return this.pageCount;
|
||||
}
|
||||
|
||||
public void setPageCount(Long pageCount) {
|
||||
this.pageCount = pageCount;
|
||||
}
|
||||
|
||||
public List<Map<String, Object>> getTitle() {
|
||||
return this.title;
|
||||
}
|
||||
|
||||
public void setTitle(List<Map<String, Object>> title) {
|
||||
this.title = title;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.adc.da.http;
|
||||
|
||||
public class ResponseMessage<T> {
|
||||
private String respCode;
|
||||
private String respMsg;
|
||||
private T data;
|
||||
private boolean ok;
|
||||
|
||||
public ResponseMessage() {
|
||||
}
|
||||
|
||||
public ResponseMessage(String respCode, String message) {
|
||||
this.respCode = respCode;
|
||||
this.respMsg = message;
|
||||
}
|
||||
|
||||
public ResponseMessage(String respCode, String message, boolean ok) {
|
||||
this.respCode = respCode;
|
||||
this.respMsg = message;
|
||||
this.ok = ok;
|
||||
}
|
||||
|
||||
public ResponseMessage(String respCode, String message, boolean ok, T data) {
|
||||
this.respCode = respCode;
|
||||
this.respMsg = message;
|
||||
this.ok = ok;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public String getRespCode() {
|
||||
return this.respCode;
|
||||
}
|
||||
|
||||
public void setRespCode(String respCode) {
|
||||
this.respCode = respCode;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return this.respMsg;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.respMsg = message;
|
||||
}
|
||||
|
||||
public T getData() {
|
||||
return this.data;
|
||||
}
|
||||
|
||||
public void setData(T data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public boolean isOk() {
|
||||
return this.ok;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.adc.da.http;
|
||||
|
||||
public enum ResponseMessageCodeEnum {
|
||||
SUCCESS("0"),
|
||||
ERROR("-1"),
|
||||
VALID_ERROR("1000"),
|
||||
SAVE_SUCCESS("r0001"),
|
||||
UPDATE_SUCCESS("r0002"),
|
||||
REMOVE_SUCCESS("r0003");
|
||||
|
||||
private String code;
|
||||
|
||||
private ResponseMessageCodeEnum(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return this.code;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.adc.da.http;
|
||||
|
||||
public class Result {
|
||||
public Result() {
|
||||
}
|
||||
|
||||
public static ResponseMessage success() {
|
||||
return new ResponseMessage(ResponseMessageCodeEnum.SUCCESS.getCode(), "", true);
|
||||
}
|
||||
|
||||
public static <T> ResponseMessage<T> success(String code, T t) {
|
||||
return new ResponseMessage(code, "", true, t);
|
||||
}
|
||||
|
||||
public static <T> ResponseMessage<T> success(String code, String message) {
|
||||
return new ResponseMessage(code, message);
|
||||
}
|
||||
|
||||
public static <T> ResponseMessage<T> success(String code, String message, T t) {
|
||||
return new ResponseMessage(code, message, true, t);
|
||||
}
|
||||
|
||||
public static <T> ResponseMessage<T> success(T t) {
|
||||
return new ResponseMessage(ResponseMessageCodeEnum.SUCCESS.getCode(), "", true, t);
|
||||
}
|
||||
|
||||
public static ResponseMessage error() {
|
||||
return error("");
|
||||
}
|
||||
|
||||
public static ResponseMessage error(String message) {
|
||||
return error(ResponseMessageCodeEnum.ERROR.getCode(), message);
|
||||
}
|
||||
|
||||
public static ResponseMessage error(String code, String message) {
|
||||
return error(code, message, (Object)null);
|
||||
}
|
||||
|
||||
public static <T> ResponseMessage<T> error(String code, String message, T t) {
|
||||
return new ResponseMessage(code, message, false, t);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.adc.da.util;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
|
||||
public static final String yyyy_MM_dd_EN = "yyyy-MM-dd";
|
||||
public static final String yyyy_MM_dd_HH_mm_ss_EN = "yyyy-MM-dd HH:mm:ss";
|
||||
public static final String yyyy_MM_dd_CN = "yyyy年MM月dd日";
|
||||
public static final String yyyy_MM_dd_HH_mm_ss_CN = "yyyy年MM月dd日HH时mm分ss秒";
|
||||
private static Map<String, DateFormat> dateFormatMap = new HashMap();
|
||||
|
||||
public DateUtils() {
|
||||
}
|
||||
|
||||
public static DateFormat getDateFormat(String formatStr) {
|
||||
DateFormat df = (DateFormat)dateFormatMap.get(formatStr);
|
||||
if (df == null) {
|
||||
df = new SimpleDateFormat(formatStr);
|
||||
dateFormatMap.put(formatStr, df);
|
||||
}
|
||||
|
||||
return (DateFormat)df;
|
||||
}
|
||||
|
||||
public static String dateToString(Date date, String dateFormatStr) {
|
||||
DateFormat format = getDateFormat(dateFormatStr);
|
||||
return date != null ? format.format(date) : null;
|
||||
}
|
||||
|
||||
public static Date stringToDate(String dateTimeStr, String dateFormatStr) {
|
||||
try {
|
||||
if (dateTimeStr != null && !dateTimeStr.equals("")) {
|
||||
DateFormat format = getDateFormat(dateFormatStr);
|
||||
Date date = format.parse(dateTimeStr);
|
||||
return date;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} catch (ParseException var4) {
|
||||
throw new RuntimeException(var4);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package com.adc.da.util;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.SecureRandom;
|
||||
|
||||
public class Digests {
|
||||
private static final String SHA1 = "SHA-1";
|
||||
private static final String MD5 = "MD5";
|
||||
private static SecureRandom random = new SecureRandom();
|
||||
|
||||
public Digests() {
|
||||
}
|
||||
|
||||
public static byte[] sha1(byte[] input) {
|
||||
return digest(input, "SHA-1", (byte[])null, 1);
|
||||
}
|
||||
|
||||
public static byte[] sha1(byte[] input, byte[] salt) {
|
||||
return digest(input, "SHA-1", salt, 1);
|
||||
}
|
||||
|
||||
public static byte[] sha1(byte[] input, byte[] salt, int iterations) {
|
||||
return digest(input, "SHA-1", salt, iterations);
|
||||
}
|
||||
|
||||
private static byte[] digest(byte[] input, String algorithm, byte[] salt, int iterations){
|
||||
|
||||
try {
|
||||
MessageDigest digest = MessageDigest.getInstance(algorithm);
|
||||
if (salt != null) {
|
||||
digest.update(salt);
|
||||
}
|
||||
|
||||
byte[] result = digest.digest(input);
|
||||
|
||||
for(int i = 1; i < iterations; ++i) {
|
||||
digest.reset();
|
||||
result = digest.digest(result);
|
||||
}
|
||||
return result;
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] generateSalt(int numBytes) {
|
||||
Validate.isTrue(numBytes > 0, "numBytes argument must be a positive integer (1 or larger)", (long)numBytes);
|
||||
byte[] bytes = new byte[numBytes];
|
||||
random.nextBytes(bytes);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public static byte[] md5(InputStream input) throws IOException {
|
||||
return digest(input, "MD5");
|
||||
}
|
||||
|
||||
public static byte[] sha1(InputStream input) throws IOException {
|
||||
return digest(input, "SHA-1");
|
||||
}
|
||||
|
||||
private static byte[] digest(InputStream input, String algorithm) throws IOException {
|
||||
try {
|
||||
MessageDigest messageDigest = MessageDigest.getInstance(algorithm);
|
||||
int bufferLength = 8192;
|
||||
byte[] buffer = new byte[bufferLength];
|
||||
|
||||
for(int read = input.read(buffer, 0, bufferLength); read > -1; read = input.read(buffer, 0, bufferLength)) {
|
||||
messageDigest.update(buffer, 0, read);
|
||||
}
|
||||
|
||||
return messageDigest.digest();
|
||||
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package com.adc.da.util;
|
||||
|
||||
import com.adc.da.exception.AdcDaBaseException;
|
||||
import org.apache.commons.codec.DecoderException;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.commons.codec.binary.Hex;
|
||||
import org.apache.commons.lang3.StringEscapeUtils;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
import java.net.URLEncoder;
|
||||
|
||||
public class Encodes {
|
||||
|
||||
private static final String DEFAULT_URL_ENCODING = "UTF-8";
|
||||
private static final char[] BASE62 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".toCharArray();
|
||||
|
||||
public Encodes() {
|
||||
}
|
||||
|
||||
public static String encodeHex(byte[] input) {
|
||||
return Hex.encodeHexString(input);
|
||||
}
|
||||
|
||||
public static byte[] decodeHex(String input) {
|
||||
|
||||
try {
|
||||
return Hex.decodeHex(input.toCharArray());
|
||||
} catch (DecoderException e) {
|
||||
throw new AdcDaBaseException(e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static String encodeBase64(byte[] input) {
|
||||
return Base64.encodeBase64String(input);
|
||||
}
|
||||
|
||||
public static String encodeUrlSafeBase64(byte[] input) {
|
||||
return Base64.encodeBase64URLSafeString(input);
|
||||
}
|
||||
|
||||
public static byte[] decodeBase64(String input) {
|
||||
return Base64.decodeBase64(input);
|
||||
}
|
||||
|
||||
public static String encodeBase62(byte[] input) {
|
||||
char[] chars = new char[input.length];
|
||||
|
||||
for(int i = 0; i < input.length; ++i) {
|
||||
chars[i] = BASE62[(input[i] & 255) % BASE62.length];
|
||||
}
|
||||
|
||||
return new String(chars);
|
||||
}
|
||||
|
||||
public static String escapeHtml(String html) {
|
||||
return StringEscapeUtils.escapeHtml4(html);
|
||||
}
|
||||
|
||||
public static String unescapeHtml(String htmlEscaped) {
|
||||
return StringEscapeUtils.unescapeHtml4(htmlEscaped);
|
||||
}
|
||||
|
||||
public static String escapeXml(String xml) {
|
||||
return StringEscapeUtils.escapeXml(xml);
|
||||
}
|
||||
|
||||
public static String unescapeXml(String xmlEscaped) {
|
||||
return StringEscapeUtils.unescapeXml(xmlEscaped);
|
||||
}
|
||||
|
||||
public static String urlEncode(String part) {
|
||||
try {
|
||||
return URLEncoder.encode(part, "UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static String urlDecode(String part) {
|
||||
try {
|
||||
return URLDecoder.decode(part, "UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,253 @@
|
||||
package com.adc.da.util;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class FileUtil extends FileUtils {
|
||||
|
||||
private static final int BUFF_SIZE = 1024;
|
||||
private static Logger log = LoggerFactory.getLogger(FileUtil.class);
|
||||
|
||||
public FileUtil() {
|
||||
}
|
||||
|
||||
public static void copyFile(String src, String target) {
|
||||
InputStream in = null;
|
||||
BufferedOutputStream out = null;
|
||||
|
||||
try {
|
||||
in = new BufferedInputStream(new FileInputStream(src));
|
||||
out = new BufferedOutputStream(new FileOutputStream(target));
|
||||
byte[] buffer = new byte[1024];
|
||||
|
||||
int len;
|
||||
while((len = in.read(buffer, 0, 1024)) > 0) {
|
||||
out.write(buffer, 0, len);
|
||||
out.flush();
|
||||
}
|
||||
} catch (IOException var9) {
|
||||
var9.printStackTrace();
|
||||
} finally {
|
||||
IOUtils.closeQuietly(in);
|
||||
IOUtils.closeQuietly(out);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static List<String> readAsStringList(String fileName) {
|
||||
List<String> list = new ArrayList();
|
||||
BufferedReader reader = null;
|
||||
FileInputStream fis = null;
|
||||
|
||||
try {
|
||||
File f = new File(fileName);
|
||||
if (f.isFile() && f.exists()) {
|
||||
fis = new FileInputStream(f);
|
||||
reader = new BufferedReader(new InputStreamReader(fis, "UTF-8"));
|
||||
|
||||
String line;
|
||||
while((line = reader.readLine()) != null) {
|
||||
if (!"".equals(line)) {
|
||||
list.add(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception var18) {
|
||||
log.error("readFile", var18);
|
||||
} finally {
|
||||
try {
|
||||
if (reader != null) {
|
||||
reader.close();
|
||||
}
|
||||
} catch (IOException var17) {
|
||||
log.error("InputStream关闭异常", var17);
|
||||
}
|
||||
|
||||
try {
|
||||
if (fis != null) {
|
||||
fis.close();
|
||||
}
|
||||
} catch (IOException var16) {
|
||||
log.error("FileInputStream关闭异常", var16);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public static byte[] readFile(File file) {
|
||||
byte[] bytes = null;
|
||||
|
||||
try {
|
||||
bytes = IOUtils.readFully(new FileInputStream(file));
|
||||
} catch (Exception var3) {
|
||||
var3.printStackTrace();
|
||||
}
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public static byte[] readFile(String fileName) {
|
||||
return readFile(new File(fileName));
|
||||
}
|
||||
|
||||
public static void writeFile(byte[] bytes, String outputFile) {
|
||||
FileOutputStream os = null;
|
||||
|
||||
try {
|
||||
os = new FileOutputStream(outputFile);
|
||||
os.write(bytes);
|
||||
} catch (Exception var7) {
|
||||
var7.printStackTrace();
|
||||
} finally {
|
||||
IOUtils.closeQuietly(os);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static File mkdir(String folderPath) {
|
||||
File file = new File(folderPath);
|
||||
if (!file.exists() || !file.isDirectory()) {
|
||||
boolean success = false;
|
||||
|
||||
do {
|
||||
success = file.mkdirs();
|
||||
} while(success);
|
||||
}
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
public static void delFolder(String folderPath) throws Exception {
|
||||
delAllFile(folderPath);
|
||||
File myFilePath = new File(folderPath);
|
||||
myFilePath.delete();
|
||||
}
|
||||
|
||||
public static boolean delAllFile(String path) throws Exception {
|
||||
boolean flag = false;
|
||||
File file = new File(path);
|
||||
if (!file.exists()) {
|
||||
return flag;
|
||||
} else if (!file.isDirectory()) {
|
||||
return flag;
|
||||
} else {
|
||||
String[] tempList = file.list();
|
||||
File temp = null;
|
||||
|
||||
for(int i = 0; i < tempList.length; ++i) {
|
||||
if (path.endsWith(File.separator)) {
|
||||
temp = new File(path + tempList[i]);
|
||||
} else {
|
||||
temp = new File(path + File.separator + tempList[i]);
|
||||
}
|
||||
|
||||
if (temp.isFile()) {
|
||||
temp.delete();
|
||||
}
|
||||
|
||||
if (temp.isDirectory()) {
|
||||
delAllFile(path + "/" + tempList[i]);
|
||||
delFolder(path + "/" + tempList[i]);
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
|
||||
return flag;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean delFile(String fileName) {
|
||||
File file = new File(fileName);
|
||||
if (!file.exists()) {
|
||||
log.info(fileName + " 文件不存在!");
|
||||
return true;
|
||||
} else {
|
||||
return file.isFile() ? deleteFile(fileName) : deleteDirectory(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean deleteFile(String fileName) {
|
||||
File file = new File(fileName);
|
||||
if (file.exists() && file.isFile()) {
|
||||
if (file.delete()) {
|
||||
log.info("删除单个文件 " + fileName + " 成功!");
|
||||
return true;
|
||||
} else {
|
||||
log.info("删除单个文件 " + fileName + " 失败!");
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
log.info(fileName + " 文件不存在!");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean deleteDirectory(String dirName) {
|
||||
String dirNames = dirName;
|
||||
if (!dirName.endsWith(File.separator)) {
|
||||
dirNames = dirName + File.separator;
|
||||
}
|
||||
|
||||
File dirFile = new File(dirNames);
|
||||
if (dirFile.exists() && dirFile.isDirectory()) {
|
||||
boolean flag = true;
|
||||
File[] files = dirFile.listFiles();
|
||||
|
||||
for(int i = 0; i < files.length; ++i) {
|
||||
if (files[i].isFile()) {
|
||||
flag = deleteFile(files[i].getAbsolutePath());
|
||||
if (!flag) {
|
||||
break;
|
||||
}
|
||||
} else if (files[i].isDirectory()) {
|
||||
flag = deleteDirectory(files[i].getAbsolutePath());
|
||||
if (!flag) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!flag) {
|
||||
log.info("删除目录失败!");
|
||||
return false;
|
||||
} else if (dirFile.delete()) {
|
||||
log.info("删除目录 " + dirName + " 成功!");
|
||||
return true;
|
||||
} else {
|
||||
log.info("删除目录 " + dirName + " 失败!");
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
log.info(dirNames + " 目录不存在!");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean exists(String path) {
|
||||
return (new File(path)).exists();
|
||||
}
|
||||
|
||||
public static void checkAndMkdirs(File file) {
|
||||
if (!file.getParentFile().exists()) {
|
||||
file.getParentFile().mkdirs();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static String getFileExtension(String fileName) {
|
||||
return fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length());
|
||||
}
|
||||
|
||||
public static String getFileName(String fileName) {
|
||||
return fileName.substring(0, fileName.lastIndexOf("."));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.adc.da.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class IOUtils extends org.apache.commons.io.IOUtils {
|
||||
|
||||
|
||||
public static byte[] readFully(InputStream is) throws IOException {
|
||||
byte[] bytes = new byte[is.available()];
|
||||
readFully(is, bytes);
|
||||
return bytes;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.adc.da.util;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
public class IpUtil {
|
||||
private IpUtil() {
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
private static boolean checkIp(String ip) {
|
||||
return ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip);
|
||||
}
|
||||
|
||||
public static String getIpAddr(HttpServletRequest request) {
|
||||
String ip = request.getHeader("X-Forwarded-For");
|
||||
if (checkIp(ip)) {
|
||||
ip = request.getHeader("Proxy-Client-IP");
|
||||
if (checkIp(ip)) {
|
||||
ip = request.getHeader("WL-Proxy-Client-IP");
|
||||
}
|
||||
|
||||
if (checkIp(ip)) {
|
||||
ip = request.getHeader("HTTP_CLIENT_IP");
|
||||
}
|
||||
|
||||
if (checkIp(ip)) {
|
||||
ip = request.getHeader("HTTP_X_FORWARDED_FOR");
|
||||
}
|
||||
|
||||
if (checkIp(ip)) {
|
||||
ip = request.getRemoteAddr();
|
||||
}
|
||||
} else if (ip.length() > 15) {
|
||||
String[] ips = ip.split(",");
|
||||
|
||||
for(int index = 0; index < ips.length; ++index) {
|
||||
String strIp = ips[index];
|
||||
if (!"unknown".equalsIgnoreCase(strIp)) {
|
||||
ip = strIp;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return StringUtils.trim(ip);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.adc.da.util;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.UnavailableSecurityManagerException;
|
||||
import org.apache.shiro.session.InvalidSessionException;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class LoginUserUtil {
|
||||
/**
|
||||
* 获取当前登录用户ID
|
||||
*
|
||||
*/
|
||||
public static String getUserId() {
|
||||
String userId = null;
|
||||
try {
|
||||
Subject subject = SecurityUtils.getSubject();
|
||||
Object object=subject.getPrincipal();
|
||||
if(object!=null){
|
||||
String json = JSONObject.toJSONString(object);
|
||||
if(json!=null && json.length()>0){
|
||||
Map<String, Object> userInfo=JSONObject.parseObject(json, Map.class);
|
||||
userId=userInfo.get("id").toString();
|
||||
}
|
||||
}
|
||||
} catch (UnavailableSecurityManagerException e) {
|
||||
} catch (InvalidSessionException e) {
|
||||
}
|
||||
return userId;
|
||||
}
|
||||
|
||||
public static String getUserParamValue() {
|
||||
String paramValue = null;
|
||||
try {
|
||||
Subject subject = SecurityUtils.getSubject();
|
||||
Object object=subject.getPrincipal();
|
||||
if(object!=null){
|
||||
String json = JSONObject.toJSONString(object);
|
||||
if(json!=null && json.length()>0){
|
||||
Map<String, Object> userInfo=JSONObject.parseObject(json, Map.class);
|
||||
paramValue=userInfo.get("paramValue").toString();
|
||||
}
|
||||
}
|
||||
} catch (UnavailableSecurityManagerException e) {
|
||||
} catch (InvalidSessionException e) {
|
||||
}
|
||||
return paramValue;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.adc.da.util;
|
||||
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 采用MD5加密解密
|
||||
* @author tfq
|
||||
* @datetime 2011-10-13
|
||||
*/
|
||||
public class MD5Util {
|
||||
|
||||
/***
|
||||
* MD5加码 生成32位md5码
|
||||
*/
|
||||
public static String string2MD5(String inStr){
|
||||
MessageDigest md5 = null;
|
||||
try{
|
||||
md5 = MessageDigest.getInstance("MD5");
|
||||
}catch (Exception e){
|
||||
System.out.println(e.toString());
|
||||
e.printStackTrace();
|
||||
return "";
|
||||
}
|
||||
char[] charArray = inStr.toCharArray();
|
||||
byte[] byteArray = new byte[charArray.length];
|
||||
|
||||
for (int i = 0; i < charArray.length; i++)
|
||||
byteArray[i] = (byte) charArray[i];
|
||||
byte[] md5Bytes = md5.digest(byteArray);
|
||||
StringBuffer hexValue = new StringBuffer();
|
||||
for (int i = 0; i < md5Bytes.length; i++){
|
||||
int val = ((int) md5Bytes[i]) & 0xff;
|
||||
if (val < 16)
|
||||
hexValue.append("0");
|
||||
hexValue.append(Integer.toHexString(val));
|
||||
}
|
||||
return hexValue.toString();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 加密解密算法 执行一次加密,两次解密
|
||||
*/
|
||||
public static String convertMD5(String inStr){
|
||||
|
||||
char[] a = inStr.toCharArray();
|
||||
for (int i = 0; i < a.length; i++){
|
||||
a[i] = (char) (a[i] ^ 't');
|
||||
}
|
||||
String s = new String(a);
|
||||
return s;
|
||||
|
||||
}
|
||||
|
||||
// 测试主函数
|
||||
public static void main(String args[]) {
|
||||
/* String s = new String("tangfuqiang");
|
||||
System.out.println("原始:" + s);
|
||||
System.out.println("MD5后:" + string2MD5(s));
|
||||
|
||||
System.out.println("加密的:" + convertMD5(s));
|
||||
|
||||
System.out.println("解密的:" + convertMD5(convertMD5(s)));*/
|
||||
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH");
|
||||
String time = df.format(new Date());
|
||||
System.out.println(time);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.adc.da.util;
|
||||
|
||||
import cn.hutool.crypto.digest.DigestAlgorithm;
|
||||
import cn.hutool.crypto.digest.Digester;
|
||||
|
||||
public class PasswordUtils {
|
||||
|
||||
public PasswordUtils() {
|
||||
}
|
||||
|
||||
public static String encryptPassword(String plainPassword) {
|
||||
byte[] salt = Digests.generateSalt(8);
|
||||
byte[] hashPassword = Digests.sha1(plainPassword.getBytes(), salt, 1024);
|
||||
return Encodes.encodeHex(salt) + Encodes.encodeHex(hashPassword);
|
||||
}
|
||||
|
||||
public static boolean validatePassword(String plainPassword, String password) {
|
||||
byte[] salt = Encodes.decodeHex(password.substring(0, 16));
|
||||
byte[] hashPassword = Digests.sha1(plainPassword.getBytes(), salt, 1024);
|
||||
return password.equals(Encodes.encodeHex(salt) + Encodes.encodeHex(hashPassword));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.adc.da.util;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
public class RequestUtils {
|
||||
public static final String LOGIN_USER = "LOGIN_USER";
|
||||
public static final String LOGIN_USER_ID = "LOGIN_USER_ID";
|
||||
public static final String LOGIN_ROLE_ID = "LOGIN_ROLE_ID";
|
||||
|
||||
private RequestUtils() {
|
||||
throw new IllegalStateException("RequestUtils");
|
||||
}
|
||||
|
||||
public static String getClientIp(HttpServletRequest request) {
|
||||
String remoteAddr = "";
|
||||
if (request != null) {
|
||||
remoteAddr = request.getHeader("X-FORWARDED-FOR");
|
||||
if (StringUtils.isEmpty(remoteAddr)) {
|
||||
remoteAddr = request.getRemoteAddr();
|
||||
}
|
||||
}
|
||||
|
||||
return remoteAddr;
|
||||
}
|
||||
|
||||
public static String getLoginUserId(HttpServletRequest request) {
|
||||
return (String)request.getSession().getAttribute("LOGIN_USER_ID");
|
||||
}
|
||||
|
||||
public static String getLoginRoleId(HttpServletRequest request) {
|
||||
return (String)request.getSession().getAttribute("LOGIN_ROLE_ID");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.adc.da.util;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class SpringContextHolder implements ApplicationContextAware {
|
||||
|
||||
|
||||
private static ApplicationContext applicationContext;
|
||||
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取applicationContext
|
||||
* @return
|
||||
*/
|
||||
public static ApplicationContext getApplicationContext() {
|
||||
return applicationContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过name获取 Bean.
|
||||
* @param name 参数传入要获取的实例的类名 首字母小写,这是默认的
|
||||
* @return
|
||||
*/
|
||||
public static Object getBean(String name){
|
||||
return getApplicationContext().getBean(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过class获取Bean.
|
||||
* @param clazz
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public static <T> T getBean(Class<T> clazz){
|
||||
return getApplicationContext().getBean(clazz);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package com.adc.da.util;
|
||||
|
||||
|
||||
|
||||
import cn.hutool.core.lang.Snowflake;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
|
||||
public class UUIDUtils {
|
||||
|
||||
public static Snowflake snowflake;
|
||||
|
||||
public static Snowflake getSnowflake() {
|
||||
return snowflake;
|
||||
}
|
||||
|
||||
/**
|
||||
* 服务编码
|
||||
*/
|
||||
private static long serverCode;
|
||||
|
||||
/**
|
||||
* 中心端编码
|
||||
*
|
||||
*/
|
||||
private static long appCenter;
|
||||
|
||||
@Value("${application.code}")
|
||||
public static void setServerCode(long serverCode) {
|
||||
UUIDUtils.serverCode = serverCode;
|
||||
}
|
||||
|
||||
@Value("${application.center}")
|
||||
public static void setAppCenter(long appCenter) {
|
||||
UUIDUtils.appCenter = appCenter;
|
||||
}
|
||||
|
||||
|
||||
public static void setSnowflake(Snowflake snowflake) {
|
||||
IdUtil.getSnowflake(serverCode,appCenter);
|
||||
}
|
||||
|
||||
public static String randomUUID10() {
|
||||
return RandomUtil.randomString(10);
|
||||
}
|
||||
|
||||
public static String randomUUID20() {
|
||||
return RandomUtil.randomString(20);
|
||||
}
|
||||
|
||||
public static String randomUUID(int length) {
|
||||
return RandomUtil.randomString(length);
|
||||
}
|
||||
|
||||
public static String randomSnowflakeID(){
|
||||
return snowflake.nextIdStr();
|
||||
}
|
||||
|
||||
|
||||
public static String getUUIDPath(String uuid){
|
||||
StringBuilder builder=new StringBuilder();
|
||||
builder.append("/");
|
||||
builder.append((uuid.substring(0, 3).hashCode())%100+"").append("/");
|
||||
builder.append((uuid.substring(7,10).hashCode())%100+"").append("/");
|
||||
builder.append((uuid.substring(11,14).hashCode())%100+"").append("/");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public static String getAttTable(){
|
||||
int nextInt = RandomUtil.randomInt(10)+1;
|
||||
StringBuilder builder=new StringBuilder();
|
||||
builder.append("ATT_FILE_").append(String.format("%02d", nextInt));
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
package com.adc.da.util;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class ValidateDatas {
|
||||
|
||||
/**
|
||||
* @param 待验证的字符串
|
||||
* @return 如果是符合邮箱格式的字符串,返回<b>true</b>,否则为<b>false</b>
|
||||
*/
|
||||
public static boolean isEmail(String str) {
|
||||
//String regex = "[a-zA-Z_]{1,}[0-9]{0,}@(([a-zA-z0-9]-*){1,}\\.){1,3}[a-zA-z\\-]{1,}";
|
||||
String regex = "([a-zA-Z0-9_-])*@([A-Za-z0-9][-A-Za-z0-9]+\\.)+(com|cn|net|org)";
|
||||
return match(regex, str);
|
||||
}
|
||||
|
||||
/**
|
||||
* 汉字和字母
|
||||
* @param str
|
||||
* @return
|
||||
*/
|
||||
public static boolean isenOrch(String str) {
|
||||
String pattern = "[\u4e00-\u9fa5A-Za-z]+";
|
||||
return match(pattern, str);
|
||||
}
|
||||
|
||||
/**
|
||||
* 汉字,字母,括号,-,下划线
|
||||
* @param str
|
||||
* @return
|
||||
*/
|
||||
public static boolean isDuty(String str) {
|
||||
String pattern = "[\u4e00-\u9fa5A-Za-z0-9_\\-\\(\\)\\(\\)]+";
|
||||
return match(pattern, str);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否是手机号
|
||||
* @param str
|
||||
* @return
|
||||
*/
|
||||
public static boolean isPhone(String str) {
|
||||
String pattern = "0?(13|14|15|18)[0-9]{9}";
|
||||
return match(pattern, str);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param regex 正则表达式字符串
|
||||
* @param str 要匹配的字符串
|
||||
* @return 如果str 符合 regex的正则表达式格式,返回true, 否则返回 false;
|
||||
*/
|
||||
private static boolean match(String regex ,String str){
|
||||
Pattern pattern = Pattern.compile(regex);
|
||||
Matcher matcher = pattern.matcher(str);
|
||||
return matcher.matches();
|
||||
}
|
||||
|
||||
public static boolean isNumber(String str) {
|
||||
String pattern = "-?[1-9]\\d*";
|
||||
return match(pattern, str);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 汉字、字母、()
|
||||
*
|
||||
* @MethodName:isLetterOrChineseOrChar1
|
||||
* @author: DuYunbao
|
||||
* @date: 2018/5/30 15:53
|
||||
*/
|
||||
public static boolean isLetterOrChineseOrChar1(String str) {
|
||||
String pattern = "^[\\u4E00-\\u9FA5A-Za-z\\(\\)]+$";
|
||||
return !str.matches(pattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* 汉字、数字、字母、()、-、下划线
|
||||
*
|
||||
* @MethodName:isChineseOrNumberOrLetterOrUnderlineOrChar
|
||||
* @author: DuYunbao
|
||||
* @date: 2018/5/30 16:45
|
||||
*/
|
||||
public static boolean isChineseOrNumberOrLetterOrUnderlineOrChar(String str) {
|
||||
String regex = "^[\\u4E00-\\u9FA5A-Za-z0-9_\\-\\(\\)]+$";
|
||||
return !str.matches(regex);
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
String aa = "9aa";
|
||||
System.out.println(isNumber(aa));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package com.adc.da.util;
|
||||
|
||||
/**
|
||||
* @Description:水印
|
||||
* @Author: yangxuenan
|
||||
* date: 2020/1/10 15:42
|
||||
*/
|
||||
public class WaterMarkUtil {
|
||||
|
||||
/**
|
||||
* @param inputFile 你的PDF文件地址
|
||||
* @param outputFile 添加水印后生成PDF存放的地址
|
||||
* @param waterMarkName 你的水印
|
||||
* @return
|
||||
*/
|
||||
public static boolean waterMark(String inputFile,
|
||||
String outputFile, String waterMarkName) {
|
||||
/* try {
|
||||
PdfReader reader = new PdfReader(inputFile);
|
||||
Field f = PdfReader.class.getDeclaredField("encrypted");
|
||||
f.setAccessible(true);
|
||||
f.set(reader, Boolean.FALSE);
|
||||
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;
|
||||
// 获得PDF最顶层
|
||||
under = stamper.getOverContent(i);
|
||||
under.saveState();
|
||||
// set Transparency
|
||||
PdfGState gs = new PdfGState();
|
||||
// 设置透明度为0.2
|
||||
gs.setFillOpacity(0.5f);
|
||||
under.setGState(gs);
|
||||
under.restoreState();
|
||||
under.beginText();
|
||||
under.setFontAndSize(base, 13);
|
||||
under.setTextMatrix(30, 30);
|
||||
under.setColorFill(BaseColor.LIGHT_GRAY);
|
||||
for (int y = 0; y < 10; y++) {
|
||||
for (int x = 0; x < 8; x++) {
|
||||
// 水印文字成45度角倾斜
|
||||
under.showTextAligned(Element.ALIGN_LEFT
|
||||
, waterMarkName, 100 + 300 * x, 300 * y, 45); }
|
||||
}
|
||||
|
||||
// 添加水印文字
|
||||
under.endText();
|
||||
under.setLineWidth(1f);
|
||||
under.stroke();
|
||||
}
|
||||
stamper.close();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}*/
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user