📄 qianbaodjtask.java
字号:
package com.zx.gwgl;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.TimerTask;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.work.db.DbConnection;
import com.work.db.DbUtil;
import com.work.exception.OurException;
public class QianBaoDjTask extends TimerTask{
private static Log log = LogFactory.getLog(QianBaoDjTask.class);
/**
* 为了实现签报流程中的数据自动登记;<br>
* 实现思路:首先判断此签报流程是否结束。将签报流程中的数据从zx_qianbao表中查询出来,
* 然后插入到表zx_qianbaodj中去,同时将zx_qianbao表中符合条件记录的sfygd设置为1
*
* @return void
*/
public void qianBaoDj() throws OurException{
String qianbaoSql = " select qbrq as rq," + //日期 签报日期
"qbdw," +//签报单位 签报单位
"qbzt as tm," +//题名 自己根据签报主题手工编写
"qbr," +//签报人 签报人
"drsy as yqr," +//阅签人 多人审阅+领导批示???
"qbzt," +//签报主题 签报主题
"'' as sjr," +//收件人 手工录入
"0 as ys," +//页数 手工录入
"id as qb_id " +//系统id zx_qianbao中的id
" from zx_qianbao where sfygd=0";
log.debug(qianbaoSql);
List srcList = DbUtil.executeQueryList(qianbaoSql);
if(srcList == null ){
log.info("没有需要归档的签报流程记录。");
return ;
}
int LEN = srcList.size(); //需要登记的收文流程记录数;
List needGdList = new ArrayList();
//=====================判断流程是否结束,然后来决定对哪些记录进行自动登记===========
for(int i=0;i<LEN;i++){
HashMap map = (HashMap) srcList.get(i);
String id = (String)map.get("qb_id");
String tempSql = "select step_closedtype from enrol_flow where process_inst_id='"+id+"' order by id desc";
//倒序排列可以提高程序的执行效率
List tempList = DbUtil.executeQueryList(tempSql);
if(tempList == null) break;//跳出循环
int tempLen = tempList.size();
//Finished
boolean tempFlag = false; //用来判断此流程过程中是否结束,如果有一条记录包含Finished,那么说明此流程已经结束,可以登记了。
for(int j=0;j<tempLen;j++){
if(((String)((HashMap)tempList.get(j)).get("step_closedtype")).equals("Finished")){
tempFlag = true;
break;
}
}
if(tempFlag) needGdList.add(map);
}
//=================================================
LEN = needGdList.size();
if(LEN<1 ){
log.info("没有需要归档的签报流程记录。");
return ;
}
log.debug("归档签报流程的记录数为:"+LEN+"条。");
String djSql = "insert into zx_qianbaodj "
+ "(rq,qbdw,tm,qbr,yqr,qbzt,sjr,ys,qb_id) values (?,?,?,?,?,?,?,?,?)";
String sfygdSql = "update zx_qianbao set sfygd=1 where id =? "; //更新签报流程中对应的记录数
String rq = "";
String qbdw ="";
String tm ="";
String qbr ="";
String yqr = "";
String qbzt="";
String sjr="";
int ys =0;
String qb_id = "";
Connection conn = DbConnection.getConn();
if(conn == null )
throw new OurException("获取数据库连接失败!");
PreparedStatement pst = null;
PreparedStatement pst2 = null;
int result = 0;
int result2 = 0; //这个sqlserver驱动程序竟然不支持PreparedStatement循环传递参数。
try{
conn.setAutoCommit(false);
pst = conn.prepareStatement(djSql);
pst2 = conn.prepareStatement(sfygdSql);
for(int i=0;i<LEN;i++){
HashMap map = (HashMap)needGdList.get(i);
rq = (String)map.get("rq");
qbdw = (String)map.get("qbdw");
tm = (String)map.get("tm");
qbr = (String)map.get("qbr");
yqr = (String)map.get("yqr");
qbzt = (String)map.get("qbzt");
sjr = (String)map.get("sjr");
ys = ((Integer)map.get("ys")).intValue();
qb_id = (String)map.get("qb_id");
pst.setString(1,rq);
pst.setString(2,qbdw);
pst.setString(3,tm);
pst.setString(4,qbr);
pst.setString(5,yqr);
pst.setString(6,qbzt);
pst.setString(7,sjr);
pst.setInt(8,ys);
pst.setString(9,qb_id);
pst2.setString(1,qb_id);
result += pst.executeUpdate();
result2 += pst2.executeUpdate();
//将已经归档的zx_shouwen中对应的记录设置sfygd为1
}
conn.commit();
log.debug("共"+result+"条签报流程记录登记成功!共"+result2+"条签报流程记录设置登记标志成功!");
}catch(SQLException e){
log.error("出现异常!由于登记了"+result+"记录,更新了"+result2+"条记录!所以登记失败!" +
"估计是记录数目太多,超出了PreparedStatement的缓存数!");
try {
conn.rollback();
} catch (SQLException e1) {
e1.printStackTrace();
}
throw new OurException("签报流程自动登记执行失败!请通知管理员!",e);
}finally{
DbUtil.closeStatement(pst2);
DbUtil.closeStatement(pst);
DbUtil.closeConnection(conn);
}
}
/* (non-Javadoc)
* @see java.lang.Runnable#run()
*/
public void run() {
try {
qianBaoDj();
} catch (OurException e) {
System.out.println(com.work.exception.ExceptionUtil
.getDetailMessage(e));
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -