From cef87e5c90c5551df2f98047e113530d79270e9f Mon Sep 17 00:00:00 2001
From: 44323 <443237572@qq.com>
Date: 星期三, 17 一月 2024 14:30:51 +0800
Subject: [PATCH] 修改附近方圆报错

---
 guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/AppUserServiceImpl.java |  539 ++++++++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 404 insertions(+), 135 deletions(-)

diff --git a/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/AppUserServiceImpl.java b/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/AppUserServiceImpl.java
index 6acf120..d0e98af 100644
--- a/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/AppUserServiceImpl.java
+++ b/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/AppUserServiceImpl.java
@@ -8,21 +8,15 @@
 import com.stylefeng.guns.core.util.JwtTokenUtil;
 import com.stylefeng.guns.core.util.ToolUtil;
 import com.stylefeng.guns.modular.system.dao.AppUserMapper;
-import com.stylefeng.guns.modular.system.model.AppUser;
-import com.stylefeng.guns.modular.system.model.CollectionHouseResource;
-import com.stylefeng.guns.modular.system.model.HouseResource;
-import com.stylefeng.guns.modular.system.model.Region;
-import com.stylefeng.guns.modular.system.service.IAppUserService;
-import com.stylefeng.guns.modular.system.service.ICollectionHouseResourceService;
-import com.stylefeng.guns.modular.system.service.IHousingDemandService;
-import com.stylefeng.guns.modular.system.service.IRegionService;
-import com.stylefeng.guns.modular.system.util.RedisUtil;
-import com.stylefeng.guns.modular.system.util.ResultUtil;
-import com.stylefeng.guns.modular.system.util.UUIDUtil;
+import com.stylefeng.guns.modular.system.model.*;
+import com.stylefeng.guns.modular.system.service.*;
+import com.stylefeng.guns.modular.system.util.*;
 import com.stylefeng.guns.modular.system.util.weChat.WXCore;
 import com.stylefeng.guns.modular.system.util.weChat.WeChatUtil;
 import com.stylefeng.guns.modular.system.warpper.req.*;
 import com.stylefeng.guns.modular.system.warpper.res.*;
+import io.swagger.annotations.ApiModelProperty;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.util.StringUtils;
@@ -31,10 +25,11 @@
 import sun.rmi.runtime.Log;
 
 import javax.servlet.http.HttpServletRequest;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
+import java.math.BigDecimal;
+import java.text.SimpleDateFormat;
+import java.time.LocalDate;
+import java.time.ZoneId;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -55,10 +50,13 @@
     @Autowired
     private HouseResourceService houseResourceService;
     @Autowired
+    private IHousingDemandService housingDemandService;
+    @Autowired
     private CollectionHouseResourceServiceImpl collectionHouseResourceService;
-
-
-
+    @Autowired
+    private ICollectionHousingDemandService collectionHousingDemandService;
+    @Autowired
+    private IHouseTypeService houseTypeService;
 
     /**
      * 通过token获取用户信息
@@ -71,7 +69,7 @@
         String authorization = request.getHeader("Authorization");
         // todo 这里注释了一段代码
         // && authorization.contains("Bearer")
-        if(ToolUtil.isNotEmpty(authorization) && authorization.contains("Bearer") ){
+        if(ToolUtil.isNotEmpty(authorization) && authorization.contains("Bearer ") ){
             String token = authorization.substring(7);
             //通过token获取用户id
             Integer appUserId = getAppUserIdFromToken(token);
@@ -80,17 +78,13 @@
         return null;
     }
 
-
-
-
-
-
     /**
      * 小程序登录
      * @return
      */
     @Override
-    public ResultUtil<AppletLoginRes> appletLogin(RegisterAccountReq req) {
+    public ResultUtil<AppletLoginRes>
+    appletLogin(RegisterAccountReq req) {
         try {
             //调用微信获取用户小程序openid
             Map<String, Object> map = weChatUtil.code2Session(req.getJscode());
@@ -98,48 +92,32 @@
                 return ResultUtil.error("获取微信身份信息失败");
             }
             String openid = map.get("openid").toString();
+            String sessionKey = map.get("sessionKey").toString();
+            //解密手机号
+            String phone = WXCore.decrypt(req.getEncryptedPhoneData(), sessionKey, req.getPhone_iv());
+            JSONObject jsonObject = JSONObject.parseObject(phone);
+            String phone1 = jsonObject.getString("phoneNumber");
             AppUser appUser = this.selectOne(new EntityWrapper<AppUser>()
                     .eq("wechat_openid", openid)
-                    .eq("audit_status", 2)
-                    .eq("status", 1));
-            AppletLoginRes appletLoginRes = new AppletLoginRes();
-            if(null != appUser){
-                String token = JwtTokenUtil.generateToken(appUser.getPhone());
-                appletLoginRes.setToken(token);
-                appletLoginRes.setUserType(appUser.getUserType());
-            }else{
-                System.err.println("新增");
-                String sessionKey = map.get("sessionKey").toString();
-                //解密手机号
-                String phone = WXCore.decrypt(req.getEncryptedPhoneData(), sessionKey, req.getPhone_iv());
-                appUser = this.selectOne(new EntityWrapper<AppUser>()
-                        .eq("phone", phone)
-                        .eq("audit_status", 2)
-                        .eq("status", 1));
-                if(null == appUser){
-                    JSONObject jsonObject = JSONObject.parseObject(phone);
-                    String phone1 = jsonObject.getString("phoneNumber");
-                    System.err.println("看看json");
-                    System.err.println(jsonObject);
-                    System.err.println(phone1);
-                    //注册新账号
-                    addNewAppUser(openid, phone1);
-                }else{
-                    appUser.setWechatOpenid(openid);
-                    this.updateById(appUser);
-                }
+                    .eq("phone",phone1)
+            .ne("status",3));
+            if(null != appUser && (appUser.getStatus() == 2|| appUser.getStatus() == 3)){
+                return ResultUtil.errorLogin("当前账号已被冻结或删除");
             }
-            AppUser appUser1 = this.selectOne(new EntityWrapper<AppUser>()
-                    .eq("wechat_openid", openid)
-                    .eq("audit_status", 2)
-                    .eq("status", 1));
+            AppletLoginRes appletLoginRes = new AppletLoginRes();
+            if(null == appUser){
+                //注册新账号
+                appUser = addNewAppUser(openid, phone1);
+            }
             //生成token
-            String token = JwtTokenUtil.generateToken(appUser1.getPhone());
+            String token = JwtTokenUtil.generateToken(appUser.getPhone());
+            System.err.println("token1111--->" + token);
+            appletLoginRes.setState(appUser.getAuth());
             appletLoginRes.setToken(token);
-            appletLoginRes.setUserType(appUser1.getUserType());
+            appletLoginRes.setUserType(appUser.getUserType());
             System.err.println("看看TOKEN:"+token);
             //存入缓存中
-            addTokenToRedis(token, appUser1.getId());
+            addTokenToRedis(token, appUser.getId());
             return ResultUtil.success(appletLoginRes);
         }catch (Exception e){
             e.printStackTrace();
@@ -166,8 +144,11 @@
             String openid = map.get("openid").toString();
             AppUser appUser = this.selectOne(new EntityWrapper<AppUser>()
                     .eq("wechat_openid", openid)
-                    .eq("audit_status", 2)
+                    .ne("audit_status", 3)
                     .eq("status", 1));
+            if(null != appUser && appUser.getAuditStatus() == 1){
+                return ResultUtil.error("账号审核中");
+            }
             AppletLoginRes appletLoginRes = new AppletLoginRes();
             if(null == appUser){
                 String sessionKey = map.get("sessionKey").toString();
@@ -184,22 +165,18 @@
                     System.err.println(jsonObject);
                     System.err.println(phone1);
                     //注册新账号
-                    addNewAppUser(openid, phone1);
+                    appUser = addNewAppUser(openid, phone1);
                 }else{
                     appUser.setWechatOpenid(openid);
                     this.updateById(appUser);
                 }
             }
-            AppUser appUser1 = this.selectOne(new EntityWrapper<AppUser>()
-                    .eq("wechat_openid", openid)
-                    .eq("audit_status", 2)
-                    .eq("status", 1));
             //生成token
-            String token = JwtTokenUtil.generateToken(appUser1.getPhone());
+            String token = JwtTokenUtil.generateToken(appUser.getPhone());
             appletLoginRes.setToken(token);
-            appletLoginRes.setUserType(appUser1.getUserType());
+            appletLoginRes.setUserType(appUser.getUserType());
             //存入缓存中
-            addTokenToRedis(token, appUser1.getId());
+            addTokenToRedis(token, appUser.getId());
             return ResultUtil.success(appletLoginRes);
         }catch (Exception e){
             e.printStackTrace();
@@ -226,8 +203,9 @@
         }
         SearchIntermediaryRes searchIntermediaryRes = new SearchIntermediaryRes();
         List<SearchIntermediaryListRes> res =this.baseMapper.searchIntermediaryList(req,districtIds,cityIds);
+        List<SearchIntermediaryListRes> res1 =this.baseMapper.searchIntermediaryList1(req,districtIds,cityIds);
         searchIntermediaryRes.setList(res);
-        searchIntermediaryRes.setTotal(res.size());
+        searchIntermediaryRes.setTotal(res1.size());
         return searchIntermediaryRes;
     }
 
@@ -235,40 +213,89 @@
     public ResultUtil<AppUser> userInfo() {
         // 获取当前登录用户
         AppUser appUser = appUserService.getAppUser();
+        if (!StringUtils.hasLength(appUser.getProfilePhoto())){
+            appUser.setProfilePhoto("https://bizuphk.oss-cn-hongkong.aliyuncs.com/1703841554373");
+        }
+        if(null != appUser && (appUser.getStatus() == 2|| appUser.getStatus() == 3)){
+            return ResultUtil.errorLogin("当前账号已被冻结或删除");
+        }
         return ResultUtil.success(appUser);
 
     }
-    @Autowired
-    private IHousingDemandService housingDemandService;
+    public static boolean isToday(Date date) {
+        // 将Date类型转换为LocalDate
+        LocalDate inputDate = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
+        // 获取当前日期
+        LocalDate currentDate = LocalDate.now();
+        // 比较日期是否相等
+        return inputDate.isEqual(currentDate);
+    }
     @Override
-    public ResultUtil<CollectRes> collect() {
-        // 查询发布的求房源信息
-        SearchHousingDemandReq req = new SearchHousingDemandReq();
-        SearchHousingDemandRes searchHousingDemandRes = housingDemandService.searchHousingDemand(req);
+    public ResultUtil<CollectRes> collect(UserInfoQuery query) {
+        AppUser appUser = appUserService.getAppUser();
+        SearchHousingDemandRes searchHousingDemandRes = housingDemandService
+                .searchHousingDemand1(appUser.getId());
+        if(null != appUser && (appUser.getStatus() == 2|| appUser.getStatus() == 3)){
+            return ResultUtil.errorLogin("当前账号已被冻结或删除");
+        }
         List<SearchHousingDemandListRes> list1 = searchHousingDemandRes.getList();
-        List<SearchHousingDemandListRes> collect1 = list1.stream().filter(t -> t.getAppuserId() == appUserService.getAppUser().getId()).
-                collect(Collectors.toList());
-        // 拿到收藏的房源ids
-        List<Integer> ids = new ArrayList<>();
+        for (SearchHousingDemandListRes searchHousingDemandListRes : list1) {
+            if (StringUtils.hasLength(searchHousingDemandListRes.getHouseTypeId())){
+                String[] split = searchHousingDemandListRes.getHouseTypeId().split(",");
+                if (split.length>0){
+                    HouseType houseType = houseTypeService.selectById(split[0]);
+                    if (houseType!=null)searchHousingDemandListRes.setHouseTypeName(houseType.getName());
+
+                }
+            }
+        }
         CollectRes searchIntermediaryRes = new CollectRes();
-        searchIntermediaryRes.setList1(collect1);
-        List<CollectListRes> list = houseResourceService.collect(ids);
-        long count1 = collect1.stream().filter(t -> t.getType() == 1).count();
-        long count = list.stream().filter(t -> t.getType() == 1).count();
-        // 草稿数量
-        searchIntermediaryRes.setDraft(Integer.parseInt(String.valueOf(count))+Integer.parseInt(String.valueOf(count1)));
-        // 上架房源数
-        int size = list.stream().filter(t -> t.getStatus() == 1 && t.getType()==2).collect(Collectors.toList()).size();
-        searchIntermediaryRes.setOn(size);
-        // 下架房源数
-        int size1 = list.stream().filter(t -> t.getStatus() == 0 && t.getType()==2).collect(Collectors.toList()).size();
-        searchIntermediaryRes.setOff(size1);
+        List<CollectListRes> list = houseResourceService.collect(appUserService.getAppUser().getId());
+        for (SearchHousingDemandListRes temp : list1) {
+            // 判断顶上去时间是不是今天
+            CollectListRes collectListRes = new CollectListRes();
+            collectListRes.setSaleAmount(temp.getSaleAmount());
+            collectListRes.setData(1);
+            collectListRes.setAuthStatus(2);
+            BeanUtils.copyProperties(temp,collectListRes);
+            StringBuilder stringBuilder = new StringBuilder("");
+            if (temp.getAddress()!=null){
+                for (String address : temp.getAddress()) {
+                    stringBuilder.append(address+",");
+                }
+                String string = stringBuilder.toString();
+                String substring = string.substring(0, string.length() - 1);
+                collectListRes.setAddress(substring);
+            }
+            list.add(collectListRes);
+        }
         for (CollectListRes collectListRes : list) {
+            // 没有顶过
+            if (collectListRes.getUpTime() == null){
+                collectListRes.setUp(1);
+                continue;
+            }
+            if (isToday(collectListRes.getUpTime())){
+                // 时间相同的话 就不能顶
+                collectListRes.setUp(0);
+            }else{
+                collectListRes.setUp(1);
+            }
+        }
+        List<CollectListRes> collect3 = list.stream().distinct().collect(Collectors.toList());
+        // 房源数据
+        List<CollectListRes> collect1 = collect3.stream().filter(t->t.getData()==2).distinct().collect(Collectors.toList());
+        // 求房源数据
+        List<CollectListRes> collect2 = collect3.stream().filter(t->t.getData()==1).distinct().collect(Collectors.toList());
+        for (CollectListRes collectListRes : collect1) {
             // 查询这个房源的收藏
             int collect = collectionHouseResourceService.selectList(new EntityWrapper<CollectionHouseResource>()
                     .eq("house_resource_id", collectListRes.getId())).size();
             collectListRes.setCollect(collect);
             // 根据区id 查询下级
+            if (collectListRes.getCityId()==null){
+                continue;
+            }
             Region city = regionService.selectById(collectListRes.getCityId());
             Region dis = regionService.selectById(collectListRes.getDistrictId());
             Region region = regionService.selectOne(new EntityWrapper<Region>().eq("parent_id",dis.getId()));
@@ -287,48 +314,287 @@
             }
             collectListRes.setAddress(city.getName()+">"+stringBuilder.toString());
         }
-        searchIntermediaryRes.setList(list);
-        searchIntermediaryRes.setTotal(list.size());
+        for (CollectListRes collectListRes : collect2) {
+            // 查询这个房源的收藏
+            int collect = collectionHousingDemandService.selectList(new EntityWrapper<CollectionHousingDemand>()
+                    .eq("housing_demand_id", collectListRes.getId())).size();
+            collectListRes.setCollect(collect);
+
+        }
+        collect1.addAll(collect2);
+        // 使用 Collections.sort() 方法排序
+        Collections.sort(collect1, Comparator.comparing(CollectListRes::getInsertTime).reversed());
+        List<CollectListRes> testing = testing(collect1.size(), query.getPageNum(), query.getPageSize(), collect1);
+        List<CollectListRes> collect = testing.stream().filter(t -> t.getData() == 2).distinct().collect(Collectors.toList());
+        List<CollectListRes> collectt = testing.stream().filter(t -> t.getData() == 1).distinct().collect(Collectors.toList());
+
+        // 草稿数量
+        long count1 = collect1.stream().filter(t -> t.getType() == 1).count();
+        // 上架数量
+        long count2 = collect1.stream().filter(t -> t.getType() == 2 && t.getStatus()==1).count();
+        // 下架数量
+        long count3 = collect1.stream().filter(t -> t.getType() == 2 && t.getStatus()==0).count();
+        searchIntermediaryRes.setDraft(Integer.parseInt(String.valueOf(count1)));
+        searchIntermediaryRes.setOff(Integer.parseInt(String.valueOf(count3)));
+        searchIntermediaryRes.setOn(Integer.parseInt(String.valueOf(count2)));
+//        @ApiModelProperty("是否有电梯(0=否,1=是)")
+//        private Integer elevator;
+//        @ApiModelProperty("是否有晾晒区(0=否,1=是)")
+//        private Integer dryingArea;
+//        @ApiModelProperty("是否有花园(0=否,1=是)")
+//        private Integer garden;
+//        @ApiModelProperty("是否有车位(0=否,1=是)")
+//        private Integer carport;
+//        @ApiModelProperty("是否有平台(0=否,1=是)")
+//        private Integer balcony;
+//        @ApiModelProperty("是否可养宠物(0=否,1=是)")
+//        private Integer keepPet;
+
+        for (CollectListRes t : testing) {
+            int a =0;
+            // 将时间转化为指定格式
+            // 创建一个日期格式化对象,指定要转换的格式
+            SimpleDateFormat formatter = new SimpleDateFormat("yyyy年MM月dd日");
+            String format = formatter.format(t.getInsertTime());
+            t.setTime(format);
+            StringBuilder temp = new StringBuilder("");
+            if (StringUtils.hasLength(t.getHouseTypeName())){
+                if (a<4){
+                    temp.append(t.getHouseTypeName()+",");
+                    a++;
+                }
+            }
+             if (t.getElevator()!=null&&t.getElevator()==1){
+                 if (a<4) {
+                     temp.append("有电梯,");
+                     a++;
+                 }
+            }
+            if (t.getBalcony()!=null&&t.getBalcony()==1){
+                if (a<4) {
+                    temp.append("有阳台,");
+                    a++;
+                }
+            }
+            if (t.getDryingArea()!=null&&t.getDryingArea()==1){
+                if (a<4) {
+                    temp.append("有天台,");
+                    a++;
+                }
+            }
+            if (t.getGarden()!=null&&t.getGarden()==1){
+                if (a<4) {
+                    temp.append("有花园,");
+                    a++;
+                }
+            }
+             if (t.getCarport()!=null&&t.getCarport()==1){
+                 if (a<4) {
+                     temp.append("有车位,");
+                     a++;
+                 }
+            }
+            if (t.getKeepPet()!=null&&t.getKeepPet()==1){
+                if (a<4) {
+                    temp.append("可养宠物,");
+                    a++;
+                }
+            }
+            String string = temp.toString();
+            if (StringUtils.hasLength(string)){
+                String substring = string.substring(0, string.length() - 1);
+                t.setHead(substring);
+            }else{
+                t.setHead("");
+            }
+        }
+
+        searchIntermediaryRes.setList(testing);
+        searchIntermediaryRes.setTotal(collect1.size());
+        return ResultUtil.success(searchIntermediaryRes);
+    }
+
+    public static List<CollectListRes> testing(long total, long current, long size, List<CollectListRes> str){
+        List<CollectListRes> result = new ArrayList<>();
+        //获取初始化分页结构
+        Page<CollectListRes> page = new Page().getPage(total, size, current - 1);
+        //获取集合下标初始值
+        long startIndex = page.getStartIndex();
+        //获取集合下标结束值
+        long endInddex = 0;
+        if(startIndex + page.getCurrent() >= total || size > total){
+            endInddex = total;
+        }else {
+            endInddex = Math.min(startIndex + page.getSize(), total);
+        }
+        //如果输入的开始查询下标大于集合大小,则查询为空值
+        if(startIndex > total){
+            result = Collections.emptyList();
+        }else{
+            result = str.subList((int)startIndex,(int)endInddex);
+        }
+        return result;
+    }
+    @Override
+    public ResultUtil<CollectRes> release(UserInfoQuery query) {
+        AppUser appUser = appUserService.getAppUser();
+        if(null != appUser && (appUser.getStatus() == 2|| appUser.getStatus() == 3)){
+            return ResultUtil.errorLogin("当前账号已被冻结或删除");
+        }
+        // 房源ids
+        List<Integer> ids = collectionHouseResourceService.selectList(new EntityWrapper<CollectionHouseResource>()
+                .eq("app_user_id", appUser.getId()))
+                .stream().map(CollectionHouseResource::getHouseResourceId).collect(Collectors.toList());
+            List<Integer> collect = houseResourceService.selectList(new EntityWrapper<HouseResource>()
+                    .eq("is_delete", 0)
+                    .eq("status", 1)
+                    .eq("auth_status", 2)
+                    .in("id", ids)).stream().map(HouseResource::getId).collect(Collectors.toList());
+        List<CollectListRes> list = new ArrayList<>();
+        if (collect.size()==0){
+            }else{
+            list = houseResourceService.release(query,collect);
+        }
+
+            List<CollectListRes> collect1 = list.stream().distinct().collect(Collectors.toList());
+        if (ids.size()==0){
+            collect=new ArrayList<>();
+            list = new ArrayList<>();
+            collect1 = new ArrayList<>();
+        }
+        for (CollectListRes collectListRes : collect1) {
+            // 查询房源的收藏量
+            int house_resource_id = collectionHouseResourceService.selectList(new EntityWrapper<CollectionHouseResource>()
+                    .eq("house_resource_id", collectListRes.getId())).size();
+            collectListRes.setCollect(house_resource_id);
+            // 根据区id 查询下级
+            Region city = regionService.selectById(collectListRes.getCityId());
+            StringBuilder stringBuilder = new StringBuilder("");
+            if (city!=null){
+                Region dis = regionService.selectById(collectListRes.getDistrictId());
+                if (dis!=null){
+                    Region region = regionService.selectOne(new EntityWrapper<Region>().eq("parent_id",dis.getId()));
+                    stringBuilder.append(dis.getName());
+                    if (region!=null){
+                        stringBuilder.append("/"+region.getName());
+                        Region region1 = regionService.selectOne(new EntityWrapper<Region>().eq("parent_id",region.getId()));
+                        if (region!=null){
+                            stringBuilder.append(region1.getName());
+                            Region region2 = regionService.selectOne(new EntityWrapper<Region>().eq("parent_id",region1.getId()));
+                            if (region2!=null){
+                                stringBuilder.append("/"+region2.getName());
+                            }
+                        }
+                    }
+                    collectListRes.setAddress(city.getName()+">"+stringBuilder.toString());
+                }
+            }
+        }
+        // 查询收藏的求房源ids
+        List<Integer> demand = collectionHousingDemandService.selectList
+                (new EntityWrapper<CollectionHousingDemand>()
+                        .eq("app_user_id", appUserService.getAppUser().getId()))
+                .stream().map(CollectionHousingDemand::getHousingDemandId)
+                .collect(Collectors.toList());
+        if (demand.size()!=0){
+            SearchHousingDemandRes searchHousingDemandRes = housingDemandService.searchHousingDemand2(demand);
+            List<SearchHousingDemandListRes> list1 = searchHousingDemandRes.getList();
+            for (SearchHousingDemandListRes temp : list1) {
+                if (StringUtils.hasLength(temp.getHouseTypeId())){
+                    String[] split = temp.getHouseTypeId().split(",");
+                    if (split.length>0){
+                        HouseType houseType = houseTypeService.selectById(split[0]);
+                        if (houseType!=null)temp.setHouseTypeName(houseType.getName());
+
+                    }
+                }
+                CollectListRes collectListRes = new CollectListRes();
+                // 求房源的收藏数量
+                int housing_demand_id = collectionHousingDemandService.selectList(new EntityWrapper<CollectionHousingDemand>()
+                        .eq("housing_demand_id", temp.getId())).size();
+                collectListRes.setSaleAmount(temp.getSaleAmount());
+                collectListRes.setData(1);
+
+                BeanUtils.copyProperties(temp,collectListRes);
+                collectListRes.setCollect(housing_demand_id);
+                StringBuilder stringBuilder = new StringBuilder("");
+                if (temp.getAddress()!=null){
+                    for (String address : temp.getAddress()) {
+                        stringBuilder.append(address+",");
+                    }
+                    String string = stringBuilder.toString();
+                    String substring = string.substring(0, string.length() - 1);
+                    collectListRes.setAddress(substring);
+                }
+                if (temp.getRentalDuration()!=null){
+                    Integer rentalDuration = temp.getRentalDuration();
+                    // 计算年数和剩余月数
+                    int years = rentalDuration / 12;
+                    int remainingMonths = rentalDuration % 12;
+                    if (years==0){
+                        collectListRes.setLeaseTime(remainingMonths+"月");
+                    }else{
+                        if (remainingMonths==0){
+                            collectListRes.setLeaseTime(years+"年");
+                        }else{
+                            collectListRes.setLeaseTime(years+"年"+remainingMonths+"月");
+                        }
+                    }
+                }
+                collect1.add(collectListRes);
+            }
+        }
+
+        CollectRes searchIntermediaryRes = new CollectRes();
+        Collections.sort(collect1, Comparator.comparing(CollectListRes::getInsertTime).reversed());
+        List<CollectListRes> testing = testing(collect1.size(), query.getPageNum(), query.getPageSize(), collect1);
+        for (CollectListRes t : testing) {
+            // 将时间转化为指定格式
+            // 创建一个日期格式化对象,指定要转换的格式
+            SimpleDateFormat formatter = new SimpleDateFormat("yyyy年MM月dd日");
+            String format = formatter.format(t.getInsertTime());
+            t.setTime(format);
+            StringBuilder temp = new StringBuilder("");
+            if (StringUtils.hasLength(t.getHouseTypeName())){
+                temp.append(t.getHouseTypeName()+",");
+            }
+            if (t.getElevator()!=null&&t.getElevator()==1){
+                temp.append("有电梯,");
+            }
+            if (t.getBalcony()!=null&&t.getBalcony()==1){
+                temp.append("有阳台,");
+            }
+            if (t.getDryingArea()!=null&&t.getDryingArea()==1){
+                temp.append("有天台,");
+            }
+            if (t.getGarden()!=null&&t.getGarden()==1){
+                temp.append("有花园,");
+            }
+            if (t.getCarport()!=null&&t.getCarport()==1){
+                temp.append("有车位,");
+            }
+
+            if (t.getKeepPet()!=null&&t.getKeepPet()==1){
+                temp.append("可养宠物,");
+            }
+            String string = temp.toString();
+            if (StringUtils.hasLength(string)){
+                String substring = string.substring(0, string.length() - 1);
+                t.setHead(substring);
+            }else{
+                t.setHead("");
+            }
+        }
+
+        searchIntermediaryRes.setList(testing);
+        searchIntermediaryRes.setTotal(collect1.size());
         return ResultUtil.success(searchIntermediaryRes);
     }
 
     @Override
-    public ResultUtil<CollectRes> release(UserInfoQuery query) {
-        query.setPageNum((query.getPageNum() - 1) * query.getPageSize());
-        // 房源ids
-        List<Integer> ids = collectionHouseResourceService.selectList(new EntityWrapper<CollectionHouseResource>()
-                .eq("app_user_id", appUserService.getAppUser().getId()))
-                .stream().map(CollectionHouseResource::getHouseResourceId).collect(Collectors.toList());
-        List<Integer> collect = houseResourceService.selectList(new EntityWrapper<HouseResource>()
-                .eq("is_delete", 0)
-                .eq("status", 1)
-                .eq("auth_status", 2)
-                .in("id", ids)).stream().map(HouseResource::getId).collect(Collectors.toList());
-        List<CollectListRes> list = houseResourceService.release(query,collect);
-        for (CollectListRes collectListRes : list) {
-            // 根据区id 查询下级
-            Region city = regionService.selectById(collectListRes.getCityId());
-            Region dis = regionService.selectById(collectListRes.getDistrictId());
-            Region region = regionService.selectOne(new EntityWrapper<Region>().eq("parent_id",dis.getId()));
-            StringBuilder stringBuilder = new StringBuilder("");
-            stringBuilder.append(dis.getName());
-            if (region!=null){
-                stringBuilder.append("/"+region.getName());
-                Region region1 = regionService.selectOne(new EntityWrapper<Region>().eq("parent_id",region.getId()));
-                if (region!=null){
-                    stringBuilder.append(region1.getName());
-                    Region region2 = regionService.selectOne(new EntityWrapper<Region>().eq("parent_id",region1.getId()));
-                    if (region2!=null){
-                        stringBuilder.append("/"+region2.getName());
-                    }
-                }
-            }
-            collectListRes.setAddress(city.getName()+">"+stringBuilder.toString());
-        }
-        CollectRes searchIntermediaryRes = new CollectRes();
-        searchIntermediaryRes.setList(list);
-        searchIntermediaryRes.setTotal(list.size());
-        return ResultUtil.success();
+    public SearchIntermediaryListRes searchIntermediaryInfo(Integer id) {
+        return this.baseMapper.searchIntermediaryInfo(id);
+
     }
 
 
@@ -337,7 +603,7 @@
      * @param openid    微信openid
      * @param phone     手机号
      */
-    private void addNewAppUser(String openid, String phone){
+    private AppUser addNewAppUser(String openid, String phone){
         AppUser appUser = new AppUser();
         appUser.setCode(UUIDUtil.getNumberRandom(16));
         appUser.setUserType(1);
@@ -345,8 +611,11 @@
         appUser.setWechatOpenid(openid);
         appUser.setAuditStatus(2);
         appUser.setStatus(1);
+        appUser.setAuth(0);
         appUser.setInsertTime(new Date());
+        appUser.setProfilePhoto("https://bizuphk.oss-cn-hongkong.aliyuncs.com/1703841554373");
         this.insert(appUser);
+        return appUser;
     }
 
 
@@ -358,8 +627,8 @@
     private void addTokenToRedis(String token, Integer id){
         String key = token;
         int length = token.length();
-        if(length > 16){
-            key = token.substring(4, 12);
+        if(length > 32){
+            key = token.substring(token.length() - 32);
         }
         //30天有效期
         redisUtil.setStrValue(key, id.toString(), 2592000);
@@ -374,8 +643,8 @@
     private Integer getAppUserIdFromToken(String token){
         String key = token;
         int length = token.length();
-        if(length > 16){
-            key = token.substring(4, 12);
+        if(length > 32){
+            key = token.substring(token.length() - 32);
         }
         String value = redisUtil.getValue(key);
         if(ToolUtil.isEmpty(value)){

--
Gitblit v1.7.1