const fs = require('fs') const path = require('path') const root = path.resolve(__dirname, '..') function read(file) { return fs.readFileSync(path.join(root, file), 'utf8') } function assertMatch(message, content, pattern) { if (!pattern.test(content)) { throw new Error(message) } } function assertNotMatch(message, content, pattern) { if (pattern.test(content)) { throw new Error(message) } } function section(content, startMarker, endMarker) { const start = content.indexOf(startMarker) if (start < 0) { throw new Error(`未找到开始标记: ${startMarker}`) } const end = content.indexOf(endMarker, start) if (end < 0) { throw new Error(`未找到结束标记: ${endMarker}`) } return content.slice(start, end) } const stockView = read('ruoyi-ui/src/views/bas/stock/index.vue') const detailDialog = section(stockView, '', '') assertMatch('库存子表必须显示项目号', stockView, /]*label="项目号"[^>]*prop="projectNo"/) assertMatch('子作业 ID 输入框必须只读', detailDialog, /v-model="detailForm\.jobDetailId"[^>]*readonly/) assertMatch('入库子单 ID 输入框必须只读', detailDialog, /v-model="detailForm\.stockinDetailId"[^>]*readonly/) assertMatch('库存明细物料状态必须使用开关', detailDialog, /') assertNotMatch('库存明细更新 SQL 不得更新子作业 ID', updateDetail, /job_detail_id\s*=/) assertNotMatch('库存明细更新 SQL 不得更新入库子单 ID', updateDetail, /stockin_detail_id\s*=/) const createStockoutView = read('ruoyi-ui/src/views/out/create/index.vue') const createStockQuery = section(createStockoutView, 'stockQuery: {', 'selectedStocks:') assertMatch('出库创建页候选库存必须固定筛选正常库存状态', createStockQuery, /stockStatus:\s*'1'/) assertMatch('出库创建页候选库存必须固定筛选正常物料状态', createStockQuery, /productStatus:\s*'1'/) assertMatch('出库创建页必须使用双正常筛选对象查询库存', createStockoutView, /listStockDetail\(this\.stockQuery\)/) const stockoutView = read('ruoyi-ui/src/views/out/stockout/index.vue') const manualStockQuery = section(stockoutView, 'listStockDetail({', '}).then(res =>') assertMatch('手动分配候选库存必须筛选正常库存状态', manualStockQuery, /stockStatus:\s*'1'/) assertMatch('手动分配候选库存必须筛选正常物料状态', manualStockQuery, /productStatus:\s*'1'/) console.log('WCS、库存与出库需求静态检查通过')