refactor(vo): 重构VO对象结构,统一字段命名和接口实现
重构所有VO对象,统一字段命名规范,移除冗余字段,优化接口实现 新增Voable接口用于VO对象转换 调整BaseViewModel和ProjectBasedViewModel接口定义 更新相关服务和控制器以适应VO对象变更
This commit is contained in:
@@ -35,29 +35,27 @@ import com.ecep.contract.vo.CompanyVo;
|
||||
import javafx.collections.ObservableList;
|
||||
|
||||
@Service
|
||||
public class CompanyFileService extends QueryService<CompanyFile, CompanyFileViewModel> {
|
||||
public List<CompanyFile> findByCompany(Company company) {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("company", company.getId());
|
||||
return findAll(params, Pageable.unpaged()).getContent();
|
||||
public class CompanyFileService extends QueryService<CompanyFileVo, CompanyFileViewModel> {
|
||||
public List<CompanyFileVo> findByCompany(CompanyVo company) {
|
||||
if (company == null) {
|
||||
return List.of();
|
||||
}
|
||||
return findAll(ParamUtils.equal("company", company.getId()), Pageable.unpaged()).getContent();
|
||||
}
|
||||
|
||||
public List<CompanyFile> findByCompanyAndPath(Company company, String absolutePath) {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("company", company.getId());
|
||||
params.put("filePath", absolutePath);
|
||||
return findAll(params, Pageable.unpaged()).getContent();
|
||||
public List<CompanyFileVo> findByCompanyAndPath(CompanyVo company, String absolutePath) {
|
||||
return findAll(ParamUtils.builder().equals("company", company.getId()).equals("filePath", absolutePath).build(),
|
||||
Pageable.unpaged()).getContent();
|
||||
}
|
||||
|
||||
|
||||
public boolean reBuildingFiles(Company company, MessageHolder holder) {
|
||||
List<CompanyFile> dbFiles = findByCompany(company);
|
||||
List<CompanyFile> retrieveFiles = new ArrayList<>();
|
||||
public boolean reBuildingFiles(CompanyVo company, MessageHolder holder) {
|
||||
List<CompanyFileVo> dbFiles = findByCompany(company);
|
||||
List<CompanyFileVo> retrieveFiles = new ArrayList<>();
|
||||
boolean modfied = false;
|
||||
|
||||
Map<String, CompanyFile> map = new HashMap<>();
|
||||
Map<String, CompanyFileVo> map = new HashMap<>();
|
||||
// 排除掉数据库中重复的
|
||||
for (CompanyFile dbFile : dbFiles) {
|
||||
for (CompanyFileVo dbFile : dbFiles) {
|
||||
String filePath = dbFile.getFilePath();
|
||||
// 没有文件信息,无效记录,删除
|
||||
if (!StringUtils.hasText(filePath)) {
|
||||
@@ -74,7 +72,7 @@ public class CompanyFileService extends QueryService<CompanyFile, CompanyFileVie
|
||||
continue;
|
||||
}
|
||||
|
||||
CompanyFile old = map.put(filePath, dbFile);
|
||||
CompanyFileVo old = map.put(filePath, dbFile);
|
||||
// 目录有重复删除
|
||||
if (old != null) {
|
||||
delete(old);
|
||||
@@ -91,8 +89,8 @@ public class CompanyFileService extends QueryService<CompanyFile, CompanyFileVie
|
||||
}
|
||||
|
||||
// 获取所有曾用名
|
||||
List<CompanyOldName> oldNames = SpringApp.getBean(CompanyOldNameService.class).findAllByCompany(company);
|
||||
for (CompanyOldName companyOldName : oldNames) {
|
||||
List<CompanyOldNameVo> oldNames = SpringApp.getBean(CompanyOldNameService.class).findAllByCompany(company);
|
||||
for (CompanyOldNameVo companyOldName : oldNames) {
|
||||
String path = companyOldName.getPath();
|
||||
if (StringUtils.hasText(path)) {
|
||||
File dir = new File(path);
|
||||
@@ -123,7 +121,7 @@ public class CompanyFileService extends QueryService<CompanyFile, CompanyFileVie
|
||||
String filePath = file.getAbsolutePath();
|
||||
if (!map.containsKey(filePath)) {
|
||||
// 未记录
|
||||
CompanyFile filled = fillFileType(file, holder);
|
||||
CompanyFileVo filled = fillFileType(file, holder);
|
||||
retrieveFiles.add(filled);
|
||||
}
|
||||
}
|
||||
@@ -136,13 +134,12 @@ public class CompanyFileService extends QueryService<CompanyFile, CompanyFileVie
|
||||
|
||||
// update db
|
||||
retrieveFiles.forEach(v -> {
|
||||
v.setCompany(company);
|
||||
v.setCompanyId(company.getId());
|
||||
save(v);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 从文件名生成公司文件对象,文件已经存在公司对应的存储目录下
|
||||
*
|
||||
@@ -150,9 +147,9 @@ public class CompanyFileService extends QueryService<CompanyFile, CompanyFileVie
|
||||
* @param holder 状态输出
|
||||
* @return 公司文件对象
|
||||
*/
|
||||
private CompanyFile fillFileType(File file, MessageHolder holder) {
|
||||
private CompanyFileVo fillFileType(File file, MessageHolder holder) {
|
||||
String fileName = file.getName();
|
||||
CompanyFile companyFile = new CompanyFile();
|
||||
CompanyFileVo companyFile = new CompanyFileVo();
|
||||
companyFile.setType(CompanyFileType.General);
|
||||
companyFile.setFilePath(file.getAbsolutePath());
|
||||
fillApplyDateAndExpiringDateAbsent(file, companyFile);
|
||||
@@ -198,7 +195,7 @@ public class CompanyFileService extends QueryService<CompanyFile, CompanyFileVie
|
||||
/**
|
||||
* 补齐有效期
|
||||
*/
|
||||
private void fillExpiringDateAbsent(CompanyFile file) {
|
||||
private void fillExpiringDateAbsent(CompanyFileVo file) {
|
||||
LocalDate expiringDate = file.getExpiringDate();
|
||||
if (expiringDate == null) {
|
||||
LocalDate applyDate = file.getApplyDate();
|
||||
@@ -209,7 +206,7 @@ public class CompanyFileService extends QueryService<CompanyFile, CompanyFileVie
|
||||
}
|
||||
}
|
||||
|
||||
private static void fillApplyDateAndExpiringDateAbsent(File file, CompanyFile companyFile) {
|
||||
private static void fillApplyDateAndExpiringDateAbsent(File file, CompanyFileVo companyFile) {
|
||||
LocalDate applyDate = companyFile.getApplyDate();
|
||||
if (applyDate != null) {
|
||||
return;
|
||||
@@ -245,10 +242,10 @@ public class CompanyFileService extends QueryService<CompanyFile, CompanyFileVie
|
||||
|
||||
}
|
||||
|
||||
public void verify(Company company, LocalDate verifyDate, MessageHolder holder) {
|
||||
public void verify(CompanyVo company, LocalDate verifyDate, MessageHolder holder) {
|
||||
// 查询公司的资信评估报告
|
||||
List<CompanyFile> files = findFileByCompanyAndType(company, CompanyFileType.CreditReport);
|
||||
CompanyFile companyFile = files.stream()
|
||||
List<CompanyFileVo> files = findFileByCompanyAndType(company, CompanyFileType.CreditReport);
|
||||
CompanyFileVo companyFile = files.stream()
|
||||
.filter(v -> v.getApplyDate() != null && v.getExpiringDate() != null)
|
||||
.filter(v -> MyDateTimeUtils.dateValidFilter(verifyDate, v.getApplyDate(), v.getExpiringDate(), 30))
|
||||
.findFirst().orElse(null);
|
||||
@@ -257,14 +254,14 @@ public class CompanyFileService extends QueryService<CompanyFile, CompanyFileVie
|
||||
|
||||
files.stream()
|
||||
.filter(v -> v.getApplyDate() != null && !verifyDate.isBefore(v.getApplyDate()))
|
||||
.max(Comparator.comparing(CompanyFile::getApplyDate))
|
||||
.map(CompanyFile::getApplyDate)
|
||||
.max(Comparator.comparing(CompanyFileVo::getApplyDate))
|
||||
.map(CompanyFileVo::getApplyDate)
|
||||
.ifPresent(dates::add);
|
||||
|
||||
files.stream()
|
||||
.filter(v -> v.getExpiringDate() != null && !verifyDate.isAfter(v.getExpiringDate()))
|
||||
.min(Comparator.comparing(CompanyFile::getApplyDate))
|
||||
.map(CompanyFile::getApplyDate)
|
||||
.min(Comparator.comparing(CompanyFileVo::getApplyDate))
|
||||
.map(CompanyFileVo::getApplyDate)
|
||||
.ifPresent(dates::add);
|
||||
|
||||
if (dates.isEmpty()) {
|
||||
@@ -278,26 +275,26 @@ public class CompanyFileService extends QueryService<CompanyFile, CompanyFileVie
|
||||
}
|
||||
}
|
||||
|
||||
private List<CompanyFile> findFileByCompanyAndType(Company company, CompanyFileType companyFileType) {
|
||||
return findAll(ParamUtils.builder().equals("company", company.getId()).equals("type", companyFileType).build(), Pageable.unpaged()).getContent();
|
||||
private List<CompanyFileVo> findFileByCompanyAndType(CompanyVo company, CompanyFileType companyFileType) {
|
||||
return findAll(ParamUtils.builder().equals("company", company.getId()).equals("type", companyFileType).build(),
|
||||
Pageable.unpaged()).getContent();
|
||||
}
|
||||
|
||||
public LocalDate getNextCreditReportDate(Company company, Consumer<String> state) {
|
||||
public LocalDate getNextCreditReportDate(CompanyVo company, Consumer<String> state) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'getNextCreditReportDate'");
|
||||
}
|
||||
|
||||
public void copyAsMatched(Company company, LocalDate applyDate, Consumer<String> state) {
|
||||
public void copyAsMatched(CompanyVo company, LocalDate applyDate, Consumer<String> state) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'copyAsMatched'");
|
||||
}
|
||||
|
||||
public void copyAsMatchedByContract(Company parent, ObservableList<String> list) {
|
||||
public void copyAsMatchedByContract(CompanyVo company, ObservableList<String> list) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'copyAsMatchedByContract'");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 移动文件到企业目录下
|
||||
*
|
||||
@@ -352,7 +349,7 @@ public class CompanyFileService extends QueryService<CompanyFile, CompanyFileVie
|
||||
dir = home;
|
||||
}
|
||||
|
||||
CompanyFile filled = fillDownloadFileType(company, file, companyName, dir, sub);
|
||||
CompanyFileVo filled = fillDownloadFileType(company, file, companyName, dir, sub);
|
||||
if (filled != null) {
|
||||
retrieveFiles.add(filled);
|
||||
}
|
||||
@@ -367,13 +364,12 @@ public class CompanyFileService extends QueryService<CompanyFile, CompanyFileVie
|
||||
|
||||
// update db
|
||||
retrieveFiles.forEach(v -> {
|
||||
v.setCompany(company);
|
||||
v.setCompanyId(company.getId());
|
||||
save(v);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 从文件名生成公司文件对象
|
||||
* 文件从下载目录中导入
|
||||
@@ -386,7 +382,7 @@ public class CompanyFileService extends QueryService<CompanyFile, CompanyFileVie
|
||||
* @return 生成的公司文件对象,如果无法转换则返回null
|
||||
*/
|
||||
private CompanyFileVo fillDownloadFileType(CompanyVo company, File file, String companyName, File destDir,
|
||||
MessageHolder holder) {
|
||||
MessageHolder holder) {
|
||||
String fileName = file.getName();
|
||||
// 天眼查的报告
|
||||
// 目前只有 基础版企业信用报告, 企业信用信息公示报告下载保存时的文件名中没有天眼查
|
||||
@@ -442,7 +438,7 @@ public class CompanyFileService extends QueryService<CompanyFile, CompanyFileVie
|
||||
|
||||
// 企业信用信息公示报告
|
||||
if (fileName.contains(CloudServiceConstant.TYC_ENTERPRISE_CREDIT_REPORT)) {
|
||||
CompanyFile companyFile = new CompanyFile();
|
||||
CompanyFileVo companyFile = new CompanyFileVo();
|
||||
companyFile.setType(CompanyFileType.CreditInfoPublicityReport);
|
||||
fillApplyDateAbsent(file, companyFile);
|
||||
File dest = new File(destDir, fileName);
|
||||
@@ -456,7 +452,7 @@ public class CompanyFileService extends QueryService<CompanyFile, CompanyFileVie
|
||||
return null;
|
||||
}
|
||||
if (file.renameTo(dest)) {
|
||||
List<CompanyFile> files = findByCompanyAndPath(company, dest.getAbsolutePath());
|
||||
List<CompanyFileVo> files = findByCompanyAndPath(company, dest.getAbsolutePath());
|
||||
if (!files.isEmpty()) {
|
||||
companyFile = files.getFirst();
|
||||
}
|
||||
@@ -477,11 +473,10 @@ public class CompanyFileService extends QueryService<CompanyFile, CompanyFileVie
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 当 ApplyDate 未设置时,尝试使用文件名中包含的日期
|
||||
*/
|
||||
private static void fillApplyDateAbsent(File file, CompanyFileVo companyFile) {
|
||||
private static void fillApplyDateAbsent(File file, CompanyFileVo companyFile) {
|
||||
LocalDate applyDate = companyFile.getApplyDate();
|
||||
if (applyDate != null) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user