refactor(client): 重构银行和公司相关代码

- 更新了多个类中的导入语句,替换了模型类为对应的VO类
- 优化了部分方法的参数和返回类型,使用VO类替代模型类
- 重构了自动补全功能,使用统一的泛型方法
- 添加了缓存注解,提高了数据访问性能
- 优化了部分代码结构,提高了可维护性
This commit is contained in:
2025-09-18 09:08:57 +08:00
parent d0645c33f1
commit 2752828094
42 changed files with 341 additions and 243 deletions

View File

@@ -7,6 +7,10 @@ import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;
import java.util.function.Function;
import com.ecep.contract.model.IdentityEntity;
import com.ecep.contract.service.QueryService;
import com.ecep.contract.vm.IdentityViewModel;
import javafx.beans.property.ObjectProperty;
import org.controlsfx.control.textfield.AutoCompletionBinding;
import org.controlsfx.control.textfield.TextFields;
import org.slf4j.Logger;
@@ -72,7 +76,7 @@ public class UITools {
* @param content 扩张节点
*/
public static CompletableFuture<ButtonType> showAndWait(Alert.AlertType alertType, String title, String header,
String message, Node content) {
String message, Node content) {
CompletableFuture<ButtonType> future = new CompletableFuture<>();
Platform.runLater(() -> {
Alert alert = new Alert(alertType);
@@ -165,7 +169,7 @@ public class UITools {
* @param init 初始化
*/
public static void showTaskDialogAndWait(String title, javafx.concurrent.Task<?> task,
Consumer<Consumer<Message>> init) {
Consumer<Consumer<Message>> init) {
Dialog<Message> dialog = createDialog();
dialog.getDialogPane().getScene().getStylesheets().add("/ui/dialog.css");
dialog.setTitle(title);
@@ -244,6 +248,52 @@ public class UITools {
return autoCompletion(textField, property, converter::suggest, converter);
}
public static <T extends IdentityEntity, TV extends IdentityViewModel<T>> AutoCompletionBinding<T> autoCompletion(
TextField textField, ObjectProperty<Integer> idProperty, QueryService<T, TV> queryService) {
Integer id = idProperty.get();
T entity = queryService.findById(id);
StringConverter<T> converter = queryService.getStringConverter();
// 先赋值
textField.textProperty().set(converter.toString(entity));
// 监听 property 变化
idProperty.addListener((observable, oldValue, newValue) -> {
T newEntity = queryService.findById(newValue);
textField.textProperty().set(converter.toString(newEntity));
});
// 关联一个 自动完成
AutoCompletionBinding<T> completionBinding = TextFields.bindAutoCompletion(textField, p -> {
if (p.isCancelled()) {
return null;
}
try {
return queryService.search(p.getUserText());
} catch (Exception e) {
textField.setText(e.getMessage());
throw new RuntimeException(e);
}
}, converter);
// 设置自动补全选中值到 property
completionBinding.setOnAutoCompleted(event -> {
T completion = event.getCompletion();
idProperty.set(completion.getId());
});
// fixed 当输入框丢失焦点时输入框内容为空时设置property 为null
textField.focusedProperty().addListener((observable, oldValue, newValue) -> {
if (!newValue) {
if (!StringUtils.hasText(textField.getText())) {
idProperty.set(null);
}
}
});
return completionBinding;
}
/**
* 给 TextField 增加一个 自动补全功能
*