新增管理后台对用户信息相关操作

This commit is contained in:
jwf1173 2020-05-12 17:56:31 +08:00
parent 6d86e349ef
commit a29fb12b8a
19 changed files with 534 additions and 2 deletions

View File

@ -1,6 +1,6 @@
package cn.iocoder.mall.order.rest.request.admin;
import cn.iocoder.mall.order.api.bo.OrderBO;
import cn.iocoder.mall.order.biz.bo.order.OrderBO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;

View File

@ -35,7 +35,7 @@ import static cn.iocoder.common.framework.vo.CommonResult.success;
*/
@RestController
@RequestMapping(MallConstants.ROOT_PATH_ADMIN + "/category")
@Api(tags = "商品分类 API")
@Api(tags = "管理员 - 商品分类 API")
public class AdminsProductCategoryController {
@Autowired

View File

@ -88,6 +88,11 @@ public enum SystemErrorCodeEnum implements ServiceExceptionUtil.Enumerable {
USER_ADDRESS_IS_DELETED(1001004001, "用户地址已被删除!"),
USER_GET_ADDRESS_NOT_EXISTS(1001004002, "获取的地址不存在!"),
// ========== 用户信息模块 1004004100 ==========
USER_NOT_EXISTS(1004004100, "用户不存在"),
USER_STATUS_NOT_EXISTS(1004004101, "用户状态不存在"),
USER_STATUS_EQUALS(1004004101, "用户已经是该状态"),
// ========== 错误码模块 1002009000 ==========
ERROR_CODE_NOT_EXISTS(1002009000, "错误码不存在"),
ERROR_CODE_DUPLICATE(1002009001, "已经存在编码为【{}}】的错误码"),

View File

@ -0,0 +1,46 @@
package cn.iocoder.mall.system.biz.enums.user;
import cn.iocoder.common.framework.core.IntArrayValuable;
import java.util.Arrays;
/**
* @Author: jiangweifan
* @Date: 2020/5/12
* @Description: 用户状态枚举
*/
public enum UserStatusEnum implements IntArrayValuable {
ENABLED(1, "启用"),
DISABLED(2, "禁用");
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(UserStatusEnum::getStatus).toArray();
/**
* 状态
*/
private final Integer status;
/**
* 描述
*/
private final String name;
UserStatusEnum(Integer status, String name) {
this.status = status;
this.name = name;
}
public Integer getStatus() {
return status;
}
public String getName() {
return name;
}
@Override
public int[] array() {
return ARRAYS;
}
}

View File

@ -18,9 +18,18 @@ public class UserBO {
* 昵称
*/
private String nickname;
/**
* 手机号
*/
private String mobile;
/**
* 头像
*/
private String avatar;
/**
* 用户状态 1 - 开启2 - 禁用
*/
private Integer status;
}

View File

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

View File

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

View File

@ -30,9 +30,18 @@ public class UserDO extends DeletableDO {
* 昵称
*/
private String nickname;
/**
* 手机
*/
private String mobile;
/**
* 头像
*/
private String avatar;
/**
* 用户状态 1 - 开启2 - 禁用
*/
private Integer status;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -0,0 +1,54 @@
package cn.iocoder.mall.system.rest.controller.admin;
import cn.iocoder.common.framework.constant.MallConstants;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.system.biz.bo.user.UserBO;
import cn.iocoder.mall.system.biz.service.user.UserService;
import cn.iocoder.mall.system.rest.convert.admin.AdminsUserConvert;
import cn.iocoder.mall.system.rest.request.admin.AdminsUserPageRequest;
import cn.iocoder.mall.system.rest.request.admin.AdminsUserUpdateRequest;
import cn.iocoder.mall.system.rest.request.admin.AdminsUserUpdateStatusRequest;
import cn.iocoder.mall.system.rest.response.admin.AdminsUserPageResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import static cn.iocoder.common.framework.vo.CommonResult.success;
/**
* @Author: jiangweifan
* @Date: 2020/5/12
* @Description: 管理员 - 用户信息
*/
@RestController
@RequestMapping(MallConstants.ROOT_PATH_ADMIN + "/user-info")
@Api(tags = "管理员 - 用户信息 API")
public class AdminsUserController {
@Autowired
private UserService userService;
@GetMapping("/page")
@ApiOperation(value = "用户分页列表")
public CommonResult<PageResult<AdminsUserPageResponse>> page(AdminsUserPageRequest adminsUserPageRequest) {
PageResult<UserBO> userPage = userService.getUserPage(AdminsUserConvert.INSTANCE.convertToPageDTO(adminsUserPageRequest));
return success(AdminsUserConvert.INSTANCE.convertToPageResponse(userPage));
}
@PostMapping("/update")
@ApiOperation(value = "更新用户基本信息")
public CommonResult<Boolean> update(AdminsUserUpdateRequest adminsUserUpdateRequest) {
return success(userService.updateUserInfo(AdminsUserConvert.INSTANCE.convertToUpdateDTO(adminsUserUpdateRequest)));
}
@PostMapping("/update_status")
@ApiOperation(value = "更新用户状态")
public CommonResult<Boolean> updateStatus(AdminsUserUpdateStatusRequest adminsUserUpdateStatusRequest) {
return success(userService.updateUserStatus(AdminsUserConvert.INSTANCE.convertToUpdateStatusDTO(adminsUserUpdateStatusRequest)));
}
}

View File

@ -0,0 +1,52 @@
package cn.iocoder.mall.system.rest.convert.admin;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.system.biz.bo.user.UserBO;
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.rest.request.admin.AdminsUserPageRequest;
import cn.iocoder.mall.system.rest.request.admin.AdminsUserUpdateRequest;
import cn.iocoder.mall.system.rest.request.admin.AdminsUserUpdateStatusRequest;
import cn.iocoder.mall.system.rest.response.admin.AdminsUserPageResponse;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
/**
* @Author: jiangweifan
* @Date: 2020/5/12
* @Description: 管理后台 - 用户数据转换
*/
@Mapper
public interface AdminsUserConvert {
AdminsUserConvert INSTANCE = Mappers.getMapper(AdminsUserConvert.class);
/**
* 分页获取用户列表 - Request转DTO
* @param adminsUserPageRequest
* @return
*/
UserPageDTO convertToPageDTO(AdminsUserPageRequest adminsUserPageRequest);
/**
* 更新用户信息 - Request转DTO
* @param adminsUserUpdateRequest
* @return
*/
UserUpdateDTO convertToUpdateDTO(AdminsUserUpdateRequest adminsUserUpdateRequest);
/**
* 更新用户状态 - Request转DTO
* @param adminsUserUpdateStatusRequest
* @return
*/
UserUpdateStatusDTO convertToUpdateStatusDTO(AdminsUserUpdateStatusRequest adminsUserUpdateStatusRequest);
/**
* 分页获取用户列表 - BO转Response
* @param userPage
* @return
*/
PageResult<AdminsUserPageResponse> convertToPageResponse(PageResult<UserBO> userPage);
}

View File

@ -0,0 +1,29 @@
package cn.iocoder.mall.system.rest.request.admin;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
/**
* @Author: jiangweifan
* @Date: 2020/5/12
* @Description: 管理员 - 用户信息 - 用户分页列表
*/
@ApiModel("用户分页列表Request")
@Data
@Accessors(chain = true)
public class AdminsUserPageRequest {
@ApiModelProperty(name = "nickname", value = "昵称,模糊匹配", example = "小王")
private String nickname;
@ApiModelProperty(name = "status", value = "状态。1 - 开启2 - 禁用", example = "0")
private Integer status;
@ApiModelProperty(name = "pageNo", value = "页码,从 1 开始", example = "1")
private Integer pageNo = 1;
@ApiModelProperty(name = "pageSize", value = "每页条数", required = true, example = "10")
private Integer pageSize = 10;
}

View File

@ -0,0 +1,29 @@
package cn.iocoder.mall.system.rest.request.admin;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotNull;
/**
* @Author: jiangweifan
* @Date: 2020/5/12
* @Description: 管理员 - 用户信息 - 更新用户信息
*/
@ApiModel("更新用户信息Request")
@Data
@Accessors(chain = true)
public class AdminsUserUpdateRequest {
@ApiModelProperty(name = "id", value = "用户编号", required = true, example = "1")
@NotNull(message = "用户编号不能为空")
private Integer id;
@ApiModelProperty(name = "nickname", value = "昵称", required = true, example = "小王")
private String nickname;
@ApiModelProperty(name = "avatar", value = "头像", required = true, example = "http://www.iocoder.cn/xxx.jpg")
private String avatar;
}

View File

@ -0,0 +1,27 @@
package cn.iocoder.mall.system.rest.request.admin;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotNull;
/**
* @Author: jiangweifan
* @Date: 2020/5/12
* @Description: 管理员 - 用户信息 - 更新用户状态
*/
@ApiModel("更新用户状态Request")
@Data
@Accessors(chain = true)
public class AdminsUserUpdateStatusRequest {
@ApiModelProperty(name = "id", value = "用户编号", required = true, example = "1")
@NotNull(message = "用户编号不能为空")
private Integer id;
@ApiModelProperty(name = "status", value = "用户状态。1 - 开启2 - 禁用", required = true, example = "1")
@NotNull(message = "用户状态不能为空")
private Integer status;
}

View File

@ -0,0 +1,32 @@
package cn.iocoder.mall.system.rest.response.admin;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
/**
* @Author: jiangweifan
* @Date: 2020/5/12
* @Description: 管理员 - 用户信息 - 用户分页列表Response
*/
@ApiModel("用户分页信息 Response")
@Data
@Accessors(chain = true)
public class AdminsUserPageResponse {
@ApiModelProperty(value = "用户编号", required = true, example = "1")
private Integer id;
@ApiModelProperty(value = "昵称", required = false, example = "1")
private String nickname;
@ApiModelProperty(value = "手机号", required = true, example = "13631780241")
private String mobile;
@ApiModelProperty(value = "头像", required = false, example = "http://www.iocoder.cn/xxx.jpg")
private String avatar;
@ApiModelProperty(value = "用户状态 1 - 开启2 - 禁用", required = true, example = "1")
private Integer status;
}