feat(优化): 优化项目代码
This commit is contained in:
parent
a950287fa1
commit
ad39a8e575
|
@ -1,21 +0,0 @@
|
||||||
package com.sky.common.config;
|
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
@Slf4j
|
|
||||||
public class AddResourceConfiguration extends WebMvcConfigurationSupport {
|
|
||||||
/**
|
|
||||||
* 设置静态资源映射
|
|
||||||
*
|
|
||||||
* @param registry ResourceHandlerRegistry
|
|
||||||
*/
|
|
||||||
protected void addResourceHandlers(ResourceHandlerRegistry registry) {
|
|
||||||
log.info("设置静态资源映射");
|
|
||||||
registry.addResourceHandler("/doc.html").addResourceLocations("classpath:/META-INF/resources/");
|
|
||||||
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -35,8 +35,8 @@ public class RedisConfiguration {
|
||||||
* 使用StringRedisSerializer序列化为字符串
|
* 使用StringRedisSerializer序列化为字符串
|
||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
public RedisTemplate<String, Object> redisTemplate(LettuceConnectionFactory connectionFactory) {
|
public RedisTemplate<Object, Object> redisTemplate(LettuceConnectionFactory connectionFactory) {
|
||||||
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
|
RedisTemplate<Object, Object> redisTemplate = new RedisTemplate<>();
|
||||||
redisTemplate.setConnectionFactory(connectionFactory);
|
redisTemplate.setConnectionFactory(connectionFactory);
|
||||||
// 设置key序列化为string
|
// 设置key序列化为string
|
||||||
redisTemplate.setKeySerializer(new StringRedisSerializer());
|
redisTemplate.setKeySerializer(new StringRedisSerializer());
|
||||||
|
|
|
@ -3,22 +3,24 @@ package com.sky.common.config;
|
||||||
import com.sky.common.interceptor.JwtTokenAdminInterceptor;
|
import com.sky.common.interceptor.JwtTokenAdminInterceptor;
|
||||||
import com.sky.common.interceptor.JwtTokenUserInterceptor;
|
import com.sky.common.interceptor.JwtTokenUserInterceptor;
|
||||||
import com.sky.common.json.JacksonObjectMapper;
|
import com.sky.common.json.JacksonObjectMapper;
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.http.converter.HttpMessageConverter;
|
import org.springframework.http.converter.HttpMessageConverter;
|
||||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||||
|
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@RequiredArgsConstructor
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class WebMvcConfiguration extends WebMvcConfigurationSupport {
|
public class WebMvcConfiguration extends WebMvcConfigurationSupport {
|
||||||
private final JwtTokenAdminInterceptor jwtTokenAdminInterceptor;
|
@Autowired
|
||||||
private final JwtTokenUserInterceptor jwtTokenUserInterceptor;
|
private JwtTokenAdminInterceptor jwtTokenAdminInterceptor;
|
||||||
|
@Autowired
|
||||||
|
private JwtTokenUserInterceptor jwtTokenUserInterceptor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 注册自定义拦截器
|
* 注册自定义拦截器
|
||||||
|
@ -50,4 +52,15 @@ public class WebMvcConfiguration extends WebMvcConfigurationSupport {
|
||||||
// 将自己的消息转化器加入容器中
|
// 将自己的消息转化器加入容器中
|
||||||
converters.add(0, converter);
|
converters.add(0, converter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置静态资源映射
|
||||||
|
*
|
||||||
|
* @param registry ResourceHandlerRegistry
|
||||||
|
*/
|
||||||
|
protected void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||||
|
log.info("设置静态资源映射");
|
||||||
|
registry.addResourceHandler("/doc.html").addResourceLocations("classpath:/META-INF/resources/");
|
||||||
|
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,5 +11,4 @@ import org.springframework.stereotype.Component;
|
||||||
@Component
|
@Component
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class AutoFillAspect {
|
public class AutoFillAspect {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,54 @@
|
||||||
package com.sky.task;
|
package com.sky.task;
|
||||||
|
|
||||||
|
import com.sky.mapper.OrderMapper;
|
||||||
|
import com.sky.pojo.entity.Orders;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class OrderTask {
|
public class OrderTask {
|
||||||
|
@Resource
|
||||||
|
private OrderMapper orderMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理超时订单
|
||||||
|
*/
|
||||||
|
@Scheduled(cron = "0 * * * * ?")
|
||||||
|
// @Scheduled(cron = "0/5 * * * * ?")
|
||||||
|
public void processTImeOrder() {
|
||||||
|
log.info("定时处理超时订单:{}", LocalDateTime.now());
|
||||||
|
LocalDateTime time = LocalDateTime.now().plusMinutes(-15);
|
||||||
|
List<Orders> list = orderMapper.getByStatusAndOrderTime(Orders.PENDING_PAYMENT, time);
|
||||||
|
if (list != null && !list.isEmpty()) {
|
||||||
|
for (Orders orders : list) {
|
||||||
|
orders.setStatus(Orders.CANCELLED);
|
||||||
|
orders.setCancelReason("订单超时,自动取消");
|
||||||
|
orders.setCancelTime(LocalDateTime.now());
|
||||||
|
orderMapper.update(orders);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理一直派送中的订单
|
||||||
|
*/
|
||||||
|
@Scheduled(cron = "0 0 1 * * ?")
|
||||||
|
// @Scheduled(cron = "0/5 * * * * ?")
|
||||||
|
public void processDeliveryOrder() {
|
||||||
|
log.info("定时处理处于派送中的订单:{}", LocalDateTime.now());
|
||||||
|
LocalDateTime time = LocalDateTime.now().plusMinutes(-60);
|
||||||
|
List<Orders> list = orderMapper.getByStatusAndOrderTime(Orders.DELIVERY_IN_PROGRESS, time);
|
||||||
|
if (list != null && !list.isEmpty()) {
|
||||||
|
for (Orders orders : list) {
|
||||||
|
orders.setStatus(Orders.COMPLETED);
|
||||||
|
orderMapper.update(orders);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@ServerEndpoint("/es/{sid}")
|
@ServerEndpoint("/ws/{sid}")
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class WebSocketServer {
|
public class WebSocketServer {
|
||||||
// 存放会话对象
|
// 存放会话对象
|
||||||
|
|
Loading…
Reference in New Issue