feat(): 初始化项目

master
DongZeLiang 2024-05-23 18:02:32 +08:00
commit e02fa34205
30 changed files with 1444 additions and 0 deletions

33
.gitignore vendored 100644
View File

@ -0,0 +1,33 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### IntelliJ IDEA ###
/.idea
### 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

View File

@ -0,0 +1,109 @@
<?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>com.muyu</groupId>
<artifactId>cloud</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>cloud-common</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- bootstrap 启动器 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
<!-- SpringCloud Alibaba Nacos -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<!-- SpringCloud Alibaba Nacos Config -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<!-- SpringCloud Alibaba Sentinel -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
<!-- 负载均衡-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
</dependency>
<!-- SpringCloud Openfeign -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<!-- JWT -->
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.9.1</version>
</dependency>
<!-- Alibaba Fastjson -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.80</version>
</dependency>
<!-- SpringBoot Boot Redis -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!-- Druid -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.2.8</version>
</dependency>
<!-- Mysql Connector -->
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
</dependency>
<!-- Mybatis 依赖配置 -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.2.2</version>
</dependency>
<!-- Pagehelper -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.4.1</version>
</dependency>
<!-- Hibernate Validator -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<!-- Apache Lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<!-- lombok依赖 -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,18 @@
package com.muyu.common.constant;
/**
* @description:
* @author DongZl
*/
public class Constants {
/**
*
*/
public static final Integer SUCCESS = 200;
public static final String SUCCESS_MSG = "操作成功";
/**
*
*/
public static final Integer ERROR = 500;
public static final String ERROR_MSG = "操作异常";
}

View File

@ -0,0 +1,27 @@
package com.muyu.common.constant;
/**
* @author DongZl
* @description: Jwt
*/
public class JwtConstants {
/**
* ID
*/
public static final String DETAILS_USER_ID = "user_id";
/**
*
*/
public static final String DETAILS_USERNAME = "username";
/**
*
*/
public static final String USER_KEY = "user_key";
/**
*
*/
public final static String SECRET = "abcdefghijklmnopqrstuvwxyz";
}

View File

@ -0,0 +1,24 @@
package com.muyu.common.constant;
/**
* @author DongZl
* @description:
*/
public class TokenConstants {
/**
* 720
*/
public final static long EXPIRATION = 720;
/**
* 120
*/
public final static long REFRESH_TIME = 120;
/**
*
*/
public final static String LOGIN_TOKEN_KEY = "login_tokens:";
/**
* token
*/
public static final String TOKEN = "token";
}

View File

@ -0,0 +1,34 @@
package com.muyu.common.result;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
/**
* @author DongZl
* @description:
*/
@Data
public class PageResult<T> implements Serializable {
/**
*
*/
private long total;
/**
*
*/
private List<T> list;
public PageResult() {
}
public PageResult(long total, List<T> list) {
this.total = total;
this.list = list;
}
public static <T> PageResult<T> toPageResult(long total, List<T> list){
return new PageResult(total , list);
}
public static <T> Result<PageResult<T>> toResult(long total, List<T> list){
return Result.success(PageResult.toPageResult(total,list));
}
}

View File

@ -0,0 +1,53 @@
package com.muyu.common.result;
import com.muyu.common.constant.Constants;
import lombok.Data;
import java.io.Serializable;
/**
* @description:
* @author DongZl
*/
@Data
public class Result<T> implements Serializable {
private static final long serialVersionUID = 1L;
/** 成功 */
public static final int SUCCESS = Constants.SUCCESS;
/** 失败 */
public static final int FAIL = Constants.ERROR;
private int code;
private String msg;
private T data;
public static <T> Result<T> success() {
return restResult(null, SUCCESS, Constants.SUCCESS_MSG);
}
public static <T> Result<T> success(T data) {
return restResult(data, SUCCESS, Constants.SUCCESS_MSG);
}
public static <T> Result<T> success(T data, String msg) {
return restResult(data, SUCCESS, msg);
}
public static <T> Result<T> error() {
return restResult(null, FAIL, Constants.ERROR_MSG);
}
public static <T> Result<T> error(String msg) {
return restResult(null, FAIL, msg);
}
public static <T> Result<T> error(T data) {
return restResult(data, FAIL, Constants.ERROR_MSG);
}
public static <T> Result<T> error(T data, String msg) {
return restResult(data, FAIL, msg);
}
public static <T> Result<T> error(int code, String msg) {
return restResult(null, code, msg);
}
private static <T> Result<T> restResult(T data, int code, String msg) {
Result<T> apiResult = new Result<>();
apiResult.setCode(code);
apiResult.setData(data);
apiResult.setMsg(msg);
return apiResult;
}
}

View File

@ -0,0 +1,104 @@
package com.muyu.common.utils;
import com.muyu.common.constant.JwtConstants;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import java.util.Map;
/**
* @description: Jwt
* @author DongZl
*/
public class JwtUtils {
public static String secret = JwtConstants.SECRET;
/**
*
*
* @param claims
* @return
*/
public static String createToken(Map<String, Object> claims){
String token = Jwts.builder().setClaims(claims).signWith(SignatureAlgorithm.HS512, secret).compact();
return token;
}
/**
*
*
* @param token
* @return
*/
public static Claims parseToken(String token){
return Jwts.parser().setSigningKey(secret).parseClaimsJws(token).getBody();
}
/**
*
*
* @param token
* @return ID
*/
public static String getUserKey(String token){
Claims claims = parseToken(token);
return getValue(claims, JwtConstants.USER_KEY);
}
/**
*
*
* @param claims
* @return ID
*/
public static String getUserKey(Claims claims){
return getValue(claims, JwtConstants.USER_KEY);
}
/**
* ID
*
* @param token
* @return ID
*/
public static String getUserId(String token){
Claims claims = parseToken(token);
return getValue(claims, JwtConstants.DETAILS_USER_ID);
}
/**
* ID
*
* @param claims
* @return ID
*/
public static String getUserId(Claims claims){
return getValue(claims, JwtConstants.DETAILS_USER_ID);
}
/**
*
*
* @param token
* @return
*/
public static String getUserName(String token){
Claims claims = parseToken(token);
return getValue(claims, JwtConstants.DETAILS_USERNAME);
}
/**
*
*
* @param claims
* @return
*/
public static String getUserName(Claims claims){
return getValue(claims, JwtConstants.DETAILS_USERNAME);
}
/**
*
*
* @param claims
* @param key
* @return
*/
public static String getValue(Claims claims, String key){
Object obj = claims.get(key);
return obj == null ? "" : obj.toString();
}
}

View File

@ -0,0 +1,68 @@
package com.muyu.common.utils;
import org.springframework.util.AntPathMatcher;
import java.util.Collection;
import java.util.List;
/**
* @author DongZl
* @description:
*/
public class StringUtils extends org.apache.commons.lang3.StringUtils {
/**
* *
*
* @param object Object
* @return true false
*/
public static boolean isNull(Object object) {
return object == null;
}
/**
* * Collection ListSetQueue
*
* @param coll Collection
* @return true false
*/
public static boolean isEmpty(Collection<?> coll) {
return isNull(coll) || coll.isEmpty();
}
/**
*
*
* @param str
* @param strs
* @return
*/
public static boolean matches(String str, List<String> strs) {
if (isEmpty(str) || isEmpty(strs)) {
return false;
}
for (String pattern : strs) {
if (isMatch(pattern, str))
{
return true;
}
}
return false;
}
/**
* url:
* ? ;
* * ;
* ** ;
*
* @param pattern
* @param url url
* @return
*/
public static boolean isMatch(String pattern, String url) {
AntPathMatcher matcher = new AntPathMatcher();
return matcher.match(pattern, url);
}
}

View File

@ -0,0 +1,59 @@
<?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>com.muyu</groupId>
<artifactId>cloud</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>cloud-gateway</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- 公共依赖 -->
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-common</artifactId>
</dependency>
<!-- SpringCloud Gateway -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<!-- SpringCloud Alibaba Sentinel Gateway -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-sentinel-gateway</artifactId>
</dependency>
<!-- 引入阿里巴巴sentinel限流 依赖-->
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-spring-cloud-gateway-adapter</artifactId>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,20 @@
package com.muyu;
import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
/**
* @Author: DongZeLiang
* @date: 2024/5/23
* @Description:
* @Version: 1.0
*/
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, DruidDataSourceAutoConfigure.class})
public class CloudGatewayApplication {
public static void main (String[] args) {
SpringApplication.run(CloudGatewayApplication.class, args);
}
}

View File

@ -0,0 +1,71 @@
package com.muyu.config;
import com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayFlowRule;
import com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayRuleManager;
import com.alibaba.csp.sentinel.adapter.gateway.sc.exception.SentinelGatewayBlockExceptionHandler;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.http.codec.ServerCodecConfigurer;
import org.springframework.web.reactive.result.view.ViewResolver;
import javax.annotation.PostConstruct;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* @deprecation:
* @author DongZl
*/
@Configuration
public class GatewaySentinelConfig {
/**
*
*/
private final List<ViewResolver> viewResolvers;
/**
*
*/
private final ServerCodecConfigurer serverCodecConfigurer;
public GatewaySentinelConfig(ObjectProvider<List<ViewResolver>> viewResolversProvider,
ServerCodecConfigurer serverCodecConfigurer) {
this.viewResolvers = viewResolversProvider.getIfAvailable(Collections::emptyList);
this.serverCodecConfigurer = serverCodecConfigurer;
}
/**
* Sentinel
* @return
*/
@Bean
@Order(Ordered.HIGHEST_PRECEDENCE)
public SentinelGatewayBlockExceptionHandler sentinelGatewayBlockExceptionHandler() {
// 给 Spring Cloud Gateway 注册块异常处理程序。
return new SentinelGatewayBlockExceptionHandler(viewResolvers, serverCodecConfigurer);
}
/**
*
*/
@PostConstruct
public void doInit() {
initGatewayRules();
}
/**
*
*/
private void initGatewayRules() {
Set<GatewayFlowRule> rules = new HashSet<>();
rules.add(new GatewayFlowRule("cloud-user")
// 限流阈值
.setCount(1)
// 统计时间窗口,单位是秒,默认是 1 秒
.setIntervalSec(5)
);
//添加到限流规则当中
GatewayRuleManager.loadRules(rules);
}
}

View File

@ -0,0 +1,31 @@
package com.muyu.config;
import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import lombok.extern.log4j.Log4j2;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Configuration;
import java.util.ArrayList;
import java.util.List;
/**
* @description:
* @author DongZl
*/
@Configuration
@RefreshScope
@ConfigurationProperties(prefix = "ignore")
@Data
@Log4j2
public class IgnoreWhiteConfig {
/**
*
*/
private List<String> whites = new ArrayList<>();
public void setWhites(List<String> whites) {
log.info("加载网关路径白名单:{}", JSONObject.toJSONString(whites));
this.whites = whites;
}
}

View File

@ -0,0 +1,73 @@
package com.muyu.utils;
import com.alibaba.fastjson.JSONObject;
import com.muyu.common.result.Result;
import com.muyu.common.utils.StringUtils;
import lombok.extern.log4j.Log4j2;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;
/**
* @author DongZl
* @description:
*/
@Log4j2
public class GatewayUtils {
/**
*
* @param mutate
* @param key
* @param value
*/
public static void addHeader(ServerHttpRequest.Builder mutate, String key, Object value) {
if (StringUtils.isEmpty(key)){
log.warn("添加请求头参数键不可以为空");
return;
}
if (value == null) {
log.warn("添加请求头参数:[{}]值为空",key);
return;
}
String valueStr = value.toString();
mutate.header(key, valueStr);
log.info("添加请求头参数成功 - 键:[{}] , 值:[{}]", key , value);
}
/**
*
* @param mutate
* @param key
*/
public static void removeHeader(ServerHttpRequest.Builder mutate, String key) {
if (StringUtils.isEmpty(key)){
log.warn("删除请求头参数键不可以为空");
return;
}
mutate.headers(httpHeaders -> httpHeaders.remove(key)).build();
log.info("删除请求头参数 - 键:[{}]",key);
}
/**
*
* @param exchange
* @param msg
* @return
*/
public static Mono<Void> errorResponse(ServerWebExchange exchange, String msg) {
ServerHttpResponse response = exchange.getResponse();
//设置HTTP响应头状态
response.setStatusCode(HttpStatus.OK);
//设置HTTP响应头文本格式
response.getHeaders().add(HttpHeaders.CONTENT_TYPE, "application/json");
//定义响应内容
Result<?> result = Result.error(msg);
String resultJson = JSONObject.toJSONString(result);
log.error("[鉴权异常处理]请求路径:[{}],异常信息:[{}],响应结果:[{}]", exchange.getRequest().getPath(), msg, resultJson);
DataBuffer dataBuffer = response.bufferFactory().wrap(resultJson.getBytes());
//进行响应
return response.writeWith(Mono.just(dataBuffer));
}
}

View File

@ -0,0 +1,31 @@
# 指定项目启动的端口号
server:
port: 8080
# 配置nacos的地址
nacos:
server-addr: 47.92.86.60:8848
spring:
application:
# 配置项目的名称
name: cloud-gateway
profiles:
# 指定项目启动使用的环境配置文件
active: dev
cloud:
nacos:
discovery:
# nacos 注册中心的地址
server-addr: ${nacos.server-addr}
config:
# nacos 配置中心的地址
server-addr: ${nacos.server-addr}
# nacos 配置中心使用的文件后缀(格式)
file-extension: yml
# nacos 配置中心的共享配置文件
shared-configs:
# 程序公共配置文件
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
# 程序Redis公共配置文件
- application-redis-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}

View File

@ -0,0 +1,26 @@
<?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>com.muyu</groupId>
<artifactId>modules</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>cloud-system</artifactId>
<packaging>pom</packaging>
<modules>
<module>system-common</module>
<module>system-remote</module>
<module>system-server</module>
</modules>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>

View File

@ -0,0 +1,28 @@
<?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>com.muyu</groupId>
<artifactId>cloud-system</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>system-common</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- 系统公共依赖包 -->
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-common</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,48 @@
package com.muyu.cloud.system.domain;
import com.muyu.cloud.system.domain.request.BookInfoSaveReq;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.math.BigDecimal;
/**
* @Author: DongZeLiang
* @date: 2024/5/23
* @Description:
* @Version: 1.0
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class BookInfo {
/**
*
*/
private Integer id;
/**
*
*/
private String name;
/**
*
*/
private String author;
/**
*
*/
private BigDecimal price;
public static BookInfo saveReqBuild(BookInfoSaveReq bookInfoSaveReq){
return BookInfo.builder()
.name(bookInfoSaveReq.getName())
.author(bookInfoSaveReq.getAuthor())
.price(bookInfoSaveReq.getPrice())
.build();
}
}

View File

@ -0,0 +1,39 @@
package com.muyu.cloud.system.domain.request;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import java.math.BigDecimal;
/**
* @Author: DongZeLiang
* @date: 2024/5/23
* @Description:
* @Version: 1.0
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class BookInfoSaveReq {
/**
*
*/
@NotBlank(message = "书籍名称不可为空")
private String name;
/**
*
*/
@NotBlank(message = "作者名称不可为空")
private String author;
/**
*
*/
@Min(value = 0L, message = "价格最小不可小于0元")
private BigDecimal price;
}

View File

@ -0,0 +1,27 @@
<?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>com.muyu</groupId>
<artifactId>cloud-system</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>system-remote</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- 系统服务公共依赖 -->
<dependency>
<groupId>com.muyu</groupId>
<artifactId>system-common</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,32 @@
<?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>com.muyu</groupId>
<artifactId>cloud-system</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>system-server</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- 系统公共 依赖 -->
<dependency>
<groupId>com.muyu</groupId>
<artifactId>system-common</artifactId>
</dependency>
<!-- SpringBoot Web-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,20 @@
package com.muyu.cloud.system;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
/**
* @Author: DongZeLiang
* @date: 2024/5/23
* @Description:
* @Version: 1.0
*/
@SpringBootApplication
@EnableFeignClients( basePackages = {"com.muyu.**"})
public class CloudSystemApplication {
public static void main(String[] args) {
SpringApplication.run(CloudSystemApplication.class, args);
}
}

View File

@ -0,0 +1,91 @@
package com.muyu.cloud.system.controller;
import com.muyu.cloud.system.domain.BookInfo;
import com.muyu.cloud.system.domain.request.BookInfoSaveReq;
import com.muyu.cloud.system.service.BookInfoService;
import com.muyu.common.result.Result;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* @Author: DongZeLiang
* @date: 2024/5/23
* @Description:
* @Version: 1.0
*/
@RestController
@AllArgsConstructor
@RequestMapping("/book-info")
public class BookInfoController {
/**
*
*/
private final BookInfoService bookInfoService;
/**
*
* @param bookInfoSaveReq
*/
@PostMapping
public Result<String> save (@RequestBody @Validated BookInfoSaveReq bookInfoSaveReq) {
bookInfoService.save(BookInfo.saveReqBuild(bookInfoSaveReq));
return Result.success();
}
/**
* ID
*
* @param bookId ID
*
* @return
*/
@GetMapping("/{bookId}")
public Result<BookInfo> selectByBookId (@PathVariable("bookId") Integer bookId) {
BookInfo bookInfo = bookInfoService.selectByBookId(bookId);
return Result.success(bookInfo);
}
/**
*
*
* @param bookInfo
*
* @return
*/
@PostMapping("/list")
public Result<List<BookInfo>> list (@RequestBody BookInfo bookInfo) {
List<BookInfo> bookInfoList = bookInfoService.list(bookInfo);
return Result.success(bookInfoList);
}
/**
* ID
*
* @param bookInfo
*
* @return
*/
@PutMapping()
public Result<String> updateByBookId (BookInfo bookInfo) {
bookInfoService.updateByBookId(bookInfo);
return Result.success();
}
/**
* ID
*
* @param bookId ID
*
* @return
*/
@DeleteMapping("/{bookId}")
public Result<String> deleteByBookId (@PathVariable("bookId") Integer bookId) {
bookInfoService.deleteByBookId(bookId);
return Result.success();
}
}

View File

@ -0,0 +1,53 @@
package com.muyu.cloud.system.mapper;
import com.muyu.cloud.system.domain.BookInfo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* @Author: DongZeLiang
* @date: 2024/5/23
* @Description:
* @Version: 1.0
*/
@Mapper
public interface BookInfoMapper {
/**
*
* @param bookInfo
* @return ID
*/
int insert(BookInfo bookInfo);
/**
* ID
* @param bookId ID
* @return
*/
BookInfo selectByBookId(@Param("bookId") Integer bookId);
/**
*
* @param bookInfo
* @return
*/
List<BookInfo> list(BookInfo bookInfo);
/**
* ID
* @param bookInfo
* @return
*/
int updateByBookId(BookInfo bookInfo);
/**
* ID
* @param bookId ID
* @return
*/
int deleteByBookId(@Param("bookId") Integer bookId);
}

View File

@ -0,0 +1,50 @@
package com.muyu.cloud.system.service;
import com.muyu.cloud.system.domain.BookInfo;
import java.util.List;
/**
* @Author: DongZeLiang
* @date: 2024/5/23
* @Description:
* @Version: 1.0
*/
public interface BookInfoService {
/**
*
* @param bookInfo
* @return ID
*/
int save (BookInfo bookInfo);
/**
* ID
* @param bookId ID
* @return
*/
BookInfo selectByBookId(Integer bookId);
/**
*
* @param bookInfo
* @return
*/
List<BookInfo> list(BookInfo bookInfo);
/**
* ID
* @param bookInfo
* @return
*/
int updateByBookId(BookInfo bookInfo);
/**
* ID
* @param bookId ID
* @return
*/
int deleteByBookId(Integer bookId);
}

View File

@ -0,0 +1,86 @@
package com.muyu.cloud.system.service.impl;
import com.muyu.cloud.system.domain.BookInfo;
import com.muyu.cloud.system.mapper.BookInfoMapper;
import com.muyu.cloud.system.service.BookInfoService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @Author: DongZeLiang
* @date: 2024/5/23
* @Description:
* @Version: 1.0
*/
@Service
@AllArgsConstructor
public class BookInfoServiceImpl implements BookInfoService {
/**
*
*/
private final BookInfoMapper bookInfoMapper;
/**
*
*
* @param bookInfo
*
* @return ID
*/
@Override
public int save (BookInfo bookInfo) {
return bookInfoMapper.insert(bookInfo);
}
/**
* ID
*
* @param bookId ID
*
* @return
*/
@Override
public BookInfo selectByBookId (Integer bookId) {
return bookInfoMapper.selectByBookId(bookId);
}
/**
*
*
* @param bookInfo
*
* @return
*/
@Override
public List<BookInfo> list (BookInfo bookInfo) {
return bookInfoMapper.list(bookInfo);
}
/**
* ID
*
* @param bookInfo
*
* @return
*/
@Override
public int updateByBookId (BookInfo bookInfo) {
return bookInfoMapper.updateByBookId(bookInfo);
}
/**
* ID
*
* @param bookId ID
*
* @return
*/
@Override
public int deleteByBookId (Integer bookId) {
return bookInfoMapper.deleteByBookId(bookId);
}
}

View File

@ -0,0 +1,38 @@
# Tomcat
server:
port: 9201
# 配置nacos的地址
nacos:
server-addr: 47.92.86.60:8848
# Spring
spring:
main:
allow-circular-references: true
jackson:
date-format: yyyy-MM-dd HH:mm:ss
time-zone: GMT+8
application:
# 应用名称
name: cloud-system
profiles:
# 环境配置
active: dev
cloud:
nacos:
discovery:
# 服务注册地址
server-addr: ${nacos.server-addr}
config:
# 配置中心地址
server-addr: ${nacos.server-addr}
# 配置文件格式
file-extension: yml
# 共享配置
shared-configs:
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
# 程序Redis公共配置文件
- application-redis-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
# 程序MySQL公共配置文件
- application-mysql-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}

View File

@ -0,0 +1,52 @@
<?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="com.muyu.cloud.system.mapper.BookInfoMapper">
<resultMap id="bookInfoResult" type="com.muyu.cloud.system.domain.BookInfo">
<result column="id" property="id"/>
<result column="name" property="name"/>
<result column="author" property="author"/>
<result column="price" property="price"/>
</resultMap>
<sql id="bookInfoSuf">
select
id,
name,
author,
price
from
book_info
</sql>
<insert id="insert">
INSERT INTO book_info
(`name`, `author`, `price`)
VALUES
( #{name}, #{author}, #{price})
</insert>
<update id="updateByBookId">
UPDATE book_info SET
`name` = #{name},
`author` = #{author},
`price` = #{price}
WHERE
`id` = #{id}
</update>
<delete id="deleteByBookId">
delete from book_info where id = #{bookId}
</delete>
<select id="selectByBookId" resultMap="bookInfoResult">
<include refid="bookInfoSuf"/>
where id = #{bookId}
</select>
<select id="list" resultMap="bookInfoResult">
<include refid="bookInfoSuf"/>
<where>
<if test="name != null and name != ''">
and name like concat('%',#{name},'%')
</if>
</where>
</select>
</mapper>

24
modules/pom.xml 100644
View File

@ -0,0 +1,24 @@
<?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>com.muyu</groupId>
<artifactId>cloud</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>modules</artifactId>
<packaging>pom</packaging>
<modules>
<module>cloud-system</module>
</modules>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>

75
pom.xml 100644
View File

@ -0,0 +1,75 @@
<?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>com.muyu</groupId>
<artifactId>cloud</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>
<modules>
<module>cloud-common</module>
<module>cloud-gateway</module>
<module>modules</module>
</modules>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<!-- 规定SpringBoot版本 -->
<!-- 父级pom文件 主要用于规定项目依赖的各个版本,用于进行项目版本约束 -->
<parent>
<artifactId>spring-boot-starter-parent</artifactId>
<groupId>org.springframework.boot</groupId>
<version>2.7.15</version>
<relativePath/>
</parent>
<!-- 依赖声明 -->
<dependencyManagement>
<dependencies>
<!-- SpringCloud 微服务 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>2021.0.8</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- SpringCloud Alibaba 微服务 -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>2021.0.5.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- Alibaba Nacos 配置 -->
<dependency>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-client</artifactId>
<version>2.0.4</version>
</dependency>
<!-- 公共依赖 -->
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-common</artifactId>
<version>1.0.0</version>
</dependency>
<!-- 系统服务公共依赖 -->
<dependency>
<groupId>com.muyu</groupId>
<artifactId>system-common</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>