Compare commits

..

No commits in common. 'for_java17' and 'master' have entirely different histories.

  1. 97
      pom.xml
  2. 43
      src/main/java/vip/xumy/core/conf/BaseConfiger.java
  3. 11
      src/main/java/vip/xumy/core/exception/ControllerExceptionHandler.java
  4. 2
      src/main/java/vip/xumy/core/exception/CoreException.java
  5. 20
      src/main/java/vip/xumy/core/golbal/GlobalConstant.java
  6. 26
      src/main/java/vip/xumy/core/http/HttpResult.java
  7. 230
      src/main/java/vip/xumy/core/http/HttpService.java
  8. 8
      src/main/java/vip/xumy/core/pojo/base/BaseCountBean.java
  9. 20
      src/main/java/vip/xumy/core/pojo/base/BasePage.java
  10. 9
      src/main/java/vip/xumy/core/pojo/base/BasePageParam.java
  11. 12
      src/main/java/vip/xumy/core/pojo/base/BasePeriod.java
  12. 2
      src/main/java/vip/xumy/core/pojo/base/BaseTree.java
  13. 31
      src/main/java/vip/xumy/core/pojo/com/BaseResponse.java
  14. 22
      src/main/java/vip/xumy/core/pojo/com/BaseTree.java
  15. 2
      src/main/java/vip/xumy/core/pojo/com/Cache.java
  16. 5
      src/main/java/vip/xumy/core/pojo/com/Entry.java
  17. 21
      src/main/java/vip/xumy/core/pojo/com/PageResponse.java
  18. 16
      src/main/java/vip/xumy/core/promise/ExcelRowParser.java
  19. 8
      src/main/java/vip/xumy/core/utils/ByteUtil.java
  20. 55
      src/main/java/vip/xumy/core/utils/CombineUtil.java
  21. 273
      src/main/java/vip/xumy/core/utils/DateUtil.java
  22. 221
      src/main/java/vip/xumy/core/utils/ExcelUtil.java
  23. 108
      src/main/java/vip/xumy/core/utils/JsonUtil.java
  24. 52
      src/main/java/vip/xumy/core/utils/StringUtil.java
  25. 3
      src/test/java/vip/xumy/core/test/Base64Tester.java
  26. 73
      src/test/java/vip/xumy/core/test/ExcelUtilTester.java
  27. 2
      src/test/java/vip/xumy/core/test/LocationUtilTester.java
  28. 2
      src/test/java/vip/xumy/core/test/RSAUtilTester.java
  29. 16
      src/test/java/vip/xumy/core/test/Tester.java

97
pom.xml

@ -1,27 +1,25 @@ @@ -1,27 +1,25 @@
<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.7.1</version>
<version>2.0.2.RELEASE</version>
</parent>
<groupId>vip.xumy.core</groupId>
<artifactId>xumy_core</artifactId>
<version>1.0.0</version>
<version>0.0.1</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>
<swagger.version>2.9.2</swagger.version>
<springdoc.version>1.6.9</springdoc.version>
<bouncycastle.version>1.66</bouncycastle.version>
<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>
<apache.poi.version>4.0.1</apache.poi.version>
<dom4j.version>2.0.0</dom4j.version>
</properties>
@ -31,40 +29,46 @@ @@ -31,40 +29,46 @@
<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>
<!--springdoc 官方Starter-->
<!-- log4j2 -->
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>${springdoc.version}</version>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
<!--junit 测试包-->
<!-- SpringBoot 的测试依赖 -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- httpclient -->
<!-- spring-boot整合mybatis -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>${mybatis-spring-boot.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<!-- fastjson -->
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15to18</artifactId>
<version>${bouncycastle.version}</version>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>${fastjson.version}</version>
</dependency>
<!-- httpclient -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<!-- poi-ooxml -->
<dependency>
<groupId>org.apache.poi</groupId>
@ -72,31 +76,12 @@ @@ -72,31 +76,12 @@
<version>${apache.poi.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.dom4j/dom4j -->
<dependency>
<groupId>org.dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>${dom4j.version}</version>
</dependency>
<dependency>
<groupId>org.dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>${dom4j.version}</version>
</dependency>
</dependencies>
<licenses>
<license>
<name>BSD 3-Clause</name>
<url>https://spdx.org/licenses/BSD-3-Clause.html</url>
</license>
</licenses>
<scm>
<connection>https://www.xumy.vip/mengyxu/core.git</connection>
<url>https://www.xumy.vip/mengyxu/core</url>
</scm>
<developers>
<developer>
<name>mengyxu</name>
<email>mengyxu2@outlook.com</email>
<roles>
<role>Developer</role>
</roles>
<timezone>+8</timezone>
</developer>
</developers>
</project>

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

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

11
src/main/java/vip/xumy/core/exception/ControllerExceptionHandler.java

@ -4,6 +4,7 @@ import java.sql.SQLException; @@ -4,6 +4,7 @@ import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
@ -27,11 +28,11 @@ public class ControllerExceptionHandler { @@ -27,11 +28,11 @@ public class ControllerExceptionHandler {
return new AjaxResponse(false, e.getMessage());
}
// @ResponseBody
// @ExceptionHandler(DuplicateKeyException.class)
// public AjaxResponse handlerDuplicateKeyException(DuplicateKeyException e) {
// return new AjaxResponse(false, "数据已存在,请勿重复添加");
// }
@ResponseBody
@ExceptionHandler(DuplicateKeyException.class)
public AjaxResponse handlerDuplicateKeyException(DuplicateKeyException e) {
return new AjaxResponse(false, "数据已存在,请勿重复添加");
}
@ResponseBody
@ExceptionHandler(SQLException.class)

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 RuntimeException{
public class CoreException extends Exception{
private static final long serialVersionUID = 1L;
private String errCode;

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

@ -9,29 +9,27 @@ import org.springframework.util.DigestUtils; @@ -9,29 +9,27 @@ 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/";
}
}

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

@ -1,12 +1,11 @@ @@ -1,12 +1,11 @@
package vip.xumy.core.http;
import java.util.Map;
import lombok.Getter;
import lombok.Setter;
/**
* Ownership belongs to the company author:mengyxu date:2019年5月25日
/** All rights reserved
* author:mengyxu
* date:2019年5月25日
*/
@Setter
@ -19,29 +18,10 @@ public class HttpResult { @@ -19,29 +18,10 @@ 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);
}
}

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

@ -1,42 +1,33 @@ @@ -1,42 +1,33 @@
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;
/**
* Ownership belongs to the company author:mengyxu date:2019年5月25日
/** All rights reserved
* author:mengyxu
* date:2019年5月25日
*/
@Log4j2
@ -46,40 +37,37 @@ public class HttpService { @@ -46,40 +37,37 @@ public class HttpService {
private static final PoolingHttpClientConnectionManager cm;
private static RequestConfig config;
private static final RequestConfig config;
private static CookieStore cookieStore = new BasicCookieStore();
static {
static{
cm = new PoolingHttpClientConnectionManager();
cm.setMaxTotal(200);
cm.setDefaultMaxPerRoute(20);
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();
config = RequestConfig.custom().setConnectTimeout(100000)
.setConnectionRequestTimeout(50000).setSocketTimeout(100000)
.setStaleConnectionCheckEnabled(true).build();
}
/**
* 创建请求所携带cookie
*
* 设置请求所携带cookie
* @param cookies
*/
public static BasicCookieStore createCookies(Map<String, String> cookies, String domain) {
BasicCookieStore cookieStore = new BasicCookieStore();
if (cookies != null) {
public static void setCookies(Map<String, String> cookies) {
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(domain);
clientCookie.setDomain(".");
clientCookie.setPath("/");
cookieStore.addCookie(clientCookie);
}
}
return cookieStore;
}
/**
@ -89,7 +77,7 @@ public class HttpService { @@ -89,7 +77,7 @@ public class HttpService {
* @param map
* @return
*/
public static HttpResult doGet(String url, Map<String, Object> param, BasicCookieStore cookieStore) {
public static HttpResult doGet(String url, Map<String, Object> param) {
try {
// 1.创建URIBuilder
URIBuilder uriBuilder = new URIBuilder(url);
@ -102,77 +90,42 @@ public class HttpService { @@ -102,77 +90,42 @@ 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);
Header[] allHeaders = httpGet.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 doGet(String url) {
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());
}
}
CloseableHttpResponse response = HttpClients.custom().setDefaultCookieStore(cookieStore).setConnectionManager(cm).build()
.execute(httpGet);
// 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");
log.error("http request failed",e);
return new HttpResult(500, "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);
/**
* 不带参数的get
*
* @param url
* @return
*/
public static HttpResult doGet(String url) {
return doGet(url, null);
}
/**
* 带参数的post请求
*
* @param url
* @param map
* @return @
* @return
* @
*/
public static HttpResult doPost(String url, Map<String, Object> param, BasicCookieStore cookieStore) {
public static HttpResult doPost(String url, Map<String, Object> param) {
try {
// 1. 声明httppost
HttpPost httpPost = new HttpPost(url);
@ -195,24 +148,25 @@ public class HttpService { @@ -195,24 +148,25 @@ 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(400, "http request failed");
log.error("http request failed",e);
return new HttpResult(500, "http request failed");
}
}
/**
* json格式参数的post请求
*
* @param url 请求地址
* @param url 请求地址
* @param params json格式参数
* @return @
* @return
* @
*/
public static HttpResult postWithJson(String url, String params, Map<String, String> headers) {
try {
@ -223,106 +177,36 @@ public class HttpService { @@ -223,106 +177,36 @@ 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(400, "http request failed");
log.error("http request failed",e);
return new HttpResult(500, "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 {
// 状态码
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);
// 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 httpResult;
return new HttpResult(code, body);
}
/**
@ -332,20 +216,20 @@ public class HttpService { @@ -332,20 +216,20 @@ public class HttpService {
* @return
*/
public static HttpResult doPost(String url) {
return doPost(url, null, null);
return doPost(url, 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, null);
doPost(url, param);
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
}
}

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;
/** Ownership belongs to the company
/** All rights reserved
* author:mengyxu
* date:2019年5月10日
*/
@ -12,9 +12,7 @@ import lombok.Setter; @@ -12,9 +12,7 @@ import lombok.Setter;
@Getter
public class BaseCountBean {
private Integer id;
private String name;
private Long total;
private Long disTotal;
private long total;
private long disTotal;
}

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

@ -1,20 +0,0 @@ @@ -1,20 +0,0 @@
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,7 +1,6 @@ @@ -1,7 +1,6 @@
package vip.xumy.core.pojo.base;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Getter;
import lombok.Setter;
@ -14,11 +13,11 @@ import lombok.Setter; @@ -14,11 +13,11 @@ import lombok.Setter;
@Getter
public class BasePageParam extends BasePojo {
@JsonIgnore
@JSONField(serialize=false)
private Integer page;
@JsonIgnore
@JSONField(serialize=false)
private Integer size;
@JsonIgnore
@JSONField(serialize=false)
private Integer limitStart;
}

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

@ -3,17 +3,15 @@ package vip.xumy.core.pojo.base; @@ -3,17 +3,15 @@ package vip.xumy.core.pojo.base;
import lombok.Getter;
import lombok.Setter;
/**
* Ownership belongs to the company
*
* @author:mengyxu
* @date:2022年7月21日
/** All rights reserved
* author:mengyxu
* date:2019年12月24日
*/
@Setter
@Getter
public class BasePeriod extends BasePage {
public class BasePeriod extends BasePageParam {
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;
/** Ownership belongs to the company
/** All rights reserved
* author:mengyxu
* date:2019年10月17日
*/

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

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

@ -1,22 +0,0 @@ @@ -1,22 +0,0 @@
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;
/** Ownership belongs to the company
/** All rights reserved
* author:mengyxu
* date:2019年6月26日
*/

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

@ -4,6 +4,11 @@ import java.io.Serializable; @@ -4,6 +4,11 @@ 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,22 +2,17 @@ package vip.xumy.core.pojo.com; @@ -2,22 +2,17 @@ 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
@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;
}
public class PageResponse<E>{
private List<E> rows; // 每页记录集合
private Long total;
}

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

@ -1,16 +0,0 @@ @@ -1,16 +0,0 @@
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] = Integer.valueOf(temp & 0xff).byteValue(); // 将最高位保存在最低位
bb[index + i] = new Integer(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] = Integer.valueOf(temp & 0xff).byteValue(); // 将最高位保存在最低位
bb[index + i] = new Integer(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] = Integer.valueOf(l).byteValue();
bb[index + i] = new Integer(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] = Long.valueOf(l).byteValue();
bb[index + i] = new Long(l).byteValue();
l = l >> 8;
}
}

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

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

273
src/main/java/vip/xumy/core/utils/DateUtil.java

@ -10,126 +10,98 @@ import java.util.Locale; @@ -10,126 +10,98 @@ import java.util.Locale;
import vip.xumy.core.exception.CoreException;
/**
* All rights reserved author:mengyxu date:2019年5月17日
/** All rights reserved
* author:mengyxu
* date:2019年5月17日
*/
public class DateUtil {
public static final String FORMAT10_LINE_DDMMYYYY = "dd-MM-yyyy";
public static final String FORMAT10_LINE_MMDDYYYY = "MM-dd-yyyy";
public static final String FORMAT10_LINE_YYYYMMDD = "yyyy-MM-dd";
public static final String FORMAT10_SLASH_DDMMYYYY = "dd/MM/yyyy";
public static final String FORMAT10_SLASH_MMDDYYYY = "MM/dd/yyyy";
public static final String FORMAT10_SLASH_YYYYMMDD = "yyyy/MM/dd";
public static final String FORMAT19_LINE_YYYYMMDDHHMMSS = "yyyy-MM-dd HH:mm:ss";
public static final String FORMAT8_DDMMYYYY = "ddMMyyyy";
public static final String FORMAT8_MMDDYYYY = "MMddyyyy";
public static final String FORMAT8_YYYYMMDD = "yyyyMMdd";
public static final String FORMAT3_YYM = "yy年M月";
public static final String FORMAT2_MD = "M月d日";
public static final String FORMAT2_DH = "d日H时";
public static final String FORMAT10_YYYYMMDDHH = "yyyyMMddHH";
public static final String FORMAT6_YYYYMM = "yyyyMM";
public static final String FORMAT8_YYYYMM = "yyyy年MM月";
public static final String FORMAT14_YYYYMMDDHHMMSS = "yyyyMMddHHmmss";
public static final String FORMAT_GMT_8 = "EEE MMM dd yyyy HH:mm:ss 'GMT+0800(中国标准时间)'";
public static final String FORMAT20_LINE_YYYYMMDDTHHMMSS = "yyyy-MM-dd'T'HH:mm:ss";
private DateUtil() {
// Add a private constructor to hide the implicit public one.
private DateUtil(){
//Add a private constructor to hide the implicit public one.
}
/**
* <p>
* Convert a date string from <code>srcPattern</code> to
* <code>destPattern</code>
* Convert a date string from <code>srcPattern</code> to <code>destPattern</code>
* </p>
*
* @param dateStr
* @param srcPattern
* @param destPattern
* @return
* @throws CoreException
*/
public static String convert(String dateStr, String srcPattern, String destPattern) throws CoreException {
if (dateStr == null) {
public static String convert(String dateStr, String srcPattern, String destPattern) throws CoreException{
if (dateStr == null){
return null;
}
Date date = parse(dateStr, srcPattern);
return format(date, destPattern);
}
/**
* Format now with default String pattern.
*
* @param date
* @param pattern
* @return
*/
public static String format() {
DateFormat formatter = new SimpleDateFormat(FORMAT19_LINE_YYYYMMDDHHMMSS);
return formatter.format(new Date());
}
/**
* Format a date with default String pattern.
*
* @param date
* @param pattern
* @return
*/
public static String format(Date date) {
DateFormat formatter = new SimpleDateFormat(FORMAT19_LINE_YYYYMMDDHHMMSS);
return formatter.format(date);
}
/**
* Format a date with specific String pattern.
*
* @param date
* @param pattern
* @return
*/
public static String format(Date date, String pattern) {
public static String format(Date date, String pattern){
DateFormat formatter = new SimpleDateFormat(pattern);
return formatter.format(date);
}
/**
* Format a date with specific String pattern.
*
* @param date
* @param pattern
* @Param locale
* @return
*/
public static String format(Date date, String pattern, Locale locale) {
public static String format(Date date, String pattern, Locale locale){
DateFormat formatter = new SimpleDateFormat(pattern, locale);
return formatter.format(date);
}
/**
* Parse a string to a date with pattern.
*
* @param src
* @param pattern
* @return
* @throws CoreException
*/
public static Date parse(String src, String pattern) throws CoreException {
public static Date parse(String src, String pattern) throws CoreException{
DateFormat formatter = new SimpleDateFormat(pattern);
try {
return formatter.parse(src);
@ -138,136 +110,125 @@ public class DateUtil { @@ -138,136 +110,125 @@ public class DateUtil {
throw new CoreException(MessageFormat.format(message, pattern, src), e);
}
}
public static int compare(String src, String dest, String pattern) throws CoreException {
public static int compare(String src, String dest, String pattern) throws CoreException{
Date srcDate = parse(src, pattern);
Date destDate = parse(dest, pattern);
return srcDate.compareTo(destDate);
}
public static long diff(String src, String dest, String pattern) throws CoreException {
public static long diff(String src, String dest, String pattern) throws CoreException{
Date srcDate = parse(src, pattern);
Date destDate = parse(dest, pattern);
return (destDate.getTime() - srcDate.getTime()) / (1000 * 60 * 60 * 24);
return (destDate.getTime()-srcDate.getTime())/(1000*60*60*24);
}
public static int diff(Date srcDate, Date destDate) throws CoreException {
public static int diff(Date srcDate, Date destDate) throws CoreException{
Calendar src = Calendar.getInstance();
src.setTime(srcDate);
Calendar dest = Calendar.getInstance();
dest.setTime(destDate);
if (src.get(Calendar.YEAR) == dest.get(Calendar.YEAR)) {
if (src.get(Calendar.YEAR) == dest.get(Calendar.YEAR)){
return dest.get(Calendar.DAY_OF_YEAR) - src.get(Calendar.DAY_OF_YEAR);
} else {
int srcYear = src.get(Calendar.YEAR);
Calendar tmp = Calendar.getInstance();
tmp.setTimeInMillis(dest.getTimeInMillis());
tmp.set(Calendar.YEAR, srcYear);
int diff = tmp.get(Calendar.DAY_OF_YEAR) - src.get(Calendar.DAY_OF_YEAR);
diff += (destDate.getTime() - tmp.getTimeInMillis()) / (1000 * 60 * 60 * 24L);
diff += (destDate.getTime()-tmp.getTimeInMillis())/(1000*60*60*24L);
return diff;
}
}
/**
* Return today with pattern.
*
* @return
*/
public static String today(String pattern) {
return format(new Date(), pattern);
return format(new Date(), pattern);
}
public static Date dayAdd(int offset) {
return dayAdd(new Date(), offset);
}
public static Date dayAdd(Date date, int offset) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) + offset);
return calendar.getTime();
}
public static String dayAdd(String pattern, int offset) {
Date date = dayAdd(offset);
return format(date, pattern);
}
public static String dayAdd(String src, String pattern, int offset) throws CoreException {
Date date = dayAdd(parse(src, pattern), offset);
return format(date, pattern);
}
public static Date hourAdd(Date date, int offset) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.set(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY) + offset);
return calendar.getTime();
}
public static Date hourAdd(int offset) {
return hourAdd(new Date(), offset);
}
public static String hourAdd(String pattern, int offset) {
Date date = hourAdd(offset);
return format(date, pattern);
}
public static String hourAdd(String src, String pattern, int offset) throws CoreException {
Date date = hourAdd(parse(src, pattern), offset);
return format(date, pattern);
}
public static Date monthAdd(Date date, int offset) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) + offset);
calendar.set(Calendar.DAY_OF_MONTH, calendar.getMinimum(Calendar.DATE));
return calendar.getTime();
}
public static Date monthAdd(int offset) {
return monthAdd(new Date(), offset);
}
public static String monthAdd(String pattern, int offset) {
Date date = monthAdd(offset);
return format(date, pattern);
}
public static String monthAdd(String src, String pattern, int offset) throws CoreException {
Date date = monthAdd(parse(src, pattern), offset);
return format(date, pattern);
}
public static String getFirstDay(Date month, String destPattern) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(month);
calendar.set(Calendar.DAY_OF_MONTH, calendar.getMinimum(Calendar.DATE));
return format(calendar.getTime(), destPattern);
}
public static String getFirstDay(String month, String srcPattern, String destPattern) throws CoreException {
return getFirstDay(parse(month, srcPattern), destPattern);
}
public static String getLastDay(Date month, String pattern) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(month);
calendar.set(Calendar.DAY_OF_MONTH, calendar.getMaximum(Calendar.DATE));
return format(calendar.getTime(), pattern);
}
public static String getLastDay(String month, String srcPattern, String destPattern) throws CoreException {
return getLastDay(parse(month, srcPattern), destPattern);
}
public static Date dayAdd(Date date, int offset) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) + offset);
return calendar.getTime();
}
public static String dayAdd(String pattern, int offset){
Date date = dayAdd(offset);
return format(date, pattern);
}
public static String dayAdd(String src, String pattern, int offset) throws CoreException {
Date date = dayAdd(parse(src, pattern), offset);
return format(date, pattern);
}
public static Date hourAdd(Date date, int offset){
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.set(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY) + offset);
return calendar.getTime();
}
public static Date hourAdd(int offset){
return hourAdd(new Date(), offset);
}
public static String hourAdd(String pattern, int offset){
Date date = hourAdd(offset);
return format(date, pattern);
}
public static String hourAdd(String src, String pattern, int offset) throws CoreException {
Date date = hourAdd(parse(src, pattern), offset);
return format(date, pattern);
}
public static Date monthAdd(Date date, int offset){
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) + offset);
calendar.set(Calendar.DAY_OF_MONTH, calendar.getMinimum(Calendar.DATE));
return calendar.getTime();
}
public static Date monthAdd(int offset){
return monthAdd(new Date(), offset);
}
public static String monthAdd(String pattern, int offset) {
Date date = monthAdd(offset);
return format(date, pattern);
}
public static String monthAdd(String src, String pattern, int offset) throws CoreException {
Date date = monthAdd(parse(src, pattern), offset);
return format(date, pattern);
}
public static String getFirstDay(Date month, String destPattern){
Calendar calendar = Calendar.getInstance();
calendar.setTime(month);
calendar.set(Calendar.DAY_OF_MONTH, calendar.getMinimum(Calendar.DATE));
return format(calendar.getTime(), destPattern);
}
public static String getFirstDay(String month, String srcPattern, String destPattern) throws CoreException{
return getFirstDay(parse(month, srcPattern),destPattern);
}
public static String getLastDay(Date month, String pattern){
Calendar calendar = Calendar.getInstance();
calendar.setTime(month);
calendar.set(Calendar.DAY_OF_MONTH, calendar.getMaximum(Calendar.DATE));
return format(calendar.getTime(), pattern);
}
public static String getLastDay(String month, String srcPattern, String destPattern) throws CoreException{
return getLastDay(parse(month, srcPattern),destPattern);
}
}

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

@ -21,43 +21,43 @@ import org.springframework.web.multipart.MultipartFile; @@ -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<? 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();) {
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,174 +76,97 @@ public class ExcelUtil { @@ -76,174 +76,97 @@ 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 <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);
}
/**
* 读取整个excel
*
* @param file
* @return
* @throws CoreException
*/
public static List<String[]> readExcel(MultipartFile file) 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);
String[] arr = readRow(row);
if (arr != null || arr.length > 0) {
list.add(arr);
if(row == null) {
continue;
}
}
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) {
short cellLen = row.getLastCellNum();
if(cellLen <= 0) {
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);
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();
}
}
}
}
/**
* 读取单行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();
if(StringUtil.isAllEmpty(arr)) {
continue;
}
list.add(arr);
}
if (StringUtil.isAllEmpty(arr)) {
return null;
}
return arr;
return list;
}
/**
* 加载表单提交excel文件
*
* @param file
* @return
* @throws CoreException
*/
public static Workbook loadExcel(MultipartFile file) 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;
}
/**
* 加载本地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)$");
}
/***
*
* @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)$");
}
}

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>>(){});
}
}

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

@ -10,6 +10,11 @@ import java.util.regex.Pattern; @@ -10,6 +10,11 @@ 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' };
@ -77,37 +82,6 @@ public class StringUtil { @@ -77,37 +82,6 @@ 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();
}
@ -210,7 +184,7 @@ public class StringUtil { @@ -210,7 +184,7 @@ public class StringUtil {
}
return sb.toString();
}
public static String getStringHex(int length) {
Random r = new Random();
StringBuilder sb = new StringBuilder();
@ -289,7 +263,7 @@ public class StringUtil { @@ -289,7 +263,7 @@ public class StringUtil {
}
return str.substring(start, start + length);
}
public static String right(String str, int length) {
if (str == null) {
return str;
@ -429,16 +403,4 @@ public class StringUtil { @@ -429,16 +403,4 @@ 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,7 +1,6 @@ @@ -1,7 +1,6 @@
package vip.xumy.core.test;
import org.junit.jupiter.api.Test;
import org.junit.Test;
import vip.xumy.core.exception.CoreException;
import vip.xumy.core.utils.Base64Util;

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

@ -1,73 +0,0 @@ @@ -1,73 +0,0 @@
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.jupiter.api.Test;
import org.junit.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.jupiter.api.Test;
import org.junit.Test;
import vip.xumy.core.exception.CoreException;
import vip.xumy.core.utils.Base64Util;

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

@ -7,11 +7,10 @@ import java.security.PublicKey; @@ -7,11 +7,10 @@ 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.jupiter.api.Test;
import org.junit.Test;
import vip.xumy.core.exception.CoreException;
import vip.xumy.core.utils.Base64Util;
@ -28,13 +27,12 @@ public class Tester { @@ -28,13 +27,12 @@ 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