refactor(配置管理): 重构配置绑定与保存逻辑
将配置绑定逻辑抽象到StringConfig类中,统一处理配置的保存与控件绑定 提取配置键常量到对应服务类中,提高代码可维护性 使用LocalDateTime替代Instant处理时间字段 简化SysConfRepository继承结构,使用自定义基础仓库 优化SysConfWindowController的配置管理逻辑,减少重复代码
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
package com.ecep.contract.manager.cloud.u8;
|
package com.ecep.contract.manager.cloud.u8;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@@ -10,8 +9,6 @@ import org.springframework.context.annotation.Scope;
|
|||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import com.ecep.contract.manager.Desktop;
|
import com.ecep.contract.manager.Desktop;
|
||||||
import com.ecep.contract.manager.cloud.CloudBaseInfo;
|
|
||||||
import com.ecep.contract.manager.cloud.CloudInfo;
|
|
||||||
import com.ecep.contract.manager.ds.company.model.Company;
|
import com.ecep.contract.manager.ds.company.model.Company;
|
||||||
import com.ecep.contract.manager.ui.AbstManagerWindowController;
|
import com.ecep.contract.manager.ui.AbstManagerWindowController;
|
||||||
import com.ecep.contract.manager.ui.BaseController;
|
import com.ecep.contract.manager.ui.BaseController;
|
||||||
|
|||||||
@@ -40,6 +40,11 @@ public class YongYouU8Service implements ViewModelService<CloudYu, CloudYuInfoVi
|
|||||||
private static final Logger logger = LoggerFactory.getLogger(YongYouU8Service.class);
|
private static final Logger logger = LoggerFactory.getLogger(YongYouU8Service.class);
|
||||||
public static final String NAME = "用友U8";
|
public static final String NAME = "用友U8";
|
||||||
|
|
||||||
|
public static final String KEY_HOST_IP = "u8.db.server.ip";
|
||||||
|
public static final String KEY_DATABASE = "u8.db.database";
|
||||||
|
public static final String KEY_USER_NAME = "u8.db.server.name";
|
||||||
|
public static final String KEY_PASSWORD = "u8.db.server.password";
|
||||||
|
|
||||||
@Lazy
|
@Lazy
|
||||||
@Autowired
|
@Autowired
|
||||||
private YongYouU8Repository repository;
|
private YongYouU8Repository repository;
|
||||||
|
|||||||
@@ -1,21 +1,21 @@
|
|||||||
package com.ecep.contract.manager.cloud.u8.ctx;
|
package com.ecep.contract.manager.cloud.u8.ctx;
|
||||||
|
|
||||||
import com.ecep.contract.manager.SpringApp;
|
import static com.ecep.contract.manager.SpringApp.getBean;
|
||||||
import com.ecep.contract.manager.cloud.u8.YongYouU8Service;
|
|
||||||
import com.ecep.contract.manager.ds.company.model.Company;
|
|
||||||
import com.ecep.contract.manager.ds.company.model.CompanyOldName;
|
|
||||||
import com.ecep.contract.manager.ds.company.service.CompanyOldNameService;
|
|
||||||
import com.ecep.contract.manager.ds.company.service.CompanyService;
|
|
||||||
import com.ecep.contract.manager.ds.other.service.SysConfService;
|
|
||||||
import com.ecep.contract.manager.ui.MessageHolder;
|
|
||||||
import lombok.Setter;
|
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import static com.ecep.contract.manager.SpringApp.getBean;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
import com.ecep.contract.manager.cloud.u8.YongYouU8Service;
|
||||||
|
import com.ecep.contract.manager.ds.company.model.Company;
|
||||||
|
import com.ecep.contract.manager.ds.company.model.CompanyOldName;
|
||||||
|
import com.ecep.contract.manager.ds.company.service.CompanyOldNameService;
|
||||||
|
import com.ecep.contract.manager.ds.company.service.CompanyService;
|
||||||
|
import com.ecep.contract.manager.ui.MessageHolder;
|
||||||
|
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
public class CompanyCtx extends AbstractYongYouU8Ctx {
|
public class CompanyCtx extends AbstractYongYouU8Ctx {
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -42,13 +42,15 @@ import java.util.stream.Collectors;
|
|||||||
@Lazy
|
@Lazy
|
||||||
@Service
|
@Service
|
||||||
@CacheConfig(cacheNames = "company-customer")
|
@CacheConfig(cacheNames = "company-customer")
|
||||||
public class CompanyCustomerService extends CompanyBasicService implements ViewModelService<CompanyCustomer, CompanyCustomerViewModel> {
|
public class CompanyCustomerService extends CompanyBasicService
|
||||||
|
implements ViewModelService<CompanyCustomer, CompanyCustomerViewModel> {
|
||||||
private static final Logger logger = LoggerFactory.getLogger(CompanyCustomerService.class);
|
private static final Logger logger = LoggerFactory.getLogger(CompanyCustomerService.class);
|
||||||
|
|
||||||
private static final String EVALUATION_FORM_NAME1 = "评定表";
|
private static final String EVALUATION_FORM_NAME1 = "评定表";
|
||||||
public static final String EVALUATION_FORM_NAME2 = "评估表";
|
public static final String EVALUATION_FORM_NAME2 = "评估表";
|
||||||
|
|
||||||
public static final String KEY_BASE_PATH = "customer.base.path";
|
public static final String KEY_BASE_PATH = "customer.base.path";
|
||||||
|
public static final String KEY_SALEBOOK_PATH = "customer.salebook.path";
|
||||||
|
|
||||||
@Lazy
|
@Lazy
|
||||||
@Autowired
|
@Autowired
|
||||||
@@ -78,20 +80,16 @@ public class CompanyCustomerService extends CompanyBasicService implements ViewM
|
|||||||
return companyCustomerRepository.findById(id).orElse(null);
|
return companyCustomerRepository.findById(id).orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Caching(
|
@Caching(evict = {
|
||||||
evict = {
|
|
||||||
@CacheEvict(key = "#p0.id")
|
@CacheEvict(key = "#p0.id")
|
||||||
}
|
})
|
||||||
)
|
|
||||||
public CompanyCustomer save(CompanyCustomer companyCustomer) {
|
public CompanyCustomer save(CompanyCustomer companyCustomer) {
|
||||||
return companyCustomerRepository.save(companyCustomer);
|
return companyCustomerRepository.save(companyCustomer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Caching(
|
@Caching(evict = {
|
||||||
evict = {
|
|
||||||
@CacheEvict(key = "#p0")
|
@CacheEvict(key = "#p0")
|
||||||
}
|
})
|
||||||
)
|
|
||||||
@Override
|
@Override
|
||||||
public void delete(CompanyCustomer entity) {
|
public void delete(CompanyCustomer entity) {
|
||||||
companyCustomerRepository.delete(entity);
|
companyCustomerRepository.delete(entity);
|
||||||
@@ -182,9 +180,9 @@ public class CompanyCustomerService extends CompanyBasicService implements ViewM
|
|||||||
return modified;
|
return modified;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected <T, F extends CompanyBasicFile<T>> boolean fillFileAsDefaultType(F dbFile, File file, Consumer<String> status) {
|
protected <T, F extends CompanyBasicFile<T>> boolean fillFileAsDefaultType(F dbFile, File file,
|
||||||
|
Consumer<String> status) {
|
||||||
dbFile.setType((T) CompanyCustomerFileType.General);
|
dbFile.setType((T) CompanyCustomerFileType.General);
|
||||||
fillFile(dbFile, file, null, status);
|
fillFile(dbFile, file, null, status);
|
||||||
companyCustomerFileService.save((CompanyCustomerFile) dbFile);
|
companyCustomerFileService.save((CompanyCustomerFile) dbFile);
|
||||||
@@ -192,7 +190,8 @@ public class CompanyCustomerService extends CompanyBasicService implements ViewM
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected <T, F extends CompanyBasicFile<T>> boolean fillFileAsEvaluationFile(F customerFile, File file, List<File> fileList, Consumer<String> status) {
|
protected <T, F extends CompanyBasicFile<T>> boolean fillFileAsEvaluationFile(F customerFile, File file,
|
||||||
|
List<File> fileList, Consumer<String> status) {
|
||||||
boolean modified = super.fillFileAsEvaluationFile(customerFile, file, fileList, status);
|
boolean modified = super.fillFileAsEvaluationFile(customerFile, file, fileList, status);
|
||||||
|
|
||||||
if (fileList != null) {
|
if (fileList != null) {
|
||||||
@@ -225,7 +224,8 @@ public class CompanyCustomerService extends CompanyBasicService implements ViewM
|
|||||||
return modified;
|
return modified;
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T, F extends CompanyBasicFile<T>> void updateEvaluationFileByJsonFile(F customerFile, File jsonFile, Consumer<String> status) throws IOException {
|
private <T, F extends CompanyBasicFile<T>> void updateEvaluationFileByJsonFile(F customerFile, File jsonFile,
|
||||||
|
Consumer<String> status) throws IOException {
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
JsonNode root = objectMapper.readTree(jsonFile);
|
JsonNode root = objectMapper.readTree(jsonFile);
|
||||||
if (!root.isObject()) {
|
if (!root.isObject()) {
|
||||||
@@ -237,7 +237,8 @@ public class CompanyCustomerService extends CompanyBasicService implements ViewM
|
|||||||
data.remove("valid");
|
data.remove("valid");
|
||||||
JsonNode type = data.remove("type");
|
JsonNode type = data.remove("type");
|
||||||
|
|
||||||
CompanyCustomerEvaluationFormFile formFile = companyCustomerFileService.findCustomerEvaluationFormFileByCustomerFile((CompanyCustomerFile) customerFile);
|
CompanyCustomerEvaluationFormFile formFile = companyCustomerFileService
|
||||||
|
.findCustomerEvaluationFormFileByCustomerFile((CompanyCustomerFile) customerFile);
|
||||||
objectMapper.updateValue(formFile, data);
|
objectMapper.updateValue(formFile, data);
|
||||||
logger.info("load json data from {}", jsonFile.getName());
|
logger.info("load json data from {}", jsonFile.getName());
|
||||||
formFile.setCatalog(type.asText());
|
formFile.setCatalog(type.asText());
|
||||||
@@ -249,7 +250,8 @@ public class CompanyCustomerService extends CompanyBasicService implements ViewM
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected <T, F extends CompanyBasicFile<T>> F fillFileType(File file, List<File> fileList, Consumer<String> status) {
|
protected <T, F extends CompanyBasicFile<T>> F fillFileType(File file, List<File> fileList,
|
||||||
|
Consumer<String> status) {
|
||||||
CompanyCustomerFile customerFile = new CompanyCustomerFile();
|
CompanyCustomerFile customerFile = new CompanyCustomerFile();
|
||||||
customerFile.setType(CompanyCustomerFileType.General);
|
customerFile.setType(CompanyCustomerFileType.General);
|
||||||
if (fillFile(customerFile, file, fileList, status)) {
|
if (fillFile(customerFile, file, fileList, status)) {
|
||||||
@@ -271,7 +273,8 @@ public class CompanyCustomerService extends CompanyBasicService implements ViewM
|
|||||||
protected boolean isEvaluationFile(String fileName) {
|
protected boolean isEvaluationFile(String fileName) {
|
||||||
return (fileName.contains(EVALUATION_FORM_NAME1)
|
return (fileName.contains(EVALUATION_FORM_NAME1)
|
||||||
|| fileName.contains(EVALUATION_FORM_NAME2))
|
|| fileName.contains(EVALUATION_FORM_NAME2))
|
||||||
&& (CompanyFileUtils.withExtensions(fileName, CompanyFileUtils.JPG, CompanyFileUtils.JPEG, CompanyFileUtils.PDF));
|
&& (CompanyFileUtils.withExtensions(fileName, CompanyFileUtils.JPG, CompanyFileUtils.JPEG,
|
||||||
|
CompanyFileUtils.PDF));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean makePathAbsent(CompanyCustomer companyCustomer) {
|
public boolean makePathAbsent(CompanyCustomer companyCustomer) {
|
||||||
@@ -302,7 +305,8 @@ public class CompanyCustomerService extends CompanyBasicService implements ViewM
|
|||||||
}
|
}
|
||||||
|
|
||||||
String companyName = company.getName();
|
String companyName = company.getName();
|
||||||
String fileName = formatCompanyVendorId(companyCustomer.getId()) + "-" + CompanyFileUtils.escapeFileName(companyName);
|
String fileName = formatCompanyVendorId(companyCustomer.getId()) + "-"
|
||||||
|
+ CompanyFileUtils.escapeFileName(companyName);
|
||||||
|
|
||||||
File dir = new File(basePath, fileName);
|
File dir = new File(basePath, fileName);
|
||||||
if (!dir.exists()) {
|
if (!dir.exists()) {
|
||||||
@@ -313,7 +317,6 @@ public class CompanyCustomerService extends CompanyBasicService implements ViewM
|
|||||||
return dir;
|
return dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Page<CompanyCustomer> findAll(Specification<CompanyCustomer> spec, Pageable pageable) {
|
public Page<CompanyCustomer> findAll(Specification<CompanyCustomer> spec, Pageable pageable) {
|
||||||
return companyCustomerRepository.findAll(spec, pageable);
|
return companyCustomerRepository.findAll(spec, pageable);
|
||||||
}
|
}
|
||||||
@@ -347,6 +350,7 @@ public class CompanyCustomerService extends CompanyBasicService implements ViewM
|
|||||||
|
|
||||||
/***
|
/***
|
||||||
* 合并两个CompanyCustomer对象,并将fromCustomer的信息合并到toCustomer中,并保存到数据库中。
|
* 合并两个CompanyCustomer对象,并将fromCustomer的信息合并到toCustomer中,并保存到数据库中。
|
||||||
|
*
|
||||||
* @param from 源客户对象
|
* @param from 源客户对象
|
||||||
* @param to 目标客户对象
|
* @param to 目标客户对象
|
||||||
*/
|
*/
|
||||||
@@ -359,7 +363,6 @@ public class CompanyCustomerService extends CompanyBasicService implements ViewM
|
|||||||
companyCustomerRepository.delete(from);
|
companyCustomerRepository.delete(from);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除 company 的 客户
|
* 删除 company 的 客户
|
||||||
*/
|
*/
|
||||||
@@ -386,12 +389,10 @@ public class CompanyCustomerService extends CompanyBasicService implements ViewM
|
|||||||
return customerCatalogRepository.findByCode(code).orElse(null);
|
return customerCatalogRepository.findByCode(code).orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Caching(
|
@Caching(evict = {
|
||||||
evict = {
|
|
||||||
@CacheEvict(key = "'catalog-'+#p0.id"),
|
@CacheEvict(key = "'catalog-'+#p0.id"),
|
||||||
@CacheEvict(key = "'catalog-code-'+#p0.code")
|
@CacheEvict(key = "'catalog-code-'+#p0.code")
|
||||||
}
|
})
|
||||||
)
|
|
||||||
public CustomerCatalog save(CustomerCatalog catalog) {
|
public CustomerCatalog save(CustomerCatalog catalog) {
|
||||||
return customerCatalogRepository.save(catalog);
|
return customerCatalogRepository.save(catalog);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -116,6 +116,10 @@ public abstract class AbstractConfigBounder<T> implements ConfigBounder {
|
|||||||
T newValue) {
|
T newValue) {
|
||||||
conf.setValue(getConverter().toString(newValue));
|
conf.setValue(getConverter().toString(newValue));
|
||||||
conf.setModified(LocalDateTime.now());
|
conf.setModified(LocalDateTime.now());
|
||||||
|
save();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void save() {
|
||||||
SysConf saved = getConfService().save(conf);
|
SysConf saved = getConfService().save(conf);
|
||||||
modified.set(saved.getModified());
|
modified.set(saved.getModified());
|
||||||
created.set(saved.getCreated());
|
created.set(saved.getCreated());
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package com.ecep.contract.manager.ds.other;
|
package com.ecep.contract.manager.ds.other;
|
||||||
|
|
||||||
import javafx.beans.property.Property;
|
import javafx.beans.property.Property;
|
||||||
|
import javafx.scene.control.Control;
|
||||||
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.control.TextField;
|
import javafx.scene.control.TextField;
|
||||||
import javafx.util.StringConverter;
|
import javafx.util.StringConverter;
|
||||||
|
|
||||||
@@ -10,10 +12,10 @@ public class StringConfig extends AbstractConfigBounder<String> {
|
|||||||
super(string);
|
super(string);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
// @Override
|
||||||
public TextField getControl() {
|
// public TextField getControl() {
|
||||||
return (TextField) super.getControl();
|
// return (TextField) super.getControl();
|
||||||
}
|
// }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StringConverter<String> getConverter() {
|
public StringConverter<String> getConverter() {
|
||||||
@@ -37,6 +39,14 @@ public class StringConfig extends AbstractConfigBounder<String> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
void bindBidirectional(Property<String> property) {
|
void bindBidirectional(Property<String> property) {
|
||||||
getControl().textProperty().bindBidirectional(property);
|
Control ctrl = getControl();
|
||||||
|
if (ctrl == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (ctrl instanceof TextField textField) {
|
||||||
|
textField.textProperty().bindBidirectional(property);
|
||||||
|
} else if (ctrl instanceof Label label) {
|
||||||
|
label.textProperty().bindBidirectional(property);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,21 @@
|
|||||||
package com.ecep.contract.manager.ds.other.controller;
|
package com.ecep.contract.manager.ds.other.controller;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.context.annotation.Lazy;
|
||||||
|
import org.springframework.context.annotation.Scope;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import com.ecep.contract.manager.cloud.u8.YongYouU8Service;
|
||||||
|
import com.ecep.contract.manager.ds.contract.service.ContractService;
|
||||||
import com.ecep.contract.manager.ds.customer.service.CompanyCustomerFileService;
|
import com.ecep.contract.manager.ds.customer.service.CompanyCustomerFileService;
|
||||||
import com.ecep.contract.manager.ds.customer.service.CompanyCustomerService;
|
import com.ecep.contract.manager.ds.customer.service.CompanyCustomerService;
|
||||||
|
import com.ecep.contract.manager.ds.other.StringConfig;
|
||||||
import com.ecep.contract.manager.ds.vendor.service.CompanyVendorService;
|
import com.ecep.contract.manager.ds.vendor.service.CompanyVendorService;
|
||||||
import com.ecep.contract.manager.ds.contract.service.ContractService;
|
|
||||||
import com.ecep.contract.manager.ds.other.repository.SysConfRepository;
|
|
||||||
import com.ecep.contract.manager.ui.BaseController;
|
import com.ecep.contract.manager.ui.BaseController;
|
||||||
|
|
||||||
import jakarta.annotation.PreDestroy;
|
import jakarta.annotation.PreDestroy;
|
||||||
import javafx.beans.property.SimpleStringProperty;
|
import javafx.beans.property.SimpleStringProperty;
|
||||||
import javafx.event.ActionEvent;
|
import javafx.event.ActionEvent;
|
||||||
@@ -14,14 +24,7 @@ import javafx.scene.control.Label;
|
|||||||
import javafx.scene.control.TextField;
|
import javafx.scene.control.TextField;
|
||||||
import javafx.stage.DirectoryChooser;
|
import javafx.stage.DirectoryChooser;
|
||||||
import javafx.stage.FileChooser;
|
import javafx.stage.FileChooser;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.context.annotation.Lazy;
|
|
||||||
import org.springframework.context.annotation.Scope;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
@Lazy
|
@Lazy
|
||||||
@Scope("prototype")
|
@Scope("prototype")
|
||||||
@Component
|
@Component
|
||||||
@@ -42,90 +45,76 @@ public class SysConfWindowController extends BaseController {
|
|||||||
public Label customerEvaluationFormTemplateLabel;
|
public Label customerEvaluationFormTemplateLabel;
|
||||||
public Label customerSaleBookPathLabel;
|
public Label customerSaleBookPathLabel;
|
||||||
|
|
||||||
|
StringConfig contractPathConfig = new StringConfig(ContractService.CONTRACT_BASE_PATH);
|
||||||
|
StringConfig vendorPathConfig = new StringConfig(CompanyVendorService.KEY_BASE_PATH);
|
||||||
|
StringConfig vendorEvaluationFormTemplateConfig = new StringConfig(
|
||||||
|
CompanyVendorService.KEY_EVALUATION_FORM_TEMPLATE);
|
||||||
|
StringConfig customerPathConfig = new StringConfig(CompanyCustomerService.KEY_BASE_PATH);
|
||||||
|
StringConfig customerEvaluationFormTemplateConfig = new StringConfig(
|
||||||
|
CompanyCustomerFileService.KEY_EVALUATION_FORM_TEMPLATE);
|
||||||
|
StringConfig customerSaleBookPathConfig = new StringConfig(CompanyCustomerService.KEY_SALEBOOK_PATH);
|
||||||
|
|
||||||
@Autowired
|
StringConfig u8DataBaseServerHostConfig = new StringConfig(YongYouU8Service.KEY_HOST_IP);
|
||||||
private SysConfRepository confRepository;
|
StringConfig u8DataBaseCatalogConfig = new StringConfig(YongYouU8Service.KEY_DATABASE);
|
||||||
|
StringConfig u8DataBaseUserNameConfig = new StringConfig(YongYouU8Service.KEY_USER_NAME);
|
||||||
private final SimpleStringProperty companyContractPath = new SimpleStringProperty();
|
StringConfig u8DataBasePasswordConfig = new StringConfig(YongYouU8Service.KEY_PASSWORD);
|
||||||
|
|
||||||
private final SimpleStringProperty u8DataBaseServerHost = new SimpleStringProperty();
|
|
||||||
private final SimpleStringProperty u8DataBaseCatalog = new SimpleStringProperty();
|
|
||||||
private final SimpleStringProperty u8DataBaseUserName = new SimpleStringProperty();
|
|
||||||
private final SimpleStringProperty u8DataBasePassword = new SimpleStringProperty();
|
|
||||||
|
|
||||||
|
|
||||||
private final SimpleStringProperty vendorPath = new SimpleStringProperty();
|
|
||||||
private final SimpleStringProperty vendorEvaluationFormTemplate = new SimpleStringProperty();
|
|
||||||
|
|
||||||
private final SimpleStringProperty customerPath = new SimpleStringProperty();
|
|
||||||
private final SimpleStringProperty customerEvaluationFormTemplate = new SimpleStringProperty();
|
|
||||||
private final SimpleStringProperty customerSaleBookPath = new SimpleStringProperty();
|
|
||||||
|
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
|
contractPathConfig.setControl(companyContractPathLabel);
|
||||||
|
contractPathConfig.initialize();
|
||||||
|
|
||||||
initializeDirectory(companyContractPathLabel, companyContractPath, ContractService.CONTRACT_BASE_PATH);
|
vendorPathConfig.setControl(vendorPathLabel);
|
||||||
|
vendorPathConfig.initialize();
|
||||||
|
vendorEvaluationFormTemplateConfig.setControl(vendorEvaluationFormTemplateLabel);
|
||||||
|
vendorEvaluationFormTemplateConfig.initialize();
|
||||||
|
|
||||||
initializeDirectory(vendorPathLabel, vendorPath, CompanyVendorService.KEY_BASE_PATH);
|
customerPathConfig.setControl(customerPathLabel);
|
||||||
initializeFile(vendorEvaluationFormTemplateLabel, vendorEvaluationFormTemplate, CompanyVendorService.KEY_EVALUATION_FORM_TEMPLATE);
|
customerPathConfig.initialize();
|
||||||
|
customerEvaluationFormTemplateConfig.setControl(customerEvaluationFormTemplateLabel);
|
||||||
|
customerEvaluationFormTemplateConfig.initialize();
|
||||||
|
customerSaleBookPathConfig.setControl(customerSaleBookPathLabel);
|
||||||
|
customerSaleBookPathConfig.initialize();
|
||||||
|
|
||||||
initializeDirectory(customerPathLabel, customerPath, CompanyCustomerService.KEY_BASE_PATH);
|
u8DataBaseServerHostConfig.setControl(u8DataBaseServerHostField);
|
||||||
initializeFile(customerEvaluationFormTemplateLabel, customerEvaluationFormTemplate, CompanyCustomerFileService.KEY_EVALUATION_FORM_TEMPLATE);
|
u8DataBaseServerHostConfig.initialize();
|
||||||
initializeDirectory(customerSaleBookPathLabel, customerSaleBookPath, "customer.salebook.path");
|
u8DataBaseCatalogConfig.setControl(u8DataBaseCatalogField);
|
||||||
|
u8DataBaseCatalogConfig.initialize();
|
||||||
initializeField(u8DataBaseServerHostField, u8DataBaseServerHost, "u8.db.server.ip");
|
u8DataBaseUserNameConfig.setControl(u8DataBaseUserNameField);
|
||||||
initializeField(u8DataBaseCatalogField, u8DataBaseCatalog, "u8.db.database");
|
u8DataBaseUserNameConfig.initialize();
|
||||||
initializeField(u8DataBaseUserNameField, u8DataBaseUserName, "u8.db.server.name");
|
u8DataBasePasswordConfig.setControl(u8DataBasePasswordField);
|
||||||
initializeField(u8DataBasePasswordField, u8DataBasePassword, "u8.db.server.password");
|
u8DataBasePasswordConfig.initialize();
|
||||||
|
|
||||||
logger.debug("#initialize()");
|
logger.debug("#initialize()");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initializeFile(Label label, SimpleStringProperty property, String key) {
|
private void directoryChoose(StringConfig config, String title, String key, ActionEvent event) {
|
||||||
label.textProperty().bind(property);
|
|
||||||
property.set(confRepository.get(key, ""));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initializeDirectory(Label label, SimpleStringProperty property, String key) {
|
|
||||||
label.textProperty().bind(property);
|
|
||||||
property.set(confRepository.get(key, ""));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initializeField(TextField field, SimpleStringProperty property, String key) {
|
|
||||||
field.textProperty().bindBidirectional(property);
|
|
||||||
property.set(confRepository.get(key, ""));
|
|
||||||
property.addListener((observable, oldValue, newValue) -> {
|
|
||||||
confRepository.set(key, newValue);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void directoryChoose(SimpleStringProperty property, String title, String key, ActionEvent event) {
|
|
||||||
DirectoryChooser chooser = new DirectoryChooser();
|
DirectoryChooser chooser = new DirectoryChooser();
|
||||||
chooser.setTitle(title);
|
chooser.setTitle(title);
|
||||||
File value = new File(property.get());
|
File value = new File(config.getProperty().getValue());
|
||||||
chooser.setInitialDirectory(value);
|
chooser.setInitialDirectory(value);
|
||||||
|
|
||||||
Node node = (Node) event.getSource();
|
Node node = (Node) event.getSource();
|
||||||
File selected = chooser.showDialog(node.getScene().getWindow());
|
File selected = chooser.showDialog(node.getScene().getWindow());
|
||||||
if (selected != null) {
|
if (selected != null) {
|
||||||
property.set(selected.getAbsolutePath());
|
config.getProperty().setValue(selected.getAbsolutePath());
|
||||||
confRepository.set(key, property.get());
|
config.save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void changeCompanyContractPath(ActionEvent actionEvent) {
|
public void changeCompanyContractPath(ActionEvent actionEvent) {
|
||||||
directoryChoose(companyContractPath, "请选择合同目录", ContractService.CONTRACT_BASE_PATH, actionEvent);
|
directoryChoose(contractPathConfig, "请选择合同目录", ContractService.CONTRACT_BASE_PATH, actionEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void changeVendorPath(ActionEvent actionEvent) {
|
public void changeVendorPath(ActionEvent actionEvent) {
|
||||||
directoryChoose(vendorPath, "请选择供应商目录", CompanyVendorService.KEY_BASE_PATH, actionEvent);
|
directoryChoose(vendorPathConfig, "请选择供应商目录", CompanyVendorService.KEY_BASE_PATH, actionEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void changeCustomerPath(ActionEvent actionEvent) {
|
public void changeCustomerPath(ActionEvent actionEvent) {
|
||||||
directoryChoose(customerPath, "请选择客户目录", CompanyCustomerService.KEY_BASE_PATH, actionEvent);
|
directoryChoose(customerPathConfig, "请选择客户目录", CompanyCustomerService.KEY_BASE_PATH, actionEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void changeCustomerSaleBookPath(ActionEvent actionEvent) {
|
public void changeCustomerSaleBookPath(ActionEvent actionEvent) {
|
||||||
directoryChoose(customerSaleBookPath, "请选择销售台账目录", "customer.salebook.path", actionEvent);
|
directoryChoose(customerSaleBookPathConfig, "请选择销售台账目录", "customer.salebook.path", actionEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 模拟销毁方法
|
// 模拟销毁方法
|
||||||
@@ -134,28 +123,29 @@ public class SysConfWindowController extends BaseController {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fileChoose(SimpleStringProperty property, String title, String key, ActionEvent event) {
|
private void fileChoose(StringConfig config, String title, String key, ActionEvent event) {
|
||||||
FileChooser chooser = new FileChooser();
|
FileChooser chooser = new FileChooser();
|
||||||
chooser.setTitle(title);
|
chooser.setTitle(title);
|
||||||
File value = new File(property.get());
|
File value = new File(config.getProperty().getValue());
|
||||||
chooser.setInitialDirectory(value.getParentFile());
|
chooser.setInitialDirectory(value.getParentFile());
|
||||||
chooser.setInitialFileName(value.getName());
|
chooser.setInitialFileName(value.getName());
|
||||||
chooser.getExtensionFilters().add(new FileChooser.ExtensionFilter(" 模板文件(*.xlsx)", "*.xlsx"));
|
chooser.getExtensionFilters().add(new FileChooser.ExtensionFilter(" 模板文件(*.xlsx)", "*.xlsx"));
|
||||||
Node node = (Node) event.getSource();
|
Node node = (Node) event.getSource();
|
||||||
File selected = chooser.showOpenDialog(node.getScene().getWindow());
|
File selected = chooser.showOpenDialog(node.getScene().getWindow());
|
||||||
if (selected != null) {
|
if (selected != null) {
|
||||||
property.set(selected.getAbsolutePath());
|
config.getProperty().setValue(selected.getAbsolutePath());
|
||||||
confRepository.set(key, property.get());
|
config.save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void changeCustomerEvaluationFormTemplate(ActionEvent actionEvent) {
|
public void changeCustomerEvaluationFormTemplate(ActionEvent actionEvent) {
|
||||||
fileChoose(customerEvaluationFormTemplate, "请选择客户资信评估表模板", CompanyCustomerFileService.KEY_EVALUATION_FORM_TEMPLATE, actionEvent);
|
fileChoose(customerEvaluationFormTemplateConfig, "请选择客户资信评估表模板",
|
||||||
|
CompanyCustomerFileService.KEY_EVALUATION_FORM_TEMPLATE, actionEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void changeVendorEvaluationFormTemplate(ActionEvent actionEvent) {
|
public void changeVendorEvaluationFormTemplate(ActionEvent actionEvent) {
|
||||||
fileChoose(vendorEvaluationFormTemplate, "请选择供方调查评价表模板", CompanyVendorService.KEY_EVALUATION_FORM_TEMPLATE, actionEvent);
|
fileChoose(vendorEvaluationFormTemplateConfig, "请选择供方调查评价表模板",
|
||||||
|
CompanyVendorService.KEY_EVALUATION_FORM_TEMPLATE,
|
||||||
|
actionEvent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,85 +1,11 @@
|
|||||||
package com.ecep.contract.manager.ds.other.repository;
|
package com.ecep.contract.manager.ds.other.repository;
|
||||||
|
|
||||||
import com.ecep.contract.manager.ds.other.model.SysConf;
|
|
||||||
import org.springframework.data.repository.CrudRepository;
|
|
||||||
import org.springframework.data.repository.PagingAndSortingRepository;
|
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
import java.time.Instant;
|
import com.ecep.contract.manager.ds.MyRepository;
|
||||||
import java.util.Optional;
|
import com.ecep.contract.manager.ds.other.model.SysConf;
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface SysConfRepository extends CrudRepository<SysConf, String>, PagingAndSortingRepository<SysConf, String> {
|
public interface SysConfRepository extends MyRepository<SysConf, String> {
|
||||||
default String get(String key) {
|
|
||||||
return get(key, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 读取配置值
|
|
||||||
*
|
|
||||||
* @param key 配置项
|
|
||||||
* @param defaultValue 没有配置时的默认值
|
|
||||||
* @return 配置值
|
|
||||||
*/
|
|
||||||
default String get(String key, String defaultValue) {
|
|
||||||
Optional<SysConf> optional = findById(key);
|
|
||||||
if (optional.isPresent()) {
|
|
||||||
return optional.get().getValue();
|
|
||||||
} else {
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
default long get(String key, long defaultValue) {
|
|
||||||
Optional<SysConf> optional = findById(key);
|
|
||||||
return optional.map(sysConf -> Long.parseLong(sysConf.getValue())).orElse(defaultValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
default int get(String key, int defaultValue) {
|
|
||||||
Optional<SysConf> optional = findById(key);
|
|
||||||
return optional.map(sysConf -> Integer.parseInt(sysConf.getValue())).orElse(defaultValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
default boolean get(String key, boolean defaultValue) {
|
|
||||||
Optional<SysConf> optional = findById(key);
|
|
||||||
return optional.map(sysConf -> {
|
|
||||||
String value = sysConf.getValue();
|
|
||||||
if (Boolean.parseBoolean(value)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return "1".equalsIgnoreCase(value);
|
|
||||||
}).orElse(defaultValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 保存配置值
|
|
||||||
*
|
|
||||||
* @param key 配置项
|
|
||||||
* @param value 配置值
|
|
||||||
* @return 配置值对象
|
|
||||||
*/
|
|
||||||
default SysConf set(String key, String value) {
|
|
||||||
SysConf conf;
|
|
||||||
Optional<SysConf> optional = findById(key);
|
|
||||||
if (optional.isPresent()) {
|
|
||||||
conf = optional.get();
|
|
||||||
} else {
|
|
||||||
conf = new SysConf();
|
|
||||||
conf.setId(key);
|
|
||||||
conf.setCreated(Instant.now());
|
|
||||||
}
|
|
||||||
conf.setValue(value);
|
|
||||||
conf.setModified(Instant.now());
|
|
||||||
save(conf);
|
|
||||||
return conf;
|
|
||||||
}
|
|
||||||
|
|
||||||
default CompletableFuture<Optional<SysConf>> value(String key) {
|
|
||||||
return CompletableFuture.supplyAsync(() -> findById(key));
|
|
||||||
}
|
|
||||||
|
|
||||||
default CompletableFuture<SysConf> value(String key, String value) {
|
|
||||||
return CompletableFuture.supplyAsync(() -> set(key, value));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.ecep.contract.manager.ds.other.service;
|
package com.ecep.contract.manager.ds.other.service;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.cache.annotation.CacheConfig;
|
import org.springframework.cache.annotation.CacheConfig;
|
||||||
@@ -35,10 +35,10 @@ public class SysConfService {
|
|||||||
if (conf == null) {
|
if (conf == null) {
|
||||||
conf = new SysConf();
|
conf = new SysConf();
|
||||||
conf.setId(key);
|
conf.setId(key);
|
||||||
conf.setCreated(Instant.now());
|
conf.setCreated(LocalDateTime.now());
|
||||||
}
|
}
|
||||||
conf.setValue(value);
|
conf.setValue(value);
|
||||||
conf.setModified(Instant.now());
|
conf.setModified(LocalDateTime.now());
|
||||||
repository.save(conf);
|
repository.save(conf);
|
||||||
return conf;
|
return conf;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user