部门模块的迁移
parent
244f248ad5
commit
846510c309
|
@ -0,0 +1,38 @@
|
|||
### /department/create 成功
|
||||
POST {{baseUrl}}/department/create
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
Authorization: Bearer {{accessToken}}
|
||||
|
||||
name=测试部门&pid=0&sort=0
|
||||
|
||||
### /department/update 成功
|
||||
POST {{baseUrl}}/department/update
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
Authorization: Bearer {{accessToken}}
|
||||
|
||||
id=1&name=测试部门&pid=0&sort=0
|
||||
|
||||
### /resource/delete 成功
|
||||
POST {{baseUrl}}/department/delete
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
Authorization: Bearer {{accessToken}}
|
||||
|
||||
id=1
|
||||
|
||||
### /department/get 成功
|
||||
GET {{baseUrl}}/department/get?departmentId=1
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
Authorization: Bearer {{accessToken}}
|
||||
|
||||
### /department/list 成功
|
||||
GET {{baseUrl}}/department/list?departmentIds=1,13
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
Authorization: Bearer {{accessToken}}
|
||||
|
||||
### /department/tree 成功
|
||||
GET {{baseUrl}}/department/tree
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
Authorization: Bearer {{accessToken}}
|
||||
|
||||
###
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
package cn.iocoder.mall.managementweb.controller.admin;
|
||||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.mall.managementweb.controller.admin.dto.DepartmentCreateDTO;
|
||||
import cn.iocoder.mall.managementweb.controller.admin.dto.DepartmentUpdateDTO;
|
||||
import cn.iocoder.mall.managementweb.controller.admin.vo.DepartmentTreeNodeVO;
|
||||
import cn.iocoder.mall.managementweb.controller.admin.vo.DepartmentVO;
|
||||
import cn.iocoder.mall.managementweb.manager.admin.DepartmentManager;
|
||||
import cn.iocoder.security.annotations.RequiresPermissions;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.common.framework.vo.CommonResult.success;
|
||||
|
||||
/**
|
||||
* 部门 Controller
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/department")
|
||||
@Api(tags = "部门")
|
||||
@Validated
|
||||
public class DepartmentController {
|
||||
|
||||
@Autowired
|
||||
private DepartmentManager departmentManager;
|
||||
|
||||
@PostMapping("/create")
|
||||
@ApiOperation("创建部门")
|
||||
@RequiresPermissions("system:department:create")
|
||||
public CommonResult<Integer> createDepartment(@Valid DepartmentCreateDTO createDTO) {
|
||||
return success(departmentManager.createDepartment(createDTO));
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
@ApiOperation("更新部门")
|
||||
@RequiresPermissions("system:department:update")
|
||||
public CommonResult<Boolean> updateDepartment(@Valid DepartmentUpdateDTO updateDTO) {
|
||||
departmentManager.updateDepartment(updateDTO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
@ApiOperation("删除部门")
|
||||
@ApiImplicitParam(name = "departmentId", value = "部门编号", required = true)
|
||||
@RequiresPermissions("system:department:delete")
|
||||
public CommonResult<Boolean> deleteDepartment(@RequestParam("departmentId") Integer departmentId) {
|
||||
departmentManager.deleteDepartment(departmentId);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@ApiOperation("获得部门")
|
||||
@ApiImplicitParam(name = "departmentId", value = "部门编号", required = true)
|
||||
@RequiresPermissions("system:department:tree")
|
||||
public CommonResult<DepartmentVO> getDepartment(@RequestParam("departmentId") Integer departmentId) {
|
||||
return success(departmentManager.getDepartment(departmentId));
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("获得部门列表")
|
||||
@ApiImplicitParam(name = "departmentIds", value = "部门编号列表", required = true)
|
||||
@RequiresPermissions("system:department:tree")
|
||||
public CommonResult<List<DepartmentVO>> listDepartments(@RequestParam("departmentIds") List<Integer> departmentIds) {
|
||||
return success(departmentManager.listDepartments(departmentIds));
|
||||
}
|
||||
|
||||
@GetMapping("/tree")
|
||||
@ApiOperation("获得部门树")
|
||||
@RequiresPermissions("system:department:tree")
|
||||
public CommonResult<List<DepartmentTreeNodeVO>> treeDepartment() {
|
||||
return success(departmentManager.treeDepartment());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package cn.iocoder.mall.managementweb.controller.admin.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@ApiModel("部门创建 DTO")
|
||||
@Data
|
||||
public class DepartmentCreateDTO {
|
||||
|
||||
@ApiModelProperty(value = "部门名称", required = true, example = "技术部")
|
||||
@NotEmpty(message = "部门名称不能为空")
|
||||
private String name;
|
||||
@ApiModelProperty(value = "排序字段", required = true, example = "1024")
|
||||
@NotNull(message = "排序字段不能为空")
|
||||
private Integer sort;
|
||||
@ApiModelProperty(value = "父级部门编号", required = true, example = "2048")
|
||||
@NotNull(message = "父级部门编号不能为空")
|
||||
private Integer pid;
|
||||
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package cn.iocoder.mall.managementweb.controller.admin.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@ApiModel("部门更新 DTO")
|
||||
@Data
|
||||
public class DepartmentUpdateDTO {
|
||||
|
||||
@ApiModelProperty(value = "部门编号", required = true, example = "1")
|
||||
@NotNull(message = "部门编号不能为空")
|
||||
private Integer id;
|
||||
@ApiModelProperty(value = "部门名称", required = true, example = "技术部")
|
||||
@NotEmpty(message = "部门名称不能为空")
|
||||
private String name;
|
||||
@ApiModelProperty(value = "排序字段", required = true, example = "1024")
|
||||
@NotNull(message = "排序字段不能为空")
|
||||
private Integer sort;
|
||||
@ApiModelProperty(value = "父级部门编号", required = true, example = "2048")
|
||||
@NotNull(message = "父级部门编号不能为空")
|
||||
private Integer pid;
|
||||
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package cn.iocoder.mall.managementweb.controller.admin.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@ApiModel("部门树节点 VO")
|
||||
@Data
|
||||
public class DepartmentTreeNodeVO {
|
||||
|
||||
@ApiModelProperty(value = "部门编号", required = true, example = "1")
|
||||
private Integer id;
|
||||
@ApiModelProperty(value = "部门名称", required = true, example = "技术部")
|
||||
private String name;
|
||||
@ApiModelProperty(value = "排序字段", required = true, example = "1024")
|
||||
private Integer sort;
|
||||
@ApiModelProperty(value = "父级部门编号", required = true, example = "2048")
|
||||
private Integer pid;
|
||||
@ApiModelProperty(value = "创建时间", required = true)
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 子节点
|
||||
*/
|
||||
private List<DepartmentTreeNodeVO> children;
|
||||
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package cn.iocoder.mall.managementweb.controller.admin.vo;
|
||||
|
||||
import lombok.*;
|
||||
import io.swagger.annotations.*;
|
||||
import java.util.*;
|
||||
|
||||
@ApiModel("部门 VO")
|
||||
@Data
|
||||
public class DepartmentVO {
|
||||
|
||||
@ApiModelProperty(value = "部门编号", required = true, example = "1")
|
||||
private Integer id;
|
||||
@ApiModelProperty(value = "部门名称", required = true, example = "技术部")
|
||||
private String name;
|
||||
@ApiModelProperty(value = "排序字段", required = true, example = "1024")
|
||||
private Integer sort;
|
||||
@ApiModelProperty(value = "父级部门编号", required = true, example = "2048")
|
||||
private Integer pid;
|
||||
@ApiModelProperty(value = "创建时间", required = true)
|
||||
private Date createTime;
|
||||
|
||||
}
|
|
@ -22,6 +22,7 @@ Authorization: Bearer {{accessToken}}
|
|||
### /passport/list-admin-permission 成功
|
||||
GET {{baseUrl}}/passport/list-admin-permission
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
Authorization: Bearer {{accessToken}}
|
||||
#Authorization: Bearer {{accessToken}}
|
||||
Authorization: Bearer 36dce986276b4d6c8f9f4f3b89b22810
|
||||
|
||||
###
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
POST {{baseUrl}}/role/create
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
Authorization: Bearer {{accessToken}}
|
||||
#Authorization: Bearer 9d250d9b6c034a6c88bf4034cdf1d4cc
|
||||
|
||||
name=测试角色
|
||||
|
||||
|
|
|
@ -8,9 +8,13 @@ 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 cn.iocoder.mall.systemservice.rpc.admin.vo.DepartmentVO;
|
||||
import cn.iocoder.mall.systemservice.rpc.permission.vo.RoleVO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface AdminConvert {
|
||||
|
||||
|
@ -28,4 +32,8 @@ public interface AdminConvert {
|
|||
|
||||
cn.iocoder.mall.managementweb.controller.admin.vo.AdminVO convert(AdminVO bean);
|
||||
|
||||
AdminPageItemVO convert02(AdminVO adminVO);
|
||||
AdminPageItemVO.Department convert(DepartmentVO bean);
|
||||
List<AdminPageItemVO.Role> convert(List<RoleVO> list);
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
package cn.iocoder.mall.managementweb.convert.admin;
|
||||
|
||||
import cn.iocoder.mall.managementweb.controller.admin.vo.DepartmentTreeNodeVO;
|
||||
import cn.iocoder.mall.managementweb.controller.admin.vo.DepartmentVO;
|
||||
import cn.iocoder.mall.systemservice.rpc.admin.dto.DepartmentCreateDTO;
|
||||
import cn.iocoder.mall.systemservice.rpc.admin.dto.DepartmentUpdateDTO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface DepartmentConvert {
|
||||
|
||||
DepartmentConvert INSTANCE = Mappers.getMapper(DepartmentConvert.class);
|
||||
|
||||
DepartmentCreateDTO convert(cn.iocoder.mall.managementweb.controller.admin.dto.DepartmentCreateDTO bean);
|
||||
|
||||
DepartmentUpdateDTO convert(cn.iocoder.mall.managementweb.controller.admin.dto.DepartmentUpdateDTO bean);
|
||||
|
||||
List<DepartmentVO> convertList(List<cn.iocoder.mall.systemservice.rpc.admin.vo.DepartmentVO> list);
|
||||
|
||||
DepartmentVO convert(cn.iocoder.mall.systemservice.rpc.admin.vo.DepartmentVO bean);
|
||||
|
||||
DepartmentTreeNodeVO convertTreeNode(cn.iocoder.mall.systemservice.rpc.admin.vo.DepartmentVO bean);
|
||||
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package cn.iocoder.mall.managementweb.manager.admin;
|
||||
|
||||
import cn.iocoder.common.framework.util.CollectionUtils;
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.managementweb.controller.admin.dto.AdminCreateDTO;
|
||||
|
@ -10,39 +11,87 @@ import cn.iocoder.mall.managementweb.controller.admin.vo.AdminPageItemVO;
|
|||
import cn.iocoder.mall.managementweb.controller.admin.vo.AdminVO;
|
||||
import cn.iocoder.mall.managementweb.convert.admin.AdminConvert;
|
||||
import cn.iocoder.mall.systemservice.rpc.admin.AdminRpc;
|
||||
import cn.iocoder.mall.systemservice.rpc.admin.DepartmentRpc;
|
||||
import cn.iocoder.mall.systemservice.rpc.admin.vo.DepartmentVO;
|
||||
import cn.iocoder.mall.systemservice.rpc.permission.PermissionRpc;
|
||||
import cn.iocoder.mall.systemservice.rpc.permission.RoleRpc;
|
||||
import cn.iocoder.mall.systemservice.rpc.permission.vo.RoleVO;
|
||||
import org.apache.dubbo.config.annotation.Reference;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@Service
|
||||
public class AdminManager {
|
||||
|
||||
@Reference(version = "${dubbo.consumer.AdminRpc.version}", validation = "false")
|
||||
private AdminRpc adminRpc;
|
||||
@Reference(version = "${dubbo.consumer.RoleRpc.version}", validation = "false")
|
||||
private RoleRpc roleRpc;
|
||||
@Reference(version = "${dubbo.consumer.DepartmentRpc.version}", validation = "false")
|
||||
private DepartmentRpc departmentRpc;
|
||||
@Reference(version = "${dubbo.consumer.PermissionRpc.version}", validation = "false")
|
||||
private PermissionRpc permissionRpc;
|
||||
|
||||
public PageResult<AdminPageItemVO> pageAdmin(AdminPageDTO pageDTO) {
|
||||
CommonResult<PageResult<cn.iocoder.mall.systemservice.rpc.admin.vo.AdminVO>> pageResult =
|
||||
adminRpc.pageAdmin(AdminConvert.INSTANCE.convert(pageDTO));
|
||||
pageResult.checkError();
|
||||
// 转换结果
|
||||
PageResult<AdminPageItemVO> adminPageVO = AdminConvert.INSTANCE.convert(pageResult.getData());
|
||||
PageResult<AdminPageItemVO> adminPageVO = new PageResult<>();
|
||||
adminPageVO.setTotal(pageResult.getData().getTotal());
|
||||
adminPageVO.setList(new ArrayList<>(pageResult.getData().getList().size()));
|
||||
// 拼接结果
|
||||
// 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())));
|
||||
// });
|
||||
// }
|
||||
if (!pageResult.getData().getList().isEmpty()) {
|
||||
// 查询角色数组
|
||||
Map<Integer, List<RoleVO>> adminRoleMap = this.listAdminRoles(CollectionUtils.convertList(pageResult.getData().getList(),
|
||||
cn.iocoder.mall.systemservice.rpc.admin.vo.AdminVO::getId));
|
||||
// 查询部门
|
||||
CommonResult<List<DepartmentVO>> listDepartmentsResult = departmentRpc.listDepartments(
|
||||
CollectionUtils.convertSet(pageResult.getData().getList(),
|
||||
cn.iocoder.mall.systemservice.rpc.admin.vo.AdminVO::getDepartmentId));
|
||||
listDepartmentsResult.checkError();
|
||||
Map<Integer, DepartmentVO> departmentMap = CollectionUtils.convertMap(listDepartmentsResult.getData(), DepartmentVO::getId);
|
||||
// 拼接数据
|
||||
for (cn.iocoder.mall.systemservice.rpc.admin.vo.AdminVO adminVO : pageResult.getData().getList()) {
|
||||
AdminPageItemVO adminPageItemVO = AdminConvert.INSTANCE.convert02(adminVO);
|
||||
adminPageVO.getList().add(adminPageItemVO);
|
||||
// 拼接部门
|
||||
adminPageItemVO.setDepartment(AdminConvert.INSTANCE.convert(departmentMap.get(adminVO.getDepartmentId())));
|
||||
// 拼接角色
|
||||
adminPageItemVO.setRoles( AdminConvert.INSTANCE.convert(adminRoleMap.get(adminVO.getId())));
|
||||
}
|
||||
} else {
|
||||
adminPageVO.setList(Collections.emptyList());
|
||||
}
|
||||
return adminPageVO;
|
||||
}
|
||||
|
||||
private Map<Integer, List<RoleVO>> listAdminRoles(List<Integer> adminIds) {
|
||||
// 获得管理员拥有的角色
|
||||
CommonResult<Map<Integer, Set<Integer>>> mapAdminRoleIdsResult = permissionRpc.mapAdminRoleIds(adminIds);
|
||||
mapAdminRoleIdsResult.checkError();
|
||||
// 获得角色列表
|
||||
Set<Integer> roleIds = new HashSet<>();
|
||||
mapAdminRoleIdsResult.getData().values().forEach(roleIds::addAll);
|
||||
CommonResult<List<RoleVO>> listRolesResult = roleRpc.listRoles(roleIds);
|
||||
listRolesResult.checkError();
|
||||
Map<Integer, RoleVO> roleVOMap = CollectionUtils.convertMap(listRolesResult.getData(), RoleVO::getId);
|
||||
// 拼接结果
|
||||
Map<Integer, List<RoleVO>> adminRoleVOMap = new HashMap<>();
|
||||
mapAdminRoleIdsResult.getData().forEach((adminId, adminRoleIds) -> {
|
||||
List<RoleVO> roleVOs = new ArrayList<>(adminRoleIds.size());
|
||||
adminRoleIds.forEach(roleId -> {
|
||||
RoleVO roleVO = roleVOMap.get(roleId);
|
||||
if (roleVO != null) {
|
||||
roleVOs.add(roleVO);
|
||||
}
|
||||
});
|
||||
adminRoleVOMap.put(adminId, roleVOs);
|
||||
});
|
||||
return adminRoleVOMap;
|
||||
}
|
||||
|
||||
public Integer createAdmin(AdminCreateDTO createDTO, Integer createAdminId, String createIp) {
|
||||
CommonResult<Integer> createAdminResult = adminRpc.createAdmin(AdminConvert.INSTANCE.convert(createDTO)
|
||||
.setCreateAdminId(createAdminId).setCreateIp(createIp));
|
||||
|
|
|
@ -0,0 +1,128 @@
|
|||
package cn.iocoder.mall.managementweb.manager.admin;
|
||||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.mall.managementweb.controller.admin.dto.DepartmentCreateDTO;
|
||||
import cn.iocoder.mall.managementweb.controller.admin.dto.DepartmentUpdateDTO;
|
||||
import cn.iocoder.mall.managementweb.controller.admin.vo.DepartmentTreeNodeVO;
|
||||
import cn.iocoder.mall.managementweb.controller.admin.vo.DepartmentVO;
|
||||
import cn.iocoder.mall.managementweb.convert.admin.DepartmentConvert;
|
||||
import cn.iocoder.mall.systemservice.enums.admin.DepartmentIdEnum;
|
||||
import cn.iocoder.mall.systemservice.rpc.admin.DepartmentRpc;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.dubbo.config.annotation.Reference;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 部门 Manager
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class DepartmentManager {
|
||||
|
||||
@Reference(version = "${dubbo.consumer.DepartmentRpc.version}", validation = "false")
|
||||
private DepartmentRpc departmentRpc;
|
||||
|
||||
/**
|
||||
* 创建部门
|
||||
*
|
||||
* @param createDTO 创建部门 DTO
|
||||
* @return 部门
|
||||
*/
|
||||
public Integer createDepartment(DepartmentCreateDTO createDTO) {
|
||||
CommonResult<Integer> createDepartmentResult = departmentRpc.createDepartment(DepartmentConvert.INSTANCE.convert(createDTO));
|
||||
createDepartmentResult.checkError();
|
||||
return createDepartmentResult.getData();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新部门
|
||||
*
|
||||
* @param updateDTO 更新部门 DTO
|
||||
*/
|
||||
public void updateDepartment(DepartmentUpdateDTO updateDTO) {
|
||||
CommonResult<Boolean> updateDepartmentResult = departmentRpc.updateDepartment(DepartmentConvert.INSTANCE.convert(updateDTO));
|
||||
updateDepartmentResult.checkError();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除部门
|
||||
*
|
||||
* @param departmentId 部门编号
|
||||
*/
|
||||
public void deleteDepartment(Integer departmentId) {
|
||||
CommonResult<Boolean> deleteDepartmentResult = departmentRpc.deleteDepartment(departmentId);
|
||||
deleteDepartmentResult.checkError();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得部门
|
||||
*
|
||||
* @param departmentId 部门编号
|
||||
* @return 部门
|
||||
*/
|
||||
public DepartmentVO getDepartment(Integer departmentId) {
|
||||
CommonResult<cn.iocoder.mall.systemservice.rpc.admin.vo.DepartmentVO> getDepartmentResult = departmentRpc.getDepartment(departmentId);
|
||||
getDepartmentResult.checkError();
|
||||
return DepartmentConvert.INSTANCE.convert(getDepartmentResult.getData());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得部门列表
|
||||
*
|
||||
* @param departmentIds 部门编号列表
|
||||
* @return 部门列表
|
||||
*/
|
||||
public List<DepartmentVO> listDepartments(List<Integer> departmentIds) {
|
||||
CommonResult<List<cn.iocoder.mall.systemservice.rpc.admin.vo.DepartmentVO>> listDepartmentResult = departmentRpc.listDepartments(departmentIds);
|
||||
listDepartmentResult.checkError();
|
||||
return DepartmentConvert.INSTANCE.convertList(listDepartmentResult.getData());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得部门树结构
|
||||
*
|
||||
* @return 部门树结构
|
||||
*/
|
||||
public List<DepartmentTreeNodeVO> treeDepartment() {
|
||||
// 获得资源全列表
|
||||
CommonResult<List<cn.iocoder.mall.systemservice.rpc.admin.vo.DepartmentVO>> listDepartmentResult = departmentRpc.listDepartments();
|
||||
listDepartmentResult.checkError();
|
||||
// 构建菜单树
|
||||
return buildDepartmentTree(listDepartmentResult.getData());
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建部门树
|
||||
*
|
||||
* @param departmentVOs 部门列表
|
||||
* @return 部门树
|
||||
*/
|
||||
public static List<DepartmentTreeNodeVO> buildDepartmentTree(List<cn.iocoder.mall.systemservice.rpc.admin.vo.DepartmentVO> departmentVOs) {
|
||||
// 排序,保证菜单的有序性
|
||||
departmentVOs.sort(Comparator.comparing(cn.iocoder.mall.systemservice.rpc.admin.vo.DepartmentVO::getSort));
|
||||
// 构建菜单树
|
||||
// 使用 LinkedHashMap 的原因,是为了排序 。实际也可以用 Stream API ,就是太丑了。
|
||||
Map<Integer, DepartmentTreeNodeVO> treeNodeMap = new LinkedHashMap<>();
|
||||
departmentVOs.forEach(departmentVO -> treeNodeMap.put(departmentVO.getId(), DepartmentConvert.INSTANCE.convertTreeNode(departmentVO)));
|
||||
// 处理父子关系
|
||||
treeNodeMap.values().stream().filter(node -> !node.getPid().equals(DepartmentIdEnum.ROOT.getId())).forEach((childNode) -> {
|
||||
// 获得父节点
|
||||
DepartmentTreeNodeVO parentNode = treeNodeMap.get(childNode.getPid());
|
||||
if (parentNode == null) {
|
||||
log.error("[buildDepartmentTree][department({}) 找不到父部门({})]", childNode.getId(), childNode.getPid());
|
||||
return;
|
||||
}
|
||||
// 将自己添加到父节点中
|
||||
if (parentNode.getChildren() == null) {
|
||||
parentNode.setChildren(new ArrayList<>());
|
||||
}
|
||||
parentNode.getChildren().add(childNode);
|
||||
});
|
||||
// 获得到所有的根节点
|
||||
return treeNodeMap.values().stream().filter(node -> node.getPid().equals(DepartmentIdEnum.ROOT.getId())).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
|
@ -36,6 +36,8 @@ dubbo:
|
|||
version: 1.0.0
|
||||
PermissionRpc:
|
||||
version: 1.0.0
|
||||
DepartmentRpc:
|
||||
version: 1.0.0
|
||||
|
||||
# Swagger 配置项
|
||||
swagger:
|
||||
|
|
|
@ -62,11 +62,12 @@ public enum SystemErrorCodeEnum implements ServiceExceptionUtil.Enumerable<Syste
|
|||
SMS_NOT_SEND_CLIENT(1002006030, "短信没有发送的client"),
|
||||
|
||||
// ========== 部门模块 1002007000 ==========
|
||||
// DEPT_SAME_LEVEL_NAME_EXITS(1002007001,"当前级别部门名字已存在"),
|
||||
// DEPT_PARENT_NOT_EXITS(1002007002,"父级部门不存在"),
|
||||
// DEPT_NOT_EXITS(1002007003, "当前部门不存在"),
|
||||
// DEPT_EXITS_CHILDREN(1002007004, "当前部门存在子部门"),
|
||||
// DEPT_PARENT_NOT_LEGAL(1002007005, "父级部门不合法"),
|
||||
DEPARTMENT_NAME_DUPLICATE(1002007001, "已经存在该名字的部门"),
|
||||
DEPARTMENT_PARENT_NOT_EXITS(1002007002,"父级部门不存在"),
|
||||
DEPARTMENT_NOT_FOUND(1002007003, "当前部门不存在"),
|
||||
DEPARTMENT_EXITS_CHILDREN(1002007004, "存在子部门,无法删除"),
|
||||
DEPARTMENT_PARENT_ERROR(1002007005, "不能设置自己为父资源"),
|
||||
DEPARTMENT_EXISTS_ADMIN(1002007006, "部门中存在员工,无法删除"),
|
||||
|
||||
// ========== 授权模块 1002008000 ==========
|
||||
AUTHORIZATION_PERMISSION_DENY(1002008001, "没有该操作权限"),
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
package cn.iocoder.mall.systemservice.enums.admin;
|
||||
|
||||
/**
|
||||
* 部门的编号枚举
|
||||
*/
|
||||
public enum DepartmentIdEnum {
|
||||
|
||||
/**
|
||||
* 根节点
|
||||
*/
|
||||
ROOT(0);
|
||||
|
||||
private final Integer id;
|
||||
|
||||
DepartmentIdEnum(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
package cn.iocoder.mall.systemservice.rpc.admin;
|
||||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.mall.systemservice.rpc.admin.dto.DepartmentCreateDTO;
|
||||
import cn.iocoder.mall.systemservice.rpc.admin.dto.DepartmentUpdateDTO;
|
||||
import cn.iocoder.mall.systemservice.rpc.admin.vo.DepartmentVO;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 部门 Rpc 接口
|
||||
*/
|
||||
public interface DepartmentRpc {
|
||||
|
||||
/**
|
||||
* 创建部门
|
||||
*
|
||||
* @param createDTO 创建部门 DTO
|
||||
* @return 部门编号
|
||||
*/
|
||||
CommonResult<Integer> createDepartment(DepartmentCreateDTO createDTO);
|
||||
|
||||
/**
|
||||
* 更新部门
|
||||
*
|
||||
* @param updateDTO 更新部门 DTO
|
||||
*/
|
||||
CommonResult<Boolean> updateDepartment(DepartmentUpdateDTO updateDTO);
|
||||
|
||||
/**
|
||||
* 删除部门
|
||||
*
|
||||
* @param departmentId 部门编号
|
||||
*/
|
||||
CommonResult<Boolean> deleteDepartment(Integer departmentId);
|
||||
|
||||
/**
|
||||
* 获得部门
|
||||
*
|
||||
* @param departmentId 部门编号
|
||||
* @return 部门
|
||||
*/
|
||||
CommonResult<DepartmentVO> getDepartment(Integer departmentId);
|
||||
|
||||
/**
|
||||
* 获得部门列表
|
||||
*
|
||||
* @param departmentIds 部门编号列表
|
||||
* @return 部门列表
|
||||
*/
|
||||
CommonResult<List<DepartmentVO>> listDepartments(Collection<Integer> departmentIds);
|
||||
|
||||
/**
|
||||
* 获得部门全列表
|
||||
*
|
||||
* @return 资源列表
|
||||
*/
|
||||
CommonResult<List<DepartmentVO>> listDepartments();
|
||||
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package cn.iocoder.mall.systemservice.rpc.admin.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 部门创建 DTO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class DepartmentCreateDTO implements Serializable {
|
||||
|
||||
/**
|
||||
* 部门名称
|
||||
*/
|
||||
@NotEmpty(message = "部门名称不能为空")
|
||||
private String name;
|
||||
/**
|
||||
* 排序字段
|
||||
*/
|
||||
@NotNull(message = "排序字段不能为空")
|
||||
private Integer sort;
|
||||
/**
|
||||
* 父级部门编号
|
||||
*/
|
||||
@NotNull(message = "父级部门编号不能为空")
|
||||
private Integer pid;
|
||||
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package cn.iocoder.mall.systemservice.rpc.admin.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 部门更新 DTO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class DepartmentUpdateDTO implements Serializable {
|
||||
|
||||
/**
|
||||
* 部门编号
|
||||
*/
|
||||
@NotNull(message = "部门编号不能为空")
|
||||
private Integer id;
|
||||
/**
|
||||
* 部门名称
|
||||
*/
|
||||
@NotEmpty(message = "部门名称不能为空")
|
||||
private String name;
|
||||
/**
|
||||
* 排序字段
|
||||
*/
|
||||
@NotNull(message = "排序字段不能为空")
|
||||
private Integer sort;
|
||||
/**
|
||||
* 父级部门编号
|
||||
*/
|
||||
@NotNull(message = "父级部门编号不能为空")
|
||||
private Integer pid;
|
||||
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package cn.iocoder.mall.systemservice.rpc.admin.vo;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 部门 VO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class DepartmentVO implements Serializable {
|
||||
|
||||
/**
|
||||
* 部门编号
|
||||
*/
|
||||
private Integer id;
|
||||
/**
|
||||
* 部门名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 排序字段
|
||||
*/
|
||||
private Integer sort;
|
||||
/**
|
||||
* 父级部门编号
|
||||
*/
|
||||
private Integer pid;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
}
|
|
@ -5,6 +5,8 @@ import cn.iocoder.mall.systemservice.rpc.permission.dto.PermissionAssignAdminRol
|
|||
import cn.iocoder.mall.systemservice.rpc.permission.dto.PermissionAssignRoleResourceDTO;
|
||||
import cn.iocoder.mall.systemservice.rpc.permission.dto.PermissionCheckDTO;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
|
@ -36,6 +38,15 @@ public interface PermissionRpc {
|
|||
*/
|
||||
CommonResult<Set<Integer>> listAdminRoleIds(Integer adminId);
|
||||
|
||||
/**
|
||||
* 获得每个管理员拥有的角色编号
|
||||
* 返回的结果,key 为管理员编号
|
||||
*
|
||||
* @param adminIds 管理员编号列表
|
||||
* @return 每个管理员拥有的角色编号
|
||||
*/
|
||||
CommonResult<Map<Integer, Set<Integer>>> mapAdminRoleIds(Collection<Integer> adminIds);
|
||||
|
||||
/**
|
||||
* 赋予管理员角色
|
||||
*
|
||||
|
|
|
@ -7,6 +7,7 @@ import cn.iocoder.mall.systemservice.rpc.permission.dto.RoleUpdateDTO;
|
|||
import cn.iocoder.mall.systemservice.rpc.permission.vo.RoleCreateDTO;
|
||||
import cn.iocoder.mall.systemservice.rpc.permission.vo.RoleVO;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -58,7 +59,7 @@ public interface RoleRpc {
|
|||
* @param roleIds 角色编号列表
|
||||
* @return 角色列表
|
||||
*/
|
||||
CommonResult<List<RoleVO>> listRoles(List<Integer> roleIds);
|
||||
CommonResult<List<RoleVO>> listRoles(Collection<Integer> roleIds);
|
||||
|
||||
/**
|
||||
* 获得角色分页
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
package cn.iocoder.mall.systemservice.convert.admin;
|
||||
|
||||
import cn.iocoder.mall.systemservice.dal.mysql.dataobject.admin.DepartmentDO;
|
||||
import cn.iocoder.mall.systemservice.rpc.admin.dto.DepartmentCreateDTO;
|
||||
import cn.iocoder.mall.systemservice.rpc.admin.dto.DepartmentUpdateDTO;
|
||||
import cn.iocoder.mall.systemservice.rpc.admin.vo.DepartmentVO;
|
||||
import cn.iocoder.mall.systemservice.service.admin.bo.DepartmentBO;
|
||||
import cn.iocoder.mall.systemservice.service.admin.bo.DepartmentCreateBO;
|
||||
import cn.iocoder.mall.systemservice.service.admin.bo.DepartmentUpdateBO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface DepartmentConvert {
|
||||
|
||||
DepartmentConvert INSTANCE = Mappers.getMapper(DepartmentConvert.class);
|
||||
|
||||
DepartmentDO convert(DepartmentCreateBO bean);
|
||||
|
||||
DepartmentBO convert(DepartmentDO bean);
|
||||
|
||||
DepartmentDO convert(DepartmentUpdateBO bean);
|
||||
|
||||
DepartmentUpdateBO convert(DepartmentUpdateDTO bean);
|
||||
|
||||
DepartmentCreateBO convert(DepartmentCreateDTO bean);
|
||||
|
||||
DepartmentVO convert(DepartmentBO bean);
|
||||
|
||||
List<DepartmentBO> convertList(List<DepartmentDO> list);
|
||||
List<DepartmentVO> convertList02(List<DepartmentBO> list);
|
||||
|
||||
}
|
|
@ -18,6 +18,12 @@ public interface AdminMapper extends BaseMapper<AdminDO> {
|
|||
);
|
||||
}
|
||||
|
||||
default Integer selectCountByDepartmentId(Integer departmentId) {
|
||||
return selectCount(new QueryWrapper<AdminDO>()
|
||||
.eq("department_id", departmentId)
|
||||
);
|
||||
}
|
||||
|
||||
default IPage<AdminDO> selectPage(AdminPageBO pageBO) {
|
||||
return selectPage(new Page<>(pageBO.getPageNo(), pageBO.getPageSize()),
|
||||
new QueryWrapperX<AdminDO>().likeIfPresent("name", pageBO.getName())
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package cn.iocoder.mall.systemservice.dal.mysql.mapper.admin;
|
||||
|
||||
import cn.iocoder.mall.mybatis.query.QueryWrapperX;
|
||||
import cn.iocoder.mall.systemservice.dal.mysql.dataobject.admin.DepartmentDO;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface DepartmentMapper extends BaseMapper<DepartmentDO> {
|
||||
|
||||
default DepartmentDO selectByPidAndName(Integer pid, String name) {
|
||||
return selectOne(new QueryWrapperX<DepartmentDO>().eqIfPresent("pid", pid)
|
||||
.eqIfPresent("name", name));
|
||||
}
|
||||
|
||||
}
|
|
@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
|
@ -19,6 +20,10 @@ public interface AdminRoleMapper extends BaseMapper<AdminRoleDO> {
|
|||
return selectList(new QueryWrapper<AdminRoleDO>().eq("admin_id", adminId));
|
||||
}
|
||||
|
||||
default List<AdminRoleDO> selectListByAdminIds(Collection<Integer> adminIds) {
|
||||
return selectList(new QueryWrapper<AdminRoleDO>().in("admin_id", adminIds));
|
||||
}
|
||||
|
||||
default int deleteByAdminId(Integer adminId) {
|
||||
return delete(new QueryWrapper<AdminRoleDO>().eq("admin_id", adminId));
|
||||
}
|
||||
|
|
|
@ -0,0 +1,85 @@
|
|||
package cn.iocoder.mall.systemservice.manager.admin;
|
||||
|
||||
import cn.iocoder.mall.systemservice.convert.admin.DepartmentConvert;
|
||||
import cn.iocoder.mall.systemservice.rpc.admin.dto.DepartmentCreateDTO;
|
||||
import cn.iocoder.mall.systemservice.rpc.admin.dto.DepartmentUpdateDTO;
|
||||
import cn.iocoder.mall.systemservice.rpc.admin.vo.DepartmentVO;
|
||||
import cn.iocoder.mall.systemservice.service.admin.DepartmentService;
|
||||
import cn.iocoder.mall.systemservice.service.admin.bo.DepartmentBO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 部门 Manager
|
||||
*/
|
||||
@Service
|
||||
public class DepartmentManager {
|
||||
|
||||
@Autowired
|
||||
private DepartmentService departmentService;
|
||||
|
||||
/**
|
||||
* 创建部门
|
||||
*
|
||||
* @param createDTO 创建部门 DTO
|
||||
* @return 部门
|
||||
*/
|
||||
public Integer createDepartment(DepartmentCreateDTO createDTO) {
|
||||
DepartmentBO departmentBO = departmentService.createDepartment(DepartmentConvert.INSTANCE.convert(createDTO));
|
||||
return departmentBO.getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新部门
|
||||
*
|
||||
* @param updateDTO 更新部门 DTO
|
||||
*/
|
||||
public void updateDepartment(DepartmentUpdateDTO updateDTO) {
|
||||
departmentService.updateDepartment(DepartmentConvert.INSTANCE.convert(updateDTO));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除部门
|
||||
*
|
||||
* @param departmentId 部门编号
|
||||
*/
|
||||
public void deleteDepartment(Integer departmentId) {
|
||||
departmentService.deleteDepartment(departmentId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得部门
|
||||
*
|
||||
* @param departmentId 部门编号
|
||||
* @return 部门
|
||||
*/
|
||||
public DepartmentVO getDepartment(Integer departmentId) {
|
||||
DepartmentBO departmentBO = departmentService.getDepartment(departmentId);
|
||||
return DepartmentConvert.INSTANCE.convert(departmentBO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得部门列表
|
||||
*
|
||||
* @param departmentIds 部门编号列表
|
||||
* @return 部门列表
|
||||
*/
|
||||
public List<DepartmentVO> listDepartments(Collection<Integer> departmentIds) {
|
||||
List<DepartmentBO> departmentBOs = departmentService.listDepartments(departmentIds);
|
||||
return DepartmentConvert.INSTANCE.convertList02(departmentBOs);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得部门全列表
|
||||
*
|
||||
* @return 资源列表
|
||||
*/
|
||||
public List<DepartmentVO> listDepartments() {
|
||||
List<DepartmentBO> departmentBOs = departmentService.listDepartments();
|
||||
return DepartmentConvert.INSTANCE.convertList02(departmentBOs);
|
||||
}
|
||||
|
||||
}
|
|
@ -13,7 +13,9 @@ import cn.iocoder.mall.systemservice.service.permission.bo.ResourceBO;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static cn.iocoder.mall.systemservice.enums.SystemErrorCodeEnum.AUTHORIZATION_PERMISSION_DENY;
|
||||
|
@ -65,6 +67,17 @@ public class PermissionManager {
|
|||
return permissionService.listAdminRoleIds(adminId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得每个管理员拥有的角色编号
|
||||
* 返回的结果,key 为管理员编号
|
||||
*
|
||||
* @param adminIds 管理员编号列表
|
||||
* @return 每个管理员拥有的角色编号
|
||||
*/
|
||||
public Map<Integer, Set<Integer>> mapAdminRoleIds(Collection<Integer> adminIds) {
|
||||
return permissionService.mapAdminRoleIds(adminIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 赋予管理员角色
|
||||
*
|
||||
|
|
|
@ -11,6 +11,7 @@ import cn.iocoder.mall.systemservice.service.permission.bo.RoleBO;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -79,7 +80,7 @@ public class RoleManager {
|
|||
* @param roleIds 角色编号列表
|
||||
* @return 角色列表
|
||||
*/
|
||||
public List<RoleVO> listRoles(List<Integer> roleIds) {
|
||||
public List<RoleVO> listRoles(Collection<Integer> roleIds) {
|
||||
List<RoleBO> roleBOs = roleService.listRole(roleIds);
|
||||
return RoleConvert.INSTANCE.convertList02(roleBOs);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
package cn.iocoder.mall.systemservice.rpc.admin;
|
||||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.mall.systemservice.manager.admin.DepartmentManager;
|
||||
import cn.iocoder.mall.systemservice.rpc.admin.dto.DepartmentCreateDTO;
|
||||
import cn.iocoder.mall.systemservice.rpc.admin.dto.DepartmentUpdateDTO;
|
||||
import cn.iocoder.mall.systemservice.rpc.admin.vo.DepartmentVO;
|
||||
import org.apache.dubbo.config.annotation.Service;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.common.framework.vo.CommonResult.success;
|
||||
|
||||
/**
|
||||
* 部门 Rpc 实现类
|
||||
*/
|
||||
@Service(version = "${dubbo.provider.DepartmentRpc.version}", validation = "false")
|
||||
public class DepartmentRpcImpl implements DepartmentRpc {
|
||||
|
||||
@Autowired
|
||||
private DepartmentManager departmentManager;
|
||||
|
||||
@Override
|
||||
public CommonResult<Integer> createDepartment(DepartmentCreateDTO createDTO) {
|
||||
return success(departmentManager.createDepartment(createDTO));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<Boolean> updateDepartment(DepartmentUpdateDTO updateDTO) {
|
||||
departmentManager.updateDepartment(updateDTO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<Boolean> deleteDepartment(Integer departmentId) {
|
||||
departmentManager.deleteDepartment(departmentId);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<DepartmentVO> getDepartment(Integer departmentId) {
|
||||
return success(departmentManager.getDepartment(departmentId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<List<DepartmentVO>> listDepartments(Collection<Integer> departmentIds) {
|
||||
return success(departmentManager.listDepartments(departmentIds));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<List<DepartmentVO>> listDepartments() {
|
||||
return success(departmentManager.listDepartments());
|
||||
}
|
||||
|
||||
}
|
|
@ -8,6 +8,8 @@ import cn.iocoder.mall.systemservice.rpc.permission.dto.PermissionCheckDTO;
|
|||
import org.apache.dubbo.config.annotation.Service;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static cn.iocoder.common.framework.vo.CommonResult.success;
|
||||
|
@ -37,6 +39,11 @@ public class PermissionRpcImpl implements PermissionRpc {
|
|||
return success(permissionManager.listAdminRoleIds(adminId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<Map<Integer, Set<Integer>>> mapAdminRoleIds(Collection<Integer> adminIds) {
|
||||
return success(permissionManager.mapAdminRoleIds(adminIds));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<Boolean> assignAdminRole(PermissionAssignAdminRoleDTO assignAdminRoleDTO) {
|
||||
permissionManager.assignAdminRole(assignAdminRoleDTO);
|
||||
|
|
|
@ -10,6 +10,7 @@ import cn.iocoder.mall.systemservice.rpc.permission.vo.RoleVO;
|
|||
import org.apache.dubbo.config.annotation.Service;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -52,7 +53,7 @@ public class RoleRpcImpl implements RoleRpc {
|
|||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<List<RoleVO>> listRoles(List<Integer> roleIds) {
|
||||
public CommonResult<List<RoleVO>> listRoles(Collection<Integer> roleIds) {
|
||||
return success(roleManager.listRoles(roleIds));
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,168 @@
|
|||
package cn.iocoder.mall.systemservice.service.admin;
|
||||
|
||||
import cn.iocoder.common.framework.util.ServiceExceptionUtil;
|
||||
import cn.iocoder.mall.systemservice.convert.admin.DepartmentConvert;
|
||||
import cn.iocoder.mall.systemservice.dal.mysql.dataobject.admin.DepartmentDO;
|
||||
import cn.iocoder.mall.systemservice.dal.mysql.mapper.admin.AdminMapper;
|
||||
import cn.iocoder.mall.systemservice.dal.mysql.mapper.admin.DepartmentMapper;
|
||||
import cn.iocoder.mall.systemservice.enums.admin.DepartmentIdEnum;
|
||||
import cn.iocoder.mall.systemservice.service.admin.bo.DepartmentBO;
|
||||
import cn.iocoder.mall.systemservice.service.admin.bo.DepartmentCreateBO;
|
||||
import cn.iocoder.mall.systemservice.service.admin.bo.DepartmentUpdateBO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.mall.systemservice.enums.SystemErrorCodeEnum.*;
|
||||
|
||||
/**
|
||||
* 部门 Service
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class DepartmentService {
|
||||
|
||||
@Autowired
|
||||
private DepartmentMapper departmentMapper;
|
||||
@Autowired
|
||||
private AdminMapper adminMapper;
|
||||
|
||||
/**
|
||||
* 创建部门
|
||||
*
|
||||
* @param createBO 创建部门 BO
|
||||
* @return 部门
|
||||
*/
|
||||
public DepartmentBO createDepartment(@Valid DepartmentCreateBO createBO) {
|
||||
// 校验父部门存在
|
||||
checkParentDepartment(createBO.getPid(), null);
|
||||
// 校验部门(自己)
|
||||
checkDepartment(createBO.getPid(), createBO.getName(), null);
|
||||
// 插入到数据库
|
||||
DepartmentDO departmentDO = DepartmentConvert.INSTANCE.convert(createBO);
|
||||
departmentMapper.insert(departmentDO);
|
||||
// 返回
|
||||
return DepartmentConvert.INSTANCE.convert(departmentDO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新部门
|
||||
*
|
||||
* @param updateBO 更新部门 BO
|
||||
*/
|
||||
public void updateDepartment(@Valid DepartmentUpdateBO updateBO) {
|
||||
// 校验更新的部门是否存在
|
||||
if (departmentMapper.selectById(updateBO.getId()) == null) {
|
||||
throw ServiceExceptionUtil.exception(DEPARTMENT_NOT_FOUND);
|
||||
}
|
||||
// 校验父部门存在
|
||||
checkParentDepartment(updateBO.getPid(), updateBO.getId());
|
||||
// 校验部门(自己)
|
||||
checkDepartment(updateBO.getPid(), updateBO.getName(), updateBO.getId());
|
||||
// 更新到数据库
|
||||
DepartmentDO updateObject = DepartmentConvert.INSTANCE.convert(updateBO);
|
||||
departmentMapper.updateById(updateObject);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除部门
|
||||
*
|
||||
* @param departmentId 部门编号
|
||||
*/
|
||||
public void deleteDepartment(Integer departmentId) {
|
||||
// 校验删除的部门是否存在
|
||||
if (departmentMapper.selectById(departmentId) == null) {
|
||||
throw ServiceExceptionUtil.exception(DEPARTMENT_NOT_FOUND);
|
||||
}
|
||||
// 校验部门里没管理员
|
||||
if (adminMapper.selectCountByDepartmentId(departmentId) > 0) {
|
||||
throw ServiceExceptionUtil.exception(DEPARTMENT_NOT_FOUND);
|
||||
}
|
||||
// 标记删除
|
||||
departmentMapper.deleteById(departmentId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得部门
|
||||
*
|
||||
* @param departmentId 部门编号
|
||||
* @return 部门
|
||||
*/
|
||||
public DepartmentBO getDepartment(Integer departmentId) {
|
||||
DepartmentDO departmentDO = departmentMapper.selectById(departmentId);
|
||||
return DepartmentConvert.INSTANCE.convert(departmentDO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得部门列表
|
||||
*
|
||||
* @param departmentIds 部门编号列表
|
||||
* @return 部门列表
|
||||
*/
|
||||
public List<DepartmentBO> listDepartments(Collection<Integer> departmentIds) {
|
||||
List<DepartmentDO> departmentDOs = departmentMapper.selectBatchIds(departmentIds);
|
||||
return DepartmentConvert.INSTANCE.convertList(departmentDOs);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得部门全列表
|
||||
*
|
||||
* @return 资源列表
|
||||
*/
|
||||
public List<DepartmentBO> listDepartments() {
|
||||
List<DepartmentDO> departmentDOs = departmentMapper.selectList(null);
|
||||
return DepartmentConvert.INSTANCE.convertList(departmentDOs);
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验父部门是否合法
|
||||
*
|
||||
* 1. 不能设置自己为父部门
|
||||
* 2. 父部门不存在
|
||||
*
|
||||
* @param pid 父部门编号
|
||||
* @param childId 当前部门编号
|
||||
*/
|
||||
private void checkParentDepartment(Integer pid, Integer childId) {
|
||||
if (pid == null || DepartmentIdEnum.ROOT.getId().equals(pid)) {
|
||||
return;
|
||||
}
|
||||
// 不能设置自己为父部门
|
||||
if (pid.equals(childId)) {
|
||||
throw ServiceExceptionUtil.exception(DEPARTMENT_PARENT_ERROR);
|
||||
}
|
||||
DepartmentDO resource = departmentMapper.selectById(pid);
|
||||
// 父部门不存在
|
||||
if (resource == null) {
|
||||
throw ServiceExceptionUtil.exception(DEPARTMENT_PARENT_NOT_EXITS);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验部门是否合法
|
||||
*
|
||||
* 1. 校验相同父部门编号下,是否存在相同的部门名
|
||||
*
|
||||
* @param name 部门名字
|
||||
* @param pid 父部门编号
|
||||
* @param id 部门编号
|
||||
*/
|
||||
private void checkDepartment(Integer pid, String name, Integer id) {
|
||||
DepartmentDO resource = departmentMapper.selectByPidAndName(pid, name);
|
||||
if (resource == null) {
|
||||
return;
|
||||
}
|
||||
// 如果 id 为空,说明不用比较是否为相同 id 的部门
|
||||
if (id == null) {
|
||||
throw ServiceExceptionUtil.exception(DEPARTMENT_NAME_DUPLICATE);
|
||||
}
|
||||
if (!resource.getId().equals(id)) {
|
||||
throw ServiceExceptionUtil.exception(DEPARTMENT_NAME_DUPLICATE);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package cn.iocoder.mall.systemservice.service.admin.bo;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 部门 BO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class DepartmentBO {
|
||||
|
||||
/**
|
||||
* 部门编号
|
||||
*/
|
||||
private Integer id;
|
||||
/**
|
||||
* 部门名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 排序字段
|
||||
*/
|
||||
private Integer sort;
|
||||
/**
|
||||
* 父级部门编号
|
||||
*/
|
||||
private Integer pid;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private Date updateTime;
|
||||
/**
|
||||
* 删除标记
|
||||
*/
|
||||
private Integer deleted;
|
||||
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package cn.iocoder.mall.systemservice.service.admin.bo;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* 部门创建 BO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class DepartmentCreateBO {
|
||||
|
||||
/**
|
||||
* 部门名称
|
||||
*/
|
||||
@NotEmpty(message = "部门名称不能为空")
|
||||
private String name;
|
||||
/**
|
||||
* 排序字段
|
||||
*/
|
||||
@NotNull(message = "排序字段不能为空")
|
||||
private Integer sort;
|
||||
/**
|
||||
* 父级部门编号
|
||||
*/
|
||||
@NotNull(message = "父级部门编号不能为空")
|
||||
private Integer pid;
|
||||
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package cn.iocoder.mall.systemservice.service.admin.bo;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* 部门更新 BO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class DepartmentUpdateBO {
|
||||
|
||||
/**
|
||||
* 部门编号
|
||||
*/
|
||||
@NotNull(message = "部门编号不能为空")
|
||||
private Integer id;
|
||||
/**
|
||||
* 部门名称
|
||||
*/
|
||||
@NotEmpty(message = "部门名称不能为空")
|
||||
private String name;
|
||||
/**
|
||||
* 排序字段
|
||||
*/
|
||||
@NotNull(message = "排序字段不能为空")
|
||||
private Integer sort;
|
||||
/**
|
||||
* 父级部门编号
|
||||
*/
|
||||
@NotNull(message = "父级部门编号不能为空")
|
||||
private Integer pid;
|
||||
|
||||
}
|
|
@ -18,10 +18,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static cn.iocoder.mall.systemservice.enums.SystemErrorCodeEnum.*;
|
||||
|
@ -127,6 +124,21 @@ public class PermissionService {
|
|||
return CollectionUtils.convertSet(adminRoleDOs, AdminRoleDO::getRoleId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得每个管理员拥有的角色编号
|
||||
* 返回的结果,key 为管理员编号
|
||||
*
|
||||
* @param adminIds 管理员编号列表
|
||||
* @return 每个管理员拥有的角色编号
|
||||
*/
|
||||
public Map<Integer, Set<Integer>> mapAdminRoleIds(Collection<Integer> adminIds) {
|
||||
List<AdminRoleDO> adminRoleDOs = adminRoleMapper.selectListByAdminIds(adminIds);
|
||||
if (CollectionUtils.isEmpty(adminRoleDOs)) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
return CollectionUtils.convertMultiMap2(adminRoleDOs, AdminRoleDO::getAdminId, AdminRoleDO::getRoleId);
|
||||
}
|
||||
|
||||
public void checkPermission(Collection<Integer> roleIds, Collection<String> permissions) {
|
||||
// 查询权限对应资源
|
||||
List<ResourceDO> resourceBOs = resourceMapper.selectListByPermissions(permissions);
|
||||
|
|
|
@ -95,6 +95,8 @@ public class ResourceService {
|
|||
}
|
||||
// 标记删除
|
||||
resourceMapper.deleteById(resourceId);
|
||||
// 删除授予给角色的权限
|
||||
roleResourceMapper.deleteByResourceId(resourceId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -160,7 +162,7 @@ public class ResourceService {
|
|||
/**
|
||||
* 校验父资源是否合法
|
||||
*
|
||||
* 1. 不能舌质红自己为父资源
|
||||
* 1. 不能设置自己为父资源
|
||||
* 2. 父资源不存在
|
||||
* 3. 父资源必须是 {@link ResourceTypeEnum#MENU} 菜单类型
|
||||
*
|
||||
|
|
|
@ -8,6 +8,7 @@ import cn.iocoder.mall.systemservice.dal.mysql.dataobject.permission.AdminRoleDO
|
|||
import cn.iocoder.mall.systemservice.dal.mysql.dataobject.permission.RoleDO;
|
||||
import cn.iocoder.mall.systemservice.dal.mysql.mapper.permission.AdminRoleMapper;
|
||||
import cn.iocoder.mall.systemservice.dal.mysql.mapper.permission.RoleMapper;
|
||||
import cn.iocoder.mall.systemservice.dal.mysql.mapper.permission.RoleResourceMapper;
|
||||
import cn.iocoder.mall.systemservice.enums.permission.RoleCodeEnum;
|
||||
import cn.iocoder.mall.systemservice.enums.permission.RoleTypeEnum;
|
||||
import cn.iocoder.mall.systemservice.service.permission.bo.RoleBO;
|
||||
|
@ -38,6 +39,8 @@ public class RoleService {
|
|||
private RoleMapper roleMapper;
|
||||
@Autowired
|
||||
private AdminRoleMapper adminRoleMapper;
|
||||
@Autowired
|
||||
private RoleResourceMapper roleResourceMapper;
|
||||
|
||||
/**
|
||||
* 创建角色
|
||||
|
@ -95,8 +98,10 @@ public class RoleService {
|
|||
}
|
||||
// 标记删除
|
||||
roleMapper.deleteById(roleId);
|
||||
// // 发布角色删除事件,方便清理关联表 TODO 芋艿,需要实现
|
||||
// eventPublisher.publishEvent(new ResourceDeleteEvent(this, roleDeleteDTO.getId()));
|
||||
// 标记删除 RoleResource
|
||||
roleResourceMapper.deleteByRoleId(roleId);
|
||||
// 标记删除 AdminRole
|
||||
adminRoleMapper.deleteByRoleId(roleId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -126,7 +131,7 @@ public class RoleService {
|
|||
* @param roleIds 角色编号列表
|
||||
* @return 角色列表
|
||||
*/
|
||||
public List<RoleBO> listRole(List<Integer> roleIds) {
|
||||
public List<RoleBO> listRole(Collection<Integer> roleIds) {
|
||||
List<RoleDO> roleDOs = roleMapper.selectBatchIds(roleIds);
|
||||
return RoleConvert.INSTANCE.convertList(roleDOs);
|
||||
}
|
||||
|
|
|
@ -45,3 +45,5 @@ dubbo:
|
|||
version: 1.0.0
|
||||
PermissionRpc:
|
||||
version: 1.0.0
|
||||
DepartmentRpc:
|
||||
version: 1.0.0
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
package cn.iocoder.mall.system.biz.service.authorization;
|
||||
|
||||
import cn.iocoder.mall.system.biz.dto.authorization.AuthorizationCheckPermissionsDTO;
|
||||
|
||||
/**
|
||||
* 授权模块 - Service 接口
|
||||
*/
|
||||
public interface AuthorizationService {
|
||||
|
||||
/**
|
||||
* 校验指定账号是否有指定权限。如果没有,则抛出 {@link ServiceException} 异常
|
||||
*
|
||||
* @param checkPermissionsDTO 校验权限 DTO
|
||||
*/
|
||||
void checkPermissions(AuthorizationCheckPermissionsDTO checkPermissionsDTO);
|
||||
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
package cn.iocoder.mall.system.biz.service.authorization;
|
||||
|
||||
import cn.iocoder.common.framework.util.CollectionUtil;
|
||||
import cn.iocoder.common.framework.util.ServiceExceptionUtil;
|
||||
import cn.iocoder.mall.mybatis.enums.DeletedStatusEnum;
|
||||
import cn.iocoder.mall.system.biz.bo.authorization.ResourceBO;
|
||||
import cn.iocoder.mall.system.biz.bo.authorization.ResourceTreeNodeBO;
|
||||
import cn.iocoder.mall.system.biz.bo.authorization.RoleBO;
|
||||
import cn.iocoder.mall.system.biz.dao.authorization.AccountRoleMapper;
|
||||
import cn.iocoder.mall.system.biz.dao.authorization.RoleResourceMapper;
|
||||
import cn.iocoder.mall.system.biz.dataobject.authorization.AccountRoleDO;
|
||||
import cn.iocoder.mall.system.biz.dataobject.authorization.RoleResourceDO;
|
||||
import cn.iocoder.mall.system.biz.dto.authorization.*;
|
||||
import cn.iocoder.mall.system.biz.enums.SystemErrorCodeEnum;
|
||||
import cn.iocoder.mall.system.biz.event.authorization.ResourceDeleteEvent;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static cn.iocoder.mall.system.biz.enums.SystemErrorCodeEnum.AUTHORIZATION_PERMISSION_DENY;
|
||||
|
||||
/**
|
||||
* 授权模块 - Service 实现类
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class AuthorizationServiceImpl implements AuthorizationService {
|
||||
|
||||
|
||||
@EventListener
|
||||
public void handleResourceDeleteEvent(ResourceDeleteEvent event) {
|
||||
roleResourceMapper.deleteByResourceId(event.getId());
|
||||
}
|
||||
|
||||
@EventListener
|
||||
public void handleRoleDeleteEvent(ResourceDeleteEvent event) {
|
||||
// 标记删除 RoleResource
|
||||
roleResourceMapper.deleteByRoleId(event.getId());
|
||||
// 标记删除 AdminRole
|
||||
accountRoleMapper.deleteByRoleId(event.getId());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
package cn.iocoder.mall.admin.convert;
|
||||
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.system.api.bo.admin.AdminAuthenticationBO;
|
||||
import cn.iocoder.mall.system.api.bo.admin.AdminBO;
|
||||
import cn.iocoder.mall.system.api.dto.admin.AdminAddDTO;
|
||||
import cn.iocoder.mall.system.api.dto.admin.AdminUpdateDTO;
|
||||
import cn.iocoder.mall.admin.dataobject.AdminDO;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
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({})
|
||||
AdminAuthenticationBO convert2(AdminDO admin);
|
||||
|
||||
@Mappings({})
|
||||
AdminDO convert(AdminAddDTO adminAddDTO);
|
||||
|
||||
@Mappings({})
|
||||
AdminDO convert(AdminUpdateDTO adminUpdateDTO);
|
||||
|
||||
@Mappings({})
|
||||
List<AdminBO> convert(List<AdminDO> adminBOs);
|
||||
|
||||
@Mappings({
|
||||
@Mapping(source = "records", target = "list"),
|
||||
})
|
||||
PageResult<AdminBO> convert(IPage<AdminDO> page);
|
||||
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
package cn.iocoder.mall.admin.convert;
|
||||
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.system.api.bo.deptment.DeptmentBO;
|
||||
import cn.iocoder.mall.system.api.dto.depetment.DeptmentAddDTO;
|
||||
import cn.iocoder.mall.system.api.dto.depetment.DeptmentUpdateDTO;
|
||||
import cn.iocoder.mall.admin.dataobject.DeptmentDO;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.Mappings;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
*
|
||||
* @author: zhenxianyimeng
|
||||
* @date: 2019-06-14
|
||||
* @time: 20:06
|
||||
*/
|
||||
@Mapper
|
||||
public interface DeptmentConvert {
|
||||
|
||||
DeptmentConvert INSTANCE = Mappers.getMapper(DeptmentConvert.class);
|
||||
|
||||
@Mappings({})
|
||||
DeptmentDO convert(DeptmentAddDTO deptmentAddDTO);
|
||||
|
||||
@Mappings({})
|
||||
DeptmentBO convert(DeptmentDO deptmentDO);
|
||||
|
||||
@Mappings({@Mapping(source = "records", target = "list")})
|
||||
PageResult<DeptmentBO> convert(IPage<DeptmentDO> list);
|
||||
|
||||
@Mappings({})
|
||||
List<DeptmentBO> convert(List<DeptmentDO> list);
|
||||
|
||||
@Mappings({})
|
||||
DeptmentDO convert(DeptmentUpdateDTO deptmentUpdateDTO);
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
package cn.iocoder.mall.admin.convert;
|
||||
|
||||
import cn.iocoder.common.framework.util.StringUtil;
|
||||
import cn.iocoder.mall.system.api.bo.resource.ResourceBO;
|
||||
import cn.iocoder.mall.system.api.dto.resource.ResourceAddDTO;
|
||||
import cn.iocoder.mall.system.api.dto.resource.ResourceUpdateDTO;
|
||||
import cn.iocoder.mall.admin.dataobject.ResourceDO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.Mappings;
|
||||
import org.mapstruct.Named;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface ResourceConvert {
|
||||
|
||||
ResourceConvert INSTANCE = Mappers.getMapper(ResourceConvert.class);
|
||||
|
||||
@Mappings({
|
||||
@Mapping(source = "permissions", target = "permissions", qualifiedByName = "translateListFromString")
|
||||
})
|
||||
ResourceBO convert(ResourceDO resourceDO);
|
||||
|
||||
@Mappings({})
|
||||
List<ResourceBO> convert(List<ResourceDO> resourceDOs);
|
||||
|
||||
@Mappings({
|
||||
@Mapping(source = "permissions", target = "permissions", qualifiedByName = "translateStringFromList")
|
||||
})
|
||||
ResourceDO convert(ResourceAddDTO resourceAddDTO);
|
||||
|
||||
@Mappings({
|
||||
@Mapping(source = "permissions", target = "permissions", qualifiedByName = "translateStringFromList")
|
||||
})
|
||||
ResourceDO convert(ResourceUpdateDTO resourceUpdateDTO);
|
||||
|
||||
@Named("translateListFromString")
|
||||
default List<String> translateListFromString(String str) {
|
||||
return StringUtil.split(str, ",");
|
||||
}
|
||||
|
||||
@Named("translateStringFromList")
|
||||
default String translateStringFromList(List<String> list) {
|
||||
return StringUtil.join(list, ",");
|
||||
}
|
||||
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
package cn.iocoder.mall.admin.convert;
|
||||
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.system.api.bo.role.RoleBO;
|
||||
import cn.iocoder.mall.system.api.dto.role.RoleAddDTO;
|
||||
import cn.iocoder.mall.system.api.dto.role.RoleUpdateDTO;
|
||||
import cn.iocoder.mall.admin.dataobject.RoleDO;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.Mappings;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface RoleConvert {
|
||||
|
||||
RoleConvert INSTANCE = Mappers.getMapper(RoleConvert.class);
|
||||
|
||||
@Mappings({})
|
||||
RoleDO convert(RoleAddDTO roleAddDTO);
|
||||
|
||||
@Mappings({})
|
||||
RoleDO convert(RoleUpdateDTO roleUpdateDTO);
|
||||
|
||||
@Mappings({})
|
||||
RoleBO convert(RoleDO roleDO);
|
||||
|
||||
@Mappings({})
|
||||
List<RoleBO> convert(List<RoleDO> roleDOs);
|
||||
|
||||
@Mappings({
|
||||
@Mapping(source = "records", target = "list"),
|
||||
})
|
||||
PageResult<RoleBO> convert(IPage<RoleDO> page);
|
||||
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
package cn.iocoder.mall.admin.dataobject;
|
||||
|
||||
import cn.iocoder.common.framework.dataobject.DeletableDO;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* Description:部门实体
|
||||
*
|
||||
* @author: zhenxianyimeng
|
||||
* @date: 2019-06-14
|
||||
* @time: 19:12
|
||||
*/
|
||||
@TableName("deptment")
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class DeptmentDO extends DeletableDO {
|
||||
|
||||
/**
|
||||
* 部门编号
|
||||
*/
|
||||
private Integer id;
|
||||
/**
|
||||
* 部门名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 部门排序字段
|
||||
*/
|
||||
private Integer sort;
|
||||
/**
|
||||
* 父级部门id
|
||||
*/
|
||||
private Integer pid;
|
||||
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
package cn.iocoder.mall.admin.dataobject;
|
||||
|
||||
import cn.iocoder.common.framework.dataobject.DeletableDO;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* Description: 部门-角色映射表
|
||||
*
|
||||
* @author: zhenxianyimeng
|
||||
* @date: 2019-06-14
|
||||
* @time: 19:19
|
||||
*/
|
||||
@TableName("deptment_role")
|
||||
@Data
|
||||
public class DeptmentRoleDO extends DeletableDO {
|
||||
/**
|
||||
* 主键id
|
||||
*/
|
||||
private Integer id;
|
||||
/**
|
||||
* 部门id
|
||||
*/
|
||||
private Integer deptmentId;
|
||||
/**
|
||||
* 角色id
|
||||
*/
|
||||
private Integer roleId;
|
||||
}
|
Loading…
Reference in New Issue