Commit 9e90a618 authored by xiaoguang.xu's avatar xiaoguang.xu

fix : userHashMapping 重复保存不报错

parent e8845f0e
...@@ -6,11 +6,12 @@ import cn.quantgroup.xyqb.repository.IUserHashMappingRepository; ...@@ -6,11 +6,12 @@ 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 lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.hibernate.exception.ConstraintViolationException;
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 @Slf4j
public class PhoneHashEventListener implements ApplicationListener<RegisterEvent> { public class PhoneHashEventListener implements ApplicationListener<RegisterEvent> {
...@@ -45,7 +46,7 @@ public class PhoneHashEventListener implements ApplicationListener<RegisterEvent ...@@ -45,7 +46,7 @@ public class PhoneHashEventListener implements ApplicationListener<RegisterEvent
try { try {
userHashMappingRepository.saveAndFlush(userHashMapping); userHashMappingRepository.saveAndFlush(userHashMapping);
} catch (ConstraintViolationException e) { } catch (PersistenceException e) {
log.error("保存userHashMapping重复, 无需再保存, userId:{}", userId); log.error("保存userHashMapping重复, 无需再保存, userId:{}", userId);
} }
......
...@@ -6,11 +6,12 @@ import cn.quantgroup.xyqb.repository.IUserHashMappingRepository; ...@@ -6,11 +6,12 @@ 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 lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.hibernate.exception.ConstraintViolationException;
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 数据
...@@ -50,7 +51,7 @@ public class UserDetailHashEventListener implements ApplicationListener<UserDeta ...@@ -50,7 +51,7 @@ public class UserDetailHashEventListener implements ApplicationListener<UserDeta
userHashMapping.setIdNoMd5(idNoMd5New); userHashMapping.setIdNoMd5(idNoMd5New);
try { try {
userHashMappingRepository.save(userHashMapping); userHashMappingRepository.save(userHashMapping);
} catch (ConstraintViolationException e) { } catch (PersistenceException e){
log.error("保存userHashMapping重复, 无需再保存, userId:{}", userDetail.getUserId()); 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