|
|
|
@ -11,7 +11,7 @@ import com.finebi.common.impl.vo.relation.FineBusinessRelation;
|
|
|
|
|
import com.finebi.common.impl.vo.table.FineDBBusinessTable; |
|
|
|
|
import com.finebi.direct.burger.api.service.FineTableService; |
|
|
|
|
import com.finebi.direct.burger.api.service.FineUserInfoService; |
|
|
|
|
import com.finebi.direct.common.api.cell.user.authority.UserAuthority; |
|
|
|
|
import com.finebi.common.api.cell.user.authority.UserAuthority; |
|
|
|
|
import com.finebi.foundation.api.reponse.FineRespond; |
|
|
|
|
import com.finebi.foundation.api.service.FineService; |
|
|
|
|
import com.finebi.foundation.api.service.context.BaseContext; |
|
|
|
@ -32,6 +32,7 @@ import com.fr.third.fasterxml.jackson.databind.JsonMappingException;
|
|
|
|
|
import com.fr.third.fasterxml.jackson.databind.ObjectMapper; |
|
|
|
|
import com.fr.third.org.apache.poi.hssf.usermodel.HSSFSheet; |
|
|
|
|
import com.fr.third.org.apache.poi.hssf.usermodel.HSSFWorkbook; |
|
|
|
|
import com.fr.third.v2.org.apache.poi.xssf.streaming.SXSSFWorkbook; |
|
|
|
|
import com.fr.third.v2.org.apache.poi.xssf.usermodel.XSSFSheet; |
|
|
|
|
import com.fr.third.v2.org.apache.poi.xssf.usermodel.XSSFWorkbook; |
|
|
|
|
import com.finebi.direct.common.api.cell.context.CellCreator; |
|
|
|
@ -71,28 +72,31 @@ 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){ |
|
|
|
|
XSSFSheet sheet = excelWork.getSheetAt(sheetNo); |
|
|
|
|
SXSSFWorkbook swb = new SXSSFWorkbook(excelWork,100); |
|
|
|
|
XSSFWorkbook xssfWorkbook = swb.getXSSFWorkbook(); |
|
|
|
|
XSSFSheet sheet = xssfWorkbook.getSheetAt(sheetNo); |
|
|
|
|
JSONObject tableCol = JSONObject.create(); |
|
|
|
|
for(int i = 0; i < fields.size(); i++){ |
|
|
|
|
FineBusinessField field = fields.get(i); |
|
|
|
|
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 +116,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,62 +127,62 @@ public class UpgradeHandler extends HWAbstractHandler {
|
|
|
|
|
values = HWUtils.get2003SheetContent(sheetAt,0, tableCol); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
String schema = ""; |
|
|
|
|
String tableName = fineBusinessTable.getName(); |
|
|
|
|
String schema = ""; |
|
|
|
|
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{ |
|
|
|
|
UserAuthority authorityUser = getFineUserInfoService().getUserAuthority(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{ |
|
|
|
|
UserAuthority authorityUser = getFineUserInfoService().getUserAuthority(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(), CellCreator.getCellProvider().userCellProvider().authorityCell().getSuperAuthority()); |
|
|
|
|
CellCreator.getCellProvider().tableCell().removeTable(fineBusinessTable.getName(), CellCreator.getCellProvider().userCellProvider().authorityCell().getSuperAuthority()); |
|
|
|
|
|
|
|
|
|
// String packId = "__my_analysis__" + fineBusinessTable.getCreateByWithId() + "1";
|
|
|
|
|
try { |
|
|
|
|
String tableString = tablesBean.toString(); |
|
|
|
|
FineBusinessTable[] businessTables = createBusinessTablesFromDBNewAddTableInfo(mapper.readValue(tableString, DataBaseAddTableRequestBean.class), authorityUser.getUser().getInfo().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.getUser().getInfo().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(); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|