feat(商城): 代码优化

master
wayn 1 year ago
parent cc38b50bfa
commit 3b64204caa

@ -10,7 +10,7 @@ public class SysConstants {
/**
* , todo
* ,
*/
public static final String CACHE_PREFIX = "waynboot-mall:";

@ -22,7 +22,6 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
@ -49,7 +48,7 @@ public class IHomeServiceImpl implements IHomeService {
R success = R.success();
Map<String, Object> shopHomeIndexHash = redisCache.getCacheMap(SHOP_HOME_INDEX_HASH);
// 当缓存中存在数据,并且过期时间不为空而且小于等于过期时间则直接从缓存中取出数据
long nowTime = System.currentTimeMillis();;
long nowTime = System.currentTimeMillis();
if (MapUtils.isNotEmpty(shopHomeIndexHash) && shopHomeIndexHash.containsKey(SHOP_HOME_INDEX_HASH_EXPIRATION_FIELD)) {
long time = (long) shopHomeIndexHash.get(SHOP_HOME_INDEX_HASH_EXPIRATION_FIELD);
if ((nowTime - time) <= Constants.ONE_DAY) {

@ -158,7 +158,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
unrecv++;
} else if (OrderUtil.isConfirmStatus(order) || OrderUtil.isAutoConfirmStatus(order)) {
uncomment += order.getComments();
} // todo
}
}
success.add("unpaid", unpaid);

@ -12,6 +12,8 @@ import org.springframework.security.config.annotation.authentication.configurati
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.config.annotation.web.configurers.HeadersConfigurer;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.web.SecurityFilterChain;
@ -38,16 +40,18 @@ public class SecurityConfig {
public SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Exception {
httpSecurity
// cors启用
.cors().and()
.cors(httpSecurityCorsConfigurer -> {
})
// CSRF(跨站请求伪造)禁用因为不使用session
.csrf().disable()
.csrf(AbstractHttpConfigurer::disable)
// 认证失败处理类
.exceptionHandling().authenticationEntryPoint(unauthorizedHandler).and()
.exceptionHandling(configurer -> configurer.authenticationEntryPoint(unauthorizedHandler))
// 基于token所以不需要session
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
.sessionManagement(configurer -> configurer.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
// 过滤请求
.authorizeHttpRequests()
// 对于登录login 验证码captchaImage 允许匿名访问
.authorizeHttpRequests(
registry -> {
registry
.requestMatchers("favicon.ico", "/actuator/**", "/login", "/registry", "/sendEmailCode", "/test/**", "/seckill/**", "/captcha").anonymous()
.requestMatchers("/home/**", "/category/**", "/comment/**", "/goods/detail/**", "/cart/goodsCount", "/diamond/**").permitAll()
.requestMatchers("/upload/**").anonymous()
@ -60,12 +64,13 @@ public class SecurityConfig {
.requestMatchers("/druid/**").anonymous()
.requestMatchers("/message/**").anonymous()
// 除上面外的所有请求全部需要鉴权认证
.anyRequest().authenticated().and()
.headers().frameOptions().disable();
httpSecurity.logout().logoutUrl("/logout").logoutSuccessHandler(logoutSuccessHandler);
// 添加JWT filter
httpSecurity.addFilterBefore(jwtAuthenticationTokenFilter, UsernamePasswordAuthenticationFilter.class);
httpSecurity.userDetailsService(userDetailsService);
.anyRequest().authenticated();
}
)
.logout(configurer -> configurer.logoutUrl("/logout").logoutSuccessHandler(logoutSuccessHandler))
.headers(configurer -> configurer.frameOptions(HeadersConfigurer.FrameOptionsConfig::disable))
.addFilterBefore(jwtAuthenticationTokenFilter, UsernamePasswordAuthenticationFilter.class)
.userDetailsService(userDetailsService);
return httpSecurity.build();
}

@ -17,7 +17,7 @@
<!-- 通用查询结果列 -->
<sql id="selectSerchHistoryVo">
select id,
user_id, keyword, from, create_time, has_goods, update_time, del_flag
user_id, keyword from create_time, has_goods, update_time, del_flag
from search_history s
</sql>

Loading…
Cancel
Save