feat(mcp): 处理人改派工具支持姓名入参+调拨/划转同步主表待办人(REQ-20261107-0004/0006)

- 新增 newHandlerName 可选入参:与 newHandlerMobile 二选一,m0 user.name 精确
  匹配+soft_delete=0,唯一命中才生效,同名报错附候选 id(手机号),同传需解析到同一用户
- 调拨/划转改派同步 UPDATE 主表 warehouse_allocation.next_user_name 待办人
  (老系统列表页展示字段),并补 modify_id/modify_time;出库/入库主表无此字段不动
- 参数轻校验提到订单查询之前,参数错误优先返回 INVALID_ARGUMENT
This commit is contained in:
my_local_kimi_dev2
2026-11-07 21:37:11 +08:00
parent 4a65003375
commit ddb5e74745
6 changed files with 222 additions and 39 deletions
@@ -9,8 +9,9 @@ import lombok.Setter;
import lombok.ToString;
import java.io.Serializable;
import java.util.Date;
/** 调拨/采购/划转单 warehouse_allocation(m2,只读):op_type 0调拨 1采购 2划转。 */
/** 调拨/采购/划转单 warehouse_allocation(m2):op_type 0调拨 1采购 2划转。 */
@Getter
@Setter
@ToString
@@ -24,4 +25,11 @@ public class WarehouseAllocation implements Serializable {
private String allocationOrderNo;
private Integer opType;
private Integer orderState;
/** 待办人(改派时与流程表待办行同步更新)。 */
@TableField("next_user_name")
private String nextUserName;
@TableField("modify_id")
private Long modifyId;
@TableField("modify_time")
private Date modifyTime;
}
@@ -40,7 +40,8 @@ import java.util.Map;
* 运维/研发专用:按单号把出库/入库/调拨/划转单的当前待办处理人改派给他人,
* 不做行级权限,访问控制完全靠专用 scope 门禁。平台首个 kind=write 工具。
* 改派语义 = UPDATE 流程物理表(warehouse_out_audit_process / warehouse_in_audit_process /
* warehouse_allocati_process)中 schedule_state=1 待办行的 user_id/user_name。
* warehouse_allocati_process)中 schedule_state=1 待办行的 user_id/user_name;
* 调拨/划转另外同步 UPDATE 主表 warehouse_allocation 的 next_user_name 待办人。
*/
@Component
public class WarehouseOrderAdminTools implements ToolObject {
@@ -82,19 +83,24 @@ public class WarehouseOrderAdminTools implements ToolObject {
@Tool(name = "warehouse.order.handler.update", description = "【写操作·研发/运维专用】按单号改派仓库单据的当前待办处理人,"
+ "覆盖出库单(orderType=out)、入库单(in)、调拨单(allocation)、划转单(transfer)。"
+ "机制:把该单流程物理表中 schedule_state=1 的待办行 user_id/user_name 改成新处理人,"
+ "并行多条待办行全部改派;不动主表、不重推审批流、不发消息通知。"
+ "新处理人按手机号在 m0 user 表精确匹配(soft_delete=0)。"
+ "并行多条待办行全部改派;出库/入库不动主表,调拨/划转会同步把主表 warehouse_allocation 的 "
+ "next_user_name 待办人改成新处理人;不重推审批流、不发消息通知。"
+ "新处理人二选一:newHandlerMobile 按手机号、newHandlerName 按姓名,"
+ "均在 m0 user 表精确匹配(soft_delete=0);姓名命中多个有效用户时报错并引导改用手机号;"
+ "两个都传时必须解析到同一用户。"
+ "无行级权限校验,任何单据都可改;访问控制靠 scope 绑定,每次调用写审计日志。"
+ "单据无待办处理人(已完成/已撤销/作废)时返回错误并附 orderStateText。"
+ "返回 before/after 明细(changedRows)与 changedCount。")
public Map<String, Object> warehouseOrderHandlerUpdate(
@ToolParam(description = "单据类型:out=出库单 in=入库单 allocation=调拨单 transfer=划转单") String orderType,
@ToolParam(description = "单据编号(精确匹配,如 OUT20261001001)") String orderNo,
@ToolParam(description = "新处理人手机号(m0 user.mobile 精确匹配)") String newHandlerMobile,
@ToolParam(required = false, description = "新处理人手机号(m0 user.mobile 精确匹配,与 newHandlerName 至少传一个)")
String newHandlerMobile,
@ToolParam(required = false, description = "新处理人姓名(m0 user.name 精确匹配,需唯一命中;与 newHandlerMobile 至少传一个)")
String newHandlerName,
@ToolParam(required = false, description = "改派原因,写入审计日志") String memo) {
String type = normalizeOrderType(orderType);
String docNo = requireText(orderNo, "orderNo");
String mobile = requireText(newHandlerMobile, "newHandlerMobile");
User caller = AuthContextHolder.get().getUser();
if (caller == null) {
@@ -102,8 +108,15 @@ public class WarehouseOrderAdminTools implements ToolObject {
"该工具要求用户身份 Token 调用(改派人需可追溯),服务身份 Token 不可用");
}
String trimmedMobile = StringUtils.hasText(newHandlerMobile) ? newHandlerMobile.trim() : null;
String trimmedName = StringUtils.hasText(newHandlerName) ? newHandlerName.trim() : null;
if (trimmedMobile == null && trimmedName == null) {
throw new ToolCallException(McpErrorCode.INVALID_ARGUMENT,
"newHandlerMobile 与 newHandlerName 至少传一个");
}
OrderRef order = locateOrder(type, docNo);
User newHandler = locateUserByMobile(mobile);
User newHandler = locateNewHandler(trimmedMobile, trimmedName);
List<ProcessRow> pendingRows = pendingRows(type, order.docId());
if (pendingRows.isEmpty()) {
@@ -212,7 +225,28 @@ public class WarehouseOrderAdminTools implements ToolObject {
return rows.get(0);
}
/** 新处理人:m0 user 表按手机号精确匹配且 soft_delete=0(王恒拍板口径)。 */
/**
* 新处理人定位:手机号/姓名二选一(至少传一个),均按 m0 user 表精确匹配且 soft_delete=0。
* 两者都传时必须解析到同一用户;姓名命中多个有效用户属于正常情况,报错引导改用手机号。
*/
private User locateNewHandler(String mobile, String name) {
String trimmedMobile = StringUtils.hasText(mobile) ? mobile.trim() : null;
String trimmedName = StringUtils.hasText(name) ? name.trim() : null;
if (trimmedMobile == null && trimmedName == null) {
throw new ToolCallException(McpErrorCode.INVALID_ARGUMENT,
"newHandlerMobile 与 newHandlerName 至少传一个");
}
User byMobile = trimmedMobile == null ? null : locateUserByMobile(trimmedMobile);
User byName = trimmedName == null ? null : locateUserByName(trimmedName);
if (byMobile != null && byName != null && !byMobile.getId().equals(byName.getId())) {
throw new ToolCallException(McpErrorCode.INVALID_ARGUMENT,
"newHandlerMobile 与 newHandlerName 匹配到的不是同一用户(手机号=" + byMobile.getId()
+ "(" + byMobile.getName() + "),姓名=" + byName.getId() + "(" + byName.getName() + "))");
}
return byMobile != null ? byMobile : byName;
}
/** 手机号路径:要求唯一命中,重复手机号视为数据异常。 */
private User locateUserByMobile(String mobile) {
List<User> users = userMapper.selectList(new LambdaQueryWrapper<User>()
.eq(User::getSoftDelete, 0)
@@ -228,6 +262,26 @@ public class WarehouseOrderAdminTools implements ToolObject {
return users.get(0);
}
/** 姓名路径:同名多用户属正常情况,命中多条时报错并附候选,引导改用 newHandlerMobile。 */
private User locateUserByName(String name) {
List<User> users = userMapper.selectList(new LambdaQueryWrapper<User>()
.eq(User::getSoftDelete, 0)
.eq(User::getName, name));
if (users.isEmpty()) {
throw new ToolCallException(McpErrorCode.INVALID_ARGUMENT,
"姓名 " + name + " 未匹配到有效用户(user 表 soft_delete=0)");
}
if (users.size() > 1) {
String candidates = users.stream()
.map(u -> u.getId() + "(" + (u.getMobile() == null ? "无手机号" : u.getMobile()) + ")")
.reduce((a, b) -> a + "、" + b).orElse("");
throw new ToolCallException(McpErrorCode.INVALID_ARGUMENT,
"姓名 " + name + " 命中 " + users.size() + " 个有效用户(" + candidates
+ "),请改用 newHandlerMobile 手机号指定");
}
return users.get(0);
}
/** 当前待办行:流程物理表 schedule_state=1 且 soft_delete=0。 */
private List<ProcessRow> pendingRows(String type, Long docId) {
return switch (type) {
@@ -276,15 +330,24 @@ public class WarehouseOrderAdminTools implements ToolObject {
.set(WarehouseInAuditProcess::getUserName, newHandler.getName())
.set(WarehouseInAuditProcess::getModifyId, callerUserId)
.set(WarehouseInAuditProcess::getModifyTime, now));
default -> allocatiProcessMapper.update(null,
new LambdaUpdateWrapper<WarehouseAllocatiProcess>()
.eq(WarehouseAllocatiProcess::getSoftDelete, 0)
.eq(WarehouseAllocatiProcess::getScheduleState, 1)
.eq(WarehouseAllocatiProcess::getWarehouseAllocationId, docId)
.set(WarehouseAllocatiProcess::getUserId, newHandler.getId())
.set(WarehouseAllocatiProcess::getUserName, newHandler.getName())
.set(WarehouseAllocatiProcess::getModifyId, callerUserId)
.set(WarehouseAllocatiProcess::getModifyTime, now));
default -> {
int rows = allocatiProcessMapper.update(null,
new LambdaUpdateWrapper<WarehouseAllocatiProcess>()
.eq(WarehouseAllocatiProcess::getSoftDelete, 0)
.eq(WarehouseAllocatiProcess::getScheduleState, 1)
.eq(WarehouseAllocatiProcess::getWarehouseAllocationId, docId)
.set(WarehouseAllocatiProcess::getUserId, newHandler.getId())
.set(WarehouseAllocatiProcess::getUserName, newHandler.getName())
.set(WarehouseAllocatiProcess::getModifyId, callerUserId)
.set(WarehouseAllocatiProcess::getModifyTime, now));
allocationMapper.update(null, new LambdaUpdateWrapper<WarehouseAllocation>()
.eq(WarehouseAllocation::getSoftDelete, 0)
.eq(WarehouseAllocation::getId, docId)
.set(WarehouseAllocation::getNextUserName, newHandler.getName())
.set(WarehouseAllocation::getModifyId, callerUserId)
.set(WarehouseAllocation::getModifyTime, now));
yield rows;
}
};
}