| | |
| | | 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.ICollectionHouseResourceService; |
| | | import com.stylefeng.guns.modular.system.service.IHouseResourceService; |
| | | import com.stylefeng.guns.modular.system.service.IHouseTypeService; |
| | | import com.stylefeng.guns.modular.system.service.IReportHouseResourceService; |
| | | 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.warpper.req.ReportHouseResourceReq; |
| | | import com.stylefeng.guns.modular.system.warpper.req.SearchHouseResourceReq; |
| | | import com.stylefeng.guns.modular.system.util.WxAppletTools; |
| | | import com.stylefeng.guns.modular.system.warpper.req.*; |
| | | import com.stylefeng.guns.modular.system.warpper.res.*; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.apache.http.entity.ContentType; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.http.*; |
| | | 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; |
| | | |
| | | import java.util.List; |
| | | import java.io.*; |
| | | import java.net.HttpURLConnection; |
| | | import java.net.URL; |
| | | import java.net.URLEncoder; |
| | | import java.security.SecureRandom; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @author zhibing.pu |
| | |
| | | private ICollectionHouseResourceService collectionHouseResourceService; |
| | | @Autowired |
| | | private IReportHouseResourceService reportHouseResourceService; |
| | | @Autowired |
| | | private IAppUserService appUserService; |
| | | @Autowired |
| | | private WxAppletTools wxAppletTools; |
| | | @Autowired |
| | | private RestTemplate restTemplate; |
| | | @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"; |
| | | // 生成小程序码 |
| | | private String generateMiniProgramCode(String apiUrl, String pagePath, String outputFilePath) throws IOException { |
| | | URL url = new URL(apiUrl); |
| | | 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); |
| | | } |
| | | } |
| | | @ResponseBody |
| | | @GetMapping("/base/houseResource/qrCode/{id}") |
| | | @ApiOperation(value = "海报二维码", tags = {"房源"}) |
| | | public ResultUtil<String> poster(@PathVariable("id") Integer id){ |
| | | 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") |
| | | @ApiOperation(value = "中介身份提示", tags = {"发布"}) |
| | | @ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", |
| | | required = true, paramType = "header") |
| | | public ResultUtil confirm(Integer userType){ |
| | | AppUser appUser = appUserService.getAppUser(); |
| | | if(null != appUser && (appUser.getStatus() == 2|| appUser.getStatus() == 3)){ |
| | | return ResultUtil.errorLogin("当前账号已被冻结或删除"); |
| | | } |
| | | return houseResourceService.confirm(userType); |
| | | } |
| | | |
| | | @ResponseBody |
| | | @PostMapping("/base/addHouse/userInfo") |
| | | @ApiOperation(value = "发布房源获取当前人的中介认证状态", tags = {"发布"}) |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header") |
| | | }) |
| | | public ResultUtil userInfo(){ |
| | | AppUser appUser = appUserService.getAppUser(); |
| | | if(null != appUser && (appUser.getStatus() == 2|| appUser.getStatus() == 3)){ |
| | | return ResultUtil.errorLogin("当前账号已被冻结或删除"); |
| | | } |
| | | Integer auth = appUserService.getAppUser().getAuth(); |
| | | return ResultUtil.success(appUser); |
| | | } |
| | | |
| | | @ResponseBody |
| | | @PostMapping("/base/addHouse/add") |
| | | @ApiOperation(value = "发布房源", tags = {"发布"}) |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header") |
| | | }) |
| | | public ResultUtil addHouse(@RequestBody AddHouseReq req){ |
| | | AppUser appUser = appUserService.getAppUser(); |
| | | if(null != appUser && (appUser.getStatus() == 2|| appUser.getStatus() == 3)){ |
| | | return ResultUtil.errorLogin("当前账号已被冻结或删除"); |
| | | } |
| | | return houseResourceService.addHouse(req); |
| | | } |
| | | |
| | | @ResponseBody |
| | | @GetMapping("/base/houseResource/searchHouseResource") |
| | |
| | | return ResultUtil.success(searchHouseResource); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | @ResponseBody |
| | | @GetMapping("/base/houseType/getHouseType") |
| | | @ApiOperation(value = "获取房源类型", tags = {"首页"}) |
| | |
| | | List<HouseType> houseTypes = houseTypeService.selectList(null); |
| | | return ResultUtil.success(houseTypes); |
| | | } |
| | | |
| | | |
| | | @ResponseBody |
| | | @GetMapping("/base/houseResource/getDistrictHouseResourceNumber") |
| | |
| | | return ResultUtil.success(districtHouseResourceNumber); |
| | | } |
| | | |
| | | |
| | | @ResponseBody |
| | | @PostMapping("/base/houseResource/getHouseResourceInfo") |
| | | @ApiOperation(value = "获取房源详情", tags = {"详情"}) |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "id", value = "房源id", required = true), |
| | | @ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = false, paramType = "header") |
| | | // @ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = false, paramType = "header") |
| | | }) |
| | | public ResultUtil<HouseResourceInfoRes> getHouseResourceInfo(Integer id){ |
| | | HouseResourceInfoRes houseResourceInfo = houseResourceService.getHouseResourceInfo(id); |
| | | return ResultUtil.success(houseResourceInfo); |
| | | } |
| | | |
| | | |
| | | @ResponseBody |
| | | @PostMapping("/api/houseResource/collectionHouseResource") |
| | | @PostMapping("/base/houseResource/collectionHouseResource") |
| | | @ApiOperation(value = "收藏/取消收藏房源操作", tags = {"详情"}) |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "id", value = "房源id", required = true), |
| | | @ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header") |
| | | }) |
| | | public ResultUtil collectionHouseResource(Integer id){ |
| | | AppUser appUser = appUserService.getAppUser(); |
| | | if(null != appUser && (appUser.getStatus() == 2|| appUser.getStatus() == 3)){ |
| | | return ResultUtil.errorLogin("当前账号已被冻结或删除"); |
| | | } |
| | | return collectionHouseResourceService.collectionHouseResource(id); |
| | | } |
| | | |
| | | |
| | | |
| | | @ResponseBody |
| | | @GetMapping("/base/houseResource/getNearbyHouseResource") |
| | |
| | | return ResultUtil.success(nearbyHouseResource); |
| | | } |
| | | |
| | | |
| | | @ResponseBody |
| | | @GetMapping("/base/houseResource/getContactInformation") |
| | | @GetMapping("/base/houseResource/getContactInformation/{id}") |
| | | @ApiOperation(value = "获取联系方式", tags = {"详情"}) |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "id", value = "房源id", required = true), |
| | | }) |
| | | public ResultUtil<ContactInformationRes> getContactInformation(Integer id){ |
| | | public ResultUtil<ContactInformationRes> getContactInformation(@PathVariable("id") Integer id){ |
| | | ContactInformationRes contactInformation = houseResourceService.getContactInformation(id); |
| | | return ResultUtil.success(contactInformation); |
| | | } |
| | | |
| | | |
| | | |
| | | @ResponseBody |
| | | @PostMapping("/api/houseResource/addReportHouseResource") |
| | | @PostMapping("/base/houseResource/addReportHouseResource") |
| | | @ApiOperation(value = "添加房源举报", tags = {"详情"}) |
| | | public ResultUtil addReportHouseResource(ReportHouseResourceReq req){ |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header") |
| | | }) |
| | | public ResultUtil addReportHouseResource(@RequestBody ReportHouseResourceReq req){ |
| | | AppUser appUser = appUserService.getAppUser(); |
| | | if(null != appUser && (appUser.getStatus() == 2|| appUser.getStatus() == 3)){ |
| | | return ResultUtil.errorLogin("当前账号已被冻结或删除"); |
| | | } |
| | | return reportHouseResourceService.addReportHouseResource(req); |
| | | } |
| | | |
| | | @ResponseBody |
| | | @PostMapping("/base/intermediary/list") |
| | | @ApiOperation(value = "找中介", tags = {"服务"}) |
| | | public ResultUtil<SearchIntermediaryRes> searchIntermediaryList(@RequestBody SearchIntermediaryReq req){ |
| | | SearchIntermediaryRes res= appUserService.searchIntermediaryList(req); |
| | | return ResultUtil.success(res); |
| | | } |
| | | |
| | | @ResponseBody |
| | | @PostMapping("/base/intermediary/intermediaryInfo") |
| | | @ApiOperation(value = "找中介-中介信息", tags = {"服务"}) |
| | | public ResultUtil<SearchIntermediaryListRes> searchIntermediaryInfo(Integer id){ |
| | | SearchIntermediaryListRes res= appUserService.searchIntermediaryInfo(id); |
| | | if (res==null){ |
| | | SearchIntermediaryListRes searchIntermediaryListRes = new SearchIntermediaryListRes(); |
| | | AppUser appUser = appUserService.selectById(id); |
| | | searchIntermediaryListRes.setId(id); |
| | | searchIntermediaryListRes.setNickname(appUser.getNickname()); |
| | | searchIntermediaryListRes.setCompanyName(appUser.getCompanyName()); |
| | | searchIntermediaryListRes.setCompanyAddress(appUser.getCompanyAddress()); |
| | | searchIntermediaryListRes.setIntroduce(appUser.getIntroduce()); |
| | | searchIntermediaryListRes.setProfilePhoto(appUser.getProfilePhoto()); |
| | | searchIntermediaryListRes.setPhone(appUser.getPhone()); |
| | | searchIntermediaryListRes.setHouseCount(0); |
| | | return ResultUtil.success(searchIntermediaryListRes); |
| | | } |
| | | return ResultUtil.success(res); |
| | | } |
| | | |
| | | @ResponseBody |
| | | @GetMapping("/base/intermediary/getContactInfo/{id}") |
| | | @ApiOperation(value = "获取中介联系方式", tags = {"详情"}) |
| | | public ResultUtil<AppUser> getContactInfo(@PathVariable("id") Integer id){ |
| | | AppUser appUser = appUserService.selectById(id); |
| | | return ResultUtil.success(appUser); |
| | | } |
| | | @ResponseBody |
| | | @PostMapping("/base/intermediary/listHouse") |
| | | @ApiOperation(value = "个人详情-我的房源", tags = {"服务"}) |
| | | @ApiImplicitParams({ |
| | | // @ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header") |
| | | }) |
| | | public ResultUtil<SearchHouseResourceRes> listHouse(@RequestBody HouseQuery query){ |
| | | SearchHouseResourceRes res= houseResourceService.listHouse(query); |
| | | return ResultUtil.success(res); |
| | | } |
| | | |
| | | @ResponseBody |
| | | @PostMapping("/base/housingDemand/getSurplusPushNumber1") |
| | | @ApiOperation(value = "获取剩余发布数量", tags = {"房源"}) |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header") |
| | | }) |
| | | public ResultUtil getSurplusPushNumber1(){ |
| | | AppUser appUser = appUserService.getAppUser(); |
| | | if(null != appUser && (appUser.getStatus() == 2|| appUser.getStatus() == 3)){ |
| | | return ResultUtil.errorLogin("当前账号已被冻结或删除"); |
| | | } |
| | | return houseResourceService.getSurplusPushNumber1(); |
| | | } |
| | | } |