mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-10-31 10:18:42 +08:00 
			
		
		
		
	Merge branch 'master' of https://gitee.com/zhijiantianya/ruoyi-vue-pro into feature/mall_product
# Conflicts: # yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/jackson/config/YudaoJacksonAutoConfiguration.java # yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java # yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/bargain/vo/activity/AppBargainActivityDetailRespVO.java # yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/bargain/vo/activity/AppBargainActivityRespVO.java # yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java # yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/AppTradeOrderSettlementReqVO.java # yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/ErrorCodeConstants.java # yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/ErrorCodeConstants.java # yudao-server/src/main/resources/application-local.yaml
This commit is contained in:
		| @@ -1,5 +1,6 @@ | ||||
| package cn.iocoder.yudao.framework.jackson.config; | ||||
|  | ||||
| import cn.hutool.core.collection.CollUtil; | ||||
| import cn.iocoder.yudao.framework.common.util.json.JsonUtils; | ||||
| import cn.iocoder.yudao.framework.jackson.core.databind.LocalDateTimeDeserializer; | ||||
| import cn.iocoder.yudao.framework.jackson.core.databind.LocalDateTimeSerializer; | ||||
| @@ -11,51 +12,41 @@ import com.fasterxml.jackson.datatype.jsr310.deser.LocalTimeDeserializer; | ||||
| import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer; | ||||
| import com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer; | ||||
| import lombok.extern.slf4j.Slf4j; | ||||
| import org.springframework.beans.BeansException; | ||||
| import org.springframework.beans.factory.config.BeanPostProcessor; | ||||
| import org.springframework.boot.autoconfigure.AutoConfiguration; | ||||
| import org.springframework.context.annotation.Bean; | ||||
|  | ||||
| import java.time.LocalDate; | ||||
| import java.time.LocalDateTime; | ||||
| import java.time.LocalTime; | ||||
| import java.util.List; | ||||
|  | ||||
| @AutoConfiguration | ||||
| @Slf4j | ||||
| public class YudaoJacksonAutoConfiguration { | ||||
|  | ||||
|     @Bean | ||||
|     public BeanPostProcessor objectMapperBeanPostProcessor() { | ||||
|         return new BeanPostProcessor() { | ||||
|     @SuppressWarnings("InstantiationOfUtilityClass") | ||||
|     public JsonUtils jsonUtils(List<ObjectMapper> objectMappers) { | ||||
|         // 1.1 创建 SimpleModule 对象 | ||||
|         SimpleModule simpleModule = new SimpleModule(); | ||||
|         simpleModule | ||||
|                 // 新增 Long 类型序列化规则,数值超过 2^53-1,在 JS 会出现精度丢失问题,因此 Long 自动序列化为字符串类型 | ||||
|                 .addSerializer(Long.class, NumberSerializer.INSTANCE) | ||||
|                 .addSerializer(Long.TYPE, NumberSerializer.INSTANCE) | ||||
|                 .addSerializer(LocalDate.class, LocalDateSerializer.INSTANCE) | ||||
|                 .addDeserializer(LocalDate.class, LocalDateDeserializer.INSTANCE) | ||||
|                 .addSerializer(LocalTime.class, LocalTimeSerializer.INSTANCE) | ||||
|                 .addDeserializer(LocalTime.class, LocalTimeDeserializer.INSTANCE) | ||||
|                 // 新增 LocalDateTime 序列化、反序列化规则 | ||||
|                 .addSerializer(LocalDateTime.class, LocalDateTimeSerializer.INSTANCE) | ||||
|                 .addDeserializer(LocalDateTime.class, LocalDateTimeDeserializer.INSTANCE); | ||||
|         // 1.2 注册到 objectMapper | ||||
|         objectMappers.forEach(objectMapper -> objectMapper.registerModule(simpleModule)); | ||||
|  | ||||
|             @Override | ||||
|             public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { | ||||
|                 if (!(bean instanceof ObjectMapper)) { | ||||
|                     return bean; | ||||
|                 } | ||||
|                 ObjectMapper objectMapper = (ObjectMapper) bean; | ||||
|                 SimpleModule simpleModule = new SimpleModule(); | ||||
|                 /* | ||||
|                  * 1. 新增Long类型序列化规则,数值超过2^53-1,在JS会出现精度丢失问题,因此Long自动序列化为字符串类型 | ||||
|                  * 2. 新增LocalDateTime序列化、反序列化规则 | ||||
|                  */ | ||||
|                 simpleModule | ||||
|                         .addSerializer(Long.class, NumberSerializer.INSTANCE) | ||||
|                         .addSerializer(Long.TYPE, NumberSerializer.INSTANCE) | ||||
|                         .addSerializer(LocalDate.class, LocalDateSerializer.INSTANCE) | ||||
|                         .addDeserializer(LocalDate.class, LocalDateDeserializer.INSTANCE) | ||||
|                         .addSerializer(LocalTime.class, LocalTimeSerializer.INSTANCE) | ||||
|                         .addDeserializer(LocalTime.class, LocalTimeDeserializer.INSTANCE) | ||||
|                         .addSerializer(LocalDateTime.class, LocalDateTimeSerializer.INSTANCE) | ||||
|                         .addDeserializer(LocalDateTime.class, LocalDateTimeDeserializer.INSTANCE); | ||||
|  | ||||
|                 objectMapper.registerModules(simpleModule); | ||||
|  | ||||
|                 JsonUtils.init(objectMapper); | ||||
|                 log.info("初始化 jackson 自动配置"); | ||||
|                 return bean; | ||||
|             } | ||||
|         }; | ||||
|         // 2. 设置 objectMapper 到 JsonUtils { | ||||
|         JsonUtils.init(CollUtil.getFirst(objectMappers)); | ||||
|         log.info("[init][初始化 JsonUtils 成功]"); | ||||
|         return new JsonUtils(); | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -11,7 +11,6 @@ import cn.iocoder.yudao.framework.common.util.json.JsonUtils; | ||||
| import cn.iocoder.yudao.framework.common.util.monitor.TracerUtils; | ||||
| import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; | ||||
| import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils; | ||||
| import io.github.resilience4j.ratelimiter.RequestNotPermitted; | ||||
| import lombok.AllArgsConstructor; | ||||
| import lombok.extern.slf4j.Slf4j; | ||||
| import org.apache.commons.lang3.exception.ExceptionUtils; | ||||
| @@ -33,6 +32,7 @@ import javax.validation.ConstraintViolationException; | ||||
| import javax.validation.ValidationException; | ||||
| import java.time.LocalDateTime; | ||||
| import java.util.Map; | ||||
| import java.util.Objects; | ||||
|  | ||||
| import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants.*; | ||||
|  | ||||
| @@ -83,9 +83,6 @@ public class GlobalExceptionHandler { | ||||
|         if (ex instanceof HttpRequestMethodNotSupportedException) { | ||||
|             return httpRequestMethodNotSupportedExceptionHandler((HttpRequestMethodNotSupportedException) ex); | ||||
|         } | ||||
|         if (ex instanceof RequestNotPermitted) { | ||||
|             return requestNotPermittedExceptionHandler(request, (RequestNotPermitted) ex); | ||||
|         } | ||||
|         if (ex instanceof ServiceException) { | ||||
|             return serviceExceptionHandler((ServiceException) ex); | ||||
|         } | ||||
| @@ -186,8 +183,7 @@ public class GlobalExceptionHandler { | ||||
|     /** | ||||
|      * 处理 Resilience4j 限流抛出的异常 | ||||
|      */ | ||||
|     @ExceptionHandler(value = RequestNotPermitted.class) | ||||
|     public CommonResult<?> requestNotPermittedExceptionHandler(HttpServletRequest req, RequestNotPermitted ex) { | ||||
|     public CommonResult<?> requestNotPermittedExceptionHandler(HttpServletRequest req, Throwable ex) { | ||||
|         log.warn("[requestNotPermittedExceptionHandler][url({}) 访问过于频繁]", req.getRequestURL(), ex); | ||||
|         return CommonResult.error(TOO_MANY_REQUESTS); | ||||
|     } | ||||
| @@ -226,7 +222,12 @@ public class GlobalExceptionHandler { | ||||
|             return tableNotExistsResult; | ||||
|         } | ||||
|  | ||||
|         // 情况二:处理异常 | ||||
|         // 情况二:部分特殊的库的处理 | ||||
|         if (Objects.equals("io.github.resilience4j.ratelimiter.RequestNotPermitted", ex.getClass().getName())) { | ||||
|             return requestNotPermittedExceptionHandler(req, ex); | ||||
|         } | ||||
|  | ||||
|         // 情况三:处理异常 | ||||
|         log.error("[defaultExceptionHandler]", ex); | ||||
|         // 插入异常日志 | ||||
|         this.createExceptionLog(req, ex); | ||||
|   | ||||
| @@ -21,6 +21,7 @@ import static cn.iocoder.yudao.framework.web.config.YudaoWebAutoConfiguration.cr | ||||
|  | ||||
| @AutoConfiguration | ||||
| @EnableConfigurationProperties(XssProperties.class) | ||||
| @ConditionalOnProperty(prefix = "yudao.xss", name = "enable", havingValue = "true", matchIfMissing = true) // 设置为 false 时,禁用 | ||||
| public class YudaoXssAutoConfiguration implements WebMvcConfigurer { | ||||
|  | ||||
|     /** | ||||
|   | ||||
| @@ -1,6 +1,5 @@ | ||||
| cn.iocoder.yudao.framework.apilog.config.YudaoApiLogAutoConfiguration | ||||
| cn.iocoder.yudao.framework.jackson.config.YudaoJacksonAutoConfiguration | ||||
| com.github.xiaoymin.knife4j.spring.configuration.Knife4jAutoConfiguration | ||||
| cn.iocoder.yudao.framework.swagger.config.YudaoSwaggerAutoConfiguration | ||||
| cn.iocoder.yudao.framework.web.config.YudaoWebAutoConfiguration | ||||
| cn.iocoder.yudao.framework.xss.config.YudaoXssAutoConfiguration | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 YunaiV
					YunaiV