| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- package com.izouma.nineth.web;
- import com.alibaba.fastjson.JSONArray;
- import com.izouma.nineth.config.MetaConstants;
- import com.izouma.nineth.domain.RaexSnapshot;
- import com.izouma.nineth.dto.PageQuery;
- import com.izouma.nineth.dto.SnapshotDTO;
- import com.izouma.nineth.exception.BusinessException;
- import com.izouma.nineth.repo.RaexSnapshotRepo;
- import com.izouma.nineth.service.RaexSnapshotService;
- import com.izouma.nineth.utils.ObjUtils;
- 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;
- import java.util.Map;
- @RestController
- @RequestMapping("/raexSnapshot")
- @AllArgsConstructor
- public class RaexSnapshotController extends BaseController {
- private RaexSnapshotService raexSnapshotService;
- private RaexSnapshotRepo raexSnapshotRepo;
- //@PreAuthorize("hasRole('ADMIN')")
- @PostMapping("/save")
- public RaexSnapshot save(@RequestBody RaexSnapshot record) {
- if (record.getId() != null) {
- RaexSnapshot orig = raexSnapshotRepo.findById(record.getId()).orElseThrow(new BusinessException("无记录"));
- ObjUtils.merge(orig, record);
- return raexSnapshotRepo.save(orig);
- }
- return raexSnapshotRepo.save(record);
- }
- //@PreAuthorize("hasRole('ADMIN')")
- @PostMapping("/all")
- public Page<RaexSnapshot> all(@RequestBody PageQuery pageQuery) {
- return raexSnapshotService.all(pageQuery);
- }
- @GetMapping("/get/{id}")
- public RaexSnapshot get(@PathVariable Long id) {
- return raexSnapshotRepo.findById(id).orElseThrow(new BusinessException("无记录"));
- }
- @PostMapping("/del/{id}")
- public void del(@PathVariable Long id) {
- raexSnapshotRepo.softDelete(id);
- }
- @GetMapping("/excel")
- @ResponseBody
- public void excel(HttpServletResponse response, PageQuery pageQuery) throws IOException {
- List<RaexSnapshot> data = all(pageQuery).getContent();
- ExcelUtils.export(response, data);
- }
- @GetMapping("/shot")
- @ResponseBody
- public void shot(HttpServletResponse response, String name, String time) throws IOException {
- List<Map<String, Object>> map = raexSnapshotRepo.shot(MetaConstants.LIKE.concat(name).concat(MetaConstants.LIKE), time);
- List<SnapshotDTO> snapshotDTOS = mapToList(map);
- ExcelUtils.export(response, snapshotDTOS);
- }
- private List<SnapshotDTO> mapToList(List<Map<String, Object>> map) {
- if (CollectionUtils.isEmpty(map)) {
- throw new BusinessException("无数据");
- }
- JSONArray jsonArray = new JSONArray();
- jsonArray.addAll(map);
- return jsonArray.toJavaList(SnapshotDTO.class);
- }
- }
|