Просмотр исходного кода

refactor(safe-inspection): 将整改趋势图重构为巡检完成趋势

- 图例名称由"首次上报数/完成数/需整改占比"改为"提交巡检/完成巡检/完成占比"
- SQL查询移除需整改数量统计逻辑,简化GROUP BY子句
- 完成占比改为按"完成巡检÷提交巡检"计算
- 移除比例轴max:100限制
- 新增tooltip格式化函数以展示正确单位
- 更新卡片标题、空数据提示及底部说明文案
caipin 1 неделя назад
Родитель
Сommit
1d482a7410

+ 15 - 6
app/public/js/safe_inspection_overview.js

@@ -53,18 +53,18 @@ $(document).ready(function () {
     const trend = safeInspectionOverview.trend;
     const trendChart = echarts.init(document.getElementById('safe-overview-trend'));
     trendChart.setOption({
-        tooltip: { trigger: 'axis', axisPointer: { type: 'cross' } },
-        legend: { data: ['首次上报数', '完成数', '需整改占比'] },
+        tooltip: { trigger: 'axis', axisPointer: { type: 'cross' }, formatter: formatSafeInspectionTrendTooltip },
+        legend: { data: ['提交巡检', '完成巡检', '完成占比'] },
         grid: { left: 15, right: 25, top: 65, bottom: 20, containLabel: true },
         xAxis: { type: 'category', data: trend.months },
         yAxis: [
             { type: 'value', name: '数量(单)', min: 0, minInterval: 1 },
-            { type: 'value', name: '比例(%)', min: 0, max: 100, axisLabel: { formatter: '{value}%' } },
+            { type: 'value', name: '比例(%)', min: 0, axisLabel: { formatter: '{value}%' } },
         ],
         series: [
-            { name: '首次上报数', type: 'bar', data: trend.submitted, itemStyle: { color: '#007bff' }, barMaxWidth: 24 },
-            { name: '完成数', type: 'bar', data: trend.completed, itemStyle: { color: '#28a745' }, barMaxWidth: 24 },
-            { name: '需整改占比', type: 'line', yAxisIndex: 1, data: trend.ratios, itemStyle: { color: '#f0ad00' }, symbolSize: 6 },
+            { name: '提交巡检', type: 'bar', data: trend.submitted, itemStyle: { color: '#007bff' }, barMaxWidth: 24 },
+            { name: '完成巡检', type: 'bar', data: trend.completed, itemStyle: { color: '#28a745' }, barMaxWidth: 24 },
+            { name: '完成占比', type: 'line', yAxisIndex: 1, data: trend.ratios, itemStyle: { color: '#f0ad00' }, symbolSize: 6 },
         ],
     });
     charts.push(trendChart);
@@ -78,3 +78,12 @@ $(document).ready(function () {
         charts.forEach(function (chart) { chart.dispose(); });
     });
 });
+
+function formatSafeInspectionTrendTooltip(items) {
+    if (!items.length) return '';
+    const title = echarts.format.encodeHTML(items[0].axisValueLabel || items[0].name);
+    return title + '<br/>' + items.map(function (item) {
+        const unit = item.seriesName === '完成占比' ? '%' : '';
+        return item.marker + echarts.format.encodeHTML(item.seriesName) + ':' + Number(item.value) + unit;
+    }).join('<br/>');
+}

+ 5 - 7
app/service/safe_inspection.js

@@ -397,23 +397,21 @@ module.exports = app => {
             // 首次上报保留历史轮次和被替换节点;完成时间只取当前已完成流程的最终阶段。
             const sql = 'SELECT YEAR(v.first_report_time) AS report_year, MONTH(v.first_report_time) AS report_month,' +
                 ' YEAR(v.completed_time) AS completed_year, MONTH(v.completed_time) AS completed_month,' +
-                ' COUNT(*) AS inspection_count, SUM(v.needs_rectification) AS rectification_count FROM (' +
-                ' SELECT a.id, CASE WHEN a.flow_version = 1 THEN CASE WHEN a.need_rectification = 1 THEN 1 ELSE 0 END' +
-                ' ELSE CASE WHEN a.rectification_uid > 0 THEN 1 ELSE 0 END END AS needs_rectification,' +
+                ' COUNT(*) AS inspection_count FROM (' +
+                ' SELECT a.id,' +
                 ' MIN(CASE WHEN (a.flow_version = 1 AND b.flow_stage = 1) OR (a.flow_version = 0 AND b.is_rectification = 0)' +
                 ' THEN b.begin_time END) AS first_report_time,' +
                 ' MAX(CASE WHEN a.status = 3 AND b.times = a.times AND b.is_old = 0 AND b.status = 3' +
                 ' AND ((a.flow_version = 1 AND b.flow_stage = a.flow_stage AND b.stage_round = a.stage_round)' +
                 ' OR (a.flow_version = 0 AND b.is_rectification = 1)) THEN b.end_time END) AS completed_time' +
                 ' FROM ?? a LEFT JOIN ?? b ON b.qiid = a.id AND b.tid = a.tid WHERE a.tid = ?' +
-                ' GROUP BY a.id, a.flow_version, a.need_rectification, a.rectification_uid' +
+                ' GROUP BY a.id' +
                 ' ) v WHERE v.first_report_time IS NOT NULL OR v.completed_time IS NOT NULL' +
                 ' GROUP BY YEAR(v.first_report_time), MONTH(v.first_report_time), YEAR(v.completed_time), MONTH(v.completed_time)';
             const sqlParam = [this.tableName, this.ctx.service.safeInspectionAudit.tableName, tid];
             const rows = await this.db.query(sql, sqlParam);
             const submitted = Array(12).fill(0);
             const completed = Array(12).fill(0);
-            const needsRectification = Array(12).fill(0);
             for (const row of rows) {
                 const reportYear = Number(row.report_year);
                 const completedYear = Number(row.completed_year);
@@ -421,7 +419,6 @@ module.exports = app => {
                 const completedMonth = Number(row.completed_month);
                 if (reportYear === year && reportMonth >= 1 && reportMonth <= 12) {
                     submitted[reportMonth - 1] += Number(row.inspection_count);
-                    needsRectification[reportMonth - 1] += Number(row.rectification_count);
                 }
                 if (completedYear === year && completedMonth >= 1 && completedMonth <= 12) {
                     completed[completedMonth - 1] += Number(row.inspection_count);
@@ -429,7 +426,8 @@ module.exports = app => {
             }
             return {
                 year, months: submitted.map((count, index) => year + '年' + (index + 1) + '月'), submitted, completed,
-                ratios: submitted.map((count, index) => (count ? Number((needsRectification[index] * 100 / count).toFixed(1)) : 0)),
+                // 完成巡检按整单最终完成月份统计,提交巡检按首次提交月份统计。
+                ratios: submitted.map((count, index) => (count ? Number((completed[index] * 100 / count).toFixed(1)) : 0)),
                 hasData: submitted.some(count => count > 0) || completed.some(count => count > 0),
             };
         }

+ 5 - 5
app/view/safe/inspection_overview.ejs

@@ -76,15 +76,15 @@
             </div>
             <div class="card mb-3">
                 <div class="card-header d-flex align-items-center">
-                    <strong>整改趋势</strong>
+                    <strong>巡检完成趋势</strong>
                 </div>
                 <div class="card-body">
-                    <% if (!overview.trend.hasData) { %><p class="text-center text-muted mb-0"><%= overview.trend.year %>年暂无上报或完成记录</p><% } %>
-                    <div id="safe-overview-trend" class="overview-trend" role="img" aria-label="<%= overview.trend.year %>年巡检上报、完成及需整改占比趋势"></div>
+                    <% if (!overview.trend.hasData) { %><p class="text-center text-muted mb-0"><%= overview.trend.year %>年暂无提交或完成巡检记录</p><% } %>
+                    <div id="safe-overview-trend" class="overview-trend" role="img" aria-label="<%= overview.trend.year %>年提交巡检、完成巡检及完成占比趋势"></div>
                 </div>
                 <div class="card-footer text-muted small">
-                    <div>首次上报数按实际首次提交月份统计,退回重报不重复计数;完成数按整个流程最终完成月份统计。</div>
-                    <div>需整改占比为该月首次上报记录中,按当前保存的整改设置计算的需整改比例;趋势统计当年数据,上方展示当前状态。</div>
+                    <div>提交巡检按实际首次提交月份统计,退回重报不重复计数;完成巡检按整张巡检单最终完成月份统计。</div>
+                    <div>完成占比=完成巡检 ÷ 提交巡检 × 100%;按当月统计,当月无提交巡检时显示0%。</div>
                 </div>
             </div>
         </div>