AuthOwnerCmd.java
9.16 KB
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
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.utils.exception.CmdException;
import com.java110.utils.util.Assert;
import com.java110.utils.util.ListUtil;
import org.springframework.beans.factory.annotation.Autowired;
import java.text.ParseException;
import java.util.List;
/**
* 业主认证命令类
* 处理业主在小程序或APP端的身份认证申请,包括业主、家庭成员等身份类型的认证
* 主要功能包括参数验证、业务逻辑校验和认证信息保存
*
* @author Java110
* @version 1.0
* @serviceCode owner.authOwner
*/
@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;
/**
* 参数验证方法
* 验证请求参数的完整性和业务逻辑的合法性,包括:
* 1. 必填参数验证
* 2. 用户身份验证
* 3. 认证关系重复性检查
* 4. 房屋信息验证
* 5. 业主身份特殊校验
*
* @param event 命令事件对象,包含事件相关信息
* @param context 数据流上下文对象,包含请求上下文信息
* @param reqJson 请求参数JSON对象,包含认证所需的所有参数
* @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", "未包含人员类型");
// 获取当前登录用户ID并验证用户信息
String userId = CmdContextUtils.getUserId(context);
UserDto userDto = new UserDto();
userDto.setUserId(userId);
List<UserDto> userDtos = userV1InnerServiceSMOImpl.queryUsers(userDto);
// 确保用户存在且唯一
Assert.listOnlyOne(userDtos, "用户未登录");
// 验证手机号是否与注册时一致
if (!userDtos.get(0).getTel().equals(reqJson.getString("link"))) {
throw new CmdException("手机号错误,不是注册时的手机号");
}
// 检查是否已存在认证关系(审核中或审核成功状态)
OwnerAppUserDto ownerAppUserDto = new OwnerAppUserDto();
ownerAppUserDto.setLink(reqJson.getString("link"));
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("业主已经被认证");
}
}
/**
* 执行业主认证命令
* 创建业主认证申请记录,包括用户信息、房屋信息、认证状态等
* 认证初始状态为"审核中",需要物业后台审核通过后方可生效
*
* @param event 命令事件对象
* @param context 数据流上下文对象
* @param reqJson 请求参数JSON对象,包含认证信息
* @throws CmdException 当命令执行失败时抛出
* @throws ParseException 当参数解析异常时抛出
*/
@Override
public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {
// 获取当前登录用户ID
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();
// 设置认证状态为审核中
ownerAppUserPo.setState(OwnerAppUserDto.STATE_AUDITING);
// 设置应用类型编码
ownerAppUserPo.setAppTypeCd("10010");
// 生成唯一应用用户ID
ownerAppUserPo.setAppUserId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_appUserId));
// 初始成员ID设为-1,审核通过后更新为实际业主ID
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);
// 初始openId设为-1,后续从用户属性中获取
ownerAppUserPo.setOpenId("-1");
// 设置房屋信息
ownerAppUserPo.setRoomId(reqJson.getString("roomId"));
ownerAppUserPo.setRoomName(reqJson.getString("roomName"));
// 设置业主类型
ownerAppUserPo.setOwnerTypeCd(reqJson.getString("ownerTypeCd"));
// 查询用户OpenID属性
UserAttrDto userAttrDto = new UserAttrDto();
userAttrDto.setUserId(userId);
userAttrDto.setSpecCd(UserAttrDto.SPEC_OPEN_ID);
List<UserAttrDto> userAttrDtos = userAttrV1InnerServiceSMOImpl.queryUserAttrs(userAttrDto);
// 如果存在OpenID,则设置到认证记录中
if (!ListUtil.isNull(userAttrDtos)) {
ownerAppUserPo.setOpenId(userAttrDtos.get(0).getValue());
}
// 保存业主认证申请记录
ownerAppUserV1InnerServiceSMOImpl.saveOwnerAppUser(ownerAppUserPo);
}
}