From b488fcc97156d2a30d7c65949d6a20dbb287f034 Mon Sep 17 00:00:00 2001 From: jieyuu <645634619@qq.com> Date: Fri, 12 Apr 2024 15:37:31 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AC=AC=E4=B8=80=E6=AC=A1=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 38 ++++ .idea/.gitignore | 8 + .idea/encodings.xml | 19 ++ .idea/misc.xml | 13 ++ .idea/uiDesigner.xml | 124 ++++++++++++ .idea/vcs.xml | 6 + README.md | 1 + pom.xml | 177 ++++++++++++++++++ xdclass-common/pom.xml | 99 ++++++++++ .../jieyuu/config/SwaggerConfiguration.java | 118 ++++++++++++ .../java/net/jieyuu/enums/BizCodeEnum.java | 42 +++++ .../java/net/jieyuu/enums/SendCodeEnum.java | 5 + .../net/jieyuu/exception/BizException.java | 27 +++ .../exception/CustomExceptionHandle.java | 28 +++ .../main/java/net/jieyuu/utils/CheckUtil.java | 43 +++++ .../java/net/jieyuu/utils/CommonUtil.java | 93 +++++++++ .../main/java/net/jieyuu/utils/JsonData.java | 74 ++++++++ xdclass-coupon-service/pom.xml | 20 ++ xdclass-gateway/pom.xml | 20 ++ xdclass-order-service/pom.xml | 20 ++ xdclass-product-service/pom.xml | 21 +++ xdclass-user-service/pom.xml | 42 +++++ .../net/jieyuu/UserServiceApplication.java | 14 ++ .../net/jieyuu/component/MailService.java | 21 +++ .../component/impl/MailServiceImpl.java | 44 +++++ .../java/net/jieyuu/config/CaptchaConfig.java | 50 +++++ .../jieyuu/controller/AddressController.java | 37 ++++ .../jieyuu/controller/NotifyController.java | 124 ++++++++++++ .../net/jieyuu/controller/UserController.java | 39 ++++ .../java/net/jieyuu/mapper/AddressMapper.java | 16 ++ .../java/net/jieyuu/mapper/UserMapper.java | 16 ++ .../main/java/net/jieyuu/model/AddressDO.java | 72 +++++++ .../main/java/net/jieyuu/model/UserDO.java | 72 +++++++ .../net/jieyuu/service/AddressService.java | 20 ++ .../java/net/jieyuu/service/MailService.java | 21 +++ .../net/jieyuu/service/NotifyService.java | 9 + .../java/net/jieyuu/service/UserService.java | 16 ++ .../service/impl/AddressServiceImpl.java | 30 +++ .../jieyuu/service/impl/MailServiceImpl.java | 44 +++++ .../service/impl/NotifyServiceImpl.java | 56 ++++++ .../jieyuu/service/impl/UserServiceImpl.java | 20 ++ .../src/main/resources/application.yml | 39 ++++ .../main/resources/mapper/AddressMapper.xml | 24 +++ .../src/main/resources/mapper/UserMapper.xml | 24 +++ .../test/java/net/jieyuu/biz/AddressTest.java | 30 +++ .../test/java/net/jieyuu/biz/MailTest.java | 24 +++ .../net/jieyuu/db/MyBatisPlusGenerator.java | 94 ++++++++++ 47 files changed, 1994 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/.gitignore create mode 100644 .idea/encodings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/uiDesigner.xml create mode 100644 .idea/vcs.xml create mode 100644 pom.xml create mode 100644 xdclass-common/pom.xml create mode 100644 xdclass-common/src/main/java/net/jieyuu/config/SwaggerConfiguration.java create mode 100644 xdclass-common/src/main/java/net/jieyuu/enums/BizCodeEnum.java create mode 100644 xdclass-common/src/main/java/net/jieyuu/enums/SendCodeEnum.java create mode 100644 xdclass-common/src/main/java/net/jieyuu/exception/BizException.java create mode 100644 xdclass-common/src/main/java/net/jieyuu/exception/CustomExceptionHandle.java create mode 100644 xdclass-common/src/main/java/net/jieyuu/utils/CheckUtil.java create mode 100644 xdclass-common/src/main/java/net/jieyuu/utils/CommonUtil.java create mode 100644 xdclass-common/src/main/java/net/jieyuu/utils/JsonData.java create mode 100644 xdclass-coupon-service/pom.xml create mode 100644 xdclass-gateway/pom.xml create mode 100644 xdclass-order-service/pom.xml create mode 100644 xdclass-product-service/pom.xml create mode 100644 xdclass-user-service/pom.xml create mode 100644 xdclass-user-service/src/main/java/net/jieyuu/UserServiceApplication.java create mode 100644 xdclass-user-service/src/main/java/net/jieyuu/component/MailService.java create mode 100644 xdclass-user-service/src/main/java/net/jieyuu/component/impl/MailServiceImpl.java create mode 100644 xdclass-user-service/src/main/java/net/jieyuu/config/CaptchaConfig.java create mode 100644 xdclass-user-service/src/main/java/net/jieyuu/controller/AddressController.java create mode 100644 xdclass-user-service/src/main/java/net/jieyuu/controller/NotifyController.java create mode 100644 xdclass-user-service/src/main/java/net/jieyuu/controller/UserController.java create mode 100644 xdclass-user-service/src/main/java/net/jieyuu/mapper/AddressMapper.java create mode 100644 xdclass-user-service/src/main/java/net/jieyuu/mapper/UserMapper.java create mode 100644 xdclass-user-service/src/main/java/net/jieyuu/model/AddressDO.java create mode 100644 xdclass-user-service/src/main/java/net/jieyuu/model/UserDO.java create mode 100644 xdclass-user-service/src/main/java/net/jieyuu/service/AddressService.java create mode 100644 xdclass-user-service/src/main/java/net/jieyuu/service/MailService.java create mode 100644 xdclass-user-service/src/main/java/net/jieyuu/service/NotifyService.java create mode 100644 xdclass-user-service/src/main/java/net/jieyuu/service/UserService.java create mode 100644 xdclass-user-service/src/main/java/net/jieyuu/service/impl/AddressServiceImpl.java create mode 100644 xdclass-user-service/src/main/java/net/jieyuu/service/impl/MailServiceImpl.java create mode 100644 xdclass-user-service/src/main/java/net/jieyuu/service/impl/NotifyServiceImpl.java create mode 100644 xdclass-user-service/src/main/java/net/jieyuu/service/impl/UserServiceImpl.java create mode 100644 xdclass-user-service/src/main/resources/application.yml create mode 100644 xdclass-user-service/src/main/resources/mapper/AddressMapper.xml create mode 100644 xdclass-user-service/src/main/resources/mapper/UserMapper.xml create mode 100644 xdclass-user-service/src/test/java/net/jieyuu/biz/AddressTest.java create mode 100644 xdclass-user-service/src/test/java/net/jieyuu/biz/MailTest.java create mode 100644 xdclass-user-service/src/test/java/net/jieyuu/db/MyBatisPlusGenerator.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ 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/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..8d6ca3e --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..6f5230a --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,13 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ 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/README.md b/README.md index e69de29..b7599ac 100644 --- a/README.md +++ b/README.md @@ -0,0 +1 @@ +# xd课堂 \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..2d909db --- /dev/null +++ b/pom.xml @@ -0,0 +1,177 @@ + + + 4.0.0 + + net.jieyuu + xdclass-shop + 1.0-SNAPSHOT + pom + + xdclass-common + xdclass-product-service + xdclass-user-service + xdclass-order-service + xdclass-coupon-service + xdclass-gateway + + + + + 1.8 + 8 + 8 + UTF-8 + + 2.3.3.RELEASE + + Hoxton.SR8 + 2.2.1.RELEASE + + 3.4.0 + 1.18.16 + 3.9 + 1.15 + 3.0.0 + + xdclass-cloud + + + true + + + + + + + + + org.springframework.boot + spring-boot-dependencies + ${spring.boot.version} + pom + import + + + + + org.springframework.cloud + spring-cloud-dependencies + ${spring.cloud.version} + pom + import + + + + + com.alibaba.cloud + spring-cloud-alibaba-dependencies + ${alibaba.cloud.version} + pom + import + + + + + + + com.baomidou + mybatis-plus-boot-starter + ${mybatisplus.boot.starter.version} + + + + + + org.projectlombok + lombok + ${lombok.version} + + + + + + + + org.apache.commons + commons-lang3 + ${commons.lang3.version} + + + + + + commons-codec + commons-codec + ${commons.codec.version} + + + + + + + io.springfox + springfox-boot-starter + ${springfox.boot.starter.version} + + + + + com.baomidou + kaptcha-spring-boot-starter + 1.1.0 + + + + + + + + + + + maven-ali + http://maven.aliyun.com/nexus/content/groups/public// + + true + + + true + always + fail + + + + + + + + public + aliyun nexus + http://maven.aliyun.com/nexus/content/groups/public/ + + true + + + false + + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + ${spring.boot.version} + + true + true + + + + + + \ No newline at end of file diff --git a/xdclass-common/pom.xml b/xdclass-common/pom.xml new file mode 100644 index 0000000..44c33b3 --- /dev/null +++ b/xdclass-common/pom.xml @@ -0,0 +1,99 @@ + + + 4.0.0 + + net.jieyuu + xdclass-shop + 1.0-SNAPSHOT + + + xdclass-common + + + + org.projectlombok + lombok + + + + + org.springframework.boot + spring-boot-starter-web + + + + mysql + mysql-connector-java + + + + com.baomidou + mybatis-plus-boot-starter + + + + + com.baomidou + mybatis-plus-generator + 3.4.1 + + + + org.apache.velocity + velocity-engine-core + 2.0 + + + + + io.springfox + springfox-boot-starter + + + + + org.springframework.boot + spring-boot-starter-test + + + + + com.baomidou + kaptcha-spring-boot-starter + 1.1.0 + + + + + org.springframework.boot + spring-boot-starter-data-redis + + + io.lettuce + lettuce-core + + + + + + redis.clients + jedis + + + + + + + + 8 + 8 + UTF-8 + + + + + + + \ No newline at end of file diff --git a/xdclass-common/src/main/java/net/jieyuu/config/SwaggerConfiguration.java b/xdclass-common/src/main/java/net/jieyuu/config/SwaggerConfiguration.java new file mode 100644 index 0000000..494a74c --- /dev/null +++ b/xdclass-common/src/main/java/net/jieyuu/config/SwaggerConfiguration.java @@ -0,0 +1,118 @@ +package net.jieyuu.config; + + +import lombok.Data; +import org.springframework.context.annotation.Bean; +import org.springframework.http.HttpMethod; +import org.springframework.stereotype.Component; +import springfox.documentation.builders.*; +import springfox.documentation.oas.annotations.EnableOpenApi; +import springfox.documentation.schema.ScalarType; +import springfox.documentation.service.*; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; + +import java.util.ArrayList; +import java.util.List; + +@Component +@EnableOpenApi +@Data +public class SwaggerConfiguration { + + + /** + * C端文档 + * @return + */ + @Bean + public Docket webApiDoc() { + + + return new Docket(DocumentationType.OAS_30) + .groupName("用户端接口文档") + .pathMapping("/") + // 定义是否开启swagger,false为关闭,可以通过变量控制,线上关闭 + .enable(true) + //配置api文档元信息 + .apiInfo(apiInfo()) + // 选择哪些接口作为swagger的doc发布 + .select() + .apis(RequestHandlerSelectors.basePackage("net.jieyuu")) + //正则匹配请求路径,并分配至当前分组 + .paths(PathSelectors.ant("/api/**")) + .build() + //新版swagger3.0配置 + .globalRequestParameters(getGlobalRequestParameters()) + .globalResponses(HttpMethod.GET, getGlobalResponseMessage()) + .globalResponses(HttpMethod.POST, getGlobalResponseMessage()); + } + + + private ApiInfo apiInfo() { + return new ApiInfoBuilder() + .title("1024电商平台") + .description("微服务接口文档") + .contact(new Contact("jieyuu", "https://134.175.219.253", "645634619@qq.com")) + .version("12") + .build(); + } + + /** + * 管理端文档 + * @return + */ + @Bean + public Docket adminApiDoc() { + return new Docket(DocumentationType.OAS_30) + .groupName("管理端接口文档") + .pathMapping("/") + // 定义是否开启swagger,false为关闭,可以通过变量控制,线上关闭 + .enable(true) + //配置api文档元信息 + .apiInfo(apiInfo()) + // 选择哪些接口作为swagger的doc发布 + .select() + .apis(RequestHandlerSelectors.basePackage("net.jieyuu")) + //正则匹配请求路径,并分配至当前分组 + .paths(PathSelectors.ant("/admin/**")) + .build(); + } + + /** + * 生成全局通用参数, 支持配置多个响应参数 + * @return + */ + private List getGlobalRequestParameters() { + List parameters = new ArrayList<>(); + parameters.add(new RequestParameterBuilder() + .name("token") + .description("登录令牌") + .in(ParameterType.HEADER) + .query(q -> q.model(m -> m.scalarModel(ScalarType.STRING))) + .required(false) + .build()); + +// parameters.add(new RequestParameterBuilder() +// .name("version") +// .description("版本号") +// .required(true) +// .in(ParameterType.HEADER) +// .query(q -> q.model(m -> m.scalarModel(ScalarType.STRING))) +// .required(false) +// .build()); + return parameters; + } + + /** + * 生成通用响应信息 + * + * @return + */ + private List getGlobalResponseMessage() { + List responseList = new ArrayList<>(); + responseList.add(new ResponseBuilder().code("4xx").description("请求错误,根据code和msg检查").build()); + return responseList; + } + +} \ No newline at end of file diff --git a/xdclass-common/src/main/java/net/jieyuu/enums/BizCodeEnum.java b/xdclass-common/src/main/java/net/jieyuu/enums/BizCodeEnum.java new file mode 100644 index 0000000..c642712 --- /dev/null +++ b/xdclass-common/src/main/java/net/jieyuu/enums/BizCodeEnum.java @@ -0,0 +1,42 @@ +package net.jieyuu.enums; + +import lombok.Getter; + +/** + * @Description 状态码定义约束,共6位数,前三位代表服务,后4位代表接口 + * 比如 商品服务210,购物车是220、用户服务230,403代表权限 + **/ +public enum BizCodeEnum { + + + /** + * 通用操作码 + */ + OPS_REPEAT(110001, "重复操作"), + + /** + * 验证码 + */ + CODE_TO_ERROR(240001, "接收号码不合规"), + CODE_LIMITED(240002, "验证码发送过快"), + CODE_ERROR(240003, "验证码错误"), + CODE_CAPTCHA(240101, "图形验证码错误"), + + /** + * 账号 + */ + ACCOUNT_REPEAT(250001, "账号已经存在"), + ACCOUNT_UNREGISTER(250002, "账号不存在"), + ACCOUNT_PWD_ERROR(250003, "账号或者密码错误"); + + @Getter + private int code; + + @Getter + private String message; + + private BizCodeEnum(int code, String message) { + this.code = code; + this.message = message; + } +} \ No newline at end of file diff --git a/xdclass-common/src/main/java/net/jieyuu/enums/SendCodeEnum.java b/xdclass-common/src/main/java/net/jieyuu/enums/SendCodeEnum.java new file mode 100644 index 0000000..ec731b3 --- /dev/null +++ b/xdclass-common/src/main/java/net/jieyuu/enums/SendCodeEnum.java @@ -0,0 +1,5 @@ +package net.jieyuu.enums; + +public enum SendCodeEnum { + USER_REGISTER; +} diff --git a/xdclass-common/src/main/java/net/jieyuu/exception/BizException.java b/xdclass-common/src/main/java/net/jieyuu/exception/BizException.java new file mode 100644 index 0000000..7fac04e --- /dev/null +++ b/xdclass-common/src/main/java/net/jieyuu/exception/BizException.java @@ -0,0 +1,27 @@ +package net.jieyuu.exception; + +import lombok.Data; +import net.jieyuu.enums.BizCodeEnum; + +/** + * 全局异常处理 + */ +@Data +public class BizException extends RuntimeException { + + private Integer code; + private String msg; + + public BizException(Integer code, String message) { + super(message); + this.code = code; + this.msg = message; + } + + public BizException(BizCodeEnum bizCodeEnum) { + super(bizCodeEnum.getMessage()); + this.code = bizCodeEnum.getCode(); + this.msg = bizCodeEnum.getMessage(); + } + +} \ No newline at end of file diff --git a/xdclass-common/src/main/java/net/jieyuu/exception/CustomExceptionHandle.java b/xdclass-common/src/main/java/net/jieyuu/exception/CustomExceptionHandle.java new file mode 100644 index 0000000..c4a055a --- /dev/null +++ b/xdclass-common/src/main/java/net/jieyuu/exception/CustomExceptionHandle.java @@ -0,0 +1,28 @@ +package net.jieyuu.exception; + +import lombok.extern.slf4j.Slf4j; +import net.jieyuu.utils.JsonData; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.ResponseBody; + +@ControllerAdvice +@Slf4j +public class CustomExceptionHandle { + + @ExceptionHandler(value = Exception.class) + @ResponseBody + public JsonData Handle(Exception e) { + + if (e instanceof BizException) { + BizException bizException = (BizException) e; + log.info("[业务异常]{}", e); + return JsonData.buildCodeAndMsg(bizException.getCode(), bizException.getMsg()); + + } else { + log.info("[系统异常]{}", e); + return JsonData.buildError("全局异常,未知错误"); + } + + } +} \ No newline at end of file diff --git a/xdclass-common/src/main/java/net/jieyuu/utils/CheckUtil.java b/xdclass-common/src/main/java/net/jieyuu/utils/CheckUtil.java new file mode 100644 index 0000000..d9d33c0 --- /dev/null +++ b/xdclass-common/src/main/java/net/jieyuu/utils/CheckUtil.java @@ -0,0 +1,43 @@ +package net.jieyuu.utils; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class CheckUtil { + + /** + * 邮箱正则 + */ + private static final Pattern MAIL_PATTERN = Pattern.compile("^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$"); + + /** + * 手机号正则,暂时未用 + */ + private static final Pattern PHONE_PATTERN = Pattern.compile("^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$"); + + /** + * @param email + * @return + */ + public static boolean isEmail(String email) { + if (null == email || "".equals(email)) { + return false; + } + Matcher m = MAIL_PATTERN.matcher(email); + return m.matches(); + } + + /** + * 暂时未用 + * @param phone + * @return + */ + public static boolean isPhone(String phone) { + if (null == phone || "".equals(phone)) { + return false; + } + Matcher m = PHONE_PATTERN.matcher(phone); + return m.matches(); + + } +} \ No newline at end of file diff --git a/xdclass-common/src/main/java/net/jieyuu/utils/CommonUtil.java b/xdclass-common/src/main/java/net/jieyuu/utils/CommonUtil.java new file mode 100644 index 0000000..e70fd29 --- /dev/null +++ b/xdclass-common/src/main/java/net/jieyuu/utils/CommonUtil.java @@ -0,0 +1,93 @@ +package net.jieyuu.utils; + +import javax.servlet.http.HttpServletRequest; +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.security.MessageDigest; +import java.util.Random; + +public class CommonUtil { + + /** + * 获取ip + * + * @param request + * @return + */ + public static String getIpAddr(HttpServletRequest request) { + String ipAddress = null; + try { + ipAddress = request.getHeader("x-forwarded-for"); + if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) { + ipAddress = request.getHeader("Proxy-Client-IP"); + } + if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) { + ipAddress = request.getHeader("WL-Proxy-Client-IP"); + } + if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) { + ipAddress = request.getRemoteAddr(); + if (ipAddress.equals("127.0.0.1")) { + // 根据网卡取本机配置的IP + InetAddress inet = null; + try { + inet = InetAddress.getLocalHost(); + } catch (UnknownHostException e) { + e.printStackTrace(); + } + ipAddress = inet.getHostAddress(); + } + } + // 对于通过多个代理的情况,第一个IP为客户端真实IP,多个IP按照','分割 + if (ipAddress != null && ipAddress.length() > 15) { + // "***.***.***.***".length() + // = 15 + if (ipAddress.indexOf(",") > 0) { + ipAddress = ipAddress.substring(0, ipAddress.indexOf(",")); + } + } + } catch (Exception e) { + ipAddress = ""; + } + return ipAddress; + } + + + /** + * MD5加密 + * + * @param data + * @return + */ + public static String MD5(String data) { + try { + java.security.MessageDigest md = MessageDigest.getInstance("MD5"); + byte[] array = md.digest(data.getBytes("UTF-8")); + StringBuilder sb = new StringBuilder(); + for (byte item : array) { + sb.append(Integer.toHexString((item & 0xFF) | 0x100).substring(1, 3)); + } + + return sb.toString().toUpperCase(); + } catch (Exception exception) { + } + return null; + + } + + /** + * 生成随机数 + * @param length + * @return + */ + + public static String getRandomCode(int length) { + String sources = "0123456789"; + Random random = new Random(); + StringBuilder stringBuilder = new StringBuilder(); + for (int i = 0; i < length; i++) { + stringBuilder.append(sources.charAt(random.nextInt(9))); + } + return stringBuilder.toString(); + + } +} diff --git a/xdclass-common/src/main/java/net/jieyuu/utils/JsonData.java b/xdclass-common/src/main/java/net/jieyuu/utils/JsonData.java new file mode 100644 index 0000000..b9a7b6f --- /dev/null +++ b/xdclass-common/src/main/java/net/jieyuu/utils/JsonData.java @@ -0,0 +1,74 @@ +package net.jieyuu.utils; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import net.jieyuu.enums.BizCodeEnum; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class JsonData { + + /** + * 状态码 0 表示成功,1表示处理中,-1表示失败 + */ + private Integer code; + + /** + * 数据 + */ + private Object data; + + /** + * 描述 + */ + private String msg; + + + /** + * 成功,传入数据 + * @return + */ + public static JsonData buildSuccess() { + return new JsonData(0, null, null); + } + + /** + * 成功,传入数据 + * @param data + * @return + */ + public static JsonData buildSuccess(Object data) { + return new JsonData(0, data, null); + } + + /** + * 失败,传入描述信息 + * @param msg + * @return + */ + public static JsonData buildError(String msg) { + return new JsonData(-1, null, msg); + } + + + /** + * 自定义状态码和错误信息 + * @param code + * @param msg + * @return + */ + public static JsonData buildCodeAndMsg(int code, String msg) { + return new JsonData(code, null, msg); + } + + /** + * 传入枚举,返回信息 + * @param codeEnum + * @return + */ + public static JsonData buildResult(BizCodeEnum codeEnum){ + return JsonData.buildCodeAndMsg(codeEnum.getCode(),codeEnum.getMessage()); + } +} \ No newline at end of file diff --git a/xdclass-coupon-service/pom.xml b/xdclass-coupon-service/pom.xml new file mode 100644 index 0000000..c5fc622 --- /dev/null +++ b/xdclass-coupon-service/pom.xml @@ -0,0 +1,20 @@ + + + 4.0.0 + + net.jieyuu + xdclass-shop + 1.0-SNAPSHOT + + + xdclass-coupon-service + + + 8 + 8 + UTF-8 + + + \ No newline at end of file diff --git a/xdclass-gateway/pom.xml b/xdclass-gateway/pom.xml new file mode 100644 index 0000000..ff388a5 --- /dev/null +++ b/xdclass-gateway/pom.xml @@ -0,0 +1,20 @@ + + + 4.0.0 + + net.jieyuu + xdclass-shop + 1.0-SNAPSHOT + + + xdclass-gateway + + + 8 + 8 + UTF-8 + + + \ No newline at end of file diff --git a/xdclass-order-service/pom.xml b/xdclass-order-service/pom.xml new file mode 100644 index 0000000..e74bb64 --- /dev/null +++ b/xdclass-order-service/pom.xml @@ -0,0 +1,20 @@ + + + 4.0.0 + + net.jieyuu + xdclass-shop + 1.0-SNAPSHOT + + + xdclass-order-service + + + 8 + 8 + UTF-8 + + + \ No newline at end of file diff --git a/xdclass-product-service/pom.xml b/xdclass-product-service/pom.xml new file mode 100644 index 0000000..470ab74 --- /dev/null +++ b/xdclass-product-service/pom.xml @@ -0,0 +1,21 @@ + + + 4.0.0 + + net.jieyuu + xdclass-shop + 1.0-SNAPSHOT + + + xdclass-product-service + + + + 8 + 8 + UTF-8 + + + \ No newline at end of file diff --git a/xdclass-user-service/pom.xml b/xdclass-user-service/pom.xml new file mode 100644 index 0000000..a820e62 --- /dev/null +++ b/xdclass-user-service/pom.xml @@ -0,0 +1,42 @@ + + + 4.0.0 + + net.jieyuu + xdclass-shop + 1.0-SNAPSHOT + + + xdclass-user-service + + + + + net.jieyuu + xdclass-common + 1.0-SNAPSHOT + + + + com.baomidou + kaptcha-spring-boot-starter + + + + + org.springframework.boot + spring-boot-starter-mail + + + + + + 8 + 8 + UTF-8 + + + + \ No newline at end of file diff --git a/xdclass-user-service/src/main/java/net/jieyuu/UserServiceApplication.java b/xdclass-user-service/src/main/java/net/jieyuu/UserServiceApplication.java new file mode 100644 index 0000000..782f039 --- /dev/null +++ b/xdclass-user-service/src/main/java/net/jieyuu/UserServiceApplication.java @@ -0,0 +1,14 @@ +package net.jieyuu; + +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +@MapperScan("net.jieyuu.mapper") +public class UserServiceApplication { + + public static void main(String[] args) { + SpringApplication.run(UserServiceApplication.class, args); + } +} diff --git a/xdclass-user-service/src/main/java/net/jieyuu/component/MailService.java b/xdclass-user-service/src/main/java/net/jieyuu/component/MailService.java new file mode 100644 index 0000000..0909342 --- /dev/null +++ b/xdclass-user-service/src/main/java/net/jieyuu/component/MailService.java @@ -0,0 +1,21 @@ +package net.jieyuu.component; + + +/** + *

+ * 邮件发送类 + *

+ * + * @author jieyuu + * @since 2024-02-12 + */ +public interface MailService { + + /** + * 发送邮件 + * @param to + * @param subject + * @param content + */ + public void sendMail(String to, String subject, String content); +} diff --git a/xdclass-user-service/src/main/java/net/jieyuu/component/impl/MailServiceImpl.java b/xdclass-user-service/src/main/java/net/jieyuu/component/impl/MailServiceImpl.java new file mode 100644 index 0000000..b41c9a8 --- /dev/null +++ b/xdclass-user-service/src/main/java/net/jieyuu/component/impl/MailServiceImpl.java @@ -0,0 +1,44 @@ +package net.jieyuu.component.impl; + + +import lombok.extern.slf4j.Slf4j; +import net.jieyuu.component.MailService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.mail.SimpleMailMessage; +import org.springframework.mail.javamail.JavaMailSender; +import org.springframework.stereotype.Service; + +@Service +@Slf4j +public class MailServiceImpl implements MailService { + + /** + * Spring Boot 提供了一个发送邮件的简单抽象,直接注入即可使用 + */ + @Autowired + private JavaMailSender mailSender; + + /** + * 配置文件中的发送邮箱 + */ + @Value("${spring.mail.from}") + private String from; + + @Override + public void sendMail(String to, String subject, String content) { + //创建SimpleMailMessage对象 + SimpleMailMessage message = new SimpleMailMessage(); + //邮件发送人 + message.setFrom(from); + //邮件接收人 + message.setTo(to); + //邮件主题 + message.setSubject(subject); + //邮件内容 + message.setText(content); + //发送邮件 + mailSender.send(message); + log.info("邮件发成功:{}", message.toString()); + } +} \ No newline at end of file diff --git a/xdclass-user-service/src/main/java/net/jieyuu/config/CaptchaConfig.java b/xdclass-user-service/src/main/java/net/jieyuu/config/CaptchaConfig.java new file mode 100644 index 0000000..27ce050 --- /dev/null +++ b/xdclass-user-service/src/main/java/net/jieyuu/config/CaptchaConfig.java @@ -0,0 +1,50 @@ +package net.jieyuu.config; + +import com.google.code.kaptcha.Constants; +import com.google.code.kaptcha.impl.DefaultKaptcha; +import com.google.code.kaptcha.util.Config; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.util.Properties; + +@Configuration +public class CaptchaConfig { + + /** + * 验证码配置 + * Kaptcha配置类名 + * + * @return + */ + @Bean + @Qualifier("captchaProducer") + public DefaultKaptcha kaptcha() { + DefaultKaptcha kaptcha = new DefaultKaptcha(); + Properties properties = new Properties(); +// properties.setProperty(Constants.KAPTCHA_BORDER, "yes"); +// properties.setProperty(Constants.KAPTCHA_BORDER_COLOR, "220,220,220"); +// //properties.setProperty(Constants.KAPTCHA_TEXTPRODUCER_FONT_COLOR, "38,29,12"); +// properties.setProperty(Constants.KAPTCHA_IMAGE_WIDTH, "147"); +// properties.setProperty(Constants.KAPTCHA_IMAGE_HEIGHT, "34"); +// properties.setProperty(Constants.KAPTCHA_TEXTPRODUCER_FONT_SIZE, "25"); +// //properties.setProperty(Constants.KAPTCHA_SESSION_KEY, "code"); + //验证码个数 + properties.setProperty(Constants.KAPTCHA_TEXTPRODUCER_CHAR_LENGTH, "4"); +// properties.setProperty(Constants.KAPTCHA_TEXTPRODUCER_FONT_NAMES, "Courier"); + //字体间隔 + properties.setProperty(Constants.KAPTCHA_TEXTPRODUCER_CHAR_SPACE, "8"); + //干扰线颜色 +// properties.setProperty(Constants.KAPTCHA_NOISE_COLOR, "white"); + //干扰实现类 + properties.setProperty(Constants.KAPTCHA_NOISE_IMPL, "com.google.code.kaptcha.impl.NoNoise"); + //图片样式 + properties.setProperty(Constants.KAPTCHA_OBSCURIFICATOR_IMPL, "com.google.code.kaptcha.impl.FishEyeGimpy"); + //文字来源 + properties.setProperty(Constants.KAPTCHA_TEXTPRODUCER_CHAR_STRING, "0123456789"); + Config config = new Config(properties); + kaptcha.setConfig(config); + return kaptcha; + } +} \ No newline at end of file diff --git a/xdclass-user-service/src/main/java/net/jieyuu/controller/AddressController.java b/xdclass-user-service/src/main/java/net/jieyuu/controller/AddressController.java new file mode 100644 index 0000000..1eb4c8f --- /dev/null +++ b/xdclass-user-service/src/main/java/net/jieyuu/controller/AddressController.java @@ -0,0 +1,37 @@ +package net.jieyuu.controller; + + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import net.jieyuu.service.AddressService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.web.bind.annotation.*; + +/** + *

+ * 电商-公司收发货地址表 前端控制器 + *

+ * + * @author jieyuu + * @since 2024-02-12 + */ +@Api(tags = "收货地址模块") +@RestController +@RequestMapping("/api/adderss/v1/") +public class AddressController { + + @Autowired + AddressService addressService; + + @ApiOperation("根据id查询地址详情") + @GetMapping("detail/{address_id}") + public Object detail( + @ApiParam(value = "地址", required = true) + @PathVariable("address_id") long id) { + return addressService.detail(id); + } + +} + diff --git a/xdclass-user-service/src/main/java/net/jieyuu/controller/NotifyController.java b/xdclass-user-service/src/main/java/net/jieyuu/controller/NotifyController.java new file mode 100644 index 0000000..9e3ccbf --- /dev/null +++ b/xdclass-user-service/src/main/java/net/jieyuu/controller/NotifyController.java @@ -0,0 +1,124 @@ +package net.jieyuu.controller; + + +import com.google.code.kaptcha.Producer; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import lombok.extern.slf4j.Slf4j; +import net.jieyuu.enums.SendCodeEnum; +import net.jieyuu.service.NotifyService; +import net.jieyuu.utils.CommonUtil; +import net.jieyuu.utils.JsonData; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.util.StringUtils; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import javax.imageio.ImageIO; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.util.concurrent.TimeUnit; + + +@Api(tags = "短信通知") +@RestController +@RequestMapping("/api/user/v1") +@Slf4j +public class NotifyController { + + @Autowired + private Producer captchaProducer; + + @Autowired + private StringRedisTemplate redisTemplate; + + @Autowired + private NotifyService notifyService; + + + /** + * 临时使用10分钟有效,方便测试 + */ + private static final long CAPTCHA_CODE_EXPIRED = 60 * 1000 * 10; + + /** + * 获取图形验证码 + * + * @param request + * @param response + */ + @ApiOperation("获取图形验证码") + @GetMapping("captcha") + public void getCaptcha(HttpServletRequest request, HttpServletResponse response) { + + String cacheKey = getCaptchaKey(request); + + String capText = captchaProducer.createText(); + + //存储 + redisTemplate.opsForValue().set(cacheKey, capText, CAPTCHA_CODE_EXPIRED, TimeUnit.MILLISECONDS); + + BufferedImage bi = captchaProducer.createImage(capText); + ServletOutputStream out = null; + try { + response.setDateHeader("Expires", 0); + response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate"); + response.addHeader("Cache-Control", "create_date-check=0, pre-check=0"); + response.setHeader("Pragma", "no-cache"); + out = response.getOutputStream(); + ImageIO.write(bi, "jpg", out); + out.flush(); + out.close(); + + } catch (IOException e) { + log.error("获取验证码失败:{}", e); + } + } + + /** + * 发送验证码接口 + * 1 匹配图形验证码 + * 2 发送邮件验证码 + * + * @return + */ + @ApiOperation("发送注册验证码") + @GetMapping("send_code") + public JsonData sendRegisterCode(@ApiParam("收信人") @RequestParam(value = "to", required = true) String to, + @ApiParam("图形验证码") @RequestParam(value = "captcha", required = true) String captcha, + HttpServletRequest request) { + String captchaKey = getCaptchaKey(request); + String cacheCaptcha = redisTemplate.opsForValue().get(captchaKey); + if (!StringUtils.isEmpty(captcha) || !StringUtils.isEmpty(cacheCaptcha) || captcha.equalsIgnoreCase(cacheCaptcha)) { + redisTemplate.delete(captchaKey); + JsonData jsonData = notifyService.sendCode(SendCodeEnum.USER_REGISTER, to); + return jsonData; + } + return null; + + } + + /** + * 获取缓存的key + * + * @param request + * @return + */ + private String getCaptchaKey(HttpServletRequest request) { + String ip = CommonUtil.getIpAddr(request); + String userAgent = request.getHeader("User-Agent"); + + String key = "user-service:captcha:" + CommonUtil.MD5(ip + userAgent); + log.info(key); + log.info("ip:{}", ip); + log.info("useragent{}", userAgent); + return key; + } +} diff --git a/xdclass-user-service/src/main/java/net/jieyuu/controller/UserController.java b/xdclass-user-service/src/main/java/net/jieyuu/controller/UserController.java new file mode 100644 index 0000000..f9c895c --- /dev/null +++ b/xdclass-user-service/src/main/java/net/jieyuu/controller/UserController.java @@ -0,0 +1,39 @@ +package net.jieyuu.controller; + + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import net.jieyuu.service.AddressService; +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; + +/** + *

+ * 前端控制器 + *

+ * + * @author jieyuu + * @since 2024-02-12 + */ +@Api(tags = "用户模块") +@RestController +@RequestMapping("/api/user/v1/") +public class UserController { + @Autowired + AddressService addressService; + + @ApiOperation("根据id查询地址详情") + @GetMapping("detail/{address_id}") + public Object detail( + @ApiParam(value = "地址", required = true) + @PathVariable("address_id") long id) { + return addressService.detail(id); + } + +} + diff --git a/xdclass-user-service/src/main/java/net/jieyuu/mapper/AddressMapper.java b/xdclass-user-service/src/main/java/net/jieyuu/mapper/AddressMapper.java new file mode 100644 index 0000000..7d98089 --- /dev/null +++ b/xdclass-user-service/src/main/java/net/jieyuu/mapper/AddressMapper.java @@ -0,0 +1,16 @@ +package net.jieyuu.mapper; + +import net.jieyuu.model.AddressDO; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** + *

+ * 电商-公司收发货地址表 Mapper 接口 + *

+ * + * @author jieyuu + * @since 2024-02-12 + */ +public interface AddressMapper extends BaseMapper { + +} diff --git a/xdclass-user-service/src/main/java/net/jieyuu/mapper/UserMapper.java b/xdclass-user-service/src/main/java/net/jieyuu/mapper/UserMapper.java new file mode 100644 index 0000000..5219ef2 --- /dev/null +++ b/xdclass-user-service/src/main/java/net/jieyuu/mapper/UserMapper.java @@ -0,0 +1,16 @@ +package net.jieyuu.mapper; + +import net.jieyuu.model.UserDO; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author jieyuu + * @since 2024-02-12 + */ +public interface UserMapper extends BaseMapper { + +} diff --git a/xdclass-user-service/src/main/java/net/jieyuu/model/AddressDO.java b/xdclass-user-service/src/main/java/net/jieyuu/model/AddressDO.java new file mode 100644 index 0000000..6241c04 --- /dev/null +++ b/xdclass-user-service/src/main/java/net/jieyuu/model/AddressDO.java @@ -0,0 +1,72 @@ +package net.jieyuu.model; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.annotation.IdType; +import java.util.Date; +import com.baomidou.mybatisplus.annotation.TableId; +import java.io.Serializable; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + *

+ * 电商-公司收发货地址表 + *

+ * + * @author jieyuu + * @since 2024-02-12 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@TableName("address") +public class AddressDO implements Serializable { + + private static final long serialVersionUID = 1L; + + @TableId(value = "id", type = IdType.AUTO) + private Long id; + + /** + * 用户id + */ + private Long userId; + + /** + * 是否默认收货地址:0->否;1->是 + */ + private Integer defaultStatus; + + /** + * 收发货人姓名 + */ + private String receiveName; + + /** + * 收货人电话 + */ + private String phone; + + /** + * 省/直辖市 + */ + private String province; + + /** + * 市 + */ + private String city; + + /** + * 区 + */ + private String region; + + /** + * 详细地址 + */ + private String detailAddress; + + private Date createTime; + + +} diff --git a/xdclass-user-service/src/main/java/net/jieyuu/model/UserDO.java b/xdclass-user-service/src/main/java/net/jieyuu/model/UserDO.java new file mode 100644 index 0000000..cc030d8 --- /dev/null +++ b/xdclass-user-service/src/main/java/net/jieyuu/model/UserDO.java @@ -0,0 +1,72 @@ +package net.jieyuu.model; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.annotation.IdType; +import java.util.Date; +import com.baomidou.mybatisplus.annotation.TableId; +import java.io.Serializable; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + *

+ * + *

+ * + * @author jieyuu + * @since 2024-02-12 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@TableName("user") +public class UserDO implements Serializable { + + private static final long serialVersionUID = 1L; + + @TableId(value = "id", type = IdType.AUTO) + private Long id; + + /** + * 昵称 + */ + private String name; + + /** + * 密码 + */ + private String pwd; + + /** + * 头像 + */ + private String headImg; + + /** + * 用户签名 + */ + private String slogan; + + /** + * 0表示女,1表示男 + */ + private Integer sex; + + /** + * 积分 + */ + private Integer points; + + private Date createTime; + + /** + * 邮箱 + */ + private String mail; + + /** + * 盐,用于个人敏感信息处理 + */ + private String secret; + + +} diff --git a/xdclass-user-service/src/main/java/net/jieyuu/service/AddressService.java b/xdclass-user-service/src/main/java/net/jieyuu/service/AddressService.java new file mode 100644 index 0000000..05b4cd1 --- /dev/null +++ b/xdclass-user-service/src/main/java/net/jieyuu/service/AddressService.java @@ -0,0 +1,20 @@ +package net.jieyuu.service; + +import net.jieyuu.mapper.AddressMapper; +import net.jieyuu.model.AddressDO; +import com.baomidou.mybatisplus.extension.service.IService; +import org.springframework.beans.factory.annotation.Autowired; + +/** + *

+ * 电商-公司收发货地址表 服务类 + *

+ * + * @author jieyuu + * @since 2024-02-12 + */ +public interface AddressService extends IService { + public AddressDO detail(Long id); + + +} diff --git a/xdclass-user-service/src/main/java/net/jieyuu/service/MailService.java b/xdclass-user-service/src/main/java/net/jieyuu/service/MailService.java new file mode 100644 index 0000000..e46548c --- /dev/null +++ b/xdclass-user-service/src/main/java/net/jieyuu/service/MailService.java @@ -0,0 +1,21 @@ +package net.jieyuu.service; + + +/** + *

+ * 邮件发送类 + *

+ * + * @author jieyuu + * @since 2024-02-12 + */ +public interface MailService { + + /** + * 发送邮件 + * @param to + * @param subject + * @param content + */ + public void sendMail(String to, String subject, String content); +} diff --git a/xdclass-user-service/src/main/java/net/jieyuu/service/NotifyService.java b/xdclass-user-service/src/main/java/net/jieyuu/service/NotifyService.java new file mode 100644 index 0000000..84d7b3d --- /dev/null +++ b/xdclass-user-service/src/main/java/net/jieyuu/service/NotifyService.java @@ -0,0 +1,9 @@ +package net.jieyuu.service; + +import net.jieyuu.enums.SendCodeEnum; +import net.jieyuu.utils.JsonData; + +public interface NotifyService { + + public JsonData sendCode(SendCodeEnum sendCodeType, String to); +} diff --git a/xdclass-user-service/src/main/java/net/jieyuu/service/UserService.java b/xdclass-user-service/src/main/java/net/jieyuu/service/UserService.java new file mode 100644 index 0000000..478af4d --- /dev/null +++ b/xdclass-user-service/src/main/java/net/jieyuu/service/UserService.java @@ -0,0 +1,16 @@ +package net.jieyuu.service; + +import net.jieyuu.model.UserDO; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + *

+ * 服务类 + *

+ * + * @author jieyuu + * @since 2024-02-12 + */ +public interface UserService extends IService { + +} diff --git a/xdclass-user-service/src/main/java/net/jieyuu/service/impl/AddressServiceImpl.java b/xdclass-user-service/src/main/java/net/jieyuu/service/impl/AddressServiceImpl.java new file mode 100644 index 0000000..759b030 --- /dev/null +++ b/xdclass-user-service/src/main/java/net/jieyuu/service/impl/AddressServiceImpl.java @@ -0,0 +1,30 @@ +package net.jieyuu.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import net.jieyuu.model.AddressDO; +import net.jieyuu.mapper.AddressMapper; +import net.jieyuu.service.AddressService; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +/** + *

+ * 电商-公司收发货地址表 服务实现类 + *

+ * + * @author jieyuu + * @since 2024-02-12 + */ +@Service +public class AddressServiceImpl extends ServiceImpl implements AddressService { + @Autowired + private AddressMapper addressMapper; + + @Override + public AddressDO detail(Long id) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("id", id); + return addressMapper.selectOne(queryWrapper); + } +} diff --git a/xdclass-user-service/src/main/java/net/jieyuu/service/impl/MailServiceImpl.java b/xdclass-user-service/src/main/java/net/jieyuu/service/impl/MailServiceImpl.java new file mode 100644 index 0000000..ab2bd78 --- /dev/null +++ b/xdclass-user-service/src/main/java/net/jieyuu/service/impl/MailServiceImpl.java @@ -0,0 +1,44 @@ +package net.jieyuu.service.impl; + + +import lombok.extern.slf4j.Slf4j; +import net.jieyuu.service.MailService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.mail.SimpleMailMessage; +import org.springframework.mail.javamail.JavaMailSender; +import org.springframework.stereotype.Service; + +@Service +@Slf4j +public class MailServiceImpl implements MailService { + + /** + * Spring Boot 提供了一个发送邮件的简单抽象,直接注入即可使用 + */ + @Autowired + private JavaMailSender mailSender; + + /** + * 配置文件中的发送邮箱 + */ + @Value("${spring.mail.from}") + private String from; + + @Override + public void sendMail(String to, String subject, String content) { + //创建SimpleMailMessage对象 + SimpleMailMessage message = new SimpleMailMessage(); + //邮件发送人 + message.setFrom(from); + //邮件接收人 + message.setTo(to); + //邮件主题 + message.setSubject(subject); + //邮件内容 + message.setText(content); + //发送邮件 + mailSender.send(message); + log.info("邮件发成功:{}", message.toString()); + } +} \ No newline at end of file diff --git a/xdclass-user-service/src/main/java/net/jieyuu/service/impl/NotifyServiceImpl.java b/xdclass-user-service/src/main/java/net/jieyuu/service/impl/NotifyServiceImpl.java new file mode 100644 index 0000000..a74de65 --- /dev/null +++ b/xdclass-user-service/src/main/java/net/jieyuu/service/impl/NotifyServiceImpl.java @@ -0,0 +1,56 @@ +package net.jieyuu.service.impl; + +import lombok.extern.slf4j.Slf4j; +import net.jieyuu.enums.SendCodeEnum; +import net.jieyuu.service.MailService; +import net.jieyuu.service.NotifyService; +import net.jieyuu.utils.CheckUtil; +import net.jieyuu.utils.CommonUtil; +import net.jieyuu.utils.JsonData; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Service; + +import javax.security.auth.Subject; + +@Slf4j +@Service +public class NotifyServiceImpl implements NotifyService { + + @Autowired + private MailService mailService; + + @Autowired + private RedisTemplate redisTemplate; + + public static final String SUBJECT = "验证码"; + public static final String CONTENT = "您的验证码是%s,有效时间为60秒"; + + + /** + * 前置判断:判断是否重复发送 + * 1 存储验证码到缓存 + * + * 2 发送验证码 + * 后置 存储发送记录 + * + * @param sendCodeType + * @param to + * @return + */ + @Override + public JsonData sendCode(SendCodeEnum sendCodeType, String to) { + if (CheckUtil.isEmail(to)) { + //邮箱验证码 + String code = CommonUtil.getRandomCode(6); + mailService.sendMail(to, SUBJECT, String.format(CONTENT, code)); + return JsonData.buildSuccess(); + + } else if (CheckUtil.isPhone(to)) { + //短信验证码 + + } + + return null; + } +} diff --git a/xdclass-user-service/src/main/java/net/jieyuu/service/impl/UserServiceImpl.java b/xdclass-user-service/src/main/java/net/jieyuu/service/impl/UserServiceImpl.java new file mode 100644 index 0000000..958a0e6 --- /dev/null +++ b/xdclass-user-service/src/main/java/net/jieyuu/service/impl/UserServiceImpl.java @@ -0,0 +1,20 @@ +package net.jieyuu.service.impl; + +import net.jieyuu.model.UserDO; +import net.jieyuu.mapper.UserMapper; +import net.jieyuu.service.UserService; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; + +/** + *

+ * 服务实现类 + *

+ * + * @author jieyuu + * @since 2024-02-12 + */ +@Service +public class UserServiceImpl extends ServiceImpl implements UserService { + +} diff --git a/xdclass-user-service/src/main/resources/application.yml b/xdclass-user-service/src/main/resources/application.yml new file mode 100644 index 0000000..5f143e9 --- /dev/null +++ b/xdclass-user-service/src/main/resources/application.yml @@ -0,0 +1,39 @@ +server: + port: 9001 + +spring: + application: + name: xdclass-user-service + + + #数据库配置 + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://134.175.219.253:3306/xdclass_user?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai + username: root + password: 59ae8683c59fead903132a8d440bd7d9fd4936529d1d6f45f9d41111d7537bdd + redis: + host: 134.175.219.253 + password: 123456 + port: 8000 + mail: + host: smtp.163.com #发送邮件服务器 + username: wa787966@163.com #发送邮件的邮箱地址 + password: QIVDMITCCGMDFFBO #客户端授权码,不是邮箱密码,网易的是自己设置的 + from: wa787966@163.com # 发送邮件的地址,和上面username一致 + properties.mail.smtp: + starttls: + enable: true + required: true + ssl.enable: true + default-encoding: utf-8 + +#配置plus打印sql日志 +mybatis-plus: + configuration: + log-impl: org.apache.ibatis.logging.stdout.StdOutImpl + +#设置日志级别,ERROR/WARN/INFO/DEBUG,默认是INFO以上才显示 +logging: + level: + root: INFO \ No newline at end of file diff --git a/xdclass-user-service/src/main/resources/mapper/AddressMapper.xml b/xdclass-user-service/src/main/resources/mapper/AddressMapper.xml new file mode 100644 index 0000000..433d1f9 --- /dev/null +++ b/xdclass-user-service/src/main/resources/mapper/AddressMapper.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + id, user_id, default_status, receive_name, phone, province, city, region, detail_address, create_time + + + diff --git a/xdclass-user-service/src/main/resources/mapper/UserMapper.xml b/xdclass-user-service/src/main/resources/mapper/UserMapper.xml new file mode 100644 index 0000000..905d814 --- /dev/null +++ b/xdclass-user-service/src/main/resources/mapper/UserMapper.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + id, name, pwd, head_img, slogan, sex, points, create_time, mail, secret + + + diff --git a/xdclass-user-service/src/test/java/net/jieyuu/biz/AddressTest.java b/xdclass-user-service/src/test/java/net/jieyuu/biz/AddressTest.java new file mode 100644 index 0000000..a9ac6bb --- /dev/null +++ b/xdclass-user-service/src/test/java/net/jieyuu/biz/AddressTest.java @@ -0,0 +1,30 @@ +package net.jieyuu.biz; + +import lombok.extern.slf4j.Slf4j; +import net.jieyuu.UserServiceApplication; +import net.jieyuu.model.AddressDO; +import net.jieyuu.service.AddressService; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = UserServiceApplication.class) +@Slf4j +public class AddressTest { + + @Autowired + private AddressService addressService; + + + @Test + public void testAddressDetail() { + + AddressDO addressDO = addressService.detail(1L); + log.info(addressDO.toString()); + } + + +} \ No newline at end of file diff --git a/xdclass-user-service/src/test/java/net/jieyuu/biz/MailTest.java b/xdclass-user-service/src/test/java/net/jieyuu/biz/MailTest.java new file mode 100644 index 0000000..e029f5d --- /dev/null +++ b/xdclass-user-service/src/test/java/net/jieyuu/biz/MailTest.java @@ -0,0 +1,24 @@ +package net.jieyuu.biz; + +import lombok.extern.slf4j.Slf4j; +import net.jieyuu.UserServiceApplication; +import net.jieyuu.service.MailService; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = UserServiceApplication.class) +@Slf4j +public class MailTest { + @Autowired + private MailService mailService; + + @Test + public void sendMail(){ + mailService.sendMail("645634619@qq.com","邮件发送测试","nihaonihao"); + } + +} diff --git a/xdclass-user-service/src/test/java/net/jieyuu/db/MyBatisPlusGenerator.java b/xdclass-user-service/src/test/java/net/jieyuu/db/MyBatisPlusGenerator.java new file mode 100644 index 0000000..353f324 --- /dev/null +++ b/xdclass-user-service/src/test/java/net/jieyuu/db/MyBatisPlusGenerator.java @@ -0,0 +1,94 @@ +package net.jieyuu.db; + +import com.baomidou.mybatisplus.annotation.DbType; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.generator.AutoGenerator; +import com.baomidou.mybatisplus.generator.config.DataSourceConfig; +import com.baomidou.mybatisplus.generator.config.GlobalConfig; +import com.baomidou.mybatisplus.generator.config.PackageConfig; +import com.baomidou.mybatisplus.generator.config.StrategyConfig; +import com.baomidou.mybatisplus.generator.config.rules.DateType; +import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy; + +public class MyBatisPlusGenerator { + + public static void main(String[] args) { + //1. 全局配置 + GlobalConfig config = new GlobalConfig(); + // 是否支持AR模式 + config.setActiveRecord(true) + // 作者 + .setAuthor("jieyuu") + // 生成路径,最好使用绝对路径,window路径是不一样的 + //TODO TODO TODO TODO + .setOutputDir("D:\\workspace\\project\\xdclass-shop\\xdclass-shop\\xdclass-user-service\\src\\main\\java") + // 文件覆盖 + .setFileOverride(true) + // 主键策略 + .setIdType(IdType.AUTO) + + .setDateType(DateType.ONLY_DATE) + // 设置生成的service接口的名字的首字母是否为I,默认Service是以I开头的 + .setServiceName("%sService") + + //实体类结尾名称 + .setEntityName("%sDO") + + //生成基本的resultMap + .setBaseResultMap(true) + + //不使用AR模式 + .setActiveRecord(false) + + //生成基本的SQL片段 + .setBaseColumnList(true); + + //2. 数据源配置 + DataSourceConfig dsConfig = new DataSourceConfig(); + // 设置数据库类型 + dsConfig.setDbType(DbType.MYSQL) + .setDriverName("com.mysql.cj.jdbc.Driver") + //TODO TODO TODO TODO + .setUrl("jdbc:mysql://134.175.219.253:3306/xdclass_user?useSSL=false") + .setUsername("root") + .setPassword("59ae8683c59fead903132a8d440bd7d9fd4936529d1d6f45f9d41111d7537bdd"); + + //3. 策略配置globalConfiguration中 + StrategyConfig stConfig = new StrategyConfig(); + + //全局大写命名 + stConfig.setCapitalMode(true) + // 数据库表映射到实体的命名策略 + .setNaming(NamingStrategy.underline_to_camel) + + //使用lombok + .setEntityLombokModel(true) + + //使用restcontroller注解 + .setRestControllerStyle(true) + + // 生成的表, 支持多表一起生成,以数组形式填写 + //TODO TODO TODO TODO + .setInclude("user","address"); + + //4. 包名策略配置 + PackageConfig pkConfig = new PackageConfig(); + pkConfig.setParent("net.jieyuu") + .setMapper("mapper") + .setService("service") + .setController("controller") + .setEntity("model") + .setXml("mapper"); + + //5. 整合配置 + AutoGenerator ag = new AutoGenerator(); + ag.setGlobalConfig(config) + .setDataSource(dsConfig) + .setStrategy(stConfig) + .setPackageInfo(pkConfig); + + //6. 执行操作 + ag.execute(); + System.out.println("======= 小滴课堂 Done 相关代码生成完毕 ========"); + } +} \ No newline at end of file