Forráskód Böngészése

feat(s5): add production return mdp readonly pipeline

- 新增生产退料单标准层 head-detail 双表(1.0.213.sql:mdp_std_production_return + _detail)
- 新增 ProductionReturnMdpSyncService(只读 NbrMaster/NbrDetail Type='WOD' → mdp_std,幂等 upsert,run-log)
- 新增 s5-production-return-mdp refresh 刷新入口
- 新增 ProductionReturn list/detail 只读 API(租户过滤 + 过滤/排序白名单)
- 新增生产退料单只读列表 + 详情页面 + API 封装
- 菜单 FUNC-S5-006 重指真实页面 /aidop/s5/warehouse/productionReturnList
- 空态先行(当前 WOD=0);不做写入/退料确认/入库/库存事务/导出/S3/S4/T8

版本:Web 2.4.208 / server 1.0.213
YY968XX 1 hete
szülő
commit
23e126f3db

+ 1 - 1
Web/package.json

@@ -1,7 +1,7 @@
 {
   "name": "admin.net",
   "type": "module",
-  "version": "2.4.207",
+  "version": "2.4.208",
   "packageManager": "pnpm@10.32.1",
   "lastBuildTime": "2026.03.15",
   "description": "Admin.NET 站在巨人肩膀上的 .NET 通用权限开发框架",

+ 77 - 0
Web/src/views/aidop/s5/api/productionReturn.ts

@@ -0,0 +1,77 @@
+import service from '/@/utils/request';
+import { withAidopTenantParams } from '../../api/aidopTenant';
+
+export interface Paged<T> {
+	total: number;
+	page: number;
+	pageSize: number;
+	list: T[];
+}
+
+// ── S5 生产退料单(只读,数据中台标准层 mdp_std_production_return)──
+export interface ProductionReturnRow {
+	id?: number;
+	/** 退料单号 nbr */
+	nbr?: string;
+	/** 退料日期 return_date */
+	returnDate?: string;
+	/** 状态中文 status_desc */
+	statusDesc?: string;
+	/** SAP单号/工单号 work_ord */
+	workOrd?: string;
+	/** 部门 department + department_desc */
+	departmentDesc?: string;
+	/** 生产线 prod_line */
+	prodLine?: string;
+	/** 退料人 return_user */
+	returnUser?: string;
+	/** 备注 remark */
+	remark?: string;
+	/** 创建用户 create_user */
+	createUser?: string;
+	/** 创建时间 source_create_time */
+	createTime?: string;
+}
+
+export interface ProductionReturnDetailLine {
+	id?: number;
+	line?: number;
+	itemNum?: string;
+	itemName?: string;
+	itemSpec?: string;
+	um?: string;
+	qtyTo?: number;
+	qtyRec?: number;
+	locationTo?: string;
+	locationToDesc?: string;
+	lotSerial?: string;
+	statusDesc?: string;
+	remark?: string;
+}
+
+export interface ProductionReturnDetail {
+	id?: number;
+	nbr?: string;
+	workOrd?: string;
+	returnDate?: string;
+	prodLine?: string;
+	departmentDesc?: string;
+	applicantName?: string;
+	returnUser?: string;
+	statusDesc?: string;
+	remark?: string;
+	/** 明细行 */
+	lines?: ProductionReturnDetailLine[];
+}
+
+export function fetchProductionReturnList(params: any) {
+	return service
+		.get<Paged<ProductionReturnRow>>('/api/ProductionReturn/list', { params: withAidopTenantParams(params) })
+		.then((r) => r.data);
+}
+
+export function fetchProductionReturnDetail(id: number) {
+	return service
+		.get<ProductionReturnDetail>('/api/ProductionReturn/detail', { params: withAidopTenantParams({ id }) })
+		.then((r) => r.data);
+}

+ 254 - 0
Web/src/views/aidop/s5/warehouse/productionReturnList.vue

@@ -0,0 +1,254 @@
+<template>
+	<AidopDemoShell :title="pageTitle" subtitle="FUNC-S5-006 · 只读列表">
+		<!--
+			S5 生产退料单 · 只读页(S5-PRODUCTION-RETURN-MDP-PIPELINE-1)。
+			数据源:DOP 数据中台标准层 mdp_std_production_return(_detail)(由 NbrMaster/NbrDetail Type='WOD' 同步标准化)。
+			只读:无新增/编辑/保存/退料确认/入库/库存事务/状态流转/导出。上游未产 WOD 单据时为真实接口空态,无 mock。
+		-->
+		<el-form :inline="true" :model="query" class="mb12" @submit.prevent>
+			<el-form-item label="退料单号">
+				<el-input v-model="query.nbr" clearable style="width: 180px" />
+			</el-form-item>
+			<el-form-item label="SAP单号">
+				<el-input v-model="query.workOrd" clearable style="width: 180px" />
+			</el-form-item>
+			<el-form-item label="状态">
+				<el-input v-model="query.status" clearable style="width: 120px" />
+			</el-form-item>
+			<el-form-item label="生产线">
+				<el-input v-model="query.prodLine" clearable style="width: 140px" />
+			</el-form-item>
+			<el-form-item label="退料日期">
+				<el-date-picker
+					v-model="dateRange"
+					type="daterange"
+					value-format="YYYY-MM-DD"
+					range-separator="-"
+					start-placeholder="开始日期"
+					end-placeholder="结束日期"
+					unlink-panels
+					style="width: 260px"
+				/>
+			</el-form-item>
+			<el-form-item>
+				<el-button type="primary" @click="doSearch">查询</el-button>
+				<el-button @click="resetQuery">重置</el-button>
+			</el-form-item>
+		</el-form>
+
+		<el-table :data="rows" row-key="id" v-loading="loading" border stripe @sort-change="onSortChange">
+			<el-table-column type="index" label="#" width="60" align="center" />
+			<el-table-column prop="nbr" label="退料单号" min-width="170" sortable="custom" show-overflow-tooltip resizable />
+			<el-table-column prop="returnDate" label="退料日期" width="130" sortable="custom" resizable>
+				<template #default="{ row }">{{ fmtDate(row.returnDate) }}</template>
+			</el-table-column>
+			<el-table-column prop="statusDesc" label="状态" width="90" sortable="custom" resizable />
+			<el-table-column prop="workOrd" label="SAP单号" min-width="160" sortable="custom" show-overflow-tooltip resizable />
+			<el-table-column prop="departmentDesc" label="部门" min-width="140" show-overflow-tooltip resizable />
+			<el-table-column prop="prodLine" label="生产线" width="110" sortable="custom" resizable />
+			<el-table-column prop="returnUser" label="退料人" width="120" show-overflow-tooltip resizable />
+			<el-table-column prop="remark" label="备注" min-width="150" show-overflow-tooltip resizable />
+			<el-table-column prop="createUser" label="创建用户" width="120" resizable />
+			<el-table-column prop="createTime" label="创建时间" width="160" resizable>
+				<template #default="{ row }">{{ fmtDateTime(row.createTime) }}</template>
+			</el-table-column>
+			<el-table-column label="操作" width="120" fixed="right">
+				<template #default="{ row }">
+					<el-button link type="primary" @click="viewRow(row)">查看</el-button>
+				</template>
+			</el-table-column>
+			<template #empty>
+				<el-empty description="暂无数据" />
+			</template>
+		</el-table>
+
+		<div class="pager">
+			<el-pagination
+				v-model:current-page="query.page"
+				v-model:page-size="query.pageSize"
+				:total="total"
+				:page-sizes="[10, 20, 50]"
+				layout="total, sizes, prev, pager, next"
+				@current-change="loadList"
+				@size-change="loadList"
+			/>
+		</div>
+
+		<!-- 查看详情:基础信息 + 退料单明细,只读,数据来自真实 detail 接口 -->
+		<el-dialog v-model="detailVisible" title="生产退料单" width="960px" append-to-body>
+			<div v-loading="detailLoading">
+				<el-descriptions :column="3" border title="基础信息">
+					<el-descriptions-item label="退料单号">{{ detail.nbr }}</el-descriptions-item>
+					<el-descriptions-item label="工单号">{{ detail.workOrd }}</el-descriptions-item>
+					<el-descriptions-item label="退料日期">{{ fmtDate(detail.returnDate) }}</el-descriptions-item>
+					<el-descriptions-item label="生产线">{{ detail.prodLine }}</el-descriptions-item>
+					<el-descriptions-item label="部门">{{ detail.departmentDesc }}</el-descriptions-item>
+					<el-descriptions-item label="申请人">{{ detail.applicantName }}</el-descriptions-item>
+					<el-descriptions-item label="退料人">{{ detail.returnUser }}</el-descriptions-item>
+					<el-descriptions-item label="备注" :span="2">{{ detail.remark }}</el-descriptions-item>
+				</el-descriptions>
+
+				<div class="detail-section-title">退料单明细</div>
+				<el-table :data="detailLines" border stripe size="small">
+					<el-table-column type="index" label="项次" width="64" align="center" />
+					<el-table-column prop="itemNum" label="物料编码" min-width="140" show-overflow-tooltip />
+					<el-table-column prop="um" label="单位" width="80" />
+					<el-table-column prop="qtyTo" label="退料数量" width="110" align="right" />
+					<el-table-column prop="qtyRec" label="已退数" width="110" align="right" />
+					<el-table-column prop="locationTo" label="转入库位" min-width="120" show-overflow-tooltip>
+						<template #default="{ row }">{{ fmtLocation(row.locationTo, row.locationToDesc) }}</template>
+					</el-table-column>
+					<el-table-column prop="lotSerial" label="批序号" min-width="130" show-overflow-tooltip />
+					<el-table-column prop="statusDesc" label="状态" width="90" />
+					<template #empty>
+						<el-empty description="暂无数据" />
+					</template>
+				</el-table>
+			</div>
+		</el-dialog>
+	</AidopDemoShell>
+</template>
+
+<script setup lang="ts" name="aidopS5WarehouseProductionReturn">
+import { computed, onActivated, onMounted, reactive, ref } from 'vue';
+import { useRoute } from 'vue-router';
+import { ElMessage } from 'element-plus';
+import AidopDemoShell from '/@/views/aidop/components/AidopDemoShell.vue';
+import {
+	fetchProductionReturnList,
+	fetchProductionReturnDetail,
+	type ProductionReturnRow,
+	type ProductionReturnDetailLine,
+} from '../api/productionReturn';
+
+const route = useRoute();
+const pageTitle = computed(() => (route.meta?.title as string) || '生产退料单');
+
+const query = reactive({
+	nbr: '',
+	workOrd: '',
+	status: '',
+	prodLine: '',
+	dateFrom: '',
+	dateTo: '',
+	page: 1,
+	pageSize: 10,
+	orderBy: '',
+	orderDir: '',
+});
+const dateRange = ref<[string, string] | null>(null);
+
+const loading = ref(false);
+const rows = ref<ProductionReturnRow[]>([]);
+const total = ref(0);
+
+const detailVisible = ref(false);
+const detailLoading = ref(false);
+const detail = reactive<Record<string, any>>({});
+const detailLines = ref<ProductionReturnDetailLine[]>([]);
+
+function fmtDate(v?: string | null) {
+	if (!v) return '';
+	return String(v).slice(0, 10);
+}
+function fmtDateTime(v?: string | null) {
+	if (!v) return '';
+	const s = String(v);
+	return s.length > 19 ? s.slice(0, 19).replace('T', ' ') : s.replace('T', ' ');
+}
+function fmtLocation(code?: string | null, desc?: string | null) {
+	const c = code ? String(code) : '';
+	const d = desc ? String(desc) : '';
+	return `${c} ${d}`.trim();
+}
+
+function onSortChange({ prop, order }: { prop: string; order: string | null }) {
+	query.orderBy = prop || '';
+	query.orderDir = order === 'ascending' ? 'asc' : order === 'descending' ? 'desc' : '';
+	loadList();
+}
+
+async function loadList() {
+	loading.value = true;
+	try {
+		query.dateFrom = dateRange.value?.[0] || '';
+		query.dateTo = dateRange.value?.[1] || '';
+		const data = await fetchProductionReturnList({
+			nbr: query.nbr,
+			workOrd: query.workOrd,
+			status: query.status,
+			prodLine: query.prodLine,
+			dateFrom: query.dateFrom,
+			dateTo: query.dateTo,
+			page: query.page,
+			pageSize: query.pageSize,
+			orderBy: query.orderBy,
+			orderDir: query.orderDir,
+		});
+		rows.value = data.list || [];
+		total.value = data.total || 0;
+	} catch (e: any) {
+		rows.value = [];
+		total.value = 0;
+		ElMessage.error(e?.message || '加载生产退料单列表失败');
+	} finally {
+		loading.value = false;
+	}
+}
+
+function doSearch() {
+	query.page = 1;
+	loadList();
+}
+
+function resetQuery() {
+	query.nbr = '';
+	query.workOrd = '';
+	query.status = '';
+	query.prodLine = '';
+	dateRange.value = null;
+	query.dateFrom = '';
+	query.dateTo = '';
+	query.page = 1;
+	query.orderBy = '';
+	query.orderDir = '';
+	loadList();
+}
+
+async function viewRow(row: ProductionReturnRow) {
+	if (!row?.id) return;
+	detailVisible.value = true;
+	detailLoading.value = true;
+	Object.keys(detail).forEach((k) => delete detail[k]);
+	detailLines.value = [];
+	try {
+		const data = await fetchProductionReturnDetail(row.id);
+		if (data) {
+			Object.assign(detail, data);
+			detailLines.value = data.lines || [];
+		}
+	} catch (e: any) {
+		ElMessage.error(e?.message || '加载生产退料单详情失败');
+	} finally {
+		detailLoading.value = false;
+	}
+}
+
+onMounted(() => loadList());
+onActivated(() => loadList());
+</script>
+
+<style scoped lang="scss">
+.mb12 {
+	margin-bottom: 12px;
+}
+.pager {
+	margin-top: 12px;
+	display: flex;
+	justify-content: flex-end;
+}
+.detail-section-title {
+	margin: 16px 0 8px;
+	font-weight: 600;
+}
+</style>

+ 6 - 3
server/Admin.NET.Web.Entry/Admin.NET.Web.Entry.csproj

@@ -11,9 +11,9 @@
     <GenerateSatelliteAssembliesForCore>true</GenerateSatelliteAssembliesForCore>
     <Copyright>Admin.NET</Copyright>
     <Description>Admin.NET ͨ��Ȩ�޿���ƽ̨</Description>
-    <AssemblyVersion>1.0.212</AssemblyVersion>
-    <FileVersion>1.0.212</FileVersion>
-    <Version>1.0.212</Version>
+    <AssemblyVersion>1.0.213</AssemblyVersion>
+    <FileVersion>1.0.213</FileVersion>
+    <Version>1.0.213</Version>
   </PropertyGroup>
 
   <ItemGroup>
@@ -196,6 +196,9 @@
     <None Update="UpdateScripts\1.0.210.sql">
       <CopyToOutputDirectory>Always</CopyToOutputDirectory>
     </None>
+    <None Update="UpdateScripts\1.0.213.sql">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
   </ItemGroup>
 
   <ItemGroup>

+ 100 - 0
server/Admin.NET.Web.Entry/UpdateScripts/1.0.213.sql

@@ -0,0 +1,100 @@
+-- ============================================================
+-- 1.0.213.sql
+-- S5-PRODUCTION-RETURN-MDP-PIPELINE-1
+--
+-- 业务目标:
+--   1) 新建 S5 生产退料单标准层 head-detail 双表(只读数据中台,DOP 内部):
+--      mdp_std_production_return(头)        源 NbrMaster(Type='WOD',IsActive=1,IsReturn=0)
+--      mdp_std_production_return_detail(明细)源 NbrDetail(Type='WOD', NbrRecID→NbrMaster.RecID)
+--      不建 stg、不建 dwd;不读/不改 S3/S4;不写源表。
+--   2) 将「生产退料单」菜单(Id=1329015020004,仓储管理目录下)的 Component
+--      由 placeholder 重指到真实页面 /aidop/s5/warehouse/productionReturnList。
+--
+-- 安全保证:
+--   - DDL 仅 CREATE TABLE IF NOT EXISTS,幂等;不 DROP / TRUNCATE。
+--   - 菜单仅 UPDATE 该单条 Component / Remark / UpdateTime;不改 Path/Name/Pid/Title/Type/OrderNo;
+--     不 INSERT/DELETE;不动 SysTenantMenu / SysRoleMenu;不动其它菜单。
+--   - 不动源单据表(NbrMaster/NbrDetail 等),不动 S3/S4 资产,不碰 S2 写路径。
+-- ============================================================
+
+CREATE TABLE IF NOT EXISTS mdp_std_production_return (
+    id BIGINT AUTO_INCREMENT PRIMARY KEY,
+    tenant_id BIGINT NOT NULL DEFAULT 0,
+    factory_id BIGINT NULL DEFAULT 1,
+    source_system VARCHAR(50) NOT NULL DEFAULT 'AIDOP',
+    domain VARCHAR(80) NOT NULL COMMENT '工厂/域 NbrMaster.Domain',
+    rec_id INT NOT NULL COMMENT '源头主键 NbrMaster.RecID',
+    nbr VARCHAR(24) NULL COMMENT '退料单号 NbrMaster.Nbr',
+    return_date DATETIME NULL COMMENT '退料日期 NbrMaster.Date',
+    status VARCHAR(8) NULL COMMENT '状态原值 NbrMaster.Status',
+    status_desc VARCHAR(20) NULL COMMENT '状态中文(C→关闭)',
+    work_ord VARCHAR(64) NULL COMMENT 'SAP单号/工单号 NbrMaster.WorkOrd',
+    department VARCHAR(8) NULL COMMENT '部门编码 NbrMaster.Department',
+    department_desc VARCHAR(255) NULL COMMENT '部门(编码+DepartmentMaster.Descr)',
+    qty_ord DECIMAL(18,5) NULL DEFAULT 0 COMMENT '数量 NbrMaster.QtyOrd(默认隐藏)',
+    prod_line VARCHAR(8) NULL COMMENT '生产线 NbrMaster.ProdLine',
+    applicant_name VARCHAR(12) NULL COMMENT '申请人 NbrMaster.Name',
+    return_user VARCHAR(255) NULL COMMENT '退料人(本批取 NbrMaster.User1)',
+    user1 TEXT NULL COMMENT '原始 NbrMaster.User1',
+    user2 TEXT NULL COMMENT '原始 NbrMaster.User2',
+    remark VARCHAR(200) NULL COMMENT '备注 NbrMaster.Remark',
+    create_user VARCHAR(24) NULL COMMENT '创建用户 NbrMaster.CreateUser',
+    source_create_time DATETIME NULL COMMENT '源创建时间 NbrMaster.CreateTime',
+    trans_type VARCHAR(24) NULL COMMENT '事务类型 NbrMaster.TransType',
+    trans_type_text VARCHAR(50) NULL COMMENT '事务类型文案(旧系统恒空)',
+    eff_date DATETIME NULL COMMENT '生效日期 NbrMaster.EffDate',
+    ufld1 VARCHAR(50) NULL COMMENT '用户字段1 NbrMaster.Ufld1',
+    source_biz_key VARCHAR(200) NULL COMMENT 'domain:rec_id',
+    sync_batch_id VARCHAR(100) NOT NULL,
+    sync_time DATETIME NOT NULL,
+    create_time DATETIME DEFAULT CURRENT_TIMESTAMP,
+    update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
+    UNIQUE KEY uk_mdp_std_prod_rtn (tenant_id, domain, rec_id),
+    KEY idx_mdp_std_prod_rtn_nbr (tenant_id, nbr),
+    KEY idx_mdp_std_prod_rtn_date (tenant_id, return_date),
+    KEY idx_mdp_std_prod_rtn_status (tenant_id, status),
+    KEY idx_mdp_std_prod_rtn_workord (tenant_id, work_ord),
+    KEY idx_mdp_std_prod_rtn_prodline (tenant_id, prod_line),
+    KEY idx_mdp_std_prod_rtn_dept (tenant_id, department)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='S5生产退料单头标准层';
+
+CREATE TABLE IF NOT EXISTS mdp_std_production_return_detail (
+    id BIGINT AUTO_INCREMENT PRIMARY KEY,
+    tenant_id BIGINT NOT NULL DEFAULT 0,
+    std_head_id BIGINT NULL COMMENT '回填头 mdp_std_production_return.id',
+    domain VARCHAR(80) NOT NULL COMMENT '工厂/域',
+    nbr_rec_id INT NOT NULL COMMENT '关联头 NbrDetail.NbrRecID→NbrMaster.RecID',
+    rec_id INT NULL COMMENT '源明细主键 NbrDetail.RecID',
+    line SMALLINT NOT NULL DEFAULT 0 COMMENT '项次 NbrDetail.Line',
+    item_num VARCHAR(24) NULL COMMENT '物料编码 NbrDetail.ItemNum',
+    item_name VARCHAR(200) NULL COMMENT '物料名称 ItemMaster.Descr',
+    item_spec VARCHAR(200) NULL COMMENT '物料规格 ItemMaster.Descr1',
+    um VARCHAR(8) NULL COMMENT '单位 NbrDetail.UM',
+    qty_to DECIMAL(18,5) NULL DEFAULT 0 COMMENT '退料数量 NbrDetail.QtyTo',
+    qty_rec DECIMAL(18,5) NULL DEFAULT 0 COMMENT '已退数 NbrDetail.QtyRec',
+    location_from VARCHAR(8) NULL COMMENT '转出库位 NbrDetail.LocationFrom',
+    location_from_desc VARCHAR(255) NULL COMMENT '转出库位名 LocationMaster.descr',
+    location_to VARCHAR(8) NULL COMMENT '转入库位 NbrDetail.LocationTo',
+    location_to_desc VARCHAR(255) NULL COMMENT '转入库位名 LocationMaster.descr',
+    lot_serial VARCHAR(120) NULL COMMENT '批序号 NbrDetail.LotSerial',
+    status VARCHAR(8) NULL COMMENT '状态原值 NbrDetail.Status',
+    status_desc VARCHAR(20) NULL COMMENT '状态中文(C→关闭)',
+    remark VARCHAR(500) NULL COMMENT '备注 NbrDetail.Remark',
+    work_ord VARCHAR(64) NULL COMMENT '工单 NbrDetail.WorkOrd',
+    source_biz_key VARCHAR(200) NULL COMMENT 'domain:nbr_rec_id:line',
+    sync_batch_id VARCHAR(100) NOT NULL,
+    sync_time DATETIME NOT NULL,
+    create_time DATETIME DEFAULT CURRENT_TIMESTAMP,
+    update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
+    UNIQUE KEY uk_mdp_std_prod_rtn_dtl (tenant_id, domain, nbr_rec_id, line),
+    KEY idx_mdp_std_prod_rtn_dtl_head (tenant_id, std_head_id),
+    KEY idx_mdp_std_prod_rtn_dtl_item (tenant_id, item_num),
+    KEY idx_mdp_std_prod_rtn_dtl_locto (tenant_id, location_to),
+    KEY idx_mdp_std_prod_rtn_dtl_lot (tenant_id, lot_serial)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='S5生产退料单明细标准层';
+
+UPDATE SysMenu
+SET Component  = '/aidop/s5/warehouse/productionReturnList',
+    Remark     = 'S5 生产退料单(只读 head-detail,数据中台标准层 mdp_std_production_return)',
+    UpdateTime = NOW()
+WHERE Id = 1329015020004;

+ 21 - 1
server/Plugins/Admin.NET.Plugin.AiDOP/Controllers/AidopKanbanController.cs

@@ -30,6 +30,7 @@ public partial class AidopKanbanController : ControllerBase
     private readonly SmartOpsKpiAtomicQueryService _atomicQuery;
     private readonly OutsourceIssueMdpSyncService _outsourceIssueMdpSyncService;
     private readonly PurchaseReceiptMdpSyncService _purchaseReceiptMdpSyncService;
+    private readonly ProductionReturnMdpSyncService _productionReturnMdpSyncService;
 
     public AidopKanbanController(
         ISqlSugarClient db,
@@ -42,7 +43,8 @@ public partial class AidopKanbanController : ControllerBase
         S7MdpSyncTransformService s7MdpSyncTransformService,
         SmartOpsKpiAtomicQueryService atomicQuery,
         OutsourceIssueMdpSyncService outsourceIssueMdpSyncService,
-        PurchaseReceiptMdpSyncService purchaseReceiptMdpSyncService)
+        PurchaseReceiptMdpSyncService purchaseReceiptMdpSyncService,
+        ProductionReturnMdpSyncService productionReturnMdpSyncService)
     {
         _db = db;
         _s1MdpSyncTransformService = s1MdpSyncTransformService;
@@ -55,6 +57,7 @@ public partial class AidopKanbanController : ControllerBase
         _atomicQuery = atomicQuery;
         _outsourceIssueMdpSyncService = outsourceIssueMdpSyncService;
         _purchaseReceiptMdpSyncService = purchaseReceiptMdpSyncService;
+        _productionReturnMdpSyncService = productionReturnMdpSyncService;
     }
 
     [HttpGet("home-l1")]
@@ -471,6 +474,23 @@ LIMIT 60
         });
     }
 
+    /// <summary>
+    /// S5 生产退料单 数据中台只读链路手动刷新(DOP 内部 head-detail:NbrMaster/NbrDetail Type='WOD' → mdp_std_production_return(_detail))。
+    /// 独立于 s5-mdp/refresh 的 KPI 管线;只读源、只写 mdp_std 表;不建 stg/dwd;不碰 S2 写路径、S3/S4、T8;WOD 为 0 行时成功、处理数 0。
+    /// </summary>
+    [HttpPost("s5-production-return-mdp/refresh")]
+    public async Task<IActionResult> RefreshS5ProductionReturnMdp(CancellationToken cancellationToken)
+    {
+        var result = await _productionReturnMdpSyncService.RunFullAsync(cancellationToken, "MANUAL");
+        return Ok(new
+        {
+            ok = true,
+            batchId = result.BatchId,
+            headRows = result.HeadRows,
+            detailRows = result.DetailRows
+        });
+    }
+
     /// <summary>
     /// S6 生产执行 KPI 手动刷新(T8 SQL Server 跨库读 → DOP DWD/KPI)。
     /// 路径 A:方老师 v5.4 KPI #22/#23 原 SQL 直发 T8。

+ 140 - 0
server/Plugins/Admin.NET.Plugin.AiDOP/MaterialWarehouse/Dto/ProductionReturnDto.cs

@@ -0,0 +1,140 @@
+namespace Admin.NET.Plugin.AiDOP.MaterialWarehouse.Dto;
+
+/// <summary>
+/// 生产退料单列表 查询入参(只读)。读 mdp_std_production_return。
+/// </summary>
+public class ProductionReturnListInput
+{
+    /// <summary>页码(从 1 开始)</summary>
+    public int Page { get; set; } = 1;
+
+    /// <summary>每页条数</summary>
+    public int PageSize { get; set; } = 10;
+
+    /// <summary>退料单号(nbr,模糊匹配)</summary>
+    public string? Nbr { get; set; }
+
+    /// <summary>SAP单号/工单号(work_ord,模糊匹配)</summary>
+    public string? WorkOrd { get; set; }
+
+    /// <summary>状态(status,精确匹配原值)</summary>
+    public string? Status { get; set; }
+
+    /// <summary>生产线(prod_line,模糊匹配)</summary>
+    public string? ProdLine { get; set; }
+
+    /// <summary>退料日期起(return_date,含当日,yyyy-MM-dd)</summary>
+    public string? DateFrom { get; set; }
+
+    /// <summary>退料日期止(return_date,含当日,yyyy-MM-dd)</summary>
+    public string? DateTo { get; set; }
+
+    /// <summary>排序字段(前端列 prop:nbr / returnDate / status / workOrd / prodLine / createTime)</summary>
+    public string? OrderBy { get; set; }
+
+    /// <summary>排序方向(asc / desc)</summary>
+    public string? OrderDir { get; set; }
+
+    /// <summary>租户 ID(前端 withAidopTenantParams 注入;为空则不按租户过滤)</summary>
+    public long? TenantId { get; set; }
+}
+
+/// <summary>
+/// 生产退料单列表 行(只读)。字段对齐前端列 prop(camelCase)。
+/// </summary>
+public class ProductionReturnListRow
+{
+    /// <summary>主键 id(mdp_std_production_return.id)</summary>
+    public long Id { get; set; }
+
+    /// <summary>退料单号(nbr)</summary>
+    public string? Nbr { get; set; }
+
+    /// <summary>退料日期(return_date)</summary>
+    public DateTime? ReturnDate { get; set; }
+
+    /// <summary>状态中文(status_desc)</summary>
+    public string? StatusDesc { get; set; }
+
+    /// <summary>SAP单号/工单号(work_ord)</summary>
+    public string? WorkOrd { get; set; }
+
+    /// <summary>部门(department + department_desc)</summary>
+    public string? DepartmentDesc { get; set; }
+
+    /// <summary>生产线(prod_line)</summary>
+    public string? ProdLine { get; set; }
+
+    /// <summary>退料人(return_user)</summary>
+    public string? ReturnUser { get; set; }
+
+    /// <summary>备注(remark)</summary>
+    public string? Remark { get; set; }
+
+    /// <summary>创建用户(create_user)</summary>
+    public string? CreateUser { get; set; }
+
+    /// <summary>创建时间(source_create_time)</summary>
+    public DateTime? CreateTime { get; set; }
+}
+
+/// <summary>
+/// 生产退料单详情(只读):头 + 明细。
+/// </summary>
+public class ProductionReturnDetailDto
+{
+    public long Id { get; set; }
+    /// <summary>退料单号</summary>
+    public string? Nbr { get; set; }
+    /// <summary>工单号(work_ord)</summary>
+    public string? WorkOrd { get; set; }
+    /// <summary>退料日期</summary>
+    public DateTime? ReturnDate { get; set; }
+    /// <summary>生产线</summary>
+    public string? ProdLine { get; set; }
+    /// <summary>部门(department + department_desc)</summary>
+    public string? DepartmentDesc { get; set; }
+    /// <summary>申请人(applicant_name)</summary>
+    public string? ApplicantName { get; set; }
+    /// <summary>退料人(return_user)</summary>
+    public string? ReturnUser { get; set; }
+    /// <summary>状态中文(status_desc)</summary>
+    public string? StatusDesc { get; set; }
+    /// <summary>备注</summary>
+    public string? Remark { get; set; }
+
+    /// <summary>明细行</summary>
+    public List<ProductionReturnDetailLineDto> Lines { get; set; } = new();
+}
+
+/// <summary>
+/// 生产退料单明细行(只读)。
+/// </summary>
+public class ProductionReturnDetailLineDto
+{
+    public long Id { get; set; }
+    /// <summary>项次(line)</summary>
+    public short Line { get; set; }
+    /// <summary>物料编码(item_num)</summary>
+    public string? ItemNum { get; set; }
+    /// <summary>物料名称(item_name)</summary>
+    public string? ItemName { get; set; }
+    /// <summary>物料规格(item_spec)</summary>
+    public string? ItemSpec { get; set; }
+    /// <summary>单位(um)</summary>
+    public string? Um { get; set; }
+    /// <summary>退料数量(qty_to)</summary>
+    public decimal? QtyTo { get; set; }
+    /// <summary>已退数(qty_rec)</summary>
+    public decimal? QtyRec { get; set; }
+    /// <summary>转入库位(location_to + location_to_desc)</summary>
+    public string? LocationTo { get; set; }
+    /// <summary>转入库位名(location_to_desc)</summary>
+    public string? LocationToDesc { get; set; }
+    /// <summary>批序号(lot_serial)</summary>
+    public string? LotSerial { get; set; }
+    /// <summary>状态中文(status_desc)</summary>
+    public string? StatusDesc { get; set; }
+    /// <summary>备注(remark)</summary>
+    public string? Remark { get; set; }
+}

+ 290 - 0
server/Plugins/Admin.NET.Plugin.AiDOP/MaterialWarehouse/ProductionReturnMdpSyncService.cs

@@ -0,0 +1,290 @@
+namespace Admin.NET.Plugin.AiDOP.MaterialWarehouse;
+
+/// <summary>
+/// S5 生产退料单 数据中台只读同步转换服务(DOP 内部,head-detail 双表,独立于 S5MdpSyncTransformService 的 KPI 管线)。
+///
+/// 源:aidopdev NbrMaster(m) + NbrDetail(dt),业务类型 Type='WOD';头明细关联 dt.NbrRecID -> m.RecID。
+///     维表 DepartmentMaster(d) / ItemMaster(i) / LocationMaster(lf,lt) 全 LEFT JOIN(LocationMaster 列名小写 location/descr)。
+/// 链路:NbrMaster/NbrDetail(WOD) 只读 → mdp_std_production_return(_detail)(typed)。
+///     不经 stg、不建 dwd(只读列表/详情);WOD=退料单业务类型有 S2 WorkOrderSchedulingService 代码实证。
+///
+/// 约束:
+///   - 只读源表,仅写 mdp_std_production_return(_detail);绝不 INSERT/UPDATE/DELETE NbrMaster/NbrDetail;不碰 S2 写路径。
+///   - 头过滤 m.Type='WOD' AND m.IsActive=1 AND m.IsReturn=0;明细 dt.Type='WOD' 且经 NbrRecID join WOD 头。
+///   - status_desc 规则本批仅:Status='C' -> '关闭',其他 -> 原值(UPPER)。
+///   - 退料人 return_user 本批取 m.User1(列表 SQL 口径);user1/user2 原样落库,页面策略后置微调。
+///   - trans_type_text 恒空(旧系统口径);不做 danjia/jiage/库存事务/状态流转。
+///   - WOD 为 0 行时转换成功完成、处理数为 0,不报错。
+/// </summary>
+public class ProductionReturnMdpSyncService : ITransient
+{
+    private const string JobCode = "S5_PRODUCTION_RETURN_MDP_SYNC";
+
+    private readonly ISqlSugarClient _db;
+
+    public ProductionReturnMdpSyncService(ISqlSugarClient db)
+    {
+        _db = db;
+    }
+
+    /// <summary>全量同步转换:源(WOD 头/明细) → 标准层(头/明细)。</summary>
+    public async Task<ProductionReturnMdpSyncResult> RunFullAsync(CancellationToken cancellationToken = default, string triggerType = "AUTO")
+    {
+        cancellationToken.ThrowIfCancellationRequested();
+        await EnsureTablesAsync();
+
+        var now = DateTime.Now;
+        var batchId = $"S5_PROD_RTN_FULL_{now:yyyyMMddHHmmss}";
+        var runLogId = await InsertRunLogAsync(batchId, now, triggerType);
+        var result = new ProductionReturnMdpSyncResult { BatchId = batchId, RunLogId = runLogId };
+
+        try
+        {
+            result.HeadRows = await TransformHeadStandardAsync(batchId, now);
+            result.DetailRows = await TransformDetailStandardAsync(batchId, now);
+            await MarkRunSuccessAsync(runLogId, now, result);
+            return result;
+        }
+        catch (Exception ex)
+        {
+            await MarkRunFailedAsync(runLogId, now, ex.Message);
+            throw;
+        }
+    }
+
+    /// <summary>防御式建表(与 UpdateScripts/1.0.213.sql 同构,幂等)。</summary>
+    private async Task EnsureTablesAsync()
+    {
+        await _db.Ado.ExecuteCommandAsync(
+            """
+            CREATE TABLE IF NOT EXISTS mdp_std_production_return (
+                id BIGINT AUTO_INCREMENT PRIMARY KEY,
+                tenant_id BIGINT NOT NULL DEFAULT 0,
+                factory_id BIGINT NULL DEFAULT 1,
+                source_system VARCHAR(50) NOT NULL DEFAULT 'AIDOP',
+                domain VARCHAR(80) NOT NULL,
+                rec_id INT NOT NULL,
+                nbr VARCHAR(24) NULL,
+                return_date DATETIME NULL,
+                status VARCHAR(8) NULL,
+                status_desc VARCHAR(20) NULL,
+                work_ord VARCHAR(64) NULL,
+                department VARCHAR(8) NULL,
+                department_desc VARCHAR(255) NULL,
+                qty_ord DECIMAL(18,5) NULL DEFAULT 0,
+                prod_line VARCHAR(8) NULL,
+                applicant_name VARCHAR(12) NULL,
+                return_user VARCHAR(255) NULL,
+                user1 TEXT NULL,
+                user2 TEXT NULL,
+                remark VARCHAR(200) NULL,
+                create_user VARCHAR(24) NULL,
+                source_create_time DATETIME NULL,
+                trans_type VARCHAR(24) NULL,
+                trans_type_text VARCHAR(50) NULL,
+                eff_date DATETIME NULL,
+                ufld1 VARCHAR(50) NULL,
+                source_biz_key VARCHAR(200) NULL,
+                sync_batch_id VARCHAR(100) NOT NULL,
+                sync_time DATETIME NOT NULL,
+                create_time DATETIME DEFAULT CURRENT_TIMESTAMP,
+                update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
+                UNIQUE KEY uk_mdp_std_prod_rtn (tenant_id, domain, rec_id),
+                KEY idx_mdp_std_prod_rtn_nbr (tenant_id, nbr),
+                KEY idx_mdp_std_prod_rtn_date (tenant_id, return_date),
+                KEY idx_mdp_std_prod_rtn_status (tenant_id, status),
+                KEY idx_mdp_std_prod_rtn_workord (tenant_id, work_ord),
+                KEY idx_mdp_std_prod_rtn_prodline (tenant_id, prod_line),
+                KEY idx_mdp_std_prod_rtn_dept (tenant_id, department)
+            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='S5生产退料单头标准层'
+            """);
+        await _db.Ado.ExecuteCommandAsync(
+            """
+            CREATE TABLE IF NOT EXISTS mdp_std_production_return_detail (
+                id BIGINT AUTO_INCREMENT PRIMARY KEY,
+                tenant_id BIGINT NOT NULL DEFAULT 0,
+                std_head_id BIGINT NULL,
+                domain VARCHAR(80) NOT NULL,
+                nbr_rec_id INT NOT NULL,
+                rec_id INT NULL,
+                line SMALLINT NOT NULL DEFAULT 0,
+                item_num VARCHAR(24) NULL,
+                item_name VARCHAR(200) NULL,
+                item_spec VARCHAR(200) NULL,
+                um VARCHAR(8) NULL,
+                qty_to DECIMAL(18,5) NULL DEFAULT 0,
+                qty_rec DECIMAL(18,5) NULL DEFAULT 0,
+                location_from VARCHAR(8) NULL,
+                location_from_desc VARCHAR(255) NULL,
+                location_to VARCHAR(8) NULL,
+                location_to_desc VARCHAR(255) NULL,
+                lot_serial VARCHAR(120) NULL,
+                status VARCHAR(8) NULL,
+                status_desc VARCHAR(20) NULL,
+                remark VARCHAR(500) NULL,
+                work_ord VARCHAR(64) NULL,
+                source_biz_key VARCHAR(200) NULL,
+                sync_batch_id VARCHAR(100) NOT NULL,
+                sync_time DATETIME NOT NULL,
+                create_time DATETIME DEFAULT CURRENT_TIMESTAMP,
+                update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
+                UNIQUE KEY uk_mdp_std_prod_rtn_dtl (tenant_id, domain, nbr_rec_id, line),
+                KEY idx_mdp_std_prod_rtn_dtl_head (tenant_id, std_head_id),
+                KEY idx_mdp_std_prod_rtn_dtl_item (tenant_id, item_num),
+                KEY idx_mdp_std_prod_rtn_dtl_locto (tenant_id, location_to),
+                KEY idx_mdp_std_prod_rtn_dtl_lot (tenant_id, lot_serial)
+            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='S5生产退料单明细标准层'
+            """);
+    }
+
+    /// <summary>
+    /// 标准化头:NbrMaster(WOD) + DepartmentMaster -> mdp_std_production_return。返回处理头行数。
+    /// SQL 由旧系统头 SQL 翻译(SQL Server -&gt; MySQL):IsNull-&gt;IFNULL、upper() 保留、
+    /// rtrim(a+' '+b)-&gt;TRIM(CONCAT(...))、with(nolock) 去除。
+    /// </summary>
+    private async Task<int> TransformHeadStandardAsync(string batchId, DateTime now)
+    {
+        var rows = await _db.Ado.GetIntAsync(
+            "SELECT COUNT(1) FROM NbrMaster m WHERE m.Type='WOD' AND m.IsActive=1 AND m.IsReturn=0");
+        await _db.Ado.ExecuteCommandAsync(
+            """
+            INSERT INTO mdp_std_production_return
+            (tenant_id, factory_id, source_system, domain, rec_id, nbr, return_date, status, status_desc,
+             work_ord, department, department_desc, qty_ord, prod_line, applicant_name, return_user,
+             user1, user2, remark, create_user, source_create_time, trans_type, trans_type_text,
+             eff_date, ufld1, source_biz_key, sync_batch_id, sync_time)
+            SELECT
+                IFNULL(m.tenant_id, 0), 1, 'AIDOP', m.Domain, m.RecID, m.Nbr, m.Date,
+                UPPER(IFNULL(m.Status, '')),
+                CASE WHEN UPPER(IFNULL(m.Status,''))='C' THEN '关闭' ELSE UPPER(IFNULL(m.Status,'')) END,
+                m.WorkOrd, m.Department, TRIM(CONCAT(m.Department, ' ', IFNULL(d.Descr, ''))),
+                m.QtyOrd, m.ProdLine, m.Name, CAST(m.User1 AS CHAR),
+                CAST(m.User1 AS CHAR), CAST(m.User2 AS CHAR), m.Remark, m.CreateUser, m.CreateTime,
+                m.TransType, '', m.EffDate, m.Ufld1,
+                CONCAT(m.Domain, ':', m.RecID), @BatchId, @Now
+            FROM NbrMaster m
+            LEFT JOIN DepartmentMaster d ON d.Domain = m.Domain AND d.Department = m.Department
+            WHERE m.Type='WOD' AND m.IsActive=1 AND m.IsReturn=0
+            ON DUPLICATE KEY UPDATE
+                factory_id=VALUES(factory_id), nbr=VALUES(nbr), return_date=VALUES(return_date),
+                status=VALUES(status), status_desc=VALUES(status_desc), work_ord=VALUES(work_ord),
+                department=VALUES(department), department_desc=VALUES(department_desc), qty_ord=VALUES(qty_ord),
+                prod_line=VALUES(prod_line), applicant_name=VALUES(applicant_name), return_user=VALUES(return_user),
+                user1=VALUES(user1), user2=VALUES(user2), remark=VALUES(remark), create_user=VALUES(create_user),
+                source_create_time=VALUES(source_create_time), trans_type=VALUES(trans_type),
+                trans_type_text=VALUES(trans_type_text), eff_date=VALUES(eff_date), ufld1=VALUES(ufld1),
+                sync_batch_id=VALUES(sync_batch_id), sync_time=VALUES(sync_time), update_time=CURRENT_TIMESTAMP
+            """,
+            new SugarParameter("@BatchId", batchId),
+            new SugarParameter("@Now", now));
+        return rows;
+    }
+
+    /// <summary>
+    /// 标准化明细:NbrDetail(WOD) + ItemMaster + LocationMaster -> mdp_std_production_return_detail(回填 std_head_id)。
+    /// 返回处理明细行数。LocationMaster 列名小写 location/descr,分别 join LocationFrom/LocationTo。
+    /// </summary>
+    private async Task<int> TransformDetailStandardAsync(string batchId, DateTime now)
+    {
+        var rows = await _db.Ado.GetIntAsync(
+            """
+            SELECT COUNT(1) FROM NbrDetail dt
+            JOIN NbrMaster m ON m.RecID = dt.NbrRecID AND m.Type='WOD' AND m.IsActive=1 AND m.IsReturn=0
+            WHERE dt.Type='WOD'
+            """);
+        await _db.Ado.ExecuteCommandAsync(
+            """
+            INSERT INTO mdp_std_production_return_detail
+            (tenant_id, std_head_id, domain, nbr_rec_id, rec_id, line, item_num, item_name, item_spec, um,
+             qty_to, qty_rec, location_from, location_from_desc, location_to, location_to_desc,
+             lot_serial, status, status_desc, remark, work_ord, source_biz_key, sync_batch_id, sync_time)
+            SELECT
+                IFNULL(dt.tenant_id, 0), h.id, m.Domain, dt.NbrRecID, dt.RecID, dt.Line,
+                dt.ItemNum, i.Descr, i.Descr1, dt.UM,
+                dt.QtyTo, dt.QtyRec, dt.LocationFrom, lf.descr, dt.LocationTo, lt.descr,
+                CAST(dt.LotSerial AS CHAR), UPPER(IFNULL(dt.Status, '')),
+                CASE WHEN UPPER(IFNULL(dt.Status,''))='C' THEN '关闭' ELSE UPPER(IFNULL(dt.Status,'')) END,
+                CAST(dt.Remark AS CHAR), dt.WorkOrd,
+                CONCAT(m.Domain, ':', dt.NbrRecID, ':', dt.Line), @BatchId, @Now
+            FROM NbrDetail dt
+            JOIN NbrMaster m ON m.RecID = dt.NbrRecID AND m.Type='WOD' AND m.IsActive=1 AND m.IsReturn=0
+            LEFT JOIN ItemMaster i ON i.Domain = dt.Domain AND i.ItemNum = dt.ItemNum
+            LEFT JOIN LocationMaster lf ON lf.tenant_id = IFNULL(dt.tenant_id, 0) AND lf.location = dt.LocationFrom
+            LEFT JOIN LocationMaster lt ON lt.tenant_id = IFNULL(dt.tenant_id, 0) AND lt.location = dt.LocationTo
+            LEFT JOIN mdp_std_production_return h ON h.tenant_id = IFNULL(dt.tenant_id, 0) AND h.domain = m.Domain AND h.rec_id = dt.NbrRecID
+            WHERE dt.Type='WOD'
+            ON DUPLICATE KEY UPDATE
+                std_head_id=VALUES(std_head_id), rec_id=VALUES(rec_id), item_num=VALUES(item_num),
+                item_name=VALUES(item_name), item_spec=VALUES(item_spec), um=VALUES(um),
+                qty_to=VALUES(qty_to), qty_rec=VALUES(qty_rec), location_from=VALUES(location_from),
+                location_from_desc=VALUES(location_from_desc), location_to=VALUES(location_to),
+                location_to_desc=VALUES(location_to_desc), lot_serial=VALUES(lot_serial),
+                status=VALUES(status), status_desc=VALUES(status_desc), remark=VALUES(remark), work_ord=VALUES(work_ord),
+                sync_batch_id=VALUES(sync_batch_id), sync_time=VALUES(sync_time), update_time=CURRENT_TIMESTAMP
+            """,
+            new SugarParameter("@BatchId", batchId),
+            new SugarParameter("@Now", now));
+        return rows;
+    }
+
+    private async Task<long> InsertRunLogAsync(string batchId, DateTime startedAt, string triggerType)
+    {
+        await _db.Ado.ExecuteCommandAsync(
+            """
+            INSERT INTO mdp_transform_run_log
+            (tenant_id, job_code, job_name, trigger_type, batch_id, status, start_time)
+            VALUES (0, @JobCode, 'S5生产退料单MDP同步与标准化转换', @TriggerType, @BatchId, 'RUNNING', @StartTime)
+            """,
+            new SugarParameter("@JobCode", JobCode),
+            new SugarParameter("@TriggerType", NormalizeTriggerType(triggerType)),
+            new SugarParameter("@BatchId", batchId),
+            new SugarParameter("@StartTime", startedAt));
+        return await _db.Ado.GetLongAsync(
+            "SELECT id FROM mdp_transform_run_log WHERE batch_id=@BatchId ORDER BY id DESC LIMIT 1",
+            new List<SugarParameter> { new("@BatchId", batchId) });
+    }
+
+    private async Task MarkRunSuccessAsync(long runLogId, DateTime startedAt, ProductionReturnMdpSyncResult result)
+    {
+        var finishedAt = DateTime.Now;
+        await _db.Ado.ExecuteCommandAsync(
+            """
+            UPDATE mdp_transform_run_log
+            SET status='SUCCESS', end_time=@EndTime, duration_ms=@DurationMs,
+                stage_rows=0, standard_rows=@StandardRows, dwd_rows=0, update_time=CURRENT_TIMESTAMP
+            WHERE id=@Id
+            """,
+            new SugarParameter("@EndTime", finishedAt),
+            new SugarParameter("@DurationMs", (int)(finishedAt - startedAt).TotalMilliseconds),
+            new SugarParameter("@StandardRows", result.HeadRows + result.DetailRows),
+            new SugarParameter("@Id", runLogId));
+    }
+
+    private async Task MarkRunFailedAsync(long runLogId, DateTime startedAt, string message)
+    {
+        var finishedAt = DateTime.Now;
+        await _db.Ado.ExecuteCommandAsync(
+            """
+            UPDATE mdp_transform_run_log
+            SET status='FAILED', end_time=@EndTime, duration_ms=@DurationMs,
+                error_message=@ErrorMessage, update_time=CURRENT_TIMESTAMP
+            WHERE id=@Id
+            """,
+            new SugarParameter("@EndTime", finishedAt),
+            new SugarParameter("@DurationMs", (int)(finishedAt - startedAt).TotalMilliseconds),
+            new SugarParameter("@ErrorMessage", message.Length > 2000 ? message[..2000] : message),
+            new SugarParameter("@Id", runLogId));
+    }
+
+    private static string NormalizeTriggerType(string? triggerType)
+        => string.IsNullOrWhiteSpace(triggerType) ? "AUTO" : triggerType.Trim().ToUpperInvariant();
+}
+
+/// <summary>生产退料单 MDP 同步转换结果。</summary>
+public sealed class ProductionReturnMdpSyncResult
+{
+    public long RunLogId { get; set; }
+    public string BatchId { get; set; } = string.Empty;
+    public int HeadRows { get; set; }
+    public int DetailRows { get; set; }
+}

+ 187 - 0
server/Plugins/Admin.NET.Plugin.AiDOP/MaterialWarehouse/ProductionReturnService.cs

@@ -0,0 +1,187 @@
+using Admin.NET.Plugin.AiDOP.MaterialWarehouse.Dto;
+
+namespace Admin.NET.Plugin.AiDOP.MaterialWarehouse;
+
+/// <summary>
+/// S5 生产退料单 只读 list/detail 服务。
+///
+/// 数据源:DOP 数据中台标准层 mdp_std_production_return(头)/ mdp_std_production_return_detail(明细)。
+/// 由 ProductionReturnMdpSyncService 从 aidopdev.NbrMaster/NbrDetail Type='WOD' 同步标准化而来。
+///
+/// 本服务仅 SELECT:无新增/编辑/删除/退料确认/入库/库存事务/状态流转。
+/// 当前上游未产 WOD 单据,标准层为空,list 返回空数组、detail 返回 null(前端空态)。
+/// </summary>
+[ApiDescriptionSettings(Order = 306, Description = "生产退料单")]
+[Route("api/ProductionReturn")]
+[AllowAnonymous]
+[NonUnify]
+public class ProductionReturnService : IDynamicApiController, ITransient
+{
+    private readonly ISqlSugarClient _db;
+
+    public ProductionReturnService(ISqlSugarClient db)
+    {
+        _db = db;
+    }
+
+    /// <summary>
+    /// 生产退料单列表(只读分页查询)。
+    /// </summary>
+    [DisplayName("生产退料单列表")]
+    [HttpGet("list")]
+    public async Task<object> GetList([FromQuery] ProductionReturnListInput input)
+    {
+        var page = input.Page <= 0 ? 1 : input.Page;
+        var pageSize = input.PageSize <= 0 ? 10 : input.PageSize;
+        var offset = (page - 1) * pageSize;
+
+        var where = new List<string> { "1=1" };
+        var pars = new List<SugarParameter>();
+
+        if (input.TenantId is > 0)
+        {
+            where.Add("m.tenant_id = @TenantId");
+            pars.Add(new SugarParameter("@TenantId", input.TenantId));
+        }
+        if (!string.IsNullOrWhiteSpace(input.Nbr))
+        {
+            where.Add("m.nbr LIKE @Nbr");
+            pars.Add(new SugarParameter("@Nbr", $"%{input.Nbr.Trim()}%"));
+        }
+        if (!string.IsNullOrWhiteSpace(input.WorkOrd))
+        {
+            where.Add("m.work_ord LIKE @WorkOrd");
+            pars.Add(new SugarParameter("@WorkOrd", $"%{input.WorkOrd.Trim()}%"));
+        }
+        if (!string.IsNullOrWhiteSpace(input.Status))
+        {
+            where.Add("m.status = @Status");
+            pars.Add(new SugarParameter("@Status", input.Status.Trim()));
+        }
+        if (!string.IsNullOrWhiteSpace(input.ProdLine))
+        {
+            where.Add("m.prod_line LIKE @ProdLine");
+            pars.Add(new SugarParameter("@ProdLine", $"%{input.ProdLine.Trim()}%"));
+        }
+        if (!string.IsNullOrWhiteSpace(input.DateFrom))
+        {
+            where.Add("m.return_date >= @DateFrom");
+            pars.Add(new SugarParameter("@DateFrom", $"{input.DateFrom.Trim()} 00:00:00"));
+        }
+        if (!string.IsNullOrWhiteSpace(input.DateTo))
+        {
+            where.Add("m.return_date <= @DateTo");
+            pars.Add(new SugarParameter("@DateTo", $"{input.DateTo.Trim()} 23:59:59"));
+        }
+
+        var whereSql = string.Join(" AND ", where);
+
+        var total = await _db.Ado.GetIntAsync(
+            $"SELECT COUNT(1) FROM mdp_std_production_return m WHERE {whereSql}", pars);
+
+        var list = await _db.Ado.SqlQueryAsync<ProductionReturnListRow>(
+            $"""
+            SELECT
+                m.id                 AS Id,
+                m.nbr                AS Nbr,
+                m.return_date        AS ReturnDate,
+                m.status_desc        AS StatusDesc,
+                m.work_ord           AS WorkOrd,
+                m.department_desc    AS DepartmentDesc,
+                m.prod_line          AS ProdLine,
+                m.return_user        AS ReturnUser,
+                m.remark             AS Remark,
+                m.create_user        AS CreateUser,
+                m.source_create_time AS CreateTime
+            FROM mdp_std_production_return m
+            WHERE {whereSql}
+            ORDER BY {BuildOrderBy(input.OrderBy, input.OrderDir)}
+            LIMIT {pageSize} OFFSET {offset}
+            """,
+            pars);
+
+        return new { total, page, pageSize, list };
+    }
+
+    /// <summary>
+    /// 生产退料单详情(只读:头 + 明细)。查不到返回 null。
+    /// </summary>
+    [DisplayName("生产退料单详情")]
+    [HttpGet("detail")]
+    public async Task<ProductionReturnDetailDto?> GetDetail([FromQuery] long id, [FromQuery] long? tenantId)
+    {
+        if (id <= 0) return null;
+
+        var headPars = new List<SugarParameter> { new("@Id", id) };
+        var headWhere = "m.id = @Id";
+        if (tenantId is > 0)
+        {
+            headWhere += " AND m.tenant_id = @TenantId";
+            headPars.Add(new SugarParameter("@TenantId", tenantId));
+        }
+
+        var head = await _db.Ado.SqlQuerySingleAsync<ProductionReturnDetailDto>(
+            $"""
+            SELECT
+                m.id              AS Id,
+                m.nbr             AS Nbr,
+                m.work_ord        AS WorkOrd,
+                m.return_date     AS ReturnDate,
+                m.prod_line       AS ProdLine,
+                m.department_desc AS DepartmentDesc,
+                m.applicant_name  AS ApplicantName,
+                m.return_user     AS ReturnUser,
+                m.status_desc     AS StatusDesc,
+                m.remark          AS Remark
+            FROM mdp_std_production_return m
+            WHERE {headWhere}
+            LIMIT 1
+            """,
+            headPars);
+
+        if (head == null || head.Id <= 0) return null;
+
+        head.Lines = await _db.Ado.SqlQueryAsync<ProductionReturnDetailLineDto>(
+            """
+            SELECT
+                d.id               AS Id,
+                d.line             AS Line,
+                d.item_num         AS ItemNum,
+                d.item_name        AS ItemName,
+                d.item_spec        AS ItemSpec,
+                d.um               AS Um,
+                d.qty_to           AS QtyTo,
+                d.qty_rec          AS QtyRec,
+                d.location_to      AS LocationTo,
+                d.location_to_desc AS LocationToDesc,
+                d.lot_serial       AS LotSerial,
+                d.status_desc      AS StatusDesc,
+                d.remark           AS Remark
+            FROM mdp_std_production_return_detail d
+            WHERE d.std_head_id = @HeadId
+            ORDER BY d.line ASC, d.id ASC
+            """,
+            new List<SugarParameter> { new("@HeadId", head.Id) });
+
+        return head;
+    }
+
+    /// <summary>
+    /// 排序白名单:仅允许按已展示列排序,杜绝 SQL 注入;非法字段回落默认。
+    /// </summary>
+    private static string BuildOrderBy(string? orderBy, string? orderDir)
+    {
+        var column = orderBy switch
+        {
+            "nbr" => "m.nbr",
+            "returnDate" => "m.return_date",
+            "status" => "m.status",
+            "workOrd" => "m.work_ord",
+            "prodLine" => "m.prod_line",
+            "createTime" => "m.source_create_time",
+            _ => "m.return_date",
+        };
+        var direction = string.Equals(orderDir, "asc", StringComparison.OrdinalIgnoreCase) ? "ASC" : "DESC";
+        return $"{column} {direction}, m.id DESC";
+    }
+}

+ 1 - 1
server/Plugins/Admin.NET.Plugin.AiDOP/SeedData/SysMenuSeedData.cs

@@ -543,7 +543,7 @@ public class SysMenuSeedData : ISqlSugarEntitySeedData<SysMenu>
         yield return new SysMenu { Id = warehouseBase + 1, Pid = warehouseDirId, Title = "委外发料单", Path = "/aidop/s5/warehouse/outsource-issue", Name = "aidopS5WarehouseOutsourceIssue", Component = "/aidop/s5/warehouse/outsourceIssueList", Icon = "ele-Document", Type = MenuTypeEnum.Menu, CreateTime = ct, OrderNo = 10, Remark = "S5 委外发料单(只读骨架,真实数据源待补证)" };
         yield return new SysMenu { Id = warehouseBase + 2, Pid = warehouseDirId, Title = "采购收货单", Path = "/aidop/s5/warehouse/purchase-receipt", Name = "aidopS5WarehousePurchaseReceipt", Component = "/aidop/s5/warehouse/purchaseReceiptList", Icon = "ele-Document", Type = MenuTypeEnum.Menu, CreateTime = ct, OrderNo = 20, Remark = "S5 采购收货单(只读列表,数据中台标准层 mdp_std_purchase_receipt)" };
         yield return new SysMenu { Id = warehouseBase + 3, Pid = warehouseDirId, Title = "生产领料单", Path = "/aidop/s5/warehouse/production-issue", Name = "aidopS5WarehouseProductionIssue", Component = placeholderComponent, Icon = "ele-Document", Type = MenuTypeEnum.Menu, CreateTime = ct, OrderNo = 30, Remark = "S5 生产领料单(真实页面待交付)" };
-        yield return new SysMenu { Id = warehouseBase + 4, Pid = warehouseDirId, Title = "生产退料单", Path = "/aidop/s5/warehouse/production-return", Name = "aidopS5WarehouseProductionReturn", Component = placeholderComponent, Icon = "ele-Document", Type = MenuTypeEnum.Menu, CreateTime = ct, OrderNo = 40, Remark = "S5 生产退料单(真实页面待交付)" };
+        yield return new SysMenu { Id = warehouseBase + 4, Pid = warehouseDirId, Title = "生产退料单", Path = "/aidop/s5/warehouse/production-return", Name = "aidopS5WarehouseProductionReturn", Component = "/aidop/s5/warehouse/productionReturnList", Icon = "ele-Document", Type = MenuTypeEnum.Menu, CreateTime = ct, OrderNo = 40, Remark = "S5 生产退料单(只读 head-detail,数据中台标准层 mdp_std_production_return)" };
         yield return new SysMenu { Id = warehouseBase + 5, Pid = warehouseDirId, Title = "生产入库单", Path = "/aidop/s5/warehouse/production-receipt", Name = "aidopS5WarehouseProductionReceipt", Component = placeholderComponent, Icon = "ele-Document", Type = MenuTypeEnum.Menu, CreateTime = ct, OrderNo = 50, Remark = "S5 生产入库单(真实页面待交付)" };
 
         // 库存数据 (1322000000017) 下 6 个三级