触发器共同在oracle apex应用程序中工作
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了触发器共同在oracle apex应用程序中工作相关的知识,希望对你有一定的参考价值。
我需要在apex应用程序中创建动态批准工作流,所以我为此创建了触发器。但是我需要结合这些/使逻辑动态。
触发器1将电子邮件发送给第一批准人以供批准。批准者登录批准后,设置p_it_issues.APPROVE_THIS ='Y',下一个触发器将设置p_it_issues.approved = 1以表明它已通过第一级。第二个触发器也会向第二个批准者发送电子邮件通知。 (下面提到的所有代码仅供参考)。但是,在此应用中,批准级别应该是动态的,一个部门可以有2个批准者,而另一个部门可以有3个批准者。到目前为止,我的逻辑是人力资源部有2个批准级别。因此,在第二次批准时,如果p_it_issues.approved = 2且与p_it_departments.approval_level(部门批准数)设置为= 2,则可以解决此问题。 (这最后一个条件,我仍然可以将授权方案设置为仅在2匹配时才解决问题)。
但是由于批准级别的不同,这意味着我将不得不创建越来越多的触发器。有没有一种方法可以结合使用此方法,以便它可以根据每个部门的approving_level不断增加并从p_it_people.approver ='审批人1'...'Áprovern'发送审批? HR有2个,因此它不会将其发送到p_it_people表中的2个批准者,并且“批准者”列分别设置为“批准者1”和“批准者2”?
为了更清楚起见,我提供了2个触发器和随后的表结构。
让我知道是否需要进一步澄清。我知道这似乎很长且乏味,但是任何帮助将不胜感激。
第一级触发触发器:
CREATE OR REPLACE EDITIONABLE TRIGGER P_IT_ISSUES_AIU_Notify_Approver_1
AFTER
insert on P_IT_ISSUES
for each row
FOLLOWS P_IT_ISSUES_AIU_EMAIL
declare
v_person_id number;
v_email varchar2(255);
v_dept_name varchar2(50);
begin
select p.person_id ,p.person_email,i.dept_name into v_person_id,v_email,v_Dept_name from p_it_people p,p_it_departments i
where p.assigned_dept=i.dept_id and i.dept_id=:new.related_dept_id and p.approver='Approver 1' ;
APEX_MAIL.SEND(
p_to => v_email,
p_from => v_email,
p_body =>
'You have been assigned a new issue for first level approval. ' ||chr(10)||
'The details are below. ' ||chr(10)||
chr(10)||
' Department:'|| v_dept_name ||chr(10)||
' Summary: '||:new.issue_summary ||chr(10)||
' Status: '||:new.status ||chr(10)||
'Priority: '||nvl(:new.priority,'-'),
p_subj => 'New Issue for First Level Approval');
end;
/
触发2,在第一个批准者设置p_it_issues.approve_this ='Y'时设置p_it_issues.approved = 1。
CREATE OR REPLACE EDITIONABLE TRIGGER P_IT_ISSUES_AIU_Notify_Approver_2
BEFORE
update on P_IT_ISSUES
for each row
declare
v_person_id number;
v_email varchar2(255);
v_dept_name varchar2(50);
begin
if :new.APPROVE_THIS = 'Y'
then :new.APPROVED :=1 ;
end if;
select p.person_id ,p.person_email,i.dept_name into v_person_id,v_email,v_Dept_name from p_it_people p,p_it_departments i
where p.assigned_dept=i.dept_id and i.dept_id=:new.related_dept_id and p.approver='Approver 2' ;
APEX_MAIL.SEND(
p_to => v_email,
p_from => v_email,
p_body =>
'You have been assigned a new issue for second level approval. ' ||chr(10)||
'The details are below. ' ||chr(10)||
chr(10)||
' Department:'|| v_dept_name ||chr(10)||
' Summary: '||:new.issue_summary ||chr(10)||
' Status: '||:new.status ||chr(10)||
'Priority: '||nvl(:new.priority,'-'),
p_subj => 'New Issue for Second Level Approval');
end;
表结构:人:
CREATE TABLE "P_IT_PEOPLE"
( "PERSON_ID" NUMBER NOT NULL ENABLE,
"PERSON_NAME" VARCHAR2(255) NOT NULL ENABLE,
"PERSON_EMAIL" VARCHAR2(255) NOT NULL ENABLE,
"PERSON_ROLE" VARCHAR2(30) NOT NULL ENABLE,
"USERNAME" VARCHAR2(255) NOT NULL ENABLE,
"ASSIGNED_DEPT" NUMBER,
"CREATED_ON" DATE NOT NULL ENABLE,
"CREATED_BY" VARCHAR2(255) NOT NULL ENABLE,
"MODIFIED_ON" DATE,
"MODIFIED_BY" VARCHAR2(255),
"PERSON_PASSWORD" VARCHAR2(100),
"APPROVER" VARCHAR2(50),
CONSTRAINT "P_IT_PEOPLE_PK" PRIMARY KEY ("PERSON_ID")
USING INDEX ENABLE,
CONSTRAINT "P_IT_PEOPLE_NAME_UK" UNIQUE ("PERSON_NAME")
USING INDEX ENABLE,
CONSTRAINT "P_IT_PEOPLE_USERNAME_UK" UNIQUE ("USERNAME")
ALTER TABLE "P_IT_PEOPLE" ADD CONSTRAINT "P_IT_PEOPLE_DEPT_FK" FOREIGN KEY ("ASSIGNED_DEPT")
REFERENCES "P_IT_DEPARTMENTS" ("DEPT_ID") ENABLE
部门:
CREATE TABLE "P_IT_DEPARTMENTS"
( "DEPT_ID" NUMBER NOT NULL ENABLE,
"DEPT_NAME" VARCHAR2(255) NOT NULL ENABLE,
"APPROVAL_LEVEL" NUMBER,
CONSTRAINT "P_IT_DEPARTMENTS_PK" PRIMARY KEY ("DEPT_ID")
USING INDEX ENABLE
)
/
问题:
CREATE TABLE "P_IT_ISSUES"
( "ISSUE_ID" NUMBER NOT NULL ENABLE,
"ISSUE_SUMMARY" VARCHAR2(255) NOT NULL ENABLE,
"ISSUE_DESCRIPTION" VARCHAR2(4000),
"IDENTIFIED_BY_PERSON_ID" NUMBER NOT NULL ENABLE,
"IDENTIFIED_DATE" DATE NOT NULL ENABLE,
"RELATED_DEPT_ID" NUMBER NOT NULL ENABLE,
"ASSIGNED_TO_PERSON_ID" NUMBER,
"STATUS" VARCHAR2(30) NOT NULL ENABLE,
"PRIORITY" VARCHAR2(30) NOT NULL ENABLE,
"TARGET_RESOLUTION_DATE" DATE,
"PROGRESS" VARCHAR2(4000),
"ACTUAL_RESOLUTION_DATE" DATE,
"RESOLUTION_SUMMARY" VARCHAR2(4000),
"CREATED_ON" DATE NOT NULL ENABLE,
"CREATED_BY" VARCHAR2(255) NOT NULL ENABLE,
"MODIFIED_ON" DATE,
"MODIFIED_BY" VARCHAR2(255),
"APPROVED" NUMBER,
"APPROVE_THIS" CHAR(1),
CONSTRAINT "P_IT_ISSUES_PK" PRIMARY KEY ("ISSUE_ID")
USING INDEX ENABLE,
CONSTRAINT "P_IT_ISSUES_PRIORITY_CC" CHECK (priority in ('High','Medium','Low')) ENABLE
)
/
ALTER TABLE "P_IT_ISSUES" ADD CONSTRAINT "P_IT_ISSUES_ASSIGNED_TO_FK" FOREIGN KEY ("ASSIGNED_TO_PERSON_ID")
REFERENCES "IT_PEOPLE" ("PERSON_ID") ENABLE
/
ALTER TABLE P_IT_ISSUES ADD CONSTRAINT "P_IT_ISSUES_IDENTIFIED_BY_FK" FOREIGN KEY ("IDENTIFIED_BY_PERSON_ID")
REFERENCES "P_IT_PEOPLE" ("PERSON_ID") ENABLE
/
ALTER TABLE P_IT_ISSUES ADD CONSTRAINT P_IT_ISSUES_PROJECT_FK FOREIGN KEY (RELATED_DEPT_ID)
REFERENCES P_IT_DEPARTMENTS (DEPT_ID) ENABLE
/
基本循环来自批准人1的触发射击邮件...批准人n是部门表中每个部门的批准申请数。
Vini,尝试在问题表上使用多个触发器,我相信这将是有问题的并且非常严格。相反,我将创建其他表来推动批准过程。
我假设P_IT_DEPARTMENTS中的APPROVAL_LEVEL拥有所需的批准级别数(1,2,3,...)。
我将在P_IT_PEOPLE和P_IT_DEPARTMENTS之间创建一个相交表,称为P_IT_DEPT_APPROVERS,其中包含FK和APPROVER_LEVEL类型NUMBER。该表允许将具有指定批准级别的任何人指定为给定部门的批准人。如果APPROVER_LEVEL(来自交叉表)大于APPROVAL_LEVEL(来自部门),则错误。
我将创建另一个表作为P_IT_ISSUES和P_IT_DEPT_APPROVERS之间的交集表,称为P_IT_APPROVALS,该表记录了用户已批准以及何时批准。
在P_IT_ISSUES中,我将包含APPROVAL_LEVEL(NUMBER)来记录当前的批准级别,APPROVAL_COMPLETE_YN VARCHAR2(1)表示已被批准。
P_IT_APPROVALS上的插入后触发器可以计算特定级别的所有批准者是否都批准了该问题,在这种情况下,请使用新的批准级别来更新P_IT_ISSUES表,如果没有更多的批准级别,则将批准设置为已完成,否则,发送至下一级批准者。
关于,大卫
以上是关于触发器共同在oracle apex应用程序中工作的主要内容,如果未能解决你的问题,请参考以下文章