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

@@ -1,6 +1,14 @@
package com.ecep.contract.ds.company.service;
import com.ecep.contract.CompanyFileType;
import com.ecep.contract.VendorType;
import com.ecep.contract.constant.ServiceConstant;
import com.ecep.contract.util.SpecificationUtils;
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;
@@ -13,17 +21,24 @@ import com.ecep.contract.model.CompanyFileTypeLocal;
import com.fasterxml.jackson.databind.JsonNode;
import jakarta.annotation.Resource;
import org.springframework.util.StringUtils;
import java.util.Locale;
import java.util.Map;
@Lazy
@Service
@CacheConfig(cacheNames = "company-file-type")
public class CompanyFileTypeService
implements IEntityService<CompanyFileTypeLocal>, QueryService<CompanyFileTypeLocal> {
@Resource
private CompanyFileTypeLocalRepository companyFileTypeLocalRepository;
private CompanyFileTypeLocalRepository repository;
@Cacheable(key = "#p0")
@Override
public CompanyFileTypeLocal findById(Integer id) {
return companyFileTypeLocalRepository.findById(id).orElse(null);
return repository.findById(id).orElse(null);
}
@Override
@@ -32,27 +47,54 @@ public class CompanyFileTypeService
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"), CompanyFileType.valueOf(paramsNode.get("type").asText())));
}
// field
return findAll(spec, pageable);
}
@Cacheable(key = "'all-'+#p0.toLanguageTag()")
public Map<CompanyFileType, CompanyFileTypeLocal> findAll(Locale locale) {
return repository.getCompleteMapByLocal(locale.toLanguageTag());
}
@Override
public Page<CompanyFileTypeLocal> findAll(Specification<CompanyFileTypeLocal> spec, Pageable pageable) {
return companyFileTypeLocalRepository.findAll(spec, pageable);
return repository.findAll(spec, pageable);
}
@Override
public Specification<CompanyFileTypeLocal> getSpecification(String searchText) {
return null;
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(CompanyFileTypeLocal entity) {
companyFileTypeLocalRepository.delete(entity);
repository.delete(entity);
}
@Caching(evict = {
@CacheEvict(key = "#p0.id"),
@CacheEvict(key = "'all-'+#p0.getLang()")
})
@Override
public CompanyFileTypeLocal save(CompanyFileTypeLocal entity) {
return companyFileTypeLocalRepository.save(entity);
return repository.save(entity);
}
}

View File

@@ -3,6 +3,7 @@ package com.ecep.contract.ds.contract.service;
import java.util.Locale;
import java.util.Map;
import com.ecep.contract.VendorType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
@@ -40,12 +41,16 @@ public class ContractFileTypeService
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"), ContractFileType.valueOf(paramsNode.get("type").asText())));
}
// field
spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "lang", "value", "suggestFileName");
return findAll(spec, pageable);
}
@Cacheable(key = "'all-'+#p0.getLanguage()")
@Cacheable(key = "'all-'+#p0.toLanguageTag()")
public Map<ContractFileType, ContractFileTypeLocal> findAll(Locale locale) {
return repository.getCompleteMapByLocal(locale.toLanguageTag());
}

View File

@@ -1,4 +1,94 @@
package com.ecep.contract.ds.customer.service;
public class CompanyCustomerFileTypeService {
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.CompanyCustomerFileTypeLocalRepository;
import com.ecep.contract.model.CompanyCustomerFileTypeLocal;
import com.ecep.contract.util.SpecificationUtils;
import com.fasterxml.jackson.databind.JsonNode;
import jakarta.annotation.Resource;
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 java.util.Locale;
import java.util.Map;
@Lazy
@Service
@CacheConfig(cacheNames = "customer-file-type")
public class CompanyCustomerFileTypeService implements IEntityService<CompanyCustomerFileTypeLocal>, QueryService<CompanyCustomerFileTypeLocal> {
@Resource
private CompanyCustomerFileTypeLocalRepository repository;
@Cacheable(key = "#p0")
@Override
public CompanyCustomerFileTypeLocal findById(Integer id) {
return repository.findById(id).orElse(null);
}
@Override
public Page<CompanyCustomerFileTypeLocal> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<CompanyCustomerFileTypeLocal> 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
return findAll(spec, pageable);
}
@Cacheable(key = "'all-'+#p0.toLanguageTag()")
public Map<CustomerFileType, CompanyCustomerFileTypeLocal> findAll(Locale locale) {
return repository.getCompleteMapByLocal(locale.toLanguageTag());
}
@Override
public Page<CompanyCustomerFileTypeLocal> findAll(Specification<CompanyCustomerFileTypeLocal> spec, Pageable pageable) {
return repository.findAll(spec, pageable);
}
@Override
public Specification<CompanyCustomerFileTypeLocal> 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 CompanyCustomerFileTypeLocal save(CompanyCustomerFileTypeLocal entity) {
return repository.save(entity);
}
@Caching(evict = {
@CacheEvict(key = "#p0.id"),
@CacheEvict(key = "'all-'+#p0.getLang()")
})
@Override
public void delete(CompanyCustomerFileTypeLocal entity) {
repository.delete(entity);
}
}

View File

@@ -1,4 +1,97 @@
package com.ecep.contract.ds.project.service;
public class ProjectFileTypeService {
import com.ecep.contract.IEntityService;
import com.ecep.contract.ProjectFileType;
import com.ecep.contract.QueryService;
import com.ecep.contract.constant.ServiceConstant;
import com.ecep.contract.ds.project.repository.ProjectFileTypeLocalRepository;
import com.ecep.contract.model.ProjectFileTypeLocal;
import com.ecep.contract.util.SpecificationUtils;
import com.fasterxml.jackson.databind.JsonNode;
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 java.util.Locale;
import java.util.Map;
@Lazy
@Service
@CacheConfig(cacheNames = "project-file-type")
public class ProjectFileTypeService implements IEntityService<ProjectFileTypeLocal>, QueryService<ProjectFileTypeLocal> {
@Lazy
@Autowired
private ProjectFileTypeLocalRepository repository;
@Override
public Page<ProjectFileTypeLocal> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<ProjectFileTypeLocal> 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"), ProjectFileType.valueOf(paramsNode.get("type").asText())));
}
// field
spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "lang", "value");
return findAll(spec, pageable);
}
@Override
public ProjectFileTypeLocal findById(Integer id) {
return repository.findById(id).orElse(null);
}
@Override
public Page<ProjectFileTypeLocal> findAll(Specification<ProjectFileTypeLocal> spec, Pageable pageable) {
return repository.findAll(spec, pageable);
}
@Cacheable(key = "'all-'+#p0.toLanguageTag()")
public Map<ProjectFileType, ProjectFileTypeLocal> findAll(Locale locale) {
return repository.getCompleteMapByLocal(locale.toLanguageTag());
}
@Override
public Specification<ProjectFileTypeLocal> 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 ProjectFileTypeLocal save(ProjectFileTypeLocal entity) {
return repository.save(entity);
}
@Caching(evict = {
@CacheEvict(key = "#p0.id"),
@CacheEvict(key = "'all-'+#p0.getLang")
})
@Override
public void delete(ProjectFileTypeLocal entity) {
repository.delete(entity);
}
}

View File

@@ -2,6 +2,7 @@ package com.ecep.contract.ds.vendor.service;
import com.ecep.contract.*;
import com.ecep.contract.constant.CompanyVendorConstant;
import com.ecep.contract.constant.ServiceConstant;
import com.ecep.contract.ds.company.service.CompanyBasicService;
import com.ecep.contract.ds.other.service.SysConfService;
import com.ecep.contract.ds.vendor.repository.CompanyVendorRepository;
@@ -73,10 +74,14 @@ public class CompanyVendorService extends CompanyBasicService
@Override
public Page<CompanyVendor> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<CompanyVendor> spec = null;
if (paramsNode.has("searchText")) {
spec = getSpecification(paramsNode.get("searchText").asText());
if (paramsNode.has(ServiceConstant.KEY_SEARCH_TEXT)) {
spec = getSpecification(paramsNode.get(ServiceConstant.KEY_SEARCH_TEXT).asText());
}
// 添加额外的参数过滤
if (paramsNode.has("type")) {
VendorType type = VendorType.valueOf(paramsNode.get("type").asText());
spec = SpecificationUtils.and(spec, (root, query, builder) -> builder.equal(root.get("type"), type));
}
spec = SpecificationUtils.andParam(spec, paramsNode, "company", "catalog");
return findAll(spec, pageable);
}
@@ -184,7 +189,7 @@ public class CompanyVendorService extends CompanyBasicService
@Override
protected <T, F extends CompanyBasicFile<T>> boolean fillFileAsDefaultType(F dbFile, File file,
Consumer<String> status) {
Consumer<String> status) {
dbFile.setType((T) VendorFileType.General);
fillFile(dbFile, file, null, status);
companyVendorFileService.save((CompanyVendorFile) dbFile);
@@ -193,7 +198,7 @@ public class CompanyVendorService extends CompanyBasicService
@Override
protected <T, F extends CompanyBasicFile<T>> F fillFileType(File file, List<File> fileList,
Consumer<String> status) {
Consumer<String> status) {
CompanyVendorFile vendorFile = new CompanyVendorFile();
vendorFile.setType(VendorFileType.General);
vendorFile.setFilePath(file.getAbsolutePath());
@@ -213,7 +218,7 @@ public class CompanyVendorService extends CompanyBasicService
@Override
protected <T, F extends CompanyBasicFile<T>> boolean fillFileAsEvaluationFile(F customerFile, File file,
List<File> fileList, Consumer<String> status) {
List<File> fileList, Consumer<String> status) {
boolean modified = super.fillFileAsEvaluationFile(customerFile, file, fileList, status);
// 当评价表有日期,并且未设审核时
boolean valid = isArchiveFile(customerFile.getFilePath()) && customerFile.getSignDate() != null;
@@ -433,14 +438,6 @@ public class CompanyVendorService extends CompanyBasicService
return vendorClassRepository.save(catalog);
}
@Cacheable(key = "'types'+#p0")
public List<VendorTypeLocal> findAllTypes(String lang) {
Map<VendorType, VendorTypeLocal> map = vendorTypeLocalRepository.getCompleteMapByLocal(lang);
List<VendorTypeLocal> list = new ArrayList<>(map.values());
list.sort((o1, o2) -> Objects.compare(o1.getValue(), o2.getValue(), String::compareTo));
return list;
}
@Caching(evict = {
@CacheEvict(key = "'type-'+#p0.lang"),
})

View File

@@ -3,6 +3,7 @@ package com.ecep.contract.ds.vendor.service;
import java.util.Locale;
import java.util.Map;
import com.ecep.contract.VendorType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
@@ -43,6 +44,10 @@ public class VendorFileTypeService implements IEntityService<VendorFileTypeLocal
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"), VendorType.valueOf(paramsNode.get("type").asText())));
}
// field
spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "lang", "value");
return findAll(spec, pageable);
@@ -71,10 +76,10 @@ public class VendorFileTypeService implements IEntityService<VendorFileTypeLocal
}
return (root, query, builder) -> {
return
// builder.or(
builder.like(root.get("type"), "%" + searchText + "%")
// )
;
// builder.or(
builder.like(root.get("type"), "%" + searchText + "%")
// )
;
};
}

View File

@@ -39,6 +39,10 @@ public class VendorTypeService implements IEntityService<VendorTypeLocal>, Query
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"), VendorType.valueOf(paramsNode.get("type").asText())));
}
// field
spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "lang", "value");
return findAll(spec, pageable);
@@ -67,10 +71,10 @@ public class VendorTypeService implements IEntityService<VendorTypeLocal>, Query
}
return (root, query, builder) -> {
return
// builder.or(
builder.like(root.get("type"), "%" + searchText + "%")
// )
;
// builder.or(
builder.like(root.get("type"), "%" + searchText + "%")
// )
;
};
}