|
|
@ -2,36 +2,36 @@ package com.lottery.admin.service.Impl; |
|
|
|
|
|
|
|
import com.alibaba.excel.EasyExcel; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils; |
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
import com.lottery.admin.controller.AdminUserController; |
|
|
|
import com.lottery.admin.mapper.AdminUserDetailMapper; |
|
|
|
import com.lottery.admin.mapper.AdminUserMapper; |
|
|
|
import com.lottery.admin.mapper.AdminWinMapper; |
|
|
|
import com.lottery.admin.service.AdminUserService; |
|
|
|
import com.lottery.api.service.Impl.UserServiceImpl; |
|
|
|
import com.lottery.dto.AdminLogin; |
|
|
|
import com.lottery.dto.UserDto; |
|
|
|
import com.lottery.dto.UserImportDto; |
|
|
|
import com.lottery.dto.UserQueryDto; |
|
|
|
import com.lottery.entity.Grade; |
|
|
|
import com.lottery.entity.User; |
|
|
|
import com.lottery.entity.UserDetail; |
|
|
|
import com.lottery.entity.WinnerRecord; |
|
|
|
import com.lottery.result.Result; |
|
|
|
import com.lottery.utils.ConvertBeanUtil; |
|
|
|
import com.lottery.utils.ExcelUtil; |
|
|
|
import com.lottery.vo.PageInfo; |
|
|
|
import com.lottery.vo.UserLoginVo; |
|
|
|
import com.lottery.vo.UserVo; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.boot.context.properties.ConfigurationProperties; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
import org.json.JSONObject; |
|
|
|
|
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
import static com.lottery.utils.HttpUtils.postUrlencoded; |
|
|
|
|
|
|
@ -50,6 +50,12 @@ public class AdminUserServiceImpl extends ServiceImpl<AdminUserMapper, User> imp |
|
|
|
private AdminUserMapper adminUserMapper; |
|
|
|
private final static Logger LOGGER = LoggerFactory.getLogger(AdminUserController.class); |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private AdminUserDetailMapper adminUserDetailMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private AdminWinMapper adminWinMapper; |
|
|
|
|
|
|
|
@Override |
|
|
|
public Result<UserLoginVo> AdminUserlogin(AdminLogin adminLogin) { |
|
|
|
String token = ""; |
|
|
@ -95,18 +101,32 @@ public class AdminUserServiceImpl extends ServiceImpl<AdminUserMapper, User> imp |
|
|
|
@Override |
|
|
|
public boolean addUser(UserDto userDto) { |
|
|
|
String jwcode = userDto.getJwcode(); |
|
|
|
LambdaQueryWrapper<User> lambdaQueryWrapper = new LambdaQueryWrapper<>(); |
|
|
|
lambdaQueryWrapper.eq(User::getJwcode, jwcode); |
|
|
|
if(this.count(lambdaQueryWrapper) > 0) { |
|
|
|
return false; |
|
|
|
|
|
|
|
// 1. 查询是否已存在相同精网号的用户 |
|
|
|
LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>(); |
|
|
|
queryWrapper.eq(User::getJwcode, jwcode); |
|
|
|
User existingUser = this.getOne(queryWrapper); |
|
|
|
|
|
|
|
// 2. 判断逻辑 |
|
|
|
if (existingUser != null) { |
|
|
|
if (existingUser.getIsDel() == 0) { |
|
|
|
// 存在未删除的同精网号用户,不允许新增 |
|
|
|
return false; |
|
|
|
} |
|
|
|
// 如果是已删除的用户(is_del=1),先物理删除旧记录 |
|
|
|
this.removeById(existingUser.getId()); |
|
|
|
} |
|
|
|
User user = new User(); // 改用构造函数或直接赋值,避免 Builder 潜在问题 |
|
|
|
|
|
|
|
// 3. 创建新用户 |
|
|
|
User user = new User(); |
|
|
|
user.setUsername(userDto.getUsername()); |
|
|
|
user.setJwcode(jwcode); |
|
|
|
user.setIsWin(0); |
|
|
|
user.setIsDel(0); |
|
|
|
user.setCreateTime(new Date()); |
|
|
|
user.setUpdateTime(new Date()); |
|
|
|
user.setPassword("123456"); // 显式设置,避免被覆盖 |
|
|
|
user.setPassword("123456"); // 默认密码 |
|
|
|
|
|
|
|
return this.save(user); |
|
|
|
} |
|
|
|
|
|
|
@ -115,6 +135,7 @@ public class AdminUserServiceImpl extends ServiceImpl<AdminUserMapper, User> imp |
|
|
|
Page<User> page = new Page<>(pageNum, pageSize); |
|
|
|
|
|
|
|
LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>(); |
|
|
|
queryWrapper.eq(User::getIsDel, 0); |
|
|
|
|
|
|
|
if (StringUtils.isNotBlank(userQueryDto.getUsername())) { |
|
|
|
queryWrapper.like(User::getUsername, userQueryDto.getUsername()); |
|
|
@ -171,7 +192,33 @@ public class AdminUserServiceImpl extends ServiceImpl<AdminUserMapper, User> imp |
|
|
|
|
|
|
|
@Override |
|
|
|
public void removeUserById(Long id) { |
|
|
|
this.removeById(id); |
|
|
|
//关联删除user_detail |
|
|
|
LambdaUpdateWrapper<UserDetail> updateWrapper = new LambdaUpdateWrapper<>(); |
|
|
|
updateWrapper.eq(UserDetail::getUserId, id).set(UserDetail::getIsDel, 1); |
|
|
|
adminUserDetailMapper.update(null, updateWrapper); |
|
|
|
|
|
|
|
|
|
|
|
//关联删除winrecord |
|
|
|
LambdaUpdateWrapper<WinnerRecord> updateWrapper1 = new LambdaUpdateWrapper<>(); |
|
|
|
updateWrapper1.eq(WinnerRecord::getUserId, id).set(WinnerRecord::getIsDel, 1); |
|
|
|
adminWinMapper.update(null, updateWrapper1); |
|
|
|
|
|
|
|
adminUserMapper.deleteUserById(id); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public boolean removeUserBatchByIds(List<Long> ids) { |
|
|
|
if (ids == null || ids.isEmpty()) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
// 使用 UpdateWrapper 批量更新 is_del 字段 |
|
|
|
LambdaUpdateWrapper<User> updateWrapper = new LambdaUpdateWrapper<>(); |
|
|
|
updateWrapper.in(User::getId, ids) // WHERE id IN (ids) |
|
|
|
.set(User::getIsDel, 1); // SET is_del = 1 |
|
|
|
|
|
|
|
// 执行更新(不更新其他字段) |
|
|
|
return this.update(updateWrapper); |
|
|
|
} |
|
|
|
|
|
|
|
private User convertToEntity(UserImportDto dto) { |
|
|
@ -181,6 +228,7 @@ public class AdminUserServiceImpl extends ServiceImpl<AdminUserMapper, User> imp |
|
|
|
user.setIsWin(0); |
|
|
|
user.setCreateTime(new Date()); |
|
|
|
user.setUpdateTime(new Date()); |
|
|
|
user.setIsDel(0); |
|
|
|
// 设置默认密码 |
|
|
|
user.setPassword("123456"); |
|
|
|
return user; |
|
|
|