7 changed files with 124 additions and 17 deletions
@ -0,0 +1,80 @@
|
||||
package com.fr.plugin.decision.request.handler; |
||||
|
||||
import com.finebi.activate.foudation.StableManager; |
||||
import com.finebi.common.impl.vo.table.FineBusinessTable; |
||||
import com.finebi.common.impl.vo.table.FineExcelBusinessTable; |
||||
import com.finebi.common.api.cell.context.CellCreator; |
||||
import com.finebi.foundation.api.service.context.BaseContext; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.plugin.decision.utils.JdbcUtils; |
||||
import com.fr.web.utils.WebUtils; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.sql.Connection; |
||||
import java.util.List; |
||||
import java.sql.SQLException; |
||||
import java.sql.DatabaseMetaData; |
||||
import java.util.ArrayList; |
||||
import java.sql.ResultSet; |
||||
|
||||
public class CheckHandler extends HWAbstractHandler { |
||||
public static final String PATH="/excelmng/check"; |
||||
@Override |
||||
protected void deal(HttpServletRequest req, HttpServletResponse res, JSONObject para, JSONObject result) throws Exception { |
||||
|
||||
String connection = para.getString("connection"); |
||||
|
||||
Connection conn = JdbcUtils.getConnection(connection); |
||||
|
||||
if (conn == null){ |
||||
FineLoggerFactory.getLogger().error("HW_excel校验重名:数据链接 " + connection + " 获取异常" ); |
||||
WebUtils.printAsJSON(res, new JSONObject().put("status","fail").put("errorText","获取数据连接异常")); |
||||
return; |
||||
} |
||||
List<String> tables = getTables(conn); |
||||
|
||||
JSONObject finalResult = JSONObject.create(); |
||||
|
||||
ArrayList<String> excelList = new ArrayList<String>(); |
||||
|
||||
List<FineBusinessTable> allTables = CellCreator.getCellProvider().tableCell().getAllTableWithoutAuth(); |
||||
allTables.forEach(fineBusinessTable -> { |
||||
if (fineBusinessTable instanceof FineExcelBusinessTable) { |
||||
excelList.add(fineBusinessTable.getName()); |
||||
} |
||||
}); |
||||
|
||||
tables.retainAll(excelList); |
||||
|
||||
WebUtils.printAsJSON(res, finalResult.put("checkResult", tables)); |
||||
} |
||||
|
||||
@Override |
||||
public String getPath() { |
||||
return PATH; |
||||
} |
||||
|
||||
/** |
||||
* service获取集合 |
||||
*/ |
||||
private static BaseContext getContext() { |
||||
return StableManager.getContext(); |
||||
} |
||||
|
||||
/**获取数据库中所有表名称 |
||||
* @param conn |
||||
* @return |
||||
* @throws SQLException |
||||
*/ |
||||
private static List<String> getTables(Connection conn) throws SQLException { |
||||
DatabaseMetaData databaseMetaData = conn.getMetaData(); |
||||
ResultSet tables = databaseMetaData.getTables(null, null, "%", null); |
||||
ArrayList<String> tablesList = new ArrayList<String>(); |
||||
while (tables.next()) { |
||||
tablesList.add(tables.getString("TABLE_NAME")); |
||||
} |
||||
return tablesList; |
||||
} |
||||
} |
Loading…
Reference in new issue