BopRuleEx.js 4.5 KB
Newer Older
fukai committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
import BigNumber from 'bignumber.js';
import moment from 'moment';

const  BopRules = window.BopRules

  function mergeRules(ruleA,ruleB){
    let rules = {}
    Object.assign(rules,ruleA)
  
    for(let key in ruleB){
      if(rules[key]){
        rules[key] =  [...rules[key],...ruleB[key]]
      }else{
        rules[key] =  [...ruleB[key]]
      }
    }
    return rules
  }

  function applyCommon(module){
    let rules = {}
    let suffix = module.substring(module.length - 3);
    if(this.model.mtabut.basflg){
      let bas = BopRules.checkRuleOfBAS().call({module:'BAS'+suffix}).call(this,this,moment,BigNumber)
      rules = bas;
    }
    if(this.model.mtabut.vrfflg){
      let vrf = BopRules.checkRuleOfVRF().call({module:'VRF'+suffix}).call(this,this,moment,BigNumber)
      rules = mergeRules(rules,vrf);
    }
    if(this.model.mtabut.dclflg){
      let dcl = BopRules.checkRuleOfDCL().call({module:'DCL'+suffix}).call(this,this,moment,BigNumber)
      rules = mergeRules(rules,dcl);
    }
    let mtabut = BopRules.checkRuleOfMTABUT().call({module:'MTABUT'+suffix}).call(this,this,moment,BigNumber)
    rules = mergeRules(rules,mtabut);
    return rules
  }

  BopRules.checkRuleOfdbaaddame=()=>function(module='DBAADD'){
    let rules = applyCommon.call(this,module)
    let self = BopRules.checkRuleOfDBA().call({module}).call(this,this,moment,BigNumber)
    rules = mergeRules(rules,self);
    return rules
  }

  BopRules.checkRuleOfdbbaddame=()=>function(module='DBBADD'){
    let rules = applyCommon.call(this,module)
    let self = BopRules.checkRuleOfDBB().call({module}).call(this,this,moment,BigNumber)
    rules = mergeRules(rules,self);
    return rules
  }

  BopRules.checkRuleOfdbcaddame=()=>function(module='DBCADD'){
    let rules = applyCommon.call(this,module)
    let self = BopRules.checkRuleOfDBC().call({module}).call(this,this,moment,BigNumber)
    rules = mergeRules(rules,self);
    return rules
  }

  BopRules.checkRuleOfdbdaddame=()=>function(module='DBDADD'){
    let rules = applyCommon.call(this,module)
    let self = BopRules.checkRuleOfDBD().call({module}).call(this,this,moment,BigNumber)
    rules = mergeRules(rules,self);
    return rules
  }

  BopRules.checkRuleOfdbeaddame=()=>function(module='DBEADD'){
    let rules = applyCommon.call(this,module)
    let self = BopRules.checkRuleOfDBE().call({module}).call(this,this,moment,BigNumber)
    rules = mergeRules(rules,self);
    return rules
  }

  BopRules.checkRuleOfdbfaddame=()=>function(module='DBFADD'){
    let rules = applyCommon.call(this,module)
    let self = BopRules.checkRuleOfDBF().call({module}).call(this,this,moment,BigNumber)
    rules = mergeRules(rules,self);
    return rules
  }


/*此处用于复用其他申报交易的函数
* 方式为动态构建一个this,将返回的规则路径映射为业务交易下的路径
*/
function convertSingle(bopFirstName,recName,buildFunc){
  var bopRecgrpName = recName.toLowerCase() + "grp";
  var trnName = recName.toLowerCase()+"add"
  //构建基础this对象
  var thiz = {
      model:{
          recgrp:this.model[bopFirstName][bopRecgrpName],
          mtabut:this.model[bopFirstName],
      },
      trnName:trnName,
      root:this,
      '$smsgbox':this.$smsgbox,
      '$msgbox':this.$msgbox,
      isCom:true,
      bopCode:bopFirstName,
      '$Api':this.$Api
      };
  var rules = buildFunc().call(thiz,recName.toUpperCase()+"COM");
  //重组rules,以解决key的问题
  var newRules = {}
  for(var key in rules){
      var newKey = key;
      if(key.startsWith("recgrp.")){
          newKey = bopFirstName + "." + bopRecgrpName + key.substring(6)
      }else if(key.startsWith("mtabut.")){
          newKey = bopFirstName + key.substring(6)
      }
      //新key赋值
      newRules[newKey] = rules[key]
  }
  return newRules
}  
  //映射组件模型下的规则
/*
BOPGAT DBA DBD     涉外/境内收入
BOPREM DBB DBE     境外/境内汇款
BOPPAY DBC DBF     对外/境内付款承兑
 */
  BopRules.checkRuleOfbopcoms=()=>function(bopName,recName){
    var buildFunc = null;
    switch (recName) {
        case 'DBA':buildFunc = BopRules.checkRuleOfdbaaddame;break;
        case 'DBD':buildFunc = BopRules.checkRuleOfdbdaddame;break;
        case 'DBB':buildFunc = BopRules.checkRuleOfdbbaddame;break;
        case 'DBE':buildFunc = BopRules.checkRuleOfdbeaddame;break;
        case 'DBC':buildFunc = BopRules.checkRuleOfdbcaddame;break;
        case 'DBF':buildFunc = BopRules.checkRuleOfdbfaddame;break;
    }
    var rules = convertSingle.call(this,bopName,recName,buildFunc);
    return rules
  }