diff --git a/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/AdminController.java b/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/AdminController.java index 2d0340d42..3a3aec8a9 100644 --- a/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/AdminController.java +++ b/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/AdminController.java @@ -1,19 +1,25 @@ package cn.iocoder.mall.admin.application.controller; import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.mall.admin.api.AdminService; import cn.iocoder.mall.admin.api.ResourceService; +import cn.iocoder.mall.admin.api.bo.AdminPageBO; import cn.iocoder.mall.admin.api.bo.ResourceBO; import cn.iocoder.mall.admin.api.constant.ResourceConstants; +import cn.iocoder.mall.admin.api.dto.AdminPageDTO; +import cn.iocoder.mall.admin.application.convert.AdminConvert; import cn.iocoder.mall.admin.application.convert.ResourceConvert; import cn.iocoder.mall.admin.application.vo.AdminMenuTreeNodeVO; +import cn.iocoder.mall.admin.application.vo.AdminPageVO; import cn.iocoder.mall.admin.sdk.context.AdminSecurityContextHolder; -import cn.iocoder.mall.admin.application.convert.AdminConvert; -import cn.iocoder.mall.admin.application.vo.AdminInfoVO; import com.alibaba.dubbo.config.annotation.Reference; import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import java.util.*; @@ -26,11 +32,8 @@ public class AdminController { @Reference(validation = "true") private ResourceService resourceService; - - @GetMapping("/info") - public CommonResult info() { - return CommonResult.success(AdminConvert.INSTANCE.convert(AdminSecurityContextHolder.getContext())); - } + @Reference(validation = "true") + private AdminService adminService; // =========== 当前管理员相关的资源 API =========== @@ -69,4 +72,20 @@ public class AdminController { return CommonResult.success(resources.stream().map(ResourceBO::getHandler).collect(Collectors.toSet())); } + // =========== 管理员管理 API =========== + + @GetMapping("/page") + @ApiOperation(value = "管理员分页") + @ApiImplicitParams({ + @ApiImplicitParam(name = "nickname", value = "昵称,模糊匹配", required = true, example = "小王"), + @ApiImplicitParam(name = "pageNo", value = "页码,从 0 开始", example = "0"), + @ApiImplicitParam(name = "pageSize", value = "每页条数", required = true, example = "10"), + }) + public CommonResult page(@RequestParam(value = "nickname", required = false) String nickname, + @RequestParam(value = "pageNo", defaultValue = "0") Integer pageNo, + @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) { + CommonResult result = adminService.getAdminPage(new AdminPageDTO().setNickname(nickname).setPageNo(pageNo).setPageSize(pageSize)); + return AdminConvert.INSTANCE.convert(result); + } + } \ No newline at end of file diff --git a/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/PassportController.java b/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/PassportController.java index dcb15a6f0..8d005c025 100644 --- a/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/PassportController.java +++ b/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/PassportController.java @@ -3,17 +3,17 @@ package cn.iocoder.mall.admin.application.controller; import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.mall.admin.api.OAuth2Service; import cn.iocoder.mall.admin.api.bo.OAuth2AccessTokenBO; +import cn.iocoder.mall.admin.application.convert.AdminConvert; import cn.iocoder.mall.admin.application.convert.PassportConvert; +import cn.iocoder.mall.admin.application.vo.AdminInfoVO; import cn.iocoder.mall.admin.application.vo.PassportLoginVO; +import cn.iocoder.mall.admin.sdk.context.AdminSecurityContextHolder; import com.alibaba.dubbo.config.annotation.Reference; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; @RestController @RequestMapping("admin/passport") @@ -35,4 +35,10 @@ public class PassportController { return PassportConvert.INSTANCE.convert(result); } + // TODO 艿艿:后续继续完善 + @GetMapping("/info") + public CommonResult info() { + return CommonResult.success(AdminConvert.INSTANCE.convert(AdminSecurityContextHolder.getContext())); + } + } \ No newline at end of file diff --git a/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/ResourceController.java b/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/ResourceController.java index 68f2c1485..48adab9b6 100644 --- a/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/ResourceController.java +++ b/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/ResourceController.java @@ -31,8 +31,6 @@ public class ResourceController { @Reference(validation = "true") private ResourceService resourceService; - // =========== 资源管理 API =========== - @SuppressWarnings("Duplicates") @GetMapping("/tree") @ApiOperation(value = "获得所有资源,按照树形结构返回") diff --git a/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/RoleController.java b/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/RoleController.java index d2faa0c9b..5f1659aa2 100644 --- a/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/RoleController.java +++ b/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/RoleController.java @@ -35,6 +35,11 @@ public class RoleController { @GetMapping("/page") @ApiOperation(value = "角色分页") + @ApiImplicitParams({ + @ApiImplicitParam(name = "name", value = "角色名,模糊匹配", required = true, example = "系统管理员"), + @ApiImplicitParam(name = "pageNo", value = "页码,从 0 开始", example = "0"), + @ApiImplicitParam(name = "pageSize", value = "每页条数", required = true, example = "10"), + }) public CommonResult page(@RequestParam(value = "name", required = false) String name, @RequestParam(value = "pageNo", defaultValue = "0") Integer pageNo, @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) { diff --git a/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/convert/AdminConvert.java b/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/convert/AdminConvert.java index a97eb25ae..8ef6b6846 100644 --- a/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/convert/AdminConvert.java +++ b/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/convert/AdminConvert.java @@ -1,7 +1,12 @@ package cn.iocoder.mall.admin.application.convert; -import cn.iocoder.mall.admin.sdk.context.AdminSecurityContext; +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.mall.admin.api.bo.AdminBO; +import cn.iocoder.mall.admin.api.bo.AdminPageBO; import cn.iocoder.mall.admin.application.vo.AdminInfoVO; +import cn.iocoder.mall.admin.application.vo.AdminPageVO; +import cn.iocoder.mall.admin.application.vo.AdminVO; +import cn.iocoder.mall.admin.sdk.context.AdminSecurityContext; import org.mapstruct.Mapper; import org.mapstruct.Mappings; import org.mapstruct.factory.Mappers; @@ -14,4 +19,10 @@ public interface AdminConvert { @Mappings({}) AdminInfoVO convert(AdminSecurityContext adminSecurityContext); + @Mappings({}) + AdminVO convert(AdminBO adminBO); + + @Mappings({}) + CommonResult convert(CommonResult result); + } \ No newline at end of file diff --git a/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/vo/AdminPageVO.java b/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/vo/AdminPageVO.java new file mode 100644 index 000000000..fb91dbc2e --- /dev/null +++ b/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/vo/AdminPageVO.java @@ -0,0 +1,34 @@ +package cn.iocoder.mall.admin.application.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import java.util.List; + +@ApiModel("管理员分页 VO") +public class AdminPageVO { + + @ApiModelProperty(value = "管理员数组") + private List admins; + @ApiModelProperty(value = "管理员总数") + private Integer count; + + public List getAdmins() { + return admins; + } + + public AdminPageVO setAdmins(List admins) { + this.admins = admins; + return this; + } + + public Integer getCount() { + return count; + } + + public AdminPageVO setCount(Integer count) { + this.count = count; + return this; + } + +} \ No newline at end of file diff --git a/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/vo/AdminVO.java b/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/vo/AdminVO.java new file mode 100644 index 000000000..a82a69fae --- /dev/null +++ b/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/vo/AdminVO.java @@ -0,0 +1,67 @@ +package cn.iocoder.mall.admin.application.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import java.util.Date; + +@ApiModel("管理员 VO") +public class AdminVO { + + @ApiModelProperty(value = "管理员编号", required = true, example = "1") + private Integer id; + @ApiModelProperty(value = "登陆账号", required = true, example = "15601691300") + private String username; + @ApiModelProperty(value = "昵称", required = true, example = "小王") + private String nickname; + @ApiModelProperty(value = "账号状态", required = true, example = "1") + private Integer status; + @ApiModelProperty(value = "创建时间", required = true, example = "时间戳格式") + private Date createTime; + + public Integer getId() { + return id; + } + + public AdminVO setId(Integer id) { + this.id = id; + return this; + } + + public String getUsername() { + return username; + } + + public AdminVO setUsername(String username) { + this.username = username; + return this; + } + + public String getNickname() { + return nickname; + } + + public AdminVO setNickname(String nickname) { + this.nickname = nickname; + return this; + } + + public Integer getStatus() { + return status; + } + + public AdminVO setStatus(Integer status) { + this.status = status; + return this; + } + + public Date getCreateTime() { + return createTime; + } + + public AdminVO setCreateTime(Date createTime) { + this.createTime = createTime; + return this; + } + +} \ No newline at end of file diff --git a/admin/admin-service-api/src/main/java/cn/iocoder/mall/admin/api/AdminService.java b/admin/admin-service-api/src/main/java/cn/iocoder/mall/admin/api/AdminService.java index 36079c724..b21ad76cc 100644 --- a/admin/admin-service-api/src/main/java/cn/iocoder/mall/admin/api/AdminService.java +++ b/admin/admin-service-api/src/main/java/cn/iocoder/mall/admin/api/AdminService.java @@ -1,16 +1,11 @@ package cn.iocoder.mall.admin.api; +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.mall.admin.api.bo.AdminPageBO; +import cn.iocoder.mall.admin.api.dto.AdminPageDTO; + public interface AdminService { -// /** -// * 创建用户。一般在用户注册时,调用该方法 -// * -// * TODO 芋艿,此处要传递一些用户注册时的相关信息,例如说 ip、ua、客户端来源等等。用于数据分析、风控等等。 -// * -// * @param mobile 手机号 -// * @param code 手机验证码 -// * @return 用户 -// */ -// UserBO createUser(String mobile, String code) throws ServiceException; + CommonResult getAdminPage(AdminPageDTO adminPageDTO); } \ No newline at end of file diff --git a/admin/admin-service-api/src/main/java/cn/iocoder/mall/admin/api/OAuth2Service.java b/admin/admin-service-api/src/main/java/cn/iocoder/mall/admin/api/OAuth2Service.java index cb62661dc..1be3644da 100644 --- a/admin/admin-service-api/src/main/java/cn/iocoder/mall/admin/api/OAuth2Service.java +++ b/admin/admin-service-api/src/main/java/cn/iocoder/mall/admin/api/OAuth2Service.java @@ -19,7 +19,7 @@ public interface OAuth2Service { CommonResult checkToken(String accessToken); /** - * TODO 校验权限 + * 校验权限(鉴权) * * @param adminId 管理员编号 * @param roleIds 管理员拥有的角色编号的集合 diff --git a/admin/admin-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/AdminBO.java b/admin/admin-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/AdminBO.java new file mode 100644 index 000000000..f983c8050 --- /dev/null +++ b/admin/admin-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/AdminBO.java @@ -0,0 +1,72 @@ +package cn.iocoder.mall.admin.api.bo; + +import java.util.Date; + +public class AdminBO { + + /** + * 管理员编号 + */ + private Integer id; + /** + * 登陆账号 + */ + private String username; + /** + * 昵称 + */ + private String nickname; + /** + * 账号状态 + */ + private Integer status; + /** + * 创建时间 + */ + private Date createTime; + + public Integer getId() { + return id; + } + + public AdminBO setId(Integer id) { + this.id = id; + return this; + } + + public String getUsername() { + return username; + } + + public AdminBO setUsername(String username) { + this.username = username; + return this; + } + + public String getNickname() { + return nickname; + } + + public AdminBO setNickname(String nickname) { + this.nickname = nickname; + return this; + } + + public Integer getStatus() { + return status; + } + + public AdminBO setStatus(Integer status) { + this.status = status; + return this; + } + + public Date getCreateTime() { + return createTime; + } + + public AdminBO setCreateTime(Date createTime) { + this.createTime = createTime; + return this; + } +} diff --git a/admin/admin-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/AdminPageBO.java b/admin/admin-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/AdminPageBO.java new file mode 100644 index 000000000..cf88ed1c9 --- /dev/null +++ b/admin/admin-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/AdminPageBO.java @@ -0,0 +1,34 @@ +package cn.iocoder.mall.admin.api.bo; + +import java.util.List; + +public class AdminPageBO { + + /** + * 管理员数组 + */ + private List admins; + /** + * 总量 + */ + private Integer count; + + public List getAdmins() { + return admins; + } + + public AdminPageBO setAdmins(List admins) { + this.admins = admins; + return this; + } + + public Integer getCount() { + return count; + } + + public AdminPageBO setCount(Integer count) { + this.count = count; + return this; + } + +} \ No newline at end of file diff --git a/admin/admin-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/AdminPageDTO.java b/admin/admin-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/AdminPageDTO.java new file mode 100644 index 000000000..959a3babe --- /dev/null +++ b/admin/admin-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/AdminPageDTO.java @@ -0,0 +1,37 @@ +package cn.iocoder.mall.admin.api.dto; + +public class AdminPageDTO { + + private String nickname; + + private Integer pageNo; + private Integer pageSize; + + public Integer getPageNo() { + return pageNo; + } + + public AdminPageDTO setPageNo(Integer pageNo) { + this.pageNo = pageNo; + return this; + } + + public Integer getPageSize() { + return pageSize; + } + + public AdminPageDTO setPageSize(Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + public String getNickname() { + return nickname; + } + + public AdminPageDTO setNickname(String nickname) { + this.nickname = nickname; + return this; + } + +} diff --git a/admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/convert/AdminConvert.java b/admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/convert/AdminConvert.java new file mode 100644 index 000000000..0cae43c6f --- /dev/null +++ b/admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/convert/AdminConvert.java @@ -0,0 +1,22 @@ +package cn.iocoder.mall.admin.convert; + +import cn.iocoder.mall.admin.api.bo.AdminBO; +import cn.iocoder.mall.admin.dataobject.AdminDO; +import org.mapstruct.Mapper; +import org.mapstruct.Mappings; +import org.mapstruct.factory.Mappers; + +import java.util.List; + +@Mapper +public interface AdminConvert { + + AdminConvert INSTANCE = Mappers.getMapper(AdminConvert.class); + + @Mappings({}) + AdminBO convert(AdminDO adminDO); + + @Mappings({}) + List convert(List adminBOs); + +} \ No newline at end of file diff --git a/admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/dao/AdminMapper.java b/admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/dao/AdminMapper.java index d27e96b02..c5cf5e410 100644 --- a/admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/dao/AdminMapper.java +++ b/admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/dao/AdminMapper.java @@ -4,9 +4,17 @@ import cn.iocoder.mall.admin.dataobject.AdminDO; import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Repository; +import java.util.List; + @Repository public interface AdminMapper { AdminDO selectByUsername(@Param("username") String username); + List selectListByNicknameLike(@Param("nickname") String nickname, + @Param("offset") Integer offset, + @Param("limit") Integer limit); + + Integer selectCountByNicknameLike(@Param("nickname") String nickname); + } \ No newline at end of file diff --git a/admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/AdminDO.java b/admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/AdminDO.java index 1874a0ea6..2ef36bbcb 100644 --- a/admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/AdminDO.java +++ b/admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/AdminDO.java @@ -1,11 +1,11 @@ package cn.iocoder.mall.admin.dataobject; -import java.util.Date; +import cn.iocoder.common.framework.dataobject.BaseDO; /** * 管理员实体 */ -public class AdminDO { +public class AdminDO extends BaseDO { /** * 账号状态 - 开启 @@ -34,10 +34,6 @@ public class AdminDO { * TODO 芋艿 暂时最简单的 MD5 */ private String password; - /** - * 创建时间 - */ - private Date createTime; /** * 账号状态 */ @@ -79,15 +75,6 @@ public class AdminDO { return this; } - public Date getCreateTime() { - return createTime; - } - - public AdminDO setCreateTime(Date createTime) { - this.createTime = createTime; - return this; - } - public Integer getStatus() { return status; } diff --git a/admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/service/AdminServiceImpl.java b/admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/service/AdminServiceImpl.java index 16a5594fb..f6ba54c1c 100644 --- a/admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/service/AdminServiceImpl.java +++ b/admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/service/AdminServiceImpl.java @@ -3,7 +3,10 @@ package cn.iocoder.mall.admin.service; import cn.iocoder.common.framework.util.ServiceExceptionUtil; import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.mall.admin.api.AdminService; +import cn.iocoder.mall.admin.api.bo.AdminPageBO; import cn.iocoder.mall.admin.api.constant.AdminErrorCodeEnum; +import cn.iocoder.mall.admin.api.dto.AdminPageDTO; +import cn.iocoder.mall.admin.convert.AdminConvert; import cn.iocoder.mall.admin.dataobject.AdminDO; import cn.iocoder.mall.admin.dao.AdminMapper; import cn.iocoder.mall.admin.dao.AdminRoleMapper; @@ -47,4 +50,16 @@ public class AdminServiceImpl implements AdminService { return adminRoleMapper.selectByAdminId(adminId); } -} + @Override + public CommonResult getAdminPage(AdminPageDTO adminPageDTO) { + AdminPageBO adminPage = new AdminPageBO(); + // 查询分页数据 + int offset = adminPageDTO.getPageNo() * adminPageDTO.getPageSize(); + adminPage.setAdmins(AdminConvert.INSTANCE.convert(adminMapper.selectListByNicknameLike(adminPageDTO.getNickname(), + offset, adminPageDTO.getPageSize()))); + // 查询分页总数 + adminPage.setCount(adminMapper.selectCountByNicknameLike(adminPageDTO.getNickname())); + return CommonResult.success(adminPage); + } + +} \ No newline at end of file diff --git a/admin/admin-service-impl/src/main/resources/mapper/AdminMapper.xml b/admin/admin-service-impl/src/main/resources/mapper/AdminMapper.xml index 1855f9514..83cc2d2f8 100644 --- a/admin/admin-service-impl/src/main/resources/mapper/AdminMapper.xml +++ b/admin/admin-service-impl/src/main/resources/mapper/AdminMapper.xml @@ -2,19 +2,42 @@ - - - - - - - + + id, username, nickname, password, status, + create_time + + + + + \ No newline at end of file diff --git a/admin/admin-service-impl/src/main/resources/mapper/RoleMapper.xml b/admin/admin-service-impl/src/main/resources/mapper/RoleMapper.xml index 8c67921b6..86a51821c 100644 --- a/admin/admin-service-impl/src/main/resources/mapper/RoleMapper.xml +++ b/admin/admin-service-impl/src/main/resources/mapper/RoleMapper.xml @@ -39,11 +39,12 @@ name LIKE "%"#{name}"%" + AND deleted = 0 LIMIT #{offset}, #{limit} - SELECT COUNT(1) FROM role @@ -51,6 +52,7 @@ name LIKE "%"#{name}"%" + AND deleted = 0