init
This commit is contained in:
commit
0094677c94
46
.gitignore
vendored
Normal file
46
.gitignore
vendored
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
<<<<<<< HEAD
|
||||||
|
target/
|
||||||
|
pom.xml.tag
|
||||||
|
pom.xml.releaseBackup
|
||||||
|
pom.xml.versionsBackup
|
||||||
|
pom.xml.next
|
||||||
|
release.properties
|
||||||
|
dependency-reduced-pom.xml
|
||||||
|
buildNumber.properties
|
||||||
|
.mvn/timing.properties
|
||||||
|
.mvn/wrapper/maven-wrapper.jar
|
||||||
|
=======
|
||||||
|
HELP.md
|
||||||
|
target/
|
||||||
|
!.mvn/wrapper/maven-wrapper.jar
|
||||||
|
!**/src/main/**/target/
|
||||||
|
!**/src/test/**/target/
|
||||||
|
|
||||||
|
### STS ###
|
||||||
|
.apt_generated
|
||||||
|
.classpath
|
||||||
|
.factorypath
|
||||||
|
.project
|
||||||
|
.settings
|
||||||
|
.springBeans
|
||||||
|
.sts4-cache
|
||||||
|
|
||||||
|
### IntelliJ IDEA ###
|
||||||
|
.idea
|
||||||
|
*.iws
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
|
||||||
|
### NetBeans ###
|
||||||
|
/nbproject/private/
|
||||||
|
/nbbuild/
|
||||||
|
/dist/
|
||||||
|
/nbdist/
|
||||||
|
/.nb-gradle/
|
||||||
|
build/
|
||||||
|
!**/src/main/**/build/
|
||||||
|
!**/src/test/**/build/
|
||||||
|
|
||||||
|
### VS Code ###
|
||||||
|
.vscode/
|
||||||
|
>>>>>>> firstcommit
|
117
.mvn/wrapper/MavenWrapperDownloader.java
vendored
Normal file
117
.mvn/wrapper/MavenWrapperDownloader.java
vendored
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2007-present the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
import java.net.*;
|
||||||
|
import java.io.*;
|
||||||
|
import java.nio.channels.*;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
public class MavenWrapperDownloader {
|
||||||
|
|
||||||
|
private static final String WRAPPER_VERSION = "0.5.6";
|
||||||
|
/**
|
||||||
|
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
|
||||||
|
*/
|
||||||
|
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
|
||||||
|
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
|
||||||
|
* use instead of the default one.
|
||||||
|
*/
|
||||||
|
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
|
||||||
|
".mvn/wrapper/maven-wrapper.properties";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Path where the maven-wrapper.jar will be saved to.
|
||||||
|
*/
|
||||||
|
private static final String MAVEN_WRAPPER_JAR_PATH =
|
||||||
|
".mvn/wrapper/maven-wrapper.jar";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Name of the property which should be used to override the default download url for the wrapper.
|
||||||
|
*/
|
||||||
|
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
|
||||||
|
|
||||||
|
public static void main(String args[]) {
|
||||||
|
System.out.println("- Downloader started");
|
||||||
|
File baseDirectory = new File(args[0]);
|
||||||
|
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
|
||||||
|
|
||||||
|
// If the maven-wrapper.properties exists, read it and check if it contains a custom
|
||||||
|
// wrapperUrl parameter.
|
||||||
|
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
|
||||||
|
String url = DEFAULT_DOWNLOAD_URL;
|
||||||
|
if(mavenWrapperPropertyFile.exists()) {
|
||||||
|
FileInputStream mavenWrapperPropertyFileInputStream = null;
|
||||||
|
try {
|
||||||
|
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
|
||||||
|
Properties mavenWrapperProperties = new Properties();
|
||||||
|
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
|
||||||
|
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if(mavenWrapperPropertyFileInputStream != null) {
|
||||||
|
mavenWrapperPropertyFileInputStream.close();
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
// Ignore ...
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
System.out.println("- Downloading from: " + url);
|
||||||
|
|
||||||
|
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
|
||||||
|
if(!outputFile.getParentFile().exists()) {
|
||||||
|
if(!outputFile.getParentFile().mkdirs()) {
|
||||||
|
System.out.println(
|
||||||
|
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
|
||||||
|
try {
|
||||||
|
downloadFileFromURL(url, outputFile);
|
||||||
|
System.out.println("Done");
|
||||||
|
System.exit(0);
|
||||||
|
} catch (Throwable e) {
|
||||||
|
System.out.println("- Error downloading");
|
||||||
|
e.printStackTrace();
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
|
||||||
|
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
|
||||||
|
String username = System.getenv("MVNW_USERNAME");
|
||||||
|
char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
|
||||||
|
Authenticator.setDefault(new Authenticator() {
|
||||||
|
@Override
|
||||||
|
protected PasswordAuthentication getPasswordAuthentication() {
|
||||||
|
return new PasswordAuthentication(username, password);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
URL website = new URL(urlString);
|
||||||
|
ReadableByteChannel rbc;
|
||||||
|
rbc = Channels.newChannel(website.openStream());
|
||||||
|
FileOutputStream fos = new FileOutputStream(destination);
|
||||||
|
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
|
||||||
|
fos.close();
|
||||||
|
rbc.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
BIN
.mvn/wrapper/maven-wrapper.jar
vendored
Normal file
BIN
.mvn/wrapper/maven-wrapper.jar
vendored
Normal file
Binary file not shown.
2
.mvn/wrapper/maven-wrapper.properties
vendored
Normal file
2
.mvn/wrapper/maven-wrapper.properties
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip
|
||||||
|
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar
|
1185
doc/trans_new_漫画翻译数据库文档_1.0.html
Normal file
1185
doc/trans_new_漫画翻译数据库文档_1.0.html
Normal file
File diff suppressed because it is too large
Load Diff
249
pom.xml
Normal file
249
pom.xml
Normal file
@ -0,0 +1,249 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<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 https://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.5.8</version>
|
||||||
|
<relativePath/> <!-- lookup parent from repository -->
|
||||||
|
</parent>
|
||||||
|
<groupId>com.dingxing</groupId>
|
||||||
|
<artifactId>dingxing</artifactId>
|
||||||
|
<version>1.0</version>
|
||||||
|
<name>dingxing</name>
|
||||||
|
<description>Demo project for Spring Boot</description>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<java.version>1.8</java.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-aop</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.junit.vintage</groupId>
|
||||||
|
<artifactId>junit-vintage-engine</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||||
|
<version>2.2.4.RELEASE</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baomidou</groupId>
|
||||||
|
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||||
|
<version>3.2.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba</groupId>
|
||||||
|
<artifactId>druid-spring-boot-starter</artifactId>
|
||||||
|
<version>1.1.10</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baomidou</groupId>
|
||||||
|
<artifactId>mybatis-plus-extension</artifactId>
|
||||||
|
<version>3.2.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jsoup</groupId>
|
||||||
|
<artifactId>jsoup</artifactId>
|
||||||
|
<version>1.14.3</version> <!-- 替换为你想要使用的Jsoup版本 -->
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>mysql</groupId>
|
||||||
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.pagehelper</groupId>
|
||||||
|
<artifactId>pagehelper-spring-boot-starter</artifactId>
|
||||||
|
<version>1.2.3</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.janeluo</groupId>
|
||||||
|
<artifactId>ikanalyzer</artifactId>
|
||||||
|
<version>2012_u6</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.huaban</groupId>
|
||||||
|
<artifactId>jieba-analysis</artifactId>
|
||||||
|
<version>1.0.2</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.wechatpay-apiv3</groupId>
|
||||||
|
<artifactId>wechatpay-apache-httpclient</artifactId>
|
||||||
|
<version>0.4.7</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.bouncycastle</groupId>
|
||||||
|
<artifactId>bcprov-jdk15on</artifactId>
|
||||||
|
<version>1.60</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baidubce</groupId>
|
||||||
|
<artifactId>bce-java-sdk</artifactId>
|
||||||
|
<version>0.10.154</version>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>com.google.guava</groupId>
|
||||||
|
<artifactId>guava</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.hutool</groupId>
|
||||||
|
<artifactId>hutool-all</artifactId>
|
||||||
|
<version>5.2.5</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba</groupId>
|
||||||
|
<artifactId>fastjson</artifactId>
|
||||||
|
<version>1.2.58</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<version>1.18.6</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.sf.json-lib</groupId>
|
||||||
|
<artifactId>json-lib-ext-spring</artifactId>
|
||||||
|
<version>1.0.2</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!--<dependency>
|
||||||
|
<groupId>io.springfox</groupId>
|
||||||
|
<artifactId>springfox-swagger2</artifactId>
|
||||||
|
<version>2.8.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.springfox</groupId>
|
||||||
|
<artifactId>springfox-swagger-ui</artifactId>
|
||||||
|
<version>2.8.0</version>
|
||||||
|
</dependency>
|
||||||
|
<!–<dependency>
|
||||||
|
<groupId>io.github.swagger2markup</groupId>
|
||||||
|
<artifactId>swagger2markup</artifactId>
|
||||||
|
<version>1.3.1</version>
|
||||||
|
</dependency>–>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.swagger</groupId>
|
||||||
|
<artifactId>swagger-core</artifactId>
|
||||||
|
<version>1.5.16</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.swagger</groupId>
|
||||||
|
<artifactId>swagger-models</artifactId>
|
||||||
|
<version>1.5.16</version>
|
||||||
|
</dependency>-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.springfox</groupId>
|
||||||
|
<artifactId>springfox-swagger2</artifactId>
|
||||||
|
<version>2.9.2</version>
|
||||||
|
</dependency>
|
||||||
|
<!--swaggerui更新前-->
|
||||||
|
<!-- <dependency>
|
||||||
|
<groupId>com.github.xiaoymin</groupId>
|
||||||
|
<artifactId>swagger-bootstrap-ui</artifactId>
|
||||||
|
<version>${swagger.ui.version}</version>
|
||||||
|
</dependency>-->
|
||||||
|
<!--更新后-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.xiaoymin</groupId>
|
||||||
|
<artifactId>knife4j-spring-boot-starter</artifactId>
|
||||||
|
<!--在引用时请在maven中央仓库搜索2.X最新版本号-->
|
||||||
|
<version>2.0.9</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.springfox</groupId>
|
||||||
|
<artifactId>springfox-swagger-ui</artifactId>
|
||||||
|
<version>2.9.2</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.pegdown</groupId>
|
||||||
|
<artifactId>pegdown</artifactId>
|
||||||
|
<version>1.4.2</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-codec</groupId>
|
||||||
|
<artifactId>commons-codec</artifactId>
|
||||||
|
<version>1.13</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.commons</groupId>
|
||||||
|
<artifactId>commons-lang3</artifactId>
|
||||||
|
<version>3.9</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-io</groupId>
|
||||||
|
<artifactId>commons-io</artifactId>
|
||||||
|
<version>2.6</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.httpcomponents</groupId>
|
||||||
|
<artifactId>httpclient</artifactId>
|
||||||
|
<version>4.5.9</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.commons</groupId>
|
||||||
|
<artifactId>commons-collections4</artifactId>
|
||||||
|
<version>4.4</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>4.12-beta-3</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.wechatpay-apiv3</groupId>
|
||||||
|
<artifactId>wechatpay-apache-httpclient</artifactId>
|
||||||
|
<version>0.4.7</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
|
||||||
|
</plugin>
|
||||||
|
<!--生成数据库文档 项目/doc/目录下-->
|
||||||
|
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
1663
sql/encryption.sql
Normal file
1663
sql/encryption.sql
Normal file
File diff suppressed because one or more lines are too long
24
src/main/java/com/shenghua/DingxingApplication.java
Normal file
24
src/main/java/com/shenghua/DingxingApplication.java
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
package com.shenghua;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.context.annotation.EnableAspectJAutoProxy;
|
||||||
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
|
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||||
|
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
@EnableAspectJAutoProxy
|
||||||
|
@EnableScheduling
|
||||||
|
@EnableSwagger2
|
||||||
|
public class DingxingApplication {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(DingxingApplication.class, args);
|
||||||
|
// RedisTemplate<String,Object> redisTemplate= SpringBeanUtil.getBean(RedisTemplate.class);
|
||||||
|
// redisTemplate.opsForValue().set("user1", new User1(2,"lumia"));
|
||||||
|
// System.out.println(redisTemplate.opsForValue().getOperations().getExpire("user1"));
|
||||||
|
// Object name = redisTemplate.opsForValue().get("shopping_car1");
|
||||||
|
// System.out.println(name);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
13
src/main/java/com/shenghua/annotations/NotNull.java
Normal file
13
src/main/java/com/shenghua/annotations/NotNull.java
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
package com.shenghua.annotations;
|
||||||
|
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
@Target(ElementType.FIELD)
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Documented
|
||||||
|
public @interface NotNull {
|
||||||
|
|
||||||
|
String message() default "";
|
||||||
|
|
||||||
|
}
|
10
src/main/java/com/shenghua/annotations/Valid.java
Normal file
10
src/main/java/com/shenghua/annotations/Valid.java
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package com.shenghua.annotations;
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
@Target(ElementType.PARAMETER)
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Documented
|
||||||
|
public @interface Valid {
|
||||||
|
|
||||||
|
}
|
15
src/main/java/com/shenghua/config/BeanConfig.java
Normal file
15
src/main/java/com/shenghua/config/BeanConfig.java
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package com.shenghua.config;
|
||||||
|
|
||||||
|
import com.shenghua.utils.SpringBeanUtil;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class BeanConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public SpringBeanUtil getSpringBeanUtil(){
|
||||||
|
return new SpringBeanUtil();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
64
src/main/java/com/shenghua/config/DateConverterConfig.java
Normal file
64
src/main/java/com/shenghua/config/DateConverterConfig.java
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
package com.shenghua.config;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonGenerator;
|
||||||
|
import com.fasterxml.jackson.databind.JsonSerializer;
|
||||||
|
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.boot.jackson.JsonComponent;
|
||||||
|
import org.springframework.core.convert.converter.Converter;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.text.DateFormat;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class DateConverterConfig implements Converter<String, Date> {
|
||||||
|
|
||||||
|
|
||||||
|
private static final String YYYY_MM_DD = "yyyy-MM-dd";
|
||||||
|
private static final String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
|
||||||
|
|
||||||
|
@JsonComponent
|
||||||
|
public static class DateJsonSerializer extends JsonSerializer<Date> {
|
||||||
|
@Override
|
||||||
|
public void serialize(Date date, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
|
||||||
|
SimpleDateFormat sdf=new SimpleDateFormat(YYYY_MM_DD_HH_MM_SS);
|
||||||
|
jsonGenerator.writeString(sdf.format(date));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Date convert(String source) {
|
||||||
|
if (StringUtils.isBlank(source)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
source = source.trim();
|
||||||
|
if(source.matches("^\\d{4}-\\d{1,2}-\\d{1,2}$")){
|
||||||
|
return parseDate(source, YYYY_MM_DD);
|
||||||
|
}else if(source.matches("^\\d{4}-\\d{1,2}-\\d{1,2} {1}\\d{1,2}:\\d{1,2}:\\d{1,2}$")){
|
||||||
|
return parseDate(source, YYYY_MM_DD_HH_MM_SS);
|
||||||
|
}else {
|
||||||
|
throw new IllegalArgumentException("Invalid false value '" + source + "'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 格式化日期
|
||||||
|
* @param dateStr String 字符型日期
|
||||||
|
* @param format String 格式
|
||||||
|
* @return Date 日期
|
||||||
|
*/
|
||||||
|
private Date parseDate(String dateStr, String format) {
|
||||||
|
Date date;
|
||||||
|
try {
|
||||||
|
DateFormat dateFormat = new SimpleDateFormat(format);
|
||||||
|
date = dateFormat.parse(dateStr);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new IllegalArgumentException(e.getLocalizedMessage());
|
||||||
|
}
|
||||||
|
return date;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
67
src/main/java/com/shenghua/config/DruidConfig.java
Normal file
67
src/main/java/com/shenghua/config/DruidConfig.java
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
package com.shenghua.config;
|
||||||
|
|
||||||
|
import com.alibaba.druid.support.http.StatViewServlet;
|
||||||
|
import com.alibaba.druid.support.http.WebStatFilter;
|
||||||
|
import com.alibaba.druid.support.spring.stat.DruidStatInterceptor;
|
||||||
|
import org.springframework.aop.support.DefaultPointcutAdvisor;
|
||||||
|
import org.springframework.aop.support.JdkRegexpMethodPointcut;
|
||||||
|
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||||
|
import org.springframework.boot.web.servlet.ServletRegistrationBean;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Scope;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class DruidConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public ServletRegistrationBean druidServlet() {
|
||||||
|
ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(new StatViewServlet(), "/druid/*");
|
||||||
|
Map<String,String> initParam = new HashMap<>();
|
||||||
|
initParam.put("loginUsername","druid");
|
||||||
|
initParam.put("loginPassword","123456");
|
||||||
|
initParam.put("allow",""); //默认就是允许所有访问
|
||||||
|
initParam.put("deny",""); //默认访问
|
||||||
|
servletRegistrationBean.setInitParameters(initParam);
|
||||||
|
return servletRegistrationBean;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public FilterRegistrationBean webStatFilter() {
|
||||||
|
FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
|
||||||
|
filterRegistrationBean.setFilter(new WebStatFilter());
|
||||||
|
Map<String, String> initParams = new HashMap<>();
|
||||||
|
initParams.put("exclusions", "*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*");
|
||||||
|
filterRegistrationBean.setInitParameters(initParams);
|
||||||
|
filterRegistrationBean.addUrlPatterns("/*");
|
||||||
|
filterRegistrationBean.setOrder(2);
|
||||||
|
filterRegistrationBean.setName("webStatFilter");
|
||||||
|
return filterRegistrationBean;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public DruidStatInterceptor druidStatInterceptor() {
|
||||||
|
DruidStatInterceptor dsInterceptor = new DruidStatInterceptor();
|
||||||
|
return dsInterceptor;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@Scope("prototype")
|
||||||
|
public JdkRegexpMethodPointcut druidStatPointcut() {
|
||||||
|
JdkRegexpMethodPointcut pointcut = new JdkRegexpMethodPointcut();
|
||||||
|
pointcut.setPattern("com.dingxing.mapper.*");
|
||||||
|
return pointcut;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public DefaultPointcutAdvisor druidStatAdvisor(DruidStatInterceptor druidStatInterceptor, JdkRegexpMethodPointcut druidStatPointcut) {
|
||||||
|
DefaultPointcutAdvisor defaultPointAdvisor = new DefaultPointcutAdvisor();
|
||||||
|
defaultPointAdvisor.setPointcut(druidStatPointcut);
|
||||||
|
defaultPointAdvisor.setAdvice(druidStatInterceptor);
|
||||||
|
return defaultPointAdvisor;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
25
src/main/java/com/shenghua/config/JobConfig.java
Normal file
25
src/main/java/com/shenghua/config/JobConfig.java
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
package com.shenghua.config;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.scheduling.TaskScheduler;
|
||||||
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class JobConfig {
|
||||||
|
|
||||||
|
@Value("${job.pool.size}")
|
||||||
|
private int poolSize;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*任务调度线程池配置
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public TaskScheduler taskScheduler() {
|
||||||
|
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
|
||||||
|
taskScheduler.setPoolSize(poolSize);
|
||||||
|
return taskScheduler;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
119
src/main/java/com/shenghua/config/RedisConfig.java
Normal file
119
src/main/java/com/shenghua/config/RedisConfig.java
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
package com.shenghua.config;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
||||||
|
import com.fasterxml.jackson.annotation.PropertyAccessor;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import org.springframework.cache.CacheManager;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Primary;
|
||||||
|
import org.springframework.data.redis.cache.RedisCacheConfiguration;
|
||||||
|
import org.springframework.data.redis.cache.RedisCacheManager;
|
||||||
|
import org.springframework.data.redis.cache.RedisCacheWriter;
|
||||||
|
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||||
|
import org.springframework.data.redis.core.*;
|
||||||
|
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
|
||||||
|
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
|
||||||
|
//@RefreshScope
|
||||||
|
@Configuration
|
||||||
|
public class RedisConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
//如使用注解的话需要配置cacheManager
|
||||||
|
CacheManager cacheManager(RedisConnectionFactory connectionFactory) {
|
||||||
|
//初始化一个RedisCacheWriter
|
||||||
|
RedisCacheWriter redisCacheWriter = RedisCacheWriter.nonLockingRedisCacheWriter(connectionFactory);
|
||||||
|
RedisCacheConfiguration defaultCacheConfig = RedisCacheConfiguration.defaultCacheConfig();
|
||||||
|
//设置默认超过期时间是1天
|
||||||
|
//defaultCacheConfig.entryTtl(Duration.ofDays(1));
|
||||||
|
defaultCacheConfig.entryTtl(Duration.ofDays(-1));
|
||||||
|
//初始化RedisCacheManager
|
||||||
|
RedisCacheManager cacheManager = new RedisCacheManager(redisCacheWriter, defaultCacheConfig);
|
||||||
|
return cacheManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@Primary
|
||||||
|
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) {
|
||||||
|
|
||||||
|
RedisTemplate<String, Object> template = new RedisTemplate<>(); // 配置连接工厂
|
||||||
|
template.setConnectionFactory(factory); //使用Jackson2JsonRedisSerializer来序列化和反序列化redis的value值(默认使用JDK的序列化方式)
|
||||||
|
Jackson2JsonRedisSerializer jacksonSerial = new Jackson2JsonRedisSerializer(Object.class);
|
||||||
|
|
||||||
|
ObjectMapper om = new ObjectMapper(); // 指定要序列化的域,field,get和set,以及修饰符范围,ANY是都有包括private和public
|
||||||
|
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY); // 指定序列化输入的类型,类必须是非final修饰的,final修饰的类,比如String,Integer等会跑出异常
|
||||||
|
om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
|
||||||
|
jacksonSerial.setObjectMapper(om); // 值采用json序列化
|
||||||
|
template.setValueSerializer(jacksonSerial); //使用StringRedisSerializer来序列化和反序列化redis的key值
|
||||||
|
template.setKeySerializer(new StringRedisSerializer()); // 设置hash key 和value序列化模式
|
||||||
|
template.setHashKeySerializer(new StringRedisSerializer());
|
||||||
|
template.setHashValueSerializer(jacksonSerial);
|
||||||
|
template.afterPropertiesSet();
|
||||||
|
return template;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对hash类型的数据操作
|
||||||
|
*
|
||||||
|
* @param redisTemplate
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public HashOperations<String, String, Object> hashOperations(RedisTemplate<String, Object> redisTemplate) {
|
||||||
|
return redisTemplate.opsForHash();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对redis字符串类型数据操作
|
||||||
|
*
|
||||||
|
* @param redisTemplate
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public ValueOperations<String, Object> valueOperations(RedisTemplate<String, Object> redisTemplate) {
|
||||||
|
return redisTemplate.opsForValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对链表类型的数据操作
|
||||||
|
*
|
||||||
|
* @param redisTemplate
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public ListOperations<String, Object> listOperations(RedisTemplate<String, Object> redisTemplate) {
|
||||||
|
return redisTemplate.opsForList();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对无序集合类型的数据操作
|
||||||
|
*
|
||||||
|
* @param redisTemplate
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public SetOperations<String, Object> setOperations(RedisTemplate<String, Object> redisTemplate) {
|
||||||
|
return redisTemplate.opsForSet();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对有序集合类型的数据操作
|
||||||
|
*
|
||||||
|
* @param redisTemplate
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public ZSetOperations<String, Object> zSetOperations(RedisTemplate<String, Object> redisTemplate) {
|
||||||
|
return redisTemplate.opsForZSet();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
61
src/main/java/com/shenghua/config/SwaggerConfig.java
Normal file
61
src/main/java/com/shenghua/config/SwaggerConfig.java
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
package com.shenghua.config;
|
||||||
|
|
||||||
|
import com.shenghua.enums.AuthEnum;
|
||||||
|
import com.shenghua.enums.CommEnum;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
|
import springfox.documentation.builders.ApiInfoBuilder;
|
||||||
|
import springfox.documentation.builders.PathSelectors;
|
||||||
|
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||||
|
import springfox.documentation.builders.ResponseMessageBuilder;
|
||||||
|
import springfox.documentation.service.Contact;
|
||||||
|
import springfox.documentation.service.ResponseMessage;
|
||||||
|
import springfox.documentation.spi.DocumentationType;
|
||||||
|
import springfox.documentation.spring.web.plugins.Docket;
|
||||||
|
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@EnableSwagger2
|
||||||
|
public class SwaggerConfig {
|
||||||
|
|
||||||
|
@Value("http:localhost:${server.port:8081}")
|
||||||
|
private String url;
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Docket docketCommon() {
|
||||||
|
System.out.println("SwaggerConfig is loaded.");
|
||||||
|
List<ResponseMessage> responseMessageList = new ArrayList<>();
|
||||||
|
Arrays.stream(CommEnum.values()).forEach(enums -> {
|
||||||
|
responseMessageList.add(
|
||||||
|
new ResponseMessageBuilder().code(enums.getCode()).message(enums.getMessage()).build()
|
||||||
|
);
|
||||||
|
});
|
||||||
|
Arrays.stream(AuthEnum.values()).forEach(enums -> {
|
||||||
|
responseMessageList.add(
|
||||||
|
new ResponseMessageBuilder().code(enums.getCode()).message(enums.getMessage()).build()
|
||||||
|
);
|
||||||
|
});
|
||||||
|
return new Docket(DocumentationType.SWAGGER_2)
|
||||||
|
.globalResponseMessage(RequestMethod.GET, responseMessageList)
|
||||||
|
.globalResponseMessage(RequestMethod.POST, responseMessageList)
|
||||||
|
.globalResponseMessage(RequestMethod.PUT, responseMessageList)
|
||||||
|
.globalResponseMessage(RequestMethod.DELETE, responseMessageList)
|
||||||
|
.groupName("shenghua").select()
|
||||||
|
.apis(RequestHandlerSelectors.basePackage("com.shenghua.controller"))
|
||||||
|
.paths(PathSelectors.any())
|
||||||
|
.build()
|
||||||
|
.apiInfo(new ApiInfoBuilder().
|
||||||
|
title("shenghua Restful API").
|
||||||
|
description("接口API").
|
||||||
|
contact(new Contact("", "", "")).termsOfServiceUrl(url).
|
||||||
|
version("1.0").
|
||||||
|
build());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
24
src/main/java/com/shenghua/config/TransDataSourceConfig.java
Normal file
24
src/main/java/com/shenghua/config/TransDataSourceConfig.java
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
package com.shenghua.config;
|
||||||
|
|
||||||
|
import com.alibaba.druid.pool.DruidDataSource;
|
||||||
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Primary;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@MapperScan(basePackages = "com.shenghua.mapper")
|
||||||
|
public class TransDataSourceConfig {
|
||||||
|
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@Primary
|
||||||
|
@ConfigurationProperties(prefix = "spring.datasource")
|
||||||
|
public DataSource getDataSource() {
|
||||||
|
return new DruidDataSource();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
package com.shenghua.config;
|
||||||
|
|
||||||
|
import com.shenghua.entitys.Result;
|
||||||
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||||
|
|
||||||
|
@RestControllerAdvice
|
||||||
|
public class UnifiedResultErrorConfig {
|
||||||
|
|
||||||
|
@ExceptionHandler(value = RuntimeException.class)
|
||||||
|
public Result exception(RuntimeException e){
|
||||||
|
e.printStackTrace();
|
||||||
|
return Result.error();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
33
src/main/java/com/shenghua/config/WebConfiguration.java
Normal file
33
src/main/java/com/shenghua/config/WebConfiguration.java
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
package com.shenghua.config;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||||
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class WebConfiguration implements WebMvcConfigurer {
|
||||||
|
|
||||||
|
// @Override
|
||||||
|
//public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||||
|
// // 新增对 /static/images/** 的支持
|
||||||
|
// registry.addResourceHandler("/images/**")
|
||||||
|
// .addResourceLocations("file:C:/upload/images/");
|
||||||
|
//
|
||||||
|
//// // 通用路径放最后
|
||||||
|
//// registry.addResourceHandler("/**")
|
||||||
|
//// .addResourceLocations("classpath:/static/");
|
||||||
|
//}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||||
|
registry.addResourceHandler("/doc.html**")
|
||||||
|
.addResourceLocations("classpath:/META-INF/resources/");
|
||||||
|
|
||||||
|
registry.addResourceHandler("/webjars/**")
|
||||||
|
.addResourceLocations("classpath:/META-INF/resources/webjars/");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
65
src/main/java/com/shenghua/controller/CaseController.java
Normal file
65
src/main/java/com/shenghua/controller/CaseController.java
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
package com.shenghua.controller;
|
||||||
|
|
||||||
|
import com.shenghua.dto.CaseArticleDTO;
|
||||||
|
import com.shenghua.entitys.CaseArticle;
|
||||||
|
import com.shenghua.entitys.CaseArticleCategory;
|
||||||
|
import com.shenghua.entitys.Page;
|
||||||
|
import com.shenghua.entitys.Result;
|
||||||
|
import com.shenghua.service.CaseArticleService;
|
||||||
|
import com.shenghua.vo.CaseArticleVO;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiImplicitParam;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/case")
|
||||||
|
@Api(tags = "案例中心")
|
||||||
|
public class CaseController {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CaseArticleService caseArticleService;
|
||||||
|
|
||||||
|
@PostMapping("/queryPage" )
|
||||||
|
@ApiOperation(value = "分页查询案例列表")
|
||||||
|
public Result<Page<List<CaseArticle>>> queryPage(@RequestBody CaseArticleDTO dto){
|
||||||
|
Page<List<CaseArticle>> listPage = caseArticleService.queryPage(dto);
|
||||||
|
return Result.success(listPage);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@GetMapping("/getCategory" )
|
||||||
|
@ApiOperation(value = "案例分类")
|
||||||
|
public Result<Page<List<CaseArticle>>> getCategory(){
|
||||||
|
List<CaseArticleCategory> listCategory = caseArticleService.getCategory();
|
||||||
|
return Result.success(listCategory);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/save" )
|
||||||
|
@ApiOperation(value = "新增案例文章")
|
||||||
|
public Result save(@RequestBody CaseArticle category){
|
||||||
|
boolean save = caseArticleService.save(category);
|
||||||
|
if (!save){
|
||||||
|
return Result.fail();
|
||||||
|
}
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/getAll" )
|
||||||
|
@ApiOperation(value = "全部案例文章")
|
||||||
|
public Result<List<CaseArticleVO>> getAll(){
|
||||||
|
return Result.success(caseArticleService.getAll());
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/getDetail")
|
||||||
|
@ApiImplicitParam(value = "ID", name = "id", paramType = "query", required = true)
|
||||||
|
@ApiOperation(value = "按新闻ID查询新闻详情")
|
||||||
|
public Result<CaseArticleVO> getNewsById(Integer id){
|
||||||
|
return Result.success(caseArticleService.getNewsById(id));
|
||||||
|
}
|
||||||
|
}
|
31
src/main/java/com/shenghua/controller/ContactController.java
Normal file
31
src/main/java/com/shenghua/controller/ContactController.java
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
package com.shenghua.controller;
|
||||||
|
|
||||||
|
|
||||||
|
import com.shenghua.annotations.Valid;
|
||||||
|
import com.shenghua.convert.MessageBoardConvert;
|
||||||
|
import com.shenghua.dto.MessageBoardDTO;
|
||||||
|
import com.shenghua.entitys.MessageBoard;
|
||||||
|
import com.shenghua.entitys.Result;
|
||||||
|
import com.shenghua.entitys.SolutionContact;
|
||||||
|
import com.shenghua.mapper.MessageBoardMapper;
|
||||||
|
import com.shenghua.service.SolutionService;
|
||||||
|
import com.shenghua.vo.ProductVO;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/contact")
|
||||||
|
@Api(tags = "联系我们api")
|
||||||
|
public class ContactController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MessageBoardMapper messageBoardMapper;
|
||||||
|
|
||||||
|
@PostMapping("/save")
|
||||||
|
@ApiOperation("保存联系信息")
|
||||||
|
public Result<ProductVO> addContact(@Valid @RequestBody MessageBoardDTO dto){
|
||||||
|
return Result.success(messageBoardMapper.insert(MessageBoardConvert.convert(dto))) ;
|
||||||
|
}
|
||||||
|
}
|
41
src/main/java/com/shenghua/controller/IndexController.java
Normal file
41
src/main/java/com/shenghua/controller/IndexController.java
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
package com.shenghua.controller;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import org.springframework.core.io.ClassPathResource;
|
||||||
|
import org.springframework.util.StreamUtils;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import com.shenghua.entitys.Result;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/index")
|
||||||
|
@Api(tags = "首页api")
|
||||||
|
public class IndexController {
|
||||||
|
|
||||||
|
@GetMapping("/config")
|
||||||
|
@ApiOperation(value = "首页产品列表")
|
||||||
|
public Result getWebConfig() throws JsonProcessingException {
|
||||||
|
// 加载 resources 目录下的 jsonConfig.json 文件
|
||||||
|
ClassPathResource resource = new ClassPathResource("jsonConfig/index.json");
|
||||||
|
|
||||||
|
// 使用 Jackson 解析 JSON 数据
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
String jsonData = null;
|
||||||
|
try {
|
||||||
|
jsonData = StreamUtils.copyToString(resource.getInputStream(), StandardCharsets.UTF_8);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 假设你的 JSON 是一个 Map 结构
|
||||||
|
return Result.success(objectMapper.readValue(jsonData, new TypeReference<Object>() {}));
|
||||||
|
}
|
||||||
|
}
|
89
src/main/java/com/shenghua/controller/NewsController.java
Normal file
89
src/main/java/com/shenghua/controller/NewsController.java
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
package com.shenghua.controller;
|
||||||
|
|
||||||
|
import com.shenghua.dto.PageDto;
|
||||||
|
import com.shenghua.entitys.Page;
|
||||||
|
import com.shenghua.entitys.Result;
|
||||||
|
import com.shenghua.entitys.news.News;
|
||||||
|
import com.shenghua.service.NewsService;
|
||||||
|
import com.shenghua.utils.ConstantUtil;
|
||||||
|
import com.shenghua.vo.NewsVo;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiImplicitParam;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/news")
|
||||||
|
@Api(tags = "新闻api")
|
||||||
|
public class NewsController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private NewsService newsService;
|
||||||
|
|
||||||
|
// @PostMapping("/getAllNewsByCategoryId")
|
||||||
|
// @ApiOperation(value = "按分类ID查询新闻列表")
|
||||||
|
// public Result<Page<List<NewsVo>>> getAllNewsByCategoryId(@RequestBody NewsDto newsDto){
|
||||||
|
// if(newsDto==null){
|
||||||
|
// return null;
|
||||||
|
// }
|
||||||
|
// return Result.success(newsService.getAllNewsByCategoryId(newsDto));
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @GetMapping("/getCategoryByNews")
|
||||||
|
// @ApiOperation(value = "新闻分类")
|
||||||
|
// public Result<List<CategoryVo>> getCategoryByNews(){
|
||||||
|
// return Result.success(newsService.getCategoryByNews());
|
||||||
|
// }
|
||||||
|
|
||||||
|
@PostMapping("/query")
|
||||||
|
@ApiOperation(value = "分页查询新闻列表")
|
||||||
|
public Result<Page<List<NewsVo>>> query(@RequestBody PageDto page){
|
||||||
|
Page<List<NewsVo>> listPage = newsService.queryList(page);
|
||||||
|
return Result.success(listPage);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/getNewsById")
|
||||||
|
@ApiImplicitParam(value = "ID", name = "id", paramType = "query", required = true)
|
||||||
|
@ApiOperation(value = "按新闻ID查询新闻详情")
|
||||||
|
public Result<NewsVo> getNewsById(Integer id){
|
||||||
|
return Result.success(newsService.getNewsById(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/save")
|
||||||
|
@ApiOperation(value = "保存新闻")
|
||||||
|
public Result<Boolean> saveNews(@RequestBody News news) {
|
||||||
|
newsService.saveNews(news);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/upload/image")
|
||||||
|
@ApiOperation(value = "上传图片")
|
||||||
|
public Result<String> uploadImage(@RequestParam("file") MultipartFile file) {
|
||||||
|
if (file.isEmpty()) {
|
||||||
|
return Result.fail("文件为空");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
// 保存文件到服务器(示例:保存到本地目录)
|
||||||
|
String originalFilename = file.getOriginalFilename();
|
||||||
|
String suffix = originalFilename.substring(originalFilename.lastIndexOf("."));
|
||||||
|
String fileName = UUID.randomUUID()+ suffix;
|
||||||
|
String filePath = ConstantUtil.IMAGE_PATH + fileName; // 替换为实际路径
|
||||||
|
|
||||||
|
file.transferTo(new java.io.File(filePath));
|
||||||
|
|
||||||
|
// 返回图片访问 URL(示例:假设图片存储在静态资源目录下)
|
||||||
|
String imageUrl = ConstantUtil.IMAGE_URL + fileName;
|
||||||
|
return Result.success(imageUrl);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return Result.fail("上传失败:" + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
47
src/main/java/com/shenghua/controller/ProductController.java
Normal file
47
src/main/java/com/shenghua/controller/ProductController.java
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
package com.shenghua.controller;
|
||||||
|
|
||||||
|
import com.shenghua.dto.PageDto;
|
||||||
|
import com.shenghua.dto.ProductDTO;
|
||||||
|
import com.shenghua.entitys.Page;
|
||||||
|
import com.shenghua.entitys.Result;
|
||||||
|
import com.shenghua.entitys.product.ProductCategory;
|
||||||
|
import com.shenghua.service.ProductService;
|
||||||
|
import com.shenghua.vo.NewsVo;
|
||||||
|
import com.shenghua.vo.ProductVO;
|
||||||
|
import io.swagger.annotations.*;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/product")
|
||||||
|
@Api(tags = "产品api")
|
||||||
|
public class ProductController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ProductService productService;
|
||||||
|
|
||||||
|
@GetMapping("/getDetail")
|
||||||
|
@ApiImplicitParam(value = "ID", name = "id", paramType = "query", required = true)
|
||||||
|
@ApiResponses({
|
||||||
|
@ApiResponse(code = 200, message = "成功", response = ProductVO.class)
|
||||||
|
})
|
||||||
|
public Result<ProductVO> getDetail(Integer id){
|
||||||
|
ProductVO vo = productService.getDetail(id);
|
||||||
|
return Result.success(vo);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/queryList")
|
||||||
|
@ApiOperation("分页查询产品列表")
|
||||||
|
public Result<List<ProductVO>> queryList(@RequestBody ProductDTO dto){
|
||||||
|
return Result.success(productService.queryList(dto)) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/category")
|
||||||
|
@ApiOperation("产品分类")
|
||||||
|
public Result<List<ProductCategory>> queryCategory(){
|
||||||
|
return Result.success(productService.queryCategory()) ;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
package com.shenghua.controller;
|
||||||
|
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
|
import com.shenghua.dto.SolutionContactDTO;
|
||||||
|
import com.shenghua.entitys.Result;
|
||||||
|
import com.shenghua.service.SolutionService;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/solution")
|
||||||
|
@Api(tags = "解决api")
|
||||||
|
public class SolutionController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SolutionService solutionService;
|
||||||
|
|
||||||
|
@PostMapping("/addContact")
|
||||||
|
@ApiOperation("提交联系信息")
|
||||||
|
public Result addContact(@Valid @RequestBody SolutionContactDTO contact){
|
||||||
|
solutionService.addContact(contact);
|
||||||
|
return Result.success() ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
28
src/main/java/com/shenghua/convert/CaseArticleConvert.java
Normal file
28
src/main/java/com/shenghua/convert/CaseArticleConvert.java
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
package com.shenghua.convert;
|
||||||
|
|
||||||
|
import com.shenghua.entitys.CaseArticle;
|
||||||
|
import com.shenghua.vo.CaseArticleVO;
|
||||||
|
|
||||||
|
public class CaseArticleConvert {
|
||||||
|
|
||||||
|
public static CaseArticleVO convertToVO(CaseArticle caseArticle) {
|
||||||
|
CaseArticleVO caseArticleVO = new CaseArticleVO();
|
||||||
|
|
||||||
|
caseArticleVO.setId(caseArticle.getId());
|
||||||
|
caseArticleVO.setCategoryId(caseArticle.getCategoryId());
|
||||||
|
caseArticleVO.setTitle(caseArticle.getTitle());
|
||||||
|
caseArticleVO.setCover(caseArticle.getCover());
|
||||||
|
caseArticleVO.setSummary(caseArticle.getSummary());
|
||||||
|
caseArticleVO.setContent(caseArticle.getContent());
|
||||||
|
caseArticleVO.setSort(caseArticle.getSort());
|
||||||
|
caseArticleVO.setStatus(caseArticle.getStatus());
|
||||||
|
caseArticleVO.setIsRecommend(caseArticle.getIsRecommend());
|
||||||
|
caseArticleVO.setCreateTime(caseArticle.getCreateTime());
|
||||||
|
caseArticleVO.setUpdateTime(caseArticle.getUpdateTime());
|
||||||
|
caseArticleVO.setSeoTitle(caseArticle.getSeoTitle());
|
||||||
|
caseArticleVO.setSeoDescription(caseArticle.getSeoDescription());
|
||||||
|
caseArticleVO.setSeoKeywords(caseArticle.getSeoKeywords());
|
||||||
|
|
||||||
|
return caseArticleVO;
|
||||||
|
}
|
||||||
|
}
|
17
src/main/java/com/shenghua/convert/MessageBoardConvert.java
Normal file
17
src/main/java/com/shenghua/convert/MessageBoardConvert.java
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package com.shenghua.convert;
|
||||||
|
|
||||||
|
import com.shenghua.dto.MessageBoardDTO;
|
||||||
|
import com.shenghua.entitys.MessageBoard;
|
||||||
|
|
||||||
|
public class MessageBoardConvert {
|
||||||
|
|
||||||
|
public static MessageBoard convert(MessageBoardDTO dto)
|
||||||
|
{
|
||||||
|
MessageBoard messageBoard = new MessageBoard();
|
||||||
|
messageBoard.setName(dto.getName());
|
||||||
|
messageBoard.setPhone(dto.getPhone());
|
||||||
|
messageBoard.setRegion(dto.getRegion());
|
||||||
|
messageBoard.setContent(dto.getContent());
|
||||||
|
return messageBoard;
|
||||||
|
}
|
||||||
|
}
|
26
src/main/java/com/shenghua/convert/NewConvert.java
Normal file
26
src/main/java/com/shenghua/convert/NewConvert.java
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package com.shenghua.convert;
|
||||||
|
|
||||||
|
import com.shenghua.entitys.news.News;
|
||||||
|
import com.shenghua.vo.NewsVo;
|
||||||
|
|
||||||
|
|
||||||
|
public class NewConvert {
|
||||||
|
public static NewsVo convertVO(News news) {
|
||||||
|
if (news == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
NewsVo newsVo = new NewsVo();
|
||||||
|
newsVo.setId(news.getId());
|
||||||
|
newsVo.setCategoryId(news.getCategoryId());
|
||||||
|
newsVo.setTitle(news.getTitle());
|
||||||
|
newsVo.setCover(news.getCover());
|
||||||
|
newsVo.setContent(news.getContent());
|
||||||
|
newsVo.setSeoTitle(news.getSeoTitle());
|
||||||
|
newsVo.setSeoKeywords(news.getSeoKeywords());
|
||||||
|
newsVo.setSeoDescription(news.getSeoDescription());
|
||||||
|
newsVo.setCreateTime(news.getCreateTime());
|
||||||
|
|
||||||
|
return newsVo;
|
||||||
|
}
|
||||||
|
}
|
46
src/main/java/com/shenghua/convert/ProductConvert.java
Normal file
46
src/main/java/com/shenghua/convert/ProductConvert.java
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
package com.shenghua.convert;
|
||||||
|
|
||||||
|
import com.shenghua.entitys.product.Product;
|
||||||
|
import com.shenghua.vo.ProductVO;
|
||||||
|
import org.apache.htrace.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class ProductConvert {
|
||||||
|
public static ProductVO convertVO(Product product){
|
||||||
|
ProductVO productVO = new ProductVO();
|
||||||
|
productVO.setId(product.getId());
|
||||||
|
productVO.setName(product.getName());
|
||||||
|
productVO.setCategoryId(product.getCategoryId());
|
||||||
|
if (Objects.nonNull(product.getTypeArr())) {
|
||||||
|
String[] typeArr = convertJsonStringToArray(product.getTypeArr());
|
||||||
|
productVO.setTypeArr(typeArr);
|
||||||
|
}
|
||||||
|
productVO.setCover(product.getCover());
|
||||||
|
productVO.setImgsRelationId(product.getImgsRelationId());
|
||||||
|
productVO.setContent(product.getContent());
|
||||||
|
productVO.setPrice(product.getPrice());
|
||||||
|
productVO.setSeoTitle(product.getSeoTitle());
|
||||||
|
productVO.setSpecsId(product.getSpecsId());
|
||||||
|
|
||||||
|
// if (Objects.nonNull(product.getOtherSpecs())){
|
||||||
|
// String[] specsArray = convertJsonStringToArray(product.getOtherSpecs());
|
||||||
|
// productVO.setOtherSpecs(specsArray);
|
||||||
|
// }
|
||||||
|
productVO.setSeoDescription(product.getSeoDescription());
|
||||||
|
productVO.setSeoKeywords(product.getSeoKeywords());
|
||||||
|
productVO.setCreateTime(product.getCreateTime());
|
||||||
|
productVO.setUpdateTime(product.getUpdateTime());
|
||||||
|
return productVO;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String[] convertJsonStringToArray(String jsonStr) {
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
try {
|
||||||
|
return objectMapper.readValue(jsonStr, String[].class);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
package com.shenghua.convert;
|
||||||
|
|
||||||
|
import com.shenghua.dto.SolutionContactDTO;
|
||||||
|
import com.shenghua.entitys.SolutionContact;
|
||||||
|
|
||||||
|
public class SolutionContactConvert {
|
||||||
|
|
||||||
|
public static SolutionContact convert(SolutionContactDTO dto) {
|
||||||
|
SolutionContact contact = new SolutionContact();
|
||||||
|
contact.setName(dto.getName());
|
||||||
|
contact.setPhone(dto.getPhone());
|
||||||
|
return contact;
|
||||||
|
}
|
||||||
|
}
|
12
src/main/java/com/shenghua/dto/CaseArticleDTO.java
Normal file
12
src/main/java/com/shenghua/dto/CaseArticleDTO.java
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
package com.shenghua.dto;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
|
||||||
|
public class CaseArticleDTO extends PageDto{
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "分类id",required = true)
|
||||||
|
private Integer categoryId;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "典型案例,传1 返回典型案例",required = true)
|
||||||
|
private Integer recommend;
|
||||||
|
}
|
10
src/main/java/com/shenghua/dto/IdDto.java
Normal file
10
src/main/java/com/shenghua/dto/IdDto.java
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package com.shenghua.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class IdDto {
|
||||||
|
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
}
|
28
src/main/java/com/shenghua/dto/MessageBoardDTO.java
Normal file
28
src/main/java/com/shenghua/dto/MessageBoardDTO.java
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
package com.shenghua.dto;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.shenghua.annotations.NotNull;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
@Data
|
||||||
|
public class MessageBoardDTO {
|
||||||
|
@TableField("name")
|
||||||
|
@ApiModelProperty(value = "姓名")
|
||||||
|
@NotNull
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@TableField("phone")
|
||||||
|
@ApiModelProperty(value = "电话")
|
||||||
|
@NotNull
|
||||||
|
private String phone;
|
||||||
|
|
||||||
|
@TableField("region")
|
||||||
|
@ApiModelProperty(value = "地区")
|
||||||
|
@NotNull
|
||||||
|
private String region;
|
||||||
|
|
||||||
|
@TableField("content")
|
||||||
|
@ApiModelProperty(value = "留言内容")
|
||||||
|
@NotNull
|
||||||
|
private String content;
|
||||||
|
}
|
17
src/main/java/com/shenghua/dto/NewsDto.java
Normal file
17
src/main/java/com/shenghua/dto/NewsDto.java
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package com.shenghua.dto;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class NewsDto {
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "分类ID")
|
||||||
|
private Integer categoryId;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "起始页",required = true)
|
||||||
|
private Integer pageNum;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "一页数量",required = true)
|
||||||
|
private Integer pageSize;
|
||||||
|
}
|
20
src/main/java/com/shenghua/dto/PageDto.java
Normal file
20
src/main/java/com/shenghua/dto/PageDto.java
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package com.shenghua.dto;
|
||||||
|
|
||||||
|
import com.shenghua.annotations.NotNull;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class PageDto {
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "起始页",required = true)
|
||||||
|
@NotNull
|
||||||
|
private Integer pageNum;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "一页数量",required = true)
|
||||||
|
@NotNull
|
||||||
|
private Integer pageSize;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "分类",required = true)
|
||||||
|
private Integer categoryId;
|
||||||
|
}
|
11
src/main/java/com/shenghua/dto/ProductDTO.java
Normal file
11
src/main/java/com/shenghua/dto/ProductDTO.java
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
package com.shenghua.dto;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ProductDTO {
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "分类id",required = true)
|
||||||
|
private Integer categoryId;
|
||||||
|
}
|
24
src/main/java/com/shenghua/dto/SolutionContactDTO.java
Normal file
24
src/main/java/com/shenghua/dto/SolutionContactDTO.java
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
package com.shenghua.dto;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.shenghua.annotations.NotNull;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
import javax.validation.constraints.Pattern;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class SolutionContactDTO {
|
||||||
|
|
||||||
|
@TableField("name")
|
||||||
|
@ApiModelProperty(value = "姓名")
|
||||||
|
@NotBlank(message = "姓名不能为空")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@TableField("phone")
|
||||||
|
@ApiModelProperty(value = "手机")
|
||||||
|
@NotNull(message = "手机不能为空")
|
||||||
|
@Pattern(regexp = "^1[3-9]\\d{9}$", message = "手机号格式不正确")
|
||||||
|
private String phone;
|
||||||
|
}
|
72
src/main/java/com/shenghua/entitys/CaseArticle.java
Normal file
72
src/main/java/com/shenghua/entitys/CaseArticle.java
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
package com.shenghua.entitys;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@TableName("case_article")
|
||||||
|
@ApiModel("案例文章表")
|
||||||
|
public class CaseArticle {
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "主键ID")
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@TableField("category_id")
|
||||||
|
@ApiModelProperty(value = "分类ID", example = "15")
|
||||||
|
private Integer categoryId;
|
||||||
|
|
||||||
|
@TableField("title")
|
||||||
|
@ApiModelProperty(value = "标题(150字内)", required = true, example = "产品案例分享")
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
@TableField("cover")
|
||||||
|
@ApiModelProperty(value = "封面地址", example = "https://example.com/cover.jpg")
|
||||||
|
private String cover;
|
||||||
|
|
||||||
|
@TableField("summary")
|
||||||
|
@ApiModelProperty(value = "简介(255字内)", required = true, example = "典型案例展示")
|
||||||
|
private String summary;
|
||||||
|
|
||||||
|
@TableField("content")
|
||||||
|
@ApiModelProperty(value = "详细内容")
|
||||||
|
private String content;
|
||||||
|
|
||||||
|
@TableField("sort")
|
||||||
|
@ApiModelProperty(value = "排序值,越大越靠前", example = "999")
|
||||||
|
private Integer sort = 0;
|
||||||
|
|
||||||
|
@TableField("status")
|
||||||
|
@ApiModelProperty(value = "状态 0:下架 1:发布", example = "1")
|
||||||
|
private Integer status = 0;
|
||||||
|
|
||||||
|
@TableField("is_recommend")
|
||||||
|
@ApiModelProperty(value = "是否推荐 0:否 1:是", example = "1")
|
||||||
|
private Integer isRecommend = 0;
|
||||||
|
|
||||||
|
@TableField("create_time")
|
||||||
|
@ApiModelProperty(value = "创建时间", example = "2025-06-13 17:35:00")
|
||||||
|
private Date createTime;
|
||||||
|
|
||||||
|
@TableField("update_time")
|
||||||
|
@ApiModelProperty(value = "修改时间", example = "2025-06-13 17:40:00")
|
||||||
|
private Date updateTime;
|
||||||
|
|
||||||
|
@TableField("seoTitle")
|
||||||
|
@ApiModelProperty(value = "SEO标题(255字内)")
|
||||||
|
private String seoTitle;
|
||||||
|
|
||||||
|
@TableField("seoDescription")
|
||||||
|
@ApiModelProperty(value = "SEO描述(长文本)")
|
||||||
|
private String seoDescription;
|
||||||
|
|
||||||
|
@TableField("seoKeywords")
|
||||||
|
@ApiModelProperty(value = "SEO关键词(255字内)")
|
||||||
|
private String seoKeywords;
|
||||||
|
}
|
26
src/main/java/com/shenghua/entitys/CaseArticleCategory.java
Normal file
26
src/main/java/com/shenghua/entitys/CaseArticleCategory.java
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package com.shenghua.entitys;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@TableName("case_article_category")
|
||||||
|
@ApiModel("案例文章表")
|
||||||
|
public class CaseArticleCategory {
|
||||||
|
|
||||||
|
@TableId(type = IdType.AUTO)
|
||||||
|
@ApiModelProperty(value = "主键ID")
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@TableId(type = IdType.AUTO)
|
||||||
|
@ApiModelProperty(value = "名称", example = "军事")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@TableId(type = IdType.AUTO)
|
||||||
|
@ApiModelProperty(value = "名称", example = "军事")
|
||||||
|
private String tag;
|
||||||
|
}
|
40
src/main/java/com/shenghua/entitys/MessageBoard.java
Normal file
40
src/main/java/com/shenghua/entitys/MessageBoard.java
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
package com.shenghua.entitys;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@TableName("message_board")
|
||||||
|
@ApiModel("留言表")
|
||||||
|
public class MessageBoard {
|
||||||
|
@TableId(type = IdType.AUTO)
|
||||||
|
@ApiModelProperty(value = "留言ID")
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@TableField("name")
|
||||||
|
@ApiModelProperty(value = "姓名")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@TableField("phone")
|
||||||
|
@ApiModelProperty(value = "电话")
|
||||||
|
private String phone;
|
||||||
|
|
||||||
|
@TableField("region")
|
||||||
|
@ApiModelProperty(value = "地区")
|
||||||
|
private String region;
|
||||||
|
|
||||||
|
@TableField("content")
|
||||||
|
@ApiModelProperty(value = "留言内容")
|
||||||
|
private String content;
|
||||||
|
|
||||||
|
@TableField("create_time")
|
||||||
|
@ApiModelProperty(value = "提交时间")
|
||||||
|
private Timestamp createTime;
|
||||||
|
}
|
119
src/main/java/com/shenghua/entitys/Page.java
Normal file
119
src/main/java/com/shenghua/entitys/Page.java
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
package com.shenghua.entitys;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
|
||||||
|
public class Page<T> {
|
||||||
|
|
||||||
|
@ApiModelProperty("当前页数")
|
||||||
|
private int pageNum;
|
||||||
|
|
||||||
|
@ApiModelProperty("总记录数")
|
||||||
|
private int total;
|
||||||
|
|
||||||
|
@ApiModelProperty("总页数")
|
||||||
|
private int pageTotal;
|
||||||
|
|
||||||
|
@ApiModelProperty("一页记录数")
|
||||||
|
private int pageSize;
|
||||||
|
|
||||||
|
@ApiModelProperty("当前页记录数")
|
||||||
|
private int size;
|
||||||
|
|
||||||
|
@ApiModelProperty("是否还有下一页")
|
||||||
|
private boolean hasNext;
|
||||||
|
|
||||||
|
@ApiModelProperty("数据记录")
|
||||||
|
private T data;
|
||||||
|
|
||||||
|
public Page(int pageNum, int total, int pageSize, T data){
|
||||||
|
this.pageNum=pageNum;
|
||||||
|
this.pageSize=pageSize;
|
||||||
|
this.total = total;
|
||||||
|
this.data=data;
|
||||||
|
int model=total%pageSize;
|
||||||
|
boolean bool=model==0;
|
||||||
|
int pageTotal=bool?total/pageSize:total/pageSize+1;
|
||||||
|
this.pageTotal=pageTotal;
|
||||||
|
if(pageTotal>pageNum){
|
||||||
|
this.hasNext=true;
|
||||||
|
this.size=pageSize;
|
||||||
|
}else if(pageTotal==pageNum){
|
||||||
|
this.size=bool?pageSize:model;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Page(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Integer getStartNum(Integer pageNum, Integer pageSize){
|
||||||
|
return (pageNum-1)*pageSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String sqlLimit(Integer pageNum, Integer pageSize){
|
||||||
|
Integer startNum=getStartNum(pageNum,pageSize);
|
||||||
|
return "LIMIT "+startNum+","+pageSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPageNum() {
|
||||||
|
return pageNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPageNum(int pageNum) {
|
||||||
|
this.pageNum = pageNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTotal() {
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTotal(int total) {
|
||||||
|
int pageTotal=total%pageSize==0?total/pageSize:total/pageSize+1;
|
||||||
|
this.pageTotal=pageTotal;
|
||||||
|
if(pageTotal>pageNum){
|
||||||
|
hasNext=true;
|
||||||
|
}
|
||||||
|
this.total = total;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPageTotal() {
|
||||||
|
return pageTotal;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPageTotal(int pageTotal) {
|
||||||
|
this.pageTotal = pageTotal;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPageSize() {
|
||||||
|
return pageSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPageSize(int pageSize) {
|
||||||
|
this.pageSize = pageSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isHasNext() {
|
||||||
|
return hasNext;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHasNext(boolean hasNext) {
|
||||||
|
this.hasNext = hasNext;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T getData() {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setData(T data) {
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSize() {
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSize(int size) {
|
||||||
|
this.size = size;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
110
src/main/java/com/shenghua/entitys/Result.java
Normal file
110
src/main/java/com/shenghua/entitys/Result.java
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
package com.shenghua.entitys;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.alibaba.fastjson.serializer.SerializeConfig;
|
||||||
|
import com.shenghua.enums.CommEnum;
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@ApiModel(description = "统一返回")
|
||||||
|
public class Result<T> {
|
||||||
|
|
||||||
|
@ApiModelProperty("数据")
|
||||||
|
private T data;
|
||||||
|
@ApiModelProperty("请求状态码")
|
||||||
|
private int code;
|
||||||
|
@ApiModelProperty("消息")
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
private Result(int code, String message, T data) {
|
||||||
|
this.code = code;
|
||||||
|
this.message = message;
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Result(int code, String message) {
|
||||||
|
this.code = code;
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Result(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static Result success() {
|
||||||
|
CommEnum e= CommEnum.SUCCESS;
|
||||||
|
int code=e.getCode();
|
||||||
|
String message=e.getMessage();
|
||||||
|
return new Result(code,message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Result success(T data) {
|
||||||
|
CommEnum e= CommEnum.SUCCESS;
|
||||||
|
int code=e.getCode();
|
||||||
|
String message=e.getMessage();
|
||||||
|
return new Result<T>(code,message,data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Result fail(String message) {
|
||||||
|
CommEnum e= CommEnum.FAIL;
|
||||||
|
int code=e.getCode();
|
||||||
|
return new Result(code,message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Result fail() {
|
||||||
|
CommEnum e= CommEnum.FAIL;
|
||||||
|
int code=e.getCode();
|
||||||
|
String message=e.getMessage();
|
||||||
|
return new Result(code,message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Result fail(Enum e){
|
||||||
|
SerializeConfig config = new SerializeConfig();
|
||||||
|
config.configEnumAsJavaBean(e.getClass());
|
||||||
|
String json= JSON.toJSONString(e,config);
|
||||||
|
JSONObject jsonObject=JSON.parseObject(json);
|
||||||
|
int code=jsonObject.getIntValue("code");
|
||||||
|
String message=jsonObject.getString("message");
|
||||||
|
return new Result(code,message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Result fail(Enum e, T data){
|
||||||
|
SerializeConfig config = new SerializeConfig();
|
||||||
|
config.configEnumAsJavaBean(e.getClass());
|
||||||
|
String json= JSON.toJSONString(e,config);
|
||||||
|
JSONObject jsonObject=JSON.parseObject(json);
|
||||||
|
int code=jsonObject.getIntValue("code");
|
||||||
|
String message=jsonObject.getString("message");
|
||||||
|
return new Result<T>(code,message,data);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static Result isEmpty(){
|
||||||
|
CommEnum e= CommEnum.EMPTY_PARAM;
|
||||||
|
int code=e.getCode();
|
||||||
|
String message=e.getMessage();
|
||||||
|
return new Result(code,message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Result isEmpty(String message){
|
||||||
|
CommEnum e= CommEnum.EMPTY_PARAM;
|
||||||
|
int code=e.getCode();
|
||||||
|
return new Result(code,message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Result error(){
|
||||||
|
CommEnum e= CommEnum.ERROR;
|
||||||
|
int code=e.getCode();
|
||||||
|
return new Result(code,e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString(){
|
||||||
|
return JSON.toJSONString(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
4
src/main/java/com/shenghua/entitys/Solution.java
Normal file
4
src/main/java/com/shenghua/entitys/Solution.java
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
package com.shenghua.entitys;
|
||||||
|
|
||||||
|
public class Solution {
|
||||||
|
}
|
30
src/main/java/com/shenghua/entitys/SolutionContact.java
Normal file
30
src/main/java/com/shenghua/entitys/SolutionContact.java
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package com.shenghua.entitys;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.shenghua.annotations.NotNull;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@TableName("solution_contact")
|
||||||
|
@Api(tags = "解决方案联系表")
|
||||||
|
public class SolutionContact {
|
||||||
|
|
||||||
|
@TableId(type = IdType.AUTO)
|
||||||
|
@ApiModelProperty(value = "主键ID")
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@TableField("name")
|
||||||
|
@ApiModelProperty(value = "姓名")
|
||||||
|
@NotNull
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@TableField("phone")
|
||||||
|
@ApiModelProperty(value = "手机")
|
||||||
|
@NotNull
|
||||||
|
private String phone;
|
||||||
|
}
|
28
src/main/java/com/shenghua/entitys/category/Category.java
Normal file
28
src/main/java/com/shenghua/entitys/category/Category.java
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
package com.shenghua.entitys.category;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@TableName("dx_category")
|
||||||
|
@Api(tags = "分类表")
|
||||||
|
public class Category {
|
||||||
|
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "分类名")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "分类")
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "图片")
|
||||||
|
private String image;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "创建时间")
|
||||||
|
private Date createTime;
|
||||||
|
}
|
31
src/main/java/com/shenghua/entitys/home/Banner.java
Normal file
31
src/main/java/com/shenghua/entitys/home/Banner.java
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
package com.shenghua.entitys.home;
|
||||||
|
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@TableName("dx_banner")
|
||||||
|
@Api(tags = "轮播图表")
|
||||||
|
public class Banner {
|
||||||
|
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "图片路径")
|
||||||
|
private String image;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "是否显示 1:显示 0:不显示")
|
||||||
|
private Integer isDisplay;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "分类ID")
|
||||||
|
private Integer categoryId;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "创建时间")
|
||||||
|
private Date createTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
23
src/main/java/com/shenghua/entitys/home/WebConfig.java
Normal file
23
src/main/java/com/shenghua/entitys/home/WebConfig.java
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
package com.shenghua.entitys.home;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@TableName("ep_web_config")
|
||||||
|
@Api(tags = "配置表")
|
||||||
|
public class WebConfig {
|
||||||
|
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "名")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "标题")
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "值")
|
||||||
|
private String value;
|
||||||
|
}
|
40
src/main/java/com/shenghua/entitys/news/News.java
Normal file
40
src/main/java/com/shenghua/entitys/news/News.java
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
package com.shenghua.entitys.news;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@TableName("news")
|
||||||
|
@Api(tags = "新闻表")
|
||||||
|
public class News {
|
||||||
|
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "分类ID")
|
||||||
|
private Integer categoryId;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "标题")
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "文章封面图片")
|
||||||
|
private String cover;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "内容")
|
||||||
|
private String content;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "SEO标题")
|
||||||
|
private String seoTitle;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "SEO关键词")
|
||||||
|
private String seoKeywords;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "SEO描述")
|
||||||
|
private String seoDescription;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "发布时间")
|
||||||
|
private Date createTime;
|
||||||
|
}
|
74
src/main/java/com/shenghua/entitys/product/Product.java
Normal file
74
src/main/java/com/shenghua/entitys/product/Product.java
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
package com.shenghua.entitys.product;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@TableName("product")
|
||||||
|
@Api(tags = "产品表")
|
||||||
|
public class Product {
|
||||||
|
@TableId(type = IdType.AUTO)
|
||||||
|
@ApiModelProperty(value = "主键ID")
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@TableField("name")
|
||||||
|
@ApiModelProperty(value = "产品名称")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@TableField("category_id")
|
||||||
|
@ApiModelProperty(value = "产品分类")
|
||||||
|
private Integer categoryId;
|
||||||
|
|
||||||
|
@TableField(value = "type_arr", updateStrategy = FieldStrategy.IGNORED)
|
||||||
|
@ApiModelProperty(value = "产品类型字符数组")
|
||||||
|
private String typeArr;
|
||||||
|
|
||||||
|
@TableField("cover")
|
||||||
|
@ApiModelProperty(value = "封面图路径")
|
||||||
|
private String cover;
|
||||||
|
|
||||||
|
@TableField("imgs_relation_id")
|
||||||
|
@ApiModelProperty(value = "详情图片关联ID")
|
||||||
|
private Integer imgsRelationId;
|
||||||
|
|
||||||
|
@TableField("content")
|
||||||
|
@ApiModelProperty(value = "产品介绍")
|
||||||
|
private String content;
|
||||||
|
|
||||||
|
@TableField("price")
|
||||||
|
@ApiModelProperty(value = "价格")
|
||||||
|
private BigDecimal price;
|
||||||
|
|
||||||
|
@TableField("specs_id")
|
||||||
|
@ApiModelProperty(value = "常规规格参数ID")
|
||||||
|
private Integer specsId;
|
||||||
|
|
||||||
|
@TableField("other_specs")
|
||||||
|
@ApiModelProperty(value = "其他额外规格")
|
||||||
|
private String otherSpecs;
|
||||||
|
|
||||||
|
@TableField("seo_title")
|
||||||
|
@ApiModelProperty(value = "SEO标题")
|
||||||
|
private String seoTitle;
|
||||||
|
|
||||||
|
@TableField("seo_description")
|
||||||
|
@ApiModelProperty(value = "SEO描述")
|
||||||
|
private String seoDescription;
|
||||||
|
|
||||||
|
@TableField("seo_keywords")
|
||||||
|
@ApiModelProperty(value = "SEO关键词")
|
||||||
|
private String seoKeywords;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "创建时间")
|
||||||
|
private Date createTime;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "修改时间")
|
||||||
|
private Date updateTime;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
package com.shenghua.entitys.product;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@ApiModel("产品分类")
|
||||||
|
@TableName("product_category")
|
||||||
|
public class ProductCategory {
|
||||||
|
@ApiModelProperty("主键")
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@ApiModelProperty("名称")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@ApiModelProperty("排序")
|
||||||
|
private Integer sort;
|
||||||
|
|
||||||
|
@ApiModelProperty("创建时间")
|
||||||
|
private Date createTime;
|
||||||
|
|
||||||
|
@ApiModelProperty("更新时间")
|
||||||
|
private Date updateTime;
|
||||||
|
|
||||||
|
@ApiModelProperty("更新时间")
|
||||||
|
private String desc;
|
||||||
|
|
||||||
|
private String other;
|
||||||
|
}
|
33
src/main/java/com/shenghua/entitys/product/ProductImg.java
Normal file
33
src/main/java/com/shenghua/entitys/product/ProductImg.java
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
package com.shenghua.entitys.product;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 产品图片实体类
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@ApiModel("产品图片")
|
||||||
|
@TableName("product_imgs")
|
||||||
|
public class ProductImg {
|
||||||
|
|
||||||
|
@TableId(type = IdType.AUTO)
|
||||||
|
@ApiModelProperty("主键ID")
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@TableField("product_id")
|
||||||
|
@ApiModelProperty(value = "产品ID")
|
||||||
|
private Integer productId;
|
||||||
|
|
||||||
|
@ApiModelProperty("图片URL")
|
||||||
|
private String url;
|
||||||
|
|
||||||
|
@ApiModelProperty("图片排序号")
|
||||||
|
private String sort;
|
||||||
|
|
||||||
|
@ApiModelProperty("类型:1-产品图,2-规格参数图(详情)")
|
||||||
|
private Integer type;
|
||||||
|
|
||||||
|
}
|
87
src/main/java/com/shenghua/entitys/product/ProductSpecs.java
Normal file
87
src/main/java/com/shenghua/entitys/product/ProductSpecs.java
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
package com.shenghua.entitys.product;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@TableName("product_specs")
|
||||||
|
@Api(tags = "产品规格表")
|
||||||
|
public class ProductSpecs {
|
||||||
|
|
||||||
|
@TableId(type = IdType.AUTO)
|
||||||
|
@ApiModelProperty(value = "主键ID")
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@TableField(value = "processor")
|
||||||
|
@ApiModelProperty(value = "处理器", required = true)
|
||||||
|
private String processor;
|
||||||
|
|
||||||
|
@TableField(value = "graphics_card")
|
||||||
|
@ApiModelProperty(value = "显卡", required = true)
|
||||||
|
private String graphicsCard;
|
||||||
|
|
||||||
|
@TableField(value = "memory")
|
||||||
|
@ApiModelProperty(value = "内存", required = true)
|
||||||
|
private String memory;
|
||||||
|
|
||||||
|
@TableField(value = "storage")
|
||||||
|
@ApiModelProperty(value = "储存")
|
||||||
|
private String storage;
|
||||||
|
|
||||||
|
@TableField(value = "usb_interface")
|
||||||
|
@ApiModelProperty(value = "USB接口")
|
||||||
|
private String usbInterface;
|
||||||
|
|
||||||
|
@TableField(value = "display_interface")
|
||||||
|
@ApiModelProperty(value = "显示接口")
|
||||||
|
private String displayInterface;
|
||||||
|
|
||||||
|
@TableField(value = "other_nterfaces")
|
||||||
|
@ApiModelProperty(value = "其他接口")
|
||||||
|
private String otherNterfaces;
|
||||||
|
|
||||||
|
@TableField(value = "network")
|
||||||
|
@ApiModelProperty(value = "网络", required = true)
|
||||||
|
private String network;
|
||||||
|
|
||||||
|
@TableField(value = "audio")
|
||||||
|
@ApiModelProperty(value = "音频")
|
||||||
|
private String audio;
|
||||||
|
|
||||||
|
@TableField(value = "pcIe_slot") // 注意数据库字段名的特殊大小写
|
||||||
|
@ApiModelProperty(value = "PCIE插槽")
|
||||||
|
private String pcIeSlot;
|
||||||
|
|
||||||
|
@TableField(value = "power_supply")
|
||||||
|
@ApiModelProperty(value = "电源")
|
||||||
|
private String powerSupply;
|
||||||
|
|
||||||
|
@TableField(value = "buzzer")
|
||||||
|
@ApiModelProperty(value = "蜂鸣器")
|
||||||
|
private String buzzer;
|
||||||
|
|
||||||
|
@TableField(value = "ruttrusted_module")
|
||||||
|
@ApiModelProperty(value = "可信模块")
|
||||||
|
private String ruttrustedModule;
|
||||||
|
|
||||||
|
@TableField(value = "motherboard_size")
|
||||||
|
@ApiModelProperty(value = "主板尺寸(cm²)")
|
||||||
|
private Double motherboardSize;
|
||||||
|
|
||||||
|
@TableField(value = "operating_system")
|
||||||
|
@ApiModelProperty(value = "操作系统")
|
||||||
|
private String operatingSystem;
|
||||||
|
|
||||||
|
@TableField(value = "title")
|
||||||
|
@ApiModelProperty(value = "详情介绍标题")
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
@TableField(value = "content")
|
||||||
|
@ApiModelProperty(value = "内容")
|
||||||
|
private String content;
|
||||||
|
}
|
24
src/main/java/com/shenghua/enums/AuthEnum.java
Normal file
24
src/main/java/com/shenghua/enums/AuthEnum.java
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
package com.shenghua.enums;
|
||||||
|
|
||||||
|
import com.shenghua.utils.ResultUtil;
|
||||||
|
|
||||||
|
public enum AuthEnum {
|
||||||
|
|
||||||
|
NOT_AUTHENTICATION(ResultUtil.NOT_AUTHENTICATION_CODE),
|
||||||
|
LOGIN_TOKEN_INVALID(ResultUtil.LOGIN_TOKEN_INVALID_CODE);
|
||||||
|
private AuthEnum(int code){
|
||||||
|
this.code=code;
|
||||||
|
this.message=ResultUtil.getMessage(code);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int code;
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
public int getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
29
src/main/java/com/shenghua/enums/CommEnum.java
Normal file
29
src/main/java/com/shenghua/enums/CommEnum.java
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
package com.shenghua.enums;
|
||||||
|
|
||||||
|
import com.shenghua.utils.ResultUtil;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通用返回信息
|
||||||
|
*/
|
||||||
|
public enum CommEnum {
|
||||||
|
|
||||||
|
SUCCESS(ResultUtil.SUCCESS_CODE),
|
||||||
|
FAIL(ResultUtil.FAIL_CODE),
|
||||||
|
EMPTY_PARAM(ResultUtil.EMPTY_PARAM_CODE),
|
||||||
|
ERROR(ResultUtil.ERROR_CODE);
|
||||||
|
private CommEnum(int code){
|
||||||
|
this.code=code;
|
||||||
|
this.message=ResultUtil.getMessage(code);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int code;
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
public int getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
196
src/main/java/com/shenghua/filter/CrossFilter.java
Normal file
196
src/main/java/com/shenghua/filter/CrossFilter.java
Normal file
@ -0,0 +1,196 @@
|
|||||||
|
package com.shenghua.filter;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.servlet.*;
|
||||||
|
import javax.servlet.annotation.WebFilter;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.PrintStream;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import java.io.StringWriter;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description CrossFilter
|
||||||
|
* @author TDW
|
||||||
|
* @date 2017年6月22日
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@WebFilter(urlPatterns = "/*", filterName = "crossFilter")
|
||||||
|
public class CrossFilter implements Filter {
|
||||||
|
|
||||||
|
private static final boolean debug = true;
|
||||||
|
// The filter configuration object we are associated with. If
|
||||||
|
// this value is null, this filter instance is not currently
|
||||||
|
// configured.
|
||||||
|
private FilterConfig filterConfig = null;
|
||||||
|
|
||||||
|
public CrossFilter() {
|
||||||
|
}
|
||||||
|
|
||||||
|
private void doBeforeProcessing(ServletRequest request, ServletResponse response)
|
||||||
|
throws IOException, ServletException {
|
||||||
|
if (debug) {
|
||||||
|
log("CrossFilter:DoBeforeProcessing");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void doAfterProcessing(ServletRequest request, ServletResponse response)
|
||||||
|
throws IOException, ServletException {
|
||||||
|
if (debug) {
|
||||||
|
log("CrossFilter:DoAfterProcessing");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addHeadersFor200Response(HttpServletResponse response){
|
||||||
|
//TODO: externalize the Allow-Origin
|
||||||
|
response.addHeader("Access-Control-Allow-Origin", "*");
|
||||||
|
response.addHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE, HEAD");
|
||||||
|
response.addHeader("Access-Control-Allow-Headers", "X-PINGOTHER, Origin, X-Requested-With, Content-Type, Accept");
|
||||||
|
response.addHeader("Access-Control-Max-Age", "1728000");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void doFilter(ServletRequest request, ServletResponse response,
|
||||||
|
FilterChain chain)
|
||||||
|
throws IOException, ServletException {
|
||||||
|
if (debug) {
|
||||||
|
log("CrossFilter:doFilter()");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(response instanceof HttpServletResponse){
|
||||||
|
HttpServletResponse alteredResponse = ((HttpServletResponse)response);
|
||||||
|
// I need to find a way to make sure this only gets called on 200-300 http responses
|
||||||
|
// TODO: see above comment
|
||||||
|
addHeadersFor200Response(alteredResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
doBeforeProcessing(request, response);
|
||||||
|
|
||||||
|
Throwable problem = null;
|
||||||
|
try {
|
||||||
|
chain.doFilter(request, response);
|
||||||
|
} catch (Throwable t) {
|
||||||
|
// If an exception is thrown somewhere down the filter chain,
|
||||||
|
// we still want to execute our after processing, and then
|
||||||
|
// rethrow the problem after that.
|
||||||
|
problem = t;
|
||||||
|
t.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
doAfterProcessing(request, response);
|
||||||
|
|
||||||
|
// If there was a problem, we want to rethrow it if it is
|
||||||
|
// a known type, otherwise log it.
|
||||||
|
if (problem != null) {
|
||||||
|
if (problem instanceof ServletException) {
|
||||||
|
throw (ServletException) problem;
|
||||||
|
}
|
||||||
|
if (problem instanceof IOException) {
|
||||||
|
throw (IOException) problem;
|
||||||
|
}
|
||||||
|
sendProcessingError(problem, response);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the filter configuration object for this filter.
|
||||||
|
*/
|
||||||
|
public FilterConfig getFilterConfig() {
|
||||||
|
return (this.filterConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the filter configuration object for this filter.
|
||||||
|
*
|
||||||
|
* @param filterConfig The filter configuration object
|
||||||
|
*/
|
||||||
|
public void setFilterConfig(FilterConfig filterConfig) {
|
||||||
|
this.filterConfig = filterConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destroy method for this filter
|
||||||
|
*/
|
||||||
|
public void destroy() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init method for this filter
|
||||||
|
*/
|
||||||
|
public void init(FilterConfig filterConfig) throws ServletException{
|
||||||
|
this.filterConfig = filterConfig;
|
||||||
|
if (filterConfig != null) {
|
||||||
|
if (debug) {
|
||||||
|
log("CrossFilter:Initializing filter");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a String representation of this object.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
if (filterConfig == null) {
|
||||||
|
return ("CrossFilter()");
|
||||||
|
}
|
||||||
|
StringBuffer sb = new StringBuffer("CrossFilter(");
|
||||||
|
sb.append(filterConfig);
|
||||||
|
sb.append(")");
|
||||||
|
return (sb.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendProcessingError(Throwable t, ServletResponse response) {
|
||||||
|
String stackTrace = getStackTrace(t);
|
||||||
|
|
||||||
|
if (stackTrace != null && !stackTrace.equals("")) {
|
||||||
|
try {
|
||||||
|
response.setContentType("text/html");
|
||||||
|
PrintStream ps = new PrintStream(response.getOutputStream());
|
||||||
|
PrintWriter pw = new PrintWriter(ps);
|
||||||
|
pw.print("<html>\n<head>\n<title>Error</title>\n</head>\n<body>\n"); //NOI18N
|
||||||
|
|
||||||
|
// PENDING! Localize this for next official release
|
||||||
|
pw.print("<h1>The resource did not process correctly</h1>\n<pre>\n");
|
||||||
|
pw.print(stackTrace);
|
||||||
|
pw.print("</pre></body>\n</html>"); //NOI18N
|
||||||
|
pw.close();
|
||||||
|
ps.close();
|
||||||
|
response.getOutputStream().close();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
PrintStream ps = new PrintStream(response.getOutputStream());
|
||||||
|
t.printStackTrace(ps);
|
||||||
|
ps.close();
|
||||||
|
response.getOutputStream().close();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getStackTrace(Throwable t) {
|
||||||
|
String stackTrace = null;
|
||||||
|
try {
|
||||||
|
StringWriter sw = new StringWriter();
|
||||||
|
PrintWriter pw = new PrintWriter(sw);
|
||||||
|
t.printStackTrace(pw);
|
||||||
|
pw.close();
|
||||||
|
sw.close();
|
||||||
|
stackTrace = sw.getBuffer().toString();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
}
|
||||||
|
return stackTrace;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void log(String msg) {
|
||||||
|
filterConfig.getServletContext().log(msg);
|
||||||
|
}
|
||||||
|
}
|
10
src/main/java/com/shenghua/job/AgentCouponJob.java
Normal file
10
src/main/java/com/shenghua/job/AgentCouponJob.java
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package com.shenghua.job;
|
||||||
|
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class AgentCouponJob {
|
||||||
|
|
||||||
|
}
|
17
src/main/java/com/shenghua/mapper/BannerMapper.java
Normal file
17
src/main/java/com/shenghua/mapper/BannerMapper.java
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package com.shenghua.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.shenghua.entitys.home.Banner;
|
||||||
|
import com.shenghua.vo.BannerVo;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
public interface BannerMapper extends BaseMapper<Banner> {
|
||||||
|
|
||||||
|
List<BannerVo> getBannerList();
|
||||||
|
|
||||||
|
List<BannerVo> getBannerContactList();
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
package com.shenghua.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.shenghua.entitys.CaseArticleCategory;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
public interface CaseArticleCategoryMapper extends BaseMapper<CaseArticleCategory> {
|
||||||
|
|
||||||
|
List<CaseArticleCategory> getCategory();
|
||||||
|
|
||||||
|
}
|
21
src/main/java/com/shenghua/mapper/CaseArticleMapper.java
Normal file
21
src/main/java/com/shenghua/mapper/CaseArticleMapper.java
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
package com.shenghua.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.shenghua.dto.CaseArticleDTO;
|
||||||
|
import com.shenghua.entitys.CaseArticle;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface CaseArticleMapper extends BaseMapper<CaseArticle> {
|
||||||
|
|
||||||
|
Integer getCount(@Param("dto") CaseArticleDTO dto);
|
||||||
|
|
||||||
|
List<CaseArticle> queryPage(@Param("pageNum") Integer pageNum, @Param("pageSize") Integer pageSize, @Param("dto") CaseArticleDTO dto);
|
||||||
|
|
||||||
|
List<CaseArticle> getAll();
|
||||||
|
|
||||||
|
CaseArticle getQueryUpChapterId(Integer id, Integer categoryId);
|
||||||
|
|
||||||
|
CaseArticle getQueryDownChapterId(Integer id, Integer categoryId);
|
||||||
|
}
|
13
src/main/java/com/shenghua/mapper/CategoryMapper.java
Normal file
13
src/main/java/com/shenghua/mapper/CategoryMapper.java
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
package com.shenghua.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.shenghua.entitys.category.Category;
|
||||||
|
import com.shenghua.vo.CategoryVo;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
public interface CategoryMapper extends BaseMapper<Category> {
|
||||||
|
|
||||||
|
List<CategoryVo> getCategoryByNews();
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
package com.shenghua.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.shenghua.entitys.MessageBoard;
|
||||||
|
|
||||||
|
public interface MessageBoardMapper extends BaseMapper<MessageBoard> {
|
||||||
|
}
|
27
src/main/java/com/shenghua/mapper/NewsMapper.java
Normal file
27
src/main/java/com/shenghua/mapper/NewsMapper.java
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
package com.shenghua.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.shenghua.entitys.news.News;
|
||||||
|
import com.shenghua.vo.NewsDetailsVo;
|
||||||
|
import com.shenghua.vo.NewsVo;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
public interface NewsMapper extends BaseMapper<News> {
|
||||||
|
|
||||||
|
List<NewsVo> getAllNewsByCategoryId(@Param("categoryId")Integer categoryId, @Param("startNum")Integer startNum, @Param("pageSize")Integer pageSize);
|
||||||
|
|
||||||
|
Integer getAllNewsCount(@Param("categoryId")Integer categoryId);
|
||||||
|
|
||||||
|
News getNewsById(Integer id);
|
||||||
|
|
||||||
|
NewsVo getQueryUpChapterId(Integer id,Integer categoryId);
|
||||||
|
|
||||||
|
NewsVo getQueryDownChapterId(Integer id,Integer categoryId);
|
||||||
|
|
||||||
|
List<NewsVo> getHomeNewsList();
|
||||||
|
|
||||||
|
List<NewsVo> queryList(@Param("startNum")Integer startNum, @Param("pageSize")Integer pageSize);
|
||||||
|
}
|
16
src/main/java/com/shenghua/mapper/ProductCategoryMapper.java
Normal file
16
src/main/java/com/shenghua/mapper/ProductCategoryMapper.java
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
package com.shenghua.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.shenghua.entitys.product.ProductCategory;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface ProductCategoryMapper extends BaseMapper<ProductCategory> {
|
||||||
|
|
||||||
|
List<ProductCategory> queryCategory();
|
||||||
|
|
||||||
|
|
||||||
|
ProductCategory queryById(@Param("id") Integer categoryId);
|
||||||
|
|
||||||
|
}
|
11
src/main/java/com/shenghua/mapper/ProductImgMapper.java
Normal file
11
src/main/java/com/shenghua/mapper/ProductImgMapper.java
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
package com.shenghua.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.shenghua.entitys.product.ProductImg;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface ProductImgMapper extends BaseMapper<ProductImg> {
|
||||||
|
|
||||||
|
List<ProductImg> selectByProductId(Integer id);
|
||||||
|
}
|
15
src/main/java/com/shenghua/mapper/ProductMapper.java
Normal file
15
src/main/java/com/shenghua/mapper/ProductMapper.java
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package com.shenghua.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.shenghua.dto.ProductDTO;
|
||||||
|
import com.shenghua.entitys.product.Product;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface ProductMapper extends BaseMapper<Product> {
|
||||||
|
|
||||||
|
Integer getCount(@Param("dto") ProductDTO dto);
|
||||||
|
|
||||||
|
List<Product> queryList(@Param("dto") ProductDTO dto);
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
package com.shenghua.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.shenghua.entitys.product.ProductSpecs;
|
||||||
|
|
||||||
|
public interface ProductSpecsMapper extends BaseMapper<ProductSpecs> {
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
package com.shenghua.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.shenghua.entitys.SolutionContact;
|
||||||
|
|
||||||
|
public interface SolutionContactMapper extends BaseMapper<SolutionContact> {
|
||||||
|
|
||||||
|
}
|
15
src/main/java/com/shenghua/mapper/WebConfigMapper.java
Normal file
15
src/main/java/com/shenghua/mapper/WebConfigMapper.java
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package com.shenghua.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
|
||||||
|
import com.shenghua.entitys.home.WebConfig;
|
||||||
|
import com.shenghua.vo.WebConfigVo;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
public interface WebConfigMapper extends BaseMapper<WebConfig> {
|
||||||
|
|
||||||
|
List<WebConfigVo> getWebConfig();
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package com.shenghua.request;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ImageUploadRequest {
|
||||||
|
private MultipartFile file;
|
||||||
|
}
|
22
src/main/java/com/shenghua/service/CaseArticleService.java
Normal file
22
src/main/java/com/shenghua/service/CaseArticleService.java
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
package com.shenghua.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.shenghua.dto.CaseArticleDTO;
|
||||||
|
import com.shenghua.entitys.CaseArticle;
|
||||||
|
import com.shenghua.entitys.CaseArticleCategory;
|
||||||
|
import com.shenghua.entitys.Page;
|
||||||
|
import com.shenghua.vo.CaseArticleVO;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface CaseArticleService extends IService<CaseArticle> {
|
||||||
|
|
||||||
|
Page<List<CaseArticle>> queryPage(CaseArticleDTO dto);
|
||||||
|
|
||||||
|
List<CaseArticleCategory> getCategory();
|
||||||
|
|
||||||
|
List<CaseArticleVO> getAll();
|
||||||
|
|
||||||
|
|
||||||
|
CaseArticleVO getNewsById(Integer id);
|
||||||
|
}
|
21
src/main/java/com/shenghua/service/FirstPageService.java
Normal file
21
src/main/java/com/shenghua/service/FirstPageService.java
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
package com.shenghua.service;
|
||||||
|
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.shenghua.entitys.home.Banner;
|
||||||
|
import com.shenghua.vo.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
||||||
|
public interface FirstPageService extends IService<Banner> {
|
||||||
|
|
||||||
|
// FirstPageVo firstPage();
|
||||||
|
//
|
||||||
|
// Map getWebConfig();
|
||||||
|
//
|
||||||
|
// List<BannerVo> getBannerContactList();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
29
src/main/java/com/shenghua/service/NewsService.java
Normal file
29
src/main/java/com/shenghua/service/NewsService.java
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
package com.shenghua.service;
|
||||||
|
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.shenghua.dto.NewsDto;
|
||||||
|
import com.shenghua.dto.PageDto;
|
||||||
|
import com.shenghua.entitys.Page;
|
||||||
|
import com.shenghua.entitys.news.News;
|
||||||
|
import com.shenghua.vo.CategoryVo;
|
||||||
|
import com.shenghua.vo.NewsDetailsVo;
|
||||||
|
import com.shenghua.vo.NewsVo;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
public interface NewsService extends IService<News> {
|
||||||
|
|
||||||
|
// Page<List<NewsVo>> getAllNewsByCategoryId(NewsDto newsDto);
|
||||||
|
//
|
||||||
|
// List<CategoryVo> getCategoryByNews();
|
||||||
|
//
|
||||||
|
// NewsDetailsVo getNewsById(Integer id);
|
||||||
|
|
||||||
|
Page<List<NewsVo>> queryList(PageDto page);
|
||||||
|
|
||||||
|
int saveNews(News news);
|
||||||
|
|
||||||
|
NewsVo getNewsById(Integer id);
|
||||||
|
}
|
21
src/main/java/com/shenghua/service/ProductService.java
Normal file
21
src/main/java/com/shenghua/service/ProductService.java
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
package com.shenghua.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.shenghua.dto.PageDto;
|
||||||
|
import com.shenghua.dto.ProductDTO;
|
||||||
|
import com.shenghua.entitys.Page;
|
||||||
|
import com.shenghua.entitys.product.Product;
|
||||||
|
import com.shenghua.entitys.product.ProductCategory;
|
||||||
|
import com.shenghua.vo.ProductVO;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface ProductService extends IService<Product> {
|
||||||
|
|
||||||
|
ProductVO getDetail(Integer id);
|
||||||
|
|
||||||
|
List<ProductVO> queryList(ProductDTO page);
|
||||||
|
|
||||||
|
List<ProductCategory> queryCategory();
|
||||||
|
|
||||||
|
}
|
9
src/main/java/com/shenghua/service/SolutionService.java
Normal file
9
src/main/java/com/shenghua/service/SolutionService.java
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package com.shenghua.service;
|
||||||
|
|
||||||
|
import com.shenghua.dto.SolutionContactDTO;
|
||||||
|
import com.shenghua.entitys.SolutionContact;
|
||||||
|
|
||||||
|
public interface SolutionService {
|
||||||
|
|
||||||
|
void addContact(SolutionContactDTO contact);
|
||||||
|
}
|
@ -0,0 +1,99 @@
|
|||||||
|
package com.shenghua.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.shenghua.convert.CaseArticleConvert;
|
||||||
|
import com.shenghua.dto.CaseArticleDTO;
|
||||||
|
import com.shenghua.entitys.CaseArticle;
|
||||||
|
|
||||||
|
import com.shenghua.entitys.CaseArticleCategory;
|
||||||
|
import com.shenghua.entitys.Page;
|
||||||
|
import com.shenghua.mapper.CaseArticleCategoryMapper;
|
||||||
|
import com.shenghua.mapper.CaseArticleMapper;
|
||||||
|
import com.shenghua.service.CaseArticleService;
|
||||||
|
import com.shenghua.vo.CaseArticleVO;
|
||||||
|
import org.apache.lucene.util.CollectionUtil;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class CaseArticleServiceImpl extends ServiceImpl<CaseArticleMapper, CaseArticle> implements CaseArticleService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CaseArticleMapper caseArticleMapper;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CaseArticleCategoryMapper categoryMapper;
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Page<List<CaseArticle>> queryPage(CaseArticleDTO dto) {
|
||||||
|
// 查询总记录数
|
||||||
|
Integer count = super.baseMapper.getCount(dto); // 假设 Mapper 中有 getNewsCount() 方法
|
||||||
|
if (count == 0){
|
||||||
|
return new Page<>(dto.getPageNum(), 0, dto.getPageSize(), null);
|
||||||
|
}
|
||||||
|
// 计算起始位置
|
||||||
|
Integer startNum = (dto.getPageNum() - 1) * dto.getPageSize();
|
||||||
|
// 查询当前页数据
|
||||||
|
List<CaseArticle> list = super.baseMapper.queryPage(dto.getPageNum(), dto.getPageSize(), dto);
|
||||||
|
|
||||||
|
// 返回分页对象
|
||||||
|
return new Page<>(dto.getPageNum(), count, dto.getPageSize(), list);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<CaseArticleCategory> getCategory() {
|
||||||
|
List<CaseArticleCategory> list = categoryMapper.getCategory();
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<CaseArticleVO> getAll() {
|
||||||
|
List<CaseArticle> caseArticles = caseArticleMapper.getAll();
|
||||||
|
if (CollectionUtils.isEmpty(caseArticles)){
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
List<CaseArticleCategory> categories = getCategory();
|
||||||
|
Map<Integer, CaseArticleCategory> categoryMap = categories.stream()
|
||||||
|
.collect(Collectors.toMap(CaseArticleCategory::getId, category -> category));
|
||||||
|
|
||||||
|
List<CaseArticleVO> vos = caseArticles.stream()
|
||||||
|
.map(caseArticle -> {
|
||||||
|
CaseArticleVO caseArticleVO = CaseArticleConvert.convertToVO(caseArticle);
|
||||||
|
CaseArticleCategory category = categoryMap.get(caseArticle.getCategoryId());
|
||||||
|
caseArticleVO.setCategory(category.getName());
|
||||||
|
caseArticleVO.setCategoryTag(category.getTag());
|
||||||
|
return caseArticleVO;
|
||||||
|
})
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
return vos;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CaseArticleVO getNewsById(Integer id) {
|
||||||
|
CaseArticle caseArticle = caseArticleMapper.selectById(id);
|
||||||
|
if (Objects.isNull(caseArticle)){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
CaseArticleVO caseArticleVO = CaseArticleConvert.convertToVO(caseArticle);
|
||||||
|
|
||||||
|
CaseArticle upCase=caseArticleMapper.getQueryUpChapterId(id, caseArticle.getCategoryId());
|
||||||
|
if(upCase!=null){
|
||||||
|
caseArticleVO.setUpChapterId(upCase.getId());
|
||||||
|
caseArticleVO.setUpChapterName(upCase.getTitle());
|
||||||
|
}
|
||||||
|
CaseArticle downCase=caseArticleMapper.getQueryDownChapterId(id, caseArticle.getCategoryId());
|
||||||
|
if(downCase!=null){
|
||||||
|
caseArticleVO.setDownChapterId(downCase.getId());
|
||||||
|
caseArticleVO.setDownChapterName(downCase.getTitle());
|
||||||
|
}
|
||||||
|
return caseArticleVO;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,78 @@
|
|||||||
|
package com.shenghua.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.shenghua.entitys.home.Banner;
|
||||||
|
import com.shenghua.mapper.*;
|
||||||
|
import com.shenghua.service.FirstPageService;
|
||||||
|
import com.shenghua.utils.ConstantUtil;
|
||||||
|
import com.shenghua.vo.*;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class FirstPageServiceImpl extends ServiceImpl<BannerMapper, Banner> implements FirstPageService {
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(FirstPageServiceImpl.class);
|
||||||
|
|
||||||
|
ConstantUtil constantUtil = null;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private NewsMapper newsMapper;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private WebConfigMapper webConfigMapper;
|
||||||
|
|
||||||
|
// @Override
|
||||||
|
// public FirstPageVo firstPage() {
|
||||||
|
// FirstPageVo firstPageVo=new FirstPageVo();
|
||||||
|
//
|
||||||
|
// List<BannerVo> bannerVos=super.baseMapper.getBannerList();
|
||||||
|
// for (BannerVo bannerVo : bannerVos) {
|
||||||
|
// bannerVo.setImage(constantUtil.IMG_URL+bannerVo.getImage());
|
||||||
|
// }
|
||||||
|
// firstPageVo.setBannerList(bannerVos);
|
||||||
|
//
|
||||||
|
// List<NewsVo> newsVos=newsMapper.getHomeNewsList();
|
||||||
|
// for (NewsVo newsVo : newsVos) {
|
||||||
|
// newsVo.setCover(constantUtil.IMG_URL+newsVo.getCover());
|
||||||
|
// }
|
||||||
|
// firstPageVo.setNewsList(newsVos);
|
||||||
|
//
|
||||||
|
// return firstPageVo;
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
// @Override
|
||||||
|
// public Map getWebConfig() {
|
||||||
|
//
|
||||||
|
// List<WebConfigVo> list=webConfigMapper.getWebConfig();
|
||||||
|
// Map map=new HashMap();
|
||||||
|
// for (WebConfigVo webConfigVo : list) {
|
||||||
|
//
|
||||||
|
// map.put(webConfigVo.getName(),webConfigVo.getValue());
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// return map;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// @Override
|
||||||
|
// public List<BannerVo> getBannerContactList() {
|
||||||
|
// List<BannerVo> list=super.baseMapper.getBannerContactList();
|
||||||
|
//
|
||||||
|
// for (BannerVo bannerVo : list) {
|
||||||
|
// bannerVo.setImage(constantUtil.IMG_URL+bannerVo.getImage());
|
||||||
|
// }
|
||||||
|
// return list;
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
124
src/main/java/com/shenghua/service/impl/NewsServiceImpl.java
Normal file
124
src/main/java/com/shenghua/service/impl/NewsServiceImpl.java
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
package com.shenghua.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.shenghua.convert.NewConvert;
|
||||||
|
import com.shenghua.dto.NewsDto;
|
||||||
|
import com.shenghua.dto.PageDto;
|
||||||
|
import com.shenghua.entitys.Page;
|
||||||
|
import com.shenghua.entitys.news.News;
|
||||||
|
import com.shenghua.mapper.CategoryMapper;
|
||||||
|
import com.shenghua.mapper.NewsMapper;
|
||||||
|
import com.shenghua.service.NewsService;
|
||||||
|
import com.shenghua.utils.ConstantUtil;
|
||||||
|
import com.shenghua.vo.CategoryVo;
|
||||||
|
import com.shenghua.vo.NewsDetailsVo;
|
||||||
|
import com.shenghua.vo.NewsVo;
|
||||||
|
import org.jsoup.nodes.Document;
|
||||||
|
import org.jsoup.nodes.Element;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class NewsServiceImpl extends ServiceImpl<NewsMapper, News> implements NewsService {
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(NewsServiceImpl.class);
|
||||||
|
|
||||||
|
private ConstantUtil constantUtil = null;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CategoryMapper categoryMapper;
|
||||||
|
|
||||||
|
// @Override
|
||||||
|
// public Page<List<NewsVo>> getAllNewsByCategoryId(NewsDto newsDto) {
|
||||||
|
//
|
||||||
|
// Integer count = super.baseMapper.getAllNewsCount(newsDto.getCategoryId());
|
||||||
|
// Integer startNum = (newsDto.getPageNum() - 1) * newsDto.getPageSize();
|
||||||
|
// List<NewsVo> list = super.baseMapper.getAllNewsByCategoryId(newsDto.getCategoryId(), startNum, newsDto.getPageSize());
|
||||||
|
// for (NewsVo newsVo : list) {
|
||||||
|
// newsVo.setImage(constantUtil.IMG_URL+newsVo.getImage());
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// return new Page<>(newsDto.getPageNum(), count, newsDto.getPageSize(), list);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @Override
|
||||||
|
// public List<CategoryVo> getCategoryByNews() {
|
||||||
|
//
|
||||||
|
// List<CategoryVo> list=categoryMapper.getCategoryByNews();
|
||||||
|
//
|
||||||
|
// for (CategoryVo categoryVo : list) {
|
||||||
|
// categoryVo.setImage(constantUtil.IMG_URL+categoryVo.getImage());
|
||||||
|
// }
|
||||||
|
// return list;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @Override
|
||||||
|
// public NewsDetailsVo getNewsById(Integer id) {
|
||||||
|
//
|
||||||
|
// NewsDetailsVo newsDetailsVo=super.baseMapper.getNewsById(id);
|
||||||
|
// String richTextContent = newsDetailsVo.getContent();
|
||||||
|
// Document doc = Document.createShell("");
|
||||||
|
// Element pTag = doc.createElement("p");
|
||||||
|
// pTag.text(richTextContent);
|
||||||
|
// doc.body().appendChild(pTag);
|
||||||
|
// String htmlContent = pTag.outerHtml();
|
||||||
|
// newsDetailsVo.setContent(htmlContent);
|
||||||
|
// newsDetailsVo.setImage(constantUtil.IMG_URL+newsDetailsVo.getImage());
|
||||||
|
// NewsVo upNewsVo=super.baseMapper.getQueryUpChapterId(id,newsDetailsVo.getCategoryId());
|
||||||
|
// if(upNewsVo!=null){
|
||||||
|
// newsDetailsVo.setUpChapterId(upNewsVo.getId());
|
||||||
|
// newsDetailsVo.setUpChapterName(upNewsVo.getTitle());
|
||||||
|
// }
|
||||||
|
// NewsVo downNewsVo=super.baseMapper.getQueryDownChapterId(id,newsDetailsVo.getCategoryId());
|
||||||
|
// if(downNewsVo!=null){
|
||||||
|
// newsDetailsVo.setDownChapterId(downNewsVo.getId());
|
||||||
|
// newsDetailsVo.setDownChapterName(downNewsVo.getTitle());
|
||||||
|
// }
|
||||||
|
// return newsDetailsVo;
|
||||||
|
// }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Page<List<NewsVo>> queryList(PageDto page) {
|
||||||
|
// 查询总记录数
|
||||||
|
Integer count = super.baseMapper.getAllNewsCount(null); // 假设 Mapper 中有 getNewsCount() 方法
|
||||||
|
if (count == 0){
|
||||||
|
return new Page<>(page.getPageNum(), 0, page.getPageSize(), null);
|
||||||
|
}
|
||||||
|
// 计算起始位置
|
||||||
|
Integer startNum = (page.getPageNum() - 1) * page.getPageSize();
|
||||||
|
|
||||||
|
// 查询当前页数据
|
||||||
|
List<NewsVo> list = super.baseMapper.queryList(page.getPageNum(), page.getPageSize());
|
||||||
|
|
||||||
|
// 返回分页对象
|
||||||
|
return new Page<>(page.getPageNum(), count, page.getPageSize(), list);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int saveNews(News news) {
|
||||||
|
return super.baseMapper.insert(news);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NewsVo getNewsById(Integer id) {
|
||||||
|
News news = super.baseMapper.getNewsById(id);
|
||||||
|
NewsVo newsVo = NewConvert.convertVO(news);
|
||||||
|
NewsVo upNewsVo=super.baseMapper.getQueryUpChapterId(id,newsVo.getCategoryId());
|
||||||
|
if(upNewsVo!=null){
|
||||||
|
newsVo.setUpChapterId(upNewsVo.getId());
|
||||||
|
newsVo.setUpChapterName(upNewsVo.getTitle());
|
||||||
|
}
|
||||||
|
NewsVo downNewsVo=super.baseMapper.getQueryDownChapterId(id,newsVo.getCategoryId());
|
||||||
|
if(downNewsVo!=null){
|
||||||
|
newsVo.setDownChapterId(downNewsVo.getId());
|
||||||
|
newsVo.setDownChapterName(downNewsVo.getTitle());
|
||||||
|
}
|
||||||
|
return newsVo;
|
||||||
|
}
|
||||||
|
}
|
106
src/main/java/com/shenghua/service/impl/ProductServiceImpl.java
Normal file
106
src/main/java/com/shenghua/service/impl/ProductServiceImpl.java
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
package com.shenghua.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.shenghua.convert.ProductConvert;
|
||||||
|
import com.shenghua.dto.PageDto;
|
||||||
|
import com.shenghua.dto.ProductDTO;
|
||||||
|
import com.shenghua.entitys.Page;
|
||||||
|
import com.shenghua.entitys.product.Product;
|
||||||
|
|
||||||
|
import com.shenghua.entitys.product.ProductCategory;
|
||||||
|
import com.shenghua.entitys.product.ProductImg;
|
||||||
|
import com.shenghua.entitys.product.ProductSpecs;
|
||||||
|
import com.shenghua.mapper.ProductCategoryMapper;
|
||||||
|
import com.shenghua.mapper.ProductImgMapper;
|
||||||
|
import com.shenghua.mapper.ProductMapper;
|
||||||
|
import com.shenghua.mapper.ProductSpecsMapper;
|
||||||
|
import com.shenghua.service.ProductService;
|
||||||
|
import com.shenghua.vo.NewsVo;
|
||||||
|
import com.shenghua.vo.ProductVO;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements ProductService {
|
||||||
|
@Autowired
|
||||||
|
private ProductMapper productMapper;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ProductSpecsMapper productSpecsMapper;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ProductCategoryMapper categoryMapper;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ProductImgMapper imgMapper;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ProductVO getDetail(Integer id) {
|
||||||
|
Product product = this.getById(id);
|
||||||
|
if (Objects.isNull(product)){
|
||||||
|
// 可以根据实际情况处理,例如抛出异常或者返回 null
|
||||||
|
throw new RuntimeException("产品不存在");
|
||||||
|
}
|
||||||
|
ProductVO productVO = ProductConvert.convertVO(product);
|
||||||
|
// ProductSpecs productSpecs = productSpecsMapper.selectById(product.getSpecsId());
|
||||||
|
ProductCategory category = categoryMapper.queryById(product.getCategoryId());
|
||||||
|
productVO.setCategory(category.getName());
|
||||||
|
// productVO.setProductSpecs(productSpecs);
|
||||||
|
|
||||||
|
List<ProductImg> productImgs = imgMapper.selectByProductId(productVO.getId());
|
||||||
|
|
||||||
|
Map<Integer, List<ProductImg>> groupedByType = productImgs.stream()
|
||||||
|
.collect(Collectors.groupingBy(ProductImg::getType));
|
||||||
|
|
||||||
|
// 获取 type=2 的图片 URL 列表(规格图)
|
||||||
|
List<String> specsImgs = groupedByType.getOrDefault(2, Collections.emptyList()).stream()
|
||||||
|
.map(ProductImg::getUrl)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
productVO.setSpecsImgs(specsImgs);
|
||||||
|
|
||||||
|
// 获取 type=1 的图片 URL 列表(产品图)
|
||||||
|
List<String> imgs = groupedByType.getOrDefault(1, Collections.emptyList()).stream()
|
||||||
|
.map(ProductImg::getUrl)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
productVO.setImgs(imgs);
|
||||||
|
|
||||||
|
|
||||||
|
return productVO;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ProductVO> queryList(ProductDTO dto) {
|
||||||
|
// 查询总记录数
|
||||||
|
Integer count = productMapper.getCount(dto); // 假设 Mapper 中有 getNewsCount() 方法
|
||||||
|
if (count == 0){
|
||||||
|
// return new Page<>(dto.getPageNum(), 0, dto.getPageSize(), null);
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
// 查询当前页数据
|
||||||
|
List<Product> list = productMapper.queryList(dto);
|
||||||
|
|
||||||
|
List<ProductVO> vos = list.stream().map(pro->{
|
||||||
|
ProductVO productVO = ProductConvert.convertVO(pro);
|
||||||
|
// ProductSpecs productSpecs = productSpecsMapper.selectById(pro.getSpecsId());
|
||||||
|
// productVO.setProductSpecs(productSpecs);
|
||||||
|
return productVO;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
|
||||||
|
// 返回分页对象
|
||||||
|
return vos;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ProductCategory> queryCategory() {
|
||||||
|
return categoryMapper.queryCategory();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
package com.shenghua.service.impl;
|
||||||
|
|
||||||
|
|
||||||
|
import com.shenghua.convert.SolutionContactConvert;
|
||||||
|
import com.shenghua.dto.SolutionContactDTO;
|
||||||
|
import com.shenghua.entitys.SolutionContact;
|
||||||
|
import com.shenghua.mapper.SolutionContactMapper;
|
||||||
|
import com.shenghua.service.SolutionService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class SolutionServiceImpl implements SolutionService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
|
||||||
|
private SolutionContactMapper solutionContactMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addContact(SolutionContactDTO contact) {
|
||||||
|
SolutionContact solutionContact = SolutionContactConvert.convert(contact);
|
||||||
|
solutionContactMapper.insert(solutionContact);
|
||||||
|
}
|
||||||
|
}
|
43
src/main/java/com/shenghua/utils/ApiReadUitl.java
Normal file
43
src/main/java/com/shenghua/utils/ApiReadUitl.java
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
package com.shenghua.utils;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
|
||||||
|
|
||||||
|
public class ApiReadUitl {
|
||||||
|
/*
|
||||||
|
* 读取返回结果
|
||||||
|
*/
|
||||||
|
public static String read(InputStream is) throws IOException {
|
||||||
|
StringBuffer sb = new StringBuffer();
|
||||||
|
BufferedReader br = new BufferedReader(new InputStreamReader(is));
|
||||||
|
String line = null;
|
||||||
|
while ((line = br.readLine()) != null) {
|
||||||
|
line = new String(line.getBytes(), "utf-8");
|
||||||
|
sb.append(line);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
//去“ "号
|
||||||
|
public static String removeDoubleQuotes(String result) {
|
||||||
|
//去掉" "号
|
||||||
|
return result.replace("\"", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
//截取字符串后四位
|
||||||
|
public static String getCardTailNum(String cardNum){
|
||||||
|
StringBuffer tailNum = new StringBuffer();
|
||||||
|
if (cardNum != null) {
|
||||||
|
int len = cardNum.length();
|
||||||
|
for (int i = len - 1; i >= len - 4; i--) {
|
||||||
|
tailNum.append(cardNum.charAt(i));
|
||||||
|
}
|
||||||
|
tailNum.reverse();
|
||||||
|
}
|
||||||
|
return tailNum.toString();
|
||||||
|
}
|
||||||
|
}
|
62
src/main/java/com/shenghua/utils/Base64Util.java
Normal file
62
src/main/java/com/shenghua/utils/Base64Util.java
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
package com.shenghua.utils;
|
||||||
|
|
||||||
|
public class Base64Util {
|
||||||
|
private static final char last2byte = (char) Integer.parseInt("00000011", 2);
|
||||||
|
private static final char last4byte = (char) Integer.parseInt("00001111", 2);
|
||||||
|
private static final char last6byte = (char) Integer.parseInt("00111111", 2);
|
||||||
|
private static final char lead6byte = (char) Integer.parseInt("11111100", 2);
|
||||||
|
private static final char lead4byte = (char) Integer.parseInt("11110000", 2);
|
||||||
|
private static final char lead2byte = (char) Integer.parseInt("11000000", 2);
|
||||||
|
private static final char[] encodeTable = new char[]{'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'};
|
||||||
|
|
||||||
|
public Base64Util() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String encode(byte[] from) {
|
||||||
|
StringBuilder to = new StringBuilder((int) ((double) from.length * 1.34D) + 3);
|
||||||
|
int num = 0;
|
||||||
|
char currentByte = 0;
|
||||||
|
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < from.length; ++i) {
|
||||||
|
for (num %= 8; num < 8; num += 6) {
|
||||||
|
switch (num) {
|
||||||
|
case 0:
|
||||||
|
currentByte = (char) (from[i] & lead6byte);
|
||||||
|
currentByte = (char) (currentByte >>> 2);
|
||||||
|
case 1:
|
||||||
|
case 3:
|
||||||
|
case 5:
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
currentByte = (char) (from[i] & last6byte);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
currentByte = (char) (from[i] & last4byte);
|
||||||
|
currentByte = (char) (currentByte << 2);
|
||||||
|
if (i + 1 < from.length) {
|
||||||
|
currentByte = (char) (currentByte | (from[i + 1] & lead2byte) >>> 6);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
currentByte = (char) (from[i] & last2byte);
|
||||||
|
currentByte = (char) (currentByte << 4);
|
||||||
|
if (i + 1 < from.length) {
|
||||||
|
currentByte = (char) (currentByte | (from[i + 1] & lead4byte) >>> 4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
to.append(encodeTable[currentByte]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (to.length() % 4 != 0) {
|
||||||
|
for (i = 4 - to.length() % 4; i > 0; --i) {
|
||||||
|
to.append("=");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return to.toString();
|
||||||
|
}
|
||||||
|
}
|
60
src/main/java/com/shenghua/utils/ConstantUtil.java
Normal file
60
src/main/java/com/shenghua/utils/ConstantUtil.java
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
package com.shenghua.utils;
|
||||||
|
|
||||||
|
|
||||||
|
public class ConstantUtil {
|
||||||
|
|
||||||
|
public static final String WX_APPID="wx754279d6a5f09653";
|
||||||
|
public static final String WX_SECRET="0c086aa9ae9f8c72f87da9d303406d48";
|
||||||
|
|
||||||
|
public static final String WX_URL_LINK="https://api.weixin.qq.com/wxa/generate_urllink?access_token=";
|
||||||
|
public static final String WX_TOKEN_URL="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="+WX_APPID+"&secret="+WX_SECRET;
|
||||||
|
public static final String WX_ACODE="https://api.weixin.qq.com/wxa/getwxacode?access_token=";
|
||||||
|
public static final String IMAGE_URL;
|
||||||
|
public static final String IMAGE_PATH;
|
||||||
|
public static final String REAL_NAME_AUTH_IMAGE_DIR="/real_name_auth";
|
||||||
|
public static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
|
||||||
|
public static final String DATE_FORMAT_NUM = "yyyyMMdd";
|
||||||
|
|
||||||
|
|
||||||
|
public static final String WX_MCH_ID="1510323761";
|
||||||
|
public static final String WX_SERIAL_NUMBER="57B58C8A793F4A6C3BE8E0C96E6A54FD071972E8";//商户证书序列号
|
||||||
|
public static final String WX_V3_SERIAL_NUMBER="xinanzulin202212121828xinanzulin";//
|
||||||
|
public static final String WX_PRIVATE_KEY="MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDZU5hW8QAgwrcp\n" +
|
||||||
|
"ssZe0YYtKo4u2DB+hWPk5BXYTTXKsRm4iAT840dmpWS0ZymrO7UrOX3K6MfwRdKk\n" +
|
||||||
|
"Kpe4zoK+136pV432gMHjOSUNErrHwRbzu3fvxT4etSLUavCQcY9vQRdgoCDBXFCG\n" +
|
||||||
|
"hTrDK9JkNLcbyzguqwnr+/0fa3zfKv+YnxpcN4OQ+JuIgT1M/Gvqf5I+0tZ0XW1v\n" +
|
||||||
|
"nZuj8BA3kncqfyorRM/kiIzyu4You6y0hR3DDHOmdzVNUnu57kA7zSKzJJPGoZpM\n" +
|
||||||
|
"kx3zj2wILyMUQpU/fskpRZUftWnTx2noNmjCL34Yc2lRPt1fzQ6n5IXNi6dIU+A9\n" +
|
||||||
|
"Y97KheufAgMBAAECggEBAKLbQQKN0PG72HQX8w1k5657AFdcTGLTZLtGrJQNr+y3\n" +
|
||||||
|
"cDXXQB2d14i1ElUaJaCaurWsfHaMoB+Owz2gaVfk8Rc/9zvBT7HUZPb4gKpeSbed\n" +
|
||||||
|
"G60D4+m6nkV2qaYSiTlE0B6n4XPYKxObMQDNX+6XrS7IThs222Albeb4S4O7EbVN\n" +
|
||||||
|
"as1D7b2j9329XsFOFhjoY3M6JvTCRy2CoTv7OpekynSYEKJGo61D03Y8DGroipqi\n" +
|
||||||
|
"cui3kRwXPxo+XEJugOXgoyfciPZxEXqn+UBNIUkDBotcE8ZZDUbbLE+63dyzpeQD\n" +
|
||||||
|
"1JodxiBqBKk/le9MIT6sUR8Ct5q5dYJpQNWx0r0CBIkCgYEA887gpjqaGJZdYHdS\n" +
|
||||||
|
"YBh53B9q0RhINv+JizY0sm7qz/47ilDL2t1kvm2xp+jf1Y4xfnccDsoJ4twc6c9Y\n" +
|
||||||
|
"JS5X53Ni2AhHoUsrSzPHKlBgB90Q7thvAlPDAmsQ1Utlyt6ECXF7TWgYBfOUCxTA\n" +
|
||||||
|
"UfQHTi127NVx25lTZOgzWoplE80CgYEA5DG2WQ8TLp4bqdVE8rfHR1LI7gw/XM2L\n" +
|
||||||
|
"Fa+Vh02d/gqxmpOtU2w3NcUtnAT9XxznSBAJZsbiDZcEDGdzLT5CdChDK+GnRcr0\n" +
|
||||||
|
"A2WZLVinD6Xjl4nMdJFf4ZAP/dt3IpsogedGo32UMAJyWraQhomot+LSxcETS1EY\n" +
|
||||||
|
"vtpYEsl1KRsCgYEAjpf+d/pqSdsXveXLvfxSuVV+qdBj3BbUoSEQ7RNGLmPo+tqK\n" +
|
||||||
|
"f/VgiKerciMXVtWVSPvs4xFzesV1+6GTUhuquemYc/VTv5gxOAiOgccEg1TeJHNd\n" +
|
||||||
|
"aaUHtxBbhgRVArPl0YgXr4wkEMcHXPvEB6qL40Nf/OBReThRuAC+mEO9HjkCgYBi\n" +
|
||||||
|
"bFq1IP5qDgHqh7U8Zy4Jwlgt7JRrx6/kw53gBQdPKneeL3ID2Fob1BcvAyvxmTrc\n" +
|
||||||
|
"ZyZW8RNRP0CcxQX1jrQE+9S1GZgXT0leKbUezO0Jn8iBdQr9gDJ1zLhJCx7gi0G2\n" +
|
||||||
|
"ffWG0MRYzMVcAQBnNvrRjYDRkMxsoObmcrCoMcJZ3wKBgGjK7hGqcgVYJD8NmhWH\n" +
|
||||||
|
"03JbttErBd5pbZ6oBqo/TzjSXVzi6cj0tk84DQhUsySpZTUz0jql2e9isoMyIg4l\n" +
|
||||||
|
"uNttOiuJilVruA51AWeS2je6IPujN2qMsq2bgPnu/B7RUsAbuLj52oq+JN3mK97b\n" +
|
||||||
|
"OwxgImEMuzGqjzTPAOxXeTaz";
|
||||||
|
|
||||||
|
// 时间类型开始时间
|
||||||
|
public static String DATE_TIME_TYPE_BEGIN = "begin";
|
||||||
|
// 时间类型结束时间
|
||||||
|
public static String DATE_TIME_TYPE_END = "end";
|
||||||
|
// public static final String IMG_URL="https://www.xinanzulin.com";
|
||||||
|
static {
|
||||||
|
IMAGE_URL=SpringBeanUtil.getProperty("image.url",String.class);
|
||||||
|
IMAGE_PATH=SpringBeanUtil.getProperty("image.path",String.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
24
src/main/java/com/shenghua/utils/CopyBeanUtil.java
Normal file
24
src/main/java/com/shenghua/utils/CopyBeanUtil.java
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
package com.shenghua.utils;
|
||||||
|
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
public class CopyBeanUtil extends BeanUtils {
|
||||||
|
|
||||||
|
public static <S,T> List<T> copyListProperties (List<S> source, Supplier<T> target){
|
||||||
|
List<T> list=new ArrayList<>();
|
||||||
|
if(source==null||source.isEmpty()){
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
for (S s:source) {
|
||||||
|
T t=target.get();
|
||||||
|
copyProperties(s,t);
|
||||||
|
list.add(t);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
497
src/main/java/com/shenghua/utils/DateUtil.java
Normal file
497
src/main/java/com/shenghua/utils/DateUtil.java
Normal file
@ -0,0 +1,497 @@
|
|||||||
|
package com.shenghua.utils;
|
||||||
|
|
||||||
|
import cn.hutool.core.date.DateTime;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
public final class DateUtil {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(com.shenghua.utils.DateUtil.class);
|
||||||
|
|
||||||
|
private DateUtil() {
|
||||||
|
throw new IllegalStateException("Utility class");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前日期,指定格式
|
||||||
|
* 描述:<描述函数实现的功能>.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String nowDate() {
|
||||||
|
return nowDate(ConstantUtil.DATE_FORMAT_NUM);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前年,指定格式
|
||||||
|
* 描述:<描述函数实现的功能>.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String nowYear() {
|
||||||
|
Calendar cal = Calendar.getInstance();
|
||||||
|
return cal.get(Calendar.YEAR) + "";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取上一年,指定格式
|
||||||
|
* 描述:<描述函数实现的功能>.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String lastYear() {
|
||||||
|
Calendar cal = Calendar.getInstance();
|
||||||
|
cal.add(Calendar.YEAR, -1);
|
||||||
|
return cal.get(Calendar.YEAR) + "";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前日期,指定格式
|
||||||
|
* 描述:<描述函数实现的功能>.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static Date nowDateTime() {
|
||||||
|
return strToDate(nowDateTimeStr(), ConstantUtil.DATE_FORMAT);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前日期,指定格式
|
||||||
|
* 描述:<描述函数实现的功能>.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String nowDateTimeStr() {
|
||||||
|
return nowDate(ConstantUtil.DATE_FORMAT);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前日期,指定格式
|
||||||
|
* 描述:<描述函数实现的功能>.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String nowDate(String DATE_FORMAT) {
|
||||||
|
SimpleDateFormat dft = new SimpleDateFormat(DATE_FORMAT);
|
||||||
|
return dft.format(new Date());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前日期,指定格式
|
||||||
|
* 描述:<描述函数实现的功能>.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String nowDateTime(String DATE_FORMAT) {
|
||||||
|
SimpleDateFormat dft = new SimpleDateFormat(DATE_FORMAT);
|
||||||
|
return dft.format(new Date());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前日期,指定格式
|
||||||
|
* 描述:<描述函数实现的功能>.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static Integer getNowTime() {
|
||||||
|
long t = (System.currentTimeMillis()/1000L);
|
||||||
|
return Integer.parseInt(String.valueOf(t));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前时间戳(秒级)
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static Long getTime() {
|
||||||
|
return (System.currentTimeMillis()/1000L);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前日期,指定格式
|
||||||
|
* 描述:<描述函数实现的功能>.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static Date nowDateTimeReturnDate(String DATE_FORMAT) {
|
||||||
|
SimpleDateFormat dft = new SimpleDateFormat(DATE_FORMAT);
|
||||||
|
return strToDate(dft.format(new Date()), DATE_FORMAT);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* convert a date to string in a specifies fromat.
|
||||||
|
*
|
||||||
|
* @param date
|
||||||
|
* @param DATE_FORMAT
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String dateToStr(Date date, String DATE_FORMAT) {
|
||||||
|
if (date == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
SimpleDateFormat myFormat = new SimpleDateFormat(DATE_FORMAT);
|
||||||
|
return myFormat.format(date);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* parse a String to Date in a specifies fromat.
|
||||||
|
*
|
||||||
|
* @param dateStr
|
||||||
|
* @param DATE_FORMAT
|
||||||
|
* @return
|
||||||
|
* @throws ParseException
|
||||||
|
*/
|
||||||
|
public static Date strToDate(String dateStr, String DATE_FORMAT) {
|
||||||
|
SimpleDateFormat myFormat = new SimpleDateFormat(DATE_FORMAT);
|
||||||
|
try {
|
||||||
|
return myFormat.parse(dateStr);
|
||||||
|
} catch (ParseException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* date add Second
|
||||||
|
*
|
||||||
|
* @param date
|
||||||
|
* @param num
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static Date addSecond(Date date, int num) {
|
||||||
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
calendar.setTime(date);
|
||||||
|
calendar.add(Calendar.SECOND, num);
|
||||||
|
return calendar.getTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* date add Second return String
|
||||||
|
*
|
||||||
|
* @param date
|
||||||
|
* @param num
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String addSecond(Date date, int num, String DATE_FORMAT) {
|
||||||
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
calendar.setTime(date);
|
||||||
|
calendar.add(Calendar.SECOND, num);
|
||||||
|
return dateToStr(calendar.getTime(), DATE_FORMAT);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 指定日期加上天数后的日期
|
||||||
|
*
|
||||||
|
* @param num 为增加的天数
|
||||||
|
* @param newDate 创建时间
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static final String addDay(String newDate, int num, String pattern) {
|
||||||
|
SimpleDateFormat format = new SimpleDateFormat(pattern);
|
||||||
|
try {
|
||||||
|
Date currdate = format.parse(newDate);
|
||||||
|
Calendar ca = Calendar.getInstance();
|
||||||
|
ca.setTime(currdate);
|
||||||
|
ca.add(Calendar.DATE, num);
|
||||||
|
return format.format(ca.getTime());
|
||||||
|
} catch (ParseException e) {
|
||||||
|
LOGGER.error("转化时间出错,", e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 指定日期加上天数后的日期
|
||||||
|
*
|
||||||
|
* @param num 为增加的天数
|
||||||
|
* @param newDate 创建时间
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static final String addDay(Date newDate, int num, String pattern) {
|
||||||
|
SimpleDateFormat format = new SimpleDateFormat(pattern);
|
||||||
|
Calendar ca = Calendar.getInstance();
|
||||||
|
ca.setTime(newDate);
|
||||||
|
ca.add(Calendar.DATE, num);
|
||||||
|
return format.format(ca.getTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* convert long to date
|
||||||
|
*
|
||||||
|
* @param date 待转换时间戳
|
||||||
|
* @return 转换后时间
|
||||||
|
*/
|
||||||
|
public static Date timeStamp11ToDate(Integer date) {
|
||||||
|
return new Date(date);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* convert long to date string
|
||||||
|
*
|
||||||
|
* @param date 待转换时间戳
|
||||||
|
* @param DATE_FORMAT 格式化时间
|
||||||
|
* @return 格式化后的时间
|
||||||
|
*/
|
||||||
|
public static String timeStamp11ToDate(Integer date, String DATE_FORMAT) {
|
||||||
|
return dateToStr(new Date(date), DATE_FORMAT);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* compare two date String with a pattern
|
||||||
|
*
|
||||||
|
* @param date1
|
||||||
|
* @param date2
|
||||||
|
* @param pattern
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static int compareDate(String date1, String date2, String pattern) {
|
||||||
|
SimpleDateFormat DATE_FORMAT = new SimpleDateFormat(pattern);
|
||||||
|
try {
|
||||||
|
Date dt1 = DATE_FORMAT.parse(date1);
|
||||||
|
Date dt2 = DATE_FORMAT.parse(date2);
|
||||||
|
if (dt1.getTime() > dt2.getTime()) {
|
||||||
|
return 1;
|
||||||
|
} else if (dt1.getTime() < dt2.getTime()) {
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (ParseException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查日期格式是否合法
|
||||||
|
* @param date
|
||||||
|
* @param style
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static boolean checkDateFormat(String date, String style) {
|
||||||
|
SimpleDateFormat DATE_FORMAT = new SimpleDateFormat(style);
|
||||||
|
try {
|
||||||
|
// 设置lenient为false.
|
||||||
|
// 否则SimpleDateFormat会比较宽松地验证日期,比如2007/02/29会被接受,并转换成2007/03/01
|
||||||
|
DATE_FORMAT.setLenient(false);
|
||||||
|
DATE_FORMAT.parse(date);
|
||||||
|
return true;
|
||||||
|
} catch (ParseException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算两个时间之间的天数差
|
||||||
|
* @param beforeDay 开始时间
|
||||||
|
* @param afterDay 结束时间
|
||||||
|
* @return 相差天数
|
||||||
|
*/
|
||||||
|
public static long getTwoDateDays(Date beforeDay, Date afterDay) {
|
||||||
|
SimpleDateFormat sm = new SimpleDateFormat(ConstantUtil.DATE_FORMAT_NUM);
|
||||||
|
long days = -1;
|
||||||
|
try {
|
||||||
|
days = (sm.parse(sm.format(afterDay)).getTime() - sm.parse(sm.format(beforeDay)).getTime()) / (1000 * 3600 * 24);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return days;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//获取时间戳11位
|
||||||
|
public static int getSecondTimestamp(Date date){
|
||||||
|
if (null == date) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
String timestamp = String.valueOf(date.getTime()/1000);
|
||||||
|
return Integer.parseInt(timestamp);
|
||||||
|
}
|
||||||
|
|
||||||
|
//获取时间戳11位
|
||||||
|
public static int getSecondTimestamp(String date){
|
||||||
|
if (null == date) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
Date date1 = strToDate(date, ConstantUtil.DATE_FORMAT);
|
||||||
|
if(date1 == null){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
String timestamp = String.valueOf(date1.getTime()/1000);
|
||||||
|
return Integer.parseInt(timestamp);
|
||||||
|
}
|
||||||
|
|
||||||
|
//获取时间戳10位
|
||||||
|
public static int getSecondTimestamp(Long timeMillis){
|
||||||
|
if (null == timeMillis) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
String timestamp = String.valueOf(timeMillis / 1000);
|
||||||
|
return Integer.parseInt(timestamp);
|
||||||
|
}
|
||||||
|
|
||||||
|
//获取时间戳11位
|
||||||
|
public static int getSecondTimestamp(){
|
||||||
|
Date date = strToDate(nowDateTime(ConstantUtil.DATE_FORMAT), ConstantUtil.DATE_FORMAT);
|
||||||
|
if (null == date) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
String timestamp = String.valueOf(date.getTime()/1000);
|
||||||
|
return Integer.parseInt(timestamp);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 获得昨天日期:yyyy-MM-dd HH:mm:ss */
|
||||||
|
public static String getYesterdayStr() {
|
||||||
|
Calendar c = Calendar.getInstance();
|
||||||
|
c.add(Calendar.DATE, -1);
|
||||||
|
SimpleDateFormat startSdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
|
return startSdf.format(c.getTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 获得本周第一天:yyyy-MM-dd HH:mm:ss */
|
||||||
|
public static String getWeekStartDay() {
|
||||||
|
Calendar c = Calendar.getInstance();
|
||||||
|
c.add(Calendar.WEEK_OF_MONTH, 0);
|
||||||
|
c.set(Calendar.DAY_OF_WEEK, 2);
|
||||||
|
SimpleDateFormat startSdf = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
|
||||||
|
return startSdf.format(c.getTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 获得本周最后一天:yyyy-MM-dd HH:mm:ss */
|
||||||
|
public static String getWeekEndDay() {
|
||||||
|
return addDay(getWeekStartDay(), 7, ConstantUtil.DATE_FORMAT);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 获得上周第一天:yyyy-MM-dd HH:mm:ss */
|
||||||
|
public static String getLastWeekStartDay() {
|
||||||
|
return addDay(getWeekStartDay(), -7, ConstantUtil.DATE_FORMAT);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 获得上周最后一天:yyyy-MM-dd HH:mm:ss */
|
||||||
|
public static String getLastWeekEndDay() {
|
||||||
|
return addDay(getLastWeekStartDay(), 7, ConstantUtil.DATE_FORMAT);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 获得本月最后一天:yyyy-MM-dd HH:mm:ss */
|
||||||
|
public static String getMonthEndDay() {
|
||||||
|
Calendar c = Calendar.getInstance();
|
||||||
|
c.set(Calendar.DAY_OF_MONTH, c.getActualMaximum(Calendar.DAY_OF_MONTH));
|
||||||
|
SimpleDateFormat endSdf = new SimpleDateFormat("yyyy-MM-dd 23:59:59");
|
||||||
|
return endSdf.format(c.getTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 获得上月第一天:yyyy-MM-dd HH:mm:ss */
|
||||||
|
public static String getLastMonthStartDay() {
|
||||||
|
Calendar c = Calendar.getInstance();
|
||||||
|
c.add(Calendar.MONTH, -1);
|
||||||
|
c.set(Calendar.DAY_OF_MONTH, 1);
|
||||||
|
SimpleDateFormat startSdf = new SimpleDateFormat("yyyy-MM-01 00:00:00");
|
||||||
|
return startSdf.format(c.getTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 获得上月最后一天:yyyy-MM-dd HH:mm:ss */
|
||||||
|
public static String getLastMonthEndDay() {
|
||||||
|
Calendar c = Calendar.getInstance();
|
||||||
|
c.add(Calendar.MONTH, -1);
|
||||||
|
c.set(Calendar.DAY_OF_MONTH, c.getActualMaximum(Calendar.DAY_OF_MONTH));
|
||||||
|
SimpleDateFormat endSdf = new SimpleDateFormat("yyyy-MM-dd 23:59:59");
|
||||||
|
return endSdf.format(c.getTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 获得上年第一天:yyyy-MM-dd HH:mm:ss */
|
||||||
|
public static String getLastYearStartDay() {
|
||||||
|
Calendar c = Calendar.getInstance();
|
||||||
|
c.add(Calendar.YEAR, -1);
|
||||||
|
SimpleDateFormat startSdf = new SimpleDateFormat("yyyy-01-01 00:00:00");
|
||||||
|
return startSdf.format(c.getTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 获得上年最后一天:yyyy-MM-dd HH:mm:ss */
|
||||||
|
public static String getLastYearEndDay() {
|
||||||
|
Calendar c = Calendar.getInstance();
|
||||||
|
c.add(Calendar.YEAR, -1);
|
||||||
|
SimpleDateFormat endSdf = new SimpleDateFormat("yyyy-12-31 23:59:59");
|
||||||
|
return endSdf.format(c.getTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 两个日期之前的相差天数
|
||||||
|
* @param starDate 开始日期
|
||||||
|
* @param endDate 结束日期
|
||||||
|
* @return 相差天数
|
||||||
|
*/
|
||||||
|
public static int daysBetween(Date starDate,Date endDate){
|
||||||
|
|
||||||
|
Calendar cal = Calendar.getInstance();
|
||||||
|
|
||||||
|
cal.setTime(starDate);
|
||||||
|
|
||||||
|
long time1 = cal.getTimeInMillis();
|
||||||
|
|
||||||
|
cal.setTime(endDate);
|
||||||
|
|
||||||
|
long time2 = cal.getTimeInMillis();
|
||||||
|
|
||||||
|
long between_days=(time2-time1)/(1000*3600*24);
|
||||||
|
|
||||||
|
return Integer.parseInt(String.valueOf(between_days));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前时间小时
|
||||||
|
* @return 当前时间小时 默认24小时
|
||||||
|
*/
|
||||||
|
public static int getCurrentHour(){
|
||||||
|
int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
|
||||||
|
return hour;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 13位时间戳转字符串
|
||||||
|
* @param timestamp
|
||||||
|
* @param dateFormat
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String timestamp2DateStr(Long timestamp, String dateFormat) {
|
||||||
|
if (ObjectUtil.isNull(timestamp)) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
if (StrUtil.isBlank(dateFormat)) {
|
||||||
|
dateFormat = ConstantUtil.DATE_FORMAT;
|
||||||
|
}
|
||||||
|
Date date = new Date(timestamp);
|
||||||
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFormat);
|
||||||
|
return simpleDateFormat.format(date);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字符串转13位时间戳
|
||||||
|
*/
|
||||||
|
public static Long dateStr2Timestamp(String dateStr, String type) {
|
||||||
|
DateTime parse = cn.hutool.core.date.DateUtil.parse(dateStr);
|
||||||
|
if (StrUtil.isNotBlank(type)) {
|
||||||
|
if (type.equals(ConstantUtil.DATE_TIME_TYPE_BEGIN)) {
|
||||||
|
parse = cn.hutool.core.date.DateUtil.beginOfDay(parse);
|
||||||
|
}
|
||||||
|
if (type.equals(ConstantUtil.DATE_TIME_TYPE_END)) {
|
||||||
|
parse = cn.hutool.core.date.DateUtil.endOfDay(parse);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return parse.getTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
310
src/main/java/com/shenghua/utils/EliminateImageUtil.java
Normal file
310
src/main/java/com/shenghua/utils/EliminateImageUtil.java
Normal file
@ -0,0 +1,310 @@
|
|||||||
|
package com.shenghua.utils;
|
||||||
|
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class EliminateImageUtil {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 坐标嘞
|
||||||
|
*/
|
||||||
|
private static class Coordinate {
|
||||||
|
private int x;
|
||||||
|
|
||||||
|
private int y;
|
||||||
|
|
||||||
|
public Coordinate(int x, int y) {
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getX() {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setX(int x) {
|
||||||
|
this.x = x;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getY() {
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setY(int y) {
|
||||||
|
this.y = y;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
Coordinate that = (Coordinate) o;
|
||||||
|
return x == that.x &&
|
||||||
|
y == that.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class CoordinateWithCenter extends Coordinate implements Comparable<CoordinateWithCenter> {
|
||||||
|
|
||||||
|
private Coordinate center;
|
||||||
|
|
||||||
|
private int distance;
|
||||||
|
|
||||||
|
public int getDistance() {
|
||||||
|
return distance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDistance(int distance) {
|
||||||
|
this.distance = distance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CoordinateWithCenter(int x, int y) {
|
||||||
|
super(x,y);
|
||||||
|
this.center = new Coordinate(0,0);
|
||||||
|
}
|
||||||
|
public CoordinateWithCenter(int x, int y,Coordinate center) {
|
||||||
|
super(x,y);
|
||||||
|
this.center = center;
|
||||||
|
this.distance = Math.abs(this.getX()-center.getX())+Math.abs(this.getY()-center.getY());
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public int compareTo(CoordinateWithCenter o) {
|
||||||
|
//负整数是小于
|
||||||
|
//0为等于
|
||||||
|
return Integer.compare(o.distance, this.distance); //正整数是大于
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int RANGE = 5;
|
||||||
|
private static int WEIGHT = 1;
|
||||||
|
|
||||||
|
|
||||||
|
public static String imageEliminate(String primaryBase64,String eraseBase64){
|
||||||
|
BufferedImage bufferedImage = ImageUtil.bufferedImage(primaryBase64);
|
||||||
|
BufferedImage bufferedMask = ImageUtil.bufferedImage(eraseBase64);
|
||||||
|
/*获取涂抹中心区域*/
|
||||||
|
Coordinate wipeCenter = getWipeCenter(bufferedMask);
|
||||||
|
/* 被涂抹的坐标,需要处理 */
|
||||||
|
List<CoordinateWithCenter> coordinateWithCenters = getWipeCoordinate(bufferedMask, wipeCenter);
|
||||||
|
|
||||||
|
System.out.println("大小:"+bufferedImage.getWidth() + "x" + bufferedImage.getHeight());
|
||||||
|
//平均颜色
|
||||||
|
Color colorAvg = getBorderAvgColor(bufferedImage, bufferedMask);
|
||||||
|
//Color colorAvg = getMostColor(bufferedImage,bufferedMask);
|
||||||
|
//已处理的坐标
|
||||||
|
Set<Coordinate> hasDoneSet = new HashSet<>();
|
||||||
|
for (CoordinateWithCenter c : coordinateWithCenters) {
|
||||||
|
/* 获取像素点周围平均像素点 */
|
||||||
|
Color color = getAvgColor(bufferedImage, bufferedMask, c.getX(), c.getY(),colorAvg,hasDoneSet);
|
||||||
|
bufferedImage.setRGB(c.getX(), c.getY(), color.getRGB());
|
||||||
|
Coordinate coordinate = new Coordinate(c.getX(), c.getY());
|
||||||
|
hasDoneSet.add(coordinate);
|
||||||
|
}
|
||||||
|
return ImageUtil.imageToBase64(bufferedImage);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<CoordinateWithCenter> getWipeCoordinate(BufferedImage bufferedMask, Coordinate wipeCenter) {
|
||||||
|
List<CoordinateWithCenter> list = new ArrayList<>();
|
||||||
|
int height = bufferedMask.getHeight();
|
||||||
|
int width = bufferedMask.getWidth();
|
||||||
|
for (int j = 0; j < height; j++) {
|
||||||
|
for (int i = 0; i < width; i++) {
|
||||||
|
if (bufferedMask.getRGB(i, j) != -1) {
|
||||||
|
list.add(new CoordinateWithCenter(i, j, wipeCenter));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Collections.sort(list);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
*获取周围的像素点的平均像素
|
||||||
|
* @param bufferedImage
|
||||||
|
* @param bufferedMask
|
||||||
|
* @param x 像素点坐标x
|
||||||
|
* @param y 像素点坐标y
|
||||||
|
* @param colorAvg 填充颜色
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private static Color getAvgColor(BufferedImage bufferedImage, BufferedImage bufferedMask, int x, int y, Color colorAvg,Set<Coordinate> hasDoneSet) {
|
||||||
|
int count = 0;
|
||||||
|
int aRed = 0, aBlue = 0, aGreen = 0;
|
||||||
|
|
||||||
|
for (int a = x - RANGE; a < x + RANGE; a++) {
|
||||||
|
for (int b = y - RANGE; b < y + RANGE; b++) {
|
||||||
|
//越界
|
||||||
|
if (a <= 0 || a > (bufferedImage.getWidth() - 1)
|
||||||
|
|| b < 0 || b > (bufferedImage.getHeight() - 1)
|
||||||
|
|| (a == x && b == y)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
//没涂抹的区域,或者已经处理过
|
||||||
|
if (bufferedMask.getRGB(a, b) == -1 ||hasDoneSet.contains(new Coordinate(a, b))) {
|
||||||
|
int ragb = bufferedImage.getRGB(a, b);
|
||||||
|
Color color = new Color(ragb, true);
|
||||||
|
int blue = color.getBlue();
|
||||||
|
int red = color.getRed();
|
||||||
|
int green = color.getGreen();
|
||||||
|
aRed = aRed + red * WEIGHT;
|
||||||
|
aBlue = aBlue + blue * WEIGHT;
|
||||||
|
aGreen = aGreen + green * WEIGHT;
|
||||||
|
count = count + WEIGHT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (count == 0) {
|
||||||
|
|
||||||
|
return colorAvg;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Color(aRed / count, aGreen / count, aBlue / count);
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
* 获取掩码涂抹的中心位置
|
||||||
|
* @param bufferedMask 掩码图
|
||||||
|
* @return 返回中心坐标
|
||||||
|
*/
|
||||||
|
private static Coordinate getWipeCenter(BufferedImage bufferedMask) {
|
||||||
|
int width = bufferedMask.getWidth();
|
||||||
|
int height = bufferedMask.getHeight();
|
||||||
|
int top = height - 1, bottom = 0, left = height - 1, right = 0;
|
||||||
|
for (int j = 0; j < height; j++) {
|
||||||
|
for (int i = 0; i < width; i++) {
|
||||||
|
if (bufferedMask.getRGB(i, j) != -1) {
|
||||||
|
right = Math.max(right, i);
|
||||||
|
left = Math.min(left, i);
|
||||||
|
bottom = Math.max(bottom, j);
|
||||||
|
top = Math.min(top, j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new Coordinate((left + right) / 2, (top + bottom) / 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
* 获取掩码未涂抹的平均颜色,如果全部涂抹,返回整个图的平均颜色,用于填充涂抹区域
|
||||||
|
* @param bufferedImage 原图
|
||||||
|
* @param bufferedMask 掩码图
|
||||||
|
* @return 返回平均颜色
|
||||||
|
*/
|
||||||
|
private static Color getAllAvgColor(BufferedImage bufferedImage, BufferedImage bufferedMask) {
|
||||||
|
int aRed = 0, aBlue = 0, aGreen = 0, count = 0, bRed = 0, bBlue = 0, bGreen = 0;
|
||||||
|
int width = bufferedMask.getWidth();
|
||||||
|
int height = bufferedMask.getHeight();
|
||||||
|
for (int j = 0; j < height; j++) {
|
||||||
|
for (int i = 0; i < width; i++) {
|
||||||
|
int ragb = bufferedImage.getRGB(i, j);
|
||||||
|
Color color = new Color(ragb, true);
|
||||||
|
if (bufferedMask.getRGB(i, j) == -1) {//未被涂抹区域
|
||||||
|
aRed = aRed + color.getRed();
|
||||||
|
aBlue = aBlue + color.getBlue();
|
||||||
|
aGreen = aGreen + color.getGreen();
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
bRed = bRed + color.getRed();
|
||||||
|
bBlue = bBlue + color.getBlue();
|
||||||
|
bGreen = bGreen + color.getGreen();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//全部涂抹
|
||||||
|
if (count == 0) {
|
||||||
|
count = width*height;
|
||||||
|
return new Color(bRed / count, bGreen / count, bBlue / count);
|
||||||
|
} else {
|
||||||
|
return new Color(aRed / count, aGreen / count, aBlue / count);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/***
|
||||||
|
* 获取边界平均颜色
|
||||||
|
* @param bufferedImage
|
||||||
|
* @param bufferedMask
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private static Color getBorderAvgColor(BufferedImage bufferedImage, BufferedImage bufferedMask) {
|
||||||
|
int aRed = 0, aBlue = 0, aGreen = 0, count = 0, bRed = 0, bBlue = 0, bGreen = 0;
|
||||||
|
Set<Coordinate> coordinates = new HashSet<>();
|
||||||
|
int width = bufferedMask.getWidth();
|
||||||
|
int height = bufferedMask.getHeight();
|
||||||
|
for (int j = 0; j < height; j++) {
|
||||||
|
for (int i = 0; i < width; i++) {
|
||||||
|
int ragb = bufferedImage.getRGB(i, j);
|
||||||
|
Color color = new Color(ragb, true);
|
||||||
|
if (bufferedMask.getRGB(i,j)==-1){//没被涂抹
|
||||||
|
for (int a = i - 1; a < i + 1; a++) {
|
||||||
|
for (int b = j - 1; b < j + 1; b++) {
|
||||||
|
//越界
|
||||||
|
if (a <= 0 || a > (bufferedImage.getWidth() - 1)
|
||||||
|
|| b < 0 || b > (bufferedImage.getHeight() - 1)
|
||||||
|
|| (a == i && b == j)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (bufferedMask.getRGB(a,b)!=-1) {//是边界点
|
||||||
|
if (coordinates.add(new Coordinate(i,j))) {
|
||||||
|
aRed = aRed + color.getRed();
|
||||||
|
aBlue = aBlue + color.getBlue();
|
||||||
|
aGreen = aGreen + color.getGreen();
|
||||||
|
count++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bRed = bRed + color.getRed();
|
||||||
|
bBlue = bBlue + color.getBlue();
|
||||||
|
bGreen = bGreen + color.getGreen();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//全部涂抹
|
||||||
|
if (coordinates.size() == 0) {//全部涂抹,取平均色
|
||||||
|
count = width*height;
|
||||||
|
return new Color(bRed / count, bGreen / count, bBlue / count);
|
||||||
|
} else {
|
||||||
|
return new Color(aRed / count, aGreen / count, aBlue / count);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
* 获取颜色最多的
|
||||||
|
* @param bufferedImage 原图
|
||||||
|
* @param bufferedMask 掩码图
|
||||||
|
* @return 返回最多的颜色
|
||||||
|
*/
|
||||||
|
private static Color getMostColor(BufferedImage bufferedImage, BufferedImage bufferedMask) {
|
||||||
|
int countArgb = 0, retArgb = 0;
|
||||||
|
int width = bufferedMask.getWidth();
|
||||||
|
int height = bufferedMask.getHeight();
|
||||||
|
HashMap<Integer, Integer> map = new HashMap();
|
||||||
|
for (int j = 0; j < height; j++) {
|
||||||
|
for (int i = 0; i < width; i++) {
|
||||||
|
if (bufferedMask.getRGB(i, j) == -1) {//未被涂抹区域
|
||||||
|
int ragb = bufferedImage.getRGB(i, j);
|
||||||
|
map.put(ragb, map.get(ragb) == null ? 0 : map.get(ragb) + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (Integer key : map.keySet()) {
|
||||||
|
if (map.get(key) > countArgb) {
|
||||||
|
countArgb = map.get(key);
|
||||||
|
retArgb = key;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new Color(retArgb);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
67
src/main/java/com/shenghua/utils/FileUtil.java
Normal file
67
src/main/java/com/shenghua/utils/FileUtil.java
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
package com.shenghua.utils;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
public class FileUtil {
|
||||||
|
/**
|
||||||
|
* 读取文件内容,作为字符串返回
|
||||||
|
*/
|
||||||
|
public static String readFileAsString(String filePath) throws IOException {
|
||||||
|
File file = new File(filePath);
|
||||||
|
if (!file.exists()) {
|
||||||
|
throw new FileNotFoundException(filePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (file.length() > 1024 * 1024 * 1024) {
|
||||||
|
throw new IOException("File is too large");
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder sb = new StringBuilder((int) (file.length()));
|
||||||
|
// 创建字节输入流
|
||||||
|
FileInputStream fis = new FileInputStream(filePath);
|
||||||
|
// 创建一个长度为10240的Buffer
|
||||||
|
byte[] bbuf = new byte[10240];
|
||||||
|
// 用于保存实际读取的字节数
|
||||||
|
int hasRead = 0;
|
||||||
|
while ( (hasRead = fis.read(bbuf)) > 0 ) {
|
||||||
|
sb.append(new String(bbuf, 0, hasRead));
|
||||||
|
}
|
||||||
|
fis.close();
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据文件路径读取byte[] 数组
|
||||||
|
*/
|
||||||
|
public static byte[] readFileByBytes(String filePath) throws IOException {
|
||||||
|
File file = new File(filePath);
|
||||||
|
if (!file.exists()) {
|
||||||
|
throw new FileNotFoundException(filePath);
|
||||||
|
} else {
|
||||||
|
ByteArrayOutputStream bos = new ByteArrayOutputStream((int) file.length());
|
||||||
|
BufferedInputStream in = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
in = new BufferedInputStream(new FileInputStream(file));
|
||||||
|
short bufSize = 1024;
|
||||||
|
byte[] buffer = new byte[bufSize];
|
||||||
|
int len1;
|
||||||
|
while (-1 != (len1 = in.read(buffer, 0, bufSize))) {
|
||||||
|
bos.write(buffer, 0, len1);
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] var7 = bos.toByteArray();
|
||||||
|
return var7;
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (in != null) {
|
||||||
|
in.close();
|
||||||
|
}
|
||||||
|
} catch (IOException var14) {
|
||||||
|
var14.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
bos.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
238
src/main/java/com/shenghua/utils/HttpPoolUtil.java
Normal file
238
src/main/java/com/shenghua/utils/HttpPoolUtil.java
Normal file
@ -0,0 +1,238 @@
|
|||||||
|
package com.shenghua.utils;
|
||||||
|
|
||||||
|
import org.apache.http.*;
|
||||||
|
import org.apache.http.client.HttpRequestRetryHandler;
|
||||||
|
import org.apache.http.client.config.RequestConfig;
|
||||||
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||||
|
import org.apache.http.client.methods.HttpGet;
|
||||||
|
import org.apache.http.client.protocol.HttpClientContext;
|
||||||
|
import org.apache.http.client.utils.URIBuilder;
|
||||||
|
import org.apache.http.config.ConnectionConfig;
|
||||||
|
import org.apache.http.config.MessageConstraints;
|
||||||
|
import org.apache.http.config.SocketConfig;
|
||||||
|
import org.apache.http.conn.ConnectTimeoutException;
|
||||||
|
import org.apache.http.conn.HttpClientConnectionManager;
|
||||||
|
import org.apache.http.conn.routing.HttpRoute;
|
||||||
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
|
import org.apache.http.impl.client.DefaultHttpRequestRetryHandler;
|
||||||
|
import org.apache.http.impl.client.HttpClients;
|
||||||
|
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
|
||||||
|
import org.apache.http.protocol.HttpContext;
|
||||||
|
import org.apache.http.util.EntityUtils;
|
||||||
|
|
||||||
|
import javax.net.ssl.SSLException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InterruptedIOException;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
import java.net.UnknownHostException;
|
||||||
|
import java.nio.charset.CodingErrorAction;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
public class HttpPoolUtil {
|
||||||
|
//连接池管理器
|
||||||
|
private static PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager();
|
||||||
|
|
||||||
|
static {
|
||||||
|
connManager.setMaxTotal(200); //设置最大连接数
|
||||||
|
connManager.setDefaultMaxPerRoute(50); //设置默认路由最大连接数
|
||||||
|
connManager.setMaxPerRoute(new HttpRoute(new HttpHost("localhost", 80)), 100);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* socket配置(默认配置 和 某个host的配置)
|
||||||
|
*/
|
||||||
|
SocketConfig socketConfig = SocketConfig.custom()
|
||||||
|
.setTcpNoDelay(true) //是否立即发送数据,设置为true会关闭Socket缓冲,默认为false
|
||||||
|
.setSoReuseAddress(true) //是否可以在一个进程关闭Socket后,即使它还没有释放端口,其它进程还可以立即重用端口
|
||||||
|
.setSoTimeout(500) //接收数据的等待超时时间,单位ms
|
||||||
|
.setSoLinger(60) //关闭Socket时,要么发送完所有数据,要么等待60s后,就关闭连接,此时socket.close()是阻塞的
|
||||||
|
.setSoKeepAlive(true) //开启监视TCP连接是否有效
|
||||||
|
.build();
|
||||||
|
connManager.setDefaultSocketConfig(socketConfig);
|
||||||
|
connManager.setSocketConfig(new HttpHost("localhost", 80), socketConfig);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* HTTP connection相关配置(默认配置 和 某个host的配置)
|
||||||
|
* 一般不修改HTTP connection相关配置,故不设置
|
||||||
|
*/
|
||||||
|
//消息约束
|
||||||
|
MessageConstraints messageConstraints = MessageConstraints.custom()
|
||||||
|
.setMaxHeaderCount(200)
|
||||||
|
.setMaxLineLength(2000)
|
||||||
|
.build();
|
||||||
|
//Http connection相关配置
|
||||||
|
ConnectionConfig connectionConfig = ConnectionConfig.custom()
|
||||||
|
.setMalformedInputAction(CodingErrorAction.IGNORE)
|
||||||
|
.setUnmappableInputAction(CodingErrorAction.IGNORE)
|
||||||
|
.setCharset(Consts.UTF_8)
|
||||||
|
.setMessageConstraints(messageConstraints)
|
||||||
|
.build();
|
||||||
|
//一般不修改HTTP connection相关配置,故不设置
|
||||||
|
//connManager.setDefaultConnectionConfig(connectionConfig);
|
||||||
|
//connManager.setConnectionConfig(new HttpHost("somehost", 80), ConnectionConfig.DEFAULT);
|
||||||
|
/**
|
||||||
|
* 重试处理
|
||||||
|
* 默认是重试3次
|
||||||
|
*/
|
||||||
|
//禁用重试(参数:retryCount、requestSentRetryEnabled)
|
||||||
|
HttpRequestRetryHandler requestRetryHandler = new DefaultHttpRequestRetryHandler(0, false);
|
||||||
|
//自定义重试策略
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static RequestConfig defaultRequestConfig = RequestConfig.custom()
|
||||||
|
.setConnectTimeout(2 * 1000) //连接超时时间
|
||||||
|
.setSocketTimeout(2 * 1000) //读超时时间(等待数据超时时间)
|
||||||
|
.setConnectionRequestTimeout(500) //从池中获取连接超时时间
|
||||||
|
// .setStaleConnectionCheckEnabled(true)//检查是否为陈旧的连接,默认为true,类似testOnBorrow
|
||||||
|
.build();
|
||||||
|
|
||||||
|
|
||||||
|
static HttpRequestRetryHandler myRetryHandler = new HttpRequestRetryHandler() {
|
||||||
|
|
||||||
|
public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {
|
||||||
|
//Do not retry if over max retry count
|
||||||
|
if (executionCount >= 3) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
//Timeout
|
||||||
|
if (exception instanceof InterruptedIOException) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
//Unknown host
|
||||||
|
if (exception instanceof UnknownHostException) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
//Connection refused
|
||||||
|
if (exception instanceof ConnectTimeoutException) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
//SSL handshake exception
|
||||||
|
if (exception instanceof SSLException) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
HttpClientContext clientContext = HttpClientContext.adapt(context);
|
||||||
|
HttpRequest request = clientContext.getRequest();
|
||||||
|
boolean idempotent = !(request instanceof HttpEntityEnclosingRequest);
|
||||||
|
//Retry if the request is considered idempotent
|
||||||
|
//如果请求类型不是HttpEntityEnclosingRequest,被认为是幂等的,那么就重试
|
||||||
|
//HttpEntityEnclosingRequest指的是有请求体的request,比HttpRequest多一个Entity属性
|
||||||
|
//而常用的GET请求是没有请求体的,POST、PUT都是有请求体的
|
||||||
|
//Rest一般用GET请求获取数据,故幂等,POST用于新增数据,故不幂等
|
||||||
|
if (idempotent) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
static CloseableHttpClient httpClient = HttpClients.custom()
|
||||||
|
.setConnectionManager(connManager) //连接管理器
|
||||||
|
// .setProxy(new HttpHost("192.168.1.156", 1080)) //设置代理
|
||||||
|
.setDefaultRequestConfig(defaultRequestConfig) //默认请求配置
|
||||||
|
.setRetryHandler(myRetryHandler) //重试策略
|
||||||
|
.build();
|
||||||
|
|
||||||
|
|
||||||
|
public static String get(String url){
|
||||||
|
return get(url, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static String get(String url, Map param) {
|
||||||
|
//创建一个Get请求,并重新设置请求参数,覆盖默认
|
||||||
|
try {
|
||||||
|
URIBuilder uriBuilder = new URIBuilder(url);
|
||||||
|
if (param != null){
|
||||||
|
for (Object o : param.keySet()) {
|
||||||
|
String value = param.get(o).toString();
|
||||||
|
uriBuilder.addParameter(o.toString(), value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
URI uri = uriBuilder.build();
|
||||||
|
HttpGet httpget = new HttpGet(uri);
|
||||||
|
RequestConfig requestConfig = RequestConfig.copy(defaultRequestConfig)
|
||||||
|
.setSocketTimeout(5000)
|
||||||
|
.setConnectTimeout(5000)
|
||||||
|
.setConnectionRequestTimeout(5000)
|
||||||
|
//设置代理
|
||||||
|
//.setProxy(new HttpHost("myotherproxy", 8080))
|
||||||
|
.build();
|
||||||
|
httpget.setConfig(requestConfig);
|
||||||
|
|
||||||
|
CloseableHttpResponse response = null;
|
||||||
|
//执行请求
|
||||||
|
try {
|
||||||
|
response = httpClient.execute(httpget);
|
||||||
|
HttpEntity entity = response.getEntity();
|
||||||
|
if (entity != null) {
|
||||||
|
return EntityUtils.toString(entity);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (response != null) {
|
||||||
|
try {
|
||||||
|
response.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (URISyntaxException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static class IdleConnectionMonitorThread extends Thread {
|
||||||
|
|
||||||
|
private final HttpClientConnectionManager connMgr;
|
||||||
|
private volatile boolean shutdown;
|
||||||
|
|
||||||
|
public IdleConnectionMonitorThread(HttpClientConnectionManager connMgr) {
|
||||||
|
super();
|
||||||
|
this.connMgr = connMgr;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
while (!shutdown) {
|
||||||
|
synchronized (this) {
|
||||||
|
wait(5000);
|
||||||
|
// Close expired connections
|
||||||
|
connMgr.closeExpiredConnections();
|
||||||
|
// Optionally, close connections
|
||||||
|
// that have been idle longer than 30 sec
|
||||||
|
connMgr.closeIdleConnections(30, TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (InterruptedException ex) {
|
||||||
|
// terminate
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void shutdown() {
|
||||||
|
shutdown = true;
|
||||||
|
synchronized (this) {
|
||||||
|
notifyAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
72
src/main/java/com/shenghua/utils/HttpUtil.java
Normal file
72
src/main/java/com/shenghua/utils/HttpUtil.java
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
package com.shenghua.utils;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.DataOutputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
public class HttpUtil {
|
||||||
|
public static String post(String requestUrl, String accessToken, String params)
|
||||||
|
throws Exception {
|
||||||
|
String contentType = "application/x-www-form-urlencoded";
|
||||||
|
return HttpUtil.post(requestUrl, accessToken, contentType, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String post(String requestUrl, String accessToken, String contentType, String params)
|
||||||
|
throws Exception {
|
||||||
|
String encoding = "UTF-8";
|
||||||
|
if (requestUrl.contains("nlp")) {
|
||||||
|
encoding = "GBK";
|
||||||
|
}
|
||||||
|
return HttpUtil.post(requestUrl, accessToken, contentType, params, encoding);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String post(String requestUrl, String accessToken, String contentType, String params, String encoding)
|
||||||
|
throws Exception {
|
||||||
|
String url = requestUrl + "?access_token=" + accessToken;
|
||||||
|
return HttpUtil.postGeneralUrl(url, contentType, params, encoding);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String postGeneralUrl(String generalUrl, String contentType, String params, String encoding)
|
||||||
|
throws Exception {
|
||||||
|
URL url = new URL(generalUrl);
|
||||||
|
// 打开和URL之间的连接
|
||||||
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||||
|
connection.setRequestMethod("POST");
|
||||||
|
// 设置通用的请求属性
|
||||||
|
connection.setRequestProperty("Content-Type", contentType);
|
||||||
|
connection.setRequestProperty("Connection", "Keep-Alive");
|
||||||
|
connection.setUseCaches(false);
|
||||||
|
connection.setDoOutput(true);
|
||||||
|
connection.setDoInput(true);
|
||||||
|
|
||||||
|
// 得到请求的输出流对象
|
||||||
|
DataOutputStream out = new DataOutputStream(connection.getOutputStream());
|
||||||
|
out.write(params.getBytes(encoding));
|
||||||
|
out.flush();
|
||||||
|
out.close();
|
||||||
|
|
||||||
|
// 建立实际的连接
|
||||||
|
connection.connect();
|
||||||
|
// 获取所有响应头字段
|
||||||
|
Map<String, List<String>> headers = connection.getHeaderFields();
|
||||||
|
// 遍历所有的响应头字段
|
||||||
|
for (String key : headers.keySet()) {
|
||||||
|
System.err.println(key + "--->" + headers.get(key));
|
||||||
|
}
|
||||||
|
// 定义 BufferedReader输入流来读取URL的响应
|
||||||
|
BufferedReader in = null;
|
||||||
|
in = new BufferedReader(
|
||||||
|
new InputStreamReader(connection.getInputStream(), encoding));
|
||||||
|
String result = "";
|
||||||
|
String getLine;
|
||||||
|
while ((getLine = in.readLine()) != null) {
|
||||||
|
result += getLine;
|
||||||
|
}
|
||||||
|
in.close();
|
||||||
|
System.err.println("result:" + result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
374
src/main/java/com/shenghua/utils/HttpUtils.java
Normal file
374
src/main/java/com/shenghua/utils/HttpUtils.java
Normal file
@ -0,0 +1,374 @@
|
|||||||
|
|
||||||
|
package com.shenghua.utils;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.web.context.request.RequestContextHolder;
|
||||||
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||||
|
|
||||||
|
import javax.net.ssl.*;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.io.*;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLConnection;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.security.cert.CertificateException;
|
||||||
|
import java.security.cert.X509Certificate;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* http context工具类
|
||||||
|
*/
|
||||||
|
public class HttpUtils {
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(HttpUtils.class);
|
||||||
|
|
||||||
|
private static int connectTimeout = 3000;
|
||||||
|
private static int ios_connectTimeout = 10000;
|
||||||
|
|
||||||
|
private static class TrustAnyTrustManager implements X509TrustManager {
|
||||||
|
|
||||||
|
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
|
||||||
|
}
|
||||||
|
|
||||||
|
public X509Certificate[] getAcceptedIssuers() {
|
||||||
|
return new X509Certificate[]{};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class TrustAnyHostnameVerifier implements HostnameVerifier {
|
||||||
|
public boolean verify(String hostname, SSLSession session) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String sendGet(String url) {
|
||||||
|
String result = "";
|
||||||
|
BufferedReader in = null;
|
||||||
|
try {
|
||||||
|
// String urlNameString = url;
|
||||||
|
URL realUrl = new URL(url);
|
||||||
|
|
||||||
|
// 打开和URL之间的连接
|
||||||
|
URLConnection connection = realUrl.openConnection();
|
||||||
|
|
||||||
|
// 设置通用的请求属性
|
||||||
|
connection.setRequestProperty("accept", "*/*");
|
||||||
|
connection.setRequestProperty("connection", "Keep-Alive");
|
||||||
|
connection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
|
||||||
|
|
||||||
|
// 建立实际的连接
|
||||||
|
connection.connect();
|
||||||
|
|
||||||
|
// 获取所有响应头字段
|
||||||
|
Map<String, List<String>> map = connection.getHeaderFields();
|
||||||
|
|
||||||
|
// 遍历所有的响应头字段
|
||||||
|
for (String key : map.keySet()) {
|
||||||
|
System.out.println(key + "--->" + map.get(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 定义 BufferedReader输入流来读取URL的响应
|
||||||
|
in = new BufferedReader(new InputStreamReader(
|
||||||
|
connection.getInputStream()));
|
||||||
|
String line;
|
||||||
|
while ((line = in.readLine()) != null) {
|
||||||
|
result += line;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println("发送GET请求出现异常!" + e);
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 使用finally块来关闭输入流
|
||||||
|
finally {
|
||||||
|
try {
|
||||||
|
if (in != null) {
|
||||||
|
in.close();
|
||||||
|
}
|
||||||
|
} catch (Exception e2) {
|
||||||
|
e2.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param url
|
||||||
|
* @param param
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String sendGet(String url, String param) {
|
||||||
|
String result = "";
|
||||||
|
BufferedReader in = null;
|
||||||
|
try {
|
||||||
|
String urlNameString = url + "?" + param;
|
||||||
|
URL realUrl = new URL(urlNameString);
|
||||||
|
// 打开和URL之间的连接
|
||||||
|
URLConnection connection = realUrl.openConnection();
|
||||||
|
// 设置通用的请求属性
|
||||||
|
connection.setRequestProperty("accept", "*/*");
|
||||||
|
connection.setRequestProperty("connection", "Keep-Alive");
|
||||||
|
connection.setRequestProperty("xm-sign","d9fdda2188c52dc128cd0d3ba157f957(79)1626234305702(74)1626232895270");
|
||||||
|
connection.setRequestProperty("user-agent",
|
||||||
|
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
|
||||||
|
// 建立实际的连接
|
||||||
|
connection.connect();
|
||||||
|
|
||||||
|
// 定义 BufferedReader输入流来读取URL的响应
|
||||||
|
in = new BufferedReader(new InputStreamReader(
|
||||||
|
connection.getInputStream()));
|
||||||
|
String line;
|
||||||
|
while ((line = in.readLine()) != null) {
|
||||||
|
result += line;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println("发送GET请求出现异常!" + e);
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
// 使用finally块来关闭输入流
|
||||||
|
finally {
|
||||||
|
try {
|
||||||
|
if (in != null) {
|
||||||
|
in.close();
|
||||||
|
}
|
||||||
|
} catch (Exception e2) {
|
||||||
|
e2.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String sendSSLPost(String url, String param) {
|
||||||
|
try {
|
||||||
|
SSLContext sc = SSLContext.getInstance("SSL");
|
||||||
|
sc.init(null, new TrustManager[]{new TrustAnyTrustManager()}, new java.security.SecureRandom());
|
||||||
|
URL console = new URL(url);
|
||||||
|
HttpsURLConnection conn = (HttpsURLConnection) console.openConnection();
|
||||||
|
conn.setSSLSocketFactory(sc.getSocketFactory());
|
||||||
|
conn.setHostnameVerifier(new TrustAnyHostnameVerifier());
|
||||||
|
conn.setRequestMethod("POST");
|
||||||
|
conn.setRequestProperty("Content-Type", "application/json");
|
||||||
|
conn.setRequestProperty("Proxy-Connection", "Keep-Alive");
|
||||||
|
conn.setConnectTimeout(ios_connectTimeout);
|
||||||
|
conn.setDoInput(true);
|
||||||
|
conn.setDoOutput(true);
|
||||||
|
BufferedOutputStream hurlBufOus = new BufferedOutputStream(conn.getOutputStream());
|
||||||
|
hurlBufOus.write(param.getBytes(StandardCharsets.UTF_8));
|
||||||
|
hurlBufOus.flush();
|
||||||
|
|
||||||
|
InputStream is = conn.getInputStream();
|
||||||
|
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
|
||||||
|
StringBuffer result = new StringBuffer();
|
||||||
|
String line;
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
result.append(line);
|
||||||
|
}
|
||||||
|
return result.toString();
|
||||||
|
} catch (Exception e) {
|
||||||
|
// log.error("[" + BaseConstants.LOG_FLAG_PRE_ERROR + "http]:", e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String sendPost(String url, String param) {
|
||||||
|
try {
|
||||||
|
URLConnection conn = null;
|
||||||
|
|
||||||
|
URL realUrl = new URL(url);
|
||||||
|
// 打开和URL之间的连接
|
||||||
|
conn = realUrl.openConnection();
|
||||||
|
// 设置通用的请求属性
|
||||||
|
conn.setRequestProperty("accept", "*/*");
|
||||||
|
conn.setRequestProperty("connection", "Keep-Alive");
|
||||||
|
conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
|
||||||
|
// 发送POST请求必须设置如下两行
|
||||||
|
conn.setDoOutput(true);
|
||||||
|
conn.setDoInput(true);
|
||||||
|
conn.setConnectTimeout(connectTimeout);
|
||||||
|
try (PrintWriter out = new PrintWriter(new OutputStreamWriter(conn.getOutputStream(), StandardCharsets.UTF_8))) {
|
||||||
|
out.print(param);
|
||||||
|
out.flush();
|
||||||
|
try (BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8))) {
|
||||||
|
StringBuffer result = new StringBuffer();
|
||||||
|
String line;
|
||||||
|
while ((line = in.readLine()) != null) {
|
||||||
|
result.append(line);
|
||||||
|
}
|
||||||
|
return result.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Http post的工具方法
|
||||||
|
*
|
||||||
|
* @param httpUrl 请求地址
|
||||||
|
* @param data 请求数据
|
||||||
|
* @param connectTimeout 连接超时时间
|
||||||
|
* @param readTimeout 读取超时时间
|
||||||
|
* @param headers 请求头
|
||||||
|
* @return 将响应body作为String返回
|
||||||
|
* @throws IOException 请求中的IO异常
|
||||||
|
*/
|
||||||
|
public static String sendPost(String httpUrl, String contentType, String data, int connectTimeout, int readTimeout, Map<String, String> headers) {
|
||||||
|
OutputStream output = null;
|
||||||
|
InputStream in = null;
|
||||||
|
HttpURLConnection urlConnection = null;
|
||||||
|
BufferedReader bufferedReader = null;
|
||||||
|
InputStreamReader inputStreamReader = null;
|
||||||
|
try {
|
||||||
|
URL url = new URL(httpUrl);
|
||||||
|
urlConnection = (HttpURLConnection) url.openConnection();
|
||||||
|
urlConnection.setRequestMethod("POST");
|
||||||
|
urlConnection.setDoOutput(true);
|
||||||
|
urlConnection.setDoInput(true);
|
||||||
|
urlConnection.setRequestProperty("Content-Type", contentType);
|
||||||
|
if (headers != null) {
|
||||||
|
for (String key : headers.keySet()) {
|
||||||
|
urlConnection.setRequestProperty(key, headers.get(key));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
urlConnection.setConnectTimeout(connectTimeout);
|
||||||
|
urlConnection.setReadTimeout(readTimeout);
|
||||||
|
urlConnection.connect();
|
||||||
|
// 发送数据
|
||||||
|
output = urlConnection.getOutputStream();
|
||||||
|
output.write(data.getBytes(StandardCharsets.UTF_8));
|
||||||
|
output.flush();
|
||||||
|
// 读取响应
|
||||||
|
if (urlConnection.getResponseCode() < 400) {
|
||||||
|
in = urlConnection.getInputStream();
|
||||||
|
} else {
|
||||||
|
in = urlConnection.getErrorStream();
|
||||||
|
}
|
||||||
|
inputStreamReader = new InputStreamReader(in, StandardCharsets.UTF_8);
|
||||||
|
bufferedReader = new BufferedReader(inputStreamReader);
|
||||||
|
StringBuilder strBuf = new StringBuilder();
|
||||||
|
String str;
|
||||||
|
while ((str = bufferedReader.readLine()) != null) {
|
||||||
|
strBuf.append(str);
|
||||||
|
}
|
||||||
|
return strBuf.toString();
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (bufferedReader != null) {
|
||||||
|
bufferedReader.close();
|
||||||
|
}
|
||||||
|
if (inputStreamReader != null) {
|
||||||
|
inputStreamReader.close();
|
||||||
|
}
|
||||||
|
if (in != null) {
|
||||||
|
in.close();
|
||||||
|
}
|
||||||
|
if (urlConnection != null) {
|
||||||
|
urlConnection.disconnect();
|
||||||
|
}
|
||||||
|
} catch (IOException ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HttpServletRequest getHttpServletRequest() {
|
||||||
|
return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getDomain() {
|
||||||
|
HttpServletRequest request = getHttpServletRequest();
|
||||||
|
StringBuffer url = request.getRequestURL();
|
||||||
|
return url.delete(url.length() - request.getRequestURI().length(), url.length()).toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getOrigin() {
|
||||||
|
HttpServletRequest request = getHttpServletRequest();
|
||||||
|
return request.getHeader("Origin");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取request中body数据
|
||||||
|
*
|
||||||
|
* @param request
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String getBody(HttpServletRequest request) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
try (InputStream inputStream = request.getInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));) {
|
||||||
|
String line = "";
|
||||||
|
while ((line = reader.readLine()) != null) {//todo 换行
|
||||||
|
sb.append(line);
|
||||||
|
}
|
||||||
|
} catch (IOException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] getByteArrBody(HttpServletRequest request) {
|
||||||
|
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
||||||
|
try (InputStream inputStream = request.getInputStream(); BufferedInputStream byteOutputStream = new BufferedInputStream(inputStream);) {
|
||||||
|
byte[] bytes = new byte[1024];
|
||||||
|
int a;
|
||||||
|
while ((a = byteOutputStream.read(bytes)) != -1) {
|
||||||
|
byteArrayOutputStream.write(bytes, 0, a);
|
||||||
|
}
|
||||||
|
} catch (IOException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
return byteArrayOutputStream.toByteArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取request中body数据
|
||||||
|
*
|
||||||
|
* @param request
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String writeToBody(HttpServletRequest request, Map<String, Serializable> params) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
try (InputStream inputStream = request.getInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));) {
|
||||||
|
String line = "";
|
||||||
|
while ((line = reader.readLine()) != null) {//todo 换行
|
||||||
|
sb.append(line);
|
||||||
|
}
|
||||||
|
} catch (IOException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static String getRealClientIp(HttpServletRequest request) {
|
||||||
|
String ip = request.getHeader("x-forwarded-for");
|
||||||
|
if (ip != null) {
|
||||||
|
ip = ip.split(",")[0];
|
||||||
|
}
|
||||||
|
if (StringUtils.isBlank(ip) || "unknown".equalsIgnoreCase(ip)) {
|
||||||
|
ip = request.getHeader("Proxy-Client-IP");
|
||||||
|
}
|
||||||
|
if (StringUtils.isBlank(ip) || "unknown".equalsIgnoreCase(ip)) {
|
||||||
|
ip = request.getHeader("WL-Proxy-Client-IP");
|
||||||
|
}
|
||||||
|
if (StringUtils.isBlank(ip) || "unknown".equalsIgnoreCase(ip)) {
|
||||||
|
ip = request.getHeader("X-Real-IP");
|
||||||
|
}
|
||||||
|
if (StringUtils.isBlank(ip) || "unknown".equalsIgnoreCase(ip)) {
|
||||||
|
ip = request.getRemoteAddr();
|
||||||
|
}
|
||||||
|
return ip;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
92
src/main/java/com/shenghua/utils/ImageUtil.java
Normal file
92
src/main/java/com/shenghua/utils/ImageUtil.java
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
package com.shenghua.utils;
|
||||||
|
|
||||||
|
import sun.misc.BASE64Decoder;
|
||||||
|
import sun.misc.BASE64Encoder;
|
||||||
|
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.*;
|
||||||
|
|
||||||
|
public class ImageUtil {
|
||||||
|
|
||||||
|
public static boolean isImage(InputStream inputStream) {
|
||||||
|
try {
|
||||||
|
BufferedImage image = ImageIO.read(inputStream);
|
||||||
|
if (image == null || image.getWidth() <= 0 || image.getHeight() <= 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BufferedImage bufferedImage(File file) {
|
||||||
|
try {
|
||||||
|
BufferedImage image = ImageIO.read(file);
|
||||||
|
if (image == null || image.getWidth() <= 0 || image.getHeight() <= 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return image;
|
||||||
|
} catch (Exception e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BufferedImage bufferedImage(String base64) {
|
||||||
|
try {
|
||||||
|
BASE64Decoder decoder = new sun.misc.BASE64Decoder();
|
||||||
|
byte[] bytes = decoder.decodeBuffer(base64);
|
||||||
|
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
|
||||||
|
BufferedImage image = ImageIO.read(bais);
|
||||||
|
if (image == null || image.getWidth() <= 0 || image.getHeight() <= 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return image;
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BufferedImage bufferedImage(InputStream inputStream) {
|
||||||
|
try {
|
||||||
|
BufferedImage image = ImageIO.read(inputStream);
|
||||||
|
if (image == null || image.getWidth() <= 0 || image.getHeight() <= 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return image;
|
||||||
|
} catch (Exception e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] imageToBytes(BufferedImage bImage) {
|
||||||
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
|
try {
|
||||||
|
ImageIO.write(bImage, "png", out);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return out.toByteArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] imageToBytes(String base64) {
|
||||||
|
BufferedImage bImage=bufferedImage(base64);
|
||||||
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
|
try {
|
||||||
|
ImageIO.write(bImage, "png", out);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return out.toByteArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String imageToBase64(BufferedImage bufferedImage){
|
||||||
|
BASE64Encoder encoder = new sun.misc.BASE64Encoder();
|
||||||
|
byte[] bytes=imageToBytes(bufferedImage);
|
||||||
|
return encoder.encodeBuffer(bytes).trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
19
src/main/java/com/shenghua/utils/MinutesUtil.java
Normal file
19
src/main/java/com/shenghua/utils/MinutesUtil.java
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
package com.shenghua.utils;
|
||||||
|
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
public class MinutesUtil {
|
||||||
|
|
||||||
|
public static Integer extractMinutes(String minutesString) {
|
||||||
|
Pattern pattern = Pattern.compile("\\d+"); // 匹配一个或多个数字
|
||||||
|
Matcher matcher = pattern.matcher(minutesString);
|
||||||
|
|
||||||
|
if (matcher.find()) {
|
||||||
|
String extractedString = matcher.group(); // 提取匹配到的数字部分
|
||||||
|
return Integer.parseInt(extractedString);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0; // 默认返回0或抛出异常,根据实际需求进行处理
|
||||||
|
}
|
||||||
|
}
|
16
src/main/java/com/shenghua/utils/RandomUtil.java
Normal file
16
src/main/java/com/shenghua/utils/RandomUtil.java
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
package com.shenghua.utils;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class RandomUtil {
|
||||||
|
|
||||||
|
public static String randomGen(int place) {
|
||||||
|
String base = "wqetryuioplkjhgfdsazxcvbmnABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||||
|
StringBuffer sb = new StringBuffer();
|
||||||
|
Random rd = new Random();
|
||||||
|
for(int i=0;i<place;i++) {
|
||||||
|
sb.append(base.charAt(rd.nextInt(base.length())));
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
}
|
56
src/main/java/com/shenghua/utils/ResultUtil.java
Normal file
56
src/main/java/com/shenghua/utils/ResultUtil.java
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
package com.shenghua.utils;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态码
|
||||||
|
*/
|
||||||
|
public class ResultUtil {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 常用
|
||||||
|
*/
|
||||||
|
public static final int SUCCESS_CODE=200;//成功
|
||||||
|
public static final int FAIL_CODE=300;//失败
|
||||||
|
public static final int EMPTY_PARAM_CODE=400;//空参数
|
||||||
|
public static final int ERROR_CODE=500;//异常
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 权限
|
||||||
|
*/
|
||||||
|
public static final int LOGIN_TOKEN_INVALID_CODE=401;//token无效
|
||||||
|
public static final int NOT_AUTHENTICATION_CODE=403;//没权限
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 图片格式
|
||||||
|
*/
|
||||||
|
public static final int NO_SUPPORT_FILE_FORMAT_CODE=505;//不支持文件形式
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private static Map<Integer,String> messageMap;
|
||||||
|
|
||||||
|
static {
|
||||||
|
messageMap=new HashMap<>();
|
||||||
|
messageMap.put(SUCCESS_CODE,"Success");
|
||||||
|
messageMap.put(FAIL_CODE,"Fail");
|
||||||
|
messageMap.put(EMPTY_PARAM_CODE,"Fount required isEmpty");
|
||||||
|
messageMap.put(ERROR_CODE,"Error");
|
||||||
|
|
||||||
|
messageMap.put(LOGIN_TOKEN_INVALID_CODE,"Token is invalid. Please login again");
|
||||||
|
messageMap.put(NOT_AUTHENTICATION_CODE,"Full authentication is required to access this resource");
|
||||||
|
|
||||||
|
messageMap.put(NO_SUPPORT_FILE_FORMAT_CODE,"File format is not supported");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据状态码获取返回消息
|
||||||
|
* @param code
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String getMessage(int code){
|
||||||
|
return messageMap.get(code);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
95
src/main/java/com/shenghua/utils/SpringBeanUtil.java
Normal file
95
src/main/java/com/shenghua/utils/SpringBeanUtil.java
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
package com.shenghua.utils;
|
||||||
|
|
||||||
|
import org.springframework.beans.BeansException;
|
||||||
|
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.springframework.context.ApplicationContextAware;
|
||||||
|
import org.springframework.core.env.Environment;
|
||||||
|
|
||||||
|
public class SpringBeanUtil implements ApplicationContextAware {
|
||||||
|
|
||||||
|
|
||||||
|
private static ApplicationContext context;
|
||||||
|
|
||||||
|
/***
|
||||||
|
* 当继承了ApplicationContextAware类之后,那么程序在调用
|
||||||
|
* getBean(String)的时候会自动调用该方法,不用自己操作
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void setApplicationContext(ApplicationContext context) throws BeansException {
|
||||||
|
SpringBeanUtil.context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
* 根据一个bean的id获取配置文件中相应的bean
|
||||||
|
* @param name
|
||||||
|
* @return
|
||||||
|
* @throws BeansException
|
||||||
|
*/
|
||||||
|
public static Object getSpringBean(String beanName) {
|
||||||
|
return context==null?null:context.getBean(beanName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
* 类似于getBean(String name)只是在参数中提供了需要返回到的类型。
|
||||||
|
* @param name
|
||||||
|
* @param requiredType
|
||||||
|
* @return
|
||||||
|
* @throws BeansException
|
||||||
|
*/
|
||||||
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||||
|
public static <T> T getBean(String name, Class<T> requiredType) throws BeansException {
|
||||||
|
return context.getBean(name, requiredType);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> T getBean(Class<T> requiredType) throws BeansException {
|
||||||
|
return context.getBean(requiredType);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> T getProperty(String name, Class<T> requiredType){
|
||||||
|
Environment environment=getBean(Environment.class);
|
||||||
|
return environment.getProperty(name,requiredType);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 如果BeanFactory包含一个与所给名称匹配的bean定义,则返回true
|
||||||
|
* @param name
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public static boolean containsBean(String name) {
|
||||||
|
return context.containsBean(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断以给定名字注册的bean定义是一个singleton还是一个prototype。
|
||||||
|
* 如果与给定名字相应的bean定义没有被找到,将会抛出一个异常(NoSuchBeanDefinitionException)
|
||||||
|
* @param name
|
||||||
|
* @return boolean
|
||||||
|
* @throws NoSuchBeanDefinitionException
|
||||||
|
*/
|
||||||
|
public static boolean isSingleton(String name) throws NoSuchBeanDefinitionException {
|
||||||
|
return context.isSingleton(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param name
|
||||||
|
* @return Class 注册对象的类型
|
||||||
|
* @throws NoSuchBeanDefinitionException
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
|
public static Class getType(String name) throws NoSuchBeanDefinitionException {
|
||||||
|
return context.getType(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 如果给定的bean名字在bean定义中有别名,则返回这些别名
|
||||||
|
* @param name
|
||||||
|
* @return
|
||||||
|
* @throws NoSuchBeanDefinitionException
|
||||||
|
*/
|
||||||
|
public static String[] getAliases(String name) throws NoSuchBeanDefinitionException {
|
||||||
|
return context.getAliases(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
49
src/main/java/com/shenghua/utils/StreamUtils.java
Normal file
49
src/main/java/com/shenghua/utils/StreamUtils.java
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
package com.shenghua.utils;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
public class StreamUtils {
|
||||||
|
private static int _buffer_size = 1024;
|
||||||
|
/**
|
||||||
|
* InputStream流转换成String字符串
|
||||||
|
* @param inStream InputStream流
|
||||||
|
* @param encoding 编码格式
|
||||||
|
* @return String字符串
|
||||||
|
*/
|
||||||
|
public static String inputStream2String(InputStream inStream, String encoding){
|
||||||
|
String result = null;
|
||||||
|
ByteArrayOutputStream outStream = null;
|
||||||
|
try {
|
||||||
|
if(inStream != null){
|
||||||
|
outStream = new ByteArrayOutputStream();
|
||||||
|
byte[] tempBytes = new byte[_buffer_size];
|
||||||
|
int count = -1;
|
||||||
|
while((count = inStream.read(tempBytes, 0, _buffer_size)) != -1){
|
||||||
|
outStream.write(tempBytes, 0, count);
|
||||||
|
}
|
||||||
|
tempBytes = null;
|
||||||
|
outStream.flush();
|
||||||
|
result = new String(outStream.toByteArray(), encoding);
|
||||||
|
outStream.close();
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
result = null;
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if(inStream != null) {
|
||||||
|
inStream.close();
|
||||||
|
inStream = null;
|
||||||
|
}
|
||||||
|
if(outStream != null) {
|
||||||
|
outStream.close();
|
||||||
|
outStream = null;
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
28
src/main/java/com/shenghua/utils/WechatUtil.java
Normal file
28
src/main/java/com/shenghua/utils/WechatUtil.java
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
package com.shenghua.utils;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class WechatUtil {
|
||||||
|
public static JSONObject getSessionKeyOrOpenId(String code) {
|
||||||
|
String requestUrl = "https://api.weixin.qq.com/sns/jscode2session";
|
||||||
|
Map<String, String> requestUrlParam = new HashMap<>();
|
||||||
|
//小程序appId
|
||||||
|
requestUrlParam.put("appid", "wx3bd156b4fad6e97f");
|
||||||
|
//小程序secret
|
||||||
|
requestUrlParam.put("secret", "f60953e5035ceeb443b6e7c0f487d0b5");
|
||||||
|
//小程序端返回的code
|
||||||
|
requestUrlParam.put("js_code", code);
|
||||||
|
//默认参数
|
||||||
|
requestUrlParam.put("grant_type", "authorization_code");
|
||||||
|
//发送post请求读取调用微信接口获取openid用户唯一标识
|
||||||
|
|
||||||
|
String msgBody = JSONObject.toJSONString(requestUrlParam);
|
||||||
|
JSONObject jsonObject = JSON.parseObject(HttpUtils.sendPost(requestUrl, msgBody));
|
||||||
|
|
||||||
|
return jsonObject;
|
||||||
|
}
|
||||||
|
}
|
120
src/main/java/com/shenghua/utils/WxUtil.java
Normal file
120
src/main/java/com/shenghua/utils/WxUtil.java
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
package com.shenghua.utils;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.wechat.pay.contrib.apache.httpclient.WechatPayHttpClientBuilder;
|
||||||
|
import com.wechat.pay.contrib.apache.httpclient.auth.AutoUpdateCertificatesVerifier;
|
||||||
|
import com.wechat.pay.contrib.apache.httpclient.auth.PrivateKeySigner;
|
||||||
|
import com.wechat.pay.contrib.apache.httpclient.auth.WechatPay2Credentials;
|
||||||
|
import com.wechat.pay.contrib.apache.httpclient.auth.WechatPay2Validator;
|
||||||
|
import com.wechat.pay.contrib.apache.httpclient.util.AesUtil;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.apache.http.client.HttpClient;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.security.KeyFactory;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.security.PrivateKey;
|
||||||
|
import java.security.spec.InvalidKeySpecException;
|
||||||
|
import java.security.spec.PKCS8EncodedKeySpec;
|
||||||
|
import java.util.Base64;
|
||||||
|
|
||||||
|
public class WxUtil {
|
||||||
|
|
||||||
|
private static Logger logger= LoggerFactory.getLogger(WxUtil.class);
|
||||||
|
|
||||||
|
public static PrivateKey merchantPrivateKey;
|
||||||
|
public static AutoUpdateCertificatesVerifier verifier;
|
||||||
|
public static HttpClient httpClient;
|
||||||
|
|
||||||
|
static {
|
||||||
|
try{
|
||||||
|
merchantPrivateKey=getPrivateKey("/www/wwwroot/xinanzulin.com/zulin/addons/cert/apiclient_key.pem");
|
||||||
|
//merchantPrivateKey=getPrivateKey("D:\\工作\\谷歌下载\\WXCertUtil\\cert\\lr\\apiclient_key.pem");
|
||||||
|
// 加载平台证书(mchId:商户号,mchSerialNo:商户证书序列号,apiV3Key:V3密钥)
|
||||||
|
verifier = new AutoUpdateCertificatesVerifier(
|
||||||
|
new WechatPay2Credentials(ConstantUtil.WX_MCH_ID, new PrivateKeySigner(ConstantUtil.WX_SERIAL_NUMBER, merchantPrivateKey)),ConstantUtil.WX_V3_SERIAL_NUMBER.getBytes("utf-8"));
|
||||||
|
|
||||||
|
// 初始化httpClient
|
||||||
|
httpClient = WechatPayHttpClientBuilder.create()
|
||||||
|
.withMerchant(ConstantUtil.WX_MCH_ID, ConstantUtil.WX_SERIAL_NUMBER, merchantPrivateKey)
|
||||||
|
.withValidator(new WechatPay2Validator(verifier)).build();
|
||||||
|
logger.info("初始化httpClient成功");
|
||||||
|
}catch (Exception e){
|
||||||
|
logger.error("初始化httpClient异常",e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取私钥。
|
||||||
|
*
|
||||||
|
* @param filename 私钥文件路径 (required)
|
||||||
|
* @return 私钥对象
|
||||||
|
*/
|
||||||
|
private static PrivateKey getPrivateKey(String filename) throws IOException {
|
||||||
|
|
||||||
|
String content = new String(Files.readAllBytes(Paths.get(filename)), "utf-8");
|
||||||
|
try {
|
||||||
|
String privateKey = content.replace("-----BEGIN PRIVATE KEY-----", "")
|
||||||
|
.replace("-----END PRIVATE KEY-----", "")
|
||||||
|
.replaceAll("\\s+", "");
|
||||||
|
|
||||||
|
KeyFactory kf = KeyFactory.getInstance("RSA");
|
||||||
|
return kf.generatePrivate(
|
||||||
|
new PKCS8EncodedKeySpec(Base64.getDecoder().decode(privateKey)));
|
||||||
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
throw new RuntimeException("当前Java环境不支持RSA", e);
|
||||||
|
} catch (InvalidKeySpecException e) {
|
||||||
|
throw new RuntimeException("无效的密钥格式");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取微信小程序token
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String getToken(){
|
||||||
|
String result= HttpUtils.sendGet(ConstantUtil.WX_TOKEN_URL);
|
||||||
|
logger.info("result :"+result);
|
||||||
|
if(StringUtils.isBlank(result)){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
JSONObject jsonObject = JSONObject.parseObject(result);
|
||||||
|
return jsonObject.getString("access_token");
|
||||||
|
}
|
||||||
|
|
||||||
|
/*支付通知和退款通知给服务器的回调 解密报文*/
|
||||||
|
public static String decryptOrder(String body) {
|
||||||
|
try {
|
||||||
|
AesUtil util = new AesUtil(ConstantUtil.WX_V3_SERIAL_NUMBER.getBytes(StandardCharsets.UTF_8));
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
JsonNode node = objectMapper.readTree(body);
|
||||||
|
JsonNode resource = node.get("resource");
|
||||||
|
String ciphertext = resource.get("ciphertext").textValue();
|
||||||
|
String associatedData = resource.get("associated_data").textValue();
|
||||||
|
String nonce = resource.get("nonce").textValue();
|
||||||
|
return util.decryptToString(associatedData.getBytes("utf-8"), nonce.getBytes("utf-8"), ciphertext);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*支付通知和退款通知给服务器的回调 请求头验签*/
|
||||||
|
public static boolean signVerify(String serialNumber, String message, String signature) {
|
||||||
|
try {
|
||||||
|
return verifier.verify(serialNumber, message.getBytes(StandardCharsets.UTF_8), signature);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
24
src/main/java/com/shenghua/vo/BannerVo.java
Normal file
24
src/main/java/com/shenghua/vo/BannerVo.java
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
package com.shenghua.vo;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class BannerVo {
|
||||||
|
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "图片路径")
|
||||||
|
private String image;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "是否显示 1:显示 0:不显示")
|
||||||
|
private Integer isDisplay;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "分类ID")
|
||||||
|
private Integer categoryId;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "创建时间")
|
||||||
|
private Date createTime;
|
||||||
|
}
|
85
src/main/java/com/shenghua/vo/CaseArticleVO.java
Normal file
85
src/main/java/com/shenghua/vo/CaseArticleVO.java
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
package com.shenghua.vo;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
@Data
|
||||||
|
@ApiModel("案例文章表")
|
||||||
|
public class CaseArticleVO {
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "主键ID")
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "分类ID", example = "15")
|
||||||
|
private Integer categoryId;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "分类名称", example = "15")
|
||||||
|
private String category;
|
||||||
|
|
||||||
|
@TableField("category_id")
|
||||||
|
@ApiModelProperty(value = "分类tag", example = "15")
|
||||||
|
private String categoryTag;
|
||||||
|
|
||||||
|
@TableField("title")
|
||||||
|
@ApiModelProperty(value = "标题(150字内)", required = true, example = "产品案例分享")
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
@TableField("cover")
|
||||||
|
@ApiModelProperty(value = "封面地址", example = "https://example.com/cover.jpg")
|
||||||
|
private String cover;
|
||||||
|
|
||||||
|
@TableField("summary")
|
||||||
|
@ApiModelProperty(value = "简介(255字内)", required = true, example = "典型案例展示")
|
||||||
|
private String summary;
|
||||||
|
|
||||||
|
@TableField("content")
|
||||||
|
@ApiModelProperty(value = "详细内容")
|
||||||
|
private String content;
|
||||||
|
|
||||||
|
@TableField("sort")
|
||||||
|
@ApiModelProperty(value = "排序值,越大越靠前", example = "999")
|
||||||
|
private Integer sort = 0;
|
||||||
|
|
||||||
|
@TableField("status")
|
||||||
|
@ApiModelProperty(value = "状态 0:下架 1:发布", example = "1")
|
||||||
|
private Integer status = 0;
|
||||||
|
|
||||||
|
@TableField("is_recommend")
|
||||||
|
@ApiModelProperty(value = "是否推荐 0:否 1:是", example = "1")
|
||||||
|
private Integer isRecommend = 0;
|
||||||
|
|
||||||
|
@TableField("create_time")
|
||||||
|
@ApiModelProperty(value = "创建时间", example = "2025-06-13 17:35:00")
|
||||||
|
private Date createTime;
|
||||||
|
|
||||||
|
@TableField("update_time")
|
||||||
|
@ApiModelProperty(value = "修改时间", example = "2025-06-13 17:40:00")
|
||||||
|
private Date updateTime;
|
||||||
|
|
||||||
|
@TableField("seoTitle")
|
||||||
|
@ApiModelProperty(value = "SEO标题(255字内)")
|
||||||
|
private String seoTitle;
|
||||||
|
|
||||||
|
@TableField("seoDescription")
|
||||||
|
@ApiModelProperty(value = "SEO描述(长文本)")
|
||||||
|
private String seoDescription;
|
||||||
|
|
||||||
|
@TableField("seoKeywords")
|
||||||
|
@ApiModelProperty(value = "SEO关键词(255字内)")
|
||||||
|
private String seoKeywords;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "上篇ID")
|
||||||
|
private Integer upChapterId;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "上篇标题")
|
||||||
|
private String upChapterName;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "下篇ID")
|
||||||
|
private Integer downChapterId;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "下篇ID")
|
||||||
|
private String downChapterName;
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user