新增管理后台对用户信息相关操作
This commit is contained in:
@@ -18,9 +18,18 @@ public class UserBO {
|
||||
* 昵称
|
||||
*/
|
||||
private String nickname;
|
||||
/**
|
||||
* 手机号
|
||||
*/
|
||||
private String mobile;
|
||||
/**
|
||||
* 头像
|
||||
*/
|
||||
private String avatar;
|
||||
|
||||
/**
|
||||
* 用户状态 1 - 开启;2 - 禁用
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
package cn.iocoder.mall.system.biz.convert.user;
|
||||
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.system.biz.bo.ouath2.OAuth2AuthenticateBO;
|
||||
import cn.iocoder.mall.system.biz.bo.user.UserAuthenticateBO;
|
||||
import cn.iocoder.mall.system.biz.bo.user.UserBO;
|
||||
import cn.iocoder.mall.system.biz.dataobject.admin.AdminDO;
|
||||
import cn.iocoder.mall.system.biz.dataobject.user.UserDO;
|
||||
import cn.iocoder.mall.system.biz.dto.user.UserUpdateDTO;
|
||||
import cn.iocoder.mall.system.biz.dto.user.UserUpdateStatusDTO;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
@@ -19,4 +24,26 @@ public interface UserConvert {
|
||||
|
||||
UserBO convert(UserDO bean);
|
||||
|
||||
/**
|
||||
* 用户分页列表 - DOPage转换BO
|
||||
* @param userDOPage
|
||||
* @return
|
||||
*/
|
||||
@Mapping(source = "records", target = "list")
|
||||
PageResult<UserBO> convertToPage(IPage<UserDO> userDOPage);
|
||||
|
||||
/**
|
||||
* 更新用户信息 - DTO转换DO
|
||||
* @param userUpdateDTO
|
||||
* @return
|
||||
*/
|
||||
UserDO convertToUserDO(UserUpdateDTO userUpdateDTO);
|
||||
|
||||
/**
|
||||
* 更新用户状态 - DTO转换DO
|
||||
* @param userUpdateStatusDTO
|
||||
* @return
|
||||
*/
|
||||
UserDO convertToUserDO(UserUpdateStatusDTO userUpdateStatusDTO);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
package cn.iocoder.mall.system.biz.dao.user;
|
||||
|
||||
import cn.iocoder.mall.system.biz.dataobject.user.UserDO;
|
||||
import cn.iocoder.mall.system.biz.dto.user.UserPageDTO;
|
||||
import cn.iocoder.mall.system.biz.dto.user.UserUpdateDTO;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
@@ -14,4 +20,17 @@ public interface UserMapper extends BaseMapper<UserDO> {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据条件分页查询用户列表
|
||||
* @param userPageDTO
|
||||
* @return
|
||||
*/
|
||||
default IPage<UserDO> selectUserPage(UserPageDTO userPageDTO) {
|
||||
return this.selectPage(new Page<>(userPageDTO.getPageNo(), userPageDTO.getPageSize()),
|
||||
Wrappers.<UserDO>query().lambda()
|
||||
.eq(StringUtils.isNotBlank(userPageDTO.getNickname()), UserDO::getNickname, userPageDTO.getNickname())
|
||||
.eq(null != userPageDTO.getStatus(), UserDO::getStatus, userPageDTO.getStatus())
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,9 +30,18 @@ public class UserDO extends DeletableDO {
|
||||
* 昵称
|
||||
*/
|
||||
private String nickname;
|
||||
/**
|
||||
* 手机
|
||||
*/
|
||||
private String mobile;
|
||||
/**
|
||||
* 头像
|
||||
*/
|
||||
private String avatar;
|
||||
|
||||
/**
|
||||
* 用户状态 1 - 开启;2 - 禁用
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package cn.iocoder.mall.system.biz.dto.user;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* @Author: jiangweifan
|
||||
* @Date: 2020/5/12
|
||||
* @Description: 用户信息 - 用户分页列表DTO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class UserPageDTO {
|
||||
|
||||
/**
|
||||
* 昵称,模糊匹配
|
||||
*/
|
||||
private String nickname;
|
||||
|
||||
/**
|
||||
* 状态。1 - 开启;2 - 禁用
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 页码,从 1 开始
|
||||
*/
|
||||
@NotNull(message = "页码不能为空")
|
||||
private Integer pageNo;
|
||||
|
||||
/**
|
||||
* 每页条数
|
||||
*/
|
||||
@NotNull(message = "每页条数不能为空")
|
||||
private Integer pageSize;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package cn.iocoder.mall.system.biz.dto.user;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* @Author: jiangweifan
|
||||
* @Date: 2020/5/12
|
||||
* @Description: 用户信息 - 更新用户信息DTO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class UserUpdateDTO {
|
||||
|
||||
/**
|
||||
* 用户编号
|
||||
*/
|
||||
@NotNull(message = "用户编号不能为空")
|
||||
private Integer id;
|
||||
|
||||
/**
|
||||
* 昵称
|
||||
*/
|
||||
private String nickname;
|
||||
|
||||
/**
|
||||
* 头像
|
||||
*/
|
||||
private String avatar;
|
||||
|
||||
/**
|
||||
* 用户状态,1 - 启用;2 - 禁用
|
||||
*/
|
||||
private Integer status;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package cn.iocoder.mall.system.biz.dto.user;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* @Author: jiangweifan
|
||||
* @Date: 2020/5/12
|
||||
* @Description: 用户信息 - 更新用户状态DTO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class UserUpdateStatusDTO {
|
||||
|
||||
/**
|
||||
* 用户编号
|
||||
*/
|
||||
@NotNull(message = "用户编号不能为空")
|
||||
private Integer id;
|
||||
|
||||
/**
|
||||
* 用户状态,1 - 启用;2 - 禁用
|
||||
*/
|
||||
@NotNull(message = "用户状态不能为空")
|
||||
private Integer status;
|
||||
}
|
||||
@@ -1,8 +1,12 @@
|
||||
package cn.iocoder.mall.system.biz.service.user;
|
||||
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.system.biz.bo.user.UserAuthenticateBO;
|
||||
import cn.iocoder.mall.system.biz.bo.user.UserBO;
|
||||
import cn.iocoder.mall.system.biz.dto.oatuh2.OAuth2MobileCodeAuthenticateDTO;
|
||||
import cn.iocoder.mall.system.biz.dto.user.UserPageDTO;
|
||||
import cn.iocoder.mall.system.biz.dto.user.UserUpdateDTO;
|
||||
import cn.iocoder.mall.system.biz.dto.user.UserUpdateStatusDTO;
|
||||
|
||||
/**
|
||||
* 用户 Service 接口
|
||||
@@ -13,4 +17,25 @@ public interface UserService {
|
||||
|
||||
UserBO getUserByAccountId(Integer accountId);
|
||||
|
||||
/**
|
||||
* 根据条件分页获取用户列表
|
||||
* @param userPageDTO
|
||||
* @return
|
||||
*/
|
||||
PageResult<UserBO> getUserPage(UserPageDTO userPageDTO);
|
||||
|
||||
/**
|
||||
* 更新用户信息
|
||||
* @param userUpdateDTO
|
||||
* @return
|
||||
*/
|
||||
Boolean updateUserInfo(UserUpdateDTO userUpdateDTO);
|
||||
|
||||
/**
|
||||
* 更新用户状态
|
||||
* @param userUpdateStatusDTO
|
||||
* @return
|
||||
*/
|
||||
Boolean updateUserStatus(UserUpdateStatusDTO userUpdateStatusDTO);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package cn.iocoder.mall.system.biz.service.user;
|
||||
|
||||
import cn.iocoder.common.framework.util.ServiceExceptionUtil;
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.mybatis.enums.DeletedStatusEnum;
|
||||
import cn.iocoder.mall.system.biz.bo.ouath2.OAuth2AuthenticateBO;
|
||||
import cn.iocoder.mall.system.biz.bo.user.UserAuthenticateBO;
|
||||
@@ -8,10 +10,16 @@ import cn.iocoder.mall.system.biz.convert.user.UserConvert;
|
||||
import cn.iocoder.mall.system.biz.dao.user.UserMapper;
|
||||
import cn.iocoder.mall.system.biz.dataobject.user.UserDO;
|
||||
import cn.iocoder.mall.system.biz.dto.oatuh2.OAuth2MobileCodeAuthenticateDTO;
|
||||
import cn.iocoder.mall.system.biz.dto.user.UserPageDTO;
|
||||
import cn.iocoder.mall.system.biz.dto.user.UserUpdateDTO;
|
||||
import cn.iocoder.mall.system.biz.dto.user.UserUpdateStatusDTO;
|
||||
import cn.iocoder.mall.system.biz.enums.user.UserStatusEnum;
|
||||
import cn.iocoder.mall.system.biz.service.oauth2.OAuth2Service;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import java.util.Arrays;
|
||||
import static cn.iocoder.mall.system.biz.enums.SystemErrorCodeEnum.*;
|
||||
|
||||
@Service
|
||||
public class UserServiceImpl implements UserService {
|
||||
@@ -43,6 +51,64 @@ public class UserServiceImpl implements UserService {
|
||||
return UserConvert.INSTANCE.convert(userDO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据条件分页获取用户列表
|
||||
* @param userPageDTO
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public PageResult<UserBO> getUserPage(UserPageDTO userPageDTO) {
|
||||
return UserConvert.INSTANCE.convertToPage(userMapper.selectUserPage(userPageDTO));
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新用户信息
|
||||
* @param userUpdateDTO
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Boolean updateUserInfo(UserUpdateDTO userUpdateDTO) {
|
||||
// 查询用户是否存在
|
||||
UserDO userDO = userMapper.selectById(userUpdateDTO.getId());
|
||||
if (null == userDO) {
|
||||
throw ServiceExceptionUtil.exception(USER_NOT_EXISTS);
|
||||
}
|
||||
// 更新用户信息
|
||||
UserDO updateDO = UserConvert.INSTANCE.convertToUserDO(userUpdateDTO);
|
||||
userMapper.updateById(updateDO);
|
||||
// TODO 伟帆 操作日志
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 更新用户状态
|
||||
* @param userUpdateStatusDTO
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Boolean updateUserStatus(UserUpdateStatusDTO userUpdateStatusDTO) {
|
||||
// 查询用户是否存在
|
||||
UserDO userDO = userMapper.selectById(userUpdateStatusDTO.getId());
|
||||
if (null == userDO) {
|
||||
throw ServiceExceptionUtil.exception(USER_NOT_EXISTS);
|
||||
}
|
||||
// 判断更新状态是否存在
|
||||
if (null != userUpdateStatusDTO.getStatus() &&
|
||||
Arrays.stream(UserStatusEnum.ARRAYS).noneMatch(status -> status == userUpdateStatusDTO.getStatus())) {
|
||||
throw ServiceExceptionUtil.exception(USER_STATUS_NOT_EXISTS);
|
||||
}
|
||||
// 如果状态相同,则返回错误
|
||||
if (null != userUpdateStatusDTO.getStatus() && userUpdateStatusDTO.getStatus().equals(userDO.getStatus())) {
|
||||
throw ServiceExceptionUtil.exception(USER_STATUS_EQUALS);
|
||||
}
|
||||
// 更新用户信息
|
||||
UserDO updateStatusDO = UserConvert.INSTANCE.convertToUserDO(userUpdateStatusDTO);
|
||||
userMapper.updateById(updateStatusDO);
|
||||
// TODO 伟帆 操作日志
|
||||
return true;
|
||||
}
|
||||
|
||||
private UserDO creatUser(Integer accountId) {
|
||||
UserDO user = new UserDO();
|
||||
user.setAccountId(accountId);
|
||||
|
||||
Reference in New Issue
Block a user