|
|
@@ -0,0 +1,60 @@
|
|
|
+package com.izouma.wenlvju.web;
|
|
|
+import com.izouma.wenlvju.domain.Record;
|
|
|
+import com.izouma.wenlvju.service.RecordService;
|
|
|
+import com.izouma.wenlvju.dto.PageQuery;
|
|
|
+import com.izouma.wenlvju.exception.BusinessException;
|
|
|
+import com.izouma.wenlvju.repo.RecordRepo;
|
|
|
+import com.izouma.wenlvju.utils.ObjUtils;
|
|
|
+import com.izouma.wenlvju.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.util.List;
|
|
|
+
|
|
|
+@RestController
|
|
|
+@RequestMapping("/record")
|
|
|
+@AllArgsConstructor
|
|
|
+public class RecordController extends BaseController {
|
|
|
+ private RecordService recordService;
|
|
|
+ private RecordRepo recordRepo;
|
|
|
+
|
|
|
+ //@PreAuthorize("hasRole('ADMIN')")
|
|
|
+ @PostMapping("/save")
|
|
|
+ public Record save(@RequestBody Record record) {
|
|
|
+ if (record.getId() != null) {
|
|
|
+ Record orig = recordRepo.findById(record.getId()).orElseThrow(new BusinessException("无记录"));
|
|
|
+ ObjUtils.merge(orig, record);
|
|
|
+ return recordRepo.save(orig);
|
|
|
+ }
|
|
|
+ return recordRepo.save(record);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //@PreAuthorize("hasRole('ADMIN')")
|
|
|
+ @PostMapping("/all")
|
|
|
+ public Page<Record> all(@RequestBody PageQuery pageQuery) {
|
|
|
+ return recordService.all(pageQuery);
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/get/{id}")
|
|
|
+ public Record get(@PathVariable Long id) {
|
|
|
+ return recordRepo.findById(id).orElseThrow(new BusinessException("无记录"));
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/del/{id}")
|
|
|
+ public void del(@PathVariable Long id) {
|
|
|
+ recordRepo.softDelete(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/excel")
|
|
|
+ @ResponseBody
|
|
|
+ public void excel(HttpServletResponse response, PageQuery pageQuery) throws IOException {
|
|
|
+ List<Record> data = all(pageQuery).getContent();
|
|
|
+ ExcelUtils.export(response, data);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|