opt:管理后台系统优化。

This commit is contained in:
2026-02-06 18:05:13 +08:00
parent c23fa3f3f3
commit 4247b41831
10 changed files with 211 additions and 115 deletions

View File

@@ -113,36 +113,6 @@ public class VehicleServiceImpl implements VehicleService {
@Override
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);
}
}

View File

@@ -13,10 +13,10 @@ import org.springframework.data.redis.listener.RedisMessageListenerContainer;
@Configuration
public class RedisListenerConfig {
// @Bean
// RedisMessageListenerContainer container(RedisConnectionFactory connectionFactory) {
// RedisMessageListenerContainer container = new RedisMessageListenerContainer();
// container.setConnectionFactory(connectionFactory);
// return container;
// }
@Bean
RedisMessageListenerContainer container(RedisConnectionFactory connectionFactory) {
RedisMessageListenerContainer container = new RedisMessageListenerContainer();
container.setConnectionFactory(connectionFactory);
return container;
}
}

View File

@@ -1,28 +1,28 @@
package org.nl.sys.modular.backgroundmanagement.common.security.satoken;
import cn.dev33.satoken.interceptor.SaInterceptor;
import cn.dev33.satoken.jwt.StpLogicJwtForSimple;
import cn.dev33.satoken.stp.StpLogic;
import cn.dev33.satoken.stp.StpUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
* @author: lyd
* @description: sa-token的配置路由拦截
* @Date: 2022-09-20
*/
@Slf4j
@Configuration
public class SaTokenConfigure implements WebMvcConfigurer {
// Sa-Token 整合 jwt (Simple 简单模式)
@Bean
public StpLogic getStpLogicJwt() {
return new StpLogicJwtForSimple();
}
}
//package org.nl.sys.modular.backgroundmanagement.common.security.satoken;
//
//import cn.dev33.satoken.interceptor.SaInterceptor;
//import cn.dev33.satoken.jwt.StpLogicJwtForSimple;
//import cn.dev33.satoken.stp.StpLogic;
//import cn.dev33.satoken.stp.StpUtil;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
//import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
//
///**
// * @author: lyd
// * @description: sa-token的配置路由拦截
// * @Date: 2022-09-20
// */
//@Slf4j
//@Configuration
//public class SaTokenConfigure implements WebMvcConfigurer {
//
// // Sa-Token 整合 jwt (Simple 简单模式)
// @Bean
// public StpLogic getStpLogicJwt() {
// return new StpLogicJwtForSimple();
// }
//}

View File

@@ -1,48 +1,48 @@
package org.nl.sys.modular.backgroundmanagement.common.security.service;
//*
// * Copyright 2019-2020 the original author or authors.
// *
// * Licensed under the Apache License, Version 2.0 (the "License");
// * you may not use this file except in compliance with the License.
// * You may obtain a copy of the License at
// *
// * http://www.apache.org/licenses/LICENSE-2.0
// *
// * Unless required by applicable law or agreed to in writing, software
// * distributed under the License is distributed on an "AS IS" BASIS,
// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// * See the License for the specific language governing permissions and
// * limitations under the License.
//package org.nl.sys.modular.backgroundmanagement.common.security.service;
////*
//// * Copyright 2019-2020 the original author or authors.
//// *
//// * Licensed under the Apache License, Version 2.0 (the "License");
//// * you may not use this file except in compliance with the License.
//// * You may obtain a copy of the License at
//// *
//// * http://www.apache.org/licenses/LICENSE-2.0
//// *
//// * Unless required by applicable law or agreed to in writing, software
//// * distributed under the License is distributed on an "AS IS" BASIS,
//// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//// * See the License for the specific language governing permissions and
//// * 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循环依赖与安全考虑 ,单独构成工具类
// */
import cn.hutool.core.util.StrUtil;
import org.springframework.stereotype.Component;
/**
* @author: liaojinlong
* @date: 2020/6/11 18:01
* @apiNote: 用于清理 用户登录信息缓存为防止Spring循环依赖与安全考虑 ,单独构成工具类
*/
@Component
public class UserCacheClean {
/**
* 清理特定用户缓存信息<br>
* 用户信息变更时
*
* @param userName /
*/
public void cleanUserCache(String userName) {
if (StrUtil.isNotEmpty(userName)) {
// UserDetailsServiceImpl.userDtoCache.remove(userName);
}
}
/**
* 清理所有用户的缓存信息<br>
* ,如发生角色授权信息变化,可以简便的全部失效缓存
*/
// public void cleanAll() {
// UserDetailsServiceImpl.userDtoCache.clear();
//@Component
//public class UserCacheClean {
//
// /**
// * 清理特定用户缓存信息<br>
// * 用户信息变更时
// *
// * @param userName /
// */
// public void cleanUserCache(String userName) {
// if (StrUtil.isNotEmpty(userName)) {
//// UserDetailsServiceImpl.userDtoCache.remove(userName);
// }
}
// }
//
// /**
// * 清理所有用户的缓存信息<br>
// * ,如发生角色授权信息变化,可以简便的全部失效缓存
// */
//// public void cleanAll() {
//// UserDetailsServiceImpl.userDtoCache.clear();
//// }
//}

View File

@@ -35,6 +35,7 @@ public class QRCodeController {
@PostMapping("/generateQRCode")
@Log("生成二维码")
@SaIgnore
public ResponseEntity<Object> generateQRCode(@Validated @RequestBody GenerateQRCodeParam generateQRCodeParam){
return new ResponseEntity<>(qrCodeService.generateQRCode(generateQRCodeParam), HttpStatus.OK);
}

View 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() {
// }
//
//}

View File

@@ -1,13 +1,23 @@
package org.nl.satoken;
import cn.dev33.satoken.context.SaHolder;
import cn.dev33.satoken.interceptor.SaInterceptor;
import cn.dev33.satoken.jwt.StpLogicJwtForSimple;
import cn.dev33.satoken.router.SaRouter;
import cn.dev33.satoken.stp.StpLogic;
import cn.dev33.satoken.stp.StpUtil;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Bean;
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.WebMvcConfigurer;
import java.util.Arrays;
import java.util.Collections;
/**
* @author dsh
@@ -19,10 +29,64 @@ public class SaTokenConfig implements WebMvcConfigurer {
@Resource
private SecurityProperties securityProperties;
// Sa-Token 整合 jwt (Simple 简单模式)
@Bean
public StpLogic getStpLogicJwt() {
return new StpLogicJwtForSimple();
}
@Override
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("/**")
.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);
}
}

View File

@@ -20,6 +20,7 @@ import org.mybatis.spring.annotation.MapperScan;
import org.nl.config.SpringContextHolder;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;
@@ -37,8 +38,10 @@ import org.springframework.web.bind.annotation.RestController;
@Slf4j
@RestController
@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
@EnableTransactionManagement
@EnableMethodCache(basePackages = "org.nl")

View File

@@ -59,7 +59,7 @@ spring:
redis:
#数据库索引
database: 2
host: 192.168.29.130
host: 127.0.0.1
port: 6379
password: 123456
@@ -126,7 +126,7 @@ sa-token:
# Redis数据库索引默认为0
database: 2
# Redis服务器地址
host: 192.168.29.130
host: 127.0.0.1
# Redis服务器连接端口
port: 6379
# Redis服务器连接密码默认为空

View File

@@ -63,3 +63,6 @@ security:
- /**/*.css
- /**/*.js
- /**/*.png
# actuator 监控配置
- /actuator
- /actuator/**