create or replace package body PG_PRD_CONFIG_BUZIRULE is
/*-- Private type declarations type is ; -- Private constant declarations constant := ; -- Private variable declarations ; -- Function and procedure implementations function ( ) return is ; begin ; return(); end;*/ function split(i_source_str in varchar2, --源字符串 i_regx in varchar2 default ',' --分隔符 ) return varchar_array is v_temp_str long := i_source_str || i_regx; -- v_tabStr varchar_array := varchar_array(); --需要返回的数组 begin while v_temp_str is not null loop v_tabStr.extend(1); v_tabStr(v_tabStr.count) := rtrim(substr(v_temp_str, 1, instr(v_temp_str, i_regx)), i_regx); v_temp_str := substr(v_temp_str, instr(v_temp_str, i_regx) + 1); end loop; return v_tabStr; end;
PROCEDURE ERROR(msg in varchar) as bad_credit EXCEPTION; begin IF 1 = 1 THEN RAISE bad_credit; END IF; EXCEPTION when OTHERS then raise_application_error(-20000, 'SQLCODE=' || SQLCODE || ',MSG=' || msg); end ERROR;
function convertFormula(i_formula in varchar2, --公式 i_ruleGenes in VARCHAR_ARRAY2 --计算因子 ) return varchar2 is v_returnValue varchar2(1000) := i_formula; --返回公式 begin if (v_returnValue is not null and length(trim(v_returnValue)) > 0) then --公式非空 for i in 1 .. i_ruleGenes.count loop v_returnValue := replace(v_returnValue, '[' || i_ruleGenes(i) (1) || ']', '[' || i_ruleGenes(i) (2) || ']'); end loop; end if; return v_returnValue; end;
/* Purpose : 用户配置业务规则 业务规则基本信息: i_rule_ofrId IN VARCHAR2, --销售品标识 tb_prd_ofr i_rule_oprTypeId in number --操作标识 tb_prd_operation_type_ref i_rule_funPoint in number, --规则触发点tb_prd_function_point i_rule_ruleName in varchar2, --业务规则名称 参考对象[允许有多个,之间以逗号分隔]: i_refObj_componentId in varchar2 --取值组件 TB_PRD_RULE_COMPONENT.type=1 i_refObj_componentfeaId in varchar2 --取值组件的属性 TB_PRD_RULE_COMP_FEA i_refObj_componentfeaValType in varchar2--组件取值的值类型,1:值;2:类型;3:长度 业务规则条件[允许有多个,之间以逗号分隔]: i_ruleCondition_operator in varchar2, --业务规则条件的操作符,1:<;2:>;3:=;4:<=;5:>=;6:!=; i_ruleCondition_leftFormula in varchar2, --业务规则条件的左边公式,引用参考对象或固定值,如[0]引用第一个refObj i_ruleCondition_rightFormula in varchar2 --业务规则条件的右边公式,引用参考对象或固定值,如[0]引用第一个refObj */ procedure configBusinessRule(i_rule_objId IN VARCHAR2, --对象标识,如主产品标识 i_rule_objType IN VARCHAR2, --对象类型,如主产品实例为T03 i_rule_oprTypeId in number, --操作标识 i_rule_funPoint in number, --规则触发点 i_rule_ruleName in varchar2, --业务规则名称 i_refObj_objName in varchar2, --参考对象名称 i_refObj_componentId in varchar2, --取值组件,如取用户的扩展属性,具体哪个属于由i_refObj_componentfeaId确定 i_refObj_componentfeaId in varchar2, --取值组件的属性,如取用户的产品密码(feaTypeCd=4) i_refObj_componentfeaValType in varchar2, --组件取值的值类型,1:值;2:类型;3:长度 i_ruleCondition_operator in varchar2, --业务规则条件的操作符,1:<;2:>;3:=;4:!=;5:<=;6:>=; i_ruleCondition_leftFormula in varchar2, --业务规则条件的左边公式,引用参考对象或固定值,如[0]引用第一个refObj i_ruleCondition_rightFormula in varchar2 --业务规则条件的右边公式,引用参考对象或固定值,如[0]引用第一个refObj ) is /*v_prdId number(9) := -1; --产品标识 */ v_tmpSql varchar2(500) := ''; --临时SQL v_oprRuleId number(9) := -1; --业务规则标识 varchar_array_refObj VARCHAR_ARRAY2 := VARCHAR_ARRAY2(); --参考对象 begin --1.获取业务规则标识 select SEQ_PRD_OPR_RULE_COMP_REL.Nextval into v_oprRuleId from dual; --2.插入业务规则记录 /*insert into TB_PRD_OPR_RULE_COMP_REL (OPR_RULE_ID, GROUP_ID, OPR_OBJECT_ID, OPR_OBJECT_TYPE, OPR_TYPE_ID, PRIORITY, RULE_COMPONENT_ID, AUDITING_FLAG, MESSAGE, RULE_ID, OFR_ID) values (97862, null, 1304, 'T03', '9', null, 243, '500008540', '欠费用户不允许移机', 2, null);*/ v_tmpSql := ' insert into TB_PRD_OPR_RULE_COMP_REL (OPR_RULE_ID, GROUP_ID, OPR_OBJECT_ID, OPR_OBJECT_TYPE, OPR_TYPE_ID, PRIORITY, RULE_COMPONENT_ID, AUDITING_FLAG, MESSAGE, RULE_ID, OFR_ID) values (:oprRuleId, null, :oprObjectId, :oprObjectType, :oprTypeId, null, 243, ''500008540'',:ruleName,:funPoint, null)'; execute immediate v_tmpSql using v_oprRuleId, i_rule_objId, i_rule_objType, i_rule_oprTypeId, i_rule_ruleName, i_rule_funPoint; --3.插入规则因子(规则参考对象) /*insert into TB_PRD_RULE_GENE (RULE_GENE_ID, RULE_GENE_NAME, RULE_COMPONENT_ID, OPRTYPEID, OPROBJECTTYPE, OPROBJECTID, OUTVLAUE, COMPFEAREFID, RULE_ID, DATA_TYPE) values (138706, 'CDMA产品号码', 242, null, null, null, '3', 5, 152055, '');*/ if (i_refObj_componentId is not null and length(trim(i_refObj_componentId)) > 0) then /*i_refObj_componentId*/ declare /*i_refObj_objName in varchar2, --参考对象名称 i_refObj_componentId in varchar2, --取值组件,如取用户的扩展属性,具体哪个属于由i_refObj_componentfeaId确定 i_refObj_componentfeaId in varchar2, --取值组件的属性,如取用户的产品密码(feaTypeCd=4) i_refObj_componentfeaValType in varchar2, --组件取值的值类型,1:值;2:类型;3:长度*/ varchar_array_objName varchar_array := split(i_refObj_objName, ','); --参考对象名称 varchar_array_componentId varchar_array := split(i_refObj_componentId, ','); --取值组件 varchar_array_componentfeaId varchar_array := split(i_refObj_componentfeaId, ','); --取值组件的属性 varchar_array_compfeaValType varchar_array := split(i_refObj_componentfeaValType, ','); --组件取值的值类型 v_arrayNum number(5) := -1; --数组个数 v_ruleComponentId number(9) := -1; --取值组件 v_ruleRefObjId number(9) := -1; --参考标识 v_oneRuleGene varchar_array := null; --需要返回的数组 v_refObj_componentFeaRelId number(9) := -1; --组件与属性关系标识 begin if (varchar_array_objName.count != varchar_array_componentId.count or varchar_array_componentId.count != varchar_array_componentfeaId.count or varchar_array_componentfeaId.count != varchar_array_compfeaValType.count) then ERROR('输入参数异常,请检查业务规则的参考对象!'); end if; /*varchar_array_cur2 */ /* select count(1) into v_arrayNum from varchar_array_cur2;*/ for i in 1 .. varchar_array_componentId.count loop --非空判断 if (varchar_array_componentId(i) is not null and length(trim(varchar_array_componentId(i))) > 0) then v_ruleComponentId := to_number(varchar_array_componentId(i)); /*用户暂存业务规则的因子*/ if (v_ruleComponentId is not null) then varchar_array_refObj.extend(1); v_oneRuleGene := VARCHAR_ARRAY(); v_oneRuleGene.extend(1); v_oneRuleGene(v_oneRuleGene.count) := varchar_array_refObj.count; --第一列为序号 select seq_rule_gene.nextval into v_ruleRefObjId from dual; v_oneRuleGene.extend(1); v_oneRuleGene(v_oneRuleGene.count) := v_ruleRefObjId; --第二列为因子标识 varchar_array_refObj(varchar_array_refObj.count) := v_oneRuleGene; end if; --查询组件与属性关系标识 SELECT to_number(a.id) into v_refObj_componentFeaRelId FROM TB_PRD_COMPONENT_FEA_REL a where a.rule_component_id = varchar_array_componentId(i) and a.fea_type_ref_id = varchar_array_componentfeaId(i) and rownum < 2; v_tmpSql := ' insert into TB_PRD_RULE_GENE (RULE_GENE_ID, RULE_GENE_NAME, RULE_COMPONENT_ID, OPRTYPEID, OPROBJECTTYPE, OPROBJECTID, OUTVLAUE, COMPFEAREFID, RULE_ID, DATA_TYPE) values (:ruleGeneId, :ruleGeneName, :ruleComponentId, null, null, null,:outValue, :compFeaRelId, :oprRuleId, null)'; execute immediate v_tmpSql using v_ruleRefObjId, varchar_array_objName(i), varchar_array_componentId(i), varchar_array_compfeaValType(i), v_refObj_componentFeaRelId, v_oprRuleId; end if; end loop; exception when others then DBMS_OUTPUT.PUT_LINE('i_refObj_componentId[' || i_refObj_componentId || '],插入规则因子异常:' || sqlerrm); end; end if; --4.插入规则因子(规则参考对象) /*insert into TB_PRD_RULE_GENE_REF (ID, OPR_RULE_ID, RULE_COMPONENT_ID, OPREXPRESS_LEFT, OPREXPRESS_RIGHT, OPRITION, RULE_GENE_ID, OPRTYPEID, OPROBJECTTYPE, OPROBJECTID) values (120864, 152055, 11, '[138706]', '0', '3', null, 28, 'T03', 1360); */ if (i_ruleCondition_operator is not null and length(trim(i_ruleCondition_operator)) > 0) then declare /*i_ruleCondition_operator in varchar2, --业务规则条件的操作符,1:<;2:>;3:=;4:!=;5:<=;6:>=; i_ruleCondition_leftFormula in varchar2, --业务规则条件的左边公式,引用参考对象或固定值,如[0]引用第一个refObj i_ruleCondition_rightFormula in varchar2 --业务规则条件的右边公式,引用参考对象或固定值,如[0]引用第一个refObj */ varchar_array_operator varchar_array := split(i_ruleCondition_operator, ','); --第二层分拆 varchar_array_leftFormula varchar_array := split(i_ruleCondition_leftFormula, ','); --第二层分拆 varchar_array_rightFormula varchar_array := split(i_ruleCondition_rightFormula, ','); --第二层分拆 /*varchar_array_cur typeCursor; --第一层分拆游标*/ v_arrayNum number(5) := -1; --数组个数 v_ruleComponentId number(9) := -1; --取值组件 v_ruleFormula number(9) := -1; --参考标识 begin if (varchar_array_operator.count != varchar_array_leftFormula.count or varchar_array_leftFormula.count != varchar_array_rightFormula.count) then ERROR('输入参数异常,请检查业务规则的参考对象!'); end if; /*varchar_array_cur2 */ /* select count(1) into v_arrayNum from varchar_array_cur2;*/ for i in 1 .. varchar_array_operator.count loop --非空判断 if (varchar_array_operator(i) is not null and length(trim(varchar_array_operator(i))) > 0) then select seq_rule_gene_ref.nextval into v_ruleFormula from dual; v_tmpSql := ' insert into TB_PRD_RULE_GENE_REF (ID, OPR_RULE_ID, RULE_COMPONENT_ID, OPREXPRESS_LEFT, OPREXPRESS_RIGHT, OPRITION, RULE_GENE_ID, OPRTYPEID, OPROBJECTTYPE, OPROBJECTID) values (:id, :oprRuleId, :ruleFunPoint, :left, :right, :operator, null, :oprTypeId, :objType, :objId)'; execute immediate v_tmpSql using v_ruleFormula, v_oprRuleId, i_rule_funPoint, convertFormula(varchar_array_leftFormula(i), varchar_array_refObj), convertFormula(varchar_array_rightFormula(i), varchar_array_refObj), i_ruleCondition_operator, i_rule_oprTypeId, i_rule_objType, i_rule_objId; end if; end loop; exception when others then DBMS_OUTPUT.PUT_LINE('i_refObj_componentId[' || i_refObj_componentId || '],插入规则因子异常:' || sqlerrm); end; end if; --5.更新业务规则表中的message字段,替换因子,如[1]替换为[ruleGeneId] declare v_rule_ruleName varchar2(100) := convertFormula(i_rule_ruleName, varchar_array_refObj); begin update TB_PRD_OPR_RULE_COMP_REL r set r.message = v_rule_ruleName where r.opr_rule_id = v_oprRuleId; end; end; end PG_PRD_CONFIG_BUZIRULE;
|