MetaTaskNewController.java 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package com.izouma.nineth.web;
  2. import com.izouma.nineth.domain.MetaTaskBind;
  3. import com.izouma.nineth.domain.MetaTaskNew;
  4. import com.izouma.nineth.dto.MetaRestResult;
  5. import com.izouma.nineth.dto.PageQuery;
  6. import com.izouma.nineth.enums.MetaTaskType;
  7. import com.izouma.nineth.exception.BusinessException;
  8. import com.izouma.nineth.repo.MetaTaskBindRepo;
  9. import com.izouma.nineth.repo.MetaTaskNewRepo;
  10. import com.izouma.nineth.service.MetaTaskNewService;
  11. import com.izouma.nineth.utils.excel.ExcelUtils;
  12. import lombok.AllArgsConstructor;
  13. import org.apache.commons.collections.CollectionUtils;
  14. import org.springframework.data.domain.Page;
  15. import org.springframework.web.bind.annotation.*;
  16. import javax.servlet.http.HttpServletResponse;
  17. import java.io.IOException;
  18. import java.util.List;
  19. @RestController
  20. @RequestMapping("/metaTaskNew")
  21. @AllArgsConstructor
  22. public class MetaTaskNewController extends BaseController {
  23. private MetaTaskNewService metaTaskNewService;
  24. private MetaTaskNewRepo metaTaskNewRepo;
  25. private MetaTaskBindRepo metaTaskBindRepo;
  26. //@PreAuthorize("hasRole('ADMIN')")
  27. @PostMapping("/save")
  28. public MetaTaskNew save(@RequestBody MetaTaskNew record) {
  29. return metaTaskNewService.save(record);
  30. }
  31. //@PreAuthorize("hasRole('ADMIN')")
  32. @PostMapping("/all")
  33. public Page<MetaTaskNew> all(@RequestBody PageQuery pageQuery) {
  34. return metaTaskNewService.all(pageQuery);
  35. }
  36. @GetMapping("/get/{id}")
  37. public MetaTaskNew get(@PathVariable Long id) {
  38. MetaTaskNew metaTaskNew = metaTaskNewRepo.findById(id).orElseThrow(new BusinessException("无记录"));
  39. List<MetaTaskBind> metaNodeTask = metaTaskBindRepo.findByTaskIdAndTypeAndDel(metaTaskNew.getId(), MetaTaskType.NODE, false);
  40. if (CollectionUtils.isNotEmpty(metaNodeTask)) {
  41. metaTaskNew.setMetaNodeTask(metaNodeTask);
  42. }
  43. List<MetaTaskBind> metaBranchLineTask = metaTaskBindRepo.findByTaskIdAndTypeAndDel(metaTaskNew.getId(), MetaTaskType.BRANCH_LINE, false);
  44. if (CollectionUtils.isNotEmpty(metaBranchLineTask)) {
  45. metaTaskNew.setMetaBranchLineTask(metaBranchLineTask);
  46. }
  47. List<MetaTaskBind> metaDailyTask = metaTaskBindRepo.findByTaskIdAndTypeAndDel(metaTaskNew.getId(), MetaTaskType.DAILY, false);
  48. if (CollectionUtils.isNotEmpty(metaDailyTask)) {
  49. metaTaskNew.setMetaDailyTask(metaDailyTask);
  50. }
  51. return metaTaskNew;
  52. }
  53. @PostMapping("/del/{id}")
  54. public void del(@PathVariable Long id) {
  55. metaTaskNewRepo.softDelete(id);
  56. }
  57. @GetMapping("/excel")
  58. @ResponseBody
  59. public void excel(HttpServletResponse response, PageQuery pageQuery) throws IOException {
  60. List<MetaTaskNew> data = all(pageQuery).getContent();
  61. ExcelUtils.export(response, data);
  62. }
  63. @GetMapping("/findAll")
  64. public MetaRestResult<List<MetaTaskNew>> findAll() {
  65. List<MetaTaskNew> metaTaskNews = metaTaskNewRepo.findAllByPublishAndFinishAndDel(true, false, false);
  66. return MetaRestResult.returnSuccess(metaTaskNews);
  67. }
  68. @GetMapping("/{userId}/{channelId}/canGet")
  69. public MetaRestResult<List<MetaTaskNew>> canGet(@PathVariable Long userId, @PathVariable Long channelId) {
  70. List<MetaTaskNew> metaTaskNews = metaTaskNewRepo.canGet(userId, channelId);
  71. return MetaRestResult.returnSuccess(metaTaskNews);
  72. }
  73. }