新增角色管理查询接口
This commit is contained in:
parent
1784ff0239
commit
ddd5c2a4e2
@ -68,6 +68,7 @@ public class PermissionsController {
|
||||
* 查询所有。
|
||||
*
|
||||
* @return 所有数据
|
||||
* @return 所有数据
|
||||
*/
|
||||
@GetMapping("list")
|
||||
public JsonResult<?> list() {
|
||||
|
||||
@ -1,19 +1,32 @@
|
||||
package com.cdzy.user.controller;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.cdzy.common.model.JsonResult;
|
||||
import com.cdzy.common.model.PageParam;
|
||||
import com.cdzy.common.model.StaffDto;
|
||||
import com.cdzy.user.model.dto.PageParamDto;
|
||||
import com.cdzy.user.model.dto.ResRolesDto;
|
||||
import com.cdzy.user.model.entity.Roles;
|
||||
import com.cdzy.user.service.PermissionsService;
|
||||
import com.cdzy.user.service.RolesService;
|
||||
import com.cdzy.user.service.StaffService;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.query.QueryColumn;
|
||||
import com.mybatisflex.core.query.QueryMethods;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.cdzy.user.model.entity.table.OrganizationsTableDef.ORGANIZATIONS;
|
||||
import static com.cdzy.user.model.entity.table.PermissionsTableDef.PERMISSIONS;
|
||||
import static com.cdzy.user.model.entity.table.RolePermissionsTableDef.ROLE_PERMISSIONS;
|
||||
import static com.cdzy.user.model.entity.table.RolesTableDef.ROLES;
|
||||
import static com.cdzy.user.model.entity.table.StaffRolesTableDef.STAFF_ROLES;
|
||||
import static com.cdzy.user.model.entity.table.StaffTableDef.STAFF;
|
||||
|
||||
/**
|
||||
* 角色控制层。
|
||||
@ -28,6 +41,11 @@ public class RolesController {
|
||||
@Resource
|
||||
private RolesService rolesService;
|
||||
|
||||
@Autowired
|
||||
private PermissionsService permissionsService;
|
||||
@Resource
|
||||
private StaffService staffService;
|
||||
|
||||
/**
|
||||
* 添加。
|
||||
*
|
||||
@ -93,7 +111,7 @@ public class RolesController {
|
||||
* @param pageParam 分页对象
|
||||
* @return 分页对象
|
||||
*/
|
||||
@GetMapping("page")
|
||||
@PostMapping("page")
|
||||
public JsonResult<?> page(@Validated PageParam pageParam) {
|
||||
Page<Roles> page = rolesService.page(pageParam.getPage());
|
||||
return JsonResult.success(page);
|
||||
@ -114,4 +132,58 @@ public class RolesController {
|
||||
return JsonResult.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询角色列表
|
||||
*
|
||||
* @param pageParam
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("pageQueryRoles")
|
||||
public JsonResult<?> pageQueryRoles(@RequestBody @Validated PageParamDto pageParam) {
|
||||
|
||||
String tokenValue = StpUtil.getTokenValue();
|
||||
Object loginId = StpUtil.getLoginIdByToken(tokenValue);
|
||||
QueryWrapper queryStaff = QueryWrapper.create()
|
||||
.where(STAFF.STAFF_ID.eq(loginId));
|
||||
StaffDto staff = staffService.getOneAs(queryStaff, StaffDto.class);
|
||||
|
||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||
.from(STAFF)
|
||||
.select(STAFF.STAFF_ID, ROLES.ALL_COLUMNS, ORGANIZATIONS.ORG_NAME)
|
||||
.innerJoin(STAFF_ROLES).on(STAFF_ROLES.STAFF_ID.eq(STAFF.STAFF_ID))
|
||||
.innerJoin(ORGANIZATIONS).on(STAFF.ORG_ID.eq(ORGANIZATIONS.ORG_ID))
|
||||
.innerJoin(ROLES).on(STAFF_ROLES.ROLE_ID.eq(ROLES.ROLE_ID))
|
||||
.where(STAFF.ORG_ID.eq(staff.getOrgId()));
|
||||
|
||||
QueryWrapper countQuery = QueryWrapper.create()
|
||||
.select(QueryMethods.count(STAFF.STAFF_ID.getName()).as("staff_count"))
|
||||
.select(ROLES.ROLE_NAME.getName(), ROLES.ROLE_ID.getName(),
|
||||
ROLES.ROLE_DESCRIPTION.getName(), ROLES.ROLE_CODE.getName(),
|
||||
ORGANIZATIONS.ORG_NAME.getName())
|
||||
.groupBy(ORGANIZATIONS.ORG_NAME, ROLES.ROLE_NAME)
|
||||
.from(queryWrapper).as("a");
|
||||
|
||||
Page<ResRolesDto> page = Page.of(pageParam.getPage().getPageNumber(), pageParam.getPageSize());
|
||||
Page<ResRolesDto> resRolesDtoPage = rolesService.pageAs(page, countQuery, ResRolesDto.class);
|
||||
List<ResRolesDto> records = resRolesDtoPage.getRecords();
|
||||
//统计pc权限数量和小程序权限数量
|
||||
for (ResRolesDto record : records) {
|
||||
QueryWrapper caseQuery = QueryWrapper.create()
|
||||
.select(QueryMethods.sum(QueryMethods.case_()
|
||||
.when(PERMISSIONS.PERM_TYPE.eq(1)).then(1)
|
||||
.else_(0).end()).as("web_count"),
|
||||
QueryMethods.sum(QueryMethods.case_()
|
||||
.when(PERMISSIONS.PERM_TYPE.eq(2)).then(1)
|
||||
.else_(0).end()).as("applet_count"))
|
||||
.innerJoin(ROLE_PERMISSIONS).on(PERMISSIONS.PERM_ID.eq(ROLE_PERMISSIONS.PERM_ID))
|
||||
.where(ROLE_PERMISSIONS.ROLE_ID.eq(record.getRoleId()))
|
||||
.where(PERMISSIONS.PERM_TYPE.ne("0"));
|
||||
ResRolesDto oneAs = permissionsService.getOneAs(caseQuery, ResRolesDto.class);
|
||||
if (oneAs == null) continue;
|
||||
record.setWebCount(oneAs.getWebCount());
|
||||
record.setAppletCount(oneAs.getAppletCount());
|
||||
}
|
||||
return JsonResult.success(resRolesDtoPage);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,31 @@
|
||||
package com.cdzy.user.model.dto;
|
||||
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import jakarta.validation.constraints.Max;
|
||||
import jakarta.validation.constraints.Min;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author attiya
|
||||
* @since 2025-03-14
|
||||
*/
|
||||
@Data
|
||||
public class PageParamDto {
|
||||
@Min(value = 1, message = "页码必须大于0")
|
||||
private Integer pageNum; // 默认第1页
|
||||
|
||||
@Min(value = 1, message = "每页数量必须大于0")
|
||||
@Max(value = 100, message = "每页数量不能超过100")
|
||||
private Integer pageSize;
|
||||
|
||||
private String roleName;
|
||||
|
||||
public <T> Page<T> getPage() {
|
||||
if (pageNum == null || pageSize == null) {
|
||||
pageNum = 1;
|
||||
pageSize = 10;
|
||||
}
|
||||
return new Page<>(pageNum, pageSize);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,39 @@
|
||||
package com.cdzy.user.model.dto;
|
||||
|
||||
import com.mybatisflex.annotation.Id;
|
||||
import com.mybatisflex.annotation.Table;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 实体类。
|
||||
*
|
||||
* @author attiya
|
||||
* @since 2025-03-14
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Table("ebike_roles")
|
||||
public class ResRolesDto implements Serializable {
|
||||
|
||||
private Long roleId;
|
||||
|
||||
private String roleName;
|
||||
|
||||
private String roleDescription;
|
||||
|
||||
private String orgName;
|
||||
|
||||
private Integer staffCount;
|
||||
|
||||
private Integer webCount;
|
||||
|
||||
private Integer appletCount;
|
||||
}
|
||||
@ -39,4 +39,6 @@ public class Permissions implements Serializable {
|
||||
|
||||
private Integer type;
|
||||
|
||||
private Integer permType;
|
||||
|
||||
}
|
||||
|
||||
@ -11,7 +11,7 @@ import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 实体类。
|
||||
* 实体类。
|
||||
*
|
||||
* @author attiya
|
||||
* @since 2025-03-14
|
||||
@ -39,4 +39,6 @@ public class Roles implements Serializable {
|
||||
|
||||
private Long createdStaff;
|
||||
|
||||
private String roleDescription;
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user