后台管理页面用户管理新增用户问题修复
This commit is contained in:
@@ -56,4 +56,9 @@ public class UserDTO {
|
||||
* 关联VIP信息表主键(0表示非VIP)
|
||||
*/
|
||||
private Long vipId;
|
||||
|
||||
/**
|
||||
* 手机号
|
||||
*/
|
||||
private String phone;
|
||||
}
|
||||
|
||||
+36
-4
@@ -43,11 +43,21 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
|
||||
@Override
|
||||
public Long createUser(UserDTO userDTO) {
|
||||
UserDO existingUser = userMapper.selectOne(
|
||||
Wrappers.lambdaQuery(UserDO.class)
|
||||
.eq(UserDO::getAccount, userDTO.getAccount())
|
||||
.eq(UserDO::getIsDelete, 0)
|
||||
);
|
||||
if (existingUser != null) {
|
||||
throw new RuntimeException("账号已存在");
|
||||
}
|
||||
|
||||
UserDO userDO = new UserDO();
|
||||
userDO.setShopId(userDTO.getShopId());
|
||||
userDO.setNickname(userDTO.getNickname());
|
||||
userDO.setAccount(userDTO.getAccount());
|
||||
userDO.setPassword(userDTO.getPassword());
|
||||
userDO.setPhone(userDTO.getPhone());
|
||||
userDO.setSignature(userDTO.getSignature());
|
||||
userDO.setLevel(userDTO.getLevel());
|
||||
userDO.setType(userDTO.getType());
|
||||
@@ -56,7 +66,16 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
userDO.setStatus(1);
|
||||
String defaultAvatar = "https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png";
|
||||
userDO.setAvatar(defaultAvatar);
|
||||
userMapper.insert(userDO);
|
||||
|
||||
try {
|
||||
userMapper.insert(userDO);
|
||||
} catch (Exception e) {
|
||||
if (e.getMessage() != null && e.getMessage().contains("Duplicate entry")) {
|
||||
throw new RuntimeException("账号已存在");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
|
||||
return userDO.getId();
|
||||
}
|
||||
|
||||
@@ -66,18 +85,31 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
if (userDO == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (userDTO.getAccount() != null && !userDTO.getAccount().equals(userDO.getAccount())) {
|
||||
UserDO existingUser = userMapper.selectOne(
|
||||
Wrappers.lambdaQuery(UserDO.class)
|
||||
.eq(UserDO::getAccount, userDTO.getAccount())
|
||||
.eq(UserDO::getIsDelete, 0)
|
||||
);
|
||||
if (existingUser != null) {
|
||||
throw new RuntimeException("账号已存在");
|
||||
}
|
||||
userDO.setAccount(userDTO.getAccount());
|
||||
}
|
||||
|
||||
if (userDTO.getShopId() != null) {
|
||||
userDO.setShopId(userDTO.getShopId());
|
||||
}
|
||||
if (userDTO.getNickname() != null) {
|
||||
userDO.setNickname(userDTO.getNickname());
|
||||
}
|
||||
if (userDTO.getAccount() != null) {
|
||||
userDO.setAccount(userDTO.getAccount());
|
||||
}
|
||||
if (userDTO.getPassword() != null) {
|
||||
userDO.setPassword(userDTO.getPassword());
|
||||
}
|
||||
if (userDTO.getPhone() != null) {
|
||||
userDO.setPhone(userDTO.getPhone());
|
||||
}
|
||||
if (userDTO.getAvatar() != null) {
|
||||
if (userDTO.getAvatar().isEmpty()) {
|
||||
userDO.setAvatar(null);
|
||||
|
||||
Reference in New Issue
Block a user