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

支持身份证号和手机号前码模糊查询UserDetail列表

parent 65a95fb2
...@@ -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,24 @@ public class InnerController implements IBaseController { ...@@ -586,6 +586,24 @@ 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")
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,8 @@ import org.springframework.data.jpa.repository.Modifying; ...@@ -8,7 +9,8 @@ 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;
import cn.quantgroup.xyqb.model.UserInfo;
/** /**
* @author mengfan.feng * @author mengfan.feng
...@@ -56,4 +58,22 @@ public interface IUserDetailRepository extends JpaRepository<UserDetail, Long>, ...@@ -56,4 +58,22 @@ 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);
/**
* 按照身份证号和手机号 - 模糊查询
* @param phoneNo - 手机号
* @param idNo - 身份证号
* @return List<UserInfo>
*/
@Query(value = "select * from user u left join user_detail ud on u.id=ud.user_id where u.phone_no like ?1 and ud.id_no like ?2", nativeQuery = true)
List<UserInfo> fuzzyQuery(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;
...@@ -29,6 +28,7 @@ import cn.quantgroup.xyqb.entity.UserDetail; ...@@ -29,6 +28,7 @@ import cn.quantgroup.xyqb.entity.UserDetail;
import cn.quantgroup.xyqb.event.StatisticsEvent; import cn.quantgroup.xyqb.event.StatisticsEvent;
import cn.quantgroup.xyqb.model.Gender; import cn.quantgroup.xyqb.model.Gender;
import cn.quantgroup.xyqb.model.IdCardInfo; import cn.quantgroup.xyqb.model.IdCardInfo;
import cn.quantgroup.xyqb.model.UserInfo;
import cn.quantgroup.xyqb.repository.IUserDetailRepository; import cn.quantgroup.xyqb.repository.IUserDetailRepository;
import cn.quantgroup.xyqb.repository.IUserRepository; import cn.quantgroup.xyqb.repository.IUserRepository;
import cn.quantgroup.xyqb.service.auth.IIdCardService; import cn.quantgroup.xyqb.service.auth.IIdCardService;
...@@ -39,9 +39,9 @@ import cn.quantgroup.xyqb.util.ValidationUtil; ...@@ -39,9 +39,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 +128,20 @@ public class UserDetailServiceImpl implements IUserDetailService { ...@@ -128,14 +128,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.isEmpty(idNo)) { if (StringUtils.isNotBlank(idNo)) {
list.add(criteriaBuilder.equal(root.get("idNo").as(String.class), 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.isNotBlank(name)) {
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 +203,7 @@ public class UserDetailServiceImpl implements IUserDetailService { ...@@ -197,7 +203,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 +223,13 @@ public class UserDetailServiceImpl implements IUserDetailService { ...@@ -217,4 +223,13 @@ public class UserDetailServiceImpl implements IUserDetailService {
}); });
return userDetails; return userDetails;
} }
@Override
public List<UserDetail> fuzzyQueryByPhoneNoAndIdNo(String phoneNo, String idNo){
List<UserDetail> userDetailList = userDetailRepository.fuzzyQueryByPhoneNoAndIdNo(phoneNo, idNo);
log.info("List<UserDetail>:{}", userDetailList);
List<UserInfo> userInfoList = userDetailRepository.fuzzyQuery(phoneNo, idNo);
log.info("List<UserInfo>:{}", userInfoList);
return userDetailList;
}
} }
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