liujie
2026-01-14 f976a39b294f8c7dd60bcd2c661983c0dcc97fc6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
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();
        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()
        );
    }
 
    @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++)));
 
        return project;
    }
}