mitao
2025-02-21 31573d6180d15ef65ed0df9c2732495f40b12663
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
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", "暂无权限");
        }
    }
}