|
|
|
|
@ -767,7 +767,23 @@ public class OnlineFormController {
@@ -767,7 +767,23 @@ public class OnlineFormController {
|
|
|
|
|
.map(OnlFormField::getFieldName).collect(Collectors.toSet()); |
|
|
|
|
Set<String> newColumnNames = new HashSet<>(widgetColumnNames); |
|
|
|
|
newColumnNames.removeAll(existingFieldNames); |
|
|
|
|
|
|
|
|
|
// 主表/单表已有字段:如果绑定了从表(slaveTableId),同步更新 refPropert
|
|
|
|
|
Map<String, JSONObject> fieldNameToWidget = mapFieldNameToWidget(widgetJson); |
|
|
|
|
for (OnlFormField existingField : existingFields) { |
|
|
|
|
JSONObject widget = fieldNameToWidget.get(existingField.getFieldName()); |
|
|
|
|
if (widget == null) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
JSONObject bindData = widget.getJSONObject("bindData"); |
|
|
|
|
if (bindData == null) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
String slaveTableId = bindData.getString("slaveTableId"); |
|
|
|
|
if (StrUtil.isNotEmpty(slaveTableId)) { |
|
|
|
|
existingField.setRefPropert(Long.valueOf(slaveTableId)); |
|
|
|
|
onlFormFieldService.updateById(existingField); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (!newColumnNames.isEmpty()) { |
|
|
|
|
Map<String, JSONObject> nameToWidget = mapColumnNameToWidget(widgetJson); |
|
|
|
|
OnlineDblink dblink = onlineDblinkService.getById(datasource.getDblinkId()); |
|
|
|
|
@ -790,7 +806,8 @@ public class OnlineFormController {
@@ -790,7 +806,8 @@ public class OnlineFormController {
|
|
|
|
|
JSONObject widget = nameToWidget.get(fieldName); |
|
|
|
|
// 从 widget 的 bindData.columnComment 设置字段备注
|
|
|
|
|
JSONObject bindData = widget.getJSONObject("bindData"); |
|
|
|
|
this.saveField(widget.getInteger("widgetType"), bindData.getString("columnComment"), widget.getString("showName"), onlFormHead, fieldName); |
|
|
|
|
String ref = bindData.containsKey("slaveTableId") ? bindData.getString("slaveTableId") : null; |
|
|
|
|
this.saveField(widget.getInteger("widgetType"), bindData.getString("columnComment"), widget.getString("showName"), onlFormHead, fieldName, ref); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// ALTER TABLE ADD COLUMN
|
|
|
|
|
@ -873,8 +890,9 @@ public class OnlineFormController {
@@ -873,8 +890,9 @@ public class OnlineFormController {
|
|
|
|
|
JSONObject columnInfoJson = nameToWidget.get(newSubColumnName); |
|
|
|
|
//step 1 : 先保存 field 表
|
|
|
|
|
String showName = columnInfoJson.getString("showName"); |
|
|
|
|
String ref = columnInfoJson.containsKey("slaveTableId") ? columnInfoJson.getString("slaveTableId") : null; |
|
|
|
|
// 默认是字符串类型
|
|
|
|
|
this.saveField(750, showName, null, entryHead, newSubColumnName); |
|
|
|
|
this.saveField(750, showName, null, entryHead, newSubColumnName, ref); |
|
|
|
|
} |
|
|
|
|
onlFormHeadService.syncDB(entryHead, 0L); |
|
|
|
|
//step 2 :在保存 OnlineColumn 表
|
|
|
|
|
@ -885,7 +903,7 @@ public class OnlineFormController {
@@ -885,7 +903,7 @@ public class OnlineFormController {
|
|
|
|
|
columnMap = allColumns.stream().collect(Collectors.toMap(SqlTableColumn::getColumnName, Function.identity())); |
|
|
|
|
} |
|
|
|
|
for (String fieldName : newSubColumnNameSet) { |
|
|
|
|
SqlTableColumn sqlCol = columnMap.get(fieldName.toLowerCase()); |
|
|
|
|
SqlTableColumn sqlCol = columnMap.get(fieldName); |
|
|
|
|
if (sqlCol != null) { |
|
|
|
|
// 回填 columnId 到 widgetJson
|
|
|
|
|
JSONObject widget = nameToWidget.get(fieldName); |
|
|
|
|
@ -905,6 +923,49 @@ public class OnlineFormController {
@@ -905,6 +923,49 @@ public class OnlineFormController {
|
|
|
|
|
metaCacheService.removeData(tableName); |
|
|
|
|
changed = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 附表已有字段:检查 tableColumnList 中 comType=402 的列是否有 slaveTableId,同步更新 refPropert
|
|
|
|
|
for (Long tableId : existingSubTableIdSet) { |
|
|
|
|
String tableName = tableIdAndNameMap.get(tableId); |
|
|
|
|
if (tableName == null) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
OnlFormHead subHead = tableNameAndHeadIdMap.get(tableName); |
|
|
|
|
if (subHead == null) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
List<OnlFormField> subFields = onlFormFieldService.list( |
|
|
|
|
new LambdaQueryWrapper<OnlFormField>().eq(OnlFormField::getHeadId, subHead.getId())); |
|
|
|
|
JSONObject props = tableIdAndPropMap.get(String.valueOf(tableId)); |
|
|
|
|
JSONArray tableColumnList = props != null ? props.getJSONArray("tableColumnList") : null; |
|
|
|
|
if (tableColumnList == null) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
for (OnlFormField field : subFields) { |
|
|
|
|
for (int i = 0; i < tableColumnList.size(); i++) { |
|
|
|
|
JSONObject col = tableColumnList.getJSONObject(i); |
|
|
|
|
// 匹配 showFieldName,兼容 showName
|
|
|
|
|
String showFieldName = col.getString("showFieldName"); |
|
|
|
|
if (StrUtil.isEmpty(showFieldName)) { |
|
|
|
|
showFieldName = col.getString("showName"); |
|
|
|
|
} |
|
|
|
|
if (!field.getFieldName().equals(showFieldName)) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
// 只有 comType=402(关联选择器)才有 slaveTableId
|
|
|
|
|
Integer comType = col.getInteger("comType"); |
|
|
|
|
if (comType != null && comType == 402) { |
|
|
|
|
String slaveTableId = col.getString("slaveTableId"); |
|
|
|
|
if (StrUtil.isNotEmpty(slaveTableId)) { |
|
|
|
|
field.setRefPropert(Long.valueOf(slaveTableId)); |
|
|
|
|
onlFormFieldService.updateById(field); |
|
|
|
|
changed = true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
//step2 : 不存在的附表,新增
|
|
|
|
|
if (newSubTableNames.isEmpty()) { |
|
|
|
|
@ -931,6 +992,15 @@ public class OnlineFormController {
@@ -931,6 +992,15 @@ public class OnlineFormController {
|
|
|
|
|
backfillRelationId(widgetJson, subTableName, subOnlineTable.getTableId()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//这里要将 所有的附表名称 加到 apelet.common.generator.model.OnlFormHead.childName 后面
|
|
|
|
|
String newSubTableName = String.join(",", newSubTableNames); |
|
|
|
|
if (StringUtils.isNotBlank(onlFormHead.getChildName())) { |
|
|
|
|
onlFormHead.setChildName(onlFormHead.getChildName() + "," + newSubTableName); |
|
|
|
|
} else { |
|
|
|
|
onlFormHead.setChildName(newSubTableName); |
|
|
|
|
} |
|
|
|
|
onlFormHeadService.updateById(onlFormHead); |
|
|
|
|
changed = true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -938,7 +1008,7 @@ public class OnlineFormController {
@@ -938,7 +1008,7 @@ public class OnlineFormController {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void saveField(Integer widgetType, String columnComment, String showName, OnlFormHead onlFormHead, String fieldName) { |
|
|
|
|
private void saveField(Integer widgetType, String columnComment, String showName, OnlFormHead onlFormHead, String fieldName, String refPropert) { |
|
|
|
|
OnlFormField field = new OnlFormField(); |
|
|
|
|
field.setHeadId(onlFormHead.getId()); |
|
|
|
|
field.setFieldName(fieldName); |
|
|
|
|
@ -947,6 +1017,9 @@ public class OnlineFormController {
@@ -947,6 +1017,9 @@ public class OnlineFormController {
|
|
|
|
|
if (length != null) { |
|
|
|
|
field.setFieldLength(length); |
|
|
|
|
} |
|
|
|
|
if (StringUtils.isNotBlank(refPropert)) { |
|
|
|
|
field.setRefPropert(Long.valueOf(refPropert)); |
|
|
|
|
} |
|
|
|
|
field.setIsEmpty(1); |
|
|
|
|
field.setIsDefault(0); |
|
|
|
|
field.setRowDisabled(0); |
|
|
|
|
@ -1057,6 +1130,28 @@ public class OnlineFormController {
@@ -1057,6 +1130,28 @@ public class OnlineFormController {
|
|
|
|
|
return map; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 构建 fieldName → widget 的映射(用于主表已有字段匹配)。 |
|
|
|
|
* key 优先取 bindData.columnFieldName,兼容 bindData.columnName。 |
|
|
|
|
*/ |
|
|
|
|
private Map<String, JSONObject> mapFieldNameToWidget(JSONObject widgetJson) { |
|
|
|
|
Map<String, JSONObject> map = new HashMap<>(); |
|
|
|
|
walkAllModes(widgetJson, widget -> { |
|
|
|
|
JSONObject bindData = widget.getJSONObject("bindData"); |
|
|
|
|
if (bindData == null) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
String fieldName = bindData.getString("columnFieldName"); |
|
|
|
|
if (StrUtil.isEmpty(fieldName)) { |
|
|
|
|
fieldName = bindData.getString("columnName"); |
|
|
|
|
} |
|
|
|
|
if (StrUtil.isNotEmpty(fieldName)) { |
|
|
|
|
map.put(fieldName, widget); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
return map; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private Map<String, JSONObject> mapColumnIdAndWidget(JSONObject widgetJson) { |
|
|
|
|
Map<String, JSONObject> resultMap = new HashMap<>(); |
|
|
|
|
walkAllModes(widgetJson, widget -> { |
|
|
|
|
@ -1136,4 +1231,19 @@ public class OnlineFormController {
@@ -1136,4 +1231,19 @@ public class OnlineFormController {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 根据表单类型查询表单列表 |
|
|
|
|
* |
|
|
|
|
* @param formType 表单类型 |
|
|
|
|
* @return 表单列表 |
|
|
|
|
* @see apelet.common.online.model.constant.FormType |
|
|
|
|
*/ |
|
|
|
|
@PostMapping(value = "/queryFormByType") |
|
|
|
|
public ResponseResult<List<OnlineForm>> queryFormByType(@MyRequestBody Integer formType) { |
|
|
|
|
if (formType == null) { |
|
|
|
|
return ResponseResult.error(ErrorCodeEnum.ARGUMENT_NULL_EXIST); |
|
|
|
|
} |
|
|
|
|
return ResponseResult.success(onlineFormService.queryListByFormType(Lists.newArrayList(formType))); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|