java110
2021-09-11 7ac92c5c1c386cc294ca0475a3bb7ecbd973f4dc
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
package com.java110.api.smo.assetImport.impl;
 
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.java110.api.smo.DefaultAbstractComponentSMO;
import com.java110.core.component.BaseComponentSMO;
import com.java110.core.context.IPageData;
import com.java110.core.smo.ISaveTransactionLogSMO;
import com.java110.dto.RoomDto;
import com.java110.dto.assetImportLog.AssetImportLogDto;
import com.java110.dto.assetImportLogDetail.AssetImportLogDetailDto;
import com.java110.entity.assetImport.*;
import com.java110.entity.component.ComponentValidateResult;
import com.java110.api.smo.assetImport.IAssetImportSMO;
import com.java110.utils.constant.ServiceConstant;
import com.java110.utils.util.*;
import com.java110.vo.ResultVo;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.multipart.MultipartFile;
 
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
/**
 * @ClassName AssetImportSmoImpl
 * @Description TODO
 * @Author wuxw
 * @Date 2019/9/23 23:14
 * @Version 1.0
 * add by wuxw 2019/9/23
 **/
@Service("assetImportSMOImpl")
public class AssetImportSMOImpl extends DefaultAbstractComponentSMO implements IAssetImportSMO {
    private final static Logger logger = LoggerFactory.getLogger(AssetImportSMOImpl.class);
 
    @Autowired
    private RestTemplate restTemplate;
 
    @Autowired
    private ISaveTransactionLogSMO saveTransactionLogSMOImpl;
 
    @Override
    public ResponseEntity<String> importExcelData(IPageData pd, MultipartFile uploadFile) throws Exception {
 
        try {
            ComponentValidateResult result = this.validateStoreStaffCommunityRelationship(pd, restTemplate);
 
            //InputStream is = uploadFile.getInputStream();
 
            Workbook workbook = null;  //工作簿
            //工作表
            String[] headers = null;   //表头信息
            List<ImportFloor> floors = new ArrayList<ImportFloor>();
            List<ImportOwner> owners = new ArrayList<ImportOwner>();
            List<ImportFee> fees = new ArrayList<>();
            List<ImportRoom> rooms = new ArrayList<ImportRoom>();
            List<ImportParkingSpace> parkingSpaces = new ArrayList<ImportParkingSpace>();
            workbook = ImportExcelUtils.createWorkbook(uploadFile);
            //获取楼信息
            getFloors(workbook, floors);
            //获取业主信息
            getOwners(workbook, owners);
 
 
            getFee(workbook, fees);
 
            //获取房屋信息
            getRooms(workbook, rooms, floors, owners);
 
            //获取车位信息
            getParkingSpaces(workbook, parkingSpaces, owners);
 
            //数据校验
            importExcelDataValidate(floors, owners, rooms, fees, parkingSpaces);
 
            // 保存数据
            return dealExcelData(pd, floors, owners, rooms, parkingSpaces, fees, result);
        } catch (Exception e) {
            logger.error("导入失败 ", e);
            return new ResponseEntity<String>("非常抱歉,您填写的模板数据有误:" + e.getMessage(), HttpStatus.BAD_REQUEST);
        }
    }
 
    /**
     * 处理ExcelData数据
     *
     * @param floors        楼栋单元信息
     * @param owners        业主信息
     * @param rooms         房屋信息
     * @param parkingSpaces 车位信息
     */
    private ResponseEntity<String> dealExcelData(IPageData pd,
                                                 List<ImportFloor> floors,
                                                 List<ImportOwner> owners,
                                                 List<ImportRoom> rooms,
                                                 List<ImportParkingSpace> parkingSpaces,
                                                 List<ImportFee> fees,
                                                 ComponentValidateResult result) {
        ResponseEntity<String> responseEntity = null;
        //保存单元信息 和 楼栋信息
        responseEntity = savedFloorAndUnitInfo(pd, floors, result);
 
        if (responseEntity == null || responseEntity.getStatusCode() != HttpStatus.OK) {
            return responseEntity;
        }
 
        // 保存业主信息
        responseEntity = savedOwnerInfo(pd, owners, result);
        if (responseEntity == null || responseEntity.getStatusCode() != HttpStatus.OK) {
            return responseEntity;
        }
 
        // 保存费用项
        responseEntity = savedFeeInfo(pd, fees, result);
        if (responseEntity == null || responseEntity.getStatusCode() != HttpStatus.OK) {
            return responseEntity;
        }
 
        //保存房屋
        responseEntity = savedRoomInfo(pd, rooms, fees, result);
        if (responseEntity == null || responseEntity.getStatusCode() != HttpStatus.OK) {
            return responseEntity;
        }
 
        //保存车位
        responseEntity = savedParkingSpaceInfo(pd, parkingSpaces, result);
 
        if (responseEntity == null || responseEntity.getStatusCode() != HttpStatus.OK) {
            return responseEntity;
        }
 
        return responseEntity;
    }
 
    private ResponseEntity<String> savedFeeInfo(IPageData pd, List<ImportFee> fees, ComponentValidateResult result) {
        String apiUrl = "";
        JSONObject paramIn = null;
        ResponseEntity<String> responseEntity = new ResponseEntity<String>("成功", HttpStatus.OK);
        ImportOwner owner = null;
 
        AssetImportLogDto assetImportLogDto = new AssetImportLogDto();
        assetImportLogDto.setSuccessCount(0L);
        assetImportLogDto.setErrorCount(0L);
        assetImportLogDto.setCommunityId(result.getCommunityId());
        assetImportLogDto.setLogType(AssetImportLogDto.LOG_TYPE_FEE_IMPORT);
        List<AssetImportLogDetailDto> assetImportLogDetailDtos = new ArrayList<>();
        assetImportLogDto.setAssetImportLogDetailDtos(assetImportLogDetailDtos);
        long successCount = 0L;
        long failCount = 0L;
        AssetImportLogDetailDto assetImportLogDetailDto = null;
        try {
            for (ImportFee fee : fees) {
                JSONObject savedFeeConfigInfo = getExistsFee(pd, result, fee);
                if (savedFeeConfigInfo != null) {
                    successCount += 1;
                    assetImportLogDto.setSuccessCount(successCount);
                    assetImportLogDto.setErrorCount(failCount);
                    continue;
                }
                //paramIn = new JSONObject();
                //保存 费用项
 
                apiUrl = ServiceConstant.SERVICE_API_URL + "/api/feeConfig.saveFeeConfig";
 
                paramIn = JSONObject.parseObject(JSONObject.toJSONString(fee));
                paramIn.put("communityId", result.getCommunityId());
 
                responseEntity = this.callCenterService(restTemplate, pd, paramIn.toJSONString(), apiUrl, HttpMethod.POST);
                if (responseEntity.getStatusCode() != HttpStatus.OK) {
                    /***************************************导入日志记录****************************************************/
                    failCount += 1;
                    assetImportLogDetailDto = new AssetImportLogDetailDto();
                    assetImportLogDetailDto.setCommunityId(assetImportLogDto.getCommunityId());
                    if (Assert.isJsonObject(responseEntity.getBody())) {
                        JSONObject paramOut = JSONObject.parseObject(responseEntity.getBody());
                        assetImportLogDetailDto.setState(paramOut.getString("code"));
                        assetImportLogDetailDto.setMessage(paramOut.getString("msg"));
                    } else {
                        assetImportLogDetailDto.setState("F");
                        assetImportLogDetailDto.setMessage(responseEntity.getBody());
                    }
                    assetImportLogDetailDto.setObjName(fee.getFeeName());
                    assetImportLogDetailDtos.add(assetImportLogDetailDto);
                } else {
                    JSONObject body = JSONObject.parseObject(responseEntity.getBody());
                    if (body.containsKey("code") && body.getIntValue("code") != 0) {
                        assetImportLogDetailDto = new AssetImportLogDetailDto();
                        assetImportLogDetailDto.setCommunityId(assetImportLogDto.getCommunityId());
                        assetImportLogDetailDto.setState(body.getString("code"));
                        assetImportLogDetailDto.setMessage(body.getString("msg"));
                        assetImportLogDetailDto.setObjName(fee.getFeeName());
                        assetImportLogDetailDtos.add(assetImportLogDetailDto);
                        failCount += 1;
                    } else {
                        successCount += 1;
                    }
                }
                assetImportLogDto.setSuccessCount(successCount);
                assetImportLogDto.setErrorCount(failCount);
            }
        } finally {
            saveTransactionLogSMOImpl.saveAssetImportLog(assetImportLogDto);
        }
 
        return responseEntity;
    }
 
    /**
     * 保存车位信息
     *
     * @param pd
     * @param parkingSpaces
     * @param result
     * @return
     */
    private ResponseEntity<String> savedParkingSpaceInfo(IPageData pd, List<ImportParkingSpace> parkingSpaces, ComponentValidateResult result) {
        String apiUrl = "";
        JSONObject paramIn = null;
        ResponseEntity<String> responseEntity = new ResponseEntity<String>("成功", HttpStatus.OK);
        ImportOwner owner = null;
        AssetImportLogDto assetImportLogDto = new AssetImportLogDto();
        assetImportLogDto.setSuccessCount(0L);
        assetImportLogDto.setErrorCount(0L);
        assetImportLogDto.setCommunityId(result.getCommunityId());
        assetImportLogDto.setLogType(AssetImportLogDto.LOG_TYPE_AREA_PARKING_IMPORT);
        List<AssetImportLogDetailDto> assetImportLogDetailDtos = new ArrayList<>();
        assetImportLogDto.setAssetImportLogDetailDtos(assetImportLogDetailDtos);
        long successCount = 0L;
        long failCount = 0L;
        AssetImportLogDetailDto assetImportLogDetailDto = null;
        try {
            for (ImportParkingSpace parkingSpace : parkingSpaces) {
                responseEntity = ResultVo.success();
                JSONObject savedParkingAreaInfo = getExistsParkingArea(pd, result, parkingSpace);
                paramIn = new JSONObject();
                // 如果不存在,才插入
                if (savedParkingAreaInfo == null) {
                    apiUrl = ServiceConstant.SERVICE_API_URL + "/api/parkingArea.saveParkingArea";
                    paramIn.put("communityId", result.getCommunityId());
                    paramIn.put("typeCd", parkingSpace.getTypeCd());
                    paramIn.put("num", parkingSpace.getPaNum());
 
                    responseEntity = this.callCenterService(restTemplate, pd, paramIn.toJSONString(), apiUrl, HttpMethod.POST);
                    savedParkingAreaInfo = getExistsParkingArea(pd, result, parkingSpace);
                }
                if (responseEntity != null && responseEntity.getStatusCode() != HttpStatus.OK) { //跳过 保存单元信息
                    failCount += 1;
                    assetImportLogDetailDto = new AssetImportLogDetailDto();
                    assetImportLogDetailDto.setCommunityId(assetImportLogDto.getCommunityId());
                    if (Assert.isJsonObject(responseEntity.getBody())) {
                        JSONObject paramOut = JSONObject.parseObject(responseEntity.getBody());
                        assetImportLogDetailDto.setState(paramOut.getString("code"));
                        assetImportLogDetailDto.setMessage(paramOut.getString("msg"));
                    } else {
                        assetImportLogDetailDto.setState("F");
                        assetImportLogDetailDto.setMessage(responseEntity.getBody());
                    }
                    assetImportLogDetailDto.setObjName(parkingSpace.getPaNum());
                    assetImportLogDetailDtos.add(assetImportLogDetailDto);
                    assetImportLogDto.setSuccessCount(successCount);
                    assetImportLogDto.setErrorCount(failCount);
                    continue;
                } else {
                    JSONObject body = JSONObject.parseObject(responseEntity.getBody());
                    if (body.containsKey("code") && body.getIntValue("code") != 0) {
                        assetImportLogDetailDto = new AssetImportLogDetailDto();
                        assetImportLogDetailDto.setCommunityId(assetImportLogDto.getCommunityId());
                        assetImportLogDetailDto.setState(body.getString("code"));
                        assetImportLogDetailDto.setMessage(body.getString("msg"));
                        assetImportLogDetailDto.setObjName(parkingSpace.getPaNum());
                        assetImportLogDetailDtos.add(assetImportLogDetailDto);
                        failCount += 1;
                        assetImportLogDto.setSuccessCount(successCount);
                        assetImportLogDto.setErrorCount(failCount);
                        continue;
                    } else {
                        successCount += 1;
                    }
                    assetImportLogDto.setSuccessCount(successCount);
                    assetImportLogDto.setErrorCount(failCount);
                }
 
                JSONObject savedParkingSpaceInfo = getExistsParkSpace(pd, result, parkingSpace);
                if (savedParkingSpaceInfo != null) {
                    continue;
                }
 
                apiUrl = ServiceConstant.SERVICE_API_URL + "/api/parkingSpace.saveParkingSpace";
 
                paramIn.put("paId", savedParkingAreaInfo.getString("paId"));
                paramIn.put("communityId", result.getCommunityId());
                paramIn.put("userId", result.getUserId());
                paramIn.put("num", parkingSpace.getPsNum());
                paramIn.put("area", parkingSpace.getArea());
                paramIn.put("typeCd", parkingSpace.getTypeCd());
                paramIn.put("parkingType", "1");
 
                responseEntity = this.callCenterService(restTemplate, pd, paramIn.toJSONString(), apiUrl, HttpMethod.POST);
                if (responseEntity.getStatusCode() != HttpStatus.OK) {
                    assetImportLogDetailDto = new AssetImportLogDetailDto();
                    assetImportLogDetailDto.setCommunityId(assetImportLogDto.getCommunityId());
                    if (Assert.isJsonObject(responseEntity.getBody())) {
                        JSONObject paramOut = JSONObject.parseObject(responseEntity.getBody());
                        assetImportLogDetailDto.setState(paramOut.getString("code"));
                        assetImportLogDetailDto.setMessage(paramOut.getString("msg"));
                    } else {
                        assetImportLogDetailDto.setState("F");
                        assetImportLogDetailDto.setMessage(responseEntity.getBody());
                    }
                    assetImportLogDetailDto.setObjName(parkingSpace.getPaNum());
                    assetImportLogDetailDtos.add(assetImportLogDetailDto);
                    failCount += 1;
                    successCount = successCount > 0 ? successCount - 1 : successCount;
                    assetImportLogDto.setSuccessCount(successCount);
                    assetImportLogDto.setErrorCount(failCount);
                    continue;
                } else {
                    JSONObject body = JSONObject.parseObject(responseEntity.getBody());
                    if (body.containsKey("code") && body.getIntValue("code") != 0) {
                        assetImportLogDetailDto = new AssetImportLogDetailDto();
                        assetImportLogDetailDto.setCommunityId(assetImportLogDto.getCommunityId());
                        assetImportLogDetailDto.setState(body.getString("code"));
                        assetImportLogDetailDto.setMessage(body.getString("msg"));
                        assetImportLogDetailDto.setObjName(parkingSpace.getPaNum());
                        assetImportLogDetailDtos.add(assetImportLogDetailDto);
                        assetImportLogDto.setSuccessCount(successCount);
                        assetImportLogDto.setErrorCount(failCount);
                        failCount += 1;
                        successCount = successCount > 0 ? successCount - 1 : successCount;
                        assetImportLogDto.setSuccessCount(successCount);
                        assetImportLogDto.setErrorCount(failCount);
                        continue;
                    }
                }
 
                savedParkingSpaceInfo = getExistsParkSpace(pd, result, parkingSpace);
                if (savedParkingSpaceInfo == null) {
                    continue;
                }
 
                //是否有业主信息
                if (parkingSpace.getImportOwner() == null) {
                    continue;
                }
 
                paramIn.clear();
 
                paramIn.put("communityId", result.getCommunityId());
                paramIn.put("ownerId", parkingSpace.getImportOwner().getOwnerId());
                paramIn.put("userId", result.getUserId());
                paramIn.put("carNum", parkingSpace.getCarNum());
                paramIn.put("carBrand", parkingSpace.getCarBrand());
                paramIn.put("carType", parkingSpace.getCarType());
                paramIn.put("carColor", parkingSpace.getCarColor());
                paramIn.put("psId", savedParkingSpaceInfo.getString("psId"));
                paramIn.put("storeId", result.getStoreId());
                paramIn.put("sellOrHire", parkingSpace.getSellOrHire());
                paramIn.put("startTime", parkingSpace.getStartTime());
                paramIn.put("endTime", parkingSpace.getEndTime());
 
                if ("H".equals(parkingSpace.getSellOrHire())) {
                    paramIn.put("cycles", "0");
                }
 
                apiUrl = ServiceConstant.SERVICE_API_URL + "/api/parkingSpace.sellParkingSpace";
                responseEntity = this.callCenterService(restTemplate, pd, paramIn.toJSONString(), apiUrl, HttpMethod.POST);
 
                if (responseEntity.getStatusCode() != HttpStatus.OK) {
                    /***************************************导入日志记录****************************************************/
                    assetImportLogDetailDto = new AssetImportLogDetailDto();
                    assetImportLogDetailDto.setCommunityId(assetImportLogDto.getCommunityId());
                    if (Assert.isJsonObject(responseEntity.getBody())) {
                        JSONObject paramOut = JSONObject.parseObject(responseEntity.getBody());
                        assetImportLogDetailDto.setState(paramOut.getString("code"));
                        assetImportLogDetailDto.setMessage(paramOut.getString("msg"));
                    } else {
                        assetImportLogDetailDto.setState("F");
                        assetImportLogDetailDto.setMessage(responseEntity.getBody());
                    }
                    assetImportLogDetailDto.setObjName(parkingSpace.getCarNum());
                    assetImportLogDetailDtos.add(assetImportLogDetailDto);
                    failCount += 1;
                    successCount = successCount > 0 ? successCount - 1 : successCount;
                    assetImportLogDto.setSuccessCount(successCount);
                    assetImportLogDto.setErrorCount(failCount);
                } else {
                    JSONObject body = JSONObject.parseObject(responseEntity.getBody());
                    if (body.containsKey("code") && body.getIntValue("code") != 0) {
                        assetImportLogDetailDto = new AssetImportLogDetailDto();
                        assetImportLogDetailDto.setCommunityId(assetImportLogDto.getCommunityId());
                        assetImportLogDetailDto.setState(body.getString("code"));
                        assetImportLogDetailDto.setMessage(body.getString("msg"));
                        assetImportLogDetailDto.setObjName(parkingSpace.getCarNum());
                        assetImportLogDetailDtos.add(assetImportLogDetailDto);
                        failCount += 1;
                        successCount = successCount > 0 ? successCount - 1 : successCount;
                        assetImportLogDto.setSuccessCount(successCount);
                        assetImportLogDto.setErrorCount(failCount);
                    }
                }
            }
        } catch (Exception e) {
            logger.error("导入车位异常", e);
            saveTransactionLogSMOImpl.saveAssetImportLog(assetImportLogDto);
            throw e;
        }
 
        return responseEntity;
    }
 
 
    /**
     * 保存房屋信息
     *
     * @param pd
     * @param rooms
     * @param result
     * @return
     */
    private ResponseEntity<String> savedRoomInfo(IPageData pd, List<ImportRoom> rooms, List<ImportFee> fees, ComponentValidateResult result) {
        String apiUrl = "";
        JSONObject paramIn = null;
        ResponseEntity<String> responseEntity = new ResponseEntity<String>("成功", HttpStatus.OK);
        ImportOwner owner = null;
        AssetImportLogDto assetImportLogDto = new AssetImportLogDto();
        assetImportLogDto.setSuccessCount(0L);
        assetImportLogDto.setErrorCount(0L);
        assetImportLogDto.setCommunityId(result.getCommunityId());
        assetImportLogDto.setLogType(AssetImportLogDto.LOG_TYPE_ROOM_IMPORT);
        List<AssetImportLogDetailDto> assetImportLogDetailDtos = new ArrayList<>();
        assetImportLogDto.setAssetImportLogDetailDtos(assetImportLogDetailDtos);
        long successCount = 0L;
        long failCount = 0L;
        AssetImportLogDetailDto assetImportLogDetailDto = null;
        try {
            for (ImportRoom room : rooms) {
                JSONObject savedRoomInfo = getExistsRoom(pd, result, room);
                if (savedRoomInfo != null) {
                    continue;
                }
 
                paramIn = new JSONObject();
 
 
                //保存 房屋
                apiUrl = ServiceConstant.SERVICE_API_URL + "/api/room.saveRoom";
 
                paramIn.put("communityId", result.getCommunityId());
                paramIn.put("unitId", room.getFloor().getUnitId());
                paramIn.put("roomNum", room.getRoomNum());
                paramIn.put("layer", room.getLayer());
                paramIn.put("section", "1");
                paramIn.put("apartment", room.getSection());
                paramIn.put("state", "2002");
                paramIn.put("builtUpArea", room.getBuiltUpArea());
                paramIn.put("feeCoefficient", "1.00");
                paramIn.put("roomSubType", room.getRoomSubType());
                paramIn.put("roomArea", room.getRoomArea());
                paramIn.put("roomRent", room.getRoomRent());
                paramIn.put("roomType", "0".equals(room.getFloor().getUnitNum()) ? RoomDto.ROOM_TYPE_SHOPS : RoomDto.ROOM_TYPE_SHOPS);
 
 
                responseEntity = this.callCenterService(restTemplate, pd, paramIn.toJSONString(), apiUrl, HttpMethod.POST);
                if (responseEntity.getStatusCode() != HttpStatus.OK) {
                    failCount += 1;
                    assetImportLogDetailDto = new AssetImportLogDetailDto();
                    assetImportLogDetailDto.setCommunityId(assetImportLogDto.getCommunityId());
                    if (Assert.isJsonObject(responseEntity.getBody())) {
                        JSONObject paramOut = JSONObject.parseObject(responseEntity.getBody());
                        assetImportLogDetailDto.setState(paramOut.getString("code"));
                        assetImportLogDetailDto.setMessage(paramOut.getString("msg"));
                    } else {
                        assetImportLogDetailDto.setState("F");
                        assetImportLogDetailDto.setMessage(responseEntity.getBody());
                    }
                    assetImportLogDetailDto.setObjName(room.getRoomNum() + "室");
                    assetImportLogDetailDtos.add(assetImportLogDetailDto);
                    assetImportLogDto.setSuccessCount(successCount);
                    assetImportLogDto.setErrorCount(failCount);
                    continue;
                } else {
                    JSONObject body = JSONObject.parseObject(responseEntity.getBody());
                    if (body.containsKey("code") && body.getIntValue("code") != 0) {
                        assetImportLogDetailDto = new AssetImportLogDetailDto();
                        assetImportLogDetailDto.setCommunityId(assetImportLogDto.getCommunityId());
                        assetImportLogDetailDto.setState(body.getString("code"));
                        assetImportLogDetailDto.setMessage(body.getString("msg"));
                        assetImportLogDetailDto.setObjName(room.getRoomNum() + "室");
                        assetImportLogDetailDtos.add(assetImportLogDetailDto);
                        failCount += 1;
                        assetImportLogDto.setSuccessCount(successCount);
                        assetImportLogDto.setErrorCount(failCount);
                        continue;
                    } else {
                        successCount += 1;
                        assetImportLogDto.setSuccessCount(successCount);
                        assetImportLogDto.setErrorCount(failCount);
                    }
                }
 
                savedRoomInfo = getExistsRoom(pd, result, room);
                if (savedRoomInfo == null) {
                    continue;
                }
                if (room.getImportOwner() == null) {
                    continue;
                }
                paramIn.clear();
                apiUrl = ServiceConstant.SERVICE_API_URL + "/api/room.sellRoom";
                paramIn.put("communityId", result.getCommunityId());
                paramIn.put("ownerId", room.getImportOwner().getOwnerId());
                paramIn.put("roomId", savedRoomInfo.getString("roomId"));
                paramIn.put("state", "2001");
                paramIn.put("storeId", result.getStoreId());
                if (!StringUtil.isEmpty(room.getRoomFeeId()) && "0".equals(room.getRoomFeeId())) {
                    paramIn.put("feeEndDate", room.getFeeEndDate());
                }
                responseEntity = this.callCenterService(restTemplate, pd, paramIn.toJSONString(), apiUrl, HttpMethod.POST);
                if (responseEntity.getStatusCode() != HttpStatus.OK) {
                    assetImportLogDetailDto = new AssetImportLogDetailDto();
                    assetImportLogDetailDto.setCommunityId(assetImportLogDto.getCommunityId());
                    if (Assert.isJsonObject(responseEntity.getBody())) {
                        JSONObject paramOut = JSONObject.parseObject(responseEntity.getBody());
                        assetImportLogDetailDto.setState(paramOut.getString("code"));
                        assetImportLogDetailDto.setMessage(paramOut.getString("msg"));
                    } else {
                        assetImportLogDetailDto.setState("F");
                        assetImportLogDetailDto.setMessage(responseEntity.getBody());
                    }
                    assetImportLogDetailDto.setObjName(room.getRoomNum() + "室");
                    assetImportLogDetailDtos.add(assetImportLogDetailDto);
                    continue;
                } else {
                    JSONObject body = JSONObject.parseObject(responseEntity.getBody());
                    if (body.containsKey("code") && body.getIntValue("code") != 0) {
                        assetImportLogDetailDto = new AssetImportLogDetailDto();
                        assetImportLogDetailDto.setCommunityId(assetImportLogDto.getCommunityId());
                        assetImportLogDetailDto.setState(body.getString("code"));
                        assetImportLogDetailDto.setMessage(body.getString("msg"));
                        assetImportLogDetailDto.setObjName(room.getRoomNum() + "室");
                        assetImportLogDetailDtos.add(assetImportLogDetailDto);
                        continue;
                    }
                }
                //创建费用
                if (StringUtil.isEmpty(room.getRoomFeeId()) || "0".equals(room.getRoomFeeId())) {
                    continue;
                }
                String[] feeIds = room.getRoomFeeId().split("#");
 
                for (int feeIndex = 0; feeIndex < feeIds.length; feeIndex++) {
                    String feeId = feeIds[feeIndex];
                    ImportFee tmpFee = null;
                    for (ImportFee fee : fees) {
                        if (feeId.equals(fee.getId())) {
                            tmpFee = fee;
                        }
                    }
 
                    if (tmpFee == null) {
                        continue;//没有费用项,可能写错了
                    }
 
                    JSONObject ttFee = getExistsFee(pd, result, tmpFee);
 
                    if (ttFee == null) {
                        continue;//没有费用项,可能写错了
                    }
 
                    apiUrl = ServiceConstant.SERVICE_API_URL + "/api/fee.saveRoomCreateFee";
                    paramIn.put("communityId", result.getCommunityId());
                    paramIn.put("locationTypeCd", "3000");
                    paramIn.put("locationObjId", savedRoomInfo.getString("roomId"));
                    paramIn.put("configId", ttFee.getString("configId"));
                    paramIn.put("storeId", result.getStoreId());
                    paramIn.put("feeEndDate", room.getFeeEndDate().split("#")[feeIndex]);
                    paramIn.put("startTime", paramIn.getString("feeEndDate"));
 
                    responseEntity = this.callCenterService(restTemplate, pd, paramIn.toJSONString(), apiUrl, HttpMethod.POST);
 
                    if (responseEntity.getStatusCode() != HttpStatus.OK) {
                        /***************************************导入日志记录****************************************************/
                        assetImportLogDetailDto = new AssetImportLogDetailDto();
                        assetImportLogDetailDto.setCommunityId(assetImportLogDto.getCommunityId());
                        if (Assert.isJsonObject(responseEntity.getBody())) {
                            JSONObject paramOut = JSONObject.parseObject(responseEntity.getBody());
                            assetImportLogDetailDto.setState(paramOut.getString("code"));
                            assetImportLogDetailDto.setMessage(paramOut.getString("msg"));
                        } else {
                            assetImportLogDetailDto.setState("F");
                            assetImportLogDetailDto.setMessage(responseEntity.getBody());
                        }
                        assetImportLogDetailDto.setObjName(room.getRoomNum() + "室");
                        assetImportLogDetailDtos.add(assetImportLogDetailDto);
                        failCount += 1;
                        successCount = successCount > 0 ? successCount - 1 : successCount;
                        assetImportLogDto.setSuccessCount(successCount);
                        assetImportLogDto.setErrorCount(failCount);
                    } else {
                        JSONObject body = JSONObject.parseObject(responseEntity.getBody());
                        if (body.containsKey("code") && body.getIntValue("code") != 0) {
                            assetImportLogDetailDto = new AssetImportLogDetailDto();
                            assetImportLogDetailDto.setCommunityId(assetImportLogDto.getCommunityId());
                            assetImportLogDetailDto.setState(body.getString("code"));
                            assetImportLogDetailDto.setMessage(body.getString("msg"));
                            assetImportLogDetailDto.setObjName(room.getRoomNum() + "室");
                            assetImportLogDetailDtos.add(assetImportLogDetailDto);
                            failCount += 1;
                            successCount = successCount > 0 ? successCount - 1 : successCount;
                            assetImportLogDto.setSuccessCount(successCount);
                            assetImportLogDto.setErrorCount(failCount);
                        }
                    }
                }
 
            }
        } finally {
            saveTransactionLogSMOImpl.saveAssetImportLog(assetImportLogDto);
        }
 
        return responseEntity;
    }
 
    /**
     * 查询存在的房屋信息
     * room.queryRooms
     *
     * @param pd
     * @param result
     * @param parkingSpace
     * @return
     */
    private JSONObject getExistsParkSpace(IPageData pd, ComponentValidateResult result, ImportParkingSpace parkingSpace) {
        String apiUrl = "";
        ResponseEntity<String> responseEntity = null;
        apiUrl = ServiceConstant.SERVICE_API_URL + "/api/parkingSpace.queryParkingSpaces?page=1&row=1&communityId=" + result.getCommunityId()
                + "&num=" + parkingSpace.getPsNum() + "&areaNum=" + parkingSpace.getPaNum();
        responseEntity = this.callCenterService(restTemplate, pd, "", apiUrl, HttpMethod.GET);
 
        if (responseEntity.getStatusCode() != HttpStatus.OK) { //跳过 保存单元信息
            return null;
        }
 
        JSONObject savedParkingSpaceInfoResults = JSONObject.parseObject(responseEntity.getBody());
 
 
        if (!savedParkingSpaceInfoResults.containsKey("parkingSpaces") || savedParkingSpaceInfoResults.getJSONArray("parkingSpaces").size() != 1) {
            return null;
        }
 
 
        JSONObject savedParkingSpaceInfo = savedParkingSpaceInfoResults.getJSONArray("parkingSpaces").getJSONObject(0);
 
        return savedParkingSpaceInfo;
    }
 
    /**
     * 查询存在的房屋信息
     * room.queryRooms
     *
     * @param pd
     * @param result
     * @param fee
     * @return
     */
    private JSONObject getExistsFee(IPageData pd, ComponentValidateResult result, ImportFee fee) {
        String apiUrl = "";
        ResponseEntity<String> responseEntity = null;
        apiUrl = ServiceConstant.SERVICE_API_URL + "/api/feeConfig.listFeeConfigs?page=1&row=1&communityId=" + result.getCommunityId()
                + "&feeName=" + fee.getFeeName();
        responseEntity = this.callCenterService(restTemplate, pd, "", apiUrl, HttpMethod.GET);
 
        if (responseEntity.getStatusCode() != HttpStatus.OK) { //跳过 保存单元信息
            return null;
        }
 
        JSONObject savedRoomInfoResults = JSONObject.parseObject(responseEntity.getBody());
 
 
        if (!savedRoomInfoResults.containsKey("feeConfigs") || savedRoomInfoResults.getJSONArray("feeConfigs").size() != 1) {
            return null;
        }
 
 
        JSONObject savedFeeConfigInfo = savedRoomInfoResults.getJSONArray("feeConfigs").getJSONObject(0);
 
        return savedFeeConfigInfo;
    }
 
 
    /**
     * 查询存在的房屋信息
     * room.queryRooms
     *
     * @param pd
     * @param result
     * @param room
     * @return
     */
    private JSONObject getExistsRoom(IPageData pd, ComponentValidateResult result, ImportRoom room) {
        String apiUrl = "";
        ResponseEntity<String> responseEntity = null;
        apiUrl = ServiceConstant.SERVICE_API_URL + "/api/room.queryRooms?page=1&row=1&communityId=" + result.getCommunityId()
                + "&floorId=" + room.getFloor().getFloorId() + "&unitId=" + room.getFloor().getUnitId() + "&roomNum=" + room.getRoomNum();
        responseEntity = this.callCenterService(restTemplate, pd, "", apiUrl, HttpMethod.GET);
 
        if (responseEntity.getStatusCode() != HttpStatus.OK) { //跳过 保存单元信息
            return null;
        }
 
        JSONObject savedRoomInfoResults = JSONObject.parseObject(responseEntity.getBody());
 
 
        if (!savedRoomInfoResults.containsKey("rooms") || savedRoomInfoResults.getJSONArray("rooms").size() != 1) {
            return null;
        }
 
 
        JSONObject savedRoomInfo = savedRoomInfoResults.getJSONArray("rooms").getJSONObject(0);
 
        return savedRoomInfo;
    }
 
    /**
     * 保存业主信息
     *
     * @param pd
     * @param owners
     * @param result
     * @return
     */
    private ResponseEntity<String> savedOwnerInfo(IPageData pd, List<ImportOwner> owners, ComponentValidateResult result) {
        String apiUrl = "";
        JSONObject paramIn = null;
        ResponseEntity<String> responseEntity = new ResponseEntity<String>("成功", HttpStatus.OK);
        AssetImportLogDto assetImportLogDto = new AssetImportLogDto();
        assetImportLogDto.setSuccessCount(0L);
        assetImportLogDto.setErrorCount(0L);
        assetImportLogDto.setCommunityId(result.getCommunityId());
        assetImportLogDto.setLogType(AssetImportLogDto.LOG_TYPE_OWENR_IMPORT);
        List<AssetImportLogDetailDto> assetImportLogDetailDtos = new ArrayList<>();
        assetImportLogDto.setAssetImportLogDetailDtos(assetImportLogDetailDtos);
        long successCount = 0L;
        long failCount = 0L;
        AssetImportLogDetailDto assetImportLogDetailDto = null;
        try {
            for (ImportOwner owner : owners) {
                JSONObject savedOwnerInfo = getExistsOwner(pd, result, owner);
 
                if (savedOwnerInfo != null) {
                    owner.setOwnerId(savedOwnerInfo.getString("ownerId"));
                    continue;
                }
                paramIn = new JSONObject();
 
                apiUrl = ServiceConstant.SERVICE_API_URL + "/api/owner.saveOwner";
 
                paramIn.put("communityId", result.getCommunityId());
                paramIn.put("userId", result.getUserId());
                paramIn.put("name", owner.getOwnerName());
                paramIn.put("age", owner.getAge());
                paramIn.put("link", owner.getTel());
                paramIn.put("sex", owner.getSex());
                paramIn.put("ownerTypeCd", "1001");
                paramIn.put("idCard", owner.getIdCard());
                paramIn.put("source", "BatchImport");
                responseEntity = this.callCenterService(restTemplate, pd, paramIn.toJSONString(), apiUrl, HttpMethod.POST);
 
                /***************************************导入日志记录****************************************************/
                if (responseEntity.getStatusCode() == HttpStatus.OK) {
                    JSONObject body = JSONObject.parseObject(responseEntity.getBody());
                    if (body.containsKey("code") && body.getIntValue("code") != 0) {
                        assetImportLogDetailDto = new AssetImportLogDetailDto();
                        assetImportLogDetailDto.setCommunityId(assetImportLogDto.getCommunityId());
                        assetImportLogDetailDto.setState(body.getString("code"));
                        assetImportLogDetailDto.setMessage(body.getString("msg"));
                        assetImportLogDetailDto.setObjName(owner.getOwnerName());
                        assetImportLogDetailDtos.add(assetImportLogDetailDto);
                        failCount += 1;
                        assetImportLogDto.setSuccessCount(successCount);
                        assetImportLogDto.setErrorCount(failCount);
                        throw new IllegalArgumentException(body.getString("msg"));
                    }
                    savedOwnerInfo = getExistsOwner(pd, result, owner);
                    owner.setOwnerId(savedOwnerInfo.getString("ownerId"));
                    successCount += 1;
                } else {
                    failCount += 1;
                    assetImportLogDetailDto = new AssetImportLogDetailDto();
                    assetImportLogDetailDto.setCommunityId(assetImportLogDto.getCommunityId());
                    if (Assert.isJsonObject(responseEntity.getBody())) {
                        JSONObject paramOut = JSONObject.parseObject(responseEntity.getBody());
                        assetImportLogDetailDto.setState(paramOut.getString("code"));
                        assetImportLogDetailDto.setMessage(paramOut.getString("msg"));
                    } else {
                        assetImportLogDetailDto.setState("F");
                        assetImportLogDetailDto.setMessage(responseEntity.getBody());
                    }
                    assetImportLogDetailDto.setObjName(owner.getOwnerName());
                    assetImportLogDetailDtos.add(assetImportLogDetailDto);
                }
                assetImportLogDto.setSuccessCount(successCount);
                assetImportLogDto.setErrorCount(failCount);
            }
        } finally {
            saveTransactionLogSMOImpl.saveAssetImportLog(assetImportLogDto);
        }
 
        return responseEntity;
    }
 
    /**
     * 保存 楼栋和 单元信息
     *
     * @param pd
     * @param floors
     * @param result
     * @return
     */
    private ResponseEntity<String> savedFloorAndUnitInfo(IPageData pd, List<ImportFloor> floors, ComponentValidateResult result) {
        String apiUrl = "";
        JSONObject paramIn = null;
        ResponseEntity<String> responseEntity = new ResponseEntity<String>("成功", HttpStatus.OK);
 
        AssetImportLogDto assetImportLogDto = new AssetImportLogDto();
        assetImportLogDto.setSuccessCount(0L);
        assetImportLogDto.setErrorCount(0L);
        assetImportLogDto.setCommunityId(result.getCommunityId());
        assetImportLogDto.setLogType(AssetImportLogDto.LOG_TYPE_FLOOR_UNIT_IMPORT);
        List<AssetImportLogDetailDto> assetImportLogDetailDtos = new ArrayList<>();
        assetImportLogDto.setAssetImportLogDetailDtos(assetImportLogDetailDtos);
        long successCount = 0L;
        long failCount = 0L;
        AssetImportLogDetailDto assetImportLogDetailDto = null;
        try {
            for (ImportFloor importFloor : floors) {
                paramIn = new JSONObject();
                //先保存 楼栋信息
                JSONObject savedFloorInfo = getExistsFloor(pd, result, importFloor);
                // 如果不存在,才插入
                if (savedFloorInfo == null) {
                    apiUrl = ServiceConstant.SERVICE_API_URL + "/api/floor.saveFloor";
                    paramIn.put("communityId", result.getCommunityId());
                    paramIn.put("floorNum", importFloor.getFloorNum());
                    paramIn.put("userId", result.getUserId());
                    paramIn.put("name", importFloor.getFloorNum() + "栋");
                    paramIn.put("floorArea", 1.00);
 
                    responseEntity = this.callCenterService(restTemplate, pd, paramIn.toJSONString(), apiUrl, HttpMethod.POST);
                    savedFloorInfo = getExistsFloor(pd, result, importFloor);
                }
 
                /***************************************导入日志记录****************************************************/
                if (responseEntity != null && responseEntity.getStatusCode() != HttpStatus.OK) { //跳过 保存单元信息
                    failCount += 1;
                    assetImportLogDetailDto = new AssetImportLogDetailDto();
                    assetImportLogDetailDto.setCommunityId(assetImportLogDto.getCommunityId());
                    if (Assert.isJsonObject(responseEntity.getBody())) {
                        JSONObject paramOut = JSONObject.parseObject(responseEntity.getBody());
                        assetImportLogDetailDto.setState(paramOut.getString("code"));
                        assetImportLogDetailDto.setMessage(paramOut.getString("msg"));
                    } else {
                        assetImportLogDetailDto.setState("F");
                        assetImportLogDetailDto.setMessage(responseEntity.getBody());
                    }
                    assetImportLogDetailDto.setObjName(importFloor.getFloorNum() + "栋");
                    assetImportLogDetailDtos.add(assetImportLogDetailDto);
                    assetImportLogDto.setSuccessCount(successCount);
                    assetImportLogDto.setErrorCount(failCount);
                    continue;
                } else {
                    successCount += 1;
                    assetImportLogDto.setSuccessCount(successCount);
                    assetImportLogDto.setErrorCount(failCount);
                }
 
 
                if (savedFloorInfo == null) {
                    continue;
                }
                importFloor.setFloorId(savedFloorInfo.getString("floorId"));
                paramIn.clear();
                //判断单元信息是否已经存在,如果存在则不保存数据unit.queryUnits
                JSONObject savedUnitInfo = getExistsUnit(pd, result, importFloor);
                if (savedUnitInfo != null) {
                    importFloor.setUnitId(savedUnitInfo.getString("unitId"));
                    continue;
                }
 
                apiUrl = ServiceConstant.SERVICE_API_URL + "/api/unit.saveUnit";
 
                paramIn.put("communityId", result.getCommunityId());
                paramIn.put("floorId", savedFloorInfo.getString("floorId"));
                paramIn.put("unitNum", importFloor.getUnitNum());
                paramIn.put("layerCount", importFloor.getLayerCount());
                paramIn.put("lift", importFloor.getLift());
                paramIn.put("unitArea", 1.00);
                responseEntity = this.callCenterService(restTemplate, pd, paramIn.toJSONString(), apiUrl, HttpMethod.POST);
                /****************************** 开始记录失败日志 *******************************/
                if (responseEntity != null && responseEntity.getStatusCode() != HttpStatus.OK) { //跳过 保存单元信息
                    assetImportLogDetailDto = new AssetImportLogDetailDto();
                    assetImportLogDetailDto.setCommunityId(assetImportLogDto.getCommunityId());
                    if (Assert.isJsonObject(responseEntity.getBody())) {
                        JSONObject paramOut = JSONObject.parseObject(responseEntity.getBody());
                        assetImportLogDetailDto.setState(paramOut.getString("code"));
                        assetImportLogDetailDto.setMessage(paramOut.getString("msg"));
                    } else {
                        assetImportLogDetailDto.setState("F");
                        assetImportLogDetailDto.setMessage(responseEntity.getBody());
                    }
                    assetImportLogDetailDto.setObjName(importFloor.getFloorNum() + "栋" + importFloor.getUnitNum() + "单元");
                    assetImportLogDetailDtos.add(assetImportLogDetailDto);
                    failCount += 1;
                    successCount = successCount > 0 ? successCount - 1 : successCount;
                    assetImportLogDto.setSuccessCount(successCount);
                    assetImportLogDto.setErrorCount(failCount);
                } else {
                    JSONObject body = JSONObject.parseObject(responseEntity.getBody());
                    if (body.containsKey("code") && body.getIntValue("code") != 0) {
                        assetImportLogDetailDto = new AssetImportLogDetailDto();
                        assetImportLogDetailDto.setCommunityId(assetImportLogDto.getCommunityId());
                        assetImportLogDetailDto.setState(body.getString("code"));
                        assetImportLogDetailDto.setMessage(body.getString("msg"));
                        assetImportLogDetailDto.setObjName(importFloor.getFloorNum() + "栋" + importFloor.getUnitNum() + "单元");
                        assetImportLogDetailDtos.add(assetImportLogDetailDto);
                        failCount += 1;
                        successCount = successCount > 0 ? successCount - 1 : successCount;
                        assetImportLogDto.setSuccessCount(successCount);
                        assetImportLogDto.setErrorCount(failCount);
                    }
                }
                //将unitId 刷入ImportFloor对象
                savedUnitInfo = getExistsUnit(pd, result, importFloor);
                importFloor.setUnitId(savedUnitInfo.getString("unitId"));
 
            }
        } finally {
            saveTransactionLogSMOImpl.saveAssetImportLog(assetImportLogDto);
        }
        return responseEntity;
    }
 
    private JSONObject getExistsUnit(IPageData pd, ComponentValidateResult result, ImportFloor importFloor) {
        String apiUrl = "";
        ResponseEntity<String> responseEntity = null;
        apiUrl = ServiceConstant.SERVICE_API_URL + "/api/unit.queryUnits?communityId=" + result.getCommunityId()
                + "&floorId=" + importFloor.getFloorId() + "&unitNum=" + importFloor.getUnitNum();
        responseEntity = this.callCenterService(restTemplate, pd, "", apiUrl, HttpMethod.GET);
 
        if (responseEntity.getStatusCode() != HttpStatus.OK) { //跳过 保存单元信息
            return null;
        }
 
        JSONArray savedFloorInfoResults = JSONArray.parseArray(responseEntity.getBody());
 
        if (savedFloorInfoResults == null || savedFloorInfoResults.size() != 1) {
            return null;
        }
 
        JSONObject savedUnitInfo = savedFloorInfoResults.getJSONObject(0);
 
        return savedUnitInfo;
    }
 
    private JSONObject getExistsFloor(IPageData pd, ComponentValidateResult result, ImportFloor importFloor) {
        String apiUrl = "";
        ResponseEntity<String> responseEntity = null;
        apiUrl = ServiceConstant.SERVICE_API_URL + "/api/floor.queryFloors?page=1&row=1&communityId=" + result.getCommunityId() + "&floorNum=" + importFloor.getFloorNum();
        responseEntity = this.callCenterService(restTemplate, pd, "", apiUrl, HttpMethod.GET);
 
        if (responseEntity.getStatusCode() != HttpStatus.OK) { //跳过 保存单元信息
            return null;
        }
 
        JSONObject savedFloorInfoResult = JSONObject.parseObject(responseEntity.getBody());
 
        if (!savedFloorInfoResult.containsKey("apiFloorDataVoList") || savedFloorInfoResult.getJSONArray("apiFloorDataVoList").size() != 1) {
            return null;
        }
 
        JSONObject savedFloorInfo = savedFloorInfoResult.getJSONArray("apiFloorDataVoList").getJSONObject(0);
 
        return savedFloorInfo;
    }
 
    /**
     * 查询存在的业主
     *
     * @param pd
     * @param result
     * @param importOwner
     * @return
     */
    private JSONObject getExistsOwner(IPageData pd, ComponentValidateResult result, ImportOwner importOwner) {
        String apiUrl = "";
        ResponseEntity<String> responseEntity = null;
        apiUrl = ServiceConstant.SERVICE_API_URL + "/api/owner.queryOwners?page=1&row=1&communityId=" + result.getCommunityId()
                + "&ownerTypeCd=1001&name=" + importOwner.getOwnerName() + "&link=" + importOwner.getTel();
        responseEntity = this.callCenterService(restTemplate, pd, "", apiUrl, HttpMethod.GET);
 
        if (responseEntity.getStatusCode() != HttpStatus.OK) { //跳过 保存单元信息
            return null;
        }
 
        JSONObject savedOwnerInfoResult = JSONObject.parseObject(responseEntity.getBody());
 
        if (!savedOwnerInfoResult.containsKey("owners") || savedOwnerInfoResult.getJSONArray("owners").size() != 1) {
            return null;
        }
 
        JSONObject savedOwnerInfo = savedOwnerInfoResult.getJSONArray("owners").getJSONObject(0);
 
        return savedOwnerInfo;
    }
 
    /**
     * 查询存在的停车场
     *
     * @param pd
     * @param result
     * @param parkingSpace
     * @return
     */
    private JSONObject getExistsParkingArea(IPageData pd, ComponentValidateResult result, ImportParkingSpace parkingSpace) {
        String apiUrl = "";
        ResponseEntity<String> responseEntity = null;
        apiUrl = ServiceConstant.SERVICE_API_URL + "/api/parkingArea.listParkingAreas?page=1&row=1&communityId=" + result.getCommunityId()
                + "&num=" + parkingSpace.getPaNum();
        responseEntity = this.callCenterService(restTemplate, pd, "", apiUrl, HttpMethod.GET);
 
        if (responseEntity.getStatusCode() != HttpStatus.OK) { //跳过 保存单元信息
            return null;
        }
 
        JSONObject savedParkingAreaInfoResult = JSONObject.parseObject(responseEntity.getBody());
 
        if (!savedParkingAreaInfoResult.containsKey("parkingAreas") || savedParkingAreaInfoResult.getJSONArray("parkingAreas").size() != 1) {
            return null;
        }
 
        JSONObject savedParkingAreaInfo = savedParkingAreaInfoResult.getJSONArray("parkingAreas").getJSONObject(0);
 
        return savedParkingAreaInfo;
    }
 
    /**
     * 数据校验处理
     *
     * @param floors
     * @param owners
     * @param rooms
     * @param parkingSpaces
     */
    private void importExcelDataValidate(List<ImportFloor> floors, List<ImportOwner> owners, List<ImportRoom> rooms, List<ImportFee> fees, List<ImportParkingSpace> parkingSpaces) {
 
    }
 
    /**
     * 获取车位信息
     *
     * @param workbook
     * @param parkingSpaces
     */
    private void getParkingSpaces(Workbook workbook, List<ImportParkingSpace> parkingSpaces, List<ImportOwner> owners) {
        Sheet sheet = null;
        sheet = ImportExcelUtils.getSheet(workbook, "车位信息");
        List<Object[]> oList = ImportExcelUtils.listFromSheet(sheet);
        ImportParkingSpace importParkingSpace = null;
        for (int osIndex = 0; osIndex < oList.size(); osIndex++) {
            Object[] os = oList.get(osIndex);
            if (osIndex == 0) { // 第一行是 头部信息 直接跳过
                continue;
            }
            if (StringUtil.isNullOrNone(os[0])) {
                continue;
            }
            Assert.hasValue(os[0], "车位信息选项中" + (osIndex + 1) + "行停车场编号为空");
            Assert.hasValue(os[1], "车位信息选项中" + (osIndex + 1) + "行车位编码为空");
            Assert.hasValue(os[2], "车位信息选项中" + (osIndex + 1) + "行停车场类型为空");
            Assert.hasValue(os[3], "车位信息选项中" + (osIndex + 1) + "行面积为空,没有请填写规定值 如10");
            importParkingSpace = new ImportParkingSpace();
            importParkingSpace.setPaNum(os[0].toString());
            importParkingSpace.setPsNum(os[1].toString());
            importParkingSpace.setTypeCd(os[2].toString());
            importParkingSpace.setArea(Double.parseDouble(os[3].toString()));
            if (os.length < 5 || StringUtil.isNullOrNone(os[4])) {
                parkingSpaces.add(importParkingSpace);
                continue;
            }
            ImportOwner importOwner = getImportOwner(owners, os[4].toString());
            importParkingSpace.setImportOwner(importOwner);
            if (importOwner != null) {
                importParkingSpace.setCarNum(os[5].toString());
                importParkingSpace.setCarBrand(os[6].toString());
                importParkingSpace.setCarType(os[7].toString());
                importParkingSpace.setCarColor(os[8].toString());
                importParkingSpace.setSellOrHire(os[9].toString());
 
                String startTime = excelDoubleToDate(os[10].toString());
                String endTime = excelDoubleToDate(os[11].toString());
                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 文本格式");
                importParkingSpace.setStartTime(startTime);
                importParkingSpace.setEndTime(endTime);
            }
 
            parkingSpaces.add(importParkingSpace);
        }
    }
 
    //解析Excel日期格式
    public static String excelDoubleToDate(String strDate) {
        if (strDate.length() == 5) {
            try {
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                Date tDate = DoubleToDate(Double.parseDouble(strDate));
                return sdf.format(tDate);
            } catch (Exception e) {
                e.printStackTrace();
                return strDate;
            }
        }
        return strDate;
    }
 
 
    //解析Excel日期格式
    public static Date DoubleToDate(Double dVal) {
        Date tDate = new Date();
        long localOffset = tDate.getTimezoneOffset() * 60000; //系统时区偏移 1900/1/1 到 1970/1/1 的 25569 天
        tDate.setTime((long) ((dVal - 25569) * 24 * 3600 * 1000 + localOffset));
 
        return tDate;
    }
 
    /**
     * 获取 房屋信息
     *
     * @param workbook
     * @param rooms
     */
    private void getRooms(Workbook workbook, List<ImportRoom> rooms,
                          List<ImportFloor> floors, List<ImportOwner> owners) {
        Sheet sheet = null;
        sheet = ImportExcelUtils.getSheet(workbook, "房屋信息");
        List<Object[]> oList = ImportExcelUtils.listFromSheet(sheet);
        ImportRoom importRoom = null;
        for (int osIndex = 0; osIndex < oList.size(); osIndex++) {
            try {
                Object[] os = oList.get(osIndex);
                if (osIndex == 0) { // 第一行是 头部信息 直接跳过
                    continue;
                }
                if (StringUtil.isNullOrNone(os[0])) {
                    continue;
                }
                Assert.hasValue(os[1], "房屋信息选项中" + (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) + "行建筑面积为空");
                if (os.length > 6 && !StringUtil.isNullOrNone(os[6])) {
                    Assert.hasValue(os[7], "房屋信息选项中" + (osIndex + 1) + "行房屋费用为空");
                    Assert.hasValue(os[8], "房屋信息选项中" + (osIndex + 1) + "行费用到期时间为空");
                }
                Assert.hasValue(os[9], "房屋信息选项中" + (osIndex + 1) + "行房屋类型为空");
                Assert.hasValue(os[10], "房屋信息选项中" + (osIndex + 1) + "行室内面积为空");
                Assert.hasValue(os[11], "房屋信息选项中" + (osIndex + 1) + "行租金为空");
                importRoom = new ImportRoom();
                importRoom.setRoomNum(os[0].toString());
                importRoom.setFloor(getImportFloor(floors, os[1].toString(), os[2].toString()));
                importRoom.setLayer(Integer.parseInt(os[3].toString()));
                importRoom.setSection(os[4].toString());
                importRoom.setBuiltUpArea(Double.parseDouble(os[5].toString()));
                importRoom.setRoomSubType(os[9].toString());
                importRoom.setRoomArea(os[10].toString());
                importRoom.setRoomRent(os[11].toString());
 
 
                if (os.length > 6 && !StringUtil.isNullOrNone(os[6])) {
                    importRoom.setRoomFeeId(os[7].toString());
                    String feeEndDate = excelDoubleToDate(os[8].toString());
                    importRoom.setFeeEndDate(feeEndDate);
                }
                if (os.length < 7 || StringUtil.isNullOrNone(os[6])) {
                    rooms.add(importRoom);
                    continue;
                }
                importRoom.setImportOwner(getImportOwner(owners, os[6].toString()));
                rooms.add(importRoom);
            } catch (Exception e) {
                logger.error("房屋数据校验失败", e);
                throw new IllegalArgumentException("房屋信息sheet中第" + (osIndex + 1) + "行数据错误,请检查" + e.getLocalizedMessage());
            }
        }
    }
 
    /**
     * 获取 房屋信息
     *
     * @param workbook
     * @param importFees
     */
    private void getFee(Workbook workbook, List<ImportFee> importFees) {
        Sheet sheet = null;
        sheet = ImportExcelUtils.getSheet(workbook, "费用设置");
        List<Object[]> oList = ImportExcelUtils.listFromSheet(sheet);
        ImportFee importFee = null;
        for (int osIndex = 0; osIndex < oList.size(); osIndex++) {
            Object[] os = oList.get(osIndex);
            if (osIndex == 0) { // 第一行是 头部信息 直接跳过
                continue;
            }
            if (StringUtil.isNullOrNone(os[0])) {
                continue;
            }
            Assert.hasValue(os[0], "费用设置选项中" + (osIndex + 1) + "行费用编号为空");
            Assert.hasValue(os[1], "费用设置选项中" + (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.isInteger(os[5].toString(), "费用设置选项中" + (osIndex + 1) + "行缴费周期不是正整数");
            Assert.hasValue(os[6], "费用设置选项中" + (osIndex + 1) + "行出账类型为空");
            Assert.isDate(os[7].toString(), DateUtil.DATE_FORMATE_STRING_B, "费用设置选项中" + (osIndex + 1) + "行计费起始时间不是有效时间格式 请输入类似2020-06-01");
            Assert.isDate(os[8].toString(), DateUtil.DATE_FORMATE_STRING_B, "费用设置选项中" + (osIndex + 1) + "行计费终止时间不是有效时间格式 请输入类似2037-01-01");
            Assert.hasValue(os[9], "费用设置选项中" + (osIndex + 1) + "行计算公式为空");
            if (!"1001".equals(os[9].toString()) && !"2002".equals(os[9].toString())) {
                throw new IllegalArgumentException("费用设置选项中" + (osIndex + 1) + "行计算公式错误 请填写1001 或者2002");
            }
            Assert.hasValue(os[10], "费用设置选项中" + (osIndex + 1) + "行计费单价为空");
            Assert.hasValue(os[11], "费用设置选项中" + (osIndex + 1) + "行固定费用为空");
            importFee = new ImportFee();
            importFee.setId(os[0].toString());
            importFee.setFeeTypeCd("物业费".equals(os[1]) ? "888800010001" : "888800010002");
            importFee.setFeeName(os[2].toString());
            importFee.setFeeFlag("周期性费用".equals(os[3]) ? "1003006" : "2006012");
            importFee.setPaymentCd("预付费".equals(os[4]) ? "1200" : "2100");
            String billType = "";
            if ("每年1月1日".equals(os[6])) {
                billType = "001";
            } else if ("每月1日".equals(os[6])) {
                billType = "002";
            } else if ("每日".equals(os[6])) {
                billType = "003";
            } else {
                billType = "004";
            }
            importFee.setBillType(billType);
            importFee.setPaymentCycle(os[5].toString());
            importFee.setStartTime(os[7].toString());
            importFee.setEndTime(os[8].toString());
            importFee.setComputingFormula(os[9].toString());
            importFee.setSquarePrice(os[10].toString());
            importFee.setAdditionalAmount(os[11].toString());
            importFees.add(importFee);
        }
    }
 
    /**
     * 从导入的业主信息中获取业主,如果没有返回 null
     *
     * @param owners
     * @param ownerNum
     * @return
     */
    private ImportOwner getImportOwner(List<ImportOwner> owners, String ownerNum) {
        for (ImportOwner importOwner : owners) {
            if (ownerNum.equals(importOwner.getOwnerNum())) {
                return importOwner;
            }
        }
 
        return null;
 
    }
 
    /**
     * get 导入楼栋信息
     *
     * @param floors
     */
    private ImportFloor getImportFloor(List<ImportFloor> floors, String floorNum, String unitNum) {
        for (ImportFloor importFloor : floors) {
            if (floorNum.equals(importFloor.getFloorNum())
                    && unitNum.equals(importFloor.getUnitNum())) {
                return importFloor;
            }
        }
 
        throw new IllegalArgumentException("在楼栋单元sheet中未找到楼栋编号[" + floorNum + "],单元编号[" + unitNum + "]数据");
    }
 
    /**
     * 获取业主信息
     *
     * @param workbook
     * @param owners
     */
    private void getOwners(Workbook workbook, List<ImportOwner> owners) {
        Sheet sheet = null;
        sheet = ImportExcelUtils.getSheet(workbook, "业主信息");
        List<Object[]> oList = ImportExcelUtils.listFromSheet(sheet);
        ImportOwner importOwner = null;
        for (int osIndex = 0; osIndex < oList.size(); osIndex++) {
            try {
                Object[] os = oList.get(osIndex);
                if (osIndex == 0) { // 第一行是 头部信息 直接跳过
                    continue;
                }
                if (StringUtil.isNullOrNone(os[0])) {
                    continue;
                }
                Assert.hasValue(os[0], "业主信息选项中" + (osIndex + 1) + "行业主编号为空");
                Assert.hasValue(os[1], "业主信息选项中" + (osIndex + 1) + "行业主名称为空");
                Assert.hasValue(os[2], "业主信息选项中" + (osIndex + 1) + "行业主性别为空");
                String tel = StringUtil.isNullOrNone(os[4]) ? "19999999999" : os[4].toString();
                String idCard = StringUtil.isNullOrNone(os[5]) ? "10000000000000000001" : os[5].toString();
 
                if (os[4].toString().length() > 11) {
                    throw new IllegalArgumentException(os[1].toString() + " 的手机号超过11位,请核实");
                }
                if (os[5].toString().length() > 18) {
                    throw new IllegalArgumentException(os[1].toString() + " 的身份证超过18位,请核实");
                }
 
                String age = StringUtil.isNullOrNone(os[3]) ? CommonUtil.getAgeByCertId(idCard) : os[3].toString();
                importOwner = new ImportOwner();
                importOwner.setOwnerNum(os[0].toString());
                importOwner.setOwnerName(os[1].toString());
                importOwner.setSex("男".equals(os[2].toString()) ? "0" : "1");
                importOwner.setAge(Integer.parseInt(age));
                importOwner.setTel(tel);
                importOwner.setIdCard(idCard);
                owners.add(importOwner);
            } catch (Exception e) {
                logger.error("第" + (osIndex + 1) + "行数据出现问题", e);
                throw new IllegalArgumentException("第" + (osIndex + 1) + "行数据出现问题" + e.getLocalizedMessage(), e);
            }
        }
    }
 
    /**
     * 获取小区
     *
     * @param workbook
     * @param floors
     */
    private void getFloors(Workbook workbook, List<ImportFloor> floors) {
        Sheet sheet = null;
        sheet = ImportExcelUtils.getSheet(workbook, "楼栋单元");
        List<Object[]> oList = ImportExcelUtils.listFromSheet(sheet);
        ImportFloor importFloor = null;
        for (int osIndex = 0; osIndex < oList.size(); osIndex++) {
            Object[] os = oList.get(osIndex);
            if (osIndex == 0) { // 第一行是 头部信息 直接跳过
                continue;
            }
 
            if (StringUtil.isNullOrNone(os[0])) {
                continue;
            }
 
            Assert.hasValue(os[0], "楼栋单元选项中" + (osIndex + 1) + "行楼栋号为空");
            Assert.hasValue(os[1], "楼栋单元选项中" + (osIndex + 1) + "行单元编号为空");
            Assert.hasValue(os[2], "楼栋单元选项中" + (osIndex + 1) + "行总楼层为空");
            Assert.hasValue(os[3], "楼栋单元选项中" + (osIndex + 1) + "行是否有电梯为空");
            importFloor = new ImportFloor();
            importFloor.setFloorNum(os[0].toString());
            importFloor.setUnitNum(os[1].toString());
            importFloor.setLayerCount(os[2].toString());
            importFloor.setLift("有".equals(os[3].toString()) ? "1010" : "2020");
            floors.add(importFloor);
        }
    }
 
 
    public RestTemplate getRestTemplate() {
        return restTemplate;
    }
 
    public void setRestTemplate(RestTemplate restTemplate) {
        this.restTemplate = restTemplate;
    }
}