From 640d1ebf2b738440ab16f8e8954bfeed1472a3b3 Mon Sep 17 00:00:00 2001 From: 44323 <443237572@qq.com> Date: 星期五, 29 十二月 2023 17:59:26 +0800 Subject: [PATCH] 接口所有代码 --- guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/AppUserServiceImpl.java | 275 ++++++++++++++++++++++++++++++++++-------------------- 1 files changed, 173 insertions(+), 102 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 cc6b676..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 @@ -26,6 +26,7 @@ import javax.servlet.http.HttpServletRequest; import java.math.BigDecimal; +import java.text.SimpleDateFormat; import java.time.LocalDate; import java.time.ZoneId; import java.util.*; @@ -54,9 +55,8 @@ private CollectionHouseResourceServiceImpl collectionHouseResourceService; @Autowired private ICollectionHousingDemandService collectionHousingDemandService; - - - + @Autowired + private IHouseTypeService houseTypeService; /** * 通过token获取用户信息 @@ -78,11 +78,6 @@ return null; } - - - - - /** * 小程序登录 * @return @@ -97,40 +92,25 @@ 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)); - if(null != appUser && appUser.getStatus() == 2){ - return ResultUtil.error("账号冻结"); + .eq("wechat_openid", openid) + .eq("phone",phone1) + .ne("status",3)); + if(null != appUser && (appUser.getStatus() == 2|| appUser.getStatus() == 3)){ + return ResultUtil.errorLogin("当前账号已被冻结或删除"); } AppletLoginRes appletLoginRes = new AppletLoginRes(); - // 当前微信号没有注册过 - if(null == appUser){ - 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("status", 1)); - JSONObject jsonObject = JSONObject.parseObject(phone); - String phone1 = jsonObject.getString("phoneNumber"); - System.err.println("看看json"); - System.err.println(jsonObject); - System.err.println(phone1); - //注册新账号 - appUser = addNewAppUser(openid, phone1); - }else{ - 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.setWechatOpenid(openid); - appUser.setPhone(phone1); - this.updateById(appUser); - } + if(null == appUser){ + //注册新账号 + appUser = addNewAppUser(openid, phone1); + } //生成token String token = JwtTokenUtil.generateToken(appUser.getPhone()); - System.err.println("token1111--->" + token); appletLoginRes.setState(appUser.getAuth()); appletLoginRes.setToken(token); @@ -223,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; } @@ -232,6 +213,12 @@ 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); } @@ -245,9 +232,23 @@ } @Override public ResultUtil<CollectRes> collect(UserInfoQuery query) { + AppUser appUser = appUserService.getAppUser(); SearchHousingDemandRes searchHousingDemandRes = housingDemandService - .searchHousingDemand1(appUserService.getAppUser().getId()); + .searchHousingDemand1(appUser.getId()); + if(null != appUser && (appUser.getStatus() == 2|| appUser.getStatus() == 3)){ + return ResultUtil.errorLogin("当前账号已被冻结或删除"); + } List<SearchHousingDemandListRes> list1 = searchHousingDemandRes.getList(); + 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(); List<CollectListRes> list = houseResourceService.collect(appUserService.getAppUser().getId()); for (SearchHousingDemandListRes temp : list1) { @@ -255,6 +256,7 @@ 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){ @@ -320,22 +322,21 @@ } 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 count = collect.stream().filter(t -> t.getType() == 1).count(); - long count1 = collectt.stream().filter(t -> t.getType() == 1).count(); // 草稿数量 - searchIntermediaryRes.setDraft(Integer.parseInt(String.valueOf(count))+Integer.parseInt(String.valueOf(count1))); - // 上架房源数 - int size = collect.stream().filter(t -> t.getStatus() == 1 && t.getType()==2).collect(Collectors.toList()).size(); - int size2 = collectt.stream().filter(t -> t.getStatus() == 1 && t.getType()==2).collect(Collectors.toList()).size(); - searchIntermediaryRes.setOn(size+size2); - // 下架房源数 - int size1 = collect.stream().filter(t -> t.getStatus() == 0 && t.getType()==2).collect(Collectors.toList()).size(); - int size3 = collectt.stream().filter(t -> t.getStatus() == 0 && t.getType()==2).collect(Collectors.toList()).size(); - searchIntermediaryRes.setOff(size1+size3); + 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=是)") @@ -350,36 +351,54 @@ // 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 (t.getElevator()==null){ - temp.append("电梯,"); - }else if (t.getElevator()==1){ - temp.append("电梯,"); + if (StringUtils.hasLength(t.getHouseTypeName())){ + if (a<4){ + temp.append(t.getHouseTypeName()+","); + a++; + } } - if (t.getDryingArea()==null){ - temp.append("晾晒区,"); - }else if (t.getDryingArea()==1){ - temp.append("晾晒区,"); + if (t.getElevator()!=null&&t.getElevator()==1){ + if (a<4) { + temp.append("有电梯,"); + a++; + } } - if (t.getGarden()==null){ - temp.append("花园,"); - }else if (t.getGarden()==1){ - temp.append("花园,"); + if (t.getBalcony()!=null&&t.getBalcony()==1){ + if (a<4) { + temp.append("有阳台,"); + a++; + } } - if (t.getCarport()==null){ - temp.append("车位,"); - }else if (t.getCarport()==1){ - temp.append("车位,"); + if (t.getDryingArea()!=null&&t.getDryingArea()==1){ + if (a<4) { + temp.append("有天台,"); + a++; + } } - if (t.getBalcony()==null){ - temp.append("平台,"); - }else if (t.getBalcony()==1){ - temp.append("平台,"); + if (t.getGarden()!=null&&t.getGarden()==1){ + if (a<4) { + temp.append("有花园,"); + a++; + } } - if (t.getKeepPet()==null){ - temp.append("宠物,"); - }else if (t.getKeepPet()==1){ - temp.append("宠物,"); + 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)){ @@ -388,15 +407,12 @@ }else{ t.setHead(""); } - } + searchIntermediaryRes.setList(testing); - - searchIntermediaryRes.setTotal(testing.size()); - + 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<>(); @@ -406,22 +422,10 @@ long startIndex = page.getStartIndex(); //获取集合下标结束值 long endInddex = 0; - /** - * 如果初始值startIndex(size * current)超过总记录数 或者 入参size(一页显示多少条)大于总记录树, - * 则下标结束值均设置为集合大小 - */ if(startIndex + page.getCurrent() >= total || size > total){ endInddex = total; }else { - /**当最后一页,开始下标加上要取值的size 大于总条数,则最终索引改为集合大小-1=》为 - *集合的最后下标值,防止下标溢出 - **/ - if(total < startIndex + page.getSize()){ - endInddex = total - 1 ; - }else { - //否则为startIndex(size * current 从哪里开始取)加上一页显示多少条得到结束值 - endInddex = startIndex + page.getSize(); - } + endInddex = Math.min(startIndex + page.getSize(), total); } //如果输入的开始查询下标大于集合大小,则查询为空值 if(startIndex > total){ @@ -429,19 +433,17 @@ }else{ result = str.subList((int)startIndex,(int)endInddex); } - /** - * 此处返回结果可以改为Page<T> T为对应业务的实体类型,最终把分页结果再塞入page的records再返回则得到与 - * mybatisplus一样的结构 - * page.setRecords(list); - * return page; - */ 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", appUserService.getAppUser().getId())) + .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) @@ -461,6 +463,10 @@ 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(""); @@ -494,10 +500,23 @@ 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()) { @@ -507,16 +526,68 @@ 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(testing.size()); + searchIntermediaryRes.setTotal(collect1.size()); return ResultUtil.success(searchIntermediaryRes); } @@ -542,6 +613,7 @@ 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; } @@ -569,7 +641,6 @@ * @return */ private Integer getAppUserIdFromToken(String token){ - System.err.println("token--->" + token); String key = token; int length = token.length(); if(length > 32){ -- Gitblit v1.7.1