|
@@ -8,7 +8,8 @@
|
|
|
* @version
|
|
|
*/
|
|
|
|
|
|
-const auditConst = require('../const/audit').flow;
|
|
|
+const auditConst = require('../const/audit').change;
|
|
|
+const auditType = require('../const/audit').auditType;
|
|
|
const pushType = require('../const/audit').pushType;
|
|
|
const shenpiConst = require('../const/shenpi');
|
|
|
const smsTypeConst = require('../const/sms_type');
|
|
@@ -84,7 +85,7 @@ module.exports = app => {
|
|
|
operate: '=',
|
|
|
});
|
|
|
this.sqlBuilder.setAndWhere('status', {
|
|
|
- value: 6,
|
|
|
+ value: auditConst.status.checkNoPre,
|
|
|
operate: '=',
|
|
|
});
|
|
|
const u_sort = [['usort', 'DESC']];
|
|
@@ -96,53 +97,6 @@ module.exports = app => {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 获取当前审批人查看info时的状态
|
|
|
- * @param {Object} change - 变更令数据
|
|
|
- * @return {void}
|
|
|
- */
|
|
|
- async getStatusByChange(change) {
|
|
|
- const statusConst = auditConst.status;
|
|
|
- const auditStatusConst = auditConst.auditStatus;
|
|
|
- const uid = this.ctx.session.sessionUser.accountId;
|
|
|
- const changeAuditInfo = await this.getAllDataByCondition({ where: { cid: change.cid, times: change.times, uid }, orders: [['usort', 'desc']], limit: 1, offset: 0 });
|
|
|
- if (!change.status === statusConst.checked && (changeAuditInfo === null || changeAuditInfo[0] === undefined) && !ctx.tender.isTourist) {
|
|
|
- // 无权限查看此变更令
|
|
|
- return 0;
|
|
|
- }
|
|
|
-
|
|
|
- if (change.status === statusConst.uncheck && uid === change.uid) {
|
|
|
- // 待上报
|
|
|
- return 1;
|
|
|
- } else if (change.status === statusConst.back && uid === change.uid) {
|
|
|
- // 待重新上报
|
|
|
- return 2;
|
|
|
- } else if (change.status === statusConst.revise && uid === change.uid) {
|
|
|
- // 修订上报
|
|
|
- return 9;
|
|
|
- } else if ((change.status === statusConst.back || change.status === statusConst.revise) && uid !== change.uid) {
|
|
|
- // 被退回或修订中但你不是原报人
|
|
|
- return 3;
|
|
|
- } else if (change.status === statusConst.checked) {
|
|
|
- // 已完成
|
|
|
- return 4;
|
|
|
- } else if (change.status === statusConst.checkNo) {
|
|
|
- // 已终止
|
|
|
- return 5;
|
|
|
- } else if ((change.status === statusConst.checking || change.status === statusConst.backnew) && changeAuditInfo.length > 0 && changeAuditInfo[0].status === auditStatusConst.checking) {
|
|
|
- // 待你审批
|
|
|
- return 6;
|
|
|
- } else if ((change.status === statusConst.checking || change.status === statusConst.backnew) && changeAuditInfo.length > 0 && changeAuditInfo[0].status !== auditStatusConst.checking) {
|
|
|
- // 审批中但你未到你审批或你已审批
|
|
|
- return 7;
|
|
|
- } else if (this.ctx.tender.isTourist) {
|
|
|
- // 游客模式,只预览不能操作
|
|
|
- return 8;
|
|
|
- }
|
|
|
- // 无权限查看此变更令
|
|
|
- return 0;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
* 根据用户查看此变更状态获取审批人列表
|
|
|
* @param {Object} change - 变更令
|
|
|
* @param {int} status - 状态
|
|
@@ -259,43 +213,6 @@ module.exports = app => {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 获取比sort大的审批人列表
|
|
|
- * @param {Object} cid - 变更令id
|
|
|
- * @param {int} usort - 排序
|
|
|
- * @return {object} 返回结果
|
|
|
- */
|
|
|
- async getNextAuditList(cid, usort) {
|
|
|
- const sql = 'SELECT * FROM ?? WHERE ' +
|
|
|
- 'cid = ? AND usort > ?';
|
|
|
- const sqlParam = [this.tableName, cid, usort];
|
|
|
- const list = await this.db.query(sql, sqlParam);
|
|
|
- return list;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取除当前次数的审批人列表
|
|
|
- * @param {Object} cid - 变更令id
|
|
|
- * @param {int} times - 次数
|
|
|
- * @return {object} 返回结果
|
|
|
- */
|
|
|
- async getListByBack(cid, times) {
|
|
|
- this.initSqlBuilder();
|
|
|
- this.sqlBuilder.setAndWhere('cid', {
|
|
|
- value: this.db.escape(cid),
|
|
|
- operate: '=',
|
|
|
- });
|
|
|
- this.sqlBuilder.setAndWhere('times', {
|
|
|
- value: times,
|
|
|
- operate: '!=',
|
|
|
- });
|
|
|
- this.sqlBuilder.orderBy = [['usort', 'ASC']];
|
|
|
- const [sql, sqlParam] = this.sqlBuilder.build(this.tableName);
|
|
|
- const result = await this.db.query(sql, sqlParam);
|
|
|
-
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
* 获取 审核人 待审批的() 变更令列表
|
|
|
* @param uid
|
|
|
* @return {Promise<void>}
|
|
@@ -310,7 +227,7 @@ module.exports = app => {
|
|
|
const sqlParam = [this.tableName, this.ctx.service.change.tableName, this.ctx.service.tender.tableName, uid, 2, auditConst.status.uncheck];
|
|
|
const changes = await this.db.query(sql, sqlParam);
|
|
|
for (const c of changes) {
|
|
|
- if (c.cstatus === auditConst.status.back) {
|
|
|
+ if (c.cstatus === auditConst.status.checkNo) {
|
|
|
const preSql = 'SELECT pa.`id`, pa.`account`, pa.`account_group`, pa.`name`, pa.`company`, pa.`role`, pa.`telephone` FROM ?? As ca, ?? As pa ' +
|
|
|
' WHERE ca.cid = ? and ca.times = ? and ca.status = ? and ca.uid = pa.id';
|
|
|
const preSqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, c.cid, c.times - 1, c.cstatus];
|
|
@@ -332,7 +249,7 @@ module.exports = app => {
|
|
|
* @return {Promise<*>}
|
|
|
*/
|
|
|
async getCountByChecked(auditorId) {
|
|
|
- const sql = 'Select count(*) as count FROM ?? WHERE uid = ? AND usite != 0 AND status in (' + this.ctx.helper.getInArrStrSqlFilter([auditConst.status.checked, auditConst.status.back, auditConst.status.backnew]) +')';
|
|
|
+ const sql = 'Select count(*) as count FROM ?? WHERE uid = ? AND usite != 0 AND status in (' + this.ctx.helper.getInArrStrSqlFilter([auditConst.status.checked, auditConst.status.checkNo, auditConst.status.checkNoPre]) +')';
|
|
|
const sqlParam = [this.tableName, auditorId];
|
|
|
const result = await this.db.queryOne(sql, sqlParam);
|
|
|
return result.count ? result.count : 0;
|
|
@@ -347,7 +264,7 @@ module.exports = app => {
|
|
|
*/
|
|
|
async getLastEndTimeByChecked(auditorId) {
|
|
|
const sql = 'SELECT `sin_time` FROM ?? WHERE `uid` = ? AND usite != 0 ' +
|
|
|
- 'AND `status` in (' + this.ctx.helper.getInArrStrSqlFilter([auditConst.status.checked, auditConst.status.back, auditConst.status.backnew]) + ') ORDER BY `sin_time` DESC';
|
|
|
+ 'AND `status` in (' + this.ctx.helper.getInArrStrSqlFilter([auditConst.status.checked, auditConst.status.checkNo, auditConst.status.checkNoPre]) + ') ORDER BY `sin_time` DESC';
|
|
|
const sqlParam = [this.tableName, auditorId];
|
|
|
const result = await this.db.queryOne(sql, sqlParam);
|
|
|
return result ? result.sin_time : null;
|
|
@@ -409,7 +326,7 @@ module.exports = app => {
|
|
|
' FROM ?? AS ca, ?? AS c, ?? As t, ?? AS ti ' +
|
|
|
' WHERE ca.`uid` = ? and ca.`status` = ? and (c.`status` = ? or c.`status` = ?)' +
|
|
|
' and ca.`cid` = c.`cid` and ca.`tid` = t.`id` and ti.`tid` = t.`id`';
|
|
|
- const sqlParam = [this.tableName, this.ctx.service.change.tableName, this.ctx.service.tender.tableName, this.ctx.service.tenderInfo.tableName, uid, auditConst.auditStatus.checking, auditConst.status.checking, auditConst.status.backnew];
|
|
|
+ const sqlParam = [this.tableName, this.ctx.service.change.tableName, this.ctx.service.tender.tableName, this.ctx.service.tenderInfo.tableName, uid, auditConst.status.checking, auditConst.status.checking, auditConst.status.checkNoPre];
|
|
|
const changes = await this.db.query(sql, sqlParam);
|
|
|
for (const c of changes) {
|
|
|
const preSql = 'SELECT pa.`id`, pa.`account`, pa.`account_group`, pa.`name`, pa.`company`, pa.`role`, pa.`telephone` FROM ?? As ca, ?? As pa ' +
|
|
@@ -420,7 +337,7 @@ module.exports = app => {
|
|
|
return await this.db.query(sql, sqlParam);
|
|
|
}
|
|
|
|
|
|
- async updateNewAuditList(change, newIdList) {
|
|
|
+ async updateNewAuditList(change, newList) {
|
|
|
const transaction = await this.db.beginTransaction();
|
|
|
try {
|
|
|
// 先删除旧的审批流(除了原报),再添加新的
|
|
@@ -429,19 +346,24 @@ module.exports = app => {
|
|
|
await transaction.query(sql, sqlParam);
|
|
|
|
|
|
const newAuditors = [];
|
|
|
- let order = 1;
|
|
|
- let uSort = await transaction.count(this.tableName, { cid: change.cid });
|
|
|
- for (const aid of newIdList) {
|
|
|
- const accountInfo = await this.ctx.service.projectAccount.getDataById(aid);
|
|
|
+ // let uSort = await transaction.count(this.tableName, { cid: change.cid });
|
|
|
+ // let last_order = 0;
|
|
|
+ for (const auditor of newList) {
|
|
|
+ const accountInfo = await this.ctx.service.projectAccount.getDataById(auditor.audit_id);
|
|
|
newAuditors.push({
|
|
|
- tid: change.tid, cid: change.cid, uid: aid,
|
|
|
+ tid: change.tid, cid: change.cid, uid: auditor.audit_id,
|
|
|
name: accountInfo.name, jobs: accountInfo.role, company: accountInfo.company,
|
|
|
- times: change.times, usite: order, usort: uSort, status: auditConst.auditStatus.uncheck,
|
|
|
+ times: change.times, usite: auditor.audit_order, usort: auditor.audit_order, status: auditConst.status.uncheck,
|
|
|
+ audit_type: auditor.audit_type, audit_order: auditor.audit_order,
|
|
|
});
|
|
|
- order++;
|
|
|
- uSort++;
|
|
|
+ // if (auditor.audit_order !== last_order) {
|
|
|
+ // last_order = auditor.audit_order;
|
|
|
+ // uSort++;
|
|
|
+ // }
|
|
|
}
|
|
|
if (newAuditors.length > 0) await transaction.insert(this.tableName, newAuditors);
|
|
|
+ // 同步设置原报为usort为0
|
|
|
+ await transaction.update(this.tableName, { usort: 0 }, { where: { cid: change.cid, times: change.times, usite: 0 } });
|
|
|
await transaction.commit();
|
|
|
} catch (err) {
|
|
|
await transaction.rollback();
|
|
@@ -453,26 +375,42 @@ module.exports = app => {
|
|
|
const transaction = await this.db.beginTransaction();
|
|
|
try {
|
|
|
// 先判断auditList里的aid是否与lastId相同,相同则删除并重新更新order
|
|
|
- const idList = this._.map(auditList, 'uid');
|
|
|
- let order = idList.length + 1;
|
|
|
- if (idList.indexOf(lastId) !== -1) {
|
|
|
- const sql = 'DELETE FROM ?? WHERE `cid`= ? AND `times` = ? AND `uid` = ? AND `usite` != 0';
|
|
|
- const sqlParam = [this.tableName, change.cid, change.times, lastId];
|
|
|
- await transaction.query(sql, sqlParam);
|
|
|
- // await transaction.delete(this.tableName, { cid: change.cid, times: change.times, uid: lastId, usite: 0 });
|
|
|
- const user = this._.find(auditList, { 'uid': lastId });
|
|
|
- // 顺移之后审核人流程顺序
|
|
|
- await this._syncOrderByDelete(transaction, change.cid, user.usite, user.usort, change.times);
|
|
|
- order = order - 1;
|
|
|
+ const existAudit = auditList.find(x => { return x.uid === lastId && x.usite !== 0 });
|
|
|
+ let order = auditList.length > 0 ? auditList.reduce((rst, a) => { return Math.max(rst, a.usort)}, 0) + 1 : 1; // 最大值 + 1
|
|
|
+ let audit_order = auditList.length > 0 ? auditList.reduce((rst, a) => { return Math.max(rst, a.audit_order)}, 0) + 1 : 1; // 最大值 + 1
|
|
|
+ if (existAudit) {
|
|
|
+ await transaction.delete(this.tableName, { cid: change.cid, times: change.times, uid: lastId });
|
|
|
+ const sameOrder = auditList.filter(x => { return x.usort === existAudit.usort });
|
|
|
+ if (sameOrder.length === 1) {
|
|
|
+ const updateData = [];
|
|
|
+ auditList.forEach(x => {
|
|
|
+ if (x.usort <= existAudit.usort) return;
|
|
|
+ updateData.push({id: x.id, usite: x.usite - 1, usort: x.usort - 1, audit_order: x.audit_order - 1});
|
|
|
+ });
|
|
|
+ if (updateData.length > 0) {
|
|
|
+ await transaction.updateRows(updateData);
|
|
|
+ }
|
|
|
+ order = order - 1;
|
|
|
+ audit_order = audit_order - 1;
|
|
|
+ }
|
|
|
+ // const sql = 'DELETE FROM ?? WHERE `cid`= ? AND `times` = ? AND `uid` = ? AND `usite` != 0';
|
|
|
+ // const sqlParam = [this.tableName, change.cid, change.times, lastId];
|
|
|
+ // await transaction.query(sql, sqlParam);
|
|
|
+ // // await transaction.delete(this.tableName, { cid: change.cid, times: change.times, uid: lastId, usite: 0 });
|
|
|
+ // const user = this._.find(auditList, { 'uid': lastId });
|
|
|
+ // // 顺移之后审核人流程顺序
|
|
|
+ // await this._syncOrderByDelete(transaction, change.cid, user.usite, user.usort, change.times);
|
|
|
+ // order = order - 1;
|
|
|
}
|
|
|
|
|
|
// 添加终审
|
|
|
const userInfo = await this.ctx.service.projectAccount.getDataById(lastId);
|
|
|
- let uSort = await transaction.count(this.tableName, { cid: change.cid });
|
|
|
+ // let uSort = await transaction.count(this.tableName, { cid: change.cid });
|
|
|
const newAuditor = {
|
|
|
tid: change.tid, cid: change.cid, uid: lastId,
|
|
|
name: userInfo.name, jobs: userInfo.role, company: userInfo.company,
|
|
|
- times: change.times, usite: order, usort: uSort, status: auditConst.auditStatus.uncheck,
|
|
|
+ times: change.times, usite: audit_order, usort: order, status: auditConst.status.uncheck,
|
|
|
+ audit_type: auditType.key.common, audit_order,
|
|
|
};
|
|
|
await transaction.insert(this.tableName, newAuditor);
|
|
|
await transaction.commit();
|
|
@@ -513,6 +451,10 @@ module.exports = app => {
|
|
|
value: 1,
|
|
|
selfOperate: selfOperate,
|
|
|
});
|
|
|
+ this.sqlBuilder.setUpdateData('audit_order', {
|
|
|
+ value: 1,
|
|
|
+ selfOperate: selfOperate,
|
|
|
+ });
|
|
|
const [sql, sqlParam] = this.sqlBuilder.build(this.tableName, 'update');
|
|
|
const data = await transaction.query(sql, sqlParam);
|
|
|
|
|
@@ -533,6 +475,19 @@ module.exports = app => {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 获取 当前审核组
|
|
|
+ *
|
|
|
+ * @param {Number} cid - 期id
|
|
|
+ * @param {Number} times - 第几次审批
|
|
|
+ * @return {Promise<*>}
|
|
|
+ */
|
|
|
+ async getCurAuditors(cid, times = 1) {
|
|
|
+ const sql = 'SELECT * FROM ?? WHERE `cid` = ? and `status` = ? and `times` = ? and usite != 0';
|
|
|
+ const sqlParam = [this.tableName, cid, auditConst.status.checking, times];
|
|
|
+ return await this.db.query(sql, sqlParam);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 获取 审核人列表(除去原报)
|
|
|
*
|
|
|
* @param {Number} cid - 变更id
|
|
@@ -548,6 +503,154 @@ module.exports = app => {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * new* 获取 审核列表信息(除去原报)
|
|
|
+ *
|
|
|
+ * @param {Number} stageId - 期id
|
|
|
+ * @param {Number} times - 第几次审批
|
|
|
+ * @param {Number} order_sort - 列表排序方式
|
|
|
+ * @return {Promise<*>}
|
|
|
+ */
|
|
|
+ async getAuditorsNew(cid, times = 1, order_sort = 'asc') {
|
|
|
+ const sql = 'SELECT la.id, la.uid, la.times, la.usite, la.usort, la.status, la.sdesc, la.begin_time, la.end_time, la.sin_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.uid = pa.id` +
|
|
|
+ ' WHERE la.cid = ? AND la.times = ?' +
|
|
|
+ ' ORDER BY la.usort ' + order_sort;
|
|
|
+ const sqlParam = [cid, times];
|
|
|
+ const result = await this.db.query(sql, sqlParam);
|
|
|
+ const max_sort = this._.max(result.map(x => { return x.audit_order; }));
|
|
|
+ for (const i in result) {
|
|
|
+ result[i].max_sort = max_sort;
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ async getAuditorGroup(cid, times) {
|
|
|
+ const auditors = await this.getAuditorsNew(cid, times); // 全部参与的审批人
|
|
|
+ return this.ctx.helper.groupAuditors(auditors, 'usort');
|
|
|
+ }
|
|
|
+
|
|
|
+ async getUserGroup(cid, times) {
|
|
|
+ const group = await this.getAuditorGroup(cid, times);
|
|
|
+ // const sql =
|
|
|
+ // 'SELECT pa.`id` As aid, pa.`name`, pa.`company`, pa.`role`, ? As times, ? As sid, 0 As `order`, 1 As audit_type, 0 As audit_order' +
|
|
|
+ // ' FROM ' + this.ctx.service.change.tableName + ' As s' +
|
|
|
+ // ' LEFT JOIN ' + this.ctx.service.projectAccount.tableName + ' As pa' +
|
|
|
+ // ' ON s.user_id = pa.id' +
|
|
|
+ // ' WHERE s.id = ?';
|
|
|
+ // const sqlParam = [times, stageId, stageId];
|
|
|
+ // const user = await this.db.queryOne(sql, sqlParam);
|
|
|
+ // group.unshift([ user ]);
|
|
|
+ return group;
|
|
|
+ }
|
|
|
+
|
|
|
+ async getUniqUserGroup(cid, times) {
|
|
|
+ const group = await this.getAuditorGroup(cid, times);
|
|
|
+ // const sql =
|
|
|
+ // 'SELECT pa.`id` As aid, pa.`name`, pa.`company`, pa.`role`, ? As times, ? As sid, 0 As `order`, 1 As audit_type, 0 As audit_order' +
|
|
|
+ // ' FROM ' + this.ctx.service.stage.tableName + ' As s' +
|
|
|
+ // ' LEFT JOIN ' + this.ctx.service.projectAccount.tableName + ' As pa' +
|
|
|
+ // ' ON s.user_id = pa.id' +
|
|
|
+ // ' WHERE s.id = ?';
|
|
|
+ // const sqlParam = [times, stageId, stageId];
|
|
|
+ // const user = await this.db.queryOne(sql, sqlParam);
|
|
|
+ // user.audit_order = 0;
|
|
|
+ // group.unshift([ user ]);
|
|
|
+ return this.ctx.helper.groupAuditorsUniq(group);
|
|
|
+ }
|
|
|
+
|
|
|
+ async getUniqAuditor(cid, times) {
|
|
|
+ const auditors = await this.getAuditorsNew(cid, times); // 全部参与的审批人
|
|
|
+ const result = [];
|
|
|
+ auditors.forEach(x => {
|
|
|
+ if (result.findIndex(r => { return x.uid === r.uid && x.audit_order === x.audit_order; }) < 0) {
|
|
|
+ result.push(x);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ async getAuditorHistory(cid, times, reverse = false) {
|
|
|
+ const history = [];
|
|
|
+ if (times >= 1) {
|
|
|
+ for (let i = 1; i <= times; i++) {
|
|
|
+ const auditors = await this.getAuditorsNew(cid, i);
|
|
|
+ const group = this.ctx.helper.groupAuditors(auditors, 'usort');
|
|
|
+ const historyGroup = [];
|
|
|
+ // 找出group里audit_order最大值
|
|
|
+ const max_info = group.length > 0 ? this._.maxBy(group, function (item) {
|
|
|
+ return item && item[0] && item[0].audit_order;
|
|
|
+ }) : null;
|
|
|
+ const max_order = max_info ? max_info[0].audit_order : -1;
|
|
|
+ for (const g of group) {
|
|
|
+ const his = {
|
|
|
+ beginYear: '', beginDate: '', beginTime: '', endYear: '', endDate: '', endTime: '', begin_time: null, end_time: null,
|
|
|
+ audit_type: g[0].audit_type, audit_order: g[0].audit_order,
|
|
|
+ auditors: g
|
|
|
+ };
|
|
|
+ if (his.audit_type === auditType.key.common) {
|
|
|
+ his.name = g[0].name;
|
|
|
+ } else {
|
|
|
+ his.name = this.ctx.helper.transFormToChinese(his.audit_order) + '审';
|
|
|
+ }
|
|
|
+ his.is_final = his.audit_order === max_order;
|
|
|
+ if (g[0].begin_time) {
|
|
|
+ his.begin_time = g[0].begin_time;
|
|
|
+ const beginTime = this.ctx.moment(g[0].begin_time);
|
|
|
+ his.beginYear = beginTime.format('YYYY');
|
|
|
+ his.beginDate = beginTime.format('MM-DD');
|
|
|
+ his.beginTime = beginTime.format('HH:mm:ss');
|
|
|
+ }
|
|
|
+ let end_time;
|
|
|
+ g.forEach(x => {
|
|
|
+ if (x.status === auditConst.status.checkSkip) return;
|
|
|
+ if (!his.status || x.status === auditConst.status.checking) his.status = x.status;
|
|
|
+ if (x.end_time && (!end_time || x.end_time > end_time)) {
|
|
|
+ end_time = x.end_time;
|
|
|
+ if (his.status !== auditConst.status.checking) his.status = x.status;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (end_time) {
|
|
|
+ his.end_time = end_time;
|
|
|
+ const endTime = this.ctx.moment(end_time);
|
|
|
+ his.endYear = endTime.format('YYYY');
|
|
|
+ his.endDate = endTime.format('MM-DD');
|
|
|
+ his.endTime = endTime.format('HH:mm:ss');
|
|
|
+ }
|
|
|
+ historyGroup.push(his);
|
|
|
+ }
|
|
|
+ if (reverse) {
|
|
|
+ history.push(historyGroup.reverse());
|
|
|
+ } else {
|
|
|
+ history.push(historyGroup);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return history;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取审核人流程列表(除去原报)
|
|
|
+ *
|
|
|
+ * @param auditorId
|
|
|
+ * @return {Promise<*>}
|
|
|
+ */
|
|
|
+ async getAuditGroupByList(cid, 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 sql =
|
|
|
+ 'SELECT la.`uid`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`cid`, la.`usite`, la.`usort`, la.`status`, la.audit_type, la.audit_order' +
|
|
|
+ ' FROM (SELECT `uid`, max(`usort`) `usort` FROM ?? WHERE `cid` = ? and `times` = ? and `usite` != 0 GROUP BY uid) sa' +
|
|
|
+ ' LEFT JOIN ?? la ON sa.`uid` = la.`uid` AND sa.`usort` = la.`usort`' +
|
|
|
+ ' Left JOIN ?? AS pa On la.`uid` = pa.`id` WHERE la.`cid` = ? and la.`times` = ? and la.`usite` != 0 order BY la.`usort`';
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 新增审核人
|
|
|
*
|
|
|
* @param {Number} cid - 变更令id
|
|
@@ -558,17 +661,19 @@ module.exports = app => {
|
|
|
async addAuditor(cid, auditorId, times = 1, is_gdzs = 0) {
|
|
|
const transaction = await this.db.beginTransaction();
|
|
|
try {
|
|
|
- let newOrder = await transaction.count(this.tableName, { cid, times });
|
|
|
- let uSort = await transaction.count(this.tableName, { cid });
|
|
|
+ let [uSort, newAuditOrder] = await this.getNewOrder(cid, times);
|
|
|
+ // let newOrder = await transaction.count(this.tableName, { cid, times });
|
|
|
+ // let uSort = await transaction.count(this.tableName, { cid });
|
|
|
// 判断是否存在固定终审,存在则newOrder - 1并使终审order+1
|
|
|
- newOrder = is_gdzs === 1 ? newOrder - 1 : newOrder;
|
|
|
uSort = is_gdzs === 1 ? uSort - 1 : uSort;
|
|
|
- if (is_gdzs) await this._syncOrderByDelete(transaction, cid, newOrder, uSort, times, '+');
|
|
|
+ newAuditOrder = is_gdzs === 1 ? newAuditOrder - 1 : newAuditOrder;
|
|
|
+ if (is_gdzs) await this._syncOrderByDelete(transaction, cid, newAuditOrder, uSort, times, '+');
|
|
|
const userInfo = await this.ctx.service.projectAccount.getDataById(auditorId);
|
|
|
const newAuditor = {
|
|
|
tid: this.ctx.tender.id, cid: cid, uid: auditorId,
|
|
|
name: userInfo.name, jobs: userInfo.role, company: userInfo.company,
|
|
|
- times: times, usite: newOrder, usort: uSort, status: auditConst.auditStatus.uncheck,
|
|
|
+ times: times, usite: newAuditOrder, usort: uSort, status: auditConst.status.uncheck,
|
|
|
+ audit_order: newAuditOrder,
|
|
|
};
|
|
|
const result = await transaction.insert(this.tableName, newAuditor);
|
|
|
await transaction.commit();
|
|
@@ -581,6 +686,20 @@ module.exports = app => {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 获取 最新审核顺序
|
|
|
+ *
|
|
|
+ * @param {Number} cid - 变更id
|
|
|
+ * @param {Number} times - 第几次审批
|
|
|
+ * @return {Promise<number>}
|
|
|
+ */
|
|
|
+ async getNewOrder(cid, times = 1) {
|
|
|
+ const sql = 'SELECT Max(`usort`) As max_order, Max(audit_order) As max_audit_order FROM ' + this.tableName + ' Where `cid` = ? and `times` = ?';
|
|
|
+ const sqlParam = [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];
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 移除审核人
|
|
|
*
|
|
|
* @param {Number} cid - 变更令id
|
|
@@ -597,8 +716,9 @@ module.exports = app => {
|
|
|
if (!auditor) {
|
|
|
throw '该审核人不存在';
|
|
|
}
|
|
|
+ // 移除整个流程的人
|
|
|
+ await transaction.delete(this.tableName, { cid, times, usite: auditor.usite });
|
|
|
await this._syncOrderByDelete(transaction, cid, auditor.usite, auditor.usort, times);
|
|
|
- await transaction.delete(this.tableName, { id: auditor.id });
|
|
|
await transaction.commit();
|
|
|
} catch (err) {
|
|
|
await transaction.rollback();
|
|
@@ -614,9 +734,9 @@ module.exports = app => {
|
|
|
* @return {Promise<boolean>}
|
|
|
*/
|
|
|
async start(cid, times = 1) {
|
|
|
- const audit = await this.getDataByCondition({ cid, times, usite: 1 });
|
|
|
+ const audits = await this.getAllDataByCondition({ where: { cid, times, usite: 1 } });
|
|
|
const yBAudit = await this.getDataByCondition({ cid, times, usite: 0 });
|
|
|
- if (!audit) {
|
|
|
+ if (audits.length === 0) {
|
|
|
if(this.ctx.tender.info.shenpi.change === shenpiConst.sp_status.gdspl) {
|
|
|
throw '请联系管理员添加审批人';
|
|
|
} else {
|
|
@@ -626,12 +746,15 @@ module.exports = app => {
|
|
|
|
|
|
const transaction = await this.db.beginTransaction();
|
|
|
try {
|
|
|
- await transaction.update(this.tableName, { id: audit.id, status: auditConst.auditStatus.checking, sin_time: new Date() });
|
|
|
+ const begin_time = new Date();
|
|
|
+ const updateUserData = audits.map(x => { return { id: x.id, status: auditConst.status.checking, begin_time, sin_time: begin_time } });
|
|
|
+ await transaction.updateRows(this.tableName, updateUserData);
|
|
|
// 更新原报人审批状态
|
|
|
await transaction.update(this.tableName, {
|
|
|
id: yBAudit.id,
|
|
|
- status: auditConst.auditStatus.checked,
|
|
|
- sin_time: new Date(),
|
|
|
+ status: auditConst.status.checked,
|
|
|
+ sin_time: begin_time,
|
|
|
+ end_time: begin_time,
|
|
|
});
|
|
|
const changeList = await this.ctx.service.changeAuditList.getList(cid);
|
|
|
let total_price = 0;
|
|
@@ -668,7 +791,7 @@ module.exports = app => {
|
|
|
const shenpiUrl = await this.ctx.helper.urlToShort(
|
|
|
this.ctx.protocol + '://' + this.ctx.host + '/wap/tender/' + this.ctx.change.tid + '/change/' + cid + '/information#shenpi'
|
|
|
);
|
|
|
- await this.ctx.helper.sendAliSms(audit.uid, smsTypeConst.const.BG, smsTypeConst.judge.approval.toString(), SmsAliConst.template.change_check, {
|
|
|
+ await this.ctx.helper.sendAliSms(this._.map(audits, 'uid'), smsTypeConst.const.BG, smsTypeConst.judge.approval.toString(), SmsAliConst.template.change_check, {
|
|
|
biangeng: code,
|
|
|
code: shenpiUrl,
|
|
|
});
|
|
@@ -680,18 +803,20 @@ module.exports = app => {
|
|
|
code: this.ctx.session.sessionProject.code,
|
|
|
c_name: this.ctx.change.name,
|
|
|
};
|
|
|
- await this.ctx.helper.sendWechat(audit.uid, smsTypeConst.const.BG, smsTypeConst.judge.approval.toString(), wxConst.template.change, wechatData);
|
|
|
+ await this.ctx.helper.sendWechat(this._.map(audits, 'uid'), smsTypeConst.const.BG, smsTypeConst.judge.approval.toString(), wxConst.template.change, wechatData);
|
|
|
// 重新发送配置
|
|
|
- await this.ctx.service.noticeAgain.addNoticeAgain(transaction, smsTypeConst.const.BG, {
|
|
|
- pid: this.ctx.session.sessionProject.id,
|
|
|
- tid: this.ctx.change.tid,
|
|
|
- uid: audit.uid,
|
|
|
- sp_type: 'change',
|
|
|
- sp_id: audit.id,
|
|
|
- table_name: this.tableName,
|
|
|
- template: wxConst.template.change,
|
|
|
- wx_data: wechatData,
|
|
|
- });
|
|
|
+ for (const audit of audits) {
|
|
|
+ await this.ctx.service.noticeAgain.addNoticeAgain(transaction, smsTypeConst.const.BG, {
|
|
|
+ pid: this.ctx.session.sessionProject.id,
|
|
|
+ tid: this.ctx.change.tid,
|
|
|
+ uid: audit.uid,
|
|
|
+ sp_type: 'change',
|
|
|
+ sp_id: audit.id,
|
|
|
+ table_name: this.tableName,
|
|
|
+ template: wxConst.template.change,
|
|
|
+ wx_data: wechatData,
|
|
|
+ });
|
|
|
+ }
|
|
|
await transaction.delete(this.ctx.service.changeHistory.tableName, { cid });
|
|
|
await transaction.commit();
|
|
|
} catch (err) {
|
|
@@ -704,7 +829,7 @@ module.exports = app => {
|
|
|
async getNumByMonth(tid, startMonth, endMonth) {
|
|
|
const sql = 'SELECT COUNT(*) as num FROM ?? t1 JOIN (SELECT MAX(id) as max_id FROM ?? WHERE tid = ? AND usite != 0 GROUP BY id ORDER BY usort DESC) t2 ON t1.id = t2.max_id WHERE t1.status = ? AND t1.sin_time between ? and ?';
|
|
|
// const sql = 'SELECT COUNT(*) as num FROM ?? WHERE id in (SELECT b.id FROM (SELECT * FROM ?? WHERE tid = ? AND usite != 0 GROUP BY id ORDER BY usort DESC) as b GROUP BY b.cid) AND status = ? AND sin_time between ? and ?';
|
|
|
- const sqlParam = [this.tableName, this.tableName, tid, auditConst.auditStatus.checked, startMonth, endMonth];
|
|
|
+ const sqlParam = [this.tableName, this.tableName, tid, auditConst.status.checked, startMonth, endMonth];
|
|
|
const result = await this.db.queryOne(sql, sqlParam);
|
|
|
return result ? result.num : 0;
|
|
|
}
|
|
@@ -722,12 +847,17 @@ module.exports = app => {
|
|
|
// 2.审批人撤回审批通过,增加流程,并回到它审批中
|
|
|
// 3.审批人撤回审批退回上一人,并删除退回人,增加流程,并回到它审批中,并更新计量期状态为审批中
|
|
|
// 4.审批人撤回退回原报操作,删除新增的审批流,增加流程,回滚到它审批中
|
|
|
- switch (change.cancancel) {
|
|
|
- case 1: await this._userCheckCancel(change); break;
|
|
|
- case 2: await this._auditCheckCancel(change); break;
|
|
|
- case 3: await this._auditCheckCancelNoPre(change); break;
|
|
|
- case 4: await this._auditCheckCancelNo(change); break;
|
|
|
- default: throw '不可撤回,请刷新页面重试';
|
|
|
+ // 5.会签审批人撤回审批通过(还有其他审批人未审批通过),仅修改本人流程状态
|
|
|
+ if (change.cancancel === 5) {
|
|
|
+ await this._auditCheckCancelAnd(change);
|
|
|
+ } else {
|
|
|
+ switch (change.cancancel) {
|
|
|
+ case 1: await this._userCheckCancel(change); break;
|
|
|
+ case 2: await this._auditCheckCancel(change); break;
|
|
|
+ case 3: await this._auditCheckCancelNoPre(change); break;
|
|
|
+ case 4: await this._auditCheckCancelNo(change); break;
|
|
|
+ default: throw '不可撤回,请刷新页面重试';
|
|
|
+ }
|
|
|
}
|
|
|
// if (stage.cancancel === 5) {
|
|
|
// await this._auditCheckCancelAnd(stage);
|
|
@@ -768,20 +898,24 @@ module.exports = app => {
|
|
|
const transaction = await this.db.beginTransaction();
|
|
|
try {
|
|
|
// 整理当前流程审核人状态更新
|
|
|
- const curAudit = await this.getDataByCondition({ cid: change.cid, times: change.times, status: auditConst.auditStatus.checking });
|
|
|
- // // 审批人变成待审批状态
|
|
|
- await transaction.update(this.tableName, {
|
|
|
- id: curAudit.id,
|
|
|
- status: auditConst.auditStatus.uncheck,
|
|
|
- sin_time: null,
|
|
|
- sdesc: null,
|
|
|
+ // 审批人变成待审批状态
|
|
|
+ const updateData = change.curAuditors.map(x => {
|
|
|
+ return {
|
|
|
+ id: x.id,
|
|
|
+ status: auditConst.status.uncheck,
|
|
|
+ begin_time: null,
|
|
|
+ sin_time: null,
|
|
|
+ sdesc: '',
|
|
|
+ }
|
|
|
});
|
|
|
- await this.ctx.service.noticeAgain.deleteNoticeAgain(transaction, this.tableName, curAudit.id);
|
|
|
+ await transaction.updateRows(this.tableName, updateData);
|
|
|
+ await this.ctx.service.noticeAgain.deleteNoticeAgain(transaction, this.tableName, this._.map(updateData, 'id'));
|
|
|
// 原报变成checking状态
|
|
|
- const ybAudit = await this.getDataByCondition({ cid: change.cid, times: change.times, usite: 0, status: auditConst.auditStatus.checked });
|
|
|
+ const ybAudit = await this.getDataByCondition({ cid: change.cid, times: change.times, usite: 0, status: auditConst.status.checked });
|
|
|
await transaction.update(this.tableName, {
|
|
|
id: ybAudit.id,
|
|
|
- status: auditConst.auditStatus.checking,
|
|
|
+ status: auditConst.status.checking,
|
|
|
+ end_time: null,
|
|
|
sin_time: new Date(),
|
|
|
});
|
|
|
// 变更令变成待上报状态
|
|
@@ -791,7 +925,7 @@ module.exports = app => {
|
|
|
},
|
|
|
};
|
|
|
await transaction.update(this.ctx.service.change.tableName, {
|
|
|
- status: change.times === 1 ? auditConst.status.uncheck : auditConst.status.back,
|
|
|
+ status: change.times === 1 ? auditConst.status.uncheck : auditConst.status.checkNo,
|
|
|
}, options);
|
|
|
await transaction.commit();
|
|
|
} catch(err) {
|
|
@@ -815,57 +949,50 @@ module.exports = app => {
|
|
|
* @private
|
|
|
*/
|
|
|
async _auditCheckCancel(change) {
|
|
|
+ if (change.curAuditors.length === 0 || change.curAuditors[0].usort <= 1) {
|
|
|
+ throw '撤回用户数据错误';
|
|
|
+ }
|
|
|
+ const accountId = this.ctx.session.sessionUser.accountId;
|
|
|
const time = new Date();
|
|
|
|
|
|
const transaction = await this.db.beginTransaction();
|
|
|
try {
|
|
|
- // 整理当前流程审核人状态更新
|
|
|
- const curAudit = await this.getDataByCondition({ cid: change.cid, times: change.times, status: auditConst.status.checking });
|
|
|
- const preAudit = change.preAudit;
|
|
|
- if (!curAudit || curAudit.usite <= 1 || !preAudit) {
|
|
|
- throw '撤回用户数据错误';
|
|
|
- }
|
|
|
+ const selfAuditor = change.preAuditors.find(x => { return x.uid === accountId; });
|
|
|
+ if (!selfAuditor) throw '撤回用户数据错误';
|
|
|
// 顺移其后审核人流程顺序
|
|
|
const sql = 'UPDATE ' + this.tableName + ' SET `usort` = `usort` + 2 WHERE cid = ? AND times = ? AND `usort` > ?';
|
|
|
- await transaction.query(sql, [change.cid, change.times, curAudit.usort]);
|
|
|
+ await transaction.query(sql, [change.cid, change.times, change.curAuditors[0].usort]);
|
|
|
// 当前审批人2次添加至流程中
|
|
|
- const newAuditors = [];
|
|
|
- // 先入撤回记录
|
|
|
- newAuditors.push({
|
|
|
- tid: change.tid,
|
|
|
- cid: change.cid,
|
|
|
- uid: preAudit.uid,
|
|
|
- name: preAudit.name,
|
|
|
- jobs: preAudit.jobs,
|
|
|
- company: preAudit.company,
|
|
|
- times: change.times,
|
|
|
- usite: preAudit.usite,
|
|
|
- usort: curAudit.usort,
|
|
|
- status: auditConst.auditStatus.checkCancel,
|
|
|
- sin_time: time,
|
|
|
- sdesc: '',
|
|
|
+ const checkCancelAuditors = [], checkingAuditors = [];
|
|
|
+ change.preAuditors.forEach(x => {
|
|
|
+ checkCancelAuditors.push({
|
|
|
+ tid: change.tid, cid: change.cid, uid: x.uid,
|
|
|
+ times: x.times, usite: x.usite, usort: x.usort + 1,
|
|
|
+ status: x.uid === selfAuditor.uid ? auditConst.status.checkCancel : auditConst.status.checkSkip,
|
|
|
+ begin_time: time, end_time: time, sin_time: time, sdesc: '',
|
|
|
+ name: x.name, jobs: x.role || x.jobs, company: x.company,
|
|
|
+ audit_type: x.audit_type, audit_order: x.audit_order,
|
|
|
+ });
|
|
|
});
|
|
|
- newAuditors.push({
|
|
|
- tid: change.tid,
|
|
|
- cid: change.cid,
|
|
|
- uid: preAudit.uid,
|
|
|
- name: preAudit.name,
|
|
|
- jobs: preAudit.jobs,
|
|
|
- company: preAudit.company,
|
|
|
- times: change.times,
|
|
|
- usite: preAudit.usite,
|
|
|
- usort: curAudit.usort + 1,
|
|
|
- status: auditConst.auditStatus.checking,
|
|
|
- sin_time: time,
|
|
|
+ change.preAuditors.forEach(x => {
|
|
|
+ checkingAuditors.push({
|
|
|
+ tid: change.tid, cid: change.cid, uid: x.uid,
|
|
|
+ times: x.times, usite: x.usite, usort: x.usort + 2,
|
|
|
+ status: auditConst.status.checking,
|
|
|
+ begin_time: time, sin_time: time, sdesc: '',
|
|
|
+ name: x.name, jobs: x.role || x.jobs, company: x.company,
|
|
|
+ audit_type: x.audit_type, audit_order: x.audit_order,
|
|
|
+ });
|
|
|
});
|
|
|
- await transaction.insert(this.tableName, newAuditors);
|
|
|
+ await transaction.insert(this.tableName, [...checkCancelAuditors, ...checkingAuditors]);
|
|
|
+ const newAuditors = [];
|
|
|
// 当前审批人变成待审批
|
|
|
- await transaction.update(this.tableName, { id: curAudit.id, usort: curAudit.usort + 2, sin_time: null, status: auditConst.auditStatus.uncheck });
|
|
|
- await this.ctx.service.noticeAgain.deleteNoticeAgain(transaction, this.tableName, curAudit.id);
|
|
|
+ await transaction.updateRows(this.tableName, change.curAuditors.map(x => { return {
|
|
|
+ id: x.id, begin_time: null, sin_time: null, status: auditConst.status.uncheck, usort: x.usort + 2
|
|
|
+ }}));
|
|
|
+ await this.ctx.service.noticeAgain.deleteNoticeAgain(transaction, this.tableName, this._.map(change.curAuditors, 'id'));
|
|
|
// 审批列表数据也要回退
|
|
|
- const changeList = await this.ctx.service.changeAuditList.getAllDataByCondition({
|
|
|
- where: { cid: change.cid },
|
|
|
- });
|
|
|
+ const changeList = await this.ctx.service.changeAuditList.getList(change.cid);
|
|
|
let total_price = 0;
|
|
|
const tp_decimal = change.tp_decimal ? change.tp_decimal : this.ctx.tender.info.decimal.tp;
|
|
|
const updateList = [];
|
|
@@ -915,50 +1042,44 @@ module.exports = app => {
|
|
|
* @private
|
|
|
*/
|
|
|
async _auditCheckCancelNoPre(change) {
|
|
|
+ if (change.curAuditors.length === 0 || change.curAuditors[0].usort <= 1) {
|
|
|
+ throw '撤回用户数据错误';
|
|
|
+ }
|
|
|
+ const accountId = this.ctx.session.sessionUser.accountId;
|
|
|
const time = new Date();
|
|
|
|
|
|
const transaction = await this.db.beginTransaction();
|
|
|
try {
|
|
|
- const curAudit = await this.getDataByCondition({ cid: change.cid, times: change.times, status: auditConst.status.checking });
|
|
|
- const preAudit = change.preAudit;
|
|
|
- if (!curAudit || curAudit.order <= 1 || !preAudit) {
|
|
|
- throw '撤回用户数据错误';
|
|
|
- }
|
|
|
+ const selfAuditor = change.preAuditors.find(x => { return x.uid === accountId; });
|
|
|
+ if (!selfAuditor) throw '撤回用户数据错误';
|
|
|
// 整理当前流程审核人状态更新
|
|
|
// 删除当前审批人
|
|
|
- await transaction.delete(this.tableName, { id: curAudit.id });
|
|
|
- await this.ctx.service.noticeAgain.deleteNoticeAgain(transaction, this.tableName, curAudit.id);
|
|
|
+ await transaction.delete(this.tableName, { id: change.curAuditors.map(x => { return x.id; }) });
|
|
|
+ await this.ctx.service.noticeAgain.deleteNoticeAgain(transaction, this.tableName, this._.map(change.curAuditors, 'id'));
|
|
|
// 添加撤回人到审批流程中
|
|
|
const newAuditors = [];
|
|
|
- newAuditors.push({
|
|
|
- tid: change.tid,
|
|
|
- cid: change.cid,
|
|
|
- uid: preAudit.uid,
|
|
|
- name: preAudit.name,
|
|
|
- jobs: preAudit.jobs,
|
|
|
- company: preAudit.company,
|
|
|
- times: change.times,
|
|
|
- usite: preAudit.usite,
|
|
|
- usort: curAudit.usort,
|
|
|
- status: auditConst.auditStatus.checkCancel,
|
|
|
- sin_time: time,
|
|
|
- sdesc: '',
|
|
|
+ change.preAuditors.forEach(x => {
|
|
|
+ newAuditors.push({
|
|
|
+ tid: change.tid, cid: change.cid, uid: x.uid,
|
|
|
+ times: x.times, usite: x.usite, usort: x.usort + 1,
|
|
|
+ status: x.uid === selfAuditor.uid ? auditConst.status.checkCancel : auditConst.status.checkSkip,
|
|
|
+ begin_time: time, end_time: time, sin_time: time, sdesc: '',
|
|
|
+ name: x.name, jobs: x.role || x.jobs, company: x.company,
|
|
|
+ audit_type: x.audit_type, audit_order: x.audit_order,
|
|
|
+ });
|
|
|
});
|
|
|
await transaction.insert(this.tableName, newAuditors);
|
|
|
// 更新上一个人,最新审批状态为审批中
|
|
|
- await transaction.update(this.tableName, { sin_time: time, status: auditConst.status.checking }, {
|
|
|
- where: { cid: change.cid, times: change.times, usort: curAudit.usort + 1 }
|
|
|
+ await transaction.update(this.tableName, { begin_time: time, sin_time: time, status: auditConst.status.checking }, {
|
|
|
+ where: { cid: change.cid, times: change.times, usort: selfAuditor.usort + 2 }
|
|
|
});
|
|
|
// 回退spamount值数据
|
|
|
- const changeList = await this.ctx.service.changeAuditList.getAllDataByCondition({
|
|
|
- where: { cid: change.cid },
|
|
|
- });
|
|
|
+ const changeList = await this.ctx.service.changeAuditList.getList(change.cid);
|
|
|
let total_price = 0;
|
|
|
const tp_decimal = change.tp_decimal ? change.tp_decimal : this.ctx.tender.info.decimal.tp;
|
|
|
const updateList = [];
|
|
|
for (const cl of changeList) {
|
|
|
const audit_amount = cl.audit_amount !== '' ? cl.audit_amount.split(',') : [];
|
|
|
- // const last_amount = audit_amount[audit_amount.length - 1] ? audit_amount[audit_amount.length - 1] : 0;
|
|
|
audit_amount.push(cl.spamount);
|
|
|
const list_update = {
|
|
|
id: cl.id,
|
|
@@ -1005,47 +1126,43 @@ module.exports = app => {
|
|
|
* @private
|
|
|
*/
|
|
|
async _auditCheckCancelNo(change) {
|
|
|
+ const accountId = this.ctx.session.sessionUser.accountId;
|
|
|
+ const selfAuditor = change.preAuditors.find(x => { return x.uid === accountId && x.status === auditConst.status.checkNo; });
|
|
|
+ if (!selfAuditor) throw '该标段由他人审批退回,您不可撤回';
|
|
|
|
|
|
const time = new Date();
|
|
|
|
|
|
const transaction = await this.db.beginTransaction();
|
|
|
try {
|
|
|
// const curAudit = await this.getDataByCondition({ cid: change.cid, times: change.times - 1, status: auditConst.auditStatus.back });
|
|
|
- const curAudit = await this.getAuditorByStatus(change.cid, change.times - 1, auditConst.auditStatus.back);
|
|
|
+ // const curAudit = await this.getAuditorByStatus(change.cid, change.times - 1, auditConst.auditStatus.back);
|
|
|
// 整理上一个流程审核人状态更新
|
|
|
// 顺移其后审核人流程顺序
|
|
|
const sql = 'UPDATE ' + this.tableName + ' SET `usort` = `usort` + 2 WHERE cid = ? AND times = ? AND `usort` > ?';
|
|
|
- await transaction.query(sql, [change.cid, change.times - 1, curAudit.usort]);
|
|
|
+ await transaction.query(sql, [change.cid, selfAuditor.times, selfAuditor.usort]);
|
|
|
// 当前审批人2次添加至流程中
|
|
|
- const newAuditors = [];
|
|
|
- newAuditors.push({
|
|
|
- tid: change.tid,
|
|
|
- cid: change.cid,
|
|
|
- uid: curAudit.uid,
|
|
|
- name: curAudit.name,
|
|
|
- jobs: curAudit.jobs,
|
|
|
- company: curAudit.company,
|
|
|
- times: curAudit.times,
|
|
|
- usite: curAudit.usite,
|
|
|
- usort: curAudit.usort + 1,
|
|
|
- status: auditConst.auditStatus.checkCancel,
|
|
|
- sin_time: time,
|
|
|
- sdesc: '',
|
|
|
+ const checkCancelAuditors = [], checkingAuditors = [];
|
|
|
+ change.preAuditors.forEach(x => {
|
|
|
+ checkCancelAuditors.push({
|
|
|
+ tid: change.tid, cid: change.cid, uid: x.uid,
|
|
|
+ times: x.times, usite: x.usite, usort: x.usort + 1,
|
|
|
+ status: x.uid === selfAuditor.uid ? auditConst.status.checkCancel : auditConst.status.checkSkip,
|
|
|
+ begin_time: time, end_time: time, sin_time: time, sdesc: '',
|
|
|
+ name: x.name, jobs: x.role || x.jobs, company: x.company,
|
|
|
+ audit_type: x.audit_type, audit_order: x.audit_order,
|
|
|
+ });
|
|
|
});
|
|
|
- newAuditors.push({
|
|
|
- tid: change.tid,
|
|
|
- cid: change.cid,
|
|
|
- uid: curAudit.uid,
|
|
|
- name: curAudit.name,
|
|
|
- jobs: curAudit.jobs,
|
|
|
- company: curAudit.company,
|
|
|
- times: curAudit.times,
|
|
|
- usite: curAudit.usite,
|
|
|
- usort: curAudit.usort + 2,
|
|
|
- status: auditConst.auditStatus.checking,
|
|
|
- sin_time: time,
|
|
|
+ change.preAuditors.forEach(x => {
|
|
|
+ checkingAuditors.push({
|
|
|
+ tid: change.tid, cid: change.cid, uid: x.uid,
|
|
|
+ times: x.times, usite: x.usite, usort: x.usort + 2,
|
|
|
+ status: auditConst.status.checking,
|
|
|
+ begin_time: time, sin_time: time, sdesc: '',
|
|
|
+ name: x.name, jobs: x.role || x.jobs, company: x.company,
|
|
|
+ audit_type: x.audit_type, audit_order: x.audit_order,
|
|
|
+ });
|
|
|
});
|
|
|
- await transaction.insert(this.tableName, newAuditors);
|
|
|
+ await transaction.insert(this.tableName, [...checkCancelAuditors, ...checkingAuditors]);
|
|
|
// 删除当前次审批流
|
|
|
await transaction.delete(this.tableName, { cid: change.cid, times: change.times });
|
|
|
// 回退数据
|
|
@@ -1057,6 +1174,29 @@ module.exports = app => {
|
|
|
throw err;
|
|
|
}
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 会签未全部审批通过时,撤回仅修改本人状态
|
|
|
+ *
|
|
|
+ * @param stage
|
|
|
+ * @returns {Promise<void>}
|
|
|
+ * @private
|
|
|
+ */
|
|
|
+ async _auditCheckCancelAnd(change) {
|
|
|
+ const accountId = this.ctx.session.sessionUser.accountId;
|
|
|
+ const selfAuditor = change.flowAuditors.find(x => { return x.uid === accountId; });
|
|
|
+ if (!selfAuditor || selfAuditor.status !== auditConst.status.checked) throw '不可撤回';
|
|
|
+
|
|
|
+ const transaction = await this.db.beginTransaction();
|
|
|
+ try {
|
|
|
+ await transaction.update(this.tableName, {
|
|
|
+ id: selfAuditor.id, status: auditConst.status.checking, sdesc: '', end_time: null,
|
|
|
+ });
|
|
|
+ await transaction.commit();
|
|
|
+ } catch(err) {
|
|
|
+ await transaction.rollback();
|
|
|
+ throw err;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
async getAuditorByStatus(cid, times, status, transaction= null) {
|
|
|
const sql = 'SELECT * FROM ?? WHERE `cid` = ? AND `times` = ? AND `status` = ? ORDER BY `usort` DESC';
|
|
@@ -1069,6 +1209,10 @@ module.exports = app => {
|
|
|
try {
|
|
|
const auditors = await this.getListGroupByWithoutYB(cid, times);
|
|
|
const now_audit = this._.find(auditors, { uid: data.old_aid });
|
|
|
+ if (data.operate !== 'del') {
|
|
|
+ const exist = await this.getDataByCondition({ cid, times, uid: data.new_aid });
|
|
|
+ if (exist) throw '该审核人已存在,请勿重复添加';
|
|
|
+ }
|
|
|
if (data.operate === 'add') {
|
|
|
if (now_audit.status !== auditConst.status.uncheck && now_audit.status !== auditConst.status.checking) {
|
|
|
throw '当前人下无法操作新增';
|
|
@@ -1081,21 +1225,44 @@ module.exports = app => {
|
|
|
name: nowAuditInfo.name,
|
|
|
company: nowAuditInfo.company,
|
|
|
jobs: nowAuditInfo.role,
|
|
|
- usort: now_audit.usort+1,
|
|
|
- usite: now_audit.usite+1,
|
|
|
+ usort: now_audit.usort + 1,
|
|
|
+ usite: now_audit.usite + 1,
|
|
|
+ audit_order: now_audit.audit_order + 1,
|
|
|
+ audit_type: auditType.key.common,
|
|
|
times: times,
|
|
|
- status: auditConst.auditStatus.uncheck,
|
|
|
+ status: auditConst.status.uncheck,
|
|
|
};
|
|
|
// order+1
|
|
|
- await this._syncOrderByDelete(transaction, cid, now_audit.usite+1, now_audit.usort+1, times, '+');
|
|
|
+ await this._syncOrderByDelete(transaction, cid, now_audit.usite + 1, now_audit.usort + 1, times, '+');
|
|
|
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 nowAuditInfo = await this.ctx.service.projectAccount.getDataById(data.new_aid);
|
|
|
+ const newAudit = {
|
|
|
+ tid: this.ctx.tender.id,
|
|
|
+ cid,
|
|
|
+ uid: data.new_aid,
|
|
|
+ name: nowAuditInfo.name,
|
|
|
+ company: nowAuditInfo.company,
|
|
|
+ jobs: nowAuditInfo.role,
|
|
|
+ usort: now_audit.usort,
|
|
|
+ usite: now_audit.usite,
|
|
|
+ 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') {
|
|
|
if (now_audit.status !== auditConst.status.uncheck) {
|
|
|
throw '当前人无法操作删除';
|
|
|
}
|
|
|
+ const flowAuditors = auditors.filter(x => { return x.order === now_audit.order; });
|
|
|
await transaction.delete(this.tableName, { cid, times, uid: now_audit.uid, usite: now_audit.usite });
|
|
|
- await this._syncOrderByDelete(transaction, cid, now_audit.usite, now_audit.usort, times);
|
|
|
+ if (flowAuditors.length === 1) await this._syncOrderByDelete(transaction, cid, now_audit.usite, now_audit.usort, times);
|
|
|
// 旧的更新为is_old为1
|
|
|
// await transaction.update(this.tableName, { is_old: 1 }, {
|
|
|
// where: {
|
|
@@ -1124,7 +1291,13 @@ module.exports = app => {
|
|
|
// }
|
|
|
// });
|
|
|
}
|
|
|
- if (this.ctx.tender.info.shenpi.change === shenpiConst.sp_status.gdspl || this.ctx.tender.info.shenpi.change === shenpiConst.sp_status.gdzs) {
|
|
|
+ if (this.ctx.tender.info.shenpi.change === shenpiConst.sp_status.gdspl) {
|
|
|
+ const newAuditors = await transaction.select(this.tableName, { where: { cid, times }, orders: [['usite', 'asc']] });
|
|
|
+ newAuditors.shift();
|
|
|
+ const newAuditorGroup = this.ctx.helper.groupAuditors(newAuditors, 'usort');
|
|
|
+ const uniqNewAuditorGroup = this.ctx.helper.groupAuditorsUniq(newAuditorGroup);
|
|
|
+ await this.ctx.service.shenpiAudit.updateAuditListWithAuditType(transaction, this.ctx.tender.id, this.ctx.tender.info.shenpi.change, shenpiConst.sp_type.change, uniqNewAuditorGroup);
|
|
|
+ } else if (this.ctx.tender.info.shenpi.change === shenpiConst.sp_status.gdzs) {
|
|
|
const newAuditors = await this.getListGroupByWithoutYB(cid, times, transaction);
|
|
|
await this.ctx.service.shenpiAudit.updateAuditList(transaction, this.ctx.tender.id, this.ctx.tender.info.shenpi.change, shenpiConst.sp_type.change, this._.map(newAuditors, 'uid'));
|
|
|
}
|