refactor(server): 重构 server模块代码
- 更新了多个类的包名,使其更加规范 - 新增了 Economics 和 Label 相关的 mapper、controller 和 model 类 - 更新了 User相关的 mapper 和 model 类- 新增了 Economics 和 Label 的更新请求类 - 新增了 Economics 的 VO 类 - 更新了 LoginInterceptor 中的导入信息 - 新增了 EconomicsController 和 LabelController 控制器类 - 更新了 UserController 中的方法
This commit is contained in:
parent
3b70bf45cc
commit
a039e0d2b9
@ -13,7 +13,7 @@
|
||||
</set>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="17" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
@ -16,6 +16,11 @@
|
||||
<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>
|
||||
@ -24,14 +29,9 @@
|
||||
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
<artifactId>mybatis-plus-spring-boot3-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!--swagger ui接口文档依赖-->
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
|
||||
<dependency>
|
||||
@ -63,11 +63,25 @@
|
||||
<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>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
|
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));
|
||||
}
|
||||
}
|
@ -27,4 +27,5 @@ public class MybatisPlusPageConfig {
|
||||
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"));
|
||||
}
|
||||
}
|
@ -1,118 +0,0 @@
|
||||
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 {
|
||||
//}
|
@ -12,8 +12,8 @@ import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@ -40,8 +40,6 @@ public class LoginInterceptor implements HandlerInterceptor {
|
||||
long userId = Long.valueOf(claims.get("id").toString());
|
||||
String name = (String) claims.get("username");
|
||||
|
||||
// LoginUser loginUser = new LoginUser();
|
||||
|
||||
LoginUser loginUser = LoginUser.builder()
|
||||
.id(userId)
|
||||
.username(name)
|
||||
|
@ -1,23 +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;
|
||||
|
||||
}
|
||||
|
@ -3,8 +3,8 @@ package net.carbon.utils;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.net.InetAddress;
|
||||
|
74
pom.xml
74
pom.xml
@ -15,20 +15,23 @@
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<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>2.3.3.RELEASE</spring.boot.version>
|
||||
<mybatisplus.boot.starter.version>3.4.0</mybatisplus.boot.starter.version>
|
||||
<lombok.version>1.18.16</lombok.version>
|
||||
<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>
|
||||
@ -51,10 +54,23 @@
|
||||
<!--mybatis plus和springboot整合-->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
<version>${mybatisplus.boot.starter.version}</version>
|
||||
<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>
|
||||
@ -80,11 +96,11 @@
|
||||
</dependency>
|
||||
|
||||
<!--接口文档依赖-->
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-boot-starter</artifactId>
|
||||
<version>${springfox.boot.starter.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>
|
||||
@ -112,11 +128,33 @@
|
||||
<version>${fastjson.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!--swagger ui接口文档依赖-->
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-boot-starter</artifactId>
|
||||
<version>${springfox.boot.starter.version}</version>
|
||||
<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>
|
||||
@ -136,6 +174,8 @@
|
||||
<checksumPolicy>fail</checksumPolicy>
|
||||
</snapshots>
|
||||
</repository>
|
||||
|
||||
|
||||
</repositories>
|
||||
|
||||
|
||||
|
@ -13,8 +13,8 @@
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
@ -37,7 +37,11 @@
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-generator</artifactId>
|
||||
<version>3.4.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-jsqlparser</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- velocity -->
|
||||
@ -51,6 +55,16 @@
|
||||
<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>
|
||||
@ -72,7 +86,16 @@
|
||||
</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>
|
@ -17,7 +17,7 @@ public class InterceptorConfig implements WebMvcConfigurer {
|
||||
//拦截的路径
|
||||
.addPathPatterns("/api/user/*/**", "/api/carbon/*/**")
|
||||
//放行的路径
|
||||
.excludePathPatterns("/api/user/*/register", "/api/user/*/login");
|
||||
.excludePathPatterns("/api/user/*/register", "/api/user/*/login", "api/label/*/**");
|
||||
|
||||
WebMvcConfigurer.super.addInterceptors(registry);
|
||||
}
|
||||
|
@ -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("删除失败");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,20 +1,14 @@
|
||||
|
||||
|
||||
// 用户登录demo
|
||||
package net.carbon.controller;
|
||||
|
||||
//import io.swagger.annotations.ApiParam;
|
||||
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import net.carbon.request.UserRegisterRequest;
|
||||
import net.carbon.request.UserLoginRequest;
|
||||
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.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/user/v1")
|
||||
@ -29,11 +23,8 @@ public class UserController {
|
||||
* @param registerRequest
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation("用户注册")
|
||||
@PostMapping(value = "register")
|
||||
public JsonData register(
|
||||
@ApiParam(value = "用户注册对象", required = true)
|
||||
@RequestBody UserRegisterRequest registerRequest) {
|
||||
public JsonData register(@RequestBody UserRegisterRequest registerRequest) {
|
||||
JsonData jsonData = userService.register(registerRequest);
|
||||
|
||||
return jsonData;
|
||||
@ -46,12 +37,24 @@ public class UserController {
|
||||
* @return
|
||||
*/
|
||||
|
||||
@ApiOperation("用户登录")
|
||||
// @ApiOperation("用户登录")
|
||||
@PostMapping("login")
|
||||
public JsonData userLogin(@ApiParam("用户登陆对象") @RequestBody UserLoginRequest loginRequest) {
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
@ -1,7 +1,8 @@
|
||||
package net.carbon.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import net.carbon.model.CarbonEmissionDO;
|
||||
import net.carbon.model.po.CarbonEmissionDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@ -11,6 +12,7 @@ import net.carbon.model.CarbonEmissionDO;
|
||||
* @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> {
|
||||
|
||||
}
|
@ -1,7 +1,8 @@
|
||||
package net.carbon.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import net.carbon.model.UserDO;
|
||||
import net.carbon.model.po.UserDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
|
||||
/**
|
||||
@ -12,6 +13,7 @@ import net.carbon.model.UserDO;
|
||||
* @author jieyuu
|
||||
* @since 2024-11-23
|
||||
*/
|
||||
@Mapper
|
||||
public interface UserMapper extends BaseMapper<UserDO> {
|
||||
|
||||
}
|
||||
|
@ -1,31 +0,0 @@
|
||||
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;
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package net.carbon.model;
|
||||
package net.carbon.model.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
@ -25,7 +25,7 @@ public class CarbonEmissionDO implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Integer id;
|
||||
private Long id;
|
||||
|
||||
private String city;
|
||||
|
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;
|
||||
}
|
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,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;
|
||||
}
|
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;
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
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;
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
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;
|
||||
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
package net.carbon.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import net.carbon.model.CarbonEmissionDO;
|
||||
import net.carbon.model.po.CarbonEmissionDO;
|
||||
import net.carbon.vo.CarbonTimelyAlertVO;
|
||||
import net.carbon.vo.CarbonVO;
|
||||
|
||||
@ -16,7 +16,7 @@ import net.carbon.vo.CarbonVO;
|
||||
*/
|
||||
public interface CarbonEmissionService extends IService<CarbonEmissionDO> {
|
||||
|
||||
public CarbonTimelyAlertVO timelyAlert(String city);
|
||||
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);
|
||||
|
||||
}
|
@ -1,10 +1,11 @@
|
||||
package net.carbon.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import net.carbon.model.UserDO;
|
||||
import net.carbon.model.po.UserDO;
|
||||
|
||||
import net.carbon.request.UserRegisterRequest;
|
||||
import net.carbon.request.UserLoginRequest;
|
||||
import net.carbon.model.vo.UserVO;
|
||||
import net.carbon.model.request.UserRegisterRequest;
|
||||
import net.carbon.model.request.UserLoginRequest;
|
||||
import net.carbon.utils.JsonData;
|
||||
|
||||
|
||||
@ -33,4 +34,6 @@ public interface UserService extends IService<UserDO> {
|
||||
* @return
|
||||
*/
|
||||
JsonData login(UserLoginRequest loginRequest);
|
||||
|
||||
UserVO userinfo();
|
||||
}
|
||||
|
@ -1,10 +1,9 @@
|
||||
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 net.carbon.mapper.CarbonEmissionMapper;
|
||||
import net.carbon.model.CarbonEmissionDO;
|
||||
import net.carbon.model.po.CarbonEmissionDO;
|
||||
import net.carbon.service.CarbonEmissionService;
|
||||
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -1,22 +1,24 @@
|
||||
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.UserDO;
|
||||
import net.carbon.model.po.UserDO;
|
||||
|
||||
import net.carbon.request.UserRegisterRequest;
|
||||
import net.carbon.request.UserLoginRequest;
|
||||
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.apache.commons.codec.digest.Md5Crypt;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -92,12 +94,12 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
*/
|
||||
@Override
|
||||
public JsonData login(UserLoginRequest loginRequest) {
|
||||
List<UserDO> userDOList = userMapper.selectList(new QueryWrapper<UserDO>().eq("username", loginRequest.getUsername()));
|
||||
LambdaQueryWrapper<UserDO> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(UserDO::getUsername, loginRequest.getUsername());
|
||||
|
||||
if (userDOList != null && userDOList.size() == 1) {
|
||||
//已经注册
|
||||
UserDO userDO = userDOList.get(0);
|
||||
UserDO userDO = userMapper.selectOne(queryWrapper);
|
||||
|
||||
if (userDO != null) {
|
||||
String cryptPwd = CommonUtil.MD5(loginRequest.getPassword());
|
||||
if (cryptPwd.equals(userDO.getPassword())) {
|
||||
//登陆成功
|
||||
@ -119,4 +121,19 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -2,9 +2,11 @@ server:
|
||||
port: 8089
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: 双碳
|
||||
datasource:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://localhost:3306/demo?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
|
||||
url: jdbc:mysql://106.52.88.120:3306/demo?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
|
||||
username: root
|
||||
password: 59ae8683c59fead903132a8d440bd7d9fd4936529d1d6f45f9d41111d7537bdd
|
||||
|
||||
@ -17,3 +19,16 @@ mybatis-plus:
|
||||
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
|
@ -3,7 +3,7 @@
|
||||
<mapper namespace="net.carbon.mapper.CarbonEmissionMapper">
|
||||
|
||||
<!-- 通用查询映射结果 -->
|
||||
<resultMap id="BaseResultMap" type="net.carbon.model.CarbonEmissionDO">
|
||||
<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" />
|
||||
|
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>
|
@ -3,16 +3,25 @@
|
||||
<mapper namespace="net.carbon.mapper.UserMapper">
|
||||
|
||||
<!-- 通用查询映射结果 -->
|
||||
<resultMap id="BaseResultMap" type="net.carbon.model.UserDO">
|
||||
<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
|
||||
, username, password, avatar, role, description, name, phone, address, creationTime, updateTime, is_delete
|
||||
</sql>
|
||||
|
||||
</mapper>
|
||||
|
@ -1,91 +1,122 @@
|
||||
package net.jieyuu.db;
|
||||
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.config.DataSourceConfig;
|
||||
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
|
||||
import com.baomidou.mybatisplus.generator.config.PackageConfig;
|
||||
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
|
||||
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\\main\\java")
|
||||
// 文件覆盖
|
||||
.setFileOverride(true)
|
||||
// 主键策略
|
||||
.setIdType(IdType.AUTO)
|
||||
// //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();
|
||||
|
||||
.setDateType(DateType.ONLY_DATE)
|
||||
// 设置生成的service接口的名字的首字母是否为I,默认Service是以I开头的
|
||||
.setServiceName("%sService")
|
||||
// 使用 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(); // 执行生成
|
||||
|
||||
//实体类结尾名称
|
||||
.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("carbon_emission");
|
||||
|
||||
//4. 包名策略配置
|
||||
PackageConfig pkConfig = new PackageConfig();
|
||||
pkConfig.setParent("net.jieyuu")
|
||||
.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();
|
||||
System.out.println("======= Done 相关代码生成完毕 ========");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user