-- drop trigger TR_toSyncAgencyinfo;
-- 摘要:当bas_agency_info新增数据时,同步到ele_agency,字段对应逻辑如下(insert)
-- 当bas_agency_info修改数据时,使用自治事务(AUTONOMOUS_TRANSACTION,该触发器不会影响TR_BAS_AGENCY_INFO触发器(华清),属于两个不同事务),先将ele_agency中对应数据进行删除,然后在执行新增逻辑(update)
-- 当bas_agency_info删除数据时,直接根据agency_id 去ele_agency中进行删除(delete)
-- 注:以后如果优化好了,统一了单位表,请将该触发器删除!!
CREATE
OR REPLACE TRIGGER TR_toSyncAgencyinfo before INSERT OR update or delete ON bas_agency_info FOR EACH ROW
Declare
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
case
when inserting then
INSERT INTO ele_agency (
IN_CODE,
IS_LEAF,
CODE1,
CODE2,
CODE3,
CODE4,
CODE5,
CODE6,
TENANT_ID,
START_DATE,
END_DATE,
ORIGIN_ID,
LAST_VER,
CREATE_USER,
CREATE_DATE,
IS_DELETED,
IS_FISAGENCY,
FINANCE_CHARGE,
TEL,
FAX,
ADDR,
ZIP_CODE,
NUM_BANKACT,
IS_REFORM,
IS_BUDGET,
IS_INAGENCY,
IS_INCOM,
NO_BUYBILL,
BILL_CHARGE,
TEL_BILLCHARGE,
IS_BUYBILL,
COST_ISBUYBILL,
TYPE_INCAGCY,
IS_MUTFUNC,
SB_CALC_TYPE,
XZ_EXP_FUNC_CODE,
XZ_EXP_FUNC_NAME,
SY_EXP_FUNC_CODE,
SY_EXP_FUNC_NAME,
ORG_CODE,
PER_CONDITION,
FDST_ARCHIVES,
FDST_REALITY,
SAL_MODE,
GYXGW,
DEHDS,
MOF,
AGENCY_KIND_CODE,
IND_TYPE,
IS_MERITPAY,
UPLOAD_AGENCY_CODE,
AGENCY_LEVEL,
IS_LOCAL,
DISP_ORDER,
REGION_CODE,
LINKNAME,
ADDRESS,
REMARK,
TELEPHONE,
ELE_CODE,
UPDATE_TIME,
ACCT_SET_ID,
IS_FORM_DEP_FINAL_ACC,
IS_FORM_GOV_DEP_FINANCE_REP,
IS_FORM_A_AGY_STATE_ASS_REP,
IS_SECRET,
AGENCY_SYSTEM,
REAL_DELETE,
ICON,
FISCAL_YEAR,
AGENCY_KIND_NAME,
ID1,
ID2,
ID3,
ID4,
ID5,
ID6,
PARENT_ID,
ELEMENT_ID,
AGENCY_KIND_ID,
XZ_EXP_FUNC_ID,
SY_EXP_FUNC_ID,
MOF_DEP_ID,
ELE_ID,
ELE_NAME,
ELE_CATALOG_ID,
MOF_DIV_CODE,
LEVEL_NO,
IS_ENABLED,
IS_STANDARD,
CREATE_TIME
)
VALUES
(
: NEW.agency_code,
: NEW.IS_LEAF,
substr( : NEW.agency_code, 1, 3 ),
decode( : NEW.agency_level_code, 1, '', substr( : NEW.agency_code, 1, 6 ) ),
decode( : NEW.agency_level_code, 1, '', 2, '', substr( : NEW.agency_code, 1, 9 ) ),
decode(
: NEW.agency_level_code,
1,
'',
2,
'',
3,
'',
substr( : NEW.agency_code, 1, 12 )
),
decode(
: NEW.agency_level_code,
1,
'',
2,
'',
3,
'',
4,
'',
substr( : NEW.agency_code, 1, 15 )
) ,
'',
to_number ( : NEW.mof_div_code ),
to_date ( ( CASE WHEN : NEW.START_DATE IS NULL THEN '29991231' ELSE : NEW.START_DATE END ), 'yyyyMMdd' ),
to_date (
(
CASE
WHEN trim( : NEW.END_DATE ) IS NULL
OR trim( : NEW.END_DATE ) = '' THEN
'29991231' ELSE : NEW.end_date
END
),
'yyyyMMdd'
),
to_number ( '' ),
to_number ( '' ),
to_number ( '' ),
to_date ( substr( : NEW.create_time, 0, 8 ), 'yyyyMMdd' ),
: NEW.IS_DELETED,
to_number ( '' ),
'',
'',
'',
'',
'',
'',
to_number ( '' ),
to_number ( '' ),
to_number ( '' ),
to_number ( '' ),
'',
'',
'',
to_number ( '' ),
to_number ( '' ),
to_number ( '' ),
to_number ( '' ),
'',
'',
'',
'',
'',
'',
to_number ( '' ),
to_number ( '' ),
to_number ( '' ),
1,
to_number ( '' ),
to_number ( '' ),
'',
: NEW.AGENCY_TYPE_CODE,
'',
to_number ( '' ),
'',
to_number ( '' ),
to_number ( '' ),
to_number ( '' ),
'',
'',
'',
'',
to_number ( '' ),
: NEW.agency_code,
to_date ( substr( : NEW.create_time, 0, 8 ), 'yyyyMMdd' ),
to_number ( '' ),
to_number ( '' ),
to_number ( '' ),
to_number ( '' ),
to_number ( '' ),
'',
to_number ( '' ),
'',
: NEW.YEAR,
( SELECT a.ele_name FROM ele_agency_type a WHERE a.ele_code =: NEW.AGENCY_TYPE_CODE ),
(SELECT
c.agency_id
FROM
bas_agency_info c
WHERE
c.is_deleted <> 1
AND c.mof_div_code =: NEW.mof_div_code
AND c.agency_code = substr( : NEW.agency_code, 1, 3 ) and rownum=1),
(case when : NEW.agency_level_code=1 then '' else (select c.agency_id from bas_agency_info c where c.is_deleted<>1 and c.mof_div_code=: NEW.mof_div_code and c.agency_code=substr(: NEW.agency_code,1,6) and rownum=1) end),
(case when : NEW.agency_level_code=2 then '' else (select c.agency_id from bas_agency_info c where c.is_deleted<>1 and c.mof_div_code=: NEW.mof_div_code and c.agency_code=substr(: NEW.agency_code,1,9) and rownum=1) end),
(case when : NEW.agency_level_code=3 then '' else (select c.agency_id from bas_agency_info c where c.is_deleted<>1 and c.mof_div_code=: NEW.mof_div_code and c.agency_code=substr(: NEW.agency_code,1,12) and rownum=1) end),
(case when : NEW.agency_level_code=4 then '' else (select c.agency_id from bas_agency_info c where c.is_deleted<>1 and c.mof_div_code=: NEW.mof_div_code and c.agency_code=substr(: NEW.agency_code,1,15) and rownum=1) end),
(case when : NEW.agency_level_code=5 then '' else (select c.agency_id from bas_agency_info c where c.is_deleted<>1 and c.mof_div_code=: NEW.mof_div_code and c.agency_code=substr(: NEW.agency_code,1,18) and rownum=1) end),
(case when : NEW.PARENT_ID is null then '0' else : NEW.PARENT_ID end ),
'',
(select a.ele_id from ele_agency_type a where a.ele_code=: NEW.AGENCY_TYPE_CODE),
'','',
(select a.id from gap_ele_mof_dep a where A.TENANT_ID=: NEW.MOF_DIV_CODE AND a.code=: NEW.MOF_DEP_CODE and a.is_deleted!=1),
: NEW.agency_id,: NEW.agency_name,'22',
: NEW.MOF_DIV_CODE,
to_number(: NEW.LEVEL_NO),
1,1,
to_date(substr(: NEW.create_time, 0, 8), 'yyyyMMdd')
);
when updating then
delete ELE_AGENCY where ELE_ID = : NEW.agency_id;
INSERT INTO ele_agency (
IN_CODE,
IS_LEAF,
CODE1,
CODE2,
CODE3,
CODE4,
CODE5,
CODE6,
TENANT_ID,
START_DATE,
END_DATE,
ORIGIN_ID,
LAST_VER,
CREATE_USER,
CREATE_DATE,
IS_DELETED,
IS_FISAGENCY,
FINANCE_CHARGE,
TEL,
FAX,
ADDR,
ZIP_CODE,
NUM_BANKACT,
IS_REFORM,
IS_BUDGET,
IS_INAGENCY,
IS_INCOM,
NO_BUYBILL,
BILL_CHARGE,
TEL_BILLCHARGE,
IS_BUYBILL,
COST_ISBUYBILL,
TYPE_INCAGCY,
IS_MUTFUNC,
SB_CALC_TYPE,
XZ_EXP_FUNC_CODE,
XZ_EXP_FUNC_NAME,
SY_EXP_FUNC_CODE,
SY_EXP_FUNC_NAME,
ORG_CODE,
PER_CONDITION,
FDST_ARCHIVES,
FDST_REALITY,
SAL_MODE,
GYXGW,
DEHDS,
MOF,
AGENCY_KIND_CODE,
IND_TYPE,
IS_MERITPAY,
UPLOAD_AGENCY_CODE,
AGENCY_LEVEL,
IS_LOCAL,
DISP_ORDER,
REGION_CODE,
LINKNAME,
ADDRESS,
REMARK,
TELEPHONE,
ELE_CODE,
UPDATE_TIME,
ACCT_SET_ID,
IS_FORM_DEP_FINAL_ACC,
IS_FORM_GOV_DEP_FINANCE_REP,
IS_FORM_A_AGY_STATE_ASS_REP,
IS_SECRET,
AGENCY_SYSTEM,
REAL_DELETE,
ICON,
FISCAL_YEAR,
AGENCY_KIND_NAME,
ID1,
ID2,
ID3,
ID4,
ID5,
ID6,
PARENT_ID,
ELEMENT_ID,
AGENCY_KIND_ID,
XZ_EXP_FUNC_ID,
SY_EXP_FUNC_ID,
MOF_DEP_ID,
ELE_ID,
ELE_NAME,
ELE_CATALOG_ID,
MOF_DIV_CODE,
LEVEL_NO,
IS_ENABLED,
IS_STANDARD,
CREATE_TIME
)
VALUES
(
: NEW.agency_code,
: NEW.IS_LEAF,
substr( : NEW.agency_code, 1, 3 ),
decode( : NEW.agency_level_code, 1, '', substr( : NEW.agency_code, 1, 6 ) ),
decode( : NEW.agency_level_code, 1, '', 2, '', substr( : NEW.agency_code, 1, 9 ) ),
decode(
: NEW.agency_level_code,
1,
'',
2,
'',
3,
'',
substr( : NEW.agency_code, 1, 12 )
),
decode(
: NEW.agency_level_code,
1,
'',
2,
'',
3,
'',
4,
'',
substr( : NEW.agency_code, 1, 15 )
) ,
'',
to_number ( : NEW.mof_div_code ),
to_date ( ( CASE WHEN : NEW.START_DATE IS NULL THEN '29991231' ELSE : NEW.START_DATE END ), 'yyyyMMdd' ),
to_date (
(
CASE
WHEN trim( : NEW.END_DATE ) IS NULL
OR trim( : NEW.END_DATE ) = '' THEN
'29991231' ELSE : NEW.end_date
END
),
'yyyyMMdd'
),
to_number ( '' ),
to_number ( '' ),
to_number ( '' ),
to_date ( substr( : NEW.create_time, 0, 8 ), 'yyyyMMdd' ),
: NEW.IS_DELETED,
to_number ( '' ),
'',
'',
'',
'',
'',
'',
to_number ( '' ),
to_number ( '' ),
to_number ( '' ),
to_number ( '' ),
'',
'',
'',
to_number ( '' ),
to_number ( '' ),
to_number ( '' ),
to_number ( '' ),
'',
'',
'',
'',
'',
'',
to_number ( '' ),
to_number ( '' ),
to_number ( '' ),
1,
to_number ( '' ),
to_number ( '' ),
'',
: NEW.AGENCY_TYPE_CODE,
'',
to_number ( '' ),
'',
to_number ( '' ),
to_number ( '' ),
to_number ( '' ),
'',
'',
'',
'',
to_number ( '' ),
: NEW.agency_code,
to_date ( substr( : NEW.create_time, 0, 8 ), 'yyyyMMdd' ),
to_number ( '' ),
to_number ( '' ),
to_number ( '' ),
to_number ( '' ),
to_number ( '' ),
'',
to_number ( '' ),
'',
: NEW.YEAR,
( SELECT a.ele_name FROM ele_agency_type a WHERE a.ele_code =: NEW.AGENCY_TYPE_CODE ),
(SELECT
c.agency_id
FROM
bas_agency_info c
WHERE
c.is_deleted <> 1
AND c.mof_div_code =: NEW.mof_div_code
AND c.agency_code = substr( : NEW.agency_code, 1, 3 ) and rownum=1),
(case when : NEW.agency_level_code=1 then '' else (select c.agency_id from bas_agency_info c where c.is_deleted<>1 and c.mof_div_code=: NEW.mof_div_code and c.agency_code=substr(: NEW.agency_code,1,6) and rownum=1) end),
(case when : NEW.agency_level_code=2 then '' else (select c.agency_id from bas_agency_info c where c.is_deleted<>1 and c.mof_div_code=: NEW.mof_div_code and c.agency_code=substr(: NEW.agency_code,1,9) and rownum=1) end),
(case when : NEW.agency_level_code=3 then '' else (select c.agency_id from bas_agency_info c where c.is_deleted<>1 and c.mof_div_code=: NEW.mof_div_code and c.agency_code=substr(: NEW.agency_code,1,12) and rownum=1) end),
(case when : NEW.agency_level_code=4 then '' else (select c.agency_id from bas_agency_info c where c.is_deleted<>1 and c.mof_div_code=: NEW.mof_div_code and c.agency_code=substr(: NEW.agency_code,1,15) and rownum=1) end),
(case when : NEW.agency_level_code=5 then '' else (select c.agency_id from bas_agency_info c where c.is_deleted<>1 and c.mof_div_code=: NEW.mof_div_code and c.agency_code=substr(: NEW.agency_code,1,18) and rownum=1) end),
(case when : NEW.PARENT_ID is null then '0' else : NEW.PARENT_ID end ),
'',
(select a.ele_id from ele_agency_type a where a.ele_code=: NEW.AGENCY_TYPE_CODE),
'','',
(select a.id from gap_ele_mof_dep a where A.TENANT_ID=: NEW.MOF_DIV_CODE AND a.code=: NEW.MOF_DEP_CODE and a.is_deleted!=1),
: NEW.agency_id,: NEW.agency_name,'22',
: NEW.MOF_DIV_CODE,
to_number(: NEW.LEVEL_NO),
1,1,
to_date(substr(: NEW.create_time, 0, 8), 'yyyyMMdd')
);
--update ELE_AGENCY set ELE_CODE = : NEW.agency_code,ELE_NAME = : NEW.agency_name,IS_DELETED = : NEW.is_deleted,IS_LEAF = : NEW.is_leaf where ELE_ID = : NEW.agency_id;
when deleting then
delete ELE_AGENCY where ELE_ID = : OLD.agency_id;
end case;
--COMMIT;
END TR_toSyncAgencyinfo;
超级无敌触发器
最新推荐文章于 2021-09-04 15:49:22 发布