|
|
@@ -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);
|
|
|
|