Browse Source

feat:添加选择全部功能

pull/3/head
lml 2 weeks ago
parent
commit
192817f8e8
  1. 8
      common/common-online/src/main/java/apelet/common/online/dto/OnlinePluginExecuteDto.java
  2. 40
      common/common-online/src/main/java/apelet/common/online/service/impl/OnlineOperationServiceImpl.java

8
common/common-online/src/main/java/apelet/common/online/dto/OnlinePluginExecuteDto.java

@ -6,6 +6,7 @@ import lombok.Data;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.util.Map;
/** /**
* 在线表单插件操作执行dto * 在线表单插件操作执行dto
@ -31,4 +32,11 @@ public class OnlinePluginExecuteDto {
@Schema(description = "billId") @Schema(description = "billId")
@NotNull(message = "数据验证失败,formId不能为空!") @NotNull(message = "数据验证失败,formId不能为空!")
private String billId; private String billId;
@Schema(description = "是否选择全部")
private Boolean isSelectAll;
@Schema(description = "列表筛选条件")
private Map<String, Object> queryParams;
} }

40
common/common-online/src/main/java/apelet/common/online/service/impl/OnlineOperationServiceImpl.java

@ -53,6 +53,7 @@ import apelet.common.orm.impl.*;
import apelet.common.redis.util.CommonRedisUtil; import apelet.common.redis.util.CommonRedisUtil;
import apelet.common.sequence.wrapper.IdGeneratorWrapper; import apelet.common.sequence.wrapper.IdGeneratorWrapper;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.io.FileUtil; import cn.hutool.core.io.FileUtil;
import cn.hutool.core.lang.Assert; import cn.hutool.core.lang.Assert;
import cn.hutool.core.map.MapUtil; import cn.hutool.core.map.MapUtil;
@ -1085,6 +1086,15 @@ public class OnlineOperationServiceImpl implements OnlineOperationService {
} }
OnlineTable onlineTable = onlineTableService.getOnlineTableFromCache(onlineForm.getMasterTableId()); OnlineTable onlineTable = onlineTableService.getOnlineTableFromCache(onlineForm.getMasterTableId());
OnlFormHead onlFormHead = onlFormHeadService.getHeadTableNameCache(onlineTable.getTableName()); OnlFormHead onlFormHead = onlFormHeadService.getHeadTableNameCache(onlineTable.getTableName());
if (BooleanUtil.isTrue(onlinePluginExecuteDto.getIsSelectAll())) {
List<String> allBillIds = this.queryAllBillIds(onlineTable, onlinePluginExecuteDto.getQueryParams());
if (CollUtil.isEmpty(allBillIds)) {
OperationResult empty = new OperationResult();
empty.setMessage("没有符合条件的数据!");
return empty;
}
onlinePluginExecuteDto.setBillId(CollUtil.join(allBillIds, ","));
}
// executePlugin 是所有按钮的统一入口,附件的写入/清理必须按插件类型分别设闸, // executePlugin 是所有按钮的统一入口,附件的写入/清理必须按插件类型分别设闸,
// 否则「审核」这类只提交部分字段的按钮会把附件全量覆盖掉,「删除」则不会清理附件。 // 否则「审核」这类只提交部分字段的按钮会把附件全量覆盖掉,「删除」则不会清理附件。
boolean saveOperation = this.containsPlugin(sortDtoList, SaveOperationServicePlugIn.class); boolean saveOperation = this.containsPlugin(sortDtoList, SaveOperationServicePlugIn.class);
@ -1122,6 +1132,36 @@ public class OnlineOperationServiceImpl implements OnlineOperationService {
} }
/** /**
* 按列表筛选条件查询主表全部主键,用于"选择全部按钮"。
* queryParams 为 {列名: 值} 的等值条件;为空表示无筛选(即整表)。
*/
private List<String> queryAllBillIds(OnlineTable masterTable, Map<String, Object> queryParams) {
List<String> billIds = new ArrayList<>();
Filter filter = new Filter();
if (MapUtil.isNotEmpty(queryParams)) {
queryParams.forEach((column, value) -> {
if (value == null || "".equals(value)) {
return; // 空条件不过滤,与列表查询语义保持一致
}
filter.add(new FilterItem(column, FilterItem.equals, value));
});
}
Selector selector = new Selector();
selector.getList().add(new SelectorItem("id"));
ObjectCollection collection = ormGenDataSourceUtil.query(masterTable.getTableName(), filter, selector);
if (collection == null || collection.isEmpty()){
return new ArrayList<>();
}
for (int i = 0; i < collection.size(); i++) {
Object id = collection.getObject(i).get("id");
if (id != null) {
billIds.add(id.toString());
}
}
return billIds;
}
/**
* 判断当前按钮绑定的插件中是否包含指定插件。 * 判断当前按钮绑定的插件中是否包含指定插件。
* <p>按钮与插件的绑定是 widgetJson 中 pluginList[].class 的全限定类名(见 QuickFormWidgetUtil#setSaveButtonEnabled), * <p>按钮与插件的绑定是 widgetJson 中 pluginList[].class 的全限定类名(见 QuickFormWidgetUtil#setSaveButtonEnabled),
* 用类名判断比用中文 buttonName 可靠。</p> * 用类名判断比用中文 buttonName 可靠。</p>

Loading…
Cancel
Save