From d26d2b14a542fca196bf7dad908eb9ab0699e35d Mon Sep 17 00:00:00 2001 From: chenchuchuan <13554600537@163.com> Date: Fri, 24 Jul 2026 10:00:30 +0800 Subject: [PATCH] =?UTF-8?q?feat(online):=20=E6=B7=BB=E5=8A=A0=E4=BB=8E?= =?UTF-8?q?=E8=A1=A8=E5=85=B3=E8=81=94=E5=AD=97=E6=AE=B5=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E5=92=8C=E8=A1=A8=E5=8D=95=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在OnlCgreportItem模型中新增isSelectShow字段用于控制下拉显示 - 在OnlineFormController中实现主表/从表已有字段的refPropert同步更新逻辑 - 修改saveField方法以支持refPropert参数传递 - 新增mapFieldNameToWidget方法构建字段名到组件的映射关系 - 添加queryFormByType接口按表单类型查询表单列表 - 实现OnlineFormService的queryListByFormType方法和OnlinePageService的queryByEnableList方法 - 添加Guava Lists依赖并优化相关工具类导入 --- .../common/generator/model/OnlCgreportItem.java | 5 + .../online/controller/OnlineFormController.java | 110 ++++++++++++++++++++- .../common/online/service/OnlineFormService.java | 8 ++ .../common/online/service/OnlinePageService.java | 7 ++ .../online/service/impl/OnlineFormServiceImpl.java | 20 +++- .../online/service/impl/OnlinePageServiceImpl.java | 5 + 6 files changed, 150 insertions(+), 5 deletions(-) diff --git a/common/common-generator/src/main/java/apelet/common/generator/model/OnlCgreportItem.java b/common/common-generator/src/main/java/apelet/common/generator/model/OnlCgreportItem.java index 1b8a0e7..7dd8ca1 100644 --- a/common/common-generator/src/main/java/apelet/common/generator/model/OnlCgreportItem.java +++ b/common/common-generator/src/main/java/apelet/common/generator/model/OnlCgreportItem.java @@ -56,6 +56,11 @@ public class OnlCgreportItem extends BaseModel implements Serializable { @Schema(description = "是否显示 0否,1显示") private Integer isShow; + + @Schema(description = "是否下拉显示 0否,1显示") + private Integer isSelectShow; + + @Schema(description = "排序") private Integer orderNum; diff --git a/common/common-online/src/main/java/apelet/common/online/controller/OnlineFormController.java b/common/common-online/src/main/java/apelet/common/online/controller/OnlineFormController.java index f450dbd..622f04f 100644 --- a/common/common-online/src/main/java/apelet/common/online/controller/OnlineFormController.java +++ b/common/common-online/src/main/java/apelet/common/online/controller/OnlineFormController.java @@ -40,6 +40,7 @@ import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.github.pagehelper.page.PageMethod; import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; +import com.google.common.collect.Lists; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; @@ -735,7 +736,23 @@ public class OnlineFormController { .map(OnlFormField::getFieldName).collect(Collectors.toSet()); Set newColumnNames = new HashSet<>(widgetColumnNames); newColumnNames.removeAll(existingFieldNames); - + // 主表/单表已有字段:如果绑定了从表(slaveTableId),同步更新 refPropert + Map 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 nameToWidget = mapColumnNameToWidget(widgetJson); OnlineDblink dblink = onlineDblinkService.getById(datasource.getDblinkId()); @@ -758,7 +775,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 @@ -841,8 +859,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 表 @@ -873,6 +892,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 subFields = onlFormFieldService.list( + new LambdaQueryWrapper().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()) { @@ -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(); field.setHeadId(onlFormHead.getId()); field.setFieldName(fieldName); @@ -915,6 +977,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); @@ -1025,6 +1090,28 @@ public class OnlineFormController { return map; } + /** + * 构建 fieldName → widget 的映射(用于主表已有字段匹配)。 + * key 优先取 bindData.columnFieldName,兼容 bindData.columnName。 + */ + private Map mapFieldNameToWidget(JSONObject widgetJson) { + Map 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 mapColumnIdAndWidget(JSONObject widgetJson) { Map resultMap = new HashMap<>(); 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> queryFormByType(@MyRequestBody Integer formType) { + if (formType == null) { + return ResponseResult.error(ErrorCodeEnum.ARGUMENT_NULL_EXIST); + } + return ResponseResult.success(onlineFormService.queryListByFormType(Lists.newArrayList(formType))); + } } diff --git a/common/common-online/src/main/java/apelet/common/online/service/OnlineFormService.java b/common/common-online/src/main/java/apelet/common/online/service/OnlineFormService.java index 4bd603d..7159ae0 100644 --- a/common/common-online/src/main/java/apelet/common/online/service/OnlineFormService.java +++ b/common/common-online/src/main/java/apelet/common/online/service/OnlineFormService.java @@ -139,4 +139,12 @@ public interface OnlineFormService extends IBaseService { * @return */ ObjectValue getObjectValue(Map masterData, Map savedata, String tableName); + + /** + * 根据表单类型查询表单列表 + * + * @param formType 表单类型 + * @return 表单列表 + */ + List queryListByFormType(List formType); } diff --git a/common/common-online/src/main/java/apelet/common/online/service/OnlinePageService.java b/common/common-online/src/main/java/apelet/common/online/service/OnlinePageService.java index 88b9fa0..b15c644 100644 --- a/common/common-online/src/main/java/apelet/common/online/service/OnlinePageService.java +++ b/common/common-online/src/main/java/apelet/common/online/service/OnlinePageService.java @@ -135,4 +135,11 @@ public interface OnlinePageService extends IBaseService { * @return 在线表单页面列表。 */ List getInListWithNonTenant(List pageIds, String orderBy); + + /** + * 查询启用的在线表单页面列表。 + * + * @return 在线表单页面列表。 + */ + List queryByEnableList(); } diff --git a/common/common-online/src/main/java/apelet/common/online/service/impl/OnlineFormServiceImpl.java b/common/common-online/src/main/java/apelet/common/online/service/impl/OnlineFormServiceImpl.java index 2898c9e..4e099f5 100644 --- a/common/common-online/src/main/java/apelet/common/online/service/impl/OnlineFormServiceImpl.java +++ b/common/common-online/src/main/java/apelet/common/online/service/impl/OnlineFormServiceImpl.java @@ -26,6 +26,7 @@ import apelet.common.orm.impl.LinkEntityColumn; import apelet.common.redis.util.CommonRedisUtil; import apelet.common.sequence.wrapper.IdGeneratorWrapper; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.util.ObjectUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; @@ -35,7 +36,6 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.github.pagehelper.Page; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang.StringUtils; import org.jetbrains.annotations.NotNull; import org.redisson.api.RBucket; import org.redisson.api.RedissonClient; @@ -460,6 +460,24 @@ public class OnlineFormServiceImpl extends BaseService impleme return objectValue; } + + @Override + public List queryListByFormType(List formType) { + // 查询已发布的 page + List pageList = onlinePageService.queryByEnableList(); + if (CollectionUtil.isEmpty(pageList)) { + return Collections.emptyList(); + } + Set pageIdSet = pageList.stream().map(OnlinePage::getPageId).collect(Collectors.toSet()); + List formList = onlineFormMapper.selectList(new LambdaQueryWrapper().in(OnlineForm::getFormType, formType).in(OnlineForm::getPageId, pageIdSet)); + if (CollectionUtil.isNotEmpty(formList)) { + formList.forEach(item -> { + item.setWidgetJson(null); + }); + } + return formList; + } + /** * 设置关联表字段转换为对象 * diff --git a/common/common-online/src/main/java/apelet/common/online/service/impl/OnlinePageServiceImpl.java b/common/common-online/src/main/java/apelet/common/online/service/impl/OnlinePageServiceImpl.java index 2a8486a..a27f08b 100644 --- a/common/common-online/src/main/java/apelet/common/online/service/impl/OnlinePageServiceImpl.java +++ b/common/common-online/src/main/java/apelet/common/online/service/impl/OnlinePageServiceImpl.java @@ -296,4 +296,9 @@ public class OnlinePageServiceImpl extends BaseService impleme } return onlinePageMapper.selectList(queryWrapper); } + + @Override + public List queryByEnableList() { + return onlinePageMapper.selectList(new LambdaQueryWrapper().eq(OnlinePage::getPublished, true)); + } }