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

sonar--npe

parent 86aedf75
......@@ -103,18 +103,27 @@ public class ContactServiceImpl implements IContactService {
private void mergeContacts(Long userId, List<Contact> contacts) {
// 当前联系人列表
List<Contact> userContact = contactRepository.findByUserId(userId);
int userContactCount = (userContact == null) ? 0 : userContact.size();
Timestamp now = new Timestamp(System.currentTimeMillis());
for (int i = 0; i < contacts.size(); i++) {
Contact c = contacts.get(i);
c.setId(null);
c.setUserId(userId);
c.setRelation(c.getRelation() == null ? Relation.OTHER : c.getRelation());
c.setCreatedAt(now);
if(Objects.isNull(c.getRelation())){
c.setRelation(Relation.OTHER);
}
c.setUpdateAt(now);
if (userContactCount > i) {
c.setId(userContact.get(i).getId());
c.setCreatedAt(userContact.get(i).getCreatedAt() == null ? now : userContact.get(i).getCreatedAt());
if (CollectionUtils.isEmpty(userContact) || userContact.size() <= i) {
continue;
}
Contact old = userContact.get(i);
if(Objects.isNull(old)){
continue;
}
c.setId(old.getId());
if(Objects.nonNull(old.getCreatedAt())){
c.setCreatedAt(old.getCreatedAt());
}else{
c.setCreatedAt(now);
}
}
}
......
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