feat: 实现文件类型枚举的本地化支持

新增文件类型枚举的本地化功能,包括供应商、项目、公司、合同和客户文件类型。添加了相关的SQL表结构、Repository、Service、ViewModel和StringConverter实现。同时更新了文档说明如何创建和使用枚举类型的本地化功能。

修改了客户文件类型的相关代码,统一使用CustomerFileTypeLocalVo替代原有的CompanyCustomerFileTypeLocal,优化了代码结构和一致性。添加了文件类型枚举的缓存支持,提高了性能。

更新了create_enum.md文档,详细说明了文件类型枚举本地化的实现方式和相关组件清单。
This commit is contained in:
2025-09-23 22:34:59 +08:00
parent 4b8c1d4038
commit 57fbae90c5
27 changed files with 633 additions and 42 deletions

View File

@@ -0,0 +1,20 @@
package com.ecep.contract.ds.customer.repository;
import org.springframework.stereotype.Repository;
import com.ecep.contract.CustomerFileType;
import com.ecep.contract.ds.other.repository.BaseEnumEntityRepository;
import com.ecep.contract.model.CustomerFileTypeLocal;
@Repository
public interface CustomerFileTypeLocalRepository extends BaseEnumEntityRepository<CustomerFileType, CustomerFileTypeLocal, Integer> {
@Override
default CustomerFileType[] getEnumConstants() {
return CustomerFileType.values();
}
@Override
default CustomerFileTypeLocal newEntity() {
return new CustomerFileTypeLocal();
}
}

View File

@@ -0,0 +1,98 @@
package com.ecep.contract.ds.customer.service;
import java.util.Locale;
import java.util.Map;
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.CustomerFileType;
import com.ecep.contract.IEntityService;
import com.ecep.contract.QueryService;
import com.ecep.contract.constant.ServiceConstant;
import com.ecep.contract.ds.customer.repository.CustomerFileTypeLocalRepository;
import com.ecep.contract.model.CustomerFileTypeLocal;
import com.ecep.contract.util.SpecificationUtils;
import com.fasterxml.jackson.databind.JsonNode;
@Lazy
@Service
@CacheConfig(cacheNames = "customer-file-type")
public class CustomerFileTypeService implements IEntityService<CustomerFileTypeLocal>, QueryService<CustomerFileTypeLocal> {
@Lazy
@Autowired
private CustomerFileTypeLocalRepository repository;
@Override
public Page<CustomerFileTypeLocal> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<CustomerFileTypeLocal> spec = null;
if (paramsNode.has(ServiceConstant.KEY_SEARCH_TEXT)) {
spec = getSpecification(paramsNode.get(ServiceConstant.KEY_SEARCH_TEXT).asText());
}
if (paramsNode.has("type")) {
spec = SpecificationUtils.and(spec, (root, query, builder) -> builder.equal(root.get("type"), CustomerFileType.valueOf(paramsNode.get("type").asText())));
}
// field
spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "lang", "value");
return findAll(spec, pageable);
}
@Cacheable(key = "#p0")
@Override
public CustomerFileTypeLocal findById(Integer id) {
return repository.findById(id).orElse(null);
}
@Override
public Page<CustomerFileTypeLocal> findAll(Specification<CustomerFileTypeLocal> spec, Pageable pageable) {
return repository.findAll(spec, pageable);
}
@Cacheable(key = "'all-'+#p0.toLanguageTag()")
public Map<CustomerFileType, CustomerFileTypeLocal> findAll(Locale locale) {
return repository.getCompleteMapByLocal(locale.toLanguageTag());
}
@Override
public Specification<CustomerFileTypeLocal> getSpecification(String searchText) {
if (!StringUtils.hasText(searchText)) {
return null;
}
return (root, query, builder) -> {
return
// builder.or(
builder.like(root.get("type"), "%" + searchText + "%")
// )
;
};
}
@Caching(evict = {
@CacheEvict(key = "#p0.id"),
@CacheEvict(key = "'all-'+#p0.getLang()")
})
@Override
public void delete(CustomerFileTypeLocal entity) {
repository.delete(entity);
}
@Caching(evict = {
@CacheEvict(key = "#p0.id"),
@CacheEvict(key = "'all-'+#p0.getLang()")
})
@Override
public CustomerFileTypeLocal save(CustomerFileTypeLocal entity) {
return repository.save(entity);
}
}