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,24 +1,5 @@
package com.ecep.contract;
import com.ecep.contract.constant.WebSocketConstant;
import com.ecep.contract.msg.SimpleMessage;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import javafx.application.Platform;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import lombok.Getter;
import lombok.Setter;
import okhttp3.*;
import okio.ByteString;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -28,6 +9,32 @@ import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ecep.contract.constant.WebSocketConstant;
import com.ecep.contract.controller.OkHttpLoginController;
import com.ecep.contract.msg.SimpleMessage;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import javafx.application.Platform;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import lombok.Getter;
import lombok.Setter;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.WebSocket;
import okhttp3.WebSocketListener;
import okio.ByteString;
/**
* WebSocket消息服务
* 提供向服务器端发送WebSocket消息的功能
@@ -90,7 +97,10 @@ public class WebSocketClientService {
} else {
logger.error("未找到对应的回调future: {}", messageId);
}
} else if (node.has(WebSocketConstant.SESSION_ID_FIELD_NAME)) {
return;
}
if (node.has(WebSocketConstant.SESSION_ID_FIELD_NAME)) {
String sessionId = node.get(WebSocketConstant.SESSION_ID_FIELD_NAME).asText();
WebSocketClientSession session = sessions.get(sessionId);
if (session != null) {
@@ -100,18 +110,26 @@ public class WebSocketClientService {
session.updateMessage(java.util.logging.Level.SEVERE, "会话异常: " + e.getMessage());
}
}
} else if (node.has(WebSocketConstant.ERROR_CODE_FIELD_NAME)) {
return;
}
if (node.has(WebSocketConstant.ERROR_CODE_FIELD_NAME)) {
int errorCode = node.get(WebSocketConstant.ERROR_CODE_FIELD_NAME).asInt();
String errorMsg = node.get(WebSocketConstant.MESSAGE_FIELD_NAME).asText();
// TODO 需要重新登录
logger.error("收到错误消息: 错误码={}, 错误信息={}", errorCode, errorMsg);
if (errorCode == WebSocketConstant.ERROR_CODE_UNAUTHORIZED) {
// 处理未授权错误,重新登录
OkHttpLoginController controller = new OkHttpLoginController();
controller.tryLogin();
// 需要把窗口顶置
}
return;
}
} catch (Exception e) {
logger.error("处理WebSocket消息失败: {}", e.getMessage(), e);
}
}
@Override
public void onMessage(WebSocket webSocket, ByteString bytes) {
// 处理收到的二进制消息
@@ -149,7 +167,8 @@ public class WebSocketClientService {
if (node.has(WebSocketConstant.SUCCESS_FIELD_VALUE)) {
if (!node.get(WebSocketConstant.SUCCESS_FIELD_VALUE).asBoolean()) {
future.completeExceptionally(
new RuntimeException("请求失败:来自服务器的消息=" + node.get(WebSocketConstant.MESSAGE_FIELD_NAME).asText()));
new RuntimeException(
"请求失败:来自服务器的消息=" + node.get(WebSocketConstant.MESSAGE_FIELD_NAME).asText()));
return;
}
}

View File

@@ -6,6 +6,7 @@ import java.time.LocalDateTime;
import java.util.NoSuchElementException;
import java.util.concurrent.CompletableFuture;
import com.ecep.contract.controller.ComboBoxUtils;
import org.springframework.util.StringUtils;
import com.ecep.contract.DesktopUtils;
@@ -123,11 +124,7 @@ public class CompanyTabSkinContract
contractSearchBtn.setOnAction(this::onTableRefreshAction);
ObservableList<ContractGroupVo> contractGroups = FXCollections.observableArrayList();
contractGroups.add(null);
contractGroups.addAll(getContractGroupService().findAll());
contractGroupSelector.setItems(contractGroups);
contractGroupSelector.setConverter(new ContractGroupStringConverter(contractGroups));
ComboBoxUtils.initialComboBox(contractGroupSelector, null, getContractGroupService(), true);
contractSearchKeyField.setOnKeyReleased(event -> {
if (event.getCode() == KeyCode.ENTER) {
contractSearchBtn.fire();

View File

@@ -8,6 +8,7 @@ import java.util.function.Consumer;
import com.ecep.contract.service.CompanyFileTypeService;
import com.ecep.contract.service.ContractFileTypeService;
import com.ecep.contract.vo.CompanyFileTypeLocalVo;
import com.ecep.contract.vo.CompanyFileVo;
import com.ecep.contract.vo.CompanyVo;
import org.springframework.util.FileSystemUtils;
@@ -64,7 +65,7 @@ public class CompanyTabSkinFile
public MenuItem fileTable_menu_del;
public MenuItem fileTable_menu_copy_as_matched_by_contract;
private final ObservableMap<CompanyFileType, CompanyFileTypeLocal> fileTypeLocalMap = FXCollections
private final ObservableMap<CompanyFileType, CompanyFileTypeLocalVo> fileTypeLocalMap = FXCollections
.observableHashMap();
public CompanyTabSkinFile(CompanyWindowController controller) {
@@ -96,7 +97,7 @@ public class CompanyTabSkinFile
idColumn.setCellValueFactory(param -> param.getValue().getId());
typeColumn.setCellValueFactory(param -> Bindings.valueAt(fileTypeLocalMap, param.getValue().getType())
.map(CompanyFileTypeLocal::getValue));
.map(CompanyFileTypeLocalVo::getValue));
filePathColumn.setCellValueFactory(param -> param.getValue().getFilePath());
filePathColumn.setCellFactory(param -> new CompanyFilePathTableCell<>(viewModel.getPath()));
applyDateColumn.setCellValueFactory(param -> param.getValue().getApplyDate());

View File

@@ -203,9 +203,13 @@ public class ContractTabSkinBase extends AbstContractBasedTabSkin {
}
private void parentCodeFieldAutoCompletion(TextField textField) {
ContractStringConverter converter = SpringApp.getBean(ContractStringConverter.class);
converter.setFormater(ContractVo::getCode);
TextFields.bindAutoCompletion(textField, converter::suggest, converter);
ContractService contractService = getContractService();
TextFields.bindAutoCompletion(textField, suggest -> contractService.search(suggest.getUserText()), new ContractStringConverter(contractService) {
@Override
public String toString(ContractVo object) {
return object.getCode();
}
});
}
private void calcMainContractNoAction(ActionEvent event) {

View File

@@ -3,8 +3,6 @@ package com.ecep.contract.controller.table.cell;
import java.util.Objects;
import java.util.concurrent.Future;
import com.ecep.contract.service.QueryService;
import com.ecep.contract.util.ProxyUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -13,6 +11,7 @@ import com.ecep.contract.model.BasedEntity;
import com.ecep.contract.model.IdentityEntity;
import com.ecep.contract.model.NamedEntity;
import com.ecep.contract.service.IEntityService;
import com.ecep.contract.util.ProxyUtils;
import javafx.application.Platform;
@@ -22,7 +21,7 @@ import javafx.application.Platform;
* @param <V>
* @param <T>
*/
public class AsyncUpdateTableCell<V, T extends IdentityEntity> extends javafx.scene.control.TableCell<V, Integer> {
public class AsyncUpdateTableCell<V, K, T extends IdentityEntity> extends javafx.scene.control.TableCell<V, K> {
private static final Logger logger = LoggerFactory.getLogger(AsyncUpdateTableCell.class);
/**
@@ -66,7 +65,7 @@ public class AsyncUpdateTableCell<V, T extends IdentityEntity> extends javafx.sc
}
@Override
protected void updateItem(Integer itemId, boolean empty) {
protected void updateItem(K itemId, boolean empty) {
super.updateItem(itemId, empty);
// 取消之前的异步任务
if (syncFuture != null) {
@@ -103,7 +102,11 @@ public class AsyncUpdateTableCell<V, T extends IdentityEntity> extends javafx.sc
* @return
*/
protected T initialize() {
return getService().findById(getItem());
K k = getItem();
if (k instanceof Integer id) {
return getService().findById(id);
}
throw new UnsupportedOperationException("Not supported yet.");
}
/**
@@ -143,7 +146,7 @@ public class AsyncUpdateTableCell<V, T extends IdentityEntity> extends javafx.sc
// 保存当前需要更新的项目信息,避免闭包引用导致的问题
final T updatedEntity = entity;
final String updatedText = texted;
final Integer finalCurrentLoadingItem = getItem();
final K finalCurrentLoadingItem = getItem();
Platform.runLater(() -> {
// 检查单元格是否仍然显示相同的项目

View File

@@ -7,7 +7,7 @@ import com.ecep.contract.vo.BankVo;
import lombok.NoArgsConstructor;
@NoArgsConstructor
public class BankTableCell<T> extends AsyncUpdateTableCell<T, BankVo> {
public class BankTableCell<T> extends AsyncUpdateTableCell<T, Integer, BankVo> {
public BankTableCell(BankService service) {
setService(service);
}

View File

@@ -12,7 +12,7 @@ import lombok.NoArgsConstructor;
* 公司单元格
*/
@NoArgsConstructor
public class CompanyTableCell<V> extends AsyncUpdateTableCell<V, CompanyVo> {
public class CompanyTableCell<V> extends AsyncUpdateTableCell<V, Integer, CompanyVo> {
/**
* 创建单元格工厂
*

View File

@@ -14,7 +14,7 @@ import lombok.NoArgsConstructor;
import lombok.Setter;
@NoArgsConstructor
public class CompanyVendorTableCell<T> extends AsyncUpdateTableCell<T, CompanyVendorVo> {
public class CompanyVendorTableCell<T> extends AsyncUpdateTableCell<T, Integer, CompanyVendorVo> {
public static <S> Callback<TableColumn<S, Integer>, TableCell<S, Integer>> forTableColumn() {
return forTableColumn(SpringApp.getBean(CompanyVendorService.class));
}

View File

@@ -11,7 +11,7 @@ import javafx.util.Callback;
import lombok.NoArgsConstructor;
@NoArgsConstructor
public class ContractFileTableCell<V> extends AsyncUpdateTableCell<V, ContractVo> {
public class ContractFileTableCell<V> extends AsyncUpdateTableCell<V, Integer, ContractVo> {
/**
* 创建一个ContractFileTableCell的TableCell工厂自动获取ContractService实例

View File

@@ -5,7 +5,7 @@ import static com.ecep.contract.SpringApp.getBean;
import com.ecep.contract.service.ContractGroupService;
import com.ecep.contract.vo.ContractGroupVo;
public class ContractGroupTableCell<V> extends AsyncUpdateTableCell<V, ContractGroupVo> {
public class ContractGroupTableCell<V> extends AsyncUpdateTableCell<V, Integer, ContractGroupVo> {
public ContractGroupTableCell() {
}

View File

@@ -5,7 +5,7 @@ import static com.ecep.contract.SpringApp.getBean;
import com.ecep.contract.service.ContractKindService;
import com.ecep.contract.vo.ContractKindVo;
public class ContractKindTableCell<V> extends AsyncUpdateTableCell<V, ContractKindVo> {
public class ContractKindTableCell<V> extends AsyncUpdateTableCell<V, Integer, ContractKindVo> {
public ContractKindTableCell() {
}

View File

@@ -7,7 +7,7 @@ import com.ecep.contract.vo.ContractVo;
import lombok.NoArgsConstructor;
@NoArgsConstructor
public class ContractTableCell<T> extends AsyncUpdateTableCell<T, ContractVo> {
public class ContractTableCell<T> extends AsyncUpdateTableCell<T, Integer, ContractVo> {
public ContractTableCell(ContractService service) {
setService(service);
}

View File

@@ -7,7 +7,7 @@ import com.ecep.contract.vo.ContractTypeVo;
import lombok.NoArgsConstructor;
@NoArgsConstructor
public class ContractTypeTableCell<V> extends AsyncUpdateTableCell<V, ContractTypeVo> {
public class ContractTypeTableCell<V> extends AsyncUpdateTableCell<V, Integer, ContractTypeVo> {
public ContractTypeTableCell(ContractTypeService contractService) {
setService(contractService);
}

View File

@@ -12,7 +12,7 @@ import javafx.util.Callback;
import lombok.NoArgsConstructor;
@NoArgsConstructor
public class CustomerCatalogTableCell<T> extends AsyncUpdateTableCell<T, CustomerCatalogVo> {
public class CustomerCatalogTableCell<T> extends AsyncUpdateTableCell<T, Integer, CustomerCatalogVo> {
public CustomerCatalogTableCell(CustomerCatalogService service) {
setService(service);
}

View File

@@ -7,7 +7,7 @@ import com.ecep.contract.vo.DepartmentVo;
import lombok.NoArgsConstructor;
@NoArgsConstructor
public class DepartmentTableCell<T> extends AsyncUpdateTableCell<T, DepartmentVo> {
public class DepartmentTableCell<T> extends AsyncUpdateTableCell<T, Integer, DepartmentVo> {
public DepartmentTableCell(DepartmentService service) {
setService(service);
}

View File

@@ -13,7 +13,7 @@ import lombok.NoArgsConstructor;
* @param <V>
*/
@NoArgsConstructor
public class EmployeeRoleTableCell<V> extends AsyncUpdateTableCell<V, EmployeeRoleVo> {
public class EmployeeRoleTableCell<V> extends AsyncUpdateTableCell<V, Integer, EmployeeRoleVo> {
public EmployeeRoleTableCell(EmployeeRoleService service) {
setService(service);

View File

@@ -11,7 +11,7 @@ import javafx.util.Callback;
import lombok.Setter;
@Setter
public class EmployeeTableCell<V> extends AsyncUpdateTableCell<V, EmployeeVo> {
public class EmployeeTableCell<V> extends AsyncUpdateTableCell<V, Integer, EmployeeVo> {
public static <S> Callback<TableColumn<S, Integer>, TableCell<S, Integer>> forTableColumn() {
return forTableColumn(getBean(EmployeeService.class));

View File

@@ -16,7 +16,7 @@ import lombok.NoArgsConstructor;
* 评估文件 TableCell
*/
@NoArgsConstructor
public class EvaluationFileTableCell<V> extends AsyncUpdateTableCell<V, CompanyCustomerEvaluationFormFileVo> {
public class EvaluationFileTableCell<V> extends AsyncUpdateTableCell<V, Integer, CompanyCustomerEvaluationFormFileVo> {
private CompanyCustomerFileService fileService;
private CompanyCustomerEvaluationFormFileService evaluationFormFileService;

View File

@@ -8,7 +8,7 @@ import com.ecep.contract.vo.InventoryCatalogVo;
import lombok.Setter;
@Setter
public class InventoryCatalogTableCell<V> extends AsyncUpdateTableCell<V, InventoryCatalogVo> {
public class InventoryCatalogTableCell<V> extends AsyncUpdateTableCell<V, Integer, InventoryCatalogVo> {
public InventoryCatalogTableCell() {
}

View File

@@ -10,7 +10,7 @@ import javafx.util.Callback;
import lombok.NoArgsConstructor;
@NoArgsConstructor
public class InventoryTableCell<V> extends AsyncUpdateTableCell<V, InventoryVo> {
public class InventoryTableCell<V> extends AsyncUpdateTableCell<V, Integer, InventoryVo> {
/**
* 创建单元格工厂
*

View File

@@ -10,7 +10,7 @@ import javafx.util.Callback;
import lombok.NoArgsConstructor;
@NoArgsConstructor
public class InvoiceTableCell<V> extends AsyncUpdateTableCell<V, InvoiceVo> {
public class InvoiceTableCell<V> extends AsyncUpdateTableCell<V, Integer, InvoiceVo> {
public InvoiceTableCell(InvoiceService invoiceService) {
setService(invoiceService);

View File

@@ -10,7 +10,7 @@ import lombok.NoArgsConstructor;
* 产品类型单元格
*/
@NoArgsConstructor
public class ProductTypeTableCell<V> extends AsyncUpdateTableCell<V, ProductTypeVo> {
public class ProductTypeTableCell<V> extends AsyncUpdateTableCell<V, Integer, ProductTypeVo> {
public ProductTypeTableCell(ProductTypeService productTypeService) {
setService(productTypeService);

View File

@@ -11,7 +11,7 @@ import lombok.NoArgsConstructor;
* 项目销售类型单元格
*/
@NoArgsConstructor
public class ProjectSaleTypeTableCell<V> extends AsyncUpdateTableCell<V, ProjectSaleTypeVo> {
public class ProjectSaleTypeTableCell<V> extends AsyncUpdateTableCell<V, Integer, ProjectSaleTypeVo> {
public ProjectSaleTypeTableCell(ProjectSaleTypeService projectSaleTypeService) {
setService(projectSaleTypeService);

View File

@@ -11,7 +11,7 @@ import javafx.util.Callback;
import lombok.NoArgsConstructor;
@NoArgsConstructor
public class ProjectTableCell<V> extends AsyncUpdateTableCell<V, ProjectVo> {
public class ProjectTableCell<V> extends AsyncUpdateTableCell<V, Integer, ProjectVo> {
public static <S> Callback<TableColumn<S, Integer>, TableCell<S, Integer>> forTableColumn() {
return forTableColumn(getBean(ProjectService.class));
}

View File

@@ -10,7 +10,7 @@ import lombok.NoArgsConstructor;
* 项目类型单元格
*/
@NoArgsConstructor
public class ProjectTypeTableCell<V> extends AsyncUpdateTableCell<V, ProjectTypeVo> {
public class ProjectTypeTableCell<V> extends AsyncUpdateTableCell<V, Integer, ProjectTypeVo> {
public ProjectTypeTableCell(ProjectTypeService projectTypeService) {
setService(projectTypeService);

View File

@@ -11,7 +11,7 @@ import com.ecep.contract.vo.PurchaseOrderItemVo;
import lombok.NoArgsConstructor;
@NoArgsConstructor
public class PurchaseOrderItemTableCell<V> extends AsyncUpdateTableCell<V, PurchaseOrderItemVo> {
public class PurchaseOrderItemTableCell<V> extends AsyncUpdateTableCell<V, Integer, PurchaseOrderItemVo> {
PurchaseOrdersService purchaseOrdersService;
PurchaseOrderItemService purchaseOrderItemService;
private InventoryService inventoryService;

View File

@@ -7,7 +7,7 @@ import com.ecep.contract.vo.UnitVo;
import lombok.NoArgsConstructor;
@NoArgsConstructor
public class UnitTableCell<T> extends AsyncUpdateTableCell<T, UnitVo> {
public class UnitTableCell<T> extends AsyncUpdateTableCell<T, Integer, UnitVo> {
public UnitTableCell(UnitService service) {
setService(service);
}

View File

@@ -11,7 +11,7 @@ import javafx.util.Callback;
import lombok.NoArgsConstructor;
@NoArgsConstructor
public class VendorCatalogTableCell<T> extends AsyncUpdateTableCell<T, VendorCatalogVo> {
public class VendorCatalogTableCell<T> extends AsyncUpdateTableCell<T, Integer, VendorCatalogVo> {
public static <S> Callback<TableColumn<S, Integer>, TableCell<S, Integer>> forTableColumn() {
return forTableColumn(SpringApp.getBean(VendorCatalogService.class));
}

View File

@@ -12,7 +12,7 @@ import javafx.util.Callback;
/**
* 供应商类型单元格,用于在表格中显示供应商类型信息
*/
public class VendorTypeTableCell<T> extends AsyncUpdateTableCell<T, VendorTypeLocalVo> {
public class VendorTypeTableCell<T> extends AsyncUpdateTableCell<T, VendorType, VendorTypeLocalVo> {
private VendorTypeService vendorTypeService;
/**
@@ -39,4 +39,10 @@ public class VendorTypeTableCell<T> extends AsyncUpdateTableCell<T, VendorTypeLo
return vendorTypeService;
}
@Override
protected VendorTypeLocalVo initialize() {
VendorType item = getItem();
return getServiceBean().findByType(item);
}
}

View File

@@ -1,32 +1,24 @@
package com.ecep.contract.converter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import com.ecep.contract.service.BankService;
import com.ecep.contract.vo.BankVo;
import javafx.util.StringConverter;
import jakarta.annotation.PostConstruct;
public class BankStringConverter extends StringConverter<BankVo> {
@Lazy
@Component
@Deprecated
public class BankStringConverter extends EntityStringConverter<BankVo> {
@Lazy
@Autowired
BankService service;
public BankStringConverter() {
public BankStringConverter(BankService service) {
this.service = service;
}
@PostConstruct
private void init() {
// #2
setInitialized(project -> service.findById(project.getId()));
setSuggestion(service::search);
setFromString(service::findByName);
@Override
public String toString(BankVo object) {
return object == null ? "" : object.getCode() + " " + object.getName();
}
@Override
public BankVo fromString(String string) {
return service.findByName(string);
}
}

View File

@@ -2,19 +2,17 @@ package com.ecep.contract.converter;
import java.util.List;
import com.ecep.contract.service.ContractGroupService;
import javafx.util.StringConverter;
import org.springframework.util.StringUtils;
import com.ecep.contract.vo.ContractGroupVo;
public class ContractGroupStringConverter extends EntityStringConverter<ContractGroupVo> {
public class ContractGroupStringConverter extends StringConverter<ContractGroupVo> {
private ContractGroupService service;
private List<ContractGroupVo> dataset;
public ContractGroupStringConverter() {
}
public ContractGroupStringConverter(List<ContractGroupVo> dataset) {
this.dataset = dataset;
public ContractGroupStringConverter(ContractGroupService contractGroupService) {
this.service = contractGroupService;
}
@Override
@@ -22,32 +20,14 @@ public class ContractGroupStringConverter extends EntityStringConverter<Contract
if (group == null) {
return "All";
}
return group.getName();
return group.getCode() + " " + group.getName() + " " + group.getTitle();
}
@Override
public ContractGroupVo fromString(String string) {
if (dataset == null) {
return null;
}
if (!StringUtils.hasText(string)) {
return null;
}
for (ContractGroupVo group : dataset) {
if (group == null) {
continue;
}
if (toString(group).equals(string)) {
return group;
}
if (group.getCode().equals(string)) {
return group;
}
if (group.getName().contains(string)) {
return group;
}
}
return null;
return service.findByCode(string);
}
}

View File

@@ -1,5 +1,6 @@
package com.ecep.contract.converter;
import javafx.util.StringConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
@@ -9,21 +10,20 @@ import com.ecep.contract.vo.ContractVo;
import jakarta.annotation.PostConstruct;
@Lazy
@Component
public class ContractStringConverter extends EntityStringConverter<ContractVo> {
@Lazy
@Autowired
public class ContractStringConverter extends StringConverter<ContractVo> {
ContractService service;
public ContractStringConverter() {
public ContractStringConverter(ContractService service) {
this.service = service;
}
@PostConstruct
private void init() {
setInitialized(project -> service.findById(project.getId()));
setSuggestion(service::search);
// TODO 按名称找出,容易出问题
setFromString(service::findByName);
@Override
public String toString(ContractVo cc) {
return cc.getCode() + " " + cc.getName();
}
@Override
public ContractVo fromString(String string) {
return service.findByCode(string);
}
}

View File

@@ -2,19 +2,30 @@ package com.ecep.contract.converter;
import com.ecep.contract.service.ContractTypeService;
import com.ecep.contract.vo.ContractTypeVo;
import javafx.util.StringConverter;
public class ContractTypeStringConverter extends EntityStringConverter<ContractTypeVo> {
/**
* 合同类型字符串转换器
*
* @author songqq
*/
public class ContractTypeStringConverter extends StringConverter<ContractTypeVo> {
ContractTypeService contractTypeService;
public ContractTypeStringConverter(ContractTypeService contractTypeService) {
this.contractTypeService = contractTypeService;
init();
}
private void init() {
setInitialized(project -> contractTypeService.findById(project.getId()));
setSuggestion(contractTypeService::search);
setFromString(contractTypeService::findByName);
@Override
public String toString(ContractTypeVo object) {
return object.getCode() + " " + object.getCatalog() + " " + object.getName() + " " + object.getTitle()
+ "("
+ object.getDirection() + ")";
}
@Override
public ContractTypeVo fromString(String string) {
return contractTypeService.findByCode(string);
}
}

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);