refactor(vo): 重构VO类及相关模型,添加Voable接口实现

feat(constant): 添加WebSocket错误码常量
docs(model): 为模型类添加注释
fix(service): 修复ProductUsageService缓存键问题
refactor(converter): 重构字符串转换器,移除EntityStringConverter依赖
feat(tab): 添加ComboBoxUtils工具类,优化下拉框初始化
style: 移除无用导入和字段
This commit is contained in:
2025-09-22 23:11:21 +08:00
parent 8aac509e51
commit 866e08224a
84 changed files with 1061 additions and 285 deletions

View File

@@ -1,5 +1,10 @@
package com.ecep.contract.service;
import com.ecep.contract.converter.BankStringConverter;
import com.ecep.contract.util.ParamUtils;
import com.ecep.contract.vm.BankViewModel;
import com.ecep.contract.vo.BankVo;
import javafx.util.StringConverter;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
@@ -8,15 +13,12 @@ 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.vm.BankViewModel;
import com.ecep.contract.vo.BankVo;
import javafx.util.StringConverter;
@Service
@CacheConfig(cacheNames = "bank")
public class BankService extends QueryService<BankVo, BankViewModel> {
private final BankStringConverter stringConverter = new BankStringConverter(this);
@Cacheable(key = "#p0")
@Override
public BankVo findById(Integer id) {
@@ -31,32 +33,20 @@ public class BankService extends QueryService<BankVo, BankViewModel> {
return page.getContent().getFirst();
}
@Caching(evict = { @CacheEvict(key = "#p0.id") })
@Caching(evict = {@CacheEvict(key = "#p0.id")})
@Override
public BankVo save(BankVo entity) {
return super.save(entity);
}
@Caching(evict = { @CacheEvict(key = "#p0.id") })
@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() {
public BankStringConverter getStringConverter() {
return stringConverter;
}

View File

@@ -6,6 +6,8 @@ import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import com.ecep.contract.util.ParamUtils;
import com.ecep.contract.vo.CompanyFileTypeLocalVo;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Pageable;
@@ -17,13 +19,11 @@ import com.ecep.contract.vm.CompanyFileTypeLocalViewModel;
@Service
@CacheConfig(cacheNames = "company-file-type")
public class CompanyFileTypeService extends QueryService<CompanyFileTypeLocal, CompanyFileTypeLocalViewModel> {
public class CompanyFileTypeService extends QueryService<CompanyFileTypeLocalVo, CompanyFileTypeLocalViewModel> {
@Cacheable
public Map<CompanyFileType, CompanyFileTypeLocal> findAll(Locale locale) {
Map<String, Object> params = new HashMap<>();
params.put("lang", locale.toLanguageTag());
return findAll(params, Pageable.unpaged()).stream()
.collect(Collectors.toMap(CompanyFileTypeLocal::getType, Function.identity()));
public Map<CompanyFileType, CompanyFileTypeLocalVo> findAll(Locale locale) {
return findAll(ParamUtils.builder().equals("lang", locale.toLanguageTag()).build(), Pageable.unpaged()).stream()
.collect(Collectors.toMap(CompanyFileTypeLocalVo::getType, Function.identity()));
}
}

View File

@@ -6,6 +6,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javafx.util.StringConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
@@ -210,4 +211,8 @@ public class CompanyService extends QueryService<CompanyVo, CompanyViewModel> {
return retrieved;
}
@Override
public StringConverter<CompanyVo> getStringConverter() {
return super.getStringConverter();
}
}

View File

@@ -1,20 +1,25 @@
package com.ecep.contract.service;
import java.util.List;
import com.ecep.contract.converter.ContractGroupStringConverter;
import com.ecep.contract.util.ParamUtils;
import com.ecep.contract.vm.ContractGroupViewModel;
import com.ecep.contract.vo.ContractGroupVo;
import javafx.util.StringConverter;
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.Pageable;
import org.springframework.stereotype.Service;
import com.ecep.contract.vm.ContractGroupViewModel;
import com.ecep.contract.vo.ContractGroupVo;
import java.util.List;
@Service
@CacheConfig(cacheNames = "contract-group")
public class ContractGroupService extends QueryService<ContractGroupVo, ContractGroupViewModel> {
private final ContractGroupStringConverter converter = new ContractGroupStringConverter(this);
@Override
@Cacheable(key = "#p0")
public ContractGroupVo findById(Integer id) {
@@ -22,19 +27,14 @@ public class ContractGroupService extends QueryService<ContractGroupVo, Contract
}
public ContractGroupVo findByCode(String code) {
try {
return async("findByCode", code, String.class).handle((response, ex) -> {
if (ex != null) {
throw new RuntimeException("远程方法+findByCode+调用失败", ex);
}
ContractGroupVo newEntity = createNewEntity();
return updateValue(newEntity, response);
}).get();
} catch (Exception e) {
throw new RuntimeException("查询实体失败" + code, e);
}
return findAll(ParamUtils.builder().equals("code", code).build(), Pageable.ofSize(1)).stream().findFirst().orElse(null);
}
public ContractGroupVo findByName(String name) {
return findAll(ParamUtils.builder().equals("name", name).build(), Pageable.ofSize(1)).stream().findFirst().orElse(null);
}
@Cacheable(key = "'groups'")
@Override
public List<ContractGroupVo> findAll() {
@@ -56,4 +56,9 @@ public class ContractGroupService extends QueryService<ContractGroupVo, Contract
public void delete(ContractGroupVo entity) {
super.delete(entity);
}
@Override
public StringConverter<ContractGroupVo> getStringConverter() {
return converter;
}
}

View File

@@ -2,6 +2,7 @@ package com.ecep.contract.service;
import java.util.List;
import com.ecep.contract.converter.ContractTypeStringConverter;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
@@ -16,6 +17,8 @@ import javafx.util.StringConverter;
@Service
@CacheConfig(cacheNames = "contract-type")
public class ContractTypeService extends QueryService<ContractTypeVo, ContractTypeViewModel> {
private final ContractTypeStringConverter stringConverter = new ContractTypeStringConverter(this);
@Cacheable(key = "#p0")
@Override
public ContractTypeVo findById(Integer id) {
@@ -70,19 +73,7 @@ public class ContractTypeService extends QueryService<ContractTypeVo, ContractTy
}
@Override
public StringConverter<ContractTypeVo> getStringConverter() {
return new StringConverter<ContractTypeVo>() {
@Override
public String toString(ContractTypeVo object) {
return object.getCode() + " " + object.getCatalog() + " " + object.getName() + " " + object.getTitle()
+ "("
+ object.getDirection() + ")";
}
@Override
public ContractTypeVo fromString(String string) {
return findByCode(string);
}
};
public ContractTypeStringConverter getStringConverter() {
return stringConverter;
}
}

View File

@@ -1,6 +1,8 @@
package com.ecep.contract.service;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
@@ -10,13 +12,21 @@ import com.ecep.contract.vm.DeliverySignMethodViewModel;
import com.ecep.contract.vo.DeliverySignMethodVo;
import com.ecep.contract.vo.ProjectSaleTypeVo;
import java.util.List;
@Service
@CacheConfig(cacheNames = "delivery-sign-method")
public class DeliverySignMethodService extends QueryService<DeliverySignMethodVo, DeliverySignMethodViewModel> {
@Cacheable(key = "#id")
@Override
public DeliverySignMethodVo findById(Integer id) {
return super.findById(id);
}
/**
* 根据销售类型和编码查询发货方式
*
*
* @param saleType
* @param code
* @return
@@ -29,4 +39,23 @@ public class DeliverySignMethodService extends QueryService<DeliverySignMethodVo
}
return page.stream().filter(v -> v.getCode().equals(code)).findFirst().orElse(null);
}
@Cacheable(key = "'all'")
@Override
public List<DeliverySignMethodVo> findAll() {
return super.findAll();
}
@CacheEvict(allEntries = true)
@Override
public DeliverySignMethodVo save(DeliverySignMethodVo entity) {
return super.save(entity);
}
@CacheEvict(allEntries = true)
@Override
public void delete(DeliverySignMethodVo entity) {
super.delete(entity);
}
}

View File

@@ -22,7 +22,7 @@ public class ProductUsageService extends QueryService<ProductUsageVo, ProductUsa
}
@Override
@Cacheable(unless = "'all'")
@Cacheable(key = "'all'")
public java.util.List<ProductUsageVo> findAll() {
return super.findAll();
}

View File

@@ -1,5 +1,23 @@
package com.ecep.contract.service;
import com.ecep.contract.PageArgument;
import com.ecep.contract.PageContent;
import com.ecep.contract.WebSocketClientService;
import com.ecep.contract.model.IdentityEntity;
import com.ecep.contract.model.NamedEntity;
import com.ecep.contract.util.ParamUtils;
import com.ecep.contract.vm.IdentityViewModel;
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;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
@@ -7,25 +25,6 @@ import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.function.Supplier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import com.ecep.contract.PageArgument;
import com.ecep.contract.PageContent;
import com.ecep.contract.WebSocketClientService;
import com.ecep.contract.model.IdentityEntity;
import com.ecep.contract.util.ParamUtils;
import com.ecep.contract.vm.IdentityViewModel;
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;
public class QueryService<T extends IdentityEntity, TV extends IdentityViewModel<T>>
implements ViewModelService<T, TV> {
// 添加日志记录器
@@ -166,7 +165,7 @@ public class QueryService<T extends IdentityEntity, TV extends IdentityViewModel
return pageContent.toPage();
} catch (Exception e) {
// 处理转换过程中的异常包装为RuntimeException并附带响应内容
throw new RuntimeException(response.toString(), e);
throw new RuntimeException("响应结果转换失败, JSON = " + response.toString(), e);
}
});
}
@@ -189,7 +188,7 @@ public class QueryService<T extends IdentityEntity, TV extends IdentityViewModel
return asyncFindAll(params, pageable).get();
} catch (Exception e) {
// 处理异步查询过程中的任何异常,转换为运行时异常抛出
throw new RuntimeException("查询所有实体失败", e);
throw new RuntimeException("查询失败, 参数:" + params, e);
}
}
@@ -261,6 +260,9 @@ public class QueryService<T extends IdentityEntity, TV extends IdentityViewModel
return new StringConverter<>() {
@Override
public String toString(T object) {
if (object instanceof NamedEntity named) {
return named.getName();
}
return object.toString();
}

View File

@@ -1,15 +1,19 @@
package com.ecep.contract.service;
import com.ecep.contract.model.VendorTypeLocal;
import com.ecep.contract.vm.VendorTypeLocalViewModel;
import com.ecep.contract.vo.VendorTypeLocalVo;
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 java.util.List;
import com.ecep.contract.VendorType;
import com.ecep.contract.util.ParamUtils;
import com.ecep.contract.vm.VendorTypeLocalViewModel;
import com.ecep.contract.vo.VendorTypeLocalVo;
@Service
@CacheConfig(cacheNames = "vendor-type")
@@ -20,19 +24,25 @@ public class VendorTypeService extends QueryService<VendorTypeLocalVo, VendorTyp
return super.findById(id);
}
@Cacheable(key = "'type-'+#p0")
public VendorTypeLocalVo findByType(VendorType type) {
return findAll(ParamUtils.builder().equals("type", type).build(), Pageable.ofSize(1)).stream().findFirst()
.orElse(null);
}
@Cacheable(key = "'all'")
@Override
public List<VendorTypeLocalVo> findAll() {
return super.findAll();
}
@Caching(put = {@CachePut(key = "#p0.id"), @CachePut(key = "'all'")})
@Caching(put = { @CachePut(key = "#p0.id"), @CachePut(key = "'type-'+#p0.type"), @CachePut(key = "'all'") })
@Override
public VendorTypeLocalVo save(VendorTypeLocalVo entity) {
return super.save(entity);
}
@Caching(put = {@CachePut(key = "#p0.id"), @CachePut(key = "'all'")})
@Caching(evict = { @CacheEvict(key = "#p0.id"), @CacheEvict(key = "'type-'+#p0.type"), @CacheEvict(key = "'all'") })
@Override
public void delete(VendorTypeLocalVo entity) {
super.delete(entity);