集成全局异常

ays
An Yong Shuai 2024-07-02 20:49:01 +08:00
parent eb692d1e59
commit 7a1dfe1f90
24 changed files with 198 additions and 34 deletions

File diff suppressed because one or more lines are too long

View File

@ -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();
}
}

View File

@ -1,8 +1,5 @@
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.PlaceRequest;
import com.etl.cleaning.service.PlaceService;

View File

@ -23,11 +23,9 @@ import java.util.List;
@RequestMapping("/role-type")
public class RoleTypeController {
private final RoleTypeService roleTypeService;
public RoleTypeController(RoleTypeService roleTypeService) {
this.roleTypeService = roleTypeService;
}
/**
*
* @return

View File

@ -29,12 +29,14 @@ public class TypeController {
return Result.success(list);
}
/**
* mysql
* @return
/*
mysql
@return
*/
// @GetMapping("/testMysql")
// public Result testMysql(){
// ServerTest.testDatabaseConnection()
// }
/*
@GetMapping("/testMysql")
public Result testMysql(){
ServerTest.testDatabaseConnection()
}
*/
}

View File

@ -74,3 +74,4 @@ public class DataPlace {
*/
private String dataUrl;
}

View File

@ -36,3 +36,4 @@ public class DataRole {
*/
private Long typeId;
}

View File

@ -46,3 +46,4 @@ public class DataTask {
}

View File

@ -27,3 +27,4 @@ public class DateType {
*/
private String name;
}

View File

@ -24,3 +24,4 @@ public class RoleType {
*/
private String name;
}

View File

@ -1,6 +1,5 @@
package com.etl.cleaning.domian.request;
import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
@ -64,3 +63,4 @@ public class InsertPlaceRequest {
@NotBlank(message = "连接地址不能为空")
private String dataUrl;
}

View File

@ -38,3 +38,4 @@ public class InsertTaskRequest {
@NotBlank(message = "任务备注不能为空")
private String remark;
}

View File

@ -37,3 +37,4 @@ public class MysqlRequest {
@NotBlank(message = "链接地址不能为空")
private String place;
}

View File

@ -13,3 +13,4 @@ public class PlaceRequest {
private Integer pageNum;
private Integer pageSize;
}

View File

@ -28,3 +28,4 @@ public class RedisRequest {
@NotBlank(message = "链接地址不能为空")
private String host;
}

View File

@ -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;
}

View File

@ -22,3 +22,4 @@ public class TaskRequest {
private Integer pageNum;
private Integer pageSize;
}

View File

@ -11,3 +11,4 @@ public class UserRequest {
private String password;
}

View File

@ -34,3 +34,4 @@ public class PlaceResponse {
@TableField(exist = false)
private String typeName;
}

View File

@ -16,7 +16,6 @@ public enum EnumMsg {
private final int code;
private final String message;
EnumMsg(int code, String message) {
this.code = code;
this.message = message;

View File

@ -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()));
}
}

View File

@ -7,4 +7,5 @@ import com.etl.cleaning.domian.pojo.DataPlace;
*
*/
public interface PlaceMapper extends BaseMapper<DataPlace> {
}

View File

@ -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;
}
}

View File

@ -37,6 +37,7 @@ public class PlaceServiceImpl extends ServiceImpl<PlaceMapper, DataPlace> implem
this.placeMapper = placeMapper;
}
@Override
public Map<String,Object> showPlacePage(PlaceRequest placeRequest) {
LambdaQueryWrapper<DataPlace> lambdaQueryWrapper = new LambdaQueryWrapper<>();
@ -65,7 +66,7 @@ public class PlaceServiceImpl extends ServiceImpl<PlaceMapper, DataPlace> implem
.typeName(typeName)
.name(item.getName())
.bank(item.getBank())
.statue(item.getStatue()) // 注意这里可能是status的拼写错误请检查
.statue(item.getStatue())
.updateTime(item.getUpdateTime())
.build();
}).collect(Collectors.toList());