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

feat(weapp): 优化审核历史记录处理,添加原报记录补齐逻辑

lanjianrong 1 неделя назад
Родитель
Сommit
027ac73b4f
1 измененных файлов с 47 добавлено и 7 удалено
  1. 47 7
      app/controller/weapp_tender_controller.js

+ 47 - 7
app/controller/weapp_tender_controller.js

@@ -511,15 +511,54 @@ module.exports = app => {
                 const subProject = await ctx.service.subProject.getDataById(ctx.tender.data.spid);
                 const fun_set = subProject.fun_set;
 
-                const auditHistory = ctx.change.auditHistory && ctx.change.auditHistory.length && ctx.change.auditHistory[ctx.change.auditHistory.length - 1].reduce((prev, curr, idx) => {
-                    prev.push({
-                        name: curr.is_final ? '终审' : curr.audit_order === 0 ? '原报' : `${curr.audit_order}审`,
+                const originAuditHistory = ctx.change.auditHistory;
+                const currentAuditHistory = Array.isArray(originAuditHistory) && originAuditHistory.length
+                    ? originAuditHistory[originAuditHistory.length - 1]
+                    : [];
+                const auditHistory = currentAuditHistory.map(curr => {
+                    // 普通变更的原报记录保存在审批表中,usort/usite 为 0;其余变更类型使用 audit_order 判断。
+                    const isReporter = curr.audit_order === 0 || curr.auditors.some(a => {
+                        return type === 'change' && (Number(a.usort) === 0 || Number(a.usite) === 0);
+                    });
+                    return {
+                        name: isReporter ? '原报' : curr.is_final ? '终审' : `${curr.audit_order}审`,
                         audit_type: curr.audit_type,
                         status: curr.status,
-                        auditors: curr.auditors.map(a => ({...a, audit_id: a.uid})),
+                        auditors: curr.auditors.map(a => ({...a, audit_id: a.uid || a.aid, opinion: a.opinion || a.sdesc})),
+                    };
+                });
+
+                // 立项、申请、方案的审批历史不包含原报记录,需要根据变更创建人补齐。
+                const hasReporter = auditHistory.some(group => {
+                    return group.name === '原报' || group.auditors.some(a => Number(a.audit_id) === Number(ctx.change.uid) && Number(a.audit_order) === 0);
+                });
+                if (!hasReporter) {
+                    const status = auditConst[type].status;
+                    const firstAudit = currentAuditHistory.length && currentAuditHistory[0].auditors.length
+                        ? currentAuditHistory[0].auditors[0]
+                        : null;
+                    const reporterStatus = ctx.change.status === status.uncheck ? status.uncheck : status.checked;
+                    const reporter = {
+                        audit_id: ctx.change.uid,
+                        audit_order: 0,
+                        audit_type: auditConst.auditType.key.common,
+                        status: reporterStatus,
+                        times: firstAudit ? firstAudit.times : ctx.change.times,
+                        begin_time: ctx.change.in_time || ctx.change.create_time || null,
+                        end_time: firstAudit ? firstAudit.begin_time : null,
+                        name: ctx.change.user.name,
+                        company: ctx.change.user.company,
+                        role: ctx.change.user.role,
+                        mobile: ctx.change.user.mobile || '',
+                        opinion: '',
+                    };
+                    auditHistory.unshift({
+                        name: '原报',
+                        audit_type: reporter.audit_type,
+                        status: reporter.status,
+                        auditors: [reporter],
                     });
-                    return prev;
-                }, []);
+                }
                 const curAuditors = ctx.change.curAuditors;
 
                 const change = {
@@ -531,7 +570,8 @@ module.exports = app => {
                     p_code: ctx.change.p_code,
                     quality: ctx.change.quality,
                     auditHistory,
-                    curAuditors: curAuditors.map(a => ({...a, audit_id: a.uid})),
+                    originAuditHistory,
+                    curAuditors: curAuditors.map(a => ({...a, audit_id: a.uid || a.aid})),
                     total_price: ctx.helper.add(ctx.change.total_price, tpUnit),
                     valuation_tp: ctx.helper.add(ctx.change.valuation_tp, tpUnit),
                     unvaluation_tp: ctx.helper.add(ctx.change.unvaluation_tp, tpUnit),