From 553feac0a4100808cefabc475cb4dcc28f7bfbfe Mon Sep 17 00:00:00 2001 From: songqq Date: Sat, 11 Oct 2025 09:21:14 +0800 Subject: [PATCH] UP --- .trae/rules/project_rules.md | 2 +- client/pom.xml | 6 +- .../contract/controller/BaseController.java | 5 +- .../company/CompanyWindowController.java | 8 +- .../ContractVerifyWindowController.java | 15 +- .../AbstCompanyCustomerTableTabSkin.java | 10 +- ...merEvaluationFormFileWindowController.java | 6 +- .../CompanyCustomerExportExcelTasker.java | 16 +- .../customer/CompanyCustomerManagerSkin.java | 8 +- ...ompanyCustomerManagerWindowController.java | 14 +- .../CompanyCustomerWindowController.java | 14 +- ...SkinBase.java => CustomerTabSkinBase.java} | 52 +- .../customer/CustomerTabSkinEntity.java | 4 +- .../customer/CustomerTabSkinFile.java | 106 ++-- .../CustomerTabSkinSatisfactionSurvey.java | 4 +- .../CustomerEvaluationFormUpdateTask.java} | 10 +- .../CustomerNextSignDateTask.java} | 12 +- .../tasker/CustomerRebuildFilesTasker.java} | 11 +- .../controller/project/ProjectTabSkinBid.java | 8 +- ...jectTabSkinCustomerSatisfactionSurvey.java | 8 +- .../project/ProjectTabSkinQuotation.java | 8 +- .../project/bid/ProjectBidTabSkinBase.java | 12 +- .../ProjectQuotationTabSkinBase.java | 8 +- ...CustomerSatisfactionSurveyTabSkinBase.java | 18 +- .../controller/tab/CompanyTabSkinFile.java | 4 +- .../controller/tab/ContractTabSkinBase.java | 8 +- .../controller/tab/ContractUpdater.java | 4 +- .../table/cell/CompanyFilePathTableCell.java | 36 -- .../table/cell/EvaluationFileTableCell.java | 4 +- .../table/cell/FilePathTableCell.java | 16 +- .../vendor/VendorManagerWindowController.java | 6 +- .../vendor/VendorNextSignDateTask.java | 34 ++ .../controller/vendor/VendorTabSkinBase.java | 42 +- .../controller/vendor/VendorTabSkinFile.java | 120 ++--- .../CompanyCustomerStringConverter.java | 8 +- .../contract/service/CloudTycService.java | 2 + .../service/CompanyCustomerEntityService.java | 4 +- ...panyCustomerEvaluationFormFileService.java | 4 +- .../service/CompanyCustomerFileService.java | 24 +- ...tomerService.java => CustomerService.java} | 21 +- .../contract/service/VendorFileService.java | 47 +- .../ecep/contract/service/VendorService.java | 5 - .../ecep/contract/task/CloudRkSyncTask.java | 6 +- .../contract/task/CompanyRkUpdateTasker.java | 3 +- ...CompanyVendorEvaluationFormUpdateTask.java | 20 +- .../contract/task/ContractVerifyComm.java | 165 ++---- .../task/VendorReBuildFilesTasker.java | 53 +- .../com/ecep/contract/util/ParamUtils.java | 38 +- .../contract/vm/CompanyCustomerViewModel.java | 10 +- ...wModel.java => CustomerFileViewModel.java} | 12 +- .../ui/company/vendor/vendor-tab-file.fxml | 6 + .../sale-orders-tab-bill-voucher.fxml | 2 +- .../ui/contract/sale-orders-tab-item.fxml | 2 +- common/pom.xml | 4 +- .../com/ecep/contract/util/ContextUtils.java | 5 + .../com/ecep/contract/util/FileUtils.java | 24 + ...ustomerFileVo.java => CustomerFileVo.java} | 2 +- ...CompanyCustomerVo.java => CustomerVo.java} | 2 +- .../ecep/contract/vo/SalesBillVoucherVo.java | 1 - pom.xml | 2 +- server/pom.xml | 6 +- .../cloud/old/OldVersionSyncCustomerTask.java | 4 +- .../contract/cloud/rk/CloudRkRepository.java | 9 +- .../contract/cloud/rk/CloudRkService.java | 8 +- .../contract/cloud/rk/ctx/CloudRkCtx.java | 7 +- .../cloud/u8/CustomerClassSyncTask.java | 8 +- .../contract/cloud/u8/CustomerSyncTask.java | 4 +- .../cloud/u8/ctx/AbstractYongYouU8Ctx.java | 10 +- .../contract/cloud/u8/ctx/ContractCtx.java | 6 +- .../repository/CompanyContactRepository.java | 2 + .../company/service/CompanyBasicService.java | 20 +- .../service/CompanyContactService.java | 5 + .../ds/company/service/CompanyService.java | 8 +- .../ds/contract/service/ContractService.java | 11 + .../ds/customer/model/CompanyCustomer.java | 8 +- .../customer/model/CompanyCustomerFile.java | 8 +- .../ds/customer/model/SalesBillVoucher.java | 1 - .../service/CompanyCustomerEntityService.java | 2 +- .../service/CompanyCustomerFileService.java | 15 +- ...tomerService.java => CustomerService.java} | 16 +- .../repository/VendorFileRepository.java | 2 + .../ds/vendor/service/VendorFileService.java | 59 ++- .../ds/vendor/service/VendorService.java | 12 +- .../vendor/task/VendorReBuildFilesTasker.java | 489 ++++++++++++++++++ ...mpanyCustomerEvaluationFormUpdateTask.java | 132 ++++- .../CompanyCustomerNextSignDateTask.java | 8 +- .../CompanyCustomerRebuildFilesTasker.java | 6 +- .../service/tasker/CompanyRkUpdateTasker.java | 7 +- ...CompanyVendorEvaluationFormUpdateTask.java | 282 ++++++++++ .../tasker/CustomerFileMoveTasker.java | 6 +- .../tasker/VendorNextSignDateTask.java | 121 +++++ .../com/ecep/contract/util/VerifyContext.java | 6 +- server/src/main/resources/tasker_mapper.json | 13 +- 93 files changed, 1736 insertions(+), 676 deletions(-) rename client/src/main/java/com/ecep/contract/controller/customer/{CompanyCustomerTabSkinBase.java => CustomerTabSkinBase.java} (76%) rename client/src/main/java/com/ecep/contract/controller/customer/{CompanyCustomerEvaluationFormUpdateTask.java => tasker/CustomerEvaluationFormUpdateTask.java} (67%) rename client/src/main/java/com/ecep/contract/controller/customer/{CompanyCustomerNextSignDateTask.java => tasker/CustomerNextSignDateTask.java} (68%) rename client/src/main/java/com/ecep/contract/{task/CompanyCustomerRebuildFilesTasker.java => controller/customer/tasker/CustomerRebuildFilesTasker.java} (69%) delete mode 100644 client/src/main/java/com/ecep/contract/controller/table/cell/CompanyFilePathTableCell.java create mode 100644 client/src/main/java/com/ecep/contract/controller/vendor/VendorNextSignDateTask.java rename client/src/main/java/com/ecep/contract/service/{CompanyCustomerService.java => CustomerService.java} (84%) rename client/src/main/java/com/ecep/contract/vm/{CompanyCustomerFileViewModel.java => CustomerFileViewModel.java} (84%) rename common/src/main/java/com/ecep/contract/vo/{CompanyCustomerFileVo.java => CustomerFileVo.java} (86%) rename common/src/main/java/com/ecep/contract/vo/{CompanyCustomerVo.java => CustomerVo.java} (86%) rename server/src/main/java/com/ecep/contract/ds/customer/service/{CompanyCustomerService.java => CustomerService.java} (97%) create mode 100644 server/src/main/java/com/ecep/contract/ds/vendor/task/VendorReBuildFilesTasker.java create mode 100644 server/src/main/java/com/ecep/contract/service/tasker/CompanyVendorEvaluationFormUpdateTask.java create mode 100644 server/src/main/java/com/ecep/contract/service/tasker/VendorNextSignDateTask.java diff --git a/.trae/rules/project_rules.md b/.trae/rules/project_rules.md index d2cc6ec..a461be5 100644 --- a/.trae/rules/project_rules.md +++ b/.trae/rules/project_rules.md @@ -60,7 +60,7 @@ - `customer/`: 客户相关业务 - `project/`: 项目相关业务 - `vendor/`: 供应商相关业务 - - 每个业务领域包含:`model/`(实体类)、`repository/`(数据访问接口)、`service/`(业务逻辑, 详细规范见 `.trae\rules\server_service_rules.md`)、`tasker/`(任务处理器)、`controller/`(控制器) + - 每个业务领域包含:`model/`(实体类)、`repository/`(数据访问接口)、`service/`(业务逻辑, 详细规范见 `.trae\rules\server_service_rules.md`)、`tasker/`(任务处理器, 详细规范见 `.trae\rules\server_tasker_rules.md`)、`controller/`(控制器, 详细规范见 `.trae\rules\server_controller_rules.md`) - `handler/`: WebSocket处理器 - `service/`: 服务层,包含一些通用服务和任务处理器 - `ui/`: UI相关组件 diff --git a/client/pom.xml b/client/pom.xml index 09e056b..28831e4 100644 --- a/client/pom.xml +++ b/client/pom.xml @@ -6,12 +6,12 @@ com.ecep.contract Contract-Manager - 0.0.101-SNAPSHOT + 0.0.102-SNAPSHOT com.ecep.contract client - 0.0.101-SNAPSHOT + 0.0.102-SNAPSHOT ${java.version} @@ -22,7 +22,7 @@ com.ecep.contract common - 0.0.101-SNAPSHOT + 0.0.102-SNAPSHOT org.springframework.boot diff --git a/client/src/main/java/com/ecep/contract/controller/BaseController.java b/client/src/main/java/com/ecep/contract/controller/BaseController.java index 1ed1cea..dc6a611 100644 --- a/client/src/main/java/com/ecep/contract/controller/BaseController.java +++ b/client/src/main/java/com/ecep/contract/controller/BaseController.java @@ -9,6 +9,7 @@ import java.util.Locale; import java.util.concurrent.CompletableFuture; import java.util.function.Consumer; +import com.ecep.contract.util.ContextUtils; import com.ecep.contract.util.FxmlPath; import com.ecep.contract.util.FxmlUtils; import com.ecep.contract.vo.EmployeeVo; @@ -41,7 +42,7 @@ import javafx.stage.Window; import javafx.stage.WindowEvent; import lombok.Getter; -public class BaseController { +public class BaseController implements ContextUtils { private static final Logger logger = LoggerFactory.getLogger(BaseController.class); public static HashMap stages = new HashMap<>(); @@ -50,7 +51,7 @@ public class BaseController { } public static CompletableFuture show(Class clz, Window owner, - Consumer consumer) { + Consumer consumer) { String key = clz.getName(); if (toFront(key)) { return null; diff --git a/client/src/main/java/com/ecep/contract/controller/company/CompanyWindowController.java b/client/src/main/java/com/ecep/contract/controller/company/CompanyWindowController.java index e8fe9c7..60b375f 100644 --- a/client/src/main/java/com/ecep/contract/controller/company/CompanyWindowController.java +++ b/client/src/main/java/com/ecep/contract/controller/company/CompanyWindowController.java @@ -26,7 +26,7 @@ import com.ecep.contract.controller.tab.CompanyTabSkinOldName; import com.ecep.contract.controller.tab.CompanyTabSkinOther; import com.ecep.contract.controller.tab.CompanyTabSkinPurchaseBillVoucher; import com.ecep.contract.controller.vendor.VendorWindowController; -import com.ecep.contract.service.CompanyCustomerService; +import com.ecep.contract.service.CustomerService; import com.ecep.contract.service.CompanyService; import com.ecep.contract.service.VendorService; import com.ecep.contract.task.CompanyCompositeUpdateTasker; @@ -34,7 +34,7 @@ import com.ecep.contract.task.CompanyVerifyTasker; import com.ecep.contract.util.FxmlPath; import com.ecep.contract.util.UITools; import com.ecep.contract.vm.CompanyViewModel; -import com.ecep.contract.vo.CompanyCustomerVo; +import com.ecep.contract.vo.CustomerVo; import com.ecep.contract.vo.VendorVo; import com.ecep.contract.vo.CompanyVo; @@ -124,7 +124,7 @@ public class CompanyWindowController // private final CompanyVendorViewModel companyVendorViewModel = new // CompanyVendorViewModel(); - private final SimpleObjectProperty companyCustomerProperty = new SimpleObjectProperty<>(); + private final SimpleObjectProperty companyCustomerProperty = new SimpleObjectProperty<>(); private final SimpleObjectProperty companyVendorProperty = new SimpleObjectProperty<>(); public Pane customerTab_pane1; @@ -202,7 +202,7 @@ public class CompanyWindowController logger.debug("onCustomerTabShown"); } getLoadedFuture().thenAcceptAsync(company -> { - CompanyCustomerVo customerVo = getCachedBean(CompanyCustomerService.class).findByCompany(company); + CustomerVo customerVo = getCachedBean(CustomerService.class).findByCompany(company); companyCustomerProperty.set(customerVo); }).exceptionally(ex -> { UITools.showExceptionAndWait(ex.getMessage(), ex); diff --git a/client/src/main/java/com/ecep/contract/controller/contract/ContractVerifyWindowController.java b/client/src/main/java/com/ecep/contract/controller/contract/ContractVerifyWindowController.java index d9c8fde..4a9b12c 100644 --- a/client/src/main/java/com/ecep/contract/controller/contract/ContractVerifyWindowController.java +++ b/client/src/main/java/com/ecep/contract/controller/contract/ContractVerifyWindowController.java @@ -158,16 +158,10 @@ public class ContractVerifyWindowController extends BaseController { } } - ContractVerifyComm comm = new ContractVerifyComm(); + ContractVerifyComm comm = new ContractVerifyComm(this); - @Autowired - private ProjectSaleTypeService saleTypeService; - @Autowired - private VendorGroupService vendorGroupService; @Autowired private ContractService contractService; - @Autowired - private EmployeeService employeeService; @FXML public DatePicker setupDateBeginSelector; @@ -218,7 +212,6 @@ public class ContractVerifyWindowController extends BaseController { public void onShown(WindowEvent windowEvent) { super.onShown(windowEvent); - comm.setContractService(contractService); viewTable.getScene().getStylesheets().add("/ui/contract/contract-verify.css"); LocalDate now = LocalDate.now(); @@ -230,11 +223,7 @@ public class ContractVerifyWindowController extends BaseController { viewTable_employeeColumn.setCellValueFactory(param -> param.getValue().getEmployee()); viewTable_employeeColumn.setCellFactory(param -> new EmployeeTableCell<>(getEmployeeService())); viewTable_setupDateColumn.setCellValueFactory(param -> param.getValue().getSetupDate()); - // viewTable_stateColumn.setCellValueFactory(param -> - // param.getValue().getMessages().map(messages -> { - // return - // messages.stream().map(Message::getMessage).collect(Collectors.joining(", ")); - // })); + viewTable_stateColumn.setCellValueFactory(param -> param.getValue().getMessages()); viewTable_stateColumn.setCellFactory(param -> new StateTableCell()); diff --git a/client/src/main/java/com/ecep/contract/controller/customer/AbstCompanyCustomerTableTabSkin.java b/client/src/main/java/com/ecep/contract/controller/customer/AbstCompanyCustomerTableTabSkin.java index 00d86d1..0e5dba1 100644 --- a/client/src/main/java/com/ecep/contract/controller/customer/AbstCompanyCustomerTableTabSkin.java +++ b/client/src/main/java/com/ecep/contract/controller/customer/AbstCompanyCustomerTableTabSkin.java @@ -3,15 +3,15 @@ package com.ecep.contract.controller.customer; import com.ecep.contract.controller.tab.TabSkin; import com.ecep.contract.controller.table.AbstEntityTableTabSkin; import com.ecep.contract.model.IdentityEntity; -import com.ecep.contract.service.CompanyCustomerService; +import com.ecep.contract.service.CustomerService; import com.ecep.contract.service.CompanyService; import com.ecep.contract.vm.CompanyCustomerViewModel; import com.ecep.contract.vm.IdentityViewModel; -import com.ecep.contract.vo.CompanyCustomerVo; +import com.ecep.contract.vo.CustomerVo; public abstract class AbstCompanyCustomerTableTabSkin> extends - AbstEntityTableTabSkin + AbstEntityTableTabSkin implements TabSkin { public AbstCompanyCustomerTableTabSkin(CompanyCustomerWindowController controller) { @@ -22,8 +22,8 @@ public abstract class AbstCompanyCustomerTableTabSkin { int id = viewModel.getId().get(); - CompanyCustomerFileVo customerFile = companyCustomerFileService.findById(id); + CustomerFileVo customerFile = companyCustomerFileService.findById(id); CompanyCustomerEvaluationFormFileVo formFile = evaluationFormFileService.findByCustomerFile(customerFile); Platform.runLater(() -> update(formFile)); return formFile; diff --git a/client/src/main/java/com/ecep/contract/controller/customer/CompanyCustomerExportExcelTasker.java b/client/src/main/java/com/ecep/contract/controller/customer/CompanyCustomerExportExcelTasker.java index 2c1214a..8825e2c 100644 --- a/client/src/main/java/com/ecep/contract/controller/customer/CompanyCustomerExportExcelTasker.java +++ b/client/src/main/java/com/ecep/contract/controller/customer/CompanyCustomerExportExcelTasker.java @@ -34,14 +34,14 @@ import com.ecep.contract.MyDateTimeUtils; import com.ecep.contract.service.CompanyCustomerEntityService; import com.ecep.contract.service.CompanyCustomerEvaluationFormFileService; import com.ecep.contract.service.CompanyCustomerFileService; -import com.ecep.contract.service.CompanyCustomerService; +import com.ecep.contract.service.CustomerService; import com.ecep.contract.task.Tasker; import com.ecep.contract.util.ExcelUtils; import com.ecep.contract.util.UITools; import com.ecep.contract.vo.CompanyCustomerEntityVo; import com.ecep.contract.vo.CompanyCustomerEvaluationFormFileVo; -import com.ecep.contract.vo.CompanyCustomerFileVo; -import com.ecep.contract.vo.CompanyCustomerVo; +import com.ecep.contract.vo.CustomerFileVo; +import com.ecep.contract.vo.CustomerVo; import com.ecep.contract.vo.CompanyVo; import lombok.Setter; @@ -52,14 +52,14 @@ public class CompanyCustomerExportExcelTasker extends Tasker { @Setter File destFile; - CompanyCustomerService customerService; + CustomerService customerService; CompanyCustomerEntityService customerEntityService; CompanyCustomerFileService customerFileService; CompanyCustomerEvaluationFormFileService customerEvaluationFormFileService; - CompanyCustomerService getCustomerService() { + CustomerService getCustomerService() { if (customerService == null) - customerService = getBean(CompanyCustomerService.class); + customerService = getBean(CustomerService.class); return customerService; } @@ -118,7 +118,7 @@ public class CompanyCustomerExportExcelTasker extends Tasker { setCellValue(sheet, "A19", "Build by CMS @ " + MyDateTimeUtils.format(LocalDateTime.now())); int rowIndex = 0; - for (CompanyCustomerVo customer : getCustomerService().findAll(null, Pageable.unpaged())) { + for (CustomerVo customer : getCustomerService().findAll(null, Pageable.unpaged())) { Integer companyId = customer.getCompanyId(); ; CompanyVo company = getCompanyService().findById(companyId); @@ -136,7 +136,7 @@ public class CompanyCustomerExportExcelTasker extends Tasker { } } - CompanyCustomerFileVo customerFile = getCustomerFileService() + CustomerFileVo customerFile = getCustomerFileService() .findAllByCustomer(customer).stream().filter(v -> v.isValid()) .max(Comparator.comparing(v -> v.getSignDate())).orElse(null); diff --git a/client/src/main/java/com/ecep/contract/controller/customer/CompanyCustomerManagerSkin.java b/client/src/main/java/com/ecep/contract/controller/customer/CompanyCustomerManagerSkin.java index 60b6e69..8d14526 100644 --- a/client/src/main/java/com/ecep/contract/controller/customer/CompanyCustomerManagerSkin.java +++ b/client/src/main/java/com/ecep/contract/controller/customer/CompanyCustomerManagerSkin.java @@ -4,18 +4,18 @@ import com.ecep.contract.MyDateTimeUtils; import com.ecep.contract.controller.AbstEntityManagerSkin; import com.ecep.contract.controller.table.cell.CompanyTableCell; import com.ecep.contract.controller.table.cell.CustomerCatalogTableCell; -import com.ecep.contract.service.CompanyCustomerService; +import com.ecep.contract.service.CustomerService; import com.ecep.contract.service.CompanyService; import com.ecep.contract.service.CustomerCatalogService; import com.ecep.contract.vm.CompanyCustomerViewModel; -import com.ecep.contract.vo.CompanyCustomerVo; +import com.ecep.contract.vo.CustomerVo; import com.ecep.contract.vo.CompanyVo; import javafx.application.Platform; public class CompanyCustomerManagerSkin extends - AbstEntityManagerSkin { + AbstEntityManagerSkin { public CompanyCustomerManagerSkin(CompanyCustomerManagerWindowController controller) { super(controller); @@ -25,7 +25,7 @@ public class CompanyCustomerManagerSkin return getBean(CompanyService.class); } - public CompanyCustomerService getCompanyCustomerService() { + public CustomerService getCompanyCustomerService() { return controller.getViewModelService(); } diff --git a/client/src/main/java/com/ecep/contract/controller/customer/CompanyCustomerManagerWindowController.java b/client/src/main/java/com/ecep/contract/controller/customer/CompanyCustomerManagerWindowController.java index 5b2a1af..848a123 100644 --- a/client/src/main/java/com/ecep/contract/controller/customer/CompanyCustomerManagerWindowController.java +++ b/client/src/main/java/com/ecep/contract/controller/customer/CompanyCustomerManagerWindowController.java @@ -5,7 +5,7 @@ import java.time.LocalDate; import java.util.concurrent.CompletableFuture; import java.util.concurrent.atomic.AtomicBoolean; -import com.ecep.contract.vo.CompanyCustomerVo; +import com.ecep.contract.vo.CustomerVo; import com.ecep.contract.vo.CompanyVo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy; @@ -17,7 +17,7 @@ import org.springframework.stereotype.Component; import com.ecep.contract.MyDateTimeUtils; import com.ecep.contract.controller.AbstManagerWindowController; -import com.ecep.contract.service.CompanyCustomerService; +import com.ecep.contract.service.CustomerService; import com.ecep.contract.service.CompanyService; import com.ecep.contract.util.FxmlPath; import com.ecep.contract.util.UITools; @@ -44,7 +44,7 @@ import javafx.stage.Stage; @Component @FxmlPath("/ui/company/customer/customer_manager.fxml") public class CompanyCustomerManagerWindowController - extends AbstManagerWindowController { + extends AbstManagerWindowController { // columns public TableColumn idColumn; @@ -59,8 +59,8 @@ public class CompanyCustomerManagerWindowController @Override - public CompanyCustomerService getViewModelService() { - return getCachedBean(CompanyCustomerService.class); + public CustomerService getViewModelService() { + return getCachedBean(CustomerService.class); } private CompanyService getCompanyService() { @@ -117,11 +117,11 @@ public class CompanyCustomerManagerWindowController CompletableFuture.runAsync(() -> { Pageable pageRequest = PageRequest.ofSize(50); while (!canceled.get()) { - Page page = getViewModelService().findAll(null, pageRequest); + Page page = getViewModelService().findAll(null, pageRequest); int index = page.getNumber() * page.getSize(); int i = 1; - for (CompanyCustomerVo companyCustomer : page) { + for (CustomerVo companyCustomer : page) { if (canceled.get()) { return; } diff --git a/client/src/main/java/com/ecep/contract/controller/customer/CompanyCustomerWindowController.java b/client/src/main/java/com/ecep/contract/controller/customer/CompanyCustomerWindowController.java index 37885c6..a16d397 100644 --- a/client/src/main/java/com/ecep/contract/controller/customer/CompanyCustomerWindowController.java +++ b/client/src/main/java/com/ecep/contract/controller/customer/CompanyCustomerWindowController.java @@ -12,11 +12,11 @@ import org.springframework.util.StringUtils; import com.ecep.contract.DesktopUtils; import com.ecep.contract.controller.AbstEntityController; import com.ecep.contract.service.CompanyContactService; -import com.ecep.contract.service.CompanyCustomerService; +import com.ecep.contract.service.CustomerService; import com.ecep.contract.service.CompanyService; import com.ecep.contract.util.FxmlPath; import com.ecep.contract.vm.CompanyCustomerViewModel; -import com.ecep.contract.vo.CompanyCustomerVo; +import com.ecep.contract.vo.CustomerVo; import com.ecep.contract.vo.CompanyVo; import javafx.event.ActionEvent; @@ -36,13 +36,13 @@ import javafx.stage.WindowEvent; @Scope("prototype") @Component @FxmlPath("/ui/company/customer/customer.fxml") -public class CompanyCustomerWindowController extends AbstEntityController { +public class CompanyCustomerWindowController extends AbstEntityController { private static final Logger logger = LoggerFactory.getLogger(CompanyCustomerWindowController.class); /** * 显示界面 */ - public static void show(CompanyCustomerVo customer, Window window) { + public static void show(CustomerVo customer, Window window) { show(CompanyCustomerWindowController.class, CompanyCustomerViewModel.from(customer), window); } @@ -80,15 +80,15 @@ public class CompanyCustomerWindowController extends AbstEntityController new CompanyCustomerTabSkinBase(this)); + registerTabSkin(baseInfoTab, tab -> new CustomerTabSkinBase(this)); registerTabSkin(fileTab, tab -> new CustomerTabSkinFile(this)); registerTabSkin(entityTab, tab -> new CustomerTabSkinEntity(this)); registerTabSkin(satisfactionTab, tab -> new CustomerTabSkinSatisfactionSurvey(this)); } @Override - public CompanyCustomerService getViewModelService() { - return getCachedBean(CompanyCustomerService.class); + public CustomerService getViewModelService() { + return getCachedBean(CustomerService.class); } public CompanyService getCompanyService() { diff --git a/client/src/main/java/com/ecep/contract/controller/customer/CompanyCustomerTabSkinBase.java b/client/src/main/java/com/ecep/contract/controller/customer/CustomerTabSkinBase.java similarity index 76% rename from client/src/main/java/com/ecep/contract/controller/customer/CompanyCustomerTabSkinBase.java rename to client/src/main/java/com/ecep/contract/controller/customer/CustomerTabSkinBase.java index bd90641..76cfff5 100644 --- a/client/src/main/java/com/ecep/contract/controller/customer/CompanyCustomerTabSkinBase.java +++ b/client/src/main/java/com/ecep/contract/controller/customer/CustomerTabSkinBase.java @@ -3,6 +3,7 @@ package com.ecep.contract.controller.customer; import java.io.File; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; +import java.util.List; import org.springframework.util.StringUtils; @@ -11,12 +12,16 @@ import com.ecep.contract.controller.company.CompanyWindowController; import com.ecep.contract.controller.tab.AbstEntityBasedTabSkin; import com.ecep.contract.controller.tab.TabSkin; import com.ecep.contract.service.CompanyContactService; -import com.ecep.contract.service.CompanyCustomerService; +import com.ecep.contract.service.CustomerService; import com.ecep.contract.service.CompanyService; +import com.ecep.contract.service.QueryService; import com.ecep.contract.util.UITools; +import com.ecep.contract.vm.CompanyContactViewModel; import com.ecep.contract.vm.CompanyCustomerViewModel; -import com.ecep.contract.vo.CompanyCustomerVo; +import com.ecep.contract.vo.CompanyContactVo; +import com.ecep.contract.vo.CustomerVo; import com.ecep.contract.vo.CompanyVo; +import com.ecep.contract.vo.VendorVo; import javafx.beans.binding.Bindings; import javafx.beans.property.SimpleObjectProperty; @@ -24,13 +29,14 @@ import javafx.event.ActionEvent; import javafx.scene.control.Tab; import javafx.scene.control.TextField; import javafx.stage.DirectoryChooser; +import javafx.util.StringConverter; import javafx.util.converter.LocalDateStringConverter; -public class CompanyCustomerTabSkinBase - extends AbstEntityBasedTabSkin +public class CustomerTabSkinBase + extends AbstEntityBasedTabSkin implements TabSkin { - public CompanyCustomerTabSkinBase(CompanyCustomerWindowController controller) { + public CustomerTabSkinBase(CompanyCustomerWindowController controller) { super(controller); } @@ -44,7 +50,25 @@ public class CompanyCustomerTabSkinBase initializeCompanyFieldAutoCompletion(controller.companyField); initializeContactFieldAutoCompletion(controller.contactField); - UITools.autoCompletion(controller.contactField, viewModel.getContact(), getCompanyContactService()); + UITools.autoCompletion(controller.contactField, viewModel.getContact(), + new QueryService() { + @Override + public CompanyContactVo findById(Integer id) { + return getCompanyContactService().findById(id); + } + + @Override + public List search(String searchText) { + CustomerVo vendor = getEntity(); + CompanyVo company = controller.getCompanyService().findById(vendor.getCompanyId()); + return getCompanyContactService().searchByCompany(company, searchText); + } + + @Override + public StringConverter getStringConverter() { + return getCompanyContactService().getStringConverter(); + } + }); LocalDateStringConverter converter = new LocalDateStringConverter(DateTimeFormatter.ISO_LOCAL_DATE, null); @@ -92,7 +116,7 @@ public class CompanyCustomerTabSkinBase } public void onCompanyCustomerCreatePathAction(ActionEvent event) { - CompanyCustomerVo companyCustomer = getCompanyCustomerService().findById(viewModel.getId().get()); + CustomerVo companyCustomer = getCompanyCustomerService().findById(viewModel.getId().get()); if (getCompanyCustomerService().makePathAbsent(companyCustomer)) { companyCustomer = getCompanyCustomerService().save(companyCustomer); viewModel.update(companyCustomer); @@ -103,10 +127,10 @@ public class CompanyCustomerTabSkinBase public void onCompanyCustomerChangePathAction(ActionEvent event) { DirectoryChooser chooser = new DirectoryChooser(); - CompanyCustomerVo entity = getEntity(); + CustomerVo entity = getEntity(); String path = entity.getPath(); File initialDirectory = null; - + // 如果当前已经设置了目录并且路径有效,则设置初始目录为该目录 if (StringUtils.hasText(path)) { File dir = new File(path); @@ -114,16 +138,16 @@ public class CompanyCustomerTabSkinBase initialDirectory = dir; } } - + // 如果没有有效的初始目录,则使用基础路径 if (initialDirectory == null) { initialDirectory = getCompanyCustomerService().getBasePath(); } - + if (initialDirectory != null) { chooser.setInitialDirectory(initialDirectory); } - + File newDirectory = chooser.showDialog(getTab().getContent().getScene().getWindow()); if (newDirectory != null) { entity.setPath(newDirectory.getAbsolutePath()); @@ -135,8 +159,8 @@ public class CompanyCustomerTabSkinBase setStatus("未实现"); } - public CompanyCustomerService getCompanyCustomerService() { - return controller.getCachedBean(CompanyCustomerService.class); + public CustomerService getCompanyCustomerService() { + return controller.getCachedBean(CustomerService.class); } public CompanyContactService getCompanyContactService() { diff --git a/client/src/main/java/com/ecep/contract/controller/customer/CustomerTabSkinEntity.java b/client/src/main/java/com/ecep/contract/controller/customer/CustomerTabSkinEntity.java index 70965aa..5468b51 100644 --- a/client/src/main/java/com/ecep/contract/controller/customer/CustomerTabSkinEntity.java +++ b/client/src/main/java/com/ecep/contract/controller/customer/CustomerTabSkinEntity.java @@ -12,7 +12,7 @@ import com.ecep.contract.util.FxmlPath; import com.ecep.contract.util.ParamUtils; import com.ecep.contract.vm.CustomerEntityViewModel; import com.ecep.contract.vo.CompanyCustomerEntityVo; -import com.ecep.contract.vo.CompanyCustomerVo; +import com.ecep.contract.vo.CustomerVo; import javafx.scene.control.MenuItem; import javafx.scene.control.Tab; @@ -89,7 +89,7 @@ public class CustomerTabSkinEntity } @Override - public ParamUtils.Builder getSpecification(CompanyCustomerVo parent) { + public ParamUtils.Builder getSpecification(CustomerVo parent) { ParamUtils.Builder params = getSpecification(); params.equals("customer", parent.getId()); return params; diff --git a/client/src/main/java/com/ecep/contract/controller/customer/CustomerTabSkinFile.java b/client/src/main/java/com/ecep/contract/controller/customer/CustomerTabSkinFile.java index f55a876..71b374f 100644 --- a/client/src/main/java/com/ecep/contract/controller/customer/CustomerTabSkinFile.java +++ b/client/src/main/java/com/ecep/contract/controller/customer/CustomerTabSkinFile.java @@ -4,49 +4,40 @@ import java.io.File; import java.time.LocalDate; import java.util.List; import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ScheduledExecutorService; -import java.util.function.Consumer; -import com.ecep.contract.controller.table.cell.CompanyCustomerFileTableTypeTableCell; -import com.ecep.contract.controller.table.cell.FilePathTableCell; import org.springframework.util.StringUtils; import com.ecep.contract.CustomerFileType; import com.ecep.contract.DesktopUtils; -import com.ecep.contract.Message; import com.ecep.contract.MyDateTimeUtils; import com.ecep.contract.SpringApp; import com.ecep.contract.constant.CompanyCustomerConstant; +import com.ecep.contract.controller.customer.tasker.CustomerEvaluationFormUpdateTask; +import com.ecep.contract.controller.customer.tasker.CustomerNextSignDateTask; import com.ecep.contract.controller.table.EditableEntityTableTabSkin; -import com.ecep.contract.model.BaseEnumEntity; +import com.ecep.contract.controller.table.cell.CompanyCustomerFileTableTypeTableCell; +import com.ecep.contract.controller.table.cell.FilePathTableCell; import com.ecep.contract.service.CompanyCustomerEvaluationFormFileService; import com.ecep.contract.service.CompanyCustomerFileService; import com.ecep.contract.service.CompanyCustomerFileTypeService; -import com.ecep.contract.service.CompanyCustomerService; -import com.ecep.contract.service.CompanyService; +import com.ecep.contract.service.CustomerService; import com.ecep.contract.task.CustomerFileMoveTasker; import com.ecep.contract.util.FileUtils; import com.ecep.contract.util.FxmlPath; import com.ecep.contract.util.ParamUtils; import com.ecep.contract.util.UITools; -import com.ecep.contract.vm.CompanyCustomerFileViewModel; +import com.ecep.contract.vm.CustomerFileViewModel; import com.ecep.contract.vo.CompanyCustomerEvaluationFormFileVo; -import com.ecep.contract.vo.CompanyCustomerFileVo; -import com.ecep.contract.vo.CompanyCustomerVo; +import com.ecep.contract.vo.CustomerFileVo; import com.ecep.contract.vo.CompanyVo; -import com.ecep.contract.vo.CustomerFileTypeLocalVo; +import com.ecep.contract.vo.CustomerVo; import javafx.application.Platform; -import javafx.beans.binding.Bindings; -import javafx.collections.FXCollections; -import javafx.collections.ObservableMap; -import javafx.concurrent.Task; import javafx.event.ActionEvent; import javafx.scene.control.Button; import javafx.scene.control.ButtonType; import javafx.scene.control.MenuItem; import javafx.scene.control.Tab; -import javafx.scene.control.TableCell; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; import javafx.scene.control.cell.CheckBoxTableCell; @@ -56,19 +47,19 @@ import lombok.Setter; @FxmlPath("/ui/company/customer/customer-tab-file.fxml") public class CustomerTabSkinFile - extends AbstCompanyCustomerTableTabSkin - implements EditableEntityTableTabSkin { + extends AbstCompanyCustomerTableTabSkin + implements EditableEntityTableTabSkin { @Setter private CompanyCustomerFileService companyCustomerFileService; - public TableColumn fileTable_idColumn; - public TableColumn fileTable_typeColumn; - public TableColumn fileTable_filePathColumn; - public TableColumn fileTable_editFilePathColumn; - public TableColumn fileTable_signDateColumn; - public TableColumn fileTable_validColumn; - public TableColumn fileTable_descriptionColumn; + public TableColumn fileTable_idColumn; + public TableColumn fileTable_typeColumn; + public TableColumn fileTable_filePathColumn; + public TableColumn fileTable_editFilePathColumn; + public TableColumn fileTable_signDateColumn; + public TableColumn fileTable_validColumn; + public TableColumn fileTable_descriptionColumn; public Button fileTable_reBuildBtn; public Button fileTable_updateEvaluationFormBuildBtn; @@ -99,7 +90,7 @@ public class CustomerTabSkinFile } @Override - public ParamUtils.Builder getSpecification(CompanyCustomerVo parent) { + public ParamUtils.Builder getSpecification(CustomerVo parent) { ParamUtils.Builder params = getSpecification(); params.equals("customer", parent.getId()); return params; @@ -109,7 +100,7 @@ public class CustomerTabSkinFile public void initializeTable() { super.initializeTable(); - TableView table = getTableView(); + TableView table = getTableView(); table.disableProperty().bind(viewModel.getPath().isEmpty()); fileTable_idColumn.setCellValueFactory(param -> param.getValue().getId()); @@ -163,7 +154,7 @@ public class CustomerTabSkinFile } @Override - protected void onTableRowDoubleClickedAction(CompanyCustomerFileViewModel item) { + protected void onTableRowDoubleClickedAction(CustomerFileViewModel item) { CustomerFileType fileType = item.getType().get(); if (fileType == CustomerFileType.EvaluationForm) { @@ -196,7 +187,7 @@ public class CustomerTabSkinFile setStatus("目录错误,不存在"); return; } - CompanyCustomerVo companyCustomer = getParent(); + CustomerVo companyCustomer = getParent(); LocalDate nextSignDate = getCompanyCustomerFileService().getNextSignDate(companyCustomer, ((level, message) -> setStatus(message))); if (nextSignDate != null && files.size() == 1) { @@ -208,15 +199,15 @@ public class CustomerTabSkinFile + "." + StringUtils.getFilenameExtension(fileName); File dest = new File(dir, destFileName); if (file.renameTo(dest)) { - CompanyCustomerFileVo ccf = new CompanyCustomerFileVo(); + CustomerFileVo ccf = new CustomerFileVo(); ccf.setCustomer(companyCustomer.getId()); ccf.setType(CustomerFileType.EvaluationForm); ccf.setFilePath(dest.getAbsolutePath()); ccf.setSignDate(nextSignDate); ccf.setValid(false); - CompanyCustomerFileVo saved = getCompanyCustomerFileService().save(ccf); + CustomerFileVo saved = getCompanyCustomerFileService().save(ccf); Platform.runLater(() -> { - CompanyCustomerFileViewModel model = new CompanyCustomerFileViewModel(); + CustomerFileViewModel model = new CustomerFileViewModel(); model.update(saved); dataSet.add(model); @@ -235,7 +226,7 @@ public class CustomerTabSkinFile for (File file : files) { File dest = new File(dir, file.getName()); if (file.renameTo(dest)) { - CompanyCustomerFileVo ccf = new CompanyCustomerFileVo(); + CustomerFileVo ccf = new CustomerFileVo(); ccf.setCustomer(companyCustomer.getId()); ccf.setType(CustomerFileType.General); ccf.setFilePath(dest.getAbsolutePath()); @@ -248,9 +239,9 @@ public class CustomerTabSkinFile public void onFileReBuildingAction(ActionEvent event) { - CompanyCustomerService customerService = getCompanyCustomerService(); + CustomerService customerService = getCompanyCustomerService(); try { - CompanyCustomerVo companyCustomer = customerService.findById(viewModel.getId().get()); + CustomerVo companyCustomer = customerService.findById(viewModel.getId().get()); if (customerService.reBuildingFiles(companyCustomer, (level, message) -> setStatus(message))) { loadTableDataSet(); } @@ -260,7 +251,7 @@ public class CustomerTabSkinFile } @Override - protected boolean deleteRow(CompanyCustomerFileViewModel row) { + protected boolean deleteRow(CustomerFileViewModel row) { String path = row.getFilePath().get(); if (super.deleteRow(row)) { File file = new File(path); @@ -280,7 +271,7 @@ public class CustomerTabSkinFile } public void onFileTableMoveToCompanyPathAction(ActionEvent event) { - CompanyCustomerFileViewModel selectedItem = getSelectedItem(); + CustomerFileViewModel selectedItem = getSelectedItem(); if (selectedItem == null) { return; } @@ -309,46 +300,17 @@ public class CustomerTabSkinFile loadTableDataSet(); } - private void initializeTask(Task task, String prefix, Consumer consumer) { - task.setOnScheduled(e -> { - consumer.accept("正在" + prefix + ",请稍后..."); - }); - task.setOnRunning(e -> { - consumer.accept("开始" + prefix + "..."); - }); - task.setOnSucceeded(e -> { - consumer.accept(prefix + "同步完成..."); - }); - task.exceptionProperty().addListener((observable, oldValue, newValue) -> { - consumer.accept(newValue.getMessage()); - }); - SpringApp.getBean(ScheduledExecutorService.class).submit(task); - consumer.accept("任务已创建..."); - } - public void onUpdateEvaluationFormAction(ActionEvent event) { - CompanyCustomerEvaluationFormUpdateTask task = new CompanyCustomerEvaluationFormUpdateTask(); + CustomerEvaluationFormUpdateTask task = new CustomerEvaluationFormUpdateTask(); task.setCustomer(getCompanyCustomerService().findById(viewModel.getId().get())); - UITools.showTaskDialogAndWait("更新评价表", task, consumer -> { - initializeTask(task, "更新评价表", msg -> consumer.accept(Message.info(msg))); - }); + UITools.showTaskDialogAndWait("更新评价表", task, null); loadTableDataSet(); } public void onCalcNextSignDateAction(ActionEvent event) { - UITools.showDialogAndWait("计算客户下一个评价日期", "依据已有的客户评估表和登记采购的合同计算下一个评估日期", ds -> { - CompanyCustomerVo companyCustomer = getCompanyCustomerService().findById(viewModel.getId().get()); - LocalDate nextSignDate = getCompanyCustomerFileService().getNextSignDate(companyCustomer, (level, msg) -> { - Platform.runLater(() -> { - ds.add(msg); - }); - }); - if (nextSignDate != null) { - Platform.runLater(() -> { - ds.add("下一个评价日期:" + nextSignDate); - }); - } - }); + CustomerNextSignDateTask task = new CustomerNextSignDateTask(); + task.setCustomer(getEntity()); + UITools.showTaskDialogAndWait("计算客户的下一个评价日期", task, null); } private CompanyCustomerFileService getCompanyCustomerFileService() { diff --git a/client/src/main/java/com/ecep/contract/controller/customer/CustomerTabSkinSatisfactionSurvey.java b/client/src/main/java/com/ecep/contract/controller/customer/CustomerTabSkinSatisfactionSurvey.java index 72b6a5d..d5a5a3b 100644 --- a/client/src/main/java/com/ecep/contract/controller/customer/CustomerTabSkinSatisfactionSurvey.java +++ b/client/src/main/java/com/ecep/contract/controller/customer/CustomerTabSkinSatisfactionSurvey.java @@ -10,7 +10,7 @@ import com.ecep.contract.controller.project.satisfaction_survey.CustomerSatisfac import com.ecep.contract.controller.table.cell.EmployeeTableCell; import com.ecep.contract.controller.table.cell.ProjectTableCell; import com.ecep.contract.converter.EntityStringConverter; -import com.ecep.contract.vo.CompanyCustomerVo; +import com.ecep.contract.vo.CustomerVo; import com.ecep.contract.vo.CustomerCatalogVo; import com.ecep.contract.vo.CustomerSatisfactionSurveyVo; import com.ecep.contract.vo.EmployeeVo; @@ -96,7 +96,7 @@ public class CustomerTabSkinSatisfactionSurvey } @Override - public ParamUtils.Builder getSpecification(CompanyCustomerVo parent) { + public ParamUtils.Builder getSpecification(CustomerVo parent) { ParamUtils.Builder params = getSpecification(); params.equals("project.customer", parent.getId()); return params; diff --git a/client/src/main/java/com/ecep/contract/controller/customer/CompanyCustomerEvaluationFormUpdateTask.java b/client/src/main/java/com/ecep/contract/controller/customer/tasker/CustomerEvaluationFormUpdateTask.java similarity index 67% rename from client/src/main/java/com/ecep/contract/controller/customer/CompanyCustomerEvaluationFormUpdateTask.java rename to client/src/main/java/com/ecep/contract/controller/customer/tasker/CustomerEvaluationFormUpdateTask.java index e2ccce2..156aa67 100644 --- a/client/src/main/java/com/ecep/contract/controller/customer/CompanyCustomerEvaluationFormUpdateTask.java +++ b/client/src/main/java/com/ecep/contract/controller/customer/tasker/CustomerEvaluationFormUpdateTask.java @@ -1,22 +1,22 @@ -package com.ecep.contract.controller.customer; +package com.ecep.contract.controller.customer.tasker; import com.ecep.contract.MessageHolder; import com.ecep.contract.WebSocketClientTasker; import com.ecep.contract.task.Tasker; -import com.ecep.contract.vo.CompanyCustomerVo; +import com.ecep.contract.vo.CustomerVo; import lombok.Setter; /** * 客户评估表更新任务 */ -public class CompanyCustomerEvaluationFormUpdateTask extends Tasker implements WebSocketClientTasker { +public class CustomerEvaluationFormUpdateTask extends Tasker implements WebSocketClientTasker { @Setter - private CompanyCustomerVo customer; + private CustomerVo customer; @Override public String getTaskName() { - return getClass().getSimpleName(); + return "CustomerEvaluationFormUpdateTask"; } @Override diff --git a/client/src/main/java/com/ecep/contract/controller/customer/CompanyCustomerNextSignDateTask.java b/client/src/main/java/com/ecep/contract/controller/customer/tasker/CustomerNextSignDateTask.java similarity index 68% rename from client/src/main/java/com/ecep/contract/controller/customer/CompanyCustomerNextSignDateTask.java rename to client/src/main/java/com/ecep/contract/controller/customer/tasker/CustomerNextSignDateTask.java index d3daeaf..8a5ad78 100644 --- a/client/src/main/java/com/ecep/contract/controller/customer/CompanyCustomerNextSignDateTask.java +++ b/client/src/main/java/com/ecep/contract/controller/customer/tasker/CustomerNextSignDateTask.java @@ -1,4 +1,4 @@ -package com.ecep.contract.controller.customer; +package com.ecep.contract.controller.customer.tasker; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -6,19 +6,19 @@ import org.slf4j.LoggerFactory; import com.ecep.contract.MessageHolder; import com.ecep.contract.WebSocketClientTasker; import com.ecep.contract.task.Tasker; -import com.ecep.contract.vo.CompanyCustomerVo; +import com.ecep.contract.vo.CustomerVo; import lombok.Setter; -public class CompanyCustomerNextSignDateTask extends Tasker implements WebSocketClientTasker { - private static final Logger logger = LoggerFactory.getLogger(CompanyCustomerNextSignDateTask.class); +public class CustomerNextSignDateTask extends Tasker implements WebSocketClientTasker { + private static final Logger logger = LoggerFactory.getLogger(CustomerNextSignDateTask.class); @Setter - private CompanyCustomerVo customer; + private CustomerVo customer; @Override public String getTaskName() { - return getClass().getSimpleName(); + return "CustomerNextSignDateTask"; } @Override diff --git a/client/src/main/java/com/ecep/contract/task/CompanyCustomerRebuildFilesTasker.java b/client/src/main/java/com/ecep/contract/controller/customer/tasker/CustomerRebuildFilesTasker.java similarity index 69% rename from client/src/main/java/com/ecep/contract/task/CompanyCustomerRebuildFilesTasker.java rename to client/src/main/java/com/ecep/contract/controller/customer/tasker/CustomerRebuildFilesTasker.java index a8b7bcc..b422344 100644 --- a/client/src/main/java/com/ecep/contract/task/CompanyCustomerRebuildFilesTasker.java +++ b/client/src/main/java/com/ecep/contract/controller/customer/tasker/CustomerRebuildFilesTasker.java @@ -1,8 +1,9 @@ -package com.ecep.contract.task; +package com.ecep.contract.controller.customer.tasker; import com.ecep.contract.MessageHolder; import com.ecep.contract.WebSocketClientTasker; -import com.ecep.contract.vo.CompanyCustomerVo; +import com.ecep.contract.task.Tasker; +import com.ecep.contract.vo.CustomerVo; import lombok.Getter; import lombok.Setter; @@ -11,10 +12,10 @@ import lombok.Setter; * 客户文件重建任务类 * 用于通过WebSocket与服务器通信,重建客户相关文件 */ -public class CompanyCustomerRebuildFilesTasker extends Tasker implements WebSocketClientTasker { +public class CustomerRebuildFilesTasker extends Tasker implements WebSocketClientTasker { @Getter @Setter - private CompanyCustomerVo companyCustomer; + private CustomerVo companyCustomer; @Getter @Setter @@ -22,7 +23,7 @@ public class CompanyCustomerRebuildFilesTasker extends Tasker implements @Override public String getTaskName() { - return "CompanyCustomerRebuildFilesTasker"; + return "CustomerRebuildFilesTasker"; } @Override diff --git a/client/src/main/java/com/ecep/contract/controller/project/ProjectTabSkinBid.java b/client/src/main/java/com/ecep/contract/controller/project/ProjectTabSkinBid.java index 77411fc..1048d28 100644 --- a/client/src/main/java/com/ecep/contract/controller/project/ProjectTabSkinBid.java +++ b/client/src/main/java/com/ecep/contract/controller/project/ProjectTabSkinBid.java @@ -13,7 +13,7 @@ import com.ecep.contract.controller.table.cell.EmployeeTableCell; import com.ecep.contract.converter.CompanyStringConverter; import com.ecep.contract.converter.EmployeeStringConverter; import com.ecep.contract.service.CompanyCustomerFileService; -import com.ecep.contract.service.CompanyCustomerService; +import com.ecep.contract.service.CustomerService; import com.ecep.contract.service.CompanyService; import com.ecep.contract.service.ProjectBidService; import com.ecep.contract.util.FxmlPath; @@ -56,7 +56,7 @@ public class ProjectTabSkinBid @Setter private CompanyService companyService; @Setter - private CompanyCustomerService customerService; + private CustomerService customerService; @Setter private CompanyCustomerFileService customerFileService; @@ -163,9 +163,9 @@ public class ProjectTabSkinBid return companyStringConverter; } - private CompanyCustomerService getCompanyCustomerService() { + private CustomerService getCompanyCustomerService() { if (customerService == null) { - customerService = getBean(CompanyCustomerService.class); + customerService = getBean(CustomerService.class); } return customerService; } diff --git a/client/src/main/java/com/ecep/contract/controller/project/ProjectTabSkinCustomerSatisfactionSurvey.java b/client/src/main/java/com/ecep/contract/controller/project/ProjectTabSkinCustomerSatisfactionSurvey.java index 5919ff1..a23c26b 100644 --- a/client/src/main/java/com/ecep/contract/controller/project/ProjectTabSkinCustomerSatisfactionSurvey.java +++ b/client/src/main/java/com/ecep/contract/controller/project/ProjectTabSkinCustomerSatisfactionSurvey.java @@ -12,7 +12,7 @@ import com.ecep.contract.controller.table.cell.EmployeeTableCell; import com.ecep.contract.converter.CompanyStringConverter; import com.ecep.contract.converter.EmployeeStringConverter; import com.ecep.contract.service.CompanyCustomerFileService; -import com.ecep.contract.service.CompanyCustomerService; +import com.ecep.contract.service.CustomerService; import com.ecep.contract.service.CompanyService; import com.ecep.contract.service.CustomerSatisfactionSurveyService; import com.ecep.contract.util.FxmlPath; @@ -52,7 +52,7 @@ public class ProjectTabSkinCustomerSatisfactionSurvey @Setter private CompanyService companyService; @Setter - private CompanyCustomerService customerService; + private CustomerService customerService; @Setter private CompanyCustomerFileService customerFileService; @@ -141,9 +141,9 @@ public class ProjectTabSkinCustomerSatisfactionSurvey return companyStringConverter; } - private CompanyCustomerService getCompanyCustomerService() { + private CustomerService getCompanyCustomerService() { if (customerService == null) { - customerService = getBean(CompanyCustomerService.class); + customerService = getBean(CustomerService.class); } return customerService; } diff --git a/client/src/main/java/com/ecep/contract/controller/project/ProjectTabSkinQuotation.java b/client/src/main/java/com/ecep/contract/controller/project/ProjectTabSkinQuotation.java index 8df6a5f..372c739 100644 --- a/client/src/main/java/com/ecep/contract/controller/project/ProjectTabSkinQuotation.java +++ b/client/src/main/java/com/ecep/contract/controller/project/ProjectTabSkinQuotation.java @@ -15,7 +15,7 @@ import com.ecep.contract.controller.table.cell.LocalDateTimeTableCell; import com.ecep.contract.converter.CompanyStringConverter; import com.ecep.contract.converter.EmployeeStringConverter; import com.ecep.contract.service.CompanyCustomerFileService; -import com.ecep.contract.service.CompanyCustomerService; +import com.ecep.contract.service.CustomerService; import com.ecep.contract.service.CompanyService; import com.ecep.contract.service.ProjectQuotationService; import com.ecep.contract.util.FxmlPath; @@ -69,7 +69,7 @@ public class ProjectTabSkinQuotation @Setter private CompanyService companyService; @Setter - private CompanyCustomerService customerService; + private CustomerService customerService; @Setter private CompanyCustomerFileService customerFileService; @@ -174,9 +174,9 @@ public class ProjectTabSkinQuotation return companyStringConverter; } - private CompanyCustomerService getCompanyCustomerService() { + private CustomerService getCompanyCustomerService() { if (customerService == null) { - customerService = getBean(CompanyCustomerService.class); + customerService = getBean(CustomerService.class); } return customerService; } diff --git a/client/src/main/java/com/ecep/contract/controller/project/bid/ProjectBidTabSkinBase.java b/client/src/main/java/com/ecep/contract/controller/project/bid/ProjectBidTabSkinBase.java index 334fe0a..9db02e7 100644 --- a/client/src/main/java/com/ecep/contract/controller/project/bid/ProjectBidTabSkinBase.java +++ b/client/src/main/java/com/ecep/contract/controller/project/bid/ProjectBidTabSkinBase.java @@ -53,7 +53,7 @@ public class ProjectBidTabSkinBase @Setter private CompanyService companyService; @Setter - private CompanyCustomerService customerService; + private CustomerService customerService; @Setter private CompanyCustomerFileService customerFileService; @Setter @@ -266,7 +266,7 @@ public class ProjectBidTabSkinBase } Integer companyId = project.getCustomerId(); CompanyVo company = getCompanyService().findById(companyId); - CompanyCustomerVo customer = getCompanyCustomerService().findByCompany(company); + CustomerVo customer = getCompanyCustomerService().findByCompany(company); if (customer == null) { // 没有对应的客户 return; @@ -275,7 +275,7 @@ public class ProjectBidTabSkinBase CompanyCustomerFileService fileService = getBean(CompanyCustomerFileService.class); // 获取客户资信评估表 - List list = fileService.findAllByCustomerAndType(customer, + List list = fileService.findAllByCustomerAndType(customer, CustomerFileType.EvaluationForm); if (list.isEmpty()) { // 没有评估表 @@ -285,7 +285,7 @@ public class ProjectBidTabSkinBase // 在时间范围内是否有评估表 LocalDateTime applyTime = getViewModel().getApplyTime().get(); LocalDate verifyDate = applyTime.toLocalDate(); - CompanyCustomerFileVo file = list.stream() + CustomerFileVo file = list.stream() .filter(v -> v.getSignDate() != null && v.isValid()) .filter(v -> v.getType() == CustomerFileType.EvaluationForm) .filter(v -> MyDateTimeUtils.dateValidFilter(verifyDate, v.getSignDate(), v.getSignDate().plusYears(1), @@ -423,9 +423,9 @@ public class ProjectBidTabSkinBase return companyStringConverter; } - private CompanyCustomerService getCompanyCustomerService() { + private CustomerService getCompanyCustomerService() { if (customerService == null) { - customerService = getBean(CompanyCustomerService.class); + customerService = getBean(CustomerService.class); } return customerService; } diff --git a/client/src/main/java/com/ecep/contract/controller/project/quotation/ProjectQuotationTabSkinBase.java b/client/src/main/java/com/ecep/contract/controller/project/quotation/ProjectQuotationTabSkinBase.java index 51de1ef..3655ef4 100644 --- a/client/src/main/java/com/ecep/contract/controller/project/quotation/ProjectQuotationTabSkinBase.java +++ b/client/src/main/java/com/ecep/contract/controller/project/quotation/ProjectQuotationTabSkinBase.java @@ -14,7 +14,7 @@ import com.ecep.contract.converter.EmployeeStringConverter; import com.ecep.contract.model.Employee; import com.ecep.contract.service.CompanyCustomerEvaluationFormFileService; import com.ecep.contract.service.CompanyCustomerFileService; -import com.ecep.contract.service.CompanyCustomerService; +import com.ecep.contract.service.CustomerService; import com.ecep.contract.service.CompanyService; import com.ecep.contract.service.ProjectQuotationService; import com.ecep.contract.service.ProjectService; @@ -54,7 +54,7 @@ public class ProjectQuotationTabSkinBase @Setter private CompanyService companyService; @Setter - private CompanyCustomerService customerService; + private CustomerService customerService; @Setter private CompanyCustomerFileService customerFileService; @Setter @@ -244,8 +244,8 @@ public class ProjectQuotationTabSkinBase return getBean(CompanyStringConverter.class); } - private CompanyCustomerService getCompanyCustomerService() { - return getBean(CompanyCustomerService.class); + private CustomerService getCompanyCustomerService() { + return getBean(CustomerService.class); } private CompanyCustomerFileService getCompanyCustomerFileService() { diff --git a/client/src/main/java/com/ecep/contract/controller/project/satisfaction_survey/CustomerSatisfactionSurveyTabSkinBase.java b/client/src/main/java/com/ecep/contract/controller/project/satisfaction_survey/CustomerSatisfactionSurveyTabSkinBase.java index f2af97b..01c8934 100644 --- a/client/src/main/java/com/ecep/contract/controller/project/satisfaction_survey/CustomerSatisfactionSurveyTabSkinBase.java +++ b/client/src/main/java/com/ecep/contract/controller/project/satisfaction_survey/CustomerSatisfactionSurveyTabSkinBase.java @@ -18,7 +18,7 @@ import com.ecep.contract.converter.CompanyStringConverter; import com.ecep.contract.converter.EmployeeStringConverter; import com.ecep.contract.service.CompanyCustomerEvaluationFormFileService; import com.ecep.contract.service.CompanyCustomerFileService; -import com.ecep.contract.service.CompanyCustomerService; +import com.ecep.contract.service.CustomerService; import com.ecep.contract.service.CompanyService; import com.ecep.contract.service.ProjectCostService; import com.ecep.contract.service.ProjectQuotationService; @@ -27,8 +27,8 @@ import com.ecep.contract.util.ProxyUtils; import com.ecep.contract.util.UITools; import com.ecep.contract.vm.CustomerSatisfactionSurveyViewModel; import com.ecep.contract.vo.CompanyCustomerEvaluationFormFileVo; -import com.ecep.contract.vo.CompanyCustomerFileVo; -import com.ecep.contract.vo.CompanyCustomerVo; +import com.ecep.contract.vo.CustomerFileVo; +import com.ecep.contract.vo.CustomerVo; import com.ecep.contract.vo.CompanyVo; import com.ecep.contract.vo.CustomerSatisfactionSurveyVo; import com.ecep.contract.vo.ProjectVo; @@ -64,7 +64,7 @@ public class CustomerSatisfactionSurveyTabSkinBase @Setter private CompanyService companyService; @Setter - private CompanyCustomerService customerService; + private CustomerService customerService; @Setter private CompanyCustomerFileService customerFileService; @Setter @@ -228,13 +228,13 @@ public class CustomerSatisfactionSurveyTabSkinBase } Integer companyId = project.getCustomerId(); CompanyVo company = getCompanyService().findById(companyId); - CompanyCustomerVo customer = getCompanyCustomerService().findByCompany(company); + CustomerVo customer = getCompanyCustomerService().findByCompany(company); if (customer == null) { return; } CompanyCustomerFileService companyCustomerFileService = getBean(CompanyCustomerFileService.class); - List list = companyCustomerFileService.findAllByCustomerAndType(customer, + List list = companyCustomerFileService.findAllByCustomerAndType(customer, CustomerFileType.EvaluationForm); if (list.isEmpty()) { return; @@ -242,7 +242,7 @@ public class CustomerSatisfactionSurveyTabSkinBase LocalDateTime applyTime = getViewModel().getApplyTime().get(); LocalDate verifyDate = applyTime.toLocalDate(); - CompanyCustomerFileVo file = list.stream() + CustomerFileVo file = list.stream() .filter(v -> v.getSignDate() != null && v.isValid()) .filter(v -> v.getType() == CustomerFileType.EvaluationForm) .filter(v -> MyDateTimeUtils.dateValidFilter(verifyDate, v.getSignDate(), v.getSignDate().plusYears(1), @@ -314,9 +314,9 @@ public class CustomerSatisfactionSurveyTabSkinBase return companyStringConverter; } - private CompanyCustomerService getCompanyCustomerService() { + private CustomerService getCompanyCustomerService() { if (customerService == null) { - customerService = getBean(CompanyCustomerService.class); + customerService = getBean(CustomerService.class); } return customerService; } diff --git a/client/src/main/java/com/ecep/contract/controller/tab/CompanyTabSkinFile.java b/client/src/main/java/com/ecep/contract/controller/tab/CompanyTabSkinFile.java index 74023f8..d5f4151 100644 --- a/client/src/main/java/com/ecep/contract/controller/tab/CompanyTabSkinFile.java +++ b/client/src/main/java/com/ecep/contract/controller/tab/CompanyTabSkinFile.java @@ -16,8 +16,8 @@ import com.ecep.contract.constant.CloudServiceConstant; import com.ecep.contract.controller.company.AbstCompanyTableTabSkin; import com.ecep.contract.controller.company.CompanyWindowController; import com.ecep.contract.controller.table.EditableEntityTableTabSkin; -import com.ecep.contract.controller.table.cell.CompanyFilePathTableCell; import com.ecep.contract.controller.table.cell.CompanyFileTypeTableCell; +import com.ecep.contract.controller.table.cell.FilePathTableCell; import com.ecep.contract.service.CloudTycService; import com.ecep.contract.service.CompanyFileService; import com.ecep.contract.service.CompanyFileTypeService; @@ -92,7 +92,7 @@ public class CompanyTabSkinFile typeColumn.setCellFactory(CompanyFileTypeTableCell.forTableColumn(getCachedBean(CompanyFileTypeService.class))); filePathColumn.setCellValueFactory(param -> param.getValue().getFilePath()); - filePathColumn.setCellFactory(param -> new CompanyFilePathTableCell<>(viewModel.getPath())); + filePathColumn.setCellFactory(FilePathTableCell.forTableColumn(viewModel.getPath())); applyDateColumn.setCellValueFactory(param -> param.getValue().getApplyDate()); expiringDateColumn.setCellValueFactory(param -> param.getValue().getExpiringDate()); diff --git a/client/src/main/java/com/ecep/contract/controller/tab/ContractTabSkinBase.java b/client/src/main/java/com/ecep/contract/controller/tab/ContractTabSkinBase.java index 73e996d..bf290f0 100644 --- a/client/src/main/java/com/ecep/contract/controller/tab/ContractTabSkinBase.java +++ b/client/src/main/java/com/ecep/contract/controller/tab/ContractTabSkinBase.java @@ -23,7 +23,7 @@ import com.ecep.contract.controller.vendor.VendorWindowController; import com.ecep.contract.converter.ContractStringConverter; import com.ecep.contract.service.VendorService; import com.ecep.contract.util.UITools; -import com.ecep.contract.vo.CompanyCustomerVo; +import com.ecep.contract.vo.CustomerVo; import com.ecep.contract.vo.VendorVo; import com.ecep.contract.vo.CompanyVo; import com.ecep.contract.vo.ContractTypeVo; @@ -445,7 +445,7 @@ public class ContractTabSkinBase extends AbstContractBasedTabSkin { public void onContractOpenRelativeCompanyCustomerAction(ActionEvent event) { ContractVo contract = getEntity(); CompanyVo company = controller.getCompanyService().findById(contract.getCompanyId()); - CompanyCustomerVo companyCustomer = getCompanyCustomerService().findByCompany(company); + CustomerVo companyCustomer = getCompanyCustomerService().findByCompany(company); CompanyCustomerWindowController.show(companyCustomer, null); } @@ -465,8 +465,8 @@ public class ContractTabSkinBase extends AbstContractBasedTabSkin { UITools.autoCompletion(textField, viewModel.getProject(), getProjectService()); } - public CompanyCustomerService getCompanyCustomerService() { - return getCachedBean(CompanyCustomerService.class); + public CustomerService getCompanyCustomerService() { + return getCachedBean(CustomerService.class); } public ProjectService getProjectService() { diff --git a/client/src/main/java/com/ecep/contract/controller/tab/ContractUpdater.java b/client/src/main/java/com/ecep/contract/controller/tab/ContractUpdater.java index aacf4eb..29211f6 100644 --- a/client/src/main/java/com/ecep/contract/controller/tab/ContractUpdater.java +++ b/client/src/main/java/com/ecep/contract/controller/tab/ContractUpdater.java @@ -150,8 +150,8 @@ public class ContractUpdater implements MessageHolder { return getBean(VendorService.class); } - private CompanyCustomerService getCustomerService() { - return getBean(CompanyCustomerService.class); + private CustomerService getCustomerService() { + return getBean(CustomerService.class); } private CompanyService getCompanyService() { diff --git a/client/src/main/java/com/ecep/contract/controller/table/cell/CompanyFilePathTableCell.java b/client/src/main/java/com/ecep/contract/controller/table/cell/CompanyFilePathTableCell.java deleted file mode 100644 index 05aa656..0000000 --- a/client/src/main/java/com/ecep/contract/controller/table/cell/CompanyFilePathTableCell.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.ecep.contract.controller.table.cell; - -import org.springframework.util.StringUtils; - -import javafx.beans.property.SimpleStringProperty; -import javafx.scene.control.TableCell; -import lombok.AllArgsConstructor; -import lombok.NoArgsConstructor; - -@NoArgsConstructor -@AllArgsConstructor -public class CompanyFilePathTableCell extends TableCell { - private SimpleStringProperty companyPathProperty; - - public void setCompanyPathProperty(SimpleStringProperty property) { - this.companyPathProperty = property; - } - - @Override - protected void updateItem(String item, boolean empty) { - super.updateItem(item, empty); - if (empty || item == null) { - setText(""); - return; - } - if (companyPathProperty != null) { - String path = companyPathProperty.get(); - if (StringUtils.hasText(path)) { - if (item.startsWith(path)) { - item = "~" + item.substring(path.length()); - } - } - } - setText(item); - } -} diff --git a/client/src/main/java/com/ecep/contract/controller/table/cell/EvaluationFileTableCell.java b/client/src/main/java/com/ecep/contract/controller/table/cell/EvaluationFileTableCell.java index 49d3c4e..ce351c0 100644 --- a/client/src/main/java/com/ecep/contract/controller/table/cell/EvaluationFileTableCell.java +++ b/client/src/main/java/com/ecep/contract/controller/table/cell/EvaluationFileTableCell.java @@ -8,7 +8,7 @@ import com.ecep.contract.SpringApp; import com.ecep.contract.service.CompanyCustomerEvaluationFormFileService; import com.ecep.contract.service.CompanyCustomerFileService; import com.ecep.contract.vo.CompanyCustomerEvaluationFormFileVo; -import com.ecep.contract.vo.CompanyCustomerFileVo; +import com.ecep.contract.vo.CustomerFileVo; import lombok.NoArgsConstructor; @@ -49,7 +49,7 @@ public class EvaluationFileTableCell extends AsyncUpdateTableCell extends TableCell { - private StringProperty path; + private StringProperty rootPathProperty; /** * 创建一个用于表格列的单元格工厂 */ public static Callback, TableCell> forTableColumn( - StringProperty parentPath) { - return param -> new FilePathTableCell<>(parentPath); + StringProperty rootPath) { + return param -> new FilePathTableCell<>(rootPath); } public FilePathTableCell(StringProperty parentPath) { - this.path = parentPath; + this.rootPathProperty = parentPath; } @Override @@ -30,7 +36,7 @@ public class FilePathTableCell extends TableCell { return; } - String path = this.path.get(); + String path = this.rootPathProperty.get(); if (StringUtils.hasText(path)) { if (item.startsWith(path)) { item = "~" + item.substring(path.length()); diff --git a/client/src/main/java/com/ecep/contract/controller/vendor/VendorManagerWindowController.java b/client/src/main/java/com/ecep/contract/controller/vendor/VendorManagerWindowController.java index 6738a0d..6c29efb 100644 --- a/client/src/main/java/com/ecep/contract/controller/vendor/VendorManagerWindowController.java +++ b/client/src/main/java/com/ecep/contract/controller/vendor/VendorManagerWindowController.java @@ -4,6 +4,7 @@ import java.time.LocalDate; import java.util.concurrent.CompletableFuture; import com.ecep.contract.service.VendorService; +import com.ecep.contract.task.VendorReBuildFilesTasker; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Scope; @@ -73,13 +74,14 @@ public class VendorManagerWindowController MessageHolder messageHolder = (level, msg) -> { System.out.println(level + ">" + msg); }; - + VendorReBuildFilesTasker tasker = new VendorReBuildFilesTasker(); while (true) { Page page = vendorService.findAll(null, pageRequest); for (VendorVo companyVendor : page) { MessageHolder sub = messageHolder .sub(page.getNumber() + "/" + page.getTotalPages() + " #" + companyVendor.getId() + ">"); - vendorService.reBuildingFiles(companyVendor, sub); + tasker.setVendor(companyVendor); + tasker.callRemoteTask(sub, getLocale(), companyVendor.getId()); } if (!page.hasNext()) { break; diff --git a/client/src/main/java/com/ecep/contract/controller/vendor/VendorNextSignDateTask.java b/client/src/main/java/com/ecep/contract/controller/vendor/VendorNextSignDateTask.java new file mode 100644 index 0000000..264a104 --- /dev/null +++ b/client/src/main/java/com/ecep/contract/controller/vendor/VendorNextSignDateTask.java @@ -0,0 +1,34 @@ +package com.ecep.contract.controller.vendor; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.ecep.contract.MessageHolder; +import com.ecep.contract.WebSocketClientTasker; +import com.ecep.contract.task.Tasker; +import com.ecep.contract.vo.VendorVo; + +import lombok.Setter; + +public class VendorNextSignDateTask extends Tasker implements WebSocketClientTasker { + private static final Logger logger = LoggerFactory.getLogger(VendorNextSignDateTask.class); + + @Setter + private VendorVo vendor; + + @Override + public String getTaskName() { + return getClass().getSimpleName(); + } + + @Override + public void updateProgress(long current, long total) { + super.updateProgress(current, total); + } + + @Override + protected Object execute(MessageHolder holder) throws Exception { + updateTitle("计算供应商下一个评价日期"); + return callRemoteTask(holder, getLocale(), vendor.getId()); + } +} \ No newline at end of file diff --git a/client/src/main/java/com/ecep/contract/controller/vendor/VendorTabSkinBase.java b/client/src/main/java/com/ecep/contract/controller/vendor/VendorTabSkinBase.java index b225d8a..777825f 100644 --- a/client/src/main/java/com/ecep/contract/controller/vendor/VendorTabSkinBase.java +++ b/client/src/main/java/com/ecep/contract/controller/vendor/VendorTabSkinBase.java @@ -2,24 +2,28 @@ package com.ecep.contract.controller.vendor; import java.io.File; import java.time.format.DateTimeFormatter; +import java.util.List; import org.springframework.util.StringUtils; import com.ecep.contract.MyDateTimeUtils; import com.ecep.contract.SpringApp; import com.ecep.contract.VendorType; -import com.ecep.contract.util.ComboBoxUtils; import com.ecep.contract.controller.company.CompanyWindowController; import com.ecep.contract.controller.tab.AbstEntityBasedTabSkin; import com.ecep.contract.service.CompanyContactService; -import com.ecep.contract.service.VendorService; +import com.ecep.contract.service.QueryService; import com.ecep.contract.service.VendorCatalogService; +import com.ecep.contract.service.VendorService; import com.ecep.contract.service.VendorTypeService; +import com.ecep.contract.util.ComboBoxUtils; import com.ecep.contract.util.UITools; +import com.ecep.contract.vm.CompanyContactViewModel; import com.ecep.contract.vm.CompanyVendorViewModel; import com.ecep.contract.vm.CompanyViewModel; -import com.ecep.contract.vo.VendorVo; +import com.ecep.contract.vo.CompanyContactVo; import com.ecep.contract.vo.CompanyVo; +import com.ecep.contract.vo.VendorVo; import javafx.collections.FXCollections; import javafx.collections.ObservableList; @@ -27,6 +31,7 @@ import javafx.event.ActionEvent; import javafx.scene.control.ComboBox; import javafx.scene.control.Tab; import javafx.stage.DirectoryChooser; +import javafx.util.StringConverter; import javafx.util.converter.LocalDateStringConverter; import javafx.util.converter.LocalDateTimeStringConverter; @@ -59,12 +64,31 @@ public class VendorTabSkinBase controller.developDateField.setConverter(converter); controller.developDateField.valueProperty().bindBidirectional(viewModel.getDevelopDate()); - ComboBoxUtils.initialComboBox(controller.catalogField, viewModel.getCatalog(), getCachedBean(VendorCatalogService.class), true); + ComboBoxUtils.initialComboBox(controller.catalogField, viewModel.getCatalog(), + getCachedBean(VendorCatalogService.class), true); initialTypeComboBox(); controller.protocolProviderField.selectedProperty().bindBidirectional(viewModel.getProtocolProvider()); - UITools.autoCompletion(controller.contactField, viewModel.getContact(), getCompanyContactService()); + UITools.autoCompletion(controller.contactField, viewModel.getContact(), + new QueryService() { + @Override + public CompanyContactVo findById(Integer id) { + return getCompanyContactService().findById(id); + } + + @Override + public List search(String searchText) { + VendorVo vendor = getEntity(); + CompanyVo company = controller.getCompanyService().findById(vendor.getCompanyId()); + return getCompanyContactService().searchByCompany(company, searchText); + } + + @Override + public StringConverter getStringConverter() { + return getCompanyContactService().getStringConverter(); + } + }); controller.purchaseField.textProperty().bindBidirectional(viewModel.getPurchase()); controller.pathField.textProperty().bind(viewModel.getPath()); @@ -115,7 +139,7 @@ public class VendorTabSkinBase VendorVo entity = getEntity(); String path = entity.getPath(); File initialDirectory = null; - + // 如果当前已经设置了目录并且路径有效,则设置初始目录为该目录 if (StringUtils.hasText(path)) { File dir = new File(path); @@ -123,16 +147,16 @@ public class VendorTabSkinBase initialDirectory = dir; } } - + // 如果没有有效的初始目录,则使用基础路径 if (initialDirectory == null) { initialDirectory = getCompanyVendorService().getBasePath(); } - + if (initialDirectory != null) { chooser.setInitialDirectory(initialDirectory); } - + File newDirectory = chooser.showDialog(getTab().getContent().getScene().getWindow()); if (newDirectory != null) { entity.setPath(newDirectory.getAbsolutePath()); diff --git a/client/src/main/java/com/ecep/contract/controller/vendor/VendorTabSkinFile.java b/client/src/main/java/com/ecep/contract/controller/vendor/VendorTabSkinFile.java index 2b4c550..3f68a39 100644 --- a/client/src/main/java/com/ecep/contract/controller/vendor/VendorTabSkinFile.java +++ b/client/src/main/java/com/ecep/contract/controller/vendor/VendorTabSkinFile.java @@ -3,40 +3,34 @@ package com.ecep.contract.controller.vendor; import java.io.File; import java.time.LocalDate; import java.util.List; -import java.util.concurrent.CompletableFuture; -import com.ecep.contract.service.VendorFileTypeService; -import com.ecep.contract.vo.VendorFileVo; -import com.ecep.contract.vo.VendorVo; -import com.ecep.contract.vo.CompanyVo; -import com.ecep.contract.vo.VendorFileTypeLocalVo; +import javafx.scene.control.*; import org.springframework.util.StringUtils; -import com.ecep.contract.VendorFileType; import com.ecep.contract.DesktopUtils; import com.ecep.contract.MyDateTimeUtils; import com.ecep.contract.SpringApp; +import com.ecep.contract.VendorFileType; import com.ecep.contract.constant.CompanyVendorConstant; import com.ecep.contract.controller.tab.TabSkin; -import com.ecep.contract.model.BaseEnumEntity; +import com.ecep.contract.controller.table.cell.FilePathTableCell; import com.ecep.contract.service.VendorFileService; +import com.ecep.contract.service.VendorFileTypeService; import com.ecep.contract.task.CompanyVendorEvaluationFormUpdateTask; +import com.ecep.contract.task.VendorReBuildFilesTasker; import com.ecep.contract.util.FxmlPath; import com.ecep.contract.util.UITools; import com.ecep.contract.vm.CompanyVendorFileViewModel; +import com.ecep.contract.vo.CompanyVo; +import com.ecep.contract.vo.VendorFileTypeLocalVo; +import com.ecep.contract.vo.VendorFileVo; +import com.ecep.contract.vo.VendorVo; import javafx.application.Platform; import javafx.beans.binding.Bindings; import javafx.collections.FXCollections; import javafx.collections.ObservableMap; import javafx.event.ActionEvent; -import javafx.scene.control.Button; -import javafx.scene.control.ButtonType; -import javafx.scene.control.MenuItem; -import javafx.scene.control.Tab; -import javafx.scene.control.TableCell; -import javafx.scene.control.TableColumn; -import javafx.scene.control.TableView; import javafx.scene.control.cell.CheckBoxTableCell; import lombok.Setter; @@ -59,6 +53,9 @@ public class VendorTabSkinFile public MenuItem fileTable_menu_refresh; public MenuItem fileTable_menu_del; public MenuItem fileTable_menu_move_to_company_path; + public Menu fileTable_menu_set_valid; + public MenuItem fileTable_menu_set_valid_true; + public MenuItem fileTable_menu_set_valid_false; public Button fileTable_reBuildBtn; public Button fileTable_updateEvaluationFormBuildBtn; @@ -97,10 +94,13 @@ public class VendorTabSkinFile param.getValue().getType()).map(VendorFileTypeLocalVo::getValue)); fileTable_filePathColumn.setCellValueFactory(param -> param.getValue().getFilePath()); - fileTable_filePathColumn.setCellFactory(param -> new FileTableFilePathTableCell()); + fileTable_filePathColumn.setCellFactory(FilePathTableCell.forTableColumn(viewModel.getPath())); + fileTable_editFilePathColumn.setCellValueFactory(param -> param.getValue().getEditFilePath()); - fileTable_editFilePathColumn.setCellFactory(param -> new FileTableFilePathTableCell()); + fileTable_editFilePathColumn.setCellFactory(FilePathTableCell.forTableColumn(viewModel.getPath())); + fileTable_signDateColumn.setCellValueFactory(param -> param.getValue().getSignDate()); + fileTable_validColumn.setEditable(true); fileTable_validColumn.setCellValueFactory(param -> param.getValue().getValid()); fileTable_validColumn.setCellFactory(param -> new CheckBoxTableCell<>()); @@ -113,6 +113,14 @@ public class VendorTabSkinFile fileTable_menu_del.setOnAction(this::onTableDeleteAction); fileTable_menu_move_to_company_path.setOnAction(this::onFileTableMoveToCompanyPathAction); + // 设置有效性菜单项事件处理 + fileTable_menu_set_valid_true.setOnAction(e -> setValidValue(true)); + fileTable_menu_set_valid_false.setOnAction(e -> setValidValue(false)); + + // 当表格中没有选中项时,菜单项不显示 + fileTable_menu_set_valid.visibleProperty() + .bind(Bindings.isNotEmpty(table.getSelectionModel().getSelectedItems())); + super.initializeTab(); } @@ -174,23 +182,19 @@ public class VendorTabSkinFile ccf.setType(VendorFileType.General); ccf.setFilePath(dest.getAbsolutePath()); ccf.setValid(false); - VendorFileVo saved = getVendorFileService().save(ccf); + getVendorFileService().save(ccf); } } loadTableDataSet(); } public void onFileReBuildingAction(ActionEvent event) { - CompletableFuture.runAsync(() -> { - try { - VendorVo companyVendor = getParent(); - if (getCompanyVendorService().reBuildingFiles(companyVendor, (level, msg) -> setStatus(msg))) { - loadTableDataSet(); - } - } catch (Exception e) { - e.printStackTrace(); - } - }); + VendorReBuildFilesTasker tasker = new VendorReBuildFilesTasker(); + tasker.setVendor(getEntity()); + UITools.showTaskDialogAndWait("重建文件", tasker, null); + if (tasker.isModified()) { + loadTableDataSet(); + } } @Override @@ -278,43 +282,15 @@ public class VendorTabSkinFile public void onUpdateEvaluationFormAction(ActionEvent event) { CompanyVendorEvaluationFormUpdateTask task = new CompanyVendorEvaluationFormUpdateTask(); + task.setVendor(getEntity()); UITools.showTaskDialogAndWait("更新评价表", task, null); loadTableDataSet(); } public void onCalcNextSignDateAction(ActionEvent event) { - UITools.showDialogAndWait("计算供应商下一个评价日期", "依据已有的供应商评价表和登记采购的合同计算下一个评价日期", ds -> { - VendorVo companyVendor = getCompanyVendorService().findById(viewModel.getId().get()); - LocalDate nextSignDate = getVendorFileService().getNextSignDate(companyVendor, msg -> { - Platform.runLater(() -> { - ds.add(msg); - }); - }); - if (nextSignDate != null) { - Platform.runLater(() -> { - ds.add("下一个评价日期:" + nextSignDate); - }); - } - }); - } - - class FileTableFilePathTableCell extends TableCell { - @Override - protected void updateItem(String item, boolean empty) { - super.updateItem(item, empty); - if (empty || !StringUtils.hasText(item)) { - setText(""); - return; - } - - String path = viewModel.getPath().get(); - if (StringUtils.hasText(path)) { - if (item.startsWith(path)) { - item = "~" + item.substring(path.length()); - } - } - setText(item); - } + VendorNextSignDateTask task = new VendorNextSignDateTask(); + task.setVendor(getEntity()); + UITools.showTaskDialogAndWait("计算供应商的下一个评价日期", task, null); } public VendorFileService getVendorFileService() { @@ -324,4 +300,28 @@ public class VendorTabSkinFile return vendorFileService; } + /** + * 设置选中行的valid值 + * + * @param valid 有效性值 + */ + private void setValidValue(boolean valid) { + List selectedItems = getTableView().getSelectionModel().getSelectedItems(); + if (selectedItems.isEmpty()) { + return; + } + + for (CompanyVendorFileViewModel item : selectedItems) { + // 更新视图模型的值 + item.getValid().set(valid); + + // 保存到后端 + VendorFileVo entity = loadRowData(item); + entity.setValid(valid); + saveRowData(entity); + } + + setStatus("已更新" + selectedItems.size() + "条记录的有效性状态"); + } + } diff --git a/client/src/main/java/com/ecep/contract/converter/CompanyCustomerStringConverter.java b/client/src/main/java/com/ecep/contract/converter/CompanyCustomerStringConverter.java index f9f432b..216ae21 100644 --- a/client/src/main/java/com/ecep/contract/converter/CompanyCustomerStringConverter.java +++ b/client/src/main/java/com/ecep/contract/converter/CompanyCustomerStringConverter.java @@ -4,17 +4,17 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Component; -import com.ecep.contract.service.CompanyCustomerService; -import com.ecep.contract.vo.CompanyCustomerVo; +import com.ecep.contract.service.CustomerService; +import com.ecep.contract.vo.CustomerVo; import jakarta.annotation.PostConstruct; @Lazy @Component -public class CompanyCustomerStringConverter extends EntityStringConverter { +public class CompanyCustomerStringConverter extends EntityStringConverter { @Lazy @Autowired - private CompanyCustomerService service; + private CustomerService service; public CompanyCustomerStringConverter() { diff --git a/client/src/main/java/com/ecep/contract/service/CloudTycService.java b/client/src/main/java/com/ecep/contract/service/CloudTycService.java index ca0205e..2518fbb 100644 --- a/client/src/main/java/com/ecep/contract/service/CloudTycService.java +++ b/client/src/main/java/com/ecep/contract/service/CloudTycService.java @@ -63,6 +63,8 @@ public class CloudTycService extends QueryService { - public List findAllByCustomer(CompanyCustomerVo customer) { + public List findAllByCustomer(CustomerVo customer) { return findAll(ParamUtils.builder() .equals("customer", customer.getId()).build(), Pageable.unpaged()) .getContent(); diff --git a/client/src/main/java/com/ecep/contract/service/CompanyCustomerEvaluationFormFileService.java b/client/src/main/java/com/ecep/contract/service/CompanyCustomerEvaluationFormFileService.java index 1a66f30..69ab8fa 100644 --- a/client/src/main/java/com/ecep/contract/service/CompanyCustomerEvaluationFormFileService.java +++ b/client/src/main/java/com/ecep/contract/service/CompanyCustomerEvaluationFormFileService.java @@ -6,7 +6,7 @@ import org.springframework.stereotype.Service; import com.ecep.contract.util.ParamUtils; import com.ecep.contract.vm.CompanyCustomerEvaluationFormFileViewModel; import com.ecep.contract.vo.CompanyCustomerEvaluationFormFileVo; -import com.ecep.contract.vo.CompanyCustomerFileVo; +import com.ecep.contract.vo.CustomerFileVo; import java.util.List; @@ -24,7 +24,7 @@ public class CompanyCustomerEvaluationFormFileService /** * 根据客户文件查找评估表文件 */ - public CompanyCustomerEvaluationFormFileVo findByCustomerFile(CompanyCustomerFileVo customerFile) { + public CompanyCustomerEvaluationFormFileVo findByCustomerFile(CustomerFileVo customerFile) { return findByCustomerFile(customerFile.getId()); } diff --git a/client/src/main/java/com/ecep/contract/service/CompanyCustomerFileService.java b/client/src/main/java/com/ecep/contract/service/CompanyCustomerFileService.java index f9d7c16..49bd2a0 100644 --- a/client/src/main/java/com/ecep/contract/service/CompanyCustomerFileService.java +++ b/client/src/main/java/com/ecep/contract/service/CompanyCustomerFileService.java @@ -17,15 +17,15 @@ import com.ecep.contract.MessageHolder; import com.ecep.contract.SpringApp; import com.ecep.contract.constant.CompanyCustomerConstant; import com.ecep.contract.util.ParamUtils; -import com.ecep.contract.vm.CompanyCustomerFileViewModel; -import com.ecep.contract.vo.CompanyCustomerFileVo; -import com.ecep.contract.vo.CompanyCustomerVo; +import com.ecep.contract.vm.CustomerFileViewModel; +import com.ecep.contract.vo.CustomerFileVo; +import com.ecep.contract.vo.CustomerVo; import com.ecep.contract.vo.CompanyVo; import com.ecep.contract.vo.ContractVo; @Service @CacheConfig(cacheNames = "customer-file") -public class CompanyCustomerFileService extends QueryService { +public class CompanyCustomerFileService extends QueryService { public File getEvaluationFormTemplate() { SysConfService confService = SpringApp.getBean(SysConfService.class); @@ -38,11 +38,11 @@ public class CompanyCustomerFileService extends QueryService files = findAllByCustomerAndType(companyCustomer, + List files = findAllByCustomerAndType(companyCustomer, CustomerFileType.EvaluationForm); - CompanyCustomerFileVo latestFile = files.stream() + CustomerFileVo latestFile = files.stream() .filter(v -> v.getSignDate() != null && v.isValid()) - .max(Comparator.comparing(CompanyCustomerFileVo::getSignDate)) + .max(Comparator.comparing(CustomerFileVo::getSignDate)) .orElse(null); if (latestFile == null) { // 没有有效的评估表的评价日期 @@ -104,12 +104,12 @@ public class CompanyCustomerFileService extends QueryService findAllByCustomer(CompanyCustomerVo companyCustomer) { + public List findAllByCustomer(CustomerVo companyCustomer) { return findAll(ParamUtils.builder().equals("customer", companyCustomer).build(), Pageable.unpaged()) .getContent(); } - public List findAllByCustomerAndType(CompanyCustomerVo customer, CustomerFileType type) { + public List findAllByCustomerAndType(CustomerVo customer, CustomerFileType type) { return findAll(ParamUtils.builder() .equals("customer", customer.getId()) .equals("type", type.name()) @@ -118,7 +118,7 @@ public class CompanyCustomerFileService extends QueryService { +public class CustomerService extends QueryService { private File basePath; public File getBasePath() { @@ -30,8 +29,8 @@ public class CompanyCustomerService extends QueryService page = findAll(ParamUtils.equal("company", company.getId()), Pageable.ofSize(1)); + public CustomerVo findByCompany(CompanyVo company) { + Page page = findAll(ParamUtils.equal("company", company.getId()), Pageable.ofSize(1)); if (page.isEmpty()) { return null; } @@ -45,14 +44,14 @@ public class CompanyCustomerService extends QueryService { + public File getEvaluationFormTemplate() { + SysConfService confService = SpringApp.getBean(SysConfService.class); + String path = confService.getString(CompanyVendorConstant.KEY_EVALUATION_FORM_TEMPLATE); + if (path == null) { + return null; + } + return new File(path); + } + /** + * 获取供应商下一个评价表的日期 + * + * @param vendor 供应商 + * @param state 状态消费者 + * @return 下一个评价表的日期 + */ public LocalDate getNextSignDate(VendorVo vendor, Consumer state) { LocalDate miniContractDate = LocalDate.of(2022, 1, 1); // 检索全部合同 ContractService contractService = SpringApp.getBean(ContractService.class); - List contractList = contractService.findAllByCompanyVendor(vendor, null, null); + List contractList = contractService.findAllByCompanyVendor(vendor, miniContractDate, LocalDate.now()); if (contractList.isEmpty()) { state.accept("未发现已登记的合同"); return null; diff --git a/client/src/main/java/com/ecep/contract/service/VendorService.java b/client/src/main/java/com/ecep/contract/service/VendorService.java index 05fe7a3..f5b8e23 100644 --- a/client/src/main/java/com/ecep/contract/service/VendorService.java +++ b/client/src/main/java/com/ecep/contract/service/VendorService.java @@ -65,11 +65,6 @@ public class VendorService extends QueryService implements WebSocketClientTasker { private static final Logger logger = LoggerFactory.getLogger(CloudRkSyncTask.class); - @Setter - private CompanyVo company; @Override protected Object execute(MessageHolder holder) throws Exception { - updateTitle(String.format("集团相关方平台同步任务[%s]", company.getName())); - return callRemoteTask(holder, getLocale(), company.getId()); + updateTitle("集团相关方平台同步任务"); + return callRemoteTask(holder, getLocale()); } @Override diff --git a/client/src/main/java/com/ecep/contract/task/CompanyRkUpdateTasker.java b/client/src/main/java/com/ecep/contract/task/CompanyRkUpdateTasker.java index ad332fa..da9d99f 100644 --- a/client/src/main/java/com/ecep/contract/task/CompanyRkUpdateTasker.java +++ b/client/src/main/java/com/ecep/contract/task/CompanyRkUpdateTasker.java @@ -2,6 +2,7 @@ package com.ecep.contract.task; import com.ecep.contract.MessageHolder; import com.ecep.contract.WebSocketClientTasker; +import com.ecep.contract.service.CloudRkService; import com.ecep.contract.vo.CompanyVo; import lombok.Setter; @@ -23,7 +24,7 @@ public class CompanyRkUpdateTasker extends Tasker implements WebSocketCl @Override protected Object execute(MessageHolder holder) throws Exception { - updateTitle("合并更新 " + company.getName()); + updateTitle("从 集团相关方平台 拉取数据更新 " + company.getName() + " 企业信息"); return callRemoteTask(holder, getLocale(), company.getId()); } diff --git a/client/src/main/java/com/ecep/contract/task/CompanyVendorEvaluationFormUpdateTask.java b/client/src/main/java/com/ecep/contract/task/CompanyVendorEvaluationFormUpdateTask.java index d8bece6..7304320 100644 --- a/client/src/main/java/com/ecep/contract/task/CompanyVendorEvaluationFormUpdateTask.java +++ b/client/src/main/java/com/ecep/contract/task/CompanyVendorEvaluationFormUpdateTask.java @@ -4,16 +4,32 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.ecep.contract.MessageHolder; +import com.ecep.contract.WebSocketClientTasker; +import com.ecep.contract.vo.VendorVo; + +import lombok.Setter; /** * 更新供应商评价表 */ -public class CompanyVendorEvaluationFormUpdateTask extends Tasker { +public class CompanyVendorEvaluationFormUpdateTask extends Tasker implements WebSocketClientTasker { private static final Logger logger = LoggerFactory.getLogger(CompanyVendorEvaluationFormUpdateTask.class); + @Setter + private VendorVo vendor; + + @Override + public void updateProgress(long current, long total) { + super.updateProgress(current, total); + } + + @Override + public String getTaskName() { + return "CompanyVendorEvaluationFormUpdateTask"; + } @Override protected Object execute(MessageHolder holder) throws Exception { updateTitle("更新供应商评价表"); - return null; + return callRemoteTask(holder, getLocale(), vendor.getId()); } } diff --git a/client/src/main/java/com/ecep/contract/task/ContractVerifyComm.java b/client/src/main/java/com/ecep/contract/task/ContractVerifyComm.java index 71f8b79..fa9465e 100644 --- a/client/src/main/java/com/ecep/contract/task/ContractVerifyComm.java +++ b/client/src/main/java/com/ecep/contract/task/ContractVerifyComm.java @@ -4,11 +4,13 @@ import com.ecep.contract.*; import com.ecep.contract.controller.project.cost.ProjectCostImportItemsFromContractsTasker; import com.ecep.contract.model.ContractFileTypeLocal; import com.ecep.contract.service.*; +import com.ecep.contract.util.ContextUtils; import com.ecep.contract.vo.*; import javafx.beans.property.SimpleBooleanProperty; import javafx.collections.ObservableMap; import javafx.util.converter.NumberStringConverter; import lombok.Data; +import org.springframework.beans.BeansException; import org.springframework.util.StringUtils; import java.io.File; @@ -20,173 +22,101 @@ import java.util.*; import java.util.stream.Collectors; @Data -public class ContractVerifyComm { - // Project - private ProjectService projectService; - private ProjectSaleTypeRequireFileTypeService saleTypeRequireFileTypeService; - private ProjectSaleTypeService saleTypeService; - private ProjectCostService projectCostService; - private ProjectQuotationService projectQuotationService; - private ProjectBidService projectBidService; - // Contract - private ContractService contractService; - private ContractFileService contractFileService; - private ContractFileTypeService contractFileTypeService; - private ContractBidVendorService contractBidVendorService; +public class ContractVerifyComm implements ContextUtils { + ContextUtils parent; - // Company - private CompanyService companyService; - private CompanyFileService companyFileService; - // Vendor - private VendorService vendorService; - private VendorGroupService vendorGroupService; - private VendorGroupRequireFileTypeService vendorGroupRequireFileTypeService; - private ExtendVendorInfoService extendVendorInfoService; - // Customer - private CompanyCustomerService companyCustomerService; - private CompanyCustomerFileService companyCustomerFileService; - private CompanyExtendInfoService companyExtendInfoService; - // Employee - private EmployeeService employeeService; + public ContractVerifyComm(ContextUtils parent) { + this.parent = parent; + } + + @Override + public T getBean(Class requiredType) throws BeansException { + return parent.getBean(requiredType); + } + + @Override + public T getCachedBean(Class requiredType) throws BeansException { + return parent.getCachedBean(requiredType); + } private ProjectService getProjectService() { - if (projectService == null) { - projectService = SpringApp.getBean(ProjectService.class); - } - return projectService; + return getCachedBean(ProjectService.class); } private ProjectSaleTypeService getSaleTypeService() { - if (saleTypeService == null) { - saleTypeService = SpringApp.getBean(ProjectSaleTypeService.class); - } - return saleTypeService; + return getCachedBean(ProjectSaleTypeService.class); } - ProjectCostService getProjectCostService() { - if (projectCostService == null) { - projectCostService = SpringApp.getBean(ProjectCostService.class); - } - return projectCostService; + private ProjectCostService getProjectCostService() { + return getCachedBean(ProjectCostService.class); } - ProjectQuotationService getProjectQuotationService() { - if (projectQuotationService == null) { - projectQuotationService = SpringApp.getBean(ProjectQuotationService.class); - } - return projectQuotationService; + private ProjectQuotationService getProjectQuotationService() { + return getCachedBean(ProjectQuotationService.class); } - ProjectBidService getProjectBidService() { - if (projectBidService == null) { - projectBidService = SpringApp.getBean(ProjectBidService.class); - } - return projectBidService; + private ProjectBidService getProjectBidService() { + return getCachedBean(ProjectBidService.class); } private ProjectSaleTypeRequireFileTypeService getSaleTypeRequireFileTypeService() { - if (saleTypeRequireFileTypeService == null) { - saleTypeRequireFileTypeService = SpringApp.getBean(ProjectSaleTypeRequireFileTypeService.class); - } - return saleTypeRequireFileTypeService; + return getCachedBean(ProjectSaleTypeRequireFileTypeService.class); } public ContractService getContractService() { - if (contractService == null) { - contractService = SpringApp.getBean(ContractService.class); - } - return contractService; + return getCachedBean(ContractService.class); } private ContractFileService getContractFileService() { - if (contractFileService == null) { - contractFileService = SpringApp.getBean(ContractFileService.class); - } - return contractFileService; + return getCachedBean(ContractFileService.class); } private ContractFileTypeService getContractFileTypeService() { - if (contractFileTypeService == null) { - contractFileTypeService = SpringApp.getBean(ContractFileTypeService.class); - } - return contractFileTypeService; + return getCachedBean(ContractFileTypeService.class); } private ContractBidVendorService getContractBidVendorService() { - if (contractBidVendorService == null) { - contractBidVendorService = SpringApp.getBean(ContractBidVendorService.class); - } - return contractBidVendorService; + return getCachedBean(ContractBidVendorService.class); } private CompanyService getCompanyService() { - if (companyService == null) { - companyService = SpringApp.getBean(CompanyService.class); - } - return companyService; + return getBean(CompanyService.class); } private CompanyFileService getCompanyFileService() { - if (companyFileService == null) { - companyFileService = SpringApp.getBean(CompanyFileService.class); - } - return companyFileService; + return getCachedBean(CompanyFileService.class); } private VendorGroupService getVendorGroupService() { - if (vendorGroupService == null) { - vendorGroupService = SpringApp.getBean(VendorGroupService.class); - } - return vendorGroupService; + return getCachedBean(VendorGroupService.class); } private VendorGroupRequireFileTypeService getVendorGroupRequireFileTypeService() { - if (vendorGroupRequireFileTypeService == null) { - vendorGroupRequireFileTypeService = SpringApp.getBean(VendorGroupRequireFileTypeService.class); - } - return vendorGroupRequireFileTypeService; + return getCachedBean(VendorGroupRequireFileTypeService.class); } private ExtendVendorInfoService getExtendVendorInfoService() { - if (extendVendorInfoService == null) { - extendVendorInfoService = SpringApp.getBean(ExtendVendorInfoService.class); - } - return extendVendorInfoService; + return getCachedBean(ExtendVendorInfoService.class); } private VendorService getVendorService() { - if (vendorService == null) { - vendorService = SpringApp.getBean(VendorService.class); - } - return vendorService; + return getCachedBean(VendorService.class); } - private CompanyCustomerService getCompanyCustomerService() { - if (companyCustomerService == null) { - companyCustomerService = SpringApp.getBean(CompanyCustomerService.class); - } - return companyCustomerService; + private CustomerService getCompanyCustomerService() { + return getCachedBean(CustomerService.class); } private CompanyCustomerFileService getCompanyCustomerFileService() { - if (companyCustomerFileService == null) { - companyCustomerFileService = SpringApp.getBean(CompanyCustomerFileService.class); - } - return companyCustomerFileService; + return getCachedBean(CompanyCustomerFileService.class); } private CompanyExtendInfoService getCompanyExtendInfoService() { - if (companyExtendInfoService == null) { - companyExtendInfoService = SpringApp.getBean(CompanyExtendInfoService.class); - } - return companyExtendInfoService; + return getCachedBean(CompanyExtendInfoService.class); } private EmployeeService getEmployeeService() { - if (employeeService == null) { - employeeService = SpringApp.getBean(EmployeeService.class); - } - return employeeService; + return getCachedBean(EmployeeService.class); } /** @@ -389,6 +319,7 @@ public class ContractVerifyComm { } } if (verifyVendor.get()) { + getVendorService().verify(contract, holder); } @@ -581,7 +512,7 @@ public class ContractVerifyComm { valid = false; } - CompanyCustomerVo companyCustomer = getCompanyCustomerService().findByCompany(company); + CustomerVo companyCustomer = getCompanyCustomerService().findByCompany(company); if (companyCustomer == null) { holder.warn("合同未关联客户"); valid = false; @@ -602,7 +533,7 @@ public class ContractVerifyComm { return valid; } - private boolean verifyCustomerFileByContract(CompanyCustomerVo companyCustomer, ContractVo contract, + private boolean verifyCustomerFileByContract(CustomerVo companyCustomer, ContractVo contract, MessageHolder holder) { List verifyDates = new ArrayList<>(); LocalDate minDate = LocalDate.of(2022, 1, 1); @@ -655,14 +586,14 @@ public class ContractVerifyComm { } // 客户 - List files = getCompanyCustomerFileService().findAllByCustomer(companyCustomer); + List files = getCompanyCustomerFileService().findAllByCustomer(companyCustomer); if (files == null || files.isEmpty()) { holder.warn("未见客户评估表"); return false; } for (LocalDate verifyDate : verifyDates) { - CompanyCustomerFileVo customerFile = files.stream() + CustomerFileVo customerFile = files.stream() .filter(v -> v.getSignDate() != null && v.isValid()) .filter(v -> v.getType() == CustomerFileType.EvaluationForm) .filter(v -> MyDateTimeUtils.dateValidFilter(verifyDate, v.getSignDate(), @@ -673,10 +604,10 @@ public class ContractVerifyComm { } } - CompanyCustomerFileVo latestFile = files.stream() + CustomerFileVo latestFile = files.stream() .filter(v -> v.getSignDate() != null && v.isValid()) .filter(v -> v.getType() == CustomerFileType.EvaluationForm) - .max(Comparator.comparing(CompanyCustomerFileVo::getSignDate)) + .max(Comparator.comparing(CustomerFileVo::getSignDate)) .orElse(null); if (latestFile == null) { diff --git a/client/src/main/java/com/ecep/contract/task/VendorReBuildFilesTasker.java b/client/src/main/java/com/ecep/contract/task/VendorReBuildFilesTasker.java index e8d4d5c..a7a8b6e 100644 --- a/client/src/main/java/com/ecep/contract/task/VendorReBuildFilesTasker.java +++ b/client/src/main/java/com/ecep/contract/task/VendorReBuildFilesTasker.java @@ -1,4 +1,55 @@ package com.ecep.contract.task; -public class VendorReBuildFilesTasker { +import com.ecep.contract.MessageHolder; +import com.ecep.contract.WebSocketClientTasker; +import com.ecep.contract.vo.VendorVo; + +import lombok.Getter; +import lombok.Setter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * 供应商文件重建任务器客户端实现 + * 用于通过WebSocket与服务器通信,重建供应商相关文件 + */ +public class VendorReBuildFilesTasker extends Tasker implements WebSocketClientTasker { + private static final Logger logger = LoggerFactory.getLogger(VendorReBuildFilesTasker.class); + + @Getter + @Setter + private VendorVo vendor; + + @Getter + protected boolean modified = false; + + @Override + public String getTaskName() { + return "VendorReBuildFilesTasker"; + } + + @Override + public void updateProgress(long current, long total) { + super.updateProgress(current, total); + } + + @Override + protected Object execute(MessageHolder holder) throws Exception { + updateTitle("重建供应商文件"); + if (vendor == null) { + holder.addMessage(java.util.logging.Level.SEVERE, "供应商信息不能为空"); + return null; + } + return callRemoteTask(holder, getLocale(), vendor.getId()); + } + + /** + * 处理从服务器返回的修改状态 + * 当服务器端更新此属性时,客户端会接收到更新 + * + * @param modified 文件是否被修改 + */ + public void setModified(boolean modified) { + this.modified = modified; + } } diff --git a/client/src/main/java/com/ecep/contract/util/ParamUtils.java b/client/src/main/java/com/ecep/contract/util/ParamUtils.java index 2bb6bee..d7cc7c0 100644 --- a/client/src/main/java/com/ecep/contract/util/ParamUtils.java +++ b/client/src/main/java/com/ecep/contract/util/ParamUtils.java @@ -14,7 +14,7 @@ import com.ecep.contract.constant.ServiceConstant; public class ParamUtils { /** * 创建日期范围查询参数 - * + * * @param key 查询字段名 * @param begin 开始日期 * @param end 结束日期 @@ -28,7 +28,7 @@ public class ParamUtils { /** * 创建等于条件查询参数 - * + * * @param key 查询字段名 * @param value 查询值 * @return 包含等于条件的查询参数Map @@ -39,7 +39,7 @@ public class ParamUtils { /** * 创建字符串模糊查询参数 - * + * * @param key 查询字段名 * @param value 模糊查询的字符串值 * @return 包含模糊查询条件的查询参数Map @@ -52,7 +52,7 @@ public class ParamUtils { /** * 创建日期模糊查询参数 - * + * * @param key 查询字段名 * @param value 模糊查询的日期值 * @return 包含日期模糊查询条件的查询参数Map @@ -65,7 +65,7 @@ public class ParamUtils { /** * 创建非空条件查询参数 - * + * * @param key 查询字段名 * @return 包含非空条件的查询参数Map */ @@ -77,7 +77,7 @@ public class ParamUtils { /** * 创建小于条件的日期查询参数 - * + * * @param key 查询字段名 * @param value 比较的日期值 * @return 包含小于条件的查询参数Map @@ -90,7 +90,7 @@ public class ParamUtils { /** * 创建参数构建器实例 - * + * * @return Builder实例,用于链式构建复杂查询条件 */ public static Builder builder() { @@ -114,7 +114,7 @@ public class ParamUtils { /** * 添加非空条件到构建器 - * + * * @param key 查询字段名 * @return 当前Builder实例,支持链式调用 */ @@ -125,7 +125,7 @@ public class ParamUtils { /** * 添加小于条件到构建器(针对日期类型) - * + * * @param key 查询字段名 * @param value 比较的日期值 * @return 当前Builder实例,支持链式调用 @@ -137,7 +137,7 @@ public class ParamUtils { /** * 添加大于条件到构建器(针对日期类型) - * + * * @param key 查询字段名 * @param value 比较的日期值 * @return 当前Builder实例,支持链式调用 @@ -149,7 +149,7 @@ public class ParamUtils { /** * 添加等于条件到构建器 - * + * * @param key 查询字段名 * @param value 查询值 * @return 当前Builder实例,支持链式调用 @@ -161,20 +161,24 @@ public class ParamUtils { /** * 添加日期范围条件到构建器 - * + * * @param key 查询字段名 * @param begin 开始日期 * @param end 结束日期 * @return 当前Builder实例,支持链式调用 */ public Builder between(String key, LocalDate begin, LocalDate end) { - params.put(key, Map.of("begin", begin, "end", end)); + Map params = new HashMap<>(); + params.put("begin", begin); + params.put("end", end); + this.params.put(key, params); return this; } + /** * 添加全文搜索条件到构建器 - * + * * @param searchText 搜索文本 * @return 当前Builder实例,支持链式调用 */ @@ -185,7 +189,7 @@ public class ParamUtils { /** * 构建并返回查询参数Map - * + * * @return 包含所有添加条件的查询参数Map */ public Map build() { @@ -194,7 +198,7 @@ public class ParamUtils { /** * 添加AND逻辑条件组到构建器 - * + * * @param consumer Builder消费者,用于构建子条件 * @return 当前Builder实例,支持链式调用 */ @@ -207,7 +211,7 @@ public class ParamUtils { /** * 添加OR逻辑条件组到构建器 - * + * * @param consumer Builder消费者,用于构建子条件 * @return 当前Builder实例,支持链式调用 */ diff --git a/client/src/main/java/com/ecep/contract/vm/CompanyCustomerViewModel.java b/client/src/main/java/com/ecep/contract/vm/CompanyCustomerViewModel.java index 0ea622c..4b58ac4 100644 --- a/client/src/main/java/com/ecep/contract/vm/CompanyCustomerViewModel.java +++ b/client/src/main/java/com/ecep/contract/vm/CompanyCustomerViewModel.java @@ -4,7 +4,7 @@ import java.time.LocalDate; import java.time.LocalDateTime; import java.util.Objects; -import com.ecep.contract.vo.CompanyCustomerVo; +import com.ecep.contract.vo.CustomerVo; import javafx.beans.property.SimpleIntegerProperty; import javafx.beans.property.SimpleObjectProperty; @@ -14,7 +14,7 @@ import lombok.EqualsAndHashCode; @Data @EqualsAndHashCode(callSuper = false) -public class CompanyCustomerViewModel extends IdentityViewModel { +public class CompanyCustomerViewModel extends IdentityViewModel { private SimpleStringProperty state = new SimpleStringProperty(); /** * 关联的企业,Company @@ -39,13 +39,13 @@ public class CompanyCustomerViewModel extends IdentityViewModel created = new SimpleObjectProperty<>(); private SimpleIntegerProperty version = new SimpleIntegerProperty(); - public static CompanyCustomerViewModel from(CompanyCustomerVo cc) { + public static CompanyCustomerViewModel from(CustomerVo cc) { CompanyCustomerViewModel model = new CompanyCustomerViewModel(); model.update(cc); return model; } - public void updateFrom(CompanyCustomerVo c) { + public void updateFrom(CustomerVo c) { super.updateFrom(c); getCompany().set(c.getCompanyId()); getCatalog().set(c.getCatalogId()); @@ -57,7 +57,7 @@ public class CompanyCustomerViewModel extends IdentityViewModel { +public class CustomerFileViewModel extends IdentityViewModel { - public static CompanyCustomerFileViewModel from(CompanyCustomerFileVo companyCustomerFile) { - CompanyCustomerFileViewModel model = new CompanyCustomerFileViewModel(); + public static CustomerFileViewModel from(CustomerFileVo companyCustomerFile) { + CustomerFileViewModel model = new CustomerFileViewModel(); model.update(companyCustomerFile); return model; } @@ -44,7 +44,7 @@ public class CompanyCustomerFileViewModel extends IdentityViewModel + + + + + + diff --git a/client/src/main/resources/ui/contract/sale-orders-tab-bill-voucher.fxml b/client/src/main/resources/ui/contract/sale-orders-tab-bill-voucher.fxml index 76ea860..e4d13f5 100644 --- a/client/src/main/resources/ui/contract/sale-orders-tab-bill-voucher.fxml +++ b/client/src/main/resources/ui/contract/sale-orders-tab-bill-voucher.fxml @@ -5,7 +5,7 @@ + fx:controller="com.ecep.contract.controller.tab.SalesOrderTabSkinBillVoucher"> diff --git a/client/src/main/resources/ui/contract/sale-orders-tab-item.fxml b/client/src/main/resources/ui/contract/sale-orders-tab-item.fxml index 7f003f3..39aefb6 100644 --- a/client/src/main/resources/ui/contract/sale-orders-tab-item.fxml +++ b/client/src/main/resources/ui/contract/sale-orders-tab-item.fxml @@ -5,7 +5,7 @@ + fx:controller="com.ecep.contract.controller.tab.SalesOrderTabSkinItems"> diff --git a/common/pom.xml b/common/pom.xml index d000796..59087d5 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -6,12 +6,12 @@ com.ecep.contract Contract-Manager - 0.0.101-SNAPSHOT + 0.0.102-SNAPSHOT com.ecep.contract common - 0.0.101-SNAPSHOT + 0.0.102-SNAPSHOT ${java.version} diff --git a/common/src/main/java/com/ecep/contract/util/ContextUtils.java b/common/src/main/java/com/ecep/contract/util/ContextUtils.java index ddd5c17..ed46d9e 100644 --- a/common/src/main/java/com/ecep/contract/util/ContextUtils.java +++ b/common/src/main/java/com/ecep/contract/util/ContextUtils.java @@ -1,4 +1,9 @@ package com.ecep.contract.util; +import org.springframework.beans.BeansException; + public interface ContextUtils { + T getBean(Class requiredType) throws BeansException; + + T getCachedBean(Class requiredType) throws BeansException; } diff --git a/common/src/main/java/com/ecep/contract/util/FileUtils.java b/common/src/main/java/com/ecep/contract/util/FileUtils.java index cd3fb9b..8756134 100644 --- a/common/src/main/java/com/ecep/contract/util/FileUtils.java +++ b/common/src/main/java/com/ecep/contract/util/FileUtils.java @@ -72,4 +72,28 @@ public class FileUtils { } return fileName.startsWith("~$"); } + + /** + * 检查文件是否为可编辑文件 + * + * @param fileName 文件名 + * @return 是否为可编辑文件 + */ + public static boolean isEditableFile(String fileName) { + return withExtensions(fileName, + XLS, XLSX, + DOC, DOCX); + } + + /** + * 检查文件是否为归档文件 + * + * @param fileName 文件名 + * @return 是否为归档文件 + */ + public static boolean isArchiveFile(String fileName) { + return withExtensions(fileName, + PNG, PDF, + JPG, JPEG); + } } diff --git a/common/src/main/java/com/ecep/contract/vo/CompanyCustomerFileVo.java b/common/src/main/java/com/ecep/contract/vo/CustomerFileVo.java similarity index 86% rename from common/src/main/java/com/ecep/contract/vo/CompanyCustomerFileVo.java rename to common/src/main/java/com/ecep/contract/vo/CustomerFileVo.java index eca1ef1..7dbfd97 100644 --- a/common/src/main/java/com/ecep/contract/vo/CompanyCustomerFileVo.java +++ b/common/src/main/java/com/ecep/contract/vo/CustomerFileVo.java @@ -7,7 +7,7 @@ import java.time.LocalDate; import lombok.Data; @Data -public class CompanyCustomerFileVo implements IdentityEntity, Serializable { +public class CustomerFileVo implements IdentityEntity, Serializable { private static final long serialVersionUID = 1L; private Integer id; private Integer customer; diff --git a/common/src/main/java/com/ecep/contract/vo/CompanyCustomerVo.java b/common/src/main/java/com/ecep/contract/vo/CustomerVo.java similarity index 86% rename from common/src/main/java/com/ecep/contract/vo/CompanyCustomerVo.java rename to common/src/main/java/com/ecep/contract/vo/CustomerVo.java index e538a56..c183d04 100644 --- a/common/src/main/java/com/ecep/contract/vo/CompanyCustomerVo.java +++ b/common/src/main/java/com/ecep/contract/vo/CustomerVo.java @@ -9,7 +9,7 @@ import com.ecep.contract.model.IdentityEntity; import lombok.Data; @Data -public class CompanyCustomerVo implements IdentityEntity, CompanyBasedVo, Serializable { +public class CustomerVo implements IdentityEntity, CompanyBasedVo, Serializable { private static final long serialVersionUID = 1L; private Integer id; /** diff --git a/common/src/main/java/com/ecep/contract/vo/SalesBillVoucherVo.java b/common/src/main/java/com/ecep/contract/vo/SalesBillVoucherVo.java index 84f1570..aac6aa5 100644 --- a/common/src/main/java/com/ecep/contract/vo/SalesBillVoucherVo.java +++ b/common/src/main/java/com/ecep/contract/vo/SalesBillVoucherVo.java @@ -15,7 +15,6 @@ public class SalesBillVoucherVo implements IdentityEntity, CompanyBasedVo, java. private String code; private Integer companyId; private Integer orderId; - private String orderCode; private Integer employeeId; private Integer makerId; private LocalDateTime makerDate; diff --git a/pom.xml b/pom.xml index ec11c30..b2fd326 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ com.ecep.contract Contract-Manager - 0.0.101-SNAPSHOT + 0.0.102-SNAPSHOT pom server diff --git a/server/pom.xml b/server/pom.xml index 8ad32f1..53b445e 100644 --- a/server/pom.xml +++ b/server/pom.xml @@ -6,12 +6,12 @@ com.ecep.contract Contract-Manager - 0.0.101-SNAPSHOT + 0.0.102-SNAPSHOT com.ecep.contract server - 0.0.101-SNAPSHOT + 0.0.102-SNAPSHOT ${java.version} @@ -22,7 +22,7 @@ com.ecep.contract common - 0.0.101-SNAPSHOT + 0.0.102-SNAPSHOT org.springframework.boot diff --git a/server/src/main/java/com/ecep/contract/cloud/old/OldVersionSyncCustomerTask.java b/server/src/main/java/com/ecep/contract/cloud/old/OldVersionSyncCustomerTask.java index 22f3b11..9baabdd 100644 --- a/server/src/main/java/com/ecep/contract/cloud/old/OldVersionSyncCustomerTask.java +++ b/server/src/main/java/com/ecep/contract/cloud/old/OldVersionSyncCustomerTask.java @@ -2,7 +2,7 @@ package com.ecep.contract.cloud.old; import com.ecep.contract.MessageHolder; import com.ecep.contract.SpringApp; -import com.ecep.contract.ds.customer.service.CompanyCustomerService; +import com.ecep.contract.ds.customer.service.CustomerService; import com.ecep.contract.ds.company.model.Company; import com.ecep.contract.ds.contract.model.Contract; import com.ecep.contract.ui.Tasker; @@ -37,7 +37,7 @@ public class OldVersionSyncCustomerTask extends Tasker { @Override protected Object execute(MessageHolder holder) throws Exception { updateTitle("老版本-同步客户数据"); - basePath = getCachedBean(CompanyCustomerService.class).getBasePath(); + basePath = getCachedBean(CustomerService.class).getBasePath(); List runnable = Arrays.asList(this::loadOldNames, this::loadContacts, this::syncCustomers, this::syncContracts); diff --git a/server/src/main/java/com/ecep/contract/cloud/rk/CloudRkRepository.java b/server/src/main/java/com/ecep/contract/cloud/rk/CloudRkRepository.java index 97e8a7f..85c84ba 100644 --- a/server/src/main/java/com/ecep/contract/cloud/rk/CloudRkRepository.java +++ b/server/src/main/java/com/ecep/contract/cloud/rk/CloudRkRepository.java @@ -1,6 +1,7 @@ package com.ecep.contract.cloud.rk; import java.time.Instant; +import java.time.LocalDateTime; import java.util.List; import java.util.Optional; import java.util.stream.Stream; @@ -38,13 +39,13 @@ public interface CloudRkRepository extends MyRepository { List findAllByCompanyId(int companyId); - long countByLatestUpdateBefore(Instant instant); + long countByLatestUpdateBefore(LocalDateTime instant); - long countByAutoUpdateIsTrueAndLatestUpdateBefore(Instant instant); + long countByAutoUpdateIsTrueAndLatestUpdateBefore(LocalDateTime instant); - List findTop100ByLatestUpdateBeforeOrderByLatestUpdateDesc(Instant instant); + List findTop100ByLatestUpdateBeforeOrderByLatestUpdateDesc(LocalDateTime instant); - List findTop100ByAutoUpdateIsTrueAndLatestUpdateBeforeOrderByLatestUpdateDesc(Instant instant); + List findTop100ByAutoUpdateIsTrueAndLatestUpdateBeforeOrderByLatestUpdateDesc(LocalDateTime instant); @Modifying @Transactional diff --git a/server/src/main/java/com/ecep/contract/cloud/rk/CloudRkService.java b/server/src/main/java/com/ecep/contract/cloud/rk/CloudRkService.java index ed865a9..15b426a 100644 --- a/server/src/main/java/com/ecep/contract/cloud/rk/CloudRkService.java +++ b/server/src/main/java/com/ecep/contract/cloud/rk/CloudRkService.java @@ -354,9 +354,9 @@ public class CloudRkService implements IEntityService, QueryService, QueryService findNeedUpdate() { - Instant now = Instant.now(); + LocalDateTime now = LocalDateTime.now(); long elapse = getSyncElapse(); - Instant instant = now.minusSeconds(elapse); + LocalDateTime instant = now.minusSeconds(elapse); return cloudRKRepository.findTop100ByAutoUpdateIsTrueAndLatestUpdateBeforeOrderByLatestUpdateDesc(instant); } diff --git a/server/src/main/java/com/ecep/contract/cloud/rk/ctx/CloudRkCtx.java b/server/src/main/java/com/ecep/contract/cloud/rk/ctx/CloudRkCtx.java index cdf3282..41c3e5a 100644 --- a/server/src/main/java/com/ecep/contract/cloud/rk/ctx/CloudRkCtx.java +++ b/server/src/main/java/com/ecep/contract/cloud/rk/ctx/CloudRkCtx.java @@ -86,7 +86,7 @@ public class CloudRkCtx extends AbstractCtx implements CloudRkContext { */ public boolean syncCompany(Company company, CloudRk cloudRk, MessageHolder holder) { if (!StringUtils.hasText(cloudRk.getCloudId())) { - holder.warn("未定义平台编号, 尝试从平台上自动获取"); + holder.warn("未定义平台编号, 尝试获取平台编号"); // 当未定义平台编号时,尝试自动获取 if (!queryCloudIdAndSelectOne(company, cloudRk, holder)) { // 自动获取到平台编号失败,立即返回 @@ -468,6 +468,7 @@ public class CloudRkCtx extends AbstractCtx implements CloudRkContext { List results = new ArrayList<>(); ObjectMapper objectMapper = getObjectMapper(); try { + holder.debug("POST " + url); HttpJsonUtils.post(url, data -> { data.put("theKey", company.getName()); data.put("get", true); @@ -819,13 +820,13 @@ public class CloudRkCtx extends AbstractCtx implements CloudRkContext { private void saveJsonToFile(Company company, JsonNode json, String fileName, MessageHolder holder) { String companyPath = company.getPath(); if (!StringUtils.hasText(companyPath)) { - holder.warn("公司路径为空"); + holder.warn("公司路径为空, 无法保存 " + fileName); return; } File dir = new File(companyPath); if (!dir.exists()) { - holder.warn("公司路径不存在"); + holder.warn("公司路径" + dir.getName() + "不存在, 无法保存 " + fileName); return; } diff --git a/server/src/main/java/com/ecep/contract/cloud/u8/CustomerClassSyncTask.java b/server/src/main/java/com/ecep/contract/cloud/u8/CustomerClassSyncTask.java index 29c5b70..33c20cd 100644 --- a/server/src/main/java/com/ecep/contract/cloud/u8/CustomerClassSyncTask.java +++ b/server/src/main/java/com/ecep/contract/cloud/u8/CustomerClassSyncTask.java @@ -12,7 +12,7 @@ import org.springframework.beans.BeansException; import com.ecep.contract.MessageHolder; import com.ecep.contract.SpringApp; -import com.ecep.contract.ds.customer.service.CompanyCustomerService; +import com.ecep.contract.ds.customer.service.CustomerService; import com.ecep.contract.model.CustomerCatalog; import com.ecep.contract.ui.Tasker; import com.ecep.contract.vo.CustomerCatalogVo; @@ -25,15 +25,15 @@ import lombok.Setter; public class CustomerClassSyncTask extends Tasker { private static final Logger logger = LoggerFactory.getLogger(CustomerClassSyncTask.class); @Setter - private CompanyCustomerService companyCustomerService; + private CustomerService companyCustomerService; public CustomerClassSyncTask() { updateTitle("用友U8系统-同步客户分类信息"); } - CompanyCustomerService getCompanyCustomerService() { + CustomerService getCompanyCustomerService() { if (companyCustomerService == null) { - companyCustomerService = SpringApp.getBean(CompanyCustomerService.class); + companyCustomerService = SpringApp.getBean(CustomerService.class); } return companyCustomerService; } diff --git a/server/src/main/java/com/ecep/contract/cloud/u8/CustomerSyncTask.java b/server/src/main/java/com/ecep/contract/cloud/u8/CustomerSyncTask.java index b4d3cf2..6aa7d53 100644 --- a/server/src/main/java/com/ecep/contract/cloud/u8/CustomerSyncTask.java +++ b/server/src/main/java/com/ecep/contract/cloud/u8/CustomerSyncTask.java @@ -20,7 +20,7 @@ import com.ecep.contract.cloud.u8.ctx.CustomerCtx; import com.ecep.contract.constant.CloudServiceConstant; import com.ecep.contract.ds.company.service.CompanyService; import com.ecep.contract.ds.contract.tasker.AbstContractRepairTasker; -import com.ecep.contract.ds.customer.service.CompanyCustomerService; +import com.ecep.contract.ds.customer.service.CustomerService; import com.ecep.contract.ds.other.model.CloudYu; import com.ecep.contract.ds.company.model.Company; import com.ecep.contract.ds.customer.model.CompanyCustomer; @@ -42,7 +42,7 @@ public class CustomerSyncTask extends AbstContractRepairTasker { updateTitle("用友U8系统-同步客户"); } - private CompanyCustomerService getCompanyCustomerService() { + private CustomerService getCompanyCustomerService() { return customerCtx.getCompanyCustomerService(); } diff --git a/server/src/main/java/com/ecep/contract/cloud/u8/ctx/AbstractYongYouU8Ctx.java b/server/src/main/java/com/ecep/contract/cloud/u8/ctx/AbstractYongYouU8Ctx.java index 75a563a..fc69b2b 100644 --- a/server/src/main/java/com/ecep/contract/cloud/u8/ctx/AbstractYongYouU8Ctx.java +++ b/server/src/main/java/com/ecep/contract/cloud/u8/ctx/AbstractYongYouU8Ctx.java @@ -14,7 +14,7 @@ import com.ecep.contract.cloud.AbstractCtx; import com.ecep.contract.cloud.u8.YongYouU8Repository; import com.ecep.contract.constant.CloudServiceConstant; import com.ecep.contract.ds.customer.service.CompanyCustomerEntityService; -import com.ecep.contract.ds.customer.service.CompanyCustomerService; +import com.ecep.contract.ds.customer.service.CustomerService; import com.ecep.contract.ds.vendor.service.VendorEntityService; import com.ecep.contract.ds.vendor.service.VendorService; import com.ecep.contract.ds.company.model.Company; @@ -45,8 +45,8 @@ public class AbstractYongYouU8Ctx extends AbstractCtx { } } - public CompanyCustomerService getCompanyCustomerService() { - return getCachedBean(CompanyCustomerService.class); + public CustomerService getCompanyCustomerService() { + return getCachedBean(CustomerService.class); } public CompanyCustomerEntityService getCompanyCustomerEntityService() { @@ -111,12 +111,12 @@ public class AbstractYongYouU8Ctx extends AbstractCtx { Company company = null; if (StringUtils.hasText(customerCode)) { CompanyCustomerEntityService customerEntityService = getCompanyCustomerEntityService(); - CompanyCustomerService customerService = getCompanyCustomerService(); + CustomerService customerService = getCompanyCustomerService(); CompanyCustomerEntityVo entity = customerEntityService.findByCustomerCode(customerCode); if (entity == null) { holder.warn("无效" + topic + ":" + customerCode); } else { - CompanyCustomerVo customer = customerService.findById(entity.getCustomerId()); + CustomerVo customer = customerService.findById(entity.getCustomerId()); if (customer == null) { holder.warn("无效" + topic + ":" + customerCode); } else { diff --git a/server/src/main/java/com/ecep/contract/cloud/u8/ctx/ContractCtx.java b/server/src/main/java/com/ecep/contract/cloud/u8/ctx/ContractCtx.java index 6b8f3a6..a81d8a8 100644 --- a/server/src/main/java/com/ecep/contract/cloud/u8/ctx/ContractCtx.java +++ b/server/src/main/java/com/ecep/contract/cloud/u8/ctx/ContractCtx.java @@ -37,7 +37,7 @@ import com.ecep.contract.ds.contract.service.ContractPayPlanService; import com.ecep.contract.ds.contract.service.ContractService; import com.ecep.contract.ds.contract.service.ContractTypeService; import com.ecep.contract.ds.customer.service.CompanyCustomerEntityService; -import com.ecep.contract.ds.customer.service.CompanyCustomerService; +import com.ecep.contract.ds.customer.service.CustomerService; import com.ecep.contract.ds.project.ProjectCtx; import com.ecep.contract.ds.project.service.ProjectSaleTypeService; import com.ecep.contract.ds.vendor.service.VendorEntityService; @@ -463,7 +463,7 @@ public class ContractCtx extends AbstractYongYouU8Ctx { boolean modified = false; boolean customerModified = false; CompanyCustomerEntityService customerEntityService = getCompanyCustomerEntityService(); - CompanyCustomerService customerService = getCompanyCustomerService(); + CustomerService customerService = getCompanyCustomerService(); CompanyCustomerEntityVo entity = customerEntityService.findByCustomerCode(unit); if (entity == null) { CompanyCustomerEntity v1 = new CompanyCustomerEntity(); @@ -472,7 +472,7 @@ public class ContractCtx extends AbstractYongYouU8Ctx { } entity = updateCustomerEntityDetailByCode(entity, unit, holder); - CompanyCustomerVo customer = customerService.findById(entity.getCustomerId()); + CustomerVo customer = customerService.findById(entity.getCustomerId()); if (customer == null) { if (company != null) { customer = customerService.findByCompany(company).toVo(); diff --git a/server/src/main/java/com/ecep/contract/ds/company/repository/CompanyContactRepository.java b/server/src/main/java/com/ecep/contract/ds/company/repository/CompanyContactRepository.java index b5d9729..b45f6fa 100644 --- a/server/src/main/java/com/ecep/contract/ds/company/repository/CompanyContactRepository.java +++ b/server/src/main/java/com/ecep/contract/ds/company/repository/CompanyContactRepository.java @@ -14,6 +14,8 @@ public interface CompanyContactRepository extends MyRepository findFirstByCompany(Company company); + Optional findFirstByCompanyId(Integer companyId); + List findAllByCompany(Company company); List findAllByCompanyAndName(Company company, String name); diff --git a/server/src/main/java/com/ecep/contract/ds/company/service/CompanyBasicService.java b/server/src/main/java/com/ecep/contract/ds/company/service/CompanyBasicService.java index 42b139e..98c14a2 100644 --- a/server/src/main/java/com/ecep/contract/ds/company/service/CompanyBasicService.java +++ b/server/src/main/java/com/ecep/contract/ds/company/service/CompanyBasicService.java @@ -77,18 +77,6 @@ public abstract class CompanyBasicService { @Autowired protected CompanyService companyService; - protected boolean isEditableFile(String fileName) { - return FileUtils.withExtensions(fileName, - FileUtils.XLS, FileUtils.XLSX, - FileUtils.DOC, FileUtils.DOCX); - } - - protected boolean isArchiveFile(String fileName) { - return FileUtils.withExtensions(fileName, - FileUtils.PNG, FileUtils.PDF, - FileUtils.JPG, FileUtils.JPEG); - } - public abstract , ID> void deleteFile(F file); protected , ID> boolean fetchDbFiles(List dbFiles, Map map, @@ -328,7 +316,7 @@ public abstract class CompanyBasicService { // 文件全路径 String fileAbsolutePath = file.getAbsolutePath(); - if (isEditableFile(fileName)) { + if (FileUtils.isEditableFile(fileName)) { // 是可编辑文件时 if (!Objects.equals(fileAbsolutePath, customerFile.getEditFilePath())) { customerFile.setEditFilePath(fileAbsolutePath); @@ -338,7 +326,7 @@ public abstract class CompanyBasicService { if (useAsEditableFile(customerFile, file, fileList, status)) { modified = true; } - } else if (isArchiveFile(fileName)) { + } else if (FileUtils.isArchiveFile(fileName)) { // 存档文件时 if (!Objects.equals(fileAbsolutePath, customerFile.getFilePath())) { customerFile.setFilePath(fileAbsolutePath); @@ -387,7 +375,7 @@ public abstract class CompanyBasicService { String name = StringUtils.stripFilenameExtension(fileName); for (File f : fileList) { // 查找存档文件 - if (f.getName().startsWith(name) && isArchiveFile(f.getName())) { + if (f.getName().startsWith(name) && FileUtils.isArchiveFile(f.getName())) { archiveFile = f; break; } @@ -431,7 +419,7 @@ public abstract class CompanyBasicService { String name = StringUtils.stripFilenameExtension(fileName); for (File f : fileList) { // 查找存档文件 - if (f.getName().startsWith(name) && isEditableFile(f.getName())) { + if (f.getName().startsWith(name) && FileUtils.isEditableFile(f.getName())) { editFile = f; break; } diff --git a/server/src/main/java/com/ecep/contract/ds/company/service/CompanyContactService.java b/server/src/main/java/com/ecep/contract/ds/company/service/CompanyContactService.java index 076bdcb..a19be87 100644 --- a/server/src/main/java/com/ecep/contract/ds/company/service/CompanyContactService.java +++ b/server/src/main/java/com/ecep/contract/ds/company/service/CompanyContactService.java @@ -25,6 +25,7 @@ import com.ecep.contract.service.VoableService; import com.ecep.contract.util.MyStringUtils; import com.ecep.contract.util.SpecificationUtils; import com.ecep.contract.vo.CompanyContactVo; +import com.ecep.contract.vo.CompanyVo; import com.fasterxml.jackson.databind.JsonNode; /** @@ -81,6 +82,10 @@ public class CompanyContactService implements IEntityService, Qu return repository.findFirstByCompany(company).orElse(null); } + public CompanyContactVo findFirstByCompany(CompanyVo company) { + return repository.findFirstByCompanyId(company.getId()).map(CompanyContact::toVo).orElse(null); + } + @Override public CompanyContactVo findById(Integer id) { return repository.findById(id).map(CompanyContact::toVo).orElse(null); diff --git a/server/src/main/java/com/ecep/contract/ds/company/service/CompanyService.java b/server/src/main/java/com/ecep/contract/ds/company/service/CompanyService.java index c23a556..ba023fe 100644 --- a/server/src/main/java/com/ecep/contract/ds/company/service/CompanyService.java +++ b/server/src/main/java/com/ecep/contract/ds/company/service/CompanyService.java @@ -33,7 +33,7 @@ import com.ecep.contract.cloud.u8.YongYouU8Service; import com.ecep.contract.constant.CompanyConstant; import com.ecep.contract.ds.company.repository.CompanyRepository; import com.ecep.contract.ds.contract.service.ContractService; -import com.ecep.contract.ds.customer.service.CompanyCustomerService; +import com.ecep.contract.ds.customer.service.CustomerService; import com.ecep.contract.ds.other.service.SysConfService; import com.ecep.contract.ds.vendor.service.VendorService; import com.ecep.contract.ds.company.model.Company; @@ -76,7 +76,7 @@ public class CompanyService extends EntityService private VendorService vendorService; @Lazy @Autowired - private CompanyCustomerService companyCustomerService; + private CustomerService companyCustomerService; @Lazy @Autowired private CompanyOldNameService companyOldNameService; @@ -267,7 +267,7 @@ public class CompanyService extends EntityService * 删除前需要把关联数据解除 *
    *
  • {@link VendorService#deleteByCompany(Company)}
  • - *
  • {@link CompanyCustomerService#deleteByCompany(Company)}
  • + *
  • {@link CustomerService#deleteByCompany(Company)}
  • *
  • {@link CompanyOldNameService#deleteByCompany(Company)}
  • *
  • {@link CompanyContactService#deleteByCompany(Company)}
  • *
  • {@link ContractService#deleteByCompany(Company)}
  • @@ -276,7 +276,7 @@ public class CompanyService extends EntityService * 或者 把关联数据转移到其他公司 *
      *
    • {@link VendorService#resetTo(Company, Company)}
    • - *
    • {@link CompanyCustomerService#resetTo(Company, Company)}
    • + *
    • {@link CustomerService#resetTo(Company, Company)}
    • *
    • {@link CompanyOldNameService#resetTo(Company, Company)}
    • *
    • {@link CompanyContactService#resetTo(Company, Company)}
    • *
    • {@link ContractService#resetTo(Company, Company)}
    • diff --git a/server/src/main/java/com/ecep/contract/ds/contract/service/ContractService.java b/server/src/main/java/com/ecep/contract/ds/contract/service/ContractService.java index 189c54f..4bde7a1 100644 --- a/server/src/main/java/com/ecep/contract/ds/contract/service/ContractService.java +++ b/server/src/main/java/com/ecep/contract/ds/contract/service/ContractService.java @@ -42,6 +42,7 @@ import com.ecep.contract.ds.vendor.model.Vendor; import com.ecep.contract.service.VoableService; import com.ecep.contract.util.MyStringUtils; import com.ecep.contract.util.SpecificationUtils; +import com.ecep.contract.vo.CompanyVo; import com.ecep.contract.vo.ContractVo; import com.fasterxml.jackson.databind.JsonNode; @@ -119,6 +120,16 @@ public class ContractService extends EntityService findAllByCompany(CompanyVo company, ContractPayWay payWay, LocalDate beginDate, + LocalDate endDate) { + return contractRepository.findAll((root, query, cb) -> { + Predicate p = cb.and( + cb.equal(root.get("company").get("id"), company.getId()), + cb.equal(root.get("payWay"), payWay)); + return applyPredicate(root, cb, p, beginDate, endDate); + }, Sort.unsorted()); + } + public List findAllByProject(Project project) { return contractRepository.findAllByProjectId(project.getId()); } diff --git a/server/src/main/java/com/ecep/contract/ds/customer/model/CompanyCustomer.java b/server/src/main/java/com/ecep/contract/ds/customer/model/CompanyCustomer.java index 3351706..117dec7 100644 --- a/server/src/main/java/com/ecep/contract/ds/customer/model/CompanyCustomer.java +++ b/server/src/main/java/com/ecep/contract/ds/customer/model/CompanyCustomer.java @@ -13,7 +13,7 @@ import com.ecep.contract.model.Voable; import org.hibernate.annotations.ColumnDefault; import com.ecep.contract.util.HibernateProxyUtils; -import com.ecep.contract.vo.CompanyCustomerVo; +import com.ecep.contract.vo.CustomerVo; import jakarta.persistence.Column; import jakarta.persistence.Entity; @@ -34,7 +34,7 @@ import lombok.ToString; }) @ToString -public class CompanyCustomer implements IdentityEntity, CompanyBasedEntity, Voable { +public class CompanyCustomer implements IdentityEntity, CompanyBasedEntity, Voable { @Id @Column(name = "ID", nullable = false) private Integer id; @@ -105,8 +105,8 @@ public class CompanyCustomer implements IdentityEntity, CompanyBasedEntity, Voab } @Override - public CompanyCustomerVo toVo() { - CompanyCustomerVo vo = new CompanyCustomerVo(); + public CustomerVo toVo() { + CustomerVo vo = new CustomerVo(); vo.setId(id); vo.setCompanyId(company != null ? company.getId() : null); vo.setCatalogId(catalog != null ? catalog.getId() : null); diff --git a/server/src/main/java/com/ecep/contract/ds/customer/model/CompanyCustomerFile.java b/server/src/main/java/com/ecep/contract/ds/customer/model/CompanyCustomerFile.java index 66bce84..24fb9fe 100644 --- a/server/src/main/java/com/ecep/contract/ds/customer/model/CompanyCustomerFile.java +++ b/server/src/main/java/com/ecep/contract/ds/customer/model/CompanyCustomerFile.java @@ -7,7 +7,7 @@ import com.ecep.contract.CustomerFileType; import com.ecep.contract.model.CompanyBasicFile; import com.ecep.contract.model.Voable; import com.ecep.contract.util.HibernateProxyUtils; -import com.ecep.contract.vo.CompanyCustomerFileVo; +import com.ecep.contract.vo.CustomerFileVo; import jakarta.persistence.Column; import jakarta.persistence.Entity; @@ -29,7 +29,7 @@ import lombok.ToString; @Entity @Table(name = "COMPANY_CUSTOMER_FILE") @ToString -public class CompanyCustomerFile implements CompanyBasicFile, Voable { +public class CompanyCustomerFile implements CompanyBasicFile, Voable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "ID", nullable = false) @@ -81,8 +81,8 @@ public class CompanyCustomerFile implements CompanyBasicFile, } @Override - public CompanyCustomerFileVo toVo() { - CompanyCustomerFileVo vo = new CompanyCustomerFileVo(); + public CustomerFileVo toVo() { + CustomerFileVo vo = new CustomerFileVo(); vo.setId(getId()); vo.setCustomer(getCustomer() != null ? getCustomer().getId() : null); vo.setType(getType()); diff --git a/server/src/main/java/com/ecep/contract/ds/customer/model/SalesBillVoucher.java b/server/src/main/java/com/ecep/contract/ds/customer/model/SalesBillVoucher.java index 3ce4a03..273da0c 100644 --- a/server/src/main/java/com/ecep/contract/ds/customer/model/SalesBillVoucher.java +++ b/server/src/main/java/com/ecep/contract/ds/customer/model/SalesBillVoucher.java @@ -143,7 +143,6 @@ public class SalesBillVoucher implements IdentityEntity, BasedEntity, Voable, QueryService, - VoableService { + VoableService { private static final Logger logger = LoggerFactory.getLogger(CompanyCustomerFileService.class); @Lazy @Autowired @@ -183,7 +184,7 @@ public class CompanyCustomerFileService LocalDate miniContractDate = LocalDate.of(2022, 1, 1); // 检索全部合同 ContractService contractService = SpringApp.getBean(ContractService.class); - List contractList = contractService.findAllByCompanyCustomer(companyCustomer, null, null); + List contractList = contractService.findAllByCompanyCustomer(companyCustomer, miniContractDate, LocalDate.now()); if (contractList.isEmpty()) { holder.error("未发现已登记的合同"); return null; @@ -210,7 +211,7 @@ public class CompanyCustomerFileService LocalDate setupDate = firstContract.getSetupDate(); holder.info("依据合同 " + firstContract.getCode() + " 的日期 " + setupDate + " 推算"); - return CompanyBasicService.adjustToWorkDay(setupDate.plusDays(-7)); + return SpringApp.getBean(HolidayService.class).adjustToWorkDay(setupDate.plusDays(-7)); } // 检查失效日期起的第一个合同 @@ -233,7 +234,7 @@ public class CompanyCustomerFileService LocalDate setupDate = firstContract.getSetupDate(); holder.info("匹配失效期 " + nextInValidDate + " 后的第一个合同 " + firstContract.getCode()); holder.info("依据合同 " + firstContract.getCode() + " 的日期 " + setupDate + " 推算"); - return CompanyBasicService.adjustToWorkDay(setupDate.plusDays(-7)); + return SpringApp.getBean(HolidayService.class).adjustToWorkDay(setupDate.plusDays(-7)); } public File getEvaluationFormTemplate() { @@ -271,7 +272,7 @@ public class CompanyCustomerFileService } @Override - public void updateByVo(CompanyCustomerFile model, CompanyCustomerFileVo vo) { + public void updateByVo(CompanyCustomerFile model, CustomerFileVo vo) { if (model == null) { throw new ServiceException("companyCustomerFile is null"); } @@ -290,7 +291,7 @@ public class CompanyCustomerFileService if (vo.getCustomer() == null) { model.setCustomer(null); } else { - CompanyCustomerService service = SpringApp.getBean(CompanyCustomerService.class); + CustomerService service = SpringApp.getBean(CustomerService.class); // 添加实体匹配检查 if (model.getCustomer() == null || !model.getCustomer().getId().equals(vo.getCustomer())) { // 使用getById方法替代findById diff --git a/server/src/main/java/com/ecep/contract/ds/customer/service/CompanyCustomerService.java b/server/src/main/java/com/ecep/contract/ds/customer/service/CustomerService.java similarity index 97% rename from server/src/main/java/com/ecep/contract/ds/customer/service/CompanyCustomerService.java rename to server/src/main/java/com/ecep/contract/ds/customer/service/CustomerService.java index ac04bfd..21a0df3 100644 --- a/server/src/main/java/com/ecep/contract/ds/customer/service/CompanyCustomerService.java +++ b/server/src/main/java/com/ecep/contract/ds/customer/service/CustomerService.java @@ -48,7 +48,7 @@ import com.ecep.contract.util.CompanyUtils; import com.ecep.contract.util.FileUtils; import com.ecep.contract.util.MyStringUtils; import com.ecep.contract.util.SpecificationUtils; -import com.ecep.contract.vo.CompanyCustomerVo; +import com.ecep.contract.vo.CustomerVo; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; @@ -58,10 +58,10 @@ import jakarta.persistence.criteria.Path; @Lazy @Service @CacheConfig(cacheNames = "company-customer") -public class CompanyCustomerService extends CompanyBasicService - implements IEntityService, QueryService, - VoableService { - private static final Logger logger = LoggerFactory.getLogger(CompanyCustomerService.class); +public class CustomerService extends CompanyBasicService + implements IEntityService, QueryService, + VoableService { + private static final Logger logger = LoggerFactory.getLogger(CustomerService.class); @Lazy @Autowired @@ -86,7 +86,7 @@ public class CompanyCustomerService extends CompanyBasicService } @Cacheable(key = "#p0") - public CompanyCustomerVo findById(Integer id) { + public CustomerVo findById(Integer id) { return repository.findById(id).map(CompanyCustomer::toVo).orElse(null); } @@ -334,7 +334,7 @@ public class CompanyCustomerService extends CompanyBasicService } @Override - public Page findAll(JsonNode paramsNode, Pageable pageable) { + public Page findAll(JsonNode paramsNode, Pageable pageable) { Specification spec = null; if (paramsNode.has("searchText")) { spec = getSpecification(paramsNode.get("searchText").asText()); @@ -399,7 +399,7 @@ public class CompanyCustomerService extends CompanyBasicService } @Override - public void updateByVo(CompanyCustomer customer, CompanyCustomerVo vo) { + public void updateByVo(CompanyCustomer customer, CustomerVo vo) { // 优化关联实体处理逻辑 - 公司关联 if (vo.getCompanyId() == null) { customer.setCompany(null); diff --git a/server/src/main/java/com/ecep/contract/ds/vendor/repository/VendorFileRepository.java b/server/src/main/java/com/ecep/contract/ds/vendor/repository/VendorFileRepository.java index e3697f2..87617c3 100644 --- a/server/src/main/java/com/ecep/contract/ds/vendor/repository/VendorFileRepository.java +++ b/server/src/main/java/com/ecep/contract/ds/vendor/repository/VendorFileRepository.java @@ -18,5 +18,7 @@ public interface VendorFileRepository List findAllByVendorAndType(Vendor vendor, VendorFileType type); + List findAllByVendorIdAndType(Integer vendorId, VendorFileType type); + List findByVendorId(int vendorId); } \ No newline at end of file diff --git a/server/src/main/java/com/ecep/contract/ds/vendor/service/VendorFileService.java b/server/src/main/java/com/ecep/contract/ds/vendor/service/VendorFileService.java index ec264c8..8cf804b 100644 --- a/server/src/main/java/com/ecep/contract/ds/vendor/service/VendorFileService.java +++ b/server/src/main/java/com/ecep/contract/ds/vendor/service/VendorFileService.java @@ -4,7 +4,6 @@ import java.io.File; import java.time.LocalDate; import java.util.Comparator; import java.util.List; -import java.util.function.Consumer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -16,22 +15,28 @@ import org.springframework.data.domain.Sort; import org.springframework.data.jpa.domain.Specification; import org.springframework.stereotype.Service; +import com.ecep.contract.ContractPayWay; import com.ecep.contract.IEntityService; import com.ecep.contract.MessageHolder; import com.ecep.contract.MyDateTimeUtils; import com.ecep.contract.QueryService; import com.ecep.contract.SpringApp; import com.ecep.contract.VendorFileType; -import com.ecep.contract.ds.company.service.CompanyBasicService; -import com.ecep.contract.ds.contract.service.ContractService; -import com.ecep.contract.ds.vendor.repository.VendorFileRepository; +import com.ecep.contract.constant.CompanyVendorConstant; +import com.ecep.contract.ds.company.service.CompanyService; +import com.ecep.contract.ds.company.service.HolidayService; import com.ecep.contract.ds.contract.model.Contract; +import com.ecep.contract.ds.contract.service.ContractService; +import com.ecep.contract.ds.other.service.SysConfService; import com.ecep.contract.ds.vendor.model.Vendor; import com.ecep.contract.ds.vendor.model.VendorFile; +import com.ecep.contract.ds.vendor.repository.VendorFileRepository; import com.ecep.contract.service.ServiceException; import com.ecep.contract.service.VoableService; import com.ecep.contract.util.SpecificationUtils; +import com.ecep.contract.vo.CompanyVo; import com.ecep.contract.vo.VendorFileVo; +import com.ecep.contract.vo.VendorVo; import com.fasterxml.jackson.databind.JsonNode; @Lazy @@ -41,6 +46,15 @@ public class VendorFileService private static final Logger logger = LoggerFactory.getLogger(VendorFileService.class); + public File getEvaluationFormTemplate() { + SysConfService confService = SpringApp.getBean(SysConfService.class); + String path = confService.getString(CompanyVendorConstant.KEY_EVALUATION_FORM_TEMPLATE); + if (path == null) { + return null; + } + return new File(path); + } + @Autowired private VendorFileRepository repository; @@ -85,6 +99,10 @@ public class VendorFileService return repository.findAllByVendorId(vendor.getId()); } + public List findAllByVendor(VendorVo vendor) { + return repository.findAllByVendorId(vendor.getId()).stream().map(VendorFile::toVo).toList(); + } + public void delete(VendorFile file) { repository.delete(file); } @@ -109,6 +127,10 @@ public class VendorFileService return repository.findAllByVendorAndType(vendor, type); } + public List findAllByVendorAndType(VendorVo vendor, VendorFileType type) { + return repository.findAllByVendorIdAndType(vendor.getId(), type); + } + /** * 验证供应商文件 * @@ -158,14 +180,17 @@ public class VendorFileService * @param vendor 供应商 * @return 下一个评价日期 */ - public LocalDate getNextSignDate(Vendor vendor, Consumer state) { + public LocalDate getNextSignDate(VendorVo vendor, MessageHolder holder) { LocalDate miniContractDate = LocalDate.of(2022, 1, 1); // 检索全部合同 ContractService contractService = SpringApp.getBean(ContractService.class); - List contractList = contractService.findAllByCompanyVendor(vendor, null, null); + CompanyService companyService = SpringApp.getBean(CompanyService.class); + CompanyVo company = companyService.findById(vendor.getCompanyId()); + List contractList = contractService.findAllByCompany(company, ContractPayWay.PAY, miniContractDate, + LocalDate.now()); if (contractList.isEmpty()) { - state.accept("未发现已登记的合同"); + holder.error("未发现已登记的合同"); return null; } // 检索评价表 @@ -177,43 +202,43 @@ public class VendorFileService // 没有有效的评价表的评价日期 if (latestFile == null) { - state.accept("未发现有效的评价表"); + holder.warn("未发现有效的评价表"); // 返回最早的合同日期 Contract firstContract = contractList.stream() .filter(v -> v.getSetupDate() != null && !v.getSetupDate().isBefore(miniContractDate)) .min(Comparator.comparing(Contract::getSetupDate)) .orElse(null); if (firstContract == null) { - state.accept("最早的合同不存在?"); + holder.error("最早的合同不存在?"); return null; } LocalDate setupDate = firstContract.getSetupDate(); - state.accept("依据合同 " + firstContract.getCode() + " 的日期 " + setupDate + " 推算"); - return CompanyBasicService.adjustToWorkDay(setupDate.plusDays(-7)); + holder.info("依据合同 " + firstContract.getCode() + " 的日期 " + setupDate + " 推算"); + return SpringApp.getBean(HolidayService.class).adjustToWorkDay(setupDate.plusDays(-7)); } // 检查失效日期起的第一个合同 LocalDate nextInValidDate = latestFile.getSignDate().plusYears(1); File file = new File(latestFile.getFilePath()); - state.accept("依据 " + file.getName() + " 的失效期 " + nextInValidDate + " 检索合同"); + holder.info("依据 " + file.getName() + " 的失效期 " + nextInValidDate + " 检索合同"); List matchedContracts = contractList.stream() .filter(v -> v.getSetupDate().isAfter(nextInValidDate)).toList(); // 没有在失效日期后的合同时,使用失效日期 if (matchedContracts.isEmpty()) { - state.accept("未发现失效期 " + nextInValidDate + " 后的合同"); + holder.warn("未发现失效期 " + nextInValidDate + " 后的合同"); return null; } - state.accept("发现匹配合同 " + matchedContracts.size() + " 个"); + holder.info("发现匹配合同 " + matchedContracts.size() + " 个"); // 按时间取最早一个 Contract firstContract = matchedContracts.stream() .min(Comparator.comparing(Contract::getSetupDate)) .orElse(null); LocalDate setupDate = firstContract.getSetupDate(); - state.accept("匹配失效期 " + nextInValidDate + " 后的第一个合同 " + firstContract.getCode()); - state.accept("依据合同 " + firstContract.getCode() + " 的日期 " + setupDate + " 推算"); - return CompanyBasicService.adjustToWorkDay(setupDate.plusDays(-7)); + holder.info("匹配失效期 " + nextInValidDate + " 后的第一个合同 " + firstContract.getCode()); + holder.info("依据合同 " + firstContract.getCode() + " 的日期 " + setupDate + " 推算"); + return SpringApp.getBean(HolidayService.class).adjustToWorkDay(setupDate.plusDays(-7)); } @Override diff --git a/server/src/main/java/com/ecep/contract/ds/vendor/service/VendorService.java b/server/src/main/java/com/ecep/contract/ds/vendor/service/VendorService.java index 4b577bf..5cfe04f 100644 --- a/server/src/main/java/com/ecep/contract/ds/vendor/service/VendorService.java +++ b/server/src/main/java/com/ecep/contract/ds/vendor/service/VendorService.java @@ -255,7 +255,7 @@ public class VendorService extends CompanyBasicService List fileList, Consumer status) { boolean modified = super.fillFileAsEvaluationFile(customerFile, file, fileList, status); // 当评价表有日期,并且未设审核时 - boolean valid = isArchiveFile(customerFile.getFilePath()) && customerFile.getSignDate() != null; + boolean valid = FileUtils.isArchiveFile(customerFile.getFilePath()) && customerFile.getSignDate() != null; if (valid != customerFile.isValid()) { customerFile.setValid(valid); modified = true; @@ -263,7 +263,7 @@ public class VendorService extends CompanyBasicService return modified; } - protected boolean isEvaluationFile(String fileName) { + public boolean isEvaluationFile(String fileName) { return fileName.contains(CompanyVendorConstant.EVALUATION_FORM_NAME1) || fileName.contains(CompanyVendorConstant.EVALUATION_FORM_NAME2) || fileName.contains(CompanyVendorConstant.EVALUATION_FORM_NAME3); @@ -375,14 +375,6 @@ public class VendorService extends CompanyBasicService return modified; } - public File getEvaluationFormTemplate() { - String path = confService.getString(CompanyVendorConstant.KEY_EVALUATION_FORM_TEMPLATE); - if (path == null) { - return null; - } - return new File(path); - } - public File getVendorApprovedListTemplate() { String path = confService.getString(CompanyVendorConstant.KEY_APPROVED_LIST_TEMPLATE); if (path == null) { diff --git a/server/src/main/java/com/ecep/contract/ds/vendor/task/VendorReBuildFilesTasker.java b/server/src/main/java/com/ecep/contract/ds/vendor/task/VendorReBuildFilesTasker.java new file mode 100644 index 0000000..62f749d --- /dev/null +++ b/server/src/main/java/com/ecep/contract/ds/vendor/task/VendorReBuildFilesTasker.java @@ -0,0 +1,489 @@ +package com.ecep.contract.ds.vendor.task; + +import java.io.File; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.util.StringUtils; + +import com.ecep.contract.MessageHolder; +import com.ecep.contract.VendorFileType; +import com.ecep.contract.ds.company.CompanyFileUtils; +import com.ecep.contract.ds.company.service.CompanyService; +import com.ecep.contract.ds.vendor.model.VendorFile; +import com.ecep.contract.ds.vendor.service.VendorFileService; +import com.ecep.contract.ds.vendor.service.VendorService; +import com.ecep.contract.service.tasker.WebSocketServerTasker; +import com.ecep.contract.ui.Tasker; +import com.ecep.contract.util.FileUtils; +import com.ecep.contract.vo.CompanyVo; +import com.ecep.contract.vo.VendorFileVo; +import com.ecep.contract.vo.VendorVo; +import com.fasterxml.jackson.databind.JsonNode; + +/** + * 供应商文件重建任务 + * 1. 从供应商目录下递归遍历所有文件 + * 2. 检查数据库中是否存在该文件 + * 3. 如果不存在,则添加到数据库中 + * 4. 如果存在,则检查文件是否被修改 + * 5. 如果被修改,则更新数据库中的文件信息 + * 6. 如果文件不存在于供应商目录下,则从数据库中删除该文件 + */ +public class VendorReBuildFilesTasker extends Tasker implements WebSocketServerTasker { + private final Logger logger = LoggerFactory.getLogger(VendorReBuildFilesTasker.class); + private VendorService vendorService; + private VendorFileService vendorFileService; + private VendorVo vendor; + + @Override + public void init(JsonNode argsNode) { + int vendorId = argsNode.get(0).asInt(); + vendorService = getCachedBean(VendorService.class); + vendorFileService = getCachedBean(VendorFileService.class); + vendor = vendorService.findById(vendorId); + } + + @Override + protected Object execute(MessageHolder holder) throws Exception { + CompanyVo company = getCachedBean(CompanyService.class).findById(vendor.getCompanyId()); + + holder.info("开始重建供应商[" + company.getName() + "]的文件信息..."); + updateProgress(0, 100); + + holder.info("正在读取数据库中的文件记录..."); + List dbFiles = vendorFileService.findAllByVendor(vendor); + holder.info("共找到 " + dbFiles.size() + " 条数据库记录,正在进行数据清理..."); + + Map map = new HashMap<>(); + boolean modified = fetchDbFiles(dbFiles, map, holder); + updateProgress(30, 100); + + // 供应商目录下,准备用于移动到公司目录 + List needMoveToCompanyPath = new ArrayList<>(); + // 有修改和新导入的文件 + List retrieveFiles = new ArrayList<>(); + + holder.info("正在扫描供应商目录[" + vendor.getPath() + "]中的文件..."); + fetchFiles(vendor.getPath(), needMoveToCompanyPath, retrieveFiles, map, holder); + updateProgress(60, 100); + + // 移动文件到公司目录下 to company path + if (!needMoveToCompanyPath.isEmpty()) { + holder.info("发现 " + needMoveToCompanyPath.size() + " 个文件需要移动到公司目录,正在处理..."); + moveFileToCompany(needMoveToCompanyPath, holder); + holder.info("文件移动完成"); + } + + holder.info("导入 " + retrieveFiles.size() + " 个文件"); + if (!retrieveFiles.isEmpty()) { + holder.info("正在更新数据库记录..."); + int totalFiles = retrieveFiles.size(); + int processed = 0; + // update db + for (VendorFileVo v0 : retrieveFiles) { + v0.setVendorId(vendor.getId()); + save(v0); + processed++; + updateProgress(60 + (processed * 40) / totalFiles, 100); + } + modified = true; + holder.info("数据库更新完成"); + } + updateProperty("modified", modified); + + updateProgress(100, 100); + holder.info("文件重建任务完成"); + + return null; + + } + + protected void moveFileToCompany(List needMoveToCompanyPath, MessageHolder holder) { + CompanyService companyService = getCachedBean(CompanyService.class); + CompanyVo company = companyService.findById(vendor.getCompanyId()); + String companyPath = company.getPath(); + if (!StringUtils.hasText(companyPath)) { + holder.warn("公司路径未设置,无法移动文件"); + return; + } + + int movedCount = 0; + int totalCount = needMoveToCompanyPath.size(); + for (File file : needMoveToCompanyPath) { + File dest = new File(companyPath, file.getName()); + if (file.renameTo(dest)) { + holder.info("移动文件: " + file.getAbsolutePath() + " -> " + dest.getAbsolutePath()); + movedCount++; + } else { + if (dest.exists()) { + if (file.delete()) { + holder.info("删除重复文件: " + file.getAbsolutePath()); + } else { + holder.warn("无法删除重复文件: " + file.getAbsolutePath()); + } + } else { + holder.warn("无法移动文件: " + file.getAbsolutePath()); + } + } + } + holder.info("文件移动完成: 共 " + totalCount + " 个文件,成功移动 " + movedCount + " 个"); + } + + /** + * 从数据库中获取所有文件信息 + * + * @param dbFiles + * @param map + * @param holder + * @return + */ + protected boolean fetchDbFiles(List dbFiles, Map map, MessageHolder holder) { + boolean modified = false; + List editFiles = new ArrayList<>(); + int deletedCount = 0; + int updatedCount = 0; + int totalCount = dbFiles.size(); + + // 排除掉数据库中重复的 + for (int i = 0; i < dbFiles.size(); i++) { + VendorFileVo dbFile = dbFiles.get(i); + String filePath = dbFile.getFilePath(); + + // 更新进度 + if (i % 10 == 0 || i == totalCount - 1) { + updateProgress(10 + (i * 20) / totalCount, 100); + } + + // 没有文件信息,无效记录,删除 + if (!StringUtils.hasText(filePath)) { + deleteFile(dbFile); + deletedCount++; + continue; + } + + // 文件不存在或者隐藏文件,删除记录 + File file = new File(filePath); + if (!file.exists() || FileUtils.isHiddenFile(file)) { + deleteFile(dbFile); + deletedCount++; + continue; + } + + // old 是冲突的,按dbFiles顺序,旧的(list前面的) + VendorFileVo old = map.put(filePath, dbFile); + // 目录有重复删除 + if (old != null) { + deleteFile(old); + deletedCount++; + } + + String editFilePath = dbFile.getEditFilePath(); + if (!Objects.equals(filePath, editFilePath)) { + // 没有文件信息,无效记录,删除 + if (StringUtils.hasText(editFilePath)) { + File editFile = new File(editFilePath); + if (editFile.exists()) { + editFiles.add(editFile); + } else { + dbFile.setEditFilePath(""); + updatedCount++; + } + } + } + + // 类型未设置,补充类型 + if (dbFile.getType() == null) { + if (fillFileAsDefaultType(dbFile, file, holder)) { + modified = true; + updatedCount++; + } + } + } + + // 处理编辑文件 + int editDeletedCount = 0; + for (File editFile : editFiles) { + String editFilePath = editFile.getAbsolutePath(); + VendorFileVo dup = map.remove(editFilePath); + // 目录有重复删除 + if (dup != null) { + deleteFile(dup); + editDeletedCount++; + } + } + + holder.info("数据库清理完成: 删除 " + (deletedCount + editDeletedCount) + " 条无效记录,更新 " + updatedCount + " 条记录"); + + return modified; + } + + /** + * 遍历扫描 path 目录下的文件, 并根据文件类型,填充到 retrieveFiles 中 + * + * @param path + * @param needMoveToCompanyPath 符合 CompanyFileUtils.isCompanyFile(file) + * 规则的文件,会加到此集合中 + * @param retrieveFiles + * @param map + * @param status + * @param + * @param + */ + protected void fetchFiles( + String path, + List needMoveToCompanyPath, + List retrieveFiles, + Map map, + MessageHolder holder) { + if (!StringUtils.hasText(path)) { + return; + } + File dir = new File(path); + if (!dir.exists()) { + return; + } + File[] files = dir.listFiles(); + if (files == null) { + return; + } + List step1 = new ArrayList<>(); + for (File file : files) { + // 只处理文件 + if (!file.isFile() || FileUtils.isHiddenFile(file)) { + continue; + } + + if (CompanyFileUtils.isCompanyFile(file)) { + needMoveToCompanyPath.add(file); + continue; + } + // 先把所有文件加到列表中 + step1.add(file); + } + + if (!step1.isEmpty()) { + // 第一步,处理已经存在的 + for (File file : new ArrayList<>(step1)) { + String filePath = file.getAbsolutePath(); + if (map.containsKey(filePath)) { + // 已记录 + VendorFileVo customerFile = map.get(filePath); + if (fillFile(customerFile, file, step1, holder)) { + retrieveFiles.add(customerFile); + } + step1.remove(file); + } + } + + // 第二步骤,再处理 + while (!step1.isEmpty()) { + File file = step1.removeLast(); + VendorFileVo vendorFile = new VendorFileVo(); + vendorFile.setType(VendorFileType.General); + vendorFile.setFilePath(file.getAbsolutePath()); + fillFile(vendorFile, file, step1, holder); + if (vendorFile != null) { + retrieveFiles.add(vendorFile); + } + } + } + } + + protected boolean fillFile(VendorFileVo customerFile, File file, List fileList, + MessageHolder holder) { + String fileName = file.getName(); + boolean modified = CompanyFileUtils.fillApplyDateAbsent(file, customerFile, VendorFileVo::getSignDate, + VendorFileVo::setSignDate); + // 评估表 + if (getCachedBean(VendorService.class).isEvaluationFile(fileName)) { + if (fillFileAsEvaluationFile(customerFile, file, fileList, holder)) { + modified = true; + } + } else { + if (!Objects.equals(file.getAbsolutePath(), customerFile.getFilePath())) { + customerFile.setFilePath(file.getAbsolutePath()); + modified = true; + } + } + return modified; + } + + /** + * 以评价表单模板。填充文件信息 + * + * @param customerFile 文件对象 + * @param file 相关文件 + * @param fileList 待处理文件列表 + * @param status 状态输出 + * @param 类型类 + * @param 文件类 + * @return true:文件对象有修改,否则返回false + */ + protected boolean fillFileAsEvaluationFile(VendorFileVo customerFile, File file, + List fileList, MessageHolder holder) { + boolean modified = setFileTypeAsEvaluationForm(customerFile); + String fileName = file.getName(); + + // 文件全路径 + String fileAbsolutePath = file.getAbsolutePath(); + + if (FileUtils.isEditableFile(fileName)) { + // 是可编辑文件时 + if (!Objects.equals(fileAbsolutePath, customerFile.getEditFilePath())) { + customerFile.setEditFilePath(fileAbsolutePath); + modified = true; + } + + if (useAsEditableFile(customerFile, file, fileList, holder)) { + modified = true; + } + } else if (FileUtils.isArchiveFile(fileName)) { + // 存档文件时 + if (!Objects.equals(fileAbsolutePath, customerFile.getFilePath())) { + customerFile.setFilePath(fileAbsolutePath); + modified = true; + } + + if (useAsArchiveFile(customerFile, file, fileList, holder)) { + modified = true; + } + } else { + customerFile.setFilePath(file.getAbsolutePath()); + } + return modified; + } + + protected boolean setFileTypeAsEvaluationForm(VendorFileVo file) { + VendorFileType type = file.getType(); + if (type != VendorFileType.EvaluationForm) { + file.setType(VendorFileType.EvaluationForm); + return true; + } + return false; + } + + private boolean useAsEditableFile(VendorFileVo customerFile, File file, List fileList, + MessageHolder holder) { + if (fileList == null) { + return false; + } + + // 检查存档文件 + if (StringUtils.hasText(customerFile.getFilePath())) { + // 移除 存档文件 + File archiveFile = new File(customerFile.getFilePath()); + fileList.remove(archiveFile); + return false; + } + + // 未关联存档文件,去找 fileList 查 + if (fileList.isEmpty()) { + // 文件全路径 + String fileAbsolutePath = file.getAbsolutePath(); + // 当没有其他文件时,与 EditFile 相同 + if (!Objects.equals(fileAbsolutePath, customerFile.getFilePath())) { + customerFile.setFilePath(fileAbsolutePath); + return true; + } + return false; + } + + File archiveFile = null; + // 文件名 + String fileName = file.getName(); + // 文件名,不含后缀 + String name = StringUtils.stripFilenameExtension(fileName); + for (File f : fileList) { + // 查找存档文件 + if (f.getName().startsWith(name) && FileUtils.isArchiveFile(f.getName())) { + archiveFile = f; + break; + } + } + // 没有匹配到文件 + if (archiveFile == null) { + return false; + } + + if (fileList.remove(archiveFile)) { + customerFile.setFilePath(archiveFile.getAbsolutePath()); + return true; + } + + return false; + } + + private boolean useAsArchiveFile(VendorFileVo customerFile, File file, List fileList, + MessageHolder holder) { + if (fileList == null) { + return false; + } + + // 未关联存档文件,去找 fileList 查 + if (fileList.isEmpty()) { + return false; + } + + // 检查可编辑文件 + if (StringUtils.hasText(customerFile.getEditFilePath())) { + // 移除 可编辑文件 + File editFile = new File(customerFile.getEditFilePath()); + fileList.remove(editFile); + return false; + } + + File editFile = null; + // 文件名 + String fileName = file.getName(); + // 文件名,不含后缀 + String name = StringUtils.stripFilenameExtension(fileName); + for (File f : fileList) { + // 查找存档文件 + if (f.getName().startsWith(name) && FileUtils.isEditableFile(f.getName())) { + editFile = f; + break; + } + } + // 没有匹配到文件 + if (editFile == null) { + return false; + } + + if (fileList.remove(editFile)) { + String editFilePath = editFile.getAbsolutePath(); + if (!Objects.equals(editFilePath, customerFile.getEditFilePath())) { + customerFile.setEditFilePath(editFilePath); + return true; + } + } + + return false; + } + + protected boolean fillFileAsDefaultType(VendorFileVo dbFile, File file, + MessageHolder holder) { + dbFile.setType(VendorFileType.General); + fillFile(dbFile, file, null, holder); + save(dbFile); + return true; + } + + private void save(VendorFileVo dbFile) { + VendorFile v1 = vendorFileService.getById(dbFile.getId()); + vendorFileService.updateByVo(v1, dbFile); + vendorFileService.save(v1); + } + + private void deleteFile(VendorFileVo dbFile) { + VendorFile v1 = vendorFileService.getById(dbFile.getId()); + vendorFileService.delete(v1); + } + +} diff --git a/server/src/main/java/com/ecep/contract/service/tasker/CompanyCustomerEvaluationFormUpdateTask.java b/server/src/main/java/com/ecep/contract/service/tasker/CompanyCustomerEvaluationFormUpdateTask.java index 94aef31..10bbd3b 100644 --- a/server/src/main/java/com/ecep/contract/service/tasker/CompanyCustomerEvaluationFormUpdateTask.java +++ b/server/src/main/java/com/ecep/contract/service/tasker/CompanyCustomerEvaluationFormUpdateTask.java @@ -1,6 +1,7 @@ package com.ecep.contract.service.tasker; import static com.ecep.contract.util.ExcelUtils.setCellValue; +import static com.ecep.contract.util.ExcelUtils.getCellValue; import java.io.File; import java.io.FileInputStream; @@ -12,6 +13,7 @@ import java.io.OutputStream; import java.time.LocalDate; import java.util.Comparator; import java.util.List; +import java.util.Objects; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; @@ -26,7 +28,7 @@ import com.ecep.contract.SpringApp; import com.ecep.contract.cloud.tyc.CloudTycService; import com.ecep.contract.ds.customer.service.CompanyCustomerEvaluationFormFileService; import com.ecep.contract.ds.customer.service.CompanyCustomerFileService; -import com.ecep.contract.ds.customer.service.CompanyCustomerService; +import com.ecep.contract.ds.customer.service.CustomerService; import com.ecep.contract.ds.other.model.CloudTyc; import com.ecep.contract.ds.company.model.Company; import com.ecep.contract.ds.customer.model.CompanyCustomer; @@ -34,6 +36,7 @@ import com.ecep.contract.ds.customer.model.CompanyCustomerEvaluationFormFile; import com.ecep.contract.ds.customer.model.CompanyCustomerFile; import com.ecep.contract.ui.Tasker; import com.ecep.contract.util.CompanyUtils; +import com.ecep.contract.util.ExcelUtils; import com.fasterxml.jackson.databind.JsonNode; public class CompanyCustomerEvaluationFormUpdateTask extends Tasker implements WebSocketServerTasker { @@ -42,7 +45,7 @@ public class CompanyCustomerEvaluationFormUpdateTask extends Tasker impl @Override public void init(JsonNode argsNode) { int customerId = argsNode.get(0).asInt(); - customer = getCachedBean(CompanyCustomerService.class).getById(customerId); + customer = getCachedBean(CustomerService.class).getById(customerId); } CompanyCustomerFileService getCompanyCustomerFileService() { @@ -131,36 +134,100 @@ public class CompanyCustomerEvaluationFormUpdateTask extends Tasker impl } private void updateSheet(Company company, Sheet sheet, MessageHolder holder) { - setCellValue(sheet, "B3", "客户编号:" + CompanyUtils.formatCompanyVendorId(customer.getId())); - setCellValue(sheet, "B4", "客户名称:" + company.getName()); + String customerId = "客户编号:" + CompanyUtils.formatCompanyVendorId(customer.getId()); + String currentCustomerId = ExcelUtils.getCellValue(sheet, "B3"); + if (!Objects.equals(customerId, currentCustomerId)) { + setCellValue(sheet, "B3", customerId); + holder.info("更新客户编号为:" + CompanyUtils.formatCompanyVendorId(customer.getId())); + } + + String customerName = "客户名称:" + company.getName(); + String currentCustomerName = ExcelUtils.getCellValue(sheet, "B4"); + if (!Objects.equals(customerName, currentCustomerName)) { + setCellValue(sheet, "B4", customerName); + holder.info("更新客户名称为:" + company.getName()); + } LocalDate suggestDate = getCompanyCustomerFileService().getNextSignDate(customer, holder); if (suggestDate == null) { suggestDate = LocalDate.now(); + holder.debug("未获取到推荐评定日期,使用当前日期:" + suggestDate); + } else { + holder.debug("获取到推荐评定日期:" + suggestDate); } - setCellValue(sheet, "H3", "评定时间:" + suggestDate); + String evalDate = "评定时间:" + suggestDate; + String currentEvalDate = ExcelUtils.getCellValue(sheet, "H3"); + if (!Objects.equals(evalDate, currentEvalDate)) { + setCellValue(sheet, "H3", evalDate); + holder.info("更新评定时间为:" + suggestDate); + } + setCellValue(sheet, "H4", "统一社会信用代码:"); - setCellValue(sheet, "H5", company.getUniscid()); + + if (!Objects.equals(company.getUniscid(), ExcelUtils.getCellValue(sheet, "H5"))) { + setCellValue(sheet, "H5", company.getUniscid()); + holder.info("更新统一社会信用代码为:" + company.getUniscid()); + } + // 注册所属地 - setCellValue(sheet, "B5", "注册所属地:" + company.getDistrict()); + String district = "注册所属地:" + company.getDistrict(); + if (!Objects.equals(district, ExcelUtils.getCellValue(sheet, "B5"))) { + setCellValue(sheet, "B5", district); + holder.info("更新注册所属地为:" + company.getDistrict()); + } + // 经营状态 - setCellValue(sheet, "D6", "经营状态:" + company.getEntStatus()); + String entStatus = "经营状态:" + company.getEntStatus(); + if (!Objects.equals(entStatus, ExcelUtils.getCellValue(sheet, "D6"))) { + setCellValue(sheet, "D6", entStatus); + holder.info("更新经营状态为:" + company.getEntStatus()); + } + // 成立日期 - setCellValue(sheet, "H6", "成立日期:" + company.getSetupDate()); + String setupDate = "成立日期:" + company.getSetupDate(); + if (!Objects.equals(setupDate, ExcelUtils.getCellValue(sheet, "H6"))) { + setCellValue(sheet, "H6", setupDate); + holder.info("更新成立日期为:" + company.getSetupDate()); + } + // 所属行业 - setCellValue(sheet, "D7", "所属行业:" + company.getIndustry()); - setCellValue(sheet, "D8", - "注册资金:" + company.getRegisteredCapital() + " " + company.getRegisteredCapitalCurrency()); + String industry = "所属行业:" + company.getIndustry(); + if (!Objects.equals(industry, ExcelUtils.getCellValue(sheet, "D7"))) { + setCellValue(sheet, "D7", industry); + holder.info("更新所属行业为:" + company.getIndustry()); + } + + String registeredCapital = "注册资金:" + company.getRegisteredCapital() + " " + company.getRegisteredCapitalCurrency(); + if (!Objects.equals(registeredCapital, ExcelUtils.getCellValue(sheet, "D8"))) { + setCellValue(sheet, "D8", registeredCapital); + holder.info("更新注册资金为:" + registeredCapital); + } + // 企业类型 - setCellValue(sheet, "H10", "企业类型:" + company.getEntType()); + String entType = "企业类型:" + company.getEntType(); + if (!Objects.equals(entType, ExcelUtils.getCellValue(sheet, "H10"))) { + setCellValue(sheet, "H10", entType); + holder.info("更新企业类型为:" + company.getEntType()); + } + // 天眼评分 CloudTycService cloudTycService = SpringApp.getBean(CloudTycService.class); CloudTyc cloudTyc = cloudTycService.getOrCreateCloudTyc(company); - setCellValue(sheet, "D10", "天眼评分:" + (cloudTyc.getScore() > 0 ? cloudTyc.getScore() : "")); + String tycScore = "天眼评分:" + (cloudTyc.getScore() > 0 ? cloudTyc.getScore() : ""); + if (!Objects.equals(tycScore, ExcelUtils.getCellValue(sheet, "D10"))) { + setCellValue(sheet, "D10", tycScore); + if (cloudTyc.getScore() > 0) { + holder.info("更新天眼评分为:" + cloudTyc.getScore()); + } else { + holder.debug("天眼评分未设置或为0"); + } + } // 检索评估表 + holder.debug("开始检索客户评价表文件"); List customerFiles = getCompanyCustomerFileService().findAllByCustomerAndType(customer, CustomerFileType.EvaluationForm); + holder.debug("共检索到 " + customerFiles.size() + " 个客户评价表文件"); List filteredList = customerFiles.stream().filter(file -> { return file.getSignDate() != null && file.isValid(); @@ -168,29 +235,45 @@ public class CompanyCustomerEvaluationFormUpdateTask extends Tasker impl .sorted(Comparator.comparing(CompanyCustomerFile::getSignDate)) .map(getCompanyCustomerEvaluationFormFileService()::findByCustomerFile) .toList(); + holder.debug("有效评价表数量:" + filteredList.size()); if (filteredList.isEmpty()) { - setCellValue(sheet, "C40", "首次评价"); + if (!Objects.equals("首次评价", ExcelUtils.getCellValue(sheet, "C40"))) { + setCellValue(sheet, "C40", "首次评价"); + holder.info("设置客户为首次评价状态"); + } try { sheet.addMergedRegion(CellRangeAddress.valueOf("C40:K40")); } catch (Exception ignored) { + holder.debug("合并单元格C40:K40失败,可能已合并"); } } else { - holder.info("客户有 " + filteredList.size() + " 条评价表"); - setCellValue(sheet, "C40", "评价日期"); - try { - sheet.addMergedRegion(CellRangeAddress.valueOf("C40:D40")); - } catch (Exception ignored) { + holder.info("客户有 " + filteredList.size() + " 条有效评价表记录"); + if (!Objects.equals("评价日期", ExcelUtils.getCellValue(sheet, "C40"))) { + setCellValue(sheet, "C40", "评价日期"); + try { + sheet.addMergedRegion(CellRangeAddress.valueOf("C40:D40")); + } catch (Exception ignored) { + holder.debug("合并单元格C40:D40失败,可能已合并"); + } + } + if (!Objects.equals("经济指标", ExcelUtils.getCellValue(sheet, "E40"))) { + setCellValue(sheet, "E40", "经济指标"); + } + if (!Objects.equals("综合指标", ExcelUtils.getCellValue(sheet, "F40"))) { + setCellValue(sheet, "F40", "综合指标"); + } + if (!Objects.equals("资信等级", ExcelUtils.getCellValue(sheet, "G40"))) { + setCellValue(sheet, "G40", "资信等级"); } - setCellValue(sheet, "E40", "经济指标"); - setCellValue(sheet, "F40", "综合指标"); - setCellValue(sheet, "G40", "资信等级"); String[] CreditLevelTitles = new String[] { "-", "差★", " 一般★★", " 较好★★★", " 好★★★★", " " }; int baseRow = 40; for (CompanyCustomerEvaluationFormFile form : filteredList) { + baseRow++; CompanyCustomerFile customerFile = form.getCustomerFile(); if (!Hibernate.isInitialized(customerFile)) { customerFile = getCompanyCustomerFileService().findById(customerFile.getId()); + holder.debug("延迟加载评价表文件信息,文件ID:" + customerFile.getId()); } setCellValue(sheet, baseRow, 2, String.valueOf(customerFile.getSignDate())); setCellValue(sheet, baseRow, 4, form.getCatalog()); @@ -203,9 +286,10 @@ public class CompanyCustomerEvaluationFormUpdateTask extends Tasker impl try { sheet.addMergedRegion(new CellRangeAddress(baseRow, baseRow, 2, 3)); } catch (Exception ignored) { + holder.debug("合并单元格第" + baseRow + "行的2-3列失败,可能已合并"); } - baseRow++; } + holder.info("已成功更新所有评价表记录到Excel中"); } } } diff --git a/server/src/main/java/com/ecep/contract/service/tasker/CompanyCustomerNextSignDateTask.java b/server/src/main/java/com/ecep/contract/service/tasker/CompanyCustomerNextSignDateTask.java index d3f17d1..cad7846 100644 --- a/server/src/main/java/com/ecep/contract/service/tasker/CompanyCustomerNextSignDateTask.java +++ b/server/src/main/java/com/ecep/contract/service/tasker/CompanyCustomerNextSignDateTask.java @@ -8,7 +8,7 @@ import com.ecep.contract.CustomerFileType; import com.ecep.contract.MessageHolder; import com.ecep.contract.ds.contract.service.ContractService; import com.ecep.contract.ds.customer.service.CompanyCustomerFileService; -import com.ecep.contract.ds.customer.service.CompanyCustomerService; +import com.ecep.contract.ds.customer.service.CustomerService; import com.ecep.contract.ds.customer.model.CompanyCustomer; import com.ecep.contract.ds.customer.model.CompanyCustomerFile; import com.ecep.contract.ds.contract.model.Contract; @@ -22,15 +22,15 @@ public class CompanyCustomerNextSignDateTask extends Tasker implements W @Override public void init(JsonNode argsNode) { int customerId = argsNode.get(0).asInt(); - customer = getCachedBean(CompanyCustomerService.class).getById(customerId); + customer = getCachedBean(CustomerService.class).getById(customerId); } CompanyCustomerFileService getCompanyCustomerFileService() { return getCachedBean(CompanyCustomerFileService.class); } - CompanyCustomerService getCompanyCustomerService() { - return getCachedBean(CompanyCustomerService.class); + CustomerService getCompanyCustomerService() { + return getCachedBean(CustomerService.class); } ContractService getContractService() { diff --git a/server/src/main/java/com/ecep/contract/service/tasker/CompanyCustomerRebuildFilesTasker.java b/server/src/main/java/com/ecep/contract/service/tasker/CompanyCustomerRebuildFilesTasker.java index 47759f9..a03291c 100644 --- a/server/src/main/java/com/ecep/contract/service/tasker/CompanyCustomerRebuildFilesTasker.java +++ b/server/src/main/java/com/ecep/contract/service/tasker/CompanyCustomerRebuildFilesTasker.java @@ -5,7 +5,7 @@ import org.springframework.util.StringUtils; import com.ecep.contract.MessageHolder; import com.ecep.contract.ds.company.service.CompanyService; -import com.ecep.contract.ds.customer.service.CompanyCustomerService; +import com.ecep.contract.ds.customer.service.CustomerService; import com.ecep.contract.ds.company.model.Company; import com.ecep.contract.ds.customer.model.CompanyCustomer; import com.ecep.contract.ui.Tasker; @@ -19,8 +19,8 @@ public class CompanyCustomerRebuildFilesTasker extends Tasker implements private CompanyCustomer customer; - CompanyCustomerService getCompanyCustomerService() { - return getCachedBean(CompanyCustomerService.class); + CustomerService getCompanyCustomerService() { + return getCachedBean(CustomerService.class); } @Override diff --git a/server/src/main/java/com/ecep/contract/service/tasker/CompanyRkUpdateTasker.java b/server/src/main/java/com/ecep/contract/service/tasker/CompanyRkUpdateTasker.java index c708592..912c346 100644 --- a/server/src/main/java/com/ecep/contract/service/tasker/CompanyRkUpdateTasker.java +++ b/server/src/main/java/com/ecep/contract/service/tasker/CompanyRkUpdateTasker.java @@ -1,6 +1,7 @@ package com.ecep.contract.service.tasker; import com.ecep.contract.MessageHolder; +import com.ecep.contract.MyDateTimeUtils; import com.ecep.contract.cloud.rk.CloudRkService; import com.ecep.contract.cloud.rk.ctx.CloudRkCtx; import com.ecep.contract.constant.CloudServiceConstant; @@ -34,16 +35,18 @@ public class CompanyRkUpdateTasker extends Tasker implements WebSocketSe @Override protected Object execute(MessageHolder holder) throws Exception { - holder.debug("1. 从 " + CloudServiceConstant.RK_NAME + " 更新..."); try { cloudRkService = getCachedBean(CloudRkService.class); } catch (BeansException e) { - throw new RuntimeException("服务未启用"); + throw new RuntimeException("服务未启用,请联系管理员"); } CloudRk cloudRk = cloudRkService.getOrCreateCloudRk(company); if (cloudRk == null) { throw new RuntimeException("无法创建或获取 CloudRk 对象"); } + if (cloudRk.getLatestUpdate() != null) { + holder.info("上次更新:" + MyDateTimeUtils.format(cloudRk.getLatestUpdate())); + } try { CloudRkCtx cloudRkCtx = new CloudRkCtx(); diff --git a/server/src/main/java/com/ecep/contract/service/tasker/CompanyVendorEvaluationFormUpdateTask.java b/server/src/main/java/com/ecep/contract/service/tasker/CompanyVendorEvaluationFormUpdateTask.java new file mode 100644 index 0000000..91fed4d --- /dev/null +++ b/server/src/main/java/com/ecep/contract/service/tasker/CompanyVendorEvaluationFormUpdateTask.java @@ -0,0 +1,282 @@ +package com.ecep.contract.service.tasker; + +import com.ecep.contract.MessageHolder; +import com.ecep.contract.VendorFileType; +import com.ecep.contract.ds.company.service.CompanyContactService; +import com.ecep.contract.ds.company.service.CompanyService; +import com.ecep.contract.ds.vendor.model.Vendor; +import com.ecep.contract.ds.vendor.model.VendorFile; +import com.ecep.contract.ds.vendor.service.VendorFileService; +import com.ecep.contract.ds.vendor.service.VendorService; +import com.ecep.contract.ui.Tasker; +import com.ecep.contract.util.ExcelUtils; +import com.ecep.contract.vo.CompanyContactVo; +import com.ecep.contract.vo.CompanyVo; +import com.ecep.contract.vo.VendorVo; +import com.fasterxml.jackson.databind.JsonNode; +import org.apache.poi.ss.usermodel.*; +import org.springframework.stereotype.Component; +import org.springframework.util.StringUtils; + +import java.io.*; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.Objects; + +import static com.ecep.contract.util.ExcelUtils.getCellValue; +import static com.ecep.contract.util.ExcelUtils.setCellValue; + +/** + * 更新供应商评价表 + */ +@Component +public class CompanyVendorEvaluationFormUpdateTask extends Tasker implements WebSocketServerTasker { + private VendorVo vendor; + private CompanyVo company; + private File template; + + @Override + public void init(JsonNode argsNode) { + int vendorId = argsNode.get(0).asInt(); + vendor = getVendorService().findById(vendorId); + } + + private VendorService getVendorService() { + return getCachedBean(VendorService.class); + } + + VendorFileService getVendorFileService() { + return getCachedBean(VendorFileService.class); + } + + @Override + protected Object execute(MessageHolder holder) throws Exception { + if (vendor == null) { + holder.error("未找到供应商信息"); + return null; + } + if (!StringUtils.hasText(vendor.getPath())) { + holder.error("供应商目录未设置,请先设置供应商目录"); + return null; + } + updateEvaluationForm(holder); + return null; + } + + public void updateEvaluationForm(MessageHolder holder) { + company = getCachedBean(CompanyService.class).findById(vendor.getCompanyId()); + + template = getVendorFileService().getEvaluationFormTemplate(); + if (template == null) { + holder.error("评价表模板文件未设置,请先设置评价表模板文件"); + return; + } + if (!template.exists()) { + holder.error("评价表模板文件 " + template.getAbsolutePath() + " 不存在,请检查"); + return; + } + + updateProgress(1, 10); + File dir = new File(vendor.getPath()); + String template_file_name = template.getName(); + File destFile = new File(dir, template_file_name); + + if (destFile.exists()) { + holder.info("表单文件已经存在," + destFile.getName()); + try ( + InputStream inp = new FileInputStream(destFile); + Workbook wb = WorkbookFactory.create(inp)) { + updateEvaluationForm(wb, destFile, holder); + holder.info("评价表已更新"); + } catch (Exception e) { + holder.error(e.getMessage()); + } + } else { + holder.info("根据模板 " + template_file_name + " 创建表单 " + destFile.getName()); + try ( + InputStream inp = new FileInputStream(template); + Workbook wb = WorkbookFactory.create(inp)) { + updateEvaluationForm(wb, destFile, holder); + holder.info("评价表已创建"); + // 创建 VendorFile 对象 + VendorFile vendorFile = new VendorFile(); + Vendor vendorEntity = getCachedBean(VendorService.class).getById(vendor.getId()); + vendorFile.setVendor(vendorEntity); + vendorFile.setFilePath(destFile.getAbsolutePath()); + vendorFile.setType(VendorFileType.EvaluationForm); + vendorFile.setSignDate(LocalDate.now()); + vendorFile.setValid(false); + getVendorFileService().save(vendorFile); + } catch (Exception e) { + holder.error(e.getMessage()); + } + } + updateProgress(10, 10); + } + + /** + * 更新供应商评估表,依据模板创建,如果已经存在生成的文件,则更新评估表 + * + * @param wb work book + * @param destFile 目标文件 + */ + public void updateEvaluationForm(Workbook wb, File destFile, MessageHolder holder) throws IOException { + updateProgress(2, 10); + Sheet sheet = wb.getSheetAt(0); + holder.info("更新 " + sheet.getSheetName() + " Sheet"); + updateSheet(sheet, holder.sub(" - ")); + updateProgress(8, 10); + // 输出到文件 + try (OutputStream fileOut = new FileOutputStream(destFile)) { + wb.write(fileOut); + } catch (FileNotFoundException e) { + holder.error("写评估表时发生文件错误,请检查评估表是否被打开中:" + e.getMessage()); + } + } + + private void updateSheet(Sheet sheet, MessageHolder holder) { + String vendor_id = "" + vendor.getId(); + if (!Objects.equals(vendor_id, getCellValue(sheet, "G1"))) { + setCellValue(sheet, "G1", vendor_id); + holder.info("供应商编号更新为:" + vendor_id); + } + + String companyName = company.getName(); + if (!Objects.equals(companyName, getCellValue(sheet, "B2"))) { + setCellValue(sheet, "B2", companyName); + holder.info("供应商名称更新为:" + companyName); + } + + String address = null; + // 联系人 + CompanyContactVo contact = null; + if (vendor.getContactId() != null) { + contact = getCompanyContactService().findById(vendor.getContactId()); + if (contact != null) { + holder.debug("供应商指定联系人:" + contact.getName()); + } + } + if (contact == null) { + contact = getCompanyContactService().findFirstByCompany(company); + if (contact != null) { + holder.debug("从公司联系人列表中获取联系人:" + contact.getName()); + } + } + if (contact != null) { + String contactName = contact.getName(); + if (!Objects.equals(contactName, getCellValue(sheet, "F2"))) { + setCellValue(sheet, "F2", contactName); + holder.info("联系人姓名更新为:" + contactName); + } + String contactPhone = contact.getPhone(); + if (StringUtils.hasText(contactPhone)) { + if (!Objects.equals(contactPhone, getCellValue(sheet, "F3"))) { + setCellValue(sheet, "F3", contactPhone); + holder.info("联系人电话更新为:" + contactPhone); + } + } + + if (StringUtils.hasText(contact.getAddress())) { + address = contact.getAddress(); + } + } + + if (!StringUtils.hasText(address)) { + address = company.getAddress(); + if (StringUtils.hasText(address)) { + holder.debug("使用公司地址:" + address); + } + } + if (!StringUtils.hasText(address)) { + address = company.getRegAddr(); + if (StringUtils.hasText(address)) { + holder.debug("使用公司注册地址:" + address); + } + } + + if (StringUtils.hasText(address)) { + if (!Objects.equals(address, getCellValue(sheet, "B3"))) { + setCellValue(sheet, "B3", address); + holder.info("更新供应商地址为:" + address); + } + } else { + holder.warn("没有获取到供应商地址,请检查供应商信息"); + } + + + String companyUniscid = company.getUniscid(); + if (!Objects.equals(companyUniscid, getCellValue(sheet, "B8"))) { + setCellValue(sheet, "B8", companyUniscid); + holder.info("更新供应商统一社会信用代码为:" + companyUniscid); + } + + String regCap = company.getRegisteredCapital() + " " + company.getRegisteredCapitalCurrency(); + if (!Objects.equals(regCap, getCellValue(sheet, "E8"))) { + setCellValue(sheet, "E8", regCap); + holder.info("更新供应商注册资金为:" + regCap); + } + + setCellValue(sheet, "H8", company.getOperationPeriodBegin()); + if (company.getOperationPeriodEnd() == null) { + if (company.getOperationPeriodBegin() != null) { + setCellValue(sheet, "H9", "无固定期限"); + } + } else { + setCellValue(sheet, "H9", company.getOperationPeriodEnd()); + } + + String vendorPurchase = vendor.getPurchase(); + if (!Objects.equals(vendorPurchase, getCellValue(sheet, "C4"))) { + setCellValue(sheet, "C4", vendorPurchase); + holder.info("更新供应商采购内容为:" + vendorPurchase); + } + + Cell a6 = ExcelUtils.getCell(sheet, "A6"); + if (a6 != null) { + if (!Objects.equals(a6.getStringCellValue(), vendor.getDescription())) { + a6.setCellValue(vendor.getDescription()); + holder.info("更新供应商描述为:" + StringUtils.truncate(a6.getStringCellValue(), 30)); + } + if (a6.getCellStyle().getAlignment() != HorizontalAlignment.LEFT) { + a6.getCellStyle().setAlignment(HorizontalAlignment.LEFT); + holder.info("更新供应商描述对齐方式为左对齐"); + } + } + + // 第一个评价日期 + Cell g16 = ExcelUtils.getCell(sheet, "G16"); + if (g16 == null) { + holder.error("模板异常, 第一个评价日期单元格(G16)未找到!"); + } else { + CellType cellType = g16.getCellType(); + // 未设置, 尝试更新 + if (cellType == CellType.BLANK || cellType == CellType.NUMERIC) { + holder.debug("推算下一个评价日期..."); + LocalDate nextSignDate = getVendorFileService().getNextSignDate(vendor, holder.sub(" -| ")); + // 当没有推荐日期时,说明不需要评价,更新为空 + if (nextSignDate == null) { + g16.setBlank(); + holder.info("!未推算出下一个评价日期,单元格设空!"); + } else { + holder.debug("推算出下一个评价日期:" + nextSignDate); + LocalDateTime value = g16.getLocalDateTimeCellValue(); + if (value == null) { + g16.setCellValue(nextSignDate); + holder.info("评价日期更新为:" + nextSignDate); + } else { + if (!Objects.equals(value.toLocalDate(), nextSignDate)) { + g16.setCellValue(nextSignDate); + holder.info("评价日期更新为:" + nextSignDate); + } + } + } + } else { + holder.warn("第一个评价日期所在单元格 " + g16.getAddress().formatAsR1C1String() + " 的单元格类型未知:" + cellType); + } + } + } + + private CompanyContactService getCompanyContactService() { + return getCachedBean(CompanyContactService.class); + } +} diff --git a/server/src/main/java/com/ecep/contract/service/tasker/CustomerFileMoveTasker.java b/server/src/main/java/com/ecep/contract/service/tasker/CustomerFileMoveTasker.java index 4e0a687..9e309e9 100644 --- a/server/src/main/java/com/ecep/contract/service/tasker/CustomerFileMoveTasker.java +++ b/server/src/main/java/com/ecep/contract/service/tasker/CustomerFileMoveTasker.java @@ -2,7 +2,7 @@ package com.ecep.contract.service.tasker; import com.ecep.contract.MessageHolder; import com.ecep.contract.ds.customer.service.CompanyCustomerFileService; -import com.ecep.contract.ds.customer.service.CompanyCustomerService; +import com.ecep.contract.ds.customer.service.CustomerService; import com.ecep.contract.ds.company.model.Company; import com.ecep.contract.ds.customer.model.CompanyCustomer; import com.ecep.contract.ds.customer.model.CompanyCustomerFile; @@ -104,7 +104,7 @@ public class CustomerFileMoveTasker extends Tasker implements WebSocketS return getCachedBean(CompanyCustomerFileService.class); } - private CompanyCustomerService getCompanyCustomerService() { - return getCachedBean(CompanyCustomerService.class); + private CustomerService getCompanyCustomerService() { + return getCachedBean(CustomerService.class); } } \ No newline at end of file diff --git a/server/src/main/java/com/ecep/contract/service/tasker/VendorNextSignDateTask.java b/server/src/main/java/com/ecep/contract/service/tasker/VendorNextSignDateTask.java new file mode 100644 index 0000000..d713f35 --- /dev/null +++ b/server/src/main/java/com/ecep/contract/service/tasker/VendorNextSignDateTask.java @@ -0,0 +1,121 @@ +package com.ecep.contract.service.tasker; + +import java.time.LocalDate; +import java.util.Comparator; +import java.util.List; + +import com.ecep.contract.MessageHolder; +import com.ecep.contract.VendorFileType; +import com.ecep.contract.ds.contract.model.Contract; +import com.ecep.contract.ds.contract.service.ContractService; +import com.ecep.contract.ds.vendor.model.Vendor; +import com.ecep.contract.ds.vendor.model.VendorFile; +import com.ecep.contract.ds.vendor.service.VendorFileService; +import com.ecep.contract.ds.vendor.service.VendorService; +import com.ecep.contract.ui.Tasker; +import com.fasterxml.jackson.databind.JsonNode; + +public class VendorNextSignDateTask extends Tasker implements WebSocketServerTasker { + + private Vendor vendor; + + @Override + public void init(JsonNode argsNode) { + int vendorId = argsNode.get(0).asInt(); + vendor = getCachedBean(VendorService.class).getById(vendorId); + } + + VendorFileService getVendorFileService() { + return getCachedBean(VendorFileService.class); + } + + VendorService getVendorService() { + return getCachedBean(VendorService.class); + } + + ContractService getContractService() { + return getCachedBean(ContractService.class); + } + + @Override + protected Object execute(MessageHolder holder) throws Exception { + if (vendor == null) { + holder.error("未找到供应商信息"); + return null; + } + + holder.info("开始计算供应商下一个评价日期"); + + LocalDate nextSignDate = calculateNextSignDate(holder); + + if (nextSignDate != null) { + holder.info("下一个评价日期:" + nextSignDate); + } else { + holder.warn("无法计算下一个评价日期"); + } + + return nextSignDate; + } + + private LocalDate calculateNextSignDate(MessageHolder holder) { + LocalDate miniContractDate = LocalDate.of(2022, 1, 1); + + // 检索全部合同 + ContractService contractService = getContractService(); + List contractList = contractService.findAllByCompanyVendor(vendor, null, null); + if (contractList.isEmpty()) { + holder.error("未发现已登记的合同"); + return null; + } + + holder.info("发现" + contractList.size() + "份合同"); + + // 检索评价表 + List files = getVendorFileService().findAllByVendorAndType(vendor, + VendorFileType.EvaluationForm); + VendorFile latestFile = files.stream() + .filter(v -> v.getSignDate() != null && v.isValid()) + .max(Comparator.comparing(VendorFile::getSignDate)) + .orElse(null); + + // 没有有效的评价表的评价日期 + if (latestFile == null) { + holder.warn("未发现有效的评价表"); + // 返回最早的合同日期 + Contract firstContract = contractList.stream() + .filter(v -> v.getSetupDate() != null && !v.getSetupDate().isBefore(miniContractDate)) + .min(Comparator.comparing(Contract::getSetupDate)) + .orElse(null); + + if (firstContract == null) { + holder.error("最早的合同不存在"); + return null; + } + + LocalDate setupDate = firstContract.getSetupDate(); + holder.info("选择最早的合同:" + firstContract.getCode() + ",日期:" + setupDate); + return setupDate.plusDays(-7); + } + + // 有有效的评价表,计算下一个日期 + LocalDate lastSignDate = latestFile.getSignDate(); + holder.info("最近一次有效的评价表日期:" + lastSignDate); + + // 查找最近一次评价日期之后的合同 + Contract firstContractAfter = contractList.stream() + .filter(v -> v.getSetupDate() != null && v.getSetupDate().isAfter(lastSignDate)) + .min(Comparator.comparing(Contract::getSetupDate)) + .orElse(null); + + if (firstContractAfter == null) { + holder.warn("没有找到在" + lastSignDate + "之后的合同"); + // 返回当前日期作为建议 + return LocalDate.now(); + } + + LocalDate setupDate = firstContractAfter.getSetupDate(); + holder.info("找到最近一次评价日期后的第一个合同:" + firstContractAfter.getCode() + ",日期:" + setupDate); + + return setupDate.plusDays(-7); + } +} \ No newline at end of file diff --git a/server/src/main/java/com/ecep/contract/util/VerifyContext.java b/server/src/main/java/com/ecep/contract/util/VerifyContext.java index c596fcc..d95beac 100644 --- a/server/src/main/java/com/ecep/contract/util/VerifyContext.java +++ b/server/src/main/java/com/ecep/contract/util/VerifyContext.java @@ -13,7 +13,7 @@ import com.ecep.contract.ds.contract.service.ContractFileTypeService; import com.ecep.contract.ds.contract.service.ContractService; import com.ecep.contract.ds.customer.service.CompanyCustomerFileService; import com.ecep.contract.ds.customer.service.CompanyCustomerFileTypeService; -import com.ecep.contract.ds.customer.service.CompanyCustomerService; +import com.ecep.contract.ds.customer.service.CustomerService; import com.ecep.contract.ds.other.service.EmployeeService; import com.ecep.contract.ds.project.service.ProjectFileService; import com.ecep.contract.ds.project.service.ProjectFileTypeService; @@ -109,8 +109,8 @@ public class VerifyContext { // Customer - protected CompanyCustomerService getCompanyCustomerService() { - return getBean(CompanyCustomerService.class); + protected CustomerService getCompanyCustomerService() { + return getBean(CustomerService.class); } protected CompanyCustomerFileTypeService getCompanyCustomerFileTypeService() { diff --git a/server/src/main/resources/tasker_mapper.json b/server/src/main/resources/tasker_mapper.json index e6d12a9..762a73a 100644 --- a/server/src/main/resources/tasker_mapper.json +++ b/server/src/main/resources/tasker_mapper.json @@ -4,14 +4,17 @@ "ContractRepairTask": "com.ecep.contract.service.tasker.ContractRepairTasker", "ContractVerifyTasker": "com.ecep.contract.service.tasker.ContractVerifyTasker", "ProjectCostImportItemsFromContractsTasker": "com.ecep.contract.service.tasker.ProjectCostImportItemsFromContractsTasker", - "CompanyCustomerEvaluationFormUpdateTask": "com.ecep.contract.service.tasker.CompanyCustomerEvaluationFormUpdateTask", - "CompanyCustomerNextSignDateTask": "com.ecep.contract.service.tasker.CompanyCustomerNextSignDateTask", - "CompanyCustomerRebuildFilesTasker": "com.ecep.contract.service.tasker.CompanyCustomerRebuildFilesTasker", + "CustomerEvaluationFormUpdateTask": "com.ecep.contract.service.tasker.CompanyCustomerEvaluationFormUpdateTask", + "CustomerNextSignDateTask": "com.ecep.contract.service.tasker.CompanyCustomerNextSignDateTask", + "CustomerRebuildFilesTasker": "com.ecep.contract.service.tasker.CompanyCustomerRebuildFilesTasker", "CustomerFileMoveTasker": "com.ecep.contract.service.tasker.CustomerFileMoveTasker", "CompanyCompositeUpdateTasker": "com.ecep.contract.service.tasker.CompanyCompositeUpdateTasker", "CompanyVerifyTasker": "com.ecep.contract.service.tasker.CompanyVerifyTasker", "CompanyRkUpdateTasker": "com.ecep.contract.service.tasker.CompanyRkUpdateTasker", - "CloudRkSyncTask": "com.ecep.contract.cloud.rk.CloudRkSyncTask" + "CloudRkSyncTask": "com.ecep.contract.cloud.rk.CloudRkSyncTask", + "VendorReBuildFilesTasker": "com.ecep.contract.ds.vendor.task.VendorReBuildFilesTasker", + "CompanyVendorEvaluationFormUpdateTask": "com.ecep.contract.service.tasker.CompanyVendorEvaluationFormUpdateTask", + "VendorNextSignDateTask": "com.ecep.contract.service.tasker.VendorNextSignDateTask" }, - "descriptions": "任务注册信息" + "descriptions": "任务注册信息, 客户端的任务可以通过 WebSocket 调用" } \ No newline at end of file