修复线上老数据性别

parent 2c64b6b5
......@@ -12,7 +12,9 @@ import cn.quantgroup.xyqb.util.ValidationUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
......@@ -31,6 +33,10 @@ public class UserDetailController implements IBaseController {
private IUserDetailService userDetailService;
@Autowired
private IIdCardService idCardService;
private static final Long MAX_COUNTER = 1L;
@Autowired
@Qualifier("stringRedisTemplate")
private RedisTemplate<String, String> stringRedisTemplate;
@RequestMapping("/save")
public JsonResult saveUserdetail(String idNo, String name) {
......@@ -71,4 +77,25 @@ public class UserDetailController implements IBaseController {
}
}
/**
* 修复老数据的性别
* @return
*/
@RequestMapping("/fix_user_gender")
public JsonResult fixUserGender() {
String redisLock= "fix_user_gender";
Long ret = stringRedisTemplate.opsForValue().increment(redisLock, 1L);
if (MAX_COUNTER < ret) { //重复提交
return JsonResult.buildSuccessResult("error_multisubmission",null);
}
try {
userDetailService.fixedIdNoAndGender();
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
} finally {
stringRedisTemplate.delete(redisLock);
}
return JsonResult.buildSuccessResult("开始执行",null);
}
}
......@@ -26,8 +26,8 @@ import java.io.PrintWriter;
public class RequestFilter implements Filter {
private static final String[] ALLOWED_PATTERNS = {
"/hello/**","/innerapi/**", "/user/exist", "/motan/**", "/user/register", "/user/login", "/user/register/fast","/auth/info/login",
"/user/login/fast", "/user/reset_password", "/user/exist_check","/user/center/**",
"/user_detail/**","/hello/**","/innerapi/**", "/user/exist", "/motan/**", "/user/register", "/user/login", "/user/register/fast","/auth/info/login",
"/user/login/fast","/user/reset_password", "/user/exist_check","/user/center/**",
"/jr58/**", "/app/login", "/app/login_super","/app/login2","/user/login2", "/wechat/**", "/config/**", "/api/**", "/user/exists_token","/query/**",
"/platform/api/page/return_url", "/MP_" +
"verify_AWiagUn4kZiwmTt0.txt"
......
......@@ -25,6 +25,18 @@ public interface IUserDetailRepository extends JpaRepository<UserDetail, Long>,J
@Query(value = "update user_detail set qq = ?1 where user_id = ?2", nativeQuery = true)
void updateUserQQ(String qq, Long userId);
@Transactional
@Modifying
@Query(value = "update user_detail set gender = ?1 where user_id = ?2", nativeQuery = true)
void updateGender( int gender, Long userId);
List<UserDetail> findAll(Specification<UserDetail> specification);
/**
* 修复线上身份证问题,后续误用
* @return
*/
@Modifying
@Query(value = "select * from user_detail where gender!=1 and gender!=2 and id_no is not null", nativeQuery = true)
List<UserDetail> selectUserDetailsBy();
}
......@@ -28,5 +28,12 @@ public interface IUserDetailService {
List<UserDetail> findByIdnos(List<String> idnos);
Page<UserDetail> getUserDetailsPage(List<Long> userId,List<String> phoneNos,List<String> idNos, int pageNumber, int pageSize,
String sortType);
/**
* 修复线上身份性别问题
*/
void fixedIdNoAndGender();
}
......@@ -69,4 +69,5 @@ public interface IUserService {
String contacts);
List<User> findRegisterUserByTime(String beginTime,String endTime);
}
package cn.quantgroup.xyqb.service.user.impl;
import cn.quantgroup.xyqb.controller.ExceptionHandlingController;
import cn.quantgroup.xyqb.entity.User;
import cn.quantgroup.xyqb.entity.UserDetail;
import cn.quantgroup.xyqb.model.Gender;
import cn.quantgroup.xyqb.model.UserQueryInfo;
import cn.quantgroup.xyqb.repository.IUserDetailRepository;
import cn.quantgroup.xyqb.repository.IUserRepository;
import cn.quantgroup.xyqb.service.auth.IIdCardService;
import cn.quantgroup.xyqb.service.user.IUserDetailService;
import cn.quantgroup.xyqb.service.user.vo.UserDetailVO;
import com.google.common.collect.Maps;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
......@@ -19,6 +23,8 @@ import javax.persistence.criteria.Root;
import javax.transaction.Transactional;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.data.domain.Page;
......@@ -34,11 +40,13 @@ import org.springframework.util.CollectionUtils;
*/
@Service
public class UserDetailServiceImpl implements IUserDetailService {
private static final Logger LOGGER = LoggerFactory.getLogger(UserDetailServiceImpl.class);
@Autowired
private IUserDetailRepository userDetailRepository;
@Autowired
private IUserRepository userRepository;
@Autowired
private IIdCardService idCardService;
@Override
public UserDetail findByUserId(Long userId) {
......@@ -175,4 +183,26 @@ public class UserDetailServiceImpl implements IUserDetailService {
return userDetailRepository.findAll(spec, pageRequest);
}
@Override public void fixedIdNoAndGender() {
List<UserDetail> details=userDetailRepository.selectUserDetailsBy();
if(!CollectionUtils.isEmpty(details)){
for (UserDetail detail:details){
try {
if(!idCardService.isIdCardValid(detail.getIdNo())){
LOGGER.error("修复用户老数据身份证号错误",detail.getUserId());
continue;
}
Gender gender=idCardService.getIdCardInfo(detail.getIdNo()).getGender();
if(null!=gender){
userDetailRepository.updateGender(gender.ordinal(),detail.getUserId());
}
} catch (ParseException e) {
LOGGER.error("修复用户老数据身份证号错误",detail.getUserId());
continue;
}
}
LOGGER.info("修复用户老数据身份证号完成");
}
}
}
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