shenpi_audit.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  1. 'use strict';
  2. /**
  3. * 版本数据模型
  4. *
  5. * @author CaiAoLin
  6. * @date 2017/10/25
  7. * @version
  8. */
  9. const shenpiConst = require('../const/shenpi');
  10. const auditType = require('../const/audit').auditType;
  11. module.exports = app => {
  12. class ShenpiAudit extends app.BaseService {
  13. /**
  14. * 构造函数
  15. *
  16. * @param {Object} ctx - egg全局变量
  17. * @return {void}
  18. */
  19. constructor(ctx) {
  20. super(ctx);
  21. this.tableName = 'shenpi_audit';
  22. }
  23. async getShenpi(tid, info) {
  24. const spConst = this._.cloneDeep(shenpiConst);
  25. for (const sp of spConst.sp_lc) {
  26. sp.status = info.shenpi ? info.shenpi[sp.code] : shenpiConst.sp_status.sqspr;
  27. if (sp.status === shenpiConst.sp_status.gdspl) {
  28. sp.groupList = await this.ctx.service.shenpiGroup.getGroupList(tid, sp.type) || [];
  29. if (sp.groupList && sp.groupList.length > 0) {
  30. for (const group of sp.groupList) {
  31. if (group.change_type) group.change_type = JSON.parse(group.change_type);
  32. group.auditGroupList = await this.getAuditGroupList(tid, sp.type, sp.status, group.id);
  33. if (group.is_select) sp.auditGroupList = group.auditGroupList;
  34. }
  35. } else {
  36. sp.auditGroupList = await this.getAuditGroupList(tid, sp.type, sp.status);
  37. }
  38. } else if (sp.status === shenpiConst.sp_status.gdzs) {
  39. sp.audit = await this.getAudit(tid, sp.type, sp.status);
  40. }
  41. }
  42. return spConst;
  43. }
  44. async getAudit(tid, type, status) {
  45. const sql = 'SELECT sp.audit_id, sp.audit_type, pa.name FROM ?? AS sp LEFT JOIN ?? AS pa ON sp.audit_id = pa.id' +
  46. ' WHERE sp.tid = ? AND sp.sp_type = ? AND sp.sp_status = ?';
  47. const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, tid, type, status];
  48. return await this.db.queryOne(sql, sqlParam);
  49. }
  50. async getUnionAudit(tid, type, audit_order) {
  51. const sql = 'SELECT sp.id, sp.audit_id, sp.audit_ledger_id, pa.name, pa.company FROM ?? AS sp LEFT JOIN ?? AS pa ON sp.audit_id = pa.id' +
  52. ' WHERE sp.tid = ? AND sp.sp_type = ? AND sp.sp_status = ? AND audit_order = ?';
  53. const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, tid, type, shenpiConst.sp_status.gdspl, audit_order];
  54. return await this.db.query(sql, sqlParam);
  55. }
  56. async getAuditList(tid, type, status, group_id = 0) {
  57. const sql = 'SELECT sp.id, sp.audit_id, sp.audit_order, sp.audit_type, pa.name FROM ?? AS sp LEFT JOIN ?? AS pa ON sp.audit_id = pa.id' +
  58. ' WHERE sp.tid = ? AND sp.sp_type = ? AND sp.sp_status = ? AND sp.sp_group = ? ORDER BY sp.audit_order ASC, sp.id ASC';
  59. const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, tid, type, status, group_id];
  60. return await this.db.query(sql, sqlParam);
  61. }
  62. async getAllAuditGroupList(tids, type, status, group_id = 0) {
  63. const sql = 'SELECT sp.tid, sp.audit_id, sp.audit_type, sp.audit_order, sp.sp_group, pa.name FROM ?? AS sp LEFT JOIN ?? AS pa ON sp.audit_id = pa.id' +
  64. ' WHERE sp.tid in (' + this.ctx.helper.getInArrStrSqlFilter(tids) + ') AND sp.sp_type = ? AND sp.sp_status = ? AND sp.sp_group = ? ORDER BY sp.audit_order ASC, sp.id ASC';
  65. const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, type, status, group_id];
  66. const audits = await this.db.query(sql, sqlParam);
  67. const result = [];
  68. for (const t of tids) {
  69. const oneResult = [];
  70. const tidAudits = audits.filter(a => a.tid === t);
  71. for (const a of tidAudits) {
  72. if (a.audit_order > 0) {
  73. if (oneResult[a.audit_order - 1]) {
  74. oneResult[a.audit_order - 1].push(a);
  75. } else {
  76. oneResult.push([a]);
  77. }
  78. } else {
  79. oneResult.push([a]);
  80. }
  81. }
  82. result.push({ tid: t, audits: oneResult });
  83. }
  84. return result;
  85. }
  86. async getAuditGroupList(tid, type, status, group_id = 0) {
  87. const sql = 'SELECT sp.audit_id, sp.audit_type, sp.audit_order, sp.sp_group, pa.name FROM ?? AS sp LEFT JOIN ?? AS pa ON sp.audit_id = pa.id' +
  88. ' WHERE sp.tid = ? AND sp.sp_type = ? AND sp.sp_status = ? AND sp.sp_group = ? ORDER BY sp.audit_order ASC, sp.id ASC';
  89. const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, tid, type, status, group_id];
  90. const audits = await this.db.query(sql, sqlParam);
  91. const result = [];
  92. for (const a of audits) {
  93. if (a.audit_order > 0) {
  94. if (result[a.audit_order - 1]) {
  95. result[a.audit_order - 1].push(a);
  96. } else {
  97. result.push([a]);
  98. }
  99. } else {
  100. result.push([a]);
  101. }
  102. }
  103. return result;
  104. }
  105. async addAudit(data, tid = this.ctx.tender.id) {
  106. let result;
  107. const transaction = await this.db.beginTransaction();
  108. try {
  109. if (parseInt(data.code) === shenpiConst.sp_type.stage && parseInt(data.status) === shenpiConst.sp_status.gdspl) {
  110. const options = {
  111. where: {
  112. tid,
  113. user_id: data.audit_id,
  114. },
  115. };
  116. const updateData = {
  117. status: 1,
  118. };
  119. await transaction.update(this.ctx.service.ledgerCooperation.tableName, updateData, options);
  120. }
  121. const group = await this.ctx.service.shenpiGroup.getGroupBySelect(tid, data.code);
  122. const insertData = {
  123. tid,
  124. sp_type: data.code,
  125. sp_status: data.status,
  126. audit_id: data.audit_id,
  127. sp_group: group ? group.id : 0,
  128. };
  129. if (data.audit_type) insertData.audit_type = data.audit_type;
  130. if (data.audit_order) insertData.audit_order = data.audit_order;
  131. result = await transaction.insert(this.tableName, insertData);
  132. await transaction.commit();
  133. } catch (err) {
  134. await transaction.rollback();
  135. throw err;
  136. }
  137. if (result.affectedRows !== 1) throw '添加审批人失败';
  138. data.id = result.insertId;
  139. return data;
  140. }
  141. async removeAudit(data) {
  142. const group = await this.ctx.service.shenpiGroup.getGroupBySelect(this.ctx.tender.id, data.code);
  143. const delData = {
  144. tid: this.ctx.tender.id,
  145. sp_type: data.code,
  146. sp_status: data.status,
  147. audit_id: data.audit_id,
  148. sp_group: group ? group.id : 0,
  149. };
  150. const audit = await this.getDataByCondition(delData);
  151. const conditon = { tid: this.ctx.tender.id, sp_type: data.code, sp_status: data.status };
  152. if (group) conditon.sp_group = group.id;
  153. const allAudit = await this.getAllDataByCondition({ where: conditon });
  154. const sameOrder = allAudit.filter(x => { return x.audit_order === audit.audit_order; });
  155. const updateData = [];
  156. if (sameOrder.length === 1) {
  157. for (const aa of allAudit) {
  158. if (aa.audit_order > audit.audit_order) updateData.push({ id: aa.id, audit_order: aa.audit_order - 1 });
  159. }
  160. }
  161. const transaction = await this.db.beginTransaction();
  162. try {
  163. await transaction.delete(this.tableName, delData);
  164. if (updateData.length > 0) await transaction.updateRows(this.tableName, updateData);
  165. if (parseInt(data.code) === shenpiConst.sp_type.stage && parseInt(data.status) === shenpiConst.sp_status.gdspl) {
  166. const options = {
  167. where: {
  168. tid: this.ctx.tender.id,
  169. user_id: data.audit_id,
  170. },
  171. };
  172. const updateData = {
  173. status: 0,
  174. };
  175. await transaction.update(this.ctx.service.ledgerCooperation.tableName, updateData, options);
  176. }
  177. await transaction.commit();
  178. return true;
  179. } catch (err) {
  180. await transaction.rollback();
  181. throw err;
  182. }
  183. }
  184. async copyAudit2otherTender(data, tid = this.ctx.tender.id) {
  185. const transaction = await this.db.beginTransaction();
  186. try {
  187. const shenpi_status = parseInt(data.status);
  188. // 1.复制修改当前审批到其他的tender_info里
  189. // 2.删除其他的shenpiAudit
  190. // 3.添加新的shenpiAudit(还要针对该标段是否为原报进行处理)
  191. const tenderInfoUpdateList = [];
  192. const tenders = [];
  193. for (const tid of data.tidList.split(',')) {
  194. // 获取原报
  195. const tender = await this.ctx.service.tender.getDataById(tid);
  196. if (tender) {
  197. tenders.push({ id: parseInt(tid), user_id: tender.user_id });
  198. const shenpiInfo = await this.ctx.service.tenderInfo.getTenderShenpiInfo(tid);
  199. // 把当前期状态复制到其他标段里
  200. if (shenpiInfo[data.code] !== shenpi_status) {
  201. shenpiInfo[data.code] = shenpi_status;
  202. tenderInfoUpdateList.push({ row: { shenpi: JSON.stringify(shenpiInfo) }, where: { tid: parseInt(tid) } });
  203. }
  204. }
  205. }
  206. if (tenderInfoUpdateList.length > 0) await transaction.updateRows(this.ctx.service.tenderInfo.tableName, tenderInfoUpdateList);
  207. const insertList = [];
  208. const needYB = ['ledger', 'revise', 'change', 'financial'];
  209. const canYB = needYB.indexOf(data.code) !== -1;
  210. let is_group = false;
  211. let groupList = [];
  212. if (shenpi_status === shenpiConst.sp_status.gdspl) {
  213. groupList = await this.ctx.service.shenpiGroup.getGroupList(tid, shenpiConst.sp_type[data.code]);
  214. if (groupList.length > 0) {
  215. is_group = true;
  216. for (const g of groupList) {
  217. g.auditList = await this.getAllDataByCondition({ where: { tid, sp_type: shenpiConst.sp_type[data.code], sp_status: shenpi_status, sp_group: g.id } });
  218. }
  219. }
  220. }
  221. for (const t of tenders) {
  222. if (shenpi_status !== shenpiConst.sp_status.sqspr) {
  223. if (shenpi_status === shenpiConst.sp_status.gdspl) {
  224. await transaction.delete(this.ctx.service.shenpiGroup.tableName, {
  225. tid: t.id, sp_type: shenpiConst.sp_type[data.code],
  226. });
  227. }
  228. await transaction.delete(this.tableName, { tid: t.id, sp_type: shenpiConst.sp_type[data.code] || shenpiConst.sp_other_type[data.code], sp_status: shenpi_status });
  229. if (is_group) {
  230. for (const g of groupList) {
  231. const result = await transaction.insert(this.ctx.service.shenpiGroup.tableName, {
  232. tid: t.id,
  233. sp_type: shenpiConst.sp_type[data.code],
  234. name: g.name,
  235. is_select: g.is_select,
  236. change_type: g.change_type,
  237. create_time: new Date(),
  238. });
  239. for (const s of g.auditList) {
  240. insertList.push({
  241. tid: t.id,
  242. sp_type: shenpiConst.sp_type[data.code],
  243. sp_status: shenpi_status,
  244. audit_id: s.audit_id,
  245. audit_type: s.audit_type,
  246. audit_order: s.audit_order,
  247. sp_group: result.insertId,
  248. });
  249. }
  250. }
  251. } else {
  252. const sourceList = data.auditList.filter(x => { return x.audit_id && (x.audit_id !== t.user_id || canYB); });
  253. sourceList.sort((a, b) => { return a.audit_order - b.audit_order; });
  254. let audit_order = 0, curAuditOrder = 0;
  255. for (const s of sourceList) {
  256. if (s.audit_order !== curAuditOrder) {
  257. curAuditOrder = s.audit_order;
  258. audit_order = audit_order + 1;
  259. }
  260. insertList.push({
  261. tid: t.id,
  262. sp_type: shenpiConst.sp_type[data.code] || shenpiConst.sp_other_type[data.code],
  263. sp_status: shenpi_status,
  264. audit_id: s.audit_id,
  265. audit_type: s.audit_type,
  266. audit_order: audit_order,
  267. sp_group: 0,
  268. });
  269. }
  270. }
  271. }
  272. }
  273. // console.log(tenderInfoUpdateList, insertList);
  274. if (insertList.length > 0) await transaction.insert(this.tableName, insertList);
  275. await transaction.commit();
  276. return true;
  277. } catch (err) {
  278. await transaction.rollback();
  279. throw err;
  280. }
  281. }
  282. async copyAudit2otherShenpi(data) {
  283. const transaction = await this.db.beginTransaction();
  284. try {
  285. const shenpi_status = parseInt(data.status);
  286. // 1.修改当前审批到它的tender_info里
  287. // 2.删除相同审批状态的shenpiAudit
  288. // 3.添加新的shenpiAudit(还要针对该标段是否为原报进行处理)
  289. const insertList = [];
  290. const needYB = ['ledger', 'revise', 'change'];
  291. const shenpiInfo = await this.ctx.service.tenderInfo.getTenderShenpiInfo(this.ctx.tender.id);
  292. for (const code of data.shenpiList.split(',')) {
  293. // 把当前审批状态复制到其他标段里
  294. if (shenpiInfo[code] !== shenpi_status) {
  295. shenpiInfo[code] = shenpi_status;
  296. }
  297. if (shenpiInfo[code] !== shenpiConst.sp_status.sqspr) {
  298. if (shenpiInfo[code] === shenpiConst.sp_status.gdspl) {
  299. const group = await this.ctx.service.shenpiGroup.getAllDataByCondition({ where: { tid: this.ctx.tender.id, sp_type: shenpiConst.sp_type[code] } });
  300. if (group && group.length > 0) {
  301. throw '选择同步的流程中存在审批组,无法设置同步';
  302. }
  303. }
  304. await transaction.delete(this.tableName, { tid: this.ctx.tender.id, sp_type: shenpiConst.sp_type[code], sp_status: shenpiInfo[code] });
  305. const flows = data.flowList.split(';');
  306. let audit_order = 1;
  307. for (const f of flows) {
  308. const audit_type = parseInt(f.split(':')[0]);
  309. const auditTypeInfo = auditType.info[audit_type];
  310. const auditTypeValid = !auditTypeInfo.valid || auditTypeInfo.valid.indexOf(code) >= 0;
  311. const auditIds = f.split(':')[1].split(',').map(x => { return parseInt(x)});
  312. for (const aid of auditIds) {
  313. if (aid !== this.ctx.tender.data.user_id || needYB.indexOf(code) >= 0) {
  314. insertList.push({
  315. tid: this.ctx.tender.id,
  316. sp_type: shenpiConst.sp_type[code], sp_status: shenpi_status,
  317. audit_id: aid,
  318. audit_type: auditTypeValid ? audit_type : auditType.key.common,
  319. audit_order: audit_order,
  320. });
  321. if (!auditTypeValid) audit_order++;
  322. }
  323. }
  324. if (auditTypeValid) audit_order++;
  325. }
  326. }
  327. }
  328. await transaction.update(this.ctx.service.tenderInfo.tableName,
  329. {
  330. shenpi: JSON.stringify(shenpiInfo),
  331. },
  332. {
  333. where: {
  334. tid: this.ctx.tender.id,
  335. },
  336. });
  337. if (insertList.length > 0) await transaction.insert(this.tableName, insertList);
  338. await transaction.commit();
  339. return true;
  340. } catch (err) {
  341. await transaction.rollback();
  342. throw err;
  343. }
  344. }
  345. async setAuditType(data) {
  346. const conn = await this.db.beginTransaction();
  347. try {
  348. const updateData = { audit_type: data.audit_type };
  349. const group = await this.ctx.service.shenpiGroup.getGroupBySelect(this.ctx.tender.id, data.code);
  350. const condition = {
  351. tid: this.ctx.tender.id,
  352. sp_type: data.code,
  353. sp_status: data.status,
  354. audit_id: data.audit_id,
  355. sp_group: group ? group.id : 0,
  356. };
  357. await conn.update(this.tableName, updateData, { where: condition });
  358. await conn.commit();
  359. } catch (err) {
  360. await conn.rollback();
  361. throw err;
  362. }
  363. }
  364. // 更新审批流程
  365. async updateAuditList(transaction, tenderId, sp_status, sp_type, ids) {
  366. if (sp_status === shenpiConst.sp_status.gdspl) {
  367. const auditList = await this.getAuditList(tenderId, sp_type, sp_status);
  368. const oldIds = this._.map(auditList, 'audit_id');
  369. if (this._.isEqual(ids, oldIds)) {
  370. return;
  371. }
  372. // 更新固定审批流
  373. await transaction.delete(this.tableName, { tid: tenderId, sp_type, sp_status });
  374. const insertDatas = [];
  375. for (const [i, id] of ids.entries()) {
  376. insertDatas.push({
  377. tid: tenderId,
  378. sp_type,
  379. sp_status,
  380. audit_id: id,
  381. audit_order: i + 1,
  382. });
  383. }
  384. await transaction.insert(this.tableName, insertDatas);
  385. if (sp_type === shenpiConst.sp_type.stage) {
  386. // 判断哪些audit_id不存在了,哪些audit_为新增
  387. const exist = this._.difference(ids, oldIds);// 判断新增的
  388. const unExist = this._.difference(oldIds, ids);// 判断已删除的
  389. console.log(ids, oldIds, exist, unExist);
  390. if (exist.length > 0) {
  391. const options = {
  392. where: {
  393. tid: this.ctx.tender.id,
  394. user_id: exist,
  395. },
  396. };
  397. const updateData = {
  398. status: 1,
  399. };
  400. await transaction.update(this.ctx.service.ledgerCooperation.tableName, updateData, options);
  401. }
  402. if (unExist.length > 0) {
  403. const options2 = {
  404. where: {
  405. tid: this.ctx.tender.id,
  406. user_id: unExist,
  407. },
  408. };
  409. const updateData2 = {
  410. status: 0,
  411. };
  412. await transaction.update(this.ctx.service.ledgerCooperation.tableName, updateData2, options2);
  413. }
  414. }
  415. } else if (sp_status === shenpiConst.sp_status.gdzs) {
  416. const audit = await this.getAudit(tenderId, sp_type, sp_status);
  417. if (audit && audit.audit_id !== ids[ids.length - 1]) {
  418. // 更换终审
  419. await transaction.update(this.tableName, { audit_id: ids[ids.length - 1] }, { where: { tid: tenderId, sp_type, sp_status } });
  420. } else if (!audit) {
  421. await transaction.insert(this.tableName, { tid: tenderId, sp_type, sp_status, audit_id: ids[ids.length - 1] });
  422. }
  423. }
  424. }
  425. async updateAuditListWithAuditType(transaction, tenderId, sp_status, sp_type, auditGroup, sp_group = 0) {
  426. const auditList = await this.getAuditList(tenderId, sp_type, sp_status, sp_group);
  427. const newAuditList = [];
  428. for (const group of auditGroup) {
  429. newAuditList.push(...group);
  430. }
  431. let sameAudit = auditList.length === newAuditList.length;
  432. if (sameAudit) {
  433. for (const audit of auditList) {
  434. const newAudit = newAuditList.find(x => { return x.audit_id === audit.aid; });
  435. if (!newAudit || newAudit.audit_order !== audit.audit_order || newAudit.audit_type !== audit.audit_type) {
  436. sameAudit = false;
  437. break;
  438. }
  439. }
  440. }
  441. if (sameAudit) return;
  442. // 更新固定审批流
  443. await transaction.delete(this.tableName, { tid: tenderId, sp_type, sp_status, sp_group });
  444. const insertDatas = [];
  445. for (const a of newAuditList) {
  446. insertDatas.push({
  447. tid: tenderId,
  448. sp_type,
  449. sp_status,
  450. audit_id: a.aid || a.uid || a.audit_id,
  451. audit_order: a.audit_order,
  452. audit_type: a.audit_type,
  453. audit_ledger_id: a.audit_ledger_id,
  454. sp_group,
  455. });
  456. }
  457. await transaction.insert(this.tableName, insertDatas);
  458. }
  459. async getRemoveTenders(tenders) {
  460. const removeTenders = [];
  461. for (const tender of tenders) {
  462. const shenpiInfo = await this.ctx.service.tenderInfo.getTenderShenpiInfo(tender.id);
  463. if (!shenpiInfo) {
  464. removeTenders.push(tender.id);
  465. } else {
  466. tender.shenpiInfo = shenpiInfo;
  467. // 获取所有的固定审批流或固定终审
  468. const shenpiauditList = {};
  469. for (const shenpi in tender.shenpiInfo) {
  470. if (tender.shenpiInfo[shenpi] === shenpiConst.sp_status.gdspl) {
  471. const group = await this.ctx.service.shenpiGroup.getGroupBySelect(tender.id, shenpiConst.sp_type[shenpi]);
  472. const shenpiList = await this.getAuditList(tender.id, shenpiConst.sp_type[shenpi], tender.shenpiInfo[shenpi], group ? group.id : 0);
  473. const shenpiIdList = this._.map(shenpiList, 'audit_id');
  474. shenpiauditList[shenpi] = shenpiIdList.length ? shenpiIdList : null;
  475. } else if (tender.shenpiInfo[shenpi] === shenpiConst.sp_status.gdzs) {
  476. const shenpiInfo = await this.getDataByCondition({ tid: tender.id, sp_type: shenpiConst.sp_type[shenpi], sp_status: tender.shenpiInfo[shenpi] });
  477. shenpiauditList[shenpi] = shenpiInfo && shenpiInfo.audit_id ? [shenpiInfo.audit_id] : null;
  478. }
  479. }
  480. tender.shenpiauditList = shenpiauditList;
  481. }
  482. }
  483. return removeTenders;
  484. }
  485. async noYbShenpiList(uid, shenpiList) {
  486. // 剔除原报及分析审批流中的审批人
  487. const yBIndex = shenpiList.findIndex(x => { return x.audit_id === uid; });
  488. if (yBIndex !== -1) {
  489. const yB = shenpiList[yBIndex];
  490. if (yB.audit_type !== auditType.key.common) {
  491. // 如果是会签或签且人数只有2人,则audit_type变为common
  492. const curSps = shenpiList.filter(x => { return x.audit_order === yB.audit_order; });
  493. if (curSps.length === 1) {
  494. shenpiList.forEach(x => { if (x.audit_order > yB.audit_order) x.audit_order--; });
  495. } else if (curSps.length === 2) {
  496. curSps.forEach(x => { x.audit_type = auditType.key.common; });
  497. }
  498. } else {
  499. // 比它大的audit_order都要-1;
  500. shenpiList.forEach(x => { if (x.audit_order > yB.audit_order) x.audit_order--; });
  501. }
  502. shenpiList.splice(yBIndex, 1);
  503. }
  504. }
  505. async saveUnionAudit(tid, data) {
  506. const orgData = await this.getAllDataByCondition({ where: { id: data.map(x => { return x.id; }) } });
  507. for (const od of orgData) {
  508. if (od.tid !== tid) throw '保存数据错误,请刷新页面后重试';
  509. }
  510. const updateData = data.map(x => { return { id: x.id, audit_ledger_id: x.audit_ledger_id }; });
  511. if (updateData.length > 0) await this.db.updateRows(this.tableName, updateData);
  512. }
  513. }
  514. return ShenpiAudit;
  515. };