|
|
|
@ -71,17 +71,18 @@ public class UpgradeHandler extends HWAbstractHandler {
|
|
|
|
|
JSONObject finalResult = JSONObject.create(); |
|
|
|
|
|
|
|
|
|
List<FineBusinessTable> allTables = CellCreator.getCellProvider().tableCell().getAllTableWithoutAuth(); |
|
|
|
|
allTables.forEach(fineBusinessTable -> { |
|
|
|
|
|
|
|
|
|
allTables.stream().filter(fineBusinessTable -> fineBusinessTable instanceof FineExcelBusinessTable).limit(15).forEach(fineBusinessTable -> { |
|
|
|
|
Map<String, List> values = new HashMap<String, List>(); |
|
|
|
|
if (fineBusinessTable instanceof FineExcelBusinessTable) { |
|
|
|
|
JSONArray items = JSONArray.create(); |
|
|
|
|
FineAttachment sheetInfo = ((FineExcelBusinessTable) fineBusinessTable).getBaseAttach(); |
|
|
|
|
String attachId = sheetInfo.getId(); |
|
|
|
|
String fileName = sheetInfo.getFileName(); |
|
|
|
|
int sheetNo = 0; |
|
|
|
|
JSONArray items = JSONArray.create(); |
|
|
|
|
FineAttachment sheetInfo = ((FineExcelBusinessTable) fineBusinessTable).getBaseAttach(); |
|
|
|
|
String attachId = sheetInfo.getId(); |
|
|
|
|
String fileName = sheetInfo.getFileName(); |
|
|
|
|
int sheetNo = 0; |
|
|
|
|
|
|
|
|
|
List<FineBusinessField> fields = ((FineExcelBusinessTable) fineBusinessTable).getExcelFields(); |
|
|
|
|
List<FineBusinessField> fields = ((FineExcelBusinessTable) fineBusinessTable).getExcelFields(); |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
if (fileName.endsWith(".xlsx")) { |
|
|
|
|
XSSFWorkbook excelWork = HWUtils.getExcelWork(attachId); |
|
|
|
|
if(excelWork != null){ |
|
|
|
@ -92,7 +93,7 @@ public class UpgradeHandler extends HWAbstractHandler {
|
|
|
|
|
tableCol.put(field.getName(), i); |
|
|
|
|
|
|
|
|
|
JSONObject item = new JSONObject(); |
|
|
|
|
item.put("colLength", "255"); |
|
|
|
|
item.put("colLength", "8000"); |
|
|
|
|
item.put("colName", field.getName()); |
|
|
|
|
item.put("colType", this.getFieldSqlType(field.getType())); |
|
|
|
|
item.put("excelCol", i); |
|
|
|
@ -112,7 +113,7 @@ public class UpgradeHandler extends HWAbstractHandler {
|
|
|
|
|
tableCol.put(field.getName(), i); |
|
|
|
|
|
|
|
|
|
JSONObject item = new JSONObject(); |
|
|
|
|
item.put("colLength", "255"); |
|
|
|
|
item.put("colLength", "8000"); |
|
|
|
|
item.put("colName", field.getName()); |
|
|
|
|
item.put("colType", this.getFieldSqlType(field.getType())); |
|
|
|
|
item.put("excelCol", i); |
|
|
|
@ -123,60 +124,61 @@ public class UpgradeHandler extends HWAbstractHandler {
|
|
|
|
|
values = HWUtils.get2003SheetContent(sheetAt,0, tableCol); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} catch (Exception e){ |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
String schema = ""; |
|
|
|
|
String tableName = fineBusinessTable.getName(); |
|
|
|
|
String schema = "guest"; |
|
|
|
|
String tableName = fineBusinessTable.getName(); |
|
|
|
|
|
|
|
|
|
ExcelDmlAction excelDmlAction = ActionFactory.getInstance().create("add"); |
|
|
|
|
ExcelDmlAction excelDmlAction = ActionFactory.getInstance().create("add"); |
|
|
|
|
|
|
|
|
|
excelDmlAction.setExcelDmlBean( new ExcelDmlBean(connection, schema, tableName, items, values) ); |
|
|
|
|
excelDmlAction.setExcelDmlBean( new ExcelDmlBean(connection, schema, tableName, items, values) ); |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
JSONObject dmlResult = excelDmlAction.execute(); |
|
|
|
|
importDbResult.put(dmlResult); |
|
|
|
|
try { |
|
|
|
|
JSONObject dmlResult = excelDmlAction.execute(); |
|
|
|
|
importDbResult.put(dmlResult); |
|
|
|
|
|
|
|
|
|
if (StringUtils.equals("success", dmlResult.getString("status")) && dmlResult.getBoolean("addLink")) { |
|
|
|
|
ExcelLinkService.getInstance().addLink(tableName, connection, schema, tableName, createUser); |
|
|
|
|
FineLoggerFactory.getLogger().info("HW_excel导入:FineDB 新增数据成功" + tableName); |
|
|
|
|
} |
|
|
|
|
if (StringUtils.equals("success", dmlResult.getString("status")) && dmlResult.getBoolean("addLink")) { |
|
|
|
|
ExcelLinkService.getInstance().addLink(tableName, connection, schema, tableName, createUser); |
|
|
|
|
FineLoggerFactory.getLogger().info("HW_excel导入:FineDB 新增数据成功" + tableName); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (StringUtils.equals("success", dmlResult.getString("status")) || StringUtils.contains(dmlResult.getString("errorText"), "exist")) { |
|
|
|
|
ObjectMapper mapper = new ObjectMapper(); |
|
|
|
|
JSONObject table = JSONObject.create().put("tableName", fineBusinessTable.getName()).put("connectionName", connection); |
|
|
|
|
JSONArray tables = JSONArray.create().put(table); |
|
|
|
|
JSONObject tablesBean = JSONObject.create().put("tables", tables); |
|
|
|
|
try{ |
|
|
|
|
FineAuthorityUser authorityUser = FineAuthorityUtils.getAuth(req); |
|
|
|
|
if (StringUtils.equals("success", dmlResult.getString("status")) || StringUtils.contains(dmlResult.getString("errorText"), "exist")) { |
|
|
|
|
ObjectMapper mapper = new ObjectMapper(); |
|
|
|
|
JSONObject table = JSONObject.create().put("tableName", fineBusinessTable.getName()).put("connectionName", connection); |
|
|
|
|
JSONArray tables = JSONArray.create().put(table); |
|
|
|
|
JSONObject tablesBean = JSONObject.create().put("tables", tables); |
|
|
|
|
try{ |
|
|
|
|
FineAuthorityUser authorityUser = FineAuthorityUtils.getAuth(req); |
|
|
|
|
|
|
|
|
|
Optional<FineBusinessPackage> packageIdWithoutAuth = CellCreator.getCellProvider().packageCell().getPackageByTableNameWithoutAuth(tableName); |
|
|
|
|
FineBusinessPackage businessPackage = packageIdWithoutAuth.get(); |
|
|
|
|
String packId = businessPackage.getId(); |
|
|
|
|
Optional<FineBusinessPackage> packageIdWithoutAuth = CellCreator.getCellProvider().packageCell().getPackageByTableNameWithoutAuth(tableName); |
|
|
|
|
FineBusinessPackage businessPackage = packageIdWithoutAuth.get(); |
|
|
|
|
String packId = businessPackage.getId(); |
|
|
|
|
|
|
|
|
|
List<FineBusinessRelation> fineBusinessRelations = CellCreator.getCellProvider().relationPathCell().getRelationsByTableNameWithoutAuth(fineBusinessTable.getName()); |
|
|
|
|
List<FineBusinessRelation> fineBusinessRelations = CellCreator.getCellProvider().relationPathCell().getRelationsByTableNameWithoutAuth(fineBusinessTable.getName()); |
|
|
|
|
|
|
|
|
|
CellCreator.getCellProvider().tableCell().removeTable(fineBusinessTable.getName(), FineAuthorityUser.ROOT_USER_ID); |
|
|
|
|
CellCreator.getCellProvider().tableCell().removeTable(fineBusinessTable.getName(), FineAuthorityUser.ROOT_USER_ID); |
|
|
|
|
// String packId = "__my_analysis__" + fineBusinessTable.getCreateByWithId() + "1";
|
|
|
|
|
try { |
|
|
|
|
String tableString = tablesBean.toString(); |
|
|
|
|
FineBusinessTable[] businessTables = createBusinessTablesFromDBNewAddTableInfo(mapper.readValue(tableString, DataBaseAddTableRequestBean.class), authorityUser.getUserId()); |
|
|
|
|
TableAddResponseBean responed = getTableService().addNewTable(packId, authorityUser, businessTables); |
|
|
|
|
CellCreator.getCellProvider().relationPathCell().addRelations(fineBusinessRelations, authorityUser); |
|
|
|
|
addDbResult.put(FineRespond.success(responed)); |
|
|
|
|
} catch (JsonMappingException e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
} catch (JsonGenerationException e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
} catch (IOException e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
} |
|
|
|
|
} catch(Exception e){ |
|
|
|
|
try { |
|
|
|
|
String tableString = tablesBean.toString(); |
|
|
|
|
FineBusinessTable[] businessTables = createBusinessTablesFromDBNewAddTableInfo(mapper.readValue(tableString, DataBaseAddTableRequestBean.class), authorityUser.getUserId()); |
|
|
|
|
TableAddResponseBean responed = getTableService().addNewTable(packId, authorityUser, businessTables); |
|
|
|
|
CellCreator.getCellProvider().relationPathCell().addRelations(fineBusinessRelations, authorityUser); |
|
|
|
|
addDbResult.put(FineRespond.success(responed)); |
|
|
|
|
} catch (JsonMappingException e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
} catch (JsonGenerationException e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
} catch (IOException e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
} |
|
|
|
|
} catch(Exception e){ |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
} |
|
|
|
|
} catch(Exception e){ |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} catch(Exception e){ |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|