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);
@ -497,7 +497,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
String form;
try {
// 需要自行申请支付宝的沙箱账号、申请appID并在配置文件中依次配置AppID、密钥、公钥否则这里会报错。
form = alipayClient.pageExecute(alipayRequest).getBody();//调用SDK生成表单
form = alipayClient.pageExecute(alipayRequest).getBody();// 调用SDK生成表单
return R.success().add("form", form);
} catch (AlipayApiException e) {
log.error(e.getMessage(), e);
@ -599,7 +599,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
@Override
public void aliPayNotify(HttpServletRequest request, HttpServletResponse response) throws AlipayApiException {
//将异步通知中收到的所有参数都存放到map中
// 将异步通知中收到的所有参数都存放到map中
Map<String, String[]> parameterMap = request.getParameterMap();
Map<String, String> paramsMap = new HashMap<>();
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.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,34 +40,37 @@ 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 允许匿名访问
.requestMatchers("favicon.ico", "/actuator/**", "/login", "/registry", "/sendEmailCode", "/test/**", "/seckill/**", "/captcha").anonymous()
.requestMatchers("/home/**", "/category/**", "/comment/**", "/goods/detail/**", "/cart/goodsCount", "/diamond/**").permitAll()
.requestMatchers("/upload/**").anonymous()
.requestMatchers("/common/download**").anonymous()
.requestMatchers("/doc.html").anonymous()
.requestMatchers("/swagger-ui/**").anonymous()
.requestMatchers("/swagger-resources/**").anonymous()
.requestMatchers("/webjars/**").anonymous()
.requestMatchers("/*/api-docs").anonymous()
.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);
.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()
.requestMatchers("/common/download**").anonymous()
.requestMatchers("/doc.html").anonymous()
.requestMatchers("/swagger-ui/**").anonymous()
.requestMatchers("/swagger-resources/**").anonymous()
.requestMatchers("/webjars/**").anonymous()
.requestMatchers("/*/api-docs").anonymous()
.requestMatchers("/druid/**").anonymous()
.requestMatchers("/message/**").anonymous()
// 除上面外的所有请求全部需要鉴权认证
.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