소스 검색

修复接口潜在异常

fuyuchuan 1 일 전
부모
커밋
21b63f0e40

+ 2 - 2
base-modules/service-system/service-system-biz/src/main/java/com/usky/system/controller/web/SysUserPersonController.java

@@ -31,9 +31,9 @@ public class SysUserPersonController {
      * @return 0:失败
      */
     @PutMapping("/upIsLoginNotify")
-    public ApiResult<Integer> upIsLoginNotice(@RequestParam Long useId,
+    public ApiResult<Integer> upIsLoginNotice(@RequestParam Long userId,
                                               @RequestParam Integer isLoginNotify) {
-        return ApiResult.success(sysUserPersonService.upIsLoginNotify(useId, isLoginNotify));
+        return ApiResult.success(sysUserPersonService.upIsLoginNotify(userId, isLoginNotify));
     }
 }
 

+ 1 - 1
base-modules/service-system/service-system-biz/src/main/java/com/usky/system/service/SysUserPersonService.java

@@ -13,5 +13,5 @@ import com.usky.common.mybatis.core.CrudService;
  */
 public interface SysUserPersonService extends CrudService<SysUserPerson> {
 
-    public Integer upIsLoginNotify(Long useId, Integer isLoginNotify);
+    public Integer upIsLoginNotify(Long userId, Integer isLoginNotify);
 }

+ 8 - 0
base-modules/service-system/service-system-biz/src/main/java/com/usky/system/service/impl/SysUserPersonServiceImpl.java

@@ -2,6 +2,7 @@ package com.usky.system.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.usky.common.core.exception.BusinessException;
+import com.usky.common.security.utils.SecurityUtils;
 import com.usky.system.domain.SysUserPerson;
 import com.usky.system.mapper.SysUserPersonMapper;
 import com.usky.system.service.SysUserPersonService;
@@ -26,15 +27,22 @@ public class SysUserPersonServiceImpl extends AbstractCrudService<SysUserPersonM
     @Override
     public Integer upIsLoginNotify(Long userId, Integer isLoginNotify) {
 
+        // 判断 isLoginNotify 是否为 0 或 1
         if (isLoginNotify != 0 && isLoginNotify != 1) {
             throw new BusinessException("参数设置错误");
         }
+        // 判断要修改的用户是否为登录用户
+        if (userId.equals(SecurityUtils.getUserId())) {
+            throw new BusinessException("你不能修改非本人的登录通知设置!");
+        }
 
+        // 更新登录通知设置
         LambdaUpdateWrapper<SysUserPerson> wrapper = new LambdaUpdateWrapper<>();
         wrapper.eq(SysUserPerson::getUserId, userId)
                 .set(SysUserPerson::getIsLoginNotify, isLoginNotify);
         int result = sysUserPersonMapper.update(null, wrapper);
 
+        //  更新失败
         if (result <= 0) {
             log.error("用户:{},操作登录通知开关操作失败!");
             throw new BusinessException("登录通知开关操作失败!请重试");