|
@@ -1,6 +1,7 @@
|
|
|
'use strict';
|
|
|
|
|
|
const auditConst = require('../const/audit').advance;
|
|
|
+const shenpiConst = require('../const/shenpi');
|
|
|
const pushType = require('../const/audit').pushType;
|
|
|
module.exports = app => {
|
|
|
class AdvanceAudit extends app.BaseService {
|
|
@@ -69,18 +70,29 @@ module.exports = app => {
|
|
|
* @param {Number} times - 第几次审批
|
|
|
* @return {Boolean} 是否插入成功
|
|
|
*/
|
|
|
- async addAuditor(tid, vid, audit_id, times = 1) {
|
|
|
- const newOrder = await this.getNewOrder(vid, times);
|
|
|
- const record = {
|
|
|
- tid,
|
|
|
- vid,
|
|
|
- audit_id,
|
|
|
- times,
|
|
|
- order: newOrder,
|
|
|
- status: auditConst.status.uncheck,
|
|
|
- };
|
|
|
- const result = await this.db.insert(this.tableName, record);
|
|
|
- return result && result.affectedRows === 1;
|
|
|
+ async addAuditor(tid, vid, audit_id, times = 1, is_gdzs = 0) {
|
|
|
+ const transaction = await this.db.beginTransaction();
|
|
|
+ try {
|
|
|
+ let newOrder = await this.getNewOrder(vid, times);
|
|
|
+ // 判断是否存在固定终审,存在则newOrder - 1并使终审order+1
|
|
|
+ newOrder = is_gdzs === 1 ? newOrder - 1 : newOrder;
|
|
|
+ if (is_gdzs) await this._syncOrderByDelete(transaction, vid, newOrder, times, '+');
|
|
|
+ const record = {
|
|
|
+ tid,
|
|
|
+ vid,
|
|
|
+ audit_id,
|
|
|
+ times,
|
|
|
+ order: newOrder,
|
|
|
+ status: auditConst.status.uncheck,
|
|
|
+ };
|
|
|
+ const result = await transaction.insert(this.tableName, record);
|
|
|
+ await transaction.commit();
|
|
|
+ return result && result.affectedRows === 1;
|
|
|
+ } catch (err) {
|
|
|
+ await transaction.rollback();
|
|
|
+ throw err;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -117,7 +129,7 @@ module.exports = app => {
|
|
|
* @return {Promise<*>} 查询结果集
|
|
|
* @private
|
|
|
*/
|
|
|
- async _syncOrderByDelete(transaction, vid, order, times) {
|
|
|
+ async _syncOrderByDelete(transaction, vid, order, times, selfOperate = '-') {
|
|
|
this.initSqlBuilder();
|
|
|
this.sqlBuilder.setAndWhere('vid', {
|
|
|
value: this.db.escape(vid),
|
|
@@ -133,7 +145,7 @@ module.exports = app => {
|
|
|
});
|
|
|
this.sqlBuilder.setUpdateData('order', {
|
|
|
value: 1,
|
|
|
- selfOperate: '-',
|
|
|
+ selfOperate: selfOperate,
|
|
|
});
|
|
|
const [sql, sqlParam] = this.sqlBuilder.build(this.tableName, 'update');
|
|
|
const data = await transaction.query(sql, sqlParam);
|
|
@@ -204,7 +216,11 @@ module.exports = app => {
|
|
|
async start(vid, times = 1, data) {
|
|
|
const audit = await this.getDataByCondition({ vid, times, order: 1 });
|
|
|
if (!audit) {
|
|
|
- throw '请先选择审批人,再上报数据';
|
|
|
+ if(this.ctx.tender.info.shenpi.advance === shenpiConst.sp_status.gdspl) {
|
|
|
+ throw '请联系管理员添加审批人';
|
|
|
+ } else {
|
|
|
+ throw '请先选择审批人,再上报数据';
|
|
|
+ }
|
|
|
}
|
|
|
const transaction = await this.db.beginTransaction();
|
|
|
try {
|
|
@@ -494,6 +510,55 @@ module.exports = app => {
|
|
|
const sqlParam = [this.tableName, this.ctx.service.advance.tableName, this.ctx.service.tender.tableName, auditorId, auditConst.status.checking, auditorId, auditConst.status.checkNo, auditConst.status.checkNo];
|
|
|
return await this.db.query(sql, sqlParam);
|
|
|
}
|
|
|
+
|
|
|
+ async updateNewAuditList(advance, newIdList) {
|
|
|
+ const transaction = await this.db.beginTransaction();
|
|
|
+ try {
|
|
|
+ // 先删除旧的审批流,再添加新的
|
|
|
+ transaction.delete(this.tableName, { vid: advance.id, times: advance.times });
|
|
|
+ const newAuditors = [];
|
|
|
+ let order = 1;
|
|
|
+ for (const aid of newIdList) {
|
|
|
+ newAuditors.push({
|
|
|
+ tid: advance.tid, vid: advance.id, audit_id: aid,
|
|
|
+ times: advance.times, order, status: auditConst.status.uncheck,
|
|
|
+ });
|
|
|
+ order++;
|
|
|
+ }
|
|
|
+ if(newAuditors.length > 0) await transaction.insert(this.tableName, newAuditors);
|
|
|
+ await transaction.commit();
|
|
|
+ } catch (err) {
|
|
|
+ await transaction.rollback();
|
|
|
+ throw err;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async updateLastAudit(advance, auditList, lastId) {
|
|
|
+ const transaction = await this.db.beginTransaction();
|
|
|
+ try {
|
|
|
+ // 先判断auditList里的aid是否与lastId相同,相同则删除并重新更新order
|
|
|
+ const idList = this._.map(auditList, 'audit_id');
|
|
|
+ let order = idList.length + 1;
|
|
|
+ if (idList.indexOf(lastId) !== -1) {
|
|
|
+ transaction.delete(this.tableName, { vid: advance.id, times: advance.times, audit_id: lastId });
|
|
|
+ const audit = this._.find(auditList, { 'audit_id': lastId });
|
|
|
+ // 顺移之后审核人流程顺序
|
|
|
+ await this._syncOrderByDelete(transaction, advance.id, audit.order, advance.times);
|
|
|
+ order = order - 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 添加终审
|
|
|
+ const newAuditor = {
|
|
|
+ tid: advance.tid, vid: advance.id, audit_id: lastId,
|
|
|
+ times: advance.times, order, status: auditConst.status.uncheck,
|
|
|
+ };
|
|
|
+ await transaction.insert(this.tableName, newAuditor);
|
|
|
+ await transaction.commit();
|
|
|
+ } catch (err) {
|
|
|
+ await transaction.rollback();
|
|
|
+ throw err;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
return AdvanceAudit;
|
|
|
};
|