管理员列表

This commit is contained in:
YunaiV 2019-03-02 00:16:02 +08:00
parent d7519b6019
commit ffeb866b91
18 changed files with 388 additions and 53 deletions

View File

@ -1,19 +1,25 @@
package cn.iocoder.mall.admin.application.controller; package cn.iocoder.mall.admin.application.controller;
import cn.iocoder.common.framework.vo.CommonResult; 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.ResourceService;
import cn.iocoder.mall.admin.api.bo.AdminPageBO;
import cn.iocoder.mall.admin.api.bo.ResourceBO; import cn.iocoder.mall.admin.api.bo.ResourceBO;
import cn.iocoder.mall.admin.api.constant.ResourceConstants; 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.convert.ResourceConvert;
import cn.iocoder.mall.admin.application.vo.AdminMenuTreeNodeVO; 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.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 com.alibaba.dubbo.config.annotation.Reference;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; 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;
import java.util.*; import java.util.*;
@ -26,11 +32,8 @@ public class AdminController {
@Reference(validation = "true") @Reference(validation = "true")
private ResourceService resourceService; private ResourceService resourceService;
@Reference(validation = "true")
@GetMapping("/info") private AdminService adminService;
public CommonResult<AdminInfoVO> info() {
return CommonResult.success(AdminConvert.INSTANCE.convert(AdminSecurityContextHolder.getContext()));
}
// =========== 当前管理员相关的资源 API =========== // =========== 当前管理员相关的资源 API ===========
@ -69,4 +72,20 @@ public class AdminController {
return CommonResult.success(resources.stream().map(ResourceBO::getHandler).collect(Collectors.toSet())); 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<AdminPageVO> page(@RequestParam(value = "nickname", required = false) String nickname,
@RequestParam(value = "pageNo", defaultValue = "0") Integer pageNo,
@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
CommonResult<AdminPageBO> result = adminService.getAdminPage(new AdminPageDTO().setNickname(nickname).setPageNo(pageNo).setPageSize(pageSize));
return AdminConvert.INSTANCE.convert(result);
}
} }

View File

@ -3,17 +3,17 @@ package cn.iocoder.mall.admin.application.controller;
import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.admin.api.OAuth2Service; import cn.iocoder.mall.admin.api.OAuth2Service;
import cn.iocoder.mall.admin.api.bo.OAuth2AccessTokenBO; 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.convert.PassportConvert;
import cn.iocoder.mall.admin.application.vo.AdminInfoVO;
import cn.iocoder.mall.admin.application.vo.PassportLoginVO; import cn.iocoder.mall.admin.application.vo.PassportLoginVO;
import cn.iocoder.mall.admin.sdk.context.AdminSecurityContextHolder;
import com.alibaba.dubbo.config.annotation.Reference; import com.alibaba.dubbo.config.annotation.Reference;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController @RestController
@RequestMapping("admin/passport") @RequestMapping("admin/passport")
@ -35,4 +35,10 @@ public class PassportController {
return PassportConvert.INSTANCE.convert(result); return PassportConvert.INSTANCE.convert(result);
} }
// TODO 艿艿后续继续完善
@GetMapping("/info")
public CommonResult<AdminInfoVO> info() {
return CommonResult.success(AdminConvert.INSTANCE.convert(AdminSecurityContextHolder.getContext()));
}
} }

View File

@ -31,8 +31,6 @@ public class ResourceController {
@Reference(validation = "true") @Reference(validation = "true")
private ResourceService resourceService; private ResourceService resourceService;
// =========== 资源管理 API ===========
@SuppressWarnings("Duplicates") @SuppressWarnings("Duplicates")
@GetMapping("/tree") @GetMapping("/tree")
@ApiOperation(value = "获得所有资源,按照树形结构返回") @ApiOperation(value = "获得所有资源,按照树形结构返回")

View File

@ -35,6 +35,11 @@ public class RoleController {
@GetMapping("/page") @GetMapping("/page")
@ApiOperation(value = "角色分页") @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<RolePageVO> page(@RequestParam(value = "name", required = false) String name, public CommonResult<RolePageVO> page(@RequestParam(value = "name", required = false) String name,
@RequestParam(value = "pageNo", defaultValue = "0") Integer pageNo, @RequestParam(value = "pageNo", defaultValue = "0") Integer pageNo,
@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) { @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {

View File

@ -1,7 +1,12 @@
package cn.iocoder.mall.admin.application.convert; 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.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.Mapper;
import org.mapstruct.Mappings; import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers; import org.mapstruct.factory.Mappers;
@ -14,4 +19,10 @@ public interface AdminConvert {
@Mappings({}) @Mappings({})
AdminInfoVO convert(AdminSecurityContext adminSecurityContext); AdminInfoVO convert(AdminSecurityContext adminSecurityContext);
@Mappings({})
AdminVO convert(AdminBO adminBO);
@Mappings({})
CommonResult<AdminPageVO> convert(CommonResult<AdminPageBO> result);
} }

View File

@ -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<AdminVO> admins;
@ApiModelProperty(value = "管理员总数")
private Integer count;
public List<AdminVO> getAdmins() {
return admins;
}
public AdminPageVO setAdmins(List<AdminVO> admins) {
this.admins = admins;
return this;
}
public Integer getCount() {
return count;
}
public AdminPageVO setCount(Integer count) {
this.count = count;
return this;
}
}

View File

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

View File

@ -1,16 +1,11 @@
package cn.iocoder.mall.admin.api; 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 { public interface AdminService {
// /** CommonResult<AdminPageBO> getAdminPage(AdminPageDTO adminPageDTO);
// * 创建用户一般在用户注册时调用该方法
// *
// * TODO 芋艿此处要传递一些用户注册时的相关信息例如说 ipua客户端来源等等用于数据分析风控等等
// *
// * @param mobile 手机号
// * @param code 手机验证码
// * @return 用户
// */
// UserBO createUser(String mobile, String code) throws ServiceException;
} }

View File

@ -19,7 +19,7 @@ public interface OAuth2Service {
CommonResult<OAuth2AuthenticationBO> checkToken(String accessToken); CommonResult<OAuth2AuthenticationBO> checkToken(String accessToken);
/** /**
* TODO 校验权限 * 校验权限鉴权
* *
* @param adminId 管理员编号 * @param adminId 管理员编号
* @param roleIds 管理员拥有的角色编号的集合 * @param roleIds 管理员拥有的角色编号的集合

View File

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

View File

@ -0,0 +1,34 @@
package cn.iocoder.mall.admin.api.bo;
import java.util.List;
public class AdminPageBO {
/**
* 管理员数组
*/
private List<AdminBO> admins;
/**
* 总量
*/
private Integer count;
public List<AdminBO> getAdmins() {
return admins;
}
public AdminPageBO setAdmins(List<AdminBO> admins) {
this.admins = admins;
return this;
}
public Integer getCount() {
return count;
}
public AdminPageBO setCount(Integer count) {
this.count = count;
return this;
}
}

View File

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

View File

@ -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<AdminBO> convert(List<AdminDO> adminBOs);
}

View File

@ -4,9 +4,17 @@ import cn.iocoder.mall.admin.dataobject.AdminDO;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.List;
@Repository @Repository
public interface AdminMapper { public interface AdminMapper {
AdminDO selectByUsername(@Param("username") String username); AdminDO selectByUsername(@Param("username") String username);
List<AdminDO> selectListByNicknameLike(@Param("nickname") String nickname,
@Param("offset") Integer offset,
@Param("limit") Integer limit);
Integer selectCountByNicknameLike(@Param("nickname") String nickname);
} }

View File

@ -1,11 +1,11 @@
package cn.iocoder.mall.admin.dataobject; 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 * TODO 芋艿 暂时最简单的 MD5
*/ */
private String password; private String password;
/**
* 创建时间
*/
private Date createTime;
/** /**
* 账号状态 * 账号状态
*/ */
@ -79,15 +75,6 @@ public class AdminDO {
return this; return this;
} }
public Date getCreateTime() {
return createTime;
}
public AdminDO setCreateTime(Date createTime) {
this.createTime = createTime;
return this;
}
public Integer getStatus() { public Integer getStatus() {
return status; return status;
} }

View File

@ -3,7 +3,10 @@ package cn.iocoder.mall.admin.service;
import cn.iocoder.common.framework.util.ServiceExceptionUtil; import cn.iocoder.common.framework.util.ServiceExceptionUtil;
import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.admin.api.AdminService; 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.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.dataobject.AdminDO;
import cn.iocoder.mall.admin.dao.AdminMapper; import cn.iocoder.mall.admin.dao.AdminMapper;
import cn.iocoder.mall.admin.dao.AdminRoleMapper; import cn.iocoder.mall.admin.dao.AdminRoleMapper;
@ -47,4 +50,16 @@ public class AdminServiceImpl implements AdminService {
return adminRoleMapper.selectByAdminId(adminId); return adminRoleMapper.selectByAdminId(adminId);
} }
@Override
public CommonResult<AdminPageBO> 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);
}
} }

View File

@ -2,19 +2,42 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.iocoder.mall.admin.dao.AdminMapper"> <mapper namespace="cn.iocoder.mall.admin.dao.AdminMapper">
<!--<insert id="insert" parameterType="UserDO" useGeneratedKeys="true" keyProperty="id">--> <sql id="FIELDS">
<!--INSERT INTO users (--> id, username, nickname, password, status,
<!--id, mobile, create_time--> create_time
<!--) VALUES (--> </sql>
<!--#{id}, #{mobile}, #{createTime}-->
<!--)-->
<!--</insert>-->
<select id="selectByUsername" parameterType="String" resultType="AdminDO"> <select id="selectByUsername" parameterType="String" resultType="AdminDO">
SELECT SELECT
id, username, nickname, password, status <include refid="FIELDS" />
FROM admin FROM admin
WHERE username = #{username} WHERE username = #{username}
AND deleted = 0
</select>
<select id="selectListByNicknameLike" resultType="AdminDO">
SELECT
<include refid="FIELDS" />
FROM admin
<where>
<if test="nickname != null">
nickname LIKE "%"#{nickname}"%"
</if>
AND deleted = 0
</where>
LIMIT #{offset}, #{limit}
</select>
<select id="selectCountByNicknameLike" resultType="Integer">
SELECT
COUNT(1)
FROM admin
<where>
<if test="nickname != null">
nickname LIKE "%"#{nickname}"%"
</if>
AND deleted = 0
</where>
</select> </select>
</mapper> </mapper>

View File

@ -39,11 +39,12 @@
<if test="name != null"> <if test="name != null">
name LIKE "%"#{name}"%" name LIKE "%"#{name}"%"
</if> </if>
AND deleted = 0
</where> </where>
LIMIT #{offset}, #{limit} LIMIT #{offset}, #{limit}
</select> </select>
<select id="selectCountByNameLike" resultType="RoleDO"> <select id="selectCountByNameLike" resultType="Integer">
SELECT SELECT
COUNT(1) COUNT(1)
FROM role FROM role
@ -51,6 +52,7 @@
<if test="name != null"> <if test="name != null">
name LIKE "%"#{name}"%" name LIKE "%"#{name}"%"
</if> </if>
AND deleted = 0
</where> </where>
</select> </select>