Compare commits

...

11 Commits

  1. 5
      .gitignore
  2. 91
      build.xml
  3. BIN
      fr-plugin-hwExcelExport-1.8.3.zip
  4. 2
      plugin.xml
  5. 32
      pom.xml
  6. 24
      src/main/java/com/fr/plugin/decision/HWUtils.java
  7. 33
      src/main/java/com/fr/plugin/decision/core/DML.java
  8. 5
      src/main/java/com/fr/plugin/decision/core/ExcelDmlBean.java
  9. 4
      src/main/java/com/fr/plugin/decision/core/action/CreateAction.java
  10. 28
      src/main/java/com/fr/plugin/decision/dialect/postgre/PostgreDialectColumnType2SQLExecutor.java
  11. 1
      src/main/java/com/fr/plugin/decision/dialect/postgre/PostgreDialectConsummate.java
  12. 2
      src/main/java/com/fr/plugin/decision/http/DeleteLinkHttpHandle.java
  13. 10
      src/main/java/com/fr/plugin/decision/request/HWHandlerProvider.java
  14. 16
      src/main/java/com/fr/plugin/decision/request/HWURLAliasProvider.java
  15. 80
      src/main/java/com/fr/plugin/decision/request/handler/CheckNameHandler.java
  16. 81
      src/main/java/com/fr/plugin/decision/request/handler/CheckSizeHandler.java
  17. 34
      src/main/java/com/fr/plugin/decision/request/handler/TableDataImport.java
  18. 217
      src/main/java/com/fr/plugin/decision/request/handler/UpgradeHandler.java
  19. 2
      src/main/java/com/fr/plugin/decision/utils/JdbcUtils.java
  20. 15
      src/main/main.iml
  21. 10
      src/main/resources/com/fr/plugin/hw/decision/js/hw.option.js
  22. 66
      src/main/resources/com/fr/plugin/hw/decision/js/pane/check/check.js
  23. 19
      src/main/resources/com/fr/plugin/hw/decision/js/pane/check/check.model.js
  24. 17
      src/main/resources/com/fr/plugin/hw/decision/js/pane/left.js
  25. 9
      src/main/resources/com/fr/plugin/hw/decision/js/pane/left.linklist.js
  26. 8
      src/main/resources/com/fr/plugin/hw/decision/js/pane/left.linklist.model.js
  27. 8
      src/main/resources/com/fr/plugin/hw/decision/js/pane/panes.js
  28. 148
      src/main/resources/com/fr/plugin/hw/decision/js/pane/upgrade/upgrade.js
  29. 33
      src/main/resources/com/fr/plugin/hw/decision/js/pane/upgrade/upgrade.model.js
  30. 9
      src/main/resources/com/fr/plugin/hw/decision/js/utils.js

5
.gitignore vendored

@ -2,4 +2,7 @@
lib
.project
plugin-exceldatamanagement.iml
.settings
.settings
classes/
fr-plugin-hwExcelExport-2.0.0.zip
target/

91
build.xml

@ -14,9 +14,9 @@
<property name="plugin-version" value="${current-version}"/>
<property name="plugin-name" value="hwExcelExport"/>
<property name="plugin-jar" value="fr-plugin-${plugin-name}-${plugin-version}.jar"/>
<target name="prepare">
<delete dir="${classes}"/>
</target>
<!-- <target name="prepare">-->
<!-- <delete dir="${classes}"/>-->
<!-- </target>-->
<path id="compile.classpath">
<!-- <fileset dir="${FRLibs}">-->
<!-- <include name="**/*.jar"/>-->
@ -38,36 +38,36 @@
<exclude name="**/*.g"/>
<exclude name="**/package.html"/>
</patternset>
<target name="copy_resources">
<echo message="从${resources_from}拷贝图片,JS,CSS等资源文件"/>
<delete dir="tmp"/>
<copy todir="tmp">
<fileset dir="${resources_from}\src\main\java">
<patternset refid="resources4Jar"/>
</fileset>
</copy>
<copy todir="tmp">
<fileset dir="${resources_from}\src\main\resources">
<patternset refid="resources4Jar"/>
</fileset>
</copy>
<copy todir="${classes}">
<fileset dir="tmp"/>
</copy>
<delete dir="tmp"/>
</target>
<target name="compile_javas">
<echo message="编译${compile_files}下的Java文件"/>
<javac destdir="${classes}" debug="false" optimize="on" source="${source_jdk_version}"
target="${target_jdk_version}"
fork="true" memoryMaximumSize="512m" listfiles="false" srcdir="${basedir}"
executable="${compile_jdk_version}/bin/javac" includeantruntime="on">
<src path="${basedir}/src"/>
<exclude name="**/.svn/**"/>
<compilerarg line="-encoding UTF8 "/>
<classpath refid="compile.classpath"/>
</javac>
</target>
<!-- <target name="copy_resources">-->
<!-- <echo message="从${resources_from}拷贝图片,JS,CSS等资源文件"/>-->
<!-- <delete dir="tmp"/>-->
<!-- <copy todir="tmp">-->
<!-- <fileset dir="${resources_from}\src\main\java">-->
<!-- <patternset refid="resources4Jar"/>-->
<!-- </fileset>-->
<!-- </copy>-->
<!-- <copy todir="tmp">-->
<!-- <fileset dir="${resources_from}\src\main\resources">-->
<!-- <patternset refid="resources4Jar"/>-->
<!-- </fileset>-->
<!-- </copy>-->
<!-- <copy todir="${classes}">-->
<!-- <fileset dir="tmp"/>-->
<!-- </copy>-->
<!-- <delete dir="tmp"/>-->
<!-- </target>-->
<!-- <target name="compile_javas">-->
<!-- <echo message="编译${compile_files}下的Java文件"/>-->
<!-- <javac destdir="${classes}" debug="true" optimize="on" source="${source_jdk_version}"-->
<!-- target="${target_jdk_version}"-->
<!-- fork="true" memoryMaximumSize="512m" listfiles="false" srcdir="${basedir}"-->
<!-- executable="${compile_jdk_version}/bin/javac" includeantruntime="on">-->
<!-- <src path="${basedir}/src"/>-->
<!-- <exclude name="**/.svn/**"/>-->
<!-- <compilerarg line="-encoding UTF8 "/>-->
<!-- <classpath refid="compile.classpath"/>-->
<!-- </javac>-->
<!-- </target>-->
<target name="jar_classes">
<echo message="打Jar包:${jar_name}"/>
@ -78,16 +78,16 @@
</jar>
</target>
<target name="super_jar" depends="prepare">
<antcall target="copy_resources">
<param name="resources_from" value="${basedir}"/>
</antcall>
<antcall target="compile_javas">
<param name="source_jdk_version" value="1.7"/>
<param name="target_jdk_version" value="1.7"/>
<param name="compile_jdk_version" value="${jdk.home}"/>
<param name="compile_files" value="${basedir}/src"/>
</antcall>
<target name="super_jar">
<!-- <antcall target="copy_resources">-->
<!-- <param name="resources_from" value="${basedir}"/>-->
<!-- </antcall>-->
<!-- <antcall target="compile_javas">-->
<!-- <param name="source_jdk_version" value="1.8"/>-->
<!-- <param name="target_jdk_version" value="1.8"/>-->
<!-- <param name="compile_jdk_version" value="${jdk.home}"/>-->
<!-- <param name="compile_files" value="${basedir}/src"/>-->
<!-- </antcall>-->
<echo message="compile plugin success!"/>
<antcall target="jar_classes">
@ -110,11 +110,6 @@
<include name="plugin.xml"/>
</fileset>
</copy>
<!-- <copy todir="${plugin-folder}">-->
<!-- <fileset dir="${libs}">-->
<!-- <include name="**/*.jar"/>-->
<!-- </fileset>-->
<!-- </copy>-->
<zip destfile="${basedir}/${plugin-folder}.zip" basedir=".">
<include name="${plugin-folder}/*.jar"/>
<include name="${plugin-folder}/plugin.xml"/>

BIN
fr-plugin-hwExcelExport-1.8.3.zip

Binary file not shown.

2
plugin.xml

@ -6,7 +6,7 @@
<env-version>10.0</env-version>
<jartime>2018-07-31</jartime>
<vendor>帆软</vendor>
<description><![CDATA[Excel导入数据库]]></description>
<description><![CDATA[批量Excel导入数据库]]></description>
<change-notes><![CDATA[导入的数据库将自动创建到我的自助数据集]]></change-notes>
<extra-decision>
<SystemOptionProvider class="com.fr.plugin.decision.HWOptionProvider"/>

32
pom.xml

@ -2,27 +2,45 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>starter</artifactId>
<groupId>com.fr.plugin</groupId>
<version>10.0</version>
<groupId>com.finebi.project</groupId>
<artifactId>nuclear-maven</artifactId>
<version>5.0-RELEASE-SNAPSHOT</version>
<relativePath>../nuclear-maven/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>plugin-exceldatamanagement</artifactId>
<dependencies>
<!-- <dependency>-->
<!-- <groupId>com.finebi</groupId>-->
<!-- <artifactId>spider-adapter-sdk</artifactId>-->
<!-- <version>${foundation-version}</version>-->
<!-- </dependency>-->
<dependency>
<groupId>com.finebi</groupId>
<artifactId>direct-adapter-sdk</artifactId>
<version>${foundation-version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-compiler-plugin -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<version>3.3</version>
<configuration>
<compilerArgument>-Xlint:unchecked</compilerArgument>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
<outputDirectory>${project.basedir}/../webroot/WEB-INF/plugins/plugin-com.fr.plugin.exceldatamanagement-1.0/classes</outputDirectory>
<!-- <outputDirectory>/Users/leezerofly/env/direct-bi/WEB-INF/plugins/plugin-com.fr.plugin.hw.import.excel-2.0.0/classes</outputDirectory>-->
<outputDirectory>/Users/leezerofly/repos/direct-bi/plugin-bi-excel-database/classes</outputDirectory>
</build>
</project>

24
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<String, List> getValues(List<FineBusinessField> fields, BIDetailResult detailResult) {
Map<String, List> result = new HashMap<String, List>();
while (detailResult.hasNext()) {
List<BIDetailCell> 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<Object> rowList = new ArrayList<>();
rowList.add(cellValue.toString());
result.put(fieldName, rowList);
}
}
}
return result;
}
public static String getCellValue(XSSFSheet sheet, List<CellRangeAddress> combineCell, int row, int col, XSSFCell cell) {
int firstC = 0;
int lastC = 0;

33
src/main/java/com/fr/plugin/decision/core/DML.java

@ -122,8 +122,8 @@ public class DML {
return execInsertedPreparedStatementByItem(dialect, conn, table, ps, rowCount, tableColName, tableColType, tableValue);
}
for (int rownum=0; rownum<rowCount; rownum++) {
for (int index=0; index<tableColName.size(); index++) {
for (int rownum = 0; rownum < rowCount; rownum++) {
for (int index = 0; index < tableColName.size(); index++) {
int type = tableColType.get(index);
Object value = tableValue.get(tableColName.get(index)).get(rownum);
// excel 中读数 1 会识别为 1.0 , 列格式为[文本]时需要调整下
@ -131,21 +131,26 @@ public class DML {
value = value.toString().split("\\.")[0];
}
DBUtils.applyColumnTypeValue(
dialect,
conn,
table,
null,
null,
ps,
index + 1,
type,
value
);
try {
DBUtils.applyColumnTypeValue(
dialect,
conn,
table,
null,
null,
ps,
index + 1,
type,
value
);
} catch (Exception e) {
// 类型推断后,若遇到不符合该类型的值,直接catch错误
FineLoggerFactory.getLogger().warn("type is not match");
}
}
count ++ ;
ps.addBatch();
if(rownum!=0 && rownum%10000==0){
if(rownum != 0 && rownum % 10000 == 0){
ps.executeBatch();
ps.clearBatch();
}

5
src/main/java/com/fr/plugin/decision/core/ExcelDmlBean.java

@ -34,7 +34,10 @@ public class ExcelDmlBean {
}
table = new Table(schema, tableName);
rowCount = tableValue.get(tableColName.get(0)).size();
rowCount = 0;
if (tableValue.size() > 0 && tableColName.size() > 0) {
rowCount = tableValue.get(tableColName.get(0)).size();
};
}
public List<Boolean> getTablePrimaryKey() {

4
src/main/java/com/fr/plugin/decision/core/action/CreateAction.java

@ -46,7 +46,7 @@ public class CreateAction extends ExcelDmlAction {
);
conn.commit();
conn.setAutoCommit(true);
result.put("status", "success").put("text", "表创建正常,成功插入数据" + count + "条").put("addLink",true);
result.put("status", "success").put("text", "【" + excelDmlBean.getTable().getName() + "】" + "DB表创建正常,成功插入数据" + count + "条").put("addLink",true);
} catch (Exception e) {
FineLoggerFactory.getLogger().error("HW_excel导入:CreateAction failed !", e.getMessage());
DBUtils.rollback(conn);
@ -56,7 +56,7 @@ public class CreateAction extends ExcelDmlAction {
FineLoggerFactory.getLogger().error("HW_excel导入:dropTable failed !", e.getMessage());
}
e.printStackTrace();
result.put("status", "failed").put("errorText", "新增操作异常" + e.getLocalizedMessage());
result.put("status", "failed").put("errorText", "【" + excelDmlBean.getTable().getName() + "】" + "导入数据库异常:" + e.getLocalizedMessage());
} finally {
DBUtils.close(conn);
DBUtils.close(preparedStatement);

28
src/main/java/com/fr/plugin/decision/dialect/postgre/PostgreDialectColumnType2SQLExecutor.java

@ -0,0 +1,28 @@
package com.fr.plugin.decision.dialect.postgre;
import com.fr.data.core.db.dialect.Dialect;
import com.fr.data.core.db.dialect.base.key.column.typetosql.AbstractDialectColumnType2SQLExecutor;
import com.fr.data.core.db.dialect.base.key.column.typetosql.DialectColumnType2SQLParameter;
import com.fr.data.core.db.dialect.util.DialectUtils;
public class PostgreDialectColumnType2SQLExecutor extends AbstractDialectColumnType2SQLExecutor {
public PostgreDialectColumnType2SQLExecutor(){
}
@Override
public String execute(DialectColumnType2SQLParameter dialectColumnType2SQLParameter, Dialect dialect) {
int columnType = dialectColumnType2SQLParameter.getColumnType();
String columnSize = dialectColumnType2SQLParameter.getParameter();
switch(columnType) {
case 8:
return "double precision";
case 12:
return "varchar(" + columnSize + ")";
case 91:
return "date";
default:
return DialectUtils.getTypeName(columnType);
}
}
}

1
src/main/java/com/fr/plugin/decision/dialect/postgre/PostgreDialectConsummate.java

@ -8,6 +8,7 @@ public class PostgreDialectConsummate extends PostgreSQLDialect {
public PostgreDialectConsummate(){
super();
this.putExecutor(DialectKeyConstants.COLUMN_TYPE_2_SQL_KEY, new PostgreDialectColumnType2SQLExecutor());
this.putExecutor(DialectKeyConstants.CREATE_TOP_N_SQL_KEY, new KylinDialectCreateTOPNSQLExecutor());
}
}

2
src/main/java/com/fr/plugin/decision/http/DeleteLinkHttpHandle.java

@ -56,7 +56,7 @@ DeleteLinkHttpHandle extends BaseHttpHandler {
conn = JdbcUtils.getConnection(connection);
Dialect dialect = DialectFactory.generateDialect(conn);
Table table = new Table(schema, tableName);
DML.deleteTable(dialect, conn, table);
DML.dropTable(dialect, conn, table);
FineLoggerFactory.getLogger().info("表删除成功");
ExcelLinkService.getInstance().deleteLinkById(id);

10
src/main/java/com/fr/plugin/decision/request/HWHandlerProvider.java

@ -2,10 +2,7 @@ package com.fr.plugin.decision.request;
import com.fr.decision.fun.HttpHandler;
import com.fr.decision.fun.impl.AbstractHttpHandlerProvider;
import com.fr.plugin.decision.request.handler.ExcelFiledHandler;
import com.fr.plugin.decision.request.handler.ExcelSheetCountHandler;
import com.fr.plugin.decision.request.handler.HWFileUploadHander;
import com.fr.plugin.decision.request.handler.TableDataImport;
import com.fr.plugin.decision.request.handler.*;
/**
* created by ezreal 2020/1/12
@ -17,7 +14,10 @@ public class HWHandlerProvider extends AbstractHttpHandlerProvider {
new HWFileUploadHander(),
new ExcelSheetCountHandler(),
new ExcelFiledHandler(),
new TableDataImport()
new TableDataImport(),
new UpgradeHandler(),
new CheckNameHandler(),
new CheckSizeHandler()
};
}
}

16
src/main/java/com/fr/plugin/decision/request/HWURLAliasProvider.java

@ -3,10 +3,7 @@ package com.fr.plugin.decision.request;
import com.fr.decision.fun.impl.AbstractURLAliasProvider;
import com.fr.decision.webservice.url.alias.URLAlias;
import com.fr.decision.webservice.url.alias.URLAliasFactory;
import com.fr.plugin.decision.request.handler.ExcelFiledHandler;
import com.fr.plugin.decision.request.handler.ExcelSheetCountHandler;
import com.fr.plugin.decision.request.handler.HWFileUploadHander;
import com.fr.plugin.decision.request.handler.TableDataImport;
import com.fr.plugin.decision.request.handler.*;
/**
* created by ezreal 2020/1/12
@ -16,11 +13,12 @@ public class HWURLAliasProvider extends AbstractURLAliasProvider {
public URLAlias[] registerAlias() {
return new URLAlias[]{
URLAliasFactory.createPluginAlias(HWFileUploadHander.PATH, HWFileUploadHander.PATH,true),
URLAliasFactory.createPluginAlias(ExcelSheetCountHandler.PATH,ExcelSheetCountHandler.PATH,false),
URLAliasFactory.createPluginAlias(ExcelFiledHandler.PATH,ExcelFiledHandler.PATH,false),
URLAliasFactory.createPluginAlias(TableDataImport.PATH,TableDataImport.PATH,false),
URLAliasFactory.createPluginAlias(ExcelSheetCountHandler.PATH, ExcelSheetCountHandler.PATH,false),
URLAliasFactory.createPluginAlias(ExcelFiledHandler.PATH, ExcelFiledHandler.PATH,false),
URLAliasFactory.createPluginAlias(TableDataImport.PATH, TableDataImport.PATH,false),
URLAliasFactory.createPluginAlias(UpgradeHandler.PATH, UpgradeHandler.PATH,false),
URLAliasFactory.createPluginAlias(CheckNameHandler.PATH, CheckNameHandler.PATH,false),
URLAliasFactory.createPluginAlias(CheckSizeHandler.PATH, CheckSizeHandler.PATH,false),
};
}
}

80
src/main/java/com/fr/plugin/decision/request/handler/CheckNameHandler.java

@ -0,0 +1,80 @@
package com.fr.plugin.decision.request.handler;
import com.finebi.activate.foundation.StableManager;
import com.finebi.common.api.vo.table.FineBusinessTable;
import com.finebi.common.api.vo.table.FineExcelBusinessTable;
import com.finebi.direct.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 CheckNameHandler extends HWAbstractHandler {
public static final String PATH="/excelmng/check/name";
@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;
}
}

81
src/main/java/com/fr/plugin/decision/request/handler/CheckSizeHandler.java

@ -0,0 +1,81 @@
package com.fr.plugin.decision.request.handler;
import com.finebi.activate.foundation.StableManager;
import com.finebi.common.api.vo.table.FineBusinessTable;
import com.finebi.common.api.vo.table.FineExcelBusinessTable;
import com.finebi.dashboard.impl.service.helper.FineDashBoardTableHelper;
import com.finebi.direct.burger.api.service.FineUserInfoService;
import com.finebi.direct.common.api.cell.context.CellCreator;
import com.finebi.common.api.cell.user.authority.UserAuthority;
import com.finebi.direct.common.impl.engine.BurgerTableDataCellImpl;
import com.finebi.foundation.api.service.FineService;
import com.finebi.foundation.api.service.context.BaseContext;
import com.finebi.burger.api.bean.configuration.table.page.ConfLimitInfo;
import com.finebi.burger.api.bean.configuration.table.page.ConfPageInfo;
import com.finebi.foundation.api.structure.result.BIDetailResult;
import com.finebi.foundation.constant.BICommonConstants;
import com.finebi.widget.direct.impl.provider.authority.AuthorityUserHelper;
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.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
public class CheckSizeHandler extends HWAbstractHandler {
public static final String PATH="/excelmng/check/size";
@Override
protected void deal(HttpServletRequest req, HttpServletResponse res, JSONObject para, JSONObject result) throws Exception {
JSONObject finalResult = JSONObject.create();
ArrayList<JSONObject> excelList = new ArrayList<JSONObject>();
List<FineBusinessTable> allTables = CellCreator.getCellProvider().tableCell().getAllTableWithoutAuth();
allTables.forEach(fineBusinessTable -> {
if (fineBusinessTable instanceof FineExcelBusinessTable) {
try {
UserAuthority authorityUser = getFineUserInfoService().getUserAuthority(req);
Optional<BIDetailResult> data = new BurgerTableDataCellImpl().getRealDataWithAuth(fineBusinessTable, new ConfLimitInfo(500000, new ConfPageInfo()), authorityUser);
BIDetailResult detailResult = data.get();
JSONObject excel = JSONObject.create();
excel.put("transferName", fineBusinessTable.getTransferName()).
put("rowCount", detailResult.totalRowSize());
excelList.add(excel);
} catch(Exception e){
e.printStackTrace();
}
}
});
WebUtils.printAsJSON(res, finalResult.put("data", excelList));
}
@Override
public String getPath() {
return PATH;
}
protected static FineUserInfoService getFineUserInfoService() {
return getBean(FineUserInfoService.class);
}
private static <T extends FineService> T getBean(Class<T> annotatedClass) {
return getContext().getServiceBean(annotatedClass);
}
/**
* service获取集合
*/
private static BaseContext getContext() {
return StableManager.getContext();
}
}

34
src/main/java/com/fr/plugin/decision/request/handler/TableDataImport.java

@ -1,5 +1,8 @@
package com.fr.plugin.decision.request.handler;
import com.finebi.burger.api.request.configuration.table.DataBaseAddTableRequestBean;
import com.finebi.common.api.cell.user.authority.UserAuthority;
import com.finebi.common.api.vo.table.FineBusinessTable;
import com.fr.decision.webservice.v10.user.UserService;
import com.fr.json.JSONArray;
import com.fr.json.JSONObject;
@ -10,6 +13,9 @@ import com.fr.plugin.decision.core.action.ExcelDmlAction;
import com.fr.plugin.decision.dao.ExcelLinkService;
import com.fr.plugin.decision.utils.JdbcUtils;
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.usermodel.XSSFSheet;
@ -18,6 +24,7 @@ import com.fr.web.utils.WebUtils;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;
import java.util.HashMap;
import java.util.List;
@ -80,6 +87,33 @@ public class TableDataImport extends HWAbstractHandler {
ExcelLinkService.getInstance().addLink(name, connection, schema, tableName, createUser);
FineLoggerFactory.getLogger().info("HW_excel导入:FineDB 新增数据成功" + name);
}
if (StringUtils.equals("success", dmlResult.getString("status")) || StringUtils.contains(dmlResult.getString("errorText"), "existed")) {
ObjectMapper mapper = new ObjectMapper();
JSONObject table = JSONObject.create().put("tableName", tableName).put("connectionName", connection);
JSONArray tables = JSONArray.create().put(table);
JSONObject tablesBean = JSONObject.create().put("tables", tables);
try{
UserAuthority authorityUser = UpgradeHandler.getFineUserInfoService().getUserAuthority(req);
String userId = authorityUser.getUser().getInfo().getUserId();
String packId = "__my_analysis__" + userId + 1;
try {
String tableString = tablesBean.toString();
FineBusinessTable[] businessTables = UpgradeHandler.createBusinessTablesFromDBNewAddTableInfo(mapper.readValue(tableString, DataBaseAddTableRequestBean.class), userId);
UpgradeHandler.getTableService().addNewTable(packId, authorityUser, businessTables);
} catch (JsonMappingException e) {
e.printStackTrace();
} catch (JsonGenerationException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
} catch(Exception e){
e.printStackTrace();
}
}
WebUtils.printAsJSON(res, dmlResult);
}

217
src/main/java/com/fr/plugin/decision/request/handler/UpgradeHandler.java

@ -0,0 +1,217 @@
package com.fr.plugin.decision.request.handler;
import com.finebi.activate.foundation.StableManager;
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;
import com.finebi.common.api.vo.pack.FineBusinessPackage;
import com.finebi.common.api.vo.relation.FineBusinessRelation;
import com.finebi.common.api.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;
import com.fr.json.JSONObject;
import com.fr.log.FineLoggerFactory;
import com.fr.plugin.decision.HWUtils;
import com.fr.plugin.decision.core.ActionFactory;
import com.fr.plugin.decision.core.ExcelDmlBean;
import com.fr.plugin.decision.core.action.ExcelDmlAction;
import com.fr.plugin.decision.dao.ExcelLinkService;
import com.fr.plugin.decision.utils.JdbcUtils;
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.finebi.direct.common.api.cell.context.CellCreator;
import com.finebi.common.api.vo.table.FineBusinessTable;
import com.finebi.common.api.vo.table.FineExcelBusinessTable;
import com.fr.web.utils.WebUtils;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
public class UpgradeHandler extends HWAbstractHandler {
public static final String PATH="/excelmng/upgrade";
@Override
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);
if (conn == null){
FineLoggerFactory.getLogger().error("HW_excel导入:数据链接 " + connection + " 获取异常" );
WebUtils.printAsJSON(res, new JSONObject().put("status","fail").put("errorText","获取数据连接异常"));
return;
}
final String createUser = UserService.getInstance().getCurrentUserIdFromCookie(req);
JSONArray importDbResult = JSONArray.create();
JSONArray addDbResult = JSONArray.create();
JSONObject finalResult = JSONObject.create();
List<FineBusinessTable> allTables = CellCreator.getCellProvider().tableCell().getAllTableWithoutAuth();
allTables.stream().filter(fineBusinessTable -> fineBusinessTable instanceof FineExcelBusinessTable).limit(15).forEach(fineBusinessTable -> {
Map<String, List> values = new HashMap<String, List>();
JSONArray items = JSONArray.create();
List<FineBusinessField> fields = ((FineExcelBusinessTable) fineBusinessTable).getExcelFields();
try {
Optional<BIDetailResult> 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();
}
String schema = "";
String tableName = fineBusinessTable.getName();
ExcelDmlAction excelDmlAction = ActionFactory.getInstance().create("add");
excelDmlAction.setExcelDmlBean( new ExcelDmlBean(connection, schema, tableName, items, values) );
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")) || StringUtils.contains(dmlResult.getString("errorText"), "existed")) {
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{
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());
CellCreator.getCellProvider().tableCell().removeTable(fineBusinessTable.getName(), CellCreator.getCellProvider().userCellProvider().authorityCell().getSuperAuthority());
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();
}
});
WebUtils.printAsJSON(res, finalResult.put("importDbResult", importDbResult).put("addDbResult", addDbResult));
}
@Override
public String getPath() {
return PATH;
}
protected static FineTableService getTableService() {
return getBean(FineTableService.class);
}
private static <T extends FineService> T getBean(Class<T> annotatedClass) {
return getContext().getServiceBean(annotatedClass);
}
/**
* service获取集合
*/
private static BaseContext getContext() {
return StableManager.getContext();
}
private int getFieldSqlType(int fieldType) {
if (CompareUtils.isEqual(fieldType, 16)) {
return 12;
} else if (CompareUtils.isEqual(fieldType, 32)) {
return 8;
} else if (CompareUtils.isEqual(fieldType, 48)) {
return 91;
}
return 12;
}
public static FineBusinessTable[] createBusinessTablesFromDBNewAddTableInfo(DataBaseAddTableRequestBean bean, String userId) {
List<DataBaseAddTableItemRequestBean> items = bean.getTables();
FineBusinessTable[] businessTables = new FineBusinessTable[items.size()];
for (int i = 0; i < businessTables.length; i++) {
DataBaseAddTableItemRequestBean item = items.get(i);
FineBusinessTable table = createBusinessTableByItem(item, userId);
businessTables[i] = table;
}
return businessTables;
}
private static FineBusinessTable createBusinessTableByItem(DataBaseAddTableItemRequestBean item, String userId) {
return createDBBusinessTable(item, userId);
}
private static FineBusinessTable createDBBusinessTable(DataBaseAddTableItemRequestBean item, String userId) {
FineDBBusinessTable table = new FineDBBusinessTable();
table.setConnectionName(item.getConnectionName());
table.setTableName(item.getDbTableName());
table.setCreateByWithId(userId);
String tableName = getTableNameWithConnection(item);
table.setId(tableName);
table.setName(tableName);
return table;
}
private static String getTableNameWithConnection(DataBaseAddTableItemRequestBean itemBean) {
return itemBean.getDbTableName();
}
protected static FineUserInfoService getFineUserInfoService() {
return getBean(FineUserInfoService.class);
}
}

2
src/main/java/com/fr/plugin/decision/utils/JdbcUtils.java

@ -6,8 +6,6 @@ import com.fr.data.impl.NameDatabaseConnection;
import com.fr.json.JSONArray;
import com.fr.json.JSONObject;
import com.fr.log.FineLoggerFactory;
import com.fr.plugin.decision.dialect.hive.HiveDialectConsummate;
import com.fr.report.core.A.S;
import com.fr.stable.StringUtils;
import com.fr.web.utils.WebUtils;

15
src/main/main.iml

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager">
<output url="file://$USER_HOME$/env/direct-bi/WEB-INF/plugins/plugin-com.fr.plugin.hw.import.excel-2.0.0/classes" />
<output-test url="file://$MODULE_DIR$/../../../../direct-bi/nuclear-maven/classes/test/main" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/java" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="lib" level="project" />
<orderEntry type="module" module-name="direct-common-adapter" />
</component>
</module>

10
src/main/resources/com/fr/plugin/hw/decision/js/hw.option.js

@ -35,6 +35,12 @@
BI.$import(commPath + "/pane/authPane/auth.pane.right.js");
BI.$import(commPath + "/pane/authPane/auth.pane.right.model.js");
BI.$import(commPath + "/pane/upgrade/upgrade.js");
BI.$import(commPath + "/pane/upgrade/upgrade.model.js");
BI.$import(commPath + "/pane/check/check.js");
BI.$import(commPath + "/pane/check/check.model.js");
BI.config("dec.constant.management.navigation", function (items) {
items.push({
@ -95,6 +101,8 @@
*/
BI.constant("dec.hw.constant.tabs", [
{value: "export", text: "Excel数据管理"},
{value: "auth", text: "Excel权限管理"}
{value: "auth", text: "Excel权限管理"},
{value: "upgrade", text: "一键升级旧Excel"},
{value: "check", text: "检测excel"},
]);
})();

66
src/main/resources/com/fr/plugin/hw/decision/js/pane/check/check.js

@ -0,0 +1,66 @@
!(function () {
var UpgradePane = BI.inherit(BI.Widget, {
props: {
baseCls: "dec-mng-check"
},
_store: function () {
return BI.Models.getModel("dec.model.mng.check");
},
watch: {
result: function (items) {
this.list.populate(this._createItems(items));
this.count.setText("excel表总数: " + BI.size(items));
}
},
render: function () {
var self = this;
return {
type: "bi.vertical",
width: 640,
hgap: 50,
vgap: 50,
items: [{
type: "bi.center_adapt",
items: [{
type: "bi.button",
width: 200,
text: "检测所有excel的大小",
handler: self.store.getResult
}]
}, {
type: "bi.center_adapt",
items: [{
type: "bi.label",
text: "excel表总数: 0",
ref: function (_ref) {
self.count = _ref;
}
}]
}, {
type: "bi.vertical",
ref: function (_ref) {
self.list = _ref;
}
}]
};
},
_createItems: function (items) {
return BI.map(items, function (idx, item) {
var text = "【" + item.transferName + "】数据量: " + item.rowCount;
return {
type: "bi.horizontal",
items: [{
type: "bi.label",
textAlign: "left",
text: text
}]
}
});
}
});
BI.shortcut("dec.mng.check", UpgradePane);
})();

19
src/main/resources/com/fr/plugin/hw/decision/js/pane/check/check.model.js

@ -0,0 +1,19 @@
!(function () {
var Model = BI.inherit(Fix.Model, {
state: function () {
return {
result: []
};
},
actions: {
getResult: function () {
var self = this;
Dec.HW.checkSize({}, function (res) {
self.model.result = res.data;
});
}
}
});
BI.model("dec.model.mng.check", Model);
})();

17
src/main/resources/com/fr/plugin/hw/decision/js/pane/left.js

@ -42,21 +42,8 @@
var tableData = BI.deepClone(table);
BI.hwfield2ColTypeDeal(tableData.items);
Dec.HW.importTableData(tableData, function (res) {
if (res.status === "success") {
BI.Utils.addTables2Pack({
packId: "__my_analysis__" + BI.Utils.getCurrentUserId(),
tables: [{
tableName: tableData.tableName,
connectionName: tableData.connection
}]
}, function () {
callback(res);
self.linkListPane.populate();
});
} else {
callback(res);
self.linkListPane.populate();
}
callback(res);
self.linkListPane.populate();
});
},
listeners: [

9
src/main/resources/com/fr/plugin/hw/decision/js/pane/left.linklist.js

@ -45,6 +45,15 @@
self.linkListPane = _ref;
}
}, top: 10, left: 0, right: 0, bottom: 10
}, {
el: {
type: "bi.button",
text: "一键删除",
height: 24,
handler: function () {
self.store.deleteAllLink();
}
}, top: -34, left: 100, right: 50, bottom: -10
}]
};
},

8
src/main/resources/com/fr/plugin/hw/decision/js/pane/left.linklist.model.js

@ -89,6 +89,14 @@
BI.emptyFn)
},
//删除全部: 仅内部人员使用
deleteAllLink: function(){
var self = this;
BI.each(self.model.linklist, function (i, v) {
self.deleteLink(v.id);
});
},
setSelectedLink: function(v){
this.model.selectedLink = v;
}

8
src/main/resources/com/fr/plugin/hw/decision/js/pane/panes.js

@ -60,6 +60,14 @@
return {
type: "dec.mng.authPane"
};
case "upgrade":
return {
type: "dec.mng.upgrade"
};
case "check":
return {
type: "dec.mng.check"
};
}
}
}]

148
src/main/resources/com/fr/plugin/hw/decision/js/pane/upgrade/upgrade.js

@ -0,0 +1,148 @@
!(function () {
var UpgradePane = BI.inherit(BI.Widget, {
props: {
baseCls: "dec-mng-upgrade"
},
_store: function () {
return BI.Models.getModel("dec.model.mng.upgrade");
},
watch: {
addDbResult: function (v) {
this.addList.populate(this._createAddItems(v));
},
importDbResult: function (v) {
this.importList.populate(this._createImportItems(v));
}
},
beforeInit: function (callback) {
this.store.initData(callback);
},
render: function () {
var self = this;
return {
type: "bi.vertical",
width: 640,
vgap: 15,
items: [{
type: "bi.vertical_adapt",
items: [{
type: "bi.label",
textAlign: "right",
cls: "dec-font-weight-bold",
text: "数据源:",
title: "数据源",
width: 100
}, {
el: {
type: "bi.text_value_combo",
lgap: 4,
cls: "bi-border",
textAlign: "left",
items: this.model.connectionItems,
width: 480,
height: 22,
ref: function (_ref) {
self.connection = _ref;
}
},
lgap: 10
}]
}, {
type: "bi.center_adapt",
items: [{
type: "bi.button",
width: 200,
text: "重名检测",
handler: function () {
Dec.HW.checkName({
connection: self.connection.getValue()[0]
}, function (res) {
var tip = "以下excel与数据库中已存在的表重名:"
BI.each(res.checkResult, function (i, tableName) {
tip += "\n" + tableName;
})
BI.Msg.toast(tip, {
autoClose: false,
level: "warning"
});
});
}
}, {
type: "bi.button",
width: 200,
text: "升级旧Excel",
handler: function () {
Dec.HW.upgrade({
connection: self.connection.getValue()[0]
}, function (res) {
self.store.setAddDbResult(res.addDbResult);
self.store.setImportDbResult(res.importDbResult);
});
}
}]
}, {
type: "bi.vertical",
items: [{
type: "bi.label",
text: "------Excel导入成数据库表报错信息------",
textAlign: "left"
}, {
type: "bi.button_group",
height: 300,
items: [],
layouts: [{
type: "bi.vertical",
scrolly: true
}],
ref: function (_ref) {
self.importList = _ref;
}
}, {
type: "bi.label",
text: "------从数据库表创建到自助数据集报错信息------",
textAlign: "left"
}, {
type: "bi.button_group",
height: 300,
items: [],
layouts: [{
type: "bi.vertical",
scrolly: true
}],
ref: function (_ref) {
self.addList = _ref;
}
}]
}]
};
},
_createAddItems: function (array) {
var items = BI.filter(array, function (idx, item) {
return !item.success;
});
return BI.map(items, function (idx, item) {
return {
type: "bi.label",
textAlign: "left",
text: item.errorMsg
}
});
},
_createImportItems: function (array) {
return BI.map(array, function (idx, item) {
return {
type: "bi.label",
textAlign: "left",
text: item.status === "failed" ? item.errorText : item.text
}
})
}
});
BI.shortcut("dec.mng.upgrade", UpgradePane);
})();

33
src/main/resources/com/fr/plugin/hw/decision/js/pane/upgrade/upgrade.model.js

@ -0,0 +1,33 @@
!(function () {
var Model = BI.inherit(Fix.Model, {
state: function () {
return {
connectionItems: [],
addDbResult: [],
importDbResult: []
};
},
actions: {
initData: function (callback) {
var self = this;
Dec.Utils.getConnections(function (res) {
self.model.connectionItems = BI.map(res, function (i, val) {
return {
text: val.connectionName || "",
value: val.connectionName || ""
};
});
callback();
});
},
setAddDbResult: function (result) {
this.model.addDbResult = result;
},
setImportDbResult: function (result) {
this.model.importDbResult = result;
}
}
});
BI.model("dec.model.mng.upgrade", Model);
})();

9
src/main/resources/com/fr/plugin/hw/decision/js/utils.js

@ -21,6 +21,15 @@
},
queryData: function (config, callback) {
Dec.reqPost("/url/excelmng/querydata", config, callback)
},
upgrade: function (config, callback) {
Dec.reqPost("/url/excelmng/upgrade", config, callback)
},
checkName: function (config, callback) {
Dec.reqPost("/url/excelmng/check/name", config, callback)
},
checkSize: function (config, callback) {
Dec.reqPost("/url/excelmng/check/size", config, callback)
}
})
})();
Loading…
Cancel
Save