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
package com.java110.user.bmo.owner.impl;
 
import com.java110.dto.RoomDto;
import com.java110.dto.basePrivilege.BasePrivilegeDto;
import com.java110.dto.contract.ContractDto;
import com.java110.dto.owner.OwnerCarDto;
import com.java110.dto.owner.OwnerDto;
import com.java110.dto.owner.OwnerRoomRelDto;
import com.java110.intf.common.IFileInnerServiceSMO;
import com.java110.intf.common.IFileRelInnerServiceSMO;
import com.java110.intf.community.IMenuInnerServiceSMO;
import com.java110.intf.community.IRoomInnerServiceSMO;
import com.java110.intf.store.IContractInnerServiceSMO;
import com.java110.intf.user.IOwnerCarInnerServiceSMO;
import com.java110.intf.user.IOwnerInnerServiceSMO;
import com.java110.intf.user.IOwnerRoomRelInnerServiceSMO;
import com.java110.user.bmo.owner.IComprehensiveQuery;
import com.java110.utils.util.Assert;
import com.java110.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
 
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
 
@Service
public class ComprehensiveQueryImpl implements IComprehensiveQuery {
 
    public static final String SEARCH_TYPE_ROOM = "1"; //根据房屋来查
    public static final String SEARCH_TYPE_OWNER_NAME = "2"; //根据业主名称查询
    public static final String SEARCH_TYPE_OWNER_TEL = "3"; //根据业主手机号
    public static final String SEARCH_TYPE_OWNER_IDCARD = "4"; //根据业主身份证
    public static final String SEARCH_TYPE_OWNER_CAR = "5"; //根据业主车牌号
    public static final String SEARCH_TYPE_OWNER_MEMBER_NAME = "6"; //根据家庭成员名称
    public static final String SEARCH_TYPE_OWNER_MEMBER_TEL = "7"; //根据家庭成员电话
    public static final String SEARCH_TYPE_OWNER_MEMBER_IDCARD = "8"; //根据家庭成员身份证
    public static final String SEARCH_TYPE_SHOPS = "9"; //根据商铺号
    public static final String SEARCH_TYPE_CONTRACT = "10"; //合同号
 
    @Autowired
    private IOwnerInnerServiceSMO ownerInnerServiceSMOImpl;
 
    @Autowired
    private IRoomInnerServiceSMO roomInnerServiceSMOImpl;
 
    @Autowired
    private IOwnerRoomRelInnerServiceSMO ownerRoomRelInnerServiceSMOImpl;
 
    @Autowired
    private IFileRelInnerServiceSMO fileRelInnerServiceSMOImpl;
 
    @Autowired
    private IFileInnerServiceSMO fileInnerServiceSMOImpl;
 
    @Autowired
    private IOwnerCarInnerServiceSMO ownerCarInnerServiceSMOImpl;
 
    @Autowired
    private IMenuInnerServiceSMO menuInnerServiceSMOImpl;
 
    @Autowired
    private IContractInnerServiceSMO contractInnerServiceSMOImpl;
 
    @Override
    public ResponseEntity<String> query(String communityId, String searchValue, String searchType, String userId, String storeId) {
        OwnerDto ownerDto = null;
        switch (searchType) {
            case SEARCH_TYPE_ROOM:
                ownerDto = queryByRoom(communityId, searchValue, userId);
                break;
            case SEARCH_TYPE_SHOPS:
                ownerDto = queryByShops(communityId, searchValue, userId);
                break;
            case SEARCH_TYPE_OWNER_NAME:
                ownerDto = queryByOwnerName(communityId, searchValue, userId);
                break;
            case SEARCH_TYPE_OWNER_TEL:
                ownerDto = queryByOwnerTel(communityId, searchValue, userId);
                break;
            case SEARCH_TYPE_OWNER_IDCARD:
                ownerDto = queryByOwnerIdCard(communityId, searchValue, userId);
                break;
            case SEARCH_TYPE_OWNER_CAR:
                ownerDto = queryByOwnerCar(communityId, searchValue, userId);
                break;
            case SEARCH_TYPE_OWNER_MEMBER_NAME:
                ownerDto = queryByOwnerMemberName(communityId, searchValue, userId);
                break;
            case SEARCH_TYPE_OWNER_MEMBER_TEL:
                ownerDto = queryByOwnerMemberTel(communityId, searchValue, userId);
                break;
            case SEARCH_TYPE_OWNER_MEMBER_IDCARD:
                ownerDto = queryByOwnerMemberIdCard(communityId, searchValue, userId);
                break;
            case SEARCH_TYPE_CONTRACT:
                ownerDto = queryByContract(communityId, searchValue, userId, storeId);
                break;
        }
        return ResultVo.createResponseEntity(1, 1, ownerDto);
    }
 
    /**
     * 成员身份证查询
     *
     * @param communityId
     * @param searchValue
     * @return
     */
    private OwnerDto queryByOwnerMemberIdCard(String communityId, String searchValue, String userId) {
        OwnerDto ownerDto = new OwnerDto();
        ownerDto.setCommunityId(communityId);
        ownerDto.setIdCard(searchValue);
        ownerDto.setOwnerTypeCds(new String[]{OwnerDto.OWNER_TYPE_CD_MEMBER, OwnerDto.OWNER_TYPE_CD_RENTING});
        List<OwnerDto> ownerDtos = ownerInnerServiceSMOImpl.queryOwnerMembers(ownerDto);
        Assert.listOnlyOne(ownerDtos, "未找到成员信息或者查询到多条,请换其他条件查询");
        OwnerDto owner = queryByOwnerId(communityId, ownerDtos.get(0).getOwnerId());
        //查询是否有脱敏权限
        List<Map> mark = getPrivilegeOwnerList("/roomCreateFee", userId);
        //对业主身份证号隐藏处理
        String idCard = owner.getIdCard();
        if (mark.size() == 0 && idCard != null && idCard != null) {
            idCard = idCard.substring(0, 6) + "**********" + idCard.substring(16);
            owner.setIdCard(idCard);
        }
        //对业主手机号隐藏处理
        String link = owner.getLink();
        if (mark.size() == 0 && link != null && !link.equals("")) {
            link = link.substring(0, 3) + "****" + link.substring(7);
            owner.setLink(link);
        }
        return owner;
    }
 
    /**
     * 成员名称查询
     *
     * @param communityId
     * @param searchValue
     * @return
     */
    private OwnerDto queryByOwnerMemberTel(String communityId, String searchValue, String userId) {
        OwnerDto ownerDto = new OwnerDto();
        ownerDto.setCommunityId(communityId);
        ownerDto.setLink(searchValue);
        ownerDto.setOwnerTypeCds(new String[]{OwnerDto.OWNER_TYPE_CD_MEMBER, OwnerDto.OWNER_TYPE_CD_RENTING});
        List<OwnerDto> ownerDtos = ownerInnerServiceSMOImpl.queryOwnerMembers(ownerDto);
        Assert.listOnlyOne(ownerDtos, "未找到成员信息或者查询到多条,请换其他条件查询");
        OwnerDto owner = queryByOwnerId(communityId, ownerDtos.get(0).getOwnerId());
        //查询是否有脱敏权限
        List<Map> mark = getPrivilegeOwnerList("/roomCreateFee", userId);
        //对业主身份证号隐藏处理
        String idCard = owner.getIdCard();
        if (mark.size() == 0 && idCard != null && idCard != null) {
            idCard = idCard.substring(0, 6) + "**********" + idCard.substring(16);
            owner.setIdCard(idCard);
        }
        //对业主手机号隐藏处理
        String link = owner.getLink();
        if (mark.size() == 0 && link != null && !link.equals("")) {
            link = link.substring(0, 3) + "****" + link.substring(7);
            owner.setLink(link);
        }
        return owner;
    }
 
    /**
     * 成员名称查询
     *
     * @param communityId
     * @param searchValue
     * @return
     */
    private OwnerDto queryByOwnerMemberName(String communityId, String searchValue, String userId) {
 
        OwnerDto ownerDto = new OwnerDto();
        ownerDto.setCommunityId(communityId);
        ownerDto.setName(searchValue);
        ownerDto.setOwnerTypeCds(new String[]{OwnerDto.OWNER_TYPE_CD_MEMBER, OwnerDto.OWNER_TYPE_CD_RENTING});
        List<OwnerDto> ownerDtos = ownerInnerServiceSMOImpl.queryOwnerMembers(ownerDto);
        Assert.isNotNull(ownerDtos,"未找到成员信息,请换其他条件查询");
        //Assert.listOnlyOne(ownerDtos, "未找到成员信息或者查询到多条,请换其他条件查询");
        OwnerDto owner = queryByOwnerId(communityId, ownerDtos.get(0).getOwnerId());
        //查询是否有脱敏权限
        List<Map> mark = getPrivilegeOwnerList("/roomCreateFee", userId);
        //对业主身份证号隐藏处理
        String idCard = owner.getIdCard();
        if (mark.size() == 0 && idCard != null && idCard != null) {
            idCard = idCard.substring(0, 6) + "**********" + idCard.substring(16);
            owner.setIdCard(idCard);
        }
        //对业主手机号隐藏处理
        String link = owner.getLink();
        if (mark.size() == 0 && link != null && !link.equals("")) {
            link = link.substring(0, 3) + "****" + link.substring(7);
            owner.setLink(link);
        }
        return owner;
    }
 
    /**
     * 根据业主车辆查询业主
     *
     * @param communityId
     * @param searchValue
     * @return
     */
    private OwnerDto queryByOwnerCar(String communityId, String searchValue, String userId) {
        OwnerCarDto ownerCarDto = new OwnerCarDto();
        ownerCarDto.setCommunityId(communityId);
        ownerCarDto.setCarNum(searchValue);
        List<OwnerCarDto> ownerCarDtos = ownerCarInnerServiceSMOImpl.queryOwnerCars(ownerCarDto);
 
        if (ownerCarDtos == null || ownerCarDtos.size() < 1) {
            throw new IllegalArgumentException("未查到车辆信息");
        }
 
        OwnerDto owner = queryByOwnerId(communityId, ownerCarDtos.get(0).getOwnerId());
        //查询是否有脱敏权限
        List<Map> mark = getPrivilegeOwnerList("/roomCreateFee", userId);
        //对业主身份证号隐藏处理
        String idCard = owner.getIdCard();
        if (mark.size() == 0 && idCard != null && idCard != null) {
            idCard = idCard.substring(0, 6) + "**********" + idCard.substring(16);
            owner.setIdCard(idCard);
        }
        //对业主手机号隐藏处理
        String link = owner.getLink();
        if (mark.size() == 0 && link != null && !link.equals("")) {
            link = link.substring(0, 3) + "****" + link.substring(7);
            owner.setLink(link);
        }
        return owner;
    }
 
 
    /**
     * 根据业主ID查询
     *
     * @param communityId
     * @param searchValue
     * @return
     */
    private OwnerDto queryByOwnerId(String communityId, String searchValue) {
        OwnerDto ownerDto = new OwnerDto();
        ownerDto.setCommunityId(communityId);
        ownerDto.setOwnerId(searchValue);
        ownerDto.setOwnerTypeCd(OwnerDto.OWNER_TYPE_CD_OWNER);
        List<OwnerDto> ownerDtos = ownerInnerServiceSMOImpl.queryOwners(ownerDto);
        Assert.listOnlyOne(ownerDtos, "未找到业主信息或者查询到多条,请换其他条件查询");
        OwnerDto resOwnerDto = ownerDtos.get(0);
        OwnerRoomRelDto ownerRoomRelDto = new OwnerRoomRelDto();
        ownerRoomRelDto.setOwnerId(ownerDtos.get(0).getOwnerId());
        List<OwnerRoomRelDto> ownerRoomRelDtos = ownerRoomRelInnerServiceSMOImpl.queryOwnerRoomRels(ownerRoomRelDto);
 
        //没有房屋
        if (ownerRoomRelDtos == null || ownerRoomRelDtos.size() < 1) {
            return resOwnerDto;
        }
        List<String> roomIds = new ArrayList<>();
        for (OwnerRoomRelDto tmpOwnerRoomRelDto : ownerRoomRelDtos) {
            roomIds.add(tmpOwnerRoomRelDto.getRoomId());
        }
 
 
        RoomDto roomDto = new RoomDto();
        roomDto.setRoomIds(roomIds.toArray(new String[roomIds.size()]));
        roomDto.setCommunityId(communityId);
        List<RoomDto> roomDtos = roomInnerServiceSMOImpl.queryRooms(roomDto);
        resOwnerDto.setRooms(roomDtos);
        return resOwnerDto;
    }
 
    /**
     * 根据业主身份证查询
     *
     * @param communityId
     * @param searchValue
     * @return
     */
    private OwnerDto queryByOwnerIdCard(String communityId, String searchValue, String userId) {
        OwnerDto ownerDto = new OwnerDto();
        ownerDto.setCommunityId(communityId);
        ownerDto.setIdCard(searchValue);
        ownerDto.setOwnerTypeCd(OwnerDto.OWNER_TYPE_CD_OWNER);
        List<OwnerDto> ownerDtos = ownerInnerServiceSMOImpl.queryOwners(ownerDto);
        Assert.listOnlyOne(ownerDtos, "未找到业主信息或者查询到多条,请换其他条件查询");
        //查询是否有脱敏权限
        List<Map> mark = getPrivilegeOwnerList("/roomCreateFee", userId);
        List<OwnerDto> ownerDtoList = new ArrayList<>();
        for (OwnerDto owner : ownerDtos) {
            //对业主身份证号隐藏处理
            String idCard = owner.getIdCard();
            if (mark.size() == 0 && idCard != null && !idCard.equals("")) {
                idCard = idCard.substring(0, 6) + "**********" + idCard.substring(16);
            }
            //对业主手机号隐藏处理
            String link = owner.getLink();
            if (mark.size() == 0 && link != null && !link.equals("")) {
                link = link.substring(0, 3) + "****" + link.substring(7);
            }
            owner.setIdCard(idCard);
            owner.setLink(link);
            ownerDtoList.add(owner);
        }
        OwnerDto resOwnerDto = ownerDtoList.get(0);
        OwnerRoomRelDto ownerRoomRelDto = new OwnerRoomRelDto();
        ownerRoomRelDto.setOwnerId(ownerDtoList.get(0).getOwnerId());
        List<OwnerRoomRelDto> ownerRoomRelDtos = ownerRoomRelInnerServiceSMOImpl.queryOwnerRoomRels(ownerRoomRelDto);
 
        //没有房屋
        if (ownerRoomRelDtos == null || ownerRoomRelDtos.size() < 1) {
            return resOwnerDto;
        }
        List<String> roomIds = new ArrayList<>();
        for (OwnerRoomRelDto tmpOwnerRoomRelDto : ownerRoomRelDtos) {
            roomIds.add(tmpOwnerRoomRelDto.getRoomId());
        }
 
 
        RoomDto roomDto = new RoomDto();
        roomDto.setRoomIds(roomIds.toArray(new String[roomIds.size()]));
        roomDto.setCommunityId(communityId);
        List<RoomDto> roomDtos = roomInnerServiceSMOImpl.queryRooms(roomDto);
        resOwnerDto.setRooms(roomDtos);
        return resOwnerDto;
    }
 
    /**
     * 根据业主手机号查询
     *
     * @param communityId
     * @param searchValue
     * @return
     */
    private OwnerDto queryByOwnerTel(String communityId, String searchValue, String userId) {
        OwnerDto ownerDto = new OwnerDto();
        ownerDto.setCommunityId(communityId);
        ownerDto.setLink(searchValue);
        ownerDto.setOwnerTypeCd(OwnerDto.OWNER_TYPE_CD_OWNER);
        List<OwnerDto> ownerDtos = ownerInnerServiceSMOImpl.queryOwners(ownerDto);
        Assert.listOnlyOne(ownerDtos, "未找到业主信息或者查询到多条,请换其他条件查询");
        //查询是否有脱敏权限
        List<Map> mark = getPrivilegeOwnerList("/roomCreateFee", userId);
        List<OwnerDto> ownerDtoList = new ArrayList<>();
        for (OwnerDto owner : ownerDtos) {
            //对业主身份证号隐藏处理
            String idCard = owner.getIdCard();
            if (mark.size() == 0 && idCard != null && !idCard.equals("")) {
                idCard = idCard.substring(0, 6) + "**********" + idCard.substring(16);
            }
            //对业主手机号隐藏处理
            String link = owner.getLink();
            if (mark.size() == 0 && link != null && !link.equals("")) {
                link = link.substring(0, 3) + "****" + link.substring(7);
            }
            owner.setIdCard(idCard);
            owner.setLink(link);
            ownerDtoList.add(owner);
        }
        OwnerDto resOwnerDto = ownerDtoList.get(0);
        OwnerRoomRelDto ownerRoomRelDto = new OwnerRoomRelDto();
        ownerRoomRelDto.setOwnerId(ownerDtoList.get(0).getOwnerId());
        List<OwnerRoomRelDto> ownerRoomRelDtos = ownerRoomRelInnerServiceSMOImpl.queryOwnerRoomRels(ownerRoomRelDto);
 
        //没有房屋
        if (ownerRoomRelDtos == null || ownerRoomRelDtos.size() < 1) {
            return resOwnerDto;
        }
        List<String> roomIds = new ArrayList<>();
        for (OwnerRoomRelDto tmpOwnerRoomRelDto : ownerRoomRelDtos) {
            roomIds.add(tmpOwnerRoomRelDto.getRoomId());
        }
 
 
        RoomDto roomDto = new RoomDto();
        roomDto.setRoomIds(roomIds.toArray(new String[roomIds.size()]));
        roomDto.setCommunityId(communityId);
        List<RoomDto> roomDtos = roomInnerServiceSMOImpl.queryRooms(roomDto);
        resOwnerDto.setRooms(roomDtos);
        return resOwnerDto;
    }
 
    /**
     * 根据业主名称 查询
     *
     * @param communityId
     * @param searchValue
     * @return
     */
    private OwnerDto queryByOwnerName(String communityId, String searchValue, String userId) {
        OwnerDto ownerDto = new OwnerDto();
        ownerDto.setCommunityId(communityId);
        ownerDto.setName(searchValue);
        ownerDto.setOwnerTypeCd(OwnerDto.OWNER_TYPE_CD_OWNER);
        List<OwnerDto> ownerDtos = ownerInnerServiceSMOImpl.queryOwners(ownerDto);
        Assert.listOnlyOne(ownerDtos, "未找到业主信息或者查询到多条,请换其他条件查询");
        //查询是否有脱敏权限
        List<Map> mark = getPrivilegeOwnerList("/roomCreateFee", userId);
        List<OwnerDto> ownerDtoList = new ArrayList<>();
        for (OwnerDto owner : ownerDtos) {
            //对业主身份证号隐藏处理
            String idCard = owner.getIdCard();
            if (mark.size() == 0 && idCard != null && !idCard.equals("")) {
                idCard = idCard.substring(0, 6) + "**********" + idCard.substring(16);
            }
            //对业主手机号隐藏处理
            String link = owner.getLink();
            if (mark.size() == 0 && link != null && !link.equals("")) {
                link = link.substring(0, 3) + "****" + link.substring(7);
            }
            owner.setIdCard(idCard);
            owner.setLink(link);
            ownerDtoList.add(owner);
        }
        OwnerDto resOwnerDto = ownerDtoList.get(0);
        OwnerRoomRelDto ownerRoomRelDto = new OwnerRoomRelDto();
        ownerRoomRelDto.setOwnerId(ownerDtoList.get(0).getOwnerId());
        List<OwnerRoomRelDto> ownerRoomRelDtos = ownerRoomRelInnerServiceSMOImpl.queryOwnerRoomRels(ownerRoomRelDto);
 
        //没有房屋
        if (ownerRoomRelDtos == null || ownerRoomRelDtos.size() < 1) {
            return resOwnerDto;
        }
        List<String> roomIds = new ArrayList<>();
        for (OwnerRoomRelDto tmpOwnerRoomRelDto : ownerRoomRelDtos) {
            roomIds.add(tmpOwnerRoomRelDto.getRoomId());
        }
 
 
        RoomDto roomDto = new RoomDto();
        roomDto.setRoomIds(roomIds.toArray(new String[roomIds.size()]));
        roomDto.setCommunityId(communityId);
        List<RoomDto> roomDtos = roomInnerServiceSMOImpl.queryRooms(roomDto);
        resOwnerDto.setRooms(roomDtos);
        return resOwnerDto;
    }
 
    /**
     * 根据房屋查询
     *
     * @param communityId
     * @param searchValue
     * @return
     */
    private OwnerDto queryByShops(String communityId, String searchValue, String userId) {
 
        if (!searchValue.contains("-")) {
            throw new IllegalArgumentException("查询内容格式错误,请输入 楼栋-商铺 如 1-1");
        }
 
        String[] values = searchValue.split("-");
 
        if (values.length != 2) {
            throw new IllegalArgumentException("查询内容格式错误,请输入 楼栋-商铺 如 1-1");
        }
 
        RoomDto roomDto = new RoomDto();
        roomDto.setFloorNum(values[0]);
        roomDto.setUnitNum("0");
        roomDto.setRoomNum(values[1]);
        roomDto.setCommunityId(communityId);
 
        List<RoomDto> roomDtos = roomInnerServiceSMOImpl.queryRooms(roomDto);
        Assert.listOnlyOne(roomDtos, "未找到房屋信息");
 
        OwnerDto ownerDto = new OwnerDto();
        ownerDto.setCommunityId(communityId);
        ownerDto.setRoomId(roomDtos.get(0).getRoomId());
        ownerDto.setOwnerTypeCd(OwnerDto.OWNER_TYPE_CD_OWNER);
        List<OwnerDto> ownerDtos = ownerInnerServiceSMOImpl.queryOwners(ownerDto);
        Assert.listOnlyOne(ownerDtos, "未找到业主信息");
        //查询是否有脱敏权限
        List<Map> mark = getPrivilegeOwnerList("/roomCreateFee", userId);
        List<OwnerDto> ownerDtoList = new ArrayList<>();
        for (OwnerDto owner : ownerDtos) {
            //对业主身份证号隐藏处理
            String idCard = owner.getIdCard();
            if (mark.size() == 0 && idCard != null && !idCard.equals("")) {
                idCard = idCard.substring(0, 6) + "**********" + idCard.substring(16);
            }
            //对业主手机号隐藏处理
            String link = owner.getLink();
            if (mark.size() == 0 && link != null && !link.equals("")) {
                link = link.substring(0, 3) + "****" + link.substring(7);
            }
            owner.setIdCard(idCard);
            owner.setLink(link);
            ownerDtoList.add(owner);
        }
 
        OwnerDto resOwnerDto = ownerDtoList.get(0);
 
        resOwnerDto.setRooms(roomDtos);
 
        return resOwnerDto;
    }
 
    /**
     * 根据房屋查询
     *
     * @param communityId
     * @param searchValue
     * @return
     */
    private OwnerDto queryByRoom(String communityId, String searchValue, String userId) {
 
        if (!searchValue.contains("-")) {
            throw new IllegalArgumentException("查询内容格式错误,请输入 楼栋-单元-房屋 如 1-1-1");
        }
 
        String[] values = searchValue.split("-",3);
 
        if (values.length != 3) {
            throw new IllegalArgumentException("查询内容格式错误,请输入 楼栋-单元-房屋 如 1-1-1");
        }
 
        RoomDto roomDto = new RoomDto();
        roomDto.setFloorNum(values[0]);
        roomDto.setUnitNum(values[1]);
        roomDto.setRoomNum(values[2]);
        roomDto.setCommunityId(communityId);
 
        List<RoomDto> roomDtos = roomInnerServiceSMOImpl.queryRooms(roomDto);
        Assert.listOnlyOne(roomDtos, "未找到房屋信息");
 
        OwnerDto ownerDto = new OwnerDto();
        ownerDto.setCommunityId(communityId);
        ownerDto.setRoomId(roomDtos.get(0).getRoomId());
        ownerDto.setOwnerTypeCd(OwnerDto.OWNER_TYPE_CD_OWNER);
        List<OwnerDto> ownerDtos = ownerInnerServiceSMOImpl.queryOwners(ownerDto);
        Assert.listOnlyOne(ownerDtos, "未找到业主信息");
        //查询是否有脱敏权限
        List<Map> mark = getPrivilegeOwnerList("/roomCreateFee", userId);
        List<OwnerDto> ownerDtoList = new ArrayList<>();
        for (OwnerDto owner : ownerDtos) {
            //对业主身份证号隐藏处理
            String idCard = owner.getIdCard();
            if (mark.size() == 0 && idCard != null && idCard.length() >= 16) {
                idCard = idCard.substring(0, 6) + "**********" + idCard.substring(16);
            }
            //对业主手机号隐藏处理
            String link = owner.getLink();
            if (mark.size() == 0 && link != null && link.length() == 11) {
                link = link.substring(0, 3) + "****" + link.substring(7);
            }
            owner.setIdCard(idCard);
            owner.setLink(link);
            ownerDtoList.add(owner);
        }
 
        OwnerDto resOwnerDto = ownerDtoList.get(0);
 
        resOwnerDto.setRooms(roomDtos);
 
        return resOwnerDto;
    }
 
    /**
     * 根据合同查询
     *
     * @param communityId
     * @param searchValue
     * @return
     */
    private OwnerDto queryByContract(String communityId, String searchValue, String userId, String storeId) {
 
 
        ContractDto contractDto = new ContractDto();
        contractDto.setContractCode(searchValue);
        contractDto.setStoreId(storeId);
        List<ContractDto> contractDtos = contractInnerServiceSMOImpl.queryContracts(contractDto);
        Assert.listOnlyOne(contractDtos, "未找到合同信息");
 
        OwnerDto ownerDto = new OwnerDto();
        ownerDto.setCommunityId(communityId);
        ownerDto.setMemberId(contractDtos.get(0).getObjId());
        ownerDto.setOwnerTypeCd(OwnerDto.OWNER_TYPE_CD_OWNER);
        List<OwnerDto> ownerDtos = ownerInnerServiceSMOImpl.queryOwners(ownerDto);
        Assert.listOnlyOne(ownerDtos, "未找到业主信息或者查询到多条,请换其他条件查询");
        //查询是否有脱敏权限
        List<Map> mark = getPrivilegeOwnerList("/roomCreateFee", userId);
        List<OwnerDto> ownerDtoList = new ArrayList<>();
        for (OwnerDto owner : ownerDtos) {
            //对业主身份证号隐藏处理
            String idCard = owner.getIdCard();
            if (mark.size() == 0 && idCard != null && !idCard.equals("")) {
                idCard = idCard.substring(0, 6) + "**********" + idCard.substring(16);
            }
            //对业主手机号隐藏处理
            String link = owner.getLink();
            if (mark.size() == 0 && link != null && !link.equals("")) {
                link = link.substring(0, 3) + "****" + link.substring(7);
            }
            owner.setIdCard(idCard);
            owner.setLink(link);
            ownerDtoList.add(owner);
        }
        OwnerDto resOwnerDto = ownerDtoList.get(0);
        OwnerRoomRelDto ownerRoomRelDto = new OwnerRoomRelDto();
        ownerRoomRelDto.setOwnerId(ownerDtoList.get(0).getOwnerId());
        List<OwnerRoomRelDto> ownerRoomRelDtos = ownerRoomRelInnerServiceSMOImpl.queryOwnerRoomRels(ownerRoomRelDto);
 
        //没有房屋
        if (ownerRoomRelDtos == null || ownerRoomRelDtos.size() < 1) {
            return resOwnerDto;
        }
        List<String> roomIds = new ArrayList<>();
        for (OwnerRoomRelDto tmpOwnerRoomRelDto : ownerRoomRelDtos) {
            roomIds.add(tmpOwnerRoomRelDto.getRoomId());
        }
 
 
        RoomDto roomDto = new RoomDto();
        roomDto.setRoomIds(roomIds.toArray(new String[roomIds.size()]));
        roomDto.setCommunityId(communityId);
        List<RoomDto> roomDtos = roomInnerServiceSMOImpl.queryRooms(roomDto);
        resOwnerDto.setRooms(roomDtos);
        return resOwnerDto;
    }
 
    /**
     * 脱敏处理
     *
     * @return
     */
    public List<Map> getPrivilegeOwnerList(String resource, String userId) {
        BasePrivilegeDto basePrivilegeDto = new BasePrivilegeDto();
        basePrivilegeDto.setResource(resource);
        basePrivilegeDto.setUserId(userId);
        List<Map> privileges = menuInnerServiceSMOImpl.checkUserHasResource(basePrivilegeDto);
        return privileges;
    }
}