commit ae8a7bb05c9ee5ab12975997548603136c164120 Author: Sheyu-yao Date: Fri Jan 19 15:53:46 2024 +0800 初始化 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fc3f89c --- /dev/null +++ b/.gitignore @@ -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 \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..aa40eda --- /dev/null +++ b/pom.xml @@ -0,0 +1,55 @@ + + + 4.0.0 + + com.ysy + senior_grade5_week02 + 1.0-SNAPSHOT + pom + + ysy-common + ysy-gateway + ysy-modules + + + + 17 + 17 + UTF-8 + + + + org.springframework.boot + spring-boot-starter-parent + 3.0.2 + + + + + + + com.alibaba.cloud + spring-cloud-alibaba-dependencies + 2022.0.0.0-RC2 + pom + import + + + + org.springframework.cloud + spring-cloud-dependencies + 2022.0.0 + pom + import + + + + com.ysy + ysy-common + 1.0-SNAPSHOT + + + + \ No newline at end of file diff --git a/ysy-common/pom.xml b/ysy-common/pom.xml new file mode 100644 index 0000000..f8bc0d6 --- /dev/null +++ b/ysy-common/pom.xml @@ -0,0 +1,170 @@ + + + 4.0.0 + + com.ysy + senior_grade5_week02 + 1.0-SNAPSHOT + + + ysy-common + + + 17 + 17 + UTF-8 + + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + + + org.springframework.cloud + spring-cloud-starter-loadbalancer + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-config + + + + + org.springframework.cloud + spring-cloud-starter-bootstrap + + + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + + + io.github.openfeign + feign-httpclient + + + + + org.springframework.boot + spring-boot-starter-amqp + + + + + co.elastic.clients + elasticsearch-java + 8.11.1 + + + + + com.fasterxml.jackson.core + jackson-databind + 2.12.3 + + + + + com.auth0 + java-jwt + 4.4.0 + + + + + org.springframework.boot + spring-boot-starter-validation + + + + + com.mysql + mysql-connector-j + runtime + + + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + 3.0.2 + + + + + com.baomidou + mybatis-plus-boot-starter + 3.5.4.1 + + + + + com.alibaba + druid-spring-boot-starter + 1.2.20 + + + + + org.springframework.boot + spring-boot-starter-data-redis + + + + + org.apache.commons + commons-pool2 + + + + + com.alibaba.fastjson2 + fastjson2 + 2.0.42 + + + + + org.apache.commons + commons-lang3 + + + + + cn.hutool + hutool-all + 5.8.20 + + + + + org.projectlombok + lombok + true + + + + + org.springframework.boot + spring-boot-starter-web + + + + + org.springframework.boot + spring-boot-starter-test + test + + + \ No newline at end of file diff --git a/ysy-common/src/main/java/com/ysy/common/config/MybatisPlusConfig.java b/ysy-common/src/main/java/com/ysy/common/config/MybatisPlusConfig.java new file mode 100644 index 0000000..2cb54bb --- /dev/null +++ b/ysy-common/src/main/java/com/ysy/common/config/MybatisPlusConfig.java @@ -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; + } +} diff --git a/ysy-common/src/main/java/com/ysy/common/contant/ResultConstants.java b/ysy-common/src/main/java/com/ysy/common/contant/ResultConstants.java new file mode 100644 index 0000000..3c23aa6 --- /dev/null +++ b/ysy-common/src/main/java/com/ysy/common/contant/ResultConstants.java @@ -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"; +} diff --git a/ysy-common/src/main/java/com/ysy/common/contant/TokenConstants.java b/ysy-common/src/main/java/com/ysy/common/contant/TokenConstants.java new file mode 100644 index 0000000..eb50791 --- /dev/null +++ b/ysy-common/src/main/java/com/ysy/common/contant/TokenConstants.java @@ -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"; +} diff --git a/ysy-common/src/main/java/com/ysy/common/domain/po/Car.java b/ysy-common/src/main/java/com/ysy/common/domain/po/Car.java new file mode 100644 index 0000000..d51ceb7 --- /dev/null +++ b/ysy-common/src/main/java/com/ysy/common/domain/po/Car.java @@ -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; +} diff --git a/ysy-common/src/main/java/com/ysy/common/domain/po/Employee.java b/ysy-common/src/main/java/com/ysy/common/domain/po/Employee.java new file mode 100644 index 0000000..dcbfe35 --- /dev/null +++ b/ysy-common/src/main/java/com/ysy/common/domain/po/Employee.java @@ -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; +} diff --git a/ysy-common/src/main/java/com/ysy/common/domain/po/Record.java b/ysy-common/src/main/java/com/ysy/common/domain/po/Record.java new file mode 100644 index 0000000..0ccfd05 --- /dev/null +++ b/ysy-common/src/main/java/com/ysy/common/domain/po/Record.java @@ -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; +} diff --git a/ysy-common/src/main/java/com/ysy/common/domain/po/Type.java b/ysy-common/src/main/java/com/ysy/common/domain/po/Type.java new file mode 100644 index 0000000..209b968 --- /dev/null +++ b/ysy-common/src/main/java/com/ysy/common/domain/po/Type.java @@ -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; +} diff --git a/ysy-common/src/main/java/com/ysy/common/domain/po/User.java b/ysy-common/src/main/java/com/ysy/common/domain/po/User.java new file mode 100644 index 0000000..a4072b9 --- /dev/null +++ b/ysy-common/src/main/java/com/ysy/common/domain/po/User.java @@ -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; +} diff --git a/ysy-common/src/main/java/com/ysy/common/domain/result/PageResult.java b/ysy-common/src/main/java/com/ysy/common/domain/result/PageResult.java new file mode 100644 index 0000000..2c961ad --- /dev/null +++ b/ysy-common/src/main/java/com/ysy/common/domain/result/PageResult.java @@ -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 implements Serializable { + + private long total; + + private List list; + + public PageResult() { + } + + public PageResult(long total, List list) { + this.total = total; + this.list = list; + } + + public static PageResult toPageResult(long total, List list){ + return new PageResult(total , list); + } + + public static Result> toResult(long total, List list){ + return Result.success(PageResult.toPageResult(total, list)); + } +} diff --git a/ysy-common/src/main/java/com/ysy/common/domain/result/R.java b/ysy-common/src/main/java/com/ysy/common/domain/result/R.java new file mode 100644 index 0000000..9d11039 --- /dev/null +++ b/ysy-common/src/main/java/com/ysy/common/domain/result/R.java @@ -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 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 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); + } +} diff --git a/ysy-common/src/main/java/com/ysy/common/domain/result/Result.java b/ysy-common/src/main/java/com/ysy/common/domain/result/Result.java new file mode 100644 index 0000000..2e47a01 --- /dev/null +++ b/ysy-common/src/main/java/com/ysy/common/domain/result/Result.java @@ -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 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 Result success() { + return restResult(SUCCESS, SUCCESS_MSG, null); + } + + public static Result success(String msg) { + return restResult(SUCCESS, msg, null); + } + + public static Result success(T data) { + return restResult(SUCCESS, SUCCESS_MSG, data); + } + + public static Result success(String msg, T data) { + return restResult(SUCCESS, msg, data); + } + + public static Result fail() { + return restResult(FAIL, FAIL_MSG, null); + } + + public static Result fail(String msg) { + return restResult(FAIL, msg, null); + } + + public static Result error() { + return restResult(ERROR, ERROR_MSG, null); + } + + public static Result error(String msg) { + return restResult(ERROR, msg, null); + } + + private static Result restResult(int code, String msg, T data) { + Result 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(); + } +} diff --git a/ysy-common/src/main/java/com/ysy/common/domain/vo/CarVO.java b/ysy-common/src/main/java/com/ysy/common/domain/vo/CarVO.java new file mode 100644 index 0000000..ea8c152 --- /dev/null +++ b/ysy-common/src/main/java/com/ysy/common/domain/vo/CarVO.java @@ -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; +} diff --git a/ysy-common/src/main/java/com/ysy/common/domain/vo/RecordVO.java b/ysy-common/src/main/java/com/ysy/common/domain/vo/RecordVO.java new file mode 100644 index 0000000..77fe8b5 --- /dev/null +++ b/ysy-common/src/main/java/com/ysy/common/domain/vo/RecordVO.java @@ -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; +} diff --git a/ysy-common/src/main/java/com/ysy/common/exception/GlobalException.java b/ysy-common/src/main/java/com/ysy/common/exception/GlobalException.java new file mode 100644 index 0000000..c00ff54 --- /dev/null +++ b/ysy-common/src/main/java/com/ysy/common/exception/GlobalException.java @@ -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(); + } +} diff --git a/ysy-common/src/main/java/com/ysy/common/remote/EmployeeServiceRemote.java b/ysy-common/src/main/java/com/ysy/common/remote/EmployeeServiceRemote.java new file mode 100644 index 0000000..f1d2090 --- /dev/null +++ b/ysy-common/src/main/java/com/ysy/common/remote/EmployeeServiceRemote.java @@ -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); +} diff --git a/ysy-common/src/main/java/com/ysy/common/utils/gateway/GatewayUtils.java b/ysy-common/src/main/java/com/ysy/common/utils/gateway/GatewayUtils.java new file mode 100644 index 0000000..594ccf0 --- /dev/null +++ b/ysy-common/src/main/java/com/ysy/common/utils/gateway/GatewayUtils.java @@ -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 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)); + } + } diff --git a/ysy-common/src/main/java/com/ysy/common/utils/jwt/JwtUtil.java b/ysy-common/src/main/java/com/ysy/common/utils/jwt/JwtUtil.java new file mode 100644 index 0000000..05fa5d1 --- /dev/null +++ b/ysy-common/src/main/java/com/ysy/common/utils/jwt/JwtUtil.java @@ -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 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 claims = decodedJWT.getClaims(); + return claims.get(CLAIM_NAME); + } +} diff --git a/ysy-common/src/main/java/com/ysy/common/utils/jwt/SecurityUtils.java b/ysy-common/src/main/java/com/ysy/common/utils/jwt/SecurityUtils.java new file mode 100644 index 0000000..9299f9e --- /dev/null +++ b/ysy-common/src/main/java/com/ysy/common/utils/jwt/SecurityUtils.java @@ -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); + } + } +} diff --git a/ysy-common/src/main/java/com/ysy/common/utils/tools/StringUtils.java b/ysy-common/src/main/java/com/ysy/common/utils/tools/StringUtils.java new file mode 100644 index 0000000..8191f3a --- /dev/null +++ b/ysy-common/src/main/java/com/ysy/common/utils/tools/StringUtils.java @@ -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 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); + } +} diff --git a/ysy-gateway/pom.xml b/ysy-gateway/pom.xml new file mode 100644 index 0000000..596994d --- /dev/null +++ b/ysy-gateway/pom.xml @@ -0,0 +1,45 @@ + + + 4.0.0 + + com.ysy + senior_grade5_week02 + 1.0-SNAPSHOT + + + ysy-gateway + + + 17 + 17 + UTF-8 + + + + + com.ysy + ysy-common + + + org.springframework.boot + spring-boot-starter-web + + + + + + + org.springframework.cloud + spring-cloud-starter-gateway + + + + + org.projectlombok + lombok + true + + + \ No newline at end of file diff --git a/ysy-gateway/src/main/java/com/ysy/gateway/GatewayApplication.java b/ysy-gateway/src/main/java/com/ysy/gateway/GatewayApplication.java new file mode 100644 index 0000000..68099d2 --- /dev/null +++ b/ysy-gateway/src/main/java/com/ysy/gateway/GatewayApplication.java @@ -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); + } +} \ No newline at end of file diff --git a/ysy-gateway/src/main/java/com/ysy/gateway/filter/ModulesFilter.java b/ysy-gateway/src/main/java/com/ysy/gateway/filter/ModulesFilter.java new file mode 100644 index 0000000..ea62b4d --- /dev/null +++ b/ysy-gateway/src/main/java/com/ysy/gateway/filter/ModulesFilter.java @@ -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 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); + } +} diff --git a/ysy-gateway/src/main/resources/bootstrap.yml b/ysy-gateway/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..a21ef87 --- /dev/null +++ b/ysy-gateway/src/main/resources/bootstrap.yml @@ -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 + + diff --git a/ysy-modules/pom.xml b/ysy-modules/pom.xml new file mode 100644 index 0000000..57e2aee --- /dev/null +++ b/ysy-modules/pom.xml @@ -0,0 +1,26 @@ + + + 4.0.0 + + com.ysy + senior_grade5_week02 + 1.0-SNAPSHOT + + + ysy-modules + pom + + ysy-employee + ysy-car + ysy-record + + + + 17 + 17 + UTF-8 + + + \ No newline at end of file diff --git a/ysy-modules/ysy-car/pom.xml b/ysy-modules/ysy-car/pom.xml new file mode 100644 index 0000000..f241170 --- /dev/null +++ b/ysy-modules/ysy-car/pom.xml @@ -0,0 +1,41 @@ + + + 4.0.0 + + com.ysy + ysy-modules + 1.0-SNAPSHOT + + + ysy-car-module + + + 17 + 17 + UTF-8 + + + + + + com.ysy + ysy-common + + + + + org.projectlombok + lombok + true + + + + + org.springframework.boot + spring-boot-starter-test + test + + + \ No newline at end of file diff --git a/ysy-modules/ysy-car/src/main/java/com/ysy/car/CarServiceApplication.java b/ysy-modules/ysy-car/src/main/java/com/ysy/car/CarServiceApplication.java new file mode 100644 index 0000000..bd5766a --- /dev/null +++ b/ysy-modules/ysy-car/src/main/java/com/ysy/car/CarServiceApplication.java @@ -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); + } +} \ No newline at end of file diff --git a/ysy-modules/ysy-car/src/main/java/com/ysy/car/controller/CarController.java b/ysy-modules/ysy-car/src/main/java/com/ysy/car/controller/CarController.java new file mode 100644 index 0000000..a3e347b --- /dev/null +++ b/ysy-modules/ysy-car/src/main/java/com/ysy/car/controller/CarController.java @@ -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 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(); + } +} diff --git a/ysy-modules/ysy-car/src/main/java/com/ysy/car/mapper/CarMapper.java b/ysy-modules/ysy-car/src/main/java/com/ysy/car/mapper/CarMapper.java new file mode 100644 index 0000000..9198fe7 --- /dev/null +++ b/ysy-modules/ysy-car/src/main/java/com/ysy/car/mapper/CarMapper.java @@ -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 { + void deleteStateByIds(List ids); +} diff --git a/ysy-modules/ysy-car/src/main/java/com/ysy/car/mapper/RecordMapper.java b/ysy-modules/ysy-car/src/main/java/com/ysy/car/mapper/RecordMapper.java new file mode 100644 index 0000000..70988de --- /dev/null +++ b/ysy-modules/ysy-car/src/main/java/com/ysy/car/mapper/RecordMapper.java @@ -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 { + int insertRecord(RecordVO recordVO); +} diff --git a/ysy-modules/ysy-car/src/main/java/com/ysy/car/mapper/TypeMapper.java b/ysy-modules/ysy-car/src/main/java/com/ysy/car/mapper/TypeMapper.java new file mode 100644 index 0000000..769bf48 --- /dev/null +++ b/ysy-modules/ysy-car/src/main/java/com/ysy/car/mapper/TypeMapper.java @@ -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 { +} diff --git a/ysy-modules/ysy-car/src/main/java/com/ysy/car/mapper/UserMapper.java b/ysy-modules/ysy-car/src/main/java/com/ysy/car/mapper/UserMapper.java new file mode 100644 index 0000000..e910c00 --- /dev/null +++ b/ysy-modules/ysy-car/src/main/java/com/ysy/car/mapper/UserMapper.java @@ -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 { + int insertUser(User build); +} diff --git a/ysy-modules/ysy-car/src/main/java/com/ysy/car/service/CarService.java b/ysy-modules/ysy-car/src/main/java/com/ysy/car/service/CarService.java new file mode 100644 index 0000000..6dc69c3 --- /dev/null +++ b/ysy-modules/ysy-car/src/main/java/com/ysy/car/service/CarService.java @@ -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 { + List getCarListByCarVO(CarVO carVO); + + + void recordAdd(RecordVO recordVO); + + void deleteState(List ids); + + List getTypeList(); + + void carAdd(Car car); +} diff --git a/ysy-modules/ysy-car/src/main/java/com/ysy/car/service/impl/CarServiceImpl.java b/ysy-modules/ysy-car/src/main/java/com/ysy/car/service/impl/CarServiceImpl.java new file mode 100644 index 0000000..2610fcd --- /dev/null +++ b/ysy-modules/ysy-car/src/main/java/com/ysy/car/service/impl/CarServiceImpl.java @@ -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 + 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 getCarListByCarVO(CarVO carVO) { + LambdaQueryWrapper 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 employeeList = new ArrayList<>(); + list.forEach(obj -> { + employeeList.add(JSON.parseObject(JSON.toJSONString(obj), Employee.class)); + }); + ArrayList ids = new ArrayList<>(); + employeeList.forEach(emp -> { + ids.add(emp.getEmpId()); + }); + lambdaQueryWrapper.in(Car::getEmpId, ids); + } + } + + List 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 ids) { + carMapper.deleteStateByIds(ids); + } + + @Override + public List 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); + } +} diff --git a/ysy-modules/ysy-car/src/main/resources/banner.txt b/ysy-modules/ysy-car/src/main/resources/banner.txt new file mode 100644 index 0000000..9a830ab --- /dev/null +++ b/ysy-modules/ysy-car/src/main/resources/banner.txt @@ -0,0 +1,9 @@ + ██ ██ ████████ ██ ██ +░░██ ██ ██░░░░░░ ░░██ ██ + ░░████ ░██ ░░████ + ░░██ ░█████████ ░░██ + ░██ ░░░░░░░░██ ░██ + ░██ ░██ ░██ + ░██ ████████ ░██ + ░░ ░░░░░░░░ ░░ +:: ysy boot :: version 1.0 \ No newline at end of file diff --git a/ysy-modules/ysy-car/src/main/resources/bootstrap.yml b/ysy-modules/ysy-car/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..d8d9287 --- /dev/null +++ b/ysy-modules/ysy-car/src/main/resources/bootstrap.yml @@ -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 + + + diff --git a/ysy-modules/ysy-car/src/main/resources/mapper/CarMapper.xml b/ysy-modules/ysy-car/src/main/resources/mapper/CarMapper.xml new file mode 100644 index 0000000..3f6fb85 --- /dev/null +++ b/ysy-modules/ysy-car/src/main/resources/mapper/CarMapper.xml @@ -0,0 +1,11 @@ + + + + + update tb_car set state = 0 where car_id in ( + + #{id} + + ) + + \ No newline at end of file diff --git a/ysy-modules/ysy-car/src/main/resources/mapper/RecordMapper.xml b/ysy-modules/ysy-car/src/main/resources/mapper/RecordMapper.xml new file mode 100644 index 0000000..97d852c --- /dev/null +++ b/ysy-modules/ysy-car/src/main/resources/mapper/RecordMapper.xml @@ -0,0 +1,7 @@ + + + + + insert into tb_record values (null, now(), #{id}, #{state}) + + \ No newline at end of file diff --git a/ysy-modules/ysy-car/src/main/resources/mapper/UserMapper.xml b/ysy-modules/ysy-car/src/main/resources/mapper/UserMapper.xml new file mode 100644 index 0000000..eed1d9a --- /dev/null +++ b/ysy-modules/ysy-car/src/main/resources/mapper/UserMapper.xml @@ -0,0 +1,7 @@ + + + + + insert into tb_user values (null, #{username}, #{phone}) + + \ No newline at end of file diff --git a/ysy-modules/ysy-employee/pom.xml b/ysy-modules/ysy-employee/pom.xml new file mode 100644 index 0000000..2c37966 --- /dev/null +++ b/ysy-modules/ysy-employee/pom.xml @@ -0,0 +1,41 @@ + + + 4.0.0 + + com.ysy + ysy-modules + 1.0-SNAPSHOT + + + ysy-employee-module + + + 17 + 17 + UTF-8 + + + + + + com.ysy + ysy-common + + + + + org.projectlombok + lombok + true + + + + + org.springframework.boot + spring-boot-starter-test + test + + + \ No newline at end of file diff --git a/ysy-modules/ysy-employee/src/main/java/com/ysy/employee/EmployeeServiceApplication.java b/ysy-modules/ysy-employee/src/main/java/com/ysy/employee/EmployeeServiceApplication.java new file mode 100644 index 0000000..238d175 --- /dev/null +++ b/ysy-modules/ysy-employee/src/main/java/com/ysy/employee/EmployeeServiceApplication.java @@ -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); + } +} \ No newline at end of file diff --git a/ysy-modules/ysy-employee/src/main/java/com/ysy/employee/controller/EmployeeController.java b/ysy-modules/ysy-employee/src/main/java/com/ysy/employee/controller/EmployeeController.java new file mode 100644 index 0000000..3903e2c --- /dev/null +++ b/ysy-modules/ysy-employee/src/main/java/com/ysy/employee/controller/EmployeeController.java @@ -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 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() + ); + } +} diff --git a/ysy-modules/ysy-employee/src/main/java/com/ysy/employee/mapper/EmployeeMapper.java b/ysy-modules/ysy-employee/src/main/java/com/ysy/employee/mapper/EmployeeMapper.java new file mode 100644 index 0000000..c3aa611 --- /dev/null +++ b/ysy-modules/ysy-employee/src/main/java/com/ysy/employee/mapper/EmployeeMapper.java @@ -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 { +} diff --git a/ysy-modules/ysy-employee/src/main/java/com/ysy/employee/service/EmployeeService.java b/ysy-modules/ysy-employee/src/main/java/com/ysy/employee/service/EmployeeService.java new file mode 100644 index 0000000..00c8d4a --- /dev/null +++ b/ysy-modules/ysy-employee/src/main/java/com/ysy/employee/service/EmployeeService.java @@ -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 { +} diff --git a/ysy-modules/ysy-employee/src/main/java/com/ysy/employee/service/impl/EmployeeServiceImpl.java b/ysy-modules/ysy-employee/src/main/java/com/ysy/employee/service/impl/EmployeeServiceImpl.java new file mode 100644 index 0000000..52bad13 --- /dev/null +++ b/ysy-modules/ysy-employee/src/main/java/com/ysy/employee/service/impl/EmployeeServiceImpl.java @@ -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 implements EmployeeService { + +} diff --git a/ysy-modules/ysy-employee/src/main/resources/banner.txt b/ysy-modules/ysy-employee/src/main/resources/banner.txt new file mode 100644 index 0000000..9a830ab --- /dev/null +++ b/ysy-modules/ysy-employee/src/main/resources/banner.txt @@ -0,0 +1,9 @@ + ██ ██ ████████ ██ ██ +░░██ ██ ██░░░░░░ ░░██ ██ + ░░████ ░██ ░░████ + ░░██ ░█████████ ░░██ + ░██ ░░░░░░░░██ ░██ + ░██ ░██ ░██ + ░██ ████████ ░██ + ░░ ░░░░░░░░ ░░ +:: ysy boot :: version 1.0 \ No newline at end of file diff --git a/ysy-modules/ysy-employee/src/main/resources/bootstrap.yml b/ysy-modules/ysy-employee/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..9c71ca4 --- /dev/null +++ b/ysy-modules/ysy-employee/src/main/resources/bootstrap.yml @@ -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 + + + diff --git a/ysy-modules/ysy-record/pom.xml b/ysy-modules/ysy-record/pom.xml new file mode 100644 index 0000000..0ce2d73 --- /dev/null +++ b/ysy-modules/ysy-record/pom.xml @@ -0,0 +1,41 @@ + + + 4.0.0 + + com.ysy + ysy-modules + 1.0-SNAPSHOT + + + ysy-record-module + + + 17 + 17 + UTF-8 + + + + + + com.ysy + ysy-common + + + + + org.projectlombok + lombok + true + + + + + org.springframework.boot + spring-boot-starter-test + test + + + \ No newline at end of file diff --git a/ysy-modules/ysy-record/src/main/java/com/ysy/Main.java b/ysy-modules/ysy-record/src/main/java/com/ysy/Main.java new file mode 100644 index 0000000..568a211 --- /dev/null +++ b/ysy-modules/ysy-record/src/main/java/com/ysy/Main.java @@ -0,0 +1,7 @@ +package com.ysy; + +public class Main { + public static void main(String[] args) { + System.out.println("Hello world!"); + } +} \ No newline at end of file