CompanyController.java 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package com.izouma.jiashanxia.web;
  2. import com.izouma.jiashanxia.domain.Company;
  3. import com.izouma.jiashanxia.domain.User;
  4. import com.izouma.jiashanxia.service.CompanyService;
  5. import com.izouma.jiashanxia.dto.PageQuery;
  6. import com.izouma.jiashanxia.exception.BusinessException;
  7. import com.izouma.jiashanxia.repo.CompanyRepo;
  8. import com.izouma.jiashanxia.utils.SecurityUtils;
  9. import com.izouma.jiashanxia.utils.excel.ExcelUtils;
  10. import io.swagger.annotations.ApiOperation;
  11. import lombok.AllArgsConstructor;
  12. import org.springframework.data.domain.Page;
  13. import org.springframework.security.access.prepost.PreAuthorize;
  14. import org.springframework.web.bind.annotation.*;
  15. import javax.servlet.http.HttpServletResponse;
  16. import java.io.IOException;
  17. import java.util.List;
  18. @RestController
  19. @RequestMapping("/company")
  20. @AllArgsConstructor
  21. public class CompanyController extends BaseController {
  22. private CompanyService companyService;
  23. private CompanyRepo companyRepo;
  24. //@PreAuthorize("hasRole('ADMIN')")
  25. @PostMapping("/save")
  26. public Company save(@RequestBody Company record) {
  27. return companyService.save(record);
  28. }
  29. @PreAuthorize("hasAnyRole('ADMIN','CREATOR')")
  30. @PostMapping("/all")
  31. public Page<Company> all(@RequestBody PageQuery pageQuery) {
  32. return companyService.all(pageQuery, SecurityUtils.getAuthenticatedUser());
  33. }
  34. @GetMapping("/get/{id}")
  35. public Company get(@PathVariable Long id) {
  36. return companyRepo.findById(id).orElseThrow(new BusinessException("无记录"));
  37. }
  38. @PostMapping("/del/{id}")
  39. public void del(@PathVariable Long id) {
  40. companyRepo.softDelete(id);
  41. }
  42. @GetMapping("/excel")
  43. @ResponseBody
  44. public void excel(HttpServletResponse response, PageQuery pageQuery) throws IOException {
  45. List<Company> data = all(pageQuery).getContent();
  46. ExcelUtils.export(response, data);
  47. }
  48. @GetMapping("/allList")
  49. public List<Company> allList() {
  50. return companyRepo.findAll();
  51. }
  52. @PostMapping("/employee")
  53. @ApiOperation("根据用户id员工列表")
  54. public List<User> employee(Long userId) {
  55. return companyService.employee(userId);
  56. }
  57. @PostMapping("/addEmp")
  58. @ApiOperation("添加员工")
  59. public void addEmp(@RequestParam Long userId, @RequestParam Long companyId) {
  60. companyService.addUser(userId, companyId);
  61. }
  62. @PostMapping("/removeEmp")
  63. @ApiOperation("添加员工")
  64. public void removeEmp(@RequestParam Long userId, @RequestParam Long companyId) {
  65. companyService.removeUser(userId, companyId);
  66. }
  67. }