|
@@ -374,6 +374,488 @@ module.exports = app => {
|
|
|
const result = await this.db.query(sql, param);
|
|
|
return result;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除变更清单(form 变更新增部位页)
|
|
|
+ * Tony Kang
|
|
|
+ * @param {String} transaction - 队列
|
|
|
+ * @param {String} tid - 标段id
|
|
|
+ * @param {Array} ids - id列表
|
|
|
+ * @param {String} column - id所属字段
|
|
|
+ * @param {String} mx_id - mx_id为空列删除
|
|
|
+ * @return {void}
|
|
|
+ */
|
|
|
+ async deleteDataByRevise(transaction, tid, ids, column = 'gcl_id', mx_id = 'hello') {
|
|
|
+ if (ids.length > 0) {
|
|
|
+ const addSql = mx_id === '' ? ' AND (`mx_id` is NULL OR `mx_id` = "")' : '';
|
|
|
+ const sql = 'SELECT `cid` FROM ?? WHERE `tid` = ? AND ' + column + ' in (' + this.ctx.helper.getInArrStrSqlFilter(ids) + ')' + addSql + ' GROUP BY `cid`';
|
|
|
+ const params = [this.tableName, tid];
|
|
|
+ const changes = await transaction.query(sql, params);
|
|
|
+ if (changes.length > 0) {
|
|
|
+ const delData = {
|
|
|
+ tid,
|
|
|
+ };
|
|
|
+ delData[column] = ids;
|
|
|
+ await transaction.delete(this.tableName, delData);
|
|
|
+ for (const c of changes) {
|
|
|
+ // 重算选了此清单的变更令已变更金额
|
|
|
+ await this.reCalcTp(transaction, c.cid);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改变更清单(form 变更新增部位页台账子节点清单编号编辑)
|
|
|
+ * Tony Kang
|
|
|
+ * @param {String} transaction - 队列
|
|
|
+ * @param {String} tid - 标段id
|
|
|
+ * @param {Array} datas - 更新列表
|
|
|
+ * @param {String} column - id所属字段
|
|
|
+ * @return {void}
|
|
|
+ */
|
|
|
+ async updateDataByReviseLedger(transaction, tid, datas, column = 'gcl_id') {
|
|
|
+ if (datas.length > 0) {
|
|
|
+ const ids = this._.map(datas, 'id');
|
|
|
+ const sql = 'SELECT ' + column + ' FROM ?? WHERE `tid` = ? AND ' + column + ' in (' + this.ctx.helper.getInArrStrSqlFilter(ids) + ') GROUP BY ' + column;
|
|
|
+ const params = [this.tableName, tid];
|
|
|
+ const changeAuditLists = await transaction.query(sql, params);
|
|
|
+ if (changeAuditLists.length > 0) {
|
|
|
+ const updateArr = [];
|
|
|
+ const cidList = [];
|
|
|
+ for (const ca of changeAuditLists) {
|
|
|
+ const d = this._.find(datas, { id: ca[column] });
|
|
|
+ if (d.id) {
|
|
|
+ const changePosNum = await transaction.count(this.ctx.service.changePos.tableName, { lid: d.id });
|
|
|
+ const updateCol = {};
|
|
|
+ if (column === 'gcl_id' && d.b_code !== undefined) updateCol.code = d.b_code;
|
|
|
+ if (column === 'gcl_id' && d.sgfh_qty !== undefined && changePosNum === 0) updateCol.oamount = d.sgfh_qty ? d.sgfh_qty : 0;
|
|
|
+ if (column === 'gcl_id' && d.unit_price !== undefined) updateCol.unit_price = d.unit_price ? d.unit_price : 0;
|
|
|
+ if (column === 'gcl_id' && d.unit !== undefined) updateCol.unit = d.unit;
|
|
|
+ if (column === 'gcl_id' && d.name !== undefined) updateCol.name = d.name;
|
|
|
+ if (d.code !== undefined && d.b_code === null) {
|
|
|
+ // 清单升级成了项目节,故删除变更已有的此清单,并找出需要重新计算的变更令
|
|
|
+ const sql = 'SELECT `cid` FROM ?? WHERE `tid` = ? AND ' + column + ' = ? GROUP BY `cid`';
|
|
|
+ const params = [this.tableName, tid, d.id];
|
|
|
+ const changes = await transaction.query(sql, params);
|
|
|
+ for (const c of changes) {
|
|
|
+ if (this._.indexOf(cidList, c.cid) === -1) {
|
|
|
+ cidList.push(c.cid);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ const delData = {
|
|
|
+ tid,
|
|
|
+ };
|
|
|
+ delData[column] = d.id;
|
|
|
+ await transaction.delete(this.tableName, delData);
|
|
|
+ } else {
|
|
|
+ const options = {
|
|
|
+ row: {},
|
|
|
+ where: {},
|
|
|
+ };
|
|
|
+ options.row = updateCol;
|
|
|
+ options.where[column] = d.id;
|
|
|
+ if (!this._.isEmpty(options.row)) updateArr.push(options);
|
|
|
+ if (updateCol.unit !== undefined || updateCol.unit_price !== undefined) {
|
|
|
+ const sql = 'SELECT `cid` FROM ?? WHERE `tid` = ? AND ' + column + ' = ? GROUP BY `cid`';
|
|
|
+ const params = [this.tableName, tid, d.id];
|
|
|
+ const changes = await transaction.query(sql, params);
|
|
|
+ for (const c of changes) {
|
|
|
+ if (this._.indexOf(cidList, c.cid) === -1) {
|
|
|
+ cidList.push(c.cid);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (updateArr.length > 0) await transaction.updateRows(this.tableName, updateArr);
|
|
|
+ if (cidList.length > 0) {
|
|
|
+ for (const c of cidList) {
|
|
|
+ await this.reCalcTp(transaction, c);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 针对项目节更新可能对清单影响判断,修正变更清单项目节编号,细目,单位工程,分部分项工程数据
|
|
|
+ for (const data of datas) {
|
|
|
+ const select = await transaction.get(this.ctx.service.changeLedger.tableName, { id: data.id });
|
|
|
+ if (select && select.is_leaf === 0) {
|
|
|
+ const lists = await this.ctx.service.changeLedger.getDataByFullPath(this.ctx.service.changeLedger.tableName, tid, select.full_path + '%', transaction);
|
|
|
+ const childLists = this._.filter(lists, { level: select.level + 1 }); // 细目or项目节编号更新
|
|
|
+ if (childLists.length > 0) {
|
|
|
+ const d = { xmj_code: '', xmj_jldy: '' };
|
|
|
+ if (select.code !== null) {
|
|
|
+ d.xmj_code = select.code;
|
|
|
+ d.xmj_jldy = select.name;
|
|
|
+ } else {
|
|
|
+ // 再找出上一个项目节节点并更新
|
|
|
+ this.newBills = false;
|
|
|
+ const parents = await this.ctx.service.changeLedger.getDataByKid(tid, select.ledger_pid);
|
|
|
+ d.xmj_code = parents.code;
|
|
|
+ d.xmj_jldy = parents.name;
|
|
|
+ }
|
|
|
+ for (const cl of childLists) {
|
|
|
+ await transaction.update(this.tableName, { xmj_code: d.xmj_code, xmj_jldy: d.xmj_jldy }, { where: { tid, gcl_id: cl.id } });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (select.code !== null && data.name !== undefined) { // 名称修改则可能影响几个数据
|
|
|
+ const secondChildLists = this._.filter(lists, { level: select.level + 2 }); // 分项工程更新
|
|
|
+ const thirdChildLists = this._.filter(lists, { level: select.level + 3 }); // 分部工程更新
|
|
|
+ const fourthChildLists = this._.filter(lists, { level: select.level + 4 }); // 单位工程更新
|
|
|
+ if (secondChildLists.length > 0) {
|
|
|
+ for (const sl of secondChildLists) {
|
|
|
+ await transaction.update(this.tableName, { xmj_fxgc: select.name }, { where: { tid, gcl_id: sl.id } });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (thirdChildLists.length > 0) {
|
|
|
+ for (const tl of thirdChildLists) {
|
|
|
+ await transaction.update(this.tableName, { xmj_fbgc: select.name }, { where: { tid, gcl_id: tl.id } });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (fourthChildLists.length > 0 && select.level === 2) {
|
|
|
+ for (const fl of fourthChildLists) {
|
|
|
+ await transaction.update(this.tableName, { xmj_dwgc: select.name }, { where: { tid, gcl_id: fl.id } });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改变更清单(form 变更新增部位页台账节点清单编号升降级)
|
|
|
+ * Tony Kang
|
|
|
+ * @param {String} transaction - 队列
|
|
|
+ * @param {String} tid - 标段id
|
|
|
+ * @param {Array} datas - 更新列表
|
|
|
+ * @param {String} column - id所属字段
|
|
|
+ * @return {void}
|
|
|
+ */
|
|
|
+ async updateDataByReviseLedgerUpDownLevel(transaction, tid, datas, column = 'gcl_id') {
|
|
|
+ if (datas.length > 0) {
|
|
|
+ console.log(datas);
|
|
|
+ // const ids = this._.map(datas, 'id');
|
|
|
+ // const sql = 'SELECT ' + column + ' FROM ?? WHERE `tid` = ? AND ' + column + ' in (' + this.ctx.helper.getInArrStrSqlFilter(ids) + ') GROUP BY ' + column;
|
|
|
+ // const params = [this.tableName, tid];
|
|
|
+ // const changeAuditLists = await transaction.query(sql, params);
|
|
|
+ // if (changeAuditLists.length > 0) {
|
|
|
+ // const updateArr = [];
|
|
|
+ // const cidList = [];
|
|
|
+ // for (const ca of changeAuditLists) {
|
|
|
+ // const d = this._.find(datas, { id: ca[column] });
|
|
|
+ // console.log(d);
|
|
|
+ // if (d.id) {
|
|
|
+ // const changePosNum = await transaction.count(this.ctx.service.changePos.tableName, { lid: d.id });
|
|
|
+ // const updateCol = {};
|
|
|
+ // if (column === 'gcl_id' && d.b_code !== undefined) updateCol.code = d.b_code;
|
|
|
+ // if (column === 'gcl_id' && d.sgfh_qty !== undefined && changePosNum === 0) updateCol.oamount = d.sgfh_qty ? d.sgfh_qty : 0;
|
|
|
+ // if (column === 'gcl_id' && d.unit_price !== undefined) updateCol.unit_price = d.unit_price ? d.unit_price : 0;
|
|
|
+ // if (column === 'gcl_id' && d.unit !== undefined) updateCol.unit = d.unit;
|
|
|
+ // if (column === 'gcl_id' && d.name !== undefined) updateCol.name = d.name;
|
|
|
+ // if (d.code !== undefined && d.b_code === null) {
|
|
|
+ // // 清单升级成了项目节,故删除变更已有的此清单,并找出需要重新计算的变更令
|
|
|
+ // const sql = 'SELECT `cid` FROM ?? WHERE `tid` = ? AND ' + column + ' = ? GROUP BY `cid`';
|
|
|
+ // const params = [this.tableName, tid, d.id];
|
|
|
+ // const changes = await transaction.query(sql, params);
|
|
|
+ // for (const c of changes) {
|
|
|
+ // if (this._.indexOf(cidList, c.cid) === -1) {
|
|
|
+ // cidList.push(c.cid);
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // const delData = {
|
|
|
+ // tid,
|
|
|
+ // };
|
|
|
+ // delData[column] = d.id;
|
|
|
+ // console.log(delData);
|
|
|
+ // await transaction.delete(this.tableName, delData);
|
|
|
+ // } else {
|
|
|
+ // const options = {
|
|
|
+ // row: {},
|
|
|
+ // where: {},
|
|
|
+ // };
|
|
|
+ // options.row = updateCol;
|
|
|
+ // options.where[column] = d.id;
|
|
|
+ // if (!this._.isEmpty(options.row)) updateArr.push(options);
|
|
|
+ // if (updateCol.unit !== undefined || updateCol.unit_price !== undefined) {
|
|
|
+ // const sql = 'SELECT `cid` FROM ?? WHERE `tid` = ? AND ' + column + ' = ? GROUP BY `cid`';
|
|
|
+ // const params = [this.tableName, tid, d.id];
|
|
|
+ // const changes = await transaction.query(sql, params);
|
|
|
+ // for (const c of changes) {
|
|
|
+ // if (this._.indexOf(cidList, c.cid) === -1) {
|
|
|
+ // cidList.push(c.cid);
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // console.log(updateArr, cidList);
|
|
|
+ // if (updateArr.length > 0) await transaction.updateRows(this.tableName, updateArr);
|
|
|
+ // if (cidList.length > 0) {
|
|
|
+ // for (const c of cidList) {
|
|
|
+ // await this.reCalcTp(transaction, c);
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // 针对项目节更新可能对清单影响判断,修正变更清单项目节编号,细目,单位工程,分部分项工程数据
|
|
|
+ // for (const data of datas) {
|
|
|
+ // const select = await transaction.get(this.ctx.service.changeLedger.tableName, { id: data.id });
|
|
|
+ // console.log(select);
|
|
|
+ // if (select && select.is_leaf === 0) {
|
|
|
+ // const lists = await this.ctx.service.changeLedger.getDataByFullPath(this.ctx.service.changeLedger.tableName, tid, select.full_path + '%', transaction);
|
|
|
+ // const childLists = this._.filter(lists, { level: select.level + 1 }); // 细目or项目节编号更新
|
|
|
+ // if (childLists.length > 0) {
|
|
|
+ // const d = { xmj_code: '', xmj_jldy: '' };
|
|
|
+ // if (select.code !== null) {
|
|
|
+ // d.xmj_code = select.code;
|
|
|
+ // d.xmj_jldy = select.name;
|
|
|
+ // } else {
|
|
|
+ // // 再找出上一个项目节节点并更新
|
|
|
+ // this.newBills = false;
|
|
|
+ // const parents = await this.ctx.service.changeLedger.getDataByKid(tid, select.ledger_pid);
|
|
|
+ // console.log('hello :', parents);
|
|
|
+ // d.xmj_code = parents.code;
|
|
|
+ // d.xmj_jldy = parents.name;
|
|
|
+ // }
|
|
|
+ // for (const cl of childLists) {
|
|
|
+ // await transaction.update(this.tableName, { xmj_code: d.xmj_code, xmj_jldy: d.xmj_jldy }, { where: { tid, gcl_id: cl.id } });
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // if (select.code !== null && data.name !== undefined) { // 名称修改则可能影响几个数据
|
|
|
+ // const secondChildLists = this._.filter(lists, { level: select.level + 2 }); // 分项工程更新
|
|
|
+ // const thirdChildLists = this._.filter(lists, { level: select.level + 3 }); // 分部工程更新
|
|
|
+ // const fourthChildLists = this._.filter(lists, { level: select.level + 4 }); // 单位工程更新
|
|
|
+ // if (secondChildLists.length > 0) {
|
|
|
+ // for (const sl of secondChildLists) {
|
|
|
+ // await transaction.update(this.tableName, { xmj_fxgc: select.name }, { where: { tid, gcl_id: sl.id } });
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // if (thirdChildLists.length > 0) {
|
|
|
+ // for (const tl of thirdChildLists) {
|
|
|
+ // await transaction.update(this.tableName, { xmj_fbgc: select.name }, { where: { tid, gcl_id: tl.id } });
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // if (fourthChildLists.length > 0) {
|
|
|
+ // for (const fl of fourthChildLists) {
|
|
|
+ // await transaction.update(this.tableName, { xmj_dwgc: select.name }, { where: { tid, gcl_id: fl.id } });
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改变更清单(form 变更新增部位页计量单元编辑)
|
|
|
+ * Tony Kang
|
|
|
+ * @param {String} transaction - 队列
|
|
|
+ * @param {String} tid - 标段id
|
|
|
+ * @param {Array} datas - 更新列表
|
|
|
+ * @param {String} column - id所属字段
|
|
|
+ * @return {void}
|
|
|
+ */
|
|
|
+ async updateDataByRevisePos(transaction, tid, datas, column = 'mx_id') {
|
|
|
+ if (datas.length > 0) {
|
|
|
+ const ids = this._.map(datas, 'id');
|
|
|
+ const sql = 'SELECT ' + column + ' FROM ?? WHERE `tid` = ? AND ' + column + ' in (' + this.ctx.helper.getInArrStrSqlFilter(ids) + ') GROUP BY ' + column;
|
|
|
+ const params = [this.tableName, tid];
|
|
|
+ const changeAuditLists = await transaction.query(sql, params);
|
|
|
+ if (changeAuditLists.length > 0) {
|
|
|
+ const updateArr = [];
|
|
|
+ for (const ca of changeAuditLists) {
|
|
|
+ const d = this._.find(datas, { id: ca[column] });
|
|
|
+ if (d.id) {
|
|
|
+ const updateCol = {};
|
|
|
+ if (column === 'mx_id' && d.name !== undefined) updateCol.bwmx = d.name;
|
|
|
+ if (column === 'mx_id' && d.sgfh_qty !== undefined) updateCol.oamount = d.sgfh_qty ? d.sgfh_qty : 0;
|
|
|
+ if (column === 'mx_id' && d.sgfh_qty === undefined && d.sgfh_expr === '') updateCol.oamount = 0;
|
|
|
+ const options = {
|
|
|
+ row: {},
|
|
|
+ where: {},
|
|
|
+ };
|
|
|
+ options.row = updateCol;
|
|
|
+ options.where[column] = d.id;
|
|
|
+ // if (!this._.isEmpty(updateCol)) await transaction.update(this.tableName, updateCol, options);
|
|
|
+ if (!this._.isEmpty(options.row)) updateArr.push(options);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ console.log(updateArr);
|
|
|
+ if (updateArr.length > 0) await transaction.updateRows(this.tableName, updateArr);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 重算变更令总金额(变更新增部位设置时使用)
|
|
|
+ * @param {String} transaction - 队列
|
|
|
+ * @param {String} cid - 变更令id
|
|
|
+ */
|
|
|
+ async reCalcTp(transaction, cid) {
|
|
|
+ const change = await transaction.get(this.ctx.service.change.tableName, { cid });
|
|
|
+ let count = '';
|
|
|
+ if (change.status === audit.flow.status.uncheck || change.status === audit.flow.status.back || change.status === audit.flow.status.revise) {
|
|
|
+ count = '`camount`';
|
|
|
+ } else if (change.status === audit.flow.status.checking || change.status === audit.flow.status.backnew) {
|
|
|
+ count = '`spamount`';
|
|
|
+ }
|
|
|
+ if (count) {
|
|
|
+ const sql = 'SELECT `unit_price`, ' + count + ' as `count` FROM ?? WHERE `cid` = ?';
|
|
|
+ const params = [this.tableName, change.cid];
|
|
|
+ const caLists = await transaction.query(sql, params);
|
|
|
+ let tp = 0;
|
|
|
+ const tpUnit = change.tp_decimal ? change.tp_decimal : this.ctx.tender.info.decimal.tp;
|
|
|
+ for (const ca of caLists) {
|
|
|
+ const catp = this.ctx.helper.round(this.ctx.helper.mul(ca.unit_price, ca.count), tpUnit);
|
|
|
+ tp = this.ctx.helper.add(tp, catp);
|
|
|
+ }
|
|
|
+ console.log(tp);
|
|
|
+ if (tp !== change.total_price) {
|
|
|
+ const options = {
|
|
|
+ where: {
|
|
|
+ cid: change.cid,
|
|
|
+ },
|
|
|
+ };
|
|
|
+ const change_update = {
|
|
|
+ total_price: tp,
|
|
|
+ };
|
|
|
+ await transaction.update(this.ctx.service.change.tableName, change_update, options);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async updateToLedger(transaction, tid, cid) {
|
|
|
+ // 找出本条变更属于新增部位的数据
|
|
|
+ const sql = 'SELECT a.* FROM ?? a LEFT JOIN ?? b ON a.id = b.gcl_id WHERE b.tid = ? AND b.cid = ? GROUP BY a.id';
|
|
|
+ const sqlParam = [this.ctx.service.changeLedger.tableName, this.tableName, tid, cid];
|
|
|
+ const result = await transaction.query(sql, sqlParam);
|
|
|
+ const sql2 = 'SELECT a.* FROM ?? a LEFT JOIN ?? b ON a.id = b.mx_id WHERE b.tid = ? AND b.cid = ?';
|
|
|
+ const sqlParam2 = [this.ctx.service.changePos.tableName, this.tableName, tid, cid];
|
|
|
+ const result2 = await transaction.query(sql2, sqlParam2);
|
|
|
+ if (result.length > 0 || result2.length > 0) {
|
|
|
+ const changeLedgerGclIdList = this._.map(result, 'id');
|
|
|
+ const changeLedgerIdList = this._.uniq(this._.map(result, 'ledger_pid'));// 父节点集合
|
|
|
+ const needUpdateLedgerList = [];// 找出需要更新的原台账清单的id
|
|
|
+ const needUpdateChangeLedgerList = [];// 找出需要更新的新台账清单的id
|
|
|
+ const tpDecimal = this.ctx.tender.info.decimal.tp;
|
|
|
+ // 要更新的ledger节点,数量及总数
|
|
|
+ for (const data of result2) {
|
|
|
+ if (this._.indexOf(changeLedgerGclIdList, data.lid) === -1) {
|
|
|
+ const info = this._.find(needUpdateLedgerList, { id: data.lid });
|
|
|
+ if (info) {
|
|
|
+ info.quantity = this.ctx.helper.add(info.quantity, data.quantity);
|
|
|
+ } else {
|
|
|
+ needUpdateLedgerList.push({ id: data.lid, quantity: data.quantity });
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ const info = this._.find(needUpdateChangeLedgerList, { id: data.lid });
|
|
|
+ if (info) {
|
|
|
+ info.quantity = this.ctx.helper.add(info.quantity, data.quantity);
|
|
|
+ } else {
|
|
|
+ needUpdateChangeLedgerList.push({ id: data.lid, quantity: data.quantity });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 更新到result上
|
|
|
+ if (needUpdateChangeLedgerList.length > 0) {
|
|
|
+ for (const nucl of needUpdateChangeLedgerList) {
|
|
|
+ const now = this._.find(result, { id: nucl.id });
|
|
|
+ now.quantity = nucl.quantity;
|
|
|
+ now.sgfh_qty = nucl.quantity;
|
|
|
+ now.sgfh_tp = this.ctx.helper.mul(now.sgfh_qty, now.unit_price, tpDecimal);
|
|
|
+ now.total_price = this.ctx.helper.mul(now.quantity, now.unit_price, tpDecimal);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 更新到ledger上
|
|
|
+ if (needUpdateLedgerList.length > 0) {
|
|
|
+ for (const nul of needUpdateLedgerList) {
|
|
|
+ const ledgerInfo = await this.ctx.service.ledger.getDataById(nul.id);
|
|
|
+ ledgerInfo.quantity = this.ctx.helper.add(ledgerInfo.quantity, nul.quantity);
|
|
|
+ ledgerInfo.sgfh_qty = this.ctx.helper.add(ledgerInfo.sgfh_qty, nul.quantity);
|
|
|
+ ledgerInfo.sgfh_tp = this.ctx.helper.mul(ledgerInfo.sgfh_qty, ledgerInfo.unit_price, tpDecimal);
|
|
|
+ ledgerInfo.total_price = this.ctx.helper.mul(ledgerInfo.quantity, ledgerInfo.unit_price, tpDecimal);
|
|
|
+ await transaction.update(this.ctx.service.ledger.tableName, ledgerInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 找出所有新增的父节点并插入到result中
|
|
|
+ for (const r of changeLedgerIdList) {
|
|
|
+ await this._findParents(transaction, tid, r, result);
|
|
|
+ }
|
|
|
+ // 插入到计量单元表,并删除变更的计量单元数据, 插入清单表,并删除变更的清单表
|
|
|
+ await this._insertByChangeRevise(transaction, tid, result, result2);
|
|
|
+ // 更新标段总金额
|
|
|
+ const sumSql = 'SELECT Sum(total_price) As total_price, Sum(deal_tp) As deal_tp' +
|
|
|
+ ' FROM ' + this.ctx.service.ledger.tableName + this.ctx.helper.whereSql({ tender_id: tid });
|
|
|
+ const sum = await transaction.queryOne(sumSql);
|
|
|
+ await transaction.update(this.ctx.service.tender.tableName, {
|
|
|
+ id: tid,
|
|
|
+ total_price: sum.total_price,
|
|
|
+ deal_tp: sum.deal_tp,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async _findParents(transaction, tid, id, result) {
|
|
|
+ const info = await transaction.get(this.ctx.service.changeLedger.tableName, { tender_id: tid, ledger_id: id });
|
|
|
+ if (info && this._.findIndex(result, { ledger_id: info.id }) === -1) {
|
|
|
+ result.push(info);
|
|
|
+ await this._findParents(transaction, tid, info.ledger_pid, result);
|
|
|
+ } else {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async _insertByChangeRevise(transaction, tid, ledgerList, posList) {
|
|
|
+ if (ledgerList.length > 0) {
|
|
|
+ const insertLedgerArr = [];
|
|
|
+ for (const l of ledgerList) {
|
|
|
+ const insertL = [
|
|
|
+ l.id, l.code, l.b_code, l.name, l.unit, l.source, l.remark, l.ledger_id,
|
|
|
+ l.ledger_pid, l.level, l.order, l.full_path, l.is_leaf, l.quantity, l.total_price,
|
|
|
+ l.unit_price, l.drawing_code, l.memo, l.dgn_qty1, l.dgn_qty2, l.deal_qty, l.deal_tp,
|
|
|
+ l.sgfh_qty, l.sgfh_tp, l.sjcl_qty, l.sjcl_tp, l.qtcl_qty, l.qtcl_tp, l.node_type, l.crid,
|
|
|
+ l.tender_id, l.is_tp, l.sgfh_expr, l.sjcl_expr, l.qtcl_expr, l.check_calc, l.gxby_status,
|
|
|
+ l.dagl_status, l.dagl_url, l.gxby_limit, l.dagl_limit, l.ex_memo1, l.ex_memo2, l.ex_memo3,
|
|
|
+ ];
|
|
|
+ insertLedgerArr.push('(' + this.ctx.helper.getInArrStrSqlFilter(insertL) + ')');
|
|
|
+ await transaction.delete(this.ctx.service.changeLedger.tableName, { id: l.id });
|
|
|
+ }
|
|
|
+ const bSql = 'Insert Into ' +
|
|
|
+ this.ctx.service.ledger.tableName +
|
|
|
+ ' (id, code, b_code, name, unit, source, remark, ledger_id, ledger_pid, level, `order`, full_path, is_leaf,' +
|
|
|
+ ' quantity, total_price, unit_price, drawing_code, memo, dgn_qty1, dgn_qty2, deal_qty, deal_tp,' +
|
|
|
+ ' sgfh_qty, sgfh_tp, sjcl_qty, sjcl_tp, qtcl_qty, qtcl_tp, node_type, crid, tender_id, is_tp,' +
|
|
|
+ ' sgfh_expr, sjcl_expr, qtcl_expr, check_calc,' +
|
|
|
+ ' gxby_status, dagl_status, dagl_url, gxby_limit, dagl_limit,' +
|
|
|
+ ' ex_memo1, ex_memo2, ex_memo3) VALUES ' + insertLedgerArr.join(',') + ';';
|
|
|
+ await transaction.query(bSql, []);
|
|
|
+ }
|
|
|
+ if (posList.length > 0) {
|
|
|
+ const insertPosArr = [];
|
|
|
+ for (const p of posList) {
|
|
|
+ const insertp = [
|
|
|
+ p.id, p.tid, p.lid, p.name, p.drawing_code, p.quantity, p.add_stage, p.add_times,
|
|
|
+ p.add_user, p.sgfh_qty, p.sjcl_qty, p.qtcl_qty, p.crid, p.porder, p.position,
|
|
|
+ p.sgfh_expr, p.sjcl_expr, p.qtcl_expr, p.real_qty,
|
|
|
+ p.gxby_status, p.dagl_status, p.dagl_url, p.gxby_limit, p.dagl_limit,
|
|
|
+ p.ex_memo1, p.ex_memo2, p.ex_memo3,
|
|
|
+ ];
|
|
|
+ insertPosArr.push('(' + this.ctx.helper.getInArrStrSqlFilter(insertp) + ')');
|
|
|
+ await transaction.delete(this.ctx.service.changePos.tableName, { id: p.id });
|
|
|
+ }
|
|
|
+ const pSql =
|
|
|
+ 'Insert Into ' +
|
|
|
+ this.ctx.service.pos.tableName +
|
|
|
+ ' (id, tid, lid, name, drawing_code, quantity, add_stage, add_times, add_user,' +
|
|
|
+ ' sgfh_qty, sjcl_qty, qtcl_qty, crid, porder, position, ' +
|
|
|
+ ' sgfh_expr, sjcl_expr, qtcl_expr, real_qty,' +
|
|
|
+ ' gxby_status, dagl_status, dagl_url, gxby_limit, dagl_limit,' +
|
|
|
+ ' ex_memo1, ex_memo2, ex_memo3) VALUES ' + insertPosArr.join(',') + ';';
|
|
|
+ await transaction.query(pSql, []);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return ChangeAuditList;
|