Compare commits

...

2 Commits

Author SHA1 Message Date
515b255567 feat: 添加供应商类型本地化支持及优化表格单元格显示
refactor: 重构供应商类型相关服务及控制器
fix: 修复供应商类型表格单元格初始化问题
style: 优化代码格式及导入顺序
2025-09-23 14:12:09 +08:00
386b6d01b4 feat: 添加项目文件和客户文件类型服务类
添加 ProjectFileTypeService 和 CompanyCustomerFileTypeService 服务类,用于处理文件和客户类型相关逻辑
2025-09-23 14:11:49 +08:00
22 changed files with 329 additions and 141 deletions

View File

@@ -103,6 +103,9 @@ public class AsyncUpdateTableCell<V, K, T extends IdentityEntity> extends javafx
*/
protected T initialize() {
K k = getItem();
if (k == null) {
return null;
}
if (k instanceof Integer id) {
return getService().findById(id);
}

View File

@@ -4,7 +4,6 @@ import com.ecep.contract.SpringApp;
import com.ecep.contract.VendorType;
import com.ecep.contract.service.VendorTypeService;
import com.ecep.contract.vo.VendorTypeLocalVo;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.util.Callback;
@@ -23,8 +22,8 @@ public class VendorTypeTableCell<T> extends AsyncUpdateTableCell<T, VendorType,
return param -> new VendorTypeTableCell<>(service);
}
public VendorTypeTableCell() {
this.vendorTypeService = SpringApp.getBean(VendorTypeService.class);
}
public VendorTypeTableCell(VendorTypeService service) {
@@ -42,7 +41,13 @@ public class VendorTypeTableCell<T> extends AsyncUpdateTableCell<T, VendorType,
@Override
protected VendorTypeLocalVo initialize() {
VendorType item = getItem();
return getServiceBean().findByType(item);
VendorTypeLocalVo localVo = getServiceBean().findByType(item);
System.out.println("item = " + item + ", localVo = " + getServiceBean().getStringConverter().toString(localVo));
return localVo;
}
@Override
public String format(VendorTypeLocalVo entity) {
return getServiceBean().getStringConverter().toString(entity);
}
}

View File

@@ -22,9 +22,6 @@ public class CompanyVendorManagerSkin
@Setter
private CompanyService companyService;
@Setter
private CompanyVendorService companyVendorService;
public CompanyVendorManagerSkin(CompanyVendorManagerWindowController controller) {
super(controller);
}
@@ -37,10 +34,7 @@ public class CompanyVendorManagerSkin
}
public CompanyVendorService getCompanyVendorService() {
if (companyVendorService == null) {
companyVendorService = getBean(CompanyVendorService.class);
}
return companyVendorService;
return controller.getViewModelService();
}
@Override
@@ -57,16 +51,17 @@ public class CompanyVendorManagerSkin
ComboBoxUtils.initialComboBox(controller.typeSelector, null, getBean(VendorTypeService.class), true);
controller.idColumn.setCellValueFactory(param -> param.getValue().getId());
// id column
controller.codeColumn.setCellValueFactory(param -> param.getValue().getCode());
// catalog column
controller.catalogColumn.setCellValueFactory(param -> param.getValue().getCatalog());
controller.catalogColumn.setCellFactory(VendorCatalogTableCell.forTableColumn(getBean(VendorCatalogService.class)));
// type column
controller.typeColumn.setCellValueFactory(param -> param.getValue().getType());
controller.typeColumn.setCellFactory(VendorTypeTableCell.forTableColumn(getBean(VendorTypeService.class)));
controller.purchaseColumn.setCellValueFactory(param -> param.getValue().getPurchase());
// company column
controller.companyColumn.setCellValueFactory(param -> param.getValue().getCompany());
controller.companyColumn.setCellFactory(CompanyTableCell.forTableColumn(getCompanyService()));

View File

@@ -115,7 +115,6 @@ public class CompanyVendorManagerWindowController
protected CompanyVendorManagerSkin createDefaultSkin() {
CompanyVendorManagerSkin skin = new CompanyVendorManagerSkin(this);
skin.setCompanyService(companyService);
skin.setCompanyVendorService(companyVendorService);
return skin;
}

View File

@@ -11,6 +11,7 @@ import com.ecep.contract.controller.tab.AbstEntityBasedTabSkin;
import com.ecep.contract.model.VendorTypeLocal;
import com.ecep.contract.service.CompanyContactService;
import com.ecep.contract.service.CompanyVendorService;
import com.ecep.contract.service.VendorTypeService;
import com.ecep.contract.util.UITools;
import com.ecep.contract.vm.CompanyVendorViewModel;
import com.ecep.contract.vm.CompanyViewModel;
@@ -51,10 +52,7 @@ public class CompanyVendorTabSkinBase
controller.developDateField.setConverter(converter);
controller.developDateField.valueProperty().bindBidirectional(viewModel.getDevelopDate());
List<VendorTypeLocal> vendorTypeLocals = getCompanyVendorService()
.findAllTypes(controller.getLocale().toLanguageTag());
ComboBoxUtils.initialComboBox(controller.catalogField, vendorTypeLocals, true);
ComboBoxUtils.bindComboBox(controller.catalogField, viewModel.getType(), vendorTypeLocals);
ComboBoxUtils.initialComboBox(controller.catalogField, viewModel.getCatalog(), getCachedBean(VendorTypeService.class), true);
controller.protocolProviderField.selectedProperty().bindBidirectional(viewModel.getProtocolProvider());
UITools.autoCompletion(controller.contactField, viewModel.getContact(), getCompanyContactService());

View File

@@ -2,6 +2,7 @@ package com.ecep.contract.controller.vendor;
import java.io.File;
import com.ecep.contract.vo.VendorTypeLocalVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Lazy;
@@ -55,7 +56,7 @@ public class CompanyVendorWindowController extends AbstEntityController<CompanyV
public Tab fileTab;
public Tab entityTab;
public ComboBox<VendorTypeLocal> catalogField;
public ComboBox<VendorTypeLocalVo> catalogField;
public CheckBox protocolProviderField;
public TextField pathField;
public TextArea descriptionField;

View File

@@ -3,6 +3,11 @@ package com.ecep.contract.controller.vendor.approved_list;
import java.util.ArrayList;
import java.util.List;
import com.ecep.contract.VendorType;
import com.ecep.contract.controller.ComboBoxUtils;
import com.ecep.contract.controller.table.cell.VendorTypeTableCell;
import com.ecep.contract.service.*;
import com.ecep.contract.vo.*;
import org.springframework.util.StringUtils;
import com.ecep.contract.controller.tab.TabSkin;
@@ -11,11 +16,6 @@ import com.ecep.contract.controller.table.cell.CompanyVendorTableCell;
import com.ecep.contract.controller.vendor.CompanyVendorWindowController;
import com.ecep.contract.model.CompanyVendor;
import com.ecep.contract.model.VendorTypeLocal;
import com.ecep.contract.service.CompanyOldNameService;
import com.ecep.contract.service.CompanyService;
import com.ecep.contract.service.CompanyVendorApprovedItemService;
import com.ecep.contract.service.CompanyVendorService;
import com.ecep.contract.service.SysConfService;
import com.ecep.contract.util.BooleanConfigProperty;
import com.ecep.contract.util.FxmlPath;
import com.ecep.contract.util.IntegerConfigProperty;
@@ -25,11 +25,6 @@ import com.ecep.contract.util.ProxyUtils;
import com.ecep.contract.util.UITools;
import com.ecep.contract.vm.CompanyVendorApprovedItemViewModel;
import com.ecep.contract.vm.CompanyVendorApprovedListViewModel;
import com.ecep.contract.vo.CompanyOldNameVo;
import com.ecep.contract.vo.CompanyVendorApprovedItemVo;
import com.ecep.contract.vo.CompanyVendorApprovedListVo;
import com.ecep.contract.vo.CompanyVendorVo;
import com.ecep.contract.vo.CompanyVo;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.collections.FXCollections;
@@ -57,12 +52,12 @@ public class CompanyVendorApprovedListTabSkinVendors
private CompanyVendorService companyVendorService;
private CompanyOldNameService companyOldNameService;
public ComboBox<VendorTypeLocal> typeSelector;
public ComboBox<VendorTypeLocalVo> typeSelector;
public Menu vendorTableContextChangeTypeMenu;
public TableColumn<CompanyVendorApprovedItemViewModel, Number> idColumn;
public TableColumn<CompanyVendorApprovedItemViewModel, Integer> vendorColumn;
public TableColumn<CompanyVendorApprovedItemViewModel, String> typeColumn;
public TableColumn<CompanyVendorApprovedItemViewModel, VendorType> typeColumn;
public TableColumn<CompanyVendorApprovedItemViewModel, String> descriptionColumn;
public CheckMenuItem logUnqualifiedVendorChecker;
@@ -115,7 +110,7 @@ public class CompanyVendorApprovedListTabSkinVendors
@Override
public ParamUtils.Builder getSpecification() {
Builder params = super.getSpecification();
VendorTypeLocal selectorType = typeSelector.getValue();
VendorTypeLocalVo selectorType = typeSelector.getValue();
if (selectorType != null) {
params.equals("type", selectorType.getType());
}
@@ -136,49 +131,22 @@ public class CompanyVendorApprovedListTabSkinVendors
@Override
public void initializeTab() {
List<VendorTypeLocal> vendorTypeLocals = getCompanyVendorService()
.findAllTypes(controller.getLocale().toLanguageTag());
ObservableList<VendorTypeLocal> vendorTypeItems = FXCollections.observableArrayList();
vendorTypeItems.add(null);
vendorTypeItems.addAll(vendorTypeLocals);
typeSelector.setItems(vendorTypeItems);
typeSelector.setConverter(new StringConverter<>() {
@Override
public String toString(VendorTypeLocal typeLocal) {
if (typeLocal == null) {
return "";
}
return typeLocal.getValue();
}
@Override
public VendorTypeLocal fromString(String string) {
return null;
}
});
ComboBoxUtils.initialComboBox(typeSelector, null, getCachedBean(VendorTypeService.class), true);
idColumn.setCellValueFactory(param -> param.getValue().getId());
// 厂商, vendor
vendorColumn.setCellValueFactory(param -> param.getValue().getVendor());
vendorColumn.setCellFactory(param -> new VendorTableCell(getCompanyVendorService(), getCompanyService()));
typeColumn.setCellValueFactory(param -> param.getValue().getType().map(v -> {
if (v == null) {
return "-";
}
for (VendorTypeLocal vendorTypeLocal : vendorTypeLocals) {
if (vendorTypeLocal.getType() == v) {
return vendorTypeLocal.getValue();
}
}
return v.name();
}));
vendorColumn.setCellFactory(CompanyVendorTableCell.forTableColumn(getCompanyVendorService()));
// 类型, type
typeColumn.setCellValueFactory(param -> param.getValue().getType());
typeColumn.setCellFactory(VendorTypeTableCell.forTableColumn(getCachedBean(VendorTypeService.class)));
// 描述, description
descriptionColumn.setCellValueFactory(param -> param.getValue().getDescription());
table.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
List<MenuItem> menuItems = new ArrayList<>();
for (VendorTypeLocal value : vendorTypeLocals) {
for (VendorTypeLocalVo value : getCachedBean(VendorTypeService.class).findAll()) {
MenuItem menuItem = new MenuItem();
menuItem.setText(value.getValue());
menuItem.setOnAction(event -> {
@@ -220,7 +188,7 @@ public class CompanyVendorApprovedListTabSkinVendors
super.initializeTab();
}
private void changeVendorTableSelectedItemType(VendorTypeLocal value) {
private void changeVendorTableSelectedItemType(VendorTypeLocalVo value) {
CompanyVendorApprovedItemViewModel selectedItem = getTableView().getSelectionModel().getSelectedItem();
selectedItem.getType().set(value.getType());
@@ -299,30 +267,4 @@ public class CompanyVendorApprovedListTabSkinVendors
}
}
}
static class VendorTableCell extends CompanyVendorTableCell<CompanyVendorApprovedItemViewModel> {
public VendorTableCell(CompanyVendorService companyVendorService, CompanyService companyService) {
super();
setService(companyVendorService);
setCompanyService(companyService);
}
@Override
protected boolean isInitialized(CompanyVendorVo item) {
CompanyVendorApprovedItemViewModel row = getTableRow().getItem();
if (StringUtils.hasText(row.getVendorName().get())) {
return true;
}
return super.isInitialized(item);
}
@Override
public String format(CompanyVendorVo vendor) {
CompanyVendorApprovedItemViewModel row = getTableRow().getItem();
if (StringUtils.hasText(row.getVendorName().get())) {
return row.getVendorName().get();
}
return super.format(vendor);
}
}
}

View File

@@ -138,17 +138,6 @@ public class CompanyVendorService extends QueryService<CompanyVendorVo, CompanyV
return valid;
}
public List<VendorTypeLocal> findAllTypes(Locale locale) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'findAllTypes'");
}
public List<VendorTypeLocal> findAllTypes(String languageTag) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'findAllTypes'");
}
public boolean makePathAbsent(CompanyVendorVo companyVendor) {
String path = companyVendor.getPath();
if (StringUtils.hasText(path)) {

View File

@@ -16,13 +16,15 @@ import java.util.Locale;
@Service
@CacheConfig(cacheNames = "vendor-type")
public class VendorTypeService extends QueryService<VendorTypeLocalVo, VendorTypeLocalViewModel> {
private final StringConverter<VendorTypeLocalVo> stringConverter = new VendorTypeStringConverter(this);
@Cacheable(key = "#p0")
@Override
public VendorTypeLocalVo findById(Integer id) {
return super.findById(id);
}
@Cacheable(key = "'type-'+#p0")
@Cacheable(key = "'type-'+#p0.ordinal()")
public VendorTypeLocalVo findByType(VendorType type) {
return findAll(ParamUtils.builder().equals("type", type).build(), Pageable.ofSize(1)).stream().findFirst()
.orElse(null);
@@ -46,8 +48,6 @@ public class VendorTypeService extends QueryService<VendorTypeLocalVo, VendorTyp
super.delete(entity);
}
private StringConverter<VendorTypeLocalVo> stringConverter = new VendorTypeStringConverter(this);
@Override
public StringConverter<VendorTypeLocalVo> getStringConverter() {
return stringConverter;

View File

@@ -1,13 +1,11 @@
package com.ecep.contract.util;
import com.ecep.contract.constant.ServiceConstant;
import java.time.LocalDate;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.function.Consumer;
import java.util.function.Supplier;
import com.ecep.contract.constant.ServiceConstant;
public class ParamUtils {
public static Map<String, Object> between(String key, LocalDate begin, LocalDate end) {

View File

@@ -0,0 +1,5 @@
ui.vendor.title=[{0}] {1} Vendor
ui.vendor.type=Type
ui.vendor.description=Description
ui.customer.title=[{0}] {1} Customer

View File

@@ -0,0 +1,5 @@
ui.vendor.title=[{0}] {1} 供应商
ui.vendor.type=类型
ui.vendor.description=描述
ui.customer.title=[{0}] {1} 客户

View File

@@ -25,7 +25,7 @@ import lombok.ToString;
@Entity
@Table(name = "VENDOR_CATALOG", schema = "supplier_ms")
@ToString
public class VendorCatalog implements BasedEntity, Serializable, Voable<VendorCatalogVo> {
public class VendorCatalog implements BasedEntity, IdentityEntity, Serializable, Voable<VendorCatalogVo> {
private static final long serialVersionUID = 1L;
@Id
@Column(name = "ID", nullable = false)

View File

@@ -4,8 +4,10 @@ import com.ecep.contract.VendorFileType;
import com.ecep.contract.model.BaseEnumEntity;
import com.ecep.contract.model.IdentityEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
@Data
@EqualsAndHashCode(callSuper = true)
public class VendorFileTypeLocalVo extends BaseEnumEntity<VendorFileType>
implements IdentityEntity {
}

View File

@@ -4,8 +4,10 @@ import com.ecep.contract.model.BaseEnumEntity;
import com.ecep.contract.model.IdentityEntity;
import com.ecep.contract.VendorType;
import lombok.Data;
import lombok.EqualsAndHashCode;
@Data
@EqualsAndHashCode(callSuper = true)
public class VendorTypeLocalVo extends BaseEnumEntity<VendorType> implements IdentityEntity {
}

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

@@ -0,0 +1,94 @@
package com.ecep.contract.ds.customer.service;
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

@@ -0,0 +1,97 @@
package com.ecep.contract.ds.project.service;
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 + "%")
// )
;
};
}