Commit e8845f0e authored by xiaoguang.xu's avatar xiaoguang.xu

fix : userHashMapping 重复保存不报错

parent 0c29b91b
...@@ -4,12 +4,15 @@ import cn.quantgroup.xyqb.entity.UserHashMapping; ...@@ -4,12 +4,15 @@ 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.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;
@Component @Component
@Slf4j
public class PhoneHashEventListener implements ApplicationListener<RegisterEvent> { public class PhoneHashEventListener implements ApplicationListener<RegisterEvent> {
@Autowired @Autowired
...@@ -40,7 +43,11 @@ public class PhoneHashEventListener implements ApplicationListener<RegisterEvent ...@@ -40,7 +43,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 (ConstraintViolationException e) {
log.error("保存userHashMapping重复, 无需再保存, userId:{}", userId);
}
} }
} }
...@@ -6,10 +6,12 @@ import cn.quantgroup.xyqb.repository.IUserHashMappingRepository; ...@@ -6,10 +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;
/** /**
* userDetail 更新时, 保存 hashMapping 数据 * userDetail 更新时, 保存 hashMapping 数据
*/ */
...@@ -46,8 +48,11 @@ public class UserDetailHashEventListener implements ApplicationListener<UserDeta ...@@ -46,8 +48,11 @@ public class UserDetailHashEventListener implements ApplicationListener<UserDeta
} }
userHashMapping.setIdNoMd5(idNoMd5New); userHashMapping.setIdNoMd5(idNoMd5New);
try {
userHashMappingRepository.save(userHashMapping); userHashMappingRepository.save(userHashMapping);
} catch (ConstraintViolationException 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