1
This commit is contained in:
commit
346726133d
38
.gitignore
vendored
Normal file
38
.gitignore
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea/modules.xml
|
||||
.idea/jarRepositories.xml
|
||||
.idea/compiler.xml
|
||||
.idea/libraries/
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
build/
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
8
.idea/.gitignore
vendored
Normal file
8
.idea/.gitignore
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
17
.idea/dataSources.xml
Normal file
17
.idea/dataSources.xml
Normal file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
|
||||
<data-source source="LOCAL" name="demo@106.52.88.120" uuid="494d4563-66cc-49c2-863b-5ab76f35808f">
|
||||
<driver-ref>mysql.8</driver-ref>
|
||||
<synchronize>true</synchronize>
|
||||
<jdbc-driver>com.mysql.cj.jdbc.Driver</jdbc-driver>
|
||||
<jdbc-url>jdbc:mysql://106.52.88.120:3306/demo?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai</jdbc-url>
|
||||
<jdbc-additional-properties>
|
||||
<property name="com.intellij.clouds.kubernetes.db.host.port" />
|
||||
<property name="com.intellij.clouds.kubernetes.db.enabled" value="false" />
|
||||
<property name="com.intellij.clouds.kubernetes.db.container.port" />
|
||||
</jdbc-additional-properties>
|
||||
<working-dir>$ProjectFileDir$</working-dir>
|
||||
</data-source>
|
||||
</component>
|
||||
</project>
|
13
.idea/encodings.xml
Normal file
13
.idea/encodings.xml
Normal file
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding">
|
||||
<file url="file://$PROJECT_DIR$/common/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/common/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/pojo/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/pojo/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/server/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/server/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||
</component>
|
||||
</project>
|
14
.idea/misc.xml
Normal file
14
.idea/misc.xml
Normal file
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="MavenProjectsManager">
|
||||
<option name="originalFiles">
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/pom.xml" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_23" default="true" project-jdk-name="17" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
124
.idea/uiDesigner.xml
Normal file
124
.idea/uiDesigner.xml
Normal file
@ -0,0 +1,124 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Palette2">
|
||||
<group name="Swing">
|
||||
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
|
||||
</item>
|
||||
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
|
||||
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
|
||||
<initial-values>
|
||||
<property name="text" value="Button" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="RadioButton" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="CheckBox" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="Label" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
|
||||
<preferred-size width="-1" height="20" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
|
||||
</item>
|
||||
</group>
|
||||
</component>
|
||||
</project>
|
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
88
common/pom.xml
Normal file
88
common/pom.xml
Normal file
@ -0,0 +1,88 @@
|
||||
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>net.carbon</groupId>
|
||||
<artifactId>CarbonNeutrality</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>common</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!--项目中添加 spring-boot-starter-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-spring-boot3-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!--用于加密-->
|
||||
<dependency>
|
||||
<groupId>commons-codec</groupId>
|
||||
<artifactId>commons-codec</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- JWT相关 -->
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.testng</groupId>
|
||||
<artifactId>testng</artifactId>
|
||||
<version>RELEASE</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-jsqlparser</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>javax.xml.bind</groupId>
|
||||
<artifactId>jaxb-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jaxb</groupId>
|
||||
<artifactId>jaxb-runtime</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
</project>
|
24
common/src/main/java/net/carbon/bean/PageRequest.java
Normal file
24
common/src/main/java/net/carbon/bean/PageRequest.java
Normal file
@ -0,0 +1,24 @@
|
||||
package net.carbon.bean;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.Setter;
|
||||
|
||||
@Setter
|
||||
public class PageRequest {
|
||||
private Long pageNo = 1L;
|
||||
private Long pageSize = 10L;
|
||||
|
||||
public Long getPageNo() {
|
||||
if (pageNo == null || pageNo < 1) {
|
||||
return 1L;
|
||||
}
|
||||
return pageNo;
|
||||
}
|
||||
|
||||
public Long getPageSize() {
|
||||
if (pageSize == null || pageSize < 1 || pageSize > Long.MAX_VALUE) {
|
||||
return 10L;
|
||||
}
|
||||
return pageSize;
|
||||
}
|
||||
}
|
58
common/src/main/java/net/carbon/bean/PageResponse.java
Normal file
58
common/src/main/java/net/carbon/bean/PageResponse.java
Normal file
@ -0,0 +1,58 @@
|
||||
package net.carbon.bean;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
@JsonFormat
|
||||
public class PageResponse<T> {
|
||||
private Long pageNo = 1L;
|
||||
private Long pageSize = 10L;
|
||||
private Long total = 0L;
|
||||
private Long totalPages = 0L;
|
||||
private List<T> records = Collections.emptyList();
|
||||
private Long start = 0L;
|
||||
private Long end = 0L;
|
||||
|
||||
public PageResponse() {
|
||||
}
|
||||
|
||||
public void setRecords(List<T> records) {
|
||||
this.records = records;
|
||||
if (records != null && records.size() > 0 && this.total == 0) {
|
||||
setTotal(Long.valueOf(records.size()));
|
||||
}
|
||||
}
|
||||
|
||||
public void setCurrent(Long pageNo) {
|
||||
if (pageNo != null && pageNo > 0) {
|
||||
this.pageNo = pageNo;
|
||||
}
|
||||
}
|
||||
|
||||
public void setPageSize(Long pageSize) {
|
||||
if (pageSize != null && pageSize > 0) {
|
||||
this.pageSize = pageSize;
|
||||
}
|
||||
}
|
||||
|
||||
public void setTotal(Long total) {
|
||||
this.total = total;
|
||||
if (total == -1) {
|
||||
this.pageNo = 1L;
|
||||
return;
|
||||
}
|
||||
if (total > 0) {
|
||||
this.totalPages = (total / pageSize) + (total % pageSize == 0 ? 0 : 1);
|
||||
} else {
|
||||
this.totalPages = 0L;
|
||||
}
|
||||
this.start = (this.pageNo > 0) ? (this.pageNo - 1) * this.pageSize : 0;
|
||||
this.end = (this.start - 1 + this.pageSize * (this.pageNo > 0 ? 1 : 0));
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package net.carbon.config;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.DbType;
|
||||
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class MybatisPlusPageConfig {
|
||||
|
||||
/* 旧版本配置
|
||||
@Bean
|
||||
public PaginationInterceptor paginationInterceptor(){
|
||||
return new PaginationInterceptor();
|
||||
}*/
|
||||
|
||||
/**
|
||||
* 新的分页插件,一缓和二缓遵循mybatis的规则,
|
||||
* 需要设置 MybatisConfiguration#useDeprecatedExecutor = false 避免缓存出现问题
|
||||
*/
|
||||
@Bean
|
||||
public MybatisPlusInterceptor mybatisPlusInterceptor() {
|
||||
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
|
||||
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
|
||||
return interceptor;
|
||||
}
|
||||
|
||||
|
||||
}
|
35
common/src/main/java/net/carbon/config/SwaggerConfig.java
Normal file
35
common/src/main/java/net/carbon/config/SwaggerConfig.java
Normal file
@ -0,0 +1,35 @@
|
||||
package net.carbon.config;
|
||||
|
||||
import io.swagger.v3.oas.models.Components;
|
||||
import io.swagger.v3.oas.models.ExternalDocumentation;
|
||||
import io.swagger.v3.oas.models.OpenAPI;
|
||||
import io.swagger.v3.oas.models.info.Info;
|
||||
import io.swagger.v3.oas.models.info.License;
|
||||
import io.swagger.v3.oas.models.media.StringSchema;
|
||||
import io.swagger.v3.oas.models.parameters.HeaderParameter;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@Configuration
|
||||
public class SwaggerConfig implements WebMvcConfigurer {
|
||||
|
||||
@Value("${spring.application.name}")
|
||||
private String applicationName;
|
||||
|
||||
@Bean
|
||||
public OpenAPI springShopOpenAPI() {
|
||||
return new OpenAPI()
|
||||
.components(new Components()
|
||||
.addParameters("token", new HeaderParameter().description("请填写Token").schema(new StringSchema()))
|
||||
.addParameters("adminID", new HeaderParameter().description("请填写用户ID").schema(new StringSchema())))
|
||||
.info(new Info().title(applicationName)
|
||||
.description("Knife4j增强文档")
|
||||
.version("v2.0")
|
||||
.license(new License().name("Apache 2.0").url("http://springdoc.org")))
|
||||
.externalDocs(new ExternalDocumentation()
|
||||
.description("二饭快速开发框架")
|
||||
.url("https://gitee.com/StandFast"));
|
||||
}
|
||||
}
|
118
common/src/main/java/net/carbon/config/SwaggerConfiguration.java
Normal file
118
common/src/main/java/net/carbon/config/SwaggerConfiguration.java
Normal file
@ -0,0 +1,118 @@
|
||||
package net.carbon.config;
|
||||
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.stereotype.Component;
|
||||
import springfox.documentation.builders.*;
|
||||
import springfox.documentation.oas.annotations.EnableOpenApi;
|
||||
import springfox.documentation.schema.ScalarType;
|
||||
import springfox.documentation.service.*;
|
||||
import springfox.documentation.spi.DocumentationType;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
@EnableOpenApi
|
||||
@Data
|
||||
public class SwaggerConfiguration {
|
||||
|
||||
|
||||
/**
|
||||
* C端文档
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public Docket webApiDoc() {
|
||||
|
||||
|
||||
return new Docket(DocumentationType.OAS_30)
|
||||
.groupName("用户端接口文档")
|
||||
.pathMapping("/")
|
||||
// 定义是否开启swagger,false为关闭,可以通过变量控制,线上关闭
|
||||
.enable(true)
|
||||
//配置api文档元信息
|
||||
.apiInfo(apiInfo())
|
||||
// 选择哪些接口作为swagger的doc发布
|
||||
.select()
|
||||
.apis(RequestHandlerSelectors.basePackage("net.carbon"))
|
||||
//正则匹配请求路径,并分配至当前分组
|
||||
.paths(PathSelectors.ant("/api/**"))
|
||||
.build()
|
||||
//新版swagger3.0配置
|
||||
.globalRequestParameters(getGlobalRequestParameters())
|
||||
.globalResponses(HttpMethod.GET, getGlobalResponseMessage())
|
||||
.globalResponses(HttpMethod.POST, getGlobalResponseMessage());
|
||||
}
|
||||
|
||||
|
||||
private ApiInfo apiInfo() {
|
||||
return new ApiInfoBuilder()
|
||||
.title("碳中和")
|
||||
.description("接口文档")
|
||||
.contact(new Contact("jieyuu", "https://106.52.88.120", "645634619@qq.com"))
|
||||
.version("12")
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理端文档
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public Docket adminApiDoc() {
|
||||
return new Docket(DocumentationType.OAS_30)
|
||||
.groupName("管理端接口文档")
|
||||
.pathMapping("/")
|
||||
// 定义是否开启swagger,false为关闭,可以通过变量控制,线上关闭
|
||||
.enable(true)
|
||||
//配置api文档元信息
|
||||
.apiInfo(apiInfo())
|
||||
// 选择哪些接口作为swagger的doc发布
|
||||
.select()
|
||||
.apis(RequestHandlerSelectors.basePackage("net.jieyuu"))
|
||||
//正则匹配请求路径,并分配至当前分组
|
||||
.paths(PathSelectors.ant("/admin/**"))
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成全局通用参数, 支持配置多个响应参数
|
||||
* @return
|
||||
*/
|
||||
private List<RequestParameter> getGlobalRequestParameters() {
|
||||
List<RequestParameter> parameters = new ArrayList<>();
|
||||
parameters.add(new RequestParameterBuilder()
|
||||
.name("token")
|
||||
.description("登录令牌")
|
||||
.in(ParameterType.HEADER)
|
||||
.query(q -> q.model(m -> m.scalarModel(ScalarType.STRING)))
|
||||
.required(false)
|
||||
.build());
|
||||
|
||||
// parameters.add(new RequestParameterBuilder()
|
||||
// .name("version")
|
||||
// .description("版本号")
|
||||
// .required(true)
|
||||
// .in(ParameterType.HEADER)
|
||||
// .query(q -> q.model(m -> m.scalarModel(ScalarType.STRING)))
|
||||
// .required(false)
|
||||
// .build());
|
||||
return parameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成通用响应信息
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private List<Response> getGlobalResponseMessage() {
|
||||
List<Response> responseList = new ArrayList<>();
|
||||
responseList.add(new ResponseBuilder().code("4xx").description("请求错误,根据code和msg检查").build());
|
||||
return responseList;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package net.carbon.config;
|
||||
|
||||
import io.swagger.v3.oas.annotations.ExternalDocumentation;
|
||||
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
|
||||
import io.swagger.v3.oas.annotations.info.Contact;
|
||||
import io.swagger.v3.oas.annotations.info.Info;
|
||||
import io.swagger.v3.oas.annotations.info.License;
|
||||
import io.swagger.v3.oas.annotations.servers.Server;
|
||||
import org.springframework.boot.SpringBootConfiguration;
|
||||
|
||||
/**
|
||||
* @author jieyuu
|
||||
**/
|
||||
//@SpringBootConfiguration
|
||||
//@OpenAPIDefinition(
|
||||
// // ## API的基本信息,包括标题、版本号、描述、联系人等
|
||||
// info = @Info(
|
||||
// title = "双碳项目接口文档", // Api接口文档标题(必填)
|
||||
// description = "用于双碳项目接口开发文档", // Api接口文档描述
|
||||
// version = "1.0", // Api接口版本
|
||||
// termsOfService = "https://example.com/", // Api接口的服务条款地址
|
||||
// contact = @Contact(
|
||||
// name = "蚂蚁小哥", // 作者名称
|
||||
// email = "xiaofeng@qq.com", // 作者邮箱
|
||||
// url = "https://www.cnblogs.com/antLaddie/" // 介绍作者的URL地址
|
||||
// ),
|
||||
// license = @License( // 设置联系人信息
|
||||
// name = "Apache 2.0", // 授权名称
|
||||
// url = "https://www.apache.org/licenses/LICENSE-2.0.html" // 授权信息
|
||||
// )
|
||||
// ),
|
||||
// // ## 表示服务器地址或者URL模板列表,多个服务地址随时切换(只不过是有多台IP有当前的服务API)
|
||||
// servers = {
|
||||
// @Server(url = "http://192.168.2.235/demo/", description = "本地服务器一服务"),
|
||||
// @Server(url = "http://192.168.2.236/demo/", description = "本地服务器二服务"),
|
||||
// },
|
||||
// externalDocs = @ExternalDocumentation(description = "更多内容请查看该链接", url = "xxx"))
|
||||
//public class SwaggerOpenApiConfig {
|
||||
//}
|
62
common/src/main/java/net/carbon/enums/BizCodeEnum.java
Normal file
62
common/src/main/java/net/carbon/enums/BizCodeEnum.java
Normal file
@ -0,0 +1,62 @@
|
||||
package net.carbon.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @Description 状态码定义约束,共6位数,前三位代表服务,后4位代表接口
|
||||
* 比如 商品服务210,购物车是220、用户服务230,403代表权限
|
||||
**/
|
||||
public enum BizCodeEnum {
|
||||
|
||||
|
||||
/**
|
||||
* 通用操作码
|
||||
*/
|
||||
OPS_REPEAT(110001, "重复操作"),
|
||||
|
||||
/**
|
||||
* 验证码
|
||||
*/
|
||||
CODE_TO_ERROR(240001, "接收号码不合规"),
|
||||
|
||||
CODE_LIMITED(240002, "验证码发送过快"),
|
||||
|
||||
CODE_ERROR(240003, "验证码错误"),
|
||||
|
||||
CODE_CAPTCHA(240101, "图形验证码错误"),
|
||||
|
||||
/**
|
||||
* 账号
|
||||
*/
|
||||
ACCOUNT_REPEAT(250001, "账号已经存在"),
|
||||
|
||||
ACCOUNT_UNREGISTER(250002, "账号不存在"),
|
||||
|
||||
ACCOUNT_PWD_ERROR(250003, "账号或者密码错误"),
|
||||
|
||||
ACCOUNT_UNLOGIN(250004, "账号未登录"),
|
||||
|
||||
ILLEGAL_ARGUMENT(250005, "参数非法"),
|
||||
|
||||
|
||||
/**
|
||||
* 流控操作
|
||||
*/
|
||||
|
||||
CONTROL_FLOW(500101, "限流控制"),
|
||||
|
||||
CONTROL_DEGRADE(500201, "降级控制"),
|
||||
|
||||
CONTROL_AUTH(500301, "认证控制");
|
||||
|
||||
@Getter
|
||||
private int code;
|
||||
|
||||
@Getter
|
||||
private String message;
|
||||
|
||||
private BizCodeEnum(int code, String message) {
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
}
|
||||
}
|
25
common/src/main/java/net/carbon/exception/BizException.java
Normal file
25
common/src/main/java/net/carbon/exception/BizException.java
Normal file
@ -0,0 +1,25 @@
|
||||
package net.carbon.exception;
|
||||
|
||||
|
||||
import lombok.Data;
|
||||
import net.carbon.enums.BizCodeEnum;
|
||||
|
||||
@Data
|
||||
public class BizException extends RuntimeException {
|
||||
|
||||
private Integer code;
|
||||
private String msg;
|
||||
|
||||
public BizException(Integer code, String message) {
|
||||
super(message);
|
||||
this.code = code;
|
||||
this.msg = message;
|
||||
}
|
||||
|
||||
public BizException(BizCodeEnum bizCodeEnum) {
|
||||
super(bizCodeEnum.getMessage());
|
||||
this.code = bizCodeEnum.getCode();
|
||||
this.msg = bizCodeEnum.getMessage();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package net.carbon.handler;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.carbon.exception.BizException;
|
||||
|
||||
import net.carbon.utils.JsonData;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
@ControllerAdvice
|
||||
@Slf4j
|
||||
public class CustomExceptionHandle {
|
||||
|
||||
@ExceptionHandler(value = Exception.class)
|
||||
@ResponseBody
|
||||
public JsonData Handle(Exception e) {
|
||||
|
||||
if (e instanceof BizException) {
|
||||
BizException bizException = (BizException) e;
|
||||
log.info("[业务异常]{}", e);
|
||||
return JsonData.buildCodeAndMsg(bizException.getCode(), bizException.getMsg());
|
||||
|
||||
} else {
|
||||
log.info("[系统异常]{}", e);
|
||||
return JsonData.buildError("全局异常,未知错误");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
package net.carbon.interceptor;
|
||||
|
||||
import io.jsonwebtoken.Claims;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import net.carbon.enums.BizCodeEnum;
|
||||
import net.carbon.model.LoginUser;
|
||||
import net.carbon.utils.CommonUtil;
|
||||
import net.carbon.utils.JWTUtil;
|
||||
import net.carbon.utils.JsonData;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
|
||||
@Slf4j
|
||||
public class LoginInterceptor implements HandlerInterceptor {
|
||||
|
||||
public static ThreadLocal<LoginUser> threadLocal = new ThreadLocal<>();
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||
String accessToken = request.getHeader("token");
|
||||
|
||||
if (accessToken == null) {
|
||||
accessToken = request.getParameter("token");
|
||||
}
|
||||
|
||||
//不为空
|
||||
if (StringUtils.isNotBlank(accessToken)) {
|
||||
Claims claims = JWTUtil.checkJWT(accessToken);
|
||||
if (claims == null) {
|
||||
//未登录
|
||||
CommonUtil.sendJsonMessage(response, JsonData.buildResult(BizCodeEnum.ACCOUNT_UNLOGIN));
|
||||
return false;
|
||||
}
|
||||
long userId = Long.valueOf(claims.get("id").toString());
|
||||
String name = (String) claims.get("username");
|
||||
|
||||
LoginUser loginUser = LoginUser.builder()
|
||||
.id(userId)
|
||||
.username(name)
|
||||
.build();
|
||||
|
||||
//通过threadlocal传递用户信息
|
||||
threadLocal.set(loginUser);
|
||||
return true;
|
||||
}
|
||||
//未登录
|
||||
CommonUtil.sendJsonMessage(response, JsonData.buildResult(BizCodeEnum.ACCOUNT_UNLOGIN));
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
|
||||
}
|
||||
}
|
21
common/src/main/java/net/carbon/model/LoginUser.java
Normal file
21
common/src/main/java/net/carbon/model/LoginUser.java
Normal file
@ -0,0 +1,21 @@
|
||||
package net.carbon.model;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class LoginUser {
|
||||
private Long id;
|
||||
|
||||
private String username;
|
||||
}
|
39
common/src/main/java/net/carbon/result/Result.java
Normal file
39
common/src/main/java/net/carbon/result/Result.java
Normal file
@ -0,0 +1,39 @@
|
||||
package net.carbon.result;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 后端统一返回结果
|
||||
*
|
||||
* @param <T>
|
||||
*/
|
||||
@Data
|
||||
public class Result<T> implements Serializable {
|
||||
|
||||
private Integer code; // 编码:1成功,0和其它数字为失败
|
||||
private String msg; // 错误信息
|
||||
private T data; // 数据
|
||||
|
||||
public static <T> Result<T> success() {
|
||||
Result<T> result = new Result<T>();
|
||||
result.code = 1;
|
||||
return result;
|
||||
}
|
||||
|
||||
public static <T> Result<T> success(T object) {
|
||||
Result<T> result = new Result<T>();
|
||||
result.data = object;
|
||||
result.code = 1;
|
||||
return result;
|
||||
}
|
||||
|
||||
public static <T> Result<T> error(String msg) {
|
||||
Result<T> result = new Result<>();
|
||||
result.msg = msg;
|
||||
result.code = 0;
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
83
common/src/main/java/net/carbon/utils/CheckUtil.java
Normal file
83
common/src/main/java/net/carbon/utils/CheckUtil.java
Normal file
@ -0,0 +1,83 @@
|
||||
package net.carbon.utils;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class CheckUtil {
|
||||
|
||||
/**
|
||||
* 邮箱正则
|
||||
*/
|
||||
private static final Pattern MAIL_PATTERN = Pattern.compile("^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$");
|
||||
|
||||
/**
|
||||
* 手机号正则,暂时未用
|
||||
*/
|
||||
private static final Pattern PHONE_PATTERN = Pattern.compile("^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$");
|
||||
|
||||
/**
|
||||
* 密码正则
|
||||
* 只能包含字母(大小写)和数字。
|
||||
* 长度必须在6到16个字符之间。
|
||||
*/
|
||||
private static final Pattern PASSWORD_PATTERN = Pattern.compile("^[a-zA-Z0-9]{6,16}$");
|
||||
|
||||
/**
|
||||
* 用户名正则
|
||||
* 用户名只能包含字母(大小写)和数字。
|
||||
* 用户名长度必须在6到16个字符之间。
|
||||
*/
|
||||
private static final Pattern USERNAME_PATTERN = Pattern.compile("^[a-zA-Z0-9]{6,16}$");
|
||||
/**
|
||||
* @param email
|
||||
* @return
|
||||
*/
|
||||
public static boolean isEmail(String email) {
|
||||
if (null == email || "".equals(email)) {
|
||||
return false;
|
||||
}
|
||||
Matcher m = MAIL_PATTERN.matcher(email);
|
||||
return m.matches();
|
||||
}
|
||||
|
||||
/**
|
||||
* 手机号验证
|
||||
* @param phone
|
||||
* @return
|
||||
*/
|
||||
public static boolean isPhone(String phone) {
|
||||
if (null == phone || "".equals(phone)) {
|
||||
return false;
|
||||
}
|
||||
Matcher m = PHONE_PATTERN.matcher(phone);
|
||||
return m.matches();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 密码验证
|
||||
* @param password
|
||||
* @return
|
||||
*/
|
||||
public static boolean isPassword(String password) {
|
||||
if (null == password || "".equals(password)) {
|
||||
return false;
|
||||
}
|
||||
Matcher m = PASSWORD_PATTERN.matcher(password);
|
||||
return m.matches();
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户名验证
|
||||
* @param username
|
||||
* @return
|
||||
*/
|
||||
public static boolean isUsername(String username) {
|
||||
if (null == username || "".equals(username)) {
|
||||
return false;
|
||||
}
|
||||
Matcher m = USERNAME_PATTERN.matcher(username);
|
||||
return m.matches();
|
||||
}
|
||||
|
||||
}
|
165
common/src/main/java/net/carbon/utils/CommonUtil.java
Normal file
165
common/src/main/java/net/carbon/utils/CommonUtil.java
Normal file
@ -0,0 +1,165 @@
|
||||
package net.carbon.utils;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
|
||||
@Slf4j
|
||||
public class CommonUtil {
|
||||
|
||||
/**
|
||||
* 获取ip
|
||||
*
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
public static String getIpAddr(HttpServletRequest request) {
|
||||
String ipAddress = null;
|
||||
try {
|
||||
ipAddress = request.getHeader("x-forwarded-for");
|
||||
if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
|
||||
ipAddress = request.getHeader("Proxy-Client-IP");
|
||||
}
|
||||
if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
|
||||
ipAddress = request.getHeader("WL-Proxy-Client-IP");
|
||||
}
|
||||
if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
|
||||
ipAddress = request.getRemoteAddr();
|
||||
if (ipAddress.equals("127.0.0.1")) {
|
||||
// 根据网卡取本机配置的IP
|
||||
InetAddress inet = null;
|
||||
try {
|
||||
inet = InetAddress.getLocalHost();
|
||||
} catch (UnknownHostException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
ipAddress = inet.getHostAddress();
|
||||
}
|
||||
}
|
||||
// 对于通过多个代理的情况,第一个IP为客户端真实IP,多个IP按照','分割
|
||||
if (ipAddress != null && ipAddress.length() > 15) {
|
||||
// "***.***.***.***".length()
|
||||
// = 15
|
||||
if (ipAddress.indexOf(",") > 0) {
|
||||
ipAddress = ipAddress.substring(0, ipAddress.indexOf(","));
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
ipAddress = "";
|
||||
}
|
||||
return ipAddress;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* MD5加密
|
||||
*
|
||||
* @param data
|
||||
* @return
|
||||
*/
|
||||
public static String MD5(String data) {
|
||||
try {
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
byte[] array = md.digest(data.getBytes("UTF-8"));
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (byte item : array) {
|
||||
sb.append(Integer.toHexString((item & 0xFF) | 0x100).substring(1, 3));
|
||||
}
|
||||
|
||||
return sb.toString().toUpperCase();
|
||||
} catch (Exception exception) {
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成随机数
|
||||
*
|
||||
* @param length
|
||||
* @return
|
||||
*/
|
||||
|
||||
public static String getRandomCode(int length) {
|
||||
String sources = "0123456789";
|
||||
Random random = new Random();
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for (int i = 0; i < length; i++) {
|
||||
stringBuilder.append(sources.charAt(random.nextInt(9)));
|
||||
}
|
||||
return stringBuilder.toString();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成UUID
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String generateUUID() {
|
||||
return UUID.randomUUID().toString()
|
||||
//删除-
|
||||
.replaceAll("-", "")
|
||||
//截取前32位
|
||||
.substring(0, 32);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前时间戳
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static long getCurrentTimestamp() {
|
||||
return System.currentTimeMillis();
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成指定长度随机串
|
||||
*
|
||||
* @param length
|
||||
* @return
|
||||
*/
|
||||
private static final String ALL_CHAR_NUM = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||
|
||||
public static String getStringNumRandom(int length) {
|
||||
//生成随机数字和字母,
|
||||
Random random = new Random();
|
||||
StringBuilder saltString = new StringBuilder(length);
|
||||
for (int i = 1; i <= length; ++i) {
|
||||
saltString.append(ALL_CHAR_NUM.charAt(random.nextInt(ALL_CHAR_NUM.length())));
|
||||
}
|
||||
return saltString.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 响应json数据给前端
|
||||
* @param response
|
||||
* @param obj
|
||||
*/
|
||||
public static void sendJsonMessage(HttpServletResponse response, Object obj) {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
response.setContentType("application/json; charset=utf-8");
|
||||
|
||||
try(PrintWriter writer=response.getWriter()){
|
||||
writer.print(objectMapper.writeValueAsString(obj));
|
||||
writer.close();
|
||||
|
||||
response.flushBuffer();
|
||||
|
||||
}catch(IOException e){
|
||||
log.warn("响应json数据给前端异常:{}",e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
76
common/src/main/java/net/carbon/utils/JWTUtil.java
Normal file
76
common/src/main/java/net/carbon/utils/JWTUtil.java
Normal file
@ -0,0 +1,76 @@
|
||||
package net.carbon.utils;
|
||||
|
||||
|
||||
import io.jsonwebtoken.Claims;
|
||||
import io.jsonwebtoken.Jwts;
|
||||
import io.jsonwebtoken.SignatureAlgorithm;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.carbon.model.LoginUser;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
@Slf4j
|
||||
public class JWTUtil {
|
||||
|
||||
/**
|
||||
* 过期时间
|
||||
* 1000毫秒 * 60秒 * 60分钟 * 24小时 * 7天 * 10
|
||||
*/
|
||||
private static final long EXPIRE = 1000 * 60 * 60 * 24 * 7 * 10;
|
||||
|
||||
/**
|
||||
* 加密密钥
|
||||
*/
|
||||
private static final String SECRET = "net.carbon";
|
||||
/**
|
||||
* 令牌前缀
|
||||
*/
|
||||
private static final String TOKEN_PREFIX = "carbon";
|
||||
|
||||
/**
|
||||
* 令牌前缀
|
||||
*/
|
||||
private static final String SUBJECT = "carbonemission";
|
||||
|
||||
/**
|
||||
* 根据用户信息,生成令牌
|
||||
*
|
||||
* @param user
|
||||
* @return
|
||||
*/
|
||||
public static String geneJsonWebToken(LoginUser user) {
|
||||
Long userId = user.getId();
|
||||
String token = Jwts.builder().setSubject(SUBJECT)
|
||||
.claim("id", userId)
|
||||
.claim("username", user.getUsername())
|
||||
.setIssuedAt(new Date())
|
||||
.setExpiration(new Date(System.currentTimeMillis() + EXPIRE))
|
||||
.signWith(SignatureAlgorithm.HS256, SECRET).compact();
|
||||
|
||||
token = TOKEN_PREFIX + token;
|
||||
return token;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 校验token的方法
|
||||
*
|
||||
* @param token
|
||||
* @return
|
||||
*/
|
||||
public static Claims checkJWT(String token) {
|
||||
try {
|
||||
final Claims claims = Jwts.parser()
|
||||
.setSigningKey(SECRET)
|
||||
.parseClaimsJws(token.replace(TOKEN_PREFIX, ""))
|
||||
.getBody();
|
||||
|
||||
return claims;
|
||||
|
||||
} catch (Exception e) {
|
||||
log.info("jwt token解密失败");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
90
common/src/main/java/net/carbon/utils/JsonData.java
Normal file
90
common/src/main/java/net/carbon/utils/JsonData.java
Normal file
@ -0,0 +1,90 @@
|
||||
package net.carbon.utils;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.TypeReference;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import net.carbon.enums.BizCodeEnum;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class JsonData {
|
||||
|
||||
/**
|
||||
* 状态码 0 表示成功,1表示处理中,-1表示失败
|
||||
*/
|
||||
private Integer code;
|
||||
|
||||
/**
|
||||
* 数据
|
||||
*/
|
||||
private Object data;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
private String msg;
|
||||
|
||||
|
||||
/**
|
||||
* 获取远程调用数据对象
|
||||
* 注意 支持多单词下划线转驼峰(序列化和反序列化)
|
||||
* 空对象不序列化
|
||||
*/
|
||||
public <T> T getData(TypeReference<T> typeReference) {
|
||||
return JSON.parseObject(JSON.toJSONString(data), typeReference);
|
||||
}
|
||||
|
||||
/**
|
||||
* 成功,传入数据
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static JsonData buildSuccess() {
|
||||
return new JsonData(0, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 成功,传入数据
|
||||
*
|
||||
* @param data
|
||||
* @return
|
||||
*/
|
||||
public static JsonData buildSuccess(Object data) {
|
||||
return new JsonData(0, data, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 失败,传入描述信息
|
||||
*
|
||||
* @param msg
|
||||
* @return
|
||||
*/
|
||||
public static JsonData buildError(String msg) {
|
||||
return new JsonData(-1, null, msg);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 自定义状态码和错误信息
|
||||
*
|
||||
* @param code
|
||||
* @param msg
|
||||
* @return
|
||||
*/
|
||||
public static JsonData buildCodeAndMsg(int code, String msg) {
|
||||
return new JsonData(code, null, msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 传入枚举,返回信息
|
||||
*
|
||||
* @param codeEnum
|
||||
* @return
|
||||
*/
|
||||
public static JsonData buildResult(BizCodeEnum codeEnum) {
|
||||
return JsonData.buildCodeAndMsg(codeEnum.getCode(), codeEnum.getMessage());
|
||||
}
|
||||
}
|
213
pom.xml
Normal file
213
pom.xml
Normal file
@ -0,0 +1,213 @@
|
||||
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>net.carbon</groupId>
|
||||
<artifactId>CarbonNeutrality</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<modules>
|
||||
<module>common</module>
|
||||
<module>server</module>
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
<java.version>17</java.version>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
|
||||
<spring.boot.version>3.3.0</spring.boot.version>
|
||||
<mybatisplus.boot3.starter.version>3.5.10.1</mybatisplus.boot3.starter.version>
|
||||
<lombok.version>1.18.24</lombok.version>
|
||||
<commons.lang3.version>3.9</commons.lang3.version>
|
||||
<commons.codec.version>1.15</commons.codec.version>
|
||||
<springfox.boot.starter.version>3.0.0</springfox.boot.starter.version>
|
||||
<jjwt.version>0.7.0</jjwt.version>
|
||||
<velocity-engine-core.version>2.0</velocity-engine-core.version>
|
||||
<fastjson.version>1.2.62</fastjson.version>
|
||||
<mysql.connection.version>8.0.33</mysql.connection.version>
|
||||
<jakarta.servlet.version>6.0.0</jakarta.servlet.version>
|
||||
<jaxb.version>2.3.1</jaxb.version>
|
||||
|
||||
<!--跳过单元测试-->
|
||||
<skipTests>true</skipTests>
|
||||
|
||||
</properties>
|
||||
|
||||
<!--锁定版本-->
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<!--https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-dependencies/2.3.3.RELEASE-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-dependencies</artifactId>
|
||||
<version>${spring.boot.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!--mybatis plus和springboot整合-->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-spring-boot3-starter</artifactId>
|
||||
<version>${mybatisplus.boot3.starter.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-jsqlparser</artifactId>
|
||||
<version>${mybatisplus.boot3.starter.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-generator</artifactId>
|
||||
<version>${mybatisplus.boot3.starter.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!--https://mvnrepository.com/artifact/org.projectlombok/lombok/1.18.16-->
|
||||
<!--scope=provided,说明它只在编译阶段生效,不需要打入包中, Lombok在编译期将带Lombok注解的Java文件正确编译为完整的Class文件-->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok.version}</version>
|
||||
<!-- <scope>provided</scope>-->
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>${commons.lang3.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/commons-codec/commons-codec -->
|
||||
<!--用于加密-->
|
||||
<dependency>
|
||||
<groupId>commons-codec</groupId>
|
||||
<artifactId>commons-codec</artifactId>
|
||||
<version>${commons.codec.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!--接口文档依赖-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>io.springfox</groupId>-->
|
||||
<!-- <artifactId>springfox-boot-starter</artifactId>-->
|
||||
<!-- <version>${springfox.boot.starter.version}</version>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- JWT相关 -->
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt</artifactId>
|
||||
<version>${jjwt.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!--单元测试依赖-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<version>${spring.boot.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- velocity -->
|
||||
<dependency>
|
||||
<groupId>org.apache.velocity</groupId>
|
||||
<artifactId>velocity-engine-core</artifactId>
|
||||
<version>${velocity-engine-core.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>${fastjson.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
|
||||
<version>4.1.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>${mysql.connection.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>jakarta.servlet</groupId>
|
||||
<artifactId>jakarta.servlet-api</artifactId>
|
||||
<version>${jakarta.servlet.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>javax.xml.bind</groupId>
|
||||
<artifactId>jaxb-api</artifactId>
|
||||
<version>${jaxb.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jaxb</groupId>
|
||||
<artifactId>jaxb-runtime</artifactId>
|
||||
<version>${jaxb.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<!-- 代码库 -->
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>maven-ali</id>
|
||||
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
<updatePolicy>always</updatePolicy>
|
||||
<checksumPolicy>fail</checksumPolicy>
|
||||
</snapshots>
|
||||
</repository>
|
||||
|
||||
|
||||
</repositories>
|
||||
|
||||
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>public</id>
|
||||
<name>aliyun nexus</name>
|
||||
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
|
||||
|
||||
<!--module不用添加打包版本信息-->
|
||||
<build>
|
||||
<!-- <plugins>-->
|
||||
<!-- <plugin>-->
|
||||
<!-- <groupId>org.springframework.boot</groupId>-->
|
||||
<!-- <artifactId>spring-boot-maven-plugin</artifactId>-->
|
||||
<!-- <version>${spring.boot.version}</version>-->
|
||||
<!-- <configuration>-->
|
||||
<!-- <fork>true</fork>-->
|
||||
<!-- <addResources>true</addResources>-->
|
||||
<!-- </configuration>-->
|
||||
<!-- </plugin>-->
|
||||
<!-- </plugins>-->
|
||||
</build>
|
||||
|
||||
|
||||
</project>
|
101
server/pom.xml
Normal file
101
server/pom.xml
Normal file
@ -0,0 +1,101 @@
|
||||
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>net.carbon</groupId>
|
||||
<artifactId>CarbonNeutrality</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>server</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.carbon</groupId>
|
||||
<artifactId>common</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!--单元测试依赖-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 代码自动生成依赖 begin -->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-generator</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-jsqlparser</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- velocity -->
|
||||
<dependency>
|
||||
<groupId>org.apache.velocity</groupId>
|
||||
<artifactId>velocity-engine-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.freemarker</groupId>
|
||||
<artifactId>freemarker</artifactId>
|
||||
<version>2.3.31</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<version>2.6.0</version>
|
||||
<configuration>
|
||||
<mainClass>net.carbon.ServerApplication</mainClass>
|
||||
<finalName>app</finalName>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>repackage</id>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<!-- maven 打包时跳过测试 -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<skip>true</skip>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
18
server/src/main/java/net/carbon/ServerApplication.java
Normal file
18
server/src/main/java/net/carbon/ServerApplication.java
Normal file
@ -0,0 +1,18 @@
|
||||
package net.carbon;
|
||||
|
||||
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableTransactionManagement
|
||||
@MapperScan("net.carbon.mapper")
|
||||
public class ServerApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ServerApplication.class, args);
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package net.carbon.config;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.carbon.interceptor.LoginInterceptor;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@Configuration
|
||||
@Slf4j
|
||||
public class InterceptorConfig implements WebMvcConfigurer {
|
||||
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
registry
|
||||
.addInterceptor(new LoginInterceptor())
|
||||
//拦截的路径
|
||||
.addPathPatterns("/api/user/*/**", "/api/carbon/*/**")
|
||||
//放行的路径
|
||||
.excludePathPatterns("/api/user/*/register", "/api/user/*/login", "api/label/*/**");
|
||||
|
||||
WebMvcConfigurer.super.addInterceptors(registry);
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package net.carbon.controller;
|
||||
|
||||
|
||||
import net.carbon.service.CarbonEmissionService;
|
||||
import net.carbon.utils.JsonData;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author jieyuu
|
||||
* @since 2024-12-29
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/carbon/v1")
|
||||
public class CarbonEmissionController {
|
||||
|
||||
@Autowired
|
||||
private CarbonEmissionService carbonEmissionService;
|
||||
|
||||
/**
|
||||
* 及时预警接口
|
||||
*
|
||||
* @param city
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("timelyAlert")
|
||||
public JsonData timelyAlert(@RequestBody String city) {
|
||||
return JsonData.buildSuccess(carbonEmissionService.timelyAlert(city));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据
|
||||
*
|
||||
* @param city
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("getCarbonEmissionData")
|
||||
public JsonData getCarbonEmissionData(@RequestBody String city) {
|
||||
return JsonData.buildSuccess(carbonEmissionService.getCarbonEmissionData(city));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,118 @@
|
||||
package net.carbon.controller;
|
||||
|
||||
import net.carbon.bean.PageResponse;
|
||||
import net.carbon.model.request.EconomicsUpdateRequest;
|
||||
import net.carbon.model.vo.EconomicsVO;
|
||||
import net.carbon.result.Result;
|
||||
import net.carbon.service.EconomicsService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* (Economics)表控制层
|
||||
*
|
||||
* @author makejava
|
||||
* @since 2025-02-21 13:44:09
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/economics/v1/")
|
||||
public class EconomicsController {
|
||||
|
||||
/**
|
||||
* 分页查询所有数据
|
||||
*
|
||||
* @param page 分页对象
|
||||
* @param economics 查询实体
|
||||
* @return 所有数据
|
||||
*/
|
||||
// @GetMapping
|
||||
// public Result selectAll(Page<Economics> page, Economics economics) {
|
||||
// return success(this.economicsService.page(page, new QueryWrapper<>(economics)));
|
||||
// }
|
||||
|
||||
/**
|
||||
* 通过主键查询单条数据
|
||||
*
|
||||
* @param id 主键
|
||||
* @return 单条数据
|
||||
*/
|
||||
// @GetMapping("{id}")
|
||||
// public R selectOne(@PathVariable Serializable id) {
|
||||
// return success(this.economicsService.getById(id));
|
||||
// }
|
||||
|
||||
/**
|
||||
* 新增数据
|
||||
*
|
||||
* @param economics 实体对象
|
||||
* @return 新增结果
|
||||
*/
|
||||
// @PostMapping
|
||||
// public R insert(@RequestBody Economics economics) {
|
||||
// return success(this.economicsService.save(economics));
|
||||
// }
|
||||
|
||||
/**
|
||||
* 修改数据
|
||||
*
|
||||
* @param economics 实体对象
|
||||
* @return 修改结果
|
||||
*/
|
||||
// @PutMapping
|
||||
// public R update(@RequestBody Economics economics) {
|
||||
// return success(this.economicsService.updateById(economics));
|
||||
// }
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
*
|
||||
* @param idList 主键结合
|
||||
* @return 删除结果
|
||||
*/
|
||||
// @DeleteMapping
|
||||
// public R delete(@RequestParam("idList") List<Long> idList) {
|
||||
// return success(this.economicsService.removeByIds(idList));
|
||||
// }
|
||||
|
||||
|
||||
@Autowired
|
||||
private EconomicsService economicsService;
|
||||
|
||||
// 获取所有指标
|
||||
@GetMapping("/list")
|
||||
public Result<PageResponse<EconomicsVO>> getAllIndicators(@RequestParam("pageSize") Long pageSize, @RequestParam("current") Long current) {
|
||||
return Result.success(economicsService.getPage(pageSize, current));
|
||||
}
|
||||
|
||||
// 新增指标
|
||||
// @PostMapping("/create")
|
||||
// public Result createIndicator(@RequestBody EconomicsRequest economicsRequest) {
|
||||
//
|
||||
// boolean save = economicsService.save(economicsRequest);
|
||||
// if (save) {
|
||||
// return Result.success();
|
||||
// }
|
||||
// return Result.error("创建失败");
|
||||
// }
|
||||
|
||||
// 生成编辑接口
|
||||
@PostMapping("/update")
|
||||
public Result updateIndicator(@RequestBody EconomicsUpdateRequest economicsUpdateReq) {
|
||||
int row = economicsService.updateById(economicsUpdateReq);
|
||||
if (row > 0) {
|
||||
return Result.success();
|
||||
}
|
||||
return Result.error("编辑失败");
|
||||
}
|
||||
|
||||
// 剔除指标
|
||||
@DeleteMapping("/delete/{id}")
|
||||
public Result delete(@PathVariable("id") Long id) {
|
||||
int row = economicsService.delete(id);
|
||||
if (row > 0) {
|
||||
return Result.success();
|
||||
}
|
||||
return Result.error("删除失败");
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,71 @@
|
||||
package net.carbon.controller;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import net.carbon.bean.PageResponse;
|
||||
import net.carbon.model.po.LabelDO;
|
||||
import net.carbon.model.request.LabelUpdateRequest;
|
||||
import net.carbon.model.vo.LabelVO;
|
||||
import net.carbon.result.Result;
|
||||
import net.carbon.service.LabelService;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 碳排放-城市高质量发展指标体系-标签表 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author jieyuu
|
||||
* @since 2025-02-19
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/label/v1")
|
||||
public class LabelController {
|
||||
@Autowired
|
||||
private LabelService labelService;
|
||||
|
||||
// 获取所有指标
|
||||
@GetMapping("/list")
|
||||
public Result<PageResponse<LabelVO>> getAllIndicators(@RequestParam("pageSize") Long pageSize, @RequestParam("current") Long current) {
|
||||
return Result.success(labelService.getList(pageSize, current));
|
||||
}
|
||||
|
||||
// // 新增指标
|
||||
// @PostMapping("/create")
|
||||
// public Result<LabelDO> createIndicator(@RequestBody LabelDO label) {
|
||||
// boolean save = labelService.save(label);
|
||||
// if (save) {
|
||||
// return Result.success();
|
||||
// }
|
||||
// return Result.error("创建失败");
|
||||
// }
|
||||
|
||||
// 生成编辑接口
|
||||
@PostMapping("/update")
|
||||
public Result update(@RequestBody LabelUpdateRequest labelUpdateReq) {
|
||||
int row = labelService.updateById(labelUpdateReq);
|
||||
if (row > 0) {
|
||||
return Result.success();
|
||||
}
|
||||
return Result.error("修改失败");
|
||||
}
|
||||
|
||||
// 剔除指标
|
||||
@DeleteMapping("/delete/{id}")
|
||||
public Result delete(@PathVariable("id") Long id) {
|
||||
int row = labelService.delete(id);
|
||||
if (row > 0) {
|
||||
return Result.success();
|
||||
}
|
||||
return Result.error("删除失败");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,45 @@
|
||||
package net.carbon.controller;
|
||||
|
||||
import net.carbon.bean.PageResponse;
|
||||
import net.carbon.model.request.LabelUpdateRequest;
|
||||
import net.carbon.model.request.TimelyWarningRequest;
|
||||
import net.carbon.model.vo.LabelVO;
|
||||
import net.carbon.model.vo.TimelyWarningVO;
|
||||
import net.carbon.result.Result;
|
||||
import net.carbon.service.TimelyWarningService;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api")
|
||||
public class TimelyWarningController {
|
||||
private TimelyWarningService timelyWarningService;
|
||||
|
||||
@GetMapping("/TimelyWarning")
|
||||
public Result<PageResponse<TimelyWarningVO>> get(@RequestParam("pageSize") Long pageSize, @RequestParam("page") Long page) {
|
||||
return Result.success(timelyWarningService.getList(pageSize, page));
|
||||
}
|
||||
|
||||
@DeleteMapping("warn/delete")
|
||||
public Result<Boolean> delete(@RequestParam("id") Long id) {
|
||||
int row = timelyWarningService.delete(id);
|
||||
if (row > 0) {
|
||||
return Result.success();
|
||||
}
|
||||
return Result.error("删除失败");
|
||||
}
|
||||
|
||||
@PostMapping("warn/edit")
|
||||
public Result update(@RequestBody TimelyWarningRequest timelyWarningRequest) {
|
||||
int row = timelyWarningService.updateById(timelyWarningRequest);
|
||||
if (row > 0) {
|
||||
return Result.success();
|
||||
}
|
||||
return Result.error("修改失败");
|
||||
}
|
||||
|
||||
@PostMapping("warn/add")
|
||||
public Result add(@RequestBody TimelyWarningRequest timelyWarningRequest) {
|
||||
timelyWarningService.add(timelyWarningRequest);
|
||||
return Result.success();
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
package net.carbon.controller;
|
||||
|
||||
//import io.swagger.annotations.ApiParam;
|
||||
|
||||
import net.carbon.model.vo.UserVO;
|
||||
import net.carbon.model.request.UserRegisterRequest;
|
||||
import net.carbon.model.request.UserLoginRequest;
|
||||
import net.carbon.service.UserService;
|
||||
import net.carbon.utils.JsonData;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/user/v1")
|
||||
public class UserController {
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
/**
|
||||
* 用户注册
|
||||
*
|
||||
* @param registerRequest
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "register")
|
||||
public JsonData register(@RequestBody UserRegisterRequest registerRequest) {
|
||||
JsonData jsonData = userService.register(registerRequest);
|
||||
|
||||
return jsonData;
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户登录
|
||||
*
|
||||
* @param loginRequest
|
||||
* @return
|
||||
*/
|
||||
|
||||
// @ApiOperation("用户登录")
|
||||
@PostMapping("login")
|
||||
public JsonData userLogin(@RequestBody UserLoginRequest loginRequest) {
|
||||
|
||||
JsonData jsonData = userService.login(loginRequest);
|
||||
return jsonData;
|
||||
}
|
||||
|
||||
@PostMapping("logout")
|
||||
public JsonData logout() {
|
||||
// todo jwt退出登录
|
||||
return JsonData.buildSuccess("退出成功");
|
||||
}
|
||||
|
||||
@GetMapping("userinfo")
|
||||
public JsonData getUserInfo() {
|
||||
UserVO userinfo = userService.userinfo();
|
||||
return JsonData.buildSuccess(userinfo);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package net.carbon.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import net.carbon.model.po.CarbonEmissionDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author jieyuu
|
||||
* @since 2024-12-29
|
||||
*/
|
||||
@Mapper
|
||||
public interface CarbonEmissionMapper extends BaseMapper<CarbonEmissionDO> {
|
||||
|
||||
}
|
20
server/src/main/java/net/carbon/mapper/EconomicsMapper.java
Normal file
20
server/src/main/java/net/carbon/mapper/EconomicsMapper.java
Normal file
@ -0,0 +1,20 @@
|
||||
package net.carbon.mapper;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import net.carbon.model.po.EconomicsDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author jieyuu
|
||||
* @since 2025-02-21
|
||||
*/
|
||||
@Mapper
|
||||
public interface EconomicsMapper extends BaseMapper<EconomicsDO> {
|
||||
|
||||
}
|
18
server/src/main/java/net/carbon/mapper/LabelMapper.java
Normal file
18
server/src/main/java/net/carbon/mapper/LabelMapper.java
Normal file
@ -0,0 +1,18 @@
|
||||
package net.carbon.mapper;
|
||||
|
||||
import net.carbon.model.po.LabelDO;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 碳排放-城市高质量发展指标体系-标签表 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author jieyuu
|
||||
* @since 2025-02-19
|
||||
*/
|
||||
@Mapper
|
||||
public interface LabelMapper extends BaseMapper<LabelDO> {
|
||||
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package net.carbon.mapper;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import net.carbon.model.po.EconomicsDO;
|
||||
import net.carbon.model.po.TimelyWarningDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
|
||||
@Mapper
|
||||
public interface TimelyWarningMapper extends BaseMapper<TimelyWarningDO> {
|
||||
|
||||
}
|
19
server/src/main/java/net/carbon/mapper/UserMapper.java
Normal file
19
server/src/main/java/net/carbon/mapper/UserMapper.java
Normal file
@ -0,0 +1,19 @@
|
||||
package net.carbon.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import net.carbon.model.po.UserDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author jieyuu
|
||||
* @since 2024-11-23
|
||||
*/
|
||||
@Mapper
|
||||
public interface UserMapper extends BaseMapper<UserDO> {
|
||||
|
||||
}
|
61
server/src/main/java/net/carbon/model/CarbonEmissionDO.java
Normal file
61
server/src/main/java/net/carbon/model/CarbonEmissionDO.java
Normal file
@ -0,0 +1,61 @@
|
||||
package net.carbon.model;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author jieyuu
|
||||
* @since 2024-12-29
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("carbon_emission")
|
||||
public class CarbonEmissionDO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Integer id;
|
||||
|
||||
private String city;
|
||||
|
||||
private BigDecimal wastewaterDischargeTotal;
|
||||
|
||||
private BigDecimal airQualityAchievementRate;
|
||||
|
||||
private BigDecimal gdpElectricityConsumption;
|
||||
|
||||
private BigDecimal wasteResourceIndustryValue;
|
||||
|
||||
private BigDecimal forestCoverageRate;
|
||||
|
||||
private BigDecimal ecologicalIndex;
|
||||
|
||||
private BigDecimal importExportTotal;
|
||||
|
||||
private Integer foreignInvestmentEnterprises;
|
||||
|
||||
private BigDecimal tourismIncome;
|
||||
|
||||
private Integer overnightTourists;
|
||||
|
||||
private BigDecimal publicManagementDensity;
|
||||
|
||||
private BigDecimal perCapitaServiceFunds;
|
||||
|
||||
private BigDecimal averageAnnualSalary;
|
||||
|
||||
private BigDecimal urbanPerCapitaIncome;
|
||||
|
||||
|
||||
}
|
31
server/src/main/java/net/carbon/model/UserDO.java
Normal file
31
server/src/main/java/net/carbon/model/UserDO.java
Normal file
@ -0,0 +1,31 @@
|
||||
package net.carbon.model;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author jieyuu
|
||||
* @since 2024-11-23
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("user")
|
||||
public class UserDO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
private String username;
|
||||
|
||||
private String password;
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
package net.carbon.model.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author jieyuu
|
||||
* @since 2024-12-29
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("carbon_emission")
|
||||
public class CarbonEmissionDO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
private String city;
|
||||
|
||||
private BigDecimal wastewaterDischargeTotal;
|
||||
|
||||
private BigDecimal airQualityAchievementRate;
|
||||
|
||||
private BigDecimal gdpElectricityConsumption;
|
||||
|
||||
private BigDecimal wasteResourceIndustryValue;
|
||||
|
||||
private BigDecimal forestCoverageRate;
|
||||
|
||||
private BigDecimal ecologicalIndex;
|
||||
|
||||
private BigDecimal importExportTotal;
|
||||
|
||||
private Integer foreignInvestmentEnterprises;
|
||||
|
||||
private BigDecimal tourismIncome;
|
||||
|
||||
private Integer overnightTourists;
|
||||
|
||||
private BigDecimal publicManagementDensity;
|
||||
|
||||
private BigDecimal perCapitaServiceFunds;
|
||||
|
||||
private BigDecimal averageAnnualSalary;
|
||||
|
||||
private BigDecimal urbanPerCapitaIncome;
|
||||
|
||||
|
||||
}
|
65
server/src/main/java/net/carbon/model/po/EconomicsDO.java
Normal file
65
server/src/main/java/net/carbon/model/po/EconomicsDO.java
Normal file
@ -0,0 +1,65 @@
|
||||
package net.carbon.model.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author jieyuu
|
||||
* @since 2025-02-21
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@TableName("economics")
|
||||
public class EconomicsDO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableField("id")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 项目名称
|
||||
*/
|
||||
@TableField("name")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 指标单位
|
||||
*/
|
||||
@TableField("unit")
|
||||
private String unit;
|
||||
|
||||
/**
|
||||
* 数据
|
||||
*/
|
||||
@TableField("data")
|
||||
private Double data;
|
||||
|
||||
/**
|
||||
* 指标属性
|
||||
*/
|
||||
@TableField("attribute")
|
||||
private String attribute;
|
||||
|
||||
/**
|
||||
* 0代表是系统数据不能删除,1代表是其他数据,可以删除
|
||||
*/
|
||||
@TableField("is_system_date")
|
||||
private Integer isSystemDate;
|
||||
|
||||
/**
|
||||
* 逻辑删除标记(默认0,删除1)
|
||||
*/
|
||||
@TableField("is_delete")
|
||||
private Byte isDelete;
|
||||
}
|
66
server/src/main/java/net/carbon/model/po/LabelDO.java
Normal file
66
server/src/main/java/net/carbon/model/po/LabelDO.java
Normal file
@ -0,0 +1,66 @@
|
||||
package net.carbon.model.po;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 碳排放-城市高质量发展指标体系-标签表
|
||||
* </p>
|
||||
*
|
||||
* @author jieyuu
|
||||
* @since 2025-02-19
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("label")
|
||||
public class LabelDO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 指标名称
|
||||
*/
|
||||
@TableField("name")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 单位
|
||||
*/
|
||||
@TableField("unit")
|
||||
private String unit;
|
||||
|
||||
/**
|
||||
* 数据值
|
||||
*/
|
||||
@TableField("data_value")
|
||||
private BigDecimal dataValue;
|
||||
|
||||
/**
|
||||
* 指数属性
|
||||
*/
|
||||
@TableField("attribute")
|
||||
private String attribute;
|
||||
|
||||
/**
|
||||
* 是否剔除(0-是系统数据不能删除,1-不是系统数据,可以删除)
|
||||
*/
|
||||
@TableField("is_system_date")
|
||||
private Integer isSystemDate;
|
||||
|
||||
/**
|
||||
* 逻辑删除标记
|
||||
*/
|
||||
@TableField("is_delete")
|
||||
@TableLogic(value = "0", delval = "1")
|
||||
private Integer isDeleted;
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package net.carbon.model.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("timely_warning")
|
||||
public class TimelyWarningDO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableField("id")
|
||||
private Long id;
|
||||
|
||||
@TableField("name")
|
||||
private String name;
|
||||
|
||||
@TableField("unit")
|
||||
private String unit;
|
||||
|
||||
@TableField("data")
|
||||
private Double data;
|
||||
|
||||
@TableField("direction")
|
||||
private String direction;
|
||||
}
|
88
server/src/main/java/net/carbon/model/po/UserDO.java
Normal file
88
server/src/main/java/net/carbon/model/po/UserDO.java
Normal file
@ -0,0 +1,88 @@
|
||||
package net.carbon.model.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author jieyuu
|
||||
* @since 2024-11-23
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("user")
|
||||
public class UserDO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
@TableField("username")
|
||||
private String username;
|
||||
|
||||
@TableField("password")
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 用户照片
|
||||
*/
|
||||
@TableField("avatar")
|
||||
private String avatar;
|
||||
|
||||
/**
|
||||
* 用户角色,1代表管理员,2代表普通用户
|
||||
*/
|
||||
@TableField("role")
|
||||
private Integer role;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
@TableField("description")
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 用户的名字
|
||||
*/
|
||||
@TableField("name")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 用户的电话号码
|
||||
*/
|
||||
@TableField("phone")
|
||||
private String phone;
|
||||
|
||||
/**
|
||||
* 用户地址
|
||||
*/
|
||||
@TableField("address")
|
||||
private String address;
|
||||
|
||||
/**
|
||||
* 用户创建时间
|
||||
*/
|
||||
@TableField("creationTime")
|
||||
private LocalDateTime creationTime;
|
||||
|
||||
/**
|
||||
* 用户更新时间
|
||||
*/
|
||||
@TableField("updateTime")
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 逻辑删除标记
|
||||
*/
|
||||
@TableField("is_delete")
|
||||
@TableLogic(value = "0", delval = "1")
|
||||
private Byte isDelete;
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package net.carbon.model.request;
|
||||
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class EconomicsUpdateRequest {
|
||||
private Long id;
|
||||
private String name;
|
||||
|
||||
private String unit;
|
||||
|
||||
private Double data;
|
||||
|
||||
private String attribute;
|
||||
|
||||
private Integer isSystemDate;
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package net.carbon.model.request;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
|
||||
@Data
|
||||
public class LabelUpdateRequest {
|
||||
|
||||
private Long id;
|
||||
/**
|
||||
* 指标名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 单位
|
||||
*/
|
||||
private String unit;
|
||||
|
||||
/**
|
||||
* 数据值
|
||||
*/
|
||||
private BigDecimal dataValue;
|
||||
|
||||
/**
|
||||
* 指数属性
|
||||
*/
|
||||
private String attribute;
|
||||
|
||||
/**
|
||||
* 是否剔除(0-是系统数据不能删除,1-不是系统数据,可以删除)
|
||||
*/
|
||||
private Integer isSystemDate;
|
||||
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package net.carbon.model.request;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class TimelyWarningRequest {
|
||||
|
||||
private Long id;
|
||||
|
||||
private String name;
|
||||
|
||||
private String unit;
|
||||
|
||||
private Double data;
|
||||
|
||||
private String direction;
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package net.carbon.model.request;
|
||||
|
||||
//import io.swagger.annotations.ApiModel;
|
||||
//import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
//@ApiModel(value = "登录对象", description = "用户登录请求对象")
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class UserLoginRequest {
|
||||
|
||||
// @ApiModelProperty(value = "用户名", example = "jieyuu")
|
||||
private String username;
|
||||
|
||||
// @ApiModelProperty(value = "密码", example = "123456")
|
||||
private String password;
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package net.carbon.model.request;
|
||||
|
||||
//import io.swagger.annotations.ApiModel;
|
||||
//import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class UserRegisterRequest {
|
||||
|
||||
private String username;
|
||||
|
||||
private String password;
|
||||
|
||||
}
|
35
server/src/main/java/net/carbon/model/vo/EconomicsVO.java
Normal file
35
server/src/main/java/net/carbon/model/vo/EconomicsVO.java
Normal file
@ -0,0 +1,35 @@
|
||||
package net.carbon.model.vo;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author jieyuu
|
||||
* @since 2025-02-21
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class EconomicsVO implements Serializable {
|
||||
private Long id;
|
||||
|
||||
private String name;
|
||||
|
||||
private String unit;
|
||||
|
||||
private Double data;
|
||||
|
||||
private String attribute;
|
||||
|
||||
private Integer isSystemDate;
|
||||
|
||||
private Byte isDelete;
|
||||
}
|
39
server/src/main/java/net/carbon/model/vo/LabelVO.java
Normal file
39
server/src/main/java/net/carbon/model/vo/LabelVO.java
Normal file
@ -0,0 +1,39 @@
|
||||
package net.carbon.model.vo;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Data
|
||||
public class LabelVO {
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 指标名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 单位
|
||||
*/
|
||||
private String unit;
|
||||
|
||||
/**
|
||||
* 数据值
|
||||
*/
|
||||
private BigDecimal dataValue;
|
||||
|
||||
/**
|
||||
* 指数属性
|
||||
*/
|
||||
private String attribute;
|
||||
|
||||
/**
|
||||
* 是否剔除(0-是系统数据不能删除,1-不是系统数据,可以删除)
|
||||
*/
|
||||
private Integer isSystemDate;
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package net.carbon.model.vo;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class TimelyWarningVO {
|
||||
|
||||
private Long id;
|
||||
|
||||
private String name;
|
||||
|
||||
private String unit;
|
||||
|
||||
private Double data;
|
||||
|
||||
private String direction;
|
||||
}
|
45
server/src/main/java/net/carbon/model/vo/UserVO.java
Normal file
45
server/src/main/java/net/carbon/model/vo/UserVO.java
Normal file
@ -0,0 +1,45 @@
|
||||
package net.carbon.model.vo;
|
||||
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class UserVO {
|
||||
private Long id;
|
||||
|
||||
|
||||
private String username;
|
||||
|
||||
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 用户照片
|
||||
*/
|
||||
private String avatar;
|
||||
|
||||
/**
|
||||
* 用户角色,1代表管理员,2代表普通用户
|
||||
*/
|
||||
private Integer role;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 用户的名字
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 用户的电话号码
|
||||
*/
|
||||
private String phone;
|
||||
|
||||
/**
|
||||
* 用户地址
|
||||
*/
|
||||
private String address;
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package net.carbon.request;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@ApiModel(value = "登录对象", description = "用户登录请求对象")
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class UserLoginRequest {
|
||||
|
||||
@ApiModelProperty(value = "用户名", example = "jieyuu")
|
||||
private String username;
|
||||
|
||||
@ApiModelProperty(value = "密码", example = "123456")
|
||||
private String password;
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package net.carbon.request;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@ApiModel(value = "用户注册实体类")
|
||||
public class UserRegisterRequest {
|
||||
|
||||
@ApiModelProperty(value = "用户名", example = "123456")
|
||||
private String username;
|
||||
|
||||
@ApiModelProperty(value = "密码", example = "123456")
|
||||
private String password;
|
||||
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package net.carbon.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import net.carbon.model.po.CarbonEmissionDO;
|
||||
import net.carbon.vo.CarbonTimelyAlertVO;
|
||||
import net.carbon.vo.CarbonVO;
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author jieyuu
|
||||
* @since 2024-12-29
|
||||
*/
|
||||
public interface CarbonEmissionService extends IService<CarbonEmissionDO> {
|
||||
|
||||
CarbonTimelyAlertVO timelyAlert(String city);
|
||||
|
||||
|
||||
CarbonVO getCarbonEmissionData(String city);
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package net.carbon.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import net.carbon.bean.PageResponse;
|
||||
import net.carbon.model.po.EconomicsDO;
|
||||
import net.carbon.model.request.EconomicsUpdateRequest;
|
||||
import net.carbon.model.vo.EconomicsVO;
|
||||
|
||||
/**
|
||||
* (Economics)表服务接口
|
||||
*
|
||||
* @author jieyuu
|
||||
* @since 2025-02-21 13:37:17
|
||||
*/
|
||||
public interface EconomicsService extends IService<EconomicsDO> {
|
||||
|
||||
PageResponse<EconomicsVO> getPage(Long pageSize, Long current);
|
||||
|
||||
Integer delete(Long id);
|
||||
|
||||
Integer updateById(EconomicsUpdateRequest economicsUpdateReq);
|
||||
|
||||
}
|
||||
|
28
server/src/main/java/net/carbon/service/LabelService.java
Normal file
28
server/src/main/java/net/carbon/service/LabelService.java
Normal file
@ -0,0 +1,28 @@
|
||||
package net.carbon.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import net.carbon.bean.PageResponse;
|
||||
import net.carbon.model.po.LabelDO;
|
||||
import net.carbon.model.request.LabelUpdateRequest;
|
||||
import net.carbon.model.vo.LabelVO;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 碳排放-城市高质量发展指标体系-标签表 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author jieyuu
|
||||
* @since 2025-02-19
|
||||
*/
|
||||
public interface LabelService extends IService<LabelDO> {
|
||||
|
||||
PageResponse<LabelVO> getList(Long pageSize, Long current);
|
||||
|
||||
int delete(Long id);
|
||||
|
||||
int updateById(LabelUpdateRequest labelUpdateReq);
|
||||
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package net.carbon.service;
|
||||
|
||||
import net.carbon.bean.PageResponse;
|
||||
import net.carbon.model.request.TimelyWarningRequest;
|
||||
import net.carbon.model.vo.LabelVO;
|
||||
import net.carbon.model.vo.TimelyWarningVO;
|
||||
|
||||
public interface TimelyWarningService {
|
||||
PageResponse<TimelyWarningVO> getList(Long pageSize, Long page);
|
||||
|
||||
int delete(Long id);
|
||||
|
||||
int updateById(TimelyWarningRequest timelyWarningRequest);
|
||||
|
||||
void add(TimelyWarningRequest timelyWarningRequest);
|
||||
}
|
39
server/src/main/java/net/carbon/service/UserService.java
Normal file
39
server/src/main/java/net/carbon/service/UserService.java
Normal file
@ -0,0 +1,39 @@
|
||||
package net.carbon.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import net.carbon.model.po.UserDO;
|
||||
|
||||
import net.carbon.model.vo.UserVO;
|
||||
import net.carbon.model.request.UserRegisterRequest;
|
||||
import net.carbon.model.request.UserLoginRequest;
|
||||
import net.carbon.utils.JsonData;
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author jieyuu
|
||||
* @since 2024-11-23
|
||||
*/
|
||||
public interface UserService extends IService<UserDO> {
|
||||
|
||||
/**
|
||||
* 用户注册
|
||||
*
|
||||
* @param userRegisterRequest
|
||||
* @return
|
||||
*/
|
||||
JsonData register(UserRegisterRequest userRegisterRequest);
|
||||
|
||||
/**
|
||||
* 用户登录
|
||||
*
|
||||
* @param loginRequest
|
||||
* @return
|
||||
*/
|
||||
JsonData login(UserLoginRequest loginRequest);
|
||||
|
||||
UserVO userinfo();
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
package net.carbon.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import net.carbon.mapper.CarbonEmissionMapper;
|
||||
import net.carbon.model.po.CarbonEmissionDO;
|
||||
import net.carbon.service.CarbonEmissionService;
|
||||
|
||||
|
||||
import net.carbon.vo.CarbonTimelyAlertVO;
|
||||
import net.carbon.vo.CarbonVO;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author jieyuu
|
||||
* @since 2024-12-29
|
||||
*/
|
||||
@Service
|
||||
public class CarbonEmissionServiceImpl extends ServiceImpl<CarbonEmissionMapper, CarbonEmissionDO> implements CarbonEmissionService {
|
||||
|
||||
@Autowired
|
||||
private CarbonEmissionMapper carbonEmissionMapper;
|
||||
|
||||
@Override
|
||||
public CarbonTimelyAlertVO timelyAlert(String city) {
|
||||
if (city == null || StringUtils.isBlank(city)) {
|
||||
return null;
|
||||
}
|
||||
QueryWrapper<CarbonEmissionDO> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.like("city", city);
|
||||
|
||||
CarbonEmissionDO carbonEmissionDO = carbonEmissionMapper.selectOne(queryWrapper);
|
||||
|
||||
CarbonTimelyAlertVO result = new CarbonTimelyAlertVO();
|
||||
if (carbonEmissionDO == null) {
|
||||
return null;
|
||||
}
|
||||
BeanUtils.copyProperties(carbonEmissionDO, result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CarbonVO getCarbonEmissionData(String city) {
|
||||
if (city == null || StringUtils.isBlank(city)) {
|
||||
return null;
|
||||
}
|
||||
QueryWrapper<CarbonEmissionDO> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.like("city", city);
|
||||
|
||||
CarbonEmissionDO carbonEmissionDO = carbonEmissionMapper.selectOne(queryWrapper);
|
||||
|
||||
CarbonVO result = new CarbonVO();
|
||||
if (carbonEmissionDO == null) {
|
||||
return null;
|
||||
}
|
||||
BeanUtils.copyProperties(carbonEmissionDO, result);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
package net.carbon.service.impl;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
|
||||
import net.carbon.bean.PageResponse;
|
||||
import net.carbon.mapper.EconomicsMapper;
|
||||
import net.carbon.model.po.EconomicsDO;
|
||||
import net.carbon.model.po.LabelDO;
|
||||
import net.carbon.model.request.EconomicsUpdateRequest;
|
||||
import net.carbon.model.vo.EconomicsVO;
|
||||
import net.carbon.model.vo.LabelVO;
|
||||
import net.carbon.service.EconomicsService;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* (Economics)表服务实现类
|
||||
*
|
||||
* @author jieyuu
|
||||
* @since 2025-02-21 13:37:20
|
||||
*/
|
||||
@Service
|
||||
public class EconomicsServiceImpl extends ServiceImpl<EconomicsMapper, EconomicsDO> implements EconomicsService {
|
||||
|
||||
@Autowired
|
||||
private EconomicsMapper economicsMapper;
|
||||
|
||||
@Override
|
||||
public PageResponse<EconomicsVO> getPage(Long pageSize, Long current) {
|
||||
|
||||
Page<EconomicsDO> pageInfo = new Page<>(current, pageSize);
|
||||
IPage<EconomicsDO> economicsDOPage = economicsMapper.selectPage(pageInfo, new LambdaQueryWrapper<EconomicsDO>());
|
||||
|
||||
PageResponse<EconomicsVO> pageResponse = new PageResponse<>();
|
||||
|
||||
List<EconomicsVO> economicsVOS = economicsDOPage.getRecords().stream().map(obj -> {
|
||||
EconomicsVO economicsVO = new EconomicsVO();
|
||||
BeanUtils.copyProperties(obj, economicsVO);
|
||||
return economicsVO;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
pageResponse.setPageSize(economicsDOPage.getSize());
|
||||
pageResponse.setCurrent(economicsDOPage.getCurrent());
|
||||
pageResponse.setTotal(economicsDOPage.getTotal());
|
||||
pageResponse.setRecords(economicsVOS);
|
||||
return pageResponse;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer delete(Long id) {
|
||||
|
||||
int row = economicsMapper.deleteById(id);
|
||||
return row;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer updateById(EconomicsUpdateRequest economicsUpdateReq) {
|
||||
EconomicsDO economicsDO = new EconomicsDO();
|
||||
BeanUtils.copyProperties(economicsUpdateReq, economicsDO);
|
||||
// 设置为0
|
||||
economicsDO.setIsDelete((byte) 0);
|
||||
int row = economicsMapper.updateById(economicsDO);
|
||||
return row;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,76 @@
|
||||
package net.carbon.service.impl;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import jakarta.annotation.Resource;
|
||||
import net.carbon.bean.PageResponse;
|
||||
import net.carbon.mapper.LabelMapper;
|
||||
import net.carbon.model.po.LabelDO;
|
||||
import net.carbon.model.request.LabelUpdateRequest;
|
||||
import net.carbon.model.vo.LabelVO;
|
||||
import net.carbon.service.LabelService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 碳排放-城市高质量发展指标体系-标签表 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author jieyuu
|
||||
* @since 2025-02-19
|
||||
*/
|
||||
@Service
|
||||
public class LabelServiceImpl extends ServiceImpl<LabelMapper, LabelDO> implements LabelService {
|
||||
|
||||
@Autowired
|
||||
private LabelMapper labelMapper;
|
||||
|
||||
@Override
|
||||
public PageResponse<LabelVO> getList(Long pageSize, Long current) {
|
||||
|
||||
Page<LabelDO> pageInfo = new Page<>(current, pageSize);
|
||||
IPage<LabelDO> labelDOPage = labelMapper.selectPage(pageInfo, new LambdaQueryWrapper<LabelDO>());
|
||||
|
||||
PageResponse<LabelVO> pageResponse = new PageResponse<>();
|
||||
|
||||
List<LabelVO> labelVOS = labelDOPage.getRecords().stream().map(obj -> {
|
||||
LabelVO labelVO = new LabelVO();
|
||||
BeanUtils.copyProperties(obj, labelVO);
|
||||
return labelVO;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
pageResponse.setPageSize(labelDOPage.getSize());
|
||||
pageResponse.setCurrent(labelDOPage.getCurrent());
|
||||
pageResponse.setTotal(labelDOPage.getTotal());
|
||||
pageResponse.setRecords(labelVOS);
|
||||
return pageResponse;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int delete(Long id) {
|
||||
LambdaQueryWrapper<LabelDO> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(LabelDO::getId, id);
|
||||
return labelMapper.delete(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateById(LabelUpdateRequest labelUpdateReq) {
|
||||
LabelDO labelDO = new LabelDO();
|
||||
|
||||
BeanUtils.copyProperties(labelUpdateReq, labelDO);
|
||||
labelDO.setIsDeleted(0);
|
||||
|
||||
int row = labelMapper.updateById(labelDO);
|
||||
return row;
|
||||
}
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
package net.carbon.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import net.carbon.bean.PageResponse;
|
||||
import net.carbon.mapper.TimelyWarningMapper;
|
||||
import net.carbon.model.po.LabelDO;
|
||||
import net.carbon.model.po.TimelyWarningDO;
|
||||
import net.carbon.model.request.TimelyWarningRequest;
|
||||
import net.carbon.model.vo.LabelVO;
|
||||
import net.carbon.model.vo.TimelyWarningVO;
|
||||
import net.carbon.service.TimelyWarningService;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class TimelyWarningServiceImpl implements TimelyWarningService {
|
||||
|
||||
@Autowired
|
||||
private TimelyWarningMapper timelyWarningMapper;
|
||||
@Override
|
||||
public PageResponse<TimelyWarningVO> getList(Long pageSize, Long page) {
|
||||
Page<TimelyWarningDO> pageInfo = new Page<>(page, pageSize);
|
||||
IPage<TimelyWarningDO> TimelyWarningDOPage = timelyWarningMapper.selectPage(pageInfo, new LambdaQueryWrapper<TimelyWarningDO>());
|
||||
|
||||
PageResponse<TimelyWarningVO> pageResponse = new PageResponse<>();
|
||||
|
||||
List<TimelyWarningVO> TimelyWarningVOS = TimelyWarningDOPage.getRecords().stream().map(obj -> {
|
||||
TimelyWarningVO timelyWarningVO = new TimelyWarningVO();
|
||||
BeanUtils.copyProperties(obj, timelyWarningVO);
|
||||
return timelyWarningVO;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
pageResponse.setPageSize(TimelyWarningDOPage.getSize());
|
||||
pageResponse.setCurrent(TimelyWarningDOPage.getCurrent());
|
||||
pageResponse.setTotal(TimelyWarningDOPage.getTotal());
|
||||
pageResponse.setRecords(TimelyWarningVOS);
|
||||
return pageResponse;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int delete(Long id) {
|
||||
LambdaQueryWrapper<TimelyWarningDO> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(TimelyWarningDO::getId, id);
|
||||
return timelyWarningMapper.delete(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateById(TimelyWarningRequest timelyWarningRequest) {
|
||||
TimelyWarningDO timelyWarningDO = new TimelyWarningDO();
|
||||
BeanUtils.copyProperties(timelyWarningRequest, timelyWarningDO);
|
||||
int row = timelyWarningMapper.updateById(timelyWarningDO);
|
||||
return row;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(TimelyWarningRequest timelyWarningRequest) {
|
||||
TimelyWarningDO timelyWarningDO = new TimelyWarningDO();
|
||||
BeanUtils.copyProperties(timelyWarningRequest, timelyWarningDO);
|
||||
timelyWarningMapper.insert(timelyWarningDO);
|
||||
}
|
||||
}
|
@ -0,0 +1,139 @@
|
||||
package net.carbon.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.carbon.enums.BizCodeEnum;
|
||||
import net.carbon.interceptor.LoginInterceptor;
|
||||
import net.carbon.mapper.UserMapper;
|
||||
import net.carbon.model.LoginUser;
|
||||
import net.carbon.model.po.UserDO;
|
||||
|
||||
import net.carbon.model.vo.UserVO;
|
||||
import net.carbon.model.request.UserRegisterRequest;
|
||||
import net.carbon.model.request.UserLoginRequest;
|
||||
import net.carbon.service.UserService;
|
||||
import net.carbon.utils.CheckUtil;
|
||||
import net.carbon.utils.CommonUtil;
|
||||
import net.carbon.utils.JWTUtil;
|
||||
import net.carbon.utils.JsonData;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author jieyuu
|
||||
* @since 2024-11-23
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements UserService {
|
||||
|
||||
@Autowired
|
||||
private UserMapper userMapper;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = RuntimeException.class, propagation = Propagation.REQUIRED)
|
||||
public JsonData register(UserRegisterRequest registerRequest) {
|
||||
UserDO userDO = new UserDO();
|
||||
|
||||
BeanUtils.copyProperties(registerRequest, userDO);
|
||||
String cryptPwd = CommonUtil.MD5(userDO.getPassword());
|
||||
userDO.setPassword(cryptPwd);
|
||||
|
||||
if (CheckUtil.isUsername(registerRequest.getUsername()) ||
|
||||
CheckUtil.isPassword(registerRequest.getPassword())) {
|
||||
|
||||
//账号唯一性检查
|
||||
if (checkUnique(userDO.getUsername())) {
|
||||
//插入数据库
|
||||
int rows = userMapper.insert(userDO);
|
||||
log.info("rows:{},注册成功{}", rows, userDO.toString());
|
||||
|
||||
return JsonData.buildSuccess();
|
||||
} else {
|
||||
return JsonData.buildResult(BizCodeEnum.ACCOUNT_REPEAT);
|
||||
}
|
||||
} else {
|
||||
return JsonData.buildResult(BizCodeEnum.ILLEGAL_ARGUMENT);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 校验用户账号唯一
|
||||
*
|
||||
* @param username
|
||||
* @return
|
||||
*/
|
||||
private boolean checkUnique(String username) {
|
||||
QueryWrapper queryWrapper = new QueryWrapper<UserDO>().eq("username", username);
|
||||
|
||||
List<UserDO> list = userMapper.selectList(queryWrapper);
|
||||
|
||||
return list.size() > 0 ? false : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户登陆注册
|
||||
* <p>
|
||||
* 判断用户注册情况
|
||||
*
|
||||
* @param loginRequest
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public JsonData login(UserLoginRequest loginRequest) {
|
||||
LambdaQueryWrapper<UserDO> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(UserDO::getUsername, loginRequest.getUsername());
|
||||
|
||||
UserDO userDO = userMapper.selectOne(queryWrapper);
|
||||
|
||||
if (userDO != null) {
|
||||
String cryptPwd = CommonUtil.MD5(loginRequest.getPassword());
|
||||
if (cryptPwd.equals(userDO.getPassword())) {
|
||||
//登陆成功
|
||||
//生成token令牌并且返回
|
||||
LoginUser loginUser = LoginUser.builder().build();
|
||||
BeanUtils.copyProperties(userDO, loginUser);
|
||||
//accessToken
|
||||
String accessToken = JWTUtil.geneJsonWebToken(loginUser);
|
||||
// accessToken过期时间
|
||||
//UUID生成一个token
|
||||
return JsonData.buildSuccess(accessToken);
|
||||
} else {
|
||||
return JsonData.buildResult(BizCodeEnum.ACCOUNT_PWD_ERROR);
|
||||
}
|
||||
|
||||
} else {
|
||||
//未注册
|
||||
//这里选择 账号或密码错误,防止被爆破
|
||||
return JsonData.buildResult(BizCodeEnum.ACCOUNT_PWD_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserVO userinfo() {
|
||||
|
||||
LoginUser loginUser = LoginInterceptor.threadLocal.get();
|
||||
|
||||
LambdaQueryWrapper<UserDO> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(UserDO::getId, loginUser.getId());
|
||||
|
||||
UserDO userDO = userMapper.selectOne(queryWrapper);
|
||||
UserVO userVO = new UserVO();
|
||||
BeanUtils.copyProperties(userDO, userVO);
|
||||
|
||||
return userVO;
|
||||
}
|
||||
}
|
50
server/src/main/java/net/carbon/vo/CarbonTimelyAlertVO.java
Normal file
50
server/src/main/java/net/carbon/vo/CarbonTimelyAlertVO.java
Normal file
@ -0,0 +1,50 @@
|
||||
package net.carbon.vo;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author jieyuu
|
||||
* @since 2024-12-29
|
||||
*/
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class CarbonTimelyAlertVO {
|
||||
private String city;
|
||||
|
||||
private BigDecimal wastewaterDischargeTotal;
|
||||
|
||||
private BigDecimal airQualityAchievementRate;
|
||||
|
||||
private BigDecimal gdpElectricityConsumption;
|
||||
|
||||
private BigDecimal wasteResourceIndustryValue;
|
||||
|
||||
private BigDecimal forestCoverageRate;
|
||||
|
||||
private BigDecimal ecologicalIndex;
|
||||
|
||||
private BigDecimal importExportTotal;
|
||||
|
||||
private Integer foreignInvestmentEnterprises;
|
||||
|
||||
private BigDecimal tourismIncome;
|
||||
|
||||
private Integer overnightTourists;
|
||||
|
||||
private BigDecimal publicManagementDensity;
|
||||
|
||||
private BigDecimal perCapitaServiceFunds;
|
||||
|
||||
private BigDecimal averageAnnualSalary;
|
||||
|
||||
private BigDecimal urbanPerCapitaIncome;
|
||||
|
||||
}
|
42
server/src/main/java/net/carbon/vo/CarbonVO.java
Normal file
42
server/src/main/java/net/carbon/vo/CarbonVO.java
Normal file
@ -0,0 +1,42 @@
|
||||
package net.carbon.vo;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author jieyuu
|
||||
* @since 2024-12-29
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class CarbonVO {
|
||||
|
||||
private String city;
|
||||
|
||||
private BigDecimal wastewaterDischargeTotal;
|
||||
|
||||
private BigDecimal airQualityAchievementRate;
|
||||
|
||||
private BigDecimal gdpElectricityConsumption;
|
||||
|
||||
private BigDecimal wasteResourceIndustryValue;
|
||||
|
||||
private BigDecimal forestCoverageRate;
|
||||
|
||||
private BigDecimal ecologicalIndex;
|
||||
|
||||
private BigDecimal importExportTotal;
|
||||
|
||||
private Integer foreignInvestmentEnterprises;
|
||||
|
||||
}
|
34
server/src/main/resources/application.yml
Normal file
34
server/src/main/resources/application.yml
Normal file
@ -0,0 +1,34 @@
|
||||
server:
|
||||
port: 8089
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: 双碳
|
||||
datasource:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://106.52.88.120:3306/demo?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
|
||||
username: root
|
||||
password: 59ae8683c59fead903132a8d440bd7d9fd4936529d1d6f45f9d41111d7537bdd
|
||||
|
||||
#配置plus打印sql日志
|
||||
mybatis-plus:
|
||||
configuration:
|
||||
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
|
||||
#设置日志级别,ERROR/WARN/INFO/DEBUG,默认是INFO以上才显示
|
||||
logging:
|
||||
level:
|
||||
root: INFO
|
||||
|
||||
|
||||
knife4j:
|
||||
enable: true
|
||||
setting:
|
||||
language: zh_cn
|
||||
springdoc:
|
||||
api-docs:
|
||||
path: /v3/api-docs
|
||||
group-configs:
|
||||
- group: 'default'
|
||||
paths-to-match: '/**'
|
||||
packages-to-scan: net.carbon
|
30
server/src/main/resources/mapper/CarbonEmissionMapper.xml
Normal file
30
server/src/main/resources/mapper/CarbonEmissionMapper.xml
Normal file
@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="net.carbon.mapper.CarbonEmissionMapper">
|
||||
|
||||
<!-- 通用查询映射结果 -->
|
||||
<resultMap id="BaseResultMap" type="net.carbon.model.po.CarbonEmissionDO">
|
||||
<id column="id" property="id" />
|
||||
<result column="city" property="city" />
|
||||
<result column="wastewater_discharge_total" property="wastewaterDischargeTotal" />
|
||||
<result column="air_quality_achievement_rate" property="airQualityAchievementRate" />
|
||||
<result column="gdp_electricity_consumption" property="gdpElectricityConsumption" />
|
||||
<result column="waste_resource_industry_value" property="wasteResourceIndustryValue" />
|
||||
<result column="forest_coverage_rate" property="forestCoverageRate" />
|
||||
<result column="ecological_index" property="ecologicalIndex" />
|
||||
<result column="import_export_total" property="importExportTotal" />
|
||||
<result column="foreign_investment_enterprises" property="foreignInvestmentEnterprises" />
|
||||
<result column="tourism_income" property="tourismIncome" />
|
||||
<result column="overnight_tourists" property="overnightTourists" />
|
||||
<result column="public_management_density" property="publicManagementDensity" />
|
||||
<result column="per_capita_service_funds" property="perCapitaServiceFunds" />
|
||||
<result column="average_annual_salary" property="averageAnnualSalary" />
|
||||
<result column="urban_per_capita_income" property="urbanPerCapitaIncome" />
|
||||
</resultMap>
|
||||
|
||||
<!-- 通用查询结果列 -->
|
||||
<sql id="Base_Column_List">
|
||||
id, city, wastewater_discharge_total, air_quality_achievement_rate, gdp_electricity_consumption, waste_resource_industry_value, forest_coverage_rate, ecological_index, import_export_total, foreign_investment_enterprises, tourism_income, overnight_tourists, public_management_density, per_capita_service_funds, average_annual_salary, urban_per_capita_income
|
||||
</sql>
|
||||
|
||||
</mapper>
|
6
server/src/main/resources/mapper/EconomicsMapper.xml
Normal file
6
server/src/main/resources/mapper/EconomicsMapper.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="net.carbon.mapper.EconomicsMapper">
|
||||
|
||||
|
||||
</mapper>
|
7
server/src/main/resources/mapper/LabelMapper.xml
Normal file
7
server/src/main/resources/mapper/LabelMapper.xml
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="net.carbon.mapper.LabelMapper">
|
||||
|
||||
|
||||
|
||||
</mapper>
|
7
server/src/main/resources/mapper/TimelyWarningMapper.xml
Normal file
7
server/src/main/resources/mapper/TimelyWarningMapper.xml
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="net.carbon.mapper.TimelyWarningMapper">
|
||||
|
||||
|
||||
|
||||
</mapper>
|
27
server/src/main/resources/mapper/UserMapper.xml
Normal file
27
server/src/main/resources/mapper/UserMapper.xml
Normal file
@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="net.carbon.mapper.UserMapper">
|
||||
|
||||
<!-- 通用查询映射结果 -->
|
||||
<resultMap id="BaseResultMap" type="net.carbon.model.po.UserDO">
|
||||
<id column="id" property="id"/>
|
||||
<result column="username" property="username"/>
|
||||
<result column="password" property="password"/>
|
||||
<result column="avatar" property="avatar"/>
|
||||
<result column="role" property="role"/>
|
||||
<result column="description" property="description"/>
|
||||
<result column="name" property="name"/>
|
||||
<result column="phone" property="phone"/>
|
||||
<result column="address" property="address"/>
|
||||
<result column="creationTime" property="creationTime"/>
|
||||
<result column="updateTime" property="updateTime"/>
|
||||
<result column="is_delete" property="isDelete"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 通用查询结果列 -->
|
||||
<sql id="Base_Column_List">
|
||||
id
|
||||
, username, password, avatar, role, description, name, phone, address, creationTime, updateTime, is_delete
|
||||
</sql>
|
||||
|
||||
</mapper>
|
122
server/src/test/java/biz/MyBatisPlusGenerator.java
Normal file
122
server/src/test/java/biz/MyBatisPlusGenerator.java
Normal file
@ -0,0 +1,122 @@
|
||||
package biz;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.DbType;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.generator.AutoGenerator;
|
||||
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
|
||||
import com.baomidou.mybatisplus.generator.config.*;
|
||||
import com.baomidou.mybatisplus.generator.config.rules.DateType;
|
||||
import com.baomidou.mybatisplus.generator.config.rules.DbColumnType;
|
||||
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
|
||||
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
|
||||
|
||||
import java.nio.file.Paths;
|
||||
import java.sql.Types;
|
||||
import java.util.Collections;
|
||||
|
||||
public class MyBatisPlusGenerator {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// //1. 全局配置
|
||||
// GlobalConfig config = new GlobalConfig();
|
||||
// // 是否支持AR模式
|
||||
// config.setActiveRecord(true)
|
||||
// // 作者
|
||||
// .setAuthor("jieyuu")
|
||||
// // 生成路径,最好使用绝对路径,window路径是不一样的
|
||||
// .setOutputDir("D:\\workspace\\project\\CarbonNeutrality\\server\\src\\test\\temp")
|
||||
// // 文件覆盖
|
||||
// .setFileOverride(true)
|
||||
// // 主键策略
|
||||
// .setIdType(IdType.AUTO)
|
||||
//
|
||||
// .setDateType(DateType.ONLY_DATE)
|
||||
// // 设置生成的service接口的名字的首字母是否为I,默认Service是以I开头的
|
||||
// .setServiceName("%sService")
|
||||
//
|
||||
// //实体类结尾名称
|
||||
// .setEntityName("%sDO")
|
||||
//
|
||||
// //生成基本的resultMap
|
||||
// .setBaseResultMap(true)
|
||||
//
|
||||
// //不使用AR模式
|
||||
// .setActiveRecord(false)
|
||||
//
|
||||
// //生成基本的SQL片段
|
||||
// .setBaseColumnList(true);
|
||||
//
|
||||
// //2. 数据源配置
|
||||
// DataSourceConfig dsConfig = new DataSourceConfig();
|
||||
// // 设置数据库类型
|
||||
// dsConfig.setDbType(DbType.MYSQL)
|
||||
// .setDriverName("com.mysql.cj.jdbc.Driver")
|
||||
// .setUrl("jdbc:mysql://106.52.88.120:3306/demo?useSSL=false")
|
||||
// .setUsername("root")
|
||||
// .setPassword("59ae8683c59fead903132a8d440bd7d9fd4936529d1d6f45f9d41111d7537bdd");
|
||||
//
|
||||
// //3. 策略配置globalConfiguration中
|
||||
// StrategyConfig stConfig = new StrategyConfig();
|
||||
//
|
||||
// //全局大写命名
|
||||
// stConfig.setCapitalMode(true)
|
||||
// // 数据库表映射到实体的命名策略
|
||||
// .setNaming(NamingStrategy.underline_to_camel)
|
||||
//
|
||||
// //使用lombok
|
||||
// .setEntityLombokModel(true)
|
||||
//
|
||||
// //使用restcontroller注解
|
||||
// .setRestControllerStyle(true)
|
||||
//
|
||||
// // 生成的表, 支持多表一起生成,以数组形式填写
|
||||
// .setInclude("label");
|
||||
//
|
||||
// //4. 包名策略配置
|
||||
// PackageConfig pkConfig = new PackageConfig();
|
||||
// pkConfig.setParent("net.carbon")
|
||||
// .setMapper("mapper")
|
||||
// .setService("service")
|
||||
// .setController("controller")
|
||||
// .setEntity("model")
|
||||
// .setXml("mapper");
|
||||
//
|
||||
// //5. 整合配置
|
||||
// AutoGenerator ag = new AutoGenerator();
|
||||
// ag.setGlobalConfig(config)
|
||||
// .setDataSource(dsConfig)
|
||||
// .setStrategy(stConfig)
|
||||
// .setPackageInfo(pkConfig);
|
||||
//
|
||||
// //6. 执行操作
|
||||
// ag.execute();
|
||||
|
||||
// 使用 FastAutoGenerator 快速配置代码生成器
|
||||
FastAutoGenerator.create("jdbc:mysql://106.52.88.120:3306/demo?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai", "root", "59ae8683c59fead903132a8d440bd7d9fd4936529d1d6f45f9d41111d7537bdd")
|
||||
.globalConfig(builder -> {
|
||||
builder.author("jieyuu") // 设置作者
|
||||
.outputDir("D:\\workspace\\project\\CarbonNeutrality\\server\\src\\test\\java"); // 输出目录
|
||||
})
|
||||
.packageConfig(builder -> {
|
||||
builder.parent("net.carbon") // 设置父包名
|
||||
.entity("model") // 设置实体类包名
|
||||
.controller("controller")
|
||||
.mapper("mapper") // 设置 Mapper 接口包名
|
||||
.service("service") // 设置 Service 接口包名
|
||||
.serviceImpl("service.impl") // 设置 Service 实现类包名
|
||||
.xml("mappers"); // 设置 Mapper XML 文件包名
|
||||
})
|
||||
.strategyConfig(builder -> {
|
||||
builder.addInclude("user", "label" , "economics") // 设置需要生成的表名
|
||||
.entityBuilder()
|
||||
.enableLombok() // 启用 Lombok
|
||||
.enableTableFieldAnnotation() // 启用字段注解
|
||||
.controllerBuilder()
|
||||
.enableRestStyle(); // 启用 REST 风格
|
||||
})
|
||||
.templateEngine(new FreemarkerTemplateEngine()) // 使用 Freemarker 模板引擎
|
||||
.execute(); // 执行生成
|
||||
|
||||
System.out.println("======= Done 相关代码生成完毕 ========");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user