From 768b18c22a927d000d5e549fb11f6838ca966e66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A0=82=E7=B3=96?= <2178503051@qq.com> Date: Wed, 17 Jun 2026 15:09:08 +0800 Subject: [PATCH] =?UTF-8?q?feat(cost+wms):=20=E6=96=B0=E5=A2=9E=E7=94=9F?= =?UTF-8?q?=E4=BA=A7=E6=8C=87=E6=A0=87=E6=A0=87=E7=AD=BE=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E5=B9=B6=E4=BC=98=E5=8C=96=E9=92=A2=E5=8D=B7=E6=88=90=E6=9C=AC?= =?UTF-8?q?=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 为生产指标实体、BO、VO新增tags标签字段并完善MyBatis映射 2. 在生产指标查询中添加标签模糊筛选条件 3. 新增生产指标计算结果API接口 4. 优化成本综合页面:支持标签字段的增改查,新增指标结果批量保存逻辑 5. 移除废弃的costDataService文件,重构钢卷详情页成本展示模块,新增加工路径可视化和吨钢成本计算展示 6. 注释并禁用了原有的检验任务相关代码逻辑 --- .../com/klp/cost/domain/CostProdMetric.java | 4 + .../klp/cost/domain/bo/CostProdMetricBo.java | 4 + .../domain/bo/CostProdMetricResultBo.java | 3 + .../klp/cost/domain/vo/CostProdMetricVo.java | 5 + .../impl/CostProdMetricServiceImpl.java | 1 + .../mapper/cost/CostProdMetricMapper.xml | 1 + klp-ui/src/api/cost/prodMetricResult.js | 53 ++ klp-ui/src/views/cost/comprehensive.vue | 45 +- klp-ui/src/views/cost/costDataService.js | 344 --------- .../coil/info/components/CostInfoSection.vue | 723 +++++++++++++++--- klp-ui/src/views/wms/coil/info/index.vue | 36 +- 11 files changed, 748 insertions(+), 471 deletions(-) create mode 100644 klp-ui/src/api/cost/prodMetricResult.js delete mode 100644 klp-ui/src/views/cost/costDataService.js diff --git a/klp-cost/src/main/java/com/klp/cost/domain/CostProdMetric.java b/klp-cost/src/main/java/com/klp/cost/domain/CostProdMetric.java index 658837a3..dc964933 100644 --- a/klp-cost/src/main/java/com/klp/cost/domain/CostProdMetric.java +++ b/klp-cost/src/main/java/com/klp/cost/domain/CostProdMetric.java @@ -53,6 +53,10 @@ public class CostProdMetric extends BaseEntity { * 备注 */ private String remark; + /** + * 标签 + */ + private String tags; /** * 删除标识 0=正常 2=删除 */ diff --git a/klp-cost/src/main/java/com/klp/cost/domain/bo/CostProdMetricBo.java b/klp-cost/src/main/java/com/klp/cost/domain/bo/CostProdMetricBo.java index 27847d6d..a82ff088 100644 --- a/klp-cost/src/main/java/com/klp/cost/domain/bo/CostProdMetricBo.java +++ b/klp-cost/src/main/java/com/klp/cost/domain/bo/CostProdMetricBo.java @@ -58,5 +58,9 @@ public class CostProdMetricBo extends BaseEntity { */ private String remark; + /** + * 标签 + */ + private String tags; } diff --git a/klp-cost/src/main/java/com/klp/cost/domain/bo/CostProdMetricResultBo.java b/klp-cost/src/main/java/com/klp/cost/domain/bo/CostProdMetricResultBo.java index c839cfc8..58e8c916 100644 --- a/klp-cost/src/main/java/com/klp/cost/domain/bo/CostProdMetricResultBo.java +++ b/klp-cost/src/main/java/com/klp/cost/domain/bo/CostProdMetricResultBo.java @@ -9,6 +9,7 @@ import java.math.BigDecimal; import java.util.Date; import java.util.List; import com.fasterxml.jackson.annotation.JsonFormat; +import org.springframework.format.annotation.DateTimeFormat; /** * 生产指标计算结果业务对象 cost_prod_metric_result @@ -39,6 +40,8 @@ public class CostProdMetricResultBo extends BaseEntity { /** * 计算日期 */ + @DateTimeFormat(pattern = "yyyy-MM-dd") + @JsonFormat(pattern = "yyyy-MM-dd") private Date metricDate; /** diff --git a/klp-cost/src/main/java/com/klp/cost/domain/vo/CostProdMetricVo.java b/klp-cost/src/main/java/com/klp/cost/domain/vo/CostProdMetricVo.java index 20a76861..880d4eb3 100644 --- a/klp-cost/src/main/java/com/klp/cost/domain/vo/CostProdMetricVo.java +++ b/klp-cost/src/main/java/com/klp/cost/domain/vo/CostProdMetricVo.java @@ -69,5 +69,10 @@ public class CostProdMetricVo { @ExcelProperty(value = "备注") private String remark; + /** + * 标签 + */ + @ExcelProperty(value = "标签") + private String tags; } diff --git a/klp-cost/src/main/java/com/klp/cost/service/impl/CostProdMetricServiceImpl.java b/klp-cost/src/main/java/com/klp/cost/service/impl/CostProdMetricServiceImpl.java index a837d0d4..f280a9fe 100644 --- a/klp-cost/src/main/java/com/klp/cost/service/impl/CostProdMetricServiceImpl.java +++ b/klp-cost/src/main/java/com/klp/cost/service/impl/CostProdMetricServiceImpl.java @@ -67,6 +67,7 @@ public class CostProdMetricServiceImpl implements ICostProdMetricService { lqw.eq(StringUtils.isNotBlank(bo.getMetricFormula()), CostProdMetric::getMetricFormula, bo.getMetricFormula()); lqw.eq(bo.getMetricValue() != null, CostProdMetric::getMetricValue, bo.getMetricValue()); lqw.eq(bo.getUsePrice() != null, CostProdMetric::getUsePrice, bo.getUsePrice()); + lqw.like(StringUtils.isNotBlank(bo.getTags()), CostProdMetric::getTags, bo.getTags()); return lqw; } diff --git a/klp-cost/src/main/resources/mapper/cost/CostProdMetricMapper.xml b/klp-cost/src/main/resources/mapper/cost/CostProdMetricMapper.xml index 1a62c69c..6b60ae7b 100644 --- a/klp-cost/src/main/resources/mapper/cost/CostProdMetricMapper.xml +++ b/klp-cost/src/main/resources/mapper/cost/CostProdMetricMapper.xml @@ -13,6 +13,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + diff --git a/klp-ui/src/api/cost/prodMetricResult.js b/klp-ui/src/api/cost/prodMetricResult.js new file mode 100644 index 00000000..c06e8e51 --- /dev/null +++ b/klp-ui/src/api/cost/prodMetricResult.js @@ -0,0 +1,53 @@ +import request from '@/utils/request' + +// 查询生产指标计算结果列表 +export function listProdMetricResult(query) { + return request({ + url: '/cost/prodMetricResult/list', + method: 'get', + params: query + }) +} + +// 查询生产指标计算结果详细 +export function getProdMetricResult(resultId) { + return request({ + url: '/cost/prodMetricResult/' + resultId, + method: 'get' + }) +} + +// 新增生产指标计算结果 +export function addProdMetricResult(data) { + return request({ + url: '/cost/prodMetricResult', + method: 'post', + data: data + }) +} + +// 修改生产指标计算结果 +export function updateProdMetricResult(data) { + return request({ + url: '/cost/prodMetricResult', + method: 'put', + data: data + }) +} + +// 删除生产指标计算结果 +export function delProdMetricResult(resultId) { + return request({ + url: '/cost/prodMetricResult/' + resultId, + method: 'delete' + }) +} + +// 批量保存计算结果(先删后插) +export function batchSaveProdMetricResult(data) { + return request({ + url: '/cost/prodMetricResult/batch', + method: 'post', + data: data + }) +} diff --git a/klp-ui/src/views/cost/comprehensive.vue b/klp-ui/src/views/cost/comprehensive.vue index 1956dca0..738b9696 100644 --- a/klp-ui/src/views/cost/comprehensive.vue +++ b/klp-ui/src/views/cost/comprehensive.vue @@ -180,6 +180,7 @@ + @@ -206,6 +207,7 @@ + @@ -324,6 +326,7 @@ import { listProdReport, getProdReport, addProdReport, updateProdReport, delProdReport, copyProdReport } from "@/api/cost/prodReport" import { listProdDetail, batchSaveProdDetail } from "@/api/cost/prodDetail" import { listProdMetric, addProdMetric, updateProdMetric, delProdMetric, getProdMetric } from "@/api/cost/prodMetric" +import { listProdMetricResult, batchSaveProdMetricResult } from "@/api/cost/prodMetricResult" import { listItem } from "@/api/cost/item" import { listLightPendingAction } from "@/api/wms/pendingAction" import { getCoilStatisticsList } from "@/api/wms/coil" @@ -608,7 +611,7 @@ export default { }, doPickMetric() { this.selMp.forEach(m => { - this.allCols.push({ $type: 'metric', metricId: m.metricId, metricName: m.metricName, metricFormula: m.metricFormula, unit: m.remark||'', isShift: false, color: null, metricValue: m.metricValue, usePrice: m.usePrice }) + this.allCols.push({ $type: 'metric', metricId: m.metricId, metricName: m.metricName, metricFormula: m.metricFormula, unit: m.remark||'', tags: m.tags || '', isShift: false, color: null, metricValue: m.metricValue, usePrice: m.usePrice }) }) this.metricPickOpen = false }, @@ -618,15 +621,15 @@ export default { this.mgrList = this._allMetricDefs || [] this.mgrOpen = true }, - addMetricDef() { this.defForm = { metricId: null, metricName: '', metricFormula: '', unit: '', usePrice: 0, metricValue: '' }; this.defTitle = '新增指标'; this.defOpen = true }, - editMetricDef(row) { this.defForm = { metricId: row.metricId, metricName: row.metricName, metricFormula: row.metricFormula, unit: row.remark||'', usePrice: row.usePrice || 0, metricValue: row.metricValue || '' }; this.defTitle = '编辑指标'; this.defOpen = true }, + addMetricDef() { this.defForm = { metricId: null, metricName: '', metricFormula: '', unit: '', tags: '', usePrice: 0, metricValue: '' }; this.defTitle = '新增指标'; this.defOpen = true }, + editMetricDef(row) { this.defForm = { metricId: row.metricId, metricName: row.metricName, metricFormula: row.metricFormula, unit: row.remark||'', tags: row.tags || '', usePrice: row.usePrice || 0, metricValue: row.metricValue || '' }; this.defTitle = '编辑指标'; this.defOpen = true }, async submitMetricDef() { const f = this.defForm if (!f.metricName) { this.$modal.msgWarning('请输入指标名称'); return } if (f.metricId) { - await updateProdMetric({ metricId: f.metricId, metricName: f.metricName, metricFormula: f.metricFormula, remark: f.unit, usePrice: f.usePrice, metricValue: f.metricValue || 0 }) + await updateProdMetric({ metricId: f.metricId, metricName: f.metricName, metricFormula: f.metricFormula, remark: f.unit, tags: f.tags || '', usePrice: f.usePrice, metricValue: f.metricValue || 0 }) } else { - await addProdMetric({ reportId: this.activeReport.reportId, metricCode: f.metricName, metricName: f.metricName, metricFormula: f.metricFormula, metricValue: f.metricValue || 0, remark: f.unit || '', usePrice: f.usePrice }) + await addProdMetric({ reportId: this.activeReport.reportId, metricCode: f.metricName, metricName: f.metricName, metricFormula: f.metricFormula, metricValue: f.metricValue || 0, remark: f.unit || '', tags: f.tags || '', usePrice: f.usePrice }) } this.defOpen = false; this.$modal.msgSuccess('保存成功') await this.openMetricMgr() @@ -676,7 +679,7 @@ export default { // ensure metric definitions exist in DB for all metric columns before saving config for (const mc of metricCols) { if (!mc.metricId) { - const r = await addProdMetric({ reportId: rid, metricCode: mc.metricName, metricName: mc.metricName, metricFormula: mc.metricFormula || '', metricValue: 0, remark: mc.unit || '' }) + const r = await addProdMetric({ reportId: rid, metricCode: mc.metricName, metricName: mc.metricName, metricFormula: mc.metricFormula || '', metricValue: 0, remark: mc.unit || '', tags: mc.tags || '' }) mc.metricId = r.data && r.data.metricId || r.metricId } } @@ -721,7 +724,7 @@ export default { if (!def && c.id) { try { const r = await getProdMetric(c.id); if (r.data) { def = r.data; this._allMetricDefs.push(def) } } catch(e) {} } - if (def) cols.push({ $type: 'metric', metricId: def.metricId, metricName: def.metricName, metricFormula: def.metricFormula, unit: def.remark||'', isShift: !!c.s, color: c.c || null, metricValue: def.metricValue, usePrice: def.usePrice }) + if (def) cols.push({ $type: 'metric', metricId: def.metricId, metricName: def.metricName, metricFormula: def.metricFormula, unit: def.remark||'', tags: def.tags || '', isShift: !!c.s, color: c.c || null, metricValue: def.metricValue, usePrice: def.usePrice }) } } this.allCols = cols @@ -782,6 +785,7 @@ export default { async saveGrid() { const rid = this.activeReport.reportId; if (!rid) return; this.saving = true try { + this.recalcAll() const exist = await listProdDetail({ reportId: rid, pageNum: 1, pageSize: 9999 }) const ids = (exist.rows||[]).map(d => d.detailId) const detailCols = this.allCols.filter(c => c.$type === 'detail'); const detailList = [] @@ -793,6 +797,31 @@ export default { }) }) await batchSaveProdDetail({ detailIds: ids, prodDetailList: detailList }) + + const metricCols = this.allCols.filter(c => c.$type === 'metric' && c.metricId) + if (metricCols.length) { + const existMR = await listProdMetricResult({ reportId: rid, pageNum: 1, pageSize: 99999 }) + const resultIds = (existMR.rows || []).map(r => r.resultId) + const metricResultList = [] + this.gridRows.forEach(row => { + if (!row.detailDate) return + metricCols.forEach(m => { + const push = (teamGroup, value) => { + if (value != null && value !== '') { + metricResultList.push({ reportId: rid, metricId: m.metricId, metricDate: row.detailDate, teamGroup, calcValue: value, tags: m.tags || '' }) + } + } + if (m.isShift) { + push('1', row['mv' + m.mIdx + '_1']) + push('2', row['mv' + m.mIdx + '_2']) + } else { + push('0', row['mv' + m.mIdx]) + } + }) + }) + await batchSaveProdMetricResult({ resultIds, prodMetricResultList: metricResultList }) + } + this.$modal.msgSuccess("保存成功"); await this.loadGrid() } catch(e) { this.$modal.msgError("保存失败") } finally { this.saving = false } }, @@ -815,7 +844,7 @@ export default { else if (sc.t === 'm') { const sid = String(sc.id) let def = this._allMetricDefs.find(m=>String(m.metricId)===sid) - if (def && !usedMids.has(sid)) { usedMids.add(sid); this.allCols.push({ $type:'metric', metricId:String(def.metricId), metricName:def.metricName, metricFormula:def.metricFormula, unit:def.remark||'', isShift:!!sc.s, color:sc.c||null, metricValue: def.metricValue, usePrice: def.usePrice }) } + if (def && !usedMids.has(sid)) { usedMids.add(sid); this.allCols.push({ $type:'metric', metricId:String(def.metricId), metricName:def.metricName, metricFormula:def.metricFormula, unit:def.remark||'', tags: def.tags || '', isShift:!!sc.s, color:sc.c||null, metricValue: def.metricValue, usePrice: def.usePrice }) } } }) this.copyCfgOpen = false; let mi = 0; this.allCols.forEach(c => { if (c.$type === 'metric') c.mIdx = mi++ }) diff --git a/klp-ui/src/views/cost/costDataService.js b/klp-ui/src/views/cost/costDataService.js deleted file mode 100644 index 527ae063..00000000 --- a/klp-ui/src/views/cost/costDataService.js +++ /dev/null @@ -1,344 +0,0 @@ -import { listProdReport } from '@/api/cost/prodReport' -import { listProdDetail } from '@/api/cost/prodDetail' -import { listProdMetric } from '@/api/cost/prodMetric' -import { listItem } from '@/api/cost/item' -import { listPrice } from '@/api/cost/price' - -/** - * 安全计算公式值 - * @param {string} f - 公式表达式 - * @returns {number|null} - */ -function evalFormula(f) { - const s = f.replace(/[^0-9+\-*/.()\s]/g, '') - if (!s) return null - try { - const r = new Function('return (' + s + ')')() - return isFinite(r) ? Math.round(r * 10000) / 10000 : null - } catch (e) { - return null - } -} - -/** - * 将明细数据按日期分组,并计算指标公式,生成完整行数据 - * - * @param {Object} report - 生产月报 - * @param {Array} details - 生产成本明细列表 - * @param {Array} metrics - 生产指标列表 - * @param {Array} items - 成本项目配置列表 - * @returns {Array} data - 完整行数据数组 - */ -function buildComputedRows(report, details, metrics, items) { - const itemCodeMap = {} // itemId -> itemCode - items.forEach(item => { - itemCodeMap[item.itemId] = item.itemCode - }) - - const esc = s => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') - - // 1. 按 detailDate 分组明细 - const dateMap = {} - details.forEach(d => { - if (!d.detailDate) return - if (!dateMap[d.detailDate]) { - dateMap[d.detailDate] = { detailDate: d.detailDate } - } - const code = itemCodeMap[d.itemId] - const sfx = d.shift && d.shift !== '0' ? '_' + d.shift : '' - if (code) { - dateMap[d.detailDate]['q_' + code + sfx] = parseFloat(d.quantity) || 0 - } - }) - - const rows = Object.values(dateMap).sort((a, b) => a.detailDate.localeCompare(b.detailDate)) - - // 2. 补齐每个 itemCode 的总量(跨班次汇总) - items.forEach(item => { - const code = item.itemCode - if (!code) return - rows.forEach(row => { - const v1 = row['q_' + code + '_1'] || 0 - const v2 = row['q_' + code + '_2'] || 0 - if (v1 || v2) { - row['q_' + code] = v1 + v2 - } - }) - }) - - // 3. 逐行计算指标公式 - const rp = report || {} - rows.forEach(row => { - metrics.forEach((m, mi) => { - if (!m.metricFormula) return - - let f = m.metricFormula - - // 替换其他指标的引用(按定义顺序,前面的指标可被后面的引用) - for (let pmi = 0; pmi < mi; pmi++) { - const pm = metrics[pmi] - if (!pm.metricName) continue - const pn = esc(pm.metricName) - const pv = row['mv_' + pm.metricName] - if (pv != null) { - f = f.replace(new RegExp('@\\{' + pn + '\\}', 'g'), pv) - } - } - - // 替换明细项引用 @{itemCode} - items.forEach(item => { - if (!item.itemCode) return - const code = esc(item.itemCode) - const totalVal = parseFloat(row['q_' + item.itemCode]) || 0 - const val1 = parseFloat(row['q_' + item.itemCode + '_1']) || 0 - const val2 = parseFloat(row['q_' + item.itemCode + '_2']) || 0 - - f = f.replace(new RegExp('@\\{' + code + '\\}\\.甲班', 'g'), val1) - f = f.replace(new RegExp('@\\{' + code + '\\}\\.乙班', 'g'), val2) - f = f.replace(new RegExp('@\\{' + code + '\\}', 'g'), totalVal) - }) - - // 替换系统变量 - f = f.replace(/input_weight/g, rp.inputWeight || 0) - .replace(/output_weight/g, rp.outputWeight || 0) - .replace(/price/g, (m.usePrice === 1) ? (m.metricValue || 0) : 0) - - const result = evalFormula(f) - if (result != null) { - row['mv_' + m.metricName] = result - } - }) - }) - - return rows -} - -/** - * 获取指定日期和产线类型的全部成本数据 - * - * @param {string} date - 日期,格式 yyyy-MM-dd,如 "2024-01-15" - * @param {string} lineType - 产线类型,"1"=镀锌,"2"=酸轧 - * @returns {Promise<{ - * report: Object|null, // 生产月报 - * metrics: Array, // 生产指标明细列表(公式列) - * details: Array, // 生产成本明细列表(原始数据) - * items: Array, // 成本项目配置列表(原始数据列定义) - * data: Array, // 完整行数据:按日期分组,包含原始值(q_xxx)和计算值(mv_xxx) - * prices: Array, // 成本单价历史列表 - * detailMap: Object, // 按 itemId 分组的明细 - * itemMap: Object, // 按 itemId 索引的项目配置 - * metricMap: Object // 按 metricId 索引的指标 - * }>} - */ -export async function getCostDataByDate(date, lineType) { - // 1. 查找指定日期和产线类型的生产月报 - // 假设每个日期只有一条月报,所以取第一个, 需要将日期转为第一天的日期 - const firstDay = new Date(date) - firstDay.setDate(1) - console.log(firstDay) - // 使用北京时间,转换为东八区时间 - const year = firstDay.getFullYear() - const month = (firstDay.getMonth() + 1).toString().padStart(2, '0') - const firstDayStr = year + '-' + month + '-01 00:00:00' - const reportRes = await listProdReport({ - reportDate: firstDayStr, - lineType: lineType, - pageNum: 1, - pageSize: 1 - }) - console.log(reportRes) - const reports = reportRes.rows || [] - const report = reports.length > 0 ? reports[0] : null - - // 2. 获取所有成本项目配置(用于映射 itemId) - const itemRes = await listItem({ pageNum: 1, pageSize: 9999 }) - const items = itemRes.rows || [] - const itemMap = {} - items.forEach(item => { - itemMap[item.itemId] = item - }) - - // 3. 获取该日期下生效的单价历史 - const priceRes = await listPrice({ - effectiveDate: date, - pageNum: 1, - pageSize: 9999 - }) - const prices = priceRes.rows || [] - - // 如果没有找到月报,返回基础数据 - if (!report) { - return { - report: null, - metrics: [], - details: [], - items, - data: [], - prices, - detailMap: {}, - itemMap, - metricMap: {} - } - } - - const reportId = report.reportId - - // 4. 获取该月报的所有生产成本明细 - const detailRes = await listProdDetail({ - reportId, - pageNum: 1, - pageSize: 9999 - }) - const details = detailRes.rows || [] - - // 5. 构建按 itemId 分组的明细 - const detailMap = {} - details.forEach(detail => { - const key = detail.itemId - if (!detailMap[key]) { - detailMap[key] = [] - } - detailMap[key].push(detail) - }) - - // 6. 获取该月报的所有生产指标 - const metricRes = await listProdMetric({ - reportId, - pageNum: 1, - pageSize: 9999 - }) - const metrics = metricRes.rows || [] - const metricMap = {} - metrics.forEach(metric => { - metricMap[metric.metricId] = metric - }) - - // 7. 构建完整行数据(原始值 + 公式计算值) - const data = buildComputedRows(report, details, metrics, items) - - return { - report, - metrics, - details, - items, - data, - prices, - detailMap, - itemMap, - metricMap - } -} - -/** - * 获取指定日期范围、产线类型的成本数据,支持多天批量查询 - * - * @param {string} startDate - 开始日期 yyyy-MM-dd - * @param {string} endDate - 结束日期 yyyy-MM-dd - * @param {string} lineType - 产线类型 - * @returns {Promise>} - */ -export async function getCostDataByDateRange(startDate, endDate, lineType) { - // 查询日期范围内的所有月报 - const reportRes = await listProdReport({ - lineType, - pageNum: 1, - pageSize: 9999 - }) - const allReports = (reportRes.rows || []).filter(r => { - return r.reportDate >= startDate && r.reportDate <= endDate - }) - - // 获取所有项目配置和单价(共享数据,只查一次) - const itemRes = await listItem({ pageNum: 1, pageSize: 9999 }) - const items = itemRes.rows || [] - const itemMap = {} - items.forEach(item => { - itemMap[item.itemId] = item - }) - - const priceRes = await listPrice({ - pageNum: 1, - pageSize: 9999 - }) - const prices = priceRes.rows || [] - - // 逐日报表获取完整数据 - const results = [] - for (const report of allReports) { - const reportId = report.reportId - - const [detailRes, metricRes] = await Promise.all([ - listProdDetail({ reportId, pageNum: 1, pageSize: 9999 }), - listProdMetric({ reportId, pageNum: 1, pageSize: 9999 }) - ]) - - const details = detailRes.rows || [] - const metrics = metricRes.rows || [] - - const detailMap = {} - details.forEach(detail => { - const key = detail.itemId - if (!detailMap[key]) detailMap[key] = [] - detailMap[key].push(detail) - }) - - const metricMap = {} - metrics.forEach(metric => { - metricMap[metric.metricId] = metric - }) - - const data = buildComputedRows(report, details, metrics, items) - - results.push({ - date: report.reportDate, - report, - metrics, - details, - items, - data, - prices, - detailMap, - itemMap, - metricMap - }) - } - - return results -} - -/** - * 根据 itemId 获取指定日期下该成本项目的明细数据 - * - * @param {string} date - 日期 yyyy-MM-dd - * @param {string} lineType - 产线类型 - * @param {string|number} itemId - 成本项目ID - * @returns {Promise<{ quantity: number|null, unitPrice: number|null, amount: number|null }>} - */ -export async function getCostItemData(date, lineType, itemId) { - const { details, items } = await getCostDataByDate(date, lineType) - const itemDetails = details.filter(d => String(d.itemId) === String(itemId)) - const item = items.find(i => String(i.itemId) === String(itemId)) - - let totalQuantity = 0 - itemDetails.forEach(d => { - totalQuantity += parseFloat(d.quantity) || 0 - }) - - return { - itemId, - itemName: item ? item.itemName : '', - itemCode: item ? item.itemCode : '', - category: item ? item.category : '', - unit: item ? item.unit : '', - quantity: totalQuantity || null, - unitPrice: itemDetails.length > 0 ? itemDetails[0].unitPrice : null, - amount: itemDetails.length > 0 ? itemDetails[0].amount : null, - details: itemDetails - } -} - -export default { - getCostDataByDate, - getCostDataByDateRange, - getCostItemData -} diff --git a/klp-ui/src/views/wms/coil/info/components/CostInfoSection.vue b/klp-ui/src/views/wms/coil/info/components/CostInfoSection.vue index bcc50fee..3c0096b3 100644 --- a/klp-ui/src/views/wms/coil/info/components/CostInfoSection.vue +++ b/klp-ui/src/views/wms/coil/info/components/CostInfoSection.vue @@ -16,69 +16,74 @@ {{ coilInfo.netWeight || 0 }} t - - {{ lineTypeName }} - - - {{ costReport.inputWeight || 0 }} t - - - {{ costReport.outputWeight || 0 }} t - - - {{ costReport.reportDate }} - - - {{ costReport.reportTitle }} - - - {{ totalCost }} - 元 - - - - 当日生产成本明细 - - - - + + 加工路径 + + + + + + + - {{ formatVal(s.row['q_' + item.itemCode]) }} + {{ s.row.costPerTon || '-' }} - - - + + {{ s.row.netWeight }} + + - {{ formatVal(s.row['mv_' + m.metricName]) }} + {{ s.row.costPerTon ? s.row.totalCost : '-' }} - - + + + + + + + +