|
|
|
|
@ -1,6 +1,5 @@
|
|
|
|
|
package com.qiujie.controller;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.qiujie.dto.ResponseDTO;
|
|
|
|
|
import com.qiujie.entity.Staff;
|
|
|
|
|
import com.qiujie.service.StaffRoleService;
|
|
|
|
|
@ -17,107 +16,187 @@ import java.util.List;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <p>
|
|
|
|
|
* 前端控制器
|
|
|
|
|
* 员工管理模块前端控制器
|
|
|
|
|
* 负责处理员工的增删改查、角色分配、密码验证与重置、数据导入导出等请求
|
|
|
|
|
* </p>
|
|
|
|
|
*
|
|
|
|
|
* @author qiujie
|
|
|
|
|
* @since 2022-01-27
|
|
|
|
|
*/
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("/staff")
|
|
|
|
|
@RestController // 标识为REST风格控制器,返回JSON格式响应
|
|
|
|
|
@RequestMapping("/staff") // 基础请求路径,所有接口路径前缀为/staff
|
|
|
|
|
public class StaffController {
|
|
|
|
|
|
|
|
|
|
// 自动注入员工服务层对象,处理员工核心业务逻辑
|
|
|
|
|
@Autowired
|
|
|
|
|
private StaffService staffService;
|
|
|
|
|
|
|
|
|
|
// 自动注入员工-角色关联服务层对象,处理员工角色分配相关业务
|
|
|
|
|
@Autowired
|
|
|
|
|
private StaffRoleService staffRoleService;
|
|
|
|
|
|
|
|
|
|
@ApiOperation("新增")
|
|
|
|
|
@PostMapping
|
|
|
|
|
@PreAuthorize("hasAnyAuthority('system:staff:add')")
|
|
|
|
|
/**
|
|
|
|
|
* 新增员工
|
|
|
|
|
* @param staff 员工实体对象(包含员工基本信息,通过请求体传递)
|
|
|
|
|
* @return 统一响应结果(操作状态、数据或错误信息)
|
|
|
|
|
*/
|
|
|
|
|
@ApiOperation("新增员工") // Swagger注解,描述接口功能
|
|
|
|
|
@PostMapping // 接收POST请求,完整路径为/staff
|
|
|
|
|
@PreAuthorize("hasAnyAuthority('system:staff:add')") // 权限控制:仅拥有该权限的用户可访问
|
|
|
|
|
public ResponseDTO add(@RequestBody Staff staff) {
|
|
|
|
|
return this.staffService.add(staff);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiOperation("逻辑删除")
|
|
|
|
|
@DeleteMapping("/{id}")
|
|
|
|
|
@PreAuthorize("hasAnyAuthority('system:staff:delete')")
|
|
|
|
|
/**
|
|
|
|
|
* 逻辑删除员工(仅标记删除状态,不物理删除数据)
|
|
|
|
|
* @param id 要删除的员工ID(通过URL路径传递)
|
|
|
|
|
* @return 统一响应结果
|
|
|
|
|
*/
|
|
|
|
|
@ApiOperation("逻辑删除员工")
|
|
|
|
|
@DeleteMapping("/{id}") // 接收DELETE请求,完整路径为/staff/{id}
|
|
|
|
|
@PreAuthorize("hasAnyAuthority('system:staff:delete')") // 权限控制
|
|
|
|
|
public ResponseDTO delete(@PathVariable Integer id) {
|
|
|
|
|
return this.staffService.delete(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiOperation("批量逻辑删除")
|
|
|
|
|
@DeleteMapping("/batch/{ids}")
|
|
|
|
|
@PreAuthorize("hasAnyAuthority('system:staff:delete')")
|
|
|
|
|
/**
|
|
|
|
|
* 批量逻辑删除员工
|
|
|
|
|
* @param ids 要删除的员工ID列表(通过URL路径传递,多个ID用逗号分隔)
|
|
|
|
|
* @return 统一响应结果
|
|
|
|
|
*/
|
|
|
|
|
@ApiOperation("批量逻辑删除员工")
|
|
|
|
|
@DeleteMapping("/batch/{ids}") // 接收DELETE请求,完整路径为/staff/batch/{ids}
|
|
|
|
|
@PreAuthorize("hasAnyAuthority('system:staff:delete')") // 权限控制
|
|
|
|
|
public ResponseDTO deleteBatch(@PathVariable List<Integer> ids) {
|
|
|
|
|
return this.staffService.deleteBatch(ids);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiOperation("编辑更新")
|
|
|
|
|
@PutMapping
|
|
|
|
|
@PreAuthorize("hasAnyAuthority('system:staff:edit','system:staff:enable')")
|
|
|
|
|
/**
|
|
|
|
|
* 编辑更新员工信息(含员工状态启用/禁用)
|
|
|
|
|
* @param staff 包含更新信息的员工实体(通过请求体传递)
|
|
|
|
|
* @return 统一响应结果
|
|
|
|
|
*/
|
|
|
|
|
@ApiOperation("编辑更新员工信息")
|
|
|
|
|
@PutMapping // 接收PUT请求,完整路径为/staff
|
|
|
|
|
@PreAuthorize("hasAnyAuthority('system:staff:edit','system:staff:enable')") // 权限控制:拥有两个权限中的任意一个即可访问
|
|
|
|
|
public ResponseDTO edit(@RequestBody Staff staff) {
|
|
|
|
|
return this.staffService.edit(staff);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiOperation("查询")
|
|
|
|
|
@GetMapping("/{id}")
|
|
|
|
|
/**
|
|
|
|
|
* 根据ID查询员工基础信息
|
|
|
|
|
* @param id 员工ID(通过URL路径传递)
|
|
|
|
|
* @return 统一响应结果(包含查询到的员工基础信息)
|
|
|
|
|
*/
|
|
|
|
|
@ApiOperation("根据ID查询员工基础信息")
|
|
|
|
|
@GetMapping("/{id}") // 接收GET请求,完整路径为/staff/{id}
|
|
|
|
|
public ResponseDTO query(@PathVariable Integer id) {
|
|
|
|
|
return this.staffService.query(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiOperation("查询员工信息")
|
|
|
|
|
@GetMapping("/info/{id}")
|
|
|
|
|
/**
|
|
|
|
|
* 根据ID查询员工详细信息(可能包含关联的部门、角色等扩展信息)
|
|
|
|
|
* @param id 员工ID(通过URL路径传递)
|
|
|
|
|
* @return 统一响应结果(包含员工详细信息)
|
|
|
|
|
*/
|
|
|
|
|
@ApiOperation("根据ID查询员工详细信息")
|
|
|
|
|
@GetMapping("/info/{id}") // 接收GET请求,完整路径为/staff/info/{id}
|
|
|
|
|
public ResponseDTO queryInfo(@PathVariable Integer id) {
|
|
|
|
|
return this.staffService.queryInfo(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiOperation("多条件分页查询")
|
|
|
|
|
@GetMapping
|
|
|
|
|
@PreAuthorize("hasAnyAuthority('system:staff:list','system:staff:search')")
|
|
|
|
|
public ResponseDTO list(@RequestParam(defaultValue = "1") Integer current, @RequestParam(defaultValue = "10") Integer size, String name, String birthday, Integer deptId, Integer status) {
|
|
|
|
|
/**
|
|
|
|
|
* 多条件分页查询员工列表
|
|
|
|
|
* @param current 当前页码(默认第1页)
|
|
|
|
|
* @param size 每页条数(默认10条)
|
|
|
|
|
* @param name 员工姓名(查询条件,可选)
|
|
|
|
|
* @param birthday 员工生日(查询条件,可选)
|
|
|
|
|
* @param deptId 所属部门ID(查询条件,可选)
|
|
|
|
|
* @param status 员工状态(查询条件,可选,如启用/禁用)
|
|
|
|
|
* @return 统一响应结果(包含分页查询结果)
|
|
|
|
|
*/
|
|
|
|
|
@ApiOperation("多条件分页查询员工列表")
|
|
|
|
|
@GetMapping // 接收GET请求,完整路径为/staff
|
|
|
|
|
@PreAuthorize("hasAnyAuthority('system:staff:list','system:staff:search')") // 权限控制
|
|
|
|
|
public ResponseDTO list(@RequestParam(defaultValue = "1") Integer current,
|
|
|
|
|
@RequestParam(defaultValue = "10") Integer size,
|
|
|
|
|
String name,
|
|
|
|
|
String birthday,
|
|
|
|
|
Integer deptId,
|
|
|
|
|
Integer status) {
|
|
|
|
|
return this.staffService.list(current, size, name, birthday, deptId, status);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiOperation("数据导出接口")
|
|
|
|
|
@GetMapping("/export/{filename}")
|
|
|
|
|
@PreAuthorize("hasAnyAuthority('system:staff:export')")
|
|
|
|
|
/**
|
|
|
|
|
* 员工数据导出接口(将员工数据导出为文件)
|
|
|
|
|
* @param response HTTP响应对象,用于输出文件流
|
|
|
|
|
* @param filename 导出的文件名(通过URL路径传递)
|
|
|
|
|
* @throws IOException 可能抛出文件IO异常
|
|
|
|
|
*/
|
|
|
|
|
@ApiOperation("员工数据导出接口")
|
|
|
|
|
@GetMapping("/export/{filename}") // 接收GET请求,完整路径为/staff/export/{filename}
|
|
|
|
|
@PreAuthorize("hasAnyAuthority('system:staff:export')") // 权限控制
|
|
|
|
|
public void export(HttpServletResponse response, @PathVariable String filename) throws IOException {
|
|
|
|
|
this.staffService.export(response, filename);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiOperation("数据导入接口")
|
|
|
|
|
@PostMapping("/import")
|
|
|
|
|
@PreAuthorize("hasAnyAuthority('system:staff:import')")
|
|
|
|
|
/**
|
|
|
|
|
* 员工数据导入接口(从上传的文件导入员工数据)
|
|
|
|
|
* @param file 包含员工数据的上传文件
|
|
|
|
|
* @return 统一响应结果(包含导入结果信息)
|
|
|
|
|
* @throws IOException 可能抛出文件读取异常
|
|
|
|
|
*/
|
|
|
|
|
@ApiOperation("员工数据导入接口")
|
|
|
|
|
@PostMapping("/import") // 接收POST请求,完整路径为/staff/import
|
|
|
|
|
@PreAuthorize("hasAnyAuthority('system:staff:import')") // 权限控制
|
|
|
|
|
public ResponseDTO imp(MultipartFile file) throws IOException {
|
|
|
|
|
return this.staffService.imp(file);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 为员工分配角色
|
|
|
|
|
* @param id 员工ID(通过URL路径传递)
|
|
|
|
|
* @param roleIds 角色ID列表(通过请求体传递,指定要分配的角色)
|
|
|
|
|
* @return 统一响应结果(包含角色分配结果)
|
|
|
|
|
*/
|
|
|
|
|
@ApiOperation("为员工设置角色")
|
|
|
|
|
@PostMapping("/set/{id}")
|
|
|
|
|
@PreAuthorize("hasAnyAuthority('system:staff:set_role')")
|
|
|
|
|
@PostMapping("/set/{id}") // 接收POST请求,完整路径为/staff/set/{id}
|
|
|
|
|
@PreAuthorize("hasAnyAuthority('system:staff:set_role')") // 权限控制
|
|
|
|
|
public ResponseDTO setRole(@PathVariable Integer id, @RequestBody List<Integer> roleIds) {
|
|
|
|
|
return this.staffRoleService.setRole(id, roleIds);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiOperation("得到员工的角色")
|
|
|
|
|
@GetMapping("/staff/{id}")
|
|
|
|
|
/**
|
|
|
|
|
* 查询指定员工已分配的角色
|
|
|
|
|
* @param id 员工ID(通过URL路径传递)
|
|
|
|
|
* @return 统一响应结果(包含员工的角色列表)
|
|
|
|
|
*/
|
|
|
|
|
@ApiOperation("查询员工已分配的角色")
|
|
|
|
|
@GetMapping("/staff/{id}") // 接收GET请求,完整路径为/staff/staff/{id}
|
|
|
|
|
public ResponseDTO queryByStaffId(@PathVariable Integer id) {
|
|
|
|
|
return this.staffRoleService.queryByStaffId(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation("检查员工的密码")
|
|
|
|
|
@GetMapping("/{pwd}/{id}")
|
|
|
|
|
/**
|
|
|
|
|
* 验证员工密码是否正确
|
|
|
|
|
* @param pwd 待验证的密码(通过URL路径传递)
|
|
|
|
|
* @param id 员工ID(通过URL路径传递)
|
|
|
|
|
* @return 统一响应结果(包含密码验证结果)
|
|
|
|
|
*/
|
|
|
|
|
@ApiOperation("验证员工密码")
|
|
|
|
|
@GetMapping("/{pwd}/{id}") // 接收GET请求,完整路径为/staff/{pwd}/{id}
|
|
|
|
|
public ResponseDTO validate(@PathVariable String pwd, @PathVariable Integer id) {
|
|
|
|
|
return this.staffService.validate(pwd, id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiOperation("更新密码")
|
|
|
|
|
@PutMapping("/reset")
|
|
|
|
|
/**
|
|
|
|
|
* 重置员工密码
|
|
|
|
|
* @param staff 包含员工ID和新密码的实体对象(通过请求体传递)
|
|
|
|
|
* @return 统一响应结果(包含密码重置结果)
|
|
|
|
|
*/
|
|
|
|
|
@ApiOperation("重置员工密码")
|
|
|
|
|
@PutMapping("/reset") // 接收PUT请求,完整路径为/staff/reset
|
|
|
|
|
public ResponseDTO reset(@RequestBody Staff staff) {
|
|
|
|
|
return this.staffService.reset(staff);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|