|
|
@@ -27,11 +27,16 @@ module.exports = app => {
|
|
|
this.tableName = 'contract_sp_audit';
|
|
|
}
|
|
|
|
|
|
- async checkShenpi(contract) {
|
|
|
+ async checkShenpi(contract, type = 'contract') {
|
|
|
const cid = contract.cid ? contract.cid : contract.id;
|
|
|
- const cpid = contract.cid ? contract.id : null;
|
|
|
- const change_type = contract.cid ? contractConst.typeMap[contract.contract_type] : 'contract';
|
|
|
- const tableName = contract.cid ? this.ctx.service.contractPay : this.ctx.service.contract;
|
|
|
+ const cpid = type === 'pay' ? contract.id : null;
|
|
|
+ const csid = type === 'supplement' ? contract.id : null;
|
|
|
+ const change_type = type === 'contract' || type === 'supplement' ? 'contract' : contractConst.typeMap[contract.contract_type];
|
|
|
+ const tableName = {
|
|
|
+ contract: this.ctx.service.contract,
|
|
|
+ pay: this.ctx.service.contractPay,
|
|
|
+ supplement: this.ctx.service.contractSupplement,
|
|
|
+ }[type];
|
|
|
const status = auditConst.status;
|
|
|
let shenpi = '';
|
|
|
if (this.ctx.contract_tender) {
|
|
|
@@ -43,7 +48,7 @@ module.exports = app => {
|
|
|
const shenpi_status = shenpi.contract;
|
|
|
if ((contract.status === status.uncheck || contract.status === status.checkNo) && shenpi_status !== shenpiConst.sp_status.sqspr) {
|
|
|
// 进一步比较审批流是否与审批流程设置的相同,不同则替换为固定审批流或固定的终审
|
|
|
- const auditList = await this.getAllDataByCondition({ where: { cid, cpid, times: contract.times }, orders: [['order', 'asc']] });
|
|
|
+ const auditList = await this.getAllDataByCondition({ where: { cid, cpid, csid, times: contract.times }, orders: [['order', 'asc']] });
|
|
|
// auditList.shift();
|
|
|
if (shenpi_status === shenpiConst.sp_status.gdspl) {
|
|
|
// 判断并获取审批组
|
|
|
@@ -68,9 +73,9 @@ module.exports = app => {
|
|
|
}
|
|
|
}
|
|
|
if (!sameAudit) {
|
|
|
- await this.updateNewAuditList(contract, shenpiList);
|
|
|
- await this.loadUser(contract);
|
|
|
- await this.loadAuditViewData(contract);
|
|
|
+ await this.updateNewAuditList(contract, type, shenpiList);
|
|
|
+ await this.loadUser(contract, type);
|
|
|
+ await this.loadAuditViewData(contract, type);
|
|
|
}
|
|
|
}
|
|
|
} else if (shenpi_status === shenpiConst.sp_status.gdzs) {
|
|
|
@@ -78,7 +83,7 @@ module.exports = app => {
|
|
|
// 判断最后一个id是否与固定终审id相同,不同则删除原审批流中如果存在的id和添加终审
|
|
|
const lastAuditors = auditList.filter(x => { return x.audit_order === auditList.length - 1; });
|
|
|
if (shenpiInfo && (lastAuditors.length === 0 || (lastAuditors.length > 1 || shenpiInfo.audit_id !== lastAuditors[0].aid))) {
|
|
|
- await this.updateLastAudit(contract, auditList, shenpiInfo.audit_id);
|
|
|
+ await this.updateLastAudit(contract, type, auditList, shenpiInfo.audit_id);
|
|
|
} else if (!shenpiInfo) {
|
|
|
// 不存在终审人的状态下这里恢复为授权审批人
|
|
|
shenpi.contract = shenpiConst.sp_status.sqspr;
|
|
|
@@ -87,12 +92,12 @@ module.exports = app => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- async loadUser(contract) {
|
|
|
+ async loadUser(contract, type = 'contract') {
|
|
|
const status = auditConst.status;
|
|
|
const accountId = this.ctx.session.sessionUser.accountId;
|
|
|
|
|
|
contract.user = await this.ctx.service.projectAccount.getAccountInfoById(contract.uid);
|
|
|
- contract.auditors = await this.getAuditors(contract.cid ? contract.cid : contract.id, contract.cid ? contract.id : null, contract.times); // 全部参与的审批人
|
|
|
+ contract.auditors = await this.getAuditors(contract, type, contract.times); // 全部参与的审批人
|
|
|
contract.auditorIds = this._.map(contract.auditors, 'aid');
|
|
|
contract.curAuditors = contract.auditors.filter(x => { return x.status === status.checking; }); // 当前流程中审批中的审批人
|
|
|
contract.curAuditorIds = this._.map(contract.curAuditors, 'aid');
|
|
|
@@ -105,21 +110,21 @@ module.exports = app => {
|
|
|
contract.finalAuditorIds = this._.map(contract.userGroups[contract.userGroups.length - 1], 'aid');
|
|
|
}
|
|
|
|
|
|
- async loadAuditViewData(contract) {
|
|
|
+ async loadAuditViewData(contract, type = 'contract') {
|
|
|
const times = contract.status === auditConst.status.checkNo ? contract.times - 1 : contract.times;
|
|
|
|
|
|
if (!contract.user) contract.user = await this.ctx.service.projectAccount.getAccountInfoById(contract.uid);
|
|
|
- contract.auditHistory = await this.getAuditorHistory(contract.cid ? contract.cid : contract.id, contract.cid ? contract.id : null, times);
|
|
|
+ contract.auditHistory = await this.getAuditorHistory(contract, type, times);
|
|
|
// 获取审批流程中左边列表
|
|
|
// if ((contract.status === auditConst.status.checkNo) && !(contract.uid === this.ctx.session.sessionUser.accountId || this.ctx.contract_audit_permission.permission_edit_contract || this.ctx.session.sessionUser.is_admin)) {
|
|
|
- const auditors = await this.getAuditors(contract.cid ? contract.cid : contract.id, contract.cid ? contract.id : null, times); // 全部参与的审批人
|
|
|
+ const auditors = await this.getAuditors(contract, type, times); // 全部参与的审批人
|
|
|
const auditorGroups = this.ctx.helper.groupAuditors(auditors);
|
|
|
contract.auditors2 = this.ctx.helper.groupAuditorsUniq(auditorGroups);
|
|
|
// } else {
|
|
|
// contract.auditors2 = contract.userGroups;
|
|
|
// }
|
|
|
if (contract.status === auditConst.status.uncheck || contract.status === auditConst.status.checkNo) {
|
|
|
- contract.auditorList = await this.getAuditors(contract.cid ? contract.cid : contract.id, contract.cid ? contract.id : null, contract.times);
|
|
|
+ contract.auditorList = await this.getAuditors(contract, type, contract.times);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -130,7 +135,7 @@ module.exports = app => {
|
|
|
* @param {Number} times - 第几次审批
|
|
|
* @return {Promise<*>}
|
|
|
*/
|
|
|
- async getAuditors(cid, cpid = null, times = 1, order_sort = 'asc', noYB = false) {
|
|
|
+ async getAuditors(contract, type, times = 1, order_sort = 'asc', noYB = false) {
|
|
|
// const sql = 'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, pa.`mobile`, pa.`telephone`, la.`times`, la.`order`, la.`status`, la.`opinion`, la.`begin_time`, la.`end_time`, g.`sort` ' +
|
|
|
// 'FROM ?? AS la, ?? AS pa, (SELECT t1.`aid`,(@i:=@i+1) as `sort` FROM (SELECT t.`aid`, t.`order` FROM (select `aid`, `order` from ?? WHERE `cpid` = ? AND `times` = ? ORDER BY `order` LIMIT 200) t GROUP BY t.`aid` ORDER BY t.`order`) t1, (select @i:=0) as it) as g ' +
|
|
|
// 'WHERE la.`cpid` = ? and la.`times` = ? and la.`aid` = pa.`id` and g.`aid` = la.`aid` order by la.`order`';
|
|
|
@@ -142,12 +147,20 @@ module.exports = app => {
|
|
|
// for (const i in result) {
|
|
|
// result[i].max_sort = count.num;
|
|
|
// }
|
|
|
+ const cid = contract.cid ? contract.cid : contract.id;
|
|
|
+ const cpid = type === 'pay' ? contract.id : null;
|
|
|
+ const csid = type === 'supplement' ? contract.id : null;
|
|
|
+ const cpidSql = type === 'pay'
|
|
|
+ ? ' AND la.cpid = ' + cpid
|
|
|
+ : ' AND la.cpid is null';
|
|
|
+ const csidSql = type === 'supplement'
|
|
|
+ ? ' AND la.csid = ' + csid
|
|
|
+ : ' AND la.csid is null';
|
|
|
const ybSql = noYB ? ' AND la.audit_order != 0' : '';
|
|
|
- const cpidSql = cpid ? ' AND la.cpid = ' + cpid : ' AND la.cpid is null';
|
|
|
const sql = 'SELECT la.id, la.aid, la.times, la.order, la.status, la.opinion, la.begin_time, la.end_time, la.audit_type, la.audit_order,' +
|
|
|
' pa.name, pa.company, pa.role, pa.mobile, pa.telephone' +
|
|
|
` FROM ${this.tableName} la LEFT JOIN ${this.ctx.service.projectAccount.tableName} pa ON la.aid = pa.id` +
|
|
|
- ' WHERE la.cid = ?' + cpidSql + ' AND la.times = ?' + ybSql +
|
|
|
+ ' WHERE la.cid = ?' + cpidSql + csidSql + ' AND la.times = ?' + ybSql +
|
|
|
' ORDER BY la.order ' + order_sort;
|
|
|
const sqlParam = [cid, times];
|
|
|
const result = await this.db.query(sql, sqlParam);
|
|
|
@@ -165,21 +178,37 @@ module.exports = app => {
|
|
|
* @param {Number} times - 第几次审批
|
|
|
* @return {Promise<*>}
|
|
|
*/
|
|
|
- async getCurAuditor(cid, cpid = null, times = 1) {
|
|
|
- const cpidSql = cpid ? ' AND la.cpid = ' + cpid : ' AND la.cpid is null';
|
|
|
+ async getCurAuditor(contract, type, times = 1) {
|
|
|
+ const cid = contract.cid ? contract.cid : contract.id;
|
|
|
+ const cpid = type === 'pay' ? contract.id : null;
|
|
|
+ const csid = type === 'supplement' ? contract.id : null;
|
|
|
+ const cpidSql = type === 'pay'
|
|
|
+ ? ' AND la.cpid = ' + cpid
|
|
|
+ : ' AND la.cpid is null';
|
|
|
+ const csidSql = type === 'supplement'
|
|
|
+ ? ' AND la.csid = ' + csid
|
|
|
+ : ' AND la.csid is null';
|
|
|
const sql = 'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, pa.`mobile`, pa.`telephone`, la.`times`, la.`order`, la.`status`, la.`opinion`, la.`begin_time`, la.`end_time` ' +
|
|
|
' FROM ?? AS la Left Join ?? AS pa On la.`aid` = pa.`id` ' +
|
|
|
- ' WHERE la.`cid` = ?' + cpidSql + ' and la.`status` = ? and la.`times` = ? and la.`audit_order` != 0';
|
|
|
+ ' WHERE la.`cid` = ?' + cpidSql + csidSql + ' and la.`status` = ? and la.`times` = ? and la.`audit_order` != 0';
|
|
|
const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, cid, auditConst.status.checking, times];
|
|
|
return await this.db.queryOne(sql, sqlParam);
|
|
|
}
|
|
|
|
|
|
- async getCurAuditors(cid, cpid = null, times = 1) {
|
|
|
- const cpidSql = cpid ? ' AND la.cpid = ' + cpid : ' AND la.cpid is null';
|
|
|
+ async getCurAuditors(contract, type, times = 1) {
|
|
|
+ const cid = contract.cid ? contract.cid : contract.id;
|
|
|
+ const cpid = type === 'pay' ? contract.id : null;
|
|
|
+ const csid = type === 'supplement' ? contract.id : null;
|
|
|
+ const cpidSql = type === 'pay'
|
|
|
+ ? ' AND la.cpid = ' + cpid
|
|
|
+ : ' AND la.cpid is null';
|
|
|
+ const csidSql = type === 'supplement'
|
|
|
+ ? ' AND la.csid = ' + csid
|
|
|
+ : ' AND la.csid is null';
|
|
|
const sql =
|
|
|
'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, pa.`mobile`, pa.`telephone`, la.`times`, la.`order`, la.`status`, la.`opinion`, la.`begin_time`, la.`end_time`, la.audit_type, la.audit_order ' +
|
|
|
' FROM ?? AS la Left Join ?? AS pa On la.`aid` = pa.`id`' +
|
|
|
- ' WHERE la.`cid` = ?' + cpidSql + ' and la.`status` = ? and la.`times` = ? and la.`audit_order` != 0';
|
|
|
+ ' WHERE la.`cid` = ?' + cpidSql + csidSql + ' and la.`status` = ? and la.`times` = ? and la.`audit_order` != 0';
|
|
|
const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, cid, auditConst.status.checking, times];
|
|
|
return await this.db.query(sql, sqlParam);
|
|
|
}
|
|
|
@@ -205,18 +234,21 @@ module.exports = app => {
|
|
|
* @param auditorId
|
|
|
* @return {Promise<*>}
|
|
|
*/
|
|
|
- async getAuditGroupByList(cid, cpid = null, times, transaction = false) {
|
|
|
- // const sql =
|
|
|
- // 'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`sid`, la.`aid`, la.`order`, la.`status`' +
|
|
|
- // ' FROM ?? AS la Left Join ?? AS pa On la.`aid` = pa.`id` ' +
|
|
|
- // ' WHERE la.`sid` = ? and la.`times` = ? and la.`is_old` = 0 GROUP BY la.`aid` ORDER BY la.`order`';
|
|
|
- // const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, stageId, times];
|
|
|
- const cpidSql = cpid ? ' AND la.`cpid` = ' + cpid : ' AND la.`cpid` is null';
|
|
|
+ async getAuditGroupByList(contract, type, times, transaction = false) {
|
|
|
+ const cid = contract.cid ? contract.cid : contract.id;
|
|
|
+ const cpid = type === 'pay' ? contract.id : null;
|
|
|
+ const csid = type === 'supplement' ? contract.id : null;
|
|
|
+ const cpidSql = type === 'pay'
|
|
|
+ ? ' AND la.cpid = ' + cpid
|
|
|
+ : ' AND la.cpid is null';
|
|
|
+ const csidSql = type === 'supplement'
|
|
|
+ ? ' AND la.csid = ' + csid
|
|
|
+ : ' AND la.csid is null';
|
|
|
const sql =
|
|
|
'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`cid`, la.`cpid`, la.`aid`, la.`order`, la.`status`, la.audit_type, la.audit_order ' +
|
|
|
- ' FROM (SELECT `aid`, max(`order`) `order` FROM ?? WHERE `cid` = ? and `cpid` ' + (cpid ? '= ' + cpid : 'is null') + ' and `times` = ? and `audit_order` != 0 GROUP BY aid) sa' +
|
|
|
+ ' FROM (SELECT `aid`, max(`order`) `order` FROM ?? WHERE `cid` = ? and `cpid` ' + (cpid ? '= ' + cpid : 'is null') + ' and `csid` ' + (csid ? '= ' + csid : 'is null') + ' and `times` = ? and `audit_order` != 0 GROUP BY aid) sa' +
|
|
|
' LEFT JOIN ?? la ON sa.`aid` = la.`aid` AND sa.`order` = la.`order`' +
|
|
|
- ' Left JOIN ?? AS pa On la.`aid` = pa.`id` WHERE la.`cid` = ?' + cpidSql + ' and la.`times` = ? and la.`audit_order` != 0 order BY la.`order`';
|
|
|
+ ' Left JOIN ?? AS pa On la.`aid` = pa.`id` WHERE la.`cid` = ?' + cpidSql + csidSql + ' and la.`times` = ? and la.`audit_order` != 0 order BY la.`order`';
|
|
|
const sqlParam = [this.tableName, cid, times, this.tableName, this.ctx.service.projectAccount.tableName, cid, times];
|
|
|
return transaction !== false ? await transaction.query(sql, sqlParam) : await this.db.query(sql, sqlParam);
|
|
|
}
|
|
|
@@ -229,8 +261,16 @@ module.exports = app => {
|
|
|
* @param {Number} status - 期次数
|
|
|
* @return {Promise<boolean>}
|
|
|
*/
|
|
|
- async getAuditorByStatus(cid, cpid = null, status, times = 1) {
|
|
|
- const cpidSql = cpid ? ' AND la.cpid = ' + cpid : ' AND la.cpid is null';
|
|
|
+ async getAuditorByStatus(contract, type, status, times = 1) {
|
|
|
+ const cid = contract.cid ? contract.cid : contract.id;
|
|
|
+ const cpid = type === 'pay' ? contract.id : null;
|
|
|
+ const csid = type === 'supplement' ? contract.id : null;
|
|
|
+ const cpidSql = type === 'pay'
|
|
|
+ ? ' AND la.cpid = ' + cpid
|
|
|
+ : ' AND la.cpid is null';
|
|
|
+ const csidSql = type === 'supplement'
|
|
|
+ ? ' AND la.csid = ' + csid
|
|
|
+ : ' AND la.csid is null';
|
|
|
let auditor = null;
|
|
|
let sql = '';
|
|
|
let sqlParam = '';
|
|
|
@@ -239,7 +279,7 @@ module.exports = app => {
|
|
|
case auditConst.status.checked :
|
|
|
sql = 'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`cid`, la.`cpid`, la.`aid`, la.`order`, la.`status` ' +
|
|
|
' FROM ?? AS la Left Join ?? AS pa On la.`aid` = pa.`id` ' +
|
|
|
- ' WHERE la.`cid` = ?' + cpidSql + ' and la.`status` = ? ' +
|
|
|
+ ' WHERE la.`cid` = ?' + cpidSql + csidSql + ' and la.`status` = ? ' +
|
|
|
' ORDER BY la.`times` desc, la.`order` desc';
|
|
|
sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, cid, status];
|
|
|
auditor = await this.db.queryOne(sql, sqlParam);
|
|
|
@@ -247,7 +287,7 @@ module.exports = app => {
|
|
|
case auditConst.status.checkNo :
|
|
|
sql = 'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`cid`, la.`cpid`, la.`aid`, la.`order`, la.`status` ' +
|
|
|
' FROM ?? AS la Left Join ?? AS pa On la.`aid` = pa.`id`' +
|
|
|
- ' WHERE la.`cid` = ?' + cpidSql + ' and la.`status` = ? and la.`times` = ?' +
|
|
|
+ ' WHERE la.`cid` = ?' + cpidSql + csidSql + ' and la.`status` = ? and la.`times` = ?' +
|
|
|
' ORDER BY la.`times` desc, la.`order` desc';
|
|
|
sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, cid, auditConst.status.checkNo, parseInt(times) - 1];
|
|
|
auditor = await this.db.queryOne(sql, sqlParam);
|
|
|
@@ -259,8 +299,16 @@ module.exports = app => {
|
|
|
return auditor;
|
|
|
}
|
|
|
|
|
|
- async getAuditorsByStatus(cid, cpid = null, status, times = 1) {
|
|
|
- const cpidSql = cpid ? ' AND la.cpid = ' + cpid : ' AND la.cpid is null';
|
|
|
+ async getAuditorsByStatus(contract, type, status, times = 1) {
|
|
|
+ const cid = contract.cid ? contract.cid : contract.id;
|
|
|
+ const cpid = type === 'pay' ? contract.id : null;
|
|
|
+ const csid = type === 'supplement' ? contract.id : null;
|
|
|
+ const cpidSql = type === 'pay'
|
|
|
+ ? ' AND la.cpid = ' + cpid
|
|
|
+ : ' AND la.cpid is null';
|
|
|
+ const csidSql = type === 'supplement'
|
|
|
+ ? ' AND la.csid = ' + csid
|
|
|
+ : ' AND la.csid is null';
|
|
|
let auditor = [];
|
|
|
let sql = '';
|
|
|
let sqlParam = '';
|
|
|
@@ -269,22 +317,22 @@ module.exports = app => {
|
|
|
case auditConst.status.checking :
|
|
|
case auditConst.status.checked :
|
|
|
case auditConst.status.checkNoPre:
|
|
|
- cur = await this.db.queryOne('SELECT * From ?? where cid = ? AND cpid ' + (cpid ? '= ' + cpid : 'is null') + ' AND times = ? AND status = ? AND audit_order != 0 ORDER By times DESC, `order` DESC', [this.tableName, cid, times, status]);
|
|
|
+ cur = await this.db.queryOne('SELECT * From ?? where cid = ? AND cpid ' + (cpid ? '= ' + cpid : 'is null') + ' AND csid ' + (csid ? '= ' + csid : 'is null') + ' AND times = ? AND status = ? AND audit_order != 0 ORDER By times DESC, `order` DESC', [this.tableName, cid, times, status]);
|
|
|
if (!cur) return [];
|
|
|
|
|
|
sql = 'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`cid`, la.`cpid`, la.`order`, la.`status`, la.`audit_order`, la.`audit_type` ' +
|
|
|
' FROM ?? AS la Left Join ?? AS pa On la.`aid` = pa.`id` ' +
|
|
|
- ' WHERE la.`cid` = ?' + cpidSql + ' and la.`order` = ? and times = ?';
|
|
|
+ ' WHERE la.`cid` = ?' + cpidSql + csidSql + ' and la.`order` = ? and times = ?';
|
|
|
sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, cid, cur.order, times];
|
|
|
auditor = await this.db.query(sql, sqlParam);
|
|
|
break;
|
|
|
case auditConst.status.checkNo :
|
|
|
- cur = await this.db.queryOne('SELECT * From ?? where cid = ? AND cpid ' + (cpid ? '= ' + cpid : 'is null') + ' AND times = ? AND status = ? AND audit_order != 0 ORDER By times DESC, `order` DESC', [this.tableName, cid, parseInt(times) - 1, status]);
|
|
|
+ cur = await this.db.queryOne('SELECT * From ?? where cid = ? AND cpid ' + (cpid ? '= ' + cpid : 'is null') + ' AND csid ' + (csid ? '= ' + csid : 'is null') + ' AND times = ? AND status = ? AND audit_order != 0 ORDER By times DESC, `order` DESC', [this.tableName, cid, parseInt(times) - 1, status]);
|
|
|
if (!cur) return [];
|
|
|
|
|
|
sql = 'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`cid`, la.`cpid`, la.`order`, la.`status`, la.`audit_order`, la.`audit_type` ' +
|
|
|
' FROM ?? AS la Left Join ?? AS pa On la.`aid` = pa.`id` ' +
|
|
|
- ' WHERE la.`cid` = ?' + cpidSql + ' and la.`order` = ? and la.`times` = ?';
|
|
|
+ ' WHERE la.`cid` = ?' + cpidSql + csidSql + ' and la.`order` = ? and la.`times` = ?';
|
|
|
sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, cid, cur.order, parseInt(times) - 1];
|
|
|
auditor = await this.db.query(sql, sqlParam);
|
|
|
break;
|
|
|
@@ -295,9 +343,17 @@ module.exports = app => {
|
|
|
return auditor;
|
|
|
}
|
|
|
|
|
|
- async getLastAudit(cid, cpid = null, times, transaction = null) {
|
|
|
- const cpidSql = cpid ? ' AND cpid = ' + cpid : ' AND cpid is null';
|
|
|
- const sql = 'SELECT * FROM ?? WHERE `cid` = ?' + cpidSql + ' AND `times` = ? ORDER BY `order` DESC';
|
|
|
+ async getLastAudit(contract, type, times, transaction = null) {
|
|
|
+ const cid = contract.cid ? contract.cid : contract.id;
|
|
|
+ const cpid = type === 'pay' ? contract.id : null;
|
|
|
+ const csid = type === 'supplement' ? contract.id : null;
|
|
|
+ const cpidSql = type === 'pay'
|
|
|
+ ? ' AND cpid = ' + cpid
|
|
|
+ : ' AND cpid is null';
|
|
|
+ const csidSql = type === 'supplement'
|
|
|
+ ? ' AND csid = ' + csid
|
|
|
+ : ' AND csid is null';
|
|
|
+ const sql = 'SELECT * FROM ?? WHERE `cid` = ?' + cpidSql + csidSql + ' AND `times` = ? ORDER BY `order` DESC';
|
|
|
const sqlParam = [this.tableName, cid, times];
|
|
|
return transaction ? await transaction.queryOne(sql, sqlParam) : await this.db.queryOne(sql, sqlParam);
|
|
|
}
|
|
|
@@ -308,9 +364,9 @@ module.exports = app => {
|
|
|
* @param {Number} times 审核次数
|
|
|
* @return {Promise<Array>} 查询结果集(包括原报)
|
|
|
*/
|
|
|
- async getAuditorsWithOwner(cid, cpid = null, times = 1) {
|
|
|
+ async getAuditorsWithOwner(contract, type, times = 1) {
|
|
|
// const cpidSql = cpid ? ' AND la.cpid = ' + cpid : ' AND la.cpid is null';
|
|
|
- const result = await this.getAuditGroupByList(cid, cpid, times);
|
|
|
+ const result = await this.getAuditGroupByList(contract, type, times);
|
|
|
// const sql =
|
|
|
// 'SELECT pa.`id` As aid, pa.`name`, pa.`company`, pa.`role`, ? As times, ? As cpid, 0 As `order`' +
|
|
|
// ' FROM ' +
|
|
|
@@ -335,20 +391,24 @@ module.exports = app => {
|
|
|
* @param {Number} times - 第几次审批
|
|
|
* @return {Promise<number>}
|
|
|
*/
|
|
|
- async addAuditor(options, cid, cpid = null, auditorId, times = 1, is_gdzs = 0) {
|
|
|
+ async addAuditor(options, contract, type, auditorId, times = 1, is_gdzs = 0) {
|
|
|
+ const cid = contract.cid ? contract.cid : contract.id;
|
|
|
+ const cpid = type === 'pay' ? contract.id : null;
|
|
|
+ const csid = type === 'supplement' ? contract.id : null;
|
|
|
const transaction = await this.db.beginTransaction();
|
|
|
let flag = false;
|
|
|
try {
|
|
|
- let [newOrder, newAuditOrder] = await this.getNewOrder(cid, cpid, times);
|
|
|
+ let [newOrder, newAuditOrder] = await this.getNewOrder(contract, type, times);
|
|
|
// 判断是否存在固定终审,存在则newOrder - 1并使终审order+1
|
|
|
newOrder = is_gdzs === 1 ? newOrder - 1 : newOrder;
|
|
|
newAuditOrder = is_gdzs === 1 ? newAuditOrder - 1 : newAuditOrder;
|
|
|
- if (is_gdzs) await this._syncOrderByDelete(transaction, cid, cpid, newOrder, times, '+');
|
|
|
+ if (is_gdzs) await this._syncOrderByDelete(transaction, contract, type, newOrder, times, '+');
|
|
|
const data = {
|
|
|
spid: options.spid || null,
|
|
|
tid: options.tid || null,
|
|
|
cid,
|
|
|
cpid,
|
|
|
+ csid,
|
|
|
aid: auditorId,
|
|
|
times,
|
|
|
order: newOrder,
|
|
|
@@ -373,9 +433,17 @@ module.exports = app => {
|
|
|
* @param {Number} times - 第几次审批
|
|
|
* @return {Promise<number>}
|
|
|
*/
|
|
|
- async getNewOrder(cid, cpid = null, times = 1) {
|
|
|
- const cpidSql = cpid ? ' AND cpid = ' + cpid : ' AND cpid is null';
|
|
|
- const sql = 'SELECT Max(`order`) As max_order, Max(audit_order) As max_audit_order FROM ?? Where `cid` = ?' + cpidSql + ' and `times` = ?';
|
|
|
+ async getNewOrder(contract, type, times = 1) {
|
|
|
+ const cid = contract.cid ? contract.cid : contract.id;
|
|
|
+ const cpid = type === 'pay' ? contract.id : null;
|
|
|
+ const csid = type === 'supplement' ? contract.id : null;
|
|
|
+ const cpidSql = type === 'pay'
|
|
|
+ ? ' AND cpid = ' + cpid
|
|
|
+ : ' AND cpid is null';
|
|
|
+ const csidSql = type === 'supplement'
|
|
|
+ ? ' AND csid = ' + csid
|
|
|
+ : ' AND csid is null';
|
|
|
+ const sql = 'SELECT Max(`order`) As max_order, Max(audit_order) As max_audit_order FROM ?? Where `cid` = ?' + cpidSql + csidSql + ' and `times` = ?';
|
|
|
const sqlParam = [this.tableName, cid, times];
|
|
|
const result = await this.db.queryOne(sql, sqlParam);
|
|
|
return result && result.max_order ? [result.max_order + 1, result.max_audit_order + 1] : [1, 1];
|
|
|
@@ -389,11 +457,19 @@ module.exports = app => {
|
|
|
* @param {Number} times - 第几次审批
|
|
|
* @return {Promise<boolean>}
|
|
|
*/
|
|
|
- async deleteAuditor(cid, cpid = null, auditorId, times = 1) {
|
|
|
+ async deleteAuditor(contract, type, auditorId, times = 1) {
|
|
|
const transaction = await this.db.beginTransaction();
|
|
|
try {
|
|
|
- const cpidSql = cpid ? ' AND cpid = ' + cpid : ' AND cpid is null';
|
|
|
- const sql = 'SELECT * FROM ?? WHERE `cid` = ?' + cpidSql + ' and `times` = ? and `aid` = ? and `audit_order` != 0 ORDER BY `order` DESC';
|
|
|
+ const cid = contract.cid ? contract.cid : contract.id;
|
|
|
+ const cpid = type === 'pay' ? contract.id : null;
|
|
|
+ const csid = type === 'supplement' ? contract.id : null;
|
|
|
+ const cpidSql = type === 'pay'
|
|
|
+ ? ' AND cpid = ' + cpid
|
|
|
+ : ' AND cpid is null';
|
|
|
+ const csidSql = type === 'supplement'
|
|
|
+ ? ' AND csid = ' + csid
|
|
|
+ : ' AND csid is null';
|
|
|
+ const sql = 'SELECT * FROM ?? WHERE `cid` = ?' + cpidSql + csidSql + ' and `times` = ? and `aid` = ? and `audit_order` != 0 ORDER BY `order` DESC';
|
|
|
const sqlParam = [this.tableName, cid, times, auditorId];
|
|
|
const auditor = await transaction.queryOne(sql, sqlParam);
|
|
|
// const condition = { cid, cpid, aid: auditorId, times };
|
|
|
@@ -401,8 +477,8 @@ module.exports = app => {
|
|
|
if (!auditor) {
|
|
|
throw '该审核人不存在';
|
|
|
}
|
|
|
- await transaction.delete(this.tableName, { cid, cpid, order: auditor.order, times });
|
|
|
- await this._syncOrderByDelete(transaction, cid, cpid, auditor.order, times);
|
|
|
+ await transaction.delete(this.tableName, { cid, cpid, csid, order: auditor.order, times });
|
|
|
+ await this._syncOrderByDelete(transaction, contract, type, auditor.order, times);
|
|
|
await transaction.commit();
|
|
|
} catch (err) {
|
|
|
await transaction.rollback();
|
|
|
@@ -420,31 +496,11 @@ module.exports = app => {
|
|
|
* @return {Promise<*>}
|
|
|
* @private
|
|
|
*/
|
|
|
- async _syncOrderByDelete(transaction, cid, cpid, order, times, selfOperate = '-') {
|
|
|
- // this.initSqlBuilder();
|
|
|
- // this.sqlBuilder.setAndWhere('cid', {
|
|
|
- // value: this.db.escape(cid),
|
|
|
- // operate: '=',
|
|
|
- // });
|
|
|
- // this.sqlBuilder.setAndWhere('order', {
|
|
|
- // value: order,
|
|
|
- // operate: '>=',
|
|
|
- // });
|
|
|
- // this.sqlBuilder.setAndWhere('times', {
|
|
|
- // value: times,
|
|
|
- // operate: '=',
|
|
|
- // });
|
|
|
- // this.sqlBuilder.setUpdateData('order', {
|
|
|
- // value: 1,
|
|
|
- // selfOperate,
|
|
|
- // });
|
|
|
- // this.sqlBuilder.setUpdateData('audit_order', {
|
|
|
- // value: 1,
|
|
|
- // selfOperate,
|
|
|
- // });
|
|
|
- // const [sql, sqlParam] = this.sqlBuilder.build(this.tableName, 'update');
|
|
|
- // const data = await transaction.query(sql, sqlParam);
|
|
|
- const sql = 'UPDATE ?? SET `order` = `order` ' + selfOperate + ' ?, `audit_order` = `audit_order` ' + selfOperate + ' ? WHERE `cid` = ? AND `cpid` ' + (cpid ? '= ' + cpid : 'is null') + ' AND `order` >= ? AND `times` = ?';
|
|
|
+ async _syncOrderByDelete(transaction, contract, type, order, times, selfOperate = '-') {
|
|
|
+ const cid = contract.cid ? contract.cid : contract.id;
|
|
|
+ const cpid = type === 'pay' ? contract.id : null;
|
|
|
+ const csid = type === 'supplement' ? contract.id : null;
|
|
|
+ const sql = 'UPDATE ?? SET `order` = `order` ' + selfOperate + ' ?, `audit_order` = `audit_order` ' + selfOperate + ' ? WHERE `cid` = ? AND `cpid` ' + (cpid ? '= ' + cpid : 'is null') + ' AND `csid` ' + (csid ? '= ' + csid : 'is null') + ' AND `order` >= ? AND `times` = ?';
|
|
|
const sqlParam = [this.tableName, 1, 1, cid, order, times];
|
|
|
const data = await transaction.query(sql, sqlParam);
|
|
|
return data;
|
|
|
@@ -456,8 +512,11 @@ module.exports = app => {
|
|
|
* @param {Number} times - 第几次审批
|
|
|
* @return {Promise<boolean>}
|
|
|
*/
|
|
|
- async start(options, shenpi, cid, cpid = null, times = 1) {
|
|
|
- const audits = await this.getAllDataByCondition({ where: { cid, cpid, times, order: 1 } });
|
|
|
+ async start(options, shenpi, contract, type, times = 1) {
|
|
|
+ const cid = contract.cid ? contract.cid : contract.id;
|
|
|
+ const cpid = type === 'pay' ? contract.id : null;
|
|
|
+ const csid = type === 'supplement' ? contract.id : null;
|
|
|
+ const audits = await this.getAllDataByCondition({ where: { cid, cpid, csid, times, order: 1 } });
|
|
|
if (audits.length === 0) {
|
|
|
if (shenpi.contract === shenpiConst.sp_status.gdspl) {
|
|
|
throw '请联系管理员添加审批人';
|
|
|
@@ -474,6 +533,7 @@ module.exports = app => {
|
|
|
tid: options.tid || null,
|
|
|
cid,
|
|
|
cpid,
|
|
|
+ csid,
|
|
|
aid: this.ctx.session.sessionUser.accountId,
|
|
|
times,
|
|
|
order: 0,
|
|
|
@@ -489,6 +549,10 @@ module.exports = app => {
|
|
|
await transaction.update(this.ctx.service.contractPay.tableName, {
|
|
|
id: cpid, status: auditConst.status.checking,
|
|
|
});
|
|
|
+ } else if (csid) {
|
|
|
+ await transaction.update(this.ctx.service.contractSupplement.tableName, {
|
|
|
+ id: csid, status: auditConst.status.checking,
|
|
|
+ });
|
|
|
} else {
|
|
|
await transaction.update(this.ctx.service.contract.tableName, {
|
|
|
id: cid, status: auditConst.status.checking,
|
|
|
@@ -589,30 +653,34 @@ module.exports = app => {
|
|
|
* @param {Number} times - 第几次审批
|
|
|
* @return {Promise<void>}
|
|
|
*/
|
|
|
- async check(contract, checkData) {
|
|
|
+ async check(contract, type, checkData) {
|
|
|
if (!this._.includes([auditConst.status.checked, auditConst.status.checkNo, auditConst.status.checkNoPre], checkData.checkType)) {
|
|
|
throw '提交数据错误';
|
|
|
}
|
|
|
const pid = this.ctx.session.sessionProject.id;
|
|
|
switch (checkData.checkType) {
|
|
|
case auditConst.status.checked:
|
|
|
- await this._checked(pid, contract, checkData);
|
|
|
+ await this._checked(pid, contract, type, checkData);
|
|
|
break;
|
|
|
case auditConst.status.checkNo:
|
|
|
- await this._checkNo(pid, contract, checkData);
|
|
|
+ await this._checkNo(pid, contract, type, checkData);
|
|
|
break;
|
|
|
case auditConst.status.checkNoPre:
|
|
|
- await this._checkNoPre(pid, contract, checkData);
|
|
|
+ await this._checkNoPre(pid, contract, type, checkData);
|
|
|
break;
|
|
|
default:
|
|
|
throw '无效审批操作';
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- async _checked(pid, contract, checkData) {
|
|
|
+ async _checked(pid, contract, type, checkData) {
|
|
|
const accountId = this.ctx.session.sessionUser.accountId;
|
|
|
const time = new Date();
|
|
|
- const tableName = contract.cid !== undefined ? this.ctx.service.contractPay.tableName : this.ctx.service.contract.tableName;
|
|
|
+ const tableName = {
|
|
|
+ contract: this.ctx.service.contract.tableName,
|
|
|
+ pay: this.ctx.service.contractPay.tableName,
|
|
|
+ supplement: this.ctx.service.contractSupplement.tableName,
|
|
|
+ }[type];
|
|
|
|
|
|
// 整理当前流程审核人状态更新
|
|
|
if (contract.curAuditorIds.length === 0) throw '审核数据错误';
|
|
|
@@ -689,18 +757,25 @@ module.exports = app => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- async _checkNo(pid, contract, checkData) {
|
|
|
+ async _checkNo(pid, contract, type, checkData) {
|
|
|
const accountId = this.ctx.session.sessionUser.accountId;
|
|
|
const time = new Date();
|
|
|
- const tableName = contract.cid !== undefined ? this.ctx.service.contractPay.tableName : this.ctx.service.contract.tableName;
|
|
|
+ const cid = contract.cid ? contract.cid : contract.id;
|
|
|
+ const cpid = type === 'pay' ? contract.id : null;
|
|
|
+ const csid = type === 'supplement' ? contract.id : null;
|
|
|
+ const tableName = {
|
|
|
+ contract: this.ctx.service.contract.tableName,
|
|
|
+ pay: this.ctx.service.contractPay.tableName,
|
|
|
+ supplement: this.ctx.service.contractSupplement.tableName,
|
|
|
+ }[type];
|
|
|
const audits = contract.curAuditors;
|
|
|
if (audits.length === 0) throw '审核数据错误';
|
|
|
const selfAudit = audits.find(x => { return x.aid === accountId; });
|
|
|
if (!selfAudit) throw '当前标段您无权审批';
|
|
|
- const auditors = await this.getUniqAuditor(contract.cid || contract.id, contract.cid ? contract.id : null, contract.times, true); // 全部参与的审批人
|
|
|
+ const auditors = await this.getUniqAuditor(contract, type, contract.times, true); // 全部参与的审批人
|
|
|
const newAuditors = auditors.map(x => {
|
|
|
return {
|
|
|
- aid: x.aid, spid: contract.spid || null, tid: contract.tid || null, cid: contract.cid ? contract.cid : contract.id, cpid: contract.cid ? contract.id : null,
|
|
|
+ aid: x.aid, spid: contract.spid || null, tid: contract.tid || null, cid, cpid, csid,
|
|
|
times: contract.times + 1, order: x.audit_order, status: auditConst.status.uncheck,
|
|
|
audit_type: x.audit_type, audit_order: x.audit_order,
|
|
|
};
|
|
|
@@ -745,10 +820,17 @@ module.exports = app => {
|
|
|
* @param {int} changeData - 变更令的数据
|
|
|
* @return {void}
|
|
|
*/
|
|
|
- async _checkNoPre(pid, contract, checkData) {
|
|
|
+ async _checkNoPre(pid, contract, type, checkData) {
|
|
|
const accountId = this.ctx.session.sessionUser.accountId;
|
|
|
const time = new Date();
|
|
|
- const tableName = contract.cid !== undefined ? this.ctx.service.contractPay.tableName : this.ctx.service.contract.tableName;
|
|
|
+ const cid = contract.cid ? contract.cid : contract.id;
|
|
|
+ const cpid = type === 'pay' ? contract.id : null;
|
|
|
+ const csid = type === 'supplement' ? contract.id : null;
|
|
|
+ const tableName = {
|
|
|
+ contract: this.ctx.service.contract.tableName,
|
|
|
+ pay: this.ctx.service.contractPay.tableName,
|
|
|
+ supplement: this.ctx.service.contractSupplement.tableName,
|
|
|
+ }[type];
|
|
|
// 整理当前流程审核人状态更新
|
|
|
const audits = contract.curAuditors;
|
|
|
if (audits.length === 0 || audits[0].order <= 1) throw '审核数据错误';
|
|
|
@@ -758,7 +840,7 @@ module.exports = app => {
|
|
|
|
|
|
// 添加重新审批后,不能用order-1,取groupby值里的上一个才对
|
|
|
// const preAuditor = await this.getDataByCondition({sid: stageId, times: times, order: audit.order - 1});
|
|
|
- const auditors2 = await this.getAuditGroupByList(contract.cid || contract.id, contract.cid ? contract.id : null, contract.times);
|
|
|
+ const auditors2 = await this.getAuditGroupByList(contract, type, contract.times);
|
|
|
const preAuditors = auditors2.filter(x => { return x.audit_order === selfAudit.audit_order - 1});
|
|
|
|
|
|
const transaction = await this.db.beginTransaction();
|
|
|
@@ -802,13 +884,13 @@ module.exports = app => {
|
|
|
await transaction.updateRows(this.tableName, updateData);
|
|
|
// await this.ctx.service.noticeAgain.stopNoticeAgain(transaction, this.tableName, this._.map(updateData, 'id'));
|
|
|
// 顺移其后审核人流程顺序
|
|
|
- const sql = 'UPDATE ' + this.tableName + ' SET `order` = `order` + 2 WHERE cid = ? AND cpid' + (contract.cid !== undefined ? ' = ' + contract.id : ' is null') + ' AND times = ? AND `order` > ?';
|
|
|
- await transaction.query(sql, [contract.cid ? contract.cid : contract.id, selfAudit.times, selfAudit.order]);
|
|
|
+ const sql = 'UPDATE ' + this.tableName + ' SET `order` = `order` + 2 WHERE cid = ? AND cpid' + (cpid ? ' = ' + cpid : ' is null') + ' AND csid' + (csid ? ' = ' + csid : ' is null') + ' AND times = ? AND `order` > ?';
|
|
|
+ await transaction.query(sql, [cid, selfAudit.times, selfAudit.order]);
|
|
|
// 上一审批人,当前审批人 再次添加至流程
|
|
|
const newAuditors = [];
|
|
|
preAuditors.forEach(x => {
|
|
|
newAuditors.push({
|
|
|
- spid: contract.spid || null, tid: contract.tid || null, cid: contract.cid ? contract.cid : contract.id, cpid: contract.cid ? contract.id : null, aid: x.aid,
|
|
|
+ spid: contract.spid || null, tid: contract.tid || null, cid, cpid, csid, aid: x.aid,
|
|
|
times: x.times, order: selfAudit.order + 1,
|
|
|
status: auditConst.status.checking, begin_time: time,
|
|
|
audit_type: x.audit_type, audit_order: x.audit_order,
|
|
|
@@ -823,7 +905,7 @@ module.exports = app => {
|
|
|
const newFlowAuditors = [];
|
|
|
flowAudits.forEach(x => {
|
|
|
newFlowAuditors.push({
|
|
|
- spid: contract.spid || null, tid: contract.tid || null, cid: contract.cid ? contract.cid : contract.id, cpid: contract.cid ? contract.id : null, aid: x.aid,
|
|
|
+ spid: contract.spid || null, tid: contract.tid || null, cid, cpid, csid, aid: x.aid,
|
|
|
times: x.times, order: selfAudit.order + 2,
|
|
|
status: auditConst.status.uncheck,
|
|
|
audit_type: x.audit_type, audit_order: x.audit_order,
|
|
|
@@ -842,13 +924,13 @@ module.exports = app => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- async getAuditorGroup(cid, cpid, times) {
|
|
|
- const auditors = await this.getAuditors(cid, cpid, times); // 全部参与的审批人
|
|
|
+ async getAuditorGroup(contract, type, times) {
|
|
|
+ const auditors = await this.getAuditors(contract, type, times); // 全部参与的审批人
|
|
|
return this.ctx.helper.groupAuditors(auditors, 'order');
|
|
|
}
|
|
|
|
|
|
- async getUserGroup(cid, cpid, times) {
|
|
|
- const group = await this.getAuditorGroup(cid, cpid, times);
|
|
|
+ async getUserGroup(contract, type, times) {
|
|
|
+ const group = await this.getAuditorGroup(contract, type, times);
|
|
|
// const sql =
|
|
|
// 'SELECT pa.`id` As aid, pa.`name`, pa.`company`, pa.`role`, ? As times, ? As cpid, 0 As `order`, 1 As audit_type, 0 As audit_order' +
|
|
|
// ' FROM ' + this.ctx.service.changePlan.tableName + ' As s' +
|
|
|
@@ -862,8 +944,8 @@ module.exports = app => {
|
|
|
return group;
|
|
|
}
|
|
|
|
|
|
- async getUniqUserGroup(cid, cpid, times) {
|
|
|
- const group = await this.getAuditorGroup(cid, cpid, times);
|
|
|
+ async getUniqUserGroup(contract, type, times) {
|
|
|
+ const group = await this.getAuditorGroup(contract, type, times);
|
|
|
// const sql =
|
|
|
// 'SELECT pa.`id` As aid, pa.`name`, pa.`company`, pa.`role`, ? As times, ? As cpid, 0 As `order`, 1 As audit_type, 0 As audit_order' +
|
|
|
// ' FROM ' + this.ctx.service.changePlan.tableName + ' As s' +
|
|
|
@@ -877,11 +959,11 @@ module.exports = app => {
|
|
|
return this.ctx.helper.groupAuditorsUniq(group);
|
|
|
}
|
|
|
|
|
|
- async getAuditorHistory(cid, cpid, times, reverse = false) {
|
|
|
+ async getAuditorHistory(contract, type, times, reverse = false) {
|
|
|
const history = [];
|
|
|
if (times >= 1) {
|
|
|
for (let i = 1; i <= times; i++) {
|
|
|
- const auditors = await this.getAuditors(cid, cpid, i);
|
|
|
+ const auditors = await this.getAuditors(contract, type, i);
|
|
|
const group = this.ctx.helper.groupAuditors(auditors);
|
|
|
const historyGroup = [];
|
|
|
// 找出group里audit_order最大值
|
|
|
@@ -936,8 +1018,8 @@ module.exports = app => {
|
|
|
return history;
|
|
|
}
|
|
|
|
|
|
- async getUniqAuditor(cid, cpid, times, noYb = false) {
|
|
|
- const auditors = await this.getAuditors(cid, cpid, times, 'asc', noYb); // 全部参与的审批人
|
|
|
+ async getUniqAuditor(contract, type, times, noYb = false) {
|
|
|
+ const auditors = await this.getAuditors(contract, type, times, 'asc', noYb); // 全部参与的审批人
|
|
|
const result = [];
|
|
|
auditors.forEach(x => {
|
|
|
if (result.findIndex(r => { return x.aid === r.aid && x.audit_order === r.audit_order; }) < 0) {
|
|
|
@@ -947,44 +1029,62 @@ module.exports = app => {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- async makeAudits(transaction, options, cid, cpid = null, uid) {
|
|
|
+ async makeAudits(transaction, options, contract, type, uid) {
|
|
|
+ const cid = contract.cid ? contract.cid : contract.id;
|
|
|
+ const cpid = type === 'pay' ? contract.id : null;
|
|
|
+ const csid = type === 'supplement' ? contract.id : null;
|
|
|
// 创建审批人列表
|
|
|
- const lastContractInfo = await this.getHaveAuditLastInfo(options, cid, cpid, uid);
|
|
|
+ const lastContractInfo = await this.getHaveAuditLastInfo(options, contract, type, uid);
|
|
|
+ let auditList = [];
|
|
|
if (lastContractInfo) {
|
|
|
// 再获取非原报审批人
|
|
|
- const auditList = await this.getUniqAuditor(lastContractInfo.cid ? lastContractInfo.cid : lastContractInfo.id, lastContractInfo.cid ? lastContractInfo.id : null, lastContractInfo.times, true); // 全部参与的审批人
|
|
|
- if (auditList.length > 0) {
|
|
|
- const spAudits = [];
|
|
|
- for (const x of auditList) {
|
|
|
- if (x.audit_order !== 0) {
|
|
|
- spAudits.push({
|
|
|
- spid: options.spid || null,
|
|
|
- tid: options.tid || null,
|
|
|
- cid, cpid, aid: x.aid,
|
|
|
- times: 1, order: x.audit_order, status: auditConst.status.uncheck,
|
|
|
- audit_type: x.audit_type, audit_order: x.audit_order,
|
|
|
- });
|
|
|
- }
|
|
|
+ auditList = await this.getUniqAuditor(lastContractInfo, type, lastContractInfo.times, true); // 全部参与的审批人
|
|
|
+ } else if ((type === 'supplement' || type === 'pay') && contract.cid) {
|
|
|
+ // 取该合同的审批人列表
|
|
|
+ const contractInfo = await this.ctx.service.contract.getDataById(contract.cid);
|
|
|
+ auditList = await this.getUniqAuditor(contractInfo, 'contract', contractInfo.times, true); // 全部参与的审批人
|
|
|
+ }
|
|
|
+ if (auditList.length > 0) {
|
|
|
+ const spAudits = [];
|
|
|
+ for (const x of auditList) {
|
|
|
+ if (x.audit_order !== 0) {
|
|
|
+ spAudits.push({
|
|
|
+ spid: options.spid || null,
|
|
|
+ tid: options.tid || null,
|
|
|
+ cid, cpid, csid, aid: x.aid,
|
|
|
+ times: 1, order: x.audit_order, status: auditConst.status.uncheck,
|
|
|
+ audit_type: x.audit_type, audit_order: x.audit_order,
|
|
|
+ });
|
|
|
}
|
|
|
- if (spAudits.length > 0) await transaction.insert(this.ctx.service.contractSpAudit.tableName, spAudits);
|
|
|
}
|
|
|
+ if (spAudits.length > 0) await transaction.insert(this.ctx.service.contractSpAudit.tableName, spAudits);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- async getHaveAuditLastInfo(options, cid, cpid, uid) {
|
|
|
+ async getHaveAuditLastInfo(options, contract, type, uid) {
|
|
|
const optionsSql = options.spid ? 'c.spid = "' + options.spid + '"' : 'c.tid = ' + options.tid;
|
|
|
- const tableName = cpid ? this.ctx.service.contractPay.tableName : this.ctx.service.contract.tableName;
|
|
|
- const joinSql = cpid ? 'ca.cpid' : 'ca.cid';
|
|
|
- const cpidSql = cpid ? 'AND ca.`cpid` is not null' : 'AND ca.`cpid` is null';
|
|
|
- const sql = 'SELECT c.* FROM ?? as c LEFT JOIN ?? as ca ON c.`id` = ' + joinSql + ' WHERE ' + optionsSql + ' AND c.`contract_type` = ? AND c.`uid` = ? ' + cpidSql + ' AND ca.`audit_order` > 0 ORDER BY c.`create_time` DESC';
|
|
|
+ const cpid = type === 'pay' ? contract.id : null;
|
|
|
+ const csid = type === 'supplement' ? contract.id : null;
|
|
|
+ const tableName = {
|
|
|
+ contract: this.ctx.service.contract.tableName,
|
|
|
+ pay: this.ctx.service.contractPay.tableName,
|
|
|
+ supplement: this.ctx.service.contractSupplement.tableName,
|
|
|
+ }[type];
|
|
|
+ const joinSql = cpid ? 'ca.`cpid`' : (csid ? 'ca.`csid`' : 'ca.`cid`');
|
|
|
+ const cpidSql = cpid ? ' AND ca.`cpid` is not null' : ' AND ca.`cpid` is null';
|
|
|
+ const csidSql = cpid ? ' AND ca.`csid` is not null' : ' AND ca.`csid` is null';
|
|
|
+ const sql = 'SELECT c.* FROM ?? as c LEFT JOIN ?? as ca ON c.`id` = ' + joinSql + ' WHERE ' + optionsSql + ' AND c.`contract_type` = ? AND c.`uid` = ?' + cpidSql + csidSql + ' AND ca.`audit_order` > 0 ORDER BY c.`create_time` DESC';
|
|
|
const sqlParam = [tableName, this.tableName, options.contract_type, uid];
|
|
|
return await this.db.queryOne(sql, sqlParam);
|
|
|
}
|
|
|
|
|
|
- async saveAudit(contract, times, sp_group, data) {
|
|
|
+ async saveAudit(contract, type, times, sp_group, data) {
|
|
|
const transaction = await this.db.beginTransaction();
|
|
|
try {
|
|
|
- const auditors = await this.getAuditGroupByList(contract.cid || contract.id, contract.cid ? contract.id : null, times);
|
|
|
+ const cid = contract.cid ? contract.cid : contract.id;
|
|
|
+ const cpid = type === 'pay' ? contract.id : null;
|
|
|
+ const csid = type === 'supplement' ? contract.id : null;
|
|
|
+ const auditors = await this.getAuditGroupByList(contract, type, times);
|
|
|
const now_audit = this._.find(auditors, { aid: data.old_aid });
|
|
|
if (data.operate !== 'del') {
|
|
|
// const exist = await this.getDataByCondition({ cpid: cpId, times, aid: data.new_aid });
|
|
|
@@ -998,13 +1098,13 @@ module.exports = app => {
|
|
|
throw '当前人下无法操作新增';
|
|
|
}
|
|
|
const newAudit = {
|
|
|
- spid: contract.spid || null, tid: contract.tid || null, cid: contract.cid || contract.id, cpid: contract.cid ? contract.id : null, aid: data.new_aid,
|
|
|
+ spid: contract.spid || null, tid: contract.tid || null, cid, cpid, csid, aid: data.new_aid,
|
|
|
order: now_audit.order + 1,
|
|
|
audit_order: now_audit.audit_order + 1, audit_type: auditType.key.common,
|
|
|
times, status: auditConst.status.uncheck,
|
|
|
};
|
|
|
// order+1
|
|
|
- await this._syncOrderByDelete(transaction, contract.cid || contract.id, contract.cid ? contract.id : null, now_audit.order + 1, times, '+');
|
|
|
+ await this._syncOrderByDelete(transaction, contract, type, now_audit.order + 1, times, '+');
|
|
|
await transaction.insert(this.tableName, newAudit);
|
|
|
// 更新审批流程页数据,如果存在
|
|
|
} else if (data.operate === 'add-sibling') {
|
|
|
@@ -1012,7 +1112,7 @@ module.exports = app => {
|
|
|
throw '当前人下无法操作新增';
|
|
|
}
|
|
|
const newAudit = {
|
|
|
- spid: contract.spid || null, tid: contract.tid || null, cid: contract.cid || contract.id, cpid: contract.cid ? contract.id : null, aid: data.new_aid,
|
|
|
+ spid: contract.spid || null, tid: contract.tid || null, cid, cpid, csid, aid: data.new_aid,
|
|
|
order: now_audit.order,
|
|
|
audit_order: now_audit.audit_order, audit_type: now_audit.audit_type,
|
|
|
times, status: auditConst.status.uncheck,
|
|
|
@@ -1023,8 +1123,8 @@ module.exports = app => {
|
|
|
throw '当前人无法操作删除';
|
|
|
}
|
|
|
const flowAuditors = auditors.filter(x => { return x.audit_order === now_audit.audit_order; });
|
|
|
- await transaction.delete(this.tableName, { cid: contract.cid || contract.id, cpid: contract.cid ? contract.id : null, times, aid: now_audit.aid, order: now_audit.order });
|
|
|
- if (flowAuditors.length === 1) await this._syncOrderByDelete(transaction, contract.cid || contract.id, contract.cid ? contract.id : null, now_audit.order, times);
|
|
|
+ await transaction.delete(this.tableName, { cid, cpid, csid, times, aid: now_audit.aid, order: now_audit.order });
|
|
|
+ if (flowAuditors.length === 1) await this._syncOrderByDelete(transaction, contract, type, now_audit.order, times);
|
|
|
// 旧的更新为is_old为1
|
|
|
// await transaction.update(this.tableName, { is_old: 1 }, {
|
|
|
// where: {
|
|
|
@@ -1034,7 +1134,7 @@ module.exports = app => {
|
|
|
// }
|
|
|
// });
|
|
|
} else if (data.operate === 'change') {
|
|
|
- const nowAudit = await this.getDataByCondition({ cid: contract.cid || contract.id, cpid: contract.cid ? contract.id : null, times, aid: now_audit.aid, order: now_audit.order });
|
|
|
+ const nowAudit = await this.getDataByCondition({ cid, cpid, csid, times, aid: now_audit.aid, order: now_audit.order });
|
|
|
if (now_audit.status !== auditConst.status.uncheck || !nowAudit) {
|
|
|
throw '当前人无法操作替换';
|
|
|
}
|
|
|
@@ -1052,24 +1152,24 @@ module.exports = app => {
|
|
|
if (this.ctx.contract_tender) {
|
|
|
const tenderInfo = await this.ctx.service.tenderInfo.getTenderInfo(this.ctx.contract.id);
|
|
|
if (tenderInfo.shenpi.contract === shenpiConst.sp_status.gdspl) {
|
|
|
- const newAuditors = await transaction.select(this.tableName, { where: { cid: contract.cid || contract.id, cpid: contract.cid ? contract.id : null, times }, orders: [['order', 'asc']] });
|
|
|
+ const newAuditors = await transaction.select(this.tableName, { where: { cid, cpid, csid, times }, orders: [['order', 'asc']] });
|
|
|
newAuditors.shift();
|
|
|
const newAuditorGroup = this.ctx.helper.groupAuditors(newAuditors, 'order');
|
|
|
const uniqNewAuditorGroup = this.ctx.helper.groupAuditorsUniq(newAuditorGroup);
|
|
|
await this.ctx.service.shenpiAudit.updateAuditListWithAuditType(transaction, this.ctx.contract.id, tenderInfo.shenpi.contract, shenpiConst.sp_type.contract, uniqNewAuditorGroup, sp_group);
|
|
|
} else if (tenderInfo.shenpi.contract === shenpiConst.sp_status.gdzs) {
|
|
|
- const newAuditors = await this.getAuditGroupByList(contract.cid || contract.id, contract.cid ? contract.id : null, times, transaction);
|
|
|
+ const newAuditors = await this.getAuditGroupByList(contract, type, times, transaction);
|
|
|
await this.ctx.service.shenpiAudit.updateAuditList(transaction, this.ctx.contract.id, tenderInfo.shenpi.contract, shenpiConst.sp_type.contract, this._.map(newAuditors, 'aid'));
|
|
|
}
|
|
|
} else {
|
|
|
if (this.ctx.subProject.shenpi.contract === shenpiConst.sp_status.gdspl) {
|
|
|
- const newAuditors = await transaction.select(this.tableName, { where: { cid: contract.cid || contract.id, cpid: contract.cid ? contract.id : null, times }, orders: [['order', 'asc']] });
|
|
|
+ const newAuditors = await transaction.select(this.tableName, { where: { cid, cpid, csid, times }, orders: [['order', 'asc']] });
|
|
|
newAuditors.shift();
|
|
|
const newAuditorGroup = this.ctx.helper.groupAuditors(newAuditors, 'order');
|
|
|
const uniqNewAuditorGroup = this.ctx.helper.groupAuditorsUniq(newAuditorGroup);
|
|
|
await this.ctx.service.shenpiAudit.updateAuditListWithAuditType(transaction, this.ctx.subProject.id, this.ctx.subProject.shenpi.contract, shenpiConst.sp_type.contract, uniqNewAuditorGroup, sp_group);
|
|
|
} else if (this.ctx.subProject.shenpi.contract === shenpiConst.sp_status.gdzs) {
|
|
|
- const newAuditors = await this.getAuditGroupByList(contract.cid || contract.id, contract.cid ? contract.id : null, times, transaction);
|
|
|
+ const newAuditors = await this.getAuditGroupByList(contract, type, times, transaction);
|
|
|
await this.ctx.service.shenpiAudit.updateAuditList(transaction, this.ctx.subProject.id, this.ctx.subProject.shenpi.contract, shenpiConst.sp_type.contract, this._.map(newAuditors, 'aid'));
|
|
|
}
|
|
|
}
|
|
|
@@ -1081,7 +1181,7 @@ module.exports = app => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- async changeSpGroup(contract, sp_group) {
|
|
|
+ async changeSpGroup(contract, type, sp_group) {
|
|
|
const transaction = await this.db.beginTransaction();
|
|
|
try {
|
|
|
const group = await this.ctx.service.shenpiGroup.getDataById(sp_group);
|
|
|
@@ -1096,11 +1196,13 @@ module.exports = app => {
|
|
|
}
|
|
|
const shenpiList = await this.ctx.service.shenpiAudit.getAllDataByCondition({ where: condition });
|
|
|
// await this.ctx.service.shenpiAudit.noYbShenpiList(change.uid, shenpiList);
|
|
|
- await this.updateNewAuditors(contract, shenpiList, transaction);
|
|
|
- if (contract.cid === undefined) {
|
|
|
+ await this.updateNewAuditors(contract, type, shenpiList, transaction);
|
|
|
+ if (type === 'contract') {
|
|
|
await transaction.update(this.ctx.service.contract.tableName, { id: contract.id, sp_group: group.id });
|
|
|
- } else {
|
|
|
+ } else if (type === 'pay') {
|
|
|
await transaction.update(this.ctx.service.contractPay.tableName, { id: contract.id, sp_group: group.id });
|
|
|
+ } else if (type === 'supplement') {
|
|
|
+ await transaction.update(this.ctx.service.contractSupplement.tableName, { id: contract.id, sp_group: group.id });
|
|
|
}
|
|
|
await transaction.commit();
|
|
|
} catch (err) {
|
|
|
@@ -1110,10 +1212,10 @@ module.exports = app => {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- async updateNewAuditList(contract, newList) {
|
|
|
+ async updateNewAuditList(contract, type, newList) {
|
|
|
const transaction = await this.db.beginTransaction();
|
|
|
try {
|
|
|
- await this.updateNewAuditors(contract, newList, transaction);
|
|
|
+ await this.updateNewAuditors(contract, type, newList, transaction);
|
|
|
await transaction.commit();
|
|
|
} catch (err) {
|
|
|
await transaction.rollback();
|
|
|
@@ -1121,22 +1223,21 @@ module.exports = app => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- async updateNewAuditors(contract, newList, transaction) {
|
|
|
+ async updateNewAuditors(contract, type, newList, transaction) {
|
|
|
const condition = { times: contract.times };
|
|
|
- if (contract.cid !== undefined) {
|
|
|
- condition.cid = contract.cid;
|
|
|
- condition.cpid = contract.id;
|
|
|
- } else {
|
|
|
- condition.cid = contract.id;
|
|
|
- condition.cpid = null;
|
|
|
- }
|
|
|
+ const cid = contract.cid ? contract.cid : contract.id;
|
|
|
+ const cpid = type === 'pay' ? contract.id : null;
|
|
|
+ const csid = type === 'supplement' ? contract.id : null;
|
|
|
+ condition.cid = cid;
|
|
|
+ condition.cpid = cpid;
|
|
|
+ condition.csid = csid;
|
|
|
// 先删除旧的审批流,再添加新的
|
|
|
await transaction.delete(this.tableName, condition);
|
|
|
|
|
|
const newAuditors = [];
|
|
|
for (const auditor of newList) {
|
|
|
newAuditors.push({
|
|
|
- spid: contract.spid || null, tid: contract.tid || null, cid: contract.cid || contract.id, cpid: contract.cid ? contract.id : null, aid: auditor.audit_id,
|
|
|
+ spid: contract.spid || null, tid: contract.tid || null, cid, cpid, csid, aid: auditor.audit_id,
|
|
|
times: contract.times, order: auditor.audit_order, status: auditConst.status.uncheck,
|
|
|
audit_type: auditor.audit_type, audit_order: auditor.audit_order,
|
|
|
});
|
|
|
@@ -1156,21 +1257,20 @@ module.exports = app => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- async updateLastAudit(contract, auditList, lastId) {
|
|
|
+ async updateLastAudit(contract, type, auditList, lastId) {
|
|
|
const transaction = await this.db.beginTransaction();
|
|
|
try {
|
|
|
// 先判断auditList里的aid是否与lastId相同,相同则删除并重新更新order
|
|
|
const existAudit = auditList.find(x => { return x.aid === lastId; });
|
|
|
+ const cid = contract.cid ? contract.cid : contract.id;
|
|
|
+ const cpid = type === 'pay' ? contract.id : null;
|
|
|
+ const csid = type === 'supplement' ? contract.id : null;
|
|
|
let order = auditList.length > 0 ? auditList.reduce((rst, a) => { return Math.max(rst, a.order); }, 0) + 1 : 1; // 最大值 + 1
|
|
|
if (existAudit) {
|
|
|
const condition = { times: contract.times, aid: lastId };
|
|
|
- if (contract.cid !== undefined) {
|
|
|
- condition.cid = contract.cid;
|
|
|
- condition.cpid = contract.id;
|
|
|
- } else {
|
|
|
- condition.cid = contract.id;
|
|
|
- condition.cpid = null;
|
|
|
- }
|
|
|
+ condition.cid = cid;
|
|
|
+ condition.cpid = cpid;
|
|
|
+ condition.csid = csid;
|
|
|
await transaction.delete(this.tableName, condition);
|
|
|
const sameOrder = auditList.filter(x => { return x.order === existAudit.order; });
|
|
|
if (sameOrder.length === 1) {
|
|
|
@@ -1187,7 +1287,7 @@ module.exports = app => {
|
|
|
}
|
|
|
// 添加终审
|
|
|
const newAuditor = {
|
|
|
- spid: contract.spid || null, tid: contract.tid || null, cid: contract.cid || contract.id, cpid: contract.cid ? contract.id : null, aid: lastId,
|
|
|
+ spid: contract.spid || null, tid: contract.tid || null, cid, cpid, csid, aid: lastId,
|
|
|
times: contract.times, order, status: auditConst.status.uncheck,
|
|
|
audit_type: auditType.key.common, audit_order: order,
|
|
|
};
|