| | |
| | | import com.alipay.api.internal.util.codec.Base64; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.service.impl.ServiceImpl; |
| | | import com.mongodb.client.result.UpdateResult; |
| | | import com.stylefeng.guns.core.util.ToolUtil; |
| | | import com.stylefeng.guns.modular.file.OSSService; |
| | | import com.stylefeng.guns.modular.system.dao.HouseResourceMapper; |
| | |
| | | import com.stylefeng.guns.modular.system.warpper.req.SearchHouseResourceReq; |
| | | import com.stylefeng.guns.modular.system.warpper.req.UserInfoQuery; |
| | | import com.stylefeng.guns.modular.system.warpper.res.*; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.apache.http.entity.ContentType; |
| | | import org.dom4j.Document; |
| | | import org.dom4j.Element; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | |
| | | import org.springframework.data.geo.Metrics; |
| | | import org.springframework.data.geo.Point; |
| | | import org.springframework.data.mongodb.core.MongoTemplate; |
| | | import org.springframework.data.mongodb.core.geo.GeoJsonPoint; |
| | | import org.springframework.data.mongodb.core.query.Criteria; |
| | | import org.springframework.data.mongodb.core.query.CriteriaDefinition; |
| | | import org.springframework.data.mongodb.core.query.Query; |
| | | import org.springframework.data.mongodb.core.query.Update; |
| | | import org.springframework.http.*; |
| | | import org.springframework.mock.web.MockMultipartFile; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | private WxAppletTools wxAppletTools; |
| | | @Autowired |
| | | private RestTemplate restTemplate; |
| | | |
| | | @Autowired |
| | | private IUserService userService; |
| | | @Autowired |
| | | private OSSService ossService; |
| | | @Value("${wx.appletsAppid}") |
| | | private String wxAppletsAppid; |
| | | |
| | | @Value("${wx.appletsAppSecret}") |
| | | private String wxAppletsAppSecret; |
| | | /** |
| | | * 生成小程序码地址 |
| | | */ |
| | | public static final String CREATE_CODE_URL = "https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=ACCESS_TOKEN"; |
| | | // 生成小程序码 |
| | | |
| | | public String generateMiniProgramCode(String outputFilePath) throws IOException { |
| | | // 获取access_token |
| | | String accessToken = wxAppletTools.getAccessToken(); |
| | | // 替换CREATE_CODE_URL |
| | | String uri = CREATE_CODE_URL.replace("ACCESS_TOKEN", accessToken); |
| | | // 跳转到的小程序页面路径 |
| | | String pagePath = "pages/index/index"; |
| | | URL url = new URL(uri); |
| | | HttpURLConnection connection = (HttpURLConnection) url.openConnection(); |
| | | // 设置请求方法 |
| | | connection.setRequestMethod("POST"); |
| | | connection.setDoOutput(true); |
| | | // 构建请求参数 |
| | | String params = "path=" + URLEncoder.encode(pagePath, "UTF-8"); |
| | | // 获取输出流 |
| | | try (OutputStream outputStream = connection.getOutputStream()) { |
| | | outputStream.write(params.getBytes()); |
| | | } |
| | | // 获取输入流 |
| | | try (InputStream inputStream = connection.getInputStream(); |
| | | FileOutputStream outputStream = new FileOutputStream(outputFilePath)) { |
| | | // 将返回的图片数据写入文件 |
| | | byte[] buffer = new byte[1024]; |
| | | int bytesRead; |
| | | while ((bytesRead = inputStream.read(buffer)) != -1) { |
| | | outputStream.write(buffer, 0, bytesRead); |
| | | } |
| | | ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(buffer); |
| | | MultipartFile file = new MockMultipartFile(ContentType.APPLICATION_OCTET_STREAM.toString(), byteArrayInputStream); |
| | | return ossService.uploadFile(file); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取房源列表 |
| | | * @param req |
| | |
| | | public SearchHouseResourceRes searchHouseResource(SearchHouseResourceReq req) { |
| | | req.setPageNum((req.getPageNum() - 1) * req.getPageSize()); |
| | | //租房处理推荐和记录历史搜索数据 |
| | | if(req.getType() == 1){ |
| | | fillSearchHistory(req); |
| | | } |
| | | fillSearchHistory(req); |
| | | //区域 |
| | | List<Integer> districtIds = new ArrayList<>(); |
| | | List<Integer> cityIds = new ArrayList<>(); |
| | | if (req.getDataType()!=null && req.getDataType()==1 && req.getUserType()==5 && req.getDistrict()==null && req.getArea()==null){ |
| | | // 如果用户有历史 并且在首页列表的时候 看他有没有历史搜索 |
| | | if (appUserService.getAppUser()!=null){ |
| | | SearchHistoryCondition app_user_id = searchHistoryConditionService.selectOne(new EntityWrapper<SearchHistoryCondition>() |
| | | .eq("app_user_id", appUserService.getAppUser().getId())); |
| | | if (app_user_id!=null){ |
| | | if(StringUtils.hasLength(app_user_id.getDistrict()) ){ |
| | | districtIds.add(Integer.valueOf(app_user_id.getDistrict())); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | if (req.getDistrict() != null &&(!req.getDistrict().equals("")) ){ |
| | | // 一级id |
| | | Integer integer = Integer.valueOf(req.getDistrict()); |
| | |
| | | cityIds.add(Integer.valueOf(s)); |
| | | } |
| | | } |
| | | }else if (StringUtils.hasLength(req.getArea())){ |
| | | String[] split = req.getArea().split(","); |
| | | for (String s : split) { |
| | | cityIds.add(Integer.valueOf(s)); |
| | | } |
| | | // 根据用户历史搜索 推荐对应的区域 |
| | | } |
| | | // if(StringUtils.hasLength(req.getDistrict())){ |
| | | // cityIds = new ArrayList<>(); |
| | |
| | | saleAmountStart = Double.valueOf(split[0]); |
| | | saleAmountEnd = Double.valueOf(split[1]); |
| | | } |
| | | |
| | | |
| | | } |
| | | //户型 |
| | | List<String> houseModels = null; |
| | |
| | | houseTypeIds.add(Integer.valueOf(s)); |
| | | } |
| | | } |
| | | |
| | | SearchHouseResourceRes searchHouseResource = new SearchHouseResourceRes(); |
| | | List<SearchHouseResourceListRes> searchHouseResourceListRes = this.baseMapper.searchHouseResource(req, cityIds, districtIds, saleAmountStart, saleAmountEnd, houseModels, houseTypeIds); |
| | | |
| | | |
| | | // 如果有根据用户历史来搜索必看 如果没有搜索出数据 那么查询所有必看 |
| | | if (req.getDataType()!=null&&req.getDataType()==1 && (!StringUtils.hasLength(req.getDistrict())) |
| | | && searchHouseResourceListRes!=null&&searchHouseResourceListRes.size()==0){ |
| | | cityIds=null; |
| | | districtIds=null; |
| | | searchHouseResourceListRes = this.baseMapper.searchHouseResource(req, cityIds, districtIds, saleAmountStart, saleAmountEnd, houseModels, houseTypeIds); |
| | | } |
| | | for (SearchHouseResourceListRes t : searchHouseResourceListRes) { |
| | | if (t.getIsManage()!=null && t.getIsManage() == 1){ |
| | | // 后台添加设置为中介房源 |
| | | t.setHouseResource(3); |
| | | } |
| | | } |
| | | if (req.getUserType()==5){ |
| | | // 中介房源 |
| | | List<SearchHouseResourceListRes> collect = searchHouseResourceListRes.stream() |
| | | .filter(t -> t.getHouseResource() == 3) |
| | | .sorted(Comparator.comparing(SearchHouseResourceListRes::getInsertTime).reversed()) |
| | | .collect(Collectors.toList()); |
| | | |
| | | // 个人房源 |
| | | List<SearchHouseResourceListRes> collect1 = searchHouseResourceListRes.stream() |
| | | .filter(t -> t.getHouseResource() == 2) |
| | | .sorted(Comparator.comparing(SearchHouseResourceListRes::getInsertTime).reversed()) |
| | | .collect(Collectors.toList()); |
| | | searchHouseResourceListRes = collect; |
| | | searchHouseResourceListRes.addAll(collect1); |
| | | }else{ |
| | | List<SearchHouseResourceListRes> collect = searchHouseResourceListRes.stream() |
| | | .sorted(Comparator.comparing(SearchHouseResourceListRes::getInsertTime).reversed()) |
| | | .collect(Collectors.toList()); |
| | | searchHouseResourceListRes = collect; |
| | | } |
| | | |
| | | searchHouseResource.setList(searchHouseResourceListRes); |
| | | searchHouseResource.setTotal(searchHouseResourceListRes.size()); |
| | | List<SearchHouseResourceListRes> searchHouseResourceListRes1 = this.baseMapper.searchHouseResource1(req, cityIds, districtIds, saleAmountStart, saleAmountEnd, houseModels, houseTypeIds); |
| | | searchHouseResource.setTotal(searchHouseResourceListRes1.size()); |
| | | return searchHouseResource; |
| | | } |
| | | |
| | |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); |
| | | AppUser appUser = appUserService.getAppUser(); |
| | | HouseResource houseResource = this.selectById(id); |
| | | SearchHouseResourceReq req = new SearchHouseResourceReq(); |
| | | if (houseResource.getDistrictId()!=null)req.setDistrict(houseResource.getCityId().toString()); |
| | | if (houseResource.getSaleAmount()!=null)req.setSaleAmount(houseResource.getSaleAmount().toString()); |
| | | req.setHouseModel(houseResource.getHouseModel()); |
| | | req.setElevator(houseResource.getElevator()); |
| | | if (houseResource.getHouseTypeId()!=null)req.setHouseTypeId(houseResource.getHouseTypeId().toString()); |
| | | fillSearchHistory(req); |
| | | HouseResourceInfoRes houseResourceInfoRes = new HouseResourceInfoRes(); |
| | | houseResourceInfoRes.setAge(houseResource.getAge()); |
| | | houseResourceInfoRes.setDataType(houseResource.getDataType()); |
| | | houseResourceInfoRes.setId(id); |
| | | houseResourceInfoRes.setBuildingOrientation(houseResource.getBuildingOrientation()); |
| | |
| | | if (houseType!=null)houseResourceInfoRes.setHouseType(houseType.getName()); |
| | | houseResourceInfoRes.setFloor(houseResource.getFloor()); |
| | | houseResourceInfoRes.setElevator(houseResource.getElevator()); |
| | | houseResourceInfoRes.setDryingArea(houseResource.getDryingArea()); |
| | | if (houseResource.getBalcony()!=null&&houseResource.getBalcony()==1)houseResourceInfoRes.setDryingAreas("阳台"); |
| | | if (houseResource.getDryingArea()!=null&&houseResource.getDryingArea()==1)houseResourceInfoRes.setDryingAreas("天台"); |
| | | if (houseResource.getAir()!=null&&houseResource.getAir()==1)houseResourceInfoRes.setDryingAreas("无"); |
| | | houseResourceInfoRes.setHouseArea(houseResource.getHouseArea()); |
| | | houseResourceInfoRes.setKeepPet(houseResource.getKeepPet()); |
| | | Region region = regionService.selectById(houseResource.getDistrictId()); |
| | |
| | | houseResourceInfoRes.setNickname(appUser1.getNickname()); |
| | | houseResourceInfoRes.setUserType(appUser1.getUserType()); |
| | | houseResourceInfoRes.setInsertTime(sdf.format(houseResource.getInsertTime())); |
| | | // 后台添加的 |
| | | if (houseResource.getIsManage()!=null && houseResource.getIsManage()==1){ |
| | | User user = userService.selectById(houseResource.getInsertUserId()); |
| | | if (user!=null){ |
| | | houseResourceInfoRes.setNickname(user.getName()); |
| | | houseResourceInfoRes.setProfilePhoto(user.getAvatar()); |
| | | houseResourceInfoRes.setUserType(3); |
| | | } |
| | | } |
| | | if (houseResource.getUpdateTime()!=null){ |
| | | houseResourceInfoRes.setUpdateTime(sdf.format(houseResource.getUpdateTime())); |
| | | } |
| | |
| | | addViewsNumber(houseResource); |
| | | return houseResourceInfoRes; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 添加访问次数记录 |
| | |
| | | Double x = Double.valueOf(houseResource.getLongitude()); |
| | | Double y = Double.valueOf(houseResource.getLatitude()); |
| | | Point point = new Point(x, y); |
| | | Circle circle = new Circle(point, new Distance(100000, Metrics.KILOMETERS)); |
| | | Circle circle = new Circle(point, new Distance(5, Metrics.KILOMETERS)); |
| | | Query query = Query.query(Criteria.where("geoJsonPoint").withinSphere(circle)); |
| | | List<PointLocation> pointLocations = mongoTemplate.find(query, PointLocation.class); |
| | | List<Integer> ids = pointLocations.stream().map(PointLocation::getHouseId).collect(Collectors.toList()); |
| | | if (ids.size()!= 0){ |
| | | List<HouseResource> houseResources = this.selectBatchIds(ids); |
| | | List<SearchHouseResourceListRes> list = new ArrayList<>(); |
| | | List<HouseResource> collect = houseResources.stream() |
| | | .filter(t -> !t.getId().equals(id) |
| | | && t.getAuthStatus() == 2 && t.getType() == 2 |
| | | && t.getStatus() == 1 && t.getIsDelete() == 0 && t.getDataType() == houseResource.getDataType()) |
| | | .collect(Collectors.toList()); |
| | | List<SearchHouseResourceListRes> list = new ArrayList<>(); |
| | | //遍历解析出返回数据 |
| | | for (HouseResource resource : houseResources) { |
| | | for (HouseResource resource : collect) { |
| | | SearchHouseResourceListRes searchHouseResourceListRes = new SearchHouseResourceListRes(); |
| | | searchHouseResourceListRes.setId(resource.getId()); |
| | | AppUser appUser = appUserService.selectById(resource.getAppUserId()); |
| | | searchHouseResourceListRes.setHouseResource(appUser.getUserType()); |
| | | searchHouseResourceListRes.setImgUrl(resource.getHousePhoto().split(",")[0]); |
| | | if(StringUtils.hasLength(resource.getHousePhoto())){ |
| | | searchHouseResourceListRes.setImgUrl(resource.getHousePhoto().split(",")[0]); |
| | | } |
| | | searchHouseResourceListRes.setTitle(resource.getTitle()); |
| | | searchHouseResourceListRes.setHouseArea(resource.getHouseArea()); |
| | | searchHouseResourceListRes.setHouseModel(resource.getHouseModel()); |
| | | Region region = regionService.selectById(houseResource.getDistrictId()); |
| | | Region region1 = regionService.selectById(houseResource.getCityId()); |
| | | searchHouseResourceListRes.setAddress(region1.getName() + " > " + region.getName() + "/" + houseResource.getHouseAddress()); |
| | | if (region!=null && region1!=null){ |
| | | searchHouseResourceListRes.setAddress(region1.getName() + " > " + region.getName() + "/" + houseResource.getHouseAddress()); |
| | | } |
| | | searchHouseResourceListRes.setSaleAmount(resource.getSaleAmount().doubleValue()); |
| | | searchHouseResourceListRes.setElevator(resource.getElevator()); |
| | | searchHouseResourceListRes.setDryingArea(resource.getDryingArea()); |
| | |
| | | @Override |
| | | public ContactInformationRes getContactInformation(Integer id) { |
| | | HouseResource houseResource = this.selectById(id); |
| | | AppUser appUser = appUserService.selectById(houseResource.getAppUserId()); |
| | | ContactInformationRes contactInformationRes = new ContactInformationRes(); |
| | | contactInformationRes.setWhatsApp(appUser.getWatchApp()); |
| | | contactInformationRes.setPhone(appUser.getPhone()); |
| | | contactInformationRes.setWatchApp(houseResource.getWatchApp()); |
| | | contactInformationRes.setPhone(houseResource.getPhone()); |
| | | contactInformationRes.setWechatQrCode(houseResource.getWechatQRCode()); |
| | | return contactInformationRes; |
| | | } |
| | | |
| | |
| | | .eq("status", 1)); |
| | | if (appUser!=null){ |
| | | if (req.getId()==null){ |
| | | if (req.getType()!=1){ |
| | | if (appUser.getAuditStatus()!=2){ |
| | | 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); |
| | | if (appUser.getAuth()!=2){ |
| | | // 未认证 只能能发布三条房源信息 |
| | | List<HouseResource> houseResources = this.selectList(new EntityWrapper<HouseResource>() |
| | | .eq("app_user_id", appUserId) |
| | | .eq("is_delete", 1) |
| | | .eq("status", 1) |
| | | .eq("is_delete", 0) |
| | | .eq("type", 2) |
| | | ); |
| | | if (houseResources.size()>=3){ |
| | | return ResultUtil.error("中介账号未认证,只能同时上架3条房源信息"); |
| | | } |
| | | }else if (appUser.getAuditStatus()==2){ |
| | | // 已经认证 只能能发布20条房源信息 |
| | | List<HouseResource> houseResources = this.selectList(new EntityWrapper<HouseResource>() |
| | | .eq("app_user_id", appUserId) |
| | | .eq("is_delete", 1) |
| | | .eq("status", 1) |
| | | ); |
| | | if (houseResources.size()>=20){ |
| | | return ResultUtil.error("当前中介账号只能同时上架20条房源信息"); |
| | | return ResultUtil.error("未认证中介或认证未通过,只能同时发布3条房源信息"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | HouseResource houseResource = new HouseResource(); |
| | | |
| | | houseResource.setPlatform(req.getPlatform()); |
| | | BeanUtils.copyProperties(req,houseResource); |
| | | houseResource.setType(req.getType()); |
| | | if (StringUtils.hasLength(req.getHousePhoto())){ |
| | | houseResource.setHousePhoto(req.getHousePhoto()); |
| | | }else{ |
| | | houseResource.setHousePhoto(""); |
| | | } |
| | | houseResource.setInsertTime(new Date()); |
| | | houseResource.setGoodHouse(0); |
| | | houseResource.setAge(req.getAge()); |
| | | houseResource.setIsDelete(0); |
| | | houseResource.setInsertUserId(appUserId); |
| | | houseResource.setViewsNumber(0); |
| | | houseResource.setUpdateTime(new Date()); |
| | | // todo 修改回审核和上下架状态 |
| | | houseResource.setStatus(1); |
| | | houseResource.setHeadImg(req.getHeadImg()); |
| | | houseResource.setDataType(req.getDataType()); |
| | | |
| | | houseResource.setAuthStatus(1); |
| | | houseResource.setAuthStatus(2); |
| | | houseResource.setLeaseTime(req.getTime()); |
| | | houseResource.setAppUserId(appUserService.getAppUser().getId()); |
| | | houseResource.setAppUserId(appUserId); |
| | | houseResource.setFirmHouse(req.getFirmHouse()); |
| | | if(req.getRentalMoney()!=null){ |
| | | // 如果勾选了同时可租 |
| | | houseResource.setKeepPet(null); |
| | | houseResource.setLeaseTime(null); |
| | | houseResource.setStartTime(""); |
| | | } |
| | | if (StringUtils.hasLength(req.getTime())){ |
| | | if (req.getTime().contains("年")){ |
| | | houseResource.setRentalDuration(2); |
| | |
| | | } |
| | | } |
| | | if (req.getType()==2){ |
| | | 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("path", "pages/home/home"); |
| | | // param.put("page", "pages/index/index"); // 路径 如果没有默认跳转到首页面微信小程序发布后才可以使用不能添加参数 |
| | | 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); |
| | | houseResource.setQrCode(imgUrl); |
| | | 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; |
| | | } |
| | | } |
| | | this.baseMapper.insert(houseResource); |
| | | }else{ |
| | | if (req.getId()==null){ |
| | | houseResource.setAuthTime(new Date()); |
| | | houseResource.setAuthStatus(2); |
| | | this.baseMapper.insert(houseResource); |
| | | }else{ |
| | | houseResource.setAuthTime(new Date()); |
| | | houseResource.setAuthStatus(2); |
| | | this.baseMapper.updateById(houseResource); |
| | | } |
| | | }else{ |
| | | if (req.getId()==null){ |
| | | houseResource.setAuthTime(new Date()); |
| | | houseResource.setAuthStatus(2); |
| | | this.baseMapper.insert(houseResource); |
| | | }else{ |
| | | houseResource.setAuthTime(new Date()); |
| | | houseResource.setAuthStatus(2); |
| | | this.baseMapper.updateById(houseResource); |
| | | } |
| | | } |
| | | HouseResource houseResource2 = new HouseResource(); |
| | | if(req.getRentalMoney()!=null){ |
| | | BeanUtils.copyProperties(houseResource,houseResource2); |
| | | houseResource2.setDataType(1); |
| | | houseResource2.setId(null); |
| | | houseResource2.setLeaseTime(req.getTime()); |
| | | houseResource2.setKeepPet(req.getKeepPet()); |
| | | houseResource2.setStartTime(req.getStartTime()); |
| | | this.baseMapper.insert(houseResource2); |
| | | if (req.getType()==2){ |
| | | getQRCode(houseResource2); |
| | | } |
| | | |
| | | } |
| | | if (req.getType()==2 && req.getId()==null){ |
| | | if(req.getRentalMoney()!=null && houseResource2.getId()!=null){ |
| | | PointLocation pointLocation = new PointLocation(); |
| | | GeoJsonPoint geoJsonPoint = new GeoJsonPoint(Double.valueOf(req.getLongitude()),Double.valueOf(req.getLatitude())); |
| | | pointLocation.setGeoJsonPoint(geoJsonPoint); |
| | | pointLocation.setHouseId(houseResource2.getId()); |
| | | mongoTemplate.insert(pointLocation); |
| | | houseResource2.setCode(pointLocation.getId()); |
| | | houseResource2.setAuthStatus(2); |
| | | houseResource2.setAuthTime(new Date()); |
| | | this.baseMapper.updateById(houseResource2); |
| | | } |
| | | |
| | | PointLocation pointLocation = new PointLocation(); |
| | | GeoJsonPoint geoJsonPoint = new GeoJsonPoint(Double.valueOf(req.getLongitude()),Double.valueOf(req.getLatitude())); |
| | | pointLocation.setGeoJsonPoint(geoJsonPoint); |
| | | pointLocation.setHouseId(houseResource.getId()); |
| | | mongoTemplate.insert(pointLocation); |
| | | houseResource.setCode(pointLocation.getId()); |
| | | houseResource.setAuthStatus(2); |
| | | houseResource.setAuthTime(new Date()); |
| | | this.baseMapper.updateById(houseResource); |
| | | getQRCode(houseResource); |
| | | } |
| | | if (req.getType()==2 && req.getId()!=null){ |
| | | if(req.getRentalMoney()!=null && houseResource2.getId()!=null){ |
| | | PointLocation pointLocation = new PointLocation(); |
| | | GeoJsonPoint geoJsonPoint = new GeoJsonPoint(Double.valueOf(req.getLongitude()),Double.valueOf(req.getLatitude())); |
| | | pointLocation.setGeoJsonPoint(geoJsonPoint); |
| | | pointLocation.setHouseId(houseResource2.getId()); |
| | | mongoTemplate.insert(pointLocation); |
| | | houseResource2.setCode(pointLocation.getId()); |
| | | houseResource2.setAuthStatus(2); |
| | | houseResource2.setAuthTime(new Date()); |
| | | this.baseMapper.updateById(houseResource2); |
| | | } |
| | | HouseResource houseResource1 = this.baseMapper.selectById(req.getId()); |
| | | if (!StringUtils.hasLength(houseResource1.getCode())){ |
| | | PointLocation pointLocation = new PointLocation(); |
| | | GeoJsonPoint geoJsonPoint = new GeoJsonPoint(Double.valueOf(req.getLongitude()),Double.valueOf(req.getLatitude())); |
| | | pointLocation.setGeoJsonPoint(geoJsonPoint); |
| | | pointLocation.setHouseId(req.getId()); |
| | | mongoTemplate.insert(pointLocation); |
| | | houseResource1.setCode(pointLocation.getId()); |
| | | houseResource1.setAuthStatus(2); |
| | | this.baseMapper.updateById(houseResource1); |
| | | } |
| | | Query query = Query.query(Criteria.where("_id").is(houseResource1.getCode())); |
| | | PointLocation pointLocation = new PointLocation(); |
| | | pointLocation.setId(houseResource1.getCode()); |
| | | pointLocation.setHouseId(houseResource.getId()); |
| | | GeoJsonPoint geoJsonPoint = new GeoJsonPoint(Double.valueOf(req.getLongitude()),Double.valueOf(req.getLatitude())); |
| | | pointLocation.setGeoJsonPoint(geoJsonPoint); |
| | | org.bson.Document document = (org.bson.Document)mongoTemplate.getConverter() .convertToMongoType(pointLocation); |
| | | Update update = Update.fromDocument (document); |
| | | UpdateResult updateResult = mongoTemplate.updateFirst(query, update, PointLocation.class); |
| | | System.err.println(updateResult.getModifiedCount()); |
| | | } |
| | | |
| | | return ResultUtil.success(); |
| | | } |
| | | return ResultUtil.success(); |
| | | } |
| | | |
| | | public void getQRCode(HouseResource houseResource) { |
| | | InputStream inputStream = null; |
| | | OutputStream outputStream = null; |
| | | String accessToken = wxAppletTools.getAccessToken(); |
| | | try { |
| | | String url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" + accessToken; |
| | | Map<String, Object> param = new HashMap<>(); |
| | | param.put("scene","id="+houseResource.getId()); |
| | | param.put("page", "pageA/houseDetail"); |
| | | 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 |
| | | String s = ossService.uploadFile2OSS(inputStream, objectName); |
| | | //获取文件的URl地址 |
| | | String imgUrl = ossService.getImgUrl(objectName); |
| | | houseResource.setQrCode(imgUrl); |
| | | this.baseMapper.updateById(houseResource); |
| | | 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(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public ResultUtil confirm(Integer userType) { |
| | | AppUser appUser = appUserService.getAppUser(); |
| | | if (userType==2 && appUser.getUserType()==2){ |
| | | |
| | | }else{ |
| | | appUser.setChangeTime(new Date()); |
| | | } |
| | | appUser.setUserType(userType); |
| | | appUserService.updateById(appUser); |
| | | |
| | | return ResultUtil.success(); |
| | | } |
| | | |
| | |
| | | // 最多只能发布三条房源信息 |
| | | int size = this.baseMapper.selectList(new EntityWrapper<HouseResource>() |
| | | .eq("app_user_id", appUser.getId()) |
| | | .eq("is_delete", 1) |
| | | .eq("is_delete", 0) |
| | | .eq("type",2) |
| | | ).size(); |
| | | if (3-size<0)size=0; |
| | | if (3-size<0){ |
| | | return ResultUtil.success(0); |
| | | } |
| | | return ResultUtil.success(3-size); |
| | | } |
| | | if (appUser.getUserType()==3){ |
| | | // 如果是中介 判断他是否认证成功 |
| | | if (appUser.getAuditStatus()==2){ |
| | | // 可以发布20条 |
| | | // 最多只能发布三条房源信息 |
| | | int size = this.baseMapper.selectList(new EntityWrapper<HouseResource>() |
| | | .eq("app_user_id", appUser.getId()) |
| | | .eq("is_delete", 1) |
| | | ).size(); |
| | | if (20-size<0)size=0; |
| | | return ResultUtil.success(3-size); |
| | | if (appUser.getAuth()==2){ |
| | | return ResultUtil.success(99999); |
| | | }else{ |
| | | // 如果是中介但是还未认证 最多只能上架三条 |
| | | int size = this.baseMapper.selectList(new EntityWrapper<HouseResource>() |
| | | .eq("app_user_id", appUser.getId()) |
| | | .eq("is_delete", 1) |
| | | .eq("is_delete", 0) |
| | | .eq("type",2) |
| | | ).size(); |
| | | if (3-size<0)size=0; |
| | | if (3-size<0){ |
| | | return ResultUtil.success(0); |
| | | } |
| | | return ResultUtil.success(3-size); |
| | | } |
| | | } |