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 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 metaNodeTask = metaTaskBindRepo.findByTaskIdAndTypeAndDel(metaTaskNew.getId(), MetaTaskType.NODE, false); if (CollectionUtils.isNotEmpty(metaNodeTask)) { metaTaskNew.setMetaNodeTask(metaNodeTask); } List metaBranchLineTask = metaTaskBindRepo.findByTaskIdAndTypeAndDel(metaTaskNew.getId(), MetaTaskType.BRANCH_LINE, false); if (CollectionUtils.isNotEmpty(metaBranchLineTask)) { metaTaskNew.setMetaBranchLineTask(metaBranchLineTask); } List 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 data = all(pageQuery).getContent(); ExcelUtils.export(response, data); } @GetMapping("/findAll") public MetaRestResult> findAll() { List metaTaskNews = metaTaskNewRepo.findAllByPublishAndFinishAndDel(true, false, false); return MetaRestResult.returnSuccess(metaTaskNews); } @GetMapping("/{userId}/{channelId}/canGet") public MetaRestResult> canGet(@PathVariable Long userId, @PathVariable Long channelId) { List metaTaskNews = metaTaskNewRepo.canGet(userId, channelId); return MetaRestResult.returnSuccess(metaTaskNews); } }