ledger_audit_check.js 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Ellisran
  6. * @date 2020/10/15
  7. * @version
  8. */
  9. const status = require('../const/audit').ledger.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* ledgerAuditCheck(next) {
  22. try {
  23. if ((this.tender.data.ledger_status === status.uncheck || this.tender.data.ledger_status === status.checkNo) && this.tender.info.shenpi.ledger !== shenpiConst.sp_status.sqspr) {
  24. const shenpi_status = this.tender.info.shenpi.ledger;
  25. // 进一步比较审批流是否与审批流程设置的相同,不同则替换为固定审批流或固定的终审
  26. const auditList = yield this.service.ledgerAudit.getAllDataByCondition({ where: { tender_id: this.tender.id, times: this.tender.data.ledger_times }, orders: [['audit_order', 'asc']] });
  27. const auditIdList = _.map(auditList, 'audit_id');
  28. if (shenpi_status === shenpiConst.sp_status.gdspl) {
  29. const shenpiList = yield this.service.shenpiAudit.getAllDataByCondition({ where: { tid: this.tender.id, sp_type: shenpiConst.sp_type.ledger, sp_status: shenpi_status } });
  30. const shenpiIdList = _.map(shenpiList, 'audit_id');
  31. // 判断2个id数组是否相同,不同则删除原审批流,切换成固定的审批流
  32. if (!_.isEqual(auditIdList, shenpiIdList)) {
  33. yield this.service.ledgerAudit.updateNewAuditList(this.tender.data, shenpiIdList);
  34. }
  35. } else if (shenpi_status === shenpiConst.sp_status.gdzs) {
  36. const shenpiInfo = yield this.service.shenpiAudit.getDataByCondition({ tid: this.tender.id, sp_type: shenpiConst.sp_type.ledger, sp_status: shenpi_status });
  37. // 判断最后一个id是否与固定终审id相同,不同则删除原审批流中如果存在的id和添加终审
  38. if (shenpiInfo && shenpiInfo.audit_id !== _.last(auditIdList)) {
  39. yield this.service.ledgerAudit.updateLastAudit(this.tender.data, auditList, shenpiInfo.audit_id);
  40. } else if (!shenpiInfo) {
  41. // 不存在终审人的状态下这里恢复为授权审批人
  42. this.tender.info.shenpi.ledger = shenpiConst.sp_status.sqspr;
  43. }
  44. }
  45. }
  46. yield next;
  47. } catch (err) {
  48. console.log(err);
  49. // 输出错误到日志
  50. if (err.stack) {
  51. this.logger.error(err);
  52. } else {
  53. this.getLogger('fail').info(JSON.stringify({
  54. error: err,
  55. project: this.session.sessionProject,
  56. user: this.session.sessionUser,
  57. body: this.session.body,
  58. }));
  59. }
  60. // 重定向值标段管理
  61. this.redirect(this.request.headers.referer);
  62. }
  63. };
  64. };