refactor(controller): 重构控制器类名和路径,优化代码结构
feat(service): 新增QueryService接口实现,支持通用查询功能 docs(util): 完善ProxyUtils工具类的注释说明 fix(model): 修复CustomerCatalog实现IdentityEntity接口 style: 优化代码格式和导入顺序 perf(util): 提升FileUtils工具类功能,新增文件处理方法 chore: 更新README.md文件,补充UI资源路径说明 build: 更新pom.xml文件中的mainClass配置 test: 调整测试类命名和路径 ci: 更新CI配置文件中的类引用 refactor(controller): 重构表格单元格异步更新逻辑 docs(constant): 新增常量定义和注释 style: 统一代码风格和命名规范 refactor(service): 重构服务类继承关系 perf(controller): 优化表格数据加载性能 fix(service): 修复文件类型服务缓存问题 docs(model): 完善视图模型类注释 refactor(util): 重构文件工具类方法 style: 清理无用导入和代码 chore: 更新.gitignore文件 build: 调整项目依赖配置 refactor(controller): 重构控制器基类 perf(service): 优化查询服务性能 fix(controller): 修复表格数据加载异常 docs: 更新代码注释和文档 style: 统一代码缩进和格式
This commit is contained in:
@@ -1,10 +1,26 @@
|
||||
package com.ecep.contract;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
|
||||
/**
|
||||
* 查询服务接口,提供通用的分页查询能力
|
||||
* 泛型T表示查询结果的数据类型
|
||||
*/
|
||||
public interface QueryService<T> {
|
||||
/**
|
||||
* 根据查询参数和分页条件获取数据列表
|
||||
*
|
||||
* @param paramsNode JSON格式的查询参数节点,包含各种过滤条件
|
||||
* @param pageable 分页参数,包含页码、每页条数、排序规则等信息
|
||||
* @return 分页查询结果,包含符合条件的数据列表和分页元数据
|
||||
*/
|
||||
Page<T> findAll(JsonNode paramsNode, Pageable pageable);
|
||||
}
|
||||
|
||||
Specification<T> getSpecification(String searchText);
|
||||
|
||||
Page<T> findAll(Specification<T> spec, Pageable pageable);
|
||||
}
|
||||
@@ -11,19 +11,28 @@ import org.springframework.boot.context.metrics.buffering.BufferingApplicationSt
|
||||
/**
|
||||
* Created by Administrator on 2017/4/16.
|
||||
*/
|
||||
public class AppV2 {
|
||||
private static final Logger logger = LoggerFactory.getLogger(AppV2.class);
|
||||
public class ServerV2 {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ServerV2.class);
|
||||
|
||||
public static void main(String[] args) {
|
||||
// 配置JVM参数以解决Java代理动态加载警告
|
||||
// 这些参数主要用于解决360安全卫士的Java代理(com.baize.aegis.plugin.dependency.DependencyExtension)加载问题
|
||||
|
||||
// 1. 启用代理使用跟踪,记录哪些代理被加载和使用
|
||||
// 添加JVM参数以解决Java代理动态加载警告
|
||||
// 这些警告来自360安全卫士的Java代理(com.baize.aegis.plugin.dependency.DependencyExtension)
|
||||
// 1. 启用代理使用跟踪
|
||||
System.setProperty("jdk.instrument.traceUsage", "true");
|
||||
// 2. 明确允许动态加载Java代理
|
||||
|
||||
// 2. 明确允许动态加载的Java代理访问本地代码
|
||||
// 这对于需要调用本地方法的代理(如安全软件的代理)非常重要
|
||||
System.setProperty("jdk.instrument.allowNativeAccess", "true");
|
||||
|
||||
// 3. 设置允许动态加载代理
|
||||
// 在较新版本的JDK中,默认可能限制了动态加载代理的能力
|
||||
// 此参数显式启用动态代理加载功能,确保安全软件的代理能够正常工作
|
||||
System.setProperty("jdk.enableDynamicAgentLoading", "true");
|
||||
|
||||
|
||||
SpringApp.application = new SpringApplication(SpringApp.class);
|
||||
|
||||
BufferingApplicationStartup startup = new BufferingApplicationStartup(2000);
|
||||
@@ -46,4 +55,4 @@ public class AppV2 {
|
||||
public static final String DEFAULT_DB_USERNAME = "supplier_ms";
|
||||
public static final String DEFAULT_DB_PASSWORD = "[TPdseO!JKMmlrpf";
|
||||
public static final String DEFAULT_DB_DATABASE = "supplier_ms";
|
||||
}
|
||||
}
|
||||
@@ -55,8 +55,6 @@ import lombok.Data;
|
||||
public class CloudRkService implements IEntityService<CloudRk> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(CloudRkService.class);
|
||||
|
||||
public final static String ENTERPRISE_CREDIT_REPORT = "企业征信报告";
|
||||
|
||||
public static final String KEY_PROXY = "cloud.rk.proxy";
|
||||
public static final String KEY_SYNC_ELAPSE = "cloud.rk.sync.elapse";
|
||||
public static final long DEFAULT_SYNC_ELAPSE = 36000L;
|
||||
|
||||
@@ -9,7 +9,6 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
@@ -18,6 +17,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import com.ecep.contract.util.FileUtils;
|
||||
import org.hibernate.Hibernate;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -1000,7 +1000,7 @@ public class ContractCtx extends AbstractYongYouU8Ctx {
|
||||
return false;
|
||||
}
|
||||
|
||||
String contractDirName = contract.getCode() + "-" + CompanyFileUtils.escapeFileName(contract.getName());
|
||||
String contractDirName = contract.getCode() + "-" + FileUtils.escapeFileName(contract.getName());
|
||||
File path = new File(contractPath, contractDirName);
|
||||
if (!path.exists()) {
|
||||
if (!path.mkdir()) {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package com.ecep.contract.ds;
|
||||
|
||||
import static com.ecep.contract.AppV2.DEFAULT_DB_DATABASE;
|
||||
import static com.ecep.contract.AppV2.DEFAULT_DB_HOST;
|
||||
import static com.ecep.contract.AppV2.DEFAULT_DB_PASSWORD;
|
||||
import static com.ecep.contract.AppV2.DEFAULT_DB_PORT;
|
||||
import static com.ecep.contract.AppV2.DEFAULT_DB_USERNAME;
|
||||
import static com.ecep.contract.ServerV2.DEFAULT_DB_DATABASE;
|
||||
import static com.ecep.contract.ServerV2.DEFAULT_DB_HOST;
|
||||
import static com.ecep.contract.ServerV2.DEFAULT_DB_PASSWORD;
|
||||
import static com.ecep.contract.ServerV2.DEFAULT_DB_PORT;
|
||||
import static com.ecep.contract.ServerV2.DEFAULT_DB_USERNAME;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
|
||||
@@ -6,16 +6,14 @@ import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.ecep.contract.constant.CompanyConstant;
|
||||
import com.ecep.contract.util.FileUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.ecep.contract.CompanyFileType;
|
||||
import com.ecep.contract.MyDateTimeUtils;
|
||||
import com.ecep.contract.constant.CloudServiceConstant;
|
||||
import com.ecep.contract.ds.company.service.CompanyFileService;
|
||||
import com.ecep.contract.model.CompanyFile;
|
||||
|
||||
public class CompanyFileUtils {
|
||||
@@ -79,23 +77,23 @@ public class CompanyFileUtils {
|
||||
}
|
||||
|
||||
// 营业执照
|
||||
if (fileName.contains(CompanyFileService.BUSINESS_LICENSE)) {
|
||||
if (fileName.contains(CompanyConstant.BUSINESS_LICENSE)) {
|
||||
return true;
|
||||
}
|
||||
// 操作证
|
||||
if (fileName.contains(CompanyFileService.OPERATION_CERTIFICATE)) {
|
||||
if (fileName.contains(CompanyConstant.OPERATION_CERTIFICATE)) {
|
||||
return true;
|
||||
}
|
||||
// 许可证
|
||||
if (fileName.contains(CompanyFileService.PERMIT_CERTIFICATE)) {
|
||||
if (fileName.contains(CompanyConstant.PERMIT_CERTIFICATE)) {
|
||||
return true;
|
||||
}
|
||||
// 登记证
|
||||
if (fileName.contains(CompanyFileService.REGISTRATION_CERTIFICATE)) {
|
||||
if (fileName.contains(CompanyConstant.REGISTRATION_CERTIFICATE)) {
|
||||
return true;
|
||||
}
|
||||
// 组织机构代码证
|
||||
if (fileName.contains(CompanyFileService.ORGANIZATION_CODE_CERTIFICATE)) {
|
||||
if (fileName.contains(CompanyConstant.ORGANIZATION_CODE_CERTIFICATE)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -132,45 +130,6 @@ public class CompanyFileUtils {
|
||||
return modified;
|
||||
}
|
||||
|
||||
public static boolean isHiddenFile(File file) {
|
||||
String fileName = file.getName();
|
||||
if (fileName.equals(FileUtils.FILE_DB_THUMBS)) {
|
||||
return true;
|
||||
}
|
||||
return fileName.startsWith("~$");
|
||||
}
|
||||
|
||||
public static String escapeFileName(String fileName) {
|
||||
String patternStr = "[\\\\/:*?\"<>|]";
|
||||
Pattern pattern = Pattern.compile(patternStr);
|
||||
Matcher matcher = pattern.matcher(fileName);
|
||||
return matcher.replaceAll("_");
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回 district 中关于省份的部门zi
|
||||
*
|
||||
* @param district 地区
|
||||
* @return 省份名称
|
||||
*/
|
||||
public static String getParentPrefixByDistrict(String district) {
|
||||
int indexOf = district.indexOf("省");
|
||||
if (indexOf != -1) {
|
||||
return district.substring(0, indexOf);
|
||||
}
|
||||
|
||||
indexOf = district.indexOf("自治区");
|
||||
if (indexOf != -1) {
|
||||
return district.substring(0, 2);
|
||||
}
|
||||
|
||||
indexOf = district.indexOf("市");
|
||||
if (indexOf != -1) {
|
||||
return district.substring(0, indexOf);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean exists(String path) {
|
||||
if (!StringUtils.hasText(path)) {
|
||||
return false;
|
||||
|
||||
@@ -107,7 +107,7 @@ public abstract class CompanyBasicService {
|
||||
|
||||
// 文件不存在或者隐藏文件,删除记录
|
||||
File file = new File(filePath);
|
||||
if (!file.exists() || CompanyFileUtils.isHiddenFile(file)) {
|
||||
if (!file.exists() || FileUtils.isHiddenFile(file)) {
|
||||
deleteFile(dbFile);
|
||||
continue;
|
||||
}
|
||||
@@ -235,7 +235,7 @@ public abstract class CompanyBasicService {
|
||||
List<File> step1 = new ArrayList<>();
|
||||
for (File file : files) {
|
||||
// 只处理文件
|
||||
if (!file.isFile() || CompanyFileUtils.isHiddenFile(file)) {
|
||||
if (!file.isFile() || FileUtils.isHiddenFile(file)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,16 +3,16 @@ package com.ecep.contract.ds.company.service;
|
||||
import java.io.File;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.ecep.contract.constant.CompanyConstant;
|
||||
import com.ecep.contract.util.FileUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -31,10 +31,7 @@ import com.ecep.contract.IEntityService;
|
||||
import com.ecep.contract.MyDateTimeUtils;
|
||||
import com.ecep.contract.QueryService;
|
||||
import com.ecep.contract.SpringApp;
|
||||
import com.ecep.contract.cloud.rk.CloudRkService;
|
||||
import com.ecep.contract.cloud.tyc.CloudTycService;
|
||||
import com.ecep.contract.constant.CloudServiceConstant;
|
||||
import com.ecep.contract.ds.company.CompanyFileUtils;
|
||||
import com.ecep.contract.ds.company.repository.CompanyFileRepository;
|
||||
import com.ecep.contract.ds.company.repository.CompanyFileTypeLocalRepository;
|
||||
import com.ecep.contract.ds.company.repository.CompanyOldNameRepository;
|
||||
@@ -54,12 +51,6 @@ import com.fasterxml.jackson.databind.JsonNode;
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "company-file")
|
||||
public class CompanyFileService implements IEntityService<CompanyFile>, QueryService<CompanyFile> {
|
||||
public final static String ENTERPRISE_REPORT = "企业信用报告";
|
||||
public final static String BUSINESS_LICENSE = "营业执照";
|
||||
public final static String ORGANIZATION_CODE_CERTIFICATE = "组织机构代码证";
|
||||
public final static String OPERATION_CERTIFICATE = "操作证";
|
||||
public final static String PERMIT_CERTIFICATE = "许可证";
|
||||
public final static String REGISTRATION_CERTIFICATE = "登记证";
|
||||
private static final Logger logger = LoggerFactory.getLogger(CompanyFileService.class);
|
||||
@Lazy
|
||||
@Autowired
|
||||
@@ -116,6 +107,7 @@ public class CompanyFileService implements IEntityService<CompanyFile>, QuerySer
|
||||
}
|
||||
// field
|
||||
spec = SpecificationUtils.andParam(spec, paramsNode, "company");
|
||||
spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "filePath");
|
||||
return findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@@ -315,7 +307,7 @@ public class CompanyFileService implements IEntityService<CompanyFile>, QuerySer
|
||||
}
|
||||
for (File file : files) {
|
||||
// 只处理文件
|
||||
if (!file.isFile() || CompanyFileUtils.isHiddenFile(file)) {
|
||||
if (!file.isFile() || FileUtils.isHiddenFile(file)) {
|
||||
continue;
|
||||
}
|
||||
String filePath = file.getAbsolutePath();
|
||||
@@ -369,20 +361,20 @@ public class CompanyFileService implements IEntityService<CompanyFile>, QuerySer
|
||||
|
||||
// 集团相关方平台 元素征信 企业征信报告
|
||||
if (fileName.contains(CloudServiceConstant.RK_VENDOR_NAME)
|
||||
&& fileName.contains(CloudRkService.ENTERPRISE_CREDIT_REPORT)) {
|
||||
&& fileName.contains(CloudServiceConstant.RK_ENTERPRISE_CREDIT_REPORT)) {
|
||||
companyFile.setType(CompanyFileType.CreditReport);
|
||||
fillExpiringDateAbsent(companyFile);
|
||||
return companyFile;
|
||||
}
|
||||
|
||||
// 营业执照
|
||||
if (fileName.contains(BUSINESS_LICENSE)) {
|
||||
if (fileName.contains(CompanyConstant.BUSINESS_LICENSE)) {
|
||||
companyFile.setType(CompanyFileType.BusinessLicense);
|
||||
return companyFile;
|
||||
}
|
||||
|
||||
// 其他企业信用报告
|
||||
if (fileName.contains(ENTERPRISE_REPORT)) {
|
||||
if (fileName.contains(CompanyConstant.ENTERPRISE_REPORT)) {
|
||||
companyFile.setType(CompanyFileType.CreditReport);
|
||||
fillExpiringDateAbsent(companyFile);
|
||||
return companyFile;
|
||||
@@ -449,201 +441,5 @@ public class CompanyFileService implements IEntityService<CompanyFile>, QuerySer
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 移动文件到企业目录下
|
||||
*
|
||||
* @param company 企业对象
|
||||
* @param files 要被移动的文件集合,需要从中选择需要的
|
||||
* @param status 状态输出
|
||||
*/
|
||||
public boolean retrieveFromDownloadFiles(Company company, File[] files, Consumer<String> status) {
|
||||
Map<String, File> map = new HashMap<>();
|
||||
File home = new File(company.getPath());
|
||||
map.put(company.getName(), home);
|
||||
List<CompanyFile> retrieveFiles = new ArrayList<>();
|
||||
|
||||
// 获取所有曾用名
|
||||
for (CompanyOldName companyOldName : companyOldNameRepository.findAllByCompanyId(company.getId())) {
|
||||
String name = companyOldName.getName();
|
||||
if (!StringUtils.hasText(name)) {
|
||||
continue;
|
||||
}
|
||||
File dir = null;
|
||||
String path = companyOldName.getPath();
|
||||
if (StringUtils.hasText(path)) {
|
||||
dir = new File(path);
|
||||
}
|
||||
map.put(name, dir);
|
||||
}
|
||||
|
||||
// 对所有文件进行遍历
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
File file = files[i];
|
||||
// 只处理文件
|
||||
if (!file.isFile()) {
|
||||
continue;
|
||||
}
|
||||
String prefix = (i + 1) + "/" + files.length + ":";
|
||||
Consumer<String> inner = (str) -> {
|
||||
status.accept(prefix + str);
|
||||
};
|
||||
|
||||
String fileName = file.getName();
|
||||
inner.accept(fileName);
|
||||
for (Map.Entry<String, File> entry : map.entrySet()) {
|
||||
String companyName = entry.getKey();
|
||||
// 必须要包含公司名称否则无法区分
|
||||
if (!fileName.contains(companyName)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 文件存储的目的地目录
|
||||
File dir = entry.getValue();
|
||||
if (dir == null) {
|
||||
dir = home;
|
||||
}
|
||||
|
||||
CompanyFile filled = fillDownloadFileType(company, file, companyName, dir, inner);
|
||||
if (filled != null) {
|
||||
retrieveFiles.add(filled);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
status.accept("导入 " + retrieveFiles.size() + " 个文件");
|
||||
if (retrieveFiles.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// update db
|
||||
retrieveFiles.forEach(v -> v.setCompany(company));
|
||||
companyFileRepository.saveAll(retrieveFiles);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从文件名生成公司文件对象
|
||||
* 文件从下载目录中导入
|
||||
*
|
||||
* @param company 公司对象
|
||||
* @param file 导入的文件对象
|
||||
* @param companyName 公司名称
|
||||
* @param destDir 目标目录
|
||||
* @param status 状态输出
|
||||
* @return 生成的公司文件对象,如果无法转换则返回null
|
||||
*/
|
||||
private CompanyFile fillDownloadFileType(Company company, File file, String companyName, File destDir,
|
||||
Consumer<String> status) {
|
||||
String fileName = file.getName();
|
||||
// 天眼查的报告
|
||||
// 目前只有 基础版企业信用报告, 企业信用信息公示报告下载保存时的文件名中没有天眼查
|
||||
if (CloudTycService.isTycReport(fileName)) {
|
||||
CompanyFile companyFile = new CompanyFile();
|
||||
companyFile.setType(CompanyFileType.CreditReport);
|
||||
fillApplyDateAbsent(file, companyFile);
|
||||
|
||||
String destFileName = fileName;
|
||||
// 重命名 基础版企业信用报告
|
||||
for (String report : Arrays.asList(
|
||||
CloudServiceConstant.TYC_ENTERPRISE_ANALYSIS_REPORT,
|
||||
CloudServiceConstant.TYC_ENTERPRISE_BASIC_REPORT,
|
||||
CloudServiceConstant.TYC_ENTERPRISE_MAJOR_REPORT)) {
|
||||
|
||||
if (fileName.contains(report)) {
|
||||
LocalDate applyDate = companyFile.getApplyDate();
|
||||
if (applyDate == null) {
|
||||
applyDate = LocalDate.now();
|
||||
companyFile.setApplyDate(applyDate);
|
||||
}
|
||||
String formatted = MyDateTimeUtils.format(applyDate);
|
||||
String extension = StringUtils.getFilenameExtension(fileName);
|
||||
destFileName = String.format("%s_%s_%s_%s.%s",
|
||||
companyName, CloudServiceConstant.TYC_NAME, report, formatted, extension);
|
||||
}
|
||||
}
|
||||
|
||||
// 重新设置 企业分析报告 未普通文件
|
||||
// if (fileName.contains(CloudTycService.TYC_ENTERPRISE_ANALYSIS_REPORT)) {
|
||||
// companyFile.setType(General);
|
||||
// }
|
||||
|
||||
File dest = new File(destDir, destFileName);
|
||||
// 移动文件
|
||||
if (!file.renameTo(dest)) {
|
||||
// 移动失败时
|
||||
status.accept(fileName + " 无法移动到 " + dest.getAbsolutePath());
|
||||
return null;
|
||||
}
|
||||
|
||||
status.accept(fileName + " 移动到 " + dest.getAbsolutePath());
|
||||
companyFile.setFilePath(dest.getAbsolutePath());
|
||||
|
||||
//
|
||||
if (companyFile.getExpiringDate() == null) {
|
||||
if (companyFile.getApplyDate() != null) {
|
||||
companyFile.setExpiringDate(companyFile.getApplyDate().plusYears(1));
|
||||
}
|
||||
}
|
||||
return companyFile;
|
||||
}
|
||||
|
||||
// 企业信用信息公示报告
|
||||
if (fileName.contains(CloudServiceConstant.TYC_ENTERPRISE_CREDIT_REPORT)) {
|
||||
CompanyFile companyFile = new CompanyFile();
|
||||
companyFile.setType(CompanyFileType.CreditInfoPublicityReport);
|
||||
fillApplyDateAbsent(file, companyFile);
|
||||
File dest = new File(destDir, fileName);
|
||||
|
||||
// 移动文件
|
||||
if (!file.renameTo(dest)) {
|
||||
if (dest.exists()) {
|
||||
// 尝试删除已经存在的文件
|
||||
if (!dest.delete()) {
|
||||
status.accept("覆盖时,无法删除已存在的文件 " + dest.getAbsolutePath());
|
||||
return null;
|
||||
}
|
||||
if (file.renameTo(dest)) {
|
||||
Optional<CompanyFile> one = companyFileRepository.findOne(((root, query, builder) -> {
|
||||
return builder.and(
|
||||
builder.equal(root.get("filePath"), dest.getAbsolutePath()),
|
||||
builder.equal(root.get("company"), company));
|
||||
}));
|
||||
if (one.isPresent()) {
|
||||
companyFile = one.get();
|
||||
}
|
||||
} else {
|
||||
status.accept(fileName + " 无法覆盖到 " + dest.getAbsolutePath());
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
status.accept(fileName + " 无法移动到 " + dest.getAbsolutePath());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
status.accept(fileName + " 移动到 " + dest.getAbsolutePath());
|
||||
companyFile.setFilePath(dest.getAbsolutePath());
|
||||
|
||||
return companyFile;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 当 ApplyDate 未设置时,尝试使用文件名中包含的日期
|
||||
*/
|
||||
private static void fillApplyDateAbsent(File file, CompanyFile companyFile) {
|
||||
LocalDate applyDate = companyFile.getApplyDate();
|
||||
if (applyDate != null) {
|
||||
return;
|
||||
}
|
||||
String fileName = file.getName();
|
||||
// 从文件名中提取日期
|
||||
LocalDate picked = MyDateTimeUtils.pickLocalDate(fileName);
|
||||
if (picked != null) {
|
||||
companyFile.setApplyDate(picked);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,57 @@
|
||||
package com.ecep.contract.ds.company.service;
|
||||
|
||||
public class CompanyFileTypeService {
|
||||
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.ds.company.repository.CompanyFileTypeLocalRepository;
|
||||
import com.ecep.contract.model.CompanyFileTypeLocal;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
|
||||
@Service
|
||||
public class CompanyFileTypeService
|
||||
implements IEntityService<CompanyFileTypeLocal>, QueryService<CompanyFileTypeLocal> {
|
||||
|
||||
@Resource
|
||||
private CompanyFileTypeLocalRepository companyFileTypeLocalRepository;
|
||||
|
||||
@Override
|
||||
public CompanyFileTypeLocal findById(Integer id) {
|
||||
return companyFileTypeLocalRepository.findById(id).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<CompanyFileTypeLocal> findAll(JsonNode paramsNode, Pageable pageable) {
|
||||
Specification<CompanyFileTypeLocal> spec = null;
|
||||
if (paramsNode.has("searchText")) {
|
||||
spec = getSpecification(paramsNode.get("searchText").asText());
|
||||
}
|
||||
// field
|
||||
return findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<CompanyFileTypeLocal> findAll(Specification<CompanyFileTypeLocal> spec, Pageable pageable) {
|
||||
return companyFileTypeLocalRepository.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Specification<CompanyFileTypeLocal> getSpecification(String searchText) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(CompanyFileTypeLocal entity) {
|
||||
companyFileTypeLocalRepository.delete(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompanyFileTypeLocal save(CompanyFileTypeLocal entity) {
|
||||
return companyFileTypeLocalRepository.save(entity);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import java.io.File;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
import com.ecep.contract.util.FileUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -17,7 +18,6 @@ import org.springframework.util.StringUtils;
|
||||
|
||||
import com.ecep.contract.IEntityService;
|
||||
import com.ecep.contract.QueryService;
|
||||
import com.ecep.contract.ds.company.CompanyFileUtils;
|
||||
import com.ecep.contract.ds.company.repository.CompanyOldNameRepository;
|
||||
import com.ecep.contract.model.Company;
|
||||
import com.ecep.contract.model.CompanyOldName;
|
||||
@@ -86,7 +86,7 @@ public class CompanyOldNameService implements IEntityService<CompanyOldName>, Qu
|
||||
Company company = companyService.findById(companyOldName.getCompanyId());
|
||||
String district = company.getDistrict();
|
||||
if (StringUtils.hasText(district)) {
|
||||
String parentPrefix = CompanyFileUtils.getParentPrefixByDistrict(district);
|
||||
String parentPrefix = FileUtils.getParentPrefixByDistrict(district);
|
||||
if (parentPrefix != null) {
|
||||
File parent = new File(basePath, parentPrefix);
|
||||
if (!parent.exists()) {
|
||||
@@ -94,7 +94,7 @@ public class CompanyOldNameService implements IEntityService<CompanyOldName>, Qu
|
||||
return null;
|
||||
}
|
||||
}
|
||||
String fileName = CompanyFileUtils.escapeFileName(oldName);
|
||||
String fileName = FileUtils.escapeFileName(oldName);
|
||||
File dir = new File(parent, fileName);
|
||||
if (!dir.exists()) {
|
||||
if (!dir.mkdir()) {
|
||||
|
||||
@@ -13,6 +13,8 @@ import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import com.ecep.contract.constant.CompanyConstant;
|
||||
import com.ecep.contract.util.FileUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -36,7 +38,6 @@ import com.ecep.contract.cloud.tyc.CloudTycService;
|
||||
import com.ecep.contract.cloud.u8.YongYouU8Service;
|
||||
import com.ecep.contract.constant.CompanyCustomerConstant;
|
||||
import com.ecep.contract.constant.CompanyVendorConstant;
|
||||
import com.ecep.contract.ds.company.CompanyFileUtils;
|
||||
import com.ecep.contract.ds.company.repository.CompanyRepository;
|
||||
import com.ecep.contract.ds.contract.service.ContractService;
|
||||
import com.ecep.contract.ds.customer.service.CompanyCustomerService;
|
||||
@@ -64,7 +65,6 @@ import jakarta.transaction.Transactional;
|
||||
@CacheConfig(cacheNames = "company")
|
||||
public class CompanyService implements IEntityService<Company>, QueryService<Company> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(CompanyService.class);
|
||||
private static final String COMPANY_BASE_PATH = "company.base.path";
|
||||
|
||||
@Lazy
|
||||
@Autowired
|
||||
@@ -390,7 +390,7 @@ public class CompanyService implements IEntityService<Company>, QueryService<Com
|
||||
}
|
||||
|
||||
public File getBasePath() {
|
||||
return new File(confService.getString(COMPANY_BASE_PATH));
|
||||
return new File(confService.getString(CompanyConstant.COMPANY_BASE_PATH));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -434,7 +434,7 @@ public class CompanyService implements IEntityService<Company>, QueryService<Com
|
||||
String companyName = company.getName();
|
||||
String district = company.getDistrict();
|
||||
if (StringUtils.hasText(district)) {
|
||||
String parentPrefix = CompanyFileUtils.getParentPrefixByDistrict(district);
|
||||
String parentPrefix = FileUtils.getParentPrefixByDistrict(district);
|
||||
if (parentPrefix != null) {
|
||||
File parent = new File(basePath, parentPrefix);
|
||||
if (!parent.exists()) {
|
||||
@@ -442,7 +442,7 @@ public class CompanyService implements IEntityService<Company>, QueryService<Com
|
||||
return null;
|
||||
}
|
||||
}
|
||||
String fileName = CompanyFileUtils.escapeFileName(companyName);
|
||||
String fileName = FileUtils.escapeFileName(companyName);
|
||||
File dir = new File(parent, fileName);
|
||||
if (!dir.exists()) {
|
||||
if (!dir.mkdir()) {
|
||||
@@ -455,43 +455,6 @@ public class CompanyService implements IEntityService<Company>, QueryService<Com
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 移动文件到企业目录下
|
||||
*
|
||||
* @param company 企业对象
|
||||
* @param files 要被移动的文件集合,需要从中选择需要的
|
||||
* @param status 状态输出
|
||||
*/
|
||||
public boolean retrieveFromDownloadFiles(Company company, File[] files, Consumer<String> status) {
|
||||
//
|
||||
boolean companyChanged = makePathAbsent(company);
|
||||
|
||||
if (!StringUtils.hasText(company.getPath())) {
|
||||
// fixed 要退出,需要保存
|
||||
if (companyChanged) {
|
||||
save(company);
|
||||
}
|
||||
status.accept("存储目录未设置,请检查");
|
||||
return false;
|
||||
}
|
||||
|
||||
File home = new File(company.getPath());
|
||||
if (!home.exists()) {
|
||||
// fixed 要退出,需要保存
|
||||
if (companyChanged) {
|
||||
company = save(company);
|
||||
}
|
||||
status.accept(company.getPath() + " 不存在,无法访问,请检查或者修改");
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean retrieved = companyFileService.retrieveFromDownloadFiles(company, files, status);
|
||||
if (companyChanged) {
|
||||
save(company);
|
||||
}
|
||||
return retrieved;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证企业状态
|
||||
*
|
||||
|
||||
@@ -4,6 +4,7 @@ import static com.ecep.contract.SpringApp.getBean;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import com.ecep.contract.util.FileUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.ecep.contract.MessageHolder;
|
||||
@@ -117,7 +118,7 @@ public class ContractRepairComm {
|
||||
return null;
|
||||
}
|
||||
parentDir = catalogPath;
|
||||
contractDirName = contract.getCode() + "-" + CompanyFileUtils.escapeFileName(contract.getName());
|
||||
contractDirName = contract.getCode() + "-" + FileUtils.escapeFileName(contract.getName());
|
||||
}
|
||||
|
||||
File path = new File(parentDir, contractDirName);
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.ecep.contract.ds.customer.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.ecep.contract.QueryService;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
@@ -23,7 +25,7 @@ import com.ecep.contract.util.SpecificationUtils;
|
||||
@Lazy
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "company-customer-entity")
|
||||
public class CompanyCustomerEntityService implements IEntityService<CompanyCustomerEntity> {
|
||||
public class CompanyCustomerEntityService implements IEntityService<CompanyCustomerEntity>, QueryService<CompanyCustomerEntity> {
|
||||
@Lazy
|
||||
@Autowired
|
||||
private CompanyCustomerEntityRepository repository;
|
||||
@@ -61,6 +63,17 @@ public class CompanyCustomerEntityService implements IEntityService<CompanyCusto
|
||||
return repository.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<CompanyCustomerEntity> findAll(JsonNode paramsNode, Pageable pageable) {
|
||||
Specification<CompanyCustomerEntity> spec = null;
|
||||
if (paramsNode.has("searchText")) {
|
||||
spec = getSpecification(paramsNode.get("searchText").asText());
|
||||
}
|
||||
// field
|
||||
spec = SpecificationUtils.andParam(spec, paramsNode, "customer");
|
||||
return findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Caching(evict = {
|
||||
@CacheEvict(key = "#p0.id"),
|
||||
@CacheEvict(key = "'code-'+#p0.code")
|
||||
|
||||
@@ -7,6 +7,10 @@ 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;
|
||||
@@ -30,17 +34,13 @@ 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 jakarta.persistence.criteria.Path;
|
||||
|
||||
@Lazy
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "company-customer-file")
|
||||
public class CompanyCustomerFileService implements IEntityService<CompanyCustomerFile> {
|
||||
public class CompanyCustomerFileService implements IEntityService<CompanyCustomerFile>, QueryService<CompanyCustomerFile> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(CompanyCustomerFileService.class);
|
||||
@Lazy
|
||||
@Autowired
|
||||
@@ -64,6 +64,8 @@ public class CompanyCustomerFileService implements IEntityService<CompanyCustome
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Caching(
|
||||
evict = {
|
||||
@CacheEvict(key = "#p0.id"),
|
||||
@@ -94,6 +96,18 @@ public class CompanyCustomerFileService implements IEntityService<CompanyCustome
|
||||
return companyCustomerFileRepository.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<CompanyCustomerFile> findAll(JsonNode paramsNode, Pageable pageable) {
|
||||
Specification<CompanyCustomerFile> spec = null;
|
||||
if (paramsNode.has("searchText")) {
|
||||
spec = getSpecification(paramsNode.get("searchText").asText());
|
||||
}
|
||||
// field
|
||||
spec = SpecificationUtils.andParam(spec, paramsNode, "customer");
|
||||
// spec = SpecificationUtils.andParam(spec, paramsNode, "company");
|
||||
return findAll(spec, pageable);
|
||||
}
|
||||
|
||||
public List<CompanyCustomerFile> findAllByCustomer(CompanyCustomer customer) {
|
||||
return companyCustomerFileRepository.findAllByCustomer(customer);
|
||||
}
|
||||
@@ -249,4 +263,5 @@ public class CompanyCustomerFileService implements IEntityService<CompanyCustome
|
||||
return companyCustomerEvaluationFormFileRepository.findAll(spec, Pageable.ofSize(10)).getContent();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -11,7 +11,9 @@ import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
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.util.CompanyUtils;
|
||||
import com.ecep.contract.util.FileUtils;
|
||||
import org.hibernate.Hibernate;
|
||||
@@ -31,19 +33,11 @@ import org.springframework.util.StringUtils;
|
||||
|
||||
import com.ecep.contract.CompanyCustomerFileType;
|
||||
import com.ecep.contract.IEntityService;
|
||||
import com.ecep.contract.ds.company.CompanyFileUtils;
|
||||
import com.ecep.contract.ds.company.service.CompanyBasicService;
|
||||
import com.ecep.contract.ds.customer.repository.CompanyCustomerEvaluationFormFileRepository;
|
||||
import com.ecep.contract.ds.customer.repository.CompanyCustomerRepository;
|
||||
import com.ecep.contract.ds.customer.repository.CustomerCatalogRepository;
|
||||
import com.ecep.contract.ds.other.service.SysConfService;
|
||||
import com.ecep.contract.model.Company;
|
||||
import com.ecep.contract.model.CompanyBasicFile;
|
||||
import com.ecep.contract.model.CompanyCustomer;
|
||||
import com.ecep.contract.model.CompanyCustomerEntity;
|
||||
import com.ecep.contract.model.CompanyCustomerEvaluationFormFile;
|
||||
import com.ecep.contract.model.CompanyCustomerFile;
|
||||
import com.ecep.contract.model.CustomerCatalog;
|
||||
import com.ecep.contract.util.MyStringUtils;
|
||||
import com.ecep.contract.util.SpecificationUtils;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
@@ -56,7 +50,7 @@ import jakarta.persistence.criteria.Path;
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "company-customer")
|
||||
public class CompanyCustomerService extends CompanyBasicService
|
||||
implements IEntityService<CompanyCustomer> {
|
||||
implements IEntityService<CompanyCustomer>, QueryService<CompanyCustomer> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(CompanyCustomerService.class);
|
||||
|
||||
@Lazy
|
||||
@@ -189,7 +183,7 @@ public class CompanyCustomerService extends CompanyBasicService
|
||||
|
||||
@Override
|
||||
protected <T, F extends CompanyBasicFile<T>> boolean fillFileAsDefaultType(F dbFile, File file,
|
||||
Consumer<String> status) {
|
||||
Consumer<String> status) {
|
||||
dbFile.setType((T) CompanyCustomerFileType.General);
|
||||
fillFile(dbFile, file, null, status);
|
||||
companyCustomerFileService.save((CompanyCustomerFile) dbFile);
|
||||
@@ -198,7 +192,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) {
|
||||
@@ -232,7 +226,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()) {
|
||||
@@ -258,7 +252,7 @@ public class CompanyCustomerService extends CompanyBasicService
|
||||
|
||||
@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(CompanyCustomerFileType.General);
|
||||
if (fillFile(customerFile, file, fileList, status)) {
|
||||
@@ -281,7 +275,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) {
|
||||
@@ -313,7 +307,7 @@ public class CompanyCustomerService extends CompanyBasicService
|
||||
|
||||
String companyName = company.getName();
|
||||
String fileName = CompanyUtils.formatCompanyVendorId(companyCustomer.getId()) + "-"
|
||||
+ CompanyFileUtils.escapeFileName(companyName);
|
||||
+ FileUtils.escapeFileName(companyName);
|
||||
|
||||
File dir = new File(basePath, fileName);
|
||||
if (!dir.exists()) {
|
||||
@@ -328,6 +322,17 @@ public class CompanyCustomerService extends CompanyBasicService
|
||||
return companyCustomerRepository.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<CompanyCustomer> findAll(JsonNode paramsNode, Pageable pageable) {
|
||||
Specification<CompanyCustomer> spec = null;
|
||||
if (paramsNode.has("searchText")) {
|
||||
spec = getSpecification(paramsNode.get("searchText").asText());
|
||||
}
|
||||
// field
|
||||
spec = SpecificationUtils.andParam(spec, paramsNode, "company");
|
||||
return findAll(spec, pageable);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将一个公司的客户信息转移到另一个公司,并保存在数据库中
|
||||
*
|
||||
@@ -357,7 +362,7 @@ public class CompanyCustomerService extends CompanyBasicService
|
||||
|
||||
/***
|
||||
* 合并两个CompanyCustomer对象,并将fromCustomer的信息合并到toCustomer中,并保存到数据库中。
|
||||
*
|
||||
*
|
||||
* @param from 源客户对象
|
||||
* @param to 目标客户对象
|
||||
*/
|
||||
@@ -403,4 +408,6 @@ public class CompanyCustomerService extends CompanyBasicService
|
||||
public CustomerCatalog save(CustomerCatalog catalog) {
|
||||
return customerCatalogRepository.save(catalog);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -12,13 +12,15 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.ecep.contract.IEntityService;
|
||||
import com.ecep.contract.QueryService;
|
||||
import com.ecep.contract.ds.other.repository.BankRepository;
|
||||
import com.ecep.contract.model.Bank;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
|
||||
@Lazy
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "bank")
|
||||
public class BankService implements IEntityService<Bank> {
|
||||
public class BankService implements IEntityService<Bank>, QueryService<Bank> {
|
||||
@Lazy
|
||||
@Autowired
|
||||
private BankRepository bankRepository;
|
||||
@@ -31,6 +33,16 @@ public class BankService implements IEntityService<Bank> {
|
||||
return bankRepository.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<Bank> findAll(JsonNode paramsNode, Pageable pageable) {
|
||||
Specification<Bank> spec = null;
|
||||
if (paramsNode.has("searchText")) {
|
||||
spec = getSpecification(paramsNode.get("searchText").asText());
|
||||
}
|
||||
// 可以根据需要添加更多参数处理
|
||||
return findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Specification<Bank> getSpecification(String searchText) {
|
||||
if (!StringUtils.hasText(searchText)) {
|
||||
|
||||
@@ -15,8 +15,10 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.ecep.contract.IEntityService;
|
||||
import com.ecep.contract.QueryService;
|
||||
import com.ecep.contract.ds.other.repository.DepartmentRepository;
|
||||
import com.ecep.contract.model.Department;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
|
||||
/**
|
||||
* 部门
|
||||
@@ -24,7 +26,7 @@ import com.ecep.contract.model.Department;
|
||||
@Lazy
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "department")
|
||||
public class DepartmentService implements IEntityService<Department> {
|
||||
public class DepartmentService implements IEntityService<Department>, QueryService<Department> {
|
||||
@Lazy
|
||||
@Autowired
|
||||
private DepartmentRepository repository;
|
||||
@@ -45,6 +47,16 @@ public class DepartmentService implements IEntityService<Department> {
|
||||
return repository.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<Department> findAll(JsonNode paramsNode, Pageable pageable) {
|
||||
Specification<Department> spec = null;
|
||||
if (paramsNode.has("searchText")) {
|
||||
spec = getSpecification(paramsNode.get("searchText").asText());
|
||||
}
|
||||
// 可以根据需要添加更多参数处理
|
||||
return findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Specification<Department> getSpecification(String searchText) {
|
||||
if (!StringUtils.hasText(searchText)) {
|
||||
@@ -54,8 +66,7 @@ public class DepartmentService implements IEntityService<Department> {
|
||||
// 使用或条件组合查询,以实现对员工代码或名称的模糊搜索
|
||||
return builder.or(
|
||||
builder.like(root.get("code"), "%" + searchText + "%"),
|
||||
builder.like(root.get("name"), "%" + searchText + "%")
|
||||
);
|
||||
builder.like(root.get("name"), "%" + searchText + "%"));
|
||||
};
|
||||
}
|
||||
|
||||
@@ -64,23 +75,19 @@ public class DepartmentService implements IEntityService<Department> {
|
||||
return repository.findAll(spec, Pageable.ofSize(10)).getContent();
|
||||
}
|
||||
|
||||
@Caching(
|
||||
evict = {
|
||||
@CacheEvict(key = "#p0.id"),
|
||||
@CacheEvict(key = "'code-'+#p0.code")
|
||||
}
|
||||
)
|
||||
@Caching(evict = {
|
||||
@CacheEvict(key = "#p0.id"),
|
||||
@CacheEvict(key = "'code-'+#p0.code")
|
||||
})
|
||||
@Override
|
||||
public void delete(Department entity) {
|
||||
repository.delete(entity);
|
||||
}
|
||||
|
||||
@Caching(
|
||||
evict = {
|
||||
@CacheEvict(key = "#p0.id"),
|
||||
@CacheEvict(key = "'code-'+#p0.code")
|
||||
}
|
||||
)
|
||||
@Caching(evict = {
|
||||
@CacheEvict(key = "#p0.id"),
|
||||
@CacheEvict(key = "'code-'+#p0.code")
|
||||
})
|
||||
@Override
|
||||
public Department save(Department entity) {
|
||||
return repository.save(entity);
|
||||
|
||||
@@ -13,14 +13,16 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.ecep.contract.IEntityService;
|
||||
import com.ecep.contract.QueryService;
|
||||
import com.ecep.contract.ds.other.repository.EmployeeAuthBindRepository;
|
||||
import com.ecep.contract.model.Employee;
|
||||
import com.ecep.contract.model.EmployeeAuthBind;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
|
||||
@Lazy
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "employee-auth-bind")
|
||||
public class EmployeeAuthBindService implements IEntityService<EmployeeAuthBind> {
|
||||
public class EmployeeAuthBindService implements IEntityService<EmployeeAuthBind>, QueryService<EmployeeAuthBind> {
|
||||
@Lazy
|
||||
@Autowired
|
||||
private EmployeeAuthBindRepository repository;
|
||||
@@ -39,8 +41,7 @@ public class EmployeeAuthBindService implements IEntityService<EmployeeAuthBind>
|
||||
return builder.or(
|
||||
builder.like(root.get("ip"), "%" + searchText + "%"),
|
||||
builder.like(root.get("mac"), "%" + searchText + "%"),
|
||||
builder.like(root.get("description"), "%" + searchText + "%")
|
||||
);
|
||||
builder.like(root.get("description"), "%" + searchText + "%"));
|
||||
};
|
||||
}
|
||||
|
||||
@@ -49,6 +50,16 @@ public class EmployeeAuthBindService implements IEntityService<EmployeeAuthBind>
|
||||
return repository.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<EmployeeAuthBind> findAll(JsonNode paramsNode, Pageable pageable) {
|
||||
Specification<EmployeeAuthBind> spec = null;
|
||||
if (paramsNode.has("searchText")) {
|
||||
spec = getSpecification(paramsNode.get("searchText").asText());
|
||||
}
|
||||
// 可以根据需要添加更多参数处理
|
||||
return findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(EmployeeAuthBind entity) {
|
||||
repository.delete(entity);
|
||||
|
||||
@@ -10,13 +10,17 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.ecep.contract.IEntityService;
|
||||
import com.ecep.contract.QueryService;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.ecep.contract.ds.other.repository.EmployeeLoginHistoryRepository;
|
||||
import com.ecep.contract.model.EmployeeLoginHistory;
|
||||
import com.ecep.contract.util.SpecificationUtils;
|
||||
|
||||
@Lazy
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "employee-login-history")
|
||||
public class EmployeeLoginHistoryService implements IEntityService<EmployeeLoginHistory> {
|
||||
public class EmployeeLoginHistoryService
|
||||
implements IEntityService<EmployeeLoginHistory>, QueryService<EmployeeLoginHistory> {
|
||||
@Lazy
|
||||
@Autowired
|
||||
private EmployeeLoginHistoryRepository repository;
|
||||
@@ -34,8 +38,7 @@ public class EmployeeLoginHistoryService implements IEntityService<EmployeeLogin
|
||||
return (root, query, builder) -> {
|
||||
return builder.or(
|
||||
builder.like(root.get("ip"), "%" + searchText + "%"),
|
||||
builder.like(root.get("mac"), "%" + searchText + "%")
|
||||
);
|
||||
builder.like(root.get("mac"), "%" + searchText + "%"));
|
||||
};
|
||||
}
|
||||
|
||||
@@ -44,6 +47,18 @@ public class EmployeeLoginHistoryService implements IEntityService<EmployeeLogin
|
||||
return repository.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<EmployeeLoginHistory> findAll(JsonNode paramsNode, Pageable pageable) {
|
||||
Specification<EmployeeLoginHistory> spec = null;
|
||||
if (paramsNode.has("searchText")) {
|
||||
spec = getSpecification(paramsNode.get("searchText").asText());
|
||||
}
|
||||
// 可以根据需要添加更多参数处理
|
||||
spec = SpecificationUtils.andParam(spec, paramsNode, "employee");
|
||||
spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "ip", "mac");
|
||||
return findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(EmployeeLoginHistory entity) {
|
||||
repository.delete(entity);
|
||||
|
||||
@@ -16,6 +16,8 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.ecep.contract.IEntityService;
|
||||
import com.ecep.contract.QueryService;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.ecep.contract.ds.other.repository.EmployeeRoleRepository;
|
||||
import com.ecep.contract.model.EmployeeRole;
|
||||
import com.ecep.contract.model.Function;
|
||||
@@ -27,7 +29,7 @@ import jakarta.transaction.Transactional;
|
||||
*/
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "employee-role")
|
||||
public class EmployeeRoleService implements IEntityService<EmployeeRole> {
|
||||
public class EmployeeRoleService implements IEntityService<EmployeeRole>, QueryService<EmployeeRole> {
|
||||
@Lazy
|
||||
@Autowired
|
||||
private EmployeeRoleRepository roleRepository;
|
||||
@@ -70,10 +72,21 @@ public class EmployeeRoleService implements IEntityService<EmployeeRole> {
|
||||
roleRepository.delete(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<EmployeeRole> findAll(Specification<EmployeeRole> spec, Pageable pageable) {
|
||||
return roleRepository.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<EmployeeRole> findAll(JsonNode paramsNode, Pageable pageable) {
|
||||
Specification<EmployeeRole> spec = null;
|
||||
if (paramsNode.has("searchText")) {
|
||||
spec = getSpecification(paramsNode.get("searchText").asText());
|
||||
}
|
||||
// 可以根据需要添加更多参数处理
|
||||
return findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public List<Function> getFunctionsByRoleId(int roleId) {
|
||||
Optional<EmployeeRole> optional = roleRepository.findById(roleId);
|
||||
|
||||
@@ -18,6 +18,8 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.ecep.contract.IEntityService;
|
||||
import com.ecep.contract.QueryService;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.ecep.contract.ds.other.repository.EmployeeRepository;
|
||||
import com.ecep.contract.model.Employee;
|
||||
import com.ecep.contract.model.EmployeeRole;
|
||||
@@ -30,7 +32,7 @@ import jakarta.transaction.Transactional;
|
||||
@Lazy
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "employee")
|
||||
public class EmployeeService implements IEntityService<Employee> {
|
||||
public class EmployeeService implements IEntityService<Employee>, QueryService<Employee> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(EmployeeService.class);
|
||||
public static final int DEFAULT_SYSTEM_EMPLOYEE_ID = 26;
|
||||
@Lazy
|
||||
@@ -105,10 +107,21 @@ public class EmployeeService implements IEntityService<Employee> {
|
||||
employeeRepository.delete(employee);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<Employee> findAll(Specification<Employee> spec, Pageable pageable) {
|
||||
return employeeRepository.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<Employee> findAll(JsonNode paramsNode, Pageable pageable) {
|
||||
Specification<Employee> spec = null;
|
||||
if (paramsNode.has("searchText")) {
|
||||
spec = getSpecification(paramsNode.get("searchText").asText());
|
||||
}
|
||||
// 可以根据需要添加更多参数处理
|
||||
return findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Specification<Employee> getSpecification(String searchText) {
|
||||
if (!StringUtils.hasText(searchText)) {
|
||||
|
||||
@@ -13,13 +13,15 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.ecep.contract.IEntityService;
|
||||
import com.ecep.contract.QueryService;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.ecep.contract.ds.other.repository.FunctionRepository;
|
||||
import com.ecep.contract.model.Function;
|
||||
|
||||
@Lazy
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "function")
|
||||
public class FunctionService implements IEntityService<Function> {
|
||||
public class FunctionService implements IEntityService<Function>, QueryService<Function> {
|
||||
@Lazy
|
||||
@Autowired
|
||||
private FunctionRepository repository;
|
||||
@@ -47,10 +49,21 @@ public class FunctionService implements IEntityService<Function> {
|
||||
repository.delete(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<Function> findAll(Specification<Function> spec, Pageable pageable) {
|
||||
return repository.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<Function> findAll(JsonNode paramsNode, Pageable pageable) {
|
||||
Specification<Function> spec = null;
|
||||
if (paramsNode.has("searchText")) {
|
||||
spec = getSpecification(paramsNode.get("searchText").asText());
|
||||
}
|
||||
// 可以根据需要添加更多参数处理
|
||||
return findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Specification<Function> getSpecification(String searchText) {
|
||||
if (!StringUtils.hasText(searchText)) {
|
||||
|
||||
@@ -12,14 +12,17 @@ import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.ecep.contract.QueryService;
|
||||
import com.ecep.contract.ds.other.repository.InventoryCatalogRepository;
|
||||
import com.ecep.contract.model.InventoryCatalog;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
|
||||
@Lazy
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "inventory-catalog")
|
||||
public class InventoryCatalogService {
|
||||
public class InventoryCatalogService implements QueryService<InventoryCatalog> {
|
||||
@Lazy
|
||||
@Autowired
|
||||
private InventoryCatalogRepository repository;
|
||||
@@ -29,7 +32,6 @@ public class InventoryCatalogService {
|
||||
return repository.findById(id).orElse(null);
|
||||
}
|
||||
|
||||
|
||||
@Cacheable(key = "'code-'+#p0")
|
||||
public InventoryCatalog findByCode(String code) {
|
||||
return repository.findByCode(code).orElse(null);
|
||||
@@ -40,17 +42,38 @@ public class InventoryCatalogService {
|
||||
return repository.findByName(name).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<InventoryCatalog> findAll(Specification<InventoryCatalog> spec, Pageable pageable) {
|
||||
return repository.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Caching(
|
||||
evict = {
|
||||
@CacheEvict(key = "#p0.id"),
|
||||
@CacheEvict(key = "'code-'+#p0.code"),
|
||||
@CacheEvict(key = "'name-'+#p0.code")
|
||||
}
|
||||
)
|
||||
@Override
|
||||
public Page<InventoryCatalog> findAll(JsonNode paramsNode, Pageable pageable) {
|
||||
Specification<InventoryCatalog> spec = null;
|
||||
if (paramsNode.has("searchText")) {
|
||||
spec = getSpecification(paramsNode.get("searchText").asText());
|
||||
}
|
||||
// 可以根据需要添加更多参数处理
|
||||
return findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Specification<InventoryCatalog> getSpecification(String searchText) {
|
||||
if (!StringUtils.hasText(searchText)) {
|
||||
return null;
|
||||
}
|
||||
return (root, query, builder) -> {
|
||||
return builder.or(
|
||||
builder.like(root.get("code"), "%" + searchText + "%"),
|
||||
builder.like(root.get("name"), "%" + searchText + "%"));
|
||||
};
|
||||
}
|
||||
|
||||
@Caching(evict = {
|
||||
@CacheEvict(key = "#p0.id"),
|
||||
@CacheEvict(key = "'code-'+#p0.code"),
|
||||
@CacheEvict(key = "'name-'+#p0.code")
|
||||
})
|
||||
public InventoryCatalog save(InventoryCatalog entity) {
|
||||
return repository.save(entity);
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.ecep.contract.IEntityService;
|
||||
import com.ecep.contract.QueryService;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.ecep.contract.ds.other.repository.InventoryHistoryPriceRepository;
|
||||
import com.ecep.contract.model.Inventory;
|
||||
import com.ecep.contract.model.InventoryHistoryPrice;
|
||||
@@ -21,7 +23,8 @@ import jakarta.persistence.criteria.Path;
|
||||
@Lazy
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "inventory-history-price")
|
||||
public class InventoryHistoryPriceService implements IEntityService<InventoryHistoryPrice> {
|
||||
public class InventoryHistoryPriceService
|
||||
implements IEntityService<InventoryHistoryPrice>, QueryService<InventoryHistoryPrice> {
|
||||
@Lazy
|
||||
@Autowired
|
||||
InventoryHistoryPriceRepository repository;
|
||||
@@ -40,8 +43,7 @@ public class InventoryHistoryPriceService implements IEntityService<InventoryHis
|
||||
Path<Inventory> inventory = root.get("inventory");
|
||||
return builder.or(
|
||||
builder.like(inventory.get("name"), "%" + searchText + "%"),
|
||||
builder.like(inventory.get("specification"), "%" + searchText + "%")
|
||||
);
|
||||
builder.like(inventory.get("specification"), "%" + searchText + "%"));
|
||||
};
|
||||
}
|
||||
|
||||
@@ -50,6 +52,15 @@ public class InventoryHistoryPriceService implements IEntityService<InventoryHis
|
||||
return repository.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<InventoryHistoryPrice> findAll(JsonNode paramsNode, Pageable pageable) {
|
||||
Specification<InventoryHistoryPrice> spec = null;
|
||||
if (paramsNode.has("searchText")) {
|
||||
spec = getSpecification(paramsNode.get("searchText").asText());
|
||||
}
|
||||
// 可以根据需要添加更多参数处理
|
||||
return findAll(spec, pageable);
|
||||
}
|
||||
|
||||
public List<InventoryHistoryPrice> findAllByInventory(Inventory inventory) {
|
||||
return repository.findAllByInventory(inventory);
|
||||
|
||||
@@ -17,9 +17,11 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.ecep.contract.IEntityService;
|
||||
import com.ecep.contract.QueryService;
|
||||
import com.ecep.contract.ds.other.repository.InventoryRepository;
|
||||
import com.ecep.contract.model.Inventory;
|
||||
import com.ecep.contract.util.SpecificationUtils;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
|
||||
import jakarta.persistence.criteria.Join;
|
||||
import jakarta.persistence.criteria.JoinType;
|
||||
@@ -29,7 +31,7 @@ import lombok.Setter;
|
||||
@Lazy
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "inventory")
|
||||
public class InventoryService implements IEntityService<Inventory> {
|
||||
public class InventoryService implements IEntityService<Inventory>, QueryService<Inventory> {
|
||||
@Lazy
|
||||
@Autowired
|
||||
private InventoryRepository inventoryRepository;
|
||||
@@ -42,10 +44,21 @@ public class InventoryService implements IEntityService<Inventory> {
|
||||
return inventoryRepository.findById(id).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<Inventory> findAll(Specification<Inventory> spec, Pageable pageable) {
|
||||
return inventoryRepository.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<Inventory> findAll(JsonNode paramsNode, Pageable pageable) {
|
||||
Specification<Inventory> spec = null;
|
||||
if (paramsNode.has("searchText")) {
|
||||
spec = getSpecification(paramsNode.get("searchText").asText());
|
||||
}
|
||||
// 可以根据需要添加更多参数处理
|
||||
return findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Specification<Inventory> getSpecification(String searchText) {
|
||||
if (!StringUtils.hasText(searchText)) {
|
||||
|
||||
@@ -15,13 +15,15 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.ecep.contract.IEntityService;
|
||||
import com.ecep.contract.QueryService;
|
||||
import com.ecep.contract.ds.other.repository.PermissionRepository;
|
||||
import com.ecep.contract.model.Permission;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
|
||||
@Lazy
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "permission")
|
||||
public class PermissionService implements IEntityService<Permission> {
|
||||
public class PermissionService implements IEntityService<Permission>, QueryService<Permission> {
|
||||
|
||||
@Lazy
|
||||
@Autowired
|
||||
@@ -59,10 +61,21 @@ public class PermissionService implements IEntityService<Permission> {
|
||||
return permissionRepository.save(role);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<Permission> findAll(Specification<Permission> spec, Pageable pageable) {
|
||||
return permissionRepository.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<Permission> findAll(JsonNode paramsNode, Pageable pageable) {
|
||||
Specification<Permission> spec = null;
|
||||
if (paramsNode.has("searchText")) {
|
||||
spec = getSpecification(paramsNode.get("searchText").asText());
|
||||
}
|
||||
// 可以根据需要添加更多参数处理
|
||||
return findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Permission entity) {
|
||||
permissionRepository.delete(entity);
|
||||
|
||||
@@ -21,11 +21,24 @@ public class CompanyVendorApprovedFileService implements IEntityService<CompanyV
|
||||
@Autowired
|
||||
private CompanyVendorApprovedFileRepository repository;
|
||||
|
||||
/**
|
||||
* 根据ID查找供应商已批准文件
|
||||
*
|
||||
* @param id 文件ID
|
||||
* @return 找到的文件实体,如果不存在则返回null
|
||||
*/
|
||||
@Override
|
||||
public CompanyVendorApprovedFile findById(Integer id) {
|
||||
return repository.findById(id).orElse(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取供应商已批准文件的查询规格
|
||||
* 根据搜索文本构建文件名和描述的模糊查询条件
|
||||
*
|
||||
* @param searchText 搜索文本
|
||||
* @return 构建的查询规格
|
||||
*/
|
||||
@Override
|
||||
public Specification<CompanyVendorApprovedFile> getSpecification(String searchText) {
|
||||
return (root, query, builder) -> {
|
||||
@@ -36,26 +49,57 @@ public class CompanyVendorApprovedFileService implements IEntityService<CompanyV
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据查询规格和分页参数获取供应商已批准文件列表
|
||||
*
|
||||
* @param spec 查询规格
|
||||
* @param pageable 分页参数
|
||||
* @return 分页的文件列表
|
||||
*/
|
||||
@Override
|
||||
public Page<CompanyVendorApprovedFile> findAll(Specification<CompanyVendorApprovedFile> spec, Pageable pageable) {
|
||||
return repository.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除供应商已批准文件
|
||||
*
|
||||
* @param entity 要删除的文件实体
|
||||
*/
|
||||
@Override
|
||||
public void delete(CompanyVendorApprovedFile entity) {
|
||||
repository.delete(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存或更新供应商已批准文件
|
||||
*
|
||||
* @param entity 要保存的文件实体
|
||||
* @return 保存后的文件实体
|
||||
*/
|
||||
@Override
|
||||
public CompanyVendorApprovedFile save(CompanyVendorApprovedFile entity) {
|
||||
return repository.save(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据已批准列表和文件名查找特定文件
|
||||
*
|
||||
* @param approvedList 已批准列表
|
||||
* @param name 文件名
|
||||
* @return 找到的文件实体
|
||||
*/
|
||||
public CompanyVendorApprovedFile findByName(CompanyVendorApprovedList approvedList, String name) {
|
||||
return repository.findByListIdAndFileName(approvedList.getId(), name);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定已批准列表下的所有文件
|
||||
*
|
||||
* @param list 已批准列表实体
|
||||
* @return 该列表下的所有文件列表
|
||||
*/
|
||||
public List<CompanyVendorApprovedFile> findAllByList(CompanyVendorApprovedList list) {
|
||||
return repository.findAllByListId(list.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,9 @@ package com.ecep.contract.ds.vendor.service;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.ecep.contract.QueryService;
|
||||
import com.ecep.contract.util.SpecificationUtils;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.data.domain.Page;
|
||||
@@ -25,7 +28,7 @@ import jakarta.persistence.criteria.Predicate;
|
||||
|
||||
@Lazy
|
||||
@Service
|
||||
public class CompanyVendorApprovedItemService implements IEntityService<CompanyVendorApprovedItem> {
|
||||
public class CompanyVendorApprovedItemService implements IEntityService<CompanyVendorApprovedItem>, QueryService<CompanyVendorApprovedItem> {
|
||||
@Lazy
|
||||
@Autowired
|
||||
private CompanyVendorApprovedItemRepository repository;
|
||||
@@ -81,6 +84,17 @@ public class CompanyVendorApprovedItemService implements IEntityService<CompanyV
|
||||
return repository.findAll(spec, sort);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<CompanyVendorApprovedItem> findAll(JsonNode paramsNode, Pageable pageable) {
|
||||
Specification<CompanyVendorApprovedItem> spec = null;
|
||||
if (paramsNode.has("searchText")) {
|
||||
spec = getSpecification(paramsNode.get("searchText").asText());
|
||||
}
|
||||
// 添加额外的参数过滤
|
||||
spec = SpecificationUtils.andParam(spec, paramsNode, "vendor", "list");
|
||||
return findAll(spec, pageable);
|
||||
}
|
||||
|
||||
public List<CompanyVendorApprovedItem> findAllByListAndVendor(CompanyVendorApprovedList approvedList, CompanyVendor vendor) {
|
||||
return repository.findAllByListAndVendor(approvedList, vendor);
|
||||
}
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
package com.ecep.contract.ds.vendor.service;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import com.ecep.contract.IEntityService;
|
||||
import com.ecep.contract.MyDateTimeUtils;
|
||||
import com.ecep.contract.QueryService;
|
||||
import com.ecep.contract.constant.CompanyVendorConstant;
|
||||
import com.ecep.contract.ds.other.service.SysConfService;
|
||||
import com.ecep.contract.ds.vendor.repository.CompanyVendorApprovedListRepository;
|
||||
import com.ecep.contract.model.CompanyVendorApprovedFile;
|
||||
import com.ecep.contract.model.CompanyVendorApprovedList;
|
||||
import com.ecep.contract.util.FileUtils;
|
||||
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;
|
||||
@@ -19,19 +23,17 @@ import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.ecep.contract.IEntityService;
|
||||
import com.ecep.contract.MyDateTimeUtils;
|
||||
import com.ecep.contract.constant.CompanyVendorConstant;
|
||||
import com.ecep.contract.ds.company.CompanyFileUtils;
|
||||
import com.ecep.contract.ds.other.service.SysConfService;
|
||||
import com.ecep.contract.ds.vendor.repository.CompanyVendorApprovedListRepository;
|
||||
import com.ecep.contract.model.CompanyVendorApprovedFile;
|
||||
import com.ecep.contract.model.CompanyVendorApprovedList;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
|
||||
@Lazy
|
||||
@Service
|
||||
public class CompanyVendorApprovedListService implements IEntityService<CompanyVendorApprovedList> {
|
||||
public class CompanyVendorApprovedListService implements IEntityService<CompanyVendorApprovedList>, QueryService<CompanyVendorApprovedList> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(CompanyVendorApprovedListService.class);
|
||||
@Lazy
|
||||
@Autowired
|
||||
@@ -61,6 +63,17 @@ public class CompanyVendorApprovedListService implements IEntityService<CompanyV
|
||||
return repository.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<CompanyVendorApprovedList> findAll(JsonNode paramsNode, Pageable pageable) {
|
||||
Specification<CompanyVendorApprovedList> spec = null;
|
||||
if (paramsNode.has("searchText")) {
|
||||
spec = getSpecification(paramsNode.get("searchText").asText());
|
||||
}
|
||||
// 添加额外的参数过滤
|
||||
spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "title");
|
||||
return findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Specification<CompanyVendorApprovedList> getSpecification(String searchText) {
|
||||
if (!StringUtils.hasText(searchText)) {
|
||||
@@ -111,7 +124,7 @@ public class CompanyVendorApprovedListService implements IEntityService<CompanyV
|
||||
return null;
|
||||
}
|
||||
String title = list.getTitle();
|
||||
String fileName = CompanyFileUtils.escapeFileName(title);
|
||||
String fileName = FileUtils.escapeFileName(title);
|
||||
File dir = new File(basePath, fileName);
|
||||
if (!dir.exists()) {
|
||||
if (!dir.mkdir()) {
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.ecep.contract.ds.vendor.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.ecep.contract.QueryService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
@@ -19,11 +20,12 @@ import com.ecep.contract.ds.vendor.repository.CompanyVendorEntityRepository;
|
||||
import com.ecep.contract.model.CompanyVendor;
|
||||
import com.ecep.contract.model.CompanyVendorEntity;
|
||||
import com.ecep.contract.util.SpecificationUtils;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
|
||||
@Lazy
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "company-vendor-entity")
|
||||
public class CompanyVendorEntityService implements IEntityService<CompanyVendorEntity> {
|
||||
public class CompanyVendorEntityService implements IEntityService<CompanyVendorEntity>, QueryService<CompanyVendorEntity> {
|
||||
@Lazy
|
||||
@Autowired
|
||||
private CompanyVendorEntityRepository repository;
|
||||
@@ -74,6 +76,17 @@ public class CompanyVendorEntityService implements IEntityService<CompanyVendorE
|
||||
return repository.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<CompanyVendorEntity> findAll(JsonNode paramsNode, Pageable pageable) {
|
||||
Specification<CompanyVendorEntity> spec = null;
|
||||
if (paramsNode.has("searchText")) {
|
||||
spec = getSpecification(paramsNode.get("searchText").asText());
|
||||
}
|
||||
// 添加额外的参数过滤
|
||||
spec = SpecificationUtils.andParam(spec, paramsNode, "vendor");
|
||||
return findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Caching(
|
||||
evict = {
|
||||
@CacheEvict(key = "#p0.id"),
|
||||
@@ -99,4 +112,4 @@ public class CompanyVendorEntityService implements IEntityService<CompanyVendorE
|
||||
public List<CompanyVendorEntity> findAllByVendor(CompanyVendor vendor) {
|
||||
return repository.findByVendor(vendor);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,10 @@ import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import com.ecep.contract.*;
|
||||
import com.ecep.contract.model.CompanyVendorApprovedList;
|
||||
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;
|
||||
@@ -16,11 +20,6 @@ import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.ecep.contract.CompanyVendorFileType;
|
||||
import com.ecep.contract.IEntityService;
|
||||
import com.ecep.contract.MessageHolder;
|
||||
import com.ecep.contract.MyDateTimeUtils;
|
||||
import com.ecep.contract.SpringApp;
|
||||
import com.ecep.contract.ds.company.service.CompanyBasicService;
|
||||
import com.ecep.contract.ds.contract.service.ContractFileService;
|
||||
import com.ecep.contract.ds.contract.service.ContractService;
|
||||
@@ -32,7 +31,9 @@ import com.ecep.contract.model.Contract;
|
||||
|
||||
@Lazy
|
||||
@Service
|
||||
public class CompanyVendorFileService implements IEntityService<CompanyVendorFile> {
|
||||
public class CompanyVendorFileService implements IEntityService<CompanyVendorFile>, QueryService<CompanyVendorFile> {
|
||||
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(CompanyVendorFileService.class);
|
||||
|
||||
@Autowired
|
||||
@@ -56,6 +57,18 @@ public class CompanyVendorFileService implements IEntityService<CompanyVendorFil
|
||||
return repository.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<CompanyVendorFile> findAll(JsonNode paramsNode, Pageable pageable) {
|
||||
Specification<CompanyVendorFile> spec = null;
|
||||
if (paramsNode.has("searchText")) {
|
||||
spec = getSpecification(paramsNode.get("searchText").asText());
|
||||
}
|
||||
// 添加额外的参数过滤
|
||||
spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "valid");
|
||||
spec = SpecificationUtils.andParam(spec, paramsNode, "vendor");
|
||||
return findAll(spec, pageable);
|
||||
}
|
||||
|
||||
public List<CompanyVendorFile> findAllByVendor(CompanyVendor companyVendor) {
|
||||
return repository.findAllByVendorId(companyVendor.getId());
|
||||
}
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
package com.ecep.contract.ds.vendor.service;
|
||||
|
||||
import java.io.File;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.ecep.contract.*;
|
||||
import com.ecep.contract.constant.CompanyVendorConstant;
|
||||
import com.ecep.contract.ds.company.service.CompanyBasicService;
|
||||
import com.ecep.contract.ds.other.service.SysConfService;
|
||||
import com.ecep.contract.ds.vendor.repository.CompanyVendorRepository;
|
||||
import com.ecep.contract.ds.vendor.repository.VendorClassRepository;
|
||||
import com.ecep.contract.ds.vendor.repository.VendorTypeLocalRepository;
|
||||
import com.ecep.contract.model.*;
|
||||
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.fasterxml.jackson.databind.JsonNode;
|
||||
import jakarta.persistence.criteria.Path;
|
||||
import org.hibernate.Hibernate;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -27,34 +29,16 @@ import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.ecep.contract.CompanyVendorFileType;
|
||||
import com.ecep.contract.IEntityService;
|
||||
import com.ecep.contract.MessageHolder;
|
||||
import com.ecep.contract.VendorType;
|
||||
import com.ecep.contract.constant.CompanyVendorConstant;
|
||||
import com.ecep.contract.ds.company.CompanyFileUtils;
|
||||
import com.ecep.contract.ds.company.service.CompanyBasicService;
|
||||
import com.ecep.contract.ds.other.service.SysConfService;
|
||||
import com.ecep.contract.ds.vendor.repository.CompanyVendorRepository;
|
||||
import com.ecep.contract.ds.vendor.repository.VendorClassRepository;
|
||||
import com.ecep.contract.ds.vendor.repository.VendorTypeLocalRepository;
|
||||
import com.ecep.contract.model.Company;
|
||||
import com.ecep.contract.model.CompanyBasicFile;
|
||||
import com.ecep.contract.model.CompanyVendor;
|
||||
import com.ecep.contract.model.CompanyVendorEntity;
|
||||
import com.ecep.contract.model.CompanyVendorFile;
|
||||
import com.ecep.contract.model.Contract;
|
||||
import com.ecep.contract.model.VendorCatalog;
|
||||
import com.ecep.contract.model.VendorTypeLocal;
|
||||
import com.ecep.contract.util.MyStringUtils;
|
||||
import com.ecep.contract.util.SpecificationUtils;
|
||||
|
||||
import jakarta.persistence.criteria.Path;
|
||||
import java.io.File;
|
||||
import java.time.LocalDate;
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Lazy
|
||||
@Service
|
||||
@CacheConfig(cacheNames = CompanyVendorConstant.CACHE_NAME)
|
||||
public class CompanyVendorService extends CompanyBasicService implements IEntityService<CompanyVendor> {
|
||||
public class CompanyVendorService extends CompanyBasicService implements IEntityService<CompanyVendor>, QueryService<CompanyVendor> {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(CompanyVendorService.class);
|
||||
|
||||
@@ -85,6 +69,16 @@ public class CompanyVendorService extends CompanyBasicService implements IEntity
|
||||
return companyVendorRepository.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<CompanyVendor> findAll(JsonNode paramsNode, Pageable pageable) {
|
||||
Specification<CompanyVendor> spec = null;
|
||||
if (paramsNode.has("searchText")) {
|
||||
spec = getSpecification(paramsNode.get("searchText").asText());
|
||||
}
|
||||
// 添加额外的参数过滤
|
||||
spec = SpecificationUtils.andParam(spec, paramsNode, "company", "catalog");
|
||||
return findAll(spec, pageable);
|
||||
}
|
||||
|
||||
public CompanyVendor findByCompany(Company company) {
|
||||
return companyVendorRepository.findByCompany(company).orElse(null);
|
||||
@@ -388,7 +382,7 @@ public class CompanyVendorService extends CompanyBasicService implements IEntity
|
||||
}
|
||||
|
||||
String companyName = company.getName();
|
||||
String fileName = CompanyUtils.formatCompanyVendorId(companyVendor.getId()) + "-" + CompanyFileUtils.escapeFileName(companyName);
|
||||
String fileName = CompanyUtils.formatCompanyVendorId(companyVendor.getId()) + "-" + FileUtils.escapeFileName(companyName);
|
||||
|
||||
File dir = new File(basePath, fileName);
|
||||
if (!dir.exists()) {
|
||||
@@ -463,5 +457,5 @@ public class CompanyVendorService extends CompanyBasicService implements IEntity
|
||||
return companyVendorRepository.count(spec);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -2,12 +2,20 @@ package com.ecep.contract.ds.vendor.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.ecep.contract.IEntityService;
|
||||
import com.ecep.contract.QueryService;
|
||||
import com.ecep.contract.model.CompanyVendorFile;
|
||||
import com.ecep.contract.util.SpecificationUtils;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.cache.annotation.Caching;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.ecep.contract.ds.vendor.repository.VendorGroupRequireFileTypeRepository;
|
||||
@@ -16,7 +24,7 @@ import com.ecep.contract.model.VendorGroupRequireFileType;
|
||||
@Lazy
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "vendor-group-require-file-type")
|
||||
public class VendorGroupRequireFileTypeService {
|
||||
public class VendorGroupRequireFileTypeService implements IEntityService<VendorGroupRequireFileType>, QueryService<VendorGroupRequireFileType> {
|
||||
@Lazy
|
||||
@Autowired
|
||||
private VendorGroupRequireFileTypeRepository repository;
|
||||
@@ -26,6 +34,26 @@ public class VendorGroupRequireFileTypeService {
|
||||
return repository.findById(id).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<VendorGroupRequireFileType> findAll(Specification<VendorGroupRequireFileType> spec, Pageable pageable) {
|
||||
return repository.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<VendorGroupRequireFileType> findAll(JsonNode paramsNode, Pageable pageable) {
|
||||
Specification<VendorGroupRequireFileType> spec = null;
|
||||
if (paramsNode.has("searchText")) {
|
||||
spec = getSpecification(paramsNode.get("searchText").asText());
|
||||
}
|
||||
// 添加额外的参数过滤
|
||||
return findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Specification<VendorGroupRequireFileType> getSpecification(String searchText) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Cacheable(key = "'byGroup-'+#p0")
|
||||
public List<VendorGroupRequireFileType> findByGroupId(int groupId) {
|
||||
return repository.findByGroupId(groupId);
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
package com.ecep.contract.ds.vendor.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.ecep.contract.IEntityService;
|
||||
import com.ecep.contract.QueryService;
|
||||
import com.ecep.contract.ds.vendor.repository.VendorGroupRepository;
|
||||
import com.ecep.contract.model.VendorGroup;
|
||||
import com.ecep.contract.util.SpecificationUtils;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
@@ -13,14 +17,12 @@ 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.ds.vendor.repository.VendorGroupRepository;
|
||||
import com.ecep.contract.model.VendorGroup;
|
||||
import java.util.List;
|
||||
|
||||
@Lazy
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "vendor-group")
|
||||
public class VendorGroupService implements IEntityService<VendorGroup> {
|
||||
public class VendorGroupService implements IEntityService<VendorGroup>, QueryService<VendorGroup> {
|
||||
@Lazy
|
||||
@Autowired
|
||||
private VendorGroupRepository vendorGroupRepository;
|
||||
@@ -48,6 +50,17 @@ public class VendorGroupService implements IEntityService<VendorGroup> {
|
||||
return vendorGroupRepository.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<VendorGroup> findAll(JsonNode paramsNode, Pageable pageable) {
|
||||
Specification<VendorGroup> spec = null;
|
||||
if (paramsNode.has("searchText")) {
|
||||
spec = getSpecification(paramsNode.get("searchText").asText());
|
||||
}
|
||||
// 添加额外的参数过滤
|
||||
spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "active", "name", "code");
|
||||
return findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Specification<VendorGroup> getSpecification(String searchText) {
|
||||
return null;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.ecep.contract.handler;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.time.LocalDateTime;
|
||||
@@ -12,7 +14,6 @@ import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -272,50 +273,190 @@ public class WebSocketHandler extends TextWebSocketHandler {
|
||||
|
||||
private Object invokerSaveMethod(Object service, JsonNode argumentsNode) throws JsonMappingException {
|
||||
JsonNode paramsNode = argumentsNode.get(0);
|
||||
IEntityService<Object> entityService = (IEntityService<Object>) service;
|
||||
Object entity = null;
|
||||
if (paramsNode.has("id")) {
|
||||
int id = paramsNode.get("id").asInt();
|
||||
entity = entityService.findById(id);
|
||||
if (entity == null) {
|
||||
throw new NoSuchElementException("未找到实体: #" + id);
|
||||
}
|
||||
} else {
|
||||
entity = createNewEntity(entityService);
|
||||
if (entity == null) {
|
||||
throw new UnsupportedOperationException("无法创建实体对象, " + service.getClass().getName());
|
||||
if (service instanceof IEntityService<?> entityService) {
|
||||
Object entity = null;
|
||||
if (paramsNode.has("id") && !paramsNode.get("id").isNull()) {
|
||||
int id = paramsNode.get("id").asInt();
|
||||
entity = entityService.findById(id);
|
||||
if (entity == null) {
|
||||
throw new NoSuchElementException("未找到实体: #" + id);
|
||||
}
|
||||
} else {
|
||||
entity = createNewEntity(entityService);
|
||||
if (entity == null) {
|
||||
throw new UnsupportedOperationException("无法创建实体对象, " + service.getClass().getName());
|
||||
}
|
||||
}
|
||||
objectMapper.updateValue(entity, paramsNode);
|
||||
return ((IEntityService<Object>) entityService).save(entity);
|
||||
}
|
||||
objectMapper.updateValue(entity, paramsNode);
|
||||
return entityService.save(entity);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private Object createNewEntity(IEntityService<Object> entityService) {
|
||||
private <T> T createNewEntity(IEntityService<T> entityService) {
|
||||
try {
|
||||
Type[] types = getClass().getGenericInterfaces();
|
||||
// System.out.println("types = " + Arrays.asList(types));
|
||||
if (types.length > 0) {
|
||||
String typeName = types[0].getTypeName();
|
||||
// System.out.println("typeName = " + typeName);
|
||||
String clz = typeName.split("<")[1].split(">")[0].split(",")[0].trim();
|
||||
// System.out.println("clz = " + clz);
|
||||
Class<?> clazz = Class.forName(clz);
|
||||
return (T) clazz.getDeclaredConstructor().newInstance();
|
||||
// 通过分析接口的泛型参数来获取实体类型
|
||||
Class<?> serviceClass = entityService.getClass();
|
||||
|
||||
// 1. 直接检查接口
|
||||
Class<T> entityClass = findEntityTypeInInterfaces(serviceClass);
|
||||
if (entityClass != null) {
|
||||
return entityClass.getDeclaredConstructor().newInstance();
|
||||
}
|
||||
|
||||
// 2. 处理Spring代理类 - 获取原始类
|
||||
Class<?> targetClass = getTargetClass(serviceClass);
|
||||
if (targetClass != serviceClass) {
|
||||
entityClass = findEntityTypeInInterfaces(targetClass);
|
||||
if (entityClass != null) {
|
||||
return entityClass.getDeclaredConstructor().newInstance();
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 尝试查找父类
|
||||
entityClass = findEntityTypeInSuperclass(serviceClass);
|
||||
if (entityClass != null) {
|
||||
return entityClass.getDeclaredConstructor().newInstance();
|
||||
}
|
||||
|
||||
// 4. 如果上述方法都失败,尝试从参数类型推断
|
||||
entityClass = findEntityTypeFromMethodParameters(serviceClass);
|
||||
if (entityClass != null) {
|
||||
return entityClass.getDeclaredConstructor().newInstance();
|
||||
}
|
||||
|
||||
// 如果所有方法都失败,抛出更具描述性的异常
|
||||
throw new UnsupportedOperationException("无法确定实体类型,请检查服务实现: " + serviceClass.getName());
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("无法创建Entity实例", e);
|
||||
throw new RuntimeException("无法创建Entity实例: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 从接口中查找实体类型
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T> Class<T> findEntityTypeInInterfaces(Class<?> serviceClass) {
|
||||
Type[] interfaces = serviceClass.getGenericInterfaces();
|
||||
|
||||
for (Type iface : interfaces) {
|
||||
if (iface instanceof ParameterizedType paramType) {
|
||||
if (IEntityService.class.isAssignableFrom((Class<?>) paramType.getRawType())) {
|
||||
// 获取IEntityService的泛型参数类型
|
||||
Type entityType = paramType.getActualTypeArguments()[0];
|
||||
if (entityType instanceof Class<?>) {
|
||||
return (Class<T>) entityType;
|
||||
} else if (entityType instanceof ParameterizedType) {
|
||||
// 处理参数化类型
|
||||
Type rawType = ((ParameterizedType) entityType).getRawType();
|
||||
if (rawType instanceof Class<?>) {
|
||||
return (Class<T>) rawType;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从父类中查找实体类型
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T> Class<T> findEntityTypeInSuperclass(Class<?> serviceClass) {
|
||||
Type genericSuperclass = serviceClass.getGenericSuperclass();
|
||||
while (genericSuperclass != null && genericSuperclass != Object.class) {
|
||||
if (genericSuperclass instanceof ParameterizedType paramType) {
|
||||
Type rawType = paramType.getRawType();
|
||||
if (rawType instanceof Class<?> && IEntityService.class.isAssignableFrom((Class<?>) rawType)) {
|
||||
Type entityType = paramType.getActualTypeArguments()[0];
|
||||
if (entityType instanceof Class<?>) {
|
||||
return (Class<T>) entityType;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 继续查找父类的父类
|
||||
if (genericSuperclass instanceof Class<?>) {
|
||||
genericSuperclass = ((Class<?>) genericSuperclass).getGenericSuperclass();
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 尝试从方法参数类型推断实体类型
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T> Class<T> findEntityTypeFromMethodParameters(Class<?> serviceClass) {
|
||||
try {
|
||||
// 尝试通过findById方法推断实体类型
|
||||
Method findByIdMethod = serviceClass.getMethod("findById", Integer.class);
|
||||
if (findByIdMethod != null) {
|
||||
return (Class<T>) findByIdMethod.getReturnType();
|
||||
}
|
||||
|
||||
// 尝试通过findAll方法推断实体类型
|
||||
Method[] methods = serviceClass.getMethods();
|
||||
for (Method method : methods) {
|
||||
if (method.getName().equals("findAll") && method.getParameterCount() > 0) {
|
||||
Type returnType = method.getGenericReturnType();
|
||||
if (returnType instanceof ParameterizedType paramType &&
|
||||
paramType.getRawType() instanceof Class<?> &&
|
||||
"org.springframework.data.domain.Page"
|
||||
.equals(((Class<?>) paramType.getRawType()).getName())) {
|
||||
|
||||
Type[] actualTypeArguments = paramType.getActualTypeArguments();
|
||||
if (actualTypeArguments.length > 0 && actualTypeArguments[0] instanceof Class<?>) {
|
||||
return (Class<T>) actualTypeArguments[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// 忽略异常,继续尝试其他方法
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取被代理的原始类
|
||||
*/
|
||||
private Class<?> getTargetClass(Class<?> proxyClass) {
|
||||
// 处理CGLIB代理类
|
||||
if (proxyClass.getName().contains("$$SpringCGLIB$$")) {
|
||||
return proxyClass.getSuperclass();
|
||||
}
|
||||
|
||||
return proxyClass;
|
||||
}
|
||||
|
||||
/*
|
||||
* see client QueryService#findById(Integer)
|
||||
*/
|
||||
private Object invokerFindByIdMethod(Object service, JsonNode argumentsNode) {
|
||||
JsonNode paramsNode = argumentsNode.get(0);
|
||||
Integer id = paramsNode.asInt();
|
||||
IEntityService<?> entityService = (IEntityService<?>) service;
|
||||
return entityService.findById(id);
|
||||
if (service instanceof IEntityService<?> entityService) {
|
||||
Integer id = paramsNode.asInt();
|
||||
return entityService.findById(id);
|
||||
}
|
||||
|
||||
try {
|
||||
if (paramsNode.isInt()) {
|
||||
Method method = service.getClass().getMethod("findById", Integer.class);
|
||||
return method.invoke(service, paramsNode.asInt());
|
||||
}
|
||||
if (paramsNode.isTextual()) {
|
||||
Method method = service.getClass().getMethod("findById", String.class);
|
||||
return method.invoke(service, paramsNode.asText());
|
||||
}
|
||||
throw new IllegalArgumentException("unable to invoke findById method, paramsNode is not int or text");
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("unable to invoke findById method", e);
|
||||
}
|
||||
}
|
||||
|
||||
private Object invokerFindAllMethod(Object service, JsonNode argumentsNode) throws JsonProcessingException {
|
||||
|
||||
Reference in New Issue
Block a user