|
@@ -8,7 +8,7 @@
|
|
|
* @version
|
|
|
*/
|
|
|
|
|
|
-const auditConst = require('../const/audit').flow;
|
|
|
+const auditConst = require('../const/audit').stage;
|
|
|
|
|
|
module.exports = app => {
|
|
|
class StageAudit extends app.BaseService {
|
|
@@ -68,6 +68,7 @@ module.exports = app => {
|
|
|
'WHERE la.`sid` = ? and la.`status` = ? and la.`times` = ?' +
|
|
|
' and la.`aid` = pa.`id`';
|
|
|
const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, stageId, auditConst.status.checking, times];
|
|
|
+ console.log(this.db.format(sql, sqlParam));
|
|
|
return await this.db.queryOne(sql, sqlParam);
|
|
|
}
|
|
|
|
|
@@ -204,8 +205,7 @@ module.exports = app => {
|
|
|
* @returns {Promise<void>}
|
|
|
*/
|
|
|
async check(stageId, checkData, times = 1) {
|
|
|
- console.log('check');
|
|
|
- if (checkType !== auditConst.status.checked && checkType !== auditConst.status.checkNo) {
|
|
|
+ if (checkData.checkType !== auditConst.status.checked && checkData.checkType !== auditConst.status.checkNo) {
|
|
|
throw '提交数据错误';
|
|
|
}
|
|
|
|
|
@@ -218,9 +218,8 @@ module.exports = app => {
|
|
|
throw '审核数据错误';
|
|
|
}
|
|
|
// 更新当前审核流程
|
|
|
- await transaction.update(this.tableName, {id: audit.id, status: checkType, opinion: opinion, end_time: time});
|
|
|
- if (checkType === auditConst.status.checked) {
|
|
|
- console.log('checked');
|
|
|
+ await transaction.update(this.tableName, {id: audit.id, status: checkData.checkType, opinion: checkData.opinion, end_time: time});
|
|
|
+ if (checkData.checkType === auditConst.status.checked) { // 审批通过
|
|
|
const nextAudit = await this.getDataByCondition({sid: stageId, times: times, order: audit.order + 1});
|
|
|
// 无下一审核人表示,审核结束
|
|
|
if (nextAudit) {
|
|
@@ -235,12 +234,11 @@ module.exports = app => {
|
|
|
// 计算并合同支付最终数据
|
|
|
await this.ctx.service.stagePay.calcAllStagePays(this.ctx.stage, transaction);
|
|
|
// 同步 期信息
|
|
|
- await transaction.update(this.ctx.service.stage.tableName, {id: stageId, status: checkType});
|
|
|
+ await transaction.update(this.ctx.service.stage.tableName, {id: stageId, status: checkData.checkType});
|
|
|
}
|
|
|
- } else {
|
|
|
- console.log('checkNo');
|
|
|
+ } else if (checkData.checkType === auditConst.status.checkNo) { // 审批退回 原报
|
|
|
// 同步 期信息
|
|
|
- await transaction.update(this.ctx.service.stage.tableName, {id: stageId, times: times+1, status: checkType});
|
|
|
+ await transaction.update(this.ctx.service.stage.tableName, {id: stageId, status: checkData.checkType});
|
|
|
// 拷贝新一次审核流程列表
|
|
|
const auditors = await this.getAllDataByCondition({
|
|
|
where: {sid: stageId, times: times},
|
|
@@ -255,6 +253,40 @@ module.exports = app => {
|
|
|
await this.ctx.service.stagePay.calcAllStagePays(this.ctx.stage, transaction);
|
|
|
// 复制一份最新数据给原报
|
|
|
await this.ctx.service.stagePay.copyAuditStagePays(this.ctx.stage, this.ctx.stage.times + 1, 0, transaction);
|
|
|
+ } else if (checkData.checkType === auditConst.status.checkNoPre) { // 审批退回 上一审批人
|
|
|
+ // 同步 期信息
|
|
|
+ await transaction.update(this.ctx.service.stage.tableName, {id: stageId, status: checkData.checkType});
|
|
|
+ // 将当前审批人 与 上一审批人再次添加至流程,顺移其后审批人流程顺序
|
|
|
+ if (audit.order > 1) {
|
|
|
+ // 顺移气候审核人流程顺序
|
|
|
+ this.initSqlBuilder();
|
|
|
+ this.sqlBuilder.setAndWhere('sid', { value: this.ctx.stage.id, operate: '=', });
|
|
|
+ this.sqlBuilder.setAndWhere('order', { value: audit.order, operate: '>', });
|
|
|
+ this.sqlBuilder.setUpdateData('order', { value: 2, selfOperate: '+', });
|
|
|
+ const [sql, sqlParam] = this.sqlBuilder.build(this.tableName, 'update');
|
|
|
+ const data = await transaction.query(sql, sqlParam);
|
|
|
+
|
|
|
+ // 上一审批人,当前审批人 再次添加至流程
|
|
|
+ const preAuditor = await this.getDataByCondition({sid: stageId, times: times, order: audit.order - 1});
|
|
|
+ const newAuditors = [];
|
|
|
+ newAuditors.push({
|
|
|
+ tid: preAuditor.tid, sid: preAuditor.sid, aid: preAuditor.aid,
|
|
|
+ times: preAuditor.times, order: preAuditor.order + 2, status: auditConst.status.checking,
|
|
|
+ begin_time: time,
|
|
|
+ });
|
|
|
+ newAuditors.push({
|
|
|
+ tid: audit.tid, sid: audit.sid, aid: audit.aid,
|
|
|
+ times: audit.times, order: audit.order + 2, status: auditConst.status.uncheck
|
|
|
+ });
|
|
|
+ await transaction.insert(this.tableName, newAuditors);
|
|
|
+
|
|
|
+ // 计算该审批人最终数据
|
|
|
+ await this.ctx.service.stagePay.calcAllStagePays(this.ctx.stage, transaction);
|
|
|
+ // 复制一份最新数据给原报
|
|
|
+ await this.ctx.service.stagePay.copyAuditStagePays(this.ctx.stage, this.ctx.stage.times, audit.order + 1, transaction);
|
|
|
+ } else {
|
|
|
+ throw '审核数据错误';
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
await transaction.commit();
|
|
@@ -265,16 +297,18 @@ module.exports = app => {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 获取审核人需要审核的标段列表
|
|
|
+ * 获取审核人需要审核的期列表
|
|
|
*
|
|
|
* @param auditorId
|
|
|
* @returns {Promise<*>}
|
|
|
*/
|
|
|
async getAuditStage(auditorId) {
|
|
|
- const sql = 'SELECT la.`aid`, la.`times`, la.`order`, la.`begin_time`, la.`tid`, la.`sid`, s.`order`, t.`name`, t.`project_id`, t.`type`, t.`user_id` ' +
|
|
|
- 'FROM ?? AS la, ?? AS s, ?? As t ' +
|
|
|
- 'WHERE la.`aid` = ? and la.`status` = ?' +
|
|
|
- ' and la.`sid` = s.`id` and la.`tid` = t.`id`';
|
|
|
+ const sql = 'SELECT sa.`aid`, sa.`times`, sa.`order`, sa.`begin_time`, sa.`tid`, sa.`sid`,' +
|
|
|
+ ' s.`order` As `sorder`, s.`status` As `sstatus`,' +
|
|
|
+ ' t.`name`, t.`project_id`, t.`type`, t.`user_id` ' +
|
|
|
+ ' FROM ?? AS sa, ?? AS s, ?? As t ' +
|
|
|
+ ' WHERE sa.`aid` = ? and sa.`status` = ?' +
|
|
|
+ ' and sa.`sid` = s.`id` and sa.`tid` = t.`id`';
|
|
|
const sqlParam = [this.tableName, this.ctx.service.stage.tableName, this.ctx.service.tender.tableName, auditorId, auditConst.status.checking];
|
|
|
return await this.db.query(sql, sqlParam);
|
|
|
}
|