我需要在 apex 应用程序中创建动态批准工作流,因此我为此创建了触发器。但是我需要结合这些/使逻辑动态。
触发器 1 向第一个审批者发送电子邮件以进行审批。当approver登录approved时,设置p_it_issues.APPROVE_THIS='Y',下一个触发器设置p_it_issues.approved=1,表示已经通过第一级。第二个触发器也将电子邮件通知发送给第二个批准者。(下面提到的所有代码供参考)。但是在这个应用程序中,审批级别应该是动态的,一个部门可能有 2 个审批者,另一个可能有 3 个。我现在的逻辑是,假设 HR 部门有 2 个审批级别。因此,当 p_it_issues.approved =2 并且与设置为 =2 的 p_it_departments.approval_level(批准部门的数量)匹配时,在第二次批准后,问题可以得到解决。(这最后一个条件,我仍然可以作为授权方案将问题设置为仅在 2 匹配时解决)。
但是由于不同程度的批准,这意味着我将不得不创建越来越多的触发器。有没有办法将其结合起来,以便根据每个部门的approval_level 不断增加和发送p_it_people.approver='Approver 1'.to..'Ápprover n' 的批准?HR 有 2 个,所以它不会将其发送给 p_it_people 表中的 2 个审批者,其中 Approver 列分别设置为 Approver 1 和 2?
为了更清楚,我的 2 个触发器和后续的表结构都存在。
让我知道是否需要进一步澄清。我知道这似乎冗长乏味,但任何帮助将不胜感激。
一级批准的触发器 1:
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 时 n 是部门表中每个部门的批准申请数。