初始化
commit
ae8a7bb05c
|
@ -0,0 +1,39 @@
|
||||||
|
target/
|
||||||
|
!.mvn/wrapper/maven-wrapper.jar
|
||||||
|
!**/src/main/**/target/
|
||||||
|
!**/src/test/**/target/
|
||||||
|
|
||||||
|
### IntelliJ IDEA ###
|
||||||
|
.idea
|
||||||
|
.idea/modules.xml
|
||||||
|
.idea/jarRepositories.xml
|
||||||
|
.idea/compiler.xml
|
||||||
|
.idea/libraries/
|
||||||
|
*.iws
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
|
||||||
|
### Eclipse ###
|
||||||
|
.apt_generated
|
||||||
|
.classpath
|
||||||
|
.factorypath
|
||||||
|
.project
|
||||||
|
.settings
|
||||||
|
.springBeans
|
||||||
|
.sts4-cache
|
||||||
|
|
||||||
|
### NetBeans ###
|
||||||
|
/nbproject/private/
|
||||||
|
/nbbuild/
|
||||||
|
/dist/
|
||||||
|
/nbdist/
|
||||||
|
/.nb-gradle/
|
||||||
|
build/
|
||||||
|
!**/src/main/**/build/
|
||||||
|
!**/src/test/**/build/
|
||||||
|
|
||||||
|
### VS Code ###
|
||||||
|
.vscode/
|
||||||
|
|
||||||
|
### Mac OS ###
|
||||||
|
.DS_Store
|
|
@ -0,0 +1,55 @@
|
||||||
|
<?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.ysy</groupId>
|
||||||
|
<artifactId>senior_grade5_week02</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<packaging>pom</packaging>
|
||||||
|
<modules>
|
||||||
|
<module>ysy-common</module>
|
||||||
|
<module>ysy-gateway</module>
|
||||||
|
<module>ysy-modules</module>
|
||||||
|
</modules>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-parent</artifactId>
|
||||||
|
<version>3.0.2</version>
|
||||||
|
<relativePath/>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<dependencyManagement>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
|
||||||
|
<version>2022.0.0.0-RC2</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-dependencies</artifactId>
|
||||||
|
<version>2022.0.0</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.ysy</groupId>
|
||||||
|
<artifactId>ysy-common</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</dependencyManagement>
|
||||||
|
</project>
|
|
@ -0,0 +1,170 @@
|
||||||
|
<?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.ysy</groupId>
|
||||||
|
<artifactId>senior_grade5_week02</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>ysy-common</artifactId>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<!-- nacos服务发现依赖 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- loadbalancer负载均衡 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- nacos配置文件 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- bootstrap优先启动文件 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-bootstrap</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- feign客户端 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- feign的httpclient客户端 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.github.openfeign</groupId>
|
||||||
|
<artifactId>feign-httpclient</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- amqp -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-amqp</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- elasticsearch -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>co.elastic.clients</groupId>
|
||||||
|
<artifactId>elasticsearch-java</artifactId>
|
||||||
|
<version>8.11.1</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- jackson-databind -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
|
<artifactId>jackson-databind</artifactId>
|
||||||
|
<version>2.12.3</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- jwt令牌校验 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.auth0</groupId>
|
||||||
|
<artifactId>java-jwt</artifactId>
|
||||||
|
<version>4.4.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Hibernate Validator -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-validation</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- mysql -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.mysql</groupId>
|
||||||
|
<artifactId>mysql-connector-j</artifactId>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- mybatis -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mybatis.spring.boot</groupId>
|
||||||
|
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||||
|
<version>3.0.2</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- mybatisPlus -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baomidou</groupId>
|
||||||
|
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||||
|
<version>3.5.4.1</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- druid连接池 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba</groupId>
|
||||||
|
<artifactId>druid-spring-boot-starter</artifactId>
|
||||||
|
<version>1.2.20</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- redis -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- redis连接池 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.commons</groupId>
|
||||||
|
<artifactId>commons-pool2</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- fastjson -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.fastjson2</groupId>
|
||||||
|
<artifactId>fastjson2</artifactId>
|
||||||
|
<version>2.0.42</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Apache Lang3 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.commons</groupId>
|
||||||
|
<artifactId>commons-lang3</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- hutool工具包 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.hutool</groupId>
|
||||||
|
<artifactId>hutool-all</artifactId>
|
||||||
|
<version>5.8.20</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- lombok -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- web -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- test -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
|
@ -0,0 +1,30 @@
|
||||||
|
package com.ysy.common.config;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.DbType;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author DongZl
|
||||||
|
* @description: Mybatis-Plus配置
|
||||||
|
* @Date 2024-1-10 下午 05:12
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class MybatisPlusConfig {
|
||||||
|
|
||||||
|
public MybatisPlusConfig () {
|
||||||
|
System.out.println("初始化-----------");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加分页插件
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public MybatisPlusInterceptor mybatisPlusInterceptor() {
|
||||||
|
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
|
||||||
|
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
|
||||||
|
return interceptor;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
package com.ysy.common.contant;
|
||||||
|
|
||||||
|
public class ResultConstants {
|
||||||
|
public final static int SUCCESS_CODE = 200;
|
||||||
|
public final static int FAIL_CODE = 300;
|
||||||
|
public final static int ERROR_CODE = 500;
|
||||||
|
public final static String SUCCESS_MSG = "success";
|
||||||
|
public final static String FAIL_MSG = "fail";
|
||||||
|
public final static String ERROR_MSG = "error";
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
package com.ysy.common.contant;
|
||||||
|
|
||||||
|
public class TokenConstants {
|
||||||
|
public final static String TOKEN = "token";
|
||||||
|
public final static String TOKEN_LOGIN = "tokenLogin";
|
||||||
|
public final static String TOKEN_KEY = "tokenKey";
|
||||||
|
public final static String USER_ID = "userId";
|
||||||
|
public final static String USER_NAME = "username";
|
||||||
|
}
|
|
@ -0,0 +1,61 @@
|
||||||
|
package com.ysy.common.domain.po;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@TableName("tb_car")
|
||||||
|
public class Car {
|
||||||
|
@TableId(value = "car_id", type = IdType.AUTO)
|
||||||
|
private Long carId;
|
||||||
|
|
||||||
|
@TableField("car_num")
|
||||||
|
private String carNum;
|
||||||
|
|
||||||
|
@TableField("car_type")
|
||||||
|
private String carType;
|
||||||
|
|
||||||
|
@TableField("registry_time")
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
private Date registryTime;
|
||||||
|
|
||||||
|
@TableField("position")
|
||||||
|
private String position;
|
||||||
|
|
||||||
|
@TableField("state")
|
||||||
|
private Boolean state;
|
||||||
|
|
||||||
|
@TableField("take_times")
|
||||||
|
private Integer takeTimes;
|
||||||
|
|
||||||
|
@TableField("last_time")
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
private Date lastTime;
|
||||||
|
|
||||||
|
@TableField("emp_id")
|
||||||
|
private Long empId;
|
||||||
|
|
||||||
|
@TableField("user_id")
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
@TableField("type_id")
|
||||||
|
private Long typeId;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private Employee employee;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private Type type;
|
||||||
|
}
|
|
@ -0,0 +1,35 @@
|
||||||
|
package com.ysy.common.domain.po;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@TableName("tb_employee")
|
||||||
|
public class Employee {
|
||||||
|
@TableId("emp_id")
|
||||||
|
private Long empId;
|
||||||
|
|
||||||
|
@TableField("username")
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
@TableField("password")
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
@TableField("phone")
|
||||||
|
private String phone;
|
||||||
|
|
||||||
|
@TableField("start_date")
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
private Date startDate;
|
||||||
|
}
|
|
@ -0,0 +1,35 @@
|
||||||
|
package com.ysy.common.domain.po;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@TableName("tb_record")
|
||||||
|
public class Record {
|
||||||
|
@TableId("record_id")
|
||||||
|
private Long recordId;
|
||||||
|
|
||||||
|
@TableField("record_time")
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
private Date recordTime;
|
||||||
|
|
||||||
|
@TableField("car_id")
|
||||||
|
private Long carId;
|
||||||
|
|
||||||
|
@TableField("recordState")
|
||||||
|
private Boolean recordState;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private Car car;
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
package com.ysy.common.domain.po;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@TableName("tb_car_type")
|
||||||
|
public class Type {
|
||||||
|
@TableId("type_id")
|
||||||
|
private Long typeId;
|
||||||
|
|
||||||
|
@TableField("type_name")
|
||||||
|
private String typeName;
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
package com.ysy.common.domain.po;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@TableName("tb_user")
|
||||||
|
public class User {
|
||||||
|
@TableId(value = "user_id", type = IdType.AUTO)
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
@TableField("username")
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
@TableField("phone")
|
||||||
|
private String phone;
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
package com.ysy.common.domain.result;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@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));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,81 @@
|
||||||
|
package com.ysy.common.domain.result;
|
||||||
|
|
||||||
|
import com.ysy.common.contant.ResultConstants;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class R {
|
||||||
|
private final static int SUCCESS_CODE = ResultConstants.SUCCESS_CODE;
|
||||||
|
|
||||||
|
private final static int FAIL_CODE = ResultConstants.FAIL_CODE;
|
||||||
|
|
||||||
|
private final static int ERROR_CODE = ResultConstants.ERROR_CODE;
|
||||||
|
|
||||||
|
private final static String SUCCESS_MSG = ResultConstants.SUCCESS_MSG;
|
||||||
|
|
||||||
|
private final static String FAIL_MSG = ResultConstants.FAIL_MSG;
|
||||||
|
|
||||||
|
private final static String ERROR_MSG = ResultConstants.ERROR_MSG;
|
||||||
|
|
||||||
|
private Integer code;
|
||||||
|
private String msg;
|
||||||
|
private Map<String, Object> data;
|
||||||
|
|
||||||
|
public R(Integer code, String msg) {
|
||||||
|
this.code = code;
|
||||||
|
this.msg = msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public R(Integer code, String msg, String key, Object value) {
|
||||||
|
this.code = code;
|
||||||
|
this.msg = msg;
|
||||||
|
this.data = new HashMap<>();
|
||||||
|
this.data.put(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
//成功结果集
|
||||||
|
public static R success() {
|
||||||
|
return new R(SUCCESS_CODE, SUCCESS_MSG);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static R success(String msg) {
|
||||||
|
return new R(SUCCESS_CODE, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static R success(Map<String, Object> data) {
|
||||||
|
return new R(SUCCESS_CODE, SUCCESS_MSG, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static R success(String key, Object value) {
|
||||||
|
return new R(SUCCESS_CODE, SUCCESS_MSG, key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static R success(String msg, String key, Object value) {
|
||||||
|
return new R(SUCCESS_CODE, msg, key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
//失败结果集
|
||||||
|
public static R fail() {
|
||||||
|
return new R(FAIL_CODE, FAIL_MSG);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static R fail(String msg) {
|
||||||
|
return new R(FAIL_CODE, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
//错误结果集
|
||||||
|
public static R error() {
|
||||||
|
return new R(ERROR_CODE, ERROR_MSG);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static R error(String msg) {
|
||||||
|
return new R(ERROR_CODE, msg);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,84 @@
|
||||||
|
package com.ysy.common.domain.result;
|
||||||
|
|
||||||
|
import com.ysy.common.contant.ResultConstants;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class Result<T> implements Serializable {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public static final int SUCCESS = ResultConstants.SUCCESS_CODE;
|
||||||
|
|
||||||
|
public static final int FAIL = ResultConstants.FAIL_CODE;
|
||||||
|
|
||||||
|
public static final int ERROR = ResultConstants.ERROR_CODE;
|
||||||
|
|
||||||
|
public static final String SUCCESS_MSG = ResultConstants.SUCCESS_MSG;
|
||||||
|
|
||||||
|
public static final String FAIL_MSG = ResultConstants.FAIL_MSG;
|
||||||
|
|
||||||
|
public static final String ERROR_MSG = ResultConstants.ERROR_MSG;
|
||||||
|
|
||||||
|
//field
|
||||||
|
private int code;
|
||||||
|
private String msg;
|
||||||
|
private T data;
|
||||||
|
|
||||||
|
public static <T> Result<T> success() {
|
||||||
|
return restResult(SUCCESS, SUCCESS_MSG, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Result<T> success(String msg) {
|
||||||
|
return restResult(SUCCESS, msg, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Result<T> success(T data) {
|
||||||
|
return restResult(SUCCESS, SUCCESS_MSG, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Result<T> success(String msg, T data) {
|
||||||
|
return restResult(SUCCESS, msg, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Result<T> fail() {
|
||||||
|
return restResult(FAIL, FAIL_MSG, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Result<T> fail(String msg) {
|
||||||
|
return restResult(FAIL, msg, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Result<T> error() {
|
||||||
|
return restResult(ERROR, ERROR_MSG, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Result<T> error(String msg) {
|
||||||
|
return restResult(ERROR, msg, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static <T> Result<T> restResult(int code, String msg, T data) {
|
||||||
|
Result<T> apiResult = new Result<>();
|
||||||
|
apiResult.setCode(code);
|
||||||
|
apiResult.setMsg(msg);
|
||||||
|
apiResult.setData(data);
|
||||||
|
return apiResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 成功
|
||||||
|
* @return 成功:true
|
||||||
|
*/
|
||||||
|
public boolean isSuccess(){
|
||||||
|
return this.code == SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 失败
|
||||||
|
* @return 失败:false
|
||||||
|
*/
|
||||||
|
public boolean isError(){
|
||||||
|
return !isSuccess();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
package com.ysy.common.domain.vo;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class CarVO {
|
||||||
|
private String carNum;
|
||||||
|
private String username;
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
package com.ysy.common.domain.vo;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class RecordVO {
|
||||||
|
private Long id;
|
||||||
|
private Boolean state;
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
package com.ysy.common.exception;
|
||||||
|
|
||||||
|
import com.ysy.common.domain.result.R;
|
||||||
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||||
|
|
||||||
|
@RestControllerAdvice
|
||||||
|
public class GlobalException {
|
||||||
|
|
||||||
|
@ExceptionHandler()
|
||||||
|
public R exception() {
|
||||||
|
return R.error();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
package com.ysy.common.remote;
|
||||||
|
|
||||||
|
import com.ysy.common.domain.result.R;
|
||||||
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
|
||||||
|
@FeignClient(name = "employeeService", path = "/employee")
|
||||||
|
public interface EmployeeServiceRemote {
|
||||||
|
@GetMapping("/get/id/{id}")
|
||||||
|
R getById(@PathVariable Long id);
|
||||||
|
|
||||||
|
@GetMapping("/get/name/{name}")
|
||||||
|
R getByName(@PathVariable String name);
|
||||||
|
}
|
|
@ -0,0 +1,74 @@
|
||||||
|
package com.ysy.common.utils.gateway;
|
||||||
|
|
||||||
|
|
||||||
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
|
import com.ysy.common.domain.result.R;
|
||||||
|
import com.ysy.common.utils.tools.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");
|
||||||
|
//定义响应内容
|
||||||
|
R result = R.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));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
package com.ysy.common.utils.jwt;
|
||||||
|
|
||||||
|
import com.auth0.jwt.JWT;
|
||||||
|
import com.auth0.jwt.JWTVerifier;
|
||||||
|
import com.auth0.jwt.algorithms.Algorithm;
|
||||||
|
import com.auth0.jwt.interfaces.Claim;
|
||||||
|
import com.auth0.jwt.interfaces.DecodedJWT;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class JwtUtil {
|
||||||
|
private final static Date EXPIRE_TIME = new Date(System.currentTimeMillis() + 1000 * 60 * 60 * 24L);
|
||||||
|
private final static String SECRET = "qwertyuiopasdfghjkl";
|
||||||
|
private final static String CLAIM_NAME = "claim_name";
|
||||||
|
|
||||||
|
public static String createToken(Map<String, Object> claim) {
|
||||||
|
String token = JWT.create()
|
||||||
|
.withClaim(CLAIM_NAME, claim)
|
||||||
|
//.withExpiresAt(EXPIRE_TIME)
|
||||||
|
.sign(Algorithm.HMAC256(SECRET));
|
||||||
|
return token;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DecodedJWT decodedJWT(String token) {
|
||||||
|
JWTVerifier build = JWT.require(Algorithm.HMAC256(SECRET))
|
||||||
|
.build();
|
||||||
|
DecodedJWT decodedJWT = build.verify(token);
|
||||||
|
return decodedJWT;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Claim getClaim(String token) {
|
||||||
|
DecodedJWT decodedJWT = decodedJWT(token);
|
||||||
|
Map<String, Claim> claims = decodedJWT.getClaims();
|
||||||
|
return claims.get(CLAIM_NAME);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,55 @@
|
||||||
|
package com.ysy.common.utils.jwt;
|
||||||
|
|
||||||
|
|
||||||
|
import java.security.MessageDigest;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.util.Base64;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 安全服务工具类
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
public class SecurityUtils {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成BCryptPasswordEncoder密码
|
||||||
|
*
|
||||||
|
* @param password 密码
|
||||||
|
*
|
||||||
|
* @return 加密字符串
|
||||||
|
*/
|
||||||
|
public static String encryptPassword (String password, String salt) {
|
||||||
|
return encryptMD5(password, salt);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断密码是否相同
|
||||||
|
*
|
||||||
|
* @param password 真实密码
|
||||||
|
* @param encodedPassword 加密后字符
|
||||||
|
*
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public static boolean matchesPassword (String password, String salt, String encodedPassword) {
|
||||||
|
return encryptMD5(password, salt).equals(encodedPassword);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算字符串的MD5加密值,并返回Base64编码的字符串。
|
||||||
|
* @param password 要加密的字符串
|
||||||
|
* @return 加密后的Base64编码字符串
|
||||||
|
*/
|
||||||
|
public static String encryptMD5(String password, String salt) {
|
||||||
|
try {
|
||||||
|
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||||
|
md.update((password + salt).getBytes()); // 加盐处理
|
||||||
|
byte[] digest = md.digest();
|
||||||
|
String encodeToString = Base64.getEncoder().encodeToString(digest);
|
||||||
|
return encodeToString;
|
||||||
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,68 @@
|
||||||
|
package com.ysy.common.utils.tools;
|
||||||
|
|
||||||
|
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是否为空, 包含List,Set,Queue
|
||||||
|
*
|
||||||
|
* @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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,45 @@
|
||||||
|
<?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.ysy</groupId>
|
||||||
|
<artifactId>senior_grade5_week02</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>ysy-gateway</artifactId>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.ysy</groupId>
|
||||||
|
<artifactId>ysy-common</artifactId>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 网关依赖 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-gateway</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- lombok -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
|
@ -0,0 +1,11 @@
|
||||||
|
package com.ysy.gateway;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
public class GatewayApplication {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(GatewayApplication.class, args);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
package com.ysy.gateway.filter;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
|
||||||
|
import org.springframework.cloud.gateway.filter.GlobalFilter;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.core.annotation.Order;
|
||||||
|
import org.springframework.http.HttpMethod;
|
||||||
|
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||||
|
import org.springframework.web.server.ServerWebExchange;
|
||||||
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@Order(1)
|
||||||
|
@Slf4j
|
||||||
|
public class ModulesFilter implements GlobalFilter {
|
||||||
|
@Override
|
||||||
|
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
|
||||||
|
ServerHttpRequest request = exchange.getRequest();
|
||||||
|
String path = request.getPath().toString();
|
||||||
|
HttpMethod method = request.getMethod();
|
||||||
|
log.info("请求路径:[{}],请求方式:[{}]", path, method);
|
||||||
|
return chain.filter(exchange);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
server:
|
||||||
|
port: 10010
|
||||||
|
spring:
|
||||||
|
application:
|
||||||
|
#服务名称
|
||||||
|
name: gateway
|
||||||
|
profiles:
|
||||||
|
#配置文件生效环境
|
||||||
|
active: dev
|
||||||
|
|
||||||
|
cloud:
|
||||||
|
nacos:
|
||||||
|
#nacos服务器地址
|
||||||
|
server-addr: http://124.70.132.13:8848
|
||||||
|
#nacos服务发现配置
|
||||||
|
discovery:
|
||||||
|
#nacos服务注册命名空间ID,默认为public
|
||||||
|
namespace: 2e6a4975-46b3-4035-b77d-92b05ae48a66
|
||||||
|
#nacos配置文件配置
|
||||||
|
config:
|
||||||
|
#指定读取命名空间配置,默认为public
|
||||||
|
namespace: ${spring.cloud.nacos.discovery.namespace}
|
||||||
|
#nacos配置文件类型
|
||||||
|
file-extension: yaml
|
||||||
|
#共享配置
|
||||||
|
shared-configs:
|
||||||
|
- data-id: common-redis.yaml
|
||||||
|
group: SPRING_CLOUD_COMMONS
|
||||||
|
refresh: true
|
||||||
|
|
||||||
|
|
|
@ -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.ysy</groupId>
|
||||||
|
<artifactId>senior_grade5_week02</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>ysy-modules</artifactId>
|
||||||
|
<packaging>pom</packaging>
|
||||||
|
<modules>
|
||||||
|
<module>ysy-employee</module>
|
||||||
|
<module>ysy-car</module>
|
||||||
|
<module>ysy-record</module>
|
||||||
|
</modules>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
</project>
|
|
@ -0,0 +1,41 @@
|
||||||
|
<?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.ysy</groupId>
|
||||||
|
<artifactId>ysy-modules</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>ysy-car-module</artifactId>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<!-- 自定义公共模块 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.ysy</groupId>
|
||||||
|
<artifactId>ysy-common</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- lombok -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- test -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
|
@ -0,0 +1,13 @@
|
||||||
|
package com.ysy.car;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
@EnableFeignClients(basePackages = {"com.ysy.common.remote"})
|
||||||
|
public class CarServiceApplication {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(CarServiceApplication.class, args);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,55 @@
|
||||||
|
package com.ysy.car.controller;
|
||||||
|
|
||||||
|
import com.ysy.car.service.CarService;
|
||||||
|
import com.ysy.common.domain.po.Car;
|
||||||
|
import com.ysy.common.domain.result.R;
|
||||||
|
import com.ysy.common.domain.vo.CarVO;
|
||||||
|
import com.ysy.common.domain.vo.RecordVO;
|
||||||
|
import org.apache.ibatis.annotations.Delete;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/car")
|
||||||
|
public class CarController {
|
||||||
|
private final CarService carService;
|
||||||
|
|
||||||
|
public CarController(CarService carService) {
|
||||||
|
this.carService = carService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/list")
|
||||||
|
public R list(@RequestBody CarVO carVO) {
|
||||||
|
return R.success(
|
||||||
|
"carList",
|
||||||
|
carService.getCarListByCarVO(carVO)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/record")
|
||||||
|
public R recordById(@RequestBody RecordVO recordVO) {
|
||||||
|
carService.recordAdd(recordVO);
|
||||||
|
return R.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/delete")
|
||||||
|
public R delete(@RequestBody List<Long> ids) {
|
||||||
|
carService.deleteState(ids);
|
||||||
|
return R.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/type/list")
|
||||||
|
public R typeList() {
|
||||||
|
return R.success(
|
||||||
|
"typeList",
|
||||||
|
carService.getTypeList()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/add")
|
||||||
|
public R carAdd(@RequestBody Car car) {
|
||||||
|
carService.carAdd(car);
|
||||||
|
return R.success();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
package com.ysy.car.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.ysy.common.domain.po.Car;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface CarMapper extends BaseMapper<Car> {
|
||||||
|
void deleteStateByIds(List<Long> ids);
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
package com.ysy.car.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.ysy.common.domain.vo.RecordVO;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface RecordMapper extends BaseMapper<Record> {
|
||||||
|
int insertRecord(RecordVO recordVO);
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
package com.ysy.car.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.ysy.common.domain.po.Type;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface TypeMapper extends BaseMapper<Type> {
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
package com.ysy.car.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.ysy.common.domain.po.User;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface UserMapper extends BaseMapper<User> {
|
||||||
|
int insertUser(User build);
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
package com.ysy.car.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.ysy.common.domain.po.Car;
|
||||||
|
import com.ysy.common.domain.po.Type;
|
||||||
|
import com.ysy.common.domain.vo.CarVO;
|
||||||
|
import com.ysy.common.domain.vo.RecordVO;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface CarService extends IService<Car> {
|
||||||
|
List<Car> getCarListByCarVO(CarVO carVO);
|
||||||
|
|
||||||
|
|
||||||
|
void recordAdd(RecordVO recordVO);
|
||||||
|
|
||||||
|
void deleteState(List<Long> ids);
|
||||||
|
|
||||||
|
List<Type> getTypeList();
|
||||||
|
|
||||||
|
void carAdd(Car car);
|
||||||
|
}
|
|
@ -0,0 +1,142 @@
|
||||||
|
package com.ysy.car.service.impl;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson2.JSON;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.ysy.car.mapper.CarMapper;
|
||||||
|
import com.ysy.car.mapper.RecordMapper;
|
||||||
|
import com.ysy.car.mapper.TypeMapper;
|
||||||
|
import com.ysy.car.mapper.UserMapper;
|
||||||
|
import com.ysy.car.service.CarService;
|
||||||
|
import com.ysy.common.domain.po.Car;
|
||||||
|
import com.ysy.common.domain.po.Employee;
|
||||||
|
import com.ysy.common.domain.po.Type;
|
||||||
|
import com.ysy.common.domain.po.User;
|
||||||
|
import com.ysy.common.domain.result.R;
|
||||||
|
import com.ysy.common.domain.vo.CarVO;
|
||||||
|
import com.ysy.common.domain.vo.RecordVO;
|
||||||
|
import com.ysy.common.remote.EmployeeServiceRemote;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class CarServiceImpl extends ServiceImpl<CarMapper, Car>
|
||||||
|
implements CarService {
|
||||||
|
private final EmployeeServiceRemote employeeServiceRemote;
|
||||||
|
private final TypeMapper typeMapper;
|
||||||
|
private final UserMapper userMapper;
|
||||||
|
private final RecordMapper recordMapper;
|
||||||
|
private final CarMapper carMapper;
|
||||||
|
|
||||||
|
public CarServiceImpl(EmployeeServiceRemote employeeServiceRemote,
|
||||||
|
TypeMapper typeMapper,
|
||||||
|
UserMapper userMapper, RecordMapper recordMapper, CarMapper carMapper) {
|
||||||
|
this.employeeServiceRemote = employeeServiceRemote;
|
||||||
|
this.typeMapper = typeMapper;
|
||||||
|
this.userMapper = userMapper;
|
||||||
|
this.recordMapper = recordMapper;
|
||||||
|
this.carMapper = carMapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Car> getCarListByCarVO(CarVO carVO) {
|
||||||
|
LambdaQueryWrapper<Car> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
|
||||||
|
//车牌号模糊查询
|
||||||
|
if (StringUtils.isNoneBlank(carVO.getCarNum())) {
|
||||||
|
lambdaQueryWrapper.like(Car::getCarNum, carVO.getCarNum());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtils.isNoneBlank(carVO.getUsername())) {
|
||||||
|
R result = employeeServiceRemote.getByName(carVO.getUsername());
|
||||||
|
List list = JSON.parseObject(
|
||||||
|
JSON.toJSONString(result.getData().get("employeeList")),
|
||||||
|
List.class
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!list.isEmpty()) {
|
||||||
|
List<Employee> employeeList = new ArrayList<>();
|
||||||
|
list.forEach(obj -> {
|
||||||
|
employeeList.add(JSON.parseObject(JSON.toJSONString(obj), Employee.class));
|
||||||
|
});
|
||||||
|
ArrayList<Long> ids = new ArrayList<>();
|
||||||
|
employeeList.forEach(emp -> {
|
||||||
|
ids.add(emp.getEmpId());
|
||||||
|
});
|
||||||
|
lambdaQueryWrapper.in(Car::getEmpId, ids);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Car> carList = list(lambdaQueryWrapper);
|
||||||
|
|
||||||
|
if (carList != null && !carList.isEmpty()) {
|
||||||
|
carList.forEach(car -> {
|
||||||
|
car.setType(typeMapper.selectById(car.getTypeId()));
|
||||||
|
if (car.getUserId() == 0) {
|
||||||
|
car.setEmployee(
|
||||||
|
JSON.parseObject(
|
||||||
|
JSON.toJSONString(
|
||||||
|
employeeServiceRemote.getById(car.getEmpId()).getData().get("employee")
|
||||||
|
),
|
||||||
|
Employee.class
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
User user = userMapper.selectById(car.getUserId());
|
||||||
|
car.setEmployee(
|
||||||
|
Employee.builder()
|
||||||
|
.empId(user.getUserId())
|
||||||
|
.phone(user.getPhone())
|
||||||
|
.username(user.getUsername())
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return carList;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void recordAdd(RecordVO recordVO) {
|
||||||
|
int recordId = recordMapper.insertRecord(recordVO);
|
||||||
|
Car car = getById(recordVO.getId());
|
||||||
|
car.setLastTime(new Date());
|
||||||
|
car.setTakeTimes(car.getTakeTimes() + 1);
|
||||||
|
updateById(car);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteState(List<Long> ids) {
|
||||||
|
carMapper.deleteStateByIds(ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Type> getTypeList() {
|
||||||
|
return typeMapper.selectList(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void carAdd(Car car) {
|
||||||
|
if (car.getEmpId() == null) {
|
||||||
|
User user = User.builder()
|
||||||
|
.username(car.getEmployee().getUsername())
|
||||||
|
.phone(car.getEmployee().getPhone())
|
||||||
|
.build();
|
||||||
|
userMapper.insertUser(user);
|
||||||
|
car.setEmpId(0L);
|
||||||
|
car.setUserId(user.getUserId());
|
||||||
|
} else {
|
||||||
|
car.setUserId(0L);
|
||||||
|
}
|
||||||
|
|
||||||
|
car.setState(true);
|
||||||
|
car.setRegistryTime(new Date());
|
||||||
|
car.setTakeTimes(1);
|
||||||
|
car.setLastTime(new Date());
|
||||||
|
save(car);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
██ ██ ████████ ██ ██
|
||||||
|
░░██ ██ ██░░░░░░ ░░██ ██
|
||||||
|
░░████ ░██ ░░████
|
||||||
|
░░██ ░█████████ ░░██
|
||||||
|
░██ ░░░░░░░░██ ░██
|
||||||
|
░██ ░██ ░██
|
||||||
|
░██ ████████ ░██
|
||||||
|
░░ ░░░░░░░░ ░░
|
||||||
|
:: ysy boot :: version 1.0
|
|
@ -0,0 +1,42 @@
|
||||||
|
server:
|
||||||
|
#服务端口
|
||||||
|
port: 10001
|
||||||
|
|
||||||
|
spring:
|
||||||
|
application:
|
||||||
|
#服务名称
|
||||||
|
name: carService
|
||||||
|
profiles:
|
||||||
|
#配置文件生效环境
|
||||||
|
active: dev
|
||||||
|
|
||||||
|
cloud:
|
||||||
|
nacos:
|
||||||
|
#nacos服务器地址
|
||||||
|
server-addr: http://124.70.132.13:8848
|
||||||
|
#nacos服务发现配置
|
||||||
|
discovery:
|
||||||
|
#nacos服务注册命名空间ID,默认为public
|
||||||
|
namespace: 2e6a4975-46b3-4035-b77d-92b05ae48a66
|
||||||
|
#cluster-name: SH #服务集群设置
|
||||||
|
config:
|
||||||
|
#指定读取命名空间配置,默认为public
|
||||||
|
namespace: ${spring.cloud.nacos.discovery.namespace}
|
||||||
|
#nacos配置文件类型
|
||||||
|
file-extension: yaml
|
||||||
|
#共享配置
|
||||||
|
shared-configs:
|
||||||
|
- data-id: common.yaml
|
||||||
|
group: SPRING_CLOUD_COMMONS
|
||||||
|
refresh: true
|
||||||
|
|
||||||
|
- data-id: common-mysql.yaml
|
||||||
|
group: SPRING_CLOUD_COMMONS
|
||||||
|
refresh: true
|
||||||
|
|
||||||
|
- data-id: common-redis.yaml
|
||||||
|
group: SPRING_CLOUD_COMMONS
|
||||||
|
refresh: true
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
<?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.ysy.car.mapper.CarMapper">
|
||||||
|
<update id="deleteStateByIds">
|
||||||
|
update tb_car set state = 0 where car_id in (
|
||||||
|
<foreach collection="ids" separator="," item="id">
|
||||||
|
#{id}
|
||||||
|
</foreach>
|
||||||
|
)
|
||||||
|
</update>
|
||||||
|
</mapper>
|
|
@ -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="com.ysy.car.mapper.RecordMapper">
|
||||||
|
<insert id="insertRecord">
|
||||||
|
insert into tb_record values (null, now(), #{id}, #{state})
|
||||||
|
</insert>
|
||||||
|
</mapper>
|
|
@ -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="com.ysy.car.mapper.UserMapper">
|
||||||
|
<insert id="insertUser" useGeneratedKeys="true" keyProperty="userId">
|
||||||
|
insert into tb_user values (null, #{username}, #{phone})
|
||||||
|
</insert>
|
||||||
|
</mapper>
|
|
@ -0,0 +1,41 @@
|
||||||
|
<?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.ysy</groupId>
|
||||||
|
<artifactId>ysy-modules</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>ysy-employee-module</artifactId>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<!-- 自定义公共模块 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.ysy</groupId>
|
||||||
|
<artifactId>ysy-common</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- lombok -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- test -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
|
@ -0,0 +1,11 @@
|
||||||
|
package com.ysy.employee;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
public class EmployeeServiceApplication {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(EmployeeServiceApplication.class, args);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,46 @@
|
||||||
|
package com.ysy.employee.controller;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.ysy.common.domain.po.Employee;
|
||||||
|
import com.ysy.common.domain.result.R;
|
||||||
|
import com.ysy.employee.service.EmployeeService;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/employee")
|
||||||
|
public class EmployeeController {
|
||||||
|
private final EmployeeService employeeService;
|
||||||
|
|
||||||
|
public EmployeeController(EmployeeService employeeService) {
|
||||||
|
this.employeeService = employeeService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/get/id/{id}")
|
||||||
|
public R getById(@PathVariable Long id) {
|
||||||
|
return R.success(
|
||||||
|
"employee",
|
||||||
|
employeeService.getById(id)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/get/name/{name}")
|
||||||
|
public R getByName(@PathVariable String name) {
|
||||||
|
LambdaQueryWrapper<Employee> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
lambdaQueryWrapper.like(Employee::getUsername, name);
|
||||||
|
return R.success(
|
||||||
|
"employeeList",
|
||||||
|
employeeService.list(lambdaQueryWrapper)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/list")
|
||||||
|
public R list() {
|
||||||
|
return R.success(
|
||||||
|
"employeeList",
|
||||||
|
employeeService.list()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
package com.ysy.employee.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.ysy.common.domain.po.Employee;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface EmployeeMapper extends BaseMapper<Employee> {
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
package com.ysy.employee.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.ysy.common.domain.po.Employee;
|
||||||
|
|
||||||
|
public interface EmployeeService extends IService<Employee> {
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
package com.ysy.employee.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.ysy.common.domain.po.Employee;
|
||||||
|
import com.ysy.employee.mapper.EmployeeMapper;
|
||||||
|
import com.ysy.employee.service.EmployeeService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class EmployeeServiceImpl extends ServiceImpl<EmployeeMapper, Employee> implements EmployeeService {
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
██ ██ ████████ ██ ██
|
||||||
|
░░██ ██ ██░░░░░░ ░░██ ██
|
||||||
|
░░████ ░██ ░░████
|
||||||
|
░░██ ░█████████ ░░██
|
||||||
|
░██ ░░░░░░░░██ ░██
|
||||||
|
░██ ░██ ░██
|
||||||
|
░██ ████████ ░██
|
||||||
|
░░ ░░░░░░░░ ░░
|
||||||
|
:: ysy boot :: version 1.0
|
|
@ -0,0 +1,42 @@
|
||||||
|
server:
|
||||||
|
#服务端口
|
||||||
|
port: 10002
|
||||||
|
|
||||||
|
spring:
|
||||||
|
application:
|
||||||
|
#服务名称
|
||||||
|
name: employeeService
|
||||||
|
profiles:
|
||||||
|
#配置文件生效环境
|
||||||
|
active: dev
|
||||||
|
|
||||||
|
cloud:
|
||||||
|
nacos:
|
||||||
|
#nacos服务器地址
|
||||||
|
server-addr: http://124.70.132.13:8848
|
||||||
|
#nacos服务发现配置
|
||||||
|
discovery:
|
||||||
|
#nacos服务注册命名空间ID,默认为public
|
||||||
|
namespace: 2e6a4975-46b3-4035-b77d-92b05ae48a66
|
||||||
|
#cluster-name: SH #服务集群设置
|
||||||
|
config:
|
||||||
|
#指定读取命名空间配置,默认为public
|
||||||
|
namespace: ${spring.cloud.nacos.discovery.namespace}
|
||||||
|
#nacos配置文件类型
|
||||||
|
file-extension: yaml
|
||||||
|
#共享配置
|
||||||
|
shared-configs:
|
||||||
|
- data-id: common.yaml
|
||||||
|
group: SPRING_CLOUD_COMMONS
|
||||||
|
refresh: true
|
||||||
|
|
||||||
|
- data-id: common-mysql.yaml
|
||||||
|
group: SPRING_CLOUD_COMMONS
|
||||||
|
refresh: true
|
||||||
|
|
||||||
|
- data-id: common-redis.yaml
|
||||||
|
group: SPRING_CLOUD_COMMONS
|
||||||
|
refresh: true
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
<?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.ysy</groupId>
|
||||||
|
<artifactId>ysy-modules</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>ysy-record-module</artifactId>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<!-- 自定义公共模块 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.ysy</groupId>
|
||||||
|
<artifactId>ysy-common</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- lombok -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- test -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
|
@ -0,0 +1,7 @@
|
||||||
|
package com.ysy;
|
||||||
|
|
||||||
|
public class Main {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.out.println("Hello world!");
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue