Commit 4634ffb7 by 黄炜

feat: 事项-督导带教提交逻辑

1 parent f177d7da
......@@ -13,7 +13,9 @@ import cn.com.glsx.dj.staff.miniprogram.util.CommonUtil;
import cn.com.glsx.dj.staff.remote.TaskInfoRemote;
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.framework.rop.response.RopResponse;
import cn.hutool.core.date.DateUtil;
import com.rop.annotation.NeedInSessionType;
import com.rop.annotation.ServiceMethod;
import com.rop.annotation.ServiceMethodBean;
......@@ -21,10 +23,12 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.validation.Valid;
/**
* 事项(专项任务)小程序接口
......@@ -39,6 +43,8 @@ import javax.annotation.Resource;
@RequiredArgsConstructor
public class TaskCenterController {
private static final String SUPERVISOR_COACH_TASK_TYPE = "spec-coach";
private final TaskInfoRemote taskInfoRemote;
/**
......@@ -95,12 +101,70 @@ public class TaskCenterController {
@ApiOperation("专项任务回复提交")
@ServiceMethod(method = "dj.staff.api.taskcenter.task.submit", needInSession = NeedInSessionType.YES)
@PostMapping("/dj.staff.api.taskcenter.task.submit/1.0.0")
public RopResponse<Boolean> submitTaskReply(TaskSubmitRequest request) {
public RopResponse<Boolean> submitTaskReply(@Valid TaskSubmitRequest request) {
LoginUserInfoResponse loginUserInfo = CommonUtil.getLoginUserInfo();
RpcResponse<TaskInfoDTO> detailResponse = taskInfoRemote.getTaskInfoDetail(request.getId());
if (detailResponse == null || !detailResponse.isSuccess() || detailResponse.getResult() == null) {
throw new RpcServiceException("任务不存在或任务详情查询失败");
}
validateTaskSubmitRequest(request, detailResponse.getResult());
TaskInfoSubmitDTO dto = CommonUtil.convertRequest(TaskInfoSubmitDTO.class);
dto.setUpdatedBy(loginUserInfo.getName());
RpcResponse<Boolean> response = taskInfoRemote.submitTaskReply(dto);
return CommonUtil.convertRopResponse(response);
}
/**
* 按任务的真实类型校验提交页面字段,避免督导带教规则影响其他事项类型。
*/
private void validateTaskSubmitRequest(TaskSubmitRequest request, TaskInfoDTO taskInfo) {
if (!SUPERVISOR_COACH_TASK_TYPE.equals(taskInfo.getTaskType())) {
if (StringUtils.isBlank(request.getReplyContent())) {
throw new RpcServiceException("专项任务回复不能为空");
}
return;
}
if (StringUtils.isBlank(request.getAssigneeDetail())) {
throw new RpcServiceException("带教内容摘要不能为空");
}
if (StringUtils.isBlank(request.getTeachingSceneCode())
|| StringUtils.isBlank(request.getTeachingSceneName())) {
throw new RpcServiceException("请选择带教场景");
}
if (StringUtils.isBlank(request.getTeachingTime())) {
throw new RpcServiceException("请选择带教时间");
}
try {
DateUtil.parse(request.getTeachingTime(), "yyyy-MM-dd HH:mm:ss");
} catch (Exception e) {
throw new RpcServiceException("带教时间格式不正确");
}
if (StringUtils.isBlank(request.getTeachingMethodCode())
|| StringUtils.isBlank(request.getTeachingMethodName())) {
throw new RpcServiceException("请选择带教方式");
}
if (StringUtils.isBlank(request.getTeachingTopicCode())
|| StringUtils.isBlank(request.getTeachingTopicName())) {
throw new RpcServiceException("请选择带教主题");
}
if (StringUtils.isBlank(taskInfo.getTaskMerchantId())
|| StringUtils.isBlank(taskInfo.getTaskMerchantName())) {
throw new RpcServiceException("带教门店不能为空");
}
if (CollectionUtils.isEmpty(taskInfo.getTaskStaffList())
|| taskInfo.getTaskStaffList().stream().noneMatch(StringUtils::isNotBlank)) {
throw new RpcServiceException("参与人员不能为空");
}
if (CollectionUtils.isEmpty(request.getAssigneeImages())
|| request.getAssigneeImages().stream().noneMatch(StringUtils::isNotBlank)) {
throw new RpcServiceException("请上传带教照片佐证");
}
boolean hasCourseId = StringUtils.isNotBlank(request.getPushCoursesId());
boolean hasCourseName = StringUtils.isNotBlank(request.getPushCoursesName());
if (hasCourseId != hasCourseName) {
throw new RpcServiceException("推送课程ID与课程名称必须同时填写");
}
}
}
......@@ -6,6 +6,12 @@ import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.List;
/**
* 专项任务回复提交 ROP 请求(去处理页面提交)
*/
......@@ -17,20 +23,70 @@ public class TaskSubmitRequest extends AbstractRopRequest {
private static final long serialVersionUID = 1L;
@ApiModelProperty(notes = "任务主键id", required = true)
@NotNull(message = "任务id不能为空")
private Long id;
@ApiModelProperty(notes = "专项任务回复内容,1-800字符", required = true)
@Size(max = 800, message = "专项任务回复不能超过800字符")
private String replyContent;
@ApiModelProperty(notes = "是否更换:0-不更换,1-更换;人员更换评估任务必填")
@Min(value = 0, message = "是否更换参数不正确")
@Max(value = 1, message = "是否更换参数不正确")
private Integer replaceFlag;
@ApiModelProperty(notes = "更换方式:1-发起招聘需求,2-关联已有招聘需求,3-关联另一个驻店人员完成调换")
@Min(value = 1, message = "更换方式参数不正确")
@Max(value = 3, message = "更换方式参数不正确")
private Integer replaceMethod;
@ApiModelProperty(notes = "招聘需求id")
@Size(max = 64, message = "招聘需求id不能超过64字符")
private String recruitmentDemandId;
@ApiModelProperty(notes = "完成调换的驻店人员uuid")
@Size(max = 64, message = "调换驻店人员uuid不能超过64字符")
private String replacementStaffUuid;
@ApiModelProperty(notes = "带教场景编码,督导带教任务必填")
@Size(max = 32, message = "带教场景编码不能超过32字符")
private String teachingSceneCode;
@ApiModelProperty(notes = "带教场景名称,督导带教任务必填")
@Size(max = 64, message = "带教场景名称不能超过64字符")
private String teachingSceneName;
@ApiModelProperty(notes = "带教时间,格式:yyyy-MM-dd HH:mm:ss,督导带教任务必填")
private String teachingTime;
@ApiModelProperty(notes = "带教方式编码,督导带教任务必填")
@Size(max = 32, message = "带教方式编码不能超过32字符")
private String teachingMethodCode;
@ApiModelProperty(notes = "带教方式名称,督导带教任务必填")
@Size(max = 64, message = "带教方式名称不能超过64字符")
private String teachingMethodName;
@ApiModelProperty(notes = "带教主题编码,督导带教任务必填")
@Size(max = 32, message = "带教主题编码不能超过32字符")
private String teachingTopicCode;
@ApiModelProperty(notes = "带教主题名称,督导带教任务必填")
@Size(max = 64, message = "带教主题名称不能超过64字符")
private String teachingTopicName;
@ApiModelProperty(notes = "带教内容摘要,督导带教任务必填")
@Size(max = 1000, message = "带教内容摘要不能超过1000字符")
private String assigneeDetail;
@ApiModelProperty(notes = "带教照片佐证URL列表,督导带教任务必填")
private List<String> assigneeImages;
@ApiModelProperty(notes = "推送课程ID,督导带教任务选填")
@Size(max = 64, message = "推送课程ID不能超过64字符")
private String pushCoursesId;
@ApiModelProperty(notes = "推送课程名称,督导带教任务选填")
@Size(max = 255, message = "推送课程名称不能超过255字符")
private String pushCoursesName;
}
  • @wangxw1
    commented
    Master

    一、关键问题与优化建议(仅限 Top 3)

    1. 功能正确性:逻辑漏洞导致必填字段校验被绕过

    • 问题描述:在 validateTaskSubmitRequest 方法中,如果任务类型为 SUPERVISOR_COACH_TASK_TYPE(督导带教),代码会直接跳过对 replyContent(专项任务回复内容)的非空校验。根据 TaskSubmitRequest 中的 @ApiModelProperty(..., required = true) 注释说明,该字段应为必填项。当前的 if-else 结构导致督导带教任务可以提交空的回复内容,存在逻辑漏洞。
    • 优化建议:将公共字段的校验与特定任务类型的校验分离。或者更推荐的做法是,直接在 TaskSubmitRequest 的 replyContent 字段上加上 @NotBlank(message = "专项任务回复不能为空")。

    2. 可维护性与规范:Controller 层包含过多业务校验,未充分利用 JSR-303(违反阿里巴巴开发手册)

    • 问题描述:方法入参虽然使用了 @Valid 注解,但 Controller 层依然手写了近 40 行的 if-else 来校验参数(validateTaskSubmitRequest)。这违反了阿里巴巴 Java 开发手册中“Controller 层主要负责路由和参数基本校验,业务逻辑需下沉”的原则,且混合使用注解校验和硬编码校验会导致代码可读性变差、维护成本增加。
    • 优化建议:
      • 基础格式校验应全部交给 JSR-303:例如在 DTO 中使用 @NotBlank、@NotEmpty 处理空值校验。
      • 对于不同任务类型的差异化校验,建议使用 JSR-303 的分组校验(Validation Groups),或者自定义类级别的校验注解(Class-level Constraint)。
      • 若涉及关联业务逻辑的校验(如校验任务状态、人员是否存在等),应下沉至 Service 层处理。

    3. 健壮性与规范:使用泛型异常捕获及低效的日期校验方式(违反阿里巴巴开发手册)

    • 问题描述:代码中使用 try { DateUtil.parse(...) } catch (Exception e) 来校验日期格式。首先,阿里巴巴规范明确要求“不允许捕获泛型 Exception,必须捕获具体异常”;其次,利用抛出异常来做流程控制(格式校验)是非常消耗性能的反模式。
    • 优化建议:移除 try-catch 校验代码,直接在 TaskSubmitRequest 的 teachingTime 字段上使用正则表达式注解进行格式约束: java @Pattern(regexp = "^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}$", message = "带教时间格式不正确") private String teachingTime;

    二、评分明细

    评审项 满分 得分 扣分原因说明
    功能正确性与健壮性 40 32 replyContent 在特定任务类型下被绕过校验,存在逻辑漏洞(-8分)。
    安全性与潜在风险 30 27 未发现严重的安全漏洞(如注入、越权),但参数校验逻辑存在分支遗漏风险(-3分)。
    最佳实践与可维护性 20 12 Controller 过于臃肿;未充分利用 JSR-303 规范;捕获了泛型 Exception,违反阿里开发规约(-8分)。
    性能与资源利用 5 4 利用异常机制来做日期字符串的格式校验,存在不必要的性能开销(-1分)。
    提交信息质量 5 4 提交信息 feat: 事项-督导带教提交逻辑 (by huangwei) 格式尚可,但缺乏对具体改动内容的详细描述(-1分)。

    总分:79分

Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!