|
@@ -8,6 +8,7 @@
|
|
|
* @version
|
|
|
*/
|
|
|
|
|
|
+const paramConst = require('../const/template_param');
|
|
|
module.exports = app => {
|
|
|
class TenderParam extends app.BaseService {
|
|
|
/**
|
|
@@ -21,6 +22,44 @@ module.exports = app => {
|
|
|
this.tableName = 'tender_param';
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ async _calculateNodeIndex(transaction, condition, globalParams, newParam) {
|
|
|
+ const nodeParams = await this.ctx.service.tenderParam.getAllDataByCondition({where: condition});
|
|
|
+ const nodeIndexes = await this.ctx.service.tenderIndex.getAllDataByCondition({where: condition});
|
|
|
+ if (newParam) {
|
|
|
+ for (const np of nodeParams) {
|
|
|
+ if (np.code === newParam.code) {
|
|
|
+ np.calc_value = newParam.value;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.ctx.service.indexCalc.calculate(nodeIndexes, globalParams, nodeParams);
|
|
|
+ for (const u of this.ctx.service.indexCalc.updateArr) {
|
|
|
+ await transaction.update(this.ctx.service.tenderIndex.tableName,
|
|
|
+ { eval_rule: u.eval_rule, value: u.value },
|
|
|
+ { where: { lib_id: u.lib_id, index_id: u.index_id } },
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async _calculateAllIndex(transaction, condition, newParam) {
|
|
|
+ const globalParams = await this.ctx.service.tenderParam.getAllDataByCondition({
|
|
|
+ where: {lib_id: condition.lib_id, node_id: paramConst.globalParamNodeId}
|
|
|
+ });
|
|
|
+ for (const gp of globalParams) {
|
|
|
+ if (gp.code === newParam.code) {
|
|
|
+ gp.calc_value = newParam.value;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ const nodes = await this.ctx.tenderNode.getAllDataByCondition({where: condition});
|
|
|
+ for (const node of nodes) {
|
|
|
+ condition.node_id = node.node_id;
|
|
|
+ await this._calculateNodeIndex(transaction, condition, globalParams);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 更新参数取值
|
|
|
* @param data
|
|
@@ -41,7 +80,18 @@ module.exports = app => {
|
|
|
calc_value: parseFloat(data.value),
|
|
|
};
|
|
|
await transaction.update(this.tableName, updateData, {where: condition});
|
|
|
- // to do 计算
|
|
|
+ if (condition.node_id === paramConst.globalParamNodeId) {
|
|
|
+ const calcCondition = { lib_id: condition.lib_id };
|
|
|
+ const calcData = { code: data.code, value: updateData.calc_value };
|
|
|
+ await this._calculateAllIndex(transaction, condition, calcData);
|
|
|
+ } else {
|
|
|
+ const globalParams = await this.ctx.service.tenderParam.getAllDataByCondition({
|
|
|
+ where: {lib_id: condition.lib_id, node_id: paramConst.globalParamNodeId}
|
|
|
+ });
|
|
|
+ const calcCondition = { lib_id: condition.lib_id, node_id: data.node_id };
|
|
|
+ const calcData = { code: data.code, value: updateData.calc_value };
|
|
|
+ await this._calculateNodeIndex(transaction, calcCondition, globalParams, calcData);
|
|
|
+ }
|
|
|
await transaction.commit();
|
|
|
return true;
|
|
|
} catch (err) {
|