change_project_audit.js 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099
  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. const result = await this.db.query(sql, sqlParam);
  312. // 过滤result中存在重复cpid的值, 保留最新的一条
  313. const filterResult = [];
  314. const cpidArr = [];
  315. for (const r of result) {
  316. if (cpidArr.indexOf(r.cpid) === -1) {
  317. filterResult.push(r);
  318. cpidArr.push(r.cpid);
  319. }
  320. }
  321. return filterResult;
  322. }
  323. /**
  324. * 获取审核人审核的次数
  325. *
  326. * @param auditorId
  327. * @return {Promise<*>}
  328. */
  329. async getCountByChecked(auditorId) {
  330. return await this.db.count(this.tableName, { aid: auditorId, status: [auditConst.status.checked, auditConst.status.back, auditConst.status.checkNo] });
  331. }
  332. /**
  333. * 获取最近一次审批结束时间
  334. *
  335. * @param auditorId
  336. * @return {Promise<*>}
  337. */
  338. async getLastEndTimeByChecked(auditorId) {
  339. const sql = 'SELECT `end_time` FROM ?? WHERE `aid` = ? ' +
  340. 'AND `status` in (' + this.ctx.helper.getInArrStrSqlFilter([auditConst.status.checked, auditConst.status.back, auditConst.status.checkNo]) + ') ORDER BY `end_time` DESC';
  341. const sqlParam = [this.tableName, auditorId];
  342. const result = await this.db.queryOne(sql, sqlParam);
  343. return result ? result.end_time : null;
  344. }
  345. /**
  346. * 用于添加推送所需的content内容
  347. * @param {Number} pid 项目id
  348. * @param {Number} tid 台账id
  349. * @param {Number} cpId 立项书id
  350. * @param {Number} uid 审批人id
  351. */
  352. async getNoticeContent(pid, tid, cpId, uid, opinion = '') {
  353. const noticeSql = 'SELECT * FROM (SELECT ' +
  354. ' t.`id` As `tid`, ma.`cpid`, m.`code` as `c_code`, t.`name`, pa.`name` As `su_name`, pa.role As `su_role`' +
  355. ' FROM (SELECT * FROM ?? WHERE `id` = ? ) As t' +
  356. ' LEFT JOIN ?? As m On t.`id` = m.`tid` AND m.`id` = ?' +
  357. ' LEFT JOIN ?? As ma ON m.`id` = ma.`cpid`' +
  358. ' LEFT JOIN ?? As pa ON pa.`id` = ?' +
  359. ' WHERE t.`project_id` = ? ) as new_t GROUP BY new_t.`tid`';
  360. const noticeSqlParam = [this.ctx.service.tender.tableName, tid, this.ctx.service.changeProject.tableName, cpId, this.tableName, this.ctx.service.projectAccount.tableName, uid, pid];
  361. const content = await this.db.query(noticeSql, noticeSqlParam);
  362. if (content.length) {
  363. content[0].opinion = opinion;
  364. }
  365. return content.length ? JSON.stringify(content[0]) : '';
  366. }
  367. /**
  368. * 审批
  369. * @param {Number} cpId - 立项书id
  370. * @param {auditConst.status.checked|auditConst.status.checkNo} checkType - 审批结果
  371. * @param {Number} times - 第几次审批
  372. * @return {Promise<void>}
  373. */
  374. async check(cpId, checkData, times = 1) {
  375. if (checkData.checkType !== auditConst.status.checked && checkData.checkType !== auditConst.status.checkNo && checkData.checkType !== auditConst.status.back) {
  376. throw '提交数据错误';
  377. }
  378. const pid = this.ctx.session.sessionProject.id;
  379. switch (checkData.checkType) {
  380. case auditConst.status.checked:
  381. await this._checked(pid, cpId, checkData, times);
  382. break;
  383. case auditConst.status.back:
  384. await this._back(pid, cpId, checkData, times);
  385. break;
  386. case auditConst.status.checkNo:
  387. await this._checkNo(pid, cpId, checkData, times);
  388. break;
  389. default:
  390. throw '无效审批操作';
  391. }
  392. }
  393. async _checked(pid, cpId, checkData, times) {
  394. const time = new Date();
  395. // 整理当前流程审核人状态更新
  396. const audit = await this.getDataByCondition({ cpid: cpId, times, status: auditConst.status.checking });
  397. if (!audit) {
  398. throw '审核数据错误';
  399. }
  400. // 获取审核人列表
  401. const sql = 'SELECT `tid`, `cpid`, `aid`, `order` FROM ?? WHERE `cpid` = ? and `times` = ? GROUP BY `aid` ORDER BY `id` ASC';
  402. const sqlParam = [this.tableName, cpId, times];
  403. const auditors = await this.db.query(sql, sqlParam);
  404. const nextAudit = await this.getDataByCondition({ cpid: cpId, times, order: audit.order + 1 });
  405. const transaction = await this.db.beginTransaction();
  406. try {
  407. await transaction.update(this.tableName, { id: audit.id, status: checkData.checkType, opinion: checkData.opinion, end_time: time });
  408. await this.ctx.service.noticeAgain.stopNoticeAgain(transaction, this.tableName, audit.id);
  409. // 获取推送必要信息
  410. const noticeContent = await this.getNoticeContent(pid, audit.tid, cpId, audit.aid, checkData.opinion);
  411. // 添加推送
  412. const records = [{ pid, type: pushType.changeProject, uid: this.ctx.change.uid, status: auditConst.status.checked, content: noticeContent }];
  413. auditors.forEach(audit => {
  414. records.push({ pid, type: pushType.changeProject, uid: audit.aid, status: auditConst.status.checked, content: noticeContent });
  415. });
  416. await transaction.insert('zh_notice', records);
  417. // 无下一审核人表示,审核结束
  418. if (nextAudit) {
  419. // 流程至下一审批人
  420. await transaction.update(this.tableName, { id: nextAudit.id, status: auditConst.status.checking, begin_time: time });
  421. // 同步 期信息
  422. await transaction.update(this.ctx.service.changeProject.tableName, {
  423. id: cpId, status: auditConst.status.checking,
  424. });
  425. // 微信模板通知
  426. const wechatData = {
  427. type: 'project',
  428. status: wxConst.status.check,
  429. tips: wxConst.tips.check,
  430. code: this.ctx.session.sessionProject.code,
  431. c_name: this.ctx.change.name,
  432. };
  433. await this.ctx.helper.sendWechat(nextAudit.aid, smsTypeConst.const.BG, smsTypeConst.judge.approval.toString(), wxConst.template.change, wechatData);
  434. await this.ctx.service.noticeAgain.addNoticeAgain(transaction, smsTypeConst.const.BG, {
  435. pid: this.ctx.session.sessionProject.id,
  436. tid: this.ctx.tender.id,
  437. uid: nextAudit.aid,
  438. sp_type: 'change',
  439. sp_id: nextAudit.id,
  440. table_name: this.tableName,
  441. template: wxConst.template.change,
  442. wx_data: wechatData,
  443. });
  444. // 检查三方特殊推送
  445. await this.ctx.service.specMsg.addChangeProjectMsg(transaction, pid, this.ctx.change, pushOperate.change_project.flow);
  446. } else {
  447. // 本期结束
  448. // 生成截止本期数据 final数据
  449. // 同步 期信息
  450. await transaction.update(this.ctx.service.changeProject.tableName, {
  451. id: cpId, status: checkData.checkType,
  452. });
  453. // 微信模板通知
  454. const users = this._.uniq(this._.concat(this._.map(auditors, 'aid'), this.ctx.change.uid));
  455. const wechatData = {
  456. type: 'project',
  457. status: wxConst.status.success,
  458. tips: wxConst.tips.success,
  459. code: this.ctx.session.sessionProject.code,
  460. c_name: this.ctx.change.name,
  461. };
  462. await this.ctx.helper.sendWechat(users, smsTypeConst.const.BG, smsTypeConst.judge.result.toString(), wxConst.template.change, wechatData);
  463. // 检查三方特殊推送
  464. await this.ctx.service.specMsg.addChangeProjectMsg(transaction, pid, this.ctx.change, pushOperate.change_project.flow);
  465. await this.ctx.service.specMsg.addChangeProjectMsg(transaction, pid, this.ctx.change, pushOperate.change_project.checked);
  466. }
  467. await transaction.commit();
  468. } catch (err) {
  469. await transaction.rollback();
  470. throw err;
  471. }
  472. }
  473. async _back(pid, cpId, checkData, times) {
  474. const time = new Date();
  475. const changeData = await this.ctx.service.changeProject.getDataById(cpId);
  476. // 整理当前流程审核人状态更新
  477. const audit = await this.getDataByCondition({ cpid: cpId, times, status: auditConst.status.checking });
  478. if (!audit) {
  479. throw '审核数据错误';
  480. }
  481. // 需要剔除原报可能存在修订进入流程的情况
  482. // const sql = 'SELECT `tid`, `cpid`, `aid`, `order` FROM ?? WHERE `cpid` = ? and `times` = ? and `status` != ? AND `status` != ? GROUP BY `aid` ORDER BY `id` ASC';
  483. // const sqlParam = [this.tableName, cpId, times];
  484. // const auditors = await this.db.query(sql, sqlParam);
  485. const auditors = await this.getAuditGroupByList(cpId, times);
  486. let order = 1;
  487. const newAuditors = [];
  488. for (const a of auditors) {
  489. a.times = times + 1;
  490. a.order = order;
  491. a.status = auditConst.status.uncheck;
  492. order++;
  493. newAuditors.push({
  494. tid: this.ctx.tender.id,
  495. cpid: cpId,
  496. times: a.times,
  497. order: a.order,
  498. status: a.status,
  499. aid: a.aid,
  500. });
  501. }
  502. const transaction = await this.db.beginTransaction();
  503. try {
  504. await transaction.update(this.tableName, { id: audit.id, status: checkData.checkType, opinion: checkData.opinion, end_time: time });
  505. await this.ctx.service.noticeAgain.stopNoticeAgain(transaction, this.tableName, audit.id);
  506. // 添加到消息推送表
  507. const noticeContent = await this.getNoticeContent(pid, audit.tid, cpId, audit.aid, checkData.opinion);
  508. const records = [{ pid, type: pushType.changeProject, uid: this.ctx.change.uid, status: auditConst.status.back, content: noticeContent }];
  509. auditors.forEach(audit => {
  510. records.push({ pid, type: pushType.changeProject, uid: audit.aid, status: auditConst.status.back, content: noticeContent });
  511. });
  512. await transaction.insert(this.ctx.service.noticePush.tableName, records);
  513. // 同步期信息
  514. await transaction.update(this.ctx.service.changeProject.tableName, {
  515. id: cpId, status: checkData.checkType,
  516. times: times + 1,
  517. });
  518. // 拷贝新一次审核流程列表
  519. await transaction.insert(this.tableName, newAuditors);
  520. // 微信模板通知
  521. const users = this._.uniq(this._.concat(this._.map(auditors, 'aid'), this.ctx.change.uid));
  522. const wechatData = {
  523. type: 'project',
  524. status: wxConst.status.back,
  525. tips: wxConst.tips.back,
  526. code: this.ctx.session.sessionProject.code,
  527. c_name: this.ctx.change.name,
  528. };
  529. await this.ctx.helper.sendWechat(users, smsTypeConst.const.BG, smsTypeConst.judge.result.toString(), wxConst.template.change, wechatData);
  530. // 生成内容保存表至zh_change_project_history中,用于撤回
  531. await this.ctx.service.changeProjectHistory.saveHistory(transaction, changeData);
  532. // 检查三方特殊推送
  533. await this.ctx.service.specMsg.addChangeProjectMsg(transaction, pid, this.ctx.change, pushOperate.change_project.flow);
  534. await transaction.commit();
  535. } catch (err) {
  536. await transaction.rollback();
  537. throw err;
  538. }
  539. }
  540. async _checkNo(pid, cpId, checkData, times) {
  541. const time = new Date();
  542. // 整理当前流程审核人状态更新
  543. const audit = await this.getDataByCondition({ cpid: cpId, times, status: auditConst.status.checking });
  544. if (!audit) {
  545. throw '审核数据错误';
  546. }
  547. // 获取审核人列表
  548. const sql = 'SELECT `tid`, `cpid`, `aid`, `order` FROM ?? WHERE `cpid` = ? and `times` = ? GROUP BY `aid` ORDER BY `id` ASC';
  549. const sqlParam = [this.tableName, cpId, times];
  550. const auditors = await this.db.query(sql, sqlParam);
  551. const transaction = await this.db.beginTransaction();
  552. try {
  553. await transaction.update(this.tableName, { id: audit.id, status: checkData.checkType, opinion: checkData.opinion, end_time: time });
  554. await this.ctx.service.noticeAgain.stopNoticeAgain(transaction, this.tableName, audit.id);
  555. // 获取推送必要信息
  556. const noticeContent = await this.getNoticeContent(pid, audit.tid, cpId, audit.aid, checkData.opinion);
  557. // 添加推送
  558. const records = [{ pid, type: pushType.changeProject, uid: this.ctx.change.uid, status: auditConst.status.checkNo, content: noticeContent }];
  559. auditors.forEach(audit => {
  560. records.push({ pid, type: pushType.changeProject, uid: audit.aid, status: auditConst.status.checkNo, content: noticeContent });
  561. });
  562. await transaction.insert('zh_notice', records);
  563. // 本期结束
  564. // 生成截止本期数据 final数据
  565. // 同步 期信息
  566. await transaction.update(this.ctx.service.changeProject.tableName, {
  567. id: cpId, status: checkData.checkType,
  568. });
  569. // 微信模板通知
  570. const users = this._.uniq(this._.concat(this._.map(auditors, 'aid'), this.ctx.change.uid));
  571. const wechatData = {
  572. type: 'project',
  573. status: wxConst.status.stop,
  574. tips: wxConst.tips.stop,
  575. code: this.ctx.session.sessionProject.code,
  576. c_name: this.ctx.change.name,
  577. };
  578. await this.ctx.helper.sendWechat(users, smsTypeConst.const.BG, smsTypeConst.judge.result.toString(), wxConst.template.change, wechatData);
  579. // 检查三方特殊推送
  580. await this.ctx.service.specMsg.addChangeProjectMsg(transaction, pid, this.ctx.change, pushOperate.change_project.flow);
  581. await transaction.commit();
  582. } catch (err) {
  583. await transaction.rollback();
  584. throw err;
  585. }
  586. }
  587. /**
  588. * 复制上一期的审批人列表给最新一期
  589. *
  590. * @param transaction - 新增一期的事务
  591. * @param {Object} preMaterial - 上一期
  592. * @param {Object} newaMaterial - 最新一期
  593. * @return {Promise<*>}
  594. */
  595. async copyPreChangeProjectAuditors(transaction, preChange, newChange) {
  596. const auditors = await this.getAuditGroupByList(preChange.id, preChange.times);
  597. const newAuditors = [];
  598. for (const a of auditors) {
  599. const na = {
  600. tid: preChange.tid,
  601. cpid: newChange.id,
  602. aid: a.aid,
  603. times: newChange.times,
  604. order: newAuditors.length + 1,
  605. status: auditConst.status.uncheck,
  606. };
  607. newAuditors.push(na);
  608. }
  609. const result = newAuditors.length > 0 ? await transaction.insert(this.tableName, newAuditors) : null;
  610. return result ? result.affectedRows === auditors.length : true;
  611. }
  612. async getAllAuditors(tenderId) {
  613. const sql = 'SELECT ma.aid, ma.tid FROM ' + this.tableName + ' ma' +
  614. ' LEFT JOIN ' + this.ctx.service.tender.tableName + ' t On ma.tid = t.id' +
  615. ' WHERE t.id = ?' +
  616. ' GROUP BY ma.aid';
  617. const sqlParam = [tenderId];
  618. return this.db.query(sql, sqlParam);
  619. }
  620. /**
  621. * 审批撤回
  622. * @param {Number} stageId - 标段id
  623. * @param {Number} times - 第几次审批
  624. * @return {Promise<void>}
  625. */
  626. async checkCancel(change) {
  627. // 分4种情况,根据ctx.cancancel值判断:
  628. // 1.原报发起撤回,当前流程删除,并回到待上报
  629. // 2.审批人撤回审批通过,增加流程,并回到它审批中
  630. // 3.审批人撤回审批终止,增加流程,并回到它审批中,并更新立项状态为审批中
  631. // 4.审批人撤回退回原报操作,删除新增的审批流,增加流程,回滚到它审批中
  632. switch (change.cancancel) {
  633. case 1: await this._userCheckCancel(change); break;
  634. case 2: await this._auditCheckCancel(change); break;
  635. case 3: await this._auditCheckCancelStop(change); break;
  636. case 4: await this._auditCheckCancelNo(change); break;
  637. default: throw '不可撤回,请刷新页面重试';
  638. }
  639. }
  640. /**
  641. * 原报撤回,直接改动审批人状态
  642. * 如果存在审批人数据,将其改为原报流程数据,但保留原提交人
  643. *
  644. * 一审 1 A checking -> A uncheck status改 pay/jl:删0(jl为增量数据,只删重复部分) 1->0 删1
  645. * ...
  646. *
  647. * @param stage
  648. * @returns {Promise<void>}
  649. * @private
  650. */
  651. async _userCheckCancel(change) {
  652. const transaction = await this.db.beginTransaction();
  653. try {
  654. // 整理当前流程审核人状态更新
  655. const curAudit = await this.getDataByCondition({ cpid: change.id, times: change.times, status: auditConst.status.checking });
  656. // 审批人变成待审批状态
  657. await transaction.update(this.tableName, {
  658. id: curAudit.id,
  659. status: auditConst.status.uncheck,
  660. begin_time: null,
  661. opinion: null,
  662. });
  663. await this.ctx.service.noticeAgain.deleteNoticeAgain(transaction, this.tableName, curAudit.id);
  664. // 变成待上报状态
  665. await transaction.update(this.ctx.service.changeProject.tableName, {
  666. id: change.id,
  667. status: change.times === 1 ? auditConst.status.uncheck : auditConst.status.back,
  668. });
  669. await transaction.commit();
  670. } catch (err) {
  671. await transaction.rollback();
  672. throw err;
  673. }
  674. }
  675. /**
  676. * 审批人撤回审批通过,插入两条数据
  677. *
  678. * 一审 1 A checked 一审 1 A checked
  679. * 二审 2 B checked pre -> 二审 2 B checked
  680. * 三审 3 C checking cur 二审 3 B checkCancel 增 增extra_his 增tp_his
  681. * 四审 4 D uncheck 二审 4 B checking 增 增pay_cur
  682. * 三审 5 C uncheck order、status改
  683. * 四审 6 D uncheck order改
  684. *
  685. * @param stage
  686. * @returns {Promise<void>}
  687. * @private
  688. */
  689. async _auditCheckCancel(change) {
  690. const time = new Date();
  691. const transaction = await this.db.beginTransaction();
  692. try {
  693. // 整理当前流程审核人状态更新
  694. const curAudit = await this.getDataByCondition({ cpid: change.id, times: change.times, status: auditConst.status.checking });
  695. const preAudit = change.preAudit;
  696. if (!curAudit || curAudit.order <= 1 || !preAudit) {
  697. throw '撤回用户数据错误';
  698. }
  699. // 顺移其后审核人流程顺序
  700. const sql = 'UPDATE ' + this.tableName + ' SET `order` = `order` + 2 WHERE cpid = ? AND times = ? AND `order` > ?';
  701. await transaction.query(sql, [change.id, change.times, curAudit.order]);
  702. // 当前审批人2次添加至流程中
  703. const newAuditors = [];
  704. // 先入撤回记录
  705. newAuditors.push({
  706. tid: change.tid,
  707. cpid: change.id,
  708. aid: preAudit.aid,
  709. times: change.times,
  710. order: curAudit.order,
  711. status: auditConst.status.checkCancel,
  712. begin_time: time,
  713. end_time: time,
  714. opinion: '',
  715. });
  716. newAuditors.push({
  717. tid: change.tid,
  718. cpid: change.id,
  719. aid: preAudit.aid,
  720. times: change.times,
  721. order: curAudit.order + 1,
  722. status: auditConst.status.checking,
  723. begin_time: time,
  724. });
  725. await transaction.insert(this.tableName, newAuditors);
  726. // 当前审批人变成待审批
  727. await transaction.update(this.tableName, { id: curAudit.id, order: curAudit.order + 2, begin_time: null, status: auditConst.status.uncheck });
  728. await this.ctx.service.noticeAgain.deleteNoticeAgain(transaction, this.tableName, curAudit.id);
  729. await transaction.commit();
  730. } catch (err) {
  731. await transaction.rollback();
  732. throw err;
  733. }
  734. }
  735. /**
  736. * 审批人撤回审批终止,插入两条数据
  737. *
  738. * @param stage
  739. * @returns {Promise<void>}
  740. * @private
  741. */
  742. async _auditCheckCancelStop(change) {
  743. const time = new Date();
  744. const transaction = await this.db.beginTransaction();
  745. try {
  746. // const curAudit = await this.getDataByCondition({ cpid: change.id, times: change.times, status: auditConst.status.checkNo });
  747. const curAudit = await this.getAuditorByStatus(change.id, auditConst.status.checkNo);
  748. if (!curAudit) {
  749. throw '撤回用户数据错误';
  750. }
  751. // 顺移其后审核人流程顺序
  752. const sql = 'UPDATE ' + this.tableName + ' SET `order` = `order` + 2 WHERE cpid = ? AND times = ? AND `order` > ?';
  753. await transaction.query(sql, [change.id, change.times, curAudit.order]);
  754. // 当前审批人2次添加至流程中
  755. const newAuditors = [];
  756. // 先入撤回记录
  757. newAuditors.push({
  758. tid: change.tid,
  759. cpid: change.id,
  760. aid: curAudit.aid,
  761. times: change.times,
  762. order: curAudit.order + 1,
  763. status: auditConst.status.checkCancel,
  764. begin_time: time,
  765. end_time: time,
  766. opinion: '',
  767. });
  768. newAuditors.push({
  769. tid: change.tid,
  770. cpid: change.id,
  771. aid: curAudit.aid,
  772. times: change.times,
  773. order: curAudit.order + 2,
  774. status: auditConst.status.checking,
  775. begin_time: time,
  776. });
  777. await transaction.insert(this.tableName, newAuditors);
  778. await transaction.update(this.ctx.service.changeProject.tableName, {
  779. id: change.id,
  780. status: auditConst.status.checking,
  781. });
  782. await transaction.commit();
  783. } catch (err) {
  784. await transaction.rollback();
  785. throw err;
  786. }
  787. }
  788. /**
  789. * 审批人撤回审批退回原报
  790. *
  791. * 1# 一审 1 A checked 1# 一审 1 A checked
  792. * 二审 2 B checkNo pre -> 二审 2 B checkNo
  793. * 三审 3 C uncheck 二审 3 B checkCancel 增 pay: 2#0 -> 1#3 jl: 2#0 -> 1#3 增tp_his 增extra_his
  794. * 二审 4 B checking 增 pay: 2#0 -> 1#4
  795. * 三审 5 C uncheck order改
  796. *
  797. * 2# 一审 1 A uncheck 2# 删 pay: 2#0删 jl: 2#0删
  798. * 二审 2 B uncheck
  799. * 三审 3 C uncheck
  800. *
  801. * @param stage
  802. * @returns {Promise<void>}
  803. * @private
  804. */
  805. async _auditCheckCancelNo(change) {
  806. const time = new Date();
  807. const transaction = await this.db.beginTransaction();
  808. try {
  809. // const curAudit = await this.getDataByCondition({ cpid: change.id, times: change.times - 1, status: auditConst.status.back });
  810. const curAudit = await this.getAuditorByStatus(change.id, auditConst.status.back, change.times);
  811. // 整理上一个流程审核人状态更新
  812. // 顺移其后审核人流程顺序
  813. const sql = 'UPDATE ' + this.tableName + ' SET `order` = `order` + 2 WHERE cpid = ? AND times = ? AND `order` > ?';
  814. await transaction.query(sql, [change.id, change.times - 1, curAudit.order]);
  815. // 当前审批人2次添加至流程中
  816. const newAuditors = [];
  817. newAuditors.push({
  818. tid: change.tid,
  819. cpid: change.id,
  820. aid: curAudit.aid,
  821. times: curAudit.times,
  822. order: curAudit.order + 1,
  823. status: auditConst.status.checkCancel,
  824. begin_time: time,
  825. end_time: time,
  826. opinion: '',
  827. });
  828. newAuditors.push({
  829. tid: change.tid,
  830. cpid: change.id,
  831. aid: curAudit.aid,
  832. times: curAudit.times,
  833. order: curAudit.order + 2,
  834. status: auditConst.status.checking,
  835. begin_time: time,
  836. });
  837. await transaction.insert(this.tableName, newAuditors);
  838. // 删除当前次审批流
  839. await transaction.delete(this.tableName, { cpid: change.id, times: change.times });
  840. // 回退数据
  841. await this.ctx.service.changeProjectHistory.returnHistory(transaction, change.id);
  842. await transaction.delete(this.ctx.service.changeProjectHistory.tableName, { cpid: change.id });
  843. // // 设置变更立项为审批中
  844. // await transaction.update(this.ctx.service.changeProject.tableName, {
  845. // id: change.id,
  846. // time: change.times - 1,
  847. // status: auditConst.status.checking,
  848. // });
  849. await transaction.commit();
  850. } catch (err) {
  851. await transaction.rollback();
  852. throw err;
  853. }
  854. }
  855. /**
  856. * 重新审批变更令
  857. * @param { string } cid - 查询的清单
  858. * @return {Promise<*>} - 可用的变更令列表
  859. */
  860. async checkRevise(change) {
  861. const time = new Date();
  862. // 初始化事务
  863. const transaction = await this.db.beginTransaction();
  864. let result = false;
  865. try {
  866. const pid = this.ctx.session.sessionProject.id;
  867. // 获取审核人列表
  868. const sql = 'SELECT `tid`, `cpid`, `aid`, `order` FROM ?? WHERE `cpid` = ? and `times` = ? GROUP BY `aid` ORDER BY `id` ASC';
  869. const sqlParam = [this.tableName, change.id, change.times];
  870. const auditors = await this.db.query(sql, sqlParam);
  871. // 添加到消息推送表
  872. const noticeContent = await this.getNoticeContent(pid, change.tid, change.id, this.ctx.session.sessionUser.accountId, '发起修订');
  873. const records = [];
  874. auditors.forEach(auditor => {
  875. records.push({
  876. pid,
  877. type: pushType.changeProject,
  878. uid: auditor.aid,
  879. status: auditConst.status.revise,
  880. content: noticeContent,
  881. });
  882. });
  883. await transaction.insert('zh_notice', records);
  884. // 获取当前次数审批人列表
  885. const auditList = await this.getAuditGroupByList(change.id, change.times);
  886. const lastAudit = await this.getLastAudit(change.id, change.times);
  887. const insert_audit_array = [];
  888. // 新增一个发起修订状态到审批流程中
  889. const revise_audit = {
  890. tid: change.tid,
  891. cpid: change.id,
  892. aid: change.uid,
  893. times: change.times,
  894. order: lastAudit.order + 1,
  895. status: auditConst.status.revise,
  896. begin_time: time,
  897. end_time: time,
  898. opinion: '',
  899. };
  900. insert_audit_array.push(revise_audit);
  901. // 新增新一次的审批人列表
  902. let order = 1;
  903. for (const al of auditList) {
  904. const insert_audit = {
  905. tid: change.tid,
  906. cpid: change.id,
  907. aid: al.aid,
  908. times: change.times + 1,
  909. order,
  910. status: auditConst.status.uncheck,
  911. };
  912. insert_audit_array.push(insert_audit);
  913. order++;
  914. }
  915. await transaction.insert(this.tableName, insert_audit_array);
  916. // 生成内容保存表至zh_change_history中,用于撤销修订回退
  917. const changeData = await transaction.get(this.ctx.service.changeProject.tableName, { id: change.id });
  918. await this.ctx.service.changeProjectHistory.saveHistory(transaction, changeData);
  919. // 设置变更立项修订状态
  920. await transaction.update(this.ctx.service.changeProject.tableName, {
  921. id: change.id,
  922. status: auditConst.status.revise,
  923. times: change.times + 1,
  924. });
  925. await transaction.commit();
  926. result = true;
  927. } catch (error) {
  928. console.log(error);
  929. await transaction.rollback();
  930. result = false;
  931. }
  932. return result;
  933. }
  934. /**
  935. * 撤销修订变更令
  936. * @param { string } cid - 查询的清单
  937. * @return {Promise<*>} - 可用的变更令列表
  938. */
  939. async cancelRevise(change) {
  940. const time = new Date();
  941. // 初始化事务
  942. const transaction = await this.db.beginTransaction();
  943. let result = false;
  944. try {
  945. const pid = this.ctx.session.sessionProject.id;
  946. // 获取审核人列表
  947. const sql = 'SELECT `tid`, `cpid`, `aid`, `order` FROM ?? WHERE `cpid` = ? and `times` = ? GROUP BY `aid` ORDER BY `id` ASC';
  948. const sqlParam = [this.tableName, change.id, change.times - 1];
  949. const auditors = await this.db.query(sql, sqlParam);
  950. // 添加到消息推送表
  951. const noticeContent = await this.getNoticeContent(pid, change.tid, change.id, this.ctx.session.sessionUser.accountId, '撤销修订');
  952. const records = [];
  953. auditors.forEach(auditor => {
  954. records.push({
  955. pid,
  956. type: pushType.changeProject,
  957. uid: auditor.aid,
  958. status: auditConst.status.cancelRevise,
  959. content: noticeContent,
  960. });
  961. });
  962. await transaction.insert('zh_notice', records);
  963. const lastAudit = await this.getLastAudit(change.id, change.times - 1);
  964. // 新增一个撤销修订状态到审批流程中
  965. const revise_audit = {
  966. tid: change.tid,
  967. cpid: change.id,
  968. aid: this.ctx.session.sessionUser.accountId,
  969. times: change.times - 1,
  970. order: lastAudit.order + 1,
  971. status: auditConst.status.cancelRevise,
  972. begin_time: time,
  973. end_time: time,
  974. opinion: '',
  975. };
  976. await transaction.insert(this.ctx.service.changeProjectAudit.tableName, revise_audit);
  977. await transaction.delete(this.ctx.service.changeProjectAudit.tableName, { cpid: change.id, times: change.times });
  978. await this.ctx.service.changeProjectHistory.returnHistory(transaction, change.id);
  979. await transaction.delete(this.ctx.service.changeProjectHistory.tableName, { cpid: change.id });
  980. await transaction.commit();
  981. result = true;
  982. } catch (error) {
  983. console.log(error);
  984. await transaction.rollback();
  985. result = false;
  986. }
  987. return result;
  988. }
  989. /**
  990. * 重新审批变更立项
  991. * @param { string } cid - 查询的清单
  992. * @return {Promise<*>} - 可用的变更令列表
  993. */
  994. async checkAgain(change) {
  995. // 初始化事务
  996. const time = new Date();
  997. const transaction = await this.db.beginTransaction();
  998. let result = false;
  999. try {
  1000. // 获取终审
  1001. const zsAudit = await this.getAuditorByStatus(change.id, auditConst.status.checked);
  1002. const lastAudit = await this.getLastAudit(change.id, change.times);
  1003. const insert_audit_array = [];
  1004. // 新增2个审批状态到审批列表中
  1005. insert_audit_array.push({
  1006. tid: change.tid,
  1007. cpid: change.id,
  1008. aid: zsAudit.aid,
  1009. times: zsAudit.times,
  1010. order: lastAudit.order + 1,
  1011. status: auditConst.status.checkAgain,
  1012. begin_time: time,
  1013. end_time: time,
  1014. opinion: '',
  1015. });
  1016. // 新增2个审批人到审批列表中
  1017. insert_audit_array.push({
  1018. tid: change.tid,
  1019. cpid: change.id,
  1020. aid: zsAudit.aid,
  1021. times: zsAudit.times,
  1022. order: lastAudit.order + 2,
  1023. status: auditConst.status.checking,
  1024. begin_time: time,
  1025. });
  1026. await transaction.insert(this.tableName, insert_audit_array);
  1027. // 设置变更令审批中
  1028. await transaction.update(this.ctx.service.changeProject.tableName, {
  1029. id: change.id,
  1030. status: auditConst.status.checking,
  1031. });
  1032. await transaction.commit();
  1033. result = true;
  1034. } catch (error) {
  1035. await transaction.rollback();
  1036. result = false;
  1037. }
  1038. return result;
  1039. }
  1040. }
  1041. return ChangeProjectAudit;
  1042. };