commit 5193c70565a2ab0f33af024f9ac22779e9183666 Author: zhanghaining <2218834824@qq.com> Date: Sat Sep 23 00:00:29 2023 +0800 first commit diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..35410ca --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# 默认忽略的文件 +/shelf/ +/workspace.xml +# 基于编辑器的 HTTP 客户端请求 +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..e8a41c1 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..8cfaa49 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..b1cfaf1 --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..67e1e61 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,12 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..6ba72ce --- /dev/null +++ b/pom.xml @@ -0,0 +1,103 @@ + + + 4.0.0 + + com.zhn + zhn-dev + pom + 1.0.0 + + zhn-common + zhn-gateway + zhn-auth + zhn-modules + + + + + + spring-boot-starter-parent + org.springframework.boot + 2.6.2 + + + + + + + + org.springframework.cloud + spring-cloud-dependencies + 2021.0.0 + pom + import + + + + com.alibaba.cloud + spring-cloud-alibaba-dependencies + 2021.1 + pom + import + + + + com.alibaba.nacos + nacos-client + 2.0.4 + + + + com.zhn + zhn-common + 1.0.0 + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 17 + 17 + + + + + + + + menghang-public + menghang公共 + http://124.221.216.186:8081/repository/maven-public/ + + + + + + menghang-release + menghang-releases + http://124.221.216.186:8081/repository/maven-releases/ + + + + + + public + aliyun nexus + https://maven.aliyun.com/repository/public + + true + + + false + + + + + diff --git a/zhn-auth/pom.xml b/zhn-auth/pom.xml new file mode 100644 index 0000000..1171181 --- /dev/null +++ b/zhn-auth/pom.xml @@ -0,0 +1,72 @@ + + + + zhn-dev + com.zhn + 1.0.0 + + 4.0.0 + + zhn-auth + + + + + com.zhn + zhn-common + + + + org.springframework.boot + spring-boot-starter-web + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 17 + 17 + + + + + + + + menghang-public + menghang公共 + http://124.221.216.186:8081/repository/maven-public/ + + + + + + menghang-release + menghang-releases + http://124.221.216.186:8081/repository/maven-releases/ + + + + + + + public + aliyun nexus + https://maven.aliyun.com/repository/public + + true + + + false + + + + + + + diff --git a/zhn-auth/src/main/java/com/zhn/auth/AuthMian.java b/zhn-auth/src/main/java/com/zhn/auth/AuthMian.java new file mode 100644 index 0000000..2c2b440 --- /dev/null +++ b/zhn-auth/src/main/java/com/zhn/auth/AuthMian.java @@ -0,0 +1,17 @@ +package com.zhn.auth; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.openfeign.EnableFeignClients; + + +/** + * @author DELL + */ +@SpringBootApplication +@EnableFeignClients +public class AuthMian { + public static void main(String[] args) { + SpringApplication.run(AuthMian.class, args); + } +} diff --git a/zhn-auth/src/main/java/com/zhn/auth/controller/AuthController.java b/zhn-auth/src/main/java/com/zhn/auth/controller/AuthController.java new file mode 100644 index 0000000..c2540d4 --- /dev/null +++ b/zhn-auth/src/main/java/com/zhn/auth/controller/AuthController.java @@ -0,0 +1,39 @@ +package com.zhn.auth.controller; + + +import com.zhn.auth.service.AuthService; +import com.zhn.common.domain.User; +import com.zhn.common.domain.request.RequestUser; +import com.zhn.common.domain.response.RespJwt; +import com.zhn.common.result.Result; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletRequest; + +/** + * @author DELL + */ +@RestController +public class AuthController { + @Autowired + AuthService authService; + + @PostMapping("/login") + Result login(@RequestBody RequestUser requestUser) { + + return authService.login(requestUser); + } + + + @GetMapping("/user/info") + Result userinfo(HttpServletRequest request) { + return authService.userinfo(request); + + } + + +} diff --git a/zhn-auth/src/main/java/com/zhn/auth/feign/AuthFeignSystem.java b/zhn-auth/src/main/java/com/zhn/auth/feign/AuthFeignSystem.java new file mode 100644 index 0000000..dbf984d --- /dev/null +++ b/zhn-auth/src/main/java/com/zhn/auth/feign/AuthFeignSystem.java @@ -0,0 +1,16 @@ +package com.zhn.auth.feign; + + +import com.zhn.common.domain.User; +import com.zhn.common.result.Result; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; + +@FeignClient("zhn-system") +public interface AuthFeignSystem { + @GetMapping("/user/byphone/{phone}") + Result byphone(@PathVariable String phone); + + +} diff --git a/zhn-auth/src/main/java/com/zhn/auth/service/AuthService.java b/zhn-auth/src/main/java/com/zhn/auth/service/AuthService.java new file mode 100644 index 0000000..8436289 --- /dev/null +++ b/zhn-auth/src/main/java/com/zhn/auth/service/AuthService.java @@ -0,0 +1,27 @@ +package com.zhn.auth.service; + +import com.zhn.common.domain.User; +import com.zhn.common.domain.request.RequestUser; +import com.zhn.common.domain.response.RespJwt; +import com.zhn.common.result.Result; + +import javax.servlet.http.HttpServletRequest; + +/** + * @author DELL + */ +public interface AuthService { + /** + * @Param requestUser + * @Return + * @描述: 登陆查询 + */ + Result login(RequestUser requestUser); + + /** + * @param request + * @return + * @描述: 鉴权 + */ + Result userinfo(HttpServletRequest request); +} diff --git a/zhn-auth/src/main/java/com/zhn/auth/service/impl/AuthServiceImpl.java b/zhn-auth/src/main/java/com/zhn/auth/service/impl/AuthServiceImpl.java new file mode 100644 index 0000000..22972ad --- /dev/null +++ b/zhn-auth/src/main/java/com/zhn/auth/service/impl/AuthServiceImpl.java @@ -0,0 +1,89 @@ +package com.zhn.auth.service.impl; + + +import com.alibaba.fastjson.JSONObject; +import com.zhn.auth.feign.AuthFeignSystem; +import com.zhn.auth.service.AuthService; +import com.zhn.common.constants.JwtConstants; +import com.zhn.common.constants.TokenConstants; +import com.zhn.common.domain.User; +import com.zhn.common.domain.request.RequestUser; +import com.zhn.common.domain.response.RespJwt; +import com.zhn.common.result.Result; +import com.zhn.common.utils.JwtUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Service; + +import javax.servlet.http.HttpServletRequest; +import java.util.HashMap; +import java.util.UUID; +import java.util.concurrent.TimeUnit; + +/** + * @author DELL + */ +@Service +public class AuthServiceImpl implements AuthService { + + @Autowired + AuthFeignSystem authFeignSystem; + + @Autowired + RedisTemplate redisTemplate; + + /** + * @param requestUser + * @return + */ + @Override + public Result login(RequestUser requestUser) { + String phone = requestUser.getPhone(); + String password = requestUser.getPassword(); + if (null == phone || null == password) { + return Result.error("联系管理员"); + } + if (phone.isEmpty() || password.isEmpty()) { + + return Result.error("请输入手机号+密码"); + } + Result byphone = authFeignSystem.byphone(phone); + User data = byphone.getData(); + if (null == data) { + return Result.error("先注册手机号,在登录"); + } + HashMap map = new HashMap<>(); + String userkey = UUID.randomUUID().toString().replaceAll("-", ""); + map.put(JwtConstants.USER_KEY, userkey); + map.put(JwtConstants.DETAILS_USER_ID, data.getId()); + String token = JwtUtils.createToken(map); + redisTemplate.opsForValue().set( + TokenConstants.LOGIN_TOKEN_KEY + userkey, + JSONObject.toJSONString(data), + TokenConstants.EXPIRATION, + TimeUnit.MINUTES + ); + RespJwt respJwt = new RespJwt(); + respJwt.setToken(token); + respJwt.setExpirationTime("720MIN"); + + return Result.success(respJwt); + } + + /** + * @param request + * @return + * @描述: 前台每次请求都会来到这里进行解析user + */ + @Override + public Result userinfo(HttpServletRequest request) { + String token = request.getHeader(TokenConstants.TOKEN); + String userKey = JwtUtils.getUserKey(token); + String s = redisTemplate.opsForValue().get( + TokenConstants.LOGIN_TOKEN_KEY + userKey + ); + User user = JSONObject.parseObject(s, User.class); + return Result.success(user); + } + +} diff --git a/zhn-auth/src/main/resources/ logback-spring.xml b/zhn-auth/src/main/resources/ logback-spring.xml new file mode 100644 index 0000000..284ae4f --- /dev/null +++ b/zhn-auth/src/main/resources/ logback-spring.xml @@ -0,0 +1,106 @@ + + + + + + + + + + + + + + + + + info + + + ${CONSOLE_LOG_PATTERN} + UTF-8 + + + + + + + + + + + + + + + + + ${logger.path}/log_info.log + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n + UTF-8 + + + + + ${logger.path}/info/log-info-%d{yyyy-MM-dd}.%i.log + + 100MB + + + 15 + + + + info + ACCEPT + DENY + + + + + + + ${logger.path}/log_error.log + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n + UTF-8 + + + + ${logger.path}/error/log-error-%d{yyyy-MM-dd}.%i.log + + 100MB + + + 15 + + + + ERROR + ACCEPT + DENY + + + + + + + + + + + + + + diff --git a/zhn-auth/src/main/resources/bootstrap.yml b/zhn-auth/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..612ed28 --- /dev/null +++ b/zhn-auth/src/main/resources/bootstrap.yml @@ -0,0 +1,41 @@ +# Tomcat +server: + port: 9001 +# Spring +spring: + main: + allow-bean-definition-overriding: true + allow-circular-references: true + + jackson: + date-format: yyyy-MM-dd HH:mm:ss + time-zone: GMT+8 + application: + # 应用名称 + name: zhn-auth + profiles: + # 环境配置 + active: dev + cloud: + nacos: + discovery: + # 服务注册地址 + server-addr: 124.221.216.186:8848 + namespace: zhn + config: + # 配置中心地址 + server-addr: 124.221.216.186:8848 + # 配置文件格式 + file-extension: yml + # 共享配置 + shared-configs: + - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} + namespace: zhn +management: + endpoints: + web: + exposure: + include: 'prometheus' + metrics: + tags: + application: ${spring.application.name} diff --git a/zhn-auth/src/main/resources/mapper/AuthMapper.xml b/zhn-auth/src/main/resources/mapper/AuthMapper.xml new file mode 100644 index 0000000..697c9a5 --- /dev/null +++ b/zhn-auth/src/main/resources/mapper/AuthMapper.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/zhn-common/pom.xml b/zhn-common/pom.xml new file mode 100644 index 0000000..ec347c6 --- /dev/null +++ b/zhn-common/pom.xml @@ -0,0 +1,160 @@ + + + + zhn-dev + com.zhn + 1.0.0 + + 4.0.0 + + zhn-common + + + UTF-8 + UTF-8 + + + + + org.springframework.cloud + spring-cloud-starter-bootstrap + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-config + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-sentinel + + + + org.springframework.cloud + spring-cloud-starter-loadbalancer + + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + + io.jsonwebtoken + jjwt + 0.9.1 + + + + com.alibaba + fastjson + 1.2.80 + + + + org.springframework.boot + spring-boot-starter-data-redis + + + + org.springframework.boot + spring-boot-starter-validation + + + + org.apache.commons + commons-lang3 + + + + org.projectlombok + lombok + + + + cn.hutool + hutool-all + 5.8.3 + + + + com.aliyun + dysmsapi20170525 + 2.0.1 + + + + com.aliyun.oss + aliyun-sdk-oss + 3.12.0 + + + org.apache.skywalking + apm-toolkit-logback-1.x + 8.0.1 + + + org.apache.skywalking + apm-toolkit-trace + 8.0.1 + + + org.springframework.boot + spring-boot-starter-actuator + + + io.micrometer + micrometer-registry-prometheus + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 17 + 17 + + + + + + + + menghang-public + menghang公共 + http://124.221.216.186:8081/repository/maven-public/ + + + + + + menghang-release + menghang-releases + http://124.221.216.186:8081/repository/maven-releases/ + + + + + + public + aliyun nexus + https://maven.aliyun.com/repository/public + + true + + + false + + + + diff --git a/zhn-common/src/main/java/com/zhn/common/constants/Constants.java b/zhn-common/src/main/java/com/zhn/common/constants/Constants.java new file mode 100644 index 0000000..875bed5 --- /dev/null +++ b/zhn-common/src/main/java/com/zhn/common/constants/Constants.java @@ -0,0 +1,18 @@ +package com.zhn.common.constants; + +/** + * @author zhn + * @description: 系统常量 + */ +public class Constants { + /** + * 成功标记 + */ + public static final Integer SUCCESS = 200; + public static final String SUCCESS_MSG = "操作成功"; + /** + * 失败标记 + */ + public static final Integer ERROR = 500; + public static final String ERROR_MSG = "操作异常"; +} diff --git a/zhn-common/src/main/java/com/zhn/common/constants/JwtConstants.java b/zhn-common/src/main/java/com/zhn/common/constants/JwtConstants.java new file mode 100644 index 0000000..e240c98 --- /dev/null +++ b/zhn-common/src/main/java/com/zhn/common/constants/JwtConstants.java @@ -0,0 +1,29 @@ +package com.zhn.common.constants; + +/** + * @author zhn + * @description: Jwt常量 + */ +public class JwtConstants { + + /** + * 用户ID字段 + */ + public static final String DETAILS_USER_ID = "user_id"; + + /** + * 用户名字段 + */ + public static final String DETAILS_USERNAME = "username"; + + /** + * 用户标识 + */ + public static final String USER_KEY = "user_key"; + + /** + * 令牌秘钥 + */ + public final static String SECRET = "abcdefghijklmnopqrstuvwxyz"; + +} diff --git a/zhn-common/src/main/java/com/zhn/common/constants/TokenConstants.java b/zhn-common/src/main/java/com/zhn/common/constants/TokenConstants.java new file mode 100644 index 0000000..0add0a0 --- /dev/null +++ b/zhn-common/src/main/java/com/zhn/common/constants/TokenConstants.java @@ -0,0 +1,24 @@ +package com.zhn.common.constants; + +/** + * @author zhn + * @description: 令牌常量 + */ +public class TokenConstants { + /** + * 缓存有效期,默认720(分钟) + */ + public final static long EXPIRATION = 720; + /** + * 缓存刷新时间,默认120(分钟) + */ + public final static long REFRESH_TIME = 120; + /** + * 权限缓存前缀 + */ + public final static String LOGIN_TOKEN_KEY = "login_tokens:"; + /** + * token标识 + */ + public static final String TOKEN = "token"; +} diff --git a/zhn-common/src/main/java/com/zhn/common/domain/BankCards.java b/zhn-common/src/main/java/com/zhn/common/domain/BankCards.java new file mode 100644 index 0000000..e1792c8 --- /dev/null +++ b/zhn-common/src/main/java/com/zhn/common/domain/BankCards.java @@ -0,0 +1,16 @@ +package com.zhn.common.domain; + +import lombok.Data; + +/** + * @author DELL + */ +@Data +public class BankCards { + private String id; + private String uid; + private String accountBank; + private String balance; + + +} diff --git a/zhn-common/src/main/java/com/zhn/common/domain/Booking.java b/zhn-common/src/main/java/com/zhn/common/domain/Booking.java new file mode 100644 index 0000000..bbf47ce --- /dev/null +++ b/zhn-common/src/main/java/com/zhn/common/domain/Booking.java @@ -0,0 +1,17 @@ +package com.zhn.common.domain; + +import lombok.Data; + +/** + * @author DELL + */ +@Data +public class Booking { + + private String id; + private String hid; + private String buyPrice; + private String deposit; + private String bcid; + private String ack; +} diff --git a/zhn-common/src/main/java/com/zhn/common/domain/Houses.java b/zhn-common/src/main/java/com/zhn/common/domain/Houses.java new file mode 100644 index 0000000..e27d0ca --- /dev/null +++ b/zhn-common/src/main/java/com/zhn/common/domain/Houses.java @@ -0,0 +1,16 @@ +package com.zhn.common.domain; + +import lombok.Data; + +/** + * @author DELL + */ +@Data +public class Houses { + + private String id; + private String prices; + private String sizeHouse; + private String totalPriceHouse; + +} diff --git a/zhn-common/src/main/java/com/zhn/common/domain/Ntermediate.java b/zhn-common/src/main/java/com/zhn/common/domain/Ntermediate.java new file mode 100644 index 0000000..d130e70 --- /dev/null +++ b/zhn-common/src/main/java/com/zhn/common/domain/Ntermediate.java @@ -0,0 +1,14 @@ +package com.zhn.common.domain; + +import lombok.Data; + +/** + * @author DELL + */ +@Data +public class Ntermediate { + private String id; + private String uid; + private String bid; + private String pid; +} diff --git a/zhn-common/src/main/java/com/zhn/common/domain/Purchase.java b/zhn-common/src/main/java/com/zhn/common/domain/Purchase.java new file mode 100644 index 0000000..256dcfc --- /dev/null +++ b/zhn-common/src/main/java/com/zhn/common/domain/Purchase.java @@ -0,0 +1,16 @@ +package com.zhn.common.domain; + +import lombok.Data; + +/** + * @author DELL + */ +@Data +public class Purchase { + private String id; + private String totalPriceHouse; + private String acklooking; + private String buyPrice; + private String bcid; + +} diff --git a/zhn-common/src/main/java/com/zhn/common/domain/User.java b/zhn-common/src/main/java/com/zhn/common/domain/User.java new file mode 100644 index 0000000..a289835 --- /dev/null +++ b/zhn-common/src/main/java/com/zhn/common/domain/User.java @@ -0,0 +1,19 @@ +package com.zhn.common.domain; + +import lombok.Data; + +/** + * @author DELL + */ +@Data +public class User { + + private String id; //用户id + private String username; //用户名 + private String password; //密码 + private String phone; //手机号 + private String sum; //余额 + private String landingTime; //登陆时间 + private String onlineStatus; //在线状态 + +} diff --git a/zhn-common/src/main/java/com/zhn/common/domain/request/ReqList.java b/zhn-common/src/main/java/com/zhn/common/domain/request/ReqList.java new file mode 100644 index 0000000..ff92c21 --- /dev/null +++ b/zhn-common/src/main/java/com/zhn/common/domain/request/ReqList.java @@ -0,0 +1,44 @@ +package com.zhn.common.domain.request; + +import lombok.Data; + +@Data +public class ReqList { + private String id; + //银行卡id + private String uid; + //用户id + private String accountBank; + //开户行 + private String balance; + //余额 + private String hid; + //房子id + private String buyPrice; + //买入价格 + private String deposit; + //定金 + private String bcid; + //银行卡id + private String ack; + // 确认 + private String prices; + // 房屋单价 + private String sizeHouse; + // 房屋面积 + private String totalPriceHouse; + // 房屋总价 + private String bid; + //预约编号 + private String pid; + //购买编号 + private String acklooking; + //确认预约 + private String username; + private String password; + private String phone; + private String sum; + private String landingTime; + private String onlineStatus; + +} diff --git a/zhn-common/src/main/java/com/zhn/common/domain/request/RequestUser.java b/zhn-common/src/main/java/com/zhn/common/domain/request/RequestUser.java new file mode 100644 index 0000000..d16867d --- /dev/null +++ b/zhn-common/src/main/java/com/zhn/common/domain/request/RequestUser.java @@ -0,0 +1,17 @@ +package com.zhn.common.domain.request; + + +import lombok.Data; + +@Data +public class RequestUser { + private String id; //用户id + private String username; //用户名 + private String password; //密码 + private String phone; //手机号 + private String sum; //余额 + private String landingTime; //登陆时间 + private String onlineStatus; //在线状态 + + +} diff --git a/zhn-common/src/main/java/com/zhn/common/domain/response/RespJwt.java b/zhn-common/src/main/java/com/zhn/common/domain/response/RespJwt.java new file mode 100644 index 0000000..7d3ec13 --- /dev/null +++ b/zhn-common/src/main/java/com/zhn/common/domain/response/RespJwt.java @@ -0,0 +1,13 @@ +package com.zhn.common.domain.response; + +import lombok.Data; + + +/** + * @author DELL + */ +@Data +public class RespJwt { + private String token; + private String expirationTime; +} diff --git a/zhn-common/src/main/java/com/zhn/common/domain/response/RespList.java b/zhn-common/src/main/java/com/zhn/common/domain/response/RespList.java new file mode 100644 index 0000000..3e2cd35 --- /dev/null +++ b/zhn-common/src/main/java/com/zhn/common/domain/response/RespList.java @@ -0,0 +1,46 @@ +package com.zhn.common.domain.response; + +import lombok.Data; + +/** + * @author DELL + */ +@Data +public class RespList { + private String id; + //银行卡id + private String uid; + //用户id + private String accountBank; + //开户行 + private String balance; + //余额 + private String hid; + //房子id + private String buyPrice; + //买入价格 + private String deposit; + //定金 + private String bcid; + //银行卡id + private String ack; + // 确认 + private String prices; + // 房屋单价 + private String sizeHouse; + // 房屋面积 + private String totalPriceHouse; + // 房屋总价 + private String bid; + //预约编号 + private String pid; + //购买编号 + private String acklooking; + //确认预约 + private String username; + private String password; + private String phone; + private String sum; + private String landingTime; + private String onlineStatus; +} diff --git a/zhn-common/src/main/java/com/zhn/common/domain/response/ResponseUser.java b/zhn-common/src/main/java/com/zhn/common/domain/response/ResponseUser.java new file mode 100644 index 0000000..75830d6 --- /dev/null +++ b/zhn-common/src/main/java/com/zhn/common/domain/response/ResponseUser.java @@ -0,0 +1,19 @@ +package com.zhn.common.domain.response; + + +import lombok.Data; + +/** + * @author DELL + */ +@Data +public class ResponseUser { + private String id; //用户id + private String username; //用户名 + private String password; //密码 + private String phone; //手机号 + private String sum; //余额 + private String landingTime; //登陆时间 + private String onlineStatus; //在线状态 + +} diff --git a/zhn-common/src/main/java/com/zhn/common/result/PageResult.java b/zhn-common/src/main/java/com/zhn/common/result/PageResult.java new file mode 100644 index 0000000..33e4030 --- /dev/null +++ b/zhn-common/src/main/java/com/zhn/common/result/PageResult.java @@ -0,0 +1,38 @@ +package com.zhn.common.result; + +import lombok.Data; + +import java.io.Serializable; +import java.util.List; + +/** + * @author zhn + * @description: 列表返回结果集 + */ +@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/zhn-common/src/main/java/com/zhn/common/result/Result.java b/zhn-common/src/main/java/com/zhn/common/result/Result.java new file mode 100644 index 0000000..5d9a28b --- /dev/null +++ b/zhn-common/src/main/java/com/zhn/common/result/Result.java @@ -0,0 +1,76 @@ +package com.zhn.common.result; + +import com.zhn.common.constants.Constants; +import lombok.Data; + +import java.io.Serializable; + +/** + * @author zhn + * @description: 响应信息主体 + */ +@Data +public class Result implements Serializable { + + /** + * 成功 + */ + public static final int SUCCESS = Constants.SUCCESS; + /** + * 失败 + */ + public static final int FAIL = Constants.ERROR; + private static final long serialVersionUID = 1L; + /** + * 返回状态码 + */ + private int code; + /** + * 响应信息 + */ + private String msg; + /** + * 响应数据 + */ + private T data; + + public static Result success() { + return restResult(null, SUCCESS, Constants.SUCCESS_MSG); + } + + public static Result success(T data) { + return restResult(data, SUCCESS, Constants.SUCCESS_MSG); + } + + public static Result success(T data, String msg) { + return restResult(data, SUCCESS, msg); + } + + public static Result error() { + return restResult(null, FAIL, Constants.ERROR_MSG); + } + + public static Result error(String msg) { + return restResult(null, FAIL, msg); + } + + public static Result error(T data) { + return restResult(data, FAIL, Constants.ERROR_MSG); + } + + public static Result error(T data, String msg) { + return restResult(data, FAIL, msg); + } + + public static Result error(int code, String msg) { + return restResult(null, code, msg); + } + + private static Result restResult(T data, int code, String msg) { + Result apiResult = new Result<>(); + apiResult.setCode(code); + apiResult.setData(data); + apiResult.setMsg(msg); + return apiResult; + } +} diff --git a/zhn-common/src/main/java/com/zhn/common/utils/JwtUtils.java b/zhn-common/src/main/java/com/zhn/common/utils/JwtUtils.java new file mode 100644 index 0000000..8630ff1 --- /dev/null +++ b/zhn-common/src/main/java/com/zhn/common/utils/JwtUtils.java @@ -0,0 +1,116 @@ +package com.zhn.common.utils; + +import com.zhn.common.constants.JwtConstants; +import io.jsonwebtoken.Claims; +import io.jsonwebtoken.Jwts; +import io.jsonwebtoken.SignatureAlgorithm; + +import java.util.Map; + +/** + * @author zhn + * @description: Jwt工具类 + */ +public class JwtUtils { + + /** + * 秘钥 + */ + public static String secret = JwtConstants.SECRET; + + /** + * 从数据声明生成令牌 + * + * @param claims 数据声明 + * @return 令牌 + */ + public static String createToken(Map claims) { + String token = Jwts.builder().setClaims(claims).signWith(SignatureAlgorithm.HS512, secret).compact(); + return token; + } + + /** + * 从令牌中获取数据声明 + * + * @param token 令牌 + * @return 数据声明 + */ + public static Claims parseToken(String token) { + return Jwts.parser().setSigningKey(secret).parseClaimsJws(token).getBody(); + } + + /** + * 根据令牌获取用户标识 + * + * @param token 令牌 + * @return 用户ID + */ + public static String getUserKey(String token) { + Claims claims = parseToken(token); + return getValue(claims, JwtConstants.USER_KEY); + } + + /** + * 根据令牌获取用户标识 + * + * @param claims 身份信息 + * @return 用户ID + */ + public static String getUserKey(Claims claims) { + return getValue(claims, JwtConstants.USER_KEY); + } + + /** + * 根据令牌获取用户ID + * + * @param token 令牌 + * @return 用户ID + */ + public static String getUserId(String token) { + Claims claims = parseToken(token); + return getValue(claims, JwtConstants.DETAILS_USER_ID); + } + + /** + * 根据身份信息获取用户ID + * + * @param claims 身份信息 + * @return 用户ID + */ + public static String getUserId(Claims claims) { + return getValue(claims, JwtConstants.DETAILS_USER_ID); + } + + /** + * 根据令牌获取用户名 + * + * @param token 令牌 + * @return 用户名 + */ + public static String getUserName(String token) { + Claims claims = parseToken(token); + return getValue(claims, JwtConstants.DETAILS_USERNAME); + } + + /** + * 根据身份信息获取用户名 + * + * @param claims 身份信息 + * @return 用户名 + */ + public static String getUserName(Claims claims) { + return getValue(claims, JwtConstants.DETAILS_USERNAME); + } + + /** + * 根据身份信息获取键值 + * + * @param claims 身份信息 + * @param key 键 + * @return 值 + */ + public static String getValue(Claims claims, String key) { + Object obj = claims.get(key); + return obj == null ? "" : obj.toString(); + } +} diff --git a/zhn-common/src/main/java/com/zhn/common/utils/Msg/HttpUtils.java b/zhn-common/src/main/java/com/zhn/common/utils/Msg/HttpUtils.java new file mode 100644 index 0000000..8a8e974 --- /dev/null +++ b/zhn-common/src/main/java/com/zhn/common/utils/Msg/HttpUtils.java @@ -0,0 +1,318 @@ +package com.zhn.common.utils.Msg; + +import com.zhn.common.utils.StringUtils; +import org.apache.http.HttpResponse; +import org.apache.http.NameValuePair; +import org.apache.http.client.HttpClient; +import org.apache.http.client.entity.UrlEncodedFormEntity; +import org.apache.http.client.methods.HttpDelete; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.client.methods.HttpPut; +import org.apache.http.conn.ClientConnectionManager; +import org.apache.http.conn.scheme.Scheme; +import org.apache.http.conn.scheme.SchemeRegistry; +import org.apache.http.conn.ssl.SSLSocketFactory; +import org.apache.http.entity.ByteArrayEntity; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.DefaultHttpClient; +import org.apache.http.message.BasicNameValuePair; + +import javax.net.ssl.SSLContext; +import javax.net.ssl.TrustManager; +import javax.net.ssl.X509TrustManager; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.security.KeyManagementException; +import java.security.NoSuchAlgorithmException; +import java.security.cert.X509Certificate; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public class HttpUtils { + + /** + * get + * + * @param host + * @param path + * @param method + * @param headers + * @param querys + * @return + * @throws Exception + */ + public static HttpResponse doGet(String host, String path, String method, + Map headers, + Map querys) + throws Exception { + HttpClient httpClient = wrapClient(host); + + HttpGet request = new HttpGet(buildUrl(host, path, querys)); + for (Map.Entry e : headers.entrySet()) { + request.addHeader(e.getKey(), e.getValue()); + } + + return httpClient.execute(request); + } + + /** + * post form + * + * @param host + * @param path + * @param method + * @param headers + * @param querys + * @param bodys + * @return + * @throws Exception + */ + public static HttpResponse doPost(String host, String path, String method, + Map headers, + Map querys, + Map bodys) + throws Exception { + HttpClient httpClient = wrapClient(host); + + HttpPost request = new HttpPost(buildUrl(host, path, querys)); + for (Map.Entry e : headers.entrySet()) { + request.addHeader(e.getKey(), e.getValue()); + } + + if (bodys != null) { + List nameValuePairList = new ArrayList(); + + for (String key : bodys.keySet()) { + nameValuePairList.add(new BasicNameValuePair(key, bodys.get(key))); + } + UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(nameValuePairList, "utf-8"); + formEntity.setContentType("application/x-www-form-urlencoded; charset=UTF-8"); + request.setEntity(formEntity); + } + + return httpClient.execute(request); + } + + /** + * Post String + * + * @param host + * @param path + * @param method + * @param headers + * @param querys + * @param body + * @return + * @throws Exception + */ + public static HttpResponse doPost(String host, String path, String method, + Map headers, + Map querys, + String body) + throws Exception { + HttpClient httpClient = wrapClient(host); + + HttpPost request = new HttpPost(buildUrl(host, path, querys)); + for (Map.Entry e : headers.entrySet()) { + request.addHeader(e.getKey(), e.getValue()); + } + + if (StringUtils.isNotBlank(body)) { + request.setEntity(new StringEntity(body, "utf-8")); + } + + return httpClient.execute(request); + } + + /** + * Post stream + * + * @param host + * @param path + * @param method + * @param headers + * @param querys + * @param body + * @return + * @throws Exception + */ + public static HttpResponse doPost(String host, String path, String method, + Map headers, + Map querys, + byte[] body) + throws Exception { + HttpClient httpClient = wrapClient(host); + + HttpPost request = new HttpPost(buildUrl(host, path, querys)); + for (Map.Entry e : headers.entrySet()) { + request.addHeader(e.getKey(), e.getValue()); + } + + if (body != null) { + request.setEntity(new ByteArrayEntity(body)); + } + + return httpClient.execute(request); + } + + /** + * Put String + * + * @param host + * @param path + * @param method + * @param headers + * @param querys + * @param body + * @return + * @throws Exception + */ + public static HttpResponse doPut(String host, String path, String method, + Map headers, + Map querys, + String body) + throws Exception { + HttpClient httpClient = wrapClient(host); + + HttpPut request = new HttpPut(buildUrl(host, path, querys)); + for (Map.Entry e : headers.entrySet()) { + request.addHeader(e.getKey(), e.getValue()); + } + + if (StringUtils.isNotBlank(body)) { + request.setEntity(new StringEntity(body, "utf-8")); + } + + return httpClient.execute(request); + } + + /** + * Put stream + * + * @param host + * @param path + * @param method + * @param headers + * @param querys + * @param body + * @return + * @throws Exception + */ + public static HttpResponse doPut(String host, String path, String method, + Map headers, + Map querys, + byte[] body) + throws Exception { + HttpClient httpClient = wrapClient(host); + + HttpPut request = new HttpPut(buildUrl(host, path, querys)); + for (Map.Entry e : headers.entrySet()) { + request.addHeader(e.getKey(), e.getValue()); + } + + if (body != null) { + request.setEntity(new ByteArrayEntity(body)); + } + + return httpClient.execute(request); + } + + /** + * Delete + * + * @param host + * @param path + * @param method + * @param headers + * @param querys + * @return + * @throws Exception + */ + public static HttpResponse doDelete(String host, String path, String method, + Map headers, + Map querys) + throws Exception { + HttpClient httpClient = wrapClient(host); + + HttpDelete request = new HttpDelete(buildUrl(host, path, querys)); + for (Map.Entry e : headers.entrySet()) { + request.addHeader(e.getKey(), e.getValue()); + } + + return httpClient.execute(request); + } + + private static String buildUrl(String host, String path, Map querys) throws UnsupportedEncodingException { + StringBuilder sbUrl = new StringBuilder(); + sbUrl.append(host); + if (!StringUtils.isBlank(path)) { + sbUrl.append(path); + } + if (null != querys) { + StringBuilder sbQuery = new StringBuilder(); + for (Map.Entry query : querys.entrySet()) { + if (0 < sbQuery.length()) { + sbQuery.append("&"); + } + if (StringUtils.isBlank(query.getKey()) && !StringUtils.isBlank(query.getValue())) { + sbQuery.append(query.getValue()); + } + if (!StringUtils.isBlank(query.getKey())) { + sbQuery.append(query.getKey()); + if (!StringUtils.isBlank(query.getValue())) { + sbQuery.append("="); + sbQuery.append(URLEncoder.encode(query.getValue(), "utf-8")); + } + } + } + if (0 < sbQuery.length()) { + sbUrl.append("?").append(sbQuery); + } + } + + return sbUrl.toString(); + } + + private static HttpClient wrapClient(String host) { + HttpClient httpClient = new DefaultHttpClient(); + if (host.startsWith("https://")) { + sslClient(httpClient); + } + + return httpClient; + } + + private static void sslClient(HttpClient httpClient) { + try { + SSLContext ctx = SSLContext.getInstance("TLS"); + X509TrustManager tm = new X509TrustManager() { + @Override + public X509Certificate[] getAcceptedIssuers() { + return null; + } + + @Override + public void checkClientTrusted(X509Certificate[] xcs, String str) { + + } + + @Override + public void checkServerTrusted(X509Certificate[] xcs, String str) { + + } + }; + ctx.init(null, new TrustManager[]{tm}, null); + SSLSocketFactory ssf = new SSLSocketFactory(ctx); + ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); + ClientConnectionManager ccm = httpClient.getConnectionManager(); + SchemeRegistry registry = ccm.getSchemeRegistry(); + registry.register(new Scheme("https", 443, ssf)); + } catch (KeyManagementException ex) { + throw new RuntimeException(ex); + } catch (NoSuchAlgorithmException ex) { + throw new RuntimeException(ex); + } + } +} diff --git a/zhn-common/src/main/java/com/zhn/common/utils/Msg/MsgUtil.java b/zhn-common/src/main/java/com/zhn/common/utils/Msg/MsgUtil.java new file mode 100644 index 0000000..926ec5f --- /dev/null +++ b/zhn-common/src/main/java/com/zhn/common/utils/Msg/MsgUtil.java @@ -0,0 +1,40 @@ +package com.zhn.common.utils.Msg; + + +import org.apache.http.HttpResponse; + +import java.util.HashMap; +import java.util.Map; + +/** + * @author + * @version 1.0.0 + * @ClassName MsgUtil.java + * @Description TODO + * @createTime 2022年05月26日 15:49:00 + */ +public class MsgUtil { + + + public static void sendMsg(String phone, String code) { + String host = "http://dingxin.market.alicloudapi.com"; + String path = "/dx/sendSms"; + String method = "POST"; + String appcode = "6519301ba878422488063fe815c9910"; + Map headers = new HashMap(); + headers.put("Authorization", "APPCODE " + appcode); + Map querys = new HashMap(); + querys.put("mobile", phone); + querys.put("param", "code:" + code); + querys.put("tpl_id", "TP1711063"); + Map bodys = new HashMap(); + + try { + + HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys); + System.out.println(response.toString()); + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/zhn-common/src/main/java/com/zhn/common/utils/OssUtil.java b/zhn-common/src/main/java/com/zhn/common/utils/OssUtil.java new file mode 100644 index 0000000..4d0fcef --- /dev/null +++ b/zhn-common/src/main/java/com/zhn/common/utils/OssUtil.java @@ -0,0 +1,162 @@ +package com.zhn.common.utils; + +import com.aliyun.oss.OSS; +import com.aliyun.oss.OSSClientBuilder; +import com.aliyun.oss.model.GetObjectRequest; +import com.aliyun.oss.model.PutObjectRequest; +import lombok.extern.log4j.Log4j2; +import org.springframework.web.multipart.MultipartFile; + +import java.io.*; +import java.time.LocalDateTime; +import java.util.UUID; + +/** + * Oss服务调用 + */ +@Log4j2 +public class OssUtil { + + /** + * Endpoint 存储对象概述 阿里云主账号AccessKey,accessKeySecret拥有所有API的访问权限 访问路径前缀 存储对象概述 + */ + private static String endPoint = "oss-cn-shanghai.aliyuncs.com"; + private static String accessKeyId = "LTAI5tGupmX9LkM6mEcmrbX7"; + private static String accessKeySecret = "4phVRUQpFcEk7Olar6E8mDfTA5JOlc"; + private static String accessPre = "https://liuxiaoting.oss-cn-shanghai.aliyuncs.com/"; + + /** + * bucket名称 + * + * @return + */ + private static String bucketName = "liuxiaoting"; + + private static OSS ossClient; + + static { + ossClient = new OSSClientBuilder().build( + endPoint, + accessKeyId, + accessKeySecret); + log.info("oss服务连接成功!"); + } + + /** + * 默认路径上传本地文件 + * + * @param filePath + */ + public static String uploadFile(String filePath) { + return uploadFileForBucket(bucketName, getOssFilePath(filePath), filePath); + } + + /** + * 默认路径上传multipartFile文件 + * + * @param multipartFile + */ + public static String uploadMultipartFile(MultipartFile multipartFile) { + return uploadMultipartFile(bucketName, getOssFilePath(multipartFile.getOriginalFilename()), multipartFile); + } + + /** + * 上传 multipartFile 类型文件 + * + * @param bucketName + * @param ossPath + * @param multipartFile + */ + public static String uploadMultipartFile(String bucketName, String ossPath, MultipartFile multipartFile) { + InputStream inputStream = null; + try { + inputStream = multipartFile.getInputStream(); + } catch (IOException e) { + e.printStackTrace(); + } + uploadFileInputStreamForBucket(bucketName, ossPath, inputStream); + return accessPre + ossPath; + } + + /** + * 使用File上传PutObject上传文件 ** 程序默认使用次方法上传 + * + * @param bucketName 实例名称 + * @param ossPath oss存储路径 + * @param filePath 本地文件路径 + */ + public static String uploadFileForBucket(String bucketName, String ossPath, String filePath) { + // 创建PutObjectRequest对象。 + PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, ossPath, new File(filePath)); + + // 上传 + ossClient.putObject(putObjectRequest); + return accessPre + ossPath; + } + + /** + * 使用文件流上传到指定的bucket实例 + * + * @param bucketName 实例名称 + * @param ossPath oss存储路径 + * @param filePath 本地文件路径 + */ + public static String uploadFileInputStreamForBucket(String bucketName, String ossPath, String filePath) { + + // 填写本地文件的完整路径。如果未指定本地路径,则默认从示例程序所属项目对应本地路径中上传文件流。 + InputStream inputStream = null; + try { + inputStream = new FileInputStream(filePath); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + // 填写Bucket名称和Object完整路径。Object完整路径中不能包含Bucket名称。 + uploadFileInputStreamForBucket(bucketName, ossPath, inputStream); + return accessPre + ossPath; + } + + public static void uploadFileInputStreamForBucket(String bucketName, String ossPath, InputStream inputStream) { + ossClient.putObject(bucketName, ossPath, inputStream); + } + + /** + * 下载 + * + * @param ossFilePath + * @param filePath + */ + public static void downloadFile(String ossFilePath, String filePath) { + downloadFileForBucket(bucketName, ossFilePath, filePath); + } + + /** + * 下载 + * + * @param bucketName 实例名称 + * @param ossFilePath oss存储路径 + * @param filePath 本地文件路径 + */ + public static void downloadFileForBucket(String bucketName, String ossFilePath, String filePath) { + ossClient.getObject(new GetObjectRequest(bucketName, ossFilePath), new File(filePath)); + } + + /** + * @return + */ + public static String getOssDefaultPath() { + LocalDateTime now = LocalDateTime.now(); + String url = + now.getYear() + "/" + + now.getMonth() + "/" + + now.getDayOfMonth() + "/" + + now.getHour() + "/" + + now.getMinute() + "/"; + return url; + } + + public static String getOssFilePath(String filePath) { + String fileSuf = filePath.substring(filePath.indexOf(".") + 1); + return getOssDefaultPath() + UUID.randomUUID().toString() + "." + fileSuf; + } + +} diff --git a/zhn-common/src/main/java/com/zhn/common/utils/StringUtils.java b/zhn-common/src/main/java/com/zhn/common/utils/StringUtils.java new file mode 100644 index 0000000..cb3d7a4 --- /dev/null +++ b/zhn-common/src/main/java/com/zhn/common/utils/StringUtils.java @@ -0,0 +1,67 @@ +package com.zhn.common.utils; + +import org.springframework.util.AntPathMatcher; + +import java.util.Collection; +import java.util.List; + +/** + * @author zhn + * @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/zhn-common/src/main/java/com/zhn/common/utils/TelSmsUtils.java b/zhn-common/src/main/java/com/zhn/common/utils/TelSmsUtils.java new file mode 100644 index 0000000..3d10e61 --- /dev/null +++ b/zhn-common/src/main/java/com/zhn/common/utils/TelSmsUtils.java @@ -0,0 +1,90 @@ +package com.zhn.common.utils; + +import com.alibaba.fastjson.JSONObject; +import com.aliyun.dysmsapi20170525.Client; +import com.aliyun.dysmsapi20170525.models.SendSmsRequest; +import com.aliyun.dysmsapi20170525.models.SendSmsResponse; +import com.aliyun.teaopenapi.models.Config; +import lombok.extern.log4j.Log4j2; + +import java.util.Map; + +/** + * 短信工具类 + */ +@Log4j2 +public class TelSmsUtils { + + /** + * 阿里云主账号AccessKey,accessKeySecret拥有所有API的访问权限 + */ + private static String accessKeyId = "LTAIEVXszCmcd1T5"; + private static String accessKeySecret = "2zHwciQXln8wExSEnkIYtRTSwLeRNd"; + + /** + * 短信访问域名 + */ + private static String endpoint = "dysmsapi.aliyuncs.com"; + /** + * 短信签名 + */ + private static String signName = "登录验证"; + + /** + * 实例化短信对象 + */ + private static Client client; + + static { + log.info("初始化短信服务开始"); + long startTime = System.currentTimeMillis(); + try { + client = initClient(); + log.info("初始化短信成功:{}", signName); + } catch (Exception e) { + e.printStackTrace(); + } + log.info("初始化短信服务结束:耗时:{}MS", (System.currentTimeMillis() - startTime)); + } + + /** + * 初始化短信对象 + * + * @return + * @throws Exception + */ + private static Client initClient() throws Exception { + Config config = new Config() + // 您的AccessKey ID + .setAccessKeyId(accessKeyId) + // 您的AccessKey Secret + .setAccessKeySecret(accessKeySecret); + // 访问的域名 + config.endpoint = endpoint; + return new Client(config); + } + + /** + * 发送单条短信 + * + * @param tel + * @param templateCode SMS_153991546 + * @param sendDataMap + */ + public static String sendSms(String tel, String templateCode, Map sendDataMap) { + SendSmsRequest sendSmsRequest = new SendSmsRequest() + .setPhoneNumbers(tel) + .setSignName(signName) + .setTemplateCode(templateCode) + .setTemplateParam(JSONObject.toJSONString(sendDataMap)); + SendSmsResponse sendSmsResponse = null; + try { + log.info("发送短信验证码:消息内容是:【{}】", JSONObject.toJSONString(sendDataMap)); + sendSmsResponse = client.sendSms(sendSmsRequest); + } catch (Exception e) { + log.error("短信发送异常,手机号:【{}】,短信内容:【{}】,异常信息:【{}】", tel, sendDataMap, e); + } + return JSONObject.toJSONString(sendSmsResponse.getBody()); + } + +} diff --git a/zhn-common/src/main/resources/date.txt b/zhn-common/src/main/resources/date.txt new file mode 100644 index 0000000..b6760bd --- /dev/null +++ b/zhn-common/src/main/resources/date.txt @@ -0,0 +1 @@ +数据源文件 \ No newline at end of file diff --git a/zhn-gateway/pom.xml b/zhn-gateway/pom.xml new file mode 100644 index 0000000..3355c4d --- /dev/null +++ b/zhn-gateway/pom.xml @@ -0,0 +1,80 @@ + + + + zhn-dev + com.zhn + 1.0.0 + + 4.0.0 + + zhn-gateway + + + + + com.zhn + zhn-common + + + + + org.springframework.cloud + spring-cloud-starter-gateway + + + + com.alibaba.cloud + spring-cloud-alibaba-sentinel-gateway + + + + com.alibaba.csp + sentinel-spring-cloud-gateway-adapter + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 17 + 17 + + + + + + + + menghang-public + menghang公共 + http://124.221.216.186:8081/repository/maven-public/ + + + + + + menghang-release + menghang-releases + http://124.221.216.186:8081/repository/maven-releases/ + + + + + + public + aliyun nexus + https://maven.aliyun.com/repository/public + + true + + + false + + + + + diff --git a/zhn-gateway/src/main/java/com/zhn/gateway/GatewayMian.java b/zhn-gateway/src/main/java/com/zhn/gateway/GatewayMian.java new file mode 100644 index 0000000..dd6e4d0 --- /dev/null +++ b/zhn-gateway/src/main/java/com/zhn/gateway/GatewayMian.java @@ -0,0 +1,14 @@ +package com.zhn.gateway; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * @author zhang + */ +@SpringBootApplication +public class GatewayMian { + public static void main(String[] args) { + SpringApplication.run(GatewayMian.class, args); + } +} diff --git a/zhn-gateway/src/main/java/com/zhn/gateway/config/IgnoreWhiteConfig.java b/zhn-gateway/src/main/java/com/zhn/gateway/config/IgnoreWhiteConfig.java new file mode 100644 index 0000000..3f4fc6b --- /dev/null +++ b/zhn-gateway/src/main/java/com/zhn/gateway/config/IgnoreWhiteConfig.java @@ -0,0 +1,32 @@ +package com.zhn.gateway.config; + +import com.alibaba.fastjson.JSONObject; +import lombok.Data; +import lombok.extern.log4j.Log4j2; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.cloud.context.config.annotation.RefreshScope; +import org.springframework.context.annotation.Configuration; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author zhn + * @description: 放行白名单配置 + */ +@Configuration +@RefreshScope +@ConfigurationProperties(prefix = "ignore") +@Data +@Log4j2 +public class IgnoreWhiteConfig { + /** + * 放行白名单配置,网关不校验此处的白名单 + */ + private List whites = new ArrayList<>(); + + public void setWhites(List whites) { + log.info("加载网关路径白名单:{}", JSONObject.toJSONString(whites)); + this.whites = whites; + } +} diff --git a/zhn-gateway/src/main/java/com/zhn/gateway/constants/Constants.java b/zhn-gateway/src/main/java/com/zhn/gateway/constants/Constants.java new file mode 100644 index 0000000..8b1a582 --- /dev/null +++ b/zhn-gateway/src/main/java/com/zhn/gateway/constants/Constants.java @@ -0,0 +1,4 @@ +package com.zhn.gateway.constants; + +public class Constants { +} diff --git a/zhn-gateway/src/main/java/com/zhn/gateway/filters/AuthFilters.java b/zhn-gateway/src/main/java/com/zhn/gateway/filters/AuthFilters.java new file mode 100644 index 0000000..12aad0c --- /dev/null +++ b/zhn-gateway/src/main/java/com/zhn/gateway/filters/AuthFilters.java @@ -0,0 +1,62 @@ +package com.zhn.gateway.filters; + +import com.zhn.common.constants.TokenConstants; +import com.zhn.common.utils.JwtUtils; +import com.zhn.common.utils.StringUtils; +import com.zhn.gateway.config.IgnoreWhiteConfig; +import com.zhn.gateway.utils.GatewayUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cloud.gateway.filter.GatewayFilterChain; +import org.springframework.cloud.gateway.filter.GlobalFilter; +import org.springframework.core.Ordered; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.http.HttpStatus; +import org.springframework.http.server.reactive.ServerHttpRequest; +import org.springframework.stereotype.Component; +import org.springframework.web.server.ServerWebExchange; +import reactor.core.publisher.Mono; + +import java.util.List; + +@Component +public class AuthFilters implements GlobalFilter, Ordered { + + @Autowired + private IgnoreWhiteConfig ignoreWhitesConfig; + + @Autowired + private RedisTemplate redisTemplate; + + @Override + public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) { + List whites = ignoreWhitesConfig.getWhites(); + ServerHttpRequest request = exchange.getRequest(); + String path = request.getURI().getPath(); + if (StringUtils.matches(path, whites)) { + return chain.filter(exchange); + } + String token = request.getHeaders().getFirst(TokenConstants.TOKEN); + if (StringUtils.isEmpty(token)) { + return GatewayUtils.errorResponse(exchange, "token不能为空!", HttpStatus.UNAUTHORIZED); + } + try { + JwtUtils.parseToken(token); + } catch (Exception e) { + return GatewayUtils.errorResponse(exchange, "token不合法!"); + } + String userKey = JwtUtils.getUserKey(token); + Boolean hasKey = redisTemplate.hasKey(TokenConstants.LOGIN_TOKEN_KEY + userKey); + if (null == hasKey || !hasKey) { + return GatewayUtils.errorResponse(exchange, "token过期!"); + } + + //redisTemplate.expire(TokenConstants.LOGIN_TOKEN_KEY + userKey, 15, TimeUnit.MINUTES); + + return chain.filter(exchange); + } + + @Override + public int getOrder() { + return 0; + } +} diff --git a/zhn-gateway/src/main/java/com/zhn/gateway/utils/GatewayUtils.java b/zhn-gateway/src/main/java/com/zhn/gateway/utils/GatewayUtils.java new file mode 100644 index 0000000..58be7db --- /dev/null +++ b/zhn-gateway/src/main/java/com/zhn/gateway/utils/GatewayUtils.java @@ -0,0 +1,102 @@ +package com.zhn.gateway.utils; + +import com.alibaba.fastjson.JSONObject; +import com.zhn.common.result.Result; +import com.zhn.common.utils.StringUtils; +import lombok.extern.log4j.Log4j2; +import org.springframework.core.io.buffer.DataBuffer; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.server.reactive.ServerHttpRequest; +import org.springframework.http.server.reactive.ServerHttpResponse; +import org.springframework.web.server.ServerWebExchange; +import reactor.core.publisher.Mono; + +/** + * @author zhn + * @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, HttpStatus httpStatus) { + ServerHttpResponse response = exchange.getResponse(); + //设置HTTP响应头状态 + response.setStatusCode(httpStatus); + //设置HTTP响应头文本格式 + response.getHeaders().add(HttpHeaders.CONTENT_TYPE, "application/json"); + //定义响应内容 + Result result = Result.error(msg); + String resultJson = JSONObject.toJSONString(result); + log.error("[鉴权异常处理]请求路径:[{}],异常信息:[{}],响应结果:[{}]", exchange.getRequest().getPath(), msg, resultJson); + DataBuffer dataBuffer = response.bufferFactory().wrap(resultJson.getBytes()); + //进行响应 + return response.writeWith(Mono.just(dataBuffer)); + } + + /** + * 错误结果响应 + * + * @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"); + //定义响应内容 + Result result = Result.error(msg); + String resultJson = JSONObject.toJSONString(result); + log.error("[鉴权异常处理]请求路径:[{}],异常信息:[{}],响应结果:[{}]", exchange.getRequest().getPath(), msg, resultJson); + DataBuffer dataBuffer = response.bufferFactory().wrap(resultJson.getBytes()); + //进行响应 + return response.writeWith(Mono.just(dataBuffer)); + } + + +} diff --git a/zhn-gateway/src/main/resources/bootstrap.yml b/zhn-gateway/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..109d1a7 --- /dev/null +++ b/zhn-gateway/src/main/resources/bootstrap.yml @@ -0,0 +1,31 @@ +# Tomcat +server: + port: 18080 +# Spring +spring: + application: + # 应用名称 + name: zhn-gateway + profiles: + # 环境配置 + active: dev + main: + # 允许使用循环引用 + allow-circular-references: true + # 允许定义相同的bean对象 去覆盖原有的 + allow-bean-definition-overriding: true + cloud: + nacos: + discovery: + # 服务注册地址 + server-addr: 124.221.216.186:8848 + namespace: zhn + config: + # 配置中心地址 + server-addr: 124.221.216.186:8848 + # 配置文件格式 + file-extension: yml + # 共享配置 + shared-configs: + - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} + namespace: zhn diff --git a/zhn-modules/pom.xml b/zhn-modules/pom.xml new file mode 100644 index 0000000..923e7cd --- /dev/null +++ b/zhn-modules/pom.xml @@ -0,0 +1,60 @@ + + + + zhn-dev + com.zhn + 1.0.0 + + 4.0.0 + + zhn-modules + pom + + zhn-system + zhn-houses + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 17 + 17 + + + + + + + + menghang-public + menghang公共 + http://124.221.216.186:8081/repository/maven-public/ + + + + + + menghang-release + menghang-releases + http://124.221.216.186:8081/repository/maven-releases/ + + + + + + public + aliyun nexus + https://maven.aliyun.com/repository/public + + true + + + false + + + + diff --git a/zhn-modules/zhn-houses/pom.xml b/zhn-modules/zhn-houses/pom.xml new file mode 100644 index 0000000..58cf79d --- /dev/null +++ b/zhn-modules/zhn-houses/pom.xml @@ -0,0 +1,96 @@ + + + 4.0.0 + + com.zhn + zhn-modules + 1.0.0 + + + zhn-houses + + + 17 + 17 + UTF-8 + + + + + com.zhn + zhn-common + + + + org.springframework.boot + spring-boot-starter-web + + + + com.alibaba + druid-spring-boot-starter + 1.2.8 + + + + mysql + mysql-connector-java + + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + 2.2.2 + + + + com.github.pagehelper + pagehelper-spring-boot-starter + 1.4.1 + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 17 + 17 + + + + + + + + menghang-public + menghang公共 + http://124.221.216.186:8081/repository/maven-public/ + + + + + + menghang-release + menghang-releases + http://124.221.216.186:8081/repository/maven-releases/ + + + + + + public + aliyun nexus + https://maven.aliyun.com/repository/public + + true + + + false + + + + diff --git a/zhn-modules/zhn-houses/src/main/java/com/zhn/houses/HousesMain.java b/zhn-modules/zhn-houses/src/main/java/com/zhn/houses/HousesMain.java new file mode 100644 index 0000000..b097510 --- /dev/null +++ b/zhn-modules/zhn-houses/src/main/java/com/zhn/houses/HousesMain.java @@ -0,0 +1,16 @@ +package com.zhn.houses; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * @author DELL + */ +@SpringBootApplication +public class HousesMain { + + public static void main(String[] args) { + SpringApplication.run(HousesMain.class, args); + } + +} diff --git a/zhn-modules/zhn-houses/src/main/java/com/zhn/houses/controller/HousesController.java b/zhn-modules/zhn-houses/src/main/java/com/zhn/houses/controller/HousesController.java new file mode 100644 index 0000000..ac0eefe --- /dev/null +++ b/zhn-modules/zhn-houses/src/main/java/com/zhn/houses/controller/HousesController.java @@ -0,0 +1,36 @@ +package com.zhn.houses.controller; + +import com.zhn.common.domain.Houses; +import com.zhn.common.domain.request.ReqList; +import com.zhn.common.result.Result; +import com.zhn.houses.service.HousesService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +/** + * @author DELL + */ +@RestController +@RequestMapping("/houses") +public class HousesController { + @Autowired + HousesService housesService; + + /** + * @param reqList + * @return Result> + */ + @GetMapping("/getHouses") + public Result> getHouses(@RequestBody ReqList reqList) { + + + return housesService.getHouses(reqList); + } + + +} diff --git a/zhn-modules/zhn-houses/src/main/java/com/zhn/houses/mapper/HousesMapper.java b/zhn-modules/zhn-houses/src/main/java/com/zhn/houses/mapper/HousesMapper.java new file mode 100644 index 0000000..299acae --- /dev/null +++ b/zhn-modules/zhn-houses/src/main/java/com/zhn/houses/mapper/HousesMapper.java @@ -0,0 +1,21 @@ +package com.zhn.houses.mapper; + +import com.zhn.common.domain.Houses; +import com.zhn.common.domain.request.ReqList; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + +/** + * @author DELL + */ +@Mapper +public interface HousesMapper { + + + /** + * @param reqList + * @return + */ + List getHouses(ReqList reqList); +} diff --git a/zhn-modules/zhn-houses/src/main/java/com/zhn/houses/service/HousesService.java b/zhn-modules/zhn-houses/src/main/java/com/zhn/houses/service/HousesService.java new file mode 100644 index 0000000..8a3e5b8 --- /dev/null +++ b/zhn-modules/zhn-houses/src/main/java/com/zhn/houses/service/HousesService.java @@ -0,0 +1,16 @@ +package com.zhn.houses.service; + +import com.zhn.common.domain.Houses; +import com.zhn.common.domain.request.ReqList; +import com.zhn.common.result.Result; + +import java.util.List; + +public interface HousesService { + /** + * @param reqList + * @return + * @描述: 查询房子 + */ + Result> getHouses(ReqList reqList); +} diff --git a/zhn-modules/zhn-houses/src/main/java/com/zhn/houses/service/impl/HousesServiceImpl.java b/zhn-modules/zhn-houses/src/main/java/com/zhn/houses/service/impl/HousesServiceImpl.java new file mode 100644 index 0000000..71447e0 --- /dev/null +++ b/zhn-modules/zhn-houses/src/main/java/com/zhn/houses/service/impl/HousesServiceImpl.java @@ -0,0 +1,32 @@ +package com.zhn.houses.service.impl; + +import com.zhn.common.domain.Houses; +import com.zhn.common.domain.request.ReqList; +import com.zhn.common.result.Result; +import com.zhn.houses.mapper.HousesMapper; +import com.zhn.houses.service.HousesService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * @author DELL + */ +@Service +public class HousesServiceImpl implements HousesService { + + @Autowired + HousesMapper housesMapper; + + /** + * @param reqList + * @return + * @描述: 查询房子 + */ + @Override + public Result> getHouses(ReqList reqList) { + List list = housesMapper.getHouses(reqList); + return Result.success(list); + } +} diff --git a/zhn-modules/zhn-houses/src/main/resources/bootstrap.yml b/zhn-modules/zhn-houses/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..c9543fe --- /dev/null +++ b/zhn-modules/zhn-houses/src/main/resources/bootstrap.yml @@ -0,0 +1,32 @@ +# Tomcat +server: + port: 9003 +# Spring +spring: + main: + allow-bean-definition-overriding: true + allow-circular-references: true + jackson: + date-format: yyyy-MM-dd HH:mm:ss + time-zone: GMT+8 + application: + # 应用名称 + name: zhn-houses + profiles: + # 环境配置 + active: dev + cloud: + nacos: + discovery: + # 服务注册地址 + server-addr: 124.221.216.186:8848 + namespace: zhn + config: + # 配置中心地址 + server-addr: 124.221.216.186:8848 + # 配置文件格式 + file-extension: yml + # 共享配置 + shared-configs: + - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} + namespace: zhn diff --git a/zhn-modules/zhn-houses/src/main/resources/mappers/HousesMapper.xml b/zhn-modules/zhn-houses/src/main/resources/mappers/HousesMapper.xml new file mode 100644 index 0000000..37d91df --- /dev/null +++ b/zhn-modules/zhn-houses/src/main/resources/mappers/HousesMapper.xml @@ -0,0 +1,12 @@ + + + + + select * + from houses + + + diff --git a/zhn-modules/zhn-system/pom.xml b/zhn-modules/zhn-system/pom.xml new file mode 100644 index 0000000..a3812da --- /dev/null +++ b/zhn-modules/zhn-system/pom.xml @@ -0,0 +1,126 @@ + + + + zhn-modules + com.zhn + 1.0.0 + + 4.0.0 + + zhn-system + + + + + com.zhn + zhn-common + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-websocket + + + + + com.alibaba + druid-spring-boot-starter + 1.2.8 + + + + mysql + mysql-connector-java + + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + 2.2.2 + + + + com.github.pagehelper + pagehelper-spring-boot-starter + 1.4.1 + + + + org.springframework.boot + spring-boot-starter-amqp + + + + com.fasterxml.jackson.dataformat + jackson-dataformat-xml + 2.9.10 + + + + org.elasticsearch.client + elasticsearch-rest-high-level-client + + + + org.redisson + redisson + 2.7.0 + + + org.springframework.boot + spring-boot-starter-websocket + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 17 + 17 + + + + + + + + menghang-public + menghang公共 + http://124.221.216.186:8081/repository/maven-public/ + + + + + + menghang-release + menghang-releases + http://124.221.216.186:8081/repository/maven-releases/ + + + + + + public + aliyun nexus + https://maven.aliyun.com/repository/public + + true + + + false + + + + + + diff --git a/zhn-modules/zhn-system/src/main/java/com/zhn/system/SystemMian.java b/zhn-modules/zhn-system/src/main/java/com/zhn/system/SystemMian.java new file mode 100644 index 0000000..b41b75c --- /dev/null +++ b/zhn-modules/zhn-system/src/main/java/com/zhn/system/SystemMian.java @@ -0,0 +1,15 @@ +package com.zhn.system; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.openfeign.EnableFeignClients; +import org.springframework.scheduling.annotation.EnableScheduling; + +@SpringBootApplication +@EnableFeignClients +@EnableScheduling +public class SystemMian { + public static void main(String[] args) { + SpringApplication.run(SystemMian.class, args); + } +} diff --git a/zhn-modules/zhn-system/src/main/java/com/zhn/system/config/EsConfig.java b/zhn-modules/zhn-system/src/main/java/com/zhn/system/config/EsConfig.java new file mode 100644 index 0000000..2f82c5d --- /dev/null +++ b/zhn-modules/zhn-system/src/main/java/com/zhn/system/config/EsConfig.java @@ -0,0 +1,33 @@ +package com.zhn.system.config; + +import lombok.Data; +import lombok.extern.log4j.Log4j2; +import org.apache.http.HttpHost; +import org.elasticsearch.client.RestClient; +import org.elasticsearch.client.RestHighLevelClient; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +@ConfigurationProperties(prefix = "es") // 支持热部署 +@Data +@Log4j2 +public class EsConfig { + private String host; + private int port; + private String scheme; + + /** + * 初始化一个 RestHighLevelClient + */ + @Bean + public RestHighLevelClient init() { + log.info("获取的三要数是host:{},port:{},scheme:{}", host, port, scheme); + return new RestHighLevelClient( + RestClient.builder( + new HttpHost(host, port, scheme) + ) + ); + } +} diff --git a/zhn-modules/zhn-system/src/main/java/com/zhn/system/controller/UserController.java b/zhn-modules/zhn-system/src/main/java/com/zhn/system/controller/UserController.java new file mode 100644 index 0000000..78eed2f --- /dev/null +++ b/zhn-modules/zhn-system/src/main/java/com/zhn/system/controller/UserController.java @@ -0,0 +1,28 @@ +package com.zhn.system.controller; + + +import com.zhn.common.domain.User; +import com.zhn.common.result.Result; +import com.zhn.system.service.UserService; +import org.springframework.beans.factory.annotation.Autowired; +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("/user") +public class UserController { + + + @Autowired + UserService userService; + + @GetMapping("/byphone/{phone}") + Result byphone(@PathVariable String phone) { + + return userService.byphone(phone); + } + +} diff --git a/zhn-modules/zhn-system/src/main/java/com/zhn/system/mapper/UserMapper.java b/zhn-modules/zhn-system/src/main/java/com/zhn/system/mapper/UserMapper.java new file mode 100644 index 0000000..afc64a0 --- /dev/null +++ b/zhn-modules/zhn-system/src/main/java/com/zhn/system/mapper/UserMapper.java @@ -0,0 +1,16 @@ +package com.zhn.system.mapper; + + +import com.zhn.common.domain.User; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +/** + * @author DELL + */ +@Mapper +public interface UserMapper { + User byphone(@Param("phone") String phone); + + +} diff --git a/zhn-modules/zhn-system/src/main/java/com/zhn/system/service/UserService.java b/zhn-modules/zhn-system/src/main/java/com/zhn/system/service/UserService.java new file mode 100644 index 0000000..d7f5cb6 --- /dev/null +++ b/zhn-modules/zhn-system/src/main/java/com/zhn/system/service/UserService.java @@ -0,0 +1,9 @@ +package com.zhn.system.service; + +import com.zhn.common.domain.User; +import com.zhn.common.result.Result; + +public interface UserService { + Result byphone(String phone); + +} diff --git a/zhn-modules/zhn-system/src/main/java/com/zhn/system/service/impl/UserServiceImpl.java b/zhn-modules/zhn-system/src/main/java/com/zhn/system/service/impl/UserServiceImpl.java new file mode 100644 index 0000000..787e3b1 --- /dev/null +++ b/zhn-modules/zhn-system/src/main/java/com/zhn/system/service/impl/UserServiceImpl.java @@ -0,0 +1,24 @@ +package com.zhn.system.service.impl; + + +import com.zhn.common.domain.User; +import com.zhn.common.result.Result; +import com.zhn.system.mapper.UserMapper; +import com.zhn.system.service.UserService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class UserServiceImpl implements UserService { + @Autowired + UserMapper userMapper; + + @Override + public Result byphone(String phone) { + User user = userMapper.byphone(phone); + + return Result.success(user); + } + + +} diff --git a/zhn-modules/zhn-system/src/main/resources/bootstrap.yml b/zhn-modules/zhn-system/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..1df4e23 --- /dev/null +++ b/zhn-modules/zhn-system/src/main/resources/bootstrap.yml @@ -0,0 +1,44 @@ +server: + port: 9002 + +spring: + main: + allow-bean-definition-overriding: true + allow-circular-references: true + jackson: + date-format: yyyy-MM-dd HH:mm:ss + time-zone: GMT+8 + application: + name: zhn-system + profiles: + active: dev + cloud: + nacos: + discovery: + server-addr: 124.221.216.186:8848 + namespace: zhn + config: + server-addr: 124.221.216.186:8848 + file-extension: yml + shared-configs: + - "application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}" + namespace: zhn + rabbitmq: + host: 124.221.216.186 + port: 5672 + username: guest + password: guest + virtualHost: / + listener: + simple: + prefetch: 1 + acknowledge-mode: manual + retry: + enabled: true + publisher-confirm-type: correlated + publisher-returns: true + +es: + host: 124.221.216.186 + port: 9200 + scheme: http diff --git a/zhn-modules/zhn-system/src/main/resources/mappers/UserMapper.xml b/zhn-modules/zhn-system/src/main/resources/mappers/UserMapper.xml new file mode 100644 index 0000000..6a9bbed --- /dev/null +++ b/zhn-modules/zhn-system/src/main/resources/mappers/UserMapper.xml @@ -0,0 +1,16 @@ + + + + + + + +