chengf
2025-08-20 aab1ad64e309fa904cc9cbeba4d76b533a5b6c71
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
package com.java110.user.cmd.owner;
 
import com.alibaba.fastjson.JSONObject;
import com.java110.core.annotation.Java110Cmd;
import com.java110.core.context.CmdContextUtils;
import com.java110.core.context.ICmdDataFlowContext;
import com.java110.core.event.cmd.Cmd;
import com.java110.core.event.cmd.CmdEvent;
import com.java110.core.factory.GenerateCodeFactory;
import com.java110.dto.community.CommunityDto;
import com.java110.dto.owner.OwnerAppUserDto;
import com.java110.dto.owner.OwnerDto;
import com.java110.dto.owner.OwnerRoomRelDto;
import com.java110.dto.room.RoomDto;
import com.java110.dto.user.UserAttrDto;
import com.java110.dto.user.UserDto;
import com.java110.intf.community.ICommunityInnerServiceSMO;
import com.java110.intf.community.IRoomV1InnerServiceSMO;
import com.java110.intf.user.*;
import com.java110.po.owner.OwnerAppUserPo;
import com.java110.po.owner.OwnerPo;
import com.java110.po.user.UserPo;
import com.java110.utils.exception.CmdException;
import com.java110.utils.util.Assert;
import com.java110.utils.util.ListUtil;
import com.java110.utils.util.StringUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
 
import java.text.ParseException;
import java.util.List;
 
@Java110Cmd(serviceCode = "owner.authOwner")
public class AuthOwnerCmd extends Cmd {
 
    @Autowired
    private IOwnerAppUserV1InnerServiceSMO ownerAppUserV1InnerServiceSMOImpl;
 
    @Autowired
    private IOwnerV1InnerServiceSMO ownerV1InnerServiceSMOImpl;
 
    @Autowired
    private IRoomV1InnerServiceSMO roomV1InnerServiceSMOImpl;
 
    @Autowired
    private IUserV1InnerServiceSMO userV1InnerServiceSMOImpl;
 
    @Autowired
    private IOwnerRoomRelV1InnerServiceSMO ownerRoomRelV1InnerServiceSMOImpl;
 
    @Autowired
    private ICommunityInnerServiceSMO communityInnerServiceSMOImpl;
 
    @Autowired
    private IUserAttrV1InnerServiceSMO userAttrV1InnerServiceSMOImpl;
 
    /**
     * {"communityId":"2023052267100146","roomName":"1-1-888","roomId":"752024021967653523","link":"15509711111","ownerName":"张三","ownerTypeCd":"1001"}
     *
     * @param event   事件对象
     * @param context 请求报文数据
     * @param reqJson
     * @throws CmdException
     * @throws ParseException
     */
    @Override
    public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {
 
        Assert.hasKeyAndValue(reqJson, "communityId", "未包含小区");
        Assert.hasKeyAndValue(reqJson, "roomName", "未包含房屋");
        Assert.hasKeyAndValue(reqJson, "roomId", "未包含房屋");
        Assert.hasKeyAndValue(reqJson, "link", "未包含手机号");
//        Assert.hasKeyAndValue(reqJson, "ownerName", "未包含人员名称");
        Assert.hasKeyAndValue(reqJson, "ownerTypeCd", "未包含人员类型");
 
        //todo 根据手机号查询 是否已经认证过,如果认证过则不能再次认证
 
//        OwnerDto ownerDto = new OwnerDto();
//        ownerDto.setLink(reqJson.getString("link"));
//        ownerDto.setCommunityId(reqJson.getString("communityId"));
//        List<OwnerDto> ownerDtos = ownerV1InnerServiceSMOImpl.queryOwners(ownerDto);
//        if(ListUtil.isNull(ownerDtos)){
//            return;
//        }
 
        String userId = CmdContextUtils.getUserId(context);
        UserDto userDto = new UserDto();
        userDto.setUserId(userId);
        List<UserDto> userDtos = userV1InnerServiceSMOImpl.queryUsers(userDto);
        Assert.listOnlyOne(userDtos, "用户未登录");
        if(!StringUtils.isEmpty(userDtos.get(0).getTel())){
            if (!userDtos.get(0).getTel().equals(reqJson.getString("link"))) {
                throw new CmdException("手机号错误,不是注册时的手机号");
            }
        }
        OwnerAppUserDto ownerAppUserDto = new OwnerAppUserDto();
        //由于手机号是非必填,所有有可能查出来大量用户,所以不能使用手机号查询,要用userId查询
//        ownerAppUserDto.setLink(reqJson.getString("link"));
        ownerAppUserDto.setUserId(userId);
        ownerAppUserDto.setCommunityId(reqJson.getString("communityId"));
        ownerAppUserDto.setStates(new String[]{
                OwnerAppUserDto.STATE_AUDITING,
                OwnerAppUserDto.STATE_AUDIT_SUCCESS
        });
        List<OwnerAppUserDto> ownerAppUserDtos = ownerAppUserV1InnerServiceSMOImpl.queryOwnerAppUsers(ownerAppUserDto);
 
        if (!ListUtil.isNull(ownerAppUserDtos)) {
            throw new CmdException("已存在认证关系,请勿重复认证");
        }
 
        RoomDto roomDto = new RoomDto();
        roomDto.setRoomId(reqJson.getString("roomId"));
        roomDto.setCommunityId(reqJson.getString("communityId"));
        List<RoomDto> roomDtos = roomV1InnerServiceSMOImpl.queryRooms(roomDto);
        Assert.listOnlyOne(roomDtos, "房屋不存在");
 
        OwnerRoomRelDto ownerRoomRelDto = new OwnerRoomRelDto();
        ownerRoomRelDto.setRoomId(roomDtos.get(0).getRoomId());
        List<OwnerRoomRelDto> ownerRoomRelDtos = ownerRoomRelV1InnerServiceSMOImpl.queryOwnerRoomRels(ownerRoomRelDto);
 
        if (ListUtil.isNull(ownerRoomRelDtos)) {
            throw new CmdException("房屋未销售,请联系物业");
        }
 
 
        if (!OwnerDto.OWNER_TYPE_CD_OWNER.equals(reqJson.getString("ownerTypeCd"))) {
            return;
        }
 
        ownerAppUserDto = new OwnerAppUserDto();
        ownerAppUserDto.setMemberId(ownerRoomRelDtos.get(0).getOwnerId());
        ownerAppUserDto.setCommunityId(reqJson.getString("communityId"));
        ownerAppUserDto.setStates(new String[]{
                OwnerAppUserDto.STATE_AUDITING,
                OwnerAppUserDto.STATE_AUDIT_SUCCESS
        });
        ownerAppUserDtos = ownerAppUserV1InnerServiceSMOImpl.queryOwnerAppUsers(ownerAppUserDto);
 
        if (!ListUtil.isNull(ownerAppUserDtos)) {
            throw new CmdException("业主已经被认证");
        }
 
    }
 
    /**
     * {"communityId":"2023052267100146","roomName":"1-1-888","roomId":"752024021967653523","link":"15509711111","ownerName":"张三","ownerTypeCd":"1001"}
     *
     * @param event   事件对象
     * @param context 数据上文对象
     * @param reqJson 请求报文
     * @throws CmdException
     * @throws ParseException
     */
    @Override
    public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {
 
        String userId = CmdContextUtils.getUserId(context);
 
        CommunityDto communityDto = new CommunityDto();
        communityDto.setCommunityId(reqJson.getString("communityId"));
        List<CommunityDto> communityDtos = communityInnerServiceSMOImpl.queryCommunitys(communityDto);
        Assert.listNotNull(communityDtos, "未包含小区信息");
        CommunityDto tmpCommunityDto = communityDtos.get(0);
        OwnerAppUserPo ownerAppUserPo = new OwnerAppUserPo();
        //用userId查询是否有待认证记录,没有新增,有的话直接更新状态
        OwnerAppUserDto ownerAppUserDto = new OwnerAppUserDto();
        ownerAppUserDto.setUserId(userId);
        List<OwnerAppUserDto> ownerAppUserDtos = ownerAppUserV1InnerServiceSMOImpl.queryOwnerAppUsers(ownerAppUserDto);
        if(CollectionUtils.isEmpty(ownerAppUserDtos)){
            //状态类型,10000 审核中, 11000 待认证 ,12000 审核成功,13000 审核失败
            ownerAppUserPo.setState(OwnerAppUserDto.STATE_AUDIT_SUCCESS);
            ownerAppUserPo.setAppTypeCd("10010");
            ownerAppUserPo.setAppUserId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_appUserId));
            ownerAppUserPo.setMemberId("-1");
            ownerAppUserPo.setCommunityName(tmpCommunityDto.getName());
            ownerAppUserPo.setCommunityId(tmpCommunityDto.getCommunityId());
            ownerAppUserPo.setAppUserName(reqJson.getString("ownerName"));
            ownerAppUserPo.setAppType("WECHAT");
            ownerAppUserPo.setLink(reqJson.getString("link"));
            ownerAppUserPo.setUserId(userId);
            ownerAppUserPo.setOpenId("-1");
            ownerAppUserPo.setRoomId(reqJson.getString("roomId"));
            ownerAppUserPo.setRoomName(reqJson.getString("roomName"));
            ownerAppUserPo.setOwnerTypeCd(reqJson.getString("ownerTypeCd"));
            UserAttrDto userAttrDto = new UserAttrDto();
            userAttrDto.setUserId(userId);
            userAttrDto.setSpecCd(UserAttrDto.SPEC_OPEN_ID);
            List<UserAttrDto> userAttrDtos = userAttrV1InnerServiceSMOImpl.queryUserAttrs(userAttrDto);
            if (!ListUtil.isNull(userAttrDtos)) {
                ownerAppUserPo.setOpenId(userAttrDtos.get(0).getValue());
            }
            ownerAppUserV1InnerServiceSMOImpl.saveOwnerAppUser(ownerAppUserPo);
        }else{
            for(OwnerAppUserDto ownerAppUser : ownerAppUserDtos){
                ownerAppUserPo.setAppUserId(ownerAppUser.getAppUserId());
                ownerAppUserPo.setLink(reqJson.getString("link"));
                ownerAppUserPo.setState(OwnerAppUserDto.STATE_AUDIT_SUCCESS);
                ownerAppUserV1InnerServiceSMOImpl.updateOwnerAppUser(ownerAppUserPo);
                //更新building_owner表的link字段
                OwnerPo ownerPo = new OwnerPo();
                ownerPo.setMemberId(ownerAppUser.getMemberId());
                ownerPo.setLink(reqJson.getString("link"));
                ownerV1InnerServiceSMOImpl.updateOwner(ownerPo);
                //更新u_user的tel字段
                UserPo userPo = new UserPo();
                userPo.setUserId(ownerAppUser.getUserId());
                userPo.setTel(reqJson.getString("link"));
                userV1InnerServiceSMOImpl.updateUser(userPo);
            }
        }
    }
}