118 lines
3.1 KiB
Java
Raw Normal View History

2025-04-14 09:35:36 +08:00
package com.cdzy.user.controller;
import com.cdzy.common.model.JsonResult;
import com.cdzy.common.model.PageParam;
import com.cdzy.user.model.entity.Roles;
import com.cdzy.user.service.RolesService;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import static com.cdzy.user.model.entity.table.RolesTableDef.ROLES;
import static com.cdzy.user.model.entity.table.StaffRolesTableDef.STAFF_ROLES;
/**
* 角色控制层
*
* @author attiya
* @since 2025-03-14
*/
@RestController
@RequestMapping("/roles")
public class RolesController {
@Resource
private RolesService rolesService;
/**
* 添加
*
* @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} 更新失败
*/
@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 分页对象
*/
@GetMapping("page")
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);
}
}