|
|
@@ -1,7 +1,9 @@
|
|
|
package shop.alien.store.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
@@ -13,6 +15,7 @@ import shop.alien.entity.store.UserLoginInfo;
|
|
|
import shop.alien.entity.store.dto.SystemUserAddDto;
|
|
|
import shop.alien.entity.store.dto.SystemUserStatusDto;
|
|
|
import shop.alien.entity.store.dto.SystemUserUpdateDto;
|
|
|
+import shop.alien.entity.store.vo.LifeSysVo;
|
|
|
import shop.alien.entity.store.vo.SystemLoginVo;
|
|
|
import shop.alien.mapper.LifeSysMapper;
|
|
|
import shop.alien.store.config.BaseRedisService;
|
|
|
@@ -22,11 +25,7 @@ import shop.alien.util.common.JwtUtil;
|
|
|
|
|
|
import java.security.MessageDigest;
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Set;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
@@ -78,10 +77,9 @@ public class SystemServiceImpl implements SystemService {
|
|
|
}
|
|
|
SystemLoginVo result = new SystemLoginVo();
|
|
|
//给密码加密MD5,查询用户是否存在
|
|
|
- LifeSys lifeSys = lifeSysMapper.selectOne(
|
|
|
- new LambdaQueryWrapper<LifeSys>()
|
|
|
- .eq(LifeSys::getUserName, username)
|
|
|
- );
|
|
|
+ QueryWrapper<LifeSys> loginQueryWrapper = new QueryWrapper<>();
|
|
|
+ loginQueryWrapper.eq("user_name", username);
|
|
|
+ LifeSys lifeSys = lifeSysMapper.selectOne(loginQueryWrapper);
|
|
|
if (lifeSys != null && lifeSys.getUserPassword().equals(encryptToMD5(password))) {
|
|
|
Map<String, String> tokenMap = new HashMap<>();
|
|
|
tokenMap.put("phone", lifeSys.getPhone());
|
|
|
@@ -119,8 +117,8 @@ public class SystemServiceImpl implements SystemService {
|
|
|
}
|
|
|
|
|
|
// 校验用户名是否已存在
|
|
|
- LambdaQueryWrapper<LifeSys> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
- queryWrapper.eq(LifeSys::getUserName, userName);
|
|
|
+ QueryWrapper<LifeSys> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("user_name", userName);
|
|
|
LifeSys existingUser = lifeSysMapper.selectOne(queryWrapper);
|
|
|
if (existingUser != null) {
|
|
|
return R.fail("该用户名已存在,请更换其他用户名");
|
|
|
@@ -147,8 +145,8 @@ public class SystemServiceImpl implements SystemService {
|
|
|
@Override
|
|
|
public R<LifeSys> addUser(SystemUserAddDto addDto) {
|
|
|
// 校验用户名是否已存在
|
|
|
- LambdaQueryWrapper<LifeSys> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
- queryWrapper.eq(LifeSys::getUserName, addDto.getUserName());
|
|
|
+ QueryWrapper<LifeSys> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("user_name", addDto.getUserName());
|
|
|
LifeSys existingUser = lifeSysMapper.selectOne(queryWrapper);
|
|
|
if (existingUser != null) {
|
|
|
return R.fail("该用户名已存在,请更换其他用户名");
|
|
|
@@ -233,8 +231,8 @@ public class SystemServiceImpl implements SystemService {
|
|
|
|
|
|
// 如果提供了用户名,校验用户名是否与其他用户重复
|
|
|
if (StringUtils.hasText(updateDto.getUserName()) && !updateDto.getUserName().equals(lifeSys.getUserName())) {
|
|
|
- LambdaQueryWrapper<LifeSys> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
- queryWrapper.eq(LifeSys::getUserName, updateDto.getUserName());
|
|
|
+ QueryWrapper<LifeSys> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("user_name", updateDto.getUserName());
|
|
|
LifeSys existingUser = lifeSysMapper.selectOne(queryWrapper);
|
|
|
if (existingUser != null) {
|
|
|
return R.fail("该用户名已存在,请更换其他用户名");
|
|
|
@@ -392,7 +390,7 @@ public class SystemServiceImpl implements SystemService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public R resetPassword(Integer userId) {
|
|
|
+ public R<LifeSys> resetPassword(Integer userId) {
|
|
|
// 校验用户ID
|
|
|
if (userId == null) {
|
|
|
return R.fail("用户ID不能为空");
|
|
|
@@ -417,6 +415,51 @@ public class SystemServiceImpl implements SystemService {
|
|
|
return R.fail("密码重置失败,请稍后重试");
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public IPage<LifeSysVo> getUserPage(int page, int size, String userName, String realName, String phone, String departmentId, Long roleId) {
|
|
|
+ // 创建分页对象
|
|
|
+ IPage<LifeSysVo> pageObj = new Page<>(page, size);
|
|
|
+
|
|
|
+ // 构建查询条件
|
|
|
+ QueryWrapper<LifeSys> queryWrapper = new QueryWrapper<>();
|
|
|
+
|
|
|
+ // 用户名模糊查询
|
|
|
+ if (StringUtils.hasText(userName)) {
|
|
|
+ queryWrapper.like("ls.user_name", userName);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 真实姓名模糊查询
|
|
|
+ if (StringUtils.hasText(realName)) {
|
|
|
+ queryWrapper.like("ls.real_name", realName);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 联系电话模糊查询
|
|
|
+ if (StringUtils.hasText(phone)) {
|
|
|
+ queryWrapper.like("ls.phone", phone);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 部门ID精确查询
|
|
|
+ if (StringUtils.hasText(departmentId)) {
|
|
|
+ queryWrapper.eq("ls.department_id", departmentId);
|
|
|
+ }
|
|
|
+
|
|
|
+ queryWrapper.eq("ls.status", 1);
|
|
|
+
|
|
|
+ // 如果指定了角色ID,需要先查询角色关联表获取用户ID列表
|
|
|
+ if (roleId != null) {
|
|
|
+ queryWrapper.eq("lsur.role_id", roleId);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 未删除的用户
|
|
|
+ queryWrapper.eq("ls.delete_flag", 0);
|
|
|
+ queryWrapper.groupBy("ls.id");
|
|
|
+ // 按创建时间倒序
|
|
|
+ queryWrapper.orderByDesc("ls.created_time");
|
|
|
+
|
|
|
+ // 执行分页查询
|
|
|
+ return lifeSysMapper.selectPageAndRoleName(pageObj, queryWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
public static String encryptToMD5(String input) {
|
|
|
try {
|
|
|
// 获取 MD5 算法的 MessageDigest 实例
|