feat: 实现客户端与服务器端Tasker通信机制及文件管理功能
refactor: 重构Tasker基类与服务获取逻辑 fix: 修复文件路径显示问题及任务注册加载机制 docs: 添加客户端与服务器端Tasker通信规则文档 style: 优化代码格式与日志输出 build: 添加tasker_mapper.json配置文件 chore: 清理无用代码与文件
This commit is contained in:
@@ -10,6 +10,7 @@ import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.ecep.contract.model.CompanyCustomer;
|
||||
import com.ecep.contract.model.CompanyCustomerEvaluationFormFile;
|
||||
import com.ecep.contract.model.CompanyCustomerFile;
|
||||
|
||||
@Repository
|
||||
public interface CompanyCustomerEvaluationFormFileRepository extends JpaRepository<CompanyCustomerEvaluationFormFile, Integer>, JpaSpecificationExecutor<CompanyCustomerEvaluationFormFile> {
|
||||
@@ -19,4 +20,6 @@ public interface CompanyCustomerEvaluationFormFileRepository extends JpaReposito
|
||||
@Query(value = "SELECT * FROM COMPANY_CUSTOMER_FILE ccf left join COMPANY_CUSTOMER_EVALUATION_FORM_FILE CCEFF on ccf.ID = CCEFF.ID " +
|
||||
"where ccf.CUSTOMER_ID=:customer and ccf.TYPE=:fileType", nativeQuery = true)
|
||||
List<CompanyCustomerEvaluationFormFile> findAllByCustomerAndType(@Param("customer") int companyCustomerId, @Param("fileType") String type);
|
||||
|
||||
CompanyCustomerEvaluationFormFile findByCustomerFile(CompanyCustomerFile customerFile);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
package com.ecep.contract.ds.customer.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.cache.annotation.Caching;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.ecep.contract.IEntityService;
|
||||
import com.ecep.contract.QueryService;
|
||||
import com.ecep.contract.constant.ServiceConstant;
|
||||
import com.ecep.contract.ds.customer.repository.CompanyCustomerEvaluationFormFileRepository;
|
||||
import com.ecep.contract.model.CompanyCustomer;
|
||||
import com.ecep.contract.model.CompanyCustomerEvaluationFormFile;
|
||||
import com.ecep.contract.model.CompanyCustomerFile;
|
||||
import com.ecep.contract.util.SpecificationUtils;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
|
||||
@Lazy
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "company-customer-evaluation-form-file")
|
||||
public class CompanyCustomerEvaluationFormFileService
|
||||
implements IEntityService<CompanyCustomerEvaluationFormFile>, QueryService<CompanyCustomerEvaluationFormFile> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(CompanyCustomerEvaluationFormFileService.class);
|
||||
|
||||
@Lazy
|
||||
@Autowired
|
||||
private CompanyCustomerEvaluationFormFileRepository repository;
|
||||
|
||||
@Cacheable(key = "#p0")
|
||||
@Override
|
||||
public CompanyCustomerEvaluationFormFile findById(Integer id) {
|
||||
return repository.findById(id).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Specification<CompanyCustomerEvaluationFormFile> getSpecification(String searchText) {
|
||||
if (!org.springframework.util.StringUtils.hasText(searchText)) {
|
||||
return null;
|
||||
}
|
||||
return (root, query, builder) -> {
|
||||
return builder.or(
|
||||
builder.like(root.get("catalog"), "%" + searchText + "%"),
|
||||
builder.like(root.get("level"), "%" + searchText + "%"));
|
||||
};
|
||||
}
|
||||
|
||||
@Caching(evict = {
|
||||
@CacheEvict(key = "#p0.id"),
|
||||
})
|
||||
@Override
|
||||
public void delete(CompanyCustomerEvaluationFormFile formFile) {
|
||||
repository.delete(formFile);
|
||||
}
|
||||
|
||||
@Caching(evict = {
|
||||
@CacheEvict(key = "#p0.id"),
|
||||
})
|
||||
@Override
|
||||
public CompanyCustomerEvaluationFormFile save(CompanyCustomerEvaluationFormFile formFile) {
|
||||
return repository.save(formFile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<CompanyCustomerEvaluationFormFile> findAll(Specification<CompanyCustomerEvaluationFormFile> spec,
|
||||
Pageable pageable) {
|
||||
return repository.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<CompanyCustomerEvaluationFormFile> findAll(JsonNode paramsNode, Pageable pageable) {
|
||||
Specification<CompanyCustomerEvaluationFormFile> spec = null;
|
||||
if (paramsNode.has(ServiceConstant.KEY_SEARCH_TEXT)) {
|
||||
spec = getSpecification(paramsNode.get(ServiceConstant.KEY_SEARCH_TEXT).asText());
|
||||
}
|
||||
|
||||
if (paramsNode.has("customer")) {
|
||||
CompanyCustomer customer = new CompanyCustomer();
|
||||
customer.setId(paramsNode.get("customer").asInt());
|
||||
spec = SpecificationUtils.and(spec,
|
||||
(root, query, builder) -> builder.equal(root.get("customerFile").get("customer"), customer));
|
||||
}
|
||||
|
||||
spec = SpecificationUtils.andParam(spec, paramsNode, "customerFile");
|
||||
spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "catalog", "level");
|
||||
|
||||
return findAll(spec, pageable);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据客户查询所有评估表文件
|
||||
*
|
||||
* @param customer 客户实体
|
||||
* @return 评估表文件列表
|
||||
*/
|
||||
public List<CompanyCustomerEvaluationFormFile> findAllByCustomer(CompanyCustomer customer) {
|
||||
return repository.findAllByCustomerFileCustomer(customer);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据客户ID和文件类型查询评估表文件
|
||||
*
|
||||
* @param companyCustomerId 客户ID
|
||||
* @param type 文件类型
|
||||
* @return 评估表文件列表
|
||||
*/
|
||||
public List<CompanyCustomerEvaluationFormFile> findAllByCustomerIdAndType(int companyCustomerId, String type) {
|
||||
return repository.findAllByCustomerAndType(companyCustomerId, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据客户文件查询评估表文件
|
||||
*
|
||||
* @param customerFile 客户文件实体
|
||||
* @return 评估表文件列表
|
||||
*/
|
||||
public CompanyCustomerEvaluationFormFile findByCustomerFile(CompanyCustomerFile customerFile) {
|
||||
return repository.findByCustomerFile(customerFile);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,12 +5,7 @@ import java.time.LocalDate;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import com.ecep.contract.QueryService;
|
||||
import com.ecep.contract.model.*;
|
||||
import com.ecep.contract.util.SpecificationUtils;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -27,20 +22,30 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import com.ecep.contract.CustomerFileType;
|
||||
import com.ecep.contract.IEntityService;
|
||||
import com.ecep.contract.MessageHolder;
|
||||
import com.ecep.contract.QueryService;
|
||||
import com.ecep.contract.SpringApp;
|
||||
import com.ecep.contract.constant.CompanyCustomerConstant;
|
||||
import com.ecep.contract.constant.ServiceConstant;
|
||||
import com.ecep.contract.ds.company.service.CompanyBasicService;
|
||||
import com.ecep.contract.ds.contract.service.ContractService;
|
||||
import com.ecep.contract.ds.customer.repository.CompanyCustomerEvaluationFormFileRepository;
|
||||
import com.ecep.contract.ds.customer.repository.CompanyCustomerFileRepository;
|
||||
import com.ecep.contract.ds.other.service.SysConfService;
|
||||
import com.ecep.contract.model.CompanyCustomer;
|
||||
import com.ecep.contract.model.CompanyCustomerEvaluationFormFile;
|
||||
import com.ecep.contract.model.CompanyCustomerFile;
|
||||
import com.ecep.contract.model.Contract;
|
||||
import com.ecep.contract.util.SpecificationUtils;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
|
||||
import jakarta.persistence.criteria.Path;
|
||||
|
||||
@Lazy
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "company-customer-file")
|
||||
public class CompanyCustomerFileService implements IEntityService<CompanyCustomerFile>, QueryService<CompanyCustomerFile> {
|
||||
public class CompanyCustomerFileService
|
||||
implements IEntityService<CompanyCustomerFile>, QueryService<CompanyCustomerFile> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(CompanyCustomerFileService.class);
|
||||
@Lazy
|
||||
@Autowired
|
||||
@@ -64,13 +69,9 @@ public class CompanyCustomerFileService implements IEntityService<CompanyCustome
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Caching(
|
||||
evict = {
|
||||
@CacheEvict(key = "#p0.id"),
|
||||
}
|
||||
)
|
||||
@Caching(evict = {
|
||||
@CacheEvict(key = "#p0.id"),
|
||||
})
|
||||
public void delete(CompanyCustomerFile file) {
|
||||
if (file.getType() == CustomerFileType.EvaluationForm) {
|
||||
companyCustomerEvaluationFormFileRepository.deleteById(file.getId());
|
||||
@@ -78,11 +79,9 @@ public class CompanyCustomerFileService implements IEntityService<CompanyCustome
|
||||
companyCustomerFileRepository.delete(file);
|
||||
}
|
||||
|
||||
@Caching(
|
||||
evict = {
|
||||
@CacheEvict(key = "#p0.id"),
|
||||
}
|
||||
)
|
||||
@Caching(evict = {
|
||||
@CacheEvict(key = "#p0.id"),
|
||||
})
|
||||
public CompanyCustomerFile save(CompanyCustomerFile dbFile) {
|
||||
return companyCustomerFileRepository.save(dbFile);
|
||||
}
|
||||
@@ -99,8 +98,8 @@ public class CompanyCustomerFileService implements IEntityService<CompanyCustome
|
||||
@Override
|
||||
public Page<CompanyCustomerFile> findAll(JsonNode paramsNode, Pageable pageable) {
|
||||
Specification<CompanyCustomerFile> spec = null;
|
||||
if (paramsNode.has("searchText")) {
|
||||
spec = getSpecification(paramsNode.get("searchText").asText());
|
||||
if (paramsNode.has(ServiceConstant.KEY_SEARCH_TEXT)) {
|
||||
spec = getSpecification(paramsNode.get(ServiceConstant.KEY_SEARCH_TEXT).asText());
|
||||
}
|
||||
// field
|
||||
spec = SpecificationUtils.andParam(spec, paramsNode, "customer");
|
||||
@@ -124,12 +123,10 @@ public class CompanyCustomerFileService implements IEntityService<CompanyCustome
|
||||
companyCustomerFileRepository.delete(customerFile);
|
||||
}
|
||||
|
||||
|
||||
public List<CompanyCustomerFile> findAll(Specification<CompanyCustomerFile> spec, Sort sort) {
|
||||
return companyCustomerFileRepository.findAll(spec, sort);
|
||||
}
|
||||
|
||||
|
||||
public List<CompanyCustomerFile> saveAll(List<CompanyCustomerFile> files) {
|
||||
return companyCustomerFileRepository.saveAll(files);
|
||||
}
|
||||
@@ -153,7 +150,8 @@ public class CompanyCustomerFileService implements IEntityService<CompanyCustome
|
||||
return companyCustomerEvaluationFormFileRepository.findById(id).orElse(null);
|
||||
}
|
||||
|
||||
public CompanyCustomerEvaluationFormFile findCustomerEvaluationFormFileByCustomerFile(CompanyCustomerFile customerFile) {
|
||||
public CompanyCustomerEvaluationFormFile findCustomerEvaluationFormFileByCustomerFile(
|
||||
CompanyCustomerFile customerFile) {
|
||||
Integer id = customerFile.getId();
|
||||
if (id == null) {
|
||||
CompanyCustomerFile saved = companyCustomerFileRepository.save(customerFile);
|
||||
@@ -161,7 +159,8 @@ public class CompanyCustomerFileService implements IEntityService<CompanyCustome
|
||||
customerFile.setId(id);
|
||||
}
|
||||
|
||||
CompanyCustomerEvaluationFormFile formFile = companyCustomerEvaluationFormFileRepository.findById(id).orElse(null);
|
||||
CompanyCustomerEvaluationFormFile formFile = companyCustomerEvaluationFormFileRepository.findById(id)
|
||||
.orElse(null);
|
||||
if (formFile == null) {
|
||||
formFile = new CompanyCustomerEvaluationFormFile();
|
||||
formFile.setId(id);
|
||||
@@ -171,13 +170,13 @@ public class CompanyCustomerFileService implements IEntityService<CompanyCustome
|
||||
return formFile;
|
||||
}
|
||||
|
||||
public LocalDate getNextSignDate(CompanyCustomer companyCustomer, Consumer<String> state) {
|
||||
public LocalDate getNextSignDate(CompanyCustomer companyCustomer, MessageHolder holder) {
|
||||
LocalDate miniContractDate = LocalDate.of(2022, 1, 1);
|
||||
// 检索全部合同
|
||||
ContractService contractService = SpringApp.getBean(ContractService.class);
|
||||
List<Contract> contractList = contractService.findAllByCompanyCustomer(companyCustomer, null, null);
|
||||
if (contractList.isEmpty()) {
|
||||
state.accept("未发现已登记的合同");
|
||||
holder.error("未发现已登记的合同");
|
||||
return null;
|
||||
}
|
||||
// 检索评估表
|
||||
@@ -189,46 +188,45 @@ public class CompanyCustomerFileService implements IEntityService<CompanyCustome
|
||||
|
||||
// 没有有效的评估表的评价日期
|
||||
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 + " 推算");
|
||||
holder.info("依据合同 " + firstContract.getCode() + " 的日期 " + setupDate + " 推算");
|
||||
return CompanyBasicService.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<Contract> 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 + " 推算");
|
||||
holder.info("匹配失效期 " + nextInValidDate + " 后的第一个合同 " + firstContract.getCode());
|
||||
holder.info("依据合同 " + firstContract.getCode() + " 的日期 " + setupDate + " 推算");
|
||||
return CompanyBasicService.adjustToWorkDay(setupDate.plusDays(-7));
|
||||
}
|
||||
|
||||
|
||||
public File getEvaluationFormTemplate() {
|
||||
String path = confService.getString(CompanyCustomerConstant.KEY_EVALUATION_FORM_TEMPLATE);
|
||||
if (path == null) {
|
||||
@@ -263,5 +261,4 @@ public class CompanyCustomerFileService implements IEntityService<CompanyCustome
|
||||
return companyCustomerEvaluationFormFileRepository.findAll(spec, Pageable.ofSize(10)).getContent();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import java.util.stream.Collectors;
|
||||
import com.ecep.contract.QueryService;
|
||||
import com.ecep.contract.constant.CompanyCustomerConstant;
|
||||
import com.ecep.contract.model.*;
|
||||
import com.ecep.contract.MessageHolder;
|
||||
import com.ecep.contract.util.CompanyUtils;
|
||||
import com.ecep.contract.util.FileUtils;
|
||||
import org.hibernate.Hibernate;
|
||||
@@ -151,25 +152,25 @@ public class CompanyCustomerService extends CompanyBasicService
|
||||
* 重置 客户文件
|
||||
*
|
||||
* @param companyCustomer 客户对象
|
||||
* @param status 输出
|
||||
* @param holder 消息持有者
|
||||
*/
|
||||
public boolean reBuildingFiles(CompanyCustomer companyCustomer, Consumer<String> status) {
|
||||
public boolean reBuildingFiles(CompanyCustomer companyCustomer, MessageHolder holder) {
|
||||
List<CompanyCustomerFile> dbFiles = companyCustomerFileService.findAllByCustomer(companyCustomer);
|
||||
Map<String, CompanyCustomerFile> map = new HashMap<>();
|
||||
|
||||
boolean modified = fetchDbFiles(dbFiles, map, status);
|
||||
boolean modified = fetchDbFiles(dbFiles, map, holder::info);
|
||||
|
||||
// 客户目录下
|
||||
List<CompanyCustomerFile> retrieveFiles = new ArrayList<>();
|
||||
List<File> needMoveToCompanyPath = new ArrayList<>();
|
||||
|
||||
// TODO 客户有曾用名,可能存在多个目录
|
||||
fetchFiles(companyCustomer.getPath(), needMoveToCompanyPath, retrieveFiles, map, status);
|
||||
fetchFiles(companyCustomer.getPath(), needMoveToCompanyPath, retrieveFiles, map, holder::info);
|
||||
|
||||
// 移动文件到公司目录下 to company path
|
||||
moveFileToCompany(companyCustomer.getCompany(), needMoveToCompanyPath);
|
||||
|
||||
status.accept("导入 " + retrieveFiles.size() + " 个文件");
|
||||
holder.info("导入 " + retrieveFiles.size() + " 个文件");
|
||||
|
||||
if (!retrieveFiles.isEmpty()) {
|
||||
// update db
|
||||
@@ -184,7 +185,7 @@ public class CompanyCustomerService extends CompanyBasicService
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
protected <T, F extends CompanyBasicFile<T>> boolean fillFileAsDefaultType(F dbFile, File file,
|
||||
Consumer<String> status) {
|
||||
Consumer<String> status) {
|
||||
dbFile.setType((T) CustomerFileType.General);
|
||||
fillFile(dbFile, file, null, status);
|
||||
companyCustomerFileService.save((CompanyCustomerFile) dbFile);
|
||||
@@ -193,7 +194,7 @@ public class CompanyCustomerService extends CompanyBasicService
|
||||
|
||||
@Override
|
||||
protected <T, F extends CompanyBasicFile<T>> boolean fillFileAsEvaluationFile(F customerFile, File file,
|
||||
List<File> fileList, Consumer<String> status) {
|
||||
List<File> fileList, Consumer<String> status) {
|
||||
boolean modified = super.fillFileAsEvaluationFile(customerFile, file, fileList, status);
|
||||
|
||||
if (fileList != null) {
|
||||
@@ -227,7 +228,7 @@ public class CompanyCustomerService extends CompanyBasicService
|
||||
}
|
||||
|
||||
private <T, F extends CompanyBasicFile<T>> void updateEvaluationFileByJsonFile(F customerFile, File jsonFile,
|
||||
Consumer<String> status) throws IOException {
|
||||
Consumer<String> status) throws IOException {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
JsonNode root = objectMapper.readTree(jsonFile);
|
||||
if (!root.isObject()) {
|
||||
@@ -250,10 +251,11 @@ public class CompanyCustomerService extends CompanyBasicService
|
||||
logger.info("delete json file {}", jsonFile.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
protected <T, F extends CompanyBasicFile<T>> F fillFileType(File file, List<File> fileList,
|
||||
Consumer<String> status) {
|
||||
Consumer<String> status) {
|
||||
CompanyCustomerFile customerFile = new CompanyCustomerFile();
|
||||
customerFile.setType(CustomerFileType.General);
|
||||
if (fillFile(customerFile, file, fileList, status)) {
|
||||
@@ -261,6 +263,7 @@ public class CompanyCustomerService extends CompanyBasicService
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
protected <T, F extends CompanyBasicFile<T>> boolean setFileTypeAsEvaluationForm(F file) {
|
||||
@@ -276,7 +279,7 @@ public class CompanyCustomerService extends CompanyBasicService
|
||||
return (fileName.contains(CompanyCustomerConstant.EVALUATION_FORM_NAME1)
|
||||
|| fileName.contains(CompanyCustomerConstant.EVALUATION_FORM_NAME2))
|
||||
&& (FileUtils.withExtensions(fileName, FileUtils.JPG, FileUtils.JPEG,
|
||||
FileUtils.PDF));
|
||||
FileUtils.PDF));
|
||||
}
|
||||
|
||||
public boolean makePathAbsent(CompanyCustomer companyCustomer) {
|
||||
@@ -410,5 +413,4 @@ public class CompanyCustomerService extends CompanyBasicService
|
||||
return customerCatalogRepository.save(catalog);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,214 @@
|
||||
package com.ecep.contract.ds.customer.tasker;
|
||||
|
||||
import static com.ecep.contract.util.ExcelUtils.setCellValue;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.time.LocalDate;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.ss.usermodel.WorkbookFactory;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
import org.hibernate.Hibernate;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.ecep.contract.CustomerFileType;
|
||||
import com.ecep.contract.MessageHolder;
|
||||
import com.ecep.contract.SpringApp;
|
||||
import com.ecep.contract.cloud.tyc.CloudTycService;
|
||||
import com.ecep.contract.ds.customer.service.CompanyCustomerFileService;
|
||||
import com.ecep.contract.ds.customer.service.CompanyCustomerEvaluationFormFileService;
|
||||
import com.ecep.contract.ds.customer.service.CompanyCustomerService;
|
||||
import com.ecep.contract.model.CloudTyc;
|
||||
import com.ecep.contract.model.Company;
|
||||
import com.ecep.contract.model.CompanyCustomer;
|
||||
import com.ecep.contract.model.CompanyCustomerEvaluationFormFile;
|
||||
import com.ecep.contract.model.CompanyCustomerFile;
|
||||
import com.ecep.contract.service.WebSocketServerTasker;
|
||||
import com.ecep.contract.ui.Tasker;
|
||||
import com.ecep.contract.util.CompanyUtils;
|
||||
import com.ecep.contract.vo.CompanyCustomerEvaluationFormFileVo;
|
||||
import com.ecep.contract.vo.CompanyCustomerFileVo;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
|
||||
public class CompanyCustomerEvaluationFormUpdateTask extends Tasker<Object> implements WebSocketServerTasker {
|
||||
private CompanyCustomer customer;
|
||||
|
||||
@Override
|
||||
public void init(JsonNode argsNode) {
|
||||
int customerId = argsNode.get(0).asInt();
|
||||
customer = getCachedBean(CompanyCustomerService.class).findById(customerId);
|
||||
}
|
||||
|
||||
CompanyCustomerFileService getCompanyCustomerFileService() {
|
||||
return getCachedBean(CompanyCustomerFileService.class);
|
||||
}
|
||||
|
||||
CompanyCustomerEvaluationFormFileService getCompanyCustomerEvaluationFormFileService() {
|
||||
return getCachedBean(CompanyCustomerEvaluationFormFileService.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object execute(MessageHolder holder) throws Exception {
|
||||
updateEvaluationForm(holder);
|
||||
return null;
|
||||
}
|
||||
|
||||
public void updateEvaluationForm(MessageHolder holder) {
|
||||
if (!StringUtils.hasText(customer.getPath())) {
|
||||
holder.error("供应商目录未设置,请先设置供应商目录");
|
||||
return;
|
||||
}
|
||||
File template = getCompanyCustomerFileService().getEvaluationFormTemplate();
|
||||
if (template == null) {
|
||||
holder.error("评价表模板文件未设置,请先设置评价表模板文件");
|
||||
return;
|
||||
}
|
||||
if (!template.exists()) {
|
||||
holder.error("评价表模板文件 " + template.getAbsolutePath() + " 不存在,请检查");
|
||||
return;
|
||||
}
|
||||
|
||||
updateProgress(1, 10);
|
||||
File dir = new File(customer.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("评价表已创建");
|
||||
CompanyCustomerFile customerFile = new CompanyCustomerFile();
|
||||
customerFile.setCustomer(customer);
|
||||
customerFile.setFilePath(destFile.getAbsolutePath());
|
||||
customerFile.setType(CustomerFileType.General);
|
||||
getCompanyCustomerFileService().save(customerFile);
|
||||
} 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);
|
||||
Company company = customer.getCompany();
|
||||
if (!Hibernate.isInitialized(company)) {
|
||||
company = getCompanyService().findById(company.getId());
|
||||
customer.setCompany(company);
|
||||
}
|
||||
Sheet sheet = wb.getSheetAt(0);
|
||||
updateSheet(company, 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(Company company, Sheet sheet, MessageHolder holder) {
|
||||
setCellValue(sheet, "B3", "客户编号:" + CompanyUtils.formatCompanyVendorId(customer.getId()));
|
||||
setCellValue(sheet, "B4", "客户名称:" + company.getName());
|
||||
|
||||
LocalDate suggestDate = getCompanyCustomerFileService().getNextSignDate(customer, holder);
|
||||
if (suggestDate == null) {
|
||||
suggestDate = LocalDate.now();
|
||||
}
|
||||
setCellValue(sheet, "H3", "评定时间:" + suggestDate);
|
||||
setCellValue(sheet, "H4", "统一社会信用代码:");
|
||||
setCellValue(sheet, "H5", company.getUniscid());
|
||||
// 注册所属地
|
||||
setCellValue(sheet, "B5", "注册所属地:" + company.getDistrict());
|
||||
// 经营状态
|
||||
setCellValue(sheet, "D6", "经营状态:" + company.getEntStatus());
|
||||
// 成立日期
|
||||
setCellValue(sheet, "H6", "成立日期:" + company.getSetupDate());
|
||||
// 所属行业
|
||||
setCellValue(sheet, "D7", "所属行业:" + company.getIndustry());
|
||||
setCellValue(sheet, "D8",
|
||||
"注册资金:" + company.getRegisteredCapital() + " " + company.getRegisteredCapitalCurrency());
|
||||
// 企业类型
|
||||
setCellValue(sheet, "H10", "企业类型:" + company.getEntType());
|
||||
// 天眼评分
|
||||
CloudTycService cloudTycService = SpringApp.getBean(CloudTycService.class);
|
||||
CloudTyc cloudTyc = cloudTycService.getOrCreateCloudTyc(company);
|
||||
setCellValue(sheet, "D10", "天眼评分:" + (cloudTyc.getScore() > 0 ? cloudTyc.getScore() : ""));
|
||||
|
||||
// 检索评估表
|
||||
List<CompanyCustomerFile> customerFiles = getCompanyCustomerFileService().findAllByCustomerAndType(customer,
|
||||
CustomerFileType.EvaluationForm);
|
||||
|
||||
List<CompanyCustomerEvaluationFormFile> filteredList = customerFiles.stream().filter(file -> {
|
||||
return file.getSignDate() != null && file.isValid();
|
||||
})
|
||||
.sorted(Comparator.comparing(CompanyCustomerFile::getSignDate))
|
||||
.map(getCompanyCustomerEvaluationFormFileService()::findByCustomerFile)
|
||||
.toList();
|
||||
|
||||
if (filteredList.isEmpty()) {
|
||||
setCellValue(sheet, "C40", "首次评价");
|
||||
try {
|
||||
sheet.addMergedRegion(CellRangeAddress.valueOf("C40:K40"));
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
} else {
|
||||
holder.info("客户有 " + filteredList.size() + " 条评价表");
|
||||
setCellValue(sheet, "C40", "评价日期");
|
||||
try {
|
||||
sheet.addMergedRegion(CellRangeAddress.valueOf("C40:D40"));
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
setCellValue(sheet, "E40", "经济指标");
|
||||
setCellValue(sheet, "F40", "综合指标");
|
||||
setCellValue(sheet, "G40", "资信等级");
|
||||
String[] CreditLevelTitles = new String[] { "-", "差★", " 一般★★", " 较好★★★", " 好★★★★", " " };
|
||||
int baseRow = 40;
|
||||
for (CompanyCustomerEvaluationFormFile form : filteredList) {
|
||||
CompanyCustomerFile customerFile = form.getCustomerFile();
|
||||
if (!Hibernate.isInitialized(customerFile)) {
|
||||
customerFile = getCompanyCustomerFileService().findById(customerFile.getId());
|
||||
}
|
||||
setCellValue(sheet, baseRow, 2, String.valueOf(customerFile.getSignDate()));
|
||||
setCellValue(sheet, baseRow, 4, form.getCatalog());
|
||||
setCellValue(sheet, baseRow, 5, form.getLevel());
|
||||
if (form.getCreditLevel() == null) {
|
||||
setCellValue(sheet, baseRow, 6, "-");
|
||||
} else {
|
||||
setCellValue(sheet, baseRow, 6, CreditLevelTitles[form.getCreditLevel()]);
|
||||
}
|
||||
try {
|
||||
sheet.addMergedRegion(new CellRangeAddress(baseRow, baseRow, 2, 3));
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
baseRow++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
package com.ecep.contract.ds.customer.tasker;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
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.model.CompanyCustomer;
|
||||
import com.ecep.contract.model.CompanyCustomerFile;
|
||||
import com.ecep.contract.model.Contract;
|
||||
import com.ecep.contract.service.WebSocketServerTasker;
|
||||
import com.ecep.contract.ui.Tasker;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
|
||||
public class CompanyCustomerNextSignDateTask extends Tasker<Object> implements WebSocketServerTasker {
|
||||
|
||||
private CompanyCustomer customer;
|
||||
|
||||
@Override
|
||||
public void init(JsonNode argsNode) {
|
||||
int customerId = argsNode.get(0).asInt();
|
||||
customer = getCachedBean(CompanyCustomerService.class).findById(customerId);
|
||||
}
|
||||
|
||||
CompanyCustomerFileService getCompanyCustomerFileService() {
|
||||
return getCachedBean(CompanyCustomerFileService.class);
|
||||
}
|
||||
|
||||
CompanyCustomerService getCompanyCustomerService() {
|
||||
return getCachedBean(CompanyCustomerService.class);
|
||||
}
|
||||
|
||||
ContractService getContractService() {
|
||||
return getCachedBean(ContractService.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object execute(MessageHolder holder) throws Exception {
|
||||
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<Contract> contractList = contractService.findAllByCompanyCustomer(customer, null, null);
|
||||
if (contractList.isEmpty()) {
|
||||
holder.error("未发现已登记的合同");
|
||||
return null;
|
||||
}
|
||||
|
||||
holder.info("发现" + contractList.size() + "份合同");
|
||||
|
||||
// 检索评估表
|
||||
List<CompanyCustomerFile> files = getCompanyCustomerFileService().findAllByCustomerAndType(customer,
|
||||
CustomerFileType.EvaluationForm);
|
||||
CompanyCustomerFile latestFile = files.stream()
|
||||
.filter(v -> v.getSignDate() != null && v.isValid())
|
||||
.max(Comparator.comparing(CompanyCustomerFile::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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.ecep.contract.ds.customer.tasker;
|
||||
|
||||
import org.hibernate.Hibernate;
|
||||
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.model.Company;
|
||||
import com.ecep.contract.model.CompanyCustomer;
|
||||
import com.ecep.contract.service.WebSocketServerTasker;
|
||||
import com.ecep.contract.ui.Tasker;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
|
||||
/**
|
||||
* 客户文件重建任务器
|
||||
* 用于重建客户相关文件,同步文件系统和数据库记录
|
||||
*/
|
||||
public class CompanyCustomerRebuildFilesTasker extends Tasker<Object> implements WebSocketServerTasker {
|
||||
|
||||
private CompanyCustomer customer;
|
||||
|
||||
CompanyCustomerService getCompanyCustomerService() {
|
||||
return getCachedBean(CompanyCustomerService.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(JsonNode argsNode) {
|
||||
int customerId = argsNode.get(0).asInt();
|
||||
customer = getCompanyCustomerService().findById(customerId);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object execute(MessageHolder holder) throws Exception {
|
||||
updateTitle("重建客户文件");
|
||||
updateProgress(0, 100);
|
||||
|
||||
if (customer == null) {
|
||||
holder.error("客户不存在");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!StringUtils.hasText(customer.getPath())) {
|
||||
holder.error("客户路径未设置,无法重建文件");
|
||||
updateProgress(100, 100);
|
||||
return false;
|
||||
}
|
||||
|
||||
Company company = customer.getCompany();
|
||||
if (!Hibernate.isInitialized(company)) {
|
||||
company = getCachedBean(CompanyService.class).findById(company.getId());
|
||||
}
|
||||
|
||||
try {
|
||||
holder.info("开始重建客户文件:" + company.getName());
|
||||
holder.info("客户路径:" + customer.getPath());
|
||||
|
||||
boolean result = getCompanyCustomerService().reBuildingFiles(customer, holder);
|
||||
|
||||
if (result) {
|
||||
holder.info("客户文件重建成功");
|
||||
updateProperty("filesUpdated", true);
|
||||
} else {
|
||||
holder.info("客户文件重建完成,但没有更新任何文件");
|
||||
updateProperty("filesUpdated", false);
|
||||
}
|
||||
|
||||
updateProgress(100, 100);
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
holder.error("客户文件重建失败:" + e.getMessage());
|
||||
updateProgress(100, 100);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,25 +1,27 @@
|
||||
package com.ecep.contract.service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.socket.TextMessage;
|
||||
import org.springframework.web.socket.WebSocketSession;
|
||||
|
||||
import com.ecep.contract.Message;
|
||||
import com.ecep.contract.constant.WebSocketConstant;
|
||||
import com.ecep.contract.ui.Tasker;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.socket.TextMessage;
|
||||
import org.springframework.web.socket.WebSocketSession;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
|
||||
@Service
|
||||
public class WebSocketServerTaskManager implements InitializingBean {
|
||||
@@ -28,16 +30,31 @@ public class WebSocketServerTaskManager implements InitializingBean {
|
||||
private ObjectMapper objectMapper;
|
||||
@Autowired
|
||||
private ScheduledExecutorService scheduledExecutorService;
|
||||
@Autowired
|
||||
private ResourceLoader resourceLoader;
|
||||
private Map<String, String> taskClzMap = Map.of();
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
taskClzMap = Map.of(
|
||||
"ContractSyncTask", "com.ecep.contract.cloud.u8.ContractSyncTask",
|
||||
"ContractRepairTask", "com.ecep.contract.ds.contract.tasker.ContractRepairTask",
|
||||
"ContractVerifyTask", "com.ecep.contract.ds.contract.tasker.ContractVerifyTask",
|
||||
"ProjectCostImportItemsFromContractsTasker", "com.ecep.contract.ds.project.ProjectCostImportItemsFromContractsTasker"
|
||||
);
|
||||
// 从tasker_mapper.json文件中加载任务注册信息
|
||||
try {
|
||||
Resource resource = resourceLoader.getResource("classpath:tasker_mapper.json");
|
||||
try (InputStream inputStream = resource.getInputStream()) {
|
||||
JsonNode rootNode = objectMapper.readTree(inputStream);
|
||||
JsonNode taskersNode = rootNode.get("taskers");
|
||||
if (taskersNode != null && taskersNode.isObject()) {
|
||||
Map<String, String> taskMap = new java.util.HashMap<>();
|
||||
taskersNode.fields().forEachRemaining(entry -> {
|
||||
taskMap.put(entry.getKey(), entry.getValue().asText());
|
||||
});
|
||||
taskClzMap = taskMap;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("Failed to load tasker_mapper.json", e);
|
||||
// 使用默认值作为fallback
|
||||
taskClzMap = Map.of();
|
||||
}
|
||||
}
|
||||
|
||||
public void onMessage(WebSocketSession session, JsonNode jsonNode) {
|
||||
@@ -51,7 +68,6 @@ public class WebSocketServerTaskManager implements InitializingBean {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void handleAsSessionCallback(WebSocketSession session, String sessionId, JsonNode jsonNode) {
|
||||
if (!jsonNode.has("type")) {
|
||||
throw new IllegalArgumentException("缺失 type 参数");
|
||||
@@ -120,8 +136,7 @@ public class WebSocketServerTaskManager implements InitializingBean {
|
||||
String text = objectMapper.writeValueAsString(Map.of(
|
||||
WebSocketConstant.SESSION_ID_FIELD_NAME, sessionId,
|
||||
"type", type,
|
||||
WebSocketConstant.ARGUMENTS_FIELD_NAME, args
|
||||
));
|
||||
WebSocketConstant.ARGUMENTS_FIELD_NAME, args));
|
||||
session.sendMessage(new TextMessage(text));
|
||||
} catch (IOException e) {
|
||||
// 捕获所有可能的异常,防止影响主流程
|
||||
@@ -130,7 +145,6 @@ public class WebSocketServerTaskManager implements InitializingBean {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private void sendError(WebSocketSession session, String sessionId, String message) {
|
||||
if (session == null || !session.isOpen()) {
|
||||
logger.warn("尝试向已关闭的WebSocket会话发送错误消息: {}", message);
|
||||
@@ -141,8 +155,7 @@ public class WebSocketServerTaskManager implements InitializingBean {
|
||||
String errorMessage = objectMapper.writeValueAsString(Map.of(
|
||||
WebSocketConstant.SESSION_ID_FIELD_NAME, sessionId,
|
||||
WebSocketConstant.SUCCESS_FIELD_VALUE, false,
|
||||
WebSocketConstant.MESSAGE_FIELD_NAME, message
|
||||
));
|
||||
WebSocketConstant.MESSAGE_FIELD_NAME, message));
|
||||
|
||||
// 检查会话状态并尝试发送错误消息
|
||||
if (session.isOpen()) {
|
||||
|
||||
Reference in New Issue
Block a user