123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- 'use strict';
- /**
- *
- *
- * @author Ellisran
- * @date 2020/10/15
- * @version
- */
- const status = require('../const/audit').revise.status;
- const shenpiConst = require('../const/shenpi');
- const _ = require('lodash');
- const checkAuditFlow = async function(ctx) {
- const info = ctx.tender.info;
- const revise = await ctx.service.ledgerRevise.getLastestRevise(ctx.tender.id);
- if (!revise) throw '台账修订数据有误';
- if (info.shenpi.revise === shenpiConst.sp_status.sqspr) return;
- if (revise.status !== status.uncheck && revise.status !== status.checkNo) return;
- const shenpi_status = info.shenpi.revise;
- // 进一步比较审批流是否与审批流程设置的相同,不同则替换为固定审批流或固定的终审
- const auditList = await ctx.service.reviseAudit.getAuditors(revise.id, revise.times);
- if (shenpi_status === shenpiConst.sp_status.gdspl) {
- const shenpiList = await ctx.service.shenpiAudit.getAllDataByCondition({ where: { tid: revise.tid, sp_type: shenpiConst.sp_type.revise, sp_status: shenpi_status } });
- // 判断2个id数组是否相同,不同则删除原审批流,切换成固定的审批流
- let sameAudit = auditList.length === shenpiList.length;
- if (sameAudit) {
- for (const audit of auditList) {
- const shenpi = shenpiList.find(x => { return x.audit_id === audit.audit_id; });
- if (!shenpi || shenpi.audit_order !== audit.audit_order || shenpi.audit_type !== audit.audit_type || shenpi.audit_ledger_id !== audit.audit_ledger_id) {
- sameAudit = false;
- break;
- }
- }
- }
- if (!sameAudit) await ctx.service.reviseAudit.updateNewAuditList(revise, shenpiList);
- } else if (shenpi_status === shenpiConst.sp_status.gdzs) {
- const shenpiInfo = await ctx.service.shenpiAudit.getDataByCondition({ tid: revise.tid, sp_type: shenpiConst.sp_type.revise, sp_status: shenpi_status });
- // 判断最后一个id是否与固定终审id相同,不同则删除原审批流中如果存在的id和添加终审
- const lastAuditors = auditList.filter(x => { x.audit_order === auditList[auditList.length - 1].audit_order; });
- if (shenpiInfo && (lastAuditors.length === 0 || (lastAuditors.length > 1 || shenpiInfo.audit_id !== lastAuditors[0].audit_id))) {
- await ctx.service.reviseAudit.updateLastAudit(revise, auditList, shenpiInfo.audit_id);
- } else if (!shenpiInfo) {
- // 不存在终审人的状态下这里恢复为授权审批人
- info.shenpi.revise = shenpiConst.sp_status.sqspr;
- }
- }
- };
- module.exports = options => {
- /**
- * 标段校验 中间件
- * 1. 读取标段数据(包括属性)
- * 2. 检验用户是否可见标段(不校验具体权限)
- *
- * @param {function} next - 中间件继续执行的方法
- * @return {void}
- */
- return function* reviseAuditCheck(next) {
- try {
- yield checkAuditFlow(this);
- yield next
- } catch (err) {
- this.log(err);
- // 重定向值标段管理
- this.redirect(this.request.headers.referer);
- }
- };
- };
|