| | |
| | | package com.stylefeng.guns.modular.api; |
| | | |
| | | import com.alipay.api.internal.util.codec.Base64; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | 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.ResultUtil; |
| | | 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.web.bind.annotation.*; |
| | | import org.springframework.web.client.RestTemplate; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | 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.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @author zhibing.pu |
| | |
| | | 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()); |
| | | } |
| | | |
| | | // todo 放行 |
| | | @ResponseBody |
| | |
| | | @ApiOperation(value = "中介身份提示", tags = {"发布"}) |
| | | @ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", |
| | | required = true, paramType = "header") |
| | | public ResultUtil confirm(@RequestBody Integer userType){ |
| | | 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); |
| | | } |
| | | // todo 放行 |
| | | |
| | | @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 = {"发布"}) |
| | |
| | | @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); |
| | | } |
| | | |
| | |
| | | return ResultUtil.success(districtHouseResourceNumber); |
| | | } |
| | | |
| | | |
| | | @ResponseBody |
| | | @PostMapping("/base/houseResource/getHouseResourceInfo") |
| | | @ApiOperation(value = "获取房源详情", tags = {"详情"}) |
| | |
| | | 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 = {"详情"}) |
| | | @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") |
| | |
| | | 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(); |
| | | } |
| | | } |