优化学员删除-关联数据的清空

This commit is contained in:
none 2023-05-30 16:18:01 +08:00
parent 2ad4105ea7
commit 43a80c26de
11 changed files with 52 additions and 12 deletions

View File

@ -22,7 +22,7 @@ import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
import xyz.playedu.api.event.UserDestroyEvent;
import xyz.playedu.api.service.UserService;
import xyz.playedu.api.service.*;
/**
* @Author 杭州白书科技有限公司
@ -35,8 +35,23 @@ public class UserDestroyListener {
@Autowired private UserService userService;
@Autowired private UserCourseHourRecordService userCourseHourRecordService;
@Autowired private UserCourseRecordService userCourseRecordService;
@Autowired private UserLearnDurationRecordService userLearnDurationRecordService;
@Autowired private UserLearnDurationStatsService userLearnDurationStatsService;
@Autowired private UserLoginRecordService userLoginRecordService;
@EventListener
public void updateLoginInfo(UserDestroyEvent event) {
public void remoteRelation(UserDestroyEvent event) {
userService.removeRelateDepartmentsByUserId(event.getUserId());
userCourseHourRecordService.remove(event.getUserId());
userCourseRecordService.destroy(event.getUserId());
userLearnDurationRecordService.remove(event.getUserId());
userLearnDurationStatsService.remove(event.getUserId());
userLoginRecordService.remove(event.getUserId());
}
}

View File

@ -51,6 +51,8 @@ public interface UserCourseHourRecordService extends IService<UserCourseHourReco
void remove(Integer userId, Integer courseId);
void remove(Integer userId);
void remove(Integer userId, Integer courseId, Integer hourId);
List<UserCourseHourRecordCourseCountMapper> getUserCourseHourCount(

View File

@ -45,6 +45,8 @@ public interface UserCourseRecordService extends IService<UserCourseRecord> {
void destroy(Integer userId, Integer courseId);
void destroy(Integer userId);
void removeByCourseId(Integer courseId);
List<UserCourseRecord> chunks(List<Integer> ids, List<String> fields);

View File

@ -26,4 +26,6 @@ import xyz.playedu.api.domain.UserLearnDurationRecord;
*/
public interface UserLearnDurationRecordService extends IService<UserLearnDurationRecord> {
void store(Integer userId, Integer courseId, Integer hourId, Long startTime, Long endTime);
void remove(Integer userId);
}

View File

@ -40,4 +40,6 @@ public interface UserLearnDurationStatsService extends IService<UserLearnDuratio
Long userDuration(Integer userId);
List<UserLearnDurationStats> dateBetween(Integer userId, String startAt, String endAt);
void remove(Integer userId);
}

View File

@ -35,7 +35,7 @@ public interface UserLoginRecordService extends IService<UserLoginRecord> {
String browserVersion,
String os);
void saveIpArea(Integer id, String area);
void logout(Integer userid, String jti);
void remove(Integer userId);
}

View File

@ -151,6 +151,11 @@ public class UserCourseHourRecordServiceImpl
remove(query().getWrapper().eq("user_id", userId).eq("course_id", courseId));
}
@Override
public void remove(Integer userId) {
remove(query().getWrapper().eq("user_id", userId));
}
@Override
public PaginationResult<UserCourseHourRecord> paginate(
int page, int size, UserCourseHourRecordPaginateFilter filter) {

View File

@ -138,6 +138,11 @@ public class UserCourseRecordServiceImpl
remove(query().getWrapper().in("user_id", userId).eq("course_id", courseId));
}
@Override
public void destroy(Integer userId) {
remove(query().getWrapper().in("user_id", userId));
}
@Override
public void decrease(Integer userId, Integer courseId, int count) {
UserCourseRecord record = find(userId, courseId);

View File

@ -57,4 +57,9 @@ public class UserLearnDurationRecordServiceImpl
save(record);
}
@Override
public void remove(Integer userId) {
remove(query().getWrapper().eq("user_id", userId));
}
}

View File

@ -114,4 +114,9 @@ public class UserLearnDurationStatsServiceImpl
return list(
query().getWrapper().eq("user_id", userId).between("created_date", startAt, endAt));
}
@Override
public void remove(Integer userId) {
remove(query().getWrapper().eq("user_id", userId));
}
}

View File

@ -54,14 +54,6 @@ public class UserLoginRecordServiceImpl extends ServiceImpl<UserLoginRecordMappe
return record;
}
@Override
public void saveIpArea(Integer id, String area) {
UserLoginRecord record = new UserLoginRecord();
record.setId(id);
record.setIpArea(area);
updateById(record);
}
@Override
public void logout(Integer userid, String jti) {
UserLoginRecord record =
@ -79,4 +71,9 @@ public class UserLoginRecordServiceImpl extends ServiceImpl<UserLoginRecordMappe
updateById(newRecord);
}
@Override
public void remove(Integer userId) {
remove(query().getWrapper().eq("user_id", userId));
}
}