|
|
@@ -0,0 +1,422 @@
|
|
|
+package com.etotem.cfc.service;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
+import com.etotem.cfc.common.Result;
|
|
|
+import com.etotem.cfc.entity.ButlerEscalationOrder;
|
|
|
+import com.etotem.cfc.entity.User;
|
|
|
+import com.etotem.cfc.mapper.ButlerEscalationOrderMapper;
|
|
|
+import com.etotem.cfc.mapper.UserMapper;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 真人管家 · AI 升级工单治理宿主服务(能力键 {@code butler.escalation.handle},SC-H-01 / SC-H-04)。
|
|
|
+ *
|
|
|
+ * <p>承载「接收 AI 升级并人工介入」与「升级与应急处理」两条场景的工单治理契约:
|
|
|
+ * <ul>
|
|
|
+ * <li>工作台:按风险等级优先排序(HIGH → MEDIUM → LOW)返回工单列表;</li>
|
|
|
+ * <li>工单上下文:家长诉求 / AI 已给结论 / 风险等级 完整携带(不丢上下文);</li>
|
|
|
+ * <li>乐观锁认领:同一工单只允许一人认领(CAS on status=PENDING,他人提示「已被认领」);</li>
|
|
|
+ * <li>家庭隔离:仅本家庭工单可见/可操作,越界 403(CanHandle 语义);</li>
|
|
|
+ * <li>SLA 超时扫描:超过 SLA 未处理的工单触发二级升级提醒(TC-H-01-E);</li>
|
|
|
+ * <li>一级自处 / 二级升级(携带完整上下文);联系动作与复盘留痕。</li>
|
|
|
+ * </ul>
|
|
|
+ *
|
|
|
+ * <p>方法签名由契约测试 {@code ButlerEscalationContractTest} 反射锚定,TDD-GREEN 阶段实现为真实行为。</p>
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class ButlerEscalationService {
|
|
|
+
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(ButlerEscalationService.class);
|
|
|
+
|
|
|
+ /** 允许的联系动作类型(电话 / 消息 / 站内)。 */
|
|
|
+ private static final List<String> CONTACT_TYPES = Arrays.asList("CALL", "MESSAGE", "IN_APP");
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private ButlerEscalationOrderMapper butlerEscalationOrderMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private UserMapper userMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 工作台:按风险等级优先排序返回待认领/处理中/已升级的工单(SC-H-01 工作台,高风险优先)。
|
|
|
+ *
|
|
|
+ * @param butlerUserId 管家用户 ID
|
|
|
+ * @return 风险等级 HIGH 优先的工单列表
|
|
|
+ */
|
|
|
+ public Result<List<ButlerEscalationOrder>> list(Long butlerUserId) {
|
|
|
+ if (butlerUserId == null) {
|
|
|
+ return Result.badRequest("butlerUserId不能为空");
|
|
|
+ }
|
|
|
+ LambdaQueryWrapper<ButlerEscalationOrder> wrapper = new LambdaQueryWrapper<ButlerEscalationOrder>()
|
|
|
+ .eq(ButlerEscalationOrder::getButlerUserId, butlerUserId)
|
|
|
+ .in(ButlerEscalationOrder::getStatus,
|
|
|
+ ButlerEscalationOrder.STATUS_PENDING,
|
|
|
+ ButlerEscalationOrder.STATUS_PROCESSING,
|
|
|
+ ButlerEscalationOrder.STATUS_ESCALATED)
|
|
|
+ .last("ORDER BY FIELD(risk_level, 'HIGH', 'MEDIUM', 'LOW') ASC, created_at DESC");
|
|
|
+ List<ButlerEscalationOrder> list = butlerEscalationOrderMapper.selectList(wrapper);
|
|
|
+ return Result.success(list);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 工单详情,仅本家庭可见(越界 403)。
|
|
|
+ *
|
|
|
+ * @param workorderId 工单 ID
|
|
|
+ * @param userId 操作用户 ID
|
|
|
+ */
|
|
|
+ public Result<ButlerEscalationOrder> detail(Long workorderId, Long userId) {
|
|
|
+ if (workorderId == null) {
|
|
|
+ return Result.badRequest("workorderId不能为空");
|
|
|
+ }
|
|
|
+ ButlerEscalationOrder order = butlerEscalationOrderMapper.selectById(workorderId);
|
|
|
+ if (order == null) {
|
|
|
+ return Result.notFound("工单不存在");
|
|
|
+ }
|
|
|
+ if (!canHandle(workorderId, userId)) {
|
|
|
+ return Result.forbidden("仅本家庭工单可查看");
|
|
|
+ }
|
|
|
+ return Result.success(order);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 乐观锁认领:同一工单只允许一人认领,他人提示「已被认领」(TC-H-01-E)。
|
|
|
+ *
|
|
|
+ * <p>CAS 语义:仅在 status=PENDING(仍无人认领)时原子更新为本人 PROCESSING;
|
|
|
+ * 并发下仅一个管家成功,其余更新行数为 0 → 409「已被认领」。</p>
|
|
|
+ *
|
|
|
+ * @param workorderId 工单 ID
|
|
|
+ * @param butlerUserId 认领管家用户 ID
|
|
|
+ */
|
|
|
+ @Transactional
|
|
|
+ public Result<String> claim(Long workorderId, Long butlerUserId) {
|
|
|
+ if (workorderId == null || butlerUserId == null) {
|
|
|
+ return Result.badRequest("workorderId和butlerUserId不能为空");
|
|
|
+ }
|
|
|
+ ButlerEscalationOrder order = butlerEscalationOrderMapper.selectById(workorderId);
|
|
|
+ if (order == null) {
|
|
|
+ return Result.notFound("工单不存在");
|
|
|
+ }
|
|
|
+ if (!ButlerEscalationOrder.STATUS_PENDING.equals(order.getStatus())) {
|
|
|
+ if (butlerUserId.equals(order.getButlerUserId())) {
|
|
|
+ return Result.error("该工单已被你认领");
|
|
|
+ }
|
|
|
+ return Result.conflict("该工单已被认领");
|
|
|
+ }
|
|
|
+ int rows = butlerEscalationOrderMapper.update(null,
|
|
|
+ new LambdaUpdateWrapper<ButlerEscalationOrder>()
|
|
|
+ .eq(ButlerEscalationOrder::getId, workorderId)
|
|
|
+ .eq(ButlerEscalationOrder::getStatus, ButlerEscalationOrder.STATUS_PENDING)
|
|
|
+ .set(ButlerEscalationOrder::getButlerUserId, butlerUserId)
|
|
|
+ .set(ButlerEscalationOrder::getStatus, ButlerEscalationOrder.STATUS_PROCESSING)
|
|
|
+ .set(ButlerEscalationOrder::getClaimedAt, new Date())
|
|
|
+ .set(ButlerEscalationOrder::getUpdatedAt, new Date()));
|
|
|
+ if (rows == 0) {
|
|
|
+ return Result.conflict("该工单已被认领");
|
|
|
+ }
|
|
|
+ log.info("管家 {} 认领升级工单 {}(CAS 成功),状态 PENDING→PROCESSING", butlerUserId, workorderId);
|
|
|
+ return Result.success("认领成功", null);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 记录联系动作留痕(电话/消息/站内),TC-H-01 步骤 3。
|
|
|
+ *
|
|
|
+ * @param workorderId 工单 ID
|
|
|
+ * @param contactType 联系类型 CALL/MESSAGE/IN_APP
|
|
|
+ * @param content 联系内容
|
|
|
+ * @param userId 操作用户 ID
|
|
|
+ */
|
|
|
+ @Transactional
|
|
|
+ public Result<String> logContact(Long workorderId, String contactType, String content, Long userId) {
|
|
|
+ if (workorderId == null || contactType == null || contactType.trim().isEmpty()) {
|
|
|
+ return Result.badRequest("workorderId和contactType不能为空");
|
|
|
+ }
|
|
|
+ if (!CONTACT_TYPES.contains(contactType)) {
|
|
|
+ return Result.badRequest("contactType必须为 CALL / MESSAGE / IN_APP");
|
|
|
+ }
|
|
|
+ if (!canHandle(workorderId, userId)) {
|
|
|
+ return Result.forbidden("仅本家庭工单可操作");
|
|
|
+ }
|
|
|
+ int rows = butlerEscalationOrderMapper.update(null,
|
|
|
+ new LambdaUpdateWrapper<ButlerEscalationOrder>()
|
|
|
+ .eq(ButlerEscalationOrder::getId, workorderId)
|
|
|
+ .set(ButlerEscalationOrder::getContactType, contactType)
|
|
|
+ .set(ButlerEscalationOrder::getContactContent, content)
|
|
|
+ .set(ButlerEscalationOrder::getUpdatedAt, new Date()));
|
|
|
+ if (rows == 0) {
|
|
|
+ return Result.notFound("工单不存在");
|
|
|
+ }
|
|
|
+ log.info("工单 {} 记录联系动作 {}(用户 {})", workorderId, contactType, userId);
|
|
|
+ return Result.success("联系动作已记录", null);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 人工处置结论并闭环,工单 PENDING→PROCESSING→CLOSED 留痕(TC-H-01 步骤 4/5)。
|
|
|
+ *
|
|
|
+ * @param workorderId 工单 ID
|
|
|
+ * @param resolution 人工结论
|
|
|
+ * @param userId 操作用户 ID
|
|
|
+ */
|
|
|
+ @Transactional
|
|
|
+ public Result<String> resolve(Long workorderId, String resolution, Long userId) {
|
|
|
+ if (workorderId == null || resolution == null || resolution.trim().isEmpty()) {
|
|
|
+ return Result.badRequest("workorderId和resolution不能为空");
|
|
|
+ }
|
|
|
+ if (!canHandle(workorderId, userId)) {
|
|
|
+ return Result.forbidden("仅本家庭工单可操作");
|
|
|
+ }
|
|
|
+ ButlerEscalationOrder order = butlerEscalationOrderMapper.selectById(workorderId);
|
|
|
+ if (order == null) {
|
|
|
+ return Result.notFound("工单不存在");
|
|
|
+ }
|
|
|
+ if (ButlerEscalationOrder.STATUS_CLOSED.equals(order.getStatus())) {
|
|
|
+ return Result.conflict("工单已闭环");
|
|
|
+ }
|
|
|
+ if (ButlerEscalationOrder.STATUS_WITHDRAWN.equals(order.getStatus())) {
|
|
|
+ return Result.conflict("工单已撤回,不可闭环");
|
|
|
+ }
|
|
|
+ int rows = butlerEscalationOrderMapper.update(null,
|
|
|
+ new LambdaUpdateWrapper<ButlerEscalationOrder>()
|
|
|
+ .eq(ButlerEscalationOrder::getId, workorderId)
|
|
|
+ .set(ButlerEscalationOrder::getResolution, resolution)
|
|
|
+ .set(ButlerEscalationOrder::getStatus, ButlerEscalationOrder.STATUS_CLOSED)
|
|
|
+ .set(ButlerEscalationOrder::getClosedAt, new Date())
|
|
|
+ .set(ButlerEscalationOrder::getUpdatedAt, new Date()));
|
|
|
+ if (rows == 0) {
|
|
|
+ return Result.notFound("工单不存在");
|
|
|
+ }
|
|
|
+ log.info("工单 {} 由用户 {} 处置闭环:{}", workorderId, userId, resolution);
|
|
|
+ return Result.success("工单已闭环", null);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 转交规划师(SC-H-01 转规划师)。
|
|
|
+ *
|
|
|
+ * @param workorderId 工单 ID
|
|
|
+ * @param teacherId 规划师用户 ID
|
|
|
+ * @param userId 操作用户 ID
|
|
|
+ */
|
|
|
+ @Transactional
|
|
|
+ public Result<String> transferToTeacher(Long workorderId, Long teacherId, Long userId) {
|
|
|
+ if (workorderId == null || teacherId == null) {
|
|
|
+ return Result.badRequest("workorderId和teacherId不能为空");
|
|
|
+ }
|
|
|
+ if (!canHandle(workorderId, userId)) {
|
|
|
+ return Result.forbidden("仅本家庭工单可操作");
|
|
|
+ }
|
|
|
+ int rows = butlerEscalationOrderMapper.update(null,
|
|
|
+ new LambdaUpdateWrapper<ButlerEscalationOrder>()
|
|
|
+ .eq(ButlerEscalationOrder::getId, workorderId)
|
|
|
+ .set(ButlerEscalationOrder::getTeacherId, teacherId)
|
|
|
+ .set(ButlerEscalationOrder::getTargetRole, "teacher")
|
|
|
+ .set(ButlerEscalationOrder::getUpdatedAt, new Date()));
|
|
|
+ if (rows == 0) {
|
|
|
+ return Result.notFound("工单不存在");
|
|
|
+ }
|
|
|
+ log.info("工单 {} 由用户 {} 转交规划师 {}", workorderId, userId, teacherId);
|
|
|
+ return Result.success("已转交规划师", null);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 按 SOP 分级:一级自行处置 / 二级升级至运营、医疗顾问(SC-H-04,管理端治理)。
|
|
|
+ *
|
|
|
+ * @param workorderId 工单 ID
|
|
|
+ * @param escalationLevel 1=一级自行处置 / 2=二级升级
|
|
|
+ * @param userId 操作用户 ID(管理端)
|
|
|
+ */
|
|
|
+ @Transactional
|
|
|
+ public Result<String> grade(Long workorderId, Integer escalationLevel, Long userId) {
|
|
|
+ if (workorderId == null || escalationLevel == null) {
|
|
|
+ return Result.badRequest("workorderId和escalationLevel不能为空");
|
|
|
+ }
|
|
|
+ if (escalationLevel != 1 && escalationLevel != 2) {
|
|
|
+ return Result.badRequest("escalationLevel必须为 1(一级自处)或 2(二级升级)");
|
|
|
+ }
|
|
|
+ ButlerEscalationOrder order = butlerEscalationOrderMapper.selectById(workorderId);
|
|
|
+ if (order == null) {
|
|
|
+ return Result.notFound("工单不存在");
|
|
|
+ }
|
|
|
+ LambdaUpdateWrapper<ButlerEscalationOrder> wrapper = new LambdaUpdateWrapper<ButlerEscalationOrder>()
|
|
|
+ .eq(ButlerEscalationOrder::getId, workorderId)
|
|
|
+ .set(ButlerEscalationOrder::getEscalationLevel, escalationLevel)
|
|
|
+ .set(ButlerEscalationOrder::getUpdatedAt, new Date());
|
|
|
+ if (escalationLevel == 1) {
|
|
|
+ if (!ButlerEscalationOrder.STATUS_PROCESSING.equals(order.getStatus())
|
|
|
+ && !ButlerEscalationOrder.STATUS_PENDING.equals(order.getStatus())) {
|
|
|
+ return Result.conflict("当前状态不支持一级自处");
|
|
|
+ }
|
|
|
+ wrapper.set(ButlerEscalationOrder::getStatus, ButlerEscalationOrder.STATUS_PROCESSING);
|
|
|
+ } else {
|
|
|
+ wrapper.set(ButlerEscalationOrder::getStatus, ButlerEscalationOrder.STATUS_ESCALATED);
|
|
|
+ wrapper.set(ButlerEscalationOrder::getTargetRole, "运营/医疗顾问");
|
|
|
+ }
|
|
|
+ int rows = butlerEscalationOrderMapper.update(null, wrapper);
|
|
|
+ if (rows == 0) {
|
|
|
+ return Result.notFound("工单不存在");
|
|
|
+ }
|
|
|
+ log.info("工单 {} 由用户 {} 按 SOP 分级为 {} 级", workorderId, userId, escalationLevel);
|
|
|
+ return Result.success(escalationLevel == 1 ? "已按 SOP 一级自行处置" : "已按 SOP 二级升级", null);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 二级升级至运营/医疗顾问,并携带完整上下文(不丢上下文,SC-H-04)。
|
|
|
+ *
|
|
|
+ * @param workorderId 工单 ID
|
|
|
+ * @param targetRole 目标角色(运营/医疗顾问)
|
|
|
+ * @param userId 操作用户 ID(管理端)
|
|
|
+ * @return 携带完整工单上下文的升级结果
|
|
|
+ */
|
|
|
+ @Transactional
|
|
|
+ public Result<ButlerEscalationOrder> escalateLevel2(Long workorderId, String targetRole, Long userId) {
|
|
|
+ if (workorderId == null) {
|
|
|
+ return Result.badRequest("workorderId不能为空");
|
|
|
+ }
|
|
|
+ ButlerEscalationOrder order = butlerEscalationOrderMapper.selectById(workorderId);
|
|
|
+ if (order == null) {
|
|
|
+ return Result.notFound("工单不存在");
|
|
|
+ }
|
|
|
+ int rows = butlerEscalationOrderMapper.update(null,
|
|
|
+ new LambdaUpdateWrapper<ButlerEscalationOrder>()
|
|
|
+ .eq(ButlerEscalationOrder::getId, workorderId)
|
|
|
+ .set(ButlerEscalationOrder::getEscalationLevel, 2)
|
|
|
+ .set(ButlerEscalationOrder::getTargetRole,
|
|
|
+ targetRole == null || targetRole.trim().isEmpty() ? "运营/医疗顾问" : targetRole)
|
|
|
+ .set(ButlerEscalationOrder::getStatus, ButlerEscalationOrder.STATUS_ESCALATED)
|
|
|
+ .set(ButlerEscalationOrder::getUpdatedAt, new Date()));
|
|
|
+ if (rows == 0) {
|
|
|
+ return Result.notFound("工单不存在");
|
|
|
+ }
|
|
|
+ // 重查并整单返回,确保升级后仍携带完整上下文(家长诉求 / AI 结论 / 风险等级)
|
|
|
+ ButlerEscalationOrder escalated = butlerEscalationOrderMapper.selectById(workorderId);
|
|
|
+ log.info("工单 {} 二级升级至 {}(用户 {},上下文完整携带)", workorderId,
|
|
|
+ escalated.getTargetRole(), userId);
|
|
|
+ return Result.success("已二级升级", escalated);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成复盘记录(含处置时长与结论,SC-H-04 复盘)。
|
|
|
+ *
|
|
|
+ * @param workorderId 工单 ID
|
|
|
+ * @param durationMinutes 处置时长(分钟)
|
|
|
+ * @param conclusion 复盘结论
|
|
|
+ * @param userId 操作用户 ID(管理端)
|
|
|
+ */
|
|
|
+ @Transactional
|
|
|
+ public Result<String> recordReview(Long workorderId, Integer durationMinutes, String conclusion, Long userId) {
|
|
|
+ if (workorderId == null) {
|
|
|
+ return Result.badRequest("workorderId不能为空");
|
|
|
+ }
|
|
|
+ ButlerEscalationOrder order = butlerEscalationOrderMapper.selectById(workorderId);
|
|
|
+ if (order == null) {
|
|
|
+ return Result.notFound("工单不存在");
|
|
|
+ }
|
|
|
+ LambdaUpdateWrapper<ButlerEscalationOrder> wrapper = new LambdaUpdateWrapper<ButlerEscalationOrder>()
|
|
|
+ .eq(ButlerEscalationOrder::getId, workorderId)
|
|
|
+ .set(ButlerEscalationOrder::getReviewConclusion, conclusion)
|
|
|
+ .set(ButlerEscalationOrder::getUpdatedAt, new Date());
|
|
|
+ if (durationMinutes != null) {
|
|
|
+ wrapper.set(ButlerEscalationOrder::getDurationMinutes, durationMinutes);
|
|
|
+ }
|
|
|
+ int rows = butlerEscalationOrderMapper.update(null, wrapper);
|
|
|
+ if (rows == 0) {
|
|
|
+ return Result.notFound("工单不存在");
|
|
|
+ }
|
|
|
+ log.info("工单 {} 复盘留痕:时长 {} 分钟,结论 {}(用户 {})",
|
|
|
+ workorderId, durationMinutes, conclusion, userId);
|
|
|
+ return Result.success("复盘记录已生成", null);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 扫描超过 SLA 未处理的工单,触发二级升级提醒(TC-H-01-E)。
|
|
|
+ *
|
|
|
+ * @return 触发升级提醒的工单数量
|
|
|
+ */
|
|
|
+ @Transactional
|
|
|
+ public Result<Integer> checkTimeoutEscalation() {
|
|
|
+ Date now = new Date();
|
|
|
+ LambdaQueryWrapper<ButlerEscalationOrder> wrapper = new LambdaQueryWrapper<ButlerEscalationOrder>()
|
|
|
+ .in(ButlerEscalationOrder::getStatus,
|
|
|
+ ButlerEscalationOrder.STATUS_PENDING,
|
|
|
+ ButlerEscalationOrder.STATUS_PROCESSING)
|
|
|
+ .isNotNull(ButlerEscalationOrder::getSlaDeadline)
|
|
|
+ .lt(ButlerEscalationOrder::getSlaDeadline, now);
|
|
|
+ List<ButlerEscalationOrder> timeoutOrders = butlerEscalationOrderMapper.selectList(wrapper);
|
|
|
+ int count = 0;
|
|
|
+ for (ButlerEscalationOrder o : timeoutOrders) {
|
|
|
+ int rows = butlerEscalationOrderMapper.update(null,
|
|
|
+ new LambdaUpdateWrapper<ButlerEscalationOrder>()
|
|
|
+ .eq(ButlerEscalationOrder::getId, o.getId())
|
|
|
+ .set(ButlerEscalationOrder::getStatus, ButlerEscalationOrder.STATUS_ESCALATED)
|
|
|
+ .set(ButlerEscalationOrder::getEscalationLevel, 2)
|
|
|
+ .set(ButlerEscalationOrder::getTargetRole, "运营/医疗顾问")
|
|
|
+ .set(ButlerEscalationOrder::getUpdatedAt, now));
|
|
|
+ if (rows > 0) {
|
|
|
+ count++;
|
|
|
+ log.warn("工单 {} SLA 超时(deadline={}),触发二级升级提醒", o.getId(), o.getSlaDeadline());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Result.success("SLA 扫描完成,触发升级提醒 " + count + " 单", count);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 家庭隔离校验:仅本家庭工单可查看/操作,越界返回 false(TC-H-01-P / TC-H-04-P)。
|
|
|
+ *
|
|
|
+ * @param workorderId 工单 ID
|
|
|
+ * @param userId 操作用户 ID
|
|
|
+ * @return true = 工单属于该用户家庭;false = 越界/不存在
|
|
|
+ */
|
|
|
+ public boolean canHandle(Long workorderId, Long userId) {
|
|
|
+ if (workorderId == null || userId == null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ ButlerEscalationOrder order = butlerEscalationOrderMapper.selectById(workorderId);
|
|
|
+ if (order == null || order.getFamilyId() == null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ User user = userMapper.selectById(userId);
|
|
|
+ return user != null && user.getFamilyId() != null
|
|
|
+ && user.getFamilyId().equals(order.getFamilyId());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 撤回工单(家庭端 SC-H-04 已撤回状态),仅本家庭工单可撤回。
|
|
|
+ *
|
|
|
+ * @param workorderId 工单 ID
|
|
|
+ * @param userId 操作用户 ID
|
|
|
+ */
|
|
|
+ @Transactional
|
|
|
+ public Result<String> withdraw(Long workorderId, Long userId) {
|
|
|
+ if (workorderId == null) {
|
|
|
+ return Result.badRequest("workorderId不能为空");
|
|
|
+ }
|
|
|
+ if (!canHandle(workorderId, userId)) {
|
|
|
+ return Result.forbidden("仅本家庭工单可操作");
|
|
|
+ }
|
|
|
+ ButlerEscalationOrder order = butlerEscalationOrderMapper.selectById(workorderId);
|
|
|
+ if (order == null) {
|
|
|
+ return Result.notFound("工单不存在");
|
|
|
+ }
|
|
|
+ if (ButlerEscalationOrder.STATUS_CLOSED.equals(order.getStatus())
|
|
|
+ || ButlerEscalationOrder.STATUS_WITHDRAWN.equals(order.getStatus())) {
|
|
|
+ return Result.conflict("工单已闭环或已撤回,不可重复操作");
|
|
|
+ }
|
|
|
+ int rows = butlerEscalationOrderMapper.update(null,
|
|
|
+ new LambdaUpdateWrapper<ButlerEscalationOrder>()
|
|
|
+ .eq(ButlerEscalationOrder::getId, workorderId)
|
|
|
+ .set(ButlerEscalationOrder::getStatus, ButlerEscalationOrder.STATUS_WITHDRAWN)
|
|
|
+ .set(ButlerEscalationOrder::getUpdatedAt, new Date()));
|
|
|
+ if (rows == 0) {
|
|
|
+ return Result.notFound("工单不存在");
|
|
|
+ }
|
|
|
+ log.info("工单 {} 由用户 {} 撤回", workorderId, userId);
|
|
|
+ return Result.success("工单已撤回", null);
|
|
|
+ }
|
|
|
+}
|