New file |
| | |
| | | package com.panzhihua.applets.api; |
| | | |
| | | import java.util.Objects; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.validation.Valid; |
| | | |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.DeleteMapping; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.PutMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestParam; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.panzhihua.common.controller.BaseController; |
| | | import com.panzhihua.common.exceptions.ServiceException; |
| | | import com.panzhihua.common.model.dtos.community.rentingHouses.NearbyDTO; |
| | | import com.panzhihua.common.model.dtos.community.rentingHouses.PageRentingHouseRegisterDTO; |
| | | import com.panzhihua.common.model.dtos.community.rentingHouses.ReleaseOrCancelHouseDTO; |
| | | import com.panzhihua.common.model.dtos.community.rentingHouses.RentingHouseRegisterDTO; |
| | | import com.panzhihua.common.model.vos.LoginUserInfoVO; |
| | | import com.panzhihua.common.model.vos.R; |
| | | import com.panzhihua.common.model.vos.community.rentingHouses.RentingHouseRegisterVO; |
| | | import com.panzhihua.common.model.vos.community.rentingHouses.RentingHousesConfigVO; |
| | | import com.panzhihua.common.service.community.CommunityService; |
| | | import com.panzhihua.common.service.user.UserService; |
| | | import com.panzhihua.common.utlis.TencentUtils; |
| | | import com.panzhihua.common.validated.AddGroup; |
| | | import com.panzhihua.common.validated.PutGroup; |
| | | |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | /** |
| | | * @title: RentingHousesApi |
| | | * @projectName: 成都呐喊信息技术有限公司-智慧社区项目 |
| | | * @description: 房屋租赁相关接口 |
| | | * @author: hans |
| | | * @date: 2021/11/24 10:18 |
| | | */ |
| | | @RestController |
| | | @Slf4j |
| | | @Api(tags = {"房屋租赁相关接口"}) |
| | | @RequestMapping("/renting/houses") |
| | | public class RentingHousesApi extends BaseController { |
| | | |
| | | private static final int NOT_COMMUNITY_WORKER = 2; |
| | | |
| | | @Resource |
| | | private CommunityService communityService; |
| | | @Resource |
| | | private UserService userService; |
| | | |
| | | @ApiOperation("新增房源信息") |
| | | @PostMapping("/register") |
| | | public R registerRentingHouse(@RequestBody @Validated(AddGroup.class) RentingHouseRegisterDTO registerDTO) { |
| | | LoginUserInfoVO loginUserInfo = getLoginUserInfo(); |
| | | checkIsCommunityWorker(loginUserInfo); |
| | | registerDTO.setUserId(loginUserInfo.getUserId()); |
| | | registerDTO.setCommunityId(loginUserInfo.getCommunityId()); |
| | | return communityService.registerRentingHouse(registerDTO); |
| | | } |
| | | |
| | | @ApiOperation("编辑房源信息") |
| | | @PostMapping("/update") |
| | | public R updateRentingHouse(@RequestBody @Validated(PutGroup.class) RentingHouseRegisterDTO registerDTO) { |
| | | LoginUserInfoVO loginUserInfo = getLoginUserInfo(); |
| | | checkIsCommunityWorker(loginUserInfo); |
| | | registerDTO.setUserId(loginUserInfo.getUserId()); |
| | | registerDTO.setCommunityId(loginUserInfo.getCommunityId()); |
| | | return communityService.updateRentingHouse(registerDTO); |
| | | } |
| | | |
| | | @ApiOperation(value = "工作人员-分页获取房源信息", response = RentingHouseRegisterVO.class) |
| | | @PostMapping("/pageAdmin") |
| | | public R pageRentingHouse(@RequestBody @Valid PageRentingHouseRegisterDTO pageRegisterDTO) { |
| | | LoginUserInfoVO loginUserInfo = getLoginUserInfo(); |
| | | pageRegisterDTO.setCommunityId(loginUserInfo.getCommunityId()); |
| | | return communityService.pageRentingHouse(pageRegisterDTO); |
| | | } |
| | | |
| | | @ApiOperation("发布/取消发布 房源信息") |
| | | @PutMapping("/releaseOrCancel") |
| | | public R releaseOrCancelHouse(@RequestBody @Valid ReleaseOrCancelHouseDTO releaseOrCancelHouseDTO) { |
| | | LoginUserInfoVO loginUserInfo = getLoginUserInfo(); |
| | | checkIsCommunityWorker(loginUserInfo); |
| | | return communityService.releaseOrCancelHouse(releaseOrCancelHouseDTO); |
| | | } |
| | | |
| | | @ApiOperation(value = "获取详情-房源信息", response = RentingHouseRegisterVO.class) |
| | | @GetMapping("/get") |
| | | @ApiImplicitParam(name = "registerId", value = "房源登记id", required = true) |
| | | public R getRentingHouse(@RequestParam("registerId") Long registerId) { |
| | | LoginUserInfoVO loginUserInfoSureNoLogin = getLoginUserInfoSureNoLogin(); |
| | | Integer isLandlord = 2; |
| | | R rentingHouseR = communityService.getRentingHouse(registerId); |
| | | if (R.isOk(rentingHouseR)) { |
| | | RentingHouseRegisterVO houseRegisterVO = JSONObject.parseObject(JSONObject.toJSONString(rentingHouseR.getData()), RentingHouseRegisterVO.class); |
| | | if (Objects.nonNull(loginUserInfoSureNoLogin)) { |
| | | String userId = loginUserInfoSureNoLogin.getUserId().toString(); |
| | | R<LoginUserInfoVO> infoVOR = userService.getUserInfoByUserId(userId); |
| | | if (R.isOk(infoVOR)) { |
| | | LoginUserInfoVO loginUserInfoVO = JSONObject.parseObject(JSONObject.toJSONString(infoVOR.getData()), LoginUserInfoVO.class); |
| | | if (houseRegisterVO.getHourseIdCard().equals(loginUserInfoVO.getIdCard())) { |
| | | isLandlord = 1; |
| | | } |
| | | } |
| | | } |
| | | houseRegisterVO.setIsLandlord(isLandlord); |
| | | return R.ok(houseRegisterVO); |
| | | } |
| | | return rentingHouseR; |
| | | } |
| | | @ApiOperation("房源认证获取eidToken") |
| | | @GetMapping("/getEidToken") |
| | | public R getEidToken(@RequestParam("registerId") Long registerId){ |
| | | R r=communityService.getRentingHouse(registerId); |
| | | if(R.isOk(r)){ |
| | | RentingHouseRegisterVO registerVO=JSONObject.parseObject(JSONObject.toJSONString(r.getData()),RentingHouseRegisterVO.class); |
| | | String result=TencentUtils.getEidToken(registerVO.getHourseOwnerName(),registerVO.getHourseIdCard()); |
| | | return R.ok(result); |
| | | } |
| | | return R.fail(); |
| | | } |
| | | @ApiOperation("房源认证") |
| | | @GetMapping("/auth") |
| | | public R authHouse(@RequestParam("registerId") Long registerId,@RequestParam("result")String result){ |
| | | R r=communityService.getRentingHouse(registerId); |
| | | if(R.isOk(r)){ |
| | | String response=TencentUtils.getEidResult(result); |
| | | JSONObject object = JSON.parseObject(response); |
| | | if (object == null) { |
| | | return R.fail("核验失败"); |
| | | } |
| | | JSONObject textObject = object.getJSONObject("Text"); |
| | | |
| | | String code = textObject.getString("ErrCode"); |
| | | if (!code.equals("0")) { |
| | | log.error("人脸核验失败,错误原因:" + textObject.toJSONString()); |
| | | return R.fail("核验失败"); |
| | | } |
| | | RentingHouseRegisterDTO registerDTO=new RentingHouseRegisterDTO(); |
| | | registerDTO.setId(registerId); |
| | | registerDTO.setAuthStatus(2); |
| | | registerDTO.setDetailStatus(2); |
| | | registerDTO.setHourseOwnerUserId(getUserId()); |
| | | return communityService.updateRentingHouse(registerDTO); |
| | | } |
| | | return R.fail(); |
| | | } |
| | | |
| | | /** |
| | | * 附近的房源 |
| | | */ |
| | | @ApiOperation(value = "附近的房源",response =RentingHouseRegisterVO.class) |
| | | @PostMapping("/nearby") |
| | | public R nearby(@RequestBody NearbyDTO nearbyDTO){ |
| | | LoginUserInfoVO loginUserInfoSureNoLogin = getLoginUserInfoSureNoLogin(); |
| | | if (Objects.nonNull(loginUserInfoSureNoLogin)) { |
| | | nearbyDTO.setCommunityId(loginUserInfoSureNoLogin.getCommunityId()); |
| | | } |
| | | return communityService.nearby(nearbyDTO); |
| | | } |
| | | |
| | | /** |
| | | * 小程序分页获取房源信息 |
| | | * @param pageRegisterDTO |
| | | * @return |
| | | */ |
| | | @ApiOperation(value = "小程序分页获取房源信息",response =RentingHouseRegisterVO.class) |
| | | @PostMapping("/houseList") |
| | | public R pageRentingHouseApplet(@RequestBody PageRentingHouseRegisterDTO pageRegisterDTO) { |
| | | Integer isMy = pageRegisterDTO.getIsMy(); |
| | | if (Objects.nonNull(isMy) && isMy.intValue() == 1) { |
| | | pageRegisterDTO.setCurrentUserId(getUserId()); |
| | | } |
| | | return communityService.pageRentingHouseApplet(pageRegisterDTO); |
| | | } |
| | | |
| | | |
| | | @ApiOperation(value = "获取房屋租赁配置",response = RentingHousesConfigVO.class) |
| | | @GetMapping("/getConfig") |
| | | @ApiImplicitParam(name = "type", value = "配置类型(1.房屋租赁合同 2.租赁合同变更协议 3.定金协议 4.房屋委托代理合同" + |
| | | "5.平台须知 6.房源标签)", required = true) |
| | | public R getRentingHouseConfig(@RequestParam("type") Integer type) { |
| | | return communityService.getRentingHouseConfig(type); |
| | | } |
| | | |
| | | @ApiOperation("删除房源信息") |
| | | @DeleteMapping("/delete") |
| | | @ApiImplicitParam(name = "registerId", value = "房源登记id", required = true) |
| | | public R deleteRentingHouse(@RequestParam("registerId") Long registerId) { |
| | | LoginUserInfoVO loginUserInfo = getLoginUserInfo(); |
| | | checkIsCommunityWorker(loginUserInfo); |
| | | return communityService.deleteRentingHouse(registerId); |
| | | } |
| | | |
| | | private void checkIsCommunityWorker(LoginUserInfoVO loginUserInfo) { |
| | | if (loginUserInfo.getIsCommunityWorker().intValue() == NOT_COMMUNITY_WORKER) { |
| | | throw new ServiceException("401", "暂无权限"); |
| | | } |
| | | } |
| | | } |