refactor(vo): 重构VO对象结构,统一字段命名和接口实现
重构所有VO对象,统一字段命名规范,移除冗余字段,优化接口实现 新增Voable接口用于VO对象转换 调整BaseViewModel和ProjectBasedViewModel接口定义 更新相关服务和控制器以适应VO对象变更
This commit is contained in:
@@ -1,32 +1,44 @@
|
||||
package com.ecep.contract.service;
|
||||
|
||||
import com.ecep.contract.CompanyCustomerFileType;
|
||||
import com.ecep.contract.MessageHolder;
|
||||
import com.ecep.contract.SpringApp;
|
||||
import com.ecep.contract.model.*;
|
||||
import com.ecep.contract.util.ParamUtils;
|
||||
import com.ecep.contract.vm.CompanyCustomerFileViewModel;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.File;
|
||||
import java.time.LocalDate;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.ecep.contract.CompanyCustomerFileType;
|
||||
import com.ecep.contract.MessageHolder;
|
||||
import com.ecep.contract.SpringApp;
|
||||
import com.ecep.contract.model.CompanyCustomer;
|
||||
import com.ecep.contract.model.CompanyCustomerEvaluationFormFile;
|
||||
import com.ecep.contract.util.ParamUtils;
|
||||
import com.ecep.contract.vm.CompanyCustomerFileViewModel;
|
||||
import com.ecep.contract.vo.CompanyCustomerFileVo;
|
||||
import com.ecep.contract.vo.CompanyCustomerVo;
|
||||
import com.ecep.contract.vo.CompanyVo;
|
||||
import com.ecep.contract.vo.ContractVo;
|
||||
|
||||
@Service
|
||||
public class CompanyCustomerFileService extends QueryService<CompanyCustomerFile, CompanyCustomerFileViewModel> {
|
||||
public List<CompanyCustomerEvaluationFormFile> findAllCustomerEvaluationFormFiles(CompanyCustomer customer) {
|
||||
throw new UnsupportedOperationException();
|
||||
@CacheConfig(cacheNames = "customer-file")
|
||||
public class CompanyCustomerFileService extends QueryService<CompanyCustomerFileVo, CompanyCustomerFileViewModel> {
|
||||
@Cacheable
|
||||
@Override
|
||||
public CompanyCustomerFileVo findById(Integer id) {
|
||||
return super.findById(id);
|
||||
}
|
||||
|
||||
public LocalDate getNextSignDate(CompanyCustomer companyCustomer, MessageHolder holder) {
|
||||
public LocalDate getNextSignDate(CompanyCustomerVo companyCustomer, MessageHolder holder) {
|
||||
LocalDate miniContractDate = LocalDate.of(2022, 1, 1);
|
||||
Company company = companyCustomer.getCompany();
|
||||
Integer companyId = companyCustomer.getCompanyId();
|
||||
|
||||
CompanyService companyService = SpringApp.getBean(CompanyService.class);
|
||||
CompanyVo company = companyService.findById(companyId);
|
||||
ContractService contractService = SpringApp.getBean(ContractService.class);
|
||||
Map<String, Object> params = ParamUtils.builder().equals("company", company.getId()).build();
|
||||
long count = contractService.count(params);
|
||||
@@ -36,18 +48,19 @@ public class CompanyCustomerFileService extends QueryService<CompanyCustomerFile
|
||||
}
|
||||
|
||||
// 检索评估表
|
||||
List<CompanyCustomerFile> files = findAllByCustomerAndType(companyCustomer, CompanyCustomerFileType.EvaluationForm);
|
||||
CompanyCustomerFile latestFile = files.stream()
|
||||
List<CompanyCustomerFileVo> files = findAllByCustomerAndType(companyCustomer,
|
||||
CompanyCustomerFileType.EvaluationForm);
|
||||
CompanyCustomerFileVo latestFile = files.stream()
|
||||
.filter(v -> v.getSignDate() != null && v.isValid())
|
||||
.max(Comparator.comparing(CompanyCustomerFile::getSignDate))
|
||||
.max(Comparator.comparing(CompanyCustomerFileVo::getSignDate))
|
||||
.orElse(null);
|
||||
if (latestFile == null) {
|
||||
// 没有有效的评估表的评价日期
|
||||
holder.warn("未发现有效的评估表");
|
||||
// 返回最早的合同日期
|
||||
Contract firstContract = contractService.findAll(params, Pageable.unpaged()).stream()
|
||||
ContractVo firstContract = contractService.findAll(params, Pageable.unpaged()).stream()
|
||||
.filter(v -> v.getSetupDate() != null && !v.getSetupDate().isBefore(miniContractDate))
|
||||
.min(Comparator.comparing(Contract::getSetupDate))
|
||||
.min(Comparator.comparing(ContractVo::getSetupDate))
|
||||
.orElse(null);
|
||||
if (firstContract == null) {
|
||||
holder.warn("最早的合同不存在?");
|
||||
@@ -63,7 +76,7 @@ public class CompanyCustomerFileService extends QueryService<CompanyCustomerFile
|
||||
LocalDate nextInValidDate = latestFile.getSignDate().plusYears(1);
|
||||
File file = new File(latestFile.getFilePath());
|
||||
holder.info("依据 " + file.getName() + " 的失效期 " + nextInValidDate + " 检索合同");
|
||||
List<Contract> matchedContracts = contractService.findAll(params, Pageable.unpaged()).stream()
|
||||
List<ContractVo> matchedContracts = contractService.findAll(params, Pageable.unpaged()).stream()
|
||||
.filter(v -> v.getSetupDate().isAfter(nextInValidDate)).toList();
|
||||
// 没有在失效日期后的合同时,使用失效日期
|
||||
if (matchedContracts.isEmpty()) {
|
||||
@@ -73,11 +86,12 @@ public class CompanyCustomerFileService extends QueryService<CompanyCustomerFile
|
||||
holder.info("发现匹配合同 " + matchedContracts.size() + " 个");
|
||||
|
||||
// 按时间取最早一个
|
||||
Contract firstContract = matchedContracts.stream()
|
||||
.min(Comparator.comparing(Contract::getSetupDate))
|
||||
ContractVo firstContract = matchedContracts.stream()
|
||||
.min(Comparator.comparing(ContractVo::getSetupDate))
|
||||
.orElse(null);
|
||||
LocalDate setupDate = firstContract.getSetupDate();
|
||||
holder.info("匹配失效期 " + nextInValidDate + " 后的第一个合同 " + firstContract.getCode() + ", 依据合同 " + firstContract.getCode() + " 的日期 " + setupDate + " 推算");
|
||||
holder.info("匹配失效期 " + nextInValidDate + " 后的第一个合同 " + firstContract.getCode() + ", 依据合同 "
|
||||
+ firstContract.getCode() + " 的日期 " + setupDate + " 推算");
|
||||
return SpringApp.getBean(HolidayService.class).adjustToWorkDay(setupDate.plusDays(-7));
|
||||
}
|
||||
|
||||
@@ -85,37 +99,26 @@ public class CompanyCustomerFileService extends QueryService<CompanyCustomerFile
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public List<CompanyCustomerFile> findAllByCustomer(CompanyCustomer companyCustomer) {
|
||||
return findAll(ParamUtils.builder().equals("customer", companyCustomer).build(), Pageable.unpaged()).getContent();
|
||||
public List<CompanyCustomerFileVo> findAllByCustomer(CompanyCustomerVo companyCustomer) {
|
||||
return findAll(ParamUtils.builder().equals("customer", companyCustomer).build(), Pageable.unpaged())
|
||||
.getContent();
|
||||
}
|
||||
|
||||
public CompanyCustomerEvaluationFormFile findCustomerEvaluationFormFileByCustomerFile(
|
||||
CompanyCustomerFile customerFile) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'findCustomerEvaluationFormFileByCustomerFile'");
|
||||
}
|
||||
|
||||
public CompanyCustomerEvaluationFormFile findCustomerEvaluationFormFileById(int id) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'findCustomerEvaluationFormFileById'");
|
||||
}
|
||||
|
||||
public void save(CompanyCustomerEvaluationFormFile formFile) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'save'");
|
||||
}
|
||||
|
||||
public Map<CompanyCustomerFileType, CompanyCustomerFileTypeLocal> getFileTypeLocalMap(Locale locale) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'getFileTypeLocalMap'");
|
||||
}
|
||||
|
||||
public List<CompanyCustomerFile> findAllByCustomerAndType(CompanyCustomer customer, CompanyCustomerFileType type) {
|
||||
return findAll(ParamUtils.builder().equals("customer", customer.getId()).equals("type", type.name()).build(), Pageable.unpaged()).getContent();
|
||||
public List<CompanyCustomerFileVo> findAllByCustomerAndType(CompanyCustomerVo customer, CompanyCustomerFileType type) {
|
||||
return findAll(ParamUtils.builder()
|
||||
.equals("customer", customer.getId())
|
||||
.equals("type", type.name())
|
||||
.build(), Pageable.unpaged()).getContent();
|
||||
}
|
||||
|
||||
public List<CompanyCustomerEvaluationFormFile> searchEvaluationFile(CompanyCustomer customer, String searchText) {
|
||||
// TODO Auto-generated method stub
|
||||
// TODO need move to CompanyCustomerEvaluationFormFileService
|
||||
throw new UnsupportedOperationException("Unimplemented method 'searchEvaluationFile'");
|
||||
}
|
||||
|
||||
@CacheEvict(allEntries = true)
|
||||
@Override
|
||||
public CompanyCustomerFileVo save(CompanyCustomerFileVo entity) {
|
||||
return super.save(entity);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user