瀏覽代碼

```
refactor(admin): 优化管理员用户查询逻辑并简化代码

- 合并 AdminUserServiceImpl 中的嵌套判断条件,提升代码可读性- 移除多余的局部变量赋值,直接返回查询结果- 将 AlarmController 中的 @Autowired 替换为 Lombok 的 @RequiredArgsConstructor, 使用 final 字段注入依赖,符合现代 Spring 编程风格- 在 WechatController 中增加微信授权地址日志输出,便于调试追踪
```

chejianzheng 1 月之前
父節點
當前提交
92b76c1585

+ 3 - 3
portal-service-application/src/main/java/com/hfln/portal/application/controller/wap/AlarmController.java

@@ -9,8 +9,8 @@ import com.hfln.portal.common.request.event.*;
 import com.hfln.portal.domain.gateway.AlarmGateway;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.tags.Tag;
+import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -24,10 +24,10 @@ import java.util.List;
 @Tag(name = "告警相关")
 @Slf4j
 @RequestMapping("/wap/alarm")
+@RequiredArgsConstructor
 public class AlarmController {
 
-    @Autowired
-    private AlarmGateway alarmGateway;
+    private final AlarmGateway alarmGateway;
 
     @PostMapping("/plan/queryTpl")
     @Operation(summary = "告警计划模板查询")

+ 1 - 0
portal-service-application/src/main/java/com/hfln/portal/application/controller/wap/WechatController.java

@@ -31,6 +31,7 @@ public class WechatController {
 
         log.info("自动跳转微信授权");
         String url = userGateway.authUrl();
+        log.info("微信授权地址:{}", url);
         response.sendRedirect(url);
         return ApiResult.success();
     }

+ 4 - 8
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/service/impl/AdminUserServiceImpl.java

@@ -29,10 +29,8 @@ public class AdminUserServiceImpl extends ServiceImpl<AdminUserInfoMapper, Admin
         queryWrapper.eq(AdminUserInfo::getAccount, account);
         queryWrapper.eq(AdminUserInfo::getIsDeleted, BasePO.DeleteFlag.NOT_DELETED);
         AdminUserInfo userInfo = this.baseMapper.selectOne(queryWrapper);
-        if (Objects.nonNull(userInfo)) {
-            if (PasswordUtil.matches(password, userInfo.getPassword())) {
-                return userInfo;
-            }
+        if (Objects.nonNull(userInfo) && PasswordUtil.matches(password, userInfo.getPassword())) {
+            return userInfo;
         }
         return null;
     }
@@ -42,8 +40,7 @@ public class AdminUserServiceImpl extends ServiceImpl<AdminUserInfoMapper, Admin
         LambdaQueryWrapper<AdminUserInfo> queryWrapper = new LambdaQueryWrapper<>();
         queryWrapper.eq(AdminUserInfo::getPhone, phone);
         queryWrapper.eq(AdminUserInfo::getIsDeleted, BasePO.DeleteFlag.NOT_DELETED);
-        AdminUserInfo userInfo = this.baseMapper.selectOne(queryWrapper);
-        return userInfo;
+        return this.baseMapper.selectOne(queryWrapper);
     }
 
     @Override
@@ -51,8 +48,7 @@ public class AdminUserServiceImpl extends ServiceImpl<AdminUserInfoMapper, Admin
         LambdaQueryWrapper<AdminUserInfo> queryWrapper = new LambdaQueryWrapper<>();
         queryWrapper.eq(AdminUserInfo::getAccount, account);
         queryWrapper.eq(AdminUserInfo::getIsDeleted, BasePO.DeleteFlag.NOT_DELETED);
-        AdminUserInfo userInfo = this.baseMapper.selectOne(queryWrapper);
-        return userInfo;
+        return this.baseMapper.selectOne(queryWrapper);
     }
 
     @Override