Browse Source

update

for_java17
许孟阳 2 years ago
parent
commit
98532aace6
  1. 60
      pom.xml
  2. 43
      src/main/java/vip/xumy/core/conf/BaseConfiger.java
  3. 2
      src/main/java/vip/xumy/core/exception/CoreException.java
  4. 6
      src/main/java/vip/xumy/core/golbal/GlobalConstant.java
  5. 26
      src/main/java/vip/xumy/core/http/HttpResult.java
  6. 212
      src/main/java/vip/xumy/core/http/HttpService.java
  7. 8
      src/main/java/vip/xumy/core/pojo/base/BaseCountBean.java
  8. 20
      src/main/java/vip/xumy/core/pojo/base/BasePage.java
  9. 9
      src/main/java/vip/xumy/core/pojo/base/BasePageParam.java
  10. 10
      src/main/java/vip/xumy/core/pojo/base/BasePeriod.java
  11. 2
      src/main/java/vip/xumy/core/pojo/base/BaseTree.java
  12. 31
      src/main/java/vip/xumy/core/pojo/com/BaseResponse.java
  13. 22
      src/main/java/vip/xumy/core/pojo/com/BaseTree.java
  14. 2
      src/main/java/vip/xumy/core/pojo/com/Cache.java
  15. 5
      src/main/java/vip/xumy/core/pojo/com/Entry.java
  16. 21
      src/main/java/vip/xumy/core/pojo/com/PageResponse.java
  17. 16
      src/main/java/vip/xumy/core/promise/ExcelRowParser.java
  18. 8
      src/main/java/vip/xumy/core/utils/ByteUtil.java
  19. 55
      src/main/java/vip/xumy/core/utils/CombineUtil.java
  20. 139
      src/main/java/vip/xumy/core/utils/ExcelUtil.java
  21. 108
      src/main/java/vip/xumy/core/utils/JsonUtil.java
  22. 48
      src/main/java/vip/xumy/core/utils/StringUtil.java
  23. 3
      src/test/java/vip/xumy/core/test/Base64Tester.java
  24. 73
      src/test/java/vip/xumy/core/test/ExcelUtilTester.java
  25. 2
      src/test/java/vip/xumy/core/test/LocationUtilTester.java
  26. 2
      src/test/java/vip/xumy/core/test/RSAUtilTester.java
  27. 16
      src/test/java/vip/xumy/core/test/Tester.java

60
pom.xml

@ -1,25 +1,27 @@ @@ -1,25 +1,27 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.2.RELEASE</version>
<version>2.7.1</version>
</parent>
<groupId>vip.xumy.core</groupId>
<artifactId>xumy_core</artifactId>
<version>0.0.1</version>
<version>1.0.0</version>
<name>xumy_core</name>
<description>xumy_core</description>
<packaging>jar</packaging>
<properties>
<java.version>17</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<mybatis-spring-boot.version>1.3.2</mybatis-spring-boot.version>
<log4j.version>1.2.17</log4j.version>
<fastjson.version>1.2.46</fastjson.version>
<swagger.version>2.9.2</swagger.version>
<springdoc.version>1.6.9</springdoc.version>
<bouncycastle.version>1.66</bouncycastle.version>
<apache.poi.version>4.0.1</apache.poi.version>
<dom4j.version>2.0.0</dom4j.version>
</properties>
@ -29,40 +31,40 @@ @@ -29,40 +31,40 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- log4j2 -->
<!--springdoc 官方Starter-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>${springdoc.version}</version>
</dependency>
<!-- SpringBoot 的测试依赖 -->
<!--junit 测试包-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<!-- httpclient -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<!-- fastjson -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>${fastjson.version}</version>
</dependency>
<!-- httpclient -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15to18</artifactId>
<version>${bouncycastle.version}</version>
</dependency>
<!-- poi-ooxml -->
<dependency>
<groupId>org.apache.poi</groupId>

43
src/main/java/vip/xumy/core/conf/BaseConfiger.java

@ -0,0 +1,43 @@ @@ -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);
}
}

2
src/main/java/vip/xumy/core/exception/CoreException.java

@ -3,7 +3,7 @@ package vip.xumy.core.exception; @@ -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;

6
src/main/java/vip/xumy/core/golbal/GlobalConstant.java

@ -19,14 +19,16 @@ public class GlobalConstant { @@ -19,14 +19,16 @@ public class GlobalConstant {
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 {
} else {
RESOURCES_ROOT_PATH = GlobalConstant.class.getClassLoader().getResource("").getPath();
}
FILE_DOWNLOAD_PATH = RESOURCES_ROOT_PATH + "/file/";

26
src/main/java/vip/xumy/core/http/HttpResult.java

@ -1,11 +1,12 @@ @@ -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 { @@ -18,10 +19,29 @@ public class HttpResult {
// 响应的响应体
private String body;
private Map<String, String> 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);
}
}

212
src/main/java/vip/xumy/core/http/HttpService.java

@ -1,33 +1,42 @@ @@ -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 { @@ -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<String, String> cookies) {
cookieStore = new BasicCookieStore();
if(cookies != null) {
public static BasicCookieStore createCookies(Map<String, String> 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 { @@ -77,7 +89,7 @@ public class HttpService {
* @param map
* @return
*/
public static HttpResult doGet(String url, Map<String, Object> param) {
public static HttpResult doGet(String url, Map<String, Object> param, BasicCookieStore cookieStore) {
try {
// 1.创建URIBuilder
URIBuilder uriBuilder = new URIBuilder(url);
@ -95,37 +107,72 @@ public class HttpService { @@ -95,37 +107,72 @@ public class HttpService {
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<String, Object> param, BasicCookieStore cookieStore) {
try {
// 1.创建URIBuilder
URIBuilder uriBuilder = new URIBuilder(url);
// 2.设置请求参数
if (param != null) {
// 遍历请求参数
for (Map.Entry<String, Object> 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<String, Object> param) {
public static HttpResult doPost(String url, Map<String, Object> param, BasicCookieStore cookieStore) {
try {
// 1. 声明httppost
HttpPost httpPost = new HttpPost(url);
@ -150,13 +197,13 @@ public class HttpService { @@ -150,13 +197,13 @@ public class HttpService {
}
// 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");
}
}
@ -165,8 +212,7 @@ public class HttpService { @@ -165,8 +212,7 @@ public class HttpService {
*
* @param url 请求地址
* @param params json格式参数
* @return
* @
* @return @
*/
public static HttpResult postWithJson(String url, String params, Map<String, String> headers) {
try {
@ -178,8 +224,8 @@ public class HttpService { @@ -178,8 +224,8 @@ public class HttpService {
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));
}
@ -191,9 +237,57 @@ public class HttpService { @@ -191,9 +237,57 @@ public class HttpService {
// 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<String, String> 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 {
@ -202,11 +296,33 @@ public class HttpService { @@ -202,11 +296,33 @@ public class HttpService {
// 响应体内容
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);
// cookie
Header[] headers = response.getHeaders("Set-Cookie");
if (headers != null && headers.length > 0) {
Map<String, String> 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 new HttpResult(code, body);
return httpResult;
}
/**
@ -216,15 +332,15 @@ public class HttpService { @@ -216,15 +332,15 @@ 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<String, Object> param){
public static void doPostAsync(final String url, final Map<String, Object> param) {
new Thread(new Runnable() {
@Override
public void run() {
try {
doPost(url, param);
doPost(url, param, null);
} catch (Exception e) {
e.printStackTrace();
}

8
src/main/java/vip/xumy/core/pojo/base/BaseCountBean.java

@ -3,7 +3,7 @@ package vip.xumy.core.pojo.base; @@ -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; @@ -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;
}

20
src/main/java/vip/xumy/core/pojo/base/BasePage.java

@ -0,0 +1,20 @@ @@ -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;
}

9
src/main/java/vip/xumy/core/pojo/base/BasePageParam.java

@ -1,6 +1,7 @@ @@ -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; @@ -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;
}

10
src/main/java/vip/xumy/core/pojo/base/BasePeriod.java

@ -3,14 +3,16 @@ package vip.xumy.core.pojo.base; @@ -3,14 +3,16 @@ 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;

2
src/main/java/vip/xumy/core/pojo/base/BaseTree.java

@ -5,7 +5,7 @@ import java.util.List; @@ -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日
*/

31
src/main/java/vip/xumy/core/pojo/com/BaseResponse.java

@ -0,0 +1,31 @@ @@ -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 <T> 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;
}
}

22
src/main/java/vip/xumy/core/pojo/com/BaseTree.java

@ -0,0 +1,22 @@ @@ -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<BaseTree> children;
}

2
src/main/java/vip/xumy/core/pojo/com/Cache.java

@ -4,7 +4,7 @@ import java.util.Date; @@ -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日
*/

5
src/main/java/vip/xumy/core/pojo/com/Entry.java

@ -4,11 +4,6 @@ import java.io.Serializable; @@ -4,11 +4,6 @@ import java.io.Serializable;
import lombok.Data;
/** All rights reserved
* author:mengyxu
* date:2019年6月26日
*/
@Data
public class Entry<K,V> implements Serializable{
private static final long serialVersionUID = 8389699482773678138L;

21
src/main/java/vip/xumy/core/pojo/com/PageResponse.java

@ -2,17 +2,22 @@ package vip.xumy.core.pojo.com; @@ -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<E>{
private List<E> rows; // 每页记录集合
private Long total;
@Schema(description = "分页查询返回格式")
public class PageResponse<E> {
@Schema(description = "数据总条数")
private long total;
@Schema(description = "返回数据")
private List<E> data;
public PageResponse(List<E> list, long total) {
this.total = total;
data = list;
}
}

16
src/main/java/vip/xumy/core/promise/ExcelRowParser.java

@ -0,0 +1,16 @@ @@ -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);
}

8
src/main/java/vip/xumy/core/utils/ByteUtil.java

@ -165,7 +165,7 @@ public class ByteUtil { @@ -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 { @@ -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 { @@ -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 { @@ -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;
}
}

55
src/main/java/vip/xumy/core/utils/CombineUtil.java

@ -0,0 +1,55 @@ @@ -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<List<Integer>> combine(int n) {
List<List<Integer>> res = new ArrayList<>();
for (int i = n; i > 0; i--) {
Deque<Integer> path = new ArrayDeque<>();
dfs(n, i, 1, path, res);
}
return res;
}
public static List<List<Integer>> combine(int n, int k) {
List<List<Integer>> res = new ArrayList<>();
if (k <= 0 || n < k) {
return res;
}
// 从 1 开始是题目的设定
Deque<Integer> path = new ArrayDeque<>();
dfs(n, k, 1, path, res);
return res;
}
private static void dfs(int n, int k, int begin, Deque<Integer> path, List<List<Integer>> 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();
}
}
}

139
src/main/java/vip/xumy/core/utils/ExcelUtil.java

@ -21,40 +21,40 @@ import org.springframework.web.multipart.MultipartFile; @@ -21,40 +21,40 @@ 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 数据转换工具
* @return
* @throws CoreException
*/
public static byte[] parseToExcelByteArray(String template, List<? extends Object> data, ExcelParser parser) throws CoreException {
public static byte[] parseToExcelByteArray(String template, List<? extends Object> data, ExcelParser parser)
throws CoreException {
Workbook book = parserToExcel(template, data, parser);
try(
ByteArrayOutputStream bos = new ByteArrayOutputStream();
) {
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 数据转换工具
@ -79,73 +79,150 @@ public class ExcelUtil { @@ -79,73 +79,150 @@ public class ExcelUtil {
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 <T> List<T> readExcelAsBeanList(MultipartFile file, ExcelParser parser) throws CoreException{
public static <T> List<T> readExcelAsBeanList(MultipartFile file, ExcelParser parser) throws CoreException {
return readExcelAsBeanList(file, parser, null);
}
public static <T> List<T> readExcelAsBeanList(MultipartFile file, ExcelParser parser, Object param) throws CoreException{
public static <T> List<T> readExcelAsBeanList(MultipartFile file, ExcelParser parser, Object param)
throws CoreException {
List<String[]> list = readExcel(file);
return parser.parseToObj(list,param);
return parser.parseToObj(list, param);
}
public static List<String[]> readExcel(MultipartFile file) throws CoreException{
/**
* 读取整个excel
*
* @param file
* @return
* @throws CoreException
*/
public static List<String[]> 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<String[]> list = new ArrayList<>();
for (int i = 1; i <= rowLen; i++) {
Row row = sheet.getRow(i);
if(row == null) {
String[] arr = readRow(row);
if (arr != null || arr.length > 0) {
list.add(arr);
}
}
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;
}
int rowLen = sheet.getLastRowNum();
List<String[]> list = new ArrayList<>();
for (int j = 1; j <= rowLen; j++) {
Row row = sheet.getRow(j);
parser.parse(row, j);
}
}
}
/**
* 读取单行Excel
*
* @param row
* @return
*/
public static String[] readRow(Row row) {
if (row == null) {
return null;
}
short cellLen = row.getLastCellNum();
if(cellLen <= 0) {
continue;
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) {
if (cell != null) {
cell.setCellType(CellType.STRING);
arr[j] = cell.getStringCellValue();
}
}
if(StringUtil.isAllEmpty(arr)) {
continue;
}
list.add(arr);
if (StringUtil.isAllEmpty(arr)) {
return null;
}
return list;
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)) {
book = new XSSFWorkbook(is);
}
} catch (Exception e) {
log.error("读取Excel失败", e);
throw new CoreException("导入失败,读取文件出错!", e);
}
if (book == null) {
throw new CoreException("导入失败,不支持的文件类型!");
}
return book;
}
/**
* 加载本地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)){
} 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;

108
src/main/java/vip/xumy/core/utils/JsonUtil.java

@ -1,54 +1,54 @@ @@ -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<String, String> toStringMap(String jsonStr){
return JSON.parseObject(jsonStr,new TypeReference<Map<String, String>>(){} );
}
public static List<Map<String, String>> toStirngMapList(String jsonStr){
return JSON.parseObject(jsonStr, new TypeReference<List<Map<String,String>>>(){});
}
public static Map<String,List<Map<String, String>>> toMapStirngMapList(String jsonStr){
return JSON.parseObject(jsonStr, new TypeReference<Map<String,List<Map<String, String>>>>(){});
}
public static List<String> toStringList(String jsonStr){
return JSON.parseObject(jsonStr, new TypeReference<List<String>>(){});
}
public static List<Integer> toIntegerList(String jsonStr){
return JSON.parseObject(jsonStr, new TypeReference<List<Integer>>(){});
}
public static<T> List<T> toEntityList(Class<T> clazz, String jsonStr){
return JSON.parseArray(jsonStr, clazz);
}
public static<T> T toEntity(Class<T> clazz, String jsonStr){
return JSON.parseObject(jsonStr, clazz);
}
public static<T,E> Map<T, E> toEntiryMap(String jsonStr){
return JSON.parseObject(jsonStr, new TypeReference<Map<T, E>>(){});
}
}
//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<String, String> toStringMap(String jsonStr){
//// return JSON.parseObject(jsonStr,new TypeReference<Map<String, String>>(){} );
//// }
////
//// public static List<Map<String, String>> toStirngMapList(String jsonStr){
//// return JSON.parseObject(jsonStr, new TypeReference<List<Map<String,String>>>(){});
//// }
////
//// public static Map<String,List<Map<String, String>>> toMapStirngMapList(String jsonStr){
//// return JSON.parseObject(jsonStr, new TypeReference<Map<String,List<Map<String, String>>>>(){});
//// }
////
//// public static List<String> toStringList(String jsonStr){
//// return JSON.parseObject(jsonStr, new TypeReference<List<String>>(){});
//// }
////
//// public static List<Integer> toIntegerList(String jsonStr){
//// return JSON.parseObject(jsonStr, new TypeReference<List<Integer>>(){});
//// }
////
//// public static<T> List<T> toEntityList(Class<T> clazz, String jsonStr){
//// return JSON.parseArray(jsonStr, clazz);
//// }
////
//// public static<T> T toEntity(Class<T> clazz, String jsonStr){
//// return JSON.parseObject(jsonStr, clazz);
//// }
////
//// public static<T,E> Map<T, E> toEntiryMap(String jsonStr){
//// return JSON.parseObject(jsonStr, new TypeReference<Map<T, E>>(){});
//// }
////
//}

48
src/main/java/vip/xumy/core/utils/StringUtil.java

@ -10,11 +10,6 @@ import java.util.regex.Pattern; @@ -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 { @@ -82,6 +77,37 @@ public class StringUtil {
return builder.toString();
}
public static String join(List<String> list, String separator) {
if (list == null || list.isEmpty()) {
return null;
}
return join(list.toArray(new String[list.size()]), separator);
}
public static String join(List<String> 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();
}
@ -403,4 +429,16 @@ public class StringUtil { @@ -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();
}
}

3
src/test/java/vip/xumy/core/test/Base64Tester.java

@ -1,6 +1,7 @@ @@ -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;

73
src/test/java/vip/xumy/core/test/ExcelUtilTester.java

@ -0,0 +1,73 @@ @@ -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();
}
}
}

2
src/test/java/vip/xumy/core/test/LocationUtilTester.java

@ -2,7 +2,7 @@ package vip.xumy.core.test; @@ -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;

2
src/test/java/vip/xumy/core/test/RSAUtilTester.java

@ -14,7 +14,7 @@ import java.security.spec.X509EncodedKeySpec; @@ -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;

16
src/test/java/vip/xumy/core/test/Tester.java

@ -7,10 +7,11 @@ import java.security.PublicKey; @@ -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 { @@ -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

Loading…
Cancel
Save