Skip to content

Commit

Permalink
fix: 调整代码
Browse files Browse the repository at this point in the history
  • Loading branch information
CarefreeState committed Oct 16, 2024
1 parent 00e129a commit 2c51669
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public interface ResourceService {

void checkImage(Long code);

void checkAndRemoveImage(Long code, Long old);
Boolean shouldRemove(Long code, Long old);

String getSystemUrl(Long code);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,12 @@ public void checkImage(Long code) {

@Override
@Transactional
public void checkAndRemoveImage(Long code, Long old) {
public Boolean shouldRemove(Long code, Long old) {
if(!code.equals(old)) {
checkImage(code);
removeKindly(old);
return Boolean.TRUE;
}
return Boolean.FALSE;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ public void submitResume(StuResumeDTO stuResumeDTO, Long userId) {
StuSimpleResumeDTO resumeDTO = stuResumeDTO.getStuSimpleResumeDTO();

// 检测
resourceService.checkAndRemoveImage(resumeDTO.getImage(), stuResume.getImage());
Long oldImage = stuResume.getImage();
Boolean shouldRemove = resourceService.shouldRemove(resumeDTO.getImage(), oldImage);

//附件列表
List<StuAttachmentDTO> stuAttachmentDTOList = stuResumeDTO.getStuAttachmentDTOList();
Expand All @@ -91,6 +92,11 @@ public void submitResume(StuResumeDTO stuResumeDTO, Long userId) {

//保存附件信息
saveStuAttachment(stuAttachmentDTOList, stuResume.getId());

// 等提交成功后再删除
if(Boolean.TRUE.equals(shouldRemove)) {
resourceService.removeKindly(oldImage);
}
}, () -> {}, simpleLockStrategy);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,15 @@ public void updateUser(Long userId, UserDTO userDTO) {
// 设置默认头像
Long avatar = userDTO.getAvatar();
UserEntity userEntity = UserConverter.INSTANCE.userDTOToUser(userDTO);
getUserById(userId).map(UserEntity::getAvatar).ifPresent(code -> {
resourceService.checkAndRemoveImage(avatar, code);
});
Long oldAvatar = getUserById(userId).map(UserEntity::getAvatar).orElse(null);
Boolean shouldRemove = resourceService.shouldRemove(avatar, oldAvatar);
// 更新
this.lambdaUpdate()
.eq(UserEntity::getId, userId)
.update(userEntity);
// 更新成功再删除
if(Boolean.TRUE.equals(shouldRemove)) {
resourceService.removeKindly(oldAvatar);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
select
c.id, c.content, c.create_time, c.update_time,
m.id m_id, m.username m_username, m.nickname m_nickname,m.email m_email,
m.phone_number m_phone_number, m.avatar m_acvtar
m.phone_number m_phone_number, m.avatar m_acvatar
from interview i
left join interview_comment c on c.interview_id = i.id and c.is_deleted = 0 and i.is_deleted = 0
left join user m on m.id = c.manager_id and m.is_deleted = 0 and c.is_deleted = 0
Expand Down

0 comments on commit 2c51669

Please sign in to comment.