Quellcode durchsuchen

添加小区调整

傅行帆 vor 6 Jahren
Ursprung
Commit
b2c6925bca

+ 4
- 0
CODE/smart-community/operate-api/src/main/java/com/community/huiju/dao/TpUserMapper.java Datei anzeigen

@@ -21,4 +21,8 @@ public interface TpUserMapper {
21 21
     TpUser selectByTel(@Param("id") Integer id,@Param("loginName") String loginName);
22 22
     
23 23
     int updateByTel(@Param("id") Integer id,@Param("loginName") String loginName,@Param("userName") String userName,@Param("oldTel") String oldTel);
24
+	
25
+	int insertUserRole(@Param("userId") Integer userId, @Param("roleId") int roleId);
26
+    
27
+    TpUser selectByLoginName(@Param("loginName") String loginName);
24 28
 }

+ 27
- 15
CODE/smart-community/operate-api/src/main/java/com/community/huiju/service/impl/CommunityServiceImpl.java Datei anzeigen

@@ -62,22 +62,34 @@ public class CommunityServiceImpl implements CommunityServiceI {
62 62
 		if (size < 1){
63 63
 			return 0;
64 64
 		}
65
+		//查询这个用户是否包含多个小区
66
+		TpUser tpUserAlread = tpUserMapper.selectByLoginName(toCommunities.getLoginName());
67
+		if (null == tpUserAlread){
68
+			//构建用户信息
69
+			TpUser tpUser = new TpUser();
70
+			tpUser.setUserName(toCommunities.getUserName());
71
+			tpUser.setLoginName(toCommunities.getLoginName());
72
+			tpUser.setCreateDate(new Date());
73
+			tpUser.setCreateUser(1);
74
+			tpUser.setStatus(Constant.EFFECTIVE);
75
+			//插入用户信息
76
+			tpUserMapper.insertSelective(tpUser);
77
+			//维护此用户的角色
78
+			tpUserMapper.insertUserRole(tpUser.getId(),1);
79
+			//维护住户端用户与社区关系表
80
+			TpUserCommunity tpUserCommunity = new TpUserCommunity();
81
+			tpUserCommunity.setTpUserId(tpUser.getId());
82
+			tpUserCommunityMapper.insertSelective(tpUserCommunity);
83
+		}else {
84
+			//维护此用户的角色
85
+			tpUserMapper.insertUserRole(tpUserAlread.getId(),1);
86
+			//维护住户端用户与社区关系表
87
+			TpUserCommunity tpUserCommunity = new TpUserCommunity();
88
+			tpUserCommunity.setTpUserId(tpUserAlread.getId());
89
+			tpUserCommunity.setCommunityId(toCommunities.getId());
90
+			tpUserCommunityMapper.insertSelective(tpUserCommunity);
91
+		}
65 92
 		
66
-		//构建用户信息
67
-		TpUser tpUser = new TpUser();
68
-		tpUser.setCommunityId(toCommunities.getId());
69
-		tpUser.setUserName(toCommunities.getUserName());
70
-		tpUser.setLoginName(toCommunities.getLoginName());
71
-		tpUser.setCreateDate(new Date());
72
-		tpUser.setCreateUser(1);
73
-		tpUser.setStatus(Constant.EFFECTIVE);
74
-		//插入用户信息
75
-		tpUserMapper.insertSelective(tpUser);
76
-		//维护住户端用户与社区关系表
77
-		TpUserCommunity tpUserCommunity = new TpUserCommunity();
78
-		tpUserCommunity.setTpUserId(tpUser.getId());
79
-		tpUserCommunity.setCommunityId(tpUser.getCommunityId());
80
-		tpUserCommunityMapper.insertSelective(tpUserCommunity);
81 93
 		return size;
82 94
 	}
83 95
 	

+ 14
- 0
CODE/smart-community/operate-api/src/main/resources/mapper/TpUserMapper.xml Datei anzeigen

@@ -207,4 +207,18 @@
207 207
     and login_name = #{oldTel,jdbcType=VARCHAR}
208 208
     and status = 1
209 209
   </update>
210
+
211
+  <insert id="insertUserRole">
212
+    insert into tp_sys_user_role (user_id,
213
+      role_id)
214
+    values (#{userId,jdbcType=INTEGER},
215
+      #{roleId,jdbcType=INTEGER})
216
+  </insert>
217
+
218
+  <select id="selectByLoginName" resultMap="BaseResultMap">
219
+    select
220
+    <include refid="Base_Column_List" />
221
+    from tp_user
222
+    where login_name = #{loginName,jdbcType=VARCHAR}
223
+  </select>
210 224
 </mapper>