StaffController.java 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. package com.ruoyi.web.controller.app;
  2. import java.util.List;
  3. import javax.servlet.http.HttpServletResponse;
  4. import com.ruoyi.common.utils.StringUtils;
  5. import com.ruoyi.system.service.ISysPostService;
  6. import org.springframework.security.access.prepost.PreAuthorize;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.validation.annotation.Validated;
  9. import org.springframework.web.bind.annotation.GetMapping;
  10. import org.springframework.web.bind.annotation.PostMapping;
  11. import org.springframework.web.bind.annotation.PutMapping;
  12. import org.springframework.web.bind.annotation.DeleteMapping;
  13. import org.springframework.web.bind.annotation.PathVariable;
  14. import org.springframework.web.bind.annotation.RequestBody;
  15. import org.springframework.web.bind.annotation.RequestMapping;
  16. import org.springframework.web.bind.annotation.RestController;
  17. import com.ruoyi.common.annotation.Log;
  18. import com.ruoyi.common.core.controller.BaseController;
  19. import com.ruoyi.common.core.domain.AjaxResult;
  20. import com.ruoyi.common.enums.BusinessType;
  21. import com.ruoyi.app.domain.Staff;
  22. import com.ruoyi.app.service.IStaffService;
  23. import com.ruoyi.common.utils.poi.ExcelUtil;
  24. import com.ruoyi.common.core.page.TableDataInfo;
  25. /**
  26. * 人员Controller
  27. *
  28. * @author coede
  29. * @date 2025-03-20
  30. */
  31. @RestController
  32. @RequestMapping("/app/staff")
  33. public class StaffController extends BaseController
  34. {
  35. @Autowired
  36. private IStaffService staffService;
  37. @Autowired
  38. private ISysPostService sysPostService;
  39. /**
  40. * 查询人员列表
  41. */
  42. @PreAuthorize("@ss.hasPermi('app:staff:list')")
  43. @GetMapping("/list")
  44. public TableDataInfo list(Staff staff)
  45. {
  46. startPage();
  47. List<Staff> list = staffService.selectStaffList(staff);
  48. return getDataTable(list);
  49. }
  50. /**
  51. * 导出人员列表
  52. */
  53. @PreAuthorize("@ss.hasPermi('app:staff:export')")
  54. @Log(title = "人员", businessType = BusinessType.EXPORT)
  55. @PostMapping("/export")
  56. public void export(HttpServletResponse response, Staff staff)
  57. {
  58. List<Staff> list = staffService.selectStaffList(staff);
  59. ExcelUtil<Staff> util = new ExcelUtil<Staff>(Staff.class);
  60. util.exportExcel(response, list, "人员数据");
  61. }
  62. /**
  63. * 获取人员详细信息
  64. */
  65. @PreAuthorize("@ss.hasPermi('app:staff:query')")
  66. @GetMapping(value = "/{id}")
  67. public AjaxResult getInfo(@PathVariable("id") Long id)
  68. {
  69. AjaxResult ajax = AjaxResult.success();
  70. if (StringUtils.isNotNull(id))
  71. {
  72. Staff staff = staffService.selectStaffById(id);
  73. ajax.put(AjaxResult.DATA_TAG, staff);
  74. ajax.put("postIds", sysPostService.selectPostListByStaffId(id));
  75. }
  76. return ajax;
  77. }
  78. /**
  79. * 新增人员
  80. */
  81. @PreAuthorize("@ss.hasPermi('app:staff:add')")
  82. @Log(title = "人员", businessType = BusinessType.INSERT)
  83. @PostMapping
  84. public AjaxResult add(@Validated @RequestBody Staff staff)
  85. {
  86. staff.setCreateBy(getUsername());
  87. return toAjax(staffService.insertStaff(staff));
  88. }
  89. /**
  90. * 修改人员
  91. */
  92. @PreAuthorize("@ss.hasPermi('app:staff:edit')")
  93. @Log(title = "人员", businessType = BusinessType.UPDATE)
  94. @PutMapping
  95. public AjaxResult edit(@Validated @RequestBody Staff staff)
  96. {
  97. staff.setUpdateBy(getUsername());
  98. return toAjax(staffService.updateStaff(staff));
  99. }
  100. /**
  101. * 删除人员
  102. */
  103. @PreAuthorize("@ss.hasPermi('app:staff:remove')")
  104. @Log(title = "人员", businessType = BusinessType.DELETE)
  105. @DeleteMapping("/{ids}")
  106. public AjaxResult remove(@PathVariable Long[] ids)
  107. {
  108. return toAjax(staffService.deleteStaffByIds(ids));
  109. }
  110. }