diff --git a/client/pom.xml b/client/pom.xml index 1356444..5e74717 100644 --- a/client/pom.xml +++ b/client/pom.xml @@ -6,12 +6,12 @@ com.ecep.contract Contract-Manager - 0.0.122-SNAPSHOT + 0.0.126-SNAPSHOT com.ecep.contract client - 0.0.122-SNAPSHOT + 0.0.126-SNAPSHOT ${java.version} @@ -22,7 +22,7 @@ com.ecep.contract common - 0.0.122-SNAPSHOT + 0.0.126-SNAPSHOT org.springframework.boot diff --git a/client/src/main/java/com/ecep/contract/controller/project/ProjectTabSkinBase.java b/client/src/main/java/com/ecep/contract/controller/project/ProjectTabSkinBase.java index 03f71f8..c6be87a 100644 --- a/client/src/main/java/com/ecep/contract/controller/project/ProjectTabSkinBase.java +++ b/client/src/main/java/com/ecep/contract/controller/project/ProjectTabSkinBase.java @@ -92,7 +92,6 @@ public class ProjectTabSkinBase extends AbstProjectBasedTabSkin implements TabSk controller.standardPayWayField.selectedProperty().bindBidirectional(viewModel.getStandardPayWay()); Bindings.bindBidirectional(controller.amountField.textProperty(), viewModel.getAmount(), new NumberStringConverter()); - ComboBoxUtils.initialComboBox(controller.saleTypeField, viewModel.getSaleType(), getSaleTypeService(), true); ComboBoxUtils.initialComboBox(controller.projectTypeField, viewModel.getProjectType(), getProjectTypeService(), true); diff --git a/client/src/main/java/com/ecep/contract/converter/ProductTypeStringConverter.java b/client/src/main/java/com/ecep/contract/converter/ProductTypeStringConverter.java index 37338f5..bafa240 100644 --- a/client/src/main/java/com/ecep/contract/converter/ProductTypeStringConverter.java +++ b/client/src/main/java/com/ecep/contract/converter/ProductTypeStringConverter.java @@ -1,29 +1,25 @@ package com.ecep.contract.converter; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Lazy; -import org.springframework.stereotype.Component; - import com.ecep.contract.service.ProductTypeService; import com.ecep.contract.vo.ProductTypeVo; -import jakarta.annotation.PostConstruct; +import javafx.util.StringConverter; -@Lazy -@Component -public class ProductTypeStringConverter extends EntityStringConverter { - @Lazy - @Autowired - private ProductTypeService service; - - public ProductTypeStringConverter() { +public class ProductTypeStringConverter extends StringConverter { + private final ProductTypeService service; + public ProductTypeStringConverter(ProductTypeService service) { + this.service = service; } - @PostConstruct - private void init() { - setInitialized(type -> service.findById(type.getId())); - setSuggestion(service::search); + @Override + public String toString(ProductTypeVo type) { + return type == null ? "" : type.getCode() + " " + type.getName(); + } + + @Override + public ProductTypeVo fromString(String string) { + return service.findByName(string); } diff --git a/client/src/main/java/com/ecep/contract/converter/ProductUsageStringConverter.java b/client/src/main/java/com/ecep/contract/converter/ProductUsageStringConverter.java index d35123c..24a5d86 100644 --- a/client/src/main/java/com/ecep/contract/converter/ProductUsageStringConverter.java +++ b/client/src/main/java/com/ecep/contract/converter/ProductUsageStringConverter.java @@ -1,5 +1,6 @@ package com.ecep.contract.converter; +import javafx.util.StringConverter; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Component; @@ -9,21 +10,21 @@ import com.ecep.contract.vo.ProductUsageVo; import jakarta.annotation.PostConstruct; -@Lazy -@Component -public class ProductUsageStringConverter extends EntityStringConverter { - @Lazy - @Autowired +public class ProductUsageStringConverter extends StringConverter { private ProductUsageService service; - public ProductUsageStringConverter() { - + public ProductUsageStringConverter(ProductUsageService service) { + this.service = service; } - @PostConstruct - private void init() { - setInitialized(usage -> service.findById(usage.getId())); - setSuggestion(service::search); + @Override + public String toString(ProductUsageVo usage) { + return usage == null ? "" : usage.getCode() + " " + usage.getName(); + } + + @Override + public ProductUsageVo fromString(String string) { + return service.findByName(string); } diff --git a/client/src/main/java/com/ecep/contract/converter/ProjectIndustryStringConverter.java b/client/src/main/java/com/ecep/contract/converter/ProjectIndustryStringConverter.java index 0591e73..b5ab546 100644 --- a/client/src/main/java/com/ecep/contract/converter/ProjectIndustryStringConverter.java +++ b/client/src/main/java/com/ecep/contract/converter/ProjectIndustryStringConverter.java @@ -1,30 +1,31 @@ package com.ecep.contract.converter; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Lazy; -import org.springframework.stereotype.Component; - import com.ecep.contract.service.ProjectIndustryService; import com.ecep.contract.vo.ProjectIndustryVo; -import jakarta.annotation.PostConstruct; +import javafx.util.StringConverter; -@Lazy -@Component -public class ProjectIndustryStringConverter extends EntityStringConverter { - @Lazy - @Autowired +public class ProjectIndustryStringConverter extends StringConverter { private ProjectIndustryService service; - public ProjectIndustryStringConverter() { - + public ProjectIndustryStringConverter(ProjectIndustryService service) { + this.service = service; } - @PostConstruct - private void init() { - setInitialized(industry -> service.findById(industry.getId())); - setSuggestion(service::search); + @Override + public String toString(ProjectIndustryVo object) { + if (object == null) { + return ""; + } + return object.getCode() + " " + object.getName(); } + @Override + public ProjectIndustryVo fromString(String string) { + if (string == null || string.isEmpty()) { + return null; + } + return service.findByName(string); + } } \ No newline at end of file diff --git a/client/src/main/java/com/ecep/contract/converter/ProjectSaleTypeStringConverter.java b/client/src/main/java/com/ecep/contract/converter/ProjectSaleTypeStringConverter.java new file mode 100644 index 0000000..52035b4 --- /dev/null +++ b/client/src/main/java/com/ecep/contract/converter/ProjectSaleTypeStringConverter.java @@ -0,0 +1,24 @@ +package com.ecep.contract.converter; + +import com.ecep.contract.service.ProjectSaleTypeService; +import com.ecep.contract.vo.ProjectSaleTypeVo; + +import javafx.util.StringConverter; + +public class ProjectSaleTypeStringConverter extends StringConverter { + private final ProjectSaleTypeService service; + + public ProjectSaleTypeStringConverter(ProjectSaleTypeService service) { + this.service = service; + } + + @Override + public String toString(ProjectSaleTypeVo type) { + return type == null ? "" : type.getCode() + " " + type.getName(); + } + + @Override + public ProjectSaleTypeVo fromString(String string) { + return service.findByName(string); + } +} \ No newline at end of file diff --git a/client/src/main/java/com/ecep/contract/converter/ProjectTypeStringConverter.java b/client/src/main/java/com/ecep/contract/converter/ProjectTypeStringConverter.java new file mode 100644 index 0000000..97d5004 --- /dev/null +++ b/client/src/main/java/com/ecep/contract/converter/ProjectTypeStringConverter.java @@ -0,0 +1,46 @@ +package com.ecep.contract.converter; + +import com.ecep.contract.service.ProjectTypeService; +import com.ecep.contract.vo.ProjectTypeVo; +import javafx.util.StringConverter; + +/** + * ProjectTypeVo的StringConverter实现,用于JavaFX控件中的显示和转换 + */ +public class ProjectTypeStringConverter extends StringConverter { + private final ProjectTypeService service; + + /** + * 构造函数 + * + * @param service ProjectTypeService实例 + */ + public ProjectTypeStringConverter(ProjectTypeService service) { + this.service = service; + } + + /** + * 将ProjectTypeVo对象转换为字符串 + * + * @param object ProjectTypeVo对象 + * @return 转换后的字符串 + */ + @Override + public String toString(ProjectTypeVo object) { + return object == null ? "" : object.getName(); + } + + /** + * 将字符串转换为ProjectTypeVo对象 + * + * @param string 字符串 + * @return 转换后的ProjectTypeVo对象 + */ + @Override + public ProjectTypeVo fromString(String string) { + if (string == null || string.isEmpty()) { + return null; + } + return service.findByName(string); + } +} \ No newline at end of file diff --git a/client/src/main/java/com/ecep/contract/service/ProductTypeService.java b/client/src/main/java/com/ecep/contract/service/ProductTypeService.java index 6c3e400..cf12f81 100644 --- a/client/src/main/java/com/ecep/contract/service/ProductTypeService.java +++ b/client/src/main/java/com/ecep/contract/service/ProductTypeService.java @@ -2,6 +2,8 @@ package com.ecep.contract.service; import java.util.List; +import com.ecep.contract.converter.ProductTypeStringConverter; +import javafx.util.StringConverter; import org.springframework.cache.annotation.CacheConfig; import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.Cacheable; @@ -17,6 +19,8 @@ import com.ecep.contract.vo.ProductTypeVo; @Service @CacheConfig(cacheNames = "product-type") public class ProductTypeService extends QueryService { + + private final StringConverter stringConverter = new ProductTypeStringConverter(this); @Cacheable(key = "#p0") @Override public ProductTypeVo findById(Integer id) { @@ -61,4 +65,8 @@ public class ProductTypeService extends QueryService getStringConverter() { + return stringConverter; + } } diff --git a/client/src/main/java/com/ecep/contract/service/ProductUsageService.java b/client/src/main/java/com/ecep/contract/service/ProductUsageService.java index 14b3094..f38a59f 100644 --- a/client/src/main/java/com/ecep/contract/service/ProductUsageService.java +++ b/client/src/main/java/com/ecep/contract/service/ProductUsageService.java @@ -1,5 +1,7 @@ package com.ecep.contract.service; +import com.ecep.contract.converter.ProductUsageStringConverter; +import javafx.util.StringConverter; import org.springframework.cache.annotation.CacheConfig; import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.Cacheable; @@ -14,6 +16,7 @@ import com.ecep.contract.vo.ProductUsageVo; @Service @CacheConfig(cacheNames = "productUsageCache") public class ProductUsageService extends QueryService { + private final StringConverter stringConverter = new ProductUsageStringConverter(this); @Override @Cacheable(key = "#id") @@ -21,6 +24,10 @@ public class ProductUsageService extends QueryService findAll() { @@ -47,4 +54,9 @@ public class ProductUsageService extends QueryService getStringConverter() { + return stringConverter; + } } diff --git a/client/src/main/java/com/ecep/contract/service/ProjectIndustryService.java b/client/src/main/java/com/ecep/contract/service/ProjectIndustryService.java index 0586b62..788a67d 100644 --- a/client/src/main/java/com/ecep/contract/service/ProjectIndustryService.java +++ b/client/src/main/java/com/ecep/contract/service/ProjectIndustryService.java @@ -6,23 +6,33 @@ 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.util.ParamUtils; +import com.ecep.contract.converter.ProjectIndustryStringConverter; import com.ecep.contract.vm.ProjectIndustryViewModel; import com.ecep.contract.vo.ProjectIndustryVo; +import javafx.util.StringConverter; + @Service @CacheConfig(cacheNames = "project-industry") public class ProjectIndustryService extends QueryService { + private final StringConverter stringConverter = new ProjectIndustryStringConverter(this); + @Cacheable(key = "#p0") @Override public ProjectIndustryVo findById(Integer id) { return super.findById(id); } + public ProjectIndustryVo findByCode(String code) { + return findOneByProperty("code", code); + } + + public ProjectIndustryVo findByName(String name) { + return findOneByProperty("name", name); + } + @Cacheable(key = "'all'") @Override public List findAll() { @@ -41,11 +51,4 @@ public class ProjectIndustryService extends QueryService page = findAll(ParamUtils.builder().equals("code", code).build(), Pageable.ofSize(1)); - if (page.isEmpty()) { - return null; - } - return page.getContent().getFirst(); - } } diff --git a/client/src/main/java/com/ecep/contract/service/ProjectSaleTypeService.java b/client/src/main/java/com/ecep/contract/service/ProjectSaleTypeService.java index 9e97679..091e995 100644 --- a/client/src/main/java/com/ecep/contract/service/ProjectSaleTypeService.java +++ b/client/src/main/java/com/ecep/contract/service/ProjectSaleTypeService.java @@ -7,13 +7,18 @@ import org.springframework.cache.annotation.Caching; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; +import com.ecep.contract.converter.ProjectSaleTypeStringConverter; import com.ecep.contract.util.ParamUtils; import com.ecep.contract.vm.ProjectSaleTypeViewModel; import com.ecep.contract.vo.ProjectSaleTypeVo; +import javafx.util.StringConverter; + @Service @CacheConfig(cacheNames = "project-sale-type") public class ProjectSaleTypeService extends QueryService { + private final StringConverter stringConverter = new ProjectSaleTypeStringConverter(this); + @Cacheable(key = "#id") @Override public ProjectSaleTypeVo findById(Integer id) { @@ -28,15 +33,20 @@ public class ProjectSaleTypeService extends QueryService getStringConverter() { + return stringConverter; + } } diff --git a/client/src/main/java/com/ecep/contract/service/ProjectTypeService.java b/client/src/main/java/com/ecep/contract/service/ProjectTypeService.java index ad47254..49efd99 100644 --- a/client/src/main/java/com/ecep/contract/service/ProjectTypeService.java +++ b/client/src/main/java/com/ecep/contract/service/ProjectTypeService.java @@ -2,17 +2,22 @@ package com.ecep.contract.service; import org.springframework.cache.annotation.CacheConfig; import org.springframework.cache.annotation.Cacheable; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; -import com.ecep.contract.util.ParamUtils; +import com.ecep.contract.converter.ProjectTypeStringConverter; import com.ecep.contract.vm.ProjectTypeViewModel; import com.ecep.contract.vo.ProjectTypeVo; +import javafx.util.StringConverter; + @Service @CacheConfig(cacheNames = "project-type") public class ProjectTypeService extends QueryService { + private final StringConverter stringConverter; + + public ProjectTypeService() { + this.stringConverter = new ProjectTypeStringConverter(this); + } @Cacheable(key = "#p0") @Override @@ -21,19 +26,15 @@ public class ProjectTypeService extends QueryService page = findAll(ParamUtils.builder().equals("name", name).build(), Pageable.ofSize(1)); - if (page.isEmpty()) { - return null; - } - return page.getContent().getFirst(); + return findOneByProperty("name", name); } public ProjectTypeVo findByCode(String code) { - Page page = findAll(ParamUtils.builder().equals("code", code).build(), Pageable.ofSize(1)); - if (page.isEmpty()) { - return null; - } - return page.getContent().getFirst(); + return findOneByProperty("code", code); + } + + public StringConverter getStringConverter() { + return stringConverter; } } diff --git a/client/src/main/java/com/ecep/contract/service/QueryService.java b/client/src/main/java/com/ecep/contract/service/QueryService.java index 085c8f7..d9db68a 100644 --- a/client/src/main/java/com/ecep/contract/service/QueryService.java +++ b/client/src/main/java/com/ecep/contract/service/QueryService.java @@ -260,6 +260,9 @@ public class QueryService() { @Override public String toString(T object) { + if (object == null) { + return ""; + } if (object instanceof NamedEntity named) { return named.getName(); } diff --git a/client/src/main/java/com/ecep/contract/util/ComboBoxUtils.java b/client/src/main/java/com/ecep/contract/util/ComboBoxUtils.java index f4ab366..6fe663d 100644 --- a/client/src/main/java/com/ecep/contract/util/ComboBoxUtils.java +++ b/client/src/main/java/com/ecep/contract/util/ComboBoxUtils.java @@ -125,9 +125,7 @@ public class ComboBoxUtils { list.addAll(queryService.findAll()); comboBox.setItems(list); - - EntityStringConverter converter = new EntityStringConverter<>(list); - comboBox.setConverter(converter); + comboBox.setConverter(queryService.getStringConverter()); if (property != null) { // 从ComboBox选择到property的单向绑定 diff --git a/common/pom.xml b/common/pom.xml index 3adeaed..f916a1e 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -6,12 +6,12 @@ com.ecep.contract Contract-Manager - 0.0.122-SNAPSHOT + 0.0.126-SNAPSHOT com.ecep.contract common - 0.0.122-SNAPSHOT + 0.0.126-SNAPSHOT ${java.version} diff --git a/pom.xml b/pom.xml index 8d17172..5258b2f 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ com.ecep.contract Contract-Manager - 0.0.122-SNAPSHOT + 0.0.126-SNAPSHOT pom server diff --git a/server/pom.xml b/server/pom.xml index 59b2c61..70375a7 100644 --- a/server/pom.xml +++ b/server/pom.xml @@ -6,12 +6,12 @@ com.ecep.contract Contract-Manager - 0.0.122-SNAPSHOT + 0.0.126-SNAPSHOT com.ecep.contract server - 0.0.122-SNAPSHOT + 0.0.126-SNAPSHOT ${java.version} @@ -22,7 +22,7 @@ com.ecep.contract common - 0.0.122-SNAPSHOT + 0.0.126-SNAPSHOT org.springframework.boot