44323
2024-02-22 aa8ff2d61669d0779fdacdba76e26388587b435d
guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/HouseResourceService.java
@@ -300,6 +300,7 @@
        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());
@@ -482,6 +483,7 @@
                }
            }
            HouseResource houseResource = new HouseResource();
            houseResource.setPlatform(req.getPlatform());
            BeanUtils.copyProperties(req,houseResource);
            houseResource.setType(req.getType());
@@ -492,17 +494,25 @@
            }
            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(2);
            houseResource.setLeaseTime(req.getTime());
            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);
@@ -531,7 +541,33 @@
                    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);
@@ -541,66 +577,20 @@
                houseResource.setAuthStatus(2);
                houseResource.setAuthTime(new Date());
                this.baseMapper.updateById(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());
                    //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); // 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调 参数仅对小程序码生效
                    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();
                        }
                        return null;
                    }
                }
                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();
@@ -623,11 +613,71 @@
                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();