change_audit.js 73 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date 2018/8/14
  7. * @version
  8. */
  9. const auditConst = require('../const/audit').change;
  10. const auditType = require('../const/audit').auditType;
  11. const pushType = require('../const/audit').pushType;
  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 ChangeAudit 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_audit';
  28. }
  29. /**
  30. * 获取最后一位审批人
  31. * @param {int} cid - 变更令id
  32. * @param {int} times - 次数
  33. * @param {int} site - 位置
  34. * @param {int} status - 状态
  35. * @return {void}
  36. */
  37. async getLastUser(cid, times, site = 1, status = 1) {
  38. this.initSqlBuilder();
  39. this.sqlBuilder.setAndWhere('cid', {
  40. value: this.db.escape(cid),
  41. operate: '=',
  42. });
  43. this.sqlBuilder.setAndWhere('times', {
  44. value: times,
  45. operate: '=',
  46. });
  47. if (status === 1) {
  48. this.sqlBuilder.setAndWhere('status', {
  49. value: 1,
  50. operate: '!=',
  51. });
  52. }
  53. if (site === 0) {
  54. this.sqlBuilder.setAndWhere('usite', {
  55. value: site,
  56. operate: '=',
  57. });
  58. }
  59. const u_sort = [['usort', 'DESC']];
  60. this.sqlBuilder.orderBy = u_sort;
  61. const [sql, sqlParam] = this.sqlBuilder.build(this.tableName);
  62. const data = await this.db.queryOne(sql, sqlParam);
  63. return data;
  64. }
  65. /**
  66. * 获取最后一位退回的审批人
  67. * @param {int} cid - 变更令id
  68. * @param {int} times - 次数
  69. * @return {void}
  70. */
  71. async getLastBackUser(cid, times) {
  72. this.initSqlBuilder();
  73. this.sqlBuilder.setAndWhere('cid', {
  74. value: this.db.escape(cid),
  75. operate: '=',
  76. });
  77. this.sqlBuilder.setAndWhere('times', {
  78. value: times,
  79. operate: '=',
  80. });
  81. this.sqlBuilder.setAndWhere('status', {
  82. value: auditConst.status.checkNoPre,
  83. operate: '=',
  84. });
  85. const u_sort = [['usort', 'DESC']];
  86. this.sqlBuilder.orderBy = u_sort;
  87. const [sql, sqlParam] = this.sqlBuilder.build(this.tableName);
  88. const data = await this.db.queryOne(sql, sqlParam);
  89. return data;
  90. }
  91. /**
  92. * 根据用户查看此变更状态获取审批人列表
  93. * @param {Object} change - 变更令
  94. * @param {int} status - 状态
  95. * @return {object} list - 列表
  96. */
  97. async getListByStatus(change, status) {
  98. let sql = '';
  99. let sqlParam = '';
  100. switch (status) {
  101. case 1:// 待上报
  102. case 2:// 待重新上报
  103. case 9:// 待修订
  104. sql = 'SELECT * FROM ?? WHERE ' +
  105. 'cid = ? AND times = ? GROUP BY usite ORDER BY usort asc';
  106. sqlParam = [this.tableName, change.cid,
  107. change.times];
  108. break;
  109. case 3: // 被退回但你不是原报人
  110. case 4:// 已完成
  111. case 5:// 已终止
  112. case 7:// 审批中但你未到你审批或你已审批
  113. case 8:// 游客
  114. // 获取完整的审批顺序
  115. sql = 'SELECT * FROM ?? WHERE ' +
  116. 'cid = ? ORDER BY usort';
  117. sqlParam = [this.tableName, change.cid];
  118. break;
  119. case 6: // 审批中
  120. sql = 'SELECT * FROM (SELECT MAX(usort) as ust FROM ?? ' +
  121. 'WHERE cid = ? and times = ? GROUP BY usite ) as b ' +
  122. 'JOIN ?? as a ON a.usort = b.ust WHERE cid = ? and times = ? ORDER BY usite asc';
  123. sqlParam = [this.tableName, change.cid, change.times, this.tableName, change.cid, change.times];
  124. // sql = 'SELECT * FROM ?? WHERE ' +
  125. // 'cid = ? AND times = ? ORDER BY usort';
  126. // sqlParam = [this.tableName, change.cid, change.times];
  127. break;
  128. default:// 无权限查看此变更令
  129. break;
  130. }
  131. const list = await this.db.query(sql, sqlParam);
  132. return list;
  133. }
  134. /**
  135. * 删除变更令审批人列表
  136. * @param {Object} transaction - 事务
  137. * @param {Object} cid - 变更令id
  138. * @param {int} times - 次数
  139. * @return {object} 返回结果
  140. */
  141. async deleteAuditData(transaction, cid, times) {
  142. this.initSqlBuilder();
  143. this.sqlBuilder.setAndWhere('cid', {
  144. value: this.db.escape(cid),
  145. operate: '=',
  146. });
  147. this.sqlBuilder.setAndWhere('times', {
  148. value: times,
  149. operate: '=',
  150. });
  151. this.sqlBuilder.setAndWhere('usite', {
  152. value: 0,
  153. operate: '!=',
  154. });
  155. const [sql, sqlParam] = this.sqlBuilder.build(this.tableName, 'delete');
  156. const result = await transaction.query(sql, sqlParam);
  157. return result;
  158. }
  159. /**
  160. * 获取不重复列表
  161. * @param {Object} cid - 变更令id
  162. * @param {int} times - 次数
  163. * @return {object} 返回结果
  164. */
  165. async getListGroupByTimes(cid, times) {
  166. const sql = 'SELECT * FROM ?? where id in (SELECT MAX(id) FROM ?? WHERE ' +
  167. 'cid = ? AND times = ? GROUP BY usite) ORDER BY usite asc';
  168. const sqlParam = [this.tableName, this.tableName, cid, times];
  169. const list = await this.db.query(sql, sqlParam);
  170. return list;
  171. }
  172. /**
  173. * 获取不重复列表
  174. * @param {Object} cid - 变更令id
  175. * @param {int} times - 次数
  176. * @return {object} 返回结果
  177. */
  178. async getListGroupByWithoutYB(cid, times, transaction = null) {
  179. const sql = 'SELECT * FROM ?? where cid = ? AND times = ? AND usite != 0 AND usort in (SELECT MAX(usort) FROM ?? WHERE ' +
  180. 'cid = ? AND times = ? AND usite != 0 GROUP BY usite) ORDER BY usite asc';
  181. const sqlParam = [this.tableName, cid, times, this.tableName, cid, times];
  182. const list = transaction ? await transaction.query(sql, sqlParam) : await this.db.query(sql, sqlParam);
  183. return list;
  184. }
  185. async getListOrderByTimes(cid, times) {
  186. const sql = 'SELECT * FROM ?? WHERE ' +
  187. 'cid = ? AND times = ? ORDER BY usort';
  188. const sqlParam = [this.tableName, cid, times];
  189. const list = await this.db.query(sql, sqlParam);
  190. return list;
  191. }
  192. async getListGroupByTimesWithDetail(cid, times) {
  193. const sql = 'SELECT *, pa.name, pa.company, pa.role, pa.mobile, pa.telephone FROM ' + this.tableName + ' ca ' +
  194. ' Left Join ' + this.ctx.service.projectAccount.tableName + ' pa On ca.uid = pa.id' +
  195. ' where id in (SELECT MAX(id) FROM ' + this.tableName +' WHERE cid = ? AND times = ? GROUP BY usite)' +
  196. ' ORDER BY usite asc';
  197. const sqlParam = [cid, times];
  198. const list = await this.db.query(sql, sqlParam);
  199. return list;
  200. }
  201. /**
  202. * 获取 审核人 待审批的() 变更令列表
  203. * @param uid
  204. * @return {Promise<void>}
  205. */
  206. async getAuditChange(uid) {
  207. // const sql = 'SELECT ca.`uid`, ca.`times`, ca.`usite`, ca.`usort`, ca.`tid`, ca.`cid`, ca.`begin_time`, ca.`end_time`, ca.`sin_time`, ca.`name` As `caname`, ' +
  208. // ' c.`code` As `ccode`, c.`name` As `cname`, c.`status` As `cstatus`, c.`cin_time`, ' +
  209. // ' t.`name`, t.`type`, t.`user_id` ' +
  210. // ' FROM ?? AS ca, ?? AS c, ?? As t ' +
  211. // ' WHERE ca.`uid` = ? and ca.`status` = ? and c.`status` != ?' +
  212. // ' and ca.`cid` = c.`cid` and ca.`tid` = t.`id` ORDER BY ca.`sin_time` DESC';
  213. const sql = 'SELECT ca.`uid`, ca.`times`, ca.`usite`, ca.`usort`, ca.`tid`, ca.`cid`, ca.`begin_time`, ca.`end_time`, ca.`sin_time`, ca.`name` As `caname`, ' +
  214. ' c.`code` As `ccode`, c.`name` As `cname`, c.`status` As `cstatus`, c.`cin_time`, ' +
  215. ' t.`name`, t.`type`, t.`user_id` ' +
  216. ' FROM ?? AS ca LEFT JOIN ?? AS c ON ca.`cid` = c.`cid` ' +
  217. ' LEFT JOIN ?? As t ON ca.`tid` = t.`id` ' +
  218. ' WHERE ca.`uid` = ? and ca.`status` = ? and c.`status` != ?' +
  219. ' ORDER BY ca.`begin_time` DESC';
  220. const sqlParam = [this.tableName, this.ctx.service.change.tableName, this.ctx.service.tender.tableName, uid, auditConst.status.checking, auditConst.status.uncheck];
  221. const changes = await this.db.query(sql, sqlParam);
  222. for (const c of changes) {
  223. if (c.cstatus === auditConst.status.checkNo || c.cstatus === auditConst.status.revise) {
  224. const preSql = 'SELECT pa.`id`, pa.`account`, pa.`account_group`, pa.`name`, pa.`company`, pa.`role`, pa.`telephone` FROM ?? As ca, ?? As pa ' +
  225. ' WHERE ca.cid = ? and ca.times = ? and ca.status = ? and ca.uid = pa.id';
  226. const preSqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, c.cid, c.times - 1, c.cstatus];
  227. c.pre = await this.db.queryOne(preSql, preSqlParam);
  228. } else {
  229. const preSql = 'SELECT pa.`id`, pa.`account`, pa.`account_group`, pa.`name`, pa.`company`, pa.`role`, pa.`telephone` FROM ?? As ca, ?? As pa ' +
  230. ' WHERE ca.cid = ? and ca.times = ? and ca.usort = ? and ca.uid = pa.id';
  231. const preSqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, c.cid, c.times, c.usort - 1];
  232. c.pre = await this.db.queryOne(preSql, preSqlParam);
  233. }
  234. }
  235. return changes;
  236. }
  237. /**
  238. * 获取审核人审核的次数
  239. *
  240. * @param auditorId
  241. * @return {Promise<*>}
  242. */
  243. async getCountByChecked(auditorId) {
  244. const sql = 'Select count(*) as count FROM ?? WHERE uid = ? AND usite != 0 AND status in (' + this.ctx.helper.getInArrStrSqlFilter([auditConst.status.checked, auditConst.status.checkNo, auditConst.status.checkNoPre]) +')';
  245. const sqlParam = [this.tableName, auditorId];
  246. const result = await this.db.queryOne(sql, sqlParam);
  247. return result.count ? result.count : 0;
  248. // return await this.db.count(this.tableName, { aid: auditorId, status: [auditConst.status.checked, auditConst.status.checkNo] });
  249. }
  250. /**
  251. * 获取最近一次审批结束时间
  252. *
  253. * @param auditorId
  254. * @return {Promise<*>}
  255. */
  256. async getLastEndTimeByChecked(auditorId) {
  257. const sql = 'SELECT `sin_time` FROM ?? WHERE `uid` = ? AND usite != 0 ' +
  258. 'AND `status` in (' + this.ctx.helper.getInArrStrSqlFilter([auditConst.status.checked, auditConst.status.checkNo, auditConst.status.checkNoPre]) + ') ORDER BY `sin_time` DESC';
  259. const sqlParam = [this.tableName, auditorId];
  260. const result = await this.db.queryOne(sql, sqlParam);
  261. return result ? result.sin_time : null;
  262. }
  263. /**
  264. * 获取 某时间后 审批进度更新的 变更令
  265. * @param {Number} pid - 查询标段
  266. * @param {Number} uid - 查询人
  267. * @param {Date} time - 查询时间
  268. * @return {Promise<*>}
  269. */
  270. async getNoticeChange(pid, uid, time) {
  271. // const sql = 'SELECT * FROM (SELECT t.`id`, t.`name`, t.`type`, t.`user_id`, ' +
  272. // ' ca.`cid`, c.`code` As `c_code`, c.name As `c_name`, ' +
  273. // ' ca.`uid`, ca.`sin_time` As `cu_time`, ca.`status` As `cu_status`, ca.`name` As `cu_name`, ca.`jobs` As `cu_jobs`, ca.company As `cu_company`' +
  274. // ' FROM (SELECT * FROM ?? WHERE `user_id` = ? OR `id` in (SELECT `tid` FROM ?? WHERE `uid` = ? GROUP BY `tid`)) As t' +
  275. // ' LEFT JOIN ?? As c ON c.`tid` = t.`id`' +
  276. // ' LEFT JOIN ?? As ca ON ca.`cid` = c.`cid`' +
  277. // ' WHERE t.`project_id` = ? and `ca`.`sin_time` > ? and `ca`.`usite` != 0 and `ca`.`status` != ?' +
  278. // ' ORDER By ca.`sin_time` DESC LIMIT 1000) as new_t GROUP BY new_t.`id`' +
  279. // ' ORDER BY new_t.`cu_time`';
  280. // const sqlParam = [this.ctx.service.tender.tableName, uid, this.tableName, uid, this.ctx.service.change.tableName, this.tableName, pid, time, auditConst.status.checking];
  281. // return await this.db.query(sql, sqlParam);
  282. let notice = await this.db.select('zh_notice', {
  283. where: { pid, type: pushType.change, uid },
  284. orders: [['create_time', 'desc']],
  285. limit: 10, offset: 0,
  286. });
  287. notice = notice.map(v => {
  288. const extra = JSON.parse(v.content);
  289. delete v.content;
  290. return { ...v, ...extra };
  291. });
  292. return notice;
  293. }
  294. async getAllAuditors(tenderId) {
  295. const sql = 'SELECT ca.uid, ca.tid FROM ' + this.tableName + ' ca' +
  296. ' LEFT JOIN ' + this.ctx.service.tender.tableName + ' t On ca.tid = t.id' +
  297. ' WHERE t.id = ?' +
  298. ' GROUP BY ca.uid';
  299. const sqlParam = [tenderId];
  300. return this.db.query(sql, sqlParam);
  301. }
  302. /**
  303. * 取待审批变更列表(wap用)
  304. *
  305. * @param auditorId
  306. * @return {Promise<*>}
  307. */
  308. async getAuditChangeByWap(uid) {
  309. const sql = 'SELECT ca.`uid`, ca.`times`, ca.`usite`, ca.`usort`, ca.`tid`, ca.`cid`, ca.`sin_time`, ca.`name` As `caname`, ' +
  310. ' c.`code` As `ccode`, c.`name` As `cname`, c.`status` As `cstatus`, c.`quality`, c.`total_price`,' +
  311. ' t.`name`, t.`type`, t.`user_id`, ' +
  312. ' ti.`deal_info`, ti.`decimal` ' +
  313. ' FROM ?? AS ca, ?? AS c, ?? As t, ?? AS ti ' +
  314. ' WHERE ca.`uid` = ? and ca.`status` = ? and (c.`status` = ? or c.`status` = ?)' +
  315. ' and ca.`cid` = c.`cid` and ca.`tid` = t.`id` and ti.`tid` = t.`id`';
  316. const sqlParam = [this.tableName, this.ctx.service.change.tableName, this.ctx.service.tender.tableName, this.ctx.service.tenderInfo.tableName, uid, auditConst.status.checking, auditConst.status.checking, auditConst.status.checkNoPre];
  317. const changes = await this.db.query(sql, sqlParam);
  318. for (const c of changes) {
  319. const preSql = 'SELECT pa.`id`, pa.`account`, pa.`account_group`, pa.`name`, pa.`company`, pa.`role`, pa.`telephone` FROM ?? As ca, ?? As pa ' +
  320. ' WHERE ca.cid = ? and ca.times = ? and ca.usort = ? and ca.uid = pa.id';
  321. const preSqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, c.cid, c.times, c.usort - 1];
  322. c.pre = await this.db.queryOne(preSql, preSqlParam);
  323. }
  324. return await this.db.query(sql, sqlParam);
  325. }
  326. async updateNewAuditList(change, newList) {
  327. const transaction = await this.db.beginTransaction();
  328. try {
  329. await this.updateNewAuditors(change, newList, transaction);
  330. await transaction.commit();
  331. } catch (err) {
  332. await transaction.rollback();
  333. throw err;
  334. }
  335. }
  336. async updateNewAuditors(change, newList, transaction) {
  337. // 先删除旧的审批流(除了原报),再添加新的
  338. const sql = 'DELETE FROM ?? WHERE `cid`= ? AND `times` = ? AND `usite` != 0';
  339. const sqlParam = [this.tableName, change.cid, change.times];
  340. await transaction.query(sql, sqlParam);
  341. const newAuditors = [];
  342. // let uSort = await transaction.count(this.tableName, { cid: change.cid });
  343. // let last_order = 0;
  344. for (const auditor of newList) {
  345. const accountInfo = await this.ctx.service.projectAccount.getDataById(auditor.audit_id);
  346. newAuditors.push({
  347. tid: change.tid, cid: change.cid, uid: auditor.audit_id,
  348. name: accountInfo.name, jobs: accountInfo.role, company: accountInfo.company,
  349. times: change.times, usite: auditor.audit_order, usort: auditor.audit_order, status: auditConst.status.uncheck,
  350. audit_type: auditor.audit_type, audit_order: auditor.audit_order,
  351. });
  352. // if (auditor.audit_order !== last_order) {
  353. // last_order = auditor.audit_order;
  354. // uSort++;
  355. // }
  356. }
  357. if (newAuditors.length > 0) await transaction.insert(this.tableName, newAuditors);
  358. // 同步设置原报为usort为0
  359. await transaction.update(this.tableName, { usort: 0 }, { where: { cid: change.cid, times: change.times, usite: 0 } });
  360. }
  361. async updateLastAudit(change, auditList, lastId) {
  362. const transaction = await this.db.beginTransaction();
  363. try {
  364. // 先判断auditList里的aid是否与lastId相同,相同则删除并重新更新order
  365. const existAudit = auditList.find(x => { return x.uid === lastId && x.usite !== 0 });
  366. let order = auditList.length > 0 ? auditList.reduce((rst, a) => { return Math.max(rst, a.usort)}, 0) + 1 : 1; // 最大值 + 1
  367. let audit_order = auditList.length > 0 ? auditList.reduce((rst, a) => { return Math.max(rst, a.audit_order)}, 0) + 1 : 1; // 最大值 + 1
  368. if (existAudit) {
  369. await transaction.delete(this.tableName, { cid: change.cid, times: change.times, uid: lastId });
  370. const sameOrder = auditList.filter(x => { return x.usort === existAudit.usort });
  371. if (sameOrder.length === 1) {
  372. const updateData = [];
  373. auditList.forEach(x => {
  374. if (x.usort <= existAudit.usort) return;
  375. updateData.push({id: x.id, usite: x.usite - 1, usort: x.usort - 1, audit_order: x.audit_order - 1});
  376. });
  377. if (updateData.length > 0) {
  378. await transaction.updateRows(updateData);
  379. }
  380. order = order - 1;
  381. audit_order = audit_order - 1;
  382. }
  383. // const sql = 'DELETE FROM ?? WHERE `cid`= ? AND `times` = ? AND `uid` = ? AND `usite` != 0';
  384. // const sqlParam = [this.tableName, change.cid, change.times, lastId];
  385. // await transaction.query(sql, sqlParam);
  386. // // await transaction.delete(this.tableName, { cid: change.cid, times: change.times, uid: lastId, usite: 0 });
  387. // const user = this._.find(auditList, { 'uid': lastId });
  388. // // 顺移之后审核人流程顺序
  389. // await this._syncOrderByDelete(transaction, change.cid, user.usite, user.usort, change.times);
  390. // order = order - 1;
  391. }
  392. // 添加终审
  393. const userInfo = await this.ctx.service.projectAccount.getDataById(lastId);
  394. // let uSort = await transaction.count(this.tableName, { cid: change.cid });
  395. const newAuditor = {
  396. tid: change.tid, cid: change.cid, uid: lastId,
  397. name: userInfo.name, jobs: userInfo.role, company: userInfo.company,
  398. times: change.times, usite: audit_order, usort: order, status: auditConst.status.uncheck,
  399. audit_type: auditType.key.common, audit_order,
  400. };
  401. await transaction.insert(this.tableName, newAuditor);
  402. await transaction.commit();
  403. } catch (err) {
  404. await transaction.rollback();
  405. throw err;
  406. }
  407. }
  408. /**
  409. * 移除审核人时,同步其后审核人order
  410. * @param transaction - 事务
  411. * @param {Number} changeId - 变更令id
  412. * @param {Number} usite - 审核人id
  413. * @param {Number} usort - 审核人id
  414. * @param {Number} times - 第几次审批
  415. * @return {Promise<*>}
  416. * @private
  417. */
  418. async _syncOrderByDelete(transaction, changeId, usite, usort, times, selfOperate = '-') {
  419. this.initSqlBuilder();
  420. this.sqlBuilder.setAndWhere('cid', {
  421. value: this.db.escape(changeId),
  422. operate: '=',
  423. });
  424. this.sqlBuilder.setAndWhere('usite', {
  425. value: usite,
  426. operate: '>=',
  427. });
  428. this.sqlBuilder.setAndWhere('times', {
  429. value: times,
  430. operate: '=',
  431. });
  432. this.sqlBuilder.setUpdateData('usite', {
  433. value: 1,
  434. selfOperate: selfOperate,
  435. });
  436. this.sqlBuilder.setUpdateData('usort', {
  437. value: 1,
  438. selfOperate: selfOperate,
  439. });
  440. this.sqlBuilder.setUpdateData('audit_order', {
  441. value: 1,
  442. selfOperate: selfOperate,
  443. });
  444. const [sql, sqlParam] = this.sqlBuilder.build(this.tableName, 'update');
  445. const data = await transaction.query(sql, sqlParam);
  446. return data;
  447. }
  448. /**
  449. * 获取 当前审核人
  450. *
  451. * @param {Number} cid - 期id
  452. * @param {Number} times - 第几次审批
  453. * @return {Promise<*>}
  454. */
  455. async getCurAuditor(cid, times = 1) {
  456. const sql = 'SELECT * FROM ?? WHERE `cid` = ? and `status` = ? and `times` = ? and usite != 0';
  457. const sqlParam = [this.tableName, cid, auditConst.status.checking, times];
  458. return await this.db.queryOne(sql, sqlParam);
  459. }
  460. /**
  461. * 获取 当前审核组
  462. *
  463. * @param {Number} cid - 期id
  464. * @param {Number} times - 第几次审批
  465. * @return {Promise<*>}
  466. */
  467. async getCurAuditors(cid, times = 1) {
  468. const sql = 'SELECT * FROM ?? WHERE `cid` = ? and `status` = ? and `times` = ? and usite != 0';
  469. const sqlParam = [this.tableName, cid, auditConst.status.checking, times];
  470. return await this.db.query(sql, sqlParam);
  471. }
  472. /**
  473. * 获取 审核人列表(除去原报)
  474. *
  475. * @param {Number} cid - 变更id
  476. * @param {Number} times - 第几次审批
  477. * @param {Boolean} includeOR - 是否包含原报
  478. * @return {Promise<*>}
  479. */
  480. async getAuditors(cid, times = 1, includeOR = false) {
  481. const sql = `SELECT * FROM ?? WHERE cid = ? and times = ?${includeOR ? '' : ' and usite != 0'}`;
  482. // const sql = 'SELECT * FROM ?? WHERE `cid` = ? and `times` = ? and usite != 0';
  483. const sqlParam = [this.tableName, cid, times];
  484. return await this.db.query(sql, sqlParam);
  485. }
  486. /**
  487. * new* 获取 审核列表信息(除去原报)
  488. *
  489. * @param {Number} stageId - 期id
  490. * @param {Number} times - 第几次审批
  491. * @param {Number} order_sort - 列表排序方式
  492. * @return {Promise<*>}
  493. */
  494. async getAuditorsNew(cid, times = 1, order_sort = 'asc') {
  495. const sql = 'SELECT la.id, la.uid, la.times, la.usite, la.usort, la.status, la.sdesc, la.begin_time, la.end_time, la.sin_time, la.audit_type, la.audit_order,' +
  496. ' pa.name, pa.company, pa.role, pa.mobile, pa.telephone' +
  497. ` FROM ${this.tableName} la LEFT JOIN ${this.ctx.service.projectAccount.tableName} pa ON la.uid = pa.id` +
  498. ' WHERE la.cid = ? AND la.times = ?' +
  499. ' ORDER BY la.usort ' + order_sort;
  500. const sqlParam = [cid, times];
  501. const result = await this.db.query(sql, sqlParam);
  502. const max_sort = this._.max(result.map(x => { return x.audit_order; }));
  503. for (const i in result) {
  504. result[i].max_sort = max_sort;
  505. }
  506. return result;
  507. }
  508. async getAuditorGroup(cid, times) {
  509. const auditors = await this.getAuditorsNew(cid, times); // 全部参与的审批人
  510. return this.ctx.helper.groupAuditors(auditors, 'usort');
  511. }
  512. async getUserGroup(cid, times) {
  513. const group = await this.getAuditorGroup(cid, times);
  514. // const sql =
  515. // 'SELECT pa.`id` As aid, pa.`name`, pa.`company`, pa.`role`, ? As times, ? As sid, 0 As `order`, 1 As audit_type, 0 As audit_order' +
  516. // ' FROM ' + this.ctx.service.change.tableName + ' As s' +
  517. // ' LEFT JOIN ' + this.ctx.service.projectAccount.tableName + ' As pa' +
  518. // ' ON s.user_id = pa.id' +
  519. // ' WHERE s.id = ?';
  520. // const sqlParam = [times, stageId, stageId];
  521. // const user = await this.db.queryOne(sql, sqlParam);
  522. // group.unshift([ user ]);
  523. return group;
  524. }
  525. async getUniqUserGroup(cid, times) {
  526. const group = await this.getAuditorGroup(cid, times);
  527. // const sql =
  528. // 'SELECT pa.`id` As aid, pa.`name`, pa.`company`, pa.`role`, ? As times, ? As sid, 0 As `order`, 1 As audit_type, 0 As audit_order' +
  529. // ' FROM ' + this.ctx.service.stage.tableName + ' As s' +
  530. // ' LEFT JOIN ' + this.ctx.service.projectAccount.tableName + ' As pa' +
  531. // ' ON s.user_id = pa.id' +
  532. // ' WHERE s.id = ?';
  533. // const sqlParam = [times, stageId, stageId];
  534. // const user = await this.db.queryOne(sql, sqlParam);
  535. // user.audit_order = 0;
  536. // group.unshift([ user ]);
  537. return this.ctx.helper.groupAuditorsUniq(group);
  538. }
  539. async getUniqAuditor(cid, times) {
  540. const auditors = await this.getAuditorsNew(cid, times); // 全部参与的审批人
  541. const result = [];
  542. auditors.forEach(x => {
  543. if (result.findIndex(r => { return x.uid === r.uid && x.audit_order === r.audit_order; }) < 0) {
  544. result.push(x);
  545. }
  546. });
  547. return result;
  548. }
  549. async getAuditorHistory(cid, times, reverse = false) {
  550. const history = [];
  551. if (times >= 1) {
  552. for (let i = 1; i <= times; i++) {
  553. const auditors = await this.getAuditorsNew(cid, i);
  554. const group = this.ctx.helper.groupAuditors(auditors, 'usort');
  555. const historyGroup = [];
  556. // 找出group里audit_order最大值
  557. const max_info = group.length > 0 ? this._.maxBy(group, function (item) {
  558. return item && item[0] && item[0].audit_order;
  559. }) : null;
  560. const max_order = max_info ? max_info[0].audit_order : -1;
  561. for (const g of group) {
  562. const his = {
  563. beginYear: '', beginDate: '', beginTime: '', endYear: '', endDate: '', endTime: '', begin_time: null, end_time: null,
  564. audit_type: g[0].audit_type, audit_order: g[0].audit_order,
  565. auditors: g
  566. };
  567. if (his.audit_type === auditType.key.common) {
  568. his.name = g[0].name;
  569. } else {
  570. his.name = this.ctx.helper.transFormToChinese(his.audit_order) + '审';
  571. }
  572. his.is_final = his.audit_order === max_order;
  573. if (g[0].begin_time) {
  574. his.begin_time = g[0].begin_time;
  575. const beginTime = this.ctx.moment(g[0].begin_time);
  576. his.beginYear = beginTime.format('YYYY');
  577. his.beginDate = beginTime.format('MM-DD');
  578. his.beginTime = beginTime.format('HH:mm:ss');
  579. }
  580. let end_time;
  581. g.forEach(x => {
  582. if (x.status === auditConst.status.checkSkip) return;
  583. if (!his.status || x.status === auditConst.status.checking) his.status = x.status;
  584. if (x.end_time && (!end_time || x.end_time > end_time)) {
  585. end_time = x.end_time;
  586. if (his.status !== auditConst.status.checking) his.status = x.status;
  587. }
  588. });
  589. if (end_time) {
  590. his.end_time = end_time;
  591. const endTime = this.ctx.moment(end_time);
  592. his.endYear = endTime.format('YYYY');
  593. his.endDate = endTime.format('MM-DD');
  594. his.endTime = endTime.format('HH:mm:ss');
  595. }
  596. historyGroup.push(his);
  597. }
  598. if (reverse) {
  599. history.push(historyGroup.reverse());
  600. } else {
  601. history.push(historyGroup);
  602. }
  603. }
  604. }
  605. return history;
  606. }
  607. /**
  608. * 获取审核人流程列表(除去原报)
  609. *
  610. * @param auditorId
  611. * @return {Promise<*>}
  612. */
  613. async getAuditGroupByList(cid, times, transaction = false) {
  614. // const sql =
  615. // 'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`sid`, la.`aid`, la.`order`, la.`status`' +
  616. // ' FROM ?? AS la Left Join ?? AS pa On la.`aid` = pa.`id` ' +
  617. // ' WHERE la.`sid` = ? and la.`times` = ? and la.`is_old` = 0 GROUP BY la.`aid` ORDER BY la.`order`';
  618. // const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, stageId, times];
  619. const sql =
  620. 'SELECT la.`uid`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`cid`, la.`usite`, la.`usort`, la.`status`, la.audit_type, la.audit_order' +
  621. ' FROM (SELECT `uid`, max(`usort`) `usort` FROM ?? WHERE `cid` = ? and `times` = ? and `usite` != 0 GROUP BY uid) sa' +
  622. ' LEFT JOIN ?? la ON sa.`uid` = la.`uid` AND sa.`usort` = la.`usort`' +
  623. ' Left JOIN ?? AS pa On la.`uid` = pa.`id` WHERE la.`cid` = ? and la.`times` = ? and la.`usite` != 0 order BY la.`usort`';
  624. const sqlParam = [this.tableName, cid, times, this.tableName, this.ctx.service.projectAccount.tableName, cid, times];
  625. return transaction !== false ? await transaction.query(sql, sqlParam) : await this.db.query(sql, sqlParam);
  626. }
  627. /**
  628. * 新增审核人
  629. *
  630. * @param {Number} cid - 变更令id
  631. * @param {Number} auditorId - 审核人id
  632. * @param {Number} times - 第几次审批
  633. * @return {Promise<number>}
  634. */
  635. async addAuditor(cid, auditorId, times = 1, is_gdzs = 0) {
  636. const transaction = await this.db.beginTransaction();
  637. try {
  638. let [uSort, newAuditOrder] = await this.getNewOrder(cid, times);
  639. // let newOrder = await transaction.count(this.tableName, { cid, times });
  640. // let uSort = await transaction.count(this.tableName, { cid });
  641. // 判断是否存在固定终审,存在则newOrder - 1并使终审order+1
  642. uSort = is_gdzs === 1 ? uSort - 1 : uSort;
  643. newAuditOrder = is_gdzs === 1 ? newAuditOrder - 1 : newAuditOrder;
  644. if (is_gdzs) await this._syncOrderByDelete(transaction, cid, newAuditOrder, uSort, times, '+');
  645. const userInfo = await this.ctx.service.projectAccount.getDataById(auditorId);
  646. const newAuditor = {
  647. tid: this.ctx.tender.id, cid: cid, uid: auditorId,
  648. name: userInfo.name, jobs: userInfo.role, company: userInfo.company,
  649. times: times, usite: newAuditOrder, usort: uSort, status: auditConst.status.uncheck,
  650. audit_order: newAuditOrder,
  651. };
  652. const result = await transaction.insert(this.tableName, newAuditor);
  653. await transaction.commit();
  654. return result.effectRows = 1;
  655. } catch (err) {
  656. await transaction.rollback();
  657. throw err;
  658. }
  659. return false;
  660. }
  661. /**
  662. * 获取 最新审核顺序
  663. *
  664. * @param {Number} cid - 变更id
  665. * @param {Number} times - 第几次审批
  666. * @return {Promise<number>}
  667. */
  668. async getNewOrder(cid, times = 1) {
  669. const sql = 'SELECT Max(`usort`) As max_order, Max(audit_order) As max_audit_order FROM ' + this.tableName + ' Where `cid` = ? and `times` = ?';
  670. const sqlParam = [cid, times];
  671. const result = await this.db.queryOne(sql, sqlParam);
  672. return result && result.max_order ? [result.max_order + 1, result.max_audit_order + 1] : [1, 1];
  673. }
  674. /**
  675. * 移除审核人
  676. *
  677. * @param {Number} cid - 变更令id
  678. * @param {Number} auditorId - 审核人id
  679. * @param {Number} times - 第几次审批
  680. * @return {Promise<boolean>}
  681. */
  682. async deleteAuditor(cid, auditorId, times = 1) {
  683. const transaction = await this.db.beginTransaction();
  684. try {
  685. const sql = 'SELECT * FROM ?? WHERE `cid` = ? and `times` = ? and `uid` = ? and `usite` != 0 ORDER BY `usort` DESC';
  686. const sqlParam = [this.tableName, cid, times, auditorId];
  687. const auditor = await transaction.queryOne(sql, sqlParam);
  688. if (!auditor) {
  689. throw '该审核人不存在';
  690. }
  691. // 移除整个流程的人
  692. await transaction.delete(this.tableName, { cid, times, usite: auditor.usite });
  693. await this._syncOrderByDelete(transaction, cid, auditor.usite, auditor.usort, times);
  694. await transaction.commit();
  695. } catch (err) {
  696. await transaction.rollback();
  697. throw err;
  698. }
  699. return true;
  700. }
  701. async changeSpGroup(change, sp_group) {
  702. const transaction = await this.db.beginTransaction();
  703. try {
  704. const group = await this.ctx.service.shenpiGroup.getDataById(sp_group);
  705. if (!group) {
  706. throw '该固定审批组不存在,请刷新页面重新获取';
  707. }
  708. const shenpiList = await this.ctx.service.shenpiAudit.getAllDataByCondition({ where: { tid: this.ctx.tender.id, sp_type: shenpiConst.sp_type.change, sp_status: shenpiConst.sp_status.gdspl, sp_group: group.id } });
  709. await this.updateNewAuditors(change, shenpiList, transaction);
  710. await transaction.update(this.ctx.service.change.tableName, { sp_group: group.id }, { where: { cid: change.cid } });
  711. await transaction.commit();
  712. } catch (err) {
  713. await transaction.rollback();
  714. throw err;
  715. }
  716. return true;
  717. }
  718. /**
  719. * 开始审批
  720. * @param {Number} cid - 变更令id
  721. * @param {Number} times - 第几次审批
  722. * @return {Promise<boolean>}
  723. */
  724. async start(cid, times = 1) {
  725. const audits = await this.getAllDataByCondition({ where: { cid, times, usite: 1 } });
  726. const yBAudit = await this.getDataByCondition({ cid, times, usite: 0 });
  727. if (audits.length === 0) {
  728. if(this.ctx.tender.info.shenpi.change === shenpiConst.sp_status.gdspl) {
  729. throw '请联系管理员添加审批人';
  730. } else {
  731. throw '请先选择审批人,再上报数据';
  732. }
  733. }
  734. const transaction = await this.db.beginTransaction();
  735. try {
  736. const begin_time = new Date();
  737. const updateUserData = audits.map(x => { return { id: x.id, status: auditConst.status.checking, begin_time, sin_time: begin_time } });
  738. await transaction.updateRows(this.tableName, updateUserData);
  739. // 更新原报人审批状态
  740. await transaction.update(this.tableName, {
  741. id: yBAudit.id,
  742. status: auditConst.status.checked,
  743. sin_time: begin_time,
  744. end_time: begin_time,
  745. });
  746. const changeList = await this.ctx.service.changeAuditList.getList(cid);
  747. let total_price = 0;
  748. // 更新清单spamount的值
  749. const updateListData = [];
  750. for (const cl of changeList) {
  751. total_price = this.ctx.helper.accAdd(total_price, this.ctx.helper.mul(cl.unit_price, cl.camount, this.ctx.tender.info.decimal.tp));
  752. if(cl.camount !== cl.spamount) {
  753. const uld = {
  754. id: cl.id,
  755. spamount: cl.camount,
  756. };
  757. updateListData.push(uld);
  758. }
  759. }
  760. if(updateListData.length > 0) await transaction.updateRows(this.ctx.service.changeAuditList.tableName, updateListData);
  761. const options = {
  762. where: {
  763. cid: cid,
  764. },
  765. };
  766. const updateData = {
  767. total_price,
  768. tp_decimal: this.ctx.tender.info.decimal.tp,
  769. up_decimal: this.ctx.tender.info.decimal.up,
  770. status: auditConst.status.checking,
  771. };
  772. await transaction.update(this.ctx.service.change.tableName, updateData, options);
  773. // 清空audit_amount
  774. if(times > 1) await transaction.update(this.ctx.service.changeAuditList.tableName, { audit_amount: null }, { where: { cid: cid } });
  775. // 添加短信通知-需要审批提醒功能
  776. const sms = new SMS(this.ctx);
  777. const code = await sms.contentChange(this.ctx.change.code);
  778. const shenpiUrl = await this.ctx.helper.urlToShort(
  779. this.ctx.protocol + '://' + this.ctx.host + '/wap/tender/' + this.ctx.change.tid + '/change/' + cid + '/information#shenpi'
  780. );
  781. await this.ctx.helper.sendAliSms(this._.map(audits, 'uid'), smsTypeConst.const.BG, smsTypeConst.judge.approval.toString(), SmsAliConst.template.change_check, {
  782. biangeng: code,
  783. code: shenpiUrl,
  784. });
  785. // 微信模板通知
  786. const wechatData = {
  787. wap_url: shenpiUrl,
  788. status: wxConst.status.check,
  789. tips: wxConst.tips.check,
  790. code: this.ctx.session.sessionProject.code,
  791. c_name: this.ctx.change.name,
  792. };
  793. await this.ctx.helper.sendWechat(this._.map(audits, 'uid'), smsTypeConst.const.BG, smsTypeConst.judge.approval.toString(), wxConst.template.change, wechatData);
  794. // 重新发送配置
  795. for (const audit of audits) {
  796. await this.ctx.service.noticeAgain.addNoticeAgain(transaction, smsTypeConst.const.BG, {
  797. pid: this.ctx.session.sessionProject.id,
  798. tid: this.ctx.change.tid,
  799. uid: audit.uid,
  800. sp_type: 'change',
  801. sp_id: audit.id,
  802. table_name: this.tableName,
  803. template: wxConst.template.change,
  804. wx_data: wechatData,
  805. });
  806. }
  807. await transaction.delete(this.ctx.service.changeHistory.tableName, { cid });
  808. await transaction.commit();
  809. } catch (err) {
  810. await transaction.rollback();
  811. throw err;
  812. }
  813. return true;
  814. }
  815. async getNumByMonth(tid, startMonth, endMonth) {
  816. const sql = 'SELECT COUNT(*) as num FROM ?? t1 JOIN (SELECT MAX(id) as max_id FROM ?? WHERE tid = ? AND usite != 0 GROUP BY id ORDER BY usort DESC) t2 ON t1.id = t2.max_id WHERE t1.status = ? AND t1.sin_time between ? and ?';
  817. // const sql = 'SELECT COUNT(*) as num FROM ?? WHERE id in (SELECT b.id FROM (SELECT * FROM ?? WHERE tid = ? AND usite != 0 GROUP BY id ORDER BY usort DESC) as b GROUP BY b.cid) AND status = ? AND sin_time between ? and ?';
  818. const sqlParam = [this.tableName, this.tableName, tid, auditConst.status.checked, startMonth, endMonth];
  819. const result = await this.db.queryOne(sql, sqlParam);
  820. return result ? result.num : 0;
  821. }
  822. /**
  823. * 审批撤回
  824. * @param {Number} stageId - 标段id
  825. * @param {Number} times - 第几次审批
  826. * @return {Promise<void>}
  827. */
  828. async checkCancel(change) {
  829. // 分4种情况,根据ctx.cancancel值判断:
  830. // 1.原报发起撤回,当前流程删除,并回到待上报
  831. // 2.审批人撤回审批通过,增加流程,并回到它审批中
  832. // 3.审批人撤回审批退回上一人,并删除退回人,增加流程,并回到它审批中,并更新计量期状态为审批中
  833. // 4.审批人撤回退回原报操作,删除新增的审批流,增加流程,回滚到它审批中
  834. // 5.会签审批人撤回审批通过(还有其他审批人未审批通过),仅修改本人流程状态
  835. if (change.cancancel === 5) {
  836. await this._auditCheckCancelAnd(change);
  837. } else {
  838. switch (change.cancancel) {
  839. case 1: await this._userCheckCancel(change); break;
  840. case 2: await this._auditCheckCancel(change); break;
  841. case 3: await this._auditCheckCancelNoPre(change); break;
  842. case 4: await this._auditCheckCancelNo(change); break;
  843. default: throw '不可撤回,请刷新页面重试';
  844. }
  845. }
  846. // if (stage.cancancel === 5) {
  847. // await this._auditCheckCancelAnd(stage);
  848. // } else {
  849. // switch (this.ctx.stage.cancancel) {
  850. // case 1: await this._userCheckCancel(stage); break;
  851. // case 2: await this._auditCheckCancel(stage); break;
  852. // case 3: await this._auditCheckCancelNoPre(stage); break;
  853. // case 4: await this._auditCheckCancelNo(stage); break;
  854. // default: throw '不可撤回,请刷新页面重试';
  855. // }
  856. // // 通知发送 - 第三方更新
  857. // if (this.ctx.session.sessionProject.custom && syncApiConst.notice_type.indexOf(this.ctx.session.sessionProject.customType) !== -1) {
  858. // const base_data = {
  859. // tid: stage.tid,
  860. // sid: stage.id,
  861. // op: 'update',
  862. // };
  863. // this.ctx.helper.syncNoticeSend(this.ctx.session.sessionProject.customType, JSON.stringify(base_data));
  864. // base_data.op = 'update';
  865. // base_data.sid = -1;
  866. // this.ctx.helper.syncNoticeSend(this.ctx.session.sessionProject.customType, JSON.stringify(base_data));
  867. // }
  868. // }
  869. }
  870. /**
  871. * 原报撤回,直接改动审批人状态
  872. * 如果存在审批人数据,将其改为原报流程数据,但保留原提交人
  873. *
  874. * 一审 1 A checking -> A uncheck status改 pay/jl:删0(jl为增量数据,只删重复部分) 1->0 删1
  875. * ...
  876. *
  877. * @param stage
  878. * @returns {Promise<void>}
  879. * @private
  880. */
  881. async _userCheckCancel(change) {
  882. const transaction = await this.db.beginTransaction();
  883. try {
  884. // 整理当前流程审核人状态更新
  885. // 审批人变成待审批状态
  886. const updateData = change.curAuditors.map(x => {
  887. return {
  888. id: x.id,
  889. status: auditConst.status.uncheck,
  890. begin_time: null,
  891. sin_time: null,
  892. sdesc: '',
  893. }
  894. });
  895. await transaction.updateRows(this.tableName, updateData);
  896. await this.ctx.service.noticeAgain.deleteNoticeAgain(transaction, this.tableName, this._.map(updateData, 'id'));
  897. // 原报变成checking状态
  898. const ybAudit = await this.getDataByCondition({ cid: change.cid, times: change.times, usite: 0, status: auditConst.status.checked });
  899. await transaction.update(this.tableName, {
  900. id: ybAudit.id,
  901. status: auditConst.status.checking,
  902. end_time: null,
  903. sin_time: new Date(),
  904. });
  905. // 变更令变成待上报状态
  906. const options = {
  907. where: {
  908. cid: change.cid,
  909. },
  910. };
  911. await transaction.update(this.ctx.service.change.tableName, {
  912. status: change.times === 1 ? auditConst.status.uncheck : auditConst.status.checkNo,
  913. }, options);
  914. await transaction.commit();
  915. } catch(err) {
  916. await transaction.rollback();
  917. throw err;
  918. }
  919. }
  920. /**
  921. * 审批人撤回审批通过,插入两条数据
  922. *
  923. * 一审 1 A checked 一审 1 A checked
  924. * 二审 2 B checked pre -> 二审 2 B checked
  925. * 三审 3 C checking cur 二审 3 B checkCancel 增 增extra_his 增tp_his
  926. * 四审 4 D uncheck 二审 4 B checking 增 增pay_cur
  927. * 三审 5 C uncheck order、status改
  928. * 四审 6 D uncheck order改
  929. *
  930. * @param stage
  931. * @returns {Promise<void>}
  932. * @private
  933. */
  934. async _auditCheckCancel(change) {
  935. if (change.curAuditors.length === 0 || change.curAuditors[0].usort <= 1) {
  936. throw '撤回用户数据错误';
  937. }
  938. const accountId = this.ctx.session.sessionUser.accountId;
  939. const time = new Date();
  940. const transaction = await this.db.beginTransaction();
  941. try {
  942. const selfAuditor = change.preAuditors.find(x => { return x.uid === accountId; });
  943. if (!selfAuditor) throw '撤回用户数据错误';
  944. // 顺移其后审核人流程顺序
  945. const sql = 'UPDATE ' + this.tableName + ' SET `usort` = `usort` + 2 WHERE cid = ? AND times = ? AND `usort` > ?';
  946. await transaction.query(sql, [change.cid, change.times, change.curAuditors[0].usort]);
  947. // 当前审批人2次添加至流程中
  948. const checkCancelAuditors = [], checkingAuditors = [];
  949. change.preAuditors.forEach(x => {
  950. checkCancelAuditors.push({
  951. tid: change.tid, cid: change.cid, uid: x.uid,
  952. times: x.times, usite: x.usite, usort: x.usort + 1,
  953. status: x.uid === selfAuditor.uid ? auditConst.status.checkCancel : auditConst.status.checkSkip,
  954. begin_time: time, end_time: time, sin_time: time, sdesc: '',
  955. name: x.name, jobs: x.role || x.jobs, company: x.company,
  956. audit_type: x.audit_type, audit_order: x.audit_order,
  957. });
  958. });
  959. change.preAuditors.forEach(x => {
  960. checkingAuditors.push({
  961. tid: change.tid, cid: change.cid, uid: x.uid,
  962. times: x.times, usite: x.usite, usort: x.usort + 2,
  963. status: auditConst.status.checking,
  964. begin_time: time, sin_time: time, sdesc: '',
  965. name: x.name, jobs: x.role || x.jobs, company: x.company,
  966. audit_type: x.audit_type, audit_order: x.audit_order,
  967. });
  968. });
  969. await transaction.insert(this.tableName, [...checkCancelAuditors, ...checkingAuditors]);
  970. const newAuditors = [];
  971. // 当前审批人变成待审批
  972. await transaction.updateRows(this.tableName, change.curAuditors.map(x => { return {
  973. id: x.id, begin_time: null, sin_time: null, status: auditConst.status.uncheck, usort: x.usort + 2
  974. }}));
  975. await this.ctx.service.noticeAgain.deleteNoticeAgain(transaction, this.tableName, this._.map(change.curAuditors, 'id'));
  976. // 审批列表数据也要回退
  977. const changeList = await this.ctx.service.changeAuditList.getList(change.cid);
  978. let total_price = 0;
  979. const tp_decimal = change.tp_decimal ? change.tp_decimal : this.ctx.tender.info.decimal.tp;
  980. const updateList = [];
  981. for (const cl of changeList) {
  982. const audit_amount = cl.audit_amount.split(',');
  983. const last_amount = audit_amount[audit_amount.length - 1] ? audit_amount[audit_amount.length - 1] : 0;
  984. audit_amount.splice(-1, 1);
  985. const list_update = {
  986. id: cl.id,
  987. audit_amount: audit_amount.join(','),
  988. spamount: parseFloat(last_amount),
  989. };
  990. total_price = this.ctx.helper.add(total_price, this.ctx.helper.mul(cl.unit_price, parseFloat(last_amount), tp_decimal));
  991. updateList.push(list_update)
  992. }
  993. if (updateList.length > 0) await transaction.updateRows(this.ctx.service.changeAuditList.tableName, updateList);
  994. // 变更令变成待上报状态
  995. const options = {
  996. where: {
  997. cid: change.cid,
  998. },
  999. };
  1000. await transaction.update(this.ctx.service.change.tableName, {
  1001. status: auditConst.status.checking,
  1002. total_price,
  1003. cin_time: Date.parse(time) / 1000,
  1004. }, options);
  1005. await transaction.commit();
  1006. } catch(err) {
  1007. await transaction.rollback();
  1008. throw err;
  1009. }
  1010. }
  1011. /**
  1012. * 审批人撤回审批退回上一人,插入两条数据
  1013. *
  1014. * 一审 1 A checked 一审 1 A checked
  1015. * 二审 2 B checked 二审 2 B checked
  1016. * 三审 3 C checkNoPre pre -> 三审 3 C checkNoPre
  1017. * 二审 4 B checking cur 三审 4 C checkCancel 删4B 增4C 增extra_his 增tp_his
  1018. * 三审 5 C uncheck 三审 5 C checking status改 增pay_cur
  1019. * 四审 6 D uncheck 四审 6 D uncheck
  1020. *
  1021. * @param stage
  1022. * @returns {Promise<void>}
  1023. * @private
  1024. */
  1025. async _auditCheckCancelNoPre(change) {
  1026. if (change.curAuditors.length === 0 || change.curAuditors[0].usort <= 1) {
  1027. throw '撤回用户数据错误';
  1028. }
  1029. const accountId = this.ctx.session.sessionUser.accountId;
  1030. const time = new Date();
  1031. const transaction = await this.db.beginTransaction();
  1032. try {
  1033. const selfAuditor = change.preAuditors.find(x => { return x.uid === accountId; });
  1034. if (!selfAuditor) throw '撤回用户数据错误';
  1035. // 整理当前流程审核人状态更新
  1036. // 删除当前审批人
  1037. await transaction.delete(this.tableName, { id: change.curAuditors.map(x => { return x.id; }) });
  1038. await this.ctx.service.noticeAgain.deleteNoticeAgain(transaction, this.tableName, this._.map(change.curAuditors, 'id'));
  1039. // 添加撤回人到审批流程中
  1040. const newAuditors = [];
  1041. change.preAuditors.forEach(x => {
  1042. newAuditors.push({
  1043. tid: change.tid, cid: change.cid, uid: x.uid,
  1044. times: x.times, usite: x.usite, usort: x.usort + 1,
  1045. status: x.uid === selfAuditor.uid ? auditConst.status.checkCancel : auditConst.status.checkSkip,
  1046. begin_time: time, end_time: time, sin_time: time, sdesc: '',
  1047. name: x.name, jobs: x.role || x.jobs, company: x.company,
  1048. audit_type: x.audit_type, audit_order: x.audit_order,
  1049. });
  1050. });
  1051. await transaction.insert(this.tableName, newAuditors);
  1052. // 更新上一个人,最新审批状态为审批中
  1053. await transaction.update(this.tableName, { begin_time: time, sin_time: time, status: auditConst.status.checking }, {
  1054. where: { cid: change.cid, times: change.times, usort: selfAuditor.usort + 2 }
  1055. });
  1056. // 回退spamount值数据
  1057. const changeList = await this.ctx.service.changeAuditList.getList(change.cid);
  1058. let total_price = 0;
  1059. const tp_decimal = change.tp_decimal ? change.tp_decimal : this.ctx.tender.info.decimal.tp;
  1060. const updateList = [];
  1061. for (const cl of changeList) {
  1062. const audit_amount = cl.audit_amount !== '' ? cl.audit_amount.split(',') : [];
  1063. audit_amount.push(cl.spamount);
  1064. const list_update = {
  1065. id: cl.id,
  1066. audit_amount: audit_amount.join(','),
  1067. };
  1068. total_price = this.ctx.helper.add(total_price, this.ctx.helper.mul(cl.unit_price, parseFloat(cl.spamount), tp_decimal));
  1069. updateList.push(list_update);
  1070. }
  1071. if (updateList.length > 0) await transaction.updateRows(this.ctx.service.changeAuditList.tableName, updateList);
  1072. // 变更令变成待上报状态
  1073. const options = {
  1074. where: {
  1075. cid: change.cid,
  1076. },
  1077. };
  1078. await transaction.update(this.ctx.service.change.tableName, {
  1079. status: auditConst.status.checking,
  1080. total_price,
  1081. cin_time: Date.parse(time) / 1000,
  1082. }, options);
  1083. await transaction.commit();
  1084. } catch(err) {
  1085. await transaction.rollback();
  1086. throw err;
  1087. }
  1088. }
  1089. /**
  1090. * 审批人撤回审批退回原报
  1091. *
  1092. * 1# 一审 1 A checked 1# 一审 1 A checked
  1093. * 二审 2 B checkNo pre -> 二审 2 B checkNo
  1094. * 三审 3 C uncheck 二审 3 B checkCancel 增 pay: 2#0 -> 1#3 jl: 2#0 -> 1#3 增tp_his 增extra_his
  1095. * 二审 4 B checking 增 pay: 2#0 -> 1#4
  1096. * 三审 5 C uncheck order改
  1097. *
  1098. * 2# 一审 1 A uncheck 2# 删 pay: 2#0删 jl: 2#0删
  1099. * 二审 2 B uncheck
  1100. * 三审 3 C uncheck
  1101. *
  1102. * @param stage
  1103. * @returns {Promise<void>}
  1104. * @private
  1105. */
  1106. async _auditCheckCancelNo(change) {
  1107. const accountId = this.ctx.session.sessionUser.accountId;
  1108. const selfAuditor = change.preAuditors.find(x => { return x.uid === accountId && x.status === auditConst.status.checkNo; });
  1109. if (!selfAuditor) throw '该标段由他人审批退回,您不可撤回';
  1110. const time = new Date();
  1111. const transaction = await this.db.beginTransaction();
  1112. try {
  1113. // const curAudit = await this.getDataByCondition({ cid: change.cid, times: change.times - 1, status: auditConst.auditStatus.back });
  1114. // const curAudit = await this.getAuditorByStatus(change.cid, change.times - 1, auditConst.auditStatus.back);
  1115. // 整理上一个流程审核人状态更新
  1116. // 顺移其后审核人流程顺序
  1117. const sql = 'UPDATE ' + this.tableName + ' SET `usort` = `usort` + 2 WHERE cid = ? AND times = ? AND `usort` > ?';
  1118. await transaction.query(sql, [change.cid, selfAuditor.times, selfAuditor.usort]);
  1119. // 当前审批人2次添加至流程中
  1120. const checkCancelAuditors = [], checkingAuditors = [];
  1121. change.preAuditors.forEach(x => {
  1122. checkCancelAuditors.push({
  1123. tid: change.tid, cid: change.cid, uid: x.uid,
  1124. times: x.times, usite: x.usite, usort: x.usort + 1,
  1125. status: x.uid === selfAuditor.uid ? auditConst.status.checkCancel : auditConst.status.checkSkip,
  1126. begin_time: time, end_time: time, sin_time: time, sdesc: '',
  1127. name: x.name, jobs: x.role || x.jobs, company: x.company,
  1128. audit_type: x.audit_type, audit_order: x.audit_order,
  1129. });
  1130. });
  1131. change.preAuditors.forEach(x => {
  1132. checkingAuditors.push({
  1133. tid: change.tid, cid: change.cid, uid: x.uid,
  1134. times: x.times, usite: x.usite, usort: x.usort + 2,
  1135. status: auditConst.status.checking,
  1136. begin_time: time, sin_time: time, sdesc: '',
  1137. name: x.name, jobs: x.role || x.jobs, company: x.company,
  1138. audit_type: x.audit_type, audit_order: x.audit_order,
  1139. });
  1140. });
  1141. await transaction.insert(this.tableName, [...checkCancelAuditors, ...checkingAuditors]);
  1142. // 删除当前次审批流
  1143. await transaction.delete(this.tableName, { cid: change.cid, times: change.times });
  1144. // 回退数据
  1145. await this.ctx.service.changeHistory.returnHistory(transaction, change.cid);
  1146. await transaction.delete(this.ctx.service.changeHistory.tableName, { cid: change.cid });
  1147. await transaction.commit();
  1148. } catch(err) {
  1149. await transaction.rollback();
  1150. throw err;
  1151. }
  1152. }
  1153. /**
  1154. * 会签未全部审批通过时,撤回仅修改本人状态
  1155. *
  1156. * @param stage
  1157. * @returns {Promise<void>}
  1158. * @private
  1159. */
  1160. async _auditCheckCancelAnd(change) {
  1161. const accountId = this.ctx.session.sessionUser.accountId;
  1162. const selfAuditor = change.flowAuditors.find(x => { return x.uid === accountId; });
  1163. if (!selfAuditor || selfAuditor.status !== auditConst.status.checked) throw '不可撤回';
  1164. const transaction = await this.db.beginTransaction();
  1165. try {
  1166. await transaction.update(this.tableName, {
  1167. id: selfAuditor.id, status: auditConst.status.checking, sdesc: '', end_time: null,
  1168. });
  1169. await transaction.commit();
  1170. } catch(err) {
  1171. await transaction.rollback();
  1172. throw err;
  1173. }
  1174. }
  1175. async getAuditorByStatus(cid, times, status, transaction= null) {
  1176. const sql = 'SELECT * FROM ?? WHERE `cid` = ? AND `times` = ? AND `status` = ? ORDER BY `usort` DESC';
  1177. const sqlParam = [this.tableName, cid, times, status];
  1178. return transaction ? await transaction.queryOne(sql, sqlParam) : await this.db.queryOne(sql, sqlParam);
  1179. }
  1180. async getAuditorsByStatus(cid, status, times = 1) {
  1181. let auditor = [];
  1182. let sql = '';
  1183. let sqlParam = '';
  1184. let cur;
  1185. switch (status) {
  1186. case auditConst.status.checking:
  1187. case auditConst.status.checked:
  1188. case auditConst.status.checkNoPre:
  1189. cur = await this.db.queryOne(`SELECT * From ${this.tableName} where cid = ? AND times = ? AND status = ? AND audit_order != 0 ORDER By times DESC, ` + '`usort` DESC', [cid, times, status]);
  1190. if (!cur) return [];
  1191. sql = 'SELECT la.`uid`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`cid`, la.`status`, la.`usort`, la.`usite`, la.audit_order, la.audit_type ' +
  1192. ' FROM ?? AS la Left Join ?? AS pa On la.`uid` = pa.`id` ' +
  1193. ' WHERE la.`cid` = ? and la.`usort` = ? and la.`times` = ?';
  1194. sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, cid, cur.usort, times];
  1195. auditor = await this.db.query(sql, sqlParam);
  1196. break;
  1197. case auditConst.status.checkNo:
  1198. cur = await this.db.queryOne(`SELECT * From ${this.tableName} where cid = ? AND times = ? AND status = ? AND audit_order != 0 ORDER By times DESC, ` + '`usort` DESC', [cid, parseInt(times) - 1, status]);
  1199. if (!cur) return [];
  1200. sql = 'SELECT la.`uid`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`cid`, la.`status`, la.`usort`, la.`usite`, la.audit_order, la.audit_type ' +
  1201. ' FROM ?? AS la Left Join ?? AS pa On la.`uid` = pa.`id` ' +
  1202. ' WHERE la.`cid` = ? and la.`usort` = ? and la.`times` = ?';
  1203. sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, cid, cur.usort, parseInt(times) - 1];
  1204. auditor = await this.db.query(sql, sqlParam);
  1205. break;
  1206. case auditConst.status.revise:
  1207. cur = await this.db.queryOne(`SELECT * From ${this.tableName} where cid = ? AND times = ? AND status = ? ORDER By times DESC, ` + '`usort` DESC', [cid, parseInt(times) - 1, status]);
  1208. if (!cur) return [];
  1209. sql = 'SELECT la.`uid`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`cid`, la.`status`, la.`usort`, la.`usite`, la.audit_order, la.audit_type ' +
  1210. ' FROM ?? AS la Left Join ?? AS pa On la.`uid` = pa.`id` ' +
  1211. ' WHERE la.`cid` = ? and la.`usort` = ? and la.`times` = ?';
  1212. sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, cid, cur.usort, parseInt(times) - 1];
  1213. auditor = await this.db.query(sql, sqlParam);
  1214. break;
  1215. case auditConst.status.uncheck:
  1216. default:
  1217. break;
  1218. }
  1219. return auditor;
  1220. }
  1221. async saveAudit(cid, times, sp_group, data) {
  1222. const transaction = await this.db.beginTransaction();
  1223. try {
  1224. const auditors = await this.getAuditGroupByList(cid, times);
  1225. const now_audit = this._.find(auditors, { uid: data.old_aid });
  1226. if (data.operate !== 'del') {
  1227. const exist = await this.getDataByCondition({ cid, times, uid: data.new_aid });
  1228. if (exist) throw '该审核人已存在,请勿重复添加';
  1229. }
  1230. if (data.operate === 'add') {
  1231. if (now_audit.status !== auditConst.status.uncheck && now_audit.status !== auditConst.status.checking) {
  1232. throw '当前人下无法操作新增';
  1233. }
  1234. const nowAuditInfo = await this.ctx.service.projectAccount.getDataById(data.new_aid);
  1235. const newAudit = {
  1236. tid: this.ctx.tender.id, cid, uid: data.new_aid,
  1237. name: nowAuditInfo.name, company: nowAuditInfo.company, jobs: nowAuditInfo.role,
  1238. usort: now_audit.usort + 1, usite: now_audit.usite + 1,
  1239. audit_order: now_audit.audit_order + 1, audit_type: auditType.key.common,
  1240. times: times, status: auditConst.status.uncheck,
  1241. };
  1242. // order+1
  1243. await this._syncOrderByDelete(transaction, cid, now_audit.usite + 1, now_audit.usort + 1, times, '+');
  1244. await transaction.insert(this.tableName, newAudit);
  1245. // 更新审批流程页数据,如果存在
  1246. } else if (data.operate === 'add-sibling') {
  1247. if (now_audit.status !== auditConst.status.uncheck && now_audit.status !== auditConst.status.checking) {
  1248. throw '当前人下无法操作新增';
  1249. }
  1250. const nowAuditInfo = await this.ctx.service.projectAccount.getDataById(data.new_aid);
  1251. const newAudit = {
  1252. tid: this.ctx.tender.id, cid, uid: data.new_aid,
  1253. name: nowAuditInfo.name, company: nowAuditInfo.company, jobs: nowAuditInfo.role,
  1254. usort: now_audit.usort, usite: now_audit.usite,
  1255. audit_order: now_audit.audit_order, audit_type: now_audit.audit_type,
  1256. times: times,
  1257. status: auditConst.status.uncheck,
  1258. };
  1259. await transaction.insert(this.tableName, newAudit);
  1260. } else if (data.operate === 'del') {
  1261. if (now_audit.status !== auditConst.status.uncheck) {
  1262. throw '当前人无法操作删除';
  1263. }
  1264. const flowAuditors = auditors.filter(x => { return x.audit_order === now_audit.audit_order; });
  1265. await transaction.delete(this.tableName, { cid, times, uid: now_audit.uid, usite: now_audit.usite });
  1266. if (flowAuditors.length === 1) await this._syncOrderByDelete(transaction, cid, now_audit.usite, now_audit.usort, times);
  1267. // 旧的更新为is_old为1
  1268. // await transaction.update(this.tableName, { is_old: 1 }, {
  1269. // where: {
  1270. // sid: stageId,
  1271. // times,
  1272. // aid: data.old_aid,
  1273. // }
  1274. // });
  1275. } else if (data.operate === 'change') {
  1276. const nowAudit = await this.getDataByCondition({ cid, times, uid: now_audit.uid, usite: now_audit.usite });
  1277. if (now_audit.status !== auditConst.status.uncheck || !nowAudit) {
  1278. throw '当前人无法操作替换';
  1279. }
  1280. const nowAuditInfo = await this.ctx.service.projectAccount.getDataById(data.new_aid);
  1281. nowAudit.uid = data.new_aid;
  1282. nowAudit.name = nowAuditInfo.name;
  1283. nowAudit.company = nowAuditInfo.company;
  1284. nowAudit.jobs = nowAuditInfo.role;
  1285. await transaction.update(this.tableName, nowAudit);
  1286. // 旧的更新为is_old为1
  1287. // await transaction.update(this.tableName, { is_old: 1 }, {
  1288. // where: {
  1289. // sid: stageId,
  1290. // times,
  1291. // aid: data.old_aid,
  1292. // }
  1293. // });
  1294. }
  1295. if (this.ctx.tender.info.shenpi.change === shenpiConst.sp_status.gdspl) {
  1296. const newAuditors = await transaction.select(this.tableName, { where: { cid, times }, orders: [['usite', 'asc']] });
  1297. newAuditors.shift();
  1298. const newAuditorGroup = this.ctx.helper.groupAuditors(newAuditors, 'usort');
  1299. const uniqNewAuditorGroup = this.ctx.helper.groupAuditorsUniq(newAuditorGroup);
  1300. await this.ctx.service.shenpiAudit.updateAuditListWithAuditType(transaction, this.ctx.tender.id, this.ctx.tender.info.shenpi.change, shenpiConst.sp_type.change, uniqNewAuditorGroup, sp_group);
  1301. } else if (this.ctx.tender.info.shenpi.change === shenpiConst.sp_status.gdzs) {
  1302. const newAuditors = await this.getListGroupByWithoutYB(cid, times, transaction);
  1303. await this.ctx.service.shenpiAudit.updateAuditList(transaction, this.ctx.tender.id, this.ctx.tender.info.shenpi.change, shenpiConst.sp_type.change, this._.map(newAuditors, 'uid'));
  1304. }
  1305. // 更新到审批流程方法
  1306. await transaction.commit();
  1307. } catch (err) {
  1308. console.log(err);
  1309. await transaction.rollback();
  1310. throw err;
  1311. }
  1312. }
  1313. async batchSetAudits(tid, cids, from_cid) {
  1314. const transaction = await this.db.beginTransaction();
  1315. try {
  1316. const changes = await this.ctx.service.change.getAllDataByCondition({ where: { tid, cid: cids } });
  1317. const from_change = await this.ctx.service.change.getDataByCondition({ tid, cid: from_cid });
  1318. const new_audits = await transaction.select(this.tableName, { where: { cid: from_cid, times: from_change.times }, orders: [['audit_order', 'asc']] });
  1319. new_audits.shift();
  1320. const insertAudits = [];
  1321. const updateChanges = [];
  1322. for (const c of changes) {
  1323. if (from_change.sp_group !== c.sp_group) {
  1324. updateChanges.push({
  1325. row: { sp_group: from_change.sp_group },
  1326. where: { tid, cid: c.cid }
  1327. });
  1328. }
  1329. const newAudits = new_audits.map(x => {
  1330. return {
  1331. tid, cid: c.cid, uid: x.uid, name: x.name,
  1332. company: x.company, jobs: x.role,
  1333. usort: x.usort, usite: x.usite,
  1334. audit_order: x.audit_order, audit_type: x.audit_type,
  1335. times: c.times, status: auditConst.status.uncheck,
  1336. };
  1337. });
  1338. // 先删除旧的审批流(除了原报),再添加新的
  1339. const sql = 'DELETE FROM ?? WHERE `cid`= ? AND `times` = ? AND `usite` != 0';
  1340. const sqlParam = [this.tableName, c.cid, c.times];
  1341. await transaction.query(sql, sqlParam);
  1342. // await transaction.delete(this.tableName, { tid, cid: c.cid, times: c.times });
  1343. insertAudits.push(...newAudits);
  1344. }
  1345. if (updateChanges.length > 0) await transaction.updateRows(this.ctx.service.change.tableName, updateChanges);
  1346. if (insertAudits.length > 0) await transaction.insert(this.tableName, insertAudits);
  1347. // 更新到审批流程方法
  1348. await transaction.commit();
  1349. return true;
  1350. } catch (err) {
  1351. console.log(err);
  1352. await transaction.rollback();
  1353. throw err;
  1354. }
  1355. }
  1356. }
  1357. return ChangeAudit;
  1358. };