refactor: 重构服务依赖注入和上下文管理
移除硬编码的服务注入,改为使用缓存机制动态获取Bean 优化上下文类结构,统一服务获取方式 添加PageContent类支持分页数据封装 实现异步数据加载功能
This commit is contained in:
@@ -20,6 +20,7 @@ import org.springframework.data.domain.Sort;
|
|||||||
import com.ecep.contract.controller.table.EditableEntityTableTabSkin;
|
import com.ecep.contract.controller.table.EditableEntityTableTabSkin;
|
||||||
import com.ecep.contract.controller.table.TableTabSkin;
|
import com.ecep.contract.controller.table.TableTabSkin;
|
||||||
import com.ecep.contract.model.IdentityEntity;
|
import com.ecep.contract.model.IdentityEntity;
|
||||||
|
import com.ecep.contract.service.QueryService;
|
||||||
import com.ecep.contract.service.ViewModelService;
|
import com.ecep.contract.service.ViewModelService;
|
||||||
import com.ecep.contract.util.TableViewUtils;
|
import com.ecep.contract.util.TableViewUtils;
|
||||||
import com.ecep.contract.util.UITools;
|
import com.ecep.contract.util.UITools;
|
||||||
@@ -419,17 +420,14 @@ public abstract class AbstEntityManagerSkin<T extends IdentityEntity, TV extends
|
|||||||
dataSet.clear();
|
dataSet.clear();
|
||||||
runAsync(() -> {
|
runAsync(() -> {
|
||||||
controller.setStatus("载入中...");
|
controller.setStatus("载入中...");
|
||||||
|
// 异步加载数据
|
||||||
|
if (getViewModelService() instanceof QueryService<T, TV> queryService) {
|
||||||
|
asyncLoadTableData(queryService, future);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 同步加载方法
|
||||||
List<TV> models = loadTableData();
|
List<TV> models = loadTableData();
|
||||||
Platform.runLater(() -> {
|
_updateModels(models, future);
|
||||||
try {
|
|
||||||
updateTableDataSet(models);
|
|
||||||
allowResize = true; // 恢复调整
|
|
||||||
future.complete(null);
|
|
||||||
} catch (Exception e) {
|
|
||||||
allowResize = true; // 恢复调整
|
|
||||||
future.completeExceptionally(e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}).exceptionally(ex -> {
|
}).exceptionally(ex -> {
|
||||||
future.completeExceptionally(ex);
|
future.completeExceptionally(ex);
|
||||||
return null;
|
return null;
|
||||||
@@ -438,6 +436,20 @@ public abstract class AbstEntityManagerSkin<T extends IdentityEntity, TV extends
|
|||||||
return future;
|
return future;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void _updateModels(List<TV> models, CompletableFuture<Void> future) {
|
||||||
|
Platform.runLater(() -> {
|
||||||
|
try {
|
||||||
|
updateTableDataSet(models);
|
||||||
|
allowResize = true; // 恢复调整
|
||||||
|
future.complete(null);
|
||||||
|
} catch (Exception e) {
|
||||||
|
allowResize = true; // 恢复调整
|
||||||
|
future.completeExceptionally(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新表格数据
|
* 更新表格数据
|
||||||
*
|
*
|
||||||
@@ -489,6 +501,25 @@ public abstract class AbstEntityManagerSkin<T extends IdentityEntity, TV extends
|
|||||||
return page.map(service::from).toList();
|
return page.map(service::from).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 异步加载表格数据
|
||||||
|
*
|
||||||
|
* @param queryService
|
||||||
|
* @param future
|
||||||
|
*/
|
||||||
|
private void asyncLoadTableData(QueryService<T, TV> queryService, CompletableFuture<Void> future) {
|
||||||
|
queryService.asyncFindAll(getSpecification(), getPageable()).whenComplete((result, ex) -> {
|
||||||
|
if (ex != null) {
|
||||||
|
future.completeExceptionally(ex);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
updateFooter(result);
|
||||||
|
List<TV> models = result.map(getViewModelService()::from).toList();
|
||||||
|
_updateModels(models, future);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取ViewModelService
|
* 获取ViewModelService
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -51,18 +51,6 @@ public class CloudTycManagerSkin
|
|||||||
return companyService;
|
return companyService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected List<CloudTycInfoViewModel> loadTableData() {
|
|
||||||
String searchText = controller.searchKeyField.getText();
|
|
||||||
Map<String, Object> spec = new HashMap<>();
|
|
||||||
if (StringUtils.hasText(searchText)) {
|
|
||||||
spec.put("searchText", searchText);
|
|
||||||
}
|
|
||||||
Page<CloudTyc> page = getCloudTycService().findAll(spec, getPageable());
|
|
||||||
updateFooter(page);
|
|
||||||
return page.map(CloudTycInfoViewModel::from).toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initializeTable() {
|
public void initializeTable() {
|
||||||
controller.idColumn.setCellValueFactory(param -> param.getValue().getId());
|
controller.idColumn.setCellValueFactory(param -> param.getValue().getId());
|
||||||
|
|||||||
@@ -41,18 +41,6 @@ public class YongYouU8ManagerSkin
|
|||||||
return getBean(CompanyService.class);
|
return getBean(CompanyService.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected List<CloudYuInfoViewModel> loadTableData() {
|
|
||||||
String searchText = controller.searchKeyField.getText();
|
|
||||||
Map<String, Object> params = ParamUtils.builder().build();
|
|
||||||
if (StringUtils.hasText(searchText)) {
|
|
||||||
params.put("searchText", searchText);
|
|
||||||
}
|
|
||||||
Page<CloudYu> page = getU8Service().findAll(params, getPageable());
|
|
||||||
updateFooter(page);
|
|
||||||
return page.map(CloudYuInfoViewModel::from).toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initializeTable() {
|
public void initializeTable() {
|
||||||
controller.idColumn.setCellValueFactory(param -> param.getValue().getId());
|
controller.idColumn.setCellValueFactory(param -> param.getValue().getId());
|
||||||
|
|||||||
@@ -64,22 +64,7 @@ public class ContractManagerSkin
|
|||||||
public Map<String, Object> getSpecification() {
|
public Map<String, Object> getSpecification() {
|
||||||
Map<String, Object> params = super.getSpecification();
|
Map<String, Object> params = super.getSpecification();
|
||||||
if (controller.composeViewBtn.isSelected()) {
|
if (controller.composeViewBtn.isSelected()) {
|
||||||
|
|
||||||
// TODO 完善查询条件
|
|
||||||
params.put("payWay", ContractPayWay.RECEIVE);
|
params.put("payWay", ContractPayWay.RECEIVE);
|
||||||
|
|
||||||
// spec = SpecificationUtils.and(spec, (root, query, builder) -> {
|
|
||||||
// Path<String> parentCode = root.get("parentCode");
|
|
||||||
// Path<ContractPayWay> payWay = root.get("payWay");
|
|
||||||
// return builder.or(
|
|
||||||
// builder.equal(payWay, ContractPayWay.RECEIVE),
|
|
||||||
// builder.and(
|
|
||||||
// builder.equal(payWay, ContractPayWay.PAY),
|
|
||||||
// builder.or(
|
|
||||||
// builder.equal(parentCode, ""),
|
|
||||||
// parentCode.isNull())));
|
|
||||||
// });
|
|
||||||
|
|
||||||
}
|
}
|
||||||
ContractGroup selectedGroup = controller.groupSelector.getValue();
|
ContractGroup selectedGroup = controller.groupSelector.getValue();
|
||||||
if (selectedGroup != null) {
|
if (selectedGroup != null) {
|
||||||
|
|||||||
@@ -9,11 +9,10 @@ import java.util.concurrent.TimeUnit;
|
|||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.PageImpl;
|
|
||||||
import org.springframework.data.domain.PageRequest;
|
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
|
|
||||||
import com.ecep.contract.PageArgument;
|
import com.ecep.contract.PageArgument;
|
||||||
|
import com.ecep.contract.PageContent;
|
||||||
import com.ecep.contract.WebSocketService;
|
import com.ecep.contract.WebSocketService;
|
||||||
import com.ecep.contract.model.IdentityEntity;
|
import com.ecep.contract.model.IdentityEntity;
|
||||||
import com.ecep.contract.msg.SimpleMessage;
|
import com.ecep.contract.msg.SimpleMessage;
|
||||||
@@ -103,7 +102,6 @@ public class QueryService<T extends IdentityEntity, TV extends IdentityViewModel
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (response == null) {
|
if (response == null) {
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
T newEntity = createNewEntity();
|
T newEntity = createNewEntity();
|
||||||
@@ -130,38 +128,59 @@ public class QueryService<T extends IdentityEntity, TV extends IdentityViewModel
|
|||||||
return findAll(null, Pageable.unpaged()).getContent();
|
return findAll(null, Pageable.unpaged()).getContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public CompletableFuture<Page<T>> asyncFindAll(Map<String, Object> params, Pageable pageable) {
|
||||||
public Page<T> findAll(Map<String, Object> params, Pageable pageable) {
|
|
||||||
SimpleMessage msg = new SimpleMessage();
|
SimpleMessage msg = new SimpleMessage();
|
||||||
msg.setService(getBeanName());
|
msg.setService(getBeanName());
|
||||||
msg.setMethod("findAll");
|
msg.setMethod("findAll");
|
||||||
msg.setArguments(params, PageArgument.of(pageable));
|
msg.setArguments(params, PageArgument.of(pageable));
|
||||||
try {
|
return webSocketService.send(msg).orTimeout(readTimeout, TimeUnit.MILLISECONDS).handle((response, ex) -> {
|
||||||
JsonNode response = webSocketService.send(msg).get(readTimeout, TimeUnit.MILLISECONDS);
|
if (ex != null) {
|
||||||
if (response != null) {
|
return null;
|
||||||
|
}
|
||||||
|
if (response == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
PageContent<T> pageContent = new PageContent<>();
|
||||||
|
try {
|
||||||
List<T> content = new ArrayList<>();
|
List<T> content = new ArrayList<>();
|
||||||
JsonNode contentNode = response.get("content");
|
if (response.has("content")) {
|
||||||
if (contentNode != null && contentNode.isArray()) {
|
JsonNode contentNode = response.get("content");
|
||||||
for (JsonNode node : contentNode) {
|
if (contentNode != null && contentNode.isArray()) {
|
||||||
T newEntity = createNewEntity();
|
for (JsonNode node : contentNode) {
|
||||||
objectMapper.updateValue(newEntity, node);
|
T newEntity = createNewEntity();
|
||||||
content.add(newEntity);
|
objectMapper.updateValue(newEntity, node);
|
||||||
|
content.add(newEntity);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pageContent.setContent(content);
|
||||||
JsonNode pageNode = response.get("page");
|
if (response.has("page")) {
|
||||||
|
JsonNode pageNode = response.get("page");
|
||||||
int total = pageNode.get("totalElements").asInt();
|
PageArgument pageArgument = objectMapper.treeToValue(pageNode, PageArgument.class);
|
||||||
int totalPages = pageNode.get("totalPages").asInt();
|
pageContent.setPage(pageArgument);
|
||||||
int size = pageNode.get("size").asInt();
|
}
|
||||||
int number = pageNode.get("number").asInt();
|
if (response.has("totalElements")) {
|
||||||
|
int totalElements = response.get("totalElements").asInt();
|
||||||
PageRequest newPageable = PageRequest.of(number, size);
|
pageContent.setTotalElements(totalElements);
|
||||||
return new PageImpl<>(content, newPageable, total);
|
}
|
||||||
|
if (response.has("totalPages")) {
|
||||||
|
int totalPages = response.get("totalPages").asInt();
|
||||||
|
pageContent.setTotalPages(totalPages);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(response.toString(), e);
|
||||||
}
|
}
|
||||||
|
return pageContent.toPage();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Page<T> findAll(Map<String, Object> params, Pageable pageable) {
|
||||||
|
try {
|
||||||
|
return asyncFindAll(params, pageable).get();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,11 +10,15 @@ import org.springframework.data.domain.Sort.Direction;
|
|||||||
import org.springframework.data.domain.Sort.NullHandling;
|
import org.springframework.data.domain.Sort.NullHandling;
|
||||||
import org.springframework.data.domain.Sort.Order;
|
import org.springframework.data.domain.Sort.Order;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
public class PageArgument {
|
public class PageArgument {
|
||||||
|
|
||||||
private boolean paged = false;
|
private boolean paged = false;
|
||||||
@@ -54,6 +58,7 @@ public class PageArgument {
|
|||||||
return Pageable.unpaged(sort);
|
return Pageable.unpaged(sort);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
public boolean isUnpaged() {
|
public boolean isUnpaged() {
|
||||||
return !isPaged();
|
return !isPaged();
|
||||||
}
|
}
|
||||||
|
|||||||
32
common/src/main/java/com/ecep/contract/PageContent.java
Normal file
32
common/src/main/java/com/ecep/contract/PageContent.java
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
package com.ecep.contract;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.PageImpl;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class PageContent<T> {
|
||||||
|
|
||||||
|
private List<T> content;
|
||||||
|
private PageArgument page;
|
||||||
|
private int totalElements;
|
||||||
|
private int totalPages;
|
||||||
|
|
||||||
|
public static <T> PageContent<T> of(Page<T> page) {
|
||||||
|
PageContent<T> content = new PageContent<>();
|
||||||
|
content.setContent(page.getContent());
|
||||||
|
content.setPage(PageArgument.of(page.getPageable()));
|
||||||
|
content.setTotalElements((int) page.getTotalElements());
|
||||||
|
content.setTotalPages(page.getTotalPages());
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Page<T> toPage() {
|
||||||
|
PageImpl<T> page = new PageImpl<>(content == null ? List.of() : content, getPage().toPageable(), totalElements);
|
||||||
|
return page;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,21 +1,25 @@
|
|||||||
package com.ecep.contract.cloud;
|
package com.ecep.contract.cloud;
|
||||||
|
|
||||||
import static com.ecep.contract.SpringApp.getBean;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeParseException;
|
import java.time.format.DateTimeParseException;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
import org.springframework.beans.BeansException;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
import com.ecep.contract.MessageHolder;
|
import com.ecep.contract.MessageHolder;
|
||||||
|
import com.ecep.contract.SpringApp;
|
||||||
|
import com.ecep.contract.ds.company.service.CompanyService;
|
||||||
|
import com.ecep.contract.ds.other.service.EmployeeService;
|
||||||
import com.ecep.contract.ds.other.service.SysConfService;
|
import com.ecep.contract.ds.other.service.SysConfService;
|
||||||
import com.ecep.contract.util.MyStringUtils;
|
import com.ecep.contract.util.MyStringUtils;
|
||||||
import com.ecep.contract.util.NumberUtils;
|
import com.ecep.contract.util.NumberUtils;
|
||||||
@@ -24,18 +28,35 @@ import lombok.Getter;
|
|||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
public class AbstractCtx {
|
public class AbstractCtx {
|
||||||
@Setter
|
|
||||||
SysConfService confService;
|
|
||||||
|
|
||||||
@Setter
|
@Setter
|
||||||
@Getter
|
@Getter
|
||||||
Locale locale = Locale.getDefault();
|
Locale locale = Locale.getDefault();
|
||||||
|
private Map<Class<?>, Object> cachedBeans = new HashMap<>();
|
||||||
|
|
||||||
|
public <T> T getBean(Class<T> requiredType) throws BeansException {
|
||||||
|
return SpringApp.getBean(requiredType);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public <T> T getCachedBean(Class<T> requiredType) throws BeansException {
|
||||||
|
Object object = cachedBeans.get(requiredType);
|
||||||
|
if (object == null) {
|
||||||
|
object = getBean(requiredType);
|
||||||
|
cachedBeans.put(requiredType, object);
|
||||||
|
}
|
||||||
|
return (T) object;
|
||||||
|
}
|
||||||
|
|
||||||
public SysConfService getConfService() {
|
public SysConfService getConfService() {
|
||||||
if (confService == null) {
|
return getCachedBean(SysConfService.class);
|
||||||
confService = getBean(SysConfService.class);
|
}
|
||||||
}
|
|
||||||
return confService;
|
public CompanyService getCompanyService() {
|
||||||
|
return getCachedBean(CompanyService.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EmployeeService getEmployeeService() {
|
||||||
|
return getCachedBean(EmployeeService.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean updateText(Supplier<String> getter, Consumer<String> setter, String text, MessageHolder holder,
|
public boolean updateText(Supplier<String> getter, Consumer<String> setter, String text, MessageHolder holder,
|
||||||
|
|||||||
@@ -205,10 +205,6 @@ public class YongYouU8Service implements IEntityService<CloudYu>, QueryService<C
|
|||||||
|
|
||||||
public void initialize(AbstractYongYouU8Ctx ctx) {
|
public void initialize(AbstractYongYouU8Ctx ctx) {
|
||||||
ctx.setRepository(repository);
|
ctx.setRepository(repository);
|
||||||
ctx.setCompanyService(companyService);
|
|
||||||
ctx.setEmployeeService(employeeService);
|
|
||||||
ctx.setCompanyVendorService(companyVendorService);
|
|
||||||
ctx.setCompanyCustomerService(companyCustomerService);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Iterable<CloudInfo> findAllCloudYu() {
|
public Iterable<CloudInfo> findAllCloudYu() {
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package com.ecep.contract.cloud.u8.ctx;
|
package com.ecep.contract.cloud.u8.ctx;
|
||||||
|
|
||||||
import static com.ecep.contract.SpringApp.getBean;
|
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
@@ -17,7 +15,6 @@ import com.ecep.contract.constant.CloudServiceConstant;
|
|||||||
import com.ecep.contract.ds.company.service.CompanyService;
|
import com.ecep.contract.ds.company.service.CompanyService;
|
||||||
import com.ecep.contract.ds.customer.service.CompanyCustomerEntityService;
|
import com.ecep.contract.ds.customer.service.CompanyCustomerEntityService;
|
||||||
import com.ecep.contract.ds.customer.service.CompanyCustomerService;
|
import com.ecep.contract.ds.customer.service.CompanyCustomerService;
|
||||||
import com.ecep.contract.ds.other.service.EmployeeService;
|
|
||||||
import com.ecep.contract.ds.vendor.service.CompanyVendorEntityService;
|
import com.ecep.contract.ds.vendor.service.CompanyVendorEntityService;
|
||||||
import com.ecep.contract.ds.vendor.service.CompanyVendorService;
|
import com.ecep.contract.ds.vendor.service.CompanyVendorService;
|
||||||
import com.ecep.contract.model.Company;
|
import com.ecep.contract.model.Company;
|
||||||
@@ -34,26 +31,9 @@ public class AbstractYongYouU8Ctx extends AbstractCtx {
|
|||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
YongYouU8Repository repository;
|
YongYouU8Repository repository;
|
||||||
@Setter
|
|
||||||
CompanyService companyService;
|
|
||||||
@Setter
|
|
||||||
EmployeeService employeeService;
|
|
||||||
@Setter
|
|
||||||
CompanyCustomerService companyCustomerService;
|
|
||||||
@Setter
|
|
||||||
CompanyCustomerEntityService companyCustomerEntityService;
|
|
||||||
@Setter
|
|
||||||
CompanyVendorService companyVendorService;
|
|
||||||
@Setter
|
|
||||||
CompanyVendorEntityService companyVendorEntityService;
|
|
||||||
|
|
||||||
|
|
||||||
public void from(AbstractYongYouU8Ctx parent) {
|
public void from(AbstractYongYouU8Ctx parent) {
|
||||||
repository = parent.repository;
|
repository = parent.repository;
|
||||||
companyService = parent.companyService;
|
|
||||||
employeeService = parent.employeeService;
|
|
||||||
companyCustomerService = parent.companyCustomerService;
|
|
||||||
companyVendorService = parent.companyVendorService;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initializeRepository(MessageHolder holder) {
|
public void initializeRepository(MessageHolder holder) {
|
||||||
@@ -67,50 +47,28 @@ public class AbstractYongYouU8Ctx extends AbstractCtx {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public CompanyService getCompanyService() {
|
public CompanyService getCompanyService() {
|
||||||
if (companyService == null) {
|
return getCachedBean(CompanyService.class);
|
||||||
companyService = getBean(CompanyService.class);
|
|
||||||
}
|
|
||||||
return companyService;
|
|
||||||
}
|
|
||||||
|
|
||||||
EmployeeService getEmployeeService() {
|
|
||||||
if (employeeService == null) {
|
|
||||||
employeeService = getBean(EmployeeService.class);
|
|
||||||
}
|
|
||||||
return employeeService;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public CompanyCustomerService getCompanyCustomerService() {
|
public CompanyCustomerService getCompanyCustomerService() {
|
||||||
if (companyCustomerService == null) {
|
return getCachedBean(CompanyCustomerService.class);
|
||||||
companyCustomerService = getBean(CompanyCustomerService.class);
|
|
||||||
}
|
|
||||||
return companyCustomerService;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public CompanyCustomerEntityService getCompanyCustomerEntityService() {
|
public CompanyCustomerEntityService getCompanyCustomerEntityService() {
|
||||||
if (companyCustomerEntityService == null) {
|
return getCachedBean(CompanyCustomerEntityService.class);
|
||||||
companyCustomerEntityService = getBean(CompanyCustomerEntityService.class);
|
|
||||||
}
|
|
||||||
return companyCustomerEntityService;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public CompanyVendorService getCompanyVendorService() {
|
public CompanyVendorService getCompanyVendorService() {
|
||||||
if (companyVendorService == null) {
|
return getCachedBean(CompanyVendorService.class);
|
||||||
companyVendorService = getBean(CompanyVendorService.class);
|
|
||||||
}
|
|
||||||
return companyVendorService;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public CompanyVendorEntityService getCompanyVendorEntityService() {
|
public CompanyVendorEntityService getCompanyVendorEntityService() {
|
||||||
if (companyVendorEntityService == null) {
|
return getCachedBean(CompanyVendorEntityService.class);
|
||||||
companyVendorEntityService = getBean(CompanyVendorEntityService.class);
|
|
||||||
}
|
|
||||||
return companyVendorEntityService;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean updateEmployeeByCode(Supplier<Employee> getter, Consumer<Employee> setter, String code, MessageHolder holder, String topic) {
|
boolean updateEmployeeByCode(Supplier<Employee> getter, Consumer<Employee> setter, String code,
|
||||||
|
MessageHolder holder, String topic) {
|
||||||
if (StringUtils.hasText(code)) {
|
if (StringUtils.hasText(code)) {
|
||||||
Employee employee = getEmployeeService().findByCode(code);
|
Employee employee = getEmployeeService().findByCode(code);
|
||||||
if (employee != null) {
|
if (employee != null) {
|
||||||
@@ -124,8 +82,8 @@ public class AbstractYongYouU8Ctx extends AbstractCtx {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean updateEmployeeByName(Supplier<Employee> getter, Consumer<Employee> setter, String name,
|
||||||
boolean updateEmployeeByName(Supplier<Employee> getter, Consumer<Employee> setter, String name, MessageHolder holder, String topic) {
|
MessageHolder holder, String topic) {
|
||||||
if (StringUtils.hasText(name)) {
|
if (StringUtils.hasText(name)) {
|
||||||
Employee employee = getEmployeeService().findByName(name);
|
Employee employee = getEmployeeService().findByName(name);
|
||||||
if (employee != null) {
|
if (employee != null) {
|
||||||
@@ -139,7 +97,8 @@ public class AbstractYongYouU8Ctx extends AbstractCtx {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean updateCompanyByCustomerCode(Supplier<Company> getter, Consumer<Company> setter, String customerCode, MessageHolder holder, String topic) {
|
boolean updateCompanyByCustomerCode(Supplier<Company> getter, Consumer<Company> setter, String customerCode,
|
||||||
|
MessageHolder holder, String topic) {
|
||||||
Company company = null;
|
Company company = null;
|
||||||
if (StringUtils.hasText(customerCode)) {
|
if (StringUtils.hasText(customerCode)) {
|
||||||
CompanyCustomerEntityService customerEntityService = getCompanyCustomerEntityService();
|
CompanyCustomerEntityService customerEntityService = getCompanyCustomerEntityService();
|
||||||
@@ -176,8 +135,8 @@ public class AbstractYongYouU8Ctx extends AbstractCtx {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean updateCompanyByVendorCode(Supplier<Company> getter, Consumer<Company> setter, String vendorCode,
|
||||||
boolean updateCompanyByVendorCode(Supplier<Company> getter, Consumer<Company> setter, String vendorCode, MessageHolder holder, String topic) {
|
MessageHolder holder, String topic) {
|
||||||
Company company = null;
|
Company company = null;
|
||||||
if (StringUtils.hasText(vendorCode)) {
|
if (StringUtils.hasText(vendorCode)) {
|
||||||
CompanyVendorEntityService vendorEntityService = getCompanyVendorEntityService();
|
CompanyVendorEntityService vendorEntityService = getCompanyVendorEntityService();
|
||||||
@@ -214,5 +173,4 @@ public class AbstractYongYouU8Ctx extends AbstractCtx {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package com.ecep.contract.cloud.u8.ctx;
|
package com.ecep.contract.cloud.u8.ctx;
|
||||||
|
|
||||||
import static com.ecep.contract.SpringApp.getBean;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.text.NumberFormat;
|
import java.text.NumberFormat;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
@@ -30,6 +28,7 @@ import com.ecep.contract.MyDateTimeUtils;
|
|||||||
import com.ecep.contract.constant.CloudServiceConstant;
|
import com.ecep.contract.constant.CloudServiceConstant;
|
||||||
import com.ecep.contract.ds.company.CompanyFileUtils;
|
import com.ecep.contract.ds.company.CompanyFileUtils;
|
||||||
import com.ecep.contract.ds.contract.service.ContractFileService;
|
import com.ecep.contract.ds.contract.service.ContractFileService;
|
||||||
|
import com.ecep.contract.ds.contract.service.ContractFileTypeService;
|
||||||
import com.ecep.contract.ds.contract.service.ContractItemService;
|
import com.ecep.contract.ds.contract.service.ContractItemService;
|
||||||
import com.ecep.contract.ds.contract.service.ContractPayPlanService;
|
import com.ecep.contract.ds.contract.service.ContractPayPlanService;
|
||||||
import com.ecep.contract.ds.contract.service.ContractService;
|
import com.ecep.contract.ds.contract.service.ContractService;
|
||||||
@@ -66,16 +65,6 @@ import lombok.Setter;
|
|||||||
* 合同上下文
|
* 合同上下文
|
||||||
*/
|
*/
|
||||||
public class ContractCtx extends AbstractYongYouU8Ctx {
|
public class ContractCtx extends AbstractYongYouU8Ctx {
|
||||||
@Setter
|
|
||||||
private ContractService contractService;
|
|
||||||
@Setter
|
|
||||||
private ContractItemService contractItemService;
|
|
||||||
@Setter
|
|
||||||
private ContractFileService contractFileService;
|
|
||||||
@Setter
|
|
||||||
private ContractPayPlanService contractPayPlanService;
|
|
||||||
@Setter
|
|
||||||
private SaleTypeService saleTypeService;
|
|
||||||
@Setter
|
@Setter
|
||||||
private VendorCtx vendorCtx;
|
private VendorCtx vendorCtx;
|
||||||
@Setter
|
@Setter
|
||||||
@@ -92,38 +81,25 @@ public class ContractCtx extends AbstractYongYouU8Ctx {
|
|||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
private int customerEntityUpdateDelayDays = 1;
|
private int customerEntityUpdateDelayDays = 1;
|
||||||
|
|
||||||
public ContractService getContractService() {
|
public ContractService getContractService() {
|
||||||
if (contractService == null) {
|
return getCachedBean(ContractService.class);
|
||||||
contractService = getBean(ContractService.class);
|
|
||||||
}
|
|
||||||
return contractService;
|
|
||||||
}
|
|
||||||
ContractItemService getContractItemService() {
|
|
||||||
if (contractItemService == null) {
|
|
||||||
contractItemService = getBean(ContractItemService.class);
|
|
||||||
}
|
|
||||||
return contractItemService;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ContractPayPlanService getContractPayPlanService() {
|
public ContractItemService getContractItemService() {
|
||||||
if (contractPayPlanService == null) {
|
return getCachedBean(ContractItemService.class);
|
||||||
contractPayPlanService = getBean(ContractPayPlanService.class);
|
|
||||||
}
|
|
||||||
return contractPayPlanService;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ContractFileService getContractFileService() {
|
public ContractPayPlanService getContractPayPlanService() {
|
||||||
if (contractFileService == null) {
|
return getCachedBean(ContractPayPlanService.class);
|
||||||
contractFileService = getBean(ContractFileService.class);
|
|
||||||
}
|
|
||||||
return contractFileService;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SaleTypeService getSaleTypeService() {
|
public ContractFileService getContractFileService() {
|
||||||
if (saleTypeService == null) {
|
return getCachedBean(ContractFileService.class);
|
||||||
saleTypeService = getBean(SaleTypeService.class);
|
}
|
||||||
}
|
|
||||||
return saleTypeService;
|
public SaleTypeService getSaleTypeService() {
|
||||||
|
return getCachedBean(SaleTypeService.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
VendorCtx getVendorCtx() {
|
VendorCtx getVendorCtx() {
|
||||||
@@ -1223,8 +1199,8 @@ public class ContractCtx extends AbstractYongYouU8Ctx {
|
|||||||
MyDateTimeUtils.pickLocalDate(file.getName()), holder, "生效日期");
|
MyDateTimeUtils.pickLocalDate(file.getName()), holder, "生效日期");
|
||||||
}
|
}
|
||||||
|
|
||||||
List<ContractFileTypeLocal> matched = getContractFileService()
|
List<ContractFileTypeLocal> matched = getCachedBean(ContractFileTypeService.class)
|
||||||
.findAllFileTypes(Locale.getDefault().toLanguageTag()).values().stream()
|
.findAll(getLocale()).values().stream()
|
||||||
.filter(local -> {
|
.filter(local -> {
|
||||||
if (payWay == ContractPayWay.PAY) {
|
if (payWay == ContractPayWay.PAY) {
|
||||||
return local.getType().isSupportVendor();
|
return local.getType().isSupportVendor();
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ public class ContractService implements IEntityService<Contract>, QueryService<C
|
|||||||
}
|
}
|
||||||
|
|
||||||
// field
|
// field
|
||||||
spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "parentCode");
|
spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "payWay", "parentCode");
|
||||||
|
|
||||||
// relation
|
// relation
|
||||||
spec = SpecificationUtils.andParam(spec, paramsNode, "group", "kind", "type", "group", "company", "project");
|
spec = SpecificationUtils.andParam(spec, paramsNode, "group", "kind", "type", "group", "company", "project");
|
||||||
|
|||||||
@@ -77,10 +77,6 @@ public abstract class AbstContractRepairTasker extends Tasker<Object> {
|
|||||||
return purchaseBillVoucherCtx;
|
return purchaseBillVoucherCtx;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setContractService(ContractService contractService) {
|
|
||||||
contractCtx.setContractService(contractService);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Object execute(MessageHolder holder) throws Exception {
|
protected Object execute(MessageHolder holder) throws Exception {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ public class ContractFilesRebuildAllTasker extends Tasker<Object> {
|
|||||||
ContractCtx getContractCtx() {
|
ContractCtx getContractCtx() {
|
||||||
if (contractCtx == null) {
|
if (contractCtx == null) {
|
||||||
contractCtx = new ContractCtx();
|
contractCtx = new ContractCtx();
|
||||||
contractCtx.setContractService(getContractService());
|
|
||||||
}
|
}
|
||||||
return contractCtx;
|
return contractCtx;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,11 @@
|
|||||||
package com.ecep.contract.ds.project;
|
package com.ecep.contract.ds.project;
|
||||||
|
|
||||||
import static com.ecep.contract.SpringApp.getBean;
|
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import org.hibernate.Hibernate;
|
import org.hibernate.Hibernate;
|
||||||
|
|
||||||
import com.ecep.contract.MessageHolder;
|
import com.ecep.contract.MessageHolder;
|
||||||
import com.ecep.contract.cloud.AbstractCtx;
|
import com.ecep.contract.cloud.AbstractCtx;
|
||||||
import com.ecep.contract.ds.company.service.CompanyService;
|
|
||||||
import com.ecep.contract.ds.project.service.ProjectService;
|
import com.ecep.contract.ds.project.service.ProjectService;
|
||||||
import com.ecep.contract.model.Company;
|
import com.ecep.contract.model.Company;
|
||||||
import com.ecep.contract.model.Project;
|
import com.ecep.contract.model.Project;
|
||||||
@@ -18,8 +15,7 @@ import lombok.Setter;
|
|||||||
public class ProjectCtx extends AbstractCtx {
|
public class ProjectCtx extends AbstractCtx {
|
||||||
@Setter
|
@Setter
|
||||||
private ProjectService projectService;
|
private ProjectService projectService;
|
||||||
@Setter
|
|
||||||
CompanyService companyService;
|
|
||||||
|
|
||||||
ProjectService getProjectService() {
|
ProjectService getProjectService() {
|
||||||
if (projectService == null) {
|
if (projectService == null) {
|
||||||
@@ -28,13 +24,6 @@ public class ProjectCtx extends AbstractCtx {
|
|||||||
return projectService;
|
return projectService;
|
||||||
}
|
}
|
||||||
|
|
||||||
CompanyService getCompanyService() {
|
|
||||||
if (companyService == null) {
|
|
||||||
companyService = getBean(CompanyService.class);
|
|
||||||
}
|
|
||||||
return companyService;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean updateCustomer(Project project, Company customer, MessageHolder holder) {
|
public boolean updateCustomer(Project project, Company customer, MessageHolder holder) {
|
||||||
boolean modified = false;
|
boolean modified = false;
|
||||||
if (!Objects.equals(project.getCustomer(), customer)) {
|
if (!Objects.equals(project.getCustomer(), customer)) {
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ import org.apache.poi.ss.formula.functions.T;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.security.authentication.AuthenticationManager;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.socket.BinaryMessage;
|
import org.springframework.web.socket.BinaryMessage;
|
||||||
import org.springframework.web.socket.CloseStatus;
|
import org.springframework.web.socket.CloseStatus;
|
||||||
@@ -27,6 +29,7 @@ import org.springframework.web.socket.handler.TextWebSocketHandler;
|
|||||||
|
|
||||||
import com.ecep.contract.IEntityService;
|
import com.ecep.contract.IEntityService;
|
||||||
import com.ecep.contract.PageArgument;
|
import com.ecep.contract.PageArgument;
|
||||||
|
import com.ecep.contract.PageContent;
|
||||||
import com.ecep.contract.QueryService;
|
import com.ecep.contract.QueryService;
|
||||||
import com.ecep.contract.SpringApp;
|
import com.ecep.contract.SpringApp;
|
||||||
import com.ecep.contract.ds.other.service.EmployeeLoginHistoryService;
|
import com.ecep.contract.ds.other.service.EmployeeLoginHistoryService;
|
||||||
@@ -48,6 +51,8 @@ import lombok.Data;
|
|||||||
@Component
|
@Component
|
||||||
public class WebSocketHandler extends TextWebSocketHandler {
|
public class WebSocketHandler extends TextWebSocketHandler {
|
||||||
|
|
||||||
|
private final AuthenticationManager authenticationManager;
|
||||||
|
|
||||||
private final ObjectMapper objectMapper;
|
private final ObjectMapper objectMapper;
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(WebSocketHandler.class);
|
private static final Logger logger = LoggerFactory.getLogger(WebSocketHandler.class);
|
||||||
@@ -78,8 +83,9 @@ public class WebSocketHandler extends TextWebSocketHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
WebSocketHandler(ObjectMapper objectMapper) {
|
WebSocketHandler(ObjectMapper objectMapper, AuthenticationManager authenticationManager) {
|
||||||
this.objectMapper = objectMapper;
|
this.objectMapper = objectMapper;
|
||||||
|
this.authenticationManager = authenticationManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -317,7 +323,8 @@ public class WebSocketHandler extends TextWebSocketHandler {
|
|||||||
JsonNode pageableNode = argumentsNode.get(1);
|
JsonNode pageableNode = argumentsNode.get(1);
|
||||||
PageArgument pageArgument = objectMapper.treeToValue(pageableNode, PageArgument.class);
|
PageArgument pageArgument = objectMapper.treeToValue(pageableNode, PageArgument.class);
|
||||||
QueryService<?> entityService = (QueryService<?>) service;
|
QueryService<?> entityService = (QueryService<?>) service;
|
||||||
return entityService.findAll(paramsNode, pageArgument.toPageable());
|
Page<?> page = entityService.findAll(paramsNode, pageArgument.toPageable());
|
||||||
|
return PageContent.of(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendError(WebSocketSession session, String messageId, String message) {
|
private void sendError(WebSocketSession session, String messageId, String message) {
|
||||||
|
|||||||
Reference in New Issue
Block a user