| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- package com.izouma.nineth.web;
- import com.izouma.nineth.domain.MetaTaskBind;
- import com.izouma.nineth.domain.MetaTaskNew;
- import com.izouma.nineth.dto.MetaRestResult;
- import com.izouma.nineth.dto.PageQuery;
- import com.izouma.nineth.enums.MetaTaskType;
- import com.izouma.nineth.exception.BusinessException;
- import com.izouma.nineth.repo.MetaTaskBindRepo;
- import com.izouma.nineth.repo.MetaTaskNewRepo;
- import com.izouma.nineth.service.MetaTaskNewService;
- import com.izouma.nineth.utils.excel.ExcelUtils;
- import lombok.AllArgsConstructor;
- import org.apache.commons.collections.CollectionUtils;
- import org.springframework.data.domain.Page;
- import org.springframework.web.bind.annotation.*;
- import javax.servlet.http.HttpServletResponse;
- import java.io.IOException;
- import java.util.List;
- @RestController
- @RequestMapping("/metaTaskNew")
- @AllArgsConstructor
- public class MetaTaskNewController extends BaseController {
- private MetaTaskNewService metaTaskNewService;
- private MetaTaskNewRepo metaTaskNewRepo;
- private MetaTaskBindRepo metaTaskBindRepo;
- //@PreAuthorize("hasRole('ADMIN')")
- @PostMapping("/save")
- public MetaTaskNew save(@RequestBody MetaTaskNew record) {
- return metaTaskNewService.save(record);
- }
- //@PreAuthorize("hasRole('ADMIN')")
- @PostMapping("/all")
- public Page<MetaTaskNew> all(@RequestBody PageQuery pageQuery) {
- return metaTaskNewService.all(pageQuery);
- }
- @GetMapping("/get/{id}")
- public MetaTaskNew get(@PathVariable Long id) {
- MetaTaskNew metaTaskNew = metaTaskNewRepo.findById(id).orElseThrow(new BusinessException("无记录"));
- List<MetaTaskBind> metaNodeTask = metaTaskBindRepo.findByTaskIdAndTypeAndDel(metaTaskNew.getId(), MetaTaskType.NODE, false);
- if (CollectionUtils.isNotEmpty(metaNodeTask)) {
- metaTaskNew.setMetaNodeTask(metaNodeTask);
- }
- List<MetaTaskBind> metaBranchLineTask = metaTaskBindRepo.findByTaskIdAndTypeAndDel(metaTaskNew.getId(), MetaTaskType.BRANCH_LINE, false);
- if (CollectionUtils.isNotEmpty(metaBranchLineTask)) {
- metaTaskNew.setMetaBranchLineTask(metaBranchLineTask);
- }
- List<MetaTaskBind> metaDailyTask = metaTaskBindRepo.findByTaskIdAndTypeAndDel(metaTaskNew.getId(), MetaTaskType.DAILY, false);
- if (CollectionUtils.isNotEmpty(metaDailyTask)) {
- metaTaskNew.setMetaDailyTask(metaDailyTask);
- }
- return metaTaskNew;
- }
- @PostMapping("/del/{id}")
- public void del(@PathVariable Long id) {
- metaTaskNewRepo.softDelete(id);
- }
- @GetMapping("/excel")
- @ResponseBody
- public void excel(HttpServletResponse response, PageQuery pageQuery) throws IOException {
- List<MetaTaskNew> data = all(pageQuery).getContent();
- ExcelUtils.export(response, data);
- }
- @GetMapping("/findAll")
- public MetaRestResult<List<MetaTaskNew>> findAll() {
- List<MetaTaskNew> metaTaskNews = metaTaskNewRepo.findAllByPublishAndFinishAndDel(true, false, false);
- return MetaRestResult.returnSuccess(metaTaskNews);
- }
- @GetMapping("/{userId}/{channelId}/canGet")
- public MetaRestResult<List<MetaTaskNew>> canGet(@PathVariable Long userId, @PathVariable Long channelId) {
- List<MetaTaskNew> metaTaskNews = metaTaskNewRepo.canGet(userId, channelId);
- return MetaRestResult.returnSuccess(metaTaskNews);
- }
- }
|