From 7ef76d238616b5c56752d53c225d2e4d07c0b8e7 Mon Sep 17 00:00:00 2001 From: lbw <1192299468@qq.com> Date: Tue, 9 Dec 2025 18:42:50 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E5=BC=95=E5=85=A5=E5=B8=B8=E9=87=8F?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- enlish-framework/enlish-common/pom.xml | 69 ++++++++ .../common/constant/DateConstants.java | 38 +++++ .../common/constant/GlobalConstants.java | 12 ++ .../framework/common/enums/DeletedEnum.java | 15 ++ .../framework/common/enums/StatusEnum.java | 16 ++ .../exception/BaseExceptionInterface.java | 9 ++ .../common/exception/BizException.java | 19 +++ .../common/response/PageResponse.java | 69 ++++++++ .../framework/common/response/Response.java | 73 +++++++++ .../framework/common/util/DateUtils.java | 81 ++++++++++ .../framework/common/util/JsonUtils.java | 92 +++++++++++ .../framework/common/util/NumberUtils.java | 34 ++++ .../framework/common/util/ParamUtils.java | 75 +++++++++ .../common/validator/PhoneNumber.java | 22 +++ .../validator/PhoneNumberValidator.java | 18 +++ enlish-framework/pom.xml | 25 +++ enlish-service/pom.xml | 6 + .../service/deoms/web/TestController.java | 14 ++ pom.xml | 147 +++++++++++++++++- 19 files changed, 832 insertions(+), 2 deletions(-) create mode 100644 enlish-framework/enlish-common/pom.xml create mode 100644 enlish-framework/enlish-common/src/main/java/com/yinlihupo/framework/common/constant/DateConstants.java create mode 100644 enlish-framework/enlish-common/src/main/java/com/yinlihupo/framework/common/constant/GlobalConstants.java create mode 100644 enlish-framework/enlish-common/src/main/java/com/yinlihupo/framework/common/enums/DeletedEnum.java create mode 100644 enlish-framework/enlish-common/src/main/java/com/yinlihupo/framework/common/enums/StatusEnum.java create mode 100644 enlish-framework/enlish-common/src/main/java/com/yinlihupo/framework/common/exception/BaseExceptionInterface.java create mode 100644 enlish-framework/enlish-common/src/main/java/com/yinlihupo/framework/common/exception/BizException.java create mode 100644 enlish-framework/enlish-common/src/main/java/com/yinlihupo/framework/common/response/PageResponse.java create mode 100644 enlish-framework/enlish-common/src/main/java/com/yinlihupo/framework/common/response/Response.java create mode 100644 enlish-framework/enlish-common/src/main/java/com/yinlihupo/framework/common/util/DateUtils.java create mode 100644 enlish-framework/enlish-common/src/main/java/com/yinlihupo/framework/common/util/JsonUtils.java create mode 100644 enlish-framework/enlish-common/src/main/java/com/yinlihupo/framework/common/util/NumberUtils.java create mode 100644 enlish-framework/enlish-common/src/main/java/com/yinlihupo/framework/common/util/ParamUtils.java create mode 100644 enlish-framework/enlish-common/src/main/java/com/yinlihupo/framework/common/validator/PhoneNumber.java create mode 100644 enlish-framework/enlish-common/src/main/java/com/yinlihupo/framework/common/validator/PhoneNumberValidator.java create mode 100644 enlish-framework/pom.xml create mode 100644 enlish-service/src/main/java/com/yinlihupo/enlish/service/deoms/web/TestController.java diff --git a/enlish-framework/enlish-common/pom.xml b/enlish-framework/enlish-common/pom.xml new file mode 100644 index 0000000..43c642e --- /dev/null +++ b/enlish-framework/enlish-common/pom.xml @@ -0,0 +1,69 @@ + + 4.0.0 + + + com.yinlihupo + enlish-framework + ${revision} + + + + jar + + enlish-common + ${project.artifactId} + 平台通用模块,如一些通用枚举、工具类等等 + + + + + org.projectlombok + lombok + + + + + com.fasterxml.jackson.core + jackson-databind + + + + com.fasterxml.jackson.core + jackson-core + + + + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + + + + + jakarta.validation + jakarta.validation-api + + + org.hibernate.validator + hibernate-validator + + + + + com.google.guava + guava + + + + cn.hutool + hutool-all + + + + org.apache.commons + commons-lang3 + + + + diff --git a/enlish-framework/enlish-common/src/main/java/com/yinlihupo/framework/common/constant/DateConstants.java b/enlish-framework/enlish-common/src/main/java/com/yinlihupo/framework/common/constant/DateConstants.java new file mode 100644 index 0000000..af882d7 --- /dev/null +++ b/enlish-framework/enlish-common/src/main/java/com/yinlihupo/framework/common/constant/DateConstants.java @@ -0,0 +1,38 @@ +package com.yinlihupo.framework.common.constant; + +import java.time.format.DateTimeFormatter; + + +public interface DateConstants { + + /** + * DateTimeFormatter:年-月-日 时:分:秒 + */ + DateTimeFormatter DATE_FORMAT_Y_M_D_H_M_S = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + + /** + * DateTimeFormatter:年-月-日 + */ + DateTimeFormatter DATE_FORMAT_Y_M_D = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + + /** + * DateTimeFormatter:时:分:秒 + */ + DateTimeFormatter DATE_FORMAT_H_M_S = DateTimeFormatter.ofPattern("HH:mm:ss"); + + /** + * DateTimeFormatter:年-月 + */ + DateTimeFormatter DATE_FORMAT_Y_M = DateTimeFormatter.ofPattern("yyyy-MM"); + + /** + * DateTimeFormatter:月-日 + */ + DateTimeFormatter DATE_FORMAT_M_D = DateTimeFormatter.ofPattern("MM-dd"); + + + /** + * DateTimeFormatter:时:分 + */ + DateTimeFormatter DATE_FORMAT_H_M = DateTimeFormatter.ofPattern("HH:mm"); +} diff --git a/enlish-framework/enlish-common/src/main/java/com/yinlihupo/framework/common/constant/GlobalConstants.java b/enlish-framework/enlish-common/src/main/java/com/yinlihupo/framework/common/constant/GlobalConstants.java new file mode 100644 index 0000000..9210d1d --- /dev/null +++ b/enlish-framework/enlish-common/src/main/java/com/yinlihupo/framework/common/constant/GlobalConstants.java @@ -0,0 +1,12 @@ +package com.yinlihupo.framework.common.constant; + + + + +public interface GlobalConstants { + + /** + * 用户 ID + */ + String USER_ID = "userId"; +} diff --git a/enlish-framework/enlish-common/src/main/java/com/yinlihupo/framework/common/enums/DeletedEnum.java b/enlish-framework/enlish-common/src/main/java/com/yinlihupo/framework/common/enums/DeletedEnum.java new file mode 100644 index 0000000..a4e66fd --- /dev/null +++ b/enlish-framework/enlish-common/src/main/java/com/yinlihupo/framework/common/enums/DeletedEnum.java @@ -0,0 +1,15 @@ +package com.yinlihupo.framework.common.enums; + +import lombok.AllArgsConstructor; +import lombok.Getter; + + +@Getter +@AllArgsConstructor +public enum DeletedEnum { + + YES(true), + NO(false); + + private final Boolean value; +} diff --git a/enlish-framework/enlish-common/src/main/java/com/yinlihupo/framework/common/enums/StatusEnum.java b/enlish-framework/enlish-common/src/main/java/com/yinlihupo/framework/common/enums/StatusEnum.java new file mode 100644 index 0000000..089e6ae --- /dev/null +++ b/enlish-framework/enlish-common/src/main/java/com/yinlihupo/framework/common/enums/StatusEnum.java @@ -0,0 +1,16 @@ +package com.yinlihupo.framework.common.enums; + +import lombok.AllArgsConstructor; +import lombok.Getter; + + +@Getter +@AllArgsConstructor +public enum StatusEnum { + // 启用 + ENABLE(0), + // 禁用 + DISABLED(1); + + private final Integer value; +} diff --git a/enlish-framework/enlish-common/src/main/java/com/yinlihupo/framework/common/exception/BaseExceptionInterface.java b/enlish-framework/enlish-common/src/main/java/com/yinlihupo/framework/common/exception/BaseExceptionInterface.java new file mode 100644 index 0000000..957f263 --- /dev/null +++ b/enlish-framework/enlish-common/src/main/java/com/yinlihupo/framework/common/exception/BaseExceptionInterface.java @@ -0,0 +1,9 @@ +package com.yinlihupo.framework.common.exception; + + +public interface BaseExceptionInterface { + + String getErrorCode(); + + String getErrorMessage(); +} diff --git a/enlish-framework/enlish-common/src/main/java/com/yinlihupo/framework/common/exception/BizException.java b/enlish-framework/enlish-common/src/main/java/com/yinlihupo/framework/common/exception/BizException.java new file mode 100644 index 0000000..9fc454d --- /dev/null +++ b/enlish-framework/enlish-common/src/main/java/com/yinlihupo/framework/common/exception/BizException.java @@ -0,0 +1,19 @@ +package com.yinlihupo.framework.common.exception; + +import lombok.Getter; +import lombok.Setter; + + +@Getter +@Setter +public class BizException extends RuntimeException { + // 异常码 + private String errorCode; + // 错误信息 + private String errorMessage; + + public BizException(BaseExceptionInterface baseExceptionInterface) { + this.errorCode = baseExceptionInterface.getErrorCode(); + this.errorMessage = baseExceptionInterface.getErrorMessage(); + } +} diff --git a/enlish-framework/enlish-common/src/main/java/com/yinlihupo/framework/common/response/PageResponse.java b/enlish-framework/enlish-common/src/main/java/com/yinlihupo/framework/common/response/PageResponse.java new file mode 100644 index 0000000..d7bf3d5 --- /dev/null +++ b/enlish-framework/enlish-common/src/main/java/com/yinlihupo/framework/common/response/PageResponse.java @@ -0,0 +1,69 @@ +package com.yinlihupo.framework.common.response; + + +import lombok.Data; + +import java.util.List; + + +@Data +public class PageResponse extends Response> { + + // 当前页码 + private long pageNo; + // 总数据量 + private long totalCount; + // 每页展示的数据量 + private long pageSize; + // 总页数 + private long totalPage; + + + public static PageResponse success(List data, long pageNo, long totalCount) { + PageResponse pageResponse = new PageResponse<>(); + pageResponse.setSuccess(true); + pageResponse.setData(data); + pageResponse.setPageNo(pageNo); + pageResponse.setTotalCount(totalCount); + // 每页展示的数据量 + long pageSize = 10L; + pageResponse.setPageSize(pageSize); + // 计算总页数 + long totalPage = (totalCount + pageSize - 1) / pageSize; + pageResponse.setTotalPage(totalPage); + return pageResponse; + } + + + public static PageResponse success(List data, long pageNo, long totalCount, long pageSize) { + PageResponse pageResponse = new PageResponse<>(); + pageResponse.setSuccess(true); + pageResponse.setData(data); + pageResponse.setPageNo(pageNo); + pageResponse.setTotalCount(totalCount); + pageResponse.setPageSize(pageSize); + // 计算总页数 + long totalPage = pageSize == 0 ? 0 : (totalCount + pageSize - 1) / pageSize; + pageResponse.setTotalPage(totalPage); + return pageResponse; + } + + /** + * 获取总页数 + */ + public static long getTotalPage(long totalCount, long pageSize) { + + return pageSize == 0 ? 0 : (totalCount + pageSize - 1) / pageSize; + } + + /** + * 计算分页查询的 offset + */ + public static long getOffset(long pageNo, long pageSize) { + // 如果页码小于 1,默认返回第一页的 offset + if (pageNo < 1) { + pageNo = 1; + } + return (pageNo - 1) * pageSize; + } +} diff --git a/enlish-framework/enlish-common/src/main/java/com/yinlihupo/framework/common/response/Response.java b/enlish-framework/enlish-common/src/main/java/com/yinlihupo/framework/common/response/Response.java new file mode 100644 index 0000000..19c6254 --- /dev/null +++ b/enlish-framework/enlish-common/src/main/java/com/yinlihupo/framework/common/response/Response.java @@ -0,0 +1,73 @@ +package com.yinlihupo.framework.common.response; + + +import com.yinlihupo.framework.common.exception.BaseExceptionInterface; +import com.yinlihupo.framework.common.exception.BizException; +import lombok.Data; + +import java.io.Serializable; + + +@Data +public class Response implements Serializable { + + // 是否成功,默认为 true + private boolean success = true; + // 响应消息 + private String message; + // 异常码 + private String errorCode; + // 响应数据 + private T data; + + // =================================== 成功响应 =================================== + public static Response success() { + Response response = new Response<>(); + return response; + } + + public static Response success(T data) { + Response response = new Response<>(); + response.setData(data); + return response; + } + + // =================================== 失败响应 =================================== + public static Response fail() { + Response response = new Response<>(); + response.setSuccess(false); + return response; + } + + public static Response fail(String errorMessage) { + Response response = new Response<>(); + response.setSuccess(false); + response.setMessage(errorMessage); + return response; + } + + public static Response fail(String errorCode, String errorMessage) { + Response response = new Response<>(); + response.setSuccess(false); + response.setErrorCode(errorCode); + response.setMessage(errorMessage); + return response; + } + + public static Response fail(BizException bizException) { + Response response = new Response<>(); + response.setSuccess(false); + response.setErrorCode(bizException.getErrorCode()); + response.setMessage(bizException.getErrorMessage()); + return response; + } + + public static Response fail(BaseExceptionInterface baseExceptionInterface) { + Response response = new Response<>(); + response.setSuccess(false); + response.setErrorCode(baseExceptionInterface.getErrorCode()); + response.setMessage(baseExceptionInterface.getErrorMessage()); + return response; + } + +} diff --git a/enlish-framework/enlish-common/src/main/java/com/yinlihupo/framework/common/util/DateUtils.java b/enlish-framework/enlish-common/src/main/java/com/yinlihupo/framework/common/util/DateUtils.java new file mode 100644 index 0000000..f8b186f --- /dev/null +++ b/enlish-framework/enlish-common/src/main/java/com/yinlihupo/framework/common/util/DateUtils.java @@ -0,0 +1,81 @@ +package com.yinlihupo.framework.common.util; + + + + +import com.yinlihupo.framework.common.constant.DateConstants; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.Period; +import java.time.ZoneOffset; +import java.time.temporal.ChronoUnit; +import java.util.Date; + +/** + * @author lbwxxc + * @date 2025/6/2 16:24 + * @description: 日期工具类 + */ +public class DateUtils { + + public static long localDateTime2Timestamp(LocalDateTime localDateTime) { + return localDateTime.toInstant(ZoneOffset.UTC).toEpochMilli(); + } + + public static long dateTime2Timestamp(Date date) { + return date.toInstant().toEpochMilli(); + } + + /** + * LocalDateTime 转 String 字符串 + */ + public static String localDateTime2String(LocalDateTime time) { + return time.format(DateConstants.DATE_FORMAT_Y_M_D_H_M_S); + } + + /** + * LocalDateTime 转友好的相对时间字符串 + */ + public static String formatRelativeTime(LocalDateTime dateTime) { + // 当前时间 + LocalDateTime now = LocalDateTime.now(); + + // 计算与当前时间的差距 + long daysDiff = ChronoUnit.DAYS.between(dateTime, now); + long hoursDiff = ChronoUnit.HOURS.between(dateTime, now); + long minutesDiff = ChronoUnit.MINUTES.between(dateTime, now); + + if (daysDiff < 1) { // 如果是今天 + if (hoursDiff < 1) { // 如果是几分钟前 + return minutesDiff + "分钟前"; + } else { // 如果是几小时前 + return hoursDiff + "小时前"; + } + } else if (daysDiff == 1) { // 如果是昨天 + return "昨天 " + dateTime.format(DateConstants.DATE_FORMAT_H_M); + } else if (daysDiff < 7) { // 如果是最近一周 + return daysDiff + "天前"; + } else if (dateTime.getYear() == now.getYear()) { // 如果是今年 + return dateTime.format(DateConstants.DATE_FORMAT_M_D); + } else { // 如果是去年或更早 + return dateTime.format(DateConstants.DATE_FORMAT_Y_M_D); + } + } + + /** + * 计算年龄 + * @param birthDate 出生日期(LocalDate) + * @return 计算得到的年龄(以年为单位) + */ + public static int calculateAge(LocalDate birthDate) { + // 获取当前日期 + LocalDate currentDate = LocalDate.now(); + + // 计算出生日期到当前日期的 Period 对象 + Period period = Period.between(birthDate, currentDate); + + // 返回完整的年份(即年龄) + return period.getYears(); + } +} diff --git a/enlish-framework/enlish-common/src/main/java/com/yinlihupo/framework/common/util/JsonUtils.java b/enlish-framework/enlish-common/src/main/java/com/yinlihupo/framework/common/util/JsonUtils.java new file mode 100644 index 0000000..9e7f66d --- /dev/null +++ b/enlish-framework/enlish-common/src/main/java/com/yinlihupo/framework/common/util/JsonUtils.java @@ -0,0 +1,92 @@ +package com.yinlihupo.framework.common.util; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.databind.type.CollectionType; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import lombok.SneakyThrows; +import org.apache.commons.lang3.StringUtils; + +import java.lang.reflect.Type; +import java.util.List; +import java.util.Map; +import java.util.Set; + + +public class JsonUtils { + + private static ObjectMapper OBJECT_MAPPER = new ObjectMapper(); + + static { + OBJECT_MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + OBJECT_MAPPER.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); + OBJECT_MAPPER.registerModules(new JavaTimeModule()); // 解决 LocalDateTime 的序列化问题 + } + + /** + * 初始化:统一使用 Spring Boot 个性化配置的 ObjectMapper + */ + public static void init(ObjectMapper objectMapper) { + OBJECT_MAPPER = objectMapper; + } + + /** + * 将对象转换为 JSON 字符串 + */ + @SneakyThrows + public static String toJsonString(Object obj) { + return OBJECT_MAPPER.writeValueAsString(obj); + } + + /** + * 将 JSON 字符串转换为对象 + */ + @SneakyThrows + public static T parseObject(String jsonStr, Class clazz) { + if (StringUtils.isBlank(jsonStr)) { + return null; + } + + return OBJECT_MAPPER.readValue(jsonStr, clazz); + } + + /** + * 将 JSON 字符串转换为 Map + */ + public static Map parseMap(String jsonStr, Class keyClass, Class valueClass) throws Exception { + // 创建 TypeReference,指定泛型类型 + TypeReference> typeRef = new TypeReference>() { + }; + + // 将 JSON 字符串转换为 Map + return OBJECT_MAPPER.readValue(jsonStr, OBJECT_MAPPER.getTypeFactory().constructMapType(Map.class, keyClass, valueClass)); + } + + /** + * 将 JSON 字符串解析为指定类型的 List 对象 + */ + public static List parseList(String jsonStr, Class clazz) throws Exception { + // 使用 TypeReference 指定 List 的泛型类型 + return OBJECT_MAPPER.readValue(jsonStr, new TypeReference<>() { + @Override + public CollectionType getType() { + return OBJECT_MAPPER.getTypeFactory().constructCollectionType(List.class, clazz); + } + }); + } + + /** + * 将 JSON 字符串解析为指定类型的 Set 对象 + */ + public static Set parseSet(String jsonStr, Class clazz) throws Exception { + + return OBJECT_MAPPER.readValue(jsonStr, new TypeReference<>() { + @Override + public Type getType() { + return OBJECT_MAPPER.getTypeFactory().constructCollectionType(Set.class, clazz); + } + }); + } +} diff --git a/enlish-framework/enlish-common/src/main/java/com/yinlihupo/framework/common/util/NumberUtils.java b/enlish-framework/enlish-common/src/main/java/com/yinlihupo/framework/common/util/NumberUtils.java new file mode 100644 index 0000000..b7d40a0 --- /dev/null +++ b/enlish-framework/enlish-common/src/main/java/com/yinlihupo/framework/common/util/NumberUtils.java @@ -0,0 +1,34 @@ +package com.yinlihupo.framework.common.util; + + +import java.math.RoundingMode; +import java.text.DecimalFormat; +import java.util.Objects; + + +public class NumberUtils { + + /** + * 数字转换字符串 + */ + public static String formatNumberString(long number) { + + if (Objects.isNull(number)) { + return "0"; + } + + if (number < 10000) { + return String.valueOf(number); // 小于 1 万显示原始数字 + } else if (number >= 10000 && number < 100000000) { + // 小于 1 亿,显示万单位 + double result = number / 10000.0; + DecimalFormat df = new DecimalFormat("#.#"); // 保留 1 位小数 + df.setRoundingMode(RoundingMode.DOWN); // 禁用四舍五入 + String formatted = df.format(result); + return formatted + "万"; + } else { + return "9999万"; // 超过 1 亿,统一显示 9999万 + } + } + +} diff --git a/enlish-framework/enlish-common/src/main/java/com/yinlihupo/framework/common/util/ParamUtils.java b/enlish-framework/enlish-common/src/main/java/com/yinlihupo/framework/common/util/ParamUtils.java new file mode 100644 index 0000000..03a184c --- /dev/null +++ b/enlish-framework/enlish-common/src/main/java/com/yinlihupo/framework/common/util/ParamUtils.java @@ -0,0 +1,75 @@ +package com.yinlihupo.framework.common.util; + + +import java.util.regex.Pattern; + + +public final class ParamUtils { + private ParamUtils() { + } + + // ============================== 校验昵称 ============================== + // 定义昵称长度范围 + private static final int NICK_NAME_MIN_LENGTH = 2; + private static final int NICK_NAME_MAX_LENGTH = 24; + + // 定义特殊字符的正则表达式 + private static final String NICK_NAME_REGEX = "[!@#$%^&*(),.?\":{}|<>]"; + + /** + * 昵称校验 + * + * @param nickname + * @return + */ + public static boolean checkNickname(String nickname) { + // 检查长度 + if (nickname.length() < NICK_NAME_MIN_LENGTH || nickname.length() > NICK_NAME_MAX_LENGTH) { + return false; + } + + // 检查是否含有特殊字符 + Pattern pattern = Pattern.compile(NICK_NAME_REGEX); + return !pattern.matcher(nickname).find(); + } + + // ============================== 校验小哈书号 ============================== + // 定义 ID 长度范围 + private static final int ID_MIN_LENGTH = 6; + private static final int ID_MAX_LENGTH = 15; + + // 定义正则表达式 + private static final String ID_REGEX = "^[a-zA-Z0-9_]+$"; + + /** + * 小哈书 ID 校验 + * + * @param xiaohashuId + * @return + */ + public static boolean checkXiaohashuId(String xiaohashuId) { + // 检查长度 + if (xiaohashuId.length() < ID_MIN_LENGTH || xiaohashuId.length() > ID_MAX_LENGTH) { + return false; + } + // 检查格式 + Pattern pattern = Pattern.compile(ID_REGEX); + return pattern.matcher(xiaohashuId).matches(); + } + + /** + * 字符串长度校验 + * + * @param str + * @param length + * @return + */ + public static boolean checkLength(String str, int length) { + // 检查长度 + if (str.isEmpty() || str.length() > length) { + return false; + } + return true; + } +} + diff --git a/enlish-framework/enlish-common/src/main/java/com/yinlihupo/framework/common/validator/PhoneNumber.java b/enlish-framework/enlish-common/src/main/java/com/yinlihupo/framework/common/validator/PhoneNumber.java new file mode 100644 index 0000000..7107876 --- /dev/null +++ b/enlish-framework/enlish-common/src/main/java/com/yinlihupo/framework/common/validator/PhoneNumber.java @@ -0,0 +1,22 @@ +package com.yinlihupo.framework.common.validator; + +import jakarta.validation.Constraint; +import jakarta.validation.Payload; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + + +@Target({ ElementType.METHOD, ElementType.FIELD, ElementType.ANNOTATION_TYPE, ElementType.PARAMETER }) +@Retention(RetentionPolicy.RUNTIME) +@Constraint(validatedBy = PhoneNumberValidator.class) +public @interface PhoneNumber { + + String message() default "手机号格式不正确, 需为 11 位数字"; + + Class[] groups() default {}; + + Class[] payload() default {}; +} diff --git a/enlish-framework/enlish-common/src/main/java/com/yinlihupo/framework/common/validator/PhoneNumberValidator.java b/enlish-framework/enlish-common/src/main/java/com/yinlihupo/framework/common/validator/PhoneNumberValidator.java new file mode 100644 index 0000000..a39882c --- /dev/null +++ b/enlish-framework/enlish-common/src/main/java/com/yinlihupo/framework/common/validator/PhoneNumberValidator.java @@ -0,0 +1,18 @@ +package com.yinlihupo.framework.common.validator; + +import jakarta.validation.ConstraintValidator; +import jakarta.validation.ConstraintValidatorContext; + + +public class PhoneNumberValidator implements ConstraintValidator { + + @Override + public void initialize(PhoneNumber constraintAnnotation) { + } + + @Override + public boolean isValid(String phoneNumber, ConstraintValidatorContext context) { + // 校验逻辑:正则表达式判断手机号是否为 11 位数字 + return phoneNumber != null && phoneNumber.matches("\\d{11}"); + } +} diff --git a/enlish-framework/pom.xml b/enlish-framework/pom.xml new file mode 100644 index 0000000..81e221c --- /dev/null +++ b/enlish-framework/pom.xml @@ -0,0 +1,25 @@ + + + 4.0.0 + + + + com.yinlihupo + enlish + ${revision} + + + + pom + + enlish-framework + ${project.artifactId} + 平台基础设施层:封装一些常用功能,供各个业务线拿来即用 + + + enlish-common + + + diff --git a/enlish-service/pom.xml b/enlish-service/pom.xml index 9ca1145..cfae0c2 100644 --- a/enlish-service/pom.xml +++ b/enlish-service/pom.xml @@ -18,6 +18,12 @@ 小哈书:认证服务(负责处理用户登录、注册、账号注销等) + + + com.yinlihupo + enlish-common + + org.springframework.boot spring-boot-starter-web diff --git a/enlish-service/src/main/java/com/yinlihupo/enlish/service/deoms/web/TestController.java b/enlish-service/src/main/java/com/yinlihupo/enlish/service/deoms/web/TestController.java new file mode 100644 index 0000000..985d42c --- /dev/null +++ b/enlish-service/src/main/java/com/yinlihupo/enlish/service/deoms/web/TestController.java @@ -0,0 +1,14 @@ +package com.yinlihupo.enlish.service.deoms.web; + +import com.yinlihupo.framework.common.response.Response; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class TestController { + + @GetMapping("/test") + public Response test() { + return Response.success("Hello, 犬小哈专栏"); + } +} \ No newline at end of file diff --git a/pom.xml b/pom.xml index 7060991..8d1f7e2 100644 --- a/pom.xml +++ b/pom.xml @@ -19,6 +19,7 @@ enlish-service + enlish-framework @@ -32,18 +33,43 @@ UTF-8 3.8.1 - + 1.5.0 1.18.30 3.4.12 + 2.16.1 + 8.0.29 + 1.2.23 + 1.38.0 + 33.0.0-jre + 5.8.26 + 3.12.0 + 2.0.24 + 0.3.0-RC + 2.14.2 + 8.2.1 + 8.2.1 + 3.17.4 + 2.3.1 + 1.1.1 + 2.3.3 + 3.8.0 + 3.1.8 + 2.2.3 + 0.2.21 - 1.5.0 + + com.yinlihupo + enlish-common + ${revision} + + org.projectlombok @@ -59,6 +85,123 @@ import + + + com.github.ben-manes.caffeine + caffeine + ${caffeine.version} + + + + + com.github.phantomthief + buffer-trigger + ${buffertrigger.version} + + + + + io.github.openfeign.form + feign-form + ${feign-form.version} + + + + com.alibaba + transmittable-thread-local + ${transmittable-thread-local.version} + + + + + com.fasterxml.jackson.core + jackson-databind + ${jackson.version} + + + + com.fasterxml.jackson.core + jackson-core + ${jackson.version} + + + + cn.dev33 + sa-token-reactor-spring-boot3-starter + ${sa-token.version} + + + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + ${spring-boot.version} + + + + + mysql + mysql-connector-java + ${mysql-connector-java.version} + + + + + com.alibaba + druid-spring-boot-3-starter + ${druid.version} + + + + + cn.dev33 + sa-token-spring-boot3-starter + ${sa-token.version} + + + + + cn.dev33 + sa-token-redis-jackson + ${sa-token.version} + + + + + com.google.guava + guava + ${guava.version} + + + + cn.hutool + hutool-all + ${hutool.version} + + + + org.apache.commons + commons-lang3 + ${commons-lang3.version} + + + + javax.xml.bind + jaxb-api + ${jaxb-api.version} + + + javax.activation + activation + ${activation.version} + + + + org.glassfish.jaxb + jaxb-runtime + ${jaxb-runtime.version} + +