refactor: 重构查询服务使用ParamConstant替换ServiceConstant style: 清理无用代码和注释 fix: 修复CompanyCustomerEvaluationFormFileService查询方法 docs: 更新CloudYuVo和CompanyBankAccountVo字段注释
100 lines
3.5 KiB
Java
100 lines
3.5 KiB
Java
package com.ecep.contract.service;
|
|
|
|
import java.io.File;
|
|
import java.time.LocalDate;
|
|
import java.util.List;
|
|
|
|
import com.ecep.contract.util.MyStringUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.data.domain.Page;
|
|
import org.springframework.data.domain.Pageable;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.util.StringUtils;
|
|
|
|
import com.ecep.contract.model.IdentityEntity;
|
|
import com.ecep.contract.util.FileUtils;
|
|
import com.ecep.contract.util.ParamUtils;
|
|
import com.ecep.contract.vm.CompanyOldNameViewModel;
|
|
import com.ecep.contract.vo.CompanyOldNameVo;
|
|
import com.ecep.contract.vo.CompanyVo;
|
|
|
|
@Service
|
|
public class CompanyOldNameService extends QueryService<CompanyOldNameVo, CompanyOldNameViewModel> {
|
|
@Autowired
|
|
private CompanyService companyService;
|
|
|
|
public boolean makePathAbsent(CompanyOldNameVo companyOldName) {
|
|
String path = companyOldName.getPath();
|
|
if (StringUtils.hasText(path)) {
|
|
File file = new File(path);
|
|
if (file.exists()) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
File dir = makePath(companyOldName);
|
|
if (dir == null) {
|
|
return false;
|
|
}
|
|
if (!dir.exists()) {
|
|
return false;
|
|
}
|
|
companyOldName.setPath(dir.getAbsolutePath());
|
|
return true;
|
|
}
|
|
|
|
public File makePath(CompanyOldNameVo companyOldName) {
|
|
String oldName = companyOldName.getName();
|
|
File basePath = companyService.getBasePath();
|
|
CompanyVo company = companyService.findById(companyOldName.getCompanyId());
|
|
String district = company.getDistrict();
|
|
if (StringUtils.hasText(district)) {
|
|
String parentPrefix = FileUtils.getParentPrefixByDistrict(district);
|
|
if (parentPrefix != null) {
|
|
File parent = new File(basePath, parentPrefix);
|
|
if (!parent.exists()) {
|
|
if (!parent.mkdir()) {
|
|
return null;
|
|
}
|
|
}
|
|
String fileName = FileUtils.escapeFileName(oldName);
|
|
File dir = new File(parent, fileName);
|
|
if (!dir.exists()) {
|
|
if (!dir.mkdir()) {
|
|
return null;
|
|
}
|
|
}
|
|
return dir;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public CompanyOldNameVo findMatchByDate(CompanyVo company, LocalDate localDate) {
|
|
findAll(ParamUtils.builder()
|
|
.equals("company", company.getId())
|
|
.equals("ambiguity", true)
|
|
.isNotNull("beginDate")
|
|
.build(), Pageable.unpaged()).getContent();
|
|
return null;
|
|
}
|
|
|
|
public List<CompanyOldNameVo> findAllByCompanyAndName(CompanyVo company, String oldName) {
|
|
return findAll(ParamUtils.builder().equals("company", company.getId()).equals("name", oldName).build(),
|
|
Pageable.unpaged()).getContent();
|
|
}
|
|
|
|
public List<CompanyOldNameVo> findAllByCompany(IdentityEntity company) {
|
|
return findAll(ParamUtils.equal("company", company.getId()), Pageable.unpaged()).getContent();
|
|
}
|
|
|
|
public void mergeTo(CompanyVo from, CompanyVo to) {
|
|
List<CompanyOldNameVo> fromOldNames = findAllByCompany(from);
|
|
for (CompanyOldNameVo fromOldName : fromOldNames) {
|
|
fromOldName.setMemo(MyStringUtils.appendIfAbsent(fromOldName.getMemo(), "转自 " + from.getId()));
|
|
fromOldName.setCompanyId(to.getId());
|
|
save(fromOldName);
|
|
}
|
|
}
|
|
}
|