guns-admin/pom.xml
@@ -34,9 +34,11 @@ <version>1.0.6</version> </dependency> <!-- Aliyun OSS SDK --> <dependency><groupId>com.aliyun.oss</groupId> <dependency> <groupId>com.aliyun.oss</groupId> <artifactId>aliyun-sdk-oss</artifactId> <version>3.14.0</version></dependency> <version>3.15.1</version> </dependency> <!--spring boot依赖--> <dependency> <groupId>org.springframework.boot</groupId> guns-admin/src/main/java/com/stylefeng/guns/modular/api/FileController.java
@@ -35,7 +35,6 @@ if (originalFilename != null && originalFilename.contains(".")) { System.err.println(originalFilename.substring(originalFilename.lastIndexOf("."))); } // 创建 OSSClient 实例 OSSClient ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret); long l = System.currentTimeMillis(); guns-admin/src/main/java/com/stylefeng/guns/modular/api/HouseResourceController.java
@@ -1,12 +1,20 @@ package com.stylefeng.guns.modular.api; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.alipay.api.internal.util.codec.Base64; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.google.gson.Gson; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.stylefeng.guns.modular.file.OSSService; import com.stylefeng.guns.modular.system.model.AppUser; import com.stylefeng.guns.modular.system.model.HouseResource; import com.stylefeng.guns.modular.system.model.HouseType; import com.stylefeng.guns.modular.system.service.*; import com.stylefeng.guns.modular.system.util.HttpRequestUtil; import com.stylefeng.guns.modular.system.util.HttpUtils; import com.stylefeng.guns.modular.system.util.ResultUtil; import com.stylefeng.guns.modular.system.util.WxAppletTools; import com.stylefeng.guns.modular.system.warpper.req.*; @@ -21,6 +29,7 @@ import org.springframework.mock.web.MockMultipartFile; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.*; import org.springframework.web.client.RestTemplate; import org.springframework.web.multipart.MultipartFile; @@ -32,10 +41,8 @@ import java.security.SecureRandom; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.*; import java.util.stream.Collectors; /** * @author zhibing.pu @@ -110,7 +117,75 @@ HouseResource houseResource = houseResourceService.selectById(id); return ResultUtil.success(houseResource.getQrCode()); } @ResponseBody @GetMapping("/base/houseResource/historyTitle") @ApiOperation(value = "选择之前填入过的标题", tags = {"房源"}) @ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header") }) public ResultUtil<List<String>> historyTitle(){ Integer id = appUserService.getAppUser().getId(); List<String> titles = houseResourceService.selectList(new EntityWrapper<HouseResource>() .eq("app_user_id", id)).stream().filter(t-> StringUtils.hasLength(t.getTitle())).map(HouseResource::getTitle) .collect(Collectors.toList()); return ResultUtil.success(titles); } @ResponseBody @GetMapping("/base/houseResource/historyIntroduce") @ApiOperation(value = "选择之前填入过的更多介绍", tags = {"房源"}) @ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header") }) public ResultUtil<List<String>> historyIntroduce(){ Integer id = appUserService.getAppUser().getId(); List<String> titles = houseResourceService.selectList(new EntityWrapper<HouseResource>() .eq("app_user_id", id)).stream().filter(t-> StringUtils.hasLength(t.getMoreIntroduction())).map(HouseResource::getMoreIntroduction) .collect(Collectors.toList()); return ResultUtil.success(titles); } @ResponseBody @GetMapping("/base/houseResource/getHouse") @ApiOperation(value = "根据选择的区域 获取附近小区", tags = {"房源"}) public ResultUtil<List<String>> getHouse(String cityName){ List<String> res = new ArrayList<>(); String url = "https://apis.map.qq.com/ws/place/v1/search?boundary=region(香港,0)&keyword="+cityName+"&filter=category=住宅区,别墅,社区,宿舍&page_size=30&page_index=1&key=G52BZ-X5AKH-V2JDQ-WSLRK-7DSMZ-YWFXZ"; String s = HttpUtils.sendGet(url); Gson gson = new Gson(); JsonObject jsonObject = gson.fromJson(s, JsonObject.class); JsonArray dataArray = jsonObject.getAsJsonArray("data"); List<String> titles = new ArrayList<>(); for (JsonElement element : dataArray) { JsonObject dataObject = element.getAsJsonObject(); String title = dataObject.get("title").getAsString(); titles.add(title); } for (String title : titles) { res.add(title); } return ResultUtil.success(res); } public static void main(String[] args) { String url = "https://apis.map.qq.com/ws/place/v1/search?boundary=region(香港,0)&keyword=上环/中环/金钟&filter=category=住宅区,别墅,社区,宿舍&page_size=30&page_index=1&key=G52BZ-X5AKH-V2JDQ-WSLRK-7DSMZ-YWFXZ"; String s = HttpUtils.sendGet(url); // 使用Gson库解析JSON Gson gson = new Gson(); JsonObject jsonObject = gson.fromJson(s, JsonObject.class); JsonArray dataArray = jsonObject.getAsJsonArray("data"); // 遍历data数组,提取title字段值并放入集合 List<String> titles = new ArrayList<>(); for (JsonElement element : dataArray) { JsonObject dataObject = element.getAsJsonObject(); String title = dataObject.get("title").getAsString(); titles.add(title); } // 打印集合中的title字段值 for (String title : titles) { System.out.println(title); } } // todo 放行 @ResponseBody @PostMapping("/base/addHouse/confirm") guns-admin/src/main/java/com/stylefeng/guns/modular/system/dao/mapping/HouseResourceMapper.xml
@@ -7,7 +7,7 @@ <select id="searchHouseResource" resultType="com.stylefeng.guns.modular.system.warpper.res.SearchHouseResourceListRes"> select hr.id, au.user_type as houseResource, IFNULL(au.user_type,0)as houseResource, hr.house_photo as imgUrl, hr.title, hr.house_area as houseArea, @@ -15,6 +15,7 @@ concat(rp.`name`, rc.`name`) as address, hr.longitude, hr.latitude, hr.headImg, hr.platform, hr.sale_amount as saleAmount, IFNULL(au.nickname,su.`name`) as nickname, @@ -37,10 +38,10 @@ left join t_region rp on (rp.id = rc.parent_id) left join t_house_type tp on hr.house_type_id = tp.id where hr.is_delete = 0 and hr.`status` = 1 and hr.auth_status = 2 and hr.type=2 <if test="null != req.type and 2 == req.type"> and hr.data_type = #{req.type} <if test="null != req.type and req.type == 1"> and (hr.data_type = #{req.type}) </if> <if test="null != req.type and 1 == req.type"> <if test="null != req.type and req.type == 2"> and hr.data_type = #{req.type} </if> <if test="null != req.userType and 2 == req.userType"> @@ -70,7 +71,7 @@ #{item} </foreach> </if> <if test="null != saleAmountStart and null != saleAmountEnd"> <if test="req.type!=null and req.type==2 and null != saleAmountStart and null != saleAmountEnd"> and hr.sale_amount >= #{saleAmountStart} and hr.sale_amount < #{saleAmountEnd} </if> <if test="null != houseModels"> @@ -146,25 +147,30 @@ hr.latitude, hr.platform, hr.sale_amount as saleAmount, IFNULL(au.nickname,su.`name`) as nickname, IFNULL(au.profile_photo,su.avatar) as profilePhoto, au.profile_photo as profilePhoto, au.nickname, hr.elevator, hr.drying_area as dryingArea, hr.garden, hr.carport, hr.air, hr.balcony, hr.is_manage as isManage, hr.leaseTime, hr.keep_pet as keepPet tp.name as houseTypeName, hr.keep_pet as keepPet, hr.insert_time as insertTime from t_house_resource hr left join t_app_user au on (hr.app_user_id = au.id) LEFT JOIN sys_user su ON hr.insert_user_id = su.id AND hr.is_manage = 1 left join t_region rc on (hr.district_id = rc.id) left join t_region rp on (rp.id = rc.parent_id) left join t_house_type tp on hr.house_type_id = tp.id where hr.is_delete = 0 and hr.`status` = 1 and hr.auth_status = 2 and hr.type=2 <if test="null != req.type and 2 == req.type"> and hr.data_type = #{req.type} <if test="null != req.type and req.type == 1"> and (hr.data_type = #{req.type}) </if> <if test="null != req.type and 1 == req.type"> <if test="null != req.type and req.type == 2"> and hr.data_type = #{req.type} </if> <if test="null != req.userType and 2 == req.userType"> @@ -194,7 +200,7 @@ #{item} </foreach> </if> <if test="null != saleAmountStart and null != saleAmountEnd"> <if test="req.type!=null and req.type==2 and null != saleAmountStart and null != saleAmountEnd"> and hr.sale_amount >= #{saleAmountStart} and hr.sale_amount < #{saleAmountEnd} </if> <if test="null != houseModels"> @@ -242,7 +248,7 @@ <if test="null != req.dataType and req.dataType == 2"> and now() <= DATE_ADD(hr.insert_time,INTERVAL 21 day) </if> order by au.user_type desc,hr.insert_time desc order by au.user_type desc <if test="null != req.sort and req.sort == 1"> ,hr.insert_time desc </if> @@ -466,6 +472,8 @@ hr.garden as garden, hr.carport as carport, hr.balcony as balcony, hr.app_user_id as appuserId, hr.city_id as cityId, hr.district_id as districtId, @@ -496,6 +504,7 @@ hr.garden, hr.carport, hr.balcony, hr.app_user_id as appUserId, hr.city_id as cityId, hr.district_id as districtId, guns-admin/src/main/java/com/stylefeng/guns/modular/system/model/HouseResource.java
@@ -42,6 +42,11 @@ @TableField("title") private String title; /** * 房源封面图 */ @TableField("headImg") private String headImg; /** * 小区名字 */ @TableField("cell_name") @@ -312,4 +317,11 @@ */ @TableField("pool") private Integer pool; /** * 楼龄 */ @TableField("age") private Integer age; } 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(); guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/Md5Util.java
New file @@ -0,0 +1,48 @@ package com.stylefeng.guns.modular.system.util; import java.security.MessageDigest; public class Md5Util { private static final String hexDigIts[] = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"}; /** * MD5加密 * * @param origin 字符 * @param charsetname 编码 * @return */ public static String MD5Encode(String origin, String charsetname) { String resultString = null; try { resultString = new String(origin); MessageDigest md = MessageDigest.getInstance("MD5"); if (null == charsetname || "".equals(charsetname)) { resultString = byteArrayToHexString(md.digest(resultString.getBytes())); } else { resultString = byteArrayToHexString(md.digest(resultString.getBytes(charsetname))); } } catch (Exception e) { } return resultString; } public static String byteArrayToHexString(byte b[]) { StringBuffer resultSb = new StringBuffer(); for (int i = 0; i < b.length; i++) { resultSb.append(byteToHexString(b[i])); } return resultSb.toString(); } public static String byteToHexString(byte b) { int n = b; if (n < 0) { n += 256; } int d1 = n / 16; int d2 = n % 16; return hexDigIts[d1] + hexDigIts[d2]; } } guns-admin/src/main/java/com/stylefeng/guns/modular/system/warpper/req/AddHouseReq.java
@@ -63,6 +63,7 @@ private String videoPhoto; @ApiModelProperty(value = "房源视频") private String houseVideo; @ApiModelProperty(value = "标题", required = true) private String title; @ApiModelProperty(value = "更多介绍(求租描述)", required = true) @@ -89,5 +90,11 @@ private Integer building; @ApiModelProperty(value ="是否有泳池(0=否,1=是)") private Integer pool; @ApiModelProperty(value ="同时可租租金") private BigDecimal rentalMoney; @ApiModelProperty(value ="楼龄") private Integer age; @ApiModelProperty(value = "房源封面图片") private String headImg; } guns-admin/src/main/java/com/stylefeng/guns/modular/system/warpper/res/CollectListRes.java
@@ -89,5 +89,8 @@ @ApiModelProperty("房源审核状态") private Integer authStatus; @ApiModelProperty("选择同时出租的租金 月") private BigDecimal rentalMoney; } guns-admin/src/main/java/com/stylefeng/guns/modular/system/warpper/res/HouseResourceInfoRes.java
@@ -76,5 +76,9 @@ @ApiModelProperty("房屋朝向") private String buildingOrientation; @ApiModelProperty("同时可租 租金") private BigDecimal rentalMoney; @ApiModelProperty("楼龄") private Integer age; } guns-admin/src/main/java/com/stylefeng/guns/modular/system/warpper/res/SearchHouseResourceListRes.java
@@ -4,6 +4,7 @@ import io.swagger.annotations.ApiModelProperty; import lombok.Data; import java.math.BigDecimal; import java.util.Date; /** @@ -17,7 +18,7 @@ private Integer id; @ApiModelProperty("房源来源(2=个人房源,3=中介房源)") private Integer houseResource; @ApiModelProperty("封面图") @ApiModelProperty("图片") private String imgUrl; @ApiModelProperty("标题") private String title; @@ -57,8 +58,11 @@ private Integer keepPet; @ApiModelProperty("租期") private String leaseTime; @ApiModelProperty("房源封面图片") private String headImg; @ApiModelProperty("是否为平台添加") private Integer isManage; @ApiModelProperty("添加时间") private Date insertTime; } guns-management/src/main/java/com/stylefeng/guns/modular/system/warpper/res/SearchHouseResourceListRes.java
@@ -4,6 +4,8 @@ import io.swagger.annotations.ApiModelProperty; import lombok.Data; import java.math.BigDecimal; /** * @author zhibing.pu * @Date 2023/11/13 11:42 @@ -47,4 +49,5 @@ private Integer balcony; @ApiModelProperty("是否可养宠物(0=否,1=是)") private Integer keepPet; }