|
@@ -382,14 +382,13 @@ module.exports = app => {
|
|
|
|
|
|
|
|
async getOverviewRectifiers(tid, ids) {
|
|
async getOverviewRectifiers(tid, ids) {
|
|
|
if (!ids.length) return [];
|
|
if (!ids.length) return [];
|
|
|
- // ids 来自当前标段的整改清单,只批量读取这十条记录的待处理人员。
|
|
|
|
|
|
|
+ // 展示本轮所有未完成整改人,包括正在处理及尚未轮到的人员。
|
|
|
const sql = 'SELECT b.qiid, b.aid, p.name FROM ?? b JOIN ?? a ON a.id = b.qiid AND a.tid = b.tid' +
|
|
const sql = 'SELECT b.qiid, b.aid, p.name FROM ?? b JOIN ?? a ON a.id = b.qiid AND a.tid = b.tid' +
|
|
|
' LEFT JOIN ?? p ON p.id = b.aid WHERE a.tid = ? AND a.id IN (?)' +
|
|
' LEFT JOIN ?? p ON p.id = b.aid WHERE a.tid = ? AND a.id IN (?)' +
|
|
|
- ' AND b.times = a.times AND b.is_old = 0 AND b.status = 12' +
|
|
|
|
|
- ' AND ((a.flow_version = 1 AND b.flow_stage = 2 AND b.stage_round = a.stage_round) OR (a.flow_version = 0 AND b.is_rectification = 1))' +
|
|
|
|
|
- ' AND (a.flow_version = 0 OR NOT EXISTS (SELECT 1 FROM ?? c WHERE c.qiid = b.qiid AND c.times = b.times AND c.flow_stage = 2 AND c.stage_round = b.stage_round AND c.is_old = 0 AND c.status IN (1, 12) AND (c.audit_order < b.audit_order OR (c.audit_order = b.audit_order AND c.id < b.id))))' +
|
|
|
|
|
- ' ORDER BY b.`order`, b.id';
|
|
|
|
|
- const sqlParam = [this.ctx.service.qualityInspectionAudit.tableName, this.tableName, this.ctx.service.projectAccount.tableName, tid, ids, this.ctx.service.qualityInspectionAudit.tableName];
|
|
|
|
|
|
|
+ ' AND b.times = a.times AND b.is_old = 0' +
|
|
|
|
|
+ ' AND ((a.flow_version = 1 AND b.flow_stage = 2 AND b.stage_round = a.stage_round AND b.status IN (1, 12)) OR (a.flow_version = 0 AND b.is_rectification = 1 AND b.status = 12))' +
|
|
|
|
|
+ ' ORDER BY b.audit_order, b.`order`, b.id';
|
|
|
|
|
+ const sqlParam = [this.ctx.service.qualityInspectionAudit.tableName, this.tableName, this.ctx.service.projectAccount.tableName, tid, ids];
|
|
|
return await this.db.query(sql, sqlParam);
|
|
return await this.db.query(sql, sqlParam);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -397,23 +396,21 @@ module.exports = app => {
|
|
|
// 首次上报保留历史轮次和被替换节点;完成时间只取当前已完成流程的最终阶段。
|
|
// 首次上报保留历史轮次和被替换节点;完成时间只取当前已完成流程的最终阶段。
|
|
|
const sql = 'SELECT YEAR(v.first_report_time) AS report_year, MONTH(v.first_report_time) AS report_month,' +
|
|
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,' +
|
|
' 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)' +
|
|
' 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,' +
|
|
' 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' +
|
|
' 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)' +
|
|
' 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' +
|
|
' 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 = ?' +
|
|
' 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' +
|
|
' ) 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)';
|
|
' 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.qualityInspectionAudit.tableName, tid];
|
|
const sqlParam = [this.tableName, this.ctx.service.qualityInspectionAudit.tableName, tid];
|
|
|
const rows = await this.db.query(sql, sqlParam);
|
|
const rows = await this.db.query(sql, sqlParam);
|
|
|
const submitted = Array(12).fill(0);
|
|
const submitted = Array(12).fill(0);
|
|
|
const completed = Array(12).fill(0);
|
|
const completed = Array(12).fill(0);
|
|
|
- const needsRectification = Array(12).fill(0);
|
|
|
|
|
for (const row of rows) {
|
|
for (const row of rows) {
|
|
|
const reportYear = Number(row.report_year);
|
|
const reportYear = Number(row.report_year);
|
|
|
const completedYear = Number(row.completed_year);
|
|
const completedYear = Number(row.completed_year);
|
|
@@ -421,7 +418,6 @@ module.exports = app => {
|
|
|
const completedMonth = Number(row.completed_month);
|
|
const completedMonth = Number(row.completed_month);
|
|
|
if (reportYear === year && reportMonth >= 1 && reportMonth <= 12) {
|
|
if (reportYear === year && reportMonth >= 1 && reportMonth <= 12) {
|
|
|
submitted[reportMonth - 1] += Number(row.inspection_count);
|
|
submitted[reportMonth - 1] += Number(row.inspection_count);
|
|
|
- needsRectification[reportMonth - 1] += Number(row.rectification_count);
|
|
|
|
|
}
|
|
}
|
|
|
if (completedYear === year && completedMonth >= 1 && completedMonth <= 12) {
|
|
if (completedYear === year && completedMonth >= 1 && completedMonth <= 12) {
|
|
|
completed[completedMonth - 1] += Number(row.inspection_count);
|
|
completed[completedMonth - 1] += Number(row.inspection_count);
|
|
@@ -429,7 +425,8 @@ module.exports = app => {
|
|
|
}
|
|
}
|
|
|
return {
|
|
return {
|
|
|
year, months: submitted.map((count, index) => year + '年' + (index + 1) + '月'), submitted, completed,
|
|
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),
|
|
hasData: submitted.some(count => count > 0) || completed.some(count => count > 0),
|
|
|
};
|
|
};
|
|
|
}
|
|
}
|