项目优化,构建文件Lombok异常问题修复
This commit is contained in:
+61
-12
@@ -1,20 +1,69 @@
|
||||
# CLAUDE.md — system-common
|
||||
# CLAUDE.md - system-common
|
||||
|
||||
Shared Java library used by all backend modules.
|
||||
This file provides guidance to Claude Code when working in the system-common module.
|
||||
|
||||
---
|
||||
## Purpose
|
||||
|
||||
## Service layer pattern
|
||||
Shared library module used by all other backend modules. Provides base classes, utilities, and cross-cutting concerns. This module has no main class and is not runnable on its own.
|
||||
|
||||
Two base classes defined here:
|
||||
## Base Class Hierarchy
|
||||
|
||||
| Base | Purpose |
|
||||
|---|---|
|
||||
| `CrudService<Dao, Entity, DTO>` | Generic CRUD: `page()`, `get()`, `save()`, `update()`, `delete()` |
|
||||
| `BaseService<Dao>` | Lighter base without DTO generic |
|
||||
### BaseEntity (`com.weather.common.entity.BaseEntity`)
|
||||
|
||||
These are used by all service implementations in `system-admin` and other modules. See `system-admin/CLAUDE.md` for the full module convention.
|
||||
All entities must extend this. Provides:
|
||||
- `id` (Long, `@TableId`)
|
||||
- `creator` (Long, `@TableField(fill = INSERT)`)
|
||||
- `createDate` (Date, `@TableField(fill = INSERT)`)
|
||||
|
||||
## i18n validation messages
|
||||
### BaseDao (`com.weather.common.dao.BaseDao<M, T>`)
|
||||
|
||||
Located at `src/main/resources/i18n/validation.properties`. Hibernate Validator messages used by `@RestControllerAdvice` exception handler in `system-admin`. Error codes follow `int` scheme: 5 digits, first 2 = module, last 3 = business (e.g. `10001`-`10029`).
|
||||
Extends MyBatis-Plus `BaseMapper<T>`. Provides `getById(Long id)` as an alias.
|
||||
|
||||
### Service Layer
|
||||
|
||||
```
|
||||
BaseService<T> # tag interface
|
||||
└── CrudService<T, D> # page/list/get/save/update/delete
|
||||
└── BaseServiceImpl<M, T> # dao injection + insert/updateById wrappers
|
||||
└── CrudServiceImpl<M, T, D> # generic CRUD with getWrapper()
|
||||
```
|
||||
|
||||
`CrudServiceImpl` is the key base class for all business services. Subclasses only need to implement `getWrapper(Map<String, Object> params)` to define query conditions. Entity-to-DTO conversion uses `ConvertUtils.sourceToTarget()`.
|
||||
|
||||
## Redis
|
||||
|
||||
- `RedisConfig`: Creates `RedisTemplate<String, Object>` with Jackson JSON serialization
|
||||
- `RedisUtils`: Wraps `RedisTemplate` operations -- `set/get/delete/deleteByPattern/hGet/hSet/hDelete/expire`
|
||||
- `RedisKeys`: Static factory for standardized key names (e.g. `getWeatherSummarizeKey()`, `getWeatherSummarizePattern()`)
|
||||
- `RedisAspect`: AOP aspect that logs Redis operation errors
|
||||
|
||||
## Validation
|
||||
|
||||
- `ValidatorUtils`: Bean Validation wrapper using Jakarta Validator
|
||||
- `AssertUtils`: Assertion helpers that throw `CommonException` on failure
|
||||
- `group/`: Validation groups -- `AddGroup`, `UpdateGroup`, `DefaultGroup`
|
||||
|
||||
## XSS Protection
|
||||
|
||||
- `XssFilter`: Servlet filter that wraps requests with `XssHttpServletRequestWrapper`
|
||||
- `XssUtils`: HTML entity encoding using Jsoup
|
||||
|
||||
## Exception Handling
|
||||
|
||||
- `CommonException`: Application-level runtime exception with error code
|
||||
- `ExceptionUtils`: Factory methods for creating typed exceptions
|
||||
- `ErrorCode`: Interface with error code constants
|
||||
|
||||
## Utilities
|
||||
|
||||
- `ConvertUtils`: Bean copy with recursive conversion support for nested objects
|
||||
- `DateUtils`: Date parsing/formatting
|
||||
- `JsonUtils`: JSON serialization via Jackson
|
||||
- `TreeUtils`: Build tree structures from flat lists (used for menus, depts, regions)
|
||||
- `HttpContextUtils`: Servlet request/response helpers
|
||||
- `IpUtils`: Extract client IP from request
|
||||
- `MessageUtils`: i18n message resolution
|
||||
- `SpringContextUtils`: Access Spring ApplicationContext statically
|
||||
- `Result<T>`: Standard API response wrapper with `code`, `msg`, `data`
|
||||
- `PageData<T>`: Paginated response with `total`, `list`
|
||||
- `TreeNode`: Tree node interface with `getId/setId/getPid/setPid/getChildren/setChildren`
|
||||
|
||||
@@ -2,30 +2,35 @@
|
||||
|
||||
package com.weather.common.utils;
|
||||
|
||||
import lombok.Data;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 树节点,所有需要实现树节点的,都需要继承该类
|
||||
* 树节点接口,所有需要实现树节点的,都需要实现该接口
|
||||
*
|
||||
* @author 123
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Data
|
||||
public class TreeNode<T> implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
public interface TreeNode<T> extends Serializable {
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
private Long id;
|
||||
Long getId();
|
||||
|
||||
void setId(Long id);
|
||||
|
||||
/**
|
||||
* 上级ID
|
||||
*/
|
||||
private Long pid;
|
||||
Long getPid();
|
||||
|
||||
void setPid(Long pid);
|
||||
|
||||
/**
|
||||
* 子节点列表
|
||||
*/
|
||||
private List<T> children = new ArrayList<>();
|
||||
List<T> getChildren();
|
||||
|
||||
void setChildren(List<T> children);
|
||||
}
|
||||
@@ -20,7 +20,7 @@ public class TreeUtils {
|
||||
/**
|
||||
* 根据pid,构建树节点
|
||||
*/
|
||||
public static <T extends TreeNode> List<T> build(List<T> treeNodes, Long pid) {
|
||||
public static <T extends TreeNode<T>> List<T> build(List<T> treeNodes, Long pid) {
|
||||
//pid不能为空
|
||||
AssertUtils.isNull(pid, "pid");
|
||||
|
||||
@@ -37,7 +37,7 @@ public class TreeUtils {
|
||||
/**
|
||||
* 查找子节点
|
||||
*/
|
||||
private static <T extends TreeNode> T findChildren(List<T> treeNodes, T rootNode) {
|
||||
private static <T extends TreeNode<T>> T findChildren(List<T> treeNodes, T rootNode) {
|
||||
for(T treeNode : treeNodes) {
|
||||
if(rootNode.getId().equals(treeNode.getPid())) {
|
||||
rootNode.getChildren().add(findChildren(treeNodes, treeNode));
|
||||
@@ -49,7 +49,7 @@ public class TreeUtils {
|
||||
/**
|
||||
* 构建树节点
|
||||
*/
|
||||
public static <T extends TreeNode> List<T> build(List<T> treeNodes) {
|
||||
public static <T extends TreeNode<T>> List<T> build(List<T> treeNodes) {
|
||||
List<T> result = new ArrayList<>();
|
||||
|
||||
//list转map
|
||||
|
||||
@@ -6,12 +6,11 @@ import com.weather.common.exception.CommonException;
|
||||
import jakarta.validation.ConstraintViolation;
|
||||
import jakarta.validation.Validation;
|
||||
import jakarta.validation.Validator;
|
||||
import jakarta.validation.ValidatorFactory;
|
||||
import org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
import org.springframework.context.support.ResourceBundleMessageSource;
|
||||
import org.springframework.validation.beanvalidation.MessageSourceResourceBundleLocator;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@@ -23,11 +22,16 @@ import java.util.Set;
|
||||
*/
|
||||
public class ValidatorUtils {
|
||||
|
||||
private static ResourceBundleMessageSource getMessageSource() {
|
||||
ResourceBundleMessageSource bundleMessageSource = new ResourceBundleMessageSource();
|
||||
bundleMessageSource.setDefaultEncoding("UTF-8");
|
||||
bundleMessageSource.setBasenames("i18n/validation");
|
||||
return bundleMessageSource;
|
||||
private static final ValidatorFactory VALIDATOR_FACTORY;
|
||||
|
||||
static {
|
||||
ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
|
||||
messageSource.setDefaultEncoding("UTF-8");
|
||||
messageSource.setBasenames("i18n/validation");
|
||||
|
||||
VALIDATOR_FACTORY = Validation.byDefaultProvider().configure().messageInterpolator(
|
||||
new ResourceBundleMessageInterpolator(new MessageSourceResourceBundleLocator(messageSource)))
|
||||
.buildValidatorFactory();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -37,14 +41,11 @@ public class ValidatorUtils {
|
||||
*/
|
||||
public static void validateEntity(Object object, Class<?>... groups)
|
||||
throws CommonException {
|
||||
Locale.setDefault(LocaleContextHolder.getLocale());
|
||||
Validator validator = Validation.byDefaultProvider().configure().messageInterpolator(
|
||||
new ResourceBundleMessageInterpolator(new MessageSourceResourceBundleLocator(getMessageSource())))
|
||||
.buildValidatorFactory().getValidator();
|
||||
Validator validator = VALIDATOR_FACTORY.getValidator();
|
||||
|
||||
Set<ConstraintViolation<Object>> constraintViolations = validator.validate(object, groups);
|
||||
if (!constraintViolations.isEmpty()) {
|
||||
ConstraintViolation<Object> constraint = constraintViolations.iterator().next();
|
||||
ConstraintViolation<Object> constraint = constraintViolations.iterator().next();
|
||||
throw new CommonException(constraint.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user