pert: 统一异常处理

iec104
huangfeng 1 year ago
parent 5e4ebe4296
commit 6bd5592109

@ -25,48 +25,32 @@ public class BdzController extends BasicController {
@GetMapping("listAll")
@ApiOperation("查询全部列表")
public Response<List<Bdz>> listAll() {
try {
List<Bdz> result = service.listAll();
return Response.success(result);
} catch (Exception ex) {
return Response.fail(ex.getMessage());
}
List<Bdz> result = service.listAll();
return Response.success(result);
}
@PostMapping("add")
@ApiOperation("新增")
public Response<Bdz> 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<Bdz> add(@Validated @RequestBody Bdz item) throws Exception {
Bdz result = service.add(item);
return Response.success(result);
}
@PostMapping("update")
@ApiOperation("更新")
public Response<String> 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<String> 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<String> 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<String> delete(@Validated @NotNull(message = "ID不能为空!") Integer id) throws Exception {
service.delete(id);
return Response.success("OK");
}
}

@ -42,68 +42,44 @@ public class IcdConfigController extends BasicController {
@GetMapping("list")
@ApiOperation("查询全部类型列表")
public Response<List<IcdFileConfig>> list(String iedName) {
try {
List<IcdFileConfig> result = configService.list(iedName);
return Response.success(result);
} catch (Exception ex) {
return Response.fail(ex.getMessage());
}
public Response<List<IcdFileConfig>> list(String iedName) throws Exception {
List<IcdFileConfig> result = configService.list(iedName);
return Response.success(result);
}
@GetMapping("iedList")
@ApiOperation("查询IED列表")
public Response<List<String>> iedList() {
try {
List<String> result = configService.iedList();
return Response.success(result);
} catch (Exception ex) {
return Response.fail(ex.getMessage());
}
List<String> result = configService.iedList();
return Response.success(result);
}
@PostMapping("update")
@ApiOperation("更新ICD类型配置")
public Response<String> 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<String> 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<List<String>> tableList() {
try {
List<String> result = dataService.getDataTables();
return Response.success(result);
} catch (Exception ex) {
return Response.fail(ex.getMessage());
}
public Response<List<String>> tableList() throws Exception {
List<String> result = dataService.getDataTables();
return Response.success(result);
}
@GetMapping("colList")
@ApiOperation("查询data表字段名")
public Response<List<String>> colList(String tableName) {
try {
List<String> result = dataService.getDataTableColumns(tableName);
return Response.success(result);
} catch (Exception ex) {
return Response.fail(ex.getMessage());
}
public Response<List<String>> colList(String tableName) throws Exception {
List<String> result = dataService.getDataTableColumns(tableName);
return Response.success(result);
}
}

@ -25,48 +25,32 @@ public class JgController extends BasicController {
@GetMapping("listAll")
@ApiOperation("查询列表")
public Response<List<Jg>> listAll(Integer bdzid) {
try {
List<Jg> result = service.listAll(bdzid);
return Response.success(result);
} catch (Exception ex) {
return Response.fail(ex.getMessage());
}
List<Jg> result = service.listAll(bdzid);
return Response.success(result);
}
@PostMapping("add")
@ApiOperation("新增")
public Response<Jg> 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<Jg> add(@Validated @RequestBody Jg item) throws Exception {
Jg result = service.add(item);
return Response.success(result);
}
@PostMapping("update")
@ApiOperation("更新")
public Response<String> 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<String> 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<String> 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<String> delete(@Validated @NotNull(message = "ID不能为空!") Integer id) throws Exception {
service.delete(id);
return Response.success("OK");
}
}

@ -25,48 +25,32 @@ public class LxController extends BasicController {
@GetMapping("listAll")
@ApiOperation("查询全部列表")
public Response<List<Lx>> listAll() {
try {
List<Lx> result = service.listAll();
return Response.success(result);
} catch (Exception ex) {
return Response.fail(ex.getMessage());
}
List<Lx> result = service.listAll();
return Response.success(result);
}
@PostMapping("add")
@ApiOperation("新增")
public Response<Lx> 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<Lx> add(@Validated @RequestBody Lx item) throws Exception {
Lx result = service.add(item);
return Response.success(result);
}
@PostMapping("update")
@ApiOperation("更新")
public Response<String> 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<String> 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<String> 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");
}
}

@ -28,59 +28,39 @@ public class ModevController extends BasicController {
@GetMapping("listAll")
@ApiOperation("查询列表")
public Response<List<Modev>> listAll(@NotNull(message = "主设备编号不能缺少") @Param("zsbid") Integer zsbid) {
try {
List<Modev> result = service.listAll(zsbid);
return Response.success(result);
} catch (Exception ex) {
return Response.fail(ex.getMessage());
}
List<Modev> result = service.listAll(zsbid);
return Response.success(result);
}
@PostMapping("add")
@ApiOperation("新增")
public Response<Modev> 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<Modev> add(@Validated @RequestBody Modev item) throws Exception {
Modev result = service.add(item);
return Response.success(result);
}
@PostMapping("update")
@ApiOperation("更新")
public Response<String> 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<String> 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<String> 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<String> delete(@Validated @NotNull(message = "ID不能为空!") @Param("id") Integer id) {
service.delete(id);
return Response.success("OK");
}
@PostMapping("detail")
@ApiOperation("详情")
public Response<Modev> 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<Modev> detail(@Validated @NotNull(message = "ID不能为空!") Integer id) throws Exception {
Modev detail = service.detail(id);
return Response.success(detail);
}
}

@ -25,59 +25,39 @@ public class ModevTypeController extends BasicController {
@GetMapping("listAll")
@ApiOperation("查询列表")
public Response<List<ModevType>> listAll() {
try {
List<ModevType> result = service.listAll();
return Response.success(result);
} catch (Exception ex) {
return Response.fail(ex.getMessage());
}
List<ModevType> result = service.listAll();
return Response.success(result);
}
@PostMapping("add")
@ApiOperation("新增")
public Response<ModevType> 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<ModevType> add(@Validated @RequestBody ModevType item) throws Exception {
ModevType result = service.add(item);
return Response.success(result);
}
@PostMapping("update")
@ApiOperation("更新")
public Response<String> 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<String> 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<String> 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<String> delete(@Validated @NotNull(message = "ID不能为空!") Integer id) {
service.delete(id);
return Response.success("OK");
}
@PostMapping("detail")
@ApiOperation("详情")
public Response<ModevType> 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<ModevType> detail(@Validated @NotNull(message = "ID不能为空!") Integer id) throws Exception {
ModevType detail = service.detail(id);
return Response.success(detail);
}
}

@ -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<NiecSensor> result = service.list(pageNum, pageSize);
return Response.success(result);
} catch (Exception ex) {
return Response.fail(ex.getMessage());
}
Page<NiecSensor> result = service.list(pageNum, pageSize);
return Response.success(result);
}
@GetMapping("listAll")
@ApiOperation("查询全部列表")
public Response<List<NiecSensor>> listAll() {
try {
List<NiecSensor> result = service.listAll();
return Response.success(result);
} catch (Exception ex) {
return Response.fail(ex.getMessage());
}
List<NiecSensor> result = service.listAll();
return Response.success(result);
}
@GetMapping("getTree")
@ApiOperation("查询树")
public Response<List<NiecSensor>> getTree() {
try {
List<NiecSensor> result = service.getTree();
return Response.success(result);
} catch (Exception ex) {
log.error("getTree Exception.", ex);
return Response.fail(ex.getMessage());
}
List<NiecSensor> result = service.getTree();
return Response.success(result);
}
@GetMapping("detail")
@ApiOperation("查询单个装置采集到的数据")
public Response<SensorDetail> 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<SensorDetail> 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<Map<String, Object>> 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<Map<String, Object>> 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());
}
}

@ -24,49 +24,33 @@ public class ZsbController extends BasicController {
@GetMapping("listAll")
@ApiOperation("查询全部列表")
public Response<List<Zsb>> listAll(Integer jgid) {
try {
List<Zsb> result = service.listAll(jgid);
return Response.success(result);
} catch (Exception ex) {
return Response.fail(ex.getMessage());
}
public Response<List<Zsb>> listAll(Integer jgid) throws Exception {
List<Zsb> result = service.listAll(jgid);
return Response.success(result);
}
@PostMapping("add")
@ApiOperation("新增")
public Response<Zsb> 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<Zsb> add(@Validated @RequestBody Zsb item) throws Exception {
Zsb result = service.add(item);
return Response.success(result);
}
@PostMapping("update")
@ApiOperation("更新")
public Response<String> 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<String> 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<String> 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<String> delete(@Validated @NotNull(message = "ID不能为空!") Integer id) throws Exception {
service.delete(id);
return Response.success("OK");
}
}

@ -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<String> handleException(Exception ex) {
log.error("", ex);
String message = ex.getMessage();
return Response.fail(message);
}

Loading…
Cancel
Save