44323
2024-01-10 a1a50ae80ce2b09af00a6a2972195b3f5617d4bf
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
package com.stylefeng.guns.modular.api;
 
import com.alibaba.druid.sql.visitor.functions.If;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.stylefeng.guns.modular.system.model.*;
import com.stylefeng.guns.modular.system.service.*;
import com.stylefeng.guns.modular.system.service.impl.FeedBackServiceImpl;
import com.stylefeng.guns.modular.system.service.impl.HouseTypeServiceImpl;
import com.stylefeng.guns.modular.system.util.HttpUtils;
import com.stylefeng.guns.modular.system.util.Page;
import com.stylefeng.guns.modular.system.util.ResultUtil;
import com.stylefeng.guns.modular.system.warpper.req.*;
import com.stylefeng.guns.modular.system.warpper.res.AppletLoginRes;
import com.stylefeng.guns.modular.system.warpper.res.CollectRes;
import com.stylefeng.guns.modular.system.warpper.res.SearchIntermediaryRes;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
 
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
 
/**
 * @author zhibing.pu
 * @Date 2023/11/7 11:07
 */
@RestController
@RequestMapping("")
public class AppUserController {
 
    @Autowired
    private IAppUserService appUserService;
    @Autowired
    private IFeedBackService feedBackService;
    @Autowired
    private IHouseResourceService houseResourceService;
    @Autowired
    private IHousingDemandService housingDemandService;
    @Autowired
    private IHouseTypeService houseTypeService;
    @Autowired
    private IRegionService regionService;
    @Autowired
    private IBannerService bannerService;
    @Autowired
    private IReportHouseResourceService reportHouseResource;
    @ResponseBody
    @GetMapping("/base/appUser/agreement")
    @ApiOperation(value = "协议", tags = {"协议"})
    public ResultUtil agreement(Integer type){
        Banner banners = bannerService.selectOne(new EntityWrapper<Banner>().eq("position",type));
        return ResultUtil.success(banners);
    }
 
    @ResponseBody
    @PostMapping("/base/appUser/appletLogin")
    @ApiOperation(value = "微信小程序登录", tags = {"登录注册"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "jscode", value = "微信jscode", required = true)})
    public ResultUtil<AppletLoginRes> appletLogin(String jscode,String encryptedPhoneData,String phoneIv){
        RegisterAccountReq req = new RegisterAccountReq();
        req.setJscode(jscode);
        req.setEncryptedPhoneData(encryptedPhoneData);
        req.setPhone_iv(phoneIv);
        return appUserService.appletLogin(req);
    }
 
    @ResponseBody
    @PostMapping("/base/appUser/registerAccount")
    @ApiOperation(value = "小程序注册账户", tags = {"登录注册"})
    public ResultUtil<AppletLoginRes> registerAccount(@RequestBody RegisterAccountReq req){
        return appUserService.registerAccount(req);
    }
 
    // todo 放行
    @ResponseBody
    @PostMapping("/base/appUser/userInfo")
    @ApiOperation(value = "个人中心", tags = {"个人中心"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header")
    })
    public ResultUtil<AppUser> userInfo(){
        return appUserService.userInfo();
    }
 
    // todo 放行
    @ResponseBody
    @PostMapping("/base/appUser/release")
    @ApiOperation(value = "发布", tags = {"个人中心"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header")
    })
    public ResultUtil<CollectRes> release(UserInfoQuery query){
        return appUserService.collect(query);
    }
 
    // todo 放行
    @ResponseBody
    @PostMapping("/base/appUser/collect")
    @ApiOperation(value = "收藏", tags = {"个人中心"})
    @ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header")
    public ResultUtil<CollectRes> collect(@RequestBody UserInfoQuery query){
        return appUserService.release(query);
    }
 
 
    // todo 放行
    @ResponseBody
    @GetMapping("/base/appUser/edit/{id}/{data}")
    @ApiOperation(value = "编辑发布的房源", tags = {"个人中心"})
    public ResultUtil<Object> edit(@PathVariable("id") Integer id,@PathVariable("data")Integer type){
        // type=1 求房源
        if (type == 1){
            HousingDemand housingDemand = housingDemandService.selectById(id);
            if (StringUtils.hasLength(housingDemand.getDistrict())){
                JSONArray jsonArray = JSON.parseArray(housingDemand.getDistrict());
                housingDemand.setDistrict(jsonArray.toString());
            }
            if (housingDemand.getHouseTypeId()!=null && (!housingDemand.getHouseTypeId().equals("0"))){
                HouseType houseType = houseTypeService.selectById(housingDemand.getHouseTypeId());
                if (houseType!=null){
                    housingDemand.setHouseTypeName(houseType.getName());
                }
            }
            if (housingDemand.getHouseTypeId()!=null && housingDemand.getHouseTypeId().equals("0")){
                housingDemand.setHouseTypeName("不限");
            }
            housingDemand.setUpdateTime(new Date());
            // 查询求房源选择的区域
            return ResultUtil.success(housingDemand);
        }else{
            HouseResource houseResource = houseResourceService.selectById(id);
            if (houseResource.getHouseTypeId()!=null){
                HouseType houseType = houseTypeService.selectById(houseResource.getHouseTypeId());
                if (houseType!=null)houseResource.setHouseTypeName(houseType.getName());
            }
            if (houseResource.getCityId()!=null){
                Region region = regionService.selectById(houseResource.getCityId());
                if (region!=null)houseResource.setCityName(region.getName());
            }
            if (houseResource.getDistrictId()!=null && houseResource.getDistrictId()==0){
                houseResource.setDistrictName("不限");
            }else{
                Region region = regionService.selectById(houseResource.getDistrictId());
                if (region!=null)houseResource.setDistrictName(region.getName());
            }
            houseResource.setUpdateTime(new Date());
            return ResultUtil.success(houseResource);
        }
    }
    // todo 放行
    @ResponseBody
    @PostMapping("/base/appUser/auth/{id}")
    @ApiOperation(value = "中介认证", tags = {"个人中心"})
    @ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....",
            required = true, paramType = "header")
    public ResultUtil auth(@RequestBody AuthDTO dto){
        AppUser appUser = appUserService.getAppUser();
        if(null != appUser && (appUser.getStatus() == 2|| appUser.getStatus() == 3)){
            return ResultUtil.errorLogin("当前账号已被冻结或删除");
        }
        appUser.setAgentLicenceCode(dto.getAgentLicenceCode());
        appUser.setCompanyName(dto.getCompanyName());
        appUser.setCompanyAddress(dto.getCompanyAddress());
        appUser.setBusinessCardPhoto(dto.getBusinessCardPhoto());
        appUser.setCityId(dto.getCityId());
        appUser.setDistrictId(dto.getDistrictId());
        appUser.setAuth(1);
        appUserService.updateById(appUser);
        return ResultUtil.success();
    }
    @ResponseBody
    @PostMapping("/base/appUser/authInfo")
    @ApiOperation(value = "中介认证信息", tags = {"个人中心"})
    @ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....",
            required = true, paramType = "header")
    public ResultUtil authInfo(){
        AppUser appUser = appUserService.getAppUser();
        AppUserDTO appUserDTO = new AppUserDTO();
        BeanUtils.copyProperties(appUser,appUserDTO);
        if (appUser.getCityId()!=null){
            Region region = regionService.selectById(appUser.getCityId());
            appUserDTO.setCityName(region.getName());
        }
        if (appUser.getDistrictId()!=null){
            Region region = regionService.selectById(appUser.getDistrictId());
            appUserDTO.setDistrictName(region.getName());
        }
        if(null != appUser && (appUser.getStatus() == 2|| appUser.getStatus() == 3)){
            return ResultUtil.errorLogin("当前账号已被冻结或删除");
        }
        return ResultUtil.success(appUserDTO);
    }
 
 
 
    /**
     *地图查询
     */
    @ResponseBody
    @ApiOperation(value = "地图查询", tags = {"个人中心"})
    @GetMapping("/base/appUser/queryMap")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "位置", required = true)
    })
    public ResultUtil queryMap(String name)
    {
        String url ="https://apis.map.qq.com/ws/geocoder/v1/?address="+name+"&key=AAIBZ-NO7AQ-RKQ5G-2YSBL-3MEJH-VTFH4";
        String result = HttpUtils.sendGet(url);
        JSONArray data = JSONObject.parseObject(result).getJSONArray("data");
        return ResultUtil.success(data);
    }
 
    public static void main(String[] args) {
        String url1 ="https://apis.map.qq.com/ws/district/v1/getchildren?id=110000&key=ZQXBZ-N4KKN-JE4FI-SUUUY-OIT2J-VEB7C";
        String result1 = HttpUtils.sendGet(url1);
        System.err.println(result1);
        JSONArray data1 = JSONObject.parseObject(result1).getJSONArray("data");
        System.err.println("返回结果:"+data1);
//        String url ="https://apis.map.qq.com/ws/place/v1/suggestion/?keyword="+"四川省成都市青羊区大墙西街72号"+"&key=AAIBZ-NO7AQ-RKQ5G-2YSBL-3MEJH-VTFH4";
//        String result = HttpUtils.sendGet(url);
//        System.err.println(result);
//        JSONArray data = JSONObject.parseObject(result).getJSONArray("data");
//        System.err.println("返回结果:"+data);
 
 
//        String url1 ="https://apis.map.qq.com/ws/district/v1/search?&keyword="+"香港"+"&key=AAIBZ-NO7AQ-RKQ5G-2YSBL-3MEJH-VTFH4";
//        String result1 = HttpUtils.sendGet(url1);
//        System.err.println(result1);
//        JSONArray data1 = JSONObject.parseObject(result1).getJSONArray("data");
//        System.err.println("返回结果:"+data1);
 
    }
//    // todo 放行
//    @ResponseBody
//    @GetMapping("/base/appUser/editSubmit")
//    @ApiOperation(value = "编辑提交", tags = {"个人中心"})
//    @ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....",
//            required = true, paramType = "header")
//    public ResultUtil editSubmit(@RequestBody AddHouseReq req){
//        HouseResource houseResource = new HouseResource();
//        BeanUtils.copyProperties(req,houseResource);
//        houseResource.setInsertTime(new Date());
//        houseResource.setAuthStatus(1);
//        houseResource.setIsDelete(0);
//        houseResource.setUpdateUserId(appUserService.getAppUser().getId());
//        houseResource.setUpdateTime(new Date());
//        houseResource.setStatus(0);
//        houseResource.setLeaseTime(req.getTime());
//        houseResource.setFirmHouse(req.getFirmHouse());
//        if (req.getTime().contains("年")){
//            houseResource.setRentalDuration(2);
//        }else{
//            houseResource.setRentalDuration(1);
//        }
//        return ResultUtil.success();
//    }
    // todo 放行
    @ResponseBody
    @PostMapping("/base/appUser/operate")
    @ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....",
            required = true, paramType = "header")
    @ApiOperation(value = "发布-删除/下架/顶上去/上架", tags = {"个人中心"})
    public ResultUtil delete(@RequestBody UserInfoDTO dto){
        AppUser appUser = appUserService.getAppUser();
        if(null != appUser && (appUser.getStatus() == 2|| appUser.getStatus() == 3)){
            return ResultUtil.errorLogin("当前账号已被冻结或删除");
        }
        Integer id = appUser.getId();
        if (dto.getData() == 2){
        switch (dto.getType()){
            case 1:
                HouseResource houseResource = houseResourceService.selectById(dto.getId());
                houseResource.setIsDelete(1);
                houseResourceService.updateById(houseResource);
                break;
            case 2:
                HouseResource houseResource1 = houseResourceService.selectById(dto.getId());
                houseResource1.setStatus(0);
                houseResourceService.updateById(houseResource1);
                break;
            case 3:
                HouseResource houseResource2 = houseResourceService.selectById(dto.getId());
                houseResource2.setInsertTime(new Date());
                houseResource2.setUpTime(new Date());
                houseResourceService.updateById(houseResource2);
                break;
            case 4:
                // 判断当前房源是否有被举报的记录
                int size = reportHouseResource.selectList(new EntityWrapper<ReportHouseResource>()
                        .eq("house_resource_id", dto.getId())
                        .eq("audit", 0)).size();
                if (size>0)return ResultUtil.errorAdd("当前房源被举报,暂时不能上架");
                HouseResource houseResource3 = houseResourceService.selectById(dto.getId());
                houseResource3.setStatus(1);
                houseResource3.setAuthStatus(2);
                houseResourceService.updateById(houseResource3);
                break;
        }
        }else{
            switch (dto.getType()){
                case 1:
                    HousingDemand houseResource = housingDemandService.selectById(dto.getId());
                    houseResource.setIsDelete(1);
                    housingDemandService.updateById(houseResource);
                    break;
                case 2:
                    HousingDemand houseResource1 = housingDemandService.selectById(dto.getId());
                    houseResource1.setStatus(0);
                    housingDemandService.updateById(houseResource1);
                    break;
                case 3:
                    HousingDemand houseResource2 = housingDemandService.selectById(dto.getId());
                    houseResource2.setInsertTime(new Date());
                    houseResource2.setUpTime(new Date());
                    housingDemandService.updateById(houseResource2);
                    break;
                case 4:
                    HousingDemand houseResource3 = housingDemandService.selectById(dto.getId());
                    houseResource3.setStatus(1);
                    housingDemandService.updateById(houseResource3);
                    break;
            }
        }
 
        return ResultUtil.success();
    }
 
    // todo 放行
    @ResponseBody
    @PostMapping("/base/appUser/feedback")
    @ApiOperation(value = "意见反馈", tags = {"个人中心"})
    @ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....",
            required = true, paramType = "header")
    public ResultUtil feedback(@RequestBody FeedBack feedBack){
        AppUser appUser = appUserService.getAppUser();
        if(null != appUser && (appUser.getStatus() == 2|| appUser.getStatus() == 3)){
            return ResultUtil.errorLogin("当前账号已被冻结或删除");
        }
        feedBack.setAppUserId(appUserService.getAppUser().getId());
        feedBack.setInsertTime(new Date());
        feedBackService.insert(feedBack);
        return ResultUtil.success();
    }
 
    // todo 放行
    @ResponseBody
    @PostMapping("/base/appUser/update")
    @ApiOperation(value = "个人资料修改", tags = {"个人中心"})
    @ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....",
            required = true, paramType = "header")
    public ResultUtil update(@RequestBody UpdateAppUser user){
        AppUser appUser = appUserService.getAppUser();
        if(null != appUser && (appUser.getStatus() == 2|| appUser.getStatus() == 3)){
            return ResultUtil.errorLogin("当前账号已被冻结或删除");
        }
        if (StringUtils.hasLength(user.getProfilePhoto())){
            appUser.setProfilePhoto(user.getProfilePhoto());
        }
        if (StringUtils.hasLength(user.getNickname())){
            appUser.setNickname(user.getNickname());
        }
        appUserService.updateById(appUser);
        return ResultUtil.success();
    }
 
}