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:"; public static final String CACHE_PREFIX = "waynboot-mall:";

@ -22,7 +22,6 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
@ -49,7 +48,7 @@ public class IHomeServiceImpl implements IHomeService {
R success = R.success(); R success = R.success();
Map<String, Object> shopHomeIndexHash = redisCache.getCacheMap(SHOP_HOME_INDEX_HASH); 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)) { if (MapUtils.isNotEmpty(shopHomeIndexHash) && shopHomeIndexHash.containsKey(SHOP_HOME_INDEX_HASH_EXPIRATION_FIELD)) {
long time = (long) shopHomeIndexHash.get(SHOP_HOME_INDEX_HASH_EXPIRATION_FIELD); long time = (long) shopHomeIndexHash.get(SHOP_HOME_INDEX_HASH_EXPIRATION_FIELD);
if ((nowTime - time) <= Constants.ONE_DAY) { if ((nowTime - time) <= Constants.ONE_DAY) {

@ -158,7 +158,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
unrecv++; unrecv++;
} else if (OrderUtil.isConfirmStatus(order) || OrderUtil.isAutoConfirmStatus(order)) { } else if (OrderUtil.isConfirmStatus(order) || OrderUtil.isAutoConfirmStatus(order)) {
uncomment += order.getComments(); uncomment += order.getComments();
} // todo }
} }
success.add("unpaid", unpaid); success.add("unpaid", unpaid);
@ -497,7 +497,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
String form; String form;
try { try {
// 需要自行申请支付宝的沙箱账号、申请appID并在配置文件中依次配置AppID、密钥、公钥否则这里会报错。 // 需要自行申请支付宝的沙箱账号、申请appID并在配置文件中依次配置AppID、密钥、公钥否则这里会报错。
form = alipayClient.pageExecute(alipayRequest).getBody();//调用SDK生成表单 form = alipayClient.pageExecute(alipayRequest).getBody();// 调用SDK生成表单
return R.success().add("form", form); return R.success().add("form", form);
} catch (AlipayApiException e) { } catch (AlipayApiException e) {
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
@ -599,7 +599,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
@Override @Override
public void aliPayNotify(HttpServletRequest request, HttpServletResponse response) throws AlipayApiException { public void aliPayNotify(HttpServletRequest request, HttpServletResponse response) throws AlipayApiException {
//将异步通知中收到的所有参数都存放到map中 // 将异步通知中收到的所有参数都存放到map中
Map<String, String[]> parameterMap = request.getParameterMap(); Map<String, String[]> parameterMap = request.getParameterMap();
Map<String, String> paramsMap = new HashMap<>(); Map<String, String> paramsMap = new HashMap<>();
parameterMap.forEach((s, strings) -> paramsMap.put(s, strings[0])); parameterMap.forEach((s, strings) -> paramsMap.put(s, strings[0]));

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

@ -17,7 +17,7 @@
<!-- 通用查询结果列 --> <!-- 通用查询结果列 -->
<sql id="selectSerchHistoryVo"> <sql id="selectSerchHistoryVo">
select id, 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 from search_history s
</sql> </sql>

Loading…
Cancel
Save