完成管理后台的 admin 相关接口

This commit is contained in:
YunaiV 2020-07-05 22:22:45 +08:00
parent 51a5e5b750
commit 3be27d0648
15 changed files with 140 additions and 88 deletions

View File

@ -6,9 +6,10 @@ import org.hibernate.validator.constraints.Range;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
@ApiModel("分页参数")
public class PageParam {
public class PageParam implements Serializable {
@ApiModelProperty(value = "页码,从 1 开始", required = true,example = "1")
@NotNull(message = "页码不能为空")

View File

@ -2,14 +2,19 @@ package cn.iocoder.mall.managementweb.controller.admin;
import cn.iocoder.common.framework.util.HttpUtil;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.managementweb.controller.admin.dto.AdminCreateDTO;
import cn.iocoder.mall.managementweb.controller.admin.dto.AdminPageDTO;
import cn.iocoder.mall.managementweb.controller.admin.dto.AdminUpdateInfoDTO;
import cn.iocoder.mall.managementweb.controller.admin.dto.AdminUpdateStatusDTO;
import cn.iocoder.mall.managementweb.controller.admin.vo.AdminPageItemVO;
import cn.iocoder.mall.managementweb.manager.admin.AdminManager;
import cn.iocoder.mall.security.admin.core.context.AdminSecurityContextHolder;
import cn.iocoder.security.annotations.RequiresPermissions;
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;
@ -27,45 +32,32 @@ public class AdminController {
private AdminManager adminManager;
// =========== 管理员管理 API ===========
// @GetMapping("/page")
// @RequiresPermissions("system.admin.page")
// @ApiOperation(value = "管理员分页")
// public CommonResult<PageResult<AdminVO>> page(AdminPageDTO adminPageDTO) {
// PageResult<AdminBO> page = adminService.getAdminPage(adminPageDTO);
// PageResult<AdminVO> resultPage = AdminConvert.INSTANCE.convertAdminVOPage(page);
// // 拼接结果
// if (!resultPage.getList().isEmpty()) {
// // 查询角色数组
// Map<Integer, Collection<RoleBO>> roleMap = adminService.getAdminRolesMap(CollectionUtil.convertList(resultPage.getList(), AdminBO::getId));
// resultPage.getList().forEach(admin -> admin.setRoles(AdminConvert.INSTANCE.convertAdminVORoleList(roleMap.get(admin.getId()))));
//
// // 查询对应部门
// List<DeptmentBO> deptmentBOS = deptmentService.getAllDeptments();
// Map<Integer, String> deptNameMap = deptmentBOS.stream().collect(Collectors.toMap(d->d.getId(), d->d.getName()));
// //管理员所在部门被删后变成未分配状态
// deptNameMap.put(0, "未分配");
// resultPage.getList().forEach(admin->{
// admin.setDeptment(new AdminVO.Deptment(admin.getDeptmentId(), deptNameMap.get(admin.getDeptmentId())));
// });
// }
// return success(resultPage);
// }
@ApiOperation(value = "管理员分页")
@GetMapping("/page")
@RequiresPermissions("system.admin.page")
public CommonResult<PageResult<AdminPageItemVO>> page(AdminPageDTO adminPageDTO) {
return success(adminManager.pageAdmin(adminPageDTO));
}
@ApiOperation(value = "创建管理员")
@PostMapping("/create")
@RequiresPermissions("admin:create")
public CommonResult<Integer> createAdmin(AdminCreateDTO createDTO, HttpServletRequest request) {
return success(adminManager.createAdmin(createDTO, AdminSecurityContextHolder.getAdminId(), HttpUtil.getIp(request)));
}
@PostMapping("/update")
@ApiOperation(value = "更新管理员")
@RequiresPermissions("admin:update")
public CommonResult<Boolean> updateAdmin(AdminUpdateInfoDTO updateInfoDTO) {
adminManager.updateAdmin(updateInfoDTO);
return success(true);
}
@PostMapping("/update_status")
@PostMapping("/update-status")
@ApiOperation(value = "更新管理员状态")
@RequiresPermissions("admin:update-status")
public CommonResult<Boolean> updateUserStatus(AdminUpdateStatusDTO updateStatusDTO) {
adminManager.updateAdminStatus(updateStatusDTO);
return success(true);

View File

@ -15,10 +15,10 @@ import javax.validation.constraints.Pattern;
@Accessors(chain = true)
public class AdminCreateDTO {
@ApiModelProperty(value = "昵称", required = true, example = "小王")
@NotEmpty(message = "昵称不能为空")
@Length(max = 10, message = "昵称长度最大为 10 位")
private String nickname;
@ApiModelProperty(value = "真实名字", required = true, example = "小王")
@NotEmpty(message = "真实名字不能为空")
@Length(max = 10, message = "真实名字长度最大为 10 位")
private String name;
@ApiModelProperty(value = "部门编号", required = true, example = "1")
@NotNull(message = "部门不能为空")

View File

@ -30,10 +30,10 @@ public class AdminUpdateInfoDTO {
@Length(min = 4, max = 16, message = "密码长度为 4-16 位")
private String password;
@ApiModelProperty(value = "昵称", required = true, example = "小王")
@NotEmpty(message = "昵称不能为空")
@Length(max = 10, message = "昵称长度最大为 10 位")
private String nickname;
@ApiModelProperty(value = "真实名字", required = true, example = "小王")
@NotEmpty(message = "真实名字不能为空")
@Length(max = 10, message = "真实名字长度最大为 10 位")
private String name;
@ApiModelProperty(value = "部门编号", required = true, example = "1")
@NotNull(message = "部门不能为空")

View File

@ -8,10 +8,10 @@ import lombok.experimental.Accessors;
import java.util.Date;
import java.util.List;
@ApiModel("管理员 - 管理员模块 - 管理员分页信息 Response")
@ApiModel(value = "分页时,管理员的信息 VO")
@Data
@Accessors(chain = true)
public class AdminsAdminPageResponse {
public class AdminPageItemVO {
@ApiModel("角色")
@Data
@ -39,19 +39,6 @@ public class AdminsAdminPageResponse {
}
@ApiModel("账号")
@Data
@Accessors(chain = true)
public static class Account {
@ApiModelProperty(value = "账号编号", required = true, example = "1")
private Integer id;
@ApiModelProperty(value = "登陆账号", required = true, example = "15601691300")
private String username;
}
@ApiModelProperty(value = "管理员编号", required = true, example = "1")
private Integer id;
@ApiModelProperty(value = "真实名字", required = true, example = "小王")
@ -60,17 +47,13 @@ public class AdminsAdminPageResponse {
private Date createTime;
@ApiModelProperty(value = "在职状态", required = true, example = "1", notes = "见 AdminStatusEnum 枚举")
private Integer status;
/**
* 账号
*/
private Account account;
@ApiModelProperty(value = "登陆账号", required = true, example = "15601691300")
private String username;
/**
* 角色列表
*/
private List<Role> roles;
/**
* 所在部门
*/

View File

@ -0,0 +1,29 @@
package cn.iocoder.mall.managementweb.convert.admin;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.managementweb.controller.admin.dto.AdminUpdateInfoDTO;
import cn.iocoder.mall.managementweb.controller.admin.dto.AdminUpdateStatusDTO;
import cn.iocoder.mall.managementweb.controller.admin.vo.AdminPageItemVO;
import cn.iocoder.mall.systemservice.rpc.admin.dto.AdminCreateDTO;
import cn.iocoder.mall.systemservice.rpc.admin.dto.AdminPageDTO;
import cn.iocoder.mall.systemservice.rpc.admin.dto.AdminUpdateDTO;
import cn.iocoder.mall.systemservice.rpc.admin.vo.AdminVO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
@Mapper
public interface AdminConvert {
AdminConvert INSTANCE = Mappers.getMapper(AdminConvert.class);
AdminCreateDTO convert(cn.iocoder.mall.managementweb.controller.admin.dto.AdminCreateDTO bean);
AdminUpdateDTO convert(AdminUpdateInfoDTO bean);
AdminUpdateDTO convert(AdminUpdateStatusDTO bean);
AdminPageDTO convert(cn.iocoder.mall.managementweb.controller.admin.dto.AdminPageDTO bean);
PageResult<AdminPageItemVO> convert(PageResult<AdminVO> pageResultData);
}

View File

@ -1,25 +1,62 @@
package cn.iocoder.mall.managementweb.manager.admin;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.managementweb.controller.admin.dto.AdminCreateDTO;
import cn.iocoder.mall.managementweb.controller.admin.dto.AdminPageDTO;
import cn.iocoder.mall.managementweb.controller.admin.dto.AdminUpdateInfoDTO;
import cn.iocoder.mall.managementweb.controller.admin.dto.AdminUpdateStatusDTO;
import cn.iocoder.mall.managementweb.controller.admin.vo.AdminPageItemVO;
import cn.iocoder.mall.managementweb.convert.admin.AdminConvert;
import cn.iocoder.mall.systemservice.rpc.admin.AdminRpc;
import cn.iocoder.mall.systemservice.rpc.admin.vo.AdminVO;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Service;
@Service
public class AdminManager {
//TODO 目前需要增加搜索所有子部门的用户
@Reference(version = "${dubbo.consumer.AdminRpc.version}", validation = "false")
private AdminRpc adminRpc;
public PageResult<AdminPageItemVO> pageAdmin(AdminPageDTO pageDTO) {
CommonResult<PageResult<AdminVO>> pageResult = adminRpc.pageAdmin(AdminConvert.INSTANCE.convert(pageDTO));
pageResult.checkError();
// 转换结果
PageResult<AdminPageItemVO> adminPageVO = AdminConvert.INSTANCE.convert(pageResult.getData());
// 拼接结果
// if (!resultPage.getList().isEmpty()) {
// // 查询角色数组
// Map<Integer, Collection<RoleBO>> roleMap = adminService.getAdminRolesMap(CollectionUtil.convertList(resultPage.getList(), AdminBO::getId));
// resultPage.getList().forEach(admin -> admin.setRoles(AdminConvert.INSTANCE.convertAdminVORoleList(roleMap.get(admin.getId()))));
//
// // 查询对应部门
// List<DeptmentBO> deptmentBOS = deptmentService.getAllDeptments();
// Map<Integer, String> deptNameMap = deptmentBOS.stream().collect(Collectors.toMap(d->d.getId(), d->d.getName()));
// //管理员所在部门被删后变成未分配状态
// deptNameMap.put(0, "未分配");
// resultPage.getList().forEach(admin->{
// admin.setDeptment(new AdminVO.Deptment(admin.getDeptmentId(), deptNameMap.get(admin.getDeptmentId())));
// });
// }
return adminPageVO;
}
public Integer createAdmin(AdminCreateDTO createDTO, Integer createAdminId, String createIp) {
return null;
CommonResult<Integer> createAdminResult = adminRpc.createAdmin(AdminConvert.INSTANCE.convert(createDTO)
.setCreateAdminId(createAdminId).setCreateIp(createIp));
createAdminResult.checkError();
return createAdminResult.getData();
}
public void updateAdmin(AdminUpdateInfoDTO updateInfoDTO) {
CommonResult<Boolean> updateAdminResult = adminRpc.updateAdmin(AdminConvert.INSTANCE.convert(updateInfoDTO));
updateAdminResult.checkError();
}
public void updateAdminStatus(AdminUpdateStatusDTO updateStatusDTO) {
CommonResult<Boolean> updateAdminResult = adminRpc.updateAdmin(AdminConvert.INSTANCE.convert(updateStatusDTO));
updateAdminResult.checkError();
}
}

View File

@ -8,7 +8,6 @@ import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.io.Serializable;
import java.util.Date;
/**
* 管理员添加 BO
@ -20,9 +19,9 @@ public class AdminCreateDTO implements Serializable {
/**
* 昵称
*/
@NotEmpty(message = "昵称不能为空")
@Length(max = 10, message = "昵称长度最大为 10 位")
private String nickname;
@NotEmpty(message = "真实名字不能为空")
@Length(max = 10, message = "真实名字长度最大为 10 位")
private String name;
/**
* 部门编号
*/
@ -47,11 +46,11 @@ public class AdminCreateDTO implements Serializable {
* 创建管理员编号
*/
@NotNull(message = "创建管理员编号不能为空")
private String createAdminId;
private Integer createAdminId;
/**
* 创建 IP
*/
@NotNull(message = "创建 IP 不能为空")
private Date createIp;
private String createIp;
}

View File

@ -1,22 +1,25 @@
package cn.iocoder.mall.systemservice.rpc.admin.dto;
import cn.iocoder.common.framework.vo.PageParam;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
@ApiModel("管理员分页查询 DTO")
/**
* 管理员分页查询 DTO
*/
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
public class AdminPageDTO extends PageParam {
@ApiModelProperty(value = "真实名字,模糊匹配", example = "小王")
/**
* 真实名字模糊匹配
*/
private String name;
@ApiModelProperty(value = "部门编号")
/**
* 部门编号
*/
private Integer departmentId;
}

View File

@ -2,7 +2,6 @@ package cn.iocoder.mall.systemservice.rpc.admin.dto;
import cn.iocoder.common.framework.enums.CommonStatusEnum;
import cn.iocoder.common.framework.validator.InEnum;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import org.hibernate.validator.constraints.Length;
@ -24,15 +23,13 @@ public class AdminUpdateDTO implements Serializable {
@NotNull(message = "管理员编号不能为空")
private Integer id;
/**
* 昵称
* 真实名字
*/
@ApiModelProperty(value = "昵称", required = true, example = "小王")
@Length(max = 10, message = "昵称长度最大为 10 位")
private String nickname;
@Length(max = 10, message = "真实名字长度最大为 10 位")
private String name;
/**
* 部门编号
*/
@ApiModelProperty(value = "部门编号", required = true, example = "1")
private Integer departmentId;
/**
* 状态
@ -48,7 +45,6 @@ public class AdminUpdateDTO implements Serializable {
/**
* 密码
*/
@ApiModelProperty(value = "密码", required = true, example = "buzhidao")
@Length(min = 4, max = 16, message = "密码长度为 4-16 位")
private String password;

View File

@ -5,6 +5,7 @@ import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.util.Date;
/**
* 管理员 DO
@ -37,4 +38,9 @@ public class AdminVO implements Serializable {
*/
private String username;
/**
* 创建时间
*/
private Date createTime;
}

View File

@ -7,8 +7,6 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.util.Date;
/**
* 管理员实体
*
@ -56,11 +54,13 @@ public class AdminDO extends BaseDO {
/**
* 创建管理员编号
*
* 外键 {@link AdminDO#id}
*/
private String createAdminId;
private Integer createAdminId;
/**
* 创建 IP
*/
private Date createIp;
private String createIp;
}

View File

@ -5,6 +5,8 @@ import cn.iocoder.mall.systemservice.enums.admin.AdminStatusEnum;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.Date;
/**
* 管理员信息 BO
*/
@ -38,4 +40,9 @@ public class AdminBO {
*/
private String username;
/**
* 创建时间
*/
private Date createTime;
}

View File

@ -7,7 +7,6 @@ import org.hibernate.validator.constraints.Length;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.util.Date;
/**
* 管理员添加 BO
@ -19,9 +18,9 @@ public class AdminCreateBO {
/**
* 昵称
*/
@NotEmpty(message = "昵称不能为空")
@Length(max = 10, message = "昵称长度最大为 10 位")
private String nickname;
@NotEmpty(message = "真实名字不能为空")
@Length(max = 10, message = "真实名字长度最大为 10 位")
private String name;
/**
* 部门编号
*/
@ -46,11 +45,11 @@ public class AdminCreateBO {
* 创建管理员编号
*/
@NotNull(message = "创建管理员编号不能为空")
private String createAdminId;
private Integer createAdminId;
/**
* 创建 IP
*/
@NotNull(message = "创建 IP 不能为空")
private Date createIp;
private String createIp;
}

View File

@ -24,8 +24,8 @@ public class AdminUpdateBO {
/**
* 昵称
*/
@Length(max = 10, message = "昵称长度最大为 10 位")
private String nickname;
@Length(max = 10, message = "真实名字长度最大为 10 位")
private String name;
/**
* 部门编号
*/