44323
2024-01-29 125a6f192ed7e611739f8648cf036360f600c41b
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
package com.stylefeng.guns.modular.system.service.impl;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alipay.api.internal.util.codec.Base64;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.stylefeng.guns.core.util.ToolUtil;
import com.stylefeng.guns.modular.file.OSSService;
import com.stylefeng.guns.modular.system.dao.HousingDemandMapper;
import com.stylefeng.guns.modular.system.model.*;
import com.stylefeng.guns.modular.system.service.*;
import com.stylefeng.guns.modular.system.util.ResultUtil;
import com.stylefeng.guns.modular.system.util.UUIDUtil;
import com.stylefeng.guns.modular.system.util.WxAppletTools;
import com.stylefeng.guns.modular.system.warpper.req.HousingDemandReq;
import com.stylefeng.guns.modular.system.warpper.req.SearchHousingDemandReq;
import com.stylefeng.guns.modular.system.warpper.res.ContactInformationRes;
import com.stylefeng.guns.modular.system.warpper.res.HousingDemandInfoRes;
import com.stylefeng.guns.modular.system.warpper.res.SearchHousingDemandListRes;
import com.stylefeng.guns.modular.system.warpper.res.SearchHousingDemandRes;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.util.StringUtils;
import org.springframework.web.client.RestTemplate;
 
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.security.SecureRandom;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * @author zhibing.pu
 * @Date 2023/11/20 16:59
 */
@Service
public class HousingDemandServiceImpl extends ServiceImpl<HousingDemandMapper, HousingDemand> implements IHousingDemandService {
 
    @Autowired
    private IAppUserService appUserService;
    @Autowired
    private IHousingDemandDistrictService housingDemandDistrictService;
    @Autowired
    private IRegionService regionService;
    @Autowired
    private IHouseTypeService houseTypeService;
    @Autowired
    private ICollectionHousingDemandService collectionHousingDemandService;
 
    @Autowired
    private WxAppletTools wxAppletTools;
    @Autowired
    private RestTemplate restTemplate;
    @Autowired
    private OSSService ossService;
 
    /**
     * 添加房源需求
     * @param req
     */
    @Override
    public ResultUtil addHousingDemand(HousingDemandReq req) {
        AppUser appUser = appUserService.getAppUser();
        if(null == appUser){
            return ResultUtil.tokenErr();
        }
        String s=null;
        if (StringUtils.hasLength(req.getDistrict())){
            s = req.getDistrict().replaceAll("\"", "");
        }
        HousingDemand housingDemand = new HousingDemand();
        housingDemand.setType(req.getType());
        BeanUtils.copyProperties(req, housingDemand);
        housingDemand.setDistrict(s);
        try {
            housingDemand.setCode(UUIDUtil.getRandomCode(8));
        } catch (Exception e) {
            e.printStackTrace();
        }
        housingDemand.setIsDelete(0);
        housingDemand.setInsertTime(new Date());
        housingDemand.setInsertUserId(appUser.getId());
        housingDemand.setAppUserId(appUser.getId());
        housingDemand.setStatus(1);
        housingDemand.setUpdateTime(new Date());
        if (StringUtils.hasLength(req.getSaleAmount())&&req.getSaleAmount().equals("2000")){
            housingDemand.setSaleAmount("2000-99999999");
        }
        if (StringUtils.hasLength(req.getSaleAmount())&&req.getSaleAmount().equals("500")){
            housingDemand.setSaleAmount("0-500");
        }
        if (req.getType()==2){
            this.insertOrUpdate(housingDemand);
        }else{
            this.insertOrUpdate(housingDemand);
        }
        if (req.getType()==2){
            if (StringUtils.hasLength(req.getWechatQRCode()))appUser.setWechatQrCode1(req.getWechatQRCode());
            if (StringUtils.hasLength(req.getWatchApp()))appUser.setWatchApp1(req.getWatchApp());
            if (StringUtils.hasLength(req.getPhone()))appUser.setPhone1(req.getPhone());
            appUserService.updateById(appUser);
            InputStream inputStream = null;
            OutputStream outputStream = null;
            String accessToken = wxAppletTools.getAccessToken();
            try {
                String url = "https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=" + accessToken;
                Map<String, Object> param = new HashMap<>();
                param.put("scene","id="+housingDemand.getId());
                param.put("page", "pageA/housingDetails");
                param.put("check_path", false);
                param.put("env_version", "trial");
                param.put("width", 200); //二维码尺寸
                param.put("is_hyaline", true); // 是否需要透明底色, is_hyaline 为true时,生成透明底色的小程序码 参数仅对小程序码生效
                param.put("auto_color", true); // 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调 参数仅对小程序码生效
                Map<String, Object> line_color = new HashMap<>();
                line_color.put("r", 0);
                line_color.put("g", 0);
                line_color.put("b", 0);
                param.put("line_color", line_color);
                System.err.println("调用生成微信URL接口传参:" + param);
                MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
                HttpEntity requestEntity = new HttpEntity(param, headers);
                ResponseEntity<byte[]> entity = restTemplate.exchange(url, HttpMethod.POST, requestEntity, byte[].class, new Object[0]);
                System.err.println("调用小程序生成微信永久小程序码URL接口返回结果:" + entity.getBody());
                byte[] result = entity.getBody();
                System.err.println(Base64.encodeBase64String(result));
                inputStream = new ByteArrayInputStream(result);
                SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
                // 最后上传生成的文件名
                String finalFileName = System.currentTimeMillis() + "" + new SecureRandom().nextInt(0x0400) + ".jpg";
                // oss中的文件夹名
                String objectName = sdf.format(new Date()) + "/" + finalFileName;
                // 上传oss
                ossService.uploadFile2OSS(inputStream, objectName);
                //获取文件的URl地址
                String imgUrl = ossService.getImgUrl(objectName);
                housingDemand.setQrCode(imgUrl);
                this.baseMapper.updateById(housingDemand);
                System.err.println("看看文件路径" + imgUrl);
            } catch (Exception e) {
                System.err.println("调用小程序生成微信永久小程序码URL接口异常" + e);
            } finally {
                if (inputStream != null) {
                    try {
                        inputStream.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                if (outputStream != null) {
                    try {
                        outputStream.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
 
                    return null;
                }
            }
        }
        List<HousingDemandDistrict> list = new ArrayList<>();
        if(ToolUtil.isNotEmpty(req.getDistrict())){
            JSONArray jsonArray = JSON.parseArray(req.getDistrict());
            for (int i = 0; i < jsonArray.size(); i++) {
                JSONObject jsonObject = jsonArray.getJSONObject(i);
                Integer cityId = jsonObject.getInteger("cityId");
                Integer districtId = jsonObject.getInteger("districtId");
                //不限区域
                if(null == districtId){
                    districtId = 0;
                }
                HousingDemandDistrict housingDemandDistrict = new HousingDemandDistrict();
                housingDemandDistrict.setCityId(cityId);
                housingDemandDistrict.setDistrictId(districtId);
                housingDemandDistrict.setHousingDemandId(housingDemand.getId());
                list.add(housingDemandDistrict);
            }
        }
        if(list.size() > 0){
            housingDemandDistrictService.insertBatch(list);
        }
 
        return ResultUtil.success();
    }
 
    /**
     * 搜索求房源列表数据
     * @param req
     * @return
     */
    @Override
    public SearchHousingDemandRes searchHousingDemand(SearchHousingDemandReq req) {
        req.setPageNum((req.getPageNum() - 1) * req.getPageSize());
        //区域一级
        List<Integer> districtIds = new ArrayList<>();
        // 二级
        List<Integer> areaIds = new ArrayList<>();
        if (req.getDistrict() != null &&(!req.getDistrict().equals("")) ){
            // 一级id
            Integer integer = Integer.valueOf(req.getDistrict());
            districtIds.add(integer);
            if (req.getArea()!=null && (!req.getArea().equals(""))){
                String[] split = req.getArea().split(",");
                for (String s : split) {
                    areaIds.add(Integer.valueOf(s));
                }
            }
        }
        //价格范围
        Double saleAmountStart = null;
        Double saleAmountEnd = null;
        if(StringUtils.hasLength(req.getSaleAmount())){
            if (req.getSaleAmount().contains("以上")){
                saleAmountEnd =2001.0;
                saleAmountStart = 2000.0;
            }else if (req.getSaleAmount().contains("以下")){
                saleAmountEnd =500.0;
                saleAmountStart = 0.0;
            }else{
                String[] split = req.getSaleAmount().split("-");
                saleAmountStart = Double.valueOf(split[0]);
                saleAmountEnd = Double.valueOf(split[1]);
            }
        }
        //户型
        List<String> houseModels = null;
        if(StringUtils.hasLength(req.getHouseModel())){
            String[] split = req.getHouseModel().split(",");
            houseModels = Arrays.asList(split);
        }
        //房型
        List<Integer> houseTypeIds = null;
        if(StringUtils.hasLength(req.getHouseTypeId())){
            houseTypeIds = new ArrayList<>();
            String[] split = req.getHouseTypeId().split(",");
            for (String s : split) {
                houseTypeIds.add(Integer.valueOf(s));
            }
            houseTypeIds.add(0);
        }
        SearchHousingDemandRes searchHouseResource = new SearchHousingDemandRes();
        List<SearchHousingDemandListRes> searchHouseResourceListRes = this.baseMapper.searchHousingDemand
                (req, districtIds,areaIds, saleAmountStart, saleAmountEnd, houseModels, houseTypeIds);
        for (SearchHousingDemandListRes searchHouseResourceListRe : searchHouseResourceListRes) {
            // 获取到房源区域id集合
            List<HousingDemandDistrict> list1 = housingDemandDistrictService.selectList(new EntityWrapper<HousingDemandDistrict>()
                    .eq("housing_demand_id", searchHouseResourceListRe.getId())
            ).stream().filter(t -> t.getCityId() == 1).collect(Collectors.toList());
            List<HousingDemandDistrict> list2 = housingDemandDistrictService.selectList(new EntityWrapper<HousingDemandDistrict>()
                    .eq("housing_demand_id", searchHouseResourceListRe.getId())
            ).stream().filter(t -> t.getCityId() == 2).collect(Collectors.toList());
            List<HousingDemandDistrict> list3 = housingDemandDistrictService.selectList(new EntityWrapper<HousingDemandDistrict>()
                    .eq("housing_demand_id", searchHouseResourceListRe.getId())
            ).stream().filter(t -> t.getCityId() == 3).collect(Collectors.toList());
            List<String> dis = new ArrayList<>();
            StringBuilder s1 = new StringBuilder("香港岛>");
            StringBuilder s2 = new StringBuilder("九龙>");
            StringBuilder s3 = new StringBuilder("新界>");
            for (HousingDemandDistrict housingDemandDistrict : list1) {
                Region region1 = regionService.selectById(housingDemandDistrict.getDistrictId());
                s1.append((null == region1 ? "不限" : region1.getName())+"/");
            }
            for (HousingDemandDistrict housingDemandDistrict : list2) {
                Region region1 = regionService.selectById(housingDemandDistrict.getDistrictId());
                s2.append((null == region1 ? "不限" : region1.getName())+"/");
            }
            for (HousingDemandDistrict housingDemandDistrict : list3) {
                Region region1 = regionService.selectById(housingDemandDistrict.getDistrictId());
                s3.append((null == region1 ? "不限" : region1.getName())+"/");
            }
            String string1 = s1.toString();
            String string2 = s2.toString();
            String string3 = s3.toString();
            String substring1=string1;
            String substring2=string2;
            String substring3=string3;
            if (string1.endsWith("/")){
                substring1 = string1.substring(0, string1.length() - 1);
            }
            if (string2.endsWith("/")){
                substring2 = string2.substring(0, string2.length() - 1);
            }
            if (string3.endsWith("/")){
                substring3 = string3.substring(0, string3.length() - 1);
            }
            if (!substring1.equals("香港岛>")){
                dis.add(substring1);
            }
            if (!substring2.equals("九龙>")){
                dis.add(substring2);
            }
            if (!substring3.equals("新界>")){
                dis.add(substring3);
            }
            //城市不限用空判断
            searchHouseResourceListRe.setAddress(dis.size() == 0 ? null : dis);
        }
        List<SearchHousingDemandListRes> collect = new ArrayList<>();
        if (StringUtils.hasLength(req.getRentalDuration())){
            if (req.getRentalDuration().equals("2")){
                collect = searchHouseResourceListRes.stream().filter(t -> t.getRentalDuration()!=null && t.getRentalDuration()>= 12)
                        .collect(Collectors.toList());
            }else if (req.getRentalDuration().equals("1")){
                collect = searchHouseResourceListRes.stream().filter(t ->t.getRentalDuration()!=null && t.getRentalDuration() < 12)
                        .collect(Collectors.toList());
            }
            searchHouseResource.setList(collect);
            searchHouseResource.setTotal(collect.size());
        }else{
            searchHouseResource.setList(searchHouseResourceListRes);
            searchHouseResource.setTotal(searchHouseResourceListRes.size());
        }
        return searchHouseResource;
    }
 
    /**
     * 搜索求房源列表数据
     * @return
     */
    @Override
    public SearchHousingDemandRes searchHousingDemand1(Integer id) {
 
        SearchHousingDemandRes searchHouseResource = new SearchHousingDemandRes();
        List<SearchHousingDemandListRes> searchHouseResourceListRes = this.baseMapper.searchHousingDemand1(id);
        for (SearchHousingDemandListRes searchHouseResourceListRe : searchHouseResourceListRes) {
            // 获取到房源区域id集合
            List<HousingDemandDistrict> list1 = housingDemandDistrictService.selectList(new EntityWrapper<HousingDemandDistrict>()
                    .eq("housing_demand_id", searchHouseResourceListRe.getId())
            ).stream().filter(t -> t.getCityId() == 1).collect(Collectors.toList());
            List<HousingDemandDistrict> list2 = housingDemandDistrictService.selectList(new EntityWrapper<HousingDemandDistrict>()
                    .eq("housing_demand_id", searchHouseResourceListRe.getId())
            ).stream().filter(t -> t.getCityId() == 2).collect(Collectors.toList());
            List<HousingDemandDistrict> list3 = housingDemandDistrictService.selectList(new EntityWrapper<HousingDemandDistrict>()
                    .eq("housing_demand_id", searchHouseResourceListRe.getId())
            ).stream().filter(t -> t.getCityId() == 3).collect(Collectors.toList());
            List<String> dis = new ArrayList<>();
            StringBuilder s1 = new StringBuilder("香港岛>");
            StringBuilder s2 = new StringBuilder("九龙>");
            StringBuilder s3 = new StringBuilder("新界>");
            for (HousingDemandDistrict housingDemandDistrict : list1) {
                Region region1 = regionService.selectById(housingDemandDistrict.getDistrictId());
                s1.append((null == region1 ? "不限" : region1.getName())+"/");
            }
            for (HousingDemandDistrict housingDemandDistrict : list2) {
                Region region1 = regionService.selectById(housingDemandDistrict.getDistrictId());
                s2.append((null == region1 ? "不限" : region1.getName())+"/");
            }
            for (HousingDemandDistrict housingDemandDistrict : list3) {
                Region region1 = regionService.selectById(housingDemandDistrict.getDistrictId());
                s3.append((null == region1 ? "不限" : region1.getName())+"/");
            }
            String string1 = s1.toString();
            String string2 = s2.toString();
            String string3 = s3.toString();
            String substring1=string1;
            String substring2=string2;
            String substring3=string3;
            if (string1.endsWith("/")){
                substring1 = string1.substring(0, string1.length() - 1);
            }
            if (string2.endsWith("/")){
                substring2 = string2.substring(0, string2.length() - 1);
            }
            if (string3.endsWith("/")){
                substring3 = string3.substring(0, string3.length() - 1);
            }
            if (!substring1.equals("香港岛>")){
                dis.add(substring1);
            }
            if (!substring2.equals("九龙>")){
                dis.add(substring2);
            }
            if (!substring3.equals("新界>")){
                dis.add(substring3);
            }
            //城市不限用空判断
            searchHouseResourceListRe.setAddress(dis.size() == 0 ? null : dis);
        }
        searchHouseResource.setList(searchHouseResourceListRes);
        searchHouseResource.setTotal(searchHouseResourceListRes.size());
        return searchHouseResource;
    }
 
    @Override
    public SearchHousingDemandRes searchHousingDemand2(List<Integer> id) {
        SearchHousingDemandRes searchHouseResource = new SearchHousingDemandRes();
        List<SearchHousingDemandListRes> searchHouseResourceListRes = this.baseMapper.searchHousingDemand2(id);
        for (SearchHousingDemandListRes searchHouseResourceListRe : searchHouseResourceListRes) {
            List<HousingDemandDistrict> list = housingDemandDistrictService.selectList(new EntityWrapper<HousingDemandDistrict>()
                    .eq("housing_demand_id", searchHouseResourceListRe.getId()));
            List<String> dis = new ArrayList<>();
            for (HousingDemandDistrict housingDemandDistrict : list) {
                Region region = regionService.selectById(housingDemandDistrict.getCityId());
                Region region1 = regionService.selectById(housingDemandDistrict.getDistrictId());
                dis.add(region.getName() + ">" + (null == region1 ? "不限" : region1.getName()));
            }
            //城市不限用空判断
            searchHouseResourceListRe.setAddress(dis.size() == 0 ? null : dis);
        }
        searchHouseResource.setList(searchHouseResourceListRes);
        searchHouseResource.setTotal(searchHouseResourceListRes.size());
        return searchHouseResource;
    }
    /**
     * 求房源详情
     * @param id
     * @return
     */
    @Override
    public HousingDemandInfoRes housingDemandInfo(Integer id) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        HousingDemand housingDemand = this.selectById(id);
        HousingDemandInfoRes housingDemandInfoRes = new HousingDemandInfoRes();
//        AppUser appUser = appUserService.getAppUser();
        housingDemandInfoRes.setId(id);
        housingDemandInfoRes.setDataType(housingDemand.getDataType());
        housingDemandInfoRes.setQrCode(housingDemand.getQrCode());
        housingDemandInfoRes.setTitle(housingDemand.getTitle());
        housingDemandInfoRes.setSaleAmount(housingDemand.getSaleAmount());
        housingDemandInfoRes.setHouseModel(housingDemand.getHouseModel());
        housingDemandInfoRes.setRentalDuration(housingDemand.getRentalDuration());
        housingDemandInfoRes.setSaleDate(housingDemand.getSaleDate());
        if (StringUtils.hasLength(housingDemand.getHouseTypeId())){
            if (housingDemand.getHouseTypeId().equals("0")){
                housingDemandInfoRes.setHouseType("不限");
            }else{
                String[] split = housingDemand.getHouseTypeId().split(",");
                String houseType = "";
                for (String s : split) {
                    HouseType htype = houseTypeService.selectById(s);
                    if (htype!=null)houseType += htype.getName() + " / ";
                }
                if (StringUtils.hasLength(houseType))housingDemandInfoRes.setHouseType(houseType.substring(0, houseType.lastIndexOf("/")));
            }
        }
        housingDemandInfoRes.setFloor(housingDemand.getFloor());
        housingDemandInfoRes.setElevator(housingDemand.getElevator());
        StringBuilder stringBuilder = new StringBuilder("");
        if (housingDemand.getBalcony()==1 && housingDemand.getAir()==1 && housingDemand.getDryingArea()==1){
            stringBuilder.append("不限");
        }else{
            if (housingDemand.getBalcony()!=null && housingDemand.getBalcony() == 1){
                stringBuilder.append("阳台");
            }
            if (housingDemand.getDryingArea()!=null && housingDemand.getDryingArea() == 1){
                stringBuilder.append("| 天台");
            }
            if (housingDemand.getAir()!=null && housingDemand.getAir() == 1){
                stringBuilder.append("| 无");
            }
        }
        housingDemandInfoRes.setDryingArea(stringBuilder.toString());
        housingDemandInfoRes.setHouseArea(housingDemand.getHouseArea());
        housingDemandInfoRes.setKeepPet(housingDemand.getKeepPet());
        // 获取到房源区域id集合
        List<HousingDemandDistrict> list1 = housingDemandDistrictService.selectList(new EntityWrapper<HousingDemandDistrict>()
                .eq("housing_demand_id", id)
        ).stream().filter(t -> t.getCityId() == 1).collect(Collectors.toList());
        List<HousingDemandDistrict> list2 = housingDemandDistrictService.selectList(new EntityWrapper<HousingDemandDistrict>()
                .eq("housing_demand_id", id)
        ).stream().filter(t -> t.getCityId() == 2).collect(Collectors.toList());
        List<HousingDemandDistrict> list3 = housingDemandDistrictService.selectList(new EntityWrapper<HousingDemandDistrict>()
                .eq("housing_demand_id", id)
        ).stream().filter(t -> t.getCityId() == 3).collect(Collectors.toList());
        List<String> dis = new ArrayList<>();
        StringBuilder s1 = new StringBuilder("香港岛>");
        StringBuilder s2 = new StringBuilder("九龙>");
        StringBuilder s3 = new StringBuilder("新界>");
        for (HousingDemandDistrict housingDemandDistrict : list1) {
            Region region1 = regionService.selectById(housingDemandDistrict.getDistrictId());
            s1.append((null == region1 ? "不限" : region1.getName())+"/");
        }
        for (HousingDemandDistrict housingDemandDistrict : list2) {
            Region region1 = regionService.selectById(housingDemandDistrict.getDistrictId());
            s2.append((null == region1 ? "不限" : region1.getName())+"/");
        }
        for (HousingDemandDistrict housingDemandDistrict : list3) {
            Region region1 = regionService.selectById(housingDemandDistrict.getDistrictId());
            s3.append((null == region1 ? "不限" : region1.getName())+"/");
        }
        String string1 = s1.toString();
        String string2 = s2.toString();
        String string3 = s3.toString();
        String substring1=string1;
        String substring2=string2;
        String substring3=string3;
        if (string1.endsWith("/")){
            substring1 = string1.substring(0, string1.length() - 1);
        }
        if (string2.endsWith("/")){
            substring2 = string2.substring(0, string2.length() - 1);
        }
        if (string3.endsWith("/")){
            substring3 = string3.substring(0, string3.length() - 1);
        }
        if (!substring1.equals("香港岛>")){
            dis.add(substring1);
        }
        if (!substring2.equals("九龙>")){
            dis.add(substring2);
        }
        if (!substring3.equals("新界>")){
            dis.add(substring3);
        }
        //城市不限用空判断
        housingDemandInfoRes.setAddress(dis.size() == 0 ? null : dis);
        housingDemandInfoRes.setMoreIntroduction(housingDemand.getMoreIntroduction());
        housingDemandInfoRes.setViewsNumber(housingDemand.getViewsNumber());
        AppUser appUser1 = appUserService.selectById(housingDemand.getAppUserId());
        housingDemandInfoRes.setProfilePhoto(appUser1.getProfilePhoto());
        housingDemandInfoRes.setNickname(appUser1.getNickname());
        housingDemandInfoRes.setInsertTime(sdf.format(housingDemand.getInsertTime()));
        if (housingDemand.getUpdateTime()==null){
            housingDemandInfoRes.setUpdateTime(null);
        }else{
            housingDemandInfoRes.setUpdateTime(sdf.format(housingDemand.getUpdateTime()));
        }
        housingDemandInfoRes.setCode(housingDemand.getCode());
        int collectionTimes = collectionHousingDemandService.selectCount(new EntityWrapper<CollectionHousingDemand>().eq("housing_demand_id", id));
        housingDemandInfoRes.setCollectionTimes(collectionTimes);
        housingDemandInfoRes.setCollection(0);
//        if(null != appUser){
//            int collection = collectionHousingDemandService
//                    .selectCount(new EntityWrapper<CollectionHousingDemand>()
//                            .eq("housing_demand_id", id)
//                            .eq("app_user_id", appUser.getId()));
//            housingDemandInfoRes.setCollection(0 == collection ? 0 : 1);
//        }
        //添加访问次数记录
//        addViewsNumber(housingDemand);
        return housingDemandInfoRes;
    }
 
 
    /**
     * 添加访问次数记录
     * @param housingDemand
     */
    private void addViewsNumber(HousingDemand housingDemand){
        housingDemand.setViewsNumber((null == housingDemand.getViewsNumber() ? 0 : housingDemand.getViewsNumber()) + 1);
        this.updateById(housingDemand);
    }
 
 
    /**
     * 获取联系方式
     * @param id
     * @return
     */
    @Override
    public ContactInformationRes getContactInformation(Integer id) {
        HousingDemand houseResource = this.selectById(id);
        ContactInformationRes contactInformationRes = new ContactInformationRes();
        contactInformationRes.setWatchApp(houseResource.getWatchApp());
        contactInformationRes.setPhone(houseResource.getPhone());
        contactInformationRes.setWechatQrCode(houseResource.getWechatQRCode());
        return contactInformationRes;
    }
 
    /**
     * 获取剩余发布数量
     * @return
     */
    @Override
    public ResultUtil<Integer> getSurplusPushNumber() {
        AppUser appUser = appUserService.getAppUser();
        if(null == appUser){
            return ResultUtil.tokenErr();
        }
        int num = this.selectCount(new EntityWrapper<HousingDemand>()
                .eq("is_delete", 0)
                .eq("app_user_id", appUser.getId())
                .eq("type", 2)
        );
        if (appUser.getAuth()==2){
            return ResultUtil.success(99999);
        }
        return ResultUtil.success(appUser.getUserType() != 3 ? (3 - num) : -1);
    }
}