新增统一禁学判断组件
This commit is contained in:
@@ -0,0 +1,90 @@
|
|||||||
|
package com.hotwj.platform.securityManagement.training.support;
|
||||||
|
|
||||||
|
import com.hotwj.platform.config.companyBasicConfig.domain.bo.HotCompanyBasicConfigBo;
|
||||||
|
import com.hotwj.platform.config.companyBasicConfig.domain.vo.HotCompanyBasicConfigVo;
|
||||||
|
import com.hotwj.platform.config.companyBasicConfig.service.IHotCompanyBasicConfigService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.dromara.common.core.exception.ServiceException;
|
||||||
|
import org.dromara.common.core.utils.StringUtils;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.time.LocalTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.time.format.DateTimeParseException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class StudyForbidPeriodSupport {
|
||||||
|
|
||||||
|
public static final String FORBID_STUDY_MESSAGE = "当前处于禁学时间";
|
||||||
|
|
||||||
|
private static final Long STATUS_ENABLED = 1L;
|
||||||
|
private static final DateTimeFormatter TIME_FORMATTER_MINUTE = DateTimeFormatter.ofPattern("H:mm");
|
||||||
|
private static final DateTimeFormatter TIME_FORMATTER_SECOND = DateTimeFormatter.ofPattern("H:mm:ss");
|
||||||
|
|
||||||
|
private final IHotCompanyBasicConfigService companyBasicConfigService;
|
||||||
|
|
||||||
|
public void checkStudyAllowed(Long companyId) {
|
||||||
|
String forbidMessage = getForbidStudyMessage(companyId);
|
||||||
|
if (StringUtils.isNotBlank(forbidMessage)) {
|
||||||
|
throw new ServiceException(forbidMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getForbidStudyMessage(Long companyId) {
|
||||||
|
if (companyId == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
HotCompanyBasicConfigVo config = getCompanyBasicConfig(companyId);
|
||||||
|
if (config == null || !STATUS_ENABLED.equals(config.getForbidPeriodEnabled())) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (!isNowInForbidPeriod(config.getForbidStartTime(), config.getForbidEndTime())) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return FORBID_STUDY_MESSAGE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private HotCompanyBasicConfigVo getCompanyBasicConfig(Long companyId) {
|
||||||
|
HotCompanyBasicConfigBo bo = new HotCompanyBasicConfigBo();
|
||||||
|
bo.setCompanyId(companyId);
|
||||||
|
bo.setIsDeleted(0L);
|
||||||
|
List<HotCompanyBasicConfigVo> configs = companyBasicConfigService.queryList(bo);
|
||||||
|
if (configs == null || configs.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return configs.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isNowInForbidPeriod(String forbidStartTime, String forbidEndTime) {
|
||||||
|
LocalTime startTime = parseTime(forbidStartTime);
|
||||||
|
LocalTime endTime = parseTime(forbidEndTime);
|
||||||
|
if (startTime == null || endTime == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
LocalTime now = LocalTime.now();
|
||||||
|
if (startTime.equals(endTime)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (startTime.isBefore(endTime)) {
|
||||||
|
return !now.isBefore(startTime) && !now.isAfter(endTime);
|
||||||
|
}
|
||||||
|
return !now.isBefore(startTime) || !now.isAfter(endTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
private LocalTime parseTime(String value) {
|
||||||
|
if (StringUtils.isBlank(value)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return LocalTime.parse(value, TIME_FORMATTER_SECOND);
|
||||||
|
} catch (DateTimeParseException ignored) {
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return LocalTime.parse(value, TIME_FORMATTER_MINUTE);
|
||||||
|
} catch (DateTimeParseException ignored) {
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,6 +15,7 @@ import com.hotwj.platform.securityManagement.trainingCourseRecord.service.IHotTr
|
|||||||
import com.hotwj.platform.securityManagement.trainingParticipant.domain.bo.HotTrainingParticipantBo;
|
import com.hotwj.platform.securityManagement.trainingParticipant.domain.bo.HotTrainingParticipantBo;
|
||||||
import com.hotwj.platform.securityManagement.trainingParticipant.domain.vo.HotTrainingParticipantVo;
|
import com.hotwj.platform.securityManagement.trainingParticipant.domain.vo.HotTrainingParticipantVo;
|
||||||
import com.hotwj.platform.securityManagement.trainingParticipant.service.IHotTrainingParticipantService;
|
import com.hotwj.platform.securityManagement.trainingParticipant.service.IHotTrainingParticipantService;
|
||||||
|
import com.hotwj.platform.securityManagement.training.support.StudyForbidPeriodSupport;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.Parameter;
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
@@ -58,6 +59,7 @@ public class HotTrainingCourseConfigController extends BaseController {
|
|||||||
private final IHotCourseResourceService hotCourseResourceService;
|
private final IHotCourseResourceService hotCourseResourceService;
|
||||||
private final IHotTrainingParticipantService hotTrainingParticipantService;
|
private final IHotTrainingParticipantService hotTrainingParticipantService;
|
||||||
private final IHotTrainingService hotTrainingService;
|
private final IHotTrainingService hotTrainingService;
|
||||||
|
private final StudyForbidPeriodSupport studyForbidPeriodSupport;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询企业课程配置列表
|
* 查询企业课程配置列表
|
||||||
@@ -66,7 +68,6 @@ public class HotTrainingCourseConfigController extends BaseController {
|
|||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
@Operation(summary = "分页查询企业课程配置列表")
|
@Operation(summary = "分页查询企业课程配置列表")
|
||||||
public TableDataInfo<HotTrainingCourseConfigVo> list(HotTrainingCourseConfigBo bo, PageQuery pageQuery) {
|
public TableDataInfo<HotTrainingCourseConfigVo> list(HotTrainingCourseConfigBo bo, PageQuery pageQuery) {
|
||||||
// TODO
|
|
||||||
if (!Boolean.TRUE.equals(bo.getSkipIntercept()) && bo.getTrainingId() != null && StringUtils.isNotBlank(bo.getUserId())
|
if (!Boolean.TRUE.equals(bo.getSkipIntercept()) && bo.getTrainingId() != null && StringUtils.isNotBlank(bo.getUserId())
|
||||||
&& !isDriverTrainingAccessible(bo.getCompanyId(), bo.getTrainingId(), bo.getUserId())) {
|
&& !isDriverTrainingAccessible(bo.getCompanyId(), bo.getTrainingId(), bo.getUserId())) {
|
||||||
TableDataInfo<HotTrainingCourseConfigVo> result = TableDataInfo.build(Collections.emptyList());
|
TableDataInfo<HotTrainingCourseConfigVo> result = TableDataInfo.build(Collections.emptyList());
|
||||||
@@ -139,8 +140,15 @@ public class HotTrainingCourseConfigController extends BaseController {
|
|||||||
@RequestParam Long companyId,
|
@RequestParam Long companyId,
|
||||||
@RequestParam Long trainingId,
|
@RequestParam Long trainingId,
|
||||||
@RequestParam String userId,
|
@RequestParam String userId,
|
||||||
@RequestParam(required = false, defaultValue = "false") Boolean forceView
|
@RequestParam(required = false, defaultValue = "false") Boolean forceView,
|
||||||
|
@RequestParam(required = false, defaultValue = "false") Boolean checkForbidStudy
|
||||||
) {
|
) {
|
||||||
|
if (Boolean.TRUE.equals(checkForbidStudy)) {
|
||||||
|
String forbidMessage = studyForbidPeriodSupport.getForbidStudyMessage(companyId);
|
||||||
|
if (StringUtils.isNotBlank(forbidMessage)) {
|
||||||
|
return R.fail(forbidMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
if (!Boolean.TRUE.equals(forceView) && !isDriverTrainingAccessible(companyId, trainingId, userId)) {
|
if (!Boolean.TRUE.equals(forceView) && !isDriverTrainingAccessible(companyId, trainingId, userId)) {
|
||||||
return R.fail("当前学习计划已关闭或已过期");
|
return R.fail("当前学习计划已关闭或已过期");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -103,6 +103,11 @@ public class HotTrainingCourseRecordBo extends BaseEntity {
|
|||||||
*/
|
*/
|
||||||
private Long hourPackageUsedHours;
|
private Long hourPackageUsedHours;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否需要校验禁学时间:false=否 true=是
|
||||||
|
*/
|
||||||
|
private Boolean checkForbidStudy;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建者姓名
|
* 创建者姓名
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import com.hotwj.platform.securityManagement.trainingCourseRecord.domain.vo.HotT
|
|||||||
import com.hotwj.platform.securityManagement.trainingCourseRecord.domain.vo.PersonalAnnualRecordCourseVo;
|
import com.hotwj.platform.securityManagement.trainingCourseRecord.domain.vo.PersonalAnnualRecordCourseVo;
|
||||||
import com.hotwj.platform.securityManagement.trainingCourseRecord.mapper.HotTrainingCourseRecordMapper;
|
import com.hotwj.platform.securityManagement.trainingCourseRecord.mapper.HotTrainingCourseRecordMapper;
|
||||||
import com.hotwj.platform.securityManagement.trainingCourseRecord.service.IHotTrainingCourseRecordService;
|
import com.hotwj.platform.securityManagement.trainingCourseRecord.service.IHotTrainingCourseRecordService;
|
||||||
|
import com.hotwj.platform.securityManagement.training.support.StudyForbidPeriodSupport;
|
||||||
import com.hotwj.platform.securityManagement.trainingProgress.service.TrainingProgressService;
|
import com.hotwj.platform.securityManagement.trainingProgress.service.TrainingProgressService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -55,6 +56,7 @@ public class HotTrainingCourseRecordServiceImpl implements IHotTrainingCourseRec
|
|||||||
private final HotHourUsageDetailMapper hotHourUsageDetailMapper;
|
private final HotHourUsageDetailMapper hotHourUsageDetailMapper;
|
||||||
private final HotTrainingMapper hotTrainingMapper;
|
private final HotTrainingMapper hotTrainingMapper;
|
||||||
private final HotTrainingCourseConfigMapper hotTrainingCourseConfigMapper;
|
private final HotTrainingCourseConfigMapper hotTrainingCourseConfigMapper;
|
||||||
|
private final StudyForbidPeriodSupport studyForbidPeriodSupport;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询培训人员课程学习记录
|
* 查询培训人员课程学习记录
|
||||||
@@ -152,6 +154,9 @@ public class HotTrainingCourseRecordServiceImpl implements IHotTrainingCourseRec
|
|||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public Long insertByBo(HotTrainingCourseRecordBo bo) {
|
public Long insertByBo(HotTrainingCourseRecordBo bo) {
|
||||||
|
if (Boolean.TRUE.equals(bo.getCheckForbidStudy())) {
|
||||||
|
studyForbidPeriodSupport.checkStudyAllowed(bo.getCompanyId());
|
||||||
|
}
|
||||||
initHourPackageUsageFieldsForInsert(bo);
|
initHourPackageUsageFieldsForInsert(bo);
|
||||||
HotTrainingCourseRecord add = MapstructUtils.convert(bo, HotTrainingCourseRecord.class);
|
HotTrainingCourseRecord add = MapstructUtils.convert(bo, HotTrainingCourseRecord.class);
|
||||||
validEntityBeforeSave(add);
|
validEntityBeforeSave(add);
|
||||||
@@ -178,8 +183,12 @@ public class HotTrainingCourseRecordServiceImpl implements IHotTrainingCourseRec
|
|||||||
public Boolean updateByBo(HotTrainingCourseRecordBo bo) {
|
public Boolean updateByBo(HotTrainingCourseRecordBo bo) {
|
||||||
HotTrainingCourseRecord update = MapstructUtils.convert(bo, HotTrainingCourseRecord.class);
|
HotTrainingCourseRecord update = MapstructUtils.convert(bo, HotTrainingCourseRecord.class);
|
||||||
HotTrainingCourseRecord before = null;
|
HotTrainingCourseRecord before = null;
|
||||||
|
Long companyId = bo.getCompanyId();
|
||||||
if (bo.getId() != null) {
|
if (bo.getId() != null) {
|
||||||
before = baseMapper.selectById(bo.getId());
|
before = baseMapper.selectById(bo.getId());
|
||||||
|
if (companyId == null && before != null) {
|
||||||
|
companyId = before.getCompanyId();
|
||||||
|
}
|
||||||
if (before != null && before.getProgressRate() != null && update.getProgressRate() != null) {
|
if (before != null && before.getProgressRate() != null && update.getProgressRate() != null) {
|
||||||
// 仅操作单条记录时,确保视频进度单调不下降
|
// 仅操作单条记录时,确保视频进度单调不下降
|
||||||
if (update.getProgressRate().compareTo(before.getProgressRate()) < 0) {
|
if (update.getProgressRate().compareTo(before.getProgressRate()) < 0) {
|
||||||
@@ -193,6 +202,9 @@ public class HotTrainingCourseRecordServiceImpl implements IHotTrainingCourseRec
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (Boolean.TRUE.equals(bo.getCheckForbidStudy())) {
|
||||||
|
studyForbidPeriodSupport.checkStudyAllowed(companyId);
|
||||||
|
}
|
||||||
initHourPackageUsageFieldsForUpdate(update, before);
|
initHourPackageUsageFieldsForUpdate(update, before);
|
||||||
validEntityBeforeSave(update);
|
validEntityBeforeSave(update);
|
||||||
boolean ok = baseMapper.updateById(update) > 0;
|
boolean ok = baseMapper.updateById(update) > 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user