集成全局异常
parent
eb692d1e59
commit
7a1dfe1f90
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,41 @@
|
||||||
|
package com.etl.cleaning.controller;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
|
import com.etl.cleaning.domian.pojo.DataPlace;
|
||||||
|
import com.etl.cleaning.domian.request.TableRequest;
|
||||||
|
import com.etl.cleaning.service.PlaceService;
|
||||||
|
import com.etl.common.result.Result;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取表名控制器
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/dataTable")
|
||||||
|
public class GetTableController {
|
||||||
|
|
||||||
|
private final PlaceService placeService;
|
||||||
|
|
||||||
|
public GetTableController(PlaceService placeService) {
|
||||||
|
this.placeService = placeService;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取所有表名
|
||||||
|
*
|
||||||
|
* @param tableRequest
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping("/getTableName")
|
||||||
|
public Result getTableName(@RequestBody TableRequest tableRequest) {
|
||||||
|
LambdaUpdateWrapper<DataPlace> eqed = new LambdaUpdateWrapper<DataPlace>().eq(DataPlace::getName, tableRequest.getName()).or().eq(DataPlace::getTypeId, tableRequest.getTypeId());
|
||||||
|
DataPlace dataPlace = placeService.getOne(eqed);
|
||||||
|
if (dataPlace == null) {
|
||||||
|
throw new RuntimeException("您所选中的数据源不存在");
|
||||||
|
}
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,8 +1,5 @@
|
||||||
package com.etl.cleaning.controller;
|
package com.etl.cleaning.controller;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
||||||
import com.etl.cleaning.domian.pojo.DataPlace;
|
|
||||||
import com.etl.cleaning.domian.request.InsertPlaceRequest;
|
import com.etl.cleaning.domian.request.InsertPlaceRequest;
|
||||||
import com.etl.cleaning.domian.request.PlaceRequest;
|
import com.etl.cleaning.domian.request.PlaceRequest;
|
||||||
import com.etl.cleaning.service.PlaceService;
|
import com.etl.cleaning.service.PlaceService;
|
||||||
|
|
|
@ -23,11 +23,9 @@ import java.util.List;
|
||||||
@RequestMapping("/role-type")
|
@RequestMapping("/role-type")
|
||||||
public class RoleTypeController {
|
public class RoleTypeController {
|
||||||
private final RoleTypeService roleTypeService;
|
private final RoleTypeService roleTypeService;
|
||||||
|
|
||||||
public RoleTypeController(RoleTypeService roleTypeService) {
|
public RoleTypeController(RoleTypeService roleTypeService) {
|
||||||
this.roleTypeService = roleTypeService;
|
this.roleTypeService = roleTypeService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 规则类型列表
|
* 规则类型列表
|
||||||
* @return
|
* @return
|
||||||
|
|
|
@ -29,12 +29,14 @@ public class TypeController {
|
||||||
return Result.success(list);
|
return Result.success(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* 测试mysql链接
|
测试mysql链接
|
||||||
* @return
|
@return
|
||||||
*/
|
*/
|
||||||
// @GetMapping("/testMysql")
|
/*
|
||||||
// public Result testMysql(){
|
@GetMapping("/testMysql")
|
||||||
// ServerTest.testDatabaseConnection()
|
public Result testMysql(){
|
||||||
// }
|
ServerTest.testDatabaseConnection()
|
||||||
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,3 +74,4 @@ public class DataPlace {
|
||||||
*/
|
*/
|
||||||
private String dataUrl;
|
private String dataUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,3 +36,4 @@ public class DataRole {
|
||||||
*/
|
*/
|
||||||
private Long typeId;
|
private Long typeId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,3 +46,4 @@ public class DataTask {
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,3 +27,4 @@ public class DateType {
|
||||||
*/
|
*/
|
||||||
private String name;
|
private String name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,3 +24,4 @@ public class RoleType {
|
||||||
*/
|
*/
|
||||||
private String name;
|
private String name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package com.etl.cleaning.domian.request;
|
package com.etl.cleaning.domian.request;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.springframework.format.annotation.DateTimeFormat;
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
@ -64,3 +63,4 @@ public class InsertPlaceRequest {
|
||||||
@NotBlank(message = "连接地址不能为空")
|
@NotBlank(message = "连接地址不能为空")
|
||||||
private String dataUrl;
|
private String dataUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,3 +38,4 @@ public class InsertTaskRequest {
|
||||||
@NotBlank(message = "任务备注不能为空")
|
@NotBlank(message = "任务备注不能为空")
|
||||||
private String remark;
|
private String remark;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,3 +37,4 @@ public class MysqlRequest {
|
||||||
@NotBlank(message = "链接地址不能为空")
|
@NotBlank(message = "链接地址不能为空")
|
||||||
private String place;
|
private String place;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,3 +13,4 @@ public class PlaceRequest {
|
||||||
private Integer pageNum;
|
private Integer pageNum;
|
||||||
private Integer pageSize;
|
private Integer pageSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,3 +28,4 @@ public class RedisRequest {
|
||||||
@NotBlank(message = "链接地址不能为空")
|
@NotBlank(message = "链接地址不能为空")
|
||||||
private String host;
|
private String host;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
package com.etl.cleaning.domian.request;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加载表参数
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class TableRequest {
|
||||||
|
/**
|
||||||
|
* 数据源类型ID
|
||||||
|
*/
|
||||||
|
@NotNull(message = "数据源类型ID不能为空")
|
||||||
|
private Long typeId;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据源描述
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "数据源描述不能为空")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -22,3 +22,4 @@ public class TaskRequest {
|
||||||
private Integer pageNum;
|
private Integer pageNum;
|
||||||
private Integer pageSize;
|
private Integer pageSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,3 +11,4 @@ public class UserRequest {
|
||||||
private String password;
|
private String password;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -34,3 +34,4 @@ public class PlaceResponse {
|
||||||
@TableField(exist = false)
|
@TableField(exist = false)
|
||||||
private String typeName;
|
private String typeName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,6 @@ public enum EnumMsg {
|
||||||
private final int code;
|
private final int code;
|
||||||
private final String message;
|
private final String message;
|
||||||
|
|
||||||
|
|
||||||
EnumMsg(int code, String message) {
|
EnumMsg(int code, String message) {
|
||||||
this.code = code;
|
this.code = code;
|
||||||
this.message = message;
|
this.message = message;
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
package com.etl.cleaning.handler;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
|
import com.etl.common.result.Result;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 全局异常捕获类
|
||||||
|
*/
|
||||||
|
@RestControllerAdvice
|
||||||
|
@Configuration
|
||||||
|
@Log4j2
|
||||||
|
public class CatchExceptions {
|
||||||
|
@ExceptionHandler(value = RuntimeException.class)
|
||||||
|
public Result<String> catchException(RuntimeException exception) {
|
||||||
|
log.error("请求异常: [{}]",exception.getMessage(),exception);
|
||||||
|
return Result.error(JSONObject.toJSONString(exception.getMessage()));
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,4 +7,5 @@ import com.etl.cleaning.domian.pojo.DataPlace;
|
||||||
* 数据源管理
|
* 数据源管理
|
||||||
*/
|
*/
|
||||||
public interface PlaceMapper extends BaseMapper<DataPlace> {
|
public interface PlaceMapper extends BaseMapper<DataPlace> {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
package com.etl.cleaning.server;
|
||||||
|
|
||||||
|
|
||||||
|
import java.sql.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取数据库下的所有表名
|
||||||
|
*/
|
||||||
|
public class GetTableServerTest {
|
||||||
|
public static List<String> getTableNames(String url,String username,String password){
|
||||||
|
ArrayList<String> tableNames = new ArrayList<>();
|
||||||
|
Connection connection = null;
|
||||||
|
try {
|
||||||
|
Class.forName("com.mysql.cj.jdbc.Driver");
|
||||||
|
connection = DriverManager.getConnection(url, username, password);
|
||||||
|
DatabaseMetaData metaData = connection.getMetaData();
|
||||||
|
ResultSet tables = metaData.getTables(null, null, "%", new String[]{"TABLE"});
|
||||||
|
while (tables.next()){
|
||||||
|
tableNames.add(tables.getString(3));
|
||||||
|
}
|
||||||
|
tables.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}finally {
|
||||||
|
// 关闭连接(如果已打开)
|
||||||
|
try {
|
||||||
|
if (connection != null && !connection.isClosed()) {
|
||||||
|
try {
|
||||||
|
connection.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return tableNames;
|
||||||
|
}
|
||||||
|
}
|
|
@ -37,6 +37,7 @@ public class PlaceServiceImpl extends ServiceImpl<PlaceMapper, DataPlace> implem
|
||||||
this.placeMapper = placeMapper;
|
this.placeMapper = placeMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String,Object> showPlacePage(PlaceRequest placeRequest) {
|
public Map<String,Object> showPlacePage(PlaceRequest placeRequest) {
|
||||||
LambdaQueryWrapper<DataPlace> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<DataPlace> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
@ -65,7 +66,7 @@ public class PlaceServiceImpl extends ServiceImpl<PlaceMapper, DataPlace> implem
|
||||||
.typeName(typeName)
|
.typeName(typeName)
|
||||||
.name(item.getName())
|
.name(item.getName())
|
||||||
.bank(item.getBank())
|
.bank(item.getBank())
|
||||||
.statue(item.getStatue()) // 注意:这里可能是status的拼写错误,请检查
|
.statue(item.getStatue())
|
||||||
.updateTime(item.getUpdateTime())
|
.updateTime(item.getUpdateTime())
|
||||||
.build();
|
.build();
|
||||||
}).collect(Collectors.toList());
|
}).collect(Collectors.toList());
|
||||||
|
|
Loading…
Reference in New Issue