package com.izouma.nineth.web; import com.izouma.nineth.domain.AirDrop; import com.izouma.nineth.dto.PageQuery; import com.izouma.nineth.exception.BusinessException; import com.izouma.nineth.repo.AirDropRepo; import com.izouma.nineth.service.AirDropService; import com.izouma.nineth.utils.excel.ExcelUtils; import lombok.AllArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.time.LocalDateTime; import java.util.List; @RestController @RequestMapping("/airDrop") @AllArgsConstructor public class AirDropController extends BaseController { private AirDropService airDropService; private AirDropRepo airDropRepo; @PreAuthorize("hasAnyRole('ADMIN', 'SAAS')") @PostMapping("/save") public AirDrop save(@RequestBody AirDrop record) { return airDropService.create(record); } //@PreAuthorize("hasRole('ADMIN')") @PostMapping("/all") @PreAuthorize("hasAnyRole('ADMIN', 'SAAS')") public Page all(@RequestBody PageQuery pageQuery) { return airDropService.all(pageQuery); } @GetMapping("/get/{id}") @PreAuthorize("hasAnyRole('ADMIN', 'SAAS')") public AirDrop get(@PathVariable Long id) { return airDropRepo.findById(id).orElseThrow(new BusinessException("无记录")); } @PostMapping("/del/{id}") public void del(@PathVariable Long id) { airDropRepo.softDelete(id); } @GetMapping("/excel") @PreAuthorize("hasAnyRole('ADMIN', 'SAAS')") @ResponseBody public void excel(HttpServletResponse response, PageQuery pageQuery) throws IOException { List data = all(pageQuery).getContent(); ExcelUtils.export(response, data); } @PostMapping("/asyncDrop") public void asyncDrop(Long collectionId, Long userId, int num, LocalDateTime time) { airDropService.asyncDrop(collectionId, userId, num, time); } }