Parcourir la source

更新用户信息完善

skyline il y a 2 ans
Parent
commit
eb8fb790dc

+ 0 - 29
common/src/main/java/com/kym/common/config/Properties.java

@@ -1,29 +0,0 @@
-package com.kym.common.config;
-
-import lombok.Data;
-import org.springframework.boot.context.properties.ConfigurationProperties;
-import org.springframework.context.annotation.Configuration;
-
-/**
- * @author skyline
- * @description 微信支付配置类
- * @date 2023-07-22 23:09
- */
-@Data
-@Configuration
-@ConfigurationProperties(prefix = "wechat.payment")
-public class Properties {
-
-    private String appId;
-
-    private String appSecret;
-
-    private String mchId;
-
-    private String mchKey;
-
-    private String notifyUrl;
-
-    private String keyPath;
-
-}

+ 2 - 1
common/src/main/java/com/kym/common/handler/GlobalExceptionHandler.java

@@ -69,7 +69,7 @@ public class GlobalExceptionHandler {
     @ExceptionHandler(value = NotLoginException.class)
     @ResponseBody
     public R handleLoginException(NotLoginException e) {
-        LOGGER.error("登录异常", e);
+
         var message = "";
         if (e.getType().equals(NotLoginException.NOT_TOKEN)) {
             message = NotLoginException.NOT_TOKEN_MESSAGE;
@@ -88,6 +88,7 @@ public class GlobalExceptionHandler {
         } else {
             message = NotLoginException.DEFAULT_MESSAGE;
         }
+        LOGGER.error("登录异常:{}", message);
         return R.failed(LOGIN_FAILED.getCode(), message);
     }
 

+ 1 - 1
entity/src/main/java/com/kym/entity/miniapp/Cars.java

@@ -32,7 +32,7 @@ public class Cars implements Serializable {
     /**
      * 车牌号码
      */
-    private Long plateNo;
+    private String plateNo;
 
     /**
      * 车辆类型

+ 26 - 0
miniapp/src/main/java/com/kym/miniapp/config/SaTokenConfigure.java

@@ -0,0 +1,26 @@
+package com.kym.miniapp.config;
+
+import cn.dev33.satoken.interceptor.SaInterceptor;
+import cn.dev33.satoken.stp.StpUtil;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+/**
+ * @author skyline
+ * @description 权限校验
+ * @date 2023-07-11 21:49
+ */
+@Configuration
+public class SaTokenConfigure implements WebMvcConfigurer {
+    // 注册拦截器
+    @Override
+    public void addInterceptors(InterceptorRegistry registry) {
+        // 注册 Sa-Token 拦截器,校验规则为 StpUtil.checkLogin() 登录校验。
+        registry.addInterceptor(new SaInterceptor(handle -> StpUtil.checkLogin()))
+                .addPathPatterns("/**")
+                // login接口不鉴权
+                .excludePathPatterns("/api/user/wxLogin");
+    }
+
+}

+ 6 - 4
service/src/main/java/com/kym/service/miniapp/impl/UserServiceImpl.java

@@ -134,7 +134,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
         StpUtil.getSession().set("mobilePhone", user.getMobilePhone());
         user.setLastLoginTime(LocalDateTime.now());
         updateById(user);
-        LOGGER.info("用户:" + user.getMobilePhone() + "/id:" + user.getId() + "登录成功");
+        LOGGER.info("用户:{}/{}登录成功,tokenName:{},tokenValue:{}", user.getMobilePhone(), user.getId(), StpUtil.getTokenName(), StpUtil.getTokenValue());
         return R.success(of("userId", user.getId(), "accessToken", "Bearer ".concat(StpUtil.getTokenValue())));
     }
 
@@ -149,21 +149,23 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
     @Transactional(rollbackFor = Exception.class)
     @Override
     public void updateUser(UserVo userVo) {
+        userVo.setId(StpUtil.getSession().getLong("userId"));
         var user = new User();
         BeanUtils.copyProperties(userVo, user);
         userMapper.updateById(user);
         // 更新车牌信息
         if (userVo.getDefaultPlateNo() != null) {
             var car = new Cars();
-            car.setEngineNo(userVo.defaultPlateNo);
+            car.setUserId(userVo.getId());
+            car.setPlateNo(userVo.defaultPlateNo);
             // 设置为默认
             car.setIsDefult(true);
-            if (!car.getVin().isBlank()) {
+            if (car.getVin() != null) {
                 car.setVin(userVo.getVin());
             }
             // 将用户名下其他车辆设为非默认
             var cars = carsService.listByMap(Map.of("user_id", userVo.getId()));
-            cars.stream().filter(c -> !userVo.getDefaultPlateNo().equals(c.getEngineNo())).peek(s -> s.setIsDefult(true)).collect(Collectors.toList());
+            cars.stream().filter(c -> !userVo.getDefaultPlateNo().equals(c.getEngineNo())).peek(s -> s.setIsDefult(false)).collect(Collectors.toList());
             carsService.updateBatchById(cars);
             var wrapper = new QueryWrapper<Cars>();
             wrapper.eq("plate_no", userVo.getDefaultPlateNo());