feat(ops): 优化工单播报语音内容,自动生成区域完整路径
1. 语音播报模板改为"工单来啦,请前往XXX进行清洁" 2. 工单创建时自动根据areaId从ops_bus_area构建完整路径 3. 使用parentPath批量查询上级区域,避免N+1问题 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude (MiniMax-M2.1) <noreply@anthropic.com>
This commit is contained in:
@@ -89,7 +89,7 @@ public class CleanNotificationConstants {
|
||||
* 新工单播报(完整版)
|
||||
* 参数: {areaName} - 区域名称, {orderTitle} - 工单标题(截断)
|
||||
*/
|
||||
public static final String NEW_ORDER_FULL = "新工单:%s,作业区域:%s";
|
||||
public static final String NEW_ORDER_FULL = "新工单来啦,请前往%s进行清洁";
|
||||
|
||||
// ==================== 工单确认播报 ====================
|
||||
|
||||
|
||||
@@ -8,7 +8,9 @@ import com.viewsh.module.ops.core.event.OrderCreatedEvent;
|
||||
import com.viewsh.module.ops.core.event.OrderEventPublisher;
|
||||
import com.viewsh.module.ops.core.lifecycle.OrderLifecycleManager;
|
||||
import com.viewsh.module.ops.core.lifecycle.model.OrderTransitionRequest;
|
||||
import com.viewsh.module.ops.dal.dataobject.area.OpsBusAreaDO;
|
||||
import com.viewsh.module.ops.dal.dataobject.workorder.OpsOrderDO;
|
||||
import com.viewsh.module.ops.dal.mysql.area.OpsBusAreaMapper;
|
||||
import com.viewsh.module.ops.dal.mysql.workorder.OpsOrderMapper;
|
||||
import com.viewsh.module.ops.enums.OperatorTypeEnum;
|
||||
import com.viewsh.module.ops.enums.PriorityEnum;
|
||||
@@ -27,6 +29,11 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 保洁工单服务实现(重构版)
|
||||
@@ -79,6 +86,9 @@ public class CleanOrderServiceImpl implements CleanOrderService {
|
||||
@Resource
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
@Resource
|
||||
private OpsBusAreaMapper opsBusAreaMapper;
|
||||
|
||||
// ==================== 工单创建 ====================
|
||||
|
||||
@Override
|
||||
@@ -98,7 +108,7 @@ public class CleanOrderServiceImpl implements CleanOrderService {
|
||||
.priority(createReq.getPriority() != null ? createReq.getPriority() : PriorityEnum.P2.getPriority())
|
||||
.status(WorkOrderStatusEnum.PENDING.getStatus())
|
||||
.areaId(createReq.getAreaId())
|
||||
.location(createReq.getLocation())
|
||||
.location(buildAreaPath(createReq.getAreaId()))
|
||||
.sourceType(createReq.getSourceType() != null ? createReq.getSourceType() : "TRAFFIC")
|
||||
// IoT集成字段
|
||||
.triggerSource(createReq.getTriggerSource())
|
||||
@@ -393,4 +403,59 @@ public class CleanOrderServiceImpl implements CleanOrderService {
|
||||
log.debug("记录完成时间: orderId={}", orderId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据区域ID构建完整路径(如"园区A栋B层电梯厅")
|
||||
*/
|
||||
private String buildAreaPath(Long areaId) {
|
||||
if (areaId == null) {
|
||||
return null;
|
||||
}
|
||||
OpsBusAreaDO area = opsBusAreaMapper.selectById(areaId);
|
||||
if (area == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String parentPath = area.getParentPath();
|
||||
if (parentPath == null || parentPath.isEmpty()) {
|
||||
return area.getAreaName();
|
||||
}
|
||||
|
||||
String[] parentIds = parentPath.split("/");
|
||||
if (parentIds.length == 0) {
|
||||
return area.getAreaName();
|
||||
}
|
||||
|
||||
// 收集有效的父级ID
|
||||
List<Long> parentIdList = new ArrayList<>();
|
||||
for (String pid : parentIds) {
|
||||
if (!pid.isEmpty()) {
|
||||
try {
|
||||
parentIdList.add(Long.parseLong(pid));
|
||||
} catch (NumberFormatException e) {
|
||||
log.warn("解析父级区域ID失败: pid={}", pid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (parentIdList.isEmpty()) {
|
||||
return area.getAreaName();
|
||||
}
|
||||
|
||||
// 批量查询所有父级,避免 N+1 查询
|
||||
List<OpsBusAreaDO> parents = opsBusAreaMapper.selectBatchIds(parentIdList);
|
||||
Map<Long, OpsBusAreaDO> parentMap = parents.stream()
|
||||
.collect(Collectors.toMap(OpsBusAreaDO::getId, Function.identity()));
|
||||
|
||||
// 按 parentPath 顺序拼接
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Long pid : parentIdList) {
|
||||
OpsBusAreaDO parent = parentMap.get(pid);
|
||||
if (parent != null) {
|
||||
sb.append(parent.getAreaName());
|
||||
}
|
||||
}
|
||||
sb.append(area.getAreaName());
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user