Skip to content

Commit 41dbdc7

Browse files
committed
merge: 解决合并冲突
2 parents 573e6aa + 7c30a52 commit 41dbdc7

116 files changed

Lines changed: 1855 additions & 1081 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

pom.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
<groupId>io.github.talelin</groupId>
1313
<artifactId>latticy</artifactId>
14-
<version>0.1.1-RC1</version>
14+
<version>0.2.0-RC1</version>
1515
<name>latticy</name>
1616
<description>Demo project for lin cms</description>
1717

@@ -47,7 +47,7 @@
4747
<dependency>
4848
<groupId>io.github.talelin</groupId>
4949
<artifactId>lin-cms-spring-boot-starter</artifactId>
50-
<version>0.1.1-RC1</version>
50+
<version>0.2.0-RC2</version>
5151
</dependency>
5252

5353
<dependency>
@@ -131,6 +131,7 @@
131131
<includes>
132132
<include>**/*.properties</include>
133133
<include>**/*.xml</include>
134+
<include>**/*.yml</include>
134135
<include>**/*.tld</include>
135136
</includes>
136137
<filtering>false</filtering>

src/main/java/io/github/talelin/latticy/LatticyApplication.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
/**
1010
* @author pedro@TaleLin
1111
*/
12-
@SpringBootApplication(scanBasePackages = {"io.github.talelin.latticy"})
13-
@MapperScan(basePackages = {"io.github.talelin.latticy.mapper"})
1412
@RestController
13+
@MapperScan(basePackages = {"io.github.talelin.latticy.mapper"})
14+
@SpringBootApplication(scanBasePackages = {"io.github.talelin.latticy"})
1515
public class LatticyApplication {
1616

1717
public static void main(String[] args) {

src/main/java/io/github/talelin/latticy/bo/FileBO.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44

55
/**
66
* @author pedro@TaleLin
7+
* @author Juzi@TaleLin
78
*/
89
@Data
910
public class FileBO {
1011

1112
/**
1213
* 文件 id
1314
*/
14-
private Long id;
15+
private Integer id;
1516

1617
/**
1718
* 文件 key,上传时指定的

src/main/java/io/github/talelin/latticy/bo/GroupPermissionBO.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import cn.hutool.core.bean.BeanUtil;
44
import io.github.talelin.latticy.model.GroupDO;
55
import io.github.talelin.latticy.model.PermissionDO;
6-
import lombok.*;
6+
import lombok.AllArgsConstructor;
7+
import lombok.Data;
8+
import lombok.NoArgsConstructor;
79

810
import java.util.List;
911

@@ -15,7 +17,7 @@
1517
@NoArgsConstructor
1618
@AllArgsConstructor
1719
public class GroupPermissionBO {
18-
private Long id;
20+
private Integer id;
1921

2022
private String name;
2123

src/main/java/io/github/talelin/latticy/common/aop/ResultAspect.java

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,32 @@
33
import cn.hutool.core.util.StrUtil;
44
import io.github.talelin.latticy.common.configuration.CodeMessageConfiguration;
55
import io.github.talelin.latticy.vo.UnifyResponseVO;
6-
import lombok.extern.slf4j.Slf4j;
76
import org.aspectj.lang.annotation.AfterReturning;
87
import org.aspectj.lang.annotation.Aspect;
9-
import org.aspectj.lang.annotation.Pointcut;
108
import org.springframework.stereotype.Component;
119

1210
/**
13-
* 处理返回结果为 UnifyResponseVO 的视图函数
14-
* 默认的返回均是英文,在此处通过code替换成中文
11+
* 处理返回结果为 UnifyResponseVO 的 Controller
12+
* message 默认为 null,在此处通过 code 设置为对应消息
1513
*
1614
* @author pedro@TaleLin
1715
* @author colorful@TaleLin
16+
* @author Juzi@TaleLin
1817
*/
1918
@Aspect
2019
@Component
21-
@Slf4j
2220
public class ResultAspect {
21+
@AfterReturning(returning = "result", pointcut = "execution(public * io.github.talelin.latticy.controller..*.*(..))")
22+
public void doAfterReturning(UnifyResponseVO<String> result) {
23+
int code = result.getCode();
24+
String oldMessage = result.getMessage();
25+
// code-message.properties 中配置的 message
26+
String newMessage = CodeMessageConfiguration.getMessage(code);
2327

24-
25-
@Pointcut("execution(public * io.github.talelin.latticy.controller..*.*(..))")
26-
public void handlePlaceholder() {
27-
}
28-
29-
@AfterReturning(returning = "ret", pointcut = "handlePlaceholder()")
30-
public void doAfterReturning(Object ret) throws Throwable {
31-
if (ret instanceof UnifyResponseVO) {
32-
UnifyResponseVO result = (UnifyResponseVO) ret;
33-
int code = result.getCode();
34-
String message = CodeMessageConfiguration.getMessage(code);
35-
if (StrUtil.isNotBlank(message) && StrUtil.isBlank((CharSequence) result.getMessage())) {
36-
result.setMessage(message);
37-
}
28+
// 如果 code-message.properties 中指定了相应的 message 并且 UnifyResponseVO 的 message 为null
29+
// 则使用 newMessage 替换 oldMessage
30+
if (StrUtil.isNotBlank(newMessage) && StrUtil.isBlank(oldMessage)) {
31+
result.setMessage(newMessage);
3832
}
3933
}
4034
}

src/main/java/io/github/talelin/latticy/common/configuration/CommonConfiguration.java

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
import com.baomidou.mybatisplus.core.injector.ISqlInjector;
55
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
66
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
7-
import io.github.talelin.autoconfigure.bean.RouteMetaCollector;
8-
import io.github.talelin.latticy.module.file.FileProperties;
7+
import io.github.talelin.autoconfigure.bean.PermissionMetaCollector;
98
import io.github.talelin.latticy.common.interceptor.RequestLogInterceptor;
9+
import io.github.talelin.latticy.module.file.FileProperties;
10+
import io.github.talelin.latticy.module.log.MDCAccessServletFilter;
1011
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
1112
import org.springframework.boot.context.properties.EnableConfigurationProperties;
13+
import org.springframework.boot.web.servlet.FilterRegistrationBean;
1214
import org.springframework.context.annotation.Bean;
1315
import org.springframework.context.annotation.Configuration;
1416

@@ -35,13 +37,13 @@ public ISqlInjector sqlInjector() {
3537
}
3638

3739
/**
38-
* 记录每个被 @RouteMeta 记录的信息,在beans的后置调用
40+
* 记录每个被 @PermissionMeta 记录的信息,在beans的后置调用
3941
*
40-
* @return RouteMetaCollector
42+
* @return PermissionMetaCollector
4143
*/
4244
@Bean
43-
public RouteMetaCollector postProcessBeans() {
44-
return new RouteMetaCollector();
45+
public PermissionMetaCollector postProcessBeans() {
46+
return new PermissionMetaCollector();
4547
}
4648

4749

@@ -56,4 +58,18 @@ public Jackson2ObjectMapperBuilderCustomizer customJackson() {
5658
jacksonObjectMapperBuilder.propertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
5759
};
5860
}
61+
62+
/**
63+
* 用于将 request 相关信息(如请求 url)放入 MDC 中供日志使用
64+
*
65+
* @return Logback 的 MDCInsertingServletFilter
66+
*/
67+
@Bean
68+
public FilterRegistrationBean<MDCAccessServletFilter> mdcInsertingServletFilter() {
69+
FilterRegistrationBean<MDCAccessServletFilter> filterRegistrationBean = new FilterRegistrationBean<>();
70+
MDCAccessServletFilter mdcAccessServletFilter = new MDCAccessServletFilter();
71+
filterRegistrationBean.setFilter(mdcAccessServletFilter);
72+
filterRegistrationBean.setName("mdc-access-servlet-filter");
73+
return filterRegistrationBean;
74+
}
5975
}

src/main/java/io/github/talelin/latticy/common/configuration/WebConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ public class WebConfiguration implements WebMvcConfigurer {
4040
@Autowired
4141
private RequestLogInterceptor requestLogInterceptor;
4242

43-
@Value("${lin.cms.file.store-dir:assets/}")
43+
@Value("${lin.file.store-dir:assets/}")
4444
private String dir;
4545

46-
@Value("${lin.cms.file.serve-path:assets/**}")
46+
@Value("${lin.file.serve-path:assets/**}")
4747
private String servePath;
4848

4949
/**
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package io.github.talelin.latticy.common.enumeration;
2+
3+
import com.baomidou.mybatisplus.core.enums.IEnum;
4+
5+
/**
6+
* @author colorful@TaleLin
7+
* @author Juzi@TaleLin
8+
*/
9+
public enum GroupLevelEnum implements IEnum<Integer> {
10+
/**
11+
* 超级管理员
12+
*/
13+
ROOT(1),
14+
/**
15+
* 游客
16+
*/
17+
GUEST(2),
18+
/**
19+
* 普通用户
20+
*/
21+
USER(3);
22+
23+
private final Integer value;
24+
25+
GroupLevelEnum(Integer value) {
26+
this.value = value;
27+
}
28+
29+
/**
30+
* MybatisEnumTypeHandler 转换时调用此方法
31+
*
32+
* @return 枚举对应的 code 值
33+
* @see com.baomidou.mybatisplus.extension.handlers.MybatisEnumTypeHandler
34+
*/
35+
@Override
36+
public Integer getValue() {
37+
return this.value;
38+
}
39+
40+
}

src/main/java/io/github/talelin/latticy/common/exception/RestExceptionHandler.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
import cn.hutool.core.util.StrUtil;
44
import io.github.talelin.autoconfigure.bean.Code;
5+
import io.github.talelin.autoconfigure.exception.HttpException;
56
import io.github.talelin.latticy.common.configuration.CodeMessageConfiguration;
67
import io.github.talelin.latticy.vo.UnifyResponseVO;
7-
import io.github.talelin.autoconfigure.exception.HttpException;
88
import lombok.extern.slf4j.Slf4j;
99
import org.springframework.beans.TypeMismatchException;
1010
import org.springframework.beans.factory.annotation.Value;
@@ -26,6 +26,8 @@
2626
import javax.servlet.http.HttpServletRequest;
2727
import javax.servlet.http.HttpServletResponse;
2828
import javax.validation.ConstraintViolationException;
29+
import java.lang.reflect.Constructor;
30+
import java.lang.reflect.InvocationTargetException;
2931
import java.util.HashMap;
3032
import java.util.List;
3133
import java.util.Map;
@@ -49,19 +51,20 @@ public class RestExceptionHandler {
4951
* HttpException
5052
*/
5153
@ExceptionHandler({HttpException.class})
52-
public UnifyResponseVO processException(HttpException exception, HttpServletRequest request, HttpServletResponse response) {
53-
log.error("", exception);
54+
public UnifyResponseVO processException(HttpException exception, HttpServletRequest request, HttpServletResponse response) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
5455
UnifyResponseVO unifyResponse = new UnifyResponseVO();
5556
unifyResponse.setRequest(getSimpleRequest(request));
5657
int code = exception.getCode();
57-
boolean messageOnly = exception.isMessageOnly();
58+
boolean defaultMessage = exception.ifDefaultMessage();
5859
unifyResponse.setCode(code);
5960
response.setStatus(exception.getHttpCode());
6061
String errorMessage = CodeMessageConfiguration.getMessage(code);
61-
if (StrUtil.isBlank(errorMessage) || messageOnly) {
62+
if (StrUtil.isBlank(errorMessage) || !defaultMessage) {
6263
unifyResponse.setMessage(exception.getMessage());
64+
log.error("", exception);
6365
} else {
6466
unifyResponse.setMessage(errorMessage);
67+
log.error("", exception.getClass().getConstructor(int.class, String.class).newInstance(code, errorMessage));
6568
}
6669
return unifyResponse;
6770
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package io.github.talelin.latticy.common.factory;
2+
3+
import org.springframework.boot.env.YamlPropertySourceLoader;
4+
import org.springframework.core.env.PropertySource;
5+
import org.springframework.core.io.support.EncodedResource;
6+
import org.springframework.core.io.support.PropertySourceFactory;
7+
8+
import java.io.IOException;
9+
import java.util.List;
10+
11+
/**
12+
* @author Juzi@TaleLin
13+
*/
14+
public class YamlPropertySourceFactory implements PropertySourceFactory {
15+
@Override
16+
public PropertySource<?> createPropertySource(String name, EncodedResource resource) throws IOException {
17+
List<PropertySource<?>> sources = new YamlPropertySourceLoader().load(resource.getResource().getFilename(), resource.getResource());
18+
return sources.get(0);
19+
}
20+
}

0 commit comments

Comments
 (0)