mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-06-29 08:55:23 +08:00
fixed: 学员课时学习记录删除线上课学习记录的更新
This commit is contained in:
parent
488c7c5c02
commit
015d8df1ac
@ -33,6 +33,7 @@ import xyz.playedu.api.constant.BPermissionConstant;
|
||||
import xyz.playedu.api.constant.CConfig;
|
||||
import xyz.playedu.api.constant.SystemConstant;
|
||||
import xyz.playedu.api.domain.*;
|
||||
import xyz.playedu.api.event.UserCourseHourRecordDestroyEvent;
|
||||
import xyz.playedu.api.event.UserDestroyEvent;
|
||||
import xyz.playedu.api.exception.NotFoundException;
|
||||
import xyz.playedu.api.middleware.BackendPermissionMiddleware;
|
||||
@ -78,6 +79,8 @@ public class UserController {
|
||||
|
||||
@Autowired private UserLearnDurationStatsService userLearnDurationStatsService;
|
||||
|
||||
@Autowired private ApplicationContext ctx;
|
||||
|
||||
@BackendPermissionMiddleware(slug = BPermissionConstant.USER_INDEX)
|
||||
@GetMapping("/index")
|
||||
public JsonResponse index(@RequestParam HashMap<String, Object> params) {
|
||||
@ -524,6 +527,7 @@ public class UserController {
|
||||
@PathVariable(name = "courseId") Integer courseId,
|
||||
@PathVariable(name = "hourId") Integer hourId) {
|
||||
userCourseHourRecordService.remove(id, courseId, hourId);
|
||||
ctx.publishEvent(new UserCourseHourRecordDestroyEvent(this, id, courseId, hourId));
|
||||
return JsonResponse.success();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2023 杭州白书科技有限公司
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package xyz.playedu.api.event;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @Author 杭州白书科技有限公司
|
||||
*
|
||||
* @create 2023/4/23 14:48
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class UserCourseHourRecordDestroyEvent extends ApplicationEvent {
|
||||
|
||||
private Integer userId;
|
||||
private Integer courseId;
|
||||
private Integer hourId;
|
||||
private Date at;
|
||||
|
||||
public UserCourseHourRecordDestroyEvent(
|
||||
Object source, Integer userId, Integer courseId, Integer hourId) {
|
||||
super(source);
|
||||
this.userId = userId;
|
||||
this.courseId = courseId;
|
||||
this.hourId = hourId;
|
||||
this.at = new Date();
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2023 杭州白书科技有限公司
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package xyz.playedu.api.listener;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import xyz.playedu.api.domain.UserCourseRecord;
|
||||
import xyz.playedu.api.event.UserCourseHourRecordDestroyEvent;
|
||||
import xyz.playedu.api.service.UserCourseRecordService;
|
||||
|
||||
/**
|
||||
* @Author 杭州白书科技有限公司
|
||||
*
|
||||
* @create 2023/4/23 14:51
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class UserCourseHourRecordDestroyListener {
|
||||
|
||||
@Autowired private UserCourseRecordService userCourseRecordService;
|
||||
|
||||
@EventListener
|
||||
public void updateUserCourseRecord(UserCourseHourRecordDestroyEvent e) {
|
||||
UserCourseRecord record = userCourseRecordService.find(e.getUserId(), e.getCourseId());
|
||||
if (record == null) {
|
||||
return;
|
||||
}
|
||||
userCourseRecordService.storeOrUpdate(
|
||||
record.getUserId(),
|
||||
record.getCourseId(),
|
||||
record.getHourCount(),
|
||||
record.getFinishedCount() - 1);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user