diff --git a/src/main/java/com/fr/plugin/decision/HWUtils.java b/src/main/java/com/fr/plugin/decision/HWUtils.java index ad47f35..c39bf4a 100644 --- a/src/main/java/com/fr/plugin/decision/HWUtils.java +++ b/src/main/java/com/fr/plugin/decision/HWUtils.java @@ -1,9 +1,10 @@ package com.fr.plugin.decision; +import com.finebi.burger.api.bean.configuration.table.field.FineBusinessField; +import com.finebi.foundation.api.structure.result.BIDetailCell; +import com.finebi.foundation.api.structure.result.BIDetailResult; import com.fr.cache.Attachment; import com.fr.cache.AttachmentSource; -import com.fr.general.CommonDateUtils; -import com.fr.general.DateUtils; import com.fr.general.Inter; import com.fr.json.JSONArray; import com.fr.json.JSONObject; @@ -107,6 +108,25 @@ public class HWUtils { return result; } + public static Map getValues(List fields, BIDetailResult detailResult) { + Map result = new HashMap(); + while (detailResult.hasNext()) { + List cells = detailResult.next(); + for (int i = 0; i < fields.size(); ++i) { + String fieldName = fields.get(i).getName(); + Object cellValue = cells.get(i).getData() != null ? cells.get(i).getData() : StringUtils.EMPTY; + if (result.containsKey(fieldName)) { + result.get(fieldName).add(cellValue.toString()); + } else { + List rowList = new ArrayList<>(); + rowList.add(cellValue.toString()); + result.put(fieldName, rowList); + } + } + } + return result; + } + public static String getCellValue(XSSFSheet sheet, List combineCell, int row, int col, XSSFCell cell) { int firstC = 0; int lastC = 0; diff --git a/src/main/java/com/fr/plugin/decision/request/handler/UpgradeHandler.java b/src/main/java/com/fr/plugin/decision/request/handler/UpgradeHandler.java index 6cf78d9..080979f 100644 --- a/src/main/java/com/fr/plugin/decision/request/handler/UpgradeHandler.java +++ b/src/main/java/com/fr/plugin/decision/request/handler/UpgradeHandler.java @@ -1,8 +1,9 @@ package com.fr.plugin.decision.request.handler; import com.finebi.activate.foundation.StableManager; -import com.finebi.burger.api.bean.configuration.table.attachment.FineAttachment; import com.finebi.burger.api.bean.configuration.table.field.FineBusinessField; +import com.finebi.burger.api.bean.configuration.table.page.ConfLimitInfo; +import com.finebi.burger.api.bean.configuration.table.page.ConfPageInfo; import com.finebi.burger.api.request.configuration.table.DataBaseAddTableItemRequestBean; import com.finebi.burger.api.request.configuration.table.DataBaseAddTableRequestBean; import com.finebi.burger.api.response.configuration.table.TableAddResponseBean; @@ -12,9 +13,11 @@ 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.common.api.cell.user.authority.UserAuthority; +import com.finebi.direct.common.impl.engine.BurgerTableDataCellImpl; import com.finebi.foundation.api.reponse.FineRespond; import com.finebi.foundation.api.service.FineService; import com.finebi.foundation.api.service.context.BaseContext; +import com.finebi.foundation.api.structure.result.BIDetailResult; import com.finebi.utils.CompareUtils; import com.fr.decision.webservice.v10.user.UserService; import com.fr.json.JSONArray; @@ -30,11 +33,6 @@ import com.fr.stable.StringUtils; import com.fr.third.fasterxml.jackson.core.JsonGenerationException; 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; import com.finebi.common.impl.vo.table.FineBusinessTable; import com.finebi.common.impl.vo.table.FineExcelBusinessTable; @@ -56,6 +54,7 @@ public class UpgradeHandler extends HWAbstractHandler { protected void deal(HttpServletRequest req, HttpServletResponse res, JSONObject para, JSONObject result) throws Exception { String connection = para.getString("connection"); + UserAuthority authorityUser = getFineUserInfoService().getUserAuthority(req); Connection conn = JdbcUtils.getConnection(connection); @@ -75,57 +74,22 @@ public class UpgradeHandler extends HWAbstractHandler { allTables.stream().filter(fineBusinessTable -> fineBusinessTable instanceof FineExcelBusinessTable).limit(15).forEach(fineBusinessTable -> { Map values = new HashMap(); JSONArray items = JSONArray.create(); - FineAttachment sheetInfo = ((FineExcelBusinessTable) fineBusinessTable).getBaseAttach(); - String attachId = sheetInfo.getId(); - String fileName = sheetInfo.getFileName(); - int sheetNo = 0; List fields = ((FineExcelBusinessTable) fineBusinessTable).getExcelFields(); try { - if (fileName.endsWith(".xlsx")) { - - XSSFWorkbook excelWork = HWUtils.getExcelWork(attachId); - if(excelWork != null){ - 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", "8000"); - item.put("colName", field.getName()); - item.put("colType", this.getFieldSqlType(field.getType())); - item.put("excelCol", i); - item.put("id", field.getId()); - - items.put(item); - } - values = HWUtils.getSheetContent(sheet, 0, tableCol); - } - } else if (fileName.endsWith(".xls")) { - HSSFWorkbook excel2003Work = HWUtils.getExcel2003Work(attachId); - if(excel2003Work != null){ - HSSFSheet sheetAt = excel2003Work.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", "8000"); - item.put("colName", field.getName()); - item.put("colType", this.getFieldSqlType(field.getType())); - item.put("excelCol", i); - item.put("id", field.getId()); - - items.put(item); - } - values = HWUtils.get2003SheetContent(sheetAt,0, tableCol); - } + Optional optionalBIDetailResult = new BurgerTableDataCellImpl().getRealDataWithAuth(fineBusinessTable, new ConfLimitInfo(500000, new ConfPageInfo(500000, 1)), authorityUser); + BIDetailResult detailResult = optionalBIDetailResult.get(); + values = HWUtils.getValues(fields, detailResult); + for(int i = 0; i < fields.size(); i++){ + FineBusinessField field = fields.get(i); + JSONObject item = new JSONObject(); + item.put("colLength", "8000"); + item.put("colName", field.getName()); + item.put("colType", this.getFieldSqlType(field.getType())); + item.put("excelCol", i); + item.put("id", field.getId()); + items.put(item); } } catch (Exception e) { e.printStackTrace(); @@ -153,8 +117,6 @@ public class UpgradeHandler extends HWAbstractHandler { JSONArray tables = JSONArray.create().put(table); JSONObject tablesBean = JSONObject.create().put("tables", tables); try{ - UserAuthority authorityUser = getFineUserInfoService().getUserAuthority(req); - Optional packageIdWithoutAuth = CellCreator.getCellProvider().packageCell().getPackageByTableNameWithoutAuth(tableName); FineBusinessPackage businessPackage = packageIdWithoutAuth.get(); String packId = businessPackage.getId();