Kaynağa Gözat

允许修改手机号码

limin 7 yıl önce
ebeveyn
işleme
b49a0949da

+ 2 - 0
src/main/java/com/goafanti/common/dao/UserMapper.java

@@ -113,4 +113,6 @@ public interface UserMapper {
 	Integer selectByMobieAndTypeCount(String mobile);
 	
 	List<JtMessageConsumer> getAllUser();
+	
+	int getCountByMobile(User user);
 }

+ 4 - 0
src/main/java/com/goafanti/common/mapper/UserMapper.xml

@@ -1246,5 +1246,9 @@
 		and username like #{u,jdbcType=VARCHAR}
 		</if>
 	</select>
+	<!-- 验证手机号码是否重复 -->
+	<select id="getCountByMobile" parameterType="com.goafanti.common.model.User" resultType="java.lang.Integer">
+		select count(0) from user where mobile = #{mobile,jdbcType=VARCHAR} and id &lt;&gt; #{id,jdbcType=VARCHAR}
+	</select>
 
 </mapper>

+ 21 - 1
src/main/java/com/goafanti/user/controller/UserApiController.java

@@ -3,6 +3,8 @@ package com.goafanti.user.controller;
 import java.math.BigDecimal;
 import java.util.Base64;
 import java.util.UUID;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
@@ -701,9 +703,27 @@ public class UserApiController extends BaseApiController {
 		User user = new User();
 		user.setId(TokenManager.getUserId());
 		user.setIdentifyName(identifyName);
-		//user.setMobile(mobile);不修改电话号码
+		if(StringUtils.isNotEmpty(mobile)){
+			//验证手机号码格式是否正确
+			Pattern p = Pattern.compile("^[1][3,4,5,7,8][0-9]{9}$"); // 验证手机号           
+			Matcher m = p.matcher(mobile);   
+			if(!m.matches()){
+				res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"电话号码格式不对"));
+			}else{
+				//验证手机是否存在
+				int i = userService.getCountByMobile(user);
+				if(i>0){
+					res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"电话号码重复"));
+				}else{
+					user.setMobile(mobile);//修改电话号码
+				}
+			}
+		}
 		if(StringUtils.isNotBlank(email))user.setEmail(email);
 		user.setNickname(nickname);
+		if(res.getError().size()>0){
+			return res;
+		}
 		userService.updateByPrimaryKeySelective(user);
 		return res;
 	}

+ 6 - 0
src/main/java/com/goafanti/user/service/UserService.java

@@ -63,5 +63,11 @@ public interface UserService {
 	
 	Pagination<User> getUserInfo(User user, Integer pageNo, Integer pageSize);
 	
+	/**
+	 * 查看除了自己是否还有其他人使用这个号码
+	 * @param user
+	 * @return
+	 */
+	int getCountByMobile(User user);
 	
 }

+ 5 - 0
src/main/java/com/goafanti/user/service/impl/UserServiceImpl.java

@@ -241,4 +241,9 @@ public class UserServiceImpl extends BaseMybatisDao<UserMapper> implements UserS
 		params.put("user", user);
 		return  (Pagination<User>) findPage("getUserInfoList", "getUserInfoCount", params, pageNo, pageSize);
 	}
+
+	@Override
+	public int getCountByMobile(User user) {
+		return userMapper.getCountByMobile(user);
+	}
 }