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

fix : userHashMapping 重复保存不报错

parent 0c29b91b
......@@ -4,12 +4,15 @@ import cn.quantgroup.xyqb.entity.UserHashMapping;
import cn.quantgroup.xyqb.model.UserRegisterParam;
import cn.quantgroup.xyqb.repository.IUserHashMappingRepository;
import cn.quantgroup.xyqb.util.encrypt.MD5Util;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.hibernate.exception.ConstraintViolationException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
@Component
@Slf4j
public class PhoneHashEventListener implements ApplicationListener<RegisterEvent> {
@Autowired
......@@ -40,7 +43,11 @@ public class PhoneHashEventListener implements ApplicationListener<RegisterEvent
userHashMapping.setIdNoMd5(MD5Util.build(idNo));
}
try {
userHashMappingRepository.saveAndFlush(userHashMapping);
} catch (ConstraintViolationException e) {
log.error("保存userHashMapping重复, 无需再保存, userId:{}", userId);
}
}
}
......@@ -6,10 +6,12 @@ import cn.quantgroup.xyqb.repository.IUserHashMappingRepository;
import cn.quantgroup.xyqb.util.encrypt.MD5Util;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.hibernate.exception.ConstraintViolationException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
/**
* userDetail 更新时, 保存 hashMapping 数据
*/
......@@ -46,8 +48,11 @@ public class UserDetailHashEventListener implements ApplicationListener<UserDeta
}
userHashMapping.setIdNoMd5(idNoMd5New);
try {
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