From 98532aace6975fceaa9eb446ebbd26d9c8603dd1 Mon Sep 17 00:00:00 2001 From: mengyxu Date: Tue, 19 Sep 2023 09:32:56 +0800 Subject: [PATCH] update --- pom.xml | 74 +++--- .../java/vip/xumy/core/conf/BaseConfiger.java | 43 ++++ .../xumy/core/exception/CoreException.java | 2 +- .../vip/xumy/core/golbal/GlobalConstant.java | 20 +- .../java/vip/xumy/core/http/HttpResult.java | 26 +- .../java/vip/xumy/core/http/HttpService.java | 230 +++++++++++++----- .../xumy/core/pojo/base/BaseCountBean.java | 8 +- .../vip/xumy/core/pojo/base/BasePage.java | 20 ++ .../xumy/core/pojo/base/BasePageParam.java | 9 +- .../vip/xumy/core/pojo/base/BasePeriod.java | 12 +- .../vip/xumy/core/pojo/base/BaseTree.java | 2 +- .../vip/xumy/core/pojo/com/BaseResponse.java | 31 +++ .../java/vip/xumy/core/pojo/com/BaseTree.java | 22 ++ .../java/vip/xumy/core/pojo/com/Cache.java | 2 +- .../java/vip/xumy/core/pojo/com/Entry.java | 5 - .../vip/xumy/core/pojo/com/PageResponse.java | 21 +- .../vip/xumy/core/promise/ExcelRowParser.java | 16 ++ .../java/vip/xumy/core/utils/ByteUtil.java | 8 +- .../java/vip/xumy/core/utils/CombineUtil.java | 55 +++++ .../java/vip/xumy/core/utils/ExcelUtil.java | 221 +++++++++++------ .../java/vip/xumy/core/utils/JsonUtil.java | 108 ++++---- .../java/vip/xumy/core/utils/StringUtil.java | 52 +++- .../java/vip/xumy/core/test/Base64Tester.java | 3 +- .../vip/xumy/core/test/ExcelUtilTester.java | 73 ++++++ .../xumy/core/test/LocationUtilTester.java | 2 +- .../vip/xumy/core/test/RSAUtilTester.java | 2 +- src/test/java/vip/xumy/core/test/Tester.java | 16 +- 27 files changed, 803 insertions(+), 280 deletions(-) create mode 100644 src/main/java/vip/xumy/core/conf/BaseConfiger.java create mode 100644 src/main/java/vip/xumy/core/pojo/base/BasePage.java create mode 100644 src/main/java/vip/xumy/core/pojo/com/BaseResponse.java create mode 100644 src/main/java/vip/xumy/core/pojo/com/BaseTree.java create mode 100644 src/main/java/vip/xumy/core/promise/ExcelRowParser.java create mode 100644 src/main/java/vip/xumy/core/utils/CombineUtil.java create mode 100644 src/test/java/vip/xumy/core/test/ExcelUtilTester.java diff --git a/pom.xml b/pom.xml index acfff5b..ce0399e 100644 --- a/pom.xml +++ b/pom.xml @@ -1,25 +1,27 @@ - + 4.0.0 org.springframework.boot spring-boot-starter-parent - 2.0.2.RELEASE + 2.7.1 vip.xumy.core xumy_core - 0.0.1 + 1.0.0 xumy_core xumy_core jar - + + 17 UTF-8 UTF-8 - 1.3.2 - 1.2.17 - 1.2.46 + + + 2.9.2 + 1.6.9 + 1.66 + 4.0.1 2.0.0 @@ -29,40 +31,40 @@ org.springframework.boot spring-boot-starter-web - - - org.springframework.boot - spring-boot-starter-logging - - - + + - org.springframework.boot - spring-boot-starter-log4j2 + org.springdoc + springdoc-openapi-ui + ${springdoc.version} - + + - org.springframework.boot - spring-boot-starter-test + org.junit.jupiter + junit-jupiter-api test + + + + org.apache.httpcomponents + httpclient + + org.projectlombok lombok - + - com.alibaba - fastjson - ${fastjson.version} - - - - org.apache.httpcomponents - httpclient + org.bouncycastle + bcprov-jdk15to18 + ${bouncycastle.version} + org.apache.poi @@ -70,12 +72,12 @@ ${apache.poi.version} - - org.dom4j - dom4j - ${dom4j.version} - - + + org.dom4j + dom4j + ${dom4j.version} + + \ No newline at end of file diff --git a/src/main/java/vip/xumy/core/conf/BaseConfiger.java b/src/main/java/vip/xumy/core/conf/BaseConfiger.java new file mode 100644 index 0000000..9e62492 --- /dev/null +++ b/src/main/java/vip/xumy/core/conf/BaseConfiger.java @@ -0,0 +1,43 @@ +package vip.xumy.core.conf; + +import java.util.Collections; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; + +/** + * Ownership belongs to the company + * + * @author:mengyxu + * @date:2022年9月29日 + */ + +@Configuration +public class BaseConfiger { + + /** + * 允许跨域请求 + * + * @return + */ + @Bean + public CorsFilter corsFilter() { + CorsConfiguration corsConfiguration = new CorsConfiguration(); + // 1,允许任何来源 + corsConfiguration.setAllowedOriginPatterns(Collections.singletonList("*")); + // 2,允许任何请求头 + corsConfiguration.addAllowedHeader(CorsConfiguration.ALL); + // 3,允许任何方法 + corsConfiguration.addAllowedMethod(CorsConfiguration.ALL); + // 4,允许凭证 + corsConfiguration.setAllowCredentials(true); + + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", corsConfiguration); + return new CorsFilter(source); + } + +} diff --git a/src/main/java/vip/xumy/core/exception/CoreException.java b/src/main/java/vip/xumy/core/exception/CoreException.java index f564a1c..5f03029 100644 --- a/src/main/java/vip/xumy/core/exception/CoreException.java +++ b/src/main/java/vip/xumy/core/exception/CoreException.java @@ -3,7 +3,7 @@ package vip.xumy.core.exception; import lombok.Getter; @Getter -public class CoreException extends Exception{ +public class CoreException extends RuntimeException{ private static final long serialVersionUID = 1L; private String errCode; diff --git a/src/main/java/vip/xumy/core/golbal/GlobalConstant.java b/src/main/java/vip/xumy/core/golbal/GlobalConstant.java index 7e0cb99..d7e52ec 100644 --- a/src/main/java/vip/xumy/core/golbal/GlobalConstant.java +++ b/src/main/java/vip/xumy/core/golbal/GlobalConstant.java @@ -9,27 +9,29 @@ import org.springframework.util.DigestUtils; @Component public class GlobalConstant { - + public static String RESOURCES_ROOT_PATH; public static String FILE_DOWNLOAD_PATH; - + public static final String DEFAULT_PASSWORD = DigestUtils.md5DigestAsHex("888888".getBytes()); public static final String CODE_KEY_PREFIX = "login-code-"; public static final String TIKEN_KEY_PREFIX = "login-token-"; public static final String LOGIN_COOKIE_NAME = "UMLoginToken"; - + public static final String ENCODING_UTF8 = "UTF-8"; - + public static final Integer DEF_SIZE = 20; + public static final Integer MAX_SIZE = 500; + @Value("${service.package.type:war}") public void setPackageType(String type) { - if("jar".equals(type)) { + if ("jar".equals(type)) { ApplicationHome h = new ApplicationHome(GlobalConstant.class); - File jarF = h.getSource(); - RESOURCES_ROOT_PATH = jarF.getParentFile().toString(); - }else { + File jarF = h.getSource(); + RESOURCES_ROOT_PATH = jarF.getParentFile().toString(); + } else { RESOURCES_ROOT_PATH = GlobalConstant.class.getClassLoader().getResource("").getPath(); } FILE_DOWNLOAD_PATH = RESOURCES_ROOT_PATH + "/file/"; } - + } diff --git a/src/main/java/vip/xumy/core/http/HttpResult.java b/src/main/java/vip/xumy/core/http/HttpResult.java index 0e0e0b8..fedc937 100644 --- a/src/main/java/vip/xumy/core/http/HttpResult.java +++ b/src/main/java/vip/xumy/core/http/HttpResult.java @@ -1,11 +1,12 @@ package vip.xumy.core.http; +import java.util.Map; + import lombok.Getter; import lombok.Setter; -/** All rights reserved - * author:mengyxu - * date:2019年5月25日 +/** + * Ownership belongs to the company author:mengyxu date:2019年5月25日 */ @Setter @@ -18,10 +19,29 @@ public class HttpResult { // 响应的响应体 private String body; + private Map cookies; + + private String contentType; + + public HttpResult() { + super(); + } + public HttpResult(int code, String body) { super(); this.code = code; this.body = body; } + public HttpResult(int code, String body, String contentType) { + super(); + this.code = code; + this.body = body; + this.contentType = contentType; + } + + public boolean isJson() { + return "application/json".equals(contentType); + } + } diff --git a/src/main/java/vip/xumy/core/http/HttpService.java b/src/main/java/vip/xumy/core/http/HttpService.java index 0379e87..01bc157 100644 --- a/src/main/java/vip/xumy/core/http/HttpService.java +++ b/src/main/java/vip/xumy/core/http/HttpService.java @@ -1,33 +1,42 @@ package vip.xumy.core.http; import java.io.IOException; +import java.security.cert.CertificateException; +import java.security.cert.X509Certificate; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; +import javax.net.ssl.SSLContext; +import javax.net.ssl.TrustManager; +import javax.net.ssl.X509TrustManager; + +import org.apache.http.Header; import org.apache.http.NameValuePair; -import org.apache.http.client.CookieStore; import org.apache.http.client.config.RequestConfig; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; +import org.apache.http.client.methods.HttpPut; import org.apache.http.client.utils.URIBuilder; +import org.apache.http.conn.ssl.NoopHostnameVerifier; +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.BasicCookieStore; -import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; import org.apache.http.impl.cookie.BasicClientCookie; +import org.apache.http.message.BasicHeader; import org.apache.http.message.BasicNameValuePair; import org.apache.http.util.EntityUtils; import lombok.extern.log4j.Log4j2; -/** All rights reserved - * author:mengyxu - * date:2019年5月25日 +/** + * Ownership belongs to the company author:mengyxu date:2019年5月25日 */ @Log4j2 @@ -37,37 +46,40 @@ public class HttpService { private static final PoolingHttpClientConnectionManager cm; - private static final RequestConfig config; - - private static CookieStore cookieStore = new BasicCookieStore(); + private static RequestConfig config; - static{ + static { cm = new PoolingHttpClientConnectionManager(); cm.setMaxTotal(200); cm.setDefaultMaxPerRoute(20); - config = RequestConfig.custom().setConnectTimeout(100000) - .setConnectionRequestTimeout(50000).setSocketTimeout(100000) - .setStaleConnectionCheckEnabled(true).build(); + config = RequestConfig.custom().setConnectTimeout(100000).setConnectionRequestTimeout(50000) + .setSocketTimeout(100000).setStaleConnectionCheckEnabled(true).build(); + } + + public static void setRedirectsEnabled(boolean enable) { + config = RequestConfig.custom().setConnectTimeout(100000).setConnectionRequestTimeout(50000) + .setSocketTimeout(100000).setRedirectsEnabled(enable).setStaleConnectionCheckEnabled(true).build(); } - + /** - * 设置请求所携带cookie + * 创建请求所携带cookie + * * @param cookies */ - public static void setCookies(Map cookies) { - cookieStore = new BasicCookieStore(); - if(cookies != null) { + public static BasicCookieStore createCookies(Map cookies, String domain) { + BasicCookieStore cookieStore = new BasicCookieStore(); + if (cookies != null) { for (String key : cookies.keySet()) { String value = cookies.get(key); BasicClientCookie clientCookie = new BasicClientCookie(key, value); clientCookie.setVersion(0); clientCookie.setSecure(false); - clientCookie.setDomain("."); - clientCookie.setPath("/"); + clientCookie.setDomain(domain); cookieStore.addCookie(clientCookie); } } + return cookieStore; } /** @@ -77,7 +89,7 @@ public class HttpService { * @param map * @return */ - public static HttpResult doGet(String url, Map param) { + public static HttpResult doGet(String url, Map param, BasicCookieStore cookieStore) { try { // 1.创建URIBuilder URIBuilder uriBuilder = new URIBuilder(url); @@ -90,42 +102,77 @@ public class HttpService { uriBuilder.setParameter(entry.getKey(), entry.getValue().toString()); } } - + // 3.创建请求对象httpGet HttpGet httpGet = new HttpGet(uriBuilder.build()); httpGet.setConfig(config); // 4.使用httpClient发起请求 - CloseableHttpResponse response = HttpClients.custom().setDefaultCookieStore(cookieStore).setConnectionManager(cm).build() - .execute(httpGet); - + CloseableHttpResponse response = HttpClients.custom().setDefaultCookieStore(cookieStore) + .setConnectionManager(cm).build().execute(httpGet); + Header[] allHeaders = httpGet.getAllHeaders(); // 5.解析返回结果,封装返回对象httpResult return getResult(response); } catch (Exception e) { - log.error("http request failed",e); - return new HttpResult(500, "http request failed"); + e.printStackTrace(); + log.error("http request failed", e); + return new HttpResult(400, "http request failed"); } } - /** - * 不带参数的get - * - * @param url - * @return - */ public static HttpResult doGet(String url) { - return doGet(url, null); + return doGet(url, null, null); + } + + public static HttpResult doGet(String url, BasicCookieStore cookieStore) { + return doGet(url, null, cookieStore); + } + + public static HttpResult doPut(String url, Map param, BasicCookieStore cookieStore) { + try { + // 1.创建URIBuilder + URIBuilder uriBuilder = new URIBuilder(url); + + // 2.设置请求参数 + if (param != null) { + // 遍历请求参数 + for (Map.Entry entry : param.entrySet()) { + // 封装请求参数 + uriBuilder.setParameter(entry.getKey(), entry.getValue().toString()); + } + } + + // 3.创建请求对象httpGet + HttpPut httpPut = new HttpPut(uriBuilder.build()); + httpPut.setConfig(config); + // 4.使用httpClient发起请求 + CloseableHttpResponse response = HttpClients.custom().setDefaultCookieStore(cookieStore) + .setConnectionManager(cm).build().execute(httpPut); + Header[] allHeaders = httpPut.getAllHeaders(); + // 5.解析返回结果,封装返回对象httpResult + return getResult(response); + } catch (Exception e) { + e.printStackTrace(); + log.error("http request failed", e); + return new HttpResult(400, "http request failed"); + } + } + + public static HttpResult doPut(String url) { + return doPut(url, null, null); + } + + public static HttpResult doPut(String url, BasicCookieStore cookieStore) { + return doPut(url, null, cookieStore); } - /** * 带参数的post请求 * * @param url * @param map - * @return - * @ + * @return @ */ - public static HttpResult doPost(String url, Map param) { + public static HttpResult doPost(String url, Map param, BasicCookieStore cookieStore) { try { // 1. 声明httppost HttpPost httpPost = new HttpPost(url); @@ -148,25 +195,24 @@ public class HttpService { // 3. 把封装好的表单实体对象设置到HttpPost对象 httpPost.setEntity(entity); } - + // 4. 使用Httpclient发起请求 - CloseableHttpResponse response = HttpClients.custom().setDefaultCookieStore(cookieStore).setConnectionManager(cm).build() - .execute(httpPost); + CloseableHttpResponse response = HttpClients.custom().setDefaultCookieStore(cookieStore) + .setConnectionManager(cm).build().execute(httpPost); return getResult(response); } catch (Exception e) { - log.error("http request failed",e); - return new HttpResult(500, "http request failed"); + log.error("http request failed", e); + return new HttpResult(400, "http request failed"); } } - + /** * json格式参数的post请求 * - * @param url 请求地址 + * @param url 请求地址 * @param params json格式参数 - * @return - * @ + * @return @ */ public static HttpResult postWithJson(String url, String params, Map headers) { try { @@ -177,36 +223,106 @@ public class HttpService { String charSet = "UTF-8"; StringEntity entity = new StringEntity(params, charSet); httpPost.setEntity(entity); - - //设置http请求头 - if(headers != null) { + + // 设置http请求头 + if (headers != null) { for (String key : headers.keySet()) { httpPost.setHeader(key, headers.get(key)); } } - + // 4. 使用Httpclient发起请求 CloseableHttpResponse response = HttpClients.custom().setConnectionManager(cm).build().execute(httpPost); // 5. 解析返回数据,封装HttpResult return getResult(response); } catch (Exception e) { - log.error("http request failed",e); - return new HttpResult(500, "http request failed"); + log.error("http request failed", e); + return new HttpResult(400, "http request failed"); } } + public static HttpResult postHttps(String url, String data) throws Exception { + return postHttps(url, data, null); + } + + public static HttpResult postHttps(String url, String data, Map headers) throws Exception { + try { + HttpPost httpPost = new HttpPost(url); + httpPost.addHeader("Content-Type", "application/json"); + if (headers != null) { + for (String key : headers.keySet()) { + httpPost.addHeader(key, headers.get(key)); + } + } + StringEntity se = new StringEntity(data); + se.setContentType("text/json"); + se.setContentEncoding(new BasicHeader("Content-Type", "application/json")); + httpPost.setEntity(se); + CloseableHttpResponse response = httpClientTrustingAllSSLCerts().build().execute(httpPost); + // 5. 解析返回数据,封装HttpResult + return getResult(response); + } catch (Exception e) { + log.error("http request failed", e); + return new HttpResult(400, "http request failed"); + } + + } + + private static HttpClientBuilder httpClientTrustingAllSSLCerts() throws Exception { + TrustManager[] trustAllCertificates = new TrustManager[] { new X509TrustManager() { + @Override + public X509Certificate[] getAcceptedIssuers() { + return null; // Not relevant. + } + + @Override + public void checkClientTrusted(X509Certificate[] arg0, String arg1) throws CertificateException { + } + + @Override + public void checkServerTrusted(X509Certificate[] arg0, String arg1) throws CertificateException { + } + } }; + SSLContext sc = SSLContext.getInstance("SSL"); + sc.init(null, trustAllCertificates, new java.security.SecureRandom()); + SSLConnectionSocketFactory scsf = new SSLConnectionSocketFactory(sc, NoopHostnameVerifier.INSTANCE); + return HttpClients.custom().setSSLSocketFactory(scsf); + } + private static HttpResult getResult(CloseableHttpResponse response) throws IOException { // 状态码 int code = response.getStatusLine().getStatusCode(); // 响应体内容 String body = null; + String contentType = null; if (response.getEntity() != null) { body = EntityUtils.toString(response.getEntity(), ENCODING_UTF8); } + Header[] types = response.getHeaders("content-type"); + if (types != null && types.length > 0) { + contentType = types[0].getValue(); + } + HttpResult httpResult = new HttpResult(code, body, contentType); - return new HttpResult(code, body); + // cookie + Header[] headers = response.getHeaders("Set-Cookie"); + if (headers != null && headers.length > 0) { + Map cookies = new HashMap<>(); + for (Header header : headers) { + String[] arr = header.getValue().split(";"); + for (String cookie : arr) { + int index = cookie.indexOf("="); + if (index != -1) { + cookies.put(cookie.substring(0, index), cookie.substring(index + 1)); + } + } + } + httpResult.setCookies(cookies); + } + + return httpResult; } /** @@ -216,20 +332,20 @@ public class HttpService { * @return */ public static HttpResult doPost(String url) { - return doPost(url, null); + return doPost(url, null, null); } - public static void doPostAsync(final String url, final Map param){ + public static void doPostAsync(final String url, final Map param) { new Thread(new Runnable() { @Override public void run() { try { - doPost(url, param); + doPost(url, param, null); } catch (Exception e) { e.printStackTrace(); } } }).start(); } - + } diff --git a/src/main/java/vip/xumy/core/pojo/base/BaseCountBean.java b/src/main/java/vip/xumy/core/pojo/base/BaseCountBean.java index 58bb38f..0375e75 100644 --- a/src/main/java/vip/xumy/core/pojo/base/BaseCountBean.java +++ b/src/main/java/vip/xumy/core/pojo/base/BaseCountBean.java @@ -3,7 +3,7 @@ package vip.xumy.core.pojo.base; import lombok.Getter; import lombok.Setter; -/** All rights reserved +/** Ownership belongs to the company * author:mengyxu * date:2019年5月10日 */ @@ -12,7 +12,9 @@ import lombok.Setter; @Getter public class BaseCountBean { - private long total; - private long disTotal; + private Integer id; + private String name; + private Long total; + private Long disTotal; } diff --git a/src/main/java/vip/xumy/core/pojo/base/BasePage.java b/src/main/java/vip/xumy/core/pojo/base/BasePage.java new file mode 100644 index 0000000..d354f9e --- /dev/null +++ b/src/main/java/vip/xumy/core/pojo/base/BasePage.java @@ -0,0 +1,20 @@ +package vip.xumy.core.pojo.base; + +import lombok.Getter; +import lombok.Setter; + +/** + * Ownership belongs to the company + * + * @author:mengyxu + * @date:2022年7月21日 + */ + +@Setter +@Getter +public class BasePage { + + private Integer page; + private Integer size; + +} diff --git a/src/main/java/vip/xumy/core/pojo/base/BasePageParam.java b/src/main/java/vip/xumy/core/pojo/base/BasePageParam.java index 02fd790..b4d107c 100644 --- a/src/main/java/vip/xumy/core/pojo/base/BasePageParam.java +++ b/src/main/java/vip/xumy/core/pojo/base/BasePageParam.java @@ -1,6 +1,7 @@ package vip.xumy.core.pojo.base; -import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonIgnore; + import lombok.Getter; import lombok.Setter; @@ -13,11 +14,11 @@ import lombok.Setter; @Getter public class BasePageParam extends BasePojo { - @JSONField(serialize=false) + @JsonIgnore private Integer page; - @JSONField(serialize=false) + @JsonIgnore private Integer size; - @JSONField(serialize=false) + @JsonIgnore private Integer limitStart; } diff --git a/src/main/java/vip/xumy/core/pojo/base/BasePeriod.java b/src/main/java/vip/xumy/core/pojo/base/BasePeriod.java index e336e8b..75f9dbc 100644 --- a/src/main/java/vip/xumy/core/pojo/base/BasePeriod.java +++ b/src/main/java/vip/xumy/core/pojo/base/BasePeriod.java @@ -3,15 +3,17 @@ package vip.xumy.core.pojo.base; import lombok.Getter; import lombok.Setter; -/** All rights reserved - * author:mengyxu - * date:2019年12月24日 +/** + * Ownership belongs to the company + * + * @author:mengyxu + * @date:2022年7月21日 */ @Setter @Getter -public class BasePeriod extends BasePageParam { - +public class BasePeriod extends BasePage { + private String startTime; private String endTime; diff --git a/src/main/java/vip/xumy/core/pojo/base/BaseTree.java b/src/main/java/vip/xumy/core/pojo/base/BaseTree.java index 175a5da..a217cbd 100644 --- a/src/main/java/vip/xumy/core/pojo/base/BaseTree.java +++ b/src/main/java/vip/xumy/core/pojo/base/BaseTree.java @@ -5,7 +5,7 @@ import java.util.List; import lombok.Getter; import lombok.Setter; -/** All rights reserved +/** Ownership belongs to the company * author:mengyxu * date:2019年10月17日 */ diff --git a/src/main/java/vip/xumy/core/pojo/com/BaseResponse.java b/src/main/java/vip/xumy/core/pojo/com/BaseResponse.java new file mode 100644 index 0000000..c606983 --- /dev/null +++ b/src/main/java/vip/xumy/core/pojo/com/BaseResponse.java @@ -0,0 +1,31 @@ +package vip.xumy.core.pojo.com; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Getter; + +@Getter +@Schema(description = "返回消息通用格式") +public class BaseResponse { + @Schema(description = "请求是否成功") + private boolean success; + @Schema(description = "结果提示信息") + private String message; + @Schema(description = "具体数据") + private Object data; + + public BaseResponse(T data) { + this.success = true; + this.data = data; + } + + public BaseResponse(boolean success, String message) { + this.success = success; + this.message = message; + } + + public BaseResponse() { + super(); + this.success = true; + } + +} diff --git a/src/main/java/vip/xumy/core/pojo/com/BaseTree.java b/src/main/java/vip/xumy/core/pojo/com/BaseTree.java new file mode 100644 index 0000000..d985261 --- /dev/null +++ b/src/main/java/vip/xumy/core/pojo/com/BaseTree.java @@ -0,0 +1,22 @@ +package vip.xumy.core.pojo.com; + +import java.util.List; + +import lombok.Getter; +import lombok.Setter; + +/** Ownership belongs to the company + * + * @author:mengyxu + * @date:2022年12月9日 + */ + +@Setter +@Getter +public class BaseTree { + + private Integer id; + private String name; + private List children; + +} diff --git a/src/main/java/vip/xumy/core/pojo/com/Cache.java b/src/main/java/vip/xumy/core/pojo/com/Cache.java index 45bccad..1bc03b3 100644 --- a/src/main/java/vip/xumy/core/pojo/com/Cache.java +++ b/src/main/java/vip/xumy/core/pojo/com/Cache.java @@ -4,7 +4,7 @@ import java.util.Date; import vip.xumy.core.utils.DateUtil; -/** All rights reserved +/** Ownership belongs to the company * author:mengyxu * date:2019年6月26日 */ diff --git a/src/main/java/vip/xumy/core/pojo/com/Entry.java b/src/main/java/vip/xumy/core/pojo/com/Entry.java index 397599f..585b786 100644 --- a/src/main/java/vip/xumy/core/pojo/com/Entry.java +++ b/src/main/java/vip/xumy/core/pojo/com/Entry.java @@ -4,11 +4,6 @@ import java.io.Serializable; import lombok.Data; -/** All rights reserved - * author:mengyxu - * date:2019年6月26日 - */ - @Data public class Entry implements Serializable{ private static final long serialVersionUID = 8389699482773678138L; diff --git a/src/main/java/vip/xumy/core/pojo/com/PageResponse.java b/src/main/java/vip/xumy/core/pojo/com/PageResponse.java index c79dd03..44abca5 100644 --- a/src/main/java/vip/xumy/core/pojo/com/PageResponse.java +++ b/src/main/java/vip/xumy/core/pojo/com/PageResponse.java @@ -2,17 +2,22 @@ package vip.xumy.core.pojo.com; import java.util.List; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Getter; import lombok.Setter; -/** All rights reserved - * author:mengyxu - * date:2019年6月26日 - */ - @Setter @Getter -public class PageResponse{ - private List rows; // 每页记录集合 - private Long total; +@Schema(description = "分页查询返回格式") +public class PageResponse { + @Schema(description = "数据总条数") + private long total; + @Schema(description = "返回数据") + private List data; + + public PageResponse(List list, long total) { + this.total = total; + data = list; + } + } \ No newline at end of file diff --git a/src/main/java/vip/xumy/core/promise/ExcelRowParser.java b/src/main/java/vip/xumy/core/promise/ExcelRowParser.java new file mode 100644 index 0000000..29096df --- /dev/null +++ b/src/main/java/vip/xumy/core/promise/ExcelRowParser.java @@ -0,0 +1,16 @@ +package vip.xumy.core.promise; + +import org.apache.poi.ss.usermodel.Row; + +/** + * Ownership belongs to the company + * + * @author:mengyxu + * @date:2023年3月20日 + */ + +public interface ExcelRowParser { + + void parse(Row row, int index); + +} diff --git a/src/main/java/vip/xumy/core/utils/ByteUtil.java b/src/main/java/vip/xumy/core/utils/ByteUtil.java index 24335db..ab680f8 100644 --- a/src/main/java/vip/xumy/core/utils/ByteUtil.java +++ b/src/main/java/vip/xumy/core/utils/ByteUtil.java @@ -165,7 +165,7 @@ public class ByteUtil { int temp = (int) ch; // byte[] b = new byte[2]; for (int i = 0; i < 2; i ++ ) { - bb[index + i] = new Integer(temp & 0xff).byteValue(); // 将最高位保存在最低位 + bb[index + i] = Integer.valueOf(temp & 0xff).byteValue(); // 将最高位保存在最低位 temp = temp >> 8; // 向右移8位 } } @@ -173,7 +173,7 @@ public class ByteUtil { int temp = (int) ch; // byte[] b = new byte[2]; for (int i = 1; i >=0; i -- ) { - bb[index + i] = new Integer(temp & 0xff).byteValue(); // 将最高位保存在最低位 + bb[index + i] = Integer.valueOf(temp & 0xff).byteValue(); // 将最高位保存在最低位 temp = temp >> 8; // 向右移8位 } } @@ -209,7 +209,7 @@ public class ByteUtil { // byte[] b = new byte[4]; int l = Float.floatToIntBits(x); for (int i = 0; i < 4; i++) { - bb[index + i] = new Integer(l).byteValue(); + bb[index + i] = Integer.valueOf(l).byteValue(); l = l >> 8; } } @@ -244,7 +244,7 @@ public class ByteUtil { // byte[] b = new byte[8]; long l = Double.doubleToLongBits(x); for (int i = 0; i < 4; i++) { - bb[index + i] = new Long(l).byteValue(); + bb[index + i] = Long.valueOf(l).byteValue(); l = l >> 8; } } diff --git a/src/main/java/vip/xumy/core/utils/CombineUtil.java b/src/main/java/vip/xumy/core/utils/CombineUtil.java new file mode 100644 index 0000000..b2f192f --- /dev/null +++ b/src/main/java/vip/xumy/core/utils/CombineUtil.java @@ -0,0 +1,55 @@ +package vip.xumy.core.utils; + +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.Deque; +import java.util.List; + +/** + * Ownership belongs to the company + * + * @author:mengyxu + * @date:2023年3月9日 + */ + +public class CombineUtil { + + public static List> combine(int n) { + List> res = new ArrayList<>(); + for (int i = n; i > 0; i--) { + Deque path = new ArrayDeque<>(); + dfs(n, i, 1, path, res); + } + return res; + } + + public static List> combine(int n, int k) { + List> res = new ArrayList<>(); + if (k <= 0 || n < k) { + return res; + } + // 从 1 开始是题目的设定 + Deque path = new ArrayDeque<>(); + dfs(n, k, 1, path, res); + return res; + } + + private static void dfs(int n, int k, int begin, Deque path, List> res) { + // 递归终止条件是:path 的长度等于 k + if (path.size() == k) { + res.add(new ArrayList<>(path)); + return; + } + + // 遍历可能的搜索起点 + for (int i = begin; i <= n; i++) { + // 向路径变量里添加一个数 + path.addLast(i); + // 下一轮搜索,设置的搜索起点要加 1,因为组合数理不允许出现重复的元素 + dfs(n, k, i + 1, path, res); + // 重点理解这里:深度优先遍历有回头的过程,因此递归之前做了什么,递归之后需要做相同操作的逆向操作 + path.removeLast(); + } + } + +} diff --git a/src/main/java/vip/xumy/core/utils/ExcelUtil.java b/src/main/java/vip/xumy/core/utils/ExcelUtil.java index cc885b6..5dfee7f 100644 --- a/src/main/java/vip/xumy/core/utils/ExcelUtil.java +++ b/src/main/java/vip/xumy/core/utils/ExcelUtil.java @@ -21,43 +21,43 @@ import org.springframework.web.multipart.MultipartFile; import lombok.extern.log4j.Log4j2; import vip.xumy.core.exception.CoreException; import vip.xumy.core.promise.ExcelParser; +import vip.xumy.core.promise.ExcelRowParser; -/** All rights reserved - * author:mengyxu - * date:2019年11月22日 +/** + * All rights reserved author:mengyxu date:2019年11月22日 */ @Log4j2 @SuppressWarnings("all") public class ExcelUtil { - - + /** - * 将数据转换为Excel表格,并将Excel表格转为字节数组返回 - * @param template 模版路径 - * @param data 源数据 - * @param parser 数据转换工具 + * 将数据转换为Excel表格,并将Excel表格转为字节数组返回 + * + * @param template 模版路径 + * @param data 源数据 + * @param parser 数据转换工具 * @return * @throws CoreException */ - public static byte[] parseToExcelByteArray(String template, List data, ExcelParser parser) throws CoreException { + public static byte[] parseToExcelByteArray(String template, List data, ExcelParser parser) + throws CoreException { Workbook book = parserToExcel(template, data, parser); - try( - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - ) { - book.write(bos); - return bos.toByteArray(); + try (ByteArrayOutputStream bos = new ByteArrayOutputStream();) { + book.write(bos); + return bos.toByteArray(); } catch (IOException e) { - log.error("将Excel转为字节数组失败",e); + log.error("将Excel转为字节数组失败", e); throw new CoreException("将Excel转为字节数组失败"); } } - + /** - * 将数据转换为Excel表格并返回 - * @param template 模版路径 - * @param data 源数据 - * @param parser 数据转换工具 + * 将数据转换为Excel表格并返回 + * + * @param template 模版路径 + * @param data 源数据 + * @param parser 数据转换工具 * @return * @throws CoreException */ @@ -76,97 +76,174 @@ public class ExcelUtil { } return book; } - + private static HSSFWorkbook loadTemplate(String template) { File file = new File(template); - if(file.exists()) { + if (file.exists()) { try { return new HSSFWorkbook(new POIFSFileSystem(new FileInputStream(file))); } catch (IOException e) { - log.warn("读取Excel模版失败:"+template,e); + log.warn("读取Excel模版失败:" + template, e); } } return new HSSFWorkbook(); } - - public static List readExcelAsBeanList(MultipartFile file, ExcelParser parser) throws CoreException{ + + public static List readExcelAsBeanList(MultipartFile file, ExcelParser parser) throws CoreException { return readExcelAsBeanList(file, parser, null); } - - public static List readExcelAsBeanList(MultipartFile file, ExcelParser parser, Object param) throws CoreException{ + + public static List readExcelAsBeanList(MultipartFile file, ExcelParser parser, Object param) + throws CoreException { List list = readExcel(file); - return parser.parseToObj(list,param); + return parser.parseToObj(list, param); } - - public static List readExcel(MultipartFile file) throws CoreException{ + + /** + * 读取整个excel + * + * @param file + * @return + * @throws CoreException + */ + public static List readExcel(MultipartFile file) throws CoreException { Workbook book = loadExcel(file); Sheet sheet = book.getSheetAt(0); - if(sheet == null || sheet.getLastRowNum() < 1) { + if (sheet == null || sheet.getLastRowNum() < 1) { return null; } int rowLen = sheet.getLastRowNum(); List list = new ArrayList<>(); for (int i = 1; i <= rowLen; i++) { Row row = sheet.getRow(i); - if(row == null) { - continue; + String[] arr = readRow(row); + if (arr != null || arr.length > 0) { + list.add(arr); } - short cellLen = row.getLastCellNum(); - if(cellLen <= 0) { + } + return list; + } + + /** + * 遍历excel + * + * @param book + * @param parser + */ + public static void traverseExcel(Workbook book, ExcelRowParser parser) { + int sheetLen = book.getActiveSheetIndex(); + for (int i = 0; i < sheetLen; i++) { + Sheet sheet = book.getSheetAt(0); + if (sheet == null || sheet.getLastRowNum() < 1) { continue; } - String[] arr = new String[cellLen]; - for (int j = 0; j < cellLen; j++) { - Cell cell = row.getCell(j); - if(cell != null) { - cell.setCellType(CellType.STRING); - arr[j] = cell.getStringCellValue(); - } + int rowLen = sheet.getLastRowNum(); + List list = new ArrayList<>(); + for (int j = 1; j <= rowLen; j++) { + Row row = sheet.getRow(j); + parser.parse(row, j); } - if(StringUtil.isAllEmpty(arr)) { - continue; + } + } + + /** + * 读取单行Excel + * + * @param row + * @return + */ + public static String[] readRow(Row row) { + if (row == null) { + return null; + } + short cellLen = row.getLastCellNum(); + if (cellLen <= 0) { + return null; + } + String[] arr = new String[cellLen]; + for (int j = 0; j < cellLen; j++) { + Cell cell = row.getCell(j); + if (cell != null) { + cell.setCellType(CellType.STRING); + arr[j] = cell.getStringCellValue(); } - list.add(arr); } - return list; + if (StringUtil.isAllEmpty(arr)) { + return null; + } + return arr; } - - public static Workbook loadExcel(MultipartFile file) throws CoreException{ + + /** + * 加载表单提交excel文件 + * + * @param file + * @return + * @throws CoreException + */ + public static Workbook loadExcel(MultipartFile file) throws CoreException { Workbook book = null; try { InputStream is = file.getInputStream(); String name = file.getOriginalFilename(); - if(isExcel2003(name)) { + if (isExcel2003(name)) { book = new HSSFWorkbook(is); - }else if(isExcel2007(name)){ + } else if (isExcel2007(name)) { book = new XSSFWorkbook(is); } } catch (Exception e) { - log.error("读取Excel失败",e); - throw new CoreException("导入失败,读取文件出错!",e); + log.error("读取Excel失败", e); + throw new CoreException("导入失败,读取文件出错!", e); } - if(book == null) { + if (book == null) { throw new CoreException("导入失败,不支持的文件类型!"); } return book; } - - /*** - * - * @param 判断文件类型是不是2003版本 - * @return - */ - public static boolean isExcel2003(String filePath) { - return filePath.matches("^.+\\.(?i)(xls)$"); - } - - /** - * - * @param 判断文件类型是不是2007版本 - * @return - */ - public static boolean isExcel2007(String filePath) { - return filePath.matches("^.+\\.(?i)(xlsx)$"); - } + + /** + * 加载本地excel文件 + * + * @param file + * @return + * @throws CoreException + */ + public static Workbook loadExcel(File file) throws CoreException { + Workbook book = null; + try { + InputStream is = new FileInputStream(file); + String name = file.getName(); + if (isExcel2003(name)) { + book = new HSSFWorkbook(is); + } else if (isExcel2007(name)) { + book = new XSSFWorkbook(is); + } + } catch (Exception e) { + log.error("读取Excel失败", e); + throw new CoreException("导入失败,读取文件出错!", e); + } + if (book == null) { + throw new CoreException("导入失败,不支持的文件类型!"); + } + return book; + } + + /*** + * + * @param 判断文件类型是不是2003版本 + * @return + */ + public static boolean isExcel2003(String filePath) { + return filePath.matches("^.+\\.(?i)(xls)$"); + } + + /** + * + * @param 判断文件类型是不是2007版本 + * @return + */ + public static boolean isExcel2007(String filePath) { + return filePath.matches("^.+\\.(?i)(xlsx)$"); + } } diff --git a/src/main/java/vip/xumy/core/utils/JsonUtil.java b/src/main/java/vip/xumy/core/utils/JsonUtil.java index f425818..d370f3f 100644 --- a/src/main/java/vip/xumy/core/utils/JsonUtil.java +++ b/src/main/java/vip/xumy/core/utils/JsonUtil.java @@ -1,54 +1,54 @@ -package vip.xumy.core.utils; - -import java.util.List; -import java.util.Map; - -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.TypeReference; - -/** All rights reserved - * author:mengyxu - * date:2019年5月25日 - * - * 处理json数据的工具类 - */ - -public class JsonUtil { - - private JsonUtil(){ - //Add a private constructor to hide the implicit public one. - } - - public static Map toStringMap(String jsonStr){ - return JSON.parseObject(jsonStr,new TypeReference>(){} ); - } - - public static List> toStirngMapList(String jsonStr){ - return JSON.parseObject(jsonStr, new TypeReference>>(){}); - } - - public static Map>> toMapStirngMapList(String jsonStr){ - return JSON.parseObject(jsonStr, new TypeReference>>>(){}); - } - - public static List toStringList(String jsonStr){ - return JSON.parseObject(jsonStr, new TypeReference>(){}); - } - - public static List toIntegerList(String jsonStr){ - return JSON.parseObject(jsonStr, new TypeReference>(){}); - } - - public static List toEntityList(Class clazz, String jsonStr){ - return JSON.parseArray(jsonStr, clazz); - } - - public static T toEntity(Class clazz, String jsonStr){ - return JSON.parseObject(jsonStr, clazz); - } - - public static Map toEntiryMap(String jsonStr){ - return JSON.parseObject(jsonStr, new TypeReference>(){}); - } - -} +//package vip.xumy.core.utils; +// +//import java.util.List; +//import java.util.Map; +// +//import com.alibaba.fastjson.JSON; +//import com.alibaba.fastjson.TypeReference; +// +///** All rights reserved +// * author:mengyxu +// * date:2019年5月25日 +// * +// * 处理json数据的工具类 +// */ +// +//public class JsonUtil { +// +// private JsonUtil(){ +// //Add a private constructor to hide the implicit public one. +// } +// +//// public static Map toStringMap(String jsonStr){ +//// return JSON.parseObject(jsonStr,new TypeReference>(){} ); +//// } +//// +//// public static List> toStirngMapList(String jsonStr){ +//// return JSON.parseObject(jsonStr, new TypeReference>>(){}); +//// } +//// +//// public static Map>> toMapStirngMapList(String jsonStr){ +//// return JSON.parseObject(jsonStr, new TypeReference>>>(){}); +//// } +//// +//// public static List toStringList(String jsonStr){ +//// return JSON.parseObject(jsonStr, new TypeReference>(){}); +//// } +//// +//// public static List toIntegerList(String jsonStr){ +//// return JSON.parseObject(jsonStr, new TypeReference>(){}); +//// } +//// +//// public static List toEntityList(Class clazz, String jsonStr){ +//// return JSON.parseArray(jsonStr, clazz); +//// } +//// +//// public static T toEntity(Class clazz, String jsonStr){ +//// return JSON.parseObject(jsonStr, clazz); +//// } +//// +//// public static Map toEntiryMap(String jsonStr){ +//// return JSON.parseObject(jsonStr, new TypeReference>(){}); +//// } +//// +//} diff --git a/src/main/java/vip/xumy/core/utils/StringUtil.java b/src/main/java/vip/xumy/core/utils/StringUtil.java index decdfdb..0bde35b 100644 --- a/src/main/java/vip/xumy/core/utils/StringUtil.java +++ b/src/main/java/vip/xumy/core/utils/StringUtil.java @@ -10,11 +10,6 @@ import java.util.regex.Pattern; import vip.xumy.core.exception.CoreException; -/** All rights reserved - * author:mengyxu - * date:2019年6月26日 - */ - public class StringUtil { private static final char[] HEX_DIGITS_L = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; @@ -82,6 +77,37 @@ public class StringUtil { return builder.toString(); } + public static String join(List list, String separator) { + if (list == null || list.isEmpty()) { + return null; + } + return join(list.toArray(new String[list.size()]), separator); + } + + public static String join(List list) { + return join(list, ","); + } + + public static String join(String[] array) { + return join(array, ","); + } + + public static String join(String[] array, String separator) { + if (array == null) { + return null; + } + + StringBuilder builder = new StringBuilder(); + + for (String element : array) { + builder.append(element).append(separator); + } + + builder.delete(builder.length() - separator.length(), builder.length()); + + return builder.toString(); + } + public static boolean isEmpty(String value) { return value == null || value.trim().isEmpty(); } @@ -184,7 +210,7 @@ public class StringUtil { } return sb.toString(); } - + public static String getStringHex(int length) { Random r = new Random(); StringBuilder sb = new StringBuilder(); @@ -263,7 +289,7 @@ public class StringUtil { } return str.substring(start, start + length); } - + public static String right(String str, int length) { if (str == null) { return str; @@ -403,4 +429,16 @@ public class StringUtil { return true; } + public static String add(String src, int add) throws CoreException { + if (isEmpty(src)) { + return add + ""; + } + if (src.length() > 19) { + throw new CoreException("data is to long"); + } + + Long dest = Long.parseLong(src) + add; + return dest.toString(); + } + } diff --git a/src/test/java/vip/xumy/core/test/Base64Tester.java b/src/test/java/vip/xumy/core/test/Base64Tester.java index 885663c..60845d4 100644 --- a/src/test/java/vip/xumy/core/test/Base64Tester.java +++ b/src/test/java/vip/xumy/core/test/Base64Tester.java @@ -1,6 +1,7 @@ package vip.xumy.core.test; -import org.junit.Test; + +import org.junit.jupiter.api.Test; import vip.xumy.core.exception.CoreException; import vip.xumy.core.utils.Base64Util; diff --git a/src/test/java/vip/xumy/core/test/ExcelUtilTester.java b/src/test/java/vip/xumy/core/test/ExcelUtilTester.java new file mode 100644 index 0000000..d5ede28 --- /dev/null +++ b/src/test/java/vip/xumy/core/test/ExcelUtilTester.java @@ -0,0 +1,73 @@ +package vip.xumy.core.test; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; + +import org.junit.jupiter.api.Test; + +import vip.xumy.core.utils.FileUtil; + +/** + * Ownership belongs to the company + * + * @author:mengyxu + * @date:2023年3月20日 + */ + +public class ExcelUtilTester { + + @Test + public void readRowTester() { + String excelPath = "E:\\download\\ok_geo.csv\\ok_geo.csv"; + String table = "geographic_area"; + String sqlPath = "E:\\download\\ok_geo.csv\\ok_geo.sql"; + File newFile = new File(sqlPath); + File parent = newFile.getParentFile(); + if (!parent.exists()) { + parent.mkdirs(); + } + try (BufferedWriter writer = new BufferedWriter(new FileWriter(newFile)); + Scanner scanner = FileUtil.scannerFile(excelPath);) { + while (scanner.hasNextLine()) { + String[] content = scanner.nextLine().split("\",\""); + if (content == null || content.length < 4) { + continue; + } + String[] arr = content[0].split(","); + StringBuilder sb = new StringBuilder(); + sb.append("INSERT INTO ").append(table).append(" VALUES ( "); + for (int i = 0; i < 3; i++) { + sb.append(arr[i]).append(","); + } + sb.append(arr[3]).append("\",\""); + + sb.append(content[1]).append("\","); + String center = content[2]; + if ("EMPTY".equals(center)) { + sb.append("NULL,"); + } else { + sb.append("GeomFromText('POINT (").append(center).append(")',0),"); + } + String area = content[3]; + if ("EMPTY\"".equals(area)) { + sb.append("NULL);"); + } else { + sb.append("GeomFromText('POLYGON ((").append(area.substring(0, area.length() - 1)); + int i = area.indexOf(","); + sb.append(",").append(area.substring(0, i)).append("))',0));"); + } + writer.write(sb.toString(), 0, sb.length()); + writer.newLine(); + } + scanner.close(); + writer.flush(); + } catch (IOException e) { + e.printStackTrace(); + } + + } + +} diff --git a/src/test/java/vip/xumy/core/test/LocationUtilTester.java b/src/test/java/vip/xumy/core/test/LocationUtilTester.java index 6668c90..d944d0e 100644 --- a/src/test/java/vip/xumy/core/test/LocationUtilTester.java +++ b/src/test/java/vip/xumy/core/test/LocationUtilTester.java @@ -2,7 +2,7 @@ package vip.xumy.core.test; import java.util.Arrays; -import org.junit.Test; +import org.junit.jupiter.api.Test; import vip.xumy.core.utils.LocationUtil; diff --git a/src/test/java/vip/xumy/core/test/RSAUtilTester.java b/src/test/java/vip/xumy/core/test/RSAUtilTester.java index 63d4563..cbd6ed9 100644 --- a/src/test/java/vip/xumy/core/test/RSAUtilTester.java +++ b/src/test/java/vip/xumy/core/test/RSAUtilTester.java @@ -14,7 +14,7 @@ import java.security.spec.X509EncodedKeySpec; import javax.crypto.Cipher; -import org.junit.Test; +import org.junit.jupiter.api.Test; import vip.xumy.core.exception.CoreException; import vip.xumy.core.utils.Base64Util; diff --git a/src/test/java/vip/xumy/core/test/Tester.java b/src/test/java/vip/xumy/core/test/Tester.java index 7a58dbd..8fc7273 100644 --- a/src/test/java/vip/xumy/core/test/Tester.java +++ b/src/test/java/vip/xumy/core/test/Tester.java @@ -7,10 +7,11 @@ import java.security.PublicKey; import java.security.interfaces.RSAPublicKey; import java.security.spec.RSAPublicKeySpec; import java.util.Base64; +import java.util.Date; import javax.crypto.Cipher; -import org.junit.Test; +import org.junit.jupiter.api.Test; import vip.xumy.core.exception.CoreException; import vip.xumy.core.utils.Base64Util; @@ -27,12 +28,13 @@ public class Tester { @Test public void test() throws Exception{ - RSAPublicKey res = a(a, b); - //待加密内容 - String text = "我是一个小test"; - //加密后内容 - String en_text = a(res, text); - System.out.println(en_text); +// RSAPublicKey res = a(a, b); +// //待加密内容 +// String text = "我是一个小test"; +// //加密后内容 +// String en_text = a(res, text); +// System.out.println(en_text); + } @Test