[fix] 出入库工具复查修复:调拨待办漏本人修改/待办行串位/调拨派生入库单凭证回查 (REQ-20260919-0003) (#22)

This commit was merged in pull request #22.
This commit is contained in:
2026-09-19 22:28:02 +08:00
parent c9240fa31c
commit 68fd71edbb
9 changed files with 195 additions and 19 deletions
@@ -0,0 +1,26 @@
package me.iiv.agent.entity.m2;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import java.io.Serializable;
/** 调拨/采购/划转单 warehouse_allocation(m2,只读):op_type 0调拨 1采购 2划转。 */
@Getter
@Setter
@ToString
@TableName("warehouse_allocation")
public class WarehouseAllocation implements Serializable {
@TableId(value = "id", type = IdType.AUTO)
private Long id;
private Integer softDelete;
@TableField("allocation_order_no")
private String allocationOrderNo;
private Integer opType;
}
@@ -0,0 +1,7 @@
package me.iiv.agent.mapper.m2;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import me.iiv.agent.entity.m2.WarehouseAllocation;
public interface WarehouseAllocationMapper extends BaseMapper<WarehouseAllocation> {
}
@@ -3,11 +3,13 @@ package me.iiv.agent.mcp.tool;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import me.iiv.agent.entity.m0.User;
import me.iiv.agent.entity.m2.WarehouseAllocation;
import me.iiv.agent.entity.m2.WarehouseIn;
import me.iiv.agent.entity.m2.WarehouseInAuditProcess;
import me.iiv.agent.entity.m2.WarehouseInDetail;
import me.iiv.agent.entity.m2.WarehouseInOutPic;
import me.iiv.agent.entity.m2.WarehouseType;
import me.iiv.agent.mapper.m2.WarehouseAllocationMapper;
import me.iiv.agent.mapper.m2.WarehouseInAuditProcessMapper;
import me.iiv.agent.mapper.m2.WarehouseInDetailMapper;
import me.iiv.agent.mapper.m2.WarehouseInMapper;
@@ -49,6 +51,7 @@ public class WarehouseInTools implements ToolObject {
private static final int DEFAULT_SERIAL_LIMIT = 100;
private static final int MAX_SERIAL_LIMIT = 500;
private static final int IN_TYPE = 0;
private static final int ALLOCATION_TYPE = 2;
private static final ZoneId BUSINESS_ZONE = ZoneId.of("Asia/Shanghai");
private static final Pattern DATE_PATTERN = Pattern.compile("^\\d{4}-\\d{2}-\\d{2}$");
private static final DateTimeFormatter DATE_FORMATTER =
@@ -71,6 +74,7 @@ public class WarehouseInTools implements ToolObject {
final WarehouseInDetailMapper detailMapper;
final WarehouseInAuditProcessMapper processMapper;
final WarehouseInOutPicMapper picMapper;
final WarehouseAllocationMapper allocationMapper;
final WarehouseTypeMapper warehouseTypeMapper;
final PermissionService permissionService;
@@ -78,12 +82,14 @@ public class WarehouseInTools implements ToolObject {
WarehouseInDetailMapper detailMapper,
WarehouseInAuditProcessMapper processMapper,
WarehouseInOutPicMapper picMapper,
WarehouseAllocationMapper allocationMapper,
WarehouseTypeMapper warehouseTypeMapper,
PermissionService permissionService) {
this.warehouseInMapper = warehouseInMapper;
this.detailMapper = detailMapper;
this.processMapper = processMapper;
this.picMapper = picMapper;
this.allocationMapper = allocationMapper;
this.warehouseTypeMapper = warehouseTypeMapper;
this.permissionService = permissionService;
}
@@ -180,6 +186,8 @@ public class WarehouseInTools implements ToolObject {
@Tool(name = "warehouse.in.detail.query", description = "按 id 或入库单号查询入库单详情。"
+ "行级权限与 warehouse.in.list.query 完全一致,不存在与无权访问统一返回 NOT_FOUND_OR_FORBIDDEN。"
+ "返回主单、场景类型、仓库、按物料和仓库汇总的明细、可选 SN、已处理流程和申请/确认附件;调拨入库单可直接查询。"
+ "files 含 application(申请附件)/confirmation(入库确认)/allocationAudit(调拨审批流图片);"
+ "调拨派生的入库单其申请附件与审批图片挂在调拨单维度,已按调拨单号自动回查合并。"
+ "关联出库仅返回索引,不内嵌内容。includeSerials 默认 false;serialLimit 默认100、上限500。")
public Map<String, Object> warehouseInDetailQuery(
@ToolParam(required = false, description = "入库单主键 id,与 inOrderNo 至少传一个") Long id,
@@ -222,11 +230,19 @@ public class WarehouseInTools implements ToolObject {
.eq(WarehouseInAuditProcess::getScheduleState, 2)
.orderByAsc(WarehouseInAuditProcess::getOperationTime)
.orderByAsc(WarehouseInAuditProcess::getId));
List<WarehouseInOutPic> pics = picMapper.selectList(new LambdaQueryWrapper<WarehouseInOutPic>()
List<WarehouseInOutPic> pics = new ArrayList<>(picMapper.selectList(new LambdaQueryWrapper<WarehouseInOutPic>()
.eq(WarehouseInOutPic::getSoftDelete, 0)
.eq(WarehouseInOutPic::getAggregateId, order.getId())
.eq(WarehouseInOutPic::getInOutAllocationType, IN_TYPE)
.orderByAsc(WarehouseInOutPic::getId));
.orderByAsc(WarehouseInOutPic::getId)));
// 调拨派生的入库单:申请附件(fileType=0)和审批流图片(fileType=3)挂在调拨单维度
// (aggregate_id=调拨单id, in_out_allocation_type=2),按调拨单号回查补齐,否则这两类凭证恒为空。
List<WarehouseInOutPic> allocationPics = allocationPics(order);
if (!allocationPics.isEmpty()) {
Set<Long> seen = pics.stream().map(WarehouseInOutPic::getId).collect(Collectors.toSet());
allocationPics.stream().filter(pic -> pic.getId() == null || seen.add(pic.getId()))
.forEach(pics::add);
}
WarehouseType type = order.getWarehouseTypeId() == null
? null : warehouseTypeMapper.selectById(order.getWarehouseTypeId());
@@ -242,6 +258,7 @@ public class WarehouseInTools implements ToolObject {
Map<String, Object> files = new LinkedHashMap<>();
files.put("application", fileRecords(pics, 0));
files.put("confirmation", fileRecords(pics, 1));
files.put("allocationAudit", fileRecords(pics, 3));
result.put("files", files);
result.put("relatedOutOrder", relatedOutOrder(order));
return result;
@@ -413,8 +430,26 @@ public class WarehouseInTools implements ToolObject {
}).collect(Collectors.toList());
}
private Map<String, Object> relatedOutOrder(WarehouseIn order) {
if (!StringUtils.hasText(order.getOutOrderNo())) return null;
/** 调拨派生入库单的申请/审批凭证挂在调拨单维度,按调拨单号回查;调拨单不存在或无调拨单号时返回空。 */
private List<WarehouseInOutPic> allocationPics(WarehouseIn order) {
if (!StringUtils.hasText(order.getAllocationOrderNo())) {
return List.of();
}
WarehouseAllocation allocation = allocationMapper.selectOne(new LambdaQueryWrapper<WarehouseAllocation>()
.eq(WarehouseAllocation::getSoftDelete, 0)
.eq(WarehouseAllocation::getAllocationOrderNo, order.getAllocationOrderNo())
.last("LIMIT 1"));
if (allocation == null) {
return List.of();
}
return picMapper.selectList(new LambdaQueryWrapper<WarehouseInOutPic>()
.eq(WarehouseInOutPic::getSoftDelete, 0)
.eq(WarehouseInOutPic::getAggregateId, allocation.getId())
.eq(WarehouseInOutPic::getInOutAllocationType, ALLOCATION_TYPE)
.orderByAsc(WarehouseInOutPic::getId));
}
private Map<String, Object> relatedOutOrder(WarehouseIn order) { if (!StringUtils.hasText(order.getOutOrderNo())) return null;
Map<String, Object> related = new LinkedHashMap<>();
related.put("outOrderNo", order.getOutOrderNo());
related.put("queryTool", "warehouse.out.detail.query");
@@ -40,7 +40,7 @@ public class WarehouseTodoTools implements ToolObject {
private static final DateTimeFormatter TIME_FORMATTER =
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").withZone(BUSINESS_ZONE);
/** 待办环节只保留可办理的操作类型,3(驳回或修改记录)为纯日志,排除。 */
/** 待办环节只保留可办理的操作类型,3(驳回或修改记录)为纯日志,排除。仅适用于出入库视图,调拨视图不过滤。 */
private static final List<Integer> TODO_OPERATION_TYPES = List.of(0, 1, 2);
private static final Map<Integer, String> SCHEDULE_STATE_TEXT = Map.of(
@@ -76,8 +76,9 @@ public class WarehouseTodoTools implements ToolObject {
@Tool(name = "warehouse.todo.list.query", description = "分页查询当前用户的仓库待办,统一老系统 /myWarehouseOut/needToBeDealtWith、"
+ "/myWarehouseIn/needToBeDealtWith、/warehouseAllocation/warehouseAllocationProcessListByPage 三个待办接口。"
+ "数据来自 m2 流程视图 warehouse_out_process / warehouse_in_process / warehouse_allocation_process:"
+ "待办语义 = 视图里存在当前用户的任务行(user_id = 当前登录人 AND soft_delete = 0 AND operation_type IN (0,1,2),"
+ "3=纯日志排除),不按代理商过滤。同一笔调拨最多以调拨审批/确认、出库执行、入库执行 3 个视角出现,不去重;"
+ "待办语义 = 视图里存在当前用户的任务行(user_id = 当前登录人 AND soft_delete = 0,"
+ "出库/入库视图排除 operation_type=3 纯日志;调拨视图不过滤 operation_type,其 3=本人修改 是真实待办),不按代理商过滤。"
+ "同一笔调拨最多以调拨审批/确认、出库执行、入库执行 3 个视角出现,不去重;"
+ "派生自调拨的真实出入库单带 derivedFrom=\"allocation\" 标记。"
+ "docType:out=出库单 in=入库单 allocation=调拨/采购/划转单(按 op_type 区分) all=全部,默认 all。"
+ "todoOnly 默认 true(只返回 schedule_state=1 真待办),false 返回当前用户参与过的全部单据。"
@@ -174,11 +175,11 @@ public class WarehouseTodoTools implements ToolObject {
}
private List<TodoStub> allocationStubs(Long userId, boolean onlyTodo, Integer orderState, String orderNo) {
// 老系统调拨待办接口不过滤 operation_type(3=本人修改 是真实待办环节),与出入库视图口径不同
LambdaQueryWrapper<WarehouseAllocationProcess> wrapper = new LambdaQueryWrapper<WarehouseAllocationProcess>()
.select(WarehouseAllocationProcess::getWarehouseAllocationId, WarehouseAllocationProcess::getApplyDate)
.eq(WarehouseAllocationProcess::getSoftDelete, 0)
.eq(WarehouseAllocationProcess::getUserId, userId)
.in(WarehouseAllocationProcess::getOperationType, TODO_OPERATION_TYPES)
.eq(onlyTodo, WarehouseAllocationProcess::getScheduleState, 1)
.eq(orderState != null, WarehouseAllocationProcess::getOrderState, orderState)
.like(StringUtils.hasText(orderNo), WarehouseAllocationProcess::getAllocationOrderNo,
@@ -206,6 +207,7 @@ public class WarehouseTodoTools implements ToolObject {
.eq(WarehouseOutProcess::getSoftDelete, 0)
.eq(WarehouseOutProcess::getUserId, userId)
.in(WarehouseOutProcess::getOperationType, TODO_OPERATION_TYPES)
.eq(onlyTodo, WarehouseOutProcess::getScheduleState, 1)
.in(WarehouseOutProcess::getWarehouseOutId, ids)
.orderByAsc(WarehouseOutProcess::getId)).stream()
.collect(Collectors.groupingBy(WarehouseOutProcess::getWarehouseOutId,
@@ -221,6 +223,7 @@ public class WarehouseTodoTools implements ToolObject {
.eq(WarehouseInProcess::getSoftDelete, 0)
.eq(WarehouseInProcess::getUserId, userId)
.in(WarehouseInProcess::getOperationType, TODO_OPERATION_TYPES)
.eq(onlyTodo, WarehouseInProcess::getScheduleState, 1)
.in(WarehouseInProcess::getWarehouseInId, ids)
.orderByAsc(WarehouseInProcess::getId)).stream()
.collect(Collectors.groupingBy(WarehouseInProcess::getWarehouseInId,
@@ -235,7 +238,7 @@ public class WarehouseTodoTools implements ToolObject {
new LambdaQueryWrapper<WarehouseAllocationProcess>()
.eq(WarehouseAllocationProcess::getSoftDelete, 0)
.eq(WarehouseAllocationProcess::getUserId, userId)
.in(WarehouseAllocationProcess::getOperationType, TODO_OPERATION_TYPES)
.eq(onlyTodo, WarehouseAllocationProcess::getScheduleState, 1)
.in(WarehouseAllocationProcess::getWarehouseAllocationId, ids)
.orderByAsc(WarehouseAllocationProcess::getId)).stream()
.collect(Collectors.groupingBy(WarehouseAllocationProcess::getWarehouseAllocationId,
@@ -263,7 +266,8 @@ public class WarehouseTodoTools implements ToolObject {
}
}
/** 取代表当前待办环节的行:优先 schedule_state=1 的真待办行,否则取首行(已办/无需待办)。 */
/** 取代表当前待办环节的行:onlyTodo 时 assemble 已下推 schedule_state=1,取首行即可;
* 否则优先 schedule_state=1 的真待办行,再退回首行(已办/无需待办)。 */
private static <T> T pickPending(List<T> rows, boolean onlyTodo) {
if (onlyTodo) {
return rows.get(0);