Compare commits
2 Commits
866e08224a
...
39dbce013f
| Author | SHA1 | Date | |
|---|---|---|---|
| 39dbce013f | |||
| b84e011857 |
@@ -124,29 +124,34 @@ public class ComboBoxUtils {
|
|||||||
}
|
}
|
||||||
list.addAll(queryService.findAll());
|
list.addAll(queryService.findAll());
|
||||||
comboBox.setItems(list);
|
comboBox.setItems(list);
|
||||||
// 从ComboBox选择到property的单向绑定
|
|
||||||
comboBox.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
|
|
||||||
property.setValue(newValue != null ? newValue.getId() : null);
|
|
||||||
});
|
|
||||||
// 从property到ComboBox的单向绑定
|
|
||||||
property.addListener((observable, oldValue, newValue) -> {
|
|
||||||
if (newValue == null) {
|
|
||||||
comboBox.getSelectionModel().clearSelection();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
list.stream()
|
|
||||||
.filter(item -> item != null && newValue.equals(item.getId()))
|
|
||||||
.findFirst()
|
|
||||||
.ifPresent(comboBox.getSelectionModel()::select);
|
|
||||||
});
|
|
||||||
EntityStringConverter<T> converter = new EntityStringConverter<>(list);
|
EntityStringConverter<T> converter = new EntityStringConverter<>(list);
|
||||||
comboBox.setConverter(converter);
|
comboBox.setConverter(converter);
|
||||||
// 初始化ComboBox的值
|
|
||||||
if (property.getValue() != null) {
|
if (property != null) {
|
||||||
list.stream()
|
// 从ComboBox选择到property的单向绑定
|
||||||
.filter(item -> item != null && property.getValue().equals(item.getId()))
|
comboBox.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
|
||||||
.findFirst()
|
property.setValue(newValue != null ? newValue.getId() : null);
|
||||||
.ifPresent(comboBox.getSelectionModel()::select);
|
});
|
||||||
|
// 从property到ComboBox的单向绑定
|
||||||
|
property.addListener((observable, oldValue, newValue) -> {
|
||||||
|
if (newValue == null) {
|
||||||
|
comboBox.getSelectionModel().clearSelection();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
list.stream()
|
||||||
|
.filter(item -> item != null && newValue.equals(item.getId()))
|
||||||
|
.findFirst()
|
||||||
|
.ifPresent(comboBox.getSelectionModel()::select);
|
||||||
|
});
|
||||||
|
|
||||||
|
// 初始化ComboBox的值
|
||||||
|
if (property.getValue() != null) {
|
||||||
|
list.stream()
|
||||||
|
.filter(item -> item != null && property.getValue().equals(item.getId()))
|
||||||
|
.findFirst()
|
||||||
|
.ifPresent(comboBox.getSelectionModel()::select);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,7 +188,7 @@ public class ComboBoxUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static <K extends Enum<?>, T extends BaseEnumEntity<K>> void bindComboBox(ComboBox<T> comboBox,
|
public static <K extends Enum<?>, T extends BaseEnumEntity<K>> void bindComboBox(ComboBox<T> comboBox,
|
||||||
Property<K> property, List<T> dataSet) {
|
Property<K> property, List<T> dataSet) {
|
||||||
property.addListener((observable, oldValue, newValue) -> {
|
property.addListener((observable, oldValue, newValue) -> {
|
||||||
dataSet.stream().filter(l -> l.getType() == newValue).findFirst().ifPresent(comboBox::setValue);
|
dataSet.stream().filter(l -> l.getType() == newValue).findFirst().ifPresent(comboBox::setValue);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package com.ecep.contract.converter;
|
||||||
|
|
||||||
|
import com.ecep.contract.model.BaseEnumEntity;
|
||||||
|
import javafx.util.StringConverter;
|
||||||
|
|
||||||
|
public class EnumEntityStringConverter<E extends Enum<?>, T extends BaseEnumEntity<E>> extends StringConverter<T> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString(T object) {
|
||||||
|
return object == null ? "" : object.getValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T fromString(String string) {
|
||||||
|
return null;
|
||||||
|
// return service.findByName(string);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package com.ecep.contract.converter;
|
||||||
|
|
||||||
|
import com.ecep.contract.Desktop;
|
||||||
|
import com.ecep.contract.service.VendorTypeService;
|
||||||
|
import com.ecep.contract.vo.VendorTypeLocalVo;
|
||||||
|
import javafx.util.StringConverter;
|
||||||
|
|
||||||
|
public class VendorTypeStringConverter extends StringConverter<VendorTypeLocalVo> {
|
||||||
|
private final VendorTypeService service;
|
||||||
|
|
||||||
|
public VendorTypeStringConverter(VendorTypeService service) {
|
||||||
|
this.service = service;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString(VendorTypeLocalVo object) {
|
||||||
|
return object.getValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VendorTypeLocalVo fromString(String string) {
|
||||||
|
return service.findByLocaleAndValue(Desktop.instance.getActiveEmployee().localeProperty().get(), string);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,19 +1,17 @@
|
|||||||
package com.ecep.contract.service;
|
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.CachePut;
|
|
||||||
import org.springframework.cache.annotation.Cacheable;
|
|
||||||
import org.springframework.cache.annotation.Caching;
|
|
||||||
import org.springframework.data.domain.Pageable;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import com.ecep.contract.VendorType;
|
import com.ecep.contract.VendorType;
|
||||||
|
import com.ecep.contract.converter.VendorTypeStringConverter;
|
||||||
import com.ecep.contract.util.ParamUtils;
|
import com.ecep.contract.util.ParamUtils;
|
||||||
import com.ecep.contract.vm.VendorTypeLocalViewModel;
|
import com.ecep.contract.vm.VendorTypeLocalViewModel;
|
||||||
import com.ecep.contract.vo.VendorTypeLocalVo;
|
import com.ecep.contract.vo.VendorTypeLocalVo;
|
||||||
|
import javafx.util.StringConverter;
|
||||||
|
import org.springframework.cache.annotation.*;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@CacheConfig(cacheNames = "vendor-type")
|
@CacheConfig(cacheNames = "vendor-type")
|
||||||
@@ -36,15 +34,27 @@ public class VendorTypeService extends QueryService<VendorTypeLocalVo, VendorTyp
|
|||||||
return super.findAll();
|
return super.findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Caching(put = { @CachePut(key = "#p0.id"), @CachePut(key = "'type-'+#p0.type"), @CachePut(key = "'all'") })
|
@Caching(put = {@CachePut(key = "#p0.id"), @CachePut(key = "'type-'+#p0.type"), @CachePut(key = "'all'")})
|
||||||
@Override
|
@Override
|
||||||
public VendorTypeLocalVo save(VendorTypeLocalVo entity) {
|
public VendorTypeLocalVo save(VendorTypeLocalVo entity) {
|
||||||
return super.save(entity);
|
return super.save(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Caching(evict = { @CacheEvict(key = "#p0.id"), @CacheEvict(key = "'type-'+#p0.type"), @CacheEvict(key = "'all'") })
|
@Caching(evict = {@CacheEvict(key = "#p0.id"), @CacheEvict(key = "'type-'+#p0.type"), @CacheEvict(key = "'all'")})
|
||||||
@Override
|
@Override
|
||||||
public void delete(VendorTypeLocalVo entity) {
|
public void delete(VendorTypeLocalVo entity) {
|
||||||
super.delete(entity);
|
super.delete(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private StringConverter<VendorTypeLocalVo> stringConverter = new VendorTypeStringConverter(this);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StringConverter<VendorTypeLocalVo> getStringConverter() {
|
||||||
|
return stringConverter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public VendorTypeLocalVo findByLocaleAndValue(Locale locale, String string) {
|
||||||
|
return findAll(ParamUtils.builder().equals("lang", locale.toLanguageTag()).equals("value", string).build(), Pageable.ofSize(1))
|
||||||
|
.stream().findFirst().orElse(null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
85
server/src/main/java/com/ecep/contract/ds/vendor/service/VendorCatalogService.java
vendored
Normal file
85
server/src/main/java/com/ecep/contract/ds/vendor/service/VendorCatalogService.java
vendored
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
package com.ecep.contract.ds.vendor.service;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
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.context.annotation.Lazy;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.data.jpa.domain.Specification;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
import com.ecep.contract.IEntityService;
|
||||||
|
import com.ecep.contract.QueryService;
|
||||||
|
import com.ecep.contract.constant.ServiceConstant;
|
||||||
|
import com.ecep.contract.ds.vendor.repository.VendorClassRepository;
|
||||||
|
import com.ecep.contract.model.VendorCatalog;
|
||||||
|
import com.ecep.contract.util.SpecificationUtils;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 供应商目录服务类
|
||||||
|
* 提供对供应商目录的查询、创建、更新和删除操作
|
||||||
|
*/
|
||||||
|
@Lazy
|
||||||
|
@Service
|
||||||
|
@CacheConfig(cacheNames = "vendor-catalog")
|
||||||
|
public class VendorCatalogService implements IEntityService<VendorCatalog>, QueryService<VendorCatalog> {
|
||||||
|
@Lazy
|
||||||
|
@Autowired
|
||||||
|
private VendorClassRepository repository;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Page<VendorCatalog> findAll(JsonNode paramsNode, Pageable pageable) {
|
||||||
|
Specification<VendorCatalog> spec = null;
|
||||||
|
if (paramsNode.has(ServiceConstant.KEY_SEARCH_TEXT)) {
|
||||||
|
spec = getSpecification(paramsNode.get(ServiceConstant.KEY_SEARCH_TEXT).asText());
|
||||||
|
}
|
||||||
|
|
||||||
|
// field
|
||||||
|
spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "name", "code", "parentId");
|
||||||
|
return findAll(spec, pageable);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Cacheable(key = "#p0")
|
||||||
|
@Override
|
||||||
|
public VendorCatalog findById(Integer id) {
|
||||||
|
return repository.findById(id).orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Page<VendorCatalog> findAll(Specification<VendorCatalog> spec, Pageable pageable) {
|
||||||
|
return repository.findAll(spec, pageable);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Specification<VendorCatalog> getSpecification(String searchText) {
|
||||||
|
if (!StringUtils.hasText(searchText)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return (root, query, builder) -> {
|
||||||
|
return builder.or(
|
||||||
|
builder.like(root.get("name"), "%" + searchText + "%"),
|
||||||
|
builder.like(root.get("code"), "%" + searchText + "%"));
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Caching(evict = {
|
||||||
|
@CacheEvict(key = "#p0.id")
|
||||||
|
})
|
||||||
|
@Override
|
||||||
|
public void delete(VendorCatalog entity) {
|
||||||
|
repository.delete(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Caching(evict = {
|
||||||
|
@CacheEvict(key = "#p0.id")
|
||||||
|
})
|
||||||
|
@Override
|
||||||
|
public VendorCatalog save(VendorCatalog entity) {
|
||||||
|
return repository.save(entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user