|
@@ -0,0 +1,253 @@
|
|
1
|
+package com.community.huiju.service.impl;
|
|
2
|
+
|
|
3
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
4
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
5
|
+import com.community.huiju.common.base.ResponseBean;
|
|
6
|
+import com.community.huiju.dao.*;
|
|
7
|
+import com.community.huiju.enums.ResponseErrorsMessages;
|
|
8
|
+import com.community.huiju.exception.WisdomException;
|
|
9
|
+import com.community.huiju.model.*;
|
|
10
|
+import com.community.huiju.service.ITaUserVerifyService;
|
|
11
|
+import org.apache.commons.collections.CollectionUtils;
|
|
12
|
+import org.apache.http.util.Asserts;
|
|
13
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
14
|
+import org.springframework.stereotype.Service;
|
|
15
|
+import org.springframework.transaction.annotation.Transactional;
|
|
16
|
+
|
|
17
|
+import java.util.Date;
|
|
18
|
+import java.util.List;
|
|
19
|
+
|
|
20
|
+/**
|
|
21
|
+ * <p>
|
|
22
|
+ * app端用户审核表,存放用户的角色还有房产信息 服务实现类
|
|
23
|
+ * </p>
|
|
24
|
+ *
|
|
25
|
+ * @author jobob
|
|
26
|
+ * @since 2019-05-16
|
|
27
|
+ */
|
|
28
|
+@Service
|
|
29
|
+public class TaUserVerifyServiceImpl extends ServiceImpl<TaUserVerifyMapper, TaUserVerify> implements ITaUserVerifyService {
|
|
30
|
+
|
|
31
|
+ @Autowired
|
|
32
|
+ private TaUserVerifyMapper taUserVerifyMapper;
|
|
33
|
+
|
|
34
|
+ @Autowired
|
|
35
|
+ private TaUserMapper taUserMapper;
|
|
36
|
+
|
|
37
|
+ @Autowired
|
|
38
|
+ private TaSysRoleMapper taSysRoleMapper;
|
|
39
|
+
|
|
40
|
+ @Autowired
|
|
41
|
+ private TpPhaseMapper tpPhaseMapper;
|
|
42
|
+
|
|
43
|
+ @Autowired
|
|
44
|
+ private TpBuildingMapper tpBuildingMapper;
|
|
45
|
+
|
|
46
|
+ @Autowired
|
|
47
|
+ private TpUnitMapper tpUnitMapper;
|
|
48
|
+
|
|
49
|
+ @Autowired
|
|
50
|
+ private TpLevelMapper tpLevelMapper;
|
|
51
|
+
|
|
52
|
+ @Autowired
|
|
53
|
+ private TpRoomNoMapper tpRoomNoMapper;
|
|
54
|
+
|
|
55
|
+ @Autowired
|
|
56
|
+ private TpBuildingOwnerInfoMapper tpBuildingOwnerInfoMapper;
|
|
57
|
+
|
|
58
|
+ @Override
|
|
59
|
+ @Transactional(rollbackFor = Exception.class)
|
|
60
|
+ public ResponseBean addUserVerify(Integer userId, Integer roleId, Integer communityId, Integer phaseId, Integer buildingId, Integer unitId, Integer levelId, Integer roomNoId) {
|
|
61
|
+ ResponseBean responseBean = new ResponseBean();
|
|
62
|
+
|
|
63
|
+ TaUser taUser = taUserMapper.selectById(userId);
|
|
64
|
+ if (null == taUser) {
|
|
65
|
+ responseBean.addError(ResponseErrorsMessages.NOT_USER.getCode(), ResponseErrorsMessages.NOT_USER.getMsg());
|
|
66
|
+ return responseBean;
|
|
67
|
+ }
|
|
68
|
+
|
|
69
|
+ TaSysRole taSysRole = taSysRoleMapper.selectById(roleId);
|
|
70
|
+ if (null == taSysRole) {
|
|
71
|
+ responseBean.addError(ResponseErrorsMessages.NO_ROLE.getCode(), ResponseErrorsMessages.NO_ROLE.getMsg());
|
|
72
|
+ return responseBean;
|
|
73
|
+ }
|
|
74
|
+
|
|
75
|
+ QueryWrapper<TpPhase> phaseQueryWrapper = new QueryWrapper<>();
|
|
76
|
+ phaseQueryWrapper.eq("community_id", communityId);
|
|
77
|
+ phaseQueryWrapper.eq("id", phaseId);
|
|
78
|
+ TpPhase tpPhase = tpPhaseMapper.selectOne(phaseQueryWrapper);
|
|
79
|
+ if (null == tpPhase) {
|
|
80
|
+ responseBean.addError(ResponseErrorsMessages.NO_PHASE.getCode(), ResponseErrorsMessages.NO_PHASE.getMsg());
|
|
81
|
+ return responseBean;
|
|
82
|
+ }
|
|
83
|
+
|
|
84
|
+ QueryWrapper<TpBuilding> buildingQueryWrapper = new QueryWrapper<>();
|
|
85
|
+ buildingQueryWrapper.eq("community_id", communityId);
|
|
86
|
+ buildingQueryWrapper.eq("phase_id", phaseId);
|
|
87
|
+ buildingQueryWrapper.eq("id", buildingId);
|
|
88
|
+ TpBuilding tpBuilding = tpBuildingMapper.selectOne(buildingQueryWrapper);
|
|
89
|
+ if (null == tpBuilding) {
|
|
90
|
+ responseBean.addError(ResponseErrorsMessages.NO_BUILDING.getCode(), ResponseErrorsMessages.NO_BUILDING.getMsg());
|
|
91
|
+ return responseBean;
|
|
92
|
+ }
|
|
93
|
+
|
|
94
|
+ QueryWrapper<TpUnit> unitQueryWrapper = new QueryWrapper<>();
|
|
95
|
+ unitQueryWrapper.eq("community_id", communityId);
|
|
96
|
+ unitQueryWrapper.eq("phase_id", phaseId);
|
|
97
|
+ unitQueryWrapper.eq("building_id", buildingId);
|
|
98
|
+ unitQueryWrapper.eq("id", unitId);
|
|
99
|
+ TpUnit tpUnit = tpUnitMapper.selectOne(unitQueryWrapper);
|
|
100
|
+ if (null == tpUnit) {
|
|
101
|
+ responseBean.addError(ResponseErrorsMessages.NO_UNIT.getCode(), ResponseErrorsMessages.NO_UNIT.getMsg());
|
|
102
|
+ return responseBean;
|
|
103
|
+ }
|
|
104
|
+
|
|
105
|
+ QueryWrapper<TpLevel> levelQueryWrapper = new QueryWrapper<>();
|
|
106
|
+ levelQueryWrapper.eq("community_id", communityId);
|
|
107
|
+ levelQueryWrapper.eq("phase_id", phaseId);
|
|
108
|
+ levelQueryWrapper.eq("building_id", buildingId);
|
|
109
|
+ levelQueryWrapper.eq("unit_id", unitId);
|
|
110
|
+ levelQueryWrapper.eq("id", levelId);
|
|
111
|
+ TpLevel tpLevel = tpLevelMapper.selectOne(levelQueryWrapper);
|
|
112
|
+ if (null == tpLevel) {
|
|
113
|
+ responseBean.addError(ResponseErrorsMessages.NO_LEVEL.getCode(), ResponseErrorsMessages.NO_LEVEL.getMsg());
|
|
114
|
+ return responseBean;
|
|
115
|
+ }
|
|
116
|
+
|
|
117
|
+ QueryWrapper<TpRoomNo> roomNoQueryWrapper = new QueryWrapper<>();
|
|
118
|
+ roomNoQueryWrapper.eq("community_id", communityId);
|
|
119
|
+ roomNoQueryWrapper.eq("phase_id", phaseId);
|
|
120
|
+ roomNoQueryWrapper.eq("building_id", buildingId);
|
|
121
|
+ roomNoQueryWrapper.eq("unit_id", unitId);
|
|
122
|
+ roomNoQueryWrapper.eq("level_id", levelId);
|
|
123
|
+ roomNoQueryWrapper.eq("id", roomNoId);
|
|
124
|
+ TpRoomNo tpRoomNo = tpRoomNoMapper.selectOne(roomNoQueryWrapper);
|
|
125
|
+ if (null == tpRoomNo) {
|
|
126
|
+ responseBean.addError(ResponseErrorsMessages.NO_ROOM_NO.getCode(), ResponseErrorsMessages.NO_ROOM_NO.getMsg());
|
|
127
|
+ return responseBean;
|
|
128
|
+ }
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+ // 校验身份
|
|
132
|
+ verifyBuidingRole(userId, roleId, true,communityId, phaseId, buildingId, unitId, levelId, roomNoId);
|
|
133
|
+
|
|
134
|
+ // 插入房产审核表,默认审核通过
|
|
135
|
+ TaUserVerify taUserVerify = new TaUserVerify();
|
|
136
|
+ taUserVerify.setUserId(taUser.getUserId());
|
|
137
|
+ taUserVerify.setCommunityId(communityId);
|
|
138
|
+ taUserVerify.setRoleId(taSysRole.getRoleId());
|
|
139
|
+ taUserVerify.setPhaseId(tpPhase.getPhaseId());
|
|
140
|
+ taUserVerify.setPhaseName(tpPhase.getName());
|
|
141
|
+ taUserVerify.setBuildingId(tpBuilding.getBuildingId());
|
|
142
|
+ taUserVerify.setBuildingName(tpBuilding.getName());
|
|
143
|
+ taUserVerify.setUnitId(tpUnit.getUnitId());
|
|
144
|
+ taUserVerify.setUnitName(tpUnit.getName());
|
|
145
|
+ taUserVerify.setLevelId(tpLevel.getLevelId());
|
|
146
|
+ taUserVerify.setLevelName(tpLevel.getName());
|
|
147
|
+ taUserVerify.setRoomNoId(tpRoomNo.getRoomNoId());
|
|
148
|
+ taUserVerify.setRoomNoName(tpRoomNo.getName());
|
|
149
|
+ taUserVerify.setVerifyStatus("1");
|
|
150
|
+ taUserVerify.setCreateDate(new Date());
|
|
151
|
+ taUserVerify.setVerifyName("大苏");
|
|
152
|
+
|
|
153
|
+ taUserVerifyMapper.insert(taUserVerify);
|
|
154
|
+
|
|
155
|
+ // 开始插入 楼栋资料库
|
|
156
|
+ TpBuildingOwnerInfo tpBuildingOwnerInfo = new TpBuildingOwnerInfo();
|
|
157
|
+ tpBuildingOwnerInfo.setCommunityId(communityId);
|
|
158
|
+ tpBuildingOwnerInfo.setPhaseId(tpPhase.getPhaseId());
|
|
159
|
+ tpBuildingOwnerInfo.setPhaseName(tpPhase.getName());
|
|
160
|
+ tpBuildingOwnerInfo.setBuildingId(tpBuilding.getBuildingId());
|
|
161
|
+ tpBuildingOwnerInfo.setBuildingName(tpBuilding.getName());
|
|
162
|
+ tpBuildingOwnerInfo.setUnitId(tpUnit.getUnitId());
|
|
163
|
+ tpBuildingOwnerInfo.setUnitName(tpUnit.getName());
|
|
164
|
+ tpBuildingOwnerInfo.setLevelId(tpLevel.getLevelId());
|
|
165
|
+ tpBuildingOwnerInfo.setLevelName(tpLevel.getName());
|
|
166
|
+ tpBuildingOwnerInfo.setRoomNoId(tpRoomNo.getRoomNoId());
|
|
167
|
+ tpBuildingOwnerInfo.setRoomNoName(tpRoomNo.getName());
|
|
168
|
+ tpBuildingOwnerInfo.setOwnerName(taUser.getUserName());
|
|
169
|
+ tpBuildingOwnerInfo.setOwnerTel(taUser.getLoginName());
|
|
170
|
+ tpBuildingOwnerInfo.setGender(taUser.getGender());
|
|
171
|
+ tpBuildingOwnerInfo.setPairStatus("1");
|
|
172
|
+ tpBuildingOwnerInfo.setVerifyStatus("1");
|
|
173
|
+ tpBuildingOwnerInfo.setCreateDate(new Date());
|
|
174
|
+ // tpBuildingOwnerInfo.setCreateUser(taUser.getUserId());
|
|
175
|
+ tpBuildingOwnerInfo.setTaUserVerifyId(taUserVerify.getUserVerifyId());
|
|
176
|
+
|
|
177
|
+ tpBuildingOwnerInfoMapper.insert(tpBuildingOwnerInfo);
|
|
178
|
+
|
|
179
|
+ responseBean.addSuccess(taUserVerify);
|
|
180
|
+ return responseBean;
|
|
181
|
+ }
|
|
182
|
+
|
|
183
|
+ /**
|
|
184
|
+ * 检查房产是否存在业主
|
|
185
|
+ * 检查这个用户是否在这个房产存在合法角色
|
|
186
|
+ *
|
|
187
|
+ * @param userId
|
|
188
|
+ * @param roleId
|
|
189
|
+ * @param hasOwner 是否执行业主校验
|
|
190
|
+ * @param communityId
|
|
191
|
+ * @param phaseId
|
|
192
|
+ * @param buildingId
|
|
193
|
+ * @param unitId
|
|
194
|
+ * @param levelId
|
|
195
|
+ * @param roomNoId
|
|
196
|
+ */
|
|
197
|
+ private void verifyBuidingRole(Integer userId, Integer roleId, boolean hasOwner, Integer communityId, Integer phaseId, Integer buildingId, Integer unitId, Integer levelId, Integer roomNoId){
|
|
198
|
+ if (roleId == 1 && hasOwner) {
|
|
199
|
+ // 查询这个房产是否存在业主
|
|
200
|
+ TaUserVerify userVerify = taUserVerifyMapper.selectCommunityAndAddress(communityId, phaseId, buildingId, unitId, levelId, roomNoId);
|
|
201
|
+ if (null != userVerify) {
|
|
202
|
+ throw new WisdomException(ResponseErrorsMessages.EXIST_OWNER.getCode(), ResponseErrorsMessages.EXIST_OWNER.getMsg());
|
|
203
|
+ }
|
|
204
|
+ }
|
|
205
|
+
|
|
206
|
+ List<TaUserVerify> userVerifyList = taUserVerifyMapper.selectAddress(userId, communityId, phaseId, buildingId, unitId, levelId, roomNoId);
|
|
207
|
+ if (CollectionUtils.isNotEmpty(userVerifyList) && userVerifyList.size() > 0) {
|
|
208
|
+ throw new WisdomException(ResponseErrorsMessages.EXIST_BUIDDING_ROLE.getCode(), ResponseErrorsMessages.EXIST_BUIDDING_ROLE.getMsg());
|
|
209
|
+ }
|
|
210
|
+ }
|
|
211
|
+
|
|
212
|
+ @Override
|
|
213
|
+ @Transactional(rollbackFor = Exception.class)
|
|
214
|
+ public ResponseBean deleteUserVerify(Integer userId, Integer userVerifyId) {
|
|
215
|
+ ResponseBean responseBean = new ResponseBean();
|
|
216
|
+
|
|
217
|
+ // 判断用户是否存在
|
|
218
|
+ // 判断是否是这个用户关联房产
|
|
219
|
+ // 删除楼栋资料库
|
|
220
|
+
|
|
221
|
+ TaUser taUser = taUserMapper.selectById(userId);
|
|
222
|
+ if (null == taUser) {
|
|
223
|
+ responseBean.addError(ResponseErrorsMessages.NOT_USER.getCode(), ResponseErrorsMessages.NOT_USER.getMsg());
|
|
224
|
+ return responseBean;
|
|
225
|
+ }
|
|
226
|
+
|
|
227
|
+ TaUserVerify hasUserVerify = taUserVerifyMapper.selectByUserIdAndUserVerifyId(userId, userVerifyId);
|
|
228
|
+ if (null == hasUserVerify) {
|
|
229
|
+ responseBean.addError(ResponseErrorsMessages.NOT_USER_VERIFY.getCode(), ResponseErrorsMessages.NOT_USER_VERIFY.getMsg());
|
|
230
|
+ return responseBean;
|
|
231
|
+ }
|
|
232
|
+
|
|
233
|
+ this.removeById(userVerifyId);
|
|
234
|
+
|
|
235
|
+ QueryWrapper<TpBuildingOwnerInfo> buildingOwnerInfoQueryWrapper = new QueryWrapper<>();
|
|
236
|
+ buildingOwnerInfoQueryWrapper.eq("ta_user_verify_id", userVerifyId);
|
|
237
|
+ tpBuildingOwnerInfoMapper.delete(buildingOwnerInfoQueryWrapper);
|
|
238
|
+
|
|
239
|
+ responseBean.addSuccess("操作成功!");
|
|
240
|
+ return responseBean;
|
|
241
|
+ }
|
|
242
|
+
|
|
243
|
+ @Override
|
|
244
|
+ public ResponseBean getUserVerifyByUserIdAndCommunityId(Integer userId, Integer communityId) {
|
|
245
|
+ ResponseBean responseBean = new ResponseBean();
|
|
246
|
+ QueryWrapper<TaUserVerify> taUserVerifyQueryWrapper = new QueryWrapper<>();
|
|
247
|
+ taUserVerifyQueryWrapper.eq("community_id", communityId);
|
|
248
|
+ taUserVerifyQueryWrapper.eq("user_id", userId);
|
|
249
|
+ List<TaUserVerify> list = this.list(taUserVerifyQueryWrapper);
|
|
250
|
+ responseBean.addSuccess(list);
|
|
251
|
+ return responseBean;
|
|
252
|
+ }
|
|
253
|
+}
|