Commit 3072205a authored by 杨锐's avatar 杨锐

使用统一md5;

批量导入数据ignore;
parent 29679ff1
package cn.quantgroup.xyqb.controller.phonenoidno;
import cn.quantgroup.xyqb.entity.UserHashPhoneNoIdNoMapping;
import cn.quantgroup.xyqb.util.encrypt.Md5Util;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
......@@ -8,7 +9,6 @@ import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.jdbc.core.BatchPreparedStatementSetter;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.util.DigestUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
......@@ -72,13 +72,13 @@ public class UserHashPhoneNoIdNoMappingController {
/* 暂存 */
userHashPhoneNoIdNoMapping.setId(rs.getLong("id"));
userHashPhoneNoIdNoMapping.setUserId(rs.getLong("user_id"));
userHashPhoneNoIdNoMapping.setPhoneNoIdNoMd5(DigestUtils.md5DigestAsHex((rs.getString("phone_no") + rs.getString("id_no")).toLowerCase().getBytes()));
userHashPhoneNoIdNoMapping.setPhoneNoIdNoMd5(Md5Util.build((rs.getString("phone_no") + rs.getString("id_no")).toLowerCase()));
userHashPhoneNoIdNoMappings.add(userHashPhoneNoIdNoMapping);
}
});
// TODO: 2019/12/13 rewriteBatchedStatements=true
if (CollectionUtils.isNotEmpty(userHashPhoneNoIdNoMappings)) {
jdbcTemplate.batchUpdate("insert into user_hash_phone_no_id_no_mapping (user_id, phone_no_id_no_md5) values (?,?)", new BatchPreparedStatementSetter() {
jdbcTemplate.batchUpdate("insert ignore into user_hash_phone_no_id_no_mapping (user_id, phone_no_id_no_md5) values (?,?)", new BatchPreparedStatementSetter() {
@Override
public void setValues(PreparedStatement ps, int i) throws SQLException {
UserHashPhoneNoIdNoMapping userHashPhoneNoIdNoMapping = userHashPhoneNoIdNoMappings.get(i);
......
......@@ -28,4 +28,16 @@ public class UserHashPhoneNoIdNoMapping {
public UserHashPhoneNoIdNoMapping(Long userId) {
this.userId = userId;
}
@PrePersist
public void prePersist() {
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
createdAt = timestamp;
updatedAt = timestamp;
}
@PreUpdate
public void preUpdate() {
updatedAt = new Timestamp(System.currentTimeMillis());
}
}
......@@ -11,7 +11,6 @@ import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
import org.springframework.util.DigestUtils;
import javax.annotation.Resource;
import javax.persistence.PersistenceException;
......@@ -42,7 +41,7 @@ public class PhoneHashEventListener implements ApplicationListener<RegisterEvent
if (StringUtils.isNotEmpty(idNo)) {
phoneNoIdNoMd5.append(idNo);
}
userHashPhoneNoIdNoMapping.setPhoneNoIdNoMd5(DigestUtils.md5DigestAsHex(phoneNoIdNoMd5.toString().toLowerCase().getBytes()));
userHashPhoneNoIdNoMapping.setPhoneNoIdNoMd5(Md5Util.build(phoneNoIdNoMd5.toString().toLowerCase()));
try {
userHashPhoneNoIdNoMappingRepository.saveAndFlush(userHashPhoneNoIdNoMapping);
} catch (PersistenceException e) {
......
......@@ -10,7 +10,6 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
import org.springframework.util.DigestUtils;
import javax.annotation.Resource;
import javax.persistence.PersistenceException;
......@@ -61,7 +60,7 @@ public class UserDetailHashEventListener implements ApplicationListener<UserDeta
}
//可能存在手机号、身份证号修改. 搞一下.
userHashPhoneNoIdNoMapping.setPhoneNoIdNoMd5(DigestUtils.md5DigestAsHex((userDetail.getPhoneNo() + userDetail.getIdNo()).toLowerCase().getBytes()));
userHashPhoneNoIdNoMapping.setPhoneNoIdNoMd5(Md5Util.build((userDetail.getPhoneNo() + userDetail.getIdNo()).toLowerCase()));
try {
userHashPhoneNoIdNoMappingRepository.save(userHashPhoneNoIdNoMapping);
......
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