Browse Source

feat: 删除旧excel,创建同名db表以使ID相同

upgrade-final
Zhenfei.Li 4 years ago
parent
commit
02199a96c8
  1. 5
      .gitignore
  2. 91
      build.xml
  3. 2
      plugin.xml
  4. 3
      pom.xml
  5. 4
      src/main/java/com/fr/plugin/decision/core/action/CreateAction.java
  6. 51
      src/main/java/com/fr/plugin/decision/request/handler/UpgradeHandler.java
  7. 2
      src/main/resources/com/fr/plugin/hw/decision/js/pane/left.js
  8. 90
      src/main/resources/com/fr/plugin/hw/decision/js/pane/upgrade/upgrade.js
  9. 8
      src/main/resources/com/fr/plugin/hw/decision/js/pane/upgrade/upgrade.model.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"/>

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"/>

3
pom.xml

@ -39,7 +39,8 @@
</configuration>
</plugin>
</plugins>
<outputDirectory>/Users/leezerofly/env/direct-bi/WEB-INF/plugins/plugin-com.fr.plugin.hw.import.excel-2.0.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>

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);

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

@ -3,11 +3,13 @@ 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.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.impl.vo.table.FineDBBusinessTable;
import com.finebi.direct.burger.api.service.FineTableService;
import com.finebi.direct.burger.impl.service.helper.table.FineTableUtils;
import com.finebi.direct.common.authority.api.FineAuthorityUtils;
import com.finebi.direct.burger.api.service.FineUserInfoService;
import com.finebi.direct.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;
@ -33,7 +35,6 @@ 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;
import com.finebi.direct.common.authority.decision.role.FineAuthorityUser;
import com.fr.web.utils.WebUtils;
import javax.servlet.http.HttpServletRequest;
@ -138,6 +139,7 @@ public class UpgradeHandler extends HWAbstractHandler {
if (StringUtils.equals("success", dmlResult.getString("status")) && dmlResult.getBoolean("addLink")) {
ExcelLinkService.getInstance().addLink(name, connection, schema, tableName, createUser);
FineLoggerFactory.getLogger().info("HW_excel导入:FineDB 新增数据成功" + name);
CellCreator.getCellProvider().tableCell().removeTable(fineBusinessTable.getName(), CellCreator.getCellProvider().userCellProvider().authorityCell().getSuperAuthority());
}
} catch(Exception e){
e.printStackTrace();
@ -148,11 +150,11 @@ public class UpgradeHandler extends HWAbstractHandler {
JSONArray tables = JSONArray.create().put(table);
JSONObject tablesBean = JSONObject.create().put("tables", tables);
try{
FineAuthorityUser authorityUser = FineAuthorityUtils.getAuth(req);
String packid = "__my_analysis__" + authorityUser.getUserId() + "1";
UserAuthority authorityUser = getFineUserInfoService().getUserAuthority(req);
String packid = "__my_analysis__" + authorityUser.getUser().getInfo().getUserId() + "1";
try {
String tableString = tablesBean.toString();
FineBusinessTable[] businessTables = FineTableUtils.createBusinessTablesFromDBNewAddTableInfo(mapper.readValue(tableString, DataBaseAddTableRequestBean.class), authorityUser.getUserId());
FineBusinessTable[] businessTables = createBusinessTablesFromDBNewAddTableInfo(mapper.readValue(tableString, DataBaseAddTableRequestBean.class), authorityUser.getUser().getInfo().getUserId());
TableAddResponseBean responed = getTableService().addNewTable(packid, authorityUser, businessTables);
addDbResult.put(FineRespond.success(responed));
} catch (JsonMappingException e) {
@ -202,4 +204,41 @@ public class UpgradeHandler extends HWAbstractHandler {
}
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 com.finebi.utils.StringUtils.join("_", itemBean.getConnectionName(), itemBean.getDbTableName());
return itemBean.getDbTableName();
}
protected static FineUserInfoService getFineUserInfoService() {
return getBean(FineUserInfoService.class);
}
}

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

@ -44,7 +44,7 @@
Dec.HW.importTableData(tableData, function (res) {
if (res.status === "success") {
BI.Utils.addTables2Pack({
packId: "__my_analysis__" + BI.Utils.getCurrentUserId(),
packId: "__my_analysis__" + BI.Utils.getCurrentUserId() + BI.Utils.getUserEngine(),
tables: [{
tableName: tableData.tableName,
connectionName: tableData.connection

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

@ -8,6 +8,15 @@
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);
},
@ -43,16 +52,81 @@
lgap: 10
}]
}, {
type: "bi.button",
width: 200,
text: "升级旧Excel",
handler: function () {
Dec.HW.upgrade({
connection: self.connection.getValue()[0]
});
}
type: "bi.center_adapt",
items: [{
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) {
var items = BI.filter(array, function (idx, item) {
return item.status === "failed";
})
return BI.map(items, function (idx, item) {
return {
type: "bi.label",
textAlign: "left",
text: item.errorText
}
})
}
});
BI.shortcut("dec.mng.upgrade", UpgradePane);

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

@ -3,6 +3,8 @@
state: function () {
return {
connectionItems: [],
addDbResult: [],
importDbResult: []
};
},
@ -18,6 +20,12 @@
});
callback();
});
},
setAddDbResult: function (result) {
this.model.addDbResult = result;
},
setImportDbResult: function (result) {
this.model.importDbResult = result;
}
}
});

Loading…
Cancel
Save