huanghongfa
2020-12-20 def38240262b4403377d4c16beac3ea048f1e658
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
package com.panzhihua.applets.api;
 
import com.panzhihua.common.model.vos.community.ComActActivityVO;
import com.panzhihua.common.model.vos.community.ComMngStructHouseVO;
import com.panzhihua.common.model.vos.user.ComMngFamilyInfoVO;
import com.panzhihua.common.model.vos.user.UserPhoneVO;
import com.panzhihua.common.service.community.CommunityService;
import com.panzhihua.common.service.user.UserService;
import com.panzhihua.common.controller.BaseController;
import com.panzhihua.common.exceptions.UnAuthenticationException;
import com.panzhihua.common.model.vos.LoginUserInfoVO;
import com.panzhihua.common.model.vos.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.util.List;
 
/**
 * @program: springcloud_k8s_panzhihuazhihuishequ
 * @description: 用户
 * @author: huang.hongfa weixin hhf9596 qq 959656820
 * @create: 2020-11-24 12:03
 **/
@RestController
@RequestMapping("/user/")
@Api(tags = {"我的模块"})
public class UserApi extends BaseController {
    @Resource
    private UserService userService;
    @Resource
    private CommunityService communityService;
 
    @ApiOperation(value = "当前登录用户信息", response = LoginUserInfoVO.class)
    @GetMapping("info")
    public R getUserInfo() {
        Long userId = this.getUserId();
        boolean empty = ObjectUtils.isEmpty(userId);
        if (empty) {
            throw new UnAuthenticationException();
        }
        R<LoginUserInfoVO> r = userService.getUserInfoByUserId(userId + "");
        if (R.isOk(r)) {
            Object data = r.getData();
            if (!ObjectUtils.isEmpty(data)) {
                LoginUserInfoVO loginUserInfoVO = (LoginUserInfoVO) data;
                R r1 = communityService.detailHouse(userId);
                if (R.isOk(r1)) {
                    Object data1 = r1.getData();
                    if (!ObjectUtils.isEmpty(data1)) {
                        loginUserInfoVO.setComMngStructHouseVOS((List<ComMngStructHouseVO>) data1);
                        r.setData(loginUserInfoVO);
                    }
                }
            }
        }
        return r;
    }
 
    @ApiOperation(value = "用户实名认证")
    @PutMapping("putuserauthentication")
    public R putUserAuthentication(@RequestBody LoginUserInfoVO loginUserInfoVO) {
        Long userId = this.getUserId();
        loginUserInfoVO.setUserId(userId);
        return userService.putUserAuthentication(loginUserInfoVO);
    }
 
    @ApiOperation(value = "修改用户手机号")
    @PutMapping("userphone")
    public R putUserphone(@RequestBody UserPhoneVO userPhoneVO) {
        Long userId = this.getUserId();
        userPhoneVO.setUserId(userId);
        R r = userService.putUserphone(userPhoneVO);
        if (R.isOk(r)) {
            communityService.putVolunteerPhone(userPhoneVO);
        }
        return r;
    }
 
    @ApiOperation(value = "修改用户手机号")
    @PutMapping("user")
    public R putUser(@RequestBody LoginUserInfoVO loginUserInfoVO) {
        Long userId = this.getUserId();
        loginUserInfoVO.setUserId(userId);
        return userService.putUser(loginUserInfoVO);
    }
 
    @ApiOperation(value = "房屋地址下拉列表")
    @GetMapping("listhouse")
    @ApiImplicitParam(name = "parentCode",value = "父级地址编码",required = false)
    public R listHouses(String parentCode) {
        Long areaId = this.getAreaId();
        if (ObjectUtils.isEmpty(parentCode)) {
            parentCode="";
        }
        return communityService.listHouses(parentCode,areaId);
    }
 
    @ApiOperation(value = "新增房屋")
    @PostMapping("houses")
    public R addHouses(@RequestBody ComMngStructHouseVO comMngStructHouseVO) {
        String houseCode = comMngStructHouseVO.getHouseCode();
        if (ObjectUtils.isEmpty(houseCode)) {
            return R.fail("房屋地址编码不能为空");
        }
        LoginUserInfoVO loginUserInfo = this.getLoginUserInfo();
        comMngStructHouseVO.setUserId(loginUserInfo.getUserId());
        comMngStructHouseVO.setAreaId(loginUserInfo.getAreaId());
        return communityService.addHouses(comMngStructHouseVO);
    }
 
    @ApiOperation(value = "家庭成员列表")
    @GetMapping("listfamily")
    public R listFamily() {
        Long userId = this.getUserId();
        return userService.listFamily(userId);
    }
 
    @ApiOperation(value = "新增家庭成员")
    @GetMapping("addfamily")
    public R addFamily(@RequestBody ComMngFamilyInfoVO comMngFamilyInfoVO) {
        Long userId = this.getUserId();
        comMngFamilyInfoVO.setUserId(userId);
        return userService.addFamily(comMngFamilyInfoVO);
    }
 
    @ApiOperation(value = "编辑家庭成员")
    @PutMapping("putfamily")
    public R putFamily(@RequestBody ComMngFamilyInfoVO comMngFamilyInfoVO) {
        Long id = comMngFamilyInfoVO.getId();
        if (null==id||0==id) {
            return R.fail("成员主键不能为空");
        }
        return userService.putFamily(comMngFamilyInfoVO);
    }
}