日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

oracle定时器在项目中的应用

發(fā)布時(shí)間:2024/1/17 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 oracle定时器在项目中的应用 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

業(yè)務(wù)需求:

現(xiàn)在業(yè)務(wù)人員提出了一個(gè)需求:

在項(xiàng)目中的工作流,都要有一個(gè)流程編號(hào),此編號(hào)有一定的規(guī)則:

前四五位是流程的字母縮寫,中間是8位的日期,后面五位是流水碼,要求流水碼每天從00001開始。即:QJLC2018060800001

?

沒(méi)有想到更好的方式,暫時(shí)考慮到了使用oracle的定時(shí)器來(lái)每天定時(shí)的將流水碼重置為1。

Oracle數(shù)據(jù)庫(kù)表和定時(shí)器的創(chuàng)建:

創(chuàng)建任務(wù)編碼表:

/*==============================================================*/

/* Table: t_flow_taskcode_conf????????????????????????????????? */

/*==============================================================*/

create table t_flow_taskcode_conf? (

?? flowflag?????? ???????varchar2(8),

?? flowab ? ? ? ? ? ? ? ?varchar2(10),

?? flowcode???????????? NUMBER(5)

);

comment on table t_flow_taskcode_conf is '流程生成任務(wù)編號(hào)表';

comment on column t_flow_taskcode_conf.flowflag is '流程標(biāo)識(shí)';

comment on column t_flow_taskcode_conf.flowab is '流程四位縮寫';

comment on column t_flow_taskcode_conf.flowcode is '流水碼';

?

insert into t_flow_taskcode_conf (FLOWFLAG, FLOWAB, FLOWCODE) values ('QJLC', 'QJLC', 1);

insert into t_flow_taskcode_conf (FLOWFLAG, FLOWAB, FLOWCODE) values ('BGYP', 'BGYP', 1);

insert into t_flow_taskcode_conf (FLOWFLAG, FLOWAB, FLOWCODE) values ('DJBX', 'DJBX', 1);

commit;

?創(chuàng)建oracle內(nèi)部的定時(shí)器:

create or replace procedure taskcode_procedure is

begin

? update t_flow_taskcode_conf fc set fc.flowcode = 1;

? commit;

end;

?

--定義taskcode每天自動(dòng)初始化的job任務(wù)

declare taskcodejob number;

begin

? dbms_job.submit(

??????? taskcodejob,? --定時(shí)器ID,系統(tǒng)自動(dòng)獲得

??????? 'taskcode_procedure;', --what 執(zhí)行的存儲(chǔ)過(guò)程名

??????? sysdate,? --定時(shí)器開始執(zhí)行的時(shí)間,這樣寫表示立即執(zhí)行 --next_date,可以不填

??????? 'TRUNC(sysdate)+1'--'Interval時(shí)間字符串' --關(guān)鍵設(shè)置,此處表示每天的0點(diǎn)執(zhí)行

? );

commit;

end;

??

#########下面是一些oracle中的job表和內(nèi)置定時(shí)器函數(shù)的介紹:

--? select * from user_jobs;? --查看調(diào)度任務(wù)

--? select * from dba_jobs_running;--查看正在執(zhí)行的調(diào)度任務(wù)

--? select * from dba_jobs;--查看執(zhí)行完的調(diào)度任務(wù)

?

----更新一個(gè)job的sql代碼

declare

taskcodejob number;

begin

????? dbms_job.run(3);? ??????--運(yùn)行jobid為3的定時(shí)器

????? --dbms_job.remove(10);? ?--9是從user_jobs這個(gè)表中查詢到然后手動(dòng)賦值到這里的

????? --dbms_job.broken(8); ???--停止一個(gè)job

????? --dbms_job.interval(84,'TRUNC(sysdate)+15/1440');--更改定時(shí)器的運(yùn)行頻率

commit;

end;?

?

項(xiàng)目中的使用

Java代碼:

/*** 傳入流程的標(biāo)志,返回流程的任務(wù)編碼* @param taskCodeEnum* @return*/public String getAndSetTaskCode(FlowTaskCodeEnum taskCodeEnum){String flowflag = taskCodeEnum.toString();? //flowflag是”BGYP”,”QJLC”等字符串//先獲取流程的編碼
?? String taskcode = publicCollectDao.getTaskCodeByFlow(flowflag);Map<String,Object> map = new HashMap<>();map.put("flowflag",flowflag);//設(shè)置流程的編碼加1publicCollectDao.updateFlowCode(map);return taskcode; }

Mybatis的xml文件:

<select id="getTaskCodeByFlow" parameterType="string" resultType="string">

  select fc.flowab||to_char(sysdate,'yyyyMMdd')||lpad(fc.flowcode,5,'0') taskcode

  from t_flow_taskcode_conf fc?

  where fc.flowflag = #{flowflag}

</select>

<update id="updateFlowCode" parameterType="map">

  update t_flow_taskcode_conf set flowcode = flowcode+1 where flowflag=#{flowflag}

</update>

?

上面的java代碼,要保證getAndSetTaskCode()方法在使用時(shí)開啟了事務(wù)。

?

參考:

https://www.cnblogs.com/mingforyou/archive/2012/06/06/2538063.html

https://blog.csdn.net/anrry258/article/details/26555693

注意區(qū)分是普通的sql窗口還是commond窗口。

?

轉(zhuǎn)載于:https://www.cnblogs.com/yjk295722366/p/9155112.html

總結(jié)

以上是生活随笔為你收集整理的oracle定时器在项目中的应用的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。