opt:管理后台系统优化。
This commit is contained in:
@@ -113,36 +113,6 @@ public class VehicleServiceImpl implements VehicleService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WebResponse getVehicleInfos() {
|
public WebResponse getVehicleInfos() {
|
||||||
VehicleInfoDto vehicleInfoDto = new VehicleInfoDto();
|
|
||||||
vehicleInfoDto.setVehicleId("1");
|
|
||||||
vehicleInfoDto.setVehicleNumber("1");
|
|
||||||
vehicleInfoDto.setIp("127.0.0.1");
|
|
||||||
vehicleInfoDto.setBatteryLevel(100);
|
|
||||||
vehicleInfoDto.setIceCapacity(50);
|
|
||||||
vehicleInfoDto.setWaterCapacity(50);
|
|
||||||
vehicleInfoDto.setSignalType("wifi");
|
|
||||||
vehicleInfoDto.setSignalStrength(10);
|
|
||||||
vehicleInfoDto.setError_code(0);
|
|
||||||
vehicleInfoDto.setError_msg("");
|
|
||||||
vehicleInfoDto.setError_info(new JSONObject());
|
|
||||||
vehicleInfoDto.setCurrentLocation(new Location());
|
|
||||||
vehicleInfoDto.setLastUpdated("2026-01-27 00:00:00");
|
|
||||||
vehicleCache.put("1",vehicleInfoDto);
|
|
||||||
VehicleInfoDto vehicleInfoDto2 = new VehicleInfoDto();
|
|
||||||
vehicleInfoDto2.setVehicleId("2");
|
|
||||||
vehicleInfoDto2.setVehicleNumber("2");
|
|
||||||
vehicleInfoDto2.setIp("127.0.0.1");
|
|
||||||
vehicleInfoDto2.setBatteryLevel(80);
|
|
||||||
vehicleInfoDto2.setIceCapacity(60);
|
|
||||||
vehicleInfoDto2.setWaterCapacity(60);
|
|
||||||
vehicleInfoDto2.setSignalType("5G");
|
|
||||||
vehicleInfoDto2.setSignalStrength(20);
|
|
||||||
vehicleInfoDto2.setError_code(0);
|
|
||||||
vehicleInfoDto2.setError_msg("");
|
|
||||||
vehicleInfoDto2.setError_info(new JSONObject());
|
|
||||||
vehicleInfoDto2.setCurrentLocation(new Location());
|
|
||||||
vehicleInfoDto2.setLastUpdated("2026-01-27 12:00:00");
|
|
||||||
vehicleCache.put("2",vehicleInfoDto2);
|
|
||||||
return WebResponse.requestParamOk(vehicleCache);
|
return WebResponse.requestParamOk(vehicleCache);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,10 +13,10 @@ import org.springframework.data.redis.listener.RedisMessageListenerContainer;
|
|||||||
@Configuration
|
@Configuration
|
||||||
public class RedisListenerConfig {
|
public class RedisListenerConfig {
|
||||||
|
|
||||||
// @Bean
|
@Bean
|
||||||
// RedisMessageListenerContainer container(RedisConnectionFactory connectionFactory) {
|
RedisMessageListenerContainer container(RedisConnectionFactory connectionFactory) {
|
||||||
// RedisMessageListenerContainer container = new RedisMessageListenerContainer();
|
RedisMessageListenerContainer container = new RedisMessageListenerContainer();
|
||||||
// container.setConnectionFactory(connectionFactory);
|
container.setConnectionFactory(connectionFactory);
|
||||||
// return container;
|
return container;
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,28 +1,28 @@
|
|||||||
package org.nl.sys.modular.backgroundmanagement.common.security.satoken;
|
//package org.nl.sys.modular.backgroundmanagement.common.security.satoken;
|
||||||
|
//
|
||||||
import cn.dev33.satoken.interceptor.SaInterceptor;
|
//import cn.dev33.satoken.interceptor.SaInterceptor;
|
||||||
import cn.dev33.satoken.jwt.StpLogicJwtForSimple;
|
//import cn.dev33.satoken.jwt.StpLogicJwtForSimple;
|
||||||
import cn.dev33.satoken.stp.StpLogic;
|
//import cn.dev33.satoken.stp.StpLogic;
|
||||||
import cn.dev33.satoken.stp.StpUtil;
|
//import cn.dev33.satoken.stp.StpUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
//import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
//import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Bean;
|
//import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
//import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
//import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
//import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
|
//
|
||||||
/**
|
///**
|
||||||
* @author: lyd
|
// * @author: lyd
|
||||||
* @description: sa-token的配置路由拦截
|
// * @description: sa-token的配置路由拦截
|
||||||
* @Date: 2022-09-20
|
// * @Date: 2022-09-20
|
||||||
*/
|
// */
|
||||||
@Slf4j
|
//@Slf4j
|
||||||
@Configuration
|
//@Configuration
|
||||||
public class SaTokenConfigure implements WebMvcConfigurer {
|
//public class SaTokenConfigure implements WebMvcConfigurer {
|
||||||
|
//
|
||||||
// Sa-Token 整合 jwt (Simple 简单模式)
|
// // Sa-Token 整合 jwt (Simple 简单模式)
|
||||||
@Bean
|
// @Bean
|
||||||
public StpLogic getStpLogicJwt() {
|
// public StpLogic getStpLogicJwt() {
|
||||||
return new StpLogicJwtForSimple();
|
// return new StpLogicJwtForSimple();
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|||||||
@@ -1,48 +1,48 @@
|
|||||||
package org.nl.sys.modular.backgroundmanagement.common.security.service;
|
//package org.nl.sys.modular.backgroundmanagement.common.security.service;
|
||||||
//*
|
////*
|
||||||
// * Copyright 2019-2020 the original author or authors.
|
//// * Copyright 2019-2020 the original author or authors.
|
||||||
// *
|
//// *
|
||||||
// * Licensed under the Apache License, Version 2.0 (the "License");
|
//// * Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
// * you may not use this file except in compliance with the License.
|
//// * you may not use this file except in compliance with the License.
|
||||||
// * You may obtain a copy of the License at
|
//// * You may obtain a copy of the License at
|
||||||
// *
|
//// *
|
||||||
// * http://www.apache.org/licenses/LICENSE-2.0
|
//// * http://www.apache.org/licenses/LICENSE-2.0
|
||||||
// *
|
//// *
|
||||||
// * Unless required by applicable law or agreed to in writing, software
|
//// * Unless required by applicable law or agreed to in writing, software
|
||||||
// * distributed under the License is distributed on an "AS IS" BASIS,
|
//// * distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
//// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
// * See the License for the specific language governing permissions and
|
//// * See the License for the specific language governing permissions and
|
||||||
// * limitations under the License.
|
//// * limitations under the License.
|
||||||
|
//// */
|
||||||
|
//
|
||||||
|
//import cn.hutool.core.util.StrUtil;
|
||||||
|
//import org.springframework.stereotype.Component;
|
||||||
|
//
|
||||||
|
///**
|
||||||
|
// * @author: liaojinlong
|
||||||
|
// * @date: 2020/6/11 18:01
|
||||||
|
// * @apiNote: 用于清理 用户登录信息缓存,为防止Spring循环依赖与安全考虑 ,单独构成工具类
|
||||||
// */
|
// */
|
||||||
|
//@Component
|
||||||
import cn.hutool.core.util.StrUtil;
|
//public class UserCacheClean {
|
||||||
import org.springframework.stereotype.Component;
|
//
|
||||||
|
// /**
|
||||||
/**
|
// * 清理特定用户缓存信息<br>
|
||||||
* @author: liaojinlong
|
// * 用户信息变更时
|
||||||
* @date: 2020/6/11 18:01
|
// *
|
||||||
* @apiNote: 用于清理 用户登录信息缓存,为防止Spring循环依赖与安全考虑 ,单独构成工具类
|
// * @param userName /
|
||||||
*/
|
// */
|
||||||
@Component
|
// public void cleanUserCache(String userName) {
|
||||||
public class UserCacheClean {
|
// if (StrUtil.isNotEmpty(userName)) {
|
||||||
|
//// UserDetailsServiceImpl.userDtoCache.remove(userName);
|
||||||
/**
|
// }
|
||||||
* 清理特定用户缓存信息<br>
|
|
||||||
* 用户信息变更时
|
|
||||||
*
|
|
||||||
* @param userName /
|
|
||||||
*/
|
|
||||||
public void cleanUserCache(String userName) {
|
|
||||||
if (StrUtil.isNotEmpty(userName)) {
|
|
||||||
// UserDetailsServiceImpl.userDtoCache.remove(userName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 清理所有用户的缓存信息<br>
|
|
||||||
* ,如发生角色授权信息变化,可以简便的全部失效缓存
|
|
||||||
*/
|
|
||||||
// public void cleanAll() {
|
|
||||||
// UserDetailsServiceImpl.userDtoCache.clear();
|
|
||||||
// }
|
// }
|
||||||
}
|
//
|
||||||
|
// /**
|
||||||
|
// * 清理所有用户的缓存信息<br>
|
||||||
|
// * ,如发生角色授权信息变化,可以简便的全部失效缓存
|
||||||
|
// */
|
||||||
|
//// public void cleanAll() {
|
||||||
|
//// UserDetailsServiceImpl.userDtoCache.clear();
|
||||||
|
//// }
|
||||||
|
//}
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ public class QRCodeController {
|
|||||||
|
|
||||||
@PostMapping("/generateQRCode")
|
@PostMapping("/generateQRCode")
|
||||||
@Log("生成二维码")
|
@Log("生成二维码")
|
||||||
|
@SaIgnore
|
||||||
public ResponseEntity<Object> generateQRCode(@Validated @RequestBody GenerateQRCodeParam generateQRCodeParam){
|
public ResponseEntity<Object> generateQRCode(@Validated @RequestBody GenerateQRCodeParam generateQRCodeParam){
|
||||||
return new ResponseEntity<>(qrCodeService.generateQRCode(generateQRCodeParam), HttpStatus.OK);
|
return new ResponseEntity<>(qrCodeService.generateQRCode(generateQRCodeParam), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|||||||
55
nl-common/src/main/java/org/nl/config/CorsFilter.java
Normal file
55
nl-common/src/main/java/org/nl/config/CorsFilter.java
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
//package org.nl.config;
|
||||||
|
//
|
||||||
|
//import jakarta.servlet.*;
|
||||||
|
//import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
//import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
//import org.springframework.core.annotation.Order;
|
||||||
|
//import org.springframework.stereotype.Component;
|
||||||
|
//
|
||||||
|
//import java.io.IOException;
|
||||||
|
//
|
||||||
|
///**
|
||||||
|
// * 跨域过滤器
|
||||||
|
// * @author kong
|
||||||
|
// */
|
||||||
|
//@Component
|
||||||
|
//@Order(-200)
|
||||||
|
//public class CorsFilter implements Filter {
|
||||||
|
//
|
||||||
|
// static final String OPTIONS = "OPTIONS";
|
||||||
|
//
|
||||||
|
// @Override
|
||||||
|
// public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
|
||||||
|
// throws IOException, ServletException {
|
||||||
|
// HttpServletRequest request = (HttpServletRequest) req;
|
||||||
|
// HttpServletResponse response = (HttpServletResponse) res;
|
||||||
|
// // 允许指定域访问跨域资源
|
||||||
|
// response.setHeader("Access-Control-Allow-Origin", "*");
|
||||||
|
// // 允许所有请求方式
|
||||||
|
// response.setHeader("Access-Control-Allow-Methods", "*");
|
||||||
|
// // 有效时间
|
||||||
|
// response.setHeader("Access-Control-Max-Age", "3600");
|
||||||
|
// // 允许的header参数
|
||||||
|
// response.setHeader("Access-Control-Allow-Headers", "*");
|
||||||
|
// response.setHeader("Access-Control-Allow-Credentials", "true");
|
||||||
|
//
|
||||||
|
// // 如果是预检请求,直接返回
|
||||||
|
// if (OPTIONS.equals(request.getMethod())) {
|
||||||
|
// System.out.println("=======================浏览器发来了OPTIONS预检请求==========");
|
||||||
|
// response.getWriter().print("");
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // System.out.println("*********************************过滤器被使用**************************");
|
||||||
|
// chain.doFilter(req, res);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @Override
|
||||||
|
// public void init(FilterConfig filterConfig) {
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @Override
|
||||||
|
// public void destroy() {
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//}
|
||||||
@@ -1,13 +1,23 @@
|
|||||||
package org.nl.satoken;
|
package org.nl.satoken;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.context.SaHolder;
|
||||||
import cn.dev33.satoken.interceptor.SaInterceptor;
|
import cn.dev33.satoken.interceptor.SaInterceptor;
|
||||||
|
import cn.dev33.satoken.jwt.StpLogicJwtForSimple;
|
||||||
import cn.dev33.satoken.router.SaRouter;
|
import cn.dev33.satoken.router.SaRouter;
|
||||||
|
import cn.dev33.satoken.stp.StpLogic;
|
||||||
import cn.dev33.satoken.stp.StpUtil;
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.cors.CorsConfiguration;
|
||||||
|
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
||||||
|
import org.springframework.web.filter.CorsFilter;
|
||||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author dsh
|
* @author dsh
|
||||||
@@ -19,10 +29,64 @@ public class SaTokenConfig implements WebMvcConfigurer {
|
|||||||
@Resource
|
@Resource
|
||||||
private SecurityProperties securityProperties;
|
private SecurityProperties securityProperties;
|
||||||
|
|
||||||
|
// Sa-Token 整合 jwt (Simple 简单模式)
|
||||||
|
@Bean
|
||||||
|
public StpLogic getStpLogicJwt() {
|
||||||
|
return new StpLogicJwtForSimple();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addInterceptors(InterceptorRegistry registry) {
|
public void addInterceptors(InterceptorRegistry registry) {
|
||||||
registry.addInterceptor(new SaInterceptor(handle -> StpUtil.checkLogin()))
|
registry.addInterceptor(new SaInterceptor(handle -> {
|
||||||
|
// 检查是否为 OPTIONS 请求
|
||||||
|
String method = SaHolder.getRequest().getMethod();
|
||||||
|
if ("OPTIONS".equalsIgnoreCase(method)) {
|
||||||
|
return; // 直接放行 OPTIONS 请求
|
||||||
|
}
|
||||||
|
StpUtil.checkLogin();
|
||||||
|
}))
|
||||||
.addPathPatterns("/**")
|
.addPathPatterns("/**")
|
||||||
.excludePathPatterns(securityProperties.getExcludes());
|
.excludePathPatterns(securityProperties.getExcludes());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public CorsFilter corsFilter() {
|
||||||
|
CorsConfiguration config = new CorsConfiguration();
|
||||||
|
|
||||||
|
// 允许的源
|
||||||
|
config.setAllowedOriginPatterns(Collections.singletonList("*"));
|
||||||
|
// 注意:如果要指定具体域名,使用下面的方式
|
||||||
|
// config.setAllowedOrigins(Arrays.asList(
|
||||||
|
// "http://192.168.10.17:8018",
|
||||||
|
// "http://localhost:8018",
|
||||||
|
// "http://127.0.0.1:8018"
|
||||||
|
// ));
|
||||||
|
|
||||||
|
// 允许凭证(cookies)
|
||||||
|
config.setAllowCredentials(true);
|
||||||
|
|
||||||
|
// 允许的请求方法
|
||||||
|
config.setAllowedMethods(Arrays.asList(
|
||||||
|
"GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH", "HEAD"
|
||||||
|
));
|
||||||
|
|
||||||
|
// 允许的请求头
|
||||||
|
config.setAllowedHeaders(Arrays.asList(
|
||||||
|
"Origin", "X-Requested-With", "Content-Type", "Accept",
|
||||||
|
"Authorization", "satoken", "X-Token", "X-Requested-With"
|
||||||
|
));
|
||||||
|
|
||||||
|
// 暴露的响应头
|
||||||
|
config.setExposedHeaders(Arrays.asList(
|
||||||
|
"satoken", "Authorization", "Content-Disposition"
|
||||||
|
));
|
||||||
|
|
||||||
|
// 预检请求的缓存时间(秒)
|
||||||
|
config.setMaxAge(3600L);
|
||||||
|
|
||||||
|
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
||||||
|
source.registerCorsConfiguration("/**", config);
|
||||||
|
|
||||||
|
return new CorsFilter(source);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import org.mybatis.spring.annotation.MapperScan;
|
|||||||
import org.nl.config.SpringContextHolder;
|
import org.nl.config.SpringContextHolder;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.boot.web.servlet.ServletComponentScan;
|
||||||
import org.springframework.context.ConfigurableApplicationContext;
|
import org.springframework.context.ConfigurableApplicationContext;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.core.env.Environment;
|
import org.springframework.core.env.Environment;
|
||||||
@@ -37,8 +38,10 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
@RestController
|
@RestController
|
||||||
@SpringBootApplication(exclude = {
|
@SpringBootApplication(exclude = {
|
||||||
io.github.eternalstone.captcha.autoconfig.EasyCaptchaAutoConfiguration.class
|
io.github.eternalstone.captcha.autoconfig.EasyCaptchaAutoConfiguration.class,
|
||||||
|
org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration.class
|
||||||
})
|
})
|
||||||
|
@ServletComponentScan
|
||||||
@EnableScheduling
|
@EnableScheduling
|
||||||
@EnableTransactionManagement
|
@EnableTransactionManagement
|
||||||
@EnableMethodCache(basePackages = "org.nl")
|
@EnableMethodCache(basePackages = "org.nl")
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ spring:
|
|||||||
redis:
|
redis:
|
||||||
#数据库索引
|
#数据库索引
|
||||||
database: 2
|
database: 2
|
||||||
host: 192.168.29.130
|
host: 127.0.0.1
|
||||||
port: 6379
|
port: 6379
|
||||||
password: 123456
|
password: 123456
|
||||||
|
|
||||||
@@ -126,7 +126,7 @@ sa-token:
|
|||||||
# Redis数据库索引(默认为0)
|
# Redis数据库索引(默认为0)
|
||||||
database: 2
|
database: 2
|
||||||
# Redis服务器地址
|
# Redis服务器地址
|
||||||
host: 192.168.29.130
|
host: 127.0.0.1
|
||||||
# Redis服务器连接端口
|
# Redis服务器连接端口
|
||||||
port: 6379
|
port: 6379
|
||||||
# Redis服务器连接密码(默认为空)
|
# Redis服务器连接密码(默认为空)
|
||||||
|
|||||||
@@ -63,3 +63,6 @@ security:
|
|||||||
- /**/*.css
|
- /**/*.css
|
||||||
- /**/*.js
|
- /**/*.js
|
||||||
- /**/*.png
|
- /**/*.png
|
||||||
|
# actuator 监控配置
|
||||||
|
- /actuator
|
||||||
|
- /actuator/**
|
||||||
Reference in New Issue
Block a user