package com.izouma.nineth.web; import com.izouma.nineth.domain.Showroom; import com.izouma.nineth.dto.PageQuery; import com.izouma.nineth.exception.BusinessException; import com.izouma.nineth.repo.ShowCollectionRepo; import com.izouma.nineth.repo.ShowroomRepo; import com.izouma.nineth.service.ShowroomService; import com.izouma.nineth.utils.SecurityUtils; import com.izouma.nineth.utils.excel.ExcelUtils; import lombok.AllArgsConstructor; 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("/showroom") @AllArgsConstructor public class ShowroomController extends BaseController { private ShowroomService showroomService; private ShowroomRepo showroomRepo; private ShowCollectionRepo showCollectionRepo; //@PreAuthorize("hasRole('ADMIN')") @PostMapping("/save") public Showroom save(@RequestBody Showroom record) { // if (record.getId() != null) { // Showroom orig = showroomRepo.findById(record.getId()).orElseThrow(new BusinessException("无记录")); // ObjUtils.merge(orig, record); // return showroomRepo.save(orig); // } // return showroomRepo.save(record); return showroomService.save(SecurityUtils.getAuthenticatedUser().getId(), record); } @PostMapping("/update") public Showroom update(@RequestBody Showroom record) { return showroomService.update(SecurityUtils.getAuthenticatedUser().getId(), record); } //@PreAuthorize("hasRole('ADMIN')") @PostMapping("/all") public Page all(@RequestBody PageQuery pageQuery) { return showroomService.all(pageQuery); } @GetMapping("/get/{id}") public Showroom get(@PathVariable Long id) { return showroomRepo.findById(id).orElseThrow(new BusinessException("无记录")); } @PostMapping("/del/{id}") public void del(@PathVariable Long id) { showCollectionRepo.softDeleteByRoom(id); showroomRepo.softDelete(id); } @GetMapping("/excel") @ResponseBody public void excel(HttpServletResponse response, PageQuery pageQuery) throws IOException { List data = all(pageQuery).getContent(); ExcelUtils.export(response, data); } }