Browse Source

feat(online): 添加数据表字段保存功能

- 新增 saveBySqlTable 方法用于保存新增数据表字段
- 添加字段注释逻辑处理,支持传入字段描述并设置默认值
- 集成 StringUtil 工具类进行字符串判空和比较操作
- 重构 OnlineFormController 中的字段创建逻辑,使用新方法替代原有实现
- 优化字段回填 columnId 到 widgetJson 的处理流程
online-form-direct-creation
chenchuchuan 2 weeks ago
parent
commit
e9c3b36512
  1. 14
      common/common-online/src/main/java/apelet/common/online/controller/OnlineFormController.java
  2. 10
      common/common-online/src/main/java/apelet/common/online/service/OnlineColumnService.java
  3. 23
      common/common-online/src/main/java/apelet/common/online/service/impl/OnlineColumnServiceImpl.java

14
common/common-online/src/main/java/apelet/common/online/controller/OnlineFormController.java

@ -793,23 +793,13 @@ public class OnlineFormController {
for (String fieldName : validColumnNames) { for (String fieldName : validColumnNames) {
SqlTableColumn sqlCol = columnMap.get(fieldName.toLowerCase()); SqlTableColumn sqlCol = columnMap.get(fieldName.toLowerCase());
if (sqlCol != null) { if (sqlCol != null) {
OnlineColumn newCol = new OnlineColumn();
newCol.setColumnName(sqlCol.getColumnName());
newCol.setColumnType(sqlCol.getColumnType());
newCol.setFullColumnType(sqlCol.getFullColumnType());
if (sqlCol.getColumnDefault() != null) {
newCol.setColumnDefault(sqlCol.getColumnDefault().toString());
}
newCol.setNullable(sqlCol.getNullable());
newCol.setTableId(onlineTable.getTableId());
onlineColumnService.save(newCol);
// 回填 columnId 到 widgetJson // 回填 columnId 到 widgetJson
JSONObject widget = nameToWidget.get(fieldName); JSONObject widget = nameToWidget.get(fieldName);
long columnId = onlineColumnService.saveBySqlTable(sqlCol, onlineTable.getTableId(), widget.getString("showName"));
if (widget != null) { if (widget != null) {
JSONObject bindData2 = widget.getJSONObject("bindData"); JSONObject bindData2 = widget.getJSONObject("bindData");
if (bindData2 != null) { if (bindData2 != null) {
bindData2.put("columnId", newCol.getColumnId()); bindData2.put("columnId", columnId);
bindData2.put("tableId", onlineTable.getTableId()); bindData2.put("tableId", onlineTable.getTableId());
} }
} }

10
common/common-online/src/main/java/apelet/common/online/service/OnlineColumnService.java

@ -27,6 +27,16 @@ public interface OnlineColumnService extends IBaseService<OnlineColumn, Long> {
List<OnlineColumn> saveNewList(List<SqlTableColumn> columnList, Long onlineTableId); List<OnlineColumn> saveNewList(List<SqlTableColumn> columnList, Long onlineTableId);
/** /**
* 保存新增数据表字段
*
* @param sqlTableColumn 新增数据表字段对象
* @param tableId 在线表对象的主键Id
* @param columnComment 字段名
* @return 插入的在线表字段数据
*/
long saveBySqlTable(SqlTableColumn sqlTableColumn, Long tableId, String columnComment);
/**
* 更新数据对象 * 更新数据对象
* *
* @param onlineColumn 更新的对象 * @param onlineColumn 更新的对象

23
common/common-online/src/main/java/apelet/common/online/service/impl/OnlineColumnServiceImpl.java

@ -31,6 +31,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.github.pagehelper.Page; import com.github.pagehelper.Page;
import com.google.common.base.CaseFormat; import com.google.common.base.CaseFormat;
import jodd.util.StringUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RedissonClient; import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -106,6 +107,28 @@ public class OnlineColumnServiceImpl extends BaseService<OnlineColumn, Long> imp
return onlineColumnList; return onlineColumnList;
} }
@Override
public long saveBySqlTable(SqlTableColumn sqlTableColumn, Long tableId, String columnComment) {
OnlineColumn onlineColumn = new OnlineColumn();
BeanUtil.copyProperties(sqlTableColumn, onlineColumn, false);
onlineColumn.setColumnId(idGenerator.nextLongId());
onlineColumn.setTableId(tableId);
// 传了描述,并且不等于原先的描述,并且原先的为空或者为"null",就赋值
if (StringUtil.isNotBlank(columnComment) && !StringUtil.equals(columnComment, onlineColumn.getColumnComment())
&& (StringUtil.isBlank(onlineColumn.getColumnComment()) || StringUtil.equals("null", onlineColumn.getColumnComment()))) {
onlineColumn.setColumnComment(columnComment);
}
if (StringUtil.isBlank(onlineColumn.getColumnComment())) {
onlineColumn.setColumnComment(onlineColumn.getColumnName());
}
this.setDefault(sqlTableColumn, onlineColumn);
if (super.save(onlineColumn)) {
return onlineColumn.getColumnId();
}
return 0;
}
/** /**
* 更新数据对象 * 更新数据对象
* *

Loading…
Cancel
Save