feat: 添加供应商类型本地化支持及优化表格单元格显示

refactor: 重构供应商类型相关服务及控制器
fix: 修复供应商类型表格单元格初始化问题
style: 优化代码格式及导入顺序
This commit is contained in:
2025-09-23 14:12:09 +08:00
parent 386b6d01b4
commit 515b255567
22 changed files with 323 additions and 143 deletions

View File

@@ -103,6 +103,9 @@ public class AsyncUpdateTableCell<V, K, T extends IdentityEntity> extends javafx
*/
protected T initialize() {
K k = getItem();
if (k == null) {
return null;
}
if (k instanceof Integer id) {
return getService().findById(id);
}

View File

@@ -4,7 +4,6 @@ import com.ecep.contract.SpringApp;
import com.ecep.contract.VendorType;
import com.ecep.contract.service.VendorTypeService;
import com.ecep.contract.vo.VendorTypeLocalVo;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.util.Callback;
@@ -23,8 +22,8 @@ public class VendorTypeTableCell<T> extends AsyncUpdateTableCell<T, VendorType,
return param -> new VendorTypeTableCell<>(service);
}
public VendorTypeTableCell() {
this.vendorTypeService = SpringApp.getBean(VendorTypeService.class);
}
public VendorTypeTableCell(VendorTypeService service) {
@@ -42,7 +41,13 @@ public class VendorTypeTableCell<T> extends AsyncUpdateTableCell<T, VendorType,
@Override
protected VendorTypeLocalVo initialize() {
VendorType item = getItem();
return getServiceBean().findByType(item);
VendorTypeLocalVo localVo = getServiceBean().findByType(item);
System.out.println("item = " + item + ", localVo = " + getServiceBean().getStringConverter().toString(localVo));
return localVo;
}
@Override
public String format(VendorTypeLocalVo entity) {
return getServiceBean().getStringConverter().toString(entity);
}
}

View File

@@ -22,9 +22,6 @@ public class CompanyVendorManagerSkin
@Setter
private CompanyService companyService;
@Setter
private CompanyVendorService companyVendorService;
public CompanyVendorManagerSkin(CompanyVendorManagerWindowController controller) {
super(controller);
}
@@ -37,10 +34,7 @@ public class CompanyVendorManagerSkin
}
public CompanyVendorService getCompanyVendorService() {
if (companyVendorService == null) {
companyVendorService = getBean(CompanyVendorService.class);
}
return companyVendorService;
return controller.getViewModelService();
}
@Override
@@ -57,16 +51,17 @@ public class CompanyVendorManagerSkin
ComboBoxUtils.initialComboBox(controller.typeSelector, null, getBean(VendorTypeService.class), true);
controller.idColumn.setCellValueFactory(param -> param.getValue().getId());
// id column
controller.codeColumn.setCellValueFactory(param -> param.getValue().getCode());
// catalog column
controller.catalogColumn.setCellValueFactory(param -> param.getValue().getCatalog());
controller.catalogColumn.setCellFactory(VendorCatalogTableCell.forTableColumn(getBean(VendorCatalogService.class)));
// type column
controller.typeColumn.setCellValueFactory(param -> param.getValue().getType());
controller.typeColumn.setCellFactory(VendorTypeTableCell.forTableColumn(getBean(VendorTypeService.class)));
controller.purchaseColumn.setCellValueFactory(param -> param.getValue().getPurchase());
// company column
controller.companyColumn.setCellValueFactory(param -> param.getValue().getCompany());
controller.companyColumn.setCellFactory(CompanyTableCell.forTableColumn(getCompanyService()));

View File

@@ -115,7 +115,6 @@ public class CompanyVendorManagerWindowController
protected CompanyVendorManagerSkin createDefaultSkin() {
CompanyVendorManagerSkin skin = new CompanyVendorManagerSkin(this);
skin.setCompanyService(companyService);
skin.setCompanyVendorService(companyVendorService);
return skin;
}

View File

@@ -11,6 +11,7 @@ import com.ecep.contract.controller.tab.AbstEntityBasedTabSkin;
import com.ecep.contract.model.VendorTypeLocal;
import com.ecep.contract.service.CompanyContactService;
import com.ecep.contract.service.CompanyVendorService;
import com.ecep.contract.service.VendorTypeService;
import com.ecep.contract.util.UITools;
import com.ecep.contract.vm.CompanyVendorViewModel;
import com.ecep.contract.vm.CompanyViewModel;
@@ -51,10 +52,7 @@ public class CompanyVendorTabSkinBase
controller.developDateField.setConverter(converter);
controller.developDateField.valueProperty().bindBidirectional(viewModel.getDevelopDate());
List<VendorTypeLocal> vendorTypeLocals = getCompanyVendorService()
.findAllTypes(controller.getLocale().toLanguageTag());
ComboBoxUtils.initialComboBox(controller.catalogField, vendorTypeLocals, true);
ComboBoxUtils.bindComboBox(controller.catalogField, viewModel.getType(), vendorTypeLocals);
ComboBoxUtils.initialComboBox(controller.catalogField, viewModel.getCatalog(), getCachedBean(VendorTypeService.class), true);
controller.protocolProviderField.selectedProperty().bindBidirectional(viewModel.getProtocolProvider());
UITools.autoCompletion(controller.contactField, viewModel.getContact(), getCompanyContactService());

View File

@@ -2,6 +2,7 @@ package com.ecep.contract.controller.vendor;
import java.io.File;
import com.ecep.contract.vo.VendorTypeLocalVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Lazy;
@@ -55,7 +56,7 @@ public class CompanyVendorWindowController extends AbstEntityController<CompanyV
public Tab fileTab;
public Tab entityTab;
public ComboBox<VendorTypeLocal> catalogField;
public ComboBox<VendorTypeLocalVo> catalogField;
public CheckBox protocolProviderField;
public TextField pathField;
public TextArea descriptionField;

View File

@@ -3,6 +3,11 @@ package com.ecep.contract.controller.vendor.approved_list;
import java.util.ArrayList;
import java.util.List;
import com.ecep.contract.VendorType;
import com.ecep.contract.controller.ComboBoxUtils;
import com.ecep.contract.controller.table.cell.VendorTypeTableCell;
import com.ecep.contract.service.*;
import com.ecep.contract.vo.*;
import org.springframework.util.StringUtils;
import com.ecep.contract.controller.tab.TabSkin;
@@ -11,11 +16,6 @@ import com.ecep.contract.controller.table.cell.CompanyVendorTableCell;
import com.ecep.contract.controller.vendor.CompanyVendorWindowController;
import com.ecep.contract.model.CompanyVendor;
import com.ecep.contract.model.VendorTypeLocal;
import com.ecep.contract.service.CompanyOldNameService;
import com.ecep.contract.service.CompanyService;
import com.ecep.contract.service.CompanyVendorApprovedItemService;
import com.ecep.contract.service.CompanyVendorService;
import com.ecep.contract.service.SysConfService;
import com.ecep.contract.util.BooleanConfigProperty;
import com.ecep.contract.util.FxmlPath;
import com.ecep.contract.util.IntegerConfigProperty;
@@ -25,11 +25,6 @@ import com.ecep.contract.util.ProxyUtils;
import com.ecep.contract.util.UITools;
import com.ecep.contract.vm.CompanyVendorApprovedItemViewModel;
import com.ecep.contract.vm.CompanyVendorApprovedListViewModel;
import com.ecep.contract.vo.CompanyOldNameVo;
import com.ecep.contract.vo.CompanyVendorApprovedItemVo;
import com.ecep.contract.vo.CompanyVendorApprovedListVo;
import com.ecep.contract.vo.CompanyVendorVo;
import com.ecep.contract.vo.CompanyVo;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.collections.FXCollections;
@@ -57,12 +52,12 @@ public class CompanyVendorApprovedListTabSkinVendors
private CompanyVendorService companyVendorService;
private CompanyOldNameService companyOldNameService;
public ComboBox<VendorTypeLocal> typeSelector;
public ComboBox<VendorTypeLocalVo> typeSelector;
public Menu vendorTableContextChangeTypeMenu;
public TableColumn<CompanyVendorApprovedItemViewModel, Number> idColumn;
public TableColumn<CompanyVendorApprovedItemViewModel, Integer> vendorColumn;
public TableColumn<CompanyVendorApprovedItemViewModel, String> typeColumn;
public TableColumn<CompanyVendorApprovedItemViewModel, VendorType> typeColumn;
public TableColumn<CompanyVendorApprovedItemViewModel, String> descriptionColumn;
public CheckMenuItem logUnqualifiedVendorChecker;
@@ -115,7 +110,7 @@ public class CompanyVendorApprovedListTabSkinVendors
@Override
public ParamUtils.Builder getSpecification() {
Builder params = super.getSpecification();
VendorTypeLocal selectorType = typeSelector.getValue();
VendorTypeLocalVo selectorType = typeSelector.getValue();
if (selectorType != null) {
params.equals("type", selectorType.getType());
}
@@ -136,49 +131,22 @@ public class CompanyVendorApprovedListTabSkinVendors
@Override
public void initializeTab() {
List<VendorTypeLocal> vendorTypeLocals = getCompanyVendorService()
.findAllTypes(controller.getLocale().toLanguageTag());
ObservableList<VendorTypeLocal> vendorTypeItems = FXCollections.observableArrayList();
vendorTypeItems.add(null);
vendorTypeItems.addAll(vendorTypeLocals);
typeSelector.setItems(vendorTypeItems);
typeSelector.setConverter(new StringConverter<>() {
@Override
public String toString(VendorTypeLocal typeLocal) {
if (typeLocal == null) {
return "";
}
return typeLocal.getValue();
}
@Override
public VendorTypeLocal fromString(String string) {
return null;
}
});
ComboBoxUtils.initialComboBox(typeSelector, null, getCachedBean(VendorTypeService.class), true);
idColumn.setCellValueFactory(param -> param.getValue().getId());
// 厂商, vendor
vendorColumn.setCellValueFactory(param -> param.getValue().getVendor());
vendorColumn.setCellFactory(param -> new VendorTableCell(getCompanyVendorService(), getCompanyService()));
typeColumn.setCellValueFactory(param -> param.getValue().getType().map(v -> {
if (v == null) {
return "-";
}
for (VendorTypeLocal vendorTypeLocal : vendorTypeLocals) {
if (vendorTypeLocal.getType() == v) {
return vendorTypeLocal.getValue();
}
}
return v.name();
}));
vendorColumn.setCellFactory(CompanyVendorTableCell.forTableColumn(getCompanyVendorService()));
// 类型, type
typeColumn.setCellValueFactory(param -> param.getValue().getType());
typeColumn.setCellFactory(VendorTypeTableCell.forTableColumn(getCachedBean(VendorTypeService.class)));
// 描述, description
descriptionColumn.setCellValueFactory(param -> param.getValue().getDescription());
table.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
List<MenuItem> menuItems = new ArrayList<>();
for (VendorTypeLocal value : vendorTypeLocals) {
for (VendorTypeLocalVo value : getCachedBean(VendorTypeService.class).findAll()) {
MenuItem menuItem = new MenuItem();
menuItem.setText(value.getValue());
menuItem.setOnAction(event -> {
@@ -220,7 +188,7 @@ public class CompanyVendorApprovedListTabSkinVendors
super.initializeTab();
}
private void changeVendorTableSelectedItemType(VendorTypeLocal value) {
private void changeVendorTableSelectedItemType(VendorTypeLocalVo value) {
CompanyVendorApprovedItemViewModel selectedItem = getTableView().getSelectionModel().getSelectedItem();
selectedItem.getType().set(value.getType());
@@ -299,30 +267,4 @@ public class CompanyVendorApprovedListTabSkinVendors
}
}
}
static class VendorTableCell extends CompanyVendorTableCell<CompanyVendorApprovedItemViewModel> {
public VendorTableCell(CompanyVendorService companyVendorService, CompanyService companyService) {
super();
setService(companyVendorService);
setCompanyService(companyService);
}
@Override
protected boolean isInitialized(CompanyVendorVo item) {
CompanyVendorApprovedItemViewModel row = getTableRow().getItem();
if (StringUtils.hasText(row.getVendorName().get())) {
return true;
}
return super.isInitialized(item);
}
@Override
public String format(CompanyVendorVo vendor) {
CompanyVendorApprovedItemViewModel row = getTableRow().getItem();
if (StringUtils.hasText(row.getVendorName().get())) {
return row.getVendorName().get();
}
return super.format(vendor);
}
}
}

View File

@@ -138,17 +138,6 @@ public class CompanyVendorService extends QueryService<CompanyVendorVo, CompanyV
return valid;
}
public List<VendorTypeLocal> findAllTypes(Locale locale) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'findAllTypes'");
}
public List<VendorTypeLocal> findAllTypes(String languageTag) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'findAllTypes'");
}
public boolean makePathAbsent(CompanyVendorVo companyVendor) {
String path = companyVendor.getPath();
if (StringUtils.hasText(path)) {

View File

@@ -16,13 +16,15 @@ import java.util.Locale;
@Service
@CacheConfig(cacheNames = "vendor-type")
public class VendorTypeService extends QueryService<VendorTypeLocalVo, VendorTypeLocalViewModel> {
private final StringConverter<VendorTypeLocalVo> stringConverter = new VendorTypeStringConverter(this);
@Cacheable(key = "#p0")
@Override
public VendorTypeLocalVo findById(Integer id) {
return super.findById(id);
}
@Cacheable(key = "'type-'+#p0")
@Cacheable(key = "'type-'+#p0.ordinal()")
public VendorTypeLocalVo findByType(VendorType type) {
return findAll(ParamUtils.builder().equals("type", type).build(), Pageable.ofSize(1)).stream().findFirst()
.orElse(null);
@@ -46,8 +48,6 @@ public class VendorTypeService extends QueryService<VendorTypeLocalVo, VendorTyp
super.delete(entity);
}
private StringConverter<VendorTypeLocalVo> stringConverter = new VendorTypeStringConverter(this);
@Override
public StringConverter<VendorTypeLocalVo> getStringConverter() {
return stringConverter;

View File

@@ -1,13 +1,11 @@
package com.ecep.contract.util;
import com.ecep.contract.constant.ServiceConstant;
import java.time.LocalDate;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.function.Consumer;
import java.util.function.Supplier;
import com.ecep.contract.constant.ServiceConstant;
public class ParamUtils {
public static Map<String, Object> between(String key, LocalDate begin, LocalDate end) {