Commit c615a161 by 杨卫

feat:1047116:学习中心限制录单

1 parent 58ed6882
package cn.com.glsx.dj.riskmanage.consts;
/**
* 时间格式常量
* @author yangwei
* @version 1.0
* @since 2025/12/01 19:54
*/
public interface DatePatternConstants {
/** yyyyMMdd */
String YYYY_MM_DD = "yyyyMMdd";
}
......@@ -3,6 +3,7 @@ package cn.com.glsx.dj.riskmanage.dto.learningcenter;
import cn.com.glsx.dj.riskmanage.model.learningcenter.LearningCenterTrainingPlanPerson;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* 学员等级考试数据对象
......@@ -41,6 +42,11 @@ public class LearningCenterLevelExamPersonDTO implements Serializable {
private Integer levelId;
/**
* 等级考试创建时间
*/
private Date createdDate;
/**
* 所属等级名称
*/
private String levelName;
......
......@@ -15,6 +15,11 @@ import java.util.Map;
public enum RiskmanageErrorEnum implements ErrorEnum {
// UNKNOW_ERROR("-4000", "未知异常"),
BUSINESS_ERROR("30990504", "业务异常"),
TRAINING_PLAN_PUSH_ERROR("30990505", "培训计划未推送"),
BEI_SEN_EMPLOYEE_INFO_ERROR("30990506", "北森员工信息数据异常"),
LEVEL_EXAM_TIME_ERROR("30990507", "等级考试时间为空"),
TRAINING_PLAN_DATA_ERROR("30990508", "培训计划数据异常"),
;
private String value;
......
package cn.com.glsx.dj.riskmanage.enums.learningcenter;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* 开单权限类型 (1:锁定开单权限, 完成培训计划后开放 2:开单权限已开放, 限时锁定)
* @author yangwei
* @version 1.0
* @since 2025/12/01 19:37
*/
@Getter
@AllArgsConstructor
public enum OrderPermissionTypeEnum {
LOCK((byte) 1, "锁定开单权限, 完成培训计划后开放"),
OPEN((byte) 2, "开单权限已开放, 限时锁定");
private Byte code;
private String message;
}
......@@ -21,7 +21,13 @@ public interface PadLearningCenterRemote {
@ApiOperation("学习中心-开始测评弹窗")
@ApiMethod("学习中心-开始测评弹窗")
@ApiParam(name = "request", notes = "开始测评请求对象", dataType = ApiParam.DataTypeEnum.OBJECT, required = true)
@ApiResponse("成功")
@ApiResponse("开始测评弹窗响应对象")
RpcResponse<LearningCenterLevelExamRespDTO> learningCenterLevelExam(LearningCenterLevelExamDTO request);
@ApiOperation("学习中心-限制录单弹窗")
@ApiMethod("学习中心-限制录单弹窗")
@ApiParam(name = "request", notes = "开始测评请求对象", dataType = ApiParam.DataTypeEnum.OBJECT, required = true)
@ApiResponse("{@code true} 具备权限 {@code false} 不具备开单权限")
RpcResponse<Boolean> learningCenterPermissionOrder(LearningCenterLevelExamDTO request);
}
......@@ -42,4 +42,24 @@ public class PadLearningCenterRemoteImpl implements PadLearningCenterRemote {
}
}
/**
* 学习中心-限制录单弹窗
* @author yangwei
* @since 2025/12/1 19:03
* @param request 请求对象
* @return cn.com.glsx.framework.core.beans.rpc.RpcResponse<cn.com.glsx.dj.riskmanage.dto.learningcenter.LearningCenterLevelExamRespDTO> 响应对象
*/
@Override
public RpcResponse<Boolean> learningCenterPermissionOrder(LearningCenterLevelExamDTO request) {
try {
return RpcResponse.success(padLearningCenterService.learningCenterPermissionOrder(request));
} catch (RpcServiceException e) {
log.error("学习中心-限制录单弹窗接口调用异常!", e);
return RpcResponse.error(e);
} catch (Exception e) {
log.error("学习中心-限制录单弹窗接口调用异常!", e);
return RpcResponse.error(e);
}
}
}
package cn.com.glsx.dj.riskmanage.service.learningcenter;
import cn.com.glsx.dj.riskmanage.consts.DatePatternConstants;
import cn.com.glsx.dj.riskmanage.dto.learningcenter.LearningCenterLevelExamDTO;
import cn.com.glsx.dj.riskmanage.dto.learningcenter.LearningCenterLevelExamPersonDTO;
import cn.com.glsx.dj.riskmanage.dto.learningcenter.LearningCenterLevelExamRespDTO;
import cn.com.glsx.dj.riskmanage.enums.RiskmanageErrorEnum;
import cn.com.glsx.dj.riskmanage.enums.learningcenter.CourseTypeEnum;
import cn.com.glsx.dj.riskmanage.enums.learningcenter.FlagEnum;
import cn.com.glsx.dj.riskmanage.enums.learningcenter.OrderPermissionTypeEnum;
import cn.com.glsx.dj.riskmanage.model.learningcenter.LearningCenterTrainingPlanCourse;
import cn.com.glsx.dj.riskmanage.model.learningcenter.LearningCenterTrainingPlanPerson;
import cn.com.glsx.dj.riskmanage.util.DateUtil;
import cn.com.glsx.dj.riskmanage.util.validation.BeanValidationUtils;
import cn.com.glsx.framework.core.beans.rpc.RpcPagination;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import cn.com.glsx.framework.core.exception.RpcServiceException;
import cn.com.glsx.merchants.dto.beisen.BeiSenEmployeeListRequestDTO;
import cn.com.glsx.merchants.dto.beisen.BeiSenEmployeeListResonseDTO;
import cn.com.glsx.merchants.remote.MerchantStaffRemote;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
......@@ -60,6 +66,8 @@ public class PadLearningCenterService {
if (ObjectUtil.isNull(userTrainingPlanStage)) {
return null;
}
log.info("用户所处的培训计划:{}", userTrainingPlanStage);
Byte isCompleted = Optional.ofNullable(userTrainingPlanStage.getIsCompleted()).orElse(FlagEnum.NO.getCode().byteValue());
if (FlagEnum.YES.getCode().compareTo(isCompleted.intValue()) == 0) {
return null;
......@@ -92,8 +100,12 @@ public class PadLearningCenterService {
return null;
}
RpcPagination<BeiSenEmployeeListResonseDTO> result = beiSenUserInfoPages.getResult();
return result.getList().get(0);
List<BeiSenEmployeeListResonseDTO> personList = beiSenUserInfoPages.getResult().getList();
if (CollUtil.isEmpty(personList)) {
return null;
}
return personList.get(0);
}
......@@ -172,4 +184,72 @@ public class PadLearningCenterService {
return result;
}
/**
* pad端学习中心-权限控制-订单权限
* 限制录单弹窗
* 0. 如果当前电话号码在北森员工中不存在,则不限制开单
* 1. 获取当前学员所处的培训计划,如果培训计划为空,则不限制开单
* 2. 如果培训计划的等级考试未完成
* 2.1 如果当前培训计划开单权限不起用,则不限制开单
* 2.2 如果当前培训计划开单权限起用,则判断当前学员是否在白名单中,在白名单则不限制开单
* 2.3 如果当前培训计划开单权限起用,且不再白名单,判断是否锁定开单权限,
* 2.3.1 锁定开单权限,直接限制开单
* 2.3.2 限时锁定,获取当前用户在当前阶段的限时开单时间区间,判断当前时间是否在限时开单时间内,在则不限制开单,不在则限制开单
* 3. 等级考试已完成,则判断培训计划是否完成
* 3.1 这里直接取用户培训计划中的开单权限字段,解锁则不限制开单,锁定则限制开单
* @author yangwei
* @since 2025/12/1 19:03
* @param request 请求对象
* @return java.lang.Boolean {@code true} 具备权限 {@code false} 不具备开单权限
*/
public Boolean learningCenterPermissionOrder(LearningCenterLevelExamDTO request) {
BeanValidationUtils.validateAndThrow(request);
BeiSenEmployeeListResonseDTO beiSenEmployeeListResonseDTO = getBeiSenUserInfo(request.getStaffPhone());
if (ObjectUtil.isNull(beiSenEmployeeListResonseDTO)) {
return true;
}
LearningCenterLevelExamPersonDTO userTrainingPlanStage = getUserTrainingPlanStage(beiSenEmployeeListResonseDTO);
if (ObjectUtil.isNull(userTrainingPlanStage)) {
return true;
}
log.info("用户所处的培训计划:{}", userTrainingPlanStage);
// 等级考试已完成,取培训计划中的开单权限字段
Byte isCompleted = Optional.ofNullable(userTrainingPlanStage.getIsCompleted()).orElse(FlagEnum.NO.getCode().byteValue());
if (isCompleted.intValue() == FlagEnum.YES.getCode()) {
LearningCenterTrainingPlanPerson learningCenterTrainingPlanPerson = Optional.ofNullable(userTrainingPlanStage.getTrainingPlanPerson())
.orElseThrow(() -> new RpcServiceException(RiskmanageErrorEnum.TRAINING_PLAN_PUSH_ERROR));
return FlagEnum.YES.getCode() == learningCenterTrainingPlanPerson.getOpenOrderStatus().intValue();
}
// 等级考试未完成
Byte orderPermissionStatus = Optional.ofNullable(userTrainingPlanStage.getOrderPermissionStatus()).orElse(FlagEnum.NO.getCode().byteValue());
if (FlagEnum.NO.getCode() == orderPermissionStatus.intValue()) {
return true;
}
List<String> whites = Arrays.asList(Optional.ofNullable(userTrainingPlanStage.getWhiteList()).orElse(StrUtil.EMPTY).split(StrUtil.COMMA));
if (CollUtil.contains(whites, beiSenEmployeeListResonseDTO.getUserID())) {
return true;
}
// 立即锁定开单权限
Byte orderPermissionType = Optional.ofNullable(userTrainingPlanStage.getOrderPermissionType())
.orElseThrow(() -> new RpcServiceException(RiskmanageErrorEnum.TRAINING_PLAN_DATA_ERROR));
if (OrderPermissionTypeEnum.LOCK.getCode().equals(orderPermissionType)) {
return false;
}
// 限时锁单
Integer limitTime = Optional.ofNullable(userTrainingPlanStage.getLimitTimeParam())
.orElseThrow(() -> new RpcServiceException(RiskmanageErrorEnum.TRAINING_PLAN_DATA_ERROR));
Date levelExamPushTime = Optional.ofNullable(userTrainingPlanStage.getCreatedDate())
.orElseThrow(() -> new RpcServiceException(RiskmanageErrorEnum.TRAINING_PLAN_DATA_ERROR));
Date date = DateUtil.addDays(levelExamPushTime, limitTime);
String maxOrderTime = DateUtil.formatDate(date, DatePatternConstants.YYYY_MM_DD);
String now = DateUtil.formatDate(new Date(), DatePatternConstants.YYYY_MM_DD);
return now.compareTo(maxOrderTime) <= 0;
}
}
......@@ -345,4 +345,33 @@ public class DateUtil {
System.out.println(list);
}
/**
* 对指定日期增加指定天数
* @author yangwei
* @since 2025/12/1 19:49
* @param date 原始日期
* @param days 要增加的天数
* @return java.util.Date
*/
public static Date addDays(Date date, int days) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.DAY_OF_MONTH, days);
return calendar.getTime();
}
/**
* 将 date 对象格式化为指定格式的字符串
* @author yangwei
* @since 2025/12/1 19:50
* @param date 要格式化的日期
* @param pattern 格式模式
* @return java.lang.String 格式化后的日期字符串
*/
public static String formatDate(Date date, String pattern) {
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
return sdf.format(date);
}
}
\ No newline at end of file
......@@ -92,6 +92,7 @@
t1.is_completed AS isCompleted,
t1.level_id AS levelId,
t1.level_name AS levelName,
t1.created_date AS createdDate,
t2.id AS planId,
t2.order_permission_status AS orderPermissionStatus,
t2.order_permission_type AS orderPermissionType,
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!