From f45b80c5f8836bfb16b6cfff7df29aec631131ed Mon Sep 17 00:00:00 2001 From: 44323 <443237572@qq.com> Date: 星期二, 16 一月 2024 17:19:56 +0800 Subject: [PATCH] 发布房源 默认为审核通过和已上架状态 --- guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/HouseResourceService.java | 106 ++++++++++++++++++---------------------------------- 1 files changed, 37 insertions(+), 69 deletions(-) diff --git a/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/HouseResourceService.java b/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/HouseResourceService.java index 8bcf13e..16223e3 100644 --- a/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/HouseResourceService.java +++ b/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/HouseResourceService.java @@ -23,6 +23,8 @@ 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; @@ -32,7 +34,6 @@ 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.mapping.Document; import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.CriteriaDefinition; import org.springframework.data.mongodb.core.query.Query; @@ -85,54 +86,12 @@ 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 @@ -158,7 +117,6 @@ } } } - if (req.getDistrict() != null &&(!req.getDistrict().equals("")) ){ // 一级id Integer integer = Integer.valueOf(req.getDistrict()); @@ -509,7 +467,7 @@ houseResource.setDataType(req.getDataType()); houseResource.setAuthStatus(1); houseResource.setLeaseTime(req.getTime()); - houseResource.setAppUserId(appUserService.getAppUser().getId()); + houseResource.setAppUserId(appUserId); houseResource.setFirmHouse(req.getFirmHouse()); if (StringUtils.hasLength(req.getTime())){ if (req.getTime().contains("年")){ @@ -519,14 +477,42 @@ } } if (req.getType()==2){ + if (req.getId()==null){ + houseResource.setAuthStatus(2); + this.baseMapper.insert(houseResource); + }else{ + houseResource.setAuthStatus(2); + this.baseMapper.updateById(houseResource); + } + }else{ + if (req.getId()==null){ + houseResource.setAuthStatus(2); + this.baseMapper.insert(houseResource); + }else{ + houseResource.setAuthStatus(2); + this.baseMapper.updateById(houseResource); + } + } + if (req.getType()==2 && req.getId()==null){ + 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); + this.baseMapper.updateById(houseResource); 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; + String url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" + accessToken; Map<String, Object> param = new HashMap<>(); - param.put("path", "pages/home/home"); -// param.put("page", "pages/index/index"); // 路径 如果没有默认跳转到首页面微信小程序发布后才可以使用不能添加参数 + param.put("scene","id="+houseResource.getId()); + //pageA/houseDetail + 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); // 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调 参数仅对小程序码生效 @@ -549,10 +535,11 @@ // oss中的文件夹名 String objectName = sdf.format(new Date()) + "/" + finalFileName; // 上传oss - ossService.uploadFile2OSS(inputStream, objectName); + 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); @@ -573,26 +560,6 @@ return null; } } - if (req.getId()==null){ - this.baseMapper.insert(houseResource); - }else{ - this.baseMapper.updateById(houseResource); - } - }else{ - if (req.getId()==null){ - this.baseMapper.insert(houseResource); - }else{ - this.baseMapper.updateById(houseResource); - } - } - if (req.getType()==2 && req.getId()==null){ - 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()); - this.baseMapper.updateById(houseResource); } if (req.getType()==2 && req.getId()!=null){ HouseResource houseResource1 = this.baseMapper.selectById(req.getId()); @@ -603,6 +570,7 @@ 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())); -- Gitblit v1.7.1