From 6bd5592109bdf764ca5f9f83762f132da7ee64aa Mon Sep 17 00:00:00 2001 From: huangfeng Date: Mon, 8 Jan 2024 09:55:44 +0800 Subject: [PATCH] =?UTF-8?q?pert:=20=E7=BB=9F=E4=B8=80=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xydl/cac/controller/BdzController.java | 42 ++++-------- .../cac/controller/IcdConfigController.java | 54 +++++---------- .../com/xydl/cac/controller/JgController.java | 42 ++++-------- .../com/xydl/cac/controller/LxController.java | 40 ++++------- .../xydl/cac/controller/ModevController.java | 52 +++++---------- .../cac/controller/ModevTypeController.java | 52 +++++---------- .../cac/controller/NiecSensorController.java | 66 +++++++------------ .../xydl/cac/controller/ZsbController.java | 44 ++++--------- .../cac/exception/GlobalExceptionHandler.java | 3 + 9 files changed, 124 insertions(+), 271 deletions(-) diff --git a/src/main/java/com/xydl/cac/controller/BdzController.java b/src/main/java/com/xydl/cac/controller/BdzController.java index 9447bc1..991f2e4 100644 --- a/src/main/java/com/xydl/cac/controller/BdzController.java +++ b/src/main/java/com/xydl/cac/controller/BdzController.java @@ -25,48 +25,32 @@ public class BdzController extends BasicController { @GetMapping("listAll") @ApiOperation("查询全部列表") public Response> listAll() { - try { - List result = service.listAll(); - return Response.success(result); - } catch (Exception ex) { - return Response.fail(ex.getMessage()); - } + List result = service.listAll(); + return Response.success(result); } @PostMapping("add") @ApiOperation("新增") - public Response add(@Validated @RequestBody Bdz item) { - try { - Bdz result = service.add(item); - return Response.success(result); - } catch (Exception ex) { - return Response.fail(ex.getMessage()); - } + public Response add(@Validated @RequestBody Bdz item) throws Exception { + Bdz result = service.add(item); + return Response.success(result); } @PostMapping("update") @ApiOperation("更新") - public Response update(@Validated @RequestBody Bdz item) { - try { - if (item.getId() == null) { - throw new Exception("ID不能为空!"); - } - service.update(item); - return Response.success("OK"); - } catch (Exception ex) { - return Response.fail(ex.getMessage()); + public Response update(@Validated @RequestBody Bdz item) throws Exception { + if (item.getId() == null) { + throw new Exception("ID不能为空!"); } + service.update(item); + return Response.success("OK"); } @PostMapping("delete") @ApiOperation("删除") - public Response delete(@Validated @NotNull(message = "ID不能为空!") Integer id) { - try { - service.delete(id); - return Response.success("OK"); - } catch (Exception ex) { - return Response.fail(ex.getMessage()); - } + public Response delete(@Validated @NotNull(message = "ID不能为空!") Integer id) throws Exception { + service.delete(id); + return Response.success("OK"); } } diff --git a/src/main/java/com/xydl/cac/controller/IcdConfigController.java b/src/main/java/com/xydl/cac/controller/IcdConfigController.java index 220e377..dd54395 100644 --- a/src/main/java/com/xydl/cac/controller/IcdConfigController.java +++ b/src/main/java/com/xydl/cac/controller/IcdConfigController.java @@ -42,68 +42,44 @@ public class IcdConfigController extends BasicController { @GetMapping("list") @ApiOperation("查询全部类型列表") - public Response> list(String iedName) { - try { - List result = configService.list(iedName); - return Response.success(result); - } catch (Exception ex) { - return Response.fail(ex.getMessage()); - } + public Response> list(String iedName) throws Exception { + List result = configService.list(iedName); + return Response.success(result); } @GetMapping("iedList") @ApiOperation("查询IED列表") public Response> iedList() { - try { - List result = configService.iedList(); - return Response.success(result); - } catch (Exception ex) { - return Response.fail(ex.getMessage()); - } + List result = configService.iedList(); + return Response.success(result); } @PostMapping("update") @ApiOperation("更新ICD类型配置") public Response update(@RequestBody IcdFileConfig item) { - try { - configService.update(item); - return Response.success("OK"); - } catch (Exception ex) { - return Response.fail(ex.getMessage()); - } + configService.update(item); + return Response.success("OK"); } @PostMapping("delete") @ApiOperation("删除ICD类型配置") public Response delete(@Validated @NotNull(message = "ID不能为空!") Integer id) { - try { - configService.delete(id); - return Response.success("OK"); - } catch (Exception ex) { - return Response.fail(ex.getMessage()); - } + configService.delete(id); + return Response.success("OK"); } @GetMapping("tableList") @ApiOperation("查询data表名") - public Response> tableList() { - try { - List result = dataService.getDataTables(); - return Response.success(result); - } catch (Exception ex) { - return Response.fail(ex.getMessage()); - } + public Response> tableList() throws Exception { + List result = dataService.getDataTables(); + return Response.success(result); } @GetMapping("colList") @ApiOperation("查询data表字段名") - public Response> colList(String tableName) { - try { - List result = dataService.getDataTableColumns(tableName); - return Response.success(result); - } catch (Exception ex) { - return Response.fail(ex.getMessage()); - } + public Response> colList(String tableName) throws Exception { + List result = dataService.getDataTableColumns(tableName); + return Response.success(result); } } diff --git a/src/main/java/com/xydl/cac/controller/JgController.java b/src/main/java/com/xydl/cac/controller/JgController.java index 7c287e6..b262c40 100644 --- a/src/main/java/com/xydl/cac/controller/JgController.java +++ b/src/main/java/com/xydl/cac/controller/JgController.java @@ -25,48 +25,32 @@ public class JgController extends BasicController { @GetMapping("listAll") @ApiOperation("查询列表") public Response> listAll(Integer bdzid) { - try { - List result = service.listAll(bdzid); - return Response.success(result); - } catch (Exception ex) { - return Response.fail(ex.getMessage()); - } + List result = service.listAll(bdzid); + return Response.success(result); } @PostMapping("add") @ApiOperation("新增") - public Response add(@Validated @RequestBody Jg item) { - try { - Jg result = service.add(item); - return Response.success(result); - } catch (Exception ex) { - return Response.fail(ex.getMessage()); - } + public Response add(@Validated @RequestBody Jg item) throws Exception { + Jg result = service.add(item); + return Response.success(result); } @PostMapping("update") @ApiOperation("更新") - public Response update(@Validated @RequestBody Jg item) { - try { - if (item.getId() == null) { - throw new Exception("ID不能为空!"); - } - service.update(item); - return Response.success("OK"); - } catch (Exception ex) { - return Response.fail(ex.getMessage()); + public Response update(@Validated @RequestBody Jg item) throws Exception { + if (item.getId() == null) { + throw new Exception("ID不能为空!"); } + service.update(item); + return Response.success("OK"); } @PostMapping("delete") @ApiOperation("删除") - public Response delete(@Validated @NotNull(message = "ID不能为空!") Integer id) { - try { - service.delete(id); - return Response.success("OK"); - } catch (Exception ex) { - return Response.fail(ex.getMessage()); - } + public Response delete(@Validated @NotNull(message = "ID不能为空!") Integer id) throws Exception { + service.delete(id); + return Response.success("OK"); } } diff --git a/src/main/java/com/xydl/cac/controller/LxController.java b/src/main/java/com/xydl/cac/controller/LxController.java index db17a09..4be5b10 100644 --- a/src/main/java/com/xydl/cac/controller/LxController.java +++ b/src/main/java/com/xydl/cac/controller/LxController.java @@ -25,48 +25,32 @@ public class LxController extends BasicController { @GetMapping("listAll") @ApiOperation("查询全部列表") public Response> listAll() { - try { - List result = service.listAll(); - return Response.success(result); - } catch (Exception ex) { - return Response.fail(ex.getMessage()); - } + List result = service.listAll(); + return Response.success(result); } @PostMapping("add") @ApiOperation("新增") - public Response add(@Validated @RequestBody Lx item) { - try { - Lx result = service.add(item); - return Response.success(result); - } catch (Exception ex) { - return Response.fail(ex.getMessage()); - } + public Response add(@Validated @RequestBody Lx item) throws Exception { + Lx result = service.add(item); + return Response.success(result); } @PostMapping("update") @ApiOperation("更新") - public Response update(@Validated @RequestBody Lx item) { - try { - if (item.getId() == null) { - throw new Exception("ID不能为空!"); - } - service.update(item); - return Response.success("OK"); - } catch (Exception ex) { - return Response.fail(ex.getMessage()); + public Response update(@Validated @RequestBody Lx item) throws Exception { + if (item.getId() == null) { + throw new Exception("ID不能为空!"); } + service.update(item); + return Response.success("OK"); } @PostMapping("delete") @ApiOperation("删除") public Response delete(@Validated @NotNull(message = "ID不能为空!") Integer id) { - try { - service.delete(id); - return Response.success("OK"); - } catch (Exception ex) { - return Response.fail(ex.getMessage()); - } + service.delete(id); + return Response.success("OK"); } } diff --git a/src/main/java/com/xydl/cac/controller/ModevController.java b/src/main/java/com/xydl/cac/controller/ModevController.java index f3a64c8..62c8899 100644 --- a/src/main/java/com/xydl/cac/controller/ModevController.java +++ b/src/main/java/com/xydl/cac/controller/ModevController.java @@ -28,59 +28,39 @@ public class ModevController extends BasicController { @GetMapping("listAll") @ApiOperation("查询列表") public Response> listAll(@NotNull(message = "主设备编号不能缺少") @Param("zsbid") Integer zsbid) { - try { - List result = service.listAll(zsbid); - return Response.success(result); - } catch (Exception ex) { - return Response.fail(ex.getMessage()); - } + List result = service.listAll(zsbid); + return Response.success(result); } @PostMapping("add") @ApiOperation("新增") - public Response add(@Validated @RequestBody Modev item) { - try { - Modev result = service.add(item); - return Response.success(result); - } catch (Exception ex) { - return Response.fail(ex.getMessage()); - } + public Response add(@Validated @RequestBody Modev item) throws Exception { + Modev result = service.add(item); + return Response.success(result); } @PostMapping("update") @ApiOperation("更新") - public Response update(@Validated @RequestBody Modev item) { - try { - if (item.getId() == null) { - throw new Exception("ID不能为空!"); - } - service.update(item); - return Response.success("OK"); - } catch (Exception ex) { - return Response.fail(ex.getMessage()); + public Response update(@Validated @RequestBody Modev item) throws Exception { + if (item.getId() == null) { + throw new Exception("ID不能为空!"); } + service.update(item); + return Response.success("OK"); } @PostMapping("delete") @ApiOperation("删除") - public Response delete(@Validated @NotNull(message = "ID不能为空!") @Param("id") Integer id) { - try { - service.delete(id); - return Response.success("OK"); - } catch (Exception ex) { - return Response.fail(ex.getMessage()); - } + public Response delete(@Validated @NotNull(message = "ID不能为空!") @Param("id") Integer id) { + service.delete(id); + return Response.success("OK"); } @PostMapping("detail") @ApiOperation("详情") - public Response detail(@Validated @NotNull(message = "ID不能为空!") Integer id) { - try { - Modev detail = service.detail(id); - return Response.success(detail); - } catch (Exception ex) { - return Response.fail(ex.getMessage()); - } + public Response detail(@Validated @NotNull(message = "ID不能为空!") Integer id) throws Exception { + Modev detail = service.detail(id); + return Response.success(detail); } } diff --git a/src/main/java/com/xydl/cac/controller/ModevTypeController.java b/src/main/java/com/xydl/cac/controller/ModevTypeController.java index b475b1a..8e3226f 100644 --- a/src/main/java/com/xydl/cac/controller/ModevTypeController.java +++ b/src/main/java/com/xydl/cac/controller/ModevTypeController.java @@ -25,59 +25,39 @@ public class ModevTypeController extends BasicController { @GetMapping("listAll") @ApiOperation("查询列表") public Response> listAll() { - try { - List result = service.listAll(); - return Response.success(result); - } catch (Exception ex) { - return Response.fail(ex.getMessage()); - } + List result = service.listAll(); + return Response.success(result); } @PostMapping("add") @ApiOperation("新增") - public Response add(@Validated @RequestBody ModevType item) { - try { - ModevType result = service.add(item); - return Response.success(result); - } catch (Exception ex) { - return Response.fail(ex.getMessage()); - } + public Response add(@Validated @RequestBody ModevType item) throws Exception { + ModevType result = service.add(item); + return Response.success(result); } @PostMapping("update") @ApiOperation("更新") - public Response update(@Validated @RequestBody ModevType item) { - try { - if (item.getId() == null) { - throw new Exception("ID不能为空!"); - } - service.update(item); - return Response.success("OK"); - } catch (Exception ex) { - return Response.fail(ex.getMessage()); + public Response update(@Validated @RequestBody ModevType item) throws Exception { + if (item.getId() == null) { + throw new Exception("ID不能为空!"); } + service.update(item); + return Response.success("OK"); } @PostMapping("delete") @ApiOperation("删除") - public Response delete(@Validated @NotNull(message = "ID不能为空!") Integer id) { - try { - service.delete(id); - return Response.success("OK"); - } catch (Exception ex) { - return Response.fail(ex.getMessage()); - } + public Response delete(@Validated @NotNull(message = "ID不能为空!") Integer id) { + service.delete(id); + return Response.success("OK"); } @PostMapping("detail") @ApiOperation("详情") - public Response detail(@Validated @NotNull(message = "ID不能为空!") Integer id) { - try { - ModevType detail = service.detail(id); - return Response.success(detail); - } catch (Exception ex) { - return Response.fail(ex.getMessage()); - } + public Response detail(@Validated @NotNull(message = "ID不能为空!") Integer id) throws Exception { + ModevType detail = service.detail(id); + return Response.success(detail); } } diff --git a/src/main/java/com/xydl/cac/controller/NiecSensorController.java b/src/main/java/com/xydl/cac/controller/NiecSensorController.java index 075be9c..5885212 100644 --- a/src/main/java/com/xydl/cac/controller/NiecSensorController.java +++ b/src/main/java/com/xydl/cac/controller/NiecSensorController.java @@ -40,70 +40,48 @@ public class NiecSensorController extends BasicController { @ApiParam("每页数量") @RequestParam(value = "pageSize", required = false) Integer pageSize) { pageNum = this.initPageNum(pageNum); pageSize = this.initPageSize(pageSize); - try { - Page result = service.list(pageNum, pageSize); - return Response.success(result); - } catch (Exception ex) { - return Response.fail(ex.getMessage()); - } + Page result = service.list(pageNum, pageSize); + return Response.success(result); } @GetMapping("listAll") @ApiOperation("查询全部列表") public Response> listAll() { - try { - List result = service.listAll(); - return Response.success(result); - } catch (Exception ex) { - return Response.fail(ex.getMessage()); - } + List result = service.listAll(); + return Response.success(result); } @GetMapping("getTree") @ApiOperation("查询树") public Response> getTree() { - try { - List result = service.getTree(); - return Response.success(result); - } catch (Exception ex) { - log.error("getTree Exception.", ex); - return Response.fail(ex.getMessage()); - } + List result = service.getTree(); + return Response.success(result); } @GetMapping("detail") @ApiOperation("查询单个装置采集到的数据") - public Response getDetail(@Validated ConditionModel model) { - try { - if (model.getPageNum() != null || model.getPageSize() != null) { - model.setPageNum(this.initPageNum(model.getPageNum())); - model.setPageSize(this.initPageSize(model.getPageSize())); - } - SensorDetail result = service.getDetail(model); - return Response.success(result); - } catch (Exception ex) { - log.error("getDetail Exception.", ex); - return Response.fail(ex.getMessage()); + public Response getDetail(@Validated ConditionModel model) throws Exception { + if (model.getPageNum() != null || model.getPageSize() != null) { + model.setPageNum(this.initPageNum(model.getPageNum())); + model.setPageSize(this.initPageSize(model.getPageSize())); } + SensorDetail result = service.getDetail(model); + return Response.success(result); } @GetMapping("export") @ApiOperation("导出单个装置采集到的数据") - public void export(@Validated ConditionModel model, HttpServletResponse response) { - try { - if (model.getPageNum() != null || model.getPageSize() != null) { - model.setPageNum(this.initPageNum(model.getPageNum())); - model.setPageSize(this.initPageSize(model.getPageSize())); - } - SensorDetail> detail = service.getDetail(model); - response.setHeader("Content-Disposition", "attachment; filename=" - + URLEncoder.encode(detail.getSensor().getName() + ".xlsx", "UTF-8")); - response.setContentType("application/vnd.ms-excel"); - response.setCharacterEncoding("utf-8"); - reportService.exportSensor(detail, response.getOutputStream()); - } catch (Exception ex) { - log.error("exportDetail Exception.", ex); + public void export(@Validated ConditionModel model, HttpServletResponse response) throws Exception { + if (model.getPageNum() != null || model.getPageSize() != null) { + model.setPageNum(this.initPageNum(model.getPageNum())); + model.setPageSize(this.initPageSize(model.getPageSize())); } + SensorDetail> detail = service.getDetail(model); + response.setHeader("Content-Disposition", "attachment; filename=" + + URLEncoder.encode(detail.getSensor().getName() + ".xlsx", "UTF-8")); + response.setContentType("application/vnd.ms-excel"); + response.setCharacterEncoding("utf-8"); + reportService.exportSensor(detail, response.getOutputStream()); } } diff --git a/src/main/java/com/xydl/cac/controller/ZsbController.java b/src/main/java/com/xydl/cac/controller/ZsbController.java index 909ad03..8a23896 100644 --- a/src/main/java/com/xydl/cac/controller/ZsbController.java +++ b/src/main/java/com/xydl/cac/controller/ZsbController.java @@ -24,49 +24,33 @@ public class ZsbController extends BasicController { @GetMapping("listAll") @ApiOperation("查询全部列表") - public Response> listAll(Integer jgid) { - try { - List result = service.listAll(jgid); - return Response.success(result); - } catch (Exception ex) { - return Response.fail(ex.getMessage()); - } + public Response> listAll(Integer jgid) throws Exception { + List result = service.listAll(jgid); + return Response.success(result); } @PostMapping("add") @ApiOperation("新增") - public Response add(@Validated @RequestBody Zsb item) { - try { - Zsb result = service.add(item); - return Response.success(result); - } catch (Exception ex) { - return Response.fail(ex.getMessage()); - } + public Response add(@Validated @RequestBody Zsb item) throws Exception { + Zsb result = service.add(item); + return Response.success(result); } @PostMapping("update") @ApiOperation("更新") - public Response update(@Validated @RequestBody Zsb item) { - try { - if (item.getId() == null) { - throw new Exception("ID不能为空!"); - } - service.update(item); - return Response.success("OK"); - } catch (Exception ex) { - return Response.fail(ex.getMessage()); + public Response update(@Validated @RequestBody Zsb item) throws Exception { + if (item.getId() == null) { + throw new Exception("ID不能为空!"); } + service.update(item); + return Response.success("OK"); } @PostMapping("delete") @ApiOperation("删除") - public Response delete(@Validated @NotNull(message = "ID不能为空!") Integer id) { - try { - service.delete(id); - return Response.success("OK"); - } catch (Exception ex) { - return Response.fail(ex.getMessage()); - } + public Response delete(@Validated @NotNull(message = "ID不能为空!") Integer id) throws Exception { + service.delete(id); + return Response.success("OK"); } } diff --git a/src/main/java/com/xydl/cac/exception/GlobalExceptionHandler.java b/src/main/java/com/xydl/cac/exception/GlobalExceptionHandler.java index 436154b..5bd73ed 100644 --- a/src/main/java/com/xydl/cac/exception/GlobalExceptionHandler.java +++ b/src/main/java/com/xydl/cac/exception/GlobalExceptionHandler.java @@ -1,6 +1,7 @@ package com.xydl.cac.exception; import com.xydl.cac.model.Response; +import lombok.extern.slf4j.Slf4j; import org.springframework.validation.FieldError; import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.annotation.ExceptionHandler; @@ -9,6 +10,7 @@ import org.springframework.web.bind.annotation.RestControllerAdvice; import java.util.stream.Collectors; @RestControllerAdvice +@Slf4j public class GlobalExceptionHandler { @ExceptionHandler(MethodArgumentNotValidException.class) @@ -21,6 +23,7 @@ public class GlobalExceptionHandler { @ExceptionHandler(Exception.class) public Response handleException(Exception ex) { + log.error("", ex); String message = ex.getMessage(); return Response.fail(message); }