2025-04-14 09:35:36 +08:00
|
|
|
|
package com.cdzy.user.controller;
|
|
|
|
|
|
|
2025-05-09 16:36:53 +08:00
|
|
|
|
import cn.dev33.satoken.stp.StpUtil;
|
2025-04-14 09:35:36 +08:00
|
|
|
|
import com.cdzy.common.model.JsonResult;
|
|
|
|
|
|
import com.cdzy.common.model.PageParam;
|
2025-05-09 16:36:53 +08:00
|
|
|
|
import com.cdzy.common.model.StaffDto;
|
|
|
|
|
|
import com.cdzy.user.model.dto.PageParamDto;
|
|
|
|
|
|
import com.cdzy.user.model.dto.ResRolesDto;
|
2025-04-14 09:35:36 +08:00
|
|
|
|
import com.cdzy.user.model.entity.Roles;
|
2025-05-09 16:36:53 +08:00
|
|
|
|
import com.cdzy.user.service.PermissionsService;
|
2025-04-14 09:35:36 +08:00
|
|
|
|
import com.cdzy.user.service.RolesService;
|
2025-05-09 16:36:53 +08:00
|
|
|
|
import com.cdzy.user.service.StaffService;
|
2025-04-14 09:35:36 +08:00
|
|
|
|
import com.mybatisflex.core.paginate.Page;
|
2025-05-09 16:36:53 +08:00
|
|
|
|
import com.mybatisflex.core.query.QueryColumn;
|
|
|
|
|
|
import com.mybatisflex.core.query.QueryMethods;
|
2025-04-14 09:35:36 +08:00
|
|
|
|
import com.mybatisflex.core.query.QueryWrapper;
|
|
|
|
|
|
import jakarta.annotation.Resource;
|
2025-05-09 16:36:53 +08:00
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
2025-04-14 09:35:36 +08:00
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
2025-05-09 16:36:53 +08:00
|
|
|
|
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;
|
2025-04-14 09:35:36 +08:00
|
|
|
|
import static com.cdzy.user.model.entity.table.RolesTableDef.ROLES;
|
|
|
|
|
|
import static com.cdzy.user.model.entity.table.StaffRolesTableDef.STAFF_ROLES;
|
2025-05-09 16:36:53 +08:00
|
|
|
|
import static com.cdzy.user.model.entity.table.StaffTableDef.STAFF;
|
2025-04-14 09:35:36 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 角色控制层。
|
|
|
|
|
|
*
|
|
|
|
|
|
* @author attiya
|
|
|
|
|
|
* @since 2025-03-14
|
|
|
|
|
|
*/
|
|
|
|
|
|
@RestController
|
|
|
|
|
|
@RequestMapping("/roles")
|
|
|
|
|
|
public class RolesController {
|
|
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
|
private RolesService rolesService;
|
|
|
|
|
|
|
2025-05-09 16:36:53 +08:00
|
|
|
|
@Autowired
|
|
|
|
|
|
private PermissionsService permissionsService;
|
|
|
|
|
|
@Resource
|
|
|
|
|
|
private StaffService staffService;
|
|
|
|
|
|
|
2025-04-14 09:35:36 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 添加。
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param roles 角色信息
|
|
|
|
|
|
* @return {@code true} 添加成功,{@code false} 添加失败
|
|
|
|
|
|
*/
|
|
|
|
|
|
@PostMapping("save")
|
|
|
|
|
|
public JsonResult<?> save(@RequestBody Roles roles) {
|
|
|
|
|
|
rolesService.save(roles);
|
|
|
|
|
|
return JsonResult.success();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 根据主键删除。
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param id 主键
|
|
|
|
|
|
* @return {@code true} 删除成功,{@code false} 删除失败
|
|
|
|
|
|
*/
|
|
|
|
|
|
@DeleteMapping("remove/{id}")
|
2025-04-22 16:23:12 +08:00
|
|
|
|
public JsonResult<?> remove(@PathVariable("id") Long id) {
|
2025-04-14 09:35:36 +08:00
|
|
|
|
rolesService.removeById(id);
|
|
|
|
|
|
return JsonResult.success();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 根据主键更新。
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param roles 角色信息
|
|
|
|
|
|
* @return {@code true} 更新成功,{@code false} 更新失败
|
|
|
|
|
|
*/
|
2025-04-15 17:33:09 +08:00
|
|
|
|
@PostMapping("update")
|
2025-04-14 09:35:36 +08:00
|
|
|
|
public JsonResult<?> update(@RequestBody Roles roles) {
|
|
|
|
|
|
rolesService.updateById(roles);
|
|
|
|
|
|
return JsonResult.success();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 查询所有。
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return 所有数据
|
|
|
|
|
|
*/
|
|
|
|
|
|
@GetMapping("list")
|
|
|
|
|
|
public JsonResult<?> list() {
|
|
|
|
|
|
List<Roles> list = rolesService.list();
|
|
|
|
|
|
return JsonResult.success(list);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 根据主键获取详细信息。
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param id 主键
|
|
|
|
|
|
* @return 详情
|
|
|
|
|
|
*/
|
|
|
|
|
|
@GetMapping("getInfo/{id}")
|
2025-04-22 16:23:12 +08:00
|
|
|
|
public JsonResult<?> getInfo(@PathVariable("id") Long id) {
|
2025-04-14 09:35:36 +08:00
|
|
|
|
Roles roles = rolesService.getById(id);
|
|
|
|
|
|
return JsonResult.success(roles);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 分页查询。
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param pageParam 分页对象
|
|
|
|
|
|
* @return 分页对象
|
|
|
|
|
|
*/
|
2025-05-09 16:36:53 +08:00
|
|
|
|
@PostMapping("page")
|
2025-04-14 09:35:36 +08:00
|
|
|
|
public JsonResult<?> page(@Validated PageParam pageParam) {
|
|
|
|
|
|
Page<Roles> page = rolesService.page(pageParam.getPage());
|
|
|
|
|
|
return JsonResult.success(page);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取当前登陆用户的所有角色码。
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return 分页对象
|
|
|
|
|
|
*/
|
|
|
|
|
|
@GetMapping("roleCodeList")
|
|
|
|
|
|
public JsonResult<?> listByStaffId(@RequestParam("staffId") String staffId) {
|
|
|
|
|
|
QueryWrapper queryWrapper = QueryWrapper.create()
|
|
|
|
|
|
.select(ROLES.ROLE_CODE)
|
|
|
|
|
|
.leftJoin(STAFF_ROLES).on(STAFF_ROLES.ROLE_ID.eq(ROLES.ROLE_CODE))
|
|
|
|
|
|
.where(STAFF_ROLES.STAFF_ID.eq(staffId));
|
|
|
|
|
|
List<String> list = rolesService.listAs(queryWrapper, String.class);
|
|
|
|
|
|
return JsonResult.success(list);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-09 16:36:53 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 分页查询角色列表
|
|
|
|
|
|
*
|
|
|
|
|
|
* @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);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-14 09:35:36 +08:00
|
|
|
|
}
|