package com.estate.expert.admin.io.processor.impl.business;
|
|
import com.estate.expert.admin.domain.project.Project;
|
import com.estate.expert.admin.domain.project.detail.AddressInfo;
|
import com.estate.expert.admin.domain.project.detail.CompanyInfo;
|
import com.estate.expert.admin.domain.project.enums.ProjectType;
|
import com.estate.expert.admin.domain.project.enums.ProjectUsageType;
|
import com.estate.expert.admin.enums.BizResultCode;
|
import com.estate.expert.admin.io.processor.RowDataProcessorBase;
|
import com.estate.expert.admin.service.ClientService;
|
import com.estate.expert.admin.service.ProjectService;
|
import com.estate.expert.admin.utils.DeletedObjectUtil;
|
import com.estate.expert.admin.utils.ExcelParseUtils;
|
import lombok.AllArgsConstructor;
|
|
import java.util.List;
|
|
/**
|
* 项目处理器
|
*
|
* 用于处理项目信息的读取和写入
|
*/
|
@AllArgsConstructor
|
public class ProjectProcessor extends RowDataProcessorBase<Project> {
|
|
private ClientService clientService;
|
|
private ProjectService projectService;
|
|
protected final String[] getHeaders() {
|
return new String[]{
|
"项目名称", "项目类型", "用途类型", "委托方", "施工许可证号", "所属分公司", "施工单位", "项目经理", "手机号",
|
"监理单位", "总监", "手机号_1", "建设单位", "项目负责人", "手机号_2", "省", "市", "区", "详细地址", "工程造价","项目规格"
|
};
|
}
|
|
@Override
|
public String getName() {
|
return "项目信息";
|
}
|
|
@Override
|
protected List<String> buildRowData(Project data) {
|
var cci = data.getConstructionCompanyInfo();
|
var sci = data.getSupervisorCompanyInfo();
|
var dci = data.getDevelopmentCompanyInfo();
|
var address = data.getAddressInfo();
|
var cost = data.getProjectCost();
|
var scale = data.getScale();
|
return List.of(
|
data.getName(),
|
data.getType().getDesc(),
|
data.getUsageType().getDesc(),
|
DeletedObjectUtil.beautifyDeletedString(data.getClient().getName()),
|
data.getConstructionLicense() == null ? "" : data.getConstructionLicense(),
|
data.getBranchCompany() == null ? "" : data.getBranchCompany(),
|
|
cci == null || cci.getName() == null ? "" : cci.getName(),
|
cci == null || cci.getLeader() == null ? "" : cci.getLeader(),
|
cci == null || cci.getPhone() == null ? "" : cci.getPhone(),
|
sci == null || sci.getName() == null ? "" : sci.getName(),
|
sci == null || sci.getLeader() == null ? "" : sci.getLeader(),
|
sci == null || sci.getPhone() == null ? "" : sci.getPhone(),
|
dci == null || dci.getName() == null ? "" : dci.getName(),
|
dci == null || dci.getLeader() == null ? "" : dci.getLeader(),
|
dci == null || dci.getPhone() == null ? "" : dci.getPhone(),
|
|
address == null || address.getProvince() == null ? "" : address.getProvince(),
|
address == null || address.getCity() == null ? "" : address.getCity(),
|
address == null || address.getDistrict() == null ? "" : address.getDistrict(),
|
address == null || address.getDetail() == null ? "" : address.getDetail(),
|
|
cost == null ? "" : cost.toString(),
|
scale == null ? "" : scale.toString()
|
);
|
}
|
|
@Override
|
protected Project parseRowData(int rowIndex, List<String> rowData) {
|
var index = 0;
|
var project = new Project();
|
project.setName(rowData.get(index++));
|
// 移除重名检查,由 ProjectService.addEntities 统一处理(自动加数字)
|
|
project.setType(ProjectType.getByDesc(rowData.get(index++)));
|
project.setUsageType(ProjectUsageType.getByDesc(rowData.get(index++)));
|
// client
|
var client = clientService.getByName(rowData.get(index++));
|
BizResultCode.CLIENT_NOT_FOUND.check(client == null, "CLIENT_NOT_FOUND");
|
|
project.setClient(client);
|
project.setConstructionLicense(rowData.get(index++));
|
project.setBranchCompany(rowData.get(index++));
|
|
|
var cci = CompanyInfo.builder()
|
.name(rowData.get(index++))
|
.leader(rowData.get(index++))
|
.phone(rowData.get(index++))
|
.build();
|
project.setConstructionCompanyInfo(cci);
|
|
var sci = CompanyInfo.builder()
|
.name(rowData.get(index++))
|
.leader(rowData.get(index++))
|
.phone(rowData.get(index++))
|
.build();
|
project.setSupervisorCompanyInfo(sci);
|
|
var dci = CompanyInfo.builder()
|
.name(rowData.get(index++))
|
.leader(rowData.get(index++))
|
.phone(rowData.get(index++))
|
.build();
|
project.setDevelopmentCompanyInfo(dci);
|
|
var address = AddressInfo.builder()
|
.province(ExcelParseUtils.parseString(rowData.get(index++)))
|
.city(ExcelParseUtils.parseString(rowData.get(index++)))
|
.district(ExcelParseUtils.parseString(rowData.get(index++)))
|
.detail(ExcelParseUtils.parseString(rowData.get(index++)))
|
.build();
|
project.setAddressInfo(address);
|
|
// 解析工程造价,使用工具类处理空值和异常
|
project.setProjectCost(ExcelParseUtils.parseInt(rowData.get(index++)));
|
|
|
project.setScale(rowData.get(index++));
|
return project;
|
}
|
}
|