|
@@ -102,23 +102,23 @@ module.exports = app => {
|
|
switch (status) {
|
|
switch (status) {
|
|
case auditConst.status.checking:
|
|
case auditConst.status.checking:
|
|
case auditConst.status.checked:
|
|
case auditConst.status.checked:
|
|
- cur = await this.db.queryOne(`SELECT * From ${this.tableName} where tender_id = ? AND times = ? AND status = ? ORDER By times DESC, ` + '`order` DESC', [tenderId, times, status]);
|
|
|
|
|
|
+ cur = await this.db.queryOne(`SELECT * From ${this.tableName} where tender_id = ? AND times = ? AND status = ? ORDER By times DESC, ` + '`audit_order` DESC', [tenderId, times, status]);
|
|
if (!cur) return [];
|
|
if (!cur) return [];
|
|
|
|
|
|
sql = 'SELECT la.`audit_id`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`tender_id`, la.audit_order, la.audit_type, la.audit_ledger_id ' +
|
|
sql = 'SELECT la.`audit_id`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`tender_id`, la.audit_order, la.audit_type, la.audit_ledger_id ' +
|
|
' FROM ?? AS la Left Join ?? AS pa On la.`audit_id` = pa.`id` ' +
|
|
' FROM ?? AS la Left Join ?? AS pa On la.`audit_id` = pa.`id` ' +
|
|
' WHERE la.`tender_id` = ? and la.`audit_order` = ? and la.`times` = ?';
|
|
' WHERE la.`tender_id` = ? and la.`audit_order` = ? and la.`times` = ?';
|
|
- sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, tenderId, cur.order, times];
|
|
|
|
|
|
+ sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, tenderId, cur.audit_order, times];
|
|
auditor = await this.db.query(sql, sqlParam);
|
|
auditor = await this.db.query(sql, sqlParam);
|
|
break;
|
|
break;
|
|
case auditConst.status.checkNo:
|
|
case auditConst.status.checkNo:
|
|
- cur = await this.db.queryOne(`SELECT * From ${this.tableName} where tender_id = ? AND times = ? AND status = ? ORDER By times DESC, ` + '`order` DESC', [tenderId, parseInt(times) - 1, status]);
|
|
|
|
|
|
+ cur = await this.db.queryOne(`SELECT * From ${this.tableName} where tender_id = ? AND times = ? AND status = ? ORDER By times DESC, ` + '`audit_order` DESC', [tenderId, parseInt(times) - 1, status]);
|
|
if (!cur) return [];
|
|
if (!cur) return [];
|
|
|
|
|
|
sql = 'SELECT la.`audit_id`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`tender_id`, la.audit_order, la.audit_type, la.audit_ledger_id ' +
|
|
sql = 'SELECT la.`audit_id`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`tender_id`, la.audit_order, la.audit_type, la.audit_ledger_id ' +
|
|
' FROM ?? AS la Left Join ?? AS pa On la.`audit_id` = pa.`id` ' +
|
|
' FROM ?? AS la Left Join ?? AS pa On la.`audit_id` = pa.`id` ' +
|
|
- ' WHERE la.`sid` = ? and la.`audit_order` = ? and la.`times` = ?';
|
|
|
|
- sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, tenderId, cur.order, parseInt(times) - 1];
|
|
|
|
|
|
+ ' WHERE la.`tender_id` = ? and la.`audit_order` = ? and la.`times` = ?';
|
|
|
|
+ sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, tenderId, cur.audit_order, parseInt(times) - 1];
|
|
auditor = await this.db.query(sql, sqlParam);
|
|
auditor = await this.db.query(sql, sqlParam);
|
|
break;
|
|
break;
|
|
case auditConst.status.uncheck:
|
|
case auditConst.status.uncheck:
|
|
@@ -213,6 +213,8 @@ module.exports = app => {
|
|
|
|
|
|
async getUniqUserGroup(tenderId, times) {
|
|
async getUniqUserGroup(tenderId, times) {
|
|
const group = await this.getAuditorGroup(tenderId, times);
|
|
const group = await this.getAuditorGroup(tenderId, times);
|
|
|
|
+ // 台账因为可选原报人为审批人,这里有点不同,这里要先过滤再取原报插入
|
|
|
|
+ const newGroup = this.groupAuditorsUniq(group);
|
|
const sql =
|
|
const sql =
|
|
'SELECT pa.`id` As audit_id, pa.`name`, pa.`company`, pa.`role`, ? As times, ? As tender_id, 0 As audit_order, 1 As audit_type' +
|
|
'SELECT pa.`id` As audit_id, pa.`name`, pa.`company`, pa.`role`, ? As times, ? As tender_id, 0 As audit_order, 1 As audit_type' +
|
|
' FROM ' + this.ctx.service.tender.tableName + ' As t' +
|
|
' FROM ' + this.ctx.service.tender.tableName + ' As t' +
|
|
@@ -221,8 +223,8 @@ module.exports = app => {
|
|
' WHERE t.id = ?';
|
|
' WHERE t.id = ?';
|
|
const sqlParam = [times, tenderId, tenderId];
|
|
const sqlParam = [times, tenderId, tenderId];
|
|
const user = await this.db.queryOne(sql, sqlParam);
|
|
const user = await this.db.queryOne(sql, sqlParam);
|
|
- group.unshift([ user ]);
|
|
|
|
- return this.groupAuditorsUniq(group);
|
|
|
|
|
|
+ newGroup.unshift([ user ]);
|
|
|
|
+ return newGroup;
|
|
}
|
|
}
|
|
|
|
|
|
async getAuditorHistory(tenderId, times, reverse = false) {
|
|
async getAuditorHistory(tenderId, times, reverse = false) {
|
|
@@ -611,8 +613,10 @@ module.exports = app => {
|
|
where: { tender_id: tenderId, times },
|
|
where: { tender_id: tenderId, times },
|
|
columns: ['tender_id', 'audit_order', 'audit_id', 'audit_type', 'audit_ledger_id'],
|
|
columns: ['tender_id', 'audit_order', 'audit_id', 'audit_type', 'audit_ledger_id'],
|
|
});
|
|
});
|
|
- const insertAuditors = orgAuditors.map(x => {
|
|
|
|
- return { ...x, times: times + 1, status: auditConst.status.uncheck };
|
|
|
|
|
|
+ const insertAuditors = [];
|
|
|
|
+ orgAuditors.forEach(x => {
|
|
|
|
+ if (insertAuditors.find(y => { return y.audit_id === x.audit_id && y.audit_type === x.audit_type})) return;
|
|
|
|
+ insertAuditors.push({ ...x, times: times + 1, status: auditConst.status.uncheck });
|
|
});
|
|
});
|
|
await transaction.insert(this.tableName, insertAuditors);
|
|
await transaction.insert(this.tableName, insertAuditors);
|
|
|
|
|
|
@@ -913,7 +917,7 @@ module.exports = app => {
|
|
// const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, tender_id, times];
|
|
// const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, tender_id, times];
|
|
// return transaction ? await transaction.query(sql, sqlParam) : await this.db.query(sql, sqlParam);
|
|
// return transaction ? await transaction.query(sql, sqlParam) : await this.db.query(sql, sqlParam);
|
|
const sql =
|
|
const sql =
|
|
- 'SELECT la.`audit_id`, la.`status`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`tender_id`, la.`audit_order` ' +
|
|
|
|
|
|
+ 'SELECT la.`audit_id`, la.`status`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`tender_id`, la.`audit_order`, la.`audit_type` ' +
|
|
' FROM ?? AS la Left Join ?? AS pa On la.`audit_id` = pa.`id`' +
|
|
' FROM ?? AS la Left Join ?? AS pa On la.`audit_id` = pa.`id`' +
|
|
' WHERE la.`tender_id` = ? and la.`times` = ? ORDER BY la.`audit_order` DESC';
|
|
' WHERE la.`tender_id` = ? and la.`times` = ? ORDER BY la.`audit_order` DESC';
|
|
const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, tender_id, times];
|
|
const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, tender_id, times];
|
|
@@ -975,7 +979,7 @@ module.exports = app => {
|
|
const existAudit = auditList.find(x => { return x.audit_id === lastId });
|
|
const existAudit = auditList.find(x => { return x.audit_id === lastId });
|
|
let order = auditList.length > 0 ? auditList.reduce((rst, a) => { return Math.max(rst, a.audit_order)}, 0) + 1 : 1; // 最大值 + 1
|
|
let order = auditList.length > 0 ? auditList.reduce((rst, a) => { return Math.max(rst, a.audit_order)}, 0) + 1 : 1; // 最大值 + 1
|
|
if (existAudit) {
|
|
if (existAudit) {
|
|
- await transaction.delete(this.tableName, { sid: stage.id, times: stage.times, audit_id: lastId });
|
|
|
|
|
|
+ await transaction.delete(this.tableName, { tender_id: tender.id, times: tender.ledger_times, audit_id: lastId });
|
|
const sameOrder = auditList.filter(x => { return x.audit_order === existAudit.audit_order });
|
|
const sameOrder = auditList.filter(x => { return x.audit_order === existAudit.audit_order });
|
|
if (sameOrder.length === 1) {
|
|
if (sameOrder.length === 1) {
|
|
const updateData = [];
|
|
const updateData = [];
|
|
@@ -1010,11 +1014,15 @@ module.exports = app => {
|
|
* @param {Object} data - 更改参数
|
|
* @param {Object} data - 更改参数
|
|
* @return {Promise<void>}
|
|
* @return {Promise<void>}
|
|
*/
|
|
*/
|
|
- async saveAudit(tenderId, times, data) {
|
|
|
|
|
|
+ async saveAudit(tenderId, times, sp_group, data) {
|
|
const transaction = await this.db.beginTransaction();
|
|
const transaction = await this.db.beginTransaction();
|
|
try {
|
|
try {
|
|
const auditors = await this.getAuditGroupByList(tenderId, times);
|
|
const auditors = await this.getAuditGroupByList(tenderId, times);
|
|
const now_audit = this._.find(auditors, { audit_id: data.old_aid });
|
|
const now_audit = this._.find(auditors, { audit_id: data.old_aid });
|
|
|
|
+ if (data.operate !== 'del') {
|
|
|
|
+ const exist = await this.getDataByCondition({ tender_id: tenderId, times, audit_id: data.new_aid });
|
|
|
|
+ if (exist) throw '该审核人已存在,请勿重复添加';
|
|
|
|
+ }
|
|
if (data.operate === 'add') {
|
|
if (data.operate === 'add') {
|
|
if (now_audit.status !== auditConst.status.uncheck && now_audit.status !== auditConst.status.checking) {
|
|
if (now_audit.status !== auditConst.status.uncheck && now_audit.status !== auditConst.status.checking) {
|
|
throw '当前人下无法操作新增';
|
|
throw '当前人下无法操作新增';
|
|
@@ -1023,6 +1031,7 @@ module.exports = app => {
|
|
tender_id: tenderId,
|
|
tender_id: tenderId,
|
|
audit_id: data.new_aid,
|
|
audit_id: data.new_aid,
|
|
audit_order: now_audit.audit_order + 1,
|
|
audit_order: now_audit.audit_order + 1,
|
|
|
|
+ audit_type: auditType.key.common,
|
|
times,
|
|
times,
|
|
status: auditConst.status.uncheck,
|
|
status: auditConst.status.uncheck,
|
|
};
|
|
};
|
|
@@ -1030,12 +1039,26 @@ module.exports = app => {
|
|
await this._syncOrderByDelete(transaction, tenderId, now_audit.audit_order + 1, times, '+');
|
|
await this._syncOrderByDelete(transaction, tenderId, now_audit.audit_order + 1, times, '+');
|
|
await transaction.insert(this.tableName, newAudit);
|
|
await transaction.insert(this.tableName, newAudit);
|
|
// 更新审批流程页数据,如果存在
|
|
// 更新审批流程页数据,如果存在
|
|
|
|
+ } else if (data.operate === 'add-sibling') {
|
|
|
|
+ if (now_audit.status !== auditConst.status.uncheck && now_audit.status !== auditConst.status.checking) {
|
|
|
|
+ throw '当前人下无法操作新增';
|
|
|
|
+ }
|
|
|
|
+ const newAudit = {
|
|
|
|
+ tender_id: tenderId,
|
|
|
|
+ audit_id: data.new_aid,
|
|
|
|
+ audit_order: now_audit.audit_order,
|
|
|
|
+ audit_type: now_audit.audit_type,
|
|
|
|
+ times: times,
|
|
|
|
+ status: auditConst.status.uncheck,
|
|
|
|
+ };
|
|
|
|
+ await transaction.insert(this.tableName, newAudit);
|
|
} else if (data.operate === 'del') {
|
|
} else if (data.operate === 'del') {
|
|
if (now_audit.status !== auditConst.status.uncheck) {
|
|
if (now_audit.status !== auditConst.status.uncheck) {
|
|
throw '当前人无法操作删除';
|
|
throw '当前人无法操作删除';
|
|
}
|
|
}
|
|
|
|
+ const flowAuditors = auditors.filter(x => { return x.audit_order === now_audit.audit_order; });
|
|
await transaction.delete(this.tableName, { tender_id: tenderId, times, audit_id: now_audit.audit_id, audit_order: now_audit.audit_order });
|
|
await transaction.delete(this.tableName, { tender_id: tenderId, times, audit_id: now_audit.audit_id, audit_order: now_audit.audit_order });
|
|
- await this._syncOrderByDelete(transaction, tenderId, now_audit.audit_order, times);
|
|
|
|
|
|
+ if (flowAuditors.length === 1) await this._syncOrderByDelete(transaction, tenderId, now_audit.audit_order, times);
|
|
} else if (data.operate === 'change') {
|
|
} else if (data.operate === 'change') {
|
|
const nowAudit = await this.getDataByCondition({ tender_id: tenderId, times, audit_id: now_audit.audit_id, audit_order: now_audit.audit_order });
|
|
const nowAudit = await this.getDataByCondition({ tender_id: tenderId, times, audit_id: now_audit.audit_id, audit_order: now_audit.audit_order });
|
|
if (now_audit.status !== auditConst.status.uncheck || !nowAudit) {
|
|
if (now_audit.status !== auditConst.status.uncheck || !nowAudit) {
|
|
@@ -1044,7 +1067,12 @@ module.exports = app => {
|
|
nowAudit.audit_id = data.new_aid;
|
|
nowAudit.audit_id = data.new_aid;
|
|
await transaction.update(this.tableName, nowAudit);
|
|
await transaction.update(this.tableName, nowAudit);
|
|
}
|
|
}
|
|
- if (this.ctx.tender.info.shenpi.ledger === shenpiConst.sp_status.gdspl || this.ctx.tender.info.shenpi.ledger === shenpiConst.sp_status.gdzs) {
|
|
|
|
|
|
+ if (this.ctx.tender.info.shenpi.ledger === shenpiConst.sp_status.gdspl) {
|
|
|
|
+ const newAuditors = await transaction.select(this.tableName, { where: { tender_id: tenderId, times } });
|
|
|
|
+ const newAuditorGroup = this.ctx.helper.groupAuditors(newAuditors, 'audit_order');
|
|
|
|
+ const uniqNewAuditorGroup = this.ctx.helper.groupAuditorsUniq(newAuditorGroup);
|
|
|
|
+ await this.ctx.service.shenpiAudit.updateAuditListWithAuditType(transaction, this.ctx.tender.id, this.ctx.tender.info.shenpi.ledger, shenpiConst.sp_type.ledger, uniqNewAuditorGroup, sp_group);
|
|
|
|
+ } else if (this.ctx.tender.info.shenpi.ledger === shenpiConst.sp_status.gdzs) {
|
|
const newAuditors = await this.getAuditGroupByList(tenderId, times, transaction);
|
|
const newAuditors = await this.getAuditGroupByList(tenderId, times, transaction);
|
|
await this.ctx.service.shenpiAudit.updateAuditList(transaction, this.ctx.tender.id, this.ctx.tender.info.shenpi.ledger, shenpiConst.sp_type.ledger, this._.map(newAuditors, 'audit_id'));
|
|
await this.ctx.service.shenpiAudit.updateAuditList(transaction, this.ctx.tender.id, this.ctx.tender.info.shenpi.ledger, shenpiConst.sp_type.ledger, this._.map(newAuditors, 'audit_id'));
|
|
}
|
|
}
|