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

@@ -3,16 +3,16 @@ package com.ecep.contract.controller.bank;
import com.ecep.contract.controller.AbstEntityManagerSkin;
import com.ecep.contract.controller.ManagerSkin;
import com.ecep.contract.controller.table.EditableEntityTableTabSkin;
import com.ecep.contract.model.Bank;
import com.ecep.contract.vm.BankViewModel;
import com.ecep.contract.vo.BankVo;
import javafx.scene.control.TableColumn;
import javafx.scene.control.cell.TextFieldTableCell;
public class BankManagerSkin
extends AbstEntityManagerSkin<Bank, BankViewModel, BankManagerSkin, BankManagerWindowController>
implements ManagerSkin, EditableEntityTableTabSkin<Bank, BankViewModel> {
extends AbstEntityManagerSkin<BankVo, BankViewModel, BankManagerSkin, BankManagerWindowController>
implements ManagerSkin, EditableEntityTableTabSkin<BankVo, BankViewModel> {
public BankManagerSkin(BankManagerWindowController controller) {
super(controller);

View File

@@ -6,10 +6,10 @@ import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import com.ecep.contract.controller.AbstManagerWindowController;
import com.ecep.contract.model.Bank;
import com.ecep.contract.service.BankService;
import com.ecep.contract.util.FxmlPath;
import com.ecep.contract.vm.BankViewModel;
import com.ecep.contract.vo.BankVo;
import javafx.event.ActionEvent;
import javafx.scene.control.TableColumn;
@@ -19,7 +19,7 @@ import javafx.scene.control.TableColumn;
@Component
@FxmlPath("/ui/bank-manager.fxml")
public class BankManagerWindowController
extends AbstManagerWindowController<Bank, BankViewModel, BankManagerSkin> {
extends AbstManagerWindowController<BankVo, BankViewModel, BankManagerSkin> {
@Autowired
private BankService bankService;

View File

@@ -1,29 +1,20 @@
package com.ecep.contract.controller.bank.account;
import com.ecep.contract.SpringApp;
import com.ecep.contract.controller.company.CompanyWindowController;
import com.ecep.contract.controller.tab.AbstEntityBasedTabSkin;
import com.ecep.contract.controller.tab.TabSkin;
import com.ecep.contract.converter.BankStringConverter;
import com.ecep.contract.converter.CompanyStringConverter;
import com.ecep.contract.model.Company;
import com.ecep.contract.model.CompanyBankAccount;
import com.ecep.contract.service.BankService;
import com.ecep.contract.service.CompanyService;
import com.ecep.contract.util.UITools;
import com.ecep.contract.vm.CompanyBankAccountViewModel;
import com.ecep.contract.vo.CompanyBankAccountVo;
import com.ecep.contract.vo.CompanyVo;
import javafx.scene.control.Tab;
import javafx.scene.control.TextField;
import lombok.Setter;
public class BankAccountBaseTabSkin
extends AbstEntityBasedTabSkin<BankAccountWindowController, CompanyBankAccount, CompanyBankAccountViewModel>
extends AbstEntityBasedTabSkin<BankAccountWindowController, CompanyBankAccountVo, CompanyBankAccountViewModel>
implements TabSkin {
@Setter
private CompanyService companyService;
@Setter
private BankService bankService;
public BankAccountBaseTabSkin(BankAccountWindowController controller) {
super(controller);
@@ -37,8 +28,9 @@ public class BankAccountBaseTabSkin
@Override
public void initializeTab() {
initializeBaseTabCompanyFieldAutoCompletion(controller.companyField);
initializeBaseTabBankFieldAutoCompletion(controller.bankField);
UITools.autoCompletion(controller.companyField, viewModel.getCompanyId(), getCompanyService());
UITools.autoCompletion(controller.bankField, viewModel.getBankId(), getBankService());
controller.openingBankField.textProperty().bindBidirectional(viewModel.getOpeningBank());
controller.bankAccountField.textProperty().bindBidirectional(viewModel.getAccount());
@@ -47,36 +39,21 @@ public class BankAccountBaseTabSkin
controller.createdField.textProperty().bind(viewModel.getCreated().asString());
controller.versionLabel.textProperty().bind(viewModel.getVersion().asString());
controller.relativeCompanyBtn.disableProperty().bind(viewModel.getCompany().isNull());
controller.relativeCompanyBtn.disableProperty().bind(viewModel.getCompanyId().isNull());
controller.relativeCompanyBtn.setOnAction(event -> {
Company company = viewModel.getCompany().get();
if (company != null) {
Integer companyId = viewModel.getCompanyId().get();
if (companyId != null) {
CompanyVo company = getCompanyService().findById(companyId);
CompanyWindowController.show(company, controller.root.getScene().getWindow());
}
});
}
private void initializeBaseTabCompanyFieldAutoCompletion(TextField textField) {
CompanyStringConverter converter = SpringApp.getBean(CompanyStringConverter.class);
UITools.autoCompletion(textField, viewModel.getCompany(), converter::suggest, converter);
}
private void initializeBaseTabBankFieldAutoCompletion(TextField textField) {
BankStringConverter converter = SpringApp.getBean(BankStringConverter.class);
UITools.autoCompletion(textField, viewModel.getBank(), converter::suggest, converter);
}
public BankService getBankService() {
if (bankService == null) {
bankService = getBean(BankService.class);
}
return bankService;
return getCachedBean(BankService.class);
}
public CompanyService getCompanyService() {
if (companyService == null) {
companyService = getBean(CompanyService.class);
}
return companyService;
return getCachedBean(CompanyService.class);
}
}

View File

@@ -10,6 +10,7 @@ import com.ecep.contract.model.CompanyBankAccount;
import com.ecep.contract.service.CompanyBankAccountService;
import com.ecep.contract.util.FxmlPath;
import com.ecep.contract.vm.CompanyBankAccountViewModel;
import com.ecep.contract.vo.CompanyBankAccountVo;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
@@ -25,7 +26,7 @@ import javafx.stage.WindowEvent;
@Scope("prototype")
@Component
@FxmlPath("/ui/company/bank-account.fxml")
public class BankAccountWindowController extends AbstEntityController<CompanyBankAccount, CompanyBankAccountViewModel> {
public class BankAccountWindowController extends AbstEntityController<CompanyBankAccountVo, CompanyBankAccountViewModel> {
public BorderPane root;
public TabPane tabPane;

View File

@@ -1,21 +1,21 @@
package com.ecep.contract.controller.company;
import java.util.HashMap;
import java.util.Map;
import com.ecep.contract.controller.tab.TabSkin;
import com.ecep.contract.controller.table.AbstEntityTableTabSkin;
import com.ecep.contract.controller.table.TableOfTabSkin;
import com.ecep.contract.model.Company;
import com.ecep.contract.model.IdentityEntity;
import com.ecep.contract.service.CompanyService;
import com.ecep.contract.util.ParamUtils;
import com.ecep.contract.vm.CompanyBasedViewModel;
import com.ecep.contract.vm.CompanyViewModel;
import com.ecep.contract.vm.IdentityViewModel;
import com.ecep.contract.vo.CompanyVo;
public abstract class AbstCompanyTableTabSkin<T extends IdentityEntity, TV extends IdentityViewModel<T>>
extends AbstEntityTableTabSkin<CompanyWindowController, Company, CompanyViewModel, T, TV>
implements TabSkin, TableOfTabSkin<Company, T, TV> {
extends AbstEntityTableTabSkin<CompanyWindowController, CompanyVo, CompanyViewModel, T, TV>
implements TabSkin, TableOfTabSkin<CompanyVo, T, TV> {
public AbstCompanyTableTabSkin(CompanyWindowController controller) {
super(controller);
@@ -26,7 +26,7 @@ public abstract class AbstCompanyTableTabSkin<T extends IdentityEntity, TV exten
protected TV createNewViewModel() {
TV model = super.createNewViewModel();
if (model instanceof CompanyBasedViewModel m) {
m.getCompany().set(getEntity());
m.getCompanyId().set(getEntity().getId());
}
return model;
}
@@ -40,13 +40,8 @@ public abstract class AbstCompanyTableTabSkin<T extends IdentityEntity, TV exten
}
@Override
public Map<String, Object> getSpecification(Company parent) {
Map<String, Object> params = getSpecification();
if (params == null) {
params = new HashMap<>();
}
params.put("company", parent.getId());
return params;
public Map<String, Object> getSpecification(CompanyVo parent) {
return ParamUtils.equal("company", parent.getId());
}
}

View File

@@ -39,6 +39,7 @@ import com.ecep.contract.util.FxmlPath;
import com.ecep.contract.util.ProxyUtils;
import com.ecep.contract.util.UITools;
import com.ecep.contract.vm.CompanyViewModel;
import com.ecep.contract.vo.CompanyVo;
import javafx.beans.property.SimpleObjectProperty;
import javafx.event.ActionEvent;
@@ -61,16 +62,11 @@ import javafx.stage.Window;
@Component
@FxmlPath("/ui/company/company.fxml")
public class CompanyWindowController
extends AbstEntityController<Company, CompanyViewModel> {
extends AbstEntityController<CompanyVo, CompanyViewModel> {
private static final Logger logger = LoggerFactory.getLogger(CompanyWindowController.class);
public static void show(Company company, Window window) {
CompanyViewModel viewModel = new CompanyViewModel();
if (!ProxyUtils.isInitialized(company)) {
company = SpringApp.getBean(CompanyService.class).findById(company.getId());
}
viewModel.update(company);
show(viewModel, window);
public static void show(CompanyVo company, Window window) {
show(CompanyViewModel.from(company), window);
}
/**
@@ -269,7 +265,7 @@ public class CompanyWindowController
* 企业合规检查
*/
public void onCompanyVerifyAction(ActionEvent event) {
Company company = getEntity();
CompanyVo company = getEntity();
CompanyVerifyTasker task = new CompanyVerifyTasker();
task.setCompanyService(companyService);
task.setCompany(company);
@@ -277,7 +273,7 @@ public class CompanyWindowController
}
public void onCompanyOpenInExplorerAction(ActionEvent event) {
Company company = getEntity();
CompanyVo company = getEntity();
String path = company.getPath();
CompletableFuture.runAsync(() -> {

View File

@@ -3,9 +3,7 @@ package com.ecep.contract.controller.project;
import java.util.List;
import java.util.function.BiFunction;
import com.ecep.contract.service.*;
import org.controlsfx.control.textfield.AutoCompletionBinding;
import com.ecep.contract.util.ProxyUtils;
import org.springframework.util.StringUtils;
import com.ecep.contract.SpringApp;
@@ -13,13 +11,20 @@ import com.ecep.contract.controller.company.CompanyWindowController;
import com.ecep.contract.controller.tab.TabSkin;
import com.ecep.contract.converter.CompanyStringConverter;
import com.ecep.contract.converter.EntityStringConverter;
import com.ecep.contract.model.Bank;
import com.ecep.contract.model.Company;
import com.ecep.contract.model.CompanyBankAccount;
import com.ecep.contract.model.CompanyContact;
import com.ecep.contract.model.CompanyInvoiceInfo;
import com.ecep.contract.service.BankService;
import com.ecep.contract.service.CompanyBankAccountService;
import com.ecep.contract.service.CompanyContactService;
import com.ecep.contract.service.CompanyInvoiceInfoService;
import com.ecep.contract.service.CompanyService;
import com.ecep.contract.util.FxmlPath;
import com.ecep.contract.util.ProxyUtils;
import com.ecep.contract.util.UITools;
import com.ecep.contract.vo.BankVo;
import com.ecep.contract.vo.CompanyVo;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.StringProperty;
@@ -103,7 +108,7 @@ public class ProjectTabSkinCustomerInfo
});
companyDetailBtn.setOnAction(event -> {
Company company = viewModel.getCustomer().get();
CompanyVo company = viewModel.getCustomer().get();
if (company == null) {
return;
}
@@ -204,7 +209,7 @@ public class ProjectTabSkinCustomerInfo
}
StringBuilder sb = new StringBuilder();
sb.append("开户行:");
Bank bank = account.getBank();
BankVo bank = account.getBank();
if (bank != null) {
if (!ProxyUtils.isInitialized(bank)) {
bank = getBankService().findById(bank.getId());

View File

@@ -4,18 +4,20 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import com.ecep.contract.model.Bank;
import com.ecep.contract.service.BankService;
import com.ecep.contract.vo.BankVo;
import jakarta.annotation.PostConstruct;
@Lazy
@Component
public class BankStringConverter extends EntityStringConverter<Bank> {
@Deprecated
public class BankStringConverter extends EntityStringConverter<BankVo> {
@Lazy
@Autowired
BankService service;
public BankStringConverter() {
}

View File

@@ -1,16 +1,63 @@
package com.ecep.contract.service;
import java.util.List;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.Caching;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import com.ecep.contract.model.Bank;
import com.ecep.contract.util.ParamUtils;
import com.ecep.contract.vm.BankViewModel;
import com.ecep.contract.vo.BankVo;
import javafx.util.StringConverter;
@Service
public class BankService extends QueryService<Bank, BankViewModel> {
public Bank findByName(String name) {
return null;
@CacheConfig(cacheNames = "bank")
public class BankService extends QueryService<BankVo, BankViewModel> {
@Cacheable(key = "#p0")
@Override
public BankVo findById(Integer id) {
return super.findById(id);
}
public BankVo findByName(String name) {
Page<BankVo> page = findAll(ParamUtils.equal(name, name), Pageable.ofSize(1));
if (page.isEmpty()) {
return null;
}
return page.getContent().getFirst();
}
@Caching(evict = { @CacheEvict(key = "#p0.id") })
@Override
public BankVo save(BankVo entity) {
return super.save(entity);
}
@Caching(evict = { @CacheEvict(key = "#p0.id") })
@Override
public void delete(BankVo entity) {
super.delete(entity);
}
private StringConverter<BankVo> stringConverter = new StringConverter<BankVo>() {
@Override
public String toString(BankVo object) {
return object == null ? "" : object.getName();
}
@Override
public BankVo fromString(String string) {
return findByName(string);
}
};
@Override
public StringConverter<BankVo> getStringConverter() {
return stringConverter;
}
}

View File

@@ -5,13 +5,13 @@ import java.util.List;
import org.springframework.stereotype.Service;
import com.ecep.contract.model.Company;
import com.ecep.contract.model.CompanyBankAccount;
import com.ecep.contract.vm.CompanyBankAccountViewModel;
import com.ecep.contract.vo.CompanyBankAccountVo;
@Service
public class CompanyBankAccountService extends QueryService<CompanyBankAccount, CompanyBankAccountViewModel> {
public class CompanyBankAccountService extends QueryService<CompanyBankAccountVo, CompanyBankAccountViewModel> {
public List<CompanyBankAccount> searchByCompany(Company company, String searchText) {
public List<CompanyBankAccountVo> searchByCompany(Company company, String searchText) {
throw new UnsupportedOperationException("未实现");
}
}

View File

@@ -1,24 +1,22 @@
package com.ecep.contract.service;
import com.ecep.contract.MessageHolder;
import com.ecep.contract.model.Company;
import com.ecep.contract.model.CompanyCustomer;
import com.ecep.contract.vm.CompanyCustomerViewModel;
import java.io.File;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import com.ecep.contract.MessageHolder;
import com.ecep.contract.model.CompanyCustomer;
import com.ecep.contract.util.ParamUtils;
import com.ecep.contract.vm.CompanyCustomerViewModel;
import com.ecep.contract.vo.CompanyVo;
@Service
public class CompanyCustomerService extends QueryService<CompanyCustomer, CompanyCustomerViewModel> {
public CompanyCustomer findByCompany(Company company) {
Map<String, Object> params = new HashMap<>();
params.put("company", company.getId());
Page<CompanyCustomer> page = findAll(params, Pageable.ofSize(1));
public CompanyCustomer findByCompany(CompanyVo company) {
Page<CompanyCustomer> page = findAll(ParamUtils.equal("company", company.getId()), Pageable.ofSize(1));
if (page.isEmpty()) {
return null;
}

View File

@@ -1,5 +1,22 @@
package com.ecep.contract.service;
import java.io.File;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.ecep.contract.vo.CompanyOldNameVo;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import com.ecep.contract.CompanyFileType;
import com.ecep.contract.MessageHolder;
import com.ecep.contract.MyDateTimeUtils;
@@ -12,17 +29,10 @@ import com.ecep.contract.model.CompanyOldName;
import com.ecep.contract.util.FileUtils;
import com.ecep.contract.util.ParamUtils;
import com.ecep.contract.vm.CompanyFileViewModel;
import javafx.collections.ObservableList;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import com.ecep.contract.vo.CompanyFileVo;
import com.ecep.contract.vo.CompanyVo;
import java.io.File;
import java.time.LocalDate;
import java.util.*;
import java.util.function.Consumer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javafx.collections.ObservableList;
@Service
public class CompanyFileService extends QueryService<CompanyFile, CompanyFileViewModel> {
@@ -295,16 +305,16 @@ public class CompanyFileService extends QueryService<CompanyFile, CompanyFileVie
* @param files 要被移动的文件集合,需要从中选择需要的
* @param holder 状态输出
*/
public boolean retrieveFromDownloadFiles(Company company, File[] files, MessageHolder holder) {
public boolean retrieveFromDownloadFiles(CompanyVo company, File[] files, MessageHolder holder) {
Map<String, File> map = new HashMap<>();
File home = new File(company.getPath());
map.put(company.getName(), home);
List<CompanyFile> retrieveFiles = new ArrayList<>();
List<CompanyFileVo> retrieveFiles = new ArrayList<>();
List<CompanyOldName> oldNames = SpringApp.getBean(CompanyOldNameService.class).findAllByCompany(company);
List<CompanyOldNameVo> oldNames = SpringApp.getBean(CompanyOldNameService.class).findAllByCompany(company);
// 获取所有曾用名
for (CompanyOldName companyOldName : oldNames) {
for (CompanyOldNameVo companyOldName : oldNames) {
String name = companyOldName.getName();
if (!StringUtils.hasText(name)) {
continue;
@@ -375,13 +385,13 @@ public class CompanyFileService extends QueryService<CompanyFile, CompanyFileVie
* @param holder 状态输出
* @return 生成的公司文件对象如果无法转换则返回null
*/
private CompanyFile fillDownloadFileType(Company company, File file, String companyName, File destDir,
private CompanyFileVo fillDownloadFileType(CompanyVo company, File file, String companyName, File destDir,
MessageHolder holder) {
String fileName = file.getName();
// 天眼查的报告
// 目前只有 基础版企业信用报告, 企业信用信息公示报告下载保存时的文件名中没有天眼查
if (CloudTycService.isTycReport(fileName)) {
CompanyFile companyFile = new CompanyFile();
CompanyFileVo companyFile = new CompanyFileVo();
companyFile.setType(CompanyFileType.CreditReport);
fillApplyDateAbsent(file, companyFile);
@@ -471,7 +481,7 @@ public class CompanyFileService extends QueryService<CompanyFile, CompanyFileVie
/**
* 当 ApplyDate 未设置时,尝试使用文件名中包含的日期
*/
private static void fillApplyDateAbsent(File file, CompanyFile companyFile) {
private static void fillApplyDateAbsent(File file, CompanyFileVo companyFile) {
LocalDate applyDate = companyFile.getApplyDate();
if (applyDate != null) {
return;

View File

@@ -1,36 +1,39 @@
package com.ecep.contract.service;
import com.ecep.contract.model.Company;
import com.ecep.contract.model.CompanyOldName;
import com.ecep.contract.vm.CompanyOldNameViewModel;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.util.HashMap;
import java.util.List;
@Service
public class CompanyOldNameService extends QueryService<CompanyOldName, CompanyOldNameViewModel> {
import com.ecep.contract.model.IdentityEntity;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
public boolean makePathAbsent(CompanyOldName companyOldName) {
import com.ecep.contract.model.Company;
import com.ecep.contract.model.CompanyOldName;
import com.ecep.contract.util.ParamUtils;
import com.ecep.contract.vm.CompanyOldNameViewModel;
import com.ecep.contract.vo.CompanyOldNameVo;
import com.ecep.contract.vo.CompanyVo;
@Service
public class CompanyOldNameService extends QueryService<CompanyOldNameVo, CompanyOldNameViewModel> {
public boolean makePathAbsent(CompanyOldNameVo companyOldName) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'makePathAbsent'");
}
public CompanyOldName findMatchByDate(Company company, LocalDate localDate) {
public CompanyOldName findMatchByDate(CompanyVo company, LocalDate localDate) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'findMatchByDate'");
}
public List<CompanyOldName> findAllByCompanyAndName(Company company, String oldName) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'findAllByCompanyAndName'");
public List<CompanyOldNameVo> findAllByCompanyAndName(CompanyVo company, String oldName) {
return findAll(ParamUtils.builder().equals("company", company.getId()).equals("oldName", oldName).build(),
Pageable.unpaged()).getContent();
}
public List<CompanyOldName> findAllByCompany(Company company) {
HashMap<String, Object> params = new HashMap<>();
params.put("company", company.getId());
return findAll(params, Pageable.unpaged()).getContent();
public List<CompanyOldNameVo> findAllByCompany(IdentityEntity company) {
return findAll(ParamUtils.equal("company", company.getId()), Pageable.unpaged()).getContent();
}
}

View File

@@ -1,5 +1,18 @@
package com.ecep.contract.service;
import java.io.File;
import java.time.LocalDate;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import com.ecep.contract.MessageHolder;
import com.ecep.contract.MyDateTimeUtils;
import com.ecep.contract.SpringApp;
@@ -7,22 +20,11 @@ import com.ecep.contract.constant.CompanyConstant;
import com.ecep.contract.model.Company;
import com.ecep.contract.util.FileUtils;
import com.ecep.contract.vm.CompanyViewModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.io.File;
import java.time.LocalDate;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.ecep.contract.vo.CompanyVo;
@Service
@CacheConfig(cacheNames = "company")
public class CompanyService extends QueryService<Company, CompanyViewModel> {
public class CompanyService extends QueryService<CompanyVo, CompanyViewModel> {
@Autowired
private SysConfService confService;
@@ -42,37 +44,37 @@ public class CompanyService extends QueryService<Company, CompanyViewModel> {
}
@Cacheable(key = "#p0")
public Company findById(Integer id) {
public CompanyVo findById(Integer id) {
return super.findById(id);
}
public Company findByName(String name) {
List<Company> list = findAllByName(name);
public CompanyVo findByName(String name) {
List<CompanyVo> list = findAllByName(name);
if (list.isEmpty()) {
return null;
}
return list.getFirst();
}
public List<Company> findAllByName(String name) {
public List<CompanyVo> findAllByName(String name) {
Map<String, Object> params = new HashMap<>();
params.put("name", name);
return findAll(params, Pageable.unpaged()).getContent();
}
public void merge(Company company, Company updater) {
public void merge(CompanyVo company, CompanyVo updater) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'merge'");
}
public Company createNewCompany(String newCompanyName) {
Company company = new Company();
public CompanyVo createNewCompany(String newCompanyName) {
CompanyVo company = new CompanyVo();
company.setName(newCompanyName);
company.setCreated(LocalDate.now());
return company;
}
public boolean existsCompanyPath(Company company) {
public boolean existsCompanyPath(CompanyVo company) {
if (!StringUtils.hasText(company.getPath())) {
return false;
}
@@ -81,7 +83,7 @@ public class CompanyService extends QueryService<Company, CompanyViewModel> {
return path.exists();
}
public boolean checkCompanyPathInBasePath(Company company) {
public boolean checkCompanyPathInBasePath(CompanyVo company) {
if (!existsCompanyPath(company)) {
return false;
}
@@ -93,7 +95,7 @@ public class CompanyService extends QueryService<Company, CompanyViewModel> {
return path.getAbsolutePath().startsWith(basePath.getAbsolutePath());
}
public void verifyEnterpriseStatus(Company company, LocalDate verifyDate, MessageHolder holder) {
public void verifyEnterpriseStatus(CompanyVo company, LocalDate verifyDate, MessageHolder holder) {
// 检查营业状态
String entStatus = company.getEntStatus();
if (StringUtils.hasText(entStatus)) {
@@ -114,7 +116,7 @@ public class CompanyService extends QueryService<Company, CompanyViewModel> {
}
}
public boolean makePathAbsent(Company company) {
public boolean makePathAbsent(CompanyVo company) {
String path = company.getPath();
if (StringUtils.hasText(path)) {
File file = new File(path);
@@ -141,7 +143,7 @@ public class CompanyService extends QueryService<Company, CompanyViewModel> {
* @param company 要创建的企业对象
* @return 目录
*/
public File makePath(Company company) {
public File makePath(CompanyVo company) {
File basePath = getBasePath();
if (!basePath.exists()) {
return null;
@@ -178,7 +180,7 @@ public class CompanyService extends QueryService<Company, CompanyViewModel> {
* @param files 要被移动的文件集合,需要从中选择需要的
* @param holder 状态输出
*/
public boolean retrieveFromDownloadFiles(Company company, File[] files, MessageHolder holder) {
public boolean retrieveFromDownloadFiles(CompanyVo company, File[] files, MessageHolder holder) {
//
boolean companyChanged = makePathAbsent(company);

View File

@@ -2,20 +2,30 @@ package com.ecep.contract.service;
import java.io.File;
import java.time.LocalDate;
import java.util.*;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import com.ecep.contract.VendorType;
import com.ecep.contract.model.*;
import com.ecep.contract.util.MyStringUtils;
import com.ecep.contract.util.ProxyUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import com.ecep.contract.MessageHolder;
import com.ecep.contract.VendorType;
import com.ecep.contract.model.Company;
import com.ecep.contract.model.CompanyVendor;
import com.ecep.contract.model.Contract;
import com.ecep.contract.model.VendorCatalog;
import com.ecep.contract.model.VendorTypeLocal;
import com.ecep.contract.util.MyStringUtils;
import com.ecep.contract.util.ParamUtils;
import com.ecep.contract.util.ProxyUtils;
import com.ecep.contract.vm.CompanyVendorViewModel;
import org.springframework.util.StringUtils;
import com.ecep.contract.vo.CompanyVo;
@Service
public class CompanyVendorService extends QueryService<CompanyVendor, CompanyVendorViewModel> {
@@ -27,14 +37,11 @@ public class CompanyVendorService extends QueryService<CompanyVendor, CompanyVen
private CompanyVendorFileService companyVendorFileService;
public VendorCatalog findCatalogById(Integer id) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'findCatalogById'");
}
public CompanyVendor findByCompany(Company company) {
Map<String, Object> params = new HashMap<>();
params.put("company", company.getId());
Page<CompanyVendor> page = findAll(params, Pageable.ofSize(1));
public CompanyVendor findByCompany(CompanyVo company) {
Page<CompanyVendor> page = findAll(ParamUtils.equal("company", company.getId()), Pageable.ofSize(1));
if (page.isEmpty()) {
return null;
}
@@ -93,7 +100,8 @@ public class CompanyVendorService extends QueryService<CompanyVendor, CompanyVen
if (entStatus.contains("注销")) {
holder.error("营业状态异常:" + entStatus + ", 自动设置为不合格");
companyVendor.setType(VendorType.UNQUALIFIED);
companyVendor.setDescription(MyStringUtils.appendIfAbsent(companyVendor.getDescription(), "自动检测到营业状态为" + entStatus + ",设置为不合格供应商."));
companyVendor.setDescription(MyStringUtils.appendIfAbsent(companyVendor.getDescription(),
"自动检测到营业状态为" + entStatus + ",设置为不合格供应商."));
valid = true;
}
} else {

View File

@@ -10,8 +10,8 @@ import com.ecep.contract.vm.InventoryViewModel;
public class InventoryService extends QueryService<Inventory, InventoryViewModel> {
public Inventory createNewInstance() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'createNewInstance'");
Inventory inventory = new Inventory();
return inventory;
}
public void syncInventory(Inventory inventory, MessageHolder holder) {

View File

@@ -9,6 +9,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import javafx.util.StringConverter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -253,4 +254,7 @@ public class QueryService<T extends IdentityEntity, TV extends IdentityViewModel
return pageContent;
}
public StringConverter<T> getStringConverter() {
throw new UnsupportedOperationException("Not implemented");
}
}

View File

@@ -5,7 +5,7 @@ import org.slf4j.LoggerFactory;
import com.ecep.contract.MessageHolder;
import com.ecep.contract.constant.CloudServiceConstant;
import com.ecep.contract.model.Company;
import com.ecep.contract.vo.CompanyVo;
import lombok.Setter;
@@ -15,7 +15,7 @@ import lombok.Setter;
public class CompanyCompositeUpdateTasker extends Tasker<Object> {
private static final Logger logger = LoggerFactory.getLogger(CompanyCompositeUpdateTasker.class);
@Setter
private Company company;
private CompanyVo company;
@Override
protected Object execute(MessageHolder holder) throws Exception {

View File

@@ -1,7 +1,7 @@
package com.ecep.contract.task;
import com.ecep.contract.MessageHolder;
import com.ecep.contract.model.Company;
import com.ecep.contract.vo.CompanyVo;
import lombok.Getter;
import lombok.Setter;
@@ -9,7 +9,7 @@ import lombok.Setter;
public class CompanyVerifyTasker extends Tasker<Object> {
@Getter
@Setter
private Company company;
private CompanyVo company;
@Override
protected Object execute(MessageHolder holder) throws Exception {

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 增加一个 自动补全功能
*

View File

@@ -3,6 +3,7 @@ package com.ecep.contract.vm;
import java.util.Objects;
import com.ecep.contract.model.Bank;
import com.ecep.contract.vo.BankVo;
import javafx.beans.property.SimpleStringProperty;
import lombok.Data;
@@ -10,12 +11,12 @@ import lombok.EqualsAndHashCode;
@Data
@EqualsAndHashCode(callSuper = false)
public class BankViewModel extends IdentityViewModel<Bank> {
public class BankViewModel extends IdentityViewModel<BankVo> {
private SimpleStringProperty code = new SimpleStringProperty();
private SimpleStringProperty name = new SimpleStringProperty();
public static BankViewModel from(Bank v) {
public static BankViewModel from(BankVo v) {
BankViewModel vm = new BankViewModel();
vm.update(v);
return vm;
@@ -23,14 +24,14 @@ public class BankViewModel extends IdentityViewModel<Bank> {
@Override
protected void updateFrom(Bank v) {
protected void updateFrom(BankVo v) {
super.updateFrom(v);
getCode().set(v.getCode());
getName().set(v.getName());
}
@Override
public boolean copyTo(Bank v) {
public boolean copyTo(BankVo v) {
boolean modified = super.copyTo(v);
if (!Objects.equals(getCode().get(), v.getCode())) {
v.setCode(getCode().get());

View File

@@ -3,9 +3,7 @@ package com.ecep.contract.vm;
import java.time.LocalDate;
import java.util.Objects;
import com.ecep.contract.model.Bank;
import com.ecep.contract.model.Company;
import com.ecep.contract.model.CompanyBankAccount;
import com.ecep.contract.vo.CompanyBankAccountVo;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleObjectProperty;
@@ -15,11 +13,12 @@ import lombok.EqualsAndHashCode;
@Data
@EqualsAndHashCode(callSuper = false)
public class CompanyBankAccountViewModel extends IdentityViewModel<CompanyBankAccount> implements CompanyBasedViewModel {
public class CompanyBankAccountViewModel extends IdentityViewModel<CompanyBankAccountVo>
implements CompanyBasedViewModel {
private SimpleIntegerProperty id = new SimpleIntegerProperty();
private SimpleObjectProperty<Company> company = new SimpleObjectProperty<>();
private SimpleObjectProperty<Bank> bank = new SimpleObjectProperty<>();
private SimpleObjectProperty<Integer> companyId = new SimpleObjectProperty<>();
private SimpleObjectProperty<Integer> bankId = new SimpleObjectProperty<>();
private SimpleStringProperty openingBank = new SimpleStringProperty();
private SimpleStringProperty account = new SimpleStringProperty();
@@ -29,27 +28,27 @@ public class CompanyBankAccountViewModel extends IdentityViewModel<CompanyBankAc
private SimpleIntegerProperty version = new SimpleIntegerProperty();
@Override
protected void updateFrom(CompanyBankAccount v) {
protected void updateFrom(CompanyBankAccountVo v) {
getId().set(v.getId());
getCompany().set(v.getCompany());
getBank().set(v.getBank());
companyId.set(v.getCompanyId());
bankId.set(v.getBankId());
getOpeningBank().set(v.getOpeningBank());
getAccount().set(v.getAccount());
}
@Override
public boolean copyTo(CompanyBankAccount v) {
public boolean copyTo(CompanyBankAccountVo v) {
boolean modified = super.copyTo(v);
if (!Objects.equals(id.get(), v.getId())) {
v.setId(id.get());
modified = true;
}
if (!Objects.equals(company.get(), v.getCompany())) {
v.setCompany(company.get());
if (!Objects.equals(companyId.get(), v.getCompanyId())) {
v.setCompanyId(companyId.get());
modified = true;
}
if (!Objects.equals(bank.get(), v.getBank())) {
v.setBank(bank.get());
if (!Objects.equals(bankId.get(), v.getBankId())) {
v.setBankId(bankId.get());
modified = true;
}
if (!Objects.equals(openingBank.get(), v.getOpeningBank())) {
@@ -63,7 +62,7 @@ public class CompanyBankAccountViewModel extends IdentityViewModel<CompanyBankAc
return modified;
}
public static CompanyBankAccountViewModel from(CompanyBankAccount v) {
public static CompanyBankAccountViewModel from(CompanyBankAccountVo v) {
CompanyBankAccountViewModel vm = new CompanyBankAccountViewModel();
vm.updateFrom(v);
return vm;

View File

@@ -1,9 +1,7 @@
package com.ecep.contract.vm;
import com.ecep.contract.model.Company;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.ObjectProperty;
public interface CompanyBasedViewModel {
SimpleObjectProperty<Company> getCompany();
ObjectProperty<Integer> getCompanyId();
}

View File

@@ -3,7 +3,7 @@ package com.ecep.contract.vm;
import java.time.LocalDate;
import java.util.Objects;
import com.ecep.contract.model.CompanyOldName;
import com.ecep.contract.vo.CompanyOldNameVo;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleIntegerProperty;
@@ -14,40 +14,39 @@ import lombok.EqualsAndHashCode;
@Data
@EqualsAndHashCode(callSuper = false)
public class CompanyOldNameViewModel extends IdentityViewModel<CompanyOldName> {
public class CompanyOldNameViewModel extends IdentityViewModel<CompanyOldNameVo> {
private SimpleIntegerProperty id = new SimpleIntegerProperty();
private SimpleStringProperty name = new SimpleStringProperty();
private SimpleStringProperty path = new SimpleStringProperty();
private SimpleObjectProperty<LocalDate> beginDate = new SimpleObjectProperty<>();
private SimpleObjectProperty<LocalDate> endDate = new SimpleObjectProperty<>();
private SimpleBooleanProperty ambiguity = new SimpleBooleanProperty();
private SimpleIntegerProperty version = new SimpleIntegerProperty();
private SimpleBooleanProperty active = new SimpleBooleanProperty();
private SimpleStringProperty memo = new SimpleStringProperty();
private SimpleIntegerProperty version = new SimpleIntegerProperty();
public static CompanyOldNameViewModel from(CompanyOldName name) {
public static CompanyOldNameViewModel from(CompanyOldNameVo name) {
CompanyOldNameViewModel model = new CompanyOldNameViewModel();
model.update(name);
return model;
}
public void updateFrom(CompanyOldName oldName) {
public void updateFrom(CompanyOldNameVo oldName) {
id.set(oldName.getId());
name.set(oldName.getName());
path.set(oldName.getPath());
memo.set(oldName.getMemo());
beginDate.set(oldName.getBeginDate());
endDate.set(oldName.getEndDate());
ambiguity.set(oldName.getAmbiguity());
ambiguity.set(oldName.isAmbiguity());
active.set(oldName.isActive());
version.set(oldName.getVersion());
}
public boolean copyTo(CompanyOldName c) {
public boolean copyTo(CompanyOldNameVo c) {
boolean modified = super.copyTo(c);
if (!Objects.equals(id.get(), c.getId())) {
c.setId(id.get());
@@ -73,10 +72,14 @@ public class CompanyOldNameViewModel extends IdentityViewModel<CompanyOldName> {
c.setEndDate(endDate.get());
modified = true;
}
if (!Objects.equals(ambiguity.get(), c.getAmbiguity())) {
if (!Objects.equals(ambiguity.get(), c.isAmbiguity())) {
c.setAmbiguity(ambiguity.get());
modified = true;
}
if (!Objects.equals(active.get(), c.isActive())) {
c.setActive(active.get());
modified = true;
}
return modified;
}
}

View File

@@ -3,7 +3,7 @@ package com.ecep.contract.vm;
import java.time.LocalDate;
import java.util.Objects;
import com.ecep.contract.model.Company;
import com.ecep.contract.vo.CompanyVo;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleIntegerProperty;
@@ -12,10 +12,9 @@ import javafx.beans.property.SimpleStringProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
@Data
@EqualsAndHashCode(callSuper = false)
public class CompanyViewModel extends IdentityViewModel<Company> {
public class CompanyViewModel extends IdentityViewModel<CompanyVo> {
private SimpleStringProperty name = new SimpleStringProperty();
private SimpleStringProperty shortName = new SimpleStringProperty();
private SimpleStringProperty uid = new SimpleStringProperty();
@@ -42,14 +41,14 @@ public class CompanyViewModel extends IdentityViewModel<Company> {
private SimpleIntegerProperty version = new SimpleIntegerProperty();
public static CompanyViewModel from(Company company) {
public static CompanyViewModel from(CompanyVo company) {
CompanyViewModel model = new CompanyViewModel();
model.update(company);
return model;
}
@Override
protected void updateFrom(Company company) {
protected void updateFrom(CompanyVo company) {
super.updateFrom(company);
name.set(company.getName());
shortName.set(company.getShortName());
@@ -79,7 +78,7 @@ public class CompanyViewModel extends IdentityViewModel<Company> {
version.set(company.getVersion());
}
public boolean copyTo(Company v) {
public boolean copyTo(CompanyVo v) {
boolean modified = super.copyTo(v);
if (!Objects.equals(name.get(), v.getName())) {
v.setName(name.get());

View File

@@ -15,6 +15,7 @@ import com.ecep.contract.model.Project;
import com.ecep.contract.model.ProjectIndustry;
import com.ecep.contract.model.ProjectSaleType;
import com.ecep.contract.model.ProjectType;
import com.ecep.contract.vo.ProjectVo;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleIntegerProperty;
@@ -25,8 +26,8 @@ import lombok.EqualsAndHashCode;
@Data
@EqualsAndHashCode(callSuper = false)
public class ProjectViewModel extends IdentityViewModel<Project> {
private SimpleObjectProperty<Company> customer = new SimpleObjectProperty<>();
public class ProjectViewModel extends IdentityViewModel<ProjectVo> {
private SimpleObjectProperty<Integer> customer = new SimpleObjectProperty<>();
/**
* 银行账户(公司可能有多个账户,此项目关联其中一个账户)
*/
@@ -78,14 +79,14 @@ public class ProjectViewModel extends IdentityViewModel<Project> {
private SimpleIntegerProperty version = new SimpleIntegerProperty();
public static ProjectViewModel from(Project project) {
public static ProjectViewModel from(ProjectVo project) {
ProjectViewModel model = new ProjectViewModel();
model.update(project);
return model;
}
@Override
protected void updateFrom(Project v) {
protected void updateFrom(ProjectVo v) {
super.updateFrom(v);
customer.set(v.getCustomer());
bankAccount.set(v.getBankAccount());
@@ -118,7 +119,7 @@ public class ProjectViewModel extends IdentityViewModel<Project> {
getVersion().set(v.getVersion());
}
public boolean copyTo(Project v) {
public boolean copyTo(ProjectVo v) {
boolean modified = super.copyTo(v);
if (!Objects.equals(customer.get(), v.getCustomer())) {
v.setCustomer(customer.get());