|
|
@@ -0,0 +1,392 @@
|
|
|
+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.ButlerOneOnOneCoachRecord;
|
|
|
+import com.etotem.cfc.mapper.ButlerOneOnOneCoachRecordMapper;
|
|
|
+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.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 真人管家 · 一对一陪跑 / 多方沟通协调宿主服务(能力键 {@code butler.oneOnOne.coach},SC-H-02 / SC-H-03)。
|
|
|
+ *
|
|
|
+ * <p>陪跑闭环:建档案 + 服务计划(周期 / 回访节奏 / 可配 SLA)→ 定期回访留痕 → 家长随时 1v1 咨询
|
|
|
+ * (即时到管家侧 + SLA 计时 + 响应留痕家长可见);到期给续费入口、暂停期不回访、敏感字段脱敏、
|
|
|
+ * 并发咨询合并单会话,仅本服务家庭可见(越界 403)。</p>
|
|
|
+ *
|
|
|
+ * <p>协调闭环:收集家长诉求与规划师方案 → 翻译后同步(不变更方案结论)→ 向规划师反馈 →
|
|
|
+ * 闭环确认并全程留痕;争议引导直连,管家不改方案。消息协同复用 {@code teacher.message.push}
|
|
|
+ * 同源通道({@link TeacherMessageService}),PII 脱敏复用 {@link PiisService}。</p>
|
|
|
+ *
|
|
|
+ * <p>方法签名由契约测试 {@code ButlerOneOnOneCoachContractTest} /
|
|
|
+ * {@code ButlerOneOnOneCoachPersistenceContractTest} 反射锚定。</p>
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class ButlerOneOnOneCoachService {
|
|
|
+
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(ButlerOneOnOneCoachService.class);
|
|
|
+
|
|
|
+ /** SLA 缺省响应时长(分钟),可按套餐 / 家庭覆盖。 */
|
|
|
+ private static final Integer DEFAULT_SLA_MINUTES = 120;
|
|
|
+ /** 缺省回访节奏。 */
|
|
|
+ private static final String DEFAULT_FOLLOW_UP_CADENCE = "WEEKLY";
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private ButlerOneOnOneCoachRecordMapper butlerOneOnOneCoachRecordMapper;
|
|
|
+
|
|
|
+ /** PII 脱敏:档案与协调消息含高敏字段时走统一脱敏口径(TC-H-02-E / TC-H-03-E)。 */
|
|
|
+ @Resource
|
|
|
+ private PiisService piisService;
|
|
|
+
|
|
|
+ /** teacher.message.push 同源通道:不另起独立消息通道,保证监督反馈闭环可审计。 */
|
|
|
+ @Resource
|
|
|
+ private TeacherMessageService teacherMessageService;
|
|
|
+
|
|
|
+ // ==================== SC-H-02:建档案 + 服务计划 + 定期回访 ====================
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 建立家长档案与服务计划(TC-H-02 步骤 1)。
|
|
|
+ */
|
|
|
+ public Result<ButlerOneOnOneCoachRecord> createProfile(Long familyId, Long parentUserId,
|
|
|
+ Long butlerUserId, String serviceCycle,
|
|
|
+ String followUpCadence, Integer slaMinutes,
|
|
|
+ Date serviceExpireAt) {
|
|
|
+ if (familyId == null || parentUserId == null) {
|
|
|
+ return Result.badRequest("familyId和parentUserId不能为空");
|
|
|
+ }
|
|
|
+ ButlerOneOnOneCoachRecord record = new ButlerOneOnOneCoachRecord();
|
|
|
+ record.setFamilyId(familyId);
|
|
|
+ record.setParentUserId(parentUserId);
|
|
|
+ record.setButlerUserId(butlerUserId);
|
|
|
+ record.setServiceCycle(serviceCycle);
|
|
|
+ record.setFollowUpCadence(followUpCadence == null ? DEFAULT_FOLLOW_UP_CADENCE : followUpCadence);
|
|
|
+ record.setSlaMinutes(slaMinutes == null ? DEFAULT_SLA_MINUTES : slaMinutes);
|
|
|
+ record.setServiceExpireAt(serviceExpireAt);
|
|
|
+ record.setStatus(ButlerOneOnOneCoachRecord.STATUS_ACTIVE);
|
|
|
+ record.setCoordinationStatus(ButlerOneOnOneCoachRecord.COORDINATION_COLLECTING);
|
|
|
+ record.setCreatedAt(new Date());
|
|
|
+ record.setUpdatedAt(new Date());
|
|
|
+ butlerOneOnOneCoachRecordMapper.insert(record);
|
|
|
+ return Result.success(record);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 执行一次定期回访并生成记录(时间 / 内容 / 待办,TC-H-02 步骤 2);暂停期不回访。
|
|
|
+ */
|
|
|
+ public Result<ButlerOneOnOneCoachRecord> recordFollowUp(Long recordId, String content,
|
|
|
+ String todo, Long butlerUserId) {
|
|
|
+ ButlerOneOnOneCoachRecord record = butlerOneOnOneCoachRecordMapper.selectById(recordId);
|
|
|
+ if (record == null) {
|
|
|
+ return Result.notFound("陪跑档案不存在");
|
|
|
+ }
|
|
|
+ if (ButlerOneOnOneCoachRecord.STATUS_PAUSED.equals(record.getStatus())) {
|
|
|
+ return Result.error("服务暂停期不发起回访");
|
|
|
+ }
|
|
|
+ butlerOneOnOneCoachRecordMapper.update(null, new LambdaUpdateWrapper<ButlerOneOnOneCoachRecord>()
|
|
|
+ .eq(ButlerOneOnOneCoachRecord::getId, recordId)
|
|
|
+ .set(ButlerOneOnOneCoachRecord::getFollowUpAt, new Date())
|
|
|
+ .set(ButlerOneOnOneCoachRecord::getFollowUpContent, content)
|
|
|
+ .set(ButlerOneOnOneCoachRecord::getFollowUpTodo, todo)
|
|
|
+ .set(ButlerOneOnOneCoachRecord::getButlerUserId,
|
|
|
+ butlerUserId == null ? record.getButlerUserId() : butlerUserId)
|
|
|
+ .set(ButlerOneOnOneCoachRecord::getUpdatedAt, new Date()));
|
|
|
+ return Result.success(butlerOneOnOneCoachRecordMapper.selectById(recordId));
|
|
|
+ }
|
|
|
+
|
|
|
+ // ==================== SC-H-02:1v1 咨询 + SLA + 响应留痕 ====================
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 家长主动发起 1v1 咨询:请求即时到管家侧并启动 SLA 计时(TC-H-02 步骤 3)。
|
|
|
+ */
|
|
|
+ public Result<ButlerOneOnOneCoachRecord> startConsultation(Long recordId, String content, Long parentUserId) {
|
|
|
+ Result<Boolean> entitlement = checkServiceEntitlement(recordId);
|
|
|
+ if (entitlement.getCode() != 200) {
|
|
|
+ return Result.error(entitlement.getCode(), entitlement.getMessage());
|
|
|
+ }
|
|
|
+ butlerOneOnOneCoachRecordMapper.update(null, new LambdaUpdateWrapper<ButlerOneOnOneCoachRecord>()
|
|
|
+ .eq(ButlerOneOnOneCoachRecord::getId, recordId)
|
|
|
+ .set(ButlerOneOnOneCoachRecord::getConsultContent, content)
|
|
|
+ .set(ButlerOneOnOneCoachRecord::getConsultStartedAt, new Date())
|
|
|
+ .set(ButlerOneOnOneCoachRecord::getConsultResponse, null)
|
|
|
+ .set(ButlerOneOnOneCoachRecord::getRespondedAt, null)
|
|
|
+ .set(ButlerOneOnOneCoachRecord::getParentUserId,
|
|
|
+ parentUserId == null ? null : parentUserId)
|
|
|
+ .set(ButlerOneOnOneCoachRecord::getUpdatedAt, new Date()));
|
|
|
+ return Result.success(butlerOneOnOneCoachRecordMapper.selectById(recordId));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 管家响应并记录,家长端可见答复(TC-H-02 步骤 4)。
|
|
|
+ */
|
|
|
+ public Result<ButlerOneOnOneCoachRecord> respondConsultation(Long recordId, String response, Long butlerUserId) {
|
|
|
+ ButlerOneOnOneCoachRecord record = butlerOneOnOneCoachRecordMapper.selectById(recordId);
|
|
|
+ if (record == null) {
|
|
|
+ return Result.notFound("陪跑档案不存在");
|
|
|
+ }
|
|
|
+ butlerOneOnOneCoachRecordMapper.update(null, new LambdaUpdateWrapper<ButlerOneOnOneCoachRecord>()
|
|
|
+ .eq(ButlerOneOnOneCoachRecord::getId, recordId)
|
|
|
+ .set(ButlerOneOnOneCoachRecord::getConsultResponse, piisService.sanitizeText(response))
|
|
|
+ .set(ButlerOneOnOneCoachRecord::getRespondedAt, new Date())
|
|
|
+ .set(ButlerOneOnOneCoachRecord::getButlerUserId,
|
|
|
+ butlerUserId == null ? record.getButlerUserId() : butlerUserId)
|
|
|
+ .set(ButlerOneOnOneCoachRecord::getUpdatedAt, new Date()));
|
|
|
+ return Result.success(butlerOneOnOneCoachRecordMapper.selectById(recordId));
|
|
|
+ }
|
|
|
+
|
|
|
+ // ==================== TC-H-02-E:到期 / 暂停 / 脱敏 / 并发 ====================
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 服务到期当天发起咨询 → 提示已到期并给出续费入口(不静默拒,TC-H-02-E)。
|
|
|
+ */
|
|
|
+ public Result<Boolean> checkServiceEntitlement(Long recordId) {
|
|
|
+ if (recordId == null) {
|
|
|
+ return Result.badRequest("recordId不能为空");
|
|
|
+ }
|
|
|
+ ButlerOneOnOneCoachRecord record = butlerOneOnOneCoachRecordMapper.selectById(recordId);
|
|
|
+ if (record == null) {
|
|
|
+ return Result.notFound("陪跑档案不存在");
|
|
|
+ }
|
|
|
+ if (ButlerOneOnOneCoachRecord.STATUS_PAUSED.equals(record.getStatus())) {
|
|
|
+ return Result.error("服务暂停中,暂不提供咨询");
|
|
|
+ }
|
|
|
+ Date expireAt = record.getServiceExpireAt();
|
|
|
+ if (ButlerOneOnOneCoachRecord.STATUS_EXPIRED.equals(record.getStatus())
|
|
|
+ || (expireAt != null && expireAt.before(new Date()))) {
|
|
|
+ return Result.error("服务已到期,请续费后继续咨询");
|
|
|
+ }
|
|
|
+ return Result.success(Boolean.TRUE);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 服务暂停期不发起回访、状态置为暂停(TC-H-02-E)。
|
|
|
+ */
|
|
|
+ public Result<ButlerOneOnOneCoachRecord> pauseFollowUp(Long recordId, Long butlerUserId, String reason) {
|
|
|
+ ButlerOneOnOneCoachRecord record = butlerOneOnOneCoachRecordMapper.selectById(recordId);
|
|
|
+ if (record == null) {
|
|
|
+ return Result.notFound("陪跑档案不存在");
|
|
|
+ }
|
|
|
+ butlerOneOnOneCoachRecordMapper.update(null, new LambdaUpdateWrapper<ButlerOneOnOneCoachRecord>()
|
|
|
+ .eq(ButlerOneOnOneCoachRecord::getId, recordId)
|
|
|
+ .set(ButlerOneOnOneCoachRecord::getStatus, ButlerOneOnOneCoachRecord.STATUS_PAUSED)
|
|
|
+ .set(ButlerOneOnOneCoachRecord::getFollowUpTodo, reason)
|
|
|
+ .set(ButlerOneOnOneCoachRecord::getButlerUserId,
|
|
|
+ butlerUserId == null ? record.getButlerUserId() : butlerUserId)
|
|
|
+ .set(ButlerOneOnOneCoachRecord::getUpdatedAt, new Date()));
|
|
|
+ return Result.success(butlerOneOnOneCoachRecordMapper.selectById(recordId));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 家长档案含高敏信息时敏感字段脱敏,未授权不可导出(复用 PII 脱敏口径,TC-H-02-E)。
|
|
|
+ */
|
|
|
+ public Result<String> sanitizeProfileSensitive(String text) {
|
|
|
+ if (text == null) {
|
|
|
+ return Result.success(null);
|
|
|
+ }
|
|
|
+ return Result.success(piisService.sanitizeText(text));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 同一家长并发发起多个咨询 → 合并为 1 个会话,不产生多条并行工单(TC-H-02-E)。
|
|
|
+ */
|
|
|
+ @Transactional
|
|
|
+ public Result<ButlerOneOnOneCoachRecord> mergeConcurrentConsultations(Long familyId, Long parentUserId) {
|
|
|
+ List<ButlerOneOnOneCoachRecord> records = butlerOneOnOneCoachRecordMapper.selectList(
|
|
|
+ new LambdaQueryWrapper<ButlerOneOnOneCoachRecord>()
|
|
|
+ .eq(familyId != null, ButlerOneOnOneCoachRecord::getFamilyId, familyId)
|
|
|
+ .eq(parentUserId != null, ButlerOneOnOneCoachRecord::getParentUserId, parentUserId)
|
|
|
+ .eq(ButlerOneOnOneCoachRecord::getStatus, ButlerOneOnOneCoachRecord.STATUS_ACTIVE)
|
|
|
+ .orderByAsc(ButlerOneOnOneCoachRecord::getId));
|
|
|
+ if (records == null || records.isEmpty()) {
|
|
|
+ return Result.notFound("无进行中的咨询");
|
|
|
+ }
|
|
|
+ ButlerOneOnOneCoachRecord primary = records.get(0);
|
|
|
+ for (int i = 1; i < records.size(); i++) {
|
|
|
+ ButlerOneOnOneCoachRecord duplicate = records.get(i);
|
|
|
+ butlerOneOnOneCoachRecordMapper.update(null, new LambdaUpdateWrapper<ButlerOneOnOneCoachRecord>()
|
|
|
+ .eq(ButlerOneOnOneCoachRecord::getId, duplicate.getId())
|
|
|
+ .set(ButlerOneOnOneCoachRecord::getStatus, ButlerOneOnOneCoachRecord.STATUS_MERGED)
|
|
|
+ .set(ButlerOneOnOneCoachRecord::getConsultResponse, "已合并至会话 " + primary.getId())
|
|
|
+ .set(ButlerOneOnOneCoachRecord::getRespondedAt, new Date())
|
|
|
+ .set(ButlerOneOnOneCoachRecord::getUpdatedAt, new Date()));
|
|
|
+ }
|
|
|
+ return Result.success(primary);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * SLA 可配:按套餐 / 家庭配置回访与响应 SLA(SC-H-02 边界)。
|
|
|
+ */
|
|
|
+ public Result<ButlerOneOnOneCoachRecord> configureSla(Long recordId, Integer slaMinutes,
|
|
|
+ String followUpCadence) {
|
|
|
+ if (slaMinutes == null || slaMinutes <= 0) {
|
|
|
+ return Result.badRequest("slaMinutes必须为正整数");
|
|
|
+ }
|
|
|
+ butlerOneOnOneCoachRecordMapper.update(null, new LambdaUpdateWrapper<ButlerOneOnOneCoachRecord>()
|
|
|
+ .eq(ButlerOneOnOneCoachRecord::getId, recordId)
|
|
|
+ .set(ButlerOneOnOneCoachRecord::getSlaMinutes, slaMinutes)
|
|
|
+ .set(ButlerOneOnOneCoachRecord::getFollowUpCadence, followUpCadence)
|
|
|
+ .set(ButlerOneOnOneCoachRecord::getUpdatedAt, new Date()));
|
|
|
+ return Result.success(butlerOneOnOneCoachRecordMapper.selectById(recordId));
|
|
|
+ }
|
|
|
+
|
|
|
+ // ==================== TC-H-02-P:家庭隔离 ====================
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 仅本服务家庭可见,越界拒绝(403,TC-H-02-P)。
|
|
|
+ */
|
|
|
+ public Result<Boolean> canAccessProfile(Long recordId, Long userId) {
|
|
|
+ if (recordId == null || userId == null) {
|
|
|
+ return Result.forbidden("仅本服务家庭可见");
|
|
|
+ }
|
|
|
+ ButlerOneOnOneCoachRecord record = butlerOneOnOneCoachRecordMapper.selectById(recordId);
|
|
|
+ if (record == null) {
|
|
|
+ return Result.notFound("陪跑档案不存在");
|
|
|
+ }
|
|
|
+ if (userId.equals(record.getParentUserId()) || userId.equals(record.getButlerUserId())) {
|
|
|
+ return Result.success(Boolean.TRUE);
|
|
|
+ }
|
|
|
+ return Result.forbidden("仅本服务家庭可见");
|
|
|
+ }
|
|
|
+
|
|
|
+ // ==================== SC-H-03:多方沟通协调 + 消息同源 ====================
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 收集家长诉求与规划师方案,三方信息在同一工单内可查(TC-H-03 步骤 1)。
|
|
|
+ */
|
|
|
+ public Result<ButlerOneOnOneCoachRecord> collectCoordination(Long recordId, String parentDemand,
|
|
|
+ String teacherConclusion, Long messageId) {
|
|
|
+ butlerOneOnOneCoachRecordMapper.update(null, new LambdaUpdateWrapper<ButlerOneOnOneCoachRecord>()
|
|
|
+ .eq(ButlerOneOnOneCoachRecord::getId, recordId)
|
|
|
+ .set(ButlerOneOnOneCoachRecord::getParentDemand, piisService.sanitizeText(parentDemand))
|
|
|
+ .set(ButlerOneOnOneCoachRecord::getTeacherConclusion, piisService.sanitizeText(teacherConclusion))
|
|
|
+ .set(ButlerOneOnOneCoachRecord::getMessageId, messageId)
|
|
|
+ .set(ButlerOneOnOneCoachRecord::getCoordinationStatus,
|
|
|
+ ButlerOneOnOneCoachRecord.COORDINATION_COLLECTING)
|
|
|
+ .set(ButlerOneOnOneCoachRecord::getUpdatedAt, new Date()));
|
|
|
+ return Result.success(butlerOneOnOneCoachRecordMapper.selectById(recordId));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 向家长同步「翻译后」结论,不擅自变更规划师方案结论(TC-H-03 步骤 2 / TC-H-03-E)。
|
|
|
+ */
|
|
|
+ public Result<ButlerOneOnOneCoachRecord> syncTranslatedConclusion(Long recordId, String translatedConclusion) {
|
|
|
+ butlerOneOnOneCoachRecordMapper.update(null, new LambdaUpdateWrapper<ButlerOneOnOneCoachRecord>()
|
|
|
+ .eq(ButlerOneOnOneCoachRecord::getId, recordId)
|
|
|
+ .set(ButlerOneOnOneCoachRecord::getTranslatedConclusion,
|
|
|
+ piisService.sanitizeText(translatedConclusion))
|
|
|
+ .set(ButlerOneOnOneCoachRecord::getCoordinationStatus,
|
|
|
+ ButlerOneOnOneCoachRecord.COORDINATION_SYNCED)
|
|
|
+ .set(ButlerOneOnOneCoachRecord::getUpdatedAt, new Date()));
|
|
|
+ return Result.success(butlerOneOnOneCoachRecordMapper.selectById(recordId));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 向规划师反馈家长执行情况与疑虑,规划师侧可回复(TC-H-03 步骤 3)。
|
|
|
+ */
|
|
|
+ public Result<ButlerOneOnOneCoachRecord> feedbackToTeacher(Long recordId, String teacherFeedback) {
|
|
|
+ butlerOneOnOneCoachRecordMapper.update(null, new LambdaUpdateWrapper<ButlerOneOnOneCoachRecord>()
|
|
|
+ .eq(ButlerOneOnOneCoachRecord::getId, recordId)
|
|
|
+ .set(ButlerOneOnOneCoachRecord::getTeacherFeedback, piisService.sanitizeText(teacherFeedback))
|
|
|
+ .set(ButlerOneOnOneCoachRecord::getCoordinationStatus,
|
|
|
+ ButlerOneOnOneCoachRecord.COORDINATION_FEEDBACKED)
|
|
|
+ .set(ButlerOneOnOneCoachRecord::getUpdatedAt, new Date()));
|
|
|
+ return Result.success(butlerOneOnOneCoachRecordMapper.selectById(recordId));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 完成节点对齐并闭环确认,工单状态置为已对齐且全过程留痕(TC-H-03 步骤 4)。
|
|
|
+ */
|
|
|
+ public Result<ButlerOneOnOneCoachRecord> closeCoordination(Long recordId) {
|
|
|
+ butlerOneOnOneCoachRecordMapper.update(null, new LambdaUpdateWrapper<ButlerOneOnOneCoachRecord>()
|
|
|
+ .eq(ButlerOneOnOneCoachRecord::getId, recordId)
|
|
|
+ .set(ButlerOneOnOneCoachRecord::getCoordinationStatus,
|
|
|
+ ButlerOneOnOneCoachRecord.COORDINATION_ALIGNED)
|
|
|
+ .set(ButlerOneOnOneCoachRecord::getStatus, ButlerOneOnOneCoachRecord.STATUS_ALIGNED)
|
|
|
+ .set(ButlerOneOnOneCoachRecord::getUpdatedAt, new Date()));
|
|
|
+ return Result.success(butlerOneOnOneCoachRecordMapper.selectById(recordId));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 家长与规划师意见冲突 → 引导双方直接沟通并记录,不由管家单方裁决 / 不改方案(TC-H-03-E)。
|
|
|
+ */
|
|
|
+ public Result<ButlerOneOnOneCoachRecord> recordDisputeDirectConnect(Long recordId, String note) {
|
|
|
+ butlerOneOnOneCoachRecordMapper.update(null, new LambdaUpdateWrapper<ButlerOneOnOneCoachRecord>()
|
|
|
+ .eq(ButlerOneOnOneCoachRecord::getId, recordId)
|
|
|
+ .set(ButlerOneOnOneCoachRecord::getCoordinationStatus,
|
|
|
+ ButlerOneOnOneCoachRecord.COORDINATION_DISPUTED)
|
|
|
+ .set(ButlerOneOnOneCoachRecord::getReplyContent, piisService.sanitizeText(note))
|
|
|
+ .set(ButlerOneOnOneCoachRecord::getUpdatedAt, new Date()));
|
|
|
+ return Result.success(butlerOneOnOneCoachRecordMapper.selectById(recordId));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 复用 teacher.message.push 同源通道推送三方协调消息(家长 / 规划师 / 管家)。
|
|
|
+ */
|
|
|
+ public Result<Long> pushCoordinationMessage(Long familyId, Long parentUserId, Long teacherId,
|
|
|
+ String content, Long recordId) {
|
|
|
+ if (familyId == null || parentUserId == null || teacherId == null) {
|
|
|
+ return Result.badRequest("familyId/parentUserId/teacherId不能为空");
|
|
|
+ }
|
|
|
+ Long messageId = teacherMessageService.sendMessage(
|
|
|
+ familyId, parentUserId, teacherId, piisService.sanitizeText(content));
|
|
|
+ if (recordId != null) {
|
|
|
+ butlerOneOnOneCoachRecordMapper.update(null, new LambdaUpdateWrapper<ButlerOneOnOneCoachRecord>()
|
|
|
+ .eq(ButlerOneOnOneCoachRecord::getId, recordId)
|
|
|
+ .set(ButlerOneOnOneCoachRecord::getMessageId, messageId)
|
|
|
+ .set(ButlerOneOnOneCoachRecord::getUpdatedAt, new Date()));
|
|
|
+ }
|
|
|
+ log.info("[butler.oneOnOne.coach] 协调消息已推送,messageId={}, recordId={}", messageId, recordId);
|
|
|
+ return Result.success(messageId);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 监督反馈闭环:记录家长 / 规划师反馈与处置结论,留痕可审计(SC-H-03 反馈→闭环)。
|
|
|
+ */
|
|
|
+ public Result<ButlerOneOnOneCoachRecord> recordSupervisionFeedback(Long recordId, String feedback,
|
|
|
+ String resolution) {
|
|
|
+ butlerOneOnOneCoachRecordMapper.update(null, new LambdaUpdateWrapper<ButlerOneOnOneCoachRecord>()
|
|
|
+ .eq(ButlerOneOnOneCoachRecord::getId, recordId)
|
|
|
+ .set(ButlerOneOnOneCoachRecord::getSupervisionFeedback, piisService.sanitizeText(feedback))
|
|
|
+ .set(ButlerOneOnOneCoachRecord::getReplyContent, piisService.sanitizeText(resolution))
|
|
|
+ .set(ButlerOneOnOneCoachRecord::getUpdatedAt, new Date()));
|
|
|
+ return Result.success(butlerOneOnOneCoachRecordMapper.selectById(recordId));
|
|
|
+ }
|
|
|
+
|
|
|
+ // ==================== 端点辅助查询 ====================
|
|
|
+
|
|
|
+ /** 分配 / 更换陪跑管家(管理端 assign)。 */
|
|
|
+ public Result<ButlerOneOnOneCoachRecord> assignButler(Long recordId, Long butlerUserId) {
|
|
|
+ if (recordId == null || butlerUserId == null) {
|
|
|
+ return Result.badRequest("recordId和butlerUserId不能为空");
|
|
|
+ }
|
|
|
+ butlerOneOnOneCoachRecordMapper.update(null, new LambdaUpdateWrapper<ButlerOneOnOneCoachRecord>()
|
|
|
+ .eq(ButlerOneOnOneCoachRecord::getId, recordId)
|
|
|
+ .set(ButlerOneOnOneCoachRecord::getButlerUserId, butlerUserId)
|
|
|
+ .set(ButlerOneOnOneCoachRecord::getUpdatedAt, new Date()));
|
|
|
+ return Result.success(butlerOneOnOneCoachRecordMapper.selectById(recordId));
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 陪跑档案台账(管理端 records,按家庭隔离)。 */
|
|
|
+ public Result<List<ButlerOneOnOneCoachRecord>> listRecords(Long familyId) {
|
|
|
+ LambdaQueryWrapper<ButlerOneOnOneCoachRecord> wrapper = new LambdaQueryWrapper<ButlerOneOnOneCoachRecord>()
|
|
|
+ .eq(familyId != null, ButlerOneOnOneCoachRecord::getFamilyId, familyId)
|
|
|
+ .orderByDesc(ButlerOneOnOneCoachRecord::getCreatedAt);
|
|
|
+ return Result.success(butlerOneOnOneCoachRecordMapper.selectList(wrapper));
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 同源消息列表(家庭端 messages,复用 teacher.message.push 通道)。 */
|
|
|
+ public Result<Map<String, Object>> listMessages(Long familyId, Integer page, Integer size) {
|
|
|
+ if (familyId == null) {
|
|
|
+ return Result.badRequest("familyId不能为空");
|
|
|
+ }
|
|
|
+ return Result.success(teacherMessageService.getFamilyMessages(
|
|
|
+ familyId, page == null ? 1 : page, size == null ? 20 : size));
|
|
|
+ }
|
|
|
+}
|