chengf
2026-03-11 b88a288f4f787b509463678e3cd9ccfa3f37014b
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
package com.java110.api.importData.adapt;
 
import com.alibaba.fastjson.JSONObject;
import com.java110.api.importData.DefaultImportDataAdapt;
import com.java110.api.importData.IImportDataCleaningAdapt;
import com.java110.dto.importData.Vtil;
import com.java110.dto.owner.OwnerCarDto;
import com.java110.dto.system.ComponentValidateResult;
import com.java110.intf.user.IOwnerV1InnerServiceSMO;
import com.java110.utils.util.Assert;
import com.java110.utils.util.ImportExcelUtils;
import com.java110.utils.util.StringUtil;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
 
@Service("importOwnerCarV2DataCleaning")
public class ImportOwnerCarV2DataCleaningAdapt extends DefaultImportDataAdapt implements IImportDataCleaningAdapt {
 
    @Autowired
    private IOwnerV1InnerServiceSMO ownerV1InnerServiceSMOImpl;
 
    @Override
    public List analysisExcel(Workbook workbook, JSONObject paramIn,  ComponentValidateResult result) throws Exception{
 
        List<OwnerCarDto> ownerCars = new ArrayList<OwnerCarDto>();
        //封装对象
        getOwnerCars(workbook, ownerCars, result);
        //数据格式校验
        validateCarInfo(ownerCars);
 
 
        return ownerCars;
    }
    public String defaultValue(Object o) {
        return o == null ? "" : o.toString();
    }
 
    /**
     * 获取业主车辆信息
     *
     * @param workbook
     * @param ownerCars
     */
    private void getOwnerCars(Workbook workbook, List<OwnerCarDto> ownerCars,  ComponentValidateResult result) throws ParseException {
        Sheet sheet = null;
        sheet = ImportExcelUtils.getSheet(workbook, "地面停车费 导入新模板");
        List<Object[]> oList = ImportExcelUtils.listFromSheet(sheet);
        OwnerCarDto importOwnerCar = null;
        for (int osIndex = 0; osIndex < oList.size(); osIndex++) {
            Object[] os = oList.get(osIndex);
            if (osIndex < 3) { // 第一行是 头部信息 直接跳过
                continue;
            }
            if (StringUtil.isNullOrNone(os[0])) {
                continue;
            }
//            Assert.hasValue(os[8], (osIndex + 1) + "行车牌号不能为空");
            if (os[8] == null || os[8].equals("")) {
                os[8] = "空";
            }
            if (defaultValue(os[1]).isEmpty() && defaultValue(os[2]).isEmpty()) {
                throw new IllegalArgumentException((osIndex + 1) + "行小区编码和小区名称必填其一");
            }
//            Assert.hasValue(os[10], (osIndex + 1) + "行业主不能为空");
//            Assert.hasValue(os[2], (osIndex + 1) + "手机号不能为空");
//            Assert.hasValue(os[3], (osIndex + 1) + "车辆品牌不能为空");
//            Assert.hasValue(os[4], (osIndex + 1) + "车辆类型不能为空");
//            Assert.hasValue(os[5], (osIndex + 1) + "车牌类型不能为空");
//            Assert.hasValue(os[6], (osIndex + 1) + "颜色不能为空");
//            Assert.hasValue(os[7], (osIndex + 1) + "停车场不能为空");
//            Assert.hasValue(os[8], (osIndex + 1) + "车位不能为空");
//            Assert.hasValue(os[14], (osIndex + 1) + "行起租时间不能为空");
//            Assert.hasValue(os[15], (osIndex + 1) + "截止时间不能为空");
            Assert.hasValue(os[12], (osIndex + 1) + "行停车类型不能为空");
//            Assert.hasValue(os[11], (osIndex + 1) + "停车场类型不能为空");
            String startTime = os.length > 14 && os[14] != null ? Vtil.defaultValueToDate(os[14], "start") : null;
            String endTime = os.length > 15 && os[15] != null ? Vtil.defaultValueToDate(os[15], "end") : null;
//            Assert.isDate(startTime, DateUtil.DATE_FORMATE_STRING_B, (osIndex + 1) + "行开始时间格式错误 请填写YYYY-MM-DD文本格式");
//            Assert.isDate(endTime, DateUtil.DATE_FORMATE_STRING_B, (osIndex + 1) + "行结束时间格式错误 请填写YYYY-MM-DD文本格式");
            importOwnerCar = new OwnerCarDto();
            importOwnerCar.setCarNum(defaultValue(os[8]).trim());
            importOwnerCar.setOwnerName(defaultValue(os[10]).trim());
            importOwnerCar.setLink(os.length <= 11 || os[11] == null ? "" : os[11].toString().trim());
//            importOwnerCar.setCarBrand(os.length <= 3 || os[3] == null ? "" : os[3].toString().trim());
            importOwnerCar.setCarType("9901");
//            importOwnerCar.setLeaseType(os.length <= 5 || os[5] == null ? "" : os[5].toString().trim());
//            importOwnerCar.setCarColor("");
            importOwnerCar.setAreaNum(os.length <= 9 || os[9] == null ? "" : os[9].toString().trim());
            //获取车位
            String parkingLot = os.length <= 9 || os[9] == null ? "" : os[9].toString().trim();
            importOwnerCar.setNum(parkingLot);
            importOwnerCar.setLogStartTime(startTime);
            importOwnerCar.setLogEndTime(endTime);
            importOwnerCar.setTypeCd("1001");
            importOwnerCar.setSpaceSate("H");
 
            importOwnerCar.setCommunityId(result.getCommunityId());
            importOwnerCar.setUserId(result.getUserId());
            importOwnerCar.setOtherItem(os);
            importOwnerCar.setRoadName(defaultValue(os[3]));
            importOwnerCar.setFloorNum(defaultValue(os[4]));
            importOwnerCar.setUnitNum(defaultValue(os[5]));
            importOwnerCar.setRoomNum(defaultValue(os[6]));
            ownerCars.add(importOwnerCar);
        }
 
 
        sheet = ImportExcelUtils.getSheet(workbook, "地下停车费 导入新模板");
        oList = ImportExcelUtils.listFromSheet(sheet);
        importOwnerCar = null;
        for (int osIndex = 0; osIndex < oList.size(); osIndex++) {
            Object[] os = oList.get(osIndex);
            if (osIndex < 3) { // 第一行是 头部信息 直接跳过
                continue;
            }
            if (StringUtil.isNullOrNone(os[0])) {
                continue;
            }
//            Assert.hasValue(os[8], (osIndex + 1) + "行车牌号不能为空");
            if (os[8] == null || os[8].equals("")) {
                os[8] = "空";
            }
            if (defaultValue(os[1]).isEmpty() && defaultValue(os[2]).isEmpty()) {
                throw new IllegalArgumentException((osIndex + 1) + "行小区编码和小区名称必填其一");
            }
//            Assert.hasValue(os[10], (osIndex + 1) + "行业主不能为空");
//            Assert.hasValue(os[2], (osIndex + 1) + "手机号不能为空");
//            Assert.hasValue(os[3], (osIndex + 1) + "车辆品牌不能为空");
//            Assert.hasValue(os[4], (osIndex + 1) + "车辆类型不能为空");
//            Assert.hasValue(os[5], (osIndex + 1) + "车牌类型不能为空");
//            Assert.hasValue(os[6], (osIndex + 1) + "颜色不能为空");
//            Assert.hasValue(os[7], (osIndex + 1) + "停车场不能为空");
//            Assert.hasValue(os[8], (osIndex + 1) + "车位不能为空");
//            Assert.hasValue(os[14], (osIndex + 1) + "行起租时间不能为空");
//            Assert.hasValue(os[15], (osIndex + 1) + "截止时间不能为空");
            Assert.hasValue(os[12], (osIndex + 1) + "行停车类型不能为空");
//            Assert.hasValue(os[11], (osIndex + 1) + "停车场类型不能为空");
            String startTime = os.length > 14 && os[14] != null ? Vtil.defaultValueToDate(os[14], "start") : null;
            String endTime = os.length > 15 && os[15] != null ? Vtil.defaultValueToDate(os[15], "end") : null;
//            Assert.isDate(startTime, DateUtil.DATE_FORMATE_STRING_B, (osIndex + 1) + "行开始时间格式错误 请填写YYYY-MM-DD文本格式");
//            Assert.isDate(endTime, DateUtil.DATE_FORMATE_STRING_B, (osIndex + 1) + "行结束时间格式错误 请填写YYYY-MM-DD文本格式");
            importOwnerCar = new OwnerCarDto();
            importOwnerCar.setCarNum(defaultValue(os[8]).trim());
            importOwnerCar.setOwnerName(defaultValue(os[10]).trim());
            importOwnerCar.setLink(os.length <= 11 || os[11] == null ? "" : os[11].toString().trim());
//            importOwnerCar.setCarBrand(os.length <= 3 || os[3] == null ? "" : os[3].toString().trim());
            importOwnerCar.setCarType("9901");
//            importOwnerCar.setLeaseType(os.length <= 5 || os[5] == null ? "" : os[5].toString().trim());
//            importOwnerCar.setCarColor("");
            importOwnerCar.setAreaNum(os.length <= 9 || os[9] == null ? "" : os[9].toString().trim());
            //获取车位
            String parkingLot = os.length <= 9 || os[9] == null ? "" : os[9].toString().trim();
            importOwnerCar.setNum(parkingLot);
            importOwnerCar.setLogStartTime(startTime);
            importOwnerCar.setLogEndTime(endTime);
            importOwnerCar.setTypeCd("2001");
            importOwnerCar.setSpaceSate("H");
            importOwnerCar.setCommunityId(result.getCommunityId());
            importOwnerCar.setUserId(result.getUserId());
            importOwnerCar.setOtherItem(os);
            importOwnerCar.setRoadName(defaultValue(os[3]));
            importOwnerCar.setFloorNum(defaultValue(os[4]));
            importOwnerCar.setUnitNum(defaultValue(os[5]));
            importOwnerCar.setRoomNum(defaultValue(os[6]));
            importOwnerCar.setParkingType(defaultValue(os[12]));
            ownerCars.add(importOwnerCar);
        }
    }
 
 
    /**
     * 数据格式校验
     *
     * @param ownerCars
     */
    private void validateCarInfo(List<OwnerCarDto> ownerCars) {
        for (OwnerCarDto ownerCarDto : ownerCars) {
            if ("".equals(ownerCarDto.getTypeCd()) || ownerCarDto.getTypeCd() == null) {
                continue;
            }
            if (!"1001".equals(ownerCarDto.getTypeCd()) && !"2001".equals(ownerCarDto.getTypeCd())) {
                throw new IllegalArgumentException(ownerCarDto.getCarNum() + "停车场类型应填写 1001(地上停车场)或者 2001 (地下停车场)");
            }
            if (!"H".equals(ownerCarDto.getSpaceSate()) && !"S".equals(ownerCarDto.getSpaceSate())) {
                throw new IllegalArgumentException(ownerCarDto.getCarNum() + "车位状态应填写 S(出售)或者 H (出租)");
            }
 
 
        }
    }
}