MetaAtomTaskController.java 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package com.izouma.nineth.web;
  2. import com.izouma.nineth.domain.MetaAtomTask;
  3. import com.izouma.nineth.dto.PageQuery;
  4. import com.izouma.nineth.exception.BusinessException;
  5. import com.izouma.nineth.repo.MetaAtomTaskRepo;
  6. import com.izouma.nineth.service.MetaAtomTaskService;
  7. import com.izouma.nineth.utils.ObjUtils;
  8. import com.izouma.nineth.utils.excel.ExcelUtils;
  9. import lombok.AllArgsConstructor;
  10. import org.springframework.data.domain.Page;
  11. import org.springframework.web.bind.annotation.*;
  12. import javax.servlet.http.HttpServletResponse;
  13. import java.io.IOException;
  14. import java.util.List;
  15. @RestController
  16. @RequestMapping("/metaAtomTask")
  17. @AllArgsConstructor
  18. public class MetaAtomTaskController extends BaseController {
  19. private MetaAtomTaskService metaAtomTaskService;
  20. private MetaAtomTaskRepo metaAtomTaskRepo;
  21. //@PreAuthorize("hasRole('ADMIN')")
  22. @PostMapping("/save")
  23. public MetaAtomTask save(@RequestBody MetaAtomTask record) {
  24. if (record.getId() != null) {
  25. MetaAtomTask orig = metaAtomTaskRepo.findById(record.getId()).orElseThrow(new BusinessException("无记录"));
  26. ObjUtils.merge(orig, record);
  27. return metaAtomTaskRepo.save(orig);
  28. }
  29. return metaAtomTaskRepo.save(record);
  30. }
  31. //@PreAuthorize("hasRole('ADMIN')")
  32. @PostMapping("/all")
  33. public Page<MetaAtomTask> all(@RequestBody PageQuery pageQuery) {
  34. return metaAtomTaskService.all(pageQuery);
  35. }
  36. @GetMapping("/get/{id}")
  37. public MetaAtomTask get(@PathVariable Long id) {
  38. return metaAtomTaskRepo.findById(id).orElseThrow(new BusinessException("无记录"));
  39. }
  40. @PostMapping("/del/{id}")
  41. public void del(@PathVariable Long id) {
  42. metaAtomTaskRepo.softDelete(id);
  43. }
  44. @GetMapping("/excel")
  45. @ResponseBody
  46. public void excel(HttpServletResponse response, PageQuery pageQuery) throws IOException {
  47. List<MetaAtomTask> data = all(pageQuery).getContent();
  48. ExcelUtils.export(response, data);
  49. }
  50. @GetMapping("/findAll")
  51. public List<MetaAtomTask> findAll() {
  52. return metaAtomTaskRepo.findAllByDel(false);
  53. }
  54. }