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

Merge branch 'user_detail_hash' into 'master'

User detail hash

已上线

See merge request !26
parents 28ccf13c 9e90a618
...@@ -4,12 +4,16 @@ import cn.quantgroup.xyqb.entity.UserHashMapping; ...@@ -4,12 +4,16 @@ import cn.quantgroup.xyqb.entity.UserHashMapping;
import cn.quantgroup.xyqb.model.UserRegisterParam; import cn.quantgroup.xyqb.model.UserRegisterParam;
import cn.quantgroup.xyqb.repository.IUserHashMappingRepository; import cn.quantgroup.xyqb.repository.IUserHashMappingRepository;
import cn.quantgroup.xyqb.util.encrypt.MD5Util; import cn.quantgroup.xyqb.util.encrypt.MD5Util;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener; import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.persistence.PersistenceException;
@Component @Component
@Slf4j
public class PhoneHashEventListener implements ApplicationListener<RegisterEvent> { public class PhoneHashEventListener implements ApplicationListener<RegisterEvent> {
@Autowired @Autowired
...@@ -40,7 +44,11 @@ public class PhoneHashEventListener implements ApplicationListener<RegisterEvent ...@@ -40,7 +44,11 @@ public class PhoneHashEventListener implements ApplicationListener<RegisterEvent
userHashMapping.setIdNoMd5(MD5Util.build(idNo)); userHashMapping.setIdNoMd5(MD5Util.build(idNo));
} }
userHashMappingRepository.saveAndFlush(userHashMapping); try {
userHashMappingRepository.saveAndFlush(userHashMapping);
} catch (PersistenceException e) {
log.error("保存userHashMapping重复, 无需再保存, userId:{}", userId);
}
} }
} }
...@@ -4,15 +4,20 @@ import cn.quantgroup.xyqb.entity.UserDetail; ...@@ -4,15 +4,20 @@ import cn.quantgroup.xyqb.entity.UserDetail;
import cn.quantgroup.xyqb.entity.UserHashMapping; import cn.quantgroup.xyqb.entity.UserHashMapping;
import cn.quantgroup.xyqb.repository.IUserHashMappingRepository; import cn.quantgroup.xyqb.repository.IUserHashMappingRepository;
import cn.quantgroup.xyqb.util.encrypt.MD5Util; import cn.quantgroup.xyqb.util.encrypt.MD5Util;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener; import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.persistence.PersistenceException;
/** /**
* userDetail 更新时, 保存 hashMapping 数据 * userDetail 更新时, 保存 hashMapping 数据
*/ */
@Component @Component
@Slf4j
public class UserDetailHashEventListener implements ApplicationListener<UserDetailUpdateEvent> { public class UserDetailHashEventListener implements ApplicationListener<UserDetailUpdateEvent> {
@Autowired @Autowired
...@@ -25,6 +30,13 @@ public class UserDetailHashEventListener implements ApplicationListener<UserDeta ...@@ -25,6 +30,13 @@ public class UserDetailHashEventListener implements ApplicationListener<UserDeta
UserHashMapping userHashMapping = userHashMappingRepository.findByUserId(userDetail.getUserId()); UserHashMapping userHashMapping = userHashMappingRepository.findByUserId(userDetail.getUserId());
//如果不存在, 我先保存一下
if (userHashMapping == null) {
userHashMapping = new UserHashMapping(userDetail.getUserId());
String phoneNo = userDetail.getPhoneNo();
userHashMapping.setPhoneNoMd5(MD5Util.build(phoneNo));
}
String idNoMd5 = userHashMapping.getIdNoMd5(); String idNoMd5 = userHashMapping.getIdNoMd5();
String idNo = userDetail.getIdNo().toUpperCase(); String idNo = userDetail.getIdNo().toUpperCase();
...@@ -37,8 +49,11 @@ public class UserDetailHashEventListener implements ApplicationListener<UserDeta ...@@ -37,8 +49,11 @@ public class UserDetailHashEventListener implements ApplicationListener<UserDeta
} }
userHashMapping.setIdNoMd5(idNoMd5New); userHashMapping.setIdNoMd5(idNoMd5New);
try {
userHashMappingRepository.save(userHashMapping); userHashMappingRepository.save(userHashMapping);
} catch (PersistenceException e){
log.error("保存userHashMapping重复, 无需再保存, userId:{}", userDetail.getUserId());
}
} }
} }
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