办件流转中执行步骤中的所挂接的存储过程

  1  /*
  2      办件流转
  3   */
  4   procedure P_DoFileFlow(varError      out varchar2,
  5                          varWaitID     in varchar2,
  6                          varFlowID     in varchar2,
  7                          varUserID     in varchar2,
  8                          varDepID      in varchar2,
  9                          varModifytime in varchar2) as
 10   
 11     varPackagename   varchar2(50);
 12     varFunctionname  varchar2(50);
 13     varFunctionParam varchar2(200);
 14     numDataCount     number(12);
 15   
 16     varStepID       varchar2(20);
 17     varTargetStepID varchar2(20);
 18     varFileID       varchar2(20);
 19     numControlID    number(12);
 20     varUserRealname oa_user.user_realname%type;
 21     varUserName     oa_user.user_name%type;
 22     varDepName      oa_department.dep_name%type;
 23     varIslast       ly_f_flowinfo.islast%type;
 24     varFlowName     ly_f_flowinfo.flowname%type;
 25   
 26     varAdviseID oa_advise.advise_id%type;
 27     varDestId   ly_f_flowinfo.dest_content%type;
 28     varDestType ly_f_flowinfo.dest_type%type;
 29     varOpinion  oa_wait.opinion%type;
 30   
 31     varFileTitle ly_s_docbase.file_title%type;
 32     varSql       varchar2(2000);
 33     varAbbSql    varchar2(2000);
 34   begin
 35     select count(1)
 36       into numDataCount
 37       from oa_wait
 38      where wait_id = varWaitID;
 39   
 40     if numDataCount = 0 then
 41       raise_application_error('-20001', '该办件不存在或已被转至其他步骤');
 42     end if;
 43   
 44     select file_id, file_title
 45       into varFileID, varFileTitle
 46       from oa_wait
 47      where wait_id = varWaitID;
 48   
 49     select count(1)
 50       into numDataCount
 51       from ly_s_docbase t
 52      where file_id = varFileID
 53        and t.modifytime = varModifytime;
 54   
 55     if numDataCount = 0 then
 56       raise_application_error('-20001', pk_systemoperation.ConModify);
 57     end if;
 58   
 59     /*本流是否需要写意见,1为写意见*/
 60     select count(1)
 61       into numDataCount
 62       from ly_f_flowinfo t
 63      where flowid = varFlowID
 64        and t.opinion = '1';
 65     select opinion into varOpinion from oa_wait where wait_id = varWaitID;
 66     /*需要写意见*/
 67     if numDataCount > 0 then
 68     
 69       if varOpinion is null then
 70         varError := '请填写转件意见';
 71         return;
 72       end if;
 73     end if;
 74   
 75     select f.stepid, f.tarstepid, f.control_id, f.islast
 76       into varStepID, varTargetStepID, numControlID, varIslast
 77       from ly_f_flowinfo f
 78      where flowid = varFlowID;
 79   
 80     select user_name, user_realname
 81       into varUserName, varUserRealname
 82       from oa_user
 83      where user_id = varUserID;
 84   
 85     select dep_name
 86       into varDepName
 87       from oa_department
 88      where dep_id = varDepID;
 89   
 90     for cc in (select *
 91                  from LY_F_FLOWINFO_todolist
 92                 where flowid = varFlowID
 93                   and VALID_FLAG = 0
 94                 order by orderno) loop
 95       begin
 96         select upper(substr(cc.todo, 1, instr(cc.todo, '.') - 1)),
 97                upper(substr(cc.todo,
 98                             instr(cc.todo, '.') + 1,
 99                             length(cc.todo)))
100           into varPackagename, varFunctionname
101           from dual;
102       
103         select count(*)
104           into numDataCount
105           from ALL_PROCEDURES
106          where procedure_name = upper(varFunctionname)
107            and object_name = upper(varPackagename);
108         if numDataCount = 0 then
109           raise_application_error('-20001', '不存在函数' || cc.todo);
110         end if;
111       
112         varFunctionParam := cc.todoparameter;
113       
114         varFunctionParam := replace(varFunctionParam,
115                                     'varSTEP_ID',
116                                     varStepID);
117         varFunctionParam := replace(varFunctionParam,
118                                     'varDESTSTEP_ID',
119                                     varTargetStepID);
120         varFunctionParam := replace(varFunctionParam,
121                                     'varCONTROL_ID',
122                                     numControlID);
123         varFunctionParam := replace(varFunctionParam,
124                                     'varFILE_ID',
125                                     varFileID);
126         varFunctionParam := replace(varFunctionParam,
127                                     'varWAIT_ID',
128                                     varWaitID);
129         varFunctionParam := replace(varFunctionParam,
130                                     'varUSER_NAME',
131                                     '''' || varUserName || '''');
132         varFunctionParam := replace(varFunctionParam,
133                                     'varUSER_REALNAME',
134                                     '''' || varUserRealname || '''');
135         varFunctionParam := replace(varFunctionParam,
136                                     'varUSER_ID',
137                                     varUserID);
138         varFunctionParam := replace(varFunctionParam, 'varDEP_ID', varDepID);
139         varFunctionParam := replace(varFunctionParam,
140                                     'varDEP_NAME',
141                                     '''' || varDepName || '''');
142       
143         varSql := 'declare varError  varchar2(2000); begin varError:=' ||
144                   cc.todo || '(' || varFunctionParam || ');
145      if varError is not null then raise_application_error(''-20001'',varError) ; end if;
146       end;';
147         execute immediate varSql;
148       
149       exception
150         when others then
151           varError := sqlerrm;
152           raise_application_error('-20001', varError);
153       end;
154     
155     end loop;
156   
157     select f.dest_content,
158            f.dest_type,
159            f.flowname,
160            SEQ_MAXID_OA_ADVISE.Nextval
161       into varDestId, varDestType, varFlowName, varAdviseID
162       from ly_f_flowinfo f
163      where flowid = varFlowID;
164   
165     if varIslast = '0' then
166       /*已经是最后一步啦,删件、更新走人;*/
167       update ly_s_docbase set is_flow = '0' where file_id = varFileID;
168     else
169       /*
170           Dest_Type 171           1人员           部门           角色          列信息          拟稿部门           上一步操作者
177           人员代词
178           部门代词
179           本部门
180           上级部门
181           abb中用100之后的代词
182       */
183       if varDestType = '5' then
184         select dep_id
185           into varDestId
186           from ly_s_docbase
187          where file_id = varFileID;
188         varDestType := 2;
189       end if;
190     
191       if varDestType = '6' then
192         select w.source_id
193           into varDestId
194           from oa_wait w
195          where wait_id = varWaitID;
196         varDestType := 2;
197       end if;
198     
199       if varDestType in ('1', '3', '7') then
200         raise_application_error('-20001',
201                                 '人员、角色、人员代词已停用,请联系管理员修改流程');
202       end if;
203     
204       if varDestType = '8' then
205         select ABB_CONTENT
206           into varAbbSql
207           from oa_abbreviate abb
208          where abb.abb_id = varDestId;
209       
210         execute immediate varAbbSql
211           into varDestId
212           using varFileID;
213         varDestType := 2;
214       
215       end if;
216     
217       --本部门
218       if varDestType = '9' then
219         varDestType := 2;
220         varDestId   := varDepID;
221       end if;
222       --上级部门
223       if varDestType = '10' then
224         varDestType := 2;
225         select father_id
226           into varDestId
227           from oa_department
228          where dep_id = varDepID;
229       end if;
230     
231       insert into oa_wait
232         (wait_id,
233          control_id,
234          step_id,
235          file_id,
236          file_title,
237          wait_date,
238          dest_id,
239          dest_type,
240          source_id,
241          advise_id,
242          flowid,
243          DB_NAME)
244       values
245         (SEQ_MAXID_OA_WAIT.nextval,
246          numControlID,
247          varTargetStepID,
248          varFileID,
249          varFileTitle,
250          to_char(sysdate, 'yyyy-mm-dd hh24:mi;ss'),
251          varDestId,
252          varDestType,
253          varDepID,
254          varAdviseID,
255          varFlowID,
256          (select controlname
257             from ly_f_controlflow
258            where control_id = numControlID));
259     
260     end if;
261   
262     insert into oa_advise
263       (advise_id,
264        control_id,
265        file_id,
266        advise,
267        user_name,
268        user_id,
269        dep_id,
270        dep_name,
271        ad_date,
272        tarcontestname,
273        targetstep,
274        doflow,
275        sourcestep,
276        flowid,
277        userrealname,
278        tarcontestid)
279     values
280       (varAdviseID,
281        numControlID,
282        varFileID,
283        varOpinion,
284        varUserName,
285        varUserID,
286        varDepID,
287        varDepName,
288        to_char(sysdate, 'yyyy-mm-dd hh24:mi;ss'),
289        (select dep_name from oa_department where dep_id = varDestId),
290        varTargetStepID,
291        varFlowName,
292        varStepID,
293        varFlowID,
294        varUserRealname,
295        varDestId);
296   
297     delete from oa_wait where wait_id = varWaitID;
298   
299     commit;
300   exception
301     when others then
302       rollback;
303       varError := sqlerrm;
304   end P_DoFileFlow;

 

posted @ 2019-03-27 20:45  王小鹏  阅读(226)  评论(0编辑  收藏  举报