Commit 6bea94c0 authored by 技术部-任文超's avatar 技术部-任文超

Merge branch '20180717-fuzzyQuery_KA' into 'master'

review



See merge request !22
parents 65a95fb2 ae4e48c1
...@@ -110,6 +110,8 @@ public interface Constants { ...@@ -110,6 +110,8 @@ public interface Constants {
* 默认随机密码长度 * 默认随机密码长度
*/ */
int RANDOM_PWD_LEN = 15; int RANDOM_PWD_LEN = 15;
/** 标准大陆身份证号长度 */
int IDNO_LENGTH = 18;
interface Channel { interface Channel {
long BAITIAO = 222L; long BAITIAO = 222L;
......
...@@ -586,6 +586,25 @@ public class InnerController implements IBaseController { ...@@ -586,6 +586,25 @@ public class InnerController implements IBaseController {
return JsonResult.buildSuccessResult("success", userDetails); return JsonResult.buildSuccessResult("success", userDetails);
} }
/**
* 按照身份证号和手机号 - 模糊查询
* @param phoneNo - 手机号
* @param idNo - 身份证号
* @return JsonResult<List<UserDetail>>
*/
@ApiOperation(httpMethod = "POST", value = "按照身份证号和手机号,模糊查询用户详情")
@RequestMapping("/user_detail/fuzzyQuery")
@TargetDataSource(type = DSType.SLAVE)
public JsonResult<List<UserDetail>> fuzzyQueryUserDetailList(@ApiParam(value = "手机号", required = true) @RequestParam(name = "phoneNo") String phoneNo,
@ApiParam(value = "身份证号", required = true) @RequestParam(name = "idNo") String idNo) {
log.info("fuzzyQueryUserDetailList, phone:{},idNo:{},ip:{}", phoneNo, idNo, getIp());
if (StringUtils.isBlank(phoneNo) && StringUtils.isBlank(idNo)) {
return JsonResult.buildErrorStateResult("至少必须满足一个条件不为空", null);
}
List<UserDetail> userDetailList = userDetailService.fuzzyQueryByPhoneNoAndIdNo(phoneNo, idNo);
return JsonResult.buildSuccessResult("success", userDetailList);
}
@RequestMapping("/user_ext_info/search/user_id") @RequestMapping("/user_ext_info/search/user_id")
@ApiOperation(httpMethod = "POST", value = "查询用户扩展信息") @ApiOperation(httpMethod = "POST", value = "查询用户扩展信息")
public JsonResult searchUserExtInfoByUserId(Long userId) { public JsonResult searchUserExtInfoByUserId(Long userId) {
......
package cn.quantgroup.xyqb.controller.external.user; package cn.quantgroup.xyqb.controller.external.user;
import java.util.Objects;
import javax.annotation.Resource;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import cn.quantgroup.xyqb.Constants; import cn.quantgroup.xyqb.Constants;
import cn.quantgroup.xyqb.aspect.accessable.IpValidator; import cn.quantgroup.xyqb.aspect.accessable.IpValidator;
import cn.quantgroup.xyqb.entity.User; import cn.quantgroup.xyqb.entity.User;
import cn.quantgroup.xyqb.model.JsonResult; import cn.quantgroup.xyqb.model.JsonResult;
import cn.quantgroup.xyqb.model.session.SessionStruct; import cn.quantgroup.xyqb.model.session.SessionStruct;
import cn.quantgroup.xyqb.service.api.IUserApiService;
import cn.quantgroup.xyqb.service.session.ISessionService; import cn.quantgroup.xyqb.service.session.ISessionService;
import cn.quantgroup.xyqb.service.user.IUserService; import cn.quantgroup.xyqb.service.user.IUserService;
import cn.quantgroup.xyqb.session.XyqbSessionContextHolder; import cn.quantgroup.xyqb.session.XyqbSessionContextHolder;
import cn.quantgroup.xyqb.util.ValidationUtil; import cn.quantgroup.xyqb.util.ValidationUtil;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.Objects;
/** /**
* Created by FrankChow on 15/12/16. * Created by FrankChow on 15/12/16.
...@@ -74,16 +77,16 @@ public class UserApiController { ...@@ -74,16 +77,16 @@ public class UserApiController {
// 判断token是否存在 // 判断token是否存在
boolean exist = stringRedisTemplate.hasKey(tokenKey) || stringRedisTemplate.hasKey(tokenKey2); boolean exist = stringRedisTemplate.hasKey(tokenKey) || stringRedisTemplate.hasKey(tokenKey2);
log.info("检查token:[{}]有效性[{}],延续生命期[{}]", token, exist, prolong); log.info("检查token:[{}]有效性[{}],延续生命期[{}]", token, exist, prolong);
/* token存在且需要延续时,进一步判断session是否有效,有效时,自动续期 */ /* token存在且需要延续时,进一步判断session是否有效,有效时,自动续期 */
if (Boolean.logicalAnd(exist, prolong)) { if (Boolean.logicalAnd(exist, prolong)) {
// 获取session信息 // 获取session信息
SessionStruct sessionStruct = XyqbSessionContextHolder.getXSessionFromRedis(token); SessionStruct sessionStruct = XyqbSessionContextHolder.getXSessionFromRedis(token);
if (Objects.isNull(sessionStruct)) { if (Objects.isNull(sessionStruct)) {
log.info("延续token:[{}]生命期,result:[{}],SessionStruct:{}", token, false, sessionStruct); log.info("延续token:[{}]生命期,result:[{}],SessionStruct:{}", token, false, sessionStruct);
/* 如果没有获取到session信息则返回错误信息 */ /* 如果没有获取到session信息则返回错误信息 */
return JsonResult.buildErrorStateResult("session invalid", token); return JsonResult.buildErrorStateResult("session invalid", token);
} else { } else {
/* 延续session生命期 */ /* 延续session生命期 */
try { try {
sessionService.persistSession(sessionStruct.getSid(), sessionStruct.getValues()); sessionService.persistSession(sessionStruct.getSid(), sessionStruct.getValues());
log.info("延续token:[{}]生命期,result:[{}]", token, true); log.info("延续token:[{}]生命期,result:[{}]", token, true);
......
package cn.quantgroup.xyqb.repository; package cn.quantgroup.xyqb.repository;
import cn.quantgroup.xyqb.entity.UserDetail; import java.util.List;
import org.springframework.data.jpa.domain.Specification; import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
...@@ -8,7 +9,7 @@ import org.springframework.data.jpa.repository.Modifying; ...@@ -8,7 +9,7 @@ import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.List; import cn.quantgroup.xyqb.entity.UserDetail;
/** /**
* @author mengfan.feng * @author mengfan.feng
...@@ -56,4 +57,13 @@ public interface IUserDetailRepository extends JpaRepository<UserDetail, Long>, ...@@ -56,4 +57,13 @@ public interface IUserDetailRepository extends JpaRepository<UserDetail, Long>,
@Query(value = "update user_detail set name=?1 where phone_no=?2", nativeQuery = true) @Query(value = "update user_detail set name=?1 where phone_no=?2", nativeQuery = true)
int updateNameByPhoneNo(String name, String phoneNo); int updateNameByPhoneNo(String name, String phoneNo);
/**
* 按照身份证号和手机号 - 模糊查询
* @param phoneNo - 手机号
* @param idNo - 身份证号
* @return List<UserDetail>
*/
@Query(value = "select * from user_detail where phone_no like ?1 and id_no like ?2", nativeQuery = true)
List<UserDetail> fuzzyQueryByPhoneNoAndIdNo(String phoneNo, String idNo);
} }
package cn.quantgroup.xyqb.repository; package cn.quantgroup.xyqb.repository;
import cn.quantgroup.xyqb.entity.User; import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.List; import cn.quantgroup.xyqb.entity.User;
/** /**
......
package cn.quantgroup.xyqb.service.user; package cn.quantgroup.xyqb.service.user;
import cn.quantgroup.xyqb.entity.UserDetail; import java.util.List;
import cn.quantgroup.xyqb.service.user.vo.UserDetailVO;
import org.springframework.dao.DataIntegrityViolationException; import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import java.util.List; import cn.quantgroup.xyqb.entity.UserDetail;
import cn.quantgroup.xyqb.service.user.vo.UserDetailVO;
/** /**
* Created by 11 on 2016/12/29. * Created by 11 on 2016/12/29.
...@@ -44,4 +45,12 @@ public interface IUserDetailService { ...@@ -44,4 +45,12 @@ public interface IUserDetailService {
int updateIdCard(String name, String idNo, String phoneNo); int updateIdCard(String name, String idNo, String phoneNo);
List<UserDetail> findByPhones(List<String> phoneNos); List<UserDetail> findByPhones(List<String> phoneNos);
/**
* 按照身份证号和手机号 - 模糊查询
* @param phoneNo - 手机号
* @param idNo - 身份证号
* @return List<UserDetail>
*/
List<UserDetail> fuzzyQueryByPhoneNoAndIdNo(String phoneNo, String idNo);
} }
package cn.quantgroup.xyqb.service.user; package cn.quantgroup.xyqb.service.user;
import cn.quantgroup.xyqb.entity.User;
import cn.quantgroup.xyqb.model.UserInfo;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import cn.quantgroup.xyqb.entity.User;
import cn.quantgroup.xyqb.model.UserInfo;
/** /**
* Created by Miraculous on 15/7/5. * Created by Miraculous on 15/7/5.
*/ */
......
...@@ -19,8 +19,7 @@ import org.springframework.stereotype.Service; ...@@ -19,8 +19,7 @@ import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import org.slf4j.Logger; import lombok.extern.slf4j.Slf4j;
import org.slf4j.LoggerFactory;
import cn.quantgroup.acolyte.buddhistscriptures.pojo.UserRealInfo; import cn.quantgroup.acolyte.buddhistscriptures.pojo.UserRealInfo;
import cn.quantgroup.xyqb.Constants; import cn.quantgroup.xyqb.Constants;
...@@ -39,9 +38,9 @@ import cn.quantgroup.xyqb.util.ValidationUtil; ...@@ -39,9 +38,9 @@ import cn.quantgroup.xyqb.util.ValidationUtil;
/** /**
* Created by 11 on 2016/12/29. * Created by 11 on 2016/12/29.
*/ */
@Slf4j
@Service @Service
public class UserDetailServiceImpl implements IUserDetailService { public class UserDetailServiceImpl implements IUserDetailService {
private static final Logger LOGGER = LoggerFactory.getLogger(UserDetailServiceImpl.class);
@Autowired @Autowired
private IUserDetailRepository userDetailRepository; private IUserDetailRepository userDetailRepository;
@Autowired @Autowired
...@@ -128,14 +127,20 @@ public class UserDetailServiceImpl implements IUserDetailService { ...@@ -128,14 +127,20 @@ public class UserDetailServiceImpl implements IUserDetailService {
private Specification<UserDetail> getSpecification(String name, String phoneNo, String idNo) { private Specification<UserDetail> getSpecification(String name, String phoneNo, String idNo) {
List<Predicate> list = new ArrayList<>(); List<Predicate> list = new ArrayList<>();
Specification<UserDetail> specification = (root, criteriaQuery, criteriaBuilder) -> { Specification<UserDetail> specification = (root, criteriaQuery, criteriaBuilder) -> {
if (!StringUtils.isEmpty(name)) { if(ValidationUtil.validatePhoneNo(phoneNo)){
list.add(criteriaBuilder.equal(root.get("name").as(String.class), name));
}
if (!StringUtils.isEmpty(phoneNo)) {
list.add(criteriaBuilder.equal(root.get(Constants.PHONE_NO).as(String.class), phoneNo)); list.add(criteriaBuilder.equal(root.get(Constants.PHONE_NO).as(String.class), phoneNo));
}else if (StringUtils.isNotBlank(phoneNo)) {
list.add(criteriaBuilder.like(root.get(Constants.PHONE_NO).as(String.class), phoneNo.concat("%")));
}
if (StringUtils.isNotBlank(idNo)) {
if(Objects.equals(Constants.IDNO_LENGTH, idNo.length())){
list.add(criteriaBuilder.equal(root.get("idNo").as(String.class), idNo));
}else{
list.add(criteriaBuilder.like(root.get("idNo").as(String.class), idNo.concat("%")));
}
} }
if (!StringUtils.isEmpty(idNo)) { if (StringUtils.isNotBlank(name)) {
list.add(criteriaBuilder.equal(root.get("idNo").as(String.class), idNo)); list.add(criteriaBuilder.equal(root.get("name").as(String.class), name));
} }
Predicate[] p = new Predicate[list.size()]; Predicate[] p = new Predicate[list.size()];
return criteriaBuilder.and(list.toArray(p)); return criteriaBuilder.and(list.toArray(p));
...@@ -197,7 +202,7 @@ public class UserDetailServiceImpl implements IUserDetailService { ...@@ -197,7 +202,7 @@ public class UserDetailServiceImpl implements IUserDetailService {
if (StringUtils.isNotBlank(idNo)) { if (StringUtils.isNotBlank(idNo)) {
IdCardInfo idCardInfo = idCardService.getIdCardInfo(idNo); IdCardInfo idCardInfo = idCardService.getIdCardInfo(idNo);
if (idCardInfo == null || !idCardInfo.isValid()) { if (idCardInfo == null || !idCardInfo.isValid()) {
LOGGER.error("用户的身份证错误,phoneNo:{},idNo:{}", phoneNo, idNo); log.error("用户的身份证错误,phoneNo:{},idNo:{}", phoneNo, idNo);
return 0; return 0;
} }
return userDetailRepository.updateIdNoByPhoneNo(idCardInfo.getIdNo(), Optional.ofNullable(idCardInfo.getGender()).orElse(Gender.UNKNOWN).ordinal(), phoneNo); return userDetailRepository.updateIdNoByPhoneNo(idCardInfo.getIdNo(), Optional.ofNullable(idCardInfo.getGender()).orElse(Gender.UNKNOWN).ordinal(), phoneNo);
...@@ -217,4 +222,10 @@ public class UserDetailServiceImpl implements IUserDetailService { ...@@ -217,4 +222,10 @@ public class UserDetailServiceImpl implements IUserDetailService {
}); });
return userDetails; return userDetails;
} }
@Override
public List<UserDetail> fuzzyQueryByPhoneNoAndIdNo(String phoneNo, String idNo){
return userDetailRepository.fuzzyQueryByPhoneNoAndIdNo(phoneNo.concat("%"), idNo.concat("%"));
}
} }
package cn.quantgroup.xyqb.util; package cn.quantgroup.xyqb.util;
import cn.quantgroup.xyqb.Constants;
import cn.quantgroup.xyqb.util.encrypt.MD5Util;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import java.util.Calendar; import java.util.Calendar;
import java.util.Objects; import java.util.Objects;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.apache.commons.lang.StringUtils;
import lombok.extern.slf4j.Slf4j;
import cn.quantgroup.xyqb.Constants;
import cn.quantgroup.xyqb.util.encrypt.MD5Util;
/** /**
* Created by Miraculous on 15/7/6. * Created by Miraculous on 15/7/6.
* 所有validate为真返回true, 否则返回false * 所有validate为真返回true, 否则返回false
...@@ -18,8 +20,8 @@ import java.util.regex.Pattern; ...@@ -18,8 +20,8 @@ import java.util.regex.Pattern;
public class ValidationUtil { public class ValidationUtil {
private static final String phoneRegExp = "^1[3456789][0-9]{9}$"; private static final String phoneRegExp = "^1[3456789][0-9]{9}$";
private static final String chineseNameRegExp = "^[\u4e00-\u9fff]+(\\.|·)?[\u4e00-\u9fff]+$"; private static final String chineseNameRegExp = "^[\u4e00-\u9fff]+((\\.|·)[\u4e00-\u9fff]+){0,2}$";
private static final String chineseNameExtendRegExp = "^[\u4dae\u4e00-\u9fff]+(\\.|·)?[\u4dae\u4e00-\u9fff]+$"; private static final String chineseNameExtendRegExp = "^[\u4dae\u4e00-\u9fff]+((\\.|·)[\u4dae\u4e00-\u9fff]+){0,2}$";
private static final String ipv4RegExp = "^((2[0-4][0-9]|25[0-5]|[01]?[0-9][0-9]?)\\.){3}(2[0-4][0-9]|25[0-5]|[01]?[0-9][0-9]?)$"; private static final String ipv4RegExp = "^((2[0-4][0-9]|25[0-5]|[01]?[0-9][0-9]?)\\.){3}(2[0-4][0-9]|25[0-5]|[01]?[0-9][0-9]?)$";
private static final String localIpv4RegExp = "^((172\\.(1[0-6]|2[0-9]|3[01]))|(192\\.168|169\\.254)|((127|10)\\.(2[0-4][0-9]|25[0-5]|[01]?[0-9][0-9]?)))(\\.(2[0-4][0-9]|25[0-5]|[01]?[0-9][0-9]?)){2}$"; private static final String localIpv4RegExp = "^((172\\.(1[0-6]|2[0-9]|3[01]))|(192\\.168|169\\.254)|((127|10)\\.(2[0-4][0-9]|25[0-5]|[01]?[0-9][0-9]?)))(\\.(2[0-4][0-9]|25[0-5]|[01]?[0-9][0-9]?)){2}$";
private static final String tokenRegExp = "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"; private static final String tokenRegExp = "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$";
......
...@@ -19,6 +19,9 @@ public class TestValidationUtil { ...@@ -19,6 +19,9 @@ public class TestValidationUtil {
{"1508964071 ","1508964071 "}, {"1508964071 ","1508964071 "},
{"16603429800","张泽浩"}, {"16603429800","张泽浩"},
{"17393151197","李小林?"}, {"17393151197","李小林?"},
{"17393151197","高晓辉.买买提"},
{"17393151197","高晓辉·喀秋莎.买买提"},
{"17393151197","高晓辉·喀秋莎"},
{"18721920553","王正\u202D"}}; {"18721920553","王正\u202D"}};
for(String[] ctc : contacts) { for(String[] ctc : contacts) {
log.info("phoneNo:[{}][{}],name:[{}][{}],name-trim:[{}][{}]", log.info("phoneNo:[{}][{}],name:[{}][{}],name-trim:[{}][{}]",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment