学习计划过期
This commit is contained in:
@@ -24,6 +24,8 @@ import com.hotwj.platform.securityManagement.hiddenDangerInspection.domain.HotHi
|
||||
import com.hotwj.platform.securityManagement.hiddenDangerInspection.mapper.HotHiddenDangerInspectionMapper;
|
||||
import com.hotwj.platform.securityManagement.securityMeeting.domain.HotSecurityMeeting;
|
||||
import com.hotwj.platform.securityManagement.securityMeeting.mapper.HotSecurityMeetingMapper;
|
||||
import com.hotwj.platform.securityManagement.training.domain.HotTraining;
|
||||
import com.hotwj.platform.securityManagement.training.mapper.HotTrainingMapper;
|
||||
import com.hotwj.platform.securityManagement.trainingParticipant.domain.HotTrainingParticipant;
|
||||
import com.hotwj.platform.securityManagement.trainingParticipant.mapper.HotTrainingParticipantMapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -61,6 +63,7 @@ public class SysFlowServiceImpl implements ISysFlowService {
|
||||
private final HotHiddenDangerInspectionMapper hotHiddenDangerInspectionMapper;
|
||||
private final HotSecurityMeetingMapper hotSecurityMeetingMapper;
|
||||
private final HotTrainingParticipantMapper hotTrainingParticipantMapper;
|
||||
private final HotTrainingMapper hotTrainingMapper;
|
||||
|
||||
// 状态常量
|
||||
private static final int STATUS_RUNNING = 0;
|
||||
@@ -250,6 +253,10 @@ public class SysFlowServiceImpl implements ISysFlowService {
|
||||
Page<SysFlowTask> page = taskMapper.selectPage(pageQuery.build(), lqw);
|
||||
|
||||
fillFlowInfo(page.getRecords());
|
||||
int removedCount = filterInvalidTrainingStudyTodos(page.getRecords());
|
||||
if (removedCount > 0) {
|
||||
page.setTotal(Math.max(0, page.getTotal() - removedCount));
|
||||
}
|
||||
|
||||
return TableDataInfo.build(page);
|
||||
}
|
||||
@@ -510,6 +517,99 @@ public class SysFlowServiceImpl implements ISysFlowService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 过滤并清理失效的培训学习待办:
|
||||
* - 计划已关闭
|
||||
* - 计划已过期
|
||||
* - 且未开启补学
|
||||
* 同时要求学员参与记录仍然有效。
|
||||
*/
|
||||
private int filterInvalidTrainingStudyTodos(List<SysFlowTask> tasks) {
|
||||
if (CollUtil.isEmpty(tasks)) {
|
||||
return 0;
|
||||
}
|
||||
List<SysFlowTask> trainingTasks = tasks.stream()
|
||||
.filter(task -> "TRAINING_STUDY".equals(task.getFlowCode()))
|
||||
.filter(task -> StrUtil.isNotBlank(task.getBusinessId()) && StrUtil.isNotBlank(task.getApproverId()))
|
||||
.toList();
|
||||
if (CollUtil.isEmpty(trainingTasks)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Set<Long> trainingIds = new HashSet<>();
|
||||
Set<String> userIds = new HashSet<>();
|
||||
for (SysFlowTask task : trainingTasks) {
|
||||
try {
|
||||
trainingIds.add(Long.valueOf(task.getBusinessId()));
|
||||
userIds.add(task.getApproverId());
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
if (CollUtil.isEmpty(trainingIds) || CollUtil.isEmpty(userIds)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Map<Long, HotTraining> trainingMap = hotTrainingMapper.selectBatchIds(trainingIds).stream()
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toMap(HotTraining::getId, training -> training));
|
||||
Set<String> participantKeys = hotTrainingParticipantMapper.selectList(
|
||||
Wrappers.<HotTrainingParticipant>lambdaQuery()
|
||||
.in(HotTrainingParticipant::getTrainingId, trainingIds)
|
||||
.in(HotTrainingParticipant::getUserId, userIds)
|
||||
.eq(HotTrainingParticipant::getIsDeleted, 0L)
|
||||
).stream()
|
||||
.filter(Objects::nonNull)
|
||||
.filter(item -> item.getTrainingId() != null && StrUtil.isNotBlank(item.getUserId()))
|
||||
.map(item -> item.getTrainingId() + "_" + item.getUserId())
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
Date now = new Date();
|
||||
List<SysFlowTask> invalidTasks = new ArrayList<>();
|
||||
for (SysFlowTask task : trainingTasks) {
|
||||
Long trainingId;
|
||||
try {
|
||||
trainingId = Long.valueOf(task.getBusinessId());
|
||||
} catch (Exception ignored) {
|
||||
invalidTasks.add(task);
|
||||
continue;
|
||||
}
|
||||
if (!participantKeys.contains(trainingId + "_" + task.getApproverId())) {
|
||||
invalidTasks.add(task);
|
||||
continue;
|
||||
}
|
||||
HotTraining training = trainingMap.get(trainingId);
|
||||
if (!isTrainingStudyAccessible(training, now)) {
|
||||
invalidTasks.add(task);
|
||||
}
|
||||
}
|
||||
|
||||
if (CollUtil.isEmpty(invalidTasks)) {
|
||||
return 0;
|
||||
}
|
||||
for (SysFlowTask task : invalidTasks) {
|
||||
deleteDirectTodo("TRAINING_STUDY", task.getBusinessId(), task.getApproverId());
|
||||
}
|
||||
tasks.removeIf(task -> invalidTasks.stream().anyMatch(invalid ->
|
||||
Objects.equals(invalid.getTaskId(), task.getTaskId())));
|
||||
return invalidTasks.size();
|
||||
}
|
||||
|
||||
private boolean isTrainingStudyAccessible(HotTraining training, Date now) {
|
||||
if (training == null) {
|
||||
return false;
|
||||
}
|
||||
if (!Objects.equals(training.getIsEnabled(), 1L)) {
|
||||
return false;
|
||||
}
|
||||
if (Objects.equals(training.getIsMakeUp(), 1L)) {
|
||||
return true;
|
||||
}
|
||||
if (training.getStartTime() == null || training.getEndTime() == null) {
|
||||
return false;
|
||||
}
|
||||
return training.getStartTime().compareTo(now) <= 0 && training.getEndTime().compareTo(now) >= 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readTask(String taskId, String userId) {
|
||||
SysFlowTask task = taskMapper.selectById(taskId);
|
||||
|
||||
@@ -23,6 +23,7 @@ import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.dromara.common.core.domain.R;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
import org.dromara.common.core.validate.AddGroup;
|
||||
import org.dromara.common.core.validate.EditGroup;
|
||||
import org.dromara.common.excel.utils.ExcelUtil;
|
||||
@@ -65,6 +66,12 @@ public class HotTrainingCourseConfigController extends BaseController {
|
||||
@GetMapping("/list")
|
||||
@Operation(summary = "分页查询企业课程配置列表")
|
||||
public TableDataInfo<HotTrainingCourseConfigVo> list(HotTrainingCourseConfigBo bo, PageQuery pageQuery) {
|
||||
if (bo.getTrainingId() != null && StringUtils.isNotBlank(bo.getUserId())
|
||||
&& !isDriverTrainingAccessible(bo.getCompanyId(), bo.getTrainingId(), bo.getUserId())) {
|
||||
TableDataInfo<HotTrainingCourseConfigVo> result = TableDataInfo.build(Collections.emptyList());
|
||||
result.setMsg("当前学习计划已关闭或已过期");
|
||||
return result;
|
||||
}
|
||||
TableDataInfo<HotTrainingCourseConfigVo> tableDataInfo = hotTrainingCourseConfigService.queryPageList(bo, pageQuery);
|
||||
List<HotTrainingCourseConfigVo> rows = tableDataInfo.getRows();
|
||||
if (rows == null || rows.isEmpty()) {
|
||||
@@ -132,6 +139,9 @@ public class HotTrainingCourseConfigController extends BaseController {
|
||||
@RequestParam Long trainingId,
|
||||
@RequestParam String userId
|
||||
) {
|
||||
if (!isDriverTrainingAccessible(companyId, trainingId, userId)) {
|
||||
return R.fail("当前学习计划已关闭或已过期");
|
||||
}
|
||||
HotTrainingVo training = hotTrainingService.queryById(trainingId);
|
||||
Long isMakeUp = training == null ? null : training.getIsMakeUp();
|
||||
|
||||
@@ -195,6 +205,36 @@ public class HotTrainingCourseConfigController extends BaseController {
|
||||
return R.ok(resp);
|
||||
}
|
||||
|
||||
private boolean isDriverTrainingAccessible(Long companyId, Long trainingId, String userId) {
|
||||
if (companyId == null || trainingId == null || StringUtils.isBlank(userId)) {
|
||||
return false;
|
||||
}
|
||||
HotTrainingVo training = hotTrainingService.queryById(trainingId);
|
||||
if (training == null || !Objects.equals(training.getCompanyId(), companyId)) {
|
||||
return false;
|
||||
}
|
||||
if (!Objects.equals(training.getIsEnabled(), 1L)) {
|
||||
return false;
|
||||
}
|
||||
HotTrainingParticipantBo participantBo = new HotTrainingParticipantBo();
|
||||
participantBo.setCompanyId(companyId);
|
||||
participantBo.setTrainingId(trainingId);
|
||||
participantBo.setUserId(userId);
|
||||
participantBo.setIsDeleted(0L);
|
||||
List<HotTrainingParticipantVo> participants = hotTrainingParticipantService.queryList(participantBo);
|
||||
if (participants == null || participants.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
if (Objects.equals(training.getIsMakeUp(), 1L)) {
|
||||
return true;
|
||||
}
|
||||
Date now = new Date();
|
||||
return training.getStartTime() != null
|
||||
&& training.getEndTime() != null
|
||||
&& training.getStartTime().compareTo(now) <= 0
|
||||
&& training.getEndTime().compareTo(now) >= 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出企业课程配置列表
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user