您好,登錄后才能下訂單哦!
這篇文章將為大家詳細講解有關如何進行基于R12 Business Event+Workflow的分析,文章內容質量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關知識有一定的了解。
今天做了個Business events + Workflow 的例子,記錄一下。
功能描述:
當表中新增一條INVOICE信息,自動觸發Business events, 然后調用Workflow,發Notification 給審批者審批。
主要目的是測試Business events 的功能,學習一下。
測是測通了,但做完后,發覺并沒有了解Business events的優勢,因為這樣的功能,完全可以在記錄新增時直接調用Workflow來處理,感覺系統標準的Business events也無非是在某個操作完成后,觸發一個Events,來完成后繼的操作,就算有延遲處理(Defer)的功能,似乎我們也可通過database job 來實現,訂閱(Subscriptions)功能也似乎可以寫Package來實現不同的業務邏輯的分支處理。
如果有TX看到我的困惑,請不吝賜教!
下面是例子的詳細步驟。
1. 建立客戶化表
Notification的定義如下:
注意Performer的定義,即為接收人
上傳Workflow并注冊至系統
Event subscription 的定義
注意,Phase 定義在100以下的為即時處理
注意: PL/SQL Rule Function 里為客制化的程序,用來完成Event 信息的保存和Event的初始化
Workflow Type 里既為上面開發的Workflow, Process 為里面唯一的 create or replace package body c_customer_invoice_pkg is
--用來生成測試數據及調用Events
procedure insert_data is
l_invoice_id number;
begin
select c_apps.c_customer_invoice_s.nextval into l_invoice_id from dual;
--Insert 數據
--3137為我的user id,此為測試方便,直接用。
insert into c_apps.c_customer_invoices_all
(invoice_id,
invoice_date,
invoice_amount,
submit_id,
submit_date,
approval_id,
approval_date,
approval_memo,
approval_status)
values
(l_invoice_id, sysdate, 1000, 3137, sysdate, null, null, null, null);
commit;
--調用過程啟動Event
raise_event(l_invoice_id, 3137);
end insert_data;
--用來啟動Event
PROCEDURE raise_event(pi_invoice_id in NUMBER, pi_submit_id in NUMBER) is
l_parameter_list wf_parameter_list_t := wf_parameter_list_t();
l_parameter_t wf_parameter_t := wf_parameter_t(null, null);
l_event_key NUMBER;
l_event_data varchar2(300);
l_message varchar2(10);
BEGIN
--用invoice id 做為event key
l_event_key := pi_invoice_id;
--定義event的參數
l_parameter_t.setName('INVOICE_ID');
l_parameter_t.setVALUE(pi_invoice_id);
l_parameter_list.extend;
l_parameter_list(1) := l_parameter_t;
l_parameter_t.setName('SUBMIT_ID');
l_parameter_t.setVALUE(pi_submit_id);
l_parameter_list.extend;
l_parameter_list(2) := l_parameter_t;
--啟動
wf_event.raise(p_event_name => 'oracle.apps.c_apps.invoice.approval',
p_event_key => l_event_key,
--p_event_data => l_event_data,
p_parameters => l_parameter_list);
commit;
l_parameter_list.DELETE;
END raise_event;
--此過程設置在Subscription的rule function中,用來往表中寫入Event信息
FUNCTION rule_function(p_subscription in RAW,
p_event in out NOCOPY WF_EVENT_T)
return varchar2 is
l_rule VARCHAR2(20);
l_parameter_list wf_parameter_list_t := wf_parameter_list_t();
l_parameter_t wf_parameter_t := wf_parameter_t(null, null);
i_parameter_name l_parameter_t.name%type;
i_parameter_value l_parameter_t.value%type;
i pls_integer;
l_invoice_id l_parameter_t.value%type;
l_submit_id l_parameter_t.value%type;
BEGIN
if p_event.geteventname() = 'oracle.apps.c_apps.invoice.approval' then
--獲取Event的參數
l_parameter_list := p_event.getParameterList();
if l_parameter_list is not null then
i := l_parameter_list.FIRST;
--獲取參數的值
while (i <= l_parameter_list.LAST) loop
i_parameter_name := null;
i_parameter_value := null;
i_parameter_name := l_parameter_list(i).getName();
i_parameter_value := l_parameter_list(i).getValue();
if i_parameter_name is not null then
if i_parameter_name = 'INVOICE_ID' then
l_invoice_id := i_parameter_value;
elsif i_parameter_name = 'SUBMIT_ID' then
l_submit_id := i_parameter_value;
end if;
end if;
i := l_parameter_list.NEXT(i);
end loop;
end if;
--寫入Event表
insert into c_apps.c_customer_invoice_events
(event_id,
event_name,
event_key,
event_data,
event_date,
invoice_id,
submit_id)
values
(c_apps.c_customer_invoice_event_s.nextval,
p_event.getEventName,
p_event.getEventKey,
p_event.getEventData,
sysdate,
l_invoice_id,
l_submit_id);
--調用系統標準的Event rule
l_rule := wf_rule.default_rule(p_subscription, p_event);
end if;
return('SUCCESS');
EXCEPTION
WHEN OTHERS THEN
wf_core.context('c_customer_invoice_pkg',
'rule_function',
p_event.geteventname(),
p_subscription);
wf_event.seterrorinfo(p_event, 'ERROR');
RETURN 'ERROR';
END rule_function;
--用于Workflow,取得submit/approval的人員信息及發票信息
PROCEDURE get_submit_info(itemtype IN VARCHAR2,
itemkey IN VARCHAR2,
actid IN NUMBER,
funcmode IN VARCHAR2,
resultout OUT NOCOPY VARCHAR2) is
l_invoice_id NUMBER;
l_invoice_amount NUMBER;
l_invoice_date date;
l_orig_system wf_roles.orig_system%TYPE := 'PER';
l_submit_id NUMBER;
l_submit_name wf_roles.NAME%TYPE;
l_submit_display_name wf_roles.display_name%TYPE;
l_approval_id NUMBER;
l_approval_name wf_roles.NAME%TYPE;
l_approval_display_name wf_roles.display_name%TYPE;
begin
IF (funcmode <> wf_engine.eng_run) THEN
resultout := wf_engine.eng_null;
RETURN;
END IF;
l_invoice_id := wf_engine.getitemattrnumber(itemtype => itemtype,
itemkey => itemkey,
aname => 'INVOICE_ID');
l_submit_id := wf_engine.getitemattrnumber(itemtype => itemtype,
itemkey => itemkey,
aname => 'SUBMIT_ID');
wf_directory.GetRoleName(p_orig_system => l_orig_system,
p_orig_system_id => l_submit_id,
p_name => l_submit_name,
p_display_name => l_submit_display_name);
wf_engine.setitemattrtext(itemtype => itemtype,
itemkey => itemkey,
aname => 'SUBMIT_NAME',
avalue => l_submit_name);
wf_engine.setitemattrtext(itemtype => itemtype,
itemkey => itemkey,
aname => 'SUBMIT_DSP_NAME',
avalue => l_submit_display_name);
wf_directory.GetRoleName(p_orig_system => l_orig_system,
p_orig_system_id => l_submit_id,
p_name => l_approval_name,
p_display_name => l_approval_display_name);
wf_engine.setitemattrnumber(itemtype => itemtype,
itemkey => itemkey,
aname => 'APPROVAL_ID',
avalue => l_submit_id);
wf_engine.setitemattrtext(itemtype => itemtype,
itemkey => itemkey,
aname => 'APPROVAL_NAME',
avalue => l_approval_name);
wf_engine.setitemattrtext(itemtype => itemtype,
itemkey => itemkey,
aname => 'APPROVAL_DSP_NAME',
avalue => l_approval_display_name);
select invoice_amount, invoice_date
into l_invoice_amount, l_invoice_date
from c_apps.c_customer_invoices_all
where invoice_id = l_invoice_id;
wf_engine.setitemattrnumber(itemtype => itemtype,
itemkey => itemkey,
aname => 'INVOICE_AMOUNT',
avalue => l_invoice_amount);
wf_engine.SetItemAttrDate(itemtype => itemtype,
itemkey => itemkey,
aname => 'INVOICE_DATE',
avalue => l_invoice_date);
resultout := 'COMPLETE';
EXCEPTION
when others then
wf_core.context('C_CUSTOMER_INVOICE_PKG',
'get_submit_info',
itemtype,
itemkey,
TO_CHAR(actid),
funcmode,
SQLERRM);
raise;
end get_submit_info;
--用于Workflow的審批分支
PROCEDURE invoice_approval(itemtype IN VARCHAR2,
itemkey IN VARCHAR2,
actid IN NUMBER,
funcmode IN VARCHAR2,
resultout OUT NOCOPY VARCHAR2) is
l_invoice_id NUMBER;
l_approval_memo c_apps.c_customer_invoices_all.approval_memo%TYPE;
l_approval_id NUMBER;
begin
IF (funcmode <> wf_engine.eng_run) THEN
resultout := wf_engine.eng_null;
RETURN;
END IF;
l_invoice_id := wf_engine.getitemattrnumber(itemtype => itemtype,
itemkey => itemkey,
aname => 'INVOICE_ID');
l_approval_id := wf_engine.getitemattrnumber(itemtype => itemtype,
itemkey => itemkey,
aname => 'APPROVAL_ID');
l_approval_memo := wf_engine.getitemattrtext(itemtype => itemtype,
itemkey => itemkey,
aname => 'APPROVAL_MEMO');
UPDATE c_apps.c_customer_invoices_all
SET approval_id = l_approval_id,
approval_date = sysdate,
approval_memo = l_approval_memo,
approval_status = 'Y'
WHERE invoice_id = l_invoice_id;
resultout := 'COMPLETE';
EXCEPTION
when others then
wf_core.context('C_CUSTOMER_INVOICE_PKG',
'invoice_approval',
itemtype,
itemkey,
TO_CHAR(actid),
funcmode,
SQLERRM);
raise;
end invoice_approval;
--用于Workflow的拒絕分支
PROCEDURE invoice_reject(itemtype IN VARCHAR2,
itemkey IN VARCHAR2,
actid IN NUMBER,
funcmode IN VARCHAR2,
resultout OUT NOCOPY VARCHAR2) is
l_invoice_id NUMBER;
l_approval_memo c_apps.c_customer_invoices_all.approval_memo%TYPE;
l_approval_id NUMBER;
begin
IF (funcmode <> wf_engine.eng_run) THEN
resultout := wf_engine.eng_null;
RETURN;
END IF;
l_invoice_id := wf_engine.getitemattrnumber(itemtype => itemtype,
itemkey => itemkey,
aname => 'INVOICE_ID');
l_approval_id := wf_engine.getitemattrnumber(itemtype => itemtype,
itemkey => itemkey,
aname => 'APPROVAL_ID');
l_approval_memo := wf_engine.getitemattrtext(itemtype => itemtype,
itemkey => itemkey,
aname => 'APPROVAL_MEMO');
UPDATE c_apps.c_customer_invoices_all
SET approval_id = l_approval_id,
approval_date = sysdate,
approval_memo = l_approval_memo,
approval_status = 'N'
WHERE invoice_id = l_invoice_id;
resultout := 'COMPLETE';
EXCEPTION
when others then
wf_core.context('C_CUSTOMER_INVOICE_PKG',
'invoice_reject',
itemtype,
itemkey,
TO_CHAR(actid),
funcmode,
SQLERRM);
raise;
end invoice_reject;
end c_customer_invoice_pkg;
最后在PL/SQL中執行
BEGIN
c_customer_invoice_pkg.insert_data;
end;
查看Event表,記錄生成,進入系統,發現Notification已經收到,可以正常審批!
關于如何進行基于R12 Business Event+Workflow的分析就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。