change_project_audit.js 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date 2018/8/14
  7. * @version
  8. */
  9. const auditConst = require('../const/audit').changeProject;
  10. const pushType = require('../const/audit').pushType;
  11. const pushOperate = require('../const/spec_3f').pushOperate;
  12. const shenpiConst = require('../const/shenpi');
  13. const smsTypeConst = require('../const/sms_type');
  14. const SMS = require('../lib/sms');
  15. const SmsAliConst = require('../const/sms_alitemplate');
  16. const wxConst = require('../const/wechat_template');
  17. module.exports = app => {
  18. class ChangeProjectAudit extends app.BaseService {
  19. /**
  20. * 构造函数
  21. *
  22. * @param {Object} ctx - egg全局变量
  23. * @return {void}
  24. */
  25. constructor(ctx) {
  26. super(ctx);
  27. this.tableName = 'change_project_audit';
  28. }
  29. /**
  30. * 获取 审核列表信息
  31. *
  32. * @param {Number} cpId - 变更立项id
  33. * @param {Number} times - 第几次审批
  34. * @return {Promise<*>}
  35. */
  36. async getAuditors(cpId, times = 1) {
  37. 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` ' +
  38. '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 ' +
  39. 'WHERE la.`cpid` = ? and la.`times` = ? and la.`aid` = pa.`id` and g.`aid` = la.`aid` order by la.`order`';
  40. const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, this.tableName, cpId, times, cpId, times];
  41. const result = await this.db.query(sql, sqlParam);
  42. const sql2 = 'SELECT COUNT(a.`aid`) as num FROM (SELECT `aid` FROM ?? WHERE `cpid` = ? AND `times` = ? GROUP BY `aid`) as a';
  43. const sqlParam2 = [this.tableName, cpId, times];
  44. const count = await this.db.queryOne(sql2, sqlParam2);
  45. for (const i in result) {
  46. result[i].max_sort = count.num;
  47. }
  48. return result;
  49. }
  50. /**
  51. * 获取 当前审核人
  52. *
  53. * @param {Number} cpId - 变更立项id
  54. * @param {Number} times - 第几次审批
  55. * @return {Promise<*>}
  56. */
  57. async getCurAuditor(cpId, times = 1) {
  58. 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` ' +
  59. ' FROM ?? AS la Left Join ?? AS pa On la.`aid` = pa.`id` ' +
  60. ' WHERE la.`cpid` = ? and la.`status` = ? and la.`times` = ?';
  61. const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, cpId, auditConst.status.checking, times];
  62. return await this.db.queryOne(sql, sqlParam);
  63. }
  64. /**
  65. * 获取审核人流程列表
  66. *
  67. * @param auditorId
  68. * @return {Promise<*>}
  69. */
  70. async getAuditGroupByList(changeId, times) {
  71. const sql = 'SELECT pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`cpid`, la.`aid`, la.`order` ' +
  72. ' FROM ?? AS la Left Join ?? AS pa On la.`aid` = pa.`id`' +
  73. ' WHERE la.`cpid` = ? and la.`times` = ? and la.`status` != ? and la.`status` != ? GROUP BY la.`aid` ORDER BY la.`order`';
  74. const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, changeId, times, auditConst.status.revise, auditConst.status.cancelRevise];
  75. return await this.db.query(sql, sqlParam);
  76. }
  77. /**
  78. * 移除审核人
  79. *
  80. * @param {Number} materialId - 材料调差期id
  81. * @param {Number} status - 期状态
  82. * @param {Number} status - 期次数
  83. * @return {Promise<boolean>}
  84. */
  85. async getAuditorByStatus(cpId, status, times = 1) {
  86. let auditor = null;
  87. let sql = '';
  88. let sqlParam = '';
  89. switch (status) {
  90. case auditConst.status.checking :
  91. case auditConst.status.checked :
  92. case auditConst.status.checkNo :
  93. case auditConst.status.revise :
  94. case auditConst.status.cancelRevise :
  95. sql = 'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`cpid`, la.`aid`, la.`order` ' +
  96. ' FROM ?? AS la Left Join ?? AS pa On la.`aid` = pa.`id` ' +
  97. ' WHERE la.`cpid` = ? and la.`status` = ? ' +
  98. ' ORDER BY la.`times` desc, la.`order` desc';
  99. sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, cpId, status];
  100. auditor = await this.db.queryOne(sql, sqlParam);
  101. break;
  102. case auditConst.status.back :
  103. sql = 'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`cpid`, la.`aid`, la.`order` ' +
  104. ' FROM ?? AS la Left Join ?? AS pa On la.`aid` = pa.`id`' +
  105. ' WHERE la.`cpid` = ? and la.`status` = ? and la.`times` = ?' +
  106. ' ORDER BY la.`times` desc, la.`order` desc';
  107. sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, cpId, auditConst.status.back, parseInt(times) - 1];
  108. auditor = await this.db.queryOne(sql, sqlParam);
  109. break;
  110. case auditConst.status.uncheck :
  111. break;
  112. default:break;
  113. }
  114. return auditor;
  115. }
  116. async getLastAudit(cpid, times, transaction = null) {
  117. const sql = 'SELECT * FROM ?? WHERE `cpid` = ? AND `times` = ? ORDER BY `order` DESC';
  118. const sqlParam = [this.tableName, cpid, times];
  119. return transaction ? await transaction.queryOne(sql, sqlParam) : await this.db.queryOne(sql, sqlParam);
  120. }
  121. /**
  122. * 获取审核人流程列表(包括原报)
  123. * @param {Number} materialId 调差id
  124. * @param {Number} times 审核次数
  125. * @return {Promise<Array>} 查询结果集(包括原报)
  126. */
  127. async getAuditorsWithOwner(cpId, times = 1) {
  128. const result = await this.getAuditGroupByList(cpId, times);
  129. const sql =
  130. 'SELECT pa.`id` As aid, pa.`name`, pa.`company`, pa.`role`, ? As times, ? As cpid, 0 As `order`' +
  131. ' FROM ' +
  132. this.ctx.service.changeProject.tableName +
  133. ' As s' +
  134. ' LEFT JOIN ' +
  135. this.ctx.service.projectAccount.tableName +
  136. ' As pa' +
  137. ' ON s.uid = pa.id' +
  138. ' WHERE s.id = ?';
  139. const sqlParam = [times, cpId, cpId];
  140. const user = await this.db.queryOne(sql, sqlParam);
  141. result.unshift(user);
  142. return result;
  143. }
  144. /**
  145. * 新增审核人
  146. *
  147. * @param {Number} cpId - 立项书id
  148. * @param {Number} auditorId - 审核人id
  149. * @param {Number} times - 第几次审批
  150. * @return {Promise<number>}
  151. */
  152. async addAuditor(cpId, auditorId, times = 1, is_gdzs = 0) {
  153. const transaction = await this.db.beginTransaction();
  154. let flag = false;
  155. try {
  156. let newOrder = await this.getNewOrder(cpId, times);
  157. // 判断是否存在固定终审,存在则newOrder - 1并使终审order+1
  158. newOrder = is_gdzs === 1 ? newOrder - 1 : newOrder;
  159. if (is_gdzs) await this._syncOrderByDelete(transaction, cpId, newOrder, times, '+');
  160. const data = {
  161. tid: this.ctx.tender.id,
  162. cpid: cpId,
  163. aid: auditorId,
  164. times,
  165. order: newOrder,
  166. status: auditConst.status.uncheck,
  167. };
  168. const result = await transaction.insert(this.tableName, data);
  169. await transaction.commit();
  170. flag = result.effectRows = 1;
  171. } catch (err) {
  172. await transaction.rollback();
  173. throw err;
  174. }
  175. return flag;
  176. }
  177. /**
  178. * 获取 最新审核顺序
  179. *
  180. * @param {Number} cpId - 立项书id
  181. * @param {Number} times - 第几次审批
  182. * @return {Promise<number>}
  183. */
  184. async getNewOrder(cpId, times = 1) {
  185. const sql = 'SELECT Max(??) As max_order FROM ?? Where `cpid` = ? and `times` = ?';
  186. const sqlParam = ['order', this.tableName, cpId, times];
  187. const result = await this.db.queryOne(sql, sqlParam);
  188. return result && result.max_order ? result.max_order + 1 : 1;
  189. }
  190. /**
  191. * 移除审核人
  192. *
  193. * @param {Number} cpId - 变更立项书id
  194. * @param {Number} auditorId - 审核人id
  195. * @param {Number} times - 第几次审批
  196. * @return {Promise<boolean>}
  197. */
  198. async deleteAuditor(cpId, auditorId, times = 1) {
  199. const transaction = await this.db.beginTransaction();
  200. try {
  201. const condition = { cpid: cpId, aid: auditorId, times };
  202. const auditor = await this.getDataByCondition(condition);
  203. if (!auditor) {
  204. throw '该审核人不存在';
  205. }
  206. await this._syncOrderByDelete(transaction, cpId, auditor.order, times);
  207. await transaction.delete(this.tableName, condition);
  208. await transaction.commit();
  209. } catch (err) {
  210. await transaction.rollback();
  211. throw err;
  212. }
  213. return true;
  214. }
  215. /**
  216. * 移除审核人时,同步其后审核人order
  217. * @param transaction - 事务
  218. * @param {Number} cpId - 变更立项书id
  219. * @param {Number} auditorId - 审核人id
  220. * @param {Number} times - 第几次审批
  221. * @return {Promise<*>}
  222. * @private
  223. */
  224. async _syncOrderByDelete(transaction, cpId, order, times, selfOperate = '-') {
  225. this.initSqlBuilder();
  226. this.sqlBuilder.setAndWhere('cpid', {
  227. value: cpId,
  228. operate: '=',
  229. });
  230. this.sqlBuilder.setAndWhere('order', {
  231. value: order,
  232. operate: '>=',
  233. });
  234. this.sqlBuilder.setAndWhere('times', {
  235. value: times,
  236. operate: '=',
  237. });
  238. this.sqlBuilder.setUpdateData('order', {
  239. value: 1,
  240. selfOperate,
  241. });
  242. const [sql, sqlParam] = this.sqlBuilder.build(this.tableName, 'update');
  243. const data = await transaction.query(sql, sqlParam);
  244. return data;
  245. }
  246. /**
  247. * 开始审批
  248. * @param {Number} cpId - 立项书id
  249. * @param {Number} times - 第几次审批
  250. * @return {Promise<boolean>}
  251. */
  252. async start(cpId, times = 1) {
  253. const audit = await this.getDataByCondition({ cpid: cpId, times, order: 1 });
  254. if (!audit) {
  255. // if (this.ctx.tender.info.shenpi.material === shenpiConst.sp_status.gdspl) {
  256. // throw '请联系管理员添加审批人';
  257. // } else {
  258. throw '请先选择审批人,再上报数据';
  259. // }
  260. }
  261. const transaction = await this.db.beginTransaction();
  262. try {
  263. await transaction.update(this.tableName, { id: audit.id, status: auditConst.status.checking, begin_time: new Date() });
  264. await transaction.update(this.ctx.service.changeProject.tableName, {
  265. id: cpId, status: auditConst.status.checking,
  266. });
  267. // 微信模板通知
  268. const wechatData = {
  269. type: 'project',
  270. status: wxConst.status.check,
  271. tips: wxConst.tips.check,
  272. code: this.ctx.session.sessionProject.code,
  273. c_name: this.ctx.change.name,
  274. };
  275. await this.ctx.helper.sendWechat(audit.aid, smsTypeConst.const.BG, smsTypeConst.judge.approval.toString(), wxConst.template.change, wechatData);
  276. await this.ctx.service.noticeAgain.addNoticeAgain(transaction, smsTypeConst.const.BG, {
  277. pid: this.ctx.session.sessionProject.id,
  278. tid: this.ctx.tender.id,
  279. uid: audit.aid,
  280. sp_type: 'change',
  281. sp_id: audit.id,
  282. table_name: this.tableName,
  283. template: wxConst.template.change,
  284. wx_data: wechatData,
  285. });
  286. await transaction.delete(this.ctx.service.changeProjectHistory.tableName, { cpid: cpId });
  287. // todo 更新标段tender状态 ?
  288. // 检查三方特殊推送
  289. await this.ctx.service.specMsg.addChangeProjectMsg(transaction, this.ctx.session.sessionProject.id, this.ctx.change, pushOperate.change_project.flow);
  290. await transaction.commit();
  291. } catch (err) {
  292. await transaction.rollback();
  293. throw err;
  294. }
  295. return true;
  296. }
  297. /**
  298. * 获取审核人需要审核的期列表
  299. *
  300. * @param auditorId
  301. * @return {Promise<*>}
  302. */
  303. async getAuditChangeProject(auditorId) {
  304. const sql = 'SELECT ma.`aid`, ma.`times`, ma.`order`, ma.`begin_time`, ma.`end_time`, ma.`tid`, ma.`cpid`,' +
  305. ' m.`status` As `mstatus`, m.`code` As `mcode`,' +
  306. ' t.`name`, t.`project_id`, t.`type`, t.`user_id` ' +
  307. ' FROM ?? AS ma, ?? AS m, ?? As t ' +
  308. ' WHERE ((ma.`aid` = ? and ma.`status` = ?) OR (m.`uid` = ? and ma.`status` = ? and m.`status` = ? and ma.`times` = (m.`times`-1)))' +
  309. ' and ma.`cpid` = m.`id` and ma.`tid` = t.`id` ORDER BY ma.`begin_time` DESC';
  310. const sqlParam = [this.tableName, this.ctx.service.changeProject.tableName, this.ctx.service.tender.tableName, auditorId, auditConst.status.checking, auditorId, auditConst.status.back, auditConst.status.back];
  311. return await this.db.query(sql, sqlParam);
  312. }
  313. /**
  314. * 获取审核人审核的次数
  315. *
  316. * @param auditorId
  317. * @return {Promise<*>}
  318. */
  319. async getCountByChecked(auditorId) {
  320. return await this.db.count(this.tableName, { aid: auditorId, status: [auditConst.status.checked, auditConst.status.back, auditConst.status.checkNo] });
  321. }
  322. /**
  323. * 获取最近一次审批结束时间
  324. *
  325. * @param auditorId
  326. * @return {Promise<*>}
  327. */
  328. async getLastEndTimeByChecked(auditorId) {
  329. const sql = 'SELECT `end_time` FROM ?? WHERE `aid` = ? ' +
  330. 'AND `status` in (' + this.ctx.helper.getInArrStrSqlFilter([auditConst.status.checked, auditConst.status.back, auditConst.status.checkNo]) + ') ORDER BY `end_time` DESC';
  331. const sqlParam = [this.tableName, auditorId];
  332. const result = await this.db.queryOne(sql, sqlParam);
  333. return result ? result.end_time : null;
  334. }
  335. /**
  336. * 用于添加推送所需的content内容
  337. * @param {Number} pid 项目id
  338. * @param {Number} tid 台账id
  339. * @param {Number} cpId 立项书id
  340. * @param {Number} uid 审批人id
  341. */
  342. async getNoticeContent(pid, tid, cpId, uid, opinion = '') {
  343. const noticeSql = 'SELECT * FROM (SELECT ' +
  344. ' t.`id` As `tid`, ma.`cpid`, m.`code` as `c_code`, t.`name`, pa.`name` As `su_name`, pa.role As `su_role`' +
  345. ' FROM (SELECT * FROM ?? WHERE `id` = ? ) As t' +
  346. ' LEFT JOIN ?? As m On t.`id` = m.`tid` AND m.`id` = ?' +
  347. ' LEFT JOIN ?? As ma ON m.`id` = ma.`cpid`' +
  348. ' LEFT JOIN ?? As pa ON pa.`id` = ?' +
  349. ' WHERE t.`project_id` = ? ) as new_t GROUP BY new_t.`tid`';
  350. const noticeSqlParam = [this.ctx.service.tender.tableName, tid, this.ctx.service.changeProject.tableName, cpId, this.tableName, this.ctx.service.projectAccount.tableName, uid, pid];
  351. const content = await this.db.query(noticeSql, noticeSqlParam);
  352. if (content.length) {
  353. content[0].opinion = opinion;
  354. }
  355. return content.length ? JSON.stringify(content[0]) : '';
  356. }
  357. /**
  358. * 审批
  359. * @param {Number} cpId - 立项书id
  360. * @param {auditConst.status.checked|auditConst.status.checkNo} checkType - 审批结果
  361. * @param {Number} times - 第几次审批
  362. * @return {Promise<void>}
  363. */
  364. async check(cpId, checkData, times = 1) {
  365. if (checkData.checkType !== auditConst.status.checked && checkData.checkType !== auditConst.status.checkNo && checkData.checkType !== auditConst.status.back) {
  366. throw '提交数据错误';
  367. }
  368. const pid = this.ctx.session.sessionProject.id;
  369. switch (checkData.checkType) {
  370. case auditConst.status.checked:
  371. await this._checked(pid, cpId, checkData, times);
  372. break;
  373. case auditConst.status.back:
  374. await this._back(pid, cpId, checkData, times);
  375. break;
  376. case auditConst.status.checkNo:
  377. await this._checkNo(pid, cpId, checkData, times);
  378. break;
  379. default:
  380. throw '无效审批操作';
  381. }
  382. }
  383. async _checked(pid, cpId, checkData, times) {
  384. const time = new Date();
  385. // 整理当前流程审核人状态更新
  386. const audit = await this.getDataByCondition({ cpid: cpId, times, status: auditConst.status.checking });
  387. if (!audit) {
  388. throw '审核数据错误';
  389. }
  390. // 获取审核人列表
  391. const sql = 'SELECT `tid`, `cpid`, `aid`, `order` FROM ?? WHERE `cpid` = ? and `times` = ? GROUP BY `aid` ORDER BY `id` ASC';
  392. const sqlParam = [this.tableName, cpId, times];
  393. const auditors = await this.db.query(sql, sqlParam);
  394. const nextAudit = await this.getDataByCondition({ cpid: cpId, times, order: audit.order + 1 });
  395. const transaction = await this.db.beginTransaction();
  396. try {
  397. await transaction.update(this.tableName, { id: audit.id, status: checkData.checkType, opinion: checkData.opinion, end_time: time });
  398. await this.ctx.service.noticeAgain.stopNoticeAgain(transaction, this.tableName, audit.id);
  399. // 获取推送必要信息
  400. const noticeContent = await this.getNoticeContent(pid, audit.tid, cpId, audit.aid, checkData.opinion);
  401. // 添加推送
  402. const records = [{ pid, type: pushType.changeProject, uid: this.ctx.change.uid, status: auditConst.status.checked, content: noticeContent }];
  403. auditors.forEach(audit => {
  404. records.push({ pid, type: pushType.changeProject, uid: audit.aid, status: auditConst.status.checked, content: noticeContent });
  405. });
  406. await transaction.insert('zh_notice', records);
  407. // 无下一审核人表示,审核结束
  408. if (nextAudit) {
  409. // 流程至下一审批人
  410. await transaction.update(this.tableName, { id: nextAudit.id, status: auditConst.status.checking, begin_time: time });
  411. // 同步 期信息
  412. await transaction.update(this.ctx.service.changeProject.tableName, {
  413. id: cpId, status: auditConst.status.checking,
  414. });
  415. // 微信模板通知
  416. const wechatData = {
  417. type: 'project',
  418. status: wxConst.status.check,
  419. tips: wxConst.tips.check,
  420. code: this.ctx.session.sessionProject.code,
  421. c_name: this.ctx.change.name,
  422. };
  423. await this.ctx.helper.sendWechat(nextAudit.aid, smsTypeConst.const.BG, smsTypeConst.judge.approval.toString(), wxConst.template.change, wechatData);
  424. await this.ctx.service.noticeAgain.addNoticeAgain(transaction, smsTypeConst.const.BG, {
  425. pid: this.ctx.session.sessionProject.id,
  426. tid: this.ctx.tender.id,
  427. uid: nextAudit.aid,
  428. sp_type: 'change',
  429. sp_id: nextAudit.id,
  430. table_name: this.tableName,
  431. template: wxConst.template.change,
  432. wx_data: wechatData,
  433. });
  434. // 检查三方特殊推送
  435. await this.ctx.service.specMsg.addChangeProjectMsg(transaction, pid, this.ctx.change, pushOperate.change_project.flow);
  436. } else {
  437. // 本期结束
  438. // 生成截止本期数据 final数据
  439. // 同步 期信息
  440. await transaction.update(this.ctx.service.changeProject.tableName, {
  441. id: cpId, status: checkData.checkType,
  442. });
  443. // 微信模板通知
  444. const users = this._.uniq(this._.concat(this._.map(auditors, 'aid'), this.ctx.change.uid));
  445. const wechatData = {
  446. type: 'project',
  447. status: wxConst.status.success,
  448. tips: wxConst.tips.success,
  449. code: this.ctx.session.sessionProject.code,
  450. c_name: this.ctx.change.name,
  451. };
  452. await this.ctx.helper.sendWechat(users, smsTypeConst.const.BG, smsTypeConst.judge.result.toString(), wxConst.template.change, wechatData);
  453. // 检查三方特殊推送
  454. await this.ctx.service.specMsg.addChangeProjectMsg(transaction, pid, this.ctx.change, pushOperate.change_project.flow);
  455. await this.ctx.service.specMsg.addChangeProjectMsg(transaction, pid, this.ctx.change, pushOperate.change_project.checked);
  456. }
  457. await transaction.commit();
  458. } catch (err) {
  459. await transaction.rollback();
  460. throw err;
  461. }
  462. }
  463. async _back(pid, cpId, checkData, times) {
  464. const time = new Date();
  465. const changeData = await this.ctx.service.changeProject.getDataById(cpId);
  466. // 整理当前流程审核人状态更新
  467. const audit = await this.getDataByCondition({ cpid: cpId, times, status: auditConst.status.checking });
  468. if (!audit) {
  469. throw '审核数据错误';
  470. }
  471. // 需要剔除原报可能存在修订进入流程的情况
  472. // const sql = 'SELECT `tid`, `cpid`, `aid`, `order` FROM ?? WHERE `cpid` = ? and `times` = ? and `status` != ? AND `status` != ? GROUP BY `aid` ORDER BY `id` ASC';
  473. // const sqlParam = [this.tableName, cpId, times];
  474. // const auditors = await this.db.query(sql, sqlParam);
  475. const auditors = await this.getAuditGroupByList(cpId, times);
  476. let order = 1;
  477. const newAuditors = [];
  478. for (const a of auditors) {
  479. a.times = times + 1;
  480. a.order = order;
  481. a.status = auditConst.status.uncheck;
  482. order++;
  483. newAuditors.push({
  484. tid: this.ctx.tender.id,
  485. cpid: cpId,
  486. times: a.times,
  487. order: a.order,
  488. status: a.status,
  489. aid: a.aid,
  490. });
  491. }
  492. const transaction = await this.db.beginTransaction();
  493. try {
  494. await transaction.update(this.tableName, { id: audit.id, status: checkData.checkType, opinion: checkData.opinion, end_time: time });
  495. await this.ctx.service.noticeAgain.stopNoticeAgain(transaction, this.tableName, audit.id);
  496. // 添加到消息推送表
  497. const noticeContent = await this.getNoticeContent(pid, audit.tid, cpId, audit.aid, checkData.opinion);
  498. const records = [{ pid, type: pushType.changeProject, uid: this.ctx.change.uid, status: auditConst.status.back, content: noticeContent }];
  499. auditors.forEach(audit => {
  500. records.push({ pid, type: pushType.changeProject, uid: audit.aid, status: auditConst.status.back, content: noticeContent });
  501. });
  502. await transaction.insert(this.ctx.service.noticePush.tableName, records);
  503. // 同步期信息
  504. await transaction.update(this.ctx.service.changeProject.tableName, {
  505. id: cpId, status: checkData.checkType,
  506. times: times + 1,
  507. });
  508. // 拷贝新一次审核流程列表
  509. await transaction.insert(this.tableName, newAuditors);
  510. // 微信模板通知
  511. const users = this._.uniq(this._.concat(this._.map(auditors, 'aid'), this.ctx.change.uid));
  512. const wechatData = {
  513. type: 'project',
  514. status: wxConst.status.back,
  515. tips: wxConst.tips.back,
  516. code: this.ctx.session.sessionProject.code,
  517. c_name: this.ctx.change.name,
  518. };
  519. await this.ctx.helper.sendWechat(users, smsTypeConst.const.BG, smsTypeConst.judge.result.toString(), wxConst.template.change, wechatData);
  520. // 生成内容保存表至zh_change_project_history中,用于撤回
  521. await this.ctx.service.changeProjectHistory.saveHistory(transaction, changeData);
  522. // 检查三方特殊推送
  523. await this.ctx.service.specMsg.addChangeProjectMsg(transaction, pid, this.ctx.change, pushOperate.change_project.flow);
  524. await transaction.commit();
  525. } catch (err) {
  526. await transaction.rollback();
  527. throw err;
  528. }
  529. }
  530. async _checkNo(pid, cpId, checkData, times) {
  531. const time = new Date();
  532. // 整理当前流程审核人状态更新
  533. const audit = await this.getDataByCondition({ cpid: cpId, times, status: auditConst.status.checking });
  534. if (!audit) {
  535. throw '审核数据错误';
  536. }
  537. // 获取审核人列表
  538. const sql = 'SELECT `tid`, `cpid`, `aid`, `order` FROM ?? WHERE `cpid` = ? and `times` = ? GROUP BY `aid` ORDER BY `id` ASC';
  539. const sqlParam = [this.tableName, cpId, times];
  540. const auditors = await this.db.query(sql, sqlParam);
  541. const transaction = await this.db.beginTransaction();
  542. try {
  543. await transaction.update(this.tableName, { id: audit.id, status: checkData.checkType, opinion: checkData.opinion, end_time: time });
  544. await this.ctx.service.noticeAgain.stopNoticeAgain(transaction, this.tableName, audit.id);
  545. // 获取推送必要信息
  546. const noticeContent = await this.getNoticeContent(pid, audit.tid, cpId, audit.aid, checkData.opinion);
  547. // 添加推送
  548. const records = [{ pid, type: pushType.changeProject, uid: this.ctx.change.uid, status: auditConst.status.checkNo, content: noticeContent }];
  549. auditors.forEach(audit => {
  550. records.push({ pid, type: pushType.changeProject, uid: audit.aid, status: auditConst.status.checkNo, content: noticeContent });
  551. });
  552. await transaction.insert('zh_notice', records);
  553. // 本期结束
  554. // 生成截止本期数据 final数据
  555. // 同步 期信息
  556. await transaction.update(this.ctx.service.changeProject.tableName, {
  557. id: cpId, status: checkData.checkType,
  558. });
  559. // 微信模板通知
  560. const users = this._.uniq(this._.concat(this._.map(auditors, 'aid'), this.ctx.change.uid));
  561. const wechatData = {
  562. type: 'project',
  563. status: wxConst.status.stop,
  564. tips: wxConst.tips.stop,
  565. code: this.ctx.session.sessionProject.code,
  566. c_name: this.ctx.change.name,
  567. };
  568. await this.ctx.helper.sendWechat(users, smsTypeConst.const.BG, smsTypeConst.judge.result.toString(), wxConst.template.change, wechatData);
  569. // 检查三方特殊推送
  570. await this.ctx.service.specMsg.addChangeProjectMsg(transaction, pid, this.ctx.change, pushOperate.change_project.flow);
  571. await transaction.commit();
  572. } catch (err) {
  573. await transaction.rollback();
  574. throw err;
  575. }
  576. }
  577. /**
  578. * 复制上一期的审批人列表给最新一期
  579. *
  580. * @param transaction - 新增一期的事务
  581. * @param {Object} preMaterial - 上一期
  582. * @param {Object} newaMaterial - 最新一期
  583. * @return {Promise<*>}
  584. */
  585. async copyPreChangeProjectAuditors(transaction, preChange, newChange) {
  586. const auditors = await this.getAuditGroupByList(preChange.id, preChange.times);
  587. const newAuditors = [];
  588. for (const a of auditors) {
  589. const na = {
  590. tid: preChange.tid,
  591. cpid: newChange.id,
  592. aid: a.aid,
  593. times: newChange.times,
  594. order: newAuditors.length + 1,
  595. status: auditConst.status.uncheck,
  596. };
  597. newAuditors.push(na);
  598. }
  599. const result = newAuditors.length > 0 ? await transaction.insert(this.tableName, newAuditors) : null;
  600. return result ? result.affectedRows === auditors.length : true;
  601. }
  602. async getAllAuditors(tenderId) {
  603. const sql = 'SELECT ma.aid, ma.tid FROM ' + this.tableName + ' ma' +
  604. ' LEFT JOIN ' + this.ctx.service.tender.tableName + ' t On ma.tid = t.id' +
  605. ' WHERE t.id = ?' +
  606. ' GROUP BY ma.aid';
  607. const sqlParam = [tenderId];
  608. return this.db.query(sql, sqlParam);
  609. }
  610. /**
  611. * 审批撤回
  612. * @param {Number} stageId - 标段id
  613. * @param {Number} times - 第几次审批
  614. * @return {Promise<void>}
  615. */
  616. async checkCancel(change) {
  617. // 分4种情况,根据ctx.cancancel值判断:
  618. // 1.原报发起撤回,当前流程删除,并回到待上报
  619. // 2.审批人撤回审批通过,增加流程,并回到它审批中
  620. // 3.审批人撤回审批终止,增加流程,并回到它审批中,并更新立项状态为审批中
  621. // 4.审批人撤回退回原报操作,删除新增的审批流,增加流程,回滚到它审批中
  622. switch (change.cancancel) {
  623. case 1: await this._userCheckCancel(change); break;
  624. case 2: await this._auditCheckCancel(change); break;
  625. case 3: await this._auditCheckCancelStop(change); break;
  626. case 4: await this._auditCheckCancelNo(change); break;
  627. default: throw '不可撤回,请刷新页面重试';
  628. }
  629. }
  630. /**
  631. * 原报撤回,直接改动审批人状态
  632. * 如果存在审批人数据,将其改为原报流程数据,但保留原提交人
  633. *
  634. * 一审 1 A checking -> A uncheck status改 pay/jl:删0(jl为增量数据,只删重复部分) 1->0 删1
  635. * ...
  636. *
  637. * @param stage
  638. * @returns {Promise<void>}
  639. * @private
  640. */
  641. async _userCheckCancel(change) {
  642. const transaction = await this.db.beginTransaction();
  643. try {
  644. // 整理当前流程审核人状态更新
  645. const curAudit = await this.getDataByCondition({ cpid: change.id, times: change.times, status: auditConst.status.checking });
  646. // 审批人变成待审批状态
  647. await transaction.update(this.tableName, {
  648. id: curAudit.id,
  649. status: auditConst.status.uncheck,
  650. begin_time: null,
  651. opinion: null,
  652. });
  653. await this.ctx.service.noticeAgain.deleteNoticeAgain(transaction, this.tableName, curAudit.id);
  654. // 变成待上报状态
  655. await transaction.update(this.ctx.service.changeProject.tableName, {
  656. id: change.id,
  657. status: change.times === 1 ? auditConst.status.uncheck : auditConst.status.back,
  658. });
  659. await transaction.commit();
  660. } catch (err) {
  661. await transaction.rollback();
  662. throw err;
  663. }
  664. }
  665. /**
  666. * 审批人撤回审批通过,插入两条数据
  667. *
  668. * 一审 1 A checked 一审 1 A checked
  669. * 二审 2 B checked pre -> 二审 2 B checked
  670. * 三审 3 C checking cur 二审 3 B checkCancel 增 增extra_his 增tp_his
  671. * 四审 4 D uncheck 二审 4 B checking 增 增pay_cur
  672. * 三审 5 C uncheck order、status改
  673. * 四审 6 D uncheck order改
  674. *
  675. * @param stage
  676. * @returns {Promise<void>}
  677. * @private
  678. */
  679. async _auditCheckCancel(change) {
  680. const time = new Date();
  681. const transaction = await this.db.beginTransaction();
  682. try {
  683. // 整理当前流程审核人状态更新
  684. const curAudit = await this.getDataByCondition({ cpid: change.id, times: change.times, status: auditConst.status.checking });
  685. const preAudit = change.preAudit;
  686. if (!curAudit || curAudit.order <= 1 || !preAudit) {
  687. throw '撤回用户数据错误';
  688. }
  689. // 顺移其后审核人流程顺序
  690. const sql = 'UPDATE ' + this.tableName + ' SET `order` = `order` + 2 WHERE cpid = ? AND times = ? AND `order` > ?';
  691. await transaction.query(sql, [change.id, change.times, curAudit.order]);
  692. // 当前审批人2次添加至流程中
  693. const newAuditors = [];
  694. // 先入撤回记录
  695. newAuditors.push({
  696. tid: change.tid,
  697. cpid: change.id,
  698. aid: preAudit.aid,
  699. times: change.times,
  700. order: curAudit.order,
  701. status: auditConst.status.checkCancel,
  702. begin_time: time,
  703. end_time: time,
  704. opinion: '',
  705. });
  706. newAuditors.push({
  707. tid: change.tid,
  708. cpid: change.id,
  709. aid: preAudit.aid,
  710. times: change.times,
  711. order: curAudit.order + 1,
  712. status: auditConst.status.checking,
  713. begin_time: time,
  714. });
  715. await transaction.insert(this.tableName, newAuditors);
  716. // 当前审批人变成待审批
  717. await transaction.update(this.tableName, { id: curAudit.id, order: curAudit.order + 2, begin_time: null, status: auditConst.status.uncheck });
  718. await this.ctx.service.noticeAgain.deleteNoticeAgain(transaction, this.tableName, curAudit.id);
  719. await transaction.commit();
  720. } catch (err) {
  721. await transaction.rollback();
  722. throw err;
  723. }
  724. }
  725. /**
  726. * 审批人撤回审批终止,插入两条数据
  727. *
  728. * @param stage
  729. * @returns {Promise<void>}
  730. * @private
  731. */
  732. async _auditCheckCancelStop(change) {
  733. const time = new Date();
  734. const transaction = await this.db.beginTransaction();
  735. try {
  736. // const curAudit = await this.getDataByCondition({ cpid: change.id, times: change.times, status: auditConst.status.checkNo });
  737. const curAudit = await this.getAuditorByStatus(change.id, auditConst.status.checkNo);
  738. if (!curAudit) {
  739. throw '撤回用户数据错误';
  740. }
  741. // 顺移其后审核人流程顺序
  742. const sql = 'UPDATE ' + this.tableName + ' SET `order` = `order` + 2 WHERE cpid = ? AND times = ? AND `order` > ?';
  743. await transaction.query(sql, [change.id, change.times, curAudit.order]);
  744. // 当前审批人2次添加至流程中
  745. const newAuditors = [];
  746. // 先入撤回记录
  747. newAuditors.push({
  748. tid: change.tid,
  749. cpid: change.id,
  750. aid: curAudit.aid,
  751. times: change.times,
  752. order: curAudit.order + 1,
  753. status: auditConst.status.checkCancel,
  754. begin_time: time,
  755. end_time: time,
  756. opinion: '',
  757. });
  758. newAuditors.push({
  759. tid: change.tid,
  760. cpid: change.id,
  761. aid: curAudit.aid,
  762. times: change.times,
  763. order: curAudit.order + 2,
  764. status: auditConst.status.checking,
  765. begin_time: time,
  766. });
  767. await transaction.insert(this.tableName, newAuditors);
  768. await transaction.update(this.ctx.service.changeProject.tableName, {
  769. id: change.id,
  770. status: auditConst.status.checking,
  771. });
  772. await transaction.commit();
  773. } catch (err) {
  774. await transaction.rollback();
  775. throw err;
  776. }
  777. }
  778. /**
  779. * 审批人撤回审批退回原报
  780. *
  781. * 1# 一审 1 A checked 1# 一审 1 A checked
  782. * 二审 2 B checkNo pre -> 二审 2 B checkNo
  783. * 三审 3 C uncheck 二审 3 B checkCancel 增 pay: 2#0 -> 1#3 jl: 2#0 -> 1#3 增tp_his 增extra_his
  784. * 二审 4 B checking 增 pay: 2#0 -> 1#4
  785. * 三审 5 C uncheck order改
  786. *
  787. * 2# 一审 1 A uncheck 2# 删 pay: 2#0删 jl: 2#0删
  788. * 二审 2 B uncheck
  789. * 三审 3 C uncheck
  790. *
  791. * @param stage
  792. * @returns {Promise<void>}
  793. * @private
  794. */
  795. async _auditCheckCancelNo(change) {
  796. const time = new Date();
  797. const transaction = await this.db.beginTransaction();
  798. try {
  799. // const curAudit = await this.getDataByCondition({ cpid: change.id, times: change.times - 1, status: auditConst.status.back });
  800. const curAudit = await this.getAuditorByStatus(change.id, auditConst.status.back, change.times);
  801. // 整理上一个流程审核人状态更新
  802. // 顺移其后审核人流程顺序
  803. const sql = 'UPDATE ' + this.tableName + ' SET `order` = `order` + 2 WHERE cpid = ? AND times = ? AND `order` > ?';
  804. await transaction.query(sql, [change.id, change.times - 1, curAudit.order]);
  805. // 当前审批人2次添加至流程中
  806. const newAuditors = [];
  807. newAuditors.push({
  808. tid: change.tid,
  809. cpid: change.id,
  810. aid: curAudit.aid,
  811. times: curAudit.times,
  812. order: curAudit.order + 1,
  813. status: auditConst.status.checkCancel,
  814. begin_time: time,
  815. end_time: time,
  816. opinion: '',
  817. });
  818. newAuditors.push({
  819. tid: change.tid,
  820. cpid: change.id,
  821. aid: curAudit.aid,
  822. times: curAudit.times,
  823. order: curAudit.order + 2,
  824. status: auditConst.status.checking,
  825. begin_time: time,
  826. });
  827. await transaction.insert(this.tableName, newAuditors);
  828. // 删除当前次审批流
  829. await transaction.delete(this.tableName, { cpid: change.id, times: change.times });
  830. // 回退数据
  831. await this.ctx.service.changeProjectHistory.returnHistory(transaction, change.id);
  832. await transaction.delete(this.ctx.service.changeProjectHistory.tableName, { cpid: change.id });
  833. // // 设置变更立项为审批中
  834. // await transaction.update(this.ctx.service.changeProject.tableName, {
  835. // id: change.id,
  836. // time: change.times - 1,
  837. // status: auditConst.status.checking,
  838. // });
  839. await transaction.commit();
  840. } catch (err) {
  841. await transaction.rollback();
  842. throw err;
  843. }
  844. }
  845. /**
  846. * 重新审批变更令
  847. * @param { string } cid - 查询的清单
  848. * @return {Promise<*>} - 可用的变更令列表
  849. */
  850. async checkRevise(change) {
  851. const time = new Date();
  852. // 初始化事务
  853. const transaction = await this.db.beginTransaction();
  854. let result = false;
  855. try {
  856. const pid = this.ctx.session.sessionProject.id;
  857. // 获取审核人列表
  858. const sql = 'SELECT `tid`, `cpid`, `aid`, `order` FROM ?? WHERE `cpid` = ? and `times` = ? GROUP BY `aid` ORDER BY `id` ASC';
  859. const sqlParam = [this.tableName, change.id, change.times];
  860. const auditors = await this.db.query(sql, sqlParam);
  861. // 添加到消息推送表
  862. const noticeContent = await this.getNoticeContent(pid, change.tid, change.id, this.ctx.session.sessionUser.accountId, '发起修订');
  863. const records = [];
  864. auditors.forEach(auditor => {
  865. records.push({
  866. pid,
  867. type: pushType.changeProject,
  868. uid: auditor.aid,
  869. status: auditConst.status.revise,
  870. content: noticeContent,
  871. });
  872. });
  873. await transaction.insert('zh_notice', records);
  874. // 获取当前次数审批人列表
  875. const auditList = await this.getAuditGroupByList(change.id, change.times);
  876. const lastAudit = await this.getLastAudit(change.id, change.times);
  877. const insert_audit_array = [];
  878. // 新增一个发起修订状态到审批流程中
  879. const revise_audit = {
  880. tid: change.tid,
  881. cpid: change.id,
  882. aid: change.uid,
  883. times: change.times,
  884. order: lastAudit.order + 1,
  885. status: auditConst.status.revise,
  886. begin_time: time,
  887. end_time: time,
  888. opinion: '',
  889. };
  890. insert_audit_array.push(revise_audit);
  891. // 新增新一次的审批人列表
  892. let order = 1;
  893. for (const al of auditList) {
  894. const insert_audit = {
  895. tid: change.tid,
  896. cpid: change.id,
  897. aid: al.aid,
  898. times: change.times + 1,
  899. order,
  900. status: auditConst.status.uncheck,
  901. };
  902. insert_audit_array.push(insert_audit);
  903. order++;
  904. }
  905. await transaction.insert(this.tableName, insert_audit_array);
  906. // 生成内容保存表至zh_change_history中,用于撤销修订回退
  907. const changeData = await transaction.get(this.ctx.service.changeProject.tableName, { id: change.id });
  908. await this.ctx.service.changeProjectHistory.saveHistory(transaction, changeData);
  909. // 设置变更立项修订状态
  910. await transaction.update(this.ctx.service.changeProject.tableName, {
  911. id: change.id,
  912. status: auditConst.status.revise,
  913. times: change.times + 1,
  914. });
  915. await transaction.commit();
  916. result = true;
  917. } catch (error) {
  918. console.log(error);
  919. await transaction.rollback();
  920. result = false;
  921. }
  922. return result;
  923. }
  924. /**
  925. * 撤销修订变更令
  926. * @param { string } cid - 查询的清单
  927. * @return {Promise<*>} - 可用的变更令列表
  928. */
  929. async cancelRevise(change) {
  930. const time = new Date();
  931. // 初始化事务
  932. const transaction = await this.db.beginTransaction();
  933. let result = false;
  934. try {
  935. const pid = this.ctx.session.sessionProject.id;
  936. // 获取审核人列表
  937. const sql = 'SELECT `tid`, `cpid`, `aid`, `order` FROM ?? WHERE `cpid` = ? and `times` = ? GROUP BY `aid` ORDER BY `id` ASC';
  938. const sqlParam = [this.tableName, change.id, change.times - 1];
  939. const auditors = await this.db.query(sql, sqlParam);
  940. // 添加到消息推送表
  941. const noticeContent = await this.getNoticeContent(pid, change.tid, change.id, this.ctx.session.sessionUser.accountId, '撤销修订');
  942. const records = [];
  943. auditors.forEach(auditor => {
  944. records.push({
  945. pid,
  946. type: pushType.changeProject,
  947. uid: auditor.aid,
  948. status: auditConst.status.cancelRevise,
  949. content: noticeContent,
  950. });
  951. });
  952. await transaction.insert('zh_notice', records);
  953. const lastAudit = await this.getLastAudit(change.id, change.times - 1);
  954. // 新增一个撤销修订状态到审批流程中
  955. const revise_audit = {
  956. tid: change.tid,
  957. cpid: change.id,
  958. aid: this.ctx.session.sessionUser.accountId,
  959. times: change.times - 1,
  960. order: lastAudit.order + 1,
  961. status: auditConst.status.cancelRevise,
  962. begin_time: time,
  963. end_time: time,
  964. opinion: '',
  965. };
  966. await transaction.insert(this.ctx.service.changeProjectAudit.tableName, revise_audit);
  967. await transaction.delete(this.ctx.service.changeProjectAudit.tableName, { cpid: change.id, times: change.times });
  968. await this.ctx.service.changeProjectHistory.returnHistory(transaction, change.id);
  969. await transaction.delete(this.ctx.service.changeProjectHistory.tableName, { cpid: change.id });
  970. await transaction.commit();
  971. result = true;
  972. } catch (error) {
  973. console.log(error);
  974. await transaction.rollback();
  975. result = false;
  976. }
  977. return result;
  978. }
  979. /**
  980. * 重新审批变更立项
  981. * @param { string } cid - 查询的清单
  982. * @return {Promise<*>} - 可用的变更令列表
  983. */
  984. async checkAgain(change) {
  985. // 初始化事务
  986. const time = new Date();
  987. const transaction = await this.db.beginTransaction();
  988. let result = false;
  989. try {
  990. // 获取终审
  991. const zsAudit = await this.getAuditorByStatus(change.id, auditConst.status.checked);
  992. const lastAudit = await this.getLastAudit(change.id, change.times);
  993. const insert_audit_array = [];
  994. // 新增2个审批状态到审批列表中
  995. insert_audit_array.push({
  996. tid: change.tid,
  997. cpid: change.id,
  998. aid: zsAudit.aid,
  999. times: zsAudit.times,
  1000. order: lastAudit.order + 1,
  1001. status: auditConst.status.checkAgain,
  1002. begin_time: time,
  1003. end_time: time,
  1004. opinion: '',
  1005. });
  1006. // 新增2个审批人到审批列表中
  1007. insert_audit_array.push({
  1008. tid: change.tid,
  1009. cpid: change.id,
  1010. aid: zsAudit.aid,
  1011. times: zsAudit.times,
  1012. order: lastAudit.order + 2,
  1013. status: auditConst.status.checking,
  1014. begin_time: time,
  1015. });
  1016. await transaction.insert(this.tableName, insert_audit_array);
  1017. // 设置变更令审批中
  1018. await transaction.update(this.ctx.service.changeProject.tableName, {
  1019. id: change.id,
  1020. status: auditConst.status.checking,
  1021. });
  1022. await transaction.commit();
  1023. result = true;
  1024. } catch (error) {
  1025. await transaction.rollback();
  1026. result = false;
  1027. }
  1028. return result;
  1029. }
  1030. }
  1031. return ChangeProjectAudit;
  1032. };