refactor(u8配置): 重构配置管理相关代码
将配置管理相关代码重构为ConfigBounder接口及其实现类,提取公共逻辑到AbstractConfigBounder基类 修复公司创建日期配置的显示问题,使用更直观的中文描述 将合同同步相关配置常量集中到ContractCtx中管理
This commit is contained in:
@@ -1,14 +1,5 @@
|
||||
package com.ecep.contract.manager.cloud.u8;
|
||||
|
||||
import com.ecep.contract.manager.SpringApp;
|
||||
import com.ecep.contract.manager.ds.contract.service.ContractService;
|
||||
import com.ecep.contract.manager.ds.contract.tasker.AbstContractRepairTasker;
|
||||
import com.ecep.contract.manager.ui.MessageHolder;
|
||||
import lombok.Setter;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Map;
|
||||
@@ -16,21 +7,45 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.ecep.contract.manager.SpringApp;
|
||||
import com.ecep.contract.manager.cloud.u8.ctx.ContractCtx;
|
||||
import com.ecep.contract.manager.ds.contract.tasker.AbstContractRepairTasker;
|
||||
import com.ecep.contract.manager.ui.MessageHolder;
|
||||
|
||||
/**
|
||||
* 合同同步任务
|
||||
*/
|
||||
public class ContractSyncTask extends AbstContractRepairTasker {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ContractSyncTask.class);
|
||||
@Setter
|
||||
private boolean useLatestId = true;
|
||||
private YongYouU8Repository repository;
|
||||
|
||||
public ContractSyncTask() {
|
||||
updateTitle("用友U8系统-同步合同");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void repair(MessageHolder holder) {
|
||||
updateTitle("用友U8系统-同步合同");
|
||||
try {
|
||||
repository = SpringApp.getBean(YongYouU8Repository.class);
|
||||
} catch (BeansException e) {
|
||||
holder.error("无法获取 YongYouU8Repository " + e.getMessage());
|
||||
return;
|
||||
}
|
||||
if (getConfService().getBoolean(ContractCtx.KEY_CONTRACT_SYNC_USE_LATEST_ID)) {
|
||||
syncByLatestId(holder);
|
||||
} else {
|
||||
syncByLatestDate(holder);
|
||||
}
|
||||
}
|
||||
|
||||
private void syncByLatestId(MessageHolder holder) {
|
||||
int latestId = getConfService().getInt(ContractService.CONTRACT_LATEST_ID);
|
||||
int latestId = getConfService().getInt(ContractCtx.CONTRACT_LATEST_ID);
|
||||
updateTitle("用友U8系统-同步合同,从 " + latestId + " 开始");
|
||||
|
||||
Long total = repository.countAllContracts(latestId);
|
||||
@@ -66,11 +81,11 @@ public class ContractSyncTask extends AbstContractRepairTasker {
|
||||
updateProgress(counter.incrementAndGet(), total);
|
||||
});
|
||||
}
|
||||
getConfService().set(ContractService.CONTRACT_LATEST_ID, String.valueOf(reference.get()));
|
||||
getConfService().set(ContractCtx.CONTRACT_LATEST_ID, String.valueOf(reference.get()));
|
||||
}
|
||||
|
||||
private void syncByLatestDate(MessageHolder holder) {
|
||||
String strDateTime = getConfService().getString(ContractService.CONTRACT_LATEST_DATE);
|
||||
String strDateTime = getConfService().getString(ContractCtx.CONTRACT_LATEST_DATE);
|
||||
LocalDateTime latestDateTime = null;
|
||||
if (StringUtils.hasText(strDateTime)) {
|
||||
try {
|
||||
@@ -120,17 +135,7 @@ public class ContractSyncTask extends AbstContractRepairTasker {
|
||||
updateProgress(counter.incrementAndGet(), total);
|
||||
});
|
||||
}
|
||||
getConfService().set(ContractService.CONTRACT_LATEST_DATE, String.valueOf(reference.get()));
|
||||
getConfService().set(ContractCtx.CONTRACT_LATEST_DATE, String.valueOf(reference.get()));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void repair(MessageHolder holder) {
|
||||
updateTitle("用友U8系统-同步合同");
|
||||
repository = SpringApp.getBean(YongYouU8Repository.class);
|
||||
if (useLatestId) {
|
||||
syncByLatestId(holder);
|
||||
} else {
|
||||
syncByLatestDate(holder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,31 +1,20 @@
|
||||
package com.ecep.contract.manager.cloud.u8;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
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 com.ecep.contract.manager.cloud.u8.ctx.CompanyCtx;
|
||||
import com.ecep.contract.manager.cloud.u8.ctx.ContractCtx;
|
||||
import com.ecep.contract.manager.ds.other.LocalDateConfig;
|
||||
import com.ecep.contract.manager.ds.other.StringConfig;
|
||||
import com.ecep.contract.manager.ui.BaseController;
|
||||
import com.ecep.contract.manager.ui.FxmlPath;
|
||||
|
||||
import javafx.beans.property.Property;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.DatePicker;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.stage.WindowEvent;
|
||||
import javafx.util.converter.LocalDateStringConverter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Lazy
|
||||
@Scope("prototype")
|
||||
@@ -49,68 +38,21 @@ public class YongYouU8ConfigWindowController extends BaseController {
|
||||
super.onShown(windowEvent);
|
||||
getTitle().set("用友U8配置");
|
||||
|
||||
LocalDateConfig config1 = new LocalDateConfig("cloud.u8.auto-create-company-after");
|
||||
LocalDateConfig config1 = new LocalDateConfig(CompanyCtx.AUTO_CREATE_COMPANY_AFTER);
|
||||
config1.setPicker(auto_create_company_after);
|
||||
config1.initialize();
|
||||
|
||||
LocalDateConfig config2 = new LocalDateConfig("cloud.u8.contract.latestDate");
|
||||
LocalDateConfig config2 = new LocalDateConfig(ContractCtx.CONTRACT_LATEST_DATE);
|
||||
config2.setPicker(contract_latest_date);
|
||||
config2.initialize();
|
||||
|
||||
}
|
||||
StringConfig config3 = new StringConfig(ContractCtx.CONTRACT_LATEST_ID);
|
||||
config3.setTextField(contract_latest_id);
|
||||
config3.initialize();
|
||||
|
||||
@NoArgsConstructor
|
||||
public static class LocalDateConfig {
|
||||
@Setter
|
||||
private SysConfService confService;
|
||||
|
||||
Property<LocalDate> property;
|
||||
@Setter
|
||||
javafx.util.StringConverter<LocalDate> converter;
|
||||
@Setter
|
||||
DatePicker picker;
|
||||
String key;
|
||||
SysConf conf;
|
||||
|
||||
public LocalDateConfig(String string) {
|
||||
key = string;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
public CompletableFuture<Void> runAsync(Runnable runnable) {
|
||||
return CompletableFuture.runAsync(runnable, Desktop.instance.getExecutorService()).exceptionally(ex -> {
|
||||
ex.printStackTrace();
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
public SysConfService getConfService() {
|
||||
if (confService == null) {
|
||||
confService = SpringApp.getBean(SysConfService.class);
|
||||
}
|
||||
return confService;
|
||||
}
|
||||
StringConfig config4 = new StringConfig("cloud.u8.sync.elapse");
|
||||
config4.setTextField(sync_elapse);
|
||||
config4.initialize();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,9 @@ import java.util.Objects;
|
||||
import static com.ecep.contract.manager.SpringApp.getBean;
|
||||
|
||||
public class CompanyCtx extends AbstractYongYouU8Ctx {
|
||||
/**
|
||||
* 自动创建公司的时间
|
||||
*/
|
||||
public static final String AUTO_CREATE_COMPANY_AFTER = "cloud.u8.auto-create-company-after";
|
||||
|
||||
@Setter
|
||||
@@ -111,7 +114,7 @@ public class CompanyCtx extends AbstractYongYouU8Ctx {
|
||||
return null;
|
||||
}
|
||||
CompanyService companyService = getCompanyService();
|
||||
String autoCreateAfter = SpringApp.getBean(SysConfService.class).getString(AUTO_CREATE_COMPANY_AFTER);
|
||||
String autoCreateAfter = getConfService().getString(AUTO_CREATE_COMPANY_AFTER);
|
||||
// 当配置存在,且开发时间小于指定时间,不创建
|
||||
if (StringUtils.hasText(autoCreateAfter)) {
|
||||
LocalDate miniDate = LocalDate.parse(autoCreateAfter);
|
||||
|
||||
@@ -45,6 +45,10 @@ import java.util.stream.Stream;
|
||||
import static com.ecep.contract.manager.SpringApp.getBean;
|
||||
|
||||
public class ContractCtx extends AbstractYongYouU8Ctx {
|
||||
public static final String CONTRACT_LATEST_DATE = "cloud.u8.contract.latestDate";
|
||||
public static final String CONTRACT_LATEST_ID = "cloud.u8.contract.latestId";
|
||||
public static final String KEY_CONTRACT_SYNC_USE_LATEST_ID = "cloud.u8.contract.sync.use-latest-id";
|
||||
|
||||
|
||||
@Setter
|
||||
private ContractService contractService;
|
||||
@@ -74,6 +78,7 @@ public class ContractCtx extends AbstractYongYouU8Ctx {
|
||||
@Setter
|
||||
private int customerEntityUpdateDelayDays = 1;
|
||||
|
||||
|
||||
public ContractService getContractService() {
|
||||
if (contractService == null) {
|
||||
contractService = getBean(ContractService.class);
|
||||
|
||||
@@ -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