|
|
@@ -118,27 +118,27 @@ module.exports = app => {
|
|
|
}
|
|
|
return history;
|
|
|
}
|
|
|
- async getAllAuditors(tenderId) {
|
|
|
+ async getAllAuditors(tenderId, stage_type) {
|
|
|
const sql =
|
|
|
'SELECT audit_id, tid FROM ' + this.tableName +
|
|
|
- ' WHERE tid = ?' +
|
|
|
+ ' WHERE tid = ? AND stage_type = ?' +
|
|
|
' GROUP BY audit_id';
|
|
|
- const sqlParam = [tenderId];
|
|
|
+ const sqlParam = [tenderId, stage_type];
|
|
|
return this.db.query(sql, sqlParam);
|
|
|
}
|
|
|
- async getAuditStage(auditorId, spid = '') {
|
|
|
+ async getAuditStage(stage_type, auditorId, spid = '') {
|
|
|
// 查询待审批的期
|
|
|
const spSql = spid ? ' and t.`spid` = "' + spid + '"' : '';
|
|
|
const sql =
|
|
|
'SELECT sa.`audit_id`, sa.`audit_times`, sa.`audit_order`, sa.active_order, sa.`tid`, sa.`stage_id`,' +
|
|
|
- ' s.`stage_order`, s.`stage_code`, s.`stage_date`, s.create_time,' +
|
|
|
+ ' s.`stage_order`, s.`stage_date`, s.create_time,' +
|
|
|
' t.`name`, t.`project_id`, t.`type`, t.`user_id`, t.`spid` ' +
|
|
|
` FROM ${this.tableName} AS sa ` +
|
|
|
` Left Join ${this.ctx.service.costStage.tableName} AS s On sa.stage_id = s.id ` +
|
|
|
` Left Join ${this.ctx.service.tender.tableName} As t ON sa.tid = t.id `+
|
|
|
- ' WHERE sa.`audit_id` = ? and (sa.`audit_status` = ? or (sa.audit_times > 1 and sa.audit_status = ? and sa.audit_order = 0))' + spSql +
|
|
|
+ ' WHERE sa.`audit_id` = ? and sa.stage_type = ? and (sa.`audit_status` = ? or (sa.audit_times > 1 and sa.audit_status = ? and sa.audit_order = 0))' + spSql +
|
|
|
' ORDER BY sa.`create_time` DESC';
|
|
|
- const sqlParam = [auditorId, auditConst.common.status.checking, auditConst.common.status.uncheck];
|
|
|
+ const sqlParam = [auditorId, stage_type, auditConst.common.status.checking, auditConst.common.status.uncheck];
|
|
|
const result = await this.db.query(sql, sqlParam);
|
|
|
for (const r of result) {
|
|
|
if (r.audit_order > 0) {
|
|
|
@@ -157,15 +157,16 @@ module.exports = app => {
|
|
|
* @param auditorId
|
|
|
* @return {Promise<*>}
|
|
|
*/
|
|
|
- async getDonesByAudit(auditorId, spid = '') {
|
|
|
+ async getDonesByAudit(stage_type, auditorId, spid = '') {
|
|
|
const spSql = spid ? ' and t.`spid` = "' + spid + '"' : '';
|
|
|
const sql =
|
|
|
- 'SELECT ssa.audit_status, ssa.audit_time AS shenpi_time, ssa.stage_id, t.id, ss.stage_code, ss.stage_order, t.name, t.spid ' +
|
|
|
+ 'SELECT ssa.audit_status, ssa.audit_time AS shenpi_time, ssa.stage_id, t.id, ss.stage_order, t.name, t.spid ' +
|
|
|
` FROM ${this.tableName} AS ssa Left Join ${this.ctx.service.tender.tableName} AS t ON ssa.tid = t.id LEFT JOIN ${this.ctx.service.costStage.tableName} AS ss ON ssa.stage_id = ss.id` +
|
|
|
- ' WHERE ssa.audit_id = ? AND ssa.audit_status in (' + this.ctx.helper.getInArrStrSqlFilter(checkRelaStatus) + ')' + spSql +
|
|
|
+ ' WHERE ssa.audit_id = ? AND ss.stage_type = ? AND ssa.audit_status in (' + this.ctx.helper.getInArrStrSqlFilter(checkRelaStatus) + ')' + spSql +
|
|
|
' ORDER BY ssa.audit_time DESC';
|
|
|
- const sqlParam = [auditorId];
|
|
|
- return await this.db.query(sql, sqlParam);
|
|
|
+ const sqlParam = [auditorId, stage_type];
|
|
|
+ const result = await this.db.query(sql, sqlParam);
|
|
|
+ return result;
|
|
|
}
|
|
|
/**
|
|
|
* 获取最近一次审批结束时间
|
|
|
@@ -173,13 +174,12 @@ module.exports = app => {
|
|
|
* @param auditorId
|
|
|
* @return {Promise<*>}
|
|
|
*/
|
|
|
- async getLastEndTimeByChecked(auditorId, spid = '') {
|
|
|
+ async getLastEndTimeByChecked(stage_type, auditorId, spid = '') {
|
|
|
const sqSql = spid ? ' AND t.`spid` = "' + spid + '"' : '';
|
|
|
- const status = [auditConst.common.status.checked, auditConst.common.status.checkNo, auditConst.common.status.checkNoPre];
|
|
|
- const sql = `SELECT a.audit_time FROM ${this.tableName} AS a LEFT JOIN ${this.ctx.service.tender.tableName} AS t ON a.tid = t.id WHERE a.audit_id = ? ` +
|
|
|
+ const sql = `SELECT a.audit_time, t.spid FROM ${this.tableName} AS a LEFT JOIN ${this.ctx.service.tender.tableName} AS t ON a.tid = t.id WHERE a.audit_id = ? AND a.stage_type = ? ` +
|
|
|
'AND a.`audit_status` in (' + this.ctx.helper.getInArrStrSqlFilter(checkRelaStatus) + ')' + sqSql +
|
|
|
' ORDER BY a.`audit_time` DESC';
|
|
|
- const sqlParam = [auditorId];
|
|
|
+ const sqlParam = [auditorId, stage_type];
|
|
|
const result = await this.db.queryOne(sql, sqlParam);
|
|
|
return result ? result.audit_time : null;
|
|
|
}
|
|
|
@@ -189,11 +189,11 @@ module.exports = app => {
|
|
|
* @param auditorId
|
|
|
* @return {Promise<*>}
|
|
|
*/
|
|
|
- async getCountByChecked(auditorId, spid = '') {
|
|
|
+ async getCountByChecked(stage_type, auditorId, spid = '') {
|
|
|
if (spid) {
|
|
|
const sql = `SELECT count(*) AS count FROM ${this.tableName} AS a LEFT JOIN ${this.ctx.service.tender.tableName} AS t ON a.tid = t.id` +
|
|
|
- ' WHERE a.audit_id = ? AND a.audit_status in (' + this.ctx.helper.getInArrStrSqlFilter(checkRelaStatus) + ') AND t.`spid` = ?';
|
|
|
- const sqlParam = [auditorId, spid];
|
|
|
+ ' WHERE a.audit_id = ? AND a.stage_type = ? AND a.audit_status in (' + this.ctx.helper.getInArrStrSqlFilter(checkRelaStatus) + ') AND t.`spid` = ?';
|
|
|
+ const sqlParam = [auditorId, stage_type, spid];
|
|
|
const result = await this.db.queryOne(sql, sqlParam);
|
|
|
return result.count ? result.count : 0;
|
|
|
}
|
|
|
@@ -259,12 +259,13 @@ module.exports = app => {
|
|
|
// 判断是否存在固定终审,存在则newOrder - 1并使终审order+1
|
|
|
newOrder = is_gdzs === 1 ? newOrder - 1 : newOrder;
|
|
|
newAuditOrder = is_gdzs === 1 ? newAuditOrder - 1 : newAuditOrder;
|
|
|
+ const costStage = await this.ctx.service.costStage.getStage(stageId);
|
|
|
|
|
|
const transaction = await this.db.beginTransaction();
|
|
|
try {
|
|
|
if (is_gdzs) await this._syncAuditOrder(transaction, stageId, newOrder, auditTimes, '+');
|
|
|
const data = {
|
|
|
- tid: this.ctx.tender.id, stage_id: stageId, audit_id: auditor.id,
|
|
|
+ tid: this.ctx.tender.id, stage_id: stageId, stage_type: costStage.stage_type, audit_id: auditor.id,
|
|
|
name: auditor.name, company: auditor.company, role: auditor.role, mobile: auditor.mobile,
|
|
|
audit_times: auditTimes, active_order: newOrder, audit_status: auditConst.costStage.status.uncheck,
|
|
|
audit_order: newAuditOrder, audit_type: auditType.key.common,
|
|
|
@@ -318,7 +319,7 @@ module.exports = app => {
|
|
|
// 添加原报
|
|
|
const user = await this.ctx.service.projectAccount.getDataById(this.ctx.session.sessionUser.accountId);
|
|
|
newAuditors.push({
|
|
|
- tid: newStage.tid, stage_id: newStage.id,
|
|
|
+ tid: newStage.tid, stage_id: newStage.id, stage_type: newStage.stage_type,
|
|
|
audit_id: this.ctx.session.sessionUser.accountId,
|
|
|
audit_times: 1, audit_order: 0, audit_type: auditConst.auditType.key.common,
|
|
|
active_order: 0, audit_status: auditConst.costStage.status.uncheck,
|
|
|
@@ -328,7 +329,7 @@ module.exports = app => {
|
|
|
for (const a of auditors) {
|
|
|
if (a.audit_order === 0) continue;
|
|
|
newAuditors.push({
|
|
|
- tid: newStage.tid, stage_id: newStage.id,
|
|
|
+ tid: newStage.tid, stage_id: newStage.id, stage_type: newStage.stage_type,
|
|
|
audit_id: a.audit_id,
|
|
|
audit_times: 1, audit_order: a.audit_order, audit_type: a.audit_type,
|
|
|
active_order: a.audit_order, audit_status: auditConst.costStage.status.uncheck,
|
|
|
@@ -352,7 +353,7 @@ module.exports = app => {
|
|
|
const auditorInfo = newAuditsInfo.find(x => { return x.id === auditor.audit_id; });
|
|
|
if (!auditorInfo) throw '配置的审批人不存在';
|
|
|
newAuditors.push({
|
|
|
- tid: stage.tid, stage_id: stage.id, audit_id: auditor.audit_id,
|
|
|
+ tid: stage.tid, stage_id: stage.id, audit_id: auditor.audit_id, stage_type: stage.stage_type,
|
|
|
name: auditorInfo.name, company: auditorInfo.company, role: auditorInfo.role, mobile: auditorInfo.mobile,
|
|
|
audit_times: stage.audit_times, active_order: auditor.audit_order, audit_status: auditConst.costStage.status.uncheck,
|
|
|
audit_type: auditor.audit_type, audit_order: auditor.audit_order,
|
|
|
@@ -408,7 +409,7 @@ module.exports = app => {
|
|
|
// 添加终审
|
|
|
if (lastUser) {
|
|
|
const newAuditor = {
|
|
|
- tid: stage.tid, stage_id: stage.id, audit_id: lastId,
|
|
|
+ tid: stage.tid, stage_id: stage.id, stage_type: stage.stage_type, audit_id: lastId,
|
|
|
name: lastUser.name, company: lastUser.company, role: lastUser.role, mobile: lastUser.mobile,
|
|
|
audit_times: stage.audit_times, active_order: auditOrder, audit_status: auditConst.costStage.status.uncheck,
|
|
|
audit_type: auditType.key.common, audit_order: auditOrder,
|
|
|
@@ -543,6 +544,7 @@ module.exports = app => {
|
|
|
const noticeContent = await this._getNoticeContent(this.ctx.session.sessionProject.id, stage.tid, stage.id, accountId, opinion);
|
|
|
const defaultNoticeRecord = {
|
|
|
pid: this.ctx.session.sessionProject.id,
|
|
|
+ spid: this.ctx.tender.spid,
|
|
|
tid: stage.tid,
|
|
|
type: pushType[stage.typeInfo.push_type],
|
|
|
status: auditConst.costStage.status.checked,
|
|
|
@@ -657,7 +659,7 @@ module.exports = app => {
|
|
|
const auditors = await this.getUniqAuditors(stage); // 全部参与的审批人
|
|
|
const newAuditors = auditors.map(x => {
|
|
|
return {
|
|
|
- tid: stage.tid, stage_id: stage.id, audit_id: x.audit_id,
|
|
|
+ tid: stage.tid, stage_id: stage.id, stage_type: stage.stage_type, audit_id: x.audit_id,
|
|
|
audit_times: stage.audit_times + 1, audit_order: x.audit_order, audit_type: x.audit_type,
|
|
|
active_order: x.audit_order, audit_status: auditConst.costStage.status.uncheck,
|
|
|
name: x.name, company: x.company, role: x.role, mobile: x.mobile,
|
|
|
@@ -668,7 +670,7 @@ module.exports = app => {
|
|
|
try {
|
|
|
// 添加提醒
|
|
|
const noticeContent = await this._getNoticeContent(pid, selfAudit.tid, stage.id, selfAudit.audit_id, opinion);
|
|
|
- const defaultNoticeRecord = { pid, tid: selfAudit.tid, type: pushType[stage.typeInfo.push_type], status: auditConst.costStage.status.checkNo, content: noticeContent };
|
|
|
+ const defaultNoticeRecord = { pid, spid: this.ctx.tender.spid, tid: selfAudit.tid, type: pushType[stage.typeInfo.push_type], status: auditConst.costStage.status.checkNo, content: noticeContent };
|
|
|
const records = stage.userIds.map(x => {
|
|
|
return { uid: x, ...defaultNoticeRecord };
|
|
|
});
|
|
|
@@ -729,7 +731,7 @@ module.exports = app => {
|
|
|
// 添加通知
|
|
|
const noticeContent = await this._getNoticeContent(pid, stage.tid, stage.id, selfAudit.audit_id, opinion);
|
|
|
const defaultNoticeRecord = {
|
|
|
- pid, tid: stage.tid, type: pushType[stage.typeInfo.push_type], status: auditConst.costStage.status.checkNoPre, content: noticeContent,
|
|
|
+ pid, spid: this.ctx.tender.spid, tid: stage.tid, type: pushType[stage.typeInfo.push_type], status: auditConst.costStage.status.checkNoPre, content: noticeContent,
|
|
|
};
|
|
|
const records = stage.userIds.map(x => {
|
|
|
return { uid: x, ...defaultNoticeRecord };
|
|
|
@@ -759,7 +761,7 @@ module.exports = app => {
|
|
|
const newAuditors = [], uncheckAuditors = [];
|
|
|
preAuditors.forEach(x => {
|
|
|
newAuditors.push({
|
|
|
- tid: x.tid, stage_id: x.stage_id, audit_id: x.audit_id,
|
|
|
+ tid: x.tid, stage_id: x.stage_id, stage_type: x.stage_type, audit_id: x.audit_id,
|
|
|
audit_times: x.audit_times, audit_order: selfAudit.audit_order - 1,
|
|
|
audit_status: auditConst.costStage.status.checking,
|
|
|
audit_type: x.audit_type, active_order: selfAudit.active_order + 1,
|
|
|
@@ -773,7 +775,7 @@ module.exports = app => {
|
|
|
}
|
|
|
stage.flowAuditors.forEach(x => {
|
|
|
uncheckAuditors.push({
|
|
|
- tid: x.tid, stage_id: x.stage_id, audit_id: x.audit_id,
|
|
|
+ tid: x.tid, stage_id: x.stage_id, stage_type: x.stage_type, audit_id: x.audit_id,
|
|
|
audit_times: x.audit_times, active_order: selfAudit.active_order + 2,
|
|
|
audit_status: auditConst.costStage.status.uncheck,
|
|
|
audit_type: x.audit_type, audit_order: x.audit_order,
|
|
|
@@ -855,7 +857,7 @@ module.exports = app => {
|
|
|
const checkAgainAuditors = [], checkingAuditors = [];
|
|
|
finalAudits.forEach(x => {
|
|
|
checkAgainAuditors.push({
|
|
|
- tid: x.tid, stage_id: x.stage_id, audit_id: x.audit_id,
|
|
|
+ tid: x.tid, stage_id: x.stage_id, stage_type: x.stage_type, audit_id: x.audit_id,
|
|
|
audit_type: x.audit_type, audit_order: x.audit_order,
|
|
|
audit_times: x.audit_times, active_order: x.active_order + 1,
|
|
|
audit_status: x.audit_id === finalAudit.audit_id ? auditConst.costStage.status.checkAgain : auditConst.costStage.status.checkSkip,
|
|
|
@@ -865,7 +867,7 @@ module.exports = app => {
|
|
|
});
|
|
|
finalAudits.forEach(x => {
|
|
|
checkingAuditors.push({
|
|
|
- tid: x.tid, stage_id: x.stage_id, audit_id: x.audit_id,
|
|
|
+ tid: x.tid, stage_id: x.stage_id, stage_type: x.stage_type, audit_id: x.audit_id,
|
|
|
audit_type: x.audit_type, audit_order: x.audit_order,
|
|
|
audit_times: x.audit_times, active_order: x.active_order + 2,
|
|
|
audit_status: auditConst.costStage.status.checking, audit_time: time, opinion: '',
|
|
|
@@ -990,7 +992,7 @@ module.exports = app => {
|
|
|
const checkCancelAuditors = [], checkingAuditors = [];
|
|
|
stage.preAuditors.forEach(x => {
|
|
|
checkCancelAuditors.push({
|
|
|
- tid: stage.tid, stage_id: stage.id, audit_id: x.audit_id,
|
|
|
+ tid: stage.tid, stage_id: stage.id, stage_type: stage.stage_type, audit_id: x.audit_id,
|
|
|
audit_times: x.audit_times, active_order: x.active_order + 1,
|
|
|
audit_type: x.audit_type, audit_order: x.audit_order,
|
|
|
audit_status: x.audit_id === selfAuditor.audit_id ? auditConst.costStage.status.checkCancel : auditConst.costStage.status.checkSkip,
|
|
|
@@ -1000,7 +1002,7 @@ module.exports = app => {
|
|
|
});
|
|
|
stage.preAuditors.forEach(x => {
|
|
|
checkingAuditors.push({
|
|
|
- tid: stage.tid, stage_id: stage.id, audit_id: x.audit_id,
|
|
|
+ tid: stage.tid, stage_id: stage.id, stage_type: stage.stage_type, audit_id: x.audit_id,
|
|
|
audit_times: x.audit_times, active_order: x.active_order + 2,
|
|
|
audit_type: x.audit_type, audit_order: x.audit_order,
|
|
|
audit_status: auditConst.costStage.status.checking,
|
|
|
@@ -1054,7 +1056,7 @@ module.exports = app => {
|
|
|
const newAuditors = [];
|
|
|
stage.preAuditors.forEach(x => {
|
|
|
newAuditors.push({
|
|
|
- tid: stage.tid, stage_id: stage.id, audit_id: x.audit_id,
|
|
|
+ tid: stage.tid, stage_id: stage.id, stage_type: stage.stage_type, audit_id: x.audit_id,
|
|
|
audit_times: x.audit_times, active_order: x.active_order + 1,
|
|
|
audit_type: x.audit_type, audit_order: x.audit_order,
|
|
|
audit_status: x.audit_id === selfAuditor.audit_id ? auditConst.costStage.status.checkCancel : auditConst.costStage.status.checkSkip,
|
|
|
@@ -1105,7 +1107,7 @@ module.exports = app => {
|
|
|
const checkCancelAuditors = [], checkingAuditors = [];
|
|
|
stage.preAuditors.forEach(x => {
|
|
|
checkCancelAuditors.push({
|
|
|
- tid: stage.tid, stage_id: stage.id, audit_id: x.audit_id,
|
|
|
+ tid: stage.tid, stage_id: stage.id, stage_type: stage.stage_type, audit_id: x.audit_id,
|
|
|
audit_times: x.audit_times, active_order: x.active_order + 1,
|
|
|
audit_type: x.audit_type, audit_order: x.audit_order,
|
|
|
audit_status: x.audit_id === selfAuditor.audit_id ? auditConst.costStage.status.checkCancel : auditConst.costStage.status.checkSkip,
|
|
|
@@ -1115,7 +1117,7 @@ module.exports = app => {
|
|
|
});
|
|
|
stage.preAuditors.forEach(x => {
|
|
|
checkingAuditors.push({
|
|
|
- tid: stage.tid, stage_id: stage.id, audit_id: x.audit_id,
|
|
|
+ tid: stage.tid, stage_id: stage.id, stage_type: stage.stage_type, audit_id: x.audit_id,
|
|
|
audit_times: x.audit_times, active_order: x.active_order + 2,
|
|
|
audit_type: x.audit_type, audit_order: x.audit_order,
|
|
|
audit_status: auditConst.costStage.status.checking,
|