|
@@ -69,7 +69,7 @@ public class FormDataWithTableService {
|
|
|
|
|
|
@Autowired
|
|
|
private DataSourceService dataSourceService;
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 获取某个表单对应的主表的主键字段在数据集中的ID
|
|
|
*
|
|
@@ -87,7 +87,8 @@ public class FormDataWithTableService {
|
|
|
Column primaryColumn = fly.getPrimaryColumn(parentRf.getTable());
|
|
|
if (primaryColumn != null) {
|
|
|
String primaryKey = primaryColumn.getColumnName();
|
|
|
- RelationField pkRf = RelationUtil.getRelationFieldByFieldAndTable(primaryKey, parentRf.getTable(),
|
|
|
+ RelationField pkRf = RelationUtil.getRelationFieldByFieldAndTable(primaryKey,
|
|
|
+ parentRf.getTable(),
|
|
|
parentRf.getFields());
|
|
|
if (pkRf != null) {
|
|
|
primaryKeyId = Integer.valueOf(pkRf.getFieldId());
|
|
@@ -114,9 +115,9 @@ public class FormDataWithTableService {
|
|
|
String sql = buildListSql(relationTree, ds);
|
|
|
log.info("list sql is " + sql);
|
|
|
|
|
|
-// if (StringUtil.isNotEmpty(paginationModel.getJson())) {
|
|
|
-// // 有条件查询
|
|
|
-// }
|
|
|
+ // if (StringUtil.isNotEmpty(paginationModel.getJson())) {
|
|
|
+ // // 有条件查询
|
|
|
+ // }
|
|
|
CubeDataModel cubeData = dataSourceService.getCubeData(formInfo.getDbLinkId());
|
|
|
DataSourceModel dataSource = dataSourceService.getReportDatasource(String.valueOf(cubeData.getId()));
|
|
|
Page<JSONObject> page = new Page<JSONObject>(paginationModel.getCurrentPage(), paginationModel.getPageSize())
|
|
@@ -129,7 +130,8 @@ public class FormDataWithTableService {
|
|
|
Column primaryColumn = fly.getPrimaryColumn(parentRf.getTable());
|
|
|
if (primaryColumn != null) {
|
|
|
String primaryKey = primaryColumn.getColumnName();
|
|
|
- RelationField pkRf = RelationUtil.getRelationFieldByFieldAndTable(primaryKey, parentRf.getTable(),
|
|
|
+ RelationField pkRf = RelationUtil.getRelationFieldByFieldAndTable(primaryKey,
|
|
|
+ parentRf.getTable(),
|
|
|
parentRf.getFields());
|
|
|
if (pkRf != null) {
|
|
|
primaryKeyId = Integer.valueOf(pkRf.getFieldId());
|
|
@@ -140,6 +142,31 @@ public class FormDataWithTableService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 分页查询 仅返回分页数据
|
|
|
+ *
|
|
|
+ * @param formInfo
|
|
|
+ * @param paginationModel
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public PageModel<JSONObject> listPage(VisualdevEntity formInfo, PaginationModel paginationModel) {
|
|
|
+ DataSourceModel ds = dataSourceService.getReportDatasource(formInfo.getDbLinkId());
|
|
|
+ if (ds == null) {
|
|
|
+ return new PageModel<JSONObject>();
|
|
|
+ }
|
|
|
+
|
|
|
+ List<RelationBean> relationTree = dataSourceService.getRelationTree(formInfo.getTables(),
|
|
|
+ formInfo.getDbLinkId());
|
|
|
+ String sql = buildListSql(relationTree, ds);
|
|
|
+ log.info("list sql is " + sql);
|
|
|
+ CubeDataModel cubeData = dataSourceService.getCubeData(formInfo.getDbLinkId());
|
|
|
+ DataSourceModel dataSource = dataSourceService.getReportDatasource(String.valueOf(cubeData.getId()));
|
|
|
+ Page<JSONObject> page = new Page<JSONObject>(paginationModel.getCurrentPage(), paginationModel.getPageSize())
|
|
|
+ .setSearchCount(true);
|
|
|
+ PageModel<JSONObject> pageData = dynamicDataService.selectPage(page, dataSource, sql);
|
|
|
+ return pageData;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 构造完整的查询语句
|
|
|
*
|
|
|
* @param relationTree
|
|
@@ -269,7 +296,8 @@ public class FormDataWithTableService {
|
|
|
// 左查询
|
|
|
boolean b = false;
|
|
|
if (colData.getTreeRelation() != null) {
|
|
|
- b = keyJsonMap.keySet().stream()
|
|
|
+ b = keyJsonMap.keySet()
|
|
|
+ .stream()
|
|
|
.anyMatch(t -> t.equalsIgnoreCase(String.valueOf(colData.getTreeRelation())));
|
|
|
}
|
|
|
if (b && keyJsonMap.size() > searchVOList.size()) {
|
|
@@ -308,13 +336,13 @@ public class FormDataWithTableService {
|
|
|
/**
|
|
|
* 多表批量导入数据
|
|
|
*
|
|
|
- * @param cubeData 数据集信息
|
|
|
+ * @param cubeData 数据集信息
|
|
|
* @param withHeader 是否带表头
|
|
|
- * @param formInfo 表单信息
|
|
|
- * @param indexList 字段和excel索引映射关系
|
|
|
- * @param excelFile excel文件
|
|
|
+ * @param formInfo 表单信息
|
|
|
+ * @param indexList 字段和excel索引映射关系
|
|
|
+ * @param excelFile excel文件
|
|
|
* @return
|
|
|
- * @throws SQLException
|
|
|
+ * @throws SQLException
|
|
|
*/
|
|
|
public ActionResult<String> batchAddForMultipleTable(CubeDataModel cubeData, boolean withHeader,
|
|
|
VisualdevEntity formInfo, List<ExcelFieldIndex> indexList, File excelFile) throws SQLException {
|
|
@@ -328,13 +356,13 @@ public class FormDataWithTableService {
|
|
|
/**
|
|
|
* 单表批量导入数据
|
|
|
*
|
|
|
- * @param cubeData 数据集信息
|
|
|
+ * @param cubeData 数据集信息
|
|
|
* @param withHeader 是否带表头
|
|
|
- * @param formInfo 表单信息
|
|
|
- * @param indexList 字段和excel索引映射关系
|
|
|
- * @param excelFile excel文件
|
|
|
+ * @param formInfo 表单信息
|
|
|
+ * @param indexList 字段和excel索引映射关系
|
|
|
+ * @param excelFile excel文件
|
|
|
* @return
|
|
|
- * @throws SQLException
|
|
|
+ * @throws SQLException
|
|
|
*/
|
|
|
public ActionResult<String> batchAddForSingleTable(CubeDataModel cubeData, boolean withHeader,
|
|
|
VisualdevEntity formInfo, List<ExcelFieldIndex> indexList, File excelFile) throws SQLException {
|
|
@@ -348,7 +376,7 @@ public class FormDataWithTableService {
|
|
|
/**
|
|
|
* 提交表单数据入库
|
|
|
*
|
|
|
- * @param modelId 表单ID
|
|
|
+ * @param modelId 表单ID
|
|
|
* @param visualdevModelDataCrForm 前端提交的数据参数
|
|
|
* @return
|
|
|
*/
|
|
@@ -367,7 +395,7 @@ public class FormDataWithTableService {
|
|
|
List<RelationBean> relationTree = dataSourceService.getRelationTree(formInfo.getTables(),
|
|
|
formInfo.getDbLinkId());
|
|
|
Map<String, Object> formDataMap = JsonUtil.stringToMap(visualdevModelDataCrForm.getData());
|
|
|
-// log.info("formDataMap is " + JSON.toJSONString(formDataMap, true));
|
|
|
+ // log.info("formDataMap is " + JSON.toJSONString(formDataMap, true));
|
|
|
recursionInsertData(cubeData, ds, relationTree, formDataMap, null);
|
|
|
return ActionResult.success("操作成功");
|
|
|
}
|
|
@@ -375,10 +403,10 @@ public class FormDataWithTableService {
|
|
|
/**
|
|
|
* 递归插入数据
|
|
|
*
|
|
|
- * @param cubeData 数据集
|
|
|
- * @param ds 数据库连接对象
|
|
|
- * @param relationTree 表关联及字段信息
|
|
|
- * @param formDataMap 前端提交的所有数据集合
|
|
|
+ * @param cubeData 数据集
|
|
|
+ * @param ds 数据库连接对象
|
|
|
+ * @param relationTree 表关联及字段信息
|
|
|
+ * @param formDataMap 前端提交的所有数据集合
|
|
|
* @param relationDataMap 父表关联字段数据
|
|
|
*/
|
|
|
private void recursionInsertData(CubeDataModel cubeData, DataSourceModel ds, List<RelationBean> relationTree,
|
|
@@ -596,7 +624,7 @@ public class FormDataWithTableService {
|
|
|
String sql = sqlBuffer.toString();
|
|
|
log.info("batch delete sql is : " + sql);
|
|
|
dynamicDataService.executeSql(ds, sql);
|
|
|
- return ActionResult.fail("批量删除成功");
|
|
|
+ return ActionResult.success("批量删除成功");
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
@@ -642,8 +670,8 @@ public class FormDataWithTableService {
|
|
|
/**
|
|
|
* 更新数据
|
|
|
*
|
|
|
- * @param formInfo 表单信息
|
|
|
- * @param id 数据主键
|
|
|
+ * @param formInfo 表单信息
|
|
|
+ * @param id 数据主键
|
|
|
* @param visualdevModelDataUpForm 新数据
|
|
|
* @return
|
|
|
*/
|
|
@@ -664,7 +692,7 @@ public class FormDataWithTableService {
|
|
|
if (primaryColumn == null) {
|
|
|
return ActionResult.fail("更新失败,该表不存在主键,表名是:" + mainTable);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
Map<String, Object> formDataMap = JsonUtil.stringToMap(visualdevModelDataUpForm.getData());
|
|
|
List<UpdateBean> updateList = new ArrayList<>();
|
|
|
DsType dsType = DsType.reslove(ds.getDsType());
|
|
@@ -680,14 +708,14 @@ public class FormDataWithTableService {
|
|
|
/**
|
|
|
* 递归构造更新对象
|
|
|
*
|
|
|
- * @param ds 数据库连接
|
|
|
- * @param dsType 数据库类型
|
|
|
- * @param mainTableId 主表的主键
|
|
|
- * @param formDataMap 前端提交的要更新的数据
|
|
|
+ * @param ds 数据库连接
|
|
|
+ * @param dsType 数据库类型
|
|
|
+ * @param mainTableId 主表的主键
|
|
|
+ * @param formDataMap 前端提交的要更新的数据
|
|
|
* @param preTableOldDataList 上个表的旧数据
|
|
|
* @param preTableNewDataList 上个表的新数据
|
|
|
- * @param relationTree 数据集关联关系的树形结构
|
|
|
- * @param updateList 要构造的更新条件结构列表
|
|
|
+ * @param relationTree 数据集关联关系的树形结构
|
|
|
+ * @param updateList 要构造的更新条件结构列表
|
|
|
*/
|
|
|
private void recursionBuildUpdate(DataSourceModel ds, DsType dsType, String mainTableId,
|
|
|
Map<String, Object> formDataMap, List<Map<String, Object>> preTableOldDataList,
|
|
@@ -812,65 +840,75 @@ public class FormDataWithTableService {
|
|
|
|
|
|
if (CollUtil.isNotEmpty(relation.getChildren())) {
|
|
|
// 有子表,则继续递归
|
|
|
- recursionBuildUpdate(ds, dsType, null, formDataMap, curTableOldDataList, newColumnList,
|
|
|
- relation.getChildren(), updateList);
|
|
|
+ recursionBuildUpdate(ds,
|
|
|
+ dsType,
|
|
|
+ null,
|
|
|
+ formDataMap,
|
|
|
+ curTableOldDataList,
|
|
|
+ newColumnList,
|
|
|
+ relation.getChildren(),
|
|
|
+ updateList);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// private ActionResult<String> updateForSingleTable(Column primaryColumn, String tableName, DataSourceModel ds,
|
|
|
-// Map<String, Object> formDataMap, String id) {
|
|
|
-// try {
|
|
|
-// DsType dsType = DsType.reslove(ds.getDsType());
|
|
|
-// StringBuffer sqlBuffer = new StringBuffer();
|
|
|
-// sqlBuffer.append("update " + tableName + " ");
|
|
|
-//
|
|
|
-// StringBuffer valueSql = new StringBuffer("set ");
|
|
|
-// formDataMap.forEach((key, object) -> {
|
|
|
-// String value = object == null || object.toString().equalsIgnoreCase("[]") ? null : object.toString();
|
|
|
-// CubeTableColumnModel field = dataSourceService.getFieldInfo(Integer.parseInt(key));
|
|
|
-// String fieldName = field.getColumnName();
|
|
|
-//
|
|
|
-// if (value != null) {
|
|
|
-// ViewColumnTypeEnum dataType = ViewColumnTypeEnum.resolve(field.getViewDataType());
|
|
|
-// if (dataType == ViewColumnTypeEnum.STRING) {
|
|
|
-// value = "'" + value + "'";
|
|
|
-// } else if (dataType == ViewColumnTypeEnum.DATETIME) {
|
|
|
-// // 时间日期类型 前端统一传递的都是时间戳
|
|
|
-// long timestamp = Long.decode(value);
|
|
|
-// value = DateUtil.daFormat(timestamp);
|
|
|
-// value = "'" + value + "'";
|
|
|
-// if (dsType == DsType.Oracle) {
|
|
|
-// value = "to_date(" + value + ",'yyyy-mm-dd HH24:mi:ss')";
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// if (!primaryColumn.getColumnName().equalsIgnoreCase(fieldName)) {
|
|
|
-// // 不是主键
|
|
|
-// valueSql.append(fieldName + "=" + value);
|
|
|
-// valueSql.append(",");
|
|
|
-// }
|
|
|
-// });
|
|
|
-//
|
|
|
-// String vsql = valueSql.toString();
|
|
|
-// vsql = vsql.substring(0, vsql.length() - 1);
|
|
|
-// sqlBuffer.append(vsql);
|
|
|
-// sqlBuffer.append(" where " + primaryColumn.getColumnName() + "=");
|
|
|
-// String symbol = "";
|
|
|
-// if (primaryColumn.getJavaType().equalsIgnoreCase("String")) {
|
|
|
-// // 主键是字符串
|
|
|
-// symbol = "'";
|
|
|
-// }
|
|
|
-// sqlBuffer.append(symbol + id + symbol + " ");
|
|
|
-//
|
|
|
-// String sql = sqlBuffer.toString();
|
|
|
-// log.info("update sql of single table is " + sql);
|
|
|
-// dynamicDataService.executeSql(ds, sql);
|
|
|
-// return ActionResult.success("更新成功");
|
|
|
-// } catch (Exception e) {
|
|
|
-// }
|
|
|
-// return ActionResult.fail("更新失败");
|
|
|
-// }
|
|
|
+ // private ActionResult<String> updateForSingleTable(Column primaryColumn,
|
|
|
+ // String tableName, DataSourceModel ds,
|
|
|
+ // Map<String, Object> formDataMap, String id) {
|
|
|
+ // try {
|
|
|
+ // DsType dsType = DsType.reslove(ds.getDsType());
|
|
|
+ // StringBuffer sqlBuffer = new StringBuffer();
|
|
|
+ // sqlBuffer.append("update " + tableName + " ");
|
|
|
+ //
|
|
|
+ // StringBuffer valueSql = new StringBuffer("set ");
|
|
|
+ // formDataMap.forEach((key, object) -> {
|
|
|
+ // String value = object == null || object.toString().equalsIgnoreCase("[]") ?
|
|
|
+ // null : object.toString();
|
|
|
+ // CubeTableColumnModel field =
|
|
|
+ // dataSourceService.getFieldInfo(Integer.parseInt(key));
|
|
|
+ // String fieldName = field.getColumnName();
|
|
|
+ //
|
|
|
+ // if (value != null) {
|
|
|
+ // ViewColumnTypeEnum dataType =
|
|
|
+ // ViewColumnTypeEnum.resolve(field.getViewDataType());
|
|
|
+ // if (dataType == ViewColumnTypeEnum.STRING) {
|
|
|
+ // value = "'" + value + "'";
|
|
|
+ // } else if (dataType == ViewColumnTypeEnum.DATETIME) {
|
|
|
+ // // 时间日期类型 前端统一传递的都是时间戳
|
|
|
+ // long timestamp = Long.decode(value);
|
|
|
+ // value = DateUtil.daFormat(timestamp);
|
|
|
+ // value = "'" + value + "'";
|
|
|
+ // if (dsType == DsType.Oracle) {
|
|
|
+ // value = "to_date(" + value + ",'yyyy-mm-dd HH24:mi:ss')";
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // if (!primaryColumn.getColumnName().equalsIgnoreCase(fieldName)) {
|
|
|
+ // // 不是主键
|
|
|
+ // valueSql.append(fieldName + "=" + value);
|
|
|
+ // valueSql.append(",");
|
|
|
+ // }
|
|
|
+ // });
|
|
|
+ //
|
|
|
+ // String vsql = valueSql.toString();
|
|
|
+ // vsql = vsql.substring(0, vsql.length() - 1);
|
|
|
+ // sqlBuffer.append(vsql);
|
|
|
+ // sqlBuffer.append(" where " + primaryColumn.getColumnName() + "=");
|
|
|
+ // String symbol = "";
|
|
|
+ // if (primaryColumn.getJavaType().equalsIgnoreCase("String")) {
|
|
|
+ // // 主键是字符串
|
|
|
+ // symbol = "'";
|
|
|
+ // }
|
|
|
+ // sqlBuffer.append(symbol + id + symbol + " ");
|
|
|
+ //
|
|
|
+ // String sql = sqlBuffer.toString();
|
|
|
+ // log.info("update sql of single table is " + sql);
|
|
|
+ // dynamicDataService.executeSql(ds, sql);
|
|
|
+ // return ActionResult.success("更新成功");
|
|
|
+ // } catch (Exception e) {
|
|
|
+ // }
|
|
|
+ // return ActionResult.fail("更新失败");
|
|
|
+ // }
|
|
|
|
|
|
/**
|
|
|
* 获取某个表的主键字段
|