change_audit_check.js 3.6 KB

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