|
@@ -232,6 +232,7 @@ module.exports = app => {
|
|
|
case materialConst.exponent_status.shared_noNode: {
|
|
case materialConst.exponent_status.shared_noNode: {
|
|
|
const exponentInfo = await transaction.get(this.tableName, { id: data.id, tid: this.ctx.tender.id });
|
|
const exponentInfo = await transaction.get(this.tableName, { id: data.id, tid: this.ctx.tender.id });
|
|
|
if (!exponentInfo) throw '指数工料数据不存在';
|
|
if (!exponentInfo) throw '指数工料数据不存在';
|
|
|
|
|
+ this._checkRiskEditPermission(data, exponentInfo);
|
|
|
this._setEffectivePrice(exponentInfo, data);
|
|
this._setEffectivePrice(exponentInfo, data);
|
|
|
await transaction.update(this.tableName, data);
|
|
await transaction.update(this.tableName, data);
|
|
|
[result.ex_tp, result.ex_tax_tp, result.ex_expr] = await this.calcMaterialExTp(transaction);
|
|
[result.ex_tp, result.ex_tax_tp, result.ex_expr] = await this.calcMaterialExTp(transaction);
|
|
@@ -248,7 +249,9 @@ module.exports = app => {
|
|
|
if (info.needUp) {
|
|
if (info.needUp) {
|
|
|
result.exponentData = await transaction.select(this.tableName, { where: { id: data.id } });
|
|
result.exponentData = await transaction.select(this.tableName, { where: { id: data.id } });
|
|
|
}
|
|
}
|
|
|
- result.exponentShardData = await transaction.select(this.ctx.service.materialExponentShard.tableName, { where: { mid: this.ctx.material.id, mn_id, me_id: data.id } });
|
|
|
|
|
|
|
+ result.exponentShardData = await transaction.select(this.ctx.service.materialExponentShard.tableName, {
|
|
|
|
|
+ where: info.needCalc ? { mid: this.ctx.material.id } : { mid: this.ctx.material.id, mn_id, me_id: data.id },
|
|
|
|
|
+ });
|
|
|
result.nodeData = info.needCalc ? await transaction.select(this.ctx.service.materialExponentNode.tableName, { where: { mid: this.ctx.material.id } }) :
|
|
result.nodeData = info.needCalc ? await transaction.select(this.ctx.service.materialExponentNode.tableName, { where: { mid: this.ctx.material.id } }) :
|
|
|
await transaction.select(this.ctx.service.materialExponentNode.tableName, { where: { mid: this.ctx.material.id, id: mn_id } });
|
|
await transaction.select(this.ctx.service.materialExponentNode.tableName, { where: { mid: this.ctx.material.id, id: mn_id } });
|
|
|
break;
|
|
break;
|
|
@@ -262,7 +265,9 @@ module.exports = app => {
|
|
|
if (info.needUp) {
|
|
if (info.needUp) {
|
|
|
result.exponentData = await transaction.select(this.tableName, { where: { id: data.id } });
|
|
result.exponentData = await transaction.select(this.tableName, { where: { id: data.id } });
|
|
|
}
|
|
}
|
|
|
- result.exponentShardData = await transaction.select(this.ctx.service.materialExponentShard.tableName, { where: { mid: this.ctx.material.id, ms_id, me_id: data.id } });
|
|
|
|
|
|
|
+ result.exponentShardData = await transaction.select(this.ctx.service.materialExponentShard.tableName, {
|
|
|
|
|
+ where: info.needCalc ? { mid: this.ctx.material.id } : { mid: this.ctx.material.id, ms_id, me_id: data.id },
|
|
|
|
|
+ });
|
|
|
result.stageData = info.needCalc ? await transaction.select(this.ctx.service.materialStage.tableName, { where: { mid: this.ctx.material.id } }) :
|
|
result.stageData = info.needCalc ? await transaction.select(this.ctx.service.materialStage.tableName, { where: { mid: this.ctx.material.id } }) :
|
|
|
await transaction.select(this.ctx.service.materialStage.tableName, { where: { mid: this.ctx.material.id, id: ms_id } });
|
|
await transaction.select(this.ctx.service.materialStage.tableName, { where: { mid: this.ctx.material.id, id: ms_id } });
|
|
|
break;
|
|
break;
|
|
@@ -276,7 +281,9 @@ module.exports = app => {
|
|
|
if (info.needUp) {
|
|
if (info.needUp) {
|
|
|
result.exponentData = await transaction.select(this.tableName, { where: { id: data.id } });
|
|
result.exponentData = await transaction.select(this.tableName, { where: { id: data.id } });
|
|
|
}
|
|
}
|
|
|
- result.exponentShardData = await transaction.select(this.ctx.service.materialExponentShard.tableName, { where: { mid: this.ctx.material.id, ms_id, mn_id, me_id: data.id } });
|
|
|
|
|
|
|
+ result.exponentShardData = await transaction.select(this.ctx.service.materialExponentShard.tableName, {
|
|
|
|
|
+ where: info.needCalc ? { mid: this.ctx.material.id } : { mid: this.ctx.material.id, ms_id, mn_id, me_id: data.id },
|
|
|
|
|
+ });
|
|
|
result.stageData = info.needCalc ? await transaction.select(this.ctx.service.materialStage.tableName, { where: { mid: this.ctx.material.id } }) :
|
|
result.stageData = info.needCalc ? await transaction.select(this.ctx.service.materialStage.tableName, { where: { mid: this.ctx.material.id } }) :
|
|
|
await transaction.select(this.ctx.service.materialStage.tableName, { where: { mid: this.ctx.material.id, id: ms_id } });
|
|
await transaction.select(this.ctx.service.materialStage.tableName, { where: { mid: this.ctx.material.id, id: ms_id } });
|
|
|
result.nodeData = info.needCalc ? await transaction.select(this.ctx.service.materialExponentNode.tableName, { where: { mid: this.ctx.material.id } }) :
|
|
result.nodeData = info.needCalc ? await transaction.select(this.ctx.service.materialExponentNode.tableName, { where: { mid: this.ctx.material.id } }) :
|
|
@@ -284,9 +291,6 @@ module.exports = app => {
|
|
|
break;
|
|
break;
|
|
|
default: break;
|
|
default: break;
|
|
|
}
|
|
}
|
|
|
- if (this.ctx.material.order < this.ctx.material.highOrder && this.ctx.session.sessionUser.is_admin) {
|
|
|
|
|
- await this._syncHistoricalTotals(transaction);
|
|
|
|
|
- }
|
|
|
|
|
await transaction.commit();
|
|
await transaction.commit();
|
|
|
return result;
|
|
return result;
|
|
|
} catch (err) {
|
|
} catch (err) {
|
|
@@ -297,14 +301,15 @@ module.exports = app => {
|
|
|
|
|
|
|
|
async _updateOneExponentData(transaction, data, ms_id = null, mn_id = null) {
|
|
async _updateOneExponentData(transaction, data, ms_id = null, mn_id = null) {
|
|
|
// 当以下值和exponent值不相同时,需要同步更新最新的计算表达式和金额到stage表里,无需更新到exponentShard表
|
|
// 当以下值和exponent值不相同时,需要同步更新最新的计算表达式和金额到stage表里,无需更新到exponentShard表
|
|
|
- const updateColsArray = ['symbol', 'symbol_desc', 'code', 'basic_price', 'is_summary', 'basic_times'];
|
|
|
|
|
- const updateCalcArray = ['weight_num', 'basic_price', 'is_summary'];
|
|
|
|
|
|
|
+ const updateColsArray = ['symbol', 'symbol_desc', 'code', 'basic_price', 'm_up_risk', 'm_down_risk', 'is_summary', 'basic_times'];
|
|
|
|
|
+ const updateCalcArray = ['weight_num', 'basic_price', 'm_up_risk', 'm_down_risk', 'is_summary'];
|
|
|
let needCalc = false;
|
|
let needCalc = false;
|
|
|
let needUp = false;
|
|
let needUp = false;
|
|
|
const meInfo = await this.getDataById(data.id);
|
|
const meInfo = await this.getDataById(data.id);
|
|
|
if (!meInfo) {
|
|
if (!meInfo) {
|
|
|
throw '指数工料数据不存在';
|
|
throw '指数工料数据不存在';
|
|
|
}
|
|
}
|
|
|
|
|
+ this._checkRiskEditPermission(data, meInfo);
|
|
|
const updateData = {};
|
|
const updateData = {};
|
|
|
for (const uc of updateColsArray) {
|
|
for (const uc of updateColsArray) {
|
|
|
if (data[uc] !== undefined && data[uc] !== meInfo[uc]) {
|
|
if (data[uc] !== undefined && data[uc] !== meInfo[uc]) {
|
|
@@ -320,7 +325,7 @@ module.exports = app => {
|
|
|
updateData.id = data.id;
|
|
updateData.id = data.id;
|
|
|
await transaction.update(this.tableName, updateData);
|
|
await transaction.update(this.tableName, updateData);
|
|
|
}
|
|
}
|
|
|
- if (updateData.basic_price !== undefined) {
|
|
|
|
|
|
|
+ if (updateData.basic_price !== undefined || updateData.m_up_risk !== undefined || updateData.m_down_risk !== undefined) {
|
|
|
await this.ctx.service.materialExponentShard.resetEffectivePrice(transaction, [data.id]);
|
|
await this.ctx.service.materialExponentShard.resetEffectivePrice(transaction, [data.id]);
|
|
|
}
|
|
}
|
|
|
if (needCalc) {
|
|
if (needCalc) {
|
|
@@ -358,6 +363,7 @@ module.exports = app => {
|
|
|
for (const data of datas) {
|
|
for (const data of datas) {
|
|
|
const exponentInfo = this._.find(exponentList, { id: data.id });
|
|
const exponentInfo = this._.find(exponentList, { id: data.id });
|
|
|
if (!exponentInfo) throw '指数工料数据不存在';
|
|
if (!exponentInfo) throw '指数工料数据不存在';
|
|
|
|
|
+ this._checkRiskEditPermission(data, exponentInfo);
|
|
|
this._setEffectivePrice(exponentInfo, data);
|
|
this._setEffectivePrice(exponentInfo, data);
|
|
|
}
|
|
}
|
|
|
await transaction.updateRows(this.tableName, datas);
|
|
await transaction.updateRows(this.tableName, datas);
|
|
@@ -399,9 +405,6 @@ module.exports = app => {
|
|
|
break;
|
|
break;
|
|
|
default: break;
|
|
default: break;
|
|
|
}
|
|
}
|
|
|
- if (this.ctx.material.order < this.ctx.material.highOrder && this.ctx.session.sessionUser.is_admin) {
|
|
|
|
|
- await this._syncHistoricalTotals(transaction);
|
|
|
|
|
- }
|
|
|
|
|
await transaction.commit();
|
|
await transaction.commit();
|
|
|
return result;
|
|
return result;
|
|
|
} catch (err) {
|
|
} catch (err) {
|
|
@@ -410,113 +413,14 @@ module.exports = app => {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- async saveHistoryRisks(datas) {
|
|
|
|
|
- if (!this.ctx.session.sessionUser.is_admin || this.ctx.material.order >= this.ctx.material.highOrder) {
|
|
|
|
|
- throw '无权修改往期指数幅度';
|
|
|
|
|
- }
|
|
|
|
|
- const updateList = datas instanceof Array ? datas : [datas];
|
|
|
|
|
- const transaction = await this.db.beginTransaction();
|
|
|
|
|
- try {
|
|
|
|
|
- const historyIds = this._.map(updateList, 'id');
|
|
|
|
|
- const historyList = await transaction.select(this.ctx.service.materialExponentHistory.tableName, {
|
|
|
|
|
- where: { id: historyIds, mid: this.ctx.material.id, order: this.ctx.material.order },
|
|
|
|
|
- });
|
|
|
|
|
- const updates = [];
|
|
|
|
|
- for (const data of updateList) {
|
|
|
|
|
- const historyInfo = this._.find(historyList, { id: data.id });
|
|
|
|
|
- if (!historyInfo || historyInfo.type !== materialConst.ex_type[1].value) throw '往期指数工料数据不存在';
|
|
|
|
|
- const updateData = { id: historyInfo.id };
|
|
|
|
|
- if (data.m_up_risk !== undefined) updateData.m_up_risk = this._normalizeRisk(data.m_up_risk);
|
|
|
|
|
- if (data.m_down_risk !== undefined) updateData.m_down_risk = this._normalizeRisk(data.m_down_risk);
|
|
|
|
|
- if (Object.keys(updateData).length === 1) continue;
|
|
|
|
|
- updateData.effective_price = this.getEffectivePrice(Object.assign({}, historyInfo, updateData));
|
|
|
|
|
- const calcNum = historyInfo.basic_price > 0 ? this.ctx.helper.mul(historyInfo.weight_num, this.ctx.helper.div(updateData.effective_price, historyInfo.basic_price)) : 0;
|
|
|
|
|
- updateData.calc_num = calcNum ? this.ctx.helper.round(calcNum, this.ctx.material.exponent_decimal.qty) : calcNum;
|
|
|
|
|
- updates.push(updateData);
|
|
|
|
|
- }
|
|
|
|
|
- if (updates.length === 0) throw '上涨、下跌幅度未发生变化';
|
|
|
|
|
- await transaction.updateRows(this.ctx.service.materialExponentHistory.tableName, updates);
|
|
|
|
|
- const [ex_tp, ex_tax_tp, ex_expr] = await this._calcHistoryExTp(transaction);
|
|
|
|
|
- await this._syncHistoricalTotals(transaction);
|
|
|
|
|
- const historyData = await transaction.select(this.ctx.service.materialExponentHistory.tableName, { where: { id: this._.map(updates, 'id') } });
|
|
|
|
|
- await transaction.commit();
|
|
|
|
|
- return { ex_tp, ex_tax_tp, ex_expr, historyData };
|
|
|
|
|
- } catch (err) {
|
|
|
|
|
- await transaction.rollback();
|
|
|
|
|
- throw err;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- async _calcHistoryExTp(transaction) {
|
|
|
|
|
- let basicCalc = 0;
|
|
|
|
|
- const exCalc = this.ctx.material.ex_calc ? JSON.parse(this.ctx.material.ex_calc) : null;
|
|
|
|
|
- if (exCalc) {
|
|
|
|
|
- for (const calc of exCalc) {
|
|
|
|
|
- if (!calc.select) continue;
|
|
|
|
|
- basicCalc = this.ctx.helper.add(basicCalc, calc.code === 'zdy' && calc.result ? calc.result : calc.value);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- const exponentList = await transaction.select(this.ctx.service.materialExponentHistory.tableName, {
|
|
|
|
|
- where: { mid: this.ctx.material.id, order: this.ctx.material.order, is_summary: materialConst.is_summary.yes },
|
|
|
|
|
- });
|
|
|
|
|
- let expr = basicCalc + '*[';
|
|
|
|
|
- let sumByChange = 0;
|
|
|
|
|
- let constant = 0;
|
|
|
|
|
- for (const ex of exponentList) {
|
|
|
|
|
- if (ex.type === materialConst.ex_type[0].value) {
|
|
|
|
|
- constant = ex.weight_num || 0;
|
|
|
|
|
- expr += constant.toString();
|
|
|
|
|
- } else if (ex.type === materialConst.ex_type[1].value) {
|
|
|
|
|
- const effectivePrice = ex.effective_price !== null && ex.effective_price !== undefined ? ex.effective_price : ex.m_price;
|
|
|
|
|
- const calcNum = ex.basic_price > 0 ? this.ctx.helper.mul(ex.weight_num, this.ctx.helper.div(effectivePrice, ex.basic_price)) : 0;
|
|
|
|
|
- const change = calcNum ? this.ctx.helper.round(calcNum, this.ctx.material.exponent_decimal.qty) : 0;
|
|
|
|
|
- expr += change !== 0 ? '+' + ex.weight_num.toString() + '*(' + effectivePrice.toString() + '/' + ex.basic_price.toString() + ')' : '';
|
|
|
|
|
- sumByChange = this.ctx.helper.add(sumByChange, change);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- expr += '-1]';
|
|
|
|
|
- expr = constant !== 0 ? expr : null;
|
|
|
|
|
- const exTp = constant !== 0 ? this.ctx.helper.round(this.ctx.helper.mul(basicCalc, this.ctx.helper.sub(this.ctx.helper.add(constant, sumByChange), 1)), this.ctx.material.exponent_decimal.tp) : null;
|
|
|
|
|
- const exTaxTp = exTp !== null ? this.ctx.helper.round(this.ctx.helper.mul(exTp, 1 + this.ctx.material.exponent_rate / 100), this.ctx.material.exponent_decimal.tp) : null;
|
|
|
|
|
- await transaction.update(this.ctx.service.material.tableName, {
|
|
|
|
|
- id: this.ctx.material.id,
|
|
|
|
|
- ex_tp: exTp,
|
|
|
|
|
- ex_tax_tp: exTaxTp,
|
|
|
|
|
- ex_expr: expr,
|
|
|
|
|
- });
|
|
|
|
|
- return [exTp, exTaxTp, expr];
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- async _syncHistoricalTotals(transaction) {
|
|
|
|
|
- const materialList = await transaction.select(this.ctx.service.material.tableName, {
|
|
|
|
|
- where: { tid: this.ctx.tender.id },
|
|
|
|
|
- orders: [['order', 'asc']],
|
|
|
|
|
- });
|
|
|
|
|
- let exponentPreTp = 0;
|
|
|
|
|
- let exponentTaxPreTp = 0;
|
|
|
|
|
- const updates = [];
|
|
|
|
|
- for (const material of materialList) {
|
|
|
|
|
- updates.push({
|
|
|
|
|
- id: material.id,
|
|
|
|
|
- ex_pre_tp: exponentPreTp,
|
|
|
|
|
- ex_tax_pre_tp: exponentTaxPreTp,
|
|
|
|
|
- });
|
|
|
|
|
- exponentPreTp = this.ctx.helper.add(exponentPreTp, material.ex_tp || 0);
|
|
|
|
|
- exponentTaxPreTp = this.ctx.helper.add(exponentTaxPreTp, material.ex_tax_tp || 0);
|
|
|
|
|
- }
|
|
|
|
|
- if (updates.length > 0) await transaction.updateRows(this.ctx.service.material.tableName, updates);
|
|
|
|
|
- const tpData = await this.ctx.service.materialAudit.getTpData(transaction, this.ctx.material.id, this.ctx.material.decimal, this.ctx.material.exponent_decimal);
|
|
|
|
|
- await transaction.update(this.ctx.service.material.tableName, { id: this.ctx.material.id, tp_data: JSON.stringify(tpData) });
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
async _updateMoreExponentData(transaction, datas, result, meList, ms_id = null, mn_id = null) {
|
|
async _updateMoreExponentData(transaction, datas, result, meList, ms_id = null, mn_id = null) {
|
|
|
// 判断data值是否需要更新materialExponent和materialExponentShard
|
|
// 判断data值是否需要更新materialExponent和materialExponentShard
|
|
|
const mesCondition = { me_id: this._.map(datas, 'id') };
|
|
const mesCondition = { me_id: this._.map(datas, 'id') };
|
|
|
if (ms_id !== null) mesCondition.ms_id = ms_id;
|
|
if (ms_id !== null) mesCondition.ms_id = ms_id;
|
|
|
if (mn_id !== null) mesCondition.mn_id = mn_id;
|
|
if (mn_id !== null) mesCondition.mn_id = mn_id;
|
|
|
const mesList = await transaction.select(this.ctx.service.materialExponentShard.tableName, { where: mesCondition });
|
|
const mesList = await transaction.select(this.ctx.service.materialExponentShard.tableName, { where: mesCondition });
|
|
|
- const materialExponentColArray = ['symbol', 'symbol_desc', 'code', 'basic_price', 'is_summary', 'basic_times'];
|
|
|
|
|
- const materialExponentShardColArray = ['weight_num', 'm_up_risk', 'm_down_risk', 'm_price', 'remark'];
|
|
|
|
|
|
|
+ const materialExponentColArray = ['symbol', 'symbol_desc', 'code', 'basic_price', 'm_up_risk', 'm_down_risk', 'is_summary', 'basic_times'];
|
|
|
|
|
+ const materialExponentShardColArray = ['weight_num', 'm_price', 'remark'];
|
|
|
const updateCalcArray = ['weight_num', 'basic_price', 'm_up_risk', 'm_down_risk', 'm_price', 'is_summary'];
|
|
const updateCalcArray = ['weight_num', 'basic_price', 'm_up_risk', 'm_down_risk', 'm_price', 'is_summary'];
|
|
|
const updateMeArray = [];
|
|
const updateMeArray = [];
|
|
|
const udpateMseArray = [];
|
|
const udpateMseArray = [];
|
|
@@ -524,6 +428,8 @@ module.exports = app => {
|
|
|
for (const data of datas) {
|
|
for (const data of datas) {
|
|
|
const meInfo = this._.find(meList, { id: data.id });
|
|
const meInfo = this._.find(meList, { id: data.id });
|
|
|
const mseInfo = this._.find(mesList, { me_id: data.id });
|
|
const mseInfo = this._.find(mesList, { me_id: data.id });
|
|
|
|
|
+ if (!meInfo || !mseInfo) throw '指数工料数据不存在';
|
|
|
|
|
+ this._checkRiskEditPermission(data, meInfo);
|
|
|
for (const uc of materialExponentColArray) {
|
|
for (const uc of materialExponentColArray) {
|
|
|
if (data[uc] !== undefined && data[uc] !== meInfo[uc]) {
|
|
if (data[uc] !== undefined && data[uc] !== meInfo[uc]) {
|
|
|
const updateMe = this._.find(updateMeArray, { id: meInfo.id });
|
|
const updateMe = this._.find(updateMeArray, { id: meInfo.id });
|
|
@@ -566,10 +472,10 @@ module.exports = app => {
|
|
|
// const condition = mn_id ? { mid: this.ctx.material.id, mn_id } : { mid: this.ctx.material.id, ms_id };
|
|
// const condition = mn_id ? { mid: this.ctx.material.id, mn_id } : { mid: this.ctx.material.id, ms_id };
|
|
|
result.exponentShardData = await transaction.select(this.ctx.service.materialExponentShard.tableName, { where: { id: this._.map(udpateMseArray, 'id') } });
|
|
result.exponentShardData = await transaction.select(this.ctx.service.materialExponentShard.tableName, { where: { id: this._.map(udpateMseArray, 'id') } });
|
|
|
}
|
|
}
|
|
|
- const basicPriceMeIds = this._.map(this._.filter(updateMeArray, data => data.basic_price !== undefined), 'id');
|
|
|
|
|
- if (basicPriceMeIds.length > 0) {
|
|
|
|
|
- await this.ctx.service.materialExponentShard.resetEffectivePrice(transaction, basicPriceMeIds);
|
|
|
|
|
- result.exponentShardData = await transaction.select(this.ctx.service.materialExponentShard.tableName, { where: { mid: this.ctx.material.id, me_id: basicPriceMeIds } });
|
|
|
|
|
|
|
+ const sharedPriceMeIds = this._.map(this._.filter(updateMeArray, data => data.basic_price !== undefined || data.m_up_risk !== undefined || data.m_down_risk !== undefined), 'id');
|
|
|
|
|
+ if (sharedPriceMeIds.length > 0) {
|
|
|
|
|
+ await this.ctx.service.materialExponentShard.resetEffectivePrice(transaction, sharedPriceMeIds);
|
|
|
|
|
+ result.exponentShardData = await transaction.select(this.ctx.service.materialExponentShard.tableName, { where: { mid: this.ctx.material.id } });
|
|
|
}
|
|
}
|
|
|
return needCalc;
|
|
return needCalc;
|
|
|
}
|
|
}
|
|
@@ -817,12 +723,29 @@ module.exports = app => {
|
|
|
if (!materialExponent) continue;
|
|
if (!materialExponent) continue;
|
|
|
const updateEx = { id: ex.id };
|
|
const updateEx = { id: ex.id };
|
|
|
if (ex.m_price !== null && ex.m_price !== undefined) updateEx.m_price = this.ctx.helper.round(ex.m_price, decimal.up);
|
|
if (ex.m_price !== null && ex.m_price !== undefined) updateEx.m_price = this.ctx.helper.round(ex.m_price, decimal.up);
|
|
|
- updateEx.effective_price = this.getEffectivePrice(Object.assign({}, materialExponent, ex, updateEx), decimal.up);
|
|
|
|
|
|
|
+ updateEx.effective_price = this.getEffectivePrice(Object.assign({}, materialExponent, ex, updateEx, {
|
|
|
|
|
+ m_up_risk: materialExponent.m_up_risk,
|
|
|
|
|
+ m_down_risk: materialExponent.m_down_risk,
|
|
|
|
|
+ }), decimal.up);
|
|
|
if (updateEx.m_price !== ex.m_price || updateEx.effective_price !== ex.effective_price) updateStageArray.push(updateEx);
|
|
if (updateEx.m_price !== ex.m_price || updateEx.effective_price !== ex.effective_price) updateStageArray.push(updateEx);
|
|
|
}
|
|
}
|
|
|
if (updateArray.length > 0) await transaction.updateRows(this.tableName, updateArray);
|
|
if (updateArray.length > 0) await transaction.updateRows(this.tableName, updateArray);
|
|
|
if (updateStageArray.length > 0) await transaction.updateRows(this.ctx.service.materialExponentShard.tableName, updateStageArray);
|
|
if (updateStageArray.length > 0) await transaction.updateRows(this.ctx.service.materialExponentShard.tableName, updateStageArray);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ _checkRiskEditPermission(data, exponentInfo) {
|
|
|
|
|
+ const riskChanged = ['m_up_risk', 'm_down_risk'].some(col => data[col] !== undefined && data[col] !== exponentInfo[col]);
|
|
|
|
|
+ if (!riskChanged) return;
|
|
|
|
|
+ if (this.ctx.material.order < this.ctx.material.highOrder) {
|
|
|
|
|
+ throw '历史期上涨、下跌幅度不能修改';
|
|
|
|
|
+ }
|
|
|
|
|
+ if (exponentInfo.type !== materialConst.ex_type[1].value) {
|
|
|
|
|
+ throw '定值不能设置上涨、下跌幅度';
|
|
|
|
|
+ }
|
|
|
|
|
+ if (exponentInfo.mid !== this.ctx.material.id && !this.ctx.session.sessionUser.is_admin) {
|
|
|
|
|
+ throw '往期添加的指数工料仅管理员可修改上涨、下跌幅度';
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return MaterialExponent;
|
|
return MaterialExponent;
|