refactor(u8配置): 重构配置管理相关代码
将配置管理相关代码重构为ConfigBounder接口及其实现类,提取公共逻辑到AbstractConfigBounder基类 修复公司创建日期配置的显示问题,使用更直观的中文描述 将合同同步相关配置常量集中到ContractCtx中管理
This commit is contained in:
@@ -9,6 +9,7 @@ import java.util.Objects;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.ecep.contract.manager.cloud.u8.ctx.ContractCtx;
|
||||
import com.ecep.contract.manager.ds.company.model.Company;
|
||||
import com.ecep.contract.manager.ds.contract.ContractPayWay;
|
||||
import com.ecep.contract.manager.ds.contract.repository.ContractRepository;
|
||||
@@ -52,9 +53,6 @@ import com.ecep.contract.manager.ui.ViewModelService;
|
||||
public class ContractService implements ViewModelService<Contract, ContractViewModel> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ContractService.class);
|
||||
public static final String CONTRACT_BASE_PATH = "contract.base.path";
|
||||
public static final String CONTRACT_LATEST_ID = "cloud.u8.contract.latestId";
|
||||
public static final String CONTRACT_LATEST_DATE = "cloud.u8.contract.latestDate";
|
||||
|
||||
@Lazy
|
||||
@Autowired
|
||||
private ContractCatalogService contractCatalogService;
|
||||
@@ -152,10 +150,10 @@ public class ContractService implements ViewModelService<Contract, ContractViewM
|
||||
*/
|
||||
public void updateLatestIdAndDate(Integer latestId, LocalDateTime latestDate) {
|
||||
if (latestId != null) {
|
||||
confService.set(CONTRACT_LATEST_ID, String.valueOf(latestId));
|
||||
confService.set(ContractCtx.CONTRACT_LATEST_ID, String.valueOf(latestId));
|
||||
}
|
||||
if (latestDate != null) {
|
||||
confService.set(CONTRACT_LATEST_DATE, latestDate.toString());
|
||||
confService.set(ContractCtx.CONTRACT_LATEST_DATE, latestDate.toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.ecep.contract.manager.ds.other;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import com.ecep.contract.manager.Desktop;
|
||||
import com.ecep.contract.manager.SpringApp;
|
||||
import com.ecep.contract.manager.ds.other.model.SysConf;
|
||||
import com.ecep.contract.manager.ds.other.service.SysConfService;
|
||||
|
||||
import lombok.Setter;
|
||||
|
||||
public abstract class AbstractConfigBounder implements ConfigBounder {
|
||||
@Setter
|
||||
private SysConfService confService;
|
||||
String key;
|
||||
SysConf conf;
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> runAsync(Runnable runnable) {
|
||||
return CompletableFuture.runAsync(runnable, Desktop.instance.getExecutorService()).exceptionally(ex -> {
|
||||
ex.printStackTrace();
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysConfService getConfService() {
|
||||
if (confService == null) {
|
||||
confService = SpringApp.getBean(SysConfService.class);
|
||||
}
|
||||
return confService;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.ecep.contract.manager.ds.other;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import com.ecep.contract.manager.ds.other.service.SysConfService;
|
||||
|
||||
public interface ConfigBounder {
|
||||
|
||||
void setConfService(SysConfService confService);
|
||||
|
||||
void initialize();
|
||||
|
||||
CompletableFuture<Void> runAsync(Runnable runnable);
|
||||
|
||||
SysConfService getConfService();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.ecep.contract.manager.ds.other;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import com.ecep.contract.manager.Desktop;
|
||||
import com.ecep.contract.manager.SpringApp;
|
||||
import com.ecep.contract.manager.ds.other.model.SysConf;
|
||||
import com.ecep.contract.manager.ds.other.service.SysConfService;
|
||||
|
||||
import javafx.beans.property.Property;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.scene.control.DatePicker;
|
||||
import javafx.util.converter.LocalDateStringConverter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@NoArgsConstructor
|
||||
public class LocalDateConfig extends AbstractConfigBounder {
|
||||
Property<LocalDate> property;
|
||||
@Setter
|
||||
javafx.util.StringConverter<LocalDate> converter;
|
||||
@Setter
|
||||
DatePicker picker;
|
||||
|
||||
|
||||
public LocalDateConfig(String string) {
|
||||
key = string;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
picker.setDisable(true);
|
||||
if (converter == null) {
|
||||
converter = new LocalDateStringConverter(DateTimeFormatter.ISO_LOCAL_DATE, null);
|
||||
}
|
||||
picker.setConverter(converter);
|
||||
runAsync(() -> {
|
||||
conf = getConfService().findById(key);
|
||||
LocalDate date = converter.fromString(conf.getValue());
|
||||
property = new SimpleObjectProperty<>(date);
|
||||
property.addListener(this::propertyChanged);
|
||||
picker.valueProperty().bindBidirectional(property);
|
||||
picker.setDisable(false);
|
||||
});
|
||||
}
|
||||
|
||||
void propertyChanged(ObservableValue<? extends LocalDate> observable, LocalDate oldValue, LocalDate newValue) {
|
||||
conf.setValue(converter.toString(newValue));
|
||||
SysConf saved = getConfService().save(conf);
|
||||
saved.getValue();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.ecep.contract.manager.ds.other;
|
||||
|
||||
import com.ecep.contract.manager.ds.other.model.SysConf;
|
||||
|
||||
import javafx.beans.property.Property;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.scene.control.TextField;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@NoArgsConstructor
|
||||
public class StringConfig extends AbstractConfigBounder {
|
||||
@Setter
|
||||
private TextField textField;
|
||||
|
||||
String key;
|
||||
SysConf conf;
|
||||
|
||||
Property<String> property;
|
||||
|
||||
public StringConfig(String string) {
|
||||
key = string;
|
||||
}
|
||||
|
||||
public void initialize() {
|
||||
textField.setDisable(true);
|
||||
runAsync(() -> {
|
||||
conf = getConfService().findById(key);
|
||||
property = new SimpleStringProperty(conf.getValue());
|
||||
property.addListener(this::propertyChanged);
|
||||
textField.textProperty().bindBidirectional(property);
|
||||
textField.setDisable(false);
|
||||
});
|
||||
}
|
||||
|
||||
void propertyChanged(ObservableValue<? extends String> observable, String oldValue, String newValue) {
|
||||
conf.setValue(newValue);
|
||||
SysConf saved = getConfService().save(conf);
|
||||
saved.getValue();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user