package com.izouma.nineth.web; import com.izouma.nineth.domain.PhotoAsset; import com.izouma.nineth.enums.CollectionStatus; import com.izouma.nineth.service.PhotoAssetService; import com.izouma.nineth.dto.PageQuery; import com.izouma.nineth.exception.BusinessException; import com.izouma.nineth.repo.PhotoAssetRepo; import com.izouma.nineth.utils.ObjUtils; import com.izouma.nineth.utils.SecurityUtils; import com.izouma.nineth.utils.excel.ExcelUtils; import io.swagger.annotations.ApiOperation; import lombok.AllArgsConstructor; import org.springframework.boot.autoconfigure.data.elasticsearch.ReactiveElasticsearchRepositoriesAutoConfiguration; 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.util.List; @RestController @RequestMapping("/photoAsset") @AllArgsConstructor public class PhotoAssetController extends BaseController { private PhotoAssetService photoAssetService; private PhotoAssetRepo photoAssetRepo; //@PreAuthorize("hasRole('ADMIN')") @PostMapping("/save") public PhotoAsset save(@RequestBody PhotoAsset record) { return photoAssetService.save(record); } @PreAuthorize("hasRole('ADMIN')") @PostMapping("/pass") public void pass(@RequestParam Long id) { photoAssetService.pass(photoAssetRepo.findById(id).orElseThrow(new BusinessException("未找到星图"))); } @PreAuthorize("hasRole('ADMIN')") @PostMapping("/deny") public void deny(@RequestParam Long id) { photoAssetService.deny(id); } // @PreAuthorize("hasRole('ADMIN')") @PostMapping("/all") public Page all(@RequestBody PageQuery pageQuery) { return photoAssetService.all(pageQuery); } @GetMapping("/get/{id}") public PhotoAsset get(@PathVariable Long id) { return photoAssetRepo.findById(id).orElseThrow(new BusinessException("无记录")); } @PostMapping("/del/{id}") public void del(@PathVariable Long id) { photoAssetRepo.softDelete(id); } @GetMapping("/excel") @ResponseBody public void excel(HttpServletResponse response, PageQuery pageQuery) throws IOException { List data = all(pageQuery).getContent(); ExcelUtils.export(response, data); } }