|
|
|
@ -40,6 +40,7 @@ import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.github.pagehelper.page.PageMethod; |
|
|
|
import com.github.pagehelper.page.PageMethod; |
|
|
|
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; |
|
|
|
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; |
|
|
|
|
|
|
|
import com.google.common.collect.Lists; |
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag; |
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
@ -735,7 +736,23 @@ public class OnlineFormController { |
|
|
|
.map(OnlFormField::getFieldName).collect(Collectors.toSet()); |
|
|
|
.map(OnlFormField::getFieldName).collect(Collectors.toSet()); |
|
|
|
Set<String> newColumnNames = new HashSet<>(widgetColumnNames); |
|
|
|
Set<String> newColumnNames = new HashSet<>(widgetColumnNames); |
|
|
|
newColumnNames.removeAll(existingFieldNames); |
|
|
|
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()) { |
|
|
|
if (!newColumnNames.isEmpty()) { |
|
|
|
Map<String, JSONObject> nameToWidget = mapColumnNameToWidget(widgetJson); |
|
|
|
Map<String, JSONObject> nameToWidget = mapColumnNameToWidget(widgetJson); |
|
|
|
OnlineDblink dblink = onlineDblinkService.getById(datasource.getDblinkId()); |
|
|
|
OnlineDblink dblink = onlineDblinkService.getById(datasource.getDblinkId()); |
|
|
|
@ -758,7 +775,8 @@ public class OnlineFormController { |
|
|
|
JSONObject widget = nameToWidget.get(fieldName); |
|
|
|
JSONObject widget = nameToWidget.get(fieldName); |
|
|
|
// 从 widget 的 bindData.columnComment 设置字段备注
|
|
|
|
// 从 widget 的 bindData.columnComment 设置字段备注
|
|
|
|
JSONObject bindData = widget.getJSONObject("bindData"); |
|
|
|
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
|
|
|
|
// ALTER TABLE ADD COLUMN
|
|
|
|
@ -841,8 +859,9 @@ public class OnlineFormController { |
|
|
|
JSONObject columnInfoJson = nameToWidget.get(newSubColumnName); |
|
|
|
JSONObject columnInfoJson = nameToWidget.get(newSubColumnName); |
|
|
|
//step 1 : 先保存 field 表
|
|
|
|
//step 1 : 先保存 field 表
|
|
|
|
String showName = columnInfoJson.getString("showName"); |
|
|
|
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); |
|
|
|
onlFormHeadService.syncDB(entryHead, 0L); |
|
|
|
//step 2 :在保存 OnlineColumn 表
|
|
|
|
//step 2 :在保存 OnlineColumn 表
|
|
|
|
@ -873,6 +892,49 @@ public class OnlineFormController { |
|
|
|
metaCacheService.removeData(tableName); |
|
|
|
metaCacheService.removeData(tableName); |
|
|
|
changed = true; |
|
|
|
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 : 不存在的附表,新增
|
|
|
|
//step2 : 不存在的附表,新增
|
|
|
|
if (newSubTableNames.isEmpty()) { |
|
|
|
if (newSubTableNames.isEmpty()) { |
|
|
|
@ -906,7 +968,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(); |
|
|
|
OnlFormField field = new OnlFormField(); |
|
|
|
field.setHeadId(onlFormHead.getId()); |
|
|
|
field.setHeadId(onlFormHead.getId()); |
|
|
|
field.setFieldName(fieldName); |
|
|
|
field.setFieldName(fieldName); |
|
|
|
@ -915,6 +977,9 @@ public class OnlineFormController { |
|
|
|
if (length != null) { |
|
|
|
if (length != null) { |
|
|
|
field.setFieldLength(length); |
|
|
|
field.setFieldLength(length); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (StringUtils.isNotBlank(refPropert)) { |
|
|
|
|
|
|
|
field.setRefPropert(Long.valueOf(refPropert)); |
|
|
|
|
|
|
|
} |
|
|
|
field.setIsEmpty(1); |
|
|
|
field.setIsEmpty(1); |
|
|
|
field.setIsDefault(0); |
|
|
|
field.setIsDefault(0); |
|
|
|
field.setRowDisabled(0); |
|
|
|
field.setRowDisabled(0); |
|
|
|
@ -1025,6 +1090,28 @@ public class OnlineFormController { |
|
|
|
return map; |
|
|
|
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) { |
|
|
|
private Map<String, JSONObject> mapColumnIdAndWidget(JSONObject widgetJson) { |
|
|
|
Map<String, JSONObject> resultMap = new HashMap<>(); |
|
|
|
Map<String, JSONObject> resultMap = new HashMap<>(); |
|
|
|
walkAllModes(widgetJson, widget -> { |
|
|
|
walkAllModes(widgetJson, widget -> { |
|
|
|
@ -1104,4 +1191,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))); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|