From a29fb12b8a4e5fc1ed6122bba6b3d61f3337e339 Mon Sep 17 00:00:00 2001 From: jwf1173 <1553713823@qq.com> Date: Tue, 12 May 2020 17:56:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=AE=A1=E7=90=86=E5=90=8E?= =?UTF-8?q?=E5=8F=B0=E5=AF=B9=E7=94=A8=E6=88=B7=E4=BF=A1=E6=81=AF=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rest/request/admin/OrderPageRequest.java | 2 +- .../AdminsProductCategoryController.java | 2 +- .../system/biz/enums/SystemErrorCodeEnum.java | 5 ++ .../system/biz/enums/user/UserStatusEnum.java | 46 +++++++++++++ .../mall/system/biz/bo/user/UserBO.java | 9 +++ .../system/biz/convert/user/UserConvert.java | 27 ++++++++ .../mall/system/biz/dao/user/UserMapper.java | 19 ++++++ .../system/biz/dataobject/user/UserDO.java | 9 +++ .../mall/system/biz/dto/user/UserPageDTO.java | 38 +++++++++++ .../system/biz/dto/user/UserUpdateDTO.java | 37 +++++++++++ .../biz/dto/user/UserUpdateStatusDTO.java | 28 ++++++++ .../system/biz/service/user/UserService.java | 25 +++++++ .../biz/service/user/UserServiceImpl.java | 66 +++++++++++++++++++ .../admin/AdminsUserController.java | 54 +++++++++++++++ .../rest/convert/admin/AdminsUserConvert.java | 52 +++++++++++++++ .../request/admin/AdminsUserPageRequest.java | 29 ++++++++ .../admin/AdminsUserUpdateRequest.java | 29 ++++++++ .../admin/AdminsUserUpdateStatusRequest.java | 27 ++++++++ .../admin/AdminsUserPageResponse.java | 32 +++++++++ 19 files changed, 534 insertions(+), 2 deletions(-) create mode 100644 system/system-biz-api/src/main/java/cn/iocoder/mall/system/biz/enums/user/UserStatusEnum.java create mode 100644 system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/user/UserPageDTO.java create mode 100644 system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/user/UserUpdateDTO.java create mode 100644 system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/user/UserUpdateStatusDTO.java create mode 100644 system/system-rest/src/main/java/cn/iocoder/mall/system/rest/controller/admin/AdminsUserController.java create mode 100644 system/system-rest/src/main/java/cn/iocoder/mall/system/rest/convert/admin/AdminsUserConvert.java create mode 100644 system/system-rest/src/main/java/cn/iocoder/mall/system/rest/request/admin/AdminsUserPageRequest.java create mode 100644 system/system-rest/src/main/java/cn/iocoder/mall/system/rest/request/admin/AdminsUserUpdateRequest.java create mode 100644 system/system-rest/src/main/java/cn/iocoder/mall/system/rest/request/admin/AdminsUserUpdateStatusRequest.java create mode 100644 system/system-rest/src/main/java/cn/iocoder/mall/system/rest/response/admin/AdminsUserPageResponse.java diff --git a/order/order-rest/src/main/java/cn/iocoder/mall/order/rest/request/admin/OrderPageRequest.java b/order/order-rest/src/main/java/cn/iocoder/mall/order/rest/request/admin/OrderPageRequest.java index 8200e491d..580029ec1 100644 --- a/order/order-rest/src/main/java/cn/iocoder/mall/order/rest/request/admin/OrderPageRequest.java +++ b/order/order-rest/src/main/java/cn/iocoder/mall/order/rest/request/admin/OrderPageRequest.java @@ -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; diff --git a/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/controller/category/AdminsProductCategoryController.java b/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/controller/category/AdminsProductCategoryController.java index 19785ae26..96d548d7f 100644 --- a/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/controller/category/AdminsProductCategoryController.java +++ b/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/controller/category/AdminsProductCategoryController.java @@ -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 diff --git a/system/system-biz-api/src/main/java/cn/iocoder/mall/system/biz/enums/SystemErrorCodeEnum.java b/system/system-biz-api/src/main/java/cn/iocoder/mall/system/biz/enums/SystemErrorCodeEnum.java index 7dbe84910..eb632381f 100644 --- a/system/system-biz-api/src/main/java/cn/iocoder/mall/system/biz/enums/SystemErrorCodeEnum.java +++ b/system/system-biz-api/src/main/java/cn/iocoder/mall/system/biz/enums/SystemErrorCodeEnum.java @@ -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, "已经存在编码为【{}}】的错误码"), diff --git a/system/system-biz-api/src/main/java/cn/iocoder/mall/system/biz/enums/user/UserStatusEnum.java b/system/system-biz-api/src/main/java/cn/iocoder/mall/system/biz/enums/user/UserStatusEnum.java new file mode 100644 index 000000000..f303e30b9 --- /dev/null +++ b/system/system-biz-api/src/main/java/cn/iocoder/mall/system/biz/enums/user/UserStatusEnum.java @@ -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; + } + +} diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/bo/user/UserBO.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/bo/user/UserBO.java index 409829ffd..e1238b17d 100644 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/bo/user/UserBO.java +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/bo/user/UserBO.java @@ -18,9 +18,18 @@ public class UserBO { * 昵称 */ private String nickname; + /** + * 手机号 + */ + private String mobile; /** * 头像 */ private String avatar; + /** + * 用户状态 1 - 开启;2 - 禁用 + */ + private Integer status; + } diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/convert/user/UserConvert.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/convert/user/UserConvert.java index 64284a935..b5bcb06ef 100644 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/convert/user/UserConvert.java +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/convert/user/UserConvert.java @@ -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 convertToPage(IPage userDOPage); + + /** + * 更新用户信息 - DTO转换DO + * @param userUpdateDTO + * @return + */ + UserDO convertToUserDO(UserUpdateDTO userUpdateDTO); + + /** + * 更新用户状态 - DTO转换DO + * @param userUpdateStatusDTO + * @return + */ + UserDO convertToUserDO(UserUpdateStatusDTO userUpdateStatusDTO); + } diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dao/user/UserMapper.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dao/user/UserMapper.java index 78a7b6903..90e571d45 100644 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dao/user/UserMapper.java +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dao/user/UserMapper.java @@ -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 { ); } + /** + * 根据条件分页查询用户列表 + * @param userPageDTO + * @return + */ + default IPage selectUserPage(UserPageDTO userPageDTO) { + return this.selectPage(new Page<>(userPageDTO.getPageNo(), userPageDTO.getPageSize()), + Wrappers.query().lambda() + .eq(StringUtils.isNotBlank(userPageDTO.getNickname()), UserDO::getNickname, userPageDTO.getNickname()) + .eq(null != userPageDTO.getStatus(), UserDO::getStatus, userPageDTO.getStatus()) + ); + } + } diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dataobject/user/UserDO.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dataobject/user/UserDO.java index 9dcfdaba2..cef5ff5c8 100644 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dataobject/user/UserDO.java +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dataobject/user/UserDO.java @@ -30,9 +30,18 @@ public class UserDO extends DeletableDO { * 昵称 */ private String nickname; + /** + * 手机 + */ + private String mobile; /** * 头像 */ private String avatar; + /** + * 用户状态 1 - 开启;2 - 禁用 + */ + private Integer status; + } diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/user/UserPageDTO.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/user/UserPageDTO.java new file mode 100644 index 000000000..65f23336b --- /dev/null +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/user/UserPageDTO.java @@ -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; +} diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/user/UserUpdateDTO.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/user/UserUpdateDTO.java new file mode 100644 index 000000000..c2216e8a8 --- /dev/null +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/user/UserUpdateDTO.java @@ -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; +} diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/user/UserUpdateStatusDTO.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/user/UserUpdateStatusDTO.java new file mode 100644 index 000000000..8ee05e0b0 --- /dev/null +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/user/UserUpdateStatusDTO.java @@ -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; +} diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/user/UserService.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/user/UserService.java index e399f14b4..aefeeff25 100644 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/user/UserService.java +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/user/UserService.java @@ -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 getUserPage(UserPageDTO userPageDTO); + + /** + * 更新用户信息 + * @param userUpdateDTO + * @return + */ + Boolean updateUserInfo(UserUpdateDTO userUpdateDTO); + + /** + * 更新用户状态 + * @param userUpdateStatusDTO + * @return + */ + Boolean updateUserStatus(UserUpdateStatusDTO userUpdateStatusDTO); + } diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/user/UserServiceImpl.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/user/UserServiceImpl.java index 080f21d8a..a5c816924 100644 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/user/UserServiceImpl.java +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/user/UserServiceImpl.java @@ -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 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); diff --git a/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/controller/admin/AdminsUserController.java b/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/controller/admin/AdminsUserController.java new file mode 100644 index 000000000..627dd35a9 --- /dev/null +++ b/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/controller/admin/AdminsUserController.java @@ -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> page(AdminsUserPageRequest adminsUserPageRequest) { + PageResult userPage = userService.getUserPage(AdminsUserConvert.INSTANCE.convertToPageDTO(adminsUserPageRequest)); + return success(AdminsUserConvert.INSTANCE.convertToPageResponse(userPage)); + } + + @PostMapping("/update") + @ApiOperation(value = "更新用户基本信息") + public CommonResult update(AdminsUserUpdateRequest adminsUserUpdateRequest) { + return success(userService.updateUserInfo(AdminsUserConvert.INSTANCE.convertToUpdateDTO(adminsUserUpdateRequest))); + } + + @PostMapping("/update_status") + @ApiOperation(value = "更新用户状态") + public CommonResult updateStatus(AdminsUserUpdateStatusRequest adminsUserUpdateStatusRequest) { + return success(userService.updateUserStatus(AdminsUserConvert.INSTANCE.convertToUpdateStatusDTO(adminsUserUpdateStatusRequest))); + } +} diff --git a/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/convert/admin/AdminsUserConvert.java b/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/convert/admin/AdminsUserConvert.java new file mode 100644 index 000000000..5dede640f --- /dev/null +++ b/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/convert/admin/AdminsUserConvert.java @@ -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 convertToPageResponse(PageResult userPage); +} diff --git a/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/request/admin/AdminsUserPageRequest.java b/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/request/admin/AdminsUserPageRequest.java new file mode 100644 index 000000000..7f99f4bf9 --- /dev/null +++ b/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/request/admin/AdminsUserPageRequest.java @@ -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; +} diff --git a/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/request/admin/AdminsUserUpdateRequest.java b/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/request/admin/AdminsUserUpdateRequest.java new file mode 100644 index 000000000..da63719e2 --- /dev/null +++ b/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/request/admin/AdminsUserUpdateRequest.java @@ -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; +} diff --git a/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/request/admin/AdminsUserUpdateStatusRequest.java b/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/request/admin/AdminsUserUpdateStatusRequest.java new file mode 100644 index 000000000..e6b31a495 --- /dev/null +++ b/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/request/admin/AdminsUserUpdateStatusRequest.java @@ -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; +} diff --git a/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/response/admin/AdminsUserPageResponse.java b/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/response/admin/AdminsUserPageResponse.java new file mode 100644 index 000000000..2e16e19ac --- /dev/null +++ b/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/response/admin/AdminsUserPageResponse.java @@ -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; +}