skyline 3 mesiacov pred
rodič
commit
8a65ad0b94

+ 14 - 0
haha-admin/src/main/java/com/haha/admin/controller/AdminController.java

@@ -49,6 +49,20 @@ public class AdminController {
         return Result.error(result.getCode(), "查询失败");
     }
     
+    /**
+     * 获取管理员详情
+     */
+    @GetMapping("/{id}")
+    public Result<Admin> getById(@PathVariable Long id) {
+        Admin admin = adminService.getById(id);
+        if (admin == null) {
+            return Result.error(404, "管理员不存在");
+        }
+        // 清除密码
+        admin.setPassword(null);
+        return Result.success("查询成功", admin);
+    }
+    
     /**
      * 添加管理员
      */

+ 1 - 1
haha-mapper/src/main/java/com/haha/mapper/RoleMapper.java

@@ -25,6 +25,6 @@ public interface RoleMapper extends BaseMapper<Role> {
      * @param roleId 角色ID
      * @return 用户数量
      */
-    @Select("SELECT COUNT(*) FROM t_admin WHERE role_id = #{roleId}")
+    @Select("SELECT COUNT(*) FROM t_admin WHERE FIND_IN_SET(#{roleId}, role_ids) > 0")
     int countUsersByRoleId(@Param("roleId") Long roleId);
 }

+ 6 - 0
haha-service/pom.xml

@@ -83,6 +83,12 @@
             <artifactId>lombok</artifactId>
             <optional>true</optional>
         </dependency>
+
+        <!-- Spring Security Crypto (BCrypt密码加密) -->
+        <dependency>
+            <groupId>org.springframework.security</groupId>
+            <artifactId>spring-security-crypto</artifactId>
+        </dependency>
     </dependencies>
 
 </project>

+ 19 - 14
haha-service/src/main/java/com/haha/service/impl/AdminServiceImpl.java

@@ -9,6 +9,7 @@ import com.haha.entity.Admin;
 import com.haha.mapper.AdminMapper;
 import com.haha.service.AdminService;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
 import org.springframework.stereotype.Service;
 import org.springframework.util.StringUtils;
 
@@ -23,6 +24,8 @@ import java.util.Map;
 @Service
 public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements AdminService {
 
+    private final BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
+
     @Override
     public Result<IPage<Admin>> getAdminList(int page, int pageSize, String username, String phone, Long roleId, Integer status) {
         try {
@@ -84,10 +87,12 @@ public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements
             admin.setCreateTime(LocalDateTime.now());
             admin.setUpdateTime(LocalDateTime.now());
 
-            // 临时方案:密码明文存储,生产环境需要加密
-            if (!StringUtils.hasText(admin.getPassword())) {
-                admin.setPassword("123456"); // 默认密码
+            // BCrypt加密密码
+            String password = admin.getPassword();
+            if (!StringUtils.hasText(password)) {
+                password = "123456"; // 默认密码
             }
+            admin.setPassword(passwordEncoder.encode(password));
 
             boolean success = this.save(admin);
             return success ? Result.success("添加成功", null) : Result.error(500, "添加失败");
@@ -164,12 +169,11 @@ public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements
                 return Result.error(404, "管理员不存在");
             }
 
-            // 临时方案:密码明文存储,生产环境需要加密
+            // BCrypt加密密码
             if (!StringUtils.hasText(newPassword)) {
                 newPassword = "123456"; // 默认密码
             }
-
-            admin.setPassword(newPassword);
+            admin.setPassword(passwordEncoder.encode(newPassword));
             admin.setUpdateTime(LocalDateTime.now());
 
             boolean success = this.updateById(admin);
@@ -187,18 +191,19 @@ public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements
             Map<String, Object> statistics = new HashMap<>();
 
             // 总管理员数
-            long totalUsers = this.count();
-            statistics.put("totalUsers", totalUsers);
+            long total = this.count();
+            statistics.put("total", total);
 
             // 正常状态管理员数
-            long activeUsers = this.count(new LambdaQueryWrapper<Admin>().eq(Admin::getStatus, 1));
-            statistics.put("activeUsers", activeUsers);
+            long active = this.count(new LambdaQueryWrapper<Admin>().eq(Admin::getStatus, 1));
+            statistics.put("active", active);
 
-            // 在线用户数(暂时返回0,后续可通过Redis统计)
-            statistics.put("onlineUsers", 0);
+            // 禁用状态管理员数
+            long disabled = this.count(new LambdaQueryWrapper<Admin>().eq(Admin::getStatus, 2));
+            statistics.put("disabled", disabled);
 
-            // 今日新增
-            statistics.put("todayNew", 0);
+            // 今日登录数(暂时返回0,后续可通过Redis统计)
+            statistics.put("todayLogin", 0);
 
             return Result.success("获取成功", statistics);