package com.ruoyi.web.controller.app; import java.util.List; import javax.servlet.http.HttpServletResponse; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.system.service.ISysPostService; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import com.ruoyi.common.annotation.Log; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.enums.BusinessType; import com.ruoyi.app.domain.Staff; import com.ruoyi.app.service.IStaffService; import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.common.core.page.TableDataInfo; /** * 人员Controller * * @author coede * @date 2025-03-20 */ @RestController @RequestMapping("/app/staff") public class StaffController extends BaseController { @Autowired private IStaffService staffService; @Autowired private ISysPostService sysPostService; /** * 查询人员列表 */ @PreAuthorize("@ss.hasPermi('app:staff:list')") @GetMapping("/list") public TableDataInfo list(Staff staff) { startPage(); List list = staffService.selectStaffList(staff); return getDataTable(list); } /** * 导出人员列表 */ @PreAuthorize("@ss.hasPermi('app:staff:export')") @Log(title = "人员", businessType = BusinessType.EXPORT) @PostMapping("/export") public void export(HttpServletResponse response, Staff staff) { List list = staffService.selectStaffList(staff); ExcelUtil util = new ExcelUtil(Staff.class); util.exportExcel(response, list, "人员数据"); } /** * 获取人员详细信息 */ @PreAuthorize("@ss.hasPermi('app:staff:query')") @GetMapping(value = "/{id}") public AjaxResult getInfo(@PathVariable("id") Long id) { AjaxResult ajax = AjaxResult.success(); if (StringUtils.isNotNull(id)) { Staff staff = staffService.selectStaffById(id); ajax.put(AjaxResult.DATA_TAG, staff); ajax.put("postIds", sysPostService.selectPostListByStaffId(id)); } return ajax; } /** * 新增人员 */ @PreAuthorize("@ss.hasPermi('app:staff:add')") @Log(title = "人员", businessType = BusinessType.INSERT) @PostMapping public AjaxResult add(@Validated @RequestBody Staff staff) { staff.setCreateBy(getUsername()); return toAjax(staffService.insertStaff(staff)); } /** * 修改人员 */ @PreAuthorize("@ss.hasPermi('app:staff:edit')") @Log(title = "人员", businessType = BusinessType.UPDATE) @PutMapping public AjaxResult edit(@Validated @RequestBody Staff staff) { staff.setUpdateBy(getUsername()); return toAjax(staffService.updateStaff(staff)); } /** * 删除人员 */ @PreAuthorize("@ss.hasPermi('app:staff:remove')") @Log(title = "人员", businessType = BusinessType.DELETE) @DeleteMapping("/{ids}") public AjaxResult remove(@PathVariable Long[] ids) { return toAjax(staffService.deleteStaffByIds(ids)); } }