revise_audit_check.js 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Ellisran
  6. * @date 2020/10/15
  7. * @version
  8. */
  9. const status = require('../const/audit').revise.status;
  10. const shenpiConst = require('../const/shenpi');
  11. const _ = require('lodash');
  12. module.exports = options => {
  13. /**
  14. * 标段校验 中间件
  15. * 1. 读取标段数据(包括属性)
  16. * 2. 检验用户是否可见标段(不校验具体权限)
  17. *
  18. * @param {function} next - 中间件继续执行的方法
  19. * @return {void}
  20. */
  21. return function* reviseAuditCheck(next) {
  22. try {
  23. // 获取revise
  24. const revise = yield this.service.ledgerRevise.getLastestRevise(this.tender.id);
  25. if (!revise) throw '台账修订数据有误';
  26. if ((revise.status === status.uncheck || revise.status === status.checkNo) && this.tender.info.shenpi.revise !== shenpiConst.sp_status.sqspr) {
  27. const shenpi_status = this.tender.info.shenpi.revise;
  28. // 进一步比较审批流是否与审批流程设置的相同,不同则替换为固定审批流或固定的终审
  29. const auditList = yield this.service.reviseAudit.getAllDataByCondition({ where: { rid: revise.id, times: revise.times }, orders: [['audit_order', 'asc']] });
  30. const auditIdList = _.map(auditList, 'audit_id');
  31. if (shenpi_status === shenpiConst.sp_status.gdspl) {
  32. const shenpiList = yield this.service.shenpiAudit.getAllDataByCondition({ where: { tid: this.tender.id, sp_type: shenpiConst.sp_type.revise, sp_status: shenpi_status } });
  33. const shenpiIdList = _.map(shenpiList, 'audit_id');
  34. // 判断2个id数组是否相同,不同则删除原审批流,切换成固定的审批流
  35. if (!_.isEqual(auditIdList, shenpiIdList)) {
  36. yield this.service.reviseAudit.updateNewAuditList(revise, shenpiIdList);
  37. }
  38. } else if (shenpi_status === shenpiConst.sp_status.gdzs) {
  39. const shenpiInfo = yield this.service.shenpiAudit.getDataByCondition({ tid: this.tender.id, sp_type: shenpiConst.sp_type.revise, sp_status: shenpi_status });
  40. // 判断最后一个id是否与固定终审id相同,不同则删除原审批流中如果存在的id和添加终审
  41. if (shenpiInfo && shenpiInfo.audit_id !== _.last(auditIdList)) {
  42. yield this.service.reviseAudit.updateLastAudit(revise, auditList, shenpiInfo.audit_id);
  43. } else if (!shenpiInfo) {
  44. // 不存在终审人的状态下这里恢复为授权审批人
  45. this.tender.info.shenpi.revise = shenpiConst.sp_status.sqspr;
  46. }
  47. }
  48. }
  49. yield next;
  50. } catch (err) {
  51. console.log(err);
  52. // 输出错误到日志
  53. if (err.stack) {
  54. this.logger.error(err);
  55. } else {
  56. this.getLogger('fail').info(JSON.stringify({
  57. error: err,
  58. project: this.session.sessionProject,
  59. user: this.session.sessionUser,
  60. body: this.session.body,
  61. }));
  62. }
  63. // 重定向值标段管理
  64. this.redirect(this.request.headers.referer);
  65. }
  66. };
  67. };